CodeQL library for C/C++
codeql/cpp-all 0.13.1 (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

getBaseSourceVariable

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

getIRFunction

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

getIndirection

Gets the index (i.e., the number of loads required) of this definition or use.

getLocation

Gets the location of this element.

getNode

Gets the node associated with this use.

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.

toString

Gets a textual representation of this element.

Inherited predicates

getBlock

Gets the block of this definition or use.

from UseImpl
getIndirectionIndex

Gets the indirection index of this use.

from UseImpl
getSourceVariable

Gets the variable that is defined or used.

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 UseImpl

Charpred