File: consume_operator_kills_copyable_values.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (47 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// RUN: %target-sil-opt -enable-sil-verify-all -o - -sil-consume-operator-copyable-values-checker -verify %s

// This file is meant for specific SIL patterns that may be hard to produce with
// the current swift frontend but have reproduced before and we want to make
// sure keep on working.

import Builtin

class Klass {}

struct Int {
  var _value: Builtin.Int64
}

enum Optional<T> {
case none
case some(T)
}

// Make sure that we only emit an error on the use within the loop and not on
// the destroy_value along the exit edge of the loop.
sil [ossa] @useInLoopWithDestroyOutOfLoop : $@convention(thin) (@guaranteed Klass) -> () {
bb0(%0 : @guaranteed $Klass):
  debug_value %0 : $Klass, let, name "x", argno 1
  %2 = begin_borrow [lexical] [var_decl] %0 : $Klass // expected-error {{'y' used after consume}}
  debug_value %2 : $Klass, let, name "y"
  %4 = copy_value %2 : $Klass
  %5 = move_value [allows_diagnostics] %4 : $Klass // expected-note {{consumed here}}
  destroy_value %5 : $Klass
  br bb1

bb1:
  switch_enum undef : $Optional<Int>, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb3

bb2(%58 : $Int):
  %59 = copy_value %2 : $Klass
  %60 = begin_borrow [lexical] [var_decl] %59 : $Klass // expected-note {{used here}}
  debug_value %60 : $Klass, let, name "m"
  end_borrow %60 : $Klass
  destroy_value %59 : $Klass
  br bb1

bb3:
  end_borrow %2 : $Klass
  %67 = tuple ()
  return %67 : $()
}