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-11269] Crash: explicit type annotation crashes compiler #53670

Closed
drodriguez opened this issue Aug 8, 2019 · 3 comments
Closed

[SR-11269] Crash: explicit type annotation crashes compiler #53670

drodriguez opened this issue Aug 8, 2019 · 3 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

@drodriguez
Copy link
Collaborator

Previous ID SR-11269
Radar rdar://problem/54312471
Original Reporter @drodriguez
Type Bug
Status Resolved
Resolution Done
Environment

Current Swift master (4277f11) and LLVM stable (200186e28b5), in a Linux machine.

It also reproduces when using master snapshot from August 5th in macOS (Apple Swift version 5.1-dev (LLVM 200186e28b, Swift caeb2a4))

Does NOT reproduce when using Xcode 10.3 compiler (Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5))

Does NOT reproduce when using 5.1 snapshot from July 25th in macOS (Apple Swift version 5.1-dev (LLVM 688b71e2f9, Swift 0450b7d))

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

md5: 7551db832e30a8dc577050cd990607e6

Issue Description:

When creating an extension of a type that conforms to `Sequence`, and restricting it to a `class`, being explicit about the type in a `for` loop crashes the compiler.

Example:

class Foo {}
extension Set where Element: Foo {
    private func function1() {
        for foo: Foo in self {
            print(foo)
        }
    }
}

Produces:

swift: /home/danielrodriguez/scratch/swift/llvm/include/llvm/Support/Casting.h:255: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = swift::ReferenceStorageType, Y = swift::TypeBase]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Stack dump:
0. Program arguments: /home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift -frontend -target x86_64-unknown-linux-gnu -module-cache-path /home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/swift-test-results/x86_64-unknown-linux-gnu/clang-module-cache -swift-version 4 -typo-correction-limit 10 /data/users/danielrodriguez/scratch/swift/swift/validation-test/compiler_crashers/something.swift -emit-ir
1. Swift version 5.1-dev (LLVM 200186e28b, Swift 4277f11922)
2. While emitting SIL for 'function1()' (at /data/users/danielrodriguez/scratch/swift/swift/validation-test/compiler_crashers/something.swift:6:13)
3. While silgen emitFunction SIL function "@$sSh9somethingAA3FooCRbzrlE9function133_C4FE6C49F06B596147E12F9712D372C2LLyyF".
 for 'function1()' (at /data/users/danielrodriguez/scratch/swift/swift/validation-test/compiler_crashers/something.swift:6:13)
 #&#8203;0 0x0000000006052d0f llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x6052d0f)
 #&#8203;1 0x0000000006050f60 llvm::sys::RunSignalHandlers() (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x6050f60)
 #&#8203;2 0x0000000006053278 SignalHandler(int) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x6053278)
 #&#8203;3 0x00007f47133625d0 __restore_rt (/lib64/libpthread.so.0+0xf5d0)
 #&#8203;4 0x00007f4711905207 __GI_raise (/lib64/libc.so.6+0x36207)
 #&#8203;5 0x00007f47119068f8 __GI_abort (/lib64/libc.so.6+0x378f8)
 #&#8203;6 0x00007f47118fe026 __assert_fail_base (/lib64/libc.so.6+0x2f026)
 #&#8203;7 0x00007f47118fe0d2 (/lib64/libc.so.6+0x2f0d2)
 #&#8203;8 0x000000000271bbc8 swift::CanTypeWrapperTraits<swift::ReferenceStorageType>::type swift::SILType::castTo<swift::ReferenceStorageType>() const (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x271bbc8)
 #&#8203;9 0x000000000271c80f swift::Lowering::SILGenFunction::emitSemanticStore(swift::SILLocation, swift::SILValue, swift::SILValue, swift::Lowering::TypeLowering const&, swift::IsInitialization_t) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x271c80f)
