Issue 176284
Summary [Flang] Assignment to a C_PTR type variable causes an internal error at a reference of SHAPE intrinsic function
Labels flang
Assignees
Reporter boo-aboutme
    ``` text
Version of flang : 22.0.0git (https://github.com/llvm/llvm-project.git a73de982a95b7bcb3a918987743136bd38c76e7a)
```

Flang causes an internal error while compiling bigdft-futile 1.9.5, an app in Spack.
https://gitlab.com/l_sim/bigdft-suite/-/tree/1.9.5/futile

Original Source File: bigdft-futile 1.9.5 futile/flib/dynamic_memory.f90
Original Compiler Options: -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -I . -I . -I ../dicts -I /work/home/boo/Spack/spack/opt/spack/linux-neoverse_v2/openmpi-5.0.8-2aaafiq4svbq2mkz4hfdfqd4fhllty6w/include -I /work/home/boo/Spack/spack/opt/spack/linux-neoverse_v2/openmpi-5.0.8-2aaafiq4svbq2mkz4hfdfqd4fhllty6w/lib -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -fopenmp -resource-dir /work/groups/ssoft/compiler/llvm/aarch64/main-20251222-366f6eb607da/lib/clang/22 -mframe-pointer=non-leaf-no-reserve -o dynamic_memory.o -x f95 dynamic_memory.f90

I have shortened the source file and options as much as possible.

$ /work/groups/ssoft/compiler/llvm/aarch64/main-20260105-a73de982a95b/bin/flang -fc1 -emit-obj -x f95 test.f90
loc("/work/home/boo/futile/flib/test.f90":40:7): error: 'llvm.call' op incorrect number of operands (1) for callee (expecting: 4)
error: Lowering to LLVM IR failed
flang: /work/groups/ssoft/compiler/llvm/src/llvm-main/llvm/lib/IR/Instructions.cpp:754: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const llvm::Twine&): Assertion `(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"' failed.


test.f90
``` fortran
      module module_f_malloc
      type::malloc_information_ptr
      integer(4)::rank
 integer(8)::shape(1_8:7_8)
      end type
      end

      module smpi_shared
      interface
      pure function smpi_shared_malloc(size,file,line) bind(c,name="malloc")
 use,intrinsic::iso_c_binding,only:c_ptr
 integer(8),intent(in),value::size
 character(1_8,1),intent(in)::file(1_8:*)
 integer(8),intent(in),value::line
      type(c_ptr)::smpi_shared_malloc
 end
      end interface
      end

      module dynamic_memory_base
 use module_f_malloc
      use iso_c_binding
      use smpi_shared
 implicit none

      contains
      subroutine d1_ptr(array,m)
 implicit none
      type(malloc_information_ptr), intent(in) :: m
 double precision, dimension(:), pointer, intent(inout) :: array
 type(c_ptr) :: p
      p = smpi_shared_malloc(product(m%shape(1:(m%rank-1)))*(m%shape(m%rank))* 8, "filename", 0_8)
      end subroutine d1_ptr

      subroutine f_free_str_ptr(length,array)
      implicit none
      integer, intent(in) :: length
      character(len=length), dimension(:), pointer, intent(inout) :: array
      integer,allocatable :: foo(:)
      foo=shape(array)
 end subroutine f_free_str_ptr
      end module dynamic_memory_base
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to