Skip to content

Commit 4b81bfb

Browse files
committed
Fix typos and cuda tests
1 parent af3cf01 commit 4b81bfb

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

clang/include/clang/Sema/Overload.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,8 @@ class Sema;
13881388

13891389
private:
13901390
OverloadingResult ResultForBestCandidate(const iterator &Best);
1391-
void CudaExcludeWrongSideCandidates(Sema &S);
1391+
void CudaExcludeWrongSideCandidates(
1392+
Sema &S, SmallVectorImpl<OverloadCandidate *> &Candidates);
13921393
OverloadingResult
13931394
BestViableFunctionImpl(Sema &S, SourceLocation Loc,
13941395
OverloadCandidateSet::iterator &Best);
@@ -1447,10 +1448,17 @@ class Sema;
14471448
return
14481449
// For user defined conversion we need to check against different
14491450
// combination of CV qualifiers and look at any expicit specifier, so
1450-
// always deduce template candidate.
1451+
// always deduce template candidates.
14511452
Kind != CSK_InitByUserDefinedConversion &&
1452-
Kind != CSK_InitByConstructor && Kind != CSK_CodeCompletion &&
1453-
Opts.CPlusPlus && (!Opts.CUDA || Opts.GPUExcludeWrongSideOverloads);
1453+
Kind != CSK_InitByConstructor
1454+
// When doing code completion, we want to see all the
1455+
// viable candidates.
1456+
&& Kind != CSK_CodeCompletion &&
1457+
Opts.CPlusPlus
1458+
// When -fgpu-exclude-wrong-side-overloads, CUDA needs
1459+
// to exclude templates from the overload sets after they
1460+
// have been instantiated. See CudaExcludeWrongSideCandidates.
1461+
&& (!Opts.CUDA || !Opts.GPUExcludeWrongSideOverloads);
14541462
}
14551463

