[Flang] Missing error for free form statement continuation
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
According to the Fortran 2023 standard, the following program should be rejected. However, Flang accepts it.
* 6.3.2.4 Free form statement continuation
> The character "&" is used to indicate that the statement is continued on the next line that is not a comment line. Comment lines cannot be continued; an "&" in a comment has no effect. Comments may occur within a continued statement. When used for continuation, the "&" is not part of the statement. No line shall contain a single "&" as the only nonblank character or as the only nonblank character before an "!" that initiates a comment.
>
> If a noncharacter context is to be continued, an "&" shall be the last nonblank character on the line, or the last nonblank character before an "!". There shall be a later line that is not a comment; the statement is continued on the next such line. If the first nonblank character on that line is an "&", the statement continues at the next character position following that "&"; otherwise, it continues with the first character position of that line.
### Reproducer
* test.f90
```fortran
subroutine test2
&
end subroutine test2
subroutine test3
k = 1
& + 1
print *, k
end subroutine test3
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 2301475676b208c555273e7c1ac5d4470d5ee70e)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -c -pedantic
$
```
## Non-problematic Conditions
The issue does not occur under the following case:
```
$ cat test2.f90
subroutine test1
& 1
end subroutine test1
$ flang test2.f90 -c
error: Could not parse test2.f90
test2.f90:2:5: error: expected end of statement
& 1
^
test2.f90:1:1: in the context: SUBROUTINE subprogram
subroutine test1
^
```
## 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 -c
f951: Warning: '&' not allowed by itself in line 2
test.f90:7:3:
7 | & + 1
| 1
Error: Invalid character in name at (1)
```
* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
$ ifx -O0 test.f90 -c
test.f90(7): error #5082: Syntax error, found '&' when expecting one of: ; TYPE MODULE ELEMENTAL IMPURE NON_RECURSIVE ...
& + 1
---^
test.f90(7): error #6252: This format specifier is invalid. [1]
& + 1
---^
compilation aborted for test.f90 (code 1)
```
* NVIDIA Fortran
```console
$ nvfortran --version
nvfortran 26.5-0 linuxarm64 target on aarch64 Linux -tp neoverse-v2
NVIDIA Compilers and Tools
Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
$ nvfortran test.f90 -c
NVFORTRAN-S-0290-Unexpected continuation line (test.f90: 2)
0 inform, 0 warnings, 1 severes, 0 fatal for test2
NVFORTRAN-S-0290-Unexpected continuation line (test.f90: 7)
0 inform, 0 warnings, 1 severes, 0 fatal for test3
```
Contributor guide
Research direction
Start by reproducing the failure with test.f90 and the shown flang --version and flang test.f90 -c -pedantic commands. Trace the Flang parsing of free-form continuation lines, then add coverage for the standalone '&' cases in the compiler's existing parser tests. Done means both invalid examples are rejected while the non-problematic continuation remains accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100