[llvm-bugs] [Bug 42897] New: LLVM optimizer eliminates zero check if return statement is missing

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 6 01:56:07 PDT 2019


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: unassignedbugs at nondot.org
          Reporter: timo.stripf at emmtrix.com
                CC: htmldeveloper at gmail.com, llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190806/cc3d380b/attachment-0001.html>


More information about the llvm-bugs mailing list