llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

[19.1.0] clangd crashes while running boost-use-ranges clang-tidy check #109367

Closed xb284524239 closed 1 month ago

xb284524239 commented 1 month ago
My Environment:

OS: Windows 10
LLVM Version: 19.1.0 (include clangd、clang-tidy、clang++, etc.)
CMake Version: 3.30.3 
IDE: VSCode

Problem Description: I have found after multiple attempts that when I configure the .clang-tidy file in the root directory of my project, the Clang Language Server frequently crashes to the point of being completely unusable. However, when I delete the .clang-tidy file, everything returns to normal.

The .clang-tidy file:

Checks: "
        *,
        -llvmlibc-*,
        -fuchsia-*,
"

bbb

20240920111639

EugeneZelenko commented 1 month ago

@xb284524239: Could you please try to run Clang-tidy standalone? Just to narrow down source of problem.

xb284524239 commented 1 month ago

@xb284524239: Could you please try to run Clang-tidy standalone? Just to narrow down source of problem.

PS C:\Users\paul> clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 19.1.0
  Optimized build.
PS C:\Users\paul>

@EugeneZelenko Hello, I usually use it via VSCode. Could you please tell me how to use Clang-tidy standalone?

EugeneZelenko commented 1 month ago

See https://clang.llvm.org/extra/clang-tidy/. There is also run-clang-tidy script to run on compile database (could be generated by CMake).

EugeneZelenko commented 1 month ago

run-clang-tidy deals with compile database.

xb284524239 commented 1 month ago

I would like to add that a few days ago, when I was using version 18.1.8 of LLVM, the Clang Language Server did not crash. The frequent crashes only started after I upgraded LLVM to version 19.1.0. Perhaps this information could be helpful in troubleshooting the problem.

run-clang-tidy:

PS C:\Workspace\VSCode_Workspace\Test004> python "C:\Program Files\LLVM\bin\run-clang-tidy" -p "./build"
Enabled checks:
    abseil-cleanup-ctad
    abseil-duration-addition
    abseil-duration-comparison
    abseil-duration-conversion-cast
    abseil-duration-division
    abseil-duration-factory-float
    abseil-duration-factory-scale
    abseil-duration-subtraction
    abseil-duration-unnecessary-conversion
    abseil-faster-strsplit-delimiter
    abseil-no-internal-dependencies
    abseil-no-namespace
    abseil-redundant-strcat-calls
    abseil-str-cat-append
    abseil-string-find-startswith
    abseil-string-find-str-contains
    abseil-time-comparison
    abseil-time-subtraction
    abseil-upgrade-duration-conversions
    altera-id-dependent-backward-branch
    altera-kernel-name-restriction
    altera-single-work-item-barrier
    altera-struct-pack-align
    altera-unroll-loops
    android-cloexec-accept
    android-cloexec-accept4
    android-cloexec-creat
    android-cloexec-dup
    android-cloexec-epoll-create
    android-cloexec-epoll-create1
    android-cloexec-fopen
    android-cloexec-inotify-init
    android-cloexec-inotify-init1
    android-cloexec-memfd-create
    android-cloexec-open
    android-cloexec-pipe
    android-cloexec-pipe2
    android-cloexec-socket
    android-comparison-in-temp-failure-retry
    boost-use-ranges
    boost-use-to-string
    bugprone-argument-comment
    bugprone-assert-side-effect
    bugprone-assignment-in-if-condition
    bugprone-bad-signal-to-kill-thread
    bugprone-bool-pointer-implicit-conversion
    bugprone-branch-clone
    bugprone-casting-through-void
    bugprone-chained-comparison
    bugprone-compare-pointer-to-member-virtual-function
    bugprone-copy-constructor-init
    bugprone-crtp-constructor-accessibility
    bugprone-dangling-handle
    bugprone-dynamic-static-initializers
    bugprone-easily-swappable-parameters
    bugprone-empty-catch
    bugprone-exception-escape
    bugprone-fold-init-type
    bugprone-forward-declaration-namespace
    bugprone-forwarding-reference-overload
    bugprone-implicit-widening-of-multiplication-result
    bugprone-inaccurate-erase
    bugprone-inc-dec-in-conditions
    bugprone-incorrect-enable-if
    bugprone-incorrect-roundings
    bugprone-infinite-loop
    bugprone-integer-division
    bugprone-lambda-function-name
    bugprone-macro-parentheses
    bugprone-macro-repeated-side-effects
    bugprone-misplaced-operator-in-strlen-in-alloc
    bugprone-misplaced-pointer-arithmetic-in-alloc
    bugprone-misplaced-widening-cast
    bugprone-move-forwarding-reference
    bugprone-multi-level-implicit-pointer-conversion
    bugprone-multiple-new-in-one-expression
    bugprone-multiple-statement-macro
    bugprone-narrowing-conversions
    bugprone-no-escape
    bugprone-non-zero-enum-to-bool-conversion
    bugprone-not-null-terminated-result
    bugprone-optional-value-conversion
    bugprone-parent-virtual-call
    bugprone-pointer-arithmetic-on-polymorphic-object
    bugprone-posix-return
    bugprone-redundant-branch-condition
    bugprone-reserved-identifier
    bugprone-return-const-ref-from-parameter
    bugprone-shared-ptr-array-mismatch
    bugprone-signal-handler
    bugprone-signed-char-misuse
    bugprone-sizeof-container
    bugprone-sizeof-expression
    bugprone-spuriously-wake-up-functions
    bugprone-standalone-empty
    bugprone-string-constructor
    bugprone-string-integer-assignment
    bugprone-string-literal-with-embedded-nul
    bugprone-stringview-nullptr
    bugprone-suspicious-enum-usage
    bugprone-suspicious-include
    bugprone-suspicious-memory-comparison
    bugprone-suspicious-memset-usage
    bugprone-suspicious-missing-comma
    bugprone-suspicious-realloc-usage
    bugprone-suspicious-semicolon
    bugprone-suspicious-string-compare
    bugprone-suspicious-stringview-data-usage
    bugprone-swapped-arguments
    bugprone-switch-missing-default-case
    bugprone-terminating-continue
    bugprone-throw-keyword-missing
    bugprone-too-small-loop-variable
    bugprone-unchecked-optional-access
    bugprone-undefined-memory-manipulation
    bugprone-undelegated-constructor
    bugprone-unhandled-exception-at-new
    bugprone-unhandled-self-assignment
    bugprone-unique-ptr-array-mismatch
    bugprone-unsafe-functions
    bugprone-unused-local-non-trivial-variable
    bugprone-unused-raii
    bugprone-unused-return-value
    bugprone-use-after-move
    bugprone-virtual-near-miss
    cert-con36-c
    cert-con54-cpp
    cert-ctr56-cpp
    cert-dcl03-c
    cert-dcl16-c
    cert-dcl37-c
    cert-dcl50-cpp
    cert-dcl51-cpp
    cert-dcl54-cpp
    cert-dcl58-cpp
    cert-dcl59-cpp
    cert-env33-c
    cert-err09-cpp
    cert-err33-c
    cert-err34-c
    cert-err52-cpp
    cert-err58-cpp
    cert-err60-cpp
    cert-err61-cpp
    cert-exp42-c
    cert-fio38-c
    cert-flp30-c
    cert-flp37-c
    cert-int09-c
    cert-mem57-cpp
    cert-msc24-c
    cert-msc30-c
    cert-msc32-c
    cert-msc33-c
    cert-msc50-cpp
    cert-msc51-cpp
    cert-msc54-cpp
    cert-oop11-cpp
    cert-oop54-cpp
    cert-oop57-cpp
    cert-oop58-cpp
    cert-pos44-c
    cert-pos47-c
    cert-sig30-c
    cert-str34-c
    clang-analyzer-apiModeling.Errno
    clang-analyzer-apiModeling.TrustNonnull
    clang-analyzer-apiModeling.TrustReturnsNonnull
    clang-analyzer-apiModeling.google.GTest
    clang-analyzer-apiModeling.llvm.CastValue
    clang-analyzer-apiModeling.llvm.ReturnValue
    clang-analyzer-core.BitwiseShift
    clang-analyzer-core.CallAndMessage
    clang-analyzer-core.CallAndMessageModeling
    clang-analyzer-core.DivideZero
    clang-analyzer-core.DynamicTypePropagation
    clang-analyzer-core.NonNullParamChecker
    clang-analyzer-core.NonnilStringConstants
    clang-analyzer-core.NullDereference
    clang-analyzer-core.StackAddrEscapeBase
    clang-analyzer-core.StackAddressEscape
    clang-analyzer-core.UndefinedBinaryOperatorResult
    clang-analyzer-core.VLASize
    clang-analyzer-core.builtin.BuiltinFunctions
    clang-analyzer-core.builtin.NoReturnFunctions
    clang-analyzer-core.uninitialized.ArraySubscript
    clang-analyzer-core.uninitialized.Assign
    clang-analyzer-core.uninitialized.Branch
    clang-analyzer-core.uninitialized.CapturedBlockVariable
    clang-analyzer-core.uninitialized.NewArraySize
    clang-analyzer-core.uninitialized.UndefReturn
    clang-analyzer-cplusplus.ArrayDelete
    clang-analyzer-cplusplus.InnerPointer
    clang-analyzer-cplusplus.Move
    clang-analyzer-cplusplus.NewDelete
    clang-analyzer-cplusplus.NewDeleteLeaks
    clang-analyzer-cplusplus.PlacementNew
    clang-analyzer-cplusplus.PureVirtualCall
    clang-analyzer-cplusplus.SelfAssignment
    clang-analyzer-cplusplus.SmartPtrModeling
    clang-analyzer-cplusplus.StringChecker
    clang-analyzer-cplusplus.VirtualCallModeling
    clang-analyzer-deadcode.DeadStores
    clang-analyzer-fuchsia.HandleChecker
    clang-analyzer-nullability.NullPassedToNonnull
    clang-analyzer-nullability.NullReturnedFromNonnull
    clang-analyzer-nullability.NullabilityBase
    clang-analyzer-nullability.NullableDereferenced
    clang-analyzer-nullability.NullablePassedToNonnull
    clang-analyzer-nullability.NullableReturnedFromNonnull
    clang-analyzer-optin.core.EnumCastOutOfRange
    clang-analyzer-optin.cplusplus.UninitializedObject
    clang-analyzer-optin.cplusplus.VirtualCall
    clang-analyzer-optin.mpi.MPI-Checker
    clang-analyzer-optin.osx.OSObjectCStyleCast
    clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
    clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker
    clang-analyzer-optin.performance.GCDAntipattern
    clang-analyzer-optin.performance.Padding
    clang-analyzer-optin.portability.UnixAPI
    clang-analyzer-optin.taint.TaintedAlloc
    clang-analyzer-osx.API
    clang-analyzer-osx.MIG
    clang-analyzer-osx.NSOrCFErrorDerefChecker
    clang-analyzer-osx.NumberObjectConversion
    clang-analyzer-osx.OSObjectRetainCount
    clang-analyzer-osx.ObjCProperty
    clang-analyzer-osx.SecKeychainAPI
    clang-analyzer-osx.cocoa.AtSync
    clang-analyzer-osx.cocoa.AutoreleaseWrite
    clang-analyzer-osx.cocoa.ClassRelease
    clang-analyzer-osx.cocoa.Dealloc
    clang-analyzer-osx.cocoa.IncompatibleMethodTypes
    clang-analyzer-osx.cocoa.Loops
    clang-analyzer-osx.cocoa.MissingSuperCall
    clang-analyzer-osx.cocoa.NSAutoreleasePool
    clang-analyzer-osx.cocoa.NSError
    clang-analyzer-osx.cocoa.NilArg
    clang-analyzer-osx.cocoa.NonNilReturnValue
    clang-analyzer-osx.cocoa.ObjCGenerics
    clang-analyzer-osx.cocoa.RetainCount
    clang-analyzer-osx.cocoa.RetainCountBase
    clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak
    clang-analyzer-osx.cocoa.SelfInit
    clang-analyzer-osx.cocoa.SuperDealloc
    clang-analyzer-osx.cocoa.UnusedIvars
    clang-analyzer-osx.cocoa.VariadicMethodTypes
    clang-analyzer-osx.coreFoundation.CFError
    clang-analyzer-osx.coreFoundation.CFNumber
    clang-analyzer-osx.coreFoundation.CFRetainRelease
    clang-analyzer-osx.coreFoundation.containers.OutOfBounds
    clang-analyzer-osx.coreFoundation.containers.PointerSizedValues
    clang-analyzer-security.FloatLoopCounter
    clang-analyzer-security.PutenvStackArray
    clang-analyzer-security.SetgidSetuidOrder
    clang-analyzer-security.cert.env.InvalidPtr
    clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
    clang-analyzer-security.insecureAPI.SecuritySyntaxChecker
    clang-analyzer-security.insecureAPI.UncheckedReturn
    clang-analyzer-security.insecureAPI.bcmp
    clang-analyzer-security.insecureAPI.bcopy
    clang-analyzer-security.insecureAPI.bzero
    clang-analyzer-security.insecureAPI.decodeValueOfObjCType
    clang-analyzer-security.insecureAPI.getpw
    clang-analyzer-security.insecureAPI.gets
    clang-analyzer-security.insecureAPI.mkstemp
    clang-analyzer-security.insecureAPI.mktemp
    clang-analyzer-security.insecureAPI.rand
    clang-analyzer-security.insecureAPI.strcpy
    clang-analyzer-security.insecureAPI.vfork
    clang-analyzer-unix.API
    clang-analyzer-unix.BlockInCriticalSection
    clang-analyzer-unix.DynamicMemoryModeling
    clang-analyzer-unix.Errno
    clang-analyzer-unix.Malloc
    clang-analyzer-unix.MallocSizeof
    clang-analyzer-unix.MismatchedDeallocator
    clang-analyzer-unix.StdCLibraryFunctions
    clang-analyzer-unix.Stream
    clang-analyzer-unix.Vfork
    clang-analyzer-unix.cstring.BadSizeArg
    clang-analyzer-unix.cstring.CStringModeling
    clang-analyzer-unix.cstring.NullArg
    clang-analyzer-valist.CopyToSelf
    clang-analyzer-valist.Uninitialized
    clang-analyzer-valist.Unterminated
    clang-analyzer-valist.ValistBase
    clang-analyzer-webkit.NoUncountedMemberChecker
    clang-analyzer-webkit.RefCntblBaseVirtualDtor
    clang-analyzer-webkit.UncountedLambdaCapturesChecker
    concurrency-mt-unsafe
    concurrency-thread-canceltype-asynchronous
    cppcoreguidelines-avoid-c-arrays
    cppcoreguidelines-avoid-capturing-lambda-coroutines
    cppcoreguidelines-avoid-const-or-ref-data-members
    cppcoreguidelines-avoid-do-while
    cppcoreguidelines-avoid-goto
    cppcoreguidelines-avoid-magic-numbers
    cppcoreguidelines-avoid-non-const-global-variables
    cppcoreguidelines-avoid-reference-coroutine-parameters
    cppcoreguidelines-c-copy-assignment-signature
    cppcoreguidelines-explicit-virtual-functions
    cppcoreguidelines-init-variables
    cppcoreguidelines-interfaces-global-init
    cppcoreguidelines-macro-to-enum
    cppcoreguidelines-macro-usage
    cppcoreguidelines-misleading-capture-default-by-value
    cppcoreguidelines-missing-std-forward
    cppcoreguidelines-narrowing-conversions
    cppcoreguidelines-no-malloc
    cppcoreguidelines-no-suspend-with-lock
    cppcoreguidelines-noexcept-destructor
    cppcoreguidelines-noexcept-move-operations
    cppcoreguidelines-noexcept-swap
    cppcoreguidelines-non-private-member-variables-in-classes
    cppcoreguidelines-owning-memory
    cppcoreguidelines-prefer-member-initializer
    cppcoreguidelines-pro-bounds-array-to-pointer-decay
    cppcoreguidelines-pro-bounds-constant-array-index
    cppcoreguidelines-pro-bounds-pointer-arithmetic
    cppcoreguidelines-pro-type-const-cast
    cppcoreguidelines-pro-type-cstyle-cast
    cppcoreguidelines-pro-type-member-init
    cppcoreguidelines-pro-type-reinterpret-cast
    cppcoreguidelines-pro-type-static-cast-downcast
    cppcoreguidelines-pro-type-union-access
    cppcoreguidelines-pro-type-vararg
    cppcoreguidelines-rvalue-reference-param-not-moved
    cppcoreguidelines-slicing
    cppcoreguidelines-special-member-functions
    cppcoreguidelines-use-default-member-init
    cppcoreguidelines-virtual-class-destructor
    darwin-avoid-spinlock
    darwin-dispatch-once-nonstatic
    google-build-explicit-make-pair
    google-build-namespaces
    google-build-using-namespace
    google-default-arguments
    google-explicit-constructor
    google-global-names-in-headers
    google-objc-avoid-nsobject-new
    google-objc-avoid-throwing-exception
    google-objc-function-naming
    google-objc-global-variable-declaration
    google-readability-avoid-underscore-in-googletest-name
    google-readability-braces-around-statements
    google-readability-casting
    google-readability-function-size
    google-readability-namespace-comments
    google-readability-todo
    google-runtime-int
    google-runtime-operator
    google-upgrade-googletest-case
    hicpp-avoid-c-arrays
    hicpp-avoid-goto
    hicpp-braces-around-statements
    hicpp-deprecated-headers
    hicpp-exception-baseclass
    hicpp-explicit-conversions
    hicpp-function-size
    hicpp-ignored-remove-result
    hicpp-invalid-access-moved
    hicpp-member-init
    hicpp-move-const-arg
    hicpp-multiway-paths-covered
    hicpp-named-parameter
    hicpp-new-delete-operators
    hicpp-no-array-decay
    hicpp-no-assembler
    hicpp-no-malloc
    hicpp-noexcept-move
    hicpp-signed-bitwise
    hicpp-special-member-functions
    hicpp-static-assert
    hicpp-undelegated-constructor
    hicpp-uppercase-literal-suffix
    hicpp-use-auto
    hicpp-use-emplace
    hicpp-use-equals-default
    hicpp-use-equals-delete
    hicpp-use-noexcept
    hicpp-use-nullptr
    hicpp-use-override
    hicpp-vararg
    linuxkernel-must-check-errs
    llvm-else-after-return
    llvm-header-guard
    llvm-include-order
    llvm-namespace-comment
    llvm-prefer-isa-or-dyn-cast-in-conditionals
    llvm-prefer-register-over-unsigned
    llvm-qualified-auto
    llvm-twine-local
    misc-confusable-identifiers
    misc-const-correctness
    misc-coroutine-hostile-raii
    misc-definitions-in-headers
    misc-header-include-cycle
    misc-include-cleaner
    misc-misleading-bidirectional
    misc-misleading-identifier
    misc-misplaced-const
    misc-new-delete-overloads
    misc-no-recursion
    misc-non-copyable-objects
    misc-non-private-member-variables-in-classes
    misc-redundant-expression
    misc-static-assert
    misc-throw-by-value-catch-by-reference
    misc-unconventional-assign-operator
    misc-uniqueptr-reset-release
    misc-unused-alias-decls
    misc-unused-parameters
    misc-unused-using-decls
    misc-use-anonymous-namespace
    misc-use-internal-linkage
    modernize-avoid-bind
    modernize-avoid-c-arrays
    modernize-concat-nested-namespaces
    modernize-deprecated-headers
    modernize-deprecated-ios-base-aliases
    modernize-loop-convert
    modernize-macro-to-enum
    modernize-make-shared
    modernize-make-unique
    modernize-min-max-use-initializer-list
    modernize-pass-by-value
    modernize-raw-string-literal
    modernize-redundant-void-arg
    modernize-replace-auto-ptr
    modernize-replace-disallow-copy-and-assign-macro
    modernize-replace-random-shuffle
    modernize-return-braced-init-list
    modernize-shrink-to-fit
    modernize-type-traits
    modernize-unary-static-assert
    modernize-use-auto
    modernize-use-bool-literals
    modernize-use-constraints
    modernize-use-default-member-init
    modernize-use-designated-initializers
    modernize-use-emplace
    modernize-use-equals-default
    modernize-use-equals-delete
    modernize-use-nodiscard
    modernize-use-noexcept
    modernize-use-nullptr
    modernize-use-override
    modernize-use-ranges
    modernize-use-starts-ends-with
    modernize-use-std-format
    modernize-use-std-numbers
    modernize-use-std-print
    modernize-use-trailing-return-type
    modernize-use-transparent-functors
    modernize-use-uncaught-exceptions
    modernize-use-using
    mpi-buffer-deref
    mpi-type-mismatch
    objc-assert-equals
    objc-avoid-nserror-init
    objc-dealloc-in-category
    objc-forbidden-subclassing
    objc-missing-hash
    objc-nsdate-formatter
    objc-nsinvocation-argument-lifetime
    objc-property-declaration
    objc-super-self
    openmp-exception-escape
    openmp-use-default-none
    performance-avoid-endl
    performance-enum-size
    performance-faster-string-find
    performance-for-range-copy
    performance-implicit-conversion-in-loop
    performance-inefficient-algorithm
    performance-inefficient-string-concatenation
    performance-inefficient-vector-operation
    performance-move-const-arg
    performance-move-constructor-init
    performance-no-automatic-move
    performance-no-int-to-ptr
    performance-noexcept-destructor
    performance-noexcept-move-constructor
    performance-noexcept-swap
    performance-trivially-destructible
    performance-type-promotion-in-math-fn
    performance-unnecessary-copy-initialization
    performance-unnecessary-value-param
    portability-restrict-system-includes
    portability-simd-intrinsics
    portability-std-allocator-const
    readability-avoid-const-params-in-decls
    readability-avoid-nested-conditional-operator
    readability-avoid-return-with-void-value
    readability-avoid-unconditional-preprocessor-if
    readability-braces-around-statements
    readability-const-return-type
    readability-container-contains
    readability-container-data-pointer
    readability-container-size-empty
    readability-convert-member-functions-to-static
    readability-delete-null-pointer
    readability-duplicate-include
    readability-else-after-return
    readability-enum-initial-value
    readability-function-cognitive-complexity
    readability-function-size
    readability-identifier-length
    readability-identifier-naming
    readability-implicit-bool-conversion
    readability-inconsistent-declaration-parameter-name
    readability-isolate-declaration
    readability-magic-numbers
    readability-make-member-function-const
    readability-math-missing-parentheses
    readability-misleading-indentation
    readability-misplaced-array-index
    readability-named-parameter
    readability-non-const-parameter
    readability-operators-representation
    readability-qualified-auto
    readability-redundant-access-specifiers
    readability-redundant-casting
    readability-redundant-control-flow
    readability-redundant-declaration
    readability-redundant-function-ptr-dereference
    readability-redundant-inline-specifier
    readability-redundant-member-init
    readability-redundant-preprocessor
    readability-redundant-smartptr-get
    readability-redundant-string-cstr
    readability-redundant-string-init
    readability-reference-to-constructed-temporary
    readability-simplify-boolean-expr
    readability-simplify-subscript-expr
    readability-static-accessed-through-instance
    readability-static-definition-in-anonymous-namespace
    readability-string-compare
    readability-suspicious-call-argument
    readability-uniqueptr-delete-release
    readability-uppercase-literal-suffix
    readability-use-anyofallof
    readability-use-std-min-max
    zircon-temporary-objects

