[llvm-bugs] [Bug 26036] New: [WinEH] bad codegen when calling printf in catch and building with optimizations

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 5 16:01:09 PST 2016


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

            Bug ID: 26036
           Summary: [WinEH] bad codegen when calling printf in catch and
                    building with optimizations
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: r.sagitario at gmx.de
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

#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 at 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 at 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.

-- 
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/20160106/70750aea/attachment.html>


More information about the llvm-bugs mailing list