summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/InitHeaderSearch.cpp
diff options
context:
space:
mode:
authorManoj Gupta <manojgupta@google.com>2019-09-12 22:36:13 +0000
committerManoj Gupta <manojgupta@google.com>2019-09-12 22:36:13 +0000
commit4fe2732161905a9bd53e09336851482a96b04ce9 (patch)
tree25acc7992f3ad35217ec73549f5f56f4050a0af3 /clang/lib/Frontend/InitHeaderSearch.cpp
parentdecff073ee413dbc39a13b45592897b77e87552f (diff)
downloadbcm5719-llvm-4fe2732161905a9bd53e09336851482a96b04ce9.tar.gz
bcm5719-llvm-4fe2732161905a9bd53e09336851482a96b04ce9.zip
Add -Wpoison-system-directories warning
When using clang as a cross-compiler, we should not use system headers to do the compilation. This CL adds support of a new warning flag -Wpoison-system-directories which emits warnings if --sysroot is set and headers from common host system location are used. By default the warning is disabled. The intention of the warning is to catch bad includes which are usually generated by third party build system not targeting cross-compilation. Such cases happen in Chrome OS when someone imports a new package or upgrade one to a newer version from upstream. Patch by: denik (Denis Nikitin) llvm-svn: 371785
Diffstat (limited to 'clang/lib/Frontend/InitHeaderSearch.cpp')
-rw-r--r--clang/lib/Frontend/InitHeaderSearch.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp
index ad0d2327148..5d877ee9c0d 100644
--- a/clang/lib/Frontend/InitHeaderSearch.cpp
+++ b/clang/lib/Frontend/InitHeaderSearch.cpp
@@ -137,6 +137,13 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
SmallString<256> MappedPathStorage;
StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
+ // If use system headers while cross-compiling, emit the warning.
+ if (HasSysroot && (MappedPathStr.startswith("/usr/include") ||
+ MappedPathStr.startswith("/usr/local/include"))) {
+ Headers.getDiags().Report(diag::warn_poison_system_directories)
+ << MappedPathStr;
+ }
+
// Compute the DirectoryLookup type.
SrcMgr::CharacteristicKind Type;
if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
OpenPOWER on IntegriCloud