<html>
    <head>
      <base href="https://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 --- - Wrong optimization when goto jumps backwards over declaration"
   href="https://llvm.org/bugs/show_bug.cgi?id=27604">27604</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong optimization when goto jumps backwards over declaration
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cherepan@mccme.ru
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The program:

#include <stdio.h>

int main()
{
  int *p = 0;

 start:
  if (p) {
    printf("%d\n", *p);
    return 0;
  }

  int x;
  x = 1;
  p = &x;
  goto start;
}

should print "1" but prints "0" when compiled with clang -O1.
Tested on clang version 3.9.0 (trunk 268228).
Tests with <a href="https://gcc.godbolt.org/">https://gcc.godbolt.org/</a> show that it started between 3.6 and 3.7.

The reason probably is insertion of llvm.lifetime.start where a declaration
occurs instead of where the corresponding block starts.
The relevant part of C11 is 6.2.4p5-6: "An object whose identifier is declared
with no linkage and without the storage-class specifier static has automatic
storage duration, as do some compound literals. [...] For such an object that
does not have a variable length array type, its lifetime extends from entry
into the block with which it is associated until execution of that block ends
in any way."</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>