This is an archive of the discontinued LLVM Phabricator instance.

Fix to PR8880 (clang dies processing a for loop).
ClosedPublic

Authored by sepavloff on Jan 7 2014, 10:51 PM.

Details

Summary

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; }); )

Such usage must be diagnosed as an error, GCC rejects it. With this
change clang interprets such constructs as GCC in C++ mode: 'break'
and 'continue' in the 3rd expression refer to the loop itself, in
the 1st and 2nd expressions - to outer loop.

This revision is reincarnation of http://llvm-reviews.chandlerc.com/D2018, which was accidentally closed.

Diff Detail

Event Timeline

sepavloff updated this revision to Unknown Object (????).Jan 8 2014, 4:37 AM

Updated patch according to notes of Justin Bogner.

sepavloff updated this revision to Unknown Object (????).Jan 8 2014, 9:06 AM

Updated test for code generation.

sepavloff updated this revision to Unknown Object (????).Jan 18 2014, 9:12 AM

Changed implementation according to reviewer's notes.

Code generation is changed so that condition and increment expressions
in loop header are considered as if they are inside break/continue
scope of the loop. Such behavior is more close to GCC in C++ mode.
In C mode such usage causes GCC compatibility warning.

Thanks, this looks good.

include/clang/Basic/DiagnosticSemaKinds.td
6336 ↗(On Diff #6518)

... "to the enclosing loop" might be clearer.

test/CodeGen/PR8880.c
8 ↗(On Diff #6518)

This test will not work with a Clang built without asserts, because label names are not emitted into the text form of the IR. If you need to match label names, run the IR through opt -instnamer -S before piping it into FileCheck (see test/CodeGenCXX/for-range.cpp for an example).

test/Sema/loop-control.cpp
1 ↗(On Diff #6518)

Can you fold this and loop-control.c into the same source file? (Maybe use -verify for the C test and -Werror for this one.)

sepavloff closed this revision.Jan 23 2014, 7:11 AM

Closed by commit rL199897 (authored by @sepavloff).