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

[SR-4011] Accessing instance variable of struct in closure during initialisation causes compiler/REPL crash #46596

Closed
swift-ci opened this issue Feb 20, 2017 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4011
Radar None
Original Reporter palle (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift version:
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

gcc version:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Xcode Version 8.2.1 (8C1002)

macOS Sierra Version 10.12.3 (16D32)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, IRGen
Assignee None
Priority Medium

md5: 2aaa2bce8a7db20f0574ce701c00f484

Issue Description:

If an instance variable of a structure is accessed inside a closure during initialization, the compiler and REPL will crash. This issue does affect calls to functions like Array.map or Array.reduce

The following code can be used to reproduce the issue:

struct Bar {
    let foo: String = "Hello World"

    init() {
        _ = {
            print(self.foo)
        }()
    }
}

This crash appears using various types for the variable foo (Tested with String, Int, Float, [Int]).

This issue appears regardless of whether the variable foo is set inside the initializer or directly at the declaration.

Also, this issue was reproducible when the closure was only returning foo unchanged.

After entering this code into the REPL, it will crash with the message "Segmentation fault: 11".
When compiling the code from a file, the compiler will crash with the error message:

0  swift                    0x00000001040e43ad PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x00000001040e3b56 SignalHandler(int) + 790
2  libsystem_platform.dylib 0x00007fff8e0fabba _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff5eb7f8f0 _sigtramp + 3500690768
4  swift                    0x00000001012148a4 (anonymous namespace)::StructTypeInfoBase<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo>::projectFieldAddress(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, swift::VarDecl*) const + 212
5  swift                    0x000000010121469e swift::irgen::projectPhysicalStructMemberAddress(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::SILType, swift::VarDecl*) + 126
6  swift                    0x0000000101260c12 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 28002
7  swift                    0x0000000101257458 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9160
8  swift                    0x000000010116920f swift::irgen::IRGenerator::emitLazyDefinitions() + 6399
9  swift                    0x000000010123c58a performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1802
10 swift                    0x00000001010f1f31 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23777
11 swift                    0x00000001010ea2b3 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17859
12 swift                    0x00000001010a65cf main + 8239
13 libdyld.dylib            0x00007fff8deed255 start + 1
14 libdyld.dylib            0x000000000000000f start + 1913728443
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file Bug.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 Bug -o /var/folders/_z/r4w3qsxd51z_2r9ww94k5z6w0000gn/T/Bug-de43d7.o 
1.  While emitting IR SIL function @_TFFV3Bug3BarcFT_S0_U_FT_T_ for expression at [Bug.swift:5:7 - line:7:3] RangeText="{
            print(self.foo)
        }"
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
@belkadan
Copy link
Contributor

Seems to be fixed in Swift 3.1. If you have the chance, can you try against the latest Xcode 8.3 beta?

@swift-ci
Copy link
Collaborator Author

Comment by Palle Klewitz (JIRA)

Yes, looks like this has been fixed in Swift 3.1

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

3 participants