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-5170] Complex expression with coding - broken function found #47746

Closed
dmcyk opened this issue Jun 9, 2017 · 7 comments
Closed

[SR-5170] Complex expression with coding - broken function found #47746

dmcyk opened this issue Jun 9, 2017 · 7 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

Comments

@dmcyk
Copy link
Contributor

dmcyk commented Jun 9, 2017

Previous ID SR-5170
Radar rdar://problem/32985962
Original Reporter @dmcyk
Type Bug
Status Closed
Resolution Duplicate
Environment

macOS 10.13 Beta (17A264c)
Default Swift compiler from the Xcode 9b1 toolchain

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

md5: a706cc9df765b88d29f55214f476a0f8

duplicates:

  • SR-5075 Swift 4 compiler crash: unexpected storage type that differs from type-of-rvalue

Issue Description:

class Foo: Codable {
    
    private enum CodingKeys: String, CodingKey {
        case nameKey
    }
    
    var name: String
    
    init(name: String) {
        self.name = name
    }
    
    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        name = try container.decode(String.self, forKey: .nameKey)
    }
    
    func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(name, forKey: .nameKey)
    }
    
}


struct Bar: Codable {
    var name: String
}

class FooKid: Foo {
    
    private enum CodingKeys: String, CodingKey {
        case fields, name
        
    }
    
    var fields: [Bar]
    
    init(name: String, fields: [Bar]) {
        self.fields = fields
        super.init(name: name)
        
    }
    
    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        fields = try container.decode([Bar].self, forKey: .fields)
        
        // abort trap 6
        try super.init(name: container.decode(String.self, forKey: .name))
        // compiles properly
//        let name = try container.decode(String.self, forKey: .name)
//        super.init(name: name)
        
        
    }
    
    override func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(fields, forKey: .fields)
        try container.encode(name, forKey: .name)
    }
    
}

Trying to compile this code results in a crash because broken function was found. When complex expression in `FooKid` required initializer is spread into separate value declaration and then call to superclass `init` then the code compiles properly.
Here's the output of using `swiftc file.swift` with the given code:

IntToPtr source must be an integral
  %89 = inttoptr %T4file3FooC* %54 to %T4file6FooKidC*
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!
0  swift                    0x000000010a4433aa PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010a4427e6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fffc2540efa _sigtramp + 26
3  libsystem_platform.dylib 0x000000010f98b934 _sigtramp + 1296345684
4  libsystem_c.dylib        0x00007fffc238114a abort + 127
5  swift                    0x0000000106e11b67 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$_0::__invoke(void*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool) + 551
6  swift                    0x000000010a4009bb llvm::report_fatal_error(llvm::Twine const&, bool) + 571
7  swift                    0x000000010a40077a llvm::report_fatal_error(char const*, bool) + 42
8  swift                    0x000000010a3d6c76 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 54
9  swift                    0x000000010a38416a llvm::FPPassManager::runOnFunction(llvm::Function&) + 506
10 swift                    0x000000010a38bcc9 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 377
11 swift                    0x000000010a38baba llvm::legacy::FunctionPassManager::run(llvm::Function&) + 410
12 swift                    0x0000000106f82238 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef) + 5128
13 swift                    0x0000000106e165bb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 19019
14 swift                    0x0000000106e10304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7332
15 swift                    0x0000000106dc6728 main + 12248
16 libdyld.dylib            0x00007fffc22dd515 start + 1
17 libdyld.dylib            0x000000000000000f start + 1037183739
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file file.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name file -o /var/folders/w4/1kb2384s29jg87fhm1rxxcb80000gn/T/file-d03c26.o
1.  Running pass 'Module Verifier' on function '@_T04file6FooKidCACs7Decoder_p4from_tKcfc'
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)
@belkadan
Copy link
Contributor

cc @itaiferber, aschwaighofer@apple.com (JIRA User)

@dmcyk
Copy link
Contributor Author

dmcyk commented Jun 13, 2017

I'd like to add that the error is not specific to `coding` code. e.g. the error breaks code compatibility between Swift 3.1 and 3.2, whereas I used to have such expression while using 3rd lib

try super.init(name: json.get("name"), id: .FieldOfStudy)

and it compiled fine \w Swift 3.1 but with 3.2 / 4 the error occurs and expression has to be changed to

let name: String = try json.get("name")
super.init(name: name, id: .FieldOfStudy)

in order to compile.

@belkadan
Copy link
Contributor

When you say "the error" you mean you get this same crash? Or a different error?

@dmcyk
Copy link
Contributor Author

dmcyk commented Jun 13, 2017

Same crash, sorry.

@belkadan
Copy link
Contributor

@swift-ci create

@aschwaighofer
Copy link
Member

This appears to be fixed with a recent swift.org 4.0 toolchain.

I tried the June 25 4.0 snapshot from https://swift.org/download/#snapshots

@belkadan
Copy link
Contributor

Suspected dup of SR-5075; fixed, regardless!

@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
Projects
None yet
Development

No branches or pull requests

4 participants