IDAClang parses type with missing field

Hi. I am using IDAClang to parse a templated class and it looks like it compiles successfully but misses a field in one of the structures. On 9.0.240925. I’ve got a minimal reproduceable case here:

template <typename T>
class TemplateTest
{
    struct SubStruct
    {
        T subval1;
    };
    
    SubStruct *s_Dummy;
};

volatile TemplateTest<int> asd;

Like I said this compiles fine but TemplateTest::SubStruct is empty and missing subval1, attached.

AST output is like so:

IDACLANG: template     C:\dev\bilbo\test.txt:1 kind=ClassTemplate(31) name=TemplateTest type=(0) sizeof=-1
IDACLANG: var          C:\dev\bilbo\test.txt:12 kind=VarDecl(9) name=asd type=volatile TemplateTest<int>(119) sizeof=0x8
IDACLANG: class        C:\dev\bilbo\test.txt:1 kind=ClassDecl(4) name=TemplateTest type=TemplateTest<int>(105) sizeof=0x8 definition=1 align=8 (required=0 packed=0 packalign=0) vptr=0
IDACLANG: field        C:\dev\bilbo\test.txt:9 kind=FieldDecl(6) name=s_Dummy type=SubStruct *(101) sizeof=0x8 offset=0x0 fda=0 packed=0
IDACLANG: struct       C:\dev\bilbo\test.txt:4 kind=StructDecl(2) name=SubStruct type=TemplateTest<int>::SubStruct(105) sizeof=-2 definition=0 align=-2 (required=0 packed=0 packalign=0)
IDACLANG: attribute    C:\dev\bilbo\test.txt:9 kind=TypeRef(43) name=struct TemplateTest<int>::SubStruct type=TemplateTest<int>::SubStruct(105) sizeof=-2
C:\dev\test.txt: successfully compiled

I’ve also tried to pass a few flags to no avail:

-g -O0 -fno-eliminate-unused-debug-types -fstandalone-debug -fno-discard-value-names -fdelayed-template-parsing

I’m not sure if this is a bug or if I’m missing something. Would appreciate some assistance please. Thanks.

It seems because the SubStruct is not instantiated but only used by pointer, just the forward declaration is added. Try adding an explicit instantiation of TemplateTest<int>::SubStruct, hopefully it will work.

That works, but if I may ask, is this the intended behavior of IDAClang? In my case, I am parsing a series of header files with structures much more complex than my example. I would have to go in and declare that for every class declaration in this library. Which I can do but alas it’s a bit tedious :slight_smile:

that’s a good question and I think it’s not exactly intentional but “just happened” when we were adding the clang parser. In C, there is no need to explicitly declare used types if they’re used only by pointer, and if they happen to be declared fully later, that declaration replaces the incomplete forward declaration. We will add a ticket to investigate the feasibility of automatic instantiation of such types, but in either case it won’t happen soon so you’ll have to do it the hard way for now.

1 Like