I'm getting a strange behaviour when I attempt to create my main function: auto func = static_cast<llvm::Function*>(module->getOrInsertFunction( "main", types->type_void(), (llvm::Type*)0 ) ); ASSERT( func ); auto block = llvm::BasicBlock::Create( *context, "entry", func ); The "BasicBlock::Create" function is causing a segfault. This only happens if the function is called "main", any other function and it works fine. Prior to this call I also do this assert to ensure "main" doesn't actually exist: ASSERT( !module->getFunction("main" ) ); I must be missing something trivial, but I'm not sure what. -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130410/a22408fd/attachment.sig>
Got it. I had a global_variable also with the name "main". Perhaps getOrInsertFuntion needs an assert to check this (it was returning a variable I guess rather than a function, and thus static_cast was broken). On 10/04/13 20:15, edA-qa mort-ora-y wrote:> I'm getting a strange behaviour when I attempt to create my main function: > > > auto func = static_cast<llvm::Function*>(module->getOrInsertFunction( > "main", > types->type_void(), (llvm::Type*)0 ) ); > ASSERT( func ); > auto block = llvm::BasicBlock::Create( *context, "entry", func ); > > The "BasicBlock::Create" function is causing a segfault. This only > happens if the function is called "main", any other function and it > works fine. Prior to this call I also do this assert to ensure "main" > doesn't actually exist: > ASSERT( !module->getFunction("main" ) ); > > I must be missing something trivial, but I'm not sure what. > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130410/8261b7d9/attachment.sig>
Hi, On 10/04/13 20:23, edA-qa mort-ora-y wrote:> Got it. I had a global_variable also with the name "main". Perhaps > getOrInsertFuntion needs an assert to check this (it was returning a > variable I guess rather than a function, and thus static_cast was broken).if you use LLVM's cast rather than static_cast then you will get an assertion failure if the cast is wrong. Ciao, Duncan.> > On 10/04/13 20:15, edA-qa mort-ora-y wrote: >> I'm getting a strange behaviour when I attempt to create my main function: >> >> >> auto func = static_cast<llvm::Function*>(module->getOrInsertFunction( >> "main", >> types->type_void(), (llvm::Type*)0 ) ); >> ASSERT( func ); >> auto block = llvm::BasicBlock::Create( *context, "entry", func ); >> >> The "BasicBlock::Create" function is causing a segfault. This only >> happens if the function is called "main", any other function and it >> works fine. Prior to this call I also do this assert to ensure "main" >> doesn't actually exist: >> ASSERT( !module->getFunction("main" ) ); >> >> I must be missing something trivial, but I'm not sure what. >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >