Skip to content

Conversation

@hmac
Copy link
Contributor

@hmac hmac commented Oct 26, 2022

  • Ruby: Add basic case string comp barrier guard
  • Ruby: Use better names in barrier guard predicates
  • Ruby: Add more case barrier guard tests
  • Ruby: Add SplatExprCfgNode
  • Ruby: Recognise more case barrier guards
  • Ruby: Fix barrier guard type
  • Ruby: Add placeholder test
  • Ruby: Add case barrier to command injection query
  • Ruby: Merge case barrier with string const barrier
  • Ruby: Add custom barrier guard for cases
  • Ruby: Move when clause special-case to shared code

hmac added 7 commits October 26, 2022 14:32
This recognises barriers of the form

    case foo
    when "some string literal"
      foo
    end

where the read of `foo` inside the `when` is guarded by the comparison
of `foo` with `"some string literal"`.

We don't yet recognise more complex constructs such as case array
inclusion.
A previous changed relaxed the signature from ExprCfgNode to AstCfgNode.
@github-actions github-actions bot added the Ruby label Oct 26, 2022
hmac added 4 commits October 26, 2022 16:33
Both these barriers are for comparison with a constant string, so it
seems cleaner to merge them together.
`when` clauses in case expressions exert control over their
corresponding `then` branches, but this is not easily noticeable in the
CFG. The individual patterns in the clause have conditional successors,
not the `when` node itself.

Specifically, this means that in an expression such as

    case foo
    when "foo", "bar"
      foo
    end

the pattern `"bar"` technically does not control the read of `foo` on
line 3, because that read is also reachable from the previous pattern
`"foo"`.

Instead of considering the patterns in isolation, we instead consider
the entire `when` clause, provided that all patterns have edges to the
`then` node with the same successor.

In practice this means we copy the implementation of
`DataFlow::BarrierGuard` but use a custom predicate in place of
`ConditionBlock.controls`.
This means that we will always treat `when` clauses specially when
considering whether one basic block controls another.

Provided the special case is correect, I think this is fine to do. It
allows us to simplify the case barrier guard by using the parameterized
module.
@hmac hmac force-pushed the case-barrier-guard-2 branch from fefa973 to b2b4842 Compare October 26, 2022 03:33
@hmac
Copy link
Contributor Author

hmac commented Nov 3, 2022

Closing in favour of #11114

@hmac hmac closed this Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant