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

            Bug ID: 42897
           Summary: LLVM optimizer eliminates zero check if return
                    statement is missing
           Product: new-bugs
           Version: 8.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedb...@nondot.org
          Reporter: timo.str...@emmtrix.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org

Created attachment 22344
  --> https://bugs.llvm.org/attachment.cgi?id=22344&action=edit
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to