[llvm-bugs] [Bug 26679] New: [WinEH] bad codegen in continuation after catch handler

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Feb 20 02:40:53 PST 2016


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

            Bug ID: 26679
           Summary: [WinEH] bad codegen in continuation after catch
                    handler
           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

The attached ccc.ll shows bad code generation for the code executed after the
catch handler: the register rsi is used but is never initialized.

Here's the initial part of the function:

//////////////////////////
; Function Attrs: uwtable
define void @_D3csv9CsvRecord5primeMFZv(%csv.CsvRecord* nocapture nonnull
readonly %.this_arg) #0 personality i32 (i8*, i8*, i8*, i8*)*
@__CxxFrameHandler3 {
assertPassed:
  %ice = alloca %csv.IncompleteCellException*, align 8 ; [#uses = 3, size/byte
= 8]
  %0 = getelementptr inbounds %csv.CsvRecord, %csv.CsvRecord* %.this_arg, i64
0, i32 0 ; [#uses = 1, type = %csv.Input**]
  %1 = load %csv.Input*, %csv.Input** %0, align 8 ; [#uses = 2]
  %2 = getelementptr inbounds %csv.CsvRecord, %csv.CsvRecord* %.this_arg, i64
0, i32 1 ; [#uses = 1, type = i8*]
  %.elt = getelementptr inbounds %csv.Input, %csv.Input* %1, i64 0, i32 0, i32
0 ; [#uses = 1, type = i64*]
  %.unpack = load i64, i64* %.elt, align 8        ; [#uses = 1]
  %3 = insertvalue { i64, i8* } undef, i64 %.unpack, 0 ; [#uses = 1]
  %.elt1 = getelementptr inbounds %csv.Input, %csv.Input* %1, i64 0, i32 0, i32
1 ; [#uses = 1, type = i8**]
  %.unpack2 = load i8*, i8** %.elt1, align 8      ; [#uses = 1]
  %4 = insertvalue { i64, i8* } %3, i8* %.unpack2, 1 ; [#uses = 1]
  %5 = getelementptr inbounds %csv.CsvRecord, %csv.CsvRecord* %.this_arg, i64
0, i32 3, i32 0 ; [#uses = 2, type = %csv.Appender.Data**]
  %.unpack3 = load %csv.Appender.Data*, %csv.Appender.Data** %5, align 8 ;
[#uses = 1]
  %6 = insertvalue %csv.Appender undef, %csv.Appender.Data* %.unpack3, 0 ;
[#uses = 1]
  %7 = load i8, i8* %2, align 1                   ; [#uses = 1]
  invoke void
@_D3csv33__T12csvNextTokenTS3csv8AppenderZ12csvNextTokenFAyaS3csv8AppenderaZv(i8
%7, %csv.Appender %6, { i64, i8* } %4)
          to label %try.success.or.caught unwind label %catch.dispatch

catch.csv.IncompleteCellException:                ; preds = %catch.dispatch
  %8 = catchpad within %9 [%rtti.TypeDescriptor28*
@"Dcsv.IncompleteCellException at TypeDescriptor", i32 0,
%csv.IncompleteCellException** %ice] ; [#uses = 1]
  catchret from %8 to label %catchhandler

try.success.or.caught:                            ; preds = %assertPassed,
%_D6object11__T4idupTwZ4idupFNaNbNdNfAwZAyw.exit
  ret void

catch.dispatch:                                   ; preds = %assertPassed
  %9 = catchswitch within none [label %catch.csv.IncompleteCellException]
unwind to caller ; [#uses = 1]

catchhandler:                                     ; preds =
%catch.csv.IncompleteCellException
  %10 = bitcast %csv.IncompleteCellException** %ice to i8* ; [#uses = 1]
  %11 = call %object.Object* @_d_eh_enter_catch(i8* %10,
%object.TypeInfo_Class* nonnull @_D3csv23IncompleteCellException7__ClassZ) ;
[#uses = 0]
  %12 = load %csv.IncompleteCellException*, %csv.IncompleteCellException**
%ice, align 8 ; [#uses = 2]
  %13 = load %csv.Appender.Data*, %csv.Appender.Data** %5, align 8 ; [#uses =
3]
  %14 = icmp eq %csv.Appender.Data* %13, null     ; [#uses = 1]
  br i1 %14, label %_D3csv8Appender4dataMFZAw.exit, label %condtrue.i
///////////////////

with the respective asm output:

///////////////////
    .text
    .def     _D3csv9CsvRecord5primeMFZv;
    .scl    2;
    .type    32;
    .endef
    .globl    _D3csv9CsvRecord5primeMFZv
    .align    16, 0x90
_D3csv9CsvRecord5primeMFZv:             # @_D3csv9CsvRecord5primeMFZv
.Lfunc_begin0:
.Ltmp2:
.seh_proc _D3csv9CsvRecord5primeMFZv
    .seh_handler __CxxFrameHandler3, @unwind, @except
# BB#0:                                 # %assertPassed
    pushq    %rbp
.Ltmp3:
    .seh_pushreg 5
    pushq    %r15
.Ltmp4:
    .seh_pushreg 15
    pushq    %r14
.Ltmp5:
    .seh_pushreg 14
    pushq    %r13
.Ltmp6:
    .seh_pushreg 13
    pushq    %r12
.Ltmp7:
    .seh_pushreg 12
    pushq    %rsi
.Ltmp8:
    .seh_pushreg 6
    pushq    %rdi
.Ltmp9:
    .seh_pushreg 7
    pushq    %rbx
.Ltmp10:
    .seh_pushreg 3
    subq    $56, %rsp
.Ltmp11:
    .seh_stackalloc 56
    leaq    48(%rsp), %rbp
.Ltmp12:
    .seh_setframe 5, 48
.Ltmp13:
    .seh_endprologue
    movq    $-2, (%rbp)
    movq    %rcx, -16(%rbp)         # 8-byte Spill
    movq    (%rcx), %rax
    movq    16(%rcx), %rdx
    movq    (%rax), %r8
    movq    8(%rax), %r9
    movzbl    8(%rcx), %ecx
.Ltmp0:
    callq   
_D3csv33__T12csvNextTokenTS3csv8AppenderZ12csvNextTokenFAyaS3csv8AppenderaZv
.Ltmp1:
.LBB0_1:                                # %try.success.or.caught
    nop
    addq    $56, %rsp
    popq    %rbx
    popq    %rdi
    popq    %rsi
    popq    %r12
    popq    %r13
    popq    %r14
    popq    %r15
    popq    %rbp
    retq
.LBB0_2:                                # Block address taken
                                        # %catchhandler
    leaq    _D3csv23IncompleteCellException7__ClassZ(%rip), %rdx
    leaq    -8(%rbp), %rcx
    callq    _d_eh_enter_catch
    movq    -8(%rbp), %r15
    movq    16(%rsi), %rax
    xorl    %ebx, %ebx
    testq    %rax, %rax
    movl    $0, %edi
    je    .LBB0_4
# BB#3:                                 # %condtrue.i
///////////////////

Please note that %5 in the IR seems to be assumed in %rsi, but it is never
loaded.

The ccc.ll is a reduced version of csv_opt.ll generated by the LLVM based D
compiler. It can also be generated by optimizing csv_noopt.ll with "opt -O2".
The latter that does not have the problem.

-- 
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/20160220/89f0099d/attachment.html>


More information about the llvm-bugs mailing list