<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - register promotion miscompilation: hoisting division by zero"
   href="https://bugs.llvm.org/show_bug.cgi?id=33673">33673</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>register promotion miscompilation: hoisting division by zero
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jeehoon.kang@sf.snu.ac.kr
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>```
$ opt --version
LLVM (<a href="http://llvm.org/">http://llvm.org/</a>):
  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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>