@@ -68,24 +68,30 @@ bool isIgnored(llvm::StringRef HeaderPath, HeaderFilter IgnoreHeaders) {
68
68
}
69
69
70
70
bool mayConsiderUnused (const Inclusion &Inc, ParsedAST &AST,
71
- const include_cleaner::PragmaIncludes *PI) {
71
+ const include_cleaner::PragmaIncludes *PI,
72
+ bool AnalyzeAngledIncludes) {
72
73
assert (Inc.HeaderID );
73
74
auto HID = static_cast <IncludeStructure::HeaderID>(*Inc.HeaderID );
74
75
auto FE = AST.getSourceManager ().getFileManager ().getFileRef (
75
76
AST.getIncludeStructure ().getRealPath (HID));
76
77
assert (FE);
77
78
if (FE->getDir () == AST.getPreprocessor ()
78
- .getHeaderSearchInfo ()
79
- .getModuleMap ()
80
- .getBuiltinDir ())
79
+ .getHeaderSearchInfo ()
80
+ .getModuleMap ()
81
+ .getBuiltinDir ())
81
82
return false ;
82
83
if (PI && PI->shouldKeep (*FE))
83
84
return false ;
84
85
// FIXME(kirillbobyrev): We currently do not support the umbrella headers.
85
86
// System headers are likely to be standard library headers.
86
- // Until we have good support for umbrella headers, don't warn about them.
87
- if (Inc.Written .front () == ' <' )
88
- return tooling::stdlib::Header::named (Inc.Written ).has_value ();
87
+ // Until we have good support for umbrella headers, don't warn about them
88
+ // (unless analysis is explicitly enabled).
89
+ if (Inc.Written .front () == ' <' ) {
90
+ if (tooling::stdlib::Header::named (Inc.Written ))
91
+ return true ;
92
+ if (!AnalyzeAngledIncludes)
93
+ return false ;
94
+ }
89
95
if (PI) {
90
96
// Check if main file is the public interface for a private header. If so we
91
97
// shouldn't diagnose it as unused.
@@ -266,7 +272,8 @@ Fix fixAll(const Fix &RemoveAllUnused, const Fix &AddAllMissing) {
266
272
267
273
std::vector<const Inclusion *>
268
274
getUnused (ParsedAST &AST,
269
- const llvm::DenseSet<IncludeStructure::HeaderID> &ReferencedFiles) {
275
+ const llvm::DenseSet<IncludeStructure::HeaderID> &ReferencedFiles,
276
+ bool AnalyzeAngledIncludes) {
270
277
trace::Span Tracer (" IncludeCleaner::getUnused" );
271
278
std::vector<const Inclusion *> Unused;
272
279
for (const Inclusion &MFI : AST.getIncludeStructure ().MainFileIncludes ) {
@@ -275,7 +282,8 @@ getUnused(ParsedAST &AST,
275
282
auto IncludeID = static_cast <IncludeStructure::HeaderID>(*MFI.HeaderID );
276
283
if (ReferencedFiles.contains (IncludeID))
277
284
continue ;
278
- if (!mayConsiderUnused (MFI, AST, &AST.getPragmaIncludes ())) {
285
+ if (!mayConsiderUnused (MFI, AST, &AST.getPragmaIncludes (),
286
+ AnalyzeAngledIncludes)) {
279
287
dlog (" {0} was not used, but is not eligible to be diagnosed as unused" ,
280
288
MFI.Written );
281
289
continue ;
@@ -347,7 +355,8 @@ include_cleaner::Includes convertIncludes(const ParsedAST &AST) {
347
355
return ConvertedIncludes;
348
356
}
349
357
350
- IncludeCleanerFindings computeIncludeCleanerFindings (ParsedAST &AST) {
358
+ IncludeCleanerFindings
359
+ computeIncludeCleanerFindings (ParsedAST &AST, bool AnalyzeAngledIncludes) {
351
360
// Interaction is only polished for C/CPP.
352
361
if (AST.getLangOpts ().ObjC )
353
362
return {};
@@ -432,7 +441,8 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
432
441
MapInfo::getHashValue (RHS.Symbol );
433
442
});
434
443
MissingIncludes.erase (llvm::unique (MissingIncludes), MissingIncludes.end ());
435
- std::vector<const Inclusion *> UnusedIncludes = getUnused (AST, Used);
444
+ std::vector<const Inclusion *> UnusedIncludes =
445
+ getUnused (AST, Used, AnalyzeAngledIncludes);
436
446
return {std::move (UnusedIncludes), std::move (MissingIncludes)};
437
447
}
438
448
0 commit comments