OSDN Git Service

Fix PR debug/49047
[pf3gnuchains/gcc-fork.git] / gcc / dwarf2out.c
index 91be9a4..9a415e9 100644 (file)
@@ -267,7 +267,6 @@ typedef union GTY(()) dw_cfi_oprnd_struct {
 dw_cfi_oprnd;
 
 typedef struct GTY(()) dw_cfi_struct {
-  dw_cfi_ref dw_cfi_next;
   enum dwarf_call_frame_info dw_cfi_opc;
   dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
     dw_cfi_oprnd1;
@@ -276,6 +275,12 @@ typedef struct GTY(()) dw_cfi_struct {
 }
 dw_cfi_node;
 
+DEF_VEC_P (dw_cfi_ref);
+DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
+DEF_VEC_ALLOC_P (dw_cfi_ref, gc);
+
+typedef VEC(dw_cfi_ref, gc) *cfi_vec;
+
 /* This is how we define the location of the CFA. We use to handle it
    as REG + OFFSET all the time,  but now it can be more complex.
    It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
@@ -304,8 +309,8 @@ typedef struct GTY(()) dw_fde_struct {
   const char *dw_fde_vms_begin_epilogue;
   const char *dw_fde_second_begin;
   const char *dw_fde_second_end;
-  dw_cfi_ref dw_fde_cfi;
-  dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections.  */
+  cfi_vec dw_fde_cfi;
+  int dw_fde_switch_cfi_index; /* Last CFI before switching sections.  */
   HOST_WIDE_INT stack_realignment;
   unsigned funcdef_number;
   /* Dynamic realign argument pointer register.  */
@@ -410,8 +415,8 @@ current_fde (void)
   return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
 }
 
-/* A list of call frame insns for the CIE.  */
-static GTY(()) dw_cfi_ref cie_cfi_head;
+/* A vector of call frame insns for the CIE.  */
+static GTY(()) cfi_vec cie_cfi_vec;
 
 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
    attribute that accelerates the lookup of the FDE associated
@@ -428,10 +433,6 @@ struct GTY(()) indirect_string_node {
 
 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
 
-/* True if the compilation unit has location entries that reference
-   debug strings.  */
-static GTY(()) bool debug_str_hash_forced = false;
-
 static GTY(()) int dw2_string_counter;
 static GTY(()) unsigned long dwarf2out_cfi_label_num;
 
@@ -451,7 +452,7 @@ static GTY(()) section *cold_text_section;
 static char *stripattributes (const char *);
 static const char *dwarf_cfi_name (unsigned);
 static dw_cfi_ref new_cfi (void);
-static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
+static void add_cfi (cfi_vec *, dw_cfi_ref);
 static void add_fde_cfi (const char *, dw_cfi_ref);
 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
 static void lookup_cfa (dw_cfa_location *);
@@ -477,7 +478,8 @@ static struct dw_loc_descr_struct *build_cfa_aligned_loc
   (HOST_WIDE_INT, HOST_WIDE_INT);
 static void def_cfa_1 (const char *, dw_cfa_location *);
 static struct dw_loc_descr_struct *mem_loc_descriptor
-  (rtx, enum machine_mode mode, enum var_init_status);
+  (rtx, enum machine_mode mode, enum machine_mode mem_mode,
+   enum var_init_status);
 
 /* How to start an assembler comment.  */
 #ifndef ASM_COMMENT_START
@@ -807,7 +809,6 @@ new_cfi (void)
 {
   dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
 
-  cfi->dw_cfi_next = NULL;
   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
   cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
 
@@ -817,9 +818,8 @@ new_cfi (void)
 /* Add a Call Frame Instruction to list of instructions.  */
 
 static inline void
-add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
+add_cfi (cfi_vec *vec, dw_cfi_ref cfi)
 {
-  dw_cfi_ref *p;
   dw_fde_ref fde = current_fde ();
 
   /* When DRAP is used, CFA is defined with an expression.  Redefine
@@ -841,11 +841,7 @@ add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
           break;
       }
 
-  /* Find the end of the chain.  */
-  for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
-    ;
-
-  *p = cfi;
+  VEC_safe_push (dw_cfi_ref, gc, *vec, cfi);
 }
 
 /* Generate a new label for the CFI info to refer to.  FORCE is true
@@ -885,7 +881,12 @@ static bool any_cfis_emitted;
 static void
 add_fde_cfi (const char *label, dw_cfi_ref cfi)
 {
-  dw_cfi_ref *list_head;
+  cfi_vec *vec;
+
+  if (cie_cfi_vec == NULL)
+    cie_cfi_vec = VEC_alloc (dw_cfi_ref, gc, 20);
+
+  vec = &cie_cfi_vec;
 
   if (emit_cfa_remember)
     {
@@ -898,8 +899,6 @@ add_fde_cfi (const char *label, dw_cfi_ref cfi)
       add_fde_cfi (label, cfi_remember);
     }
 
-  list_head = &cie_cfi_head;
-
   if (dwarf2out_do_cfi_asm ())
     {
       if (label)
@@ -957,7 +956,7 @@ add_fde_cfi (const char *label, dw_cfi_ref cfi)
 
          output_cfi_directive (cfi);
 
-         list_head = &fde->dw_fde_cfi;
+         vec = &fde->dw_fde_cfi;
          any_cfis_emitted = true;
        }
       /* ??? If this is a CFI for the CIE, we don't emit.  This
@@ -995,11 +994,11 @@ add_fde_cfi (const char *label, dw_cfi_ref cfi)
          fde->dw_fde_current_label = label;
        }
 
-      list_head = &fde->dw_fde_cfi;
+      vec = &fde->dw_fde_cfi;
       any_cfis_emitted = true;
     }
 
-  add_cfi (list_head, cfi);
+  add_cfi (vec, cfi);
 }
 
 /* Subroutine of lookup_cfa.  */
@@ -1046,6 +1045,7 @@ lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
 static void
 lookup_cfa (dw_cfa_location *loc)
 {
+  int ix;
   dw_cfi_ref cfi;
   dw_fde_ref fde;
   dw_cfa_location remember;
@@ -1054,12 +1054,12 @@ lookup_cfa (dw_cfa_location *loc)
   loc->reg = INVALID_REGNUM;
   remember = *loc;
 
-  for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
+  FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
     lookup_cfa_1 (cfi, loc, &remember);
 
   fde = current_fde ();
   if (fde)
-    for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
+    FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
       lookup_cfa_1 (cfi, loc, &remember);
 }
 
@@ -2050,6 +2050,17 @@ dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
   reg_save (label, sregno, dregno, 0);
 }
 
+/* Helper function to get mode of MEM's address.  */
+
+static inline enum machine_mode
+get_address_mode (rtx mem)
+{
+  enum machine_mode mode = GET_MODE (XEXP (mem, 0));
+  if (mode != VOIDmode)
+    return mode;
+  return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
+}
+
 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
 
 static void
@@ -2070,8 +2081,8 @@ dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
   cfi->dw_cfi_opc = DW_CFA_expression;
   cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
   cfi->dw_cfi_oprnd2.dw_cfi_loc
-    = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
-                         VAR_INIT_STATUS_INITIALIZED);
+    = mem_loc_descriptor (XEXP (dest, 0), get_address_mode (dest),
+                         GET_MODE (dest), VAR_INIT_STATUS_INITIALIZED);
 
   /* ??? We'd like to use queue_reg_save, were the interface different,
      and, as above, we could manage flushing for epilogues.  */
@@ -2226,7 +2237,7 @@ dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
           cfa_temp.offset = <const_int>
 
   Rule 10:
-  (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
+  (set (mem ({pre,post}_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
   effects: cfa_store.offset -= <const_int>
           cfa.offset = cfa_store.offset if cfa.reg == sp
           cfa.reg = sp
@@ -2567,6 +2578,7 @@ dwarf2out_frame_debug_expr (rtx expr, const char *label)
          /* Rule 10 */
          /* With a push.  */
        case PRE_MODIFY:
+       case POST_MODIFY:
          /* We can't handle variable size modifications.  */
          gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
                      == CONST_INT);
@@ -2579,7 +2591,10 @@ dwarf2out_frame_debug_expr (rtx expr, const char *label)
          if (cfa.reg == STACK_POINTER_REGNUM)
            cfa.offset = cfa_store.offset;
 
-         offset = -cfa_store.offset;
+         if (GET_CODE (XEXP (dest, 0)) == POST_MODIFY)
+           offset -= cfa_store.offset;
+         else
+           offset = -cfa_store.offset;
          break;
 
          /* Rule 11 */
@@ -2788,38 +2803,6 @@ dwarf2out_frame_debug (rtx insn, bool after_p)
   rtx note, n;
   bool handled_one = false;
 
-  if (insn == NULL_RTX)
-    {
-      size_t i;
-
-      /* Flush any queued register saves.  */
-      dwarf2out_flush_queued_reg_saves ();
-
-      /* Set up state for generating call frame debug info.  */
-      lookup_cfa (&cfa);
-      gcc_assert (cfa.reg
-                 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
-
-      cfa.reg = STACK_POINTER_REGNUM;
-      cfa_store = cfa;
-      cfa_temp.reg = -1;
-      cfa_temp.offset = 0;
-
-      for (i = 0; i < num_regs_saved_in_regs; i++)
-       {
-         regs_saved_in_regs[i].orig_reg = NULL_RTX;
-         regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
-       }
-      num_regs_saved_in_regs = 0;
-
-      if (barrier_args_size)
-       {
-         XDELETEVEC (barrier_args_size);
-         barrier_args_size = NULL;
-       }
-      return;
-    }
-
   if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
     dwarf2out_flush_queued_reg_saves ();
 
@@ -2937,6 +2920,40 @@ dwarf2out_frame_debug (rtx insn, bool after_p)
     dwarf2out_flush_queued_reg_saves ();
 }
 
+/* Called once at the start of final to initialize some data for the
+   current function.  */
+void
+dwarf2out_frame_debug_init (void)
+{
+  size_t i;
+
+  /* Flush any queued register saves.  */
+  dwarf2out_flush_queued_reg_saves ();
+
+  /* Set up state for generating call frame debug info.  */
+  lookup_cfa (&cfa);
+  gcc_assert (cfa.reg
+             == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
+
+  cfa.reg = STACK_POINTER_REGNUM;
+  cfa_store = cfa;
+  cfa_temp.reg = -1;
+  cfa_temp.offset = 0;
+
+  for (i = 0; i < num_regs_saved_in_regs; i++)
+    {
+      regs_saved_in_regs[i].orig_reg = NULL_RTX;
+      regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
+    }
+  num_regs_saved_in_regs = 0;
+
+  if (barrier_args_size)
+    {
+      XDELETEVEC (barrier_args_size);
+      barrier_args_size = NULL;
+    }
+}
+
 /* Determine if we need to save and restore CFI information around this
    epilogue.  If SIBCALL is true, then this is a sibcall epilogue.  If
    we do need to save/restore, then emit the save now, and insert a
@@ -3428,169 +3445,183 @@ output_cfi_directive (dw_cfi_ref cfi)
     }
 }
 
-DEF_VEC_P (dw_cfi_ref);
-DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
-
-/* Output CFIs to bring current FDE to the same state as after executing
-   CFIs in CFI chain.  DO_CFI_ASM is true if .cfi_* directives shall
-   be emitted, false otherwise.  If it is false, FDE and FOR_EH are the
-   other arguments to pass to output_cfi.  */
+/* Output CFIs from VEC, up to index UPTO, to bring current FDE to the
+   same state as after executing CFIs in CFI chain.  DO_CFI_ASM is
+   true if .cfi_* directives shall be emitted, false otherwise.  If it
+   is false, FDE and FOR_EH are the other arguments to pass to
+   output_cfi.  */
 
 static void
-output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
+output_cfis (cfi_vec vec, int upto, bool do_cfi_asm,
+            dw_fde_ref fde, bool for_eh)
 {
+  int ix;
   struct dw_cfi_struct cfi_buf;
   dw_cfi_ref cfi2;
   dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
-  VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
+  VEC(dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
   unsigned int len, idx;
 
-  for (;; cfi = cfi->dw_cfi_next)
-    switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
-      {
-      case DW_CFA_advance_loc:
-      case DW_CFA_advance_loc1:
-      case DW_CFA_advance_loc2:
-      case DW_CFA_advance_loc4:
-      case DW_CFA_MIPS_advance_loc8:
-      case DW_CFA_set_loc:
-       /* All advances should be ignored.  */
-       break;
-      case DW_CFA_remember_state:
+  for (ix = 0; ix < upto + 1; ix++)
+    {
+      dw_cfi_ref cfi = ix < upto ? VEC_index (dw_cfi_ref, vec, ix) : NULL;
+      switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
        {
-         dw_cfi_ref args_size = cfi_args_size;
-
-         /* Skip everything between .cfi_remember_state and
-            .cfi_restore_state.  */
-         for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
-           if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
-             break;
-           else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
-             args_size = cfi2;
-           else
-             gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
-
-         if (cfi2 == NULL)
-           goto flush_all;
-         else
-           {
-             cfi = cfi2;
-             cfi_args_size = args_size;
-           }
+       case DW_CFA_advance_loc:
+       case DW_CFA_advance_loc1:
+       case DW_CFA_advance_loc2:
+       case DW_CFA_advance_loc4:
+       case DW_CFA_MIPS_advance_loc8:
+       case DW_CFA_set_loc:
+         /* All advances should be ignored.  */
          break;
-       }
-      case DW_CFA_GNU_args_size:
-       cfi_args_size = cfi;
-       break;
-      case DW_CFA_GNU_window_save:
-       goto flush_all;
-      case DW_CFA_offset:
-      case DW_CFA_offset_extended:
-      case DW_CFA_offset_extended_sf:
-      case DW_CFA_restore:
-      case DW_CFA_restore_extended:
-      case DW_CFA_undefined:
-      case DW_CFA_same_value:
-      case DW_CFA_register:
-      case DW_CFA_val_offset:
-      case DW_CFA_val_offset_sf:
-      case DW_CFA_expression:
-      case DW_CFA_val_expression:
-      case DW_CFA_GNU_negative_offset_extended:
-       if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
-         VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
-                                cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
-       VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
-       break;
-      case DW_CFA_def_cfa:
-      case DW_CFA_def_cfa_sf:
-      case DW_CFA_def_cfa_expression:
-       cfi_cfa = cfi;
-       cfi_cfa_offset = cfi;
-       break;
-      case DW_CFA_def_cfa_register:
-       cfi_cfa = cfi;
-       break;
-      case DW_CFA_def_cfa_offset:
-      case DW_CFA_def_cfa_offset_sf:
-       cfi_cfa_offset = cfi;
-       break;
-      case DW_CFA_nop:
-       gcc_assert (cfi == NULL);
-      flush_all:
-       len = VEC_length (dw_cfi_ref, regs);
-       for (idx = 0; idx < len; idx++)
+       case DW_CFA_remember_state:
          {
-           cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
-           if (cfi2 != NULL
-               && cfi2->dw_cfi_opc != DW_CFA_restore
-               && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
+           dw_cfi_ref args_size = cfi_args_size;
+
+           /* Skip everything between .cfi_remember_state and
+              .cfi_restore_state.  */
+           ix++;
+           if (ix == upto)
+             goto flush_all;
+
+           for (; ix < upto; ix++)
              {
-               if (do_cfi_asm)
-                 output_cfi_directive (cfi2);
+               cfi2 = VEC_index (dw_cfi_ref, vec, ix);
+               if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
+                 break;
+               else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
+                 args_size = cfi2;
                else
-                 output_cfi (cfi2, fde, for_eh);
-             }
-         }
-       if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
-         {
-           gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
-           cfi_buf = *cfi_cfa;
-           switch (cfi_cfa_offset->dw_cfi_opc)
-             {
-             case DW_CFA_def_cfa_offset:
-               cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
-               cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
-               break;
-             case DW_CFA_def_cfa_offset_sf:
-               cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
-               cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
-               break;
-             case DW_CFA_def_cfa:
-             case DW_CFA_def_cfa_sf:
-               cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
-               cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
-               break;
-             default:
-               gcc_unreachable ();
+                 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
              }
-           cfi_cfa = &cfi_buf;
-         }
-       else if (cfi_cfa_offset)
-         cfi_cfa = cfi_cfa_offset;
-       if (cfi_cfa)
-         {
-           if (do_cfi_asm)
-             output_cfi_directive (cfi_cfa);
-           else
-             output_cfi (cfi_cfa, fde, for_eh);
-         }
-       cfi_cfa = NULL;
-       cfi_cfa_offset = NULL;
-       if (cfi_args_size
-           && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
-         {
-           if (do_cfi_asm)
-             output_cfi_directive (cfi_args_size);
-           else
-             output_cfi (cfi_args_size, fde, for_eh);
-         }
-       cfi_args_size = NULL;
-       if (cfi == NULL)
-         {
-           VEC_free (dw_cfi_ref, heap, regs);
-           return;
+
+           cfi_args_size = args_size;
+           break;
          }
-       else if (do_cfi_asm)
-         output_cfi_directive (cfi);
-       else
-         output_cfi (cfi, fde, for_eh);
-       break;
-      default:
-       gcc_unreachable ();
+       case DW_CFA_GNU_args_size:
+         cfi_args_size = cfi;
+         break;
+       case DW_CFA_GNU_window_save:
+         goto flush_all;
+       case DW_CFA_offset:
+       case DW_CFA_offset_extended:
+       case DW_CFA_offset_extended_sf:
+       case DW_CFA_restore:
+       case DW_CFA_restore_extended:
+       case DW_CFA_undefined:
+       case DW_CFA_same_value:
+       case DW_CFA_register:
+       case DW_CFA_val_offset:
+       case DW_CFA_val_offset_sf:
+       case DW_CFA_expression:
+       case DW_CFA_val_expression:
+       case DW_CFA_GNU_negative_offset_extended:
+         if (VEC_length (dw_cfi_ref, regs)
+             <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
+           VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
+                                  cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
+         VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
+                      cfi);
+         break;
+       case DW_CFA_def_cfa:
+       case DW_CFA_def_cfa_sf:
+       case DW_CFA_def_cfa_expression:
+         cfi_cfa = cfi;
+         cfi_cfa_offset = cfi;
+         break;
+       case DW_CFA_def_cfa_register:
+         cfi_cfa = cfi;
+         break;
+       case DW_CFA_def_cfa_offset:
+       case DW_CFA_def_cfa_offset_sf:
+         cfi_cfa_offset = cfi;
+         break;
+       case DW_CFA_nop:
+         gcc_assert (cfi == NULL);
+       flush_all:
+         len = VEC_length (dw_cfi_ref, regs);
+         for (idx = 0; idx < len; idx++)
+           {
+             cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
+             if (cfi2 != NULL
+                 && cfi2->dw_cfi_opc != DW_CFA_restore
+                 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
+               {
+                 if (do_cfi_asm)
+                   output_cfi_directive (cfi2);
+                 else
+                   output_cfi (cfi2, fde, for_eh);
+               }
+           }
+         if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
+           {
+             gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
+             cfi_buf = *cfi_cfa;
+             switch (cfi_cfa_offset->dw_cfi_opc)
+               {
+               case DW_CFA_def_cfa_offset:
+                 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
+                 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
+                 break;
+               case DW_CFA_def_cfa_offset_sf:
+                 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
+                 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
+                 break;
+               case DW_CFA_def_cfa:
+               case DW_CFA_def_cfa_sf:
+                 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
+                 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
+                 break;
+               default:
+                 gcc_unreachable ();
+               }
+             cfi_cfa = &cfi_buf;
+           }
+         else if (cfi_cfa_offset)
+           cfi_cfa = cfi_cfa_offset;
+         if (cfi_cfa)
+           {
+             if (do_cfi_asm)
+               output_cfi_directive (cfi_cfa);
+             else
+               output_cfi (cfi_cfa, fde, for_eh);
+           }
+         cfi_cfa = NULL;
+         cfi_cfa_offset = NULL;
+         if (cfi_args_size
+             && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
+           {
+             if (do_cfi_asm)
+               output_cfi_directive (cfi_args_size);
+             else
+               output_cfi (cfi_args_size, fde, for_eh);
+           }
+         cfi_args_size = NULL;
+         if (cfi == NULL)
+           {
+             VEC_free (dw_cfi_ref, heap, regs);
+             return;
+           }
+         else if (do_cfi_asm)
+           output_cfi_directive (cfi);
+         else
+           output_cfi (cfi, fde, for_eh);
+         break;
+       default:
+         gcc_unreachable ();
+       }
     }
 }
 
+/* Like output_cfis, but emit all CFIs in the vector.  */
+static void
+output_all_cfis (cfi_vec vec, bool do_cfi_asm,
+                dw_fde_ref fde, bool for_eh)
+{
+  output_cfis (vec, VEC_length (dw_cfi_ref, vec), do_cfi_asm, fde, for_eh);
+}
+
 /* Output one FDE.  */
 
 static void
@@ -3598,6 +3629,7 @@ output_fde (dw_fde_ref fde, bool for_eh, bool second,
            char *section_start_label, int fde_encoding, char *augmentation,
            bool any_lsda_needed, int lsda_encoding)
 {
+  int ix;
   const char *begin, *end;
   static unsigned int j;
   char l1[20], l2[20];
@@ -3685,31 +3717,31 @@ output_fde (dw_fde_ref fde, bool for_eh, bool second,
      this FDE.  */
   fde->dw_fde_current_label = begin;
   if (fde->dw_fde_second_begin == NULL)
-    for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
+    FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
       output_cfi (cfi, fde, for_eh);
   else if (!second)
     {
-      if (fde->dw_fde_switch_cfi)
-       for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
+      if (fde->dw_fde_switch_cfi_index > 0)
+       FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
          {
-           output_cfi (cfi, fde, for_eh);
-           if (cfi == fde->dw_fde_switch_cfi)
+           if (ix == fde->dw_fde_switch_cfi_index)
              break;
+           output_cfi (cfi, fde, for_eh);
          }
     }
   else
     {
-      dw_cfi_ref cfi_next = fde->dw_fde_cfi;
+      int i, from = 0;
+      int until = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
 
-      if (fde->dw_fde_switch_cfi)
+      if (fde->dw_fde_switch_cfi_index > 0)
        {
-         cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
-         fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
-         output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
-         fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
+         from = fde->dw_fde_switch_cfi_index;
+         output_cfis (fde->dw_fde_cfi, from, false, fde, for_eh);
        }
-      for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
-       output_cfi (cfi, fde, for_eh);
+      for (i = from; i < until; i++)
+       output_cfi (VEC_index (dw_cfi_ref, fde->dw_fde_cfi, i),
+                   fde, for_eh);
     }
 
   /* If we are to emit a ref/link from function bodies to their frame tables,
@@ -3945,7 +3977,7 @@ output_call_frame_info (int for_eh)
                             eh_data_format_name (fde_encoding));
     }
 
-  for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
+  FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, i, cfi)
     output_cfi (cfi, NULL, for_eh);
 
   /* Pad the CIE out to an address sized boundary.  */
@@ -4087,8 +4119,8 @@ dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
   fde->dw_fde_second_end = NULL;
   fde->dw_fde_vms_end_prologue = NULL;
   fde->dw_fde_vms_begin_epilogue = NULL;
-  fde->dw_fde_cfi = NULL;
-  fde->dw_fde_switch_cfi = NULL;
+  fde->dw_fde_cfi = VEC_alloc (dw_cfi_ref, gc, 20);
+  fde->dw_fde_switch_cfi_index = 0;
   fde->funcdef_number = current_function_funcdef_no;
   fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
   fde->uses_eh_lsda = crtl->uses_eh_lsda;
@@ -4242,13 +4274,13 @@ dwarf2out_note_section_used (void)
 }
 
 static void var_location_switch_text_section (void);
+static void set_cur_line_info_table (section *);
 
 void
 dwarf2out_switch_text_section (void)
 {
   section *sect;
   dw_fde_ref fde = current_fde ();
-  dw_cfi_ref cfi;
 
   gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
 
@@ -4290,14 +4322,12 @@ dwarf2out_switch_text_section (void)
       dwarf2out_do_cfi_startproc (true);
       /* As this is a different FDE, insert all current CFI instructions
         again.  */
-      output_cfis (fde->dw_fde_cfi, true, fde, true);
+      output_all_cfis (fde->dw_fde_cfi, true, fde, true);
     }
-  cfi = fde->dw_fde_cfi;
-  if (cfi)
-    while (cfi->dw_cfi_next != NULL)
-      cfi = cfi->dw_cfi_next;
-  fde->dw_fde_switch_cfi = cfi;
+  fde->dw_fde_switch_cfi_index = VEC_length (dw_cfi_ref, fde->dw_fde_cfi);
   var_location_switch_text_section ();
+
+  set_cur_line_info_table (sect);
 }
 \f
 /* And now, the subset of the debugging information support code necessary
@@ -4767,6 +4797,16 @@ dwarf_stack_op_name (unsigned int op)
       return "DW_OP_GNU_implicit_pointer";
     case DW_OP_GNU_entry_value:
       return "DW_OP_GNU_entry_value";
+    case DW_OP_GNU_const_type:
+      return "DW_OP_GNU_const_type";
+    case DW_OP_GNU_regval_type:
+      return "DW_OP_GNU_regval_type";
+    case DW_OP_GNU_deref_type:
+      return "DW_OP_GNU_deref_type";
+    case DW_OP_GNU_convert:
+      return "DW_OP_GNU_convert";
+    case DW_OP_GNU_reinterpret:
+      return "DW_OP_GNU_reinterpret";
 
     default:
       return "OP_<unknown>";
@@ -4874,6 +4914,7 @@ loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
   (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
 
 static unsigned long size_of_locs (dw_loc_descr_ref);
+static unsigned long int get_base_type_offset (dw_die_ref);
 
 /* Return the size of a location descriptor.  */
 
@@ -4996,6 +5037,50 @@ size_of_loc_descr (dw_loc_descr_ref loc)
        size += size_of_uleb128 (op_size) + op_size;
        break;
       }
+    case DW_OP_GNU_const_type:
+      {
+       unsigned long o
+         = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
+       size += size_of_uleb128 (o) + 1;
+       switch (loc->dw_loc_oprnd2.val_class)
+         {
+         case dw_val_class_vec:
+           size += loc->dw_loc_oprnd2.v.val_vec.length
+                   * loc->dw_loc_oprnd2.v.val_vec.elt_size;
+           break;
+         case dw_val_class_const:
+           size += HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
+           break;
+         case dw_val_class_const_double:
+           size += 2 * HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT;
+           break;
+         default:
+           gcc_unreachable ();
+         }
+       break;
+      }
+    case DW_OP_GNU_regval_type:
+      {
+       unsigned long o
+         = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
+       size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
+               + size_of_uleb128 (o);
+      }
+      break;
+    case DW_OP_GNU_deref_type:
+      {
+       unsigned long o
+         = get_base_type_offset (loc->dw_loc_oprnd2.v.val_die_ref.die);
+       size += 1 + size_of_uleb128 (o);
+      }
+      break;
+    case DW_OP_GNU_convert:
+    case DW_OP_GNU_reinterpret:
+      {
+       unsigned long o
+         = get_base_type_offset (loc->dw_loc_oprnd1.v.val_die_ref.die);
+       size += size_of_uleb128 (o);
+      }
     default:
       break;
     }
@@ -5288,6 +5373,96 @@ output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
       output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
       break;
 
+    case DW_OP_GNU_const_type:
+      {
+       unsigned long o = get_base_type_offset (val1->v.val_die_ref.die), l;
+       gcc_assert (o);
+       dw2_asm_output_data_uleb128 (o, NULL);
+       switch (val2->val_class)
+         {
+         case dw_val_class_const:
+           l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
+           dw2_asm_output_data (1, l, NULL);
+           dw2_asm_output_data (l, val2->v.val_int, NULL);
+           break;
+         case dw_val_class_vec:
+           {
+             unsigned int elt_size = val2->v.val_vec.elt_size;
+             unsigned int len = val2->v.val_vec.length;
+             unsigned int i;
+             unsigned char *p;
+
+             l = len * elt_size;
+             dw2_asm_output_data (1, l, NULL);
+             if (elt_size > sizeof (HOST_WIDE_INT))
+               {
+                 elt_size /= 2;
+                 len *= 2;
+               }
+             for (i = 0, p = val2->v.val_vec.array;
+                  i < len;
+                  i++, p += elt_size)
+               dw2_asm_output_data (elt_size, extract_int (p, elt_size),
+                                    "fp or vector constant word %u", i);
+           }
+           break;
+         case dw_val_class_const_double:
+           {
+             unsigned HOST_WIDE_INT first, second;
+             l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
+
+             dw2_asm_output_data (1, 2 * l, NULL);
+             if (WORDS_BIG_ENDIAN)
+               {
+                 first = val2->v.val_double.high;
+                 second = val2->v.val_double.low;
+               }
+             else
+               {
+                 first = val2->v.val_double.low;
+                 second = val2->v.val_double.high;
+               }
+             dw2_asm_output_data (l, first, NULL);
+             dw2_asm_output_data (l, second, NULL);
+           }
+           break;
+         default:
+           gcc_unreachable ();
+         }
+      }
+      break;
+    case DW_OP_GNU_regval_type:
+      {
+       unsigned r = val1->v.val_unsigned;
+       unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
+       gcc_assert (o);
+       if (for_eh_or_skip >= 0)
+         {
+           r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
+           gcc_assert (size_of_uleb128 (r)
+                       == size_of_uleb128 (val1->v.val_unsigned));
+         }
+       dw2_asm_output_data_uleb128 (r, NULL);
+       dw2_asm_output_data_uleb128 (o, NULL);
+      }
+      break;
+    case DW_OP_GNU_deref_type:
+      {
+       unsigned long o = get_base_type_offset (val2->v.val_die_ref.die);
+       gcc_assert (o);
+       dw2_asm_output_data (1, val1->v.val_int, NULL);
+       dw2_asm_output_data_uleb128 (o, NULL);
+      }
+      break;
+    case DW_OP_GNU_convert:
+    case DW_OP_GNU_reinterpret:
+      {
+       unsigned long o = get_base_type_offset (val1->v.val_die_ref.die);
+       gcc_assert (o);
+       dw2_asm_output_data_uleb128 (o, NULL);
+      }
+      break;
+
     default:
       /* Other codes have no operands.  */
       break;
@@ -5465,6 +5640,11 @@ output_loc_operands_raw (dw_loc_descr_ref loc)
 
     case DW_OP_GNU_implicit_pointer:
     case DW_OP_GNU_entry_value:
+    case DW_OP_GNU_const_type:
+    case DW_OP_GNU_regval_type:
+    case DW_OP_GNU_deref_type:
+    case DW_OP_GNU_convert:
+    case DW_OP_GNU_reinterpret:
       gcc_unreachable ();
       break;
 
@@ -5819,31 +5999,70 @@ typedef long int dw_offset;
 
 typedef struct dw_attr_struct *dw_attr_ref;
 typedef struct dw_line_info_struct *dw_line_info_ref;
-typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
 typedef struct pubname_struct *pubname_ref;
 typedef struct dw_ranges_struct *dw_ranges_ref;
 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
 typedef struct comdat_type_struct *comdat_type_node_ref;
 
-/* Each entry in the line_info_table maintains the file and
-   line number associated with the label generated for that
-   entry.  The label gives the PC value associated with
-   the line number entry.  */
+/* The entries in the line_info table more-or-less mirror the opcodes
+   that are used in the real dwarf line table.  Arrays of these entries
+   are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
+   supported.  */
+
+enum dw_line_info_opcode {
+  /* Emit DW_LNE_set_address; the operand is the label index.  */
+  LI_set_address,
+
+  /* Emit a row to the matrix with the given line.  This may be done
+     via any combination of DW_LNS_copy, DW_LNS_advance_line, and
+     special opcodes.  */
+  LI_set_line,
+
+  /* Emit a DW_LNS_set_file.  */
+  LI_set_file,
+
+  /* Emit a DW_LNS_set_column.  */
+  LI_set_column,
+
+  /* Emit a DW_LNS_negate_stmt; the operand is ignored.  */
+  LI_negate_stmt,
+
+  /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored.  */
+  LI_set_prologue_end,
+  LI_set_epilogue_begin,
+
+  /* Emit a DW_LNE_set_discriminator.  */
+  LI_set_discriminator
+};
 
 typedef struct GTY(()) dw_line_info_struct {
-  unsigned long dw_file_num;
-  unsigned long dw_line_num;
-}
-dw_line_info_entry;
+  enum dw_line_info_opcode opcode;
+  unsigned int val;
+} dw_line_info_entry;
 
-/* Line information for functions in separate sections; each one gets its
-   own sequence.  */
-typedef struct GTY(()) dw_separate_line_info_struct {
-  unsigned long dw_file_num;
-  unsigned long dw_line_num;
-  unsigned long function;
-}
-dw_separate_line_info_entry;
+DEF_VEC_O(dw_line_info_entry);
+DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
+
+typedef struct GTY(()) dw_line_info_table_struct {
+  /* The label that marks the end of this section.  */
+  const char *end_label;
+
+  /* The values for the last row of the matrix, as collected in the table.
+     These are used to minimize the changes to the next row.  */
+  unsigned int file_num;
+  unsigned int line_num;
+  unsigned int column_num;
+  int discrim_num;
+  bool is_stmt;
+  bool in_use;
+
+  VEC(dw_line_info_entry, gc) *entries;
+} dw_line_info_table;
+
+typedef dw_line_info_table *dw_line_info_table_p;
+
+DEF_VEC_P(dw_line_info_table_p);
+DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
 
 /* Each DIE attribute has a field specifying the attribute kind,
    a link to the next attribute in the chain, and an attribute value.
@@ -6021,7 +6240,7 @@ skeleton_chain_node;
 #define DWARF_LINE_BASE  -10
 
 /* First special line opcode - leave room for the standard opcodes.  */
-#define DWARF_LINE_OPCODE_BASE  10
+#define DWARF_LINE_OPCODE_BASE  ((int)DW_LNS_set_isa + 1)
 
 /* Range of line offsets in a special line info. opcode.  */
 #define DWARF_LINE_RANGE  (254-DWARF_LINE_OPCODE_BASE+1)
@@ -6166,31 +6385,20 @@ static GTY(()) unsigned abbrev_die_table_in_use;
    abbrev_die_table.  */
 #define ABBREV_DIE_TABLE_INCREMENT 256
 
-/* A pointer to the base of a table that contains line information
-   for each source code line in .text in the compilation unit.  */
-static GTY((length ("line_info_table_allocated")))
-     dw_line_info_ref line_info_table;
-
-/* Number of elements currently allocated for line_info_table.  */
-static GTY(()) unsigned line_info_table_allocated;
-
-/* Number of elements in line_info_table currently in use.  */
-static GTY(()) unsigned line_info_table_in_use;
+/* A global counter for generating labels for line number data.  */
+static unsigned int line_info_label_num;
 
-/* A pointer to the base of a table that contains line information
-   for each source code line outside of .text in the compilation unit.  */
-static GTY ((length ("separate_line_info_table_allocated")))
-     dw_separate_line_info_ref separate_line_info_table;
+/* The current table to which we should emit line number information
+   for the current function.  This will be set up at the beginning of
+   assembly for the function.  */
+static dw_line_info_table *cur_line_info_table;
 
-/* Number of elements currently allocated for separate_line_info_table.  */
-static GTY(()) unsigned separate_line_info_table_allocated;
+/* The two default tables of line number info.  */
+static GTY(()) dw_line_info_table *text_section_line_info;
+static GTY(()) dw_line_info_table *cold_text_section_line_info;
 
-/* Number of elements in separate_line_info_table currently in use.  */
-static GTY(()) unsigned separate_line_info_table_in_use;
-
-/* Size (in elements) of increments by which we may expand the
-   line_info_table.  */
-#define LINE_INFO_TABLE_INCREMENT 1024
+/* The set of all non-default tables of line number info.  */
+static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
 
 /* A flag to tell pubnames/types export if there is an info section to
    refer to.  */
@@ -6264,6 +6472,8 @@ static GTY(()) VEC(tree,gc) *generic_type_instances;
    within the current function.  */
 static HOST_WIDE_INT frame_pointer_fb_offset;
 
+static VEC (dw_die_ref, heap) *base_types;
+
 /* Forward declarations for functions defined in this file.  */
 
 static int is_pseudo_reg (const_rtx);
@@ -6343,7 +6553,6 @@ static void equate_decl_number_to_die (tree, dw_die_ref);
 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
 static void print_spaces (FILE *);
 static void print_die (dw_die_ref, FILE *);
-static void print_dwarf_line_table (FILE *);
 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
 static dw_die_ref pop_compile_unit (dw_die_ref);
 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
@@ -6397,6 +6606,7 @@ static void output_location_lists (dw_die_ref);
 static int constant_size (unsigned HOST_WIDE_INT);
 static unsigned long size_of_die (dw_die_ref);
 static void calc_die_sizes (dw_die_ref);
+static void calc_base_type_die_sizes (void);
 static void mark_dies (dw_die_ref);
 static void unmark_dies (dw_die_ref);
 static void unmark_all_dies (dw_die_ref);
@@ -6421,6 +6631,7 @@ static unsigned int add_ranges (const_tree);
 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
                                  bool *);
 static void output_ranges (void);
+static dw_line_info_table *new_line_info_table (void);
 static void output_line_info (void);
 static void output_file_names (void);
 static dw_die_ref base_type_die (tree);
@@ -6466,6 +6677,7 @@ static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
 static bool tree_add_const_value_attribute (dw_die_ref, tree);
 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
 static void add_name_attribute (dw_die_ref, const char *);
+static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
 static void add_comp_dir_attribute (dw_die_ref);
 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
 static void add_subscript_info (dw_die_ref, tree, bool);
@@ -6518,7 +6730,7 @@ static void gen_typedef_die (tree, dw_die_ref);
 static void gen_type_die (tree, dw_die_ref);
 static void gen_block_die (tree, dw_die_ref, int);
 static void decls_for_scope (tree, dw_die_ref, int);
-static int is_redundant_typedef (const_tree);
+static inline int is_redundant_typedef (const_tree);
 static bool is_naming_typedef_decl (const_tree);
 static inline dw_die_ref get_context_die (tree);
 static void gen_namespace_die (tree, dw_die_ref);
@@ -6662,9 +6874,6 @@ static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
 #ifndef LINE_CODE_LABEL
 #define LINE_CODE_LABEL                "LM"
 #endif
-#ifndef SEPARATE_LINE_CODE_LABEL
-#define SEPARATE_LINE_CODE_LABEL       "LSM"
-#endif
 
 \f
 /* Return the root of the DIE's built for the current compilation unit.  */
@@ -6736,6 +6945,21 @@ get_ref_die_offset_label (char *label, dw_die_ref ref)
   sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
 }
 
+/* Return die_offset of a DIE reference to a base type.  */
+
+static unsigned long int
+get_base_type_offset (dw_die_ref ref)
+{
+  if (ref->die_offset)
+    return ref->die_offset;
+  if (comp_unit_die ()->die_abbrev)
+    {
+      calc_base_type_die_sizes ();
+      gcc_assert (ref->die_offset);
+    }
+  return ref->die_offset;
+}
+
 /* Convert a DIE tag into its string name.  */
 
 static const char *
@@ -7111,6 +7335,7 @@ dwarf_attr_name (unsigned int attr)
       return "DW_AT_body_begin";
     case DW_AT_body_end:
       return "DW_AT_body_end";
+
     case DW_AT_GNU_vector:
       return "DW_AT_GNU_vector";
     case DW_AT_GNU_guarded_by:
@@ -7148,6 +7373,9 @@ dwarf_attr_name (unsigned int attr)
     case DW_AT_GNU_all_source_call_sites:
       return "DW_AT_GNU_all_source_call_sites";
 
+    case DW_AT_GNAT_descriptive_type:
+      return "DW_AT_GNAT_descriptive_type";
+
     case DW_AT_VMS_rtnbeg_pd_address:
       return "DW_AT_VMS_rtnbeg_pd_address";
 
@@ -7448,52 +7676,22 @@ add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
   add_dwarf_attr (die, &attr);
 }
 
-/* Create a label for an indirect string node, ensuring it is going to
-   be output, unless its reference count goes down to zero.  */
-
-static inline void
-gen_label_for_indirect_string (struct indirect_string_node *node)
+static inline const char *
+AT_string (dw_attr_ref a)
 {
-  char label[32];
+  gcc_assert (a && AT_class (a) == dw_val_class_str);
+  return a->dw_attr_val.v.val_str->str;
+}
 
-  if (node->label)
-    return;
-
-  ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
-  ++dw2_string_counter;
-  node->label = xstrdup (label);
-}
-
-/* Create a SYMBOL_REF rtx whose value is the initial address of a
-   debug string STR.  */
-
-static inline rtx
-get_debug_string_label (const char *str)
-{
-  struct indirect_string_node *node = find_AT_string (str);
-
-  debug_str_hash_forced = true;
-
-  gen_label_for_indirect_string (node);
-
-  return gen_rtx_SYMBOL_REF (Pmode, node->label);
-}
-
-static inline const char *
-AT_string (dw_attr_ref a)
-{
-  gcc_assert (a && AT_class (a) == dw_val_class_str);
-  return a->dw_attr_val.v.val_str->str;
-}
-
-/* Find out whether a string should be output inline in DIE
-   or out-of-line in .debug_str section.  */
+/* Find out whether a string should be output inline in DIE
+   or out-of-line in .debug_str section.  */
 
 static enum dwarf_form
 AT_string_form (dw_attr_ref a)
 {
   struct indirect_string_node *node;
   unsigned int len;
+  char label[32];
 
   gcc_assert (a && AT_class (a) == dw_val_class_str);
 
@@ -7516,7 +7714,9 @@ AT_string_form (dw_attr_ref a)
       && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
     return node->form = DW_FORM_string;
 
-  gen_label_for_indirect_string (node);
+  ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
+  ++dw2_string_counter;
+  node->label = xstrdup (label);
 
   return node->form = DW_FORM_strp;
 }
@@ -8682,27 +8882,6 @@ print_die (dw_die_ref die, FILE *outfile)
     fprintf (outfile, "\n");
 }
 
-/* Print the contents of the source code line number correspondence table.
-   This routine is a debugging aid only.  */
-
-static void
-print_dwarf_line_table (FILE *outfile)
-{
-  unsigned i;
-  dw_line_info_ref line_info;
-
-  fprintf (outfile, "\n\nDWARF source line information\n");
-  for (i = 1; i < line_info_table_in_use; i++)
-    {
-      line_info = &line_info_table[i];
-      fprintf (outfile, "%5d: %4ld %6ld\n", i,
-              line_info->dw_file_num,
-              line_info->dw_line_num);
-    }
-
-  fprintf (outfile, "\n\n");
-}
-
 /* Print the information collected for a given DIE.  */
 
 DEBUG_FUNCTION void
@@ -8719,8 +8898,6 @@ debug_dwarf (void)
 {
   print_indent = 0;
   print_die (comp_unit_die (), stderr);
-  if (! DWARF2_ASM_LINE_DEBUG_INFO)
-    print_dwarf_line_table (stderr);
 }
 \f
 /* Start a new compilation unit DIE for an include file.  OLD_UNIT is the CU
@@ -9993,6 +10170,20 @@ is_nested_in_subprogram (dw_die_ref die)
   return local_scope_p (decl);
 }
 
+/* Return non-zero if this DIE contains a defining declaration of a
+   subprogram.  */
+
+static int
+contains_subprogram_definition (dw_die_ref die)
+{
+  dw_die_ref c;
+
+  if (die->die_tag == DW_TAG_subprogram && ! is_declaration_die (die))
+    return 1;
+  FOR_EACH_CHILD (die, c, if (contains_subprogram_definition(c)) return 1);
+  return 0;
+}
+
 /* Return non-zero if this is a type DIE that should be moved to a
    COMDAT .debug_types section.  */
 
@@ -10011,6 +10202,8 @@ should_move_die_to_comdat (dw_die_ref die)
           || get_AT (die, DW_AT_abstract_origin)
           || is_nested_in_subprogram (die))
         return 0;
+      /* A type definition should never contain a subprogram definition.  */
+      gcc_assert (!contains_subprogram_definition (die));
       return 1;
     case DW_TAG_array_type:
     case DW_TAG_interface_type:
@@ -10786,6 +10979,8 @@ calc_die_sizes (dw_die_ref die)
 {
   dw_die_ref c;
 
+  gcc_assert (die->die_offset == 0
+             || (unsigned long int) die->die_offset == next_die_offset);
   die->die_offset = next_die_offset;
   next_die_offset += size_of_die (die);
 
@@ -10796,6 +10991,36 @@ calc_die_sizes (dw_die_ref die)
     next_die_offset += 1;
 }
 
+/* Size just the base type children at the start of the CU.
+   This is needed because build_abbrev needs to size locs
+   and sizing of type based stack ops needs to know die_offset
+   values for the base types.  */
+
+static void
+calc_base_type_die_sizes (void)
+{
+  unsigned long die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
+  unsigned int i;
+  dw_die_ref base_type;
+#if ENABLE_ASSERT_CHECKING
+  dw_die_ref prev = comp_unit_die ()->die_child;
+#endif
+
+  die_offset += size_of_die (comp_unit_die ());
+  for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
+    {
+#if ENABLE_ASSERT_CHECKING
+      gcc_assert (base_type->die_offset == 0
+                 && prev->die_sib == base_type
+                 && base_type->die_child == NULL
+                 && base_type->die_abbrev);
+      prev = base_type;
+#endif
+      base_type->die_offset = die_offset;
+      die_offset += size_of_die (base_type);
+    }
+}
+
 /* Set the marks for a die and its children.  We do this so
    that we know whether or not a reference needs to use FORM_ref_addr; only
    DIEs in the same CU will be marked.  We used to clear out the offset
@@ -12289,6 +12514,117 @@ output_file_names (void)
 }
 
 
+/* Output one line number table into the .debug_line section.  */
+
+static void
+output_one_line_info_table (dw_line_info_table *table)
+{
+  char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
+  unsigned int current_line = 1;
+  bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
+  dw_line_info_entry *ent;
+  size_t i;
+
+  FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
+    {
+      switch (ent->opcode)
+       {
+       case LI_set_address:
+         /* ??? Unfortunately, we have little choice here currently, and
+            must always use the most general form.  GCC does not know the
+            address delta itself, so we can't use DW_LNS_advance_pc.  Many
+            ports do have length attributes which will give an upper bound
+            on the address range.  We could perhaps use length attributes
+            to determine when it is safe to use DW_LNS_fixed_advance_pc.  */
+         ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
+
+         /* This can handle any delta.  This takes
+            4+DWARF2_ADDR_SIZE bytes.  */
+         dw2_asm_output_data (1, 0, "set address %s", line_label);
+         dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
+         dw2_asm_output_data (1, DW_LNE_set_address, NULL);
+         dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
+         break;
+
+       case LI_set_line:
+         if (ent->val == current_line)
+           {
+             /* We still need to start a new row, so output a copy insn.  */
+             dw2_asm_output_data (1, DW_LNS_copy,
+                                  "copy line %u", current_line);
+           }
+         else
+           {
+             int line_offset = ent->val - current_line;
+             int line_delta = line_offset - DWARF_LINE_BASE;
+
+             current_line = ent->val;
+             if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
+               {
+                 /* This can handle deltas from -10 to 234, using the current
+                    definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
+                    This takes 1 byte.  */
+                 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
+                                      "line %u", current_line);
+               }
+             else
+               {
+                 /* This can handle any delta.  This takes at least 4 bytes,
+                    depending on the value being encoded.  */
+                 dw2_asm_output_data (1, DW_LNS_advance_line,
+                                      "advance to line %u", current_line);
+                 dw2_asm_output_data_sleb128 (line_offset, NULL);
+                 dw2_asm_output_data (1, DW_LNS_copy, NULL);
+               }
+           }
+         break;
+
+       case LI_set_file:
+         dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
+         dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
+         break;
+
+       case LI_set_column:
+         dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
+         dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
+         break;
+
+       case LI_negate_stmt:
+         current_is_stmt = !current_is_stmt;
+         dw2_asm_output_data (1, DW_LNS_negate_stmt,
+                              "is_stmt %d", current_is_stmt);
+         break;
+
+       case LI_set_prologue_end:
+         dw2_asm_output_data (1, DW_LNS_set_prologue_end,
+                              "set prologue end");
+         break;
+         
+       case LI_set_epilogue_begin:
+         dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
+                              "set epilogue begin");
+         break;
+
+       case LI_set_discriminator:
+         dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
+         dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
+         dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
+         dw2_asm_output_data_uleb128 (ent->val, NULL);
+         break;
+       }
+    }
+
+  /* Emit debug info for the address of the end of the table.  */
+  dw2_asm_output_data (1, 0, "set address %s", table->end_label);
+  dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
+  dw2_asm_output_data (1, DW_LNE_set_address, NULL);
+  dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
+
+  dw2_asm_output_data (1, 0, "end sequence");
+  dw2_asm_output_data_uleb128 (1, NULL);
+  dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
+}
+
 /* Output the source line number correspondence information.  This
    information goes into the .debug_line section.  */
 
