Skip to content

Commit 943c704

Browse files
authored
[flang] Support #if defined when no definitions (llvm#156080)
The "defined" operator isn't working in #if/#elif expressions when there are no defined macros. Fix.
1 parent 3f6768c commit 943c704

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

flang/lib/Parser/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ std::optional<TokenSequence> Preprocessor::MacroReplacement(
414414
const TokenSequence &input, Prescanner &prescanner,
415415
std::optional<std::size_t> *partialFunctionLikeMacro, bool inIfExpression) {
416416
// Do quick scan for any use of a defined name.
417-
if (definitions_.empty()) {
417+
if (!inIfExpression && definitions_.empty()) {
418418
return std::nullopt;
419419
}
420420
std::size_t tokens{input.SizeInTokens()};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!RUN: %flang -fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
2+
!CHECK-NOT: ERROR STOP
3+
!CHECK: CONTINUE
4+
#if defined UNDEFINED
5+
error stop
6+
#endif
7+
#if !defined UNDEFINED
8+
continue
9+
#endif
10+
end

0 commit comments

Comments
 (0)