首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有动态(可分配)向量的gfortran编译器错误

带有动态(可分配)向量的gfortran编译器错误
EN

Stack Overflow用户
提问于 2019-10-09 20:05:47
回答 1查看 140关注 0票数 0

我正在编写一个由多个模块组成的大型Fortran代码,并使用OOP功能。在用gfortran版本7到9编译这段代码时,我遇到了一个错误。

  • 在下面提供了一个最小的工作示例来重现这个bug。它可以保存为test.f95,并在将-fcheck=all传递给编译器时触发使用-fcheck=all进行编译。
  • 出现时使用gfortran 7、8和9,而不是以前的版本(用gfortran 5和6进行测试)。
  • I正在使用Ubuntu18.04.3LTS,4.15.0-65-泛型x86_64

有人能试着复制并确认这个错误吗?我看过不同的bug跟踪系统,但找不到类似的东西。我还没有报告它,并希望确保它是值得报告,然后才这样做。

另外,有什么方法可以避免这个编译器错误呢?

最小工作示例:

代码语言:javascript
复制
module buggy
  implicit none

  type :: par
  contains
    procedure, public :: fun => fun_par
  end type par

  type comp
    class(par), allocatable :: p
  end type comp

  type foo
    type(comp), allocatable :: m(:)
  contains
    procedure, public :: init   => init_foo
    procedure, public :: update => update_foo
  end type foo

contains

  function fun_par(this, x) result(y)
    implicit none
    class(par)          :: this
    integer, intent(in) :: x(:)
    integer             :: y(size(x))
  end function fun_par

  subroutine init_foo(this, n)
    implicit none
    class(foo)          :: this
    integer, intent(in) :: n
    integer             :: k
    allocate(this%m(n))
    do k = 1, n
      allocate(par :: this%m(k)%p)
    end do
  end subroutine init_foo

  subroutine update_foo(this, x)
    implicit none
    class(foo)       :: this
    integer, intent(in) :: x(:)
    integer             :: k
    do k = 1, size(this%m)
      write(*,*) this%m(k)%p%fun(x)
    end do
  end subroutine update_foo

end module buggy

几点意见,从试验和错误:

  • foo的定义中,如果将m指定为固定长度的向量(例如,type(comp) :: m(10)),则会触发相同的bug。allocatable似乎不是comp中使用type(par)而不是class(par)来触发错误的罪魁祸首。但是我需要p在我的代码中是多态的。当指定p为指针而不是可分配的向量时,
  • 相同的错误。
  • 结果yfun_par()中的维数似乎是有问题的:例如,当它是标量时(y而不是y(size(x))),错误不会被触发。H 238F 239

编译器错误消息

使用gfortran 9.2.1:

代码语言:javascript
复制
$ /usr/bin/gfortran-9 -fcheck=all -c test.f95 
test.f95:50:0:

   50 |       write(*,*) this%m(k)%p%fun(x)
      | 
internal compiler error: in gfc_conv_procedure_call, at fortran/trans-expr.c:6785
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-9/README.Bugs> for instructions.

使用gfortran 8.3.0:

代码语言:javascript
复制
$ /usr/bin/gfortran-8 -fcheck=all -c test.f95 
test.f95:50:0:

       write(*,*) this%m(k)%p%fun(x)

internal compiler error: in gfc_conv_procedure_call, at fortran/trans-expr.c:6410
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.

使用gfortran 7.4.0:

代码语言:javascript
复制
$ /usr/bin/gfortran-7 -fcheck=all -c test.f95 
test.f95:50:0:

       write(*,*) this%m(k)%p%fun(x)

internal compiler error: in gfc_conv_procedure_call, at fortran/trans-expr.c:6290
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.

使用gfortran 6.5.0和gfortran 5.5.0:无错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-10 09:29:44

未知的内部编译器错误总是值得报告的。在这种情况下,我也找不到报告,但更熟悉gcc历史的人也许能找到。

要解决此编译器错误,您似乎可以直接引用函数fun_par,而不是组件p的绑定p

代码语言:javascript
复制
write(*,*) fun_par(this%m(1)%p, x)

最后,我们可以将示例稍微简化一些:

代码语言:javascript
复制
module buggy
  implicit none

  type :: par
  contains
    procedure, public :: fun => fun_par
  end type par

  type comp
    class(par), allocatable :: p
  end type comp

  type foo
    type(comp), allocatable :: m(:)
  end type foo

contains

  function fun_par(this)
    class(par)          :: this
    integer             :: fun_par(1)
    fun_par=0
  end function fun_par

  subroutine update_foo(this)
    class(foo)       :: this
    write(*,*) this%m(1)%p%fun()
  end subroutine update_foo

end module buggy
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58311522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档