[llvm-dev] llvm extract struct elements and struct size in C++

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Mar 28 18:37:39 PDT 2016


On 28 March 2016 at 13:34, Shehbaz Jaffer via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I want to create a database of all structures (global and local)
> defined and being used in my program. Eg. < A , <int32, int32> , B ,
> <int32, bool , char *>>.

I think the closest LLVM has is either
Module::getIdentifiedStructTypes or the class it actually uses:
"TypeFinder". Beware though, struct types may not have a name, and
even if they do it won't necessarily correspond to the original C or
C++ name in any meaningful way.

These both return an std::vector<StructType *> in some form, which you
can probe for the fields (they'll definitely be unnamed).

The other detail that's not obvious is that it looks like TypeFinder
probes nested structs, without requiring an explicit use of that
subtype within the modules. E.g. it would return [{i32, {i32}}, {i32}]
for something trivial like:

    define {i32, {i32}} @foo() { ret {i32, {i32}} undef }

Cheers

Tim.


More information about the llvm-dev mailing list