Module HashCons

Provides an implementation of Hash consing. See https://en.wikipedia.org/wiki/Hash_consing

The predicate hashCons converts an expression into a HashCons, which is an abstract type presenting the hash-cons of the expression. If two expressions have the same HashCons then they are structurally equal.

Important note: this library ignores the possibility that the value of an expression might change between one occurrence and the next. For example:

x = a+b;
a++;
y = a+b;

In this example, both copies of the expression a+b will hash-cons to the same value, even though the value of a has changed. This is the intended behavior of this library. If you care about the value of the expression being the same, then you should use the GlobalValueNumbering library instead.

To determine if the expression x is structurally equal to the expression y, use the library like this:

hashCons(x) = hashCons(y)

Import path

semmle.code.cpp.valuenumbering.HashCons

Imports

cpp

Provides classes and predicates for working with C/C++/ObjC/ObjC++ code.

Predicates

analyzableExpr

Holds if the expression is explicitly handled by hashCons. Unanalyzable expressions still need to be given a hash-cons, but it will be a unique number that is not shared with any other expression.

hashCons

Gets the hash-cons of expression e.

Classes

HashCons

HashCons is the hash-cons of an expression. The relationship between Expr and HC is many-to-one: every Expr has exactly one HC, but multiple expressions can have the same HC. If two expressions have the same HC, it means that they are structurally equal. The HC is an opaque value. The only use for the HC of an expression is to find other expressions that are structurally equal to it. Use the predicate hashCons to get the HC for an Expr.