Bug 755757

Summary: Using ANY with a mask containing an overloaded == operator crashes gfortran 4.6
Product: [Fedora] Fedora Reporter: Karl <kaiserkarl31>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: medium    
Version: 15CC: aravindvijayan224185, jakub
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-11-24 11:12:30 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
Program to reproduce segmentation fault / internal compiler error none

Description Karl 2011-11-21 23:43:58 UTC
Created attachment 534883 [details]
Program to reproduce segmentation fault / internal compiler error

Description of problem:
Using a construct like the following:
  IF ( ANY( A == B ) ) THEN
    ...
  END IF
will crash gfortran 4.6.1 if A and B are derived types and the == operator has been overloaded with a function that compares the two.

Version-Release number of selected component (if applicable):
GNU Fortran (GCC) 4.6.1 20110908 (Red Hat 4.6.1-9)

How reproducible:
Easily

Steps to Reproduce:
1. Make a derived type with two integers bound to it
2. Define an elemental function that accepts two members of that derived type that compares both components and returns .TRUE. if they are the same and .FALSE. if either one is different
3. Define an overloaded == operator that uses this function
4. Write something like "if ( any(h == g) ) then ..." somewhere, where h is an array (rank 1 object) of the derived type and g is a rank-0 object ("scalar") of the same type.
  
Actual results:
internal compiler error:  Segmentation fault

Expected results:
compiles as it would if h and g were integers instead of derived types

Additional info:
Attached example program (29 lines) reproduces the problem on my system.

Comment 1 Aravind vijayan 2011-11-22 02:19:05 UTC
Hi Karl,
       As we know Segmentation fault is due to some memory errors , i am unaware about FORTRAN but while going through the code i saw something, 
   
   type (a), dimension(10) :: h //The dimension of array is specified
   type (a) :: g               // but there is no memory allocation here 

would you please check this?

Comment 2 Aravind vijayan 2011-11-22 02:46:12 UTC

 elemental function equal_a (x,y) result (same)
    
     +  type (a), intent(in) :: x, y
     
       logical :: same
      if ( x%i == y%i .and. x%j == y%j ) then
         same = .TRUE.
      else
         same = .FALSE.
      end if
   end function equal_a


changing class to type compiled the code without segmentation fault....

Comment 3 Karl 2011-11-22 14:26:50 UTC
If using a polymorphic type here is wrong, the compiler should toss up an error (not segfault).  I can see where it doesn't really make sense to use a polymorphic type for the comparison operator (==) here (good point), but there's still a bug in the compiler for this construct.

Comment 4 Aravind vijayan 2011-11-23 02:28:54 UTC
Yes, i think i get your point,and the gfortran updated to:

GNU Fortran (GCC) 4.6.2 20111027 (Red Hat 4.6.2-1)

please update your compiler, would you please send a feed back after updating your compiler , thanks for a fair report.



-- 
Fedora Bugzappers volunteer triage team
https://fedoraproject.org/wiki/BugZappers

Comment 5 Jakub Jelinek 2011-11-24 11:12:30 UTC
Tracking this upstream.