diff options
author | DeLesley Hutchins <delesley@google.com> | 2012-04-06 15:10:17 +0000 |
---|---|---|
committer | DeLesley Hutchins <delesley@google.com> | 2012-04-06 15:10:17 +0000 |
commit | cf2fa2f0c9d67adb98b282ec0eaa88f08df29804 (patch) | |
tree | 1bceca7c2b58a989bb6d6dafb7642895313423c7 | |
parent | 7a521806831b8724364ff714c959b354bbf5a438 (diff) |
Fixed scoping error for late parsed attributes in nested classes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154173 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 17 | ||||
-rw-r--r-- | test/SemaCXX/warn-thread-safety-parsing.cpp | 44 |
4 files changed, 67 insertions, 5 deletions
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index b639332a49..20b4a311cd 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -1378,7 +1378,7 @@ public: /// Push the parameters of D, which must be a function, into scope. void ActOnReenterFunctionContext(Scope* S, Decl* D); - void ActOnExitFunctionContext() { PopDeclContext(); } + void ActOnExitFunctionContext(); DeclContext *getFunctionLevelDeclContext(); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 9216b23d31..b5ce193521 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -735,9 +735,18 @@ void Parser::ParseLexedAttributes(ParsingClass &Class) { ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope); ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope); + // Enter the scope of nested classes + if (!AlreadyHasClassScope) + Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), + Class.TagOrTemplate); + for (unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i) { Class.LateParsedDeclarations[i]->ParseLexedAttributes(); } + + if (!AlreadyHasClassScope) + Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), + Class.TagOrTemplate); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 12b9a63025..f54f0fd942 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -872,7 +872,13 @@ void Sema::ActOnReenterFunctionContext(Scope* S, Decl *D) { if (!FD) return; - PushDeclContext(S, FD); + // Same implementation as PushDeclContext, but enters the context + // from the lexical parent, rather than the top-level class. + assert(CurContext == FD->getLexicalParent() && + "The next DeclContext should be lexically contained in the current one."); + CurContext = FD; + S->setEntity(CurContext); + for (unsigned P = 0, NumParams = FD->getNumParams(); P < NumParams; ++P) { ParmVarDecl *Param = FD->getParamDecl(P); // If the parameter has an identifier, then add it to the scope @@ -884,6 +890,15 @@ void Sema::ActOnReenterFunctionContext(Scope* S, Decl *D) { } +void Sema::ActOnExitFunctionContext() { + // Same implementation as PopDeclContext, but returns to the lexical parent, + // rather than the top-level class. + assert(CurContext && "DeclContext imbalance!"); + CurContext = CurContext->getLexicalParent(); + assert(CurContext && "Popped translation unit!"); +} + + /// \brief Determine whether we allow overloading of the function /// PrevDecl with another declaration. /// diff --git a/test/SemaCXX/warn-thread-safety-parsing.cpp b/test/SemaCXX/warn-thread-safety-parsing.cpp index 2e5106ce8a..19cb63f326 100644 --- a/test/SemaCXX/warn-thread-safety-parsing.cpp +++ b/test/SemaCXX/warn-thread-safety-parsing.cpp @@ -1,9 +1,26 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s +#define LOCKABLE __attribute__ ((lockable)) +#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable)) +#define GUARDED_BY(x) __attribute__ ((guarded_by(x))) +#define GUARDED_VAR __attribute__ ((guarded_var)) +#define PT_GUARDED_BY(x) __attribute__ ((pt_guarded_by(x))) +#define PT_GUARDED_VAR __attribute__ ((pt_guarded_var)) +#define ACQUIRED_AFTER(...) __attribute__ ((acquired_after(__VA_ARGS__))) +#define ACQUIRED_BEFORE(...) __attribute__ ((acquired_before(__VA_ARGS__))) +#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__ ((exclusive_lock_function(__VA_ARGS__))) +#define SHARED_LOCK_FUNCTION(...) __attribute__ ((shared_lock_function(__VA_ARGS__))) +#define EXCLUSIVE_TRYLOCK_FUNCTION(...) __attribute__ ((exclusive_trylock_function(__VA_ARGS__))) +#define SHARED_TRYLOCK_FUNCTION(...) __attribute__ ((shared_trylock_function(__VA_ARGS__))) +#define UNLOCK_FUNCTION(...) __attribute__ ((unlock_function(__VA_ARGS__))) +#define LOCK_RETURNED(x) __attribute__ ((lock_returned(x))) +#define LOCKS_EXCLUDED(...) __attribute__ ((locks_excluded(__VA_ARGS__))) +#define EXCLUSIVE_LOCKS_REQUIRED(...) \ + __attribute__ ((exclusive_locks_required(__VA_ARGS__))) +#define SHARED_LOCKS_REQUIRED(...) \ + __attribute__ ((shared_locks_required(__VA_ARGS__))) +#define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis)) -//-----------------------------------------// -// Helper fields -//-----------------------------------------// class __attribute__((lockable)) Mu { public: @@ -1303,5 +1320,26 @@ private: }; +namespace NestedClassLateDecl { + +class Foo { + class Bar { + int a GUARDED_BY(mu); + int b GUARDED_BY(fooMuStatic); + + void bar() EXCLUSIVE_LOCKS_REQUIRED(mu) { a = 0; } + void bar2(Bar* b) EXCLUSIVE_LOCKS_REQUIRED(b->mu) { b->a = 0; } + void bar3(Foo* f) EXCLUSIVE_LOCKS_REQUIRED(f->fooMu) { f->a = 0; } + + Mu mu; + }; + + int a GUARDED_BY(fooMu); + Mu fooMu; + static Mu fooMuStatic; +}; + +} + } // end namespace TestMultiDecl |