@@ -12296,17 +12632,9 @@ static void
 output_line_info (void)
 {
   char l1[20], l2[20], p1[20], p2[20];
-  char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
-  char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
-  unsigned opc;
-  unsigned n_op_args;
-  unsigned long lt_index;
-  unsigned long current_line;
-  long line_offset;
-  long line_delta;
-  unsigned long current_file;
-  unsigned long function;
   int ver = dwarf_version;
+  bool saw_one = false;
+  int opc;
 
   ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
   ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
@@ -12324,16 +12652,15 @@ output_line_info (void)
   dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
   ASM_OUTPUT_LABEL (asm_out_file, p1);
 
-  /* Define the architecture-dependent minimum instruction length (in
-   bytes).  In this implementation of DWARF, this field is used for
-   information purposes only.  Since GCC generates assembly language,
-   we have no a priori knowledge of how many instruction bytes are
-   generated for each source line, and therefore can use only the
-   DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
-   commands.  Accordingly, we fix this as `1', which is "correct
-   enough" for all architectures, and don't let the target override.  */
-  dw2_asm_output_data (1, 1,
-                      "Minimum Instruction Length");
+  /* Define the architecture-dependent minimum instruction length (in bytes).
+     In this implementation of DWARF, this field is used for information
+     purposes only.  Since GCC generates assembly language, we have no
+     a priori knowledge of how many instruction bytes are generated for each
+     source line, and therefore can use only the DW_LNE_set_address and
+     DW_LNS_fixed_advance_pc line information commands.  Accordingly, we fix
+     this as '1', which is "correct enough" for all architectures,
+     and don't let the target override.  */
+  dw2_asm_output_data (1, 1, "Minimum Instruction Length");
 
   if (ver >= 4)
     dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
@@ -12349,6 +12676,7 @@ output_line_info (void)
 
   for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
     {
+      int n_op_args;
       switch (opc)
        {
        case DW_LNS_advance_pc:
@@ -12356,6 +12684,7 @@ output_line_info (void)
        case DW_LNS_set_file:
        case DW_LNS_set_column:
        case DW_LNS_fixed_advance_pc:
+       case DW_LNS_set_isa:
          n_op_args = 1;
          break;
        default:
@@ -12371,237 +12700,31 @@ output_line_info (void)
   output_file_names ();
   ASM_OUTPUT_LABEL (asm_out_file, p2);
 
-  /* We used to set the address register to the first location in the text
-     section here, but that didn't accomplish anything since we already
-     have a line note for the opening brace of the first function.  */
-
-  /* Generate the line number to PC correspondence table, encoded as
-     a series of state machine operations.  */
-  current_file = 1;
-  current_line = 1;
-
-  if (cfun && in_cold_section_p)
-    strcpy (prev_line_label, crtl->subsections.cold_section_label);
-  else
-    strcpy (prev_line_label, text_section_label);
-  for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
+  if (separate_line_info)
     {
-      dw_line_info_ref line_info = &line_info_table[lt_index];
-
-#if 0
-      /* Disable this optimization for now; GDB wants to see two line notes
-        at the beginning of a function so it can find the end of the
-        prologue.  */
-
-      /* Don't emit anything for redundant notes.  Just updating the
-        address doesn't accomplish anything, because we already assume
-        that anything after the last address is this line.  */
-      if (line_info->dw_line_num == current_line
-         && line_info->dw_file_num == current_file)
-       continue;
-#endif
-
-      /* Emit debug info for the address of the current line.
-
-        Unfortunately, we have little choice here currently, and must always
-        use the most general form.  GCC does not know the address delta
-        itself, so we can't use DW_LNS_advance_pc.  Many ports do have length
-        attributes which will give an upper bound on the address range.  We
-        could perhaps use length attributes to determine when it is safe to
-        use DW_LNS_fixed_advance_pc.  */
-
-      ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
-      if (0)
-       {
-         /* This can handle deltas up to 0xffff.  This takes 3 bytes.  */
-         dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
-                              "DW_LNS_fixed_advance_pc");
-         dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
-       }
-      else
-       {
-         /* This can handle any delta.  This takes
-            4+DWARF2_ADDR_SIZE bytes.  */
-         dw2_asm_output_data (1, 0, "DW_LNE_set_address");
-         dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
-         dw2_asm_output_data (1, DW_LNE_set_address, NULL);
-         dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
-       }
-
-      strcpy (prev_line_label, line_label);
-
-      /* Emit debug info for the source file of the current line, if
-        different from the previous line.  */
-      if (line_info->dw_file_num != current_file)
-       {
-         current_file = line_info->dw_file_num;
-         dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
-         dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
-       }
-
-      /* Emit debug info for the current line number, choosing the encoding
-        that uses the least amount of space.  */
-      if (line_info->dw_line_num != current_line)
-       {
-         line_offset = line_info->dw_line_num - current_line;
-         line_delta = line_offset - DWARF_LINE_BASE;
-         current_line = line_info->dw_line_num;
-         if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
-           /* This can handle deltas from -10 to 234, using the current
-              definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.  This
-              takes 1 byte.  */
-           dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
-                                "line %lu", current_line);
-         else
-           {
-             /* This can handle any delta.  This takes at least 4 bytes,
-                depending on the value being encoded.  */
-             dw2_asm_output_data (1, DW_LNS_advance_line,
-                                  "advance to line %lu", current_line);
-             dw2_asm_output_data_sleb128 (line_offset, NULL);
-             dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
-           }
-       }
-      else
-       /* We still need to start a new row, so output a copy insn.  */
-       dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
-    }
+      dw_line_info_table *table;
+      size_t i;
 
-  /* Emit debug info for the address of the end of the function.  */
-  if (0)
-    {
-      dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
-                          "DW_LNS_fixed_advance_pc");
-      dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
+      FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
+       if (table->in_use)
+         {
+           output_one_line_info_table (table);
+           saw_one = true;
+         }
     }
