[PATCH] D154696: [Clang] Diagnose jumps into statement expressions

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 7 12:11:14 PDT 2023


shafik added inline comments.


================
Comment at: clang/docs/ReleaseNotes.rst:571
   (`#61758 <https://github.com/llvm/llvm-project/issues/61758>`_)
+- Correcly diagnose jumps into statement expressions.
+  (`#63682 <https://github.com/llvm/llvm-project/issues/63682>`_)
----------------
Maybe remark this conforms with gcc behavior.


================
Comment at: clang/lib/Sema/JumpDiagnostics.cpp:489
+    Scopes.push_back(GotoScope(ParentScope,
+                               diag::note_enters_statement_expression, 0,
+                               SE->getBeginLoc()));
----------------
I guess we don't have a variable that stands or no-diagnostic.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:16468
   PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
+  setFunctionHasBranchProtectedScope();
 }
----------------
I see why we need this but I am not sure how someone would know that need to do this in addition to the change in `BuildScopeInformation(...)`


================
Comment at: clang/test/Sema/scope-check.c:251
+  {
+    (void)sizeof (int){({ goto O; 1; })}; // ok (not evaluated)
+    O: ;
----------------
I am sorry for this example:

```
int main() {
   sizeof(({goto label;}), 0);
   return 3;
  ({label:1;});  
}
```

see godbolt: https://godbolt.org/z/aeb6TbsoG

Note gcc's behavior Vs clangs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154696/new/

https://reviews.llvm.org/D154696



More information about the cfe-commits mailing list