@@ -8527,7 +8527,7 @@ void Sema::AddNonMemberOperatorCandidates(
8527
8527
if (CandidateSet.getRewriteInfo().shouldAddReversed(*this, Args, FD)) {
8528
8528
8529
8529
// As template candidates are not deduced immediately,
8530
- // persist the arry in the overload set.
8530
+ // persist the array in the overload set.
8531
8531
ArrayRef<Expr *> Reversed = CandidateSet.getPersistentArgsArray(
8532
8532
FunctionArgs[1], FunctionArgs[0]);
8533
8533
AddTemplateOverloadCandidate(FunTmpl, F.getPair(), ExplicitTemplateArgs,
@@ -10309,7 +10309,7 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
10309
10309
*this, Args, FTD->getTemplatedDecl())) {
10310
10310
10311
10311
// As template candidates are not deduced immediately,
10312
- // persist the arry in the overload set.
10312
+ // persist the array in the overload set.
10313
10313
if (ReversedArgs.empty())
10314
10314
ReversedArgs = CandidateSet.getPersistentArgsArray(Args[1], Args[0]);
10315
10315
@@ -11083,7 +11083,8 @@ OverloadCandidateSet::ResultForBestCandidate(const iterator &Best) {
11083
11083
return OR_Success;
11084
11084
}
11085
11085
11086
- void OverloadCandidateSet::CudaExcludeWrongSideCandidates(Sema &S) {
11086
+ void OverloadCandidateSet::CudaExcludeWrongSideCandidates(
11087
+ Sema &S, SmallVectorImpl<OverloadCandidate *> &Candidates) {
11087
11088
// [CUDA] HD->H or HD->D calls are technically not allowed by CUDA but
11088
11089
// are accepted by both clang and NVCC. However, during a particular
11089
11090
// compilation mode only one call variant is viable. We need to
@@ -11100,26 +11101,23 @@ void OverloadCandidateSet::CudaExcludeWrongSideCandidates(Sema &S) {
11100
11101
const FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
11101
11102
11102
11103
bool ContainsSameSideCandidate =
11103
- llvm::any_of(Candidates, [&](const OverloadCandidate & Cand) {
11104
+ llvm::any_of(Candidates, [&](const OverloadCandidate * Cand) {
11104
11105
// Check viable function only.
11105
- return Cand. Viable && Cand. Function &&
11106
- S.CUDA().IdentifyPreference(Caller, Cand. Function) ==
11106
+ return Cand-> Viable && Cand-> Function &&
11107
+ S.CUDA().IdentifyPreference(Caller, Cand-> Function) ==
11107
11108
SemaCUDA::CFP_SameSide;
11108
11109
});
11110
+
11109
11111
if (!ContainsSameSideCandidate)
11110
11112
return;
11111
11113
11112
- auto IsWrongSideCandidate = [&](const OverloadCandidate & Cand) {
11114
+ auto IsWrongSideCandidate = [&](const OverloadCandidate * Cand) {
11113
11115
// Check viable function only to avoid unnecessary data copying/moving.
11114
- return Cand. Viable && Cand. Function &&
11115
- S.CUDA().IdentifyPreference(Caller, Cand. Function) ==
11116
+ return Cand-> Viable && Cand-> Function &&
11117
+ S.CUDA().IdentifyPreference(Caller, Cand-> Function) ==
11116
11118
SemaCUDA::CFP_WrongSide;
11117
11119
};
11118
-
11119
- for (auto &Cand : Candidates) {
11120
- if (IsWrongSideCandidate(Cand))
11121
- Cand.Viable = false;
11122
- }
11120
+ llvm::erase_if(Candidates, IsWrongSideCandidate);
11123
11121
}
11124
11122
11125
11123
/// Computes the best viable function (C++ 13.3.3)
@@ -11140,9 +11138,6 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
11140
11138
DeferredCandidates.empty() &&
11141
11139
"Unexpected deferred template candidate");
11142
11140
11143
- if (S.getLangOpts().CUDA)
11144
- CudaExcludeWrongSideCandidates(S);
11145
-
11146
11141
bool TwoPhaseResolution = !DeferredCandidates.empty();
11147
11142
11148
11143
if (TwoPhaseResolution) {
@@ -11152,16 +11147,14 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
11152
11147
return ResultForBestCandidate(Best);
11153
11148
11154
11149
InjectNonDeducedTemplateCandidates(S);
11155
-
11156
- if (S.getLangOpts().CUDA)
11157
- CudaExcludeWrongSideCandidates(S);
11158
11150
}
11159
11151
11160
11152
return BestViableFunctionImpl(S, Loc, Best);
11161
11153
}
11162
11154
11163
11155
void OverloadCandidateSet::PerfectViableFunction(
11164
11156
Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best) {
11157
+
11165
11158
Best = end();
11166
11159
for (auto It = begin(); It != end(); ++It) {
11167
11160
if (It->isPerfectMatch(S.getASTContext())) {
@@ -11194,6 +11187,9 @@ OverloadingResult OverloadCandidateSet::BestViableFunctionImpl(
11194
11187
std::transform(begin(), end(), std::back_inserter(Candidates),
11195
11188
[](OverloadCandidate &Cand) { return &Cand; });
11196
11189
11190
+ if (S.getLangOpts().CUDA)
11191
+ CudaExcludeWrongSideCandidates(S, Candidates);
11192
+
11197
11193
Best = end();
11198
11194
for (auto *Cand : Candidates) {
11199
11195
Cand->Best = false;
@@ -14935,7 +14931,7 @@ void Sema::LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet,
14935
14931
AddNonMemberOperatorCandidates(Fns, Args, CandidateSet);
14936
14932
14937
14933
// As template candidates are not deduced immediately,
14938
- // persist the arry in the overload set.
14934
+ // persist the array in the overload set.
14939
14935
ArrayRef<Expr *> ReversedArgs;
14940
14936
if (CandidateSet.getRewriteInfo().allowsReversed(Op) ||
14941
14937
CandidateSet.getRewriteInfo().allowsReversed(ExtraOp))
0 commit comments