]> granicus.if.org Git - clang/commitdiff
Add a warning for unsupported elements of the target attribute.
authorEric Christopher <echristo@gmail.com>
Fri, 12 Jun 2015 01:36:05 +0000 (01:36 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 12 Jun 2015 01:36:05 +0000 (01:36 +0000)
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

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaDeclAttr.cpp
test/Sema/attr-target.c

index 6ea3ef8bb702ad6cc1aa96768dd48c6beac16ab6..08520107e91fd749292cfa2f98e8db4fdc71bb4b 100644 (file)
@@ -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<IgnoredAttributes>;
+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<
index 28c09a1c60497af2a40711d3086a371116041ed4..edffabc6e5fcfbd3773838bfabdeffd285452696 100644 (file)
@@ -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);
index 5c5321ef2d5a7186556092b0fdfbe4e3166ec80e..ab3e0abfb90f00c08916e297dbba9c508627a14d 100644 (file)
@@ -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);
index da3b374fd4c2e60dcc926d680fe4fe23473c68e6..f8b0665dcc3409f718f0f4d5649d2a6c337bd758 100644 (file)
@@ -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}}