<div dir="ltr">With the following AST visitor:<div><br></div><div><div>bool VisitFieldDecl( FieldDecl * f )</div><div>{</div><div>   RecordDecl * r = f->getParent() ;</div><div>   const QualType & theMembersClassType = m_context.getRecordType( r ) ;</div>
<div><br></div><div>   TypeSourceInfo * pThisFieldSourceInfo = f->getTypeSourceInfo() ;</div><div><br></div><div>   TypeLoc thisFieldTypeLoc = pThisFieldSourceInfo->getTypeLoc() ;</div><div><br></div><div>   const QualType & thisFieldQualType = thisFieldTypeLoc.getType() ;</div>
<div><br></div><div>   size_t szInBits = m_context.getTypeSize( thisFieldQualType ) ;</div><div>   size_t offsetInBits = m_context.getFieldOffset( f ) ;</div><div><br></div><div>   cout</div><div>      << "[" << offsetInBits/8 << "]:\t"</div>
<div>      << theMembersClassType.getAsString( m_pp ) << "::" << thisFieldQualType.getAsString( m_pp ) << "\t" << f->getNameAsString()</div><div>      << "\tsize: " << szInBits/8 << endl ;</div>
<div>      ;</div><div><br></div><div>   return true ;</div><div>}</div><div><br></div><div><br></div><div style>I'm able to dump the sizeof and offsetof the members of a my C++ structures.  I have trouble with input like so:<br>
<br><div>#include <signal.h></div><div><br></div><div>struct signalDisposition</div><div>{</div><div>   struct sigaction sigact ;</div><div>   int signum ;</div><div>} ;</div><div style><br></div><div style>getting the following assert:<br>
<br><div>(gdb) run asample8.cpp</div><div>Starting program: /home/hotellnx94/peeterj/.physicsplay/rewriter/memberdumper asample8.cpp</div><div>Failed to read a valid object file image from memory.</div><div>[Thread debugging using libthread_db enabled]</div>
<div>asample8.cpp:1:10: fatal error: 'signal.h' file not found</div><div>#include <signal.h></div><div>         ^</div><div>memberdumper: /home/hotellnx94/peeterj/clang/sources/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2470: const clang::ASTRecordLayout& clang::ASTContext::getASTRecordLayout(const clang::RecordDecl*) const: Assertion `D && "Cannot get layout of forward declarations!"' failed.</div>
<div><br></div><div>Program received signal SIGABRT, Aborted.</div><div>0x00002aaaab39ef45 in raise () from /lib64/libc.so.6</div><div>(gdb) where</div><div>#0  0x00002aaaab39ef45 in raise () from /lib64/libc.so.6</div><div>
#1  0x00002aaaab3a0340 in abort () from /lib64/libc.so.6</div><div>#2  0x00002aaaab398486 in __assert_fail () from /lib64/libc.so.6</div><div>#3  0x0000000000b29c80 in clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const ()</div>
<div>#4  0x0000000000a34f99 in clang::ASTContext::getTypeInfoImpl(clang::Type const*) const ()</div><div>#5  0x0000000000a32892 in clang::ASTContext::getTypeInfo(clang::Type const*) const ()</div><div>#6  0x0000000000a348b9 in clang::ASTContext::getTypeInfoImpl(clang::Type const*) const ()</div>
<div>#7  0x0000000000a32892 in clang::ASTContext::getTypeInfo(clang::Type const*) const ()</div><div>#8  0x000000000046409d in clang::ASTContext::getTypeInfo (this=0x1366ff0, T=...)</div><div>    at /home/hotellnx94/peeterj/clang/optimized48rt/include/clang/AST/ASTContext.h:1489</div>
<div>#9  0x0000000000464022 in clang::ASTContext::getTypeSize (this=0x1366ff0, T=...)</div><div>    at /home/hotellnx94/peeterj/clang/optimized48rt/include/clang/AST/ASTContext.h:1494</div><div>#10 0x0000000000463e6a in MyASTVisitor::VisitFieldDecl (this=0x7fffffffc3b8, f=0x136f390) at ./memberdumper.h:68</div>
<div><br></div><br>I understand the root cause for the assert: I've been unable to coerse my AST visitor into properly setting up the paths for my system headers. That appears to be a difficult problem.  I've had some advise in the past from this list on how to do so, that I've been able to use with only partial success.</div>
<div style><br></div><div style>For now, I'd just like to skip such an incomplete type.  How could I code a check that the type of the FieldDecl is complete so that I don't hit the forward reference assert above?</div>
</div><div><br></div>-- <br>Peeter
</div></div>