r325364 - Clean up 'target' attribute diagnostics

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 16 09:31:59 PST 2018


Author: erichkeane
Date: Fri Feb 16 09:31:59 2018
New Revision: 325364

URL: http://llvm.org/viewvc/llvm-project?rev=325364&view=rev
Log:
Clean up 'target' attribute diagnostics

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

Added:
    cfe/trunk/test/Sema/attr-target-ast.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/attr-target.c
    cfe/trunk/test/SemaCXX/attr-target-mv.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=325364&r1=325363&r2=325364&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Feb 16 09:31:59 2018
@@ -2445,8 +2445,8 @@ def err_attribute_requires_positive_inte
 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">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=325364&r1=325363&r2=325364&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Feb 16 09:31:59 2018
@@ -3024,15 +3024,16 @@ bool Sema::checkTargetAttr(SourceLocatio
              << 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);

Added: cfe/trunk/test/Sema/attr-target-ast.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-target-ast.c?rev=325364&view=auto
==============================================================================
--- cfe/trunk/test/Sema/attr-target-ast.c (added)
+++ cfe/trunk/test/Sema/attr-target-ast.c Fri Feb 16 09:31:59 2018
@@ -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

Modified: cfe/trunk/test/Sema/attr-target.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-target.c?rev=325364&r1=325363&r2=325364&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-target.c (original)
+++ cfe/trunk/test/Sema/attr-target.c Fri Feb 16 09:31:59 2018
@@ -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 at +1 {{'target' attribute takes one argument}}
+int __attribute__((target())) bar() { return 4; }
+//expected-warning at +1 {{unsupported 'tune=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("tune=sandybridge"))) baz() { return 4; }
+//expected-warning at +1 {{unsupported 'fpmath=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("fpmath=387"))) walrus() { return 4; }
+//expected-warning at +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 at +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 at +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 at +1 {{duplicate 'arch=' in the 'target' attribute string; 'target' attribute ignored}}
+int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree() { return 4; }
 
 

Modified: cfe/trunk/test/SemaCXX/attr-target-mv.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-target-mv.cpp?rev=325364&r1=325363&r2=325364&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-target-mv.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-target-mv.cpp Fri Feb 16 09:31:59 2018
@@ -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 at +2 {{function multiversioning doesn't support feature 'hello_world'}}
-//expected-warning at +1 {{ignoring unsupported 'hello_world' in the target attribute string}}
+//expected-error at +2 {{function declaration is missing 'target' attribute in a multiversioned function}}
+//expected-warning at +1 {{unsupported 'hello_world' in the 'target' attribute string; 'target' attribute ignored}}
 void __attribute__((target("hello_world"))) invalid_features(void);
 //expected-error at +1 {{function multiversioning doesn't support feature 'no-sse4.2'}}
 void __attribute__((target("no-sse4.2"))) invalid_features(void);




More information about the cfe-commits mailing list