http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49799

           Summary: gcc arm generates illegal sbfx instruction
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: car...@google.com
              Host: linux
            Target: armeabi


Compile the following code with options -march=armv7-a -O2

extern __inline int bar(int a)
{
    int tmp;

    if (a <= 0) a ^= 0xFFFFFFFF;

    return tmp - 1;
}

void foo(short *K)
{
    short tmp;
    short *pptr, P[14];

    pptr = P;
    tmp = bar(*K);
    *pptr = (*K << tmp) >> 16;

    if (*P < tmp)
        *K++ = 0;
}

gcc 4.7 generates

foo:
    ldrsh    r3, [r0, #0]
    sbfx    r3, r3, #17, #16    // A
    sxth    r3, r3
    cmn    r3, #1
    movlt    r3, #0
    strlth    r3, [r0, #0]    @ movhi
    bx    lr

The sbfx instruction is illegal since the bit position + width > 32.

Although the source code is ill formed (function bar returns undefined value),
compiler should never generate illegal instructions.

gcc4.6 has the same problem.

Reply via email to