[clang] 7d54aae - Revert "[Clang] Diagnose jumps into statement expressions"
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 12 08:54:24 PDT 2023
Author: Corentin Jabot
Date: 2023-07-12T17:54:16+02:00
New Revision: 7d54aae2f122cac8989af0b978938152c6b08454
URL: https://github.com/llvm/llvm-project/commit/7d54aae2f122cac8989af0b978938152c6b08454
DIFF: https://github.com/llvm/llvm-project/commit/7d54aae2f122cac8989af0b978938152c6b08454.diff
LOG: Revert "[Clang] Diagnose jumps into statement expressions"
This reverts commit b0cc947b5d0a74f4ffe63c53b32978b21498e72e.
Breaks in presence of asm goto
https://reviews.llvm.org/D154696#4493805
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
clang/test/Sema/asm-goto.cpp
clang/test/Sema/scope-check.c
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaObjC/scope-check.m
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f86dc00fa8bcfb..42e92576808218 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -585,10 +585,6 @@ Bug Fixes in This Version
(`#50243 <https://github.com/llvm/llvm-project/issues/50243>`_),
(`#48636 <https://github.com/llvm/llvm-project/issues/48636>`_),
(`#50320 <https://github.com/llvm/llvm-project/issues/50320>`_).
-- Correcly diagnose jumps into statement expressions.
- This ensures the behavior of Clang is consistent with GCC.
- (`#63682 <https://github.com/llvm/llvm-project/issues/63682>`_)
- (`#38717 <https://github.com/llvm/llvm-project/issues/38717>_`).
- Fix an assertion when using ``\u0024`` (``$``) as an identifier, by disallowing
that construct (`#62133 <https://github.com/llvm/llvm-project/issues/38717>_`).
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 695cf9bce93e87..eea4d4961c077a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6196,8 +6196,6 @@ def note_enters_block_captures_non_trivial_c_struct : Note<
"to destroy">;
def note_enters_compound_literal_scope : Note<
"jump enters lifetime of a compound literal that is non-trivial to destruct">;
-def note_enters_statement_expression : Note<
- "jump enters a statement expression">;
def note_exits_cleanup : Note<
"jump exits scope of variable with __attribute__((cleanup))">;
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index 45e3cc2b00f0e8..bd2ce9a93e7e03 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -477,21 +477,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
return;
}
- case Stmt::StmtExprClass: {
- // [GNU]
- // Jumping into a statement expression with goto or using
- // a switch statement outside the statement expression with
- // a case or default label inside the statement expression is not permitted.
- // Jumping out of a statement expression is permitted.
- StmtExpr *SE = cast<StmtExpr>(S);
- unsigned NewParentScope = Scopes.size();
- Scopes.push_back(GotoScope(ParentScope,
- diag::note_enters_statement_expression,
- /*OutDiag=*/0, SE->getBeginLoc()));
- BuildScopeInformation(SE->getSubStmt(), NewParentScope);
- return;
- }
-
case Stmt::ObjCAtTryStmtClass: {
// Disallow jumps into any part of an @try statement by pushing a scope and
// walking all sub-stmts in that scope.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6cebb7e2dd540d..56e9c4ca133278 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16490,8 +16490,6 @@ ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
void Sema::ActOnStartStmtExpr() {
PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
- // Make sure we diagnose jumping into a statement expression.
- setFunctionHasBranchProtectedScope();
}
void Sema::ActOnStmtExprError() {
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 55af13bfc0ef3a..0c357db764a92a 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -153,8 +153,7 @@ a: if constexpr(sizeof(n) == 4) // expected-error {{redefinition}} expected-not
void evil_things() {
goto evil_label; // expected-error {{cannot jump}}
- if constexpr (true || ({evil_label: false;})) {} // expected-note {{constexpr if}} \
- // expected-note {{jump enters a statement expression}}
+ if constexpr (true || ({evil_label: false;})) {} // expected-note {{constexpr if}}
if constexpr (true) // expected-note {{constexpr if}}
goto surprise; // expected-error {{cannot jump}}
diff --git a/clang/test/Sema/asm-goto.cpp b/clang/test/Sema/asm-goto.cpp
index 8e9aaa4382a651..64addd9d75b6ef 100644
--- a/clang/test/Sema/asm-goto.cpp
+++ b/clang/test/Sema/asm-goto.cpp
@@ -50,9 +50,8 @@ int test3(int n)
// expected-error at +2 {{cannot jump from this asm goto statement to one of its possible targets}}
// expected-error at +1 {{cannot jump from this asm goto statement to one of its possible targets}}
asm volatile goto("testl %0, %0; jne %l1;" :: "r"(n)::label_true, loop);
- // expected-note at +3 {{jump bypasses initialization of variable length array}}
- // expected-note at +2 {{possible target of asm goto statement}}
- // expected-note at +1 {{jump enters a statement expression}}
+ // expected-note at +2 {{jump bypasses initialization of variable length array}}
+ // expected-note at +1 {{possible target of asm goto statement}}
return ({int a[n];label_true: 2;});
// expected-note at +1 {{jump bypasses initialization of variable length array}}
int b[n];
diff --git a/clang/test/Sema/scope-check.c b/clang/test/Sema/scope-check.c
index c6aa421b3ebdef..d8201780635365 100644
--- a/clang/test/Sema/scope-check.c
+++ b/clang/test/Sema/scope-check.c
@@ -65,8 +65,7 @@ int test8(int x) {
// Statement expressions.
goto L3; // expected-error {{cannot jump from this goto statement to its label}}
- int Y = ({ int a[x]; // expected-note {{jump bypasses initialization of variable length array}} \
- // expected-note {{jump enters a statement expression}}
+ int Y = ({ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
L3: 4; });
goto L4; // expected-error {{cannot jump from this goto statement to its label}}
@@ -108,25 +107,25 @@ int test8(int x) {
4; })];
L10:; // bad
}
-
+
{
// FIXME: Crashes goto checker.
//goto L11;// ok
//int A[({ L11: 4; })];
}
-
+
{
goto L12;
-
+
int y = 4; // fixme-warn: skips initializer.
L12:
;
}
-
+
// Statement expressions 2.
goto L1; // expected-error {{cannot jump from this goto statement to its label}}
- return x == ({ // expected-note {{jump enters a statement expression}}
- int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ return x == ({
+ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
L1:
42; });
}
@@ -232,27 +231,3 @@ void test15(int n, void *pc) {
}
int test16(int [sizeof &&z]); // expected-error {{use of address-of-label extension outside of a function body}}
-
-void GH63682() {
- {
- goto L; // expected-error {{cannot jump from this goto statement to its label}}
- (void)sizeof (int){({ L:; 1; })}; // expected-note {{jump enters a statement expression}}
- }
- {
- goto M; // expected-error {{cannot jump from this goto statement to its label}}
- (void)({ M:; 1; }); // expected-note {{jump enters a statement expression}}
- }
- {
- (void)({ goto N; 1; }); // ok
- N: ;
- }
- {
- (void)sizeof (int){({ goto O; 1; })}; // ok (not evaluated)
- O: ;
- }
- {
- (void)sizeof(({goto P;}), 0); // expected-error {{cannot jump from this goto statement to its label}}
- return;
- (void)({P:1;}); // expected-note {{jump enters a statement expression}}
- }
-}
diff --git a/clang/test/SemaCXX/constant-expression-cxx14.cpp b/clang/test/SemaCXX/constant-expression-cxx14.cpp
index cf242aaf90aa63..52a7cceea2a3fd 100644
--- a/clang/test/SemaCXX/constant-expression-cxx14.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp
@@ -831,9 +831,8 @@ namespace StmtExpr {
case 0:
return 0;
- ({ // expected-note {{jump enters a statement expression}}
- case 1:// expected-error {{cannot jump from switch statement to this case label}} \
- // expected-note {{not supported}}
+ ({
+ case 1: // expected-note {{not supported}}
return 1;
});
}
diff --git a/clang/test/SemaObjC/scope-check.m b/clang/test/SemaObjC/scope-check.m
index 9cd9356c1d1d10..c6f88f26164ab6 100644
--- a/clang/test/SemaObjC/scope-check.m
+++ b/clang/test/SemaObjC/scope-check.m
@@ -15,7 +15,7 @@ void test1(void) {
} @finally {// expected-note {{jump bypasses initialization of @finally block}}
L3: ;
}
-
+
@try {
goto L4; // expected-error{{cannot jump}}
goto L5; // expected-error{{cannot jump}}
@@ -27,8 +27,8 @@ void test1(void) {
} @finally { // expected-note {{jump bypasses initialization of @finally block}}
L4: ;
}
-
-
+
+
@try { // expected-note 2 {{jump bypasses initialization of @try block}}
L7: ;
} @catch (C *c) {
@@ -36,19 +36,20 @@ void test1(void) {
} @finally {
goto L7; // expected-error{{cannot jump}}
}
-
+
goto L8; // expected-error{{cannot jump}}
- @try {
+ @try {
} @catch (A *c) {
} @catch (B *c) {
} @catch (C *c) { // expected-note {{jump bypasses initialization of @catch block}}
L8: ;
}
-
+
id X;
goto L9; // expected-error{{cannot jump}}
- @synchronized (X) // expected-note {{jump bypasses initialization of @synchronized block}}
- {
+ goto L10; // ok
+ @synchronized // expected-note {{jump bypasses initialization of @synchronized block}}
+ ( ({ L10: ; X; })) {
L9:
;
}
@@ -87,7 +88,7 @@ + (void)meth2 {
goto L0; // expected-error {{cannot jump}}
typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
L0:
-
+
goto L1; // expected-error {{cannot jump}}
A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
L1:
More information about the cfe-commits
mailing list