blob: 40610af9d7d09a2fee43558bc7399ccf0f34fd4e [file] [log] [blame]
Daniel Dunbarc216edb2009-02-05 11:21:33 +00001// Check the various ways in which the three classes of values
2// (scalar, complex, aggregate) interact with parameter passing
3// (function entry, function return, call argument, call result).
Daniel Dunbar8b979d92009-02-10 00:06:49 +00004//
5// We also check _Bool and empty structures, as these can have annoying
6// corner cases.
Daniel Dunbarc216edb2009-02-05 11:21:33 +00007
Dmitri Gribenko057519d2013-01-24 23:34:51 +00008// RUN: %clang_cc1 %s -triple i386-unknown-unknown -O3 -emit-llvm -o - | FileCheck %s
9// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -O3 -emit-llvm -o - | FileCheck %s
10// RUN: %clang_cc1 %s -triple powerpc-unknown-unknown -O3 -emit-llvm -o - | FileCheck %s
11// CHECK-NOT: @g0
Daniel Dunbarc216edb2009-02-05 11:21:33 +000012
Daniel Dunbar8b979d92009-02-10 00:06:49 +000013typedef _Bool BoolTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000014typedef int ScalarTy;
15typedef _Complex int ComplexTy;
16typedef struct { int a, b, c; } AggrTy;
Daniel Dunbar8b979d92009-02-10 00:06:49 +000017typedef struct { int a[0]; } EmptyTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000018
19static int result;
20
Daniel Dunbar8b979d92009-02-10 00:06:49 +000021static BoolTy bool_id(BoolTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000022static AggrTy aggr_id(AggrTy a) { return a; }
Daniel Dunbar8b979d92009-02-10 00:06:49 +000023static EmptyTy empty_id(EmptyTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000024static ScalarTy scalar_id(ScalarTy a) { return a; }
25static ComplexTy complex_id(ComplexTy a) { return a; }
26
Daniel Dunbar8b979d92009-02-10 00:06:49 +000027static void bool_mul(BoolTy a) { result *= a; }
28
Daniel Dunbarc216edb2009-02-05 11:21:33 +000029static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; }
30
Daniel Dunbar8b979d92009-02-10 00:06:49 +000031static void empty_mul(EmptyTy a) { result *= 53; }
32
Daniel Dunbarc216edb2009-02-05 11:21:33 +000033static void scalar_mul(ScalarTy a) { result *= a; }
34
35static void complex_mul(ComplexTy a) { result *= __real a * __imag a; }
36
37extern void g0(void);
38
39void f0(void) {
40 result = 1;
41
Daniel Dunbar8b979d92009-02-10 00:06:49 +000042 bool_mul(bool_id(1));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000043 aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
Daniel Dunbar8b979d92009-02-10 00:06:49 +000044 empty_mul(empty_id((EmptyTy) {}));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000045 scalar_mul(scalar_id(7));
46 complex_mul(complex_id(11 + 13i));
47
48 // This call should be eliminated.
Daniel Dunbar8b979d92009-02-10 00:06:49 +000049 if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
Daniel Dunbarc216edb2009-02-05 11:21:33 +000050 g0();
51}
52