Commit b02398bd by Ben Elliston Committed by Ben Elliston

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
parent 12fea1f9
2004-05-22 Ben Elliston <bje@au.ibm.com>
* 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 <uweigand@de.ibm.com> 2004-05-21 Ulrich Weigand <uweigand@de.ibm.com>
* fold-const.c (fold_read_from_constant_string): Convert result to * fold-const.c (fold_read_from_constant_string): Convert result to
......
...@@ -114,7 +114,7 @@ add_env_var_paths (const char *env_var, int chain) ...@@ -114,7 +114,7 @@ add_env_var_paths (const char *env_var, int chain)
path[q - p] = '\0'; 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) ...@@ -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)) if (!strncmp (p->fname, cpp_GCC_INCLUDE_DIR, len))
{ {
char *str = concat (iprefix, p->fname + len, NULL); 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) ...@@ -160,7 +160,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, int cxx_stdinc)
else else
str = update_path (p->fname, p->component); str = update_path (p->fname, p->component);
add_path (str, SYSTEM, p->cxx_aware); add_path (str, SYSTEM, p->cxx_aware, false);
} }
} }
} }
...@@ -192,8 +192,14 @@ remove_duplicates (cpp_reader *pfile, struct cpp_dir *head, ...@@ -192,8 +192,14 @@ remove_duplicates (cpp_reader *pfile, struct cpp_dir *head,
if (errno != ENOENT) if (errno != ENOENT)
cpp_errno (pfile, CPP_DL_ERROR, cur->name); cpp_errno (pfile, CPP_DL_ERROR, cur->name);
else else
{
/* 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; reason = REASON_NOENT;
} }
}
else if (!S_ISDIR (st.st_mode)) else if (!S_ISDIR (st.st_mode))
cpp_error_with_line (pfile, CPP_DL_ERROR, 0, 0, cpp_error_with_line (pfile, CPP_DL_ERROR, 0, 0,
"%s: not a directory", cur->name); "%s: not a directory", cur->name);
...@@ -317,7 +323,7 @@ add_cpp_dir_path (cpp_dir *p, int chain) ...@@ -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 /* Add PATH to the include chain CHAIN. PATH must be malloc-ed and
NUL-terminated. */ NUL-terminated. */
void 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; cpp_dir *p;
...@@ -329,12 +335,9 @@ add_path (char *path, int chain, int cxx_aware) ...@@ -329,12 +335,9 @@ add_path (char *path, int chain, int cxx_aware)
else else
p->sysp = 0; p->sysp = 0;
p->construct = 0; p->construct = 0;
p->user_supplied_p = user_supplied_p;
if (tails[chain]) add_cpp_dir_path (p, chain);
tails[chain]->next = p;
else
heads[chain] = p;
tails[chain] = p;
} }
/* Exported function to handle include chain merging, duplicate /* Exported function to handle include chain merging, duplicate
......
...@@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software ...@@ -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. */ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
extern void split_quote_chain (void); 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 *, extern void register_include_chains (cpp_reader *, const char *,
const char *, int, int, int); const char *, int, int, int);
extern void add_cpp_dir_path (struct cpp_dir *, int); extern void add_cpp_dir_path (struct cpp_dir *, int);
......
...@@ -297,7 +297,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -297,7 +297,7 @@ c_common_handle_option (size_t scode, const char *arg, int value)
case OPT_I: case OPT_I:
if (strcmp (arg, "-")) if (strcmp (arg, "-"))
add_path (xstrdup (arg), BRACKET, 0); add_path (xstrdup (arg), BRACKET, 0, true);
else else
{ {
if (quote_chain_split) if (quote_chain_split)
...@@ -541,6 +541,10 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -541,6 +541,10 @@ c_common_handle_option (size_t scode, const char *arg, int value)
warn_missing_format_attribute = value; warn_missing_format_attribute = value;
break; break;
case OPT_Wmissing_include_dirs:
cpp_opts->warn_missing_include_dirs = value;
break;
case OPT_Wmissing_prototypes: case OPT_Wmissing_prototypes:
warn_missing_prototypes = value; warn_missing_prototypes = value;
break; break;
...@@ -939,7 +943,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -939,7 +943,7 @@ c_common_handle_option (size_t scode, const char *arg, int value)
break; break;
case OPT_idirafter: case OPT_idirafter:
add_path (xstrdup (arg), AFTER, 0); add_path (xstrdup (arg), AFTER, 0, true);
break; break;
case OPT_imacros: case OPT_imacros:
...@@ -952,7 +956,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -952,7 +956,7 @@ c_common_handle_option (size_t scode, const char *arg, int value)
break; break;
case OPT_iquote: case OPT_iquote:
add_path (xstrdup (arg), QUOTE, 0); add_path (xstrdup (arg), QUOTE, 0, true);
break; break;
case OPT_isysroot: case OPT_isysroot:
...@@ -960,7 +964,7 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -960,7 +964,7 @@ c_common_handle_option (size_t scode, const char *arg, int value)
break; break;
case OPT_isystem: case OPT_isystem:
add_path (xstrdup (arg), SYSTEM, 0); add_path (xstrdup (arg), SYSTEM, 0, true);
break; break;
case OPT_iwithprefix: case OPT_iwithprefix:
...@@ -1390,7 +1394,7 @@ add_prefixed_path (const char *suffix, size_t chain) ...@@ -1390,7 +1394,7 @@ add_prefixed_path (const char *suffix, size_t chain)
memcpy (path + prefix_len, suffix, suffix_len); memcpy (path + prefix_len, suffix, suffix_len);
path[prefix_len + suffix_len] = '\0'; 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. */ /* Handle -D, -U, -A, -imacros, and the first -include. */
......
...@@ -289,6 +289,10 @@ Wmissing-format-attribute ...@@ -289,6 +289,10 @@ Wmissing-format-attribute
C ObjC C++ ObjC++ C ObjC C++ ObjC++
Warn about functions which might be candidates for format attributes 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 Wmissing-prototypes
C ObjC C ObjC
Warn about global functions without prototypes Warn about global functions without prototypes
......
...@@ -264,6 +264,10 @@ struct cpp_options ...@@ -264,6 +264,10 @@ struct cpp_options
/* Nonzero means warn if slash-star appears in a comment. */ /* Nonzero means warn if slash-star appears in a comment. */
unsigned char warn_comments; 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. */ /* Nonzero means warn if there are any trigraphs. */
unsigned char warn_trigraphs; unsigned char warn_trigraphs;
...@@ -439,6 +443,9 @@ struct cpp_dir ...@@ -439,6 +443,9 @@ struct cpp_dir
directories in the search path. */ directories in the search path. */
ino_t ino; ino_t ino;
dev_t dev; dev_t dev;
/* Is this a user-supplied directory? */
bool user_supplied_p;
}; };
/* Name under which this program was invoked. */ /* Name under which this program was invoked. */
......
...@@ -222,7 +222,8 @@ in the following sections. ...@@ -222,7 +222,8 @@ in the following sections.
-Wno-invalid-offsetof -Winvalid-pch @gol -Wno-invalid-offsetof -Winvalid-pch @gol
-Wlarger-than-@var{len} -Wlong-long @gol -Wlarger-than-@var{len} -Wlong-long @gol
-Wmain -Wmissing-braces @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 -Wno-multichar -Wnonnull -Wpacked -Wpadded @gol
-Wparentheses -Wpointer-arith -Wredundant-decls @gol -Wparentheses -Wpointer-arith -Wredundant-decls @gol
-Wreturn-type -Wsequence-point -Wshadow @gol -Wreturn-type -Wsequence-point -Wshadow @gol
...@@ -2224,6 +2225,10 @@ int a[2][2] = @{ 0, 1, 2, 3 @}; ...@@ -2224,6 +2225,10 @@ int a[2][2] = @{ 0, 1, 2, 3 @};
int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @}; int b[2][2] = @{ @{ 0, 1 @}, @{ 2, 3 @} @};
@end smallexample @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 @item -Wparentheses
@opindex Wparentheses @opindex Wparentheses
Warn if parentheses are omitted in certain contexts, such Warn if parentheses are omitted in certain contexts, such
......
2004-05-22 Ben Elliston <bje@au.ibm.com>
* gcc.dg/cpp/Wmissingdirs.c: New.
2004-05-20 H.J. Lu <hongjiu.lu@intel.com> 2004-05-20 H.J. Lu <hongjiu.lu@intel.com>
PR target/15301 PR target/15301
...@@ -5208,10 +5212,6 @@ ...@@ -5208,10 +5212,6 @@
2003-06-30 Volker Reichelt <reichelt@igpm.rwth-aachen.de> 2003-06-30 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
* Changelog: Remove ">>>>>>>" from previous change.
2003-06-30 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
* g++.old-deja/g++.niklas/README: Fix spelling for "testcase". * g++.old-deja/g++.niklas/README: Fix spelling for "testcase".
* g++.old-deja/g++.other/access2.C: Likewise. * g++.old-deja/g++.other/access2.C: Likewise.
* g++.old-deja/g++.other/decl2.C: Likewise. * g++.old-deja/g++.other/decl2.C: Likewise.
......
/* { 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 } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment