[4.5] PATCH: PR c/39323: MAX_OFILE_ALIGNMENT in elfos.h is too big
H.J. Lu
hjl.tools@gmail.com
Tue Mar 3 19:39:00 GMT 2009
On Mon, Mar 2, 2009 at 10:27 PM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> gcc/
>>
>> 2009-02-28 H.J. Lu <hongjiu.lu@intel.com>
>>
>> PR c/39323
>> * c-common.c (handle_aligned_attribute): Check alignment
>> overlow.
>>
>> gcc/testsuite/
>>
>> 2009-02-28 H.J. Lu <hongjiu.lu@intel.com>
>>
>> PR c/39323
>> * gcc.dg/pr39323.c: New.
>>
>
>> @@ -5954,7 +5956,19 @@ handle_aligned_attribute (tree *node, tr
>> *type = build_variant_type_copy (*type);
>
>> TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
>> - TYPE_USER_ALIGN (*type) = 1;
>> + /* TYPE_ALIGN and DECL_ALIGN, defined as decl_common.align, may
>> + have different widths. Use decl_common.align directly to check
>> + for overflow. */
>> + saved = (*type)->decl_common.align;
>> + (*type)->decl_common.align = (1 << i) * BITS_PER_UNIT;
>> + if ((*type)->decl_common.align != (1 << i) * BITS_PER_UNIT)
>> + {
>> + error ("requested alignment is too large");
>> + *no_add_attrs = true;
>> + }
>> + else
>> + TYPE_USER_ALIGN (*type) = 1;
>> + (*type)->decl_common.align = saved;
>
> It is never OK to refer to decl_common outside of tree.h. In any case I
> don't see why it matters here whether decl_common.align overflows. What
> matters is whether TYPE_ALIGN overflows.
>
> If you are concerned about the TYPE_ALIGN value overflowing when you
> copy it to DECL_ALIGN, check it at the point of the copy to DECL_ALIGN.
>
> Please use a variable to hold the expression "(1 << i) * BIT_PER_UNIT",
> rather than repeating it.
>
>> @@ -5977,7 +5991,13 @@ handle_aligned_attribute (tree *node, tr
>> else
>> {
>> DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
>> - DECL_USER_ALIGN (decl) = 1;
>> + if (DECL_ALIGN (decl) != (1 << i) * BITS_PER_UNIT)
>> + {
>> + error ("requested alignment is too large");
>> + *no_add_attrs = true;
>> + }
>> + else
>> + DECL_USER_ALIGN (decl) = 1;
>
> Please use a variable for "(1 << i) * BIT_PER_UNIT".
>
Here is the updated patch. It added decl_align_ok in
tree.h.
There are
coverage.c: DECL_ALIGN (tree_ctr_tables[counter]) = TYPE_ALIGN
(gcov_type_node);
omp-low.c: DECL_ALIGN (field) = TYPE_ALIGN (type);
stmt.c: DECL_ALIGN (decl) = TYPE_ALIGN (type);
stor-layout.c: DECL_ALIGN (decl) = TYPE_ALIGN (type);
tree-nested.c: TYPE_ALIGN (type) = DECL_ALIGN (field);
tree-nested.c: DECL_ALIGN (field) = TYPE_ALIGN (TREE_TYPE (field));
tree-nested.c: DECL_ALIGN (field) = TYPE_ALIGN (type);
tree-nested.c: DECL_ALIGN (field) = TYPE_ALIGN (type);
tree-vect-analyze.c: DECL_ALIGN (base) = TYPE_ALIGN (vectype);
tree-vectorizer.c: DECL_ALIGN (decl) = TYPE_ALIGN (vectype);
cp/class.c: DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
cp/class.c: DECL_ALIGN (decl) = CLASSTYPE_ALIGN (basetype);
cp/class.c: DECL_ALIGN (field) = TYPE_ALIGN (integer_type);
fortran/trans-common.c: DECL_ALIGN (decl) = TYPE_ALIGN (TREE_TYPE (field));
java/typeck.c: DECL_ALIGN (arfld) = TYPE_ALIGN (element_type);
ada/gcc-interface/utils.c: DECL_ALIGN (field_decl) = TYPE_ALIGN (field_type);
If we want to delay DECL_ALIGN overflow check, we may need to
check it at those places above and we may only call sorry ().
I can prepare such a patch if it is desirable.
Thanks.
--
H.J.
---
gcc/
2009-02-28 H.J. Lu <hongjiu.lu@intel.com>
PR c/39323
* c-common.c (handle_aligned_attribute): Check alignment
overflow.
* tree.h (decl_align_ok): New.
gcc/testsuite/
2009-02-28 H.J. Lu <hongjiu.lu@intel.com>
PR c/39323
* gcc.dg/pr39323.c: New.
-------------- next part --------------
gcc/
2009-02-28 H.J. Lu <hongjiu.lu@intel.com>
PR c/39323
* c-common.c (handle_aligned_attribute): Check alignment
overflow.
* tree.h (decl_align_ok): New.
gcc/testsuite/
2009-02-28 H.J. Lu <hongjiu.lu@intel.com>
PR c/39323
* gcc.dg/pr39323.c: New.
--- gcc/c-common.c.pr39323 2009-03-02 11:53:39.000000000 -0800
+++ gcc/c-common.c 2009-03-03 10:44:26.000000000 -0800
@@ -5911,6 +5911,7 @@ handle_aligned_attribute (tree *node, tr
tree align_expr = (args ? TREE_VALUE (args)
: size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT));
int i;
+ unsigned int align;
if (DECL_P (*node))
{
@@ -5953,8 +5954,16 @@ handle_aligned_attribute (tree *node, tr
else if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
*type = build_variant_type_copy (*type);
- TYPE_ALIGN (*type) = (1 << i) * BITS_PER_UNIT;
- TYPE_USER_ALIGN (*type) = 1;
+ align = (1 << i) * BITS_PER_UNIT;
+ TYPE_ALIGN (*type) = align;
+ /* Check DECL_ALIGN overflow. */
+ if (!decl_align_ok (align))
+ {
+ error ("requested alignment is too large");
+ *no_add_attrs = true;
+ }
+ else
+ TYPE_USER_ALIGN (*type) = 1;
}
else if (! VAR_OR_FUNCTION_DECL_P (decl)
&& TREE_CODE (decl) != FIELD_DECL)
@@ -5976,8 +5985,15 @@ handle_aligned_attribute (tree *node, tr
}
else
{
- DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
- DECL_USER_ALIGN (decl) = 1;
+ align = (1 << i) * BITS_PER_UNIT;
+ DECL_ALIGN (decl) = align;
+ if (DECL_ALIGN (decl) != align)
+ {
+ error ("requested alignment is too large");
+ *no_add_attrs = true;
+ }
+ else
+ DECL_USER_ALIGN (decl) = 1;
}
return NULL_TREE;
--- gcc/testsuite/gcc.dg/pr39323.c.pr39323 2009-03-02 17:27:59.000000000 -0800
+++ gcc/testsuite/gcc.dg/pr39323.c 2009-03-02 17:48:29.000000000 -0800
@@ -0,0 +1,7 @@
+/* PR c/39323 */
+/* { dg-do compile { target *-*-linux* } } */
+
+int bar __attribute__ ((aligned(1 << 20))) = 20;
+int foo __attribute__ ((aligned(1 << 21))) = 20; /* { dg-error "requested alignment is too large" } */
+typedef int __attribute__ ((aligned(1 << 20))) int20;
+typedef int __attribute__ ((aligned(1 << 21))) int21; /* { dg-error "requested alignment is too large" } */
--- gcc/tree.h.pr39323 2009-03-03 10:20:55.000000000 -0800
+++ gcc/tree.h 2009-03-03 10:43:16.000000000 -0800
@@ -2743,6 +2743,17 @@ struct tree_decl_common GTY(())
struct lang_decl *lang_specific;
};
+/* Return TRUE if __ALIGN won't overflow the align field in
+ tree_decl_common. */
+
+static inline bool
+decl_align_ok (unsigned int __align)
+{
+ struct tree_decl_common __decl_common;
+ __decl_common.align = __align;
+ return __decl_common.align == __align;
+}
+
extern tree decl_value_expr_lookup (tree);
extern void decl_value_expr_insert (tree, tree);
More information about the Gcc-patches
mailing list