[flang-commits] [flang] 1ada235 - [flang][preprocessor] Fix handling of #line before free-form continua… (#100178)
via flang-commits
flang-commits at lists.llvm.org
Tue Jul 30 09:43:03 PDT 2024
Author: Peter Klausler
Date: 2024-07-30T09:42:59-07:00
New Revision: 1ada2352677cd271869660c99f1f18b2f556ac31
URL: https://github.com/llvm/llvm-project/commit/1ada2352677cd271869660c99f1f18b2f556ac31
DIFF: https://github.com/llvm/llvm-project/commit/1ada2352677cd271869660c99f1f18b2f556ac31.diff
LOG: [flang][preprocessor] Fix handling of #line before free-form continua… (#100178)
…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.
Added:
flang/test/Preprocessing/line-in-contin.F90
Modified:
flang/lib/Parser/prescan.cpp
Removed:
################################################################################
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
More information about the flang-commits
mailing list