Skip to content

Pointer comparison failure with opt -O2 #11754

@llvmbot

Description

@llvmbot
Bugzilla Link 11382
Resolution INVALID
Resolved on Nov 16, 2011 02:22
Version trunk
OS Linux
Attachments C file to reproduce problem, ll produced by clang at -O0, ll file after opt -O2 ptrcomp.ll -S -o ptrcomp.opt.ll
Reporter LLVM Bugzilla Contributor
CC @efriedma-quic,@sunfishcode

Extended Description

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:

result[8]=4

Where as at -O0 printed output is:

result[8]=0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillainvalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions