However, where strict alignment is not required, avoid
over-aligning structures, since most compilers do not do this
alignment. */
+ bool tua_cleared_p = false;
if (TYPE_MODE (type) != BLKmode
&& TYPE_MODE (type) != VOIDmode
&& (STRICT_ALIGNMENT || !AGGREGATE_TYPE_P (type)))
if (mode_align >= TYPE_ALIGN (type))
{
SET_TYPE_ALIGN (type, mode_align);
- TYPE_USER_ALIGN (type) = 0;
+ /* Remember that we're about to reset this flag. */
+ tua_cleared_p = TYPE_USER_ALIGN (type);
+ TYPE_USER_ALIGN (type) = false;
}
}
/* Copy it into all variants. */
for (variant = TYPE_MAIN_VARIANT (type);
- variant != 0;
+ variant != NULL_TREE;
variant = TYPE_NEXT_VARIANT (variant))
{
TYPE_SIZE (variant) = size;
TYPE_SIZE_UNIT (variant) = size_unit;
unsigned valign = align;
if (TYPE_USER_ALIGN (variant))
- valign = MAX (valign, TYPE_ALIGN (variant));
+ {
+ valign = MAX (valign, TYPE_ALIGN (variant));
+ /* If we reset TYPE_USER_ALIGN on the main variant, we might
+ need to reset it on the variants too. TYPE_MODE will be set
+ to MODE in this variant, so we can use that. */
+ if (tua_cleared_p && GET_MODE_ALIGNMENT (mode) >= valign)
+ TYPE_USER_ALIGN (variant) = false;
+ }
else
TYPE_USER_ALIGN (variant) = user_align;
SET_TYPE_ALIGN (variant, valign);
--- /dev/null
+// PR c++/94775
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-mstrict-align" { target { aarch64*-*-* powerpc*-*-linux* powerpc*-*-elf* } } }
+
+struct alignas(8) S {
+ S *arr[1];
+ void fn () const { (void) arr[0]; }
+};
--- /dev/null
+// PR c++/94775
+// { dg-do compile { target c++14 } }
+// { dg-options "-O2 -Warray-bounds" }
+
+template <typename> using a = int;
+template <bool, typename, typename> using b = int;
+typedef char d;
+template <long> using e = int;
+template <int f, int q> struct h { using i = b<q, a<e<f>>, e<f>>; };
+template <long f, bool g> using j = typename h<f, g>::i;
+long ab, k, aj;
+const d l[]{};
+class m {
+public:
+ m(int);
+};
+class n {
+ void ad() const;
+ template <class ae> void o(long) const {
+ using c __attribute__((aligned(1))) = const ae;
+ }
+ long p;
+ template <class, class>
+ auto s(unsigned long, unsigned long, unsigned long, unsigned long) const;
+ template <bool = false> auto q(unsigned long, unsigned long) const;
+};
+template <class, class>
+auto n::s(unsigned long, unsigned long, unsigned long, unsigned long t) const {
+ o<d>(p);
+ return t;
+}
+template <bool g> auto n::q(unsigned long p1, unsigned long p2) const {
+ using r = j<4, false>;
+ using ai = j<4, g>;
+ return s<ai, r>(ab, k, p1, p2);
+}
+void n::ad() const {
+ long f(l[aj]); // { dg-warning "outside array bounds" }
+ m(q(8, f));
+}
TYPE_ATTRIBUTES (base)))
return false;
/* Check alignment. */
- if (TYPE_ALIGN (cand) == TYPE_ALIGN (base))
+ if (TYPE_ALIGN (cand) == TYPE_ALIGN (base)
+ && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base))
return true;
/* Atomic types increase minimal alignment. We must to do so as well
or we get duplicated canonical types. See PR88686. */
&& TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
/* Check alignment. */
&& TYPE_ALIGN (cand) == align
+ && TYPE_USER_ALIGN (cand) == TYPE_USER_ALIGN (base)
&& attribute_list_equal (TYPE_ATTRIBUTES (cand),
TYPE_ATTRIBUTES (base))
&& check_lang_type (cand, base));