Skip to content

[SILOptimizer] Don't diagnose unreachable instructions that belong to… #63390

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
Feb 3, 2023

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Feb 2, 2023

… no-return func

The pass is attempting to diagnose any user-written code that appears after the result of no-return function call. It has to skip any instructions that happen after the no-return call but are associated with it, such as alloc_stack to pass result of such call indirectly.

This helps to avoid extraneous diagnostics for synthesized code i.e. a result builder with buildExpression:

static func buildExpression<T>(_ e: T) -> T { e }

The following example would produce extraneous warning:

switch <value> {
case ...
default: fatalError()
}

because it is translated into:

switch <value> {
case ...
default: {
  var $__builderDefault = buildExpression(fatalError())
  $__builderSwitch = buildEither(second: $__builderDefault)
}
}

In such cases all instructions that follow fatalError() call are synthesized except to alloc_stack $Never which is passed to buildExpression, that instruction is anchored on the fatalError() itself which is where the diagnostic would point, which is incorrect.

Resolves: rdar://104931999

@xedin xedin requested a review from atrick February 2, 2023 21:43
@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2023

@swift-ci please test

… no-return func

The pass is attempting to diagnose any user-written code that appears
after the result of no-return function call. It has to skip any
instructions that happen after the no-return call but are associated
with it, such as `alloc_stack` to pass result of such call indirectly.

This helps to avoid extraneous diagnostics for synthesized code i.e.
a result builder with `buildExpression`:

```
static func buildExpression<T>(_ e: T) -> T { e }
```

The following example would produce extraneous warning:

```
switch <value> {
case ...
default: fatalError()
}
```

because it is translated into:

```
switch <value> {
case ...
default: {
  var $__builderDefault = buildExpression(fatalError())
  $__builderSwitch = buildEither(second: $__builderDefault)
}
}
```

In such cases all instructions that follow `fatalError()` call
are synthesized except to `alloc_stack $Never` which is passed
to `buildExpression`, that instruction is anchored on the
`fatalError()` itself which is where the diagnostic would point,
which is incorrect.

Resolves: rdar://104775183
@xedin
Copy link
Contributor Author

xedin commented Feb 2, 2023

@swift-ci please test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

LGTM

@xedin
Copy link
Contributor Author

xedin commented Feb 3, 2023

@swift-ci please test macOS platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants