<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:paul_robinson@playstation.sony.com" title="Paul Robinson <paul_robinson@playstation.sony.com>"> <span class="fn">Paul Robinson</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Missing return statement causes wrong branch to be taken"
   href="https://bugs.llvm.org/show_bug.cgi?id=43075">bug 43075</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>paul_robinson@playstation.sony.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Missing return statement causes wrong branch to be taken"
   href="https://bugs.llvm.org/show_bug.cgi?id=43075#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Missing return statement causes wrong branch to be taken"
   href="https://bugs.llvm.org/show_bug.cgi?id=43075">bug 43075</a>
              from <span class="vcard"><a class="email" href="mailto:paul_robinson@playstation.sony.com" title="Paul Robinson <paul_robinson@playstation.sony.com>"> <span class="fn">Paul Robinson</span></a>
</span></b>
        <pre><span class="quote">> I gather that omitting the return statement in C++ leads to undefined
> behavior, but taking the rtn !=0 branch is still rather surprising.</span >

Undefined behavior is often surprising.

In Clang 7, we observe that reaching the end of the function would be UB,
therefore we are allowed to assume that execution path cannot occur.  
However, the "then" branch under the "if" does not have UB, therefore that
must be the path that is taken.  We eliminate the unnecessary if (because
we know the "then" branch will be taken) and the printf and exit calls are
executed.

In current Clang, we do a different analysis (or perhaps change the order of
the analyses) to see that "rtn" is guaranteed to be zero when the "if" is
executed, therefore the "then" path is dead code and can be eliminated.  
Because reaching the end of the function is still UB, and the only live path 
in the entire function goes there, we may assume the function is never executed
and we can eliminate the entire function body.

Fixing your source, as you did, is the correct solution.

Note that if your source had been C code rather than C++, reaching the end
of the function would not be undefined behavior unless the function's caller
attempted to make use of the return value.</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>