Skip to content

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

@klausler klausler requested a review from akuhlens November 25, 2024 17:24
@klausler klausler merged commit dfbc80f into llvm:main Dec 2, 2024
11 checks passed
@klausler klausler deleted the bug117297 branch December 2, 2024 20:26
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