Skip to content

Commit 98ae27a

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 f1d13bb commit 98ae27a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,6 @@ Bug Fixes to C++ Support
734734
from being explicitly specialized for a given implicit instantiation of the class template.
735735
- Fixed a crash when ``this`` is used in a dependent class scope function template specialization
736736
that instantiates to a static member function.
737-
738737
- Fix crash when inheriting from a cv-qualified type. Fixes #GH35603
739738
- Fix a crash when the using enum declaration uses an anonymous enumeration. Fixes (#GH86790).
740739
- Handled an edge case in ``getFullyPackExpandedSize`` so that we now avoid a false-positive diagnostic. (#GH84220)
@@ -796,6 +795,8 @@ Bug Fixes to C++ Support
796795
Fixes (#GH91308).
797796
- Fix a crash caused by a regression in the handling of ``source_location``
798797
in dependent contexts. Fixes (#GH92680).
798+
- Fixed a crash when diagnosing failed conversions involving template parameter
799+
packs. (#GH93076)
799800

800801
Bug Fixes to AST Handling
801802
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaOverload.cpp

Lines changed: 11 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,16 @@ 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 =
11310+
llvm::any_of(Fn->parameters().take_front(I), [](const ParmVarDecl *Parm) {
11311+
return Parm->isParameterPack();
11312+
});
11313+
if (!isObjectArgument && !HasParamPack)
11314+
ToParamRange = Fn->getParamDecl(I)->getSourceRange();
1130611315

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

clang/test/SemaCXX/overload-template.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ namespace overloadCheck{
5858
}
5959
}
6060
#endif
61+
62+
namespace GH93076 {
63+
template <typename ...a> int b(a..., int); // expected-note-re 3 {{candidate function template not viable: no known conversion from 'int ()' to 'int' for {{.*}} argument}}
64+
int d() {
65+
(void)b<int, int>(0, 0, d); // expected-error {{no matching function for call to 'b'}}
66+
(void)b<int, int>(0, d, 0); // expected-error {{no matching function for call to 'b'}}
67+
(void)b<int, int>(d, 0, 0); // expected-error {{no matching function for call to 'b'}}
68+
return 0;
69+
}
70+
}

0 commit comments

Comments
 (0)