Skip to content

Commit

Permalink
Merge pull request #14203 from hvitved/ruby/semantic-merge-fix
Browse files Browse the repository at this point in the history
Ruby: Fix semantic merge conflict
  • Loading branch information
hvitved authored Sep 13, 2023
2 parents e722e32 + f3a78ef commit bb7ba78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions ruby/ql/consistency-queries/DataFlowConsistency.ql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ private module Input implements InputSig<RubyDataFlow> {
arg.asExpr().getASuccessor(any(SuccessorTypes::ConditionalSuccessor c)).getASuccessor*() = n and
n.getASplit() instanceof Split::ConditionalCompletionSplit
)
or
// Synthetic block parameter nodes are passed directly as lambda-self reference
// arguments to all `yield` calls
arg instanceof ArgumentNodes::BlockParameterArgumentNode
}
}

Expand Down
28 changes: 16 additions & 12 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ private module ParameterNodes {
* The value of a block parameter at function entry, viewed as a node in a data
* flow graph.
*/
class BlockParameterNode extends ParameterNodeImpl, ArgumentNode, TBlockParameterNode {
class BlockParameterNode extends ParameterNodeImpl, TBlockParameterNode {
private MethodBase method;

BlockParameterNode() { this = TBlockParameterNode(method) }
Expand All @@ -935,16 +935,6 @@ private module ParameterNodes {
this.getMethod() = result.getExpr().(YieldCall).getEnclosingMethod()
}

// needed for variable capture flow
override predicate sourceArgumentOf(CfgNodes::ExprNodes::CallCfgNode call, ArgumentPosition pos) {
call = this.getAYieldCall() and
pos.isLambdaSelf()
}

override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
this.sourceArgumentOf(call.asCall(), pos)
}

override CfgScope getCfgScope() { result = method }

override Location getLocationImpl() {
Expand Down Expand Up @@ -1199,7 +1189,7 @@ abstract class ArgumentNode extends Node {
final DataFlowCall getCall() { this.argumentOf(result, _) }
}

private module ArgumentNodes {
module ArgumentNodes {
/** A data-flow node that represents an explicit call argument. */
class ExplicitArgumentNode extends ArgumentNode {
Argument arg;
Expand All @@ -1215,6 +1205,20 @@ private module ArgumentNodes {
}
}

class BlockParameterArgumentNode extends BlockParameterNode, ArgumentNode {
BlockParameterArgumentNode() { exists(this.getAYieldCall()) }

// needed for variable capture flow
override predicate sourceArgumentOf(CfgNodes::ExprNodes::CallCfgNode call, ArgumentPosition pos) {
call = this.getAYieldCall() and
pos.isLambdaSelf()
}

override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
this.sourceArgumentOf(call.asCall(), pos)
}
}

private class SummaryArgumentNode extends FlowSummaryNode, ArgumentNode {
private DataFlowCall call_;
private ArgumentPosition pos_;
Expand Down

0 comments on commit bb7ba78

Please sign in to comment.