[clang] [Sema] Fix an out-of-bounds crash when diagnosing bad conversion for a function with a parameter pack. (PR #92721)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 02:46:44 PDT 2024


================
@@ -11298,8 +11298,14 @@ 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) {
+    if (I < Fn->getNumParams())
+      ToParamRange = Fn->getParamDecl(I)->getSourceRange();
+    else
+      // parameter pack case.
+      ToParamRange = Fn->parameters().back()->getSourceRange();
----------------
hokein wrote:

thanks for the test cases. (I wonder if there is a case where we should point at the second pack, but I don't come up with one, I think using the first pack is probably good enough. Alternatively, we could use the full `getParametersSourceRange` range without finding a particular pack, but it provides less precise location information).

> Should we put that in a function in FunctionDecl?

Probably not worth, it seems heavy to add a method in FunctionDecl to only fix this regression.

https://github.com/llvm/llvm-project/pull/92721


More information about the cfe-commits mailing list