https://github.com/AV01DANC3 created 
https://github.com/llvm/llvm-project/pull/183933

When a VLA type is hidden behind a type alias and used as a local variable 
inside a local class or struct constructor, CodeGen could fail to emit VLA size 
information, leading to an assertion failure in getVLASize().

Desugar the variable type before emitting variably-modified type information.

Add a regression test.

>From ddc8d6f2e483d75ae3a270ae6701fa97180e26d0 Mon Sep 17 00:00:00 2001
From: Nikita Miroshnichenko <[email protected]>
Date: Sat, 28 Feb 2026 18:12:48 +0100
Subject: [PATCH] [clang][CodeGen] Fix crash for VLA alias in local class
 constructor

When a VLA type is hidden behind a type alias and used as a local
variable inside a local class or struct constructor, CodeGen could fail to emit
VLA size information, leading to an assertion failure in getVLASize().

Desugar the variable type before emitting variably-modified type
information.

Add a regression test.
---
 clang/lib/CodeGen/CGDecl.cpp                     |  6 ++++--
 clang/test/CodeGenCXX/vla-alias-local-struct.cpp | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/vla-alias-local-struct.cpp

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 8b5ffde1b73f3..a08e0a79671d1 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1493,8 +1493,10 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
   CharUnits alignment = getContext().getDeclAlign(&D);
 
   // If the type is variably-modified, emit all the VLA sizes for it.
-  if (Ty->isVariablyModifiedType())
-    EmitVariablyModifiedType(Ty);
+  if (Ty->isVariablyModifiedType()) {
+    QualType DesugaredTy = Ty.getDesugaredType(getContext());
+    EmitVariablyModifiedType(DesugaredTy);
+  }
 
   auto *DI = getDebugInfo();
   bool EmitDebugInfo = DI && CGM.getCodeGenOpts().hasReducedDebugInfo();
diff --git a/clang/test/CodeGenCXX/vla-alias-local-struct.cpp 
b/clang/test/CodeGenCXX/vla-alias-local-struct.cpp
new file mode 100644
index 0000000000000..bb33bdbcccb87
--- /dev/null
+++ b/clang/test/CodeGenCXX/vla-alias-local-struct.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=gnu++20 -emit-llvm %s -o - >/dev/null
+
+int f() { return 1; }
+
+int test0() {
+  using X = int[f()];
+
+  struct S {
+    S() {
+      X x;
+    }
+  } s;
+
+  return 0;
+}

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

Reply via email to