mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-22 04:55:50 -04:00

Due to statement expressions supported as GCC extension, it is possible to put 'break' or 'continue' into a loop/switch statement but outside its body, for example: for ( ; ({ if (first) { first = 0; continue; } 0; }); ) This code is rejected by GCC if compiled in C mode but is accepted in C++ code. GCC bug 44715 tracks this discrepancy. Clang used code generation that differs from GCC in both modes: only statement of the third expression of 'for' behaves as if it was inside loop body. This change makes code generation more close to GCC, considering 'break' or 'continue' statement in condition and increment expressions of a loop as it was inside the loop body. It also adds error for the cases when 'break'/'continue' appear outside loop due to this syntax. If code generation differ from GCC, warning is issued. Differential Revision: http://llvm-reviews.chandlerc.com/D2518 llvm-svn: 199897
25 lines
674 B
C
25 lines
674 B
C
/* RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
*/
|
|
void foo() {
|
|
break; /* expected-error {{'break' statement not in loop or switch statement}} */
|
|
}
|
|
|
|
void foo2() {
|
|
continue; /* expected-error {{'continue' statement not in loop statement}} */
|
|
}
|
|
|
|
int pr8880_9 (int first) {
|
|
switch(({ if (first) { first = 0; break; } 1; })) { // expected-error {{'break' statement not in loop or switch statement}}
|
|
case 2: return 2;
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
void pr8880_24() {
|
|
for (({break;});;); // expected-error {{'break' statement not in loop or switch statement}}
|
|
}
|
|
|
|
void pr8880_25() {
|
|
for (({continue;});;); // expected-error {{'continue' statement not in loop statement}}
|
|
}
|