Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -emit-llvm -w -o - %s | FileCheck -check-prefix=PCS %s
      2 
      3 // Sign extension is performed by the callee on AArch64, which means
      4 // that we *shouldn't* tag arguments and returns with their extension.
      5 
      6 // PCS: define i8 @f0(i16 %a)
      7 char f0(short a) {
      8   return a;
      9 }
     10 
     11 // PCS: define [1 x i64] @f1()
     12 struct s1 { char f0; };
     13 struct s1 f1(void) {}
     14 
     15 // PCS: define [1 x i64] @f2()
     16 struct s2 { short f0; };
     17 struct s2 f2(void) {}
     18 
     19 // PCS: define [1 x i64] @f3()
     20 struct s3 { int f0; };
     21 struct s3 f3(void) {}
     22 
     23 // PCS: define [1 x i64] @f4()
     24 struct s4 { struct s4_0 { int f0; } f0; };
     25 struct s4 f4(void) {}
     26 
     27 // PCS: define [1 x i64] @f5()
     28 struct s5 { struct { } f0; int f1; };
     29 struct s5 f5(void) {}
     30 
     31 // PCS: define  [1 x i64] @f6()
     32 struct s6 { int f0[1]; };
     33 struct s6 f6(void) {}
     34 
     35 // PCS: define void @f7()
     36 struct s7 { struct { int : 0; } f0; };
     37 struct s7 f7(void) {}
     38 
     39 // PCS: define  void @f8()
     40 struct s8 { struct { int : 0; } f0[1]; };
     41 struct s8 f8(void) {}
     42 
     43 // PCS: define [1 x i64] @f9()
     44 struct s9 { long f0; int : 0; };
     45 struct s9 f9(void) {}
     46 
     47 // PCS: define [1 x i64] @f10()
     48 struct s10 { long f0; int : 0; int : 0; };
     49 struct s10 f10(void) {}
     50 
     51 // PCS: define [1 x i64] @f11()
     52 struct s11 { int : 0; long f0; };
     53 struct s11 f11(void) {}
     54 
     55 // PCS: define [1 x i64] @f12()
     56 union u12 { char f0; short f1; int f2; long f3; };
     57 union u12 f12(void) {}
     58 
     59 // PCS: define %struct.s13 @f13()
     60 struct s13 { float f0; };
     61 struct s13 f13(void) {}
     62 
     63 // PCS: define %union.u14 @f14()
     64 union u14 { float f0; };
     65 union u14 f14(void) {}
     66 
     67 // PCS: define void @f15()
     68 void f15(struct s7 a0) {}
     69 
     70 // PCS: define void @f16()
     71 void f16(struct s8 a0) {}
     72 
     73 // PCS: define [1 x i64] @f17()
     74 struct s17 { short f0 : 13; char f1 : 4; };
     75 struct s17 f17(void) {}
     76 
     77 // PCS: define [1 x i64] @f18()
     78 struct s18 { short f0; char f1 : 4; };
     79 struct s18 f18(void) {}
     80 
     81 // PCS: define [1 x i64] @f19()
     82 struct s19 { long f0; struct s8 f1; };
     83 struct s19 f19(void) {}
     84 
     85 // PCS: define [1 x i64] @f20()
     86 struct s20 { struct s8 f1; long f0; };
     87 struct s20 f20(void) {}
     88 
     89 // PCS: define [1 x i64] @f21()
     90 struct s21 { struct {} f1; long f0 : 4; };
     91 struct s21 f21(void) {}
     92 
     93 // PCS: define { float, float } @f22()
     94 // PCS: define { double, double } @f23(
     95 _Complex float      f22(void) {}
     96 _Complex double     f23(void) {}
     97 
     98 // PCS: define [1 x i64] @f24()
     99 struct s24 { _Complex char f0; };
    100 struct s24 f24() {}
    101 
    102 // PCS: define [1 x i64] @f25()
    103 struct s25 { _Complex short f0; };
    104 struct s25 f25() {}
    105 
    106 // PCS: define [1 x i64] @f26()
    107 struct s26 { _Complex int f0; };
    108 struct s26 f26() {}
    109 
    110 // PCS: define [2 x i64] @f27()
    111 struct s27 { _Complex long f0; };
    112 struct s27 f27() {}
    113 
    114 // PCS: define void @f28(i8 %a, i16 %b, i32 %c, i64 %d, float %e, double %f)
    115 void f28(char a, short b, int c, long d, float e, double f) {}
    116 
    117 // PCS: define void @f29([2 x i64] %a
    118 struct s29 { int arr[4]; };
    119 void f29(struct s29 a) {}
    120 
    121 // PCS: define void @f30(%struct.s30* %a)
    122 struct s30 { int arr[4]; char c;};
    123 void f30(struct s30 a) {}
    124 
    125 // PCS: define void @f31([4 x double] %a
    126 struct s31 { double arr[4]; };
    127 void f31(struct s31 a) {}
    128 
    129 // PCS: define void @f32(%struct.s32* %a)
    130 struct s32 { float arr[5]; };
    131 void f32(struct s32 a) {}
    132 
    133 // Not the only solution, but it *is* an HFA.
    134 // PCS: define void @f33([3 x float] %a.coerce0, float %a.coerce1)
    135 struct s33 { float arr[3]; float a; };
    136 void f33(struct s33 a) {}
    137 
    138 // PCS: define void @f34(%struct.s34* noalias sret
    139 struct s34 { int a[4]; char b };
    140 struct s34 f34(void) {}
    141 
    142 // PCS: define void @f35()
    143 struct s35 {};
    144 void f35(struct s35 a) {}
    145 
    146 // Check padding is added:
    147 // PCS: @f36(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s36* byval align 8 %stacked)
    148 struct s36 { long a, b; };
    149 void f36(int x0, int x1, int x2, int x3, int x4, int x5, int x6, struct s36 stacked) {}
    150 
    151 // But only once:
    152 // PCS: @f37(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s37* byval align 8 %stacked, %struct.s37* byval align 8 %stacked2)
    153 struct s37 { long a, b; };
    154 void f37(int x0, int x1, int x2, int x3, int x4, int x5, int x6, struct s37 stacked, struct s37 stacked2) {}
    155 
    156 // Check for HFA padding args. Also, they should not end up on the stack in a
    157 // way which will have holes in when lowered further by LLVM. In particular [3 x
    158 // float] would be unacceptable.
    159 
    160 // PCS: @f38(float %s0, double %d1, float %s2, float %s3, float %s4, float %s5, [2 x float], %struct.s38* byval align 4 %stacked)
    161 struct s38 { float a, b, c; };
    162 void f38(float s0, double d1, float s2, float s3, float s4, float s5, struct s38 stacked) {}
    163 
    164 // Check both VFP and integer arguments are padded (also that pointers and enums
    165 // get counted as integer types correctly).
    166 struct s39_int { long a, b; };
    167 struct s39_float { float a, b, c, d; };
    168 enum s39_enum { Val1, Val2 };
    169 // PCS: @f39(float %s0, i32 %x0, float %s1, i32* %x1, float %s2, i32 %x2, float %s3, float %s4, i32 %x3, [3 x float], %struct.s39_float* byval align 4 %stacked, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s39_int* byval align 8 %stacked2)
    170 void f39(float s0, int x0, float s1, int *x1, float s2, enum s39_enum x2, float s3, float s4,
    171          int x3, struct s39_float stacked, int x4, int x5, int x6,
    172          struct s39_int stacked2) {}
    173 
    174 struct s40 { __int128 a; };
    175 // PCS: @f40(i32 %x0, [1 x i128] %x2_3.coerce, i32 %x4, i32 %x5, i32 %x6, [1 x i64], %struct.s40* byval align 16 %stacked)
    176 void f40(int x0, struct s40 x2_3, int x4, int x5, int x6, struct s40 stacked) {}
    177 
    178 // Checking: __int128 will get properly aligned type, with padding so big struct doesn't use x7.
    179 struct s41 { int arr[5]; };
    180 // PCS: @f41(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i32 %x5, i32 %x6, [1 x i64], i128* byval align 16, %struct.s41* %stacked2)
    181 int f41(int x0, int x1, int x2, int x3, int x4, int x5, int x6, __int128 stacked, struct s41 stacked2) {}
    182 
    183 // Checking: __int128 needing to be aligned in registers will consume correct
    184 // number. Previously padding was inserted before "stacked" because x6_7 was
    185 // "allocated" to x5 and x6 by clang.
    186 // PCS: @f42(i32 %x0, i32 %x1, i32 %x2, i32 %x3, i32 %x4, i128 %x6_7, i128* byval align 16)
    187 void f42(int x0, int x1, int x2, int x3, int x4, __int128 x6_7, __int128 stacked) {}
    188 
    189 // Checking: __fp16 is extended to double when calling variadic functions
    190 void variadic(int a, ...);
    191 void f43(__fp16 *in) {
    192   variadic(42, *in);
    193 // CHECK: call void @variadic(i32 42, double
    194 }
    195