Skip to content

Commit 36541ec

Browse files
[flang] Fix #else with trailing text (#138045)
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 ```
1 parent f46ff4c commit 36541ec

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

flang/lib/Parser/preprocessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ void Preprocessor::Directive(const TokenSequence &dir, Prescanner &prescanner) {
684684
dir.GetIntervalProvenanceRange(j, tokens - j),
685685
"#else: excess tokens at end of directive"_port_en_US);
686686
}
687-
} else if (ifStack_.empty()) {
687+
}
688+
if (ifStack_.empty()) {
688689
prescanner.Say(dir.GetTokenProvenanceRange(dirOffset),
689690
"#else: not nested within #if, #ifdef, or #ifndef"_err_en_US);
690691
} else if (ifStack_.top() != CanDeadElseAppear::Yes) {

flang/test/Preprocessing/pp048.F

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! RUN: %flang -E %s 2>&1 | FileCheck %s
2+
#ifndef XYZ42
3+
PARAMETER(A=2)
4+
#else Z
5+
PARAMETER(A=3)
6+
#endif
7+
! Ensure that "PARAMETER(A" is printed only once
8+
! CHECK: PARAMETER(A
9+
! CHECK-NOT: PARAMETER(A
10+
end
11+

0 commit comments

Comments
 (0)