diff mbox

[Ada] Fix 'Last_Bit attribute applied to zero-sized type

Message ID 1602805.ChmZN7zUlP@polaris
State New
Headers show

Commit Message

Eric Botcazou May 26, 2013, 10:06 a.m. UTC
The value of the attribute should be -1 if an object of such a type is placed 
on a storage unit boundary, but the compiler was generating Storage_Error.

Tested on x86_64-suse-linux, applied on all active branches.


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-05-26  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/specs/last_bit.ads: New test.
diff mbox

Patch

Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 199336)
+++ gcc-interface/trans.c	(working copy)
@@ -2080,14 +2080,19 @@  Attribute_to_gnu (Node_Id gnat_node, tre
 	    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.  */