Skip to content

Commit 9ed8b75

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

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal

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
@@ -1163,6 +1163,49 @@ class Definition extends SsaImpl::Definition {
11631163
)
11641164
}
11651165

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

0 commit comments

Comments
 (0)