Skip to content

SIL verification failure #84337

@mhegazy

Description

@mhegazy

Description

SIL verification failure with !calleeConv.funcTy->hasErrorResult()

This is the smallest repro i could get to. apologies if not short enough. Here is a link to godbolt reproduction on nightly from main

Reproduction

/// test.swift
@propertyWrapper
public struct Dependency2<Value> {
  public init(
    _ keyPath: KeyPath<DependencyValues, Value>
  ) {

  }
  public var wrappedValue: Value {
      let any: Any = "somestring"
      return any as! Value
  }
}

struct Client {
    var get: (_ id: String) -> Bool
}

public struct DependencyValues {
    var client3: Client
}

public protocol WindowData2 {
    var id :String {get set}
}

extension WindowData2 {
    func didSetProfileForSpaceIDs(
        spaceIDs: [String]
    ) -> Void {
        @Dependency2(\.client3) var client: Client
        spaceIDs.forEach { _ in
            spaceIDs
                .map { _ in return client.get(id) }
        }
    }
}

Stack dump

SIL verification failed: apply instruction cannot call function with error result: !calleeConv.funcTy->hasErrorResult()
Verifying instruction:
   %0 = argument of bb0 : $Array<String>          // users: %38, %6, %2
   %1 = argument of bb0 : $*Self                  // users: %38, %3
     %4 = alloc_stack $Dependency2<Client>, var, name "_client", type $Dependency2<Client> // users: %38, %42
     %35 = alloc_stack [var_decl] $String         // users: %38, %40
     // function_ref specialized closure #1 in WindowData2.didSetProfileForSpaceIDs(spaceIDs:)
  %36 = function_ref @$s6output11WindowData2PAAE24didSetProfileForSpaceIDs05spaceI0ySaySSG_tFySSXEfU_Tf0nnsn_n : $@convention(thin) <τ_0_0 where τ_0_0 : WindowData2> (@in_guaranteed String, @guaranteed Array<String>, @inout_aliasable Dependency2<Client>, @in_guaranteed τ_0_0) -> @error any Error // user: %38
