Skip to content

Commit 9c691ab

Browse files
committed
[clang][Sema] Fix crash when diagnosing candidates with parameter packs
Prevent OOB access by not printing target parameter range when there's a pack in the function parameters. Fixes #93076. Fixes #76354. Fixes #70191.
1 parent a79a0c5 commit 9c691ab

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ Bug Fixes to C++ Support
730730
from being explicitly specialized for a given implicit instantiation of the class template.
731731
- Fixed a crash when ``this`` is used in a dependent class scope function template specialization
732732
that instantiates to a static member function.
733-
734733
- Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
735734
- Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790).
736735
- Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a false-positive diagnostic. (#GH84220)
@@ -790,6 +789,8 @@ Bug Fixes to C++ Support
790789
Fixes (#GH87210), (GH89541).
791790
- Clang no longer tries to check if an expression is immediate-escalating in an unevaluated context.
792791
Fixes (#GH91308).
792+
- Fixed a crash when diagnosing failed conversions involving template parameter
793+
packs. (#GH93076)
793794

794795
Bug Fixes to AST Handling
795796
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaOverload.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/AST/ASTContext.h"
1414
#include "clang/AST/ASTLambda.h"
1515
#include "clang/AST/CXXInheritance.h"
16+
#include "clang/AST/Decl.h"
1617
#include "clang/AST/DeclCXX.h"
1718
#include "clang/AST/DeclObjC.h"
1819
#include "clang/AST/DependenceFlags.h"
@@ -11301,8 +11302,14 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
1130111302
Expr *FromExpr = Conv.Bad.FromExpr;
1130211303
QualType FromTy = Conv.Bad.getFromType();
1130311304
QualType ToTy = Conv.Bad.getToType();
11304-
SourceRange ToParamRange =
11305-
!isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : SourceRange();
11305+
SourceRange ToParamRange;
11306+
11307+
// FIXME: In presence of parameter packs we can't determine parameter range
11308+
// reliably, as we don't have access to instantiation.
11309+
bool HasParamPack = llvm::any_of(Fn->parameters().take_front(I),
11310+
[](const ParmVarDecl *Parm) { return Parm->isParameterPack(); });
11311+
if (!isObjectArgument && !HasParamPack)
11312+
ToParamRange = Fn->getParamDecl(I)->getSourceRange();
1130611313

1130711314
if (FromTy == S.Context.OverloadTy) {
1130811315
assert(FromExpr && "overload set argument came from implicit argument?");

clang/test/SemaCXX/overload-template.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ namespace overloadCheck{
5858
}
5959
}
6060
#endif
61+
62+
template <typename ...a> int b(a...); // expected-note {{candidate function template not viable: no known conversion from 'int ()' to 'int' for 2nd argument}}
63+
int d() { return b<int, int>(0, d); } // expected-error {{no matching function for call to 'b'}}

0 commit comments

Comments
 (0)