> On Sep 8, 2016, at 6:50 AM, Ole Begemann via swift-dev <[email protected]>
> wrote:
>
> I'm seeing a segmentation fault when compiling this code with Xcode 8 GM:
>
> ```
> // stack.swift
> struct Stack<Element> {
> var elements: [Element] = []
> }
>
> extension Stack: ExpressibleByArrayLiteral {
> init(arrayLiteral elements: Element...) {
> self.elements = elements
> }
> }
> ```
>
> ---
>
> This is my Swift version (Xcode 8 GM):
>
> ```
> $ xcrun swift --version
> Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
> Target: x86_64-apple-macosx10.9
> ```
>
> I'm on OS X 10.11.6.
>
> ---
>
> Compiling with `xcrun swift stack.swift`, I see this:
>
> ```
> $ xcrun swift stack.swift
> 0 swift 0x000000010558fb6d
> PrintStackTraceSignalHandler(void*) + 45
> 1 swift 0x000000010558f5b6 SignalHandler(int) + 470
> 2 libsystem_platform.dylib 0x00007fff8e5a952a _sigtramp + 26
> 3 libsystem_platform.dylib 0x00007fff5d2ca6d0 _sigtramp + 3469873600
> 4 swift 0x0000000102a6d8b9
> swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 73
> 5 swift 0x0000000102aab07d void llvm::function_ref<void
> (swift::irgen::GenericRequirement)>::callback_fn<(anonymous
> namespace)::EmitPolymorphicArguments::emit(swift::CanTypeWrapper<swift::SILFunctionType>,
> llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*,
> swift::irgen::Explosion&)::$_14>(long, swift::irgen::GenericRequirement) + 861
> 6 swift 0x0000000102aa09e1 (anonymous
> namespace)::PolymorphicConvention::enumerateRequirements(llvm::function_ref<void
> (swift::irgen::GenericRequirement)> const&) + 129
> 7 swift 0x0000000102aaabdb
> swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&,
> swift::CanTypeWrapper<swift::SILFunctionType>,
> swift::CanTypeWrapper<swift::SILFunctionType>,
> llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*,
> swift::irgen::Explosion&) + 459
> 8 swift 0x0000000102b074f5 (anonymous
> namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2997
> 9 swift 0x0000000102af2268
> swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9080
> 10 swift 0x0000000102a184d0
> swift::irgen::IRGenerator::emitLazyDefinitions() + 5216
> 11 swift 0x0000000102ad819b
> performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*,
> swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*,
> unsigned int) + 1723
> 12 swift 0x0000000102ad6507
> swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*,
> swift::SILModule*, llvm::StringRef, llvm::LLVMContext&) + 1527
> 13 swift 0x00000001029baa7b
> swift::RunImmediately(swift::CompilerInstance&,
> std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>,
> std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char,
> std::__1::char_traits<char>, std::__1::allocator<char> > > > const&,
> swift::IRGenOptions&, swift::SILOptions const&) + 187
> 14 swift 0x00000001029a607e
> performCompile(swift::CompilerInstance&, swift::CompilerInvocation&,
> llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23358
> 15 swift 0x000000010299e265
> swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*,
> swift::FrontendObserver*) + 17029
> 16 swift 0x000000010295b82d main + 8685
> 17 libdyld.dylib 0x00007fff91eef5ad start + 1
> 18 libdyld.dylib 0x000000000000000c start + 1846610528
> Stack dump:
> 0. Program arguments:
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
> -frontend -interpret stack.swift -target x86_64-apple-macosx10.9
> -enable-objc-interop -sdk
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
> -color-diagnostics -module-name stack
> 1. While emitting IR SIL function
> @_TFV5stack5StackCft12arrayLiteralGSax__GS0_x_ for 'init' at stack.swift:6:5
> [1] 38858 segmentation fault xcrun swift stack.swift
> $
> ```
>
> ---
>
> Regression:
> I observed the same behavior at least in Xcode 8b6 and b5. I did not report
> this earlier because the problem did not occur in recent Swift snapshots. The
> oldest one I still have installed is `DEVELOPMENT-SNAPSHOT-2016-08-07-a`, and
> with that one it already compiles fine:
>
> ```
> # DEVELOPMENT-SNAPSHOT-2016-08-07-a
> $ swift --version
> Apple Swift version 3.0-dev (LLVM 17c4c6cf7a, Clang 4ca9e01a7c, Swift
> 13a9908f8d)
> Target: x86_64-apple-macosx10.9
>
> $ swift ~/code/stack.swift
> $
> ```
>
> ---
>
> Workaround:
> It compiles fine if I rewrite the `ExpressibleByArrayLiteral` initializer
> like this:
>
> ```
> struct Stack<Element> {
> var elements: [Element] = []
> }
>
> extension Stack: ExpressibleByArrayLiteral {
> init(arrayLiteral elements: Element...) {
> self.init(elements: elements)
> }
> }
> ```
>
> Or alternatively, provide an explicit initializer for the struct:
>
> ```
> struct Stack<Element> {
> var elements: [Element]
> init(elements: [Element]) {
> self.elements = elements
> }
> }
>
> extension Stack: ExpressibleByArrayLiteral {
> init(arrayLiteral elements: Element...) {
> self.elements = elements
> }
> }
> ```
>
> ---
>
> Is this something for Radar or bugs.swift.org?
FWIW, it’s actually fixed in master (probably due to Slava’s recent work on the
generics system). The primary benefit to filing a radar at this point is that
you’ll get notified when the fix makes it into an Xcode release.
- Doug
_______________________________________________
swift-dev mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-dev