[flang-commits] [flang] [flang][preprocessor] Fix handling of #line before free-form continua… (PR #100178)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Jul 23 11:51:20 PDT 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/100178

…tion

See new test.  A #line (or #) directive after a line ending with & and before its continuation shouldn't elicit an error about mismatched parentheses.

Fixes https://github.com/llvm/llvm-project/issues/100073.

>From a2903a800bcc62fb8c7a1a8537400aea024a876f Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 23 Jul 2024 11:42:22 -0700
Subject: [PATCH] [flang][preprocessor] Fix handling of #line before free-form
 continuation

See new test.  A #line (or #) directive after a line ending with &
and before its continuation shouldn't elicit an error about
mismatched parentheses.

Fixes https://github.com/llvm/llvm-project/issues/100073.
---
 flang/lib/Parser/prescan.cpp                |  6 +++++-
 flang/test/Preprocessing/line-in-contin.F90 | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Preprocessing/line-in-contin.F90

diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index aa45548408aa9..c01d512b4653d 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -111,9 +111,13 @@ void Prescanner::Statement() {
     skipLeadingAmpersand_ |= !inFixedForm_;
     return;
   case LineClassification::Kind::PreprocessorDirective:
+    preprocessor_.Directive(TokenizePreprocessorDirective(), *this);
+    afterPreprocessingDirective_ = true;
+    // Don't set skipLeadingAmpersand_
+    return;
   case LineClassification::Kind::DefinitionDirective:
     preprocessor_.Directive(TokenizePreprocessorDirective(), *this);
-    // Don't set afterPreprocessingDirective_
+    // Don't set afterPreprocessingDirective_ or skipLeadingAmpersand_
     return;
   case LineClassification::Kind::CompilerDirective: {
     directiveSentinel_ = line.sentinel;
diff --git a/flang/test/Preprocessing/line-in-contin.F90 b/flang/test/Preprocessing/line-in-contin.F90
new file mode 100644
index 0000000000000..138e579bffaa2
--- /dev/null
+++ b/flang/test/Preprocessing/line-in-contin.F90
@@ -0,0 +1,20 @@
+! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s
+! CHECK: call foo( 0.)
+! CHECK: call foo( 1.)
+! CHECK: call foo( 2.)
+! CHECK: call foo( 3.)
+call foo( &
+# 100 "bar.h"
+         & 0.)
+call foo( &
+# 101 "bar.h"
+         1.)
+call foo( &
+# 102 "bar.h"
+         & 2. &
+    & )
+call foo( &
+# 103 "bar.h"
+         & 3. &
+    )
+end



More information about the flang-commits mailing list