[clang] [CIR] Refactor lowerUnion so unions get laid out consistently (PR #210709)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 20 07:25:49 PDT 2026


github-actions[bot] wrote:

<!--PREMERGE ADVISOR COMMENT: Linux-->
# :penguin: Linux x64 Test Results

* 92279 tests passed
* 811 tests skipped
* 2 tests failed

## Failed Tests
(click on a test name to see its output)

### Clang
<details>
<summary>Clang.CIR/CodeGen/unions-with-zero-init.cpp</summary>

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-cir -mmlir -mlir-print-ir-before=cir-cxxabi-lowering /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir 2> /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-before.cir
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-cir -mmlir -mlir-print-ir-before=cir-cxxabi-lowering /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-BEFORE --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-before.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-BEFORE --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-before.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-AFTER --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-AFTER --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll
# note: command had no output on stdout or stderr
# RUN: at line 5
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=LLVM,LLVMCIR --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=LLVM,LLVMCIR --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp:34:14: error: LLVM-DAG: expected string not found in input
# | // LLVM-DAG: @__const._Z1fv.inner_a2 = private {{.*}}constant { i32, [4 x i8] } { i32 12, [4 x i8] undef }
# |              ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll:1:1: note: scanning from here
# | ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp'
# | ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll:12:1: note: possible intended match here
# | @__const._Z1fv.inner_a2 = private constant %union.inner_aggregate2 { i64 12 }
# | ^
# | 
# | Input file: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |           1: ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp' 
# | dag:34'0    {                                                                                                                           search range start (exclusive)
# | dag:34'1                                                                                                                                error: no match found in search range
# |           2: source_filename = "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp" 
# |           3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 
# |           4: target triple = "x86_64-unknown-linux-gnu" 
# |           5:  
# |           6: %union.inner_aggregate2 = type { i64 } 
# |           7: %union.outer_aggregate = type { i64 } 
# |           8: %union.outer_aggregate2 = type { i64 } 
# |           9: %union.outer_aggregate3 = type { i64 } 
# |          10: %union.inner_aggregate = type { i64 } 
# |          11:  
# |          12: @__const._Z1fv.inner_a2 = private constant %union.inner_aggregate2 { i64 12 } 
# | dag:34'2     ?                                                                               possible intended match
# |          13: @p = global i64 -1, align 8 
# |          14: @outer_a1 = global %union.outer_aggregate zeroinitializer, align 8 
# |          15: @outer_a2 = global %union.outer_aggregate2 { i64 32 }, align 8 
# |          16: @outer_a3 = global %union.outer_aggregate3 { i64 -1 }, align 8 
# |          17: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_unions_with_zero_init.cpp, ptr null }] 
# |          18:  
# |          19: define internal void @__cxx_global_var_init() { 
# |          20:  %1 = load i64, ptr @p, align 8 
# |          21:  store i64 %1, ptr @outer_a1, align 8 
# |          22:  ret void 
# |          23: } 
# |          24:  
# |          25: ; Function Attrs: noinline 
# |          26: define dso_local void @_Z1fv() #0 { 
# | dag:34'3                                   }       search range end (exclusive)
# |          27:  %1 = alloca %union.inner_aggregate, i64 1, align 8 
# |          28:  %2 = alloca %union.inner_aggregate2, i64 1, align 8 
# |          29:  %3 = load i64, ptr @p, align 8 
# |          30:  store i64 %3, ptr %1, align 8 
# |          31:  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %2, ptr align 8 @__const._Z1fv.inner_a2, i64 8, i1 false) 
# |           .
# |           .
# |           .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

```
</details>
<details>
<summary>Clang.CIR/CodeGen/unions-with-zero-init.cpp</summary>

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-cir -mmlir -mlir-print-ir-before=cir-cxxabi-lowering /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir 2> /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-before.cir
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-cir -mmlir -mlir-print-ir-before=cir-cxxabi-lowering /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-BEFORE --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-before.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-BEFORE --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-before.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-AFTER --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=CIR,CIR-AFTER --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp.cir /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/24/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -Wno-unused-value -emit-llvm /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp -o /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll
# note: command had no output on stdout or stderr
# RUN: at line 5
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=LLVM,LLVMCIR --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck --check-prefix=LLVM,LLVMCIR --input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp:34:14: error: LLVM-DAG: expected string not found in input
# | // LLVM-DAG: @__const._Z1fv.inner_a2 = private {{.*}}constant { i32, [4 x i8] } { i32 12, [4 x i8] undef }
# |              ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll:1:1: note: scanning from here
# | ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp'
# | ^
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll:12:1: note: possible intended match here
# | @__const._Z1fv.inner_a2 = private constant %union.inner_aggregate2 { i64 12 }
# | ^
# | 
# | Input file: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/unions-with-zero-init.cpp.tmp-cir.ll
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |           1: ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp' 
# | dag:34'0    {                                                                                                                           search range start (exclusive)
# | dag:34'1                                                                                                                                error: no match found in search range
# |           2: source_filename = "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/unions-with-zero-init.cpp" 
# |           3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 
# |           4: target triple = "x86_64-unknown-linux-gnu" 
# |           5:  
# |           6: %union.inner_aggregate2 = type { i64 } 
# |           7: %union.outer_aggregate = type { i64 } 
# |           8: %union.outer_aggregate2 = type { i64 } 
# |           9: %union.outer_aggregate3 = type { i64 } 
# |          10: %union.inner_aggregate = type { i64 } 
# |          11:  
# |          12: @__const._Z1fv.inner_a2 = private constant %union.inner_aggregate2 { i64 12 } 
# | dag:34'2     ?                                                                               possible intended match
# |          13: @p = global i64 -1, align 8 
# |          14: @outer_a1 = global %union.outer_aggregate zeroinitializer, align 8 
# |          15: @outer_a2 = global %union.outer_aggregate2 { i64 32 }, align 8 
# |          16: @outer_a3 = global %union.outer_aggregate3 { i64 -1 }, align 8 
# |          17: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_unions_with_zero_init.cpp, ptr null }] 
# |          18:  
# |          19: define internal void @__cxx_global_var_init() { 
# |          20:  %1 = load i64, ptr @p, align 8 
# |          21:  store i64 %1, ptr @outer_a1, align 8 
# |          22:  ret void 
# |          23: } 
# |          24:  
# |          25: ; Function Attrs: noinline 
# |          26: define dso_local void @_Z1fv() #0 { 
# | dag:34'3                                   }       search range end (exclusive)
# |          27:  %1 = alloca %union.inner_aggregate, i64 1, align 8 
# |          28:  %2 = alloca %union.inner_aggregate2, i64 1, align 8 
# |          29:  %3 = load i64, ptr @p, align 8 
# |          30:  store i64 %3, ptr %1, align 8 
# |          31:  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %2, ptr align 8 @__const._Z1fv.inner_a2, i64 8, i1 false) 
# |           .
# |           .
# |           .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

```
</details>

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.

https://github.com/llvm/llvm-project/pull/210709


More information about the cfe-commits mailing list