summaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2011-11-06 23:51:19 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2011-11-06 23:51:19 +0000
commit83e25171a1cb0db643150e81b4cbe310fd6f4215 (patch)
tree665bdd624cc911e728a962281f278e5fbf2aefce /gcc/c-family
parent7cc301360be9e2df43673fe7e6c273f28496b31a (diff)
downloadgcc-83e25171a1cb0db643150e81b4cbe310fd6f4215.tar.gz
* c-decl.c (shadow_tag_warned, grokdeclarator): Handle _Alignas
specifiers. (build_null_declspecs): Initialize align_log and alignas_p fields. (declspecs_add_alignas): New. * c-parser.c (c_token_starts_declspecs): Handle RID_ALIGNAS. (c_parser_declspecs): Handle _Alignas specifiers. (c_parser_alignas_specifier): New. (c_parser_alignof_expression): Diagnose alignof use for non-C1X. Diagnose _Alignof (expression). * c-tree.h (struct c_declspecs): Add align_log and alignas_p fields. (declspecs_add_alignas): Declare. * ginclude/stddef.h (max_align_t): Define for C1X and C++11. * ginclude/stdalign.h: New. * Makefile.in (USER_H): Add stdalign.h. c-family: * c-common.c (c_common_reswords): Add _Alignas and _Alignof. (c_sizeof_or_alignof_type): Diagnose alignof applied to a function type. (check_user_alignment): New. Split out of handle_aligned_attribute. Disallow integer constants with noninteger types. Conditionally allow zero. (handle_aligned_attribute): Use check_user_alignment. * c-common.h (RID_ALIGNAS, check_user_alignment): New. testsuite: * g++.dg/cpp0x/alignof3.C, gcc.dg/c1x-align-1.c, gcc.dg/c1x-align-2.c, gcc.dg/c1x-align-3.c, gcc.dg/c1x-align-4.c, gcc.dg/c90-align-1.c, gcc.dg/c99-align-1.c: New tests. * gcc.dg/gnu89-const-expr-1.c, gcc.dg/gnu90-const-expr-1.c, gcc.dg/gnu99-const-expr-1.c, gcc.dg/gnu99-static-1.c: Update expected diagnostics. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181048 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog11
-rw-r--r--gcc/c-family/c-common.c62
-rw-r--r--gcc/c-family/c-common.h4
3 files changed, 61 insertions, 16 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 1c8a6b412f3..3829411d726 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,14 @@
+2011-11-06 Joseph Myers <joseph@codesourcery.com>
+
+ * c-common.c (c_common_reswords): Add _Alignas and _Alignof.
+ (c_sizeof_or_alignof_type): Diagnose alignof applied to a function
+ type.
+ (check_user_alignment): New. Split out of
+ handle_aligned_attribute. Disallow integer constants with
+ noninteger types. Conditionally allow zero.
+ (handle_aligned_attribute): Use check_user_alignment.
+ * c-common.h (RID_ALIGNAS, check_user_alignment): New.
+
2011-11-06 Andrew MacLeod <amacleod@redhat.com>
Richard Henderson <rth@redhat.com>
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index aa5f3bf24aa..0329bc7e01c 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -404,6 +404,8 @@ static int resort_field_decl_cmp (const void *, const void *);
*/
const struct c_common_resword c_common_reswords[] =
{
+ { "_Alignas", RID_ALIGNAS, D_CONLY },
+ { "_Alignof", RID_ALIGNOF, D_CONLY },
{ "_Bool", RID_BOOL, D_CONLY },
{ "_Complex", RID_COMPLEX, 0 },
{ "_Imaginary", RID_IMAGINARY, D_CONLY },
@@ -4332,7 +4334,18 @@ c_sizeof_or_alignof_type (location_t loc,
value = size_one_node;
}
else
- value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
+ {
+ if (complain)
+ {
+ if (c_dialect_cxx ())
+ pedwarn (loc, OPT_pedantic, "ISO C++ does not permit "
+ "%<alignof%> applied to a function type");
+ else
+ pedwarn (loc, OPT_pedantic, "ISO C does not permit "
+ "%<_Alignof%> applied to a function type");
+ }
+ value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
+ }
}
else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
{
@@ -6670,6 +6683,36 @@ handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
return NULL_TREE;
}
+/* Check whether ALIGN is a valid user-specified alignment. If so,
+ return its base-2 log; if not, output an error and return -1. If
+ ALLOW_ZERO then 0 is valid and should result in a return of -1 with
+ no error. */
+int
+check_user_alignment (const_tree align, bool allow_zero)
+{
+ int i;
+
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (align))
+ || TREE_CODE (align) != INTEGER_CST)
+ {
+ error ("requested alignment is not an integer constant");
+ return -1;
+ }
+ else if (allow_zero && integer_zerop (align))
+ return -1;
+ else if ((i = tree_log2 (align)) == -1)
+ {
+ error ("requested alignment is not a power of 2");
+ return -1;
+ }
+ else if (i >= HOST_BITS_PER_INT - BITS_PER_UNIT_LOG)
+ {
+ error ("requested alignment is too large");
+ return -1;
+ }
+ return i;
+}
+
/* Handle a "aligned" attribute; arguments as in
struct attribute_spec.handler. */
@@ -6693,21 +6736,8 @@ handle_aligned_attribute (tree *node, tree ARG_UNUSED (name), tree args,
else if (TYPE_P (*node))
type = node, is_type = 1;
- if (TREE_CODE (align_expr) != INTEGER_CST)
- {
- error ("requested alignment is not a constant");
- *no_add_attrs = true;
- }
- else if ((i = tree_log2 (align_expr)) == -1)
- {
- error ("requested alignment is not a power of 2");
- *no_add_attrs = true;
- }
- else if (i >= HOST_BITS_PER_INT - BITS_PER_UNIT_LOG)
- {
- error ("requested alignment is too large");
- *no_add_attrs = true;
- }
+ if ((i = check_user_alignment (align_expr, false)) == -1)
+ *no_add_attrs = true;
else if (is_type)
{
if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 7ecb57e5867..bff6956cc14 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -106,6 +106,9 @@ enum rid
RID_DFLOAT32, RID_DFLOAT64, RID_DFLOAT128,
RID_FRACT, RID_ACCUM,
+ /* C1X */
+ RID_ALIGNAS,
+
/* This means to warn that this is a C++ keyword, and then treat it
as a normal identifier. */
RID_CXX_COMPAT_WARN,
@@ -724,6 +727,7 @@ extern void finish_fname_decls (void);
extern const char *fname_as_string (int);
extern tree fname_decl (location_t, unsigned, tree);
+extern int check_user_alignment (const_tree, bool);
extern void check_function_arguments (const_tree, int, tree *);
extern void check_function_arguments_recurse (void (*)
(void *, tree,