Skip to content

Commit ead2c43

Browse files
committed
Fix typos and cuda tests
1 parent 477d531 commit ead2c43

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
@@ -10045,7 +10045,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1004510045
if (TD) {
1004610046

1004710047
// As template candidates are not deduced immediately,
10048-
// persist the arry in the overload set.
10048+
// persist the array in the overload set.
1004910049
MutableArrayRef<Expr *> TmpInits =
1005010050
Candidates.getPersistentArgsArray(Inits.size());
1005110051

clang/lib/Sema/SemaOverload.cpp

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

85298529
// As template candidates are not deduced immediately,
8530-
// persist the arry in the overload set.
8530+
// persist the array in the overload set.
85318531
ArrayRef<Expr *> Reversed = CandidateSet.getPersistentArgsArray(
85328532
FunctionArgs[1], FunctionArgs[0]);
85338533
AddTemplateOverloadCandidate(FunTmpl, F.getPair(), ExplicitTemplateArgs,
@@ -10309,7 +10309,7 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
1030910309
*this, Args, FTD->getTemplatedDecl())) {
1031010310

1031110311
// As template candidates are not deduced immediately,
10312-
// persist the arry in the overload set.
10312+
// persist the array in the overload set.
1031310313
if (ReversedArgs.empty())
1031410314
ReversedArgs = CandidateSet.getPersistentArgsArray(Args[1], Args[0]);
1031510315

@@ -11083,7 +11083,8 @@ OverloadCandidateSet::ResultForBestCandidate(const iterator &Best) {
1108311083
return OR_Success;
1108411084
}
1108511085

11086-
void OverloadCandidateSet::CudaExcludeWrongSideCandidates(Sema &S) {
11086+
void OverloadCandidateSet::CudaExcludeWrongSideCandidates(
11087+
Sema &S, SmallVectorImpl<OverloadCandidate *> &Candidates) {
1108711088
// [CUDA] HD->H or HD->D calls are technically not allowed by CUDA but
1108811089
// are accepted by both clang and NVCC. However, during a particular
1108911090
// compilation mode only one call variant is viable. We need to
@@ -11100,26 +11101,23 @@ void OverloadCandidateSet::CudaExcludeWrongSideCandidates(Sema &S) {
1110011101
const FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
1110111102

1110211103
bool ContainsSameSideCandidate =
11103-
llvm::any_of(Candidates, [&](const OverloadCandidate &Cand) {
11104+
llvm::any_of(Candidates, [&](const OverloadCandidate *Cand) {
1110411105
// 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) ==
1110711108
SemaCUDA::CFP_SameSide;
1110811109
});
11110+
1110911111
if (!ContainsSameSideCandidate)
1111011112
return;
1111111113

11112-
auto IsWrongSideCandidate = [&](const OverloadCandidate &Cand) {
11114+
auto IsWrongSideCandidate = [&](const OverloadCandidate *Cand) {
1111311115
// 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) ==
1111611118
SemaCUDA::CFP_WrongSide;
1111711119
};
11118-
11119-
for (auto &Cand : Candidates) {
11120-
if (IsWrongSideCandidate(Cand))
11121-
Cand.Viable = false;
11122-
}
11120+
llvm::erase_if(Candidates, IsWrongSideCandidate);
1112311121
}
1112411122

1112511123
/// Computes the best viable function (C++ 13.3.3)
@@ -11140,9 +11138,6 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
1114011138
DeferredCandidates.empty() &&
1114111139
"Unexpected deferred template candidate");
1114211140

11143-
if (S.getLangOpts().CUDA)
11144-
CudaExcludeWrongSideCandidates(S);
11145-
1114611141
bool TwoPhaseResolution = !DeferredCandidates.empty();
1114711142

1114811143
if (TwoPhaseResolution) {
@@ -11152,16 +11147,14 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
1115211147
return ResultForBestCandidate(Best);
1115311148

1115411149
InjectNonDeducedTemplateCandidates(S);
11155-
11156-
if (S.getLangOpts().CUDA)
11157-
CudaExcludeWrongSideCandidates(S);
1115811150
}
1115911151

1116011152
return BestViableFunctionImpl(S, Loc, Best);
1116111153
}
1116211154

1116311155
void OverloadCandidateSet::PerfectViableFunction(
1116411156
Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best) {
11157+
1116511158
Best = end();
1116611159
for (auto It = begin(); It != end(); ++It) {
1116711160
if (It->isPerfectMatch(S.getASTContext())) {
@@ -11194,6 +11187,9 @@ OverloadingResult OverloadCandidateSet::BestViableFunctionImpl(
1119411187
std::transform(begin(), end(), std::back_inserter(Candidates),
1119511188
[](OverloadCandidate &Cand) { return &Cand; });
1119611189

11190+
if (S.getLangOpts().CUDA)
11191+
CudaExcludeWrongSideCandidates(S, Candidates);
11192+
1119711193
Best = end();
1119811194
for (auto *Cand : Candidates) {
1119911195
Cand->Best = false;
@@ -14935,7 +14931,7 @@ void Sema::LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet,
1493514931
AddNonMemberOperatorCandidates(Fns, Args, CandidateSet);
1493614932

1493714933
// As template candidates are not deduced immediately,
14938-
// persist the arry in the overload set.
14934+
// persist the array in the overload set.
1493914935
ArrayRef<Expr *> ReversedArgs;
1494014936
if (CandidateSet.getRewriteInfo().allowsReversed(Op) ||
1494114937
CandidateSet.getRewriteInfo().allowsReversed(ExtraOp))

0 commit comments

Comments
 (0)