public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR71452
Date: Wed, 08 Jun 2016 08:19:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.11.1606081016280.1493@t29.fhfr.qr> (raw)


The following fixes a bug when rewriting a memory location into SSA
form.  For the testcase we didn't consider the case where the type
we end up using for the SSA name does not have enough precision
to cover all values of the dynamic type (thus we only need to consider
stores).

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2016-06-08  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/71452
	* tree-ssa.c (non_rewritable_lvalue_p): Make sure that the
	type used for the SSA rewrite has enough precision to cover
	the dynamic type of the location.

	* gcc.dg/torture/pr71452.c: New testcase.

Index: gcc/tree-ssa.c
===================================================================
*** gcc/tree-ssa.c	(revision 237196)
--- gcc/tree-ssa.c	(working copy)
*************** non_rewritable_lvalue_p (tree lhs)
*** 1292,1297 ****
--- 1320,1333 ----
        if (integer_zerop (TREE_OPERAND (lhs, 1))
  	  && DECL_P (decl)
  	  && DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
+ 	  /* If the dynamic type of the decl has larger precision than
+ 	     the decl itself we can't use the decls type for SSA rewriting.  */
+ 	  && ((! INTEGRAL_TYPE_P (TREE_TYPE (decl))
+ 	       || compare_tree_int (DECL_SIZE (decl),
+ 				    TYPE_PRECISION (TREE_TYPE (decl))) == 0)
+ 	      || (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
+ 		  && (TYPE_PRECISION (TREE_TYPE (decl))
+ 		      >= TYPE_PRECISION (TREE_TYPE (lhs)))))
  	  && (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
  	return false;
  
Index: gcc/testsuite/gcc.dg/torture/pr71452.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr71452.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr71452.c	(working copy)
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do run } */
+ 
+ int main()
+ {
+   _Bool b;
+   *(char *)&b = 123;
+   if (*(char *)&b != 123)
+     __builtin_abort ();
+   return 0;
+ }
Index: gcc/testsuite/g++.dg/torture/pr71452.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr71452.C	(revision 0)
--- gcc/testsuite/g++.dg/torture/pr71452.C	(working copy)
***************
*** 0 ****
--- 1,10 ----
+ // { dg-do run }
+ 
+ int main()
+ {
+   bool b;
+   *(char *)&b = 123;
+   if (*(char *)&b != 123)
+     __builtin_abort ();
+   return 0;
+ }

                 reply	other threads:[~2016-06-08  8:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.11.1606081016280.1493@t29.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).