-  else
+  if (cold_text_section_line_info && cold_text_section_line_info->in_use)
     {
-      dw2_asm_output_data (1, 0, "DW_LNE_set_address");
-      dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
-      dw2_asm_output_data (1, DW_LNE_set_address, NULL);
-      dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
+      output_one_line_info_table (cold_text_section_line_info);
+      saw_one = true;
     }
 
-  dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
-  dw2_asm_output_data_uleb128 (1, NULL);
-  dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
-
-  function = 0;
-  current_file = 1;
-  current_line = 1;
-  for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
-    {
-      dw_separate_line_info_ref line_info
-       = &separate_line_info_table[lt_index];
-
-#if 0
-      /* Don't emit anything for redundant notes.  */
-      if (line_info->dw_line_num == current_line
-         && line_info->dw_file_num == current_file
-         && line_info->function == function)
-       goto cont;
-#endif
-
-      /* Emit debug info for the address of the current line.  If this is
-        a new function, or the first line of a function, then we need
-        to handle it differently.  */
-      ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
-                                  lt_index);
-      if (function != line_info->function)
-       {
-         function = line_info->function;
-
-         /* Set the address register to the first line in the function.  */
-         dw2_asm_output_data (1, 0, "DW_LNE_set_address");
-         dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
-         dw2_asm_output_data (1, DW_LNE_set_address, NULL);
-         dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
-       }
-      else
-       {
-         /* ??? See the DW_LNS_advance_pc comment above.  */
-         if (0)
-           {
-             dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
-                                  "DW_LNS_fixed_advance_pc");
-             dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
-           }
-         else
-           {
-             dw2_asm_output_data (1, 0, "DW_LNE_set_address");
-             dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
-             dw2_asm_output_data (1, DW_LNE_set_address, NULL);
-             dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
-           }
-       }
-
-      strcpy (prev_line_label, line_label);
-
-      /* Emit debug info for the source file of the current line, if
-        different from the previous line.  */
-      if (line_info->dw_file_num != current_file)
-       {
-         current_file = line_info->dw_file_num;
-         dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
-         dw2_asm_output_data_uleb128 (current_file, "%lu", current_file);
-       }
-
-      /* Emit debug info for the current line number, choosing the encoding
-        that uses the least amount of space.  */
-      if (line_info->dw_line_num != current_line)
-       {
-         line_offset = line_info->dw_line_num - current_line;
-         line_delta = line_offset - DWARF_LINE_BASE;
-         current_line = line_info->dw_line_num;
-         if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
-           dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
-                                "line %lu", current_line);
-         else
-           {
-             dw2_asm_output_data (1, DW_LNS_advance_line,
-                                  "advance to line %lu", current_line);
-             dw2_asm_output_data_sleb128 (line_offset, NULL);
-             dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
-           }
-       }
-      else
-       dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
-
-#if 0
-    cont:
-#endif
-
-      lt_index++;
-
-      /* If we're done with a function, end its sequence.  */
-      if (lt_index == separate_line_info_table_in_use
-         || separate_line_info_table[lt_index].function != function)
-       {
-         current_file = 1;
-         current_line = 1;
-
-         /* Emit debug info for the address of the end of the function.  */
-         ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
-         if (0)
-           {
-             dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
-                                  "DW_LNS_fixed_advance_pc");
-             dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
-           }
-         else
-           {
-             dw2_asm_output_data (1, 0, "DW_LNE_set_address");
-             dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
-             dw2_asm_output_data (1, DW_LNE_set_address, NULL);
-             dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
-           }
-
-         /* Output the marker for the end of this sequence.  */
-         dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
-         dw2_asm_output_data_uleb128 (1, NULL);
-         dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
-       }
-    }
+  /* ??? Some Darwin linkers crash on a .debug_line section with no
+     sequences.  Further, merely a DW_LNE_end_sequence entry is not
+     sufficient -- the address column must also be initialized.
+     Make sure to output at least one set_address/end_sequence pair,
+     choosing .text since that section is always present.  */
+  if (text_section_line_info->in_use || !saw_one)
+    output_one_line_info_table (text_section_line_info);
 
   /* Output the marker for the end of the line number info.  */
   ASM_OUTPUT_LABEL (asm_out_file, l2);
