diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/NaCl/ExpandI64.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/NaCl/ResolvePNaClIntrinsics.cpp | 2 |
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/Transforms/NaCl/ExpandI64.cpp b/lib/Transforms/NaCl/ExpandI64.cpp index 40ad6b6cbf..f56932dec4 100644 --- a/lib/Transforms/NaCl/ExpandI64.cpp +++ b/lib/Transforms/NaCl/ExpandI64.cpp @@ -163,6 +163,15 @@ void ExpandI64::ensureLegalFunc(Function *F) { FunctionType *FT = F->getFunctionType(); int Num = FT->getNumParams(); + + // XXX Emscripten TODO: Move this fix to PNacl upstream. + // Allocate small names on stack, large ones on heap. + // This is because on VS2010, arrays on the stack must + // be compile-time constant sized. (no C99 dynamic-length array support) + const int StackSize = 256; + char StackArray[StackSize]; + char *AllocArray = 0; + for (int i = -1; i < Num; i++) { Type *T = i == -1 ? FT->getReturnType() : FT->getParamType(i); if (isIllegal(T)) { @@ -170,12 +179,19 @@ void ExpandI64::ensureLegalFunc(Function *F) { std::string Name = NF->getName(); if (strncmp(Name.c_str(), "llvm.", 5) == 0) { // this is an intrinsic, and we are changing its signature, which will annoy LLVM, so rename - char NewName[Name.size()+1]; + const size_t len = Name.size()+1; + char *NewName; + if (len > StackSize) + NewName = AllocArray = new char[len]; + else + NewName = StackArray; const char *CName = Name.c_str(); - for (unsigned i = 0; i < Name.size()+1; i++) { + for (unsigned i = 0; i < len; i++) { NewName[i] = CName[i] != '.' ? CName[i] : '_'; } NF->setName(NewName); + delete[] AllocArray; + AllocArray = 0; } // Move and update arguments for (Function::arg_iterator Arg = F->arg_begin(), E = F->arg_end(), NewArg = NF->arg_begin(); diff --git a/lib/Transforms/NaCl/ResolvePNaClIntrinsics.cpp b/lib/Transforms/NaCl/ResolvePNaClIntrinsics.cpp index 428caef2b5..d58b70d4d0 100644 --- a/lib/Transforms/NaCl/ResolvePNaClIntrinsics.cpp +++ b/lib/Transforms/NaCl/ResolvePNaClIntrinsics.cpp @@ -185,7 +185,7 @@ struct IsLockFreeToConstant { } # elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) // Continue. -# elif defined(__mips__) +# elif defined(__mips__) || defined(_M_IX86) // XXX Emscripten TODO: Move this fix to PNacl upstream. MaxLockFreeByteSize = 4; # else # error "Unknown architecture" |