Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic generic function crash with inlining, tuple with 1 param or using inout parameter #78425

Open
iDmitriyy opened this issue Jan 3, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@iDmitriyy
Copy link

Description

The crash appears only with certain combination of circumstances.

Reproduction

@inline(__always)
public func _countVariadicParams_for<each T>(_ params: repeat each T) -> Int {
  var count: Int = 0
  for _ in repeat each params {
    count += 1
  }
  return count
}

@inline(__always)
internal func _countVParams_ret_for<each L>(_ externalCount: inout Int) -> (repeat (each L).Type) {
  externalCount += _countVariadicParams_for(repeat (each L).self)
  
  let result = (repeat (each L).self)
  return result
}

var count: Int = 0
_countVParams_ret_for(&count) as (Int.Type)

Stack dump

xcrun swiftc -Osize swiftScript.swift -o swiftScript -v
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file swiftScript.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -color-diagnostics -Osize -new-driver-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name swiftScript -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path '/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server' -external-plugin-path '/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server' -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -enable-default-cmo -o /var/folders/sn/c6hd64q14v7bkp5g_b1ltqb80000gn/T/TemporaryDirectory.0u3OMl/swiftScript-1.o
error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.

Expected behavior

successful compilation

Environment

Swift 6, Xcode 16.2

Additional information

No crash when casting to as (Int.Type, Int.self) instead of as (Int.Type)
No crash when += is not done – externalCount += _countVariadicParams_for(repeat (each L).self) vs _countVariadicParams_for(repeat (each L).self)
No crash without @inline(__always)

@iDmitriyy iDmitriyy added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant