[Flang][OpenMP] Compilation error for a continuation line that has no white space after a directive sentinel
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
According to the OpenMP 6.0 specification, initial directive lines must have a space after the sentinel. However, there seems no such restriction on continuation lines.
* 5.1.1 Free Source Form Directives
> The sentinel can appear in any column as long as it is preceded only by white space. It must appear as a single word with no intervening white space. Fortran free form line length and white space rules apply to the directive line. The syntax that allows white space to be optional has been deprecated. Initial directive lines must have a space after the sentinel. The initial line of a directive must not be a continuation line for a base language statement. Fortran free form continuation rules apply. Thus, continued directive lines must have an ampersand (&) as the last non-blank character on the line, prior to any comment placed inside the directive; continuation directive lines can have an ampersand after the directive sentinel with optional white space before and after the ampersand.
> Comments may appear on the same line as a directive. The exclamation point (!) initiates a comment. The comment extends to the end of the source line and is ignored. If the first non-blank character after the directive sentinel is an exclamation point, the line is ignored.
### Reproducer
* test.f90
```fortran
program main
integer :: x
!$omp parallel &
!$ompdo
do i=1,3
x = i
end do
print *, "pass"
end program main
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git f95ccbae8bd70e56e31fc04d6307d317212b7fbc)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
error: Could not scan test.f90
test.f90:4:16: error: bad character ('&') in Fortran token
!$omp parallel &
^
```
## Non-problematic Conditions
The issue does not occur under the following conditions:
* Putting a white space after the directive sentinel:
```diff
@@ -2,7 +2,7 @@
integer :: x
!$omp parallel &
-!$ompdo
+!$omp do
do i=1,3
x = i
end do
```
## 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 -fopenmp && ./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 -qopenmp && ./a.out
pass
```
Contributor guide
Assessment
This issue has not been assessed yet.