-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang][Sema][FMV] Add a note to the 'cannot become multiversioned' diagnostic #124364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][Sema][FMV] Add a note to the 'cannot become multiversioned' diagnostic #124364
Conversation
…iagnostic ... pointing out the previous declaration.
@llvm/pr-subscribers-clang Author: Jon Roelofs (jroelofs) Changes... pointing out the previous declaration. Full diff: https://github.com/llvm/llvm-project/pull/124364.diff 4 Files Affected:
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ad49eac66e98e5..4151d9f83c8d8e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11380,8 +11380,11 @@ static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl *OldFD,
return true;
// Only allow transition to MultiVersion if it hasn't been used.
- if (OldFD && CausesMV && OldFD->isUsed(false))
- return S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used);
+ if (OldFD && CausesMV && OldFD->isUsed(false)) {
+ S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used);
+ S.Diag(OldFD->getLocation(), diag::note_previous_declaration);
+ return true;
+ }
return S.areMultiversionVariantFunctionsCompatible(
OldFD, NewFD, S.PDiag(diag::err_multiversion_noproto),
diff --git a/clang/test/Sema/attr-cpuspecific.c b/clang/test/Sema/attr-cpuspecific.c
index 3cd58f49faa5e6..238db0ac0b85dc 100644
--- a/clang/test/Sema/attr-cpuspecific.c
+++ b/clang/test/Sema/attr-cpuspecific.c
@@ -44,7 +44,8 @@ int allow_fwd_decl2(void);
void use_fwd_decl(void) {
allow_fwd_decl2();
}
-// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
+// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}}
+// expected-note@-5 {{previous declaration is here}}
int __attribute__((cpu_dispatch(atom))) allow_fwd_decl2(void) {}
diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c
index ddb1d82b02f098..dfc3d614dc1e00 100644
--- a/clang/test/Sema/attr-target-mv.c
+++ b/clang/test/Sema/attr-target-mv.c
@@ -66,7 +66,8 @@ int use3(void) {
return mv_after_use();
}
-// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
+// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}}
+// expected-note@-6 {{previous declaration is here}}
int __attribute__((target("arch=sandybridge"))) mv_after_use(void) { return 2; }
int __attribute__((target("sse4.2,arch=sandybridge"))) mangle(void) { return 1; }
diff --git a/clang/test/Sema/attr-target-version.c b/clang/test/Sema/attr-target-version.c
index cfcc1622abe5c0..d062212848daf1 100644
--- a/clang/test/Sema/attr-target-version.c
+++ b/clang/test/Sema/attr-target-version.c
@@ -88,7 +88,8 @@ int bar() {
nodef();
return def();
}
-// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
+// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}}
+// expected-note@-13 {{previous declaration is here}}
int __attribute__((target_version("sha2"))) def(void) { return 1; }
int __attribute__((target_version("sve"))) prot();
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/12500 Here is the relevant piece of the build log for the reference
|
... pointing out the previous declaration.