Skip to content

Commit 7bd0535

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

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
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
1010

11-
// SHADOWING: {{.*}} warning: multiple candidates for header 'header.h' found; directory '{{.*}}include1' chosen, ignoring '{{.*}}include2' and others [-Wshadow-header]
11+
// SHADOWING: {{.*}} warning: multiple candidates for header 'header.h' found; directory '{{.*}}/include1' chosen, ignoring '{{.*}}/include2' and others [-Wshadow-header]
1212
// SHADOWING: warning: include1/header.h included!
13-
// SHADOWING-NOT: {{.*}} warning: multiple candidates for header 'header.h' found; directory '{{.*}}include2' chosen, ignoring '{{.*}}include1' and others [-Wshadow-header]
13+
// SHADOWING-NOT: {{.*}} warning: multiple candidates for header 'header.h' found; directory '{{.*}}/include2' chosen, ignoring '{{.*}}/include1' and others [-Wshadow-header]
1414
// SHADOWING: warning: include2/header.h included!
15-
// SHADOWING-NOT: {{.*}} warning: multiple candidates for header 'stdio.h' found; directory '{{.*}}system1' chosen, ignoring '{{.*}}system2' and others [-Wshadow-header]
15+
// SHADOWING-NOT: {{.*}} warning: multiple candidates for header 'stdio.h' found; directory '{{.*}}/system1' chosen, ignoring '{{.*}}/system2' and others [-Wshadow-header]
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

21-
// SHADOWING-MS: {{.*}} warning: multiple candidates for header 't3.h' found; directory '{{.*}}foo' chosen, ignoring '{{.*}}' and others [-Wshadow-header]
21+
// 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)