From 616aeba2bb37e55c24cc65a861e12c08e18e3943 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sat, 11 Sep 2004 00:10:05 +0100 Subject: [PATCH] c-tree.h (struct c_declspecs): Remove typedef_decl. * c-tree.h (struct c_declspecs): Remove typedef_decl. Add typedef_p and typedef_signed_p. * c-decl.c (shadow_tag_warned): Check typedef_p, not typedef_decl. (grokdeclarator): Don't use typedef_decl for warn_deprecated_use. Check typedef_p and typedef_signed_p, not typedef_decl. (grokfield): Check typedef_p, not typedef_decl. (build_null_declspecs): Initialize typedef_p and typedef_signed_p, not typedef_decl. (declspecs_add_type): Set typedef_p and typedef_signed_p, not typedef_decl. testsuite: * gcc.dg/bitfld-9.c: New test. From-SVN: r87326 --- gcc/ChangeLog | 13 ++++ gcc/c-decl.c | 24 +++---- gcc/c-tree.h | 7 +- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/bitfld-9.c | 119 ++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/bitfld-9.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f4af2480d8c..4e691a19a49 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2004-09-11 Joseph S. Myers + + * c-tree.h (struct c_declspecs): Remove typedef_decl. Add + typedef_p and typedef_signed_p. + * c-decl.c (shadow_tag_warned): Check typedef_p, not typedef_decl. + (grokdeclarator): Don't use typedef_decl for warn_deprecated_use. + Check typedef_p and typedef_signed_p, not typedef_decl. + (grokfield): Check typedef_p, not typedef_decl. + (build_null_declspecs): Initialize typedef_p and typedef_signed_p, + not typedef_decl. + (declspecs_add_type): Set typedef_p and typedef_signed_p, not + typedef_decl. + 2004-09-10 Kazu Hirata * doc/tm.texi, doc/tree-ssa.texi: Fix typos. diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 12e27a0053d..dd0e42f0ab2 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -2681,7 +2681,7 @@ shadow_tag_warned (const struct c_declspecs *declspecs, int warned) pending_invalid_xref = 0; - if (declspecs->type && !declspecs->typedef_decl) + if (declspecs->type && !declspecs->typedef_p) { tree value = declspecs->type; enum tree_code code = TREE_CODE (value); @@ -2724,7 +2724,7 @@ shadow_tag_warned (const struct c_declspecs *declspecs, int warned) } } } - else if (warned != 1 && !in_system_header && declspecs->typedef_decl) + else if (warned != 1 && !in_system_header && declspecs->typedef_p) { pedwarn ("useless type name in empty declaration"); warned = 1; @@ -3666,9 +3666,7 @@ grokdeclarator (const struct c_declarator *declarator, decl_context = PARM; if (declspecs->deprecated_p && deprecated_state != DEPRECATED_SUPPRESS) - warn_deprecated_use (declspecs->typedef_decl - ? declspecs->typedef_decl - : declspecs->type); + warn_deprecated_use (declspecs->type); typedef_type = type; if (type) @@ -3782,8 +3780,7 @@ grokdeclarator (const struct c_declarator *declarator, || declspecs->explicit_char_p /* A typedef for plain `int' without `signed' can be controlled just like plain `int'. */ - || ! (declspecs->typedef_decl != 0 - && C_TYPEDEF_EXPLICITLY_SIGNED (declspecs->typedef_decl))) + || !declspecs->typedef_signed_p) && TREE_CODE (type) != ENUMERAL_TYPE && !(specbits & 1 << (int) RID_SIGNED))) { @@ -3795,7 +3792,7 @@ grokdeclarator (const struct c_declarator *declarator, type = short_unsigned_type_node; else if (type == char_type_node) type = unsigned_char_type_node; - else if (declspecs->typedef_decl) + else if (declspecs->typedef_p) type = c_common_unsigned_type (type); else type = unsigned_type_node; @@ -4352,8 +4349,7 @@ grokdeclarator (const struct c_declarator *declarator, type = c_build_qualified_type (type, type_quals); decl = build_decl (TYPE_DECL, declarator->u.id, type); if ((specbits & (1 << (int) RID_SIGNED)) - || (declspecs->typedef_decl - && C_TYPEDEF_EXPLICITLY_SIGNED (declspecs->typedef_decl))) + || declspecs->typedef_signed_p) C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; decl_attributes (&decl, returned_attrs, 0); return decl; @@ -5099,7 +5095,7 @@ grokfield (struct c_declarator *declarator, struct c_declspecs *declspecs, if (type && (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE) - && (flag_ms_extensions || !declspecs->typedef_decl)) + && (flag_ms_extensions || !declspecs->typedef_p)) { if (flag_ms_extensions) ; /* ok */ @@ -6728,11 +6724,12 @@ build_null_declspecs (void) { struct c_declspecs *ret = XOBNEW (&parser_obstack, struct c_declspecs); ret->type = 0; - ret->typedef_decl = 0; ret->decl_attr = 0; ret->attrs = 0; ret->specbits = 0; ret->non_sc_seen_p = false; + ret->typedef_p = false; + ret->typedef_signed_p = false; ret->deprecated_p = false; ret->explicit_int_p = false; ret->explicit_char_p = false; @@ -6807,7 +6804,8 @@ declspecs_add_type (struct c_declspecs *specs, tree type) { specs->type = TREE_TYPE (type); specs->decl_attr = DECL_ATTRIBUTES (type); - specs->typedef_decl = type; + specs->typedef_p = true; + specs->typedef_signed_p = C_TYPEDEF_EXPLICITLY_SIGNED (type); } } /* Built-in types come as identifiers. */ diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 37075518b83..dde8dc3249d 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -136,8 +136,6 @@ struct c_declspecs { /* The type specified, not reflecting modifiers such as "short" and "unsigned", or NULL_TREE if none. */ tree type; - /* If the type was specified with a typedef, that typedef decl. */ - tree typedef_decl; /* The attributes from a typedef decl. */ tree decl_attr; /* When parsing, the attributes. Outside the parser, this will be @@ -153,6 +151,11 @@ struct c_declspecs { specifiers to be handled separately from storage class specifiers.) */ BOOL_BITFIELD non_sc_seen_p : 1; + /* Whether the type is specified by a typedef. */ + BOOL_BITFIELD typedef_p : 1; + /* Whether the type is specified by a typedef whose type is + explicitly "signed". */ + BOOL_BITFIELD typedef_signed_p : 1; /* Whether the specifiers include a deprecated typedef. */ BOOL_BITFIELD deprecated_p : 1; /* Whether "int" was explicitly specified. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 80dd8b05c5d..056073cce16 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-09-11 Joseph S. Myers + + * gcc.dg/bitfld-9.c: New test. + 2004-09-10 Richard Sandiford * gcc.c-torture/execute/ieee/acc1.c: New test. diff --git a/gcc/testsuite/gcc.dg/bitfld-9.c b/gcc/testsuite/gcc.dg/bitfld-9.c new file mode 100644 index 00000000000..d6ae0ac31e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitfld-9.c @@ -0,0 +1,119 @@ +/* Test -funsigned-bitfields works. */ +/* Origin: Joseph Myers */ +/* { dg-do run } */ +/* { dg-options "-funsigned-bitfields -fsigned-char" } */ + +typedef char c; +typedef signed char sc; +typedef unsigned char uc; +typedef short s; +typedef signed short ss; +typedef unsigned short us; +typedef n; +typedef int i; +typedef signed int si; +typedef unsigned int ui; +typedef long l; +typedef signed long sl; +typedef unsigned long ul; +typedef long long ll; +typedef signed long long sll; +typedef unsigned long long ull; + +typedef c ct; +typedef sc sct; +typedef uc uct; +typedef s st; +typedef ss sst; +typedef us ust; +typedef n nt; +typedef i it; +typedef si sit; +typedef ui uit; +typedef l lt; +typedef sl slt; +typedef ul ult; +typedef ll llt; +typedef sll sllt; +typedef ull ullt; + +struct foo { + char char0 : 1; + c char1 : 1; + ct char2 : 1; + signed char schar0 : 1; + sc schar1 : 1; + sct schar2 : 1; + unsigned char uchar0 : 1; + uc uchar1 : 1; + uct uchar2 : 1; + short short0 : 1; + s short1 : 1; + st short2 : 1; + signed short sshort0 : 1; + ss sshort1 : 1; + sst sshort2 : 1; + unsigned short ushort0 : 1; + us ushort1 : 1; + ust ushort2 : 1; + __attribute__((dummy)) int0 : 1; /* { dg-warning "attribute directive ignored" } */ + n int1 : 1; + nt int2 : 1; + int int3 : 1; + i int4 : 1; + it int5 : 1; + signed int sint0 : 1; + si sint1 : 1; + sit sint2 : 1; + unsigned int uint0 : 1; + ui uint1 : 1; + uit uint2 : 1; + long long0 : 1; + l long1 : 1; + lt long2 : 1; + signed long slong0 : 1; + sl slong1 : 1; + slt slong2 : 1; + unsigned long ulong0 : 1; + ul ulong1 : 1; + ult ulong2 : 1; + long long llong0 : 1; + ll llong1 : 1; + llt llong2 : 1; + signed long long sllong0 : 1; + sll sllong1 : 1; + sllt sllong2 : 1; + unsigned long long ullong0 : 1; + ull ullong1 : 1; + ullt ullong2 : 1; +}; + +struct foo x; + +extern void abort (void); +extern void exit (int); +extern void *memset (void *, int, __SIZE_TYPE__); + +int +main (void) +{ + memset (&x, (unsigned char)-1, sizeof(x)); + if (x.char0 != 1 || x.char1 != 1 || x.char2 != 1 + || x.schar0 != -1 || x.schar1 != -1 || x.schar2 != -1 + || x.uchar0 != 1 || x.uchar1 != 1 || x.uchar2 != 1 + || x.short0 != 1 || x.short1 != 1 || x.short2 != 1 + || x.sshort0 != -1 || x.sshort1 != -1 || x.sshort2 != -1 + || x.ushort0 != 1 || x.ushort1 != 1 || x.ushort2 != 1 + || x.int0 != 1 || x.int1 != 1 || x.int2 != 1 + || x.int3 != 1 || x.int4 != 1 || x.int5 != 1 + || x.sint0 != -1 || x.sint1 != -1 || x.sint2 != -1 + || x.uint0 != 1 || x.uint1 != 1 || x.uint2 != 1 + || x.long0 != 1 || x.long1 != 1 || x.long2 != 1 + || x.slong0 != -1 || x.slong1 != -1 || x.slong2 != -1 + || x.ulong0 != 1 || x.ulong1 != 1 || x.ulong2 != 1 + || x.llong0 != 1 || x.llong1 != 1 || x.llong2 != 1 + || x.sllong0 != -1 || x.sllong1 != -1 || x.sllong2 != -1 + || x.ullong0 != 1 || x.ullong1 != 1 || x.ullong2 != 1) + abort (); + exit (0); +} -- 2.30.2