File: dr268.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (63 lines) | stat: -rw-r--r-- 1,960 bytes parent folder | download | duplicates (13)
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
57
58
59
60
61
62
63
/* RUN: %clang_cc1 -std=c89 -pedantic -verify -emit-llvm -o -  %s | FileCheck %s
   RUN: %clang_cc1 -std=c99 -pedantic -verify -emit-llvm -o -  %s | FileCheck %s
   RUN: %clang_cc1 -std=c11 -pedantic -verify -emit-llvm -o -  %s | FileCheck %s
   RUN: %clang_cc1 -std=c17 -pedantic -verify -emit-llvm -o -  %s | FileCheck %s
   RUN: %clang_cc1 -std=c2x -pedantic -verify -emit-llvm -o -  %s | FileCheck %s
 */

/* expected-no-diagnostics */

/* WG14 DR268: yes
 * Jumps into iteration statements
 */
void foo(void);
void dr268(void) {
  int i = 5;
  goto goto_target;

  for (i = 0; i < 10; ++i) {
    if (i > 2) ++i;
goto_target:
    foo();
  }

  /* Ensure that the goto jumps into the middle of the for loop body, and that
   * the initialization and controlling expression are not evaluated on the
   * first pass through.
   */
  /* Get us to the right function.
     CHECK-LABEL: define{{.*}} void @dr268() {{.*}} {

     First is the initialization and goto.
     CHECK: store i32 5
     CHECK-NEXT: br label %[[GOTO_TARGET:.+]]

     Then comes the initialization of the for loop variable.
     CHECK: store i32 0
     CHECK-NEXT: br label %[[FOR_COND:.+]]

     Then comes the for loop condition check label followed eventually by the
     for loop body label.
     CHECK: [[FOR_COND]]:
     CHECK: {{.+}} = icmp slt i32 {{.+}}, 10
     CHECK: [[FOR_BODY:.+]]:
     CHECK: {{.+}} = icmp sgt i32 {{.+}}, 2

     Then comes the then branch of the if statement.
     CHECK: %[[I:.+]] = load i32,
     CHECK-NEXT: %[[INC:.+]] = add nsw i32 %[[I]], 1
     CHECK-NEXT: store i32 %[[INC]],

     Eventually, we get to the goto label and its call
     CHECK: [[GOTO_TARGET]]:
     CHECK-NEXT: call void @foo()
     CHECK-NEXT: br label %[[FOR_INC:.+]]

     CHECK: [[FOR_INC]]:
     CHECK-NEXT: %[[I2:.+]] = load i32,
     CHECK-NEXT: %[[INC2:.+]] = add nsw i32 %[[I2]], 1
     CHECK-NEXT: store i32 %[[INC2]],
     CHECK-NEXT: br label %[[FOR_COND]]
   */
}