[llvm-bugs] [Bug 37663] New: Incorrect code generated when references are used with ||

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jun 2 13:18:33 PDT 2018


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

            Bug ID: 37663
           Summary: Incorrect code generated when references are used with
                    ||
           Product: clang
           Version: 6.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: anand.shankar.k at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following two functions have identical semantics. Only when x is false
should y be dereferenced. Incorrect code is generated for the first function.

int foo1(int x, int& y, int size)
{
    if (x || y < size)
        return x;
    return size;
}

int foo2(int x, int* y, int size)
{
    if (x || *y < size)
        return x;
    return size;
}

Code via compiler explorer (with -O2) shows that for foo1, y is always
dereferenced.

_Z4foo1iRii: # @_Z4foo1iRii
  cmpl %edx, (%rsi)    # y is dereferenced
  cmovll %edi, %edx
  testl %edi, %edi
  cmovnel %edi, %edx
  movl %edx, %eax
  retq

_Z4foo2iPii: # @_Z4foo2iPii
  testl %edi, %edi
  je .LBB1_1
  movl %edi, %eax
  retq
.LBB1_1:
  xorl %eax, %eax
  cmpl %edx, (%rsi)
  cmovgel %edx, %eax
  retq

-- 
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/20180602/b17f4950/attachment.html>


More information about the llvm-bugs mailing list