================
@@ -19,9 +19,10 @@ struct B2 { struct E2 e; int x; int y; };
extern struct B2 b2;
int *a2 = &b2.y;
struct B2 b2 = { {}, 10, 20 };
-// CIR-DAG: cir.global external @b2 = #cir.const_record<{#cir.int<10> : !s32i,
#cir.int<20> : !s32i}> : !rec_B2
-// CIR-DAG: cir.global external @a2 = #cir.global_view<@b2, [1 : i32]> :
!cir.ptr<!s32i>
-// LLVM-DAG: @b2 = global %struct.B2 { i32 10, i32 20 }
+// CIR-DAG: cir.global external @b2 = #cir.const_record<{#cir.zero : !rec_E2,
#cir.int<10> : !s32i, #cir.int<20> : !s32i}> : !rec_B2
+// CIR-DAG: cir.global external @a2 = #cir.global_view<@b2, [2 : i32]> :
!cir.ptr<!s32i>
+// LLVMCIR-DAG: @b2 = global %struct.B2 { %struct.E2 zeroinitializer, i32 10,
i32 20 }
----------------
erichkeane wrote:
AH! I forgot to do the comment here where I was unsure, but I'm sure now :)
I'm going to add 1 more check line that makes this clear, but:
Given (a very similar example here that makes it obvious what is happening):
```
struct Empty{};
struct HasEmpty {
struct Empty e;
int i;
};
struct HasEmpty e;
```
In C++ mode we represent this as:
```
%struct.HasEmpty = type { %struct.Empty, i32 }
%struct.Empty = type { i8 }
```
The Empty being size==1 + the alignment of i32 causes the 4xi8 padding to be
there, but named.
In C mode, it is:
```
%struct.HasEmpty = type { %struct.Empty, i32 }
%struct.Empty = type { }
```
The Empty being size ==0 means it doesn't participate in layout. We zero init
it, which is meaningless for a zero-sized type.
I'm going to add a check to show that `E2` is empty here to make it clear.
https://github.com/llvm/llvm-project/pull/207033
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits