<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 26 May 2017 at 09:54, Umesh Kalappa via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All ,<br>
<br>
We added the below code to differentiate Local  and Global Variable in<br>
the "NamedDecl *Sema::HandleDeclarator" function.<br>
<br>
if(S->getFlags() == Scope::DeclScope)<br>
 its global<br>
else<br>
 its local<br>
<br>
Where S  is a pointer parameter to the  HandleDeclarator of type Scope.<br>
<br>
At first place ,we decided  to use<br>
"D.getDeclSpec().<wbr>getStorageClassSpec()" ,but has no luck ,since its<br>
always "SCS_unspecified " .<br>
<br>
Question is that , do using the  "Scope::DeclScope" to differentiate<br>
the variable scope is the  right approach, if so<br>
<br>
we have a problem for some instance like a nested  local declaration,<br>
we are not able to differentiate.<br>
<br>
if the "Scope::DeclScope" is not the right approach, then  please<br>
anybody here , help us with the right approach and would like to<br>
inform you all that, we need this info before any Act call like<br>
"ActOnVariableDeclarator"</blockquote><div><br></div><div>HandleDeclarator computes the DeclContext for the declarator; you can check DC->getRedeclContext()->isFileContext() to find if that's global scope (translation unit or namespace scope, or extern "C" context within them, that kind of thing).</div><div><br></div><div>But that just tells you where the variable was declared, which is not the same as whether it's local or global. You'll also need to check for SCS_extern to handle local extern declarations, and possibly also for SCS_static if you want to treat static local variables as global rather than local. If you also care about C++, you'd also need to decide how you want to handle static class members (for which DC would be a CXXRecordDecl).</div></div></div></div>