[cfe-dev] Getting past error: member access into incomplete type

Eric Schulte eric.schulte at gmx.com
Tue Sep 4 12:39:01 PDT 2012


Manuel Klimek <klimek at google.com> writes:

> On Sun, Sep 2, 2012 at 10:51 PM, Eric Schulte <eric.schulte at gmx.com> wrote:
>> Matthieu Monrocq <matthieu.monrocq at gmail.com> writes:
>>
>>> On Sun, Sep 2, 2012 at 8:04 AM, James Dennett <james.dennett at gmail.com>wrote:
>>>
>>>> On Sat, Sep 1, 2012 at 6:14 PM, Eric Schulte <eric.schulte at gmx.com> wrote:
>>>> > Hi,
>>>> >
>>>> > I'm working on a small AST-manipulation tool built upon clang [1].  I
>>>> > had an implementation which worked but didn't deal well with included
>>>> > headings.  I've since re-written this using the Tooling interface,
>>>> > however using the example code from [2] I run into the following "member
>>>> > access into incomplete type" error on an ASTContext [3].
>>>> >
>>>> > It looks like I could solve this error by stepping back to previous
>>>> > versions of clang and llvm [4], but I'd prefer to fix this so that it
>>>> > works with the current code and moving forward.  The broken file is at,
>>>> > https://github.com/eschulte/clang-mutate/blob/master/mutate-tool.cpp
>>>> >
>>>> > Any suggestions would be greatly appreciated.
>>>>
>>>> If I'm reading this correctly, your code just needs to #include the
>>>> definition of the ASTContext class (from
>>>> include/clang/AST/ASTContext.h) in order to refer to a member of
>>>> ASTContext (e.g., "Context.getTranslationUnitDecl()").
>>>>
>>>> -- James
>>>>
>>>>
>>> I agree with James.
>>>
>>> There has been refactoring on the headers in the AST and Sema (I think) to
>>> move from direct inclusion to forward declaration which probably broke a
>>> few clients that relied on the inclusions being done for them. Normally if
>>> you would just make the inclusion yourself now, it should work as before.
>>>
>>> -- Matthieu
>>
>> Thanks,
>>
>> Having added the ASTContext include directive (and copied some linking
>> behavior from tools distributed with clang) I'm now compiling
>> successfully.
>>
>> However it seems that some more work will be required to inform clang's
>> search for included files.  When running on a simple hello world example
>> file which includes stdio.h, clang tools run without problem, e.g.,
>>
>>     $ clang hello.c
>>     $ clang-check hello.c
>>     Processing: /home/eschulte/src/clang-mutate/hello.c.
>>
>> however my tool (using the Tooling interface) results in the following.
>>
>>     $ ./clang-mutate n hello.c
>>     numbering
>>     Processing: /home/eschulte/src/clang-mutate/hello.c.
>>     In file included from /home/eschulte/src/clang-mutate/hello.c:1:
>>     /usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found
>>     # include <stddef.h>
>>               ^
>>     Stack dump:
>>     0.      <eof> parser at end of file
>>     zsh: segmentation fault  ./clang-mutate n hello.c
>>
>> Any ideas what could be going wrong here?  FWIW all of this code is
>> available at https://github.com/eschulte/clang-mutate, and the above
>> error can be demonstrated by running "make check".
>
> The tool needs to find the builtin include directory.
>
> See http://clang.llvm.org/docs/LibTooling.html#builtin
>

So since this tool uses LibTooling I can just copy the executable to
$(dirname $(which clang)) and the includes will be handled for me.

After pulling the ASTMutation logic out into it's own class, and
figuring out how to call a rewriting recursive AST visitor from a
FrontendActionFactory, everything is now working as hoped for.

Thanks all for your help.

-- 
Eric Schulte
http://cs.unm.edu/~eschulte



More information about the cfe-dev mailing list