NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Shape Analysis

Reinhard Wilhelm, Shmuel Sagiv, Thomas W. Reps

Abstract

Shape analysis is a static analysis technique designed to predict the structural properties of heap-allocated data, such as linked lists and trees, during program execution. This paper presents a parametric framework implemented in the Three-Valued Logic Analysis (TVLA) system. By utilizing three-valued logic and a novel "summarization" process, the framework provides a robust method for verifying complex pointer manipulations and detecting memory errors like NULL pointer dereferences and memory leaks before execution.

Introduction

Pointers represent a significant challenge in imperative programming due to their ability to reference anonymous objects in an unbounded heap. These references often lead to side effects that are difficult for traditional static analysis to track accurately. Coarse approximations frequently fail to distinguish between disjoint data structures or to verify that structural invariants (e.g., acyclicity) are maintained after operations like list reversal. Such imprecision results in safety vulnerabilities, missed compiler optimizations, and difficult-to-trace aliasing bugs.

Methods: Parametric Shape Analysis

The proposed framework addresses these challenges through Parametric Shape Analysis, implemented in the TVLA system. The analysis represents the heap using abstract Shape Graphs. To maintain a finite state space for unbounded structures, the framework employs Summarization, where multiple heap cells are grouped into a single "summary node."

Figure 1: Control flow graph of a pointer-manipulating program used as input for shape analysis.

A core innovation is the use of Three-Valued Logic, which introduces an "Unknown" (1/2) value alongside True and False. This allows the system to represent uncertainty, such as whether a pointer might point to a specific summary node. To regain precision, the framework uses Materialization (or "focus"): when a pointer accesses a summary node, a concrete node is "materialized" from the abstraction, allowing for precise local updates.

Key Insights and Results

The analysis demonstrates that higher precision can lead to improved efficiency. By incorporating "instrumentation properties"—user-defined traits like reachability or sharing—the analysis can significantly prune the state space. For instance, in a list-merge benchmark, adding reachability properties reduced the number of generated graphs from tens of thousands to just 327, enabling completion in seconds.

Figure 3: Evolution of shape graphs during the analysis of a list reversal algorithm, showing the step-by-step transformation of the heap.

The TVLA engine, implemented in Java, successfully verified classic algorithms such as destructive list reversal. The system proved that the reversal program:

  1. Never dereferences a NULL pointer.
  2. Maintains the acyclicity of the list.
  3. Avoids creating unreachable "garbage" cells.
  4. Preserves disjointness between sub-lists.

Conclusion and Future Work

While highly effective for small, pointer-intensive kernels, shape analysis remains computationally expensive, with the state space potentially growing exponentially. Future work focuses on scaling the TVLA engine to larger programs and reducing the manual effort required to define instrumentation properties for diverse data structures like binary trees or doubly linked lists. Despite these challenges, the framework provides a foundational approach to formal heap verification.

Summary updated

BibTeX
@inproceedings{wilhelm2000shape,
  author = {Reinhard Wilhelm and Shmuel Sagiv and Thomas W. Reps},
  title = {{Shape Analysis}},
  booktitle = {CC},
  year = {2000},
  doi = {10.1007/3-540-46423-9\_1},
}
Figure