r196105 - Replacing custom subject application logic with table-generated logic. Affects: guarded_var, pt_guarded_var, guarded_by, pt_guarded_by, acquired_after and acquired_before. No functional change intended.
Aaron Ballman
aaron at aaronballman.com
Mon Dec 2 07:02:49 PST 2013
Author: aaronballman
Date: Mon Dec 2 09:02:49 2013
New Revision: 196105
URL: http://llvm.org/viewvc/llvm-project?rev=196105&view=rev
Log:
Replacing custom subject application logic with table-generated logic. Affects: guarded_var, pt_guarded_var, guarded_by, pt_guarded_by, acquired_after and acquired_before. No functional change intended.
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=196105&r1=196104&r2=196105&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Dec 2 09:02:49 2013
@@ -46,6 +46,9 @@ def Struct : SubsetSubject<Record,
def TLSVar : SubsetSubject<Var,
[{S->getTLSKind() != 0}]>;
+def SharedVar : SubsetSubject<Var,
+ [{S->hasGlobalStorage() && !S->getTLSKind()}]>;
+
// A single argument to an attribute
class Argument<string name, bit optional> {
string Name = name;
@@ -910,12 +913,14 @@ def NoSanitizeMemory : InheritableAttr {
def GuardedVar : InheritableAttr {
let Spellings = [GNU<"guarded_var">];
- let Subjects = SubjectList<[Field, Var]>;
+ let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
+ "ExpectedFieldOrGlobalVar">;
}
def PtGuardedVar : InheritableAttr {
let Spellings = [GNU<"pt_guarded_var">];
- let Subjects = SubjectList<[Field, Var]>;
+ let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
+ "ExpectedFieldOrGlobalVar">;
}
def Lockable : InheritableAttr {
@@ -938,7 +943,8 @@ def GuardedBy : InheritableAttr {
let Args = [ExprArgument<"Arg">];
let LateParsed = 1;
let TemplateDependent = 1;
- let Subjects = SubjectList<[Field, Var]>;
+ let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
+ "ExpectedFieldOrGlobalVar">;
}
def PtGuardedBy : InheritableAttr {
@@ -946,7 +952,8 @@ def PtGuardedBy : InheritableAttr {
let Args = [ExprArgument<"Arg">];
let LateParsed = 1;
let TemplateDependent = 1;
- let Subjects = SubjectList<[Field, Var]>;
+ let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
+ "ExpectedFieldOrGlobalVar">;
}
def AcquiredAfter : InheritableAttr {
@@ -954,7 +961,8 @@ def AcquiredAfter : InheritableAttr {
let Args = [VariadicExprArgument<"Args">];
let LateParsed = 1;
let TemplateDependent = 1;
- let Subjects = SubjectList<[Field, Var]>;
+ let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
+ "ExpectedFieldOrGlobalVar">;
}
def AcquiredBefore : InheritableAttr {
@@ -962,7 +970,8 @@ def AcquiredBefore : InheritableAttr {
let Args = [VariadicExprArgument<"Args">];
let LateParsed = 1;
let TemplateDependent = 1;
- let Subjects = SubjectList<[Field, Var]>;
+ let Subjects = SubjectList<[Field, SharedVar], WarnDiag,
+ "ExpectedFieldOrGlobalVar">;
}
def ExclusiveLockFunction : InheritableAttr {
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=196105&r1=196104&r2=196105&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Dec 2 09:02:49 2013
@@ -337,17 +337,6 @@ static void handleSimpleAttribute(Sema &
Attr.getAttributeSpellingListIndex()));
}
-///
-/// \brief Check if passed in Decl is a field or potentially shared global var
-/// \return true if the Decl is a field or potentially shared global variable
-///
-static bool mayBeSharedVariable(const Decl *D) {
- if (const VarDecl *vd = dyn_cast<VarDecl>(D))
- return vd->hasGlobalStorage() && !vd->getTLSKind();
-
- return true;
-}
-
/// \brief Check if the passed-in expression is of type int or bool.
static bool isIntOrBool(Expr *Exp) {
QualType QT = Exp->getType();
@@ -543,32 +532,8 @@ static void checkAttrArgsAreLockableObjs
// least add some helper functions to check most argument patterns (#
// and types of args).
-static bool checkGuardedVarAttrCommon(Sema &S, Decl *D,
- const AttributeList &Attr) {
- // D must be either a member field or global (potentially shared) variable.
- if (!mayBeSharedVariable(D)) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
- << Attr.getName() << ExpectedFieldOrGlobalVar;
- return false;
- }
-
- return true;
-}
-
-static void handleGuardedVarAttr(Sema &S, Decl *D, const AttributeList &Attr) {
- if (!checkGuardedVarAttrCommon(S, D, Attr))
- return;
-
- D->addAttr(::new (S.Context)
- GuardedVarAttr(Attr.getRange(), S.Context,
- Attr.getAttributeSpellingListIndex()));
-}
-
static void handlePtGuardedVarAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
- if (!checkGuardedVarAttrCommon(S, D, Attr))
- return;
-
if (!threadSafetyCheckIsPointer(S, D, Attr))
return;
@@ -580,13 +545,6 @@ static void handlePtGuardedVarAttr(Sema
static bool checkGuardedByAttrCommon(Sema &S, Decl *D,
const AttributeList &Attr,
Expr* &Arg) {
- // D must be either a member field or global (potentially shared) variable.
- if (!mayBeSharedVariable(D)) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
- << Attr.getName() << ExpectedFieldOrGlobalVar;
- return false;
- }
-
SmallVector<Expr*, 1> Args;
// check that all arguments are lockable objects
checkAttrArgsAreLockableObjs(S, D, Attr, Args);
@@ -626,16 +584,8 @@ static bool checkAcquireOrderAttrCommon(
if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
return false;
- // D must be either a member field or global (potentially shared) variable.
- ValueDecl *VD = dyn_cast<ValueDecl>(D);
- if (!VD || !mayBeSharedVariable(D)) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
- << Attr.getName() << ExpectedFieldOrGlobalVar;
- return false;
- }
-
// Check that this attribute only applies to lockable types.
- QualType QT = VD->getType();
+ QualType QT = cast<ValueDecl>(D)->getType();
if (!QT->isDependentType()) {
const RecordType *RT = getRecordType(QT);
if (!RT || !RT->getDecl()->getAttr<LockableAttr>()) {
@@ -4302,8 +4252,7 @@ static void ProcessDeclAttribute(Sema &S
handleAssertSharedLockAttr(S, D, Attr);
break;
case AttributeList::AT_GuardedVar:
- handleGuardedVarAttr(S, D, Attr);
- break;
+ handleSimpleAttribute<GuardedVarAttr>(S, D, Attr); break;
case AttributeList::AT_PtGuardedVar:
handlePtGuardedVarAttr(S, D, Attr);
break;
More information about the cfe-commits
mailing list