+/* If the DIE has a DW_AT_alignment attribute, return its value, doing
+ appropriate error checking and issuing complaints if there is a
+ problem. */
+
+static ULONGEST
+get_alignment (struct dwarf2_cu *cu, struct die_info *die)
+{
+ struct attribute *attr = dwarf2_attr (die, DW_AT_alignment, cu);
+
+ if (attr == nullptr)
+ return 0;
+
+ if (!attr_form_is_constant (attr))
+ {
+ complaint (_("DW_AT_alignment must have constant form"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+
+ ULONGEST align;
+ if (attr->form == DW_FORM_sdata)
+ {
+ LONGEST val = DW_SND (attr);
+ if (val < 0)
+ {
+ complaint (_("DW_AT_alignment value must not be negative"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+ align = val;
+ }
+ else
+ align = DW_UNSND (attr);
+
+ if (align == 0)
+ {
+ complaint (_("DW_AT_alignment value must not be zero"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+ if ((align & (align - 1)) != 0)
+ {
+ complaint (_("DW_AT_alignment value must be a power of 2"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+
+ return align;
+}
+
+/* If the DIE has a DW_AT_alignment attribute, use its value to set
+ the alignment for TYPE. */
+
+static void
+maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die,
+ struct type *type)
+{
+ if (!set_type_align (type, get_alignment (cu, die)))
+ complaint (_("DW_AT_alignment value too large"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+}