#&#8203;10 0x000000000267aa04 swift::Lowering::ManagedValue::forwardInto(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::SILValue) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x267aa04)
#&#8203;11 0x00000000026cf4dd swift::Lowering::SingleBufferInitialization::copyOrInitValueIntoSingleBuffer(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, bool, swift::SILValue) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26cf4dd)
#&#8203;12 0x00000000026cd9fa void llvm::function_ref<void (swift::SILValue)>::callback_fn<swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool)::$_6>(long, swift::SILValue) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26cd9fa)
#&#8203;13 0x00000000026b2786 swift::Lowering::SILGenBuilder::bufferForExpr(swift::SILLocation, swift::SILType, swift::Lowering::TypeLowering const&, swift::Lowering::SGFContext, llvm::function_ref<void (swift::SILValue)>) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26b2786)
#&#8203;14 0x00000000026c8370 swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26c8370)
#&#8203;15 0x00000000026f346a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26f346a)
#&#8203;16 0x00000000026dfe59 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26dfe59)
#&#8203;17 0x00000000026a0605 swift::Lowering::ArgumentSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::Initialization*) && (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26a0605)
#&#8203;18 0x00000000026a0e5c swift::Lowering::ArgumentSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*, swift::Lowering::TypeLowering const&) && (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26a0e5c)
#&#8203;19 0x00000000026fa2f0 (anonymous namespace)::RValueEmitter::visitCollectionExpr(swift::CollectionExpr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26fa2f0)
#&#8203;20 0x00000000026ed859 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26ed859)
#&#8203;21 0x00000000026ed815 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26ed815)
#&#8203;22 0x00000000026e2e48 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26e2e48)
#&#8203;23 0x0000000002692f77 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2692f77)
#&#8203;24 0x000000000267f675 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x267f675)
#&#8203;25 0x000000000269e4f0 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x269e4f0)
#&#8203;26 0x000000000269e21d (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x269e21d)
#&#8203;27 0x000000000269da30 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x269da30)
#&#8203;28 0x0000000002682789 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2682789)
#&#8203;29 0x00000000026819eb swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26819eb)
#&#8203;30 0x00000000026ed82c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26ed82c)
#&#8203;31 0x00000000026e3378 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26e3378)
#&#8203;32 0x0000000002743dac swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2743dac)
#&#8203;33 0x00000000027489ab std::_Function_handler<void (swift::Lowering::ManagedValue, swift::Lowering::SwitchCaseFullExpr&&), (anonymous namespace)::StmtEmitter::visitForEachStmt(swift::ForEachStmt*)::$_0>::_M_invoke(std::_Any_data const&, swift::Lowering::ManagedValue, swift::Lowering::SwitchCaseFullExpr&&) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x27489ab)
#&#8203;34 0x00000000026ce8a0 swift::Lowering::SwitchEnumBuilder::emit() && (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x26ce8a0)
#&#8203;35 0x0000000002745c79 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2745c79)
#&#8203;36 0x0000000002743cda swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2743cda)
#&#8203;37 0x0000000002741d2d swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2741d2d)
#&#8203;38 0x0000000002706a83 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2706a83)
#&#8203;39 0x0000000002671258 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_0::operator()(swift::SILFunction*) const (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2671258)
#&#8203;40 0x0000000002669410 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2669410)
#&#8203;41 0x0000000002761f79 SILGenExtension::visitFuncDecl(swift::FuncDecl*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x2761f79)
#&#8203;42 0x000000000275ebfb SILGenExtension::emitExtension(swift::ExtensionDecl*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x275ebfb)
#&#8203;43 0x000000000275ebbd swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x275ebbd)
#&#8203;44 0x000000000266ea9c swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x266ea9c)
#&#8203;45 0x000000000266f9e3 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x266f9e3)
#&#8203;46 0x000000000266feeb swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x266feeb)
#&#8203;47 0x00000000022feed8 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x22feed8)
#&#8203;48 0x00000000022fbbc5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x22fbbc5)
#&#8203;49 0x000000000229d3e6 main (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x229d3e6)
#&#8203;50 0x00007f47118f13d5 __libc_start_main (/lib64/libc.so.6+0x223d5)
#&#8203;51 0x000000000229d029 _start (/home/danielrodriguez/scratch/swift/build/my_linux/swift-linux-x86_64/bin/swift+0x229d029)
error: Aborted (core dumped)

The problem disappears if `class Foo {}` is a `protocol`, or if `for foo: Foo in self` doesn't explicitly use the `Foo` type.

PR with the crashing test: #26550

@theblixguy
Copy link
Collaborator

It crashes because of `print(foo)`. If you remove that then it compiles. Seems like its trying to cast foo (of type Foo) to a ReferenceStorageType and then crashing.

@belkadan
Copy link
Contributor

Wacky. Thanks, @drodriguez.

@swift-ci create

@theblixguy
Copy link
Collaborator

pschuh (JIRA User) has fixed this here: #26590

(PR has already been merged, so closing this on behalf of him). Thanks Parker!

@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