Skip to content

Commit 0312677

Browse files
committed
Identify if a file is a system header by its path
1 parent cde15fa commit 0312677

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,11 @@ void HeaderSearch::DiagnoseHeaderShadowing(
887887
ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,
888888
bool isAngled, int IncluderLoopIndex, ConstSearchDirIterator MainLoopIt) {
889889

890-
if (Diags.isIgnored(diag::warn_header_shadowing, IncludeLoc) || isAngled ||
891-
DiagnosedShadowing)
890+
if (Diags.isIgnored(diag::warn_header_shadowing, IncludeLoc) ||
891+
DiagnosedShadowing || (getFileInfo(*FE).DirInfo != SrcMgr::C_User)) {
892+
DiagnosedShadowing = true;
892893
return;
894+
}
893895

894896
DiagnosedShadowing = true;
895897

clang/test/Preprocessor/header-shadowing.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/// Check that:
55
/// - Quoted includes ("...") trigger the diagnostic.
6-
/// - Angled includes (<...>) are ignored.
6+
/// - System headers are ignored.
77
/// - #include_next does not cause a duplicate warning.
88
// RUN: %clang_cc1 -Wshadow-header -Eonly %t/main.c -I %t/include1 -I %t/include2 \
99
// RUN: -isystem %t/system1 -isystem %t/system2 2>&1 | FileCheck %s --check-prefix=SHADOWING
@@ -16,11 +16,11 @@
1616
// SHADOWING: warning: system1/stdio.h included!
1717

1818
/// Check that the diagnostic is only performed once in MSVC compatibility mode.
19-
// RUN: %clang_cc1 -fms-compatibility -Wshadow-header -Eonly %t/t.c -I %t -I %t/foo -I %t/foo/bar 2>&1 | FileCheck %s --check-prefix=SHADOWING-MS
19+
// RUN: %clang_cc1 -fms-compatibility -Wshadow-header -Eonly %t/t.c 2>&1 | FileCheck %s --check-prefix=SHADOWING-MS
2020

2121
// SHADOWING-MS: {{.*}} warning: multiple candidates for header 't3.h' found; directory '{{.*}}foo' chosen, ignoring '{{.*}}' and others [-Wshadow-header]
22+
// SHADOWING-MS-NOT: {{.*}} warning: multiple candidates for header 't3.h' found; directory '{{.*}}' chosen, ignoring '{{.*}}foo' and others [-Wshadow-header]
2223
// SHADOWING-MS: warning: Found foo/t3.h.
23-
// SHADOWING-MS-NOT: {{.*}} warning: multiple candidates for header 't3.h' found; directory '{{.*}}foo' chosen, ignoring '{{.*}}' and others [-Wshadow-header]
2424

2525
//--- main.c
2626
#include "header.h"

0 commit comments

Comments
 (0)