1 // RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
3 // RUN:     | FileCheck %s
4 
5 // This file contains test cases that will have the same output for the ilp32
6 // and ilp32f ABIs.
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 struct tiny {
12   uint8_t a, b, c, d;
13 };
14 
15 struct small {
16   int32_t a, *b;
17 };
18 
19 struct small_aligned {
20   int64_t a;
21 };
22 
23 struct large {
24   int32_t a, b, c, d;
25 };
26 
27 // Scalars passed on the stack should not have signext/zeroext attributes
28 // (they are anyext).
29 
30 // CHECK-LABEL: define{{.*}} i32 @f_scalar_stack_1(i32 %a, i64 %b, i32 %c, double %d, fp128 %e, i8 zeroext %f, i8 %g, i8 %h)
f_scalar_stack_1(int32_t a,int64_t b,int32_t c,double d,long double e,uint8_t f,int8_t g,uint8_t h)31 int f_scalar_stack_1(int32_t a, int64_t b, int32_t c, double d, long double e,
32                      uint8_t f, int8_t g, uint8_t h) {
33   return g + h;
34 }
35 
36 // Ensure that scalars passed on the stack are still determined correctly in
37 // the presence of large return values that consume a register due to the need
38 // to pass a pointer.
39 
40 // CHECK-LABEL: define{{.*}} void @f_scalar_stack_2(%struct.large* noalias sret(%struct.large) align 4 %agg.result, i32 %a, i64 %b, double %c, fp128 %d, i8 zeroext %e, i8 %f, i8 %g)
f_scalar_stack_2(int32_t a,int64_t b,double c,long double d,uint8_t e,int8_t f,uint8_t g)41 struct large f_scalar_stack_2(int32_t a, int64_t b, double c, long double d,
42                               uint8_t e, int8_t f, uint8_t g) {
43   return (struct large){a, e, f, g};
44 }
45 
46 // Aggregates and >=XLen scalars passed on the stack should be lowered just as
47 // they would be if passed via registers.
48 
49 // CHECK-LABEL: define{{.*}} void @f_scalar_stack_3(double %a, i64 %b, double %c, i64 %d, i32 %e, i64 %f, i32 %g, double %h, fp128 %i)
f_scalar_stack_3(double a,int64_t b,double c,int64_t d,int e,int64_t f,int32_t g,double h,long double i)50 void f_scalar_stack_3(double a, int64_t b, double c, int64_t d, int e,
51                       int64_t f, int32_t g, double h, long double i) {}
52 
53 // CHECK-LABEL: define{{.*}} void @f_agg_stack(double %a, i64 %b, double %c, i64 %d, i32 %e.coerce, [2 x i32] %f.coerce, i64 %g.coerce, %struct.large* %h)
f_agg_stack(double a,int64_t b,double c,int64_t d,struct tiny e,struct small f,struct small_aligned g,struct large h)54 void f_agg_stack(double a, int64_t b, double c, int64_t d, struct tiny e,
55                  struct small f, struct small_aligned g, struct large h) {}
56