chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.78k stars 418 forks source link

[Bug]: Chapel/Fortran interoperability, internal compiler error #25105

Open mstrout opened 3 months ago

mstrout commented 3 months ago

Summary of Problem

Description:

internal error: UTI-MIS-1041 chpl version 2.0.1

Internal errors indicate a bug in the Chapel compiler,
and we're sorry for the hassle.  We would appreciate your reporting this bug --
please see https://chapel-lang.org/bugs.html for instructions.

Is this a blocking issue with no known work-arounds? There is a work around. The work around is to replace the incorrectly typed extern

extern proc initArray(arr: c_ptr(c_double), size: c_int, val: c_double);

with

extern proc initArray(arr: c_ptr(c_double), const ref size: c_int, const ref val: c_double);

and then the example not only compiles, it also runs correctly. :)

Steps to Reproduce

Source Code:

// example.chpl
use CTypes;

// array example
var D = 0..9;
extern proc initArray(arr: c_ptr(c_double), size: c_int, val: c_double);

var arr : [D] c_double;

initArray(c_ptrTo(arr), arr.size:c_int, 42.0:c_double);
writeln("arr = ", arr);
! exampleLib.f90
module TestProcs
  use iso_c_binding
  implicit none

  contains

! initializes the given 1D array of length size with val at each index
subroutine initArray(arr, size, val) bind(C,name='initArray')
  use iso_c_binding, only: c_int, c_double
  implicit none
  integer(c_int), intent(in) :: size
  real(c_double), intent(out) :: arr(size)
  real(c_double), intent(in) :: val
  integer :: i

  do i = 1, size
    arr(i) = val
  end do
end subroutine initArray

end module TestProcs
// exampleLib.h
void initArray(double* arr, int* size, double* val);

Compile command:

gfortran -c exampleLib.f90
chpl exampleLib.h exampleLib.o example.chpl

Configuration Information

chpl --print-chpl-settings
CHPL_HOME: /usr/local/Cellar/chapel/2.0.1/libexec
CHPL_RUNTIME_LIB: /usr/local/Cellar/chapel/2.0.1/libexec/lib
CHPL_RUNTIME_INCL: /usr/local/Cellar/chapel/2.0.1/libexec/runtime/include
CHPL_THIRD_PARTY: /usr/local/Cellar/chapel/2.0.1/libexec/third-party

machine info: Darwin nameelided 22.6.0 Darwin Kernel Version 22.6.0: Mon Feb 19 19:48:53 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_X86_64 x86_64
CHPL_HOME: /usr/local/Cellar/chapel/2.0.1/libexec *
script location: /usr/local/Cellar/chapel/2.0.1/libexec/util/chplenv
CHPL_HOST_PLATFORM: darwin
CHPL_HOST_COMPILER: clang
  CHPL_HOST_CC: clang
  CHPL_HOST_CXX: clang++
CHPL_HOST_ARCH: x86_64
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: llvm
  CHPL_TARGET_CC: /usr/local/Cellar/llvm@17/17.0.6/bin/clang
  CHPL_TARGET_CXX: /usr/local/Cellar/llvm@17/17.0.6/bin/clang++
  CHPL_TARGET_LD: /usr/local/Cellar/llvm@17/17.0.6/bin/clang++
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: fifo +
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_HOST_MEM: cstdlib
CHPL_MEM: cstdlib +
CHPL_ATOMICS: cstdlib
CHPL_GMP: system +
CHPL_HWLOC: none
CHPL_RE2: bundled +
CHPL_LLVM: system
  CHPL_LLVM_SUPPORT: system
  CHPL_LLVM_CONFIG: /usr/local/opt/llvm@17/bin/llvm-config +
  CHPL_LLVM_VERSION: 17
CHPL_AUX_FILESYS: none
CHPL_LIB_PIC: none
CHPL_SANITIZE: none
CHPL_SANITIZE_EXE: none
gfortran --version
GNU Fortran (Homebrew GCC 14.1.0) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
mstrout commented 3 months ago

Note, this seems to be related to https://github.com/chapel-lang/chapel/issues/24017.