[PATCH] D98816: PR49585: Emit the jump destination for a for loop 'continue' from within the scope of the condition variable.

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 17 14:09:30 PDT 2021


rsmith created this revision.
rsmith added a reviewer: rjmccall.
rsmith requested review of this revision.
Herald added a project: clang.

The condition variable is in scope in the loop increment, so we need to
emit the jump destination from wthin the scope of the condition
variable.

For GCC compatibility (and compatibility with real-world 'FOR_EACH'
macros), 'continue' is permitted in a statement expression within the
condition of a for loop, though, so there are two cases here:

- If the for loop has no condition variable, we can emit the jump destination before emitting the condition.

- If the for loop has a condition variable, we must defer emitting the jump destination until after emitting the variable. We diagnose a 'continue' appearing in the initializer of the condition variable, because it would jump past the initializer into the scope of that variable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98816

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Scope.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CodeGenCXX/for-cond-var.cpp
  clang/test/Parser/cxx2a-init-statement.cpp
  clang/test/SemaCXX/scope-check.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98816.331370.patch
Type: text/x-patch
Size: 15810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210317/0d210292/attachment.bin>


More information about the cfe-commits mailing list