[llvm-dev] How do set 'nest' addribute in an indirect call?

Rodney M. Bates via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 17 15:15:31 PDT 2017


I need to set the 'next' attribute on a parameter.  If the function is to be
directly called, i.e., a function constant, I am getting what I want as follows
(using the C 'Core.h' binding)

1) Build a function type, using LLVMFunctionType.
2) Build a function value, passing the result of 1) to LLVMAddFunction
3) Go through the formal parameters of 2), using LLVMGet[First|Next]Param,
    which give me a value for each formal
4) For the desired formal, pass it to LLVMAddAttribute.

This results in compiled code that passes my parameter in the same way as gcc,
giving the interoperability I need.

For an indirect call, i.e., on a function whose address is runtime variable,
I can't find any place/way to attach this attribute.  LLVMAddAttribute
won't take a type.

I don't see a way to construct a function value with a runtime variable
address, that I could do 3) & 4) on.  (I already have an i8* pointer to
the function code.)

The comment on LLVMAddAttribute says  " Add an attribute to a function argument",
which, to me, "argument" means an actual parameter.  But When I try that, I get
an assertion failure, which I am having trouble interpreting:

m3llvm: /home/rodney/proj/llvm/llvm-3.6.1/llvm-3.6.1.src/include/llvm/Support/Casting.h:237: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = llvm::Argument, Y = llvm::Value]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

My actual parameter is a load instruction, which I would expect to be a value.
Its llvm type is i8*, but I don't think that is relevant.

Here are some relevant debugger lines:

(m3gdb) frame 7
#7  0x00000000004264fd in M3CG_LLVM__InnerCallIndirect (self=16_0000000001b30830, proc=16_0000000001a7e388, t=Void,
     cc=16_0000000001b07928, Nested=TRUE) at ../src/M3CG_LLVM.m3:4750
4750	          LLVM.LLVMAddAttribute(actual.lVal, LLVM.NestAttribute);
Current language:  auto; currently Modula-3
(m3gdb) p M3CG_LLVM__DumpLvVal(actual.lVal)
   %load_ind13 = load i8** %load_ind_toptr12
$1 = <void>
(m3gdb) p M3CG_LLVM__LvType(actual.lVal)
$2 = 16_0000000001a78620
(m3gdb) p M3CG_LLVM__DumpLvType($2)
i8*
$3 = <void>
(m3gdb)


-- 
Rodney Bates
rodney.m.bates at acm.org


More information about the llvm-dev mailing list