Skip to content

SIL verification failed: result of struct_extract does not match type of field #71708

@tayloraswift

Description

@tayloraswift

Description

this crashes 5.9.2 with assertions enabled

Reproduction

struct B
{
    let x:Bool
    let y:String
}
struct C
{
    init(b:borrowing B)
    {
        if  b.x
        {
            let _:String = b.y
        }
    }
}

class S
{
    init(x:Bool)
    {
    }
}
extension S
{
    convenience
    init()
    {
        self.init(x: true)
    }
}

Stack dump

SIL verification failed: result of struct_extract does not match type of field
  $@moveOnly Bool
  $Bool
Verifying instruction:
     %5 = begin_borrow %0 : $B                    // users: %8, %6
->   %6 = struct_extract %5 : $@moveOnly B, #B.x  // user: %7
     %7 = struct_extract %6 : $Bool, #Bool._value // user: %9
In function:
// C.init(b:)
sil hidden [ossa] @$s4main1CV1bAcA1BVh_tcfC : $@convention(method) (@guaranteed B, @thin C.Type) -> C {
// %0 "b"                                         // users: %4, %5, %3
// %1 "$metatype"
bb0(%0 : @noImplicitCopy @guaranteed $B, %1 : $@thin C.Type):
  %2 = alloc_stack $C, var, name "self", implicit // users: %12, %13
  %3 = copyable_to_moveonlywrapper [guaranteed] %0 : $B
  debug_value [moveable_value_debuginfo] %0 : $B, let, name "b", argno 1 // id: %4
  %5 = begin_borrow %0 : $B                       // users: %8, %6
  %6 = struct_extract %5 : $@moveOnly B, #B.x     // user: %7
  %7 = struct_extract %6 : $Bool, #Bool._value    // user: %9
  end_borrow %5 : $@moveOnly B                    // id: %8
  cond_br %7, bb1, bb2                            // id: %9
bb1:                                              // Preds: bb0
  br bb3                                          // id: %10
bb2:                                              // Preds: bb0
  br bb3                                          // id: %11
bb3:                                              // Preds: bb1 bb2
  %12 = load [trivial] %2 : $*C                   // user: %14
  dealloc_stack %2 : $*C                          // id: %13
  return %12 : $C                                 // id: %14
} // end sil function '$s4main1CV1bAcA1BVh_tcfC'
Stack dump:
0.      Program arguments: /usr/bin/swift-frontend -frontend -interpret - -disable-objc-interop -I swiftfiddle.com/_Packages/.build/release -new-driver-path /usr/bin/swift-driver -empty-abi-descriptor -resource-dir /usr/lib/swift -module-name main -plugin-path /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/plugins -l_Packages
1.      Swift version 5.9.2-dev (LLVM 2b42c5ce063a374, Swift 9067148bc9c9a72)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for main)
4.      While running pass #96 SILModuleTransform "MandatoryInlining".
5.      While verifying SIL function "@$s4main1CV1bAcA1BVh_tcfC".
 for 'init(b:)' (at <stdin>:8:5)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
