realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.57k stars 2.21k forks source link

When scanning apple/swift, linting multiple files fails with a bus error #4829

Open mildm8nnered opened 1 year ago

mildm8nnered commented 1 year ago

New Issue Checklist

Describe the bug

brew install swiftlint
git clone https://github.com/apple/swift
cd swift
swiftlint validation-test/compiler_crashers_fixed/28616-swift-parser-parseexprsequence-swift-diag-bool-bool.swift
Linting Swift files at paths validation-test/compiler_crashers_fixed/28616-swift-parser-parseexprsequence-swift-diag-bool-bool.swift
Linting '28616-swift-parser-parseexprsequence-swift-diag-bool-bool.swift' (1/1)
zsh: bus error  swiftlint 

The following files are affected:

validation-test/compiler_crashers_fixed/28678-result-case-not-implemented.swift
validation-test/compiler_crashers_fixed/28616-swift-parser-parseexprsequence-swift-diag-bool-bool.swift
validation-test/compiler_crashers_2_fixed/parser-cutoff.swift
test/Parse/structure_no_overflow.swift
test/Parse/structure_overflow.swift
test/SourceKit/Misc/parser-cutoff.swift

This may be a problem with SourceKit/SourceKitten:

Screenshot 2023-03-19 at 12 55 32
Complete output when running SwiftLint, including the stack trace and command used

See above

Environment

none

Xcode 14.2
Build version 14C18

See above for sample files that cause the issue

mildm8nnered commented 1 year ago

Actually, digging a little deeper, I'm not seeing the same stack as above, but instead what looks like a stack overflow:

#0  0x0000000100693500 in Lexer.Cursor.StateStack.currentState.getter [inlined] at /Users/martin.redington/Library/Developer/Xcode/DerivedData/SwiftLint-gklsqxiezwwcpadjrqtcoqyssyxg/SourcePackages/checkouts/swift-syntax/Sources/SwiftParser/Lexer/Cursor.swift:156
#1  0x00000001006934e0 in Lexer.Cursor.currentState.getter [inlined] at /Users/martin.redington/Library/Developer/Xcode/DerivedData/SwiftLint-gklsqxiezwwcpadjrqtcoqyssyxg/SourcePackages/checkouts/swift-syntax/Sources/SwiftParser/Lexer/Cursor.swift:231
#2  0x00000001006934d0 in Lexer.Cursor.nextToken(sourceBufferStart:stateAllocator:) at /Users/martin.redington/Library/Developer/Xcode/DerivedData/SwiftLint-gklsqxiezwwcpadjrqtcoqyssyxg/SourcePackages/checkouts/swift-syntax/Sources/SwiftParser/Lexer/Cursor.swift:309
#3  0x0000000100648db4 in $defer #1 () in Lexer.LexemeSequence.advance() [inlined] at /Users/martin.redington/Library/Developer/Xcode/DerivedData/SwiftLint-gklsqxiezwwcpadjrqtcoqyssyxg/SourcePackages/checkouts/swift-syntax/Sources/SwiftParser/Lexer/LexemeSequence.swift:58
...
#1815   0x0000000100027ac0 in specialized closure #1 in Configuration.visit(linters:visitor:duplicateFileNames:) at /Users/martin.redington/Documents/Hudl/Source/SwiftLint/Source/swiftlint/Extensions/Configuration+CommandLine.swift:201
#1816   0x0000000100022b24 in closure #1 in Configuration.visit(linters:visitor:duplicateFileNames:) ()
#1817   0x00000001000272a0 in partial apply for closure #1 in Configuration.visit(linters:visitor:duplicateFileNames:) ()
...
#1822   0x0000000100b73e34 in thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out τ_0_0) ()
#1823   0x0000000100b73e18 in partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out τ_0_0) ()

But when I run the same code manually, in a unit test, it does not crash for me.

import SwiftParser
import SwiftSyntax

final class ParserTests: XCTestCase {
    public func testXXX(){
      let string = "// This source file is part of the Swift.org open source project\n// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors\n// Licensed under Apache License v2.0 with Runtime Library Exception\n//\n// See https://swift.org/LICENSE.txt for license information\n// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors\n\n// RUN: not %target-swift-frontend %s -emit-ir\n[{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{\n{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{func b(UInt=1 + 1 as?Int){{{{{ }struct c=1 + 1 + 1 as?Int){{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{\n[.==A{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{\n"

        _ = Parser.parse(source: string)
    }
}
SimplyDanny commented 1 year ago

You have to be careful. The Swift repository contains test cases that don't describe valid Swift code or are just very pathologic edge cases. SwiftLint doesn't guarantee anything if the code to be linted isn't valid. test/Parse/structure_overflow.swift is such an example.