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-5022] Accepts-invalid: polymorphic use of non-required initializer #47598

Closed
swift-ci opened this issue May 26, 2017 · 5 comments
Closed
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5022
Radar rdar://problem/21991470
Original Reporter Deng (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.12.5
Xcode 8.3.2

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

md5: 0b580fd9a0aee060409a581f4093589c

Issue Description:

When trying to run this:

public class A {
    
    internal let x: Int
    
    internal init(x: Int) {
        self.x = x
    }
}

public protocol P {
    
    var y: Int { get }
    
    init(y: Int)
}

extension P where Self: A {
    
    public var y: Int {
        return x
    }
    
    public init(y: Int) {
        self.init(x: y)
    }
}

public class B: A, P {}

let b = B(y: 1)

I got this error:

error: memory read failed for 0x0
@belkadan
Copy link
Contributor

On master, with assertions on:

Assertion failed: (!TargetOffset.isInvalid() && "target not found!"), function getTargetOffset, file /Volumes/Data/swift-public/swift/lib/IRGen/GenMeta.cpp, line 2230.

4  swift                    0x000000010eb50427 swift::Type llvm::function_ref<swift::Type (swift::SubstitutableType*)>::callback_fn<swift::irgen::TypeConverter::getExemplarType(swift::CanType)::$_0>(long, swift::SubstitutableType*) + 23
5  libsystem_c.dylib        0x00007fffd62b0420 abort + 129
6  libsystem_c.dylib        0x00007fffd6277893 basename_r + 0
7  swift                    0x000000010eafbe11 (anonymous namespace)::MetadataSearcher<swift::irgen::ClassMetadataScanner<(anonymous namespace)::FindClassMethodIndex> >::getTargetIndex() + 289
8  swift                    0x000000010eafb83d swift::irgen::emitVirtualMethodValue(swift::irgen::IRGenFunction&, llvm::Value*, swift::SILType, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, bool) + 909
9  swift                    0x000000010eb8a151 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 8961
10 swift                    0x000000010eb8473f (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 7535
11 swift                    0x000000010eb824e9 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1353
12 swift                    0x000000010ea8cb0b swift::irgen::IRGenerator::emitGlobalTopLevel() + 459
13 swift                    0x000000010eb5fb28 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1160
14 swift                    0x000000010eb60066 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, unsigned int, llvm::GlobalVariable**) + 86
15 swift                    0x000000010ea0ba57 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 11399
16 swift                    0x000000010ea07cfa swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2650
17 swift                    0x000000010e9c47f0 main + 3312
18 libdyld.dylib            0x00007fffd621c235 start + 1
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--c8c5b1.o 
1.  While emitting IR SIL function "@_T04main1PPA2A1ACRbzAaBRzlExSi1y_tcfC".
 for 'init' at <stdin>:23:12

@belkadan
Copy link
Contributor

@swift-ci create

@aschwaighofer
Copy link
Member

The generated code is trying to call a class method that does not exist (' #A.init!allocator.1'):

sil @_T04main1PPA2A1ACRbzAaBRzlExSi1y_tcfC : $@convention(method) <Self where Self : A, Self : P> (Int, @thick Self.Type) -> @owned Self {
// %0                                             // users: %6, %3
// %1                                             // user: %4
bb0(%0 : $Int, %1 : $@thick Self.Type):
  %2 = alloc_stack $Self, var, name "self"        // users: %8, %9
  debug_value %0 : $Int, let, name "y", argno 1   // id: %3
  %4 = upcast %1 : $@thick Self.Type to $@thick A.Type // users: %6, %5
  %5 = class_method %4 : $@thick A.Type, #A.init!allocator.1 : (A.Type) -> (Int) -> A, $@convention(method) (Int, @thick A.Type) -> @owned A // user: %6
  %6 = apply %5(%0, %4) : $@convention(method) (Int, @thick A.Type) -> @owned A // user: %7
  %7 = unchecked_ref_cast %6 : $A to $Self        // users: %10, %8
  store %7 to %2 : $*Self                         // id: %8
  dealloc_stack %2 : $*Self                       // id: %9
  return %7 : $Self                               // id: %10
} // end sil function '_T04main1PPA2A1ACRbzAaBRzlExSi1y_tcfC'

sil_vtable A {
  #A.init!initializer.1: (A.Type) -> (Int) -> A : _T04main1ACACSi1x_tcfc        // A.init(x:)
  #A.deinit!deallocator: _T04main1ACfD  // A.__deallocating_deinit
}

@slavapestov
Copy link
Member

The code is invalid, because the call to the non-required initializer should not type check. Of course it shouldn't crash; the fix would be to emit a proper diagnostic, and not proceed to IRGen.

@slavapestov
Copy link
Member

#13351

@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

5 participants