erichkeane created this revision. erichkeane added reviewers: echristo, aaron.ballman.
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. https://reviews.llvm.org/D43359 Files: lib/Sema/SemaDeclAttr.cpp test/Sema/attr-target-ast.c test/Sema/attr-target.c test/SemaCXX/attr-target-mv.cpp Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -3024,15 +3024,18 @@ << 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)) { + S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL.getName(); return; + } + unsigned Index = AL.getAttributeSpellingListIndex(); TargetAttr *NewAttr = ::new (S.Context) TargetAttr(AL.getRange(), S.Context, Str, Index); Index: test/SemaCXX/attr-target-mv.cpp =================================================================== --- test/SemaCXX/attr-target-mv.cpp +++ test/SemaCXX/attr-target-mv.cpp @@ -1,7 +1,8 @@ // 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@+3 {{function declaration is missing 'target' attribute in a multiversioned function}} +//expected-warning@+2 {{ignoring unsupported 'hello_world' in the target attribute string}} +//expected-warning@+1 {{'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); Index: test/Sema/attr-target-ast.c =================================================================== --- test/Sema/attr-target-ast.c +++ test/Sema/attr-target-ast.c @@ -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: test/Sema/attr-target.c =================================================================== --- test/Sema/attr-target.c +++ test/Sema/attr-target.c @@ -2,12 +2,18 @@ int __attribute__((target("avx,sse4.2,arch=ivybridge"))) foo() { return 4; } int __attribute__((target())) bar() { return 4; } //expected-error {{'target' attribute takes one argument}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("tune=sandybridge"))) baz() { return 4; } //expected-warning {{ignoring unsupported 'tune=' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("fpmath=387"))) walrus() { return 4; } //expected-warning {{ignoring unsupported 'fpmath=' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("avx,sse4.2,arch=hiss"))) meow() { return 4; }//expected-warning {{ignoring unsupported architecture 'hiss' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} 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'. +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("arch=hiss,arch=woof"))) pine_tree() { return 4; } //expected-warning {{ignoring unsupported architecture 'hiss' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree() { return 4; } //expected-warning {{ignoring duplicate 'arch=' in the target attribute string}}
Index: lib/Sema/SemaDeclAttr.cpp =================================================================== --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -3024,15 +3024,18 @@ << 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)) { + S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL.getName(); return; + } + unsigned Index = AL.getAttributeSpellingListIndex(); TargetAttr *NewAttr = ::new (S.Context) TargetAttr(AL.getRange(), S.Context, Str, Index); Index: test/SemaCXX/attr-target-mv.cpp =================================================================== --- test/SemaCXX/attr-target-mv.cpp +++ test/SemaCXX/attr-target-mv.cpp @@ -1,7 +1,8 @@ // 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@+3 {{function declaration is missing 'target' attribute in a multiversioned function}} +//expected-warning@+2 {{ignoring unsupported 'hello_world' in the target attribute string}} +//expected-warning@+1 {{'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); Index: test/Sema/attr-target-ast.c =================================================================== --- test/Sema/attr-target-ast.c +++ test/Sema/attr-target-ast.c @@ -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: test/Sema/attr-target.c =================================================================== --- test/Sema/attr-target.c +++ test/Sema/attr-target.c @@ -2,12 +2,18 @@ int __attribute__((target("avx,sse4.2,arch=ivybridge"))) foo() { return 4; } int __attribute__((target())) bar() { return 4; } //expected-error {{'target' attribute takes one argument}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("tune=sandybridge"))) baz() { return 4; } //expected-warning {{ignoring unsupported 'tune=' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("fpmath=387"))) walrus() { return 4; } //expected-warning {{ignoring unsupported 'fpmath=' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("avx,sse4.2,arch=hiss"))) meow() { return 4; }//expected-warning {{ignoring unsupported architecture 'hiss' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} 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'. +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("arch=hiss,arch=woof"))) pine_tree() { return 4; } //expected-warning {{ignoring unsupported architecture 'hiss' in the target attribute string}} +// expected-warning@+1 {{'target' attribute ignored}} int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree() { return 4; } //expected-warning {{ignoring duplicate 'arch=' in the target attribute string}}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits