Author: Qixi
Date: 2026-07-03T15:09:51+01:00
New Revision: ee82fc0ca6d276c5fe8b19b7f8c24b8a64550193

URL: 
https://github.com/llvm/llvm-project/commit/ee82fc0ca6d276c5fe8b19b7f8c24b8a64550193
DIFF: 
https://github.com/llvm/llvm-project/commit/ee82fc0ca6d276c5fe8b19b7f8c24b8a64550193.diff

LOG: [Clang] Fix crash on subscripting a complete matrix subscript expression 
(#207317)

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp
    clang/test/Sema/matrix-type-operators.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index de697448ee9a8..592cb1d588370 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5085,12 +5085,10 @@ 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();
 
-    assert(matSubscriptE->isIncomplete() &&
-           "base has to be an incomplete matrix subscript");
     return CreateBuiltinMatrixSubscriptExpr(matSubscriptE->getBase(),
                                             matSubscriptE->getRowIdx(),
                                             ArgExprs.front(), rbLoc);

diff  --git a/clang/test/Sema/matrix-type-operators.c 
b/clang/test/Sema/matrix-type-operators.c
index c83685fc7c640..2a3bd392a6b88 100644
--- a/clang/test/Sema/matrix-type-operators.c
+++ b/clang/test/Sema/matrix-type-operators.c
@@ -228,3 +228,8 @@ float *address_of_element(sx5x10_t *a) {
   return &(*a)[0][1];
   // expected-error@-1 {{address of matrix element requested}}
 }
+
+void test_triple_subscript(sx5x10_t a) {
+  float v13 = a[0][0][0];
+  // expected-error@-1 {{subscripted value is not an array, pointer, or 
vector}}
+}


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

Reply via email to