Issue 61444
Summary "Illegal instruction" error when compiling code with std::function in clang
Labels new issue
Assignees
Reporter DD-L
    Hello, 
Can someone explain this?

The following code can be compiled using `gcc`/`MSVC` and the resulting program can work normally, outputting the number `1` :

```
#include <functional>
#include <iostream>
#include <string>

typedef std::function<void(int, const std::string&, int)> Fn;

void foo(int a, ...) {
    std::cout << a << std::endl;
}

int main() {
    Fn fn(foo);
    fn(1, "str", 3);
    return 0;
}
```

However, in almost all versions of clang (`<= ver 15.0.0`), the resulting program reports an "`Illegal instruction`" error. Is this considered a bug in clang?

Details:

```
* thread #1, name = 'a.out', stop reason = signal SIGILL: illegal instruction operand
 frame #0: 0x00005555555557e6 a.out`void std::__invoke_impl<void, void (*&)(int, ...), int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int>((null)=__invoke_other @ 0x00007fffffffe038, __f=0x00007fffffffe198, __args=0x00007fffffffe134, __args=0x00007fffffffe178, __args=0x00007fffffffe124)(int, ...), int&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&&) at invoke.h:61:37
   58     template<typename _Res, typename _Fn, typename... _Args>
   59       constexpr _Res
   60 __invoke_impl(__invoke_other, _Fn&& __f, _Args&&... __args)
-> 61       { return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
   62
 63     template<typename _Res, typename _MemFun, typename _Tp, typename... _Args>
   64       constexpr _Res
(lldb) bt
* thread #1, name = 'a.out', stop reason = signal SIGILL: illegal instruction operand
  * frame #0: 0x00005555555557e6 a.out`void std::__invoke_impl<void, void (*&)(int, ...), int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int>((null)=__invoke_other @ 0x00007fffffffe038, __f=0x00007fffffffe198, __args=0x00007fffffffe134, __args=0x00007fffffffe178, __args=0x00007fffffffe124)(int, ...), int&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&&) at invoke.h:61:37
    frame #1: 0x000055555555574c a.out`std::enable_if<__and_<std::is_void<void>, std::__is_invocable<void (*&)(int, ...), int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int> >::value, void>::type std::__invoke_r<void, void (__fn=0x00007fffffffe198, __args=0x00007fffffffe134, __args=0x00007fffffffe178, __args=0x00007fffffffe124)(int, ...), int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int>(void (*&)(int, ...), int&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&&) at invoke.h:154:7
    frame #2: 0x00005555555555fc a.out`std::_Function_handler<void (int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), void (*)(int, ...)>::_M_invoke(__functor=0x00007fffffffe198, __args=0x00007fffffffe134, __args=0x00007fffffffe178, __args=0x00007fffffffe124) at std_function.h:290:9
    frame #3: 0x000055555555547d a.out`std::function<void (int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)>::operator(this=0x00007fffffffe198, __args=1, __args=0x00007fffffffe178, __args=3)(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) const at std_function.h:590:9
    frame #4: 0x00005555555552cc a.out`main at 1.cpp:13:5
    frame #5: 0x00007ffff7a86d90 libc.so.6`__libc_start_call_main(main=(a.out`main at 1.cpp:11), argc=1, argv=0x00007fffffffe2d8) at libc_start_call_main.h:58:16
    frame #6: 0x00007ffff7a86e40 libc.so.6`__libc_start_main_impl(main=(a.out`main at 1.cpp:11), argc=1, argv=0x00007fffffffe2d8, init=0x00007ffff7ffd040, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe2c8) at libc-start.c:392:3
    frame #7: 0x0000555555555175 a.out`_start + 37
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to