[PATCH] D152009: [clang] Fix assertion while parsing an invalid for loop
Corentin Jabot via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 6 23:55:27 PDT 2023
cor3ntin updated this revision to Diff 529186.
cor3ntin added a comment.
Add tests for missing semi colons
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152009/new/
https://reviews.llvm.org/D152009
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Parse/ParseStmt.cpp
clang/test/Parser/cxx0x-for-range.cpp
clang/test/Parser/objc-foreach-syntax.m
Index: clang/test/Parser/objc-foreach-syntax.m
===================================================================
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -21,8 +21,6 @@
static int test7(id keys) {
- // FIXME: would be nice to suppress the secondary diagnostics.
for (id key; in keys) ; // expected-error {{use of undeclared identifier 'in'}} \
- // expected-error {{expected ';' in 'for' statement specifier}} \
- // expected-warning {{expression result unused}}
+ // expected-error {{expected ';' in 'for' statement specifier}}
}
Index: clang/test/Parser/cxx0x-for-range.cpp
===================================================================
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,22 @@
}
}
}
+
+namespace GH63010 {
+void foo(int n) {
+ int a[] = {1, 2, 3, 4, 5};
+ {
+ for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}} \
+ // expected-error {{expected expression}}
+ for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}}
+ }
+ {
+ for (auto x = n ? 1 : 2 : a) // expected-error {{expected ';' in 'for' statement specifier}} \
+ // expected-error {{expected expression}}
+
+ } // expected-error {{expected statement}}
+ {
+ for (int i = 1; auto x = n ? 1 : 2 : a) // expected-error {{expected ';' in 'for' statement specifier}}
+ } // expected-error {{expected statement}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===================================================================
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
if (Tok.isNot(tok::semi)) {
if (!SecondPart.isInvalid())
Diag(Tok, diag::err_expected_semi_for);
- else
- // Skip until semicolon or rparen, don't consume it.
- SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
+ SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
}
if (Tok.is(tok::semi)) {
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2138,8 +2138,6 @@
DeclGroupPtrTy DG = ParseSimpleDeclaration(
DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false, FRI);
FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
- assert((FRI->ColonLoc.isValid() || !DG) &&
- "cannot find for range declaration");
return Sema::ConditionResult();
}
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -455,6 +455,9 @@
- Fix crash when diagnosing default comparison method.
(`#62791 <https://github.com/llvm/llvm-project/issues/62791>`_) and
(`#62102 <https://github.com/llvm/llvm-project/issues/62102>`_).
+- Fix assertion and quality of diagnostic messages in a for loop
+ containing multiple declarations and a range specifier
+ (`#63010 <https://github.com/llvm/llvm-project/issues/63010>`_).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152009.529186.patch
Type: text/x-patch
Size: 3448 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230607/6c44620d/attachment.bin>
More information about the cfe-commits
mailing list