The fix for PR c/60226
  https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=212346
changed the type of the 'divisor' parameter of the round_up_loc function from 
'int' to 'unsigned int'.  Now the function does the usual masking dance with 
powers of two, in particular:

  t = build_int_cst (TREE_TYPE (value), -divisor);

The 2nd parameter of build_int_cst being HOST_WIDE_INT, the argument is now 
zero-extended from 'unsigned int' to HOST_WIDE_INT instead of sign-extended.

This is harmless in most cases, but not if you're manipulating huge sizes 
because the upper 32-bit part is wrongly masked out, which for example causes 
a warning to disappear for the attached Ada testcase.

Tested on x86_64-suse-linux, applied on the mainline as obvious.

There might be a similar issue in the block of code just above:

          wide_int val = value;
          bool overflow_p;

          if ((val & (divisor - 1)) == 0)
            return value;

          overflow_p = TREE_OVERFLOW (value);
          val &= ~(divisor - 1);

but I don't have a testcase and don't know enough of wide_int to assert it.


2015-03-03  Eric Botcazou  <ebotca...@adacore.com>

        * fold-const.c (round_up_loc): Cast divisor to HOST_WIDE_INT before
        negating it.

        * tree-sra.c (pa_sra_preliminary_function_checks): Fix typo in message.


2015-03-03  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/object_overflow5.adb: New test.


-- 
Eric Botcazou
Index: fold-const.c
===================================================================
--- fold-const.c	(revision 221132)
+++ fold-const.c	(working copy)
@@ -16032,7 +16032,7 @@ round_up_loc (location_t loc, tree value
 
 	  t = build_int_cst (TREE_TYPE (value), divisor - 1);
 	  value = size_binop_loc (loc, PLUS_EXPR, value, t);
-	  t = build_int_cst (TREE_TYPE (value), -divisor);
+	  t = build_int_cst (TREE_TYPE (value), - (HOST_WIDE_INT) divisor);
 	  value = size_binop_loc (loc, BIT_AND_EXPR, value, t);
 	}
     }
Index: tree-sra.c
===================================================================
--- tree-sra.c	(revision 221150)
+++ tree-sra.c	(working copy)
@@ -5144,7 +5144,7 @@ ipa_sra_preliminary_function_checks (str
     {
       if (dump_file)
 	fprintf (dump_file,
-		 "A function call has an argument with non-unit alignemnt.\n");
+		 "A function call has an argument with non-unit alignment.\n");
       return false;
     }
 
-- { dg-do compile }

procedure Object_Overflow5 is

  procedure Proc (c : Character) is begin null; end;

  type Index is new Long_Integer range 0 .. Long_Integer'Last;

  type Arr is array(Index range <>) of Character;

  type Rec (Size: Index := 6) is record -- { dg-warning "Storage_Error" }
    A: Arr (0..Size);
  end record;

  Obj : Rec; -- { dg-warning "Storage_Error" }

begin
  Obj.A(1) := 'a';
  Proc (Obj.A(1));
end;

Reply via email to