public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Remove bogus TYPE_IS_SIZETYPE special-casing in extract_muldiv_1
@ 2011-08-31  9:14 Richard Guenther
  2011-09-02  8:37 ` Eric Botcazou
  0 siblings, 1 reply; 16+ messages in thread
From: Richard Guenther @ 2011-08-31  9:14 UTC (permalink / raw)
  To: gcc-patches


When making sizetypes no longer sign-extended (they are unsigned)
we run into extract_muldiv_1 miscompiling the Ada RTS during
secondary stack initialization while folding sizes for an allocation.

From

((sizetype) (_GLOBAL.SZ4_system.secondary_stack (<PLACEHOLDER_EXPR struct 
system__secondary_stack__chunk_id>.last, <PLACEHOLDER_EXPR struct 
system__secondary_stack__chunk_id>.first) /[cl] 8) + 15 & 
0x0fffffffffffffff0) + 32

we eventually generate 2305843009213704224.  Oops.

This is because extract_multiv_1 happily transforms

(((10240 - (sizetype) first) + 1) * 8) /[cl] 8

through

((sizetype) first * 0x0fffffffffffffff8 + 81928) /[cl] 8

to

((sizetype) first * 2305843009213693951 + 10241)

and then substitute 1 for first.

Well, the comment for that folding is totally odd - of _course_
unsigned sizetype things can overflow (we hid that issue merely
by pretending all unsigned sizetype constants (yes, only constants)
are signed.  Huh.)

Off it goes.

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

Richard.

2011-08-31  Richard Guenther  <rguenther@suse.de>

	* fold-const.c (extract_muldiv_1): Remove bogus TYPE_IS_SIZETYPE
	special-casing.

Index: trunk/gcc/fold-const.c
===================================================================
--- trunk.orig/gcc/fold-const.c	2011-08-31 10:53:58.000000000 +0200
+++ trunk/gcc/fold-const.c	2011-08-31 10:45:09.000000000 +0200
@@ -5894,11 +5894,9 @@ extract_muldiv_1 (tree t, tree c, enum t
 	 multiple of the other, in which case we replace this with either an
 	 operation or CODE or TCODE.
 
-	 If we have an unsigned type that is not a sizetype, we cannot do
-	 this since it will change the result if the original computation
-	 overflowed.  */
-      if ((TYPE_OVERFLOW_UNDEFINED (ctype)
-	   || (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype)))
+	 If we have an unsigned type, we cannot do this since it will change
+	 the result if the original computation overflowed.  */
+      if (TYPE_OVERFLOW_UNDEFINED (ctype)
 	  && ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR)
 	      || (tcode == MULT_EXPR
 		  && code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR

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

end of thread, other threads:[~2011-09-05  7:33 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-31  9:14 [PATCH] Remove bogus TYPE_IS_SIZETYPE special-casing in extract_muldiv_1 Richard Guenther
2011-09-02  8:37 ` Eric Botcazou
2011-09-02  9:05   ` Richard Guenther
2011-09-02 13:26     ` Eric Botcazou
2011-09-02 13:33       ` Richard Guenther
2011-09-03  9:23         ` Eric Botcazou
2011-09-03 11:57           ` Richard Guenther
2011-09-03 15:08             ` Eric Botcazou
2011-09-03 19:09               ` Richard Guenther
2011-09-03 19:47                 ` Richard Kenner
2011-09-03 20:37                   ` Richard Guenther
2011-09-03 20:39                     ` Richard Guenther
2011-09-03 21:20                       ` Richard Kenner
2011-09-03 21:20                     ` Richard Kenner
2011-09-03 21:27                     ` Richard Kenner
2011-09-05  7:33           ` Richard Guenther

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).