llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: None (AV01DANC3)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/183933.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDecl.cpp (+4-2) 
- (added) clang/test/CodeGenCXX/vla-alias-local-struct.cpp (+15) 


``````````diff
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;
+}

``````````

</details>


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

Reply via email to