1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
36 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. */
48 #define SIZE_TYPE "long unsigned int"
52 #define WCHAR_TYPE "int"
56 #define PTRDIFF_TYPE "long int"
60 #define WINT_TYPE "unsigned int"
64 #define INTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
66 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
72 #define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
74 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
75 ? "long unsigned int" \
76 : "long long unsigned int"))
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.
161 tree ptr_ftype_sizetype;
163 A VOID_TYPE node, packaged in a TREE_LIST.
167 The identifiers __FUNCTION__, __PRETTY_FUNCTION__, and __func__.
169 tree function_id_node;
170 tree pretty_function_id_node;
175 tree c_global_trees
[CTI_MAX
];
177 /* Nonzero means don't recognize the non-ANSI builtin functions. */
181 /* Nonzero means don't recognize the non-ANSI builtin functions.
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 /* Nonzero means warn about possible violations of sequence point rules. */
196 int warn_sequence_point
;
198 /* The elements of `ridpointers' are identifier nodes for the reserved
199 type names and storage classes. It is indexed by a RID_... value. */
202 tree (*make_fname_decl
) PARAMS ((tree
, const char *, int));
204 /* If non-NULL, the address of a language-specific function that
205 returns 1 for language-specific statement codes. */
206 int (*lang_statement_code_p
) PARAMS ((enum tree_code
));
208 /* If non-NULL, the address of a language-specific function that takes
209 any action required right before expand_function_end is called. */
210 void (*lang_expand_function_end
) PARAMS ((void));
212 /* If this variable is defined to a non-NULL value, it will be called
213 after the file has been completely parsed. */
214 void (*back_end_hook
) PARAMS ((tree
));
216 /* Nonzero means the expression being parsed will never be evaluated.
217 This is a count, since unevaluated expressions can nest. */
220 enum attrs
{A_PACKED
, A_NOCOMMON
, A_COMMON
, A_NORETURN
, A_CONST
, A_T_UNION
,
221 A_NO_CHECK_MEMORY_USAGE
, A_NO_INSTRUMENT_FUNCTION
,
222 A_CONSTRUCTOR
, A_DESTRUCTOR
, A_MODE
, A_SECTION
, A_ALIGNED
,
223 A_UNUSED
, A_FORMAT
, A_FORMAT_ARG
, A_WEAK
, A_ALIAS
, A_MALLOC
,
224 A_NO_LIMIT_STACK
, A_PURE
};
226 static void add_attribute
PARAMS ((enum attrs
, const char *,
228 static void init_attributes
PARAMS ((void));
229 static int default_valid_lang_attribute
PARAMS ((tree
, tree
, tree
, tree
));
230 static int constant_fits_type_p
PARAMS ((tree
, tree
));
232 /* Keep a stack of if statements. We record the number of compound
233 statements seen up to the if keyword, as well as the line number
234 and file of the if. If a potentially ambiguous else is seen, that
235 fact is recorded; the warning is issued when we can be sure that
236 the enclosing if statement does not have an else branch. */
246 static if_elt
*if_stack
;
248 /* Amount of space in the if statement stack. */
249 static int if_stack_space
= 0;
252 static int if_stack_pointer
= 0;
254 /* Record the start of an if-then, and record the start of it
255 for ambiguous else detection. */
258 c_expand_start_cond (cond
, compstmt_count
)
264 /* Make sure there is enough space on the stack. */
265 if (if_stack_space
== 0)
268 if_stack
= (if_elt
*)xmalloc (10 * sizeof (if_elt
));
270 else if (if_stack_space
== if_stack_pointer
)
272 if_stack_space
+= 10;
273 if_stack
= (if_elt
*)xrealloc (if_stack
, if_stack_space
* sizeof (if_elt
));
276 if_stmt
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
277 IF_COND (if_stmt
) = cond
;
280 /* Record this if statement. */
281 if_stack
[if_stack_pointer
].compstmt_count
= compstmt_count
;
282 if_stack
[if_stack_pointer
].file
= input_filename
;
283 if_stack
[if_stack_pointer
].line
= lineno
;
284 if_stack
[if_stack_pointer
].needs_warning
= 0;
285 if_stack
[if_stack_pointer
].if_stmt
= if_stmt
;
289 /* Called after the then-clause for an if-statement is processed. */
294 tree if_stmt
= if_stack
[if_stack_pointer
- 1].if_stmt
;
295 RECHAIN_STMTS (if_stmt
, THEN_CLAUSE (if_stmt
));
298 /* Record the end of an if-then. Optionally warn if a nested
299 if statement had an ambiguous else clause. */
305 if (if_stack
[if_stack_pointer
].needs_warning
)
306 warning_with_file_and_line (if_stack
[if_stack_pointer
].file
,
307 if_stack
[if_stack_pointer
].line
,
308 "suggest explicit braces to avoid ambiguous `else'");
309 last_expr_type
= NULL_TREE
;
312 /* Called between the then-clause and the else-clause
313 of an if-then-else. */
316 c_expand_start_else ()
318 /* An ambiguous else warning must be generated for the enclosing if
319 statement, unless we see an else branch for that one, too. */
321 && if_stack_pointer
> 1
322 && (if_stack
[if_stack_pointer
- 1].compstmt_count
323 == if_stack
[if_stack_pointer
- 2].compstmt_count
))
324 if_stack
[if_stack_pointer
- 2].needs_warning
= 1;
326 /* Even if a nested if statement had an else branch, it can't be
327 ambiguous if this one also has an else. So don't warn in that
328 case. Also don't warn for any if statements nested in this else. */
329 if_stack
[if_stack_pointer
- 1].needs_warning
= 0;
330 if_stack
[if_stack_pointer
- 1].compstmt_count
--;
333 /* Called after the else-clause for an if-statement is processed. */
338 tree if_stmt
= if_stack
[if_stack_pointer
- 1].if_stmt
;
339 RECHAIN_STMTS (if_stmt
, ELSE_CLAUSE (if_stmt
));
342 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
345 declare_function_name ()
347 const char *name
, *printable_name
;
349 if (current_function_decl
== NULL
)
352 printable_name
= "top level";
356 /* Allow functions to be nameless (such as artificial ones). */
357 if (DECL_NAME (current_function_decl
))
358 name
= IDENTIFIER_POINTER (DECL_NAME (current_function_decl
));
361 printable_name
= (*decl_printable_name
) (current_function_decl
, 2);
363 /* ISO C99 defines __func__, which is a variable, not a string
364 constant, and which is not a defined symbol at file scope. */
365 (*make_fname_decl
) (func_id_node
, name
, 0);
368 (*make_fname_decl
) (function_id_node
, name
, 0);
369 (*make_fname_decl
) (pretty_function_id_node
, printable_name
, 1);
372 /* Given a chain of STRING_CST nodes,
373 concatenate them into one STRING_CST
374 and give it a suitable array-of-chars data type. */
377 combine_strings (strings
)
380 register tree value
, t
;
381 register int length
= 1;
384 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
386 const int nchars_max
= flag_isoc99
? 4095 : 509;
388 if (TREE_CHAIN (strings
))
390 /* More than one in the chain, so concatenate. */
391 register char *p
, *q
;
393 /* Don't include the \0 at the end of each substring,
394 except for the last one.
395 Count wide strings and ordinary strings separately. */
396 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
398 if (TREE_TYPE (t
) == wchar_array_type_node
)
400 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
404 length
+= (TREE_STRING_LENGTH (t
) - 1);
407 /* If anything is wide, the non-wides will be converted,
408 which makes them take more space. */
410 length
= length
* wchar_bytes
+ wide_length
;
414 /* Copy the individual strings into the new combined string.
415 If the combined string is wide, convert the chars to ints
416 for any individual strings that are not wide. */
419 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
421 int len
= (TREE_STRING_LENGTH (t
)
422 - ((TREE_TYPE (t
) == wchar_array_type_node
)
424 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
426 memcpy (q
, TREE_STRING_POINTER (t
), len
);
432 for (i
= 0; i
< len
; i
++)
434 if (WCHAR_TYPE_SIZE
== HOST_BITS_PER_SHORT
)
435 ((short *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
437 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
439 q
+= len
* wchar_bytes
;
445 for (i
= 0; i
< wchar_bytes
; i
++)
451 value
= build_string (length
, p
);
456 length
= TREE_STRING_LENGTH (value
);
457 if (TREE_TYPE (value
) == wchar_array_type_node
)
461 /* Compute the number of elements, for the array type. */
462 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
464 if (pedantic
&& nchars
- 1 > nchars_max
&& c_language
== clk_c
)
465 pedwarn ("string length `%d' is greater than the length `%d' ISO C%d compilers are required to support",
466 nchars
- 1, nchars_max
, flag_isoc99
? 99 : 89);
468 /* Create the array type for the string constant.
469 -Wwrite-strings says make the string constant an array of const char
470 so that copying it to a non-const pointer will get a warning.
471 For C++, this is the standard behavior. */
472 if (flag_const_strings
473 && (! flag_traditional
&& ! flag_writable_strings
))
476 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
479 = build_array_type (elements
,
480 build_index_type (build_int_2 (nchars
- 1, 0)));
484 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
485 build_index_type (build_int_2 (nchars
- 1, 0)));
487 TREE_CONSTANT (value
) = 1;
488 TREE_READONLY (value
) = ! flag_writable_strings
;
489 TREE_STATIC (value
) = 1;
493 /* To speed up processing of attributes, we maintain an array of
494 IDENTIFIER_NODES and the corresponding attribute types. */
496 /* Array to hold attribute information. */
498 static struct {enum attrs id
; tree name
; int min
, max
, decl_req
;} attrtab
[50];
500 static int attrtab_idx
= 0;
502 /* Add an entry to the attribute table above. */
505 add_attribute (id
, string
, min_len
, max_len
, decl_req
)
508 int min_len
, max_len
;
513 attrtab
[attrtab_idx
].id
= id
;
514 attrtab
[attrtab_idx
].name
= get_identifier (string
);
515 attrtab
[attrtab_idx
].min
= min_len
;
516 attrtab
[attrtab_idx
].max
= max_len
;
517 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
519 sprintf (buf
, "__%s__", string
);
521 attrtab
[attrtab_idx
].id
= id
;
522 attrtab
[attrtab_idx
].name
= get_identifier (buf
);
523 attrtab
[attrtab_idx
].min
= min_len
;
524 attrtab
[attrtab_idx
].max
= max_len
;
525 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
528 /* Initialize attribute table. */
533 add_attribute (A_PACKED
, "packed", 0, 0, 0);
534 add_attribute (A_NOCOMMON
, "nocommon", 0, 0, 1);
535 add_attribute (A_COMMON
, "common", 0, 0, 1);
536 add_attribute (A_NORETURN
, "noreturn", 0, 0, 1);
537 add_attribute (A_NORETURN
, "volatile", 0, 0, 1);
538 add_attribute (A_UNUSED
, "unused", 0, 0, 0);
539 add_attribute (A_CONST
, "const", 0, 0, 1);
540 add_attribute (A_T_UNION
, "transparent_union", 0, 0, 0);
541 add_attribute (A_CONSTRUCTOR
, "constructor", 0, 0, 1);
542 add_attribute (A_DESTRUCTOR
, "destructor", 0, 0, 1);
543 add_attribute (A_MODE
, "mode", 1, 1, 1);
544 add_attribute (A_SECTION
, "section", 1, 1, 1);
545 add_attribute (A_ALIGNED
, "aligned", 0, 1, 0);
546 add_attribute (A_FORMAT
, "format", 3, 3, 1);
547 add_attribute (A_FORMAT_ARG
, "format_arg", 1, 1, 1);
548 add_attribute (A_WEAK
, "weak", 0, 0, 1);
549 add_attribute (A_ALIAS
, "alias", 1, 1, 1);
550 add_attribute (A_NO_INSTRUMENT_FUNCTION
, "no_instrument_function", 0, 0, 1);
551 add_attribute (A_NO_CHECK_MEMORY_USAGE
, "no_check_memory_usage", 0, 0, 1);
552 add_attribute (A_MALLOC
, "malloc", 0, 0, 1);
553 add_attribute (A_NO_LIMIT_STACK
, "no_stack_limit", 0, 0, 1);
554 add_attribute (A_PURE
, "pure", 0, 0, 1);
557 /* Default implementation of valid_lang_attribute, below. By default, there
558 are no language-specific attributes. */
561 default_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
562 tree attr_name ATTRIBUTE_UNUSED
;
563 tree attr_args ATTRIBUTE_UNUSED
;
564 tree decl ATTRIBUTE_UNUSED
;
565 tree type ATTRIBUTE_UNUSED
;
570 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
571 attribute for either declaration DECL or type TYPE and 0 otherwise. */
573 int (*valid_lang_attribute
) PARAMS ((tree
, tree
, tree
, tree
))
574 = default_valid_lang_attribute
;
576 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
577 and install them in NODE, which is either a DECL (including a TYPE_DECL)
578 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
579 and declaration modifiers but before the declaration proper. */
582 decl_attributes (node
, attributes
, prefix_attributes
)
583 tree node
, attributes
, prefix_attributes
;
585 tree decl
= 0, type
= 0;
589 if (attrtab_idx
== 0)
595 type
= TREE_TYPE (decl
);
596 is_type
= TREE_CODE (node
) == TYPE_DECL
;
598 else if (TYPE_P (node
))
599 type
= node
, is_type
= 1;
601 #ifdef PRAGMA_INSERT_ATTRIBUTES
602 /* If the code in c-pragma.c wants to insert some attributes then
603 allow it to do so. Do this before allowing machine back ends to
604 insert attributes, so that they have the opportunity to override
605 anything done here. */
606 PRAGMA_INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
609 #ifdef INSERT_ATTRIBUTES
610 INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
613 attributes
= chainon (prefix_attributes
, attributes
);
615 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
617 tree name
= TREE_PURPOSE (a
);
618 tree args
= TREE_VALUE (a
);
622 for (i
= 0; i
< attrtab_idx
; i
++)
623 if (attrtab
[i
].name
== name
)
626 if (i
== attrtab_idx
)
628 if (! valid_machine_attribute (name
, args
, decl
, type
)
629 && ! (* valid_lang_attribute
) (name
, args
, decl
, type
))
630 warning ("`%s' attribute directive ignored",
631 IDENTIFIER_POINTER (name
));
633 type
= TREE_TYPE (decl
);
636 else if (attrtab
[i
].decl_req
&& decl
== 0)
638 warning ("`%s' attribute does not apply to types",
639 IDENTIFIER_POINTER (name
));
642 else if (list_length (args
) < attrtab
[i
].min
643 || list_length (args
) > attrtab
[i
].max
)
645 error ("wrong number of arguments specified for `%s' attribute",
646 IDENTIFIER_POINTER (name
));
655 TYPE_PACKED (type
) = 1;
656 else if (TREE_CODE (decl
) == FIELD_DECL
)
657 DECL_PACKED (decl
) = 1;
658 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
659 used for DECL_REGISTER. It wouldn't mean anything anyway. */
661 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
665 if (TREE_CODE (decl
) == VAR_DECL
)
666 DECL_COMMON (decl
) = 0;
668 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
672 if (TREE_CODE (decl
) == VAR_DECL
)
673 DECL_COMMON (decl
) = 1;
675 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
679 if (TREE_CODE (decl
) == FUNCTION_DECL
)
680 TREE_THIS_VOLATILE (decl
) = 1;
681 else if (TREE_CODE (type
) == POINTER_TYPE
682 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
683 TREE_TYPE (decl
) = type
685 (build_type_variant (TREE_TYPE (type
),
686 TREE_READONLY (TREE_TYPE (type
)), 1));
688 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
692 if (TREE_CODE (decl
) == FUNCTION_DECL
)
693 DECL_IS_MALLOC (decl
) = 1;
694 /* ??? TODO: Support types. */
696 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
702 TREE_USED (decl
) = 1;
704 TREE_USED (type
) = 1;
705 else if (TREE_CODE (decl
) == PARM_DECL
706 || TREE_CODE (decl
) == VAR_DECL
707 || TREE_CODE (decl
) == FUNCTION_DECL
708 || TREE_CODE (decl
) == LABEL_DECL
)
709 TREE_USED (decl
) = 1;
711 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
715 if (TREE_CODE (decl
) == FUNCTION_DECL
)
716 TREE_READONLY (decl
) = 1;
717 else if (TREE_CODE (type
) == POINTER_TYPE
718 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
719 TREE_TYPE (decl
) = type
721 (build_type_variant (TREE_TYPE (type
), 1,
722 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
724 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name
));
728 if (TREE_CODE (decl
) == FUNCTION_DECL
)
729 DECL_IS_PURE (decl
) = 1;
730 /* ??? TODO: Support types. */
732 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
738 && TREE_CODE (type
) == UNION_TYPE
740 || (TYPE_FIELDS (type
) != 0
741 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))))
742 TYPE_TRANSPARENT_UNION (type
) = 1;
743 else if (decl
!= 0 && TREE_CODE (decl
) == PARM_DECL
744 && TREE_CODE (type
) == UNION_TYPE
745 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))
746 DECL_TRANSPARENT_UNION (decl
) = 1;
748 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
752 if (TREE_CODE (decl
) == FUNCTION_DECL
753 && TREE_CODE (type
) == FUNCTION_TYPE
754 && decl_function_context (decl
) == 0)
756 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
757 TREE_USED (decl
) = 1;
760 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
764 if (TREE_CODE (decl
) == FUNCTION_DECL
765 && TREE_CODE (type
) == FUNCTION_TYPE
766 && decl_function_context (decl
) == 0)
768 DECL_STATIC_DESTRUCTOR (decl
) = 1;
769 TREE_USED (decl
) = 1;
772 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
776 if (TREE_CODE (TREE_VALUE (args
)) != IDENTIFIER_NODE
)
777 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
781 const char *p
= IDENTIFIER_POINTER (TREE_VALUE (args
));
782 int len
= strlen (p
);
783 enum machine_mode mode
= VOIDmode
;
786 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
787 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
789 char *newp
= (char *) alloca (len
- 1);
791 strcpy (newp
, &p
[2]);
792 newp
[len
- 4] = '\0';
796 /* Give this decl a type with the specified mode.
797 First check for the special modes. */
798 if (! strcmp (p
, "byte"))
800 else if (!strcmp (p
, "word"))
802 else if (! strcmp (p
, "pointer"))
805 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
806 if (!strcmp (p
, GET_MODE_NAME (j
)))
807 mode
= (enum machine_mode
) j
;
809 if (mode
== VOIDmode
)
810 error ("unknown machine mode `%s'", p
);
811 else if (0 == (typefm
= type_for_mode (mode
,
812 TREE_UNSIGNED (type
))))
813 error ("no data type for mode `%s'", p
);
816 if (TYPE_PRECISION (typefm
) > (TREE_UNSIGNED (type
)
817 ? TYPE_PRECISION(uintmax_type_node
)
818 : TYPE_PRECISION(intmax_type_node
))
820 pedwarn ("type with more precision than %s",
821 TREE_UNSIGNED (type
) ? "uintmax_t" : "intmax_t");
822 TREE_TYPE (decl
) = type
= typefm
;
823 DECL_SIZE (decl
) = DECL_SIZE_UNIT (decl
) = 0;
824 layout_decl (decl
, 0);
830 #ifdef ASM_OUTPUT_SECTION_NAME
831 if ((TREE_CODE (decl
) == FUNCTION_DECL
832 || TREE_CODE (decl
) == VAR_DECL
)
833 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
835 if (TREE_CODE (decl
) == VAR_DECL
836 && current_function_decl
!= NULL_TREE
837 && ! TREE_STATIC (decl
))
838 error_with_decl (decl
,
839 "section attribute cannot be specified for local variables");
840 /* The decl may have already been given a section attribute from
841 a previous declaration. Ensure they match. */
842 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
843 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
844 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
845 error_with_decl (node
,
846 "section of `%s' conflicts with previous declaration");
848 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
851 error_with_decl (node
,
852 "section attribute not allowed for `%s'");
854 error_with_decl (node
,
855 "section attributes are not supported for this target");
862 = (args
? TREE_VALUE (args
)
863 : size_int (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
866 /* Strip any NOPs of any kind. */
867 while (TREE_CODE (align_expr
) == NOP_EXPR
868 || TREE_CODE (align_expr
) == CONVERT_EXPR
869 || TREE_CODE (align_expr
) == NON_LVALUE_EXPR
)
870 align_expr
= TREE_OPERAND (align_expr
, 0);
872 if (TREE_CODE (align_expr
) != INTEGER_CST
)
874 error ("requested alignment is not a constant");
878 if ((i
= tree_log2 (align_expr
)) == -1)
879 error ("requested alignment is not a power of 2");
880 else if (i
> HOST_BITS_PER_INT
- 2)
881 error ("requested alignment is too large");
884 /* If we have a TYPE_DECL, then copy the type, so that we
885 don't accidentally modify a builtin type. See pushdecl. */
886 if (decl
&& TREE_TYPE (decl
) != error_mark_node
887 && DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
)
889 tree tt
= TREE_TYPE (decl
);
890 DECL_ORIGINAL_TYPE (decl
) = tt
;
891 tt
= build_type_copy (tt
);
892 TYPE_NAME (tt
) = decl
;
893 TREE_USED (tt
) = TREE_USED (decl
);
894 TREE_TYPE (decl
) = tt
;
898 TYPE_ALIGN (type
) = (1 << i
) * BITS_PER_UNIT
;
899 TYPE_USER_ALIGN (type
) = 1;
901 else if (TREE_CODE (decl
) != VAR_DECL
902 && TREE_CODE (decl
) != FIELD_DECL
)
903 error_with_decl (decl
,
904 "alignment may not be specified for `%s'");
907 DECL_ALIGN (decl
) = (1 << i
) * BITS_PER_UNIT
;
908 DECL_USER_ALIGN (decl
) = 1;
914 decl_handle_format_attribute (decl
, args
);
918 decl_handle_format_arg_attribute (decl
, args
);
926 if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
927 || (TREE_CODE (decl
) != FUNCTION_DECL
&& ! DECL_EXTERNAL (decl
)))
928 error_with_decl (decl
,
929 "`%s' defined both normally and as an alias");
930 else if (decl_function_context (decl
) == 0)
934 id
= TREE_VALUE (args
);
935 if (TREE_CODE (id
) != STRING_CST
)
937 error ("alias arg not a string");
940 id
= get_identifier (TREE_STRING_POINTER (id
));
941 /* This counts as a use of the object pointed to. */
944 if (TREE_CODE (decl
) == FUNCTION_DECL
)
945 DECL_INITIAL (decl
) = error_mark_node
;
947 DECL_EXTERNAL (decl
) = 0;
948 assemble_alias (decl
, id
);
951 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
954 case A_NO_CHECK_MEMORY_USAGE
:
955 if (TREE_CODE (decl
) != FUNCTION_DECL
)
957 error_with_decl (decl
,
958 "`%s' attribute applies only to functions",
959 IDENTIFIER_POINTER (name
));
961 else if (DECL_INITIAL (decl
))
963 error_with_decl (decl
,
964 "can't set `%s' attribute after definition",
965 IDENTIFIER_POINTER (name
));
968 DECL_NO_CHECK_MEMORY_USAGE (decl
) = 1;
971 case A_NO_INSTRUMENT_FUNCTION
:
972 if (TREE_CODE (decl
) != FUNCTION_DECL
)
974 error_with_decl (decl
,
975 "`%s' attribute applies only to functions",
976 IDENTIFIER_POINTER (name
));
978 else if (DECL_INITIAL (decl
))
980 error_with_decl (decl
,
981 "can't set `%s' attribute after definition",
982 IDENTIFIER_POINTER (name
));
985 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
988 case A_NO_LIMIT_STACK
:
989 if (TREE_CODE (decl
) != FUNCTION_DECL
)
991 error_with_decl (decl
,
992 "`%s' attribute applies only to functions",
993 IDENTIFIER_POINTER (name
));
995 else if (DECL_INITIAL (decl
))
997 error_with_decl (decl
,
998 "can't set `%s' attribute after definition",
999 IDENTIFIER_POINTER (name
));
1002 DECL_NO_LIMIT_STACK (decl
) = 1;
1008 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1009 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1011 The head of the declspec list is stored in DECLSPECS.
1012 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1014 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1015 the list elements. We drop the containing TREE_LIST nodes and link the
1016 resulting attributes together the way decl_attributes expects them. */
1019 split_specs_attrs (specs_attrs
, declspecs
, prefix_attributes
)
1021 tree
*declspecs
, *prefix_attributes
;
1023 tree t
, s
, a
, next
, specs
, attrs
;
1025 /* This can happen after an __extension__ in pedantic mode. */
1026 if (specs_attrs
!= NULL_TREE
1027 && TREE_CODE (specs_attrs
) == INTEGER_CST
)
1029 *declspecs
= NULL_TREE
;
1030 *prefix_attributes
= NULL_TREE
;
1034 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1035 if (specs_attrs
!= NULL_TREE
1036 && TREE_CODE (specs_attrs
) != TREE_LIST
)
1038 *declspecs
= specs_attrs
;
1039 *prefix_attributes
= NULL_TREE
;
1043 /* Remember to keep the lists in the same order, element-wise. */
1045 specs
= s
= NULL_TREE
;
1046 attrs
= a
= NULL_TREE
;
1047 for (t
= specs_attrs
; t
; t
= next
)
1049 next
= TREE_CHAIN (t
);
1050 /* Declspecs have a non-NULL TREE_VALUE. */
1051 if (TREE_VALUE (t
) != NULL_TREE
)
1053 if (specs
== NULL_TREE
)
1063 if (attrs
== NULL_TREE
)
1064 attrs
= a
= TREE_PURPOSE (t
);
1067 TREE_CHAIN (a
) = TREE_PURPOSE (t
);
1068 a
= TREE_PURPOSE (t
);
1070 /* More attrs can be linked here, move A to the end. */
1071 while (TREE_CHAIN (a
) != NULL_TREE
)
1076 /* Terminate the lists. */
1078 TREE_CHAIN (s
) = NULL_TREE
;
1080 TREE_CHAIN (a
) = NULL_TREE
;
1084 *prefix_attributes
= attrs
;
1087 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1088 This function is used by the parser when a rule will accept attributes
1089 in a particular position, but we don't want to support that just yet.
1091 A warning is issued for every ignored attribute. */
1094 strip_attrs (specs_attrs
)
1099 split_specs_attrs (specs_attrs
, &specs
, &attrs
);
1103 warning ("`%s' attribute ignored",
1104 IDENTIFIER_POINTER (TREE_PURPOSE (attrs
)));
1105 attrs
= TREE_CHAIN (attrs
);
1111 static int is_valid_printf_arglist
PARAMS ((tree
));
1112 static rtx c_expand_builtin
PARAMS ((tree
, rtx
, enum machine_mode
, enum expand_modifier
));
1113 static rtx c_expand_builtin_printf
PARAMS ((tree
, rtx
, enum machine_mode
,
1114 enum expand_modifier
, int));
1115 static rtx c_expand_builtin_fprintf
PARAMS ((tree
, rtx
, enum machine_mode
,
1116 enum expand_modifier
, int));
1118 /* Print a warning if a constant expression had overflow in folding.
1119 Invoke this function on every expression that the language
1120 requires to be a constant expression.
1121 Note the ANSI C standard says it is erroneous for a
1122 constant expression to overflow. */
1125 constant_expression_warning (value
)
1128 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
1129 || TREE_CODE (value
) == COMPLEX_CST
)
1130 && TREE_CONSTANT_OVERFLOW (value
) && pedantic
)
1131 pedwarn ("overflow in constant expression");
1134 /* Print a warning if an expression had overflow in folding.
1135 Invoke this function on every expression that
1136 (1) appears in the source code, and
1137 (2) might be a constant expression that overflowed, and
1138 (3) is not already checked by convert_and_check;
1139 however, do not invoke this function on operands of explicit casts. */
1142 overflow_warning (value
)
1145 if ((TREE_CODE (value
) == INTEGER_CST
1146 || (TREE_CODE (value
) == COMPLEX_CST
1147 && TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
))
1148 && TREE_OVERFLOW (value
))
1150 TREE_OVERFLOW (value
) = 0;
1151 if (skip_evaluation
== 0)
1152 warning ("integer overflow in expression");
1154 else if ((TREE_CODE (value
) == REAL_CST
1155 || (TREE_CODE (value
) == COMPLEX_CST
1156 && TREE_CODE (TREE_REALPART (value
)) == REAL_CST
))
1157 && TREE_OVERFLOW (value
))
1159 TREE_OVERFLOW (value
) = 0;
1160 if (skip_evaluation
== 0)
1161 warning ("floating point overflow in expression");
1165 /* Print a warning if a large constant is truncated to unsigned,
1166 or if -Wconversion is used and a constant < 0 is converted to unsigned.
1167 Invoke this function on every expression that might be implicitly
1168 converted to an unsigned type. */
1171 unsigned_conversion_warning (result
, operand
)
1172 tree result
, operand
;
1174 if (TREE_CODE (operand
) == INTEGER_CST
1175 && TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
1176 && TREE_UNSIGNED (TREE_TYPE (result
))
1177 && skip_evaluation
== 0
1178 && !int_fits_type_p (operand
, TREE_TYPE (result
)))
1180 if (!int_fits_type_p (operand
, signed_type (TREE_TYPE (result
))))
1181 /* This detects cases like converting -129 or 256 to unsigned char. */
1182 warning ("large integer implicitly truncated to unsigned type");
1183 else if (warn_conversion
)
1184 warning ("negative integer implicitly converted to unsigned type");
1188 /* Nonzero if constant C has a value that is permissible
1189 for type TYPE (an INTEGER_TYPE). */
1192 constant_fits_type_p (c
, type
)
1195 if (TREE_CODE (c
) == INTEGER_CST
)
1196 return int_fits_type_p (c
, type
);
1198 c
= convert (type
, c
);
1199 return !TREE_OVERFLOW (c
);
1202 /* Convert EXPR to TYPE, warning about conversion problems with constants.
1203 Invoke this function on every expression that is converted implicitly,
1204 i.e. because of language rules and not because of an explicit cast. */
1207 convert_and_check (type
, expr
)
1210 tree t
= convert (type
, expr
);
1211 if (TREE_CODE (t
) == INTEGER_CST
)
1213 if (TREE_OVERFLOW (t
))
1215 TREE_OVERFLOW (t
) = 0;
1217 /* Do not diagnose overflow in a constant expression merely
1218 because a conversion overflowed. */
1219 TREE_CONSTANT_OVERFLOW (t
) = TREE_CONSTANT_OVERFLOW (expr
);
1221 /* No warning for converting 0x80000000 to int. */
1222 if (!(TREE_UNSIGNED (type
) < TREE_UNSIGNED (TREE_TYPE (expr
))
1223 && TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
1224 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (expr
))))
1225 /* If EXPR fits in the unsigned version of TYPE,
1226 don't warn unless pedantic. */
1228 || TREE_UNSIGNED (type
)
1229 || ! constant_fits_type_p (expr
, unsigned_type (type
)))
1230 && skip_evaluation
== 0)
1231 warning ("overflow in implicit constant conversion");
1234 unsigned_conversion_warning (t
, expr
);
1239 /* A node in a list that describes references to variables (EXPR), which are
1240 either read accesses if WRITER is zero, or write accesses, in which case
1241 WRITER is the parent of EXPR. */
1248 /* Used to implement a cache the results of a call to verify_tree. We only
1249 use this for SAVE_EXPRs. */
1252 struct tlist_cache
*next
;
1253 struct tlist
*cache_before_sp
;
1254 struct tlist
*cache_after_sp
;
1258 /* Obstack to use when allocating tlist structures, and corresponding
1260 static struct obstack tlist_obstack
;
1261 static char *tlist_firstobj
= 0;
1263 /* Keep track of the identifiers we've warned about, so we can avoid duplicate
1265 static struct tlist
*warned_ids
;
1266 /* SAVE_EXPRs need special treatment. We process them only once and then
1267 cache the results. */
1268 static struct tlist_cache
*save_expr_cache
;
1270 static void add_tlist
PARAMS ((struct tlist
**, struct tlist
*, tree
, int));
1271 static void merge_tlist
PARAMS ((struct tlist
**, struct tlist
*, int));
1272 static void verify_tree
PARAMS ((tree
, struct tlist
**, struct tlist
**, tree
));
1273 static int warning_candidate_p
PARAMS ((tree
));
1274 static void warn_for_collisions
PARAMS ((struct tlist
*));
1275 static void warn_for_collisions_1
PARAMS ((tree
, tree
, struct tlist
*, int));
1276 static struct tlist
*new_tlist
PARAMS ((struct tlist
*, tree
, tree
));
1277 static void verify_sequence_points
PARAMS ((tree
));
1279 /* Create a new struct tlist and fill in its fields. */
1280 static struct tlist
*
1281 new_tlist (next
, t
, writer
)
1287 l
= (struct tlist
*) obstack_alloc (&tlist_obstack
, sizeof *l
);
1294 /* Add duplicates of the nodes found in ADD to the list *TO. If EXCLUDE_WRITER
1295 is nonnull, we ignore any node we find which has a writer equal to it. */
1298 add_tlist (to
, add
, exclude_writer
, copy
)
1301 tree exclude_writer
;
1306 struct tlist
*next
= add
->next
;
1309 if (! exclude_writer
|| add
->writer
!= exclude_writer
)
1310 *to
= copy
? new_tlist (*to
, add
->expr
, add
->writer
) : add
;
1315 /* Merge the nodes of ADD into TO. This merging process is done so that for
1316 each variable that already exists in TO, no new node is added; however if
1317 there is a write access recorded in ADD, and an occurrence on TO is only
1318 a read access, then the occurrence in TO will be modified to record the
1322 merge_tlist (to
, add
, copy
)
1327 struct tlist
**end
= to
;
1330 end
= &(*end
)->next
;
1336 struct tlist
*next
= add
->next
;
1338 for (tmp2
= *to
; tmp2
; tmp2
= tmp2
->next
)
1339 if (tmp2
->expr
== add
->expr
)
1343 tmp2
->writer
= add
->writer
;
1347 *end
= copy
? add
: new_tlist (NULL
, add
->expr
, add
->writer
);
1348 end
= &(*end
)->next
;
1355 /* WRITTEN is a variable, WRITER is its parent. Warn if any of the variable
1356 references in list LIST conflict with it, excluding reads if ONLY writers
1360 warn_for_collisions_1 (written
, writer
, list
, only_writes
)
1361 tree written
, writer
;
1367 /* Avoid duplicate warnings. */
1368 for (tmp
= warned_ids
; tmp
; tmp
= tmp
->next
)
1369 if (tmp
->expr
== written
)
1374 if (list
->expr
== written
1375 && list
->writer
!= writer
1376 && (! only_writes
|| list
->writer
))
1378 warned_ids
= new_tlist (warned_ids
, written
, NULL_TREE
);
1379 warning ("operation on `%s' may be undefined",
1380 IDENTIFIER_POINTER (DECL_NAME (list
->expr
)));
1386 /* Given a list LIST of references to variables, find whether any of these
1387 can cause conflicts due to missing sequence points. */
1390 warn_for_collisions (list
)
1395 for (tmp
= list
; tmp
; tmp
= tmp
->next
)
1398 warn_for_collisions_1 (tmp
->expr
, tmp
->writer
, list
, 0);
1402 /* Return nonzero if X is a tree that can be verified by the sequence poitn
1405 warning_candidate_p (x
)
1408 return TREE_CODE (x
) == VAR_DECL
|| TREE_CODE (x
) == PARM_DECL
;
1411 /* Walk the tree X, and record accesses to variables. If X is written by the
1412 parent tree, WRITER is the parent.
1413 We store accesses in one of the two lists: PBEFORE_SP, and PNO_SP. If this
1414 expression or its only operand forces a sequence point, then everything up
1415 to the sequence point is stored in PBEFORE_SP. Everything else gets stored
1417 Once we return, we will have emitted warnings if any subexpression before
1418 such a sequence point could be undefined. On a higher level, however, the
1419 sequence point may not be relevant, and we'll merge the two lists.
1421 Example: (b++, a) + b;
1422 The call that processes the COMPOUND_EXPR will store the increment of B
1423 in PBEFORE_SP, and the use of A in PNO_SP. The higher-level call that
1424 processes the PLUS_EXPR will need to merge the two lists so that
1425 eventually, all accesses end up on the same list (and we'll warn about the
1426 unordered subexpressions b++ and b.
1428 A note on merging. If we modify the former example so that our expression
1431 care must be taken not simply to add all three expressions into the final
1432 PNO_SP list. The function merge_tlist takes care of that by merging the
1433 before-SP list of the COMPOUND_EXPR into its after-SP list in a special
1434 way, so that no more than one access to B is recorded. */
1437 verify_tree (x
, pbefore_sp
, pno_sp
, writer
)
1439 struct tlist
**pbefore_sp
, **pno_sp
;
1442 struct tlist
*tmp_before
, *tmp_nosp
, *tmp_list2
, *tmp_list3
;
1443 enum tree_code code
;
1447 code
= TREE_CODE (x
);
1448 class = TREE_CODE_CLASS (code
);
1450 if (warning_candidate_p (x
))
1452 *pno_sp
= new_tlist (*pno_sp
, x
, writer
);
1462 case TRUTH_ANDIF_EXPR
:
1463 case TRUTH_ORIF_EXPR
:
1464 tmp_before
= tmp_nosp
= tmp_list3
= 0;
1465 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
1466 warn_for_collisions (tmp_nosp
);
1467 merge_tlist (pbefore_sp
, tmp_before
, 0);
1468 merge_tlist (pbefore_sp
, tmp_nosp
, 0);
1469 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, pno_sp
, NULL_TREE
);
1470 merge_tlist (pbefore_sp
, tmp_list3
, 0);
1474 tmp_before
= tmp_list2
= 0;
1475 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_list2
, NULL_TREE
);
1476 warn_for_collisions (tmp_list2
);
1477 merge_tlist (pbefore_sp
, tmp_before
, 0);
1478 merge_tlist (pbefore_sp
, tmp_list2
, 1);
1480 tmp_list3
= tmp_nosp
= 0;
1481 verify_tree (TREE_OPERAND (x
, 1), &tmp_list3
, &tmp_nosp
, NULL_TREE
);
1482 warn_for_collisions (tmp_nosp
);
1483 merge_tlist (pbefore_sp
, tmp_list3
, 0);
1485 tmp_list3
= tmp_list2
= 0;
1486 verify_tree (TREE_OPERAND (x
, 2), &tmp_list3
, &tmp_list2
, NULL_TREE
);
1487 warn_for_collisions (tmp_list2
);
1488 merge_tlist (pbefore_sp
, tmp_list3
, 0);
1489 /* Rather than add both tmp_nosp and tmp_list2, we have to merge the
1490 two first, to avoid warning for (a ? b++ : b++). */
1491 merge_tlist (&tmp_nosp
, tmp_list2
, 0);
1492 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
1495 case PREDECREMENT_EXPR
:
1496 case PREINCREMENT_EXPR
:
1497 case POSTDECREMENT_EXPR
:
1498 case POSTINCREMENT_EXPR
:
1499 verify_tree (TREE_OPERAND (x
, 0), pno_sp
, pno_sp
, x
);
1503 tmp_before
= tmp_nosp
= tmp_list3
= 0;
1504 verify_tree (TREE_OPERAND (x
, 1), &tmp_before
, &tmp_nosp
, NULL_TREE
);
1505 verify_tree (TREE_OPERAND (x
, 0), &tmp_list3
, &tmp_list3
, x
);
1506 /* Expressions inside the LHS are not ordered wrt. the sequence points
1507 in the RHS. Example:
1509 Despite the fact that the modification of "a" is in the before_sp
1510 list (tmp_before), it conflicts with the use of "a" in the LHS.
1511 We can handle this by adding the contents of tmp_list3
1512 to those of tmp_before, and redoing the collision warnings for that
1514 add_tlist (&tmp_before
, tmp_list3
, x
, 1);
1515 warn_for_collisions (tmp_before
);
1516 /* Exclude the LHS itself here; we first have to merge it into the
1517 tmp_nosp list. This is done to avoid warning for "a = a"; if we
1518 didn't exclude the LHS, we'd get it twice, once as a read and once
1520 add_tlist (pno_sp
, tmp_list3
, x
, 0);
1521 warn_for_collisions_1 (TREE_OPERAND (x
, 0), x
, tmp_nosp
, 1);
1523 merge_tlist (pbefore_sp
, tmp_before
, 0);
1524 if (warning_candidate_p (TREE_OPERAND (x
, 0)))
1525 merge_tlist (&tmp_nosp
, new_tlist (NULL
, TREE_OPERAND (x
, 0), x
), 0);
1526 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 1);
1530 /* We need to warn about conflicts among arguments and conflicts between
1531 args and the function address. Side effects of the function address,
1532 however, are not ordered by the sequence point of the call. */
1533 tmp_before
= tmp_nosp
= tmp_list2
= tmp_list3
= 0;
1534 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
1535 if (TREE_OPERAND (x
, 1))
1536 verify_tree (TREE_OPERAND (x
, 1), &tmp_list2
, &tmp_list3
, NULL_TREE
);
1537 merge_tlist (&tmp_list3
, tmp_list2
, 0);
1538 add_tlist (&tmp_before
, tmp_list3
, NULL_TREE
, 0);
1539 add_tlist (&tmp_before
, tmp_nosp
, NULL_TREE
, 0);
1540 warn_for_collisions (tmp_before
);
1541 add_tlist (pbefore_sp
, tmp_before
, NULL_TREE
, 0);
1545 /* Scan all the list, e.g. indices of multi dimensional array. */
1548 tmp_before
= tmp_nosp
= 0;
1549 verify_tree (TREE_VALUE (x
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
1550 merge_tlist (&tmp_nosp
, tmp_before
, 0);
1551 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
1558 struct tlist_cache
*t
;
1559 for (t
= save_expr_cache
; t
; t
= t
->next
)
1565 t
= (struct tlist_cache
*) obstack_alloc (&tlist_obstack
,
1567 t
->next
= save_expr_cache
;
1569 save_expr_cache
= t
;
1571 tmp_before
= tmp_nosp
= 0;
1572 verify_tree (TREE_OPERAND (x
, 0), &tmp_before
, &tmp_nosp
, NULL_TREE
);
1573 warn_for_collisions (tmp_nosp
);
1578 struct tlist
*t
= tmp_nosp
;
1580 merge_tlist (&tmp_list3
, t
, 0);
1582 t
->cache_before_sp
= tmp_before
;
1583 t
->cache_after_sp
= tmp_list3
;
1585 merge_tlist (pbefore_sp
, t
->cache_before_sp
, 1);
1586 add_tlist (pno_sp
, t
->cache_after_sp
, NULL_TREE
, 1);
1595 if (first_rtl_op (code
) == 0)
1597 x
= TREE_OPERAND (x
, 0);
1613 int max
= first_rtl_op (TREE_CODE (x
));
1614 for (lp
= 0; lp
< max
; lp
++)
1616 tmp_before
= tmp_nosp
= 0;
1617 verify_tree (TREE_OPERAND (x
, lp
), &tmp_before
, &tmp_nosp
, NULL_TREE
);
1618 merge_tlist (&tmp_nosp
, tmp_before
, 0);
1619 add_tlist (pno_sp
, tmp_nosp
, NULL_TREE
, 0);
1626 /* Try to warn for undefined behaviour in EXPR due to missing sequence
1630 verify_sequence_points (expr
)
1633 struct tlist
*before_sp
= 0, *after_sp
= 0;
1636 save_expr_cache
= 0;
1637 if (tlist_firstobj
== 0)
1639 gcc_obstack_init (&tlist_obstack
);
1640 tlist_firstobj
= obstack_alloc (&tlist_obstack
, 0);
1643 verify_tree (expr
, &before_sp
, &after_sp
, 0);
1644 warn_for_collisions (after_sp
);
1645 obstack_free (&tlist_obstack
, tlist_firstobj
);
1649 c_expand_expr_stmt (expr
)
1652 /* Do default conversion if safe and possibly important,
1653 in case within ({...}). */
1654 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
1655 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
1656 expr
= default_conversion (expr
);
1658 if (warn_sequence_point
)
1659 verify_sequence_points (expr
);
1661 if (TREE_TYPE (expr
) != error_mark_node
1662 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr
))
1663 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
1664 error ("expression statement has incomplete type");
1666 last_expr_type
= TREE_TYPE (expr
);
1667 return add_stmt (build_stmt (EXPR_STMT
, expr
));
1670 /* Validate the expression after `case' and apply default promotions. */
1673 check_case_value (value
)
1676 if (value
== NULL_TREE
)
1679 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
1680 STRIP_TYPE_NOPS (value
);
1681 /* In C++, the following is allowed:
1684 switch (...) { case i: ... }
1686 So, we try to reduce the VALUE to a constant that way. */
1687 if (c_language
== clk_cplusplus
)
1689 value
= decl_constant_value (value
);
1690 STRIP_TYPE_NOPS (value
);
1691 value
= fold (value
);
1694 if (TREE_CODE (value
) != INTEGER_CST
1695 && value
!= error_mark_node
)
1697 error ("case label does not reduce to an integer constant");
1698 value
= error_mark_node
;
1701 /* Promote char or short to int. */
1702 value
= default_conversion (value
);
1704 constant_expression_warning (value
);
1709 /* Return an integer type with BITS bits of precision,
1710 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
1713 type_for_size (bits
, unsignedp
)
1717 if (bits
== TYPE_PRECISION (integer_type_node
))
1718 return unsignedp
? unsigned_type_node
: integer_type_node
;
1720 if (bits
== TYPE_PRECISION (signed_char_type_node
))
1721 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1723 if (bits
== TYPE_PRECISION (short_integer_type_node
))
1724 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1726 if (bits
== TYPE_PRECISION (long_integer_type_node
))
1727 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1729 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
1730 return (unsignedp
? long_long_unsigned_type_node
1731 : long_long_integer_type_node
);
1733 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
1734 return (unsignedp
? widest_unsigned_literal_type_node
1735 : widest_integer_literal_type_node
);
1737 if (bits
<= TYPE_PRECISION (intQI_type_node
))
1738 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
1740 if (bits
<= TYPE_PRECISION (intHI_type_node
))
1741 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
1743 if (bits
<= TYPE_PRECISION (intSI_type_node
))
1744 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
1746 if (bits
<= TYPE_PRECISION (intDI_type_node
))
1747 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
1752 /* Return a data type that has machine mode MODE.
1753 If the mode is an integer,
1754 then UNSIGNEDP selects between signed and unsigned types. */
1757 type_for_mode (mode
, unsignedp
)
1758 enum machine_mode mode
;
1761 if (mode
== TYPE_MODE (integer_type_node
))
1762 return unsignedp
? unsigned_type_node
: integer_type_node
;
1764 if (mode
== TYPE_MODE (signed_char_type_node
))
1765 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1767 if (mode
== TYPE_MODE (short_integer_type_node
))
1768 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1770 if (mode
== TYPE_MODE (long_integer_type_node
))
1771 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1773 if (mode
== TYPE_MODE (long_long_integer_type_node
))
1774 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
1776 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
1777 return unsignedp
? widest_unsigned_literal_type_node
1778 : widest_integer_literal_type_node
;
1780 if (mode
== TYPE_MODE (intQI_type_node
))
1781 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
1783 if (mode
== TYPE_MODE (intHI_type_node
))
1784 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
1786 if (mode
== TYPE_MODE (intSI_type_node
))
1787 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
1789 if (mode
== TYPE_MODE (intDI_type_node
))
1790 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
1792 #if HOST_BITS_PER_WIDE_INT >= 64
1793 if (mode
== TYPE_MODE (intTI_type_node
))
1794 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
1797 if (mode
== TYPE_MODE (float_type_node
))
1798 return float_type_node
;
1800 if (mode
== TYPE_MODE (double_type_node
))
1801 return double_type_node
;
1803 if (mode
== TYPE_MODE (long_double_type_node
))
1804 return long_double_type_node
;
1806 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
1807 return build_pointer_type (char_type_node
);
1809 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
1810 return build_pointer_type (integer_type_node
);
1812 #ifdef VECTOR_MODE_SUPPORTED_P
1813 if (mode
== TYPE_MODE (V4SF_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
1814 return V4SF_type_node
;
1815 if (mode
== TYPE_MODE (V4SI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
1816 return V4SI_type_node
;
1817 if (mode
== TYPE_MODE (V2SI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
1818 return V2SI_type_node
;
1819 if (mode
== TYPE_MODE (V4HI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
1820 return V4HI_type_node
;
1821 if (mode
== TYPE_MODE (V8QI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
1822 return V8QI_type_node
;
1828 /* Return an unsigned type the same as TYPE in other respects. */
1830 unsigned_type (type
)
1833 tree type1
= TYPE_MAIN_VARIANT (type
);
1834 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
1835 return unsigned_char_type_node
;
1836 if (type1
== integer_type_node
)
1837 return unsigned_type_node
;
1838 if (type1
== short_integer_type_node
)
1839 return short_unsigned_type_node
;
1840 if (type1
== long_integer_type_node
)
1841 return long_unsigned_type_node
;
1842 if (type1
== long_long_integer_type_node
)
1843 return long_long_unsigned_type_node
;
1844 if (type1
== widest_integer_literal_type_node
)
1845 return widest_unsigned_literal_type_node
;
1846 #if HOST_BITS_PER_WIDE_INT >= 64
1847 if (type1
== intTI_type_node
)
1848 return unsigned_intTI_type_node
;
1850 if (type1
== intDI_type_node
)
1851 return unsigned_intDI_type_node
;
1852 if (type1
== intSI_type_node
)
1853 return unsigned_intSI_type_node
;
1854 if (type1
== intHI_type_node
)
1855 return unsigned_intHI_type_node
;
1856 if (type1
== intQI_type_node
)
1857 return unsigned_intQI_type_node
;
1859 return signed_or_unsigned_type (1, type
);
1862 /* Return a signed type the same as TYPE in other respects. */
1868 tree type1
= TYPE_MAIN_VARIANT (type
);
1869 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
1870 return signed_char_type_node
;
1871 if (type1
== unsigned_type_node
)
1872 return integer_type_node
;
1873 if (type1
== short_unsigned_type_node
)
1874 return short_integer_type_node
;
1875 if (type1
== long_unsigned_type_node
)
1876 return long_integer_type_node
;
1877 if (type1
== long_long_unsigned_type_node
)
1878 return long_long_integer_type_node
;
1879 if (type1
== widest_unsigned_literal_type_node
)
1880 return widest_integer_literal_type_node
;
1881 #if HOST_BITS_PER_WIDE_INT >= 64
1882 if (type1
== unsigned_intTI_type_node
)
1883 return intTI_type_node
;
1885 if (type1
== unsigned_intDI_type_node
)
1886 return intDI_type_node
;
1887 if (type1
== unsigned_intSI_type_node
)
1888 return intSI_type_node
;
1889 if (type1
== unsigned_intHI_type_node
)
1890 return intHI_type_node
;
1891 if (type1
== unsigned_intQI_type_node
)
1892 return intQI_type_node
;
1894 return signed_or_unsigned_type (0, type
);
1897 /* Return a type the same as TYPE except unsigned or
1898 signed according to UNSIGNEDP. */
1901 signed_or_unsigned_type (unsignedp
, type
)
1905 if (! INTEGRAL_TYPE_P (type
)
1906 || TREE_UNSIGNED (type
) == unsignedp
)
1909 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
1910 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
1911 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
1912 return unsignedp
? unsigned_type_node
: integer_type_node
;
1913 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
1914 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
1915 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
1916 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
1917 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
1918 return (unsignedp
? long_long_unsigned_type_node
1919 : long_long_integer_type_node
);
1920 if (TYPE_PRECISION (type
) == TYPE_PRECISION (widest_integer_literal_type_node
))
1921 return (unsignedp
? widest_unsigned_literal_type_node
1922 : widest_integer_literal_type_node
);
1926 /* Return the minimum number of bits needed to represent VALUE in a
1927 signed or unsigned type, UNSIGNEDP says which. */
1930 min_precision (value
, unsignedp
)
1936 /* If the value is negative, compute its negative minus 1. The latter
1937 adjustment is because the absolute value of the largest negative value
1938 is one larger than the largest positive value. This is equivalent to
1939 a bit-wise negation, so use that operation instead. */
1941 if (tree_int_cst_sgn (value
) < 0)
1942 value
= fold (build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
));
1944 /* Return the number of bits needed, taking into account the fact
1945 that we need one more bit for a signed than unsigned type. */
1947 if (integer_zerop (value
))
1950 log
= tree_floor_log2 (value
);
1952 return log
+ 1 + ! unsignedp
;
1955 /* Print an error message for invalid operands to arith operation CODE.
1956 NOP_EXPR is used as a special case (see truthvalue_conversion). */
1959 binary_op_error (code
)
1960 enum tree_code code
;
1962 register const char *opname
;
1967 error ("invalid truth-value expression");
1971 opname
= "+"; break;
1973 opname
= "-"; break;
1975 opname
= "*"; break;
1977 opname
= "max"; break;
1979 opname
= "min"; break;
1981 opname
= "=="; break;
1983 opname
= "!="; break;
1985 opname
= "<="; break;
1987 opname
= ">="; break;
1989 opname
= "<"; break;
1991 opname
= ">"; break;
1993 opname
= "<<"; break;
1995 opname
= ">>"; break;
1996 case TRUNC_MOD_EXPR
:
1997 case FLOOR_MOD_EXPR
:
1998 opname
= "%"; break;
1999 case TRUNC_DIV_EXPR
:
2000 case FLOOR_DIV_EXPR
:
2001 opname
= "/"; break;
2003 opname
= "&"; break;
2005 opname
= "|"; break;
2006 case TRUTH_ANDIF_EXPR
:
2007 opname
= "&&"; break;
2008 case TRUTH_ORIF_EXPR
:
2009 opname
= "||"; break;
2011 opname
= "^"; break;
2014 opname
= "rotate"; break;
2016 opname
= "unknown"; break;
2018 error ("invalid operands to binary %s", opname
);
2021 /* Subroutine of build_binary_op, used for comparison operations.
2022 See if the operands have both been converted from subword integer types
2023 and, if so, perhaps change them both back to their original type.
2024 This function is also responsible for converting the two operands
2025 to the proper common type for comparison.
2027 The arguments of this function are all pointers to local variables
2028 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2029 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2031 If this function returns nonzero, it means that the comparison has
2032 a constant value. What this function returns is an expression for
2036 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
2037 tree
*op0_ptr
, *op1_ptr
;
2039 enum tree_code
*rescode_ptr
;
2042 tree op0
= *op0_ptr
;
2043 tree op1
= *op1_ptr
;
2044 int unsignedp0
, unsignedp1
;
2046 tree primop0
, primop1
;
2047 enum tree_code code
= *rescode_ptr
;
2049 /* Throw away any conversions to wider types
2050 already present in the operands. */
2052 primop0
= get_narrower (op0
, &unsignedp0
);
2053 primop1
= get_narrower (op1
, &unsignedp1
);
2055 /* Handle the case that OP0 does not *contain* a conversion
2056 but it *requires* conversion to FINAL_TYPE. */
2058 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
2059 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
2060 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
2061 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
2063 /* If one of the operands must be floated, we cannot optimize. */
2064 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
2065 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
2067 /* If first arg is constant, swap the args (changing operation
2068 so value is preserved), for canonicalization. Don't do this if
2069 the second arg is 0. */
2071 if (TREE_CONSTANT (primop0
)
2072 && ! integer_zerop (primop1
) && ! real_zerop (primop1
))
2074 register tree tem
= primop0
;
2075 register int temi
= unsignedp0
;
2083 unsignedp0
= unsignedp1
;
2106 *rescode_ptr
= code
;
2109 /* If comparing an integer against a constant more bits wide,
2110 maybe we can deduce a value of 1 or 0 independent of the data.
2111 Or else truncate the constant now
2112 rather than extend the variable at run time.
2114 This is only interesting if the constant is the wider arg.
2115 Also, it is not safe if the constant is unsigned and the
2116 variable arg is signed, since in this case the variable
2117 would be sign-extended and then regarded as unsigned.
2118 Our technique fails in this case because the lowest/highest
2119 possible unsigned results don't follow naturally from the
2120 lowest/highest possible values of the variable operand.
2121 For just EQ_EXPR and NE_EXPR there is another technique that
2122 could be used: see if the constant can be faithfully represented
2123 in the other operand's type, by truncating it and reextending it
2124 and see if that preserves the constant's value. */
2126 if (!real1
&& !real2
2127 && TREE_CODE (primop1
) == INTEGER_CST
2128 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
2130 int min_gt
, max_gt
, min_lt
, max_lt
;
2131 tree maxval
, minval
;
2132 /* 1 if comparison is nominally unsigned. */
2133 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
2136 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
2138 /* If TYPE is an enumeration, then we need to get its min/max
2139 values from it's underlying integral type, not the enumerated
2141 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
2142 type
= type_for_size (TYPE_PRECISION (type
), unsignedp0
);
2144 maxval
= TYPE_MAX_VALUE (type
);
2145 minval
= TYPE_MIN_VALUE (type
);
2147 if (unsignedp
&& !unsignedp0
)
2148 *restype_ptr
= signed_type (*restype_ptr
);
2150 if (TREE_TYPE (primop1
) != *restype_ptr
)
2151 primop1
= convert (*restype_ptr
, primop1
);
2152 if (type
!= *restype_ptr
)
2154 minval
= convert (*restype_ptr
, minval
);
2155 maxval
= convert (*restype_ptr
, maxval
);
2158 if (unsignedp
&& unsignedp0
)
2160 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
2161 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
2162 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
2163 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
2167 min_gt
= INT_CST_LT (primop1
, minval
);
2168 max_gt
= INT_CST_LT (primop1
, maxval
);
2169 min_lt
= INT_CST_LT (minval
, primop1
);
2170 max_lt
= INT_CST_LT (maxval
, primop1
);
2174 /* This used to be a switch, but Genix compiler can't handle that. */
2175 if (code
== NE_EXPR
)
2177 if (max_lt
|| min_gt
)
2178 val
= boolean_true_node
;
2180 else if (code
== EQ_EXPR
)
2182 if (max_lt
|| min_gt
)
2183 val
= boolean_false_node
;
2185 else if (code
== LT_EXPR
)
2188 val
= boolean_true_node
;
2190 val
= boolean_false_node
;
2192 else if (code
== GT_EXPR
)
2195 val
= boolean_true_node
;
2197 val
= boolean_false_node
;
2199 else if (code
== LE_EXPR
)
2202 val
= boolean_true_node
;
2204 val
= boolean_false_node
;
2206 else if (code
== GE_EXPR
)
2209 val
= boolean_true_node
;
2211 val
= boolean_false_node
;
2214 /* If primop0 was sign-extended and unsigned comparison specd,
2215 we did a signed comparison above using the signed type bounds.
2216 But the comparison we output must be unsigned.
2218 Also, for inequalities, VAL is no good; but if the signed
2219 comparison had *any* fixed result, it follows that the
2220 unsigned comparison just tests the sign in reverse
2221 (positive values are LE, negative ones GE).
2222 So we can generate an unsigned comparison
2223 against an extreme value of the signed type. */
2225 if (unsignedp
&& !unsignedp0
)
2232 primop1
= TYPE_MIN_VALUE (type
);
2238 primop1
= TYPE_MAX_VALUE (type
);
2245 type
= unsigned_type (type
);
2248 if (!max_gt
&& !unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2250 /* This is the case of (char)x >?< 0x80, which people used to use
2251 expecting old C compilers to change the 0x80 into -0x80. */
2252 if (val
== boolean_false_node
)
2253 warning ("comparison is always false due to limited range of data type");
2254 if (val
== boolean_true_node
)
2255 warning ("comparison is always true due to limited range of data type");
2258 if (!min_lt
&& unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2260 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2261 if (val
== boolean_false_node
)
2262 warning ("comparison is always false due to limited range of data type");
2263 if (val
== boolean_true_node
)
2264 warning ("comparison is always true due to limited range of data type");
2269 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2270 if (TREE_SIDE_EFFECTS (primop0
))
2271 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
2275 /* Value is not predetermined, but do the comparison
2276 in the type of the operand that is not constant.
2277 TYPE is already properly set. */
2279 else if (real1
&& real2
2280 && (TYPE_PRECISION (TREE_TYPE (primop0
))
2281 == TYPE_PRECISION (TREE_TYPE (primop1
))))
2282 type
= TREE_TYPE (primop0
);
2284 /* If args' natural types are both narrower than nominal type
2285 and both extend in the same manner, compare them
2286 in the type of the wider arg.
2287 Otherwise must actually extend both to the nominal
2288 common type lest different ways of extending
2290 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2292 else if (unsignedp0
== unsignedp1
&& real1
== real2
2293 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
2294 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
2296 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
2297 type
= signed_or_unsigned_type (unsignedp0
2298 || TREE_UNSIGNED (*restype_ptr
),
2300 /* Make sure shorter operand is extended the right way
2301 to match the longer operand. */
2302 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
2304 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
2309 /* Here we must do the comparison on the nominal type
2310 using the args exactly as we received them. */
2311 type
= *restype_ptr
;
2315 if (!real1
&& !real2
&& integer_zerop (primop1
)
2316 && TREE_UNSIGNED (*restype_ptr
))
2322 /* All unsigned values are >= 0, so we warn if extra warnings
2323 are requested. However, if OP0 is a constant that is
2324 >= 0, the signedness of the comparison isn't an issue,
2325 so suppress the warning. */
2326 if (extra_warnings
&& !in_system_header
2327 && ! (TREE_CODE (primop0
) == INTEGER_CST
2328 && ! TREE_OVERFLOW (convert (signed_type (type
),
2330 warning ("comparison of unsigned expression >= 0 is always true");
2331 value
= boolean_true_node
;
2335 if (extra_warnings
&& !in_system_header
2336 && ! (TREE_CODE (primop0
) == INTEGER_CST
2337 && ! TREE_OVERFLOW (convert (signed_type (type
),
2339 warning ("comparison of unsigned expression < 0 is always false");
2340 value
= boolean_false_node
;
2349 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2350 if (TREE_SIDE_EFFECTS (primop0
))
2351 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
2358 *op0_ptr
= convert (type
, primop0
);
2359 *op1_ptr
= convert (type
, primop1
);
2361 *restype_ptr
= boolean_type_node
;
2366 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2367 or validate its data type for an `if' or `while' statement or ?..: exp.
2369 This preparation consists of taking the ordinary
2370 representation of an expression expr and producing a valid tree
2371 boolean expression describing whether expr is nonzero. We could
2372 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2373 but we optimize comparisons, &&, ||, and !.
2375 The resulting type should always be `boolean_type_node'. */
2378 truthvalue_conversion (expr
)
2381 if (TREE_CODE (expr
) == ERROR_MARK
)
2384 #if 0 /* This appears to be wrong for C++. */
2385 /* These really should return error_mark_node after 2.4 is stable.
2386 But not all callers handle ERROR_MARK properly. */
2387 switch (TREE_CODE (TREE_TYPE (expr
)))
2390 error ("struct type value used where scalar is required");
2391 return boolean_false_node
;
2394 error ("union type value used where scalar is required");
2395 return boolean_false_node
;
2398 error ("array type value used where scalar is required");
2399 return boolean_false_node
;
2406 switch (TREE_CODE (expr
))
2409 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
2410 case TRUTH_ANDIF_EXPR
:
2411 case TRUTH_ORIF_EXPR
:
2412 case TRUTH_AND_EXPR
:
2414 case TRUTH_XOR_EXPR
:
2415 case TRUTH_NOT_EXPR
:
2416 TREE_TYPE (expr
) = boolean_type_node
;
2423 return integer_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2426 return real_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2429 /* If we are taking the address of a external decl, it might be zero
2430 if it is weak, so we cannot optimize. */
2431 if (DECL_P (TREE_OPERAND (expr
, 0))
2432 && DECL_EXTERNAL (TREE_OPERAND (expr
, 0)))
2435 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
2436 return build (COMPOUND_EXPR
, boolean_type_node
,
2437 TREE_OPERAND (expr
, 0), boolean_true_node
);
2439 return boolean_true_node
;
2442 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
2443 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
2444 truthvalue_conversion (TREE_OPERAND (expr
, 0)),
2445 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2452 /* These don't change whether an object is non-zero or zero. */
2453 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2457 /* These don't change whether an object is zero or non-zero, but
2458 we can't ignore them if their second arg has side-effects. */
2459 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
2460 return build (COMPOUND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 1),
2461 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
2463 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2466 /* Distribute the conversion into the arms of a COND_EXPR. */
2467 return fold (build (COND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 0),
2468 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2469 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
2472 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2473 since that affects how `default_conversion' will behave. */
2474 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
2475 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
2477 /* fall through... */
2479 /* If this is widening the argument, we can ignore it. */
2480 if (TYPE_PRECISION (TREE_TYPE (expr
))
2481 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
2482 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2486 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2488 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
2489 && TREE_CODE (TREE_TYPE (expr
)) == REAL_TYPE
)
2491 /* fall through... */
2493 /* This and MINUS_EXPR can be changed into a comparison of the
2495 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
2496 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
2497 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
2498 TREE_OPERAND (expr
, 1), 1);
2499 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
2500 fold (build1 (NOP_EXPR
,
2501 TREE_TYPE (TREE_OPERAND (expr
, 0)),
2502 TREE_OPERAND (expr
, 1))), 1);
2505 if (integer_onep (TREE_OPERAND (expr
, 1))
2506 && TREE_TYPE (expr
) != boolean_type_node
)
2507 /* Using convert here would cause infinite recursion. */
2508 return build1 (NOP_EXPR
, boolean_type_node
, expr
);
2512 if (warn_parentheses
&& C_EXP_ORIGINAL_CODE (expr
) == MODIFY_EXPR
)
2513 warning ("suggest parentheses around assignment used as truth value");
2520 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
2522 tree tem
= save_expr (expr
);
2523 return (build_binary_op
2524 ((TREE_SIDE_EFFECTS (expr
)
2525 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
2526 truthvalue_conversion (build_unary_op (REALPART_EXPR
, tem
, 0)),
2527 truthvalue_conversion (build_unary_op (IMAGPART_EXPR
, tem
, 0)),
2531 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
2534 static tree builtin_function_2
PARAMS ((const char *, const char *, tree
, tree
,
2535 int, enum built_in_class
, int, int,
2538 /* Make a variant type in the proper way for C/C++, propagating qualifiers
2539 down to the element type of an array. */
2542 c_build_qualified_type (type
, type_quals
)
2546 /* A restrict-qualified pointer type must be a pointer to object or
2547 incomplete type. Note that the use of POINTER_TYPE_P also allows
2548 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
2549 the C++ front-end also use POINTER_TYPE for pointer-to-member
2550 values, so even though it should be illegal to use `restrict'
2551 with such an entity we don't flag that here. Thus, special case
2552 code for that case is required in the C++ front-end. */
2553 if ((type_quals
& TYPE_QUAL_RESTRICT
)
2554 && (!POINTER_TYPE_P (type
)
2555 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
))))
2557 error ("invalid use of `restrict'");
2558 type_quals
&= ~TYPE_QUAL_RESTRICT
;
2561 if (TREE_CODE (type
) == ARRAY_TYPE
)
2562 return build_array_type (c_build_qualified_type (TREE_TYPE (type
),
2564 TYPE_DOMAIN (type
));
2565 return build_qualified_type (type
, type_quals
);
2568 /* Apply the TYPE_QUALS to the new DECL. */
2571 c_apply_type_quals_to_decl (type_quals
, decl
)
2575 if ((type_quals
& TYPE_QUAL_CONST
)
2576 || (TREE_TYPE (decl
)
2577 && TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
))
2578 TREE_READONLY (decl
) = 1;
2579 if (type_quals
& TYPE_QUAL_VOLATILE
)
2581 TREE_SIDE_EFFECTS (decl
) = 1;
2582 TREE_THIS_VOLATILE (decl
) = 1;
2584 if (type_quals
& TYPE_QUAL_RESTRICT
)
2586 if (!TREE_TYPE (decl
)
2587 || !POINTER_TYPE_P (TREE_TYPE (decl
))
2588 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl
))))
2589 error ("invalid use of `restrict'");
2590 else if (flag_strict_aliasing
)
2592 /* No two restricted pointers can point at the same thing.
2593 However, a restricted pointer can point at the same thing
2594 as an unrestricted pointer, if that unrestricted pointer
2595 is based on the restricted pointer. So, we make the
2596 alias set for the restricted pointer a subset of the
2597 alias set for the type pointed to by the type of the
2600 HOST_WIDE_INT pointed_to_alias_set
2601 = get_alias_set (TREE_TYPE (TREE_TYPE (decl
)));
2603 if (pointed_to_alias_set
== 0)
2604 /* It's not legal to make a subset of alias set zero. */
2608 DECL_POINTER_ALIAS_SET (decl
) = new_alias_set ();
2609 record_alias_subset (pointed_to_alias_set
,
2610 DECL_POINTER_ALIAS_SET (decl
));
2617 /* Return the typed-based alias set for T, which may be an expression
2618 or a type. Return -1 if we don't do anything special. */
2621 lang_get_alias_set (t
)
2626 /* We know nothing about vector types */
2627 if (TREE_CODE (t
) == VECTOR_TYPE
)
2630 /* Permit type-punning when accessing a union, provided the access
2631 is directly through the union. For example, this code does not
2632 permit taking the address of a union member and then storing
2633 through it. Even the type-punning allowed here is a GCC
2634 extension, albeit a common and useful one; the C standard says
2635 that such accesses have implementation-defined behavior. */
2637 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
2638 u
= TREE_OPERAND (u
, 0))
2639 if (TREE_CODE (u
) == COMPONENT_REF
2640 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
2643 /* If this is a char *, the ANSI C standard says it can alias
2644 anything. Note that all references need do this. */
2645 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 'r'
2646 && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
2647 && TYPE_PRECISION (TREE_TYPE (t
)) == TYPE_PRECISION (char_type_node
))
2650 /* That's all the expressions we handle specially. */
2654 /* The C standard specifically allows aliasing between signed and
2655 unsigned variants of the same type. We treat the signed
2656 variant as canonical. */
2657 if (TREE_CODE (t
) == INTEGER_TYPE
&& TREE_UNSIGNED (t
))
2659 tree t1
= signed_type (t
);
2661 /* t1 == t can happen for boolean nodes which are always unsigned. */
2663 return get_alias_set (t1
);
2665 else if (POINTER_TYPE_P (t
))
2669 /* Unfortunately, there is no canonical form of a pointer type.
2670 In particular, if we have `typedef int I', then `int *', and
2671 `I *' are different types. So, we have to pick a canonical
2672 representative. We do this below.
2674 Technically, this approach is actually more conservative that
2675 it needs to be. In particular, `const int *' and `int *'
2676 chould be in different alias sets, according to the C and C++
2677 standard, since their types are not the same, and so,
2678 technically, an `int **' and `const int **' cannot point at
2681 But, the standard is wrong. In particular, this code is
2686 const int* const* cipp = &ip;
2688 And, it doesn't make sense for that to be legal unless you
2689 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
2690 the pointed-to types. This issue has been reported to the
2692 t1
= build_type_no_quals (t
);
2694 return get_alias_set (t1
);
2696 /* It's not yet safe to use alias sets for classes in C++ because
2697 the TYPE_FIELDs list for a class doesn't mention base classes. */
2698 else if (c_language
== clk_cplusplus
&& AGGREGATE_TYPE_P (t
))
2704 /* Build tree nodes and builtin functions common to both C and C++ language
2708 c_common_nodes_and_builtins ()
2710 int wchar_type_size
;
2711 tree array_domain_type
;
2713 tree memcpy_ftype
, memset_ftype
, strlen_ftype
;
2714 tree bzero_ftype
, bcmp_ftype
, puts_ftype
, printf_ftype
;
2715 tree fputs_ftype
, fputc_ftype
, fwrite_ftype
, fprintf_ftype
;
2716 tree endlink
, int_endlink
, double_endlink
, unsigned_endlink
;
2717 tree cstring_endlink
, sizetype_endlink
;
2718 tree ptr_ftype
, ptr_ftype_unsigned
;
2719 tree void_ftype_any
, void_ftype_int
, int_ftype_any
;
2720 tree double_ftype_double
, double_ftype_double_double
;
2721 tree float_ftype_float
, ldouble_ftype_ldouble
;
2722 tree cfloat_ftype_cfloat
, cdouble_ftype_cdouble
, cldouble_ftype_cldouble
;
2723 tree float_ftype_cfloat
, double_ftype_cdouble
, ldouble_ftype_cldouble
;
2724 tree int_ftype_cptr_cptr_sizet
, sizet_ftype_cstring_cstring
;
2725 tree int_ftype_cstring_cstring
, string_ftype_string_cstring
;
2726 tree string_ftype_cstring_int
, string_ftype_cstring_cstring
;
2727 tree string_ftype_string_cstring_sizet
, int_ftype_cstring_cstring_sizet
;
2728 tree long_ftype_long
;
2729 tree longlong_ftype_longlong
;
2730 tree intmax_ftype_intmax
;
2731 /* Either char* or void*. */
2732 tree traditional_ptr_type_node
;
2733 /* Either const char* or const void*. */
2734 tree traditional_cptr_type_node
;
2735 tree traditional_len_type_node
;
2736 tree traditional_len_endlink
;
2737 tree va_list_ref_type_node
;
2738 tree va_list_arg_type_node
;
2740 /* Define `int' and `char' first so that dbx will output them first. */
2741 record_builtin_type (RID_INT
, NULL_PTR
, integer_type_node
);
2742 record_builtin_type (RID_CHAR
, "char", char_type_node
);
2744 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
2745 "unsigned long", "long long unsigned" and "unsigned short" were in C++
2746 but not C. Are the conditionals here needed? */
2747 if (c_language
== clk_cplusplus
)
2748 record_builtin_type (RID_SIGNED
, NULL_PTR
, integer_type_node
);
2749 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
2750 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
2751 record_builtin_type (RID_MAX
, "long unsigned int",
2752 long_unsigned_type_node
);
2753 if (c_language
== clk_cplusplus
)
2754 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
2755 record_builtin_type (RID_MAX
, "long long int",
2756 long_long_integer_type_node
);
2757 record_builtin_type (RID_MAX
, "long long unsigned int",
2758 long_long_unsigned_type_node
);
2759 if (c_language
== clk_cplusplus
)
2760 record_builtin_type (RID_MAX
, "long long unsigned",
2761 long_long_unsigned_type_node
);
2762 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
2763 record_builtin_type (RID_MAX
, "short unsigned int",
2764 short_unsigned_type_node
);
2765 if (c_language
== clk_cplusplus
)
2766 record_builtin_type (RID_MAX
, "unsigned short",
2767 short_unsigned_type_node
);
2769 /* Define both `signed char' and `unsigned char'. */
2770 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
2771 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
2773 /* These are types that type_for_size and type_for_mode use. */
2774 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intQI_type_node
));
2775 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intHI_type_node
));
2776 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intSI_type_node
));
2777 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intDI_type_node
));
2778 #if HOST_BITS_PER_WIDE_INT >= 64
2779 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__int128_t"), intTI_type_node
));
2781 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intQI_type_node
));
2782 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intHI_type_node
));
2783 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intSI_type_node
));
2784 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intDI_type_node
));
2785 #if HOST_BITS_PER_WIDE_INT >= 64
2786 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__uint128_t"), unsigned_intTI_type_node
));
2789 /* Create the widest literal types. */
2790 widest_integer_literal_type_node
2791 = make_signed_type (HOST_BITS_PER_WIDE_INT
* 2);
2792 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
,
2793 widest_integer_literal_type_node
));
2795 widest_unsigned_literal_type_node
2796 = make_unsigned_type (HOST_BITS_PER_WIDE_INT
* 2);
2797 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
,
2798 widest_unsigned_literal_type_node
));
2800 /* `unsigned long' is the standard type for sizeof.
2801 Note that stddef.h uses `unsigned long',
2802 and this must agree, even if long and int are the same size. */
2804 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE
)));
2805 signed_size_type_node
= signed_type (c_size_type_node
);
2806 if (flag_traditional
)
2807 c_size_type_node
= signed_size_type_node
;
2808 set_sizetype (c_size_type_node
);
2810 build_common_tree_nodes_2 (flag_short_double
);
2812 record_builtin_type (RID_FLOAT
, NULL_PTR
, float_type_node
);
2813 record_builtin_type (RID_DOUBLE
, NULL_PTR
, double_type_node
);
2814 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
2816 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex int"),
2817 complex_integer_type_node
));
2818 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex float"),
2819 complex_float_type_node
));
2820 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex double"),
2821 complex_double_type_node
));
2822 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex long double"),
2823 complex_long_double_type_node
));
2825 record_builtin_type (RID_VOID
, NULL_PTR
, void_type_node
);
2827 void_list_node
= build_void_list_node ();
2829 /* Make a type to be the domain of a few array types
2830 whose domains don't really matter.
2831 200 is small enough that it always fits in size_t
2832 and large enough that it can hold most function names for the
2833 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
2834 array_domain_type
= build_index_type (size_int (200));
2836 /* Make a type for arrays of characters.
2837 With luck nothing will ever really depend on the length of this
2839 char_array_type_node
2840 = build_array_type (char_type_node
, array_domain_type
);
2842 /* Likewise for arrays of ints. */
2844 = build_array_type (integer_type_node
, array_domain_type
);
2846 #ifdef MD_INIT_BUILTINS
2850 /* This is special for C++ so functions can be overloaded. */
2851 wchar_type_node
= get_identifier (flag_short_wchar
2852 ? "short unsigned int"
2854 wchar_type_node
= TREE_TYPE (identifier_global_value (wchar_type_node
));
2855 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
2856 if (c_language
== clk_cplusplus
)
2858 if (TREE_UNSIGNED (wchar_type_node
))
2859 wchar_type_node
= make_unsigned_type (wchar_type_size
);
2861 wchar_type_node
= make_signed_type (wchar_type_size
);
2862 record_builtin_type (RID_WCHAR
, "wchar_t", wchar_type_node
);
2866 signed_wchar_type_node
= signed_type (wchar_type_node
);
2867 unsigned_wchar_type_node
= unsigned_type (wchar_type_node
);
2870 /* This is for wide string constants. */
2871 wchar_array_type_node
2872 = build_array_type (wchar_type_node
, array_domain_type
);
2874 string_type_node
= build_pointer_type (char_type_node
);
2875 const_string_type_node
2876 = build_pointer_type (build_type_variant (char_type_node
, 1, 0));
2879 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE
)));
2882 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE
)));
2884 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE
)));
2886 default_function_type
= build_function_type (integer_type_node
, NULL_TREE
);
2888 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE
)));
2889 unsigned_ptrdiff_type_node
= unsigned_type (ptrdiff_type_node
);
2891 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_va_list"),
2892 va_list_type_node
));
2894 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_ptrdiff_t"),
2895 ptrdiff_type_node
));
2897 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_size_t"),
2900 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
2902 va_list_arg_type_node
= va_list_ref_type_node
=
2903 build_pointer_type (TREE_TYPE (va_list_type_node
));
2907 va_list_arg_type_node
= va_list_type_node
;
2908 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
2911 endlink
= void_list_node
;
2912 int_endlink
= tree_cons (NULL_TREE
, integer_type_node
, endlink
);
2913 double_endlink
= tree_cons (NULL_TREE
, double_type_node
, endlink
);
2914 unsigned_endlink
= tree_cons (NULL_TREE
, unsigned_type_node
, endlink
);
2915 cstring_endlink
= tree_cons (NULL_TREE
, const_string_type_node
, endlink
);
2917 ptr_ftype
= build_function_type (ptr_type_node
, NULL_TREE
);
2918 ptr_ftype_unsigned
= build_function_type (ptr_type_node
, unsigned_endlink
);
2919 sizetype_endlink
= tree_cons (NULL_TREE
, TYPE_DOMAIN (sizetype
), endlink
);
2920 /* We realloc here because sizetype could be int or unsigned. S'ok. */
2921 ptr_ftype_sizetype
= build_function_type (ptr_type_node
, sizetype_endlink
);
2923 int_ftype_any
= build_function_type (integer_type_node
, NULL_TREE
);
2924 void_ftype_any
= build_function_type (void_type_node
, NULL_TREE
);
2925 void_ftype
= build_function_type (void_type_node
, endlink
);
2926 void_ftype_int
= build_function_type (void_type_node
, int_endlink
);
2928 = build_function_type (void_type_node
,
2929 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
2932 = build_function_type (float_type_node
,
2933 tree_cons (NULL_TREE
, float_type_node
, endlink
));
2936 = build_function_type (double_type_node
, double_endlink
);
2938 ldouble_ftype_ldouble
2939 = build_function_type (long_double_type_node
,
2940 tree_cons (NULL_TREE
, long_double_type_node
,
2943 double_ftype_double_double
2944 = build_function_type (double_type_node
,
2945 tree_cons (NULL_TREE
, double_type_node
,
2949 = build_function_type (complex_float_type_node
,
2950 tree_cons (NULL_TREE
, complex_float_type_node
,
2952 cdouble_ftype_cdouble
2953 = build_function_type (complex_double_type_node
,
2954 tree_cons (NULL_TREE
, complex_double_type_node
,
2956 cldouble_ftype_cldouble
2957 = build_function_type (complex_long_double_type_node
,
2958 tree_cons (NULL_TREE
, complex_long_double_type_node
,
2962 = build_function_type (float_type_node
,
2963 tree_cons (NULL_TREE
, complex_float_type_node
,
2965 double_ftype_cdouble
2966 = build_function_type (double_type_node
,
2967 tree_cons (NULL_TREE
, complex_double_type_node
,
2969 ldouble_ftype_cldouble
2970 = build_function_type (long_double_type_node
,
2971 tree_cons (NULL_TREE
, complex_long_double_type_node
,
2975 = build_function_type (integer_type_node
, int_endlink
);
2978 = build_function_type (long_integer_type_node
,
2979 tree_cons (NULL_TREE
, long_integer_type_node
,
2982 longlong_ftype_longlong
2983 = build_function_type (long_long_integer_type_node
,
2984 tree_cons (NULL_TREE
, long_long_integer_type_node
,
2988 = build_function_type (intmax_type_node
,
2989 tree_cons (NULL_TREE
, intmax_type_node
,
2992 int_ftype_cptr_cptr_sizet
2993 = build_function_type (integer_type_node
,
2994 tree_cons (NULL_TREE
, const_ptr_type_node
,
2995 tree_cons (NULL_TREE
,
2996 const_ptr_type_node
,
2997 sizetype_endlink
)));
2999 void_zero_node
= build_int_2 (0, 0);
3000 TREE_TYPE (void_zero_node
) = void_type_node
;
3002 /* Prototype for strcpy/strcat. */
3003 string_ftype_string_cstring
3004 = build_function_type (string_type_node
,
3005 tree_cons (NULL_TREE
, string_type_node
,
3008 /* Prototype for strncpy/strncat. */
3009 string_ftype_string_cstring_sizet
3010 = build_function_type (string_type_node
,
3011 tree_cons (NULL_TREE
, string_type_node
,
3012 tree_cons (NULL_TREE
,
3013 const_string_type_node
,
3014 sizetype_endlink
)));
3016 traditional_len_type_node
= ((flag_traditional
&&
3017 c_language
!= clk_cplusplus
)
3018 ? integer_type_node
: sizetype
);
3019 traditional_len_endlink
= tree_cons (NULL_TREE
, traditional_len_type_node
,
3022 /* Prototype for strcmp. */
3023 int_ftype_cstring_cstring
3024 = build_function_type (integer_type_node
,
3025 tree_cons (NULL_TREE
, const_string_type_node
,
3028 /* Prototype for strspn/strcspn. */
3029 sizet_ftype_cstring_cstring
3030 = build_function_type (c_size_type_node
,
3031 tree_cons (NULL_TREE
, const_string_type_node
,
3034 /* Prototype for strncmp. */
3035 int_ftype_cstring_cstring_sizet
3036 = build_function_type (integer_type_node
,
3037 tree_cons (NULL_TREE
, const_string_type_node
,
3038 tree_cons (NULL_TREE
,
3039 const_string_type_node
,
3040 sizetype_endlink
)));
3042 /* Prototype for strstr, strpbrk, etc. */
3043 string_ftype_cstring_cstring
3044 = build_function_type (string_type_node
,
3045 tree_cons (NULL_TREE
, const_string_type_node
,
3048 /* Prototype for strchr. */
3049 string_ftype_cstring_int
3050 = build_function_type (string_type_node
,
3051 tree_cons (NULL_TREE
, const_string_type_node
,
3054 /* Prototype for strlen. */
3056 = build_function_type (traditional_len_type_node
, cstring_endlink
);
3058 traditional_ptr_type_node
= ((flag_traditional
&&
3059 c_language
!= clk_cplusplus
)
3060 ? string_type_node
: ptr_type_node
);
3061 traditional_cptr_type_node
= ((flag_traditional
&&
3062 c_language
!= clk_cplusplus
)
3063 ? const_string_type_node
: const_ptr_type_node
);
3065 /* Prototype for memcpy. */
3067 = build_function_type (traditional_ptr_type_node
,
3068 tree_cons (NULL_TREE
, ptr_type_node
,
3069 tree_cons (NULL_TREE
, const_ptr_type_node
,
3070 sizetype_endlink
)));
3072 /* Prototype for memset. */
3074 = build_function_type (traditional_ptr_type_node
,
3075 tree_cons (NULL_TREE
, ptr_type_node
,
3076 tree_cons (NULL_TREE
, integer_type_node
,
3077 sizetype_endlink
)));
3079 /* Prototype for bzero. */
3081 = build_function_type (void_type_node
,
3082 tree_cons (NULL_TREE
, traditional_ptr_type_node
,
3083 traditional_len_endlink
));
3085 /* Prototype for bcmp. */
3087 = build_function_type (integer_type_node
,
3088 tree_cons (NULL_TREE
, traditional_cptr_type_node
,
3089 tree_cons (NULL_TREE
,
3090 traditional_cptr_type_node
,
3091 traditional_len_endlink
)));
3093 /* Prototype for puts. */
3095 = build_function_type (integer_type_node
, cstring_endlink
);
3097 /* Prototype for printf. */
3099 = build_function_type (integer_type_node
,
3100 tree_cons (NULL_TREE
, const_string_type_node
,
3103 /* These stdio prototypes are declared using void* in place of
3104 FILE*. They are only used for __builtin_ style calls, regular
3105 style builtin prototypes omit the arguments and merge those
3106 provided by stdio.h. */
3107 /* Prototype for fwrite. */
3109 = build_function_type (c_size_type_node
,
3110 tree_cons (NULL_TREE
, const_ptr_type_node
,
3111 tree_cons (NULL_TREE
, c_size_type_node
,
3112 tree_cons (NULL_TREE
, c_size_type_node
,
3113 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)))));
3115 /* Prototype for fputc. */
3117 = build_function_type (integer_type_node
,
3118 tree_cons (NULL_TREE
, integer_type_node
,
3119 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
3121 /* Prototype for fputs. */
3123 = build_function_type (integer_type_node
,
3124 tree_cons (NULL_TREE
, const_string_type_node
,
3125 tree_cons (NULL_TREE
, ptr_type_node
, endlink
)));
3127 /* Prototype for fprintf. */
3129 = build_function_type (integer_type_node
,
3130 tree_cons (NULL_TREE
, ptr_type_node
,
3131 tree_cons (NULL_TREE
,
3132 const_string_type_node
,
3135 builtin_function ("__builtin_constant_p", default_function_type
,
3136 BUILT_IN_CONSTANT_P
, BUILT_IN_NORMAL
, NULL_PTR
);
3138 builtin_function ("__builtin_return_address", ptr_ftype_unsigned
,
3139 BUILT_IN_RETURN_ADDRESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3141 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned
,
3142 BUILT_IN_FRAME_ADDRESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3144 #ifdef EH_RETURN_DATA_REGNO
3145 builtin_function ("__builtin_eh_return_data_regno", int_ftype_int
,
3146 BUILT_IN_EH_RETURN_DATA_REGNO
, BUILT_IN_NORMAL
, NULL_PTR
);
3149 builtin_function ("__builtin_alloca", ptr_ftype_sizetype
,
3150 BUILT_IN_ALLOCA
, BUILT_IN_NORMAL
, "alloca");
3151 builtin_function_2 ("__builtin_ffs", "ffs",
3152 int_ftype_int
, int_ftype_int
,
3153 BUILT_IN_FFS
, BUILT_IN_NORMAL
, 0, 1, 0);
3154 /* Define alloca as builtin, unless SMALL_STACK. */
3156 builtin_function_2 (NULL_PTR
, "alloca", NULL_TREE
, ptr_ftype_sizetype
,
3157 BUILT_IN_ALLOCA
, BUILT_IN_NORMAL
, 0, 1, 0);
3159 /* Declare _exit and _Exit just to mark them as non-returning. */
3160 builtin_function_2 (NULL_PTR
, "_exit", NULL_TREE
, void_ftype_int
,
3161 0, NOT_BUILT_IN
, 0, 1, 1);
3162 builtin_function_2 (NULL_PTR
, "_Exit", NULL_TREE
, void_ftype_int
,
3163 0, NOT_BUILT_IN
, 0, !flag_isoc99
, 1);
3165 builtin_function_2 ("__builtin_index", "index",
3166 string_ftype_cstring_int
, string_ftype_cstring_int
,
3167 BUILT_IN_INDEX
, BUILT_IN_NORMAL
, 1, 1, 0);
3168 builtin_function_2 ("__builtin_rindex", "rindex",
3169 string_ftype_cstring_int
, string_ftype_cstring_int
,
3170 BUILT_IN_RINDEX
, BUILT_IN_NORMAL
, 1, 1, 0);
3172 /* The system prototypes for these functions have many
3173 variations, so don't specify parameters to avoid conflicts.
3174 The expand_* functions check the argument types anyway. */
3175 builtin_function_2 ("__builtin_bzero", "bzero",
3176 bzero_ftype
, void_ftype_any
,
3177 BUILT_IN_BZERO
, BUILT_IN_NORMAL
, 1, 1, 0);
3178 builtin_function_2 ("__builtin_bcmp", "bcmp",
3179 bcmp_ftype
, int_ftype_any
,
3180 BUILT_IN_BCMP
, BUILT_IN_NORMAL
, 1, 1, 0);
3182 builtin_function_2 ("__builtin_abs", "abs",
3183 int_ftype_int
, int_ftype_int
,
3184 BUILT_IN_ABS
, BUILT_IN_NORMAL
, 0, 0, 0);
3185 builtin_function_2 ("__builtin_fabsf", "fabsf",
3186 float_ftype_float
, float_ftype_float
,
3187 BUILT_IN_FABS
, BUILT_IN_NORMAL
, 0, 0, 0);
3188 builtin_function_2 ("__builtin_fabs", "fabs",
3189 double_ftype_double
, double_ftype_double
,
3190 BUILT_IN_FABS
, BUILT_IN_NORMAL
, 0, 0, 0);
3191 builtin_function_2 ("__builtin_fabsl", "fabsl",
3192 ldouble_ftype_ldouble
, ldouble_ftype_ldouble
,
3193 BUILT_IN_FABS
, BUILT_IN_NORMAL
, 0, 0, 0);
3194 builtin_function_2 ("__builtin_labs", "labs",
3195 long_ftype_long
, long_ftype_long
,
3196 BUILT_IN_ABS
, BUILT_IN_NORMAL
, 0, 0, 0);
3197 builtin_function_2 ("__builtin_llabs", "llabs",
3198 longlong_ftype_longlong
, longlong_ftype_longlong
,
3199 BUILT_IN_ABS
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3200 builtin_function_2 ("__builtin_imaxabs", "imaxabs",
3201 intmax_ftype_intmax
, intmax_ftype_intmax
,
3202 BUILT_IN_ABS
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3204 builtin_function ("__builtin_saveregs", ptr_ftype
, BUILT_IN_SAVEREGS
,
3205 BUILT_IN_NORMAL
, NULL_PTR
);
3206 builtin_function ("__builtin_classify_type", default_function_type
,
3207 BUILT_IN_CLASSIFY_TYPE
, BUILT_IN_NORMAL
, NULL_PTR
);
3208 builtin_function ("__builtin_next_arg", ptr_ftype
, BUILT_IN_NEXT_ARG
,
3209 BUILT_IN_NORMAL
, NULL_PTR
);
3210 builtin_function ("__builtin_args_info", int_ftype_int
, BUILT_IN_ARGS_INFO
,
3211 BUILT_IN_NORMAL
, NULL_PTR
);
3212 builtin_function ("__builtin_setjmp",
3213 build_function_type (integer_type_node
,
3214 tree_cons (NULL_TREE
, ptr_type_node
,
3216 BUILT_IN_SETJMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3217 builtin_function ("__builtin_longjmp",
3218 build_function_type (void_type_node
,
3219 tree_cons (NULL_TREE
, ptr_type_node
,
3221 BUILT_IN_LONGJMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3222 builtin_function ("__builtin_trap", void_ftype
, BUILT_IN_TRAP
,
3223 BUILT_IN_NORMAL
, NULL_PTR
);
3225 /* ISO C99 IEEE Unordered compares. */
3226 builtin_function ("__builtin_isgreater", default_function_type
,
3227 BUILT_IN_ISGREATER
, BUILT_IN_NORMAL
, NULL_PTR
);
3228 builtin_function ("__builtin_isgreaterequal", default_function_type
,
3229 BUILT_IN_ISGREATEREQUAL
, BUILT_IN_NORMAL
, NULL_PTR
);
3230 builtin_function ("__builtin_isless", default_function_type
,
3231 BUILT_IN_ISLESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3232 builtin_function ("__builtin_islessequal", default_function_type
,
3233 BUILT_IN_ISLESSEQUAL
, BUILT_IN_NORMAL
, NULL_PTR
);
3234 builtin_function ("__builtin_islessgreater", default_function_type
,
3235 BUILT_IN_ISLESSGREATER
, BUILT_IN_NORMAL
, NULL_PTR
);
3236 builtin_function ("__builtin_isunordered", default_function_type
,
3237 BUILT_IN_ISUNORDERED
, BUILT_IN_NORMAL
, NULL_PTR
);
3239 /* Untyped call and return. */
3240 builtin_function ("__builtin_apply_args", ptr_ftype
,
3241 BUILT_IN_APPLY_ARGS
, BUILT_IN_NORMAL
, NULL_PTR
);
3243 temp
= tree_cons (NULL_TREE
,
3244 build_pointer_type (build_function_type (void_type_node
,
3246 tree_cons (NULL_TREE
, ptr_type_node
, sizetype_endlink
));
3247 builtin_function ("__builtin_apply",
3248 build_function_type (ptr_type_node
, temp
),
3249 BUILT_IN_APPLY
, BUILT_IN_NORMAL
, NULL_PTR
);
3250 builtin_function ("__builtin_return", void_ftype_ptr
,
3251 BUILT_IN_RETURN
, BUILT_IN_NORMAL
, NULL_PTR
);
3253 /* Support for varargs.h and stdarg.h. */
3254 builtin_function ("__builtin_varargs_start",
3255 build_function_type (void_type_node
,
3256 tree_cons (NULL_TREE
,
3257 va_list_ref_type_node
,
3259 BUILT_IN_VARARGS_START
, BUILT_IN_NORMAL
, NULL_PTR
);
3261 builtin_function ("__builtin_stdarg_start",
3262 build_function_type (void_type_node
,
3263 tree_cons (NULL_TREE
,
3264 va_list_ref_type_node
,
3266 BUILT_IN_STDARG_START
, BUILT_IN_NORMAL
, NULL_PTR
);
3268 builtin_function ("__builtin_va_end",
3269 build_function_type (void_type_node
,
3270 tree_cons (NULL_TREE
,
3271 va_list_ref_type_node
,
3273 BUILT_IN_VA_END
, BUILT_IN_NORMAL
, NULL_PTR
);
3275 builtin_function ("__builtin_va_copy",
3276 build_function_type (void_type_node
,
3277 tree_cons (NULL_TREE
,
3278 va_list_ref_type_node
,
3279 tree_cons (NULL_TREE
,
3280 va_list_arg_type_node
,
3282 BUILT_IN_VA_COPY
, BUILT_IN_NORMAL
, NULL_PTR
);
3284 /* ??? Ought to be `T __builtin_expect(T, T)' for any type T. */
3285 builtin_function ("__builtin_expect",
3286 build_function_type (long_integer_type_node
,
3287 tree_cons (NULL_TREE
,
3288 long_integer_type_node
,
3289 tree_cons (NULL_TREE
,
3290 long_integer_type_node
,
3292 BUILT_IN_EXPECT
, BUILT_IN_NORMAL
, NULL_PTR
);
3294 /* Currently under experimentation. */
3295 builtin_function_2 ("__builtin_memcpy", "memcpy",
3296 memcpy_ftype
, memcpy_ftype
,
3297 BUILT_IN_MEMCPY
, BUILT_IN_NORMAL
, 1, 0, 0);
3298 builtin_function_2 ("__builtin_memcmp", "memcmp",
3299 int_ftype_cptr_cptr_sizet
, int_ftype_cptr_cptr_sizet
,
3300 BUILT_IN_MEMCMP
, BUILT_IN_NORMAL
, 1, 0, 0);
3301 builtin_function_2 ("__builtin_memset", "memset",
3302 memset_ftype
, memset_ftype
,
3303 BUILT_IN_MEMSET
, BUILT_IN_NORMAL
, 1, 0, 0);
3304 built_in_decls
[BUILT_IN_STRCMP
] =
3305 builtin_function_2 ("__builtin_strcmp", "strcmp",
3306 int_ftype_cstring_cstring
, int_ftype_cstring_cstring
,
3307 BUILT_IN_STRCMP
, BUILT_IN_NORMAL
, 1, 0, 0);
3308 builtin_function_2 ("__builtin_strncmp", "strncmp",
3309 int_ftype_cstring_cstring_sizet
,
3310 int_ftype_cstring_cstring_sizet
,
3311 BUILT_IN_STRNCMP
, BUILT_IN_NORMAL
, 1, 0, 0);
3312 builtin_function_2 ("__builtin_strstr", "strstr",
3313 string_ftype_cstring_cstring
, string_ftype_cstring_cstring
,
3314 BUILT_IN_STRSTR
, BUILT_IN_NORMAL
, 1, 0, 0);
3315 builtin_function_2 ("__builtin_strpbrk", "strpbrk",
3316 string_ftype_cstring_cstring
, string_ftype_cstring_cstring
,
3317 BUILT_IN_STRPBRK
, BUILT_IN_NORMAL
, 1, 0, 0);
3318 built_in_decls
[BUILT_IN_STRCHR
] =
3319 builtin_function_2 ("__builtin_strchr", "strchr",
3320 string_ftype_cstring_int
, string_ftype_cstring_int
,
3321 BUILT_IN_STRCHR
, BUILT_IN_NORMAL
, 1, 0, 0);
3322 builtin_function_2 ("__builtin_strrchr", "strrchr",
3323 string_ftype_cstring_int
, string_ftype_cstring_int
,
3324 BUILT_IN_STRRCHR
, BUILT_IN_NORMAL
, 1, 0, 0);
3325 builtin_function_2 ("__builtin_strcpy", "strcpy",
3326 string_ftype_string_cstring
, string_ftype_string_cstring
,
3327 BUILT_IN_STRCPY
, BUILT_IN_NORMAL
, 1, 0, 0);
3328 builtin_function_2 ("__builtin_strncpy", "strncpy",
3329 string_ftype_string_cstring_sizet
,
3330 string_ftype_string_cstring_sizet
,
3331 BUILT_IN_STRNCPY
, BUILT_IN_NORMAL
, 1, 0, 0);
3332 built_in_decls
[BUILT_IN_STRCAT
] =
3333 builtin_function_2 ("__builtin_strcat", "strcat",
3334 string_ftype_string_cstring
,
3335 string_ftype_string_cstring
,
3336 BUILT_IN_STRCAT
, BUILT_IN_NORMAL
, 1, 0, 0);
3337 builtin_function_2 ("__builtin_strncat", "strncat",
3338 string_ftype_string_cstring_sizet
,
3339 string_ftype_string_cstring_sizet
,
3340 BUILT_IN_STRNCAT
, BUILT_IN_NORMAL
, 1, 0, 0);
3341 builtin_function_2 ("__builtin_strspn", "strspn",
3342 sizet_ftype_cstring_cstring
, sizet_ftype_cstring_cstring
,
3343 BUILT_IN_STRSPN
, BUILT_IN_NORMAL
, 1, 0, 0);
3344 builtin_function_2 ("__builtin_strcspn", "strcspn",
3345 sizet_ftype_cstring_cstring
, sizet_ftype_cstring_cstring
,
3346 BUILT_IN_STRCSPN
, BUILT_IN_NORMAL
, 1, 0, 0);
3347 built_in_decls
[BUILT_IN_STRLEN
] =
3348 builtin_function_2 ("__builtin_strlen", "strlen",
3349 strlen_ftype
, strlen_ftype
,
3350 BUILT_IN_STRLEN
, BUILT_IN_NORMAL
, 1, 0, 0);
3352 builtin_function_2 ("__builtin_sqrtf", "sqrtf",
3353 float_ftype_float
, float_ftype_float
,
3354 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, 1, 0, 0);
3355 builtin_function_2 ("__builtin_sqrt", "sqrt",
3356 double_ftype_double
, double_ftype_double
,
3357 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, 1, 0, 0);
3358 builtin_function_2 ("__builtin_sqrtl", "sqrtl",
3359 ldouble_ftype_ldouble
, ldouble_ftype_ldouble
,
3360 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, 1, 0, 0);
3361 builtin_function_2 ("__builtin_sinf", "sinf",
3362 float_ftype_float
, float_ftype_float
,
3363 BUILT_IN_SIN
, BUILT_IN_NORMAL
, 1, 0, 0);
3364 builtin_function_2 ("__builtin_sin", "sin",
3365 double_ftype_double
, double_ftype_double
,
3366 BUILT_IN_SIN
, BUILT_IN_NORMAL
, 1, 0, 0);
3367 builtin_function_2 ("__builtin_sinl", "sinl",
3368 ldouble_ftype_ldouble
, ldouble_ftype_ldouble
,
3369 BUILT_IN_SIN
, BUILT_IN_NORMAL
, 1, 0, 0);
3370 builtin_function_2 ("__builtin_cosf", "cosf",
3371 float_ftype_float
, float_ftype_float
,
3372 BUILT_IN_COS
, BUILT_IN_NORMAL
, 1, 0, 0);
3373 builtin_function_2 ("__builtin_cos", "cos",
3374 double_ftype_double
, double_ftype_double
,
3375 BUILT_IN_COS
, BUILT_IN_NORMAL
, 1, 0, 0);
3376 builtin_function_2 ("__builtin_cosl", "cosl",
3377 ldouble_ftype_ldouble
, ldouble_ftype_ldouble
,
3378 BUILT_IN_COS
, BUILT_IN_NORMAL
, 1, 0, 0);
3380 /* ISO C99 complex arithmetic functions. */
3381 builtin_function_2 ("__builtin_conjf", "conjf",
3382 cfloat_ftype_cfloat
, cfloat_ftype_cfloat
,
3383 BUILT_IN_CONJ
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3384 builtin_function_2 ("__builtin_conj", "conj",
3385 cdouble_ftype_cdouble
, cdouble_ftype_cdouble
,
3386 BUILT_IN_CONJ
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3387 builtin_function_2 ("__builtin_conjl", "conjl",
3388 cldouble_ftype_cldouble
, cldouble_ftype_cldouble
,
3389 BUILT_IN_CONJ
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3390 builtin_function_2 ("__builtin_crealf", "crealf",
3391 float_ftype_cfloat
, float_ftype_cfloat
,
3392 BUILT_IN_CREAL
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3393 builtin_function_2 ("__builtin_creal", "creal",
3394 double_ftype_cdouble
, double_ftype_cdouble
,
3395 BUILT_IN_CREAL
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3396 builtin_function_2 ("__builtin_creall", "creall",
3397 ldouble_ftype_cldouble
, ldouble_ftype_cldouble
,
3398 BUILT_IN_CREAL
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3399 builtin_function_2 ("__builtin_cimagf", "cimagf",
3400 float_ftype_cfloat
, float_ftype_cfloat
,
3401 BUILT_IN_CIMAG
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3402 builtin_function_2 ("__builtin_cimag", "cimag",
3403 double_ftype_cdouble
, double_ftype_cdouble
,
3404 BUILT_IN_CIMAG
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3405 builtin_function_2 ("__builtin_cimagl", "cimagl",
3406 ldouble_ftype_cldouble
, ldouble_ftype_cldouble
,
3407 BUILT_IN_CIMAG
, BUILT_IN_NORMAL
, 0, !flag_isoc99
, 0);
3409 built_in_decls
[BUILT_IN_PUTCHAR
] =
3410 builtin_function ("__builtin_putchar", int_ftype_int
,
3411 BUILT_IN_PUTCHAR
, BUILT_IN_NORMAL
, "putchar");
3412 built_in_decls
[BUILT_IN_PUTS
] =
3413 builtin_function ("__builtin_puts", puts_ftype
,
3414 BUILT_IN_PUTS
, BUILT_IN_NORMAL
, "puts");
3415 builtin_function_2 ("__builtin_printf", "printf",
3416 printf_ftype
, printf_ftype
,
3417 BUILT_IN_PRINTF
, BUILT_IN_FRONTEND
, 1, 0, 0);
3418 builtin_function_2 ("__builtin_fprintf", "fprintf",
3419 fprintf_ftype
, fprintf_ftype
,
3420 BUILT_IN_FPRINTF
, BUILT_IN_FRONTEND
, 1, 0, 0);
3421 built_in_decls
[BUILT_IN_FWRITE
] =
3422 builtin_function ("__builtin_fwrite", fwrite_ftype
,
3423 BUILT_IN_FWRITE
, BUILT_IN_NORMAL
, "fwrite");
3424 built_in_decls
[BUILT_IN_FPUTC
] =
3425 builtin_function ("__builtin_fputc", fputc_ftype
,
3426 BUILT_IN_FPUTC
, BUILT_IN_NORMAL
, "fputc");
3427 /* Declare the __builtin_ style with arguments and the regular style
3428 without them. We rely on stdio.h to supply the arguments for the
3429 regular style declaration since we had to use void* instead of
3430 FILE* in the __builtin_ prototype supplied here. */
3431 built_in_decls
[BUILT_IN_FPUTS
] =
3432 builtin_function_2 ("__builtin_fputs", "fputs",
3433 fputs_ftype
, int_ftype_any
,
3434 BUILT_IN_FPUTS
, BUILT_IN_NORMAL
, 1, 0, 0);
3436 /* Declare these functions non-returning
3437 to avoid spurious "control drops through" warnings. */
3438 builtin_function_2 (NULL_PTR
, "abort",
3439 NULL_TREE
, ((c_language
== clk_cplusplus
)
3440 ? void_ftype
: void_ftype_any
),
3441 0, NOT_BUILT_IN
, 0, 0, 1);
3443 builtin_function_2 (NULL_PTR
, "exit",
3444 NULL_TREE
, ((c_language
== clk_cplusplus
)
3445 ? void_ftype_int
: void_ftype_any
),
3446 0, NOT_BUILT_IN
, 0, 0, 1);
3449 /* Support for these has not been written in either expand_builtin
3450 or build_function_call. */
3451 builtin_function ("__builtin_div", default_ftype
, BUILT_IN_DIV
,
3452 BUILT_IN_NORMAL
, NULL_PTR
);
3453 builtin_function ("__builtin_ldiv", default_ftype
, BUILT_IN_LDIV
,
3454 BUILT_IN_NORMAL
, NULL_PTR
);
3455 builtin_function ("__builtin_ffloor", double_ftype_double
, BUILT_IN_FFLOOR
,
3456 BUILT_IN_NORMAL
, NULL_PTR
);
3457 builtin_function ("__builtin_fceil", double_ftype_double
, BUILT_IN_FCEIL
,
3458 BUILT_IN_NORMAL
, NULL_PTR
);
3459 builtin_function ("__builtin_fmod", double_ftype_double_double
,
3460 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, NULL_PTR
);
3461 builtin_function ("__builtin_frem", double_ftype_double_double
,
3462 BUILT_IN_FREM
, BUILT_IN_NORMAL
, NULL_PTR
);
3463 builtin_function ("__builtin_getexp", double_ftype_double
, BUILT_IN_GETEXP
,
3464 BUILT_IN_NORMAL
, NULL_PTR
);
3465 builtin_function ("__builtin_getman", double_ftype_double
, BUILT_IN_GETMAN
,
3466 BUILT_IN_NORMAL
, NULL_PTR
);
3469 main_identifier_node
= get_identifier ("main");
3471 /* ??? Perhaps there's a better place to do this. But it is related
3472 to __builtin_va_arg, so it isn't that off-the-wall. */
3473 lang_type_promotes_to
= simple_type_promotes_to
;
3477 build_va_arg (expr
, type
)
3480 return build1 (VA_ARG_EXPR
, type
, expr
);
3484 /* Possibly define a builtin function with one or two names. BUILTIN_NAME
3485 is an __builtin_-prefixed name; NAME is the ordinary name; one or both
3486 of these may be NULL (though both being NULL is useless).
3487 BUILTIN_TYPE is the type of the __builtin_-prefixed function;
3488 TYPE is the type of the function with the ordinary name. These
3489 may differ if the ordinary name is declared with a looser type to avoid
3490 conflicts with headers. FUNCTION_CODE and CLASS are as for
3491 builtin_function. If LIBRARY_NAME_P is nonzero, NAME is passed as
3492 the LIBRARY_NAME parameter to builtin_function when declaring BUILTIN_NAME.
3493 If NONANSI_P is nonzero, the name NAME is treated as a non-ANSI name; if
3494 NORETURN_P is nonzero, the function is marked as non-returning.
3495 Returns the declaration of BUILTIN_NAME, if any, otherwise
3496 the declaration of NAME. Does not declare NAME if flag_no_builtin,
3497 or if NONANSI_P and flag_no_nonansi_builtin. */
3500 builtin_function_2 (builtin_name
, name
, builtin_type
, type
, function_code
,
3501 class, library_name_p
, nonansi_p
, noreturn_p
)
3502 const char *builtin_name
;
3507 enum built_in_class
class;
3512 tree bdecl
= NULL_TREE
;
3513 tree decl
= NULL_TREE
;
3514 if (builtin_name
!= 0)
3516 bdecl
= builtin_function (builtin_name
, builtin_type
, function_code
,
3517 class, library_name_p
? name
: NULL_PTR
);
3520 TREE_THIS_VOLATILE (bdecl
) = 1;
3521 TREE_SIDE_EFFECTS (bdecl
) = 1;
3524 if (name
!= 0 && !flag_no_builtin
&& !(nonansi_p
&& flag_no_nonansi_builtin
))
3526 decl
= builtin_function (name
, type
, function_code
, class, NULL_PTR
);
3528 DECL_BUILT_IN_NONANSI (decl
) = 1;
3531 TREE_THIS_VOLATILE (decl
) = 1;
3532 TREE_SIDE_EFFECTS (decl
) = 1;
3535 return (bdecl
!= 0 ? bdecl
: decl
);
3538 /* Nonzero if the type T promotes to int. This is (nearly) the
3539 integral promotions defined in ISO C99 6.3.1.1/2. */
3542 c_promoting_integer_type_p (t
)
3545 switch (TREE_CODE (t
))
3548 return (TYPE_MAIN_VARIANT (t
) == char_type_node
3549 || TYPE_MAIN_VARIANT (t
) == signed_char_type_node
3550 || TYPE_MAIN_VARIANT (t
) == unsigned_char_type_node
3551 || TYPE_MAIN_VARIANT (t
) == short_integer_type_node
3552 || TYPE_MAIN_VARIANT (t
) == short_unsigned_type_node
);
3555 /* ??? Technically all enumerations not larger than an int
3556 promote to an int. But this is used along code paths
3557 that only want to notice a size change. */
3558 return TYPE_PRECISION (t
) < TYPE_PRECISION (integer_type_node
);
3568 /* Given a type, apply default promotions wrt unnamed function arguments
3569 and return the new type. Return NULL_TREE if no change. */
3570 /* ??? There is a function of the same name in the C++ front end that
3571 does something similar, but is more thorough and does not return NULL
3572 if no change. We could perhaps share code, but it would make the
3573 self_promoting_type property harder to identify. */
3576 simple_type_promotes_to (type
)
3579 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3580 return double_type_node
;
3582 if (c_promoting_integer_type_p (type
))
3584 /* Traditionally, unsignedness is preserved in default promotions.
3585 Also preserve unsignedness if not really getting any wider. */
3586 if (TREE_UNSIGNED (type
)
3587 && (flag_traditional
3588 || TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
3589 return unsigned_type_node
;
3590 return integer_type_node
;
3596 /* Return 1 if PARMS specifies a fixed number of parameters
3597 and none of their types is affected by default promotions. */
3600 self_promoting_args_p (parms
)
3604 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
3606 register tree type
= TREE_VALUE (t
);
3608 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
3614 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3617 if (c_promoting_integer_type_p (type
))
3623 /* Recursively examines the array elements of TYPE, until a non-array
3624 element type is found. */
3627 strip_array_types (type
)
3630 while (TREE_CODE (type
) == ARRAY_TYPE
)
3631 type
= TREE_TYPE (type
);
3636 /* Recognize certain built-in functions so we can make tree-codes
3637 other than CALL_EXPR. We do this when it enables fold-const.c
3638 to do something useful. */
3639 /* ??? By rights this should go in builtins.c, but only C and C++
3640 implement build_{binary,unary}_op. Not exactly sure what bits
3641 of functionality are actually needed from those functions, or
3642 where the similar functionality exists in the other front ends. */
3645 expand_tree_builtin (function
, params
, coerced_params
)
3646 tree function
, params
, coerced_params
;
3648 enum tree_code code
;
3650 if (DECL_BUILT_IN_CLASS (function
) != BUILT_IN_NORMAL
)
3653 switch (DECL_FUNCTION_CODE (function
))
3657 if (coerced_params
== 0)
3658 return integer_zero_node
;
3659 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
3662 if (coerced_params
== 0)
3663 return integer_zero_node
;
3664 return build_unary_op (CONJ_EXPR
, TREE_VALUE (coerced_params
), 0);
3666 case BUILT_IN_CREAL
:
3667 if (coerced_params
== 0)
3668 return integer_zero_node
;
3669 return build_unary_op (REALPART_EXPR
, TREE_VALUE (coerced_params
), 0);
3671 case BUILT_IN_CIMAG
:
3672 if (coerced_params
== 0)
3673 return integer_zero_node
;
3674 return build_unary_op (IMAGPART_EXPR
, TREE_VALUE (coerced_params
), 0);
3676 case BUILT_IN_ISGREATER
:
3677 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3683 case BUILT_IN_ISGREATEREQUAL
:
3684 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3690 case BUILT_IN_ISLESS
:
3691 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3697 case BUILT_IN_ISLESSEQUAL
:
3698 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3704 case BUILT_IN_ISLESSGREATER
:
3705 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3711 case BUILT_IN_ISUNORDERED
:
3712 if (TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
)
3713 return integer_zero_node
;
3714 code
= UNORDERED_EXPR
;
3722 || TREE_CHAIN (params
) == 0)
3724 error ("too few arguments to function `%s'",
3725 IDENTIFIER_POINTER (DECL_NAME (function
)));
3726 return error_mark_node
;
3728 else if (TREE_CHAIN (TREE_CHAIN (params
)) != 0)
3730 error ("too many arguments to function `%s'",
3731 IDENTIFIER_POINTER (DECL_NAME (function
)));
3732 return error_mark_node
;
3735 arg0
= TREE_VALUE (params
);
3736 arg1
= TREE_VALUE (TREE_CHAIN (params
));
3737 arg0
= build_binary_op (code
, arg0
, arg1
, 0);
3738 if (code
!= UNORDERED_EXPR
)
3739 arg0
= build_unary_op (TRUTH_NOT_EXPR
, arg0
, 0);
3751 /* Returns non-zero if CODE is the code for a statement. */
3754 statement_code_p (code
)
3755 enum tree_code code
;
3778 if (lang_statement_code_p
)
3779 return (*lang_statement_code_p
) (code
);
3784 /* Walk the statemen tree, rooted at *tp. Apply FUNC to all the
3785 sub-trees of *TP in a pre-order traversal. FUNC is called with the
3786 DATA and the address of each sub-tree. If FUNC returns a non-NULL
3787 value, the traversal is aborted, and the value returned by FUNC is
3788 returned. If FUNC sets WALK_SUBTREES to zero, then the subtrees of
3789 the node being visited are not walked.
3791 We don't need a without_duplicates variant of this one because the
3792 statement tree is a tree, not a graph. */
3795 walk_stmt_tree (tp
, func
, data
)
3800 enum tree_code code
;
3805 #define WALK_SUBTREE(NODE) \
3808 result = walk_stmt_tree (&(NODE), func, data); \
3814 /* Skip empty subtrees. */
3818 /* Skip subtrees below non-statement nodes. */
3819 if (!statement_code_p (TREE_CODE (*tp
)))
3822 /* Call the function. */
3824 result
= (*func
) (tp
, &walk_subtrees
, data
);
3826 /* If we found something, return it. */
3830 /* Even if we didn't, FUNC may have decided that there was nothing
3831 interesting below this point in the tree. */
3835 /* FUNC may have modified the tree, recheck that we're looking at a
3837 code
= TREE_CODE (*tp
);
3838 if (!statement_code_p (code
))
3841 /* Walk over all the sub-trees of this operand. Statement nodes never
3842 contain RTL, and we needn't worry about TARGET_EXPRs. */
3843 len
= TREE_CODE_LENGTH (code
);
3845 /* Go through the subtrees. We need to do this in forward order so
3846 that the scope of a FOR_EXPR is handled properly. */
3847 for (i
= 0; i
< len
; ++i
)
3848 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
3850 /* Finally visit the chain. This can be tail-recursion optimized if
3851 we write it this way. */
3852 return walk_stmt_tree (&TREE_CHAIN (*tp
), func
, data
);
3857 /* Used to compare case labels. K1 and K2 are actually tree nodes
3858 representing case labels, or NULL_TREE for a `default' label.
3859 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
3860 K2, and 0 if K1 and K2 are equal. */
3863 case_compare (k1
, k2
)
3867 /* Consider a NULL key (such as arises with a `default' label) to be
3868 smaller than anything else. */
3874 return tree_int_cst_compare ((tree
) k1
, (tree
) k2
);
3877 /* Process a case label for the range LOW_VALUE ... HIGH_VALUE. If
3878 LOW_VALUE and HIGH_VALUE are both NULL_TREE then this case label is
3879 actually a `default' label. If only HIGH_VALUE is NULL_TREE, then
3880 case label was declared using the usual C/C++ syntax, rather than
3881 the GNU case range extension. CASES is a tree containing all the
3882 case ranges processed so far; COND is the condition for the
3883 switch-statement itself. Returns the CASE_LABEL created, or
3884 ERROR_MARK_NODE if no CASE_LABEL is created. */
3887 c_add_case_label (cases
, cond
, low_value
, high_value
)
3896 splay_tree_node node
;
3898 /* Create the LABEL_DECL itself. */
3899 label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
3900 DECL_CONTEXT (label
) = current_function_decl
;
3902 /* If there was an error processing the switch condition, bail now
3903 before we get more confused. */
3904 if (!cond
|| cond
== error_mark_node
)
3906 /* Add a label anyhow so that the back-end doesn't think that
3907 the beginning of the switch is unreachable. */
3909 add_stmt (build_case_label (NULL_TREE
, NULL_TREE
, label
));
3910 return error_mark_node
;
3913 if ((low_value
&& TREE_TYPE (low_value
)
3914 && POINTER_TYPE_P (TREE_TYPE (low_value
)))
3915 || (high_value
&& TREE_TYPE (high_value
)
3916 && POINTER_TYPE_P (TREE_TYPE (high_value
))))
3917 error ("pointers are not permitted as case values");
3919 /* Case ranges are a GNU extension. */
3920 if (high_value
&& pedantic
)
3922 if (c_language
== clk_cplusplus
)
3923 pedwarn ("ISO C++ forbids range expressions in switch statements");
3925 pedwarn ("ISO C forbids range expressions in switch statements");
3928 type
= TREE_TYPE (cond
);
3931 low_value
= check_case_value (low_value
);
3932 low_value
= convert_and_check (type
, low_value
);
3936 high_value
= check_case_value (high_value
);
3937 high_value
= convert_and_check (type
, high_value
);
3940 /* If an error has occurred, bail out now. */
3941 if (low_value
== error_mark_node
|| high_value
== error_mark_node
)
3944 add_stmt (build_case_label (NULL_TREE
, NULL_TREE
, label
));
3945 return error_mark_node
;
3948 /* If the LOW_VALUE and HIGH_VALUE are the same, then this isn't
3949 really a case range, even though it was written that way. Remove
3950 the HIGH_VALUE to simplify later processing. */
3951 if (tree_int_cst_equal (low_value
, high_value
))
3952 high_value
= NULL_TREE
;
3953 if (low_value
&& high_value
3954 && !tree_int_cst_lt (low_value
, high_value
))
3955 warning ("empty range specified");
3957 /* Look up the LOW_VALUE in the table of case labels we already
3959 node
= splay_tree_lookup (cases
, (splay_tree_key
) low_value
);
3960 /* If there was not an exact match, check for overlapping ranges.
3961 There's no need to do this if there's no LOW_VALUE or HIGH_VALUE;
3962 that's a `default' label and the only overlap is an exact match. */
3963 if (!node
&& (low_value
|| high_value
))
3965 splay_tree_node low_bound
;
3966 splay_tree_node high_bound
;
3968 /* Even though there wasn't an exact match, there might be an
3969 overlap between this case range and another case range.
3970 Since we've (inductively) not allowed any overlapping case
3971 ranges, we simply need to find the greatest low case label
3972 that is smaller that LOW_VALUE, and the smallest low case
3973 label that is greater than LOW_VALUE. If there is an overlap
3974 it will occur in one of these two ranges. */
3975 low_bound
= splay_tree_predecessor (cases
,
3976 (splay_tree_key
) low_value
);
3977 high_bound
= splay_tree_successor (cases
,
3978 (splay_tree_key
) low_value
);
3980 /* Check to see if the LOW_BOUND overlaps. It is smaller than
3981 the LOW_VALUE, so there is no need to check unless the
3982 LOW_BOUND is in fact itself a case range. */
3984 && CASE_HIGH ((tree
) low_bound
->value
)
3985 && tree_int_cst_compare (CASE_HIGH ((tree
) low_bound
->value
),
3988 /* Check to see if the HIGH_BOUND overlaps. The low end of that
3989 range is bigger than the low end of the current range, so we
3990 are only interested if the current range is a real range, and
3991 not an ordinary case label. */
3994 && (tree_int_cst_compare ((tree
) high_bound
->key
,
3999 /* If there was an overlap, issue an error. */
4002 tree duplicate
= CASE_LABEL_DECL ((tree
) node
->value
);
4006 error ("duplicate (or overlapping) case value");
4007 error_with_decl (duplicate
,
4008 "this is the first entry overlapping that value");
4012 error ("duplicate case value") ;
4013 error_with_decl (duplicate
, "previously used here");
4017 error ("multiple default labels in one switch");
4018 error_with_decl (duplicate
, "this is the first default label");
4021 add_stmt (build_case_label (NULL_TREE
, NULL_TREE
, label
));
4024 /* Add a CASE_LABEL to the statement-tree. */
4025 case_label
= add_stmt (build_case_label (low_value
, high_value
, label
));
4026 /* Register this case label in the splay tree. */
4027 splay_tree_insert (cases
,
4028 (splay_tree_key
) low_value
,
4029 (splay_tree_value
) case_label
);
4034 /* Mark P (a stmt_tree) for GC. The use of a `void *' for the
4035 parameter allows this function to be used as a GC-marking
4042 stmt_tree st
= (stmt_tree
) p
;
4044 ggc_mark_tree (st
->x_last_stmt
);
4045 ggc_mark_tree (st
->x_last_expr_type
);
4048 /* Mark LD for GC. */
4051 c_mark_lang_decl (c
)
4052 struct c_lang_decl
*c
;
4054 ggc_mark_tree (c
->saved_tree
);
4057 /* Mark F for GC. */
4060 mark_c_language_function (f
)
4061 struct language_function
*f
;
4066 mark_stmt_tree (&f
->x_stmt_tree
);
4067 ggc_mark_tree (f
->x_scope_stmt_stack
);
4070 /* Hook used by expand_expr to expand language-specific tree codes. */
4073 c_expand_expr (exp
, target
, tmode
, modifier
)
4076 enum machine_mode tmode
;
4077 enum expand_modifier modifier
;
4079 switch (TREE_CODE (exp
))
4086 /* Since expand_expr_stmt calls free_temp_slots after every
4087 expression statement, we must call push_temp_slots here.
4088 Otherwise, any temporaries in use now would be considered
4089 out-of-scope after the first EXPR_STMT from within the
4092 rtl_expr
= expand_start_stmt_expr ();
4093 expand_stmt (STMT_EXPR_STMT (exp
));
4094 expand_end_stmt_expr (rtl_expr
);
4095 result
= expand_expr (rtl_expr
, target
, tmode
, modifier
);
4103 if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
4104 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
4106 && DECL_BUILT_IN (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
4107 && (DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (exp
, 0), 0))
4108 == BUILT_IN_FRONTEND
))
4109 return c_expand_builtin (exp
, target
, tmode
, modifier
);
4123 /* Hook used by safe_from_p to handle language-specific tree codes. */
4126 c_safe_from_p (target
, exp
)
4130 /* We can see statements here when processing the body of a
4131 statement-expression. For a declaration statement declaring a
4132 variable, look at the variable's initializer. */
4133 if (TREE_CODE (exp
) == DECL_STMT
)
4135 tree decl
= DECL_STMT_DECL (exp
);
4137 if (TREE_CODE (decl
) == VAR_DECL
4138 && DECL_INITIAL (decl
)
4139 && !safe_from_p (target
, DECL_INITIAL (decl
), /*top_p=*/0))
4143 /* For any statement, we must follow the statement-chain. */
4144 if (statement_code_p (TREE_CODE (exp
)) && TREE_CHAIN (exp
))
4145 return safe_from_p (target
, TREE_CHAIN (exp
), /*top_p=*/0);
4147 /* Assume everything else is safe. */
4151 /* Hook used by unsafe_for_reeval to handle language-specific tree codes. */
4154 c_unsafe_for_reeval (exp
)
4157 /* Statement expressions may not be reevaluated. */
4158 if (TREE_CODE (exp
) == STMT_EXPR
)
4161 /* Walk all other expressions. */
4165 /* Tree code classes. */
4167 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
4169 static char c_tree_code_type
[] = {
4171 #include "c-common.def"
4175 /* Table indexed by tree code giving number of expression
4176 operands beyond the fixed part of the node structure.
4177 Not used for types or decls. */
4179 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
4181 static int c_tree_code_length
[] = {
4183 #include "c-common.def"
4187 /* Names of tree components.
4188 Used for printing out the tree and error messages. */
4189 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
4191 static const char *c_tree_code_name
[] = {
4193 #include "c-common.def"
4197 /* Adds the tree codes specific to the C front end to the list of all
4203 memcpy (tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4205 (int)LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
);
4206 memcpy (tree_code_length
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4208 (LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (int));
4209 memcpy (tree_code_name
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4211 (LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));
4212 lang_unsafe_for_reeval
= c_unsafe_for_reeval
;
4215 #define CALLED_AS_BUILT_IN(NODE) \
4216 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
4219 c_expand_builtin (exp
, target
, tmode
, modifier
)
4222 enum machine_mode tmode
;
4223 enum expand_modifier modifier
;
4225 tree type
= TREE_TYPE (exp
);
4226 tree fndecl
= TREE_OPERAND (TREE_OPERAND (exp
, 0), 0);
4227 tree arglist
= TREE_OPERAND (exp
, 1);
4228 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
4229 enum tree_code code
= TREE_CODE (exp
);
4230 const int ignore
= (target
== const0_rtx
4231 || ((code
== NON_LVALUE_EXPR
|| code
== NOP_EXPR
4232 || code
== CONVERT_EXPR
|| code
== REFERENCE_EXPR
4233 || code
== COND_EXPR
)
4234 && TREE_CODE (type
) == VOID_TYPE
));
4236 if (! optimize
&& ! CALLED_AS_BUILT_IN (fndecl
))
4237 return expand_call (exp
, target
, ignore
);
4241 case BUILT_IN_PRINTF
:
4242 target
= c_expand_builtin_printf (arglist
, target
, tmode
,
4248 case BUILT_IN_FPRINTF
:
4249 target
= c_expand_builtin_fprintf (arglist
, target
, tmode
,
4255 default: /* just do library call, if unknown builtin */
4256 error ("built-in function `%s' not currently supported",
4257 IDENTIFIER_POINTER (DECL_NAME (fndecl
)));
4260 /* The switch statement above can drop through to cause the function
4261 to be called normally. */
4262 return expand_call (exp
, target
, ignore
);
4265 /* Check an arglist to *printf for problems. The arglist should start
4266 at the format specifier, with the remaining arguments immediately
4269 is_valid_printf_arglist (arglist
)
4272 /* Save this value so we can restore it later. */
4273 const int SAVE_pedantic
= pedantic
;
4274 int diagnostic_occurred
= 0;
4276 /* Set this to a known value so the user setting won't affect code
4279 /* Check to make sure there are no format specifier errors. */
4280 check_function_format (&diagnostic_occurred
,
4281 maybe_get_identifier("printf"),
4282 NULL_TREE
, arglist
);
4284 /* Restore the value of `pedantic'. */
4285 pedantic
= SAVE_pedantic
;
4287 /* If calling `check_function_format_ptr' produces a warning, we
4288 return false, otherwise we return true. */
4289 return ! diagnostic_occurred
;
4292 /* If the arguments passed to printf are suitable for optimizations,
4293 we attempt to transform the call. */
4295 c_expand_builtin_printf (arglist
, target
, tmode
, modifier
, ignore
)
4298 enum machine_mode tmode
;
4299 enum expand_modifier modifier
;
4302 tree fn_putchar
= built_in_decls
[BUILT_IN_PUTCHAR
],
4303 fn_puts
= built_in_decls
[BUILT_IN_PUTS
];
4304 tree fn
, format_arg
, stripped_string
;
4306 /* If the return value is used, or the replacement _DECL isn't
4307 initialized, don't do the transformation. */
4308 if (!ignore
|| !fn_putchar
|| !fn_puts
)
4311 /* Verify the required arguments in the original call. */
4313 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist
))) != POINTER_TYPE
))
4316 /* Check the specifier vs. the parameters. */
4317 if (!is_valid_printf_arglist (arglist
))
4320 format_arg
= TREE_VALUE (arglist
);
4321 stripped_string
= format_arg
;
4322 STRIP_NOPS (stripped_string
);
4323 if (stripped_string
&& TREE_CODE (stripped_string
) == ADDR_EXPR
)
4324 stripped_string
= TREE_OPERAND (stripped_string
, 0);
4326 /* If the format specifier isn't a STRING_CST, punt. */
4327 if (TREE_CODE (stripped_string
) != STRING_CST
)
4330 /* OK! We can attempt optimization. */
4332 /* If the format specifier was "%s\n", call __builtin_puts(arg2). */
4333 if (strcmp (TREE_STRING_POINTER (stripped_string
), "%s\n") == 0)
4335 arglist
= TREE_CHAIN (arglist
);
4338 /* If the format specifier was "%c", call __builtin_putchar (arg2). */
4339 else if (strcmp (TREE_STRING_POINTER (stripped_string
), "%c") == 0)
4341 arglist
= TREE_CHAIN (arglist
);
4346 /* We can't handle anything else with % args or %% ... yet. */
4347 if (strchr (TREE_STRING_POINTER (stripped_string
), '%'))
4350 /* If the resulting constant string has a length of 1, call
4351 putchar. Note, TREE_STRING_LENGTH includes the terminating
4352 NULL in its count. */
4353 if (TREE_STRING_LENGTH (stripped_string
) == 2)
4355 /* Given printf("c"), (where c is any one character,)
4356 convert "c"[0] to an int and pass that to the replacement
4358 arglist
= build_int_2 (TREE_STRING_POINTER (stripped_string
)[0], 0);
4359 arglist
= build_tree_list (NULL_TREE
, arglist
);
4363 /* If the resulting constant was "string\n", call
4364 __builtin_puts("string"). Ensure "string" has at least one
4365 character besides the trailing \n. Note, TREE_STRING_LENGTH
4366 includes the terminating NULL in its count. */
4367 else if (TREE_STRING_LENGTH (stripped_string
) > 2
4368 && TREE_STRING_POINTER (stripped_string
)
4369 [TREE_STRING_LENGTH (stripped_string
) - 2] == '\n')
4371 /* Create a NULL-terminated string that's one char shorter
4372 than the original, stripping off the trailing '\n'. */
4373 const int newlen
= TREE_STRING_LENGTH (stripped_string
) - 1;
4374 char *newstr
= (char *) alloca (newlen
);
4375 memcpy (newstr
, TREE_STRING_POINTER (stripped_string
), newlen
- 1);
4376 newstr
[newlen
- 1] = 0;
4378 arglist
= combine_strings (build_string (newlen
, newstr
));
4379 arglist
= build_tree_list (NULL_TREE
, arglist
);
4383 /* We'd like to arrange to call fputs(string) here, but we
4384 need stdout and don't have a way to get it ... yet. */
4388 return expand_expr (build_function_call (fn
, arglist
),
4389 (ignore
? const0_rtx
: target
),
4393 /* If the arguments passed to fprintf are suitable for optimizations,
4394 we attempt to transform the call. */
4396 c_expand_builtin_fprintf (arglist
, target
, tmode
, modifier
, ignore
)
4399 enum machine_mode tmode
;
4400 enum expand_modifier modifier
;
4403 tree fn_fputc
= built_in_decls
[BUILT_IN_FPUTC
],
4404 fn_fputs
= built_in_decls
[BUILT_IN_FPUTS
];
4405 tree fn
, format_arg
, stripped_string
;
4407 /* If the return value is used, or the replacement _DECL isn't
4408 initialized, don't do the transformation. */
4409 if (!ignore
|| !fn_fputc
|| !fn_fputs
)
4412 /* Verify the required arguments in the original call. */
4414 || (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist
))) != POINTER_TYPE
)
4415 || (TREE_CHAIN (arglist
) == 0)
4416 || (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist
)))) !=
4420 /* Check the specifier vs. the parameters. */
4421 if (!is_valid_printf_arglist (TREE_CHAIN (arglist
)))
4424 format_arg
= TREE_VALUE (TREE_CHAIN (arglist
));
4425 stripped_string
= format_arg
;
4426 STRIP_NOPS (stripped_string
);
4427 if (stripped_string
&& TREE_CODE (stripped_string
) == ADDR_EXPR
)
4428 stripped_string
= TREE_OPERAND (stripped_string
, 0);
4430 /* If the format specifier isn't a STRING_CST, punt. */
4431 if (TREE_CODE (stripped_string
) != STRING_CST
)
4434 /* OK! We can attempt optimization. */
4436 /* If the format specifier was "%s", call __builtin_fputs(arg3, arg1). */
4437 if (strcmp (TREE_STRING_POINTER (stripped_string
), "%s") == 0)
4439 tree newarglist
= build_tree_list (NULL_TREE
, TREE_VALUE (arglist
));
4440 arglist
= tree_cons (NULL_TREE
,
4441 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist
))),
4445 /* If the format specifier was "%c", call __builtin_fputc (arg3, arg1). */
4446 else if (strcmp (TREE_STRING_POINTER (stripped_string
), "%c") == 0)
4448 tree newarglist
= build_tree_list (NULL_TREE
, TREE_VALUE (arglist
));
4449 arglist
= tree_cons (NULL_TREE
,
4450 TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist
))),
4456 /* We can't handle anything else with % args or %% ... yet. */
4457 if (strchr (TREE_STRING_POINTER (stripped_string
), '%'))
4460 /* When "string" doesn't contain %, replace all cases of
4461 fprintf(stream,string) with fputs(string,stream). The fputs
4462 builtin will take take of special cases like length==1. */
4463 arglist
= tree_cons (NULL_TREE
, TREE_VALUE (TREE_CHAIN (arglist
)),
4464 build_tree_list (NULL_TREE
, TREE_VALUE (arglist
)));
4468 return expand_expr (build_function_call (fn
, arglist
),
4469 (ignore
? const0_rtx
: target
),
4474 /* Given a boolean expression ARG, return a tree representing an increment
4475 or decrement (as indicated by CODE) of ARG. The front end must check for
4476 invalid cases (e.g., decrement in C++). */
4478 boolean_increment (code
, arg
)
4479 enum tree_code code
;
4483 tree true_res
= (c_language
== clk_cplusplus
4485 : c_bool_true_node
);
4486 arg
= stabilize_reference (arg
);
4489 case PREINCREMENT_EXPR
:
4490 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
4492 case POSTINCREMENT_EXPR
:
4493 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, true_res
);
4494 arg
= save_expr (arg
);
4495 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4496 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4498 case PREDECREMENT_EXPR
:
4499 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, invert_truthvalue (arg
));
4501 case POSTDECREMENT_EXPR
:
4502 val
= build (MODIFY_EXPR
, TREE_TYPE (arg
), arg
, invert_truthvalue (arg
));
4503 arg
= save_expr (arg
);
4504 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), val
, arg
);
4505 val
= build (COMPOUND_EXPR
, TREE_TYPE (arg
), arg
, val
);
4510 TREE_SIDE_EFFECTS (val
) = 1;
4515 /* Do the parts of lang_init common to C and C++. */
4517 c_common_lang_init ()
4519 /* If still "unspecified", make it match -fbounded-pointers. */
4520 if (flag_bounds_check
< 0)
4521 flag_bounds_check
= flag_bounded_pointers
;
4523 /* Special format checking options don't work without -Wformat; warn if
4525 if (warn_format_y2k
&& !warn_format
)
4526 warning ("-Wformat-y2k ignored without -Wformat");
4527 if (warn_format_extra_args
&& !warn_format
)
4528 warning ("-Wformat-extra-args ignored without -Wformat");
4529 if (warn_format_nonliteral
&& !warn_format
)
4530 warning ("-Wformat-nonliteral ignored without -Wformat");
4531 if (warn_format_security
&& !warn_format
)
4532 warning ("-Wformat-security ignored without -Wformat");
4533 if (warn_missing_format_attribute
&& !warn_format
)
4534 warning ("-Wmissing-format-attribute ignored without -Wformat");