Michael Welsh Duggan
2012-Jul-02 16:29 UTC
[LLVMdev] Intrinsic::getDeclaration causing dump() segfault
In the following scrap of code (pared down from actually useful code), the func->dump() command segfaults iff the commented-out line is uncommented. This is with llvm 3.0. I'm only dipping my toes into the waters of llvm for the first time, and have no idea what I am doing incorrectly. In actual code, I would be wanting to call the memcpy intrinsic eventually, of course. int main(void) { Module *module = new Module("testmod", getGlobalContext()); FunctionType *ft = FunctionType::get( Type::getInt1Ty(getGlobalContext()), false); Function *func = Function::Create(ft, Function::ExternalLinkage, "", module); BasicBlock *bb = BasicBlock::Create(getGlobalContext(), "entry", func); builder.SetInsertPoint(bb); builder.CreateRet(ConstantInt::getTrue(getGlobalContext())); // Value *memcpy = Intrinsic::getDeclaration( // module, Intrinsic::memcpy, Type::getInt64Ty(getGlobalContext())); func->dump(); delete module; return 0; } -- Michael Welsh Duggan (md5i at md5i.com)
Duncan Sands
2012-Jul-02 18:03 UTC
[LLVMdev] Intrinsic::getDeclaration causing dump() segfault
Hi Michael, when developing with LLVM you should always build LLVM with assertions enabled, as then you get informative messages rather than mysterious crashes. Ciao, Duncan.> In the following scrap of code (pared down from actually useful code), > the func->dump() command segfaults iff the commented-out line is > uncommented. This is with llvm 3.0. I'm only dipping my toes into the > waters of llvm for the first time, and have no idea what I am doing > incorrectly. In actual code, I would be wanting to call the memcpy > intrinsic eventually, of course. > > int main(void) > { > Module *module = new Module("testmod", getGlobalContext()); > FunctionType *ft = FunctionType::get( > Type::getInt1Ty(getGlobalContext()), false); > Function *func = Function::Create(ft, Function::ExternalLinkage, > "", module); > BasicBlock *bb = BasicBlock::Create(getGlobalContext(), "entry", func); > builder.SetInsertPoint(bb); > builder.CreateRet(ConstantInt::getTrue(getGlobalContext())); > // Value *memcpy = Intrinsic::getDeclaration( > // module, Intrinsic::memcpy, Type::getInt64Ty(getGlobalContext())); > > func->dump(); > > delete module; > > return 0; > } > >