-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][Sema] Fix crash when diagnosing candidates with parameter packs #93079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: kadir çetinkaya (kadircet) ChangesPrevent OOB access. Fixes #93076 Full diff: https://github.com/llvm/llvm-project/pull/93079.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 2eb25237a0de6..c4f85df1ef697 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11298,8 +11298,9 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
Expr *FromExpr = Conv.Bad.FromExpr;
QualType FromTy = Conv.Bad.getFromType();
QualType ToTy = Conv.Bad.getToType();
- SourceRange ToParamRange =
- !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : SourceRange();
+ SourceRange ToParamRange;
+ if (!isObjectArgument && I < Fn->getNumParams())
+ ToParamRange = Fn->getParamDecl(I)->getSourceRange();
if (FromTy == S.Context.OverloadTy) {
assert(FromExpr && "overload set argument came from implicit argument?");
diff --git a/clang/test/SemaCXX/overload-template.cpp b/clang/test/SemaCXX/overload-template.cpp
index 0fe13c479cce2..01cfe87a05831 100644
--- a/clang/test/SemaCXX/overload-template.cpp
+++ b/clang/test/SemaCXX/overload-template.cpp
@@ -58,3 +58,6 @@ namespace overloadCheck{
}
}
#endif
+
+template <typename ...a> int b(a...); // expected-note {{candidate function template not viable: no known conversion from 'int ()' to 'int' for 2nd argument}}
+int d() { return b<int, int>(0, d); } // expected-error {{no matching function for call to 'b'}}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix. Can you please a little more details to your summary so that folks reading git log have more context.
This also needs a release note.
Please also add that this also fixes: #76354
Can you also confirm this fixes: #70191 |
✅ With the latest revision this PR passed the C/C++ code formatter. |
@shafik thx for the pointers, i didn't know this came up before and even there were attempted fixes. I can verify that both of those are also fixed with this patch. @knightXun do you plan to proceed with #70280 ? If so I am happy to discard this PR in favor of yours. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test based on my example?
With also a variant on that in which the bad conversion happens on the last element of the pack, instead of the last parameter.
Lastly, please namespace the tests with the name of, or add a comment naming, the GitHub issue.
Otherwise, LGTM.
Prevent OOB access by not printing target parameter range when there's a pack in the function parameters. Fixes llvm#93076. Fixes llvm#76354. Fixes llvm#70191.
…4034d613e Local branch amd-gfx 6434034 Merged main:7429950d840b8fec3d9a48d00e612a3240c2be83 into amd-gfx:49c66abb8fcb Remote branch main 7a28a5b [clang][Sema] Fix crash when diagnosing candidates with parameter packs (llvm#93079)
Prevent OOB access.
Fixes #93076