swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-2497] isa<> used on a null pointer #45102

Open swift-ci opened 8 years ago

swift-ci commented 8 years ago
Previous ID SR-2497
Radar None
Original Reporter tannernelson (JIRA User)
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash | |Assignee | @slavapestov | |Priority | Medium | md5: c2ffc64b656a1ebb4e6e3632949e0c01

Issue Description:

Snapshot 08-18, 08-23, and 08-24 on macOS El Cap.

Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/llvm/include/llvm/Support/Casting.h, line 95.
0  swift                    0x000000010d03530b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010d034556 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010d035a5f SignalHandler(int) + 383
3  libsystem_platform.dylib 0x00007fff8b99552a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff67873ac5 _sigtramp + 3689801141
5  swift                    0x000000010d0357ae abort + 14
6  swift                    0x000000010d035791 __assert_rtn + 81
7  swift                    0x000000010abc8caa (anonymous namespace)::TypeAccessScopeChecker::walkToTypePre(swift::Type) + 570
8  swift                    0x000000010ad9e13b swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visit(swift::Type) + 619
9  swift                    0x000000010ad9ec89 swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visit(swift::Type) + 3513
10 swift                    0x000000010ad9de4d swift::Type::walk(swift::TypeWalker&) const + 61
11 swift                    0x000000010abc837d (anonymous namespace)::TypeAccessScopeChecker::getAccessScope(swift::Type, swift::DeclContext const*, llvm::DenseMap<swift::SourceFile const*, llvm::DenseMap<swift::Type, swift::DeclContext const*, llvm::DenseMapInfo<swift::Type>, llvm::detail::DenseMapPair<swift::Type, swift::DeclContext const*> >, llvm::DenseMapInfo<swift::SourceFile const*>, llvm::detail::DenseMapPair<swift::SourceFile const*, llvm::DenseMap<swift::Type, swift::DeclContext const*, llvm::DenseMapInfo<swift::Type>, llvm::detail::DenseMapPair<swift::Type, swift::DeclContext const*> > > >&) + 141
12 swift                    0x000000010abd884e std::__1::__function::__func<checkAccessibility(swift::TypeChecker&, swift::Decl const*)::$_14, std::__1::allocator<checkAccessibility(swift::TypeChecker&, swift::Decl const*)::$_14>, void (swift::Pattern*)>::operator()(swift::Pattern*&&) + 414
13 swift                    0x000000010ad7e252 swift::Pattern::forEachNode(std::__1::function<void (swift::Pattern*)> const&) + 34
14 swift                    0x000000010abd4b93 checkAccessibility(swift::TypeChecker&, swift::Decl const*) + 243
15 swift                    0x000000010abc237c (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 1468
16 swift                    0x000000010abc1dac swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 156
17 swift                    0x000000010ac2ad96 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 454
18 swift                    0x000000010ac2a7bc swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 140
19 swift                    0x000000010abe4f7c swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1420
20 swift                    0x000000010a881b10 swift::CompilerInstance::performSema() + 3664
21 swift                    0x000000010a376171 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3185
22 swift                    0x000000010a336320 main + 2544
23 libdyld.dylib            0x00007fff91d6b5ad start + 1
24 libdyld.dylib            0x0000000000000034 start + 1848199816
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/tanner/Developer/vapor/vapor/Sources/Development/main.swift /Users/tanner/Developer/vapor/vapor/Sources/Development/Controllers/UserController.swift /Users/tanner/Developer/vapor/vapor/Sources/Development/Middleware/AuthMiddleware.swift /Users/tanner/Developer/vapor/vapor/Sources/Development/Models/User.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Products/Debug -F /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Products/Debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -g -module-cache-path /Users/tanner/Library/Developer/Xcode/DerivedData/ModuleCache -D Xcode -serialize-debugging-options -Xcc -I/Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/swift-overrides.hmap -Xcc -I/Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Products/Debug/include -Xcc -I/Users/tanner/Developer/vapor/vapor/Packages/CLibreSSL-0.1.13/Sources/CLibreSSL/include -Xcc -I/Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/DerivedSources/x86_64 -Xcc -I/Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/DerivedSources -Xcc -working-directory/Users/tanner/Developer/vapor/vapor -emit-module-doc-path /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name Development -emit-module-path /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/Objects-normal/x86_64/main.swiftdeps -o /Users/tanner/Library/Developer/Xcode/DerivedData/Vapor-byhbiaosegxkobfmgevrluccndcc/Build/Intermediates/Vapor.build/Debug/Development.build/Objects-normal/x86_64/main.o 
1.  While type-checking declaration 0x7feaa50affa8 at /Users/tanner/Developer/vapor/vapor/Sources/Development/main.swift:93:1

When calling:

let secure = drop.grouped(ba, um)
secure.get("user") { req in
    return "hello"
}

extension RouteBuilder where Value == Responder {
    public func grouped(_ middleware: Middleware ...) -> RouteGroup<Value, Self> {
        return grouped(prefix: [nil, nil], path: [], map: { handler in
            return Request.Handler { request in
                return try middleware.chain(to: handler).respond(to: request)
            }
        })
    }
}

I believe it is conflicting with another protocol extension:

    public func grouped(_ path: String...) -> Routing.RouteGroup<Responder, Self>

Adding an external label to either fixes the issue for now.

belkadan commented 8 years ago

I think we're going to need the whole project to track this one down.

swift-ci commented 8 years ago

Comment by tanner0101 (JIRA)

I've confirmed this is still happening on 08-26.

https://github.com/vapor/vapor/files/440393/vapor.copy.zip

Here is the zipped project. I deleted the `Packages` and `.build` folder so the file size is smaller. Running `swift build` on anything higher than `08-18` on macOS El cap should reproduce the crash.

Here was my last test of compiling it:

swift build
....
...
...
Compile Swift Module 'Performance' (1 sources)
Compile Swift Module 'Development' (3 sources)
Linking ./.build/debug/Performance
Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/llvm/include/llvm/Support/Casting.h, line 95.
0  swift                    0x000000010d1b730b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010d1b6556 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010d1b7a5f SignalHandler(int) + 383
3  libsystem_platform.dylib 0x00007fff8b99552a _sigtramp + 26
4  swift                    0x000000010ddb1621 cmark_strbuf__initbuf + 74160
5  swift                    0x000000010d1b77ae abort + 14
6  swift                    0x000000010d1b7791 __assert_rtn + 81
7  swift                    0x000000010ad4acaa (anonymous namespace)::TypeAccessScopeChecker::walkToTypePre(swift::Type) + 570
8  swift                    0x000000010af2013b swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visit(swift::Type) + 619
9  swift                    0x000000010af20c89 swift::TypeVisitor<(anonymous namespace)::Traversal, bool>::visit(swift::Type) + 3513
10 swift                    0x000000010af1fe4d swift::Type::walk(swift::TypeWalker&) const + 61
11 swift                    0x000000010ad4a37d (anonymous namespace)::TypeAccessScopeChecker::getAccessScope(swift::Type, swift::DeclContext const*, llvm::DenseMap<swift::SourceFile const*, llvm::DenseMap<swift::Type, swift::DeclContext const*, llvm::DenseMapInfo<swift::Type>, llvm::detail::DenseMapPair<swift::Type, swift::DeclContext const*> >, llvm::DenseMapInfo<swift::SourceFile const*>, llvm::detail::DenseMapPair<swift::SourceFile const*, llvm::DenseMap<swift::Type, swift::DeclContext const*, llvm::DenseMapInfo<swift::Type>, llvm::detail::DenseMapPair<swift::Type, swift::DeclContext const*> > > >&) + 141
12 swift                    0x000000010ad5a84e std::__1::__function::__func<checkAccessibility(swift::TypeChecker&, swift::Decl const*)::$_14, std::__1::allocator<checkAccessibility(swift::TypeChecker&, swift::Decl const*)::$_14>, void (swift::Pattern*)>::operator()(swift::Pattern*&&) + 414
13 swift                    0x000000010af00252 swift::Pattern::forEachNode(std::__1::function<void (swift::Pattern*)> const&) + 34
14 swift                    0x000000010ad56b93 checkAccessibility(swift::TypeChecker&, swift::Decl const*) + 243
15 swift                    0x000000010ad4437c (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 1468
16 swift                    0x000000010ad43dac swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 156
17 swift                    0x000000010adacd96 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 454
18 swift                    0x000000010adac7bc swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 140
19 swift                    0x000000010ad66f7c swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1420
20 swift                    0x000000010aa03b10 swift::CompilerInstance::performSema() + 3664
21 swift                    0x000000010a4f8171 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3185
22 swift                    0x000000010a4b8320 main + 2544
23 libdyld.dylib            0x00007fff91d6b5ad start + 1
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/tanner/Developer/vapor/vapor/Sources/Development/main.swift /Users/tanner/Developer/vapor/vapor/Sources/Development/Controllers/UserController.swift /Users/tanner/Developer/vapor/vapor/Sources/Development/Models/User.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/tanner/Developer/vapor/vapor/.build/debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/tanner/Developer/vapor/vapor/.build/debug/ModuleCache -D SWIFT_PACKAGE -Xcc -fmodule-map-file=/Users/tanner/Developer/vapor/vapor/.build/debug/CLibreSSL.build/module.modulemap -emit-module-doc-path /Users/tanner/Developer/vapor/vapor/.build/debug/Development.build/main~partial.swiftdoc -Onone -module-name Development -emit-module-path /Users/tanner/Developer/vapor/vapor/.build/debug/Development.build/main~partial.swiftmodule -emit-dependencies-path /Users/tanner/Developer/vapor/vapor/.build/debug/Development.build/main.d -emit-reference-dependencies-path /Users/tanner/Developer/vapor/vapor/.build/debug/Development.build/main.swiftdeps -num-threads 8 -o /Users/tanner/Developer/vapor/vapor/.build/debug/Development.build/main.swift.o 
1.  While type-checking declaration 0x7fafdacdc968 at /Users/tanner/Developer/vapor/vapor/Sources/Development/main.swift:107:1
<unknown>:0: error: unable to execute command: Illegal instruction: 4
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-18-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tanner/Developer/vapor/vapor/.build/debug.yaml

The crash, like it says, is in Sources/Development/main.swift at line 107

There's a lot of cross-module protocols, extensions, and generics going on here so I'm not surprised to see it breaking.

Thanks for looking into this!

ffried commented 7 years ago

This seems like the same crash as in SR-4850. Are they related?

belkadan commented 7 years ago

No, isa is just a helper function. Think of this like a null pointer dereference.