<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - LLVM optimizes away local variables making them alias"
   href="http://llvm.org/bugs/show_bug.cgi?id=18304">18304</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM optimizes away local variables making them alias
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.3
          </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>normal
          </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>uzytkownik2@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11771" name="attach_11771" title="Test case in C++">attachment 11771</a> <a href="attachment.cgi?id=11771&action=edit" title="Test case in C++">[details]</a></span>
Test case in C++

The LLVM opt -O2 optimizes the:

define i32 @main() #2 {
  %1 = alloca i32, align 4
  %ptr1 = alloca i32, align 4
  %ptr2 = alloca i32, align 4
  store i32 0, i32* %1
  call void @_Z4testPi(i32* %ptr2)
  %2 = load i32* %ptr2, align 4
  store i32 %2, i32* %ptr1, align 4
  call void @_Z4testPi(i32* %ptr1)
  ret i32 0
}

into:

define i32 @main() #2 {
  %ptr1 = alloca i32, align 4
  call void @_Z4testPi(i32* %ptr1)
  call void @_Z4testPi(i32* %ptr1)
  ret i32 0
}

The problem is that ptr1 and 'new' ptr2 alias in second case while they did not
in first case. As ptr2 is still formally alive (at least in case of C++) the
test might access it. So the attached testcase produce:

clang++ 3.3/gcc 4.8 -O3:
0
2

clang++ 3.3 -O2:
0
AAA
1

(I've observed it while playing with how clang handles aliases)</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>