<html>
    <head>
      <base href="https://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 --- - [WinEH] bad codegen when calling printf in catch and building with optimizations"
   href="https://llvm.org/bugs/show_bug.cgi?id=26036">26036</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[WinEH] bad codegen when calling printf in catch and building with optimizations
          </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>Windows NT
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>r.sagitario@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <stdio.h>

int main(int argc, char** argv)
{
    try
    {
        throw int(8);
    }
    catch (int o)
    {
        printf("caught\n");
    }
    return 0;
}

Compiling this with "clang -m32 -fexceptions -O" creates a crashing executable.
This is caused by the LibCallSimplifier pass replacing printf with puts, but
dropping the "funclet" token:

[...]
catch.dispatch.i:                                 ; preds = %entry
  %2 = catchswitch within none [label %catch.i] unwind to caller

catch.i:                                          ; preds = %catch.dispatch.i
  %3 = catchpad within %2 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32*
%o.i]
  %puts.i = call i32 @puts(i8* nonnull getelementptr inbounds ([7 x i8], [7 x
i8]* @str, i32 0, i32 0))
  catchret from %3 to label %"\01?test56@@YAXXZ.exit" 
[...]

This generates an incomplete funclet for the catch:

"?catch$2@?0??main@@YAXXZ@4HA":
LBB1_2:                                 # %catch
    pushl    %ebp
    subl    $8, %esp
    addl    $12, %ebp
    movl    %esp, -28(%ebp)
Lfunc_end0:

You can disable replacements by setting the NoBuiltin attribute on the printf
function call, but that's not ideal.</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>