Bug 35130 - OpenMP: Private variable passed to subroutine
Summary: OpenMP: Private variable passed to subroutine
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Jakub Jelinek
URL:
Keywords: openmp, wrong-code
: 35131 35133 36351 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-02-07 22:22 UTC by Tobias Burnus
Modified: 2008-05-28 07:18 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-02-11 16:11:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-02-07 22:22:43 UTC
As reported by Ignacio Fernández Galván, the following program prints with "gfortran -fopenmp" 0.0 instead of 42.0. Without -fopenmp or using, e.g., ifort or sunf95 42.0 is printed.

See also http://gcc.gnu.org/ml/fortran/2008-02/msg00058.html

I believe the program is valid, compare also
http://www.openmp.org/pipermail/omp/2006/000532.html

PROGRAM Outer
 IMPLICIT NONE
 REAL, DIMENSION(20) :: A
 INTEGER :: k
 A = 0.0
!$OMP PARALLEL DO PRIVATE(k)
 DO k=1,SIZE(A)
   CALL Inner(k)
 END DO
!$OMP END PARALLEL DO
 print *, A
CONTAINS
 SUBROUTINE Inner(i)
   IMPLICIT NONE
   INTEGER :: i
   A(i) = 42
 END SUBROUTINE Inner
END PROGRAM Outer
Comment 1 Jakub Jelinek 2008-02-07 22:44:08 UTC
*** Bug 35133 has been marked as a duplicate of this bug. ***
Comment 2 Jakub Jelinek 2008-02-07 22:44:20 UTC
*** Bug 35131 has been marked as a duplicate of this bug. ***
Comment 3 Francois-Xavier Coudert 2008-02-10 15:37:46 UTC
I have managed to reduce it a bit more, and it does not involve passing the loop variable as an argument:

program outer
  integer k, a(1)
  a = 0.0
!$OMP PARALLEL DO
  do k = 1, 1
    call inner
  end do
!$OMP END PARALLEL DO
 print *, a(1)

contains
  subroutine inner
    a(1) = 42
  end subroutine inner
end program outer

From the tree dump, I've made the following C testcase which also exhibits the same bug:

$ cat u.c 
int main (void)
{
  int a[1], k;
  void inner (void) { a[0] = 42; }

  a[0] = 0;

  #pragma omp parallel
  #pragma omp for private(k) nowait
  for (k = 1; k <= 1; k = k + 1)
    inner ();

  __builtin_printf ("%d\n", a[0]);
  return 0;
}

$ gcc -fopenmp u.c && ./a.out
0


There is no OpenMP component, and since I'm not sure the C code I have created is valid, I leave this bug as "fortran" for now... but I think it's a generic issue of contained functions.
Comment 4 Jakub Jelinek 2008-02-15 17:37:27 UTC
Subject: Bug 35130

Author: jakub
Date: Fri Feb 15 17:36:43 2008
New Revision: 132349

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132349
Log:
	PR middle-end/35130
	* tree-nested.c (convert_call_expr): Put FRAME.* vars into
	OMP_CLAUSE_SHARED rather than OMP_CLAUSE_FIRSTPRIVATE clause.

	* testsuite/libgomp.fortran/pr35130.f90: New test.
	* testsuite/libgomp.c/pr35130.c: New test.

Added:
    trunk/libgomp/testsuite/libgomp.c/pr35130.c
    trunk/libgomp/testsuite/libgomp.fortran/pr35130.f90
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-nested.c
    trunk/libgomp/ChangeLog

Comment 5 Jakub Jelinek 2008-02-15 17:50:32 UTC
Fixed on the trunk.
Comment 6 Uroš Bizjak 2008-02-15 18:10:11 UTC
Fixed for real.
Comment 7 Andrew Pinski 2008-05-28 07:18:03 UTC
*** Bug 36351 has been marked as a duplicate of this bug. ***