aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSimon Baldwin <simonb@google.com>2008-09-18 15:39:08 +0000
committerSimon Baldwin <simonb@gcc.gnu.org>2008-09-18 15:39:08 +0000
commitc047ce93830ab288948c3e225fc8c5efdfbe3c2a (patch)
treee6725c527874d936bd2e164a6a7f885ebaffaf47 /gcc
parent1d295886287812ee7e5b5bfc63ff598a2a9e9958 (diff)
downloadgcc-c047ce93830ab288948c3e225fc8c5efdfbe3c2a.zip
gcc-c047ce93830ab288948c3e225fc8c5efdfbe3c2a.tar.gz
gcc-c047ce93830ab288948c3e225fc8c5efdfbe3c2a.tar.bz2
cpplib.h (struct cpp_options): Add new boolean flag warn_builtin_macro_redefined.
* include/cpplib.h (struct cpp_options): Add new boolean flag warn_builtin_macro_redefined. * init.c (cpp_create_reader): Initialize warn_builtin_macro_redefined. * (struct builtin_operator): Split out from previous struct builtin, enhance extra const correctness. * (struct builtin_macro): Split out from previous struct builtin, add new always_warn_if_redefined flag, enhance const correctness. * (mark_named_operators): Use struct builtin_operator. * (cpp_init_special_builtins): Use struct builtin_macro, add NODE_WARN to builtins selectively. * macro.c (warn_of_redefinition): Return false if a builtin macro is not flagged with NODE_WARN. * c-opts.c (c_common_handle_option): Add handling for -Wbuiltin-macro-redefined command line option. * c.opt: Added builtin-macro-redefined option. * doc/invoke.texi (Warning Options): Add -Wbuiltin-macro-redefined documentation. * gcc.dg/builtin-redefine.c: New. From-SVN: r140461
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-opts.c4
-rw-r--r--gcc/c.opt4
-rw-r--r--gcc/doc/invoke.texi10
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/builtin-redefine.c79
6 files changed, 108 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9f9ddde..99b34c5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2008-09-18 Simon Baldwin <simonb@google.com>
+
+ * c-opts.c (c_common_handle_option): Add handling for
+ -Wbuiltin-macro-redefined command line option.
+ * c.opt: Added builtin-macro-redefined option.
+ * doc/invoke.texi (Warning Options): Add -Wbuiltin-macro-redefined
+ documentation.
+
2008-09-18 Richard Guenther <rguenther@suse.de>
PR tree-optimization/37258
diff --git a/gcc/c-opts.c b/gcc/c-opts.c
index 164ca4a..589b05b 100644
--- a/gcc/c-opts.c
+++ b/gcc/c-opts.c
@@ -426,6 +426,10 @@ c_common_handle_option (size_t scode, const char *arg, int value)
warn_pointer_sign = 1;
break;
+ case OPT_Wbuiltin_macro_redefined:
+ cpp_opts->warn_builtin_macro_redefined = value;
+ break;
+
case OPT_Wcomment:
case OPT_Wcomments:
cpp_opts->warn_comments = value;
diff --git a/gcc/c.opt b/gcc/c.opt
index d33fa46..94d6047 100644
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -131,6 +131,10 @@ Wbad-function-cast
C ObjC Var(warn_bad_function_cast) Warning
Warn about casting functions to incompatible types
+Wbuiltin-macro-redefined
+C ObjC C++ ObjC++ Warning
+Warn when a built-in preprocessor macro is undefined or redefined
+
Wc++-compat
C ObjC Var(warn_cxx_compat) Warning
Warn about C constructs that are not in the common subset of C and C++
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e9aae02..05fc091 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -228,7 +228,8 @@ Objective-C and Objective-C++ Dialects}.
@xref{Warning Options,,Options to Request or Suppress Warnings}.
@gccoptlist{-fsyntax-only -pedantic -pedantic-errors @gol
-w -Wextra -Wall -Waddress -Waggregate-return -Warray-bounds @gol
--Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol
+-Wno-attributes -Wno-builtin-macro-redefined @gol
+-Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol
-Wchar-subscripts -Wclobbered -Wcomment @gol
-Wconversion -Wcoverage-mismatch -Wno-deprecated @gol
-Wno-deprecated-declarations -Wdisabled-optimization @gol
@@ -3731,6 +3732,13 @@ unrecognized attributes, function attributes applied to variables,
etc. This will not stop errors for incorrect use of supported
attributes.
+@item -Wno-builtin-macro-redefined
+@opindex Wno-builtin-macro-redefined
+@opindex Wbuiltin-macro-redefined
+Do not warn if certain built-in macros are redefined. This suppresses
+warnings for redefinition of @code{__TIMESTAMP__}, @code{__TIME__},
+@code{__DATE__}, @code{__FILE__}, and @code{__BASE_FILE__}.
+
@item -Wstrict-prototypes @r{(C and Objective-C only)}
@opindex Wstrict-prototypes
@opindex Wno-strict-prototypes
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e8d9846..dbeb7e6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2008-09-18 Simon Baldwin <simonb@google.com>
+
+ * gcc.dg/builtin-redefine.c: New.
+
2008-09-18 Richard Guenther <rguenther@suse.de>
PR tree-optimization/37258
diff --git a/gcc/testsuite/gcc.dg/builtin-redefine.c b/gcc/testsuite/gcc.dg/builtin-redefine.c
new file mode 100644
index 0000000..f94d3f3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-redefine.c
@@ -0,0 +1,79 @@
+/* Test -Wno-builtin-macro-redefined warnings. */
+
+/* { dg-do compile } */
+/* { dg-options "-Wno-builtin-macro-redefined -U__DATE__ -D__TIME__=X" } */
+
+/* Check date, time, and datestamp built-ins warnings may be suppressed. */
+
+#if defined(__DATE__)
+#error "__DATE__ is defined, but should not be (-U command line error)"
+/* { dg-bogus "__DATE__ is defined" "" { target *-*-* } 9 } */
+#endif
+
+#if __TIME__ != X
+#error "__TIME__ is not defined as expected (-D command line error)"
+/* { dg-bogus "__TIME__ is not defined" "" { target *-*-* } 14 } */
+#endif
+
+#if !defined(__TIMESTAMP__)
+#error "__TIMESTAMP__ is not defined (built-in macro expectation error)"
+/* { dg-bogus "__TIMESTAMP__ is not defined" "" { target *-*-* } 19 } */
+#endif
+
+
+#undef __TIME__ /* Undefine while defined. */
+#undef __TIME__ /* Undefine while already undefined. */
+
+#define __TIME__ "X" /* Define while undefined. */
+#define __TIME__ "X" /* Re-define while defined. */
+
+#define __TIME__ "Y" /* { dg-warning "\"__TIME__\" redefined" } */
+/* { dg-warning "previous definition" "" { target *-*-* } 28 } */
+
+#undef __TIME__ /* Undefine while defined. */
+
+
+#undef __DATE__ /* Undefine while already undefined. */
+
+#define __DATE__ "X" /* Define while undefined. */
+#define __DATE__ "X" /* Re-define while defined. */
+
+#define __DATE__ "Y" /* { dg-warning "\"__DATE__\" redefined" } */
+/* { dg-warning "previous definition" "" { target *-*-* } 39 } */
+
+#undef __DATE__ /* Undefine while defined. */
+
+
+#define __TIMESTAMP__ "X" /* Define while already defined. */
+#define __TIMESTAMP__ "X" /* Re-define while defined. */
+
+#define __TIMESTAMP__ "Y" /* { dg-warning "\"__TIMESTAMP__\" redefined" } */
+/* { dg-warning "previous definition" "" { target *-*-* } 48 } */
+
+#undef __TIMESTAMP__ /* Undefine while defined. */
+
+
+/* Check other built-ins with warnings that may be suppressed. */
+
+#if !defined(__FILE__) || !defined(__BASE_FILE__)
+#error "Expected built-in is not defined (built-in macro expectation error)"
+/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } 59 } */
+#endif
+
+#define __FILE__ "X" /* Define while already defined. */
+#define __BASE_FILE__ "X" /* Define while already defined. */
+
+
+/* Check selected built-ins not affected by warning suppression. */
+
+#if !defined(__LINE__) || !defined(__INCLUDE_LEVEL__) || !defined(__COUNTER__)
+#error "Expected built-in is not defined (built-in macro expectation error)"
+/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } 70 } */
+#endif
+
+#define __LINE__ 0 /* { dg-warning "\"__LINE__\" redef" } */
+#define __INCLUDE_LEVEL__ 0 /* { dg-warning "\"__INCLUDE_LEVEL__\" redef" } */
+#define __COUNTER__ 0 /* { dg-warning "\"__COUNTER__\" redef" } */
+
+
+int unused; /* Silence `ISO C forbids an empty translation unit' warning. */