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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to