From f92377d79bdc150609fd39c255d5aebade7fc3e0 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Wed, 18 Mar 2015 21:52:47 +0000 Subject: [PATCH] When cloning LocalInstantiationScope's, don't update the current scope in Sema. Construction of LocalInstantiationScope automatically updates the current scope inside Sema. However, when cloning a scope, the current scope does not change. Change the cloning function to preserve the current scope. Review: http://reviews.llvm.org/D8407 BUG: https://llvm.org/bugs/show_bug.cgi?id=22931 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232675 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Template.h | 7 +++++++ test/SemaCXX/warn-thread-safety-negative.cpp | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/clang/Sema/Template.h b/include/clang/Sema/Template.h index 6c34e5862f..b822b11126 100644 --- a/include/clang/Sema/Template.h +++ b/include/clang/Sema/Template.h @@ -273,6 +273,11 @@ namespace clang { /// 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 @@ namespace clang { newScope->ArgumentPacks.push_back(NewPack); } } + // Restore the saved scope to SemaRef + SemaRef.CurrentInstantiationScope = oldScope; return newScope; } diff --git a/test/SemaCXX/warn-thread-safety-negative.cpp b/test/SemaCXX/warn-thread-safety-negative.cpp index f88233a60b..f831010293 100644 --- a/test/SemaCXX/warn-thread-safety-negative.cpp +++ b/test/SemaCXX/warn-thread-safety-negative.cpp @@ -102,3 +102,20 @@ public: }; } // end namespace SimpleTest + +namespace DoubleAttribute { + +struct Foo { + Mutex &mutex(); +}; + +template +class TemplateClass { + template + static void Function(Foo *F) + EXCLUSIVE_LOCKS_REQUIRED(F->mutex()) UNLOCK_FUNCTION(F->mutex()) {} +}; + +void test() { TemplateClass TC; } + +} // end namespace DoubleAttribute -- 2.40.0