Skip to content

Commit 73db9ee

Browse files
authored
[clang][Sema][FMV] Add a note to the 'cannot become multiversioned' diagnostic (#124364)
... pointing out the previous declaration.
1 parent 73f9034 commit 73db9ee

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11380,8 +11380,11 @@ static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl *OldFD,
1138011380
return true;
1138111381

1138211382
// Only allow transition to MultiVersion if it hasn't been used.
11383-
if (OldFD && CausesMV && OldFD->isUsed(false))
11384-
return S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used);
11383+
if (OldFD && CausesMV && OldFD->isUsed(false)) {
11384+
S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used);
11385+
S.Diag(OldFD->getLocation(), diag::note_previous_declaration);
11386+
return true;
11387+
}
1138511388

1138611389
return S.areMultiversionVariantFunctionsCompatible(
1138711390
OldFD, NewFD, S.PDiag(diag::err_multiversion_noproto),

clang/test/Sema/attr-cpuspecific.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ int allow_fwd_decl2(void);
4444
void use_fwd_decl(void) {
4545
allow_fwd_decl2();
4646
}
47-
// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
47+
// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}}
48+
// expected-note@-5 {{previous declaration is here}}
4849
int __attribute__((cpu_dispatch(atom))) allow_fwd_decl2(void) {}
4950

5051

clang/test/Sema/attr-target-mv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ int use3(void) {
6666
return mv_after_use();
6767
}
6868

69-
// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
69+
// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}}
70+
// expected-note@-6 {{previous declaration is here}}
7071
int __attribute__((target("arch=sandybridge"))) mv_after_use(void) { return 2; }
7172

7273
int __attribute__((target("sse4.2,arch=sandybridge"))) mangle(void) { return 1; }

clang/test/Sema/attr-target-version.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ int bar() {
8888
nodef();
8989
return def();
9090
}
91-
// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
91+
// expected-error@+2 {{function declaration cannot become a multiversioned function after first usage}}
92+
// expected-note@-13 {{previous declaration is here}}
9293
int __attribute__((target_version("sha2"))) def(void) { return 1; }
9394

9495
int __attribute__((target_version("sve"))) prot();

0 commit comments

Comments
 (0)