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 rejects valid empty constructor #239

Closed
nncarlson opened this Issue Sep 23, 2017 · 20 comments

Comments

Projects
None yet
6 participants
@nncarlson

nncarlson commented Sep 23, 2017

The current version of flang (5.0) rejects this valid code

module example
  type :: map
    integer, pointer :: first => null()
  end type
  type :: parameter_list
    type(map) :: params = map() ! this is entirely valid
  end type
end module

with this error

F90/x86-64 Linux Flang - 1.5 2017-05-01: compilation aborted
$ flang -c flang-bug-20170923b.f90 
F90-F-0155-Empty structure constructor() - type map (flang-bug-20170923b.f90: 12)

This issue is related to the ECP ExaAM project.

@nncarlson

This comment has been minimized.

nncarlson commented Mar 20, 2018

@sscalpone this seems to have been fixed along with #240 by c97bf69. Was that @gklimowicz expectation too?

@dev-zero

This comment has been minimized.

dev-zero commented Mar 20, 2018

Negative. With a freshly built flang (1efaacf) I still get:

flang -c -ffree-form -D__COMPILE_ARCH="\"flang\"" -D__COMPILE_DATE="\"Die Mär 20 10:28:16 CET 2018\"" -D__COMPILE_HOST="\"tcpc18\"" -D__COMPILE_REVISION="\"svn:18331\"" -D__DATA_DIR="\"/scratch/tiziano/flang/cp2k.svn/data\"" -D__SHORT_FILE__="\"dbcsr/base/dbcsr_types.F\"" -I'/scratch/tiziano/flang/cp2k.svn/src/dbcsr/base/' dbcsr_types.F90 
F90-F-0155-Empty structure constructor() - type dbcsr_memtype_type (/scratch/tiziano/flang/cp2k.svn/src/dbcsr/base/dbcsr_types.F: 488)
F90/x86-64 Linux Flang - 1.5 2017-05-01: compilation aborted

Note: the version shown here seems to come from clang. Is there a way to get the built-in version strings for flang1/2?

@nncarlson

This comment has been minimized.

nncarlson commented Mar 20, 2018

Your still-failing result prompted me to do a completely fresh build (llvm, clang, openmp-llvm, flang). For a long time I'd just been pulling the latest flang and running make. This is still passing for me with the new 1efaacf. I followed the wiki build instructions exactly, installing everything into a common CMAKE_INSTALL_PREFIX

@dev-zero

This comment has been minimized.

dev-zero commented Mar 22, 2018

while I can confirm that it works for a MWE, I still get the error on at least one of our source files cp2k/src/dbcsr/base/dbcsr_types.F:

$ flang -std=f2003 -ffree-form -D__COMPILE_ARCH="\"flang\"" -D__COMPILE_DATE="\"Don Mär 22 09:12:28 CET 2018\"" -D__COMPILE_HOST="\"tcpc18\"" -D__COMPILE_REVISION="\"svn:18331\"" -D__SHORT_FILE__="\"dbcsr/base/dbcsr_types.F\"" dbcsr_types.F90
F90-F-0155-Empty structure constructor() - type dbcsr_memtype_type (/scratch/tiziano/flang/cp2k.svn/src/dbcsr/base/dbcsr_types.F: 488)
F90/x86-64 Linux Flang - 1.5 2017-05-01: compilation aborted

with the line in question:

      TYPE(dbcsr_memtype_type)                     :: data_memory_type = dbcsr_memtype_type()
@dev-zero

This comment has been minimized.

dev-zero commented Mar 22, 2018

ok, here we go with the minimal reproducer:

dbcsr_data_types.f90:

module dbcsr_data_types
   TYPE dbcsr_mempool_type
   END TYPE dbcsr_mempool_type

   TYPE dbcsr_memtype_type
      LOGICAL                           :: mpi = .FALSE.
      TYPE(dbcsr_mempool_type), POINTER :: pool => Null()
   END TYPE dbcsr_memtype_type
end module

dbcsr_data_types_user.f90:

module a
   use dbcsr_data_types, only: dbcsr_memtype_type

   type foo
      type(dbcsr_memtype_type) :: val = dbcsr_memtype_type()
   end type
