Skip to content

Ruby: Case barrier guards - #10981

Closed
hmac wants to merge 12 commits into
github:mainfrom
hmac:case-barrier-guard-2
Closed

Ruby: Case barrier guards#10981
hmac wants to merge 12 commits into
github:mainfrom
hmac:case-barrier-guard-2

Conversation

@hmac

@hmachmac commented Oct 26, 2022

Copy link
Copy Markdown
Contributor
  • 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

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.
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
hmacforce-pushed the case-barrier-guard-2 branch from fefa973 to b2b4842CompareOctober 26, 2022 03:33
@hmac

hmac commented Nov 3, 2022

Copy link
Copy Markdown
ContributorAuthor

Closing in favour of #11114

@hmachmac closed this Nov 3, 2022
Sign up for freeto 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

@hmac