Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 1 | // 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 Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 4 | // |
| 5 | // We also check _Bool and empty structures, as these can have annoying |
| 6 | // corner cases. |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 7 | |
| 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 Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 19 | typedef _Bool BoolTy; |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 20 | typedef int ScalarTy; |
| 21 | typedef _Complex int ComplexTy; |
| 22 | typedef struct { int a, b, c; } AggrTy; |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 23 | typedef struct { int a[0]; } EmptyTy; |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 24 | |
| 25 | static int result; |
| 26 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 27 | static BoolTy bool_id(BoolTy a) { return a; } |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 28 | static AggrTy aggr_id(AggrTy a) { return a; } |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 29 | static EmptyTy empty_id(EmptyTy a) { return a; } |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 30 | static ScalarTy scalar_id(ScalarTy a) { return a; } |
| 31 | static ComplexTy complex_id(ComplexTy a) { return a; } |
| 32 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 33 | static void bool_mul(BoolTy a) { result *= a; } |
| 34 | |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 35 | static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; } |
| 36 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 37 | static void empty_mul(EmptyTy a) { result *= 53; } |
| 38 | |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 39 | static void scalar_mul(ScalarTy a) { result *= a; } |
| 40 | |
| 41 | static void complex_mul(ComplexTy a) { result *= __real a * __imag a; } |
| 42 | |
| 43 | extern void g0(void); |
| 44 | |
| 45 | void f0(void) { |
| 46 | result = 1; |
| 47 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 48 | bool_mul(bool_id(1)); |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 49 | aggr_mul(aggr_id((AggrTy) { 2, 3, 5})); |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 50 | empty_mul(empty_id((EmptyTy) {})); |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 51 | scalar_mul(scalar_id(7)); |
| 52 | complex_mul(complex_id(11 + 13i)); |
| 53 | |
| 54 | // This call should be eliminated. |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame^] | 55 | if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53) |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 56 | g0(); |
| 57 | } |
| 58 | |