<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Exception handling bug with mingw-w64"
   href="https://bugs.llvm.org/show_bug.cgi?id=33220">33220</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Exception handling bug with mingw-w64
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>svyatoslav.scherbina@jetbrains.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18533" name="attach_18533" title="test">attachment 18533</a> <a href="attachment.cgi?id=18533&action=edit" title="test">[details]</a></span>
test

$ cat bug.cpp

class Foo {
    public:
        ~Foo() {}
};

void __attribute__((noinline)) bar() {
    Foo foo;
    throw 42;
}

int main() {
    try {
        bar();
    } catch (int x) {
    }
    return 0;
}


The attached program doesn't run right if compiled by clang++ with '-O2' for
x86_64-w64-mingw32 (tested with mingw-w64 6.3.0).
The program abnormally terminates instead of catching the exception:

$ clang++ -O2 -target x86_64-w64-mingw32 bug.cpp && ./a.exe

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'int'


The bug seems to be triggered by the function 'bar' which has personality
function '__gxx_personality_seh0' specified but doesn't have any landingpad
after the optimization:

___________
; Function Attrs: noinline noreturn uwtable
define void @_Z3barv() local_unnamed_addr #0 personality i8* bitcast (i32
(...)* @__gxx_personality_seh0 to i8*) {
entry:
  %exception = tail call i8* @__cxa_allocate_exception(i64 4) #3
  %0 = bitcast i8* %exception to i32*
  store i32 42, i32* %0, align 16, !tbaa !2
  tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*),
i8* null) #4
  unreachable
}
___________</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>