[flang-commits] [flang] [flang][preprocessor] Fix handling of #line before free-form continua… (PR #100178)
via flang-commits
flang-commits at lists.llvm.org
Tue Jul 23 11:51:51 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
…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.
---
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/100178
More information about the flang-commits
mailing list