@@ -12908,7 +13031,7 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type,
     }
   else if (code == REFERENCE_TYPE)
     {
-      if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
+      if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
        mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
                                type);
       else
@@ -12966,6 +13089,7 @@ modified_type_die (tree type, int is_const_type, int is_volatile_type,
           useful source coordinates anyway.  */
        name = DECL_NAME (name);
       add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
+      add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
     }
   /* This probably indicates a bug.  */
   else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
@@ -13244,7 +13368,8 @@ reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
 
       if (dwarf_version >= 4 || !dwarf_strict)
        {
-         result = mem_loc_descriptor (rtl, VOIDmode, initialized);
+         result = mem_loc_descriptor (rtl, GET_MODE (rtl), VOIDmode,
+                                      initialized);
          if (result)
            add_loc_descr (&result,
                           new_loc_descr (DW_OP_stack_value, 0, 0));
@@ -13484,7 +13609,7 @@ based_loc_descr (rtx reg, HOST_WIDE_INT offset,
              int base_reg
                = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
                                      ? HARD_FRAME_POINTER_REGNUM
-                                     : STACK_POINTER_REGNUM);
+                                     : REGNO (elim));
              return new_reg_loc_descr (base_reg, offset);
            }
 
@@ -13672,6 +13797,33 @@ const_ok_for_output (rtx rtl)
   return true;
 }
 
+/* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
+   if possible, NULL otherwise.  */
+
+static dw_die_ref
+base_type_for_mode (enum machine_mode mode, bool unsignedp)
+{
+  dw_die_ref type_die;
+  tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
+
+  if (type == NULL)
+    return NULL;
+  switch (TREE_CODE (type))
+    {
+    case INTEGER_TYPE:
+    case REAL_TYPE:
+      break;
+    default:
+      return NULL;
+    }
+  type_die = lookup_type_die (type);
+  if (!type_die)
+    type_die = modified_type_die (type, false, false, comp_unit_die ());
+  if (type_die == NULL || type_die->die_tag != DW_TAG_base_type)
+    return NULL;
+  return type_die;
+}
+
 /* The following routine converts the RTL for a variable or parameter
    (resident in memory) into an equivalent Dwarf representation of a
    mechanism for getting the address of that same variable onto the top of a
@@ -13682,22 +13834,25 @@ const_ok_for_output (rtx rtl)
    equivalent.  This routine recursively descends an RTL tree, turning
    it into Dwarf postfix code as it goes.
 
-   MODE is the mode of the memory reference, needed to handle some
-   autoincrement addressing modes.
+   MODE is the mode that should be assumed for the rtl if it is VOIDmode.
 
-   CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
-   location list for RTL.
+   MEM_MODE is the mode of the memory reference, needed to handle some
+   autoincrement addressing modes.
 
    Return 0 if we can't represent the location.  */
 
 static dw_loc_descr_ref
 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
+                   enum machine_mode mem_mode,
                    enum var_init_status initialized)
 {
   dw_loc_descr_ref mem_loc_result = NULL;
   enum dwarf_location_atom op;
   dw_loc_descr_ref op0, op1;
 
+  if (mode == VOIDmode)
+    mode = GET_MODE (rtl);
+
   /* Note that for a dynamically sized array, the location we will generate a
      description of here will be the lowest numbered location which is
      actually within the array.  That's *not* necessarily the same as the
@@ -13705,12 +13860,15 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
 
   rtl = targetm.delegitimize_address (rtl);
 
+  if (mode != GET_MODE (rtl) && GET_MODE (rtl) != VOIDmode)
+    return NULL;
+
   switch (GET_CODE (rtl))
     {
     case POST_INC:
     case POST_DEC:
     case POST_MODIFY:
-      return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
+      return mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, initialized);
 
     case SUBREG:
       /* The case of a subreg may arise when we have a local (register)
@@ -13720,15 +13878,80 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
         contains the given subreg.  */
       if (!subreg_lowpart_p (rtl))
        break;
-      rtl = SUBREG_REG (rtl);
-      if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
+      if (GET_MODE_CLASS (mode) == MODE_INT
+         && GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) == MODE_INT
+         && (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
+#ifdef POINTERS_EXTEND_UNSIGNED
+             || (mode == Pmode && mem_mode != VOIDmode)
+#endif
+            )
+         && GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))) <= DWARF2_ADDR_SIZE)
+       {
+         mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
+                                              GET_MODE (SUBREG_REG (rtl)),
+                                              mem_mode, initialized);
+         break;
+       }
+      if (dwarf_strict)
+       break;
+      if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
        break;
