aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/CppBackend/CPPBackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r--lib/Target/CppBackend/CPPBackend.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp
index 80621c04cd..4a311f0ce0 100644
--- a/lib/Target/CppBackend/CPPBackend.cpp
+++ b/lib/Target/CppBackend/CPPBackend.cpp
@@ -2156,6 +2156,25 @@ void CppWriter::printModuleBody() {
for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
I != E; ++I) {
if (!I->isDeclaration()) {
+ // Ensure all arguments and locals are named (we assume used values need names, which might be false if the optimizer did not run)
+ unsigned Next = 1;
+ for (Function::const_arg_iterator AI = I->arg_begin(), AE = I->arg_end();
+ AI != AE; ++AI) {
+ if (!AI->hasName() && AI->hasNUsesOrMore(1)) {
+ ValueNames[AI] = "$" + utostr(Next++);
+ }
+ }
+ for (Function::const_iterator BI = I->begin(), BE = I->end();
+ BI != BE; ++BI) {
+ for (BasicBlock::const_iterator II = BI->begin(), E = BI->end();
+ II != E; ++II) {
+ if (!II->hasName() && II->hasNUsesOrMore(1)) {
+ ValueNames[II] = "$" + utostr(Next++);
+ }
+ }
+ }
+
+ // Emit the function
Out << "function _" << I->getName() << "(";
for (Function::const_arg_iterator AI = I->arg_begin(), AE = I->arg_end();
AI != AE; ++AI) {