[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
```
This commit is contained in:
Eugene Epshteyn 2025-05-01 23:07:52 -04:00 committed by GitHub
parent f46ff4c204
commit 36541ec3ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -684,7 +684,8 @@ 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) {

View File

@ -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