llvm / llvm/llvm-project

[Flang][OpenMP] Incorrect execution results when continuation lines of OpenMP (free source form conditional compilation sentinel) and Fortran `free source form` are mixed

Open
#198,771 0 comments 0 reactions 0 assignees View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

This is a similar issue to #89559, which reported a compilation error. The compilation now succeeds, but the execution result is incorrect.

### Reproducer

* ompc_066_.f90

```fortran
program main
!$ i = 0
i = 1&
!$ +10 &
!$+100&
!$&+ 1000&
&+ 10000&
!$& +100000&
& +1000000

if(i .eq. 1111111) then
print *, 'OK'
else
print *, 'NG'
endif
end program main
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 3e20d3d3964a3a6ac5f882842c7716e2682d622f)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang -fopenmp ompc_066_.f90 && ./a.out
NG
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Adding a white space or an ampersand after the conditional compilation sentinel:
```diff
@@ -2,7 +2,7 @@
!$ i = 0
i = 1&
!$ +10 &
-!$+100&
+!$ +100&
!$&+ 1000&
&+ 10000&
!$& +100000&
```

## 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 -fopenmp ompc_066_.f90 && ./a.out
OK
```

* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.

$ ifx -qopenmp ompc_066_.f90 && ./a.out
OK
```

Contributor guide

Open the contributing guide

Research direction

The reproducer is ompc_066_.f90; first run flang -fopenmp ompc_066_.f90 && ./a.out and confirm it prints NG. Trace Flang's handling of mixed free-form continuation lines and OpenMP conditional-compilation sentinels, then verify the program prints OK under the same command.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.