From c7a59c0617898093f8aa35d139000a2c0b52a442 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Wed, 2 Apr 2025 13:26:48 -0700 Subject: [PATCH] [flang][preprocessor] Directive continuation must skip empty macros When a compiler directive continuation line starts with keyword macro names that have empty expansions, skip them. --- flang/lib/Parser/prescan.cpp | 2 +- flang/test/Preprocessing/directive-contin-with-pp.F90 | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp index 0df1e3e291923..809b728c47ffe 100644 --- a/flang/lib/Parser/prescan.cpp +++ b/flang/lib/Parser/prescan.cpp @@ -1325,7 +1325,7 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) { if (p >= limit_) { return nullptr; } - p = SkipWhiteSpace(p); + p = SkipWhiteSpaceIncludingEmptyMacros(p); if (*p == '!') { ++p; if (InCompilerDirective()) { diff --git a/flang/test/Preprocessing/directive-contin-with-pp.F90 b/flang/test/Preprocessing/directive-contin-with-pp.F90 index 6e84c2bde52f9..f1cfafe0bdf14 100644 --- a/flang/test/Preprocessing/directive-contin-with-pp.F90 +++ b/flang/test/Preprocessing/directive-contin-with-pp.F90 @@ -8,6 +8,7 @@ #define COMMENT ! #define OMP_START !$omp #define OMP_CONT !$omp& +#define EMPTY module m contains @@ -50,6 +51,11 @@ subroutine s1(x1, x2, x3, x4, x5, x6, x7) OMP_CONT reduction(+:x) do j3 = 1, n end do + +EMPTY !$omp parallel & +EMPTY !$omp do + do j4 = 1, n + end do end COMMENT & @@ -79,6 +85,9 @@ subroutine s3 !CHECK: !$OMP PARALLEL DO REDUCTION(+: x) !CHECK: DO j3=1_4,n !CHECK: END DO +!CHECK: !$OMP PARALLEL DO +!CHECK: DO j4=1_4,n +!CHECK: END DO !CHECK: END SUBROUTINE !CHECK: SUBROUTINE s2 !CHECK: END SUBROUTINE