[llvm-bugs] [Bug 31439] New: LLVM consider GEP(a + i - 1) could not be zero

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 20 14:44:52 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31439

            Bug ID: 31439
           Summary: LLVM consider GEP(a + i - 1) could not be zero
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Global Analyses
          Assignee: unassignedbugs at nondot.org
          Reporter: evstupac at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

char *foo() {
  return 0;
}
int main(int argc, char *argv[]) {
  if(foo() + argc - 1)
    return 1;
  return 0;
}

clang test.c -O0
./a.out; echo $?
0
clang test.c -O3
./a.out; echo $?
1

The transformation that leads to this is Early CSE:

ValueTracking.cpp:
isGEPKnownNonNull consider GEP is not null if one of its operands is constant.
That way LLVMoptimize "if(foo() + argc - 1)" to always true.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161220/e246f17d/attachment.html>


More information about the llvm-bugs mailing list