|
| 1 | +// GVN may create indirect constants with higher alignment than their type requires. Verify that we |
| 2 | +// do not ICE during codegen, and that the LLVM constant has the higher alignment. |
| 3 | +// |
| 4 | +// compile-flags: -Zmir-opt-level=0 -Zmir-enable-passes=+GVN |
| 5 | +// compile-flags: -Cno-prepopulate-passes |
| 6 | +// only-64bit |
| 7 | + |
| 8 | +struct S(i32); |
| 9 | + |
| 10 | +struct SmallStruct(f32, Option<S>, &'static [f32]); |
| 11 | + |
| 12 | +// CHECK: @0 = private unnamed_addr constant |
| 13 | +// CHECK-SAME: , align 8 |
| 14 | + |
| 15 | +fn main() { |
| 16 | + // CHECK-LABEL: @_ZN20overaligned_constant4main |
| 17 | + // CHECK: [[full:%_.*]] = alloca %SmallStruct, align 8 |
| 18 | + // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[full]], ptr align 8 @0, i64 32, i1 false) |
| 19 | + // CHECK: %b.0 = load i32, ptr @0, align 4, |
| 20 | + // CHECK: %b.1 = load i32, ptr getelementptr inbounds ({ i32, i32 }, ptr @0, i32 0, i32 1), align 4 |
| 21 | + let mut s = S(1); |
| 22 | + |
| 23 | + s.0 = 3; |
| 24 | + |
| 25 | + // SMALL_VAL corresponds to a MIR allocation with alignment 8. |
| 26 | + const SMALL_VAL: SmallStruct = SmallStruct(4., Some(S(1)), &[]); |
| 27 | + |
| 28 | + // In pre-codegen MIR: |
| 29 | + // `a` is a scalar 4. |
| 30 | + // `b` is an indirect constant at `SMALL_VAL`'s alloc with 0 offset. |
| 31 | + // `c` is the empty slice. |
| 32 | + // |
| 33 | + // As a consequence, during codegen, we create a LLVM allocation for `SMALL_VAL`, with |
| 34 | + // alignment 8, but only use the `Option<S>` field, at offset 0 with alignment 4. |
| 35 | + let SmallStruct(a, b, c) = SMALL_VAL; |
| 36 | +} |
0 commit comments