<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/142325>142325</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Compilation error of unlimited-format-item specified in FORMAT statement with double parentheses
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ohno-fj
      </td>
    </tr>
</table>

<pre>
    ```
Version of flang : 21.0.0(9513284f25545029de68f7e09bc5c1606636c489)/AArch64
```

In the attached program (`unlimited_format_item011.f90`), `unlimited-format-item : *(G0," ",G0,",")` specified in `FORMAT statement` with double parentheses results in a compilation error.  

Compilation ends normally in the following cases:  
- do not use `unlimited-format-item`  
  see `unlimited_format_item021.f90` below.  
- format statement with one parenthesis  
  see `unlimited_format_item031.f90` below.  

>From the above, when `FORMAT statement with double parentheses` or `unlimited-format-item` is used alone, compilation ends normally.  
It seems to be a problem when the two are used together.

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

unlimited_format_item011.f90:
```fortran
subroutine sub
 integer::aa,bb
  character(20)::ch,bh
  logical::ll
  ll=.true.
  aa=10
 bb=20
  ch = "black"
  bh = "blue"
 open(100,file="fort.03",action="write")
 write(100,10)ll,aa,ch,bb,bh,aa,ch,bb,bh
10 format((l1," ",*(G0," ",G0,",")))
  close(100)
end subroutine sub

program main
  call sub
  print*,"pass"
end program main
```

```
$ flang unlimited_format_item011.f90
error: Could not parse unlimited_format_item011.f90
./unlimited_format_item011.f90:12:11: error: expected ')'
  10 format((l1," ",*(G0," ",G0,",")))
 ^
./unlimited_format_item011.f90:12:4: in the context: FORMAT statement
 10 format((l1," ",*(G0," ",G0,",")))
 ^
./unlimited_format_item011.f90:12:1: in the context: execution part construct
  10 format((l1," ",*(G0," ",G0,",")))
 ^
./unlimited_format_item011.f90:12:11: error: expected one of '+-'
  10 format((l1," ",*(G0," ",G0,",")))
 ^
./unlimited_format_item011.f90:12:4: in the context: pointer assignment statement
  10 format((l1," ",*(G0," ",G0,",")))
 ^
./unlimited_format_item011.f90:12:1: in the context: execution part construct
  10 format((l1," ",*(G0," ",G0,",")))
 ^
$
```

```
$ gfortran unlimited_format_item011.f90; ./a.out
 pass
$
```

```
$ ifx unlimited_format_item011.f90; ./a.out
 pass
$
```

unlimited_format_item021.f90:
```fortran
subroutine sub
 integer::aa,bb
  character(20)::ch,bh
  logical::ll
  ll=.true.
  aa=10
 bb=20
  ch = "black"
  bh = "blue"
 open(100,file="fort.03",action="write")
 write(100,10)ll,aa,ch,bb,bh,aa,ch,bb,bh
10 format((l1," ",G0," ",G0,",",G0," ",G0,",",G0," ",G0,",",G0," ",G0,","))
 close(100)
end subroutine sub

program main
  call sub
 print*,"pass"
end program main
```

```
$ flang unlimited_format_item021.f90; ./a.out
 pass
$
```

unlimited_format_item031.f90:
```fortran
subroutine sub
 integer::aa,bb
  character(20)::ch,bh
  logical::ll
  ll=.true.
  aa=10
 bb=20
  ch = "black"
  bh = "blue"
 open(100,file="fort.03",action="write")
 write(100,10)ll,aa,ch,bb,bh,aa,ch,bb,bh
10 format(l1," ",*(G0," ",G0,","))
  close(100)
end subroutine sub

program main
  call sub
 print*,"pass"
end program main
```

```
$ flang unlimited_format_item031.f90; ./a.out
 pass
$
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWE2P2zgP_jXKRYgh03HGPuTgJm-KHl4ssCj2WsgyHasrW4Ykd6b_fkHZaZN2vrqYtnsYIMiMJZLiw4-HjqT3-jQg7lj-huWHlZxCZ93OdoNdtx9XtW0-79hWLB9R_YXOaztw2_LWyOHEWVZxSBORCAZFmacZFJsW8nyTCygb3BbtDYqyVrlKt2K7zbZqU5QMSgbHqnKq226YqC5PYKJ6N_DQIZchSNVhw0dnT072nEHBtmIajO51wOZDa10vwwcdsBdpmrRlNEG29_xScD0LrkkwOsygYlC8FQz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