14561464
} // namespace clang

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10031,7 +10031,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1003110031
if (TD) {
1003210032

1003310033
// As template candidates are not deduced immediately,
10034-
// persist the arry in the overload set.
10034+
// persist the array in the overload set.
1003510035
MutableArrayRef<Expr *> TmpInits =
1003610036
Candidates.getPersistentArgsArray(Inits.size());
1003710037

clang/lib/Sema/SemaOverload.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8535,7 +8535,7 @@ void Sema::AddNonMemberOperatorCandidates(
85358535
if (CandidateSet.getRewriteInfo().shouldAddReversed(*this, Args, FD)) {
85368536

85378537
// As template candidates are not deduced immediately,
8538-
// persist the arry in the overload set.
8538+
// persist the array in the overload set.
85398539
ArrayRef<Expr *> Reversed = CandidateSet.getPersistentArgsArray(
85408540
FunctionArgs[1], FunctionArgs[0]);
85418541
AddTemplateOverloadCandidate(FunTmpl, F.getPair(), ExplicitTemplateArgs,
@@ -10317,7 +10317,7 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
1031710317
*this, Args, FTD->getTemplatedDecl())) {
1031810318

1031910319
// As template candidates are not deduced immediately,
10320-
// persist the arry in the overload set.
10320+
// persist the array in the overload set.
1032110321
if (ReversedArgs.empty())
1032210322
ReversedArgs = CandidateSet.getPersistentArgsArray(Args[1], Args[0]);
1032310323

@@ -11091,7 +11091,8 @@ OverloadCandidateSet::ResultForBestCandidate(const iterator &Best) {
1109111091
return OR_Success;
1109211092
}
1109311093

11094-
void OverloadCandidateSet::CudaExcludeWrongSideCandidates(Sema &S) {
11094+
void OverloadCandidateSet::CudaExcludeWrongSideCandidates(
11095+
Sema &S, SmallVectorImpl<OverloadCandidate *> &Candidates) {
1109511096
// [CUDA] HD->H or HD->D calls are technically not allowed by CUDA but
1109611097
// are accepted by both clang and NVCC. However, during a particular
1109711098
// compilation mode only one call variant is viable. We need to
@@ -11108,26 +11109,23 @@ void OverloadCandidateSet::CudaExcludeWrongSideCandidates(Sema &S) {
1110811109
const FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
1110911110

1111011111
bool ContainsSameSideCandidate =
11111-
llvm::any_of(Candidates, [&](const OverloadCandidate &Cand) {
11112+
llvm::any_of(Candidates, [&](const OverloadCandidate *Cand) {
1111211113
// Check viable function only.
11113-
return Cand.Viable && Cand.Function &&
11114-
S.CUDA().IdentifyPreference(Caller, Cand.Function) ==
11114+
return Cand->Viable && Cand->Function &&
11115+
S.CUDA().IdentifyPreference(Caller, Cand->Function) ==
1111511116
SemaCUDA::CFP_SameSide;
1111611117
});
11118+
1111711119
if (!ContainsSameSideCandidate)
1111811120
return;
1111911121

11120-
auto IsWrongSideCandidate = [&](const OverloadCandidate &Cand) {
11122+
auto IsWrongSideCandidate = [&](const OverloadCandidate *Cand) {
1112111123
// Check viable function only to avoid unnecessary data copying/moving.
11122-
return Cand.Viable && Cand.Function &&
11123-
S.CUDA().IdentifyPreference(Caller, Cand.Function) ==
11124+
return Cand->Viable && Cand->Function &&
11125+
S.CUDA().IdentifyPreference(Caller, Cand->Function) ==
1112411126
SemaCUDA::CFP_WrongSide;
1112511127
};
11126-
11127-
for (auto &Cand : Candidates) {
11128-
if (IsWrongSideCandidate(Cand))
11129-
Cand.Viable = false;
11130-
}
11128+
llvm::erase_if(Candidates, IsWrongSideCandidate);
1113111129
}
1113211130

1113311131
/// Computes the best viable function (C++ 13.3.3)
@@ -11148,9 +11146,6 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
1114811146
DeferredCandidates.empty() &&
1114911147
"Unexpected deferred template candidate");
1115011148

11151-
if (S.getLangOpts().CUDA)
11152-
CudaExcludeWrongSideCandidates(S);
11153-
1115411149
bool TwoPhaseResolution = !DeferredCandidates.empty();
1115511150

1115611151
if (TwoPhaseResolution) {
@@ -11160,16 +11155,14 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
1116011155
return ResultForBestCandidate(Best);
1116111156

1116211157
InjectNonDeducedTemplateCandidates(S);
11163-
11164-
if (S.getLangOpts().CUDA)
11165-
CudaExcludeWrongSideCandidates(S);
1116611158
}
1116711159

1116811160
return BestViableFunctionImpl(S, Loc, Best);
1116911161
}
1117011162

1117111163
void OverloadCandidateSet::PerfectViableFunction(
1117211164
Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best) {
11165+
1117311166
Best = end();
1117411167
for (auto It = begin(); It != end(); ++It) {
1117511168
if (It->isPerfectMatch(S.getASTContext())) {
@@ -11202,6 +11195,9 @@ OverloadingResult OverloadCandidateSet::BestViableFunctionImpl(
1120211195
std::transform(begin(), end(), std::back_inserter(Candidates),
1120311196
[](OverloadCandidate &Cand) { return &Cand; });
1120411197

11198+
if (S.getLangOpts().CUDA)
11199+
CudaExcludeWrongSideCandidates(S, Candidates);
11200+
1120511201
Best = end();
1120611202
for (auto *Cand : Candidates) {
1120711203
Cand->Best = false;
@@ -14954,7 +14950,7 @@ void Sema::LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet,
1495414950
AddNonMemberOperatorCandidates(Fns, Args, CandidateSet);
1495514951

1495614952
// As template candidates are not deduced immediately,
14957-
// persist the arry in the overload set.
14953+
// persist the array in the overload set.
1495814954
ArrayRef<Expr *> ReversedArgs;
1495914955
if (CandidateSet.getRewriteInfo().allowsReversed(Op) ||
1496014956
CandidateSet.getRewriteInfo().allowsReversed(ExtraOp))

0 commit comments

Comments
 (0)