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

Shehbaz Jaffer via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 29 08:42:41 PDT 2016


Thank you,

This information was very useful.

On Mon, Mar 28, 2016 at 9:37 PM, Tim Northover <t.p.northover at gmail.com> wrote:
> 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.



-- 
Shehbaz Jaffer
First Year Graduate Student
Sir Edward S Rogers Sr Department of Electrical and Computer Engineering
University of Toronto


More information about the llvm-dev mailing list