@@ -960,7 +960,6 @@ OptionalFileEntryRef Preprocessor::LookupFile(
960
960
961
961
Module *RequestingModule = getModuleForLocation (
962
962
FilenameLoc, LangOpts.ModulesValidateTextualHeaderIncludes );
963
- bool RequestingModuleIsModuleInterface = !SourceMgr.isInMainFile (FilenameLoc);
964
963
965
964
// If the header lookup mechanism may be relative to the current inclusion
966
965
// stack, record the parent #includes.
@@ -1041,13 +1040,8 @@ OptionalFileEntryRef Preprocessor::LookupFile(
1041
1040
Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath,
1042
1041
RelativePath, RequestingModule, SuggestedModule, IsMapped,
1043
1042
IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures);
1044
- if (FE) {
1045
- if (SuggestedModule && !LangOpts.AsmPreprocessor )
1046
- HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
1047
- RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
1048
- Filename, *FE);
1043
+ if (FE)
1049
1044
return FE;
1050
- }
1051
1045
1052
1046
OptionalFileEntryRef CurFileEnt;
1053
1047
// Otherwise, see if this is a subframework header. If so, this is relative
@@ -1058,10 +1052,6 @@ OptionalFileEntryRef Preprocessor::LookupFile(
1058
1052
if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader (
1059
1053
Filename, *CurFileEnt, SearchPath, RelativePath, RequestingModule,
1060
1054
SuggestedModule)) {
1061
- if (SuggestedModule && !LangOpts.AsmPreprocessor )
1062
- HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
1063
- RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
1064
- Filename, *FE);
1065
1055
return FE;
1066
1056
}
1067
1057
}
@@ -1073,10 +1063,6 @@ OptionalFileEntryRef Preprocessor::LookupFile(
1073
1063
if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader (
1074
1064
Filename, *CurFileEnt, SearchPath, RelativePath,
1075
1065
RequestingModule, SuggestedModule)) {
1076
- if (SuggestedModule && !LangOpts.AsmPreprocessor )
1077
- HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
1078
- RequestingModule, RequestingModuleIsModuleInterface,
1079
- FilenameLoc, Filename, *FE);
1080
1066
return FE;
1081
1067
}
1082
1068
}
@@ -2027,12 +2013,28 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
2027
2013
const FileEntry *LookupFromFile, StringRef &LookupFilename,
2028
2014
SmallVectorImpl<char > &RelativePath, SmallVectorImpl<char > &SearchPath,
2029
2015
ModuleMap::KnownHeader &SuggestedModule, bool isAngled) {
2016
+ auto DiagnoseHeaderInclusion = [&](FileEntryRef FE) {
2017
+ if (LangOpts.AsmPreprocessor )
2018
+ return ;
2019
+
2020
+ Module *RequestingModule = getModuleForLocation (
2021
+ FilenameLoc, LangOpts.ModulesValidateTextualHeaderIncludes );
2022
+ bool RequestingModuleIsModuleInterface =
2023
+ !SourceMgr.isInMainFile (FilenameLoc);
2024
+
2025
+ HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
2026
+ RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
2027
+ Filename, FE);
2028
+ };
2029
+
2030
2030
OptionalFileEntryRef File = LookupFile (
2031
2031
FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir,
2032
2032
Callbacks ? &SearchPath : nullptr , Callbacks ? &RelativePath : nullptr ,
2033
2033
&SuggestedModule, &IsMapped, &IsFrameworkFound);
2034
- if (File)
2034
+ if (File) {
2035
+ DiagnoseHeaderInclusion (*File);
2035
2036
return File;
2037
+ }
2036
2038
2037
2039
// Give the clients a chance to silently skip this include.
2038
2040
if (Callbacks && Callbacks->FileNotFound (Filename))
@@ -2051,6 +2053,7 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
2051
2053
&SuggestedModule, &IsMapped,
2052
2054
/* IsFrameworkFound=*/ nullptr );
2053
2055
if (File) {
2056
+ DiagnoseHeaderInclusion (*File);
2054
2057
Diag (FilenameTok, diag::err_pp_file_not_found_angled_include_not_fatal)
2055
2058
<< Filename << IsImportDecl
2056
2059
<< FixItHint::CreateReplacement (FilenameRange,
@@ -2081,6 +2084,7 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
2081
2084
Callbacks ? &RelativePath : nullptr , &SuggestedModule, &IsMapped,
2082
2085
/* IsFrameworkFound=*/ nullptr );
2083
2086
if (File) {
2087
+ DiagnoseHeaderInclusion (*File);
2084
2088
auto Hint =
2085
2089
isAngled ? FixItHint::CreateReplacement (
2086
2090
FilenameRange, " <" + TypoCorrectionName.str () + " >" )
0 commit comments