diff options
author | Joseph Myers <joseph@codesourcery.com> | 2005-04-27 01:47:06 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2005-04-27 01:47:06 +0100 |
commit | eb3490b96c149c8a5559b3f3947257c4ce0df650 (patch) | |
tree | cf0c6299cc325166c5334689a7def45d807128fa /gcc | |
parent | 968744fc6609f4efdadb4272ac895d1e15867c77 (diff) | |
download | gcc-eb3490b96c149c8a5559b3f3947257c4ce0df650.zip gcc-eb3490b96c149c8a5559b3f3947257c4ce0df650.tar.gz gcc-eb3490b96c149c8a5559b3f3947257c4ce0df650.tar.bz2 |
re PR c/21213 (segfault declaring a transparent union)
PR c/21213
* c-decl.c (finish_struct): Don't dereference NULL TYPE_FIELDS of
transparent union.
testsuite:
* gcc.dg/transparent-union-3.c: New test.
From-SVN: r98808
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-decl.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/transparent-union-3.c | 22 |
4 files changed, 34 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 89af6e5..f0da7e6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2005-04-27 Joseph S. Myers <joseph@codesourcery.com> + PR c/21213 + * c-decl.c (finish_struct): Don't dereference NULL TYPE_FIELDS of + transparent union. + +2005-04-27 Joseph S. Myers <joseph@codesourcery.com> + PR c/20740 * c-format.c (init_dynamic_asm_fprintf_info): Give errors, not assertion failures, if __gcc_host_wide_int__ is not properly diff --git a/gcc/c-decl.c b/gcc/c-decl.c index b1309b3..3578862 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -5329,7 +5329,7 @@ finish_struct (tree t, tree fieldlist, tree attributes) make it one, warn and turn off the flag. */ if (TREE_CODE (t) == UNION_TYPE && TYPE_TRANSPARENT_UNION (t) - && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))) + && (!TYPE_FIELDS (t) || TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t)))) { TYPE_TRANSPARENT_UNION (t) = 0; warning (0, "union cannot be made transparent"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0f6ab3d..bd88d35 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2005-04-27 Joseph S. Myers <joseph@codesourcery.com> + PR c/21213 + * gcc.dg/transparent-union-3.c: New test. + +2005-04-27 Joseph S. Myers <joseph@codesourcery.com> + PR c/20740 * gcc.dg/format/asm_fprintf-2.c, gcc.dg/format/asm_fprintf-3.c, gcc.dg/format/asm_fprintf-4.c, gcc.dg/format/asm_fprintf-5.c, diff --git a/gcc/testsuite/gcc.dg/transparent-union-3.c b/gcc/testsuite/gcc.dg/transparent-union-3.c new file mode 100644 index 0000000..cebd5f8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/transparent-union-3.c @@ -0,0 +1,22 @@ +/* Test for ICEs on invalid transparent unions (empty or no named + members). Bug 21213. */ +/* Origin: Joseph Myers <joseph@codesourcery.com> */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +enum e { A }; + +union __attribute__((__transparent_union__)) ue1 { enum e; }; /* { dg-warning "warning: declaration does not declare anything" } */ +/* { dg-warning "warning: union cannot be made transparent" "" { target *-*-* } 9 } */ +union ue2 { enum e; } __attribute__((__transparent_union__)); /* { dg-warning "warning: declaration does not declare anything" } */ +/* { dg-warning "warning: union cannot be made transparent" "" { target *-*-* } 11 } */ + +union __attribute__((__transparent_union__)) ui1 { int; }; /* { dg-warning "warning: declaration does not declare anything" } */ +/* { dg-warning "warning: union cannot be made transparent" "" { target *-*-* } 14 } */ +union ui2 { int; } __attribute__((__transparent_union__)); /* { dg-warning "warning: declaration does not declare anything" } */ +/* { dg-warning "warning: union cannot be made transparent" "" { target *-*-* } 16 } */ + +union __attribute__((__transparent_union__)) u1 { }; +/* { dg-warning "warning: union cannot be made transparent" "" { target *-*-* } 19 } */ +union u2 { } __attribute__((__transparent_union__)); +/* { dg-warning "warning: union cannot be made transparent" "" { target *-*-* } 21 } */ |