[LLVMbugs] [Bug 3149] New: possible integer miscompilation

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Nov 30 20:50:47 PST 2008


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

           Summary: possible integer miscompilation
           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 one is interesting because llvm-gcc's output is wrong at all optimization
levels (-O0 through -O3).

This is a regression since 2.3.

Seen on r60325 on Ubuntu Hardy on x86.

regehr at john-home:~/volatile/tmp71$ llvm-gcc -O small.c -o small ; ./small
-1
regehr at john-home:~/volatile/tmp71$ llvm-gcc-2.4 -O small.c -o small ; ./small
-1
regehr at john-home:~/volatile/tmp71$ llvm-gcc-2.3 -O small.c -o small ; ./small
-10347
regehr at john-home:~/volatile/tmp71$ llvm-gcc-2.2 -O small.c -o small ; ./small
-10347
regehr at john-home:~/volatile/tmp71$ icc -O small.c -o small ; ./small
-10347
regehr at john-home:~/volatile/tmp71$ gcc -O small.c -o small ; ./small
-10347
regehr at john-home:~/volatile/tmp71$ cat small.c
#include <stdint.h>
#include <stdio.h>


static inline int16_t
safe_mul_int16_t_s_s (int16_t si1, int16_t si2) 
{                                               
        if (si1 > 0){  /* si1 is positive */    
                if (si2 > 0) {  /* si1 and si2 are positive */
                        if (si1 > (INT16_MAX / si2)) {          
                                return si1;                     
                        }                                       
                } /* end if si1 and si2 are positive */         
                else { /* si1 positive, si2 non-positive */     
                        if (si2 < (INT16_MIN / si1)) {          
                                return si1;                     
                        }                                       
                } /* si1 positive, si2 non-positive */          
        } /* end if si1 is positive */                          
        else { /* si1 is non-positive */                        
                if (si2 > 0) { /* si1 is non-positive, si2 is positive */       
                        if (si1 < (INT16_MIN / si2)) {                  
                                return si1;                             
                        }                                               
                } /* end if si1 is non-positive, si2 is positive */     
                else { /* si1 and si2 are non-positive */               
                        if ( (si1 != 0) && (si2 < (INT16_MAX / si1))) { 
                                return si1;                     
                        }                                               
                } /* end if si1 and si2 are non-positive */
        } /* end if si1 is non-positive */                      
        return si1 * si2;                                       
}                                                               

static inline uint64_t                                                  
safe_mod_uint64_t_u_u (uint64_t ui1, uint64_t ui2)                      
{                                                                       
        if (ui2 == 0) return ui1;                                       
        return ui1 % ui2;                                               
}                                                                       

int32_t g_355 = 0xC5E0286AL;
int32_t g_379 = -1L;
uint32_t g_450;

int32_t func_3 (uint32_t p_4);
int32_t func_3 (uint32_t p_4)
{
  g_450 = safe_mul_int16_t_s_s (p_4, 1);
  return 1;
}

int32_t func_1 (void);
int32_t func_1 (void)
{
  func_3 (safe_mod_uint64_t_u_u (g_379, g_355));
  return 1;
}

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