diff mbox

RFA: prefer double over same-size float as conversion result

Message ID 20130826120748.v4q5uhr068o04k8g-nzlynne@webmail.spamcop.net
State New
Headers show

Commit Message

Joern Rennecke Aug. 26, 2013, 4:07 p.m. UTC
This fixes the following avr failures:

FAIL: gcc.dg/Wdouble-promotion.c  (test for warnings, line 45)
FAIL: gcc.dg/Wdouble-promotion.c  (test for warnings, line 52)
FAIL: gcc.dg/Wdouble-promotion.c  (test for warnings, line 53)
FAIL: gcc.dg/Wdouble-promotion.c  (test for warnings, line 56)
FAIL: gcc.dg/pr44214-2.c scan-tree-dump-times original " \\* " 1

bootstrapped/regtested on i686-pc-linux-gnu

OK to apply?
2013-05-14  Joern Rennecke  <joern.rennecke@embecosm.com>

	* c-typeck.c (c_common_type): Prefer double_type_node over
	other REAL_TYPE types with the same precision.
	(convert_arguments): Likewise.

Comments

Richard Henderson Aug. 26, 2013, 4:13 p.m. UTC | #1
On 08/26/2013 09:07 AM, Joern Rennecke wrote:
> 2013-05-14  Joern Rennecke  <joern.rennecke@embecosm.com>
> 
> 	* c-typeck.c (c_common_type): Prefer double_type_node over
> 	other REAL_TYPE types with the same precision.
> 	(convert_arguments): Likewise.

Ok.


r~
Joseph Myers Aug. 26, 2013, 4:30 p.m. UTC | #2
In convert_arguments I think you should be comparing TYPE_MAIN_VARIANT 
(valtype) against double_type_node and long_double_type_node, rather than 
just valtype.

This is PR c/35649 (so include that number in your ChangeLog entry and 
close that bug as fixed).
diff mbox

Patch

Index: c/c-typeck.c
===================================================================
--- c/c-typeck.c	(revision 201992)
+++ c/c-typeck.c	(working copy)
@@ -919,6 +919,13 @@  c_common_type (tree t1, tree t2)
       || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
     return long_double_type_node;
 
+  /* Likewise, prefer double to float even if same size.
+     We got a couple of embedded targets with 32 bit doubles, and the
+     pdp11 might have 64 bit floats.  */
+  if (TYPE_MAIN_VARIANT (t1) == double_type_node
+      || TYPE_MAIN_VARIANT (t2) == double_type_node)
+    return double_type_node;
+
   /* Otherwise prefer the unsigned one.  */
 
   if (TYPE_UNSIGNED (t1))
@@ -3156,7 +3163,9 @@  convert_arguments (tree typelist, vec<tr
 	}
       else if (TREE_CODE (valtype) == REAL_TYPE
 	       && (TYPE_PRECISION (valtype)
-		   < TYPE_PRECISION (double_type_node))
+		   <= TYPE_PRECISION (double_type_node))
+	       && valtype != double_type_node
+	       && valtype != long_double_type_node
 	       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (valtype)))
         {
 	  if (type_generic)