[LLVMdev] static constant structs

Michael Welsh Duggan md5i at md5i.com
Mon Jul 23 07:24:47 PDT 2012


I hope this is the correct forum in which to ask this question.

Currently I am writing code meant to compile with LLVM 3.0.  I am trying
to figure out, using the C++ API, how to create a constant static
struct, or the equivalent.  Since I am copying data from existing C
structs, I am currently I am using a ConstantArray global variable, and
then pointer casting it to the appropriate type when I use it, but this
seems overly clunky.

    Constant *cip = ConstantArray::get(
        ctx(), StringRef((char *)&addr_, sizeof(addr_)), false);
    return new GlobalVariable(
        *mod(), cip->getType(), true,
        GlobalVariable::PrivateLinkage, cip);

In a previous version of my code, I replaced cip->getType() with the
llvm equivalent of the type of addr_.  This worked until I tried with a
build of llvm that had assertions turned on.  Even without that, I am
hoping there is a better way to do this that I have managed to overlook.

-- 
Michael Welsh Duggan
(md5i at md5i.com)




More information about the llvm-dev mailing list