OSDN Git Service

Update copyrights.
[pf3gnuchains/gcc-fork.git] / gcc / c-common.c
1 /* Subroutines shared by all languages that are variants of C.
2    Copyright (C) 1992, 93-98, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "tree.h"
24 #include "c-lex.h"
25 #include "c-tree.h"
26 #include "flags.h"
27 #include "obstack.h"
28 #include "toplev.h"
29 #include "output.h"
30 #include "c-pragma.h"
31 #include "rtl.h"
32
33 #if USE_CPPLIB
34 #include "cpplib.h"
35 cpp_reader  parse_in;
36 cpp_options parse_options;
37 static enum cpp_token cpp_token;
38 #endif
39
40 #ifndef WCHAR_TYPE_SIZE
41 #ifdef INT_TYPE_SIZE
42 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
43 #else
44 #define WCHAR_TYPE_SIZE BITS_PER_WORD
45 #endif
46 #endif
47
48 extern struct obstack permanent_obstack;
49
50 /* Nonzero means the expression being parsed will never be evaluated.
51    This is a count, since unevaluated expressions can nest.  */
52 int skip_evaluation;
53
54 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
55             A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
56             A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
57             A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS,
58             A_INIT_PRIORITY};
59
60 enum format_type { printf_format_type, scanf_format_type,
61                    strftime_format_type };
62
63 static void declare_hidden_char_array   PROTO((char *, char *));
64 static void add_attribute               PROTO((enum attrs, char *,
65                                                int, int, int));
66 static void init_attributes             PROTO((void));
67 static void record_function_format      PROTO((tree, tree, enum format_type,
68                                                int, int));
69 static void record_international_format PROTO((tree, tree, int));
70 static tree c_find_base_decl            PROTO((tree));
71
72 /* Keep a stack of if statements.  We record the number of compound
73    statements seen up to the if keyword, as well as the line number
74    and file of the if.  If a potentially ambiguous else is seen, that
75    fact is recorded; the warning is issued when we can be sure that
76    the enclosing if statement does not have an else branch.  */
77 typedef struct
78 {
79   int compstmt_count;
80   int line;
81   char *file;
82   int needs_warning;
83 } if_elt;
84
85 static if_elt *if_stack;
86
87 /* Amount of space in the if statement stack.  */
88 static int if_stack_space = 0;
89
90 /* Stack pointer.  */
91 static int if_stack_pointer = 0;
92
93 /* Generate RTL for the start of an if-then, and record the start of it
94    for ambiguous else detection.  */
95
96 /* A list of objects which have constructors or destructors which
97    reside in the global scope, and have an init_priority attribute
98    associated with them.  The decl is stored in the TREE_VALUE slot
99    and the priority number is stored in the TREE_PURPOSE slot.  */
100 tree static_aggregates_initp;
101
102 void
103 c_expand_start_cond (cond, exitflag, compstmt_count)
104      tree cond;
105      int exitflag;
106      int compstmt_count;
107 {
108   /* Make sure there is enough space on the stack.  */
109   if (if_stack_space == 0)
110     {
111       if_stack_space = 10;
112       if_stack = (if_elt *)xmalloc (10 * sizeof (if_elt));
113     }
114   else if (if_stack_space == if_stack_pointer)
115     {
116       if_stack_space += 10;
117       if_stack = (if_elt *)xrealloc (if_stack, if_stack_space * sizeof (if_elt));
118     }
119
120   /* Record this if statement.  */
121   if_stack[if_stack_pointer].compstmt_count = compstmt_count;
122   if_stack[if_stack_pointer].file = input_filename;
123   if_stack[if_stack_pointer].line = lineno;
124   if_stack[if_stack_pointer].needs_warning = 0;
125   if_stack_pointer++;
126
127   expand_start_cond (cond, exitflag);
128 }
129
130 /* Generate RTL for the end of an if-then.  Optionally warn if a nested
131    if statement had an ambiguous else clause.  */
132
133 void
134 c_expand_end_cond ()
135 {
136   if_stack_pointer--;
137   if (if_stack[if_stack_pointer].needs_warning)
138     warning_with_file_and_line (if_stack[if_stack_pointer].file,
139                                 if_stack[if_stack_pointer].line,
140                                 "suggest explicit braces to avoid ambiguous `else'");
141   expand_end_cond ();
142 }
143
144 /* Generate RTL between the then-clause and the else-clause
145    of an if-then-else.  */
146
147 void
148 c_expand_start_else ()
149 {
150   /* An ambiguous else warning must be generated for the enclosing if
151      statement, unless we see an else branch for that one, too.  */
152   if (warn_parentheses
153       && if_stack_pointer > 1
154       && (if_stack[if_stack_pointer - 1].compstmt_count
155           == if_stack[if_stack_pointer - 2].compstmt_count))
156     if_stack[if_stack_pointer - 2].needs_warning = 1;
157
158   /* Even if a nested if statement had an else branch, it can't be
159      ambiguous if this one also has an else.  So don't warn in that
160      case.  Also don't warn for any if statements nested in this else.  */
161   if_stack[if_stack_pointer - 1].needs_warning = 0;
162   if_stack[if_stack_pointer - 1].compstmt_count--;
163
164   expand_start_else ();
165 }
166
167 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__.  */
168
169 void
170 declare_function_name ()
171 {
172   char *name, *printable_name;
173
174   if (current_function_decl == NULL)
175     {
176       name = "";
177       printable_name = "top level";
178     }
179   else
180     {
181       /* Allow functions to be nameless (such as artificial ones).  */
182       if (DECL_NAME (current_function_decl))
183         name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
184       else
185         name = "";
186       printable_name = (*decl_printable_name) (current_function_decl, 2);
187     }
188
189   declare_hidden_char_array ("__FUNCTION__", name);
190   declare_hidden_char_array ("__PRETTY_FUNCTION__", printable_name);
191   /* The ISO C people "of course" couldn't use __FUNCTION__ in the
192      ISO C 9x standard; instead a new variable is invented.  */
193   declare_hidden_char_array ("__func__", name);
194 }
195
196 static void
197 declare_hidden_char_array (name, value)
198      char *name, *value;
199 {
200   tree decl, type, init;
201   int vlen;
202
203   /* If the default size of char arrays isn't big enough for the name,
204      or if we want to give warnings for large objects, make a bigger one.  */
205   vlen = strlen (value) + 1;
206   type = char_array_type_node;
207   if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < vlen
208       || warn_larger_than)
209     type = build_array_type (char_type_node,
210                              build_index_type (build_int_2 (vlen, 0)));
211   push_obstacks_nochange ();
212   decl = build_decl (VAR_DECL, get_identifier (name), type);
213   TREE_STATIC (decl) = 1;
214   TREE_READONLY (decl) = 1;
215   TREE_ASM_WRITTEN (decl) = 1;
216   DECL_SOURCE_LINE (decl) = 0;
217   DECL_ARTIFICIAL (decl) = 1;
218   DECL_IN_SYSTEM_HEADER (decl) = 1;
219   DECL_IGNORED_P (decl) = 1;
220   init = build_string (vlen, value);
221   TREE_TYPE (init) = type;
222   DECL_INITIAL (decl) = init;
223   finish_decl (pushdecl (decl), init, NULL_TREE);
224 }
225
226 /* Given a chain of STRING_CST nodes,
227    concatenate them into one STRING_CST
228    and give it a suitable array-of-chars data type.  */
229
230 tree
231 combine_strings (strings)
232      tree strings;
233 {
234   register tree value, t;
235   register int length = 1;
236   int wide_length = 0;
237   int wide_flag = 0;
238   int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
239   int nchars;
240
241   if (TREE_CHAIN (strings))
242     {
243       /* More than one in the chain, so concatenate.  */
244       register char *p, *q;
245
246       /* Don't include the \0 at the end of each substring,
247          except for the last one.
248          Count wide strings and ordinary strings separately.  */
249       for (t = strings; t; t = TREE_CHAIN (t))
250         {
251           if (TREE_TYPE (t) == wchar_array_type_node)
252             {
253               wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
254               wide_flag = 1;
255             }
256           else
257             length += (TREE_STRING_LENGTH (t) - 1);
258         }
259
260       /* If anything is wide, the non-wides will be converted,
261          which makes them take more space.  */
262       if (wide_flag)
263         length = length * wchar_bytes + wide_length;
264
265       p = savealloc (length);
266
267       /* Copy the individual strings into the new combined string.
268          If the combined string is wide, convert the chars to ints
269          for any individual strings that are not wide.  */
270
271       q = p;
272       for (t = strings; t; t = TREE_CHAIN (t))
273         {
274           int len = (TREE_STRING_LENGTH (t)
275                      - ((TREE_TYPE (t) == wchar_array_type_node)
276                         ? wchar_bytes : 1));
277           if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
278             {
279               memcpy (q, TREE_STRING_POINTER (t), len);
280               q += len;
281             }
282           else
283             {
284               int i;
285               for (i = 0; i < len; i++)
286                 {
287                   if (WCHAR_TYPE_SIZE == HOST_BITS_PER_SHORT)
288                     ((short *) q)[i] = TREE_STRING_POINTER (t)[i];
289                   else
290                     ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
291                 }
292               q += len * wchar_bytes;
293             }
294         }
295       if (wide_flag)
296         {
297           int i;
298           for (i = 0; i < wchar_bytes; i++)
299             *q++ = 0;
300         }
301       else
302         *q = 0;
303
304       value = make_node (STRING_CST);
305       TREE_STRING_POINTER (value) = p;
306       TREE_STRING_LENGTH (value) = length;
307     }
308   else
309     {
310       value = strings;
311       length = TREE_STRING_LENGTH (value);
312       if (TREE_TYPE (value) == wchar_array_type_node)
313         wide_flag = 1;
314     }
315
316   /* Compute the number of elements, for the array type.  */
317   nchars = wide_flag ? length / wchar_bytes : length;
318
319   /* Create the array type for the string constant.
320      -Wwrite-strings says make the string constant an array of const char
321      so that copying it to a non-const pointer will get a warning.
322      For C++, this is the standard behavior.  */
323   if (flag_const_strings
324       && (! flag_traditional  && ! flag_writable_strings))
325     {
326       tree elements
327         = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
328                               1, 0);
329       TREE_TYPE (value)
330         = build_array_type (elements,
331                             build_index_type (build_int_2 (nchars - 1, 0)));
332     }
333   else
334     TREE_TYPE (value)
335       = build_array_type (wide_flag ? wchar_type_node : char_type_node,
336                           build_index_type (build_int_2 (nchars - 1, 0)));
337
338   TREE_READONLY (value) = TREE_CONSTANT (value) = ! flag_writable_strings;
339   TREE_STATIC (value) = 1;
340   return value;
341 }
342 \f
343 /* To speed up processing of attributes, we maintain an array of
344    IDENTIFIER_NODES and the corresponding attribute types.  */
345
346 /* Array to hold attribute information.  */
347
348 static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50];
349
350 static int attrtab_idx = 0;
351
352 /* Add an entry to the attribute table above.  */
353
354 static void
355 add_attribute (id, string, min_len, max_len, decl_req)
356      enum attrs id;
357      char *string;
358      int min_len, max_len;
359      int decl_req;
360 {
361   char buf[100];
362
363   attrtab[attrtab_idx].id = id;
364   attrtab[attrtab_idx].name = get_identifier (string);
365   attrtab[attrtab_idx].min = min_len;
366   attrtab[attrtab_idx].max = max_len;
367   attrtab[attrtab_idx++].decl_req = decl_req;
368
369   sprintf (buf, "__%s__", string);
370
371   attrtab[attrtab_idx].id = id;
372   attrtab[attrtab_idx].name = get_identifier (buf);
373   attrtab[attrtab_idx].min = min_len;
374   attrtab[attrtab_idx].max = max_len;
375   attrtab[attrtab_idx++].decl_req = decl_req;
376 }
377
378 /* Initialize attribute table.  */
379
380 static void
381 init_attributes ()
382 {
383   add_attribute (A_PACKED, "packed", 0, 0, 0);
384   add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1);
385   add_attribute (A_COMMON, "common", 0, 0, 1);
386   add_attribute (A_NORETURN, "noreturn", 0, 0, 1);
387   add_attribute (A_NORETURN, "volatile", 0, 0, 1);
388   add_attribute (A_UNUSED, "unused", 0, 0, 0);
389   add_attribute (A_CONST, "const", 0, 0, 1);
390   add_attribute (A_T_UNION, "transparent_union", 0, 0, 0);
391   add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1);
392   add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1);
393   add_attribute (A_MODE, "mode", 1, 1, 1);
394   add_attribute (A_SECTION, "section", 1, 1, 1);
395   add_attribute (A_ALIGNED, "aligned", 0, 1, 0);
396   add_attribute (A_FORMAT, "format", 3, 3, 1);
397   add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1);
398   add_attribute (A_WEAK, "weak", 0, 0, 1);
399   add_attribute (A_ALIAS, "alias", 1, 1, 1);
400   add_attribute (A_INIT_PRIORITY, "init_priority", 0, 1, 0);
401   add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
402   add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
403 }
404 \f
405 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
406    and install them in NODE, which is either a DECL (including a TYPE_DECL)
407    or a TYPE.  PREFIX_ATTRIBUTES can appear after the declaration specifiers
408    and declaration modifiers but before the declaration proper.  */
409
410 void
411 decl_attributes (node, attributes, prefix_attributes)
412      tree node, attributes, prefix_attributes;
413 {
414   tree decl = 0, type = 0;
415   int is_type = 0;
416   tree a;
417
418   if (attrtab_idx == 0)
419     init_attributes ();
420
421   if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd')
422     {
423       decl = node;
424       type = TREE_TYPE (decl);
425       is_type = TREE_CODE (node) == TYPE_DECL;
426     }
427   else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't')
428     type = node, is_type = 1;
429
430 #ifdef PRAGMA_INSERT_ATTRIBUTES
431   /* If the code in c-pragma.c wants to insert some attributes then
432      allow it to do so.  Do this before allowing machine back ends to
433      insert attributes, so that they have the opportunity to override
434      anything done here.  */
435   PRAGMA_INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
436 #endif
437   
438 #ifdef INSERT_ATTRIBUTES
439   INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
440 #endif
441   
442   attributes = chainon (prefix_attributes, attributes);
443
444   for (a = attributes; a; a = TREE_CHAIN (a))
445     {
446       tree name = TREE_PURPOSE (a);
447       tree args = TREE_VALUE (a);
448       int i;
449       enum attrs id;
450
451       for (i = 0; i < attrtab_idx; i++)
452         if (attrtab[i].name == name)
453           break;
454
455       if (i == attrtab_idx)
456         {
457           if (! valid_machine_attribute (name, args, decl, type))
458             warning ("`%s' attribute directive ignored",
459                      IDENTIFIER_POINTER (name));
460           else if (decl != 0)
461             type = TREE_TYPE (decl);
462           continue;
463         }
464       else if (attrtab[i].decl_req && decl == 0)
465         {
466           warning ("`%s' attribute does not apply to types",
467                    IDENTIFIER_POINTER (name));
468           continue;
469         }
470       else if (list_length (args) < attrtab[i].min
471                || list_length (args) > attrtab[i].max)
472         {
473           error ("wrong number of arguments specified for `%s' attribute",
474                  IDENTIFIER_POINTER (name));
475           continue;
476         }
477
478       id = attrtab[i].id;
479       switch (id)
480         {
481         case A_PACKED:
482           if (is_type)
483             TYPE_PACKED (type) = 1;
484           else if (TREE_CODE (decl) == FIELD_DECL)
485             DECL_PACKED (decl) = 1;
486           /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
487              used for DECL_REGISTER.  It wouldn't mean anything anyway.  */
488           else
489             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
490           break;
491
492         case A_NOCOMMON:
493           if (TREE_CODE (decl) == VAR_DECL)
494             DECL_COMMON (decl) = 0;
495           else
496             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
497           break;
498
499         case A_COMMON:
500           if (TREE_CODE (decl) == VAR_DECL)
501             DECL_COMMON (decl) = 1;
502           else
503             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
504           break;
505
506         case A_NORETURN:
507           if (TREE_CODE (decl) == FUNCTION_DECL)
508             TREE_THIS_VOLATILE (decl) = 1;
509           else if (TREE_CODE (type) == POINTER_TYPE
510                    && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
511             TREE_TYPE (decl) = type
512               = build_pointer_type
513                 (build_type_variant (TREE_TYPE (type),
514                                      TREE_READONLY (TREE_TYPE (type)), 1));
515           else
516             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
517           break;
518
519         case A_UNUSED:
520           if (is_type)
521             TREE_USED (type) = 1;
522           else if (TREE_CODE (decl) == PARM_DECL
523                    || TREE_CODE (decl) == VAR_DECL
524                    || TREE_CODE (decl) == FUNCTION_DECL
525                    || TREE_CODE (decl) == LABEL_DECL)
526             TREE_USED (decl) = 1;
527           else
528             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
529           break;
530
531         case A_CONST:
532           if (TREE_CODE (decl) == FUNCTION_DECL)
533             TREE_READONLY (decl) = 1;
534           else if (TREE_CODE (type) == POINTER_TYPE
535                    && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
536             TREE_TYPE (decl) = type
537               = build_pointer_type
538                 (build_type_variant (TREE_TYPE (type), 1,
539                                      TREE_THIS_VOLATILE (TREE_TYPE (type))));
540           else
541             warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name));
542           break;
543
544         case A_T_UNION:
545           if (is_type
546               && TREE_CODE (type) == UNION_TYPE
547               && (decl == 0
548                   || (TYPE_FIELDS (type) != 0
549                       && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))))
550             TYPE_TRANSPARENT_UNION (type) = 1;
551           else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
552                    && TREE_CODE (type) == UNION_TYPE
553                    && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))
554             DECL_TRANSPARENT_UNION (decl) = 1;
555           else
556             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
557           break;
558
559         case A_CONSTRUCTOR:
560           if (TREE_CODE (decl) == FUNCTION_DECL
561               && TREE_CODE (type) == FUNCTION_TYPE
562               && decl_function_context (decl) == 0)
563             {
564               DECL_STATIC_CONSTRUCTOR (decl) = 1;
565               TREE_USED (decl) = 1;
566             }
567           else
568             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
569           break;
570
571         case A_DESTRUCTOR:
572           if (TREE_CODE (decl) == FUNCTION_DECL
573               && TREE_CODE (type) == FUNCTION_TYPE
574               && decl_function_context (decl) == 0)
575             {
576               DECL_STATIC_DESTRUCTOR (decl) = 1;
577               TREE_USED (decl) = 1;
578             }
579           else
580             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
581           break;
582
583         case A_MODE:
584           if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
585             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
586           else
587             {
588               int j;
589               char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
590               int len = strlen (p);
591               enum machine_mode mode = VOIDmode;
592               tree typefm;
593
594               if (len > 4 && p[0] == '_' && p[1] == '_'
595                   && p[len - 1] == '_' && p[len - 2] == '_')
596                 {
597                   char *newp = (char *) alloca (len - 1);
598
599                   strcpy (newp, &p[2]);
600                   newp[len - 4] = '\0';
601                   p = newp;
602                 }
603
604               /* Give this decl a type with the specified mode.
605                  First check for the special modes.  */
606               if (! strcmp (p, "byte"))
607                 mode = byte_mode;
608               else if (!strcmp (p, "word"))
609                 mode = word_mode;
610               else if (! strcmp (p, "pointer"))
611                 mode = ptr_mode;
612               else
613                 for (j = 0; j < NUM_MACHINE_MODES; j++)
614                   if (!strcmp (p, GET_MODE_NAME (j)))
615                     mode = (enum machine_mode) j;
616
617               if (mode == VOIDmode)
618                 error ("unknown machine mode `%s'", p);
619               else if (0 == (typefm = type_for_mode (mode,
620                                                      TREE_UNSIGNED (type))))
621                 error ("no data type for mode `%s'", p);
622               else
623                 {
624                   TREE_TYPE (decl) = type = typefm;
625                   DECL_SIZE (decl) = 0;
626                   layout_decl (decl, 0);
627                 }
628             }
629           break;
630
631         case A_SECTION:
632 #ifdef ASM_OUTPUT_SECTION_NAME
633           if ((TREE_CODE (decl) == FUNCTION_DECL
634                || TREE_CODE (decl) == VAR_DECL)
635               && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
636             {
637               if (TREE_CODE (decl) == VAR_DECL
638                   && current_function_decl != NULL_TREE
639                   && ! TREE_STATIC (decl))
640                 error_with_decl (decl,
641                   "section attribute cannot be specified for local variables");
642               /* The decl may have already been given a section attribute from
643                  a previous declaration.  Ensure they match.  */
644               else if (DECL_SECTION_NAME (decl) != NULL_TREE
645                        && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
646                                   TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
647                 error_with_decl (node,
648                                  "section of `%s' conflicts with previous declaration");
649               else
650                 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
651             }
652           else
653             error_with_decl (node,
654                            "section attribute not allowed for `%s'");
655 #else
656           error_with_decl (node,
657                   "section attributes are not supported for this target");
658 #endif
659           break;
660
661         case A_ALIGNED:
662           {
663             tree align_expr
664               = (args ? TREE_VALUE (args)
665                  : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
666             int align;
667             
668             /* Strip any NOPs of any kind.  */
669             while (TREE_CODE (align_expr) == NOP_EXPR
670                    || TREE_CODE (align_expr) == CONVERT_EXPR
671                    || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
672               align_expr = TREE_OPERAND (align_expr, 0);
673
674             if (TREE_CODE (align_expr) != INTEGER_CST)
675               {
676                 error ("requested alignment is not a constant");
677                 continue;
678               }
679
680             align = TREE_INT_CST_LOW (align_expr) * BITS_PER_UNIT;
681
682             if (exact_log2 (align) == -1)
683               error ("requested alignment is not a power of 2");
684             else if (is_type)
685               TYPE_ALIGN (type) = align;
686             else if (TREE_CODE (decl) != VAR_DECL
687                      && TREE_CODE (decl) != FIELD_DECL)
688               error_with_decl (decl,
689                                "alignment may not be specified for `%s'");
690             else
691               DECL_ALIGN (decl) = align;
692           }
693           break;
694
695         case A_FORMAT:
696           {
697             tree format_type_id = TREE_VALUE (args);
698             tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
699             tree first_arg_num_expr
700               = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
701             int format_num;
702             int first_arg_num;
703             enum format_type format_type;
704             tree argument;
705             int arg_num;
706
707             if (TREE_CODE (decl) != FUNCTION_DECL)
708               {
709                 error_with_decl (decl,
710                          "argument format specified for non-function `%s'");
711                 continue;
712               }
713         
714             if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
715               {
716                 error ("unrecognized format specifier");
717                 continue;
718               }
719             else
720               {
721                 char *p = IDENTIFIER_POINTER (format_type_id);
722                 
723                 if (!strcmp (p, "printf") || !strcmp (p, "__printf__"))
724                   format_type = printf_format_type;
725                 else if (!strcmp (p, "scanf") || !strcmp (p, "__scanf__"))
726                   format_type = scanf_format_type;
727                 else if (!strcmp (p, "strftime")
728                          || !strcmp (p, "__strftime__"))
729                   format_type = strftime_format_type;
730                 else
731                   {
732                     error ("`%s' is an unrecognized format function type", p);
733                     continue;
734                   }
735               }
736
737             /* Strip any conversions from the string index and first arg number
738                and verify they are constants.  */
739             while (TREE_CODE (format_num_expr) == NOP_EXPR
740                    || TREE_CODE (format_num_expr) == CONVERT_EXPR
741                    || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
742               format_num_expr = TREE_OPERAND (format_num_expr, 0);
743
744             while (TREE_CODE (first_arg_num_expr) == NOP_EXPR
745                    || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR
746                    || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR)
747               first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0);
748
749             if (TREE_CODE (format_num_expr) != INTEGER_CST
750                 || TREE_CODE (first_arg_num_expr) != INTEGER_CST)
751               {
752                 error ("format string has non-constant operand number");
753                 continue;
754               }
755
756             format_num = TREE_INT_CST_LOW (format_num_expr);
757             first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr);
758             if (first_arg_num != 0 && first_arg_num <= format_num)
759               {
760                 error ("format string arg follows the args to be formatted");
761                 continue;
762               }
763
764             /* If a parameter list is specified, verify that the format_num
765                argument is actually a string, in case the format attribute
766                is in error.  */
767             argument = TYPE_ARG_TYPES (type);
768             if (argument)
769               {
770                 for (arg_num = 1; ; ++arg_num)
771                   {
772                     if (argument == 0 || arg_num == format_num)
773                       break;
774                     argument = TREE_CHAIN (argument);
775                   }
776                 if (! argument
777                     || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
778                   || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
779                       != char_type_node))
780                   {
781                     error ("format string arg not a string type");
782                     continue;
783                   }
784                 if (first_arg_num != 0)
785                   {
786                     /* Verify that first_arg_num points to the last arg,
787                        the ...  */
788                     while (argument)
789                       arg_num++, argument = TREE_CHAIN (argument);
790                   if (arg_num != first_arg_num)
791                     {
792                       error ("args to be formatted is not ...");
793                       continue;
794                     }
795                   }
796               }
797
798             record_function_format (DECL_NAME (decl),
799                                     DECL_ASSEMBLER_NAME (decl),
800                                     format_type, format_num, first_arg_num);
801             break;
802           }
803
804         case A_FORMAT_ARG:
805           {
806             tree format_num_expr = TREE_VALUE (args);
807             int format_num, arg_num;
808             tree argument;
809
810             if (TREE_CODE (decl) != FUNCTION_DECL)
811               {
812                 error_with_decl (decl,
813                          "argument format specified for non-function `%s'");
814                 continue;
815               }
816
817             /* Strip any conversions from the first arg number and verify it
818                is a constant.  */
819             while (TREE_CODE (format_num_expr) == NOP_EXPR
820                    || TREE_CODE (format_num_expr) == CONVERT_EXPR
821                    || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
822               format_num_expr = TREE_OPERAND (format_num_expr, 0);
823
824             if (TREE_CODE (format_num_expr) != INTEGER_CST)
825               {
826                 error ("format string has non-constant operand number");
827                 continue;
828               }
829
830             format_num = TREE_INT_CST_LOW (format_num_expr);
831
832             /* If a parameter list is specified, verify that the format_num
833                argument is actually a string, in case the format attribute
834                is in error.  */
835             argument = TYPE_ARG_TYPES (type);
836             if (argument)
837               {
838                 for (arg_num = 1; ; ++arg_num)
839                   {
840                     if (argument == 0 || arg_num == format_num)
841                       break;
842                     argument = TREE_CHAIN (argument);
843                   }
844                 if (! argument
845                     || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
846                   || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
847                       != char_type_node))
848                   {
849                     error ("format string arg not a string type");
850                     continue;
851                   }
852               }
853
854             if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != POINTER_TYPE
855                 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl))))
856                     != char_type_node))
857               {
858                 error ("function does not return string type");
859                 continue;
860               }
861
862             record_international_format (DECL_NAME (decl),
863                                          DECL_ASSEMBLER_NAME (decl),
864                                          format_num);
865             break;
866           }
867
868         case A_WEAK:
869           declare_weak (decl);
870           break;
871
872         case A_ALIAS:
873           if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
874               || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
875             error_with_decl (decl,
876                              "`%s' defined both normally and as an alias");
877           else if (decl_function_context (decl) == 0)
878             {
879               tree id;
880
881               id = TREE_VALUE (args);
882               if (TREE_CODE (id) != STRING_CST)
883                 {
884                   error ("alias arg not a string");
885                   break;
886                 }
887               id = get_identifier (TREE_STRING_POINTER (id));
888
889               if (TREE_CODE (decl) == FUNCTION_DECL)
890                 DECL_INITIAL (decl) = error_mark_node;
891               else
892                 DECL_EXTERNAL (decl) = 0;
893               assemble_alias (decl, id);
894             }
895           else
896             warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
897           break;
898
899         case A_NO_CHECK_MEMORY_USAGE:
900           if (TREE_CODE (decl) != FUNCTION_DECL)
901             {
902               error_with_decl (decl,
903                                "`%s' attribute applies only to functions",
904                                IDENTIFIER_POINTER (name));
905             }
906           else if (DECL_INITIAL (decl))
907             {
908               error_with_decl (decl,
909                                "can't set `%s' attribute after definition",
910                                IDENTIFIER_POINTER (name));
911             }
912           else
913             DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
914           break;
915
916         case A_INIT_PRIORITY:
917           {
918             tree initp_expr = (args ? TREE_VALUE (args): NULL_TREE);
919             int pri;
920
921             if (initp_expr)
922               STRIP_NOPS (initp_expr);
923           
924             if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST)
925               {
926                 error ("requested init_priority is not an integer constant");
927                 continue;
928               }
929
930             pri = TREE_INT_CST_LOW (initp_expr);
931         
932             if (is_type || TREE_CODE (decl) != VAR_DECL
933                 || ! TREE_STATIC (decl)
934                 || DECL_EXTERNAL (decl)
935                 || (TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
936                     && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE)
937                 /* Static objects in functions are initialized the
938                    first time control passes through that
939                    function. This is not precise enough to pin down an
940                    init_priority value, so don't allow it. */
941                 || current_function_decl) 
942               {
943                 error ("can only use init_priority attribute on file-scope definitions of objects of class type");
944                 continue; 
945               }
946
947             /* Check for init_priorities that are reserved for
948                implementation. Reserved for language and runtime
949                support implementations.*/
950             if ((10 <= pri && pri <= 99)
951                 /* Reserved for standard library implementations. */
952                 || (500 <= pri && pri <= 999)
953                 /* Reserved for objects with no attributes. */
954                 || pri > (MAX_INIT_PRIORITY - 50))
955               {
956                 warning
957                   ("requested init_priority is reserved for internal use");
958                 continue;
959               }
960
961             if (pri > MAX_INIT_PRIORITY || pri <= 0)
962               {
963                 error ("requested init_priority is out of range");
964                 continue;
965               }
966
967             static_aggregates_initp
968               = perm_tree_cons (initp_expr, decl, static_aggregates_initp);
969             break;
970           }
971
972         case A_NO_INSTRUMENT_FUNCTION:
973           if (TREE_CODE (decl) != FUNCTION_DECL)
974             {
975               error_with_decl (decl,
976                                "`%s' attribute applies only to functions",
977                                IDENTIFIER_POINTER (name));
978             }
979           else if (DECL_INITIAL (decl))
980             {
981               error_with_decl (decl,
982                                "can't set `%s' attribute after definition",
983                                IDENTIFIER_POINTER (name));
984             }
985           else
986             DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
987           break;
988         }
989     }
990 }
991
992 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
993    lists.  SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
994
995    The head of the declspec list is stored in DECLSPECS.
996    The head of the attribute list is stored in PREFIX_ATTRIBUTES.
997
998    Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
999    the list elements.  We drop the containing TREE_LIST nodes and link the
1000    resulting attributes together the way decl_attributes expects them.  */
1001
1002 void
1003 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1004      tree specs_attrs;
1005      tree *declspecs, *prefix_attributes;
1006 {
1007   tree t, s, a, next, specs, attrs;
1008
1009   /* This can happen in c++ (eg: decl: typespec initdecls ';').  */
1010   if (specs_attrs != NULL_TREE
1011       && TREE_CODE (specs_attrs) != TREE_LIST)
1012     {
1013       *declspecs = specs_attrs;
1014       *prefix_attributes = NULL_TREE;
1015       return;
1016     }
1017
1018   /* Remember to keep the lists in the same order, element-wise.  */
1019
1020   specs = s = NULL_TREE;
1021   attrs = a = NULL_TREE;
1022   for (t = specs_attrs; t; t = next)
1023     {
1024       next = TREE_CHAIN (t);
1025       /* Declspecs have a non-NULL TREE_VALUE.  */
1026       if (TREE_VALUE (t) != NULL_TREE)
1027         {
1028           if (specs == NULL_TREE)
1029             specs = s = t;
1030           else
1031             {
1032               TREE_CHAIN (s) = t;
1033               s = t;
1034             }
1035         }
1036       else
1037         {
1038           if (attrs == NULL_TREE)
1039             attrs = a = TREE_PURPOSE (t);
1040           else
1041             {
1042               TREE_CHAIN (a) = TREE_PURPOSE (t);
1043               a = TREE_PURPOSE (t);
1044             }
1045           /* More attrs can be linked here, move A to the end.  */
1046           while (TREE_CHAIN (a) != NULL_TREE)
1047             a = TREE_CHAIN (a);
1048         }
1049     }
1050
1051   /* Terminate the lists.  */
1052   if (s != NULL_TREE)
1053     TREE_CHAIN (s) = NULL_TREE;
1054   if (a != NULL_TREE)
1055     TREE_CHAIN (a) = NULL_TREE;
1056
1057   /* All done.  */
1058   *declspecs = specs;
1059   *prefix_attributes = attrs;
1060 }
1061
1062 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1063    This function is used by the parser when a rule will accept attributes
1064    in a particular position, but we don't want to support that just yet.
1065
1066    A warning is issued for every ignored attribute.  */
1067
1068 tree
1069 strip_attrs (specs_attrs)
1070      tree specs_attrs;
1071 {
1072   tree specs, attrs;
1073
1074   split_specs_attrs (specs_attrs, &specs, &attrs);
1075
1076   while (attrs)
1077     {
1078       warning ("`%s' attribute ignored",
1079                IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1080       attrs = TREE_CHAIN (attrs);
1081     }
1082
1083   return specs;
1084 }
1085 \f
1086 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1087    a parameter list.  */
1088
1089 #define T_I     &integer_type_node
1090 #define T_L     &long_integer_type_node
1091 #define T_LL    &long_long_integer_type_node
1092 #define T_S     &short_integer_type_node
1093 #define T_UI    &unsigned_type_node
1094 #define T_UL    &long_unsigned_type_node
1095 #define T_ULL   &long_long_unsigned_type_node
1096 #define T_US    &short_unsigned_type_node
1097 #define T_F     &float_type_node
1098 #define T_D     &double_type_node
1099 #define T_LD    &long_double_type_node
1100 #define T_C     &char_type_node
1101 #define T_UC    &unsigned_char_type_node
1102 #define T_V     &void_type_node
1103 #define T_W     &wchar_type_node
1104 #define T_ST    &sizetype
1105
1106 typedef struct {
1107   char *format_chars;
1108   int pointer_count;
1109   /* Type of argument if no length modifier is used.  */
1110   tree *nolen;
1111   /* Type of argument if length modifier for shortening to byte is used.
1112      If NULL, then this modifier is not allowed.  */
1113   tree *hhlen;
1114   /* Type of argument if length modifier for shortening is used.
1115      If NULL, then this modifier is not allowed.  */
1116   tree *hlen;
1117   /* Type of argument if length modifier `l' is used.
1118      If NULL, then this modifier is not allowed.  */
1119   tree *llen;
1120   /* Type of argument if length modifier `q' or `ll' is used.
1121      If NULL, then this modifier is not allowed.  */
1122   tree *qlen;
1123   /* Type of argument if length modifier `L' is used.
1124      If NULL, then this modifier is not allowed.  */
1125   tree *bigllen;
1126   /* Type of argument if length modifier `Z' is used.
1127      If NULL, then this modifier is not allowed.  */
1128   tree *zlen;
1129   /* List of other modifier characters allowed with these options.  */
1130   char *flag_chars;
1131 } format_char_info;
1132
1133 static format_char_info print_char_table[] = {
1134   { "di",       0,      T_I,    T_I,    T_I,    T_L,    T_LL,   T_LL,   T_ST,   "-wp0 +"        },
1135   { "oxX",      0,      T_UI,   T_UI,   T_UI,   T_UL,   T_ULL,  T_ULL,  T_ST,   "-wp0#"         },
1136   { "u",        0,      T_UI,   T_UI,   T_UI,   T_UL,   T_ULL,  T_ULL,  T_ST,   "-wp0"          },
1137 /* A GNU extension.  */
1138   { "m",        0,      T_V,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "-wp"           },
1139   { "feEgGaA",  0,      T_D,    NULL,   NULL,   NULL,   NULL,   T_LD,   NULL,   "-wp0 +#"       },
1140   { "c",        0,      T_I,    NULL,   NULL,   T_W,    NULL,   NULL,   NULL,   "-w"            },
1141   { "C",        0,      T_W,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "-w"            },
1142   { "s",        1,      T_C,    NULL,   NULL,   T_W,    NULL,   NULL,   NULL,   "-wp"           },
1143   { "S",        1,      T_W,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "-wp"           },
1144   { "p",        1,      T_V,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "-w"            },
1145   { "n",        1,      T_I,    NULL,   T_S,    T_L,    T_LL,   NULL,   NULL,   ""              },
1146   { NULL,       0,      NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL            }
1147 };
1148
1149 static format_char_info scan_char_table[] = {
1150   { "di",       1,      T_I,    T_C,    T_S,    T_L,    T_LL,   T_LL,   NULL,   "*"     },
1151   { "ouxX",     1,      T_UI,   T_UC,   T_US,   T_UL,   T_ULL,  T_ULL,  NULL,   "*"     },
1152   { "efgEGaA",  1,      T_F,    NULL,   NULL,   T_D,    NULL,   T_LD,   NULL,   "*"     },
1153   { "c",        1,      T_C,    NULL,   NULL,   T_W,    NULL,   NULL,   NULL,   "*"     },
1154   { "s",        1,      T_C,    NULL,   NULL,   T_W,    NULL,   NULL,   NULL,   "*a"    },
1155   { "[",        1,      T_C,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "*a"    },
1156   { "C",        1,      T_W,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "*"     },
1157   { "S",        1,      T_W,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "*a"    },
1158   { "p",        2,      T_V,    NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   "*"     },
1159   { "n",        1,      T_I,    T_C,    T_S,    T_L,    T_LL,   NULL,   NULL,   ""      },
1160   { NULL,       0,      NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL    }
1161 };
1162
1163 /* Handle format characters recognized by glibc's strftime.c.
1164    '2' - MUST do years as only two digits
1165    '3' - MAY do years as only two digits (depending on locale)
1166    'E' - E modifier is acceptable
1167    'O' - O modifier is acceptable to Standard C
1168    'o' - O modifier is acceptable as a GNU extension
1169    'G' - other GNU extensions  */
1170
1171 static format_char_info time_char_table[] = {
1172   { "y",                0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2EO-_0w" },
1173   { "D",                0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2" },
1174   { "g",                0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2O-_0w" },
1175   { "cx",               0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "3E" },
1176   { "%RTXnrt",          0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "" },
1177   { "P",                0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "G" },
1178   { "HIMSUWdemw",       0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Ow" },
1179   { "Vju",              0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow" },
1180   { "Gklsz",            0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0OGw" },
1181   { "ABZa",             0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^#" },
1182   { "p",                0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "#" },
1183   { "bh",               0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^" },
1184   { "CY",               0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0EOw" },
1185   { NULL,               0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1186 };
1187
1188 typedef struct function_format_info
1189 {
1190   struct function_format_info *next;  /* next structure on the list */
1191   tree name;                    /* identifier such as "printf" */
1192   tree assembler_name;          /* optional mangled identifier (for C++) */
1193   enum format_type format_type; /* type of format (printf, scanf, etc.) */
1194   int format_num;               /* number of format argument */
1195   int first_arg_num;            /* number of first arg (zero for varargs) */
1196 } function_format_info;
1197
1198 static function_format_info *function_format_list = NULL;
1199
1200 typedef struct international_format_info
1201 {
1202   struct international_format_info *next;  /* next structure on the list */
1203   tree name;                    /* identifier such as "gettext" */
1204   tree assembler_name;          /* optional mangled identifier (for C++) */
1205   int format_num;               /* number of format argument */
1206 } international_format_info;
1207
1208 static international_format_info *international_format_list = NULL;
1209
1210 static void check_format_info           PROTO((function_format_info *, tree));
1211
1212 /* Initialize the table of functions to perform format checking on.
1213    The ANSI functions are always checked (whether <stdio.h> is
1214    included or not), since it is common to call printf without
1215    including <stdio.h>.  There shouldn't be a problem with this,
1216    since ANSI reserves these function names whether you include the
1217    header file or not.  In any case, the checking is harmless.
1218
1219    Also initialize the name of function that modify the format string for
1220    internationalization purposes.  */
1221
1222 void
1223 init_function_format_info ()
1224 {
1225   record_function_format (get_identifier ("printf"), NULL_TREE,
1226                           printf_format_type, 1, 2);
1227   record_function_format (get_identifier ("fprintf"), NULL_TREE,
1228                           printf_format_type, 2, 3);
1229   record_function_format (get_identifier ("sprintf"), NULL_TREE,
1230                           printf_format_type, 2, 3);
1231   record_function_format (get_identifier ("scanf"), NULL_TREE,
1232                           scanf_format_type, 1, 2);
1233   record_function_format (get_identifier ("fscanf"), NULL_TREE,
1234                           scanf_format_type, 2, 3);
1235   record_function_format (get_identifier ("sscanf"), NULL_TREE,
1236                           scanf_format_type, 2, 3);
1237   record_function_format (get_identifier ("vprintf"), NULL_TREE,
1238                           printf_format_type, 1, 0);
1239   record_function_format (get_identifier ("vfprintf"), NULL_TREE,
1240                           printf_format_type, 2, 0);
1241   record_function_format (get_identifier ("vsprintf"), NULL_TREE,
1242                           printf_format_type, 2, 0);
1243   record_function_format (get_identifier ("strftime"), NULL_TREE,
1244                           strftime_format_type, 3, 0);
1245
1246   record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
1247   record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
1248   record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
1249 }
1250
1251 /* Record information for argument format checking.  FUNCTION_IDENT is
1252    the identifier node for the name of the function to check (its decl
1253    need not exist yet).
1254    FORMAT_TYPE specifies the type of format checking.  FORMAT_NUM is the number
1255    of the argument which is the format control string (starting from 1).
1256    FIRST_ARG_NUM is the number of the first actual argument to check
1257    against the format string, or zero if no checking is not be done
1258    (e.g. for varargs such as vfprintf).  */
1259
1260 static void
1261 record_function_format (name, assembler_name, format_type,
1262                         format_num, first_arg_num)
1263       tree name;
1264       tree assembler_name;
1265       enum format_type format_type;
1266       int format_num;
1267       int first_arg_num;
1268 {
1269   function_format_info *info;
1270
1271   /* Re-use existing structure if it's there.  */
1272
1273   for (info = function_format_list; info; info = info->next)
1274     {
1275       if (info->name == name && info->assembler_name == assembler_name)
1276         break;
1277     }
1278   if (! info)
1279     {
1280       info = (function_format_info *) xmalloc (sizeof (function_format_info));
1281       info->next = function_format_list;
1282       function_format_list = info;
1283
1284       info->name = name;
1285       info->assembler_name = assembler_name;
1286     }
1287
1288   info->format_type = format_type;
1289   info->format_num = format_num;
1290   info->first_arg_num = first_arg_num;
1291 }
1292
1293 /* Record information for the names of function that modify the format
1294    argument to format functions.  FUNCTION_IDENT is the identifier node for
1295    the name of the function (its decl need not exist yet) and FORMAT_NUM is
1296    the number of the argument which is the format control string (starting
1297    from 1).  */
1298
1299 static void
1300 record_international_format (name, assembler_name, format_num)
1301       tree name;
1302       tree assembler_name;
1303       int format_num;
1304 {
1305   international_format_info *info;
1306
1307   /* Re-use existing structure if it's there.  */
1308
1309   for (info = international_format_list; info; info = info->next)
1310     {
1311       if (info->name == name && info->assembler_name == assembler_name)
1312         break;
1313     }
1314
1315   if (! info)
1316     {
1317       info
1318         = (international_format_info *)
1319           xmalloc (sizeof (international_format_info));
1320       info->next = international_format_list;
1321       international_format_list = info;
1322
1323       info->name = name;
1324       info->assembler_name = assembler_name;
1325     }
1326
1327   info->format_num = format_num;
1328 }
1329
1330 static char     tfaff[] = "too few arguments for format";
1331 \f
1332 /* Check the argument list of a call to printf, scanf, etc.
1333    NAME is the function identifier.
1334    ASSEMBLER_NAME is the function's assembler identifier.
1335    (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1336    PARAMS is the list of argument values.  */
1337
1338 void
1339 check_function_format (name, assembler_name, params)
1340      tree name;
1341      tree assembler_name;
1342      tree params;
1343 {
1344   function_format_info *info;
1345
1346   /* See if this function is a format function.  */
1347   for (info = function_format_list; info; info = info->next)
1348     {
1349       if (info->assembler_name
1350           ? (info->assembler_name == assembler_name)
1351           : (info->name == name))
1352         {
1353           /* Yup; check it.  */
1354           check_format_info (info, params);
1355           break;
1356         }
1357     }
1358 }
1359
1360 /* Check the argument list of a call to printf, scanf, etc.
1361    INFO points to the function_format_info structure.
1362    PARAMS is the list of argument values.  */
1363
1364 static void
1365 check_format_info (info, params)
1366      function_format_info *info;
1367      tree params;
1368 {
1369   int i;
1370   int arg_num;
1371   int suppressed, wide, precise;
1372   int length_char = 0;
1373   int format_char;
1374   int format_length;
1375   tree format_tree;
1376   tree cur_param;
1377   tree cur_type;
1378   tree wanted_type;
1379   tree first_fillin_param;
1380   char *format_chars;
1381   format_char_info *fci = NULL;
1382   char flag_chars[8];
1383   int has_operand_number = 0;
1384
1385   /* Skip to format argument.  If the argument isn't available, there's
1386      no work for us to do; prototype checking will catch the problem.  */
1387   for (arg_num = 1; ; ++arg_num)
1388     {
1389       if (params == 0)
1390         return;
1391       if (arg_num == info->format_num)
1392         break;
1393       params = TREE_CHAIN (params);
1394     }
1395   format_tree = TREE_VALUE (params);
1396   params = TREE_CHAIN (params);
1397   if (format_tree == 0)
1398     return;
1399
1400   /* We can only check the format if it's a string constant.  */
1401   while (TREE_CODE (format_tree) == NOP_EXPR)
1402     format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
1403
1404   if (TREE_CODE (format_tree) == CALL_EXPR
1405       && TREE_CODE (TREE_OPERAND (format_tree, 0)) == ADDR_EXPR
1406       && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0))
1407           == FUNCTION_DECL))
1408     {
1409       tree function = TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0);
1410
1411       /* See if this is a call to a known internationalization function
1412          that modifies the format arg.  */
1413       international_format_info *info;
1414
1415       for (info = international_format_list; info; info = info->next)
1416         if (info->assembler_name
1417             ? (info->assembler_name == DECL_ASSEMBLER_NAME (function))
1418             : (info->name == DECL_NAME (function)))
1419           {
1420             tree inner_args;
1421             int i;
1422
1423             for (inner_args = TREE_OPERAND (format_tree, 1), i = 1;
1424                  inner_args != 0;
1425                  inner_args = TREE_CHAIN (inner_args), i++)
1426               if (i == info->format_num)
1427                 {
1428                   format_tree = TREE_VALUE (inner_args);
1429
1430                   while (TREE_CODE (format_tree) == NOP_EXPR)
1431                     format_tree = TREE_OPERAND (format_tree, 0);
1432                 }
1433           }
1434     }
1435
1436   if (integer_zerop (format_tree))
1437     {
1438       warning ("null format string");
1439       return;
1440     }
1441   if (TREE_CODE (format_tree) != ADDR_EXPR)
1442     return;
1443   format_tree = TREE_OPERAND (format_tree, 0);
1444   if (TREE_CODE (format_tree) != STRING_CST)
1445     return;
1446   format_chars = TREE_STRING_POINTER (format_tree);
1447   format_length = TREE_STRING_LENGTH (format_tree);
1448   if (format_length <= 1)
1449     warning ("zero-length format string");
1450   if (format_chars[--format_length] != 0)
1451     {
1452       warning ("unterminated format string");
1453       return;
1454     }
1455   /* Skip to first argument to check.  */
1456   while (arg_num + 1 < info->first_arg_num)
1457     {
1458       if (params == 0)
1459         return;
1460       params = TREE_CHAIN (params);
1461       ++arg_num;
1462     }
1463
1464   first_fillin_param = params;
1465   while (1)
1466     {
1467       int aflag;
1468       if (*format_chars == 0)
1469         {
1470           if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
1471             warning ("embedded `\\0' in format");
1472           if (info->first_arg_num != 0 && params != 0 && ! has_operand_number)
1473             warning ("too many arguments for format");
1474           return;
1475         }
1476       if (*format_chars++ != '%')
1477         continue;
1478       if (*format_chars == 0)
1479         {
1480           warning ("spurious trailing `%%' in format");
1481           continue;
1482         }
1483       if (*format_chars == '%')
1484         {
1485           ++format_chars;
1486           continue;
1487         }
1488       flag_chars[0] = 0;
1489       suppressed = wide = precise = FALSE;
1490       if (info->format_type == scanf_format_type)
1491         {
1492           suppressed = *format_chars == '*';
1493           if (suppressed)
1494             ++format_chars;
1495           while (ISDIGIT (*format_chars))
1496             ++format_chars;
1497         }
1498       else if (info->format_type == strftime_format_type)
1499         {
1500           while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0)
1501             {
1502               if (pedantic)
1503                 warning ("ANSI C does not support the strftime `%c' flag",
1504                          *format_chars);
1505               if (index (flag_chars, *format_chars) != 0)
1506                 {
1507                   warning ("repeated `%c' flag in format",
1508                            *format_chars);
1509                   ++format_chars;
1510                 }
1511               else
1512                 {
1513                   i = strlen (flag_chars);
1514                   flag_chars[i++] = *format_chars++;
1515                   flag_chars[i] = 0;
1516                 }
1517             }
1518           while (ISDIGIT ((unsigned char) *format_chars))
1519             {
1520               wide = TRUE;
1521               ++format_chars;
1522             }
1523           if (wide && pedantic)
1524             warning ("ANSI C does not support strftime format width");
1525           if (*format_chars == 'E' || *format_chars == 'O')
1526             {
1527               i = strlen (flag_chars);
1528               flag_chars[i++] = *format_chars++;
1529               flag_chars[i] = 0;
1530               if (*format_chars == 'E' || *format_chars == 'O')
1531                 {
1532                   warning ("multiple E/O modifiers in format");
1533                   while (*format_chars == 'E' || *format_chars == 'O')
1534                     ++format_chars;
1535                 }
1536             }
1537         }
1538       else if (info->format_type == printf_format_type)
1539         {
1540           /* See if we have a number followed by a dollar sign.  If we do,
1541              it is an operand number, so set PARAMS to that operand.  */
1542           if (*format_chars >= '0' && *format_chars <= '9')
1543             {
1544               char *p = format_chars;
1545
1546               while (*p >= '0' && *p++ <= '9')
1547                 ;
1548
1549               if (*p == '$')
1550                 {
1551                   int opnum = atoi (format_chars);
1552
1553                   params = first_fillin_param;
1554                   format_chars = p + 1;
1555                   has_operand_number = 1;
1556
1557                   for (i = 1; i < opnum && params != 0; i++)
1558                     params = TREE_CHAIN (params);
1559
1560                   if (opnum == 0 || params == 0)
1561                     {
1562                       warning ("operand number out of range in format");
1563                       return;
1564                     }
1565                 }
1566             }
1567
1568           while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
1569             {
1570               if (index (flag_chars, *format_chars) != 0)
1571                 warning ("repeated `%c' flag in format", *format_chars++);
1572               else
1573                 {
1574                   i = strlen (flag_chars);
1575                   flag_chars[i++] = *format_chars++;
1576                   flag_chars[i] = 0;
1577                 }
1578             }
1579           /* "If the space and + flags both appear,
1580              the space flag will be ignored."  */
1581           if (index (flag_chars, ' ') != 0
1582               && index (flag_chars, '+') != 0)
1583             warning ("use of both ` ' and `+' flags in format");
1584           /* "If the 0 and - flags both appear,
1585              the 0 flag will be ignored."  */
1586           if (index (flag_chars, '0') != 0
1587               && index (flag_chars, '-') != 0)
1588             warning ("use of both `0' and `-' flags in format");
1589           if (*format_chars == '*')
1590             {
1591               wide = TRUE;
1592               /* "...a field width...may be indicated by an asterisk.
1593                  In this case, an int argument supplies the field width..."  */
1594               ++format_chars;
1595               if (params == 0)
1596                 {
1597                   warning (tfaff);
1598                   return;
1599                 }
1600               if (info->first_arg_num != 0)
1601                 {
1602                   cur_param = TREE_VALUE (params);
1603                   params = TREE_CHAIN (params);
1604                   ++arg_num;
1605                   /* size_t is generally not valid here.
1606                      It will work on most machines, because size_t and int
1607                      have the same mode.  But might as well warn anyway,
1608                      since it will fail on other machines.  */
1609                   if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1610                        != integer_type_node)
1611                       &&
1612                       (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1613                        != unsigned_type_node))
1614                     warning ("field width is not type int (arg %d)", arg_num);
1615                 }
1616             }
1617           else
1618             {
1619               while (ISDIGIT (*format_chars))
1620                 {
1621                   wide = TRUE;
1622                   ++format_chars;
1623                 }
1624             }
1625           if (*format_chars == '.')
1626             {
1627               precise = TRUE;
1628               ++format_chars;
1629               if (*format_chars != '*' && !ISDIGIT (*format_chars))
1630                 warning ("`.' not followed by `*' or digit in format");
1631               /* "...a...precision...may be indicated by an asterisk.
1632                  In this case, an int argument supplies the...precision."  */
1633               if (*format_chars == '*')
1634                 {
1635                   if (info->first_arg_num != 0)
1636                     {
1637                       ++format_chars;
1638                       if (params == 0)
1639                         {
1640                           warning (tfaff);
1641                           return;
1642                         }
1643                       cur_param = TREE_VALUE (params);
1644                       params = TREE_CHAIN (params);
1645                       ++arg_num;
1646                       if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1647                           != integer_type_node)
1648                         warning ("field width is not type int (arg %d)",
1649                                  arg_num);
1650                     }
1651                 }
1652               else
1653                 {
1654                   while (ISDIGIT (*format_chars))
1655                     ++format_chars;
1656                 }
1657             }
1658         }
1659
1660       aflag = 0;
1661
1662       if (info->format_type != strftime_format_type)
1663         {
1664           if (*format_chars == 'h' || *format_chars == 'l')
1665             length_char = *format_chars++;
1666           else if (*format_chars == 'q' || *format_chars == 'L')
1667             {
1668               length_char = *format_chars++;
1669               if (pedantic)
1670                 warning ("ANSI C does not support the `%c' length modifier",
1671                          length_char);
1672             }
1673           else if (*format_chars == 'Z')
1674             {
1675               length_char = *format_chars++;
1676               if (pedantic)
1677                 warning ("ANSI C does not support the `Z' length modifier");
1678             }
1679           else
1680             length_char = 0;
1681           if (length_char == 'l' && *format_chars == 'l')
1682             {
1683               length_char = 'q', format_chars++;
1684               /* FIXME: Is allowed in ISO C 9x.  */
1685               if (pedantic)
1686                 warning ("ANSI C does not support the `ll' length modifier");
1687             }
1688           else if (length_char == 'h' && *format_chars == 'h')
1689             {
1690               length_char = 'H', format_chars++;
1691               /* FIXME: Is allowed in ISO C 9x.  */
1692               if (pedantic)
1693                 warning ("ANSI C does not support the `hh' length modifier");
1694             }
1695           if (*format_chars == 'a' && info->format_type == scanf_format_type)
1696             {
1697               if (format_chars[1] == 's' || format_chars[1] == 'S'
1698                   || format_chars[1] == '[')
1699                 {
1700                   /* `a' is used as a flag.  */
1701                   aflag = 1;
1702                   format_chars++;
1703                 }
1704             }
1705           if (suppressed && length_char != 0)
1706             warning ("use of `*' and `%c' together in format", length_char);
1707         }
1708       format_char = *format_chars;
1709       if (format_char == 0
1710           || (info->format_type != strftime_format_type && format_char == '%'))
1711         {
1712           warning ("conversion lacks type at end of format");
1713           continue;
1714         }
1715       /* The m, C, and S formats are GNU extensions.  */
1716       if (pedantic && info->format_type != strftime_format_type
1717           && (format_char == 'm' || format_char == 'C' || format_char == 'S'))
1718         warning ("ANSI C does not support the `%c' format", format_char);
1719       /* ??? The a and A formats are C9X extensions, and should be allowed
1720          when a C9X option is added.  */
1721       if (pedantic && info->format_type != strftime_format_type
1722           && (format_char == 'a' || format_char == 'A'))
1723         warning ("ANSI C does not support the `%c' format", format_char);
1724       format_chars++;
1725       switch (info->format_type)
1726         {
1727         case printf_format_type:
1728           fci = print_char_table;
1729           break;
1730         case scanf_format_type:
1731           fci = scan_char_table;
1732           break;
1733         case strftime_format_type:
1734           fci = time_char_table;
1735           break;
1736         default:
1737           abort ();
1738         }
1739       while (fci->format_chars != 0
1740              && index (fci->format_chars, format_char) == 0)
1741           ++fci;
1742       if (fci->format_chars == 0)
1743         {
1744           if (format_char >= 040 && format_char < 0177)
1745             warning ("unknown conversion type character `%c' in format",
1746                      format_char);
1747           else
1748             warning ("unknown conversion type character 0x%x in format",
1749                      format_char);
1750           continue;
1751         }
1752       if (pedantic)
1753         {
1754           if (index (fci->flag_chars, 'G') != 0)
1755             warning ("ANSI C does not support `%%%c'", format_char);
1756           if (index (fci->flag_chars, 'o') != 0
1757               && index (flag_chars, 'O') != 0)
1758             warning ("ANSI C does not support `%%O%c'", format_char);
1759         }
1760       if (wide && index (fci->flag_chars, 'w') == 0)
1761         warning ("width used with `%c' format", format_char);
1762       if (index (fci->flag_chars, '2') != 0)
1763         warning ("`%%%c' yields only last 2 digits of year", format_char);
1764       else if (index (fci->flag_chars, '3') != 0)
1765         warning ("`%%%c' yields only last 2 digits of year in some locales",
1766                  format_char);
1767       if (precise && index (fci->flag_chars, 'p') == 0)
1768         warning ("precision used with `%c' format", format_char);
1769       if (aflag && index (fci->flag_chars, 'a') == 0)
1770         {
1771           warning ("`a' flag used with `%c' format", format_char);
1772           /* To simplify the following code.  */
1773           aflag = 0;
1774         }
1775       /* The a flag is a GNU extension.  */
1776       else if (pedantic && aflag)
1777         warning ("ANSI C does not support the `a' flag");
1778       if (info->format_type == scanf_format_type && format_char == '[')
1779         {
1780           /* Skip over scan set, in case it happens to have '%' in it.  */
1781           if (*format_chars == '^')
1782             ++format_chars;
1783           /* Find closing bracket; if one is hit immediately, then
1784              it's part of the scan set rather than a terminator.  */
1785           if (*format_chars == ']')
1786             ++format_chars;
1787           while (*format_chars && *format_chars != ']')
1788             ++format_chars;
1789           if (*format_chars != ']')
1790             /* The end of the format string was reached.  */
1791             warning ("no closing `]' for `%%[' format");
1792         }
1793       if (suppressed)
1794         {
1795           if (index (fci->flag_chars, '*') == 0)
1796             warning ("suppression of `%c' conversion in format", format_char);
1797           continue;
1798         }
1799       for (i = 0; flag_chars[i] != 0; ++i)
1800         {
1801           if (index (fci->flag_chars, flag_chars[i]) == 0)
1802             warning ("flag `%c' used with type `%c'",
1803                      flag_chars[i], format_char);
1804         }
1805       if (info->format_type == strftime_format_type)
1806         continue;
1807       if (precise && index (flag_chars, '0') != 0
1808           && (format_char == 'd' || format_char == 'i'
1809               || format_char == 'o' || format_char == 'u'
1810               || format_char == 'x' || format_char == 'X'))
1811         warning ("`0' flag ignored with precision specifier and `%c' format",
1812                  format_char);
1813       switch (length_char)
1814         {
1815         default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
1816         case 'H': wanted_type = fci->hhlen ? *(fci->hhlen) : 0; break;
1817         case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
1818         case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
1819         case 'q': wanted_type = fci->qlen ? *(fci->qlen) : 0; break;
1820         case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
1821         case 'Z': wanted_type = fci->zlen ? *fci->zlen : 0; break;
1822         }
1823       if (wanted_type == 0)
1824         warning ("use of `%c' length character with `%c' type character",
1825                  length_char, format_char);
1826
1827       /* Finally. . .check type of argument against desired type!  */
1828       if (info->first_arg_num == 0)
1829         continue;
1830       if (fci->pointer_count == 0 && wanted_type == void_type_node)
1831         /* This specifier takes no argument.  */
1832         continue;
1833       if (params == 0)
1834         {
1835           warning (tfaff);
1836           return;
1837         }
1838       cur_param = TREE_VALUE (params);
1839       params = TREE_CHAIN (params);
1840       ++arg_num;
1841       cur_type = TREE_TYPE (cur_param);
1842
1843       STRIP_NOPS (cur_param);
1844
1845       /* Check the types of any additional pointer arguments
1846          that precede the "real" argument.  */
1847       for (i = 0; i < fci->pointer_count + aflag; ++i)
1848         {
1849           if (TREE_CODE (cur_type) == POINTER_TYPE)
1850             {
1851               cur_type = TREE_TYPE (cur_type);
1852
1853               if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
1854                 cur_param = TREE_OPERAND (cur_param, 0);
1855               else
1856                 cur_param = 0;
1857
1858               continue;
1859             }
1860           if (TREE_CODE (cur_type) != ERROR_MARK)
1861             warning ("format argument is not a %s (arg %d)",
1862                      ((fci->pointer_count + aflag == 1)
1863                       ? "pointer" : "pointer to a pointer"),
1864                      arg_num);
1865           break;
1866         }
1867
1868       /* See if this is an attempt to write into a const type with
1869          scanf or with printf "%n".  */
1870       if ((info->format_type == scanf_format_type
1871            || (info->format_type == printf_format_type
1872                && format_char == 'n'))
1873           && i == fci->pointer_count + aflag
1874           && wanted_type != 0
1875           && TREE_CODE (cur_type) != ERROR_MARK
1876           && (TYPE_READONLY (cur_type)
1877               || (cur_param != 0
1878                   && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
1879                       || (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'd'
1880                           && TREE_READONLY (cur_param))))))
1881         warning ("writing into constant object (arg %d)", arg_num);
1882
1883       /* Check the type of the "real" argument, if there's a type we want.  */
1884       if (i == fci->pointer_count + aflag && wanted_type != 0
1885           && TREE_CODE (cur_type) != ERROR_MARK
1886           && wanted_type != TYPE_MAIN_VARIANT (cur_type)
1887           /* If we want `void *', allow any pointer type.
1888              (Anything else would already have got a warning.)  */
1889           && ! (wanted_type == void_type_node
1890                 && fci->pointer_count > 0)
1891           /* Don't warn about differences merely in signedness.  */
1892           && !(TREE_CODE (wanted_type) == INTEGER_TYPE
1893                && TREE_CODE (TYPE_MAIN_VARIANT (cur_type)) == INTEGER_TYPE
1894                && (TREE_UNSIGNED (wanted_type)
1895                    ? wanted_type == (cur_type = unsigned_type (cur_type))
1896                    : wanted_type == (cur_type = signed_type (cur_type))))
1897           /* Likewise, "signed char", "unsigned char" and "char" are
1898              equivalent but the above test won't consider them equivalent.  */
1899           && ! (wanted_type == char_type_node
1900                 && (TYPE_MAIN_VARIANT (cur_type) == signed_char_type_node
1901                     || TYPE_MAIN_VARIANT (cur_type) == unsigned_char_type_node)))
1902         {
1903           register char *this;
1904           register char *that;
1905
1906           this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
1907           that = 0;
1908           if (TREE_CODE (cur_type) != ERROR_MARK
1909               && TYPE_NAME (cur_type) != 0
1910               && TREE_CODE (cur_type) != INTEGER_TYPE
1911               && !(TREE_CODE (cur_type) == POINTER_TYPE
1912                    && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE))
1913             {
1914               if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL
1915                   && DECL_NAME (TYPE_NAME (cur_type)) != 0)
1916                 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1917               else
1918                 that = IDENTIFIER_POINTER (TYPE_NAME (cur_type));
1919             }
1920
1921           /* A nameless type can't possibly match what the format wants.
1922              So there will be a warning for it.
1923              Make up a string to describe vaguely what it is.  */
1924           if (that == 0)
1925             {
1926               if (TREE_CODE (cur_type) == POINTER_TYPE)
1927                 that = "pointer";
1928               else
1929                 that = "different type";
1930             }
1931
1932           /* Make the warning better in case of mismatch of int vs long.  */
1933           if (TREE_CODE (cur_type) == INTEGER_TYPE
1934               && TREE_CODE (wanted_type) == INTEGER_TYPE
1935               && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type)
1936               && TYPE_NAME (cur_type) != 0
1937               && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL)
1938             that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1939
1940           if (strcmp (this, that) != 0)
1941             warning ("%s format, %s arg (arg %d)", this, that, arg_num);
1942         }
1943     }
1944 }
1945 \f
1946 /* Print a warning if a constant expression had overflow in folding.
1947    Invoke this function on every expression that the language
1948    requires to be a constant expression.
1949    Note the ANSI C standard says it is erroneous for a
1950    constant expression to overflow.  */
1951
1952 void
1953 constant_expression_warning (value)
1954      tree value;
1955 {
1956   if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
1957        || TREE_CODE (value) == COMPLEX_CST)
1958       && TREE_CONSTANT_OVERFLOW (value) && pedantic)
1959     pedwarn ("overflow in constant expression");
1960 }
1961
1962 /* Print a warning if an expression had overflow in folding.
1963    Invoke this function on every expression that
1964    (1) appears in the source code, and
1965    (2) might be a constant expression that overflowed, and
1966    (3) is not already checked by convert_and_check;
1967    however, do not invoke this function on operands of explicit casts.  */
1968
1969 void
1970 overflow_warning (value)
1971      tree value;
1972 {
1973   if ((TREE_CODE (value) == INTEGER_CST
1974        || (TREE_CODE (value) == COMPLEX_CST
1975            && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
1976       && TREE_OVERFLOW (value))
1977     {
1978       TREE_OVERFLOW (value) = 0;
1979       if (skip_evaluation == 0)
1980         warning ("integer overflow in expression");
1981     }
1982   else if ((TREE_CODE (value) == REAL_CST
1983             || (TREE_CODE (value) == COMPLEX_CST
1984                 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
1985            && TREE_OVERFLOW (value))
1986     {
1987       TREE_OVERFLOW (value) = 0;
1988       if (skip_evaluation == 0)
1989         warning ("floating point overflow in expression");
1990     }
1991 }
1992
1993 /* Print a warning if a large constant is truncated to unsigned,
1994    or if -Wconversion is used and a constant < 0 is converted to unsigned.
1995    Invoke this function on every expression that might be implicitly
1996    converted to an unsigned type.  */
1997
1998 void
1999 unsigned_conversion_warning (result, operand)
2000      tree result, operand;
2001 {
2002   if (TREE_CODE (operand) == INTEGER_CST
2003       && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
2004       && TREE_UNSIGNED (TREE_TYPE (result))
2005       && skip_evaluation == 0
2006       && !int_fits_type_p (operand, TREE_TYPE (result)))
2007     {
2008       if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
2009         /* This detects cases like converting -129 or 256 to unsigned char.  */
2010         warning ("large integer implicitly truncated to unsigned type");
2011       else if (warn_conversion)
2012         warning ("negative integer implicitly converted to unsigned type");
2013     }
2014 }
2015
2016 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2017    Invoke this function on every expression that is converted implicitly,
2018    i.e. because of language rules and not because of an explicit cast.  */
2019
2020 tree
2021 convert_and_check (type, expr)
2022      tree type, expr;
2023 {
2024   tree t = convert (type, expr);
2025   if (TREE_CODE (t) == INTEGER_CST)
2026     {
2027       if (TREE_OVERFLOW (t))
2028         {
2029           TREE_OVERFLOW (t) = 0;
2030
2031           /* Do not diagnose overflow in a constant expression merely
2032              because a conversion overflowed.  */
2033           TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
2034
2035           /* No warning for converting 0x80000000 to int.  */
2036           if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
2037                 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
2038                 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
2039             /* If EXPR fits in the unsigned version of TYPE,
2040                don't warn unless pedantic.  */
2041             if ((pedantic
2042                  || TREE_UNSIGNED (type)
2043                  || ! int_fits_type_p (expr, unsigned_type (type)))
2044                 && skip_evaluation == 0)
2045               warning ("overflow in implicit constant conversion");
2046         }
2047       else
2048         unsigned_conversion_warning (t, expr);
2049     }
2050   return t;
2051 }
2052 \f
2053 void
2054 c_expand_expr_stmt (expr)
2055      tree expr;
2056 {
2057   /* Do default conversion if safe and possibly important,
2058      in case within ({...}).  */
2059   if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
2060       || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
2061     expr = default_conversion (expr);
2062
2063   if (TREE_TYPE (expr) != error_mark_node
2064       && TYPE_SIZE (TREE_TYPE (expr)) == 0
2065       && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
2066     error ("expression statement has incomplete type");
2067
2068   expand_expr_stmt (expr);
2069 }
2070 \f
2071 /* Validate the expression after `case' and apply default promotions.  */
2072
2073 tree
2074 check_case_value (value)
2075      tree value;
2076 {
2077   if (value == NULL_TREE)
2078     return value;
2079
2080   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
2081   STRIP_TYPE_NOPS (value);
2082
2083   if (TREE_CODE (value) != INTEGER_CST
2084       && value != error_mark_node)
2085     {
2086       error ("case label does not reduce to an integer constant");
2087       value = error_mark_node;
2088     }
2089   else
2090     /* Promote char or short to int.  */
2091     value = default_conversion (value);
2092
2093   constant_expression_warning (value);
2094
2095   return value;
2096 }
2097 \f
2098 /* Return an integer type with BITS bits of precision,
2099    that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
2100
2101 tree
2102 type_for_size (bits, unsignedp)
2103      unsigned bits;
2104      int unsignedp;
2105 {
2106   if (bits == TYPE_PRECISION (integer_type_node))
2107     return unsignedp ? unsigned_type_node : integer_type_node;
2108
2109   if (bits == TYPE_PRECISION (signed_char_type_node))
2110     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2111
2112   if (bits == TYPE_PRECISION (short_integer_type_node))
2113     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2114
2115   if (bits == TYPE_PRECISION (long_integer_type_node))
2116     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2117
2118   if (bits == TYPE_PRECISION (long_long_integer_type_node))
2119     return (unsignedp ? long_long_unsigned_type_node
2120             : long_long_integer_type_node);
2121
2122   if (bits <= TYPE_PRECISION (intQI_type_node))
2123     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2124
2125   if (bits <= TYPE_PRECISION (intHI_type_node))
2126     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2127
2128   if (bits <= TYPE_PRECISION (intSI_type_node))
2129     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2130
2131   if (bits <= TYPE_PRECISION (intDI_type_node))
2132     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2133
2134   return 0;
2135 }
2136
2137 /* Return a data type that has machine mode MODE.
2138    If the mode is an integer,
2139    then UNSIGNEDP selects between signed and unsigned types.  */
2140
2141 tree
2142 type_for_mode (mode, unsignedp)
2143      enum machine_mode mode;
2144      int unsignedp;
2145 {
2146   if (mode == TYPE_MODE (integer_type_node))
2147     return unsignedp ? unsigned_type_node : integer_type_node;
2148
2149   if (mode == TYPE_MODE (signed_char_type_node))
2150     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2151
2152   if (mode == TYPE_MODE (short_integer_type_node))
2153     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2154
2155   if (mode == TYPE_MODE (long_integer_type_node))
2156     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2157
2158   if (mode == TYPE_MODE (long_long_integer_type_node))
2159     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2160
2161   if (mode == TYPE_MODE (intQI_type_node))
2162     return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2163
2164   if (mode == TYPE_MODE (intHI_type_node))
2165     return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2166
2167   if (mode == TYPE_MODE (intSI_type_node))
2168     return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2169
2170   if (mode == TYPE_MODE (intDI_type_node))
2171     return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2172
2173 #if HOST_BITS_PER_WIDE_INT >= 64
2174   if (mode == TYPE_MODE (intTI_type_node))
2175     return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2176 #endif
2177
2178   if (mode == TYPE_MODE (float_type_node))
2179     return float_type_node;
2180
2181   if (mode == TYPE_MODE (double_type_node))
2182     return double_type_node;
2183
2184   if (mode == TYPE_MODE (long_double_type_node))
2185     return long_double_type_node;
2186
2187   if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
2188     return build_pointer_type (char_type_node);
2189
2190   if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2191     return build_pointer_type (integer_type_node);
2192
2193   return 0;
2194 }
2195 \f
2196 /* Return the minimum number of bits needed to represent VALUE in a
2197    signed or unsigned type, UNSIGNEDP says which.  */
2198
2199 int
2200 min_precision (value, unsignedp)
2201      tree value;
2202      int unsignedp;
2203 {
2204   int log;
2205
2206   /* If the value is negative, compute its negative minus 1.  The latter
2207      adjustment is because the absolute value of the largest negative value
2208      is one larger than the largest positive value.  This is equivalent to
2209      a bit-wise negation, so use that operation instead.  */
2210
2211   if (tree_int_cst_sgn (value) < 0)
2212     value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
2213
2214   /* Return the number of bits needed, taking into account the fact
2215      that we need one more bit for a signed than unsigned type.  */
2216
2217   if (integer_zerop (value))
2218     log = 0;
2219   else if (TREE_INT_CST_HIGH (value) != 0)
2220     log = HOST_BITS_PER_WIDE_INT + floor_log2 (TREE_INT_CST_HIGH (value));
2221   else
2222     log = floor_log2 (TREE_INT_CST_LOW (value));
2223
2224   return log + 1 + ! unsignedp;
2225 }
2226 \f
2227 /* Print an error message for invalid operands to arith operation CODE.
2228    NOP_EXPR is used as a special case (see truthvalue_conversion).  */
2229
2230 void
2231 binary_op_error (code)
2232      enum tree_code code;
2233 {
2234   register char *opname;
2235
2236   switch (code)
2237     {
2238     case NOP_EXPR:
2239       error ("invalid truth-value expression");
2240       return;
2241
2242     case PLUS_EXPR:
2243       opname = "+"; break;
2244     case MINUS_EXPR:
2245       opname = "-"; break;
2246     case MULT_EXPR:
2247       opname = "*"; break;
2248     case MAX_EXPR:
2249       opname = "max"; break;
2250     case MIN_EXPR:
2251       opname = "min"; break;
2252     case EQ_EXPR:
2253       opname = "=="; break;
2254     case NE_EXPR:
2255       opname = "!="; break;
2256     case LE_EXPR:
2257       opname = "<="; break;
2258     case GE_EXPR:
2259       opname = ">="; break;
2260     case LT_EXPR:
2261       opname = "<"; break;
2262     case GT_EXPR:
2263       opname = ">"; break;
2264     case LSHIFT_EXPR:
2265       opname = "<<"; break;
2266     case RSHIFT_EXPR:
2267       opname = ">>"; break;
2268     case TRUNC_MOD_EXPR:
2269     case FLOOR_MOD_EXPR:
2270       opname = "%"; break;
2271     case TRUNC_DIV_EXPR:
2272     case FLOOR_DIV_EXPR:
2273       opname = "/"; break;
2274     case BIT_AND_EXPR:
2275       opname = "&"; break;
2276     case BIT_IOR_EXPR:
2277       opname = "|"; break;
2278     case TRUTH_ANDIF_EXPR:
2279       opname = "&&"; break;
2280     case TRUTH_ORIF_EXPR:
2281       opname = "||"; break;
2282     case BIT_XOR_EXPR:
2283       opname = "^"; break;
2284     case LROTATE_EXPR:
2285     case RROTATE_EXPR:
2286       opname = "rotate"; break;
2287     default:
2288       opname = "unknown"; break;
2289     }
2290   error ("invalid operands to binary %s", opname);
2291 }
2292 \f
2293 /* Subroutine of build_binary_op, used for comparison operations.
2294    See if the operands have both been converted from subword integer types
2295    and, if so, perhaps change them both back to their original type.
2296    This function is also responsible for converting the two operands
2297    to the proper common type for comparison.
2298
2299    The arguments of this function are all pointers to local variables
2300    of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2301    RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2302
2303    If this function returns nonzero, it means that the comparison has
2304    a constant value.  What this function returns is an expression for
2305    that value.  */
2306
2307 tree
2308 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
2309      tree *op0_ptr, *op1_ptr;
2310      tree *restype_ptr;
2311      enum tree_code *rescode_ptr;
2312 {
2313   register tree type;
2314   tree op0 = *op0_ptr;
2315   tree op1 = *op1_ptr;
2316   int unsignedp0, unsignedp1;
2317   int real1, real2;
2318   tree primop0, primop1;
2319   enum tree_code code = *rescode_ptr;
2320
2321   /* Throw away any conversions to wider types
2322      already present in the operands.  */
2323
2324   primop0 = get_narrower (op0, &unsignedp0);
2325   primop1 = get_narrower (op1, &unsignedp1);
2326
2327   /* Handle the case that OP0 does not *contain* a conversion
2328      but it *requires* conversion to FINAL_TYPE.  */
2329
2330   if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
2331     unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
2332   if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
2333     unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
2334
2335   /* If one of the operands must be floated, we cannot optimize.  */
2336   real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
2337   real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
2338
2339   /* If first arg is constant, swap the args (changing operation
2340      so value is preserved), for canonicalization.  Don't do this if
2341      the second arg is 0.  */
2342
2343   if (TREE_CONSTANT (primop0)
2344       && ! integer_zerop (primop1) && ! real_zerop (primop1))
2345     {
2346       register tree tem = primop0;
2347       register int temi = unsignedp0;
2348       primop0 = primop1;
2349       primop1 = tem;
2350       tem = op0;
2351       op0 = op1;
2352       op1 = tem;
2353       *op0_ptr = op0;
2354       *op1_ptr = op1;
2355       unsignedp0 = unsignedp1;
2356       unsignedp1 = temi;
2357       temi = real1;
2358       real1 = real2;
2359       real2 = temi;
2360
2361       switch (code)
2362         {
2363         case LT_EXPR:
2364           code = GT_EXPR;
2365           break;
2366         case GT_EXPR:
2367           code = LT_EXPR;
2368           break;
2369         case LE_EXPR:
2370           code = GE_EXPR;
2371           break;
2372         case GE_EXPR:
2373           code = LE_EXPR;
2374           break;
2375         default:
2376           break;
2377         }
2378       *rescode_ptr = code;
2379     }
2380
2381   /* If comparing an integer against a constant more bits wide,
2382      maybe we can deduce a value of 1 or 0 independent of the data.
2383      Or else truncate the constant now
2384      rather than extend the variable at run time.
2385
2386      This is only interesting if the constant is the wider arg.
2387      Also, it is not safe if the constant is unsigned and the
2388      variable arg is signed, since in this case the variable
2389      would be sign-extended and then regarded as unsigned.
2390      Our technique fails in this case because the lowest/highest
2391      possible unsigned results don't follow naturally from the
2392      lowest/highest possible values of the variable operand.
2393      For just EQ_EXPR and NE_EXPR there is another technique that
2394      could be used: see if the constant can be faithfully represented
2395      in the other operand's type, by truncating it and reextending it
2396      and see if that preserves the constant's value.  */
2397
2398   if (!real1 && !real2
2399       && TREE_CODE (primop1) == INTEGER_CST
2400       && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
2401     {
2402       int min_gt, max_gt, min_lt, max_lt;
2403       tree maxval, minval;
2404       /* 1 if comparison is nominally unsigned.  */
2405       int unsignedp = TREE_UNSIGNED (*restype_ptr);
2406       tree val;
2407
2408       type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
2409
2410       maxval = TYPE_MAX_VALUE (type);
2411       minval = TYPE_MIN_VALUE (type);
2412
2413       if (unsignedp && !unsignedp0)
2414         *restype_ptr = signed_type (*restype_ptr);
2415
2416       if (TREE_TYPE (primop1) != *restype_ptr)
2417         primop1 = convert (*restype_ptr, primop1);
2418       if (type != *restype_ptr)
2419         {
2420           minval = convert (*restype_ptr, minval);
2421           maxval = convert (*restype_ptr, maxval);
2422         }
2423
2424       if (unsignedp && unsignedp0)
2425         {
2426           min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
2427           max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
2428           min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
2429           max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
2430         }
2431       else
2432         {
2433           min_gt = INT_CST_LT (primop1, minval);
2434           max_gt = INT_CST_LT (primop1, maxval);
2435           min_lt = INT_CST_LT (minval, primop1);
2436           max_lt = INT_CST_LT (maxval, primop1);
2437         }
2438
2439       val = 0;
2440       /* This used to be a switch, but Genix compiler can't handle that.  */
2441       if (code == NE_EXPR)
2442         {
2443           if (max_lt || min_gt)
2444             val = boolean_true_node;
2445         }
2446       else if (code == EQ_EXPR)
2447         {
2448           if (max_lt || min_gt)
2449             val = boolean_false_node;
2450         }
2451       else if (code == LT_EXPR)
2452         {
2453           if (max_lt)
2454             val = boolean_true_node;
2455           if (!min_lt)
2456             val = boolean_false_node;
2457         }
2458       else if (code == GT_EXPR)
2459         {
2460           if (min_gt)
2461             val = boolean_true_node;
2462           if (!max_gt)
2463             val = boolean_false_node;
2464         }
2465       else if (code == LE_EXPR)
2466         {
2467           if (!max_gt)
2468             val = boolean_true_node;
2469           if (min_gt)
2470             val = boolean_false_node;
2471         }
2472       else if (code == GE_EXPR)
2473         {
2474           if (!min_lt)
2475             val = boolean_true_node;
2476           if (max_lt)
2477             val = boolean_false_node;
2478         }
2479
2480       /* If primop0 was sign-extended and unsigned comparison specd,
2481          we did a signed comparison above using the signed type bounds.
2482          But the comparison we output must be unsigned.
2483
2484          Also, for inequalities, VAL is no good; but if the signed
2485          comparison had *any* fixed result, it follows that the
2486          unsigned comparison just tests the sign in reverse
2487          (positive values are LE, negative ones GE).
2488          So we can generate an unsigned comparison
2489          against an extreme value of the signed type.  */
2490
2491       if (unsignedp && !unsignedp0)
2492         {
2493           if (val != 0)
2494             switch (code)
2495               {
2496               case LT_EXPR:
2497               case GE_EXPR:
2498                 primop1 = TYPE_MIN_VALUE (type);
2499                 val = 0;
2500                 break;
2501
2502               case LE_EXPR:
2503               case GT_EXPR:
2504                 primop1 = TYPE_MAX_VALUE (type);
2505                 val = 0;
2506                 break;
2507
2508               default:
2509                 break;
2510               }
2511           type = unsigned_type (type);
2512         }
2513
2514       if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2515         {
2516           /* This is the case of (char)x >?< 0x80, which people used to use
2517              expecting old C compilers to change the 0x80 into -0x80.  */
2518           if (val == boolean_false_node)
2519             warning ("comparison is always false due to limited range of data type");
2520           if (val == boolean_true_node)
2521             warning ("comparison is always true due to limited range of data type");
2522         }
2523
2524       if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2525         {
2526           /* This is the case of (unsigned char)x >?< -1 or < 0.  */
2527           if (val == boolean_false_node)
2528             warning ("comparison is always false due to limited range of data type");
2529           if (val == boolean_true_node)
2530             warning ("comparison is always true due to limited range of data type");
2531         }
2532
2533       if (val != 0)
2534         {
2535           /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
2536           if (TREE_SIDE_EFFECTS (primop0))
2537             return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
2538           return val;
2539         }
2540
2541       /* Value is not predetermined, but do the comparison
2542          in the type of the operand that is not constant.
2543          TYPE is already properly set.  */
2544     }
2545   else if (real1 && real2
2546            && (TYPE_PRECISION (TREE_TYPE (primop0))
2547                == TYPE_PRECISION (TREE_TYPE (primop1))))
2548     type = TREE_TYPE (primop0);
2549
2550   /* If args' natural types are both narrower than nominal type
2551      and both extend in the same manner, compare them
2552      in the type of the wider arg.
2553      Otherwise must actually extend both to the nominal
2554      common type lest different ways of extending
2555      alter the result.
2556      (eg, (short)-1 == (unsigned short)-1  should be 0.)  */
2557
2558   else if (unsignedp0 == unsignedp1 && real1 == real2
2559            && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
2560            && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
2561     {
2562       type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
2563       type = signed_or_unsigned_type (unsignedp0
2564                                       || TREE_UNSIGNED (*restype_ptr),
2565                                       type);
2566       /* Make sure shorter operand is extended the right way
2567          to match the longer operand.  */
2568       primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
2569                          primop0);
2570       primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
2571                          primop1);
2572     }
2573   else
2574     {
2575       /* Here we must do the comparison on the nominal type
2576          using the args exactly as we received them.  */
2577       type = *restype_ptr;
2578       primop0 = op0;
2579       primop1 = op1;
2580
2581       if (!real1 && !real2 && integer_zerop (primop1)
2582           && TREE_UNSIGNED (*restype_ptr))
2583         {
2584           tree value = 0;
2585           switch (code)
2586             {
2587             case GE_EXPR:
2588               /* All unsigned values are >= 0, so we warn if extra warnings
2589                  are requested.  However, if OP0 is a constant that is
2590                  >= 0, the signedness of the comparison isn't an issue,
2591                  so suppress the warning.  */
2592               if (extra_warnings
2593                   && ! (TREE_CODE (primop0) == INTEGER_CST
2594                         && ! TREE_OVERFLOW (convert (signed_type (type),
2595                                                      primop0))))
2596                 warning ("comparison of unsigned expression >= 0 is always true");
2597               value = boolean_true_node;
2598               break;
2599
2600             case LT_EXPR:
2601               if (extra_warnings
2602                   && ! (TREE_CODE (primop0) == INTEGER_CST
2603                         && ! TREE_OVERFLOW (convert (signed_type (type),
2604                                                      primop0))))
2605                 warning ("comparison of unsigned expression < 0 is always false");
2606               value = boolean_false_node;
2607               break;
2608
2609             default:
2610               break;
2611             }
2612
2613           if (value != 0)
2614             {
2615               /* Don't forget to evaluate PRIMOP0 if it has side effects.  */
2616               if (TREE_SIDE_EFFECTS (primop0))
2617                 return build (COMPOUND_EXPR, TREE_TYPE (value),
2618                               primop0, value);
2619               return value;
2620             }
2621         }
2622     }
2623
2624   *op0_ptr = convert (type, primop0);
2625   *op1_ptr = convert (type, primop1);
2626
2627   *restype_ptr = boolean_type_node;
2628
2629   return 0;
2630 }
2631 \f
2632 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2633    or validate its data type for an `if' or `while' statement or ?..: exp.
2634
2635    This preparation consists of taking the ordinary
2636    representation of an expression expr and producing a valid tree
2637    boolean expression describing whether expr is nonzero.  We could
2638    simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2639    but we optimize comparisons, &&, ||, and !.
2640
2641    The resulting type should always be `boolean_type_node'.  */
2642
2643 tree
2644 truthvalue_conversion (expr)
2645      tree expr;
2646 {
2647   if (TREE_CODE (expr) == ERROR_MARK)
2648     return expr;
2649
2650 #if 0 /* This appears to be wrong for C++.  */
2651   /* These really should return error_mark_node after 2.4 is stable.
2652      But not all callers handle ERROR_MARK properly.  */
2653   switch (TREE_CODE (TREE_TYPE (expr)))
2654     {
2655     case RECORD_TYPE:
2656       error ("struct type value used where scalar is required");
2657       return boolean_false_node;
2658
2659     case UNION_TYPE:
2660       error ("union type value used where scalar is required");
2661       return boolean_false_node;
2662
2663     case ARRAY_TYPE:
2664       error ("array type value used where scalar is required");
2665       return boolean_false_node;
2666
2667     default:
2668       break;
2669     }
2670 #endif /* 0 */
2671
2672   switch (TREE_CODE (expr))
2673     {
2674       /* It is simpler and generates better code to have only TRUTH_*_EXPR
2675          or comparison expressions as truth values at this level.  */
2676 #if 0
2677     case COMPONENT_REF:
2678       /* A one-bit unsigned bit-field is already acceptable.  */
2679       if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
2680           && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
2681         return expr;
2682       break;
2683 #endif
2684
2685     case EQ_EXPR:
2686       /* It is simpler and generates better code to have only TRUTH_*_EXPR
2687          or comparison expressions as truth values at this level.  */
2688 #if 0
2689       if (integer_zerop (TREE_OPERAND (expr, 1)))
2690         return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0);
2691 #endif
2692     case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
2693     case TRUTH_ANDIF_EXPR:
2694     case TRUTH_ORIF_EXPR:
2695     case TRUTH_AND_EXPR:
2696     case TRUTH_OR_EXPR:
2697     case TRUTH_XOR_EXPR:
2698     case TRUTH_NOT_EXPR:
2699       TREE_TYPE (expr) = boolean_type_node;
2700       return expr;
2701
2702     case ERROR_MARK:
2703       return expr;
2704
2705     case INTEGER_CST:
2706       return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
2707
2708     case REAL_CST:
2709       return real_zerop (expr) ? boolean_false_node : boolean_true_node;
2710
2711     case ADDR_EXPR:
2712       /* If we are taking the address of a external decl, it might be zero
2713          if it is weak, so we cannot optimize.  */
2714       if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (expr, 0))) == 'd'
2715           && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
2716         break;
2717
2718       if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
2719         return build (COMPOUND_EXPR, boolean_type_node,
2720                       TREE_OPERAND (expr, 0), boolean_true_node);
2721       else
2722         return boolean_true_node;
2723
2724     case COMPLEX_EXPR:
2725       return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2726                                ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2727                               truthvalue_conversion (TREE_OPERAND (expr, 0)),
2728                               truthvalue_conversion (TREE_OPERAND (expr, 1)),
2729                               0);
2730
2731     case NEGATE_EXPR:
2732     case ABS_EXPR:
2733     case FLOAT_EXPR:
2734     case FFS_EXPR:
2735       /* These don't change whether an object is non-zero or zero.  */
2736       return truthvalue_conversion (TREE_OPERAND (expr, 0));
2737
2738     case LROTATE_EXPR:
2739     case RROTATE_EXPR:
2740       /* These don't change whether an object is zero or non-zero, but
2741          we can't ignore them if their second arg has side-effects.  */
2742       if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2743         return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2744                       truthvalue_conversion (TREE_OPERAND (expr, 0)));
2745       else
2746         return truthvalue_conversion (TREE_OPERAND (expr, 0));
2747
2748     case COND_EXPR:
2749       /* Distribute the conversion into the arms of a COND_EXPR.  */
2750       return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2751                           truthvalue_conversion (TREE_OPERAND (expr, 1)),
2752                           truthvalue_conversion (TREE_OPERAND (expr, 2))));
2753
2754     case CONVERT_EXPR:
2755       /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2756          since that affects how `default_conversion' will behave.  */
2757       if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2758           || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2759         break;
2760       /* fall through...  */
2761     case NOP_EXPR:
2762       /* If this is widening the argument, we can ignore it.  */
2763       if (TYPE_PRECISION (TREE_TYPE (expr))
2764           >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2765         return truthvalue_conversion (TREE_OPERAND (expr, 0));
2766       break;
2767
2768     case MINUS_EXPR:
2769       /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2770          this case.  */
2771       if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2772           && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2773         break;
2774       /* fall through...  */
2775     case BIT_XOR_EXPR:
2776       /* This and MINUS_EXPR can be changed into a comparison of the
2777          two objects.  */
2778       if (TREE_TYPE (TREE_OPERAND (expr, 0))
2779           == TREE_TYPE (TREE_OPERAND (expr, 1)))
2780         return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2781                                 TREE_OPERAND (expr, 1), 1);
2782       return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2783                               fold (build1 (NOP_EXPR,
2784                                             TREE_TYPE (TREE_OPERAND (expr, 0)),
2785                                             TREE_OPERAND (expr, 1))), 1);
2786
2787     case BIT_AND_EXPR:
2788       if (integer_onep (TREE_OPERAND (expr, 1))
2789           && TREE_TYPE (expr) != boolean_type_node)
2790         /* Using convert here would cause infinite recursion.  */
2791         return build1 (NOP_EXPR, boolean_type_node, expr);
2792       break;
2793
2794     case MODIFY_EXPR:
2795       if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
2796         warning ("suggest parentheses around assignment used as truth value");
2797       break;
2798
2799     default:
2800       break;
2801     }
2802
2803   if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2804     {
2805       tree tem = save_expr (expr);
2806       return (build_binary_op
2807               ((TREE_SIDE_EFFECTS (expr)
2808                 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2809                truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
2810                truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
2811                0));
2812     }
2813
2814   return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
2815 }
2816 \f
2817 #if USE_CPPLIB
2818 /* Read the rest of a #-directive from input stream FINPUT.
2819    In normal use, the directive name and the white space after it
2820    have already been read, so they won't be included in the result.
2821    We allow for the fact that the directive line may contain
2822    a newline embedded within a character or string literal which forms
2823    a part of the directive.
2824
2825    The value is a string in a reusable buffer.  It remains valid
2826    only until the next time this function is called.  */
2827 unsigned char *yy_cur, *yy_lim;
2828
2829 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
2830 #define UNGETC(c) ((c), yy_cur--)
2831
2832 int
2833 yy_get_token ()
2834 {
2835   for (;;)
2836     {
2837       parse_in.limit = parse_in.token_buffer;
2838       cpp_token = cpp_get_token (&parse_in);
2839       if (cpp_token == CPP_EOF)
2840         return -1;
2841       yy_lim = CPP_PWRITTEN (&parse_in);
2842       yy_cur = parse_in.token_buffer;
2843       if (yy_cur < yy_lim)
2844         return *yy_cur++;
2845     }
2846 }
2847
2848 char *
2849 get_directive_line ()
2850 {
2851   static char *directive_buffer = NULL;
2852   static unsigned buffer_length = 0;
2853   register char *p;
2854   register char *buffer_limit;
2855   register int looking_for = 0;
2856   register int char_escaped = 0;
2857
2858   if (buffer_length == 0)
2859     {
2860       directive_buffer = (char *)xmalloc (128);
2861       buffer_length = 128;
2862     }
2863
2864   buffer_limit = &directive_buffer[buffer_length];
2865
2866   for (p = directive_buffer; ; )
2867     {
2868       int c;
2869
2870       /* Make buffer bigger if it is full.  */
2871       if (p >= buffer_limit)
2872         {
2873           register unsigned bytes_used = (p - directive_buffer);
2874
2875           buffer_length *= 2;
2876           directive_buffer
2877             = (char *)xrealloc (directive_buffer, buffer_length);
2878           p = &directive_buffer[bytes_used];
2879           buffer_limit = &directive_buffer[buffer_length];
2880         }
2881
2882       c = GETC ();
2883
2884       /* Discard initial whitespace.  */
2885       if ((c == ' ' || c == '\t') && p == directive_buffer)
2886         continue;
2887
2888       /* Detect the end of the directive.  */
2889       if (c == '\n' && looking_for == 0)
2890         {
2891           UNGETC (c);
2892           c = '\0';
2893         }
2894
2895       *p++ = c;
2896
2897       if (c == 0)
2898         return directive_buffer;
2899
2900       /* Handle string and character constant syntax.  */
2901       if (looking_for)
2902         {
2903           if (looking_for == c && !char_escaped)
2904             looking_for = 0;    /* Found terminator... stop looking.  */
2905         }
2906       else
2907         if (c == '\'' || c == '"')
2908           looking_for = c;      /* Don't stop buffering until we see another
2909                                    another one of these (or an EOF).  */
2910
2911       /* Handle backslash.  */
2912       char_escaped = (c == '\\' && ! char_escaped);
2913     }
2914 }
2915 #else
2916 /* Read the rest of a #-directive from input stream FINPUT.
2917    In normal use, the directive name and the white space after it
2918    have already been read, so they won't be included in the result.
2919    We allow for the fact that the directive line may contain
2920    a newline embedded within a character or string literal which forms
2921    a part of the directive.
2922
2923    The value is a string in a reusable buffer.  It remains valid
2924    only until the next time this function is called.
2925
2926    The terminating character ('\n' or EOF) is left in FINPUT for the
2927    caller to re-read.  */
2928
2929 char *
2930 get_directive_line (finput)
2931      register FILE *finput;
2932 {
2933   static char *directive_buffer = NULL;
2934   static unsigned buffer_length = 0;
2935   register char *p;
2936   register char *buffer_limit;
2937   register int looking_for = 0;
2938   register int char_escaped = 0;
2939
2940   if (buffer_length == 0)
2941     {
2942       directive_buffer = (char *)xmalloc (128);
2943       buffer_length = 128;
2944     }
2945
2946   buffer_limit = &directive_buffer[buffer_length];
2947
2948   for (p = directive_buffer; ; )
2949     {
2950       int c;
2951
2952       /* Make buffer bigger if it is full.  */
2953       if (p >= buffer_limit)
2954         {
2955           register unsigned bytes_used = (p - directive_buffer);
2956
2957           buffer_length *= 2;
2958           directive_buffer
2959             = (char *)xrealloc (directive_buffer, buffer_length);
2960           p = &directive_buffer[bytes_used];
2961           buffer_limit = &directive_buffer[buffer_length];
2962         }
2963
2964       c = getc (finput);
2965
2966       /* Discard initial whitespace.  */
2967       if ((c == ' ' || c == '\t') && p == directive_buffer)
2968         continue;
2969
2970       /* Detect the end of the directive.  */
2971       if (looking_for == 0
2972           && (c == '\n' || c == EOF))
2973         {
2974           ungetc (c, finput);
2975           c = '\0';
2976         }
2977
2978       *p++ = c;
2979
2980       if (c == 0)
2981         return directive_buffer;
2982
2983       /* Handle string and character constant syntax.  */
2984       if (looking_for)
2985         {
2986           if (looking_for == c && !char_escaped)
2987             looking_for = 0;    /* Found terminator... stop looking.  */
2988         }
2989       else
2990         if (c == '\'' || c == '"')
2991           looking_for = c;      /* Don't stop buffering until we see another
2992                                    one of these (or an EOF).  */
2993
2994       /* Handle backslash.  */
2995       char_escaped = (c == '\\' && ! char_escaped);
2996     }
2997 }
2998 #endif /* !USE_CPPLIB */
2999 \f
3000 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3001    down to the element type of an array.  */
3002
3003 tree
3004 c_build_qualified_type (type, type_quals)
3005      tree type;
3006      int type_quals;
3007 {
3008   /* A restrict-qualified pointer type must be a pointer to object or
3009      incomplete type.  Note that the use of POINTER_TYPE_P also allows
3010      REFERENCE_TYPEs, which is appropriate for C++.  Unfortunately,
3011      the C++ front-end also use POINTER_TYPE for pointer-to-member
3012      values, so even though it should be illegal to use `restrict'
3013      with such an entity we don't flag that here.  Thus, special case
3014      code for that case is required in the C++ front-end.  */
3015   if ((type_quals & TYPE_QUAL_RESTRICT)
3016       && (!POINTER_TYPE_P (type)
3017           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
3018     {
3019       error ("invalid use of `restrict'");
3020       type_quals &= ~TYPE_QUAL_RESTRICT;
3021     }
3022
3023   if (TREE_CODE (type) == ARRAY_TYPE)
3024     return build_array_type (c_build_qualified_type (TREE_TYPE (type),
3025                                                      type_quals),
3026                              TYPE_DOMAIN (type));
3027   return build_qualified_type (type, type_quals);
3028 }
3029
3030 /* Apply the TYPE_QUALS to the new DECL.  */
3031
3032 void
3033 c_apply_type_quals_to_decl (type_quals, decl)
3034      int type_quals;
3035      tree decl;
3036 {
3037   if (type_quals & TYPE_QUAL_CONST)
3038     TREE_READONLY (decl) = 1;
3039   if (type_quals & TYPE_QUAL_VOLATILE)
3040     {
3041       TREE_SIDE_EFFECTS (decl) = 1;
3042       TREE_THIS_VOLATILE (decl) = 1;
3043     }
3044   if (type_quals & TYPE_QUAL_RESTRICT)
3045     {
3046       if (!TREE_TYPE (decl)
3047           || !POINTER_TYPE_P (TREE_TYPE (decl))
3048           || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
3049         error ("invalid use of `restrict'");
3050       else if (flag_strict_aliasing)
3051         {
3052           /* No two restricted pointers can point at the same thing.
3053              However, a restricted pointer can point at the same thing
3054              as an unrestricted pointer, if that unrestricted pointer
3055              is based on the restricted pointer.  So, we make the
3056              alias set for the restricted pointer a subset of the
3057              alias set for the type pointed to by the type of the
3058              decl.  */
3059
3060           int pointed_to_alias_set 
3061             = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
3062           
3063           if (!pointed_to_alias_set)
3064             /* It's not legal to make a subset of alias set zero.  */
3065             ;
3066           else
3067             {
3068               DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
3069               record_alias_subset  (pointed_to_alias_set,
3070                                     DECL_POINTER_ALIAS_SET (decl));
3071             }
3072         }
3073     }
3074 }
3075
3076 /* T is an expression with pointer type.  Find the DECL on which this
3077    expression is based.  (For example, in `a[i]' this would be `a'.)
3078    If there is no such DECL, or a unique decl cannot be determined,
3079    NULL_TREE is retured.  */
3080
3081 static tree
3082 c_find_base_decl (t)
3083      tree t;
3084 {
3085   int i;
3086   tree decl;
3087
3088   if (t == NULL_TREE || t == error_mark_node)
3089     return NULL_TREE;
3090
3091   if (!POINTER_TYPE_P (TREE_TYPE (t)))
3092     return NULL_TREE;
3093
3094   decl = NULL_TREE;
3095
3096   if (TREE_CODE (t) == FIELD_DECL 
3097       || TREE_CODE (t) == PARM_DECL
3098       || TREE_CODE (t) == VAR_DECL)
3099     /* Aha, we found a pointer-typed declaration.  */
3100     return t;
3101
3102   /* It would be nice to deal with COMPONENT_REFs here.  If we could
3103      tell that `a' and `b' were the same, then `a->f' and `b->f' are
3104      also the same.  */
3105
3106   /* Handle general expressions.  */
3107   switch (TREE_CODE_CLASS (TREE_CODE (t)))
3108     {
3109     case '1':
3110     case '2':
3111     case '3':
3112       for (i = tree_code_length [(int) TREE_CODE (t)]; --i >= 0;)
3113         {
3114           tree d = c_find_base_decl (TREE_OPERAND (t, i));
3115           if (d)
3116             {
3117               if (!decl)
3118                 decl = d;
3119               else if (d && d != decl)
3120                 /* Two different declarations.  That's confusing; let's
3121                    just assume we don't know what's going on.  */
3122                 decl = NULL_TREE;
3123             }
3124         }
3125       break;
3126
3127     default:
3128       break;
3129     }
3130
3131   return decl;
3132 }
3133
3134 /* Return the typed-based alias set for T, which may be an expression
3135    or a type.  */
3136
3137 int
3138 c_get_alias_set (t)
3139      tree t;
3140 {
3141   tree type;
3142   tree u;
3143
3144   if (t == error_mark_node)
3145     return 0;
3146
3147   type = (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
3148     ? t : TREE_TYPE (t);
3149
3150   if (type == error_mark_node)
3151     return 0;
3152
3153   /* Deal with special cases first; for certain kinds of references
3154      we're interested in more than just the type.  */
3155
3156   if (TREE_CODE (t) == BIT_FIELD_REF)
3157     /* Perhaps reads and writes to this piece of data alias fields
3158        neighboring the bitfield.  Perhaps that's impossible.  For now,
3159        let's just assume that bitfields can alias everything, which is
3160        the conservative assumption.  */
3161     return 0;
3162
3163   /* Permit type-punning when accessing a union, provided the access
3164      is directly through the union.  For example, this code does not
3165      permit taking the address of a union member and then storing
3166      through it.  Even the type-punning allowed here is a GCC
3167      extension, albeit a common and useful one; the C standard says
3168      that such accesses have implementation-defined behavior.  */
3169   for (u = t;
3170        TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
3171        u = TREE_OPERAND (u, 0))
3172     if (TREE_CODE (u) == COMPONENT_REF
3173         && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
3174       return 0;
3175
3176   if (TREE_CODE (t) == INDIRECT_REF)
3177     {
3178       /* Check for accesses through restrict-qualified pointers.  */
3179       tree decl = c_find_base_decl (TREE_OPERAND (t, 0));
3180
3181       if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
3182         /* We use the alias set indicated in the declaration.  */
3183         return DECL_POINTER_ALIAS_SET (decl);
3184     }
3185
3186   /* From here on, only the type matters.  */
3187
3188   if (TREE_CODE (t) == COMPONENT_REF
3189       && DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1)))
3190     /* Since build_modify_expr calls get_unwidened for stores to
3191        component references, the type of a bit field can be changed
3192        from (say) `unsigned int : 16' to `unsigned short' or from 
3193        `enum E : 16' to `short'.  We want the real type of the
3194        bit-field in this case, not some the integral equivalent.  */
3195     type = DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1));
3196
3197   if (TYPE_ALIAS_SET_KNOWN_P (type))
3198     /* If we've already calculated the value, just return it.  */
3199     return TYPE_ALIAS_SET (type);
3200   else if (TYPE_MAIN_VARIANT (type) != type)
3201     /* The C standard specifically allows aliasing between
3202        cv-qualified variants of types.  */
3203     TYPE_ALIAS_SET (type) = c_get_alias_set (TYPE_MAIN_VARIANT (type));
3204   else if (TREE_CODE (type) == INTEGER_TYPE)
3205     {
3206       tree signed_variant;
3207
3208       /* The C standard specifically allows aliasing between signed and
3209          unsigned variants of the same type.  We treat the signed
3210          variant as canonical.  */
3211       signed_variant = signed_type (type);
3212
3213       if (signed_variant != type)
3214         TYPE_ALIAS_SET (type) = c_get_alias_set (signed_variant);
3215       else if (signed_variant == signed_char_type_node)
3216         /* The C standard guarantess that any object may be accessed
3217            via an lvalue that has character type.  We don't have to
3218            check for unsigned_char_type_node or char_type_node because
3219            we are specifically looking at the signed variant.  */
3220         TYPE_ALIAS_SET (type) = 0;
3221     }
3222   else if (TREE_CODE (type) == ARRAY_TYPE)
3223     /* Anything that can alias one of the array elements can alias
3224        the entire array as well.  */
3225     TYPE_ALIAS_SET (type) = c_get_alias_set (TREE_TYPE (type));
3226   else if (TREE_CODE (type) == FUNCTION_TYPE)
3227     /* There are no objects of FUNCTION_TYPE, so there's no point in
3228        using up an alias set for them.  (There are, of course,
3229        pointers and references to functions, but that's 
3230        different.)  */
3231     TYPE_ALIAS_SET (type) = 0;
3232   else if (TREE_CODE (type) == RECORD_TYPE
3233            || TREE_CODE (type) == UNION_TYPE)
3234     /* If TYPE is a struct or union type then we're reading or
3235        writing an entire struct.  Thus, we don't know anything about
3236        aliasing.  (In theory, such an access can only alias objects
3237        whose type is the same as one of the fields, recursively, but
3238        we don't yet make any use of that information.)  */
3239     TYPE_ALIAS_SET (type) = 0;
3240
3241   if (!TYPE_ALIAS_SET_KNOWN_P (type)) 
3242     /* TYPE is something we haven't seen before.  Put it in a new
3243        alias set.  */
3244     TYPE_ALIAS_SET (type) = new_alias_set ();
3245
3246   return TYPE_ALIAS_SET (type);
3247 }