<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 --- - Incorrect code generated with tail call" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24353&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=1QvJjvP5MN0vhtWENATwUP9i6SLFxtPaMX_1qT8pQ9Y&s=8da4sLh-uK6SdlFYGNRPrQ6UNhwrVlAGmXsKYyQaSWg&e=">24353</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect code generated with tail call
          </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>All
          </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>jbush342@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>clang & llvm @243600

The following code:

    #include <stdio.h>

    static int function1() {
        printf("B\n");
    }

    void function2() {
        function1();
        printf("C\n");
    }

    int main(int argc, const char *argv[]) {
        function2();
    }

Will go into infinite recursion and crash. When compiled with -O3, function2
generates the following. The function abruptly ends after the first puts call
(printf "B"), and there is no epilogue:

__Z9function2v:                         ## @_Z9function2v
    .cfi_startproc
    pushq    %rbp
    movq    %rsp, %rbp
Ltmp2:  leaq    L_str.2(%rip), %rdi
    callq    _puts
    .cfi_endproc

    .globl    _main

The LLVM IR has inserted an unreachable after the first inlined call to printf
for some reason:

define void @_Z9function2v() #0 {
entry:
  %puts.i = tail call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]*
@str.2, i64 0, i64 0)) #1
  unreachable
}</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>