end module

building with flang -c dbcsr_data_types.f90 && flang -c dbcsr_data_types_user.f90:

F90-F-0155-Empty structure constructor() - type dbcsr_memtype_type (dbcsr_data_types_user.f90: 5)
F90/x86-64 Linux Flang - 1.5 2017-05-01: compilation aborted

leaving away either the mpi or the pool attributes in dbcsr_memtype_type makes it compile.

Works with gfortran 4.8 and 8.
May or may not be related to invalid intermediate code in issue #424 I found on the way to this.

@nncarlson

This comment has been minimized.

nncarlson commented Mar 22, 2018

@dev-zero, I think my original example and yours are exposing the same problem as #240. Tweaking the examples slightly can go from it compiling without error, compiling with an error, or dying with an internal error.

@pawosm-arm

This comment has been minimized.

Contributor

pawosm-arm commented Apr 26, 2018

It's still not fixed on current master. Although initial example builds now, the minimal reproducer as presented above still fails with the same error message.

@pawosm-arm

This comment has been minimized.

Contributor

pawosm-arm commented Jun 9, 2018

Although this commit 4582628 makes it (the new reproducer given above) compile (with bunch of ugly warnings!), when I added some fields after and before pointer-typed field and printed content of those fields, their values became completely messed up!
Also, cp2k 5.1 still doesn't build, though the error message is different:

F90-S-0091-Constant expression of wrong data type (dbcsr_types.F90: 494)
F90-S-0091-Constant expression of wrong data type (dbcsr_types.F90: 494)
@sscalpone

This comment has been minimized.

Contributor

sscalpone commented Jun 11, 2018

Hi Paul, do you have an example of the new issues to upload?

@pawosm-arm

This comment has been minimized.

Contributor

pawosm-arm commented Jun 11, 2018

Something like this:

module empty
  type :: map
    integer :: q = 0
    integer :: j = -1
    integer, pointer :: first => null()
    integer :: i = 3
    integer :: i1 = 4
    integer, pointer :: first2 => null()
    integer :: i2 = 5
    integer :: i3 = 6
    integer, pointer :: first3 => null()
  end type
  type :: parameter_list
    type(map) :: params = map() ! this is entirely valid
  end type
end module

program a
  use empty

  type(parameter_list) :: var

  print *, var%params%j, var%params%i, var%params%i1, var%params%i2
end program

...spits warnings at compile time and prints wrong values at runtime.

@sscalpone

This comment has been minimized.

Contributor

sscalpone commented Jun 11, 2018

Seeing these:
F90-W-0164-Overlapping data initializations of ._dtInit0080 (flang-239c.f90)
....

@nncarlson

This comment has been minimized.

nncarlson commented Jun 11, 2018

Also see the examples from #240 which I think is the same underlying problem(s)

@janusw

This comment has been minimized.

janusw commented Jul 9, 2018

F90-S-0091-Constant expression of wrong data type (dbcsr_types.F90: 494)

I'm seeing the same error here with this example:

module m

   type :: t1
   contains
      procedure :: isEqual   => t1_tbp
   end type

   type, extends(t1) :: t2
      integer :: a = 0
   end type

   type(t2), parameter, public :: x = t2()

contains

   logical function t1_tbp(self)
      class(t1), intent(in) :: self
   end function

end

flang complains:

F90-S-0091-Constant expression of wrong data type (test.f90: 12)
F90-S-0066-Too few data constants in initialization statement (test.f90: 12)
@gklimowicz

This comment has been minimized.

Contributor

gklimowicz commented Aug 2, 2018

Janus, I've added this to the list of test cases we have for structure constructors.

@janusw

This comment has been minimized.

janusw commented Aug 3, 2018

Thanks! Is the bug fixed, though? I still see the same errors with today's master ...

@gklimowicz

This comment has been minimized.

Contributor

gklimowicz commented Aug 3, 2018

Not fixed yet; there are multiple cases that we're chasing down. I just wanted to make sure we had yours for internal testing and regression testing. If you're interested in contributing this to the open source Flang tests, that would be great (but we need a CLA, according to NVIDIA). See the Wiki Community page if you're interested. https://github.com/flang-compiler/flang/wiki/Community

