]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
trans.c (Attribute_to_gnu): Add kludge to avoid generating an overflow for -1.
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 26 May 2013 10:06:18 +0000 (10:06 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Sun, 26 May 2013 10:06:18 +0000 (10:06 +0000)
* gcc-interface/trans.c (Attribute_to_gnu) <Attr_Last_Bit>: Add kludge
to avoid generating an overflow for -1.

From-SVN: r199341

gcc/ada/ChangeLog
gcc/ada/gcc-interface/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/specs/last_bit.ads [new file with mode: 0644]

index af231667fe6df1a97c4d7eb7925d4ee41972f511..3da582dd2d6e9d83756bb575ead9e9256031c622 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-26  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/trans.c (Attribute_to_gnu) <Attr_Last_Bit>: Add kludge
+       to avoid generating an overflow for -1.
+
 2013-04-11  Release Manager
 
        * GCC 4.7.3 released.
index aabe9b6bd02004d405085e4155691e9d4c52da56..e5f8351242aafec3c29db98e0328fe8b0b1821a9 100644 (file)
@@ -1901,14 +1901,19 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
            gnu_result = bitsize_int (bitpos % BITS_PER_UNIT);
            gnu_result = size_binop (PLUS_EXPR, gnu_result,
                                     TYPE_SIZE (TREE_TYPE (gnu_prefix)));
-           gnu_result = size_binop (MINUS_EXPR, gnu_result,
-                                    bitsize_one_node);
+           /* ??? Avoid a large unsigned result that will overflow when
+              converted to the signed universal_integer.  */
+           if (integer_zerop (gnu_result))
+             gnu_result = integer_minus_one_node;
+           else
+             gnu_result
+               = size_binop (MINUS_EXPR, gnu_result, bitsize_one_node);
            break;
 
          case Attr_Bit_Position:
            gnu_result = gnu_field_bitpos;
            break;
-               }
+         }
 
        /* If this has a PLACEHOLDER_EXPR, qualify it by the object we are
           handling.  */
index eda744322b74827c881766ae8cdc09ab0bd69944..e8b54e4fb14b9bb09a1a84de1aeebaa8103ffa68 100644 (file)
@@ -1,3 +1,7 @@
+2013-05-26  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/last_bit.ads: New test.
+
 2013-05-13  Uros Bizjak  <ubizjak@gmail.com>
 
        PR target/57264
diff --git a/gcc/testsuite/gnat.dg/specs/last_bit.ads b/gcc/testsuite/gnat.dg/specs/last_bit.ads
new file mode 100644 (file)
index 0000000..ecfc254
--- /dev/null
@@ -0,0 +1,19 @@
+-- { dg-do compile }
+
+package Last_Bit is
+
+   Max_Components : constant := 100;
+   type Count_Type is new Natural range 0 .. Max_Components;
+   subtype Index_Type is Count_Type range 1 .. Count_Type'Last;
+   
+   type List_Type is array (Index_Type range <>) of Integer;
+
+   type Record_Type (Count : Count_Type := 0) is record
+      List : List_Type (1 .. Count);
+   end record;
+
+   Null_Record : Record_Type (Count => 0);
+
+   List_Last_Bit : Integer := Null_Record.List'Last_Bit;
+
+end Last_Bit;