c-common.h (struct c_common_identifier): Remove rid_code field.
authorZack Weinberg <zack@gcc.gnu.org>
Wed, 24 Oct 2001 20:10:53 +0000 (20:10 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Wed, 24 Oct 2001 20:10:53 +0000 (20:10 +0000)
* c-common.h (struct c_common_identifier): Remove rid_code field.
(C_RID_CODE): Use ->node.rid_code instead of ->rid_code.

* c-typeck.c (constructor_designated): New local flag.
(struct constructor_stack): Add "designated" field to match.
(start_init): Clear it.
(really_start_incremental_init, push_init_level): Push and
clear it.
(pop_init_level): Pop it.
(set_designator): Set it.

(pop_init_level): Suppress "missing initializer" warnings if
constructor_designated is true.
(process_init_element): Suppress warning about union
initialization under traditional C, if constructor_designated
is true.

* intl/loadmsgcat.c (INTTYPE_SIGNED, INTTYPE_MINIMUM,
INTTYPE_MAXIMUM): Clone from system.h.
(_nl_load_domain): Use them when testing for overflow of size_t.
Cast result of sizeof to off_t to compare to st_size value.
Move side effects out of conditional for comprehensibility.

* testsuite/gcc.dg/20011021-1.c: New test.

From-SVN: r46472

gcc/ChangeLog
gcc/c-common.h
gcc/c-typeck.c
gcc/intl/ChangeLog
gcc/intl/loadmsgcat.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20011021-1.c [new file with mode: 0644]

index 0832377217559d8171eceab27ad7a6994f79e2ef..773395322b89e4578a437df471f1a0b7450b0fa4 100644 (file)
@@ -1,3 +1,22 @@
+2001-10-24  Zack Weinberg  <zack@codesourcery.com>
+
+       * c-common.h (struct c_common_identifier): Remove rid_code field.
+       (C_RID_CODE): Use ->node.rid_code instead of ->rid_code.
+
+       * c-typeck.c (constructor_designated): New local flag.
+       (struct constructor_stack): Add "designated" field to match.
+       (start_init): Clear it.
+       (really_start_incremental_init, push_init_level): Push and
+       clear it.
+       (pop_init_level): Pop it.
+       (set_designator): Set it.
+
+       (pop_init_level): Suppress "missing initializer" warnings if
+       constructor_designated is true.
+       (process_init_element): Suppress warning about union
+       initialization under traditional C, if constructor_designated
+       is true.
+
 Wed Oct 24 15:35:38 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
        * integrate.c (copy_rtx_and_substitute, case CALL): Fix error in last
@@ -10,7 +29,7 @@ Wed Oct 24 13:26:12 2001  Jeffrey A Law  (law@cygnus.com)
 2001-10-24  Dan Nicolaescu  <dann@ics.uci.edu>
 
        * ssa-ccp.c (ssa_ccp_substitute_constants): Don't do anything if
-       the node was already a set to a constant. 
+       the node was already a set to a constant.
 
 Wed Oct 24 12:41:19 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
 
@@ -1811,8 +1830,8 @@ Wed Oct  3 12:22:11 EDT 2001  John Wehle  (john@feith.com)
        * cppmain.c: Update comments.
 
 Tue Oct  2 12:46:01 CEST 2001  Bo Thorsen     <bo@suse.co.uk>,
-                              Andreas Jaeger <aj@suse.de>,
-                              Jan Hubicka    <jh@suse.cz>
+                               Andreas Jaeger <aj@suse.de>,
+                               Jan Hubicka    <jh@suse.cz>
 
        * doc/invoke.texi (i386 Options): Document x86-64 options.
        (i386 and x86-64 Options): Rename i386 options section.
@@ -8410,7 +8429,7 @@ Sun Jul 29 18:59:13 CEST 2001  Jan Hubicka  <jh@suse.cz>
        (try_optimize_cfg): Update call of try_forward_edges.
 
 Sun Jul 29 18:59:56 CEST 2001  Roman Zippel  <zippel@linux-m68k.org>
-                              Jan Hubicka  <jh@suse.cz>
+                               Jan Hubicka  <jh@suse.cz>
 
        * (validate_replace_rtx_1): Fix simplification of MINUS.
 
@@ -9145,7 +9164,7 @@ Sun Jul 22 21:31:04 CEST 2001  Jan Hubicka  <jh@suse.cz>
        insns to delete in the presence of cc0 in a jump insn.
 
 Fri Jul 20 22:14:49 CEST 2001  Roman Zippel  <zippel@linux-m68k.org>
-                              Jan Hubicka  <jh@suse.cz>
+                               Jan Hubicka  <jh@suse.cz>
 
        * m68k.md (zero_extend?i?i2 expander): Use gen_lowpart instead
        of doing the change by hand.
@@ -9428,7 +9447,7 @@ Wed Jul 18 20:47:36 CEST 2001  Jan Hubicka  <jh@suse.cz>
        * aclocal.m4 (AM_ICONV): New macro from Bruno Haible.
 
 Wed Jul 18 18:46:30 CEST 2001  Richard Henderson <rth@cygnus.com>
-                              Jan Hubicka  <jh@suse.cz>
+                               Jan Hubicka  <jh@suse.cz>
 
        * flow.c (redirect_edge_and_branch): Bail out on complex edges.
        (try_optimize_cfg): Do not remove tail recursive labels before sibcall.
@@ -9485,9 +9504,9 @@ Wed Jul 18 12:05:29 2001  Nicola Pero  <n.pero@mi.flashnet.it>
 
 2001-07-17  Andreas Schwab  <schwab@suse.de>
 
-       * configure.in  (assembler eh_frame optimization): Handle big
-       endian.
-       * configure: Regenerated.
+       * configure.in  (assembler eh_frame optimization): Handle big
+       endian.
+       * configure: Regenerated.
 
 Tue Jul 17 23:43:31 CEST 2001  Jan Hubicka  <jh@suse.cz>
 
index 8d378b823488e269a2352022709a6c1709999009..d8bb629d4bb7f812a33613852e1b6ded168bdf33 100644 (file)
@@ -177,7 +177,7 @@ enum c_tree_index
     CTI_MAX
 };
 
