[flang-commits] [flang] c2e41be - [flang][Parser] Add whitespace token after the sentinel in fixed form (#148825)
via flang-commits
flang-commits at lists.llvm.org
Tue Jul 15 08:39:37 PDT 2025
Author: Tom Eccles
Date: 2025-07-15T16:39:34+01:00
New Revision: c2e41be50f2cc3d1e99c30b1996b8873b05c4b0e
URL: https://github.com/llvm/llvm-project/commit/c2e41be50f2cc3d1e99c30b1996b8873b05c4b0e
DIFF: https://github.com/llvm/llvm-project/commit/c2e41be50f2cc3d1e99c30b1996b8873b05c4b0e.diff
LOG: [flang][Parser] Add whitespace token after the sentinel in fixed form (#148825)
Fixes #148386
The first time the line was classified (using
`Prescanner::ClassifyLine(const char *)`) the line was correctly
classified as a compiler directive. But then later on the token form is
invoked (`Prescanner::ClassifyLine(TokenSequence, Provenance)`). This
one incorrectly classified the line as a comment because there was no
whitespace token right after the sentinel. This fixes the issue by
ensuring this whitespace is added.
Added:
flang/test/Preprocessing/omp-sentinel-fixed-form.F
Modified:
flang/lib/Parser/prescan.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index ec894ab8513d2..3a9a475c365ee 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -179,7 +179,9 @@ void Prescanner::Statement() {
EmitChar(tokens, *sp);
}
if (inFixedForm_) {
- while (column_ < 6) {
+ // We need to add the whitespace after the sentinel because otherwise
+ // the line cannot be re-categorised as a compiler directive.
+ while (column_ <= 6) {
if (*at_ == '\t') {
tabInCurrentLine_ = true;
++at_;
diff --git a/flang/test/Preprocessing/omp-sentinel-fixed-form.F b/flang/test/Preprocessing/omp-sentinel-fixed-form.F
new file mode 100644
index 0000000000000..c8271682a5b92
--- /dev/null
+++ b/flang/test/Preprocessing/omp-sentinel-fixed-form.F
@@ -0,0 +1,21 @@
+! RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=50 %s | FileCheck %s
+
+#define OMP_TARGET .true.
+#define OMP_SIMD .false.
+ program test
+ implicit none
+ integer i,j,n
+ n = 100
+! CHECK: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: TARGET TEAMS DISTRIBUTE PARALLEL&
+! CHECK: !$OMP& DO) DEFAULT(TARGET TEAMS LOOP)
+!$omp metadirective
+!$omp& when(user={condition(OMP_TARGET.or.OMP_SIMD)}:
+!$omp& target teams distribute parallel do )
+!$omp& default(target teams loop)
+ do i=0,n
+ do j=0,n
+ write(*,*) "Test"
+ enddo
+ enddo
+ return
+ end program
More information about the flang-commits
mailing list