* c.opt (Wmissing-include-dirs): New.
authorbje <bje@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 May 2004 02:39:35 +0000 (02:39 +0000)
committerbje <bje@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 May 2004 02:39:35 +0000 (02:39 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82121 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-incpath.c
gcc/c-incpath.h
gcc/c-opts.c
gcc/c.opt
gcc/cpplib.h
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c [new file with mode: 0644]

index a0e205e..9de23e4 100644 (file)
@@ -1,3 +1,20 @@
+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>
 
        * fold-const.c (fold_read_from_constant_string): Convert result to
index b4da86f..ea83c1a 100644 (file)
@@ -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
index 30d7fd6..1096016 100644 (file)
@@ -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);
index 1300b69..47c7024 100644 (file)
@@ -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.  */
index bafe6a1..209f43e 100644 (file)
--- 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
index 5ac0a19..d006192 100644 (file)
@@ -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.  */
index 09c538e..1ed9e65 100644 (file)
@@ -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
index 99dcf88..95fc70c 100644 (file)
@@ -1,3 +1,7 @@
+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>
 
        PR target/15301
 
 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++.other/access2.C: Likewise.
        * g++.old-deja/g++.other/decl2.C: Likewise.
diff --git a/gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c b/gcc/testsuite/gcc.dg/cpp/Wmissingdirs.c
new file mode 100644 (file)
index 0000000..915aaa8
--- /dev/null
@@ -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 } */