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-13555] Compiler crash when emitting IR #55992

Open
swift-ci opened this issue Sep 16, 2020 · 5 comments
Open

[SR-13555] Compiler crash when emitting IR #55992

swift-ci opened this issue Sep 16, 2020 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13555
Radar rdar://problem/68993159
Original Reporter sagishm (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode Version 12.0 (12A7209)

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

md5: 8c03d92935ef6c2e620c09ffcd51105b

Issue Description:

I have a compiler error when used following code:

public struct LoginApiError<T: GigyaAccountProtocol> {
    public let error: NetworkError
    public let interruption: GigyaInterruptions<T>?
    public init(error: NetworkError, interruption: GigyaInterruptions<T>? = nil) {
        self.error = error
        self.interruption = interruption
    }
}
* The `GigyaAccountProtocol` is Codable

When changing the struct to class it compiles successfully.

1. Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2. While evaluating request IRGenWholeModuleRequest(IR Generation for module Gigya)
3. While emitting IR for source file /Users/**/Documents/GigyaDemoApp2/Pods/Gigya/GigyaSwift/Network/Request/GigyaApiResult.swift
4. While emitting metadata for 'LoginApiError' (at /Users/**/Documents/GigyaDemoApp2/Pods/Gigya/GigyaSwift/Network/Request/GigyaApiResult.swift:31:8)
0  swift                    0x000000010cd71865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x000000010cd70865 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010cd71e1f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff692b85fd _sigtramp + 29
4  libsystem_malloc.dylib   0x00007fff69278297 tiny_malloc_should_clear + 288
5  swift                    0x0000000108d1eee2 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 194
6  swift                    0x0000000108d1c061 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 737
7  swift                    0x0000000108d24b3c void llvm::function_ref<void (unsigned int, swift::CanType, swift::ProtocolConformanceRef)>::callback_fn<swift::irgen::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, swift::ProtocolConformanceRef)>(long, unsigned int, swift::CanType, swift::ProtocolConformanceRef) + 108
8  swift                    0x0000000108c4d0da swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap, llvm::function_ref<void (unsigned int, swift::CanType, swift::ProtocolConformanceRef)>) + 298
9  swift                    0x0000000108d23f78 emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType, swift::irgen::DynamicMetadataRequest) + 728
10 swift                    0x0000000108d1eebe emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 158
11 swift                    0x0000000108d1c061 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 737
12 swift                    0x0000000108c1d914 swift::irgen::IRGenFunction::emitValueWitnessTableRef(swift::SILType, llvm::Value**) + 516
13 swift                    0x0000000108c35569 swift::irgen::IRGenFunction::emitValueWitnessFunctionRef(swift::SILType, llvm::Value*&, swift::irgen::ValueWitness) + 569
14 swift                    0x0000000108c3a3ef swift::irgen::emitDestroyCall(swift::irgen::IRGenFunction&, swift::SILType, swift::irgen::Address) + 127
15 swift                    0x0000000108bac9ca (anonymous namespace)::SinglePayloadEnumImplStrategy::emitIndirectAssign(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, swift::IsTake_t, bool) const + 2218
16 swift                    0x0000000108ba6d5c (anonymous namespace)::SinglePayloadEnumImplStrategy::assignWithCopy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, bool) const + 108
17 swift                    0x0000000108c670a7 swift::irgen::RecordTypeInfoImpl<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true>::assignWithCopy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address, swift::SILType, bool) const + 583
18 swift                    0x0000000108d35c56 swift::irgen::ScalarTypeLayoutEntry::assignWithCopy(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::irgen::Address) const + 182
19 swift                    0x0000000108c8ff51 addValueWitness(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::irgen::ValueWitness, swift::irgen::FixedPacking, swift::CanType, swift::SILType, swift::irgen::TypeInfo const&) + 9121
20 swift                    0x0000000108c8ccb8 swift::irgen::emitValueWitnessTable(swift::irgen::IRGenModule&, swift::CanType, bool, bool) + 1624
22 swift                    0x0000000108b5a263 swift::irgen::IRGenModule::emitGlobalDecl(swift::Decl*) + 115
23 swift                    0x0000000108b59ebc swift::irgen::IRGenModule::emitSourceFile(swift::SourceFile&) + 220
24 swift                    0x0000000108c99cca swift::IRGenWholeModuleRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2762
25 swift                    0x0000000108cc56e5 swift::SimpleRequest<swift::IRGenWholeModuleRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::IRGenWholeModuleRequest const&, swift::Evaluator&) + 37
26 swift                    0x0000000108c9fd9d llvm::Expected<swift::IRGenWholeModuleRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenWholeModuleRequest>(swift::IRGenWholeModuleRequest const&) + 941
27 swift                    0x0000000108c991dc swift::performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 220
28 swift                    0x00000001088e8ccc performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2892
29 swift                    0x00000001088d8ae0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21152
30 swift                    0x0000000108859c07 main + 1255
31 libdyld.dylib            0x00007fff690bfcc9 start + 1
32 libdyld.dylib            0x000000000000015c start + 18446603338753770644
error: Segmentation fault: 11 (in target 'Gigya' from project 'Pods')
21 swift                    0x0000000108c0e9f0 swift::irgen::emitStructMetadata(swift::irgen::IRGenModule&, swift::StructDecl*) + 4192
@typesanitizer
Copy link

@swift-ci create

@nate-chandler
Copy link
Contributor

sagishm (JIRA User) Thanks for your report! Unfortunately, the code here is not quite enough to trigger the compiler crash. Adding types until to compiles results in the following which compile without issue with Xcode 12 GM (Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)).

```
public protocol GigyaAccountProtocol : Codable {}
public struct NetworkError : Error {}
public struct GigyaInterruptions<T : GigyaAccountProtocol> {}

public struct LoginApiError<T: GigyaAccountProtocol> {
public let error: NetworkError
public let interruption: GigyaInterruptions<T>?
public init(error: NetworkError, interruption: GigyaInterruptions<T>? = nil) {
self.error = error
self.interruption = interruption
}
}
```

Can you provide a bit more code that when compiled on its own results in the crash?

@swift-ci
Copy link
Collaborator Author

Comment by Sagi Shmuel (JIRA)

Another solution was found, so when moving the `LoginApiError` above the `GigyaLoginResult` the compiler stop crashes.

@aschwaighofer
Copy link
Member

You can also work around the issue by adding "-Xfrontend -disable-type-layout" to the "Other Swift Flags" build setting.

A small repro:

public protocol P {}

public class Ref<T: P> {}

public enum E1<R: P> {
  case first(R)
  case second(S<R>)
}

public struct S<T: P> {
  public let f: E2<T>? = nil
}

public enum E2<T: P> {
    case first(Ref<T>)
    case second(String)
}
% swiftc -O Repro.swift
<crash>
% swiftc -O -Xfrontend -disable-type-layout Repro.swift
%

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

4 participants