-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathIRCppLanguage.qll
More file actions
110 lines (71 loc) · 2.93 KB
/
IRCppLanguage.qll
File metadata and controls
110 lines (71 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
private import cpp as Cpp
private import IRUtilities
private import semmle.code.cpp.ir.implementation.IRType
private import semmle.code.cpp.ir.implementation.raw.internal.IRConstruction as IRConstruction
import CppType
class LanguageType = CppType;
class OpaqueTypeTag = Cpp::Type;
class TypeDomain = Cpp::TypeDomain;
class RealDomain = Cpp::RealDomain;
class ComplexDomain = Cpp::ComplexDomain;
class ImaginaryDomain = Cpp::ImaginaryDomain;
class Function = Cpp::Function;
class Location = Cpp::Location;
class UnknownLocation = Cpp::UnknownLocation;
class File = Cpp::File;
class AST = Cpp::Locatable;
class Type = Cpp::Type;
class UnknownType = Cpp::UnknownType;
class VoidType = Cpp::VoidType;
class IntegralType = Cpp::IntegralType;
class FloatingPointType = Cpp::FloatingPointType;
// REVIEW: May need to synthesize this for other languages. Or do we really need it at all?
class ClassDerivation = Cpp::ClassDerivation;
class StringLiteral = Cpp::StringLiteral;
class Variable = Cpp::Variable;
class AutomaticVariable = Cpp::StackVariable;
class StaticVariable = Cpp::StaticStorageDurationVariable;
class GlobalVariable = Cpp::GlobalOrNamespaceVariable;
class Parameter = Cpp::Parameter;
class Field = Cpp::Field;
class BuiltInOperation = Cpp::BuiltInOperation;
class Declaration = Cpp::Declaration;
// TODO: Remove necessity for these.
class Expr = Cpp::Expr;
class Class = Cpp::Class; // Used for inheritance conversions
predicate hasCaseEdge(string minValue, string maxValue) { hasCaseEdge(_, minValue, maxValue) }
predicate hasPositionalArgIndex(int argIndex) {
exists(Cpp::FunctionCall call | exists(call.getArgument(argIndex)))
or
exists(Cpp::BuiltInOperation op | exists(op.getChild(argIndex)))
or
// Ensure we are always able to output the argument of a call to the delete operator.
exists(Cpp::DeleteExpr d) and
argIndex = 0
}
predicate hasAsmOperandIndex(int operandIndex) {
exists(Cpp::AsmStmt asm | exists(asm.getChild(operandIndex)))
}
int getTypeSize(Type type) { result = type.getSize() }
int getPointerSize() { exists(Cpp::NullPointerType nullptr | result = nullptr.getSize()) }
predicate isVariableAutomatic(Cpp::StackVariable var) { any() }
string getStringLiteralText(StringLiteral s) {
result = s.getValueText().replaceAll("\n", " ").replaceAll("\r", "").replaceAll("\t", " ")
}
predicate hasPotentialLoop(Function f) {
exists(Cpp::Loop l | l.getEnclosingFunction() = f) or
exists(Cpp::GotoStmt s | s.getEnclosingFunction() = f)
}
predicate hasGoto(Function f) { exists(Cpp::GotoStmt s | s.getEnclosingFunction() = f) }
/**
* Gets the offset of field `field` in bits.
*/
int getFieldBitOffset(Field field) {
if field instanceof Cpp::BitField
then result = (field.getByteOffset() * 8) + field.(Cpp::BitField).getBitOffset()
else result = field.getByteOffset() * 8
}
/**
* Holds if the specified `Function` can be overridden in a derived class.
*/
predicate isFunctionVirtual(Function f) { f.isVirtual() }