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
VariableNodethat represents the global variable. - Flowing from the
VariableNodeto 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:
- Flow from
source()to(2)(via SSA). - Flow from
(2)to(1)(via ajumpStep). - Flow from
(1)to(3)(via ajumpStep). - Flow from
(3)to(4)(via SSA).
Import path
import semmle.code.cpp.ir.dataflow.internal.SsaImplDirect supertypes
Indirect supertypes
Inherited fields
Predicates
| getBaseSourceVariable | Gets the base source variable (i.e., the variable without any indirection) of this definition or use. |
| getIRFunction | Gets the |
| 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 |
| 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 | from UseImpl |