Skip to content

Commit 4e49bae

Browse files
committed
[FOLD] use getMoreConstrainedFunction in more places
1 parent 6c14b67 commit 4e49bae

File tree

2 files changed

+12
-51
lines changed

2 files changed

+12
-51
lines changed

clang/lib/Sema/SemaOverload.cpp

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10700,29 +10700,10 @@ bool clang::isBetterOverloadCandidate(
1070010700
// -— F1 and F2 are non-template functions with the same
1070110701
// parameter-type-lists, and F1 is more constrained than F2 [...],
1070210702
if (!Cand1IsSpecialization && !Cand2IsSpecialization &&
10703-
sameFunctionParameterTypeLists(S, Cand1, Cand2)) {
10704-
FunctionDecl *Function1 = Cand1.Function;
10705-
FunctionDecl *Function2 = Cand2.Function;
10706-
if (FunctionDecl *MF = Function1->getInstantiatedFromMemberFunction())
10707-
Function1 = MF;
10708-
if (FunctionDecl *MF = Function2->getInstantiatedFromMemberFunction())
10709-
Function2 = MF;
10710-
10711-
const Expr *RC1 = Function1->getTrailingRequiresClause();
10712-
const Expr *RC2 = Function2->getTrailingRequiresClause();
10713-
if (RC1 && RC2) {
10714-
bool AtLeastAsConstrained1, AtLeastAsConstrained2;
10715-
if (S.IsAtLeastAsConstrained(Function1, RC1, Function2, RC2,
10716-
AtLeastAsConstrained1) ||
10717-
S.IsAtLeastAsConstrained(Function2, RC2, Function1, RC1,
10718-
AtLeastAsConstrained2))
10719-
return false;
10720-
if (AtLeastAsConstrained1 != AtLeastAsConstrained2)
10721-
return AtLeastAsConstrained1;
10722-
} else if (RC1 || RC2) {
10723-
return RC1 != nullptr;
10724-
}
10725-
}
10703+
sameFunctionParameterTypeLists(S, Cand1, Cand2) &&
10704+
S.getMoreConstrainedFunction(Cand1.Function, Cand2.Function) ==
10705+
Cand1.Function)
10706+
return true;
1072610707

1072710708
// -- F1 is a constructor for a class D, F2 is a constructor for a base
1072810709
// class B of D, and for all arguments the corresponding parameters of
@@ -13390,25 +13371,6 @@ Sema::resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &Pair) {
1339013371
static_cast<int>(CUDA().IdentifyPreference(Caller, FD2));
1339113372
};
1339213373

13393-
auto CheckMoreConstrained = [&](FunctionDecl *FD1,
13394-
FunctionDecl *FD2) -> std::optional<bool> {
13395-
if (FunctionDecl *MF = FD1->getInstantiatedFromMemberFunction())
13396-
FD1 = MF;
13397-
if (FunctionDecl *MF = FD2->getInstantiatedFromMemberFunction())
13398-
FD2 = MF;
13399-
SmallVector<const Expr *, 1> AC1, AC2;
13400-
FD1->getAssociatedConstraints(AC1);
13401-
FD2->getAssociatedConstraints(AC2);
13402-
bool AtLeastAsConstrained1, AtLeastAsConstrained2;
13403-
if (IsAtLeastAsConstrained(FD1, AC1, FD2, AC2, AtLeastAsConstrained1))
13404-
return std::nullopt;
13405-
if (IsAtLeastAsConstrained(FD2, AC2, FD1, AC1, AtLeastAsConstrained2))
13406-
return std::nullopt;
13407-
if (AtLeastAsConstrained1 == AtLeastAsConstrained2)
13408-
return std::nullopt;
13409-
return AtLeastAsConstrained1;
13410-
};
13411-
1341213374
// Don't use the AddressOfResolver because we're specifically looking for
1341313375
// cases where we have one overload candidate that lacks
1341413376
// enable_if/pass_object_size/...
@@ -13445,15 +13407,14 @@ Sema::resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &Pair) {
1344513407
}
1344613408
// FD has the same CUDA prefernece than Result. Continue check
1344713409
// constraints.
13448-
std::optional<bool> MoreConstrainedThanPrevious =
13449-
CheckMoreConstrained(FD, Result);
13450-
if (!MoreConstrainedThanPrevious) {
13451-
IsResultAmbiguous = true;
13452-
AmbiguousDecls.push_back(FD);
13410+
FunctionDecl *MoreConstrained = getMoreConstrainedFunction(FD, Result);
13411+
if (MoreConstrained != FD) {
13412+
if (!MoreConstrained) {
13413+
IsResultAmbiguous = true;
13414+
AmbiguousDecls.push_back(FD);
13415+
}
1345313416
continue;
1345413417
}
13455-
if (!*MoreConstrainedThanPrevious)
13456-
continue;
1345713418
// FD is more constrained - replace Result with it.
1345813419
}
1345913420
FoundBetter();
@@ -13472,7 +13433,7 @@ Sema::resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &Pair) {
1347213433
// constraints.
1347313434
if (getLangOpts().CUDA && CheckCUDAPreference(Skipped, Result) != 0)
1347413435
continue;
13475-
if (!CheckMoreConstrained(Skipped, Result))
13436+
if (!getMoreConstrainedFunction(Skipped, Result))
1347613437
return nullptr;
1347713438
}
1347813439
Pair = DAP;

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5897,7 +5897,7 @@ FunctionDecl *Sema::getMoreConstrainedFunction(FunctionDecl *FD1,
58975897
FunctionDecl *F2 = FD2;
58985898
if (FunctionDecl *MF = FD2->getInstantiatedFromMemberFunction())
58995899
F2 = MF;
5900-
llvm::SmallVector<const Expr *, 3> AC1, AC2;
5900+
llvm::SmallVector<const Expr *, 1> AC1, AC2;
59015901
F1->getAssociatedConstraints(AC1);
59025902
F2->getAssociatedConstraints(AC2);
59035903
bool AtLeastAsConstrained1, AtLeastAsConstrained2;

0 commit comments

Comments
 (0)