[Flang] preprocessor bug with OpenMP sentinels in fixed-format source
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When fixed-format .F source code with OpenMP directives exists, but OpenMP isn't used, Flang isn't preprocessing the source code correctly. This impacts CMake + Ninja, with the root cause seeming to be a bug in Flang revealed by that common use case.
The bottom of this issue has minimal reproducer code. This occurs across all versions of LLVM Flang I've tried over a couple years.
```sh
src = "flang_mwe.F"
pp = "flang_mwe-pp.f"
flang -c $src # OK
flang -cpp -E $src -o $pp # emits warning
flang -c $pp # errors
```
### Expected
1. direct compile succeeds
2. preprocess succeeds
3. compile succeds
The expected source preprocessed snippet is the following. This is like what Gfortran correctly generates.
```fortran
call mysub(a, b
!$ & ,dummy
& )
```
### Actual
1. Direct compile succeeds.
2. Preprocess gives warning and incorrect syntax generated
3. Compile of preprocessed file fails with unmatched parentheses.
The Flang preprocess step generates this syntax with a warning, which is incorrect generated syntax.
```fortran
call mysub(a, b
!$ &,dummy&
)
```
## file "flang_mwe.F"
```fortran
program mwe
call mysub(a, b
!$ & ,dummy
& )
contains
subroutine mysub(a, b, dummy)
real :: a, b
real, optional :: dummy
end subroutine mysub
end program
```
Contributor guide
Research direction
Start by running the commands with flang_mwe.F and compare Flang's preprocessed output with the expected snippet and the GFortran-like form shown in the issue. Trace fixed-format preprocessing of the OpenMP sentinel and continuation lines; done means preprocessing emits valid syntax and the resulting file compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, fortran
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100