This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] convert.c: Fix PR middle-end/26632.


Hi,

Attached is a patch to fix PR middle-end/26632.

The attached testcase compiled without this patch triggers a warning:

  pr26632.c: In function âfâ:
  pr26632.c:13: warning: value computed is not used

This warning is issued for an implicit conversion that
convert_to_integer adds to the result of g ().

This patch supresses the warning for such implicit conversions as
suggested by Mark Mitchell in the audit trail.

Tested on x86_64-pc-linux-gnu.  OK to apply?

Kazu Hirata

2006-08-28  Kazu Hirata  <kazu@codesourcery.com>

	PR middle-end/26632
	* convert.c (convert_to_integer): Set TREE_NO_WARNING to 1 on
	an implicit conversion.

2006-08-28  Kazu Hirata  <kazu@codesourcery.com>

	PR middle-end/26632
	* gcc.dg/pr26632.c: New.

Index: convert.c
===================================================================
--- convert.c	(revision 116466)
+++ convert.c	(working copy)
@@ -487,6 +487,7 @@ convert_to_integer (tree type, tree expr
       else if (outprec >= inprec)
 	{
 	  enum tree_code code;
+	  tree tem;
 
 	  /* If the precision of the EXPR's type is K bits and the
 	     destination mode has more bits, and the sign is changing,
@@ -504,7 +505,13 @@ convert_to_integer (tree type, tree expr
 	  else
 	    code = NOP_EXPR;
 
-	  return fold_build1 (code, type, expr);
+	  tem = fold_unary (code, type, expr);
+	  if (tem)
+	    return tem;
+
+	  tem = build1 (code, type, expr);
+	  TREE_NO_WARNING (tem) = 1;
+	  return tem;
 	}
 
       /* If TYPE is an enumeral type or a type with a precision less
Index: testsuite/gcc.dg/pr26632.c
===================================================================
--- testsuite/gcc.dg/pr26632.c	(revision 0)
+++ testsuite/gcc.dg/pr26632.c	(revision 0)
@@ -0,0 +1,14 @@
+/* PR middle-end/26632
+   We used to issue a warning for an implicit cast whose result is not
+   used.  */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int g (void);
+long h (void);
+
+void
+f (void)
+{
+  0 ? h () : g (); /* { dg-bogus "value computed is not used" } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]