r198424 - Simplifying the mutual exclusion check now that the diagnostics engine knows how to handle Attr objects directly. Updates an associated test case due to the attribute name being properly quoted again.

Aaron Ballman aaron at aaronballman.com
Fri Jan 3 08:23:47 PST 2014


Author: aaronballman
Date: Fri Jan  3 10:23:46 2014
New Revision: 198424

URL: http://llvm.org/viewvc/llvm-project?rev=198424&view=rev
Log:
Simplifying the mutual exclusion check now that the diagnostics engine knows how to handle Attr objects directly. Updates an associated test case due to the attribute name being properly quoted again.

Modified:
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/attr-coldhot.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=198424&r1=198423&r2=198424&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Jan  3 10:23:46 2014
@@ -245,13 +245,10 @@ static bool checkUInt32Argument(Sema &S,
 /// declaration. Returns true if diagnosed.
 template <typename AttrTy>
 static bool checkAttrMutualExclusion(Sema &S, Decl *D,
-                                     const AttributeList &Attr,
-                                     const char *OtherName) {
-  // FIXME: it would be nice if OtherName did not have to be passed in, but was
-  // instead determined based on the AttrTy template parameter.
-  if (D->hasAttr<AttrTy>()) {
+                                     const AttributeList &Attr) {
+  if (AttrTy *A = D->getAttr<AttrTy>()) {
     S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
-      << Attr.getName() << OtherName;
+      << Attr.getName() << A;
     return true;
   }
   return false;
@@ -1428,7 +1425,7 @@ static void handleAliasAttr(Sema &S, Dec
 }
 
 static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (checkAttrMutualExclusion<HotAttr>(S, D, Attr, "hot"))
+  if (checkAttrMutualExclusion<HotAttr>(S, D, Attr))
     return;
 
   D->addAttr(::new (S.Context) ColdAttr(Attr.getRange(), S.Context,
@@ -1436,7 +1433,7 @@ static void handleColdAttr(Sema &S, Decl
 }
 
 static void handleHotAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (checkAttrMutualExclusion<ColdAttr>(S, D, Attr, "cold"))
+  if (checkAttrMutualExclusion<ColdAttr>(S, D, Attr))
     return;
 
   D->addAttr(::new (S.Context) HotAttr(Attr.getRange(), S.Context,
@@ -3562,8 +3559,7 @@ static void handleObjCRequiresSuperAttr(
 
 static void handleCFAuditedTransferAttr(Sema &S, Decl *D,
                                         const AttributeList &Attr) {
-  if (checkAttrMutualExclusion<CFUnknownTransferAttr>(S, D, Attr,
-                                                      "cf_unknown_transfer"))
+  if (checkAttrMutualExclusion<CFUnknownTransferAttr>(S, D, Attr))
     return;
 
   D->addAttr(::new (S.Context)
@@ -3573,8 +3569,7 @@ static void handleCFAuditedTransferAttr(
 
 static void handleCFUnknownTransferAttr(Sema &S, Decl *D,
                                         const AttributeList &Attr) {
-  if (checkAttrMutualExclusion<CFAuditedTransferAttr>(S, D, Attr,
-                                                      "cf_audited_transfer"))
+  if (checkAttrMutualExclusion<CFAuditedTransferAttr>(S, D, Attr))
     return;
 
   D->addAttr(::new (S.Context)

Modified: cfe/trunk/test/Sema/attr-coldhot.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-coldhot.c?rev=198424&r1=198423&r2=198424&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-coldhot.c (original)
+++ cfe/trunk/test/Sema/attr-coldhot.c Fri Jan  3 10:23:46 2014
@@ -6,5 +6,5 @@ int bar() __attribute__((__cold__));
 int var1 __attribute__((__cold__)); // expected-warning{{'__cold__' attribute only applies to functions}}
 int var2 __attribute__((__hot__)); // expected-warning{{'__hot__' attribute only applies to functions}}
 
-int qux() __attribute__((__hot__)) __attribute__((__cold__)); // expected-error{{'__hot__' and cold attributes are not compatible}}
-int baz() __attribute__((__cold__)) __attribute__((__hot__)); // expected-error{{'__cold__' and hot attributes are not compatible}}
+int qux() __attribute__((__hot__)) __attribute__((__cold__)); // expected-error{{'__hot__' and 'cold' attributes are not compatible}}
+int baz() __attribute__((__cold__)) __attribute__((__hot__)); // expected-error{{'__cold__' and 'hot' attributes are not compatible}}





More information about the cfe-commits mailing list