Skip to content

Ruby: Include empty StmtSequences in CFG #7324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2021
Merged

Conversation

hmac
Copy link
Contributor

@hmac hmac commented Dec 7, 2021

Empty StmtSequences appear, for example, in the else branch of if
statements like the following:

foo

if cond
  bar
else
end

baz

Before this change, the CFG for this code would look like this:

    foo
     │
     │
     ▼
    cond
     │
true │
     ▼
    bar
     │
     │
     ▼
     if
     │
     │
     ▼
    baz

i.e. there is linear flow through the condition, the then branch, and
out of the if. This doesn't account for the possibility that the
condition is false and bar is not executed. After this change, the CFG
looks like this:

      foo
       │
       │
       ▼
      cond
     │    │
true │    │ false
     ▼    │
    bar   │
     │    │
     │    │
     ▼    ▼
       if
       │
       │
       ▼
      baz

i.e. we correctly account for the false condition.

Empty StmtSequences appear, for example, in the `else` branch of `if`
statements like the following:

    foo

    if cond
      bar
    else
    end

    baz

Before this change, the CFG for this code would look like this:

        foo
         │
         │
         ▼
        cond
         │
    true │
         ▼
        bar
         │
         │
         ▼
         if
         │
         │
         ▼
        baz

i.e. there is linear flow through the condition, the `then` branch, and
out of the if. This doesn't account for the possibility that the
condition is false and `bar` is not executed. After this change, the CFG
looks like this:

          foo
           │
           │
           ▼
          cond
         │    │
    true │    │ false
         ▼    │
        bar   │
         │    │
         │    │
         ▼    ▼
           if
           │
           │
           ▼
          baz

i.e. we correctly account for the `false` condition.
@hmac hmac added the Ruby label Dec 7, 2021
@hmac hmac marked this pull request as ready for review December 7, 2021 03:29
@hmac hmac requested a review from a team as a code owner December 7, 2021 03:29
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Great catch! I have started a DCA run, so let's wait for that before we merge.

@hvitved hvitved merged commit 4d797d6 into main Dec 7, 2021
@hvitved hvitved deleted the hmac/empty-else-cfg branch December 7, 2021 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants