This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

target/8972: the c code ' x << i' causes infinite loop when i = 0


>Number:         8972
>Category:       target
>Synopsis:       the c code ' x << i' causes infinite loop when i = 0
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 17 01:16:03 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Or Poran
>Release:        Configured with: ./configure --prefix=/afs/iil/home/o/oporan/fw/gcc/gcc-3.2/../install/ --target=arc-7-elf
>Organization:
>Environment:
Linux
gcc as a cross compiler for arc.
>Description:
the folloing code:
# 1 "a.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "a.c"
int f(int x, int i)
{
        return x << i;
}

produce the following asm code:
    .cpu base
    .section .text
    .align 4
    .global _f
    .type   _f,@function
_f:
    ; BEGIN PROLOGUE ; vars= 0, regs= 0, args= 0, extra= 0
    st fp,[sp]
    mov fp,sp
    ; END PROLOGUE
    mov lp_count,r1
    mov r2,%st(1f)  ; (single insn loop start) >> 2
    sr r2,[lp_start]
    add r2,r2,1
    sr r2,[lp_end]
    nop
    nop
1:  ; single insn loop
    asl r0,r0
    ; EPILOGUE
    j.d blink
    ld.a fp,[sp,0]
.Lfe1:
    .size   _f,.Lfe1-_f
    .ident  "GCC: (GNU) 3.2"


if i is set to 0, the loop counter will wrap around to 0xfffffff thus crating very long loop.
>How-To-Repeat:

>Fix:
a diffrent compiler produce the following asm code
        .file   "a.c"
        .option %reg
        .ident  "hc4.5a -arc7 -O1 a.c"
        .seg    ".text",text
.L00TEXT:
;-------------| f |-------------------
        .global f
f:
        asr.f   %lp_count, %r1
        lsl.cs  %r0, %r0
        lpne    .LP01.4
        lsl     %r0, %r0
        lsl     %r0, %r0
.LP01.4:
        j       [%blink]

        .type f, @function
        .size f, . - f

        .end
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]