-      if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
+      if (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl)))
+         && (GET_MODE_CLASS (mode) != MODE_INT
+             || GET_MODE_CLASS (GET_MODE (SUBREG_REG (rtl))) != MODE_INT))
        break;
-      mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
+      else
+       {
+         dw_die_ref type_die;
+         dw_loc_descr_ref cvt;
+
+         mem_loc_result = mem_loc_descriptor (SUBREG_REG (rtl),
+                                              GET_MODE (SUBREG_REG (rtl)),
+                                              mem_mode, initialized);
+         if (mem_loc_result == NULL)
+           break;
+         type_die = base_type_for_mode (mode, 0);
+         if (type_die == NULL)
+           {
+             mem_loc_result = NULL;
+             break;
+           }
+         if (GET_MODE_SIZE (mode)
+             != GET_MODE_SIZE (GET_MODE (SUBREG_REG (rtl))))
+           cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+         else
+           cvt = new_loc_descr (DW_OP_GNU_reinterpret, 0, 0);
+         cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+         cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+         cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+         add_loc_descr (&mem_loc_result, cvt);
+       }
       break;
 
     case REG:
+      if (GET_MODE_CLASS (mode) != MODE_INT
+         || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
+#ifdef POINTERS_EXTEND_UNSIGNED
+             && (mode != Pmode || mem_mode == VOIDmode)
+#endif
+             ))
+       {
+         dw_die_ref type_die;
+
+         if (dwarf_strict)
+           break;
+         if (REGNO (rtl) > FIRST_PSEUDO_REGISTER)
+           break;
+         type_die = base_type_for_mode (mode, 0);
+         if (type_die == NULL)
+           break;
+         mem_loc_result = new_loc_descr (DW_OP_GNU_regval_type,
+                                         dbx_reg_number (rtl), 0);
+         mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
+         mem_loc_result->dw_loc_oprnd2.v.val_die_ref.die = type_die;
+         mem_loc_result->dw_loc_oprnd2.v.val_die_ref.external = 0;
+         break;
+       }
       /* Whenever a register number forms a part of the description of the
         method for calculating the (dynamic) address of a memory resident
         object, DWARF rules require the register number be referred to as
@@ -13758,11 +13981,12 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
 
     case SIGN_EXTEND:
     case ZERO_EXTEND:
-      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
-                               VAR_INIT_STATUS_INITIALIZED);
+      gcc_assert (GET_MODE_CLASS (mode) == MODE_INT);
+      op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
+                               mem_mode, VAR_INIT_STATUS_INITIALIZED);
       if (op0 == 0)
        break;
-      else
+      else if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
        {
          int shift = DWARF2_ADDR_SIZE
                      - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
@@ -13777,39 +14001,75 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
          add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
          add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
        }
+      else if (!dwarf_strict)
+       {
+         dw_die_ref type_die1, type_die2;
+         dw_loc_descr_ref cvt;
+
+         type_die1 = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
+                                         GET_CODE (rtl) == ZERO_EXTEND);
+         if (type_die1 == NULL)
+           break;
+         type_die2 = base_type_for_mode (mode, 0);
+         if (type_die2 == NULL)
+           break;
+         mem_loc_result = op0;
+         cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+         cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+         cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die1;
+         cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+         add_loc_descr (&mem_loc_result, cvt);
+         cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+         cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+         cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die2;
+         cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+         add_loc_descr (&mem_loc_result, cvt);
+       }
       break;
 
     case MEM:
-      mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
+      mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0),
+                                          get_address_mode (rtl), mode,
                                           VAR_INIT_STATUS_INITIALIZED);
       if (mem_loc_result == NULL)
        mem_loc_result = tls_mem_loc_descriptor (rtl);
       if (mem_loc_result != 0)
        {
-         if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
+         if (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
+             || GET_MODE_CLASS (mode) != MODE_INT)
            {
-             expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
-             return 0;
+             dw_die_ref type_die;
+             dw_loc_descr_ref deref;
+
+             if (dwarf_strict)
+               return NULL;
+             type_die = base_type_for_mode (mode, 0);
+             if (type_die == NULL)
+               return NULL;
+             deref = new_loc_descr (DW_OP_GNU_deref_type,
+                                    GET_MODE_SIZE (mode), 0);
+             deref->dw_loc_oprnd2.val_class = dw_val_class_die_ref;
+             deref->dw_loc_oprnd2.v.val_die_ref.die = type_die;
+             deref->dw_loc_oprnd2.v.val_die_ref.external = 0;
+             add_loc_descr (&mem_loc_result, deref);
            }
-         else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
+         else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
            add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
          else
            add_loc_descr (&mem_loc_result,
                           new_loc_descr (DW_OP_deref_size,
-                                         GET_MODE_SIZE (GET_MODE (rtl)), 0));
+                                         GET_MODE_SIZE (mode), 0));
        }
       else
        {
          rtx new_rtl = avoid_constant_pool_reference (rtl);
          if (new_rtl != rtl)
-           return mem_loc_descriptor (new_rtl, mode, initialized);
+           return mem_loc_descriptor (new_rtl, mode, mem_mode, initialized);
        }
       break;
 
     case LO_SUM:
-        rtl = XEXP (rtl, 1);
-
-      /* ... fall through ...  */
+      return mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, initialized);
 
     case LABEL_REF:
       /* Some ports can transform a symbol ref into a label ref, because
@@ -13817,6 +14077,13 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
         pool.  */
     case CONST:
     case SYMBOL_REF:
+      if (GET_MODE_CLASS (mode) != MODE_INT
+         || (GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE
+#ifdef POINTERS_EXTEND_UNSIGNED
+             && (mode != Pmode || mem_mode == VOIDmode)
+#endif
+             ))
+       break;
       if (GET_CODE (rtl) == SYMBOL_REF
          && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
        {
@@ -13862,23 +14129,32 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
     case ENTRY_VALUE:
       if (dwarf_strict)
        return NULL;
-      mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
-      mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
       if (REG_P (ENTRY_VALUE_EXP (rtl)))
-       mem_loc_result->dw_loc_oprnd1.v.val_loc
-         = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
-                                   VAR_INIT_STATUS_INITIALIZED);
-      else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
        {
-         dw_loc_descr_ref ref
-           = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
-                                 VAR_INIT_STATUS_INITIALIZED);
-         if (ref == NULL || ref->dw_loc_opc == DW_OP_fbreg)
+         if (GET_MODE_CLASS (mode) != MODE_INT
+             || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
+           op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
+                                     VOIDmode, VAR_INIT_STATUS_INITIALIZED);
+         else
+           op0
+             = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
+                                       VAR_INIT_STATUS_INITIALIZED);
+       }
+      else if (MEM_P (ENTRY_VALUE_EXP (rtl))
+              && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
+       {
+         op0 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), mode,
+                                   VOIDmode, VAR_INIT_STATUS_INITIALIZED);
+         if (op0 && op0->dw_loc_opc == DW_OP_fbreg)
            return NULL;
-         mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
        }
       else
        gcc_unreachable ();
+      if (op0 == NULL)
+       return NULL;
+      mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
+      mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
+      mem_loc_result->dw_loc_oprnd1.v.val_loc = op0;
       return mem_loc_result;
 
     case PRE_MODIFY:
@@ -13891,32 +14167,35 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
     case PRE_DEC:
       /* Turn these into a PLUS expression and fall into the PLUS code
         below.  */
-      rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
+      rtl = gen_rtx_PLUS (mode, XEXP (rtl, 0),
                          GEN_INT (GET_CODE (rtl) == PRE_INC
-                                  ? GET_MODE_UNIT_SIZE (mode)
-                                  : -GET_MODE_UNIT_SIZE (mode)));
+                                  ? GET_MODE_UNIT_SIZE (mem_mode)
+                                  : -GET_MODE_UNIT_SIZE (mem_mode)));
 
       /* ... fall through ...  */
 
     case PLUS:
     plus:
-      if (is_based_loc (rtl))
+      if (is_based_loc (rtl)
+         && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
+         && GET_MODE_CLASS (mode) == MODE_INT)
        mem_loc_result = based_loc_descr (XEXP (rtl, 0),
                                          INTVAL (XEXP (rtl, 1)),
                                          VAR_INIT_STATUS_INITIALIZED);
       else
        {
-         mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
+         mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
                                               VAR_INIT_STATUS_INITIALIZED);
          if (mem_loc_result == 0)
            break;
 
-         if (CONST_INT_P (XEXP (rtl, 1)))
+         if (CONST_INT_P (XEXP (rtl, 1))
+             && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE)
            loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
          else
            {
              dw_loc_descr_ref mem_loc_result2
-               = mem_loc_descriptor (XEXP (rtl, 1), mode,
+               = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
                                      VAR_INIT_STATUS_INITIALIZED);
              if (mem_loc_result2 == 0)
                break;
@@ -13947,15 +14226,31 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
 
     case ASHIFT:
       op = DW_OP_shl;
-      goto do_binop;
+      goto do_shift;
 
     case ASHIFTRT:
       op = DW_OP_shra;
-      goto do_binop;
+      goto do_shift;
 
     case LSHIFTRT:
       op = DW_OP_shr;
-      goto do_binop;
+      goto do_shift;
+
+    do_shift:
+      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
+                               VAR_INIT_STATUS_INITIALIZED);
+      op1 = mem_loc_descriptor (XEXP (rtl, 1),
+                               GET_MODE (XEXP (rtl, 1)) == VOIDmode
+                               ? mode : GET_MODE (XEXP (rtl, 1)), mem_mode,
+                               VAR_INIT_STATUS_INITIALIZED);
+
+      if (op0 == 0 || op1 == 0)
+       break;
+
+      mem_loc_result = op0;
+      add_loc_descr (&mem_loc_result, op1);
+      add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
+      break;
 
     case AND:
       op = DW_OP_and;
@@ -13970,9 +14265,9 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       goto do_binop;
 
     do_binop:
-      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
+      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
-      op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
+      op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
 
       if (op0 == 0 || op1 == 0)
@@ -13984,9 +14279,9 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       break;
 
     case MOD:
-      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
+      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
-      op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
+      op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
 
       if (op0 == 0 || op1 == 0)
@@ -14014,7 +14309,7 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       goto do_unop;
 
     do_unop:
-      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
+      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
 
       if (op0 == 0)
@@ -14025,7 +14320,81 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       break;
 
     case CONST_INT:
-      mem_loc_result = int_loc_descriptor (INTVAL (rtl));
+      if (GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
+#ifdef POINTERS_EXTEND_UNSIGNED
+         || (mode == Pmode
+             && mem_mode != VOIDmode
+             && trunc_int_for_mode (INTVAL (rtl), ptr_mode) == INTVAL (rtl))
+#endif
+         )
+       {
+         mem_loc_result = int_loc_descriptor (INTVAL (rtl));
+         break;
+       }
+      if (!dwarf_strict
+         && (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT
+             || GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT))
+       {
+         dw_die_ref type_die = base_type_for_mode (mode, 0);
+         if (type_die == NULL)
+           return NULL;
+         mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0,
+                                         INTVAL (rtl));
+         mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+         mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+         mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
+         if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
+           mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
+         else
+           {
+             mem_loc_result->dw_loc_oprnd2.val_class
+               = dw_val_class_const_double;
+             mem_loc_result->dw_loc_oprnd2.v.val_double
+               = shwi_to_double_int (INTVAL (rtl));
+           }
+       }
+      break;
+
+    case CONST_DOUBLE:
+      if (!dwarf_strict)
+       {
+         dw_die_ref type_die;
+
+         /* Note that a CONST_DOUBLE rtx could represent either an integer
+            or a floating-point constant.  A CONST_DOUBLE is used whenever
+            the constant requires more than one word in order to be
+            adequately represented.  We output CONST_DOUBLEs as blocks.  */
+         if (mode == VOIDmode
+             || (GET_MODE (rtl) == VOIDmode
+                 && GET_MODE_BITSIZE (mode) != 2 * HOST_BITS_PER_WIDE_INT))
+           break;
+         type_die = base_type_for_mode (mode, 0);
+         if (type_die == NULL)
+           return NULL;
+         mem_loc_result = new_loc_descr (DW_OP_GNU_const_type, 0, 0);
+         mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+         mem_loc_result->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+         mem_loc_result->dw_loc_oprnd1.v.val_die_ref.external = 0;
+         if (SCALAR_FLOAT_MODE_P (mode))
+           {
+             unsigned int length = GET_MODE_SIZE (mode);
+             unsigned char *array
+                 = (unsigned char*) ggc_alloc_atomic (length);
+
+             insert_float (rtl, array);
+             mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
+             mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
+             mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
+             mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
+           }
+         else
+           {
+             mem_loc_result->dw_loc_oprnd2.val_class
+               = dw_val_class_const_double;
+             mem_loc_result->dw_loc_oprnd2.v.val_double
+               = rtx_to_double_int (rtl);
+           }
+       }
       break;
 
     case EQ:
@@ -14053,74 +14422,75 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       goto do_scompare;
 
     do_scompare:
-      if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
-         || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
-       break;
-      else
-       {
-         enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
+      {
+       enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
 
-         if (op_mode == VOIDmode)
-           op_mode = GET_MODE (XEXP (rtl, 1));
-         if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
-           break;
+       if (op_mode == VOIDmode)
+         op_mode = GET_MODE (XEXP (rtl, 1));
+       if (op_mode == VOIDmode)
+         break;
 
-         op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
-                                   VAR_INIT_STATUS_INITIALIZED);
-         op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
-                                   VAR_INIT_STATUS_INITIALIZED);
+       if (dwarf_strict
+           && (GET_MODE_CLASS (op_mode) != MODE_INT
+               || GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE))
+         break;
 
-         if (op0 == 0 || op1 == 0)
-           break;
+       op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
+                                 VAR_INIT_STATUS_INITIALIZED);
+       op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
+                                 VAR_INIT_STATUS_INITIALIZED);
 
-         if (op_mode != VOIDmode
-             && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
-           {
-             int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
-             shift *= BITS_PER_UNIT;
-             /* For eq/ne, if the operands are known to be zero-extended,
-                there is no need to do the fancy shifting up.  */
-             if (op == DW_OP_eq || op == DW_OP_ne)
-               {
-                 dw_loc_descr_ref last0, last1;
-                 for (last0 = op0;
-                      last0->dw_loc_next != NULL;
-                      last0 = last0->dw_loc_next)
-                   ;
-                 for (last1 = op1;
-                      last1->dw_loc_next != NULL;
-                      last1 = last1->dw_loc_next)
-                   ;
-                 /* deref_size zero extends, and for constants we can check
-                    whether they are zero extended or not.  */
-                 if (((last0->dw_loc_opc == DW_OP_deref_size
-                       && last0->dw_loc_oprnd1.v.val_int
-                          <= GET_MODE_SIZE (op_mode))
-                      || (CONST_INT_P (XEXP (rtl, 0))
-                           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
-                              == (INTVAL (XEXP (rtl, 0))
-                                  & GET_MODE_MASK (op_mode))))
-                     && ((last1->dw_loc_opc == DW_OP_deref_size
-                          && last1->dw_loc_oprnd1.v.val_int
-                             <= GET_MODE_SIZE (op_mode))
-                         || (CONST_INT_P (XEXP (rtl, 1))
-                             && (unsigned HOST_WIDE_INT)
-                                INTVAL (XEXP (rtl, 1))
-                                == (INTVAL (XEXP (rtl, 1))
-                                    & GET_MODE_MASK (op_mode)))))
-                   goto do_compare;
-               }
-             add_loc_descr (&op0, int_loc_descriptor (shift));
-             add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
-             if (CONST_INT_P (XEXP (rtl, 1)))
-               op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
-             else
-               {
-                 add_loc_descr (&op1, int_loc_descriptor (shift));
-                 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
-               }
-           }
-       }
+       if (op0 == 0 || op1 == 0)
+         break;
+
+       if (GET_MODE_CLASS (op_mode) == MODE_INT
+           && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
+         {
+           int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
+           shift *= BITS_PER_UNIT;
+           /* For eq/ne, if the operands are known to be zero-extended,
+              there is no need to do the fancy shifting up.  */
+           if (op == DW_OP_eq || op == DW_OP_ne)
+             {
+               dw_loc_descr_ref last0, last1;
+               for (last0 = op0;
+                    last0->dw_loc_next != NULL;
+                    last0 = last0->dw_loc_next)
+                 ;
+               for (last1 = op1;
+                    last1->dw_loc_next != NULL;
+                    last1 = last1->dw_loc_next)
+                 ;
+               /* deref_size zero extends, and for constants we can check
+                  whether they are zero extended or not.  */
+               if (((last0->dw_loc_opc == DW_OP_deref_size
+                     && last0->dw_loc_oprnd1.v.val_int
+                        <= GET_MODE_SIZE (op_mode))
+                    || (CONST_INT_P (XEXP (rtl, 0))
+                        && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
+                            == (INTVAL (XEXP (rtl, 0))
+                                & GET_MODE_MASK (op_mode))))
+                   && ((last1->dw_loc_opc == DW_OP_deref_size
+                        && last1->dw_loc_oprnd1.v.val_int
+                           <= GET_MODE_SIZE (op_mode))
+                       || (CONST_INT_P (XEXP (rtl, 1))
+                           && (unsigned HOST_WIDE_INT)
+                              INTVAL (XEXP (rtl, 1))
+                              == (INTVAL (XEXP (rtl, 1))
+                                  & GET_MODE_MASK (op_mode)))))
+                 goto do_compare;
+             }
+           add_loc_descr (&op0, int_loc_descriptor (shift));
+           add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
+           if (CONST_INT_P (XEXP (rtl, 1)))
+             op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
+           else
+             {
+               add_loc_descr (&op1, int_loc_descriptor (shift));
+               add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
+             }
+         }
+      }
 
     do_compare:
       mem_loc_result = op0;
