summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-02-19 19:16:48 +0000
committerAnders Carlsson <andersca@mac.com>2009-02-19 19:16:48 +0000
commit880971241bc86b5027c4a19abedd1aadb9a700ed (patch)
treedfda4d43a5a1bb4626afce05ff42e2224f3bc631 /clang
parent193cbdcbe362dd6c5433a6b16c8bc07c3b146968 (diff)
downloadbcm5719-llvm-880971241bc86b5027c4a19abedd1aadb9a700ed.tar.gz
bcm5719-llvm-880971241bc86b5027c4a19abedd1aadb9a700ed.zip
Add sema support for the noinline attribute.
llvm-svn: 65055
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/Attr.h17
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp25
-rw-r--r--clang/test/Sema/attr-noinline.c8
3 files changed, 46 insertions, 4 deletions
diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index b2c5c23a4f6..e814c5c7197 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -58,7 +58,8 @@ public:
Const,
Pure,
Cleanup,
- Nodebug
+ Nodebug,
+ Noinline
};
private:
@@ -499,7 +500,7 @@ public:
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Nodebug; }
- static bool classof(const DeprecatedAttr *A) { return true; }
+ static bool classof(const NodebugAttr *A) { return true; }
};
class WarnUnusedResultAttr : public Attr {
@@ -510,7 +511,17 @@ public:
static bool classof(const Attr *A) { return A->getKind() == WarnUnusedResult;}
static bool classof(const WarnUnusedResultAttr *A) { return true; }
};
-
+
+class NoinlineAttr : public Attr {
+public:
+ NoinlineAttr() : Attr(Noinline) {}
+
+ // Implement isa/cast/dyncast/etc.
+
+ static bool classof(const Attr *A) { return A->getKind() == Noinline; }
+ static bool classof(const NoinlineAttr *A) { return true; }
+};
+
} // end namespace clang
#endif
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 614e53a751a..2ceea33d07d 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -395,6 +395,12 @@ static void HandleAlwaysInlineAttr(Decl *d, const AttributeList &Attr,
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return;
}
+
+ if (!isFunctionOrMethod(d)) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << "always_inline" << 0 /*function*/;
+ return;
+ }
d->addAttr(new AlwaysInlineAttr());
}
@@ -1343,7 +1349,7 @@ static void HandleNodebugAttr(Decl *d, const AttributeList &Attr, Sema &S) {
return;
}
- if (!isa<FunctionDecl>(d)) {
+ if (!isFunctionOrMethod(d)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< "nodebug" << 0 /*function*/;
return;
@@ -1352,6 +1358,22 @@ static void HandleNodebugAttr(Decl *d, const AttributeList &Attr, Sema &S) {
d->addAttr(new NodebugAttr());
}
+static void HandleNoinlineAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+ // check the attribute arguments.
+ if (Attr.getNumArgs() != 0) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ return;
+ }
+
+ if (!isFunctionOrMethod(d)) {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
+ << "noinline" << 0 /*function*/;
+ return;
+ }
+
+ d->addAttr(new NoinlineAttr());
+}
+
//===----------------------------------------------------------------------===//
// Top Level Sema Entry Points
//===----------------------------------------------------------------------===//
@@ -1410,6 +1432,7 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) {
case AttributeList::AT_pure: HandlePureAttr (D, Attr, S); break;
case AttributeList::AT_cleanup: HandleCleanupAttr (D, Attr, S); break;
case AttributeList::AT_nodebug: HandleNodebugAttr (D, Attr, S); break;
+ case AttributeList::AT_noinline: HandleNoinlineAttr (D, Attr, S); break;
case AttributeList::IgnoredAttribute:
// Just ignore
break;
diff --git a/clang/test/Sema/attr-noinline.c b/clang/test/Sema/attr-noinline.c
new file mode 100644
index 00000000000..2d1c0f00d47
--- /dev/null
+++ b/clang/test/Sema/attr-noinline.c
@@ -0,0 +1,8 @@
+// RUN: clang %s -verify -fsyntax-only
+
+int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to function types}}
+
+void t1() __attribute__((noinline));
+
+void t2() __attribute__((noinline(2))); // expected-error {{attribute requires 0 argument(s)}}
+
OpenPOWER on IntegriCloud