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 | |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 8 | // RUN: %clang_cc1 %s -triple i386-unknown-unknown -O3 -emit-llvm -o %t |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 9 | // RUN: not grep '@g0' %t |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 10 | |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 11 | // RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -O3 -emit-llvm -o %t |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 12 | // RUN: not grep '@g0' %t |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 13 | |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 14 | // RUN: %clang_cc1 %s -triple powerpc-unknown-unknown -O3 -emit-llvm -o %t |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 15 | // RUN: not grep '@g0' %t |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 17 | typedef _Bool BoolTy; |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 18 | typedef int ScalarTy; |
| 19 | typedef _Complex int ComplexTy; |
| 20 | typedef struct { int a, b, c; } AggrTy; |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 21 | typedef struct { int a[0]; } EmptyTy; |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 22 | |
| 23 | static int result; |
| 24 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 25 | static BoolTy bool_id(BoolTy a) { return a; } |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 26 | static AggrTy aggr_id(AggrTy a) { return a; } |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 27 | static EmptyTy empty_id(EmptyTy a) { return a; } |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 28 | static ScalarTy scalar_id(ScalarTy a) { return a; } |
| 29 | static ComplexTy complex_id(ComplexTy a) { return a; } |
| 30 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 31 | static void bool_mul(BoolTy a) { result *= a; } |
| 32 | |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 33 | static void aggr_mul(AggrTy a) { result *= a.a * a.b * a.c; } |
| 34 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 35 | static void empty_mul(EmptyTy a) { result *= 53; } |
| 36 | |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 37 | static void scalar_mul(ScalarTy a) { result *= a; } |
| 38 | |
| 39 | static void complex_mul(ComplexTy a) { result *= __real a * __imag a; } |
| 40 | |
| 41 | extern void g0(void); |
| 42 | |
| 43 | void f0(void) { |
| 44 | result = 1; |
| 45 | |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 46 | bool_mul(bool_id(1)); |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 47 | aggr_mul(aggr_id((AggrTy) { 2, 3, 5})); |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 48 | empty_mul(empty_id((EmptyTy) {})); |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 49 | scalar_mul(scalar_id(7)); |
| 50 | complex_mul(complex_id(11 + 13i)); |
| 51 | |
| 52 | // This call should be eliminated. |
Daniel Dunbar | 8b979d9 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 53 | if (result != 2 * 3 * 5 * 7 * 11 * 13 * 53) |
Daniel Dunbar | c216edb | 2009-02-05 11:21:33 +0000 | [diff] [blame] | 54 | g0(); |
| 55 | } |
| 56 | |