CodeQL library for C/C++
codeql/cpp-all 1.1.2-dev (changelog, source)
Search

Module DefUse

Module containing the predicates that connect uses to their reaching definition. The reaching definitions are computed separately for each unique use MemoryLocation. An instruction is treated as a definition of a use location if the defined location overlaps the use location in any way. Thus, a single instruction may serve as a definition for multiple use locations, since a single definition location may overlap many use locations.

Definitions and uses are identified by a block and an integer “offset”. An offset of -1 indicates the definition from a Phi instruction at the beginning of the block. An offset of 2i indicates a definition or use on the instruction at index i in the block. An offset of 2i+1 indicates a definition or use on the Chi instruction that will be inserted immediately after the instruction at index i in the block.

For a given use location, each definition and use is also assigned a “rank” within its block. The rank is simply the one-based index of that definition or use within the list of definitions and uses of that location within the block, ordered by offset. The rank allows the various reachability predicates to be computed more efficiently than they would if based solely on offset, since the set of possible ranks is dense while the set of possible offsets is potentially very sparse.

Import path

import semmle.code.cpp.ir.implementation.aliased_ssa.internal.SSAConstruction

Predicates

definitionReachesEndOfBlock

Holds if the definition that overlaps useLocation at (defBlock, defRank) reaches the end of block block without any intervening definitions that overlap useLocation.

definitionReachesUse

Holds if a definition that overlaps useLocation at (defBlock, defRank) reaches the use of useLocation at (useBlock, useRank) without any intervening definitions that overlap useLocation.

getDefinitionOrChiInstruction

Gets the Instruction for the definition at offset defOffset in block defBlock.

hasDefinitionAtRank

Holds if there is a definition at offset offset in block block that overlaps memory location useLocation. rankIndex is the rank of the definition as computed by defUseRank().

hasPhiOperandDefinition

Holds if the Phi instruction for location useLocation at the beginning of block phiBlock has an operand along the incoming edge from predBlock, where that operand’s definition is at offset defOffset in block defBlock.

hasUseAtRank

Holds if there is a use of memory location useLocation on instruction use in block block. rankIndex is the rank of the use use as computed by defUseRank.

locationLiveOnEntryToBlock

Holds if the specified useLocation is live on entry to block. This holds if there is a use of useLocation that is reachable from the start of block without passing through a definition that overlaps useLocation. Note that even a partially-overlapping definition blocks liveness, because such a definition will insert a Chi instruction whose result totally overlaps the location.

locationLiveOnExitFromBlock

Holds if the specified useLocation is live on exit from block.