From af668b0e7d3581dea3b4f29a9262686e83887e5b Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 28 Oct 2008 00:17:57 +0000 Subject: [PATCH] Add attribute always_inline support. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58304 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Attr.h | 11 +++++++++++ include/clang/Parse/AttributeList.h | 1 + lib/CodeGen/CodeGenModule.cpp | 3 +++ lib/Parse/AttributeList.cpp | 1 + lib/Sema/SemaDeclAttr.cpp | 14 ++++++++++++++ test/CodeGen/function-attributes.c | 4 +++- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 8b0f79fbbc..0a9ceb0666 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -27,6 +27,7 @@ public: enum Kind { Alias, Aligned, + AlwaysInline, Annotate, AsmLabel, // Represent GCC asm label extension. Constructor, @@ -140,6 +141,16 @@ public: 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 d41faa31b0..9c73aa013e 100644 --- a/include/clang/Parse/AttributeList.h +++ b/include/clang/Parse/AttributeList.h @@ -45,6 +45,7 @@ public: 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 a1cd6f1e6c..aaca21bab3 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -274,6 +274,9 @@ void CodeGenModule::SetFunctionAttributesForDefinition(const Decl *D, if (!Features.Exceptions) F->addFnAttr(llvm::Attribute::NoUnwind); + + if (D->getAttr()) + F->addFnAttr(llvm::Attribute::AlwaysInline); } void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD, diff --git a/lib/Parse/AttributeList.cpp b/lib/Parse/AttributeList.cpp index 825570dce2..342c87f1fe 100644 --- a/lib/Parse/AttributeList.cpp +++ b/lib/Parse/AttributeList.cpp @@ -97,6 +97,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { 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 41fe4ed044..e1afd6d924 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -396,6 +396,18 @@ static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) { 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 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) { 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 1ee855dbc1..c09b2af9f4 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 f6(signed short x) { } void f7(unsigned short x) { } +void __attribute__((always_inline)) f8(void) { } -- 2.40.0