<div class="gmail_quote">On Mon, Aug 20, 2012 at 2:32 PM, DeLesley Hutchins <span dir="ltr"><<a href="mailto:delesley@google.com" target="_blank">delesley@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: delesley<br>
Date: Mon Aug 20 16:32:18 2012<br>
New Revision: 162229<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=162229&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=162229&view=rev</a><br>
Log:<br>
Thread-safety analysis: fix scoping issues related to 'this', including an<br>
ICE in friend functions.<br>
<br>
Modified:<br>
cfe/trunk/lib/Parse/ParseDecl.cpp<br>
cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=162229&r1=162228&r2=162229&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=162229&r1=162228&r2=162229&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Aug 20 16:32:18 2012<br>
@@ -851,10 +851,6 @@<br>
Actions.ActOnStartDelayedMemberDeclarations(getCurScope(),<br>
Class.TagOrTemplate);<br>
if (!Class.LateParsedDeclarations.empty()) {<br>
- // Allow 'this' within late-parsed attributes.<br>
- Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate,<br>
- /*TypeQuals=*/0);<br>
-<br>
for (unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i){<br>
Class.LateParsedDeclarations[i]->ParseLexedAttributes();<br>
}<br>
@@ -904,34 +900,43 @@<br>
ParsedAttributes Attrs(AttrFactory);<br>
SourceLocation endLoc;<br>
<br>
- if (LA.Decls.size() == 1) {<br>
+ if (LA.Decls.size() > 0) {<br>
Decl *D = LA.Decls[0];<br>
+ NamedDecl *ND = dyn_cast<NamedDecl>(D);<br>
+ RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext());<br>
<br>
- // If the Decl is templatized, add template parameters to scope.<br>
- bool HasTemplateScope = EnterScope && D->isTemplateDecl();<br>
- ParseScope TempScope(this, Scope::TemplateParamScope, HasTemplateScope);<br>
- if (HasTemplateScope)<br>
- Actions.ActOnReenterTemplateScope(Actions.CurScope, D);<br>
-<br>
- // If the Decl is on a function, add function parameters to the scope.<br>
- bool HasFunctionScope = EnterScope && D->isFunctionOrFunctionTemplate();<br>
- ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope, HasFunctionScope);<br>
- if (HasFunctionScope)<br>
- Actions.ActOnReenterFunctionContext(Actions.CurScope, D);<br>
-<br>
- ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc);<br>
-<br>
- if (HasFunctionScope) {<br>
- Actions.ActOnExitFunctionContext();<br>
- FnScope.Exit(); // Pop scope, and remove Decls from IdResolver<br>
- }<br>
- if (HasTemplateScope) {<br>
- TempScope.Exit();<br>
- }<br>
- } else if (LA.Decls.size() > 0) {<br>
- // If there are multiple decls, then the decl cannot be within the<br>
- // function scope.<br>
- ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc);<br>
+ // Allow 'this' within late-parsed attributes.<br>
+ Sema::CXXThisScopeRAII ThisScope(Actions, RD,<br>
+ /*TypeQuals=*/0,<br></blockquote><div><br></div><div>I don't know whether you care about this for the thread safety annotations, but I believe you're now in a position where you can get the type qualifiers "right" -- if the attribute is attached to a CXXMethodDecl, you can use the cv-qualifiers specified on that function declaration in the type of 'this'.</div>
</div>