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 <rguent...@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