[llvm-bugs] [Bug 33673] New: register promotion miscompilation: hoisting division by zero

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 2 01:51:47 PDT 2017


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

            Bug ID: 33673
           Summary: register promotion miscompilation: hoisting division
                    by zero
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: jeehoon.kang at sf.snu.ac.kr
                CC: llvm-bugs at lists.llvm.org

```
$ opt --version
LLVM (http://llvm.org/):
  LLVM version 5.0.0svn
  DEBUG build with assertions.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: ivybridge


$ cat yy.ll

@G = external global i32, align 4

define void @bar() {
  %p = alloca i32, align 4
  %a = load i32, i32* %p, align 4
  call void @foo(i32 %a)
  store i32 sdiv (i32 1, i32 sub (i32 ptrtoint (i32* @G to i32), i32 ptrtoint
(i32* @G to i32))), i32* %p, align 4
  ret void
}

declare void @foo(i32)


$ opt yy.ll -mem2reg -S                        

; ModuleID = 'yy.ll'
source_filename = "yy.ll"

@G = external global i32, align 4

define void @bar() {
  call void @foo(i32 sdiv (i32 1, i32 sub (i32 ptrtoint (i32* @G to i32), i32
ptrtoint (i32* @G to i32))))
  ret void
}

declare void @foo(i32)
```


This is a miscompilation, because the sdiv constant expression, which is a
division by zero, is hoisted across a function call to foo().  It may introduce
undefined behavior when foo() does not terminate.

This bug is due to rewriteSingleStoreAlloca(...) in
PromoteMemoryToRegister.cpp.  It should check that the stored value is not
division by zero, when it is a constant expression.

-- 
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/20170702/398a7541/attachment.html>


More information about the llvm-bugs mailing list