Skip to content
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

[flang] Fix continuation when line begins with empty macro expansion #117407

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

klausler
Copy link
Contributor

A free form source line that begins with a macro should still be classified as a source line, and have its continuation lines work, even if the macro expands to an empty replacement.

Fixes #117297.

A free form source line that begins with a macro should still be
classified as a source line, and have its continuation lines work,
even if the macro expands to an empty replacement.

Fixes llvm#117297.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:parser labels Nov 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 23, 2024

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

Changes

A free form source line that begins with a macro should still be classified as a source line, and have its continuation lines work, even if the macro expands to an empty replacement.

Fixes #117297.


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

2 Files Affected:

  • (modified) flang/lib/Parser/prescan.cpp (+1-1)
  • (added) flang/test/Preprocessing/bug117297.F90 (+7)
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 34e660f8d26646..3cd32d7e6c92e8 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -234,7 +234,7 @@ void Prescanner::Statement() {
             directiveSentinel_ = newLineClass.sentinel;
             disableSourceContinuation_ = false;
           } else {
-            disableSourceContinuation_ =
+            disableSourceContinuation_ = !replaced->empty() &&
                 newLineClass.kind != LineClassification::Kind::Source;
           }
         }
diff --git a/flang/test/Preprocessing/bug117297.F90 b/flang/test/Preprocessing/bug117297.F90
new file mode 100644
index 00000000000000..88b54000f04630
--- /dev/null
+++ b/flang/test/Preprocessing/bug117297.F90
@@ -0,0 +1,7 @@
+! RUN: %flang -E %s 2>&1 | FileCheck %s
+!CHECK: CALL myfunc( 'hello ' // 'world' // 'again')
+#define NOCOMMENT
+NOCOMMENT CALL myfunc( 'hello ' // &
+NOCOMMENT 'world' // &
+NOCOMMENT 'again' )
+end

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] Incorrect preprocesor output
3 participants