47
47
#include "llvm/ADT/SmallVector.h"
48
48
#include "llvm/Support/Casting.h"
49
49
#include <algorithm>
50
+ #include <cassert>
50
51
#include <cstddef>
51
52
#include <cstdlib>
52
53
#include <optional>
@@ -9977,8 +9978,9 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
9977
9978
CandEnd = CandidateSet.end();
9978
9979
Cand != CandEnd; ++Cand)
9979
9980
if (Cand->Function) {
9980
- Fns.erase(Cand->Function);
9981
- if (FunctionTemplateDecl *FunTmpl = Cand->Function->getPrimaryTemplate())
9981
+ FunctionDecl *Fn = Cand->Function;
9982
+ Fns.erase(Fn);
9983
+ if (FunctionTemplateDecl *FunTmpl = Fn->getPrimaryTemplate())
9982
9984
Fns.erase(FunTmpl);
9983
9985
}
9984
9986
@@ -11332,8 +11334,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
11332
11334
}
11333
11335
}
11334
11336
11335
- if (TakingCandidateAddress &&
11336
- !checkAddressOfCandidateIsAvailable(S, Cand->Function))
11337
+ if (TakingCandidateAddress && !checkAddressOfCandidateIsAvailable(S, Fn))
11337
11338
return;
11338
11339
11339
11340
// Emit the generic diagnostic and, optionally, add the hints to it.
@@ -11359,6 +11360,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
11359
11360
/// over a candidate in any candidate set.
11360
11361
static bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand,
11361
11362
unsigned NumArgs, bool IsAddressOf = false) {
11363
+ assert(Cand->Function && "Candidate is required to be a function.");
11362
11364
FunctionDecl *Fn = Cand->Function;
11363
11365
unsigned MinParams = Fn->getMinRequiredExplicitArguments() +
11364
11366
((IsAddressOf && !Fn->isStatic()) ? 1 : 0);
@@ -11449,8 +11451,10 @@ static void DiagnoseArityMismatch(Sema &S, NamedDecl *Found, Decl *D,
11449
11451
/// Arity mismatch diagnosis specific to a function overload candidate.
11450
11452
static void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand,
11451
11453
unsigned NumFormalArgs) {
11454
+ assert(Cand->Function && "Candidate must be a function");
11455
+ FunctionDecl *Fn = Cand->Function;
11452
11456
if (!CheckArityMismatch(S, Cand, NumFormalArgs, Cand->TookAddressOfOverload))
11453
- DiagnoseArityMismatch(S, Cand->FoundDecl, Cand->Function , NumFormalArgs,
11457
+ DiagnoseArityMismatch(S, Cand->FoundDecl, Fn , NumFormalArgs,
11454
11458
Cand->TookAddressOfOverload);
11455
11459
}
11456
11460
@@ -11750,19 +11754,22 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
11750
11754
static void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand,
11751
11755
unsigned NumArgs,
11752
11756
bool TakingCandidateAddress) {
11757
+ assert(Cand->Function && "Candidate must be a function");
11758
+ FunctionDecl *Fn = Cand->Function;
11753
11759
TemplateDeductionResult TDK = Cand->DeductionFailure.getResult();
11754
11760
if (TDK == TemplateDeductionResult::TooFewArguments ||
11755
11761
TDK == TemplateDeductionResult::TooManyArguments) {
11756
11762
if (CheckArityMismatch(S, Cand, NumArgs))
11757
11763
return;
11758
11764
}
11759
- DiagnoseBadDeduction(S, Cand->FoundDecl, Cand->Function , // pattern
11765
+ DiagnoseBadDeduction(S, Cand->FoundDecl, Fn , // pattern
11760
11766
Cand->DeductionFailure, NumArgs, TakingCandidateAddress);
11761
11767
}
11762
11768
11763
11769
/// CUDA: diagnose an invalid call across targets.
11764
11770
static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) {
11765
11771
FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
11772
+ assert(Cand->Function && "Candidate must be a Function.");
11766
11773
FunctionDecl *Callee = Cand->Function;
11767
11774
11768
11775
CUDAFunctionTarget CallerTarget = S.CUDA().IdentifyTarget(Caller),
@@ -11820,6 +11827,7 @@ static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) {
11820
11827
}
11821
11828
11822
11829
static void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) {
11830
+ assert(Cand->Function && "Candidate must be a function");
11823
11831
FunctionDecl *Callee = Cand->Function;
11824
11832
EnableIfAttr *Attr = static_cast<EnableIfAttr*>(Cand->DeductionFailure.Data);
11825
11833
@@ -11829,19 +11837,21 @@ static void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) {
11829
11837
}
11830
11838
11831
11839
static void DiagnoseFailedExplicitSpec(Sema &S, OverloadCandidate *Cand) {
11832
- ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(Cand->Function);
11840
+ assert(Cand->Function && "Candidate must be a function");
11841
+ FunctionDecl *Fn = Cand->Function;
11842
+ ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(Fn);
11833
11843
assert(ES.isExplicit() && "not an explicit candidate");
11834
11844
11835
11845
unsigned Kind;
11836
- switch (Cand->Function ->getDeclKind()) {
11846
+ switch (Fn ->getDeclKind()) {
11837
11847
case Decl::Kind::CXXConstructor:
11838
11848
Kind = 0;
11839
11849
break;
11840
11850
case Decl::Kind::CXXConversion:
11841
11851
Kind = 1;
11842
11852
break;
11843
11853
case Decl::Kind::CXXDeductionGuide:
11844
- Kind = Cand->Function ->isImplicit() ? 0 : 2;
11854
+ Kind = Fn ->isImplicit() ? 0 : 2;
11845
11855
break;
11846
11856
default:
11847
11857
llvm_unreachable("invalid Decl");
@@ -11851,7 +11861,7 @@ static void DiagnoseFailedExplicitSpec(Sema &S, OverloadCandidate *Cand) {
11851
11861
// (particularly an out-of-class definition) will typically lack the
11852
11862
// 'explicit' specifier.
11853
11863
// FIXME: This is probably a good thing to do for all 'candidate' notes.
11854
- FunctionDecl *First = Cand->Function ->getFirstDecl();
11864
+ FunctionDecl *First = Fn ->getFirstDecl();
11855
11865
if (FunctionDecl *Pattern = First->getTemplateInstantiationPattern())
11856
11866
First = Pattern->getFirstDecl();
11857
11867
@@ -11920,6 +11930,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
11920
11930
unsigned NumArgs,
11921
11931
bool TakingCandidateAddress,
11922
11932
LangAS CtorDestAS = LangAS::Default) {
11933
+ assert(Cand->Function && "Candidate must be a function");
11923
11934
FunctionDecl *Fn = Cand->Function;
11924
11935
if (shouldSkipNotingLambdaConversionDecl(Fn))
11925
11936
return;
@@ -11934,8 +11945,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
11934
11945
// Skip implicit member functions when trying to resolve
11935
11946
// the address of a an overload set for a function pointer.
11936
11947
if (Cand->TookAddressOfOverload &&
11937
- !Cand->Function->hasCXXExplicitFunctionObjectParameter() &&
11938
- !Cand->Function->isStatic())
11948
+ !Fn->hasCXXExplicitFunctionObjectParameter() && !Fn->isStatic())
11939
11949
return;
11940
11950
11941
11951
// Note deleted candidates, but only if they're viable.
@@ -12033,7 +12043,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
12033
12043
return;
12034
12044
12035
12045
case ovl_fail_addr_not_available: {
12036
- bool Available = checkAddressOfCandidateIsAvailable(S, Cand->Function );
12046
+ bool Available = checkAddressOfCandidateIsAvailable(S, Fn );
12037
12047
(void)Available;
12038
12048
assert(!Available);
12039
12049
break;
0 commit comments