]> granicus.if.org Git - clang/commitdiff
[Sema] Fix a crash on invalid features in multiversioning
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 16 Jan 2018 03:01:50 +0000 (03:01 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Tue, 16 Jan 2018 03:01:50 +0000 (03:01 +0000)
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. :)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322530 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/attr-target-mv.cpp

index 23fcfb4ec7ca83c8494e8e9c82e2cd44ffeeb7c1..1a7d9a84306f7dcb106a2eec35b3df943971e530 100644 (file)
@@ -9175,9 +9175,9 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) {
     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;
index 18ec1bf7ca5b03d8edbdcb0fb2b98370fb6c9f65..cc2d4f16c3ff55090ad85a471816752103821af8 100644 (file)
@@ -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);