diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index dbbd4a16248d..6b23dd669119 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -245,13 +245,10 @@ static bool checkUInt32Argument(Sema &S, const AttributeList &Attr, /// declaration. Returns true if diagnosed. template 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()) { + const AttributeList &Attr) { + if (AttrTy *A = D->getAttr()) { 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, Decl *D, const AttributeList &Attr) { } static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (checkAttrMutualExclusion(S, D, Attr, "hot")) + if (checkAttrMutualExclusion(S, D, Attr)) return; D->addAttr(::new (S.Context) ColdAttr(Attr.getRange(), S.Context, @@ -1436,7 +1433,7 @@ static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) { } static void handleHotAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (checkAttrMutualExclusion(S, D, Attr, "cold")) + if (checkAttrMutualExclusion(S, D, Attr)) return; D->addAttr(::new (S.Context) HotAttr(Attr.getRange(), S.Context, @@ -3562,8 +3559,7 @@ static void handleObjCRequiresSuperAttr(Sema &S, Decl *D, static void handleCFAuditedTransferAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (checkAttrMutualExclusion(S, D, Attr, - "cf_unknown_transfer")) + if (checkAttrMutualExclusion(S, D, Attr)) return; D->addAttr(::new (S.Context) @@ -3573,8 +3569,7 @@ static void handleCFAuditedTransferAttr(Sema &S, Decl *D, static void handleCFUnknownTransferAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (checkAttrMutualExclusion(S, D, Attr, - "cf_audited_transfer")) + if (checkAttrMutualExclusion(S, D, Attr)) return; D->addAttr(::new (S.Context) diff --git a/clang/test/Sema/attr-coldhot.c b/clang/test/Sema/attr-coldhot.c index 253b1898c0a0..abadf889fc63 100644 --- a/clang/test/Sema/attr-coldhot.c +++ b/clang/test/Sema/attr-coldhot.c @@ -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}}