aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2019-03-25 22:56:40 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2019-03-25 16:56:40 -0600
commit0c9992c8b5e07e7295c8be65586a2a82e7f191e5 (patch)
tree9d606885c33689f567cb979e674488195d67d6e2 /gcc
parent3f9a6608899dbbe22f98ef7c42937d2729864f85 (diff)
downloadgcc-0c9992c8b5e07e7295c8be65586a2a82e7f191e5.zip
gcc-0c9992c8b5e07e7295c8be65586a2a82e7f191e5.tar.gz
gcc-0c9992c8b5e07e7295c8be65586a2a82e7f191e5.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-family/c-common.c13
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/attr-aligned-3.c28
4 files changed, 47 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cdce539..18682f3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 2b99842..67f68f0 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 7a0c4bc..b4b1159 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
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 0000000..0603377
--- /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" } */