4747#include "llvm/ADT/SmallVector.h"
4848#include "llvm/Support/Casting.h"
4949#include <algorithm>
50+ #include <cassert>
5051#include <cstddef>
5152#include <cstdlib>
5253#include <optional>
@@ -9977,8 +9978,9 @@ Sema::AddArgumentDependentLookupCandidates(DeclarationName Name,
99779978 CandEnd = CandidateSet.end();
99789979 Cand != CandEnd; ++Cand)
99799980 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())
99829984 Fns.erase(FunTmpl);
99839985 }
99849986
@@ -11332,8 +11334,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
1133211334 }
1133311335 }
1133411336
11335- if (TakingCandidateAddress &&
11336- !checkAddressOfCandidateIsAvailable(S, Cand->Function))
11337+ if (TakingCandidateAddress && !checkAddressOfCandidateIsAvailable(S, Fn))
1133711338 return;
1133811339
1133911340 // Emit the generic diagnostic and, optionally, add the hints to it.
@@ -11359,6 +11360,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
1135911360/// over a candidate in any candidate set.
1136011361static bool CheckArityMismatch(Sema &S, OverloadCandidate *Cand,
1136111362 unsigned NumArgs, bool IsAddressOf = false) {
11363+ assert(Cand->Function && "Candidate is required to be a function.");
1136211364 FunctionDecl *Fn = Cand->Function;
1136311365 unsigned MinParams = Fn->getMinRequiredExplicitArguments() +
1136411366 ((IsAddressOf && !Fn->isStatic()) ? 1 : 0);
@@ -11449,8 +11451,10 @@ static void DiagnoseArityMismatch(Sema &S, NamedDecl *Found, Decl *D,
1144911451/// Arity mismatch diagnosis specific to a function overload candidate.
1145011452static void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand,
1145111453 unsigned NumFormalArgs) {
11454+ assert(Cand->Function && "Candidate must be a function");
11455+ FunctionDecl *Fn = Cand->Function;
1145211456 if (!CheckArityMismatch(S, Cand, NumFormalArgs, Cand->TookAddressOfOverload))
11453- DiagnoseArityMismatch(S, Cand->FoundDecl, Cand->Function , NumFormalArgs,
11457+ DiagnoseArityMismatch(S, Cand->FoundDecl, Fn , NumFormalArgs,
1145411458 Cand->TookAddressOfOverload);
1145511459}
1145611460
@@ -11750,19 +11754,22 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
1175011754static void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand,
1175111755 unsigned NumArgs,
1175211756 bool TakingCandidateAddress) {
11757+ assert(Cand->Function && "Candidate must be a function");
11758+ FunctionDecl *Fn = Cand->Function;
1175311759 TemplateDeductionResult TDK = Cand->DeductionFailure.getResult();
1175411760 if (TDK == TemplateDeductionResult::TooFewArguments ||
1175511761 TDK == TemplateDeductionResult::TooManyArguments) {
1175611762 if (CheckArityMismatch(S, Cand, NumArgs))
1175711763 return;
1175811764 }
11759- DiagnoseBadDeduction(S, Cand->FoundDecl, Cand->Function , // pattern
11765+ DiagnoseBadDeduction(S, Cand->FoundDecl, Fn , // pattern
1176011766 Cand->DeductionFailure, NumArgs, TakingCandidateAddress);
1176111767}
1176211768
1176311769/// CUDA: diagnose an invalid call across targets.
1176411770static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) {
1176511771 FunctionDecl *Caller = S.getCurFunctionDecl(/*AllowLambda=*/true);
11772+ assert(Cand->Function && "Candidate must be a Function.");
1176611773 FunctionDecl *Callee = Cand->Function;
1176711774
1176811775 CUDAFunctionTarget CallerTarget = S.CUDA().IdentifyTarget(Caller),
@@ -11820,6 +11827,7 @@ static void DiagnoseBadTarget(Sema &S, OverloadCandidate *Cand) {
1182011827}
1182111828
1182211829static void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) {
11830+ assert(Cand->Function && "Candidate must be a function");
1182311831 FunctionDecl *Callee = Cand->Function;
1182411832 EnableIfAttr *Attr = static_cast<EnableIfAttr*>(Cand->DeductionFailure.Data);
1182511833
@@ -11829,19 +11837,21 @@ static void DiagnoseFailedEnableIfAttr(Sema &S, OverloadCandidate *Cand) {
1182911837}
1183011838
1183111839static 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);
1183311843 assert(ES.isExplicit() && "not an explicit candidate");
1183411844
1183511845 unsigned Kind;
11836- switch (Cand->Function ->getDeclKind()) {
11846+ switch (Fn ->getDeclKind()) {
1183711847 case Decl::Kind::CXXConstructor:
1183811848 Kind = 0;
1183911849 break;
1184011850 case Decl::Kind::CXXConversion:
1184111851 Kind = 1;
1184211852 break;
1184311853 case Decl::Kind::CXXDeductionGuide:
11844- Kind = Cand->Function ->isImplicit() ? 0 : 2;
11854+ Kind = Fn ->isImplicit() ? 0 : 2;
1184511855 break;
1184611856 default:
1184711857 llvm_unreachable("invalid Decl");
@@ -11851,7 +11861,7 @@ static void DiagnoseFailedExplicitSpec(Sema &S, OverloadCandidate *Cand) {
1185111861 // (particularly an out-of-class definition) will typically lack the
1185211862 // 'explicit' specifier.
1185311863 // FIXME: This is probably a good thing to do for all 'candidate' notes.
11854- FunctionDecl *First = Cand->Function ->getFirstDecl();
11864+ FunctionDecl *First = Fn ->getFirstDecl();
1185511865 if (FunctionDecl *Pattern = First->getTemplateInstantiationPattern())
1185611866 First = Pattern->getFirstDecl();
1185711867
@@ -11920,6 +11930,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
1192011930 unsigned NumArgs,
1192111931 bool TakingCandidateAddress,
1192211932 LangAS CtorDestAS = LangAS::Default) {
11933+ assert(Cand->Function && "Candidate must be a function");
1192311934 FunctionDecl *Fn = Cand->Function;
1192411935 if (shouldSkipNotingLambdaConversionDecl(Fn))
1192511936 return;
@@ -11934,8 +11945,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
1193411945 // Skip implicit member functions when trying to resolve
1193511946 // the address of a an overload set for a function pointer.
1193611947 if (Cand->TookAddressOfOverload &&
11937- !Cand->Function->hasCXXExplicitFunctionObjectParameter() &&
11938- !Cand->Function->isStatic())
11948+ !Fn->hasCXXExplicitFunctionObjectParameter() && !Fn->isStatic())
1193911949 return;
1194011950
1194111951 // Note deleted candidates, but only if they're viable.
@@ -12033,7 +12043,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
1203312043 return;
1203412044
1203512045 case ovl_fail_addr_not_available: {
12036- bool Available = checkAddressOfCandidateIsAvailable(S, Cand->Function );
12046+ bool Available = checkAddressOfCandidateIsAvailable(S, Fn );
1203712047 (void)Available;
1203812048 assert(!Available);
1203912049 break;
0 commit comments