]> granicus.if.org Git - clang/commitdiff
Diagnose attributes 'optnone' and 'minsize' on the same declaration.
authorPaul Robinson <paul_robinson@playstation.sony.com>
Wed, 10 Dec 2014 23:34:36 +0000 (23:34 +0000)
committerPaul Robinson <paul_robinson@playstation.sony.com>
Wed, 10 Dec 2014 23:34:36 +0000 (23:34 +0000)
Eventually we'll diagnose them on different declarations, but let's
get this part out of the way first.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223985 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/CodeGen/attr-optnone.c
test/SemaCXX/attr-optnone.cpp
test/SemaCXX/pragma-optimize.cpp

index ffb8b77a7d0e34e09225185b51ccf3ce8a084e07..9cace20ee190d22070d52413fa7a67bad5853fbd 100644 (file)
@@ -3146,10 +3146,22 @@ static void handleAlwaysInlineAttr(Sema &S, Decl *D,
                               Attr.getAttributeSpellingListIndex()));
 }
 
+static void handleMinSizeAttr(Sema &S, Decl *D,
+                              const AttributeList &Attr) {
+  if (checkAttrMutualExclusion<OptimizeNoneAttr>(S, D, Attr))
+    return;
+
+  D->addAttr(::new (S.Context)
+             MinSizeAttr(Attr.getRange(), S.Context,
+                         Attr.getAttributeSpellingListIndex()));
+}
+
 static void handleOptimizeNoneAttr(Sema &S, Decl *D,
                                    const AttributeList &Attr) {
   if (checkAttrMutualExclusion<AlwaysInlineAttr>(S, D, Attr))
     return;
+  if (checkAttrMutualExclusion<MinSizeAttr>(S, D, Attr))
+    return;
 
   D->addAttr(::new (S.Context)
              OptimizeNoneAttr(Attr.getRange(), S.Context,
@@ -4340,7 +4352,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
     handleExtVectorTypeAttr(S, scope, D, Attr);
     break;
   case AttributeList::AT_MinSize:
-    handleSimpleAttribute<MinSizeAttr>(S, D, Attr);
+    handleMinSizeAttr(S, D, Attr);
     break;
   case AttributeList::AT_OptimizeNone:
     handleOptimizeNoneAttr(S, D, Attr);
index 2a6e0d1d96f828773ebbc1264f172db6c572c6e2..020218a2f417cb203eacc88495cdc6daf164f231 100644 (file)
@@ -9,7 +9,7 @@ __attribute__((always_inline))
 int test2() { return 0; }
 // OPTSIZE: @test2{{.*}}[[ATTR2:#[0-9]+]]
 
-__attribute__((optnone)) __attribute__((minsize))
+__attribute__((optnone))
 int test3() { return 0; }
 // PRESENT-DAG: @test3{{.*}}[[ATTR3:#[0-9]+]]
 
index eaa50004047c4098de4dc6eab47ad5d8e1d953e2..e2fce8e239425b2d5c2ce8bf289e47e7378e35ec 100644 (file)
@@ -6,6 +6,9 @@ int bar() __attribute__((optnone)) __attribute__((noinline));
 int baz() __attribute__((always_inline)) __attribute__((optnone)); // expected-error{{'always_inline' and 'optnone' attributes are not compatible}}
 int quz() __attribute__((optnone)) __attribute__((always_inline)); // expected-error{{'optnone' and 'always_inline' attributes are not compatible}}
 
+int bay() __attribute__((minsize)) __attribute__((optnone)); // expected-error{{'minsize' and 'optnone' attributes are not compatible}}
+int quy() __attribute__((optnone)) __attribute__((minsize)); // expected-error{{'optnone' and 'minsize' attributes are not compatible}}
+
 __forceinline __attribute__((optnone)) int bax(); // expected-error{{'__forceinline' and 'optnone' attributes are not compatible}}
 __attribute__((optnone)) __forceinline int qux(); // expected-error{{'optnone' and '__forceinline' attributes are not compatible}}
 
index 0a9f0410703b3ec1cd61ea28a1d1eda21312e185..b84d232b8ad9d231692f87b2ccc082ed9fe83886 100644 (file)
@@ -55,6 +55,13 @@ int __attribute__((always_inline)) baz(int z) {
 }
 // CHECK-DAG: @_Z3bazi{{.*}} [[ATTRBAZ:#[0-9]+]]
 
+// This function definition will not be decorated with `optnone` because the
+// attribute would conflict with `minsize`.
+int __attribute__((minsize)) bax(int z) {
+    return foo(z, 2);
+}
+// CHECK-DAG: @_Z3baxi{{.*}} [[ATTRBAX:#[0-9]+]]
+
 #pragma clang optimize on
 
 // The function "int wombat(int param)" created by the macro is not
@@ -144,6 +151,7 @@ int yet_another_normal(int x) {
 // Check that the other functions do NOT have optnone.
 // CHECK-DAG-NOT: attributes [[ATTRFOO]] = { {{.*}}optnone{{.*}} }
 // CHECK-DAG-NOT: attributes [[ATTRBAZ]] = { {{.*}}optnone{{.*}} }
+// CHECK-DAG-NOT: attributes [[ATTRBAX]] = { {{.*}}optnone{{.*}} }
 // CHECK-DAG-NOT: attributes [[ATTRWOMBAT]] = { {{.*}}optnone{{.*}} }
 // CHECK-DAG-NOT: attributes [[ATTRCONTAINER]] = { {{.*}}optnone{{.*}} }
 // CHECK-DAG-NOT: attributes [[ATTRTWICE]] = { {{.*}}optnone{{.*}} }