Skip to content

clang crash for fopenmp statement(parallel for) inside lambda function while generating llvm-ir #146335

Open
@suganyat14

Description

@suganyat14

clang crashes with following stack for debug build as follows:

clang++ -fopenmp lambda_iter.cpp
lambda_iter.cpp:15:3: warning: missing 'typename' prior to dependent type name 'l::h' is a C++20 extension [-Wc++20-extensions]
   15 |   l::h aa;
      |   ^
      |   typename
lambda_iter.cpp:52:20: warning: field 'q' is uninitialized when used here [-Wuninitialized]
   52 |   H(n ag, m r) : D(q, 0, ag, r, v), t{o(af, 0, 0)} {}
      |                    ^
lambda_iter.cpp:52:33: warning: field 'v' is uninitialized when used here [-Wuninitialized]
   52 |   H(n ag, m r) : D(q, 0, ag, r, v), t{o(af, 0, 0)} {}
      |                                 ^
lambda_iter.cpp:52:41: warning: field 'af' is uninitialized when used here [-Wuninitialized]
   52 |   H(n ag, m r) : D(q, 0, ag, r, v), t{o(af, 0, 0)} {}
      |                                         ^
DeclRefExpr for Decl not entered in LocalDeclMap?
UNREACHABLE executed at /home/suganya/upstream_llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3260!
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: /home/suganya/upstream_llvm/build/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name lambda_iter.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/suganya -fcoverage-compilation-dir=/home/suganya -resource-dir /home/suganya/upstream_llvm/build/lib/clang/21 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward -internal-isystem /home/suganya/upstream_llvm/build/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fopenmp -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/lambda_iter-1675e7.o -x c++ lambda_iter.cpp
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      lambda_iter.cpp:58:13: Generating code for declaration 'F<double>::ak(H &)::(anonymous class)::operator()'
 #0 0x00005dfda87f5210 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 

Example: (Reduced example of SIRIUS library application using creduce)

enum a {};
class b {
public:
  b(int);
};
struct c {
  typedef b h;
};
using e = b;
using f = b;
template <typename> class g {};
template <typename l> class i {
public:
  using j = long;
  l::h aa;
  i(g<l>) : aa{0} {}
  bool operator!=(i);
  void operator++();
  auto operator*() {
    int k;
    return k;
  }
  j operator-(i);
  void operator+=(j);
};
class o : public g<c> {
public:
  using p = int;
  o(p, e, f);
};
auto begin(g<c> ac) {
  i ad(ac);
  return ad;
}
template <typename l> auto end(l ac) {
  i ad(ac);
  return ad;
}
using m = b;
using n = b;
class D {
protected:
  D(int, int, n, m, a);
};
class H : D {
  int af;
  o t;

public:
  a v;
  int q;
  H(n ag, m r) : D(q, 0, ag, r, v), t{o(af, 0, 0)} {}
  auto s() { return t; }
};
template <typename> class F { void ak(H &) const; };
template <typename am> void F<am>::ak(H &an) const {
  auto ao = an.s();
  auto ap = [ao](H) {
#pragma omp for
    for (auto d : ao)
      ;
  };
  H ar(0, 0);
  ap(ar);
}
template class F<double>;

With release llvm binaries, it compiles successfully.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions