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

Class GlobalUse

A use that models a synthetic “last use” of a global variable just before a function returns.

We model global variable flow by:

  • Inserting a last use of any global variable that’s modified by a function
  • Flowing from the last use to the VariableNode that represents the global variable.
  • Flowing from the VariableNode to an “initial def” of the global variable in any function that may read the global variable.
  • Flowing from the initial definition to any subsequent uses of the global variable in the function body.

For example, consider the following pair of functions:

int global;
int source();
void sink(int);

void set_global() {
  global = source();
}

void read_global() {
 sink(global);
}

we insert global uses and defs so that (from the point-of-view of dataflow) the above scenario looks like:

int global; // (1)
int source();
void sink(int);

void set_global() {
  global = source();
  __global_use(global); // (2)
}

void read_global() {
 global = __global_def; // (3)
 sink(global); // (4)
}

and flow from source() to the argument of sink is then modeled as follows:

  1. Flow from source() to (2) (via SSA).
  2. Flow from (2) to (1) (via a jumpStep).
  3. Flow from (1) to (3) (via a jumpStep).
  4. Flow from (3) to (4) (via SSA).

Import path

import semmle.code.cpp.ir.dataflow.internal.SsaInternals

Direct supertypes

Indirect supertypes

Fields

Inherited fields

Predicates

getBase

Gets the instruction that computes the base of this definition or use. This is always a VariableAddressInstruction or an CallInstruction.

getIRFunction

Gets the IRFunction whose body is exited from after this use.

getIndirection

Gets the number of loads that precedence this use.

getLocation

Gets the location of this element.

getNode

Gets the node associated with this use.

getSourceVariable

Gets the variable that is defined or used.

getUnderlyingType

Gets the type of this use, after typedefs have been resolved.

getUnspecifiedType

Gets the type of this use after specifiers have been deeply stripped and typedefs have been resolved.

getVariable

Gets the global variable associated with this use.

hasIndexInBlock

Holds if this definition or use has index index in block block.

isCertain

Holds if this use is guaranteed to read the associated variable.

Inherited predicates

getBaseSourceVariable

Gets the base source variable (i.e., the variable without any indirection) of this definition or use.

from DefOrUseImpl
getBlock

Gets the block of this definition or use.

from DefOrUseImpl
getIndirectionIndex

Gets the indirection index of this use.

from UseImpl
hasIndexInBlock

Holds if this definition (or use) has index index in block block, and is a definition (or use) of the variable sv

from DefOrUseImpl
toString

Gets a textual representation of this element.

from UseImpl

Charpred