<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 18, 2015 at 8:56 AM, 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"><div dir="ltr"><br><div>Nice catch!  LGTM.   BTW, I'm surprised it has taken so long for this bug to manifest, since we should have lots of code with multiple </div><div>late parsed attributes.  When did it show up?</div></div></blockquote><div><br></div><div>It caused an assert to fire, which doesn't show up for release Clang builds.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div><div class="h5"><div class="gmail_quote">On Tue, Mar 17, 2015 at 8:12 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi delesley,<br>
<br>
Fix for PR22931, assertion failure with attributes and templates.<br>
<br>
When cloning a scope, the constructor of LocalInstantiationScope will set the current scope in Sema to be that new scope.  However, cloning scopes doesn't change what the current scope should be.  This manifests when multiple late parsed attributed are used.  The first attribute has a properly cloned scope, but the other attributes get the wrong scope.  The assertion in PR22931 is triggered when a Decl is looked up within an incorrect scope and is not found.<br>
<br>
<a href="http://reviews.llvm.org/D8407" target="_blank">http://reviews.llvm.org/D8407</a><br>
<br>
Files:<br>
  include/clang/Sema/Template.h<br>
  test/SemaCXX/warn-thread-safety-negative.cpp<br>
<br>
Index: include/clang/Sema/Template.h<br>
===================================================================<br>
--- include/clang/Sema/Template.h<br>
+++ include/clang/Sema/Template.h<br>
@@ -273,6 +273,11 @@<br>
     /// outermost scope.<br>
     LocalInstantiationScope *cloneScopes(LocalInstantiationScope *Outermost) {<br>
       if (this == Outermost) return this;<br>
+<br>
+      // Save the current scope from SemaRef since the LocalInstantiationScope<br>
+      // will overwrite it on construction<br>
+      LocalInstantiationScope *oldScope = SemaRef.CurrentInstantiationScope;<br>
+<br>
       LocalInstantiationScope *newScope =<br>
         new LocalInstantiationScope(SemaRef, CombineWithOuterScope);<br>
<br>
@@ -299,6 +304,8 @@<br>
           newScope->ArgumentPacks.push_back(NewPack);<br>
         }<br>
       }<br>
+      // Restore the saved scope to SemaRef<br>
+      SemaRef.CurrentInstantiationScope = oldScope;<br>
       return newScope;<br>
     }<br>
<br>
Index: test/SemaCXX/warn-thread-safety-negative.cpp<br>
===================================================================<br>
--- test/SemaCXX/warn-thread-safety-negative.cpp<br>
+++ test/SemaCXX/warn-thread-safety-negative.cpp<br>
@@ -102,3 +102,20 @@<br>
 };<br>
<br>
 }  // end namespace SimpleTest<br>
+<br>
+namespace DoubleAttribute {<br>
+<br>
+struct Foo {<br>
+  Mutex &mutex();<br>
+};<br>
+<br>
+template <typename A><br>
+class TemplateClass {<br>
+  template <typename B><br>
+  static void Function(Foo *F)<br>
+      EXCLUSIVE_LOCKS_REQUIRED(F->mutex()) UNLOCK_FUNCTION(F->mutex()) {}<br>
+};<br>
+<br>
+void test() { TemplateClass<int> TC; }<br>
+<br>
+}  // end namespace DoubleAttribute<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>DeLesley Hutchins | Software Engineer | <a href="mailto:delesley@google.com" target="_blank">delesley@google.com</a> | <a href="tel:505-206-0315" value="+15052060315" target="_blank">505-206-0315</a><br></div>
</font></span></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>