[flang-commits] [flang] [flang] Fix continuation when line begins with empty macro expansion (PR #117407)

via flang-commits flang-commits at lists.llvm.org
Fri Nov 22 16:27:43 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-parser

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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 https://github.com/llvm/llvm-project/issues/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
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

``````````

</details>


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


More information about the flang-commits mailing list