flang icon indicating copy to clipboard operation
flang copied to clipboard

contiguous and save conflict

Open ajmay81 opened this issue 6 years ago • 5 comments

There appears to be some inappropriate policing of save and contiguous attributes which causes compilation to fail:

> cat test.f90
module test
 implicit none
 integer, dimension(:), pointer, contiguous, save :: ptr
end module
> flang -c test.f90 
F90-S-0134-Illegal attribute - conflict with save (test.f90: 3)
> gfortran -c test.f90
> ifort -c test.f90
>

ajmay81 avatar Feb 18 '19 13:02 ajmay81

There's a similar error for contiguous and asynchronous:

> cat test.f03
subroutine test
  implicit none
  integer, dimension(:), pointer, contiguous, asynchronous :: x
end subroutine test
> flang -c test.f03
F90-S-0134-Illegal attribute - conflict with asynchronous (test.f03: 3)
  0 inform,   0 warnings,   1 severes, 0 fatal for test
> gfortran -c test.f03
> ifort -c test.f03

Not sure whether this should be a separate issue as it seems closely related.

smparker avatar Mar 13 '19 22:03 smparker

@smparker Shane, I'll add this test case to our internal tracking. If they're separate issues, we'll handle that on our end. Thanks for the additional information.

gklimowicz avatar Mar 14 '19 17:03 gklimowicz

Funny finding I've made: if you change order of the CONTIGUOUS and SAVE attribute (namely, SAVE, CONTIGUOUS instead of CONTIGUOUS, SAVE) this code compiles!

pawosm-arm avatar Dec 23 '20 12:12 pawosm-arm

Finally, I've found an easy patch for this issue, at least for the CONTIGUOUS attribute:

diff --git a/tools/flang1/flang1exe/semant.c b/tools/flang1/flang1exe/semant.c
index 747b7a1b..2b098ee7 100644
--- a/tools/flang1/flang1exe/semant.c
+++ b/tools/flang1/flang1exe/semant.c
@@ -291,7 +291,7 @@ static struct {
        ET_B(ET_VALUE) | ET_B(ET_VOLATILE) | ET_B(ET_SHARED) |
        ET_B(ET_ASYNCHRONOUS) | ET_B(ET_PROTECTED) | ET_B(ET_PINNED) |
        ET_B(ET_TEXTURE) | ET_B(ET_DEVICE) | ET_B(ET_MANAGED) |
-       ET_B(ET_IMPL_MANAGED))},
+       ET_B(ET_CONTIGUOUS) | ET_B(ET_IMPL_MANAGED))},
     {"target",
      ~(ET_B(ET_ACCESS) | ET_B(ET_ALLOCATABLE) | ET_B(ET_DIMENSION) |
        ET_B(ET_INTENT) | ET_B(ET_OPTIONAL) | ET_B(ET_SAVE) | ET_B(ET_VALUE) |

pawosm-arm avatar Dec 23 '20 14:12 pawosm-arm

The spurious conflict between CONTIGUOUS and ASYNCHRONOUS can be solved similarly by adding ET_B(ET_CONTIGUOUS) to expression in the et.no field for "asynchronous". The language standard does not seem to forbid this combination of attributes.

The et.no field for "contiguous" is currently 0, meaning that no other attribute conflicts with it, and no error is emitted as long as contiguous appears later in a declaration. In reality, besides asynchronous, several other attributes currently conflict with contiguous: external, intrinsic, parameter, automatic, static, shared, constant, texture, pass, and nopass. It probably makes sense to set the et.no field for "contiguous" such that the compiler will report consistent error messages for these attributes regardless of the order of their appearance.

bryanpkc avatar Jan 20 '21 20:01 bryanpkc