Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][debug] Unexpected Assertion `!attr.getIsRecSelf() && "unbound DI recursive self reference"' failure #122024

Closed
jieljiel opened this issue Jan 8, 2025 · 11 comments · Fixed by #122770
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] debuginfo flang:ir

Comments

@jieljiel
Copy link

jieljiel commented Jan 8, 2025

flang crashes with -g on the following example.

module m1
  type t1
    type(t2),pointer :: x1
  end type
  type t2
    type(t3),pointer :: x2
  end type
  type t3
    type(t1),pointer :: x3
  end type
end

program test
  use m1
  type(t1),pointer :: foo
  allocate(foo)
  allocate(foo%x1)
  allocate(foo%x1%x2)
  allocate(foo%x1%x2%x3)
  call sub1(foo%x1)
  print *,'done'
end program

subroutine sub1(bar)
  use m1
  type(t2) :: bar
end subroutine
$ flang -g bug.f90
flang: /proj/build/llvm/Linux_x86_64/mlir/lib/Target/LLVMIR/DebugTranslation.cpp:276: llvm::DINode* mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface): Assertion `!attr.getIsRecSelf() && "u
nbound DI recursive self reference"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -debug-info-kind=standalone -resource-dir /proj/nv/llvm/Linux_x86_64/llvm-4092/lib/clang/20 -mframe-pointer=all -o /tmp/bug-112a39.o -x f95-cpp-input bug.f90
 #0 0x000055b5c315fa8b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x447ba8b)
 #1 0x000055b5c315d2c4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fec3c83c4b0 (/lib/x86_64-linux-gnu/libc.so.6+0x3c4b0)
 #3 0x00007fec3c890ffb __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #4 0x00007fec3c890ffb __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #5 0x00007fec3c890ffb pthread_kill ./nptl/pthread_kill.c:89:10
 #6 0x00007fec3c83c406 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007fec3c82287c abort ./stdlib/abort.c:81:7
 #8 0x00007fec3c82279b _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007fec3c833b86 (/lib/x86_64-linux-gnu/libc.so.6+0x33b86)
#10 0x000055b5c5f2b289 mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7247289)
#11 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#12 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#13 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#14 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#15 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#16 0x000055b5c5f29dd0 mlir::LLVM::detail::DebugTranslation::getMDTupleOrNull(llvm::ArrayRef<mlir::LLVM::DINodeAttr>) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7245dd0)
#17 0x000055b5c5f2abab mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DICompositeTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246bab)
#18 0x000055b5c5f2af9f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246f9f)
#19 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#20 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#21 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#22 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#23 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#24 0x000055b5c5f29dd0 mlir::LLVM::detail::DebugTranslation::getMDTupleOrNull(llvm::ArrayRef<mlir::LLVM::DINodeAttr>) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7245dd0)
#25 0x000055b5c5f2abab mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DICompositeTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246bab)
#26 0x000055b5c5f2af9f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246f9f)
#27 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#28 0x000055b5c5f28a2b mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DISubroutineTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244a2b)
#29 0x000055b5c5f27e63 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243e63)
#30 0x000055b5c5f2a0e6 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DISubprogramAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x72460e6)
#31 0x000055b5c5f2b05f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x724705f)
#32 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#33 0x000055b5c5f2b342 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::LLVMFuncOp, llvm::Function&) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7247342)
#34 0x000055b5c5f1e1c6 mlir::LLVM::ModuleTranslation::convertFunctionSignatures() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x723a1c6)
#35 0x000055b5c5f253c4 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef, bool) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x72413c4)
#36 0x000055b5c32d06ba Fortran::frontend::CodeGenAction::generateLLVMIR() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x45ec6ba)
#37 0x000055b5c32d3be0 Fortran::frontend::CodeGenAction::executeAction() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x45efbe0)
#38 0x000055b5c31a5f3d Fortran::frontend::FrontendAction::execute() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44c1f3d)
#39 0x000055b5c3185c9b Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44a1c9b)
#40 0x000055b5c31ad54e Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44c954e)
#41 0x000055b5c2a868cd fc1_main(llvm::ArrayRef<char const*>, char const*) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da28cd)
#42 0x000055b5c2a86279 main (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da2279)
#43 0x00007fec3c823a90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#44 0x00007fec3c823b49 call_init ./csu/../csu/libc-start.c:128:20
#45 0x00007fec3c823b49 __libc_start_main ./csu/../csu/libc-start.c:347:5
#46 0x000055b5c2a846ee _start (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da06ee)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (https://github.com/llvm/llvm-project 4c4364869c490600b4e33606d481fb27b438d090)
@llvmbot llvmbot added the flang Flang issues not falling into any other category label Jan 8, 2025
@jieljiel
Copy link
Author

