John McCall | 410ffb2 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -fblocks | FileCheck %s |
Anders Carlsson | 4de9fce | 2009-03-01 01:09:12 +0000 | [diff] [blame] | 2 | void (^f)(void) = ^{}; |
Anders Carlsson | a17d7cc | 2009-04-08 02:55:55 +0000 | [diff] [blame] | 3 | |
| 4 | // rdar://6768379 |
| 5 | int f0(int (^a0)()) { |
| 6 | return a0(1, 2, 3); |
| 7 | } |
Daniel Dunbar | 0e4f40e | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 8 | |
| 9 | // Verify that attributes on blocks are set correctly. |
| 10 | typedef struct s0 T; |
| 11 | struct s0 { |
| 12 | int a[64]; |
| 13 | }; |
| 14 | |
Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 15 | // CHECK: define internal void @__f2_block_invoke(%struct.s0* noalias sret {{%.*}}, i8* {{%.*}}, %struct.s0* byval align 4 {{.*}}) |
Daniel Dunbar | 0e4f40e | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 16 | struct s0 f2(struct s0 a0) { |
| 17 | return ^(struct s0 a1){ return a1; }(a0); |
| 18 | } |
| 19 | |
Chris Lattner | f1c97eb | 2009-04-21 04:41:23 +0000 | [diff] [blame] | 20 | // This should not crash: rdar://6808051 |
| 21 | void *P = ^{ |
| 22 | void *Q = __func__; |
| 23 | }; |
| 24 | |
Mike Stump | dd2fb9c | 2009-05-01 01:31:57 +0000 | [diff] [blame] | 25 | void (^test1)(void) = ^(void) { |
| 26 | __block int i; |
| 27 | ^ { i = 1; }(); |
| 28 | }; |
Chris Lattner | f1c97eb | 2009-04-21 04:41:23 +0000 | [diff] [blame] | 29 | |
John McCall | c71a491 | 2010-06-04 19:02:56 +0000 | [diff] [blame] | 30 | typedef double ftype(double); |
| 31 | // It's not clear that we *should* support this syntax, but until that decision |
| 32 | // is made, we should support it properly and not crash. |
| 33 | ftype ^test2 = ^ftype { |
| 34 | return 0; |
| 35 | }; |
John McCall | 46ec70e | 2010-10-28 21:37:57 +0000 | [diff] [blame] | 36 | |
| 37 | // rdar://problem/8605032 |
| 38 | void f3_helper(void (^)(void)); |
| 39 | void f3() { |
| 40 | _Bool b = 0; |
| 41 | f3_helper(^{ if (b) {} }); |
| 42 | } |
John McCall | 6ea4841 | 2012-04-26 21:14:42 +0000 | [diff] [blame] | 43 | |
| 44 | // rdar://problem/11322251 |
John McCall | 6c803f7 | 2012-05-01 20:28:00 +0000 | [diff] [blame] | 45 | // The bool can fill in between the header and the long long. |
| 46 | // Add the appropriate amount of padding between them. |
John McCall | 6ea4841 | 2012-04-26 21:14:42 +0000 | [diff] [blame] | 47 | void f4_helper(long long (^)(void)); |
John McCall | 6c803f7 | 2012-05-01 20:28:00 +0000 | [diff] [blame] | 48 | // CHECK: define void @f4() |
John McCall | 6ea4841 | 2012-04-26 21:14:42 +0000 | [diff] [blame] | 49 | void f4(void) { |
| 50 | _Bool b = 0; |
| 51 | long long ll = 0; |
John McCall | 6c803f7 | 2012-05-01 20:28:00 +0000 | [diff] [blame] | 52 | // CHECK: alloca <{ i8*, i32, i32, i8*, {{%.*}}*, i8, [3 x i8], i64 }>, align 8 |
John McCall | 6ea4841 | 2012-04-26 21:14:42 +0000 | [diff] [blame] | 53 | f4_helper(^{ if (b) return ll; return 0LL; }); |
| 54 | } |
John McCall | 6c803f7 | 2012-05-01 20:28:00 +0000 | [diff] [blame] | 55 | |
| 56 | // rdar://problem/11354538 |
| 57 | // The alignment after rounding up to the align of F5 is actually |
| 58 | // greater than the required alignment. Don't assert. |
| 59 | struct F5 { |
| 60 | char buffer[32] __attribute((aligned)); |
| 61 | }; |
| 62 | void f5_helper(void (^)(struct F5 *)); |
| 63 | // CHECK: define void @f5() |
| 64 | void f5(void) { |
| 65 | struct F5 value; |
| 66 | // CHECK: alloca <{ i8*, i32, i32, i8*, {{%.*}}*, [12 x i8], [[F5:%.*]] }>, align 16 |
| 67 | f5_helper(^(struct F5 *slot) { *slot = value; }); |
| 68 | } |