mirror of
https://github.com/apple/swift.git
synced 2026-10-14 15:51:20 +02:00
This instruction marks an instruction as needing a diagnostic emitted for it, by some diagnostic pass. It's purpose is to allow for a separation between analysis/transformation and diagnostics. The motivating use-case is LifetimeResolution, which among other things, inserts copies that are required to make the SIL valid. But there are copies that are invalid according to the Swift language rules, that the pass also detects quite easily. Quality diagnostic emission can require some more heavy-weight analysis. Rather than bake that into LifetimeResolution, we mark such language-rule violations with a `diagnose` for some other pass to consume and emit.
34 lines
877 B
Plaintext
34 lines
877 B
Plaintext
// RUN: %target-sil-opt -verify %s
|
|
|
|
// Negative tests for parsing the `diagnose` instruction's required `[kind]`
|
|
// attribute.
|
|
|
|
sil_stage raw
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
class Klass {}
|
|
|
|
sil [ossa] @diagnose_missing_attribute : $@convention(thin) (@owned Klass) -> () {
|
|
bb0(%0 : @owned $Klass):
|
|
%1 = copy_value %0 : $Klass
|
|
diagnose %1 : $Klass
|
|
// expected-error @-1 {{diagnose requires an attribute like '[unpermitted_copy]'}}
|
|
destroy_value %1 : $Klass
|
|
destroy_value %0 : $Klass
|
|
%r = tuple ()
|
|
return %r : $()
|
|
}
|
|
|
|
sil [ossa] @diagnose_invalid_attribute : $@convention(thin) (@owned Klass) -> () {
|
|
bb0(%0 : @owned $Klass):
|
|
%1 = copy_value %0 : $Klass
|
|
diagnose [bogus] %1 : $Klass
|
|
// expected-error @-1 {{Attribute '[bogus]' is not known to the diagnose instruction}}
|
|
destroy_value %1 : $Klass
|
|
destroy_value %0 : $Klass
|
|
%r = tuple ()
|
|
return %r : $()
|
|
}
|