[clang] [clang][CFG] Fix crash on statement-expression in condition variable (PR #212138)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 26 18:52:20 PDT 2026


================
@@ -797,6 +797,21 @@ class CFGBuilder {
   CFGBlock *createBlock(bool add_successor = true);
   CFGBlock *createNoReturnBlock();
 
+  /// Add a statement to the CFG, returning the block it was added to.
+  ///
+  /// Beware that this does not necessarily leave \c Block current, because the
+  /// statement may itself contain control flow. In particular, a GCC
+  /// statement-expression holding a loop (e.g. \c ({ while (...) {} v; })) ends
+  /// the block it started in, so afterwards \c Block may be null and the
+  /// returned block may differ from the one on entry. Callers that need the
+  /// block a statement ended up in must therefore use the returned value rather
+  /// than \c Block, and keep the last non-null result when adding several
+  /// statements in a row. The same caveat applies to \c Visit(), which this
+  /// wraps.
+  ///
+  /// May also return null when no block was created, e.g. for a NullStmt when
+  /// \c Block is not current; callers therefore have to keep the previous
+  /// non-null block rather than overwrite it unconditionally.
----------------
ojhunt wrote:

Did you author this comment? The scale of the comment is unnecessary, in a way the Claude really likes to do.

https://github.com/llvm/llvm-project/pull/212138


More information about the cfe-commits mailing list