[llvm-bugs] [Bug 37774] New: Incorrect result at self-comparison of uninitialized value

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 11 16:26:13 PDT 2018


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

            Bug ID: 37774
           Summary: Incorrect result at self-comparison of uninitialized
                    value
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: m-takahiro at jp.fujitsu.com
                CC: llvm-bugs at lists.llvm.org

I have tested a program using self-comparison of uninitialized value as below.

--- test.c ---
#include <stdio.h>
int main() {
  int a;
  if (a == a) puts("equal");
  else puts("not equal");
  return 0;
}
--------------

A correct result is output at -O0, but an incorrect result is output at -O1.

$ clang --version
clang version 7.0.0 (trunk 334448)

$ clang -O0 test.c
test.c:4:9: warning: self-comparison always evaluates to true
[-Wtautological-compare]
  if (a == a) puts("equal");
        ^
1 warning generated.

$ ./a.out
equal

$ clang -O1 test.c
test.c:4:9: warning: self-comparison always evaluates to true
[-Wtautological-compare]
  if (a == a) puts("equal");
        ^
1 warning generated.

$ ./a.out
not equal

This is a rare case and I think no one writes a program like this, but I think
self-comparison program should always pass true route even if an uninitialized
value is used.

-- 
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/20180611/7849a528/attachment.html>


More information about the llvm-bugs mailing list