-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Fix #else with trailing text #138045
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
Conversation
Fixed the issue, where the extra text on #else line (' Z' in the example below) caused the data from the "else" clause to be processed together with the data of "then" clause. ``` PARAMETER(A=2) PARAMETER(A=3) end ```
@llvm/pr-subscribers-flang-parser Author: Eugene Epshteyn (eugeneepshteyn) ChangesFixed the issue, where the extra text on #else line (' Z' in the example
Full diff: https://github.com/llvm/llvm-project/pull/138045.diff 2 Files Affected:
diff --git a/flang/lib/Parser/preprocessor.cpp b/flang/lib/Parser/preprocessor.cpp
index a47f9c32ad27c..1e984896ea4ed 100644
--- a/flang/lib/Parser/preprocessor.cpp
+++ b/flang/lib/Parser/preprocessor.cpp
@@ -684,7 +684,9 @@ void Preprocessor::Directive(const TokenSequence &dir, Prescanner &prescanner) {
dir.GetIntervalProvenanceRange(j, tokens - j),
"#else: excess tokens at end of directive"_port_en_US);
}
- } else if (ifStack_.empty()) {
+ }
+
+ if (ifStack_.empty()) {
prescanner.Say(dir.GetTokenProvenanceRange(dirOffset),
"#else: not nested within #if, #ifdef, or #ifndef"_err_en_US);
} else if (ifStack_.top() != CanDeadElseAppear::Yes) {
diff --git a/flang/test/Preprocessing/pp048.F b/flang/test/Preprocessing/pp048.F
new file mode 100644
index 0000000000000..121262c1840f9
--- /dev/null
+++ b/flang/test/Preprocessing/pp048.F
@@ -0,0 +1,11 @@
+! RUN: %flang -E %s 2>&1 | FileCheck %s
+#ifndef XYZ42
+ PARAMETER(A=2)
+#else Z
+ PARAMETER(A=3)
+#endif
+! Ensure that "PARAMETER(A" is printed only once
+! CHECK: PARAMETER(A
+! CHECK-NOT: PARAMETER(A
+ end
+
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixed the issue, where the extra text on #else line (' Z' in the example below) caused the data from the "else" clause to be processed together with the data of "then" clause. ``` #ifndef XYZ42 PARAMETER(A=2) #else Z PARAMETER(A=3) #endif end ```
Fixed the issue, where the extra text on #else line (' Z' in the example below) caused the data from the "else" clause to be processed together with the data of "then" clause. ``` #ifndef XYZ42 PARAMETER(A=2) #else Z PARAMETER(A=3) #endif end ```
Fixed the issue, where the extra text on #else line (' Z' in the example below) caused the data from the "else" clause to be processed together with the data of "then" clause. ``` #ifndef XYZ42 PARAMETER(A=2) #else Z PARAMETER(A=3) #endif end ```
Fixed the issue, where the extra text on #else line (' Z' in the example below) caused the data from the "else" clause to be processed together with the data of "then" clause. ``` #ifndef XYZ42 PARAMETER(A=2) #else Z PARAMETER(A=3) #endif end ```
Fixed the issue, where the extra text on #else line (' Z' in the example
below) caused the data from the "else" clause to be processed together
with the data of "then" clause.