Hello, I'm writing a pass that adds a function prototype to the module during doInitialization() and stores the pointer in a global variable. If I run opt with "-O1" or less, everything works fine. However, If I call opt with "-O2" or "-O3" then as soon as runOnFunction() is called, the pointer seems to be NULL. Here is a code that shows the problem: namespace { struct InitTest : public FunctionPass { Constant *someF; public: static char ID; // Pass identification, replacement for typeid InitTest() : FunctionPass(&ID) {} virtual bool doInitialization(Module &mdl) { someF = mdl.getOrInsertFunction("test", /* return type */ Type::VoidTy, /* actual 1 type */ IntegerType::get(32), NULL); if( !someF ){ cerr << "### Error: someF is NULL ###" << std::endl; } return true; } virtual bool runOnFunction(Function &func) { if( !someF ){ cerr << "--- Error: someF is NULL ---" << std::endl; } return false; } }; } char InitTest::ID = 0; static RegisterPass<InitTest> IT("inittest", "Initialization Testing Pass"); and here is the output of some runs: $ opt -load Test.so -inittest < test.bc > /dev/null --- Success --- $ opt -O1 -load Test.so -inittest < test.bc > /dev/null --- Success --- $ opt -O2 -load Test.so -inittest < test.bc > /dev/null --- Error: someF is NULL --- $ opt -O3 -load Test.so -inittest < test.bc > /dev/null --- Error: someF is NULL --- Is this normal? What can I do to preserve my "test" function prototype? thanks, Anthony
oops, I copy pasted a code older than my output. Here is the correct snippet: virtual bool runOnFunction(Function &func) { if( !someF ){ cerr << "--- Error: someF is NULL ---" << std::endl; }else{ cerr << "--- Success ---" << std::endl; } return false; } On Mar 11, 2009, at 3:03 PM, Anthony Danalis wrote:> Hello, > > I'm writing a pass that adds a function prototype to the module during > doInitialization() and stores the pointer in a global variable. If I > run opt with "-O1" or less, everything works fine. However, If I call > opt with "-O2" or "-O3" then as soon as runOnFunction() is called, the > pointer seems to be NULL. Here is a code that shows the problem: > > namespace { > struct InitTest : public FunctionPass { > Constant *someF; > public: > static char ID; // Pass identification, replacement for typeid > InitTest() : FunctionPass(&ID) {} > > virtual bool doInitialization(Module &mdl) { > someF = mdl.getOrInsertFunction("test", > /* return type */ Type::VoidTy, > /* actual 1 type */ IntegerType::get(32), > NULL); > if( !someF ){ > cerr << "### Error: someF is NULL ###" << std::endl; > } > return true; > } > > virtual bool runOnFunction(Function &func) { > if( !someF ){ > cerr << "--- Error: someF is NULL ---" << std::endl; > } > return false; > } > }; > } > > char InitTest::ID = 0; > static RegisterPass<InitTest> IT("inittest", "Initialization Testing > Pass"); > > > and here is the output of some runs: > > $ opt -load Test.so -inittest < test.bc > /dev/null > --- Success --- > $ opt -O1 -load Test.so -inittest < test.bc > /dev/null > --- Success --- > $ opt -O2 -load Test.so -inittest < test.bc > /dev/null > --- Error: someF is NULL --- > $ opt -O3 -load Test.so -inittest < test.bc > /dev/null > --- Error: someF is NULL --- > > > Is this normal? What can I do to preserve my "test" function > prototype? > > thanks, > Anthony > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Anthony Danalis wrote:> Hello, > > I'm writing a pass that adds a function prototype to the module during > doInitialization() and stores the pointer in a global variable. If I > run opt with "-O1" or less, everything works fine. However, If I call > opt with "-O2" or "-O3" then as soon as runOnFunction() is called, the > pointer seems to be NULL. Here is a code that shows the problem:That sounds like the same bug as llvm.org/PR3520 , which was fixed after the 2.5 release. Can you confirm which version of LLVM you're seeing this in, and if it is 2.5, could you update to SVN head and see whether it still happens for you? Nick
I was using 2.4, but I built 2.5 and it behaves the same. I will test the SVN head too. On Mar 11, 2009, at 10:41 PM, Nick Lewycky wrote:> Anthony Danalis wrote: >> Hello, >> >> I'm writing a pass that adds a function prototype to the module >> during >> doInitialization() and stores the pointer in a global variable. If I >> run opt with "-O1" or less, everything works fine. However, If I >> call >> opt with "-O2" or "-O3" then as soon as runOnFunction() is called, >> the >> pointer seems to be NULL. Here is a code that shows the problem: > > That sounds like the same bug as llvm.org/PR3520 , which was fixed > after > the 2.5 release. Can you confirm which version of LLVM you're seeing > this in, and if it is 2.5, could you update to SVN head and see > whether > it still happens for you? > > Nick > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev