[LLVMdev] How to get a pointer to a constant struct?
Callum Rogers
callum.rogers at keble.ox.ac.uk
Mon Apr 8 18:43:48 PDT 2013
Hi,
I'm trying to create a constant (named) struct and store a pointer to it
in another struct using the C Api (and the llvm-fs bindings). As a
contrived example, this is what I want to do:
%A = type { %VTable* }
%VTable = type { void (%A*)*, void (%A*)* }
define void @main(%A* %a) {
entry:
%0 = getelementptr inbounds %A* %a, i32 0, i32 0 ; [type=%VTable**]
%2 = somehow make a pointer to: { void(%A*)* null, void (%A*)* @main }
store %VTable* %2, %VTable** %1
ret void
}
How would I do the "somehow make a pointer to" part? I currently make
the constant named struct by using LLVMConstNamedStruct(passing in
%VTable, [null, @main]) and have tried using LLVMConstGEP with [0] as
the indices on this but both times I get an assertion error saying:
"Assertion failed: getOperand(0)->getType() ==
cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr
must be a pointer to Val type!", file I
nstructions.cpp, line 1056"
Cheers,
Callum Rogers
(I am using LLVM 3.1 btw)
More information about the llvm-dev
mailing list