[cfe-dev] Shadowed local variables

Peter Jacobsen jacobsen.peter at gmail.com
Tue Aug 20 04:32:09 PDT 2013


 Hi,

Referring to the code below, as I climb the Clang AST, when I arrive at the
DeclRefExpr refering to x on the lhs of the assignment x=2, how do I detect
that it is the block scope x, rather than the function scope x?

void f()
{
  int x;
  x=1;
  {
    int x;
    x=2;
  }
  gx=x;
}

I need unique identifiers for the each x, so my symbolic execution
calculates the correct value for gx. Currently I am calling getDecl() and
then getQualifiedNameAsString().  I have tried calling getDeclContext, but
in references to both xs, I get a CXXMethod as the context.
Presumably I could use the value of the pointer returned by getDecl(), but
this doesn’t feel right.

Any help much appreciated.

Thanks,
Peter




--
View this message in context: http://clang-developers.42468.n3.nabble.com/Shadowed-local-variables-tp4033981.html
Sent from the Clang Developers mailing list archive at Nabble.com.




More information about the cfe-dev mailing list