-#define C_RID_CODE(id) (((struct c_common_identifier *) (id))->rid_code)
+#define C_RID_CODE(id) (((struct c_common_identifier *) (id))->node.rid_code)
 
 /* Identifier part common to the C front ends.  Inherits from
    tree_identifier, despite appearances.  */
@@ -185,7 +185,6 @@ struct c_common_identifier
 {
   struct tree_common common;
   struct cpp_hashnode node;
-  ENUM_BITFIELD(rid) rid_code: CHAR_BIT;
 };
 
 #define wchar_type_node                        c_global_trees[CTI_WCHAR_TYPE]
index 5dac4774f57d8be813547667f6c456b3e4bdb09a..aa7e89f7f2a14c343bba86d88cad07f72cf47966 100644 (file)
@@ -4943,6 +4943,9 @@ static const char *constructor_asmspec;
 /* Nonzero if this is an initializer for a top-level decl.  */
 static int constructor_top_level;
 
+/* Nonzero if there were any member designators in this initializer.  */
+static int constructor_designated;
+
 /* Nesting depth of designator list.  */
 static int designator_depth;
 
@@ -4980,6 +4983,7 @@ struct constructor_stack
   char erroneous;
   char outer;
   char incremental;
+  char designated;
 };
 
 struct constructor_stack *constructor_stack;
@@ -5056,6 +5060,7 @@ start_init (decl, asmspec_tree, top_level)
   constructor_decl = decl;
   constructor_asmspec = asmspec;
   constructor_subconstants_deferred = 0;
+  constructor_designated = 0;
   constructor_top_level = top_level;
 
   if (decl != 0)
@@ -5165,6 +5170,7 @@ really_start_incremental_init (type)
   p->range_stack = 0;
   p->outer = 0;
   p->incremental = constructor_incremental;
+  p->designated = constructor_designated;
   p->next = 0;
   constructor_stack = p;
 
@@ -5175,6 +5181,7 @@ really_start_incremental_init (type)
   constructor_pending_elts = 0;
   constructor_type = type;
   constructor_incremental = 1;
+  constructor_designated = 0;
   designator_depth = 0;
   designator_errorneous = 0;
 
@@ -5276,6 +5283,7 @@ push_init_level (implicit)
   p->implicit = implicit;
   p->outer = 0;
   p->incremental = constructor_incremental;
+  p->designated = constructor_designated;
   p->next = constructor_stack;
   p->range_stack = 0;
   constructor_stack = p;
@@ -5285,6 +5293,7 @@ push_init_level (implicit)
   constructor_depth = SPELLING_DEPTH ();
   constructor_elements = 0;
   constructor_incremental = 1;
+  constructor_designated = 0;
   constructor_pending_elts = 0;
   if (!implicit)
     {
@@ -5465,7 +5474,9 @@ pop_init_level (implicit)
                   || integer_zerop (DECL_SIZE (constructor_unfilled_fields))))
          constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
 
-       if (constructor_unfilled_fields)
+       /* Do not warn if this level of the initializer uses member
+          designators; it is likely to be deliberate.  */
+       if (constructor_unfilled_fields && !constructor_designated)
          {
            push_member_name (constructor_unfilled_fields);
            warning_init ("missing initializer");
@@ -5531,6 +5542,7 @@ pop_init_level (implicit)
   constructor_simple = p->simple;
   constructor_erroneous = p->erroneous;
   constructor_incremental = p->incremental;
+  constructor_designated = p->designated;
   constructor_pending_elts = p->pending_elts;
   constructor_depth = p->depth;
   if (!p->implicit)
@@ -5577,6 +5589,7 @@ set_designator (array)
         braces.  */
       while (constructor_stack->implicit)
        process_init_element (pop_init_level (1));
+      constructor_designated = 1;
       return 0;
     }
 
@@ -5612,6 +5625,7 @@ set_designator (array)
       return 1;
     }
 
