https://github.com/Qixi-1 updated 
https://github.com/llvm/llvm-project/pull/207317

>From 54c5844fbe439ea93519eb3912c3c62d760bdfb6 Mon Sep 17 00:00:00 2001
From: Qixi-1 <[email protected]>
Date: Thu, 11 Jun 2026 15:19:21 +0800
Subject: [PATCH] [Clang] Fix crash on subscripting a complete matrix subscript
 expression

Subscripting a complete MatrixSubscriptExpr (which has scalar type)
caused an assertion failure in ActOnArraySubscriptExpr because the code
unconditionally asserted isIncomplete() on any MatrixSubscriptExpr base.

Fix by guarding the matrix subscript path with an isIncomplete() check,
allowing complete matrix subscript expressions to fall through to the
standard subscript handling, which emits an appropriate diagnostic.

Fixes #203163
---
 clang/lib/Sema/SemaExpr.cpp             | 2 +-
 clang/test/Sema/matrix-type-operators.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ad6e7183cb3a4..38482f55a447a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5078,7 +5078,7 @@ ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr 
*base,
   // If the base is a MatrixSubscriptExpr, try to create a new
   // MatrixSubscriptExpr.
   auto *matSubscriptE = dyn_cast<MatrixSubscriptExpr>(base);
-  if (matSubscriptE) {
+  if (matSubscriptE && matSubscriptE->isIncomplete()) {
     if (CheckAndReportCommaError(ArgExprs.front()))
       return ExprError();
 
diff --git a/clang/test/Sema/matrix-type-operators.c 
b/clang/test/Sema/matrix-type-operators.c
index c83685fc7c640..cfe3d2d59efee 100644
--- a/clang/test/Sema/matrix-type-operators.c
+++ b/clang/test/Sema/matrix-type-operators.c
@@ -228,3 +228,5 @@ float *address_of_element(sx5x10_t *a) {
   return &(*a)[0][1];
   // expected-error@-1 {{address of matrix element requested}}
 }
+
+float v13 = a[0][0][0]; // expected-error {{subscripted value is not an array, 
pointer, or vector}}
\ 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