@janusw

This comment has been minimized.

janusw commented Aug 4, 2018

If you're interested in contributing this to the open source Flang tests, that would be great (but we need a CLA, according to NVIDIA)

Sure! I'll send you the CLA soon ...

@pawosm-arm

This comment has been minimized.

Contributor

pawosm-arm commented Nov 9, 2018

Resuming this one, I'd like to remind two reproducers:

  1. Following code gives wrong results:
module empty
  implicit none
  type :: map
    integer :: q = 0
    integer :: j = -1
    integer, pointer :: first => null()
    integer :: i = 3
    integer :: i1 = 4
    integer, pointer :: first2 => null()
    integer :: i2 = 5
    integer :: i3 = 6
    integer, pointer :: first3 => null()
  end type

  type :: parameter_list
    type(map) :: params = map() ! this is entirely valid
  end type
end module

program a
  use empty
  implicit none

  type(parameter_list) :: var

  print *, var%params%j, var%params%i, var%params%i1, var%params%i2
end program

It prints "-1 4 0 0" instead of "-1 3 4 5" (gfortran prints it right)

  1. Following code does not compile:
module m
  implicit none

  type :: t1

  contains

    procedure :: isEqual   => t1_tbp

  end type

  type, extends(t1) :: t2
    integer :: a = 0
  end type

  type(t2), parameter, public :: x = t2()

  contains

    logical function t1_tbp(self)
      class(t1), intent(in) :: self
    end function
end module

compiler complains:

F90-S-0091-Constant expression of wrong data type (m.f90: 16)
F90-S-0066-Too few data constants in initialization statement (m.f90: 16)
  0 inform,   0 warnings,   2 severes, 0 fatal for m
  0 inform,   0 warnings,   2 severes, 0 fatal for m

while gfortran compiles it fine.

@pawosm-arm

This comment has been minimized.

Contributor

pawosm-arm commented Nov 13, 2018

This issue seems to be fixed by commit 8dc5b8b and now cp2k's dbcsr_data_types.f90 compiles (without warnings). However, cp2k still cannot be compiled as the compiler suffers from segfault in flang1 later on trying to compile src/dbcsr/block/dbcsr_work_operations.F:

Program received signal SIGSEGV, Segmentation fault.
mkexpr1 (stkptr=0x2) at tools/flang1/flang1exe/semutil.c:971
971       switch (SST_IDG(stkptr)) {
(gdb) bt
#0  mkexpr1 (stkptr=0x2) at tools/flang1/flang1exe/semutil.c:971
#1  0x00000000006319e0 in mkexpr (stkptr=0x2) at tools/flang1/flang1exe/semutil.c:949
#2  0x000000000064f6e4 in _constructf90 (base_id=10203, in_indexast=<optimized out>, in_array=false, aclp=0x81e9a8) at tools/flang1/flang1exe/semutil2.c:2705
#3  0x000000000064efb0 in _constructf90 (base_id=10163, in_indexast=<optimized out>, in_array=false, aclp=0x81e8e8) at tools/flang1/flang1exe/semutil2.c:2905
#4  0x0000000000641468 in constructf90 (arr=<optimized out>, aclp=<optimized out>) at tools/flang1/flang1exe/semutil2.c:3142
#5  0x0000000000646700 in init_derived_w_acl (in_sptr=<optimized out>, sconst=0x81e8e8) at tools/flang1/flang1exe/semutil2.c:6114
#6  0x00000000005d51dc in semant3 (rednum=<optimized out>, top=0xb38d78) at tools/flang1/flang1exe/semant3.c:436
#7  0x0000000000564a88 in _parser () at tools/flang1/flang1exe/parser.c:312
#8  0x0000000000564570 in parser () at tools/flang1/flang1exe/parser.c:162
#9  0x00000000005485d8 in main (argc=<optimized out>, argv=<optimized out>) at tools/flang1/flang1exe/main.c:222
(gdb)

I propose to close this ticket as I opened new one (#615) for the segfault issue.

@nncarlson

This comment has been minimized.

nncarlson commented Nov 17, 2018

Okay with me, the OP.

@nncarlson nncarlson closed this Nov 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment