xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/parameter-passing.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // Check the various ways in which the three classes of values
2*f4a2713aSLionel Sambuc // (scalar, complex, aggregate) interact with parameter passing
3*f4a2713aSLionel Sambuc // (function entry, function return, call argument, call result).
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // We also check _Bool and empty structures, as these can have annoying
6*f4a2713aSLionel Sambuc // corner cases.
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O3 -emit-llvm -o - | FileCheck %s
9*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -O3 -emit-llvm -o - | FileCheck %s
10*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple powerpc-unknown-unknown -O3 -emit-llvm -o - | FileCheck %s
11*f4a2713aSLionel Sambuc // CHECK-NOT: @g0
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc typedef _Bool BoolTy;
14*f4a2713aSLionel Sambuc typedef int ScalarTy;
15*f4a2713aSLionel Sambuc typedef _Complex int ComplexTy;
16*f4a2713aSLionel Sambuc typedef struct { int a, b, c; } AggrTy;
17*f4a2713aSLionel Sambuc typedef struct { int a[0]; } EmptyTy;
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc static int result;
20*f4a2713aSLionel Sambuc 
bool_id(BoolTy a)21*f4a2713aSLionel Sambuc static BoolTy bool_id(BoolTy a) { return a; }
aggr_id(AggrTy a)22*f4a2713aSLionel Sambuc static AggrTy aggr_id(AggrTy a) { return a; }
empty_id(EmptyTy a)23*f4a2713aSLionel Sambuc static EmptyTy empty_id(EmptyTy a) { return a; }
scalar_id(ScalarTy a)24*f4a2713aSLionel Sambuc static ScalarTy scalar_id(ScalarTy a) { return a; }
complex_id(ComplexTy a)25*f4a2713aSLionel Sambuc static ComplexTy complex_id(ComplexTy a) { return a; }
26*f4a2713aSLionel Sambuc 
bool_mul(BoolTy a)27*f4a2713aSLionel Sambuc static void bool_mul(BoolTy a) { result *= a; }
28*f4a2713aSLionel Sambuc 
aggr_mul(AggrTy a)29*f4a2713aSLionel Sambuc static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; }
30*f4a2713aSLionel Sambuc 
empty_mul(EmptyTy a)31*f4a2713aSLionel Sambuc static void empty_mul(EmptyTy a) { result *= 53; }
32*f4a2713aSLionel Sambuc 
scalar_mul(ScalarTy a)33*f4a2713aSLionel Sambuc static void scalar_mul(ScalarTy a) { result *= a; }
34*f4a2713aSLionel Sambuc 
complex_mul(ComplexTy a)35*f4a2713aSLionel Sambuc static void complex_mul(ComplexTy a) { result *= __real a * __imag a; }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc extern void g0(void);
38*f4a2713aSLionel Sambuc 
f0(void)39*f4a2713aSLionel Sambuc void f0(void) {
40*f4a2713aSLionel Sambuc   result = 1;
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc   bool_mul(bool_id(1));
43*f4a2713aSLionel Sambuc   aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
44*f4a2713aSLionel Sambuc   empty_mul(empty_id((EmptyTy) {}));
45*f4a2713aSLionel Sambuc   scalar_mul(scalar_id(7));
46*f4a2713aSLionel Sambuc   complex_mul(complex_id(11 + 13i));
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc   // This call should be eliminated.
49*f4a2713aSLionel Sambuc   if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
50*f4a2713aSLionel Sambuc     g0();
51*f4a2713aSLionel Sambuc }
52*f4a2713aSLionel Sambuc 
53