diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/AST/Attr.h | 11 | ||||
-rw-r--r-- | clang/include/clang/Parse/AttributeList.h | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Parse/AttributeList.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 14 | ||||
-rw-r--r-- | clang/test/CodeGen/function-attributes.c | 4 |
6 files changed, 33 insertions, 1 deletions
diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h index 8b0f79fbbce..0a9ceb0666d 100644 --- a/clang/include/clang/AST/Attr.h +++ b/clang/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/clang/include/clang/Parse/AttributeList.h b/clang/include/clang/Parse/AttributeList.h index d41faa31b07..9c73aa013e0 100644 --- a/clang/include/clang/Parse/AttributeList.h +++ b/clang/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/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index a1cd6f1e6ca..aaca21bab33 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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<AlwaysInlineAttr>()) + F->addFnAttr(llvm::Attribute::AlwaysInline); } void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD, diff --git a/clang/lib/Parse/AttributeList.cpp b/clang/lib/Parse/AttributeList.cpp index 825570dce2e..342c87f1fe2 100644 --- a/clang/lib/Parse/AttributeList.cpp +++ b/clang/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/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 41fe4ed0442..e1afd6d924f 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/CodeGen/function-attributes.c b/clang/test/CodeGen/function-attributes.c index 1ee855dbc1b..c09b2af9f40 100644 --- a/clang/test/CodeGen/function-attributes.c +++ b/clang/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) { } |