https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/208112

>From 67ba08af2c9c233c25fa1e10e556b803b3cfe25d Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <[email protected]>
Date: Tue, 7 Jul 2026 15:18:42 -0700
Subject: [PATCH] [Clang] Adjust assert in addUnsizedArray to check Base is set
 before checking its type

In addUnsizedArray we attempt to check the type of Base in an assert but don't
verify if it set before doing so. This can lead to a crash, check Base is set
before checking its type and add a regression test.

Fixes: https://github.com/llvm/llvm-project/issues/44212
---
 clang/lib/AST/ExprConstant.cpp                       | 2 +-
 clang/test/SemaCXX/constexpr-array-unknown-bound.cpp | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 109dc627133f2..42b422aecb8e9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1558,7 +1558,7 @@ namespace {
         return;
       }
       if (checkSubobject(Info, E, CSK_ArrayToPointer)) {
-        assert(getType(Base).getNonReferenceType()->isPointerType() ||
+        assert(!Base || getType(Base).getNonReferenceType()->isPointerType() ||
                getType(Base).getNonReferenceType()->isArrayType());
         Designator.FirstEntryIsAnUnsizedArray = true;
         Designator.addUnsizedArrayUnchecked(ElemTy);
diff --git a/clang/test/SemaCXX/constexpr-array-unknown-bound.cpp 
b/clang/test/SemaCXX/constexpr-array-unknown-bound.cpp
index 2b09a1cf8be70..13d541dcca689 100644
--- a/clang/test/SemaCXX/constexpr-array-unknown-bound.cpp
+++ b/clang/test/SemaCXX/constexpr-array-unknown-bound.cpp
@@ -26,3 +26,9 @@ void g(int i) {  // expected-note 2{{declared here}}
                      expected-note {{function parameter 'i' with unknown value 
cannot be used in a constant expression}}
   constexpr int m = ((void)arr2[2], 0); // expected-error {{constant 
expression}}
 }
+
+namespace GH44212 {
+  int* f() {
+    return *(int(*)[])0;
+  }
+}

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

Reply via email to