[clang] Fix #99858 (PR #99859)

2024-07-22 Thread Ahmet Faruk Aktaş via cfe-commits

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?= 
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 *Instantiation =
   CurrentInstantiationScope->findInstantiationOf(
   ParmPack.first.get());
-  if (Instantiation->is()) {
+  if (Instantiation && Instantiation->is()) {
 // We could expand this function parameter pack.
 NewPackSize = Instantiation->get()->size();
   } else {
@@ -850,7 +850,7 @@ std::optional Sema::getNumArgumentsInExpansion(
 llvm::PointerUnion *Instantiation =
 CurrentInstantiationScope->findInstantiationOf(
 Unexpanded[I].first.get());
-if (Instantiation->is())
+if (Instantiation && Instantiation->is())
   // The pattern refers to an unexpanded pack. We're not ready to 
expand
   // this pack yet.
   return std::nullopt;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix #99858 (PR #99859)

2024-07-22 Thread Ahmet Faruk Aktaş via cfe-commits

ahfakt wrote:

I tried to represent the error with a sample code but can not reproduce. It may 
be removed because of unused template function optimization. In my project it 
is in a template library which is not a compiled context. I just wanted to 
point the issue so someone who is experienced in the project can do a more 
detailed development on potential similar issues(all references to 
findInstantiationOf function). It is an obvious missing null check bug. If i 
have a free time i will try to provide test case.

Thanks for your quick response.

https://github.com/llvm/llvm-project/pull/99859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits