llvm / llvm-project

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

clang-tidy crash in ASTMatcher: Matching cppcoreguidelines-missing-std-forward #89518

Open jackua22 opened 6 months ago

jackua22 commented 6 months ago

clang-tidy llvm-v18.1.4 crashes with an attached stack. It is a very popular crash; about 50 files failed with the same stack, and the priority of the issue is high. ua_Debug_corun_src_coInit.C.log

There is a second, similar crash, it can be useful. ua_Platinum_CompilerRT_src_smdbUtil.h.log

EugeneZelenko commented 6 months ago

@jackua22: Could you please provide reproducer?

jackua22 commented 6 months ago

I cut the test to 30 lines. Having problems attaching tgz, not supported type. Inserting code here. === t1.cpp ===


#include <utility>

using node_index_t = int;

class Node {
public:
    template<class T>
    bool isType() const;
};

class Tree
{
public:
    enum : node_index_t { invalid_id = -1 };

    const Node* getNode(node_index_t id) const noexcept;

    template<class...Ts>
    bool isType(node_index_t index) const { return getNode(index)->isType<Ts...>(); }

    template<class Predicate>
    node_index_t find_child_by_name(node_index_t parent, const char *name, Predicate&& predicate) const;

    template<class T1, class... Ts, class Predicate>
    node_index_t find_child_by_name(node_index_t parent, const char *name, Predicate&& predicate) const {
        return find_child_by_name(parent, name, [&](node_index_t id) {
            return isType<T1, Ts...>(id) && std::forward<Predicate>(predicate)(id);
        });
    }
};

=== runs.sh ===

#!/bin/bash -xe
/grid/common/test/llvm-v18.1.4d1rh74_lnx86/bin/clang++ -c -stdlib=libc++ --std=c++17 t1.cpp
/grid/common/test/llvm-v18.1.4d1rh74_lnx86/bin/clang-tidy '--checks=cppcoreguidelines-missing-std-forward' t1.cpp -- -std=c++17 -stdlib=libc++
EugeneZelenko commented 6 months ago

Seems to work in main: https://godbolt.org/z/soY5xMEM4

jackua22 commented 6 months ago

tidy crashes. clang++ there is to prove that the code is valid. Compilation is OK, but static analysis fails.

jackua22 commented 4 months ago

Is there any update on the clang-tidy crash?

PiotrZSL commented 3 months ago

Can't reproduce crash...

jackua22 commented 3 months ago

I ran the latest clang-tidy we have in-house, llvm-v18.1.6d1rh74_lnx86/bin/clang-tidy, and it crashed as before. Which exact version did you run, and how can we get this non-crashing version?