]> granicus.if.org Git - clang/commitdiff
Clean up 'target' attribute diagnostics
authorErich Keane <erich.keane@intel.com>
Fri, 16 Feb 2018 17:31:59 +0000 (17:31 +0000)
committerErich Keane <erich.keane@intel.com>
Fri, 16 Feb 2018 17:31:59 +0000 (17:31 +0000)
There were a few issues previously with the target
attribute diagnostics implementation that lead to the
attribute being added to the AST despite having an error
in it.

This patch changes that, and adds a test to ensure it
does not get added to the AST.

Differential Revision: https://reviews.llvm.org/D43359

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-target-ast.c [new file with mode: 0644]
test/Sema/attr-target.c
test/SemaCXX/attr-target-mv.cpp

index b666bf0b9ae0eded7e9c1f4d28bd8c34849e767d..04e3d465a9b8ab343333b0eafd6573392f8f8a7b 100644 (file)
@@ -2445,8 +2445,8 @@ def err_attribute_requires_positive_integer : Error<
 def err_attribute_requires_opencl_version : Error<
   "%0 attribute requires OpenCL version %1%select{| or above}2">;
 def warn_unsupported_target_attribute
-    : Warning<"ignoring %select{unsupported|duplicate}0"
-              "%select{| architecture}1 '%2' in the target attribute string">,
+    : Warning<"%select{unsupported|duplicate}0%select{| architecture}1 '%2' in"
+              " the 'target' attribute string; 'target' attribute ignored">,
       InGroup<IgnoredAttributes>;
 def err_attribute_unsupported
     : Error<"%0 attribute is not supported for this target">;
index 6126c7f516c249cc0d612ef577ac51126aa502d8..458c31881dc16e7b3da0dd6563814c790500f8ef 100644 (file)
@@ -3024,15 +3024,16 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
              << Unsupported << None << CurFeature;
   }
 
-  return true;
+  return false;
 }
 
 static void handleTargetAttr(Sema &S, Decl *D, const AttributeList &AL) {
   StringRef Str;
   SourceLocation LiteralLoc;
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
-      !S.checkTargetAttr(LiteralLoc, Str))
+      S.checkTargetAttr(LiteralLoc, Str))
     return;
+
   unsigned Index = AL.getAttributeSpellingListIndex();
   TargetAttr *NewAttr =
       ::new (S.Context) TargetAttr(AL.getRange(), S.Context, Str, Index);
diff --git a/test/Sema/attr-target-ast.c b/test/Sema/attr-target-ast.c
new file mode 100644 (file)
index 0000000..6e8497e
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ast-dump %s | FileCheck %s
+
+int __attribute__((target("arch=hiss,arch=woof"))) pine_tree() { return 4; }
+// CHECK-NOT: arch=hiss
+// CHECK-NOT: arch=woof
index 058bfc421a19053403e640dea69e42aa1d044ba2..644d7cb1604e0a936eab9e7b322339ed198b1f4b 100644 (file)
@@ -1,14 +1,21 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify %s
 
 int __attribute__((target("avx,sse4.2,arch=ivybridge"))) foo() { return 4; }
-int __attribute__((target())) bar() { return 4; } //expected-error {{'target' attribute takes one argument}}
-int __attribute__((target("tune=sandybridge"))) baz() { return 4; } //expected-warning {{ignoring unsupported 'tune=' in the target attribute string}}
-int __attribute__((target("fpmath=387"))) walrus() { return 4; } //expected-warning {{ignoring unsupported 'fpmath=' in the target attribute string}}
-int __attribute__((target("avx,sse4.2,arch=hiss"))) meow() {  return 4; }//expected-warning {{ignoring unsupported architecture 'hiss' in the target attribute string}}
-int __attribute__((target("woof"))) bark() {  return 4; }//expected-warning {{ignoring unsupported 'woof' in the target attribute string}}
-int __attribute__((target("arch="))) turtle() { return 4; } // no warning, same as saying 'nothing'.
-int __attribute__((target("arch=hiss,arch=woof"))) pine_tree() { return 4; } //expected-warning {{ignoring unsupported architecture 'hiss' in the target attribute string}}
-int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree() { return 4; } //expected-warning {{ignoring duplicate 'arch=' in the target attribute string}}
-
+//expected-error@+1 {{'target' attribute takes one argument}}
+int __attribute__((target())) bar() { return 4; }
+//expected-warning@+1 {{unsupported 'tune=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("tune=sandybridge"))) baz() { return 4; }
+//expected-warning@+1 {{unsupported 'fpmath=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("fpmath=387"))) walrus() { return 4; }
+//expected-warning@+1 {{unsupported architecture 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("avx,sse4.2,arch=hiss"))) meow() {  return 4; }
+//expected-warning@+1 {{unsupported 'woof' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("woof"))) bark() {  return 4; }
+// no warning, same as saying 'nothing'.
+int __attribute__((target("arch="))) turtle() { return 4; }
+//expected-warning@+1 {{unsupported architecture 'hiss' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("arch=hiss,arch=woof"))) pine_tree() { return 4; }
+//expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree() { return 4; }
 
 
index cc2d4f16c3ff55090ad85a471816752103821af8..11f3a276c7c7e7e98489fc77e8ba8d912e2dcbfb 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
 void __attribute__((target("default"))) invalid_features(void);
-//expected-error@+2 {{function multiversioning doesn't support feature 'hello_world'}}
-//expected-warning@+1 {{ignoring unsupported 'hello_world' in the target attribute string}}
+//expected-error@+2 {{function declaration is missing 'target' attribute in a multiversioned function}}
+//expected-warning@+1 {{unsupported 'hello_world' in the 'target' attribute string; 'target' attribute ignored}}
 void __attribute__((target("hello_world"))) invalid_features(void);
 //expected-error@+1 {{function multiversioning doesn't support feature 'no-sse4.2'}}
 void __attribute__((target("no-sse4.2"))) invalid_features(void);