[LLVMbugs] [Bug 2779] New: likely loop bug

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Sep 7 22:15:23 PDT 2008


http://llvm.org/bugs/show_bug.cgi?id=2779

           Summary: likely loop bug
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu


Seen using r55890 on Ubuntu Hardy on ia32.  I think the -O1 output is wrong,
the loop looks like it has no choice but to execute nearly 2^16 times.

regehr at john-home:~/volatile/tmp28$ llvm-gcc -O0 small.c -o small
regehr at john-home:~/volatile/tmp28$ ./small
65508
regehr at john-home:~/volatile/tmp28$ llvm-gcc -O1 small.c -o small
regehr at john-home:~/volatile/tmp28$ ./small
36
regehr at john-home:~/volatile/tmp28$ cat small.c
#include <stdint.h>
#include <stdio.h>
#include <limits.h>

static inline int
lshift_s_s(int left, int right)
{
        if ((left < 0)
                || (right < 0)
                || (right >= sizeof(int)*CHAR_BIT)
                || (left > (INT_MAX >> right))) {
                /* Avoid undefined behavior. */
                return left;
        }
        return left << right;
}

static inline unsigned int
lshift_u_u(unsigned int left, unsigned int right)
{
        if ((right >= sizeof(unsigned int)*CHAR_BIT)
                || (left > (UINT_MAX >> right))) {
                /* Avoid undefined behavior. */
                return left;
        }
        return left << right;
}

int32_t func_8 (uint8_t p_9);
int32_t func_8 (uint8_t p_9)
{
  return 1;
}

int32_t func_3 (int8_t p_5);
int32_t func_3 (int8_t p_5)
{
  return 1;
}

uint32_t g_19;

void func_1 (void);
void func_1 (void)
{
  uint16_t l_2;
  for (l_2 = -28; l_2; l_2--)
    {
      func_3 (
              lshift_s_s (l_2, 
                          lshift_u_u (
                                      func_8 (g_19++), 
                                      1)
                          )
              );
    }
}

int main (void)
{
  func_1 ();
  printf ("%d\n", g_19);
  return 0;
}


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list