https://github.com/knightXun created https://github.com/llvm/llvm-project/pull/70280
…iadic Template Variables When template variables are variadic, sema may panic, potentially leading to a situation where the number of function variables exceeds the number of template variables. The sema compares the template signature and function signature parameters one by one, which can trigger an assertion error. This PR, when encountering variadic templates, avoids comparing the template signature and function signature parameters one by one. issue: https://github.com/llvm/llvm-project/issues/70191 >From e26572e5cf6ce85221bf25f74a1ace05240e910d Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Thu, 26 Oct 2023 09:25:58 +0800 Subject: [PATCH] [clang][Sema] Resolving Panic Caused by Inconsistent Arguments in Variadic Template Variables When template variables are variadic, sema may panic, potentially leading to a situation where the number of function variables exceeds the number of template variables. The sema compares the template signature and function signature parameters one by one, which can trigger an assertion error. This PR, when encountering variadic templates, avoids comparing the template signature and function signature parameters one by one. issue: https://github.com/llvm/llvm-project/issues/70191 --- clang/lib/Sema/SemaOverload.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index db386fef0661c05..187922a8611614e 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -11044,6 +11044,14 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, I--; } + bool isVariadic = false; + for(unsigned N = 0 ; N < Fn->getNumParams(); N++) { + if( Fn->getParamDecl(N)->isParameterPack()) { + isVariadic = true; + break; + } + } + std::string FnDesc; std::pair<OverloadCandidateKind, OverloadCandidateSelect> FnKindPair = ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(), @@ -11053,7 +11061,7 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, QualType FromTy = Conv.Bad.getFromType(); QualType ToTy = Conv.Bad.getToType(); SourceRange ToParamRange = - !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : SourceRange(); + !isObjectArgument && !isVariadic ? Fn->getParamDecl(I)->getSourceRange() : SourceRange(); if (FromTy == S.Context.OverloadTy) { assert(FromExpr && "overload set argument came from implicit argument?"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits