This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] [2of5] looking for feedback on Wcoercion warning (for stage1)
- From: "Manuel LÃpez-IbÃÃez" <lopezibanez at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Cc: "Joseph Myers" <jsm at polyomino dot org dot uk>, "Richard Henderson" <rth at redhat dot com>, "Jason Merrill" <jason at redhat dot com>, "Mark Mitchell" <mark at codesourcery dot com>, "Nathan Sidwell" <nathan at codesourcery dot com>
- Date: Wed, 9 Aug 2006 09:33:50 +0100
- Subject: [PATCH] [2of5] looking for feedback on Wcoercion warning (for stage1)
(The following patch implements part of the functionality of the
Wcoercion project as explained in
http://gcc.gnu.org/wiki/Wcoercion#Background ).
This patch adds a new function which detects when a real value can be
exactly represented as an integer.
This is the second of a series of 5 patches. The previous patch can be
found at http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00212.html .
:ADDPATCH c/c++:
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 1of3-split/gcc/builtins.c 2of3-real_isinteger/gcc/builtins.c
--- 1of3-split/gcc/builtins.c 2006-08-05 18:05:20.000000000 +0100
+++ 2of3-real_isinteger/gcc/builtins.c 2006-08-06 16:24:26.000000000 +0100
@@ -6654,15 +6654,7 @@ integer_valued_real_p (tree t)
&& integer_valued_real_p (TREE_OPERAND (t, 2));
case REAL_CST:
- if (! TREE_CONSTANT_OVERFLOW (t))
- {
- REAL_VALUE_TYPE c, cint;
-
- c = TREE_REAL_CST (t);
- real_trunc (&cint, TYPE_MODE (TREE_TYPE (t)), &c);
- return real_identical (&c, &cint);
- }
- break;
+ return real_isinteger (TREE_REAL_CST (t), TYPE_MODE (TREE_TYPE (t)));
case NOP_EXPR:
{
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 1of3-split/gcc/real.c 2of3-real_isinteger/gcc/real.c
--- 1of3-split/gcc/real.c 2006-08-05 18:05:20.000000000 +0100
+++ 2of3-real_isinteger/gcc/real.c 2006-08-06 16:24:26.000000000 +0100
@@ -4922,3 +4922,13 @@ real_copysign (REAL_VALUE_TYPE *r, const
r->sign = x->sign;
}
+/* Check whether the real constant value given is an integer. */
+
+bool
+real_isinteger (const REAL_VALUE_TYPE c, enum machine_mode mode)
+{
+ REAL_VALUE_TYPE cint;
+
+ real_trunc (&cint, mode, &c);
+ return real_identical (&c, &cint);
+}
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 1of3-split/gcc/real.h 2of3-real_isinteger/gcc/real.h
--- 1of3-split/gcc/real.h 2006-08-05 18:05:20.000000000 +0100
+++ 2of3-real_isinteger/gcc/real.h 2006-08-06 16:24:26.000000000 +0100
@@ -425,4 +425,7 @@ extern void real_round (REAL_VALUE_TYPE
/* Set the sign of R to the sign of X. */
extern void real_copysign (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
+/* Check whether the real constant value given is an integer. */
+extern bool real_isinteger (const REAL_VALUE_TYPE c, enum machine_mode mode);
+
#endif /* ! GCC_REAL_H */