summaryrefslogtreecommitdiffstats
path: root/clang/test/Frontend
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/test/Frontend
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/test/Frontend')
-rw-r--r--clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/lib/.keep0
-rw-r--r--clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/include/c++/.keep0
-rw-r--r--clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/lib/gcc/.keep0
-rw-r--r--clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/include/.keep0
-rw-r--r--clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/lib/.keep0
-rw-r--r--clang/test/Frontend/warning-poison-system-directories.c27
6 files changed, 27 insertions, 0 deletions
diff --git a/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/lib/.keep b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/lib/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/lib/.keep
diff --git a/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/include/c++/.keep b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/include/c++/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/include/c++/.keep
diff --git a/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/lib/gcc/.keep b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/lib/gcc/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/lib/gcc/.keep
diff --git a/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/include/.keep b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/include/.keep
diff --git a/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/lib/.keep b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/lib/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Frontend/Inputs/sysroot_x86_64_cross_linux_tree/usr/local/lib/.keep
diff --git a/clang/test/Frontend/warning-poison-system-directories.c b/clang/test/Frontend/warning-poison-system-directories.c
new file mode 100644
index 00000000000..018f02db361
--- /dev/null
+++ b/clang/test/Frontend/warning-poison-system-directories.c
@@ -0,0 +1,27 @@
+// System directory and sysroot option causes warning.
+// RUN: %clang -Wpoison-system-directories -target x86_64 -I/usr/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.1.stderr
+// RUN: FileCheck -check-prefix=WARN < %t.1.stderr %s
+// RUN: %clang -Wpoison-system-directories -target x86_64 -cxx-isystem/usr/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.1.stderr
+// RUN: FileCheck -check-prefix=WARN < %t.1.stderr %s
+// RUN: %clang -Wpoison-system-directories -target x86_64 -iquote/usr/local/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.1.stderr
+// RUN: FileCheck -check-prefix=WARN < %t.1.stderr %s
+// RUN: %clang -Wpoison-system-directories -target x86_64 -isystem/usr/local/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.1.stderr
+// RUN: FileCheck -check-prefix=WARN < %t.1.stderr %s
+
+// Missing target but included sysroot still causes the warning.
+// RUN: %clang -Wpoison-system-directories -I/usr/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.2.stderr
+// RUN: FileCheck -check-prefix=WARN < %t.2.stderr %s
+
+// With -Werror the warning causes the failure.
+// RUN: not %clang -Werror=poison-system-directories -target x86_64 -I/usr/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s 2> %t.3.stderr
+// RUN: FileCheck -check-prefix=ERROR < %t.3.stderr %s
+
+// Cros target without sysroot causes no warning.
+// RUN: %clang -Wpoison-system-directories -Werror -target x86_64 -I/usr/include -c -o - %s
+
+// By default the warning is off.
+// RUN: %clang -Werror -target x86_64 -I/usr/include --sysroot %S/Inputs/sysroot_x86_64_cross_linux_tree -c -o - %s
+
+// WARN: warning: include location {{[^ ]+}} is unsafe for cross-compilation [-Wpoison-system-directories]
+
+// ERROR: error: include location {{[^ ]+}} is unsafe for cross-compilation [-Werror,-Wpoison-system-directories]
OpenPOWER on IntegriCloud