File: strong-in-c-struct.m

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,436 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (56 lines) | stat: -rw-r--r-- 1,709 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  -fobjc-runtime=ios-11.0 -fsyntax-only -verify %s

typedef struct {
  id a;
} Strong;

void callee_variadic(const char *, ...);

void test_variadic(void) {
  Strong t;
  callee_variadic("s", t); // expected-error {{cannot pass non-trivial C object of type 'Strong' by value to variadic function}}
}

void test_jump0(int cond) {
  switch (cond) {
  case 0:
    ;
    Strong x; // expected-note {{jump bypasses initialization of variable of non-trivial C struct type}}
    break;
  case 1: // expected-error {{cannot jump from switch statement to this case label}}
    x.a = 0;
    break;
  }
}

void test_jump1(void) {
  static void *ips[] = { &&L0 };
L0:  // expected-note {{possible target of indirect goto}}
  ;
  Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}}
  goto *ips; // expected-error {{cannot jump}}
}

typedef void (^BlockTy)(void);
void func(BlockTy);
void func2(Strong);

void test_block_scope0(int cond) {
  Strong x; // expected-note {{jump enters lifetime of block which captures a C struct that is non-trivial to destroy}}
  switch (cond) {
  case 0:
    func(^{ func2(x); });
    break;
  default: // expected-error {{cannot jump from switch statement to this case label}}
    break;
  }
}

void test_block_scope1(void) {
  static void *ips[] = { &&L0 };
L0:  // expected-note {{possible target of indirect goto}}
  ;
  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}}
  func(^{ func2(x); });
  goto *ips; // expected-error {{cannot jump}}
}