[clang] Fix #99858 (PR #99859)

Ahmet Faruk Aktaş via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 03:28:50 PDT 2024


https://github.com/ahfakt created https://github.com/llvm/llvm-project/pull/99859

Fix crash caused by template parameter pack expansion when no instantiation exist.

>From a84e2af497f827996afe9a820904f9f1d2f9fb22 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ahmet=20Faruk=20Akta=C5=9F?= <a.farukakts at outlook.com>
Date: Mon, 22 Jul 2024 13:28:01 +0300
Subject: [PATCH] Fix #99858

Fix crash caused by template parameter pack expansion when no instantiation exist.
---
 clang/lib/Sema/SemaTemplateVariadic.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 3d4ccaf68c700..70ceea1dda65b 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -732,7 +732,7 @@ bool Sema::CheckParameterPacksForExpansion(
       llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
           CurrentInstantiationScope->findInstantiationOf(
               ParmPack.first.get<NamedDecl *>());
-      if (Instantiation->is<DeclArgumentPack *>()) {
+      if (Instantiation && Instantiation->is<DeclArgumentPack *>()) {
         // We could expand this function parameter pack.
         NewPackSize = Instantiation->get<DeclArgumentPack *>()->size();
       } else {
@@ -850,7 +850,7 @@ std::optional<unsigned> Sema::getNumArgumentsInExpansion(
         llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation =
             CurrentInstantiationScope->findInstantiationOf(
                 Unexpanded[I].first.get<NamedDecl *>());
-        if (Instantiation->is<Decl *>())
+        if (Instantiation && Instantiation->is<Decl *>())
           // The pattern refers to an unexpanded pack. We're not ready to expand
           // this pack yet.
           return std::nullopt;



More information about the cfe-commits mailing list