Top 3 Graph Representations from ASTs for Code Analysis

Beyond basic Abstract Syntax Trees (ASTs), specialized graph representations like Control Flow Graphs (CFG) for execution paths, Data Flow Graphs (DFG) for variable dependencies, and Program Dependency Graphs (PDG) which combine both, are crucial. Code Property Graphs (CPG) further unify these for comprehensive code analysis tasks.

The top 3

  1. Key Edges: CFG, DFG, and PDG's Defining Links: Differentiates Control Flow Graphs (CFG) by control transfer edges, Data Flow Graphs (DFG) by def-use chains, and Program Dependence Graphs (PDG) by combining both control and data dependence edges, each derived from an AST.
  2. Best Graph for Each: Analysis Task vs. Representation: Identifies Control Flow Graphs (CFG) as optimal for reachability and loop detection, Data Flow Graphs (DFG) for data anomaly and variable misuse, and Program Dependence Graphs (PDG) for precise program slicing.
  3. Graph Construction Hurdles: Pointer Aliasing & Dynamic Dispatch: Explores the complexities of accurately generating Control Flow Graphs and Data Flow Graphs from ASTs, highlighting challenges like resolving pointer aliasing, dynamic dispatch, and implicit control transfers in modern languages.

Sources

Open the full topic