[cfe-dev] extern "C" parsing

Jay L. T. Cornwall jay at thefoundry.co.uk
Wed Feb 17 23:25:03 PST 2010


Hi Doug,

>> The clang driver from SVN successfully parses this. My
>> library-based interface to clang, however, gives this error:
>> 
>> test.cpp:5:1: error: unknown type name 'MyStruct'
>> 
>> The presence of an extern "C" {} block appears to hide the type. It
>>  parses correctly without the block. I have set
>> LangOptions::CPlusPlus but have been unable to locate an option
>> which controls this behaviour.

> That's very strange. CPlusPlus is the only option that should matter
> here, because C++ name lookup involves looking into linkage
> specifications.

I tracked this down in the end. With the -fsyntax-only parameter Clang 
parses the program correctly. With -parse-noop it gives the 
aforementioned error.

I believe this is because -parse-noop uses MinimalAction whereas 
-fsyntax-only invokes SyntaxOnlyAction. I traced the program error in 
the former case to MinimalAction::getTypeName failing to acknowledge 
MyStruct as a type name.

> Perhaps we should step back a bit, however: how are you setting up
> your library interface to Clang? Are you using
> CompilerInstance/CompilerInvocation

Initially I had followed this tutorial:

http://amnoid.de/tmp/clangtut/tut.html

This information appears to be quite outdated now. I subsequently 
remodelled our application to Clang to use the 
CompilerInstace/CompilerInvocation interface and this now works.

With Clang successfully parsing a complex C++ file (with many deep Boost 
MPL-based templates and other magic) I now have access to the ASTContext 
to begin porting our semantic analyses. The (speed/memory) performance 
issues we had with ROSE have gone away with Clang. You guys have done 
some nice work!

-- 
Jay L. T. Cornwall, Software Engineer
The Foundry, 1 Wardour Street, London. W1D 6PA
Tel: +44 (0)20 7434 0449, Fax: +44 (0)20 7434 1550, Web:
www.thefoundry.co.uk

The Foundry Visionmongers Ltd • Registered in England and Wales No: 4642027



More information about the cfe-dev mailing list