* configure.in: Arrange to include defaults.h in [ht]config.h/tm.h.
[official-gcc.git] / gcc / c-common.c
blob437f64a94c990a81d9c4a14f0ab5cc1af825060a
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)
10 any later version.
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. */
22 #include "config.h"
23 #include "system.h"
24 #include "tree.h"
25 #include "flags.h"
26 #include "toplev.h"
27 #include "output.h"
28 #include "c-pragma.h"
29 #include "rtl.h"
30 #include "ggc.h"
31 #include "expr.h"
32 #include "c-common.h"
33 #include "tm_p.h"
34 #include "obstack.h"
35 #include "cpplib.h"
36 cpp_reader *parse_in; /* Declared in c-lex.h. */
38 #undef WCHAR_TYPE_SIZE
39 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
41 /* We let tm.h override the types used here, to handle trivial differences
42 such as the choice of unsigned int or long unsigned int for size_t.
43 When machines start needing nontrivial differences in the size type,
44 it would be best to do something here to figure out automatically
45 from other information what type to use. */
47 #ifndef SIZE_TYPE
48 #define SIZE_TYPE "long unsigned int"
49 #endif
51 #ifndef WCHAR_TYPE
52 #define WCHAR_TYPE "int"
53 #endif
55 #ifndef PTRDIFF_TYPE
56 #define PTRDIFF_TYPE "long int"
57 #endif
59 #ifndef WINT_TYPE
60 #define WINT_TYPE "unsigned int"
61 #endif
63 #ifndef INTMAX_TYPE
64 #define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
65 ? "int" \
66 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
67 ? "long int" \
68 : "long long int"))
69 #endif
71 #ifndef UINTMAX_TYPE
72 #define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
73 ? "unsigned int" \
74 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
75 ? "long unsigned int" \
76 : "long long unsigned int"))
77 #endif
79 /* The following symbols are subsumed in the c_global_trees array, and
80 listed here individually for documentation purposes.
82 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
84 tree short_integer_type_node;
85 tree long_integer_type_node;
86 tree long_long_integer_type_node;
88 tree short_unsigned_type_node;
89 tree long_unsigned_type_node;
90 tree long_long_unsigned_type_node;
92 tree boolean_type_node;
93 tree boolean_false_node;
94 tree boolean_true_node;
96 tree ptrdiff_type_node;
98 tree unsigned_char_type_node;
99 tree signed_char_type_node;
100 tree wchar_type_node;
101 tree signed_wchar_type_node;
102 tree unsigned_wchar_type_node;
104 tree float_type_node;
105 tree double_type_node;
106 tree long_double_type_node;
108 tree complex_integer_type_node;
109 tree complex_float_type_node;
110 tree complex_double_type_node;
111 tree complex_long_double_type_node;
113 tree intQI_type_node;
114 tree intHI_type_node;
115 tree intSI_type_node;
116 tree intDI_type_node;
117 tree intTI_type_node;
119 tree unsigned_intQI_type_node;
120 tree unsigned_intHI_type_node;
121 tree unsigned_intSI_type_node;
122 tree unsigned_intDI_type_node;
123 tree unsigned_intTI_type_node;
125 tree widest_integer_literal_type_node;
126 tree widest_unsigned_literal_type_node;
128 Nodes for types `void *' and `const void *'.
130 tree ptr_type_node, const_ptr_type_node;
132 Nodes for types `char *' and `const char *'.
134 tree string_type_node, const_string_type_node;
136 Type `char[SOMENUMBER]'.
137 Used when an array of char is needed and the size is irrelevant.
139 tree char_array_type_node;
141 Type `int[SOMENUMBER]' or something like it.
142 Used when an array of int needed and the size is irrelevant.
144 tree int_array_type_node;
146 Type `wchar_t[SOMENUMBER]' or something like it.
147 Used when a wide string literal is created.
149 tree wchar_array_type_node;
151 Type `int ()' -- used for implicit declaration of functions.
153 tree default_function_type;
155 Function types `int (int)', etc.
157 tree int_ftype_int;
158 tree void_ftype;
159 tree void_ftype_ptr;
160 tree int_ftype_int;
161 tree ptr_ftype_sizetype;
163 A VOID_TYPE node, packaged in a TREE_LIST.
165 tree void_list_node;
167 The identifiers __FUNCTION__, __PRETTY_FUNCTION__, and __func__.
169 tree function_id_node;
170 tree pretty_function_id_node;
171 tree func_id_node;
175 tree c_global_trees[CTI_MAX];
177 /* Nonzero means don't recognize the non-ANSI builtin functions. */
179 int flag_no_builtin;
181 /* Nonzero means don't recognize the non-ANSI builtin functions.
182 -ansi sets this. */
184 int flag_no_nonansi_builtin;
186 /* Nonzero means give `double' the same size as `float'. */
188 int flag_short_double;
190 /* Nonzero means give `wchar_t' the same size as `short'. */
192 int flag_short_wchar;
194 /* If non-NULL, dump the tree structure for the entire translation
195 unit to this file. */
197 const char *flag_dump_translation_unit;
199 /* Nonzero means warn about possible violations of sequence point rules. */
201 int warn_sequence_point;
203 /* The elements of `ridpointers' are identifier nodes for the reserved
204 type names and storage classes. It is indexed by a RID_... value. */
205 tree *ridpointers;
207 tree (*make_fname_decl) PARAMS ((tree, const char *, int));
209 /* If non-NULL, the address of a language-specific function that
210 returns 1 for language-specific statement codes. */
211 int (*lang_statement_code_p) PARAMS ((enum tree_code));
213 /* If non-NULL, the address of a language-specific function that takes
214 any action required right before expand_function_end is called. */
215 void (*lang_expand_function_end) PARAMS ((void));
217 /* If this variable is defined to a non-NULL value, it will be called
218 after the file has been completely parsed. */
219 void (*back_end_hook) PARAMS ((tree));
221 /* Nonzero means the expression being parsed will never be evaluated.
222 This is a count, since unevaluated expressions can nest. */
223 int skip_evaluation;
225 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
226 A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
227 A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
228 A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, A_MALLOC,
229 A_NO_LIMIT_STACK, A_PURE};
231 static void add_attribute PARAMS ((enum attrs, const char *,
232 int, int, int));
233 static void init_attributes PARAMS ((void));
234 static int default_valid_lang_attribute PARAMS ((tree, tree, tree, tree));
236 /* Keep a stack of if statements. We record the number of compound
237 statements seen up to the if keyword, as well as the line number
238 and file of the if. If a potentially ambiguous else is seen, that
239 fact is recorded; the warning is issued when we can be sure that
240 the enclosing if statement does not have an else branch. */
241 typedef struct
243 int compstmt_count;
244 int line;
245 const char *file;
246 int needs_warning;
247 tree if_stmt;
248 } if_elt;
250 static if_elt *if_stack;
252 /* Amount of space in the if statement stack. */
253 static int if_stack_space = 0;
255 /* Stack pointer. */
256 static int if_stack_pointer = 0;
258 /* Record the start of an if-then, and record the start of it
259 for ambiguous else detection. */
261 void
262 c_expand_start_cond (cond, compstmt_count)
263 tree cond;
264 int compstmt_count;
266 tree if_stmt;
268 /* Make sure there is enough space on the stack. */
269 if (if_stack_space == 0)
271 if_stack_space = 10;
272 if_stack = (if_elt *)xmalloc (10 * sizeof (if_elt));
274 else if (if_stack_space == if_stack_pointer)
276 if_stack_space += 10;
277 if_stack = (if_elt *)xrealloc (if_stack, if_stack_space * sizeof (if_elt));
280 if_stmt = build_stmt (IF_STMT, NULL_TREE, NULL_TREE, NULL_TREE);
281 IF_COND (if_stmt) = cond;
282 add_stmt (if_stmt);
284 /* Record this if statement. */
285 if_stack[if_stack_pointer].compstmt_count = compstmt_count;
286 if_stack[if_stack_pointer].file = input_filename;
287 if_stack[if_stack_pointer].line = lineno;
288 if_stack[if_stack_pointer].needs_warning = 0;
289 if_stack[if_stack_pointer].if_stmt = if_stmt;
290 if_stack_pointer++;
293 /* Called after the then-clause for an if-statement is processed. */
295 void
296 c_finish_then ()
298 tree if_stmt = if_stack[if_stack_pointer - 1].if_stmt;
299 RECHAIN_STMTS (if_stmt, THEN_CLAUSE (if_stmt));
302 /* Record the end of an if-then. Optionally warn if a nested
303 if statement had an ambiguous else clause. */
305 void
306 c_expand_end_cond ()
308 if_stack_pointer--;
309 if (if_stack[if_stack_pointer].needs_warning)
310 warning_with_file_and_line (if_stack[if_stack_pointer].file,
311 if_stack[if_stack_pointer].line,
312 "suggest explicit braces to avoid ambiguous `else'");
313 last_expr_type = NULL_TREE;
316 /* Called between the then-clause and the else-clause
317 of an if-then-else. */
319 void
320 c_expand_start_else ()
322 /* An ambiguous else warning must be generated for the enclosing if
323 statement, unless we see an else branch for that one, too. */
324 if (warn_parentheses
325 && if_stack_pointer > 1
326 && (if_stack[if_stack_pointer - 1].compstmt_count
327 == if_stack[if_stack_pointer - 2].compstmt_count))
328 if_stack[if_stack_pointer - 2].needs_warning = 1;
330 /* Even if a nested if statement had an else branch, it can't be
331 ambiguous if this one also has an else. So don't warn in that
332 case. Also don't warn for any if statements nested in this else. */
333 if_stack[if_stack_pointer - 1].needs_warning = 0;
334 if_stack[if_stack_pointer - 1].compstmt_count--;
337 /* Called after the else-clause for an if-statement is processed. */
339 void
340 c_finish_else ()
342 tree if_stmt = if_stack[if_stack_pointer - 1].if_stmt;
343 RECHAIN_STMTS (if_stmt, ELSE_CLAUSE (if_stmt));
346 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
348 void
349 declare_function_name ()
351 const char *name, *printable_name;
353 if (current_function_decl == NULL)
355 name = "";
356 printable_name = "top level";
358 else
360 /* Allow functions to be nameless (such as artificial ones). */
361 if (DECL_NAME (current_function_decl))
362 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
363 else
364 name = "";
365 printable_name = (*decl_printable_name) (current_function_decl, 2);
367 /* ISO C99 defines __func__, which is a variable, not a string
368 constant, and which is not a defined symbol at file scope. */
369 (*make_fname_decl) (func_id_node, name, 0);
372 (*make_fname_decl) (function_id_node, name, 0);
373 (*make_fname_decl) (pretty_function_id_node, printable_name, 1);
376 /* Given a chain of STRING_CST nodes,
377 concatenate them into one STRING_CST
378 and give it a suitable array-of-chars data type. */
380 tree
381 combine_strings (strings)
382 tree strings;
384 register tree value, t;
385 register int length = 1;
386 int wide_length = 0;
387 int wide_flag = 0;
388 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
389 int nchars;
390 const int nchars_max = flag_isoc99 ? 4095 : 509;
392 if (TREE_CHAIN (strings))
394 /* More than one in the chain, so concatenate. */
395 register char *p, *q;
397 /* Don't include the \0 at the end of each substring,
398 except for the last one.
399 Count wide strings and ordinary strings separately. */
400 for (t = strings; t; t = TREE_CHAIN (t))
402 if (TREE_TYPE (t) == wchar_array_type_node)
404 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
405 wide_flag = 1;
407 else
408 length += (TREE_STRING_LENGTH (t) - 1);
411 /* If anything is wide, the non-wides will be converted,
412 which makes them take more space. */
413 if (wide_flag)
414 length = length * wchar_bytes + wide_length;
416 p = alloca (length);
418 /* Copy the individual strings into the new combined string.
419 If the combined string is wide, convert the chars to ints
420 for any individual strings that are not wide. */
422 q = p;
423 for (t = strings; t; t = TREE_CHAIN (t))
425 int len = (TREE_STRING_LENGTH (t)
426 - ((TREE_TYPE (t) == wchar_array_type_node)
427 ? wchar_bytes : 1));
428 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
430 memcpy (q, TREE_STRING_POINTER (t), len);
431 q += len;
433 else
435 int i;
436 for (i = 0; i < len; i++)
438 if (WCHAR_TYPE_SIZE == HOST_BITS_PER_SHORT)
439 ((short *) q)[i] = TREE_STRING_POINTER (t)[i];
440 else
441 ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
443 q += len * wchar_bytes;
446 if (wide_flag)
448 int i;
449 for (i = 0; i < wchar_bytes; i++)
450 *q++ = 0;
452 else
453 *q = 0;
455 value = build_string (length, p);
457 else
459 value = strings;
460 length = TREE_STRING_LENGTH (value);
461 if (TREE_TYPE (value) == wchar_array_type_node)
462 wide_flag = 1;
465 /* Compute the number of elements, for the array type. */
466 nchars = wide_flag ? length / wchar_bytes : length;
468 if (pedantic && nchars - 1 > nchars_max && c_language == clk_c)
469 pedwarn ("string length `%d' is greater than the minimum length `%d' ISO C%d is required to support",
470 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
472 /* Create the array type for the string constant.
473 -Wwrite-strings says make the string constant an array of const char
474 so that copying it to a non-const pointer will get a warning.
475 For C++, this is the standard behavior. */
476 if (flag_const_strings
477 && (! flag_traditional && ! flag_writable_strings))
479 tree elements
480 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
481 1, 0);
482 TREE_TYPE (value)
483 = build_array_type (elements,
484 build_index_type (build_int_2 (nchars - 1, 0)));
486 else
487 TREE_TYPE (value)
488 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
489 build_index_type (build_int_2 (nchars - 1, 0)));
491 TREE_CONSTANT (value) = 1;
492 TREE_READONLY (value) = ! flag_writable_strings;
493 TREE_STATIC (value) = 1;
494 return value;
497 /* To speed up processing of attributes, we maintain an array of
498 IDENTIFIER_NODES and the corresponding attribute types. */
500 /* Array to hold attribute information. */
502 static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50];
504 static int attrtab_idx = 0;
506 /* Add an entry to the attribute table above. */
508 static void
509 add_attribute (id, string, min_len, max_len, decl_req)
510 enum attrs id;
511 const char *string;
512 int min_len, max_len;
513 int decl_req;
515 char buf[100];
517 attrtab[attrtab_idx].id = id;
518 attrtab[attrtab_idx].name = get_identifier (string);
519 attrtab[attrtab_idx].min = min_len;
520 attrtab[attrtab_idx].max = max_len;
521 attrtab[attrtab_idx++].decl_req = decl_req;
523 sprintf (buf, "__%s__", string);
525 attrtab[attrtab_idx].id = id;
526 attrtab[attrtab_idx].name = get_identifier (buf);
527 attrtab[attrtab_idx].min = min_len;
528 attrtab[attrtab_idx].max = max_len;
529 attrtab[attrtab_idx++].decl_req = decl_req;
532 /* Initialize attribute table. */
534 static void
535 init_attributes ()
537 add_attribute (A_PACKED, "packed", 0, 0, 0);
538 add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1);
539 add_attribute (A_COMMON, "common", 0, 0, 1);
540 add_attribute (A_NORETURN, "noreturn", 0, 0, 1);
541 add_attribute (A_NORETURN, "volatile", 0, 0, 1);
542 add_attribute (A_UNUSED, "unused", 0, 0, 0);
543 add_attribute (A_CONST, "const", 0, 0, 1);
544 add_attribute (A_T_UNION, "transparent_union", 0, 0, 0);
545 add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1);
546 add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1);
547 add_attribute (A_MODE, "mode", 1, 1, 1);
548 add_attribute (A_SECTION, "section", 1, 1, 1);
549 add_attribute (A_ALIGNED, "aligned", 0, 1, 0);
550 add_attribute (A_FORMAT, "format", 3, 3, 1);
551 add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1);
552 add_attribute (A_WEAK, "weak", 0, 0, 1);
553 add_attribute (A_ALIAS, "alias", 1, 1, 1);
554 add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
555 add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
556 add_attribute (A_MALLOC, "malloc", 0, 0, 1);
557 add_attribute (A_NO_LIMIT_STACK, "no_stack_limit", 0, 0, 1);
558 add_attribute (A_PURE, "pure", 0, 0, 1);
561 /* Default implementation of valid_lang_attribute, below. By default, there
562 are no language-specific attributes. */
564 static int
565 default_valid_lang_attribute (attr_name, attr_args, decl, type)
566 tree attr_name ATTRIBUTE_UNUSED;
567 tree attr_args ATTRIBUTE_UNUSED;
568 tree decl ATTRIBUTE_UNUSED;
569 tree type ATTRIBUTE_UNUSED;
571 return 0;
574 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
575 attribute for either declaration DECL or type TYPE and 0 otherwise. */
577 int (*valid_lang_attribute) PARAMS ((tree, tree, tree, tree))
578 = default_valid_lang_attribute;
580 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
581 and install them in NODE, which is either a DECL (including a TYPE_DECL)
582 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
583 and declaration modifiers but before the declaration proper. */
585 void
586 decl_attributes (node, attributes, prefix_attributes)
587 tree node, attributes, prefix_attributes;
589 tree decl = 0, type = 0;
590 int is_type = 0;
591 tree a;
593 if (attrtab_idx == 0)
594 init_attributes ();
596 if (DECL_P (node))
598 decl = node;
599 type = TREE_TYPE (decl);
600 is_type = TREE_CODE (node) == TYPE_DECL;
602 else if (TYPE_P (node))
603 type = node, is_type = 1;
605 #ifdef PRAGMA_INSERT_ATTRIBUTES
606 /* If the code in c-pragma.c wants to insert some attributes then
607 allow it to do so. Do this before allowing machine back ends to
608 insert attributes, so that they have the opportunity to override
609 anything done here. */
610 PRAGMA_INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
611 #endif
613 #ifdef INSERT_ATTRIBUTES
614 INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
615 #endif
617 attributes = chainon (prefix_attributes, attributes);
619 for (a = attributes; a; a = TREE_CHAIN (a))
621 tree name = TREE_PURPOSE (a);
622 tree args = TREE_VALUE (a);
623 int i;
624 enum attrs id;
626 for (i = 0; i < attrtab_idx; i++)
627 if (attrtab[i].name == name)
628 break;
630 if (i == attrtab_idx)
632 if (! valid_machine_attribute (name, args, decl, type)
633 && ! (* valid_lang_attribute) (name, args, decl, type))
634 warning ("`%s' attribute directive ignored",
635 IDENTIFIER_POINTER (name));
636 else if (decl != 0)
637 type = TREE_TYPE (decl);
638 continue;
640 else if (attrtab[i].decl_req && decl == 0)
642 warning ("`%s' attribute does not apply to types",
643 IDENTIFIER_POINTER (name));
644 continue;
646 else if (list_length (args) < attrtab[i].min
647 || list_length (args) > attrtab[i].max)
649 error ("wrong number of arguments specified for `%s' attribute",
650 IDENTIFIER_POINTER (name));
651 continue;
654 id = attrtab[i].id;
655 switch (id)
657 case A_PACKED:
658 if (is_type)
659 TYPE_PACKED (type) = 1;
660 else if (TREE_CODE (decl) == FIELD_DECL)
661 DECL_PACKED (decl) = 1;
662 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
663 used for DECL_REGISTER. It wouldn't mean anything anyway. */
664 else
665 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
666 break;
668 case A_NOCOMMON:
669 if (TREE_CODE (decl) == VAR_DECL)
670 DECL_COMMON (decl) = 0;
671 else
672 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
673 break;
675 case A_COMMON:
676 if (TREE_CODE (decl) == VAR_DECL)
677 DECL_COMMON (decl) = 1;
678 else
679 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
680 break;
682 case A_NORETURN:
683 if (TREE_CODE (decl) == FUNCTION_DECL)
684 TREE_THIS_VOLATILE (decl) = 1;
685 else if (TREE_CODE (type) == POINTER_TYPE
686 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
687 TREE_TYPE (decl) = type
688 = build_pointer_type
689 (build_type_variant (TREE_TYPE (type),
690 TREE_READONLY (TREE_TYPE (type)), 1));
691 else
692 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
693 break;
695 case A_MALLOC:
696 if (TREE_CODE (decl) == FUNCTION_DECL)
697 DECL_IS_MALLOC (decl) = 1;
698 /* ??? TODO: Support types. */
699 else
700 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
701 break;
703 case A_UNUSED:
704 if (is_type)
705 if (decl)
706 TREE_USED (decl) = 1;
707 else
708 TREE_USED (type) = 1;
709 else if (TREE_CODE (decl) == PARM_DECL
710 || TREE_CODE (decl) == VAR_DECL
711 || TREE_CODE (decl) == FUNCTION_DECL
712 || TREE_CODE (decl) == LABEL_DECL)
713 TREE_USED (decl) = 1;
714 else
715 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
716 break;
718 case A_CONST:
719 if (TREE_CODE (decl) == FUNCTION_DECL)
720 TREE_READONLY (decl) = 1;
721 else if (TREE_CODE (type) == POINTER_TYPE
722 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
723 TREE_TYPE (decl) = type
724 = build_pointer_type
725 (build_type_variant (TREE_TYPE (type), 1,
726 TREE_THIS_VOLATILE (TREE_TYPE (type))));
727 else
728 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name));
729 break;
731 case A_PURE:
732 if (TREE_CODE (decl) == FUNCTION_DECL)
733 DECL_IS_PURE (decl) = 1;
734 /* ??? TODO: Support types. */
735 else
736 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
737 break;
740 case A_T_UNION:
741 if (is_type
742 && TREE_CODE (type) == UNION_TYPE
743 && (decl == 0
744 || (TYPE_FIELDS (type) != 0
745 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))))
746 TYPE_TRANSPARENT_UNION (type) = 1;
747 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
748 && TREE_CODE (type) == UNION_TYPE
749 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))
750 DECL_TRANSPARENT_UNION (decl) = 1;
751 else
752 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
753 break;
755 case A_CONSTRUCTOR:
756 if (TREE_CODE (decl) == FUNCTION_DECL
757 && TREE_CODE (type) == FUNCTION_TYPE
758 && decl_function_context (decl) == 0)
760 DECL_STATIC_CONSTRUCTOR (decl) = 1;
761 TREE_USED (decl) = 1;
763 else
764 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
765 break;
767 case A_DESTRUCTOR:
768 if (TREE_CODE (decl) == FUNCTION_DECL
769 && TREE_CODE (type) == FUNCTION_TYPE
770 && decl_function_context (decl) == 0)
772 DECL_STATIC_DESTRUCTOR (decl) = 1;
773 TREE_USED (decl) = 1;
775 else
776 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
777 break;
779 case A_MODE:
780 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
781 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
782 else
784 int j;
785 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
786 int len = strlen (p);
787 enum machine_mode mode = VOIDmode;
788 tree typefm;
790 if (len > 4 && p[0] == '_' && p[1] == '_'
791 && p[len - 1] == '_' && p[len - 2] == '_')
793 char *newp = (char *) alloca (len - 1);
795 strcpy (newp, &p[2]);
796 newp[len - 4] = '\0';
797 p = newp;
800 /* Give this decl a type with the specified mode.
801 First check for the special modes. */
802 if (! strcmp (p, "byte"))
803 mode = byte_mode;
804 else if (!strcmp (p, "word"))
805 mode = word_mode;
806 else if (! strcmp (p, "pointer"))
807 mode = ptr_mode;
808 else
809 for (j = 0; j < NUM_MACHINE_MODES; j++)
810 if (!strcmp (p, GET_MODE_NAME (j)))
811 mode = (enum machine_mode) j;
813 if (mode == VOIDmode)
814 error ("unknown machine mode `%s'", p);
815 else if (0 == (typefm = type_for_mode (mode,
816 TREE_UNSIGNED (type))))
817 error ("no data type for mode `%s'", p);
818 else
820 if (TYPE_PRECISION (typefm) > (TREE_UNSIGNED (type)
821 ? TYPE_PRECISION(uintmax_type_node)
822 : TYPE_PRECISION(intmax_type_node))
823 && pedantic)
824 pedwarn ("type with more precision than %s",
825 TREE_UNSIGNED (type) ? "uintmax_t" : "intmax_t");
826 TREE_TYPE (decl) = type = typefm;
827 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
828 layout_decl (decl, 0);
831 break;
833 case A_SECTION:
834 #ifdef ASM_OUTPUT_SECTION_NAME
835 if ((TREE_CODE (decl) == FUNCTION_DECL
836 || TREE_CODE (decl) == VAR_DECL)
837 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
839 if (TREE_CODE (decl) == VAR_DECL
840 && current_function_decl != NULL_TREE
841 && ! TREE_STATIC (decl))
842 error_with_decl (decl,
843 "section attribute cannot be specified for local variables");
844 /* The decl may have already been given a section attribute from
845 a previous declaration. Ensure they match. */
846 else if (DECL_SECTION_NAME (decl) != NULL_TREE
847 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
848 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
849 error_with_decl (node,
850 "section of `%s' conflicts with previous declaration");
851 else
852 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
854 else
855 error_with_decl (node,
856 "section attribute not allowed for `%s'");
857 #else
858 error_with_decl (node,
859 "section attributes are not supported for this target");
860 #endif
861 break;
863 case A_ALIGNED:
865 tree align_expr
866 = (args ? TREE_VALUE (args)
867 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
868 int i;
870 /* Strip any NOPs of any kind. */
871 while (TREE_CODE (align_expr) == NOP_EXPR
872 || TREE_CODE (align_expr) == CONVERT_EXPR
873 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
874 align_expr = TREE_OPERAND (align_expr, 0);
876 if (TREE_CODE (align_expr) != INTEGER_CST)
878 error ("requested alignment is not a constant");
879 continue;
882 if ((i = tree_log2 (align_expr)) == -1)
883 error ("requested alignment is not a power of 2");
884 else if (i > HOST_BITS_PER_INT - 2)
885 error ("requested alignment is too large");
886 else if (is_type)
888 /* If we have a TYPE_DECL, then copy the type, so that we
889 don't accidentally modify a builtin type. See pushdecl. */
890 if (decl && TREE_TYPE (decl) != error_mark_node
891 && DECL_ORIGINAL_TYPE (decl) == NULL_TREE)
893 tree tt = TREE_TYPE (decl);
894 DECL_ORIGINAL_TYPE (decl) = tt;
895 tt = build_type_copy (tt);
896 TYPE_NAME (tt) = decl;
897 TREE_USED (tt) = TREE_USED (decl);
898 TREE_TYPE (decl) = tt;
899 type = tt;
902 TYPE_ALIGN (type) = (1 << i) * BITS_PER_UNIT;
903 TYPE_USER_ALIGN (type) = 1;
905 else if (TREE_CODE (decl) != VAR_DECL
906 && TREE_CODE (decl) != FIELD_DECL)
907 error_with_decl (decl,
908 "alignment may not be specified for `%s'");
909 else
911 DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
912 DECL_USER_ALIGN (decl) = 1;
915 break;
917 case A_FORMAT:
918 decl_handle_format_attribute (decl, args);
919 break;
921 case A_FORMAT_ARG:
922 decl_handle_format_arg_attribute (decl, args);
923 break;
925 case A_WEAK:
926 declare_weak (decl);
927 break;
929 case A_ALIAS:
930 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
931 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
932 error_with_decl (decl,
933 "`%s' defined both normally and as an alias");
934 else if (decl_function_context (decl) == 0)
936 tree id;
938 id = TREE_VALUE (args);
939 if (TREE_CODE (id) != STRING_CST)
941 error ("alias arg not a string");
942 break;
944 id = get_identifier (TREE_STRING_POINTER (id));
945 /* This counts as a use of the object pointed to. */
946 TREE_USED (id) = 1;
948 if (TREE_CODE (decl) == FUNCTION_DECL)
949 DECL_INITIAL (decl) = error_mark_node;
950 else
951 DECL_EXTERNAL (decl) = 0;
952 assemble_alias (decl, id);
954 else
955 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
956 break;
958 case A_NO_CHECK_MEMORY_USAGE:
959 if (TREE_CODE (decl) != FUNCTION_DECL)
961 error_with_decl (decl,
962 "`%s' attribute applies only to functions",
963 IDENTIFIER_POINTER (name));
965 else if (DECL_INITIAL (decl))
967 error_with_decl (decl,
968 "can't set `%s' attribute after definition",
969 IDENTIFIER_POINTER (name));
971 else
972 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
973 break;
975 case A_NO_INSTRUMENT_FUNCTION:
976 if (TREE_CODE (decl) != FUNCTION_DECL)
978 error_with_decl (decl,
979 "`%s' attribute applies only to functions",
980 IDENTIFIER_POINTER (name));
982 else if (DECL_INITIAL (decl))
984 error_with_decl (decl,
985 "can't set `%s' attribute after definition",
986 IDENTIFIER_POINTER (name));
988 else
989 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
990 break;
992 case A_NO_LIMIT_STACK:
993 if (TREE_CODE (decl) != FUNCTION_DECL)
995 error_with_decl (decl,
996 "`%s' attribute applies only to functions",
997 IDENTIFIER_POINTER (name));
999 else if (DECL_INITIAL (decl))
1001 error_with_decl (decl,
1002 "can't set `%s' attribute after definition",
1003 IDENTIFIER_POINTER (name));
1005 else
1006 DECL_NO_LIMIT_STACK (decl) = 1;
1007 break;
1012 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1013 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1015 The head of the declspec list is stored in DECLSPECS.
1016 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1018 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1019 the list elements. We drop the containing TREE_LIST nodes and link the
1020 resulting attributes together the way decl_attributes expects them. */
1022 void
1023 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1024 tree specs_attrs;
1025 tree *declspecs, *prefix_attributes;
1027 tree t, s, a, next, specs, attrs;
1029 /* This can happen after an __extension__ in pedantic mode. */
1030 if (specs_attrs != NULL_TREE
1031 && TREE_CODE (specs_attrs) == INTEGER_CST)
1033 *declspecs = NULL_TREE;
1034 *prefix_attributes = NULL_TREE;
1035 return;
1038 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1039 if (specs_attrs != NULL_TREE
1040 && TREE_CODE (specs_attrs) != TREE_LIST)
1042 *declspecs = specs_attrs;
1043 *prefix_attributes = NULL_TREE;
1044 return;
1047 /* Remember to keep the lists in the same order, element-wise. */
1049 specs = s = NULL_TREE;
1050 attrs = a = NULL_TREE;
1051 for (t = specs_attrs; t; t = next)
1053 next = TREE_CHAIN (t);
1054 /* Declspecs have a non-NULL TREE_VALUE. */
1055 if (TREE_VALUE (t) != NULL_TREE)
1057 if (specs == NULL_TREE)
1058 specs = s = t;
1059 else
1061 TREE_CHAIN (s) = t;
1062 s = t;
1065 else
1067 if (attrs == NULL_TREE)
1068 attrs = a = TREE_PURPOSE (t);
1069 else
1071 TREE_CHAIN (a) = TREE_PURPOSE (t);
1072 a = TREE_PURPOSE (t);
1074 /* More attrs can be linked here, move A to the end. */
1075 while (TREE_CHAIN (a) != NULL_TREE)
1076 a = TREE_CHAIN (a);
1080 /* Terminate the lists. */
1081 if (s != NULL_TREE)
1082 TREE_CHAIN (s) = NULL_TREE;
1083 if (a != NULL_TREE)
1084 TREE_CHAIN (a) = NULL_TREE;
1086 /* All done. */
1087 *declspecs = specs;
1088 *prefix_attributes = attrs;
1091 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1092 This function is used by the parser when a rule will accept attributes
1093 in a particular position, but we don't want to support that just yet.
1095 A warning is issued for every ignored attribute. */
1097 tree
1098 strip_attrs (specs_attrs)
1099 tree specs_attrs;
1101 tree specs, attrs;
1103 split_specs_attrs (specs_attrs, &specs, &attrs);
1105 while (attrs)
1107 warning ("`%s' attribute ignored",
1108 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1109 attrs = TREE_CHAIN (attrs);
1112 return specs;
1115 static int is_valid_printf_arglist PARAMS ((tree));
1116 static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
1117 static rtx c_expand_builtin_printf PARAMS ((tree, rtx, enum machine_mode,
1118 enum expand_modifier, int));
1119 static rtx c_expand_builtin_fprintf PARAMS ((tree, rtx, enum machine_mode,
1120 enum expand_modifier, int));
1122 /* Print a warning if a constant expression had overflow in folding.
1123 Invoke this function on every expression that the language
1124 requires to be a constant expression.
1125 Note the ANSI C standard says it is erroneous for a
1126 constant expression to overflow. */
1128 void
1129 constant_expression_warning (value)
1130 tree value;
1132 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
1133 || TREE_CODE (value) == COMPLEX_CST)
1134 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
1135 pedwarn ("overflow in constant expression");
1138 /* Print a warning if an expression had overflow in folding.
1139 Invoke this function on every expression that
1140 (1) appears in the source code, and
1141 (2) might be a constant expression that overflowed, and
1142 (3) is not already checked by convert_and_check;
1143 however, do not invoke this function on operands of explicit casts. */
1145 void
1146 overflow_warning (value)
1147 tree value;
1149 if ((TREE_CODE (value) == INTEGER_CST
1150 || (TREE_CODE (value) == COMPLEX_CST
1151 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
1152 && TREE_OVERFLOW (value))
1154 TREE_OVERFLOW (value) = 0;
1155 if (skip_evaluation == 0)
1156 warning ("integer overflow in expression");
1158 else if ((TREE_CODE (value) == REAL_CST
1159 || (TREE_CODE (value) == COMPLEX_CST
1160 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
1161 && TREE_OVERFLOW (value))
1163 TREE_OVERFLOW (value) = 0;
1164 if (skip_evaluation == 0)
1165 warning ("floating point overflow in expression");
1169 /* Print a warning if a large constant is truncated to unsigned,
1170 or if -Wconversion is used and a constant < 0 is converted to unsigned.
1171 Invoke this function on every expression that might be implicitly
1172 converted to an unsigned type. */
1174 void
1175 unsigned_conversion_warning (result, operand)
1176 tree result, operand;
1178 if (TREE_CODE (operand) == INTEGER_CST
1179 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
1180 && TREE_UNSIGNED (TREE_TYPE (result))
1181 && skip_evaluation == 0
1182 && !int_fits_type_p (operand, TREE_TYPE (result)))
1184 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
1185 /* This detects cases like converting -129 or 256 to unsigned char. */
1186 warning ("large integer implicitly truncated to unsigned type");
1187 else if (warn_conversion)
1188 warning ("negative integer implicitly converted to unsigned type");
1192 /* Convert EXPR to TYPE, warning about conversion problems with constants.
1193 Invoke this function on every expression that is converted implicitly,
1194 i.e. because of language rules and not because of an explicit cast. */
1196 tree
1197 convert_and_check (type, expr)
1198 tree type, expr;
1200 tree t = convert (type, expr);
1201 if (TREE_CODE (t) == INTEGER_CST)
1203 if (TREE_OVERFLOW (t))
1205 TREE_OVERFLOW (t) = 0;
1207 /* Do not diagnose overflow in a constant expression merely
1208 because a conversion overflowed. */
1209 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
1211 /* No warning for converting 0x80000000 to int. */
1212 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
1213 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
1214 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
1215 /* If EXPR fits in the unsigned version of TYPE,
1216 don't warn unless pedantic. */
1217 if ((pedantic
1218 || TREE_UNSIGNED (type)
1219 || ! int_fits_type_p (expr, unsigned_type (type)))
1220 && skip_evaluation == 0)
1221 warning ("overflow in implicit constant conversion");
1223 else
1224 unsigned_conversion_warning (t, expr);
1226 return t;
1229 /* A node in a list that describes references to variables (EXPR), which are
1230 either read accesses if WRITER is zero, or write accesses, in which case
1231 WRITER is the parent of EXPR. */
1232 struct tlist
1234 struct tlist *next;
1235 tree expr, writer;
1238 /* Used to implement a cache the results of a call to verify_tree. We only
1239 use this for SAVE_EXPRs. */
1240 struct tlist_cache
1242 struct tlist_cache *next;
1243 struct tlist *cache_before_sp;
1244 struct tlist *cache_after_sp;
1245 tree expr;
1248 /* Obstack to use when allocating tlist structures, and corresponding
1249 firstobj. */
1250 static struct obstack tlist_obstack;
1251 static char *tlist_firstobj = 0;
1253 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
1254 warnings. */
1255 static struct tlist *warned_ids;
1256 /* SAVE_EXPRs need special treatment. We process them only once and then
1257 cache the results. */
1258 static struct tlist_cache *save_expr_cache;
1260 static void add_tlist PARAMS ((struct tlist **, struct tlist *, tree, int));
1261 static void merge_tlist PARAMS ((struct tlist **, struct tlist *, int));
1262 static void verify_tree PARAMS ((tree, struct tlist **, struct tlist **, tree));
1263 static int warning_candidate_p PARAMS ((tree));
1264 static void warn_for_collisions PARAMS ((struct tlist *));
1265 static void warn_for_collisions_1 PARAMS ((tree, tree, struct tlist *, int));
1266 static struct tlist *new_tlist PARAMS ((struct tlist *, tree, tree));
1267 static void verify_sequence_points PARAMS ((tree));
1269 /* Create a new struct tlist and fill in its fields. */
1270 static struct tlist *
1271 new_tlist (next, t, writer)
1272 struct tlist *next;
1273 tree t;
1274 tree writer;
1276 struct tlist *l;
1277 l = (struct tlist *) obstack_alloc (&tlist_obstack, sizeof *l);
1278 l->next = next;
1279 l->expr = t;
1280 l->writer = writer;
1281 return l;
1284 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
1285 is nonnull, we ignore any node we find which has a writer equal to it. */
1287 static void
1288 add_tlist (to, add, exclude_writer, copy)
1289 struct tlist **to;
1290 struct tlist *add;
1291 tree exclude_writer;
1292 int copy;
1294 while (add)
1296 struct tlist *next = add->next;
1297 if (! copy)
1298 add->next = *to;
1299 if (! exclude_writer || add->writer != exclude_writer)
1300 *to = copy ? new_tlist (*to, add->expr, add->writer) : add;
1301 add = next;
1305 /* Merge the nodes of ADD into TO. This merging process is done so that for
1306 each variable that already exists in TO, no new node is added; however if
1307 there is a write access recorded in ADD, and an occurrence on TO is only
1308 a read access, then the occurrence in TO will be modified to record the
1309 write. */
1311 static void
1312 merge_tlist (to, add, copy)
1313 struct tlist **to;
1314 struct tlist *add;
1315 int copy;
1317 struct tlist **end = to;
1319 while (*end)
1320 end = &(*end)->next;
1322 while (add)
1324 int found = 0;
1325 struct tlist *tmp2;
1326 struct tlist *next = add->next;
1328 for (tmp2 = *to; tmp2; tmp2 = tmp2->next)
1329 if (tmp2->expr == add->expr)
1331 found = 1;
1332 if (! tmp2->writer)
1333 tmp2->writer = add->writer;
1335 if (! found)
1337 *end = copy ? add : new_tlist (NULL, add->expr, add->writer);
1338 end = &(*end)->next;
1339 *end = 0;
1341 add = next;
1345 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
1346 references in list LIST conflict with it, excluding reads if ONLY writers
1347 is nonzero. */
1349 static void
1350 warn_for_collisions_1 (written, writer, list, only_writes)
1351 tree written, writer;
1352 struct tlist *list;
1353 int only_writes;
1355 struct tlist *tmp;
1357 /* Avoid duplicate warnings. */
1358 for (tmp = warned_ids; tmp; tmp = tmp->next)
1359 if (tmp->expr == written)
1360 return;
1362 while (list)
1364 if (list->expr == written
1365 && list->writer != writer
1366 && (! only_writes || list->writer))
1368 warned_ids = new_tlist (warned_ids, written, NULL_TREE);
1369 warning ("operation on `%s' may be undefined",
1370 IDENTIFIER_POINTER (DECL_NAME (list->expr)));
1372 list = list->next;
1376 /* Given a list LIST of references to variables, find whether any of these
1377 can cause conflicts due to missing sequence points. */
1379 static void
1380 warn_for_collisions (list)
1381 struct tlist *list;
1383 struct tlist *tmp;
1385 for (tmp = list; tmp; tmp = tmp->next)
1387 if (tmp->writer)
1388 warn_for_collisions_1 (tmp->expr, tmp->writer, list, 0);
1392 /* Return nonzero if X is a tree that can be verified by the sequence poitn
1393 warnings. */
1394 static int
1395 warning_candidate_p (x)
1396 tree x;
1398 return TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == PARM_DECL;
1401 /* Walk the tree X, and record accesses to variables. If X is written by the
1402 parent tree, WRITER is the parent.
1403 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
1404 expression or its only operand forces a sequence point, then everything up
1405 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
1406 in PNO_SP.
1407 Once we return, we will have emitted warnings if any subexpression before
1408 such a sequence point could be undefined. On a higher level, however, the
1409 sequence point may not be relevant, and we'll merge the two lists.
1411 Example: (b++, a) + b;
1412 The call that processes the COMPOUND_EXPR will store the increment of B
1413 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
1414 processes the PLUS_EXPR will need to merge the two lists so that
1415 eventually, all accesses end up on the same list (and we'll warn about the
1416 unordered subexpressions b++ and b.
1418 A note on merging. If we modify the former example so that our expression
1419 becomes
1420 (b++, b) + a
1421 care must be taken not simply to add all three expressions into the final
1422 PNO_SP list. The function merge_tlist takes care of that by merging the
1423 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
1424 way, so that no more than one access to B is recorded. */
1426 static void
1427 verify_tree (x, pbefore_sp, pno_sp, writer)
1428 tree x;
1429 struct tlist **pbefore_sp, **pno_sp;
1430 tree writer;
1432 struct tlist *tmp_before, *tmp_nosp, *tmp_list2, *tmp_list3;
1433 enum tree_code code;
1434 char class;
1436 restart:
1437 code = TREE_CODE (x);
1438 class = TREE_CODE_CLASS (code);
1440 if (warning_candidate_p (x))
1442 *pno_sp = new_tlist (*pno_sp, x, writer);
1443 return;
1446 switch (code)
1448 case CONSTRUCTOR:
1449 return;
1451 case COMPOUND_EXPR:
1452 case TRUTH_ANDIF_EXPR:
1453 case TRUTH_ORIF_EXPR:
1454 tmp_before = tmp_nosp = tmp_list3 = 0;
1455 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
1456 warn_for_collisions (tmp_nosp);
1457 merge_tlist (pbefore_sp, tmp_before, 0);
1458 merge_tlist (pbefore_sp, tmp_nosp, 0);
1459 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, pno_sp, NULL_TREE);
1460 merge_tlist (pbefore_sp, tmp_list3, 0);
1461 return;
1463 case COND_EXPR:
1464 tmp_before = tmp_list2 = 0;
1465 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_list2, NULL_TREE);
1466 warn_for_collisions (tmp_list2);
1467 merge_tlist (pbefore_sp, tmp_before, 0);
1468 merge_tlist (pbefore_sp, tmp_list2, 1);
1470 tmp_list3 = tmp_nosp = 0;
1471 verify_tree (TREE_OPERAND (x, 1), &tmp_list3, &tmp_nosp, NULL_TREE);
1472 warn_for_collisions (tmp_nosp);
1473 merge_tlist (pbefore_sp, tmp_list3, 0);
1475 tmp_list3 = tmp_list2 = 0;
1476 verify_tree (TREE_OPERAND (x, 2), &tmp_list3, &tmp_list2, NULL_TREE);
1477 warn_for_collisions (tmp_list2);
1478 merge_tlist (pbefore_sp, tmp_list3, 0);
1479 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
1480 two first, to avoid warning for (a ? b++ : b++). */
1481 merge_tlist (&tmp_nosp, tmp_list2, 0);
1482 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
1483 return;
1485 case PREDECREMENT_EXPR:
1486 case PREINCREMENT_EXPR:
1487 case POSTDECREMENT_EXPR:
1488 case POSTINCREMENT_EXPR:
1489 verify_tree (TREE_OPERAND (x, 0), pno_sp, pno_sp, x);
1490 return;
1492 case MODIFY_EXPR:
1493 tmp_before = tmp_nosp = tmp_list3 = 0;
1494 verify_tree (TREE_OPERAND (x, 1), &tmp_before, &tmp_nosp, NULL_TREE);
1495 verify_tree (TREE_OPERAND (x, 0), &tmp_list3, &tmp_list3, x);
1496 /* Expressions inside the LHS are not ordered wrt. the sequence points
1497 in the RHS. Example:
1498 *a = (a++, 2)
1499 Despite the fact that the modification of "a" is in the before_sp
1500 list (tmp_before), it conflicts with the use of "a" in the LHS.
1501 We can handle this by adding the contents of tmp_list3
1502 to those of tmp_before, and redoing the collision warnings for that
1503 list. */
1504 add_tlist (&tmp_before, tmp_list3, x, 1);
1505 warn_for_collisions (tmp_before);
1506 /* Exclude the LHS itself here; we first have to merge it into the
1507 tmp_nosp list. This is done to avoid warning for "a = a"; if we
1508 didn't exclude the LHS, we'd get it twice, once as a read and once
1509 as a write. */
1510 add_tlist (pno_sp, tmp_list3, x, 0);
1511 warn_for_collisions_1 (TREE_OPERAND (x, 0), x, tmp_nosp, 1);
1513 merge_tlist (pbefore_sp, tmp_before, 0);
1514 if (warning_candidate_p (TREE_OPERAND (x, 0)))
1515 merge_tlist (&tmp_nosp, new_tlist (NULL, TREE_OPERAND (x, 0), x), 0);
1516 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 1);
1517 return;
1519 case CALL_EXPR:
1520 /* We need to warn about conflicts among arguments and conflicts between
1521 args and the function address. Side effects of the function address,
1522 however, are not ordered by the sequence point of the call. */
1523 tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0;
1524 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
1525 if (TREE_OPERAND (x, 1))
1526 verify_tree (TREE_OPERAND (x, 1), &tmp_list2, &tmp_list3, NULL_TREE);
1527 merge_tlist (&tmp_list3, tmp_list2, 0);
1528 add_tlist (&tmp_before, tmp_list3, NULL_TREE, 0);
1529 add_tlist (&tmp_before, tmp_nosp, NULL_TREE, 0);
1530 warn_for_collisions (tmp_before);
1531 add_tlist (pbefore_sp, tmp_before, NULL_TREE, 0);
1532 return;
1534 case TREE_LIST:
1535 /* Scan all the list, e.g. indices of multi dimensional array. */
1536 while (x)
1538 tmp_before = tmp_nosp = 0;
1539 verify_tree (TREE_VALUE (x), &tmp_before, &tmp_nosp, NULL_TREE);
1540 merge_tlist (&tmp_nosp, tmp_before, 0);
1541 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
1542 x = TREE_CHAIN (x);
1544 return;
1546 case SAVE_EXPR:
1548 struct tlist_cache *t;
1549 for (t = save_expr_cache; t; t = t->next)
1550 if (t->expr == x)
1551 break;
1553 if (! t)
1555 t = (struct tlist_cache *) obstack_alloc (&tlist_obstack,
1556 sizeof *t);
1557 t->next = save_expr_cache;
1558 t->expr = x;
1559 save_expr_cache = t;
1561 tmp_before = tmp_nosp = 0;
1562 verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE);
1563 warn_for_collisions (tmp_nosp);
1565 tmp_list3 = 0;
1566 while (tmp_nosp)
1568 struct tlist *t = tmp_nosp;
1569 tmp_nosp = t->next;
1570 merge_tlist (&tmp_list3, t, 0);
1572 t->cache_before_sp = tmp_before;
1573 t->cache_after_sp = tmp_list3;
1575 merge_tlist (pbefore_sp, t->cache_before_sp, 1);
1576 add_tlist (pno_sp, t->cache_after_sp, NULL_TREE, 1);
1577 return;
1579 default:
1580 break;
1583 if (class == '1')
1585 if (first_rtl_op (code) == 0)
1586 return;
1587 x = TREE_OPERAND (x, 0);
1588 writer = 0;
1589 goto restart;
1592 switch (class)
1594 case 'r':
1595 case '<':
1596 case '2':
1597 case 'b':
1598 case 'e':
1599 case 's':
1600 case 'x':
1602 int lp;
1603 int max = first_rtl_op (TREE_CODE (x));
1604 for (lp = 0; lp < max; lp++)
1606 tmp_before = tmp_nosp = 0;
1607 verify_tree (TREE_OPERAND (x, lp), &tmp_before, &tmp_nosp, NULL_TREE);
1608 merge_tlist (&tmp_nosp, tmp_before, 0);
1609 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
1611 break;
1616 /* Try to warn for undefined behaviour in EXPR due to missing sequence
1617 points. */
1619 static void
1620 verify_sequence_points (expr)
1621 tree expr;
1623 struct tlist *before_sp = 0, *after_sp = 0;
1625 warned_ids = 0;
1626 save_expr_cache = 0;
1627 if (tlist_firstobj == 0)
1629 gcc_obstack_init (&tlist_obstack);
1630 tlist_firstobj = obstack_alloc (&tlist_obstack, 0);
1633 verify_tree (expr, &before_sp, &after_sp, 0);
1634 warn_for_collisions (after_sp);
1635 obstack_free (&tlist_obstack, tlist_firstobj);
1638 tree
1639 c_expand_expr_stmt (expr)
1640 tree expr;
1642 /* Do default conversion if safe and possibly important,
1643 in case within ({...}). */
1644 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
1645 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
1646 expr = default_conversion (expr);
1648 if (warn_sequence_point)
1649 verify_sequence_points (expr);
1651 if (TREE_TYPE (expr) != error_mark_node
1652 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr))
1653 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
1654 error ("expression statement has incomplete type");
1656 last_expr_type = TREE_TYPE (expr);
1657 return add_stmt (build_stmt (EXPR_STMT, expr));
1660 /* Validate the expression after `case' and apply default promotions. */
1662 tree
1663 check_case_value (value)
1664 tree value;
1666 if (value == NULL_TREE)
1667 return value;
1669 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1670 STRIP_TYPE_NOPS (value);
1671 /* In C++, the following is allowed:
1673 const int i = 3;
1674 switch (...) { case i: ... }
1676 So, we try to reduce the VALUE to a constant that way. */
1677 if (c_language == clk_cplusplus)
1679 value = decl_constant_value (value);
1680 STRIP_TYPE_NOPS (value);
1681 value = fold (value);
1684 if (TREE_CODE (value) != INTEGER_CST
1685 && value != error_mark_node)
1687 error ("case label does not reduce to an integer constant");
1688 value = error_mark_node;
1690 else
1691 /* Promote char or short to int. */
1692 value = default_conversion (value);
1694 constant_expression_warning (value);
1696 return value;
1699 /* Return an integer type with BITS bits of precision,
1700 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
1702 tree
1703 type_for_size (bits, unsignedp)
1704 unsigned bits;
1705 int unsignedp;
1707 if (bits == TYPE_PRECISION (integer_type_node))
1708 return unsignedp ? unsigned_type_node : integer_type_node;
1710 if (bits == TYPE_PRECISION (signed_char_type_node))
1711 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1713 if (bits == TYPE_PRECISION (short_integer_type_node))
1714 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1716 if (bits == TYPE_PRECISION (long_integer_type_node))
1717 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1719 if (bits == TYPE_PRECISION (long_long_integer_type_node))
1720 return (unsignedp ? long_long_unsigned_type_node
1721 : long_long_integer_type_node);
1723 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
1724 return (unsignedp ? widest_unsigned_literal_type_node
1725 : widest_integer_literal_type_node);
1727 if (bits <= TYPE_PRECISION (intQI_type_node))
1728 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
1730 if (bits <= TYPE_PRECISION (intHI_type_node))
1731 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
1733 if (bits <= TYPE_PRECISION (intSI_type_node))
1734 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
1736 if (bits <= TYPE_PRECISION (intDI_type_node))
1737 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
1739 return 0;
1742 /* Return a data type that has machine mode MODE.
1743 If the mode is an integer,
1744 then UNSIGNEDP selects between signed and unsigned types. */
1746 tree
1747 type_for_mode (mode, unsignedp)
1748 enum machine_mode mode;
1749 int unsignedp;
1751 if (mode == TYPE_MODE (integer_type_node))
1752 return unsignedp ? unsigned_type_node : integer_type_node;
1754 if (mode == TYPE_MODE (signed_char_type_node))
1755 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1757 if (mode == TYPE_MODE (short_integer_type_node))
1758 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1760 if (mode == TYPE_MODE (long_integer_type_node))
1761 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1763 if (mode == TYPE_MODE (long_long_integer_type_node))
1764 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
1766 if (mode == TYPE_MODE (widest_integer_literal_type_node))
1767 return unsignedp ? widest_unsigned_literal_type_node
1768 : widest_integer_literal_type_node;
1770 if (mode == TYPE_MODE (intQI_type_node))
1771 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
1773 if (mode == TYPE_MODE (intHI_type_node))
1774 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
1776 if (mode == TYPE_MODE (intSI_type_node))
1777 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
1779 if (mode == TYPE_MODE (intDI_type_node))
1780 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
1782 #if HOST_BITS_PER_WIDE_INT >= 64
1783 if (mode == TYPE_MODE (intTI_type_node))
1784 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
1785 #endif
1787 if (mode == TYPE_MODE (float_type_node))
1788 return float_type_node;
1790 if (mode == TYPE_MODE (double_type_node))
1791 return double_type_node;
1793 if (mode == TYPE_MODE (long_double_type_node))
1794 return long_double_type_node;
1796 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
1797 return build_pointer_type (char_type_node);
1799 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
1800 return build_pointer_type (integer_type_node);
1802 #ifdef VECTOR_MODE_SUPPORTED_P
1803 if (mode == TYPE_MODE (V4SF_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
1804 return V4SF_type_node;
1805 if (mode == TYPE_MODE (V4SI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
1806 return V4SI_type_node;
1807 if (mode == TYPE_MODE (V2SI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
1808 return V2SI_type_node;
1809 if (mode == TYPE_MODE (V4HI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
1810 return V4HI_type_node;
1811 if (mode == TYPE_MODE (V8QI_type_node) && VECTOR_MODE_SUPPORTED_P (mode))
1812 return V8QI_type_node;
1813 #endif
1815 return 0;
1818 /* Return an unsigned type the same as TYPE in other respects. */
1819 tree
1820 unsigned_type (type)
1821 tree type;
1823 tree type1 = TYPE_MAIN_VARIANT (type);
1824 if (type1 == signed_char_type_node || type1 == char_type_node)
1825 return unsigned_char_type_node;
1826 if (type1 == integer_type_node)
1827 return unsigned_type_node;
1828 if (type1 == short_integer_type_node)
1829 return short_unsigned_type_node;
1830 if (type1 == long_integer_type_node)
1831 return long_unsigned_type_node;
1832 if (type1 == long_long_integer_type_node)
1833 return long_long_unsigned_type_node;
1834 if (type1 == widest_integer_literal_type_node)
1835 return widest_unsigned_literal_type_node;
1836 #if HOST_BITS_PER_WIDE_INT >= 64
1837 if (type1 == intTI_type_node)
1838 return unsigned_intTI_type_node;
1839 #endif
1840 if (type1 == intDI_type_node)
1841 return unsigned_intDI_type_node;
1842 if (type1 == intSI_type_node)
1843 return unsigned_intSI_type_node;
1844 if (type1 == intHI_type_node)
1845 return unsigned_intHI_type_node;
1846 if (type1 == intQI_type_node)
1847 return unsigned_intQI_type_node;
1849 return signed_or_unsigned_type (1, type);
1852 /* Return a signed type the same as TYPE in other respects. */
1854 tree
1855 signed_type (type)
1856 tree type;
1858 tree type1 = TYPE_MAIN_VARIANT (type);
1859 if (type1 == unsigned_char_type_node || type1 == char_type_node)
1860 return signed_char_type_node;
1861 if (type1 == unsigned_type_node)
1862 return integer_type_node;
1863 if (type1 == short_unsigned_type_node)
1864 return short_integer_type_node;
1865 if (type1 == long_unsigned_type_node)
1866 return long_integer_type_node;
1867 if (type1 == long_long_unsigned_type_node)
1868 return long_long_integer_type_node;
1869 if (type1 == widest_unsigned_literal_type_node)
1870 return widest_integer_literal_type_node;
1871 #if HOST_BITS_PER_WIDE_INT >= 64
1872 if (type1 == unsigned_intTI_type_node)
1873 return intTI_type_node;
1874 #endif
1875 if (type1 == unsigned_intDI_type_node)
1876 return intDI_type_node;
1877 if (type1 == unsigned_intSI_type_node)
1878 return intSI_type_node;
1879 if (type1 == unsigned_intHI_type_node)
1880 return intHI_type_node;
1881 if (type1 == unsigned_intQI_type_node)
1882 return intQI_type_node;
1884 return signed_or_unsigned_type (0, type);
1887 /* Return a type the same as TYPE except unsigned or
1888 signed according to UNSIGNEDP. */
1890 tree
1891 signed_or_unsigned_type (unsignedp, type)
1892 int unsignedp;
1893 tree type;
1895 if (! INTEGRAL_TYPE_P (type)
1896 || TREE_UNSIGNED (type) == unsignedp)
1897 return type;
1899 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
1900 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1901 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1902 return unsignedp ? unsigned_type_node : integer_type_node;
1903 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
1904 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1905 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
1906 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1907 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
1908 return (unsignedp ? long_long_unsigned_type_node
1909 : long_long_integer_type_node);
1910 if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
1911 return (unsignedp ? widest_unsigned_literal_type_node
1912 : widest_integer_literal_type_node);
1913 return type;
1916 /* Return the minimum number of bits needed to represent VALUE in a
1917 signed or unsigned type, UNSIGNEDP says which. */
1919 unsigned int
1920 min_precision (value, unsignedp)
1921 tree value;
1922 int unsignedp;
1924 int log;
1926 /* If the value is negative, compute its negative minus 1. The latter
1927 adjustment is because the absolute value of the largest negative value
1928 is one larger than the largest positive value. This is equivalent to
1929 a bit-wise negation, so use that operation instead. */
1931 if (tree_int_cst_sgn (value) < 0)
1932 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
1934 /* Return the number of bits needed, taking into account the fact
1935 that we need one more bit for a signed than unsigned type. */
1937 if (integer_zerop (value))
1938 log = 0;
1939 else
1940 log = tree_floor_log2 (value);
1942 return log + 1 + ! unsignedp;
1945 /* Print an error message for invalid operands to arith operation CODE.
1946 NOP_EXPR is used as a special case (see truthvalue_conversion). */
1948 void
1949 binary_op_error (code)
1950 enum tree_code code;
1952 register const char *opname;
1954 switch (code)
1956 case NOP_EXPR:
1957 error ("invalid truth-value expression");
1958 return;
1960 case PLUS_EXPR:
1961 opname = "+"; break;
1962 case MINUS_EXPR:
1963 opname = "-"; break;
1964 case MULT_EXPR:
1965 opname = "*"; break;
1966 case MAX_EXPR:
1967 opname = "max"; break;
1968 case MIN_EXPR:
1969 opname = "min"; break;
1970 case EQ_EXPR:
1971 opname = "=="; break;
1972 case NE_EXPR:
1973 opname = "!="; break;
1974 case LE_EXPR:
1975 opname = "<="; break;
1976 case GE_EXPR:
1977 opname = ">="; break;
1978 case LT_EXPR:
1979 opname = "<"; break;
1980 case GT_EXPR:
1981 opname = ">"; break;
1982 case LSHIFT_EXPR:
1983 opname = "<<"; break;
1984 case RSHIFT_EXPR:
1985 opname = ">>"; break;
1986 case TRUNC_MOD_EXPR:
1987 case FLOOR_MOD_EXPR:
1988 opname = "%"; break;
1989 case TRUNC_DIV_EXPR:
1990 case FLOOR_DIV_EXPR:
1991 opname = "/"; break;
1992 case BIT_AND_EXPR:
1993 opname = "&"; break;
1994 case BIT_IOR_EXPR:
1995 opname = "|"; break;
1996 case TRUTH_ANDIF_EXPR:
1997 opname = "&&"; break;
1998 case TRUTH_ORIF_EXPR:
1999 opname = "||"; break;
2000 case BIT_XOR_EXPR:
2001 opname = "^"; break;
2002 case LROTATE_EXPR:
2003 case RROTATE_EXPR:
2004 opname = "rotate"; break;
2005 default:
2006 opname = "unknown"; break;
2008 error ("invalid operands to binary %s", opname);
2011 /* Subroutine of build_binary_op, used for comparison operations.
2012 See if the operands have both been converted from subword integer types
2013 and, if so, perhaps change them both back to their original type.
2014 This function is also responsible for converting the two operands
2015 to the proper common type for comparison.
2017 The arguments of this function are all pointers to local variables
2018 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2019 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2021 If this function returns nonzero, it means that the comparison has
2022 a constant value. What this function returns is an expression for
2023 that value. */
2025 tree
2026 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
2027 tree *op0_ptr, *op1_ptr;
2028 tree *restype_ptr;
2029 enum tree_code *rescode_ptr;
2031 register tree type;
2032 tree op0 = *op0_ptr;
2033 tree op1 = *op1_ptr;
2034 int unsignedp0, unsignedp1;
2035 int real1, real2;
2036 tree primop0, primop1;
2037 enum tree_code code = *rescode_ptr;
2039 /* Throw away any conversions to wider types
2040 already present in the operands. */
2042 primop0 = get_narrower (op0, &unsignedp0);
2043 primop1 = get_narrower (op1, &unsignedp1);
2045 /* Handle the case that OP0 does not *contain* a conversion
2046 but it *requires* conversion to FINAL_TYPE. */
2048 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
2049 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
2050 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
2051 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
2053 /* If one of the operands must be floated, we cannot optimize. */
2054 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
2055 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
2057 /* If first arg is constant, swap the args (changing operation
2058 so value is preserved), for canonicalization. Don't do this if
2059 the second arg is 0. */
2061 if (TREE_CONSTANT (primop0)
2062 && ! integer_zerop (primop1) && ! real_zerop (primop1))
2064 register tree tem = primop0;
2065 register int temi = unsignedp0;
2066 primop0 = primop1;
2067 primop1 = tem;
2068 tem = op0;
2069 op0 = op1;
2070 op1 = tem;
2071 *op0_ptr = op0;
2072 *op1_ptr = op1;
2073 unsignedp0 = unsignedp1;
2074 unsignedp1 = temi;
2075 temi = real1;
2076 real1 = real2;
2077 real2 = temi;
2079 switch (code)
2081 case LT_EXPR:
2082 code = GT_EXPR;
2083 break;
2084 case GT_EXPR:
2085 code = LT_EXPR;
2086 break;
2087 case LE_EXPR:
2088 code = GE_EXPR;
2089 break;
2090 case GE_EXPR:
2091 code = LE_EXPR;
2092 break;
2093 default:
2094 break;
2096 *rescode_ptr = code;
2099 /* If comparing an integer against a constant more bits wide,
2100 maybe we can deduce a value of 1 or 0 independent of the data.
2101 Or else truncate the constant now
2102 rather than extend the variable at run time.
2104 This is only interesting if the constant is the wider arg.
2105 Also, it is not safe if the constant is unsigned and the
2106 variable arg is signed, since in this case the variable
2107 would be sign-extended and then regarded as unsigned.
2108 Our technique fails in this case because the lowest/highest
2109 possible unsigned results don't follow naturally from the
2110 lowest/highest possible values of the variable operand.
2111 For just EQ_EXPR and NE_EXPR there is another technique that
2112 could be used: see if the constant can be faithfully represented
2113 in the other operand's type, by truncating it and reextending it
2114 and see if that preserves the constant's value. */
2116 if (!real1 && !real2
2117 && TREE_CODE (primop1) == INTEGER_CST
2118 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
2120 int min_gt, max_gt, min_lt, max_lt;
2121 tree maxval, minval;
2122 /* 1 if comparison is nominally unsigned. */
2123 int unsignedp = TREE_UNSIGNED (*restype_ptr);
2124 tree val;
2126 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
2128 /* If TYPE is an enumeration, then we need to get its min/max
2129 values from it's underlying integral type, not the enumerated
2130 type itself. */
2131 if (TREE_CODE (type) == ENUMERAL_TYPE)
2132 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
2134 maxval = TYPE_MAX_VALUE (type);
2135 minval = TYPE_MIN_VALUE (type);
2137 if (unsignedp && !unsignedp0)
2138 *restype_ptr = signed_type (*restype_ptr);
2140 if (TREE_TYPE (primop1) != *restype_ptr)
2141 primop1 = convert (*restype_ptr, primop1);
2142 if (type != *restype_ptr)
2144 minval = convert (*restype_ptr, minval);
2145 maxval = convert (*restype_ptr, maxval);
2148 if (unsignedp && unsignedp0)
2150 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
2151 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
2152 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
2153 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
2155 else
2157 min_gt = INT_CST_LT (primop1, minval);
2158 max_gt = INT_CST_LT (primop1, maxval);
2159 min_lt = INT_CST_LT (minval, primop1);
2160 max_lt = INT_CST_LT (maxval, primop1);
2163 val = 0;
2164 /* This used to be a switch, but Genix compiler can't handle that. */
2165 if (code == NE_EXPR)
2167 if (max_lt || min_gt)
2168 val = boolean_true_node;
2170 else if (code == EQ_EXPR)
2172 if (max_lt || min_gt)
2173 val = boolean_false_node;
2175 else if (code == LT_EXPR)
2177 if (max_lt)
2178 val = boolean_true_node;
2179 if (!min_lt)
2180 val = boolean_false_node;
2182 else if (code == GT_EXPR)
2184 if (min_gt)
2185 val = boolean_true_node;
2186 if (!max_gt)
2187 val = boolean_false_node;
2189 else if (code == LE_EXPR)
2191 if (!max_gt)
2192 val = boolean_true_node;
2193 if (min_gt)
2194 val = boolean_false_node;
2196 else if (code == GE_EXPR)
2198 if (!min_lt)
2199 val = boolean_true_node;
2200 if (max_lt)
2201 val = boolean_false_node;
2204 /* If primop0 was sign-extended and unsigned comparison specd,
2205 we did a signed comparison above using the signed type bounds.
2206 But the comparison we output must be unsigned.
2208 Also, for inequalities, VAL is no good; but if the signed
2209 comparison had *any* fixed result, it follows that the
2210 unsigned comparison just tests the sign in reverse
2211 (positive values are LE, negative ones GE).
2212 So we can generate an unsigned comparison
2213 against an extreme value of the signed type. */
2215 if (unsignedp && !unsignedp0)
2217 if (val != 0)
2218 switch (code)
2220 case LT_EXPR:
2221 case GE_EXPR:
2222 primop1 = TYPE_MIN_VALUE (type);
2223 val = 0;
2224 break;
2226 case LE_EXPR:
2227 case GT_EXPR:
2228 primop1 = TYPE_MAX_VALUE (type);
2229 val = 0;
2230 break;
2232 default:
2233 break;
2235 type = unsigned_type (type);
2238 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2240 /* This is the case of (char)x >?< 0x80, which people used to use
2241 expecting old C compilers to change the 0x80 into -0x80. */
2242 if (val == boolean_false_node)
2243 warning ("comparison is always false due to limited range of data type");
2244 if (val == boolean_true_node)
2245 warning ("comparison is always true due to limited range of data type");
2248 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2250 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2251 if (val == boolean_false_node)
2252 warning ("comparison is always false due to limited range of data type");
2253 if (val == boolean_true_node)
2254 warning ("comparison is always true due to limited range of data type");
2257 if (val != 0)
2259 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2260 if (TREE_SIDE_EFFECTS (primop0))
2261 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
2262 return val;
2265 /* Value is not predetermined, but do the comparison
2266 in the type of the operand that is not constant.
2267 TYPE is already properly set. */
2269 else if (real1 && real2
2270 && (TYPE_PRECISION (TREE_TYPE (primop0))
2271 == TYPE_PRECISION (TREE_TYPE (primop1))))
2272 type = TREE_TYPE (primop0);
2274 /* If args' natural types are both narrower than nominal type
2275 and both extend in the same manner, compare them
2276 in the type of the wider arg.
2277 Otherwise must actually extend both to the nominal
2278 common type lest different ways of extending
2279 alter the result.
2280 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2282 else if (unsignedp0 == unsignedp1 && real1 == real2
2283 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
2284 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
2286 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
2287 type = signed_or_unsigned_type (unsignedp0
2288 || TREE_UNSIGNED (*restype_ptr),
2289 type);
2290 /* Make sure shorter operand is extended the right way
2291 to match the longer operand. */
2292 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
2293 primop0);
2294 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
2295 primop1);
2297 else
2299 /* Here we must do the comparison on the nominal type
2300 using the args exactly as we received them. */
2301 type = *restype_ptr;
2302 primop0 = op0;
2303 primop1 = op1;
2305 if (!real1 && !real2 && integer_zerop (primop1)
2306 && TREE_UNSIGNED (*restype_ptr))
2308 tree value = 0;
2309 switch (code)
2311 case GE_EXPR:
2312 /* All unsigned values are >= 0, so we warn if extra warnings
2313 are requested. However, if OP0 is a constant that is
2314 >= 0, the signedness of the comparison isn't an issue,
2315 so suppress the warning. */
2316 if (extra_warnings && !in_system_header
2317 && ! (TREE_CODE (primop0) == INTEGER_CST
2318 && ! TREE_OVERFLOW (convert (signed_type (type),
2319 primop0))))
2320 warning ("comparison of unsigned expression >= 0 is always true");
2321 value = boolean_true_node;
2322 break;
2324 case LT_EXPR:
2325 if (extra_warnings && !in_system_header
2326 && ! (TREE_CODE (primop0) == INTEGER_CST
2327 && ! TREE_OVERFLOW (convert (signed_type (type),
2328 primop0))))
2329 warning ("comparison of unsigned expression < 0 is always false");
2330 value = boolean_false_node;
2331 break;
2333 default:
2334 break;
2337 if (value != 0)
2339 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2340 if (TREE_SIDE_EFFECTS (primop0))
2341 return build (COMPOUND_EXPR, TREE_TYPE (value),
2342 primop0, value);
2343 return value;
2348 *op0_ptr = convert (type, primop0);
2349 *op1_ptr = convert (type, primop1);
2351 *restype_ptr = boolean_type_node;
2353 return 0;
2356 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2357 or validate its data type for an `if' or `while' statement or ?..: exp.
2359 This preparation consists of taking the ordinary
2360 representation of an expression expr and producing a valid tree
2361 boolean expression describing whether expr is nonzero. We could
2362 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2363 but we optimize comparisons, &&, ||, and !.
2365 The resulting type should always be `boolean_type_node'. */
2367 tree
2368 truthvalue_conversion (expr)
2369 tree expr;
2371 if (TREE_CODE (expr) == ERROR_MARK)
2372 return expr;
2374 #if 0 /* This appears to be wrong for C++. */
2375 /* These really should return error_mark_node after 2.4 is stable.
2376 But not all callers handle ERROR_MARK properly. */
2377 switch (TREE_CODE (TREE_TYPE (expr)))
2379 case RECORD_TYPE:
2380 error ("struct type value used where scalar is required");
2381 return boolean_false_node;
2383 case UNION_TYPE:
2384 error ("union type value used where scalar is required");
2385 return boolean_false_node;
2387 case ARRAY_TYPE:
2388 error ("array type value used where scalar is required");
2389 return boolean_false_node;
2391 default:
2392 break;
2394 #endif /* 0 */
2396 switch (TREE_CODE (expr))
2398 case EQ_EXPR:
2399 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
2400 case TRUTH_ANDIF_EXPR:
2401 case TRUTH_ORIF_EXPR:
2402 case TRUTH_AND_EXPR:
2403 case TRUTH_OR_EXPR:
2404 case TRUTH_XOR_EXPR:
2405 case TRUTH_NOT_EXPR:
2406 TREE_TYPE (expr) = boolean_type_node;
2407 return expr;
2409 case ERROR_MARK:
2410 return expr;
2412 case INTEGER_CST:
2413 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
2415 case REAL_CST:
2416 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
2418 case ADDR_EXPR:
2419 /* If we are taking the address of a external decl, it might be zero
2420 if it is weak, so we cannot optimize. */
2421 if (DECL_P (TREE_OPERAND (expr, 0))
2422 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
2423 break;
2425 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
2426 return build (COMPOUND_EXPR, boolean_type_node,
2427 TREE_OPERAND (expr, 0), boolean_true_node);
2428 else
2429 return boolean_true_node;
2431 case COMPLEX_EXPR:
2432 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2433 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2434 truthvalue_conversion (TREE_OPERAND (expr, 0)),
2435 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2438 case NEGATE_EXPR:
2439 case ABS_EXPR:
2440 case FLOAT_EXPR:
2441 case FFS_EXPR:
2442 /* These don't change whether an object is non-zero or zero. */
2443 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2445 case LROTATE_EXPR:
2446 case RROTATE_EXPR:
2447 /* These don't change whether an object is zero or non-zero, but
2448 we can't ignore them if their second arg has side-effects. */
2449 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2450 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2451 truthvalue_conversion (TREE_OPERAND (expr, 0)));
2452 else
2453 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2455 case COND_EXPR:
2456 /* Distribute the conversion into the arms of a COND_EXPR. */
2457 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2458 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2459 truthvalue_conversion (TREE_OPERAND (expr, 2))));
2461 case CONVERT_EXPR:
2462 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2463 since that affects how `default_conversion' will behave. */
2464 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2465 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2466 break;
2467 /* fall through... */
2468 case NOP_EXPR:
2469 /* If this is widening the argument, we can ignore it. */
2470 if (TYPE_PRECISION (TREE_TYPE (expr))
2471 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2472 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2473 break;
2475 case MINUS_EXPR:
2476 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2477 this case. */
2478 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2479 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2480 break;
2481 /* fall through... */
2482 case BIT_XOR_EXPR:
2483 /* This and MINUS_EXPR can be changed into a comparison of the
2484 two objects. */
2485 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2486 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2487 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2488 TREE_OPERAND (expr, 1), 1);
2489 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2490 fold (build1 (NOP_EXPR,
2491 TREE_TYPE (TREE_OPERAND (expr, 0)),
2492 TREE_OPERAND (expr, 1))), 1);
2494 case BIT_AND_EXPR:
2495 if (integer_onep (TREE_OPERAND (expr, 1))
2496 && TREE_TYPE (expr) != boolean_type_node)
2497 /* Using convert here would cause infinite recursion. */
2498 return build1 (NOP_EXPR, boolean_type_node, expr);
2499 break;
2501 case MODIFY_EXPR:
2502 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
2503 warning ("suggest parentheses around assignment used as truth value");
2504 break;
2506 default:
2507 break;
2510 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2512 tree tem = save_expr (expr);
2513 return (build_binary_op
2514 ((TREE_SIDE_EFFECTS (expr)
2515 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2516 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
2517 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
2518 0));
2521 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
2524 static tree builtin_function_2 PARAMS ((const char *, const char *, tree, tree,
2525 int, enum built_in_class, int, int,
2526 int));
2528 /* Make a variant type in the proper way for C/C++, propagating qualifiers
2529 down to the element type of an array. */
2531 tree
2532 c_build_qualified_type (type, type_quals)
2533 tree type;
2534 int type_quals;
2536 /* A restrict-qualified pointer type must be a pointer to object or
2537 incomplete type. Note that the use of POINTER_TYPE_P also allows
2538 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
2539 the C++ front-end also use POINTER_TYPE for pointer-to-member
2540 values, so even though it should be illegal to use `restrict'
2541 with such an entity we don't flag that here. Thus, special case
2542 code for that case is required in the C++ front-end. */
2543 if ((type_quals & TYPE_QUAL_RESTRICT)
2544 && (!POINTER_TYPE_P (type)
2545 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
2547 error ("invalid use of `restrict'");
2548 type_quals &= ~TYPE_QUAL_RESTRICT;
2551 if (TREE_CODE (type) == ARRAY_TYPE)
2552 return build_array_type (c_build_qualified_type (TREE_TYPE (type),
2553 type_quals),
2554 TYPE_DOMAIN (type));
2555 return build_qualified_type (type, type_quals);
2558 /* Apply the TYPE_QUALS to the new DECL. */
2560 void
2561 c_apply_type_quals_to_decl (type_quals, decl)
2562 int type_quals;
2563 tree decl;
2565 if ((type_quals & TYPE_QUAL_CONST)
2566 || (TREE_TYPE (decl)
2567 && TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE))
2568 TREE_READONLY (decl) = 1;
2569 if (type_quals & TYPE_QUAL_VOLATILE)
2571 TREE_SIDE_EFFECTS (decl) = 1;
2572 TREE_THIS_VOLATILE (decl) = 1;
2574 if (type_quals & TYPE_QUAL_RESTRICT)
2576 if (!TREE_TYPE (decl)
2577 || !POINTER_TYPE_P (TREE_TYPE (decl))
2578 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
2579 error ("invalid use of `restrict'");
2580 else if (flag_strict_aliasing)
2582 /* No two restricted pointers can point at the same thing.
2583 However, a restricted pointer can point at the same thing
2584 as an unrestricted pointer, if that unrestricted pointer
2585 is based on the restricted pointer. So, we make the
2586 alias set for the restricted pointer a subset of the
2587 alias set for the type pointed to by the type of the
2588 decl. */
2590 HOST_WIDE_INT pointed_to_alias_set
2591 = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
2593 if (pointed_to_alias_set == 0)
2594 /* It's not legal to make a subset of alias set zero. */
2596 else
2598 DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
2599 record_alias_subset (pointed_to_alias_set,
2600 DECL_POINTER_ALIAS_SET (decl));
2607 /* Return the typed-based alias set for T, which may be an expression
2608 or a type. Return -1 if we don't do anything special. */
2610 HOST_WIDE_INT
2611 lang_get_alias_set (t)
2612 tree t;
2614 tree u;
2616 /* We know nothing about vector types */
2617 if (TREE_CODE (t) == VECTOR_TYPE)
2618 return 0;
2620 /* Permit type-punning when accessing a union, provided the access
2621 is directly through the union. For example, this code does not
2622 permit taking the address of a union member and then storing
2623 through it. Even the type-punning allowed here is a GCC
2624 extension, albeit a common and useful one; the C standard says
2625 that such accesses have implementation-defined behavior. */
2626 for (u = t;
2627 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
2628 u = TREE_OPERAND (u, 0))
2629 if (TREE_CODE (u) == COMPONENT_REF
2630 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
2631 return 0;
2633 /* If this is a char *, the ANSI C standard says it can alias
2634 anything. Note that all references need do this. */
2635 if (TREE_CODE_CLASS (TREE_CODE (t)) == 'r'
2636 && TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
2637 && TYPE_PRECISION (TREE_TYPE (t)) == TYPE_PRECISION (char_type_node))
2638 return 0;
2640 /* That's all the expressions we handle specially. */
2641 if (! TYPE_P (t))
2642 return -1;
2644 /* The C standard specifically allows aliasing between signed and
2645 unsigned variants of the same type. We treat the signed
2646 variant as canonical. */
2647 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
2649 tree t1 = signed_type (t);
2651 /* t1 == t can happen for boolean nodes which are always unsigned. */
2652 if (t1 != t)
2653 return get_alias_set (t1);
2655 else if (POINTER_TYPE_P (t))
2657 tree t1;
2659 /* Unfortunately, there is no canonical form of a pointer type.
2660 In particular, if we have `typedef int I', then `int *', and
2661 `I *' are different types. So, we have to pick a canonical
2662 representative. We do this below.
2664 Technically, this approach is actually more conservative that
2665 it needs to be. In particular, `const int *' and `int *'
2666 chould be in different alias sets, according to the C and C++
2667 standard, since their types are not the same, and so,
2668 technically, an `int **' and `const int **' cannot point at
2669 the same thing.
2671 But, the standard is wrong. In particular, this code is
2672 legal C++:
2674 int *ip;
2675 int **ipp = &ip;
2676 const int* const* cipp = &ip;
2678 And, it doesn't make sense for that to be legal unless you
2679 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
2680 the pointed-to types. This issue has been reported to the
2681 C++ committee. */
2682 t1 = build_type_no_quals (t);
2683 if (t1 != t)
2684 return get_alias_set (t1);
2686 /* It's not yet safe to use alias sets for classes in C++ because
2687 the TYPE_FIELDs list for a class doesn't mention base classes. */
2688 else if (c_language == clk_cplusplus && AGGREGATE_TYPE_P (t))
2689 return 0;
2691 return -1;
2694 /* Build tree nodes and builtin functions common to both C and C++ language
2695 frontends. */
2697 void
2698 c_common_nodes_and_builtins ()
2700 int wchar_type_size;
2701 tree array_domain_type;
2702 tree temp;
2703 tree memcpy_ftype, memset_ftype, strlen_ftype;
2704 tree bzero_ftype, bcmp_ftype, puts_ftype, printf_ftype;
2705 tree fputs_ftype, fputc_ftype, fwrite_ftype, fprintf_ftype;
2706 tree endlink, int_endlink, double_endlink, unsigned_endlink;
2707 tree cstring_endlink, sizetype_endlink;
2708 tree ptr_ftype, ptr_ftype_unsigned;
2709 tree void_ftype_any, void_ftype_int, int_ftype_any;
2710 tree double_ftype_double, double_ftype_double_double;
2711 tree float_ftype_float, ldouble_ftype_ldouble;
2712 tree cfloat_ftype_cfloat, cdouble_ftype_cdouble, cldouble_ftype_cldouble;
2713 tree float_ftype_cfloat, double_ftype_cdouble, ldouble_ftype_cldouble;
2714 tree int_ftype_cptr_cptr_sizet, sizet_ftype_cstring_cstring;
2715 tree int_ftype_cstring_cstring, string_ftype_string_cstring;
2716 tree string_ftype_cstring_int, string_ftype_cstring_cstring;
2717 tree string_ftype_string_cstring_sizet, int_ftype_cstring_cstring_sizet;
2718 tree long_ftype_long;
2719 tree longlong_ftype_longlong;
2720 tree intmax_ftype_intmax;
2721 /* Either char* or void*. */
2722 tree traditional_ptr_type_node;
2723 /* Either const char* or const void*. */
2724 tree traditional_cptr_type_node;
2725 tree traditional_len_type_node;
2726 tree traditional_len_endlink;
2727 tree va_list_ref_type_node;
2728 tree va_list_arg_type_node;
2730 /* Define `int' and `char' first so that dbx will output them first. */
2731 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
2732 record_builtin_type (RID_CHAR, "char", char_type_node);
2734 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
2735 "unsigned long", "long long unsigned" and "unsigned short" were in C++
2736 but not C. Are the conditionals here needed? */
2737 if (c_language == clk_cplusplus)
2738 record_builtin_type (RID_SIGNED, NULL_PTR, integer_type_node);
2739 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
2740 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
2741 record_builtin_type (RID_MAX, "long unsigned int",
2742 long_unsigned_type_node);
2743 if (c_language == clk_cplusplus)
2744 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
2745 record_builtin_type (RID_MAX, "long long int",
2746 long_long_integer_type_node);
2747 record_builtin_type (RID_MAX, "long long unsigned int",
2748 long_long_unsigned_type_node);
2749 if (c_language == clk_cplusplus)
2750 record_builtin_type (RID_MAX, "long long unsigned",
2751 long_long_unsigned_type_node);
2752 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
2753 record_builtin_type (RID_MAX, "short unsigned int",
2754 short_unsigned_type_node);
2755 if (c_language == clk_cplusplus)
2756 record_builtin_type (RID_MAX, "unsigned short",
2757 short_unsigned_type_node);
2759 /* Define both `signed char' and `unsigned char'. */
2760 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
2761 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
2763 /* These are types that type_for_size and type_for_mode use. */
2764 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
2765 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
2766 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
2767 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
2768 #if HOST_BITS_PER_WIDE_INT >= 64
2769 pushdecl (build_decl (TYPE_DECL, get_identifier ("__int128_t"), intTI_type_node));
2770 #endif
2771 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
2772 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
2773 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
2774 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
2775 #if HOST_BITS_PER_WIDE_INT >= 64
2776 pushdecl (build_decl (TYPE_DECL, get_identifier ("__uint128_t"), unsigned_intTI_type_node));
2777 #endif
2779 /* Create the widest literal types. */
2780 widest_integer_literal_type_node
2781 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
2782 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2783 widest_integer_literal_type_node));
2785 widest_unsigned_literal_type_node
2786 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
2787 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2788 widest_unsigned_literal_type_node));
2790 /* `unsigned long' is the standard type for sizeof.
2791 Note that stddef.h uses `unsigned long',
2792 and this must agree, even if long and int are the same size. */
2793 c_size_type_node =
2794 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
2795 signed_size_type_node = signed_type (c_size_type_node);
2796 if (flag_traditional)
2797 c_size_type_node = signed_size_type_node;
2798 set_sizetype (c_size_type_node);
2800 build_common_tree_nodes_2 (flag_short_double);
2802 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
2803 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
2804 record_builtin_type (RID_MAX, "long double", long_double_type_node);
2806 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
2807 complex_integer_type_node));
2808 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
2809 complex_float_type_node));
2810 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
2811 complex_double_type_node));
2812 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
2813 complex_long_double_type_node));
2815 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
2817 void_list_node = build_void_list_node ();
2819 /* Make a type to be the domain of a few array types
2820 whose domains don't really matter.
2821 200 is small enough that it always fits in size_t
2822 and large enough that it can hold most function names for the
2823 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
2824 array_domain_type = build_index_type (size_int (200));
2826 /* Make a type for arrays of characters.
2827 With luck nothing will ever really depend on the length of this
2828 array type. */
2829 char_array_type_node
2830 = build_array_type (char_type_node, array_domain_type);
2832 /* Likewise for arrays of ints. */
2833 int_array_type_node
2834 = build_array_type (integer_type_node, array_domain_type);
2836 #ifdef MD_INIT_BUILTINS
2837 MD_INIT_BUILTINS;
2838 #endif
2840 /* This is special for C++ so functions can be overloaded. */
2841 wchar_type_node = get_identifier (flag_short_wchar
2842 ? "short unsigned int"
2843 : WCHAR_TYPE);
2844 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
2845 wchar_type_size = TYPE_PRECISION (wchar_type_node);
2846 if (c_language == clk_cplusplus)
2848 if (TREE_UNSIGNED (wchar_type_node))
2849 wchar_type_node = make_unsigned_type (wchar_type_size);
2850 else
2851 wchar_type_node = make_signed_type (wchar_type_size);
2852 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
2854 else
2856 signed_wchar_type_node = signed_type (wchar_type_node);
2857 unsigned_wchar_type_node = unsigned_type (wchar_type_node);
2860 /* This is for wide string constants. */
2861 wchar_array_type_node
2862 = build_array_type (wchar_type_node, array_domain_type);
2864 string_type_node = build_pointer_type (char_type_node);
2865 const_string_type_node
2866 = build_pointer_type (build_type_variant (char_type_node, 1, 0));
2868 wint_type_node =
2869 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
2871 intmax_type_node =
2872 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
2873 uintmax_type_node =
2874 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
2876 default_function_type = build_function_type (integer_type_node, NULL_TREE);
2877 ptrdiff_type_node
2878 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
2879 unsigned_ptrdiff_type_node = unsigned_type (ptrdiff_type_node);
2881 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
2882 va_list_type_node));
2884 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
2885 ptrdiff_type_node));
2887 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
2888 sizetype));
2890 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
2892 va_list_arg_type_node = va_list_ref_type_node =
2893 build_pointer_type (TREE_TYPE (va_list_type_node));
2895 else
2897 va_list_arg_type_node = va_list_type_node;
2898 va_list_ref_type_node = build_reference_type (va_list_type_node);
2901 endlink = void_list_node;
2902 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
2903 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
2904 unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink);
2905 cstring_endlink = tree_cons (NULL_TREE, const_string_type_node, endlink);
2907 ptr_ftype = build_function_type (ptr_type_node, NULL_TREE);
2908 ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink);
2909 sizetype_endlink = tree_cons (NULL_TREE, TYPE_DOMAIN (sizetype), endlink);
2910 /* We realloc here because sizetype could be int or unsigned. S'ok. */
2911 ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink);
2913 int_ftype_any = build_function_type (integer_type_node, NULL_TREE);
2914 void_ftype_any = build_function_type (void_type_node, NULL_TREE);
2915 void_ftype = build_function_type (void_type_node, endlink);
2916 void_ftype_int = build_function_type (void_type_node, int_endlink);
2917 void_ftype_ptr
2918 = build_function_type (void_type_node,
2919 tree_cons (NULL_TREE, ptr_type_node, endlink));
2921 float_ftype_float
2922 = build_function_type (float_type_node,
2923 tree_cons (NULL_TREE, float_type_node, endlink));
2925 double_ftype_double
2926 = build_function_type (double_type_node, double_endlink);
2928 ldouble_ftype_ldouble
2929 = build_function_type (long_double_type_node,
2930 tree_cons (NULL_TREE, long_double_type_node,
2931 endlink));
2933 double_ftype_double_double
2934 = build_function_type (double_type_node,
2935 tree_cons (NULL_TREE, double_type_node,
2936 double_endlink));
2938 cfloat_ftype_cfloat
2939 = build_function_type (complex_float_type_node,
2940 tree_cons (NULL_TREE, complex_float_type_node,
2941 endlink));
2942 cdouble_ftype_cdouble
2943 = build_function_type (complex_double_type_node,
2944 tree_cons (NULL_TREE, complex_double_type_node,
2945 endlink));
2946 cldouble_ftype_cldouble
2947 = build_function_type (complex_long_double_type_node,
2948 tree_cons (NULL_TREE, complex_long_double_type_node,
2949 endlink));
2951 float_ftype_cfloat
2952 = build_function_type (float_type_node,
2953 tree_cons (NULL_TREE, complex_float_type_node,
2954 endlink));
2955 double_ftype_cdouble
2956 = build_function_type (double_type_node,
2957 tree_cons (NULL_TREE, complex_double_type_node,
2958 endlink));
2959 ldouble_ftype_cldouble
2960 = build_function_type (long_double_type_node,
2961 tree_cons (NULL_TREE, complex_long_double_type_node,
2962 endlink));
2964 int_ftype_int
2965 = build_function_type (integer_type_node, int_endlink);
2967 long_ftype_long
2968 = build_function_type (long_integer_type_node,
2969 tree_cons (NULL_TREE, long_integer_type_node,
2970 endlink));
2972 longlong_ftype_longlong
2973 = build_function_type (long_long_integer_type_node,
2974 tree_cons (NULL_TREE, long_long_integer_type_node,
2975 endlink));
2977 intmax_ftype_intmax
2978 = build_function_type (intmax_type_node,
2979 tree_cons (NULL_TREE, intmax_type_node,
2980 endlink));
2982 int_ftype_cptr_cptr_sizet
2983 = build_function_type (integer_type_node,
2984 tree_cons (NULL_TREE, const_ptr_type_node,
2985 tree_cons (NULL_TREE,
2986 const_ptr_type_node,
2987 sizetype_endlink)));
2989 void_zero_node = build_int_2 (0, 0);
2990 TREE_TYPE (void_zero_node) = void_type_node;
2992 /* Prototype for strcpy/strcat. */
2993 string_ftype_string_cstring
2994 = build_function_type (string_type_node,
2995 tree_cons (NULL_TREE, string_type_node,
2996 cstring_endlink));
2998 /* Prototype for strncpy/strncat. */
2999 string_ftype_string_cstring_sizet
3000 = build_function_type (string_type_node,
3001 tree_cons (NULL_TREE, string_type_node,
3002 tree_cons (NULL_TREE,
3003 const_string_type_node,
3004 sizetype_endlink)));
3006 traditional_len_type_node = ((flag_traditional &&
3007 c_language != clk_cplusplus)
3008 ? integer_type_node : sizetype);
3009 traditional_len_endlink = tree_cons (NULL_TREE, traditional_len_type_node,
3010 endlink);
3012 /* Prototype for strcmp. */
3013 int_ftype_cstring_cstring
3014 = build_function_type (integer_type_node,
3015 tree_cons (NULL_TREE, const_string_type_node,
3016 cstring_endlink));
3018 /* Prototype for strspn/strcspn. */
3019 sizet_ftype_cstring_cstring
3020 = build_function_type (c_size_type_node,
3021 tree_cons (NULL_TREE, const_string_type_node,
3022 cstring_endlink));
3024 /* Prototype for strncmp. */
3025 int_ftype_cstring_cstring_sizet
3026 = build_function_type (integer_type_node,
3027 tree_cons (NULL_TREE, const_string_type_node,
3028 tree_cons (NULL_TREE,
3029 const_string_type_node,
3030 sizetype_endlink)));
3032 /* Prototype for strstr, strpbrk, etc. */
3033 string_ftype_cstring_cstring
3034 = build_function_type (string_type_node,
3035 tree_cons (NULL_TREE, const_string_type_node,
3036 cstring_endlink));
3038 /* Prototype for strchr. */
3039 string_ftype_cstring_int
3040 = build_function_type (string_type_node,
3041 tree_cons (NULL_TREE, const_string_type_node,
3042 int_endlink));
3044 /* Prototype for strlen. */
3045 strlen_ftype
3046 = build_function_type (traditional_len_type_node, cstring_endlink);
3048 traditional_ptr_type_node = ((flag_traditional &&
3049 c_language != clk_cplusplus)
3050 ? string_type_node : ptr_type_node);
3051 traditional_cptr_type_node = ((flag_traditional &&
3052 c_language != clk_cplusplus)
3053 ? const_string_type_node : const_ptr_type_node);
3055 /* Prototype for memcpy. */
3056 memcpy_ftype
3057 = build_function_type (traditional_ptr_type_node,
3058 tree_cons (NULL_TREE, ptr_type_node,
3059 tree_cons (NULL_TREE, const_ptr_type_node,
3060 sizetype_endlink)));
3062 /* Prototype for memset. */
3063 memset_ftype
3064 = build_function_type (traditional_ptr_type_node,
3065 tree_cons (NULL_TREE, ptr_type_node,
3066 tree_cons (NULL_TREE, integer_type_node,
3067 sizetype_endlink)));
3069 /* Prototype for bzero. */
3070 bzero_ftype
3071 = build_function_type (void_type_node,
3072 tree_cons (NULL_TREE, traditional_ptr_type_node,
3073 traditional_len_endlink));
3075 /* Prototype for bcmp. */
3076 bcmp_ftype
3077 = build_function_type (integer_type_node,
3078 tree_cons (NULL_TREE, traditional_cptr_type_node,
3079 tree_cons (NULL_TREE,
3080 traditional_cptr_type_node,
3081 traditional_len_endlink)));
3083 /* Prototype for puts. */
3084 puts_ftype
3085 = build_function_type (integer_type_node, cstring_endlink);
3087 /* Prototype for printf. */
3088 printf_ftype
3089 = build_function_type (integer_type_node,
3090 tree_cons (NULL_TREE, const_string_type_node,
3091 NULL_TREE));
3093 /* These stdio prototypes are declared using void* in place of
3094 FILE*. They are only used for __builtin_ style calls, regular
3095 style builtin prototypes omit the arguments and merge those
3096 provided by stdio.h. */
3097 /* Prototype for fwrite. */
3098 fwrite_ftype
3099 = build_function_type (c_size_type_node,
3100 tree_cons (NULL_TREE, const_ptr_type_node,
3101 tree_cons (NULL_TREE, c_size_type_node,
3102 tree_cons (NULL_TREE, c_size_type_node,
3103 tree_cons (NULL_TREE, ptr_type_node, endlink)))));
3105 /* Prototype for fputc. */
3106 fputc_ftype
3107 = build_function_type (integer_type_node,
3108 tree_cons (NULL_TREE, integer_type_node,
3109 tree_cons (NULL_TREE, ptr_type_node, endlink)));
3111 /* Prototype for fputs. */
3112 fputs_ftype
3113 = build_function_type (integer_type_node,
3114 tree_cons (NULL_TREE, const_string_type_node,
3115 tree_cons (NULL_TREE, ptr_type_node, endlink)));
3117 /* Prototype for fprintf. */
3118 fprintf_ftype
3119 = build_function_type (integer_type_node,
3120 tree_cons (NULL_TREE, ptr_type_node,
3121 tree_cons (NULL_TREE,
3122 const_string_type_node,
3123 NULL_TREE)));
3125 builtin_function ("__builtin_constant_p", default_function_type,
3126 BUILT_IN_CONSTANT_P, BUILT_IN_NORMAL, NULL_PTR);
3128 builtin_function ("__builtin_return_address", ptr_ftype_unsigned,
3129 BUILT_IN_RETURN_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
3131 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned,
3132 BUILT_IN_FRAME_ADDRESS, BUILT_IN_NORMAL, NULL_PTR);
3134 builtin_function ("__builtin_alloca", ptr_ftype_sizetype,
3135 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, "alloca");
3136 builtin_function_2 ("__builtin_ffs", "ffs",
3137 int_ftype_int, int_ftype_int,
3138 BUILT_IN_FFS, BUILT_IN_NORMAL, 0, 1, 0);
3139 /* Define alloca as builtin, unless SMALL_STACK. */
3140 #ifndef SMALL_STACK
3141 builtin_function_2 (NULL_PTR, "alloca", NULL_TREE, ptr_ftype_sizetype,
3142 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, 0, 1, 0);
3143 #endif
3144 /* Declare _exit and _Exit just to mark them as non-returning. */
3145 builtin_function_2 (NULL_PTR, "_exit", NULL_TREE, void_ftype_int,
3146 0, NOT_BUILT_IN, 0, 1, 1);
3147 builtin_function_2 (NULL_PTR, "_Exit", NULL_TREE, void_ftype_int,
3148 0, NOT_BUILT_IN, 0, !flag_isoc99, 1);
3150 builtin_function_2 ("__builtin_index", "index",
3151 string_ftype_cstring_int, string_ftype_cstring_int,
3152 BUILT_IN_INDEX, BUILT_IN_NORMAL, 1, 1, 0);
3153 builtin_function_2 ("__builtin_rindex", "rindex",
3154 string_ftype_cstring_int, string_ftype_cstring_int,
3155 BUILT_IN_RINDEX, BUILT_IN_NORMAL, 1, 1, 0);
3157 /* The system prototypes for these functions have many
3158 variations, so don't specify parameters to avoid conflicts.
3159 The expand_* functions check the argument types anyway. */
3160 builtin_function_2 ("__builtin_bzero", "bzero",
3161 bzero_ftype, void_ftype_any,
3162 BUILT_IN_BZERO, BUILT_IN_NORMAL, 1, 1, 0);
3163 builtin_function_2 ("__builtin_bcmp", "bcmp",
3164 bcmp_ftype, int_ftype_any,
3165 BUILT_IN_BCMP, BUILT_IN_NORMAL, 1, 1, 0);
3167 builtin_function_2 ("__builtin_abs", "abs",
3168 int_ftype_int, int_ftype_int,
3169 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, 0, 0);
3170 builtin_function_2 ("__builtin_fabsf", "fabsf",
3171 float_ftype_float, float_ftype_float,
3172 BUILT_IN_FABS, BUILT_IN_NORMAL, 0, 0, 0);
3173 builtin_function_2 ("__builtin_fabs", "fabs",
3174 double_ftype_double, double_ftype_double,
3175 BUILT_IN_FABS, BUILT_IN_NORMAL, 0, 0, 0);
3176 builtin_function_2 ("__builtin_fabsl", "fabsl",
3177 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
3178 BUILT_IN_FABS, BUILT_IN_NORMAL, 0, 0, 0);
3179 builtin_function_2 ("__builtin_labs", "labs",
3180 long_ftype_long, long_ftype_long,
3181 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, 0, 0);
3182 builtin_function_2 ("__builtin_llabs", "llabs",
3183 longlong_ftype_longlong, longlong_ftype_longlong,
3184 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3185 builtin_function_2 ("__builtin_imaxabs", "imaxabs",
3186 intmax_ftype_intmax, intmax_ftype_intmax,
3187 BUILT_IN_ABS, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3189 builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS,
3190 BUILT_IN_NORMAL, NULL_PTR);
3191 builtin_function ("__builtin_classify_type", default_function_type,
3192 BUILT_IN_CLASSIFY_TYPE, BUILT_IN_NORMAL, NULL_PTR);
3193 builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG,
3194 BUILT_IN_NORMAL, NULL_PTR);
3195 builtin_function ("__builtin_args_info", int_ftype_int, BUILT_IN_ARGS_INFO,
3196 BUILT_IN_NORMAL, NULL_PTR);
3197 builtin_function ("__builtin_setjmp",
3198 build_function_type (integer_type_node,
3199 tree_cons (NULL_TREE, ptr_type_node,
3200 endlink)),
3201 BUILT_IN_SETJMP, BUILT_IN_NORMAL, NULL_PTR);
3202 builtin_function ("__builtin_longjmp",
3203 build_function_type (void_type_node,
3204 tree_cons (NULL_TREE, ptr_type_node,
3205 int_endlink)),
3206 BUILT_IN_LONGJMP, BUILT_IN_NORMAL, NULL_PTR);
3207 builtin_function ("__builtin_trap", void_ftype, BUILT_IN_TRAP,
3208 BUILT_IN_NORMAL, NULL_PTR);
3210 /* ISO C99 IEEE Unordered compares. */
3211 builtin_function ("__builtin_isgreater", default_function_type,
3212 BUILT_IN_ISGREATER, BUILT_IN_NORMAL, NULL_PTR);
3213 builtin_function ("__builtin_isgreaterequal", default_function_type,
3214 BUILT_IN_ISGREATEREQUAL, BUILT_IN_NORMAL, NULL_PTR);
3215 builtin_function ("__builtin_isless", default_function_type,
3216 BUILT_IN_ISLESS, BUILT_IN_NORMAL, NULL_PTR);
3217 builtin_function ("__builtin_islessequal", default_function_type,
3218 BUILT_IN_ISLESSEQUAL, BUILT_IN_NORMAL, NULL_PTR);
3219 builtin_function ("__builtin_islessgreater", default_function_type,
3220 BUILT_IN_ISLESSGREATER, BUILT_IN_NORMAL, NULL_PTR);
3221 builtin_function ("__builtin_isunordered", default_function_type,
3222 BUILT_IN_ISUNORDERED, BUILT_IN_NORMAL, NULL_PTR);
3224 /* Untyped call and return. */
3225 builtin_function ("__builtin_apply_args", ptr_ftype,
3226 BUILT_IN_APPLY_ARGS, BUILT_IN_NORMAL, NULL_PTR);
3228 temp = tree_cons (NULL_TREE,
3229 build_pointer_type (build_function_type (void_type_node,
3230 NULL_TREE)),
3231 tree_cons (NULL_TREE, ptr_type_node, sizetype_endlink));
3232 builtin_function ("__builtin_apply",
3233 build_function_type (ptr_type_node, temp),
3234 BUILT_IN_APPLY, BUILT_IN_NORMAL, NULL_PTR);
3235 builtin_function ("__builtin_return", void_ftype_ptr,
3236 BUILT_IN_RETURN, BUILT_IN_NORMAL, NULL_PTR);
3238 /* Support for varargs.h and stdarg.h. */
3239 builtin_function ("__builtin_varargs_start",
3240 build_function_type (void_type_node,
3241 tree_cons (NULL_TREE,
3242 va_list_ref_type_node,
3243 endlink)),
3244 BUILT_IN_VARARGS_START, BUILT_IN_NORMAL, NULL_PTR);
3246 builtin_function ("__builtin_stdarg_start",
3247 build_function_type (void_type_node,
3248 tree_cons (NULL_TREE,
3249 va_list_ref_type_node,
3250 NULL_TREE)),
3251 BUILT_IN_STDARG_START, BUILT_IN_NORMAL, NULL_PTR);
3253 builtin_function ("__builtin_va_end",
3254 build_function_type (void_type_node,
3255 tree_cons (NULL_TREE,
3256 va_list_ref_type_node,
3257 endlink)),
3258 BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL_PTR);
3260 builtin_function ("__builtin_va_copy",
3261 build_function_type (void_type_node,
3262 tree_cons (NULL_TREE,
3263 va_list_ref_type_node,
3264 tree_cons (NULL_TREE,
3265 va_list_arg_type_node,
3266 endlink))),
3267 BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL_PTR);
3269 /* ??? Ought to be `T __builtin_expect(T, T)' for any type T. */
3270 builtin_function ("__builtin_expect",
3271 build_function_type (long_integer_type_node,
3272 tree_cons (NULL_TREE,
3273 long_integer_type_node,
3274 tree_cons (NULL_TREE,
3275 long_integer_type_node,
3276 endlink))),
3277 BUILT_IN_EXPECT, BUILT_IN_NORMAL, NULL_PTR);
3279 /* Currently under experimentation. */
3280 builtin_function_2 ("__builtin_memcpy", "memcpy",
3281 memcpy_ftype, memcpy_ftype,
3282 BUILT_IN_MEMCPY, BUILT_IN_NORMAL, 1, 0, 0);
3283 builtin_function_2 ("__builtin_memcmp", "memcmp",
3284 int_ftype_cptr_cptr_sizet, int_ftype_cptr_cptr_sizet,
3285 BUILT_IN_MEMCMP, BUILT_IN_NORMAL, 1, 0, 0);
3286 builtin_function_2 ("__builtin_memset", "memset",
3287 memset_ftype, memset_ftype,
3288 BUILT_IN_MEMSET, BUILT_IN_NORMAL, 1, 0, 0);
3289 built_in_decls[BUILT_IN_STRCMP] =
3290 builtin_function_2 ("__builtin_strcmp", "strcmp",
3291 int_ftype_cstring_cstring, int_ftype_cstring_cstring,
3292 BUILT_IN_STRCMP, BUILT_IN_NORMAL, 1, 0, 0);
3293 builtin_function_2 ("__builtin_strncmp", "strncmp",
3294 int_ftype_cstring_cstring_sizet,
3295 int_ftype_cstring_cstring_sizet,
3296 BUILT_IN_STRNCMP, BUILT_IN_NORMAL, 1, 0, 0);
3297 builtin_function_2 ("__builtin_strstr", "strstr",
3298 string_ftype_cstring_cstring, string_ftype_cstring_cstring,
3299 BUILT_IN_STRSTR, BUILT_IN_NORMAL, 1, 0, 0);
3300 builtin_function_2 ("__builtin_strpbrk", "strpbrk",
3301 string_ftype_cstring_cstring, string_ftype_cstring_cstring,
3302 BUILT_IN_STRPBRK, BUILT_IN_NORMAL, 1, 0, 0);
3303 built_in_decls[BUILT_IN_STRCHR] =
3304 builtin_function_2 ("__builtin_strchr", "strchr",
3305 string_ftype_cstring_int, string_ftype_cstring_int,
3306 BUILT_IN_STRCHR, BUILT_IN_NORMAL, 1, 0, 0);
3307 builtin_function_2 ("__builtin_strrchr", "strrchr",
3308 string_ftype_cstring_int, string_ftype_cstring_int,
3309 BUILT_IN_STRRCHR, BUILT_IN_NORMAL, 1, 0, 0);
3310 builtin_function_2 ("__builtin_strcpy", "strcpy",
3311 string_ftype_string_cstring, string_ftype_string_cstring,
3312 BUILT_IN_STRCPY, BUILT_IN_NORMAL, 1, 0, 0);
3313 builtin_function_2 ("__builtin_strncpy", "strncpy",
3314 string_ftype_string_cstring_sizet,
3315 string_ftype_string_cstring_sizet,
3316 BUILT_IN_STRNCPY, BUILT_IN_NORMAL, 1, 0, 0);
3317 built_in_decls[BUILT_IN_STRCAT] =
3318 builtin_function_2 ("__builtin_strcat", "strcat",
3319 string_ftype_string_cstring,
3320 string_ftype_string_cstring,
3321 BUILT_IN_STRCAT, BUILT_IN_NORMAL, 1, 0, 0);
3322 builtin_function_2 ("__builtin_strncat", "strncat",
3323 string_ftype_string_cstring_sizet,
3324 string_ftype_string_cstring_sizet,
3325 BUILT_IN_STRNCAT, BUILT_IN_NORMAL, 1, 0, 0);
3326 builtin_function_2 ("__builtin_strspn", "strspn",
3327 sizet_ftype_cstring_cstring, sizet_ftype_cstring_cstring,
3328 BUILT_IN_STRSPN, BUILT_IN_NORMAL, 1, 0, 0);
3329 builtin_function_2 ("__builtin_strcspn", "strcspn",
3330 sizet_ftype_cstring_cstring, sizet_ftype_cstring_cstring,
3331 BUILT_IN_STRCSPN, BUILT_IN_NORMAL, 1, 0, 0);
3332 built_in_decls[BUILT_IN_STRLEN] =
3333 builtin_function_2 ("__builtin_strlen", "strlen",
3334 strlen_ftype, strlen_ftype,
3335 BUILT_IN_STRLEN, BUILT_IN_NORMAL, 1, 0, 0);
3337 builtin_function_2 ("__builtin_sqrtf", "sqrtf",
3338 float_ftype_float, float_ftype_float,
3339 BUILT_IN_FSQRT, BUILT_IN_NORMAL, 1, 0, 0);
3340 builtin_function_2 ("__builtin_fsqrt", "sqrt",
3341 double_ftype_double, double_ftype_double,
3342 BUILT_IN_FSQRT, BUILT_IN_NORMAL, 1, 0, 0);
3343 builtin_function_2 ("__builtin_sqrtl", "sqrtl",
3344 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
3345 BUILT_IN_FSQRT, BUILT_IN_NORMAL, 1, 0, 0);
3346 builtin_function_2 ("__builtin_sinf", "sinf",
3347 float_ftype_float, float_ftype_float,
3348 BUILT_IN_SIN, BUILT_IN_NORMAL, 1, 0, 0);
3349 builtin_function_2 ("__builtin_sin", "sin",
3350 double_ftype_double, double_ftype_double,
3351 BUILT_IN_SIN, BUILT_IN_NORMAL, 1, 0, 0);
3352 builtin_function_2 ("__builtin_sinl", "sinl",
3353 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
3354 BUILT_IN_SIN, BUILT_IN_NORMAL, 1, 0, 0);
3355 builtin_function_2 ("__builtin_cosf", "cosf",
3356 float_ftype_float, float_ftype_float,
3357 BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
3358 builtin_function_2 ("__builtin_cos", "cos",
3359 double_ftype_double, double_ftype_double,
3360 BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
3361 builtin_function_2 ("__builtin_cosl", "cosl",
3362 ldouble_ftype_ldouble, ldouble_ftype_ldouble,
3363 BUILT_IN_COS, BUILT_IN_NORMAL, 1, 0, 0);
3365 /* ISO C99 complex arithmetic functions. */
3366 builtin_function_2 ("__builtin_conjf", "conjf",
3367 cfloat_ftype_cfloat, cfloat_ftype_cfloat,
3368 BUILT_IN_CONJ, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3369 builtin_function_2 ("__builtin_conj", "conj",
3370 cdouble_ftype_cdouble, cdouble_ftype_cdouble,
3371 BUILT_IN_CONJ, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3372 builtin_function_2 ("__builtin_conjl", "conjl",
3373 cldouble_ftype_cldouble, cldouble_ftype_cldouble,
3374 BUILT_IN_CONJ, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3375 builtin_function_2 ("__builtin_crealf", "crealf",
3376 float_ftype_cfloat, float_ftype_cfloat,
3377 BUILT_IN_CREAL, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3378 builtin_function_2 ("__builtin_creal", "creal",
3379 double_ftype_cdouble, double_ftype_cdouble,
3380 BUILT_IN_CREAL, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3381 builtin_function_2 ("__builtin_creall", "creall",
3382 ldouble_ftype_cldouble, ldouble_ftype_cldouble,
3383 BUILT_IN_CREAL, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3384 builtin_function_2 ("__builtin_cimagf", "cimagf",
3385 float_ftype_cfloat, float_ftype_cfloat,
3386 BUILT_IN_CIMAG, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3387 builtin_function_2 ("__builtin_cimag", "cimag",
3388 double_ftype_cdouble, double_ftype_cdouble,
3389 BUILT_IN_CIMAG, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3390 builtin_function_2 ("__builtin_cimagl", "cimagl",
3391 ldouble_ftype_cldouble, ldouble_ftype_cldouble,
3392 BUILT_IN_CIMAG, BUILT_IN_NORMAL, 0, !flag_isoc99, 0);
3394 built_in_decls[BUILT_IN_PUTCHAR] =
3395 builtin_function ("__builtin_putchar", int_ftype_int,
3396 BUILT_IN_PUTCHAR, BUILT_IN_NORMAL, "putchar");
3397 built_in_decls[BUILT_IN_PUTS] =
3398 builtin_function ("__builtin_puts", puts_ftype,
3399 BUILT_IN_PUTS, BUILT_IN_NORMAL, "puts");
3400 builtin_function_2 ("__builtin_printf", "printf",
3401 printf_ftype, printf_ftype,
3402 BUILT_IN_PRINTF, BUILT_IN_FRONTEND, 1, 0, 0);
3403 builtin_function_2 ("__builtin_fprintf", "fprintf",
3404 fprintf_ftype, fprintf_ftype,
3405 BUILT_IN_FPRINTF, BUILT_IN_FRONTEND, 1, 0, 0);
3406 built_in_decls[BUILT_IN_FWRITE] =
3407 builtin_function ("__builtin_fwrite", fwrite_ftype,
3408 BUILT_IN_FWRITE, BUILT_IN_NORMAL, "fwrite");
3409 built_in_decls[BUILT_IN_FPUTC] =
3410 builtin_function ("__builtin_fputc", fputc_ftype,
3411 BUILT_IN_FPUTC, BUILT_IN_NORMAL, "fputc");
3412 /* Declare the __builtin_ style with arguments and the regular style
3413 without them. We rely on stdio.h to supply the arguments for the
3414 regular style declaration since we had to use void* instead of
3415 FILE* in the __builtin_ prototype supplied here. */
3416 built_in_decls[BUILT_IN_FPUTS] =
3417 builtin_function_2 ("__builtin_fputs", "fputs",
3418 fputs_ftype, int_ftype_any,
3419 BUILT_IN_FPUTS, BUILT_IN_NORMAL, 1, 0, 0);
3421 /* Declare these functions non-returning
3422 to avoid spurious "control drops through" warnings. */
3423 builtin_function_2 (NULL_PTR, "abort",
3424 NULL_TREE, ((c_language == clk_cplusplus)
3425 ? void_ftype : void_ftype_any),
3426 0, NOT_BUILT_IN, 0, 0, 1);
3428 builtin_function_2 (NULL_PTR, "exit",
3429 NULL_TREE, ((c_language == clk_cplusplus)
3430 ? void_ftype_int : void_ftype_any),
3431 0, NOT_BUILT_IN, 0, 0, 1);
3433 #if 0
3434 /* Support for these has not been written in either expand_builtin
3435 or build_function_call. */
3436 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV,
3437 BUILT_IN_NORMAL, NULL_PTR);
3438 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV,
3439 BUILT_IN_NORMAL, NULL_PTR);
3440 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
3441 BUILT_IN_NORMAL, NULL_PTR);
3442 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
3443 BUILT_IN_NORMAL, NULL_PTR);
3444 builtin_function ("__builtin_fmod", double_ftype_double_double,
3445 BUILT_IN_FMOD, BUILT_IN_NORMAL, NULL_PTR);
3446 builtin_function ("__builtin_frem", double_ftype_double_double,
3447 BUILT_IN_FREM, BUILT_IN_NORMAL, NULL_PTR);
3448 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
3449 BUILT_IN_NORMAL, NULL_PTR);
3450 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
3451 BUILT_IN_NORMAL, NULL_PTR);
3452 #endif
3454 main_identifier_node = get_identifier ("main");
3456 /* ??? Perhaps there's a better place to do this. But it is related
3457 to __builtin_va_arg, so it isn't that off-the-wall. */
3458 lang_type_promotes_to = simple_type_promotes_to;
3461 tree
3462 build_va_arg (expr, type)
3463 tree expr, type;
3465 return build1 (VA_ARG_EXPR, type, expr);
3469 /* Possibly define a builtin function with one or two names. BUILTIN_NAME
3470 is an __builtin_-prefixed name; NAME is the ordinary name; one or both
3471 of these may be NULL (though both being NULL is useless).
3472 BUILTIN_TYPE is the type of the __builtin_-prefixed function;
3473 TYPE is the type of the function with the ordinary name. These
3474 may differ if the ordinary name is declared with a looser type to avoid
3475 conflicts with headers. FUNCTION_CODE and CLASS are as for
3476 builtin_function. If LIBRARY_NAME_P is nonzero, NAME is passed as
3477 the LIBRARY_NAME parameter to builtin_function when declaring BUILTIN_NAME.
3478 If NONANSI_P is nonzero, the name NAME is treated as a non-ANSI name; if
3479 NORETURN_P is nonzero, the function is marked as non-returning.
3480 Returns the declaration of BUILTIN_NAME, if any, otherwise
3481 the declaration of NAME. Does not declare NAME if flag_no_builtin,
3482 or if NONANSI_P and flag_no_nonansi_builtin. */
3484 static tree
3485 builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
3486 class, library_name_p, nonansi_p, noreturn_p)
3487 const char *builtin_name;
3488 const char *name;
3489 tree builtin_type;
3490 tree type;
3491 int function_code;
3492 enum built_in_class class;
3493 int library_name_p;
3494 int nonansi_p;
3495 int noreturn_p;
3497 tree bdecl = NULL_TREE;
3498 tree decl = NULL_TREE;
3499 if (builtin_name != 0)
3501 bdecl = builtin_function (builtin_name, builtin_type, function_code,
3502 class, library_name_p ? name : NULL_PTR);
3503 if (noreturn_p)
3505 TREE_THIS_VOLATILE (bdecl) = 1;
3506 TREE_SIDE_EFFECTS (bdecl) = 1;
3509 if (name != 0 && !flag_no_builtin && !(nonansi_p && flag_no_nonansi_builtin))
3511 decl = builtin_function (name, type, function_code, class, NULL_PTR);
3512 if (nonansi_p)
3513 DECL_BUILT_IN_NONANSI (decl) = 1;
3514 if (noreturn_p)
3516 TREE_THIS_VOLATILE (decl) = 1;
3517 TREE_SIDE_EFFECTS (decl) = 1;
3520 return (bdecl != 0 ? bdecl : decl);
3523 /* Given a type, apply default promotions wrt unnamed function arguments
3524 and return the new type. Return NULL_TREE if no change. */
3525 /* ??? There is a function of the same name in the C++ front end that
3526 does something similar, but is more thorough and does not return NULL
3527 if no change. We could perhaps share code, but it would make the
3528 self_promoting_type property harder to identify. */
3530 tree
3531 simple_type_promotes_to (type)
3532 tree type;
3534 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3535 return double_type_node;
3537 if (C_PROMOTING_INTEGER_TYPE_P (type))
3539 /* Traditionally, unsignedness is preserved in default promotions.
3540 Also preserve unsignedness if not really getting any wider. */
3541 if (TREE_UNSIGNED (type)
3542 && (flag_traditional
3543 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
3544 return unsigned_type_node;
3545 return integer_type_node;
3548 return NULL_TREE;
3551 /* Return 1 if PARMS specifies a fixed number of parameters
3552 and none of their types is affected by default promotions. */
3555 self_promoting_args_p (parms)
3556 tree parms;
3558 register tree t;
3559 for (t = parms; t; t = TREE_CHAIN (t))
3561 register tree type = TREE_VALUE (t);
3563 if (TREE_CHAIN (t) == 0 && type != void_type_node)
3564 return 0;
3566 if (type == 0)
3567 return 0;
3569 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3570 return 0;
3572 if (C_PROMOTING_INTEGER_TYPE_P (type))
3573 return 0;
3575 return 1;
3578 /* Recursively examines the array elements of TYPE, until a non-array
3579 element type is found. */
3581 tree
3582 strip_array_types (type)
3583 tree type;
3585 while (TREE_CODE (type) == ARRAY_TYPE)
3586 type = TREE_TYPE (type);
3588 return type;
3591 /* Recognize certain built-in functions so we can make tree-codes
3592 other than CALL_EXPR. We do this when it enables fold-const.c
3593 to do something useful. */
3594 /* ??? By rights this should go in builtins.c, but only C and C++
3595 implement build_{binary,unary}_op. Not exactly sure what bits
3596 of functionality are actually needed from those functions, or
3597 where the similar functionality exists in the other front ends. */
3599 tree
3600 expand_tree_builtin (function, params, coerced_params)
3601 tree function, params, coerced_params;
3603 enum tree_code code;
3605 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
3606 return NULL_TREE;
3608 switch (DECL_FUNCTION_CODE (function))
3610 case BUILT_IN_ABS:
3611 case BUILT_IN_FABS:
3612 if (coerced_params == 0)
3613 return integer_zero_node;
3614 return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
3616 case BUILT_IN_CONJ:
3617 if (coerced_params == 0)
3618 return integer_zero_node;
3619 return build_unary_op (CONJ_EXPR, TREE_VALUE (coerced_params), 0);
3621 case BUILT_IN_CREAL:
3622 if (coerced_params == 0)
3623 return integer_zero_node;
3624 return build_unary_op (REALPART_EXPR, TREE_VALUE (coerced_params), 0);
3626 case BUILT_IN_CIMAG:
3627 if (coerced_params == 0)
3628 return integer_zero_node;
3629 return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
3631 case BUILT_IN_ISGREATER:
3632 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3633 code = UNLE_EXPR;
3634 else
3635 code = LE_EXPR;
3636 goto unordered_cmp;
3638 case BUILT_IN_ISGREATEREQUAL:
3639 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3640 code = UNLT_EXPR;
3641 else
3642 code = LT_EXPR;
3643 goto unordered_cmp;
3645 case BUILT_IN_ISLESS:
3646 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3647 code = UNGE_EXPR;
3648 else
3649 code = GE_EXPR;
3650 goto unordered_cmp;
3652 case BUILT_IN_ISLESSEQUAL:
3653 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3654 code = UNGT_EXPR;
3655 else
3656 code = GT_EXPR;
3657 goto unordered_cmp;
3659 case BUILT_IN_ISLESSGREATER:
3660 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3661 code = UNEQ_EXPR;
3662 else
3663 code = EQ_EXPR;
3664 goto unordered_cmp;
3666 case BUILT_IN_ISUNORDERED:
3667 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
3668 return integer_zero_node;
3669 code = UNORDERED_EXPR;
3670 goto unordered_cmp;
3672 unordered_cmp:
3674 tree arg0, arg1;
3676 if (params == 0
3677 || TREE_CHAIN (params) == 0)
3679 error ("too few arguments to function `%s'",
3680 IDENTIFIER_POINTER (DECL_NAME (function)));
3681 return error_mark_node;
3683 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
3685 error ("too many arguments to function `%s'",
3686 IDENTIFIER_POINTER (DECL_NAME (function)));
3687 return error_mark_node;
3690 arg0 = TREE_VALUE (params);
3691 arg1 = TREE_VALUE (TREE_CHAIN (params));
3692 arg0 = build_binary_op (code, arg0, arg1, 0);
3693 if (code != UNORDERED_EXPR)
3694 arg0 = build_unary_op (TRUTH_NOT_EXPR, arg0, 0);
3695 return arg0;
3697 break;
3699 default:
3700 break;
3703 return NULL_TREE;
3706 /* Returns non-zero if CODE is the code for a statement. */
3709 statement_code_p (code)
3710 enum tree_code code;
3712 switch (code)
3714 case EXPR_STMT:
3715 case COMPOUND_STMT:
3716 case DECL_STMT:
3717 case IF_STMT:
3718 case FOR_STMT:
3719 case WHILE_STMT:
3720 case DO_STMT:
3721 case RETURN_STMT:
3722 case BREAK_STMT:
3723 case CONTINUE_STMT:
3724 case SCOPE_STMT:
3725 case SWITCH_STMT:
3726 case GOTO_STMT:
3727 case LABEL_STMT:
3728 case ASM_STMT:
3729 case CASE_LABEL:
3730 return 1;
3732 default:
3733 if (lang_statement_code_p)
3734 return (*lang_statement_code_p) (code);
3735 return 0;
3739 /* Walk the statemen tree, rooted at *tp. Apply FUNC to all the
3740 sub-trees of *TP in a pre-order traversal. FUNC is called with the
3741 DATA and the address of each sub-tree. If FUNC returns a non-NULL
3742 value, the traversal is aborted, and the value returned by FUNC is
3743 returned. If FUNC sets WALK_SUBTREES to zero, then the subtrees of
3744 the node being visited are not walked.
3746 We don't need a without_duplicates variant of this one because the
3747 statement tree is a tree, not a graph. */
3749 tree
3750 walk_stmt_tree (tp, func, data)
3751 tree *tp;
3752 walk_tree_fn func;
3753 void *data;
3755 enum tree_code code;
3756 int walk_subtrees;
3757 tree result;
3758 int i, len;
3760 #define WALK_SUBTREE(NODE) \
3761 do \
3763 result = walk_stmt_tree (&(NODE), func, data); \
3764 if (result) \
3765 return result; \
3767 while (0)
3769 /* Skip empty subtrees. */
3770 if (!*tp)
3771 return NULL_TREE;
3773 /* Skip subtrees below non-statement nodes. */
3774 if (!statement_code_p (TREE_CODE (*tp)))
3775 return NULL_TREE;
3777 /* Call the function. */
3778 walk_subtrees = 1;
3779 result = (*func) (tp, &walk_subtrees, data);
3781 /* If we found something, return it. */
3782 if (result)
3783 return result;
3785 /* Even if we didn't, FUNC may have decided that there was nothing
3786 interesting below this point in the tree. */
3787 if (!walk_subtrees)
3788 return NULL_TREE;
3790 /* FUNC may have modified the tree, recheck that we're looking at a
3791 statement node. */
3792 code = TREE_CODE (*tp);
3793 if (!statement_code_p (code))
3794 return NULL_TREE;
3796 /* Walk over all the sub-trees of this operand. Statement nodes never
3797 contain RTL, and we needn't worry about TARGET_EXPRs. */
3798 len = TREE_CODE_LENGTH (code);
3800 /* Go through the subtrees. We need to do this in forward order so
3801 that the scope of a FOR_EXPR is handled properly. */
3802 for (i = 0; i < len; ++i)
3803 WALK_SUBTREE (TREE_OPERAND (*tp, i));
3805 /* Finally visit the chain. This can be tail-recursion optimized if
3806 we write it this way. */
3807 return walk_stmt_tree (&TREE_CHAIN (*tp), func, data);
3809 #undef WALK_SUBTREE
3812 /* Used to compare case labels. K1 and K2 are actually tree nodes
3813 representing case labels, or NULL_TREE for a `default' label.
3814 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
3815 K2, and 0 if K1 and K2 are equal. */
3818 case_compare (k1, k2)
3819 splay_tree_key k1;
3820 splay_tree_key k2;
3822 /* Consider a NULL key (such as arises with a `default' label) to be
3823 smaller than anything else. */
3824 if (!k1)
3825 return k2 ? -1 : 0;
3826 else if (!k2)
3827 return k1 ? 1 : 0;
3829 return tree_int_cst_compare ((tree) k1, (tree) k2);
3832 /* Process a case label for the range LOW_VALUE ... HIGH_VALUE. If
3833 LOW_VALUE and HIGH_VALUE are both NULL_TREE then this case label is
3834 actually a `default' label. If only HIGH_VALUE is NULL_TREE, then
3835 case label was declared using the usual C/C++ syntax, rather than
3836 the GNU case range extension. CASES is a tree containing all the
3837 case ranges processed so far; COND is the condition for the
3838 switch-statement itself. Returns the CASE_LABEL created, or
3839 ERROR_MARK_NODE if no CASE_LABEL is created. */
3841 tree
3842 c_add_case_label (cases, cond, low_value, high_value)
3843 splay_tree cases;
3844 tree cond;
3845 tree low_value;
3846 tree high_value;
3848 tree type;
3849 tree label;
3850 tree case_label;
3851 splay_tree_node node;
3853 /* Create the LABEL_DECL itself. */
3854 label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
3855 DECL_CONTEXT (label) = current_function_decl;
3857 /* If there was an error processing the switch condition, bail now
3858 before we get more confused. */
3859 if (!cond || cond == error_mark_node)
3861 /* Add a label anyhow so that the back-end doesn't think that
3862 the beginning of the switch is unreachable. */
3863 if (!cases->root)
3864 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
3865 return error_mark_node;
3868 if ((low_value && TREE_TYPE (low_value)
3869 && POINTER_TYPE_P (TREE_TYPE (low_value)))
3870 || (high_value && TREE_TYPE (high_value)
3871 && POINTER_TYPE_P (TREE_TYPE (high_value))))
3872 error ("pointers are not permitted as case values");
3874 /* Case ranges are a GNU extension. */
3875 if (high_value && pedantic)
3877 if (c_language == clk_cplusplus)
3878 pedwarn ("ISO C++ forbids range expressions in switch statements");
3879 else
3880 pedwarn ("ISO C forbids range expressions in switch statements");
3883 type = TREE_TYPE (cond);
3884 if (low_value)
3886 low_value = check_case_value (low_value);
3887 low_value = convert_and_check (type, low_value);
3889 if (high_value)
3891 high_value = check_case_value (high_value);
3892 high_value = convert_and_check (type, high_value);
3895 /* If an error has occurred, bail out now. */
3896 if (low_value == error_mark_node || high_value == error_mark_node)
3898 if (!cases->root)
3899 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
3900 return error_mark_node;
3903 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
3904 really a case range, even though it was written that way. Remove
3905 the HIGH_VALUE to simplify later processing. */
3906 if (tree_int_cst_equal (low_value, high_value))
3907 high_value = NULL_TREE;
3908 if (low_value && high_value
3909 && !tree_int_cst_lt (low_value, high_value))
3910 warning ("empty range specified");
3912 /* Look up the LOW_VALUE in the table of case labels we already
3913 have. */
3914 node = splay_tree_lookup (cases, (splay_tree_key) low_value);
3915 /* If there was not an exact match, check for overlapping ranges.
3916 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
3917 that's a `default' label and the only overlap is an exact match. */
3918 if (!node && (low_value || high_value))
3920 splay_tree_node low_bound;
3921 splay_tree_node high_bound;
3923 /* Even though there wasn't an exact match, there might be an
3924 overlap between this case range and another case range.
3925 Since we've (inductively) not allowed any overlapping case
3926 ranges, we simply need to find the greatest low case label
3927 that is smaller that LOW_VALUE, and the smallest low case
3928 label that is greater than LOW_VALUE. If there is an overlap
3929 it will occur in one of these two ranges. */
3930 low_bound = splay_tree_predecessor (cases,
3931 (splay_tree_key) low_value);
3932 high_bound = splay_tree_successor (cases,
3933 (splay_tree_key) low_value);
3935 /* Check to see if the LOW_BOUND overlaps. It is smaller than
3936 the LOW_VALUE, so there is no need to check unless the
3937 LOW_BOUND is in fact itself a case range. */
3938 if (low_bound
3939 && CASE_HIGH ((tree) low_bound->value)
3940 && tree_int_cst_compare (CASE_HIGH ((tree) low_bound->value),
3941 low_value) >= 0)
3942 node = low_bound;
3943 /* Check to see if the HIGH_BOUND overlaps. The low end of that
3944 range is bigger than the low end of the current range, so we
3945 are only interested if the current range is a real range, and
3946 not an ordinary case label. */
3947 else if (high_bound
3948 && high_value
3949 && (tree_int_cst_compare ((tree) high_bound->key,
3950 high_value)
3951 <= 0))
3952 node = high_bound;
3954 /* If there was an overlap, issue an error. */
3955 if (node)
3957 tree duplicate = CASE_LABEL_DECL ((tree) node->value);
3959 if (high_value)
3961 error ("duplicate (or overlapping) case value");
3962 error_with_decl (duplicate,
3963 "this is the first entry overlapping that value");
3965 else if (low_value)
3967 error ("duplicate case value") ;
3968 error_with_decl (duplicate, "previously used here");
3970 else
3972 error ("multiple default labels in one switch");
3973 error_with_decl (duplicate, "this is the first default label");
3975 if (!cases->root)
3976 add_stmt (build_case_label (NULL_TREE, NULL_TREE, label));
3979 /* Add a CASE_LABEL to the statement-tree. */
3980 case_label = add_stmt (build_case_label (low_value, high_value, label));
3981 /* Register this case label in the splay tree. */
3982 splay_tree_insert (cases,
3983 (splay_tree_key) low_value,
3984 (splay_tree_value) case_label);
3986 return case_label;
3989 /* Mark P (a stmt_tree) for GC. The use of a `void *' for the
3990 parameter allows this function to be used as a GC-marking
3991 function. */
3993 void
3994 mark_stmt_tree (p)
3995 void *p;
3997 stmt_tree st = (stmt_tree) p;
3999 ggc_mark_tree (st->x_last_stmt);
4000 ggc_mark_tree (st->x_last_expr_type);
4003 /* Mark LD for GC. */
4005 void
4006 c_mark_lang_decl (c)
4007 struct c_lang_decl *c;
4009 ggc_mark_tree (c->saved_tree);
4012 /* Mark F for GC. */
4014 void
4015 mark_c_language_function (f)
4016 struct language_function *f;
4018 if (!f)
4019 return;
4021 mark_stmt_tree (&f->x_stmt_tree);
4022 ggc_mark_tree (f->x_scope_stmt_stack);
4025 /* Hook used by expand_expr to expand language-specific tree codes. */
4028 c_expand_expr (exp, target, tmode, modifier)
4029 tree exp;
4030 rtx target;
4031 enum machine_mode tmode;
4032 enum expand_modifier modifier;
4034 switch (TREE_CODE (exp))
4036 case STMT_EXPR:
4038 tree rtl_expr;
4039 rtx result;
4041 /* Since expand_expr_stmt calls free_temp_slots after every
4042 expression statement, we must call push_temp_slots here.
4043 Otherwise, any temporaries in use now would be considered
4044 out-of-scope after the first EXPR_STMT from within the
4045 STMT_EXPR. */
4046 push_temp_slots ();
4047 rtl_expr = expand_start_stmt_expr ();
4048 expand_stmt (STMT_EXPR_STMT (exp));
4049 expand_end_stmt_expr (rtl_expr);
4050 result = expand_expr (rtl_expr, target, tmode, modifier);
4051 pop_temp_slots ();
4052 return result;
4054 break;
4056 case CALL_EXPR:
4058 if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
4059 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
4060 == FUNCTION_DECL)
4061 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
4062 && (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
4063 == BUILT_IN_FRONTEND))
4064 return c_expand_builtin (exp, target, tmode, modifier);
4065 else
4066 abort();
4068 break;
4070 default:
4071 abort ();
4074 abort ();
4075 return NULL;
4078 /* Hook used by safe_from_p to handle language-specific tree codes. */
4081 c_safe_from_p (target, exp)
4082 rtx target;
4083 tree exp;
4085 /* We can see statements here when processing the body of a
4086 statement-expression. For a declaration statement declaring a
4087 variable, look at the variable's initializer. */
4088 if (TREE_CODE (exp) == DECL_STMT)
4090 tree decl = DECL_STMT_DECL (exp);
4092 if (TREE_CODE (decl) == VAR_DECL
4093 && DECL_INITIAL (decl)
4094 && !safe_from_p (target, DECL_INITIAL (decl), /*top_p=*/0))
4095 return 0;
4098 /* For any statement, we must follow the statement-chain. */
4099 if (statement_code_p (TREE_CODE (exp)) && TREE_CHAIN (exp))
4100 return safe_from_p (target, TREE_CHAIN (exp), /*top_p=*/0);
4102 /* Assume everything else is safe. */
4103 return 1;
4106 /* Hook used by unsafe_for_reeval to handle language-specific tree codes. */
4109 c_unsafe_for_reeval (exp)
4110 tree exp;
4112 /* Statement expressions may not be reevaluated. */
4113 if (TREE_CODE (exp) == STMT_EXPR)
4114 return 2;
4116 /* Walk all other expressions. */
4117 return -1;
4120 /* Tree code classes. */
4122 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
4124 static char c_tree_code_type[] = {
4125 'x',
4126 #include "c-common.def"
4128 #undef DEFTREECODE
4130 /* Table indexed by tree code giving number of expression
4131 operands beyond the fixed part of the node structure.
4132 Not used for types or decls. */
4134 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
4136 static int c_tree_code_length[] = {
4138 #include "c-common.def"
4140 #undef DEFTREECODE
4142 /* Names of tree components.
4143 Used for printing out the tree and error messages. */
4144 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
4146 static const char *c_tree_code_name[] = {
4147 "@@dummy",
4148 #include "c-common.def"
4150 #undef DEFTREECODE
4152 /* Adds the tree codes specific to the C front end to the list of all
4153 tree codes. */
4155 void
4156 add_c_tree_codes ()
4158 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
4159 c_tree_code_type,
4160 (int)LAST_C_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
4161 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
4162 c_tree_code_length,
4163 (LAST_C_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
4164 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
4165 c_tree_code_name,
4166 (LAST_C_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
4167 lang_unsafe_for_reeval = c_unsafe_for_reeval;
4170 #define CALLED_AS_BUILT_IN(NODE) \
4171 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
4173 static rtx
4174 c_expand_builtin (exp, target, tmode, modifier)
4175 tree exp;
4176 rtx target;
4177 enum machine_mode tmode;
4178 enum expand_modifier modifier;
4180 tree type = TREE_TYPE (exp);
4181 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4182 tree arglist = TREE_OPERAND (exp, 1);
4183 enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
4184 enum tree_code code = TREE_CODE (exp);
4185 const int ignore = (target == const0_rtx
4186 || ((code == NON_LVALUE_EXPR || code == NOP_EXPR
4187 || code == CONVERT_EXPR || code == REFERENCE_EXPR
4188 || code == COND_EXPR)
4189 && TREE_CODE (type) == VOID_TYPE));
4191 if (! optimize && ! CALLED_AS_BUILT_IN (fndecl))
4192 return expand_call (exp, target, ignore);
4194 switch (fcode)
4196 case BUILT_IN_PRINTF:
4197 target = c_expand_builtin_printf (arglist, target, tmode,
4198 modifier, ignore);
4199 if (target)
4200 return target;
4201 break;
4203 case BUILT_IN_FPRINTF:
4204 target = c_expand_builtin_fprintf (arglist, target, tmode,
4205 modifier, ignore);
4206 if (target)
4207 return target;
4208 break;
4210 default: /* just do library call, if unknown builtin */
4211 error ("built-in function `%s' not currently supported",
4212 IDENTIFIER_POINTER (DECL_NAME (fndecl)));
4215 /* The switch statement above can drop through to cause the function
4216 to be called normally. */
4217 return expand_call (exp, target, ignore);
4220 /* Check an arglist to *printf for problems. The arglist should start
4221 at the format specifier, with the remaining arguments immediately
4222 following it. */
4223 static int
4224 is_valid_printf_arglist (arglist)
4225 tree arglist;
4227 /* Save this value so we can restore it later. */
4228 const int SAVE_pedantic = pedantic;
4229 int diagnostic_occurred = 0;
4231 /* Set this to a known value so the user setting won't affect code
4232 generation. */
4233 pedantic = 1;
4234 /* Check to make sure there are no format specifier errors. */
4235 check_function_format (&diagnostic_occurred,
4236 maybe_get_identifier("printf"),
4237 NULL_TREE, arglist);
4239 /* Restore the value of `pedantic'. */
4240 pedantic = SAVE_pedantic;
4242 /* If calling `check_function_format_ptr' produces a warning, we
4243 return false, otherwise we return true. */
4244 return ! diagnostic_occurred;
4247 /* If the arguments passed to printf are suitable for optimizations,
4248 we attempt to transform the call. */
4249 static rtx
4250 c_expand_builtin_printf (arglist, target, tmode, modifier, ignore)
4251 tree arglist;
4252 rtx target;
4253 enum machine_mode tmode;
4254 enum expand_modifier modifier;
4255 int ignore;
4257 tree fn_putchar = built_in_decls[BUILT_IN_PUTCHAR],
4258 fn_puts = built_in_decls[BUILT_IN_PUTS];
4259 tree fn, format_arg, stripped_string;
4261 /* If the return value is used, or the replacement _DECL isn't
4262 initialized, don't do the transformation. */
4263 if (!ignore || !fn_putchar || !fn_puts)
4264 return 0;
4266 /* Verify the required arguments in the original call. */
4267 if (arglist == 0
4268 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE))
4269 return 0;
4271 /* Check the specifier vs. the parameters. */
4272 if (!is_valid_printf_arglist (arglist))
4273 return 0;
4275 format_arg = TREE_VALUE (arglist);
4276 stripped_string = format_arg;
4277 STRIP_NOPS (stripped_string);
4278 if (stripped_string && TREE_CODE (stripped_string) == ADDR_EXPR)
4279 stripped_string = TREE_OPERAND (stripped_string, 0);
4281 /* If the format specifier isn't a STRING_CST, punt. */
4282 if (TREE_CODE (stripped_string) != STRING_CST)
4283 return 0;
4285 /* OK! We can attempt optimization. */
4287 /* If the format specifier was "%s\n", call __builtin_puts(arg2). */
4288 if (strcmp (TREE_STRING_POINTER (stripped_string), "%s\n") == 0)
4290 arglist = TREE_CHAIN (arglist);
4291 fn = fn_puts;
4293 /* If the format specifier was "%c", call __builtin_putchar (arg2). */
4294 else if (strcmp (TREE_STRING_POINTER (stripped_string), "%c") == 0)
4296 arglist = TREE_CHAIN (arglist);
4297 fn = fn_putchar;
4299 else
4301 /* We can't handle anything else with % args or %% ... yet. */
4302 if (strchr (TREE_STRING_POINTER (stripped_string), '%'))
4303 return 0;
4305 /* If the resulting constant string has a length of 1, call
4306 putchar. Note, TREE_STRING_LENGTH includes the terminating
4307 NULL in its count. */
4308 if (TREE_STRING_LENGTH (stripped_string) == 2)
4310 /* Given printf("c"), (where c is any one character,)
4311 convert "c"[0] to an int and pass that to the replacement
4312 function. */
4313 arglist = build_int_2 (TREE_STRING_POINTER (stripped_string)[0], 0);
4314 arglist = build_tree_list (NULL_TREE, arglist);
4316 fn = fn_putchar;
4318 /* If the resulting constant was "string\n", call
4319 __builtin_puts("string"). Ensure "string" has at least one
4320 character besides the trailing \n. Note, TREE_STRING_LENGTH
4321 includes the terminating NULL in its count. */
4322 else if (TREE_STRING_LENGTH (stripped_string) > 2
4323 && TREE_STRING_POINTER (stripped_string)
4324 [TREE_STRING_LENGTH (stripped_string) - 2] == '\n')
4326 /* Create a NULL-terminated string that's one char shorter
4327 than the original, stripping off the trailing '\n'. */
4328 const int newlen = TREE_STRING_LENGTH (stripped_string) - 1;
4329 char *newstr = (char *) alloca (newlen);
4330 memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
4331 newstr[newlen - 1] = 0;
4333 arglist = combine_strings (build_string (newlen, newstr));
4334 arglist = build_tree_list (NULL_TREE, arglist);
4335 fn = fn_puts;
4337 else
4338 /* We'd like to arrange to call fputs(string) here, but we
4339 need stdout and don't have a way to get it ... yet. */
4340 return 0;
4343 return expand_expr (build_function_call (fn, arglist),
4344 (ignore ? const0_rtx : target),
4345 tmode, modifier);
4348 /* If the arguments passed to fprintf are suitable for optimizations,
4349 we attempt to transform the call. */
4350 static rtx
4351 c_expand_builtin_fprintf (arglist, target, tmode, modifier, ignore)
4352 tree arglist;
4353 rtx target;
4354 enum machine_mode tmode;
4355 enum expand_modifier modifier;
4356 int ignore;
4358 tree fn_fputc = built_in_decls[BUILT_IN_FPUTC],
4359 fn_fputs = built_in_decls[BUILT_IN_FPUTS];
4360 tree fn, format_arg, stripped_string;
4362 /* If the return value is used, or the replacement _DECL isn't
4363 initialized, don't do the transformation. */
4364 if (!ignore || !fn_fputc || !fn_fputs)
4365 return 0;
4367 /* Verify the required arguments in the original call. */
4368 if (arglist == 0
4369 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != POINTER_TYPE)
4370 || (TREE_CHAIN (arglist) == 0)
4371 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))) !=
4372 POINTER_TYPE))
4373 return 0;
4375 /* Check the specifier vs. the parameters. */
4376 if (!is_valid_printf_arglist (TREE_CHAIN (arglist)))
4377 return 0;
4379 format_arg = TREE_VALUE (TREE_CHAIN (arglist));
4380 stripped_string = format_arg;
4381 STRIP_NOPS (stripped_string);
4382 if (stripped_string && TREE_CODE (stripped_string) == ADDR_EXPR)
4383 stripped_string = TREE_OPERAND (stripped_string, 0);
4385 /* If the format specifier isn't a STRING_CST, punt. */
4386 if (TREE_CODE (stripped_string) != STRING_CST)
4387 return 0;
4389 /* OK! We can attempt optimization. */
4391 /* If the format specifier was "%s", call __builtin_fputs(arg3, arg1). */
4392 if (strcmp (TREE_STRING_POINTER (stripped_string), "%s") == 0)
4394 tree newarglist = build_tree_list (NULL_TREE, TREE_VALUE (arglist));
4395 arglist = tree_cons (NULL_TREE,
4396 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))),
4397 newarglist);
4398 fn = fn_fputs;
4400 /* If the format specifier was "%c", call __builtin_fputc (arg3, arg1). */
4401 else if (strcmp (TREE_STRING_POINTER (stripped_string), "%c") == 0)
4403 tree newarglist = build_tree_list (NULL_TREE, TREE_VALUE (arglist));
4404 arglist = tree_cons (NULL_TREE,
4405 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))),
4406 newarglist);
4407 fn = fn_fputc;
4409 else
4411 /* We can't handle anything else with % args or %% ... yet. */
4412 if (strchr (TREE_STRING_POINTER (stripped_string), '%'))
4413 return 0;
4415 /* When "string" doesn't contain %, replace all cases of
4416 fprintf(stream,string) with fputs(string,stream). The fputs
4417 builtin will take take of special cases like length==1. */
4418 arglist = tree_cons (NULL_TREE, TREE_VALUE (TREE_CHAIN (arglist)),
4419 build_tree_list (NULL_TREE, TREE_VALUE (arglist)));
4420 fn = fn_fputs;
4423 return expand_expr (build_function_call (fn, arglist),
4424 (ignore ? const0_rtx : target),
4425 tmode, modifier);
4429 /* Given a boolean expression ARG, return a tree representing an increment
4430 or decrement (as indicated by CODE) of ARG. The front end must check for
4431 invalid cases (e.g., decrement in C++). */
4432 tree
4433 boolean_increment (code, arg)
4434 enum tree_code code;
4435 tree arg;
4437 tree val;
4438 tree true_res = (c_language == clk_cplusplus
4439 ? boolean_true_node
4440 : c_bool_true_node);
4441 arg = stabilize_reference (arg);
4442 switch (code)
4444 case PREINCREMENT_EXPR:
4445 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
4446 break;
4447 case POSTINCREMENT_EXPR:
4448 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, true_res);
4449 arg = save_expr (arg);
4450 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
4451 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
4452 break;
4453 case PREDECREMENT_EXPR:
4454 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, invert_truthvalue (arg));
4455 break;
4456 case POSTDECREMENT_EXPR:
4457 val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, invert_truthvalue (arg));
4458 arg = save_expr (arg);
4459 val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
4460 val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
4461 break;
4462 default:
4463 abort ();
4465 TREE_SIDE_EFFECTS (val) = 1;
4466 return val;
4470 /* Do the parts of lang_init common to C and C++. */
4471 void
4472 c_common_lang_init ()
4474 /* If still "unspecified", make it match -fbounded-pointers. */
4475 if (flag_bounds_check < 0)
4476 flag_bounds_check = flag_bounded_pointers;
4478 /* Special format checking options don't work without -Wformat; warn if
4479 they are used. */
4480 if (warn_format_y2k && !warn_format)
4481 warning ("-Wformat-y2k ignored without -Wformat");
4482 if (warn_format_extra_args && !warn_format)
4483 warning ("-Wformat-extra-args ignored without -Wformat");
4484 if (warn_format_nonliteral && !warn_format)
4485 warning ("-Wformat-nonliteral ignored without -Wformat");
4486 if (warn_format_security && !warn_format)
4487 warning ("-Wformat-security ignored without -Wformat");
4488 if (warn_missing_format_attribute && !warn_format)
4489 warning ("-Wmissing-format-attribute ignored without -Wformat");