aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2000-11-13 14:14:44 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2000-11-13 14:14:44 +0000
commit19552aa5728591fdd2913ef54422e869af46852e (patch)
treef2b5f8cbfe56d1d0cc94e1b89e38e9cb318f7ece /gcc/c-decl.c
parent444ca59fa44336fbfe4744c9870bf1dd0a75093f (diff)
downloadgcc-19552aa5728591fdd2913ef54422e869af46852e.zip
gcc-19552aa5728591fdd2913ef54422e869af46852e.tar.gz
gcc-19552aa5728591fdd2913ef54422e869af46852e.tar.bz2
c-common.c (boolean_increment): New function.
* c-common.c (boolean_increment): New function. * c-common.h (enum c_tree_index): Add CTI_C_BOOL_TYPE, CTI_C_BOOL_TRUE and CTI_C_BOOL_FALSE. (c_bool_type_node, c_bool_true_node, c_bool_false_node): Define. (boolean_increment): Declare. * c-convert.c (convert): Allow for BOOLEAN_TYPE. * c-decl.c (init_decl_processing): Create boolean nodes. (finish_struct): Allow for _Bool bitfields. * c-parse.in (reswords): Add _Bool. (rid_to_yy): Allow for RID_BOOL. * c-typeck.c (default_conversion): Make booleans promote to int. (convert_arguments, build_unary_op, build_modify_expr, convert_for_assignment): Allow for booleans. * ginclude/stdbool.h: Make conforming to C99. cp: * typeck.c (build_unary_op): Use boolean_increment from c-common.c, moving the relevant code there. testsuite: * gcc.dg/c99-bool-1.c: New test. From-SVN: r37428
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 45dbb2c..d9ceac8 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -3113,6 +3113,19 @@ init_decl_processing ()
boolean_true_node = integer_one_node;
boolean_false_node = integer_zero_node;
+ /* With GCC, C99's _Bool is always of size 1. */
+ c_bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
+ TREE_SET_CODE (c_bool_type_node, BOOLEAN_TYPE);
+ TYPE_MAX_VALUE (c_bool_type_node) = build_int_2 (1, 0);
+ TREE_TYPE (TYPE_MAX_VALUE (c_bool_type_node)) = c_bool_type_node;
+ TYPE_PRECISION (c_bool_type_node) = 1;
+ pushdecl (build_decl (TYPE_DECL, get_identifier ("_Bool"),
+ c_bool_type_node));
+ c_bool_false_node = build_int_2 (0, 0);
+ TREE_TYPE (c_bool_false_node) = c_bool_type_node;
+ c_bool_true_node = build_int_2 (1, 0);
+ TREE_TYPE (c_bool_true_node) = c_bool_type_node;
+
string_type_node = build_pointer_type (char_type_node);
const_string_type_node
= build_pointer_type (build_type_variant (char_type_node, 1, 0));
@@ -5431,6 +5444,7 @@ finish_struct (t, fieldlist, attributes)
/* Detect invalid bit-field type. */
if (DECL_INITIAL (x)
&& TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
+ && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE
&& TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
{
error_with_decl (x, "bit-field `%s' has invalid type");
@@ -5440,6 +5454,7 @@ finish_struct (t, fieldlist, attributes)
if (DECL_INITIAL (x) && pedantic
&& TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
&& TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
+ && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != c_bool_type_node
/* Accept an enum that's equivalent to int or unsigned int. */
&& !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
&& (TYPE_PRECISION (TREE_TYPE (x))
@@ -5450,10 +5465,14 @@ finish_struct (t, fieldlist, attributes)
field widths. */
if (DECL_INITIAL (x))
{
+ int max_width;
+ if (TYPE_MAIN_VARIANT (TREE_TYPE (x)) == c_bool_type_node)
+ max_width = CHAR_TYPE_SIZE;
+ else
+ max_width = TYPE_PRECISION (TREE_TYPE (x));
if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0)
error_with_decl (x, "negative width in bit-field `%s'");
- else if (0 < compare_tree_int (DECL_INITIAL (x),
- TYPE_PRECISION (TREE_TYPE (x))))
+ else if (0 < compare_tree_int (DECL_INITIAL (x), max_width))
pedwarn_with_decl (x, "width of `%s' exceeds its type");
else if (integer_zerop (DECL_INITIAL (x)) && DECL_NAME (x) != 0)
error_with_decl (x, "zero width for bit-field `%s'");