<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - crash in ExitCXXTryStmt where top of EHStack does not contain EHCatchScope"
   href="http://llvm.org/bugs/show_bug.cgi?id=21236">21236</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>crash in ExitCXXTryStmt where top of EHStack does not contain EHCatchScope
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nlewycky@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

class exception {};

struct T {
  char a[33];
};

void foo() {
  try {
    const T& t = T();
  } catch (const exception& e) {
  }
}

Reproduce with "clang -O2".

This crashes in clang's llvm codegen but only with -O2. You can use -mllvm
-disable-llvm-optzns and it still crashes. 

nlewycky@ducttape:~$ llvm/Debug+Asserts/bin/clang -O2 x.cc
clang: /usr/local/google/home/nlewycky/llvm/include/llvm/Support/Casting.h:230:
typename llvm::cast_retty<To, From>::ret_type llvm::cast(Y&) [with X =
clang::CodeGen::EHCatchScope; Y = clang::CodeGen::EHScope; typename
llvm::cast_retty<To, From>::ret_type = clang::CodeGen::EHCatchScope&]:
Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
0  clang           0x0000000003e86b19 llvm::sys::PrintStackTrace(_IO_FILE*) +
38
1  clang           0x0000000003e86d96
2  clang           0x0000000003e86696
3  libpthread.so.0 0x00007f8ae8b88340
4  libc.so.6       0x00007f8ae7b9bbb9 gsignal + 57
5  libc.so.6       0x00007f8ae7b9efc8 abort + 328
6  libc.so.6       0x00007f8ae7b94a76
7  libc.so.6       0x00007f8ae7b94b22
8  clang           0x000000000162ec0a
9  clang           0x000000000162ceeb
clang::CodeGen::CodeGenFunction::ExitCXXTryStmt(clang::CXXTryStmt const&, bool)
+ 123

I think the top of the stack has a NormalAndEHCleanup:

(gdb) p EHStack.begin() 
$1 = {Ptr = 0x67a82a0 ""}
(gdb) p *(EHCleanupScope*)0x67a82a0
$7 = {<clang::CodeGen::EHScope> = {CachedLandingPad = 0x0, 
    CachedEHDispatchBlock = 0x0, EnclosingEHScope = {Size = 48}, {
      CommonBits = {Kind = 0}, CatchBits = {NumHandlers = 775}, CleanupBits = {
        IsNormalCleanup = 1, IsEHCleanup = 1, IsActive = 1, 
        TestFlagInNormalCleanup = 0, TestFlagInEHCleanup = 0, 
        CleanupSize = 24, FixupDepth = 0}, FilterBits = {NumFilters = 775}}}, 
  EnclosingNormal = {Size = 0}, EnclosingEH = {Size = -1}, NormalBlock = 0x0, 
  ActiveFlag = 0x0, ExtInfo = 0x0}</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>