[all-commits] [llvm/llvm-project] 21ab25: [dataflow] Add global invariant condition to Dataf...

Sam McCall via All-commits all-commits at lists.llvm.org
Thu Sep 14 10:30:18 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 21ab252f972cd810888636c106bfa88a18f72572
      https://github.com/llvm/llvm-project/commit/21ab252f972cd810888636c106bfa88a18f72572
  Author: Sam McCall <sam.mccall at gmail.com>
  Date:   2023-09-14 (Thu, 14 Sep 2023)

  Changed paths:
    M clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
    M clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
    M clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

  Log Message:
  -----------
  [dataflow] Add global invariant condition to DataflowAnalysisContext (#65949)

This records facts that are not sensitive to the current flow condition,
and should apply to all environments.

The motivating case is recording information about where a Value
originated, such as nullability:
 - we may see the same Value for multiple expressions (e.g. reads of the
   same field) in multiple environments (multiple blocks or iterations)
 - we want to record information only when we first see the Value
   (e.g. Nullability annotations on fields only add information if we
   don't know where the value came from)
 - this information should be expressible as a SAT condition
 - we must add this SAT condition to every environment where the
   Value may appear

We solve this by recording the information in the global condition.
This doesn't seem particularly elegant, but solves the problem and is
a fairly small and natural extension of the Environment.

Alternatives considered:
 - store the constraint directly as a property on the Value.
   But it's more composable for such properties to always be variables
   (AtomicBoolValue), and constrain them with SAT conditions.
 - add a hook whenever values are created, giving the analysis the
   chance to populate them.
   However the framework relies on/provides the ability to construct
   values in arbitrary places without providing the context such a hook
   would need, this would be a very invasive change.




More information about the All-commits mailing list