diff options
author | DeLesley Hutchins <delesley@google.com> | 2013-05-17 23:02:59 +0000 |
---|---|---|
committer | DeLesley Hutchins <delesley@google.com> | 2013-05-17 23:02:59 +0000 |
commit | b68243177556fab5e0c5fee88a5767bda83f8eb5 (patch) | |
tree | 2fa383fadd81024a13bf7bd45e258f0cca34ec95 /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | f5bb53f19f342b9cfd88aaa9c0aa4f5785b60461 (diff) | |
download | bcm5719-llvm-b68243177556fab5e0c5fee88a5767bda83f8eb5.tar.gz bcm5719-llvm-b68243177556fab5e0c5fee88a5767bda83f8eb5.zip |
Thread safety analysis: add two new attributes to the thread safety analysis:
assert_exclusive_lock and assert_shared_lock. These attributes are used to
mark functions that dynamically check (i.e. assert) that a lock is held.
llvm-svn: 182170
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d9b8e160610..c365bfc508c 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -788,6 +788,34 @@ static void handleExclusiveLockFunctionAttr(Sema &S, Decl *D, Attr.getAttributeSpellingListIndex())); } +static void handleAssertSharedLockAttr(Sema &S, Decl *D, + const AttributeList &Attr) { + SmallVector<Expr*, 1> Args; + if (!checkLockFunAttrCommon(S, D, Attr, Args)) + return; + + unsigned Size = Args.size(); + Expr **StartArg = Size == 0 ? 0 : &Args[0]; + D->addAttr(::new (S.Context) + AssertSharedLockAttr(Attr.getRange(), S.Context, StartArg, Size, + Attr.getAttributeSpellingListIndex())); +} + +static void handleAssertExclusiveLockAttr(Sema &S, Decl *D, + const AttributeList &Attr) { + SmallVector<Expr*, 1> Args; + if (!checkLockFunAttrCommon(S, D, Attr, Args)) + return; + + unsigned Size = Args.size(); + Expr **StartArg = Size == 0 ? 0 : &Args[0]; + D->addAttr(::new (S.Context) + AssertExclusiveLockAttr(Attr.getRange(), S.Context, + StartArg, Size, + Attr.getAttributeSpellingListIndex())); +} + + static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVector<Expr*, 2> &Args) { @@ -4918,6 +4946,12 @@ static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D, break; // Thread safety attributes: + case AttributeList::AT_AssertExclusiveLock: + handleAssertExclusiveLockAttr(S, D, Attr); + break; + case AttributeList::AT_AssertSharedLock: + handleAssertSharedLockAttr(S, D, Attr); + break; case AttributeList::AT_GuardedVar: handleGuardedVarAttr(S, D, Attr); break; |