llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

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

Open jackua22 opened this issue 2 years ago • 8 comments

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

jackua22 avatar Apr 20 '24 23:04 jackua22

@jackua22: Could you please provide reproducer?

EugeneZelenko avatar Apr 21 '24 01:04 EugeneZelenko

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++

jackua22 avatar Apr 21 '24 22:04 jackua22

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

EugeneZelenko avatar Apr 22 '24 02:04 EugeneZelenko

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

jackua22 avatar Apr 22 '24 04:04 jackua22

Is there any update on the clang-tidy crash?

jackua22 avatar Jun 27 '24 01:06 jackua22

Can't reproduce crash...

PiotrZSL avatar Jul 09 '24 17:07 PiotrZSL

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?

jackua22 avatar Jul 10 '24 01:07 jackua22

Not reproducible on latest trunk: https://godbolt.org/z/8P9nbGEWM

Please try on version 19 or 20 and reopen if the issue persists.

carlosgalvezp avatar Jun 02 '25 20:06 carlosgalvezp