<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 - UBSan error negating INT64_MIN in AArch64TargetLowering::LowerSELECT_CC"
   href="https://bugs.llvm.org/show_bug.cgi?id=43818">43818</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>UBSan error negating INT64_MIN in AArch64TargetLowering::LowerSELECT_CC
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Backend: AArch64
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andrew@scheidecker.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, peter.smith@linaro.org, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In a LLVM 9 build with -DLLVM_USE_SANITIZER=Undefined, run:

  llc -march=aarch64 repro.ll

where repro.ll contains:

  define i64 @0(i1) {
  entry:
    %1 = select i1 %0, i64 0, i64 -9223372036854775808
    ret i64 %1
  }

This produces the error:

  <snip>/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:4867:29: runtime
error: negation of -9223372036854775808 cannot be represented in type 'int64_t'
(aka 'long'); cast to an unsigned type to negate this value to itself
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
<snip>/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:4867:29 in

It looks like the bug is still present in the tip of tree code, though I
haven't tested it. Here's the code in question:

 
<a href="https://github.com/llvm/llvm-project/blob/073ab70b72fa0db7d9c591f77377ef3ce88cc222/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L5076">https://github.com/llvm/llvm-project/blob/073ab70b72fa0db7d9c591f77377ef3ce88cc222/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L5076</a>

  const int64_t TrueVal = CTVal->getSExtValue();
  const int64_t FalseVal = CFVal->getSExtValue();
  //<snip>
  } else if (TrueVal == -FalseVal) {
                        ^~~~~~~~~

FalseVal is INT64_MIN, and negating it is undefined behavior.</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>