diff options
| author | Alexandros Lamprineas <alexandros.lamprineas@arm.com> | 2024-03-06 10:42:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-06 10:42:39 +0000 |
| commit | 92529eb4aeb2dbb706aedebc1ed9fc4f8045231a (patch) | |
| tree | aaebe41a2d3f4375d4f99d0cb454c7c7a19269c3 /clang/lib/Sema/SemaDecl.cpp | |
| parent | 20459ddc82514249501c3517583c4ec8dd23cecd (diff) | |
| download | llvm-92529eb4aeb2dbb706aedebc1ed9fc4f8045231a.zip llvm-92529eb4aeb2dbb706aedebc1ed9fc4f8045231a.tar.gz llvm-92529eb4aeb2dbb706aedebc1ed9fc4f8045231a.tar.bz2 | |
[FMV] Allow target version definitions in any order. (#83887)
This patch fixes #71698. It allows defining the default target version
prior to other version definitions without raising semantic errors.
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 210e283..6b81ee1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11479,6 +11479,16 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, FunctionDecl *OldFD, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous) { + assert(!OldFD->isMultiVersion() && "Unexpected MultiVersion"); + + // The definitions should be allowed in any order. If we have discovered + // a new target version and the preceeding was the default, then add the + // corresponding attribute to it. + if (OldFD->getMultiVersionKind() == MultiVersionKind::None && + NewFD->getMultiVersionKind() == MultiVersionKind::TargetVersion) + OldFD->addAttr(TargetVersionAttr::CreateImplicit(S.Context, "default", + OldFD->getSourceRange())); + const auto *NewTA = NewFD->getAttr<TargetAttr>(); const auto *NewTVA = NewFD->getAttr<TargetVersionAttr>(); const auto *OldTA = OldFD->getAttr<TargetAttr>(); @@ -11505,9 +11515,8 @@ static bool CheckTargetCausesMultiVersioning(Sema &S, FunctionDecl *OldFD, } // If this is 'default', permit the forward declaration. - if (!OldFD->isMultiVersion() && - ((NewTA && NewTA->isDefaultVersion() && !OldTA) || - (NewTVA && NewTVA->isDefaultVersion() && !OldTVA))) { + if ((NewTA && NewTA->isDefaultVersion() && !OldTA) || + (NewTVA && NewTVA->isDefaultVersion() && !OldTVA)) { Redeclaration = true; OldDecl = OldFD; OldFD->setIsMultiVersion(); |
