diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index 2c2e8df79ba..71d6049c8a1 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -1564,11 +1564,25 @@ void CppWriter::printFunctionUses(const Function* F) { // If the operand references a GVal or Constant, make a note of it if (GlobalValue* GV = dyn_cast(operand)) { gvs.insert(GV); - if (GlobalVariable *GVar = dyn_cast(GV)) - if (GVar->hasInitializer()) - consts.insert(GVar->getInitializer()); - } else if (Constant* C = dyn_cast(operand)) + if (GenerationType != GenFunction) + if (GlobalVariable *GVar = dyn_cast(GV)) + if (GVar->hasInitializer()) + consts.insert(GVar->getInitializer()); + } else if (Constant* C = dyn_cast(operand)) { consts.insert(C); + for (unsigned j = 0; j < C->getNumOperands(); ++j) { + // If the operand references a GVal or Constant, make a note of it + Value* operand = C->getOperand(j); + printType(operand->getType()); + if (GlobalValue* GV = dyn_cast(operand)) { + gvs.insert(GV); + if (GenerationType != GenFunction) + if (GlobalVariable *GVar = dyn_cast(GV)) + if (GVar->hasInitializer()) + consts.insert(GVar->getInitializer()); + } + } + } } } } @@ -1591,7 +1605,7 @@ void CppWriter::printFunctionUses(const Function* F) { printVariableHead(F); } -// Print the constants found + // Print the constants found nl(Out) << "// Constant Definitions"; nl(Out); for (SmallPtrSet::iterator I = consts.begin(), E = consts.end(); I != E; ++I) { @@ -1601,11 +1615,13 @@ void CppWriter::printFunctionUses(const Function* F) { // Process the global variables definitions now that all the constants have // been emitted. These definitions just couple the gvars with their constant // initializers. - nl(Out) << "// Global Variable Definitions"; nl(Out); - for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end(); - I != E; ++I) { - if (GlobalVariable* GV = dyn_cast(*I)) - printVariableBody(GV); + if (GenerationType != GenFunction) { + nl(Out) << "// Global Variable Definitions"; nl(Out); + for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end(); + I != E; ++I) { + if (GlobalVariable* GV = dyn_cast(*I)) + printVariableBody(GV); + } } }