aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/NaCl/ExpandI64.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/NaCl/ExpandI64.cpp')
-rw-r--r--lib/Transforms/NaCl/ExpandI64.cpp20
1 files changed, 18 insertions, 2 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();