1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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. */
36 #include "diagnostic.h"
39 cpp_reader *parse_in; /* Declared in c-lex.h. */
41 #undef WCHAR_TYPE_SIZE
42 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
45 #define PTRDIFF_TYPE "long int"
49 #define WINT_TYPE "unsigned int"
53 #define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
55 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
61 #define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
63 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
64 ? "long unsigned int" \
65 : "long long unsigned int"))
68 /* The following symbols are subsumed in the c_global_trees array, and
69 listed here individually for documentation purposes.
71 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
73 tree short_integer_type_node;
74 tree long_integer_type_node;
75 tree long_long_integer_type_node;
77 tree short_unsigned_type_node;
78 tree long_unsigned_type_node;
79 tree long_long_unsigned_type_node;
81 tree boolean_type_node;
82 tree boolean_false_node;
83 tree boolean_true_node;
85 tree ptrdiff_type_node;
87 tree unsigned_char_type_node;
88 tree signed_char_type_node;
90 tree signed_wchar_type_node;
91 tree unsigned_wchar_type_node;
94 tree double_type_node;
95 tree long_double_type_node;
97 tree complex_integer_type_node;
98 tree complex_float_type_node;
99 tree complex_double_type_node;
100 tree complex_long_double_type_node;
102 tree intQI_type_node;
103 tree intHI_type_node;
104 tree intSI_type_node;
105 tree intDI_type_node;
106 tree intTI_type_node;
108 tree unsigned_intQI_type_node;
109 tree unsigned_intHI_type_node;
110 tree unsigned_intSI_type_node;
111 tree unsigned_intDI_type_node;
112 tree unsigned_intTI_type_node;
114 tree widest_integer_literal_type_node;
115 tree widest_unsigned_literal_type_node;
117 Nodes for types `void *' and `const void *'.
119 tree ptr_type_node, const_ptr_type_node;
121 Nodes for types `char *' and `const char *'.
123 tree string_type_node, const_string_type_node;
125 Type `char[SOMENUMBER]'.
126 Used when an array of char is needed and the size is irrelevant.
128 tree char_array_type_node;
130 Type `int[SOMENUMBER]' or something like it.
131 Used when an array of int needed and the size is irrelevant.
133 tree int_array_type_node;
135 Type `wchar_t[SOMENUMBER]' or something like it.
136 Used when a wide string literal is created.
138 tree wchar_array_type_node;
140 Type `int ()' -- used for implicit declaration of functions.
142 tree default_function_type;
144 Function types `int (int)', etc.
150 tree ptr_ftype_sizetype;
152 A VOID_TYPE node, packaged in a TREE_LIST.
156 The identifiers __FUNCTION__, __PRETTY_FUNCTION__, and __func__.
158 tree function_id_node;
159 tree pretty_function_id_node;
164 tree c_global_trees[CTI_MAX];
166 /* Nonzero means don't recognize the non-ANSI builtin functions. */
170 /* Nonzero means don't recognize the non-ANSI builtin functions.
173 int flag_no_nonansi_builtin;
175 /* If non-NULL, dump the tree structure for the entire translation
176 unit to this file. */
178 const char *flag_dump_translation_unit;
180 /* Warn about *printf or *scanf format/argument anomalies. */
184 /* Warn about Y2K problems with strftime formats. */
188 /* Warn about excess arguments to formats. */
190 int warn_format_extra_args;
192 /* Warn about non-literal format arguments. */
194 int warn_format_nonliteral;
196 /* Warn about possible security problems with calls to format functions. */
198 int warn_format_security;
200 /* Nonzero means warn about possible violations of sequence point rules. */
202 int warn_sequence_point;
204 /* The elements of `ridpointers' are identifier nodes for the reserved
205 type names and storage classes. It is indexed by a RID_... value. */
208 tree (*make_fname_decl) PARAMS ((tree, const char *, int));
210 /* If non-NULL, the address of a language-specific function that
211 returns 1 for language-specific statement codes. */
212 int (*lang_statement_code_p) PARAMS ((enum tree_code));
214 /* If non-NULL, the address of a language-specific function that takes
215 any action required right before expand_function_end is called. */
216 void (*lang_expand_function_end) PARAMS ((void));
218 /* If this variable is defined to a non-NULL value, it will be called
219 after the file has been completely parsed. */
220 void (*back_end_hook) PARAMS ((tree));
222 /* Nonzero means the expression being parsed will never be evaluated.
223 This is a count, since unevaluated expressions can nest. */
226 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
227 A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
228 A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
229 A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, A_MALLOC,
230 A_NO_LIMIT_STACK, A_PURE};
232 enum format_type { printf_format_type, scanf_format_type,
233 strftime_format_type, strfmon_format_type };
235 static void add_attribute PARAMS ((enum attrs, const char *,
237 static void init_attributes PARAMS ((void));
238 static void record_function_format PARAMS ((tree, tree, enum format_type,
240 static void record_international_format PARAMS ((tree, tree, int));
241 static int default_valid_lang_attribute PARAMS ((tree, tree, tree, tree));
243 /* Keep a stack of if statements. We record the number of compound
244 statements seen up to the if keyword, as well as the line number
245 and file of the if. If a potentially ambiguous else is seen, that
246 fact is recorded; the warning is issued when we can be sure that
247 the enclosing if statement does not have an else branch. */
257 static if_elt *if_stack;
259 /* Amount of space in the if statement stack. */
260 static int if_stack_space = 0;
263 static int if_stack_pointer = 0;
265 /* Record the start of an if-then, and record the start of it
266 for ambiguous else detection. */
269 c_expand_start_cond (cond, compstmt_count)
275 /* Make sure there is enough space on the stack. */
276 if (if_stack_space == 0)
279 if_stack = (if_elt *)xmalloc (10 * sizeof (if_elt));
281 else if (if_stack_space == if_stack_pointer)
283 if_stack_space += 10;
284 if_stack = (if_elt *)xrealloc (if_stack, if_stack_space * sizeof (if_elt));
287 if_stmt = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
288 IF_COND (if_stmt) = cond;
291 /* Record this if statement. */
292 if_stack[if_stack_pointer].compstmt_count = compstmt_count;
293 if_stack[if_stack_pointer].file = input_filename;
294 if_stack[if_stack_pointer].line = lineno;
295 if_stack[if_stack_pointer].needs_warning = 0;
296 if_stack[if_stack_pointer].if_stmt = if_stmt;
300 /* Called after the then-clause for an if-statement is processed. */
305 tree if_stmt = if_stack[if_stack_pointer - 1].if_stmt;
306 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
309 /* Record the end of an if-then. Optionally warn if a nested
310 if statement had an ambiguous else clause. */
316 if (if_stack[if_stack_pointer].needs_warning)
317 warning_with_file_and_line (if_stack[if_stack_pointer].file,
318 if_stack[if_stack_pointer].line,
319 "suggest explicit braces to avoid ambiguous `else'");
320 last_expr_type = NULL_TREE;
323 /* Called between the then-clause and the else-clause
324 of an if-then-else. */
327 c_expand_start_else ()
329 /* An ambiguous else warning must be generated for the enclosing if
330 statement, unless we see an else branch for that one, too. */
332 && if_stack_pointer > 1
333 && (if_stack[if_stack_pointer - 1].compstmt_count
334 == if_stack[if_stack_pointer - 2].compstmt_count))
335 if_stack[if_stack_pointer - 2].needs_warning = 1;
337 /* Even if a nested if statement had an else branch, it can't be
338 ambiguous if this one also has an else. So don't warn in that
339 case. Also don't warn for any if statements nested in this else. */
340 if_stack[if_stack_pointer - 1].needs_warning = 0;
341 if_stack[if_stack_pointer - 1].compstmt_count--;
344 /* Called after the else-clause for an if-statement is processed. */
349 tree if_stmt = if_stack[if_stack_pointer - 1].if_stmt;
350 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
353 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
356 declare_function_name ()
358 const char *name, *printable_name;
360 if (current_function_decl == NULL)
363 printable_name = "top level";
367 /* Allow functions to be nameless (such as artificial ones). */
368 if (DECL_NAME (current_function_decl))
369 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
372 printable_name = (*decl_printable_name) (current_function_decl, 2);
374 /* ISO C99 defines __func__, which is a variable, not a string
375 constant, and which is not a defined symbol at file scope. */
376 (*make_fname_decl) (func_id_node, name, 0);
379 (*make_fname_decl) (function_id_node, name, 0);
380 (*make_fname_decl) (pretty_function_id_node, printable_name, 1);
383 /* Given a chain of STRING_CST nodes,
384 concatenate them into one STRING_CST
385 and give it a suitable array-of-chars data type. */
388 combine_strings (strings)
391 register tree value, t;
392 register int length = 1;
395 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
397 const int nchars_max = flag_isoc99 ? 4095 : 509;
399 if (TREE_CHAIN (strings))
401 /* More than one in the chain, so concatenate. */
402 register char *p, *q;
404 /* Don't include the \0 at the end of each substring,
405 except for the last one.
406 Count wide strings and ordinary strings separately. */
407 for (t = strings; t; t = TREE_CHAIN (t))
409 if (TREE_TYPE (t) == wchar_array_type_node)
411 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
415 length += (TREE_STRING_LENGTH (t) - 1);
418 /* If anything is wide, the non-wides will be converted,
419 which makes them take more space. */
421 length = length * wchar_bytes + wide_length;
425 /* Copy the individual strings into the new combined string.
426 If the combined string is wide, convert the chars to ints
427 for any individual strings that are not wide. */
430 for (t = strings; t; t = TREE_CHAIN (t))
432 int len = (TREE_STRING_LENGTH (t)
433 - ((TREE_TYPE (t) == wchar_array_type_node)
435 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
437 memcpy (q, TREE_STRING_POINTER (t), len);
443 for (i = 0; i < len; i++)
445 if (WCHAR_TYPE_SIZE == HOST_BITS_PER_SHORT)
446 ((short *) q)[i] = TREE_STRING_POINTER (t)[i];
448 ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
450 q += len * wchar_bytes;
456 for (i = 0; i < wchar_bytes; i++)
462 value = build_string (length, p);
467 length = TREE_STRING_LENGTH (value);
468 if (TREE_TYPE (value) == wchar_array_type_node)
472 /* Compute the number of elements, for the array type. */
473 nchars = wide_flag ? length / wchar_bytes : length;
475 if (pedantic && nchars - 1 > nchars_max && c_language == clk_c)
476 pedwarn ("string length `%d' is greater than the minimum length `%d' ISO C%d is required to support",
477 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
479 /* Create the array type for the string constant.
480 -Wwrite-strings says make the string constant an array of const char
481 so that copying it to a non-const pointer will get a warning.
482 For C++, this is the standard behavior. */
483 if (flag_const_strings
484 && (! flag_traditional && ! flag_writable_strings))
487 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
490 = build_array_type (elements,
491 build_index_type (build_int_2 (nchars - 1, 0)));
495 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
496 build_index_type (build_int_2 (nchars - 1, 0)));
498 TREE_CONSTANT (value) = 1;
499 TREE_READONLY (value) = ! flag_writable_strings;
500 TREE_STATIC (value) = 1;
504 /* To speed up processing of attributes, we maintain an array of
505 IDENTIFIER_NODES and the corresponding attribute types. */
507 /* Array to hold attribute information. */
509 static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50];
511 static int attrtab_idx = 0;
513 /* Add an entry to the attribute table above. */
516 add_attribute (id, string, min_len, max_len, decl_req)
519 int min_len, max_len;
524 attrtab[attrtab_idx].id = id;
525 attrtab[attrtab_idx].name = get_identifier (string);
526 attrtab[attrtab_idx].min = min_len;
527 attrtab[attrtab_idx].max = max_len;
528 attrtab[attrtab_idx++].decl_req = decl_req;
530 sprintf (buf, "__%s__", string);
532 attrtab[attrtab_idx].id = id;
533 attrtab[attrtab_idx].name = get_identifier (buf);
534 attrtab[attrtab_idx].min = min_len;
535 attrtab[attrtab_idx].max = max_len;
536 attrtab[attrtab_idx++].decl_req = decl_req;
539 /* Initialize attribute table. */
544 add_attribute (A_PACKED, "packed", 0, 0, 0);
545 add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1);
546 add_attribute (A_COMMON, "common", 0, 0, 1);
547 add_attribute (A_NORETURN, "noreturn", 0, 0, 1);
548 add_attribute (A_NORETURN, "volatile", 0, 0, 1);
549 add_attribute (A_UNUSED, "unused", 0, 0, 0);
550 add_attribute (A_CONST, "const", 0, 0, 1);
551 add_attribute (A_T_UNION, "transparent_union", 0, 0, 0);
552 add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1);
553 add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1);
554 add_attribute (A_MODE, "mode", 1, 1, 1);
555 add_attribute (A_SECTION, "section", 1, 1, 1);
556 add_attribute (A_ALIGNED, "aligned", 0, 1, 0);
557 add_attribute (A_FORMAT, "format", 3, 3, 1);
558 add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1);
559 add_attribute (A_WEAK, "weak", 0, 0, 1);
560 add_attribute (A_ALIAS, "alias", 1, 1, 1);
561 add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
562 add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
563 add_attribute (A_MALLOC, "malloc", 0, 0, 1);
564 add_attribute (A_NO_LIMIT_STACK, "no_stack_limit", 0, 0, 1);
565 add_attribute (A_PURE, "pure", 0, 0, 1);
568 /* Default implementation of valid_lang_attribute, below. By default, there
569 are no language-specific attributes. */
572 default_valid_lang_attribute (attr_name, attr_args, decl, type)
573 tree attr_name ATTRIBUTE_UNUSED;
574 tree attr_args ATTRIBUTE_UNUSED;
575 tree decl ATTRIBUTE_UNUSED;
576 tree type ATTRIBUTE_UNUSED;
581 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
582 attribute for either declaration DECL or type TYPE and 0 otherwise. */
584 int (*valid_lang_attribute) PARAMS ((tree, tree, tree, tree))
585 = default_valid_lang_attribute;
587 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
588 and install them in NODE, which is either a DECL (including a TYPE_DECL)
589 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
590 and declaration modifiers but before the declaration proper. */
593 decl_attributes (node, attributes, prefix_attributes)
594 tree node, attributes, prefix_attributes;
596 tree decl = 0, type = 0;
600 if (attrtab_idx == 0)
606 type = TREE_TYPE (decl);
607 is_type = TREE_CODE (node) == TYPE_DECL;
609 else if (TYPE_P (node))
610 type = node, is_type = 1;
612 #ifdef PRAGMA_INSERT_ATTRIBUTES
613 /* If the code in c-pragma.c wants to insert some attributes then
614 allow it to do so. Do this before allowing machine back ends to
615 insert attributes, so that they have the opportunity to override
616 anything done here. */
617 PRAGMA_INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
620 #ifdef INSERT_ATTRIBUTES
621 INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
624 attributes = chainon (prefix_attributes, attributes);
626 for (a = attributes; a; a = TREE_CHAIN (a))
628 tree name = TREE_PURPOSE (a);
629 tree args = TREE_VALUE (a);
633 for (i = 0; i < attrtab_idx; i++)
634 if (attrtab[i].name == name)
637 if (i == attrtab_idx)
639 if (! valid_machine_attribute (name, args, decl, type)
640 && ! (* valid_lang_attribute) (name, args, decl, type))
641 warning ("`%s' attribute directive ignored",
642 IDENTIFIER_POINTER (name));
644 type = TREE_TYPE (decl);
647 else if (attrtab[i].decl_req && decl == 0)
649 warning ("`%s' attribute does not apply to types",
650 IDENTIFIER_POINTER (name));
653 else if (list_length (args) < attrtab[i].min
654 || list_length (args) > attrtab[i].max)
656 error ("wrong number of arguments specified for `%s' attribute",
657 IDENTIFIER_POINTER (name));
666 TYPE_PACKED (type) = 1;
667 else if (TREE_CODE (decl) == FIELD_DECL)
668 DECL_PACKED (decl) = 1;
669 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
670 used for DECL_REGISTER. It wouldn't mean anything anyway. */
672 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
676 if (TREE_CODE (decl) == VAR_DECL)
677 DECL_COMMON (decl) = 0;
679 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
683 if (TREE_CODE (decl) == VAR_DECL)
684 DECL_COMMON (decl) = 1;
686 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
690 if (TREE_CODE (decl) == FUNCTION_DECL)
691 TREE_THIS_VOLATILE (decl) = 1;
692 else if (TREE_CODE (type) == POINTER_TYPE
693 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
694 TREE_TYPE (decl) = type
696 (build_type_variant (TREE_TYPE (type),
697 TREE_READONLY (TREE_TYPE (type)), 1));
699 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
703 if (TREE_CODE (decl) == FUNCTION_DECL)
704 DECL_IS_MALLOC (decl) = 1;
705 /* ??? TODO: Support types. */
707 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
713 TREE_USED (decl) = 1;
715 TREE_USED (type) = 1;
716 else if (TREE_CODE (decl) == PARM_DECL
717 || TREE_CODE (decl) == VAR_DECL
718 || TREE_CODE (decl) == FUNCTION_DECL
719 || TREE_CODE (decl) == LABEL_DECL)
720 TREE_USED (decl) = 1;
722 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
726 if (TREE_CODE (decl) == FUNCTION_DECL)
727 TREE_READONLY (decl) = 1;
728 else if (TREE_CODE (type) == POINTER_TYPE
729 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
730 TREE_TYPE (decl) = type
732 (build_type_variant (TREE_TYPE (type), 1,
733 TREE_THIS_VOLATILE (TREE_TYPE (type))));
735 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name));
739 if (TREE_CODE (decl) == FUNCTION_DECL)
740 DECL_IS_PURE (decl) = 1;
741 /* ??? TODO: Support types. */
743 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
749 && TREE_CODE (type) == UNION_TYPE
751 || (TYPE_FIELDS (type) != 0
752 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))))
753 TYPE_TRANSPARENT_UNION (type) = 1;
754 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
755 && TREE_CODE (type) == UNION_TYPE
756 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))
757 DECL_TRANSPARENT_UNION (decl) = 1;
759 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
763 if (TREE_CODE (decl) == FUNCTION_DECL
764 && TREE_CODE (type) == FUNCTION_TYPE
765 && decl_function_context (decl) == 0)
767 DECL_STATIC_CONSTRUCTOR (decl) = 1;
768 TREE_USED (decl) = 1;
771 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
775 if (TREE_CODE (decl) == FUNCTION_DECL
776 && TREE_CODE (type) == FUNCTION_TYPE
777 && decl_function_context (decl) == 0)
779 DECL_STATIC_DESTRUCTOR (decl) = 1;
780 TREE_USED (decl) = 1;
783 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
787 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
788 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
792 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
793 int len = strlen (p);
794 enum machine_mode mode = VOIDmode;
797 if (len > 4 && p[0] == '_' && p[1] == '_'
798 && p[len - 1] == '_' && p[len - 2] == '_')
800 char *newp = (char *) alloca (len - 1);
802 strcpy (newp, &p[2]);
803 newp[len - 4] = '\0';
807 /* Give this decl a type with the specified mode.
808 First check for the special modes. */
809 if (! strcmp (p, "byte"))
811 else if (!strcmp (p, "word"))
813 else if (! strcmp (p, "pointer"))
816 for (j = 0; j < NUM_MACHINE_MODES; j++)
817 if (!strcmp (p, GET_MODE_NAME (j)))
818 mode = (enum machine_mode) j;
820 if (mode == VOIDmode)
821 error ("unknown machine mode `%s'", p);
822 else if (0 == (typefm = type_for_mode (mode,
823 TREE_UNSIGNED (type))))
824 error ("no data type for mode `%s'", p);
827 if (TYPE_PRECISION (typefm) > (TREE_UNSIGNED (type)
828 ? TYPE_PRECISION(uintmax_type_node)
829 : TYPE_PRECISION(intmax_type_node))
831 pedwarn ("type with more precision than %s",
832 TREE_UNSIGNED (type) ? "uintmax_t" : "intmax_t");
833 TREE_TYPE (decl) = type = typefm;
834 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
835 layout_decl (decl, 0);
841 #ifdef ASM_OUTPUT_SECTION_NAME
842 if ((TREE_CODE (decl) == FUNCTION_DECL
843 || TREE_CODE (decl) == VAR_DECL)
844 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
846 if (TREE_CODE (decl) == VAR_DECL
847 && current_function_decl != NULL_TREE
848 && ! TREE_STATIC (decl))
849 error_with_decl (decl,
850 "section attribute cannot be specified for local variables");
851 /* The decl may have already been given a section attribute from
852 a previous declaration. Ensure they match. */
853 else if (DECL_SECTION_NAME (decl) != NULL_TREE
854 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
855 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
856 error_with_decl (node,
857 "section of `%s' conflicts with previous declaration");
859 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
862 error_with_decl (node,
863 "section attribute not allowed for `%s'");
865 error_with_decl (node,
866 "section attributes are not supported for this target");
873 = (args ? TREE_VALUE (args)
874 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
877 /* Strip any NOPs of any kind. */
878 while (TREE_CODE (align_expr) == NOP_EXPR
879 || TREE_CODE (align_expr) == CONVERT_EXPR
880 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
881 align_expr = TREE_OPERAND (align_expr, 0);
883 if (TREE_CODE (align_expr) != INTEGER_CST)
885 error ("requested alignment is not a constant");
889 if ((i = tree_log2 (align_expr)) == -1)
890 error ("requested alignment is not a power of 2");
891 else if (i > HOST_BITS_PER_INT - 2)
892 error ("requested alignment is too large");
895 /* If we have a TYPE_DECL, then copy the type, so that we
896 don't accidentally modify a builtin type. See pushdecl. */
897 if (decl && TREE_TYPE (decl) != error_mark_node
898 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
900 tree tt = TREE_TYPE (decl);
901 DECL_ORIGINAL_TYPE (decl) = tt;
902 tt = build_type_copy (tt);
903 TYPE_NAME (tt) = decl;
904 TREE_USED (tt) = TREE_USED (decl);
905 TREE_TYPE (decl) = tt;
909 TYPE_ALIGN (type) = (1 << i) * BITS_PER_UNIT;
910 TYPE_USER_ALIGN (type) = 1;
912 else if (TREE_CODE (decl) != VAR_DECL
913 && TREE_CODE (decl) != FIELD_DECL)
914 error_with_decl (decl,
915 "alignment may not be specified for `%s'");
918 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
919 DECL_USER_ALIGN (decl) = 1;
926 tree format_type_id = TREE_VALUE (args);
927 tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
928 tree first_arg_num_expr
929 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
930 unsigned HOST_WIDE_INT format_num, first_arg_num;
931 enum format_type format_type;
933 unsigned int arg_num;
935 if (TREE_CODE (decl) != FUNCTION_DECL)
937 error_with_decl (decl,
938 "argument format specified for non-function `%s'");
942 if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
944 error ("unrecognized format specifier");
949 const char *p = IDENTIFIER_POINTER (format_type_id);
951 if (!strcmp (p, "printf") || !strcmp (p, "__printf__"))
952 format_type = printf_format_type;
953 else if (!strcmp (p, "scanf") || !strcmp (p, "__scanf__"))
954 format_type = scanf_format_type;
955 else if (!strcmp (p, "strftime")
956 || !strcmp (p, "__strftime__"))
957 format_type = strftime_format_type;
958 else if (!strcmp (p, "strfmon")
959 || !strcmp (p, "__strfmon__"))
960 format_type = strfmon_format_type;
963 warning ("`%s' is an unrecognized format function type", p);
968 /* Strip any conversions from the string index and first arg number
969 and verify they are constants. */
970 while (TREE_CODE (format_num_expr) == NOP_EXPR
971 || TREE_CODE (format_num_expr) == CONVERT_EXPR
972 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
973 format_num_expr = TREE_OPERAND (format_num_expr, 0);
975 while (TREE_CODE (first_arg_num_expr) == NOP_EXPR
976 || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR
977 || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR)
978 first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0);
980 if (TREE_CODE (format_num_expr) != INTEGER_CST
981 || TREE_INT_CST_HIGH (format_num_expr) != 0
982 || TREE_CODE (first_arg_num_expr) != INTEGER_CST
983 || TREE_INT_CST_HIGH (first_arg_num_expr) != 0)
985 error ("format string has invalid operand number");
989 format_num = TREE_INT_CST_LOW (format_num_expr);
990 first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr);
991 if (first_arg_num != 0 && first_arg_num <= format_num)
993 error ("format string arg follows the args to be formatted");
997 /* If a parameter list is specified, verify that the format_num
998 argument is actually a string, in case the format attribute
1000 argument = TYPE_ARG_TYPES (type);
1003 for (arg_num = 1; argument != 0 && arg_num != format_num;
1004 ++arg_num, argument = TREE_CHAIN (argument))
1008 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
1009 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
1012 error ("format string arg not a string type");
1016 else if (first_arg_num != 0)
1018 /* Verify that first_arg_num points to the last arg,
1021 arg_num++, argument = TREE_CHAIN (argument);
1023 if (arg_num != first_arg_num)
1025 error ("args to be formatted is not '...'");
1031 if (format_type == strftime_format_type && first_arg_num != 0)
1033 error ("strftime formats cannot format arguments");
1037 record_function_format (DECL_NAME (decl),
1038 DECL_ASSEMBLER_NAME (decl),
1039 format_type, format_num, first_arg_num);
1045 tree format_num_expr = TREE_VALUE (args);
1046 unsigned HOST_WIDE_INT format_num;
1047 unsigned int arg_num;
1050 if (TREE_CODE (decl) != FUNCTION_DECL)
1052 error_with_decl (decl,
1053 "argument format specified for non-function `%s'");
1057 /* Strip any conversions from the first arg number and verify it
1059 while (TREE_CODE (format_num_expr) == NOP_EXPR
1060 || TREE_CODE (format_num_expr) == CONVERT_EXPR
1061 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
1062 format_num_expr = TREE_OPERAND (format_num_expr, 0);
1064 if (TREE_CODE (format_num_expr) != INTEGER_CST
1065 || TREE_INT_CST_HIGH (format_num_expr) != 0)
1067 error ("format string has invalid operand number");
1071 format_num = TREE_INT_CST_LOW (format_num_expr);
1073 /* If a parameter list is specified, verify that the format_num
1074 argument is actually a string, in case the format attribute
1076 argument = TYPE_ARG_TYPES (type);
1079 for (arg_num = 1; argument != 0 && arg_num != format_num;
1080 ++arg_num, argument = TREE_CHAIN (argument))
1084 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
1085 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
1088 error ("format string arg not a string type");
1093 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != POINTER_TYPE
1094 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl))))
1097 error ("function does not return string type");
1101 record_international_format (DECL_NAME (decl),
1102 DECL_ASSEMBLER_NAME (decl),
1108 declare_weak (decl);
1112 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
1113 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
1114 error_with_decl (decl,
1115 "`%s' defined both normally and as an alias");
1116 else if (decl_function_context (decl) == 0)
1120 id = TREE_VALUE (args);
1121 if (TREE_CODE (id) != STRING_CST)
1123 error ("alias arg not a string");
1126 id = get_identifier (TREE_STRING_POINTER (id));
1127 /* This counts as a use of the object pointed to. */
1130 if (TREE_CODE (decl) == FUNCTION_DECL)
1131 DECL_INITIAL (decl) = error_mark_node;
1133 DECL_EXTERNAL (decl) = 0;
1134 assemble_alias (decl, id);
1137 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1140 case A_NO_CHECK_MEMORY_USAGE:
1141 if (TREE_CODE (decl) != FUNCTION_DECL)
1143 error_with_decl (decl,
1144 "`%s' attribute applies only to functions",
1145 IDENTIFIER_POINTER (name));
1147 else if (DECL_INITIAL (decl))
1149 error_with_decl (decl,
1150 "can't set `%s' attribute after definition",
1151 IDENTIFIER_POINTER (name));
1154 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
1157 case A_NO_INSTRUMENT_FUNCTION:
1158 if (TREE_CODE (decl) != FUNCTION_DECL)
1160 error_with_decl (decl,
1161 "`%s' attribute applies only to functions",
1162 IDENTIFIER_POINTER (name));
1164 else if (DECL_INITIAL (decl))
1166 error_with_decl (decl,
1167 "can't set `%s' attribute after definition",
1168 IDENTIFIER_POINTER (name));
1171 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
1174 case A_NO_LIMIT_STACK:
1175 if (TREE_CODE (decl) != FUNCTION_DECL)
1177 error_with_decl (decl,
1178 "`%s' attribute applies only to functions",
1179 IDENTIFIER_POINTER (name));
1181 else if (DECL_INITIAL (decl))
1183 error_with_decl (decl,
1184 "can't set `%s' attribute after definition",
1185 IDENTIFIER_POINTER (name));
1188 DECL_NO_LIMIT_STACK (decl) = 1;
1194 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1195 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1197 The head of the declspec list is stored in DECLSPECS.
1198 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1200 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1201 the list elements. We drop the containing TREE_LIST nodes and link the
1202 resulting attributes together the way decl_attributes expects them. */
1205 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1207 tree *declspecs, *prefix_attributes;
1209 tree t, s, a, next, specs, attrs;
1211 /* This can happen after an __extension__ in pedantic mode. */
1212 if (specs_attrs != NULL_TREE
1213 && TREE_CODE (specs_attrs) == INTEGER_CST)
1215 *declspecs = NULL_TREE;
1216 *prefix_attributes = NULL_TREE;
1220 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1221 if (specs_attrs != NULL_TREE
1222 && TREE_CODE (specs_attrs) != TREE_LIST)
1224 *declspecs = specs_attrs;
1225 *prefix_attributes = NULL_TREE;
1229 /* Remember to keep the lists in the same order, element-wise. */
1231 specs = s = NULL_TREE;
1232 attrs = a = NULL_TREE;
1233 for (t = specs_attrs; t; t = next)
1235 next = TREE_CHAIN (t);
1236 /* Declspecs have a non-NULL TREE_VALUE. */
1237 if (TREE_VALUE (t) != NULL_TREE)
1239 if (specs == NULL_TREE)
1249 if (attrs == NULL_TREE)
1250 attrs = a = TREE_PURPOSE (t);
1253 TREE_CHAIN (a) = TREE_PURPOSE (t);
1254 a = TREE_PURPOSE (t);
1256 /* More attrs can be linked here, move A to the end. */
1257 while (TREE_CHAIN (a) != NULL_TREE)
1262 /* Terminate the lists. */
1264 TREE_CHAIN (s) = NULL_TREE;
1266 TREE_CHAIN (a) = NULL_TREE;
1270 *prefix_attributes = attrs;
1273 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1274 This function is used by the parser when a rule will accept attributes
1275 in a particular position, but we don't want to support that just yet.
1277 A warning is issued for every ignored attribute. */
1280 strip_attrs (specs_attrs)
1285 split_specs_attrs (specs_attrs, &specs, &attrs);
1289 warning ("`%s' attribute ignored",
1290 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1291 attrs = TREE_CHAIN (attrs);
1297 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1298 a parameter list. */
1300 /* The meaningfully distinct length modifiers for format checking recognised
1317 /* The standard versions in which various format features appeared. */
1318 enum format_std_version
1322 STD_C9L, /* C99, but treat as C89 if -Wno-long-long. */
1327 /* The C standard version C++ is treated as equivalent to
1328 or inheriting from, for the purpose of format features supported. */
1329 #define CPLUSPLUS_STD_VER STD_C89
1330 /* The C standard version we are checking formats against when pedantic. */
1331 #define C_STD_VER (c_language == clk_cplusplus \
1332 ? CPLUSPLUS_STD_VER \
1335 : (flag_isoc94 ? STD_C94 : STD_C89)))
1336 /* The name to give to the standard version we are warning about when
1337 pedantic. FEATURE_VER is the version in which the feature warned out
1338 appeared, which is higher than C_STD_VER. */
1339 #define C_STD_NAME(FEATURE_VER) (c_language == clk_cplusplus \
1341 : ((FEATURE_VER) == STD_EXT \
1344 /* Adjust a C standard version, which may be STD_C9L, to account for
1345 -Wno-long-long. Returns other standard versions unchanged. */
1346 #define ADJ_STD(VER) ((int)((VER) == STD_C9L \
1347 ? (warn_long_long ? STD_C99 : STD_C89) \
1350 /* Flags that may apply to a particular kind of format checked by GCC. */
1353 /* This format converts arguments of types determined by the
1355 FMT_FLAG_ARG_CONVERT = 1,
1356 /* The scanf allocation 'a' kludge applies to this format kind. */
1357 FMT_FLAG_SCANF_A_KLUDGE = 2,
1358 /* A % during parsing a specifier is allowed to be a modified % rather
1359 that indicating the format is broken and we are out-of-sync. */
1360 FMT_FLAG_FANCY_PERCENT_OK = 4,
1361 /* With $ operand numbers, it is OK to reference the same argument more
1363 FMT_FLAG_DOLLAR_MULTIPLE = 8,
1364 /* This format type uses $ operand numbers (strfmon doesn't). */
1365 FMT_FLAG_USE_DOLLAR = 16,
1366 /* Zero width is bad in this type of format (scanf). */
1367 FMT_FLAG_ZERO_WIDTH_BAD = 32,
1368 /* Empty precision specification is OK in this type of format (printf). */
1369 FMT_FLAG_EMPTY_PREC_OK = 64
1370 /* Not included here: details of whether width or precision may occur
1371 (controlled by width_char and precision_char); details of whether
1372 '*' can be used for these (width_type and precision_type); details
1373 of whether length modifiers can occur (length_char_specs). */
1377 /* Structure describing a length modifier supported in format checking, and
1378 possibly a doubled version such as "hh". */
1381 /* Name of the single-character length modifier. */
1383 /* Index into a format_char_info.types array. */
1384 enum format_lengths index;
1385 /* Standard version this length appears in. */
1386 enum format_std_version std;
1387 /* Same, if the modifier can be repeated, or NULL if it can't. */
1388 const char *double_name;
1389 enum format_lengths double_index;
1390 enum format_std_version double_std;
1391 } format_length_info;
1394 /* Structure desribing the combination of a conversion specifier
1395 (or a set of specifiers which act identically) and a length modifier. */
1398 /* The standard version this combination of length and type appeared in.
1399 This is only relevant if greater than those for length and type
1400 individually; otherwise it is ignored. */
1401 enum format_std_version std;
1402 /* The name to use for the type, if different from that generated internally
1403 (e.g., "signed size_t"). */
1405 /* The type itself. */
1407 } format_type_detail;
1410 /* Macros to fill out tables of these. */
1411 #define BADLEN { 0, NULL, NULL }
1412 #define NOLENGTHS { BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }
1415 /* Structure desribing a format conversion specifier (or a set of specifiers
1416 which act identically), and the length modifiers used with it. */
1419 const char *format_chars;
1421 enum format_std_version std;
1422 /* Types accepted for each length modifier. */
1423 format_type_detail types[FMT_LEN_MAX];
1424 /* List of other modifier characters allowed with these specifiers.
1425 This lists flags, and additionally "w" for width, "p" for precision
1426 (right precision, for strfmon), "#" for left precision (strfmon),
1427 "a" for scanf "a" allocation extension (not applicable in C99 mode),
1428 "*" for scanf suppression, and "E" and "O" for those strftime
1430 const char *flag_chars;
1431 /* List of additional flags describing these conversion specifiers.
1432 "c" for generic character pointers being allowed, "2" for strftime
1433 two digit year formats, "3" for strftime formats giving two digit
1434 years in some locales, "4" for "2" which becomes "3" with an "E" modifier,
1435 "o" if use of strftime "O" is a GNU extension beyond C99,
1436 "W" if the argument is a pointer which is dereferenced and written into,
1437 "R" if the argument is a pointer which is dereferenced and read from,
1438 "i" for printf integer formats where the '0' flag is ignored with
1439 precision, and "[" for the starting character of a scanf scanset. */
1444 /* Structure describing a flag accepted by some kind of format. */
1447 /* The flag character in question (0 for end of array). */
1449 /* Zero if this entry describes the flag character in general, or a
1450 non-zero character that may be found in flags2 if it describes the
1451 flag when used with certain formats only. If the latter, only
1452 the first such entry found that applies to the current conversion
1453 specifier is used; the values of `name' and `long_name' it supplies
1454 will be used, if non-NULL and the standard version is higher than
1455 the unpredicated one, for any pedantic warning. For example, 'o'
1456 for strftime formats (meaning 'O' is an extension over C99). */
1458 /* Nonzero if the next character after this flag in the format should
1459 be skipped ('=' in strfmon), zero otherwise. */
1461 /* The name to use for this flag in diagnostic messages. For example,
1462 N_("`0' flag"), N_("field width"). */
1464 /* Long name for this flag in diagnostic messages; currently only used for
1465 "ISO C does not support ...". For example, N_("the `I' printf flag"). */
1466 const char *long_name;
1467 /* The standard version in which it appeared. */
1468 enum format_std_version std;
1472 /* Structure describing a combination of flags that is bad for some kind
1476 /* The first flag character in question (0 for end of array). */
1478 /* The second flag character. */
1480 /* Non-zero if the message should say that the first flag is ignored with
1481 the second, zero if the combination should simply be objected to. */
1483 /* Zero if this entry applies whenever this flag combination occurs,
1484 a non-zero character from flags2 if it only applies in some
1485 circumstances (e.g. 'i' for printf formats ignoring 0 with precision). */
1490 /* Structure describing a particular kind of format processed by GCC. */
1493 /* The name of this kind of format, for use in diagnostics. */
1495 /* Specifications of the length modifiers accepted; possibly NULL. */
1496 const format_length_info *length_char_specs;
1497 /* Details of the conversion specification characters accepted. */
1498 const format_char_info *conversion_specs;
1499 /* String listing the flag characters that are accepted. */
1500 const char *flag_chars;
1501 /* String listing modifier characters (strftime) accepted. May be NULL. */
1502 const char *modifier_chars;
1503 /* Details of the flag characters, including pseudo-flags. */
1504 const format_flag_spec *flag_specs;
1505 /* Details of bad combinations of flags. */
1506 const format_flag_pair *bad_flag_pairs;
1507 /* Flags applicable to this kind of format. */
1509 /* Flag character to treat a width as, or 0 if width not used. */
1511 /* Flag character to treat a left precision (strfmon) as,
1512 or 0 if left precision not used. */
1513 int left_precision_char;
1514 /* Flag character to treat a precision (for strfmon, right precision) as,
1515 or 0 if precision not used. */
1517 /* If a flag character has the effect of suppressing the conversion of
1518 an argument ('*' in scanf), that flag character, otherwise 0. */
1519 int suppression_char;
1520 /* Flag character to treat a length modifier as (ignored if length
1521 modifiers not used). Need not be placed in flag_chars for conversion
1522 specifiers, but is used to check for bad combinations such as length
1523 modifier with assignment suppression in scanf. */
1524 int length_code_char;
1525 /* Pointer to type of argument expected if '*' is used for a width,
1526 or NULL if '*' not used for widths. */
1528 /* Pointer to type of argument expected if '*' is used for a precision,
1529 or NULL if '*' not used for precisions. */
1530 tree *precision_type;
1534 /* Structure describing details of a type expected in format checking,
1535 and the type to check against it. */
1536 typedef struct format_wanted_type
1538 /* The type wanted. */
1540 /* The name of this type to use in diagnostics. */
1541 const char *wanted_type_name;
1542 /* The level of indirection through pointers at which this type occurs. */
1544 /* Whether, when pointer_count is 1, to allow any character type when
1545 pedantic, rather than just the character or void type specified. */
1546 int char_lenient_flag;
1547 /* Whether the argument, dereferenced once, is written into and so the
1548 argument must not be a pointer to a const-qualified type. */
1549 int writing_in_flag;
1550 /* Whether the argument, dereferenced once, is read from and so
1551 must not be a NULL pointer. */
1552 int reading_from_flag;
1553 /* If warnings should be of the form "field precision is not type int",
1554 the name to use (in this case "field precision"), otherwise NULL,
1555 for "%s format, %s arg" type messages. If (in an extension), this
1556 is a pointer type, wanted_type_name should be set to include the
1557 terminating '*' characters of the type name to give a correct
1560 /* The actual parameter to check against the wanted type. */
1562 /* The argument number of that parameter. */
1564 /* The next type to check for this format conversion, or NULL if none. */
1565 struct format_wanted_type *next;
1566 } format_wanted_type;
1569 static const format_length_info printf_length_specs[] =
1571 { "h", FMT_LEN_h, STD_C89, "hh", FMT_LEN_hh, STD_C99 },
1572 { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C9L },
1573 { "q", FMT_LEN_ll, STD_EXT, NULL, 0, 0 },
1574 { "L", FMT_LEN_L, STD_C89, NULL, 0, 0 },
1575 { "z", FMT_LEN_z, STD_C99, NULL, 0, 0 },
1576 { "Z", FMT_LEN_z, STD_EXT, NULL, 0, 0 },
1577 { "t", FMT_LEN_t, STD_C99, NULL, 0, 0 },
1578 { "j", FMT_LEN_j, STD_C99, NULL, 0, 0 },
1579 { NULL, 0, 0, NULL, 0, 0 }
1583 /* This differs from printf_length_specs only in that "Z" is not accepted. */
1584 static const format_length_info scanf_length_specs[] =
1586 { "h", FMT_LEN_h, STD_C89, "hh", FMT_LEN_hh, STD_C99 },
1587 { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C9L },
1588 { "q", FMT_LEN_ll, STD_EXT, NULL, 0, 0 },
1589 { "L", FMT_LEN_L, STD_C89, NULL, 0, 0 },
1590 { "z", FMT_LEN_z, STD_C99, NULL, 0, 0 },
1591 { "t", FMT_LEN_t, STD_C99, NULL, 0, 0 },
1592 { "j", FMT_LEN_j, STD_C99, NULL, 0, 0 },
1593 { NULL, 0, 0, NULL, 0, 0 }
1597 /* All tables for strfmon use STD_C89 everywhere, since -pedantic warnings
1598 make no sense for a format type not part of any C standard version. */
1599 static const format_length_info strfmon_length_specs[] =
1601 /* A GNU extension. */
1602 { "L", FMT_LEN_L, STD_C89, NULL, 0, 0 },
1603 { NULL, 0, 0, NULL, 0, 0 }
1606 static const format_flag_spec printf_flag_specs[] =
1608 { ' ', 0, 0, N_("` ' flag"), N_("the ` ' printf flag"), STD_C89 },
1609 { '+', 0, 0, N_("`+' flag"), N_("the `+' printf flag"), STD_C89 },
1610 { '#', 0, 0, N_("`#' flag"), N_("the `#' printf flag"), STD_C89 },
1611 { '0', 0, 0, N_("`0' flag"), N_("the `0' printf flag"), STD_C89 },
1612 { '-', 0, 0, N_("`-' flag"), N_("the `-' printf flag"), STD_C89 },
1613 { '\'', 0, 0, N_("`'' flag"), N_("the `'' printf flag"), STD_EXT },
1614 { 'I', 0, 0, N_("`I' flag"), N_("the `I' printf flag"), STD_EXT },
1615 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
1616 { 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89 },
1617 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
1618 { 0, 0, 0, NULL, NULL, 0 }
1622 static const format_flag_pair printf_flag_pairs[] =
1626 { '0', 'p', 1, 'i' },
1631 static const format_flag_spec scanf_flag_specs[] =
1633 { '*', 0, 0, N_("assignment suppression"), N_("assignment suppression"), STD_C89 },
1634 { 'a', 0, 0, N_("`a' flag"), N_("the `a' scanf flag"), STD_EXT },
1635 { 'w', 0, 0, N_("field width"), N_("field width in scanf format"), STD_C89 },
1636 { 'L', 0, 0, N_("length modifier"), N_("length modifier in scanf format"), STD_C89 },
1637 { '\'', 0, 0, N_("`'' flag"), N_("the `'' scanf flag"), STD_EXT },
1638 { 'I', 0, 0, N_("`I' flag"), N_("the `I' scanf flag"), STD_EXT },
1639 { 0, 0, 0, NULL, NULL, 0 }
1643 static const format_flag_pair scanf_flag_pairs[] =
1650 static const format_flag_spec strftime_flag_specs[] =
1652 { '_', 0, 0, N_("`_' flag"), N_("the `_' strftime flag"), STD_EXT },
1653 { '-', 0, 0, N_("`-' flag"), N_("the `-' strftime flag"), STD_EXT },
1654 { '0', 0, 0, N_("`0' flag"), N_("the `0' strftime flag"), STD_EXT },
1655 { '^', 0, 0, N_("`^' flag"), N_("the `^' strftime flag"), STD_EXT },
1656 { '#', 0, 0, N_("`#' flag"), N_("the `#' strftime flag"), STD_EXT },
1657 { 'w', 0, 0, N_("field width"), N_("field width in strftime format"), STD_EXT },
1658 { 'E', 0, 0, N_("`E' modifier"), N_("the `E' strftime modifier"), STD_C99 },
1659 { 'O', 0, 0, N_("`O' modifier"), N_("the `O' strftime modifier"), STD_C99 },
1660 { 'O', 'o', 0, NULL, N_("the `O' modifier"), STD_EXT },
1661 { 0, 0, 0, NULL, NULL, 0 }
1665 static const format_flag_pair strftime_flag_pairs[] =
1676 static const format_flag_spec strfmon_flag_specs[] =
1678 { '=', 0, 1, N_("fill character"), N_("fill character in strfmon format"), STD_C89 },
1679 { '^', 0, 0, N_("`^' flag"), N_("the `^' strfmon flag"), STD_C89 },
1680 { '+', 0, 0, N_("`+' flag"), N_("the `+' strfmon flag"), STD_C89 },
1681 { '(', 0, 0, N_("`(' flag"), N_("the `(' strfmon flag"), STD_C89 },
1682 { '!', 0, 0, N_("`!' flag"), N_("the `!' strfmon flag"), STD_C89 },
1683 { '-', 0, 0, N_("`-' flag"), N_("the `-' strfmon flag"), STD_C89 },
1684 { 'w', 0, 0, N_("field width"), N_("field width in strfmon format"), STD_C89 },
1685 { '#', 0, 0, N_("left precision"), N_("left precision in strfmon format"), STD_C89 },
1686 { 'p', 0, 0, N_("right precision"), N_("right precision in strfmon format"), STD_C89 },
1687 { 'L', 0, 0, N_("length modifier"), N_("length modifier in strfmon format"), STD_C89 },
1688 { 0, 0, 0, NULL, NULL, 0 }
1691 static const format_flag_pair strfmon_flag_pairs[] =
1698 #define T_I &integer_type_node
1699 #define T89_I { STD_C89, NULL, T_I }
1700 #define T99_I { STD_C99, NULL, T_I }
1701 #define T_L &long_integer_type_node
1702 #define T89_L { STD_C89, NULL, T_L }
1703 #define T_LL &long_long_integer_type_node
1704 #define T9L_LL { STD_C9L, NULL, T_LL }
1705 #define TEX_LL { STD_EXT, NULL, T_LL }
1706 #define T_S &short_integer_type_node
1707 #define T89_S { STD_C89, NULL, T_S }
1708 #define T_UI &unsigned_type_node
1709 #define T89_UI { STD_C89, NULL, T_UI }
1710 #define T99_UI { STD_C99, NULL, T_UI }
1711 #define T_UL &long_unsigned_type_node
1712 #define T89_UL { STD_C89, NULL, T_UL }
1713 #define T_ULL &long_long_unsigned_type_node
1714 #define T9L_ULL { STD_C9L, NULL, T_ULL }
1715 #define TEX_ULL { STD_EXT, NULL, T_ULL }
1716 #define T_US &short_unsigned_type_node
1717 #define T89_US { STD_C89, NULL, T_US }
1718 #define T_F &float_type_node
1719 #define T89_F { STD_C89, NULL, T_F }
1720 #define T99_F { STD_C99, NULL, T_F }
1721 #define T_D &double_type_node
1722 #define T89_D { STD_C89, NULL, T_D }
1723 #define T99_D { STD_C99, NULL, T_D }
1724 #define T_LD &long_double_type_node
1725 #define T89_LD { STD_C89, NULL, T_LD }
1726 #define T99_LD { STD_C99, NULL, T_LD }
1727 #define T_C &char_type_node
1728 #define T89_C { STD_C89, NULL, T_C }
1729 #define T_SC &signed_char_type_node
1730 #define T99_SC { STD_C99, NULL, T_SC }
1731 #define T_UC &unsigned_char_type_node
1732 #define T99_UC { STD_C99, NULL, T_UC }
1733 #define T_V &void_type_node
1734 #define T89_V { STD_C89, NULL, T_V }
1735 #define T_W &wchar_type_node
1736 #define T94_W { STD_C94, "wchar_t", T_W }
1737 #define TEX_W { STD_EXT, "wchar_t", T_W }
1738 #define T_WI &wint_type_node
1739 #define T94_WI { STD_C94, "wint_t", T_WI }
1740 #define TEX_WI { STD_EXT, "wint_t", T_WI }
1741 #define T_ST &c_size_type_node
1742 #define T99_ST { STD_C99, "size_t", T_ST }
1743 #define T_SST &signed_size_type_node
1744 #define T99_SST { STD_C99, "signed size_t", T_SST }
1745 #define T_PD &ptrdiff_type_node
1746 #define T99_PD { STD_C99, "ptrdiff_t", T_PD }
1747 #define T_UPD &unsigned_ptrdiff_type_node
1748 #define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD }
1749 #define T_IM &intmax_type_node
1750 #define T99_IM { STD_C99, "intmax_t", T_IM }
1751 #define T_UIM &uintmax_type_node
1752 #define T99_UIM { STD_C99, "uintmax_t", T_UIM }
1754 static const format_char_info print_char_table[] =
1756 /* C89 conversion specifiers. */
1757 { "di", 0, STD_C89, { T89_I, T99_SC, T89_S, T89_L, T9L_LL, TEX_LL, T99_SST, T99_PD, T99_IM }, "-wp0 +'I", "i" },
1758 { "oxX", 0, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_ULL, T99_ST, T99_UPD, T99_UIM }, "-wp0#", "i" },
1759 { "u", 0, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_ULL, T99_ST, T99_UPD, T99_UIM }, "-wp0'I", "i" },
1760 { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, T89_LD, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "" },
1761 { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, T89_LD, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "" },
1762 { "c", 0, STD_C89, { T89_I, BADLEN, BADLEN, T94_WI, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w", "" },
1763 { "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR" },
1764 { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w", "c" },
1765 { "n", 1, STD_C89, { T89_I, T99_SC, T89_S, T89_L, T9L_LL, BADLEN, T99_SST, T99_PD, T99_IM }, "", "W" },
1766 /* C99 conversion specifiers. */
1767 { "F", 0, STD_C99, { T99_D, BADLEN, BADLEN, T99_D, BADLEN, T99_LD, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "" },
1768 { "aA", 0, STD_C99, { T99_D, BADLEN, BADLEN, T99_D, BADLEN, T99_LD, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "" },
1769 /* X/Open conversion specifiers. */
1770 { "C", 0, STD_EXT, { TEX_WI, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w", "" },
1771 { "S", 1, STD_EXT, { TEX_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "R" },
1772 /* GNU conversion specifiers. */
1773 { "m", 0, STD_EXT, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "" },
1774 { NULL, 0, 0, NOLENGTHS, NULL, NULL }
1777 static const format_char_info scan_char_table[] =
1779 /* C89 conversion specifiers. */
1780 { "di", 1, STD_C89, { T89_I, T99_SC, T89_S, T89_L, T9L_LL, TEX_LL, T99_SST, T99_PD, T99_IM }, "*w'I", "W" },
1781 { "u", 1, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_ULL, T99_ST, T99_UPD, T99_UIM }, "*w'I", "W" },
1782 { "oxX", 1, STD_C89, { T89_UI, T99_UC, T89_US, T89_UL, T9L_ULL, TEX_ULL, T99_ST, T99_UPD, T99_UIM }, "*w", "W" },
1783 { "efgEG", 1, STD_C89, { T89_F, BADLEN, BADLEN, T89_D, BADLEN, T89_LD, BADLEN, BADLEN, BADLEN }, "*w'", "W" },
1784 { "c", 1, STD_C89, { T89_C, BADLEN, BADLEN, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "cW" },
1785 { "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*aw", "cW" },
1786 { "[", 1, STD_C89, { T89_C, BADLEN, BADLEN, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*aw", "cW[" },
1787 { "p", 2, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "W" },
1788 { "n", 1, STD_C89, { T89_I, T99_SC, T89_S, T89_L, T9L_LL, BADLEN, T99_SST, T99_PD, T99_IM }, "", "W" },
1789 /* C99 conversion specifiers. */
1790 { "FaA", 1, STD_C99, { T99_F, BADLEN, BADLEN, T99_D, BADLEN, T99_LD, BADLEN, BADLEN, BADLEN }, "*w'", "W" },
1791 /* X/Open conversion specifiers. */
1792 { "C", 1, STD_EXT, { TEX_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "W" },
1793 { "S", 1, STD_EXT, { TEX_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*aw", "W" },
1794 { NULL, 0, 0, NOLENGTHS, NULL, NULL }
1797 static const format_char_info time_char_table[] =
1799 /* C89 conversion specifiers. */
1800 { "ABZab", 0, STD_C89, NOLENGTHS, "^#", "" },
1801 { "cx", 0, STD_C89, NOLENGTHS, "E", "3" },
1802 { "HIMSUWdmw", 0, STD_C89, NOLENGTHS, "-_0Ow", "" },
1803 { "j", 0, STD_C89, NOLENGTHS, "-_0Ow", "o" },
1804 { "p", 0, STD_C89, NOLENGTHS, "#", "" },
1805 { "X", 0, STD_C89, NOLENGTHS, "E", "" },
1806 { "y", 0, STD_C89, NOLENGTHS, "EO-_0w", "4" },
1807 { "Y", 0, STD_C89, NOLENGTHS, "-_0EOw", "o" },
1808 { "%", 0, STD_C89, NOLENGTHS, "", "" },
1809 /* C99 conversion specifiers. */
1810 { "C", 0, STD_C99, NOLENGTHS, "-_0EOw", "o" },
1811 { "D", 0, STD_C99, NOLENGTHS, "", "2" },
1812 { "eVu", 0, STD_C99, NOLENGTHS, "-_0Ow", "" },
1813 { "FRTnrt", 0, STD_C99, NOLENGTHS, "", "" },
1814 { "g", 0, STD_C99, NOLENGTHS, "O-_0w", "2o" },
1815 { "G", 0, STD_C99, NOLENGTHS, "-_0Ow", "o" },
1816 { "h", 0, STD_C99, NOLENGTHS, "^#", "" },
1817 { "z", 0, STD_C99, NOLENGTHS, "O", "o" },
1818 /* GNU conversion specifiers. */
1819 { "kls", 0, STD_EXT, NOLENGTHS, "-_0Ow", "" },
1820 { "P", 0, STD_EXT, NOLENGTHS, "", "" },
1821 { NULL, 0, 0, NOLENGTHS, NULL, NULL }
1824 static const format_char_info monetary_char_table[] =
1826 { "in", 0, STD_C89, { T89_D, BADLEN, BADLEN, BADLEN, BADLEN, T89_LD, BADLEN, BADLEN, BADLEN }, "=^+(!-w#p", "" },
1827 { NULL, 0, 0, NOLENGTHS, NULL, NULL }
1831 /* This must be in the same order as enum format_type. */
1832 static const format_kind_info format_types[] =
1834 { "printf", printf_length_specs, print_char_table, " +#0-'I", NULL,
1835 printf_flag_specs, printf_flag_pairs,
1836 FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
1837 'w', 0, 'p', 0, 'L',
1838 &integer_type_node, &integer_type_node
1840 { "scanf", scanf_length_specs, scan_char_table, "*'I", NULL,
1841 scanf_flag_specs, scanf_flag_pairs,
1842 FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD,
1843 'w', 0, 0, '*', 'L',
1846 { "strftime", NULL, time_char_table, "_-0^#", "EO",
1847 strftime_flag_specs, strftime_flag_pairs,
1848 FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0,
1851 { "strfmon", strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
1852 strfmon_flag_specs, strfmon_flag_pairs,
1853 FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L',
1859 typedef struct function_format_info
1861 struct function_format_info *next; /* next structure on the list */
1862 tree name; /* identifier such as "printf" */
1863 tree assembler_name; /* optional mangled identifier (for C++) */
1864 enum format_type format_type; /* type of format (printf, scanf, etc.) */
1865 int format_num; /* number of format argument */
1866 int first_arg_num; /* number of first arg (zero for varargs) */
1867 } function_format_info;
1869 static function_format_info *function_format_list = NULL;
1871 typedef struct international_format_info
1873 struct international_format_info *next; /* next structure on the list */
1874 tree name; /* identifier such as "gettext" */
1875 tree assembler_name; /* optional mangled identifier (for C++) */
1876 int format_num; /* number of format argument */
1877 } international_format_info;
1879 static international_format_info *international_format_list = NULL;
1881 /* Structure detailing the results of checking a format function call
1882 where the format expression may be a conditional expression with
1883 many leaves resulting from nested conditional expressions. */
1886 /* Number of leaves of the format argument that could not be checked
1887 as they were not string literals. */
1888 int number_non_literal;
1889 /* Number of leaves of the format argument that were null pointers or
1890 string literals, but had extra format arguments. */
1891 int number_extra_args;
1892 /* Number of leaves of the format argument that were null pointers or
1893 string literals, but had extra format arguments and used $ operand
1895 int number_dollar_extra_args;
1896 /* Number of leaves of the format argument that were wide string
1899 /* Number of leaves of the format argument that were empty strings. */
1901 /* Number of leaves of the format argument that were unterminated
1903 int number_unterminated;
1904 /* Number of leaves of the format argument that were not counted above. */
1906 } format_check_results;
1908 static void check_format_info PARAMS ((int *, function_format_info *, tree));
1909 static void check_format_info_recurse PARAMS ((int *, format_check_results *,
1910 function_format_info *, tree,
1912 static void check_format_info_main PARAMS ((int *, format_check_results *,
1913 function_format_info *,
1914 const char *, int, tree, int));
1915 static void status_warning PARAMS ((int *, const char *, ...))
1918 static void init_dollar_format_checking PARAMS ((int, tree));
1919 static int maybe_read_dollar_number PARAMS ((int *, const char **, int,
1921 const format_kind_info *));
1922 static void finish_dollar_format_checking PARAMS ((int *, format_check_results *));
1924 static const format_flag_spec *get_flag_spec PARAMS ((const format_flag_spec *,
1925 int, const char *));
1927 static void check_format_types PARAMS ((int *, format_wanted_type *));
1928 static int is_valid_printf_arglist PARAMS ((tree));
1929 static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
1930 static rtx c_expand_builtin_printf PARAMS ((tree, rtx, enum machine_mode,
1931 enum expand_modifier, int));
1933 /* Initialize the table of functions to perform format checking on.
1934 The ISO C functions are always checked (whether <stdio.h> is
1935 included or not), since it is common to call printf without
1936 including <stdio.h>. There shouldn't be a problem with this,
1937 since ISO C reserves these function names whether you include the
1938 header file or not. In any case, the checking is harmless. With
1939 -ffreestanding, these default attributes are disabled, and must be
1940 specified manually if desired.
1942 Also initialize the name of function that modify the format string for
1943 internationalization purposes. */
1946 init_function_format_info ()
1950 /* Functions from ISO/IEC 9899:1990. */
1951 record_function_format (get_identifier ("printf"), NULL_TREE,
1952 printf_format_type, 1, 2);
1953 record_function_format (get_identifier ("__builtin_printf"), NULL_TREE,
1954 printf_format_type, 1, 2);
1955 record_function_format (get_identifier ("fprintf"), NULL_TREE,
1956 printf_format_type, 2, 3);
1957 record_function_format (get_identifier ("sprintf"), NULL_TREE,
1958 printf_format_type, 2, 3);
1959 record_function_format (get_identifier ("scanf"), NULL_TREE,
1960 scanf_format_type, 1, 2);
1961 record_function_format (get_identifier ("fscanf"), NULL_TREE,
1962 scanf_format_type, 2, 3);
1963 record_function_format (get_identifier ("sscanf"), NULL_TREE,
1964 scanf_format_type, 2, 3);
1965 record_function_format (get_identifier ("vprintf"), NULL_TREE,
1966 printf_format_type, 1, 0);
1967 record_function_format (get_identifier ("vfprintf"), NULL_TREE,
1968 printf_format_type, 2, 0);
1969 record_function_format (get_identifier ("vsprintf"), NULL_TREE,
1970 printf_format_type, 2, 0);
1971 record_function_format (get_identifier ("strftime"), NULL_TREE,
1972 strftime_format_type, 3, 0);
1975 if (flag_hosted && flag_isoc99)
1977 /* ISO C99 adds the snprintf and vscanf family functions. */
1978 record_function_format (get_identifier ("snprintf"), NULL_TREE,
1979 printf_format_type, 3, 4);
1980 record_function_format (get_identifier ("vsnprintf"), NULL_TREE,
1981 printf_format_type, 3, 0);
1982 record_function_format (get_identifier ("vscanf"), NULL_TREE,
1983 scanf_format_type, 1, 0);
1984 record_function_format (get_identifier ("vfscanf"), NULL_TREE,
1985 scanf_format_type, 2, 0);
1986 record_function_format (get_identifier ("vsscanf"), NULL_TREE,
1987 scanf_format_type, 2, 0);
1990 if (flag_hosted && flag_noniso_default_format_attributes)
1992 /* Uniforum/GNU gettext functions, not in ISO C. */
1993 record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
1994 record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
1995 record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
1996 /* X/Open strfmon function. */
1997 record_function_format (get_identifier ("strfmon"), NULL_TREE,
1998 strfmon_format_type, 3, 4);
2002 /* Record information for argument format checking. FUNCTION_IDENT is
2003 the identifier node for the name of the function to check (its decl
2004 need not exist yet).
2005 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
2006 of the argument which is the format control string (starting from 1).
2007 FIRST_ARG_NUM is the number of the first actual argument to check
2008 against the format string, or zero if no checking is not be done
2009 (e.g. for varargs such as vfprintf). */
2012 record_function_format (name, assembler_name, format_type,
2013 format_num, first_arg_num)
2015 tree assembler_name;
2016 enum format_type format_type;
2020 function_format_info *info;
2022 /* Re-use existing structure if it's there. */
2024 for (info = function_format_list; info; info = info->next)
2026 if (info->name == name && info->assembler_name == assembler_name)
2031 info = (function_format_info *) xmalloc (sizeof (function_format_info));
2032 info->next = function_format_list;
2033 function_format_list = info;
2036 info->assembler_name = assembler_name;
2039 info->format_type = format_type;
2040 info->format_num = format_num;
2041 info->first_arg_num = first_arg_num;
2044 /* Record information for the names of function that modify the format
2045 argument to format functions. FUNCTION_IDENT is the identifier node for
2046 the name of the function (its decl need not exist yet) and FORMAT_NUM is
2047 the number of the argument which is the format control string (starting
2051 record_international_format (name, assembler_name, format_num)
2053 tree assembler_name;
2056 international_format_info *info;
2058 /* Re-use existing structure if it's there. */
2060 for (info = international_format_list; info; info = info->next)
2062 if (info->name == name && info->assembler_name == assembler_name)
2069 = (international_format_info *)
2070 xmalloc (sizeof (international_format_info));
2071 info->next = international_format_list;
2072 international_format_list = info;
2075 info->assembler_name = assembler_name;
2078 info->format_num = format_num;
2081 /* Check the argument list of a call to printf, scanf, etc.
2082 NAME is the function identifier.
2083 ASSEMBLER_NAME is the function's assembler identifier.
2084 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
2085 PARAMS is the list of argument values. Also, if -Wmissing-format-attribute,
2086 warn for calls to vprintf or vscanf in functions with no such format
2087 attribute themselves. */
2090 check_function_format (status, name, assembler_name, params)
2093 tree assembler_name;
2096 function_format_info *info;
2098 /* See if this function is a format function. */
2099 for (info = function_format_list; info; info = info->next)
2101 if (info->assembler_name
2102 ? (info->assembler_name == assembler_name)
2103 : (info->name == name))
2105 /* Yup; check it. */
2106 check_format_info (status, info, params);
2107 if (warn_missing_format_attribute && info->first_arg_num == 0
2108 && (format_types[info->format_type].flags & FMT_FLAG_ARG_CONVERT))
2110 function_format_info *info2;
2111 for (info2 = function_format_list; info2; info2 = info2->next)
2112 if ((info2->assembler_name
2113 ? (info2->assembler_name == DECL_ASSEMBLER_NAME (current_function_decl))
2114 : (info2->name == DECL_NAME (current_function_decl)))
2115 && info2->format_type == info->format_type)
2119 /* Check if the current function has a parameter to which
2120 the format attribute could be attached; if not, it
2121 can't be a candidate for a format attribute, despite
2122 the vprintf-like or vscanf-like call. */
2124 for (args = DECL_ARGUMENTS (current_function_decl);
2126 args = TREE_CHAIN (args))
2128 if (TREE_CODE (TREE_TYPE (args)) == POINTER_TYPE
2129 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (args)))
2134 warning ("function might be possible candidate for `%s' format attribute",
2135 format_types[info->format_type].name);
2143 /* This function replaces `warning' inside the printf format checking
2144 functions. If the `status' parameter is non-NULL, then it is
2145 dereferenced and set to 1 whenever a warning is caught. Otherwise
2146 it warns as usual by replicating the innards of the warning
2147 function from diagnostic.c. */
2149 status_warning VPARAMS ((int *status, const char *msgid, ...))
2151 #ifndef ANSI_PROTOTYPES
2156 diagnostic_context dc;
2158 VA_START (ap, msgid);
2160 #ifndef ANSI_PROTOTYPES
2161 status = va_arg (ap, int *);
2162 msgid = va_arg (ap, const char *);
2169 /* This duplicates the warning function behavior. */
2170 set_diagnostic_context
2171 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 1);
2172 report_diagnostic (&dc);
2178 /* Variables used by the checking of $ operand number formats. */
2179 static char *dollar_arguments_used = NULL;
2180 static int dollar_arguments_alloc = 0;
2181 static int dollar_arguments_count;
2182 static int dollar_first_arg_num;
2183 static int dollar_max_arg_used;
2184 static int dollar_format_warned;
2186 /* Initialize the checking for a format string that may contain $
2187 parameter number specifications; we will need to keep track of whether
2188 each parameter has been used. FIRST_ARG_NUM is the number of the first
2189 argument that is a parameter to the format, or 0 for a vprintf-style
2190 function; PARAMS is the list of arguments starting at this argument. */
2193 init_dollar_format_checking (first_arg_num, params)
2197 dollar_first_arg_num = first_arg_num;
2198 dollar_arguments_count = 0;
2199 dollar_max_arg_used = 0;
2200 dollar_format_warned = 0;
2201 if (first_arg_num > 0)
2205 dollar_arguments_count++;
2206 params = TREE_CHAIN (params);
2209 if (dollar_arguments_alloc < dollar_arguments_count)
2211 if (dollar_arguments_used)
2212 free (dollar_arguments_used);
2213 dollar_arguments_alloc = dollar_arguments_count;
2214 dollar_arguments_used = xmalloc (dollar_arguments_alloc);
2216 if (dollar_arguments_alloc)
2217 memset (dollar_arguments_used, 0, dollar_arguments_alloc);
2221 /* Look for a decimal number followed by a $ in *FORMAT. If DOLLAR_NEEDED
2222 is set, it is an error if one is not found; otherwise, it is OK. If
2223 such a number is found, check whether it is within range and mark that
2224 numbered operand as being used for later checking. Returns the operand
2225 number if found and within range, zero if no such number was found and
2226 this is OK, or -1 on error. PARAMS points to the first operand of the
2227 format; PARAM_PTR is made to point to the parameter referred to. If
2228 a $ format is found, *FORMAT is updated to point just after it. */
2231 maybe_read_dollar_number (status, format, dollar_needed, params, param_ptr,
2234 const char **format;
2238 const format_kind_info *fki;
2242 const char *fcp = *format;
2243 if (*fcp < '0' || *fcp > '9')
2247 status_warning (status, "missing $ operand number in format");
2255 while (*fcp >= '0' && *fcp <= '9')
2258 nargnum = 10 * argnum + (*fcp - '0');
2259 if (nargnum < 0 || nargnum / 10 != argnum)
2268 status_warning (status, "missing $ operand number in format");
2275 if (pedantic && !dollar_format_warned)
2277 status_warning (status,
2278 "%s does not support %%n$ operand number formats",
2279 C_STD_NAME (STD_EXT));
2280 dollar_format_warned = 1;
2282 if (overflow_flag || argnum == 0
2283 || (dollar_first_arg_num && argnum > dollar_arguments_count))
2285 status_warning (status, "operand number out of range in format");
2288 if (argnum > dollar_max_arg_used)
2289 dollar_max_arg_used = argnum;
2290 /* For vprintf-style functions we may need to allocate more memory to
2291 track which arguments are used. */
2292 while (dollar_arguments_alloc < dollar_max_arg_used)
2295 nalloc = 2 * dollar_arguments_alloc + 16;
2296 dollar_arguments_used = xrealloc (dollar_arguments_used, nalloc);
2297 memset (dollar_arguments_used + dollar_arguments_alloc, 0,
2298 nalloc - dollar_arguments_alloc);
2299 dollar_arguments_alloc = nalloc;
2301 if (!(fki->flags & FMT_FLAG_DOLLAR_MULTIPLE)
2302 && dollar_arguments_used[argnum - 1] == 1)
2304 dollar_arguments_used[argnum - 1] = 2;
2305 status_warning (status,
2306 "format argument %d used more than once in %s format",
2310 dollar_arguments_used[argnum - 1] = 1;
2311 if (dollar_first_arg_num)
2314 *param_ptr = params;
2315 for (i = 1; i < argnum && *param_ptr != 0; i++)
2316 *param_ptr = TREE_CHAIN (*param_ptr);
2318 if (*param_ptr == 0)
2320 /* This case shouldn't be caught here. */
2330 /* Finish the checking for a format string that used $ operand number formats
2331 instead of non-$ formats. We check for unused operands before used ones
2332 (a serious error, since the implementation of the format function
2333 can't know what types to pass to va_arg to find the later arguments).
2334 and for unused operands at the end of the format (if we know how many
2335 arguments the format had, so not for vprintf). If there were operand
2336 numbers out of range on a non-vprintf-style format, we won't have reached
2340 finish_dollar_format_checking (status, res)
2342 format_check_results *res;
2345 for (i = 0; i < dollar_max_arg_used; i++)
2347 if (!dollar_arguments_used[i])
2348 status_warning (status, "format argument %d unused before used argument %d in $-style format",
2349 i + 1, dollar_max_arg_used);
2351 if (dollar_first_arg_num && dollar_max_arg_used < dollar_arguments_count)
2353 res->number_other--;
2354 res->number_dollar_extra_args++;
2359 /* Retrieve the specification for a format flag. SPEC contains the
2360 specifications for format flags for the applicable kind of format.
2361 FLAG is the flag in question. If PREDICATES is NULL, the basic
2362 spec for that flag must be retrieved and this function aborts if
2363 it cannot be found. If PREDICATES is not NULL, it is a string listing
2364 possible predicates for the spec entry; if an entry predicated on any
2365 of these is found, it is returned, otherwise NULL is returned. */
2367 static const format_flag_spec *
2368 get_flag_spec (spec, flag, predicates)
2369 const format_flag_spec *spec;
2371 const char *predicates;
2374 for (i = 0; spec[i].flag_char != 0; i++)
2376 if (spec[i].flag_char != flag)
2378 if (predicates != NULL)
2380 if (spec[i].predicate != 0
2381 && strchr (predicates, spec[i].predicate) != 0)
2384 else if (spec[i].predicate == 0)
2387 if (predicates == NULL)
2394 /* Check the argument list of a call to printf, scanf, etc.
2395 INFO points to the function_format_info structure.
2396 PARAMS is the list of argument values. */
2399 check_format_info (status, info, params)
2401 function_format_info *info;
2406 format_check_results res;
2407 /* Skip to format argument. If the argument isn't available, there's
2408 no work for us to do; prototype checking will catch the problem. */
2409 for (arg_num = 1; ; ++arg_num)
2413 if (arg_num == info->format_num)
2415 params = TREE_CHAIN (params);
2417 format_tree = TREE_VALUE (params);
2418 params = TREE_CHAIN (params);
2419 if (format_tree == 0)
2422 res.number_non_literal = 0;
2423 res.number_extra_args = 0;
2424 res.number_dollar_extra_args = 0;
2425 res.number_wide = 0;
2426 res.number_empty = 0;
2427 res.number_unterminated = 0;
2428 res.number_other = 0;
2430 check_format_info_recurse (status, &res, info, format_tree, params, arg_num);
2432 if (res.number_non_literal > 0)
2434 /* Functions taking a va_list normally pass a non-literal format
2435 string. These functions typically are declared with
2436 first_arg_num == 0, so avoid warning in those cases. */
2437 if (!(format_types[info->format_type].flags & FMT_FLAG_ARG_CONVERT))
2439 /* For strftime-like formats, warn for not checking the format
2440 string; but there are no arguments to check. */
2441 if (warn_format_nonliteral)
2442 status_warning (status, "format not a string literal, format string not checked");
2444 else if (info->first_arg_num != 0)
2446 /* If there are no arguments for the format at all, we may have
2447 printf (foo) which is likely to be a security hole. */
2448 while (arg_num + 1 < info->first_arg_num)
2452 params = TREE_CHAIN (params);
2455 if (params == 0 && (warn_format_nonliteral || warn_format_security))
2456 status_warning (status, "format not a string literal and no format arguments");
2457 else if (warn_format_nonliteral)
2458 status_warning (status, "format not a string literal, argument types not checked");
2462 /* If there were extra arguments to the format, normally warn. However,
2463 the standard does say extra arguments are ignored, so in the specific
2464 case where we have multiple leaves (conditional expressions or
2465 ngettext) allow extra arguments if at least one leaf didn't have extra
2466 arguments, but was otherwise OK (either non-literal or checked OK).
2467 If the format is an empty string, this should be counted similarly to the
2468 case of extra format arguments. */
2469 if (res.number_extra_args > 0 && res.number_non_literal == 0
2470 && res.number_other == 0 && warn_format_extra_args)
2471 status_warning (status, "too many arguments for format");
2472 if (res.number_dollar_extra_args > 0 && res.number_non_literal == 0
2473 && res.number_other == 0 && warn_format_extra_args)
2474 status_warning (status, "unused arguments in $-style format");
2475 if (res.number_empty > 0 && res.number_non_literal == 0
2476 && res.number_other == 0)
2477 status_warning (status, "zero-length format string");
2479 if (res.number_wide > 0)
2480 status_warning (status, "format is a wide character string");
2482 if (res.number_unterminated > 0)
2483 status_warning (status, "unterminated format string");
2487 /* Recursively check a call to a format function. FORMAT_TREE is the
2488 format parameter, which may be a conditional expression in which
2489 both halves should be checked. ARG_NUM is the number of the
2490 format argument; PARAMS points just after it in the argument list. */
2493 check_format_info_recurse (status, res, info, format_tree, params, arg_num)
2495 format_check_results *res;
2496 function_format_info *info;
2502 const char *format_chars;
2503 tree array_size = 0;
2506 if (TREE_CODE (format_tree) == NOP_EXPR)
2508 /* Strip coercion. */
2509 check_format_info_recurse (status, res, info,
2510 TREE_OPERAND (format_tree, 0), params,
2515 if (TREE_CODE (format_tree) == CALL_EXPR
2516 && TREE_CODE (TREE_OPERAND (format_tree, 0)) == ADDR_EXPR
2517 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0))
2520 tree function = TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0);
2522 /* See if this is a call to a known internationalization function
2523 that modifies the format arg. */
2524 international_format_info *iinfo;
2526 for (iinfo = international_format_list; iinfo; iinfo = iinfo->next)
2527 if (iinfo->assembler_name
2528 ? (iinfo->assembler_name == DECL_ASSEMBLER_NAME (function))
2529 : (iinfo->name == DECL_NAME (function)))
2534 for (inner_args = TREE_OPERAND (format_tree, 1), i = 1;
2536 inner_args = TREE_CHAIN (inner_args), i++)
2537 if (i == iinfo->format_num)
2539 /* FIXME: with Marc Espie's __attribute__((nonnull))
2540 patch in GCC, we will have chained attributes,
2541 and be able to handle functions like ngettext
2542 with multiple format_arg attributes properly. */
2543 check_format_info_recurse (status, res, info,
2544 TREE_VALUE (inner_args), params,
2551 if (TREE_CODE (format_tree) == COND_EXPR)
2553 /* Check both halves of the conditional expression. */
2554 check_format_info_recurse (status, res, info,
2555 TREE_OPERAND (format_tree, 1), params,
2557 check_format_info_recurse (status, res, info,
2558 TREE_OPERAND (format_tree, 2), params,
2563 if (integer_zerop (format_tree))
2565 /* FIXME: this warning should go away once Marc Espie's
2566 __attribute__((nonnull)) patch is in. Instead, checking for
2567 nonnull attributes should probably change this function to act
2568 specially if info == NULL and add a res->number_null entry for
2569 that case, or maybe add a function pointer to be called at
2570 the end instead of hardcoding check_format_info_main. */
2571 status_warning (status, "null format string");
2573 /* Skip to first argument to check, so we can see if this format
2574 has any arguments (it shouldn't). */
2575 while (arg_num + 1 < info->first_arg_num)
2579 params = TREE_CHAIN (params);
2584 res->number_other++;
2586 res->number_extra_args++;
2591 if (TREE_CODE (format_tree) != ADDR_EXPR)
2593 res->number_non_literal++;
2596 format_tree = TREE_OPERAND (format_tree, 0);
2597 if (TREE_CODE (format_tree) == VAR_DECL
2598 && TREE_CODE (TREE_TYPE (format_tree)) == ARRAY_TYPE
2599 && (array_init = decl_constant_value (format_tree)) != format_tree
2600 && TREE_CODE (array_init) == STRING_CST)
2602 /* Extract the string constant initializer. Note that this may include
2603 a trailing NUL character that is not in the array (e.g.
2604 const char a[3] = "foo";). */
2605 array_size = DECL_SIZE_UNIT (format_tree);
2606 format_tree = array_init;
2608 if (TREE_CODE (format_tree) != STRING_CST)
2610 res->number_non_literal++;
2613 if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (format_tree))) != char_type_node)
2618 format_chars = TREE_STRING_POINTER (format_tree);
2619 format_length = TREE_STRING_LENGTH (format_tree);
2620 if (array_size != 0)
2622 /* Variable length arrays can't be initialized. */
2623 if (TREE_CODE (array_size) != INTEGER_CST)
2625 if (host_integerp (array_size, 0))
2627 HOST_WIDE_INT array_size_value = TREE_INT_CST_LOW (array_size);
2628 if (array_size_value > 0
2629 && array_size_value == (int) array_size_value
2630 && format_length > array_size_value)
2631 format_length = array_size_value;
2634 if (format_length < 1)
2636 res->number_unterminated++;
2639 if (format_length == 1)
2641 res->number_empty++;
2644 if (format_chars[--format_length] != 0)
2646 res->number_unterminated++;
2650 /* Skip to first argument to check. */
2651 while (arg_num + 1 < info->first_arg_num)
2655 params = TREE_CHAIN (params);
2658 /* Provisionally increment res->number_other; check_format_info_main
2659 will decrement it if it finds there are extra arguments, but this way
2660 need not adjust it for every return. */
2661 res->number_other++;
2662 check_format_info_main (status, res, info, format_chars, format_length,
2667 /* Do the main part of checking a call to a format function. FORMAT_CHARS
2668 is the NUL-terminated format string (which at this point may contain
2669 internal NUL characters); FORMAT_LENGTH is its length (excluding the
2670 terminating NUL character). ARG_NUM is one less than the number of
2671 the first format argument to check; PARAMS points to that format
2672 argument in the list of arguments. */
2675 check_format_info_main (status, res, info, format_chars, format_length,
2678 format_check_results *res;
2679 function_format_info *info;
2680 const char *format_chars;
2685 const char *orig_format_chars = format_chars;
2686 tree first_fillin_param = params;
2688 const format_kind_info *fki = &format_types[info->format_type];
2689 const format_flag_spec *flag_specs = fki->flag_specs;
2690 const format_flag_pair *bad_flag_pairs = fki->bad_flag_pairs;
2692 /* -1 if no conversions taking an operand have been found; 0 if one has
2693 and it didn't use $; 1 if $ formats are in use. */
2694 int has_operand_number = -1;
2696 init_dollar_format_checking (info->first_arg_num, first_fillin_param);
2701 int suppressed = FALSE;
2702 const char *length_chars = NULL;
2703 enum format_lengths length_chars_val = FMT_LEN_none;
2704 enum format_std_version length_chars_std = STD_C89;
2708 int main_arg_num = 0;
2709 tree main_arg_params = 0;
2710 enum format_std_version wanted_type_std;
2711 const char *wanted_type_name;
2712 format_wanted_type width_wanted_type;
2713 format_wanted_type precision_wanted_type;
2714 format_wanted_type main_wanted_type;
2715 format_wanted_type *first_wanted_type = NULL;
2716 format_wanted_type *last_wanted_type = NULL;
2717 const format_length_info *fli = NULL;
2718 const format_char_info *fci = NULL;
2719 char flag_chars[256];
2721 if (*format_chars == 0)
2723 if (format_chars - orig_format_chars != format_length)
2724 status_warning (status, "embedded `\\0' in format");
2725 if (info->first_arg_num != 0 && params != 0
2726 && has_operand_number <= 0)
2728 res->number_other--;
2729 res->number_extra_args++;
2731 if (has_operand_number > 0)
2732 finish_dollar_format_checking (status, res);
2735 if (*format_chars++ != '%')
2737 if (*format_chars == 0)
2739 status_warning (status, "spurious trailing `%%' in format");
2742 if (*format_chars == '%')
2749 if ((fki->flags & FMT_FLAG_USE_DOLLAR) && has_operand_number != 0)
2751 /* Possibly read a $ operand number at the start of the format.
2752 If one was previously used, one is required here. If one
2753 is not used here, we can't immediately conclude this is a
2754 format without them, since it could be printf %m or scanf %*. */
2756 opnum = maybe_read_dollar_number (status, &format_chars, 0,
2758 &main_arg_params, fki);
2763 has_operand_number = 1;
2764 main_arg_num = opnum + info->first_arg_num - 1;
2768 /* Read any format flags, but do not yet validate them beyond removing
2769 duplicates, since in general validation depends on the rest of
2771 while (*format_chars != 0
2772 && strchr (fki->flag_chars, *format_chars) != 0)
2774 const format_flag_spec *s = get_flag_spec (flag_specs,
2775 *format_chars, NULL);
2776 if (strchr (flag_chars, *format_chars) != 0)
2778 status_warning (status, "repeated %s in format", _(s->name));
2782 i = strlen (flag_chars);
2783 flag_chars[i++] = *format_chars;
2786 if (s->skip_next_char)
2789 if (*format_chars == 0)
2791 status_warning (status, "missing fill character at end of strfmon format");
2798 /* Read any format width, possibly * or *m$. */
2799 if (fki->width_char != 0)
2801 if (fki->width_type != NULL && *format_chars == '*')
2803 i = strlen (flag_chars);
2804 flag_chars[i++] = fki->width_char;
2806 /* "...a field width...may be indicated by an asterisk.
2807 In this case, an int argument supplies the field width..." */
2811 status_warning (status, "too few arguments for format");
2814 if (has_operand_number != 0)
2817 opnum = maybe_read_dollar_number (status, &format_chars,
2818 has_operand_number == 1,
2825 has_operand_number = 1;
2826 arg_num = opnum + info->first_arg_num - 1;
2829 has_operand_number = 0;
2831 if (info->first_arg_num != 0)
2833 cur_param = TREE_VALUE (params);
2834 if (has_operand_number <= 0)
2836 params = TREE_CHAIN (params);
2839 width_wanted_type.wanted_type = *fki->width_type;
2840 width_wanted_type.wanted_type_name = NULL;
2841 width_wanted_type.pointer_count = 0;
2842 width_wanted_type.char_lenient_flag = 0;
2843 width_wanted_type.writing_in_flag = 0;
2844 width_wanted_type.reading_from_flag = 0;
2845 width_wanted_type.name = _("field width");
2846 width_wanted_type.param = cur_param;
2847 width_wanted_type.arg_num = arg_num;
2848 width_wanted_type.next = NULL;
2849 if (last_wanted_type != 0)
2850 last_wanted_type->next = &width_wanted_type;
2851 if (first_wanted_type == 0)
2852 first_wanted_type = &width_wanted_type;
2853 last_wanted_type = &width_wanted_type;
2858 /* Possibly read a numeric width. If the width is zero,
2859 we complain if appropriate. */
2860 int non_zero_width_char = FALSE;
2861 int found_width = FALSE;
2862 while (ISDIGIT (*format_chars))
2865 if (*format_chars != '0')
2866 non_zero_width_char = TRUE;
2869 if (found_width && !non_zero_width_char &&
2870 (fki->flags & FMT_FLAG_ZERO_WIDTH_BAD))
2871 status_warning (status, "zero width in %s format",
2875 i = strlen (flag_chars);
2876 flag_chars[i++] = fki->width_char;
2882 /* Read any format left precision (must be a number, not *). */
2883 if (fki->left_precision_char != 0 && *format_chars == '#')
2886 i = strlen (flag_chars);
2887 flag_chars[i++] = fki->left_precision_char;
2889 if (!ISDIGIT (*format_chars))
2890 status_warning (status, "empty left precision in %s format",
2892 while (ISDIGIT (*format_chars))
2896 /* Read any format precision, possibly * or *m$. */
2897 if (fki->precision_char != 0 && *format_chars == '.')
2900 i = strlen (flag_chars);
2901 flag_chars[i++] = fki->precision_char;
2903 if (fki->precision_type != NULL && *format_chars == '*')
2905 /* "...a...precision...may be indicated by an asterisk.
2906 In this case, an int argument supplies the...precision." */
2908 if (has_operand_number != 0)
2911 opnum = maybe_read_dollar_number (status, &format_chars,
2912 has_operand_number == 1,
2919 has_operand_number = 1;
2920 arg_num = opnum + info->first_arg_num - 1;
2923 has_operand_number = 0;
2925 if (info->first_arg_num != 0)
2929 status_warning (status, "too few arguments for format");
2932 cur_param = TREE_VALUE (params);
2933 if (has_operand_number <= 0)
2935 params = TREE_CHAIN (params);
2938 precision_wanted_type.wanted_type = *fki->precision_type;
2939 precision_wanted_type.wanted_type_name = NULL;
2940 precision_wanted_type.pointer_count = 0;
2941 precision_wanted_type.char_lenient_flag = 0;
2942 precision_wanted_type.writing_in_flag = 0;
2943 precision_wanted_type.reading_from_flag = 0;
2944 precision_wanted_type.name = _("field precision");
2945 precision_wanted_type.param = cur_param;
2946 precision_wanted_type.arg_num = arg_num;
2947 precision_wanted_type.next = NULL;
2948 if (last_wanted_type != 0)
2949 last_wanted_type->next = &precision_wanted_type;
2950 if (first_wanted_type == 0)
2951 first_wanted_type = &precision_wanted_type;
2952 last_wanted_type = &precision_wanted_type;
2957 if (!(fki->flags & FMT_FLAG_EMPTY_PREC_OK)
2958 && !ISDIGIT (*format_chars))
2959 status_warning (status, "empty precision in %s format",
2961 while (ISDIGIT (*format_chars))
2966 /* Read any length modifier, if this kind of format has them. */
2967 fli = fki->length_char_specs;
2968 length_chars = NULL;
2969 length_chars_val = FMT_LEN_none;
2970 length_chars_std = STD_C89;
2973 while (fli->name != 0 && fli->name[0] != *format_chars)
2978 if (fli->double_name != 0 && fli->name[0] == *format_chars)
2981 length_chars = fli->double_name;
2982 length_chars_val = fli->double_index;
2983 length_chars_std = fli->double_std;
2987 length_chars = fli->name;
2988 length_chars_val = fli->index;
2989 length_chars_std = fli->std;
2991 i = strlen (flag_chars);
2992 flag_chars[i++] = fki->length_code_char;
2997 /* Warn if the length modifier is non-standard. */
2998 if (ADJ_STD (length_chars_std) > C_STD_VER)
2999 status_warning (status, "%s does not support the `%s' %s length modifier",
3000 C_STD_NAME (length_chars_std), length_chars,
3005 /* Read any modifier (strftime E/O). */
3006 if (fki->modifier_chars != NULL)
3008 while (*format_chars != 0
3009 && strchr (fki->modifier_chars, *format_chars) != 0)
3011 if (strchr (flag_chars, *format_chars) != 0)
3013 const format_flag_spec *s = get_flag_spec (flag_specs,
3014 *format_chars, NULL);
3015 status_warning (status, "repeated %s in format", _(s->name));
3019 i = strlen (flag_chars);
3020 flag_chars[i++] = *format_chars;
3027 /* Handle the scanf allocation kludge. */
3028 if (fki->flags & FMT_FLAG_SCANF_A_KLUDGE)
3030 if (*format_chars == 'a' && !flag_isoc99)
3032 if (format_chars[1] == 's' || format_chars[1] == 'S'
3033 || format_chars[1] == '[')
3035 /* `a' is used as a flag. */
3036 i = strlen (flag_chars);
3037 flag_chars[i++] = 'a';
3044 format_char = *format_chars;
3045 if (format_char == 0
3046 || (!(fki->flags & FMT_FLAG_FANCY_PERCENT_OK) && format_char == '%'))
3048 status_warning (status, "conversion lacks type at end of format");
3052 fci = fki->conversion_specs;
3053 while (fci->format_chars != 0
3054 && strchr (fci->format_chars, format_char) == 0)
3056 if (fci->format_chars == 0)
3058 if (ISGRAPH(format_char))
3059 status_warning (status, "unknown conversion type character `%c' in format",
3062 status_warning (status, "unknown conversion type character 0x%x in format",
3068 if (ADJ_STD (fci->std) > C_STD_VER)
3069 status_warning (status, "%s does not support the `%%%c' %s format",
3070 C_STD_NAME (fci->std), format_char, fki->name);
3073 /* Validate the individual flags used, removing any that are invalid. */
3076 for (i = 0; flag_chars[i] != 0; i++)
3078 const format_flag_spec *s = get_flag_spec (flag_specs,
3079 flag_chars[i], NULL);
3080 flag_chars[i - d] = flag_chars[i];
3081 if (flag_chars[i] == fki->length_code_char)
3083 if (strchr (fci->flag_chars, flag_chars[i]) == 0)
3085 status_warning (status, "%s used with `%%%c' %s format",
3086 _(s->name), format_char, fki->name);
3092 const format_flag_spec *t;
3093 if (ADJ_STD (s->std) > C_STD_VER)
3094 status_warning (status, "%s does not support %s",
3095 C_STD_NAME (s->std), _(s->long_name));
3096 t = get_flag_spec (flag_specs, flag_chars[i], fci->flags2);
3097 if (t != NULL && ADJ_STD (t->std) > ADJ_STD (s->std))
3099 const char *long_name = (t->long_name != NULL
3102 if (ADJ_STD (t->std) > C_STD_VER)
3103 status_warning (status, "%s does not support %s with the `%%%c' %s format",
3104 C_STD_NAME (t->std), _(long_name),
3105 format_char, fki->name);
3109 flag_chars[i - d] = 0;
3112 if ((fki->flags & FMT_FLAG_SCANF_A_KLUDGE)
3113 && strchr (flag_chars, 'a') != 0)
3116 if (fki->suppression_char
3117 && strchr (flag_chars, fki->suppression_char) != 0)
3120 /* Validate the pairs of flags used. */
3121 for (i = 0; bad_flag_pairs[i].flag_char1 != 0; i++)
3123 const format_flag_spec *s, *t;
3124 if (strchr (flag_chars, bad_flag_pairs[i].flag_char1) == 0)
3126 if (strchr (flag_chars, bad_flag_pairs[i].flag_char2) == 0)
3128 if (bad_flag_pairs[i].predicate != 0
3129 && strchr (fci->flags2, bad_flag_pairs[i].predicate) == 0)
3131 s = get_flag_spec (flag_specs, bad_flag_pairs[i].flag_char1, NULL);
3132 t = get_flag_spec (flag_specs, bad_flag_pairs[i].flag_char2, NULL);
3133 if (bad_flag_pairs[i].ignored)
3135 if (bad_flag_pairs[i].predicate != 0)
3136 status_warning (status, "%s ignored with %s and `%%%c' %s format",
3137 _(s->name), _(t->name), format_char,
3140 status_warning (status, "%s ignored with %s in %s format",
3141 _(s->name), _(t->name), fki->name);
3145 if (bad_flag_pairs[i].predicate != 0)
3146 status_warning (status, "use of %s and %s together with `%%%c' %s format",
3147 _(s->name), _(t->name), format_char,
3150 status_warning (status, "use of %s and %s together in %s format",
3151 _(s->name), _(t->name), fki->name);
3155 /* Give Y2K warnings. */
3156 if (warn_format_y2k)
3159 if (strchr (fci->flags2, '4') != 0)
3160 if (strchr (flag_chars, 'E') != 0)
3164 else if (strchr (fci->flags2, '3') != 0)
3166 else if (strchr (fci->flags2, '2') != 0)
3169 status_warning (status, "`%%%c' yields only last 2 digits of year in some locales",
3171 else if (y2k_level == 2)
3172 status_warning (status, "`%%%c' yields only last 2 digits of year", format_char);
3175 if (strchr (fci->flags2, '[') != 0)
3177 /* Skip over scan set, in case it happens to have '%' in it. */
3178 if (*format_chars == '^')
3180 /* Find closing bracket; if one is hit immediately, then
3181 it's part of the scan set rather than a terminator. */
3182 if (*format_chars == ']')
3184 while (*format_chars && *format_chars != ']')
3186 if (*format_chars != ']')
3187 /* The end of the format string was reached. */
3188 status_warning (status, "no closing `]' for `%%[' format");
3192 wanted_type_name = 0;
3193 if (fki->flags & FMT_FLAG_ARG_CONVERT)
3195 wanted_type = (fci->types[length_chars_val].type
3196 ? *fci->types[length_chars_val].type : 0);
3197 wanted_type_name = fci->types[length_chars_val].name;
3198 wanted_type_std = fci->types[length_chars_val].std;
3199 if (wanted_type == 0)
3201 status_warning (status, "use of `%s' length modifier with `%c' type character",
3202 length_chars, format_char);
3203 /* Heuristic: skip one argument when an invalid length/type
3204 combination is encountered. */
3208 status_warning (status, "too few arguments for format");
3211 params = TREE_CHAIN (params);
3215 /* Warn if non-standard, provided it is more non-standard
3216 than the length and type characters that may already
3217 have been warned for. */
3218 && ADJ_STD (wanted_type_std) > ADJ_STD (length_chars_std)
3219 && ADJ_STD (wanted_type_std) > ADJ_STD (fci->std))
3221 if (ADJ_STD (wanted_type_std) > C_STD_VER)
3222 status_warning (status, "%s does not support the `%%%s%c' %s format",
3223 C_STD_NAME (wanted_type_std), length_chars,
3224 format_char, fki->name);
3228 /* Finally. . .check type of argument against desired type! */
3229 if (info->first_arg_num == 0)
3231 if ((fci->pointer_count == 0 && wanted_type == void_type_node)
3234 if (main_arg_num != 0)
3237 status_warning (status, "operand number specified with suppressed assignment");
3239 status_warning (status, "operand number specified for format taking no argument");
3244 if (main_arg_num != 0)
3246 arg_num = main_arg_num;
3247 params = main_arg_params;
3252 if (has_operand_number > 0)
3254 status_warning (status, "missing $ operand number in format");
3258 has_operand_number = 0;
3261 status_warning (status, "too few arguments for format");
3265 cur_param = TREE_VALUE (params);
3266 params = TREE_CHAIN (params);
3267 main_wanted_type.wanted_type = wanted_type;
3268 main_wanted_type.wanted_type_name = wanted_type_name;
3269 main_wanted_type.pointer_count = fci->pointer_count + aflag;
3270 main_wanted_type.char_lenient_flag = 0;
3271 if (strchr (fci->flags2, 'c') != 0)
3272 main_wanted_type.char_lenient_flag = 1;
3273 main_wanted_type.writing_in_flag = 0;
3274 main_wanted_type.reading_from_flag = 0;
3276 main_wanted_type.writing_in_flag = 1;
3279 if (strchr (fci->flags2, 'W') != 0)
3280 main_wanted_type.writing_in_flag = 1;
3281 if (strchr (fci->flags2, 'R') != 0)
3282 main_wanted_type.reading_from_flag = 1;
3284 main_wanted_type.name = NULL;
3285 main_wanted_type.param = cur_param;
3286 main_wanted_type.arg_num = arg_num;
3287 main_wanted_type.next = NULL;
3288 if (last_wanted_type != 0)
3289 last_wanted_type->next = &main_wanted_type;
3290 if (first_wanted_type == 0)
3291 first_wanted_type = &main_wanted_type;
3292 last_wanted_type = &main_wanted_type;
3295 if (first_wanted_type != 0)
3296 check_format_types (status, first_wanted_type);
3302 /* Check the argument types from a single format conversion (possibly
3303 including width and precision arguments). */
3305 check_format_types (status, types)
3307 format_wanted_type *types;
3309 for (; types != 0; types = types->next)
3319 cur_param = types->param;
3320 cur_type = TREE_TYPE (cur_param);
3321 if (cur_type == error_mark_node)
3324 wanted_type = types->wanted_type;
3325 arg_num = types->arg_num;
3327 /* The following should not occur here. */
3328 if (wanted_type == 0)
3330 if (wanted_type == void_type_node && types->pointer_count == 0)
3333 if (types->pointer_count == 0)
3335 promoted_type = simple_type_promotes_to (wanted_type);
3336 if (promoted_type != NULL_TREE)
3337 wanted_type = promoted_type;
3340 STRIP_NOPS (cur_param);
3342 /* Check the types of any additional pointer arguments
3343 that precede the "real" argument. */
3344 for (i = 0; i < types->pointer_count; ++i)
3346 if (TREE_CODE (cur_type) == POINTER_TYPE)
3348 cur_type = TREE_TYPE (cur_type);
3349 if (cur_type == error_mark_node)
3352 /* Check for writing through a NULL pointer. */
3353 if (types->writing_in_flag
3356 && integer_zerop (cur_param))
3357 status_warning (status,
3358 "writing through null pointer (arg %d)",
3361 /* Check for reading through a NULL pointer. */
3362 if (types->reading_from_flag
3365 && integer_zerop (cur_param))
3366 status_warning (status,
3367 "reading through null pointer (arg %d)",
3370 if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
3371 cur_param = TREE_OPERAND (cur_param, 0);
3375 /* See if this is an attempt to write into a const type with
3376 scanf or with printf "%n". Note: the writing in happens
3377 at the first indirection only, if for example
3378 void * const * is passed to scanf %p; passing
3379 const void ** is simply passing an incompatible type. */
3380 if (types->writing_in_flag
3382 && (TYPE_READONLY (cur_type)
3384 && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
3385 || (DECL_P (cur_param)
3386 && TREE_READONLY (cur_param))))))
3387 status_warning (status, "writing into constant object (arg %d)", arg_num);
3389 /* If there are extra type qualifiers beyond the first
3390 indirection, then this makes the types technically
3394 && (TYPE_READONLY (cur_type)
3395 || TYPE_VOLATILE (cur_type)
3396 || TYPE_RESTRICT (cur_type)))
3397 status_warning (status, "extra type qualifiers in format argument (arg %d)",
3403 if (types->pointer_count == 1)
3404 status_warning (status, "format argument is not a pointer (arg %d)", arg_num);
3406 status_warning (status, "format argument is not a pointer to a pointer (arg %d)", arg_num);
3411 if (i < types->pointer_count)
3414 orig_cur_type = cur_type;
3415 cur_type = TYPE_MAIN_VARIANT (cur_type);
3417 /* Check whether the argument type is a character type. This leniency
3418 only applies to certain formats, flagged with 'c'.
3420 if (types->char_lenient_flag)
3421 char_type_flag = (cur_type == char_type_node
3422 || cur_type == signed_char_type_node
3423 || cur_type == unsigned_char_type_node);
3425 /* Check the type of the "real" argument, if there's a type we want. */
3426 if (wanted_type == cur_type)
3428 /* If we want `void *', allow any pointer type.
3429 (Anything else would already have got a warning.)
3430 With -pedantic, only allow pointers to void and to character
3432 if (wanted_type == void_type_node
3433 && (!pedantic || (i == 1 && char_type_flag)))
3435 /* Don't warn about differences merely in signedness, unless
3436 -pedantic. With -pedantic, warn if the type is a pointer
3437 target and not a character type, and for character types at
3438 a second level of indirection. */
3439 if (TREE_CODE (wanted_type) == INTEGER_TYPE
3440 && TREE_CODE (cur_type) == INTEGER_TYPE
3441 && (! pedantic || i == 0 || (i == 1 && char_type_flag))
3442 && (TREE_UNSIGNED (wanted_type)
3443 ? wanted_type == unsigned_type (cur_type)
3444 : wanted_type == signed_type (cur_type)))
3446 /* Likewise, "signed char", "unsigned char" and "char" are
3447 equivalent but the above test won't consider them equivalent. */
3448 if (wanted_type == char_type_node
3449 && (! pedantic || i < 2)
3452 /* Now we have a type mismatch. */
3454 register const char *this;
3455 register const char *that;
3457 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
3459 if (TYPE_NAME (orig_cur_type) != 0
3460 && TREE_CODE (orig_cur_type) != INTEGER_TYPE
3461 && !(TREE_CODE (orig_cur_type) == POINTER_TYPE
3462 && TREE_CODE (TREE_TYPE (orig_cur_type)) == INTEGER_TYPE))
3464 if (TREE_CODE (TYPE_NAME (orig_cur_type)) == TYPE_DECL
3465 && DECL_NAME (TYPE_NAME (orig_cur_type)) != 0)
3466 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (orig_cur_type)));
3468 that = IDENTIFIER_POINTER (TYPE_NAME (orig_cur_type));
3471 /* A nameless type can't possibly match what the format wants.
3472 So there will be a warning for it.
3473 Make up a string to describe vaguely what it is. */
3476 if (TREE_CODE (orig_cur_type) == POINTER_TYPE)
3479 that = "different type";
3482 /* Make the warning better in case of mismatch of int vs long. */
3483 if (TREE_CODE (orig_cur_type) == INTEGER_TYPE
3484 && TREE_CODE (wanted_type) == INTEGER_TYPE
3485 && TYPE_PRECISION (orig_cur_type) == TYPE_PRECISION (wanted_type)
3486 && TYPE_NAME (orig_cur_type) != 0
3487 && TREE_CODE (TYPE_NAME (orig_cur_type)) == TYPE_DECL)
3488 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (orig_cur_type)));
3490 if (strcmp (this, that) != 0)
3492 /* There may be a better name for the format, e.g. size_t,
3493 but we should allow for programs with a perverse typedef
3494 making size_t something other than what the compiler
3496 if (types->wanted_type_name != 0
3497 && strcmp (types->wanted_type_name, that) != 0)
3498 this = types->wanted_type_name;
3499 if (types->name != 0)
3500 status_warning (status, "%s is not type %s (arg %d)", types->name, this,
3503 status_warning (status, "%s format, %s arg (arg %d)", this, that, arg_num);
3509 /* Set format warning options according to a -Wformat=n option. */
3512 set_Wformat (setting)
3515 warn_format = setting;
3516 warn_format_y2k = setting;
3517 warn_format_extra_args = setting;
3520 warn_format_nonliteral = setting;
3521 warn_format_security = setting;
3525 /* Print a warning if a constant expression had overflow in folding.
3526 Invoke this function on every expression that the language
3527 requires to be a constant expression.
3528 Note the ANSI C standard says it is erroneous for a
3529 constant expression to overflow. */
3532 constant_expression_warning (value)
3535 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
3536 || TREE_CODE (value) == COMPLEX_CST)
3537 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
3538 pedwarn ("overflow in constant expression");
3541 /* Print a warning if an expression had overflow in folding.
3542 Invoke this function on every expression that
3543 (1) appears in the source code, and
3544 (2) might be a constant expression that overflowed, and
3545 (3) is not already checked by convert_and_check;
3546 however, do not invoke this function on operands of explicit casts. */
3549 overflow_warning (value)
3552 if ((TREE_CODE (value) == INTEGER_CST
3553 || (TREE_CODE (value) == COMPLEX_CST
3554 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
3555 && TREE_OVERFLOW (value))
3557 TREE_OVERFLOW (value) = 0;
3558 if (skip_evaluation == 0)
3559 warning ("integer overflow in expression");
3561 else if ((TREE_CODE (value) == REAL_CST
3562 || (TREE_CODE (value) == COMPLEX_CST
3563 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
3564 && TREE_OVERFLOW (value))
3566 TREE_OVERFLOW (value) = 0;
3567 if (skip_evaluation == 0)
3568 warning ("floating point overflow in expression");
3572 /* Print a warning if a large constant is truncated to unsigned,
3573 or if -Wconversion is used and a constant < 0 is converted to unsigned.
3574 Invoke this function on every expression that might be implicitly
3575 converted to an unsigned type. */
3578 unsigned_conversion_warning (result, operand)
3579 tree result, operand;
3581 if (TREE_CODE (operand) == INTEGER_CST
3582 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
3583 && TREE_UNSIGNED (TREE_TYPE (result))
3584 && skip_evaluation == 0
3585 && !int_fits_type_p (operand, TREE_TYPE (result)))
3587 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
3588 /* This detects cases like converting -129 or 256 to unsigned char. */
3589 warning ("large integer implicitly truncated to unsigned type");
3590 else if (warn_conversion)
3591 warning ("negative integer implicitly converted to unsigned type");
3595 /* Convert EXPR to TYPE, warning about conversion problems with constants.
3596 Invoke this function on every expression that is converted implicitly,
3597 i.e. because of language rules and not because of an explicit cast. */
3600 convert_and_check (type, expr)
3603 tree t = convert (type, expr);
3604 if (TREE_CODE (t) == INTEGER_CST)
3606 if (TREE_OVERFLOW (t))
3608 TREE_OVERFLOW (t) = 0;
3610 /* Do not diagnose overflow in a constant expression merely
3611 because a conversion overflowed. */
3612 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
3614 /* No warning for converting 0x80000000 to int. */
3615 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
3616 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
3617 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
3618 /* If EXPR fits in the unsigned version of TYPE,
3619 don't warn unless pedantic. */
3621 || TREE_UNSIGNED (type)
3622 || ! int_fits_type_p (expr, unsigned_type (type)))
3623 && skip_evaluation == 0)
3624 warning ("overflow in implicit constant conversion");
3627 unsigned_conversion_warning (t, expr);
3632 /* A node in a list that describes references to variables (EXPR), which are
3633 either read accesses if WRITER is zero, or write accesses, in which case
3634 WRITER is the parent of EXPR. */
3641 /* Used to implement a cache the results of a call to verify_tree. We only
3642 use this for SAVE_EXPRs. */
3645 struct tlist_cache *next;
3646 struct tlist *cache_before_sp;
3647 struct tlist *cache_after_sp;
3651 /* Obstack to use when allocating tlist structures, and corresponding
3653 static struct obstack tlist_obstack;
3654 static char *tlist_firstobj = 0;
3656 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
3658 static struct tlist *warned_ids;
3659 /* SAVE_EXPRs need special treatment. We process them only once and then
3660 cache the results. */
3661 static struct tlist_cache *save_expr_cache;
3663 static void add_tlist PARAMS ((struct tlist **, struct tlist *, tree, int));
3664 static void merge_tlist PARAMS ((struct tlist **, struct tlist *, int));
3665 static void verify_tree PARAMS ((tree, struct tlist **, struct tlist **, tree));
3666 static int warning_candidate_p PARAMS ((tree));
3667 static void warn_for_collisions PARAMS ((struct tlist *));
3668 static void warn_for_collisions_1 PARAMS ((tree, tree, struct tlist *, int));
3669 static struct tlist *new_tlist PARAMS ((struct tlist *, tree, tree));
3670 static void verify_sequence_points PARAMS ((tree));
3672 /* Create a new struct tlist and fill in its fields. */
3673 static struct tlist *
3674 new_tlist (next, t, writer)
3680 l = (struct tlist *) obstack_alloc (&tlist_obstack, sizeof *l);
3687 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
3688 is nonnull, we ignore any node we find which has a writer equal to it. */
3691 add_tlist (to, add, exclude_writer, copy)
3694 tree exclude_writer;
3699 struct tlist *next = add->next;
3702 if (! exclude_writer || add->writer != exclude_writer)
3703 *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
3708 /* Merge the nodes of ADD into TO. This merging process is done so that for
3709 each variable that already exists in TO, no new node is added; however if
3710 there is a write access recorded in ADD, and an occurrence on TO is only
3711 a read access, then the occurrence in TO will be modified to record the
3715 merge_tlist (to, add, copy)
3720 struct tlist **end = to;
3723 end = &(*end)->next;
3729 struct tlist *next = add->next;
3731 for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
3732 if (tmp2->expr == add->expr)
3736 tmp2->writer = add->writer;
3740 *end = copy ? add : new_tlist (NULL, add->expr, add->writer);
3741 end = &(*end)->next;
3748 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
3749 references in list LIST conflict with it, excluding reads if ONLY writers
3753 warn_for_collisions_1 (written, writer, list, only_writes)
3754 tree written, writer;
3760 /* Avoid duplicate warnings. */
3761 for (tmp = warned_ids; tmp; tmp = tmp->next)
3762 if (tmp->expr == written)
3767 if (list->expr == written
3768 && list->writer != writer
3769 && (! only_writes || list->writer))
3771 warned_ids = new_tlist (warned_ids, written, NULL_TREE);
3772 warning ("operation on `%s' may be undefined",
3773 IDENTIFIER_POINTER (DECL_NAME (list->expr)));
3779 /* Given a list LIST of references to variables, find whether any of these
3780 can cause conflicts due to missing sequence points. */
3783 warn_for_collisions (list)
3788 for (tmp = list; tmp; tmp = tmp->next)
3791 warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
3795 /* Return nonzero if X is a tree that can be verified by the sequence poitn
3798 warning_candidate_p (x)
3801 return TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == PARM_DECL;
3804 /* Walk the tree X, and record accesses to variables. If X is written by the
3805 parent tree, WRITER is the parent.
3806 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
3807 expression or its only operand forces a sequence point, then everything up
3808 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
3810 Once we return, we will have emitted warnings if any subexpression before
3811 such a sequence point could be undefined. On a higher level, however, the
3812 sequence point may not be relevant, and we'll merge the two lists.
3814 Example: (b++, a) + b;
3815 The call that processes the COMPOUND_EXPR will store the increment of B
3816 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
3817 processes the PLUS_EXPR will need to merge the two lists so that
3818 eventually, all accesses end up on the same list (and we'll warn about the
3819 unordered subexpressions b++ and b.
3821 A note on merging. If we modify the former example so that our expression
3824 care must be taken not simply to add all three expressions into the final
3825 PNO_SP list. The function merge_tlist takes care of that by merging the
3826 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
3827 way, so that no more than one access to B is recorded. */
3830 verify_tree (x, pbefore_sp, pno_sp, writer)
3832 struct tlist **pbefore_sp, **pno_sp;
3835 struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
3836 enum tree_code code;
3840 code = TREE_CODE (x);
3841 class = TREE_CODE_CLASS (code);
3843 if (warning_candidate_p (x))
3845 *pno_sp = new_tlist (*pno_sp, x, writer);
3855 case TRUTH_ANDIF_EXPR:
3856 case TRUTH_ORIF_EXPR:
3857 tmp_before = tmp_nosp = tmp_list3 = 0;
3858 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
3859 warn_for_collisions (tmp_nosp);
3860 merge_tlist (pbefore_sp, tmp_before, 0);
3861 merge_tlist (pbefore_sp, tmp_nosp, 0);
3862 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, pno_sp, NULL_TREE);
3863 merge_tlist (pbefore_sp, tmp_list3, 0);
3867 tmp_before = tmp_list2 = 0;
3868 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
3869 warn_for_collisions (tmp_list2);
3870 merge_tlist (pbefore_sp, tmp_before, 0);
3871 merge_tlist (pbefore_sp, tmp_list2, 1);
3873 tmp_list3 = tmp_nosp = 0;
3874 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
3875 warn_for_collisions (tmp_nosp);
3876 merge_tlist (pbefore_sp, tmp_list3, 0);
3878 tmp_list3 = tmp_list2 = 0;
3879 verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
3880 warn_for_collisions (tmp_list2);
3881 merge_tlist (pbefore_sp, tmp_list3, 0);
3882 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
3883 two first, to avoid warning for (a ? b++ : b++). */
3884 merge_tlist (&tmp_nosp, tmp_list2, 0);
3885 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
3888 case PREDECREMENT_EXPR:
3889 case PREINCREMENT_EXPR:
3890 case POSTDECREMENT_EXPR:
3891 case POSTINCREMENT_EXPR:
3892 verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
3896 tmp_before = tmp_nosp = tmp_list3 = 0;
3897 verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
3898 verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
3899 /* Expressions inside the LHS are not ordered wrt. the sequence points
3900 in the RHS. Example:
3902 Despite the fact that the modification of "a" is in the before_sp
3903 list (tmp_before), it conflicts with the use of "a" in the LHS.
3904 We can handle this by adding the contents of tmp_list3
3905 to those of tmp_before, and redoing the collision warnings for that
3907 add_tlist (&tmp_before, tmp_list3, x, 1);
3908 warn_for_collisions (tmp_before);
3909 /* Exclude the LHS itself here; we first have to merge it into the
3910 tmp_nosp list. This is done to avoid warning for "a = a"; if we
3911 didn't exclude the LHS, we'd get it twice, once as a read and once
3913 add_tlist (pno_sp, tmp_list3, x, 0);
3914 warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
3916 merge_tlist (pbefore_sp, tmp_before, 0);
3917 if (warning_candidate_p (TREE_OPERAND (x, 0)))
3918 merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
3919 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
3923 /* We need to warn about conflicts among arguments and conflicts between
3924 args and the function address. Side effects of the function address,
3925 however, are not ordered by the sequence point of the call. */
3926 tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
3927 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
3928 if (TREE_OPERAND (x, 1))
3929 verify_tree (TREE_OPERAND (x, 1), &tmp_list2, &tmp_list3, NULL_TREE);
3930 merge_tlist (&tmp_list3, tmp_list2, 0);
3931 add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
3932 add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
3933 warn_for_collisions (tmp_before);
3934 add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
3938 /* Scan all the list, e.g. indices of multi dimensional array. */
3941 tmp_before = tmp_nosp = 0;
3942 verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
3943 merge_tlist (&tmp_nosp, tmp_before, 0);
3944 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
3951 struct tlist_cache *t;
3952 for (t = save_expr_cache; t; t = t->next)
3958 t = (struct tlist_cache *) obstack_alloc (&tlist_obstack,
3960 t->next = save_expr_cache;
3962 save_expr_cache = t;
3964 tmp_before = tmp_nosp = 0;
3965 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
3966 warn_for_collisions (tmp_nosp);
3971 struct tlist *t = tmp_nosp;
3973 merge_tlist (&tmp_list3, t, 0);
3975 t->cache_before_sp = tmp_before;
3976 t->cache_after_sp = tmp_list3;
3978 merge_tlist (pbefore_sp, t->cache_before_sp, 1);
3979 add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
3988 if (first_rtl_op (code) == 0)
3990 x = TREE_OPERAND (x, 0);
4006 int max = first_rtl_op (TREE_CODE (x));
4007 for (lp = 0; lp < max; lp++)
4009 tmp_before = tmp_nosp = 0;
4010 verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, NULL_TREE);
4011 merge_tlist (&tmp_nosp, tmp_before, 0);
4012 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
4019 /* Try to warn for undefined behaviour in EXPR due to missing sequence
4023 verify_sequence_points (expr)
4026 struct tlist *before_sp = 0, *after_sp = 0;
4029 save_expr_cache = 0;
4030 if (tlist_firstobj == 0)
4032 gcc_obstack_init (&tlist_obstack);
4033 tlist_firstobj = obstack_alloc (&tlist_obstack, 0);
4036 verify_tree (expr, &before_sp, &after_sp, 0);
4037 warn_for_collisions (after_sp);
4038 obstack_free (&tlist_obstack, tlist_firstobj);
4042 c_expand_expr_stmt (expr)
4045 /* Do default conversion if safe and possibly important,
4046 in case within ({...}). */
4047 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
4048 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
4049 expr = default_conversion (expr);
4051 if (warn_sequence_point)
4052 verify_sequence_points (expr);
4054 if (TREE_TYPE (expr) != error_mark_node
4055 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
4056 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
4057 error ("expression statement has incomplete type");
4059 last_expr_type = TREE_TYPE (expr);
4060 return add_stmt (build_stmt (EXPR_STMT, expr));
4063 /* Validate the expression after `case' and apply default promotions. */
4066 check_case_value (value)
4069 if (value == NULL_TREE)
4072 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
4073 STRIP_TYPE_NOPS (value);
4074 /* In C++, the following is allowed:
4077 switch (...) { case i: ... }
4079 So, we try to reduce the VALUE to a constant that way. */
4080 if (c_language == clk_cplusplus)
4082 value = decl_constant_value (value);
4083 STRIP_TYPE_NOPS (value);
4084 value = fold (value);
4087 if (TREE_CODE (value) != INTEGER_CST
4088 && value != error_mark_node)
4090 error ("case label does not reduce to an integer constant");
4091 value = error_mark_node;
4094 /* Promote char or short to int. */
4095 value = default_conversion (value);
4097 constant_expression_warning (value);
4102 /* Return an integer type with BITS bits of precision,
4103 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
4106 type_for_size (bits, unsignedp)
4110 if (bits == TYPE_PRECISION (integer_type_node))
4111 return unsignedp ? unsigned_type_node : integer_type_node;
4113 if (bits == TYPE_PRECISION (signed_char_type_node))
4114 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
4116 if (bits == TYPE_PRECISION (short_integer_type_node))
4117 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4119 if (bits == TYPE_PRECISION (long_integer_type_node))
4120 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4122 if (bits == TYPE_PRECISION (long_long_integer_type_node))
4123 return (unsignedp ? long_long_unsigned_type_node
4124 : long_long_integer_type_node);
4126 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
4127 return (unsignedp ? widest_unsigned_literal_type_node
4128 : widest_integer_literal_type_node);
4130 if (bits <= TYPE_PRECISION (intQI_type_node))
4131 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
4133 if (bits <= TYPE_PRECISION (intHI_type_node))
4134 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
4136 if (bits <= TYPE_PRECISION (intSI_type_node))
4137 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
4139 if (bits <= TYPE_PRECISION (intDI_type_node))
4140 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
4145 /* Return a data type that has machine mode MODE.
4146 If the mode is an integer,
4147 then UNSIGNEDP selects between signed and unsigned types. */
4150 type_for_mode (mode, unsignedp)
4151 enum machine_mode mode;
4154 if (mode == TYPE_MODE (integer_type_node))
4155 return unsignedp ? unsigned_type_node : integer_type_node;
4157 if (mode == TYPE_MODE (signed_char_type_node))
4158 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
4160 if (mode == TYPE_MODE (short_integer_type_node))
4161 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4163 if (mode == TYPE_MODE (long_integer_type_node))
4164 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4166 if (mode == TYPE_MODE (long_long_integer_type_node))
4167 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
4169 if (mode == TYPE_MODE (widest_integer_literal_type_node))
4170 return unsignedp ? widest_unsigned_literal_type_node
4171 : widest_integer_literal_type_node;
4173 if (mode == TYPE_MODE (intQI_type_node))
4174 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
4176 if (mode == TYPE_MODE (intHI_type_node))
4177 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
4179 if (mode == TYPE_MODE (intSI_type_node))
4180 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
4182 if (mode == TYPE_MODE (intDI_type_node))
4183 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
4185 #if HOST_BITS_PER_WIDE_INT >= 64
4186 if (mode == TYPE_MODE (intTI_type_node))
4187 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
4190 if (mode == TYPE_MODE (float_type_node))
4191 return float_type_node;
4193 if (mode == TYPE_MODE (double_type_node))
4194 return double_type_node;
4196 if (mode == TYPE_MODE (long_double_type_node))
4197 return long_double_type_node;
4199 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
4200 return build_pointer_type (char_type_node);
4202 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
4203 return build_pointer_type (integer_type_node);
4205 #ifdef VECTOR_MODE_SUPPORTED_P
4206 if (mode == TYPE_MODE (V4SF_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
4207 return V4SF_type_node;
4208 if (mode == TYPE_MODE (V4SI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
4209 return V4SI_type_node;
4210 if (mode == TYPE_MODE (V2SI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
4211 return V2SI_type_node;
4212 if (mode == TYPE_MODE (V4HI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
4213 return V4HI_type_node;
4214 if (mode == TYPE_MODE (V8QI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
4215 return V8QI_type_node;
4221 /* Return an unsigned type the same as TYPE in other respects. */
4223 unsigned_type (type)
4226 tree type1 = TYPE_MAIN_VARIANT (type);
4227 if (type1 == signed_char_type_node || type1 == char_type_node)
4228 return unsigned_char_type_node;
4229 if (type1 == integer_type_node)
4230 return unsigned_type_node;
4231 if (type1 == short_integer_type_node)
4232 return short_unsigned_type_node;
4233 if (type1 == long_integer_type_node)
4234 return long_unsigned_type_node;
4235 if (type1 == long_long_integer_type_node)
4236 return long_long_unsigned_type_node;
4237 if (type1 == widest_integer_literal_type_node)
4238 return widest_unsigned_literal_type_node;
4239 #if HOST_BITS_PER_WIDE_INT >= 64
4240 if (type1 == intTI_type_node)
4241 return unsigned_intTI_type_node;
4243 if (type1 == intDI_type_node)
4244 return unsigned_intDI_type_node;
4245 if (type1 == intSI_type_node)
4246 return unsigned_intSI_type_node;
4247 if (type1 == intHI_type_node)
4248 return unsigned_intHI_type_node;
4249 if (type1 == intQI_type_node)
4250 return unsigned_intQI_type_node;
4252 return signed_or_unsigned_type (1, type);
4255 /* Return a signed type the same as TYPE in other respects. */
4261 tree type1 = TYPE_MAIN_VARIANT (type);
4262 if (type1 == unsigned_char_type_node || type1 == char_type_node)
4263 return signed_char_type_node;
4264 if (type1 == unsigned_type_node)
4265 return integer_type_node;
4266 if (type1 == short_unsigned_type_node)
4267 return short_integer_type_node;
4268 if (type1 == long_unsigned_type_node)
4269 return long_integer_type_node;
4270 if (type1 == long_long_unsigned_type_node)
4271 return long_long_integer_type_node;
4272 if (type1 == widest_unsigned_literal_type_node)
4273 return widest_integer_literal_type_node;
4274 #if HOST_BITS_PER_WIDE_INT >= 64
4275 if (type1 == unsigned_intTI_type_node)
4276 return intTI_type_node;
4278 if (type1 == unsigned_intDI_type_node)
4279 return intDI_type_node;
4280 if (type1 == unsigned_intSI_type_node)
4281 return intSI_type_node;
4282 if (type1 == unsigned_intHI_type_node)
4283 return intHI_type_node;
4284 if (type1 == unsigned_intQI_type_node)
4285 return intQI_type_node;
4287 return signed_or_unsigned_type (0, type);
4290 /* Return a type the same as TYPE except unsigned or
4291 signed according to UNSIGNEDP. */
4294 signed_or_unsigned_type (unsignedp, type)
4298 if (! INTEGRAL_TYPE_P (type)
4299 || TREE_UNSIGNED (type) == unsignedp)
4302 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
4303 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
4304 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
4305 return unsignedp ? unsigned_type_node : integer_type_node;
4306 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
4307 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
4308 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
4309 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
4310 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
4311 return (unsignedp ? long_long_unsigned_type_node
4312 : long_long_integer_type_node);
4313 if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
4314 return (unsignedp ? widest_unsigned_literal_type_node
4315 : widest_integer_literal_type_node);
4319 /* Return the minimum number of bits needed to represent VALUE in a
4320 signed or unsigned type, UNSIGNEDP says which. */
4323 min_precision (value, unsignedp)
4329 /* If the value is negative, compute its negative minus 1. The latter
4330 adjustment is because the absolute value of the largest negative value
4331 is one larger than the largest positive value. This is equivalent to
4332 a bit-wise negation, so use that operation instead. */
4334 if (tree_int_cst_sgn (value) < 0)
4335 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
4337 /* Return the number of bits needed, taking into account the fact
4338 that we need one more bit for a signed than unsigned type. */
4340 if (integer_zerop (value))
4343 log = tree_floor_log2 (value);
4345 return log + 1 + ! unsignedp;
4348 /* Print an error message for invalid operands to arith operation CODE.
4349 NOP_EXPR is used as a special case (see truthvalue_conversion). */
4352 binary_op_error (code)
4353 enum tree_code code;
4355 register const char *opname;
4360 error ("invalid truth-value expression");
4364 opname = "+"; break;
4366 opname = "-"; break;
4368 opname = "*"; break;
4370 opname = "max"; break;
4372 opname = "min"; break;
4374 opname = "=="; break;
4376 opname = "!="; break;
4378 opname = "<="; break;
4380 opname = ">="; break;
4382 opname = "<"; break;
4384 opname = ">"; break;
4386 opname = "<<"; break;
4388 opname = ">>"; break;
4389 case TRUNC_MOD_EXPR:
4390 case FLOOR_MOD_EXPR:
4391 opname = "%"; break;
4392 case TRUNC_DIV_EXPR:
4393 case FLOOR_DIV_EXPR:
4394 opname = "/"; break;
4396 opname = "&"; break;
4398 opname = "|"; break;
4399 case TRUTH_ANDIF_EXPR:
4400 opname = "&&"; break;
4401 case TRUTH_ORIF_EXPR:
4402 opname = "||"; break;
4404 opname = "^"; break;
4407 opname = "rotate"; break;
4409 opname = "unknown"; break;
4411 error ("invalid operands to binary %s", opname);
4414 /* Subroutine of build_binary_op, used for comparison operations.
4415 See if the operands have both been converted from subword integer types
4416 and, if so, perhaps change them both back to their original type.
4417 This function is also responsible for converting the two operands
4418 to the proper common type for comparison.
4420 The arguments of this function are all pointers to local variables
4421 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
4422 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
4424 If this function returns nonzero, it means that the comparison has
4425 a constant value. What this function returns is an expression for
4429 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
4430 tree *op0_ptr, *op1_ptr;
4432 enum tree_code *rescode_ptr;
4435 tree op0 = *op0_ptr;
4436 tree op1 = *op1_ptr;
4437 int unsignedp0, unsignedp1;
4439 tree primop0, primop1;
4440 enum tree_code code = *rescode_ptr;
4442 /* Throw away any conversions to wider types
4443 already present in the operands. */
4445 primop0 = get_narrower (op0, &unsignedp0);
4446 primop1 = get_narrower (op1, &unsignedp1);
4448 /* Handle the case that OP0 does not *contain* a conversion
4449 but it *requires* conversion to FINAL_TYPE. */
4451 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
4452 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
4453 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
4454 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
4456 /* If one of the operands must be floated, we cannot optimize. */
4457 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
4458 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
4460 /* If first arg is constant, swap the args (changing operation
4461 so value is preserved), for canonicalization. Don't do this if
4462 the second arg is 0. */
4464 if (TREE_CONSTANT (primop0)
4465 && ! integer_zerop (primop1) && ! real_zerop (primop1))
4467 register tree tem = primop0;
4468 register int temi = unsignedp0;
4476 unsignedp0 = unsignedp1;
4499 *rescode_ptr = code;
4502 /* If comparing an integer against a constant more bits wide,
4503 maybe we can deduce a value of 1 or 0 independent of the data.
4504 Or else truncate the constant now
4505 rather than extend the variable at run time.
4507 This is only interesting if the constant is the wider arg.
4508 Also, it is not safe if the constant is unsigned and the
4509 variable arg is signed, since in this case the variable
4510 would be sign-extended and then regarded as unsigned.
4511 Our technique fails in this case because the lowest/highest
4512 possible unsigned results don't follow naturally from the
4513 lowest/highest possible values of the variable operand.
4514 For just EQ_EXPR and NE_EXPR there is another technique that
4515 could be used: see if the constant can be faithfully represented
4516 in the other operand's type, by truncating it and reextending it
4517 and see if that preserves the constant's value. */
4519 if (!real1 && !real2
4520 && TREE_CODE (primop1) == INTEGER_CST
4521 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
4523 int min_gt, max_gt, min_lt, max_lt;
4524 tree maxval, minval;
4525 /* 1 if comparison is nominally unsigned. */
4526 int unsignedp = TREE_UNSIGNED (*restype_ptr);
4529 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
4531 /* If TYPE is an enumeration, then we need to get its min/max
4532 values from it's underlying integral type, not the enumerated
4534 if (TREE_CODE (type) == ENUMERAL_TYPE)
4535 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
4537 maxval = TYPE_MAX_VALUE (type);
4538 minval = TYPE_MIN_VALUE (type);
4540 if (unsignedp && !unsignedp0)
4541 *restype_ptr = signed_type (*restype_ptr);
4543 if (TREE_TYPE (primop1) != *restype_ptr)
4544 primop1 = convert (*restype_ptr, primop1);
4545 if (type != *restype_ptr)
4547 minval = convert (*restype_ptr, minval);
4548 maxval = convert (*restype_ptr, maxval);
4551 if (unsignedp && unsignedp0)
4553 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
4554 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
4555 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
4556 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
4560 min_gt = INT_CST_LT (primop1, minval);
4561 max_gt = INT_CST_LT (primop1, maxval);
4562 min_lt = INT_CST_LT (minval, primop1);
4563 max_lt = INT_CST_LT (maxval, primop1);
4567 /* This used to be a switch, but Genix compiler can't handle that. */
4568 if (code == NE_EXPR)
4570 if (max_lt || min_gt)
4571 val = boolean_true_node;
4573 else if (code == EQ_EXPR)
4575 if (max_lt || min_gt)
4576 val = boolean_false_node;
4578 else if (code == LT_EXPR)
4581 val = boolean_true_node;
4583 val = boolean_false_node;
4585 else if (code == GT_EXPR)
4588 val = boolean_true_node;
4590 val = boolean_false_node;
4592 else if (code == LE_EXPR)
4595 val = boolean_true_node;
4597 val = boolean_false_node;
4599 else if (code == GE_EXPR)
4602 val = boolean_true_node;
4604 val = boolean_false_node;
4607 /* If primop0 was sign-extended and unsigned comparison specd,
4608 we did a signed comparison above using the signed type bounds.
4609 But the comparison we output must be unsigned.
4611 Also, for inequalities, VAL is no good; but if the signed
4612 comparison had *any* fixed result, it follows that the
4613 unsigned comparison just tests the sign in reverse
4614 (positive values are LE, negative ones GE).
4615 So we can generate an unsigned comparison
4616 against an extreme value of the signed type. */
4618 if (unsignedp && !unsignedp0)
4625 primop1 = TYPE_MIN_VALUE (type);
4631 primop1 = TYPE_MAX_VALUE (type);
4638 type = unsigned_type (type);
4641 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
4643 /* This is the case of (char)x >?< 0x80, which people used to use
4644 expecting old C compilers to change the 0x80 into -0x80. */
4645 if (val == boolean_false_node)
4646 warning ("comparison is always false due to limited range of data type");
4647 if (val == boolean_true_node)
4648 warning ("comparison is always true due to limited range of data type");
4651 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
4653 /* This is the case of (unsigned char)x >?< -1 or < 0. */
4654 if (val == boolean_false_node)
4655 warning ("comparison is always false due to limited range of data type");
4656 if (val == boolean_true_node)
4657 warning ("comparison is always true due to limited range of data type");
4662 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4663 if (TREE_SIDE_EFFECTS (primop0))
4664 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
4668 /* Value is not predetermined, but do the comparison
4669 in the type of the operand that is not constant.
4670 TYPE is already properly set. */
4672 else if (real1 && real2
4673 && (TYPE_PRECISION (TREE_TYPE (primop0))
4674 == TYPE_PRECISION (TREE_TYPE (primop1))))
4675 type = TREE_TYPE (primop0);
4677 /* If args' natural types are both narrower than nominal type
4678 and both extend in the same manner, compare them
4679 in the type of the wider arg.
4680 Otherwise must actually extend both to the nominal
4681 common type lest different ways of extending
4683 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
4685 else if (unsignedp0 == unsignedp1 && real1 == real2
4686 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
4687 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
4689 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
4690 type = signed_or_unsigned_type (unsignedp0
4691 || TREE_UNSIGNED (*restype_ptr),
4693 /* Make sure shorter operand is extended the right way
4694 to match the longer operand. */
4695 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
4697 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
4702 /* Here we must do the comparison on the nominal type
4703 using the args exactly as we received them. */
4704 type = *restype_ptr;
4708 if (!real1 && !real2 && integer_zerop (primop1)
4709 && TREE_UNSIGNED (*restype_ptr))
4715 /* All unsigned values are >= 0, so we warn if extra warnings
4716 are requested. However, if OP0 is a constant that is
4717 >= 0, the signedness of the comparison isn't an issue,
4718 so suppress the warning. */
4719 if (extra_warnings && !in_system_header
4720 && ! (TREE_CODE (primop0) == INTEGER_CST
4721 && ! TREE_OVERFLOW (convert (signed_type (type),
4723 warning ("comparison of unsigned expression >= 0 is always true");
4724 value = boolean_true_node;
4728 if (extra_warnings && !in_system_header
4729 && ! (TREE_CODE (primop0) == INTEGER_CST
4730 && ! TREE_OVERFLOW (convert (signed_type (type),
4732 warning ("comparison of unsigned expression < 0 is always false");
4733 value = boolean_false_node;
4742 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
4743 if (TREE_SIDE_EFFECTS (primop0))
4744 return build (COMPOUND_EXPR, TREE_TYPE (value),
4751 *op0_ptr = convert (type, primop0);
4752 *op1_ptr = convert (type, primop1);
4754 *restype_ptr = boolean_type_node;
4759 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
4760 or validate its data type for an `if' or `while' statement or ?..: exp.
4762 This preparation consists of taking the ordinary
4763 representation of an expression expr and producing a valid tree
4764 boolean expression describing whether expr is nonzero. We could
4765 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
4766 but we optimize comparisons, &&, ||, and !.
4768 The resulting type should always be `boolean_type_node'. */
4771 truthvalue_conversion (expr)
4774 if (TREE_CODE (expr) == ERROR_MARK)
4777 #if 0 /* This appears to be wrong for C++. */
4778 /* These really should return error_mark_node after 2.4 is stable.
4779 But not all callers handle ERROR_MARK properly. */
4780 switch (TREE_CODE (TREE_TYPE (expr)))
4783 error ("struct type value used where scalar is required");
4784 return boolean_false_node;
4787 error ("union type value used where scalar is required");
4788 return boolean_false_node;
4791 error ("array type value used where scalar is required");
4792 return boolean_false_node;
4799 switch (TREE_CODE (expr))
4802 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
4803 case TRUTH_ANDIF_EXPR:
4804 case TRUTH_ORIF_EXPR:
4805 case TRUTH_AND_EXPR:
4807 case TRUTH_XOR_EXPR:
4808 case TRUTH_NOT_EXPR:
4809 TREE_TYPE (expr) = boolean_type_node;
4816 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
4819 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
4822 /* If we are taking the address of a external decl, it might be zero
4823 if it is weak, so we cannot optimize. */
4824 if (DECL_P (TREE_OPERAND (expr, 0))
4825 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
4828 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
4829 return build (COMPOUND_EXPR, boolean_type_node,
4830 TREE_OPERAND (expr, 0), boolean_true_node);
4832 return boolean_true_node;
4835 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
4836 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
4837 truthvalue_conversion (TREE_OPERAND (expr, 0)),
4838 truthvalue_conversion (TREE_OPERAND (expr, 1)),
4845 /* These don't change whether an object is non-zero or zero. */
4846 return truthvalue_conversion (TREE_OPERAND (expr, 0));
4850 /* These don't change whether an object is zero or non-zero, but
4851 we can't ignore them if their second arg has side-effects. */
4852 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
4853 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
4854 truthvalue_conversion (TREE_OPERAND (expr, 0)));
4856 return truthvalue_conversion (TREE_OPERAND (expr, 0));
4859 /* Distribute the conversion into the arms of a COND_EXPR. */
4860 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
4861 truthvalue_conversion (TREE_OPERAND (expr, 1)),
4862 truthvalue_conversion (TREE_OPERAND (expr, 2))));
4865 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
4866 since that affects how `default_conversion' will behave. */
4867 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
4868 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
4870 /* fall through... */
4872 /* If this is widening the argument, we can ignore it. */
4873 if (TYPE_PRECISION (TREE_TYPE (expr))
4874 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
4875 return truthvalue_conversion (TREE_OPERAND (expr, 0));
4879 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
4881 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
4882 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
4884 /* fall through... */
4886 /* This and MINUS_EXPR can be changed into a comparison of the
4888 if (TREE_TYPE (TREE_OPERAND (expr, 0))
4889 == TREE_TYPE (TREE_OPERAND (expr, 1)))
4890 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
4891 TREE_OPERAND (expr, 1), 1);
4892 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
4893 fold (build1 (NOP_EXPR,
4894 TREE_TYPE (TREE_OPERAND (expr, 0)),
4895 TREE_OPERAND (expr, 1))), 1);
4898 if (integer_onep (TREE_OPERAND (expr, 1))
4899 && TREE_TYPE (expr) != boolean_type_node)
4900 /* Using convert here would cause infinite recursion. */
4901 return build1 (NOP_EXPR, boolean_type_node, expr);
4905 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
4906 warning ("suggest parentheses around assignment used as truth value");
4913 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
4915 tree tem = save_expr (expr);
4916 return (build_binary_op
4917 ((TREE_SIDE_EFFECTS (expr)
4918 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
4919 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
4920 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
4924 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
4927 static tree builtin_function_2 PARAMS ((const char *, const char *, tree, tree,
4928 int, enum built_in_class, int, int,
4931 /* Make a variant type in the proper way for C/C++, propagating qualifiers
4932 down to the element type of an array. */
4935 c_build_qualified_type (type, type_quals)
4939 /* A restrict-qualified pointer type must be a pointer to object or
4940 incomplete type. Note that the use of POINTER_TYPE_P also allows
4941 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
4942 the C++ front-end also use POINTER_TYPE for pointer-to-member
4943 values, so even though it should be illegal to use `restrict'
4944 with such an entity we don't flag that here. Thus, special case
4945 code for that case is required in the C++ front-end. */
4946 if ((type_quals & TYPE_QUAL_RESTRICT)
4947 && (!POINTER_TYPE_P (type)
4948 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
4950 error ("invalid use of `restrict'");
4951 type_quals &= ~TYPE_QUAL_RESTRICT;
4954 if (TREE_CODE (type) == ARRAY_TYPE)
4955 return build_array_type (c_build_qualified_type (TREE_TYPE (type),
4957 TYPE_DOMAIN (type));
4958 return build_qualified_type (type, type_quals);
4961 /* Apply the TYPE_QUALS to the new DECL. */
4964 c_apply_type_quals_to_decl (type_quals, decl)
4968 if ((type_quals & TYPE_QUAL_CONST)
4969 || (TREE_TYPE (decl)
4970 && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE))
4971 TREE_READONLY (decl) = 1;
4972 if (type_quals & TYPE_QUAL_VOLATILE)
4974 TREE_SIDE_EFFECTS (decl) = 1;
4975 TREE_THIS_VOLATILE (decl) = 1;
4977 if (type_quals & TYPE_QUAL_RESTRICT)
4979 if (!TREE_TYPE (decl)
4980 || !POINTER_TYPE_P (TREE_TYPE (decl))
4981 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
4982 error ("invalid use of `restrict'");
4983 else if (flag_strict_aliasing)
4985 /* No two restricted pointers can point at the same thing.
4986 However, a restricted pointer can point at the same thing
4987 as an unrestricted pointer, if that unrestricted pointer
4988 is based on the restricted pointer. So, we make the
4989 alias set for the restricted pointer a subset of the
4990 alias set for the type pointed to by the type of the
4993 HOST_WIDE_INT pointed_to_alias_set
4994 = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
4996 if (pointed_to_alias_set == 0)
4997 /* It's not legal to make a subset of alias set zero. */
5001 DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
5002 record_alias_subset (pointed_to_alias_set,
5003 DECL_POINTER_ALIAS_SET (decl));
5010 /* Return the typed-based alias set for T, which may be an expression
5011 or a type. Return -1 if we don't do anything special. */
5014 lang_get_alias_set (t)
5019 /* Permit type-punning when accessing a union, provided the access
5020 is directly through the union. For example, this code does not
5021 permit taking the address of a union member and then storing
5022 through it. Even the type-punning allowed here is a GCC
5023 extension, albeit a common and useful one; the C standard says
5024 that such accesses have implementation-defined behavior. */
5026 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
5027 u = TREE_OPERAND (u, 0))
5028 if (TREE_CODE (u) == COMPONENT_REF
5029 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
5032 /* If this is a char *, the ANSI C standard says it can alias
5033 anything. Note that all references need do this. */
5034 if (TREE_CODE_CLASS (TREE_CODE (t)) == 'r'
5035 && TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
5036 && TYPE_PRECISION (TREE_TYPE (t)) == TYPE_PRECISION (char_type_node))
5039 /* That's all the expressions we handle specially. */
5043 /* The C standard specifically allows aliasing between signed and
5044 unsigned variants of the same type. We treat the signed
5045 variant as canonical. */
5046 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
5048 tree t1 = signed_type (t);
5050 /* t1 == t can happen for boolean nodes which are always unsigned. */
5052 return get_alias_set (t1);
5054 else if (POINTER_TYPE_P (t))
5058 /* Unfortunately, there is no canonical form of a pointer type.
5059 In particular, if we have `typedef int I', then `int *', and
5060 `I *' are different types. So, we have to pick a canonical
5061 representative. We do this below.
5063 Technically, this approach is actually more conservative that
5064 it needs to be. In particular, `const int *' and `int *'
5065 chould be in different alias sets, according to the C and C++
5066 standard, since their types are not the same, and so,
5067 technically, an `int **' and `const int **' cannot point at
5070 But, the standard is wrong. In particular, this code is
5075 const int* const* cipp = &ip;
5077 And, it doesn't make sense for that to be legal unless you
5078 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
5079 the pointed-to types. This issue has been reported to the
5081 t1 = build_type_no_quals (t);
5083 return get_alias_set (t1);
5085 /* It's not yet safe to use alias sets for classes in C++ because
5086 the TYPE_FIELDs list for a class doesn't mention base classes. */
5087 else if (c_language == clk_cplusplus && AGGREGATE_TYPE_P (t))
5093 /* Build tree nodes and builtin functions common to both C and C++ language
5097 c_common_nodes_and_builtins ()
5100 tree memcpy_ftype, memset_ftype, strlen_ftype;
5101 tree bzero_ftype, bcmp_ftype, puts_ftype, printf_ftype;
5102 tree fputs_ftype, fputc_ftype, fwrite_ftype;
5103 tree endlink, int_endlink, double_endlink, unsigned_endlink;
5104 tree cstring_endlink, sizetype_endlink;
5105 tree ptr_ftype, ptr_ftype_unsigned;
5106 tree void_ftype_any, void_ftype_int, int_ftype_any;
5107 tree double_ftype_double, double_ftype_double_double;
5108 tree float_ftype_float, ldouble_ftype_ldouble;
5109 tree int_ftype_cptr_cptr_sizet, sizet_ftype_cstring_cstring;
5110 tree int_ftype_cstring_cstring, string_ftype_string_cstring;
5111 tree string_ftype_cstring_int, string_ftype_cstring_cstring;
5112 tree string_ftype_string_cstring_sizet, int_ftype_cstring_cstring_sizet;
5113 tree long_ftype_long;
5114 tree longlong_ftype_longlong;
5115 tree intmax_ftype_intmax;
5116 /* Either char* or void*. */
5117 tree traditional_ptr_type_node;
5118 /* Either const char* or const void*. */
5119 tree traditional_cptr_type_node;
5120 tree traditional_len_type_node;
5121 tree traditional_len_endlink;
5122 tree va_list_ref_type_node;
5123 tree va_list_arg_type_node;
5125 string_type_node = build_pointer_type (char_type_node);
5126 const_string_type_node
5127 = build_pointer_type (build_type_variant (char_type_node, 1, 0));
5130 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
5133 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
5135 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
5137 default_function_type = build_function_type (integer_type_node, NULL_TREE);
5139 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
5140 unsigned_ptrdiff_type_node = unsigned_type (ptrdiff_type_node);
5142 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
5143 va_list_type_node));
5145 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
5146 ptrdiff_type_node));
5148 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
5151 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
5153 va_list_arg_type_node = va_list_ref_type_node =
5154 build_pointer_type (TREE_TYPE (va_list_type_node));
5158 va_list_arg_type_node = va_list_type_node;
5159 va_list_ref_type_node = build_reference_type (va_list_type_node);
5162 endlink = void_list_node;
5163 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
5164 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
5165 unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink);
5166 cstring_endlink = tree_cons (NULL_TREE, const_string_type_node, endlink);
5168 ptr_ftype = build_function_type (ptr_type_node, NULL_TREE);
5169 ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink);
5170 sizetype_endlink = tree_cons (NULL_TREE, TYPE_DOMAIN (sizetype), endlink);
5171 /* We realloc here because sizetype could be int or unsigned. S'ok. */
5172 ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink);
5174 int_ftype_any = build_function_type (integer_type_node, NULL_TREE);
5175 void_ftype_any = build_function_type (void_type_node, NULL_TREE);
5176 void_ftype = build_function_type (void_type_node, endlink);
5177 void_ftype_int = build_function_type (void_type_node, int_endlink);
5179 = build_function_type (void_type_node,
5180 tree_cons (NULL_TREE, ptr_type_node, endlink));
5183 = build_function_type (float_type_node,
5184 tree_cons (NULL_TREE, float_type_node, endlink));
5187 = build_function_type (double_type_node, double_endlink);
5189 ldouble_ftype_ldouble
5190 = build_function_type (long_double_type_node,
5191 tree_cons (NULL_TREE, long_double_type_node,
5194 double_ftype_double_double
5195 = build_function_type (double_type_node,
5196 tree_cons (NULL_TREE, double_type_node,
5200 = build_function_type (integer_type_node, int_endlink);
5203 = build_function_type (long_integer_type_node,
5204 tree_cons (NULL_TREE, long_integer_type_node,
5207 longlong_ftype_longlong
5208 = build_function_type (long_long_integer_type_node,
5209 tree_cons (NULL_TREE, long_long_integer_type_node,
5213 = build_function_type (intmax_type_node,
5214 tree_cons (NULL_TREE, intmax_type_node,
5217 int_ftype_cptr_cptr_sizet
5218 = build_function_type (integer_type_node,
5219 tree_cons (NULL_TREE, const_ptr_type_node,
5220 tree_cons (NULL_TREE,
5221 const_ptr_type_node,
5222 sizetype_endlink)));
5224 void_zero_node = build_int_2 (0, 0);
5225 TREE_TYPE (void_zero_node) = void_type_node;
5227 /* Prototype for strcpy/strcat. */
5228 string_ftype_string_cstring
5229 = build_function_type (string_type_node,
5230 tree_cons (NULL_TREE, string_type_node,
5233 /* Prototype for strncpy/strncat. */
5234 string_ftype_string_cstring_sizet
5235 = build_function_type (string_type_node,
5236 tree_cons (NULL_TREE, string_type_node,
5237 tree_cons (NULL_TREE,
5238 const_string_type_node,
5239 sizetype_endlink)));
5241 traditional_len_type_node = ((flag_traditional &&
5242 c_language != clk_cplusplus)
5243 ? integer_type_node : sizetype);
5244 traditional_len_endlink = tree_cons (NULL_TREE, traditional_len_type_node,
5247 /* Prototype for strcmp. */
5248 int_ftype_cstring_cstring
5249 = build_function_type (integer_type_node,
5250 tree_cons (NULL_TREE, const_string_type_node,
5253 /* Prototype for strspn/strcspn. */
5254 sizet_ftype_cstring_cstring
5255 = build_function_type (c_size_type_node,
5256 tree_cons (NULL_TREE, const_string_type_node,
5259 /* Prototype for strncmp. */
5260 int_ftype_cstring_cstring_sizet
5261 = build_function_type (integer_type_node,
5262 tree_cons (NULL_TREE, const_string_type_node,
5263 tree_cons (NULL_TREE,
5264 const_string_type_node,
5265 sizetype_endlink)));
5267 /* Prototype for strstr, strpbrk, etc. */
5268 string_ftype_cstring_cstring
5269 = build_function_type (string_type_node,
5270 tree_cons (NULL_TREE, const_string_type_node,
5273 /* Prototype for strchr. */
5274 string_ftype_cstring_int
5275 = build_function_type (string_type_node,
5276 tree_cons (NULL_TREE, const_string_type_node,
5279 /* Prototype for strlen. */
5281 = build_function_type (traditional_len_type_node, cstring_endlink);
5283 traditional_ptr_type_node = ((flag_traditional &&
5284 c_language != clk_cplusplus)
5285 ? string_type_node : ptr_type_node);
5286 traditional_cptr_type_node = ((flag_traditional &&
5287 c_language != clk_cplusplus)
5288 ? const_string_type_node : const_ptr_type_node);
5290 /* Prototype for memcpy. */
5292 = build_function_type (traditional_ptr_type_node,
5293 tree_cons (NULL_TREE, ptr_type_node,
5294 tree_cons (NULL_TREE, const_ptr_type_node,
5295 sizetype_endlink)));
5297 /* Prototype for memset. */
5299 = build_function_type (traditional_ptr_type_node,
5300 tree_cons (NULL_TREE, ptr_type_node,
5301 tree_cons (NULL_TREE, integer_type_node,
5302 sizetype_endlink)));
5304 /* Prototype for bzero. */
5306 = build_function_type (void_type_node,
5307 tree_cons (NULL_TREE, traditional_ptr_type_node,
5308 traditional_len_endlink));
5310 /* Prototype for bcmp. */
5312 = build_function_type (integer_type_node,
5313 tree_cons (NULL_TREE, traditional_cptr_type_node,
5314 tree_cons (NULL_TREE,
5315 traditional_cptr_type_node,
5316 traditional_len_endlink)));
5318 /* Prototype for puts. */
5320 = build_function_type (integer_type_node, cstring_endlink);
5322 /* Prototype for printf. */
5324 = build_function_type (integer_type_node,
5325 tree_cons (NULL_TREE, const_string_type_node,
5328 /* These stdio prototypes are declared using void* in place of
5329 FILE*. They are only used for __builtin_ style calls, regular
5330 style builtin prototypes omit the arguments and merge those
5331 provided by stdio.h. */
5332 /* Prototype for fwrite. */
5334 = build_function_type (c_size_type_node,
5335 tree_cons (NULL_TREE, const_ptr_type_node,
5336 tree_cons (NULL_TREE, c_size_type_node,
5337 tree_cons (NULL_TREE, c_size_type_node,
5338 tree_cons (NULL_TREE, ptr_type_node, endlink)))));
5340 /* Prototype for fputc. */
5342 = build_function_type (integer_type_node,
5343 tree_cons (NULL_TREE, integer_type_node,
5344 tree_cons (NULL_TREE, ptr_type_node, endlink)));
5346 /* Prototype for fputs. */
5348 = build_function_type (integer_type_node,
5349 tree_cons (NULL_TREE, const_string_type_node,
5350 tree_cons (NULL_TREE, ptr_type_node, endlink)));
5352 builtin_function ("__builtin_constant_p", default_function_type,
5353 BUILT_IN_CONSTANT_P, BUILT_IN_NORMAL, NULL_PTR);
5355 builtin_function ("__builtin_return_address", ptr_ftype_unsigned,
5356 BUILT_IN_RETURN_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
5358 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned,
5359 BUILT_IN_FRAME_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
5361 builtin_function ("__builtin_alloca", ptr_ftype_sizetype,
5362 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, "alloca");
5363 builtin_function_2 ("__builtin_ffs", "ffs",
5364 int_ftype_int, int_ftype_int,
5365 BUILT_IN_FFS, BUILT_IN_NORMAL, 0, 1, 0);
5366 /* Define alloca as builtin, unless SMALL_STACK. */
5368 builtin_function_2 (NULL_PTR, "alloca", NULL_TREE, ptr_ftype_sizetype,
5369 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, 0, 1, 0);
5371 /* Declare _exit just to mark it as non-returning. */
5372 builtin_function_2 (NULL_PTR, "_exit", NULL_TREE, void_ftype_int,
5373 0, NOT_BUILT_IN, 0, 1, 1);
5375 builtin_function_2 ("__builtin_index", "index",
5376 string_ftype_cstring_int, string_ftype_cstring_int,
5377 BUILT_IN_INDEX, BUILT_IN_NORMAL, 1, 1, 0);
5378 builtin_function_2 ("__builtin_rindex", "rindex",
5379 string_ftype_cstring_int, string_ftype_cstring_int,
5380 BUILT_IN_RINDEX, BUILT_IN_NORMAL, 1, 1, 0);
5382 /* The system prototypes for these functions have many
5383 variations, so don't specify parameters to avoid conflicts.
5384 The expand_* functions check the argument types anyway. */
5385 builtin_function_2 ("__builtin_bzero", "bzero",
5386 bzero_ftype, void_ftype_any,
5387 BUILT_IN_BZERO, BUILT_IN_NORMAL, 1, 1, 0);
5388 builtin_function_2 ("__builtin_bcmp", "bcmp",
5389 bcmp_ftype, int_ftype_any,
5390 BUILT_IN_BCMP, BUILT_IN_NORMAL, 1, 1, 0);
5392 builtin_function_2 ("__builtin_abs", "abs",
5393 int_ftype_int, int_ftype_int,
5394 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, 0, 0);
5395 builtin_function_2 ("__builtin_fabsf", "fabsf",
5396 float_ftype_float, float_ftype_float,
5397 BUILT_IN_FABS, BUILT_IN_NORMAL, 0, 0, 0);
5398 builtin_function_2 ("__builtin_fabs", "fabs",
5399 double_ftype_double, double_ftype_double,
5400 BUILT_IN_FABS, BUILT_IN_NORMAL, 0, 0, 0);
5401 builtin_function_2 ("__builtin_fabsl", "fabsl",
5402 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
5403 BUILT_IN_FABS, BUILT_IN_NORMAL, 0, 0, 0);
5404 builtin_function_2 ("__builtin_labs", "labs",
5405 long_ftype_long, long_ftype_long,
5406 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, 0, 0);
5407 builtin_function_2 ("__builtin_llabs", "llabs",
5408 longlong_ftype_longlong, longlong_ftype_longlong,
5409 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
5410 builtin_function_2 ("__builtin_imaxabs", "imaxabs",
5411 intmax_ftype_intmax, intmax_ftype_intmax,
5412 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
5414 builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS,
5415 BUILT_IN_NORMAL, NULL_PTR);
5416 builtin_function ("__builtin_classify_type", default_function_type,
5417 BUILT_IN_CLASSIFY_TYPE, BUILT_IN_NORMAL, NULL_PTR);
5418 builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG,
5419 BUILT_IN_NORMAL, NULL_PTR);
5420 builtin_function ("__builtin_args_info", int_ftype_int, BUILT_IN_ARGS_INFO,
5421 BUILT_IN_NORMAL, NULL_PTR);
5422 builtin_function ("__builtin_setjmp",
5423 build_function_type (integer_type_node,
5424 tree_cons (NULL_TREE, ptr_type_node,
5426 BUILT_IN_SETJMP, BUILT_IN_NORMAL, NULL_PTR);
5427 builtin_function ("__builtin_longjmp",
5428 build_function_type (void_type_node,
5429 tree_cons (NULL_TREE, ptr_type_node,
5431 BUILT_IN_LONGJMP, BUILT_IN_NORMAL, NULL_PTR);
5432 builtin_function ("__builtin_trap", void_ftype, BUILT_IN_TRAP,
5433 BUILT_IN_NORMAL, NULL_PTR);
5435 /* ISO C99 IEEE Unordered compares. */
5436 builtin_function ("__builtin_isgreater", default_function_type,
5437 BUILT_IN_ISGREATER, BUILT_IN_NORMAL, NULL_PTR);
5438 builtin_function ("__builtin_isgreaterequal", default_function_type,
5439 BUILT_IN_ISGREATEREQUAL, BUILT_IN_NORMAL, NULL_PTR);
5440 builtin_function ("__builtin_isless", default_function_type,
5441 BUILT_IN_ISLESS, BUILT_IN_NORMAL, NULL_PTR);
5442 builtin_function ("__builtin_islessequal", default_function_type,
5443 BUILT_IN_ISLESSEQUAL, BUILT_IN_NORMAL, NULL_PTR);
5444 builtin_function ("__builtin_islessgreater", default_function_type,
5445 BUILT_IN_ISLESSGREATER, BUILT_IN_NORMAL, NULL_PTR);
5446 builtin_function ("__builtin_isunordered", default_function_type,
5447 BUILT_IN_ISUNORDERED, BUILT_IN_NORMAL, NULL_PTR);
5449 /* Untyped call and return. */
5450 builtin_function ("__builtin_apply_args", ptr_ftype,
5451 BUILT_IN_APPLY_ARGS, BUILT_IN_NORMAL, NULL_PTR);
5453 temp = tree_cons (NULL_TREE,
5454 build_pointer_type (build_function_type (void_type_node,
5456 tree_cons (NULL_TREE, ptr_type_node, sizetype_endlink));
5457 builtin_function ("__builtin_apply",
5458 build_function_type (ptr_type_node, temp),
5459 BUILT_IN_APPLY, BUILT_IN_NORMAL, NULL_PTR);
5460 builtin_function ("__builtin_return", void_ftype_ptr,
5461 BUILT_IN_RETURN, BUILT_IN_NORMAL, NULL_PTR);
5463 /* Support for varargs.h and stdarg.h. */
5464 builtin_function ("__builtin_varargs_start",
5465 build_function_type (void_type_node,
5466 tree_cons (NULL_TREE,
5467 va_list_ref_type_node,
5469 BUILT_IN_VARARGS_START, BUILT_IN_NORMAL, NULL_PTR);
5471 builtin_function ("__builtin_stdarg_start",
5472 build_function_type (void_type_node,
5473 tree_cons (NULL_TREE,
5474 va_list_ref_type_node,
5476 BUILT_IN_STDARG_START, BUILT_IN_NORMAL, NULL_PTR);
5478 builtin_function ("__builtin_va_end",
5479 build_function_type (void_type_node,
5480 tree_cons (NULL_TREE,
5481 va_list_ref_type_node,
5483 BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL_PTR);
5485 builtin_function ("__builtin_va_copy",
5486 build_function_type (void_type_node,
5487 tree_cons (NULL_TREE,
5488 va_list_ref_type_node,
5489 tree_cons (NULL_TREE,
5490 va_list_arg_type_node,
5492 BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL_PTR);
5494 /* ??? Ought to be `T __builtin_expect(T, T)' for any type T. */
5495 builtin_function ("__builtin_expect",
5496 build_function_type (long_integer_type_node,
5497 tree_cons (NULL_TREE,
5498 long_integer_type_node,
5499 tree_cons (NULL_TREE,
5500 long_integer_type_node,
5502 BUILT_IN_EXPECT, BUILT_IN_NORMAL, NULL_PTR);
5504 /* Currently under experimentation. */
5505 builtin_function_2 ("__builtin_memcpy", "memcpy",
5506 memcpy_ftype, memcpy_ftype,
5507 BUILT_IN_MEMCPY, BUILT_IN_NORMAL, 1, 0, 0);
5508 builtin_function_2 ("__builtin_memcmp", "memcmp",
5509 int_ftype_cptr_cptr_sizet, int_ftype_cptr_cptr_sizet,
5510 BUILT_IN_MEMCMP, BUILT_IN_NORMAL, 1, 0, 0);
5511 builtin_function_2 ("__builtin_memset", "memset",
5512 memset_ftype, memset_ftype,
5513 BUILT_IN_MEMSET, BUILT_IN_NORMAL, 1, 0, 0);
5514 built_in_decls[BUILT_IN_STRCMP] =
5515 builtin_function_2 ("__builtin_strcmp", "strcmp",
5516 int_ftype_cstring_cstring, int_ftype_cstring_cstring,
5517 BUILT_IN_STRCMP, BUILT_IN_NORMAL, 1, 0, 0);
5518 builtin_function_2 ("__builtin_strncmp", "strncmp",
5519 int_ftype_cstring_cstring_sizet,
5520 int_ftype_cstring_cstring_sizet,
5521 BUILT_IN_STRNCMP, BUILT_IN_NORMAL, 1, 0, 0);
5522 builtin_function_2 ("__builtin_strstr", "strstr",
5523 string_ftype_cstring_cstring, string_ftype_cstring_cstring,
5524 BUILT_IN_STRSTR, BUILT_IN_NORMAL, 1, 0, 0);
5525 builtin_function_2 ("__builtin_strpbrk", "strpbrk",
5526 string_ftype_cstring_cstring, string_ftype_cstring_cstring,
5527 BUILT_IN_STRPBRK, BUILT_IN_NORMAL, 1, 0, 0);
5528 built_in_decls[BUILT_IN_STRCHR] =
5529 builtin_function_2 ("__builtin_strchr", "strchr",
5530 string_ftype_cstring_int, string_ftype_cstring_int,
5531 BUILT_IN_STRCHR, BUILT_IN_NORMAL, 1, 0, 0);
5532 builtin_function_2 ("__builtin_strrchr", "strrchr",
5533 string_ftype_cstring_int, string_ftype_cstring_int,
5534 BUILT_IN_STRRCHR, BUILT_IN_NORMAL, 1, 0, 0);
5535 builtin_function_2 ("__builtin_strcpy", "strcpy",
5536 string_ftype_string_cstring, string_ftype_string_cstring,
5537 BUILT_IN_STRCPY, BUILT_IN_NORMAL, 1, 0, 0);
5538 builtin_function_2 ("__builtin_strncpy", "strncpy",
5539 string_ftype_string_cstring_sizet,
5540 string_ftype_string_cstring_sizet,
5541 BUILT_IN_STRNCPY, BUILT_IN_NORMAL, 1, 0, 0);
5542 built_in_decls[BUILT_IN_STRCAT] =
5543 builtin_function_2 ("__builtin_strcat", "strcat",
5544 string_ftype_string_cstring,
5545 string_ftype_string_cstring,
5546 BUILT_IN_STRCAT, BUILT_IN_NORMAL, 1, 0, 0);
5547 builtin_function_2 ("__builtin_strncat", "strncat",
5548 string_ftype_string_cstring_sizet,
5549 string_ftype_string_cstring_sizet,
5550 BUILT_IN_STRNCAT, BUILT_IN_NORMAL, 1, 0, 0);
5551 builtin_function_2 ("__builtin_strspn", "strspn",
5552 sizet_ftype_cstring_cstring, sizet_ftype_cstring_cstring,
5553 BUILT_IN_STRSPN, BUILT_IN_NORMAL, 1, 0, 0);
5554 builtin_function_2 ("__builtin_strcspn", "strcspn",
5555 sizet_ftype_cstring_cstring, sizet_ftype_cstring_cstring,
5556 BUILT_IN_STRCSPN, BUILT_IN_NORMAL, 1, 0, 0);
5557 built_in_decls[BUILT_IN_STRLEN] =
5558 builtin_function_2 ("__builtin_strlen", "strlen",
5559 strlen_ftype, strlen_ftype,
5560 BUILT_IN_STRLEN, BUILT_IN_NORMAL, 1, 0, 0);
5562 builtin_function_2 ("__builtin_sqrtf", "sqrtf",
5563 float_ftype_float, float_ftype_float,
5564 BUILT_IN_FSQRT, BUILT_IN_NORMAL, 1, 0, 0);
5565 builtin_function_2 ("__builtin_fsqrt", "sqrt",
5566 double_ftype_double, double_ftype_double,
5567 BUILT_IN_FSQRT, BUILT_IN_NORMAL, 1, 0, 0);
5568 builtin_function_2 ("__builtin_sqrtl", "sqrtl",
5569 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
5570 BUILT_IN_FSQRT, BUILT_IN_NORMAL, 1, 0, 0);
5571 builtin_function_2 ("__builtin_sinf", "sinf",
5572 float_ftype_float, float_ftype_float,
5573 BUILT_IN_SIN, BUILT_IN_NORMAL, 1, 0, 0);
5574 builtin_function_2 ("__builtin_sin", "sin",
5575 double_ftype_double, double_ftype_double,
5576 BUILT_IN_SIN, BUILT_IN_NORMAL, 1, 0, 0);
5577 builtin_function_2 ("__builtin_sinl", "sinl",
5578 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
5579 BUILT_IN_SIN, BUILT_IN_NORMAL, 1, 0, 0);
5580 builtin_function_2 ("__builtin_cosf", "cosf",
5581 float_ftype_float, float_ftype_float,
5582 BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
5583 builtin_function_2 ("__builtin_cos", "cos",
5584 double_ftype_double, double_ftype_double,
5585 BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
5586 builtin_function_2 ("__builtin_cosl", "cosl",
5587 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
5588 BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
5589 built_in_decls[BUILT_IN_PUTCHAR] =
5590 builtin_function ("__builtin_putchar", int_ftype_int,
5591 BUILT_IN_PUTCHAR, BUILT_IN_NORMAL, "putchar");
5592 built_in_decls[BUILT_IN_PUTS] =
5593 builtin_function ("__builtin_puts", puts_ftype,
5594 BUILT_IN_PUTS, BUILT_IN_NORMAL, "puts");
5595 builtin_function_2 ("__builtin_printf", "printf",
5596 printf_ftype, printf_ftype,
5597 BUILT_IN_PRINTF, BUILT_IN_FRONTEND, 1, 0, 0);
5598 built_in_decls[BUILT_IN_FWRITE] =
5599 builtin_function ("__builtin_fwrite", fwrite_ftype,
5600 BUILT_IN_FWRITE, BUILT_IN_NORMAL, "fwrite");
5601 built_in_decls[BUILT_IN_FPUTC] =
5602 builtin_function ("__builtin_fputc", fputc_ftype,
5603 BUILT_IN_FPUTC, BUILT_IN_NORMAL, "fputc");
5604 /* Declare the __builtin_ style with arguments and the regular style
5605 without them. We rely on stdio.h to supply the arguments for the
5606 regular style declaration since we had to use void* instead of
5607 FILE* in the __builtin_ prototype supplied here. */
5608 built_in_decls[BUILT_IN_FPUTS] =
5609 builtin_function_2 ("__builtin_fputs", "fputs",
5610 fputs_ftype, int_ftype_any,
5611 BUILT_IN_FPUTS, BUILT_IN_NORMAL, 1, 0, 0);
5613 /* Declare these functions non-returning
5614 to avoid spurious "control drops through" warnings. */
5615 builtin_function_2 (NULL_PTR, "abort",
5616 NULL_TREE, ((c_language == clk_cplusplus)
5617 ? void_ftype : void_ftype_any),
5618 0, NOT_BUILT_IN, 0, 0, 1);
5620 builtin_function_2 (NULL_PTR, "exit",
5621 NULL_TREE, ((c_language == clk_cplusplus)
5622 ? void_ftype_int : void_ftype_any),
5623 0, NOT_BUILT_IN, 0, 0, 1);
5626 /* Support for these has not been written in either expand_builtin
5627 or build_function_call. */
5628 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV,
5629 BUILT_IN_NORMAL, NULL_PTR);
5630 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV,
5631 BUILT_IN_NORMAL, NULL_PTR);
5632 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
5633 BUILT_IN_NORMAL, NULL_PTR);
5634 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
5635 BUILT_IN_NORMAL, NULL_PTR);
5636 builtin_function ("__builtin_fmod", double_ftype_double_double,
5637 BUILT_IN_FMOD, BUILT_IN_NORMAL, NULL_PTR);
5638 builtin_function ("__builtin_frem", double_ftype_double_double,
5639 BUILT_IN_FREM, BUILT_IN_NORMAL, NULL_PTR);
5640 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
5641 BUILT_IN_NORMAL, NULL_PTR);
5642 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
5643 BUILT_IN_NORMAL, NULL_PTR);
5646 main_identifier_node = get_identifier ("main");
5648 /* ??? Perhaps there's a better place to do this. But it is related
5649 to __builtin_va_arg, so it isn't that off-the-wall. */
5650 lang_type_promotes_to = simple_type_promotes_to;
5654 build_va_arg (expr, type)
5657 return build1 (VA_ARG_EXPR, type, expr);
5661 /* Possibly define a builtin function with one or two names. BUILTIN_NAME
5662 is an __builtin_-prefixed name; NAME is the ordinary name; one or both
5663 of these may be NULL (though both being NULL is useless).
5664 BUILTIN_TYPE is the type of the __builtin_-prefixed function;
5665 TYPE is the type of the function with the ordinary name. These
5666 may differ if the ordinary name is declared with a looser type to avoid
5667 conflicts with headers. FUNCTION_CODE and CLASS are as for
5668 builtin_function. If LIBRARY_NAME_P is nonzero, NAME is passed as
5669 the LIBRARY_NAME parameter to builtin_function when declaring BUILTIN_NAME.
5670 If NONANSI_P is nonzero, the name NAME is treated as a non-ANSI name; if
5671 NORETURN_P is nonzero, the function is marked as non-returning.
5672 Returns the declaration of BUILTIN_NAME, if any, otherwise
5673 the declaration of NAME. Does not declare NAME if flag_no_builtin,
5674 or if NONANSI_P and flag_no_nonansi_builtin. */
5677 builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
5678 class, library_name_p, nonansi_p, noreturn_p)
5679 const char *builtin_name;
5684 enum built_in_class class;
5689 tree bdecl = NULL_TREE;
5690 tree decl = NULL_TREE;
5691 if (builtin_name != 0)
5693 bdecl = builtin_function (builtin_name, builtin_type, function_code,
5694 class, library_name_p ? name : NULL_PTR);
5697 TREE_THIS_VOLATILE (bdecl) = 1;
5698 TREE_SIDE_EFFECTS (bdecl) = 1;
5701 if (name != 0 && !flag_no_builtin && !(nonansi_p && flag_no_nonansi_builtin))
5703 decl = builtin_function (name, type, function_code, class, NULL_PTR);
5705 DECL_BUILT_IN_NONANSI (decl) = 1;
5708 TREE_THIS_VOLATILE (decl) = 1;
5709 TREE_SIDE_EFFECTS (decl) = 1;
5712 return (bdecl != 0 ? bdecl : decl);
5715 /* Given a type, apply default promotions wrt unnamed function arguments
5716 and return the new type. Return NULL_TREE if no change. */
5717 /* ??? There is a function of the same name in the C++ front end that
5718 does something similar, but is more thorough and does not return NULL
5719 if no change. We could perhaps share code, but it would make the
5720 self_promoting_type property harder to identify. */
5723 simple_type_promotes_to (type)
5726 if (TYPE_MAIN_VARIANT (type) == float_type_node)
5727 return double_type_node;
5729 if (C_PROMOTING_INTEGER_TYPE_P (type))
5731 /* Traditionally, unsignedness is preserved in default promotions.
5732 Also preserve unsignedness if not really getting any wider. */
5733 if (TREE_UNSIGNED (type)
5734 && (flag_traditional
5735 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
5736 return unsigned_type_node;
5737 return integer_type_node;
5743 /* Return 1 if PARMS specifies a fixed number of parameters
5744 and none of their types is affected by default promotions. */
5747 self_promoting_args_p (parms)
5751 for (t = parms; t; t = TREE_CHAIN (t))
5753 register tree type = TREE_VALUE (t);
5755 if (TREE_CHAIN (t) == 0 && type != void_type_node)
5761 if (TYPE_MAIN_VARIANT (type) == float_type_node)
5764 if (C_PROMOTING_INTEGER_TYPE_P (type))
5770 /* Recursively examines the array elements of TYPE, until a non-array
5771 element type is found. */
5774 strip_array_types (type)
5777 while (TREE_CODE (type) == ARRAY_TYPE)
5778 type = TREE_TYPE (type);
5783 /* Recognize certain built-in functions so we can make tree-codes
5784 other than CALL_EXPR. We do this when it enables fold-const.c
5785 to do something useful. */
5786 /* ??? By rights this should go in builtins.c, but only C and C++
5787 implement build_{binary,unary}_op. Not exactly sure what bits
5788 of functionality are actually needed from those functions, or
5789 where the similar functionality exists in the other front ends. */
5792 expand_tree_builtin (function, params, coerced_params)
5793 tree function, params, coerced_params;
5795 enum tree_code code;
5797 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
5800 switch (DECL_FUNCTION_CODE (function))
5804 if (coerced_params == 0)
5805 return integer_zero_node;
5806 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
5808 case BUILT_IN_ISGREATER:
5809 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
5815 case BUILT_IN_ISGREATEREQUAL:
5816 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
5822 case BUILT_IN_ISLESS:
5823 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
5829 case BUILT_IN_ISLESSEQUAL:
5830 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
5836 case BUILT_IN_ISLESSGREATER:
5837 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
5843 case BUILT_IN_ISUNORDERED:
5844 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
5845 return integer_zero_node;
5846 code = UNORDERED_EXPR;
5854 || TREE_CHAIN (params) == 0)
5856 error ("too few arguments to function `%s'",
5857 IDENTIFIER_POINTER (DECL_NAME (function)));
5858 return error_mark_node;
5860 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
5862 error ("too many arguments to function `%s'",
5863 IDENTIFIER_POINTER (DECL_NAME (function)));
5864 return error_mark_node;
5867 arg0 = TREE_VALUE (params);
5868 arg1 = TREE_VALUE (TREE_CHAIN (params));
5869 arg0 = build_binary_op (code, arg0, arg1, 0);
5870 if (code != UNORDERED_EXPR)
5871 arg0 = build_unary_op (TRUTH_NOT_EXPR, arg0, 0);
5883 /* Returns non-zero if CODE is the code for a statement. */
5886 statement_code_p (code)
5887 enum tree_code code;
5910 if (lang_statement_code_p)
5911 return (*lang_statement_code_p) (code);
5916 /* Walk the statemen tree, rooted at *tp. Apply FUNC to all the
5917 sub-trees of *TP in a pre-order traversal. FUNC is called with the
5918 DATA and the address of each sub-tree. If FUNC returns a non-NULL
5919 value, the traversal is aborted, and the value returned by FUNC is
5920 returned. If FUNC sets WALK_SUBTREES to zero, then the subtrees of
5921 the node being visited are not walked.
5923 We don't need a without_duplicates variant of this one because the
5924 statement tree is a tree, not a graph. */
5927 walk_stmt_tree (tp, func, data)
5932 enum tree_code code;
5937 #define WALK_SUBTREE(NODE) \
5940 result = walk_stmt_tree (&(NODE), func, data); \
5946 /* Skip empty subtrees. */
5950 /* Skip subtrees below non-statement nodes. */
5951 if (!statement_code_p (TREE_CODE (*tp)))
5954 /* Call the function. */
5956 result = (*func) (tp, &walk_subtrees, data);
5958 /* If we found something, return it. */
5962 /* Even if we didn't, FUNC may have decided that there was nothing
5963 interesting below this point in the tree. */
5967 /* FUNC may have modified the tree, recheck that we're looking at a
5969 code = TREE_CODE (*tp);
5970 if (!statement_code_p (code))
5973 /* Walk over all the sub-trees of this operand. Statement nodes never
5974 contain RTL, and we needn't worry about TARGET_EXPRs. */
5975 len = TREE_CODE_LENGTH (code);
5977 /* Go through the subtrees. We need to do this in forward order so
5978 that the scope of a FOR_EXPR is handled properly. */
5979 for (i = 0; i < len; ++i)
5980 WALK_SUBTREE (TREE_OPERAND (*tp, i));
5982 /* Finally visit the chain. This can be tail-recursion optimized if
5983 we write it this way. */
5984 return walk_stmt_tree (&TREE_CHAIN (*tp), func, data);
5989 /* Used to compare case labels. K1 and K2 are actually tree nodes
5990 representing case labels, or NULL_TREE for a `default' label.
5991 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
5992 K2, and 0 if K1 and K2 are equal. */
5995 case_compare (k1, k2)
5999 /* Consider a NULL key (such as arises with a `default' label) to be
6000 smaller than anything else. */
6006 return tree_int_cst_compare ((tree) k1, (tree) k2);
6009 /* Process a case label for the range LOW_VALUE ... HIGH_VALUE. If
6010 LOW_VALUE and HIGH_VALUE are both NULL_TREE then this case label is
6011 actually a `default' label. If only HIGH_VALUE is NULL_TREE, then
6012 case label was declared using the usual C/C++ syntax, rather than
6013 the GNU case range extension. CASES is a tree containing all the
6014 case ranges processed so far; COND is the condition for the
6015 switch-statement itself. Returns the CASE_LABEL created, or
6016 ERROR_MARK_NODE if no CASE_LABEL is created. */
6019 c_add_case_label (cases, cond, low_value, high_value)
6028 splay_tree_node node;
6030 /* Create the LABEL_DECL itself. */
6031 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
6032 DECL_CONTEXT (label) = current_function_decl;
6034 /* If there was an error processing the switch condition, bail now
6035 before we get more confused. */
6036 if (!cond || cond == error_mark_node)
6038 /* Add a label anyhow so that the back-end doesn't think that
6039 the beginning of the switch is unreachable. */
6041 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
6042 return error_mark_node;
6045 if ((low_value && TREE_TYPE (low_value)
6046 && POINTER_TYPE_P (TREE_TYPE (low_value)))
6047 || (high_value && TREE_TYPE (high_value)
6048 && POINTER_TYPE_P (TREE_TYPE (high_value))))
6049 error ("pointers are not permitted as case values");
6051 /* Case ranges are a GNU extension. */
6052 if (high_value && pedantic)
6054 if (c_language == clk_cplusplus)
6055 pedwarn ("ISO C++ forbids range expressions in switch statements");
6057 pedwarn ("ISO C forbids range expressions in switch statements");
6060 type = TREE_TYPE (cond);
6063 low_value = check_case_value (low_value);
6064 low_value = convert_and_check (type, low_value);
6068 high_value = check_case_value (high_value);
6069 high_value = convert_and_check (type, high_value);
6072 /* If an error has occurred, bail out now. */
6073 if (low_value == error_mark_node || high_value == error_mark_node)
6076 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
6077 return error_mark_node;
6080 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
6081 really a case range, even though it was written that way. Remove
6082 the HIGH_VALUE to simplify later processing. */
6083 if (tree_int_cst_equal (low_value, high_value))
6084 high_value = NULL_TREE;
6085 if (low_value && high_value
6086 && !tree_int_cst_lt (low_value, high_value))
6087 warning ("empty range specified");
6089 /* Look up the LOW_VALUE in the table of case labels we already
6091 node = splay_tree_lookup (cases, (splay_tree_key) low_value);
6092 /* If there was not an exact match, check for overlapping ranges.
6093 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
6094 that's a `default' label and the only overlap is an exact match. */
6095 if (!node && (low_value || high_value))
6097 splay_tree_node low_bound;
6098 splay_tree_node high_bound;
6100 /* Even though there wasn't an exact match, there might be an
6101 overlap between this case range and another case range.
6102 Since we've (inductively) not allowed any overlapping case
6103 ranges, we simply need to find the greatest low case label
6104 that is smaller that LOW_VALUE, and the smallest low case
6105 label that is greater than LOW_VALUE. If there is an overlap
6106 it will occur in one of these two ranges. */
6107 low_bound = splay_tree_predecessor (cases,
6108 (splay_tree_key) low_value);
6109 high_bound = splay_tree_successor (cases,
6110 (splay_tree_key) low_value);
6112 /* Check to see if the LOW_BOUND overlaps. It is smaller than
6113 the LOW_VALUE, so there is no need to check unless the
6114 LOW_BOUND is in fact itself a case range. */
6116 && CASE_HIGH ((tree) low_bound->value)
6117 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
6120 /* Check to see if the HIGH_BOUND overlaps. The low end of that
6121 range is bigger than the low end of the current range, so we
6122 are only interested if the current range is a real range, and
6123 not an ordinary case label. */
6126 && (tree_int_cst_compare ((tree) high_bound->key,
6131 /* If there was an overlap, issue an error. */
6134 tree duplicate = CASE_LABEL_DECL ((tree) node->value);
6138 error ("duplicate (or overlapping) case value");
6139 error_with_decl (duplicate,
6140 "this is the first entry overlapping that value");
6144 error ("duplicate case value") ;
6145 error_with_decl (duplicate, "previously used here");
6149 error ("multiple default labels in one switch");
6150 error_with_decl (duplicate, "this is the first default label");
6153 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
6156 /* Add a CASE_LABEL to the statement-tree. */
6157 case_label = add_stmt (build_case_label (low_value, high_value, label));
6158 /* Register this case label in the splay tree. */
6159 splay_tree_insert (cases,
6160 (splay_tree_key) low_value,
6161 (splay_tree_value) case_label);
6166 /* Mark P (a stmt_tree) for GC. The use of a `void *' for the
6167 parameter allows this function to be used as a GC-marking
6174 stmt_tree st = (stmt_tree) p;
6176 ggc_mark_tree (st->x_last_stmt);
6177 ggc_mark_tree (st->x_last_expr_type);
6180 /* Mark LD for GC. */
6183 c_mark_lang_decl (c)
6184 struct c_lang_decl *c;
6186 ggc_mark_tree (c->saved_tree);
6189 /* Mark F for GC. */
6192 mark_c_language_function (f)
6193 struct language_function *f;
6198 mark_stmt_tree (&f->x_stmt_tree);
6199 ggc_mark_tree (f->x_scope_stmt_stack);
6202 /* Hook used by expand_expr to expand language-specific tree codes. */
6205 c_expand_expr (exp, target, tmode, modifier)
6208 enum machine_mode tmode;
6209 enum expand_modifier modifier;
6211 switch (TREE_CODE (exp))
6218 /* Since expand_expr_stmt calls free_temp_slots after every
6219 expression statement, we must call push_temp_slots here.
6220 Otherwise, any temporaries in use now would be considered
6221 out-of-scope after the first EXPR_STMT from within the
6224 rtl_expr = expand_start_stmt_expr ();
6225 expand_stmt (STMT_EXPR_STMT (exp));
6226 expand_end_stmt_expr (rtl_expr);
6227 result = expand_expr (rtl_expr, target, tmode, modifier);
6235 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
6236 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6238 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6239 && (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
6240 == BUILT_IN_FRONTEND))
6241 return c_expand_builtin (exp, target, tmode, modifier);
6255 /* Hook used by safe_from_p to handle language-specific tree codes. */
6258 c_safe_from_p (target, exp)
6262 /* We can see statements here when processing the body of a
6263 statement-expression. For a declaration statement declaring a
6264 variable, look at the variable's initializer. */
6265 if (TREE_CODE (exp) == DECL_STMT)
6267 tree decl = DECL_STMT_DECL (exp);
6269 if (TREE_CODE (decl) == VAR_DECL
6270 && DECL_INITIAL (decl)
6271 && !safe_from_p (target, DECL_INITIAL (decl), /*top_p=*/0))
6275 /* For any statement, we must follow the statement-chain. */
6276 if (statement_code_p (TREE_CODE (exp)) && TREE_CHAIN (exp))
6277 return safe_from_p (target, TREE_CHAIN (exp), /*top_p=*/0);
6279 /* Assume everything else is safe. */
6283 /* Hook used by unsafe_for_reeval to handle language-specific tree codes. */
6286 c_unsafe_for_reeval (exp)
6289 /* Statement expressions may not be reevaluated. */
6290 if (TREE_CODE (exp) == STMT_EXPR)
6293 /* Walk all other expressions. */
6297 /* Tree code classes. */
6299 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
6301 static char c_tree_code_type[] = {
6303 #include "c-common.def"
6307 /* Table indexed by tree code giving number of expression
6308 operands beyond the fixed part of the node structure.
6309 Not used for types or decls. */
6311 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
6313 static int c_tree_code_length[] = {
6315 #include "c-common.def"
6319 /* Names of tree components.
6320 Used for printing out the tree and error messages. */
6321 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
6323 static const char *c_tree_code_name[] = {
6325 #include "c-common.def"
6329 /* Adds the tree codes specific to the C front end to the list of all
6335 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
6337 (int)LAST_C_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
6338 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
6340 (LAST_C_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
6341 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
6343 (LAST_C_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
6344 lang_unsafe_for_reeval = c_unsafe_for_reeval;
6347 #define CALLED_AS_BUILT_IN(NODE) \
6348 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
6351 c_expand_builtin (exp, target, tmode, modifier)
6354 enum machine_mode tmode;
6355 enum expand_modifier modifier;
6357 tree type = TREE_TYPE (exp);
6358 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6359 tree arglist = TREE_OPERAND (exp, 1);
6360 enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
6361 enum tree_code code = TREE_CODE (exp);
6362 const int ignore = (target == const0_rtx
6363 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
6364 || code == CONVERT_EXPR || code == REFERENCE_EXPR
6365 || code == COND_EXPR)
6366 && TREE_CODE (type) == VOID_TYPE));
6368 if (! optimize && ! CALLED_AS_BUILT_IN (fndecl))
6369 return expand_call (exp, target, ignore);
6373 case BUILT_IN_PRINTF:
6374 target = c_expand_builtin_printf (arglist, target, tmode,
6380 default: /* just do library call, if unknown builtin */
6381 error ("built-in function `%s' not currently supported",
6382 IDENTIFIER_POINTER (DECL_NAME (fndecl)));
6385 /* The switch statement above can drop through to cause the function
6386 to be called normally. */
6387 return expand_call (exp, target, ignore);
6390 /* Check an arglist to *printf for problems. The arglist should start
6391 at the format specifier, with the remaining arguments immediately
6394 is_valid_printf_arglist (arglist)
6397 /* Save this value so we can restore it later. */
6398 const int SAVE_pedantic = pedantic;
6399 int diagnostic_occurred = 0;
6401 /* Set this to a known value so the user setting won't affect code
6404 /* Check to make sure there are no format specifier errors. */
6405 check_function_format (&diagnostic_occurred,
6406 maybe_get_identifier("printf"),
6407 NULL_TREE, arglist);
6409 /* Restore the value of `pedantic'. */
6410 pedantic = SAVE_pedantic;
6412 /* If calling `check_function_format_ptr' produces a warning, we
6413 return false, otherwise we return true. */
6414 return ! diagnostic_occurred;
6417 /* If the arguments passed to printf are suitable for optimizations,
6418 we attempt to transform the call. */
6420 c_expand_builtin_printf (arglist, target, tmode, modifier, ignore)
6423 enum machine_mode tmode;
6424 enum expand_modifier modifier;
6427 tree fn_putchar = built_in_decls[BUILT_IN_PUTCHAR],
6428 fn_puts = built_in_decls[BUILT_IN_PUTS];
6429 tree fn, format_arg, stripped_string;
6431 /* If the return value is used, or the replacement _DECL isn't
6432 initialized, don't do the transformation. */
6433 if (!ignore || !fn_putchar || !fn_puts)
6436 /* Verify the required arguments in the original call. */
6438 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE))
6441 /* Check the specifier vs. the parameters. */
6442 if (!is_valid_printf_arglist (arglist))
6445 format_arg = TREE_VALUE (arglist);
6446 stripped_string = format_arg;
6447 STRIP_NOPS (stripped_string);
6448 if (stripped_string && TREE_CODE (stripped_string) == ADDR_EXPR)
6449 stripped_string = TREE_OPERAND (stripped_string, 0);
6451 /* If the format specifier isn't a STRING_CST, punt. */
6452 if (TREE_CODE (stripped_string) != STRING_CST)
6455 /* OK! We can attempt optimization. */
6457 /* If the format specifier was "%s\n", call __builtin_puts(arg2). */
6458 if (strcmp (TREE_STRING_POINTER (stripped_string), "%s\n") == 0)
6460 arglist = TREE_CHAIN (arglist);
6463 /* If the format specifier was "%c", call __builtin_putchar (arg2). */
6464 else if (strcmp (TREE_STRING_POINTER (stripped_string), "%c") == 0)
6466 arglist = TREE_CHAIN (arglist);
6471 /* We can't handle anything else with % args or %% ... yet. */
6472 if (strchr (TREE_STRING_POINTER (stripped_string), '%'))
6475 /* If the resulting constant string has a length of 1, call
6476 putchar. Note, TREE_STRING_LENGTH includes the terminating
6477 NULL in its count. */
6478 if (TREE_STRING_LENGTH (stripped_string) == 2)
6480 /* Given printf("c"), (where c is any one character,)
6481 convert "c"[0] to an int and pass that to the replacement
6483 arglist = build_int_2 (TREE_STRING_POINTER (stripped_string)[0], 0);
6484 arglist = build_tree_list (NULL_TREE, arglist);
6488 /* If the resulting constant was "string\n", call
6489 __builtin_puts("string"). Ensure "string" has at least one
6490 character besides the trailing \n. Note, TREE_STRING_LENGTH
6491 includes the terminating NULL in its count. */
6492 else if (TREE_STRING_LENGTH (stripped_string) > 2
6493 && TREE_STRING_POINTER (stripped_string)
6494 [TREE_STRING_LENGTH (stripped_string) - 2] == '\n')
6496 /* Create a NULL-terminated string that's one char shorter
6497 than the original, stripping off the trailing '\n'. */
6498 const int newlen = TREE_STRING_LENGTH (stripped_string) - 1;
6499 char *newstr = (char *) alloca (newlen);
6500 memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
6501 newstr[newlen - 1] = 0;
6503 arglist = combine_strings (build_string (newlen, newstr));
6504 arglist = build_tree_list (NULL_TREE, arglist);
6508 /* We'd like to arrange to call fputs(string) here, but we
6509 need stdout and don't have a way to get it ... yet. */
6513 return expand_expr (build_function_call (fn, arglist),
6514 (ignore ? const0_rtx : target),
6519 /* Given a boolean expression ARG, return a tree representing an increment
6520 or decrement (as indicated by CODE) of ARG. The front end must check for
6521 invalid cases (e.g., decrement in C++). */
6523 boolean_increment (code, arg)
6524 enum tree_code code;
6528 tree true_res = (c_language == clk_cplusplus
6530 : c_bool_true_node);
6531 arg = stabilize_reference (arg);
6534 case PREINCREMENT_EXPR:
6535 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
6537 case POSTINCREMENT_EXPR:
6538 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
6539 arg = save_expr (arg);
6540 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
6541 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
6543 case PREDECREMENT_EXPR:
6544 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, invert_truthvalue (arg));
6546 case POSTDECREMENT_EXPR:
6547 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, invert_truthvalue (arg));
6548 arg = save_expr (arg);
6549 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
6550 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
6555 TREE_SIDE_EFFECTS (val) = 1;