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
This commit is contained in:
Martin Sebor 2019-03-25 22:56:40 +00:00 committed by Martin Sebor
parent 3f9a660889
commit 0c9992c8b5
4 changed files with 47 additions and 6 deletions

View file

@ -1,3 +1,10 @@
2019-03-25 Martin Sebor <msebor@redhat.com>
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 <johan.karlsson@enea.com>
PR debug/86964

View file

@ -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

View file

@ -1,3 +1,8 @@
2019-03-25 Martin Sebor <msebor@redhat.com>
PR c/89812
* gcc.dg/attr-aligned-3.c: New test.
2019-03-25 Johan Karlsson <johan.karlsson@enea.com>
PR debug/86964

View file

@ -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" } */