-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-15845] SourceKitService crashes when a documentation comment contains a tag #58119
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
Comments
Thanks for reporting this Andrés. Unfortunately, I can’t reproduce the issue. I tried the following $ brew install swiftlint
$ cat /tmp/e.swift
/// - Tag: sometag
func sayHi() {
print("hello world")
}
$ swiftlint /tmp/e.swift
Linting Swift files at paths /tmp/e.swift
Linting 'e.swift' (1/1)
/tmp/e.swift:4:1: warning: Trailing Newline Violation: Files should have a single trailing newline. (trailing_newline)
Done linting! Found 1 violation, 0 serious in 1 file Are you using other instructions to reproduce the issue? |
Hi @ahoppen, thanks for your answer. Yes. I am using swiftlint with the analysis rule unused_declaration. Running an analysis rule requires to have a compilation database of the file under analysis. In the issue realm/SwiftLint#3851 I link a sample project demonstrating the crash. I copy here the steps to reproduce:
|
Hi Andrés, I am still unable to reproduce the issue with the steps you provide. Here’s what I did: $ brew install bazelisk mint
$ git clone https://github.com/acecilia/swift-compilation-database
$ cd swift-compilation-database
$ make go_with_bazel_compilation_database
rm -rf SwiftCompilationDatabase.xcodeproj
rm -rf outputs
mkdir outputs
swift run --package-path CompilationDatabaseGenerator CompilationDatabaseGenerator bazel outputs/compile_commands.json
[9/9] Build complete!
Loading: 0 packages loaded
Loading: 1 packages loaded
Loading: 1 packages loaded
Loading:
Loading: 0 packages loaded
Analyzing: 3 targets (0 packages loaded, 0 targets configured)
Analyzing: 3 targets (2 packages loaded, 8 targets configured)
Analyzing: 3 targets (2 packages loaded, 8 targets configured)
INFO: Analyzed 3 targets (3 packages loaded, 117 targets configured).
INFO: Found 3 targets...
[0 / 9] [Prepa] BazelWorkspaceStatusAction stable-status.txt
INFO: Elapsed time: 15.153s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Loading:
Loading: 0 packages loaded
Analyzing: 3 targets (0 packages loaded, 0 targets configured)
INFO: Analyzed 3 targets (0 packages loaded, 0 targets configured).
INFO: Found 3 targets...
INFO: Elapsed time: 0.290s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
INFO: Build completed successfully, 0 total actions
Full command: /private/tmp/xxxs/swift-compilation-database/bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc -target x86_64-apple-macosx12.1 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -emit-object -output-file-map /private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin/ModuleB.output_file_map.json -Xfrontend -no-clang-module-breadcrumbs -emit-module-path /private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin/ModuleB.swiftmodule -DDEBUG -Onone -Xfrontend -serialize-debugging-options -enable-testing -gline-tables-only -I/private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin -Xcc -iquote. -Xcc -iquote/private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin -Xfrontend -color-diagnostics -enable-batch-mode -module-name ModuleB -parse-as-library -Xcc -O0 -Xcc -DDEBUG=1 /private/tmp/xxxs/swift-compilation-database/Sources/ModuleB/ModuleB.swift /private/tmp/xxxs/swift-compilation-database/Sources/ModuleB/Something+conformance.swift /private/tmp/xxxs/swift-compilation-database/Sources/ModuleB/SomethingProtocol.swift
Full command: /private/tmp/xxxs/swift-compilation-database/bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc -target x86_64-apple-macosx12.1 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -emit-object -output-file-map /private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin/TagCrashModule.output_file_map.json -Xfrontend -no-clang-module-breadcrumbs -emit-module-path /private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin/TagCrashModule.swiftmodule -DDEBUG -Onone -Xfrontend -serialize-debugging-options -enable-testing -gline-tables-only -Xcc -iquote. -Xcc -iquote/private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin -Xfrontend -color-diagnostics -enable-batch-mode -module-name TagCrashModule -parse-as-library -Xcc -O0 -Xcc -DDEBUG=1 /private/tmp/xxxs/swift-compilation-database/Sources/TagCrashModule/Crash.swift
Full command: /private/tmp/xxxs/swift-compilation-database/bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc -target x86_64-apple-macosx12.1 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -emit-object -output-file-map /private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin/ModuleA.output_file_map.json -Xfrontend -no-clang-module-breadcrumbs -emit-module-path /private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin/ModuleA.swiftmodule -DDEBUG -Onone -Xfrontend -serialize-debugging-options -enable-testing -gline-tables-only -Xcc -iquote. -Xcc -iquote/private/tmp/xxxs/swift-compilation-database/bazel-out/darwin-fastbuild/bin -Xfrontend -color-diagnostics -enable-batch-mode -module-name ModuleA -parse-as-library -Xcc -O0 -Xcc -DDEBUG=1 /private/tmp/xxxs/swift-compilation-database/Sources/ModuleA/ModuleA1.swift /private/tmp/xxxs/swift-compilation-database/Sources/ModuleA/ModuleA2.swift
mint run realm/SwiftLint@0.45.0 analyze --compile-commands outputs/compile_commands.json
Analyzing Swift files in current working directory
Done analyzing! Found 0 violations, 0 serious in 0 files. |
Mmm I am out of ideas then. Seems swiftlint cant find any swift files in your current directory: Done analyzing! Found 0 violations, 0 serious in 0 files. But really it should find 6 files. For me, I did the same steps as you, and this is my output: andres.luque@macintosh Developer % rm -rf swift-compilation-database
andres.luque@macintosh Developer % git clone git@github.com:acecilia/swift-compilation-database.git
Cloning into 'swift-compilation-database'...
remote: Enumerating objects: 97, done.
remote: Counting objects: 100% (97/97), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 97 (delta 33), reused 81 (delta 17), pack-reused 0
Receiving objects: 100% (97/97), 15.20 KiB | 3.80 MiB/s, done.
Resolving deltas: 100% (33/33), done.
andres.luque@macintosh Developer % cd swift-compilation-database
andres.luque@macintosh swift-compilation-database % make go_with_bazel_compilation_database
rm -rf SwiftCompilationDatabase.xcodeproj
rm -rf outputs
mkdir outputs
swift run --package-path CompilationDatabaseGenerator CompilationDatabaseGenerator bazel outputs/compile_commands.json
[9/9] Build complete!
Loading: 0 packages loaded
Loading: 1 packages loaded
Loading: 1 packages loaded
Loading:
Loading: 0 packages loaded
Analyzing: 3 targets (0 packages loaded, 0 targets configured)
Analyzing: 3 targets (2 packages loaded, 8 targets configured)
INFO: Analyzed 3 targets (3 packages loaded, 123 targets configured).
INFO: Found 3 targets...
[0 / 8] [Prepa] BazelWorkspaceStatusAction stable-status.txt
INFO: Elapsed time: 1.445s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Loading:
Loading: 0 packages loaded
Analyzing: 3 targets (0 packages loaded, 0 targets configured)
INFO: Analyzed 3 targets (0 packages loaded, 0 targets configured).
INFO: Found 3 targets...
INFO: Elapsed time: 0.131s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
INFO: Build completed successfully, 0 total actions
Full command: /Users/andres.luque/Developer/swift-compilation-database/bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc -target arm64-apple-macosx12.1 -sdk /Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -F/Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I/Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -emit-object -output-file-map /Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin/ModuleB.output_file_map.json -Xfrontend -no-clang-module-breadcrumbs -emit-module-path /Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin/ModuleB.swiftmodule -DDEBUG -Onone -Xfrontend -serialize-debugging-options -enable-testing -gline-tables-only -I/Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin -Xcc -iquote. -Xcc -iquote/Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin -Xfrontend -color-diagnostics -enable-batch-mode -module-name ModuleB -parse-as-library -Xcc -O0 -Xcc -DDEBUG=1 /Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleB/ModuleB.swift /Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleB/Something+conformance.swift /Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleB/SomethingProtocol.swift
Full command: /Users/andres.luque/Developer/swift-compilation-database/bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc -target arm64-apple-macosx12.1 -sdk /Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -F/Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I/Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -emit-object -output-file-map /Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin/TagCrashModule.output_file_map.json -Xfrontend -no-clang-module-breadcrumbs -emit-module-path /Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin/TagCrashModule.swiftmodule -DDEBUG -Onone -Xfrontend -serialize-debugging-options -enable-testing -gline-tables-only -Xcc -iquote. -Xcc -iquote/Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin -Xfrontend -color-diagnostics -enable-batch-mode -module-name TagCrashModule -parse-as-library -Xcc -O0 -Xcc -DDEBUG=1 /Users/andres.luque/Developer/swift-compilation-database/Sources/TagCrashModule/Crash.swift
Full command: /Users/andres.luque/Developer/swift-compilation-database/bazel-out/host/bin/external/build_bazel_rules_swift/tools/worker/worker swiftc -target arm64-apple-macosx12.1 -sdk /Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -F/Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I/Applications/Xcode-13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -emit-object -output-file-map /Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin/ModuleA.output_file_map.json -Xfrontend -no-clang-module-breadcrumbs -emit-module-path /Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin/ModuleA.swiftmodule -DDEBUG -Onone -Xfrontend -serialize-debugging-options -enable-testing -gline-tables-only -Xcc -iquote. -Xcc -iquote/Users/andres.luque/Developer/swift-compilation-database/bazel-out/darwin_arm64-fastbuild/bin -Xfrontend -color-diagnostics -enable-batch-mode -module-name ModuleA -parse-as-library -Xcc -O0 -Xcc -DDEBUG=1 /Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleA/ModuleA1.swift /Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleA/ModuleA2.swift
mint run realm/SwiftLint@0.45.0 analyze --compile-commands outputs/compile_commands.json
Analyzing Swift files in current working directory
Collecting 'ModuleB.swift' (1/6)
Collecting 'Something+conformance.swift' (2/6)
Collecting 'ModuleA1.swift' (3/6)
Collecting 'ModuleA2.swift' (4/6)
Collecting 'Crash.swift' (5/6)
Collecting 'SomethingProtocol.swift' (6/6)
sourcekit: [1:connection-event-handler:9219: 0.0000] Connection interruptsourcekit: [1:updateSemanticEditorDelay:9219: 0.0003] disabling semantic editor for 10 secondssourcekit: [1:pingService:9219: 0.0003] pinging servicesourcekitten: connection to SourceKitService restored!
Could not index file at path '/Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleB/SomethingProtocol.swift' with the unused_declaration rule.
sourcekit: [1:ping-event-handler:12035: 0.0120] service restoredsourcekitten: connection to SourceKitService restored!
Could not index file at path '/Users/andres.luque/Developer/swift-compilation-database/Sources/TagCrashModule/Crash.swift' with the unused_declaration rule.
Could not index file at path '/Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleA/ModuleA2.swift' with the unused_declaration rule.
Could not index file at path '/Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleB/ModuleB.swift' with the unused_declaration rule.
Could not index file at path '/Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleB/Something+conformance.swift' with the unused_declaration rule.
Could not index file at path '/Users/andres.luque/Developer/swift-compilation-database/Sources/ModuleA/ModuleA1.swift' with the unused_declaration rule.
Analyzing 'ModuleB.swift' (1/6)
Analyzing 'Something+conformance.swift' (2/6)
Analyzing 'ModuleA1.swift' (3/6)
Analyzing 'Crash.swift' (4/6)
Analyzing 'SomethingProtocol.swift' (5/6)
Analyzing 'ModuleA2.swift' (6/6)
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Could not get cursor info
Done analyzing! Found 0 violations, 0 serious in 6 files.
andres.luque@macintosh swift-compilation-database % I am running in 12.1 (21C52), Xcode 13.2.1, Apple M1 Pro |
I just run the same commands, getting the same results and showing the crash, in a different machine: MacOS 12.0.1 (21A559), Xcode 13.2.1, intel chip Sorry of not being of more help, I can not think of what the reason is for you not being able to reproduce it :/ |
Hmm, weird. Could you share the SourceKit crash report by opening Console -> Crash Reports and attaching any recent crashes of SourceKitService to this bug report? Maybe that will allow me to reproduce the issue without actually running SwiftLint. |
Sure! Attached crash report to this ticket, and also a demonstration video 🙂 |
Thanks, I was able to reproduce the crash. $ cat /tmp/e.swift
/// - Tag: sometag
func sayHi() {
print("hello world")
}
$ ./sourcekitd-test -req=index /tmp/e.swift -- /tmp/e.swift
{
key.request: source.request.indexsource,
key.compilerargs: [
"/tmp/e.swift"
],
key.sourcefile: "/tmp/e.swift"
}
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. While walking into decl 'sayHi()' (at /private/tmp/e.swift:2:1)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 sourcekitd-test 0x0000000109e3a9e7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 sourcekitd-test 0x0000000109e39c46 llvm::sys::RunSignalHandlers() + 198
2 sourcekitd-test 0x0000000109e3b020 SignalHandler(int) + 288
3 libsystem_platform.dylib 0x00007ff815792e2d _sigtramp + 29
4 libsystem_platform.dylib 0x0000000000000002 _sigtramp + 18446603370220671474
5 libsourcekitdInProc.dylib 0x000000011fc1a850 SKIndexDataConsumer::getDeclAttributeUIDs(swift::Decl const*) + 32
6 libsourcekitdInProc.dylib 0x000000011fc1a668 bool SKIndexDataConsumer::withEntityInfo<SKIndexDataConsumer::startSourceEntity(swift::index::IndexSymbol const&)::'lambda0'(SourceKit::EntityInfo const&)>(swift::index::IndexSymbol const&, SKIndexDataConsumer::startSourceEntity(swift::index::IndexSymbol const&)::'lambda0'(SourceKit::EntityInfo const&)) + 296
7 libsourcekitdInProc.dylib 0x000000011fc1a26b SKIndexDataConsumer::startSourceEntity(swift::index::IndexSymbol const&) + 107
8 libsourcekitdInProc.dylib 0x000000012109c346 (anonymous namespace)::IndexSwiftASTWalker::walkToDeclPre(swift::Decl*, swift::CharSourceRange) + 2022
9 libsourcekitdInProc.dylib 0x000000011fe25ab6 (anonymous namespace)::SemaAnnotator::walkToDeclPre(swift::Decl*) + 1494
10 libsourcekitdInProc.dylib 0x0000000121440dc0 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 48
11 libsourcekitdInProc.dylib 0x0000000121440d7b swift::Decl::walk(swift::ASTWalker&) + 27
12 libsourcekitdInProc.dylib 0x000000012163a146 swift::SourceFile::walk(swift::ASTWalker&) + 198
13 libsourcekitdInProc.dylib 0x000000011fe2397e swift::SourceEntityWalker::walk(swift::SourceFile&) + 270
14 libsourcekitdInProc.dylib 0x000000012109b8f9 (anonymous namespace)::IndexSwiftASTWalker::visitModule(swift::ModuleDecl&) + 217
15 libsourcekitdInProc.dylib 0x000000012109b7e5 swift::index::indexSourceFile(swift::SourceFile*, swift::index::IndexDataConsumer&) + 373
16 libsourcekitdInProc.dylib 0x000000011fc19c50 SourceKit::SwiftLangSupport::indexSource(llvm::StringRef, SourceKit::IndexingConsumer&, llvm::ArrayRef<char const*>) + 2544
17 libsourcekitdInProc.dylib 0x000000011fc8b167 handleSemanticRequest(sourcekitd::RequestDict, std::__1::function<void (void*)>, sourcekitd_uid_s*, llvm::Optional<llvm::StringRef>, llvm::Optional<llvm::StringRef>, llvm::ArrayRef<char const*>, llvm::Optional<SourceKit::VFSOptions>, void const*) + 5767
18 libsourcekitdInProc.dylib 0x000000011fc89a0b void SourceKit::WorkQueue::DispatchData::callAndDelete<handleRequestImpl(void*, void const*, std::__1::function<void (void*)>)::$_12>(void*) + 299
19 libdispatch.dylib 0x00007ff8155c6cc9 _dispatch_client_callout + 8
20 libdispatch.dylib 0x00007ff8155c9c96 _dispatch_block_invoke_direct + 241
21 libsourcekitdInProc.dylib 0x000000012135990f executeBlock(void*) + 15
22 libsourcekitdInProc.dylib 0x000000012135993f void* llvm::thread::ThreadProxy<std::__1::tuple<void (*)(void*), void*> >(void*) + 15
23 libsystem_pthread.dylib 0x00007ff81577d4f4 _pthread_start + 125
24 libsystem_pthread.dylib 0x00007ff81577900f thread_start + 15
fish: Job 1, './sourcekitd-test -req=index /t…' terminated by signal SIGSEGV (Address boundary error) |
Great to know ⭐ |
#41681 |
Attachment: Download
Environment
Xcode 13.2.1
Additional Detail from JIRA
md5: b1a93d21f8b441ee68b0cced66922382
Issue Description:
SourceKitService crashes when analysing swift code. It happens when a documentation comment contains a tag. It is reproducible 100% of the times. See this issue for details: realm/SwiftLint#3851
Steps to reproduce the issue:
I run swiftlint analyse rule unused_declaration in a swift file with the following content:
What did you expect to happen?
SourceKitService works correctly
What actually happened?
SourceKitService crashes with this error:
The text was updated successfully, but these errors were encountered: