void foo (void) { int i = 0, j = 0; #pragma omp for firstprivate (j) /* { dg-error "j is private in outer context" } */ for (i = 0; i < 10; i++) j++; }
int bar (void) { int i, j; #pragma omp for lastprivate (j) /* { dg-error "j is private in outer context" } */ for (i = 0; i < 10; i++) j = i; return j; } ICEs in build_outer_var_ref, but should instead report diagnostics (violates the 2.8.3.{4,5} restrictions (the non-language specific one)). I think we need to handle the case where in build_outer_var_ref we are not parallel context, decl is not global var and there is no outer context, because e.g. integer :: j j = 6 !$omp parallel num_threads (4) call foo (j) !$omp end parallel if (j.ne.6+16) call abort end subroutine foo (j) integer :: i, j !$omp do firstprivate (j) lastprivate (j) do i = 1, 16 if (i.eq.16) j = j + i end do end subroutine foo is IMHO a valid testcase (2.8.1.2 says that the dummy arguments inherit data-sharing attributes of the associated actual argument and in this testcase the actual argument is shared). So, gimplify.c should check if it knows something about the variable in the outer contexts (if any) if it is not a global var and if we can prove it is say GOVD_LOCAL or for some other reason we know the variable is really private, we should issue error, if we can't prove it (as e.g. in the case of Fortran dummy args (be it REFERENCE_TYPE or dereferences of a pointer var for optional arguments), just let build_outer_var_ref access the outer variable and trust the user that the var is shared, not private. -- Summary: ICE on invalid firstprivate/lastprivate Product: gcc Version: 4.2.0 Status: UNCONFIRMED Keywords: openmp Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jakub at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27416