blob: 5cc5e4797ca8ac130c76ea8f875097335c8bfaee [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
8// RUN: clang %s -triple i386-unknown-unknown -O3 -emit-llvm -o %t &&
9// RUN: not grep '@g0' %t &&
10
11// FIXME: Enable once PR3489 is fixed.
12// RUNX: clang %s -triple x86_64-unknown-unknown -O3 -emit-llvm -o %t &&
13// RUNX: not grep '@g0' %t &&
14
15// RUN: clang %s -triple ppc-unknown-unknown -O3 -emit-llvm -o %t &&
16// RUN: not grep '@g0' %t &&
17// RUN: true
18
Daniel Dunbar8b979d92009-02-10 00:06:49 +000019typedef _Bool BoolTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000020typedef int ScalarTy;
21typedef _Complex int ComplexTy;
22typedef struct { int a, b, c; } AggrTy;
Daniel Dunbar8b979d92009-02-10 00:06:49 +000023typedef struct { int a[0]; } EmptyTy;
Daniel Dunbarc216edb2009-02-05 11:21:33 +000024
25static int result;
26
Daniel Dunbar8b979d92009-02-10 00:06:49 +000027static BoolTy bool_id(BoolTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000028static AggrTy aggr_id(AggrTy a) { return a; }
Daniel Dunbar8b979d92009-02-10 00:06:49 +000029static EmptyTy empty_id(EmptyTy a) { return a; }
Daniel Dunbarc216edb2009-02-05 11:21:33 +000030static ScalarTy scalar_id(ScalarTy a) { return a; }
31static ComplexTy complex_id(ComplexTy a) { return a; }
32
Daniel Dunbar8b979d92009-02-10 00:06:49 +000033static void bool_mul(BoolTy a) { result *= a; }
34
Daniel Dunbarc216edb2009-02-05 11:21:33 +000035static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; }
36
Daniel Dunbar8b979d92009-02-10 00:06:49 +000037static void empty_mul(EmptyTy a) { result *= 53; }
38
Daniel Dunbarc216edb2009-02-05 11:21:33 +000039static void scalar_mul(ScalarTy a) { result *= a; }
40
41static void complex_mul(ComplexTy a) { result *= __real a * __imag a; }
42
43extern void g0(void);
44
45void f0(void) {
46 result = 1;
47
Daniel Dunbar8b979d92009-02-10 00:06:49 +000048 bool_mul(bool_id(1));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000049 aggr_mul(aggr_id((AggrTy) { 2, 3, 5}));
Daniel Dunbar8b979d92009-02-10 00:06:49 +000050 empty_mul(empty_id((EmptyTy) {}));
Daniel Dunbarc216edb2009-02-05 11:21:33 +000051 scalar_mul(scalar_id(7));
52 complex_mul(complex_id(11 + 13i));
53
54 // This call should be eliminated.
Daniel Dunbar8b979d92009-02-10 00:06:49 +000055 if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53)
Daniel Dunbarc216edb2009-02-05 11:21:33 +000056 g0();
57}
58