<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 - "error in backend" caused in the code using _Float16 and long double"
   href="https://bugs.llvm.org/show_bug.cgi?id=44385">44385</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"error in backend" caused in the code using _Float16 and long double
          </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>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>Backend: AArch64
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>utsumi.yuichiro@fujitsu.com
          </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>When compiling the following code, "error in backend" was caused.

test.c

```
#include <stdio.h>

_Float16 test(int    const  n,
            long double const* x) {
  _Float16 ret = 0.0f16;
  for(int i=0; i<n; ++i){
    ret += (_Float16)x[i];
  }
  return ret;
}

int main() {
  long double a[35];

  for (int i=0; i<35; i++) {
    a[i] = (long double)i;
  }

  printf("test: %f\n", (float)test(35, a));

  return 0;
}
```

The command and the error when compiling at x86_64 machine is below.

```
$ clang --target=aarch64-unknown-linux-gnu -S test.c -I ./include
fatal error: error in backend: Cannot select: 0xd78c70: f16 = fp_round
0xd78da8, TargetConstant:i64<0>
  0xd78da8: f128,ch = load<(load 16 from %ir.15)> 0xd18a98, 0xd78e10, undef:i64
    0xd78e10: i64 = add 0xd786c0, 0xd78658
      0xd786c0: i64,ch = load<(dereferenceable load 8 from %ir.4)> 0xd18a98,
FrameIndex:i64<1>, undef:i64
        0xd78c08: i64 = FrameIndex<1>
        0xd78d40: i64 = undef
      0xd78658: i64 = shl 0xd78a00, Constant:i64<4>
        0xd78a00: i64,ch = load<(dereferenceable load 4 from %ir.6), sext from
i32> 0xd18a98, FrameIndex:i64<3>, undef:i64
          0xd78b38: i64 = FrameIndex<3>
          0xd78d40: i64 = undef
        0xd78588: i64 = Constant<4>
    0xd78d40: i64 = undef
  0xd787f8: i64 = TargetConstant<0>
In function: test
clang-9: error: clang frontend command failed with exit code 70 (use -v to see
invocation)
clang version 9.0.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/utsumi/llvm9/bin
clang-9: note: diagnostic msg: PLEASE submit a bug report to
<a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash backtrace, preprocessed source,
and associated run script.
clang-9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-9: note: diagnostic msg: /tmp/test-207815.c
clang-9: note: diagnostic msg: /tmp/test-207815.sh
clang-9: note: diagnostic msg:

********************
```

To avoid the following error I specified the `-I ./include`.

```
/usr/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-32.h' file not found
# include <gnu/stubs-32.h>
          ^~~~~~~~~~~~~~~~
1 error generated.
```

The command and the error when compiling at aarch64 machine is below.

```
$ clang test.c
fatal error: error in backend: Cannot select: t13: f16 = fp_round t11,
TargetConstant:i64<0>
  t11: f128,ch = load<(load 16 from %ir.arrayidx)> t0, t10, undef:i64
    t10: i64 = add t4, t9
      t4: i64,ch = load<(dereferenceable load 8 from %ir.x.addr)> t0,
FrameIndex:i64<1>, undef:i64
        t1: i64 = FrameIndex<1>
        t3: i64 = undef
      t9: i64 = shl t21, Constant:i64<4>
        t21: i64,ch = load<(dereferenceable load 4 from %ir.i), sext from i32>
t0, FrameIndex:i64<3>, undef:i64
          t5: i64 = FrameIndex<3>
          t3: i64 = undef
        t8: i64 = Constant<4>
    t3: i64 = undef
  t12: i64 = TargetConstant<0>
In function: test
clang-9: error: clang frontend command failed with exit code 70 (use -v to see
invocation)
Fujitsu clang version 9.0.1  (based on LLVM 9.0.1)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work02/lang2/utsumi/build_9/bin
clang-9: note: diagnostic msg: PLEASE submit a bug report to
<a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash backtrace, preprocessed source,
and associated run script.
clang-9: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-9: note: diagnostic msg: /tmp/test-2ccc58.c
clang-9: note: diagnostic msg: /tmp/test-2ccc58.sh
clang-9: note: diagnostic msg:

********************
```

I apologize in advance that I may not be able to respond to comments or
questions because New Year holidays.</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>