+static void parse_bitfield_member(entity_t *entity)
+{
+ eat(':');
+
+ expression_t *size = parse_constant_expression();
+ long size_long;
+
+ assert(entity->kind == ENTITY_COMPOUND_MEMBER);
+ type_t *type = entity->declaration.type;
+ if (!is_type_integer(skip_typeref(type))) {
+ errorf(HERE, "bitfield base type '%T' is not an integer type",
+ type);
+ }
+
+ if (is_constant_expression(size) != EXPR_CLASS_CONSTANT) {
+ /* error already reported by parse_constant_expression */
+ size_long = get_type_size(type) * 8;
+ } else {
+ size_long = fold_constant_to_int(size);
+
+ const symbol_t *symbol = entity->base.symbol;
+ const symbol_t *user_symbol
+ = symbol == NULL ? sym_anonymous : symbol;
+ unsigned bit_size = get_type_size(type) * 8;
+ if (size_long < 0) {
+ errorf(HERE, "negative width in bit-field '%Y'", user_symbol);
+ } else if (size_long == 0 && symbol != NULL) {
+ errorf(HERE, "zero width for bit-field '%Y'", user_symbol);
+ } else if (bit_size > 0 && (unsigned)size_long > bit_size) {
+ errorf(HERE, "width of bitfield '%Y' exceeds its type",
+ user_symbol);
+ } else {
+ /* hope that people don't invent crazy types with more bits
+ * than our struct can hold */
+ assert(size_long <
+ (1 << sizeof(entity->compound_member.bit_size)*8));
+ }
+ }
+
+ entity->compound_member.bitfield = true;
+ entity->compound_member.bit_size = (unsigned char)size_long;
+}
+