Bug 34262 - MVBITS does not work for arrays
Summary: MVBITS does not work for arrays
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 minor
Target Milestone: ---
Assignee: Tobias Burnus
URL:
Keywords: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-11-28 12:21 UTC by phl
Modified: 2007-11-29 15:00 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-28 14:20:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description phl 2007-11-28 12:21:25 UTC
hades [TEST] cat bug-mvbits.f90 
program main
  implicit none

  integer :: a( 1 ), b( 1 )
  integer :: x, y

  a = 1
  b = 0
  x = 1
  y = 0

  call mvbits (a, 0, 1, b, 1)
  call mvbits (x, 0, 1, y, 1)

  write (*, *) 'a: ', a
  write (*, *) 'x: ', x
  write (*, *)
  write (*, *) 'b: ', b
  write (*, *) 'y: ', y
  write (*, *)

  if ( all (b == y) ) then
     write (*, *) 'GOOD:  b == y'
  else
     write (*, *) 'BAD:  b /= y'
  end if

end program main

hades [TEST] ./a.out 
 a:            1
 x:            1

 b:            0
 y:            2

 BAD:  b /= y

hades [TEST] gfortran --version
GNU Fortran (GCC) 4.2.1 (Ubuntu 4.2.1-5ubuntu4)
Copyright (C) 2007 Free Software Foundation, Inc.


It does not work for MacOS PowerPC either, same output. The version
I used ton my Mac was:

epsilon [TEST] gfortran --version      
GNU Fortran (GCC) 4.3.0 20071017 (experimental) [trunk revision 129405]
Copyright (C) 2007 Free Software Foundation, Inc.
Comment 1 Tobias Burnus 2007-11-28 14:09:34 UTC
For a scalars x and y:
   _gfortran_mvbits_i4 (&x, &C.860, &C.861, &y, &C.862);
for an arrays a and b:
   _gfortran_mvbits_i4 (&parm.2, &C.872, &C.873, &parm.3, &C.875);

It actually does not surprise me that this does not work if one replaces the integer variable by a "struct array1_integer(kind=4)".
Comment 2 Tobias Burnus 2007-11-28 14:20:53 UTC
The following fixes it, but I need to check for unwanted side effects:

Index: intrinsic.c
===================================================================
--- intrinsic.c (revision 130489)
+++ intrinsic.c (working copy)
@@ -104,6 +104,7 @@ gfc_get_intrinsic_sub_symbol (const char
   gfc_symbol *sym;

   gfc_get_symbol (name, gfc_intrinsic_namespace, &sym);
+  sym->attr.elemental = 1;
   sym->attr.always_explicit = 1;
   sym->attr.subroutine = 1;
   sym->attr.flavor = FL_PROCEDURE;
Comment 3 Tobias Burnus 2007-11-29 14:57:01 UTC
Subject: Bug 34262

Author: burnus
Date: Thu Nov 29 14:56:48 2007
New Revision: 130513

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130513
Log:
2007-11-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34262
        * intrinsic.c (gfc_get_intrinsic_sub_symbol): Add comment.
        (gfc_intrinsic_sub_interface): Copy elemental state if needed.
        * iresolve.c (gfc_resolve_mvbits): Mark procedure as elemental.

2007-11-29  Tobias Burnus  <burnus@net-b.de>

        PR fortran/34262
        * gfortran.dg/mvbits_3.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/mvbits_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Tobias Burnus 2007-11-29 15:00:13 UTC
Fixed on the trunk (4.3.0). I do not intent to backport the patch to 4.2.x and 4.1.x, but I can be convinced to do so.