Skip to content

Commit

Permalink
[AArch64] Fix FMV crash on unspecified number of parameters function (#…
Browse files Browse the repository at this point in the history
…65671)

Fix Function Multi Versioning crash reported in
#65669
  • Loading branch information
ilinpv authored Sep 8, 2023
1 parent 8c03239 commit e5fe3d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
28 changes: 15 additions & 13 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11680,20 +11680,22 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD,
FunctionDecl *OldFD = OldDecl->getAsFunction();

if (!OldFD->isMultiVersion() && MVKind == MultiVersionKind::None) {
// No target_version attributes mean default
if (!NewTVA) {
const auto *OldTVA = OldFD->getAttr<TargetVersionAttr>();
if (OldTVA) {
NewFD->addAttr(TargetVersionAttr::CreateImplicit(
S.Context, "default", NewFD->getSourceRange()));
NewFD->setIsMultiVersion();
OldFD->setIsMultiVersion();
OldDecl = OldFD;
Redeclaration = true;
return true;
}
if (NewTVA || !OldFD->getAttr<TargetVersionAttr>())
return false;
if (!NewFD->getType()->getAs<FunctionProtoType>()) {
// Multiversion declaration doesn't have prototype.
S.Diag(NewFD->getLocation(), diag::err_multiversion_noproto);
NewFD->setInvalidDecl();
} else {
// No "target_version" attribute is equivalent to "default" attribute.
NewFD->addAttr(TargetVersionAttr::CreateImplicit(
S.Context, "default", NewFD->getSourceRange()));
NewFD->setIsMultiVersion();
OldFD->setIsMultiVersion();
OldDecl = OldFD;
Redeclaration = true;
}
return false;
return true;
}

// Multiversioned redeclarations aren't allowed to omit the attribute, except
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Sema/attr-target-version.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@ float __attribute__((target_version("rdm"))) rtype(int);
int __attribute__((target_version("sha2"))) combine(void) { return 1; }
// expected-error@+1 {{multiversioned function declaration has a different calling convention}}
int __attribute__((aarch64_vector_pcs, target_version("sha3"))) combine(void) { return 2; }

int __attribute__((target_version("fp+aes+pmull+rcpc"))) unspec_args() { return -1; }
// expected-error@+1 {{multiversioned function must have a prototype}}
int __attribute__((target_version("default"))) unspec_args() { return 0; }
int cargs() { return unspec_args(); }

0 comments on commit e5fe3d2

Please sign in to comment.