Waddress: warn about suspicious uses of memory addresses.

Manuel López-Ibáñez lopezibanez@gmail.com
Fri Feb 16 19:11:00 GMT 2007


This patch proposes a new option -Waddress to warn about suspicious
uses of memory addresses. A follow-up patch will add again
-Walways-true but this time actually warning for what its description
says it should warn.

This new option replaces 3 warnings: -Walways-true,
-Wstring-literal-comparison and an unconditional warning for a bare
reference to a function used in void context.

Replacing -Walways-true will prevent future confusion between the
original intent of -Walways-true and its name and description. This
has been explained in detail elsewhere [1].  The current mismatch is
leading to a situation similar to Wconversion, where the original
intent of the option is conflicting with the perceived meaning, but
worse in this case, since the perceived meaning is sanctioned by the
manual page but not by the implementation.

Even GCC developers are being confused by the current situation [2]. I
think we should fix this before a version of GCC with the current
-Walways-true is publicly released.

Also, there are other warnings that would be more suitable for
-Walways-true but they won't be for -Waddress [3]. This patch 'frees'
-Walways-true so it can be used for those warnings. Once this patch is
approved I will submit a follow-up for the new -Walways-true.

As for replacing -Wstrong-literal-comparison, its purpose matches
-Waddress and since it is a stated goal to avoid multiplication of
options as much as possible, I think it makes sense to integrate it
(and the name is shorter and nicer). But this is a secondary goal,
fixing -Walways-true is more important.

Lastly, the unconditional warning matched the original intent of
-Walways-true, however it didn't match its description. It matches
-Waddress, though.

Boostrapped and regression tested on i686-pc-linux-gnu.

[1] http://gcc.gnu.org/ml/gcc/2007-01/msg00480.html
[2] http://sourceware.org/ml/gdb-patches/2006-12/msg00351.html
[3] http://gcc.gnu.org/ml/gcc-patches/2007-01/msg01933.html


:ADDPATCH C/C++:

2007-02-16  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

  * c.opt (Waddress): New.
  * common.opt (Walways-true): Delete.
  (Wstring-literal-comparison): Delete.
  * doc/invoke.texi (Warning Options): Delete -Walways-true and
-Wstring-literal-comparison. Add -Waddress.
  (Waddress): New.
  (Walways-true): Delete.
  (Wstring-literal-comparison): Delete.
  * doc/extend.texi (#pragma GCC diagnostic): Use -Wformat
consistently instead of -Walways-true in example.
  * c-opts.c (c_common_handle_option): -Waddress is enabled by -Wall.
  * c-typeck.c (parser_build_binary_op): Replace
-Wstring-literal-comparison and -Walways-true with -Waddress.
  * c-common.c (c_common_truthvalue_conversion): Replace -Walways-true
with -Waddress.

cp/
  * typeck.c (build_binary_op): Replace -Wstring-literal-comparison
and -Walways-true with -Waddress.
  * cvt.c (convert_to_void): Replace unconditional warning with -Waddress.

testsuite/
  * gcc.dg/20031012-1.c: Replace -Walways-true with -Waddress.
  * gcc.dg/Walways-true-1.c: Likewise.
  * gcc.dg/weak/weak-3.c: Likewise.
  * gcc.dg/Werror-1.c: Likewise.
  * gcc.dg/Werror-3.c: Likewise.
  * gcc.dg/Werror-4.c: Likewise.
  * gcc.dg/Werror-5.c: Likewise.
  * gcc.dg/Werror-6.c: Likewise.
  * gcc.dg/Werror-7.c: Likewise.
  * gcc.dg/Werror-8.c: Likewise.
  * gcc.dg/Werror-10.c: Likewise.
  * gcc.dg/Werror-11.c: Likewise.
  * gcc.dg/Werror-12.c: Likewise.
  * g++.old-deja/g++.mike/warn8.C: Likewise.
  * g++.dg/warn/Walways-true-1.C: Likewise.
  * g++.dg/warn/Walways-true-2.C: Likewise.
  * g++.dg/warn/noeffect8.C: Warn only with -Waddress.
  * g++.dg/warn/Wstring-literal-comparison-1.C: Replace
-Wstring-literal-comparison with -Waddress.
  * gcc.dg/Wstring-literal-comparison-4.c: Replace
-Wno-string-literal-comparison with -Wno-address.
-------------- next part --------------
Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi	(revision 121953)
+++ gcc/doc/extend.texi	(working copy)
@@ -10149,8 +10149,8 @@ option.
 
 @example
 #pragma GCC diagnostic warning "-Wformat"
-#pragma GCC diagnostic error "-Walways-true"
-#pragma GCC diagnostic ignored "-Walways-true"
+#pragma GCC diagnostic error "-Wformat"
+#pragma GCC diagnostic ignored "-Wformat"
 @end example
 
 Note that these pragmas override any command line options.  Also,
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 121953)
+++ gcc/doc/invoke.texi	(working copy)
@@ -223,7 +223,7 @@ Objective-C and Objective-C++ Dialects}.
 @item Warning Options
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
 @gccoptlist{-fsyntax-only  -pedantic  -pedantic-errors @gol
--w  -Wextra  -Wall  -Waggregate-return -Walways-true -Warray-bounds @gol
+-w  -Wextra  -Wall  -Waddress  -Waggregate-return -Warray-bounds @gol
 -Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align  -Wcast-qual  @gol
 -Wchar-subscripts -Wclobbered  -Wcomment @gol
 -Wconversion -Wcoverage-mismatch -Wno-deprecated-declarations @gol
@@ -249,7 +249,6 @@ Objective-C and Objective-C++ Dialects}.
 -Wsign-compare  -Wstack-protector @gol
 -Wstrict-aliasing -Wstrict-aliasing=2 @gol
 -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