@@ -14151,87 +14521,111 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       goto do_ucompare;
 
     do_ucompare:
-      if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
-         || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
-       break;
-      else
-       {
-         enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
+      {
+       enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
 
-         if (op_mode == VOIDmode)
-           op_mode = GET_MODE (XEXP (rtl, 1));
-         if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
-           break;
+       if (op_mode == VOIDmode)
+         op_mode = GET_MODE (XEXP (rtl, 1));
+       if (op_mode == VOIDmode)
+         break;
+       if (GET_MODE_CLASS (op_mode) != MODE_INT)
+         break;
 
-         op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
-                                   VAR_INIT_STATUS_INITIALIZED);
-         op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
-                                   VAR_INIT_STATUS_INITIALIZED);
+       if (dwarf_strict && GET_MODE_SIZE (op_mode) > DWARF2_ADDR_SIZE)
+         break;
 
-         if (op0 == 0 || op1 == 0)
+       if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
            break;
 
-         if (op_mode != VOIDmode
-             && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
-           {
-             HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
-             dw_loc_descr_ref last0, last1;
-             for (last0 = op0;
-                  last0->dw_loc_next != NULL;
-                  last0 = last0->dw_loc_next)
-               ;
-             for (last1 = op1;
-                  last1->dw_loc_next != NULL;
-                  last1 = last1->dw_loc_next)
-               ;
-             if (CONST_INT_P (XEXP (rtl, 0)))
-               op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
-             /* deref_size zero extends, so no need to mask it again.  */
-             else if (last0->dw_loc_opc != DW_OP_deref_size
-                      || last0->dw_loc_oprnd1.v.val_int
-                         > GET_MODE_SIZE (op_mode))
-               {
-                 add_loc_descr (&op0, int_loc_descriptor (mask));
-                 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
-               }
-             if (CONST_INT_P (XEXP (rtl, 1)))
-               op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
-             /* deref_size zero extends, so no need to mask it again.  */
-             else if (last1->dw_loc_opc != DW_OP_deref_size
-                      || last1->dw_loc_oprnd1.v.val_int
-                         > GET_MODE_SIZE (op_mode))
-               {
-                 add_loc_descr (&op1, int_loc_descriptor (mask));
-                 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
-               }
-           }
-         else
-           {
-             HOST_WIDE_INT bias = 1;
-             bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
-             add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
-             if (CONST_INT_P (XEXP (rtl, 1)))
-               op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
-                                         + INTVAL (XEXP (rtl, 1)));
-             else
-               add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
-                                                   bias, 0));
-           }
-       }
+       op0 = mem_loc_descriptor (XEXP (rtl, 0), op_mode, mem_mode,
+                                 VAR_INIT_STATUS_INITIALIZED);
+       op1 = mem_loc_descriptor (XEXP (rtl, 1), op_mode, mem_mode,
+                                 VAR_INIT_STATUS_INITIALIZED);
+
+       if (op0 == 0 || op1 == 0)
+         break;
+
+       if (GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
+         {
+           HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
+           dw_loc_descr_ref last0, last1;
+           for (last0 = op0;
+                last0->dw_loc_next != NULL;
+                last0 = last0->dw_loc_next)
+             ;
+           for (last1 = op1;
+                last1->dw_loc_next != NULL;
+                last1 = last1->dw_loc_next)
+             ;
+           if (CONST_INT_P (XEXP (rtl, 0)))
+             op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
+           /* deref_size zero extends, so no need to mask it again.  */
+           else if (last0->dw_loc_opc != DW_OP_deref_size
+                    || last0->dw_loc_oprnd1.v.val_int
+                       > GET_MODE_SIZE (op_mode))
+             {
+               add_loc_descr (&op0, int_loc_descriptor (mask));
+               add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
+             }
+           if (CONST_INT_P (XEXP (rtl, 1)))
+             op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
+           /* deref_size zero extends, so no need to mask it again.  */
+           else if (last1->dw_loc_opc != DW_OP_deref_size
+                    || last1->dw_loc_oprnd1.v.val_int
+                       > GET_MODE_SIZE (op_mode))
+             {
+               add_loc_descr (&op1, int_loc_descriptor (mask));
+               add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
+             }
+         }
+       else if (GET_MODE_SIZE (op_mode) == DWARF2_ADDR_SIZE)
+         {
+           HOST_WIDE_INT bias = 1;
+           bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
+           add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
+           if (CONST_INT_P (XEXP (rtl, 1)))
+             op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
+                                       + INTVAL (XEXP (rtl, 1)));
+           else
+             add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
+                                                 bias, 0));
+         }
+       else
+         {
+           dw_die_ref type_die = base_type_for_mode (mode, 1);
+           dw_loc_descr_ref cvt;
+
+           if (type_die == NULL)
+             break;
+           cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+           cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+           cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+           cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+           add_loc_descr (&op0, cvt);
+           cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+           cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+           cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+           cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+           add_loc_descr (&op1, cvt);
+         }
+      }
       goto do_compare;
 
-    case SMIN:
-    case SMAX:
     case UMIN:
     case UMAX:
-      if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
-         || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
-         || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
+      if (GET_MODE_CLASS (mode) != MODE_INT)
+       break;
+      /* FALLTHRU */
+    case SMIN:
+    case SMAX:
+      if (dwarf_strict
+         && (GET_MODE_CLASS (mode) != MODE_INT
+             || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE))
        break;
 
-      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
+      op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
-      op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
+      op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
                                VAR_INIT_STATUS_INITIALIZED);
 
       if (op0 == 0 || op1 == 0)
@@ -14242,26 +14636,44 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
       if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
        {
-         if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
+         if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
            {
-             HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
+             HOST_WIDE_INT mask = GET_MODE_MASK (mode);
              add_loc_descr (&op0, int_loc_descriptor (mask));
              add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
              add_loc_descr (&op1, int_loc_descriptor (mask));
              add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
            }
-         else
+         else if (GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE)
            {
              HOST_WIDE_INT bias = 1;
              bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
              add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
              add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
            }
+         else
+           {
+             dw_die_ref type_die = base_type_for_mode (mode, 1);
+             dw_loc_descr_ref cvt;
+
+             if (type_die == NULL)
+               break;
+             cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+             cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+             cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+             cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+             add_loc_descr (&op0, cvt);
+             cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+             cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+             cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+             cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+             add_loc_descr (&op1, cvt);
+           }
        }
-      else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
+      else if (GET_MODE_CLASS (mode) == MODE_INT
+              && GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
        {
-         int shift = DWARF2_ADDR_SIZE
-                     - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
+         int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (mode);
          shift *= BITS_PER_UNIT;
          add_loc_descr (&op0, int_loc_descriptor (shift));
          add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
@@ -14295,13 +14707,14 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
          && CONST_INT_P (XEXP (rtl, 2))
          && ((unsigned) INTVAL (XEXP (rtl, 1))
              + (unsigned) INTVAL (XEXP (rtl, 2))
-             <= GET_MODE_BITSIZE (GET_MODE (rtl)))
-         && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
+             <= GET_MODE_BITSIZE (mode))
+         && GET_MODE_CLASS (mode) == MODE_INT
+         && GET_MODE_SIZE (mode) <= DWARF2_ADDR_SIZE
          && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
        {
          int shift, size;
-         op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
-                                   VAR_INIT_STATUS_INITIALIZED);
+         op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
+                                   mem_mode, VAR_INIT_STATUS_INITIALIZED);
          if (op0 == 0)
            break;
          if (GET_CODE (rtl) == SIGN_EXTRACT)
@@ -14333,11 +14746,13 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
     case IF_THEN_ELSE:
       {
        dw_loc_descr_ref op2, bra_node, drop_node;
-       op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
-                                 VAR_INIT_STATUS_INITIALIZED);
-       op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
+       op0 = mem_loc_descriptor (XEXP (rtl, 0),
+                                 GET_MODE (XEXP (rtl, 0)) == VOIDmode
+                                 ? word_mode : GET_MODE (XEXP (rtl, 0)),
+                                 mem_mode, VAR_INIT_STATUS_INITIALIZED);
+       op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode,
                                  VAR_INIT_STATUS_INITIALIZED);
-       op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
+       op2 = mem_loc_descriptor (XEXP (rtl, 2), mode, mem_mode,
                                  VAR_INIT_STATUS_INITIALIZED);
        if (op0 == NULL || op1 == NULL || op2 == NULL)
          break;
@@ -14355,6 +14770,70 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
       }
       break;
 
+    case FLOAT_EXTEND:
+    case FLOAT_TRUNCATE:
+    case FLOAT:
+    case UNSIGNED_FLOAT:
+    case FIX:
+    case UNSIGNED_FIX:
+      if (!dwarf_strict)
+       {
+         dw_die_ref type_die;
+         dw_loc_descr_ref cvt;
+
+         op0 = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (XEXP (rtl, 0)),
+                                   mem_mode, VAR_INIT_STATUS_INITIALIZED);
+         if (op0 == NULL)
+           break;
+         if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) == MODE_INT
+             && (GET_CODE (rtl) == UNSIGNED_FLOAT
+                 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)))
+                    <= DWARF2_ADDR_SIZE))
+           {
+             type_die = base_type_for_mode (GET_MODE (XEXP (rtl, 0)),
+                                            GET_CODE (rtl) == UNSIGNED_FLOAT);
+             if (type_die == NULL)
+               break;
+             cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+             cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+             cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+             cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+             add_loc_descr (&op0, cvt);
+           }
+         type_die = base_type_for_mode (mode, GET_CODE (rtl) == UNSIGNED_FIX);
+         if (type_die == NULL)
+           break;
+         cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+         cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+         cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+         cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+         add_loc_descr (&op0, cvt);
+         if (GET_MODE_CLASS (mode) == MODE_INT
+             && (GET_CODE (rtl) == UNSIGNED_FIX
+                 || GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE))
+           {
+             enum machine_mode outer_mode = mode;
+             if (GET_MODE_SIZE (mode) < DWARF2_ADDR_SIZE)
+               {
+                 outer_mode = mode_for_size (DWARF2_ADDR_SIZE * BITS_PER_UNIT,
+                                             MODE_INT, 0);
+                 if (outer_mode == BLKmode
+                     || GET_MODE_SIZE (outer_mode) != DWARF2_ADDR_SIZE)
+                   break;
+               }
+             type_die = base_type_for_mode (outer_mode, 0);
+             if (type_die == NULL)
+               break;
+             cvt = new_loc_descr (DW_OP_GNU_convert, 0, 0);
+             cvt->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
+             cvt->dw_loc_oprnd1.v.val_die_ref.die = type_die;
+             cvt->dw_loc_oprnd1.v.val_die_ref.external = 0;
+             add_loc_descr (&op0, cvt);
+           }
+         mem_loc_result = op0;
+       }
+      break;
+
     case COMPARE:
     case ROTATE:
     case ROTATERT:
@@ -14386,12 +14865,6 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
     case UNLE:
     case UNLT:
     case LTGT:
-    case FLOAT_EXTEND:
-    case FLOAT_TRUNCATE:
-    case FLOAT:
-    case UNSIGNED_FLOAT:
-    case FIX:
-    case UNSIGNED_FIX:
     case FRACT_CONVERT:
     case UNSIGNED_FRACT_CONVERT:
     case SAT_FRACT:
@@ -14410,6 +14883,10 @@ mem_loc_descriptor (rtx rtl, enum machine_mode mode,
     case VEC_DUPLICATE:
     case UNSPEC:
     case HIGH:
+    case FMA:
+    case STRICT_LOW_PART:
+    case CONST_VECTOR:
+    case CONST_FIXED:
       /* If delegitimize_address couldn't do anything with the UNSPEC, we
         can't express it in the debug info.  This can happen e.g. with some
         TLS UNSPECs.  */
@@ -14547,7 +15024,10 @@ loc_descriptor (rtx rtl, enum machine_mode mode,
         up an entire register.  For now, just assume that it is
         legitimate to make the Dwarf info refer to the whole register which
         contains the given subreg.  */
-      loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
+      if (REG_P (SUBREG_REG (rtl)) && subreg_lowpart_p (rtl))
+       loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
+      else
+       goto do_default;
       break;
 
     case REG:
@@ -14555,8 +15035,8 @@ loc_descriptor (rtx rtl, enum machine_mode mode,
       break;
 
     case MEM:
-      loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
-                                      initialized);
+      loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
+                                      GET_MODE (rtl), initialized);
       if (loc_result == NULL)
        loc_result = tls_mem_loc_descriptor (rtl);
       if (loc_result == NULL)
@@ -14751,13 +15231,15 @@ loc_descriptor (rtx rtl, enum machine_mode mode,
          break;
        }
       /* FALLTHRU */
+    do_default:
     default:
-      if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
-         && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
-         && (dwarf_version >= 4 || !dwarf_strict))
+      if ((GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
+          && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
+          && dwarf_version >= 4)
+         || (!dwarf_strict && mode != VOIDmode && mode != BLKmode))
        {
          /* Value expression.  */
-         loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
+         loc_result = mem_loc_descriptor (rtl, mode, VOIDmode, initialized);
          if (loc_result)
            add_loc_descr (&loc_result,
                           new_loc_descr (DW_OP_stack_value, 0, 0));
@@ -14832,18 +15314,20 @@ dw_loc_list_1 (tree loc, rtx varloc, int want_address,
          if (MEM_P (varloc))
            {
              rtx addr = XEXP (varloc, 0);
-             descr = mem_loc_descriptor (addr, mode, initialized);
+             descr = mem_loc_descriptor (addr, get_address_mode (varloc),
+                                         mode, initialized);
              if (descr)
                have_address = 1;
              else
                {
                  rtx x = avoid_constant_pool_reference (varloc);
                  if (x != varloc)
-                   descr = mem_loc_descriptor (x, mode, initialized);
+                   descr = mem_loc_descriptor (x, mode, VOIDmode,
+                                               initialized);
                }
            }
          else
-           descr = mem_loc_descriptor (varloc, mode, initialized);
+           descr = mem_loc_descriptor (varloc, mode, VOIDmode, initialized);
        }
       else
        return 0;
@@ -15265,7 +15749,6 @@ cst_pool_loc_descr (tree loc)
 {
   /* Get an RTL for this, if something has been emitted.  */
   rtx rtl = lookup_constant_def (loc);
-  enum machine_mode mode;
 
   if (!rtl || !MEM_P (rtl))
     {
@@ -15283,9 +15766,8 @@ cst_pool_loc_descr (tree loc)
                        "CST value in contant pool but not marked.");
       return 0;
     }
-  mode = GET_MODE (rtl);
-  rtl = XEXP (rtl, 0);
-  return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
+  return mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl),
+                            GET_MODE (rtl), VAR_INIT_STATUS_INITIALIZED);
 }
 
 /* Return dw_loc_list representing address of addr_expr LOC
@@ -15530,7 +16012,7 @@ loc_list_from_tree (tree loc, int want_address)
          }
        else
          {
-           enum machine_mode mode;
+           enum machine_mode mode, mem_mode;
 
            /* Certain constructs can only be represented at top-level.  */
            if (want_address == 2)
