Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flang][OpenMP] Compilation error when declarations within threadprivate directive and explicit declarations #106021

Open
ohno-fj opened this issue Aug 25, 2024 · 3 comments

Comments

@ohno-fj
Copy link

ohno-fj commented Aug 25, 2024

Version of flang-new : 20.0.0(3496245ed3d0b4d24444260da77dcdb93512fb5a/AArch64

Variables defined with threadprivate directive and explicit declaration result in a compilation-time error.
When threadprivate directive is removed, the compilation succeeds

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snggy156_.f90:

subroutine s1
  integer omp_get_thread_num
  save p1,x1
!$omp threadprivate (p1)
!$omp threadprivate (x1)
  integer x1
  procedure(ss1),pointer::p1
  interface
     subroutine ss1(i)
     end subroutine ss1
     subroutine ss2(i)
     end subroutine ss2
  end interface
!$omp parallel private(k)
  if (omp_get_thread_num() ==1) then
     p1=> ss1
  else
     p1=> ss2
  end if
  call p1(k)
  if (omp_get_thread_num() ==1) then
     if (k/=1) print *,101
  else
     if (k/=2) print *,102
  endif
!$omp end parallel
end subroutine s1

program main
  call s1
  print *,'pass'
end program main

subroutine ss1(i)
  i=1
end subroutine ss1

subroutine ss2(i)
  i=2
end subroutine ss2
$ flang-new -fopenmp snggy156_1.f90
error: Semantic errors in snggy156_.f90
./snggy156_.f90:6:11: error: The type of 'x1' has already been implicitly declared
    integer x1
            ^^
./snggy156_.f90:3:11: Implicit declaration of 'x1'
    save p1,x1
            ^^
./snggy156_.f90:7:27: error: The interface for procedure 'p1' has already been declared
    procedure(ss1),pointer::p1
                            ^^
./snggy156_.f90:3:8: Implicit declaration of 'p1'
    save p1,x1
         ^^
$
$ gfortran -fopenmp snggy156_.f90; ./a.out
 pass
$
$ ifort -qopenmp -diag-disable=10448 snggy156_.f90
snggy156_.f90(6): error #6415: This name cannot be assigned this data type because it conflicts with prior uses of the name.
  [X1]
  integer x1
----------^
snggy156_.f90(7): error #6406: Conflicting attributes or multiple declaration of name.   [P1]
  procedure(ss1),pointer::p1
--------------------------^
snggy156_.f90(16): error #6424: This name has already been used as an external subroutine name.   [SS1]
     p1=> ss1
----------^
snggy156_.f90(16): error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute.   [SS1]
     p1=> ss1
----------^
snggy156_.f90(18): error #6424: This name has already been used as an external subroutine name.   [SS2]
     p1=> ss2
----------^
snggy156_.f90(18): error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute.   [SS2]
     p1=> ss2
----------^
snggy156_.f90(20): error #6419: This scalar name is invalid in this context.   [P1]
  call p1(k)
-------^
compilation aborted for snggy156_.f90 (code 1)
$
@ohno-fj ohno-fj added openmp flang Flang issues not falling into any other category labels Aug 25, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 25, 2024

@llvm/issue-subscribers-openmp

Author: None (ohno-fj)

``` Version of flang-new : 20.0.0(3496245/AArch64 ```

Variables defined with threadprivate directive and explicit declaration result in a compilation-time error.
When threadprivate directive is removed, the compilation succeeds

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snggy156_.f90:

subroutine s1
  integer omp_get_thread_num
  save p1,x1
!$omp threadprivate (p1)
!$omp threadprivate (x1)
  integer x1
  procedure(ss1),pointer::p1
  interface
     subroutine ss1(i)
     end subroutine ss1
     subroutine ss2(i)
     end subroutine ss2
  end interface
!$omp parallel private(k)
  if (omp_get_thread_num() ==1) then
     p1=> ss1
  else
     p1=> ss2
  end if
  call p1(k)
  if (omp_get_thread_num() ==1) then
     if (k/=1) print *,101
  else
     if (k/=2) print *,102
  endif
!$omp end parallel
end subroutine s1

program main
  call s1
  print *,'pass'
end program main

subroutine ss1(i)
  i=1
end subroutine ss1

subroutine ss2(i)
  i=2
end subroutine ss2
$ flang-new -fopenmp snggy156_1.f90
error: Semantic errors in snggy156_.f90
./snggy156_.f90:6:11: error: The type of 'x1' has already been implicitly declared
    integer x1
            ^^
./snggy156_.f90:3:11: Implicit declaration of 'x1'
    save p1,x1
            ^^
./snggy156_.f90:7:27: error: The interface for procedure 'p1' has already been declared
    procedure(ss1),pointer::p1
                            ^^
./snggy156_.f90:3:8: Implicit declaration of 'p1'
    save p1,x1
         ^^
$
$ gfortran -fopenmp snggy156_.f90; ./a.out
 pass
$
$ ifort -qopenmp -diag-disable=10448 snggy156_.f90
snggy156_.f90(6): error #<!-- -->6415: This name cannot be assigned this data type because it conflicts with prior uses of the name.
  [X1]
  integer x1
----------^
snggy156_.f90(7): error #<!-- -->6406: Conflicting attributes or multiple declaration of name.   [P1]
  procedure(ss1),pointer::p1
--------------------------^
snggy156_.f90(16): error #<!-- -->6424: This name has already been used as an external subroutine name.   [SS1]
     p1=&gt; ss1
----------^
snggy156_.f90(16): error #<!-- -->6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute.   [SS1]
     p1=&gt; ss1
----------^
snggy156_.f90(18): error #<!-- -->6424: This name has already been used as an external subroutine name.   [SS2]
     p1=&gt; ss2
----------^
snggy156_.f90(18): error #<!-- -->6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute.   [SS2]
     p1=&gt; ss2
----------^
snggy156_.f90(20): error #<!-- -->6419: This scalar name is invalid in this context.   [P1]
  call p1(k)
-------^
compilation aborted for snggy156_.f90 (code 1)
$

@EugeneZelenko EugeneZelenko added flang:frontend flang:openmp and removed openmp flang Flang issues not falling into any other category labels Aug 25, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 25, 2024

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 20.0.0(3496245/AArch64 ```

Variables defined with threadprivate directive and explicit declaration result in a compilation-time error.
When threadprivate directive is removed, the compilation succeeds

The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.

snggy156_.f90:

subroutine s1
  integer omp_get_thread_num
  save p1,x1
!$omp threadprivate (p1)
!$omp threadprivate (x1)
  integer x1
  procedure(ss1),pointer::p1
  interface
     subroutine ss1(i)
     end subroutine ss1
     subroutine ss2(i)
     end subroutine ss2
  end interface
!$omp parallel private(k)
  if (omp_get_thread_num() ==1) then
     p1=&gt; ss1
  else
     p1=&gt; ss2
  end if
  call p1(k)
  if (omp_get_thread_num() ==1) then
     if (k/=1) print *,101
  else
     if (k/=2) print *,102
  endif
!$omp end parallel
end subroutine s1

program main
  call s1
  print *,'pass'
end program main

subroutine ss1(i)
  i=1
end subroutine ss1

subroutine ss2(i)
  i=2
end subroutine ss2
$ flang-new -fopenmp snggy156_1.f90
error: Semantic errors in snggy156_.f90
./snggy156_.f90:6:11: error: The type of 'x1' has already been implicitly declared
    integer x1
            ^^
./snggy156_.f90:3:11: Implicit declaration of 'x1'
    save p1,x1
            ^^
./snggy156_.f90:7:27: error: The interface for procedure 'p1' has already been declared
    procedure(ss1),pointer::p1
                            ^^
./snggy156_.f90:3:8: Implicit declaration of 'p1'
    save p1,x1
         ^^
$
$ gfortran -fopenmp snggy156_.f90; ./a.out
 pass
$
$ ifort -qopenmp -diag-disable=10448 snggy156_.f90
snggy156_.f90(6): error #<!-- -->6415: This name cannot be assigned this data type because it conflicts with prior uses of the name.
  [X1]
  integer x1
----------^
snggy156_.f90(7): error #<!-- -->6406: Conflicting attributes or multiple declaration of name.   [P1]
  procedure(ss1),pointer::p1
--------------------------^
snggy156_.f90(16): error #<!-- -->6424: This name has already been used as an external subroutine name.   [SS1]
     p1=&gt; ss1
----------^
snggy156_.f90(16): error #<!-- -->6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute.   [SS1]
     p1=&gt; ss1
----------^
snggy156_.f90(18): error #<!-- -->6424: This name has already been used as an external subroutine name.   [SS2]
     p1=&gt; ss2
----------^
snggy156_.f90(18): error #<!-- -->6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET at
tribute, or it must have the POINTER attribute.   [SS2]
     p1=&gt; ss2
----------^
snggy156_.f90(20): error #<!-- -->6419: This scalar name is invalid in this context.   [P1]
  call p1(k)
-------^
compilation aborted for snggy156_.f90 (code 1)
$

@luporl
Copy link
Contributor

luporl commented Sep 11, 2024

The problem is the declaration of a variable type after !$omp threadprivate, as the reduced test below shows:

subroutine s1
  save x1
  !$omp threadprivate (x1)
  integer x1
end subroutine

Gfortran allows it, while ifort and ifx don't. I couldn't find anything in OpenMP standard that allows or disallows it.
Do we want to support this kind of declaration on flang?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants