[PATCH] PR22931 - When cloning scopes, reset the scope in Sema instead of using the cloned scope as the current scope

Richard Trieu rtrieu at google.com
Tue Mar 17 20:12:15 PDT 2015


Hi delesley,

Fix for PR22931, assertion failure with attributes and templates.

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.

http://reviews.llvm.org/D8407

Files:
  include/clang/Sema/Template.h
  test/SemaCXX/warn-thread-safety-negative.cpp

Index: include/clang/Sema/Template.h
===================================================================
--- include/clang/Sema/Template.h
+++ include/clang/Sema/Template.h
@@ -273,6 +273,11 @@
     /// outermost scope.
     LocalInstantiationScope *cloneScopes(LocalInstantiationScope *Outermost) {
       if (this == Outermost) return this;
+
+      // Save the current scope from SemaRef since the LocalInstantiationScope
+      // will overwrite it on construction
+      LocalInstantiationScope *oldScope = SemaRef.CurrentInstantiationScope;
+
       LocalInstantiationScope *newScope =
         new LocalInstantiationScope(SemaRef, CombineWithOuterScope);
 
@@ -299,6 +304,8 @@
           newScope->ArgumentPacks.push_back(NewPack);
         }
       }
+      // Restore the saved scope to SemaRef
+      SemaRef.CurrentInstantiationScope = oldScope;
       return newScope;
     }
 
Index: test/SemaCXX/warn-thread-safety-negative.cpp
===================================================================
--- test/SemaCXX/warn-thread-safety-negative.cpp
+++ test/SemaCXX/warn-thread-safety-negative.cpp
@@ -102,3 +102,20 @@
 };
 
 }  // end namespace SimpleTest
+
+namespace DoubleAttribute {
+
+struct Foo {
+  Mutex &mutex();
+};
+
+template <typename A>
+class TemplateClass {
+  template <typename B>
+  static void Function(Foo *F)
+      EXCLUSIVE_LOCKS_REQUIRED(F->mutex()) UNLOCK_FUNCTION(F->mutex()) {}
+};
+
+void test() { TemplateClass<int> TC; }
+
+}  // end namespace DoubleAttribute

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8407.22153.patch
Type: text/x-patch
Size: 1502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150318/bf2dfb90/attachment.bin>


More information about the cfe-commits mailing list