[llvm-bugs] [Bug 40657] New: An IR program prints an incorrect result after it is compiled with -O0

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Feb 7 23:53:00 PST 2019


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

            Bug ID: 40657
           Summary: An IR program prints an incorrect result after it is
                    compiled with -O0
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: juneyoung.lee at sf.snu.ac.kr
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

Created attachment 21449
  --> https://bugs.llvm.org/attachment.cgi?id=21449&action=edit
bug 1

Consider this program:

```

define i32 @main() {
entry:
  %call = tail call i64 @f(i8 249, i8 101)
  %call1 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x
i8], [4 x i8]* @.str, i64 0, i64 0), i64 %call)
  ret i32 0
}

declare i32 @printf(i8* nocapture readonly, ...)

@.str = private unnamed_addr constant [4 x i8] c"%lu\00", align 1
define i64 @f(i8 %var2, i8 %var9) {
  %var6 = trunc i8 %var9 to i1
  %var7 = trunc i8 175 to i1
  %var3 = sub nsw i1 %var6, %var7
  %var4 = icmp eq i64 1114591064, 1114591064
  %var1 = udiv i1 %var3, %var4
  %var0 = trunc i8 %var2 to i1
  %res = sub nsw nuw i1 %var0, %var1
  %res.cast = zext i1 %res to i64
  ret i64 %res.cast
}
```

This program should print 1, but it prints 0 after being compiled with -O0.

$ clang --version
clang version 9.0.0 (https://github.com/llvm-mirror/clang.git
23cffd780f5647d02c6c12491f9b2c928757c798)
(https://github.com/llvm-mirror/llvm.git
903a5691e0214c29a4da3796f9a4d598ad3d18f3)
Target: x86_64-unknown-linux-gnu
$ clang -O0 -o a.out 2332174.ll
$ ./a.out
0

I attach a few more programs which should print 1 but they print 0.

-- 
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/20190208/3d5b69f4/attachment.html>


More information about the llvm-bugs mailing list