<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 - LLVM optimizer eliminates zero check if return statement is missing"
   href="https://bugs.llvm.org/show_bug.cgi?id=42897">42897</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM optimizer eliminates zero check if return statement is missing
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>timo.stripf@emmtrix.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22344" name="attach_22344" title="C++ file to reproduce bug">attachment 22344</a> <a href="attachment.cgi?id=22344&action=edit" title="C++ file to reproduce bug">[details]</a></span>
C++ file to reproduce bug

Dear LLVM developers,

I think I have found a bug inside the LLVM optimizer for O1.

We have the following function that is missing the return statement:

int func1_broken(long long count) {
        Test t1[10][count];
}

The code should call the constructor of Test class 10*count times. In the IR
generated by the clang front end, there is a zero check followed by a do/while
construct to call the constructor. The bug is now that the optimizer eliminates
the zero check.

If we change the return type to void or add the missing return statement

void func2_correct(long long count) {
        Test t1[10][count];
}

the zero check is not eliminated.


You can reproduce the bug by compiling the attached llvmbug.cpp. Just run

clang++ -S -emit-llvm -O1 llvmbug.cpp -o llvmbug.ll 

and take a look at llvmbug.ll. Different results for func1_broken and
func2_correct/func3_correct are generated.

I have tested it with clang 5.0.1 from cygwin as well as a self-compiled
clang/llvm version 8.0.0.</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>