jieljiel commented Jan 8, 2025

@abidh, could you please take a look?

@EugeneZelenko EugeneZelenko added debuginfo flang:ir crash Prefer [crash-on-valid] or [crash-on-invalid] and removed flang Flang issues not falling into any other category labels Jan 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2025

@llvm/issue-subscribers-flang-ir

Author: JL (jieljiel)

flang crashes with -g on the following example.
module m1
  type t1
    type(t2),pointer :: x1
  end type
  type t2
    type(t3),pointer :: x2
  end type
  type t3
    type(t1),pointer :: x3
  end type
end

program test
  use m1
  type(t1),pointer :: foo
  allocate(foo)
  allocate(foo%x1)
  allocate(foo%x1%x2)
  allocate(foo%x1%x2%x3)
  call sub1(foo%x1)
  print *,'done'
end program

subroutine sub1(bar)
  use m1
  type(t2) :: bar
end subroutine
$ flang -g bug.f90
flang: /proj/build/llvm/Linux_x86_64/mlir/lib/Target/LLVMIR/DebugTranslation.cpp:276: llvm::DINode* mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface): Assertion `!attr.getIsRecSelf() &amp;&amp; "u
nbound DI recursive self reference"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -debug-info-kind=standalone -resource-dir /proj/nv/llvm/Linux_x86_64/llvm-4092/lib/clang/20 -mframe-pointer=all -o /tmp/bug-112a39.o -x f95-cpp-input bug.f90
 #<!-- -->0 0x000055b5c315fa8b llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x447ba8b)
 #<!-- -->1 0x000055b5c315d2c4 SignalHandler(int) Signals.cpp:0:0
 #<!-- -->2 0x00007fec3c83c4b0 (/lib/x86_64-linux-gnu/libc.so.6+0x3c4b0)
 #<!-- -->3 0x00007fec3c890ffb __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->4 0x00007fec3c890ffb __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #<!-- -->5 0x00007fec3c890ffb pthread_kill ./nptl/pthread_kill.c:89:10
 #<!-- -->6 0x00007fec3c83c406 raise ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->7 0x00007fec3c82287c abort ./stdlib/abort.c:81:7
 #<!-- -->8 0x00007fec3c82279b _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #<!-- -->9 0x00007fec3c833b86 (/lib/x86_64-linux-gnu/libc.so.6+0x33b86)
#<!-- -->10 0x000055b5c5f2b289 mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7247289)
#<!-- -->11 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->12 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->13 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->14 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->15 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->16 0x000055b5c5f29dd0 mlir::LLVM::detail::DebugTranslation::getMDTupleOrNull(llvm::ArrayRef&lt;mlir::LLVM::DINodeAttr&gt;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7245dd0)
#<!-- -->17 0x000055b5c5f2abab mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DICompositeTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246bab)
#<!-- -->18 0x000055b5c5f2af9f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246f9f)
#<!-- -->19 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->20 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->21 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->22 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->23 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->24 0x000055b5c5f29dd0 mlir::LLVM::detail::DebugTranslation::getMDTupleOrNull(llvm::ArrayRef&lt;mlir::LLVM::DINodeAttr&gt;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7245dd0)
#<!-- -->25 0x000055b5c5f2abab mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DICompositeTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246bab)
#<!-- -->26 0x000055b5c5f2af9f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246f9f)
#<!-- -->27 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->28 0x000055b5c5f28a2b mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DISubroutineTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244a2b)
#<!-- -->29 0x000055b5c5f27e63 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243e63)
#<!-- -->30 0x000055b5c5f2a0e6 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DISubprogramAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x72460e6)
#<!-- -->31 0x000055b5c5f2b05f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x724705f)
#<!-- -->32 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->33 0x000055b5c5f2b342 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::LLVMFuncOp, llvm::Function&amp;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7247342)
#<!-- -->34 0x000055b5c5f1e1c6 mlir::LLVM::ModuleTranslation::convertFunctionSignatures() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x723a1c6)
#<!-- -->35 0x000055b5c5f253c4 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&amp;, llvm::StringRef, bool) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x72413c4)
#<!-- -->36 0x000055b5c32d06ba Fortran::frontend::CodeGenAction::generateLLVMIR() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x45ec6ba)
#<!-- -->37 0x000055b5c32d3be0 Fortran::frontend::CodeGenAction::executeAction() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x45efbe0)
#<!-- -->38 0x000055b5c31a5f3d Fortran::frontend::FrontendAction::execute() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44c1f3d)
#<!-- -->39 0x000055b5c3185c9b Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&amp;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44a1c9b)
#<!-- -->40 0x000055b5c31ad54e Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44c954e)
#<!-- -->41 0x000055b5c2a868cd fc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da28cd)
#<!-- -->42 0x000055b5c2a86279 main (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da2279)
#<!-- -->43 0x00007fec3c823a90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#<!-- -->44 0x00007fec3c823b49 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->45 0x00007fec3c823b49 __libc_start_main ./csu/../csu/libc-start.c:347:5
#<!-- -->46 0x000055b5c2a846ee _start (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da06ee)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (https://github.com/llvm/llvm-project 4c4364869c490600b4e33606d481fb27b438d090)

@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2025

@llvm/issue-subscribers-debuginfo

Author: JL (jieljiel)

flang crashes with -g on the following example.
module m1
  type t1
    type(t2),pointer :: x1
  end type
  type t2
    type(t3),pointer :: x2
  end type
  type t3
    type(t1),pointer :: x3
  end type
end

program test
  use m1
  type(t1),pointer :: foo
  allocate(foo)
  allocate(foo%x1)
  allocate(foo%x1%x2)
  allocate(foo%x1%x2%x3)
  call sub1(foo%x1)
  print *,'done'
end program

subroutine sub1(bar)
  use m1
  type(t2) :: bar
end subroutine
$ flang -g bug.f90
flang: /proj/build/llvm/Linux_x86_64/mlir/lib/Target/LLVMIR/DebugTranslation.cpp:276: llvm::DINode* mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface): Assertion `!attr.getIsRecSelf() &amp;&amp; "u
nbound DI recursive self reference"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -debug-info-kind=standalone -resource-dir /proj/nv/llvm/Linux_x86_64/llvm-4092/lib/clang/20 -mframe-pointer=all -o /tmp/bug-112a39.o -x f95-cpp-input bug.f90
 #<!-- -->0 0x000055b5c315fa8b llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x447ba8b)
 #<!-- -->1 0x000055b5c315d2c4 SignalHandler(int) Signals.cpp:0:0
 #<!-- -->2 0x00007fec3c83c4b0 (/lib/x86_64-linux-gnu/libc.so.6+0x3c4b0)
 #<!-- -->3 0x00007fec3c890ffb __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->4 0x00007fec3c890ffb __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #<!-- -->5 0x00007fec3c890ffb pthread_kill ./nptl/pthread_kill.c:89:10
 #<!-- -->6 0x00007fec3c83c406 raise ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->7 0x00007fec3c82287c abort ./stdlib/abort.c:81:7
 #<!-- -->8 0x00007fec3c82279b _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #<!-- -->9 0x00007fec3c833b86 (/lib/x86_64-linux-gnu/libc.so.6+0x33b86)
