https://github.com/Sriraj2911 created 
https://github.com/llvm/llvm-project/pull/235408

### Fixes #225792

**Problem**
Malformed concept template parameters (e.g., `template <template <class> 
concept... CC>`) result in an assertion failure in 
`CheckVarOrConceptTemplateTemplateId`:
`Assertion 'Parameter && "A variable template id without template?"' failed.`

**Solution**
Added a check for `!Parameter || Parameter->isInvalidDecl()` in 
`SemaTemplate.cpp` to gracefully exit with `ExprError()` when processing 
invalid declarations instead of crashing.

**Testing**
Added regression test `clang/test/SemaCXX/225792.cpp` and verified via 
`llvm-lit`.

**Use of LLM**
- To understand the exact problem of the issue #225792 
- To filter down the possible causes of this particular crash

>From cf9c75351b1e8ee6af6eee35e4364e5e8daccad0 Mon Sep 17 00:00:00 2001
From: Sriraj2911 <[email protected]>
Date: Thu, 22 Oct 2026 13:19:00 +0530
Subject: [PATCH 1/2] [clang][AST] Fix assertion crash in
 LValue::addUnsizedArray on invalid base type

When evaluating array subscript designators on an invalid or redeclared
declaration (such as evaluating  on ),
can receive a Base object whose type is neither an array nor a pointer.
This triggered an assertion failure at ExprConstant.cpp:1542.

This patch adds safety checks for invalid declarations, error-containing types, 
and non-pointer/non-array base types before updating the designator, safely 
marking the designator as invalid instead of crashing.

Fixes #225046
---
 clang/lib/AST/ExprConstant.cpp | 29 +++++++++++++++++++++++++++++
 clang/test/SemaCXX/225046.cpp  | 10 ++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 clang/test/SemaCXX/225046.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6d390032e2c717..17d3855f0d907a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1538,7 +1538,36 @@ namespace {
         Designator.setInvalid();
         return;
       }
+
+      if(Base){
+        // Mark invalid and return early if Base points to an invalid decl
+        if(const auto *VD = Base.dyn_cast<const ValueDecl *>()){
+          if(VD->isInvalidDecl()){
+            Designator.setInvalid();
+            return;
+          }
+        }
+        // Mark invalid and return early if Base points to an invalid type
+        QualType BaseTy = getType(Base).getNonReferenceType();
+        if(BaseTy.isNull() || BaseTy->containsErrors() || 
(!BaseTy->isPointerType() && !BaseTy->isArrayType())){
+          Designator.setInvalid();
+          return;
+        }
+      }
+
       if (checkSubobject(Info, E, CSK_ArrayToPointer)) {
+        /*
+        When a user writes invalid C++ code (e.g., declaring a 
+        variable as void and then illegally re-declaring/indexing 
+        it as an array), the AST node representing Base ends up
+        with an invalid or unexpected type structure. 
+        => getType(Base) does not fulfill either conditions, causing
+        the assert statement to fail and crash the compiler.
+        */
+       /*
+       To get a clean error, add a check before entering the above
+       if clause
+       */
         assert(!Base || getType(Base).getNonReferenceType()->isPointerType() ||
                getType(Base).getNonReferenceType()->isArrayType());
         Designator.FirstEntryIsAnUnsizedArray = true;
diff --git a/clang/test/SemaCXX/225046.cpp b/clang/test/SemaCXX/225046.cpp
new file mode 100644
index 00000000000000..98c22f8b1a5691
--- /dev/null
+++ b/clang/test/SemaCXX/225046.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void a; // expected-error {{variable has incomplete type 'void'}}
+extern int a[];
+
+void test() {
+  // Force constant evaluation of &a[6].
+  // Before the fix this asserted in LValue::addUnsizedArray.
+  (void)__builtin_constant_p(&a[6]);
+}
\ No newline at end of file

>From cf0e22aed41b9a47606546747366d4ac463ae642 Mon Sep 17 00:00:00 2001
From: Sriraj2911 <[email protected]>
Date: Sun, 25 Oct 2026 11:45:45 +0530
Subject: [PATCH 2/2] [clang][Sema] Fix assertion crash on invalid concept
 template parameter (#225792)

Fixes an assertion failure ('Parameter && 'A variable template id without 
template?'') in CheckVarOrConceptTemplateTemplateId when processing malformed 
concept template parameters.

When substituting template arguments into an invalid concept template parameter 
list (such as ),  can end up as nullptr, causing an assertion crash. This patch 
adds a null and invalid-declaration guard check before asserting on the 
Parameter pointer.

Fixes #225792
---
 clang/lib/Sema/SemaTemplate.cpp |  3 +++
 clang/test/SemaCXX/225792.cpp   | 10 ++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/SemaCXX/225792.cpp

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5a61cb852d15e5..0b4d7343b901f5 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4874,6 +4874,9 @@ ExprResult Sema::CheckVarOrConceptTemplateTemplateId(
     const TemplateArgumentListInfo *TemplateArgs) {
   TemplateTemplateParmDecl *Parameter =
       Template.getAsTemplateTemplateParmDecl();
+  if(!Parameter || Parameter->isInvalidDecl()){
+    return ExprError();
+  }
   assert(Parameter && "A variable template id without template?");
 
   if (Parameter->templateParameterKind() !=
diff --git a/clang/test/SemaCXX/225792.cpp b/clang/test/SemaCXX/225792.cpp
new file mode 100644
index 00000000000000..eec8be8c100d9f
--- /dev/null
+++ b/clang/test/SemaCXX/225792.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+template <class T>
+concept C = true;
+
+template <template <class> concept... CC> // expected-error {{concept template 
parameter is a C++2c extension}}
+int foo(CC &) { return 42; } // expected-error {{expected 'auto' or 
'decltype(auto)' after concept name}} \
+                             // expected-note {{candidate template ignored: 
constraints not satisfied}}
+
+static_assert(foo<C>(0) == 42, ""); // expected-error {{no matching function 
for call to 'foo'}}
\ No newline at end of file

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to