[llvm-bugs] [Bug 26251] New: [WinEH] bad codegen AllocAInst inside cleanup pad

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 22 01:29:23 PST 2016


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

            Bug ID: 26251
           Summary: [WinEH] bad codegen AllocAInst inside cleanup pad
           Product: new-bugs
           Version: 3.8
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: r.sagitario at gmx.de
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Not sure if this is meant to be supported, but adding an AllocAInst inside a
cleanuppad generates code that does not restore the stack correctly. This
cleanup IR:

////////////////
cleanuppad:                                       ; preds = %0
  %1 = cleanuppad within none []                  ; [#uses = 4]
  %cleanup.frame = alloca [40 x i8]               ; [#uses = 1, size/byte = 40]
  %2 = bitcast [40 x i8]* %cleanup.frame to i8*   ; [#uses = 2]
  %3 = call i1 @_d_enter_cleanup(i8* %2) [ "funclet"(token %1) ] ; [#uses = 1]
  br i1 %3, label %finally1, label %cleanupret

finally1:                                         ; preds = %cleanuppad
  call x86_stdcallcc void @"\01__D7cleanup5sexitFZv"() #0 [ "funclet"(token %1)
]
  br label %cleanupret

cleanupret:                                       ; preds = %cleanuppad,
%finally1
  call void @_d_leave_cleanup(i8* %2) [ "funclet"(token %1) ]
  cleanupret from %1 unwind to caller 
////////////////

is translated to this x86-asm:

////////////////
"?dtor$2@?0?__D7cleanup7cleanupFZv at 4HA":
LBB0_2:
    pushl    %ebp
    pushl    %eax
    addl    $12, %ebp
    movl    $40, %eax
    calll    __chkstk
    movl    %esp, %eax
    movl    $-1, -16(%ebp)
    subl    $4, %esp
    movl    %eax, (%esp)
    movl    %eax, -32(%ebp)
    calll    __d_enter_cleanup
    addl    $4, %esp
    testb    $1, %al
    jne    LBB0_3
    jmp    LBB0_4
LBB0_3:
    movl    $-1, -16(%ebp)
    calll    __D7cleanup5sexitFZv
LBB0_4:
    movl    $-1, -16(%ebp)
    movl    -32(%ebp), %eax
    pushl    %eax
    calll    __d_leave_cleanup
    addl    $8, %esp
    popl    %ebp
    retl
////////////////

Please note that %esp is changed by the "calll __chkstk; movl %esp, %eax"
sequence, but never restored.

I'll attach the full IR and asm files.

-- 
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/20160122/f2062cef/attachment.html>


More information about the llvm-bugs mailing list