[cfe-dev] Return type of statement

Alexei Svitkine alexei.svitkine at gmail.com
Tue Jan 6 12:36:50 PST 2009


Thanks for info.

I'm now getting a crash in getAsString() on the Expr's type:

if (clang::Expr *E = dyn_cast<clang::Expr>(S)) {
  std::cout << "Type: '" << E->getType().getAsString() << "'\n";
}

GDB prints:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xc000000f
0x00072d8a in clang::QualType::getAsStringInternal (this=0xbffff758,
S=@0xbffff754) at Type.cpp:894
894	  getTypePtr()->getAsStringInternal(S);
(gdb) bt
#0  0x00072d8a in clang::QualType::getAsStringInternal
(this=0xbffff758, S=@0xbffff754) at Type.cpp:894
#1  0x000050a8 in clang::QualType::getAsString (this=0xbffff758) at Type.h:168

Am I doing something wrong, or is this a bug I stumbled upon?

Also, is there some better way to ask questions I encounter, rather
than emailing each one? Like some kind of irc chat? (I joined #llvm
but there didn't seem to be any clang discussion going on there...)

Or is bombarding this list with questions the way to go? :P

-Alexei

On Mon, Jan 5, 2009 at 11:21 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Jan 5, 2009, at 6:31 PM, Alexei Svitkine wrote:
>
>> Thanks for the pointers.
>>
>> What's the best way to map from a location in the source to the
>> corresponding Stmt (and hence Expr if it is exists)?
>
> There isn't an efficient way to do it.  You'd have to walk the whole
> function body and look at the source ranges that each stmt covers, stopping
> at the smallest one that covers the point of interest.  You could do this
> once and build a location -> stmt mapping of course.  This would be useful
> if you do repeated queries (such as having a mouse float over code etc).
>
> -Chris
>



More information about the cfe-dev mailing list