ensure globals have names, as we rely on names for address lookups
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp index 362dd24..ce647d6 100644 --- a/lib/Target/JSBackend/JSBackend.cpp +++ b/lib/Target/JSBackend/JSBackend.cpp
@@ -146,7 +146,7 @@ /// module to JavaScript. class JSWriter : public ModulePass { raw_pwrite_stream &Out; - const Module *TheModule; + Module *TheModule; unsigned UniqueNum; unsigned NextFunctionIndex; // used with NoAliasingFunctionPointers ValueMap ValueNames; @@ -2698,6 +2698,24 @@ } void JSWriter::processConstants() { + // Ensure a name for each global + for (Module::global_iterator I = TheModule->global_begin(), + E = TheModule->global_end(); I != E; ++I) { + if (I->hasInitializer()) { + if (!I->hasName()) { + // ensure a unique name + static int id = 1; + std::string newName; + while (1) { + newName = std::string("glb_") + utostr(id); + if (!TheModule->getGlobalVariable("glb_" + utostr(id))) break; + id++; + assert(id != 0); + } + I->setName(Twine(newName)); + } + } + } // First, calculate the address of each constant for (Module::const_global_iterator I = TheModule->global_begin(), E = TheModule->global_end(); I != E; ++I) {