#<!-- -->10 0x000055b5c5f2b289 mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7247289)
#<!-- -->11 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->12 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->13 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->14 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->15 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->16 0x000055b5c5f29dd0 mlir::LLVM::detail::DebugTranslation::getMDTupleOrNull(llvm::ArrayRef&lt;mlir::LLVM::DINodeAttr&gt;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7245dd0)
#<!-- -->17 0x000055b5c5f2abab mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DICompositeTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246bab)
#<!-- -->18 0x000055b5c5f2af9f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246f9f)
#<!-- -->19 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->20 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->21 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->22 0x000055b5c5f28c14 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DIDerivedTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244c14)
#<!-- -->23 0x000055b5c5f27c7b mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243c7b)
#<!-- -->24 0x000055b5c5f29dd0 mlir::LLVM::detail::DebugTranslation::getMDTupleOrNull(llvm::ArrayRef&lt;mlir::LLVM::DINodeAttr&gt;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7245dd0)
#<!-- -->25 0x000055b5c5f2abab mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DICompositeTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246bab)
#<!-- -->26 0x000055b5c5f2af9f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7246f9f)
#<!-- -->27 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->28 0x000055b5c5f28a2b mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DISubroutineTypeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7244a2b)
#<!-- -->29 0x000055b5c5f27e63 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243e63)
#<!-- -->30 0x000055b5c5f2a0e6 mlir::LLVM::detail::DebugTranslation::translateImpl(mlir::LLVM::DISubprogramAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x72460e6)
#<!-- -->31 0x000055b5c5f2b05f mlir::LLVM::detail::DebugTranslation::translateRecursive(mlir::LLVM::DIRecursiveTypeAttrInterface) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x724705f)
#<!-- -->32 0x000055b5c5f27952 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::DINodeAttr) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7243952)
#<!-- -->33 0x000055b5c5f2b342 mlir::LLVM::detail::DebugTranslation::translate(mlir::LLVM::LLVMFuncOp, llvm::Function&amp;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x7247342)
#<!-- -->34 0x000055b5c5f1e1c6 mlir::LLVM::ModuleTranslation::convertFunctionSignatures() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x723a1c6)
#<!-- -->35 0x000055b5c5f253c4 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&amp;, llvm::StringRef, bool) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x72413c4)
#<!-- -->36 0x000055b5c32d06ba Fortran::frontend::CodeGenAction::generateLLVMIR() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x45ec6ba)
#<!-- -->37 0x000055b5c32d3be0 Fortran::frontend::CodeGenAction::executeAction() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x45efbe0)
#<!-- -->38 0x000055b5c31a5f3d Fortran::frontend::FrontendAction::execute() (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44c1f3d)
#<!-- -->39 0x000055b5c3185c9b Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&amp;) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44a1c9b)
#<!-- -->40 0x000055b5c31ad54e Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x44c954e)
#<!-- -->41 0x000055b5c2a868cd fc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*) (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da28cd)
#<!-- -->42 0x000055b5c2a86279 main (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da2279)
#<!-- -->43 0x00007fec3c823a90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#<!-- -->44 0x00007fec3c823b49 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->45 0x00007fec3c823b49 __libc_start_main ./csu/../csu/libc-start.c:347:5
#<!-- -->46 0x000055b5c2a846ee _start (/proj/nv/llvm/Linux_x86_64/llvm-4092/bin/flang+0x3da06ee)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (https://github.com/llvm/llvm-project 4c4364869c490600b4e33606d481fb27b438d090)

