[LLVMbugs] [Bug 3296] New: another math bug

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Wed Jan 7 22:16:09 PST 2009


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

           Summary: another math 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


This is possibly the same bug as PR 3275 and/or PR 3294.  However, this one
first manifests in r61826.  This in on Ubuntu Hardy on x86.

Much of this bulky test input is irrelevant to the problem which involves only
the induction variable.  However, removing code from the body of the loop makes
the problem go away.

llvm-gcc is not valgrind-clean at -O2 for this testcase.

regehr at john-home:~/volatile/tmp113$ llvm-gcc -O1 small.c -o small
regehr at john-home:~/volatile/tmp113$ ./small
0
regehr at john-home:~/volatile/tmp113$ llvm-gcc -O2 small.c -o small
regehr at john-home:~/volatile/tmp113$ ./small
-20
regehr at john-home:~/volatile/tmp113$ cat small.c
#include <stdio.h>
#include <stdint.h>
#include <limits.h>


#define safe_add_macro_int64_t_s_s(si1,si2) \
                ((((((int64_t)(si1))>((int64_t)0)) &&
(((int64_t)(si2))>((int64_t)0)) && (((int64_t)(si1)) >
((INT64_MAX)-((int64_t)(si2))))) \
                  || ((((int64_t)(si1))<((int64_t)0)) &&
(((int64_t)(si2))<((int64_t)0)) && (((int64_t)(si1)) <
((INT64_MIN)-((int64_t)(si2)))))) \
                 ? ((int64_t)(si1)) \
                 : (((int64_t)(si1)) + ((int64_t)(si2))) \
                 ) 

static int64_t
safe_add_func_int64_t_s_s(int64_t _si1, int64_t _si2)
{
  return safe_add_macro_int64_t_s_s(_si1,_si2);
}

#define safe_lshift_macro_uint16_t_u_s(left,right) \
        (((((int)(right)) < ((uint16_t)0)) \
                         || (((int)(right)) >= sizeof(uint16_t)*CHAR_BIT) \
                         || (((uint16_t)(left)) > ((UINT16_MAX) >>
((int)(right))))) \
                        ? ((uint16_t)(left)) \
                        : (((uint16_t)(left)) << ((int)(right))))

static uint16_t
safe_lshift_func_uint16_t_u_s(uint16_t _left, int _right)
{
  return safe_lshift_macro_uint16_t_u_s(_left,_right);
}

#define safe_sub_macro_int8_t_s_s(si1,si2) \
                ((((((int8_t)(si1))^((int8_t)(si2))) \
                & (((((int8_t)(si1)) ^ ((((int8_t)(si1))^((int8_t)(si2))) \
                & (((int8_t)1) <<
(sizeof(int8_t)*CHAR_BIT-1))))-((int8_t)(si2)))^((int8_t)(si2)))) <
((int8_t)0)) \
                ? ((int8_t)(si1)) \
                : (((int8_t)(si1)) - ((int8_t)(si2))) \
                )

#define safe_mod_macro_int16_t_s_s(si1,si2) \
  (((((int16_t)(si2)) == ((int16_t)0)) || ((((int16_t)(si1)) == (INT16_MIN)) &&
(((int16_t)(si2)) == ((int16_t)-1)))) \
  ? ((int16_t)(si1)) \
  : (((int16_t)(si1)) % ((int16_t)(si2))))

#define safe_mul_macro_uint8_t_u_u(ui1,ui2) \
  (((uint8_t)(ui1)) * ((uint8_t)(ui2)))

static uint8_t
safe_mul_func_uint8_t_u_u (uint8_t _ui1, uint8_t _ui2)
{
  return safe_mul_macro_uint8_t_u_u(_ui1,_ui2);
}

uint32_t g_14;

void func_13 (uint32_t p_15);
void func_13 (uint32_t p_15)
{
  for (g_14 = -21; g_14 >= 12; g_14 = safe_add_func_int64_t_s_s (g_14, 1))
    {
      uint32_t l_17 = 1;
      uint32_t l_20;
      (safe_lshift_func_uint16_t_u_s
       ((safe_sub_macro_int8_t_s_s (p_15, 1)), 1))
        && (safe_mod_macro_int16_t_s_s (l_17, p_15)) ||
        safe_mul_func_uint8_t_u_u (l_20, 1);
    }
}

int main (void)
{
  func_13 (1);
  printf ("%d\n", g_14);
  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