Skip to content

Commit

Permalink
[clang] Fix a crash when referencing the result if the overload fails (
Browse files Browse the repository at this point in the history
…#77288)

after 20a0567

If the overload fails, the `Best` might point to the `end()`,
referencing it leads to asan crashes.
  • Loading branch information
hokein committed Jan 8, 2024
1 parent a9ffc92 commit 10b5b5d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13994,21 +13994,22 @@ ExprResult Sema::BuildOverloadedCallExpr(Scope *S, Expr *Fn,
OverloadCandidateSet::iterator Best;
OverloadingResult OverloadResult =
CandidateSet.BestViableFunction(*this, Fn->getBeginLoc(), Best);
FunctionDecl *FDecl = Best->Function;

// Model the case with a call to a templated function whose definition
// encloses the call and whose return type contains a placeholder type as if
// the UnresolvedLookupExpr was type-dependent.
if (OverloadResult == OR_Success && FDecl &&
FDecl->isTemplateInstantiation() &&
FDecl->getReturnType()->isUndeducedType()) {
if (auto TP = FDecl->getTemplateInstantiationPattern(false)) {
if (TP->willHaveBody()) {
CallExpr *CE =
CallExpr::Create(Context, Fn, Args, Context.DependentTy, VK_PRValue,
RParenLoc, CurFPFeatureOverrides());
result = CE;
return result;
if (OverloadResult == OR_Success) {
FunctionDecl *FDecl = Best->Function;
if (FDecl && FDecl->isTemplateInstantiation() &&
FDecl->getReturnType()->isUndeducedType()) {
if (auto TP = FDecl->getTemplateInstantiationPattern(false)) {
if (TP->willHaveBody()) {
CallExpr *CE =
CallExpr::Create(Context, Fn, Args, Context.DependentTy,
VK_PRValue, RParenLoc, CurFPFeatureOverrides());
result = CE;
return result;
}
}
}
}
Expand Down

0 comments on commit 10b5b5d

Please sign in to comment.