[llvm-dev] Problems with GEP and CallInst

Lorenzo Laneve via llvm-dev llvm-dev at lists.llvm.org
Sun Apr 17 05:52:14 PDT 2016

I got a little problems with strings (const char pointers). Global variables holding the string literal are declared correctly, but i have a problem when I pass this string to a function: it asserts with this message.

Assertion failed: ((i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"), function init, file llvm-3.8.0.src/lib/IR/Instructions.cpp, line 245.

Function declaration in the IR:
; Function Attrs: nounwind ssp uwtable
declare i32 @_wrts(i8*) #0

All the types match (even if the assertion condition makes me think they shouldn’t), am I doing something wrong with GEP?
here’s the code that translates the AST Literal into LLVM IR and creates the GEP (the return value will be passed to the Callee):

llvm::Value *ast::StringLiteral::build(llvmir_builder *builder) {
    TypeRef *strtype = evalType();
    TypeRef *chrtype = strtype->getType()->getPointedType();
    llvm::ArrayType *arty = llvm::ArrayType::get(chrtype->getIRType(), val.length()+1);
    if (!strcst) {
        strcst = new llvm::GlobalVariable(*container,
                                          llvm::ConstantDataArray::getString(container->getContext(), val.c_str()),
    return builder->CreateInBoundsGEP(arty, strcst, llvm::ConstantInt::get(llvm::Type::getInt8Ty(container->getContext()), 0));

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160417/f5a4df11/attachment.html>

More information about the llvm-dev mailing list