]> granicus.if.org Git - clang/commitdiff
Add attribute always_inline support.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 28 Oct 2008 00:17:57 +0000 (00:17 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 28 Oct 2008 00:17:57 +0000 (00:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58304 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
include/clang/Parse/AttributeList.h
lib/CodeGen/CodeGenModule.cpp
lib/Parse/AttributeList.cpp
lib/Sema/SemaDeclAttr.cpp
test/CodeGen/function-attributes.c

index 8b0f79fbbce7ab4adfb54c65d099dc0c369e06b1..0a9ceb0666d62024c13a71af9bba5d884f795166 100644 (file)
@@ -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:
index d41faa31b07b65a05bc32b75deb935776f78da67..9c73aa013e008360984931b98a49bc171c3565e5 100644 (file)
@@ -45,6 +45,7 @@ public:
     AT_address_space,
     AT_alias,
     AT_aligned,
+    AT_always_inline,
     AT_annotate,
     AT_constructor,
     AT_deprecated,
index a1cd6f1e6ca4ed4d671f0760327f4b19de0e3f16..aaca21bab33bb3b6fd73634e5e8c7643dec52da2 100644 (file)
@@ -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,
index 825570dce2e1a9502c8ff8d6b0fa150c6f35e0dc..342c87f1fe25572094392c2907aa80daaf9cd442 100644 (file)
@@ -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;
index 41fe4ed044279c7fe5faa3bc2dbdd97cc0ee08fb..e1afd6d924f23a90ce443060b6f5a97a01c8d883 100644 (file)
@@ -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;
index 1ee855dbc1be05f4a430df2a890cbc9aa7a9685b..c09b2af9f40f74a4916c9f244647163891797356 100644 (file)
@@ -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) { }