<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Incorrect order of evaluation for || somehow involving ! of _Bool"
   href="https://bugs.llvm.org/show_bug.cgi?id=35363">35363</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect order of evaluation for || somehow involving ! of _Bool
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jseward@acm.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Incorrect order of evaluation for || somehow involving ! of _Bool

For the following input (in C)

  void ff(void);
  void gg(void);
  _Bool hh(int*);

  void test()
  {
    int a;
    _Bool q = hh(&a);
    if (!q || (a == 42))
      ff();
    else
      gg();
  }

"clang version 5.0.0 (tags/RELEASE_500/final) (llvm/tags/RELEASE_500/final
312553)" on x86_64-Linux, at -O and above, produces code that firsts tests
|a == 42| and only then |!q|:

  test:                                   # @test
          .cfi_startproc
  # BB#0:
          pushq   %rax
  .Lcfi0:
          .cfi_def_cfa_offset 16
          leaq    4(%rsp), %rdi
          callq   hh
          cmpl    $42, 4(%rsp)
          je      .LBB0_2
  # BB#1:
          testb   %al, %al
          je      .LBB0_2
  # BB#3:
          callq   gg
          popq    %rax
          retq
  .LBB0_2:
          callq   ff
          popq    %rax
          retq

I don't see how it can justify comparing |a==42| before looking at the
return value from hh.

I notice also that it produces the "expected" order of tests (testb, then
cmpl) for either of the following changes:

* using |unsigned char| or |int| or |long| instead of |_Bool|
* changing the first term from |!q| to simply |q|

It's as if the compiler believes that ! of _Bool is undefined behavior in
C, so it can do what it likes.  But I can't imagine why it would believe
that.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>