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-7896] Build crash with "While emitting IR SIL function" #50431

Closed
swift-ci opened this issue Jun 6, 2018 · 4 comments
Closed

[SR-7896] Build crash with "While emitting IR SIL function" #50431

swift-ci opened this issue Jun 6, 2018 · 4 comments
Assignees
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 optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 6, 2018

Previous ID SR-7896
Radar rdar://problem/40853265
Original Reporter Shavitov (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.4

Swift 4.1

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

md5: 0815c6e4eed45e382e9733dc30dc4aab

Issue Description:

This unpleasant code

public final class B {
    var t : Int
    
    public init() {
        self.t = 1
    }
    
    public convenience init(val: Int) {
        self.init()
        self.t = val
    }
}

public class A<SomeType:B> {
    let someType : SomeType
    public init(val: Int) {
        someType = SomeType(val: val)
    }
}

causes build error with this text:

  swift                    0x000000010ae17fea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010ae173a6 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff5a559f5a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000018 _sigtramp + 2779406552
4  swift                    0x0000000107515932 swift::irgen::emitClassAllocation(swift::irgen::IRGenFunction&, swift::SILType, bool, int&, llvm::ArrayRef<std::__1::pair<swift::SILType, llvm::Value*> >) + 226
5  swift                    0x000000010763fe4d swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 9149
6  swift                    0x000000010763b4f1 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9073
7  swift                    0x0000000107530520 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1024
8  swift                    0x0000000107619f8e swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, llvm::GlobalVariable**) + 1806
9  swift                    0x0000000107478336 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 38310
10 swift                    0x000000010746d304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
11 swift                    0x0000000107421ce5 main + 18917
12 libdyld.dylib            0x00007fff5a24b015 start + 1
13 libdyld.dylib            0x000000000000003f start + 2782613547
...
1.  While emitting IR SIL function ... for 'init(val:)' at file.swift

This bug repeats if set flag -O.
Without this flag code compiles and works.
In both cases Xcode does not show any warnings.

@belkadan
Copy link
Contributor

belkadan commented Jun 6, 2018

Fun times. We should probably warn about SomeType: B, but it shouldn't crash. Either it should work or the init(val:) call should be rejected for not being required.

@swift-ci create

@belkadan
Copy link
Contributor

belkadan commented Jun 6, 2018

cc @slavapestov

@aschwaighofer
Copy link
Member

SIL Combine creates an invalid ``alloc_ref`` referencing a type parameter:

SIL verification failed: alloc_ref must allocate class: AI->isObjC() || AI->getType().getClassOrBoundGenericClass()
Verifying instruction:
->   %4 = alloc_ref $SomeType                     // users: %14, %5
     %5 = upcast %4 : $SomeType to $B             // users: %7, %10
     store %4 to %13 : $*SomeType                 // id: %14
In function:
// A.init(val:)
sil @$S6Crash21AC3valACyxGSi_tcfc : $@convention(method) <SomeType where SomeType : B> (Int, @owned A<SomeType>) -> @owned A<SomeType> {
// %0                                             // users: %12, %6, %2
// %1                                             // users: %15, %13, %3
bb0(%0 : $Int, %1 : $A<SomeType>):
  debug_value %0 : $Int, let, name "val", argno 1 // id: %2
  debug_value %1 : $A<SomeType>, let, name "self", argno 2 // id: %3
  %4 = alloc_ref $SomeType                        // users: %14, %5

@aschwaighofer
Copy link
Member

#17024

@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 optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

4 participants