Issue 91006
Summary [clang] ice taking lambda::operator() address
Labels clang
Assignees
Reporter jvcppdev
    The following code crashes all recent versions clang (tested up to 18.1.0), but compiles smoothly both with recent versions of both g++ and msvc:

```c++
#include <tuple>
#include <functional>
#include <utility>

template<typename T> T fake_get();

using type_list = std::tuple<int, char&, const float*, std::size_t&&, bool>;

template<typename T> struct analyzer_base {};
template<typename T> using analyzer = analyzer_base<decltype(&T::operator())>;

int main(int, char**)
{
    std::invoke([]<std::size_t... i>(std::index_sequence<i...>)
    {
 (std::invoke([]<std::size_t... j>(auto k, std::index_sequence<j...>)
 {
            using return_type = std::tuple_element_t<k, type_list>;
            using arguments_type = std::tuple<std::tuple_element_t<j, type_list>...>;

            using lambda_type = decltype([](std::tuple_element_t<j, type_list>...) -> return_type { return fake_get<return_type>(); });

 analyzer<lambda_type>{};
       }, std::integral_constant<std::size_t, i>{}, std::make_index_sequence<i>{}), ...);
    }, std::make_index_sequence<std::tuple_size_v<type_list> - 1>{});
}
```

```
>clang++ test.cpp -std=c++20
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/lib/llvm-18/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/jvilar -fcoverage-compilation-dir=/home/jvilar -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-191165.o -x c++ test.cpp
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      test.cpp:16:22: Generating code for declaration 'main(int, char **)::(anonymous class)::operator()(std::index_sequence<0UL, 1UL, 2UL, 3UL>)::(anonymous class)::operator()'
#0 0x00007f8e6f7e967f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Unix/Signals.inc:723:13
#1 0x00007f8e6f7e77b9 llvm::sys::RunSignalHandlers() build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Signals.cpp:106:18
#2 0x00007f8e6f7e9dc0 SignalHandler build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Unix/Signals.inc:413:1
#3 0x00007f8e6e5f3320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
#4 0x00007f8e77fb9351 use_empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/IR/Value.h:346:20
#5 0x00007f8e77fb9351 clang::CodeGen::CodeGenFunction::EmitReturnBlock() build-llvm/tools/clang/stage2-bins/clang/lib/CodeGen/CodeGenFunction.cpp:286:51
#6 0x00007fff734b4c50
clang++: error: unable to execute command: Segmentation fault
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 18.1.3 (1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/test-7765b2.cpp
clang++: note: diagnostic msg: /tmp/test-7765b2.sh
clang++: note: diagnostic msg:

********************
```

A live demo is in [Compiler Explorer](https://godbolt.org/z/fb37zGanv).

A zip with original c++ file, preprocessed file and run script is in [test.zip](https://github.com/llvm/llvm-project/files/15204527/test.zip)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to