llvm / llvm-project

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

Clang crashes on nested lambdas with parameter packs #102169

Open Taw3e8 opened 3 months ago

Taw3e8 commented 3 months ago

This code crashes: https://godbolt.org/z/zdGvoE6h4

template <std::size_t N, std::size_t M>
concept C = requires {
    []<std::size_t... Is>(std::index_sequence<Is...>)
    requires requires {
        []<std::size_t... Js>(std::index_sequence<Js...>)
        requires requires { true; }
        {}(std::make_index_sequence<M>{});
    }
    {}(std::make_index_sequence<N>{});
};

But without the nested lambda it's fine: https://godbolt.org/z/P8svEfjYd

Some issues that seem related: https://github.com/llvm/llvm-project/issues/86361, https://github.com/llvm/llvm-project/issues/93256, https://github.com/llvm/llvm-project/issues/85667

llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-frontend

Author: Jan Piotrowicz (Taw3e8)

This code crashes: https://godbolt.org/z/zdGvoE6h4 ```cpp template <std::size_t N, std::size_t M> concept C = requires { []<std::size_t... Is>(std::index_sequence<Is...>) requires requires { []<std::size_t... Js>(std::index_sequence<Js...>) requires requires { true; } {}(std::make_index_sequence<M>{}); } {}(std::make_index_sequence<N>{}); }; ``` But without the nested lambda it's fine: https://godbolt.org/z/P8svEfjYd Some issues that seem related: https://github.com/llvm/llvm-project/issues/86361, https://github.com/llvm/llvm-project/issues/93256, https://github.com/llvm/llvm-project/issues/85667
zyn0217 commented 3 months ago

Looks like a regression since 18.

zyn0217 commented 3 months ago

I tested locally, and we seem to run into an infinite recursion when mangling requires expressions:

#5 0x00007fd5cc08098d (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:4657:12
  #6 0x00007fd5cc089aa7 (anonymous namespace)::CXXNameMangler::mangleRequiresClause(clang::Expr const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:2085:1
  #7 0x00007fd5cc08c79a (anonymous namespace)::CXXNameMangler::mangleBareFunctionType(clang::FunctionProtoType const*, bool, clang::FunctionDecl const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:0:5
  #8 0x00007fd5cc071610 (anonymous namespace)::CXXNameMangler::mangleFunctionEncodingBareType(clang::FunctionDecl const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:957:1
  #9 0x00007fd5cc070c65 (anonymous namespace)::CXXNameMangler::mangleFunctionEncoding(clang::GlobalDecl) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:855:5
 #10 0x00007fd5cc08f2f0 (anonymous namespace)::CXXNameMangler::mangleLocalName(clang::GlobalDecl, llvm::SmallVector<llvm::StringRef, 4u> const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:0:7
 #11 0x00007fd5cc071909 (anonymous namespace)::CXXNameMangler::mangleNameWithAbiTags(clang::GlobalDecl, llvm::SmallVector<llvm::StringRef, 4u> const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1090:5
 #12 0x00007fd5cc0711f1 (anonymous namespace)::CXXNameMangler::mangleName(clang::GlobalDecl) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1042:1
 #13 0x00007fd5cc08dfed (anonymous namespace)::CXXNameMangler::mangleType(clang::TagType const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:3666:1
 #14 0x00007fd5cc07f6dd (anonymous namespace)::CXXNameMangler::mangleType(clang::RecordType const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:3663:1
 #15 0x00007fd5cc0722d5 (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) /repo/llvm-project-Build/BuildDebug/tools/clang/include/clang/AST/TypeNodes.inc:75:1
 #16 0x00007fd5cc083f05 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:5608:5
 #17 0x00007fd5cc0812c3 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:4915:28
 #18 0x00007fd5cc087883 (anonymous namespace)::CXXNameMangler::mangleRequirement(clang::SourceLocation, clang::concepts::Requirement const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:4598:9
 #19 0x00007fd5cc08375b (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:5466:45
 #20 0x00007fd5cc089aa7 (anonymous namespace)::CXXNameMangler::mangleRequiresClause(clang::Expr const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:2085:1
 #21 0x00007fd5cc08c79a (anonymous namespace)::CXXNameMangler::mangleBareFunctionType(clang::FunctionProtoType const*, bool, clang::FunctionDecl const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:0:5
 #22 0x00007fd5cc071610 (anonymous namespace)::CXXNameMangler::mangleFunctionEncodingBareType(clang::FunctionDecl const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:957:1
 #23 0x00007fd5cc070c65 (anonymous namespace)::CXXNameMangler::mangleFunctionEncoding(clang::GlobalDecl) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:855:5
 #24 0x00007fd5cc08f2f0 (anonymous namespace)::CXXNameMangler::mangleLocalName(clang::GlobalDecl, llvm::SmallVector<llvm::StringRef, 4u> const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:0:7
 #25 0x00007fd5cc071909 (anonymous namespace)::CXXNameMangler::mangleNameWithAbiTags(clang::GlobalDecl, llvm::SmallVector<llvm::StringRef, 4u> const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1090:5
 #26 0x00007fd5cc0711f1 (anonymous namespace)::CXXNameMangler::mangleName(clang::GlobalDecl) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:1042:1
 #27 0x00007fd5cc08dfed (anonymous namespace)::CXXNameMangler::mangleType(clang::TagType const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:3666:1
 #28 0x00007fd5cc07f6dd (anonymous namespace)::CXXNameMangler::mangleType(clang::RecordType const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:3663:1
 #29 0x00007fd5cc0722d5 (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) /repo/llvm-project-Build/BuildDebug/tools/clang/include/clang/AST/TypeNodes.inc:75:1
 #30 0x00007fd5cc083f05 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:5608:5
 #31 0x00007fd5cc0812c3 (anonymous namespace)::CXXNameMangler::mangleExpression(clang::Expr const*, unsigned int, bool) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:4915:28
 #32 0x00007fd5cc087883 (anonymous namespace)::CXXNameMangler::mangleRequirement(clang::SourceLocation, clang::concepts::Requirement const*) /repo/llvm-project/clang/lib/AST/ItaniumMangle.cpp:4598:9
...

So this is probably a duplicate of https://github.com/llvm/llvm-project/issues/70064.

llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-codegen

Author: Jan Piotrowicz (Taw3e8)

This code crashes: https://godbolt.org/z/zdGvoE6h4 ```cpp template <std::size_t N, std::size_t M> concept C = requires { []<std::size_t... Is>(std::index_sequence<Is...>) requires requires { []<std::size_t... Js>(std::index_sequence<Js...>) requires requires { true; } {}(std::make_index_sequence<M>{}); } {}(std::make_index_sequence<N>{}); }; ``` But without the nested lambda it's fine: https://godbolt.org/z/P8svEfjYd Some issues that seem related: https://github.com/llvm/llvm-project/issues/86361, https://github.com/llvm/llvm-project/issues/93256, https://github.com/llvm/llvm-project/issues/85667