[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 00:20:06 PST 2024


================
@@ -489,6 +482,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext &AC,
     }
     AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond =
+          dyn_cast_or_null<Expr>(Block.getTerminatorCondition())) {
+    if (State.Env.getValue(*TerminatorCond) == nullptr)
+      // FIXME: This only runs the builtin transfer, not the analysis-specific
+      // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+      // takes a `CFGElement` as input, but some expressions only show up as a
+      // terminator condition, but not as a `CFGElement`. The condition of an if
----------------
martinboehme wrote:

Hm, that's an idea!

I'd still like to leave this to a future patch, as it's a further change in behavior. Note that the code we had so far also only ran the builtin transfer; this FIXME just documents this previously undocumented deficiency, so we're not regressing in any way.

I'd like to make this change separately so that we can separate out any unwanted side-effects of the two changes.

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


More information about the cfe-commits mailing list