/usr/bin/swift-frontend(+0x70ab263)[0x56116adbd263]
/usr/bin/swift-frontend(+0x70a8fae)[0x56116adbafae]
/usr/bin/swift-frontend(+0x70ab5da)[0x56116adbd5da]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f8d67280520]
/lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7f8d672d49fc]
/lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7f8d67280476]
/lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f8d672667f3]
/usr/bin/swift-frontend(+0x1f5c9d6)[0x561165c6e9d6]
/usr/bin/swift-frontend(+0x1f7b813)[0x561165c8d813]
/usr/bin/swift-frontend(+0x1f611d0)[0x561165c731d0]
/usr/bin/swift-frontend(+0x1f5f8b9)[0x561165c718b9]
/usr/bin/swift-frontend(+0x1f58363)[0x561165c6a363]
/usr/bin/swift-frontend(+0x1f5ba93)[0x561165c6da93]
/usr/bin/swift-frontend(+0x1d1ec90)[0x561165a30c90]
/usr/bin/swift-frontend(+0x1e5e842)[0x561165b70842]
/usr/bin/swift-frontend(+0x1e624eb)[0x561165b744eb]
/usr/bin/swift-frontend(+0x1ab5d2b)[0x5611657c7d2b]
/usr/bin/swift-frontend(+0x1ab5042)[0x5611657c7042]
/usr/bin/swift-frontend(+0x15fb2a2)[0x56116530d2a2]
/usr/bin/swift-frontend(+0x15fd88a)[0x56116530f88a]
/usr/bin/swift-frontend(+0x15f7d08)[0x561165309d08]
/usr/bin/swift-frontend(+0x15f7cbd)[0x561165309cbd]
/usr/bin/swift-frontend(+0x161926a)[0x56116532b26a]
/usr/bin/swift-frontend(+0x1605843)[0x561165317843]
/usr/bin/swift-frontend(+0x15f7f05)[0x561165309f05]
/usr/bin/swift-frontend(+0x16074f1)[0x5611653194f1]
/usr/bin/swift-frontend(+0x10687b7)[0x561164d7a7b7]
/usr/bin/swift-frontend(+0xde0114)[0x561164af2114]
/usr/bin/swift-frontend(+0xddf3ba)[0x561164af13ba]
/usr/bin/swift-frontend(+0xdf4fc5)[0x561164b06fc5]
/usr/bin/swift-frontend(+0xde2479)[0x561164af4479]
/usr/bin/swift-frontend(+0xde11a5)[0x561164af31a5]
/usr/bin/swift-frontend(+0xc2a30b)[0x56116493c30b]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f8d67267d90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f8d67267e40]
/usr/bin/swift-frontend(+0xc29a65)[0x56116493ba65]
*** Signal 11: Backtracing from 0x7f8d67266898...
 done ***
*** Program crashed: Bad pointer dereference at 0x0000000000000000 ***
Thread 0 "swift-frontend" crashed:
0  0x00007f8d67266898 <unknown> in libc.so.6
Registers:
rax 0x0000000000000000  0
rdx 0x00007f8d66f6f840  40 f8 f6 66 8d 7f 00 00 60 02 f7 66 8d 7f 00 00  @øöf····`·÷f····
rcx 0x00007f8d672d49fc  41 89 c5 41 f7 dd 3d 00 f0 ff ff b8 00 00 00 00  A·ÅA÷Ý=·ðÿÿ¸····
rbx 0x0000000000000006  6
rsi 0x0000000000000001  1
rdi 0x0000000000000001  1
rbp 0x00007f8d67459e90  01 00 00 00 01 00 00 00 40 f8 f6 66 8d 7f 00 00  ········@øöf····
rsp 0x00007ffc29915c50  20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ···············
 r8 0x0000000000000000  0
 r9 0x0000000000000000  0
r10 0x0000000000000008  8
r11 0x0000000000000246  582
r12 0x0000000000000018  24
r13 0x00007ffc29915f60  ef 73 79 6c 11 56 00 00 f0 60 91 29 fc 7f 00 00  ïsyl·V··ð`·)ü···
r14 0x00007ffc299166e8  00 ea 35 6f 11 56 00 00 90 16 49 6f 11 56 00 00  ·ê5o·V····Io·V··
r15 0x000056116f4b45f0  24 73 34 6d 61 69 6e 31 43 56 31 62 41 63 41 31  $s4main1CV1bAcA1
rip 0x00007f8d67266898  f4 83 3d 00 36 1f 00 05 75 14 c7 05 f4 35 1f 00  ô·=·6···u·Ç·ô5··
rflags 0x0000000000010246  ZF PF
cs 0x0033  fs 0x0000  gs 0x0000
Images (25 omitted):
0x00007f8d6723e000–0x00007f8d673fa341 c289da5071a3399de893d2af81d6a30c62646e1e libc.so.6 /usr/lib/x86_64-linux-gnu/libc.so.6
Backtrace took 0.12s

Expected behavior

it should not crash

Environment

Swift version 5.9.2-dev (LLVM 2b42c5ce063a374, Swift 9067148)
Target: x86_64-unknown-linux-gnu

Additional information

the unrelated class and convenience init really are required to reproduce this crash, although i can’t imagine how they could possibly be involved.

Fiddle

this does not crash on 5.10, or on main.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILSILOptimizerArea → compiler: SIL optimization passesassertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwarefunction parametersFeature → declarations: function parametersownershipFeature: Ownership modifiers and semanticsswift 6.0verifier

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions