home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / gcc / bug / 2247 < prev    next >
Encoding:
Text File  |  1992-09-02  |  24.5 KB  |  914 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert
  3. From: eggert@twinsun.COM (Paul Eggert)
  4. Subject: GCC 2.2.2 patches for overflow detection in constant expressions
  5. Message-ID: <9209030412.AA26982@farside.twinsun.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Thu, 3 Sep 1992 04:12:21 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 901
  12.  
  13. GCC 2.2.2 doesn't check for overflow in constant expressions, even though it
  14. really should -- not only because ANSI says so, but because it catches several
  15. all-too-common coding errors.  Here is a patch.
  16.  
  17. Thu Sep  3 02:33:55 1992  Paul Eggert  (eggert@twinsun.com)
  18.  
  19.     * c-typeck.c (constant_expression_warning): Now works;
  20.     it reports signed integer overflow in constant expressions,
  21.     and uncasted negative constants that appear in unsigned contexts.
  22.     (build_c_cast, convert_for_assignment, parser_build_binary_op,
  23.     store_init_value) Check for overflow.
  24.     * c-parse.y (unary_expr): Likewise.
  25.     * c-tree.h (constant_expression_warning): Now exported.
  26.  
  27.     * fold-const.c (left_shift_overflows, possible_sum_sign) New macros.
  28.     (force_fit_type): Mark overflowed or truncated INTEGER_CSTs.
  29.     (add_double, div_and_round_double, lshift_double, mul_double,
  30.     neg_double, const_binop, fold): Check for signed integer overflow.
  31.     (const_binop, fold_convert): Use pedwarn for overflow warnings.
  32.     Say `constant expression', not `constant folding', for user's sake.
  33.  
  34. ===================================================================
  35. RCS file: c-parse.y,v
  36. retrieving revision 2.2.2.3
  37. diff -c2 -r2.2.2.3 c-parse.y
  38. *** c-parse.y    1992/08/13 23:59:47    2.2.2.3
  39. --- c-parse.y    1992/09/02 19:17:38
  40. ***************
  41. *** 331,335 ****
  42.             pedantic = $<itype>1; }
  43.       | unop cast_expr  %prec UNARY
  44. !         { $$ = build_unary_op ($1, $2, 0); }
  45.       /* Refer to the address of a label as a pointer.  */
  46.       | ANDAND identifier
  47. --- 331,336 ----
  48.             pedantic = $<itype>1; }
  49.       | unop cast_expr  %prec UNARY
  50. !         { $$ = build_unary_op ($1, $2, 0);
  51. !           constant_expression_warning ($$, 0); }
  52.       /* Refer to the address of a label as a pointer.  */
  53.       | ANDAND identifier
  54. ===================================================================
  55. RCS file: c-tree.h,v
  56. retrieving revision 2.2
  57. diff -c2 -r2.2 c-tree.h
  58. *** c-tree.h    1992/03/14 20:55:54    2.2
  59. --- c-tree.h    1992/09/02 19:15:57
  60. ***************
  61. *** 108,111 ****
  62. --- 108,112 ----
  63.   extern tree c_expand_start_case ();
  64.   extern tree default_conversion ();
  65. + extern void constant_expression_warning ();
  66.   
  67.   /* Given two integer or real types, return the type for their sum.
  68. ===================================================================
  69. RCS file: c-typeck.c,v
  70. retrieving revision 2.2.2.7
  71. diff -c2 -r2.2.2.7 c-typeck.c
  72. *** c-typeck.c    1992/08/29 23:55:12    2.2.2.7
  73. --- c-typeck.c    1992/09/03 02:27:45
  74. ***************
  75. *** 785,796 ****
  76.   
  77.   /* Print a warning if a constant expression had overflow in folding.
  78. !    This doesn't really work--it is waiting for changes in fold.  */
  79.   
  80.   void
  81. ! constant_expression_warning (value)
  82.        tree value;
  83.   {
  84. !   if (TREE_CODE (value) == NON_LVALUE_EXPR && TREE_CONSTANT_OVERFLOW (value))
  85. !     pedwarn ("overflow in constant expression");
  86.   }
  87.   
  88. --- 785,804 ----
  89.   
  90.   /* Print a warning if a constant expression had overflow in folding.
  91. !    If EVEN_IF_UNSIGNED is nonzero, warn even if the expression is unsigned.  */
  92.   
  93.   void
  94. ! constant_expression_warning (value, even_if_unsigned)
  95.        tree value;
  96. +      int even_if_unsigned;
  97.   {
  98. !   if (TREE_CODE (value) == INTEGER_CST
  99. !       && TREE_CONSTANT_OVERFLOW (value)
  100. !       && (! TREE_UNSIGNED (TREE_TYPE (value)) || even_if_unsigned))
  101. !     {
  102. !       TREE_CONSTANT_OVERFLOW (value) = 0;
  103. !       pedwarn (TREE_UNSIGNED (TREE_TYPE (value))
  104. !            ? "constant expression out of range for unsigned type"
  105. !            : "signed integer overflow in constant expression");
  106. !     }
  107.   }
  108.   
  109. ***************
  110. *** 2135,2138 ****
  111. --- 2143,2148 ----
  112.       warning ("comparisons like X<=Y<=Z do not have the usual meaning");
  113.   
  114. +   constant_expression_warning (result, 0);
  115.     class = TREE_CODE_CLASS (TREE_CODE (result));
  116.   
  117. ***************
  118. *** 3728,3731 ****
  119. --- 3738,3742 ----
  120.   
  121.         value = convert (type, value);
  122. +       constant_expression_warning (value, 0);
  123.       }
  124.   
  125. ***************
  126. *** 3946,3950 ****
  127.         (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE))
  128.       {
  129. !       return convert (type, rhs);
  130.       }
  131.     /* Conversions among pointers */
  132. --- 3957,3963 ----
  133.         (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE))
  134.       {
  135. !       tree t = convert (type, rhs);
  136. !       constant_expression_warning (t, 1);
  137. !       return t;
  138.       }
  139.     /* Conversions among pointers */
  140. ***************
  141. *** 4233,4237 ****
  142.   
  143.     /* ANSI wants warnings about out-of-range constant initializers.  */
  144. !   constant_expression_warning (value);
  145.   
  146.     DECL_INITIAL (decl) = value;
  147. --- 4246,4250 ----
  148.   
  149.     /* ANSI wants warnings about out-of-range constant initializers.  */
  150. !   constant_expression_warning (value, 1);
  151.   
  152.     DECL_INITIAL (decl) = value;
  153. ===================================================================
  154. RCS file: fold-const.c,v
  155. retrieving revision 2.2.2.4
  156. diff -c2 -r2.2.2.4 fold-const.c
  157. *** fold-const.c    1992/08/29 08:21:30    2.2.2.4
  158. --- fold-const.c    1992/09/03 02:33:55
  159. ***************
  160. *** 49,53 ****
  161.   static jmp_buf float_error;
  162.   
  163. ! void lshift_double ();
  164.   void rshift_double ();
  165.   void lrotate_double ();
  166. --- 49,53 ----
  167.   static jmp_buf float_error;
  168.   
  169. ! int lshift_double ();
  170.   void rshift_double ();
  171.   void lrotate_double ();
  172. ***************
  173. *** 54,57 ****
  174. --- 54,65 ----
  175.   void rrotate_double ();
  176.   static tree const_binop ();
  177. + /* Yield nonzero if a signed left shift of A by B bits overflows.
  178. +    A is a C int; B is nonnegative.  */
  179. + #define left_shift_overflows(a, b)  ((a)  ^  ((a) << (b)) >> (b))
  180. + /* Yield nonzero if adding two numbers with A's and B's signs can yield a
  181. +    number with SUM's sign, where A, B, and SUM are all C ints.  */
  182. + #define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0)
  183.   
  184.   /* To do constant folding on INTEGER_CST nodes requires 64-bit arithmetic.
  185. ***************
  186. *** 97,106 ****
  187.   /* Make the integer constant T valid for its type
  188.      by setting to 0 or 1 all the bits in the constant
  189. !    that don't belong in the type.  */
  190.   
  191.   static void
  192. ! force_fit_type (t)
  193.        tree t;
  194.   {
  195.     register int prec = TYPE_PRECISION (TREE_TYPE (t));
  196.   
  197. --- 105,119 ----
  198.   /* Make the integer constant T valid for its type
  199.      by setting to 0 or 1 all the bits in the constant
  200. !    that don't belong in the type.
  201. !    Mark the constant if it has overflowed.
  202. !    If OVERFLOW is nonzero and the result is signed,
  203. !    the calculation has already overflowed.  */
  204.   
  205.   static void
  206. ! force_fit_type (t, overflow)
  207.        tree t;
  208. +      int overflow;
  209.   {
  210. +   int low = TREE_INT_CST_LOW (t), high = TREE_INT_CST_HIGH (t);
  211.     register int prec = TYPE_PRECISION (TREE_TYPE (t));
  212.   
  213. ***************
  214. *** 148,154 ****
  215. --- 161,174 ----
  216.       }
  217.       }
  218. +   /* In C, by definition, unsigned arithmetic does not overflow.
  219. +      But sometimes we want to warn about unsigned truncation.  */
  220. +   if ((low ^ TREE_INT_CST_LOW (t)) | (high ^ TREE_INT_CST_HIGH (t))
  221. +       || overflow && ! TREE_UNSIGNED (TREE_TYPE (t)))
  222. +     TREE_CONSTANT_OVERFLOW (t) = 1;
  223.   }
  224.   
  225.   /* Add two 64-bit integers with 64-bit result.
  226. +    Yield nonzero if the (signed) operation overflows.
  227.      Each argument is given as two `int' pieces.
  228.      One argument is L1 and H1; the other, L2 and H2.
  229. ***************
  230. *** 156,160 ****
  231.      We use the 8-shorts representation internally.  */
  232.   
  233. ! void
  234.   add_double (l1, h1, l2, h2, lv, hv)
  235.        int l1, h1, l2, h2;
  236. --- 176,180 ----
  237.      We use the 8-shorts representation internally.  */
  238.   
  239. ! int
  240.   add_double (l1, h1, l2, h2, lv, hv)
  241.        int l1, h1, l2, h2;
  242. ***************
  243. *** 177,183 ****
  244. --- 197,205 ----
  245.   
  246.     decode (arg1, lv, hv);
  247. +   return !possible_sum_sign (h1, h2, *hv);
  248.   }
  249.   
  250.   /* Negate a 64-bit integers with 64-bit result.
  251. +    Yield nonzero if the (signed) operation overflows.
  252.      The argument is given as two `int' pieces in L1 and H1.
  253.      The value is stored as two `int' pieces in *LV and *HV.
  254. ***************
  255. *** 184,188 ****
  256.      We use the 8-shorts representation internally.  */
  257.   
  258. ! void
  259.   neg_double (l1, h1, lv, hv)
  260.        int l1, h1;
  261. --- 206,210 ----
  262.      We use the 8-shorts representation internally.  */
  263.   
  264. ! int
  265.   neg_double (l1, h1, lv, hv)
  266.        int l1, h1;
  267. ***************
  268. *** 199,205 ****
  269. --- 221,229 ----
  270.         *hv = ~ h1;
  271.       }
  272. +   return (h1 & *hv) < 0;
  273.   }
  274.   
  275.   /* Multiply two 64-bit integers with 64-bit result.
  276. +    Yield nonzero if the (signed) operation overflows.
  277.      Each argument is given as two `int' pieces.
  278.      One argument is L1 and H1; the other, L2 and H2.
  279. ***************
  280. *** 207,211 ****
  281.      We use the 8-shorts representation internally.  */
  282.   
  283. ! void
  284.   mul_double (l1, h1, l2, h2, lv, hv)
  285.        int l1, h1, l2, h2;
  286. --- 231,235 ----
  287.      We use the 8-shorts representation internally.  */
  288.   
  289. ! int
  290.   mul_double (l1, h1, l2, h2, lv, hv)
  291.        int l1, h1, l2, h2;
  292. ***************
  293. *** 217,223 ****
  294.     register int carry = 0;
  295.     register int i, j, k;
  296.   
  297. !   /* These two cases are used extensively, arising from pointer
  298. !      combinations.  */
  299.     if (h2 == 0)
  300.       {
  301. --- 241,247 ----
  302.     register int carry = 0;
  303.     register int i, j, k;
  304. +   int toplow, tophigh, neglow, neghigh;
  305.   
  306. !   /* These cases are used extensively, arising from pointer combinations.  */
  307.     if (h2 == 0)
  308.       {
  309. ***************
  310. *** 224,236 ****
  311.         if (l2 == 2)
  312.       {
  313.         unsigned temp = l1 + l1;
  314. !       *hv = h1 * 2 + (temp < l1);
  315.         *lv = temp;
  316. !       return;
  317.       }
  318.         if (l2 == 4)
  319.       {
  320.         unsigned temp = l1 + l1;
  321. !       h1 = h1 * 4 + ((temp < l1) << 1);
  322.         l1 = temp;
  323.         temp += temp;
  324. --- 248,262 ----
  325.         if (l2 == 2)
  326.       {
  327. +       int overflow = left_shift_overflows (h1, 1);
  328.         unsigned temp = l1 + l1;
  329. !       *hv = (h1 << 1) + (temp < l1);
  330.         *lv = temp;
  331. !       return overflow;
  332.       }
  333.         if (l2 == 4)
  334.       {
  335. +       int overflow = left_shift_overflows (h1, 2);
  336.         unsigned temp = l1 + l1;
  337. !       h1 = (h1 << 2) + ((temp < l1) << 1);
  338.         l1 = temp;
  339.         temp += temp;
  340. ***************
  341. *** 238,247 ****
  342.         *lv = temp;
  343.         *hv = h1;
  344. !       return;
  345.       }
  346.         if (l2 == 8)
  347.       {
  348.         unsigned temp = l1 + l1;
  349. !       h1 = h1 * 8 + ((temp < l1) << 2);
  350.         l1 = temp;
  351.         temp += temp;
  352. --- 264,274 ----
  353.         *lv = temp;
  354.         *hv = h1;
  355. !       return overflow;
  356.       }
  357.         if (l2 == 8)
  358.       {
  359. +       int overflow = left_shift_overflows (h1, 3);
  360.         unsigned temp = l1 + l1;
  361. !       h1 = (h1 << 3) + ((temp < l1) << 2);
  362.         l1 = temp;
  363.         temp += temp;
  364. ***************
  365. *** 252,256 ****
  366.         *lv = temp;
  367.         *hv = h1;
  368. !       return;
  369.       }
  370.       }
  371. --- 279,283 ----
  372.         *lv = temp;
  373.         *hv = h1;
  374. !       return overflow;
  375.       }
  376.       }
  377. ***************
  378. *** 276,279 ****
  379. --- 303,321 ----
  380.   
  381.     decode (prod, lv, hv);    /* @@decode ignores prod[8] -> prod[15] */
  382. +   /* Check for overflow by calculating the top half of the answer in full;
  383. +      it should agree with the low half's sign bit.  */
  384. +   decode (prod+8, &toplow, &tophigh);
  385. +   if (h1 < 0)
  386. +     {
  387. +       neg_double (l2, h2, &neglow, &neghigh);
  388. +       add_double (neglow, neghigh, toplow, tophigh, &toplow, &tophigh);
  389. +     }
  390. +   if (h2 < 0)
  391. +     {
  392. +       neg_double (l1, h1, &neglow, &neghigh);
  393. +       add_double (neglow, neghigh, toplow, tophigh, &toplow, &tophigh);
  394. +     }
  395. +   return *hv < 0 ? ~(toplow & tophigh) : (toplow | tophigh);
  396.   }
  397.   
  398. ***************
  399. *** 282,288 ****
  400.      Shift right if COUNT is negative.
  401.      ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
  402.      Store the value as two `int' pieces in *LV and *HV.  */
  403.   
  404. ! void
  405.   lshift_double (l1, h1, count, prec, lv, hv, arith)
  406.        int l1, h1, count, prec;
  407. --- 324,331 ----
  408.      Shift right if COUNT is negative.
  409.      ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
  410. +    Yield nonzero if the arithmetic shift overflows.
  411.      Store the value as two `int' pieces in *LV and *HV.  */
  412.   
  413. ! int
  414.   lshift_double (l1, h1, count, prec, lv, hv, arith)
  415.        int l1, h1, count, prec;
  416. ***************
  417. *** 292,296 ****
  418.     short arg1[8];
  419.     register int i;
  420. !   register int carry;
  421.   
  422.     if (count < 0)
  423. --- 335,339 ----
  424.     short arg1[8];
  425.     register int i;
  426. !   register int carry, overflow;
  427.   
  428.     if (count < 0)
  429. ***************
  430. *** 297,301 ****
  431.       {
  432.         rshift_double (l1, h1, - count, prec, lv, hv, arith);
  433. !       return;
  434.       }
  435.   
  436. --- 340,344 ----
  437.       {
  438.         rshift_double (l1, h1, - count, prec, lv, hv, arith);
  439. !       return 0;
  440.       }
  441.   
  442. ***************
  443. *** 305,308 ****
  444. --- 348,352 ----
  445.       count = prec;
  446.   
  447. +   overflow = 0;
  448.     while (count > 0)
  449.       {
  450. ***************
  451. *** 315,325 ****
  452.       }
  453.         count--;
  454.       }
  455.   
  456.     decode (arg1, lv, hv);
  457.   }
  458.   
  459.   /* Shift the 64-bit integer in L1, H1 right by COUNT places
  460. !    keeping only PREC bits of result.  COUNT must be positive.
  461.      ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
  462.      Store the value as two `int' pieces in *LV and *HV.  */
  463. --- 359,371 ----
  464.       }
  465.         count--;
  466. +       overflow |= carry ^ (arg1[7] >> 7);
  467.       }
  468.   
  469.     decode (arg1, lv, hv);
  470. +   return overflow;
  471.   }
  472.   
  473.   /* Shift the 64-bit integer in L1, H1 right by COUNT places
  474. !    keeping only PREC bits of result.  COUNT must be nonnegative.
  475.      ARITH nonzero specifies arithmetic shifting; otherwise use logical shift.
  476.      Store the value as two `int' pieces in *LV and *HV.  */
  477. ***************
  478. *** 434,440 ****
  479.      or EXACT_DIV_EXPR
  480.      It controls how the quotient is rounded to a integer.
  481.      UNS nonzero says do unsigned division.  */
  482.   
  483. ! static void
  484.   div_and_round_double (code, uns,
  485.                 lnum_orig, hnum_orig, lden_orig, hden_orig,
  486. --- 480,487 ----
  487.      or EXACT_DIV_EXPR
  488.      It controls how the quotient is rounded to a integer.
  489. +    Yield nonzero if the operation overflows.
  490.      UNS nonzero says do unsigned division.  */
  491.   
  492. ! static int
  493.   div_and_round_double (code, uns,
  494.                 lnum_orig, hnum_orig, lden_orig, hden_orig,
  495. ***************
  496. *** 454,457 ****
  497. --- 501,505 ----
  498.     unsigned int lden = lden_orig;
  499.     int hden = hden_orig;
  500. +   int overflow = 0;
  501.   
  502.     if ((hden == 0) && (lden == 0))
  503. ***************
  504. *** 461,473 ****
  505.     if (!uns) 
  506.       {
  507. !       if (hden < 0) 
  508.       {
  509.         quo_neg = ~ quo_neg;
  510. !       neg_double (lden, hden, &lden, &hden);
  511.       }
  512. !       if (hnum < 0)
  513.       {
  514.         quo_neg = ~ quo_neg;
  515. !       neg_double (lnum, hnum, &lnum, &hnum);
  516.       }
  517.       }
  518. --- 509,523 ----
  519.     if (!uns) 
  520.       {
  521. !       if (hnum < 0)
  522.       {
  523.         quo_neg = ~ quo_neg;
  524. !       /* (minimum integer) / (-1) is the only overflow case.  */
  525. !       if (neg_double (lnum, hnum, &lnum, &hnum))
  526. !         overflow = ~(hden & lden);
  527.       }
  528. !       if (hden < 0) 
  529.       {
  530.         quo_neg = ~ quo_neg;
  531. !       neg_double (lden, hden, &lden, &hden);
  532.       }
  533.       }
  534. ***************
  535. *** 642,646 ****
  536.       case TRUNC_MOD_EXPR:    /* round toward zero */
  537.       case EXACT_DIV_EXPR:    /* for this one, it shouldn't matter */
  538. !       return;
  539.   
  540.       case FLOOR_DIV_EXPR:
  541. --- 692,696 ----
  542.       case TRUNC_MOD_EXPR:    /* round toward zero */
  543.       case EXACT_DIV_EXPR:    /* for this one, it shouldn't matter */
  544. !       return overflow;
  545.   
  546.       case FLOOR_DIV_EXPR:
  547. ***************
  548. *** 651,655 ****
  549.         add_double (*lquo, *hquo, -1, -1, lquo, hquo);
  550.       }
  551. !       else return;
  552.         break;
  553.   
  554. --- 701,705 ----
  555.         add_double (*lquo, *hquo, -1, -1, lquo, hquo);
  556.       }
  557. !       else return overflow;
  558.         break;
  559.   
  560. ***************
  561. *** 660,664 ****
  562.         add_double (*lquo, *hquo, 1, 0, lquo, hquo);
  563.       }
  564. !       else return;
  565.         break;
  566.       
  567. --- 710,714 ----
  568.         add_double (*lquo, *hquo, 1, 0, lquo, hquo);
  569.       }
  570. !       else return overflow;
  571.         break;
  572.       
  573. ***************
  574. *** 686,690 ****
  575.             add_double (*lquo, *hquo, 1, 0, lquo, hquo);
  576.         }
  577. !     else return;
  578.         }
  579.         break;
  580. --- 736,740 ----
  581.             add_double (*lquo, *hquo, 1, 0, lquo, hquo);
  582.         }
  583. !     else return overflow;
  584.         }
  585.         break;
  586. ***************
  587. *** 698,701 ****
  588. --- 748,752 ----
  589.     neg_double (*lrem, *hrem, lrem, hrem);
  590.     add_double (lnum_orig, hnum_orig, *lrem, *hrem, lrem, hrem);
  591. +   return overflow;
  592.   }
  593.   
  594. ***************
  595. *** 957,960 ****
  596. --- 1008,1012 ----
  597.         register tree t;
  598.         int uns = TREE_UNSIGNED (TREE_TYPE (arg1));
  599. +       int overflow = 0;
  600.   
  601.         switch (code)
  602. ***************
  603. *** 979,986 ****
  604.         int2l = - int2l;
  605.       case LSHIFT_EXPR:
  606. !       lshift_double (int1l, int1h, int2l,
  607. !              TYPE_PRECISION (TREE_TYPE (arg1)),
  608. !              &low, &hi,
  609. !              !uns);
  610.         t = build_int_2 (low, hi);
  611.         break;
  612. --- 1031,1038 ----
  613.         int2l = - int2l;
  614.       case LSHIFT_EXPR:
  615. !       overflow = lshift_double (int1l, int1h, int2l,
  616. !                     TYPE_PRECISION (TREE_TYPE (arg1)),
  617. !                     &low, &hi,
  618. !                     !uns);
  619.         t = build_int_2 (low, hi);
  620.         break;
  621. ***************
  622. *** 1000,1004 ****
  623.             int2l += int1l;
  624.             if ((unsigned) int2l < int1l)
  625. !         int2h += 1;
  626.             t = build_int_2 (int2l, int2h);
  627.             break;
  628. --- 1052,1056 ----
  629.             int2l += int1l;
  630.             if ((unsigned) int2l < int1l)
  631. !         overflow = int2h++ >= 0 && int2h < 0;
  632.             t = build_int_2 (int2l, int2h);
  633.             break;
  634. ***************
  635. *** 1008,1016 ****
  636.             int1l += int2l;
  637.             if ((unsigned) int1l < int2l)
  638. !         int1h += 1;
  639.             t = build_int_2 (int1l, int1h);
  640.             break;
  641.           }
  642. !       add_double (int1l, int1h, int2l, int2h, &low, &hi);
  643.         t = build_int_2 (low, hi);
  644.         break;
  645. --- 1060,1068 ----
  646.             int1l += int2l;
  647.             if ((unsigned) int1l < int2l)
  648. !         overflow = int1h++ >= 0 && int1h < 0;
  649.             t = build_int_2 (int1l, int1h);
  650.             break;
  651.           }
  652. !       overflow = add_double (int1l, int1h, int2l, int2h, &low, &hi);
  653.         t = build_int_2 (low, hi);
  654.         break;
  655. ***************
  656. *** 1022,1027 ****
  657.             break;
  658.           }
  659. !       neg_double (int2l, int2h, &int2l, &int2h);
  660. !       add_double (int1l, int1h, int2l, int2h, &low, &hi);
  661.         t = build_int_2 (low, hi);
  662.         break;
  663. --- 1074,1080 ----
  664.             break;
  665.           }
  666. !       neg_double (int2l, int2h, &low, &hi);
  667. !       add_double (int1l, int1h, low, hi, &low, &hi);
  668. !       overflow = !possible_sum_sign (hi, int2h, int1h);
  669.         t = build_int_2 (low, hi);
  670.         break;
  671. ***************
  672. *** 1042,1052 ****
  673.             goto got_it;
  674.           case 2:
  675.             temp = int2l + int2l;
  676. !           int2h = int2h * 2 + (temp < int2l);
  677.             t = build_int_2 (temp, int2h);
  678.             goto got_it;
  679.           case 4:
  680.             temp = int2l + int2l;
  681. !           int2h = int2h * 4 + ((temp < int2l) << 1);
  682.             int2l = temp;
  683.             temp += temp;
  684. --- 1095,1107 ----
  685.             goto got_it;
  686.           case 2:
  687. +           overflow = left_shift_overflows (int2h, 1);
  688.             temp = int2l + int2l;
  689. !           int2h = (int2h << 1) + (temp < int2l);
  690.             t = build_int_2 (temp, int2h);
  691.             goto got_it;
  692.           case 4:
  693. +           overflow = left_shift_overflows (int2h, 2);
  694.             temp = int2l + int2l;
  695. !           int2h = (int2h << 2) + ((temp < int2l) << 1);
  696.             int2l = temp;
  697.             temp += temp;
  698. ***************
  699. *** 1055,1060 ****
  700.             goto got_it;
  701.           case 8:
  702.             temp = int2l + int2l;
  703. !           int2h = int2h * 8 + ((temp < int2l) << 2);
  704.             int2l = temp;
  705.             temp += temp;
  706. --- 1110,1116 ----
  707.             goto got_it;
  708.           case 8:
  709. +           overflow = left_shift_overflows (int2h, 3);
  710.             temp = int2l + int2l;
  711. !           int2h = (int2h << 3) + ((temp < int2l) << 2);
  712.             int2l = temp;
  713.             temp += temp;
  714. ***************
  715. *** 1084,1088 ****
  716.           }
  717.   
  718. !       mul_double (int1l, int1h, int2l, int2h, &low, &hi);
  719.         t = build_int_2 (low, hi);
  720.         break;
  721. --- 1140,1144 ----
  722.           }
  723.   
  724. !       overflow = mul_double (int1l, int1h, int2l, int2h, &low, &hi);
  725.         t = build_int_2 (low, hi);
  726.         break;
  727. ***************
  728. *** 1115,1120 ****
  729.             break;
  730.           }
  731. !       div_and_round_double (code, uns, int1l, int1h, int2l, int2h,
  732. !                 &low, &hi, &garbagel, &garbageh);
  733.         t = build_int_2 (low, hi);
  734.         break;
  735. --- 1171,1177 ----
  736.             break;
  737.           }
  738. !       overflow = div_and_round_double (code, uns,
  739. !                        int1l, int1h, int2l, int2h,
  740. !                        &low, &hi, &garbagel, &garbageh);
  741.         t = build_int_2 (low, hi);
  742.         break;
  743. ***************
  744. *** 1122,1127 ****
  745.       case TRUNC_MOD_EXPR: case ROUND_MOD_EXPR: 
  746.       case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
  747. !       div_and_round_double (code, uns, int1l, int1h, int2l, int2h,
  748. !                 &garbagel, &garbageh, &low, &hi);
  749.         t = build_int_2 (low, hi);
  750.         break;
  751. --- 1179,1185 ----
  752.       case TRUNC_MOD_EXPR: case ROUND_MOD_EXPR: 
  753.       case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
  754. !       overflow = div_and_round_double (code, uns,
  755. !                        int1l, int1h, int2l, int2h,
  756. !                        &garbagel, &garbageh, &low, &hi);
  757.         t = build_int_2 (low, hi);
  758.         break;
  759. ***************
  760. *** 1152,1156 ****
  761.       got_it:
  762.         TREE_TYPE (t) = TREE_TYPE (arg1);
  763. !       force_fit_type (t);
  764.         return t;
  765.       }
  766. --- 1210,1214 ----
  767.       got_it:
  768.         TREE_TYPE (t) = TREE_TYPE (arg1);
  769. !       force_fit_type (t, overflow);
  770.         return t;
  771.       }
  772. ***************
  773. *** 1167,1171 ****
  774.         if (setjmp (float_error))
  775.       {
  776. !       warning ("floating overflow in constant folding");
  777.         return build (code, TREE_TYPE (arg1), arg1, arg2);
  778.       }
  779. --- 1225,1229 ----
  780.         if (setjmp (float_error))
  781.       {
  782. !       pedwarn ("floating overflow in constant expression");
  783.         return build (code, TREE_TYPE (arg1), arg1, arg2);
  784.       }
  785. ***************
  786. *** 1359,1363 ****
  787.                  TREE_INT_CST_HIGH (arg1));
  788.         TREE_TYPE (t) = type;
  789. !       force_fit_type (t);
  790.       }
  791.   #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  792. --- 1417,1421 ----
  793.                  TREE_INT_CST_HIGH (arg1));
  794.         TREE_TYPE (t) = type;
  795. !       force_fit_type (t, 0);
  796.       }
  797.   #if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
  798. ***************
  799. *** 1377,1381 ****
  800.         if (! (REAL_VALUES_LESS (l, x) && REAL_VALUES_LESS (x, u)))
  801.           {
  802. !           warning ("real constant out of range for integer conversion");
  803.             return t;
  804.           }
  805. --- 1435,1439 ----
  806.         if (! (REAL_VALUES_LESS (l, x) && REAL_VALUES_LESS (x, u)))
  807.           {
  808. !           pedwarn ("real constant out of range for integer conversion");
  809.             return t;
  810.           }
  811. ***************
  812. *** 1405,1409 ****
  813.   #endif
  814.         TREE_TYPE (t) = type;
  815. !       force_fit_type (t);
  816.       }
  817.   #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  818. --- 1463,1467 ----
  819.   #endif
  820.         TREE_TYPE (t) = type;
  821. !       force_fit_type (t, 0);
  822.       }
  823.   #endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */
  824. ***************
  825. *** 1420,1424 ****
  826.         if (setjmp (float_error))
  827.           {
  828. !           warning ("floating overflow in constant folding");
  829.             return t;
  830.           }
  831. --- 1478,1482 ----
  832.         if (setjmp (float_error))
  833.           {
  834. !           pedwarn ("floating overflow in constant expression");
  835.             return t;
  836.           }
  837. ***************
  838. *** 2805,2809 ****
  839.             t = build_int_2 (TREE_STRING_POINTER (arg0)[i], 0);
  840.             TREE_TYPE (t) = TREE_TYPE (TREE_TYPE (arg0));
  841. !           force_fit_type (t);
  842.           }
  843.       }
  844. --- 2863,2867 ----
  845.             t = build_int_2 (TREE_STRING_POINTER (arg0)[i], 0);
  846.             TREE_TYPE (t) = TREE_TYPE (TREE_TYPE (arg0));
  847. !           force_fit_type (t, 0);
  848.           }
  849.       }
  850. ***************
  851. *** 2820,2830 ****
  852.         if (TREE_CODE (arg0) == INTEGER_CST)
  853.           {
  854. !           if (TREE_INT_CST_LOW (arg0) == 0)
  855. !         t = build_int_2 (0, - TREE_INT_CST_HIGH (arg0));
  856. !           else
  857. !         t = build_int_2 (- TREE_INT_CST_LOW (arg0),
  858. !                  ~ TREE_INT_CST_HIGH (arg0));
  859.             TREE_TYPE (t) = type;
  860. !           force_fit_type (t);
  861.           }
  862.         else if (TREE_CODE (arg0) == REAL_CST)
  863. --- 2878,2888 ----
  864.         if (TREE_CODE (arg0) == INTEGER_CST)
  865.           {
  866. !           int low, high;
  867. !           int overflow = neg_double (TREE_INT_CST_LOW (arg0),
  868. !                      TREE_INT_CST_HIGH (arg0),
  869. !                      &low, &high);
  870. !           t = build_int_2 (low, high);
  871.             TREE_TYPE (t) = type;
  872. !           force_fit_type (t, overflow);
  873.           }
  874.         else if (TREE_CODE (arg0) == REAL_CST)
  875. ***************
  876. *** 2876,2880 ****
  877.                    ~ TREE_INT_CST_HIGH (arg0));
  878.         TREE_TYPE (t) = type;
  879. !       force_fit_type (t);
  880.       }
  881.         else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
  882. --- 2934,2938 ----
  883.                    ~ TREE_INT_CST_HIGH (arg0));
  884.         TREE_TYPE (t) = type;
  885. !       force_fit_type (t, 0);
  886.       }
  887.         else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
  888. ===================================================================
  889. RCS file: tree.h,v
  890. retrieving revision 2.2.2.1
  891. diff -c2 -r2.2.2.1 tree.h
  892. *** tree.h    1992/06/21 05:34:02    2.2.2.1
  893. --- tree.h    1992/09/03 02:15:57
  894. ***************
  895. *** 219,224 ****
  896.   #define TREE_NO_UNUSED_WARNING(NODE) ((NODE)->common.static_flag)
  897.   
  898. ! /* In a NON_LVALUE_EXPR, this means there was overflow in folding.
  899. !    The folded constant is inside the NON_LVALUE_EXPR.  */
  900.   #define TREE_CONSTANT_OVERFLOW(NODE) ((NODE)->common.static_flag)
  901.   
  902. --- 219,223 ----
  903.   #define TREE_NO_UNUSED_WARNING(NODE) ((NODE)->common.static_flag)
  904.   
  905. ! /* In an INTEGER_CST, this means there was overflow in folding.  */
  906.   #define TREE_CONSTANT_OVERFLOW(NODE) ((NODE)->common.static_flag)
  907.   
  908.  
  909.