Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ private class PrimaryArgumentNode extends ArgumentNode {

PrimaryArgumentNode() { exists(CallInstruction call | op = call.getAnArgumentOperand()) }

override predicate argumentOf(DataFlowCall call, int pos) {
op = call.getPositionalArgumentOperand(pos)
or
op = call.getThisArgumentOperand() and pos = -1
}
override predicate argumentOf(DataFlowCall call, int pos) { op = call.getArgumentOperand(pos) }

override string toString() {
result = "Argument " + op.(PositionalArgumentOperand).getIndex()
Expand Down Expand Up @@ -110,10 +106,10 @@ class ReturnIndirectionNode extends ReturnNode {
override ReturnIndirectionInstruction primary;

override ReturnKind getKind() {
result = TIndirectReturnKind(-1) and
primary.isThisIndirection()
or
result = TIndirectReturnKind(primary.getParameter().getIndex())
exists(int index |
primary.hasIndex(index) and
result = TIndirectReturnKind(index)
)
}
}

Expand Down Expand Up @@ -500,13 +496,6 @@ class DataFlowType = IRType;

/** A function call relevant for data flow. */
class DataFlowCall extends CallInstruction {
/**
* Gets the nth argument for this call.
*
* The range of `n` is from `0` to `getNumberOfArguments() - 1`.
*/
Node getArgument(int n) { result.asInstruction() = this.getPositionalArgument(n) }

Function getEnclosingCallable() { result = this.getEnclosingFunction() }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,8 @@ class ParameterIndirectionNode extends ParameterNode {

override predicate isParameterOf(Function f, int pos) {
exists(int index |
f.getParameter(index) = instr.getParameter()
or
index = -1 and
instr.getIRVariable().(IRThisVariable).getEnclosingFunction() = f
instr.getEnclosingFunction() = f and
instr.hasIndex(index)
|
pos = getArgumentPosOfSideEffect(index)
)
Expand Down Expand Up @@ -476,16 +474,8 @@ class DefinitionByReferenceNode extends InstructionNode {
instr
.getPrimaryInstruction()
.(CallInstruction)
.getPositionalArgument(instr.getIndex())
.getArgument(instr.getIndex())
.getUnconvertedResultExpression()
or
result =
instr
.getPrimaryInstruction()
.(CallInstruction)
.getThisArgument()
.getUnconvertedResultExpression() and
instr.getIndex() = -1
}

/** Gets the parameter through which this value is assigned. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,17 @@ class InitializeParameterInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the parameter with index `index`, or
* if `index` is `-1` and this instruction initializes `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand All @@ -601,6 +612,18 @@ class InitializeIndirectionInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the memory pointed to by the parameter with
* index `index`, or if `index` is `-1` and this instruction initializes the memory
* pointed to by `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand Down Expand Up @@ -775,6 +798,17 @@ class ReturnIndirectionInstruction extends VariableInstruction {
* Holds if this instruction is the return indirection for `this`.
*/
final predicate isThisIndirection() { var instanceof IRThisVariable }

/**
* Holds if this instruction is the return indirection for the parameter with index `index`, or
* if this instruction is the return indirection for `this` and `index` is `-1`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.isThisIndirection()
}
Comment on lines +807 to +811

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of this predicate looks a lot like getArgumentOperand, but only the latter has pragma[noinline] on it. Is there a good reason to put pragma[noinline] on one but not the other?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, no. I suspect the pragma[noinline] is an artifact of me copy/pasting from getPositionalArgumentOperand. I'll just double-check that I can safely remove the new pragma[noinline]s.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... looking at this comment you made, I'd actually feel more comfortable adding a pragma[noinline] to the hasIndex predicates. It doesn't seem to be necessary right now, but if it avoids a future bad join-order we might as well put it there now. Would that be reasonable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

}

/**
Expand Down Expand Up @@ -1587,6 +1621,22 @@ class CallInstruction extends Instruction {
result = getPositionalArgumentOperand(index).getDef()
}

/**
* Gets the argument operand at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final ArgumentOperand getArgumentOperand(int index) {
index >= 0 and result = getPositionalArgumentOperand(index)
or
index = -1 and result = getThisArgumentOperand()
}

/**
* Gets the argument at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final Instruction getArgument(int index) { result = getArgumentOperand(index).getDef() }

/**
* Gets the number of arguments of the call, including the `this` pointer, if any.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,17 @@ class InitializeParameterInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the parameter with index `index`, or
* if `index` is `-1` and this instruction initializes `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand All @@ -601,6 +612,18 @@ class InitializeIndirectionInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the memory pointed to by the parameter with
* index `index`, or if `index` is `-1` and this instruction initializes the memory
* pointed to by `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand Down Expand Up @@ -775,6 +798,17 @@ class ReturnIndirectionInstruction extends VariableInstruction {
* Holds if this instruction is the return indirection for `this`.
*/
final predicate isThisIndirection() { var instanceof IRThisVariable }

/**
* Holds if this instruction is the return indirection for the parameter with index `index`, or
* if this instruction is the return indirection for `this` and `index` is `-1`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.isThisIndirection()
}
}

/**
Expand Down Expand Up @@ -1587,6 +1621,22 @@ class CallInstruction extends Instruction {
result = getPositionalArgumentOperand(index).getDef()
}

/**
* Gets the argument operand at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final ArgumentOperand getArgumentOperand(int index) {
index >= 0 and result = getPositionalArgumentOperand(index)
or
index = -1 and result = getThisArgumentOperand()
}

/**
* Gets the argument at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final Instruction getArgument(int index) { result = getArgumentOperand(index).getDef() }

/**
* Gets the number of arguments of the call, including the `this` pointer, if any.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,17 @@ class InitializeParameterInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the parameter with index `index`, or
* if `index` is `-1` and this instruction initializes `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand All @@ -601,6 +612,18 @@ class InitializeIndirectionInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the memory pointed to by the parameter with
* index `index`, or if `index` is `-1` and this instruction initializes the memory
* pointed to by `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand Down Expand Up @@ -775,6 +798,17 @@ class ReturnIndirectionInstruction extends VariableInstruction {
* Holds if this instruction is the return indirection for `this`.
*/
final predicate isThisIndirection() { var instanceof IRThisVariable }

/**
* Holds if this instruction is the return indirection for the parameter with index `index`, or
* if this instruction is the return indirection for `this` and `index` is `-1`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.isThisIndirection()
}
}

/**
Expand Down Expand Up @@ -1587,6 +1621,22 @@ class CallInstruction extends Instruction {
result = getPositionalArgumentOperand(index).getDef()
}

/**
* Gets the argument operand at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final ArgumentOperand getArgumentOperand(int index) {
index >= 0 and result = getPositionalArgumentOperand(index)
or
index = -1 and result = getThisArgumentOperand()
}

/**
* Gets the argument at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final Instruction getArgument(int index) { result = getArgumentOperand(index).getDef() }

/**
* Gets the number of arguments of the call, including the `this` pointer, if any.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,17 @@ class InitializeParameterInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the parameter with index `index`, or
* if `index` is `-1` and this instruction initializes `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand All @@ -601,6 +612,18 @@ class InitializeIndirectionInstruction extends VariableInstruction {
* Gets the parameter initialized by this instruction.
*/
final Language::Parameter getParameter() { result = var.(IRUserVariable).getVariable() }

/**
* Holds if this instruction initializes the memory pointed to by the parameter with
* index `index`, or if `index` is `-1` and this instruction initializes the memory
* pointed to by `this`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.getIRVariable() instanceof IRThisVariable
}
}

/**
Expand Down Expand Up @@ -775,6 +798,17 @@ class ReturnIndirectionInstruction extends VariableInstruction {
* Holds if this instruction is the return indirection for `this`.
*/
final predicate isThisIndirection() { var instanceof IRThisVariable }

/**
* Holds if this instruction is the return indirection for the parameter with index `index`, or
* if this instruction is the return indirection for `this` and `index` is `-1`.
*/
pragma[noinline]
final predicate hasIndex(int index) {
index >= 0 and index = this.getParameter().getIndex()
or
index = -1 and this.isThisIndirection()
}
}

/**
Expand Down Expand Up @@ -1587,6 +1621,22 @@ class CallInstruction extends Instruction {
result = getPositionalArgumentOperand(index).getDef()
}

/**
* Gets the argument operand at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final ArgumentOperand getArgumentOperand(int index) {
index >= 0 and result = getPositionalArgumentOperand(index)
or
index = -1 and result = getThisArgumentOperand()
}

/**
* Gets the argument at the specified index, or `this` if `index` is `-1`.
*/
pragma[noinline]
final Instruction getArgument(int index) { result = getArgumentOperand(index).getDef() }

/**
* Gets the number of arguments of the call, including the `this` pointer, if any.
*/
Expand Down
Loading