+  constructor_designated = 1;
   push_init_level (2);
   return 0;
 }
@@ -6589,8 +6603,12 @@ process_init_element (value)
             under the assumption that the zero initializer in user
             code appears conditioned on e.g. __STDC__ to avoid
             "missing initializer" warnings and relies on default
-            initialization to zero in the traditional C case.  */
-         if (warn_traditional && !in_system_header
+            initialization to zero in the traditional C case.
+            We also skip the warning if the initializer is designated,
+            again on the assumption that this must be conditional on
+            __STDC__ anyway (and we've already complained about the
+            member-designator already).  */
+         if (warn_traditional && !in_system_header && !constructor_designated
              && !(value && (integer_zerop (value) || real_zerop (value))))
            warning ("traditional C rejects initialization of unions");
 
index f298b2e37ef5e116820d973f9fb6ee3a0d53b479..a677ba5e467a3f47bf124842e2e9966345f32598 100644 (file)
@@ -1,3 +1,11 @@
+2001-10-24  Zack Weinberg  <zack@codesourcery.com>
+
+       * loadmsgcat.c (INTTYPE_SIGNED, INTTYPE_MINIMUM,
+       INTTYPE_MAXIMUM): Clone from system.h.
+       (_nl_load_domain): Use them when testing for overflow of size_t.
+       Cast result of sizeof to off_t to compare to st_size value.
+       Move side effects out of conditional for comprehensibility.
+
 2001-10-21  Zack Weinberg  <zack@codesourcery.com>
 
        * dcigettext.c: Don't use #elif.
index b6b13ff2cada2844f426737dd38e72ae2d26bd87..7055e52fadc9c3811800bce078ab7bd98fbb656e 100644 (file)
@@ -78,6 +78,15 @@ char *alloca ();
 # include "../locale/localeinfo.h"
 #endif
 
+/* GCC LOCAL: These macros are used below.  */
+/* The extra casts work around common compiler bugs.  */
+#define INTTYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
+   It is necessary at least when t == time_t.  */
+#define INTTYPE_MINIMUM(t) ((t) (INTTYPE_SIGNED (t) \
+                             ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
+#define INTTYPE_MAXIMUM(t) ((t) (~ (t) 0 - INTTYPE_MINIMUM (t)))
+
 /* @@ end of prolog @@ */
 
 #ifdef _LIBC
@@ -373,19 +382,23 @@ _nl_load_domain (domain_file, domainbinding)
     return;
 
   /* We must know about the size of the file.  */
+  /* GCC_LOCAL: Use INTTYPE_MAXIMUM for overflow check, cast sizeof to
+     off_t, move set of size below if.  */
   if (
 #ifdef _LIBC
       __builtin_expect (fstat64 (fd, &st) != 0, 0)
 #else
       __builtin_expect (fstat (fd, &st) != 0, 0)
 #endif
-      || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
-      || __builtin_expect (size < sizeof (struct mo_file_header), 0))
+      || __builtin_expect (st.st_size > INTTYPE_MAXIMUM (ssize_t), 0)
+      || __builtin_expect (st.st_size < (off_t) sizeof (struct mo_file_header),
+                          0))
     {
       /* Something went wrong.  */
       close (fd);
       return;
     }
+  size = (size_t) st.st_size;
 
 #ifdef HAVE_MMAP
   /* Now we are ready to load the file.  If mmap() is available we try
index 106e21ab9796fc0f287cac8d1c5f22aafc62f815..a4701cfd900b65f86854d96c5945e33e6beaa219 100644 (file)
@@ -1,3 +1,7 @@
+2001-10-24  Zack Weinberg  <zack@codesourcery.com>
+
+       * gcc.dg/20011021-1.c: New test.
+
 2001-10-24  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/compile/20011023-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/20011021-1.c b/gcc/testsuite/gcc.dg/20011021-1.c
new file mode 100644 (file)
index 0000000..821db47
--- /dev/null
@@ -0,0 +1,43 @@
+/* Test for various initializer warnings being suppressed by use of
+   designated initializers.  */
+
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -W -Wall -Wtraditional" } */
+
+
+struct t
+{
+  int a;
+  int b;
+  int c;
+};
+
+union u
+{
+  int n;
+  float i;
+};
+
+struct multilevel
+{
+   int x;
+   struct t t;
+   union u u;
+   union u v;
+   char *f;
+};
+
+struct t T0 = { 1 };           /* { dg-warning "(missing|near) init" } */
+struct t T1 = { .a = 1 };      /* { dg-bogus "(missing|near) init" } */
+
+union u U0 = { 1 };            /* { dg-warning "initialization of union" } */
+union u U1 = { .i = 1 };       /* { dg-bogus "initialization of union" } */
+
+struct multilevel M =
+{
+  12,
+  { .b = 3 },                  /* { dg-bogus "(missing|near) init" } */
+  { 4 },                       /* { dg-warning "initialization of union" } */
+  { .n = 9 },                  /* { dg-bogus "initialization of union" } */
+  /* "string here" */
+};                             /* { dg-warning "(missing|near) init" } */