[LLVMbugs] [Bug 24353] New: Incorrect code generated with tail call

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Aug 4 06:56:19 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24353

            Bug ID: 24353
           Summary: Incorrect code generated with tail call
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jbush342 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150804/9b1123b6/attachment.html>


More information about the llvm-bugs mailing list