@@ -2074,10 +2074,11 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
20742074 return ;
20752075
20762076 if (FilenameTok.isNot (tok::header_name)) {
2077- if (FilenameTok.is (tok::identifier) && PPOpts.SingleFileParseMode ) {
2077+ if (FilenameTok.is (tok::identifier) &&
2078+ (PPOpts.SingleFileParseMode || PPOpts.SingleModuleParseMode )) {
20782079 // If we saw #include IDENTIFIER and lexing didn't turn in into a header
2079- // name, it was undefined. In 'single-file-parse' mode, just skip the
2080- // directive without emitting diagnostics - the identifier might be
2080+ // name, it was undefined. In 'single-{ file,module} -parse' mode, just skip
2081+ // the directive without emitting diagnostics - the identifier might be
20812082 // normally defined in previously-skipped include directive.
20822083 DiscardUntilEndOfDirective ();
20832084 return ;
@@ -2385,10 +2386,15 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
23852386 (getLangOpts ().CPlusPlusModules || getLangOpts ().Modules ) &&
23862387 ModuleToImport && !ModuleToImport->isHeaderUnit ();
23872388
2389+ if (MaybeTranslateInclude && (UsableHeaderUnit || UsableClangHeaderModule) &&
2390+ PPOpts.SingleModuleParseMode ) {
2391+ Action = IncludeLimitReached;
2392+ }
23882393 // Determine whether we should try to import the module for this #include, if
23892394 // there is one. Don't do so if precompiled module support is disabled or we
23902395 // are processing this module textually (because we're building the module).
2391- if (MaybeTranslateInclude && (UsableHeaderUnit || UsableClangHeaderModule)) {
2396+ else if (MaybeTranslateInclude &&
2397+ (UsableHeaderUnit || UsableClangHeaderModule)) {
23922398 // If this include corresponds to a module but that module is
23932399 // unavailable, diagnose the situation and bail out.
23942400 // FIXME: Remove this; loadModule does the same check (but produces
@@ -3440,6 +3446,13 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
34403446 CurPPLexer->pushConditionalLevel (DirectiveTok.getLocation (),
34413447 /* wasskip*/ false , /* foundnonskip*/ false ,
34423448 /* foundelse*/ false );
3449+ } else if (PPOpts.SingleModuleParseMode && !MI) {
3450+ // In 'single-module-parse mode' undefined identifiers trigger skipping of
3451+ // all the directive blocks. We lie here and set FoundNonSkipPortion so that
3452+ // even any \#else blocks get skipped.
3453+ SkipExcludedConditionalBlock (
3454+ HashToken.getLocation (), DirectiveTok.getLocation (),
3455+ /* FoundNonSkipPortion=*/ true , /* FoundElse=*/ false );
34433456 } else if (!MI == isIfndef || RetainExcludedCB) {
34443457 // Yes, remember that we are inside a conditional, then lex the next token.
34453458 CurPPLexer->pushConditionalLevel (DirectiveTok.getLocation (),
@@ -3494,6 +3507,13 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
34943507 // the directive blocks.
34953508 CurPPLexer->pushConditionalLevel (IfToken.getLocation (), /* wasskip*/ false ,
34963509 /* foundnonskip*/ false , /* foundelse*/ false );
3510+ } else if (PPOpts.SingleModuleParseMode && DER.IncludedUndefinedIds ) {
3511+ // In 'single-module-parse mode' undefined identifiers trigger skipping of
3512+ // all the directive blocks. We lie here and set FoundNonSkipPortion so that
3513+ // even any \#else blocks get skipped.
3514+ SkipExcludedConditionalBlock (HashToken.getLocation (), IfToken.getLocation (),
3515+ /* FoundNonSkipPortion=*/ true ,
3516+ /* FoundElse=*/ false );
34973517 } else if (ConditionalTrue || RetainExcludedCB) {
34983518 // Yes, remember that we are inside a conditional, then lex the next token.
34993519 CurPPLexer->pushConditionalLevel (IfToken.getLocation (), /* wasskip*/ false ,
0 commit comments