185 lines · cpp
1// REQUIRES: arm-registered-target2// RUN: %clang_cc1 -triple arm-none-none-eabi \3// RUN: -O2 \4// RUN: -target-cpu cortex-a8 \5// RUN: -emit-llvm -o - %s | FileCheck %s6 7extern "C" {8 9// CHECK: @sizeof_OverSizedBitfield ={{.*}} global i32 810// CHECK: @alignof_OverSizedBitfield ={{.*}} global i32 811// CHECK: @sizeof_VeryOverSizedBitfield ={{.*}} global i32 1612// CHECK: @alignof_VeryOverSizedBitfield ={{.*}} global i32 813 14// Base case, nothing interesting.15struct S {16 int x, y;17};18 19void f0(int, S);20void f0m(int, int, int, int, int, S);21void g0() {22 S s = {6, 7};23 f0(1, s);24 f0m(1, 2, 3, 4, 5, s);25}26// CHECK: define{{.*}} void @g027// CHECK: call void @f0(i32 noundef 1, [2 x i32] [i32 6, i32 7]28// CHECK: call void @f0m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [2 x i32] [i32 6, i32 7]29// CHECK: declare void @f0(i32 noundef, [2 x i32])30// CHECK: declare void @f0m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [2 x i32])31 32// Aligned struct, passed according to its natural alignment.33struct __attribute__((aligned(8))) S8 {34 int x, y;35} s8;36 37void f1(int, S8);38void f1m(int, int, int, int, int, S8);39void g1() {40 S8 s = {6, 7};41 f1(1, s);42 f1m(1, 2, 3, 4, 5, s);43}44// CHECK: define{{.*}} void @g145// CHECK: call void @f1(i32 noundef 1, [2 x i32] [i32 6, i32 7]46// CHECK: call void @f1m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [2 x i32] [i32 6, i32 7]47// CHECK: declare void @f1(i32 noundef, [2 x i32])48// CHECK: declare void @f1m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [2 x i32])49 50// Aligned struct, passed according to its natural alignment.51struct alignas(16) S16 {52 int x, y;53};54 55extern "C" void f2(int, S16);56extern "C" void f2m(int, int, int, int, int, S16);57 58void g2() {59 S16 s = {6, 7};60 f2(1, s);61 f2m(1, 2, 3, 4, 5, s);62}63// CHECK: define{{.*}} void @g264// CHECK: call void @f2(i32 noundef 1, [4 x i32] [i32 6, i32 765// CHECK: call void @f2m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [4 x i32] [i32 6, i32 766// CHECK: declare void @f2(i32 noundef, [4 x i32])67// CHECK: declare void @f2m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [4 x i32])68 69// Increased natural alignment.70struct SF8 {71 int x __attribute__((aligned(8)));72 int y;73};74 75void f3(int, SF8);76void f3m(int, int, int, int, int, SF8);77void g3() {78 SF8 s = {6, 7};79 f3(1, s);80 f3m(1, 2, 3, 4, 5, s);81}82// CHECK: define{{.*}} void @g383// CHECK: call void @f3(i32 noundef 1, [1 x i64] [i64 30064771078]84// CHECK: call void @f3m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [1 x i64] [i64 30064771078]85// CHECK: declare void @f3(i32 noundef, [1 x i64])86// CHECK: declare void @f3m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [1 x i64])87 88// Increased natural alignment, capped to 8 though.89struct SF16 {90 int x;91 int y alignas(16);92 int z, a, b, c, d, e, f, g, h, i, j, k;93};94 95void f4(int, SF16);96void f4m(int, int, int, int, int, SF16);97void g4() {98 SF16 s = {6, 7};99 f4(1, s);100 f4m(1, 2, 3, 4, 5, s);101}102// CHECK: define{{.*}} void @g4103// CHECK: call void @f4(i32 noundef 1, ptr noundef nonnull byval(%struct.SF16) align 8104// CHECK: call void @f4m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, ptr noundef nonnull byval(%struct.SF16) align 8105// CHECK: declare void @f4(i32 noundef, ptr noundef byval(%struct.SF16) align 8)106// CHECK: declare void @f4m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef byval(%struct.SF16) align 8)107 108// Packed structure.109struct __attribute__((packed)) P {110 int x;111 long long u;112};113 114void f5(int, P);115void f5m(int, int, int, int, int, P);116void g5() {117 P s = {6, 7};118 f5(1, s);119 f5m(1, 2, 3, 4, 5, s);120}121// CHECK: define{{.*}} void @g5122// CHECK: call void @f5(i32 noundef 1, [3 x i32] [i32 6, i32 7, i32 0])123// CHECK: call void @f5m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [3 x i32] [i32 6, i32 7, i32 0])124// CHECK: declare void @f5(i32 noundef, [3 x i32])125// CHECK: declare void @f5m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [3 x i32])126 127 128// Packed and aligned, alignement causes padding at the end.129struct __attribute__((packed, aligned(8))) P8 {130 int x;131 long long u;132};133 134void f6(int, P8);135void f6m(int, int, int, int, int, P8);136void g6() {137 P8 s = {6, 7};138 f6(1, s);139 f6m(1, 2, 3, 4, 5, s);140}141// CHECK: define{{.*}} void @g6142// CHECK: call void @f6(i32 noundef 1, [4 x i32] [i32 6, i32 7, i32 0, i32 undef])143// CHECK: call void @f6m(i32 noundef 1, i32 noundef 2, i32 noundef 3, i32 noundef 4, i32 noundef 5, [4 x i32] [i32 6, i32 7, i32 0, i32 undef])144// CHECK: declare void @f6(i32 noundef, [4 x i32])145// CHECK: declare void @f6m(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, [4 x i32])146 147// Over-sized bitfield, which results in a 64-bit container type, so 64-bit148// alignment.149struct OverSizedBitfield {150 int x : 64;151};152 153unsigned sizeof_OverSizedBitfield = sizeof(OverSizedBitfield);154unsigned alignof_OverSizedBitfield = alignof(OverSizedBitfield);155 156// CHECK: define{{.*}} void @g7157// CHECK: call void @f7(i32 noundef 1, [1 x i64] [i64 42])158// CHECK: declare void @f7(i32 noundef, [1 x i64])159void f7(int a, OverSizedBitfield b);160void g7() {161 OverSizedBitfield s = {42};162 f7(1, s);163}164 165// There are no 128-bit fundamental data types defined by AAPCS32, so this gets166// a 64-bit container plus 64 bits of padding, giving it a size of 16 bytes and167// alignment of 8 bytes.168struct VeryOverSizedBitfield {169 int x : 128;170};171 172unsigned sizeof_VeryOverSizedBitfield = sizeof(VeryOverSizedBitfield);173unsigned alignof_VeryOverSizedBitfield = alignof(VeryOverSizedBitfield);174 175// CHECK: define{{.*}} void @g8176// CHECK: call void @f8(i32 noundef 1, [2 x i64] [i64 42, i64 0])177// CHECK: declare void @f8(i32 noundef, [2 x i64])178void f8(int a, VeryOverSizedBitfield b);179void g8() {180 VeryOverSizedBitfield s = {42};181 f8(1, s);182}183 184}185