->   %38 = apply %36<Self>(%35, %0, %4, %1) : $@convention(thin) <τ_0_0 where τ_0_0 : WindowData2> (@in_guaranteed String, @guaranteed Array<String>, @inout_aliasable Dependency2<Client>, @in_guaranteed τ_0_0) -> @error any Error
In function:
// WindowData2.didSetProfileForSpaceIDs(spaceIDs:)
// Isolation: unspecified
sil hidden @$s6output11WindowData2PAAE24didSetProfileForSpaceIDs05spaceI0ySaySSG_tF : $@convention(method) <Self where Self : WindowData2> (@guaranteed Array<String>, @in_guaranteed Self) -> () {
[%0: noescape v**, noescape v**.c*.v**, read s0.s0.c*.i*.s0.s0.v**, copy v**.c*.v**, destroy v**.c*.v**]
[%1: read v**, write v**, copy v**, destroy v**]
[global: read,write,copy,destroy,allocate,deinit_barrier]
// %0 "spaceIDs"                                  // users: %38, %6, %2
// %1 "self"                                      // users: %38, %3
bb0(%0 : $Array<String>, %1 : $*Self):
  debug_value %0, let, name "spaceIDs", argno 1   // id: %2
  debug_value %1, let, name "self", argno 2, expr op_deref // id: %3
  %4 = alloc_stack $Dependency2<Client>, var, name "_client", type $Dependency2<Client> // users: %38, %42
  %5 = integer_literal $Builtin.Int64, 0          // users: %18, %14
  %6 = struct_extract %0, #Array._buffer          // user: %7
  %7 = struct_extract %6, #_ContiguousArrayBuffer._storage // users: %22, %8
  %8 = ref_element_addr [immutable] %7, #__ContiguousArrayStorageBase.countAndCapacity // user: %9
  %9 = struct_element_addr %8, #_ArrayBody._storage // user: %10
  %10 = struct_element_addr %9, #_SwiftArrayBodyStorage.count // user: %11
  %11 = struct_element_addr %10, #Int._value      // user: %12
  %12 = load %11                                  // user: %13
  %13 = builtin "assumeNonNegative_Int64"(%12) : $Builtin.Int64 // users: %19, %16
  br bb1(%5)                                      // id: %14

// %15                                            // users: %18, %19, %23, %31, %16
bb1(%15 : $Builtin.Int64):                        // Preds: bb2 bb0
  %16 = builtin "cmp_eq_Int64"(%15, %13) : $Builtin.Int1 // user: %17
  cond_br %16, bb3, bb2                           // id: %17

bb2:                                              // Preds: bb1
  %18 = builtin "cmp_slt_Int64"(%15, %5) : $Builtin.Int1 // user: %20
  %19 = builtin "cmp_sge_Int64"(%15, %13) : $Builtin.Int1 // user: %20
  %20 = builtin "or_Int1"(%18, %19) : $Builtin.Int1 // user: %21
  cond_fail %20, "Index out of range"             // id: %21
  %22 = ref_tail_addr [immutable] %7, $String     // user: %24
  %23 = builtin "truncOrBitCast_Int64_Word"(%15) : $Builtin.Word // user: %24
  %24 = index_addr [stack_protection] %22, %23    // user: %25
  %25 = struct_element_addr %24, #String._guts    // user: %26
  %26 = struct_element_addr %25, #_StringGuts._object // user: %27
  %27 = struct_element_addr %26, #_StringObject._object // user: %28
  %28 = load %27                                  // users: %39, %37
  %29 = integer_literal $Builtin.Int64, 1         // user: %31
  %30 = integer_literal $Builtin.Int1, -1         // user: %31
  %31 = builtin "sadd_with_overflow_Int64"(%15, %29, %30) : $(Builtin.Int64, Builtin.Int1) // users: %33, %32
  %32 = tuple_extract %31, 0                      // user: %41
  %33 = tuple_extract %31, 1                      // user: %34
  cond_fail %33, "arithmetic overflow"            // id: %34
  %35 = alloc_stack [var_decl] $String            // users: %38, %40
  // function_ref specialized closure #1 in WindowData2.didSetProfileForSpaceIDs(spaceIDs:)
  %36 = function_ref @$s6output11WindowData2PAAE24didSetProfileForSpaceIDs05spaceI0ySaySSG_tFySSXEfU_Tf0nnsn_n : $@convention(thin) <τ_0_0 where τ_0_0 : WindowData2> (@in_guaranteed String, @guaranteed Array<String>, @inout_aliasable Dependency2<Client>, @in_guaranteed τ_0_0) -> @error any Error // user: %38
  strong_retain %28                               // id: %37
  %38 = apply %36<Self>(%35, %0, %4, %1) : $@convention(thin) <τ_0_0 where τ_0_0 : WindowData2> (@in_guaranteed String, @guaranteed Array<String>, @inout_aliasable Dependency2<Client>, @in_guaranteed τ_0_0) -> @error any Error
  strong_release %28                              // id: %39
  dealloc_stack %35                               // id: %40
  br bb1(%32)                                     // id: %41

bb3:                                              // Preds: bb1
  dealloc_stack %4                                // id: %42
  %43 = tuple ()                                  // user: %44
  return %43                                      // id: %44
} // end sil function '$s6output11WindowData2PAAE24didSetProfileForSpaceIDs05spaceI0ySaySSG_tF'

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend -frontend -S -primary-file <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -no-color-diagnostics -Xcc -fno-color-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -O -empty-abi-descriptor -file-compilation-dir /app -Xllvm --x86-asm-syntax=intel -no-auto-bridging-header-chaining -module-name output -in-process-plugin-server-path /cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/lib/swift/host/plugins -plugin-path /cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/local/lib/swift/host/plugins -enable-default-cmo -o /app/output.s
1.	Swift version 6.3-dev (LLVM 73f0f4667f22bd1, Swift c987ea9c8e684c2)
2.	Compiling with effective version 5.10
3.	While verifying SIL function "@$s6output11WindowData2PAAE24didSetProfileForSpaceIDs05spaceI0ySaySSG_tF".
 for 'didSetProfileForSpaceIDs(spaceIDs:)' (at <source>:28:5)
 #0 0x0000628135c9b0e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x8c610e8)
 #1 0x0000628135c98c0e llvm::sys::RunSignalHandlers() (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x8c5ec0e)
 #2 0x0000628135c9b781 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007a7490042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007a74900969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007a7490042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007a74900287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000062812ed6b3e4 (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x1d313e4)
 #8 0x000062812ed8c597 swift::SILVisitorBase<(anonymous namespace)::SILVerifier, void>::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
 #9 0x000062812ed762df (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) SILVerifier.cpp:0:0