Running clang-tidy for 2 files out of 2 in compilation database ...
[1/2][0.1s] C:\Program Files\LLVM\bin\clang-tidy.EXE -p=./build C:\Workspace\VSCode_Workspace\Test004\main.cpp
C:\Workspace\VSCode_Workspace\Test004\main.cpp:23:5: warning: use a trailing return type for this function [modernize-use-trailing-return-type]
   23 | int main(int argc, char** argv) {
      | ~~~ ^
      | auto                            -> int
C:\Workspace\VSCode_Workspace\Test004\main.cpp:23:14: warning: parameter 'argc' is unused [misc-unused-parameters]
   23 | int main(int argc, char** argv) {
      |              ^~~~
      |               /*argc*/
C:\Workspace\VSCode_Workspace\Test004\main.cpp:23:27: warning: parameter 'argv' is unused [misc-unused-parameters]
   23 | int main(int argc, char** argv) {
      |                           ^~~~
      |                            /*argv*/
4 warnings generated.
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

[2/2][18.4s] C:\Program Files\LLVM\bin\clang-tidy.EXE -p=./build C:\Workspace\VSCode_Workspace\Test004\test.cpp
93662 warnings generated.
Suppressed 93662 warnings (93662 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

PS C:\Workspace\VSCode_Workspace\Test004>
xb284524239 commented 1 month ago

@EugeneZelenko Hello Sir,

After multiple tests, I have finally identified the cause of the Clang Language Server crashes. The specific reasons are as follows:

  1. The following .clang-tidy configuration file causes the Clang Language Server to crash:
Checks: "
        *
"
  1. The following .clang-tidy configuration file does not cause the Clang Language Server to crash:
    Checks: "
        *,
        -boost-use-ranges
    "

The only difference between the two configuration files is that the second one includes an additional -boost-use-ranges configuration. Therefore, I suspect that there is a bug in clang-tidy.exe when handling the boost-use-ranges check, which leads to the Clang Language Server crashing.

By the way, my project is a very simple Hello-World-level demo and does not use the Boost library. If needed, I can send you my demo code (for testing purposes).

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-tidy

Author: Paul Xu (xb284524239)

``` My Environment: OS: Windows 10 LLVM Version: 19.1.0 (include clangd、clang-tidy、clang++, etc.) CMake Version: 3.30.3 IDE: VSCode ``` Problem Description: I have found after multiple attempts that when I configure the `.clang-tidy` file in the root directory of my project, the Clang Language Server frequently crashes to the point of being completely unusable. However, when I delete the `.clang-tidy` file, everything returns to normal. The `.clang-tidy` file: ``` Checks: " *, -llvmlibc-*, -fuchsia-*, " ``` ![bbb](https://github.com/user-attachments/assets/640c6803-42aa-47d0-9784-41d51323a181) ![20240920111639](https://github.com/user-attachments/assets/07cd7050-0e65-4f7f-87dc-7714818e46e5)
EugeneZelenko commented 1 month ago

@xb284524239: Please provide reproducer. https://godbolt.org should be helpful.

xb284524239 commented 1 month ago

@EugeneZelenko

Hello, here is my demo code, and I have recorded a video to reproduce the issue. In my video, there is only one check item in the .clang-tidy file: boost-use-ranges. If I delete this check item or modify it to -boost-use-ranges, then the Clang Language Server will not crash.

# CMakeLists.txt

cmake_minimum_required(VERSION 3.30)
project(Test006 VERSION 0.1.0 LANGUAGES C CXX)
add_executable(Test006 main.cpp test.cpp)
// main.cpp

#include "test.h"
int main(int, char **) { test(); }
// test.h

#pragma once
void test();
// test.cpp

#include "test.h"
#include <iostream>
void test() {
  std::cout << "Hello, I'm only use for testing clang-tidy!" << std::endl;
}
// .clang-tidy

Checks: "boost-use-ranges"

https://github.com/user-attachments/assets/8d2afcb4-fab5-468c-b126-b18d36fbf154

HighCommander4 commented 1 month ago

Thank you @xb284524239 for the reduced code example. I can reproduce the crash using this example.

The crash occurs when opening test.cpp, but interestingly, it seems to only happen if test.h has been opened previously.

I have not been able to reproduce the crash with clangd --check=test.cpp, or with clang-tidy on the command line, which suggests that even though the crash is in a clang-tidy checker, it may only occur when the checker is run via clangd.

llvmbot commented 1 month ago

@llvm/issue-subscribers-clangd

Author: Paul Xu (xb284524239)

``` My Environment: OS: Windows 10 LLVM Version: 19.1.0 (include clangd、clang-tidy、clang++, etc.) CMake Version: 3.30.3 IDE: VSCode ``` Problem Description: I have found after multiple attempts that when I configure the `.clang-tidy` file in the root directory of my project, the Clang Language Server frequently crashes to the point of being completely unusable. However, when I delete the `.clang-tidy` file, everything returns to normal. The `.clang-tidy` file: ``` Checks: " *, -llvmlibc-*, -fuchsia-*, " ``` ![bbb](https://github.com/user-attachments/assets/640c6803-42aa-47d0-9784-41d51323a181) ![20240920111639](https://github.com/user-attachments/assets/07cd7050-0e65-4f7f-87dc-7714818e46e5)
HighCommander4 commented 1 month ago

The reason for the crash is that UseRangesCheck::getReplacerMap() is capturing the local variable Results in the static lambda AddFrom. Since the lambda is static, when the function is called a second time, the lambda still references and uses the Result variable from the first invocation, which has been destroyed by that point. (Credit to @hia3 for spotting this here.)

To trigger the crash, it's sufficient to just open any two files in clangd with this checker enabled, even if the contents are empty, since each time a file is opened clangd will call into this function when registering the matchers for the checker.

The function does get called once for each source file with clang-tidy as well (e.g. with clang-tidy source1.cpp source2.cpp it will get called twice), but since the calls occur in sequence on the same thread, in my local testing the crash is avoided because the local variable has the same address each time. (It's still undefined behaviour, of course.) Clangd on the other hand will handle each file on its own thread, and thus with local variables stored in a different region on the stack, and the crash occurs fairly readily.

HighCommander4 commented 1 month ago

Proposed fix: https://github.com/llvm/llvm-project/pull/111282

xb284524239 commented 4 weeks ago

The reason for the crash is that UseRangesCheck::getReplacerMap() is capturing the local variable Results in the static lambda AddFrom. Since the lambda is static, when the function is called a second time, the lambda still references and uses the Result variable from the first invocation, which has been destroyed by that point. (Credit to @hia3 for spotting this here.)

To trigger the crash, it's sufficient to just open any two files in clangd with this checker enabled, even if the contents are empty, since each time a file is opened clangd will call into this function when registering the matchers for the checker.

The function does get called once for each source file with clang-tidy as well (e.g. with clang-tidy source1.cpp source2.cpp it will get called twice), but since the calls occur in sequence on the same thread, in my local testing the crash is avoided because the local variable has the same address each time. (It's still undefined behaviour, of course.) Clangd on the other hand will handle each file on its own thread, and thus with local variables stored in a different region on the stack, and the crash occurs fairly readily.

@HighCommander4 Thank you for telling me the reason.