[cfe-dev] Type>>isObjCInterfaceType() blows up

Emerson Murphy-Hill emerson at apple.com
Tue Apr 22 16:17:34 PDT 2008


Solution:
I was using ASTParser.cpp, which allocated an ASTContext on the stack:

   ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
                      PP.getIdentifierTable(), PP.getSelectorTable());

When I returned from the method, the ASTContext gets destroyed, after  
which I wasn't getting valid types.  Changed the line in ASTParser to  
allocate the ASTContext on the heap:

   ASTContext* Context = new ASTContext(PP.getSourceManager(),  
PP.getTargetInfo(),
                      PP.getIdentifierTable(), PP.getSelectorTable());

And isObjCInterfaceType works as expected. Thanks to Ted, Chris, and  
Steve for helping me out with this.

-e

On Apr 18, 2008, at 10:55 AM, Chris Lattner wrote:

>
> On Apr 18, 2008, at 10:52 AM, Emerson Murphy-Hill wrote:
>
>> Ahoy!
>>
>> I'm trying to determine the SourceLocation of an Objective-C  
>> instance variable's type, if there is one.  This seemed like a  
>> reasonable way to start:
>>
>>     clang::ObjCIvarDecl* iVar = ... //your ivar here...
>>     clang::Type* t = iVar->getType().getTypePtr();
>>     t->isObjCInterfaceType();
>>
>> Unfortunately, I get an EXC_BAD_ACCESS on the final line.  For the  
>> test case I'm working on, I would have expected it to simply return  
>> false, since my ivar is an int.
>>
> What does iVar->getType().dump()  print?
>
> Does 'iVar->getType()->isObjCInterfaceType()' work?
>
> -Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080422/2c358f91/attachment.html>


More information about the cfe-dev mailing list