Skip to content

Commit fa5d567

Browse files
cor3ntinyuxuanchen1997
authored andcommitted
[Clang][NFC] Simplify initialization of OverloadCandidate objects. (#100318)
Summary: Initialize some fields of OverloadCandidate in its constructor. The goal here is try to fix read of uninitialized variable (which I was not able to reproduce) #93430 (comment) We should certainly try to improve the construction of `OverloadCandidate` further as it can be quite britle. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250652
1 parent 39cc344 commit fa5d567

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

clang/include/clang/Sema/Overload.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,9 @@ class Sema;
998998
private:
999999
friend class OverloadCandidateSet;
10001000
OverloadCandidate()
1001-
: IsSurrogate(false), IsADLCandidate(CallExpr::NotADL), RewriteKind(CRK_None) {}
1001+
: IsSurrogate(false), IgnoreObjectArgument(false),
1002+
TookAddressOfOverload(false), IsADLCandidate(CallExpr::NotADL),
1003+
RewriteKind(CRK_None) {}
10021004
};
10031005

10041006
/// OverloadCandidateSet - A set of overload candidates, used in C++

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6857,10 +6857,7 @@ void Sema::AddOverloadCandidate(
68576857
Candidate.Viable = true;
68586858
Candidate.RewriteKind =
68596859
CandidateSet.getRewriteInfo().getRewriteKind(Function, PO);
6860-
Candidate.IsSurrogate = false;
68616860
Candidate.IsADLCandidate = IsADLCandidate;
6862-
Candidate.IgnoreObjectArgument = false;
6863-
Candidate.TookAddressOfOverload = false;
68646861
Candidate.ExplicitCallArguments = Args.size();
68656862

68666863
// Explicit functions are not actually candidates at all if we're not
@@ -7422,8 +7419,6 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl,
74227419
Candidate.Function = Method;
74237420
Candidate.RewriteKind =
74247421
CandidateSet.getRewriteInfo().getRewriteKind(Method, PO);
7425-
Candidate.IsSurrogate = false;
7426-
Candidate.IgnoreObjectArgument = false;
74277422
Candidate.TookAddressOfOverload =
74287423
CandidateSet.getKind() == OverloadCandidateSet::CSK_AddressOfOverloadSet;
74297424
Candidate.ExplicitCallArguments = Args.size();
@@ -7617,7 +7612,6 @@ void Sema::AddMethodTemplateCandidate(
76177612
Candidate.IgnoreObjectArgument =
76187613
cast<CXXMethodDecl>(Candidate.Function)->isStatic() ||
76197614
ObjectType.isNull();
7620-
Candidate.TookAddressOfOverload = false;
76217615
Candidate.ExplicitCallArguments = Args.size();
76227616
if (Result == TemplateDeductionResult::NonDependentConversionFailure)
76237617
Candidate.FailureKind = ovl_fail_bad_conversion;
@@ -7705,7 +7699,6 @@ void Sema::AddTemplateOverloadCandidate(
77057699
Candidate.IgnoreObjectArgument =
77067700
isa<CXXMethodDecl>(Candidate.Function) &&
77077701
!isa<CXXConstructorDecl>(Candidate.Function);
7708-
Candidate.TookAddressOfOverload = false;
77097702
Candidate.ExplicitCallArguments = Args.size();
77107703
if (Result == TemplateDeductionResult::NonDependentConversionFailure)
77117704
Candidate.FailureKind = ovl_fail_bad_conversion;
@@ -7886,9 +7879,6 @@ void Sema::AddConversionCandidate(
78867879
OverloadCandidate &Candidate = CandidateSet.addCandidate(1);
78877880
Candidate.FoundDecl = FoundDecl;
78887881
Candidate.Function = Conversion;
7889-
Candidate.IsSurrogate = false;
7890-
Candidate.IgnoreObjectArgument = false;
7891-
Candidate.TookAddressOfOverload = false;
78927882
Candidate.FinalConversion.setAsIdentityConversion();
78937883
Candidate.FinalConversion.setFromType(ConvType);
78947884
Candidate.FinalConversion.setAllToTypes(ToType);
@@ -8084,9 +8074,6 @@ void Sema::AddTemplateConversionCandidate(
80848074
Candidate.Function = FunctionTemplate->getTemplatedDecl();
80858075
Candidate.Viable = false;
80868076
Candidate.FailureKind = ovl_fail_bad_deduction;
8087-
Candidate.IsSurrogate = false;
8088-
Candidate.IgnoreObjectArgument = false;
8089-
Candidate.TookAddressOfOverload = false;
80908077
Candidate.ExplicitCallArguments = 1;
80918078
Candidate.DeductionFailure = MakeDeductionFailureInfo(Context, Result,
80928079
Info);
@@ -8119,10 +8106,8 @@ void Sema::AddSurrogateCandidate(CXXConversionDecl *Conversion,
81198106
Candidate.FoundDecl = FoundDecl;
81208107
Candidate.Function = nullptr;
81218108
Candidate.Surrogate = Conversion;
8122-
Candidate.Viable = true;
81238109
Candidate.IsSurrogate = true;
8124-
Candidate.IgnoreObjectArgument = false;
8125-
Candidate.TookAddressOfOverload = false;
8110+
Candidate.Viable = true;
81268111
Candidate.ExplicitCallArguments = Args.size();
81278112

81288113
// Determine the implicit conversion sequence for the implicit
@@ -8328,9 +8313,6 @@ void Sema::AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args,
83288313
OverloadCandidate &Candidate = CandidateSet.addCandidate(Args.size());
83298314
Candidate.FoundDecl = DeclAccessPair::make(nullptr, AS_none);
83308315
Candidate.Function = nullptr;
8331-
Candidate.IsSurrogate = false;
8332-
Candidate.IgnoreObjectArgument = false;
8333-
Candidate.TookAddressOfOverload = false;
83348316
std::copy(ParamTys, ParamTys + Args.size(), Candidate.BuiltinParamTypes);
83358317

83368318
// Determine the implicit conversion sequences for each of the

0 commit comments

Comments
 (0)