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: unassignedclangb...@nondot.org
          Reporter: jbush...@gmail.com
                CC: llvmbugs@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.
_______________________________________________
LLVMbugs mailing list
LLVMbugs@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to