@@ -15542,12 +16024,16 @@ loc_list_from_tree (tree loc, int want_address)
            else
              {
                mode = GET_MODE (rtl);
+               mem_mode = VOIDmode;
                if (MEM_P (rtl))
                  {
+                   mem_mode = mode;
+                   mode = get_address_mode (rtl);
                    rtl = XEXP (rtl, 0);
                    have_address = 1;
                  }
-               ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
+               ret = mem_loc_descriptor (rtl, mode, mem_mode,
+                                         VAR_INIT_STATUS_INITIALIZED);
              }
            if (!ret)
              expansion_failed (loc, rtl,
@@ -17233,7 +17719,9 @@ tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
 
   if (!decl
       || (TREE_CODE (decl) != VAR_DECL
-         && TREE_CODE (decl) != CONST_DECL))
+         && TREE_CODE (decl) != CONST_DECL)
+      || (TREE_CODE (decl) == VAR_DECL
+         && !TREE_STATIC (decl)))
     return false;
 
     if (TREE_READONLY (decl)
@@ -17259,6 +17747,7 @@ tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
 static dw_loc_list_ref
 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
 {
+  int ix;
   dw_fde_ref fde;
   dw_loc_list_ref list, *list_tail;
   dw_cfi_ref cfi;
@@ -17281,13 +17770,13 @@ convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
 
   /* ??? Bald assumption that the CIE opcode list does not contain
      advance opcodes.  */
-  for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
+  FOR_EACH_VEC_ELT (dw_cfi_ref, cie_cfi_vec, ix, cfi)
     lookup_cfa_1 (cfi, &next_cfa, &remember);
 
   last_cfa = next_cfa;
   last_label = start_label;
 
-  if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi == NULL)
+  if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi_index == 0)
     {
       /* If the first partition contained no CFI adjustments, the
         CIE opcodes apply to the whole first partition.  */
@@ -17297,7 +17786,7 @@ convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
       start_label = last_label = fde->dw_fde_second_begin;
     }
 
-  for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
+  FOR_EACH_VEC_ELT (dw_cfi_ref, fde->dw_fde_cfi, ix, cfi)
     {
       switch (cfi->dw_cfi_opc)
        {
@@ -17325,7 +17814,7 @@ convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
          lookup_cfa_1 (cfi, &next_cfa, &remember);
          break;
        }
-      if (cfi == fde->dw_fde_switch_cfi)
+      if (ix + 1 == fde->dw_fde_switch_cfi_index)
        {
          if (!cfa_equal_p (&last_cfa, &next_cfa))
            {
@@ -17413,6 +17902,38 @@ add_name_attribute (dw_die_ref die, const char *name_string)
     }
 }
 
+/* Retrieve the descriptive type of TYPE, if any, make sure it has a
+   DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
+   of TYPE accordingly.
+
+   ??? This is a temporary measure until after we're able to generate
+   regular DWARF for the complex Ada type system.  */
+
+static void 
+add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
+                                    dw_die_ref context_die)
+{
+  tree dtype;
+  dw_die_ref dtype_die;
+
+  if (!lang_hooks.types.descriptive_type)
+    return;
+
+  dtype = lang_hooks.types.descriptive_type (type);
+  if (!dtype)
+    return;
+
+  dtype_die = lookup_type_die (dtype);
+  if (!dtype_die)
+    {
+      gen_type_die (dtype, context_die);
+      dtype_die = lookup_type_die (dtype);
+      gcc_assert (dtype_die);
+    }
+
+  add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
+}
+
 /* Generate a DW_AT_comp_dir attribute for DIE.  */
 
 static void
@@ -18292,6 +18813,7 @@ gen_array_type_die (tree type, dw_die_ref context_die)
 
   array_die = new_die (DW_TAG_array_type, scope_die, type);
   add_name_attribute (array_die, type_tag (type));
+  add_gnat_descriptive_type_attribute (array_die, type, context_die);
   equate_type_number_to_die (type, array_die);
 
   if (TREE_CODE (type) == VECTOR_TYPE)
@@ -18594,6 +19116,7 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
                          scope_die_for (type, context_die), type);
       equate_type_number_to_die (type, type_die);
       add_name_attribute (type_die, type_tag (type));
+      add_gnat_descriptive_type_attribute (type_die, type, context_die);
       if (dwarf_version >= 4 || !dwarf_strict)
        {
          if (ENUM_IS_SCOPED (type))
@@ -19113,6 +19636,12 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
 
       subr_die = new_die (DW_TAG_subprogram, context_die, decl);
       add_abstract_origin_attribute (subr_die, origin);
+      /*  This is where the actual code for a cloned function is.
+         Let's emit linkage name attribute for it.  This helps
+         debuggers to e.g, set breakpoints into
+         constructors/destructors when the user asks "break
+         K::K".  */
+      add_linkage_name (subr_die, decl);
     }
   else if (old_die)
     {
@@ -19556,8 +20085,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                      if (mode == VOIDmode)
                        mode = GET_MODE (XEXP (arg, 0));
                    }
-                 if (GET_MODE_CLASS (mode) != MODE_INT
-                     || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
+                 if (mode == VOIDmode || mode == BLKmode)
                    continue;
                  if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
                    {
@@ -19576,14 +20104,19 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                    reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
                                              VAR_INIT_STATUS_INITIALIZED);
                  else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
-                   reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
-                                                         0), 0), mode,
-                                             VAR_INIT_STATUS_INITIALIZED);
+                   {
+                     rtx mem = XEXP (XEXP (arg, 0), 0);
+                     reg = mem_loc_descriptor (XEXP (mem, 0),
+                                               get_address_mode (mem),
+                                               GET_MODE (mem),
+                                               VAR_INIT_STATUS_INITIALIZED);
+                   }
                  else
                    continue;
                  if (reg == NULL)
                    continue;
-                 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
+                 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), mode,
+                                           VOIDmode,
                                            VAR_INIT_STATUS_INITIALIZED);
                  if (val == NULL)
                    continue;
@@ -19595,8 +20128,12 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                  add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
                  if (next_arg != XEXP (arg, 1))
                    {
+                     mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 1));
+                     if (mode == VOIDmode)
+                       mode = GET_MODE (XEXP (XEXP (XEXP (arg, 1), 0), 0));
                      val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
-                                                           0), 1), VOIDmode,
+                                                           0), 1),
+                                               mode, VOIDmode,
                                                VAR_INIT_STATUS_INITIALIZED);
                      if (val != NULL)
                        add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
@@ -19610,13 +20147,19 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
                  dw_loc_descr_ref tval = NULL;
 
                  if (tloc != NULL_RTX)
-                   tval = mem_loc_descriptor (tloc, VOIDmode,
+                   tval = mem_loc_descriptor (tloc,
+                                              GET_MODE (tloc) == VOIDmode
+                                              ? Pmode : GET_MODE (tloc),
+                                              VOIDmode,
                                               VAR_INIT_STATUS_INITIALIZED);
                  if (tval)
                    add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
                  else if (tlocc != NULL_RTX)
                    {
-                     tval = mem_loc_descriptor (tlocc, VOIDmode,
+                     tval = mem_loc_descriptor (tlocc,
+                                                GET_MODE (tlocc) == VOIDmode
+                                                ? Pmode : GET_MODE (tlocc),
+                                                VOIDmode,
                                                 VAR_INIT_STATUS_INITIALIZED);
                      if (tval)
                        add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
@@ -20149,7 +20692,7 @@ gen_reference_type_die (tree type, dw_die_ref context_die)
 {
   dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
 
-  if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
+  if (TYPE_REF_IS_RVALUE (type) && dwarf_version >= 4)
     ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
   else
     ref_die = new_die (DW_TAG_reference_type, scope_die, type);
@@ -20413,7 +20956,10 @@ gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
       if (old_die)
        add_AT_specification (type_die, old_die);
       else
-       add_name_attribute (type_die, type_tag (type));
+       {
+         add_name_attribute (type_die, type_tag (type));
+         add_gnat_descriptive_type_attribute (type_die, type, context_die);
+       }
     }
   else
     remove_AT (type_die, DW_AT_declaration);
@@ -22113,6 +22659,69 @@ var_location_switch_text_section (void)
   htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
 }
 
+/* Create a new line number table.  */
+
+static dw_line_info_table *
+new_line_info_table (void)
+{
+  dw_line_info_table *table;
+
+  table = ggc_alloc_cleared_dw_line_info_table_struct ();
+  table->file_num = 1;
+  table->line_num = 1;
+  table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
+
+  return table;
+}
+
+/* Lookup the "current" table into which we emit line info, so
+   that we don't have to do it for every source line.  */
+
+static void
+set_cur_line_info_table (section *sec)
+{
+  dw_line_info_table *table;
+
+  if (sec == text_section)
+    table = text_section_line_info;
+  else if (sec == cold_text_section)
+    {
+      table = cold_text_section_line_info;
+      if (!table)
+       {
+         cold_text_section_line_info = table = new_line_info_table ();
+         table->end_label = cold_end_label;
+       }
+    }
+  else
+    {
+      const char *end_label;
+
+      if (flag_reorder_blocks_and_partition)
+       {
+         if (in_cold_section_p)
+           end_label = crtl->subsections.cold_section_end_label;
+         else
+           end_label = crtl->subsections.hot_section_end_label;
+       }
+      else
+       {
+         char label[MAX_ARTIFICIAL_LABEL_BYTES];
+         ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
+                                      current_function_funcdef_no);
+         end_label = ggc_strdup (label);
+       }
+
+      table = new_line_info_table ();
+      table->end_label = end_label;
+
+      VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
+    }
+
+  cur_line_info_table = table;
+}
+
+
 /* We need to reset the locations at the beginning of each
    function. We can't do this in the end_function hook, because the
    declarations that use the locations won't have been output when
@@ -22121,114 +22730,119 @@ var_location_switch_text_section (void)
 static void
 dwarf2out_begin_function (tree fun)
 {
-  if (function_section (fun) != text_section)
+  section *sec = function_section (fun);
+
+  if (sec != text_section)
     have_multiple_function_sections = true;
+
   if (flag_reorder_blocks_and_partition && !cold_text_section)
     {
       gcc_assert (current_function_decl == fun);
       cold_text_section = unlikely_text_section ();
       switch_to_section (cold_text_section);
       ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
-      switch_to_section (current_function_section ());
+      switch_to_section (sec);
     }
 
   dwarf2out_note_section_used ();
   call_site_count = 0;
   tail_call_site_count = 0;
+
+  set_cur_line_info_table (sec);
+}
+
+/* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE.  */
+
+static void
+push_dw_line_info_entry (dw_line_info_table *table,
+                        enum dw_line_info_opcode opcode, unsigned int val)
+{
+  dw_line_info_entry e;
+  e.opcode = opcode;
+  e.val = val;
+  VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
 }
 
 /* Output a label to mark the beginning of a source code line entry
    and record information relating to this source line, in
    'line_info_table' for later output of the .debug_line section.  */
+/* ??? The discriminator parameter ought to be unsigned.  */
 
 static void
 dwarf2out_source_line (unsigned int line, const char *filename,
                        int discriminator, bool is_stmt)
 {
-  static bool last_is_stmt = true;
-
-  if (debug_info_level >= DINFO_LEVEL_NORMAL
-      && line != 0)
-    {
-      int file_num = maybe_emit_file (lookup_filename (filename));
+  unsigned int file_num;
+  dw_line_info_table *table;
 
-      switch_to_section (current_function_section ());
-
-      /* If requested, emit something human-readable.  */
-      if (flag_debug_asm)
-       fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
-                filename, line);
+  if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
+    return;
 
-      if (DWARF2_ASM_LINE_DEBUG_INFO)
-       {
-         /* Emit the .loc directive understood by GNU as.  */
-         fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
-         if (is_stmt != last_is_stmt)
-           {
-             fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
-             last_is_stmt = is_stmt;
-           }
-         if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
-           fprintf (asm_out_file, " discriminator %d", discriminator);
-         fputc ('\n', asm_out_file);
+  /* The discriminator column was added in dwarf4.  Simplify the below
+     by simply removing it if we're not supposed to output it.  */
+  if (dwarf_version < 4 && dwarf_strict)
+    discriminator = 0;
+
+  table = cur_line_info_table;
+  file_num = maybe_emit_file (lookup_filename (filename));
+
+  /* ??? TODO: Elide duplicate line number entries.  Traditionally,
+     the debugger has used the second (possibly duplicate) line number
+     at the beginning of the function to mark the end of the prologue.
+     We could eliminate any other duplicates within the function.  For
+     Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
+     that second line number entry.  */
+  /* Recall that this end-of-prologue indication is *not* the same thing
+     as the end_prologue debug hook.  The NOTE_INSN_PROLOGUE_END note,
+     to which the hook corresponds, follows the last insn that was 
+     emitted by gen_prologue.  What we need is to preceed the first insn
+     that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
+     insn that corresponds to something the user wrote.  These may be
+     very different locations once scheduling is enabled.  */
+
+  if (0 && file_num == table->file_num
+      && line == table->line_num
+      && discriminator == table->discrim_num
+      && is_stmt == table->is_stmt)
+    return;
 
-         /* Indicate that line number info exists.  */
-         line_info_table_in_use++;
-       }
-      else if (function_section (current_function_decl) != text_section)
-       {
-         dw_separate_line_info_ref line_info;
-         targetm.asm_out.internal_label (asm_out_file,
-                                         SEPARATE_LINE_CODE_LABEL,
-                                         separate_line_info_table_in_use);
-
-         /* Expand the line info table if necessary.  */
-         if (separate_line_info_table_in_use
-             == separate_line_info_table_allocated)
-           {
-             separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
-             separate_line_info_table
-               = GGC_RESIZEVEC (dw_separate_line_info_entry,
-                                separate_line_info_table,
-                                separate_line_info_table_allocated);
-             memset (separate_line_info_table
-                      + separate_line_info_table_in_use,
-                     0,
-                     (LINE_INFO_TABLE_INCREMENT
-                      * sizeof (dw_separate_line_info_entry)));
-           }
+  switch_to_section (current_function_section ());
 
-         /* Add the new entry at the end of the line_info_table.  */
-         line_info
-           = &separate_line_info_table[separate_line_info_table_in_use++];
-         line_info->dw_file_num = file_num;
-         line_info->dw_line_num = line;
-         line_info->function = current_function_funcdef_no;
-       }
-      else
-       {
-         dw_line_info_ref line_info;
+  /* If requested, emit something human-readable.  */
+  if (flag_debug_asm)
+    fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
 
-         targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
-                                    line_info_table_in_use);
+  if (DWARF2_ASM_LINE_DEBUG_INFO)
+    {
+      /* Emit the .loc directive understood by GNU as.  */
+      fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
+      if (is_stmt != table->is_stmt)
+       fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
+      if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
+       fprintf (asm_out_file, " discriminator %d", discriminator);
+      fputc ('\n', asm_out_file);
+    }
+  else
+    {
+      unsigned int label_num = ++line_info_label_num;
 
-         /* Expand the line info table if necessary.  */
-         if (line_info_table_in_use == line_info_table_allocated)
-           {
-             line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
-             line_info_table
-               = GGC_RESIZEVEC (dw_line_info_entry, line_info_table,
-                                line_info_table_allocated);
-             memset (line_info_table + line_info_table_in_use, 0,
-                     LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
-           }
+      targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
 
-         /* Add the new entry at the end of the line_info_table.  */
-         line_info = &line_info_table[line_info_table_in_use++];
-         line_info->dw_file_num = file_num;
-         line_info->dw_line_num = line;
-       }
+      push_dw_line_info_entry (table, LI_set_address, label_num);
+      if (file_num != table->file_num)
+       push_dw_line_info_entry (table, LI_set_file, file_num);
+      if (discriminator != table->discrim_num)
+       push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
+      if (is_stmt != table->is_stmt)
+       push_dw_line_info_entry (table, LI_negate_stmt, 0);
+      push_dw_line_info_entry (table, LI_set_line, line);
     }
+
+  table->file_num = file_num;
+  table->line_num = line;
+  table->discrim_num = discriminator;
+  table->is_stmt = is_stmt;
+  table->in_use = true;
 }
 
 /* Record the beginning of a new source file.  */
@@ -22389,14 +23003,6 @@ dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
   /* Zero-th entry is allocated, but unused.  */
   abbrev_die_table_in_use = 1;
 
-  /* Allocate the initial hunk of the line_info_table.  */
-  line_info_table = ggc_alloc_cleared_vec_dw_line_info_entry
-    (LINE_INFO_TABLE_INCREMENT);
-  line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
-
-  /* Zero-th entry is allocated, but unused.  */
-  line_info_table_in_use = 1;
-
   /* Allocate the pubtypes and pubnames vectors.  */
   pubname_table = VEC_alloc (pubname_entry, gc, 32);
   pubtype_table = VEC_alloc (pubname_entry, gc, 32);
@@ -22450,6 +23056,10 @@ dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
 
   switch_to_section (text_section);
   ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
+
+  /* Make sure the line number table for .text always exists.  */
+  text_section_line_info = new_line_info_table ();
+  text_section_line_info->end_label = text_end_label;
 }
 
 /* Called before cgraph_optimize starts outputtting functions, variables
@@ -22473,7 +23083,7 @@ output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
 {
   struct indirect_string_node *node = (struct indirect_string_node *) *h;
 
-  if (node->label && node->refcount)
+  if (node->form == DW_FORM_strp)
     {
       switch_to_section (debug_str_section);
       ASM_OUTPUT_LABEL (asm_out_file, node->label);
@@ -22790,21 +23400,6 @@ prune_unused_types_prune (dw_die_ref die)
   } while (c != die->die_child);
 }
 
-/* A helper function for dwarf2out_finish called through
-   htab_traverse.  Clear .debug_str strings that we haven't already
-   decided to emit.  */
-
-static int
-prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
-{
-  struct indirect_string_node *node = (struct indirect_string_node *) *h;
-
-  if (!node->label || !node->refcount)
-    htab_clear_slot (debug_str_hash, h);
-
-  return 1;
-}
-
 /* Remove dies representing declarations that we never use.  */
 
 static void
