[LLVMdev] Defining/Accessing Structs Dynamically
eli.friedman at gmail.com
Thu Jun 11 20:13:47 PDT 2009
On Thu, Jun 11, 2009 at 7:51 PM, Nyx<mcheva at cs.mcgill.ca> wrote:
> 1. I'm not sure exactly how to return a structure on the stack. Right now,
> I'm allocating one with alloca, but it seems I can only return a pointer to
> it, not the structure itself. Is there any way to dereference the pointer?
You should be able to do it with the load instruction.
> 2. On the calling side, I get a structure as a return value. However, it
> seems GEP is complaining (I get an assertion failure) that I can't do GEP on
> a structure object that isn't a pointer. How do I get a pointer to this
> return value?
The extractvalue instruction.
> Right now, as a potential solution, I'm actually considering allocating the
> structure on the calling side and passing a pointer to it instead, but
> perhaps there's a better way to go about this.
If you need to interface with C code, this is the only reliable way to do it.
More information about the llvm-dev