mate_query.cpg.models.node.ast.llvm module

Nodes in the LLVM AST.

At runtime, the models here are accessed via attributes on a CPG, not directly.

class mate_query.cpg.models.node.ast.llvm.Alloca(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Instruction

LLVM IR alloca instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property variable: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Argument(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Variable

A formal parameter to an LLVM function

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property allocation_site: RelationshipProperty
argument_number
Return type

int

property as_dwarf: RelationshipProperty
location

A location in a source-language file

Return type

dict

property memory_locations: Optional[List[MemoryLocation]]
might_be_null

True when the pointer analysis determines the parameter could be a null pointer

Return type

bool

name

The source-level name of this formal parameter

Return type

str

class mate_query.cpg.models.node.ast.llvm.Block(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

LLVM IR basic blocks

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property controls: RelationshipProperty

The blocks controlled by this block.

property entry: RelationshipProperty

The entry instruction for this block.

property instructions: RelationshipProperty

All instructions in this block.

label
Return type

str

property mi_blocks: RelationshipProperty

All middle-end blocks (``MachineBasicBlock``s) for this IR block.

pretty_string
Return type

str

sorted_mi_blocks() typing.Iterable[Node]

The ``MachineBasicBlock``s for this block, sorted.

Return type

typing.Iterable[Node]

property successors: RelationshipProperty

The successor blocks for this block.

property terminator: RelationshipProperty

The terminator instruction for this block.

class mate_query.cpg.models.node.ast.llvm.CSComparator(expression)

Bases: sqlalchemy.ext.hybrid.Comparator

A specialized SQLAlchemy Comparator for ConstantString

operate(op: Any, other: Any, **_kwargs: Any) Any

Operate on an argument.

This is the lowest level of operation, raises NotImplementedError by default.

Overriding this on a subclass can allow common behavior to be applied to all operations. For example, overriding ColumnOperators to apply func.lower() to the left and right side:

class MyComparator(ColumnOperators):
    def operate(self, op, other):
        return op(func.lower(self), func.lower(other))
Parameters
  • op – Operator callable.

  • *other – the ‘other’ side of the operation. Will be a single scalar for most operations.

  • **kwargs – modifiers. These may be passed by special operators such as ColumnOperators.contains().

  • op (Any) –

  • other (Any) –

  • _kwargs (Any) –

Return type

Any

prop
property
class mate_query.cpg.models.node.ast.llvm.Call(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.CallSite

LLVM IR call instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

is_direct
Return type

bool

class mate_query.cpg.models.node.ast.llvm.CallReturn(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

A node that connects a value used in a return statement to the corresponding call site.

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property bindings: RelationshipProperty
property callsite: RelationshipProperty
property instruction: RelationshipProperty
property returns_from: RelationshipProperty
property value: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.CallSite(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Instruction

LLVM IR instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property argument0: RelationshipProperty
property argument1: RelationshipProperty
property argument2: RelationshipProperty
property argument3: RelationshipProperty
property argument4: RelationshipProperty
property argument5: RelationshipProperty
property argument6: RelationshipProperty
property argument7: RelationshipProperty
property argument8: RelationshipProperty
property argument9: RelationshipProperty
classmethod argument_relationship(cpg: CPG, number: int) RelationshipProperty
Parameters
  • cpg (CPG) –

  • number (int) –

Return type

RelationshipProperty

property callee_operand: RelationshipProperty
calls(*fns)
property signatures: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Constant(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

A constant value in the LLVM IR

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

can_trap

true if evaluation of this constant could trap

Return type

bool

constant_data_subclass

If this constant had a type that was a subclass of the LLVM class ConstantData, which subclass was it?

Return type

str

contains_undef

true if this is a vector constant that includes any undefined elements

Return type

bool

is_all_ones_value

true if this is the value that would be returned by LLVM’s getAllOnesValue

Return type

bool

is_nan

true if this is a floating-point NaN constant or a vector floating-point constant with all NaN elements

Return type

bool

is_normal_fp

true if this is a normal (as opposed to denormal) floating-point scalar constant or a vector constant with all normal elements

Return type

bool

is_null_value

true if this is the value that would be returned by LLVM’s getNullValue

Return type

bool

is_one_value

true if the value is one

Return type

bool

is_zero_value

true if the value is negative zero or null value

Return type

bool

pretty_string
Return type

str

class mate_query.cpg.models.node.ast.llvm.ConstantFP(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Constant

A constant floating point value in the LLVM IR

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

class mate_query.cpg.models.node.ast.llvm.ConstantInt(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Constant

A constant int value in the LLVM IR

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

constant_int_value

The value of this integer constant.

Return type

int

class mate_query.cpg.models.node.ast.llvm.ConstantString(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Constant

A constant string value in the LLVM IR

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

string_value
class mate_query.cpg.models.node.ast.llvm.ConstantUndef(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Constant

An undef value in the LLVM IR

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

class mate_query.cpg.models.node.ast.llvm.Function(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

LLVM IR functions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

alignment
Return type

int

property arguments: RelationshipProperty
as_salient() mate_common.models.analyses.SalientFunction

Create a SalientFunction from this Function.

Return type

mate_common.models.analyses.SalientFunction

property blocks: RelationshipProperty
property callees: RelationshipProperty
property callsites: RelationshipProperty
demangled_name

The demangled name of the function.

Return type

str

property entry_block: RelationshipProperty
property entry_controls_blocks: RelationshipProperty
property entry_controls_instructions: RelationshipProperty
is_declaration

True if this function has no definition.

Return type

bool

location

A location in a source-language file

Return type

dict

property machine_functions: RelationshipProperty
name

The name of the LLVM function. For functions generated by compiling C code, this is often the same name that appears in the source, e.g. @recv’ (at the LLVM level) corresponds to ‘recv’ (at the C level). However, compiled from other languages, the names will often be mangled. The source-level name will generally appear as a substring in the LLVM-level name.

Return type

str

property plt_stub: RelationshipProperty
pretty_string
Return type

str

section
Return type

str

property signatures: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.GlobalVariable(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Variable

A program global variable at the LLVM level

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

alignment
Return type

int

has_initializer
Return type

bool

property initializer: RelationshipProperty
is_constant
Return type

bool

is_declaration

True if this global variable has no definition.

Return type

bool

location

A location in a source-language file

Return type

dict

property memory_locations: Optional[List[MemoryLocation]]
name
Return type

str

section
Return type

str

class mate_query.cpg.models.node.ast.llvm.Instruction(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

LLVM IR instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property controls: RelationshipProperty
intrinsic

If this field is set, this instruction is a call to an LLVM intrinsic function, and this field is the ID of that intrinsic.

Return type

int

location

A location in a source-language file

Return type

dict

might_be_null

True when the pointer analysis determines the value could be a null pointer

Return type

bool

opcode
Return type

str

property operand0: RelationshipProperty
property operand1: RelationshipProperty
property operand2: RelationshipProperty
property operand3: RelationshipProperty
property operand4: RelationshipProperty
property operand5: RelationshipProperty
property operand6: RelationshipProperty
property operand7: RelationshipProperty
property operand8: RelationshipProperty
property operand9: RelationshipProperty
classmethod operand_relationship(cpg: CPG, operand_number: int, operand_class: Optional[Type[Node]] = None) RelationshipProperty

Specifications of the operands of an LLVM instruction.

Arguments:

  • cpg: The CPG

  • operand_number: The operand number

  • operand_class: The Node subclass that should be on the other end of the use edge/relationship, if it’s more specific than LLVM’s Value class (e.g. the first operand of a CallSite) node should be a Function, but the other operands could be any Node in the LLVM AST).

Parameters
  • cpg (CPG) –

  • operand_number (int) –

  • operand_class (Optional[Type[Node]]) –

Return type

RelationshipProperty

pretty_string
Return type

str

ssa_name

The name of the SSA variable that this instruction ‘returns’ to, if set

Return type

str

property successors: RelationshipProperty
property uses: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Intrinsic(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Call

LLVM IR call instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

overloaded: ClassVar[bool] = False
class mate_query.cpg.models.node.ast.llvm.Invoke(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.CallSite

LLVM IR invoke instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

is_direct
Return type

bool

class mate_query.cpg.models.node.ast.llvm.LLVMType(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

A type in the LLVM type system. See https://llvm.org/docs/LangRef.html#type-system for details.

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

abi_type_alignment

the minimum ABI-required alignment for this type

Return type

int

alloc_size_in_bits

the offset in bits between successive objects of the specified type, including alignment padding; always a multiple of 8

Return type

int

property arguments: RelationshipProperty
array_size
property blocks: RelationshipProperty
property constants: RelationshipProperty
definition
property functions: RelationshipProperty
get(key: str) Any
Parameters

key (str) –

Return type

Any

property global_variables: RelationshipProperty
property instructions: RelationshipProperty
is_array_type
is_function_type
is_named_struct_type
is_pointer_type
is_struct_type
is_void
name
pretty_string
Return type

str

size_in_bits
store_size_in_bits

the maximum number of bits that may be overwritten by storing the specified type; always a multiple of 8

Return type

int

class mate_query.cpg.models.node.ast.llvm.Load(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Instruction

LLVM IR load instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property pointer_operand: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.LocalVariable(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Variable

An LLVM-level stack-local variable

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property allocation_site: RelationshipProperty
property as_dwarf: RelationshipProperty
property llvm_type: RelationshipProperty
location

A location in a source-language file

Return type

dict

property memory_locations: Optional[List[MemoryLocation]]
name

The source-level name of this local variable

Return type

str

property parent_function: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Memcpy(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Intrinsic

LLVM IR memcpy intrinsics

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property dest: RelationshipProperty
overloaded: ClassVar[bool] = True
property size: RelationshipProperty
property src: RelationshipProperty
property volatile: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Memset(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Intrinsic

LLVM IR memset intrinsics

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

overloaded: ClassVar[bool] = True
property pointer: RelationshipProperty
property size: RelationshipProperty
property value: RelationshipProperty
property volatile: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Module(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

The unified LLVM bitcode module that the program was compiled from

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

data_layout

The LLVM datalayout string

Return type

str

module_name

The name of the LLVM module

Return type

str

source_file

The source file that this module was loaded from, if from a single source file

Return type

str

symbols

A list of all symbols in the module

Return type

list

target_triple

The LLVM target triple

Return type

str

translation_units() RelationshipProperty

A sequence of all source-level translation units in this module.

Return type

RelationshipProperty

class mate_query.cpg.models.node.ast.llvm.ParamBinding(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

A node which connects argument values with formal parameters

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

arg_op_number
Return type

int

property argument: RelationshipProperty
property callsite: RelationshipProperty
property operand: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Resume(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Instruction

LLVM IR resume instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property value: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Ret(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Instruction

LLVM IR ret instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property value: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.Store(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node.ast.llvm.Instruction

LLVM IR store instructions

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

property pointer_operand: RelationshipProperty
property value_operand: RelationshipProperty
class mate_query.cpg.models.node.ast.llvm.UnclassifiedNode(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

An as-of-yet underspecified node of the LLVM AST

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

pretty_string
Return type

str

class mate_query.cpg.models.node.ast.llvm.Variable(uuid: str, kind: NodeKind, attributes: Dict[str, Any] = {})

Bases: mate_query.cpg.models.node._typechecking.NodeMixin

A variable in the LLVM IR

Parameters
  • uuid (str) –

  • kind (NodeKind) –

  • attributes (Dict[str, Any]) –

pretty_string
Return type

str