@@ -22814,6 +23409,7 @@ prune_unused_types (void)
   limbo_die_node *node;
   comdat_type_node *ctnode;
   pubname_ref pub;
+  dw_die_ref base_type;
 
 #if ENABLE_ASSERT_CHECKING
   /* All the marks should already be clear.  */
@@ -22841,11 +23437,10 @@ prune_unused_types (void)
      pubname_table.  */
   FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
     prune_unused_types_mark (pub->die, 1);
+  for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
+    prune_unused_types_mark (base_type, 1);
 
-  /* Get rid of nodes that aren't marked; and update the string counts.  */
-  if (debug_str_hash && debug_str_hash_forced)
-    htab_traverse (debug_str_hash, prune_indirect_string, NULL);
-  else if (debug_str_hash)
+  if (debug_str_hash)
     htab_empty (debug_str_hash);
   prune_unused_types_prune (comp_unit_die ());
   for (node = limbo_die_list; node; node = node->next)
@@ -22929,6 +23524,117 @@ move_linkage_attr (dw_die_ref die)
     }
 }
 
+/* Helper function for resolve_addr, mark DW_TAG_base_type nodes
+   referenced from typed stack ops and count how often they are used.  */
+
+static void
+mark_base_types (dw_loc_descr_ref loc)
+{
+  dw_die_ref base_type = NULL;
+
+  for (; loc; loc = loc->dw_loc_next)
+    {
+      switch (loc->dw_loc_opc)
+       {
+       case DW_OP_GNU_regval_type:
+       case DW_OP_GNU_deref_type:
+         base_type = loc->dw_loc_oprnd2.v.val_die_ref.die;
+         break;
+       case DW_OP_GNU_const_type:
+       case DW_OP_GNU_convert:
+       case DW_OP_GNU_reinterpret:
+         base_type = loc->dw_loc_oprnd1.v.val_die_ref.die;
+         break;
+       case DW_OP_GNU_entry_value:
+         mark_base_types (loc->dw_loc_oprnd1.v.val_loc);
+         continue;
+       default:
+         continue;
+       }
+      gcc_assert (base_type->die_parent == comp_unit_die ());
+      if (base_type->die_mark)
+       base_type->die_mark++;
+      else
+       {
+         VEC_safe_push (dw_die_ref, heap, base_types, base_type);
+         base_type->die_mark = 1;
+       }
+    }
+}
+
+/* Comparison function for sorting marked base types.  */
+
+static int
+base_type_cmp (const void *x, const void *y)
+{
+  dw_die_ref dx = *(const dw_die_ref *) x;
+  dw_die_ref dy = *(const dw_die_ref *) y;
+  unsigned int byte_size1, byte_size2;
+  unsigned int encoding1, encoding2;
+  if (dx->die_mark > dy->die_mark)
+    return -1;
+  if (dx->die_mark < dy->die_mark)
+    return 1;
+  byte_size1 = get_AT_unsigned (dx, DW_AT_byte_size);
+  byte_size2 = get_AT_unsigned (dy, DW_AT_byte_size);
+  if (byte_size1 < byte_size2)
+    return 1;
+  if (byte_size1 > byte_size2)
+    return -1;
+  encoding1 = get_AT_unsigned (dx, DW_AT_encoding);
+  encoding2 = get_AT_unsigned (dy, DW_AT_encoding);
+  if (encoding1 < encoding2)
+    return 1;
+  if (encoding1 > encoding2)
+    return -1;
+  return 0;
+}
+
+/* Move base types marked by mark_base_types as early as possible
+   in the CU, sorted by decreasing usage count both to make the
+   uleb128 references as small as possible and to make sure they
+   will have die_offset already computed by calc_die_sizes when
+   sizes of typed stack loc ops is computed.  */
+
+static void
+move_marked_base_types (void)
+{
+  unsigned int i;
+  dw_die_ref base_type, die, c;
+
+  if (VEC_empty (dw_die_ref, base_types))
+    return;
+
+  /* Sort by decreasing usage count, they will be added again in that
+     order later on.  */
+  VEC_qsort (dw_die_ref, base_types, base_type_cmp);
+  die = comp_unit_die ();
+  c = die->die_child;
+  do
+    {
+      dw_die_ref prev = c;
+      c = c->die_sib;
+      while (c->die_mark)
+       {
+         remove_child_with_prev (c, prev);
+         /* As base types got marked, there must be at least
+            one node other than DW_TAG_base_type.  */
+         gcc_assert (c != c->die_sib);
+         c = c->die_sib;
+       }
+    }
+  while (c != die->die_child);
+  gcc_assert (die->die_child);
+  c = die->die_child;
+  for (i = 0; VEC_iterate (dw_die_ref, base_types, i, base_type); i++)
+    {
+      base_type->die_mark = 0;
+      base_type->die_sib = c->die_sib;
+      c->die_sib = base_type;
+      c = base_type;
+    }
+}
+
 /* Helper function for resolve_addr, attempt to resolve
    one CONST_STRING, return non-zero if not successful.  Similarly verify that
    SYMBOL_REFs refer to variables emitted in the current CU.  */
@@ -22942,7 +23648,7 @@ resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
     {
       size_t len = strlen (XSTR (rtl, 0)) + 1;
       tree t = build_string (len, XSTR (rtl, 0));
-      tree tlen = build_int_cst (NULL_TREE, len - 1);
+      tree tlen = size_int (len - 1);
       TREE_TYPE (t)
        = build_array_type (char_type_node, build_index_type (tlen));
       rtl = lookup_constant_def (t);
@@ -23049,7 +23755,10 @@ resolve_addr (dw_die_ref die)
                    *curr = next;
                  }
                else
-                 curr = &(*curr)->dw_loc_next;
+                 {
+                   mark_base_types ((*curr)->expr);
+                   curr = &(*curr)->dw_loc_next;
+                 }
              }
            if (loc == *start)
              loc->resolved_addr = 1;
@@ -23071,6 +23780,8 @@ resolve_addr (dw_die_ref die)
            remove_AT (die, a->dw_attr);
            ix--;
          }
+       else
+         mark_base_types (AT_loc (a));
        break;
       case dw_val_class_addr:
        if (a->dw_attr == DW_AT_const_value
@@ -23084,7 +23795,9 @@ resolve_addr (dw_die_ref die)
          {
            tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
            dw_die_ref tdie = lookup_decl_die (tdecl);
-           if (tdie == NULL && DECL_EXTERNAL (tdecl))
+           if (tdie == NULL
+               && DECL_EXTERNAL (tdecl)
+               && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
              {
                force_decl_die (tdecl);
                tdie = lookup_decl_die (tdecl);
@@ -23236,6 +23949,56 @@ hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
     case DW_OP_GNU_entry_value:
       hash = hash_loc_operands (val1->v.val_loc, hash);
       break;
+    case DW_OP_GNU_regval_type:
+    case DW_OP_GNU_deref_type:
+      {
+       unsigned int byte_size
+         = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_byte_size);
+       unsigned int encoding
+         = get_AT_unsigned (val2->v.val_die_ref.die, DW_AT_encoding);
+       hash = iterative_hash_object (val1->v.val_int, hash);
+       hash = iterative_hash_object (byte_size, hash);
+       hash = iterative_hash_object (encoding, hash);
+      }
+      break;
+    case DW_OP_GNU_convert:
+    case DW_OP_GNU_reinterpret:
+    case DW_OP_GNU_const_type:
+      {
+       unsigned int byte_size
+         = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_byte_size);
+       unsigned int encoding
+         = get_AT_unsigned (val1->v.val_die_ref.die, DW_AT_encoding);
+       hash = iterative_hash_object (byte_size, hash);
+       hash = iterative_hash_object (encoding, hash);
+       if (loc->dw_loc_opc != DW_OP_GNU_const_type)
+         break;
+       hash = iterative_hash_object (val2->val_class, hash);
+       switch (val2->val_class)
+         {
+         case dw_val_class_const:
+           hash = iterative_hash_object (val2->v.val_int, hash);
+           break;
+         case dw_val_class_vec:
+           {
+             unsigned int elt_size = val2->v.val_vec.elt_size;
+             unsigned int len = val2->v.val_vec.length;
+
+             hash = iterative_hash_object (elt_size, hash);
+             hash = iterative_hash_object (len, hash);
+             hash = iterative_hash (val2->v.val_vec.array,
+                                    len * elt_size, hash);
+           }
+           break;
+         case dw_val_class_const_double:
+           hash = iterative_hash_object (val2->v.val_double.low, hash);
+           hash = iterative_hash_object (val2->v.val_double.high, hash);
+           break;
+         default:
+           gcc_unreachable ();
+         }
+      }
+      break;
 
     default:
       /* Other codes have no operands.  */
@@ -23395,6 +24158,33 @@ compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
             && valx2->v.val_int == valy2->v.val_int;
     case DW_OP_GNU_entry_value:
       return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
+    case DW_OP_GNU_const_type:
+      if (valx1->v.val_die_ref.die != valy1->v.val_die_ref.die
+         || valx2->val_class != valy2->val_class)
+       return false;
+      switch (valx2->val_class)
+       {
+       case dw_val_class_const:
+         return valx2->v.val_int == valy2->v.val_int;
+       case dw_val_class_vec:
+         return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
+                && valx2->v.val_vec.length == valy2->v.val_vec.length
+                && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
+                           valx2->v.val_vec.elt_size
+                           * valx2->v.val_vec.length) == 0;
+       case dw_val_class_const_double:
+         return valx2->v.val_double.low == valy2->v.val_double.low
+                && valx2->v.val_double.high == valy2->v.val_double.high;
+       default:
+         gcc_unreachable ();
+       }
+    case DW_OP_GNU_regval_type:
+    case DW_OP_GNU_deref_type:
+      return valx1->v.val_int == valy1->v.val_int
+            && valx2->v.val_die_ref.die == valy2->v.val_die_ref.die;
+    case DW_OP_GNU_convert:
+    case DW_OP_GNU_reinterpret:
+      return valx1->v.val_die_ref.die == valy1->v.val_die_ref.die;
     default:
       /* Other codes have no operands.  */
       return true;
@@ -23576,7 +24366,14 @@ dwarf2out_finish (const char *filename)
 
   limbo_die_list = NULL;
 
+#if ENABLE_ASSERT_CHECKING
+  {
+    dw_die_ref die = comp_unit_die (), c;
+    FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
+  }
+#endif
   resolve_addr (comp_unit_die ());
+  move_marked_base_types ();
 
   for (node = deferred_asm_name; node; node = node->next)
     {
@@ -23647,23 +24444,18 @@ dwarf2out_finish (const char *filename)
   if (!have_multiple_function_sections 
       || (dwarf_version < 3 && dwarf_strict))
     {
-      add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
-      add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
+      /* Don't add if the CU has no associated code.  */
+      if (text_section_used)
+       {
+         add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
+         add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
+       }
     }
-
   else
     {
       unsigned fde_idx = 0;
       bool range_list_added = false;
 
-      /* We need to give .debug_loc and .debug_ranges an appropriate
-        "base address".  Use zero so that these addresses become
-        absolute.  Historically, we've emitted the unexpected
-        DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
-        Emit both to give time for other tools to adapt.  */
-      add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
-      add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
-
       if (text_section_used)
        add_ranges_by_labels (comp_unit_die (), text_section_label,
                              text_end_label, &range_list_added);
@@ -23684,7 +24476,18 @@ dwarf2out_finish (const char *filename)
        }
 
       if (range_list_added)
-       add_ranges (NULL);
+       {
+         /* We need to give .debug_loc and .debug_ranges an appropriate
+            "base address".  Use zero so that these addresses become
+            absolute.  Historically, we've emitted the unexpected
+            DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
+            Emit both to give time for other tools to adapt.  */
+         add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
+         if (! dwarf_strict && dwarf_version < 4)
+           add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
+
+         add_ranges (NULL);
+       }
     }
 
   if (debug_info_level >= DINFO_LEVEL_NORMAL)
@@ -23780,21 +24583,17 @@ dwarf2out_finish (const char *filename)
        }
     }
 
-  /* Output the address range information.  We only put functions in the
-     arange table, so don't write it out if we don't have any.  */
+  /* Output the address range information if a CU (.debug_info section)
+     was emitted.  We output an empty table even if we had no functions
+     to put in it.  This because the consumer has no way to tell the
+     difference between an empty table that we omitted and failure to
+     generate a table that would have contained data.  */
   if (info_section_emitted)
     {
       unsigned long aranges_length = size_of_aranges ();
 
-      /* Empty .debug_aranges would contain just header and
-        terminating 0,0.  */
-      if (aranges_length
-         != (unsigned long) (DWARF_ARANGES_HEADER_SIZE
-                             + 2 * DWARF2_ADDR_SIZE))
-       {
-         switch_to_section (debug_aranges_section);
-         output_aranges (aranges_length);
-       }
+      switch_to_section (debug_aranges_section);
+      output_aranges (aranges_length);
     }
 
   /* Output ranges section if necessary.  */