public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix middle-end/30132: ICE with complex and taking the real part of  a ?:
@ 2007-03-14 23:30 Andrew_Pinski
  2007-03-15 11:34 ` Richard Guenther
  2007-03-20 21:39 ` Richard Henderson
  0 siblings, 2 replies; 8+ messages in thread
From: Andrew_Pinski @ 2007-03-14 23:30 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1382 bytes --]

Hi,
   The problem here is that the gimplifier can produce invalid gimple when 
the address is of an non addressable expression like a conditional 
expression.  When Alexandre fixed PR 20280, he introduced the issue of 
building addresses of the two operand of a conditional expression if we 
wantted either a lvalue or a rvalue, this introduced this latent bug of 
invalid gimple. 

Now my patch fixes PR 20280 in the front-end so we never get &(a?b:c), we 
always get a?&b:&c instead.  This patch also fixes the invalid gimple 
issue when needing a temp variable.  This patch also reverts part of the 
patch for PR 20280 so only when we want lvalue of a conditional, we take 
the address inside the conditional. 

The middle part of the patch is enough to fix the bug but we get worse 
code as we get * (a?&b:&c) which is not optimized currently.

OK? Bootstrapped and tested on i686-linux-gnu with no regressions.


Thanks,
Andrew Pinski

ChangeLog:

        * gimplifier.c (gimplify_cond_expr): Don't create *(a?&b:&c), if a 
rvalue is ok.
        (gimplify_addr_expr): Create one more extra variable if we have a 
temp decl.


cp/ChangeLog:

        * typeck.c (build_address): For COND_EXPR, create a?&b:&c instead 
of the plain
        &(a?b:c) so we don't get a temp variable in the gimplifier.

testsuite/ChangeLog:

        * gcc.c-torture/compile/complex-5.c: New test.


[-- Attachment #2: fixpr30132.diff.txt --]
[-- Type: text/plain, Size: 2224 bytes --]

Index: testsuite/gcc.c-torture/compile/complex-5.c
===================================================================
--- testsuite/gcc.c-torture/compile/complex-5.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/complex-5.c	(revision 0)
@@ -0,0 +1,13 @@
+/* PR 30132 */
+#define complex _Complex
+void testit(double complex* t, double* b)
+{
+  b[0] = t[0]==0.0?0.0:-t[0];
+}
+
+main(void)
+{
+  static double complex k = 5;
+  static double b;
+  testit(&k,&b);
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 122896)
+++ cp/typeck.c	(working copy)
@@ -4060,6 +4060,14 @@ build_address (tree t)
   if (error_operand_p (t) || !cxx_mark_addressable (t))
     return error_mark_node;
 
+  if (TREE_CODE (t) == COND_EXPR)
+    {
+      tree ptrtype = build_pointer_type (TREE_TYPE (t));
+      return build3 (COND_EXPR, ptrtype, TREE_OPERAND (t, 0),
+		     build_address (TREE_OPERAND (t, 1)),
+		     build_address (TREE_OPERAND (t, 2)));
+    }
+
   addr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (t)), t);
 
   return addr;
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 122896)
+++ gimplify.c	(working copy)
@@ -2436,7 +2436,7 @@ gimplify_cond_expr (tree *expr_p, tree *
     {
       tree result;
 
-      if ((fallback & fb_lvalue) == 0)
+      if (fallback != fb_lvalue)
 	{
 	  result = tmp2 = tmp = create_tmp_var (TREE_TYPE (expr), "iftmp");
 	  ret = GS_ALL_DONE;
@@ -3948,6 +3948,15 @@ gimplify_addr_expr (tree *expr_p, tree *
 	  if (TREE_CODE (op0) == INDIRECT_REF)
 	    goto do_indirect_ref;
 
+	  /* If we don't already have an addressable expression, create a new
+	     decl to hold it so we don't get non gimple as the decl which was
+	     holding this before was not marked as addressable already.  */
+	  if (TREE_CODE (op0) == VAR_DECL
+	      && DECL_GIMPLE_FORMAL_TEMP_P (op0)
+	      && !TREE_ADDRESSABLE (op0))
+	    TREE_OPERAND (expr, 0) = get_initialized_tmp_var (op0, pre_p,
+							      post_p);
+
 	  /* Make sure TREE_INVARIANT, TREE_CONSTANT, and TREE_SIDE_EFFECTS
 	     is set properly.  */
 	  recompute_tree_invariant_for_addr_expr (expr);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-12-06 20:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-14 23:30 [PATCH] Fix middle-end/30132: ICE with complex and taking the real part of a ?: Andrew_Pinski
2007-03-15 11:34 ` Richard Guenther
2007-03-20 21:39 ` Richard Henderson
2007-11-02  4:17   ` Andrew Pinski
2007-11-02 14:08     ` Richard Guenther
2007-12-06 20:27       ` Jakub Jelinek
2007-11-12 21:22     ` Jason Merrill
2007-11-12 21:28       ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).