public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97864] New: Homebrew Operator Overload ICE
@ 2020-11-16 20:33 everythingfunctional at protonmail dot com
  2020-11-16 23:02 ` [Bug fortran/97864] " dominiq at lps dot ens.fr
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: everythingfunctional at protonmail dot com @ 2020-11-16 20:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97864

            Bug ID: 97864
           Summary: Homebrew Operator Overload ICE
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: everythingfunctional at protonmail dot com
  Target Milestone: ---

I have a project that was building fine on linux, but when I switched to MacOS
and tried to build, I got an ICE. I was able to narrow it down to the operator
overload. I'm completely baffled as to why this would build and run just fine
on linux, but cause an ICE on MacOS.

Version info:

GNU Fortran (Homebrew GCC 10.2.0) 10.2.0
Copyright (C) 2020 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.

MWE (this could probably be simplified a bit more, but this seemed far enough):

module string_m
    implicit none
    private

    type, public :: VARYING_STRING
        private
        character(len=1), allocatable :: characters(:)
    end type

    interface operator(==)
        module procedure character_EQ_String
        module procedure string_EQ_String
    end interface

    interface CHAR
        module procedure stringToChar
    end interface

    public :: &
            operator(==), &
            CHAR, &
            VAR_STR
contains
    elemental function character_EQ_String(lhs, rhs) result(equals)
        character(len=*), intent(in) :: lhs
        type(VARYING_STRING), intent(in) :: rhs
        logical :: equals

        equals = lhs == char(rhs)
    end function character_EQ_String

    elemental function string_EQ_String(lhs, rhs) result(equals)
      type(VARYING_STRING), intent(in) :: lhs
      type(VARYING_STRING), intent(in) :: rhs
      logical :: equals

      equals = char(lhs) == char(rhs)
    end function

    pure function stringToChar(string) result(chars)
        type(VARYING_STRING), intent(in) :: string
        character(len=size(string%characters)) :: chars

        integer :: i
        integer :: length_input
        integer :: length_output

        length_output = len(chars)
        if (allocated(string%characters)) then
            length_input = size(string%characters)
            do concurrent (i = 1 : min(length_input, length_output))
                chars(i:i) = string%characters(i)
            end do
            if (length_input < length_output) then
                do concurrent (i = length_input+1 : length_output)
                    chars(i:i) = " "
                end do
            end if
        else
            do concurrent (i = 1 : length_output)
                chars(i:i) = " "
            end do
        end if
    end function stringToChar

    elemental function VAR_STR(char)
        character(len=*), intent(in) :: char
        type(VARYING_STRING) :: VAR_STR

        integer :: i
        integer :: length

        length = len(char)
        allocate(VAR_STR%characters(length))
        do concurrent (i = 1 : length)
            VAR_STR%characters(i) = char(i:i)
        end do
    end function VAR_STR
end module

module equal_test
    use string_m, only: VARYING_STRING, operator(==), char

    implicit none
    private

    public :: do_compare
contains
  pure function do_compare(first, second) result(result_)
    type(VARYING_STRING), intent(in) :: first
    type(VARYING_STRING), intent(in) :: second
    logical :: result_

    result_ = char(first) == char(second) ! works
    result_ = first == second ! works
    ! result_ = char(first) == second ! causes ice
  end function
end module

program main
  use equal_test, only: do_compare
  use string_m, only: var_str

  implicit none

  print *, do_compare(var_str("Hello"), var_str("World"))
end program main

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-11-26  1:09 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 20:33 [Bug fortran/97864] New: Homebrew Operator Overload ICE everythingfunctional at protonmail dot com
2020-11-16 23:02 ` [Bug fortran/97864] " dominiq at lps dot ens.fr
2020-11-17  5:57 ` everythingfunctional at protonmail dot com
2020-11-19 19:42 ` damian at sourceryinstitute dot org
2020-11-19 20:27 ` damian at sourceryinstitute dot org
2020-11-19 20:36 ` iains at gcc dot gnu.org
2020-11-19 20:49 ` everythingfunctional at protonmail dot com
2020-11-25 17:09 ` iains at gcc dot gnu.org
2020-11-25 20:05 ` everythingfunctional at protonmail dot com
2020-11-25 20:11 ` iains at gcc dot gnu.org
2020-11-25 20:26 ` fxcoudert at gcc dot gnu.org
2020-11-25 20:31 ` iains at gcc dot gnu.org
2020-11-25 20:35 ` fxcoudert at gcc dot gnu.org
2020-11-25 20:37 ` fxcoudert at gcc dot gnu.org
2020-11-25 20:43 ` iains at gcc dot gnu.org
2020-11-25 20:45 ` fxcoudert at gcc dot gnu.org
2020-11-26  1:09 ` iains at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).