Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

klausler
Copy link
Contributor

…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 #100073.

…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 llvm#100073.
@klausler klausler requested a review from mjklemm July 23, 2024 18:51
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Jul 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2024

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

Changes

…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 #100073.


Full diff: https://github.com/llvm/llvm-project/pull/100178.diff

2 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+5-1)
  • (added) flang/test/Preprocessing/line-in-contin.F90 (+20)
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

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mjklemm mjklemm requested review from kparzysz and Meinersbur July 24, 2024 09:14
@klausler klausler merged commit 1ada235 into llvm:main Jul 30, 2024
10 checks passed
@klausler klausler deleted the bug100073 branch July 30, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:parser flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang] Cannot scan continuation lines with preprocessor marks
3 participants