@abidh abidh self-assigned this Jan 8, 2025
@abidh
Copy link
Contributor

abidh commented Jan 8, 2025

@abidh, could you please take a look?

Thanks for reporting this issue. The comment here describe the source of this problem. I thought our implementation would side step the issue but it seems there may be cases where it can still be problem. I will have a look as time permits.

@pawosm-arm
Copy link
Contributor

I was about to file a new bug report, but fortunately, I've found this one. I'm facing the same assertion failing when building dbcsr (one of the CP2K dependencies) with -g -O3 on file https://github.com/cp2k/dbcsr/blob/develop/src/mm/dbcsr_mm_accdrv.F preprocessed into dbcsr_mm_accdrv.F90.

@pawosm-arm
Copy link
Contributor

As a side note, building CP2K's dbcsr seems to be broken again due to some recent commit, it fails like that:

error: Semantic errors in dbt_types.F90
./cp_dbcsr_api.mod:321:1527: error: Value in structure constructor of type 'REAL(4)' is incompatible with component 'dist' of type 'dbcsr_distribution_obj'
  type(dbcsr_type_prv),private::prv=dbcsr_type_prv(prv=dbcsr_types$dbcsr_type(serial_number=-1_4,valid=.false._4,name="                                                                                ",data_area=dbcsr_data_obj(d=NULL()),index=NULL(),row_p=NULL(),col_i=NULL(),blk_p=NULL(),thr_c=NULL(),coo_l=NULL(),ro
w_blk_size=array_i1d_obj(low=NULL()),col_blk_size=array_i1d_obj(low=NULL()),row_blk_offset=array_i1d_obj(low=NULL()),col_blk_offset=array_i1d_obj(low=NULL()),local_rows=array_i1d_obj(low=NULL()),global_rows=array_i1d_obj(low=NULL()),local_cols=array_i1d_obj(low=NULL()),global_cols=array_i1d_obj(low=NULL()),has_loca
l_rows=.false._4,has_global_rows=.false._4,has_local_cols=.false._4,has_global_cols=.false._4,max_rbs=-1_4,max_cbs=-1_4,sparsity_id=-1_4,id_nr=-1_4,nblks=-1_4,nze=-1_4,nblkrows_total=-1_4,nblkcols_total=-1_4,nfullrows_total=-1_4,nfullcols_total=-1_4,nblkrows_local=-1_4,nblkcols_local=-1_4,nfullrows_local=-1_4,nfull
cols_local=-1_4,data_type=-1_4,replication_type=" ",symmetry=.false._4,negate_real=.false._4,negate_imaginary=.false._4,bcsc=.false._4,local_indexing=.false._4,list_indexing=.false._4,data_memory_type=dbcsr_memtype_type(mpi=.false._4,acc_hostalloc=.false._4,acc_devalloc=.false._4,acc_stream=acc_stream_type(dummy=1_
4),pool=NULL(),oversize_factor=1._8),index_memory_type=dbcsr_memtype_type(mpi=.false._4,acc_hostalloc=.false._4,acc_devalloc=.false._4,acc_stream=acc_stream_type(dummy=1_4),pool=NULL(),oversize_factor=1._8),buffers=dbcsr_block_buffer_obj(b=NULL()),wms=NULL(),dist=dbcsr_dist_prv_obj(d=NULL()),refcount=0_4,work_mutab
le=.false._4))




                                                                                                                                                                                                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psmp/exts/dbcsr/dbcsr_types.mod:238:31: Declaration of 'dist'
  type(dbcsr_distribution_obj)::dist=dbcsr_distribution_obj(d=NULL())
                                ^^^^
