From 55972f40444d3f281db0fc4bf814e8a40e66410c Mon Sep 17 00:00:00 2001
From: sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 1 May 2006 04:27:15 +0000
Subject: [PATCH] 	* common.opt (Woverflow): New command line option. 
 * c-common.c (constant_expression_warning): Check warn_overflow. 
 (overflow_waring): Pass OPT_Woverflow to warning. 
 (unsigned_conversion_warning): Likewise. 	(convert_and_check): Likewise.
 	* doc/invoke.texi: Document new command line option.

	* gcc.dg/Woverflow-1.c: New test case.
	* gcc.dg/Woverflow-2.c: Likewise.
	* gcc.dg/Woverflow-3.c: Likewise.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113408 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                      |  9 +++++++++
 gcc/c-common.c                     | 16 ++++++++++------
 gcc/common.opt                     |  4 ++++
 gcc/doc/invoke.texi                |  7 ++++++-
 gcc/testsuite/ChangeLog            |  6 ++++++
 gcc/testsuite/gcc.dg/Woverflow-1.c |  7 +++++++
 gcc/testsuite/gcc.dg/Woverflow-2.c |  7 +++++++
 gcc/testsuite/gcc.dg/Woverflow-3.c |  7 +++++++
 8 files changed, 56 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/Woverflow-1.c
 create mode 100644 gcc/testsuite/gcc.dg/Woverflow-2.c
 create mode 100644 gcc/testsuite/gcc.dg/Woverflow-3.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 49d96389628b..bc5e24f65446 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2006-04-30  Roger Sayle  <roger@eyesopen.com>
+
+	* common.opt (Woverflow): New command line option.
+	* c-common.c (constant_expression_warning): Check warn_overflow.
+	(overflow_waring): Pass OPT_Woverflow to warning.
+	(unsigned_conversion_warning): Likewise.
+	(convert_and_check): Likewise.
+	* doc/invoke.texi: Document new command line option.
+
 2006-04-30  David Edelsohn  <edelsohn@gnu.org>
 
 	* config/rs6000/rs6000.c (rs6000_override_options): Enable
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 35982e58c1ea..5e546603fa54 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -906,7 +906,9 @@ constant_expression_warning (tree value)
   if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
        || TREE_CODE (value) == VECTOR_CST
        || TREE_CODE (value) == COMPLEX_CST)
-      && TREE_CONSTANT_OVERFLOW (value) && pedantic)
+      && TREE_CONSTANT_OVERFLOW (value)
+      && warn_overflow
+      && pedantic)
     pedwarn ("overflow in constant expression");
 }
 
@@ -927,7 +929,7 @@ overflow_warning (tree value)
     {
       TREE_OVERFLOW (value) = 0;
       if (skip_evaluation == 0)
-	warning (0, "integer overflow in expression");
+	warning (OPT_Woverflow, "integer overflow in expression");
     }
   else if ((TREE_CODE (value) == REAL_CST
 	    || (TREE_CODE (value) == COMPLEX_CST
@@ -936,13 +938,13 @@ overflow_warning (tree value)
     {
       TREE_OVERFLOW (value) = 0;
       if (skip_evaluation == 0)
-	warning (0, "floating point overflow in expression");
+	warning (OPT_Woverflow, "floating point overflow in expression");
     }
   else if (TREE_CODE (value) == VECTOR_CST && TREE_OVERFLOW (value))
     {
       TREE_OVERFLOW (value) = 0;
       if (skip_evaluation == 0)
-	warning (0, "vector overflow in expression");
+	warning (OPT_Woverflow, "vector overflow in expression");
     }
 }
 
@@ -964,7 +966,8 @@ unsigned_conversion_warning (tree result, tree operand)
     {
       if (!int_fits_type_p (operand, c_common_signed_type (type)))
 	/* This detects cases like converting -129 or 256 to unsigned char.  */
-	warning (0, "large integer implicitly truncated to unsigned type");
+	warning (OPT_Woverflow,
+		 "large integer implicitly truncated to unsigned type");
       else
 	warning (OPT_Wconversion,
 		 "negative integer implicitly converted to unsigned type");
@@ -1093,7 +1096,8 @@ convert_and_check (tree type, tree expr)
 		 || !constant_fits_type_p (expr,
 					   c_common_unsigned_type (type)))
 		&& skip_evaluation == 0)
-	      warning (0, "overflow in implicit constant conversion");
+	      warning (OPT_Woverflow,
+                       "overflow in implicit constant conversion");
 	}
       else
 	unsigned_conversion_warning (t, expr);
diff --git a/gcc/common.opt b/gcc/common.opt
index f14a1cf1a2e7..53836f399e73 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -109,6 +109,10 @@ Wmissing-noreturn
 Common Var(warn_missing_noreturn)
 Warn about functions which might be candidates for __attribute__((noreturn))
 
+Woverflow
+Common Var(warn_overflow) Init(1)
+Warn about overflow in arithmetic expressions
+
 Wpacked
 Common Var(warn_packed)
 Warn when the packed attribute has no effect on struct layout
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 5dcf70b97472..3e523d45efff 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -238,7 +238,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wmain  -Wmissing-braces  -Wmissing-field-initializers @gol
 -Wmissing-format-attribute  -Wmissing-include-dirs @gol
 -Wmissing-noreturn @gol
--Wno-multichar  -Wnonnull  -Woverlength-strings  -Wpacked  -Wpadded @gol
+-Wno-multichar  -Wnonnull  -Wno-overflow @gol
+-Woverlength-strings  -Wpacked  -Wpadded @gol
 -Wparentheses  -Wpointer-arith  -Wno-pointer-to-int-cast @gol
 -Wredundant-decls @gol
 -Wreturn-type  -Wsequence-point  -Wshadow @gol
@@ -3284,6 +3285,10 @@ deprecated by using the @code{deprecated} attribute.
 (@pxref{Function Attributes}, @pxref{Variable Attributes},
 @pxref{Type Attributes}.)
 
+@item -Wno-overflow
+@opindex Wno-overflow
+Do not warn about compile-time overflow in constant expressions.
+
 @item -Wpacked
 @opindex Wpacked
 Warn if a structure is given the packed attribute, but the packed
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b9ca4cff981a..1aeb5ac2a153 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2006-04-30  Roger Sayle  <roger@eyesopen.com>
+
+	* gcc.dg/Woverflow-1.c: New test case.
+	* gcc.dg/Woverflow-2.c: Likewise.
+	* gcc.dg/Woverflow-3.c: Likewise.
+
 2006-04-30  Mark Mitchell  <mark@codesourcery.com>
 
 	PR c++/27094
diff --git a/gcc/testsuite/gcc.dg/Woverflow-1.c b/gcc/testsuite/gcc.dg/Woverflow-1.c
new file mode 100644
index 000000000000..064af4561eaa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverflow-1.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#include <limits.h>
+
+int foo = INT_MAX + 1;  /* { dg-warning "integer overflow" } */
+
diff --git a/gcc/testsuite/gcc.dg/Woverflow-2.c b/gcc/testsuite/gcc.dg/Woverflow-2.c
new file mode 100644
index 000000000000..44368b66f9f7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverflow-2.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Woverflow" } */
+
+#include <limits.h>
+
+int foo = INT_MAX + 1;  /* { dg-warning "integer overflow" } */
+
diff --git a/gcc/testsuite/gcc.dg/Woverflow-3.c b/gcc/testsuite/gcc.dg/Woverflow-3.c
new file mode 100644
index 000000000000..73a021b59460
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Woverflow-3.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wno-overflow" } */
+
+#include <limits.h>
+
+int foo = INT_MAX + 1;
+
-- 
GitLab