diff --git a/flang/lib/Parser/preprocessor.cpp b/flang/lib/Parser/preprocessor.cpp index ae14e2d46020f..9176b4db3408a 100644 --- a/flang/lib/Parser/preprocessor.cpp +++ b/flang/lib/Parser/preprocessor.cpp @@ -414,7 +414,7 @@ std::optional Preprocessor::MacroReplacement( const TokenSequence &input, Prescanner &prescanner, std::optional *partialFunctionLikeMacro, bool inIfExpression) { // Do quick scan for any use of a defined name. - if (definitions_.empty()) { + if (!inIfExpression && definitions_.empty()) { return std::nullopt; } std::size_t tokens{input.SizeInTokens()}; diff --git a/flang/test/Preprocessing/no-pp-if.f90 b/flang/test/Preprocessing/no-pp-if.f90 new file mode 100644 index 0000000000000..3e49df3deb251 --- /dev/null +++ b/flang/test/Preprocessing/no-pp-if.f90 @@ -0,0 +1,10 @@ +!RUN: %flang -fc1 -fdebug-unparse %s 2>&1 | FileCheck %s +!CHECK-NOT: ERROR STOP +!CHECK: CONTINUE +#if defined UNDEFINED +error stop +#endif +#if !defined UNDEFINED +continue +#endif +end