Skip to content

Commit bce32a8

Browse files
committed
C++: Add a few helper predicates on 'Definition' which the guards library needs.
1 parent 9ba0c76 commit bce32a8

File tree

1 file changed

+43
-0
lines changed
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal

1 file changed

+43
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,49 @@ class Definition extends SsaImpl::Definition {
11591159
)
11601160
}
11611161

1162+
/**
1163+
* Holds if this definition defines the parameter `p` upon entry into the
1164+
* enclosing function.
1165+
*/
1166+
pragma[nomagic]
1167+
predicate isParameterDefinition(Parameter p) {
1168+
this.getIndirectionIndex() = 0 and
1169+
getDefImpl(this).getValue().asInstruction().(InitializeParameterInstruction).getParameter() = p
1170+
}
1171+
1172+
/**
1173+
* Holds if this definition defines the `indirectionIndex`'th indirection of
1174+
* parameter `p` upon entry into the enclosing function.
1175+
*/
1176+
pragma[nomagic]
1177+
predicate isIndirectParameterDefinition(Parameter p, int indirectionIndex) {
1178+
this.getIndirectionIndex() = indirectionIndex and
1179+
indirectionIndex > 0 and
1180+
getDefImpl(this).getValue().asInstruction().(InitializeParameterInstruction).getParameter() = p
1181+
}
1182+
1183+
/**
1184+
* Holds if this definition defines the implicit `this` parameter upon entry into
1185+
* the enclosing member function.
1186+
*/
1187+
pragma[nomagic]
1188+
predicate isThisDefinition() {
1189+
this.getIndirectionIndex() = 0 and
1190+
getDefImpl(this).getValue().asInstruction().(InitializeParameterInstruction).hasIndex(-1)
1191+
}
1192+
1193+
/**
1194+
* Holds if this definition defines the implicit `*this` parameter (i.e., the
1195+
* indirection of the `this` parameter) upon entry into the enclosing member
1196+
* function.
1197+
*/
1198+
pragma[nomagic]
1199+
predicate isIndirectThisDefinition(int indirectionIndex) {
1200+
this.getIndirectionIndex() = indirectionIndex and
1201+
indirectionIndex > 0 and
1202+
getDefImpl(this).getValue().asInstruction().(InitializeParameterInstruction).hasIndex(-1)
1203+
}
1204+
11621205
/**
11631206
* Gets an `Operand` that represents an indirect use of this definition.
11641207
*

0 commit comments

Comments
 (0)