--Wstring-literal-comparison @gol
 -Wswitch  -Wswitch-default  -Wswitch-enum @gol
 -Wsystem-headers  -Wtrigraphs  -Wundef  -Wuninitialized @gol
 -Wunknown-pragmas  -Wno-pragmas -Wunreachable-code @gol
@@ -3381,18 +3380,27 @@ an incorrect result when the signed valu
 This warning is also enabled by @option{-Wextra}; to get the other warnings
 of @option{-Wextra} without this warning, use @samp{-Wextra -Wno-sign-compare}.
 
+@item -Waddress
+@opindex Waddress
+@opindex Wno-address
+Warn about suspicious uses of memory addresses. These include using
+the address of a function in a conditional expression, such as
+@code{void func(void); if (func)}, and comparisons against the memory
+address of a string literal, such as @code{if (x == "abc")}.  Such
+uses typically indicate a programmer error: the address of a function
+always evaluates to true, so their use in a conditional usually
+indicate that the programmer forgot the parentheses in a function
+call; and comparisons against string literals result in unspecified
+behavior and are not portable in C, so they usually indicate that the
+programmer intended to use @code{strcmp}.  This warning is enabled by
+@option{-Wall}.
+
 @item -Waggregate-return
 @opindex Waggregate-return
 Warn if any functions that return structures or unions are defined or
 called.  (In languages where you can return an array, this also elicits
 a warning.)
 
-@item -Walways-true
-@opindex Walways-true
-Warn about comparisons which are always true such as testing if
-unsigned values are greater than or equal to zero.  This warning is
-enabled by @option{-Wall}.
-
 @item -Wno-attributes
 @opindex Wno-attributes
 @opindex Wattributes
@@ -3742,15 +3750,6 @@ imply anything.
 This option is only active when @option{-fstack-protector} is active.  It
 warns about functions that will not be protected against stack smashing.
 
-@item -Wstring-literal-comparison
-@opindex Wstring-literal-comparison
-Warn about suspicious comparisons to string literal constants.  In C,
-direct comparisons against the memory address of a string literal, such
-as @code{if (x == "abc")}, typically indicate a programmer error, and
-even when intentional, result in unspecified behavior and are not portable.
-Usually these warnings alert that the programmer intended to use
-@code{strcmp}.  This warning is enabled by @option{-Wall}.
-
 @item -Woverlength-strings
 @opindex Woverlength-strings
 Warn about string constants which are longer than the ``minimum
Index: gcc/testsuite/gcc.dg/warn-addr-cmp.c
===================================================================
--- gcc/testsuite/gcc.dg/warn-addr-cmp.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/warn-addr-cmp.c	(working copy)
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
 /* { dg-require-weak "" } */
