You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to use BuildCall2 to call the printf function, I'm encountering an assertion error related to type mismatch in variadic arguments. The error occurs specifically when passing an integer value as a variadic argument to printf.
Error Message
Assertion failed: (i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!", file C:\src\llvm_package_6923b0a7\llvm-project\llvm\lib\IR\Instructions.cpp, line 455
Code Example
Here's a simplified version of my code that reproduces the issue:
publicLLVMValueRefVisitPrintStatement(CodeParser.PrintStatementContextcontext){stringvariableName=context.ID().GetText();if(!_variables.TryGetValue(variableName,outvarvariable)){thrownewException($"Variable {variableName} is not defined.");}// Load integer value from allocated memoryvarvarType=variable.TypeOf.ElementType;varvalue=Builder.BuildLoad2(varType,variable,$"{variableName}_value");// Create format string for printfstringformatStr="%d\n";varformatStrPtr=Builder.BuildGlobalStringPtr(formatStr,"formatStr");// Define printf functionvarprintfType=LLVMTypeRef.CreateFunction(LLVMTypeRef.Int32,[LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8,0)],true);varfunc=GetOrInsertFunction("printf",printfType);// Call printf - this line causes the assertion errorvarcall=Builder.BuildCall2(func.TypeOf,func,[formatStrPtr,value]);returncall;}
Debugging Information
I've examined the types right before the assertion fails:
printfType = {i32 (i8*, ...)}
func = {declare i32 @printf(i8*, ...)}
formatStrPtr = {i8* getelementptr inbounds ([4 x i8], [4 x i8]* @formatStr, i32 0, i32 0)}
args[0] = {i8* getelementptr inbounds ([4 x i8], [4 x i8]* @formatStr, i32 0, i32 0)}
Description
When trying to use
BuildCall2
to call theprintf
function, I'm encountering an assertion error related to type mismatch in variadic arguments. The error occurs specifically when passing an integer value as a variadic argument to printf.Error Message
Code Example
Here's a simplified version of my code that reproduces the issue:
Debugging Information
I've examined the types right before the assertion fails:
printfType = {i32 (i8*, ...)}
func = {declare i32 @printf(i8*, ...)}
formatStrPtr = {i8* getelementptr inbounds ([4 x i8], [4 x i8]* @formatStr, i32 0, i32 0)}
args[0] = {i8* getelementptr inbounds ([4 x i8], [4 x i8]* @formatStr, i32 0, i32 0)}
args[1] = { %value1_value = load i32, i32* %value1, align 4}
Expected Behavior
I expect
BuildCall2
to properly handle variadic functions and their arguments, especially for common use cases likeprintf
with integer arguments.Environment
Any guidance would be greatly appreciated!
The text was updated successfully, but these errors were encountered: