From: Eric Christopher Date: Fri, 12 Jun 2015 01:36:05 +0000 (+0000) Subject: Add a warning for unsupported elements of the target attribute. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8e7e4d0ca6fffcaf2af30c3fec21e4ee66f4bfe;p=clang Add a warning for unsupported elements of the target attribute. Since we're ignoring the tune= and fpmath= attributes go ahead and add a warning alerting people to the fact that we're going to ignore that part of it during code generation and tie it to the attribute warning set. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239583 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 6ea3ef8bb7..08520107e9 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1974,8 +1974,11 @@ def err_attribute_too_few_arguments : Error< def err_attribute_invalid_vector_type : Error<"invalid vector element type %0">; def err_attribute_bad_neon_vector_size : Error< "Neon vector size must be 64 or 128 bits">; -def err_attribute_unsupported : Error< - "%0 attribute is not supported for this target">; +def warn_unsupported_target_attribute + : Warning<"Ignoring unsupported %0 in the target attribute string">, + InGroup; +def err_attribute_unsupported + : Error<"%0 attribute is not supported for this target">; // The err_*_attribute_argument_not_int are seperate because they're used by // VerifyIntegerConstantExpression. def err_aligned_attribute_argument_not_int : Error< diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 28c09a1c60..edffabc6e5 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2820,6 +2820,7 @@ public: unsigned ArgNum, StringRef &Str, SourceLocation *ArgLocation = nullptr); bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); + void checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); bool checkMSInheritanceAttrOnDefinition( CXXRecordDecl *RD, SourceRange Range, bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling); diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 5c5321ef2d..ab3e0abfb9 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2397,14 +2397,22 @@ static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) { D->addAttr(NewAttr); } +// Check for things we'd like to warn about, no errors or validation for now. +// TODO: Validation should use a backend target library that specifies +// the allowable subtarget features and cpus. We could use something like a +// TargetCodeGenInfo hook here to do validation. +void Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) { + for (auto Str : {"tune=", "fpmath="}) + if (AttrStr.find(Str) != StringRef::npos) + Diag(LiteralLoc, diag::warn_unsupported_target_attribute) << Str; +} + static void handleTargetAttr(Sema &S, Decl *D, const AttributeList &Attr) { - // TODO: Validation should use a backend target library that specifies - // the allowable subtarget features and cpus. We could use something like a - // TargetCodeGenInfo hook here to do validation. StringRef Str; SourceLocation LiteralLoc; if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str, &LiteralLoc)) return; + S.checkTargetAttr(LiteralLoc, Str); unsigned Index = Attr.getAttributeSpellingListIndex(); TargetAttr *NewAttr = ::new (S.Context) TargetAttr(Attr.getRange(), S.Context, Str, Index); diff --git a/test/Sema/attr-target.c b/test/Sema/attr-target.c index da3b374fd4..f8b0665dcc 100644 --- a/test/Sema/attr-target.c +++ b/test/Sema/attr-target.c @@ -2,5 +2,7 @@ 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}}