[cfe-dev] Rules for FunctionDecls without bodies

Sean Callanan via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 12 15:07:05 PDT 2017


I am looking at some debug information for the following code:

int main (int argc, char const *argv[])
{
    struct point_tag {
        int x;
        int y;
        char padding[0];
    };
…

LLDB has constructed the struct like this:

(lldb) p ((TagDecl*)0x1102eed78)->dump()
CXXRecordDecl 0x1102eed78 <<invalid sloc>> <invalid sloc> struct point_tag definition
|-FieldDecl 0x1102eeeb8 <<invalid sloc>> <invalid sloc> x 'int'
|-FieldDecl 0x1102eef00 <<invalid sloc>> <invalid sloc> y 'int'
`-FieldDecl 0x1102eef78 <<invalid sloc>> <invalid sloc> padding 'char []'
(lldb) p ((TagDecl*)0x1102eed78)->getContext()
error: no member named 'getContext' in 'clang::TagDecl'
(lldb) p ((TagDecl*)0x1102eed78)->getDeclContext()
(clang::DeclContext *) $22 = 0x00000001102eed10

But the context doesn't have a body.

(lldb) p ((FunctionDecl*)$22)
(clang::FunctionDecl *) $23 = 0x00000001102eecd0
(lldb) p $23->dump()
FunctionDecl 0x1102eecd0 <<invalid sloc>> <invalid sloc> main 'int (int, const char **)' extern
|-ParmVarDecl 0x1102eec10 <<invalid sloc>> <invalid sloc> argc 'int'
`-ParmVarDecl 0x1102eec70 <<invalid sloc>> <invalid sloc> argv 'const char **'
(lldb) p $23->getBody()
(clang::Stmt *) $24 = 0x0000000000000000

Are these legal ASTs?  It seems like with things set up the way they are, point_tag can't be looked up if you only have the FunctionDecl. 

Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170412/d699c513/attachment.html>


More information about the cfe-dev mailing list