-/* { dg-options "-Walways-true" } */
+/* { dg-options "-Waddress" } */
 /* Warning when addr convert to bool always gives known result.
    Ada/Pascal programmers sometimes write 0-param functions without
    (), and might as well warn on variables, too.  */
Index: gcc/testsuite/gcc.dg/Werror-10.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-10.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-10.c	(working copy)
@@ -4,7 +4,7 @@
 
 /* Make sure #pragma can work with -Werror.  */
 
-#pragma GCC diagnostic error "-Walways-true"
+#pragma GCC diagnostic error "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "warning: .* attribute directive ignored" } */
 
Index: gcc/testsuite/gcc.dg/Walways-true-1.c
===================================================================
--- gcc/testsuite/gcc.dg/Walways-true-1.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Walways-true-1.c	(working copy)
@@ -1,8 +1,8 @@
-/* Test -Walways-true for testing an address against NULL.
+/* Test -Waddress for testing an address against NULL.
    Origin: Ian Lance Taylor <iant@google.com>.  */
 
 /* { dg-do compile} */
-/* { dg-options "-Walways-true" } */
+/* { dg-options "-Waddress" } */
 
 extern int foo (int);
 
Index: gcc/testsuite/gcc.dg/Werror-12.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-12.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-12.c	(working copy)
@@ -1,9 +1,9 @@
 /* { dg-do compile } */
-/* { dg-options "-Wattributes -Walways-true" } */
+/* { dg-options "-Wattributes -Waddress" } */
 
 /* Make sure #pragma can override -Wfoo.  */
 
-#pragma GCC diagnostic ignored "-Walways-true"
+#pragma GCC diagnostic ignored "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "attribute directive ignored" } */
 
Index: gcc/testsuite/gcc.dg/Werror-4.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-4.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-4.c	(working copy)
@@ -3,7 +3,7 @@
 
 /* Make sure the pragma enables the error.  */
 
-#pragma GCC diagnostic error "-Walways-true"
+#pragma GCC diagnostic error "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "warning: .* attribute directive ignored" } */
 
Index: gcc/testsuite/gcc.dg/20031012-1.c
===================================================================
--- gcc/testsuite/gcc.dg/20031012-1.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/20031012-1.c	(working copy)
@@ -1,4 +1,4 @@
-/* { dg-options "-Walways-true" } */
+/* { dg-options "-Waddress" } */
 /* Origin: Andrew Morton <akpm@osdl.org> */
 /* Warn if a function addres of a non-weak function is used
    as a truth value.  */
Index: gcc/testsuite/gcc.dg/Wstring-literal-comparison-4.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstring-literal-comparison-4.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Wstring-literal-comparison-4.c	(working copy)
@@ -1,6 +1,6 @@
 /* PR c/7776 */
 /* { dg-do compile } */
