1 | // RUN: %clang_cc1 -triple arm64-apple-ios7.0 -target-abi darwinpcs -emit-llvm -o - %s | FileCheck %s |
2 | // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - -x c %s | FileCheck %s --check-prefix=CHECK-GNU-C |
3 | // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-GNU-CXX |
4 | |
5 | // Empty structs are ignored for PCS purposes on Darwin and in C mode elsewhere. |
6 | // In C++ mode on ELF they consume a register slot though. Functions are |
7 | // slightly bigger than minimal to make confirmation against actual GCC |
8 | // behaviour easier. |
9 | |
10 | #if __cplusplus |
11 | #define EXTERNC extern "C" |
12 | #else |
13 | #define EXTERNC |
14 | #endif |
15 | |
16 | struct Empty {}; |
17 | |
18 | // CHECK: define i32 @empty_arg(i32 %a) |
19 | // CHECK-GNU-C: define i32 @empty_arg(i32 %a) |
20 | // CHECK-GNU-CXX: define i32 @empty_arg(i8 %e.coerce, i32 %a) |
21 | EXTERNC int empty_arg(struct Empty e, int a) { |
22 | return a; |
23 | } |
24 | |
25 | // CHECK: define void @empty_ret() |
26 | // CHECK-GNU-C: define void @empty_ret() |
27 | // CHECK-GNU-CXX: define void @empty_ret() |
28 | EXTERNC struct Empty empty_ret() { |
29 | struct Empty e; |
30 | return e; |
31 | } |
32 | |
33 | // However, what counts as "empty" is a baroque mess. This is super-empty, it's |
34 | // ignored even in C++ mode. It also has sizeof == 0, violating C++, but that's |
35 | // legacy for you: |
36 | |
37 | struct SuperEmpty { |
38 | int arr[0]; |
39 | }; |
40 | |
41 | // CHECK: define i32 @super_empty_arg(i32 %a) |
42 | // CHECK-GNU-C: define i32 @super_empty_arg(i32 %a) |
43 | // CHECK-GNU-CXX: define i32 @super_empty_arg(i32 %a) |
44 | EXTERNC int super_empty_arg(struct SuperEmpty e, int a) { |
45 | return a; |
46 | } |
47 | |
48 | // This is not empty. It has 0 size but consumes a register slot for GCC. |
49 | |
50 | struct SortOfEmpty { |
51 | struct SuperEmpty e; |
52 | }; |
53 | |
54 | // CHECK: define i32 @sort_of_empty_arg(i32 %a) |
55 | // CHECK-GNU-C: define i32 @sort_of_empty_arg(i32 %a) |
56 | // CHECK-GNU-CXX: define i32 @sort_of_empty_arg(i8 %e.coerce, i32 %a) |
57 | EXTERNC int sort_of_empty_arg(struct Empty e, int a) { |
58 | return a; |
59 | } |
60 | |
61 | // CHECK: define void @sort_of_empty_ret() |
62 | // CHECK-GNU-C: define void @sort_of_empty_ret() |
63 | // CHECK-GNU-CXX: define void @sort_of_empty_ret() |
64 | EXTERNC struct SortOfEmpty sort_of_empty_ret() { |
65 | struct SortOfEmpty e; |
66 | return e; |
67 | } |
68 | |