Skip to content

Commit e5fe3d2

Browse files
authored
[AArch64] Fix FMV crash on unspecified number of parameters function (#65671)
Fix Function Multi Versioning crash reported in #65669
1 parent 8c03239 commit e5fe3d2

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11680,20 +11680,22 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
1168011680
FunctionDecl *OldFD = OldDecl->getAsFunction();
1168111681

1168211682
if (!OldFD->isMultiVersion() && MVKind == MultiVersionKind::None) {
11683-
// No target_version attributes mean default
11684-
if (!NewTVA) {
11685-
const auto *OldTVA = OldFD->getAttr<TargetVersionAttr>();
11686-
if (OldTVA) {
11687-
NewFD->addAttr(TargetVersionAttr::CreateImplicit(
11688-
S.Context, "default", NewFD->getSourceRange()));
11689-
NewFD->setIsMultiVersion();
11690-
OldFD->setIsMultiVersion();
11691-
OldDecl = OldFD;
11692-
Redeclaration = true;
11693-
return true;
11694-
}
11683+
if (NewTVA || !OldFD->getAttr<TargetVersionAttr>())
11684+
return false;
11685+
if (!NewFD->getType()->getAs<FunctionProtoType>()) {
11686+
// Multiversion declaration doesn't have prototype.
11687+
S.Diag(NewFD->getLocation(), diag::err_multiversion_noproto);
11688+
NewFD->setInvalidDecl();
11689+
} else {
11690+
// No "target_version" attribute is equivalent to "default" attribute.
11691+
NewFD->addAttr(TargetVersionAttr::CreateImplicit(
11692+
S.Context, "default", NewFD->getSourceRange()));
11693+
NewFD->setIsMultiVersion();
11694+
OldFD->setIsMultiVersion();
11695+
OldDecl = OldFD;
11696+
Redeclaration = true;
1169511697
}
11696-
return false;
11698+
return true;
1169711699
}
1169811700

1169911701
// Multiversioned redeclarations aren't allowed to omit the attribute, except

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ float __attribute__((target_version("rdm"))) rtype(int);
8989
int __attribute__((target_version("sha2"))) combine(void) { return 1; }
9090
// expected-error@+1 {{multiversioned function declaration has a different calling convention}}
9191
int __attribute__((aarch64_vector_pcs, target_version("sha3"))) combine(void) { return 2; }
92+
93+
int __attribute__((target_version("fp+aes+pmull+rcpc"))) unspec_args() { return -1; }
94+
// expected-error@+1 {{multiversioned function must have a prototype}}
95+
int __attribute__((target_version("default"))) unspec_args() { return 0; }
96+
int cargs() { return unspec_args(); }

0 commit comments

Comments
 (0)