| 1 |
/* RUN: %clang_cc1 -std=c89 -pedantic -verify -emit-llvm -o - %s | FileCheck %s |
| 2 |
RUN: %clang_cc1 -std=c99 -pedantic -verify -emit-llvm -o - %s | FileCheck %s |
| 3 |
RUN: %clang_cc1 -std=c11 -pedantic -verify -emit-llvm -o - %s | FileCheck %s |
| 4 |
RUN: %clang_cc1 -std=c17 -pedantic -verify -emit-llvm -o - %s | FileCheck %s |
| 5 |
RUN: %clang_cc1 -std=c2x -pedantic -verify -emit-llvm -o - %s | FileCheck %s |
| 6 |
*/ |
| 7 |
|
| 8 |
/* expected-no-diagnostics */ |
| 9 |
|
| 10 |
/* WG14 DR268: yes |
| 11 |
* Jumps into iteration statements |
| 12 |
*/ |
| 13 |
void foo(void); |
| 14 |
void dr268(void) { |
| 15 |
int i = 5; |
| 16 |
goto goto_target; |
| 17 |
|
| 18 |
for (i = 0; i < 10; ++i) { |
| 19 |
if (i > 2) ++i; |
| 20 |
goto_target: |
| 21 |
foo(); |
| 22 |
} |
| 23 |
|
| 24 |
/* Ensure that the goto jumps into the middle of the for loop body, and that |
| 25 |
* the initialization and controlling expression are not evaluated on the |
| 26 |
* first pass through. |
| 27 |
*/ |
| 28 |
/* Get us to the right function. |
| 29 |
CHECK-LABEL: define{{.*}} void @dr268() {{.*}} { |
| 30 |
|
| 31 |
First is the initialization and goto. |
| 32 |
CHECK: store i32 5 |
| 33 |
CHECK-NEXT: br label %[[GOTO_TARGET:.+]] |
| 34 |
|
| 35 |
Then comes the initialization of the for loop variable. |
| 36 |
CHECK: store i32 0 |
| 37 |
CHECK-NEXT: br label %[[FOR_COND:.+]] |
| 38 |
|
| 39 |
Then comes the for loop condition check label followed eventually by the |
| 40 |
for loop body label. |
| 41 |
CHECK: [[FOR_COND]]: |
| 42 |
CHECK: {{.+}} = icmp slt i32 {{.+}}, 10 |
| 43 |
CHECK: [[FOR_BODY:.+]]: |
| 44 |
CHECK: {{.+}} = icmp sgt i32 {{.+}}, 2 |
| 45 |
|
| 46 |
Then comes the then branch of the if statement. |
| 47 |
CHECK: %[[I:.+]] = load i32, |
| 48 |
CHECK-NEXT: %[[INC:.+]] = add nsw i32 %[[I]], 1 |
| 49 |
CHECK-NEXT: store i32 %[[INC]], |
| 50 |
|
| 51 |
Eventually, we get to the goto label and its call |
| 52 |
CHECK: [[GOTO_TARGET]]: |
| 53 |
CHECK-NEXT: call void @foo() |
| 54 |
CHECK-NEXT: br label %[[FOR_INC:.+]] |
| 55 |
|
| 56 |
CHECK: [[FOR_INC]]: |
| 57 |
CHECK-NEXT: %[[I2:.+]] = load i32, |
| 58 |
CHECK-NEXT: %[[INC2:.+]] = add nsw i32 %[[I2]], 1 |
| 59 |
CHECK-NEXT: store i32 %[[INC2]], |
| 60 |
CHECK-NEXT: br label %[[FOR_COND]] |
| 61 |
*/ |
| 62 |
} |
| 63 |
|