This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PR c/25892]: disable -Wpointer-sign by default
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 25 Jan 2006 23:29:49 -0200
- Subject: [PR c/25892]: disable -Wpointer-sign by default
This patch implements the AFAIK-agreed-by-SC-and-RMS behavior for
-Wpointer-sign, removing the only blocker for GCC 4.1. Branch
bootstrapped and regression tested on amd64-linux-gnu. Ok for branch
and mainline, if forward-porting proves to be trivial?
Index: gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c/25892
* c.opt (Wpointer-sign): Init to -1.
* c-opts.c (c_common_handle_option): Set to 1 on OPT_Wall and
OPT_pedantic, to 0 otherwise.
* doc/invoke.texi: Update.
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR c/25892
* gcc.dg/Wpointer-sign.c: New.
* gcc.dg/Wpointer-sign-Wall.c: New.
* gcc.dg/Wpointer-sign-Wall-no.c: New.
* gcc.dg/Wpointer-sign-pedantic.c: New.
* gcc.dg/Wpointer-sign-pedantic-no.c: New.
* gcc.dg/conv-2.c: Use -Wpointer-sign.
Index: gcc/c.opt
===================================================================
--- gcc/c.opt.orig 2006-01-25 16:01:26.000000000 -0200
+++ gcc/c.opt 2006-01-25 16:02:28.000000000 -0200
@@ -420,7 +420,7 @@ C ObjC C++ ObjC++
Give strings the type \"array of char\"
Wpointer-sign
-C ObjC Var(warn_pointer_sign) Init(1)
+C ObjC Var(warn_pointer_sign) Init(-1)
Warn when a pointer differs in signedness in an assignment
ansi
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c.orig 2006-01-25 16:01:26.000000000 -0200
+++ gcc/c-opts.c 2006-01-25 16:02:28.000000000 -0200
@@ -413,6 +413,9 @@ c_common_handle_option (size_t scode, co
cpp_opts->warn_comments = value;
cpp_opts->warn_num_sign_change = value;
cpp_opts->warn_multichar = value; /* Was C++ only. */
+
+ if (warn_pointer_sign == -1)
+ warn_pointer_sign = 1;
break;
case OPT_Wcomment:
@@ -874,6 +877,8 @@ c_common_handle_option (size_t scode, co
case OPT_pedantic:
cpp_opts->pedantic = 1;
cpp_opts->warn_endif_labels = 1;
+ if (warn_pointer_sign == -1)
+ warn_pointer_sign = 1;
break;
case OPT_print_objc_runtime_info:
@@ -994,6 +999,11 @@ c_common_post_options (const char **pfil
if (warn_missing_field_initializers == -1)
warn_missing_field_initializers = extra_warnings;
+ /* -Wpointer_sign is disabled by default, but it is enabled if any
+ of -Wall or -pedantic are given. */
+ if (warn_pointer_sign == -1)
+ warn_pointer_sign = 0;
+
/* Special format checking options don't work without -Wformat; warn if
they are used. */
if (!warn_format)
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi.orig 2006-01-25 16:01:26.000000000 -0200
+++ gcc/doc/invoke.texi 2006-01-25 16:02:28.000000000 -0200
@@ -251,7 +251,7 @@ Objective-C and Objective-C++ Dialects}.
@gccoptlist{-Wbad-function-cast -Wmissing-declarations @gol
-Wmissing-prototypes -Wnested-externs -Wold-style-definition @gol
-Wstrict-prototypes -Wtraditional @gol
--Wdeclaration-after-statement -Wno-pointer-sign}
+-Wdeclaration-after-statement -Wpointer-sign}
@item Debugging Options
@xref{Debugging Options,,Options for Debugging Your Program or GCC}.
@@ -3385,11 +3385,13 @@ effectively. Often, the problem is that
complex; GCC will refuse to optimize programs when the optimization
itself is likely to take inordinate amounts of time.
-@item -Wno-pointer-sign
+@item -Wpointer-sign
+@opindex Wpointer-sign
@opindex Wno-pointer-sign
-Don't warn for pointer argument passing or assignment with different signedness.
-Only useful in the negative form since this warning is enabled by default.
-This option is only supported for C and Objective-C@.
+Warn for pointer argument passing or assignment with different signedness.
+This option is only supported for C and Objective-C@. It is implied by
+@option{-Wall} and by @option{-pedantic}, which can be disabled with
+@option{-Wno-pointer-sign}.
@item -Werror
@opindex Werror
Index: gcc/testsuite/gcc.dg/Wpointer-sign.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-sign.c 2006-01-25 23:22:24.000000000 -0200
@@ -0,0 +1,13 @@
+/* This is from PR c/25892. The SC promised RMS that -Wpointer-sign
+ would be off by default in GCC 4.1 to avoid inconvenient warnings
+ while compiling GNU Emacs. It should be enabled with -Wall and/or
+ -pedantic, though. Make sure it's off by default in this test (so
+ use dg-options "" to avoid passing -pedantic-errors). */
+
+/* { dg-options "" } */
+
+void foo(unsigned long* ulp);
+
+void bar(long* lp) {
+ foo(lp);
+}
Index: gcc/testsuite/gcc.dg/Wpointer-sign-Wall-no.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-sign-Wall-no.c 2006-01-25 16:02:28.000000000 -0200
@@ -0,0 +1,9 @@
+/* This is from PR c/25892. See Wpointer-sign.c for more details. */
+
+/* { dg-options "-Wno-pointer-sign -Wall" } */
+
+void foo(unsigned long* ulp);
+
+void bar(long* lp) {
+ foo(lp);
+}
Index: gcc/testsuite/gcc.dg/Wpointer-sign-Wall.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-sign-Wall.c 2006-01-25 16:02:28.000000000 -0200
@@ -0,0 +1,9 @@
+/* This is from PR c/25892. See Wpointer-sign.c for more details. */
+
+/* { dg-options "-Wall" } */
+
+void foo(unsigned long* ulp);
+
+void bar(long* lp) {
+ foo(lp); /* { dg-warning "differ in signedness" } */
+}
Index: gcc/testsuite/gcc.dg/Wpointer-sign-pedantic-no.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-sign-pedantic-no.c 2006-01-25 16:02:28.000000000 -0200
@@ -0,0 +1,9 @@
+/* This is from PR c/25892. See Wpointer-sign.c for more details. */
+
+/* { dg-options "-Wno-pointer-sign -pedantic" } */
+
+void foo(unsigned long* ulp);
+
+void bar(long* lp) {
+ foo(lp);
+}
Index: gcc/testsuite/gcc.dg/Wpointer-sign-pedantic.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/Wpointer-sign-pedantic.c 2006-01-25 16:02:28.000000000 -0200
@@ -0,0 +1,9 @@
+/* This is from PR c/25892. See Wpointer-sign.c for more details. */
+
+/* { dg-options "-pedantic" } */
+
+void foo(unsigned long* ulp);
+
+void bar(long* lp) {
+ foo(lp); /* { dg-warning "differ in signedness" } */
+}
Index: gcc/testsuite/gcc.dg/conv-2.c
===================================================================
--- gcc/testsuite/gcc.dg/conv-2.c.orig 2006-01-25 23:20:06.000000000 -0200
+++ gcc/testsuite/gcc.dg/conv-2.c 2006-01-25 23:23:24.000000000 -0200
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-Wpointer-sign" } */
void f1(long *);
void f2(unsigned long *);
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}