1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
39 cpp_options parse_options;
40 enum cpp_token cpp_token;
43 #undef WCHAR_TYPE_SIZE
44 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
46 /* The following symbols are subsumed in the c_global_trees array, and
47 listed here individually for documentation purposes.
49 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
51 tree short_integer_type_node;
52 tree long_integer_type_node;
53 tree long_long_integer_type_node;
55 tree short_unsigned_type_node;
56 tree long_unsigned_type_node;
57 tree long_long_unsigned_type_node;
59 tree boolean_type_node;
60 tree boolean_false_node;
61 tree boolean_true_node;
63 tree ptrdiff_type_node;
65 tree unsigned_char_type_node;
66 tree signed_char_type_node;
68 tree signed_wchar_type_node;
69 tree unsigned_wchar_type_node;
72 tree double_type_node;
73 tree long_double_type_node;
75 tree complex_integer_type_node;
76 tree complex_float_type_node;
77 tree complex_double_type_node;
78 tree complex_long_double_type_node;
86 tree unsigned_intQI_type_node;
87 tree unsigned_intHI_type_node;
88 tree unsigned_intSI_type_node;
89 tree unsigned_intDI_type_node;
90 tree unsigned_intTI_type_node;
92 tree widest_integer_literal_type_node;
93 tree widest_unsigned_literal_type_node;
95 Nodes for types `void *' and `const void *'.
97 tree ptr_type_node, const_ptr_type_node;
99 Nodes for types `char *' and `const char *'.
101 tree string_type_node, const_string_type_node;
103 Type `char[SOMENUMBER]'.
104 Used when an array of char is needed and the size is irrelevant.
106 tree char_array_type_node;
108 Type `int[SOMENUMBER]' or something like it.
109 Used when an array of int needed and the size is irrelevant.
111 tree int_array_type_node;
113 Type `wchar_t[SOMENUMBER]' or something like it.
114 Used when a wide string literal is created.
116 tree wchar_array_type_node;
118 Type `int ()' -- used for implicit declaration of functions.
120 tree default_function_type;
122 Function types `int (int)', etc.
128 tree ptr_ftype_sizetype;
130 A VOID_TYPE node, packaged in a TREE_LIST.
136 tree c_global_trees[CTI_MAX];
138 tree (*make_fname_decl) PARAMS ((tree, const char *, int));
140 /* Nonzero means the expression being parsed will never be evaluated.
141 This is a count, since unevaluated expressions can nest. */
144 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
145 A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
146 A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
147 A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, A_MALLOC,
148 A_NO_LIMIT_STACK, A_PURE};
150 enum format_type { printf_format_type, scanf_format_type,
151 strftime_format_type };
153 static void add_attribute PARAMS ((enum attrs, const char *,
155 static void init_attributes PARAMS ((void));
156 static void record_function_format PARAMS ((tree, tree, enum format_type,
158 static void record_international_format PARAMS ((tree, tree, int));
159 static int default_valid_lang_attribute PARAMS ((tree, tree, tree, tree));
161 /* Keep a stack of if statements. We record the number of compound
162 statements seen up to the if keyword, as well as the line number
163 and file of the if. If a potentially ambiguous else is seen, that
164 fact is recorded; the warning is issued when we can be sure that
165 the enclosing if statement does not have an else branch. */
173 static void tfaff PARAMS ((void));
175 static if_elt *if_stack;
177 /* Amount of space in the if statement stack. */
178 static int if_stack_space = 0;
181 static int if_stack_pointer = 0;
183 /* Generate RTL for the start of an if-then, and record the start of it
184 for ambiguous else detection. */
187 c_expand_start_cond (cond, exitflag, compstmt_count)
192 /* Make sure there is enough space on the stack. */
193 if (if_stack_space == 0)
196 if_stack = (if_elt *)xmalloc (10 * sizeof (if_elt));
198 else if (if_stack_space == if_stack_pointer)
200 if_stack_space += 10;
201 if_stack = (if_elt *)xrealloc (if_stack, if_stack_space * sizeof (if_elt));
204 /* Record this if statement. */
205 if_stack[if_stack_pointer].compstmt_count = compstmt_count;
206 if_stack[if_stack_pointer].file = input_filename;
207 if_stack[if_stack_pointer].line = lineno;
208 if_stack[if_stack_pointer].needs_warning = 0;
211 expand_start_cond (cond, exitflag);
214 /* Generate RTL for the end of an if-then. Optionally warn if a nested
215 if statement had an ambiguous else clause. */
221 if (if_stack[if_stack_pointer].needs_warning)
222 warning_with_file_and_line (if_stack[if_stack_pointer].file,
223 if_stack[if_stack_pointer].line,
224 "suggest explicit braces to avoid ambiguous `else'");
228 /* Generate RTL between the then-clause and the else-clause
229 of an if-then-else. */
232 c_expand_start_else ()
234 /* An ambiguous else warning must be generated for the enclosing if
235 statement, unless we see an else branch for that one, too. */
237 && if_stack_pointer > 1
238 && (if_stack[if_stack_pointer - 1].compstmt_count
239 == if_stack[if_stack_pointer - 2].compstmt_count))
240 if_stack[if_stack_pointer - 2].needs_warning = 1;
242 /* Even if a nested if statement had an else branch, it can't be
243 ambiguous if this one also has an else. So don't warn in that
244 case. Also don't warn for any if statements nested in this else. */
245 if_stack[if_stack_pointer - 1].needs_warning = 0;
246 if_stack[if_stack_pointer - 1].compstmt_count--;
248 expand_start_else ();
251 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
254 declare_function_name ()
256 const char *name, *printable_name;
258 if (current_function_decl == NULL)
261 printable_name = "top level";
265 /* Allow functions to be nameless (such as artificial ones). */
266 if (DECL_NAME (current_function_decl))
267 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
270 printable_name = (*decl_printable_name) (current_function_decl, 2);
273 (*make_fname_decl) (get_identifier ("__FUNCTION__"), name, 0);
274 (*make_fname_decl) (get_identifier ("__PRETTY_FUNCTION__"), printable_name, 1);
275 /* The ISO C people "of course" couldn't use __FUNCTION__ in the
276 ISO C 99 standard; instead a new variable is invented. */
277 (*make_fname_decl) (get_identifier ("__func__"), name, 0);
280 /* Given a chain of STRING_CST nodes,
281 concatenate them into one STRING_CST
282 and give it a suitable array-of-chars data type. */
285 combine_strings (strings)
288 register tree value, t;
289 register int length = 1;
292 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
295 if (TREE_CHAIN (strings))
297 /* More than one in the chain, so concatenate. */
298 register char *p, *q;
300 /* Don't include the \0 at the end of each substring,
301 except for the last one.
302 Count wide strings and ordinary strings separately. */
303 for (t = strings; t; t = TREE_CHAIN (t))
305 if (TREE_TYPE (t) == wchar_array_type_node)
307 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
311 length += (TREE_STRING_LENGTH (t) - 1);
314 /* If anything is wide, the non-wides will be converted,
315 which makes them take more space. */
317 length = length * wchar_bytes + wide_length;
319 p = ggc_alloc_string (NULL, length);
321 /* Copy the individual strings into the new combined string.
322 If the combined string is wide, convert the chars to ints
323 for any individual strings that are not wide. */
326 for (t = strings; t; t = TREE_CHAIN (t))
328 int len = (TREE_STRING_LENGTH (t)
329 - ((TREE_TYPE (t) == wchar_array_type_node)
331 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
333 memcpy (q, TREE_STRING_POINTER (t), len);
339 for (i = 0; i < len; i++)
341 if (WCHAR_TYPE_SIZE == HOST_BITS_PER_SHORT)
342 ((short *) q)[i] = TREE_STRING_POINTER (t)[i];
344 ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
346 q += len * wchar_bytes;
352 for (i = 0; i < wchar_bytes; i++)
358 value = make_node (STRING_CST);
359 TREE_STRING_POINTER (value) = p;
360 TREE_STRING_LENGTH (value) = length;
365 length = TREE_STRING_LENGTH (value);
366 if (TREE_TYPE (value) == wchar_array_type_node)
370 /* Compute the number of elements, for the array type. */
371 nchars = wide_flag ? length / wchar_bytes : length;
373 /* Create the array type for the string constant.
374 -Wwrite-strings says make the string constant an array of const char
375 so that copying it to a non-const pointer will get a warning.
376 For C++, this is the standard behavior. */
377 if (flag_const_strings
378 && (! flag_traditional && ! flag_writable_strings))
381 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
384 = build_array_type (elements,
385 build_index_type (build_int_2 (nchars - 1, 0)));
389 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
390 build_index_type (build_int_2 (nchars - 1, 0)));
392 TREE_CONSTANT (value) = 1;
393 TREE_READONLY (value) = ! flag_writable_strings;
394 TREE_STATIC (value) = 1;
398 /* To speed up processing of attributes, we maintain an array of
399 IDENTIFIER_NODES and the corresponding attribute types. */
401 /* Array to hold attribute information. */
403 static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50];
405 static int attrtab_idx = 0;
407 /* Add an entry to the attribute table above. */
410 add_attribute (id, string, min_len, max_len, decl_req)
413 int min_len, max_len;
418 attrtab[attrtab_idx].id = id;
419 attrtab[attrtab_idx].name = get_identifier (string);
420 attrtab[attrtab_idx].min = min_len;
421 attrtab[attrtab_idx].max = max_len;
422 attrtab[attrtab_idx++].decl_req = decl_req;
424 sprintf (buf, "__%s__", string);
426 attrtab[attrtab_idx].id = id;
427 attrtab[attrtab_idx].name = get_identifier (buf);
428 attrtab[attrtab_idx].min = min_len;
429 attrtab[attrtab_idx].max = max_len;
430 attrtab[attrtab_idx++].decl_req = decl_req;
433 /* Initialize attribute table. */
438 add_attribute (A_PACKED, "packed", 0, 0, 0);
439 add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1);
440 add_attribute (A_COMMON, "common", 0, 0, 1);
441 add_attribute (A_NORETURN, "noreturn", 0, 0, 1);
442 add_attribute (A_NORETURN, "volatile", 0, 0, 1);
443 add_attribute (A_UNUSED, "unused", 0, 0, 0);
444 add_attribute (A_CONST, "const", 0, 0, 1);
445 add_attribute (A_T_UNION, "transparent_union", 0, 0, 0);
446 add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1);
447 add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1);
448 add_attribute (A_MODE, "mode", 1, 1, 1);
449 add_attribute (A_SECTION, "section", 1, 1, 1);
450 add_attribute (A_ALIGNED, "aligned", 0, 1, 0);
451 add_attribute (A_FORMAT, "format", 3, 3, 1);
452 add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1);
453 add_attribute (A_WEAK, "weak", 0, 0, 1);
454 add_attribute (A_ALIAS, "alias", 1, 1, 1);
455 add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
456 add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
457 add_attribute (A_MALLOC, "malloc", 0, 0, 1);
458 add_attribute (A_NO_LIMIT_STACK, "no_stack_limit", 0, 0, 1);
459 add_attribute (A_PURE, "pure", 0, 0, 1);
462 /* Default implementation of valid_lang_attribute, below. By default, there
463 are no language-specific attributes. */
466 default_valid_lang_attribute (attr_name, attr_args, decl, type)
467 tree attr_name ATTRIBUTE_UNUSED;
468 tree attr_args ATTRIBUTE_UNUSED;
469 tree decl ATTRIBUTE_UNUSED;
470 tree type ATTRIBUTE_UNUSED;
475 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
476 attribute for either declaration DECL or type TYPE and 0 otherwise. */
478 int (*valid_lang_attribute) PARAMS ((tree, tree, tree, tree))
479 = default_valid_lang_attribute;
481 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
482 and install them in NODE, which is either a DECL (including a TYPE_DECL)
483 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
484 and declaration modifiers but before the declaration proper. */
487 decl_attributes (node, attributes, prefix_attributes)
488 tree node, attributes, prefix_attributes;
490 tree decl = 0, type = 0;
494 if (attrtab_idx == 0)
500 type = TREE_TYPE (decl);
501 is_type = TREE_CODE (node) == TYPE_DECL;
503 else if (TYPE_P (node))
504 type = node, is_type = 1;
506 #ifdef PRAGMA_INSERT_ATTRIBUTES
507 /* If the code in c-pragma.c wants to insert some attributes then
508 allow it to do so. Do this before allowing machine back ends to
509 insert attributes, so that they have the opportunity to override
510 anything done here. */
511 PRAGMA_INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
514 #ifdef INSERT_ATTRIBUTES
515 INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
518 attributes = chainon (prefix_attributes, attributes);
520 for (a = attributes; a; a = TREE_CHAIN (a))
522 tree name = TREE_PURPOSE (a);
523 tree args = TREE_VALUE (a);
527 for (i = 0; i < attrtab_idx; i++)
528 if (attrtab[i].name == name)
531 if (i == attrtab_idx)
533 if (! valid_machine_attribute (name, args, decl, type)
534 && ! (* valid_lang_attribute) (name, args, decl, type))
535 warning ("`%s' attribute directive ignored",
536 IDENTIFIER_POINTER (name));
538 type = TREE_TYPE (decl);
541 else if (attrtab[i].decl_req && decl == 0)
543 warning ("`%s' attribute does not apply to types",
544 IDENTIFIER_POINTER (name));
547 else if (list_length (args) < attrtab[i].min
548 || list_length (args) > attrtab[i].max)
550 error ("wrong number of arguments specified for `%s' attribute",
551 IDENTIFIER_POINTER (name));
560 TYPE_PACKED (type) = 1;
561 else if (TREE_CODE (decl) == FIELD_DECL)
562 DECL_PACKED (decl) = 1;
563 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
564 used for DECL_REGISTER. It wouldn't mean anything anyway. */
566 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
570 if (TREE_CODE (decl) == VAR_DECL)
571 DECL_COMMON (decl) = 0;
573 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
577 if (TREE_CODE (decl) == VAR_DECL)
578 DECL_COMMON (decl) = 1;
580 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
584 if (TREE_CODE (decl) == FUNCTION_DECL)
585 TREE_THIS_VOLATILE (decl) = 1;
586 else if (TREE_CODE (type) == POINTER_TYPE
587 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
588 TREE_TYPE (decl) = type
590 (build_type_variant (TREE_TYPE (type),
591 TREE_READONLY (TREE_TYPE (type)), 1));
593 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
597 if (TREE_CODE (decl) == FUNCTION_DECL)
598 DECL_IS_MALLOC (decl) = 1;
599 /* ??? TODO: Support types. */
601 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
607 TREE_USED (decl) = 1;
609 TREE_USED (type) = 1;
610 else if (TREE_CODE (decl) == PARM_DECL
611 || TREE_CODE (decl) == VAR_DECL
612 || TREE_CODE (decl) == FUNCTION_DECL
613 || TREE_CODE (decl) == LABEL_DECL)
614 TREE_USED (decl) = 1;
616 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
620 if (TREE_CODE (decl) == FUNCTION_DECL)
621 TREE_READONLY (decl) = 1;
622 else if (TREE_CODE (type) == POINTER_TYPE
623 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
624 TREE_TYPE (decl) = type
626 (build_type_variant (TREE_TYPE (type), 1,
627 TREE_THIS_VOLATILE (TREE_TYPE (type))));
629 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name));
633 if (TREE_CODE (decl) == FUNCTION_DECL)
634 DECL_IS_PURE (decl) = 1;
635 /* ??? TODO: Support types. */
637 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
643 && TREE_CODE (type) == UNION_TYPE
645 || (TYPE_FIELDS (type) != 0
646 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))))
647 TYPE_TRANSPARENT_UNION (type) = 1;
648 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
649 && TREE_CODE (type) == UNION_TYPE
650 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))
651 DECL_TRANSPARENT_UNION (decl) = 1;
653 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
657 if (TREE_CODE (decl) == FUNCTION_DECL
658 && TREE_CODE (type) == FUNCTION_TYPE
659 && decl_function_context (decl) == 0)
661 DECL_STATIC_CONSTRUCTOR (decl) = 1;
662 TREE_USED (decl) = 1;
665 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
669 if (TREE_CODE (decl) == FUNCTION_DECL
670 && TREE_CODE (type) == FUNCTION_TYPE
671 && decl_function_context (decl) == 0)
673 DECL_STATIC_DESTRUCTOR (decl) = 1;
674 TREE_USED (decl) = 1;
677 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
681 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
682 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
686 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
687 int len = strlen (p);
688 enum machine_mode mode = VOIDmode;
691 if (len > 4 && p[0] == '_' && p[1] == '_'
692 && p[len - 1] == '_' && p[len - 2] == '_')
694 char *newp = (char *) alloca (len - 1);
696 strcpy (newp, &p[2]);
697 newp[len - 4] = '\0';
701 /* Give this decl a type with the specified mode.
702 First check for the special modes. */
703 if (! strcmp (p, "byte"))
705 else if (!strcmp (p, "word"))
707 else if (! strcmp (p, "pointer"))
710 for (j = 0; j < NUM_MACHINE_MODES; j++)
711 if (!strcmp (p, GET_MODE_NAME (j)))
712 mode = (enum machine_mode) j;
714 if (mode == VOIDmode)
715 error ("unknown machine mode `%s'", p);
716 else if (0 == (typefm = type_for_mode (mode,
717 TREE_UNSIGNED (type))))
718 error ("no data type for mode `%s'", p);
721 TREE_TYPE (decl) = type = typefm;
722 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
723 layout_decl (decl, 0);
729 #ifdef ASM_OUTPUT_SECTION_NAME
730 if ((TREE_CODE (decl) == FUNCTION_DECL
731 || TREE_CODE (decl) == VAR_DECL)
732 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
734 if (TREE_CODE (decl) == VAR_DECL
735 && current_function_decl != NULL_TREE
736 && ! TREE_STATIC (decl))
737 error_with_decl (decl,
738 "section attribute cannot be specified for local variables");
739 /* The decl may have already been given a section attribute from
740 a previous declaration. Ensure they match. */
741 else if (DECL_SECTION_NAME (decl) != NULL_TREE
742 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
743 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
744 error_with_decl (node,
745 "section of `%s' conflicts with previous declaration");
747 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
750 error_with_decl (node,
751 "section attribute not allowed for `%s'");
753 error_with_decl (node,
754 "section attributes are not supported for this target");
761 = (args ? TREE_VALUE (args)
762 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
765 /* Strip any NOPs of any kind. */
766 while (TREE_CODE (align_expr) == NOP_EXPR
767 || TREE_CODE (align_expr) == CONVERT_EXPR
768 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
769 align_expr = TREE_OPERAND (align_expr, 0);
771 if (TREE_CODE (align_expr) != INTEGER_CST)
773 error ("requested alignment is not a constant");
777 if ((i = tree_log2 (align_expr)) == -1)
778 error ("requested alignment is not a power of 2");
779 else if (i > HOST_BITS_PER_INT - 2)
780 error ("requested alignment is too large");
782 TYPE_ALIGN (type) = (1 << i) * BITS_PER_UNIT;
783 else if (TREE_CODE (decl) != VAR_DECL
784 && TREE_CODE (decl) != FIELD_DECL)
785 error_with_decl (decl,
786 "alignment may not be specified for `%s'");
788 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
794 tree format_type_id = TREE_VALUE (args);
795 tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
796 tree first_arg_num_expr
797 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
798 unsigned HOST_WIDE_INT format_num, first_arg_num;
799 enum format_type format_type;
801 unsigned int arg_num;
803 if (TREE_CODE (decl) != FUNCTION_DECL)
805 error_with_decl (decl,
806 "argument format specified for non-function `%s'");
810 if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
812 error ("unrecognized format specifier");
817 const char *p = IDENTIFIER_POINTER (format_type_id);
819 if (!strcmp (p, "printf") || !strcmp (p, "__printf__"))
820 format_type = printf_format_type;
821 else if (!strcmp (p, "scanf") || !strcmp (p, "__scanf__"))
822 format_type = scanf_format_type;
823 else if (!strcmp (p, "strftime")
824 || !strcmp (p, "__strftime__"))
825 format_type = strftime_format_type;
828 warning ("`%s' is an unrecognized format function type", p);
833 /* Strip any conversions from the string index and first arg number
834 and verify they are constants. */
835 while (TREE_CODE (format_num_expr) == NOP_EXPR
836 || TREE_CODE (format_num_expr) == CONVERT_EXPR
837 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
838 format_num_expr = TREE_OPERAND (format_num_expr, 0);
840 while (TREE_CODE (first_arg_num_expr) == NOP_EXPR
841 || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR
842 || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR)
843 first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0);
845 if (TREE_CODE (format_num_expr) != INTEGER_CST
846 || TREE_INT_CST_HIGH (format_num_expr) != 0
847 || TREE_CODE (first_arg_num_expr) != INTEGER_CST
848 || TREE_INT_CST_HIGH (first_arg_num_expr) != 0)
850 error ("format string has invalid operand number");
854 format_num = TREE_INT_CST_LOW (format_num_expr);
855 first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr);
856 if (first_arg_num != 0 && first_arg_num <= format_num)
858 error ("format string arg follows the args to be formatted");
862 /* If a parameter list is specified, verify that the format_num
863 argument is actually a string, in case the format attribute
865 argument = TYPE_ARG_TYPES (type);
868 for (arg_num = 1; argument != 0 && arg_num != format_num;
869 ++arg_num, argument = TREE_CHAIN (argument))
873 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
874 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
877 error ("format string arg not a string type");
881 else if (first_arg_num != 0)
883 /* Verify that first_arg_num points to the last arg,
886 arg_num++, argument = TREE_CHAIN (argument);
888 if (arg_num != first_arg_num)
890 error ("args to be formatted is not '...'");
896 record_function_format (DECL_NAME (decl),
897 DECL_ASSEMBLER_NAME (decl),
898 format_type, format_num, first_arg_num);
904 tree format_num_expr = TREE_VALUE (args);
905 unsigned HOST_WIDE_INT format_num;
906 unsigned int arg_num;
909 if (TREE_CODE (decl) != FUNCTION_DECL)
911 error_with_decl (decl,
912 "argument format specified for non-function `%s'");
916 /* Strip any conversions from the first arg number and verify it
918 while (TREE_CODE (format_num_expr) == NOP_EXPR
919 || TREE_CODE (format_num_expr) == CONVERT_EXPR
920 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
921 format_num_expr = TREE_OPERAND (format_num_expr, 0);
923 if (TREE_CODE (format_num_expr) != INTEGER_CST
924 || TREE_INT_CST_HIGH (format_num_expr) != 0)
926 error ("format string has invalid operand number");
930 format_num = TREE_INT_CST_LOW (format_num_expr);
932 /* If a parameter list is specified, verify that the format_num
933 argument is actually a string, in case the format attribute
935 argument = TYPE_ARG_TYPES (type);
938 for (arg_num = 1; argument != 0 && arg_num != format_num;
939 ++arg_num, argument = TREE_CHAIN (argument))
943 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
944 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
947 error ("format string arg not a string type");
952 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != POINTER_TYPE
953 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl))))
956 error ("function does not return string type");
960 record_international_format (DECL_NAME (decl),
961 DECL_ASSEMBLER_NAME (decl),
971 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
972 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
973 error_with_decl (decl,
974 "`%s' defined both normally and as an alias");
975 else if (decl_function_context (decl) == 0)
979 id = TREE_VALUE (args);
980 if (TREE_CODE (id) != STRING_CST)
982 error ("alias arg not a string");
985 id = get_identifier (TREE_STRING_POINTER (id));
986 /* This counts as a use of the object pointed to. */
989 if (TREE_CODE (decl) == FUNCTION_DECL)
990 DECL_INITIAL (decl) = error_mark_node;
992 DECL_EXTERNAL (decl) = 0;
993 assemble_alias (decl, id);
996 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
999 case A_NO_CHECK_MEMORY_USAGE:
1000 if (TREE_CODE (decl) != FUNCTION_DECL)
1002 error_with_decl (decl,
1003 "`%s' attribute applies only to functions",
1004 IDENTIFIER_POINTER (name));
1006 else if (DECL_INITIAL (decl))
1008 error_with_decl (decl,
1009 "can't set `%s' attribute after definition",
1010 IDENTIFIER_POINTER (name));
1013 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
1016 case A_NO_INSTRUMENT_FUNCTION:
1017 if (TREE_CODE (decl) != FUNCTION_DECL)
1019 error_with_decl (decl,
1020 "`%s' attribute applies only to functions",
1021 IDENTIFIER_POINTER (name));
1023 else if (DECL_INITIAL (decl))
1025 error_with_decl (decl,
1026 "can't set `%s' attribute after definition",
1027 IDENTIFIER_POINTER (name));
1030 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
1033 case A_NO_LIMIT_STACK:
1034 if (TREE_CODE (decl) != FUNCTION_DECL)
1036 error_with_decl (decl,
1037 "`%s' attribute applies only to functions",
1038 IDENTIFIER_POINTER (name));
1040 else if (DECL_INITIAL (decl))
1042 error_with_decl (decl,
1043 "can't set `%s' attribute after definition",
1044 IDENTIFIER_POINTER (name));
1047 DECL_NO_LIMIT_STACK (decl) = 1;
1053 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1054 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1056 The head of the declspec list is stored in DECLSPECS.
1057 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1059 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1060 the list elements. We drop the containing TREE_LIST nodes and link the
1061 resulting attributes together the way decl_attributes expects them. */
1064 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1066 tree *declspecs, *prefix_attributes;
1068 tree t, s, a, next, specs, attrs;
1070 /* This can happen after an __extension__ in pedantic mode. */
1071 if (specs_attrs != NULL_TREE
1072 && TREE_CODE (specs_attrs) == INTEGER_CST)
1074 *declspecs = NULL_TREE;
1075 *prefix_attributes = NULL_TREE;
1079 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1080 if (specs_attrs != NULL_TREE
1081 && TREE_CODE (specs_attrs) != TREE_LIST)
1083 *declspecs = specs_attrs;
1084 *prefix_attributes = NULL_TREE;
1088 /* Remember to keep the lists in the same order, element-wise. */
1090 specs = s = NULL_TREE;
1091 attrs = a = NULL_TREE;
1092 for (t = specs_attrs; t; t = next)
1094 next = TREE_CHAIN (t);
1095 /* Declspecs have a non-NULL TREE_VALUE. */
1096 if (TREE_VALUE (t) != NULL_TREE)
1098 if (specs == NULL_TREE)
1108 if (attrs == NULL_TREE)
1109 attrs = a = TREE_PURPOSE (t);
1112 TREE_CHAIN (a) = TREE_PURPOSE (t);
1113 a = TREE_PURPOSE (t);
1115 /* More attrs can be linked here, move A to the end. */
1116 while (TREE_CHAIN (a) != NULL_TREE)
1121 /* Terminate the lists. */
1123 TREE_CHAIN (s) = NULL_TREE;
1125 TREE_CHAIN (a) = NULL_TREE;
1129 *prefix_attributes = attrs;
1132 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1133 This function is used by the parser when a rule will accept attributes
1134 in a particular position, but we don't want to support that just yet.
1136 A warning is issued for every ignored attribute. */
1139 strip_attrs (specs_attrs)
1144 split_specs_attrs (specs_attrs, &specs, &attrs);
1148 warning ("`%s' attribute ignored",
1149 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1150 attrs = TREE_CHAIN (attrs);
1156 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1157 a parameter list. */
1159 #define T_I &integer_type_node
1160 #define T_L &long_integer_type_node
1161 #define T_LL &long_long_integer_type_node
1162 #define T_S &short_integer_type_node
1163 #define T_UI &unsigned_type_node
1164 #define T_UL &long_unsigned_type_node
1165 #define T_ULL &long_long_unsigned_type_node
1166 #define T_US &short_unsigned_type_node
1167 #define T_F &float_type_node
1168 #define T_D &double_type_node
1169 #define T_LD &long_double_type_node
1170 #define T_C &char_type_node
1171 #define T_UC &unsigned_char_type_node
1172 #define T_V &void_type_node
1173 #define T_W &wchar_type_node
1174 #define T_ST &sizetype
1177 const char *format_chars;
1179 /* Type of argument if no length modifier is used. */
1181 /* Type of argument if length modifier for shortening to byte is used.
1182 If NULL, then this modifier is not allowed. */
1184 /* Type of argument if length modifier for shortening is used.
1185 If NULL, then this modifier is not allowed. */
1187 /* Type of argument if length modifier `l' is used.
1188 If NULL, then this modifier is not allowed. */
1190 /* Type of argument if length modifier `q' or `ll' is used.
1191 If NULL, then this modifier is not allowed. */
1193 /* Type of argument if length modifier `L' is used.
1194 If NULL, then this modifier is not allowed. */
1196 /* Type of argument if length modifiers 'z' or `Z' is used.
1197 If NULL, then this modifier is not allowed. */
1199 /* List of other modifier characters allowed with these options. */
1200 const char *flag_chars;
1203 static format_char_info print_char_table[] = {
1204 { "di", 0, T_I, T_I, T_I, T_L, T_LL, T_LL, T_ST, "-wp0 +" },
1205 { "oxX", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, "-wp0#" },
1206 { "u", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, "-wp0" },
1207 /* A GNU extension. */
1208 { "m", 0, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
1209 { "feEgGaA", 0, T_D, NULL, NULL, NULL, NULL, T_LD, NULL, "-wp0 +#" },
1210 { "c", 0, T_I, NULL, NULL, T_W, NULL, NULL, NULL, "-w" },
1211 { "C", 0, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
1212 { "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "-wp" },
1213 { "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
1214 { "p", 1, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
1215 { "n", 1, T_I, NULL, T_S, T_L, T_LL, NULL, NULL, "" },
1216 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1219 static format_char_info scan_char_table[] = {
1220 { "di", 1, T_I, T_C, T_S, T_L, T_LL, T_LL, NULL, "*" },
1221 { "ouxX", 1, T_UI, T_UC, T_US, T_UL, T_ULL, T_ULL, NULL, "*" },
1222 { "efgEGaA", 1, T_F, NULL, NULL, T_D, NULL, T_LD, NULL, "*" },
1223 { "c", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "*" },
1224 { "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "*a" },
1225 { "[", 1, T_C, NULL, NULL, NULL, NULL, NULL, NULL, "*a" },
1226 { "C", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "*" },
1227 { "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "*a" },
1228 { "p", 2, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "*" },
1229 { "n", 1, T_I, T_C, T_S, T_L, T_LL, NULL, NULL, "" },
1230 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1233 /* Handle format characters recognized by glibc's strftime.c.
1234 '2' - MUST do years as only two digits
1235 '3' - MAY do years as only two digits (depending on locale)
1236 'E' - E modifier is acceptable
1237 'O' - O modifier is acceptable to Standard C
1238 'o' - O modifier is acceptable as a GNU extension
1239 'G' - other GNU extensions */
1241 static format_char_info time_char_table[] = {
1242 { "y", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2EO-_0w" },
1243 { "D", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2" },
1244 { "g", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2O-_0w" },
1245 { "cx", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "3E" },
1246 { "%RTXnrt", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "" },
1247 { "P", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "G" },
1248 { "HIMSUWdemw", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Ow" },
1249 { "Vju", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow" },
1250 { "Gklsz", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0OGw" },
1251 { "ABZa", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^#" },
1252 { "p", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "#" },
1253 { "bh", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^" },
1254 { "CY", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0EOw" },
1255 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1258 typedef struct function_format_info
1260 struct function_format_info *next; /* next structure on the list */
1261 tree name; /* identifier such as "printf" */
1262 tree assembler_name; /* optional mangled identifier (for C++) */
1263 enum format_type format_type; /* type of format (printf, scanf, etc.) */
1264 int format_num; /* number of format argument */
1265 int first_arg_num; /* number of first arg (zero for varargs) */
1266 } function_format_info;
1268 static function_format_info *function_format_list = NULL;
1270 typedef struct international_format_info
1272 struct international_format_info *next; /* next structure on the list */
1273 tree name; /* identifier such as "gettext" */
1274 tree assembler_name; /* optional mangled identifier (for C++) */
1275 int format_num; /* number of format argument */
1276 } international_format_info;
1278 static international_format_info *international_format_list = NULL;
1280 static void check_format_info PARAMS ((function_format_info *, tree));
1282 /* Initialize the table of functions to perform format checking on.
1283 The ANSI functions are always checked (whether <stdio.h> is
1284 included or not), since it is common to call printf without
1285 including <stdio.h>. There shouldn't be a problem with this,
1286 since ANSI reserves these function names whether you include the
1287 header file or not. In any case, the checking is harmless.
1289 Also initialize the name of function that modify the format string for
1290 internationalization purposes. */
1293 init_function_format_info ()
1295 record_function_format (get_identifier ("printf"), NULL_TREE,
1296 printf_format_type, 1, 2);
1297 record_function_format (get_identifier ("fprintf"), NULL_TREE,
1298 printf_format_type, 2, 3);
1299 record_function_format (get_identifier ("sprintf"), NULL_TREE,
1300 printf_format_type, 2, 3);
1301 record_function_format (get_identifier ("scanf"), NULL_TREE,
1302 scanf_format_type, 1, 2);
1303 record_function_format (get_identifier ("fscanf"), NULL_TREE,
1304 scanf_format_type, 2, 3);
1305 record_function_format (get_identifier ("sscanf"), NULL_TREE,
1306 scanf_format_type, 2, 3);
1307 record_function_format (get_identifier ("vprintf"), NULL_TREE,
1308 printf_format_type, 1, 0);
1309 record_function_format (get_identifier ("vfprintf"), NULL_TREE,
1310 printf_format_type, 2, 0);
1311 record_function_format (get_identifier ("vsprintf"), NULL_TREE,
1312 printf_format_type, 2, 0);
1313 record_function_format (get_identifier ("strftime"), NULL_TREE,
1314 strftime_format_type, 3, 0);
1316 record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
1317 record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
1318 record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
1321 /* Record information for argument format checking. FUNCTION_IDENT is
1322 the identifier node for the name of the function to check (its decl
1323 need not exist yet).
1324 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
1325 of the argument which is the format control string (starting from 1).
1326 FIRST_ARG_NUM is the number of the first actual argument to check
1327 against the format string, or zero if no checking is not be done
1328 (e.g. for varargs such as vfprintf). */
1331 record_function_format (name, assembler_name, format_type,
1332 format_num, first_arg_num)
1334 tree assembler_name;
1335 enum format_type format_type;
1339 function_format_info *info;
1341 /* Re-use existing structure if it's there. */
1343 for (info = function_format_list; info; info = info->next)
1345 if (info->name == name && info->assembler_name == assembler_name)
1350 info = (function_format_info *) xmalloc (sizeof (function_format_info));
1351 info->next = function_format_list;
1352 function_format_list = info;
1355 info->assembler_name = assembler_name;
1358 info->format_type = format_type;
1359 info->format_num = format_num;
1360 info->first_arg_num = first_arg_num;
1363 /* Record information for the names of function that modify the format
1364 argument to format functions. FUNCTION_IDENT is the identifier node for
1365 the name of the function (its decl need not exist yet) and FORMAT_NUM is
1366 the number of the argument which is the format control string (starting
1370 record_international_format (name, assembler_name, format_num)
1372 tree assembler_name;
1375 international_format_info *info;
1377 /* Re-use existing structure if it's there. */
1379 for (info = international_format_list; info; info = info->next)
1381 if (info->name == name && info->assembler_name == assembler_name)
1388 = (international_format_info *)
1389 xmalloc (sizeof (international_format_info));
1390 info->next = international_format_list;
1391 international_format_list = info;
1394 info->assembler_name = assembler_name;
1397 info->format_num = format_num;
1403 warning ("too few arguments for format");
1406 /* Check the argument list of a call to printf, scanf, etc.
1407 NAME is the function identifier.
1408 ASSEMBLER_NAME is the function's assembler identifier.
1409 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1410 PARAMS is the list of argument values. */
1413 check_function_format (name, assembler_name, params)
1415 tree assembler_name;
1418 function_format_info *info;
1420 /* See if this function is a format function. */
1421 for (info = function_format_list; info; info = info->next)
1423 if (info->assembler_name
1424 ? (info->assembler_name == assembler_name)
1425 : (info->name == name))
1427 /* Yup; check it. */
1428 check_format_info (info, params);
1434 /* Check the argument list of a call to printf, scanf, etc.
1435 INFO points to the function_format_info structure.
1436 PARAMS is the list of argument values. */
1439 check_format_info (info, params)
1440 function_format_info *info;
1445 int suppressed, wide, precise;
1446 int length_char = 0;
1453 tree first_fillin_param;
1454 const char *format_chars;
1455 format_char_info *fci = NULL;
1457 int has_operand_number = 0;
1459 /* Skip to format argument. If the argument isn't available, there's
1460 no work for us to do; prototype checking will catch the problem. */
1461 for (arg_num = 1; ; ++arg_num)
1465 if (arg_num == info->format_num)
1467 params = TREE_CHAIN (params);
1469 format_tree = TREE_VALUE (params);
1470 params = TREE_CHAIN (params);
1471 if (format_tree == 0)
1474 /* We can only check the format if it's a string constant. */
1475 while (TREE_CODE (format_tree) == NOP_EXPR)
1476 format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
1478 if (TREE_CODE (format_tree) == CALL_EXPR
1479 && TREE_CODE (TREE_OPERAND (format_tree, 0)) == ADDR_EXPR
1480 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0))
1483 tree function = TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0);
1485 /* See if this is a call to a known internationalization function
1486 that modifies the format arg. */
1487 international_format_info *info;
1489 for (info = international_format_list; info; info = info->next)
1490 if (info->assembler_name
1491 ? (info->assembler_name == DECL_ASSEMBLER_NAME (function))
1492 : (info->name == DECL_NAME (function)))
1497 for (inner_args = TREE_OPERAND (format_tree, 1), i = 1;
1499 inner_args = TREE_CHAIN (inner_args), i++)
1500 if (i == info->format_num)
1502 format_tree = TREE_VALUE (inner_args);
1504 while (TREE_CODE (format_tree) == NOP_EXPR)
1505 format_tree = TREE_OPERAND (format_tree, 0);
1510 if (integer_zerop (format_tree))
1512 warning ("null format string");
1515 if (TREE_CODE (format_tree) != ADDR_EXPR)
1517 /* The user may get multiple warnings if the supplied argument
1518 isn't even a string pointer. */
1519 /* Functions taking a va_list normally pass a non-literal format
1520 string. These functions typically are declared with
1521 first_arg_num == 0, so avoid warning in those cases. */
1522 if (info->first_arg_num != 0 && warn_format > 1)
1523 warning ("format not a string literal, argument types not checked");
1526 format_tree = TREE_OPERAND (format_tree, 0);
1527 if (TREE_CODE (format_tree) != STRING_CST)
1529 /* The user may get multiple warnings if the supplied argument
1530 isn't even a string pointer. */
1531 /* Functions taking a va_list normally pass a non-literal format
1532 string. These functions typically are declared with
1533 first_arg_num == 0, so avoid warning in those cases. */
1534 if (info->first_arg_num != 0 && warn_format > 1)
1535 warning ("format not a string literal, argument types not checked");
1538 format_chars = TREE_STRING_POINTER (format_tree);
1539 format_length = TREE_STRING_LENGTH (format_tree);
1540 if (format_length <= 1)
1541 warning ("zero-length format string");
1542 if (format_chars[--format_length] != 0)
1544 warning ("unterminated format string");
1547 /* Skip to first argument to check. */
1548 while (arg_num + 1 < info->first_arg_num)
1552 params = TREE_CHAIN (params);
1556 first_fillin_param = params;
1560 if (*format_chars == 0)
1562 if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
1563 warning ("embedded `\\0' in format");
1564 if (info->first_arg_num != 0 && params != 0 && ! has_operand_number)
1565 warning ("too many arguments for format");
1568 if (*format_chars++ != '%')
1570 if (*format_chars == 0)
1572 warning ("spurious trailing `%%' in format");
1575 if (*format_chars == '%')
1581 suppressed = wide = precise = FALSE;
1582 if (info->format_type == scanf_format_type)
1584 suppressed = *format_chars == '*';
1587 while (ISDIGIT (*format_chars))
1590 else if (info->format_type == strftime_format_type)
1592 while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0)
1595 warning ("ANSI C does not support the strftime `%c' flag",
1597 if (index (flag_chars, *format_chars) != 0)
1599 warning ("repeated `%c' flag in format",
1605 i = strlen (flag_chars);
1606 flag_chars[i++] = *format_chars++;
1610 while (ISDIGIT ((unsigned char) *format_chars))
1615 if (wide && pedantic)
1616 warning ("ANSI C does not support strftime format width");
1617 if (*format_chars == 'E' || *format_chars == 'O')
1619 i = strlen (flag_chars);
1620 flag_chars[i++] = *format_chars++;
1622 if (*format_chars == 'E' || *format_chars == 'O')
1624 warning ("multiple E/O modifiers in format");
1625 while (*format_chars == 'E' || *format_chars == 'O')
1630 else if (info->format_type == printf_format_type)
1632 /* See if we have a number followed by a dollar sign. If we do,
1633 it is an operand number, so set PARAMS to that operand. */
1634 if (*format_chars >= '0' && *format_chars <= '9')
1636 const char *p = format_chars;
1638 while (*p >= '0' && *p++ <= '9')
1643 int opnum = atoi (format_chars);
1645 params = first_fillin_param;
1646 format_chars = p + 1;
1647 has_operand_number = 1;
1649 for (i = 1; i < opnum && params != 0; i++)
1650 params = TREE_CHAIN (params);
1652 if (opnum == 0 || params == 0)
1654 warning ("operand number out of range in format");
1660 while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
1662 if (index (flag_chars, *format_chars) != 0)
1663 warning ("repeated `%c' flag in format", *format_chars++);
1666 i = strlen (flag_chars);
1667 flag_chars[i++] = *format_chars++;
1671 /* "If the space and + flags both appear,
1672 the space flag will be ignored." */
1673 if (index (flag_chars, ' ') != 0
1674 && index (flag_chars, '+') != 0)
1675 warning ("use of both ` ' and `+' flags in format");
1676 /* "If the 0 and - flags both appear,
1677 the 0 flag will be ignored." */
1678 if (index (flag_chars, '0') != 0
1679 && index (flag_chars, '-') != 0)
1680 warning ("use of both `0' and `-' flags in format");
1681 if (*format_chars == '*')
1684 /* "...a field width...may be indicated by an asterisk.
1685 In this case, an int argument supplies the field width..." */
1692 if (info->first_arg_num != 0)
1694 cur_param = TREE_VALUE (params);
1695 params = TREE_CHAIN (params);
1697 /* size_t is generally not valid here.
1698 It will work on most machines, because size_t and int
1699 have the same mode. But might as well warn anyway,
1700 since it will fail on other machines. */
1701 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1702 != integer_type_node)
1704 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1705 != unsigned_type_node))
1706 warning ("field width is not type int (arg %d)", arg_num);
1711 while (ISDIGIT (*format_chars))
1717 if (*format_chars == '.')
1721 if (*format_chars != '*' && !ISDIGIT (*format_chars))
1722 warning ("`.' not followed by `*' or digit in format");
1723 /* "...a...precision...may be indicated by an asterisk.
1724 In this case, an int argument supplies the...precision." */
1725 if (*format_chars == '*')
1727 if (info->first_arg_num != 0)
1735 cur_param = TREE_VALUE (params);
1736 params = TREE_CHAIN (params);
1738 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1739 != integer_type_node)
1740 warning ("field width is not type int (arg %d)",
1746 while (ISDIGIT (*format_chars))
1754 if (info->format_type != strftime_format_type)
1756 if (*format_chars == 'h' || *format_chars == 'l')
1757 length_char = *format_chars++;
1758 else if (*format_chars == 'q' || *format_chars == 'L')
1760 length_char = *format_chars++;
1762 warning ("ANSI C does not support the `%c' length modifier",
1765 else if (*format_chars == 'Z' || *format_chars == 'z')
1767 length_char = *format_chars++;
1768 if (pedantic && (length_char == 'Z' || !flag_isoc99))
1769 warning ("ANSI C does not support the `%c' length modifier",
1774 if (length_char == 'l' && *format_chars == 'l')
1776 length_char = 'q', format_chars++;
1777 if (pedantic && !flag_isoc99)
1778 warning ("ANSI C does not support the `ll' length modifier");
1780 else if (length_char == 'h' && *format_chars == 'h')
1782 length_char = 'H', format_chars++;
1783 if (pedantic && !flag_isoc99)
1784 warning ("ANSI C does not support the `hh' length modifier");
1786 if (*format_chars == 'a' && info->format_type == scanf_format_type)
1788 if (format_chars[1] == 's' || format_chars[1] == 'S'
1789 || format_chars[1] == '[')
1791 /* `a' is used as a flag. */
1796 if (suppressed && length_char != 0)
1797 warning ("use of `*' and `%c' together in format", length_char);
1799 format_char = *format_chars;
1800 if (format_char == 0
1801 || (info->format_type != strftime_format_type && format_char == '%'))
1803 warning ("conversion lacks type at end of format");
1806 /* The m, C, and S formats are GNU extensions. */
1807 if (pedantic && info->format_type != strftime_format_type
1808 && (format_char == 'm' || format_char == 'C' || format_char == 'S'))
1809 warning ("ANSI C does not support the `%c' format", format_char);
1810 /* The a and A formats are C99 extensions. */
1811 if (pedantic && info->format_type != strftime_format_type
1812 && (format_char == 'a' || format_char == 'A')
1814 warning ("ANSI C does not support the `%c' format", format_char);
1816 switch (info->format_type)
1818 case printf_format_type:
1819 fci = print_char_table;
1821 case scanf_format_type:
1822 fci = scan_char_table;
1824 case strftime_format_type:
1825 fci = time_char_table;
1830 while (fci->format_chars != 0
1831 && index (fci->format_chars, format_char) == 0)
1833 if (fci->format_chars == 0)
1835 if (ISGRAPH(format_char))
1836 warning ("unknown conversion type character `%c' in format",
1839 warning ("unknown conversion type character 0x%x in format",
1845 if (index (fci->flag_chars, 'G') != 0)
1846 warning ("ANSI C does not support `%%%c'", format_char);
1847 if (index (fci->flag_chars, 'o') != 0
1848 && index (flag_chars, 'O') != 0)
1849 warning ("ANSI C does not support `%%O%c'", format_char);
1851 if (wide && index (fci->flag_chars, 'w') == 0)
1852 warning ("width used with `%c' format", format_char);
1853 if (index (fci->flag_chars, '2') != 0)
1854 warning ("`%%%c' yields only last 2 digits of year", format_char);
1855 else if (index (fci->flag_chars, '3') != 0)
1856 warning ("`%%%c' yields only last 2 digits of year in some locales",
1858 if (precise && index (fci->flag_chars, 'p') == 0)
1859 warning ("precision used with `%c' format", format_char);
1860 if (aflag && index (fci->flag_chars, 'a') == 0)
1862 warning ("`a' flag used with `%c' format", format_char);
1863 /* To simplify the following code. */
1866 /* The a flag is a GNU extension. */
1867 else if (pedantic && aflag)
1868 warning ("ANSI C does not support the `a' flag");
1869 if (info->format_type == scanf_format_type && format_char == '[')
1871 /* Skip over scan set, in case it happens to have '%' in it. */
1872 if (*format_chars == '^')
1874 /* Find closing bracket; if one is hit immediately, then
1875 it's part of the scan set rather than a terminator. */
1876 if (*format_chars == ']')
1878 while (*format_chars && *format_chars != ']')
1880 if (*format_chars != ']')
1881 /* The end of the format string was reached. */
1882 warning ("no closing `]' for `%%[' format");
1886 if (index (fci->flag_chars, '*') == 0)
1887 warning ("suppression of `%c' conversion in format", format_char);
1890 for (i = 0; flag_chars[i] != 0; ++i)
1892 if (index (fci->flag_chars, flag_chars[i]) == 0)
1893 warning ("flag `%c' used with type `%c'",
1894 flag_chars[i], format_char);
1896 if (info->format_type == strftime_format_type)
1898 if (precise && index (flag_chars, '0') != 0
1899 && (format_char == 'd' || format_char == 'i'
1900 || format_char == 'o' || format_char == 'u'
1901 || format_char == 'x' || format_char == 'X'))
1902 warning ("`0' flag ignored with precision specifier and `%c' format",
1904 switch (length_char)
1906 default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
1907 case 'H': wanted_type = fci->hhlen ? *(fci->hhlen) : 0; break;
1908 case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
1909 case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
1910 case 'q': wanted_type = fci->qlen ? *(fci->qlen) : 0; break;
1911 case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
1912 case 'z': case 'Z': wanted_type = fci->zlen ? *fci->zlen : 0; break;
1914 if (wanted_type == 0)
1915 warning ("use of `%c' length character with `%c' type character",
1916 length_char, format_char);
1918 /* Finally. . .check type of argument against desired type! */
1919 if (info->first_arg_num == 0)
1921 if (fci->pointer_count == 0 && wanted_type == void_type_node)
1922 /* This specifier takes no argument. */
1929 cur_param = TREE_VALUE (params);
1930 params = TREE_CHAIN (params);
1932 cur_type = TREE_TYPE (cur_param);
1934 STRIP_NOPS (cur_param);
1936 /* Check the types of any additional pointer arguments
1937 that precede the "real" argument. */
1938 for (i = 0; i < fci->pointer_count + aflag; ++i)
1940 if (TREE_CODE (cur_type) == POINTER_TYPE)
1942 cur_type = TREE_TYPE (cur_type);
1944 if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
1945 cur_param = TREE_OPERAND (cur_param, 0);
1951 if (TREE_CODE (cur_type) != ERROR_MARK)
1953 if (fci->pointer_count + aflag == 1)
1954 warning ("format argument is not a pointer (arg %d)", arg_num);
1956 warning ("format argument is not a pointer to a pointer (arg %d)", arg_num);
1961 /* See if this is an attempt to write into a const type with
1962 scanf or with printf "%n". */
1963 if ((info->format_type == scanf_format_type
1964 || (info->format_type == printf_format_type
1965 && format_char == 'n'))
1966 && i == fci->pointer_count + aflag
1968 && TREE_CODE (cur_type) != ERROR_MARK
1969 && (TYPE_READONLY (cur_type)
1971 && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
1972 || (DECL_P (cur_param) && TREE_READONLY (cur_param))))))
1973 warning ("writing into constant object (arg %d)", arg_num);
1975 /* Check the type of the "real" argument, if there's a type we want. */
1976 if (i == fci->pointer_count + aflag && wanted_type != 0
1977 && TREE_CODE (cur_type) != ERROR_MARK
1978 && wanted_type != TYPE_MAIN_VARIANT (cur_type)
1979 /* If we want `void *', allow any pointer type.
1980 (Anything else would already have got a warning.) */
1981 && ! (wanted_type == void_type_node
1982 && fci->pointer_count > 0)
1983 /* Don't warn about differences merely in signedness. */
1984 && !(TREE_CODE (wanted_type) == INTEGER_TYPE
1985 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type)) == INTEGER_TYPE
1986 && (TREE_UNSIGNED (wanted_type)
1987 ? wanted_type == (cur_type = unsigned_type (cur_type))
1988 : wanted_type == (cur_type = signed_type (cur_type))))
1989 /* Likewise, "signed char", "unsigned char" and "char" are
1990 equivalent but the above test won't consider them equivalent. */
1991 && ! (wanted_type == char_type_node
1992 && (TYPE_MAIN_VARIANT (cur_type) == signed_char_type_node
1993 || TYPE_MAIN_VARIANT (cur_type) == unsigned_char_type_node)))
1995 register const char *this;
1996 register const char *that;
1998 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
2000 if (TREE_CODE (cur_type) != ERROR_MARK
2001 && TYPE_NAME (cur_type) != 0
2002 && TREE_CODE (cur_type) != INTEGER_TYPE
2003 && !(TREE_CODE (cur_type) == POINTER_TYPE
2004 && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE))
2006 if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL
2007 && DECL_NAME (TYPE_NAME (cur_type)) != 0)
2008 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
2010 that = IDENTIFIER_POINTER (TYPE_NAME (cur_type));
2013 /* A nameless type can't possibly match what the format wants.
2014 So there will be a warning for it.
2015 Make up a string to describe vaguely what it is. */
2018 if (TREE_CODE (cur_type) == POINTER_TYPE)
2021 that = "different type";
2024 /* Make the warning better in case of mismatch of int vs long. */
2025 if (TREE_CODE (cur_type) == INTEGER_TYPE
2026 && TREE_CODE (wanted_type) == INTEGER_TYPE
2027 && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type)
2028 && TYPE_NAME (cur_type) != 0
2029 && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL)
2030 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
2032 if (strcmp (this, that) != 0)
2033 warning ("%s format, %s arg (arg %d)", this, that, arg_num);
2038 /* Print a warning if a constant expression had overflow in folding.
2039 Invoke this function on every expression that the language
2040 requires to be a constant expression.
2041 Note the ANSI C standard says it is erroneous for a
2042 constant expression to overflow. */
2045 constant_expression_warning (value)
2048 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
2049 || TREE_CODE (value) == COMPLEX_CST)
2050 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
2051 pedwarn ("overflow in constant expression");
2054 /* Print a warning if an expression had overflow in folding.
2055 Invoke this function on every expression that
2056 (1) appears in the source code, and
2057 (2) might be a constant expression that overflowed, and
2058 (3) is not already checked by convert_and_check;
2059 however, do not invoke this function on operands of explicit casts. */
2062 overflow_warning (value)
2065 if ((TREE_CODE (value) == INTEGER_CST
2066 || (TREE_CODE (value) == COMPLEX_CST
2067 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
2068 && TREE_OVERFLOW (value))
2070 TREE_OVERFLOW (value) = 0;
2071 if (skip_evaluation == 0)
2072 warning ("integer overflow in expression");
2074 else if ((TREE_CODE (value) == REAL_CST
2075 || (TREE_CODE (value) == COMPLEX_CST
2076 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
2077 && TREE_OVERFLOW (value))
2079 TREE_OVERFLOW (value) = 0;
2080 if (skip_evaluation == 0)
2081 warning ("floating point overflow in expression");
2085 /* Print a warning if a large constant is truncated to unsigned,
2086 or if -Wconversion is used and a constant < 0 is converted to unsigned.
2087 Invoke this function on every expression that might be implicitly
2088 converted to an unsigned type. */
2091 unsigned_conversion_warning (result, operand)
2092 tree result, operand;
2094 if (TREE_CODE (operand) == INTEGER_CST
2095 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
2096 && TREE_UNSIGNED (TREE_TYPE (result))
2097 && skip_evaluation == 0
2098 && !int_fits_type_p (operand, TREE_TYPE (result)))
2100 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
2101 /* This detects cases like converting -129 or 256 to unsigned char. */
2102 warning ("large integer implicitly truncated to unsigned type");
2103 else if (warn_conversion)
2104 warning ("negative integer implicitly converted to unsigned type");
2108 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2109 Invoke this function on every expression that is converted implicitly,
2110 i.e. because of language rules and not because of an explicit cast. */
2113 convert_and_check (type, expr)
2116 tree t = convert (type, expr);
2117 if (TREE_CODE (t) == INTEGER_CST)
2119 if (TREE_OVERFLOW (t))
2121 TREE_OVERFLOW (t) = 0;
2123 /* Do not diagnose overflow in a constant expression merely
2124 because a conversion overflowed. */
2125 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
2127 /* No warning for converting 0x80000000 to int. */
2128 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
2129 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
2130 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
2131 /* If EXPR fits in the unsigned version of TYPE,
2132 don't warn unless pedantic. */
2134 || TREE_UNSIGNED (type)
2135 || ! int_fits_type_p (expr, unsigned_type (type)))
2136 && skip_evaluation == 0)
2137 warning ("overflow in implicit constant conversion");
2140 unsigned_conversion_warning (t, expr);
2146 c_expand_expr_stmt (expr)
2149 /* Do default conversion if safe and possibly important,
2150 in case within ({...}). */
2151 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
2152 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
2153 expr = default_conversion (expr);
2155 if (TREE_TYPE (expr) != error_mark_node
2156 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
2157 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
2158 error ("expression statement has incomplete type");
2160 expand_expr_stmt (expr);
2163 /* Validate the expression after `case' and apply default promotions. */
2166 check_case_value (value)
2169 if (value == NULL_TREE)
2172 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2173 STRIP_TYPE_NOPS (value);
2175 if (TREE_CODE (value) != INTEGER_CST
2176 && value != error_mark_node)
2178 error ("case label does not reduce to an integer constant");
2179 value = error_mark_node;
2182 /* Promote char or short to int. */
2183 value = default_conversion (value);
2185 constant_expression_warning (value);
2190 /* Return an integer type with BITS bits of precision,
2191 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2194 type_for_size (bits, unsignedp)
2198 if (bits == TYPE_PRECISION (integer_type_node))
2199 return unsignedp ? unsigned_type_node : integer_type_node;
2201 if (bits == TYPE_PRECISION (signed_char_type_node))
2202 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2204 if (bits == TYPE_PRECISION (short_integer_type_node))
2205 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2207 if (bits == TYPE_PRECISION (long_integer_type_node))
2208 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2210 if (bits == TYPE_PRECISION (long_long_integer_type_node))
2211 return (unsignedp ? long_long_unsigned_type_node
2212 : long_long_integer_type_node);
2214 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
2215 return (unsignedp ? widest_unsigned_literal_type_node
2216 : widest_integer_literal_type_node);
2218 if (bits <= TYPE_PRECISION (intQI_type_node))
2219 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2221 if (bits <= TYPE_PRECISION (intHI_type_node))
2222 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2224 if (bits <= TYPE_PRECISION (intSI_type_node))
2225 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2227 if (bits <= TYPE_PRECISION (intDI_type_node))
2228 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2233 /* Return a data type that has machine mode MODE.
2234 If the mode is an integer,
2235 then UNSIGNEDP selects between signed and unsigned types. */
2238 type_for_mode (mode, unsignedp)
2239 enum machine_mode mode;
2242 if (mode == TYPE_MODE (integer_type_node))
2243 return unsignedp ? unsigned_type_node : integer_type_node;
2245 if (mode == TYPE_MODE (signed_char_type_node))
2246 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2248 if (mode == TYPE_MODE (short_integer_type_node))
2249 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2251 if (mode == TYPE_MODE (long_integer_type_node))
2252 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2254 if (mode == TYPE_MODE (long_long_integer_type_node))
2255 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2257 if (mode == TYPE_MODE (widest_integer_literal_type_node))
2258 return unsignedp ? widest_unsigned_literal_type_node
2259 : widest_integer_literal_type_node;
2261 if (mode == TYPE_MODE (intQI_type_node))
2262 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2264 if (mode == TYPE_MODE (intHI_type_node))
2265 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2267 if (mode == TYPE_MODE (intSI_type_node))
2268 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2270 if (mode == TYPE_MODE (intDI_type_node))
2271 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2273 #if HOST_BITS_PER_WIDE_INT >= 64
2274 if (mode == TYPE_MODE (intTI_type_node))
2275 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2278 if (mode == TYPE_MODE (float_type_node))
2279 return float_type_node;
2281 if (mode == TYPE_MODE (double_type_node))
2282 return double_type_node;
2284 if (mode == TYPE_MODE (long_double_type_node))
2285 return long_double_type_node;
2287 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
2288 return build_pointer_type (char_type_node);
2290 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2291 return build_pointer_type (integer_type_node);
2296 /* Return an unsigned type the same as TYPE in other respects. */
2298 unsigned_type (type)
2301 tree type1 = TYPE_MAIN_VARIANT (type);
2302 if (type1 == signed_char_type_node || type1 == char_type_node)
2303 return unsigned_char_type_node;
2304 if (type1 == integer_type_node)
2305 return unsigned_type_node;
2306 if (type1 == short_integer_type_node)
2307 return short_unsigned_type_node;
2308 if (type1 == long_integer_type_node)
2309 return long_unsigned_type_node;
2310 if (type1 == long_long_integer_type_node)
2311 return long_long_unsigned_type_node;
2312 if (type1 == widest_integer_literal_type_node)
2313 return widest_unsigned_literal_type_node;
2314 #if HOST_BITS_PER_WIDE_INT >= 64
2315 if (type1 == intTI_type_node)
2316 return unsigned_intTI_type_node;
2318 if (type1 == intDI_type_node)
2319 return unsigned_intDI_type_node;
2320 if (type1 == intSI_type_node)
2321 return unsigned_intSI_type_node;
2322 if (type1 == intHI_type_node)
2323 return unsigned_intHI_type_node;
2324 if (type1 == intQI_type_node)
2325 return unsigned_intQI_type_node;
2327 return signed_or_unsigned_type (1, type);
2330 /* Return a signed type the same as TYPE in other respects. */
2336 tree type1 = TYPE_MAIN_VARIANT (type);
2337 if (type1 == unsigned_char_type_node || type1 == char_type_node)
2338 return signed_char_type_node;
2339 if (type1 == unsigned_type_node)
2340 return integer_type_node;
2341 if (type1 == short_unsigned_type_node)
2342 return short_integer_type_node;
2343 if (type1 == long_unsigned_type_node)
2344 return long_integer_type_node;
2345 if (type1 == long_long_unsigned_type_node)
2346 return long_long_integer_type_node;
2347 if (type1 == widest_unsigned_literal_type_node)
2348 return widest_integer_literal_type_node;
2349 #if HOST_BITS_PER_WIDE_INT >= 64
2350 if (type1 == unsigned_intTI_type_node)
2351 return intTI_type_node;
2353 if (type1 == unsigned_intDI_type_node)
2354 return intDI_type_node;
2355 if (type1 == unsigned_intSI_type_node)
2356 return intSI_type_node;
2357 if (type1 == unsigned_intHI_type_node)
2358 return intHI_type_node;
2359 if (type1 == unsigned_intQI_type_node)
2360 return intQI_type_node;
2362 return signed_or_unsigned_type (0, type);
2365 /* Return a type the same as TYPE except unsigned or
2366 signed according to UNSIGNEDP. */
2369 signed_or_unsigned_type (unsignedp, type)
2373 if (! INTEGRAL_TYPE_P (type)
2374 || TREE_UNSIGNED (type) == unsignedp)
2377 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
2378 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2379 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2380 return unsignedp ? unsigned_type_node : integer_type_node;
2381 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
2382 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2383 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
2384 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2385 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
2386 return (unsignedp ? long_long_unsigned_type_node
2387 : long_long_integer_type_node);
2388 if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
2389 return (unsignedp ? widest_unsigned_literal_type_node
2390 : widest_integer_literal_type_node);
2394 /* Return the minimum number of bits needed to represent VALUE in a
2395 signed or unsigned type, UNSIGNEDP says which. */
2398 min_precision (value, unsignedp)
2404 /* If the value is negative, compute its negative minus 1. The latter
2405 adjustment is because the absolute value of the largest negative value
2406 is one larger than the largest positive value. This is equivalent to
2407 a bit-wise negation, so use that operation instead. */
2409 if (tree_int_cst_sgn (value) < 0)
2410 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
2412 /* Return the number of bits needed, taking into account the fact
2413 that we need one more bit for a signed than unsigned type. */
2415 if (integer_zerop (value))
2418 log = tree_floor_log2 (value);
2420 return log + 1 + ! unsignedp;
2423 /* Print an error message for invalid operands to arith operation CODE.
2424 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2427 binary_op_error (code)
2428 enum tree_code code;
2430 register const char *opname;
2435 error ("invalid truth-value expression");
2439 opname = "+"; break;
2441 opname = "-"; break;
2443 opname = "*"; break;
2445 opname = "max"; break;
2447 opname = "min"; break;
2449 opname = "=="; break;
2451 opname = "!="; break;
2453 opname = "<="; break;
2455 opname = ">="; break;
2457 opname = "<"; break;
2459 opname = ">"; break;
2461 opname = "<<"; break;
2463 opname = ">>"; break;
2464 case TRUNC_MOD_EXPR:
2465 case FLOOR_MOD_EXPR:
2466 opname = "%"; break;
2467 case TRUNC_DIV_EXPR:
2468 case FLOOR_DIV_EXPR:
2469 opname = "/"; break;
2471 opname = "&"; break;
2473 opname = "|"; break;
2474 case TRUTH_ANDIF_EXPR:
2475 opname = "&&"; break;
2476 case TRUTH_ORIF_EXPR:
2477 opname = "||"; break;
2479 opname = "^"; break;
2482 opname = "rotate"; break;
2484 opname = "unknown"; break;
2486 error ("invalid operands to binary %s", opname);
2489 /* Subroutine of build_binary_op, used for comparison operations.
2490 See if the operands have both been converted from subword integer types
2491 and, if so, perhaps change them both back to their original type.
2492 This function is also responsible for converting the two operands
2493 to the proper common type for comparison.
2495 The arguments of this function are all pointers to local variables
2496 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2497 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2499 If this function returns nonzero, it means that the comparison has
2500 a constant value. What this function returns is an expression for
2504 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
2505 tree *op0_ptr, *op1_ptr;
2507 enum tree_code *rescode_ptr;
2510 tree op0 = *op0_ptr;
2511 tree op1 = *op1_ptr;
2512 int unsignedp0, unsignedp1;
2514 tree primop0, primop1;
2515 enum tree_code code = *rescode_ptr;
2517 /* Throw away any conversions to wider types
2518 already present in the operands. */
2520 primop0 = get_narrower (op0, &unsignedp0);
2521 primop1 = get_narrower (op1, &unsignedp1);
2523 /* Handle the case that OP0 does not *contain* a conversion
2524 but it *requires* conversion to FINAL_TYPE. */
2526 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
2527 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
2528 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
2529 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
2531 /* If one of the operands must be floated, we cannot optimize. */
2532 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
2533 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
2535 /* If first arg is constant, swap the args (changing operation
2536 so value is preserved), for canonicalization. Don't do this if
2537 the second arg is 0. */
2539 if (TREE_CONSTANT (primop0)
2540 && ! integer_zerop (primop1) && ! real_zerop (primop1))
2542 register tree tem = primop0;
2543 register int temi = unsignedp0;
2551 unsignedp0 = unsignedp1;
2574 *rescode_ptr = code;
2577 /* If comparing an integer against a constant more bits wide,
2578 maybe we can deduce a value of 1 or 0 independent of the data.
2579 Or else truncate the constant now
2580 rather than extend the variable at run time.
2582 This is only interesting if the constant is the wider arg.
2583 Also, it is not safe if the constant is unsigned and the
2584 variable arg is signed, since in this case the variable
2585 would be sign-extended and then regarded as unsigned.
2586 Our technique fails in this case because the lowest/highest
2587 possible unsigned results don't follow naturally from the
2588 lowest/highest possible values of the variable operand.
2589 For just EQ_EXPR and NE_EXPR there is another technique that
2590 could be used: see if the constant can be faithfully represented
2591 in the other operand's type, by truncating it and reextending it
2592 and see if that preserves the constant's value. */
2594 if (!real1 && !real2
2595 && TREE_CODE (primop1) == INTEGER_CST
2596 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
2598 int min_gt, max_gt, min_lt, max_lt;
2599 tree maxval, minval;
2600 /* 1 if comparison is nominally unsigned. */
2601 int unsignedp = TREE_UNSIGNED (*restype_ptr);
2604 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
2606 /* If TYPE is an enumeration, then we need to get its min/max
2607 values from it's underlying integral type, not the enumerated
2609 if (TREE_CODE (type) == ENUMERAL_TYPE)
2610 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
2612 maxval = TYPE_MAX_VALUE (type);
2613 minval = TYPE_MIN_VALUE (type);
2615 if (unsignedp && !unsignedp0)
2616 *restype_ptr = signed_type (*restype_ptr);
2618 if (TREE_TYPE (primop1) != *restype_ptr)
2619 primop1 = convert (*restype_ptr, primop1);
2620 if (type != *restype_ptr)
2622 minval = convert (*restype_ptr, minval);
2623 maxval = convert (*restype_ptr, maxval);
2626 if (unsignedp && unsignedp0)
2628 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
2629 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
2630 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
2631 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
2635 min_gt = INT_CST_LT (primop1, minval);
2636 max_gt = INT_CST_LT (primop1, maxval);
2637 min_lt = INT_CST_LT (minval, primop1);
2638 max_lt = INT_CST_LT (maxval, primop1);
2642 /* This used to be a switch, but Genix compiler can't handle that. */
2643 if (code == NE_EXPR)
2645 if (max_lt || min_gt)
2646 val = boolean_true_node;
2648 else if (code == EQ_EXPR)
2650 if (max_lt || min_gt)
2651 val = boolean_false_node;
2653 else if (code == LT_EXPR)
2656 val = boolean_true_node;
2658 val = boolean_false_node;
2660 else if (code == GT_EXPR)
2663 val = boolean_true_node;
2665 val = boolean_false_node;
2667 else if (code == LE_EXPR)
2670 val = boolean_true_node;
2672 val = boolean_false_node;
2674 else if (code == GE_EXPR)
2677 val = boolean_true_node;
2679 val = boolean_false_node;
2682 /* If primop0 was sign-extended and unsigned comparison specd,
2683 we did a signed comparison above using the signed type bounds.
2684 But the comparison we output must be unsigned.
2686 Also, for inequalities, VAL is no good; but if the signed
2687 comparison had *any* fixed result, it follows that the
2688 unsigned comparison just tests the sign in reverse
2689 (positive values are LE, negative ones GE).
2690 So we can generate an unsigned comparison
2691 against an extreme value of the signed type. */
2693 if (unsignedp && !unsignedp0)
2700 primop1 = TYPE_MIN_VALUE (type);
2706 primop1 = TYPE_MAX_VALUE (type);
2713 type = unsigned_type (type);
2716 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2718 /* This is the case of (char)x >?< 0x80, which people used to use
2719 expecting old C compilers to change the 0x80 into -0x80. */
2720 if (val == boolean_false_node)
2721 warning ("comparison is always false due to limited range of data type");
2722 if (val == boolean_true_node)
2723 warning ("comparison is always true due to limited range of data type");
2726 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2728 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2729 if (val == boolean_false_node)
2730 warning ("comparison is always false due to limited range of data type");
2731 if (val == boolean_true_node)
2732 warning ("comparison is always true due to limited range of data type");
2737 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2738 if (TREE_SIDE_EFFECTS (primop0))
2739 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
2743 /* Value is not predetermined, but do the comparison
2744 in the type of the operand that is not constant.
2745 TYPE is already properly set. */
2747 else if (real1 && real2
2748 && (TYPE_PRECISION (TREE_TYPE (primop0))
2749 == TYPE_PRECISION (TREE_TYPE (primop1))))
2750 type = TREE_TYPE (primop0);
2752 /* If args' natural types are both narrower than nominal type
2753 and both extend in the same manner, compare them
2754 in the type of the wider arg.
2755 Otherwise must actually extend both to the nominal
2756 common type lest different ways of extending
2758 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2760 else if (unsignedp0 == unsignedp1 && real1 == real2
2761 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
2762 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
2764 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
2765 type = signed_or_unsigned_type (unsignedp0
2766 || TREE_UNSIGNED (*restype_ptr),
2768 /* Make sure shorter operand is extended the right way
2769 to match the longer operand. */
2770 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
2772 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
2777 /* Here we must do the comparison on the nominal type
2778 using the args exactly as we received them. */
2779 type = *restype_ptr;
2783 if (!real1 && !real2 && integer_zerop (primop1)
2784 && TREE_UNSIGNED (*restype_ptr))
2790 /* All unsigned values are >= 0, so we warn if extra warnings
2791 are requested. However, if OP0 is a constant that is
2792 >= 0, the signedness of the comparison isn't an issue,
2793 so suppress the warning. */
2795 && ! (TREE_CODE (primop0) == INTEGER_CST
2796 && ! TREE_OVERFLOW (convert (signed_type (type),
2798 warning ("comparison of unsigned expression >= 0 is always true");
2799 value = boolean_true_node;
2804 && ! (TREE_CODE (primop0) == INTEGER_CST
2805 && ! TREE_OVERFLOW (convert (signed_type (type),
2807 warning ("comparison of unsigned expression < 0 is always false");
2808 value = boolean_false_node;
2817 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2818 if (TREE_SIDE_EFFECTS (primop0))
2819 return build (COMPOUND_EXPR, TREE_TYPE (value),
2826 *op0_ptr = convert (type, primop0);
2827 *op1_ptr = convert (type, primop1);
2829 *restype_ptr = boolean_type_node;
2834 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2835 or validate its data type for an `if' or `while' statement or ?..: exp.
2837 This preparation consists of taking the ordinary
2838 representation of an expression expr and producing a valid tree
2839 boolean expression describing whether expr is nonzero. We could
2840 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2841 but we optimize comparisons, &&, ||, and !.
2843 The resulting type should always be `boolean_type_node'. */
2846 truthvalue_conversion (expr)
2849 if (TREE_CODE (expr) == ERROR_MARK)
2852 #if 0 /* This appears to be wrong for C++. */
2853 /* These really should return error_mark_node after 2.4 is stable.
2854 But not all callers handle ERROR_MARK properly. */
2855 switch (TREE_CODE (TREE_TYPE (expr)))
2858 error ("struct type value used where scalar is required");
2859 return boolean_false_node;
2862 error ("union type value used where scalar is required");
2863 return boolean_false_node;
2866 error ("array type value used where scalar is required");
2867 return boolean_false_node;
2874 switch (TREE_CODE (expr))
2877 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
2878 case TRUTH_ANDIF_EXPR:
2879 case TRUTH_ORIF_EXPR:
2880 case TRUTH_AND_EXPR:
2882 case TRUTH_XOR_EXPR:
2883 case TRUTH_NOT_EXPR:
2884 TREE_TYPE (expr) = boolean_type_node;
2891 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
2894 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
2897 /* If we are taking the address of a external decl, it might be zero
2898 if it is weak, so we cannot optimize. */
2899 if (DECL_P (TREE_OPERAND (expr, 0))
2900 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
2903 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
2904 return build (COMPOUND_EXPR, boolean_type_node,
2905 TREE_OPERAND (expr, 0), boolean_true_node);
2907 return boolean_true_node;
2910 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2911 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2912 truthvalue_conversion (TREE_OPERAND (expr, 0)),
2913 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2920 /* These don't change whether an object is non-zero or zero. */
2921 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2925 /* These don't change whether an object is zero or non-zero, but
2926 we can't ignore them if their second arg has side-effects. */
2927 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2928 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2929 truthvalue_conversion (TREE_OPERAND (expr, 0)));
2931 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2934 /* Distribute the conversion into the arms of a COND_EXPR. */
2935 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2936 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2937 truthvalue_conversion (TREE_OPERAND (expr, 2))));
2940 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2941 since that affects how `default_conversion' will behave. */
2942 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2943 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2945 /* fall through... */
2947 /* If this is widening the argument, we can ignore it. */
2948 if (TYPE_PRECISION (TREE_TYPE (expr))
2949 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2950 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2954 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2956 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2957 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2959 /* fall through... */
2961 /* This and MINUS_EXPR can be changed into a comparison of the
2963 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2964 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2965 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2966 TREE_OPERAND (expr, 1), 1);
2967 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2968 fold (build1 (NOP_EXPR,
2969 TREE_TYPE (TREE_OPERAND (expr, 0)),
2970 TREE_OPERAND (expr, 1))), 1);
2973 if (integer_onep (TREE_OPERAND (expr, 1))
2974 && TREE_TYPE (expr) != boolean_type_node)
2975 /* Using convert here would cause infinite recursion. */
2976 return build1 (NOP_EXPR, boolean_type_node, expr);
2980 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
2981 warning ("suggest parentheses around assignment used as truth value");
2988 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2990 tree tem = save_expr (expr);
2991 return (build_binary_op
2992 ((TREE_SIDE_EFFECTS (expr)
2993 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2994 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
2995 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
2999 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
3003 /* Read the rest of a #-directive from input stream FINPUT.
3004 In normal use, the directive name and the white space after it
3005 have already been read, so they won't be included in the result.
3006 We allow for the fact that the directive line may contain
3007 a newline embedded within a character or string literal which forms
3008 a part of the directive.
3010 The value is a string in a reusable buffer. It remains valid
3011 only until the next time this function is called. */
3012 unsigned char *yy_cur, *yy_lim;
3014 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
3015 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
3022 parse_in.limit = parse_in.token_buffer;
3023 cpp_token = cpp_get_token (&parse_in);
3024 if (cpp_token == CPP_EOF)
3026 yy_lim = CPP_PWRITTEN (&parse_in);
3027 yy_cur = parse_in.token_buffer;
3028 if (yy_cur < yy_lim)
3034 get_directive_line ()
3036 static char *directive_buffer = NULL;
3037 static unsigned buffer_length = 0;
3039 register char *buffer_limit;
3040 register int looking_for = 0;
3041 register int char_escaped = 0;
3043 if (buffer_length == 0)
3045 directive_buffer = (char *)xmalloc (128);
3046 buffer_length = 128;
3049 buffer_limit = &directive_buffer[buffer_length];
3051 for (p = directive_buffer; ; )
3055 /* Make buffer bigger if it is full. */
3056 if (p >= buffer_limit)
3058 register unsigned bytes_used = (p - directive_buffer);
3062 = (char *)xrealloc (directive_buffer, buffer_length);
3063 p = &directive_buffer[bytes_used];
3064 buffer_limit = &directive_buffer[buffer_length];
3069 /* Discard initial whitespace. */
3070 if ((c == ' ' || c == '\t') && p == directive_buffer)
3073 /* Detect the end of the directive. */
3074 if (c == '\n' && looking_for == 0)
3083 return directive_buffer;
3085 /* Handle string and character constant syntax. */
3088 if (looking_for == c && !char_escaped)
3089 looking_for = 0; /* Found terminator... stop looking. */
3092 if (c == '\'' || c == '"')
3093 looking_for = c; /* Don't stop buffering until we see another
3094 another one of these (or an EOF). */
3096 /* Handle backslash. */
3097 char_escaped = (c == '\\' && ! char_escaped);
3101 /* Read the rest of a #-directive from input stream FINPUT.
3102 In normal use, the directive name and the white space after it
3103 have already been read, so they won't be included in the result.
3104 We allow for the fact that the directive line may contain
3105 a newline embedded within a character or string literal which forms
3106 a part of the directive.
3108 The value is a string in a reusable buffer. It remains valid
3109 only until the next time this function is called.
3111 The terminating character ('\n' or EOF) is left in FINPUT for the
3112 caller to re-read. */
3115 get_directive_line (finput)
3116 register FILE *finput;
3118 static char *directive_buffer = NULL;
3119 static unsigned buffer_length = 0;
3121 register char *buffer_limit;
3122 register int looking_for = 0;
3123 register int char_escaped = 0;
3125 if (buffer_length == 0)
3127 directive_buffer = (char *)xmalloc (128);
3128 buffer_length = 128;
3131 buffer_limit = &directive_buffer[buffer_length];
3133 for (p = directive_buffer; ; )
3137 /* Make buffer bigger if it is full. */
3138 if (p >= buffer_limit)
3140 register unsigned bytes_used = (p - directive_buffer);
3144 = (char *)xrealloc (directive_buffer, buffer_length);
3145 p = &directive_buffer[bytes_used];
3146 buffer_limit = &directive_buffer[buffer_length];
3151 /* Discard initial whitespace. */
3152 if ((c == ' ' || c == '\t') && p == directive_buffer)
3155 /* Detect the end of the directive. */
3156 if (looking_for == 0
3157 && (c == '\n' || c == EOF))
3166 return directive_buffer;
3168 /* Handle string and character constant syntax. */
3171 if (looking_for == c && !char_escaped)
3172 looking_for = 0; /* Found terminator... stop looking. */
3175 if (c == '\'' || c == '"')
3176 looking_for = c; /* Don't stop buffering until we see another
3177 one of these (or an EOF). */
3179 /* Handle backslash. */
3180 char_escaped = (c == '\\' && ! char_escaped);
3183 #endif /* !USE_CPPLIB */
3185 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3186 down to the element type of an array. */
3189 c_build_qualified_type (type, type_quals)
3193 /* A restrict-qualified pointer type must be a pointer to object or
3194 incomplete type. Note that the use of POINTER_TYPE_P also allows
3195 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
3196 the C++ front-end also use POINTER_TYPE for pointer-to-member
3197 values, so even though it should be illegal to use `restrict'
3198 with such an entity we don't flag that here. Thus, special case
3199 code for that case is required in the C++ front-end. */
3200 if ((type_quals & TYPE_QUAL_RESTRICT)
3201 && (!POINTER_TYPE_P (type)
3202 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
3204 error ("invalid use of `restrict'");
3205 type_quals &= ~TYPE_QUAL_RESTRICT;
3208 if (TREE_CODE (type) == ARRAY_TYPE)
3209 return build_array_type (c_build_qualified_type (TREE_TYPE (type),
3211 TYPE_DOMAIN (type));
3212 return build_qualified_type (type, type_quals);
3215 /* Apply the TYPE_QUALS to the new DECL. */
3218 c_apply_type_quals_to_decl (type_quals, decl)
3222 if ((type_quals & TYPE_QUAL_CONST)
3223 || (TREE_TYPE (decl)
3224 && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE))
3225 TREE_READONLY (decl) = 1;
3226 if (type_quals & TYPE_QUAL_VOLATILE)
3228 TREE_SIDE_EFFECTS (decl) = 1;
3229 TREE_THIS_VOLATILE (decl) = 1;
3231 if (type_quals & TYPE_QUAL_RESTRICT)
3233 if (!TREE_TYPE (decl)
3234 || !POINTER_TYPE_P (TREE_TYPE (decl))
3235 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
3236 error ("invalid use of `restrict'");
3237 else if (flag_strict_aliasing)
3239 /* No two restricted pointers can point at the same thing.
3240 However, a restricted pointer can point at the same thing
3241 as an unrestricted pointer, if that unrestricted pointer
3242 is based on the restricted pointer. So, we make the
3243 alias set for the restricted pointer a subset of the
3244 alias set for the type pointed to by the type of the
3247 HOST_WIDE_INT pointed_to_alias_set
3248 = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
3250 if (pointed_to_alias_set == 0)
3251 /* It's not legal to make a subset of alias set zero. */
3255 DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
3256 record_alias_subset (pointed_to_alias_set,
3257 DECL_POINTER_ALIAS_SET (decl));
3264 /* Return the typed-based alias set for T, which may be an expression
3265 or a type. Return -1 if we don't do anything special. */
3273 /* Permit type-punning when accessing a union, provided the access
3274 is directly through the union. For example, this code does not
3275 permit taking the address of a union member and then storing
3276 through it. Even the type-punning allowed here is a GCC
3277 extension, albeit a common and useful one; the C standard says
3278 that such accesses have implementation-defined behavior. */
3280 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
3281 u = TREE_OPERAND (u, 0))
3282 if (TREE_CODE (u) == COMPONENT_REF
3283 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
3286 /* If this is a char *, the ANSI C standard says it can alias
3287 anything. Note that all references need do this. */
3288 if (TREE_CODE_CLASS (TREE_CODE (t)) == 'r'
3289 && TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
3290 && TYPE_PRECISION (TREE_TYPE (t)) == TYPE_PRECISION (char_type_node))
3293 /* That's all the expressions we handle specially. */
3297 /* The C standard specifically allows aliasing between signed and
3298 unsigned variants of the same type. We treat the signed
3299 variant as canonical. */
3300 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
3302 tree t1 = signed_type (t);
3304 /* t1 == t can happen for boolean nodes which are always unsigned. */
3306 return get_alias_set (t1);
3308 else if (POINTER_TYPE_P (t))
3312 /* Unfortunately, there is no canonical form of a pointer type.
3313 In particular, if we have `typedef int I', then `int *', and
3314 `I *' are different types. So, we have to pick a canonical
3315 representative. We do this below.
3317 Technically, this approach is actually more conservative that
3318 it needs to be. In particular, `const int *' and `int *'
3319 chould be in different alias sets, according to the C and C++
3320 standard, since their types are not the same, and so,
3321 technically, an `int **' and `const int **' cannot point at
3324 But, the standard is wrong. In particular, this code is
3329 const int* const* cipp = &ip;
3331 And, it doesn't make sense for that to be legal unless you
3332 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
3333 the pointed-to types. This issue has been reported to the
3335 t1 = TYPE_MAIN_VARIANT (TREE_TYPE (t));
3336 t1 = ((TREE_CODE (t) == POINTER_TYPE)
3337 ? build_pointer_type (t1) : build_reference_type (t1));
3339 return get_alias_set (t1);
3345 /* Build tree nodes and builtin functions common to both C and C++ language
3347 CPLUS_MODE is nonzero if we are called from the C++ frontend, we generate
3348 some stricter prototypes in that case.
3349 NO_BUILTINS and NO_NONANSI_BUILTINS contain the respective values of
3350 the language frontend flags flag_no_builtin and
3351 flag_no_nonansi_builtin. */
3354 c_common_nodes_and_builtins (cplus_mode, no_builtins, no_nonansi_builtins)
3355 int cplus_mode, no_builtins, no_nonansi_builtins;
3358 tree memcpy_ftype, memset_ftype, strlen_ftype;
3359 tree bzero_ftype, bcmp_ftype;
3360 tree endlink, int_endlink, double_endlink, unsigned_endlink;
3361 tree sizetype_endlink;
3362 tree ptr_ftype, ptr_ftype_unsigned;
3363 tree void_ftype_any, void_ftype_int, int_ftype_any;
3364 tree double_ftype_double, double_ftype_double_double;
3365 tree float_ftype_float, ldouble_ftype_ldouble;
3366 tree int_ftype_cptr_cptr_sizet;
3367 tree int_ftype_string_string, string_ftype_ptr_ptr;
3368 tree long_ftype_long;
3369 /* Either char* or void*. */
3370 tree traditional_ptr_type_node;
3371 /* Either const char* or const void*. */
3372 tree traditional_cptr_type_node;
3373 tree traditional_len_type_node;
3374 tree traditional_len_endlink;
3375 tree va_list_ref_type_node;
3376 tree va_list_arg_type_node;
3378 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
3379 va_list_type_node));
3381 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
3382 ptrdiff_type_node));
3384 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
3387 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
3389 va_list_arg_type_node = va_list_ref_type_node =
3390 build_pointer_type (TREE_TYPE (va_list_type_node));
3394 va_list_arg_type_node = va_list_type_node;
3395 va_list_ref_type_node = build_reference_type (va_list_type_node);
3398 endlink = void_list_node;
3399 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
3400 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
3401 unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink);
3403 ptr_ftype = build_function_type (ptr_type_node, NULL_TREE);
3404 ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink);
3405 sizetype_endlink = tree_cons (NULL_TREE, TYPE_DOMAIN (sizetype), endlink);
3406 /* We realloc here because sizetype could be int or unsigned. S'ok. */
3407 ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink);
3409 int_ftype_any = build_function_type (integer_type_node, NULL_TREE);
3410 void_ftype_any = build_function_type (void_type_node, NULL_TREE);
3411 void_ftype = build_function_type (void_type_node, endlink);
3412 void_ftype_int = build_function_type (void_type_node, int_endlink);
3414 = build_function_type (void_type_node,
3415 tree_cons (NULL_TREE, ptr_type_node, endlink));
3418 = build_function_type (float_type_node,
3419 tree_cons (NULL_TREE, float_type_node, endlink));
3422 = build_function_type (double_type_node, double_endlink);
3424 ldouble_ftype_ldouble
3425 = build_function_type (long_double_type_node,
3426 tree_cons (NULL_TREE, long_double_type_node,
3429 double_ftype_double_double
3430 = build_function_type (double_type_node,
3431 tree_cons (NULL_TREE, double_type_node,
3435 = build_function_type (integer_type_node, int_endlink);
3438 = build_function_type (long_integer_type_node,
3439 tree_cons (NULL_TREE, long_integer_type_node,
3442 int_ftype_cptr_cptr_sizet
3443 = build_function_type (integer_type_node,
3444 tree_cons (NULL_TREE, const_ptr_type_node,
3445 tree_cons (NULL_TREE, const_ptr_type_node,
3446 tree_cons (NULL_TREE,
3450 /* Prototype for strcpy. */
3451 string_ftype_ptr_ptr
3452 = build_function_type (string_type_node,
3453 tree_cons (NULL_TREE, string_type_node,
3454 tree_cons (NULL_TREE,
3455 const_string_type_node,
3458 traditional_len_type_node = (flag_traditional && ! cplus_mode
3459 ? integer_type_node : sizetype);
3460 traditional_len_endlink = tree_cons (NULL_TREE, traditional_len_type_node,
3463 /* Prototype for strcmp. */
3464 int_ftype_string_string
3465 = build_function_type (integer_type_node,
3466 tree_cons (NULL_TREE, const_string_type_node,
3467 tree_cons (NULL_TREE,
3468 const_string_type_node,
3471 /* Prototype for strlen. */
3473 = build_function_type (traditional_len_type_node,
3474 tree_cons (NULL_TREE, const_string_type_node,
3477 traditional_ptr_type_node = (flag_traditional && ! cplus_mode
3478 ? string_type_node : ptr_type_node);
3479 traditional_cptr_type_node = (flag_traditional && ! cplus_mode
3480 ? const_string_type_node : const_ptr_type_node);
3482 /* Prototype for memcpy. */
3484 = build_function_type (traditional_ptr_type_node,
3485 tree_cons (NULL_TREE, ptr_type_node,
3486 tree_cons (NULL_TREE, const_ptr_type_node,
3487 sizetype_endlink)));
3489 /* Prototype for memset. */
3491 = build_function_type (traditional_ptr_type_node,
3492 tree_cons (NULL_TREE, ptr_type_node,
3493 tree_cons (NULL_TREE, integer_type_node,
3494 tree_cons (NULL_TREE,
3498 /* Prototype for bzero. */
3500 = build_function_type (void_type_node,
3501 tree_cons (NULL_TREE, traditional_ptr_type_node,
3502 traditional_len_endlink));
3504 /* Prototype for bcmp. */
3506 = build_function_type (integer_type_node,
3507 tree_cons (NULL_TREE, traditional_cptr_type_node,
3508 tree_cons (NULL_TREE,
3509 traditional_cptr_type_node,
3510 traditional_len_endlink)));
3512 builtin_function ("__builtin_constant_p", default_function_type,
3513 BUILT_IN_CONSTANT_P, BUILT_IN_NORMAL, NULL_PTR);
3515 builtin_function ("__builtin_return_address", ptr_ftype_unsigned,
3516 BUILT_IN_RETURN_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
3518 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned,
3519 BUILT_IN_FRAME_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
3521 builtin_function ("__builtin_alloca", ptr_ftype_sizetype,
3522 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, "alloca");
3523 builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS,
3524 BUILT_IN_NORMAL, NULL_PTR);
3525 /* Define alloca, ffs as builtins.
3526 Declare _exit just to mark it as volatile. */
3527 if (! no_builtins && ! no_nonansi_builtins)
3530 temp = builtin_function ("alloca", ptr_ftype_sizetype,
3531 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, NULL_PTR);
3532 /* Suppress error if redefined as a non-function. */
3533 DECL_BUILT_IN_NONANSI (temp) = 1;
3535 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS,
3536 BUILT_IN_NORMAL, NULL_PTR);
3537 /* Suppress error if redefined as a non-function. */
3538 DECL_BUILT_IN_NONANSI (temp) = 1;
3539 temp = builtin_function ("_exit", void_ftype_int,
3540 0, NOT_BUILT_IN, NULL_PTR);
3541 TREE_THIS_VOLATILE (temp) = 1;
3542 TREE_SIDE_EFFECTS (temp) = 1;
3543 /* Suppress error if redefined as a non-function. */
3544 DECL_BUILT_IN_NONANSI (temp) = 1;
3546 /* The system prototypes for these functions have many
3547 variations, so don't specify parameters to avoid conflicts.
3548 The expand_* functions check the argument types anyway. */
3549 temp = builtin_function ("bzero", void_ftype_any,
3550 BUILT_IN_BZERO, BUILT_IN_NORMAL, NULL_PTR);
3551 DECL_BUILT_IN_NONANSI (temp) = 1;
3552 temp = builtin_function ("bcmp", int_ftype_any,
3553 BUILT_IN_BCMP, BUILT_IN_NORMAL, NULL_PTR);
3554 DECL_BUILT_IN_NONANSI (temp) = 1;
3557 builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS,
3558 BUILT_IN_NORMAL, NULL_PTR);
3559 builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
3560 BUILT_IN_NORMAL, NULL_PTR);
3561 builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
3562 BUILT_IN_NORMAL, NULL_PTR);
3563 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3564 BUILT_IN_NORMAL, NULL_PTR);
3565 builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS,
3566 BUILT_IN_NORMAL, NULL_PTR);
3567 builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS,
3568 BUILT_IN_NORMAL, NULL_PTR);
3569 builtin_function ("__builtin_classify_type", default_function_type,
3570 BUILT_IN_CLASSIFY_TYPE, BUILT_IN_NORMAL, NULL_PTR);
3571 builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG,
3572 BUILT_IN_NORMAL, NULL_PTR);
3573 builtin_function ("__builtin_args_info", int_ftype_int, BUILT_IN_ARGS_INFO,
3574 BUILT_IN_NORMAL, NULL_PTR);
3575 builtin_function ("__builtin_setjmp",
3576 build_function_type (integer_type_node,
3577 tree_cons (NULL_TREE, ptr_type_node,
3579 BUILT_IN_SETJMP, BUILT_IN_NORMAL, NULL_PTR);
3580 builtin_function ("__builtin_longjmp",
3581 build_function_type (void_type_node,
3582 tree_cons (NULL_TREE, ptr_type_node,
3583 tree_cons (NULL_TREE,
3586 BUILT_IN_LONGJMP, BUILT_IN_NORMAL, NULL_PTR);
3587 builtin_function ("__builtin_trap", void_ftype, BUILT_IN_TRAP,
3588 BUILT_IN_NORMAL, NULL_PTR);
3590 /* ISO C99 IEEE Unordered compares. */
3591 builtin_function ("__builtin_isgreater", default_function_type,
3592 BUILT_IN_ISGREATER, BUILT_IN_NORMAL, NULL_PTR);
3593 builtin_function ("__builtin_isgreaterequal", default_function_type,
3594 BUILT_IN_ISGREATEREQUAL, BUILT_IN_NORMAL, NULL_PTR);
3595 builtin_function ("__builtin_isless", default_function_type,
3596 BUILT_IN_ISLESS, BUILT_IN_NORMAL, NULL_PTR);
3597 builtin_function ("__builtin_islessequal", default_function_type,
3598 BUILT_IN_ISLESSEQUAL, BUILT_IN_NORMAL, NULL_PTR);
3599 builtin_function ("__builtin_islessgreater", default_function_type,
3600 BUILT_IN_ISLESSGREATER, BUILT_IN_NORMAL, NULL_PTR);
3601 builtin_function ("__builtin_isunordered", default_function_type,
3602 BUILT_IN_ISUNORDERED, BUILT_IN_NORMAL, NULL_PTR);
3604 /* Untyped call and return. */
3605 builtin_function ("__builtin_apply_args", ptr_ftype,
3606 BUILT_IN_APPLY_ARGS, BUILT_IN_NORMAL, NULL_PTR);
3608 temp = tree_cons (NULL_TREE,
3609 build_pointer_type (build_function_type (void_type_node,
3611 tree_cons (NULL_TREE,
3613 tree_cons (NULL_TREE,
3616 builtin_function ("__builtin_apply",
3617 build_function_type (ptr_type_node, temp),
3618 BUILT_IN_APPLY, BUILT_IN_NORMAL, NULL_PTR);
3619 builtin_function ("__builtin_return", void_ftype_ptr,
3620 BUILT_IN_RETURN, BUILT_IN_NORMAL, NULL_PTR);
3622 /* Support for varargs.h and stdarg.h. */
3623 builtin_function ("__builtin_varargs_start",
3624 build_function_type (void_type_node,
3625 tree_cons (NULL_TREE,
3626 va_list_ref_type_node,
3628 BUILT_IN_VARARGS_START, BUILT_IN_NORMAL, NULL_PTR);
3630 builtin_function ("__builtin_stdarg_start",
3631 build_function_type (void_type_node,
3632 tree_cons (NULL_TREE,
3633 va_list_ref_type_node,
3635 BUILT_IN_STDARG_START, BUILT_IN_NORMAL, NULL_PTR);
3637 builtin_function ("__builtin_va_end",
3638 build_function_type (void_type_node,
3639 tree_cons (NULL_TREE,
3640 va_list_ref_type_node,
3642 BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL_PTR);
3644 builtin_function ("__builtin_va_copy",
3645 build_function_type (void_type_node,
3646 tree_cons (NULL_TREE,
3647 va_list_ref_type_node,
3648 tree_cons (NULL_TREE,
3649 va_list_arg_type_node,
3651 BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL_PTR);
3653 /* ??? Ought to be `T __builtin_expect(T, T)' for any type T. */
3654 builtin_function ("__builtin_expect",
3655 build_function_type (long_integer_type_node,
3656 tree_cons (NULL_TREE,
3657 long_integer_type_node,
3658 tree_cons (NULL_TREE,
3659 long_integer_type_node,
3661 BUILT_IN_EXPECT, BUILT_IN_NORMAL, NULL_PTR);
3663 /* Currently under experimentation. */
3664 builtin_function ("__builtin_memcpy", memcpy_ftype, BUILT_IN_MEMCPY,
3665 BUILT_IN_NORMAL, "memcpy");
3666 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
3667 BUILT_IN_MEMCMP, BUILT_IN_NORMAL, "memcmp");
3668 builtin_function ("__builtin_memset", memset_ftype,
3669 BUILT_IN_MEMSET, BUILT_IN_NORMAL, "memset");
3670 builtin_function ("__builtin_bzero", bzero_ftype,
3671 BUILT_IN_BZERO, BUILT_IN_NORMAL, "bzero");
3672 builtin_function ("__builtin_bcmp", bcmp_ftype,
3673 BUILT_IN_BCMP, BUILT_IN_NORMAL, "bcmp");
3674 builtin_function ("__builtin_strcmp", int_ftype_string_string,
3675 BUILT_IN_STRCMP, BUILT_IN_NORMAL, "strcmp");
3676 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
3677 BUILT_IN_STRCPY, BUILT_IN_NORMAL, "strcpy");
3678 builtin_function ("__builtin_strlen", strlen_ftype,
3679 BUILT_IN_STRLEN, BUILT_IN_NORMAL, "strlen");
3680 builtin_function ("__builtin_sqrtf", float_ftype_float,
3681 BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrtf");
3682 builtin_function ("__builtin_fsqrt", double_ftype_double,
3683 BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrt");
3684 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
3685 BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrtl");
3686 builtin_function ("__builtin_sinf", float_ftype_float,
3687 BUILT_IN_SIN, BUILT_IN_NORMAL, "sinf");
3688 builtin_function ("__builtin_sin", double_ftype_double,
3689 BUILT_IN_SIN, BUILT_IN_NORMAL, "sin");
3690 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
3691 BUILT_IN_SIN, BUILT_IN_NORMAL, "sinl");
3692 builtin_function ("__builtin_cosf", float_ftype_float,
3693 BUILT_IN_COS, BUILT_IN_NORMAL, "cosf");
3694 builtin_function ("__builtin_cos", double_ftype_double,
3695 BUILT_IN_COS, BUILT_IN_NORMAL, "cos");
3696 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
3697 BUILT_IN_COS, BUILT_IN_NORMAL, "cosl");
3701 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS,
3702 BUILT_IN_NORMAL, NULL_PTR);
3703 builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS,
3704 BUILT_IN_NORMAL, NULL_PTR);
3705 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS,
3706 BUILT_IN_NORMAL, NULL_PTR);
3707 builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3708 BUILT_IN_NORMAL, NULL_PTR);
3709 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS,
3710 BUILT_IN_NORMAL, NULL_PTR);
3711 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY,
3712 BUILT_IN_NORMAL, NULL_PTR);
3713 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
3714 BUILT_IN_NORMAL, NULL_PTR);
3715 builtin_function ("memset", memset_ftype, BUILT_IN_MEMSET,
3716 BUILT_IN_NORMAL, NULL_PTR);
3717 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
3718 BUILT_IN_NORMAL, NULL_PTR);
3719 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
3720 BUILT_IN_NORMAL, NULL_PTR);
3721 builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN,
3722 BUILT_IN_NORMAL, NULL_PTR);
3723 builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT,
3724 BUILT_IN_NORMAL, NULL_PTR);
3725 builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT,
3726 BUILT_IN_NORMAL, NULL_PTR);
3727 builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
3728 BUILT_IN_NORMAL, NULL_PTR);
3729 builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN,
3730 BUILT_IN_NORMAL, NULL_PTR);
3731 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN,
3732 BUILT_IN_NORMAL, NULL_PTR);
3733 builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN,
3734 BUILT_IN_NORMAL, NULL_PTR);
3735 builtin_function ("cosf", float_ftype_float, BUILT_IN_COS,
3736 BUILT_IN_NORMAL, NULL_PTR);
3737 builtin_function ("cos", double_ftype_double, BUILT_IN_COS,
3738 BUILT_IN_NORMAL, NULL_PTR);
3739 builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS,
3740 BUILT_IN_NORMAL, NULL_PTR);
3742 /* Declare these functions volatile
3743 to avoid spurious "control drops through" warnings. */
3744 temp = builtin_function ("abort", cplus_mode ? void_ftype : void_ftype_any,
3745 0, NOT_BUILT_IN, NULL_PTR);
3746 TREE_THIS_VOLATILE (temp) = 1;
3747 TREE_SIDE_EFFECTS (temp) = 1;
3749 #if 0 /* ??? The C++ frontend used to do this. */
3750 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3752 DECL_BUILT_IN_NONANSI (temp) = 1;
3754 temp = builtin_function ("exit",
3755 cplus_mode ? void_ftype_int : void_ftype_any,
3756 0, NOT_BUILT_IN, NULL_PTR);
3757 TREE_THIS_VOLATILE (temp) = 1;
3758 TREE_SIDE_EFFECTS (temp) = 1;
3760 #if 0 /* ??? The C++ frontend used to do this. */
3761 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3763 DECL_BUILT_IN_NONANSI (temp) = 1;
3768 /* Support for these has not been written in either expand_builtin
3769 or build_function_call. */
3770 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV,
3771 BUILT_IN_NORMAL, NULL_PTR);
3772 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV,
3773 BUILT_IN_NORMAL, NULL_PTR);
3774 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
3775 BUILT_IN_NORMAL, NULL_PTR);
3776 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
3777 BUILT_IN_NORMAL, NULL_PTR);
3778 builtin_function ("__builtin_fmod", double_ftype_double_double,
3779 BUILT_IN_FMOD, BUILT_IN_NORMAL, NULL_PTR);
3780 builtin_function ("__builtin_frem", double_ftype_double_double,
3781 BUILT_IN_FREM, BUILT_IN_NORMAL, NULL_PTR);
3782 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
3783 BUILT_IN_NORMAL, NULL_PTR);
3784 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
3785 BUILT_IN_NORMAL, NULL_PTR);
3788 /* ??? Perhaps there's a better place to do this. But it is related
3789 to __builtin_va_arg, so it isn't that off-the-wall. */
3790 lang_type_promotes_to = simple_type_promotes_to;
3794 build_va_arg (expr, type)
3797 return build1 (VA_ARG_EXPR, type, expr);
3800 /* Given a type, apply default promotions wrt unnamed function arguments
3801 and return the new type. Return NULL_TREE if no change. */
3802 /* ??? There is a function of the same name in the C++ front end that
3803 does something similar, but is more thorough and does not return NULL
3804 if no change. We could perhaps share code, but it would make the
3805 self_promoting_type property harder to identify. */
3808 simple_type_promotes_to (type)
3811 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3812 return double_type_node;
3814 if (C_PROMOTING_INTEGER_TYPE_P (type))
3816 /* Traditionally, unsignedness is preserved in default promotions.
3817 Also preserve unsignedness if not really getting any wider. */
3818 if (TREE_UNSIGNED (type)
3819 && (flag_traditional
3820 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
3821 return unsigned_type_node;
3822 return integer_type_node;
3828 /* Return 1 if PARMS specifies a fixed number of parameters
3829 and none of their types is affected by default promotions. */
3832 self_promoting_args_p (parms)
3836 for (t = parms; t; t = TREE_CHAIN (t))
3838 register tree type = TREE_VALUE (t);
3840 if (TREE_CHAIN (t) == 0 && type != void_type_node)
3846 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3849 if (C_PROMOTING_INTEGER_TYPE_P (type))
3855 /* Recognize certain built-in functions so we can make tree-codes
3856 other than CALL_EXPR. We do this when it enables fold-const.c
3857 to do something useful. */
3858 /* ??? By rights this should go in builtins.c, but only C and C++
3859 implement build_{binary,unary}_op. Not exactly sure what bits
3860 of functionality are actually needed from those functions, or
3861 where the similar functionality exists in the other front ends. */
3864 expand_tree_builtin (function, params, coerced_params)
3865 tree function, params, coerced_params;
3867 enum tree_code code;
3869 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
3872 switch (DECL_FUNCTION_CODE (function))
3877 if (coerced_params == 0)
3878 return integer_zero_node;
3879 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
3881 case BUILT_IN_ISGREATER:
3882 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3888 case BUILT_IN_ISGREATEREQUAL:
3889 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3895 case BUILT_IN_ISLESS:
3896 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3902 case BUILT_IN_ISLESSEQUAL:
3903 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3909 case BUILT_IN_ISLESSGREATER:
3910 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3916 case BUILT_IN_ISUNORDERED:
3917 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
3918 return integer_zero_node;
3919 code = UNORDERED_EXPR;
3927 || TREE_CHAIN (params) == 0)
3929 error ("too few arguments to function `%s'",
3930 IDENTIFIER_POINTER (DECL_NAME (function)));
3931 return error_mark_node;
3933 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
3935 error ("too many arguments to function `%s'",
3936 IDENTIFIER_POINTER (DECL_NAME (function)));
3937 return error_mark_node;
3940 arg0 = TREE_VALUE (params);
3941 arg1 = TREE_VALUE (TREE_CHAIN (params));
3942 arg0 = build_binary_op (code, arg0, arg1, 0);
3943 if (code != UNORDERED_EXPR)
3944 arg0 = build_unary_op (TRUTH_NOT_EXPR, arg0, 0);