llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.8k stars 11.45k forks source link

Assertion failure in Hexagon constant-extender optimization from Hexagon Linux kernel #99714

Closed nathanchance closed 1 month ago

nathanchance commented 1 month ago

After a seemingly innocuous change in a filesystem driver in the Linux kernel, there is an assertion failure in the Hexagon constant-extender optimization pass. cvise spits out for a reproducer:

enum { BCH_RECOVERY_PASS_scan_for_btree_nodes } six_lock_ip_waiter(long);
void trace_btree_path_lock(long);
static int __btree_node_lock_nopath(long ip) {
  int ret = six_lock_ip_waiter(ip);
  trace_btree_path_lock(({
    __here:
      (long) && __here;
  }));
  return ret;
}
void btree_node_lock_nopath_nofail() {
  int ret = __btree_node_lock_nopath(({
    __here:
      (long) && __here;
  }));
  ret;
}

which can be crashed when using -fno-PIE (which the Linux kernel uses):

$ clang --target=hexagon-linux -O2 -c -o /dev/null btree_io.i
btree_io.i:16:3: warning: expression result unused [-Wunused-value]
   16 |   ret;
      |   ^~~
1 warning generated.

$ clang --target=hexagon-linux -O2 -c -o /dev/null btree_io.i -fno-PIE
btree_io.i:16:3: warning: expression result unused [-Wunused-value]
   16 |   ret;
      |   ^~~
clang: /home/nathan/cbl/src/patched/tc-build/src/llvm-project/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp:745: bool (anonymous namespace)::HexagonConstExtenders::ExtRoot::operator<(const HCE::ExtRoot &) const: Assertion `ThisB->getParent() == OtherB->getParent()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang --target=hexagon-linux -O2 -c -o /dev/null btree_io.i -fno-PIE
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'btree_io.i'.
4.      Running pass 'Hexagon constant-extender optimization' on function '@__btree_node_lock_nopath'
...
llvmbot commented 1 month ago

@llvm/issue-subscribers-backend-hexagon

Author: Nathan Chancellor (nathanchance)

After [a seemingly innocuous change in a filesystem driver in the Linux kernel](https://git.kernel.org/next/linux-next/c/fbb76c9f55205bd8a34164ba34b25411d45e7069), there is an assertion failure in the `Hexagon constant-extender optimization` pass. `cvise` spits out for a reproducer: ```c enum { BCH_RECOVERY_PASS_scan_for_btree_nodes } six_lock_ip_waiter(long); void trace_btree_path_lock(long); static int __btree_node_lock_nopath(long ip) { int ret = six_lock_ip_waiter(ip); trace_btree_path_lock(({ __here: (long) && __here; })); return ret; } void btree_node_lock_nopath_nofail() { int ret = __btree_node_lock_nopath(({ __here: (long) && __here; })); ret; } ``` which can be crashed when using `-fno-PIE` (which the Linux kernel [uses](https://elixir.bootlin.com/linux/v6.10/source/Makefile#L566)): ``` $ clang --target=hexagon-linux -O2 -c -o /dev/null btree_io.i btree_io.i:16:3: warning: expression result unused [-Wunused-value] 16 | ret; | ^~~ 1 warning generated. $ clang --target=hexagon-linux -O2 -c -o /dev/null btree_io.i -fno-PIE btree_io.i:16:3: warning: expression result unused [-Wunused-value] 16 | ret; | ^~~ clang: /home/nathan/cbl/src/patched/tc-build/src/llvm-project/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp:745: bool (anonymous namespace)::HexagonConstExtenders::ExtRoot::operator<(const HCE::ExtRoot &) const: Assertion `ThisB->getParent() == OtherB->getParent()' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: clang --target=hexagon-linux -O2 -c -o /dev/null btree_io.i -fno-PIE 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module 'btree_io.i'. 4. Running pass 'Hexagon constant-extender optimization' on function '@__btree_node_lock_nopath' ... ```
nathanchance commented 1 month ago

I forgot to mention: without assertions enabled, this appears to just result in an infinite loop.

androm3da commented 1 month ago

@iajbar could you take a look at this?

iajbar commented 1 month ago

Thanks for reporting the assert. We are working on fixing it.