[llvm-bugs] [Bug 43668] New: Throwing C++ exceptions crashes in code which is compiled with clang++ 8 and running on Cygwin64

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 14 01:24:51 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43668

            Bug ID: 43668
           Summary: Throwing C++ exceptions crashes in code which is
                    compiled with clang++ 8 and running on Cygwin64
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zettsu.tatsuya at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Throwing C++ exceptions crashes in code which is compiled with clang++ 8.0.1
(Target: x86_64-unknown-windows-cygnus) and running on Cygwin 64-bit
installation 3.0.7. Compiling with -O0 option causes a crash and compiling with
-O2 option does not.

This does not occur with Cygwin g++ 7.4.0, MinGW g++ 8.2.0 and Windows native
clang++ 8.0.1 (Target: x86_64-pc-windows-msvc).

The following code crashes. Full source code is available on
https://github.com/zettsu-t/throwAndCatch .

1. A free function calls another function
2. The later function invokes (calls the operator() of) a std::function
instance
3. The invoked instance throws an exception.

  void invokeFunc(std::function<void(void)>& func) {
    func();
  }
  void throwInLocal(void) {
    throw std::runtime_error("Error");
  }
  std::function<void(void)> funcObj = &throwInLocal;
  invokeFunc(funcObj);

This is a gdb backtrace when throwing an exception crashed.

  gdb: unknown target exception 0x20474343 at 0x7fface6ea839
  Thread 1 "throw_catch_clang" received signal ?, Unknown signal.
  0x00007fface6ea839 in RaiseException () from
/cygdrive/c/WINDOWS/System32/KERNELBASE.dll
  (gdb) bt
  #0  0x00007fface6ea839 in RaiseException () from
/cygdrive/c/WINDOWS/System32/KERNELBASE.dll
  #1  0x00000003de6bcbf1 in cyggcc_s-seh-1!_Unwind_RaiseException () from
/usr/bin/cyggcc_s-seh-1.dll
  #2  0x00000003c3599148 in cygstdc++-6!.cxa_throw () from
/usr/bin/cygstdc++-6.dll
  #3  0x0000000100401948 in (anonymous namespace)::throwInLocal () at
throw_catch_main.cpp:12
  #4  0x0000000100402c65 in std::_Function_handler<void (), void
(*)()>::_M_invoke(std::_Any_data const&)
      (__functor=...) at
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/std_function.h:316
  #5  0x00000001004032aa in std::function<void ()>::operator()() const
(this=0xffffcb58)
      at
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/std_function.h:706
  #6  0x00000000ffffc8a8 in ?? ()
  Backtrace stopped: previous frame inner to this frame (corrupt stack?)

I found invoking the std::function instance in other statements prevents
crashes like shown below.

  std::function<void(void)> funcObj = &throwInLocal;
  funcObj();
  invokeFunc(funcObj);

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191014/ddb657dc/attachment.html>


More information about the llvm-bugs mailing list