================ @@ -1,7 +1,19 @@ -// RUN: %clang_cc1 -emit-llvm < %s | grep "zeroinitializer, i16 16877" +// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK,EMPTY +// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s --check-prefixes=CHECK,EMPTY-MSVC // PR4390 struct sysfs_dirent { - union { struct sysfs_elem_dir {} s_dir; }; + union { struct sysfs_elem_dir { int x; } s_dir; }; unsigned short s_mode; }; struct sysfs_dirent sysfs_root = { {}, 16877 }; + +// CHECK: @sysfs_root = {{.*}}global %struct.sysfs_dirent { %union.anon zeroinitializer, i16 16877 } + +struct Foo { + union { struct empty {} x; }; + unsigned short s_mode; +}; +struct Foo foo = { {}, 16877 }; + +// EMPTY: @foo = {{.*}}global %struct.Foo { i16 16877 } +// EMPTY-MSVC: @foo = {{.*}}global %struct.Foo { [4 x i8] undef, i16 16877 } ---------------- efriedma-quic wrote:
clang doesn't currently implement the C23 rules for empty-brace initialization... but I guess if you extend those rules to empty structs/unions (which aren't valid C, but ignoring that), we arguably should zero-init? But really, nobody should notice; this weird stuff is only realistically used for stuff like FAMs. Testcase which MSVC accepts: ``` struct Foo { unsigned short s_mode; struct empty {int a[0];} x; }; struct Foo f() { return (struct Foo){16877}; }; ``` See #78034/#97121. https://github.com/llvm/llvm-project/pull/96422 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits