aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2010-09-06 17:48:53 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2010-09-06 17:48:53 +0000
commitc5ee1358b94d1dc84376932d65d407d928289d30 (patch)
tree8d764bed307ee0730b51e4687fd0373d0bbc7c5d /gcc/c-family
parentc28350ab29cf774843ebdefc3f62cd6b203e4489 (diff)
downloadgcc-c5ee1358b94d1dc84376932d65d407d928289d30.zip
gcc-c5ee1358b94d1dc84376932d65d407d928289d30.tar.gz
gcc-c5ee1358b94d1dc84376932d65d407d928289d30.tar.bz2
c-common.h (do_warn_double_promotion): Declare.
* c-common.h (do_warn_double_promotion): Declare. * c-common.c (do_warn_double_promotion): Define. * c-typeck.c (do_warn_double_promotion): Remove. * doc/invoke.texi (-Wdouble-promotion): Note available for C++ and Objective-C++ too. * typeck.c (cp_build_binary_op): Call do_warn_double_promotion. * call.c (build_conditional_expr): Likewise. (convert_arg_to_ellipsis): Likewise. * g++.dg/warn/Wdouble-promotion.C: New. From-SVN: r163925
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-common.c34
-rw-r--r--gcc/c-family/c-common.h2
3 files changed, 41 insertions, 0 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 0a6aaa5..50c4ea1 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-06 Mark Mitchell <mark@codesourcery.com>
+
+ * c-common.h (do_warn_double_promotion): Declare.
+ * c-common.c (do_warn_double_promotion): Define.
+
2010-09-05 Mark Mitchell <mark@codesourcery.com>
* c.opt (Wdouble-promotion): New.
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 6b9a967..48c67b4 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -9128,6 +9128,40 @@ warn_for_sign_compare (location_t location,
}
}
+/* RESULT_TYPE is the result of converting TYPE1 and TYPE2 to a common
+ type via c_common_type. If -Wdouble-promotion is in use, and the
+ conditions for warning have been met, issue a warning. GMSGID is
+ the warning message. It must have two %T specifiers for the type
+ that was converted (generally "float") and the type to which it was
+ converted (generally "double), respectively. LOC is the location
+ to which the awrning should refer. */
+
+void
+do_warn_double_promotion (tree result_type, tree type1, tree type2,
+ const char *gmsgid, location_t loc)
+{
+ tree source_type;
+
+ if (!warn_double_promotion)
+ return;
+ /* If the conversion will not occur at run-time, there is no need to
+ warn about it. */
+ if (c_inhibit_evaluation_warnings)
+ return;
+ if (TYPE_MAIN_VARIANT (result_type) != double_type_node
+ && TYPE_MAIN_VARIANT (result_type) != complex_double_type_node)
+ return;
+ if (TYPE_MAIN_VARIANT (type1) == float_type_node
+ || TYPE_MAIN_VARIANT (type1) == complex_float_type_node)
+ source_type = type1;
+ else if (TYPE_MAIN_VARIANT (type2) == float_type_node
+ || TYPE_MAIN_VARIANT (type2) == complex_float_type_node)
+ source_type = type2;
+ else
+ return;
+ warning_at (loc, OPT_Wdouble_promotion, gmsgid, source_type, result_type);
+}
+
/* Setup a TYPE_DECL node as a typedef representation.
X is a TYPE_DECL for a typedef statement. Create a brand new
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 3f22485..6118f51 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -900,6 +900,8 @@ extern void warn_for_sign_compare (location_t,
tree op0, tree op1,
tree result_type,
enum tree_code resultcode);
+extern void do_warn_double_promotion (tree, tree, tree, const char *,
+ location_t);
extern void set_underlying_type (tree x);
extern VEC(tree,gc) *make_tree_vector (void);
extern void release_tree_vector (VEC(tree,gc) *);