[LLVMdev] Code crashing in CreateGlobalStringPtr, passes when I add code for main routine + entry

Nick Lewycky nicholas at mxc.ca
Sun Jan 22 20:05:34 PST 2012


Arpan Sen wrote:
> Hi All,
>
> The following crashes in CreateGlobalStringPtr:
> #include "llvm/Support/DataTypes.h"
> #include "llvm/LLVMContext.h"
> #include "llvm/Module.h"
> #include "llvm/Constants.h"
> #include "llvm/Function.h"
> #include "llvm/BasicBlock.h"
> #include "llvm/ExecutionEngine/ExecutionEngine.h"
> #include "llvm/ExecutionEngine/GenericValue.h"
> #include "llvm/Support/IRBuilder.h"
>
> #include <vector>
> #include <cstdio>
> #include <string>
>
> int main()
> {
>    llvm::LLVMContext & context = llvm::getGlobalContext();
>    llvm::Module *module = new llvm::Module("asdf", context);
>    llvm::IRBuilder<> builder(context);
>    llvm::Value *helloWorld = builder.CreateGlobalStringPtr("hello
> world!\n"); // crash here

The IRBuilder doesn't know what Module you're trying to create the 
string in, and ends up dereferencing a null pointer.

(Did your build have assertions enabled? I haven't checked whether 
there's an assert for this, but there ought to be!)

Nick



More information about the llvm-dev mailing list