-/* { dg-options "-Wall -Wno-string-literal-comparison" } */
+/* { dg-options "-Wall -Wno-address" } */
 
 int test1(char *ptr)
 {
Index: gcc/testsuite/gcc.dg/Werror-6.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-6.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-6.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Wattributes -Werror=always-true" } */
+/* { dg-options "-Wattributes -Werror=address" } */
 
 /* Make sure -Werror-foo emits an error and not a warning */
 
Index: gcc/testsuite/gcc.dg/Werror-8.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-8.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-8.c	(working copy)
@@ -3,7 +3,7 @@
 
 /* Make sure #pragma can enable a warning.  */
 
-#pragma GCC diagnostic warning "-Walways-true"
+#pragma GCC diagnostic warning "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "warning: .* attribute directive ignored" } */
 
Index: gcc/testsuite/gcc.dg/weak/weak-3.c
===================================================================
--- gcc/testsuite/gcc.dg/weak/weak-3.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/weak/weak-3.c	(working copy)
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
 /* { dg-require-alias "" } */
 /* { dg-require-weak "" } */
-/* { dg-options "-fno-common -Walways-true" } */
+/* { dg-options "-fno-common -Waddress" } */
 
 /* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?ffoo1a" } } */
 /* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?ffoo1b" } } */
Index: gcc/testsuite/gcc.dg/Werror-1.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-1.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-1.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Walways-true -Wattributes -Werror" } */
+/* { dg-options "-Waddress -Wattributes -Werror" } */
 /* { dg-warning "warnings being treated as errors" "" {target "*-*-*"} 0 } */
 
 /* This is the first in a series of test cases that test the
@@ -7,7 +7,7 @@
    diagnostic error foo.  This one has all the bits we're testing, the
    others are subsets of this one.  */
 
-#pragma GCC diagnostic error "-Walways-true"
+#pragma GCC diagnostic error "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "warning: .* attribute directive ignored" } */
 
Index: gcc/testsuite/gcc.dg/Werror-11.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-11.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-11.c	(working copy)
@@ -4,7 +4,7 @@
 
 /* Make sure #pragma can override -Werror.  */
 
-#pragma GCC diagnostic warning "-Walways-true"
+#pragma GCC diagnostic warning "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "warning: .* attribute directive ignored" } */
 
Index: gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c	(working copy)
@@ -1,6 +1,6 @@
 /* PR c/7776 */
 /* { dg-do compile } */
-/* { dg-options "-Wstring-literal-comparison" } */
+/* { dg-options "-Waddress" } */
 
 int test1(char *ptr)
 {
Index: gcc/testsuite/gcc.dg/Werror-3.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-3.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-3.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Walways-true -Wattributes" } */
+/* { dg-options "-Waddress -Wattributes" } */
 
 /* Make sure the command line option enables the warning.  */
 
Index: gcc/testsuite/gcc.dg/Walways-true-2.c
===================================================================
--- gcc/testsuite/gcc.dg/Walways-true-2.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Walways-true-2.c	(working copy)
@@ -4,7 +4,7 @@
    Origin: Ian Lance Taylor <iant@google.com>.  */
 
 /* { dg-do compile} */
-/* { dg-options "-Walways-true" } */
+/* { dg-options "-Waddress" } */
 /* { dg-require-weak "" } */
 
 extern int foo (int) __attribute__ ((weak));
Index: gcc/testsuite/gcc.dg/Werror-5.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-5.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-5.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Walways-true -Wattributes -Werror" } */
+/* { dg-options "-Waddress -Wattributes -Werror" } */
 /* { dg-warning "warnings being treated as errors" "" {target "*-*-*"} 0 } */
 
 /* Make sure -Werror turns warnings in to errors.  */
Index: gcc/testsuite/gcc.dg/Werror-7.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-7.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-7.c	(working copy)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Walways-true -Werror -Wno-error=always-true -Wattributes" } */
+/* { dg-options "-Waddress -Werror -Wno-error=address -Wattributes" } */
 /* { dg-warning "warnings being treated as errors" "" {target "*-*-*"} 0 } */
 
 /* Make sure -Wno-error= overrides -Werror.  */
Index: gcc/testsuite/gcc.dg/Werror-9.c
===================================================================
--- gcc/testsuite/gcc.dg/Werror-9.c	(revision 121953)
+++ gcc/testsuite/gcc.dg/Werror-9.c	(working copy)
@@ -3,7 +3,7 @@
 
 /* Make sure #pragma can enable a warning as an error.  */
 
-#pragma GCC diagnostic error "-Walways-true"
+#pragma GCC diagnostic error "-Waddress"
 
 void __attribute__((dj)) bar() { }	/* { dg-warning "warning: .* attribute directive ignored" } */
 
Index: gcc/testsuite/g++.old-deja/g++.mike/warn8.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.mike/warn8.C	(revision 121953)
+++ gcc/testsuite/g++.old-deja/g++.mike/warn8.C	(working copy)
@@ -1,5 +1,5 @@
 // { dg-do assemble  }
-// { dg-options "-Walways-true" }
+// { dg-options "-Waddress" }
 
 struct foo {
   bool test();
Index: gcc/testsuite/g++.dg/warn/Walways-true-1.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Walways-true-1.C	(revision 121953)
+++ gcc/testsuite/g++.dg/warn/Walways-true-1.C	(working copy)
@@ -1,8 +1,8 @@
-// Test -Walways-true for testing an address against NULL.
+// Test -Waddress for testing an address against NULL.
 // Origin: Ian Lance Taylor <iant@google.com>
 
 // { dg-do compile}
-// { dg-options "-Walways-true" }
+// { dg-options "-Waddress" }
 
 extern int foo (int);
 
Index: gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C	(revision 121953)
+++ gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C	(working copy)
@@ -1,6 +1,6 @@
 /* PR c/7776 */
 /* { dg-do compile } */
-/* { dg-options "-Wstring-literal-comparison" } */
+/* { dg-options "-Waddress" } */
 
 int test1(char *ptr)
 {
Index: gcc/testsuite/g++.dg/warn/Walways-true-2.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Walways-true-2.C	(revision 121953)
+++ gcc/testsuite/g++.dg/warn/Walways-true-2.C	(working copy)
@@ -4,7 +4,7 @@
 // Origin: Ian Lance Taylor <iant@google.com>
 
 // { dg-do compile}
-// { dg-options "-Walways-true" }
+// { dg-options "-Waddress" }
 // { dg-require-weak "" }
 
 extern int foo (int) __attribute__ ((weak));
Index: gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C	(revision 121953)
+++ gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C	(working copy)
@@ -1,6 +1,6 @@
 /* PR c/7776 */
 /* { dg-do compile } */
-/* { dg-options "-Wall -Wno-string-literal-comparison" } */
+/* { dg-options "-Wall -Wno-address" } */
 
 int test1(char *ptr)
 {
Index: gcc/testsuite/g++.dg/warn/noeffect8.C
===================================================================
--- gcc/testsuite/g++.dg/warn/noeffect8.C	(revision 121953)
+++ gcc/testsuite/g++.dg/warn/noeffect8.C	(working copy)
@@ -1,4 +1,6 @@
 // PR c++/26696, 28996
+// { dg-do compile }
+// { dg-options "-Waddress" }
 
 struct A
 {
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 121953)
+++ gcc/cp/typeck.c	(working copy)
@@ -3319,8 +3319,7 @@ build_binary_op (enum tree_code code, tr
 		 "comparing floating point with == or != is unsafe");
       if ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1))
 	  || (TREE_CODE (orig_op1) == STRING_CST && !integer_zerop (op0)))
-	warning (OPT_Wstring_literal_comparison,
-		 "comparison with string literal");
+	warning (OPT_Waddress, "comparison with string literal results in unspecified behaviour");
 
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
@@ -3337,7 +3336,7 @@ build_binary_op (enum tree_code code, tr
 	{
 	  if (TREE_CODE (op0) == ADDR_EXPR
 	      && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
-	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
+	    warning (OPT_Waddress, "the address of %qD will never be NULL",
 		     TREE_OPERAND (op0, 0));
 	  result_type = type0;
 	}
@@ -3346,7 +3345,7 @@ build_binary_op (enum tree_code code, tr
 	{
 	  if (TREE_CODE (op1) == ADDR_EXPR 
 	      && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
-	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
+	    warning (OPT_Waddress, "the address of %qD will never be NULL",
 		     TREE_OPERAND (op1, 0));
 	  result_type = type1;
 	}
@@ -3495,8 +3494,7 @@ build_binary_op (enum tree_code code, tr
     case GT_EXPR:
       if (TREE_CODE (orig_op0) == STRING_CST
 	  || TREE_CODE (orig_op1) == STRING_CST)
-	warning (OPT_Wstring_literal_comparison,
-		 "comparison with string literal");
+	warning (OPT_Waddress, "comparison with string literal results in unspecified behaviour");
 
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
Index: gcc/cp/cvt.c
===================================================================
--- gcc/cp/cvt.c	(revision 121953)
+++ gcc/cp/cvt.c	(working copy)
@@ -927,7 +927,7 @@ convert_to_void (tree expr, const char *
     else if (implicit && probe == expr && is_overloaded_fn (probe))
       {
 	/* Only warn when there is no &.  */
-	warning (0, "%s is a reference, not call, to function %qE",
+	warning (OPT_Waddress, "%s is a reference, not call, to function %qE",
 		 implicit, expr);
 	if (TREE_CODE (expr) == COMPONENT_REF)
 	  expr = TREE_OPERAND (expr, 0);
Index: gcc/c.opt
===================================================================
--- gcc/c.opt	(revision 121953)
+++ gcc/c.opt	(working copy)
@@ -116,6 +116,10 @@ Wabi
 C++ ObjC++ Var(warn_abi) Warning
 Warn about things that will change when compiling with an ABI-compliant compiler
 
+Waddress
+C ObjC C++ ObjC++ Var(warn_address) Warning
+Warn about suspicious uses of memory addresses
+
 Wall
 C ObjC C++ ObjC++ Warning
 Enable most warning messages
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 121953)
+++ gcc/c-typeck.c	(working copy)
@@ -2640,13 +2640,11 @@ parser_build_binary_op (enum tree_code c
     {
       if ((code1 == STRING_CST && !integer_zerop (arg2.value))
 	  || (code2 == STRING_CST && !integer_zerop (arg1.value)))
-	warning (OPT_Wstring_literal_comparison,
-		 "comparison with string literal");
+	warning (OPT_Waddress, "comparison with string literal results in unspecified behaviour");
     }
   else if (TREE_CODE_CLASS (code) == tcc_comparison
 	   && (code1 == STRING_CST || code2 == STRING_CST))
-    warning (OPT_Wstring_literal_comparison,
-	     "comparison with string literal");
+    warning (OPT_Waddress, "comparison with string literal results in unspecified behaviour");
 
   if (TREE_OVERFLOW_P (result.value) 
       && !TREE_OVERFLOW_P (arg1.value) 
@@ -8025,7 +8023,7 @@ build_binary_op (enum tree_code code, tr
 	{
 	  if (TREE_CODE (op0) == ADDR_EXPR
 	      && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
-	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
+	    warning (OPT_Waddress, "the address of %qD will never be NULL",
 		     TREE_OPERAND (op0, 0));
 	  result_type = type0;
 	}
@@ -8033,7 +8031,7 @@ build_binary_op (enum tree_code code, tr
 	{
 	  if (TREE_CODE (op1) == ADDR_EXPR
 	      && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
-	    warning (OPT_Walways_true, "the address of %qD will never be NULL",
+	    warning (OPT_Waddress, "the address of %qD will never be NULL",
 		     TREE_OPERAND (op1, 0));
 	  result_type = type1;
 	}
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c	(revision 121953)
+++ gcc/c-opts.c	(working copy)
@@ -395,9 +395,8 @@ c_common_handle_option (size_t scode, co
 	warn_sign_compare = value;
       warn_switch = value;
       warn_strict_aliasing = value;
+      warn_address = value;
       warn_strict_overflow = value;
-      warn_string_literal_comparison = value;
-      warn_always_true = value;
       warn_array_bounds = value;
 
       /* Only warn about unknown pragmas that are not in system
Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 121953)
+++ gcc/common.opt	(working copy)
@@ -74,10 +74,6 @@ Waggregate-return
 Common Var(warn_aggregate_return) Warning
 Warn about returning structures, unions or arrays
 
-Walways-true
-Common Var(warn_always_true) Warning
-Warn about comparisons that always evaluate to true
-
 Warray-bounds
 Common Var(warn_array_bounds)
 Warn if an array is accessed out of bounds
@@ -166,10 +162,6 @@ Wstrict-overflow=
 Common Joined UInteger
 Warn about optimizations that assume that signed overflow is undefined
 
-Wstring-literal-comparison
-Common Var(warn_string_literal_comparison) Warning
-Warn about comparisons to constant string literals
-
 Wswitch
 Common Var(warn_switch) Warning
 Warn about enumerated switches, with no default, missing a case
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c	(revision 121953)
+++ gcc/c-common.c	(working copy)
@@ -2709,7 +2709,7 @@ c_common_truthvalue_conversion (tree exp
 	if (decl_with_nonnull_addr_p (inner))
 	  {
 	    /* Common Ada/Pascal programmer's mistake.  */
-	    warning (OPT_Walways_true,
+	    warning (OPT_Waddress,
 		     "the address of %qD will always evaluate as %<true%>",
 		     inner);
 	    return truthvalue_true_node;


More information about the Gcc-patches mailing list