blob: e48815b96612c5845ab05357c2216724d143a5a9 [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 Dunbara5728872009-12-15 20:14:24 +00008// RUN: %clang_cc1 %s -triple i386-unknown-unknown -O3 -emit-llvm -o %t
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00009// RUN: not grep '@g0' %t
Daniel Dunbarc216edb2009-02-05 11:21:33 +000010
Daniel Dunbara5728872009-12-15 20:14:24 +000011// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -O3 -emit-llvm -o %t
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000012// RUN: not grep '@g0' %t
Daniel Dunbarc216edb2009-02-05 11:21:33 +000013
Daniel Dunbara5728872009-12-15 20:14:24 +000014// RUN: %clang_cc1 %s -triple powerpc-unknown-unknown -O3 -emit-llvm -o %t
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000015// RUN: not grep '@g0' %t
Daniel Dunbarc216edb2009-02-05 11:21:33 +000016
Daniel Dunbar8b979d92009-02-10 00:06:49 +000017typedef _Bool BoolTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000018typedef int ScalarTy;
19typedef _Complex int ComplexTy;
20typedef struct { int a, b, c; } AggrTy;
Daniel Dunbar8b979d92009-02-10 00:06:49 +000021typedef struct { int a[0]; } EmptyTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000022
23static int result;
24
Daniel Dunbar8b979d92009-02-10 00:06:49 +000025static BoolTy bool_id(BoolTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000026static AggrTy aggr_id(AggrTy a) { return a; }
Daniel Dunbar8b979d92009-02-10 00:06:49 +000027static EmptyTy empty_id(EmptyTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000028static ScalarTy scalar_id(ScalarTy a) { return a; }
29static ComplexTy complex_id(ComplexTy a) { return a; }
30
Daniel Dunbar8b979d92009-02-10 00:06:49 +000031static void bool_mul(BoolTy a) { result *= a; }
32
Daniel Dunbarc216edb2009-02-05 11:21:33 +000033static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; }
34
Daniel Dunbar8b979d92009-02-10 00:06:49 +000035static void empty_mul(EmptyTy a) { result *= 53; }
36
Daniel Dunbarc216edb2009-02-05 11:21:33 +000037static void scalar_mul(ScalarTy a) { result *= a; }
38
39static void complex_mul(ComplexTy a) { result *= __real a * __imag a; }
40
41extern void g0(void);
42
43void f0(void) {
44 result = 1;
45
Daniel Dunbar8b979d92009-02-10 00:06:49 +000046 bool_mul(bool_id(1));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000047 aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
Daniel Dunbar8b979d92009-02-10 00:06:49 +000048 empty_mul(empty_id((EmptyTy) {}));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000049 scalar_mul(scalar_id(7));
50 complex_mul(complex_id(11 + 13i));
51
52 // This call should be eliminated.
Daniel Dunbar8b979d92009-02-10 00:06:49 +000053 if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
Daniel Dunbarc216edb2009-02-05 11:21:33 +000054 g0();
55}
56