Issue 208362
Summary [Flang] Host association does not work for variables with the ASYNCHRONOUS/VOLATILE attribute in submodules
Labels flang:frontend
Assignees
Reporter yus3710-fj
    ## Summary

When a variable is declared in a module and it appears in ASYNCHRONOUS/VOLATILE statements in a submodule, its value is incorrect.

* 8.5.4 ASYNCHRONOUS attribute

> An object with the ASYNCHRONOUS attribute may be associated with an object that does not have the ASYNCHRONOUS attribute, including by use (14.2.2) or host association (19.5.1.4).

* 8.5.20 VOLATILE attribute

> A noncoarray object that has the VOLATILE attribute may be associated with an object that does not have the VOLATILE attribute, including by use (14.2.2) or host association (19.5.1.4).

* 19.5.1.4 Host association

> A derived-type definition, interface body, internal subprogram, module subprogram, or submodule has access to entities from its host as specified in 8.8. A host-associated variable is considered to have been previously declared; any other host-associated entity is considered to have been previously defined. In the case of an internal subprogram, the access is to the entities in its host instance. The accessed entities are identified by the same identifier and have the same attributes as in the host, except that a local entity may have the ASYNCHRONOUS attribute even if the host entity does not, and a noncoarray local entity may have the VOLATILE attribute even if the host entity does not.

> NOTE 1
>> A name that appears in an ASYNCHRONOUS or VOLATILE statement is not necessarily the name of a local variable. In an internal or module procedure, if a variable that is accessible via host association is specified in an ASYNCHRONOUS or VOLATILE statement, that host variable is given the ASYNCHRONOUS or VOLATILE attribute in the local scope.

### Reproducer

* test.f90

```fortran
module m1
integer::n=1,k=2
  interface
    module subroutine sub()
    end subroutine
  end interface
end
submodule (m1) submod
volatile::n
asynchronous::k
contains
  module subroutine sub()
 implicit none
  if (n/=1) print *,'Error n=',n
  if (k/=2) print *,'Error k=',k
  end subroutine
end submodule

use m1
call sub
print *,'pass'
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git ecdd6403fd213f90243a3d354d4db3483b89471f)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 && ./a.out 
 Error n= 0
 Error k= 0
 pass
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Using host association with internal subprograms instead of submodules:
 ```fortran
  subroutine m1
    integer::n=1,k=2
    call sub
  contains
 subroutine sub()
      implicit none
      volatile::n
 asynchronous::k
      if (n/=1) print *,'Error n=',n
      if (k/=2) print *,'Error k=',k
    end subroutine
  end subroutine

  call m1
  print *,'pass'
  end
  ```

## Other Compilers

* GFortran
  ```console
  $ gfortran --version
  GNU Fortran (GCC) 15.2.0
  Copyright (C) 2025 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
  $ gfortran test.f90 && ./a.out
 pass
  ```

* Intel Fortran
  ```console
  $ ifx --version
  ifx (IFX) 2025.3.2 20260112
  Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
  
  $ ifx -O0 test.f90 && ./a.out
   Error n=           0
 Error k=           0
   pass
  ```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to