@@ -584,6 +584,12 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
584
584
Parser::StructureMarkerRAII ParsingDecl (
585
585
*this , Tok.getLoc (), Parser::StructureMarkerKind::IfConfig);
586
586
587
+ bool shouldEvaluate =
588
+ // Don't evaluate if it's in '-parse' mode, etc.
589
+ State->PerformConditionEvaluation &&
590
+ // If it's in inactive #if ... #endif block, there's no point to do it.
591
+ !getScopeInfo ().isInactiveConfigBlock ();
592
+
587
593
bool foundActive = false ;
588
594
bool isVersionCondition = false ;
589
595
while (1 ) {
@@ -598,7 +604,7 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
598
604
// Parse the condition. Evaluate it to determine the active
599
605
// clause unless we're doing a parse-only pass.
600
606
if (isElse) {
601
- isActive = !foundActive && State-> PerformConditionEvaluation ;
607
+ isActive = !foundActive && shouldEvaluate ;
602
608
} else {
603
609
llvm::SaveAndRestore<bool > S (InPoundIfEnvironment, true );
604
610
ParserResult<Expr> Result = parseExprSequence (diag::expected_expr,
@@ -613,7 +619,7 @@ ParserResult<IfConfigDecl> Parser::parseIfConfig(
613
619
// Error in the condition;
614
620
isActive = false ;
615
621
isVersionCondition = false ;
616
- } else if (!foundActive && State-> PerformConditionEvaluation ) {
622
+ } else if (!foundActive && shouldEvaluate ) {
617
623
// Evaluate the condition only if we haven't found any active one and
618
624
// we're not in parse-only mode.
619
625
isActive = evaluateIfConfigCondition (Condition, Context);
0 commit comments