Add attribute always_inline support.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58304 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h
index 8b0f79f..0a9ceb0 100644
--- a/include/clang/AST/Attr.h
+++ b/include/clang/AST/Attr.h
@@ -27,6 +27,7 @@
enum Kind {
Alias,
Aligned,
+ AlwaysInline,
Annotate,
AsmLabel, // Represent GCC asm label extension.
Constructor,
@@ -140,6 +141,16 @@
static bool classof(const AsmLabelAttr *A) { return true; }
};
+class AlwaysInlineAttr : public Attr {
+public:
+ AlwaysInlineAttr() : Attr(AlwaysInline) {}
+
+ // Implement isa/cast/dyncast/etc.
+
+ static bool classof(const Attr *A) { return A->getKind() == AlwaysInline; }
+ static bool classof(const AlwaysInlineAttr *A) { return true; }
+};
+
class AliasAttr : public Attr {
std::string Aliasee;
public:
diff --git a/include/clang/Parse/AttributeList.h b/include/clang/Parse/AttributeList.h
index d41faa3..9c73aa01 100644
--- a/include/clang/Parse/AttributeList.h
+++ b/include/clang/Parse/AttributeList.h
@@ -45,6 +45,7 @@
AT_address_space,
AT_alias,
AT_aligned,
+ AT_always_inline,
AT_annotate,
AT_constructor,
AT_deprecated,
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index a1cd6f1..aaca21b 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -274,6 +274,9 @@
if (!Features.Exceptions)
F->addFnAttr(llvm::Attribute::NoUnwind);
+
+ if (D->getAttr<AlwaysInlineAttr>())
+ F->addFnAttr(llvm::Attribute::AlwaysInline);
}
void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD,
diff --git a/lib/Parse/AttributeList.cpp b/lib/Parse/AttributeList.cpp
index 825570d..342c87f 100644
--- a/lib/Parse/AttributeList.cpp
+++ b/lib/Parse/AttributeList.cpp
@@ -97,6 +97,7 @@
break;
case 13:
if (!memcmp(Str, "address_space", 13)) return AT_address_space;
+ if (!memcmp(Str, "always_inline", 13)) return AT_always_inline;
break;
case 15:
if (!memcmp(Str, "ext_vector_type", 15)) return AT_ext_vector_type;
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 41fe4ed..e1afd6d 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -396,6 +396,18 @@
d->addAttr(new AliasAttr(std::string(Alias, AliasLen)));
}
+static void HandleAlwaysInlineAttr(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,
+ std::string("0"));
+ return;
+ }
+
+ d->addAttr(new AlwaysInlineAttr());
+}
+
static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() != 0) {
@@ -1121,6 +1133,8 @@
break;
case AttributeList::AT_alias: HandleAliasAttr (D, Attr, S); break;
case AttributeList::AT_aligned: HandleAlignedAttr (D, Attr, S); break;
+ case AttributeList::AT_always_inline:
+ HandleAlwaysInlineAttr (D, Attr, S); break;
case AttributeList::AT_annotate: HandleAnnotateAttr (D, Attr, S); break;
case AttributeList::AT_constructor: HandleConstructorAttr(D, Attr, S); break;
case AttributeList::AT_deprecated: HandleDeprecatedAttr(D, Attr, S); break;
diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c
index 1ee855d..c09b2af 100644
--- a/test/CodeGen/function-attributes.c
+++ b/test/CodeGen/function-attributes.c
@@ -6,7 +6,8 @@
// RUN: grep 'define signext i16 @f4(i32 %x) nounwind' %t &&
// RUN: grep 'define zeroext i16 @f5(i32 %x) nounwind' %t &&
// RUN: grep 'define void @f6(i16 signext %x) nounwind' %t &&
-// RUN: grep 'define void @f7(i16 zeroext %x) nounwind' %t
+// RUN: grep 'define void @f7(i16 zeroext %x) nounwind' %t &&
+// RUN: grep 'define void @f8() nounwind alwaysinline' %t
signed char f0(int x) { return x; }
@@ -24,3 +25,4 @@
void f7(unsigned short x) { }
+void __attribute__((always_inline)) f8(void) { }