blob: 2af392dcf7b3ff6c4baa581dd50a87245572ba86 [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
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00008// RUN: clang-cc %s -triple i386-unknown-unknown -O3 -emit-llvm -o %t
9// RUN: not grep '@g0' %t
Daniel Dunbarc216edb2009-02-05 11:21:33 +000010
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000011// RUN: clang-cc %s -triple x86_64-unknown-unknown -O3 -emit-llvm -o %t
12// RUN: not grep '@g0' %t
Daniel Dunbarc216edb2009-02-05 11:21:33 +000013
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000014// RUN: clang-cc %s -triple powerpc-unknown-unknown -O3 -emit-llvm -o %t
15// RUN: not grep '@g0' %t
Daniel Dunbarc216edb2009-02-05 11:21:33 +000016// RUN: true
17
Daniel Dunbar8b979d92009-02-10 00:06:49 +000018typedef _Bool BoolTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000019typedef int ScalarTy;
20typedef _Complex int ComplexTy;
21typedef struct { int a, b, c; } AggrTy;
Daniel Dunbar8b979d92009-02-10 00:06:49 +000022typedef struct { int a[0]; } EmptyTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000023
24static int result;
25
Daniel Dunbar8b979d92009-02-10 00:06:49 +000026static BoolTy bool_id(BoolTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000027static AggrTy aggr_id(AggrTy a) { return a; }
Daniel Dunbar8b979d92009-02-10 00:06:49 +000028static EmptyTy empty_id(EmptyTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000029static ScalarTy scalar_id(ScalarTy a) { return a; }
30static ComplexTy complex_id(ComplexTy a) { return a; }
31
Daniel Dunbar8b979d92009-02-10 00:06:49 +000032static void bool_mul(BoolTy a) { result *= a; }
33
Daniel Dunbarc216edb2009-02-05 11:21:33 +000034static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; }
35
Daniel Dunbar8b979d92009-02-10 00:06:49 +000036static void empty_mul(EmptyTy a) { result *= 53; }
37
Daniel Dunbarc216edb2009-02-05 11:21:33 +000038static void scalar_mul(ScalarTy a) { result *= a; }
39
40static void complex_mul(ComplexTy a) { result *= __real a * __imag a; }
41
42extern void g0(void);
43
44void f0(void) {
45 result = 1;
46
Daniel Dunbar8b979d92009-02-10 00:06:49 +000047 bool_mul(bool_id(1));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000048 aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
Daniel Dunbar8b979d92009-02-10 00:06:49 +000049 empty_mul(empty_id((EmptyTy) {}));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000050 scalar_mul(scalar_id(7));
51 complex_mul(complex_id(11 + 13i));
52
53 // This call should be eliminated.
Daniel Dunbar8b979d92009-02-10 00:06:49 +000054 if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
Daniel Dunbarc216edb2009-02-05 11:21:33 +000055 g0();
56}
57