./cp_dbcsr_api.mod:321:1546: error: Keyword 'd=' may not appear in a reference to a procedure with an implicit interface
  type(dbcsr_type_prv),private::prv=dbcsr_type_prv(prv=dbcsr_types$dbcsr_type(serial_number=-1_4,valid=.false._4,name="                                                                                ",data_area=dbcsr_data_obj(d=NULL()),index=NULL(),row_p=NULL(),col_i=NULL(),blk_p=NULL(),thr_c=NULL(),coo_l=NULL(),ro
w_blk_size=array_i1d_obj(low=NULL()),col_blk_size=array_i1d_obj(low=NULL()),row_blk_offset=array_i1d_obj(low=NULL()),col_blk_offset=array_i1d_obj(low=NULL()),local_rows=array_i1d_obj(low=NULL()),global_rows=array_i1d_obj(low=NULL()),local_cols=array_i1d_obj(low=NULL()),global_cols=array_i1d_obj(low=NULL()),has_loca
l_rows=.false._4,has_global_rows=.false._4,has_local_cols=.false._4,has_global_cols=.false._4,max_rbs=-1_4,max_cbs=-1_4,sparsity_id=-1_4,id_nr=-1_4,nblks=-1_4,nze=-1_4,nblkrows_total=-1_4,nblkcols_total=-1_4,nfullrows_total=-1_4,nfullcols_total=-1_4,nblkrows_local=-1_4,nblkcols_local=-1_4,nfullrows_local=-1_4,nfull
cols_local=-1_4,data_type=-1_4,replication_type=" ",symmetry=.false._4,negate_real=.false._4,negate_imaginary=.false._4,bcsc=.false._4,local_indexing=.false._4,list_indexing=.false._4,data_memory_type=dbcsr_memtype_type(mpi=.false._4,acc_hostalloc=.false._4,acc_devalloc=.false._4,acc_stream=acc_stream_type(dummy=1_
4),pool=NULL(),oversize_factor=1._8),index_memory_type=dbcsr_memtype_type(mpi=.false._4,acc_hostalloc=.false._4,acc_devalloc=.false._4,acc_stream=acc_stream_type(dummy=1_4),pool=NULL(),oversize_factor=1._8),buffers=dbcsr_block_buffer_obj(b=NULL()),wms=NULL(),dist=dbcsr_dist_prv_obj(d=NULL()),refcount=0_4,work_mutab
le=.false._4))




                                                                                                                                                                                                                                                                                           ^
