91 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG7 8struct padding_after_field {9 char c;10 int i;11};12 13struct bitfield_with_padding {14 unsigned int a : 3;15 unsigned int b : 5;16 int c;17};18 19struct tail_padding {20 int a;21 char b;22};23 24struct multiple_padding {25 char a;26 short b;27 long long c;28};29 30void test_zero_init_padding(void) {31 static const struct padding_after_field paf = {1, 42};32 static const struct bitfield_with_padding bfp = {1, 2, 99};33 static const struct tail_padding tp = {10, 20};34 static const struct multiple_padding mp = {5, 10, 100};35}36 37// Type definitions for anonymous structs with padding38// CIR-DAG: !rec_anon_struct = !cir.record<struct {!s8i, !u8i, !s16i, !cir.array<!u8i x 4>, !s64i}>39// CIR-DAG: !rec_anon_struct1 = !cir.record<struct {!s32i, !s8i, !cir.array<!u8i x 3>}>40// CIR-DAG: !rec_anon_struct2 = !cir.record<struct {!u8i, !cir.array<!u8i x 3>, !s32i}>41// CIR-DAG: !rec_anon_struct3 = !cir.record<struct {!s8i, !cir.array<!u8i x 3>, !s32i}>42 43// paf: char + 3 bytes padding + int -> uses !rec_anon_struct344// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.paf = #cir.const_record<{45// CIR-DAG-SAME: #cir.int<1> : !s8i,46// CIR-DAG-SAME: #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>,47// CIR-DAG-SAME: #cir.int<42> : !s32i48// CIR-DAG-SAME: }> : !rec_anon_struct349 50// bfp: unsigned bitfield byte + 3 bytes padding + int -> uses !rec_anon_struct251// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.bfp = #cir.const_record<{52// CIR-DAG-SAME: #cir.int<17> : !u8i,53// CIR-DAG-SAME: #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>,54// CIR-DAG-SAME: #cir.int<99> : !s32i55// CIR-DAG-SAME: }> : !rec_anon_struct256 57// tp: int + char + 3 bytes tail padding -> uses !rec_anon_struct158// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.tp = #cir.const_record<{59// CIR-DAG-SAME: #cir.int<10> : !s32i,60// CIR-DAG-SAME: #cir.int<20> : !s8i,61// CIR-DAG-SAME: #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>62// CIR-DAG-SAME: }> : !rec_anon_struct163 64// mp: char + 1 byte padding + short + 4 bytes padding + long long -> uses !rec_anon_struct65// CIR-DAG: cir.global "private" constant internal dso_local @test_zero_init_padding.mp = #cir.const_record<{66// CIR-DAG-SAME: #cir.int<5> : !s8i,67// CIR-DAG-SAME: #cir.zero : !u8i,68// CIR-DAG-SAME: #cir.int<10> : !s16i,69// CIR-DAG-SAME: #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 4>,70// CIR-DAG-SAME: #cir.int<100> : !s64i71// CIR-DAG-SAME: }> : !rec_anon_struct72 73// CIR-LABEL: cir.func {{.*}}@test_zero_init_padding74// CIR: cir.return75 76// LLVM-DAG: @test_zero_init_padding.paf = internal constant { i8, [3 x i8], i32 } { i8 1, [3 x i8] zeroinitializer, i32 42 }77// LLVM-DAG: @test_zero_init_padding.bfp = internal constant { i8, [3 x i8], i32 } { i8 17, [3 x i8] zeroinitializer, i32 99 }78// LLVM-DAG: @test_zero_init_padding.tp = internal constant { i32, i8, [3 x i8] } { i32 10, i8 20, [3 x i8] zeroinitializer }79// LLVM-DAG: @test_zero_init_padding.mp = internal constant { i8, i8, i16, [4 x i8], i64 } { i8 5, i8 0, i16 10, [4 x i8] zeroinitializer, i64 100 }80 81// LLVM-LABEL: define{{.*}} void @test_zero_init_padding82// LLVM: ret void83 84// OGCG-DAG: @test_zero_init_padding.paf = internal constant { i8, [3 x i8], i32 } { i8 1, [3 x i8] zeroinitializer, i32 42 }85// OGCG-DAG: @test_zero_init_padding.bfp = internal constant { i8, [3 x i8], i32 } { i8 17, [3 x i8] zeroinitializer, i32 99 }86// OGCG-DAG: @test_zero_init_padding.tp = internal constant { i32, i8, [3 x i8] } { i32 10, i8 20, [3 x i8] zeroinitializer }87// OGCG-DAG: @test_zero_init_padding.mp = internal constant { i8, i8, i16, [4 x i8], i64 } { i8 5, i8 0, i16 10, [4 x i8] zeroinitializer, i64 100 }88 89// OGCG-LABEL: define{{.*}} void @test_zero_init_padding90// OGCG: ret void91