[LLVMbugs] [Bug 4737] New: possible clang wrong code bug

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Aug 18 08:38:22 PDT 2009


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

           Summary: possible clang wrong code 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


Sorry for the size of the test input, I wasn't able to reduce it any more.  I
think the test input is well-formed and that clang is wrong at -O2.

Seen on Ubuntu Hardy on x86.

regehr at john-home:~/volatile/tmp183$ clang -O small.c -o small
regehr at john-home:~/volatile/tmp183$ ./small
checksum = 1
regehr at john-home:~/volatile/tmp183$ clang -O2 small.c -o small
regehr at john-home:~/volatile/tmp183$ ./small
checksum = 4294967297
regehr at john-home:~/volatile/tmp183$ clang -v
clang version 1.0 (http://llvm.org/svn/llvm-project/cfe/trunk 79306)
Target: i386-pc-linux-gnu
Thread model: posix
regehr at john-home:~/volatile/tmp183$ cat small.c
#include <stdint.h>
#include <stdio.h>

uint8_t crc32_tab[256];
static uint8_t crc32_context = 1;

static void 
crc32_gentab (void)
{
  uint32_t crc;
  const uint32_t poly = 0xEDB88320UL;
  int i, j;

  for (i = 0; i < 256; i++) {
    crc = i;
    for (j = 8; j > 0; j--) {
      if (crc & 1) {
        crc = (crc >> 1) ^ poly;
      } else {
        crc >>= 1;
      }
    }
    crc32_tab[i] = crc;
  }
}

static void 
crc32_byte (uint8_t b) {
  crc32_context = 
    (((int)crc32_context >> 8) & 0x00FFFFFF) ^ 
    crc32_tab[(crc32_context ^ b) & 0xFF];
}

struct S0
{
  uint8_t f1;
  uint32_t f2;
  uint32_t f3;
};

volatile uint8_t g_3 = 1;
uint8_t g_14;
uint64_t g_17;

struct S0 g_174 = {
  -4L, 0xE212550BL, 1
};

int32_t func_12 (void);
int32_t func_12 (void)
{
  for (g_14 = 0; 0; )
    {
    }
  return 1;
}

uint64_t func_72 (struct S0 p_82);
uint64_t func_72 (struct S0 p_82)
{
  if (func_12 ())
    {
    }
  return p_82.f3;
}

void func_1 (void);
void func_1 (void)
{
  if (g_3)
    {
    }
  else
    {
      return;
    }
  g_17 = func_72 (g_174);
}

int main (void)
{
  crc32_gentab ();
  func_1 ();
  crc32_byte (g_17);
  printf ("checksum = %lld\n", g_17);
  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