From 83c15f8a1b19e7b656cf4bb75a01c9fea8be7a6d Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sat, 16 Jun 2007 20:33:24 +0000 Subject: [PATCH] Fix PR1516: When printing the uses of a function (-gen-function only), make sure to include the constants referenced by intializers of global variables. llvm-svn: 37615 --- llvm/tools/llvm2cpp/CppWriter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/tools/llvm2cpp/CppWriter.cpp b/llvm/tools/llvm2cpp/CppWriter.cpp index 1076b59c0211..a5aa7d46e3c6 100644 --- a/llvm/tools/llvm2cpp/CppWriter.cpp +++ b/llvm/tools/llvm2cpp/CppWriter.cpp @@ -1435,9 +1435,14 @@ void CppWriter::printFunctionUses(const Function* F) { for (unsigned i = 0; i < I->getNumOperands(); ++i) { Value* operand = I->getOperand(i); printType(operand->getType()); - if (GlobalValue* GV = dyn_cast(operand)) + + // If the operand references a GVal or Constant, make a note of it + if (GlobalValue* GV = dyn_cast(operand)) { gvs.push_back(GV); - else if (Constant* C = dyn_cast(operand)) + if (GlobalVariable *GVar = dyn_cast(GV)) + if (GVar->hasInitializer()) + consts.push_back(GVar->getInitializer()); + } else if (Constant* C = dyn_cast(operand)) consts.push_back(C); } }