diff mbox

[Ada] Correctly annotate negative values for the front-end

Message ID 1496279.mVPCX8eUif@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 13, 2016, 6:20 p.m. UTC
gigi cannot back-annotate negative values in expressions for the front-end 
directly because only non-negative values are supported directly.

Fixed thusly, tested on x86_64-suse-linux, applied on the mainline.


2016-11-13  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (annotate_value) <INTEGER_CST>: Deal specially
	with negative constants.

-- 
Eric Botcazou
diff mbox

Patch

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 242334)
+++ gcc-interface/decl.c	(working copy)
@@ -8022,6 +8022,14 @@  annotate_value (tree gnu_size)
   switch (TREE_CODE (gnu_size))
     {
     case INTEGER_CST:
+      /* For negative values, build NEGATE_EXPR of the opposite.  Such values
+	 can appear for discriminants in expressions for variants.  */
+      if (tree_int_cst_sgn (gnu_size) < 0)
+	{
+	  tree t = wide_int_to_tree (sizetype, wi::neg (gnu_size));
+	  return annotate_value (build1 (NEGATE_EXPR, sizetype, t));
+	}
+
       return TREE_OVERFLOW (gnu_size) ? No_Uint : UI_From_gnu (gnu_size);
 
     case COMPONENT_REF: