diff options
Diffstat (limited to 'gcc-4.9/gcc/incpath.c')
-rw-r--r-- | gcc-4.9/gcc/incpath.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/incpath.c b/gcc-4.9/gcc/incpath.c index ddd856cb7..c25a37659 100644 --- a/gcc-4.9/gcc/incpath.c +++ b/gcc-4.9/gcc/incpath.c @@ -28,6 +28,7 @@ #include "intl.h" #include "incpath.h" #include "cppdefault.h" +#include "diagnostic.h" /* Microsoft Windows does not natively support inodes. VMS has non-numeric inodes. */ @@ -348,6 +349,45 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose) add_sysroot_to_chain (sysroot, AFTER); } + /* Need to run here before processing below as that'll automatically cull + paths that do not exist. However, we want to throw errors whenever the + build includes things like -I/usr/include/asdf even if it happens to not + exist on the current system. */ + if (flag_poison_system_directories) + { + unsigned int c; + unsigned int chains[] = { QUOTE, BRACKET, SYSTEM, AFTER }; + + /* Enable -Werror=poison-system-directories when -Werror and -Wno-error + have not been set. + + Ideally this would be done in toplev's process_options, but this + function runs before that one, so we inline it here instead. */ + if (POISON_SYSTEM_DIRECTORIES_DEFAULT + && !global_options_set.x_warnings_are_errors + && global_dc->classify_diagnostic[OPT_Wpoison_system_directories] == + DK_UNSPECIFIED) + diagnostic_classify_diagnostic (global_dc, + OPT_Wpoison_system_directories, + DK_ERROR, UNKNOWN_LOCATION); + + for (c = 0; c < ARRAY_SIZE (chains); ++c) + { + unsigned int chain = chains[c]; + struct cpp_dir *p; + + for (p = heads[chain]; p; p = p->next) + if (!strncmp (p->name, "/usr/include", 12) + || !strncmp (p->name, "/usr/local/include", 18) + || !strncmp (p->name, "/usr/X11R6/include", 18) + || !strncmp (p->name, "/lib", 4) + || !strncmp (p->name, "/usr/local/lib", 14)) + warning (OPT_Wpoison_system_directories, + "include location \"%s\" is unsafe for " + "cross-compilation", p->name); + } + } + /* Join the SYSTEM and AFTER chains. Remove duplicates in the resulting SYSTEM chain. */ if (heads[SYSTEM]) |