From b02398bd5bebe35bc44def2963fee7a4c4cf3568 Mon Sep 17 00:00:00 2001 From: Ben Elliston Date: Sat, 22 May 2004 02:39:35 +0000 Subject: [PATCH] c.opt (Wmissing-include-dirs): New. * c.opt (Wmissing-include-dirs): New. * c-opts.c (c_common_handle_option): Pass true for user_supplied_p to add_path () for -I, but false for OPT_idirafter, OPT_iquote and OPT_isystem. Handle case OPT_Wmissing_include_dirs. * c-incpath.h (add_path): Add fourth (bool) argument. * c-incpath.c (add_env_var_paths): Pass false to add_path (). (add_standard_paths): Likewise. (remove_duplicates) [REASON_NOENT]: Warn if -Wmissing-include-dirs is used and the directory was user-supplied via -I. (add_path): Set p->user_supplied_p. Remove duplicated code by using add_cpp_dir_path (). * cpplib.h (struct cpp_options): Add warn_missing_include_dirs. (struct cpp_dir): Add user_supplied_p. * doc/invoke.texi (Warning Options): Document new option. [testsuite] * gcc.dg/cpp/Wmissingdirs.c: New. From-SVN: r82121 --- gcc/ChangeLog | 17 +++++++++++++++++ gcc/c-incpath.c | 23 +++++++++++++---------- gcc/c-incpath.h | 2 +- gcc/c-opts.c | 14 +++++++++----- gcc/c.opt | 4 ++++ gcc/cpplib.h | 7 +++++++ gcc/doc/invoke.texi | 7 ++++++- gcc/testsuite/ChangeLog | 8 ++++---- gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c | 7 +++++++ 9 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a0e205e337c..9de23e4c27f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +2004-05-22 Ben Elliston + + * c.opt (Wmissing-include-dirs): New. + * c-opts.c (c_common_handle_option): Pass true for user_supplied_p + to add_path () for -I, but false for OPT_idirafter, OPT_iquote and + OPT_isystem. Handle case OPT_Wmissing_include_dirs. + * c-incpath.h (add_path): Add fourth (bool) argument. + * c-incpath.c (add_env_var_paths): Pass false to add_path (). + (add_standard_paths): Likewise. + (remove_duplicates) [REASON_NOENT]: Warn if -Wmissing-include-dirs + is used and the directory was user-supplied via -I. + (add_path): Set p->user_supplied_p. Remove duplicated code by + using add_cpp_dir_path (). + * cpplib.h (struct cpp_options): Add warn_missing_include_dirs. + (struct cpp_dir): Add user_supplied_p. + * doc/invoke.texi (Warning Options): Document new option. + 2004-05-21 Ulrich Weigand * fold-const.c (fold_read_from_constant_string): Convert result to diff --git a/gcc/c-incpath.c b/gcc/c-incpath.c index b4da86fb7ba..ea83c1a18b4 100644 --- a/gcc/c-incpath.c +++ b/gcc/c-incpath.c @@ -114,7 +114,7 @@ add_env_var_paths (const char *env_var, int chain) path[q - p] = '\0'; } - add_path (path, chain, chain == SYSTEM); + add_path (path, chain, chain == SYSTEM, false); } } @@ -142,7 +142,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, int cxx_stdinc) if (!strncmp (p->fname, cpp_GCC_INCLUDE_DIR, len)) { char *str = concat (iprefix, p->fname + len, NULL); - add_path (str, SYSTEM, p->cxx_aware); + add_path (str, SYSTEM, p->cxx_aware, false); } } } @@ -160,7 +160,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, int cxx_stdinc) else str = update_path (p->fname, p->component); - add_path (str, SYSTEM, p->cxx_aware); + add_path (str, SYSTEM, p->cxx_aware, false); } } } @@ -192,7 +192,13 @@ remove_duplicates (cpp_reader *pfile, struct cpp_dir *head, if (errno != ENOENT) cpp_errno (pfile, CPP_DL_ERROR, cur->name); else - reason = REASON_NOENT; + { + /* If -Wmissing-include-dirs is given, warn. */ + cpp_options *opts = cpp_get_options (pfile); + if (opts->warn_missing_include_dirs && cur->user_supplied_p) + cpp_errno (pfile, CPP_DL_WARNING, cur->name); + reason = REASON_NOENT; + } } else if (!S_ISDIR (st.st_mode)) cpp_error_with_line (pfile, CPP_DL_ERROR, 0, 0, @@ -317,7 +323,7 @@ add_cpp_dir_path (cpp_dir *p, int chain) /* Add PATH to the include chain CHAIN. PATH must be malloc-ed and NUL-terminated. */ void -add_path (char *path, int chain, int cxx_aware) +add_path (char *path, int chain, int cxx_aware, bool user_supplied_p) { cpp_dir *p; @@ -329,12 +335,9 @@ add_path (char *path, int chain, int cxx_aware) else p->sysp = 0; p->construct = 0; + p->user_supplied_p = user_supplied_p; - if (tails[chain]) - tails[chain]->next = p; - else - heads[chain] = p; - tails[chain] = p; + add_cpp_dir_path (p, chain); } /* Exported function to handle include chain merging, duplicate diff --git a/gcc/c-incpath.h b/gcc/c-incpath.h index 30d7fd63d6f..1096016784f 100644 --- a/gcc/c-incpath.h +++ b/gcc/c-incpath.h @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ extern void split_quote_chain (void); -extern void add_path (char *, int, int); +extern void add_path (char *, int, int, bool); extern void register_include_chains (cpp_reader *, const char *, const char *, int, int, int); extern void add_cpp_dir_path (struct cpp_dir *, int); diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 1300b69cd0b..47c702474c7 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -297,7 +297,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) case OPT_I: if (strcmp (arg, "-")) - add_path (xstrdup (arg), BRACKET, 0); + add_path (xstrdup (arg), BRACKET, 0, true); else { if (quote_chain_split) @@ -541,6 +541,10 @@ c_common_handle_option (size_t scode, const char *arg, int value) warn_missing_format_attribute = value; break; + case OPT_Wmissing_include_dirs: + cpp_opts->warn_missing_include_dirs = value; + break; + case OPT_Wmissing_prototypes: warn_missing_prototypes = value; break; @@ -939,7 +943,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) break; case OPT_idirafter: - add_path (xstrdup (arg), AFTER, 0); + add_path (xstrdup (arg), AFTER, 0, true); break; case OPT_imacros: @@ -952,7 +956,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) break; case OPT_iquote: - add_path (xstrdup (arg), QUOTE, 0); + add_path (xstrdup (arg), QUOTE, 0, true); break; case OPT_isysroot: @@ -960,7 +964,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) break; case OPT_isystem: - add_path (xstrdup (arg), SYSTEM, 0); + add_path (xstrdup (arg), SYSTEM, 0, true); break; case OPT_iwithprefix: @@ -1390,7 +1394,7 @@ add_prefixed_path (const char *suffix, size_t chain) memcpy (path + prefix_len, suffix, suffix_len); path[prefix_len + suffix_len] = '\0'; - add_path (path, chain, 0); + add_path (path, chain, 0, false); } /* Handle -D, -U, -A, -imacros, and the first -include. */ diff --git a/gcc/c.opt b/gcc/c.opt index bafe6a14d8b..209f43ed4c8 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -289,6 +289,10 @@ Wmissing-format-attribute C ObjC C++ ObjC++ Warn about functions which might be candidates for format attributes +Wmissing-include-dirs +C ObjC C++ ObjC++ +Warn about user-specified include directories that do not exist + Wmissing-prototypes C ObjC Warn about global functions without prototypes diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 5ac0a19bec9..d006192afb3 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -264,6 +264,10 @@ struct cpp_options /* Nonzero means warn if slash-star appears in a comment. */ unsigned char warn_comments; + /* Nonzero means warn if a user-supplied include directory does not + exist. */ + unsigned char warn_missing_include_dirs; + /* Nonzero means warn if there are any trigraphs. */ unsigned char warn_trigraphs; @@ -439,6 +443,9 @@ struct cpp_dir directories in the search path. */ ino_t ino; dev_t dev; + + /* Is this a user-supplied directory? */ + bool user_supplied_p; }; /* Name under which this program was invoked. */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 09c538e4852..1ed9e6588f4 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -222,7 +222,8 @@ in the following sections. -Wno-invalid-offsetof -Winvalid-pch @gol -Wlarger-than-@var{len} -Wlong-long @gol -Wmain -Wmissing-braces @gol --Wmissing-format-attribute -Wmissing-noreturn @gol +-Wmissing-format-attribute -Wmissing-include-dirs @gol +-Wmissing-noreturn @gol -Wno-multichar -Wnonnull -Wpacked -Wpadded @gol -Wparentheses -Wpointer-arith -Wredundant-decls @gol -Wreturn-type -Wsequence-point -Wshadow @gol @@ -2224,6 +2225,10 @@ int a[2][2] = @{ 0, 1, 2, 3 @}; int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @}; @end smallexample +@item -Wmissing-include-dirs @r{(C, C++, and Objective-C only)} +@opindex Wmissing-include-dirs +Warn if a user-supplied include directory does not exist. + @item -Wparentheses @opindex Wparentheses Warn if parentheses are omitted in certain contexts, such diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 99dcf889ec0..95fc70c754e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-05-22 Ben Elliston + + * gcc.dg/cpp/Wmissingdirs.c: New. + 2004-05-20 H.J. Lu PR target/15301 @@ -5206,10 +5210,6 @@ PR c++/9559 * g++.dg/init/static1.C: New test. -2003-06-30 Volker Reichelt - - * Changelog: Remove ">>>>>>>" from previous change. - 2003-06-30 Volker Reichelt * g++.old-deja/g++.niklas/README: Fix spelling for "testcase". diff --git a/gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c b/gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c new file mode 100644 index 00000000000..915aaa8de98 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c @@ -0,0 +1,7 @@ +/* { dg-do preprocess } */ +/* { dg-options "-std=gnu99 -I /jolly/well/better/not/exist -Wmissing-include-dirs -fno-show-column" } */ + +/* Test that -Wmissing-include-dirs issues a warning when a specified + directory does not exist. Source Ben Elliston, 2004-05-13. */ + +/* { dg-warning "No such file or directory" "-Wmissing-include-dirs" { target *-*-* } 0 } */ -- 2.30.2