[LLVMbugs] [Bug 11382] New: Pointer comparison failure with opt -O2

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 15 07:51:12 PST 2011


             Bug #: 11382
           Summary: Pointer comparison failure with opt -O2
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: babslachem at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 7613
  --> http://llvm.org/bugs/attachment.cgi?id=7613
C file to reproduce problem

Here is a simple C example:

#include <stdio.h>

static int rslts[31] ;

int main(int argc, char *argv[]) 
    char *pp = "abcdef", *qq = pp + 5;

    if (qq < pp - 1)     rslts[8] = 4;
    printf ("result[8] = %d\n", rslts[8]) ;
    return 0 ;

When compiled using clang at -O0 or -O2 we got different results.
It seems that at -O2 LLVM opt assumes that pointer comparison is always true
and thus result printed output is:


Where as at -O0 printed output is:


Correct behavior is at -O0. looking at LLVM assembly generated at -O0 on which
we invoke 'opt -O2' we clearly see that final LLVM is not correct.

I used LLVM 2.9, trunk and 3.0rc3 and they all exhibits same behavior.

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