blob: 77fb0e1899895bfdea23c3b0d2251bd3700553f3 [file] [log] [blame]
John McCall410ffb22011-08-25 23:04:34 +00001// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - -fblocks | FileCheck %s
Anders Carlsson4de9fce2009-03-01 01:09:12 +00002void (^f)(void) = ^{};
Anders Carlssona17d7cc2009-04-08 02:55:55 +00003
4// rdar://6768379
5int f0(int (^a0)()) {
6 return a0(1, 2, 3);
7}
Daniel Dunbar0e4f40e2009-04-17 00:48:04 +00008
9// Verify that attributes on blocks are set correctly.
10typedef struct s0 T;
11struct s0 {
12 int a[64];
13};
14
John McCall410ffb22011-08-25 23:04:34 +000015// CHECK: define internal void @__f2_block_invoke_0(%struct.s0* noalias sret {{%.*}}, i8* {{%.*}}, %struct.s0* byval align 4 {{.*}})
Daniel Dunbar0e4f40e2009-04-17 00:48:04 +000016struct s0 f2(struct s0 a0) {
17 return ^(struct s0 a1){ return a1; }(a0);
18}
19
Chris Lattnerf1c97eb2009-04-21 04:41:23 +000020// This should not crash: rdar://6808051
21void *P = ^{
22 void *Q = __func__;
23};
24
Mike Stumpdd2fb9c2009-05-01 01:31:57 +000025void (^test1)(void) = ^(void) {
26 __block int i;
27 ^ { i = 1; }();
28};
Chris Lattnerf1c97eb2009-04-21 04:41:23 +000029
John McCallc71a4912010-06-04 19:02:56 +000030typedef 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.
33ftype ^test2 = ^ftype {
34 return 0;
35};
John McCall46ec70e2010-10-28 21:37:57 +000036
37// rdar://problem/8605032
38void f3_helper(void (^)(void));
39void f3() {
40 _Bool b = 0;
41 f3_helper(^{ if (b) {} });
42}
John McCall6ea48412012-04-26 21:14:42 +000043
44// rdar://problem/11322251
45void f4_helper(long long (^)(void));
46void f4(void) {
47 _Bool b = 0;
48 long long ll = 0;
49 f4_helper(^{ if (b) return ll; return 0LL; });
50}