./cp_dbcsr_api.mod:321:1548: error: Null pointer argument requires an explicit interface
  type(dbcsr_type_prv),private::prv=dbcsr_type_prv(prv=dbcsr_types$dbcsr_type(serial_number=-1_4,valid=.false._4,name="                                                                                ",data_area=dbcsr_data_obj(d=NULL()),index=NULL(),row_p=NULL(),col_i=NULL(),blk_p=NULL(),thr_c=NULL(),coo_l=NULL(),ro
w_blk_size=array_i1d_obj(low=NULL()),col_blk_size=array_i1d_obj(low=NULL()),row_blk_offset=array_i1d_obj(low=NULL()),col_blk_offset=array_i1d_obj(low=NULL()),local_rows=array_i1d_obj(low=NULL()),global_rows=array_i1d_obj(low=NULL()),local_cols=array_i1d_obj(low=NULL()),global_cols=array_i1d_obj(low=NULL()),has_loca
l_rows=.false._4,has_global_rows=.false._4,has_local_cols=.false._4,has_global_cols=.false._4,max_rbs=-1_4,max_cbs=-1_4,sparsity_id=-1_4,id_nr=-1_4,nblks=-1_4,nze=-1_4,nblkrows_total=-1_4,nblkcols_total=-1_4,nfullrows_total=-1_4,nfullcols_total=-1_4,nblkrows_local=-1_4,nblkcols_local=-1_4,nfullrows_local=-1_4,nfull
cols_local=-1_4,data_type=-1_4,replication_type=" ",symmetry=.false._4,negate_real=.false._4,negate_imaginary=.false._4,bcsc=.false._4,local_indexing=.false._4,list_indexing=.false._4,data_memory_type=dbcsr_memtype_type(mpi=.false._4,acc_hostalloc=.false._4,acc_devalloc=.false._4,acc_stream=acc_stream_type(dummy=1_
4),pool=NULL(),oversize_factor=1._8),index_memory_type=dbcsr_memtype_type(mpi=.false._4,acc_hostalloc=.false._4,acc_devalloc=.false._4,acc_stream=acc_stream_type(dummy=1_4),pool=NULL(),oversize_factor=1._8),buffers=dbcsr_block_buffer_obj(b=NULL()),wms=NULL(),dist=dbcsr_dist_prv_obj(d=NULL()),refcount=0_4,work_mutab
le=.false._4))

