* optimize.c (initialize_inlined_parameters): Take FN to which the
[official-gcc.git] / gcc / c-common.c
blobf921e6cebfb834141473afadec8a0890cd98521f
1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 93-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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.
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.
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. */
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 #include "ggc.h"
34 #if USE_CPPLIB
35 #include "cpplib.h"
36 cpp_reader parse_in;
37 cpp_options parse_options;
38 enum cpp_token cpp_token;
39 #endif
41 #undef WCHAR_TYPE_SIZE
42 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
44 /* The following symbols are subsumed in the c_global_trees array, and
45 listed here individually for documentation purposes.
47 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
49 tree short_integer_type_node;
50 tree long_integer_type_node;
51 tree long_long_integer_type_node;
53 tree short_unsigned_type_node;
54 tree long_unsigned_type_node;
55 tree long_long_unsigned_type_node;
57 tree boolean_type_node;
58 tree boolean_false_node;
59 tree boolean_true_node;
61 tree ptrdiff_type_node;
63 tree unsigned_char_type_node;
64 tree signed_char_type_node;
65 tree wchar_type_node;
66 tree signed_wchar_type_node;
67 tree unsigned_wchar_type_node;
69 tree float_type_node;
70 tree double_type_node;
71 tree long_double_type_node;
73 tree complex_integer_type_node;
74 tree complex_float_type_node;
75 tree complex_double_type_node;
76 tree complex_long_double_type_node;
78 tree intQI_type_node;
79 tree intHI_type_node;
80 tree intSI_type_node;
81 tree intDI_type_node;
82 tree intTI_type_node;
84 tree unsigned_intQI_type_node;
85 tree unsigned_intHI_type_node;
86 tree unsigned_intSI_type_node;
87 tree unsigned_intDI_type_node;
88 tree unsigned_intTI_type_node;
90 tree widest_integer_literal_type_node;
91 tree widest_unsigned_literal_type_node;
93 Nodes for types `void *' and `const void *'.
95 tree ptr_type_node, const_ptr_type_node;
97 Nodes for types `char *' and `const char *'.
99 tree string_type_node, const_string_type_node;
101 Type `char[SOMENUMBER]'.
102 Used when an array of char is needed and the size is irrelevant.
104 tree char_array_type_node;
106 Type `int[SOMENUMBER]' or something like it.
107 Used when an array of int needed and the size is irrelevant.
109 tree int_array_type_node;
111 Type `wchar_t[SOMENUMBER]' or something like it.
112 Used when a wide string literal is created.
114 tree wchar_array_type_node;
116 Type `int ()' -- used for implicit declaration of functions.
118 tree default_function_type;
120 Function types `int (int)', etc.
122 tree int_ftype_int;
123 tree void_ftype;
124 tree void_ftype_ptr;
125 tree int_ftype_int;
126 tree ptr_ftype_sizetype;
128 A VOID_TYPE node, packaged in a TREE_LIST.
130 tree void_list_node;
134 tree c_global_trees[CTI_MAX];
136 /* Nonzero means the expression being parsed will never be evaluated.
137 This is a count, since unevaluated expressions can nest. */
138 int skip_evaluation;
140 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
141 A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
142 A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
143 A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, A_MALLOC,
144 A_NO_LIMIT_STACK};
146 enum format_type { printf_format_type, scanf_format_type,
147 strftime_format_type };
149 static void declare_hidden_char_array PROTO((const char *, const char *));
150 static void add_attribute PROTO((enum attrs, const char *,
151 int, int, int));
152 static void init_attributes PROTO((void));
153 static void record_function_format PROTO((tree, tree, enum format_type,
154 int, int));
155 static void record_international_format PROTO((tree, tree, int));
156 static tree c_find_base_decl PROTO((tree));
157 static int default_valid_lang_attribute PROTO ((tree, tree, tree, tree));
159 /* Keep a stack of if statements. We record the number of compound
160 statements seen up to the if keyword, as well as the line number
161 and file of the if. If a potentially ambiguous else is seen, that
162 fact is recorded; the warning is issued when we can be sure that
163 the enclosing if statement does not have an else branch. */
164 typedef struct
166 int compstmt_count;
167 int line;
168 const char *file;
169 int needs_warning;
170 } if_elt;
171 static void tfaff PROTO((void));
173 static if_elt *if_stack;
175 /* Amount of space in the if statement stack. */
176 static int if_stack_space = 0;
178 /* Stack pointer. */
179 static int if_stack_pointer = 0;
181 /* Generate RTL for the start of an if-then, and record the start of it
182 for ambiguous else detection. */
184 void
185 c_expand_start_cond (cond, exitflag, compstmt_count)
186 tree cond;
187 int exitflag;
188 int compstmt_count;
190 /* Make sure there is enough space on the stack. */
191 if (if_stack_space == 0)
193 if_stack_space = 10;
194 if_stack = (if_elt *)xmalloc (10 * sizeof (if_elt));
196 else if (if_stack_space == if_stack_pointer)
198 if_stack_space += 10;
199 if_stack = (if_elt *)xrealloc (if_stack, if_stack_space * sizeof (if_elt));
202 /* Record this if statement. */
203 if_stack[if_stack_pointer].compstmt_count = compstmt_count;
204 if_stack[if_stack_pointer].file = input_filename;
205 if_stack[if_stack_pointer].line = lineno;
206 if_stack[if_stack_pointer].needs_warning = 0;
207 if_stack_pointer++;
209 expand_start_cond (cond, exitflag);
212 /* Generate RTL for the end of an if-then. Optionally warn if a nested
213 if statement had an ambiguous else clause. */
215 void
216 c_expand_end_cond ()
218 if_stack_pointer--;
219 if (if_stack[if_stack_pointer].needs_warning)
220 warning_with_file_and_line (if_stack[if_stack_pointer].file,
221 if_stack[if_stack_pointer].line,
222 "suggest explicit braces to avoid ambiguous `else'");
223 expand_end_cond ();
226 /* Generate RTL between the then-clause and the else-clause
227 of an if-then-else. */
229 void
230 c_expand_start_else ()
232 /* An ambiguous else warning must be generated for the enclosing if
233 statement, unless we see an else branch for that one, too. */
234 if (warn_parentheses
235 && if_stack_pointer > 1
236 && (if_stack[if_stack_pointer - 1].compstmt_count
237 == if_stack[if_stack_pointer - 2].compstmt_count))
238 if_stack[if_stack_pointer - 2].needs_warning = 1;
240 /* Even if a nested if statement had an else branch, it can't be
241 ambiguous if this one also has an else. So don't warn in that
242 case. Also don't warn for any if statements nested in this else. */
243 if_stack[if_stack_pointer - 1].needs_warning = 0;
244 if_stack[if_stack_pointer - 1].compstmt_count--;
246 expand_start_else ();
249 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
251 void
252 declare_function_name ()
254 const char *name, *printable_name;
256 if (current_function_decl == NULL)
258 name = "";
259 printable_name = "top level";
261 else
263 /* Allow functions to be nameless (such as artificial ones). */
264 if (DECL_NAME (current_function_decl))
265 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
266 else
267 name = "";
268 printable_name = (*decl_printable_name) (current_function_decl, 2);
271 declare_hidden_char_array ("__FUNCTION__", name);
272 declare_hidden_char_array ("__PRETTY_FUNCTION__", printable_name);
273 /* The ISO C people "of course" couldn't use __FUNCTION__ in the
274 ISO C 9x standard; instead a new variable is invented. */
275 declare_hidden_char_array ("__func__", name);
278 static void
279 declare_hidden_char_array (name, value)
280 const char *name, *value;
282 tree decl, type, init;
283 int vlen;
285 /* If the default size of char arrays isn't big enough for the name,
286 or if we want to give warnings for large objects, make a bigger one. */
287 vlen = strlen (value) + 1;
288 type = char_array_type_node;
289 if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < vlen
290 || warn_larger_than)
291 type = build_array_type (char_type_node,
292 build_index_type (build_int_2 (vlen, 0)));
293 push_obstacks_nochange ();
294 decl = build_decl (VAR_DECL, get_identifier (name), type);
295 TREE_STATIC (decl) = 1;
296 TREE_READONLY (decl) = 1;
297 TREE_ASM_WRITTEN (decl) = 1;
298 DECL_SOURCE_LINE (decl) = 0;
299 DECL_ARTIFICIAL (decl) = 1;
300 DECL_IN_SYSTEM_HEADER (decl) = 1;
301 DECL_IGNORED_P (decl) = 1;
302 init = build_string (vlen, value);
303 TREE_TYPE (init) = type;
304 DECL_INITIAL (decl) = init;
305 finish_decl (pushdecl (decl), init, NULL_TREE);
308 /* Given a chain of STRING_CST nodes,
309 concatenate them into one STRING_CST
310 and give it a suitable array-of-chars data type. */
312 tree
313 combine_strings (strings)
314 tree strings;
316 register tree value, t;
317 register int length = 1;
318 int wide_length = 0;
319 int wide_flag = 0;
320 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
321 int nchars;
323 if (TREE_CHAIN (strings))
325 /* More than one in the chain, so concatenate. */
326 register char *p, *q;
328 /* Don't include the \0 at the end of each substring,
329 except for the last one.
330 Count wide strings and ordinary strings separately. */
331 for (t = strings; t; t = TREE_CHAIN (t))
333 if (TREE_TYPE (t) == wchar_array_type_node)
335 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
336 wide_flag = 1;
338 else
339 length += (TREE_STRING_LENGTH (t) - 1);
342 /* If anything is wide, the non-wides will be converted,
343 which makes them take more space. */
344 if (wide_flag)
345 length = length * wchar_bytes + wide_length;
347 p = ggc_p ? ggc_alloc_string (NULL, length) : savealloc (length);
349 /* Copy the individual strings into the new combined string.
350 If the combined string is wide, convert the chars to ints
351 for any individual strings that are not wide. */
353 q = p;
354 for (t = strings; t; t = TREE_CHAIN (t))
356 int len = (TREE_STRING_LENGTH (t)
357 - ((TREE_TYPE (t) == wchar_array_type_node)
358 ? wchar_bytes : 1));
359 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
361 memcpy (q, TREE_STRING_POINTER (t), len);
362 q += len;
364 else
366 int i;
367 for (i = 0; i < len; i++)
369 if (WCHAR_TYPE_SIZE == HOST_BITS_PER_SHORT)
370 ((short *) q)[i] = TREE_STRING_POINTER (t)[i];
371 else
372 ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
374 q += len * wchar_bytes;
377 if (wide_flag)
379 int i;
380 for (i = 0; i < wchar_bytes; i++)
381 *q++ = 0;
383 else
384 *q = 0;
386 value = make_node (STRING_CST);
387 TREE_STRING_POINTER (value) = p;
388 TREE_STRING_LENGTH (value) = length;
390 else
392 value = strings;
393 length = TREE_STRING_LENGTH (value);
394 if (TREE_TYPE (value) == wchar_array_type_node)
395 wide_flag = 1;
398 /* Compute the number of elements, for the array type. */
399 nchars = wide_flag ? length / wchar_bytes : length;
401 /* Create the array type for the string constant.
402 -Wwrite-strings says make the string constant an array of const char
403 so that copying it to a non-const pointer will get a warning.
404 For C++, this is the standard behavior. */
405 if (flag_const_strings
406 && (! flag_traditional && ! flag_writable_strings))
408 tree elements
409 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
410 1, 0);
411 TREE_TYPE (value)
412 = build_array_type (elements,
413 build_index_type (build_int_2 (nchars - 1, 0)));
415 else
416 TREE_TYPE (value)
417 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
418 build_index_type (build_int_2 (nchars - 1, 0)));
420 TREE_CONSTANT (value) = 1;
421 TREE_READONLY (value) = ! flag_writable_strings;
422 TREE_STATIC (value) = 1;
423 return value;
426 /* To speed up processing of attributes, we maintain an array of
427 IDENTIFIER_NODES and the corresponding attribute types. */
429 /* Array to hold attribute information. */
431 static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50];
433 static int attrtab_idx = 0;
435 /* Add an entry to the attribute table above. */
437 static void
438 add_attribute (id, string, min_len, max_len, decl_req)
439 enum attrs id;
440 const char *string;
441 int min_len, max_len;
442 int decl_req;
444 char buf[100];
446 attrtab[attrtab_idx].id = id;
447 attrtab[attrtab_idx].name = get_identifier (string);
448 attrtab[attrtab_idx].min = min_len;
449 attrtab[attrtab_idx].max = max_len;
450 attrtab[attrtab_idx++].decl_req = decl_req;
452 sprintf (buf, "__%s__", string);
454 attrtab[attrtab_idx].id = id;
455 attrtab[attrtab_idx].name = get_identifier (buf);
456 attrtab[attrtab_idx].min = min_len;
457 attrtab[attrtab_idx].max = max_len;
458 attrtab[attrtab_idx++].decl_req = decl_req;
461 /* Initialize attribute table. */
463 static void
464 init_attributes ()
466 add_attribute (A_PACKED, "packed", 0, 0, 0);
467 add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1);
468 add_attribute (A_COMMON, "common", 0, 0, 1);
469 add_attribute (A_NORETURN, "noreturn", 0, 0, 1);
470 add_attribute (A_NORETURN, "volatile", 0, 0, 1);
471 add_attribute (A_UNUSED, "unused", 0, 0, 0);
472 add_attribute (A_CONST, "const", 0, 0, 1);
473 add_attribute (A_T_UNION, "transparent_union", 0, 0, 0);
474 add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1);
475 add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1);
476 add_attribute (A_MODE, "mode", 1, 1, 1);
477 add_attribute (A_SECTION, "section", 1, 1, 1);
478 add_attribute (A_ALIGNED, "aligned", 0, 1, 0);
479 add_attribute (A_FORMAT, "format", 3, 3, 1);
480 add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1);
481 add_attribute (A_WEAK, "weak", 0, 0, 1);
482 add_attribute (A_ALIAS, "alias", 1, 1, 1);
483 add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
484 add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
485 add_attribute (A_MALLOC, "malloc", 0, 0, 1);
486 add_attribute (A_NO_LIMIT_STACK, "no_stack_limit", 0, 0, 1);
489 /* Default implementation of valid_lang_attribute, below. By default, there
490 are no language-specific attributes. */
492 static int
493 default_valid_lang_attribute (attr_name, attr_args, decl, type)
494 tree attr_name ATTRIBUTE_UNUSED;
495 tree attr_args ATTRIBUTE_UNUSED;
496 tree decl ATTRIBUTE_UNUSED;
497 tree type ATTRIBUTE_UNUSED;
499 return 0;
502 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
503 attribute for either declaration DECL or type TYPE and 0 otherwise. */
505 int (*valid_lang_attribute) PROTO ((tree, tree, tree, tree))
506 = default_valid_lang_attribute;
508 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
509 and install them in NODE, which is either a DECL (including a TYPE_DECL)
510 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
511 and declaration modifiers but before the declaration proper. */
513 void
514 decl_attributes (node, attributes, prefix_attributes)
515 tree node, attributes, prefix_attributes;
517 tree decl = 0, type = 0;
518 int is_type = 0;
519 tree a;
521 if (attrtab_idx == 0)
522 init_attributes ();
524 if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd')
526 decl = node;
527 type = TREE_TYPE (decl);
528 is_type = TREE_CODE (node) == TYPE_DECL;
530 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't')
531 type = node, is_type = 1;
533 #ifdef PRAGMA_INSERT_ATTRIBUTES
534 /* If the code in c-pragma.c wants to insert some attributes then
535 allow it to do so. Do this before allowing machine back ends to
536 insert attributes, so that they have the opportunity to override
537 anything done here. */
538 PRAGMA_INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
539 #endif
541 #ifdef INSERT_ATTRIBUTES
542 INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
543 #endif
545 attributes = chainon (prefix_attributes, attributes);
547 for (a = attributes; a; a = TREE_CHAIN (a))
549 tree name = TREE_PURPOSE (a);
550 tree args = TREE_VALUE (a);
551 int i;
552 enum attrs id;
554 for (i = 0; i < attrtab_idx; i++)
555 if (attrtab[i].name == name)
556 break;
558 if (i == attrtab_idx)
560 if (! valid_machine_attribute (name, args, decl, type)
561 && ! (* valid_lang_attribute) (name, args, decl, type))
562 warning ("`%s' attribute directive ignored",
563 IDENTIFIER_POINTER (name));
564 else if (decl != 0)
565 type = TREE_TYPE (decl);
566 continue;
568 else if (attrtab[i].decl_req && decl == 0)
570 warning ("`%s' attribute does not apply to types",
571 IDENTIFIER_POINTER (name));
572 continue;
574 else if (list_length (args) < attrtab[i].min
575 || list_length (args) > attrtab[i].max)
577 error ("wrong number of arguments specified for `%s' attribute",
578 IDENTIFIER_POINTER (name));
579 continue;
582 id = attrtab[i].id;
583 switch (id)
585 case A_PACKED:
586 if (is_type)
587 TYPE_PACKED (type) = 1;
588 else if (TREE_CODE (decl) == FIELD_DECL)
589 DECL_PACKED (decl) = 1;
590 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
591 used for DECL_REGISTER. It wouldn't mean anything anyway. */
592 else
593 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
594 break;
596 case A_NOCOMMON:
597 if (TREE_CODE (decl) == VAR_DECL)
598 DECL_COMMON (decl) = 0;
599 else
600 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
601 break;
603 case A_COMMON:
604 if (TREE_CODE (decl) == VAR_DECL)
605 DECL_COMMON (decl) = 1;
606 else
607 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
608 break;
610 case A_NORETURN:
611 if (TREE_CODE (decl) == FUNCTION_DECL)
612 TREE_THIS_VOLATILE (decl) = 1;
613 else if (TREE_CODE (type) == POINTER_TYPE
614 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
615 TREE_TYPE (decl) = type
616 = build_pointer_type
617 (build_type_variant (TREE_TYPE (type),
618 TREE_READONLY (TREE_TYPE (type)), 1));
619 else
620 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
621 break;
623 case A_MALLOC:
624 if (TREE_CODE (decl) == FUNCTION_DECL)
625 DECL_IS_MALLOC (decl) = 1;
626 else
627 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
628 break;
630 case A_UNUSED:
631 if (is_type)
632 TREE_USED (type) = 1;
633 else if (TREE_CODE (decl) == PARM_DECL
634 || TREE_CODE (decl) == VAR_DECL
635 || TREE_CODE (decl) == FUNCTION_DECL
636 || TREE_CODE (decl) == LABEL_DECL)
637 TREE_USED (decl) = 1;
638 else
639 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
640 break;
642 case A_CONST:
643 if (TREE_CODE (decl) == FUNCTION_DECL)
644 TREE_READONLY (decl) = 1;
645 else if (TREE_CODE (type) == POINTER_TYPE
646 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
647 TREE_TYPE (decl) = type
648 = build_pointer_type
649 (build_type_variant (TREE_TYPE (type), 1,
650 TREE_THIS_VOLATILE (TREE_TYPE (type))));
651 else
652 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name));
653 break;
655 case A_T_UNION:
656 if (is_type
657 && TREE_CODE (type) == UNION_TYPE
658 && (decl == 0
659 || (TYPE_FIELDS (type) != 0
660 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))))
661 TYPE_TRANSPARENT_UNION (type) = 1;
662 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
663 && TREE_CODE (type) == UNION_TYPE
664 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))
665 DECL_TRANSPARENT_UNION (decl) = 1;
666 else
667 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
668 break;
670 case A_CONSTRUCTOR:
671 if (TREE_CODE (decl) == FUNCTION_DECL
672 && TREE_CODE (type) == FUNCTION_TYPE
673 && decl_function_context (decl) == 0)
675 DECL_STATIC_CONSTRUCTOR (decl) = 1;
676 TREE_USED (decl) = 1;
678 else
679 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
680 break;
682 case A_DESTRUCTOR:
683 if (TREE_CODE (decl) == FUNCTION_DECL
684 && TREE_CODE (type) == FUNCTION_TYPE
685 && decl_function_context (decl) == 0)
687 DECL_STATIC_DESTRUCTOR (decl) = 1;
688 TREE_USED (decl) = 1;
690 else
691 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
692 break;
694 case A_MODE:
695 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
696 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
697 else
699 int j;
700 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
701 int len = strlen (p);
702 enum machine_mode mode = VOIDmode;
703 tree typefm;
705 if (len > 4 && p[0] == '_' && p[1] == '_'
706 && p[len - 1] == '_' && p[len - 2] == '_')
708 char *newp = (char *) alloca (len - 1);
710 strcpy (newp, &p[2]);
711 newp[len - 4] = '\0';
712 p = newp;
715 /* Give this decl a type with the specified mode.
716 First check for the special modes. */
717 if (! strcmp (p, "byte"))
718 mode = byte_mode;
719 else if (!strcmp (p, "word"))
720 mode = word_mode;
721 else if (! strcmp (p, "pointer"))
722 mode = ptr_mode;
723 else
724 for (j = 0; j < NUM_MACHINE_MODES; j++)
725 if (!strcmp (p, GET_MODE_NAME (j)))
726 mode = (enum machine_mode) j;
728 if (mode == VOIDmode)
729 error ("unknown machine mode `%s'", p);
730 else if (0 == (typefm = type_for_mode (mode,
731 TREE_UNSIGNED (type))))
732 error ("no data type for mode `%s'", p);
733 else
735 TREE_TYPE (decl) = type = typefm;
736 DECL_SIZE (decl) = 0;
737 layout_decl (decl, 0);
740 break;
742 case A_SECTION:
743 #ifdef ASM_OUTPUT_SECTION_NAME
744 if ((TREE_CODE (decl) == FUNCTION_DECL
745 || TREE_CODE (decl) == VAR_DECL)
746 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
748 if (TREE_CODE (decl) == VAR_DECL
749 && current_function_decl != NULL_TREE
750 && ! TREE_STATIC (decl))
751 error_with_decl (decl,
752 "section attribute cannot be specified for local variables");
753 /* The decl may have already been given a section attribute from
754 a previous declaration. Ensure they match. */
755 else if (DECL_SECTION_NAME (decl) != NULL_TREE
756 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
757 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
758 error_with_decl (node,
759 "section of `%s' conflicts with previous declaration");
760 else
761 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
763 else
764 error_with_decl (node,
765 "section attribute not allowed for `%s'");
766 #else
767 error_with_decl (node,
768 "section attributes are not supported for this target");
769 #endif
770 break;
772 case A_ALIGNED:
774 tree align_expr
775 = (args ? TREE_VALUE (args)
776 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
777 int align;
779 /* Strip any NOPs of any kind. */
780 while (TREE_CODE (align_expr) == NOP_EXPR
781 || TREE_CODE (align_expr) == CONVERT_EXPR
782 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
783 align_expr = TREE_OPERAND (align_expr, 0);
785 if (TREE_CODE (align_expr) != INTEGER_CST)
787 error ("requested alignment is not a constant");
788 continue;
791 align = TREE_INT_CST_LOW (align_expr) * BITS_PER_UNIT;
793 if (exact_log2 (align) == -1)
794 error ("requested alignment is not a power of 2");
795 else if (is_type)
796 TYPE_ALIGN (type) = align;
797 else if (TREE_CODE (decl) != VAR_DECL
798 && TREE_CODE (decl) != FIELD_DECL)
799 error_with_decl (decl,
800 "alignment may not be specified for `%s'");
801 else
802 DECL_ALIGN (decl) = align;
804 break;
806 case A_FORMAT:
808 tree format_type_id = TREE_VALUE (args);
809 tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
810 tree first_arg_num_expr
811 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
812 int format_num;
813 int first_arg_num;
814 enum format_type format_type;
815 tree argument;
816 int arg_num;
818 if (TREE_CODE (decl) != FUNCTION_DECL)
820 error_with_decl (decl,
821 "argument format specified for non-function `%s'");
822 continue;
825 if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
827 error ("unrecognized format specifier");
828 continue;
830 else
832 const char *p = IDENTIFIER_POINTER (format_type_id);
834 if (!strcmp (p, "printf") || !strcmp (p, "__printf__"))
835 format_type = printf_format_type;
836 else if (!strcmp (p, "scanf") || !strcmp (p, "__scanf__"))
837 format_type = scanf_format_type;
838 else if (!strcmp (p, "strftime")
839 || !strcmp (p, "__strftime__"))
840 format_type = strftime_format_type;
841 else
843 warning ("`%s' is an unrecognized format function type", p);
844 continue;
848 /* Strip any conversions from the string index and first arg number
849 and verify they are constants. */
850 while (TREE_CODE (format_num_expr) == NOP_EXPR
851 || TREE_CODE (format_num_expr) == CONVERT_EXPR
852 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
853 format_num_expr = TREE_OPERAND (format_num_expr, 0);
855 while (TREE_CODE (first_arg_num_expr) == NOP_EXPR
856 || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR
857 || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR)
858 first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0);
860 if (TREE_CODE (format_num_expr) != INTEGER_CST
861 || TREE_CODE (first_arg_num_expr) != INTEGER_CST)
863 error ("format string has non-constant operand number");
864 continue;
867 format_num = TREE_INT_CST_LOW (format_num_expr);
868 first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr);
869 if (first_arg_num != 0 && first_arg_num <= format_num)
871 error ("format string arg follows the args to be formatted");
872 continue;
875 /* If a parameter list is specified, verify that the format_num
876 argument is actually a string, in case the format attribute
877 is in error. */
878 argument = TYPE_ARG_TYPES (type);
879 if (argument)
881 for (arg_num = 1; ; ++arg_num)
883 if (argument == 0 || arg_num == format_num)
884 break;
885 argument = TREE_CHAIN (argument);
887 if (! argument
888 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
889 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
890 != char_type_node))
892 error ("format string arg not a string type");
893 continue;
895 if (first_arg_num != 0)
897 /* Verify that first_arg_num points to the last arg,
898 the ... */
899 while (argument)
900 arg_num++, argument = TREE_CHAIN (argument);
901 if (arg_num != first_arg_num)
903 error ("args to be formatted is not ...");
904 continue;
909 record_function_format (DECL_NAME (decl),
910 DECL_ASSEMBLER_NAME (decl),
911 format_type, format_num, first_arg_num);
912 break;
915 case A_FORMAT_ARG:
917 tree format_num_expr = TREE_VALUE (args);
918 int format_num, arg_num;
919 tree argument;
921 if (TREE_CODE (decl) != FUNCTION_DECL)
923 error_with_decl (decl,
924 "argument format specified for non-function `%s'");
925 continue;
928 /* Strip any conversions from the first arg number and verify it
929 is a constant. */
930 while (TREE_CODE (format_num_expr) == NOP_EXPR
931 || TREE_CODE (format_num_expr) == CONVERT_EXPR
932 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
933 format_num_expr = TREE_OPERAND (format_num_expr, 0);
935 if (TREE_CODE (format_num_expr) != INTEGER_CST)
937 error ("format string has non-constant operand number");
938 continue;
941 format_num = TREE_INT_CST_LOW (format_num_expr);
943 /* If a parameter list is specified, verify that the format_num
944 argument is actually a string, in case the format attribute
945 is in error. */
946 argument = TYPE_ARG_TYPES (type);
947 if (argument)
949 for (arg_num = 1; ; ++arg_num)
951 if (argument == 0 || arg_num == format_num)
952 break;
953 argument = TREE_CHAIN (argument);
955 if (! argument
956 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
957 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
958 != char_type_node))
960 error ("format string arg not a string type");
961 continue;
965 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != POINTER_TYPE
966 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl))))
967 != char_type_node))
969 error ("function does not return string type");
970 continue;
973 record_international_format (DECL_NAME (decl),
974 DECL_ASSEMBLER_NAME (decl),
975 format_num);
976 break;
979 case A_WEAK:
980 declare_weak (decl);
981 break;
983 case A_ALIAS:
984 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
985 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
986 error_with_decl (decl,
987 "`%s' defined both normally and as an alias");
988 else if (decl_function_context (decl) == 0)
990 tree id;
992 id = TREE_VALUE (args);
993 if (TREE_CODE (id) != STRING_CST)
995 error ("alias arg not a string");
996 break;
998 id = get_identifier (TREE_STRING_POINTER (id));
1000 if (TREE_CODE (decl) == FUNCTION_DECL)
1001 DECL_INITIAL (decl) = error_mark_node;
1002 else
1003 DECL_EXTERNAL (decl) = 0;
1004 assemble_alias (decl, id);
1006 else
1007 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1008 break;
1010 case A_NO_CHECK_MEMORY_USAGE:
1011 if (TREE_CODE (decl) != FUNCTION_DECL)
1013 error_with_decl (decl,
1014 "`%s' attribute applies only to functions",
1015 IDENTIFIER_POINTER (name));
1017 else if (DECL_INITIAL (decl))
1019 error_with_decl (decl,
1020 "can't set `%s' attribute after definition",
1021 IDENTIFIER_POINTER (name));
1023 else
1024 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
1025 break;
1027 case A_NO_INSTRUMENT_FUNCTION:
1028 if (TREE_CODE (decl) != FUNCTION_DECL)
1030 error_with_decl (decl,
1031 "`%s' attribute applies only to functions",
1032 IDENTIFIER_POINTER (name));
1034 else if (DECL_INITIAL (decl))
1036 error_with_decl (decl,
1037 "can't set `%s' attribute after definition",
1038 IDENTIFIER_POINTER (name));
1040 else
1041 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
1042 break;
1044 case A_NO_LIMIT_STACK:
1045 if (TREE_CODE (decl) != FUNCTION_DECL)
1047 error_with_decl (decl,
1048 "`%s' attribute applies only to functions",
1049 IDENTIFIER_POINTER (name));
1051 else if (DECL_INITIAL (decl))
1053 error_with_decl (decl,
1054 "can't set `%s' attribute after definition",
1055 IDENTIFIER_POINTER (name));
1057 else
1058 DECL_NO_LIMIT_STACK (decl) = 1;
1059 break;
1064 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1065 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1067 The head of the declspec list is stored in DECLSPECS.
1068 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1070 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1071 the list elements. We drop the containing TREE_LIST nodes and link the
1072 resulting attributes together the way decl_attributes expects them. */
1074 void
1075 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1076 tree specs_attrs;
1077 tree *declspecs, *prefix_attributes;
1079 tree t, s, a, next, specs, attrs;
1081 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1082 if (specs_attrs != NULL_TREE
1083 && TREE_CODE (specs_attrs) != TREE_LIST)
1085 *declspecs = specs_attrs;
1086 *prefix_attributes = NULL_TREE;
1087 return;
1090 /* Remember to keep the lists in the same order, element-wise. */
1092 specs = s = NULL_TREE;
1093 attrs = a = NULL_TREE;
1094 for (t = specs_attrs; t; t = next)
1096 next = TREE_CHAIN (t);
1097 /* Declspecs have a non-NULL TREE_VALUE. */
1098 if (TREE_VALUE (t) != NULL_TREE)
1100 if (specs == NULL_TREE)
1101 specs = s = t;
1102 else
1104 TREE_CHAIN (s) = t;
1105 s = t;
1108 else
1110 if (attrs == NULL_TREE)
1111 attrs = a = TREE_PURPOSE (t);
1112 else
1114 TREE_CHAIN (a) = TREE_PURPOSE (t);
1115 a = TREE_PURPOSE (t);
1117 /* More attrs can be linked here, move A to the end. */
1118 while (TREE_CHAIN (a) != NULL_TREE)
1119 a = TREE_CHAIN (a);
1123 /* Terminate the lists. */
1124 if (s != NULL_TREE)
1125 TREE_CHAIN (s) = NULL_TREE;
1126 if (a != NULL_TREE)
1127 TREE_CHAIN (a) = NULL_TREE;
1129 /* All done. */
1130 *declspecs = specs;
1131 *prefix_attributes = attrs;
1134 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1135 This function is used by the parser when a rule will accept attributes
1136 in a particular position, but we don't want to support that just yet.
1138 A warning is issued for every ignored attribute. */
1140 tree
1141 strip_attrs (specs_attrs)
1142 tree specs_attrs;
1144 tree specs, attrs;
1146 split_specs_attrs (specs_attrs, &specs, &attrs);
1148 while (attrs)
1150 warning ("`%s' attribute ignored",
1151 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1152 attrs = TREE_CHAIN (attrs);
1155 return specs;
1158 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1159 a parameter list. */
1161 #define T_I &integer_type_node
1162 #define T_L &long_integer_type_node
1163 #define T_LL &long_long_integer_type_node
1164 #define T_S &short_integer_type_node
1165 #define T_UI &unsigned_type_node
1166 #define T_UL &long_unsigned_type_node
1167 #define T_ULL &long_long_unsigned_type_node
1168 #define T_US &short_unsigned_type_node
1169 #define T_F &float_type_node
1170 #define T_D &double_type_node
1171 #define T_LD &long_double_type_node
1172 #define T_C &char_type_node
1173 #define T_UC &unsigned_char_type_node
1174 #define T_V &void_type_node
1175 #define T_W &wchar_type_node
1176 #define T_ST &sizetype
1178 typedef struct {
1179 const char *format_chars;
1180 int pointer_count;
1181 /* Type of argument if no length modifier is used. */
1182 tree *nolen;
1183 /* Type of argument if length modifier for shortening to byte is used.
1184 If NULL, then this modifier is not allowed. */
1185 tree *hhlen;
1186 /* Type of argument if length modifier for shortening is used.
1187 If NULL, then this modifier is not allowed. */
1188 tree *hlen;
1189 /* Type of argument if length modifier `l' is used.
1190 If NULL, then this modifier is not allowed. */
1191 tree *llen;
1192 /* Type of argument if length modifier `q' or `ll' is used.
1193 If NULL, then this modifier is not allowed. */
1194 tree *qlen;
1195 /* Type of argument if length modifier `L' is used.
1196 If NULL, then this modifier is not allowed. */
1197 tree *bigllen;
1198 /* Type of argument if length modifier `Z' is used.
1199 If NULL, then this modifier is not allowed. */
1200 tree *zlen;
1201 /* List of other modifier characters allowed with these options. */
1202 const char *flag_chars;
1203 } format_char_info;
1205 static format_char_info print_char_table[] = {
1206 { "di", 0, T_I, T_I, T_I, T_L, T_LL, T_LL, T_ST, "-wp0 +" },
1207 { "oxX", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, "-wp0#" },
1208 { "u", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, "-wp0" },
1209 /* A GNU extension. */
1210 { "m", 0, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
1211 { "feEgGaA", 0, T_D, NULL, NULL, NULL, NULL, T_LD, NULL, "-wp0 +#" },
1212 { "c", 0, T_I, NULL, NULL, T_W, NULL, NULL, NULL, "-w" },
1213 { "C", 0, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
1214 { "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "-wp" },
1215 { "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
1216 { "p", 1, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
1217 { "n", 1, T_I, NULL, T_S, T_L, T_LL, NULL, NULL, "" },
1218 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1221 static format_char_info scan_char_table[] = {
1222 { "di", 1, T_I, T_C, T_S, T_L, T_LL, T_LL, NULL, "*" },
1223 { "ouxX", 1, T_UI, T_UC, T_US, T_UL, T_ULL, T_ULL, NULL, "*" },
1224 { "efgEGaA", 1, T_F, NULL, NULL, T_D, NULL, T_LD, NULL, "*" },
1225 { "c", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "*" },
1226 { "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "*a" },
1227 { "[", 1, T_C, NULL, NULL, NULL, NULL, NULL, NULL, "*a" },
1228 { "C", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "*" },
1229 { "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "*a" },
1230 { "p", 2, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "*" },
1231 { "n", 1, T_I, T_C, T_S, T_L, T_LL, NULL, NULL, "" },
1232 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1235 /* Handle format characters recognized by glibc's strftime.c.
1236 '2' - MUST do years as only two digits
1237 '3' - MAY do years as only two digits (depending on locale)
1238 'E' - E modifier is acceptable
1239 'O' - O modifier is acceptable to Standard C
1240 'o' - O modifier is acceptable as a GNU extension
1241 'G' - other GNU extensions */
1243 static format_char_info time_char_table[] = {
1244 { "y", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2EO-_0w" },
1245 { "D", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2" },
1246 { "g", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2O-_0w" },
1247 { "cx", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "3E" },
1248 { "%RTXnrt", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "" },
1249 { "P", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "G" },
1250 { "HIMSUWdemw", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Ow" },
1251 { "Vju", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow" },
1252 { "Gklsz", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0OGw" },
1253 { "ABZa", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^#" },
1254 { "p", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "#" },
1255 { "bh", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^" },
1256 { "CY", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0EOw" },
1257 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1260 typedef struct function_format_info
1262 struct function_format_info *next; /* next structure on the list */
1263 tree name; /* identifier such as "printf" */
1264 tree assembler_name; /* optional mangled identifier (for C++) */
1265 enum format_type format_type; /* type of format (printf, scanf, etc.) */
1266 int format_num; /* number of format argument */
1267 int first_arg_num; /* number of first arg (zero for varargs) */
1268 } function_format_info;
1270 static function_format_info *function_format_list = NULL;
1272 typedef struct international_format_info
1274 struct international_format_info *next; /* next structure on the list */
1275 tree name; /* identifier such as "gettext" */
1276 tree assembler_name; /* optional mangled identifier (for C++) */
1277 int format_num; /* number of format argument */
1278 } international_format_info;
1280 static international_format_info *international_format_list = NULL;
1282 static void check_format_info PROTO((function_format_info *, tree));
1284 /* Initialize the table of functions to perform format checking on.
1285 The ANSI functions are always checked (whether <stdio.h> is
1286 included or not), since it is common to call printf without
1287 including <stdio.h>. There shouldn't be a problem with this,
1288 since ANSI reserves these function names whether you include the
1289 header file or not. In any case, the checking is harmless.
1291 Also initialize the name of function that modify the format string for
1292 internationalization purposes. */
1294 void
1295 init_function_format_info ()
1297 record_function_format (get_identifier ("printf"), NULL_TREE,
1298 printf_format_type, 1, 2);
1299 record_function_format (get_identifier ("fprintf"), NULL_TREE,
1300 printf_format_type, 2, 3);
1301 record_function_format (get_identifier ("sprintf"), NULL_TREE,
1302 printf_format_type, 2, 3);
1303 record_function_format (get_identifier ("scanf"), NULL_TREE,
1304 scanf_format_type, 1, 2);
1305 record_function_format (get_identifier ("fscanf"), NULL_TREE,
1306 scanf_format_type, 2, 3);
1307 record_function_format (get_identifier ("sscanf"), NULL_TREE,
1308 scanf_format_type, 2, 3);
1309 record_function_format (get_identifier ("vprintf"), NULL_TREE,
1310 printf_format_type, 1, 0);
1311 record_function_format (get_identifier ("vfprintf"), NULL_TREE,
1312 printf_format_type, 2, 0);
1313 record_function_format (get_identifier ("vsprintf"), NULL_TREE,
1314 printf_format_type, 2, 0);
1315 record_function_format (get_identifier ("strftime"), NULL_TREE,
1316 strftime_format_type, 3, 0);
1318 record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
1319 record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
1320 record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
1323 /* Record information for argument format checking. FUNCTION_IDENT is
1324 the identifier node for the name of the function to check (its decl
1325 need not exist yet).
1326 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
1327 of the argument which is the format control string (starting from 1).
1328 FIRST_ARG_NUM is the number of the first actual argument to check
1329 against the format string, or zero if no checking is not be done
1330 (e.g. for varargs such as vfprintf). */
1332 static void
1333 record_function_format (name, assembler_name, format_type,
1334 format_num, first_arg_num)
1335 tree name;
1336 tree assembler_name;
1337 enum format_type format_type;
1338 int format_num;
1339 int first_arg_num;
1341 function_format_info *info;
1343 /* Re-use existing structure if it's there. */
1345 for (info = function_format_list; info; info = info->next)
1347 if (info->name == name && info->assembler_name == assembler_name)
1348 break;
1350 if (! info)
1352 info = (function_format_info *) xmalloc (sizeof (function_format_info));
1353 info->next = function_format_list;
1354 function_format_list = info;
1356 info->name = name;
1357 info->assembler_name = assembler_name;
1360 info->format_type = format_type;
1361 info->format_num = format_num;
1362 info->first_arg_num = first_arg_num;
1365 /* Record information for the names of function that modify the format
1366 argument to format functions. FUNCTION_IDENT is the identifier node for
1367 the name of the function (its decl need not exist yet) and FORMAT_NUM is
1368 the number of the argument which is the format control string (starting
1369 from 1). */
1371 static void
1372 record_international_format (name, assembler_name, format_num)
1373 tree name;
1374 tree assembler_name;
1375 int format_num;
1377 international_format_info *info;
1379 /* Re-use existing structure if it's there. */
1381 for (info = international_format_list; info; info = info->next)
1383 if (info->name == name && info->assembler_name == assembler_name)
1384 break;
1387 if (! info)
1389 info
1390 = (international_format_info *)
1391 xmalloc (sizeof (international_format_info));
1392 info->next = international_format_list;
1393 international_format_list = info;
1395 info->name = name;
1396 info->assembler_name = assembler_name;
1399 info->format_num = format_num;
1402 static void
1403 tfaff ()
1405 warning ("too few arguments for format");
1408 /* Check the argument list of a call to printf, scanf, etc.
1409 NAME is the function identifier.
1410 ASSEMBLER_NAME is the function's assembler identifier.
1411 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1412 PARAMS is the list of argument values. */
1414 void
1415 check_function_format (name, assembler_name, params)
1416 tree name;
1417 tree assembler_name;
1418 tree params;
1420 function_format_info *info;
1422 /* See if this function is a format function. */
1423 for (info = function_format_list; info; info = info->next)
1425 if (info->assembler_name
1426 ? (info->assembler_name == assembler_name)
1427 : (info->name == name))
1429 /* Yup; check it. */
1430 check_format_info (info, params);
1431 break;
1436 /* Check the argument list of a call to printf, scanf, etc.
1437 INFO points to the function_format_info structure.
1438 PARAMS is the list of argument values. */
1440 static void
1441 check_format_info (info, params)
1442 function_format_info *info;
1443 tree params;
1445 int i;
1446 int arg_num;
1447 int suppressed, wide, precise;
1448 int length_char = 0;
1449 int format_char;
1450 int format_length;
1451 tree format_tree;
1452 tree cur_param;
1453 tree cur_type;
1454 tree wanted_type;
1455 tree first_fillin_param;
1456 const char *format_chars;
1457 format_char_info *fci = NULL;
1458 char flag_chars[8];
1459 int has_operand_number = 0;
1461 /* Skip to format argument. If the argument isn't available, there's
1462 no work for us to do; prototype checking will catch the problem. */
1463 for (arg_num = 1; ; ++arg_num)
1465 if (params == 0)
1466 return;
1467 if (arg_num == info->format_num)
1468 break;
1469 params = TREE_CHAIN (params);
1471 format_tree = TREE_VALUE (params);
1472 params = TREE_CHAIN (params);
1473 if (format_tree == 0)
1474 return;
1476 /* We can only check the format if it's a string constant. */
1477 while (TREE_CODE (format_tree) == NOP_EXPR)
1478 format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
1480 if (TREE_CODE (format_tree) == CALL_EXPR
1481 && TREE_CODE (TREE_OPERAND (format_tree, 0)) == ADDR_EXPR
1482 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0))
1483 == FUNCTION_DECL))
1485 tree function = TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0);
1487 /* See if this is a call to a known internationalization function
1488 that modifies the format arg. */
1489 international_format_info *info;
1491 for (info = international_format_list; info; info = info->next)
1492 if (info->assembler_name
1493 ? (info->assembler_name == DECL_ASSEMBLER_NAME (function))
1494 : (info->name == DECL_NAME (function)))
1496 tree inner_args;
1497 int i;
1499 for (inner_args = TREE_OPERAND (format_tree, 1), i = 1;
1500 inner_args != 0;
1501 inner_args = TREE_CHAIN (inner_args), i++)
1502 if (i == info->format_num)
1504 format_tree = TREE_VALUE (inner_args);
1506 while (TREE_CODE (format_tree) == NOP_EXPR)
1507 format_tree = TREE_OPERAND (format_tree, 0);
1512 if (integer_zerop (format_tree))
1514 warning ("null format string");
1515 return;
1517 if (TREE_CODE (format_tree) != ADDR_EXPR)
1519 /* The user may get multiple warnings if the supplied argument
1520 isn't even a string pointer. */
1521 /* Functions taking a va_list normally pass a non-literal format
1522 string. These functions typically are declared with
1523 first_arg_num == 0, so avoid warning in those cases. */
1524 if (info->first_arg_num != 0)
1525 warning ("format not a string literal, argument types not checked");
1526 return;
1528 format_tree = TREE_OPERAND (format_tree, 0);
1529 if (TREE_CODE (format_tree) != STRING_CST)
1531 /* The user may get multiple warnings if the supplied argument
1532 isn't even a string pointer. */
1533 /* Functions taking a va_list normally pass a non-literal format
1534 string. These functions typically are declared with
1535 first_arg_num == 0, so avoid warning in those cases. */
1536 if (info->first_arg_num != 0)
1537 warning ("format not a string literal, argument types not checked");
1538 return;
1540 format_chars = TREE_STRING_POINTER (format_tree);
1541 format_length = TREE_STRING_LENGTH (format_tree);
1542 if (format_length <= 1)
1543 warning ("zero-length format string");
1544 if (format_chars[--format_length] != 0)
1546 warning ("unterminated format string");
1547 return;
1549 /* Skip to first argument to check. */
1550 while (arg_num + 1 < info->first_arg_num)
1552 if (params == 0)
1553 return;
1554 params = TREE_CHAIN (params);
1555 ++arg_num;
1558 first_fillin_param = params;
1559 while (1)
1561 int aflag;
1562 if (*format_chars == 0)
1564 if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
1565 warning ("embedded `\\0' in format");
1566 if (info->first_arg_num != 0 && params != 0 && ! has_operand_number)
1567 warning ("too many arguments for format");
1568 return;
1570 if (*format_chars++ != '%')
1571 continue;
1572 if (*format_chars == 0)
1574 warning ("spurious trailing `%%' in format");
1575 continue;
1577 if (*format_chars == '%')
1579 ++format_chars;
1580 continue;
1582 flag_chars[0] = 0;
1583 suppressed = wide = precise = FALSE;
1584 if (info->format_type == scanf_format_type)
1586 suppressed = *format_chars == '*';
1587 if (suppressed)
1588 ++format_chars;
1589 while (ISDIGIT (*format_chars))
1590 ++format_chars;
1592 else if (info->format_type == strftime_format_type)
1594 while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0)
1596 if (pedantic)
1597 warning ("ANSI C does not support the strftime `%c' flag",
1598 *format_chars);
1599 if (index (flag_chars, *format_chars) != 0)
1601 warning ("repeated `%c' flag in format",
1602 *format_chars);
1603 ++format_chars;
1605 else
1607 i = strlen (flag_chars);
1608 flag_chars[i++] = *format_chars++;
1609 flag_chars[i] = 0;
1612 while (ISDIGIT ((unsigned char) *format_chars))
1614 wide = TRUE;
1615 ++format_chars;
1617 if (wide && pedantic)
1618 warning ("ANSI C does not support strftime format width");
1619 if (*format_chars == 'E' || *format_chars == 'O')
1621 i = strlen (flag_chars);
1622 flag_chars[i++] = *format_chars++;
1623 flag_chars[i] = 0;
1624 if (*format_chars == 'E' || *format_chars == 'O')
1626 warning ("multiple E/O modifiers in format");
1627 while (*format_chars == 'E' || *format_chars == 'O')
1628 ++format_chars;
1632 else if (info->format_type == printf_format_type)
1634 /* See if we have a number followed by a dollar sign. If we do,
1635 it is an operand number, so set PARAMS to that operand. */
1636 if (*format_chars >= '0' && *format_chars <= '9')
1638 const char *p = format_chars;
1640 while (*p >= '0' && *p++ <= '9')
1643 if (*p == '$')
1645 int opnum = atoi (format_chars);
1647 params = first_fillin_param;
1648 format_chars = p + 1;
1649 has_operand_number = 1;
1651 for (i = 1; i < opnum && params != 0; i++)
1652 params = TREE_CHAIN (params);
1654 if (opnum == 0 || params == 0)
1656 warning ("operand number out of range in format");
1657 return;
1662 while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
1664 if (index (flag_chars, *format_chars) != 0)
1665 warning ("repeated `%c' flag in format", *format_chars++);
1666 else
1668 i = strlen (flag_chars);
1669 flag_chars[i++] = *format_chars++;
1670 flag_chars[i] = 0;
1673 /* "If the space and + flags both appear,
1674 the space flag will be ignored." */
1675 if (index (flag_chars, ' ') != 0
1676 && index (flag_chars, '+') != 0)
1677 warning ("use of both ` ' and `+' flags in format");
1678 /* "If the 0 and - flags both appear,
1679 the 0 flag will be ignored." */
1680 if (index (flag_chars, '0') != 0
1681 && index (flag_chars, '-') != 0)
1682 warning ("use of both `0' and `-' flags in format");
1683 if (*format_chars == '*')
1685 wide = TRUE;
1686 /* "...a field width...may be indicated by an asterisk.
1687 In this case, an int argument supplies the field width..." */
1688 ++format_chars;
1689 if (params == 0)
1691 tfaff ();
1692 return;
1694 if (info->first_arg_num != 0)
1696 cur_param = TREE_VALUE (params);
1697 params = TREE_CHAIN (params);
1698 ++arg_num;
1699 /* size_t is generally not valid here.
1700 It will work on most machines, because size_t and int
1701 have the same mode. But might as well warn anyway,
1702 since it will fail on other machines. */
1703 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1704 != integer_type_node)
1706 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1707 != unsigned_type_node))
1708 warning ("field width is not type int (arg %d)", arg_num);
1711 else
1713 while (ISDIGIT (*format_chars))
1715 wide = TRUE;
1716 ++format_chars;
1719 if (*format_chars == '.')
1721 precise = TRUE;
1722 ++format_chars;
1723 if (*format_chars != '*' && !ISDIGIT (*format_chars))
1724 warning ("`.' not followed by `*' or digit in format");
1725 /* "...a...precision...may be indicated by an asterisk.
1726 In this case, an int argument supplies the...precision." */
1727 if (*format_chars == '*')
1729 if (info->first_arg_num != 0)
1731 ++format_chars;
1732 if (params == 0)
1734 tfaff ();
1735 return;
1737 cur_param = TREE_VALUE (params);
1738 params = TREE_CHAIN (params);
1739 ++arg_num;
1740 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1741 != integer_type_node)
1742 warning ("field width is not type int (arg %d)",
1743 arg_num);
1746 else
1748 while (ISDIGIT (*format_chars))
1749 ++format_chars;
1754 aflag = 0;
1756 if (info->format_type != strftime_format_type)
1758 if (*format_chars == 'h' || *format_chars == 'l')
1759 length_char = *format_chars++;
1760 else if (*format_chars == 'q' || *format_chars == 'L')
1762 length_char = *format_chars++;
1763 if (pedantic)
1764 warning ("ANSI C does not support the `%c' length modifier",
1765 length_char);
1767 else if (*format_chars == 'Z')
1769 length_char = *format_chars++;
1770 if (pedantic)
1771 warning ("ANSI C does not support the `Z' length modifier");
1773 else
1774 length_char = 0;
1775 if (length_char == 'l' && *format_chars == 'l')
1777 length_char = 'q', format_chars++;
1778 /* FIXME: Is allowed in ISO C 9x. */
1779 if (pedantic)
1780 warning ("ANSI C does not support the `ll' length modifier");
1782 else if (length_char == 'h' && *format_chars == 'h')
1784 length_char = 'H', format_chars++;
1785 /* FIXME: Is allowed in ISO C 9x. */
1786 if (pedantic)
1787 warning ("ANSI C does not support the `hh' length modifier");
1789 if (*format_chars == 'a' && info->format_type == scanf_format_type)
1791 if (format_chars[1] == 's' || format_chars[1] == 'S'
1792 || format_chars[1] == '[')
1794 /* `a' is used as a flag. */
1795 aflag = 1;
1796 format_chars++;
1799 if (suppressed && length_char != 0)
1800 warning ("use of `*' and `%c' together in format", length_char);
1802 format_char = *format_chars;
1803 if (format_char == 0
1804 || (info->format_type != strftime_format_type && format_char == '%'))
1806 warning ("conversion lacks type at end of format");
1807 continue;
1809 /* The m, C, and S formats are GNU extensions. */
1810 if (pedantic && info->format_type != strftime_format_type
1811 && (format_char == 'm' || format_char == 'C' || format_char == 'S'))
1812 warning ("ANSI C does not support the `%c' format", format_char);
1813 /* ??? The a and A formats are C9X extensions, and should be allowed
1814 when a C9X option is added. */
1815 if (pedantic && info->format_type != strftime_format_type
1816 && (format_char == 'a' || format_char == 'A'))
1817 warning ("ANSI C does not support the `%c' format", format_char);
1818 format_chars++;
1819 switch (info->format_type)
1821 case printf_format_type:
1822 fci = print_char_table;
1823 break;
1824 case scanf_format_type:
1825 fci = scan_char_table;
1826 break;
1827 case strftime_format_type:
1828 fci = time_char_table;
1829 break;
1830 default:
1831 abort ();
1833 while (fci->format_chars != 0
1834 && index (fci->format_chars, format_char) == 0)
1835 ++fci;
1836 if (fci->format_chars == 0)
1838 if (ISGRAPH(format_char))
1839 warning ("unknown conversion type character `%c' in format",
1840 format_char);
1841 else
1842 warning ("unknown conversion type character 0x%x in format",
1843 format_char);
1844 continue;
1846 if (pedantic)
1848 if (index (fci->flag_chars, 'G') != 0)
1849 warning ("ANSI C does not support `%%%c'", format_char);
1850 if (index (fci->flag_chars, 'o') != 0
1851 && index (flag_chars, 'O') != 0)
1852 warning ("ANSI C does not support `%%O%c'", format_char);
1854 if (wide && index (fci->flag_chars, 'w') == 0)
1855 warning ("width used with `%c' format", format_char);
1856 if (index (fci->flag_chars, '2') != 0)
1857 warning ("`%%%c' yields only last 2 digits of year", format_char);
1858 else if (index (fci->flag_chars, '3') != 0)
1859 warning ("`%%%c' yields only last 2 digits of year in some locales",
1860 format_char);
1861 if (precise && index (fci->flag_chars, 'p') == 0)
1862 warning ("precision used with `%c' format", format_char);
1863 if (aflag && index (fci->flag_chars, 'a') == 0)
1865 warning ("`a' flag used with `%c' format", format_char);
1866 /* To simplify the following code. */
1867 aflag = 0;
1869 /* The a flag is a GNU extension. */
1870 else if (pedantic && aflag)
1871 warning ("ANSI C does not support the `a' flag");
1872 if (info->format_type == scanf_format_type && format_char == '[')
1874 /* Skip over scan set, in case it happens to have '%' in it. */
1875 if (*format_chars == '^')
1876 ++format_chars;
1877 /* Find closing bracket; if one is hit immediately, then
1878 it's part of the scan set rather than a terminator. */
1879 if (*format_chars == ']')
1880 ++format_chars;
1881 while (*format_chars && *format_chars != ']')
1882 ++format_chars;
1883 if (*format_chars != ']')
1884 /* The end of the format string was reached. */
1885 warning ("no closing `]' for `%%[' format");
1887 if (suppressed)
1889 if (index (fci->flag_chars, '*') == 0)
1890 warning ("suppression of `%c' conversion in format", format_char);
1891 continue;
1893 for (i = 0; flag_chars[i] != 0; ++i)
1895 if (index (fci->flag_chars, flag_chars[i]) == 0)
1896 warning ("flag `%c' used with type `%c'",
1897 flag_chars[i], format_char);
1899 if (info->format_type == strftime_format_type)
1900 continue;
1901 if (precise && index (flag_chars, '0') != 0
1902 && (format_char == 'd' || format_char == 'i'
1903 || format_char == 'o' || format_char == 'u'
1904 || format_char == 'x' || format_char == 'X'))
1905 warning ("`0' flag ignored with precision specifier and `%c' format",
1906 format_char);
1907 switch (length_char)
1909 default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
1910 case 'H': wanted_type = fci->hhlen ? *(fci->hhlen) : 0; break;
1911 case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
1912 case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
1913 case 'q': wanted_type = fci->qlen ? *(fci->qlen) : 0; break;
1914 case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
1915 case 'Z': wanted_type = fci->zlen ? *fci->zlen : 0; break;
1917 if (wanted_type == 0)
1918 warning ("use of `%c' length character with `%c' type character",
1919 length_char, format_char);
1921 /* Finally. . .check type of argument against desired type! */
1922 if (info->first_arg_num == 0)
1923 continue;
1924 if (fci->pointer_count == 0 && wanted_type == void_type_node)
1925 /* This specifier takes no argument. */
1926 continue;
1927 if (params == 0)
1929 tfaff ();
1930 return;
1932 cur_param = TREE_VALUE (params);
1933 params = TREE_CHAIN (params);
1934 ++arg_num;
1935 cur_type = TREE_TYPE (cur_param);
1937 STRIP_NOPS (cur_param);
1939 /* Check the types of any additional pointer arguments
1940 that precede the "real" argument. */
1941 for (i = 0; i < fci->pointer_count + aflag; ++i)
1943 if (TREE_CODE (cur_type) == POINTER_TYPE)
1945 cur_type = TREE_TYPE (cur_type);
1947 if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
1948 cur_param = TREE_OPERAND (cur_param, 0);
1949 else
1950 cur_param = 0;
1952 continue;
1954 if (TREE_CODE (cur_type) != ERROR_MARK)
1956 if (fci->pointer_count + aflag == 1)
1957 warning ("format argument is not a pointer (arg %d)", arg_num);
1958 else
1959 warning ("format argument is not a pointer to a pointer (arg %d)", arg_num);
1961 break;
1964 /* See if this is an attempt to write into a const type with
1965 scanf or with printf "%n". */
1966 if ((info->format_type == scanf_format_type
1967 || (info->format_type == printf_format_type
1968 && format_char == 'n'))
1969 && i == fci->pointer_count + aflag
1970 && wanted_type != 0
1971 && TREE_CODE (cur_type) != ERROR_MARK
1972 && (TYPE_READONLY (cur_type)
1973 || (cur_param != 0
1974 && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
1975 || (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'd'
1976 && TREE_READONLY (cur_param))))))
1977 warning ("writing into constant object (arg %d)", arg_num);
1979 /* Check the type of the "real" argument, if there's a type we want. */
1980 if (i == fci->pointer_count + aflag && wanted_type != 0
1981 && TREE_CODE (cur_type) != ERROR_MARK
1982 && wanted_type != TYPE_MAIN_VARIANT (cur_type)
1983 /* If we want `void *', allow any pointer type.
1984 (Anything else would already have got a warning.) */
1985 && ! (wanted_type == void_type_node
1986 && fci->pointer_count > 0)
1987 /* Don't warn about differences merely in signedness. */
1988 && !(TREE_CODE (wanted_type) == INTEGER_TYPE
1989 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type)) == INTEGER_TYPE
1990 && (TREE_UNSIGNED (wanted_type)
1991 ? wanted_type == (cur_type = unsigned_type (cur_type))
1992 : wanted_type == (cur_type = signed_type (cur_type))))
1993 /* Likewise, "signed char", "unsigned char" and "char" are
1994 equivalent but the above test won't consider them equivalent. */
1995 && ! (wanted_type == char_type_node
1996 && (TYPE_MAIN_VARIANT (cur_type) == signed_char_type_node
1997 || TYPE_MAIN_VARIANT (cur_type) == unsigned_char_type_node)))
1999 register const char *this;
2000 register const char *that;
2002 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
2003 that = 0;
2004 if (TREE_CODE (cur_type) != ERROR_MARK
2005 && TYPE_NAME (cur_type) != 0
2006 && TREE_CODE (cur_type) != INTEGER_TYPE
2007 && !(TREE_CODE (cur_type) == POINTER_TYPE
2008 && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE))
2010 if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL
2011 && DECL_NAME (TYPE_NAME (cur_type)) != 0)
2012 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
2013 else
2014 that = IDENTIFIER_POINTER (TYPE_NAME (cur_type));
2017 /* A nameless type can't possibly match what the format wants.
2018 So there will be a warning for it.
2019 Make up a string to describe vaguely what it is. */
2020 if (that == 0)
2022 if (TREE_CODE (cur_type) == POINTER_TYPE)
2023 that = "pointer";
2024 else
2025 that = "different type";
2028 /* Make the warning better in case of mismatch of int vs long. */
2029 if (TREE_CODE (cur_type) == INTEGER_TYPE
2030 && TREE_CODE (wanted_type) == INTEGER_TYPE
2031 && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type)
2032 && TYPE_NAME (cur_type) != 0
2033 && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL)
2034 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
2036 if (strcmp (this, that) != 0)
2037 warning ("%s format, %s arg (arg %d)", this, that, arg_num);
2042 /* Print a warning if a constant expression had overflow in folding.
2043 Invoke this function on every expression that the language
2044 requires to be a constant expression.
2045 Note the ANSI C standard says it is erroneous for a
2046 constant expression to overflow. */
2048 void
2049 constant_expression_warning (value)
2050 tree value;
2052 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
2053 || TREE_CODE (value) == COMPLEX_CST)
2054 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
2055 pedwarn ("overflow in constant expression");
2058 /* Print a warning if an expression had overflow in folding.
2059 Invoke this function on every expression that
2060 (1) appears in the source code, and
2061 (2) might be a constant expression that overflowed, and
2062 (3) is not already checked by convert_and_check;
2063 however, do not invoke this function on operands of explicit casts. */
2065 void
2066 overflow_warning (value)
2067 tree value;
2069 if ((TREE_CODE (value) == INTEGER_CST
2070 || (TREE_CODE (value) == COMPLEX_CST
2071 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
2072 && TREE_OVERFLOW (value))
2074 TREE_OVERFLOW (value) = 0;
2075 if (skip_evaluation == 0)
2076 warning ("integer overflow in expression");
2078 else if ((TREE_CODE (value) == REAL_CST
2079 || (TREE_CODE (value) == COMPLEX_CST
2080 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
2081 && TREE_OVERFLOW (value))
2083 TREE_OVERFLOW (value) = 0;
2084 if (skip_evaluation == 0)
2085 warning ("floating point overflow in expression");
2089 /* Print a warning if a large constant is truncated to unsigned,
2090 or if -Wconversion is used and a constant < 0 is converted to unsigned.
2091 Invoke this function on every expression that might be implicitly
2092 converted to an unsigned type. */
2094 void
2095 unsigned_conversion_warning (result, operand)
2096 tree result, operand;
2098 if (TREE_CODE (operand) == INTEGER_CST
2099 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
2100 && TREE_UNSIGNED (TREE_TYPE (result))
2101 && skip_evaluation == 0
2102 && !int_fits_type_p (operand, TREE_TYPE (result)))
2104 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
2105 /* This detects cases like converting -129 or 256 to unsigned char. */
2106 warning ("large integer implicitly truncated to unsigned type");
2107 else if (warn_conversion)
2108 warning ("negative integer implicitly converted to unsigned type");
2112 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2113 Invoke this function on every expression that is converted implicitly,
2114 i.e. because of language rules and not because of an explicit cast. */
2116 tree
2117 convert_and_check (type, expr)
2118 tree type, expr;
2120 tree t = convert (type, expr);
2121 if (TREE_CODE (t) == INTEGER_CST)
2123 if (TREE_OVERFLOW (t))
2125 TREE_OVERFLOW (t) = 0;
2127 /* Do not diagnose overflow in a constant expression merely
2128 because a conversion overflowed. */
2129 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
2131 /* No warning for converting 0x80000000 to int. */
2132 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
2133 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
2134 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
2135 /* If EXPR fits in the unsigned version of TYPE,
2136 don't warn unless pedantic. */
2137 if ((pedantic
2138 || TREE_UNSIGNED (type)
2139 || ! int_fits_type_p (expr, unsigned_type (type)))
2140 && skip_evaluation == 0)
2141 warning ("overflow in implicit constant conversion");
2143 else
2144 unsigned_conversion_warning (t, expr);
2146 return t;
2149 void
2150 c_expand_expr_stmt (expr)
2151 tree expr;
2153 /* Do default conversion if safe and possibly important,
2154 in case within ({...}). */
2155 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
2156 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
2157 expr = default_conversion (expr);
2159 if (TREE_TYPE (expr) != error_mark_node
2160 && TYPE_SIZE (TREE_TYPE (expr)) == 0
2161 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
2162 error ("expression statement has incomplete type");
2164 expand_expr_stmt (expr);
2167 /* Validate the expression after `case' and apply default promotions. */
2169 tree
2170 check_case_value (value)
2171 tree value;
2173 if (value == NULL_TREE)
2174 return value;
2176 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2177 STRIP_TYPE_NOPS (value);
2179 if (TREE_CODE (value) != INTEGER_CST
2180 && value != error_mark_node)
2182 error ("case label does not reduce to an integer constant");
2183 value = error_mark_node;
2185 else
2186 /* Promote char or short to int. */
2187 value = default_conversion (value);
2189 constant_expression_warning (value);
2191 return value;
2194 /* Return an integer type with BITS bits of precision,
2195 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2197 tree
2198 type_for_size (bits, unsignedp)
2199 unsigned bits;
2200 int unsignedp;
2202 if (bits == TYPE_PRECISION (integer_type_node))
2203 return unsignedp ? unsigned_type_node : integer_type_node;
2205 if (bits == TYPE_PRECISION (signed_char_type_node))
2206 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2208 if (bits == TYPE_PRECISION (short_integer_type_node))
2209 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2211 if (bits == TYPE_PRECISION (long_integer_type_node))
2212 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2214 if (bits == TYPE_PRECISION (long_long_integer_type_node))
2215 return (unsignedp ? long_long_unsigned_type_node
2216 : long_long_integer_type_node);
2218 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
2219 return (unsignedp ? widest_unsigned_literal_type_node
2220 : widest_integer_literal_type_node);
2222 if (bits <= TYPE_PRECISION (intQI_type_node))
2223 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2225 if (bits <= TYPE_PRECISION (intHI_type_node))
2226 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2228 if (bits <= TYPE_PRECISION (intSI_type_node))
2229 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2231 if (bits <= TYPE_PRECISION (intDI_type_node))
2232 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2234 return 0;
2237 /* Return a data type that has machine mode MODE.
2238 If the mode is an integer,
2239 then UNSIGNEDP selects between signed and unsigned types. */
2241 tree
2242 type_for_mode (mode, unsignedp)
2243 enum machine_mode mode;
2244 int unsignedp;
2246 if (mode == TYPE_MODE (integer_type_node))
2247 return unsignedp ? unsigned_type_node : integer_type_node;
2249 if (mode == TYPE_MODE (signed_char_type_node))
2250 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2252 if (mode == TYPE_MODE (short_integer_type_node))
2253 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2255 if (mode == TYPE_MODE (long_integer_type_node))
2256 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2258 if (mode == TYPE_MODE (long_long_integer_type_node))
2259 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2261 if (mode == TYPE_MODE (widest_integer_literal_type_node))
2262 return unsignedp ? widest_unsigned_literal_type_node
2263 : widest_integer_literal_type_node;
2265 if (mode == TYPE_MODE (intQI_type_node))
2266 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2268 if (mode == TYPE_MODE (intHI_type_node))
2269 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2271 if (mode == TYPE_MODE (intSI_type_node))
2272 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2274 if (mode == TYPE_MODE (intDI_type_node))
2275 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2277 #if HOST_BITS_PER_WIDE_INT >= 64
2278 if (mode == TYPE_MODE (intTI_type_node))
2279 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2280 #endif
2282 if (mode == TYPE_MODE (float_type_node))
2283 return float_type_node;
2285 if (mode == TYPE_MODE (double_type_node))
2286 return double_type_node;
2288 if (mode == TYPE_MODE (long_double_type_node))
2289 return long_double_type_node;
2291 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
2292 return build_pointer_type (char_type_node);
2294 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2295 return build_pointer_type (integer_type_node);
2297 return 0;
2300 /* Return an unsigned type the same as TYPE in other respects. */
2301 tree
2302 unsigned_type (type)
2303 tree type;
2305 tree type1 = TYPE_MAIN_VARIANT (type);
2306 if (type1 == signed_char_type_node || type1 == char_type_node)
2307 return unsigned_char_type_node;
2308 if (type1 == integer_type_node)
2309 return unsigned_type_node;
2310 if (type1 == short_integer_type_node)
2311 return short_unsigned_type_node;
2312 if (type1 == long_integer_type_node)
2313 return long_unsigned_type_node;
2314 if (type1 == long_long_integer_type_node)
2315 return long_long_unsigned_type_node;
2316 if (type1 == widest_integer_literal_type_node)
2317 return widest_unsigned_literal_type_node;
2318 #if HOST_BITS_PER_WIDE_INT >= 64
2319 if (type1 == intTI_type_node)
2320 return unsigned_intTI_type_node;
2321 #endif
2322 if (type1 == intDI_type_node)
2323 return unsigned_intDI_type_node;
2324 if (type1 == intSI_type_node)
2325 return unsigned_intSI_type_node;
2326 if (type1 == intHI_type_node)
2327 return unsigned_intHI_type_node;
2328 if (type1 == intQI_type_node)
2329 return unsigned_intQI_type_node;
2331 return signed_or_unsigned_type (1, type);
2334 /* Return a signed type the same as TYPE in other respects. */
2336 tree
2337 signed_type (type)
2338 tree type;
2340 tree type1 = TYPE_MAIN_VARIANT (type);
2341 if (type1 == unsigned_char_type_node || type1 == char_type_node)
2342 return signed_char_type_node;
2343 if (type1 == unsigned_type_node)
2344 return integer_type_node;
2345 if (type1 == short_unsigned_type_node)
2346 return short_integer_type_node;
2347 if (type1 == long_unsigned_type_node)
2348 return long_integer_type_node;
2349 if (type1 == long_long_unsigned_type_node)
2350 return long_long_integer_type_node;
2351 if (type1 == widest_unsigned_literal_type_node)
2352 return widest_integer_literal_type_node;
2353 #if HOST_BITS_PER_WIDE_INT >= 64
2354 if (type1 == unsigned_intTI_type_node)
2355 return intTI_type_node;
2356 #endif
2357 if (type1 == unsigned_intDI_type_node)
2358 return intDI_type_node;
2359 if (type1 == unsigned_intSI_type_node)
2360 return intSI_type_node;
2361 if (type1 == unsigned_intHI_type_node)
2362 return intHI_type_node;
2363 if (type1 == unsigned_intQI_type_node)
2364 return intQI_type_node;
2366 return signed_or_unsigned_type (0, type);
2369 /* Return a type the same as TYPE except unsigned or
2370 signed according to UNSIGNEDP. */
2372 tree
2373 signed_or_unsigned_type (unsignedp, type)
2374 int unsignedp;
2375 tree type;
2377 if (! INTEGRAL_TYPE_P (type)
2378 || TREE_UNSIGNED (type) == unsignedp)
2379 return type;
2381 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
2382 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2383 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2384 return unsignedp ? unsigned_type_node : integer_type_node;
2385 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
2386 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2387 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
2388 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2389 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
2390 return (unsignedp ? long_long_unsigned_type_node
2391 : long_long_integer_type_node);
2392 if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
2393 return (unsignedp ? widest_unsigned_literal_type_node
2394 : widest_integer_literal_type_node);
2395 return type;
2398 /* Return the minimum number of bits needed to represent VALUE in a
2399 signed or unsigned type, UNSIGNEDP says which. */
2402 min_precision (value, unsignedp)
2403 tree value;
2404 int unsignedp;
2406 int log;
2408 /* If the value is negative, compute its negative minus 1. The latter
2409 adjustment is because the absolute value of the largest negative value
2410 is one larger than the largest positive value. This is equivalent to
2411 a bit-wise negation, so use that operation instead. */
2413 if (tree_int_cst_sgn (value) < 0)
2414 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
2416 /* Return the number of bits needed, taking into account the fact
2417 that we need one more bit for a signed than unsigned type. */
2419 if (integer_zerop (value))
2420 log = 0;
2421 else if (TREE_INT_CST_HIGH (value) != 0)
2422 log = HOST_BITS_PER_WIDE_INT + floor_log2 (TREE_INT_CST_HIGH (value));
2423 else
2424 log = floor_log2 (TREE_INT_CST_LOW (value));
2426 return log + 1 + ! unsignedp;
2429 /* Print an error message for invalid operands to arith operation CODE.
2430 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2432 void
2433 binary_op_error (code)
2434 enum tree_code code;
2436 register const char *opname;
2438 switch (code)
2440 case NOP_EXPR:
2441 error ("invalid truth-value expression");
2442 return;
2444 case PLUS_EXPR:
2445 opname = "+"; break;
2446 case MINUS_EXPR:
2447 opname = "-"; break;
2448 case MULT_EXPR:
2449 opname = "*"; break;
2450 case MAX_EXPR:
2451 opname = "max"; break;
2452 case MIN_EXPR:
2453 opname = "min"; break;
2454 case EQ_EXPR:
2455 opname = "=="; break;
2456 case NE_EXPR:
2457 opname = "!="; break;
2458 case LE_EXPR:
2459 opname = "<="; break;
2460 case GE_EXPR:
2461 opname = ">="; break;
2462 case LT_EXPR:
2463 opname = "<"; break;
2464 case GT_EXPR:
2465 opname = ">"; break;
2466 case LSHIFT_EXPR:
2467 opname = "<<"; break;
2468 case RSHIFT_EXPR:
2469 opname = ">>"; break;
2470 case TRUNC_MOD_EXPR:
2471 case FLOOR_MOD_EXPR:
2472 opname = "%"; break;
2473 case TRUNC_DIV_EXPR:
2474 case FLOOR_DIV_EXPR:
2475 opname = "/"; break;
2476 case BIT_AND_EXPR:
2477 opname = "&"; break;
2478 case BIT_IOR_EXPR:
2479 opname = "|"; break;
2480 case TRUTH_ANDIF_EXPR:
2481 opname = "&&"; break;
2482 case TRUTH_ORIF_EXPR:
2483 opname = "||"; break;
2484 case BIT_XOR_EXPR:
2485 opname = "^"; break;
2486 case LROTATE_EXPR:
2487 case RROTATE_EXPR:
2488 opname = "rotate"; break;
2489 default:
2490 opname = "unknown"; break;
2492 error ("invalid operands to binary %s", opname);
2495 /* Subroutine of build_binary_op, used for comparison operations.
2496 See if the operands have both been converted from subword integer types
2497 and, if so, perhaps change them both back to their original type.
2498 This function is also responsible for converting the two operands
2499 to the proper common type for comparison.
2501 The arguments of this function are all pointers to local variables
2502 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2503 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2505 If this function returns nonzero, it means that the comparison has
2506 a constant value. What this function returns is an expression for
2507 that value. */
2509 tree
2510 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
2511 tree *op0_ptr, *op1_ptr;
2512 tree *restype_ptr;
2513 enum tree_code *rescode_ptr;
2515 register tree type;
2516 tree op0 = *op0_ptr;
2517 tree op1 = *op1_ptr;
2518 int unsignedp0, unsignedp1;
2519 int real1, real2;
2520 tree primop0, primop1;
2521 enum tree_code code = *rescode_ptr;
2523 /* Throw away any conversions to wider types
2524 already present in the operands. */
2526 primop0 = get_narrower (op0, &unsignedp0);
2527 primop1 = get_narrower (op1, &unsignedp1);
2529 /* Handle the case that OP0 does not *contain* a conversion
2530 but it *requires* conversion to FINAL_TYPE. */
2532 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
2533 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
2534 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
2535 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
2537 /* If one of the operands must be floated, we cannot optimize. */
2538 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
2539 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
2541 /* If first arg is constant, swap the args (changing operation
2542 so value is preserved), for canonicalization. Don't do this if
2543 the second arg is 0. */
2545 if (TREE_CONSTANT (primop0)
2546 && ! integer_zerop (primop1) && ! real_zerop (primop1))
2548 register tree tem = primop0;
2549 register int temi = unsignedp0;
2550 primop0 = primop1;
2551 primop1 = tem;
2552 tem = op0;
2553 op0 = op1;
2554 op1 = tem;
2555 *op0_ptr = op0;
2556 *op1_ptr = op1;
2557 unsignedp0 = unsignedp1;
2558 unsignedp1 = temi;
2559 temi = real1;
2560 real1 = real2;
2561 real2 = temi;
2563 switch (code)
2565 case LT_EXPR:
2566 code = GT_EXPR;
2567 break;
2568 case GT_EXPR:
2569 code = LT_EXPR;
2570 break;
2571 case LE_EXPR:
2572 code = GE_EXPR;
2573 break;
2574 case GE_EXPR:
2575 code = LE_EXPR;
2576 break;
2577 default:
2578 break;
2580 *rescode_ptr = code;
2583 /* If comparing an integer against a constant more bits wide,
2584 maybe we can deduce a value of 1 or 0 independent of the data.
2585 Or else truncate the constant now
2586 rather than extend the variable at run time.
2588 This is only interesting if the constant is the wider arg.
2589 Also, it is not safe if the constant is unsigned and the
2590 variable arg is signed, since in this case the variable
2591 would be sign-extended and then regarded as unsigned.
2592 Our technique fails in this case because the lowest/highest
2593 possible unsigned results don't follow naturally from the
2594 lowest/highest possible values of the variable operand.
2595 For just EQ_EXPR and NE_EXPR there is another technique that
2596 could be used: see if the constant can be faithfully represented
2597 in the other operand's type, by truncating it and reextending it
2598 and see if that preserves the constant's value. */
2600 if (!real1 && !real2
2601 && TREE_CODE (primop1) == INTEGER_CST
2602 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
2604 int min_gt, max_gt, min_lt, max_lt;
2605 tree maxval, minval;
2606 /* 1 if comparison is nominally unsigned. */
2607 int unsignedp = TREE_UNSIGNED (*restype_ptr);
2608 tree val;
2610 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
2612 /* If TYPE is an enumeration, then we need to get its min/max
2613 values from it's underlying integral type, not the enumerated
2614 type itself. */
2615 if (TREE_CODE (type) == ENUMERAL_TYPE)
2616 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
2618 maxval = TYPE_MAX_VALUE (type);
2619 minval = TYPE_MIN_VALUE (type);
2621 if (unsignedp && !unsignedp0)
2622 *restype_ptr = signed_type (*restype_ptr);
2624 if (TREE_TYPE (primop1) != *restype_ptr)
2625 primop1 = convert (*restype_ptr, primop1);
2626 if (type != *restype_ptr)
2628 minval = convert (*restype_ptr, minval);
2629 maxval = convert (*restype_ptr, maxval);
2632 if (unsignedp && unsignedp0)
2634 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
2635 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
2636 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
2637 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
2639 else
2641 min_gt = INT_CST_LT (primop1, minval);
2642 max_gt = INT_CST_LT (primop1, maxval);
2643 min_lt = INT_CST_LT (minval, primop1);
2644 max_lt = INT_CST_LT (maxval, primop1);
2647 val = 0;
2648 /* This used to be a switch, but Genix compiler can't handle that. */
2649 if (code == NE_EXPR)
2651 if (max_lt || min_gt)
2652 val = boolean_true_node;
2654 else if (code == EQ_EXPR)
2656 if (max_lt || min_gt)
2657 val = boolean_false_node;
2659 else if (code == LT_EXPR)
2661 if (max_lt)
2662 val = boolean_true_node;
2663 if (!min_lt)
2664 val = boolean_false_node;
2666 else if (code == GT_EXPR)
2668 if (min_gt)
2669 val = boolean_true_node;
2670 if (!max_gt)
2671 val = boolean_false_node;
2673 else if (code == LE_EXPR)
2675 if (!max_gt)
2676 val = boolean_true_node;
2677 if (min_gt)
2678 val = boolean_false_node;
2680 else if (code == GE_EXPR)
2682 if (!min_lt)
2683 val = boolean_true_node;
2684 if (max_lt)
2685 val = boolean_false_node;
2688 /* If primop0 was sign-extended and unsigned comparison specd,
2689 we did a signed comparison above using the signed type bounds.
2690 But the comparison we output must be unsigned.
2692 Also, for inequalities, VAL is no good; but if the signed
2693 comparison had *any* fixed result, it follows that the
2694 unsigned comparison just tests the sign in reverse
2695 (positive values are LE, negative ones GE).
2696 So we can generate an unsigned comparison
2697 against an extreme value of the signed type. */
2699 if (unsignedp && !unsignedp0)
2701 if (val != 0)
2702 switch (code)
2704 case LT_EXPR:
2705 case GE_EXPR:
2706 primop1 = TYPE_MIN_VALUE (type);
2707 val = 0;
2708 break;
2710 case LE_EXPR:
2711 case GT_EXPR:
2712 primop1 = TYPE_MAX_VALUE (type);
2713 val = 0;
2714 break;
2716 default:
2717 break;
2719 type = unsigned_type (type);
2722 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2724 /* This is the case of (char)x >?< 0x80, which people used to use
2725 expecting old C compilers to change the 0x80 into -0x80. */
2726 if (val == boolean_false_node)
2727 warning ("comparison is always false due to limited range of data type");
2728 if (val == boolean_true_node)
2729 warning ("comparison is always true due to limited range of data type");
2732 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2734 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2735 if (val == boolean_false_node)
2736 warning ("comparison is always false due to limited range of data type");
2737 if (val == boolean_true_node)
2738 warning ("comparison is always true due to limited range of data type");
2741 if (val != 0)
2743 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2744 if (TREE_SIDE_EFFECTS (primop0))
2745 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
2746 return val;
2749 /* Value is not predetermined, but do the comparison
2750 in the type of the operand that is not constant.
2751 TYPE is already properly set. */
2753 else if (real1 && real2
2754 && (TYPE_PRECISION (TREE_TYPE (primop0))
2755 == TYPE_PRECISION (TREE_TYPE (primop1))))
2756 type = TREE_TYPE (primop0);
2758 /* If args' natural types are both narrower than nominal type
2759 and both extend in the same manner, compare them
2760 in the type of the wider arg.
2761 Otherwise must actually extend both to the nominal
2762 common type lest different ways of extending
2763 alter the result.
2764 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2766 else if (unsignedp0 == unsignedp1 && real1 == real2
2767 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
2768 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
2770 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
2771 type = signed_or_unsigned_type (unsignedp0
2772 || TREE_UNSIGNED (*restype_ptr),
2773 type);
2774 /* Make sure shorter operand is extended the right way
2775 to match the longer operand. */
2776 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
2777 primop0);
2778 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
2779 primop1);
2781 else
2783 /* Here we must do the comparison on the nominal type
2784 using the args exactly as we received them. */
2785 type = *restype_ptr;
2786 primop0 = op0;
2787 primop1 = op1;
2789 if (!real1 && !real2 && integer_zerop (primop1)
2790 && TREE_UNSIGNED (*restype_ptr))
2792 tree value = 0;
2793 switch (code)
2795 case GE_EXPR:
2796 /* All unsigned values are >= 0, so we warn if extra warnings
2797 are requested. However, if OP0 is a constant that is
2798 >= 0, the signedness of the comparison isn't an issue,
2799 so suppress the warning. */
2800 if (extra_warnings
2801 && ! (TREE_CODE (primop0) == INTEGER_CST
2802 && ! TREE_OVERFLOW (convert (signed_type (type),
2803 primop0))))
2804 warning ("comparison of unsigned expression >= 0 is always true");
2805 value = boolean_true_node;
2806 break;
2808 case LT_EXPR:
2809 if (extra_warnings
2810 && ! (TREE_CODE (primop0) == INTEGER_CST
2811 && ! TREE_OVERFLOW (convert (signed_type (type),
2812 primop0))))
2813 warning ("comparison of unsigned expression < 0 is always false");
2814 value = boolean_false_node;
2815 break;
2817 default:
2818 break;
2821 if (value != 0)
2823 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2824 if (TREE_SIDE_EFFECTS (primop0))
2825 return build (COMPOUND_EXPR, TREE_TYPE (value),
2826 primop0, value);
2827 return value;
2832 *op0_ptr = convert (type, primop0);
2833 *op1_ptr = convert (type, primop1);
2835 *restype_ptr = boolean_type_node;
2837 return 0;
2840 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2841 or validate its data type for an `if' or `while' statement or ?..: exp.
2843 This preparation consists of taking the ordinary
2844 representation of an expression expr and producing a valid tree
2845 boolean expression describing whether expr is nonzero. We could
2846 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2847 but we optimize comparisons, &&, ||, and !.
2849 The resulting type should always be `boolean_type_node'. */
2851 tree
2852 truthvalue_conversion (expr)
2853 tree expr;
2855 if (TREE_CODE (expr) == ERROR_MARK)
2856 return expr;
2858 #if 0 /* This appears to be wrong for C++. */
2859 /* These really should return error_mark_node after 2.4 is stable.
2860 But not all callers handle ERROR_MARK properly. */
2861 switch (TREE_CODE (TREE_TYPE (expr)))
2863 case RECORD_TYPE:
2864 error ("struct type value used where scalar is required");
2865 return boolean_false_node;
2867 case UNION_TYPE:
2868 error ("union type value used where scalar is required");
2869 return boolean_false_node;
2871 case ARRAY_TYPE:
2872 error ("array type value used where scalar is required");
2873 return boolean_false_node;
2875 default:
2876 break;
2878 #endif /* 0 */
2880 switch (TREE_CODE (expr))
2882 /* It is simpler and generates better code to have only TRUTH_*_EXPR
2883 or comparison expressions as truth values at this level. */
2884 #if 0
2885 case COMPONENT_REF:
2886 /* A one-bit unsigned bit-field is already acceptable. */
2887 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
2888 && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
2889 return expr;
2890 break;
2891 #endif
2893 case EQ_EXPR:
2894 /* It is simpler and generates better code to have only TRUTH_*_EXPR
2895 or comparison expressions as truth values at this level. */
2896 #if 0
2897 if (integer_zerop (TREE_OPERAND (expr, 1)))
2898 return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0);
2899 #endif
2900 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
2901 case TRUTH_ANDIF_EXPR:
2902 case TRUTH_ORIF_EXPR:
2903 case TRUTH_AND_EXPR:
2904 case TRUTH_OR_EXPR:
2905 case TRUTH_XOR_EXPR:
2906 case TRUTH_NOT_EXPR:
2907 TREE_TYPE (expr) = boolean_type_node;
2908 return expr;
2910 case ERROR_MARK:
2911 return expr;
2913 case INTEGER_CST:
2914 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
2916 case REAL_CST:
2917 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
2919 case ADDR_EXPR:
2920 /* If we are taking the address of a external decl, it might be zero
2921 if it is weak, so we cannot optimize. */
2922 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (expr, 0))) == 'd'
2923 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
2924 break;
2926 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
2927 return build (COMPOUND_EXPR, boolean_type_node,
2928 TREE_OPERAND (expr, 0), boolean_true_node);
2929 else
2930 return boolean_true_node;
2932 case COMPLEX_EXPR:
2933 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2934 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2935 truthvalue_conversion (TREE_OPERAND (expr, 0)),
2936 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2939 case NEGATE_EXPR:
2940 case ABS_EXPR:
2941 case FLOAT_EXPR:
2942 case FFS_EXPR:
2943 /* These don't change whether an object is non-zero or zero. */
2944 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2946 case LROTATE_EXPR:
2947 case RROTATE_EXPR:
2948 /* These don't change whether an object is zero or non-zero, but
2949 we can't ignore them if their second arg has side-effects. */
2950 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2951 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2952 truthvalue_conversion (TREE_OPERAND (expr, 0)));
2953 else
2954 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2956 case COND_EXPR:
2957 /* Distribute the conversion into the arms of a COND_EXPR. */
2958 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2959 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2960 truthvalue_conversion (TREE_OPERAND (expr, 2))));
2962 case CONVERT_EXPR:
2963 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2964 since that affects how `default_conversion' will behave. */
2965 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2966 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2967 break;
2968 /* fall through... */
2969 case NOP_EXPR:
2970 /* If this is widening the argument, we can ignore it. */
2971 if (TYPE_PRECISION (TREE_TYPE (expr))
2972 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2973 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2974 break;
2976 case MINUS_EXPR:
2977 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2978 this case. */
2979 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2980 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2981 break;
2982 /* fall through... */
2983 case BIT_XOR_EXPR:
2984 /* This and MINUS_EXPR can be changed into a comparison of the
2985 two objects. */
2986 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2987 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2988 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2989 TREE_OPERAND (expr, 1), 1);
2990 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2991 fold (build1 (NOP_EXPR,
2992 TREE_TYPE (TREE_OPERAND (expr, 0)),
2993 TREE_OPERAND (expr, 1))), 1);
2995 case BIT_AND_EXPR:
2996 if (integer_onep (TREE_OPERAND (expr, 1))
2997 && TREE_TYPE (expr) != boolean_type_node)
2998 /* Using convert here would cause infinite recursion. */
2999 return build1 (NOP_EXPR, boolean_type_node, expr);
3000 break;
3002 case MODIFY_EXPR:
3003 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
3004 warning ("suggest parentheses around assignment used as truth value");
3005 break;
3007 default:
3008 break;
3011 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
3013 tree tem = save_expr (expr);
3014 return (build_binary_op
3015 ((TREE_SIDE_EFFECTS (expr)
3016 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
3017 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
3018 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
3019 0));
3022 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
3025 #if USE_CPPLIB
3026 /* Read the rest of a #-directive from input stream FINPUT.
3027 In normal use, the directive name and the white space after it
3028 have already been read, so they won't be included in the result.
3029 We allow for the fact that the directive line may contain
3030 a newline embedded within a character or string literal which forms
3031 a part of the directive.
3033 The value is a string in a reusable buffer. It remains valid
3034 only until the next time this function is called. */
3035 unsigned char *yy_cur, *yy_lim;
3037 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
3038 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
3041 yy_get_token ()
3043 for (;;)
3045 parse_in.limit = parse_in.token_buffer;
3046 cpp_token = cpp_get_token (&parse_in);
3047 if (cpp_token == CPP_EOF)
3048 return -1;
3049 yy_lim = CPP_PWRITTEN (&parse_in);
3050 yy_cur = parse_in.token_buffer;
3051 if (yy_cur < yy_lim)
3052 return *yy_cur++;
3056 char *
3057 get_directive_line ()
3059 static char *directive_buffer = NULL;
3060 static unsigned buffer_length = 0;
3061 register char *p;
3062 register char *buffer_limit;
3063 register int looking_for = 0;
3064 register int char_escaped = 0;
3066 if (buffer_length == 0)
3068 directive_buffer = (char *)xmalloc (128);
3069 buffer_length = 128;
3072 buffer_limit = &directive_buffer[buffer_length];
3074 for (p = directive_buffer; ; )
3076 int c;
3078 /* Make buffer bigger if it is full. */
3079 if (p >= buffer_limit)
3081 register unsigned bytes_used = (p - directive_buffer);
3083 buffer_length *= 2;
3084 directive_buffer
3085 = (char *)xrealloc (directive_buffer, buffer_length);
3086 p = &directive_buffer[bytes_used];
3087 buffer_limit = &directive_buffer[buffer_length];
3090 c = GETC ();
3092 /* Discard initial whitespace. */
3093 if ((c == ' ' || c == '\t') && p == directive_buffer)
3094 continue;
3096 /* Detect the end of the directive. */
3097 if (c == '\n' && looking_for == 0)
3099 UNGETC (c);
3100 c = '\0';
3103 *p++ = c;
3105 if (c == 0)
3106 return directive_buffer;
3108 /* Handle string and character constant syntax. */
3109 if (looking_for)
3111 if (looking_for == c && !char_escaped)
3112 looking_for = 0; /* Found terminator... stop looking. */
3114 else
3115 if (c == '\'' || c == '"')
3116 looking_for = c; /* Don't stop buffering until we see another
3117 another one of these (or an EOF). */
3119 /* Handle backslash. */
3120 char_escaped = (c == '\\' && ! char_escaped);
3123 #else
3124 /* Read the rest of a #-directive from input stream FINPUT.
3125 In normal use, the directive name and the white space after it
3126 have already been read, so they won't be included in the result.
3127 We allow for the fact that the directive line may contain
3128 a newline embedded within a character or string literal which forms
3129 a part of the directive.
3131 The value is a string in a reusable buffer. It remains valid
3132 only until the next time this function is called.
3134 The terminating character ('\n' or EOF) is left in FINPUT for the
3135 caller to re-read. */
3137 char *
3138 get_directive_line (finput)
3139 register FILE *finput;
3141 static char *directive_buffer = NULL;
3142 static unsigned buffer_length = 0;
3143 register char *p;
3144 register char *buffer_limit;
3145 register int looking_for = 0;
3146 register int char_escaped = 0;
3148 if (buffer_length == 0)
3150 directive_buffer = (char *)xmalloc (128);
3151 buffer_length = 128;
3154 buffer_limit = &directive_buffer[buffer_length];
3156 for (p = directive_buffer; ; )
3158 int c;
3160 /* Make buffer bigger if it is full. */
3161 if (p >= buffer_limit)
3163 register unsigned bytes_used = (p - directive_buffer);
3165 buffer_length *= 2;
3166 directive_buffer
3167 = (char *)xrealloc (directive_buffer, buffer_length);
3168 p = &directive_buffer[bytes_used];
3169 buffer_limit = &directive_buffer[buffer_length];
3172 c = getc (finput);
3174 /* Discard initial whitespace. */
3175 if ((c == ' ' || c == '\t') && p == directive_buffer)
3176 continue;
3178 /* Detect the end of the directive. */
3179 if (looking_for == 0
3180 && (c == '\n' || c == EOF))
3182 ungetc (c, finput);
3183 c = '\0';
3186 *p++ = c;
3188 if (c == 0)
3189 return directive_buffer;
3191 /* Handle string and character constant syntax. */
3192 if (looking_for)
3194 if (looking_for == c && !char_escaped)
3195 looking_for = 0; /* Found terminator... stop looking. */
3197 else
3198 if (c == '\'' || c == '"')
3199 looking_for = c; /* Don't stop buffering until we see another
3200 one of these (or an EOF). */
3202 /* Handle backslash. */
3203 char_escaped = (c == '\\' && ! char_escaped);
3206 #endif /* !USE_CPPLIB */
3208 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3209 down to the element type of an array. */
3211 tree
3212 c_build_qualified_type (type, type_quals)
3213 tree type;
3214 int type_quals;
3216 /* A restrict-qualified pointer type must be a pointer to object or
3217 incomplete type. Note that the use of POINTER_TYPE_P also allows
3218 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
3219 the C++ front-end also use POINTER_TYPE for pointer-to-member
3220 values, so even though it should be illegal to use `restrict'
3221 with such an entity we don't flag that here. Thus, special case
3222 code for that case is required in the C++ front-end. */
3223 if ((type_quals & TYPE_QUAL_RESTRICT)
3224 && (!POINTER_TYPE_P (type)
3225 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
3227 error ("invalid use of `restrict'");
3228 type_quals &= ~TYPE_QUAL_RESTRICT;
3231 if (TREE_CODE (type) == ARRAY_TYPE)
3232 return build_array_type (c_build_qualified_type (TREE_TYPE (type),
3233 type_quals),
3234 TYPE_DOMAIN (type));
3235 return build_qualified_type (type, type_quals);
3238 /* Apply the TYPE_QUALS to the new DECL. */
3240 void
3241 c_apply_type_quals_to_decl (type_quals, decl)
3242 int type_quals;
3243 tree decl;
3245 if (type_quals & TYPE_QUAL_CONST)
3246 TREE_READONLY (decl) = 1;
3247 if (type_quals & TYPE_QUAL_VOLATILE)
3249 TREE_SIDE_EFFECTS (decl) = 1;
3250 TREE_THIS_VOLATILE (decl) = 1;
3252 if (type_quals & TYPE_QUAL_RESTRICT)
3254 if (!TREE_TYPE (decl)
3255 || !POINTER_TYPE_P (TREE_TYPE (decl))
3256 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
3257 error ("invalid use of `restrict'");
3258 else if (flag_strict_aliasing)
3260 /* No two restricted pointers can point at the same thing.
3261 However, a restricted pointer can point at the same thing
3262 as an unrestricted pointer, if that unrestricted pointer
3263 is based on the restricted pointer. So, we make the
3264 alias set for the restricted pointer a subset of the
3265 alias set for the type pointed to by the type of the
3266 decl. */
3268 int pointed_to_alias_set
3269 = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
3271 if (!pointed_to_alias_set)
3272 /* It's not legal to make a subset of alias set zero. */
3274 else
3276 DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
3277 record_alias_subset (pointed_to_alias_set,
3278 DECL_POINTER_ALIAS_SET (decl));
3284 /* T is an expression with pointer type. Find the DECL on which this
3285 expression is based. (For example, in `a[i]' this would be `a'.)
3286 If there is no such DECL, or a unique decl cannot be determined,
3287 NULL_TREE is retured. */
3289 static tree
3290 c_find_base_decl (t)
3291 tree t;
3293 int i;
3294 tree decl;
3296 if (t == NULL_TREE || t == error_mark_node)
3297 return NULL_TREE;
3299 if (!POINTER_TYPE_P (TREE_TYPE (t)))
3300 return NULL_TREE;
3302 decl = NULL_TREE;
3304 if (TREE_CODE (t) == FIELD_DECL
3305 || TREE_CODE (t) == PARM_DECL
3306 || TREE_CODE (t) == VAR_DECL)
3307 /* Aha, we found a pointer-typed declaration. */
3308 return t;
3310 /* It would be nice to deal with COMPONENT_REFs here. If we could
3311 tell that `a' and `b' were the same, then `a->f' and `b->f' are
3312 also the same. */
3314 /* Handle general expressions. */
3315 switch (TREE_CODE_CLASS (TREE_CODE (t)))
3317 case '1':
3318 case '2':
3319 case '3':
3320 for (i = tree_code_length [(int) TREE_CODE (t)]; --i >= 0;)
3322 tree d = c_find_base_decl (TREE_OPERAND (t, i));
3323 if (d)
3325 if (!decl)
3326 decl = d;
3327 else if (d && d != decl)
3328 /* Two different declarations. That's confusing; let's
3329 just assume we don't know what's going on. */
3330 decl = NULL_TREE;
3333 break;
3335 default:
3336 break;
3339 return decl;
3342 /* Return the typed-based alias set for T, which may be an expression
3343 or a type. */
3346 c_get_alias_set (t)
3347 tree t;
3349 tree type;
3350 tree u;
3352 if (t == error_mark_node)
3353 return 0;
3355 type = (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
3356 ? t : TREE_TYPE (t);
3358 if (type == error_mark_node)
3359 return 0;
3361 /* Deal with special cases first; for certain kinds of references
3362 we're interested in more than just the type. */
3364 if (TREE_CODE (t) == BIT_FIELD_REF)
3365 /* Perhaps reads and writes to this piece of data alias fields
3366 neighboring the bitfield. Perhaps that's impossible. For now,
3367 let's just assume that bitfields can alias everything, which is
3368 the conservative assumption. */
3369 return 0;
3371 /* Permit type-punning when accessing a union, provided the access
3372 is directly through the union. For example, this code does not
3373 permit taking the address of a union member and then storing
3374 through it. Even the type-punning allowed here is a GCC
3375 extension, albeit a common and useful one; the C standard says
3376 that such accesses have implementation-defined behavior. */
3377 for (u = t;
3378 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
3379 u = TREE_OPERAND (u, 0))
3380 if (TREE_CODE (u) == COMPONENT_REF
3381 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
3382 return 0;
3384 if (TREE_CODE (t) == INDIRECT_REF)
3386 /* Check for accesses through restrict-qualified pointers. */
3387 tree decl = c_find_base_decl (TREE_OPERAND (t, 0));
3389 if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
3390 /* We use the alias set indicated in the declaration. */
3391 return DECL_POINTER_ALIAS_SET (decl);
3394 /* From here on, only the type matters. */
3396 if (TREE_CODE (t) == COMPONENT_REF
3397 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1)))
3398 /* Since build_modify_expr calls get_unwidened for stores to
3399 component references, the type of a bit field can be changed
3400 from (say) `unsigned int : 16' to `unsigned short' or from
3401 `enum E : 16' to `short'. We want the real type of the
3402 bit-field in this case, not some the integral equivalent. */
3403 type = DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1));
3405 if (TYPE_ALIAS_SET_KNOWN_P (type))
3406 /* If we've already calculated the value, just return it. */
3407 return TYPE_ALIAS_SET (type);
3408 else if (TYPE_MAIN_VARIANT (type) != type)
3409 /* The C standard specifically allows aliasing between
3410 cv-qualified variants of types. */
3411 TYPE_ALIAS_SET (type) = c_get_alias_set (TYPE_MAIN_VARIANT (type));
3412 else if (TREE_CODE (type) == INTEGER_TYPE)
3414 tree signed_variant;
3416 /* The C standard specifically allows aliasing between signed and
3417 unsigned variants of the same type. We treat the signed
3418 variant as canonical. */
3419 signed_variant = signed_type (type);
3421 if (signed_variant != type)
3422 TYPE_ALIAS_SET (type) = c_get_alias_set (signed_variant);
3423 else if (signed_variant == signed_char_type_node)
3424 /* The C standard guarantess that any object may be accessed
3425 via an lvalue that has character type. We don't have to
3426 check for unsigned_char_type_node or char_type_node because
3427 we are specifically looking at the signed variant. */
3428 TYPE_ALIAS_SET (type) = 0;
3430 else if (TREE_CODE (type) == ARRAY_TYPE)
3431 /* Anything that can alias one of the array elements can alias
3432 the entire array as well. */
3433 TYPE_ALIAS_SET (type) = c_get_alias_set (TREE_TYPE (type));
3434 else if (TREE_CODE (type) == FUNCTION_TYPE)
3435 /* There are no objects of FUNCTION_TYPE, so there's no point in
3436 using up an alias set for them. (There are, of course,
3437 pointers and references to functions, but that's
3438 different.) */
3439 TYPE_ALIAS_SET (type) = 0;
3440 else if (TREE_CODE (type) == RECORD_TYPE
3441 || TREE_CODE (type) == UNION_TYPE)
3442 /* If TYPE is a struct or union type then we're reading or
3443 writing an entire struct. Thus, we don't know anything about
3444 aliasing. (In theory, such an access can only alias objects
3445 whose type is the same as one of the fields, recursively, but
3446 we don't yet make any use of that information.) */
3447 TYPE_ALIAS_SET (type) = 0;
3448 else if (TREE_CODE (type) == POINTER_TYPE
3449 || TREE_CODE (type) == REFERENCE_TYPE)
3451 tree t;
3453 /* Unfortunately, there is no canonical form of a pointer type.
3454 In particular, if we have `typedef int I', then `int *', and
3455 `I *' are different types. So, we have to pick a canonical
3456 representative. We do this below.
3458 Technically, this approach is actually more conservative that
3459 it needs to be. In particular, `const int *' and `int *'
3460 chould be in different alias sets, according to the C and C++
3461 standard, since their types are not the same, and so,
3462 technically, an `int **' and `const int **' cannot point at
3463 the same thing.
3465 But, the standard is wrong. In particular, this code is
3466 legal C++:
3468 int *ip;
3469 int **ipp = &ip;
3470 const int* const* cipp = &ip;
3472 And, it doesn't make sense for that to be legal unless you
3473 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
3474 the pointed-to types. This issue has been reported to the
3475 C++ committee. */
3476 t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
3477 t = ((TREE_CODE (type) == POINTER_TYPE)
3478 ? build_pointer_type (t) : build_reference_type (t));
3479 if (t != type)
3480 TYPE_ALIAS_SET (type) = c_get_alias_set (t);
3483 if (!TYPE_ALIAS_SET_KNOWN_P (type))
3485 /* Types that are not allocated on the permanent obstack are not
3486 placed in the type hash table. Thus, there can be multiple
3487 copies of identical types in local scopes. In the long run,
3488 all types should be permanent. */
3489 if (! TREE_PERMANENT (type))
3490 TYPE_ALIAS_SET (type) = 0;
3491 else
3492 /* TYPE is something we haven't seen before. Put it in a new
3493 alias set. */
3494 TYPE_ALIAS_SET (type) = new_alias_set ();
3497 return TYPE_ALIAS_SET (type);
3500 /* Build tree nodes and builtin functions common to both C and C++ language
3501 frontends.
3502 CPLUS_MODE is nonzero if we are called from the C++ frontend, we generate
3503 some stricter prototypes in that case.
3504 NO_BUILTINS and NO_NONANSI_BUILTINS contain the respective values of
3505 the language frontend flags flag_no_builtin and
3506 flag_no_nonansi_builtin. */
3507 void
3508 c_common_nodes_and_builtins (cplus_mode, no_builtins, no_nonansi_builtins)
3509 int cplus_mode, no_builtins, no_nonansi_builtins;
3511 tree temp;
3512 tree memcpy_ftype, memset_ftype, strlen_ftype;
3513 tree endlink, int_endlink, double_endlink, unsigned_endlink;
3514 tree sizetype_endlink;
3515 tree ptr_ftype, ptr_ftype_unsigned;
3516 tree void_ftype_any, void_ftype_int;
3517 tree double_ftype_double, double_ftype_double_double;
3518 tree float_ftype_float, ldouble_ftype_ldouble;
3519 tree int_ftype_cptr_cptr_sizet;
3520 tree int_ftype_string_string, string_ftype_ptr_ptr;
3521 tree long_ftype_long;
3522 /* Either char* or void*. */
3523 tree traditional_ptr_type_node;
3524 tree va_list_ptr_type_node;
3525 tree va_list_arg_type_node;
3527 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
3528 va_list_type_node));
3530 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
3531 ptrdiff_type_node));
3533 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
3534 sizetype));
3536 va_list_ptr_type_node = build_pointer_type (va_list_type_node);
3538 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
3539 va_list_arg_type_node = build_pointer_type (TREE_TYPE (va_list_type_node));
3540 else
3541 va_list_arg_type_node = va_list_type_node;
3543 endlink = void_list_node;
3544 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
3545 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
3546 unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink);
3548 ptr_ftype = build_function_type (ptr_type_node, NULL_TREE);
3549 ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink);
3550 sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink);
3551 /* We realloc here because sizetype could be int or unsigned. S'ok. */
3552 ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink);
3554 void_ftype_any = build_function_type (void_type_node, NULL_TREE);
3555 void_ftype = build_function_type (void_type_node, endlink);
3556 void_ftype_int = build_function_type (void_type_node, int_endlink);
3557 void_ftype_ptr
3558 = build_function_type (void_type_node,
3559 tree_cons (NULL_TREE, ptr_type_node, endlink));
3561 float_ftype_float
3562 = build_function_type (float_type_node,
3563 tree_cons (NULL_TREE, float_type_node, endlink));
3565 double_ftype_double
3566 = build_function_type (double_type_node, double_endlink);
3568 ldouble_ftype_ldouble
3569 = build_function_type (long_double_type_node,
3570 tree_cons (NULL_TREE, long_double_type_node,
3571 endlink));
3573 double_ftype_double_double
3574 = build_function_type (double_type_node,
3575 tree_cons (NULL_TREE, double_type_node,
3576 double_endlink));
3578 int_ftype_int
3579 = build_function_type (integer_type_node, int_endlink);
3581 long_ftype_long
3582 = build_function_type (long_integer_type_node,
3583 tree_cons (NULL_TREE, long_integer_type_node,
3584 endlink));
3586 int_ftype_cptr_cptr_sizet
3587 = build_function_type (integer_type_node,
3588 tree_cons (NULL_TREE, const_ptr_type_node,
3589 tree_cons (NULL_TREE, const_ptr_type_node,
3590 tree_cons (NULL_TREE,
3591 sizetype,
3592 endlink))));
3594 /* Prototype for strcpy. */
3595 string_ftype_ptr_ptr
3596 = build_function_type (string_type_node,
3597 tree_cons (NULL_TREE, string_type_node,
3598 tree_cons (NULL_TREE,
3599 const_string_type_node,
3600 endlink)));
3602 /* Prototype for strcmp. */
3603 int_ftype_string_string
3604 = build_function_type (integer_type_node,
3605 tree_cons (NULL_TREE, const_string_type_node,
3606 tree_cons (NULL_TREE,
3607 const_string_type_node,
3608 endlink)));
3610 /* Prototype for strlen. */
3611 strlen_ftype
3612 = build_function_type ((flag_traditional && ! cplus_mode
3613 ? integer_type_node : sizetype),
3614 tree_cons (NULL_TREE, const_string_type_node,
3615 endlink));
3617 traditional_ptr_type_node = (flag_traditional && ! cplus_mode
3618 ? string_type_node : ptr_type_node);
3620 /* Prototype for memcpy. */
3621 memcpy_ftype
3622 = build_function_type (traditional_ptr_type_node,
3623 tree_cons (NULL_TREE, ptr_type_node,
3624 tree_cons (NULL_TREE, const_ptr_type_node,
3625 sizetype_endlink)));
3627 /* Prototype for memset. */
3628 memset_ftype
3629 = build_function_type (traditional_ptr_type_node,
3630 tree_cons (NULL_TREE, ptr_type_node,
3631 tree_cons (NULL_TREE, integer_type_node,
3632 tree_cons (NULL_TREE,
3633 sizetype,
3634 endlink))));
3636 builtin_function ("__builtin_constant_p", default_function_type,
3637 BUILT_IN_CONSTANT_P, BUILT_IN_NORMAL, NULL_PTR);
3639 builtin_function ("__builtin_return_address", ptr_ftype_unsigned,
3640 BUILT_IN_RETURN_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
3642 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned,
3643 BUILT_IN_FRAME_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
3645 builtin_function ("__builtin_alloca", ptr_ftype_sizetype,
3646 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, "alloca");
3647 builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS,
3648 BUILT_IN_NORMAL, NULL_PTR);
3649 /* Define alloca, ffs as builtins.
3650 Declare _exit just to mark it as volatile. */
3651 if (! no_builtins && ! no_nonansi_builtins)
3653 temp = builtin_function ("alloca", ptr_ftype_sizetype,
3654 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, NULL_PTR);
3655 /* Suppress error if redefined as a non-function. */
3656 DECL_BUILT_IN_NONANSI (temp) = 1;
3657 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS,
3658 BUILT_IN_NORMAL, NULL_PTR);
3659 /* Suppress error if redefined as a non-function. */
3660 DECL_BUILT_IN_NONANSI (temp) = 1;
3661 temp = builtin_function ("_exit", void_ftype_int,
3662 0, NOT_BUILT_IN, NULL_PTR);
3663 TREE_THIS_VOLATILE (temp) = 1;
3664 TREE_SIDE_EFFECTS (temp) = 1;
3665 /* Suppress error if redefined as a non-function. */
3666 DECL_BUILT_IN_NONANSI (temp) = 1;
3669 builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS,
3670 BUILT_IN_NORMAL, NULL_PTR);
3671 builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
3672 BUILT_IN_NORMAL, NULL_PTR);
3673 builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
3674 BUILT_IN_NORMAL, NULL_PTR);
3675 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3676 BUILT_IN_NORMAL, NULL_PTR);
3677 builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS,
3678 BUILT_IN_NORMAL, NULL_PTR);
3679 builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS,
3680 BUILT_IN_NORMAL, NULL_PTR);
3681 builtin_function ("__builtin_classify_type", default_function_type,
3682 BUILT_IN_CLASSIFY_TYPE, BUILT_IN_NORMAL, NULL_PTR);
3683 builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG,
3684 BUILT_IN_NORMAL, NULL_PTR);
3685 builtin_function ("__builtin_args_info", int_ftype_int, BUILT_IN_ARGS_INFO,
3686 BUILT_IN_NORMAL, NULL_PTR);
3687 builtin_function ("__builtin_setjmp",
3688 build_function_type (integer_type_node,
3689 tree_cons (NULL_TREE, ptr_type_node,
3690 endlink)),
3691 BUILT_IN_SETJMP, BUILT_IN_NORMAL, NULL_PTR);
3692 builtin_function ("__builtin_longjmp",
3693 build_function_type (void_type_node,
3694 tree_cons (NULL_TREE, ptr_type_node,
3695 tree_cons (NULL_TREE,
3696 integer_type_node,
3697 endlink))),
3698 BUILT_IN_LONGJMP, BUILT_IN_NORMAL, NULL_PTR);
3699 builtin_function ("__builtin_trap", void_ftype, BUILT_IN_TRAP,
3700 BUILT_IN_NORMAL, NULL_PTR);
3702 /* Untyped call and return. */
3703 builtin_function ("__builtin_apply_args", ptr_ftype,
3704 BUILT_IN_APPLY_ARGS, BUILT_IN_NORMAL, NULL_PTR);
3706 temp = tree_cons (NULL_TREE,
3707 build_pointer_type (build_function_type (void_type_node,
3708 NULL_TREE)),
3709 tree_cons (NULL_TREE,
3710 ptr_type_node,
3711 tree_cons (NULL_TREE,
3712 sizetype,
3713 endlink)));
3714 builtin_function ("__builtin_apply",
3715 build_function_type (ptr_type_node, temp),
3716 BUILT_IN_APPLY, BUILT_IN_NORMAL, NULL_PTR);
3717 builtin_function ("__builtin_return", void_ftype_ptr,
3718 BUILT_IN_RETURN, BUILT_IN_NORMAL, NULL_PTR);
3720 /* Support for varargs.h and stdarg.h. */
3721 builtin_function ("__builtin_varargs_start",
3722 build_function_type (void_type_node,
3723 tree_cons (NULL_TREE,
3724 va_list_ptr_type_node,
3725 endlink)),
3726 BUILT_IN_VARARGS_START, BUILT_IN_NORMAL, NULL_PTR);
3728 builtin_function ("__builtin_stdarg_start",
3729 build_function_type (void_type_node,
3730 tree_cons (NULL_TREE,
3731 va_list_ptr_type_node,
3732 NULL_TREE)),
3733 BUILT_IN_STDARG_START, BUILT_IN_NORMAL, NULL_PTR);
3735 builtin_function ("__builtin_va_end",
3736 build_function_type (void_type_node,
3737 tree_cons (NULL_TREE,
3738 va_list_arg_type_node,
3739 endlink)),
3740 BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL_PTR);
3742 builtin_function ("__builtin_va_copy",
3743 build_function_type (void_type_node,
3744 tree_cons (NULL_TREE,
3745 va_list_ptr_type_node,
3746 tree_cons (NULL_TREE,
3747 va_list_arg_type_node,
3748 endlink))),
3749 BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL_PTR);
3751 /* Currently under experimentation. */
3752 builtin_function ("__builtin_memcpy", memcpy_ftype, BUILT_IN_MEMCPY,
3753 BUILT_IN_NORMAL, "memcpy");
3754 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
3755 BUILT_IN_MEMCMP, BUILT_IN_NORMAL, "memcmp");
3756 builtin_function ("__builtin_memset", memset_ftype, BUILT_IN_MEMSET,
3757 BUILT_IN_NORMAL, "memset");
3758 builtin_function ("__builtin_strcmp", int_ftype_string_string,
3759 BUILT_IN_STRCMP, BUILT_IN_NORMAL, "strcmp");
3760 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
3761 BUILT_IN_STRCPY, BUILT_IN_NORMAL, "strcpy");
3762 builtin_function ("__builtin_strlen", strlen_ftype,
3763 BUILT_IN_STRLEN, BUILT_IN_NORMAL, "strlen");
3764 builtin_function ("__builtin_sqrtf", float_ftype_float,
3765 BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrtf");
3766 builtin_function ("__builtin_fsqrt", double_ftype_double,
3767 BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrt");
3768 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
3769 BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrtl");
3770 builtin_function ("__builtin_sinf", float_ftype_float,
3771 BUILT_IN_SIN, BUILT_IN_NORMAL, "sinf");
3772 builtin_function ("__builtin_sin", double_ftype_double,
3773 BUILT_IN_SIN, BUILT_IN_NORMAL, "sin");
3774 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
3775 BUILT_IN_SIN, BUILT_IN_NORMAL, "sinl");
3776 builtin_function ("__builtin_cosf", float_ftype_float,
3777 BUILT_IN_COS, BUILT_IN_NORMAL, "cosf");
3778 builtin_function ("__builtin_cos", double_ftype_double,
3779 BUILT_IN_COS, BUILT_IN_NORMAL, "cos");
3780 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
3781 BUILT_IN_COS, BUILT_IN_NORMAL, "cosl");
3783 if (! no_builtins)
3785 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS,
3786 BUILT_IN_NORMAL, NULL_PTR);
3787 builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS,
3788 BUILT_IN_NORMAL, NULL_PTR);
3789 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS,
3790 BUILT_IN_NORMAL, NULL_PTR);
3791 builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3792 BUILT_IN_NORMAL, NULL_PTR);
3793 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS,
3794 BUILT_IN_NORMAL, NULL_PTR);
3795 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY,
3796 BUILT_IN_NORMAL, NULL_PTR);
3797 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
3798 BUILT_IN_NORMAL, NULL_PTR);
3799 builtin_function ("memset", memset_ftype, BUILT_IN_MEMSET,
3800 BUILT_IN_NORMAL, NULL_PTR);
3801 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
3802 BUILT_IN_NORMAL, NULL_PTR);
3803 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
3804 BUILT_IN_NORMAL, NULL_PTR);
3805 builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN,
3806 BUILT_IN_NORMAL, NULL_PTR);
3807 builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT,
3808 BUILT_IN_NORMAL, NULL_PTR);
3809 builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT,
3810 BUILT_IN_NORMAL, NULL_PTR);
3811 builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
3812 BUILT_IN_NORMAL, NULL_PTR);
3813 builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN,
3814 BUILT_IN_NORMAL, NULL_PTR);
3815 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN,
3816 BUILT_IN_NORMAL, NULL_PTR);
3817 builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN,
3818 BUILT_IN_NORMAL, NULL_PTR);
3819 builtin_function ("cosf", float_ftype_float, BUILT_IN_COS,
3820 BUILT_IN_NORMAL, NULL_PTR);
3821 builtin_function ("cos", double_ftype_double, BUILT_IN_COS,
3822 BUILT_IN_NORMAL, NULL_PTR);
3823 builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS,
3824 BUILT_IN_NORMAL, NULL_PTR);
3826 /* Declare these functions volatile
3827 to avoid spurious "control drops through" warnings. */
3828 temp = builtin_function ("abort", cplus_mode ? void_ftype : void_ftype_any,
3829 0, NOT_BUILT_IN, NULL_PTR);
3830 TREE_THIS_VOLATILE (temp) = 1;
3831 TREE_SIDE_EFFECTS (temp) = 1;
3833 #if 0 /* ??? The C++ frontend used to do this. */
3834 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3835 them... */
3836 DECL_BUILT_IN_NONANSI (temp) = 1;
3837 #endif
3838 temp = builtin_function ("exit",
3839 cplus_mode ? void_ftype_int : void_ftype_any,
3840 0, NOT_BUILT_IN, NULL_PTR);
3841 TREE_THIS_VOLATILE (temp) = 1;
3842 TREE_SIDE_EFFECTS (temp) = 1;
3844 #if 0 /* ??? The C++ frontend used to do this. */
3845 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3846 them... */
3847 DECL_BUILT_IN_NONANSI (temp) = 1;
3848 #endif
3851 #if 0
3852 /* Support for these has not been written in either expand_builtin
3853 or build_function_call. */
3854 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV,
3855 BUILT_IN_NORMAL, NULL_PTR);
3856 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV,
3857 BUILT_IN_NORMAL, NULL_PTR);
3858 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
3859 BUILT_IN_NORMAL, NULL_PTR);
3860 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
3861 BUILT_IN_NORMAL, NULL_PTR);
3862 builtin_function ("__builtin_fmod", double_ftype_double_double,
3863 BUILT_IN_FMOD, BUILT_IN_NORMAL, NULL_PTR);
3864 builtin_function ("__builtin_frem", double_ftype_double_double,
3865 BUILT_IN_FREM, BUILT_IN_NORMAL, NULL_PTR);
3866 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
3867 BUILT_IN_NORMAL, NULL_PTR);
3868 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
3869 BUILT_IN_NORMAL, NULL_PTR);
3870 #endif
3872 /* ??? Perhaps there's a better place to do this. But it is related
3873 to __builtin_va_arg, so it isn't that off-the-wall. */
3874 lang_type_promotes_to = simple_type_promotes_to;
3877 tree
3878 build_va_arg (expr, type)
3879 tree expr, type;
3881 return build1 (VA_ARG_EXPR, type, expr);
3884 /* Given a type, apply default promotions wrt unnamed function arguments
3885 and return the new type. Return NULL_TREE if no change. */
3886 /* ??? There is a function of the same name in the C++ front end that
3887 does something similar, but is more thorough and does not return NULL
3888 if no change. We could perhaps share code, but it would make the
3889 self_promoting_type property harder to identify. */
3891 tree
3892 simple_type_promotes_to (type)
3893 tree type;
3895 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3896 return double_type_node;
3898 if (C_PROMOTING_INTEGER_TYPE_P (type))
3900 /* Traditionally, unsignedness is preserved in default promotions.
3901 Also preserve unsignedness if not really getting any wider. */
3902 if (TREE_UNSIGNED (type)
3903 && (flag_traditional
3904 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
3905 return unsigned_type_node;
3906 return integer_type_node;
3909 return NULL_TREE;
3912 /* Return 1 if PARMS specifies a fixed number of parameters
3913 and none of their types is affected by default promotions. */
3916 self_promoting_args_p (parms)
3917 tree parms;
3919 register tree t;
3920 for (t = parms; t; t = TREE_CHAIN (t))
3922 register tree type = TREE_VALUE (t);
3924 if (TREE_CHAIN (t) == 0 && type != void_type_node)
3925 return 0;
3927 if (type == 0)
3928 return 0;
3930 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3931 return 0;
3933 if (C_PROMOTING_INTEGER_TYPE_P (type))
3934 return 0;
3936 return 1;