diff mbox

Fix ICE on conditional expression between DFP and non-DFP float (PR c/71601)

Message ID alpine.DEB.2.20.1606202258220.29719@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers June 20, 2016, 10:58 p.m. UTC
A conditional expression between DFP and non-DFP floating-point
produces an ICE.  This patch fixes this by making
build_conditional_expr return early when c_common_type produces an
error.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.  Applied to 
mainline.

gcc/c:
2016-06-20  Joseph Myers  <joseph@codesourcery.com>

	PR c/71601
	* c-typeck.c (build_conditional_expr): Return error_mark_node if
	c_common_type returns error_mark_node.

gcc/testsuite:
2016-06-20  Joseph Myers  <joseph@codesourcery.com>

	PR c/71601
	* gcc.dg/dfp/usual-arith-conv-bad-3.c: New test.
diff mbox

Patch

Index: gcc/c/c-typeck.c
===================================================================
--- gcc/c/c-typeck.c	(revision 237589)
+++ gcc/c/c-typeck.c	(working copy)
@@ -4846,6 +4846,8 @@  build_conditional_expr (location_t colon_loc, tree
 	       || code2 == COMPLEX_TYPE))
     {
       result_type = c_common_type (type1, type2);
+      if (result_type == error_mark_node)
+	return error_mark_node;
       do_warn_double_promotion (result_type, type1, type2,
 				"implicit conversion from %qT to %qT to "
 				"match other result of conditional",
Index: gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-3.c
===================================================================
--- gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-3.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/dfp/usual-arith-conv-bad-3.c	(working copy)
@@ -0,0 +1,13 @@ 
+/* Test error for conditional expression between DFP and other
+   floating operand.  */
+/* { dg-do compile } */
+
+_Decimal32 a;
+float b;
+int i;
+
+void
+f (void)
+{
+  (void) (i ? a : b); /* { dg-error "mix operands" } */
+}