Fix to PR8880 (clang dies processing a for loop)
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199897 91177308-0d34-0410-b5e6-96231b3b80d8
Showing
- include/clang/Basic/DiagnosticSemaKinds.td 6 additions, 0 deletionsinclude/clang/Basic/DiagnosticSemaKinds.td
- include/clang/Sema/Scope.h 5 additions, 0 deletionsinclude/clang/Sema/Scope.h
- include/clang/Sema/Sema.h 4 additions, 0 deletionsinclude/clang/Sema/Sema.h
- lib/CodeGen/CGStmt.cpp 12 additions, 12 deletionslib/CodeGen/CGStmt.cpp
- lib/Parse/ParseStmt.cpp 7 additions, 6 deletionslib/Parse/ParseStmt.cpp
- lib/Sema/Scope.cpp 15 additions, 0 deletionslib/Sema/Scope.cpp
- lib/Sema/SemaStmt.cpp 44 additions, 12 deletionslib/Sema/SemaStmt.cpp
- test/Analysis/dead-stores.c 1 addition, 1 deletiontest/Analysis/dead-stores.c
- test/CodeGen/PR8880.c 173 additions, 0 deletionstest/CodeGen/PR8880.c
- test/Parser/bad-control.c 15 additions, 0 deletionstest/Parser/bad-control.c
- test/Sema/loop-control.c 121 additions, 0 deletionstest/Sema/loop-control.c
- test/Sema/statements.c 0 additions, 3 deletionstest/Sema/statements.c
Loading
Please register or sign in to comment