[Ada] Fix debug info for variant records on m68k

Message ID 1693514.iT2t62ubmi@polaris
State New
Headers show
Series
  • [Ada] Fix debug info for variant records on m68k
Related show

Commit Message

Eric Botcazou Dec. 3, 2019, 10:12 a.m.
This fixes a bug in the encoding used in the debug info generated for record 
types with variant part for targets where the alignment is capped to 16 bits 
like the m68k (unless -malign-int is specified).

Tested on m68k-elf and x86_64-suse-linux, applied on the mainline.


2019-12-03  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils.c (fold_convert_size): New function.
	(fold_bit_position): Invoke it to do further folding.

-- 
Eric Botcazou

Patch

Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 277906)
+++ gcc-interface/utils.c	(working copy)
@@ -2349,19 +2349,27 @@  merge_sizes (tree last_size, tree first_
   return new_size;
 }
 
+/* Convert the size expression EXPR to TYPE and fold the result.  */
+
+static tree
+fold_convert_size (tree type, tree expr)
+{
+  /* We assume that size expressions do not wrap around.  */
+  if (TREE_CODE (expr) == MULT_EXPR || TREE_CODE (expr) == PLUS_EXPR)
+    return size_binop (TREE_CODE (expr),
+		       fold_convert_size (type, TREE_OPERAND (expr, 0)),
+		       fold_convert_size (type, TREE_OPERAND (expr, 1)));
+
+  return fold_convert (type, expr);
+}
+
 /* Return the bit position of FIELD, in bits from the start of the record,
    and fold it as much as possible.  This is a tree of type bitsizetype.  */
 
 static tree
 fold_bit_position (const_tree field)
 {
-  tree offset = DECL_FIELD_OFFSET (field);
-  if (TREE_CODE (offset) == MULT_EXPR || TREE_CODE (offset) == PLUS_EXPR)
-    offset = size_binop (TREE_CODE (offset),
-			 fold_convert (bitsizetype, TREE_OPERAND (offset, 0)),
-			 fold_convert (bitsizetype, TREE_OPERAND (offset, 1)));
-  else
-    offset = fold_convert (bitsizetype, offset);
+  tree offset = fold_convert_size (bitsizetype, DECL_FIELD_OFFSET (field));
   return size_binop (PLUS_EXPR, DECL_FIELD_BIT_OFFSET (field),
  		     size_binop (MULT_EXPR, offset, bitsize_unit_node));
 }