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-5934] Segmentation fault: 11 when creating a Set from an array of arrays #48493

Closed
swift-ci opened this issue Sep 19, 2017 · 7 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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5934
Radar rdar://problem/34522348
Original Reporter michalciuba (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 4.0 (swiftlang-900.0.63 clang-900.0.37)

Xcode Version 9.0 (9A235)

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

md5: 56b6fc636fc82460ce2539269a008d4d

duplicates:

  • SR-5932 Segmentation fault: 11 when creating a Set of optionals

is duplicated by:

  • SR-6013 Segmentation fault while creating Set from Array inside an extension

relates to:

  • SR-5932 Segmentation fault: 11 when creating a Set of optionals

Issue Description:

Creating a set from an array of arrays, like this:

let arrayOfArrays = [["Test"]]
let set = Set(arrayOfArrays)}}

results in the following compiler crash:

0  swift                    0x0000000112e23dba PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000112e231f6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fffca7cfb3a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff00000000 _sigtramp + 897778912
4  swift                    0x0000000110981c15 swift::NominalTypeDecl::hasFixedLayout() const + 21
5  swift                    0x0000000110515931 (anonymous namespace)::LowerType::visitAnyStructType(swift::CanType, swift::StructDecl*) + 49
6  swift                    0x00000001105146c7 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type) + 2791
7  swift                    0x000000011004936f swift::Lowering::SILGenFunction::emitInitializationForVarDecl(swift::VarDecl*) + 1775
8  swift                    0x000000011004b643 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 83
9  swift                    0x00000001100c910d swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 1885
10 swift                    0x0000000110080389 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 393
11 swift                    0x000000010fff63a1 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 273
12 swift                    0x000000010fff5919 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 761
13 swift                    0x00000001100d7467 (anonymous namespace)::SILGenType::emitType() + 1143
14 swift                    0x000000010fffccaa swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 74
15 swift                    0x000000010fffbf6b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1115
16 swift                    0x000000010fffd8f9 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 841
17 swift                    0x000000010f7962c6 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13014
18 swift                    0x000000010f791784 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
19 swift                    0x000000010f7466a8 main + 12248
20 libdyld.dylib            0x00007fffca5c0235 start + 1
@belkadan
Copy link
Contributor

It shouldn't crash, of course, but it's worth noting that the code isn't valid, since Arrays aren't Hashable.

@belkadan
Copy link
Contributor

cc @xedin, @rudkx

@rudkx
Copy link
Member

rudkx commented Sep 19, 2017

Intersesting, we somehow end up with no relationship between the constraint that the element type needs to be Hashable and the other constraints in the system:

  $T0 conforms to Hashable [[locator@0x10d8fa870 [Type@/Users/mark_lacey/Radar/sr5934.swift:2:11 -> opened generic]]];
  disjunction [[locator@0x10d8fabc8 [Call@/Users/mark_lacey/Radar/sr5934.swift:2:11 -> apply function -> constructor member]]]:($T3) -> $T2 bound to decl Swift.(file).Set.init : <Element, Source where Element : Hashable, Element == Source.Element, Source : Sequence> (Set<Element>.Type) -> (Source) -> Set<Element> [[locator@0x10d8fabc8 [Call@/Users/mark_lacey/Radar/sr5934.swift:2:11 -> apply function -> constructor member]]]; or ($T3) -> $T2 bound to decl Swift.(file).SetAlgebra.init : <Self, S where Self : SetAlgebra, S : Sequence, Self.Element == S.Element> (Self.Type) -> (S) -> Self [[locator@0x10d8fabc8 [Call@/Users/mark_lacey/Radar/sr5934.swift:2:11 -> apply function -> constructor member]]];
  ([[String]]) arg tuple conv $T3 [[locator@0x10d8fab70 [Call@/Users/mark_lacey/Radar/sr5934.swift:2:11 -> apply argument]]];

@rudkx
Copy link
Member

rudkx commented Sep 19, 2017

@swift-ci create

@slavapestov
Copy link
Member

Here is a minimal repro:

struct S <T : Hashable> {
    init<C : Collection>(_: C) where C.Element == T {}
}

func f<T>(a: [T]) {
    _ = S(a)
}

@slavapestov
Copy link
Member

Smaller repro:

func g<T, U>(_: T) where T : Collection, T.Element == U, T.Element : Hashable {}

func f<T>(a: [T]) {
    _ = g(a)
}

In a build with asserts, we fail as follows:

l-value expression does not have l-value access kind set
(discard_assignment_expr type='@lvalue _' location=min.swift:4:5 range=[min.swift:4:5 - line:4:5])0  swift                    0x0000000106494db8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000106495476 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fffb5cd2b3a _sigtramp + 26
3  libsystem_platform.dylib 0x00000001164ef86d _sigtramp + 1619119437
4  libsystem_c.dylib        0x00007fffb5b57420 abort + 129
5  swift                    0x0000000103ee8894 (anonymous namespace)::Verifier::verifyChecked(swift::Expr*) + 116
6  swift                    0x0000000103ee3647 (anonymous namespace)::Verifier::walkToExprPost(swift::Expr*) + 12551
7  swift                    0x0000000103ef432a swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 11658
8  swift                    0x0000000103ef59a7 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Stmt*) + 391
9  swift                    0x0000000103ef7d0c (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 668
10 swift                    0x0000000103ef0e63 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 339
11 swift                    0x0000000103ef0cfb swift::Decl::walk(swift::ASTWalker&) + 27
12 swift                    0x0000000103f8deea swift::SourceFile::walk(swift::ASTWalker&) + 170
13 swift                    0x0000000103edf6cb swift::verify(swift::SourceFile&) + 59
14 swift                    0x0000000103cd346f swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1935
15 swift                    0x0000000103978f33 swift::CompilerInstance::parseAndTypeCheckMainFile(swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 435
16 swift                    0x0000000103977e0e swift::CompilerInstance::parseAndCheckTypes(swift::CompilerInstance::ImplicitImports const&) + 702
17 swift                    0x00000001039775d8 swift::CompilerInstance::performSema() + 520
18 swift                    0x0000000102e8901e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1742
19 swift                    0x0000000102e87a4b swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3339
20 swift                    0x0000000102e48880 main + 3360
21 libdyld.dylib            0x00007fffb5ac3235 start + 1
Stack dump:
0.  Program arguments: /Volumes/Transcend/build/Ninja-ReleaseAssert/swift-macosx-x86_64/bin/swift -frontend -c -primary-file min.swift -target x86_64-apple-darwin16.7.0 -enable-objc-interop -color-diagnostics -module-name min -o /var/folders/xl/gkpskbyn18zb3d024fs0t88m0000gn/T/min-9db877.o 
1.  While walking into decl 'f(a:)' at min.swift:3:1
2.  While walking into body of 'f(a:)' at min.swift:3:1

I suspect we're failing to emit a diagnostic.

@slavapestov
Copy link
Member

Yeah, we're going into ConstraintSystem::salvage(), and then CSDiag doesn't diagnose anything. It's a bug in CSDiag, not in the solver, I think @rudkx.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants