llvm / llvm-project

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

clang musttail crash on arm32 #50758

Open m-gupta opened 3 years ago

m-gupta commented 3 years ago
Bugzilla Link 51416
Version trunk
OS All
CC @haberman,@kbeyls,@lalozano,@m-gupta,@zygoloid,@smithp35,@stephenhines,@yabinc

Extended Description

A new feture in clang [[msuttail]] is causing clang to cash on our internal builds.

Reduced test case:

typedef long a;
typedef short b;
typedef long long c;
class d;
class e;
struct f {};
struct g;
class h {
public:
  enum i { j };
};
template <unsigned> struct k : h {
  static char *l(d *, const char *, e *, const g *, c, f);
  template <typename, typename, i>
  static const char *m(d *, const char *, e *, const g *, c, f);
};
template <unsigned n>
template <typename, typename, h::i>
const char *k<n>::m(d *o, const char *p, e *p3, const g *q, c r, f s) {
  [[clang::musttail]] return l(o, p, p3, q, r, s);
}
template const char *k<1>::m<a, b, h::j>(d *, const char *, e *, const g *, c,
                                         f);
$ clang++ -target armv7a-linux-gnueabihf -mfpu=neon tctable_lite.cpp -c

fatal error: error in backend: failed to perform tail call elimination on a call site marked musttail
PLEASE submit a bug report to https://crbug.com and run tools/clang/scripts/process_crashreports.py (only works inside Google) which will upload a report and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /usr/local/google/home/manojgupta/chromeclang/third_party/llvm-build/Release+Asserts/bin/clang++ -target armv7a-linux-gnueabihf -mfpu=neon generated_message_tctable_lite-b3fd7e.cpp -c
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module 'generated_message_tctable_lite-b3fd7e.cpp'.
4.  Running pass 'ARM Instruction Selection' on function '@_ZN1kILj1EE1mIlsLN1h1iE0EEEPKcP1dS5_P1ePK1gx1f'
#&#8203;0 0x00000000033130b8 

clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 14.0.0 (https://github.com/llvm/llvm-project/ 7d9d926a1861e2f6876943d47f297e2a08a57392)
Target: armv7a-unknown-linux-gnueabihf

Still repros on ToT.

haberman commented 3 years ago

Further reduced:

char *l(int, int, int, long long);
char *m(int a, int b, int c, long long d) {
  [[clang::musttail]] return l(a, b, c, d);
}

Godbolt link: https://godbolt.org/z/81jbn5oEr

Note that the error goes away with -O: https://godbolt.org/z/MrvoT7c4P

This seems like an issue with the ARM backend.

nickdesaulniers commented 1 year ago

ARMTargetLowering::IsEligibleForTailCallOptimization encodes numerous conditions which may prevent tail calls.