Skip to content

Commit dae5af6

Browse files
authored
Merge pull request #7392 from MathiasVP/fix-join-order-in-is-argument-for-parameter
C++: Fix join order in `isArgumentForParameter`
2 parents f66a081 + dd6085f commit dae5af6

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ private predicate operandReturned(Operand operand, IntValue bitOffset) {
266266
bitOffset = Ints::unknown()
267267
}
268268

269+
pragma[nomagic]
270+
private predicate initializeParameterInstructionHasVariable(
271+
IRVariable var, InitializeParameterInstruction init
272+
) {
273+
init.getIRVariable() = var
274+
}
275+
276+
private predicate instructionInitializesThisInFunction(
277+
Language::Function f, InitializeParameterInstruction init
278+
) {
279+
initializeParameterInstructionHasVariable(any(IRThisVariable var), pragma[only_bind_into](init)) and
280+
init.getEnclosingFunction() = f
281+
}
282+
269283
private predicate isArgumentForParameter(
270284
CallInstruction ci, Operand operand, InitializeParameterInstruction init
271285
) {
@@ -275,8 +289,7 @@ private predicate isArgumentForParameter(
275289
(
276290
init.getParameter() = f.getParameter(operand.(PositionalArgumentOperand).getIndex())
277291
or
278-
init.getIRVariable() instanceof IRThisVariable and
279-
unique( | | init.getEnclosingFunction()) = f and
292+
instructionInitializesThisInFunction(f, init) and
280293
operand instanceof ThisArgumentOperand
281294
) and
282295
not Language::isFunctionVirtual(f) and

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ private predicate operandReturned(Operand operand, IntValue bitOffset) {
266266
bitOffset = Ints::unknown()
267267
}
268268

269+
pragma[nomagic]
270+
private predicate initializeParameterInstructionHasVariable(
271+
IRVariable var, InitializeParameterInstruction init
272+
) {
273+
init.getIRVariable() = var
274+
}
275+
276+
private predicate instructionInitializesThisInFunction(
277+
Language::Function f, InitializeParameterInstruction init
278+
) {
279+
initializeParameterInstructionHasVariable(any(IRThisVariable var), pragma[only_bind_into](init)) and
280+
init.getEnclosingFunction() = f
281+
}
282+
269283
private predicate isArgumentForParameter(
270284
CallInstruction ci, Operand operand, InitializeParameterInstruction init
271285
) {
@@ -275,8 +289,7 @@ private predicate isArgumentForParameter(
275289
(
276290
init.getParameter() = f.getParameter(operand.(PositionalArgumentOperand).getIndex())
277291
or
278-
init.getIRVariable() instanceof IRThisVariable and
279-
unique( | | init.getEnclosingFunction()) = f and
292+
instructionInitializesThisInFunction(f, init) and
280293
operand instanceof ThisArgumentOperand
281294
) and
282295
not Language::isFunctionVirtual(f) and

csharp/ql/src/experimental/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ private predicate operandReturned(Operand operand, IntValue bitOffset) {
266266
bitOffset = Ints::unknown()
267267
}
268268

269+
pragma[nomagic]
270+
private predicate initializeParameterInstructionHasVariable(
271+
IRVariable var, InitializeParameterInstruction init
272+
) {
273+
init.getIRVariable() = var
274+
}
275+
276+
private predicate instructionInitializesThisInFunction(
277+
Language::Function f, InitializeParameterInstruction init
278+
) {
279+
initializeParameterInstructionHasVariable(any(IRThisVariable var), pragma[only_bind_into](init)) and
280+
init.getEnclosingFunction() = f
281+
}
282+
269283
private predicate isArgumentForParameter(
270284
CallInstruction ci, Operand operand, InitializeParameterInstruction init
271285
) {
@@ -275,8 +289,7 @@ private predicate isArgumentForParameter(
275289
(
276290
init.getParameter() = f.getParameter(operand.(PositionalArgumentOperand).getIndex())
277291
or
278-
init.getIRVariable() instanceof IRThisVariable and
279-
unique( | | init.getEnclosingFunction()) = f and
292+
instructionInitializesThisInFunction(f, init) and
280293
operand instanceof ThisArgumentOperand
281294
) and
282295
not Language::isFunctionVirtual(f) and

0 commit comments

Comments
 (0)