Merge pull request #7392 from MathiasVP/fix-join-order-in-is-argument-for-parameter

C++: Fix join order in `isArgumentForParameter`
This commit is contained in:
Mathias Vorreiter Pedersen
2021-12-21 09:29:32 +01:00
committed by GitHub
3 changed files with 45 additions and 6 deletions

View File

@@ -266,6 +266,20 @@ private predicate operandReturned(Operand operand, IntValue bitOffset) {
bitOffset = Ints::unknown()
}
pragma[nomagic]
private predicate initializeParameterInstructionHasVariable(
IRVariable var, InitializeParameterInstruction init
) {
init.getIRVariable() = var
}
private predicate instructionInitializesThisInFunction(
Language::Function f, InitializeParameterInstruction init
) {
initializeParameterInstructionHasVariable(any(IRThisVariable var), pragma[only_bind_into](init)) and
init.getEnclosingFunction() = f
}
private predicate isArgumentForParameter(
CallInstruction ci, Operand operand, InitializeParameterInstruction init
) {
@@ -275,8 +289,7 @@ private predicate isArgumentForParameter(
(
init.getParameter() = f.getParameter(operand.(PositionalArgumentOperand).getIndex())
or
init.getIRVariable() instanceof IRThisVariable and
unique( | | init.getEnclosingFunction()) = f and
instructionInitializesThisInFunction(f, init) and
operand instanceof ThisArgumentOperand
) and
not Language::isFunctionVirtual(f) and

View File

@@ -266,6 +266,20 @@ private predicate operandReturned(Operand operand, IntValue bitOffset) {
bitOffset = Ints::unknown()
}
pragma[nomagic]
private predicate initializeParameterInstructionHasVariable(
IRVariable var, InitializeParameterInstruction init
) {
init.getIRVariable() = var
}
private predicate instructionInitializesThisInFunction(
Language::Function f, InitializeParameterInstruction init
) {
initializeParameterInstructionHasVariable(any(IRThisVariable var), pragma[only_bind_into](init)) and
init.getEnclosingFunction() = f
}
private predicate isArgumentForParameter(
CallInstruction ci, Operand operand, InitializeParameterInstruction init
) {
@@ -275,8 +289,7 @@ private predicate isArgumentForParameter(
(
init.getParameter() = f.getParameter(operand.(PositionalArgumentOperand).getIndex())
or
init.getIRVariable() instanceof IRThisVariable and
unique( | | init.getEnclosingFunction()) = f and
instructionInitializesThisInFunction(f, init) and
operand instanceof ThisArgumentOperand
) and
not Language::isFunctionVirtual(f) and