From: Martin Sebor Date: Mon, 25 Mar 2019 22:56:40 +0000 (+0000) Subject: PR c/89812 - incorrect maximum in error: requested alignment '536870912' exceeds... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0c9992c8b5e07e7295c8be65586a2a82e7f191e5;p=gcc.git PR c/89812 - incorrect maximum in error: requested alignment '536870912' exceeds maximum 2147483648 gcc/c-family/ChangeLog: PR c/89812 * c-common.c (check_user_alignment): Rename local. Correct maximum alignment in diagnostic. Avoid assuming argument fits in SHWI, convert it to UHWI when it fits. gcc/testsuite/ChangeLog: PR c/89812 * gcc.dg/attr-aligned-3.c: New test. From-SVN: r269927 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cdce539ac6f..18682f3d130 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-03-25 Martin Sebor + + PR c/89812 + * c-common.c (check_user_alignment): Rename local. Correct maximum + alignment in diagnostic. Avoid assuming argument fits in SHWI, + convert it to UHWI when it fits. + 2019-03-25 Johan Karlsson PR debug/86964 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 2b99842309d..67f68f0b76f 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5287,9 +5287,10 @@ check_user_alignment (const_tree align, bool objfile, bool warn_zero) return -1; } - int log2bitalign; + /* Log2 of the byte alignment ALIGN. */ + int log2align; if (tree_int_cst_sgn (align) == -1 - || (log2bitalign = tree_log2 (align)) == -1) + || (log2align = tree_log2 (align)) == -1) { error ("requested alignment %qE is not a positive power of 2", align); @@ -5299,7 +5300,7 @@ check_user_alignment (const_tree align, bool objfile, bool warn_zero) if (objfile) { unsigned maxalign = MAX_OFILE_ALIGNMENT / BITS_PER_UNIT; - if (tree_to_shwi (align) > maxalign) + if (!tree_fits_uhwi_p (align) || tree_to_uhwi (align) > maxalign) { error ("requested alignment %qE exceeds object file maximum %u", align, maxalign); @@ -5307,14 +5308,14 @@ check_user_alignment (const_tree align, bool objfile, bool warn_zero) } } - if (log2bitalign >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT) + if (log2align >= HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT) { error ("requested alignment %qE exceeds maximum %u", - align, 1U << (HOST_BITS_PER_INT - 1)); + align, 1U << (HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT - 1)); return -1; } - return log2bitalign; + return log2align; } /* Determine the ELF symbol visibility for DECL, which is either a diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7a0c4bc5edc..b4b1159e3bf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-25 Martin Sebor + + PR c/89812 + * gcc.dg/attr-aligned-3.c: New test. + 2019-03-25 Johan Karlsson PR debug/86964 diff --git a/gcc/testsuite/gcc.dg/attr-aligned-3.c b/gcc/testsuite/gcc.dg/attr-aligned-3.c new file mode 100644 index 00000000000..0603377a32d --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-aligned-3.c @@ -0,0 +1,28 @@ +/* PR c/89812 - incorrect maximum in error: requested alignment '536870912' + exceeds maximum 2147483648 + { dg-do compile } + { dg-require-effective-target size32plus } */ + +#define POWALIGN(N) __attribute__ ((aligned ((__UINT64_TYPE__)1 << (N)))) + +typedef POWALIGN (28) char T28; + +/* The maximum alignment is constrained by the number of bits in int + on host minus 3: HOST_BITS_PER_INT - LOG2_BITS_PER_UNIT. The test + assumes host int is 32-bits wide. */ +typedef POWALIGN (29) char X29; /* { dg-error "requested alignment .536870912. exceeds maximum 268435456" } */ +typedef POWALIGN (30) char X30; /* { dg-error "requested alignment .1073741824. exceeds maximum 268435456" } */ +typedef POWALIGN (31) char X31; /* { dg-error "requested alignment .2147483648. exceeds maximum 268435456" } */ +typedef POWALIGN (32) char X32; /* { dg-error "requested alignment .4294967296. exceeds maximum 268435456" } */ +typedef POWALIGN (60) char X60; /* { dg-error "requested alignment .1152921504606846976. exceeds maximum 268435456" } */ +typedef POWALIGN (63) char X63; /* { dg-error "requested alignment .9223372036854775808. exceeds maximum 268435456" } */ + + +POWALIGN (28) char c28; + +POWALIGN (29) char c29; /* { dg-error "requested alignment .536870912. exceeds object file maximum 268435456" } */ +POWALIGN (30) char x30; /* { dg-error "requested alignment .1073741824. exceeds object file maximum 268435456" } */ +POWALIGN (31) char x31; /* { dg-error "requested alignment .2147483648. exceeds object file maximum 268435456" } */ +POWALIGN (32) char x32; /* { dg-error "requested alignment .4294967296. exceeds object file maximum 268435456" } */ +POWALIGN (60) char x60; /* { dg-error "requested alignment .1152921504606846976. exceeds object file maximum 268435456" } */ +POWALIGN (63) char x63; /* { dg-error "requested alignment .9223372036854775808. exceeds object file maximum 268435456" } */