#10 0x000062812ed744bb (anonymous namespace)::SILVerifier::visitSILFunction(swift::SILFunction*) SILVerifier.cpp:0:0
#11 0x000062812ed6be88 swift::SILFunction::verify(swift::CalleeCache*, bool, bool, bool) const (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x1d31e88)
#12 0x000062812ed6fc38 swift::SILModule::verify(swift::CalleeCache*, bool, bool) const (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x1d35c38)
#13 0x000062812ed6faef swift::SILModule::verify(bool, bool) const (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x1d35aef)
#14 0x000062812e31f5b0 swift::CompilerInstance::performSILProcessing(swift::SILModule*) (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0x12e55b0)
#15 0x000062812dfa4927 performCompileStepsPostSILGen(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#16 0x000062812dfa3730 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0xf69730)
#17 0x000062812dfb9cca withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#18 0x000062812dfa8ca4 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#19 0x000062812dfa5971 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0xf6b971)
#20 0x000062812dd0af80 swift::mainEntry(int, char const**) (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0xcd0f80)
#21 0x00007a7490029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#22 0x00007a7490029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#23 0x000062812dd09fd5 _start (/cefs/3b/3b7f5b7c333caf492bc06a41_swift-nightly/usr/bin/swift-frontend+0xccffd5)

*** Signal 6: Backtracing from 0x7a749011e88d... done ***

*** Program crashed: Aborted at 0x0000280000000001 ***

Platform: x86_64 Linux (Ubuntu 22.04.5 LTS)

Thread 0 "swift-frontend" crashed:

  0  0x00007a749011e88d <unknown> in libc.so.6
...


Registers:

rax 0x0000000000000000  0
rdx 0x0000000000000006  6
rcx 0x00007a749011e88d  48 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 b5 0f 00  H=·ðÿÿs·ÃH··sµ··
rbx 0x0000000000000006  6
rsi 0x0000000000000001  1
rdi 0x0000000000000001  1
rbp 0x0000000000000001  1
rsp 0x0000628151d49568  ab b7 c9 35 81 62 00 00 f0 97 d4 51 81 62 00 00  «·É5·b··ð·ÔQ·b··
 r8 0x0000628151d497f0  06 00 00 00 00 00 00 00 fa ff ff ff 00 00 00 00  ········úÿÿÿ····
 r9 0x0000628151d497f0  06 00 00 00 00 00 00 00 fa ff ff ff 00 00 00 00  ········úÿÿÿ····
r10 0x0000628151d497f0  06 00 00 00 00 00 00 00 fa ff ff ff 00 00 00 00  ········úÿÿÿ····
r11 0x0000000000000246  582
r12 0x0000000000000000  0
r13 0x0000000000000000  0
r14 0x0000000000000000  0
r15 0x0000628151d49578  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ················
rip 0x00007a749011e88d  48 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 b5 0f 00  H=·ðÿÿs·ÃH··sµ··

rflags 0x0000000000000246  ZF PF

cs 0x0033  fs 0x0000  gs 0x0000


Images (26 omitted):

0x00007a7490000000–0x00007a74901bc341 d5197096f709801829b118af1b7cf6631efa2dcd libc.so.6 /lib/x86_64-linux-gnu/libc.so.6

Backtrace took 0.00s

Program terminated with signal: SIGSEGV
Compiler returned: 139

Expected behavior

No crash when compile with -O.

Environment

Swift version 6.3-dev (LLVM 73f0f4667f22bd1, Swift c987ea9)

Additional information

I started seeing this consistently on 9/11 and later.

Command line:
MacOS

swift-frontend -frontend -c -primary-file test.swift  -O

Windows

swift-frontend.exe -frontend -c -primary-file test.swift  -target aarch64-unknown-windows-msvc -sdk %LOCALAPPDATA%\Programs\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\ -windows-sdk-version 10.0.22621.0 -O
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions