aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDirk Zoller <duz@rtsffm.com>1999-09-30 06:19:54 +0000
committerJeff Law <law@gcc.gnu.org>1999-09-30 00:19:54 -0600
commitb843d2101e5b335f9ae87d5dea12372aca5fb5da (patch)
tree61b757d3537f8ed69955652a8d7feba76e9d7c6d /gcc
parent1bdba2c09c51979c2ec3387637e87648b0ac1db6 (diff)
downloadgcc-b843d2101e5b335f9ae87d5dea12372aca5fb5da.zip
gcc-b843d2101e5b335f9ae87d5dea12372aca5fb5da.tar.gz
gcc-b843d2101e5b335f9ae87d5dea12372aca5fb5da.tar.bz2
c-tree.h (warn_float_equal): Declare.
* c-tree.h (warn_float_equal): Declare. * c-decl.c (warn_float_equal): Define. (c_decode_option): Recognize -W[no-]float-equal. * c-typeck.c (build_binary_op): Conditionally warn about equality tests of floating point types. * toplev.c (documented_lan_options): Add -W[no-]float-equal. From-SVN: r29722
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/c-decl.c8
-rw-r--r--gcc/c-tree.h4
-rw-r--r--gcc/c-typeck.c2
-rw-r--r--gcc/toplev.c2
5 files changed, 25 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ced478a..08eecb4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+Thu Sep 30 00:13:27 1999 Dirk Zoller <duz@rtsffm.com>
+
+ * c-tree.h (warn_float_equal): Declare.
+ * c-decl.c (warn_float_equal): Define.
+ (c_decode_option): Recognize -W[no-]float-equal.
+ * c-typeck.c (build_binary_op): Conditionally warn
+ about equality tests of floating point types.
+ * toplev.c (documented_lan_options): Add -W[no-]float-equal.
+
Wed Sep 29 23:43:39 1999 Jeffrey A Law (law@cygnus.com)
* cse.c (struct set): Delete inner_dest_loc field.
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 433030d..ca8f26b 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -446,6 +446,10 @@ int warn_unknown_pragmas = 0; /* Tri state variable. */
int warn_sign_compare = -1;
+/* Warn about testing equality of floating point numbers. */
+
+int warn_float_equal = 0;
+
/* Nonzero means warn about use of multicharacter literals. */
int warn_multichar = 1;
@@ -724,6 +728,10 @@ c_decode_option (argc, argv)
warn_sign_compare = 1;
else if (!strcmp (p, "-Wno-sign-compare"))
warn_sign_compare = 0;
+ else if (!strcmp (p, "-Wfloat-equal"))
+ warn_float_equal = 1;
+ else if (!strcmp (p, "-Wno-float-equal"))
+ warn_float_equal = 0;
else if (!strcmp (p, "-Wmultichar"))
warn_multichar = 1;
else if (!strcmp (p, "-Wno-multichar"))
diff --git a/gcc/c-tree.h b/gcc/c-tree.h
index 44ec800..0d2dd63 100644
--- a/gcc/c-tree.h
+++ b/gcc/c-tree.h
@@ -422,6 +422,10 @@ extern int warn_missing_braces;
extern int warn_sign_compare;
+/* Warn about testing equality of floating point numbers. */
+
+extern int warn_float_equal;
+
/* Warn about multicharacter constants. */
extern int warn_multichar;
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 0783683..0d6ec00 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2099,6 +2099,8 @@ build_binary_op (code, orig_op0, orig_op1, convert_p)
case EQ_EXPR:
case NE_EXPR:
+ if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
+ warning ("comparing floating point with == or != is unsafe");
/* Result of comparison is always int,
but don't convert the args to int! */
build_type = integer_type_node;
diff --git a/gcc/toplev.c b/gcc/toplev.c
index b4e65c7..99efdb3 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1100,6 +1100,8 @@ documented_lang_options[] =
{ "-Wno-redundant-decls", "" },
{ "-Wsign-compare", "Warn about signed/unsigned comparisons" },
{ "-Wno-sign-compare", "" },
+ { "-Wfloat-equal", "Warn about testing equality of floating point numbers" },
+ { "-Wno-float-equal", "" },
{ "-Wunknown-pragmas", "Warn about unrecognised pragmas" },
{ "-Wno-unknown-pragmas", "" },
{ "-Wstrict-prototypes", "Warn about non-prototyped function decls" },