Author: gbiv
Date: Mon Jan 15 19:01:50 2018
New Revision: 322530

URL: http://llvm.org/viewvc/llvm-project?rev=322530&view=rev
Log:
[Sema] Fix a crash on invalid features in multiversioning

We were trying to emit a diag::err_bad_multiversion_option diagnostic,
which expects an int as its first argument, with a string argument. As
it happens, the string `Feature` that was causing this was shadowing an
int `Feature` from the surrounding scope. :)

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/attr-target-mv.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=322530&r1=322529&r2=322530&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 15 19:01:50 2018
@@ -9175,9 +9175,9 @@ static bool CheckMultiVersionValue(Sema
     return true;
   }
 
-  for (const auto &Feature : ParseInfo.Features) {
-    auto BareFeat = StringRef{Feature}.substr(1);
-    if (Feature[0] == '-') {
+  for (const auto &Feat : ParseInfo.Features) {
+    auto BareFeat = StringRef{Feat}.substr(1);
+    if (Feat[0] == '-') {
       S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
           << Feature << ("no-" + BareFeat).str();
       return true;

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=322530&r1=322529&r2=322530&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-target-mv.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-target-mv.cpp Mon Jan 15 19:01:50 2018
@@ -1,4 +1,11 @@
 // 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}}
+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);
+
 void __attribute__((target("sse4.2"))) no_default(void);
 void __attribute__((target("arch=sandybridge")))  no_default(void);
 


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to