Skip to content

Miscompile of Never-returning function passed to variadic Any parameter with -O #85851

@hamishknight

Description

@hamishknight

The following miscompiles and crashes with a seg fault instead of infinite looping when compiled with -O:

func foo() -> Never {
  while true {}
}
func bar(_ x: Any...) {}
bar(foo())

The SIL for main looks like this:

  %2 = integer_literal $Builtin.Word, 1           // user: %3
  %3 = alloc_ref [stack] [tail_elems $Any * %2] $_ContiguousArrayStorage<Any> // user: %4
  strong_release %3                               // id: %4
  br bb1                                          // id: %5

Seems like we're ending up with a spurious release of storage that was never retained

Swift version 6.3-dev (LLVM d519e7def27afb0, Swift dcebf64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILOptimizerArea → compiler: SIL optimization passesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfmiscompileBug: Compiler produces incorrect codegenoptimized onlyFlag: An issue whose reproduction requires optimized compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions