@@ -953,7 +953,6 @@ OptionalFileEntryRef Preprocessor::LookupFile(
953
953
954
954
Module *RequestingModule = getModuleForLocation (
955
955
FilenameLoc, LangOpts.ModulesValidateTextualHeaderIncludes );
956
- bool RequestingModuleIsModuleInterface = !SourceMgr.isInMainFile (FilenameLoc);
957
956
958
957
// If the header lookup mechanism may be relative to the current inclusion
959
958
// stack, record the parent #includes.
@@ -1029,13 +1028,8 @@ OptionalFileEntryRef Preprocessor::LookupFile(
1029
1028
Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath,
1030
1029
RelativePath, RequestingModule, SuggestedModule, IsMapped,
1031
1030
IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures);
1032
- if (FE) {
1033
- if (SuggestedModule && !LangOpts.AsmPreprocessor )
1034
- HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
1035
- RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
1036
- Filename, *FE);
1031
+ if (FE)
1037
1032
return FE;
1038
- }
1039
1033
1040
1034
const FileEntry *CurFileEnt;
1041
1035
// Otherwise, see if this is a subframework header. If so, this is relative
@@ -1046,10 +1040,6 @@ OptionalFileEntryRef Preprocessor::LookupFile(
1046
1040
if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader (
1047
1041
Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule,
1048
1042
SuggestedModule)) {
1049
- if (SuggestedModule && !LangOpts.AsmPreprocessor )
1050
- HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
1051
- RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
1052
- Filename, *FE);
1053
1043
return FE;
1054
1044
}
1055
1045
}
@@ -1061,10 +1051,6 @@ OptionalFileEntryRef Preprocessor::LookupFile(
1061
1051
if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader (
1062
1052
Filename, CurFileEnt, SearchPath, RelativePath,
1063
1053
RequestingModule, SuggestedModule)) {
1064
- if (SuggestedModule && !LangOpts.AsmPreprocessor )
1065
- HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
1066
- RequestingModule, RequestingModuleIsModuleInterface,
1067
- FilenameLoc, Filename, *FE);
1068
1054
return FE;
1069
1055
}
1070
1056
}
@@ -2093,12 +2079,28 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
2093
2079
const FileEntry *LookupFromFile, StringRef &LookupFilename,
2094
2080
SmallVectorImpl<char > &RelativePath, SmallVectorImpl<char > &SearchPath,
2095
2081
ModuleMap::KnownHeader &SuggestedModule, bool isAngled) {
2082
+ auto DiagnoseHeaderInclusion = [&](FileEntryRef FE) {
2083
+ if (LangOpts.AsmPreprocessor )
2084
+ return ;
2085
+
2086
+ Module *RequestingModule = getModuleForLocation (
2087
+ FilenameLoc, LangOpts.ModulesValidateTextualHeaderIncludes );
2088
+ bool RequestingModuleIsModuleInterface =
2089
+ !SourceMgr.isInMainFile (FilenameLoc);
2090
+
2091
+ HeaderInfo.getModuleMap ().diagnoseHeaderInclusion (
2092
+ RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
2093
+ Filename, FE);
2094
+ };
2095
+
2096
2096
OptionalFileEntryRef File = LookupFile (
2097
2097
FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir,
2098
2098
Callbacks ? &SearchPath : nullptr , Callbacks ? &RelativePath : nullptr ,
2099
2099
&SuggestedModule, &IsMapped, &IsFrameworkFound);
2100
- if (File)
2100
+ if (File) {
2101
+ DiagnoseHeaderInclusion (*File);
2101
2102
return File;
2103
+ }
2102
2104
2103
2105
// Give the clients a chance to silently skip this include.
2104
2106
if (Callbacks && Callbacks->FileNotFound (Filename))
@@ -2117,6 +2119,7 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
2117
2119
&SuggestedModule, &IsMapped,
2118
2120
/* IsFrameworkFound=*/ nullptr );
2119
2121
if (File) {
2122
+ DiagnoseHeaderInclusion (*File);
2120
2123
Diag (FilenameTok, diag::err_pp_file_not_found_angled_include_not_fatal)
2121
2124
<< Filename << IsImportDecl
2122
2125
<< FixItHint::CreateReplacement (FilenameRange,
@@ -2147,6 +2150,7 @@ OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
2147
2150
Callbacks ? &RelativePath : nullptr , &SuggestedModule, &IsMapped,
2148
2151
/* IsFrameworkFound=*/ nullptr );
2149
2152
if (File) {
2153
+ DiagnoseHeaderInclusion (*File);
2150
2154
auto Hint =
2151
2155
isAngled ? FixItHint::CreateReplacement (
2152
2156
FilenameRange, " <" + TypoCorrectionName.str () + " >" )
0 commit comments