annotate clang/test/SemaObjC/strong-in-c-struct.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 typedef struct {
anatofuz
parents:
diff changeset
4 id a;
anatofuz
parents:
diff changeset
5 } Strong;
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 void callee_variadic(const char *, ...);
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void test_variadic(void) {
anatofuz
parents:
diff changeset
10 Strong t;
anatofuz
parents:
diff changeset
11 callee_variadic("s", t); // expected-error {{cannot pass non-trivial C object of type 'Strong' by value to variadic function}}
anatofuz
parents:
diff changeset
12 }
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 void test_jump0(int cond) {
anatofuz
parents:
diff changeset
15 switch (cond) {
anatofuz
parents:
diff changeset
16 case 0:
anatofuz
parents:
diff changeset
17 ;
anatofuz
parents:
diff changeset
18 Strong x; // expected-note {{jump bypasses initialization of variable of non-trivial C struct type}}
anatofuz
parents:
diff changeset
19 break;
anatofuz
parents:
diff changeset
20 case 1: // expected-error {{cannot jump from switch statement to this case label}}
anatofuz
parents:
diff changeset
21 x.a = 0;
anatofuz
parents:
diff changeset
22 break;
anatofuz
parents:
diff changeset
23 }
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 void test_jump1(void) {
anatofuz
parents:
diff changeset
27 static void *ips[] = { &&L0 };
anatofuz
parents:
diff changeset
28 L0: // expected-note {{possible target of indirect goto}}
anatofuz
parents:
diff changeset
29 ;
anatofuz
parents:
diff changeset
30 Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}}
anatofuz
parents:
diff changeset
31 goto *ips; // expected-error {{cannot jump}}
anatofuz
parents:
diff changeset
32 }
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 typedef void (^BlockTy)(void);
anatofuz
parents:
diff changeset
35 void func(BlockTy);
anatofuz
parents:
diff changeset
36 void func2(Strong);
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 void test_block_scope0(int cond) {
anatofuz
parents:
diff changeset
39 Strong x; // expected-note {{jump enters lifetime of block which captures a C struct that is non-trivial to destroy}}
anatofuz
parents:
diff changeset
40 switch (cond) {
anatofuz
parents:
diff changeset
41 case 0:
anatofuz
parents:
diff changeset
42 func(^{ func2(x); });
anatofuz
parents:
diff changeset
43 break;
anatofuz
parents:
diff changeset
44 default: // expected-error {{cannot jump from switch statement to this case label}}
anatofuz
parents:
diff changeset
45 break;
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47 }
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 void test_block_scope1(void) {
anatofuz
parents:
diff changeset
50 static void *ips[] = { &&L0 };
anatofuz
parents:
diff changeset
51 L0: // expected-note {{possible target of indirect goto}}
anatofuz
parents:
diff changeset
52 ;
anatofuz
parents:
diff changeset
53 Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}} expected-note {{jump exits lifetime of block which captures a C struct that is non-trivial to destroy}}
anatofuz
parents:
diff changeset
54 func(^{ func2(x); });
anatofuz
parents:
diff changeset
55 goto *ips; // expected-error {{cannot jump}}
anatofuz
parents:
diff changeset
56 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
57
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
58 void test_compound_literal0(int cond, id x) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
59 switch (cond) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
60 case 0:
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
61 (void)(Strong){ .a = x }; // expected-note {{jump enters lifetime of a compound literal that is non-trivial to destruct}}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
62 break;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
63 default: // expected-error {{cannot jump from switch statement to this case label}}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
64 break;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
65 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
66 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
67
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
68 void test_compound_literal1(id x) {
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
69 static void *ips[] = { &&L0 };
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
70 L0: // expected-note {{possible target of indirect goto}}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
71 ;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
72 (void)(Strong){ .a = x }; // expected-note {{jump exits lifetime of a compound literal that is non-trivial to destruct}}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
73 goto *ips; // expected-error {{cannot jump}}
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
74 }