abidh added a commit to abidh/llvm-project that referenced this issue Jan 13, 2025
When RecordType is converted to corresponding DIType, we cache the
information to avoid doing the conversion again.

Our conversion of RecordType looks like this:

ConvertRecordType(RecordType Ty)
1. If type Ty is already in the cache, then return the corresponding item.
2. Create a place holder DICompositeTypeAttr (called ty_self below) for Ty
3. Put Ty->ty_self in the cache
4. Convert members of Ty. This may cause ConvertRecordType to be called
   agin with other types.
5. Create final DICompositeTypeAttr
6. Replace the ty_self in the cache with one created in step 5
end

The purpose of creating ty_self is to handle cases where a member may
have reference to parent type.

Now consider the code below:

type t1
  type(t2), pointer :: p1
end type
type t2
   type(t1), pointer :: p2
end type

While processing t1, we could have a structure like below.
t1 -> t2 -> t1_self

The t2 created during handling of t1 cant be cached on its own as it contains a
place holder reference. It will fail an assert in MLIR if it is processed
standalone. We previously had a check in the step 6 above to not cache it.
But this check was not tight enough. It just checked if a type should not have
a place holder reference to another type. It missed the following case where
the place holder reference can be in a type further down the line.

type t1
  type(t2), pointer :: p1
end type
type t2
  type(t3), pointer :: p2
end type
type t3
  type(t1), pointer :: p3
end type

So while processing t1, we have to stop caching of not only t3 but also
of t2. This PR improves the check and moves the logic inside
convertRecordType.

Please note that this limitation of why a type cant have a placeholder
reference is because of how such references are resolved in the mlir. Please
see the discussion at the end of the following PR.
llvm#106571

Fixes llvm#122024.
@abidh
Copy link
Contributor

abidh commented Jan 13, 2025

Hi @jieljiel, @pawosm-arm
I opened ##122770 to fix this problem. Please have a look and see it resolved your issues.

@pawosm-arm
If you share the recipe on how to build CP2K's dbcsr with flang then I can test the failing file on my side.

@pawosm-arm
Copy link
Contributor

@pawosm-arm If you share the recipe on how to build CP2K's dbcsr with flang then I can test the failing file on my side.

