let Args = [FunctionArgument<"FunctionDecl">];
}
+def Cold : InheritableAttr {
+ let Spellings = ["cold"];
+}
+
def Common : InheritableAttr {
let Spellings = ["common"];
}
let Spellings = ["gnu_inline"];
}
+def Hot : InheritableAttr {
+ let Spellings = ["hot"];
+}
+
def IBAction : InheritableAttr {
let Spellings = ["ibaction"];
}
Str->getString()));
}
+static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+ // Check the attribute arguments.
+ if (!checkAttributeNumArgs(S, Attr, 0))
+ return;
+
+ if (!isa<FunctionDecl>(D)) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << Attr.getName() << ExpectedFunction;
+ return;
+ }
+
+ if (D->hasAttr<HotAttr>()) {
+ S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
+ << Attr.getName() << "hot";
+ return;
+ }
+
+ D->addAttr(::new (S.Context) ColdAttr(Attr.getRange(), S.Context));
+}
+
+static void handleHotAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+ // Check the attribute arguments.
+ if (!checkAttributeNumArgs(S, Attr, 0))
+ return;
+
+ if (!isa<FunctionDecl>(D)) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << Attr.getName() << ExpectedFunction;
+ return;
+ }
+
+ if (D->hasAttr<ColdAttr>()) {
+ S.Diag(Attr.getLoc(), diag::err_attributes_are_not_compatible)
+ << Attr.getName() << "cold";
+ return;
+ }
+
+ D->addAttr(::new (S.Context) HotAttr(Attr.getRange(), S.Context));
+}
+
static void handleNakedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
// Check the attribute arguments.
if (!checkAttributeNumArgs(S, Attr, 0))
case AttributeList::AT_ownership_takes:
case AttributeList::AT_ownership_holds:
handleOwnershipAttr (S, D, Attr); break;
+ case AttributeList::AT_cold: handleColdAttr (S, D, Attr); break;
+ case AttributeList::AT_hot: handleHotAttr (S, D, Attr); break;
case AttributeList::AT_naked: handleNakedAttr (S, D, Attr); break;
case AttributeList::AT_noreturn: handleNoReturnAttr (S, D, Attr); break;
case AttributeList::AT_nothrow: handleNothrowAttr (S, D, Attr); break;
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int foo() __attribute__((__hot__));
+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}}