Hi @abidh, the most painful moment when building CP2K is the preparation of all of the required dependencies (namely, sufficient version of OpenMPI, e.g. 5.0.6, fftw with OpenMP support, OpenBLAS from the develop branch, ScaLAPACK and optionally cp2k-libinit). With the required libraries compiled using MPI wrapper and installed in your $HOME, you can use the following config file (name it e.g. Linux-LLVM-upstream.psmp and put it into the CP2K's arch directory):

CC          = $(HOME)/ompi5-upstream/bin/mpicc
CPP         =
FC          = $(HOME)/ompi5-upstream/bin/mpifort -fno-backslash
LD          = $(HOME)/ompi5-upstream/bin/mpifort
AR          = ar -r

OLEVEL      = -g -O3

FFTW_DIR    = $(HOME)/fftw-ompi5-upstream
FFTW_INC    = $(FFTW_DIR)/include
FFTW_LIB    = $(FFTW_DIR)/lib
OPENBLAS_DIR = $(HOME)/openblas-upstream
OPENBLAS_LIB = $(OPENBLAS_DIR)/lib
SCALAPACK_DIR = $(HOME)/scalapack-ompi5-upstream
SCALAPACK_LIB = $(SCALAPACK_DIR)/lib
# LIBINT_DIR  = $(HOME)/cp2k-libint-upstream
# LIBINT_INC  = $(LIBINT_DIR)/include
# LIBINT_LIB  = $(LIBINT_DIR)/lib
# If using LIBINT, add -D__LIBINT below and use the variables defined above

CFLAGS      = $(OLEVEL) -fopenmp -ffp-contract=fast -I$(FFTW_INC)

DFLAGS      = -D__FFTW3 -D__parallel -D__SCALAPACK
FLANG1FLAGS = -ffp-contract=fast
CPPFLAGS    =
FCFLAGS     = $(DFLAGS) $(FLANG1FLAGS) $(OLEVEL) -fopenmp -mcpu=native -ffree-form -I$(FFTW_INC)
LDFLAGS     = $(FCFLAGS)
LIBS        = -L$(SCALAPACK_LIB) -lscalapack -L$(FFTW_LIB) -lfftw3 -lfftw3_omp -Wl,-rpath=$(SCALAPACK_LIB) -L$(OPENBLAS_LIB) -lopenblas -Wl,-rpath=$(OPENBLAS_LIB)

To trigger the build:

$ make ARCH=Linux-LLVM-upstream VERSION="psmp"

The dbcsr will be built first automatically, remember to clone CP2K recursively, so the dbcsr repo will be cloned too.

@abidh
Copy link
Contributor

abidh commented Jan 17, 2025

Hi @pawosm-arm

The PR is approved. If you could confirm that it fixes the issue that you observed then I will merge it.

@pawosm-arm
Copy link
Contributor

pawosm-arm commented Jan 17, 2025

Hi @abidh doing anything with CP2K takes several hours (days if you want to build all of it), I'm starting it now to build up until this know failure point, but you'd have to wait for it if you want to be sure.
EDIT: @abidh please don't wait for me and merge it. I won't be able to proceed this week. I'll try and build CP2K with your change next week.

@pawosm-arm
Copy link
Contributor

@abidh I've managed to prepare building environment for CP2K on a brand new host, and I can confirm that with the patch from your PR applied, I can build dbcsr_mm_accdrv.F90 with -O3 -g flags, so indeed your patch does the job.

abidh added a commit that referenced this issue Jan 20, 2025
When `RecordType` is converted to corresponding `DIType`, we cache the
information to avoid doing the conversion again.

Our conversion of `RecordType` looks like this:

`ConvertRecordType(RecordType Ty)`
1. If type `Ty` is already in the cache, then return the corresponding
item.
2. Create a place holder `DICompositeTypeAttr` (called `ty_self` below)
for `Ty`
3. Put `Ty->ty_self` in the cache
4. Convert members of `Ty`. This may cause `ConvertRecordType` to be
called again with other types.
5. Create final `DICompositeTypeAttr`
6. Replace the `ty_self` in the cache with one created in step 5 end


The purpose of creating `ty_self` is to handle cases where a member may
have reference to parent type.

Now consider the code below:

```
type t1
  type(t2), pointer :: p1
end type
type t2
   type(t1), pointer :: p2
end type
```

While processing t1, we could have a structure like below. `t1 -> t2 ->
t1_self`

The `t2` created during handling of `t1` cant be cached on its own as it
contains a place holder reference. It will fail an assert in MLIR if it
is processed standalone. To avoid this problem, we have a check in the
step 6 above to not cache such types. But this check was not tight
enough. It just checked if a type should not have a place holder
reference to another type. It missed the following case where the place
holder reference can be in a type further down the line.

```
type t1
  type(t2), pointer :: p1
end type
type t2
  type(t3), pointer :: p2
end type
type t3
  type(t1), pointer :: p3
end type
```

So while processing `t1`, we have to stop caching of not only `t3` but
also of `t2`. This PR improves the check and moves the logic inside
`convertRecordType`.

Please note that this limitation of why a type cant have a placeholder
reference is because of how such references are resolved in the mlir.
Please see the discussion at the end of this
[PR](#106571).

I have to change `getDerivedType` so that it will also get the derived
type for things like `type(t2), pointer :: p1` which are wrapped in
`BoxType`. Happy to move it to a new function or a local helper in case
this change is problematic.

Fixes #122024.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] debuginfo flang:ir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants