1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
39 cpp_options parse_options
;
40 enum cpp_token cpp_token
;
43 #undef WCHAR_TYPE_SIZE
44 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
46 /* The following symbols are subsumed in the c_global_trees array, and
47 listed here individually for documentation purposes.
49 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
51 tree short_integer_type_node;
52 tree long_integer_type_node;
53 tree long_long_integer_type_node;
55 tree short_unsigned_type_node;
56 tree long_unsigned_type_node;
57 tree long_long_unsigned_type_node;
59 tree boolean_type_node;
60 tree boolean_false_node;
61 tree boolean_true_node;
63 tree ptrdiff_type_node;
65 tree unsigned_char_type_node;
66 tree signed_char_type_node;
68 tree signed_wchar_type_node;
69 tree unsigned_wchar_type_node;
72 tree double_type_node;
73 tree long_double_type_node;
75 tree complex_integer_type_node;
76 tree complex_float_type_node;
77 tree complex_double_type_node;
78 tree complex_long_double_type_node;
86 tree unsigned_intQI_type_node;
87 tree unsigned_intHI_type_node;
88 tree unsigned_intSI_type_node;
89 tree unsigned_intDI_type_node;
90 tree unsigned_intTI_type_node;
92 tree widest_integer_literal_type_node;
93 tree widest_unsigned_literal_type_node;
95 Nodes for types `void *' and `const void *'.
97 tree ptr_type_node, const_ptr_type_node;
99 Nodes for types `char *' and `const char *'.
101 tree string_type_node, const_string_type_node;
103 Type `char[SOMENUMBER]'.
104 Used when an array of char is needed and the size is irrelevant.
106 tree char_array_type_node;
108 Type `int[SOMENUMBER]' or something like it.
109 Used when an array of int needed and the size is irrelevant.
111 tree int_array_type_node;
113 Type `wchar_t[SOMENUMBER]' or something like it.
114 Used when a wide string literal is created.
116 tree wchar_array_type_node;
118 Type `int ()' -- used for implicit declaration of functions.
120 tree default_function_type;
122 Function types `int (int)', etc.
128 tree ptr_ftype_sizetype;
130 A VOID_TYPE node, packaged in a TREE_LIST.
136 tree c_global_trees
[CTI_MAX
];
138 tree (*make_fname_decl
) PARAMS ((tree
, const char *, int));
140 /* Nonzero means the expression being parsed will never be evaluated.
141 This is a count, since unevaluated expressions can nest. */
144 enum attrs
{A_PACKED
, A_NOCOMMON
, A_COMMON
, A_NORETURN
, A_CONST
, A_T_UNION
,
145 A_NO_CHECK_MEMORY_USAGE
, A_NO_INSTRUMENT_FUNCTION
,
146 A_CONSTRUCTOR
, A_DESTRUCTOR
, A_MODE
, A_SECTION
, A_ALIGNED
,
147 A_UNUSED
, A_FORMAT
, A_FORMAT_ARG
, A_WEAK
, A_ALIAS
, A_MALLOC
,
148 A_NO_LIMIT_STACK
, A_PURE
};
150 enum format_type
{ printf_format_type
, scanf_format_type
,
151 strftime_format_type
};
153 static void add_attribute
PARAMS ((enum attrs
, const char *,
155 static void init_attributes
PARAMS ((void));
156 static void record_function_format
PARAMS ((tree
, tree
, enum format_type
,
158 static void record_international_format
PARAMS ((tree
, tree
, int));
159 static int default_valid_lang_attribute
PARAMS ((tree
, tree
, tree
, tree
));
161 /* Keep a stack of if statements. We record the number of compound
162 statements seen up to the if keyword, as well as the line number
163 and file of the if. If a potentially ambiguous else is seen, that
164 fact is recorded; the warning is issued when we can be sure that
165 the enclosing if statement does not have an else branch. */
173 static void tfaff
PARAMS ((void));
175 static if_elt
*if_stack
;
177 /* Amount of space in the if statement stack. */
178 static int if_stack_space
= 0;
181 static int if_stack_pointer
= 0;
183 /* Generate RTL for the start of an if-then, and record the start of it
184 for ambiguous else detection. */
187 c_expand_start_cond (cond
, exitflag
, compstmt_count
)
192 /* Make sure there is enough space on the stack. */
193 if (if_stack_space
== 0)
196 if_stack
= (if_elt
*)xmalloc (10 * sizeof (if_elt
));
198 else if (if_stack_space
== if_stack_pointer
)
200 if_stack_space
+= 10;
201 if_stack
= (if_elt
*)xrealloc (if_stack
, if_stack_space
* sizeof (if_elt
));
204 /* Record this if statement. */
205 if_stack
[if_stack_pointer
].compstmt_count
= compstmt_count
;
206 if_stack
[if_stack_pointer
].file
= input_filename
;
207 if_stack
[if_stack_pointer
].line
= lineno
;
208 if_stack
[if_stack_pointer
].needs_warning
= 0;
211 expand_start_cond (cond
, exitflag
);
214 /* Generate RTL for the end of an if-then. Optionally warn if a nested
215 if statement had an ambiguous else clause. */
221 if (if_stack
[if_stack_pointer
].needs_warning
)
222 warning_with_file_and_line (if_stack
[if_stack_pointer
].file
,
223 if_stack
[if_stack_pointer
].line
,
224 "suggest explicit braces to avoid ambiguous `else'");
228 /* Generate RTL between the then-clause and the else-clause
229 of an if-then-else. */
232 c_expand_start_else ()
234 /* An ambiguous else warning must be generated for the enclosing if
235 statement, unless we see an else branch for that one, too. */
237 && if_stack_pointer
> 1
238 && (if_stack
[if_stack_pointer
- 1].compstmt_count
239 == if_stack
[if_stack_pointer
- 2].compstmt_count
))
240 if_stack
[if_stack_pointer
- 2].needs_warning
= 1;
242 /* Even if a nested if statement had an else branch, it can't be
243 ambiguous if this one also has an else. So don't warn in that
244 case. Also don't warn for any if statements nested in this else. */
245 if_stack
[if_stack_pointer
- 1].needs_warning
= 0;
246 if_stack
[if_stack_pointer
- 1].compstmt_count
--;
248 expand_start_else ();
251 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
254 declare_function_name ()
256 const char *name
, *printable_name
;
258 if (current_function_decl
== NULL
)
261 printable_name
= "top level";
265 /* Allow functions to be nameless (such as artificial ones). */
266 if (DECL_NAME (current_function_decl
))
267 name
= IDENTIFIER_POINTER (DECL_NAME (current_function_decl
));
270 printable_name
= (*decl_printable_name
) (current_function_decl
, 2);
273 (*make_fname_decl
) (get_identifier ("__FUNCTION__"), name
, 0);
274 (*make_fname_decl
) (get_identifier ("__PRETTY_FUNCTION__"), printable_name
, 1);
275 /* The ISO C people "of course" couldn't use __FUNCTION__ in the
276 ISO C 99 standard; instead a new variable is invented. */
277 (*make_fname_decl
) (get_identifier ("__func__"), name
, 0);
280 /* Given a chain of STRING_CST nodes,
281 concatenate them into one STRING_CST
282 and give it a suitable array-of-chars data type. */
285 combine_strings (strings
)
288 register tree value
, t
;
289 register int length
= 1;
292 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
295 if (TREE_CHAIN (strings
))
297 /* More than one in the chain, so concatenate. */
298 register char *p
, *q
;
300 /* Don't include the \0 at the end of each substring,
301 except for the last one.
302 Count wide strings and ordinary strings separately. */
303 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
305 if (TREE_TYPE (t
) == wchar_array_type_node
)
307 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
311 length
+= (TREE_STRING_LENGTH (t
) - 1);
314 /* If anything is wide, the non-wides will be converted,
315 which makes them take more space. */
317 length
= length
* wchar_bytes
+ wide_length
;
319 p
= ggc_alloc_string (NULL
, length
);
321 /* Copy the individual strings into the new combined string.
322 If the combined string is wide, convert the chars to ints
323 for any individual strings that are not wide. */
326 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
328 int len
= (TREE_STRING_LENGTH (t
)
329 - ((TREE_TYPE (t
) == wchar_array_type_node
)
331 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
333 memcpy (q
, TREE_STRING_POINTER (t
), len
);
339 for (i
= 0; i
< len
; i
++)
341 if (WCHAR_TYPE_SIZE
== HOST_BITS_PER_SHORT
)
342 ((short *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
344 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
346 q
+= len
* wchar_bytes
;
352 for (i
= 0; i
< wchar_bytes
; i
++)
358 value
= make_node (STRING_CST
);
359 TREE_STRING_POINTER (value
) = p
;
360 TREE_STRING_LENGTH (value
) = length
;
365 length
= TREE_STRING_LENGTH (value
);
366 if (TREE_TYPE (value
) == wchar_array_type_node
)
370 /* Compute the number of elements, for the array type. */
371 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
373 /* Create the array type for the string constant.
374 -Wwrite-strings says make the string constant an array of const char
375 so that copying it to a non-const pointer will get a warning.
376 For C++, this is the standard behavior. */
377 if (flag_const_strings
378 && (! flag_traditional
&& ! flag_writable_strings
))
381 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
384 = build_array_type (elements
,
385 build_index_type (build_int_2 (nchars
- 1, 0)));
389 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
390 build_index_type (build_int_2 (nchars
- 1, 0)));
392 TREE_CONSTANT (value
) = 1;
393 TREE_READONLY (value
) = ! flag_writable_strings
;
394 TREE_STATIC (value
) = 1;
398 /* To speed up processing of attributes, we maintain an array of
399 IDENTIFIER_NODES and the corresponding attribute types. */
401 /* Array to hold attribute information. */
403 static struct {enum attrs id
; tree name
; int min
, max
, decl_req
;} attrtab
[50];
405 static int attrtab_idx
= 0;
407 /* Add an entry to the attribute table above. */
410 add_attribute (id
, string
, min_len
, max_len
, decl_req
)
413 int min_len
, max_len
;
418 attrtab
[attrtab_idx
].id
= id
;
419 attrtab
[attrtab_idx
].name
= get_identifier (string
);
420 attrtab
[attrtab_idx
].min
= min_len
;
421 attrtab
[attrtab_idx
].max
= max_len
;
422 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
424 sprintf (buf
, "__%s__", string
);
426 attrtab
[attrtab_idx
].id
= id
;
427 attrtab
[attrtab_idx
].name
= get_identifier (buf
);
428 attrtab
[attrtab_idx
].min
= min_len
;
429 attrtab
[attrtab_idx
].max
= max_len
;
430 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
433 /* Initialize attribute table. */
438 add_attribute (A_PACKED
, "packed", 0, 0, 0);
439 add_attribute (A_NOCOMMON
, "nocommon", 0, 0, 1);
440 add_attribute (A_COMMON
, "common", 0, 0, 1);
441 add_attribute (A_NORETURN
, "noreturn", 0, 0, 1);
442 add_attribute (A_NORETURN
, "volatile", 0, 0, 1);
443 add_attribute (A_UNUSED
, "unused", 0, 0, 0);
444 add_attribute (A_CONST
, "const", 0, 0, 1);
445 add_attribute (A_T_UNION
, "transparent_union", 0, 0, 0);
446 add_attribute (A_CONSTRUCTOR
, "constructor", 0, 0, 1);
447 add_attribute (A_DESTRUCTOR
, "destructor", 0, 0, 1);
448 add_attribute (A_MODE
, "mode", 1, 1, 1);
449 add_attribute (A_SECTION
, "section", 1, 1, 1);
450 add_attribute (A_ALIGNED
, "aligned", 0, 1, 0);
451 add_attribute (A_FORMAT
, "format", 3, 3, 1);
452 add_attribute (A_FORMAT_ARG
, "format_arg", 1, 1, 1);
453 add_attribute (A_WEAK
, "weak", 0, 0, 1);
454 add_attribute (A_ALIAS
, "alias", 1, 1, 1);
455 add_attribute (A_NO_INSTRUMENT_FUNCTION
, "no_instrument_function", 0, 0, 1);
456 add_attribute (A_NO_CHECK_MEMORY_USAGE
, "no_check_memory_usage", 0, 0, 1);
457 add_attribute (A_MALLOC
, "malloc", 0, 0, 1);
458 add_attribute (A_NO_LIMIT_STACK
, "no_stack_limit", 0, 0, 1);
459 add_attribute (A_PURE
, "pure", 0, 0, 1);
462 /* Default implementation of valid_lang_attribute, below. By default, there
463 are no language-specific attributes. */
466 default_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
467 tree attr_name ATTRIBUTE_UNUSED
;
468 tree attr_args ATTRIBUTE_UNUSED
;
469 tree decl ATTRIBUTE_UNUSED
;
470 tree type ATTRIBUTE_UNUSED
;
475 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
476 attribute for either declaration DECL or type TYPE and 0 otherwise. */
478 int (*valid_lang_attribute
) PARAMS ((tree
, tree
, tree
, tree
))
479 = default_valid_lang_attribute
;
481 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
482 and install them in NODE, which is either a DECL (including a TYPE_DECL)
483 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
484 and declaration modifiers but before the declaration proper. */
487 decl_attributes (node
, attributes
, prefix_attributes
)
488 tree node
, attributes
, prefix_attributes
;
490 tree decl
= 0, type
= 0;
494 if (attrtab_idx
== 0)
500 type
= TREE_TYPE (decl
);
501 is_type
= TREE_CODE (node
) == TYPE_DECL
;
503 else if (TYPE_P (node
))
504 type
= node
, is_type
= 1;
506 #ifdef PRAGMA_INSERT_ATTRIBUTES
507 /* If the code in c-pragma.c wants to insert some attributes then
508 allow it to do so. Do this before allowing machine back ends to
509 insert attributes, so that they have the opportunity to override
510 anything done here. */
511 PRAGMA_INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
514 #ifdef INSERT_ATTRIBUTES
515 INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
518 attributes
= chainon (prefix_attributes
, attributes
);
520 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
522 tree name
= TREE_PURPOSE (a
);
523 tree args
= TREE_VALUE (a
);
527 for (i
= 0; i
< attrtab_idx
; i
++)
528 if (attrtab
[i
].name
== name
)
531 if (i
== attrtab_idx
)
533 if (! valid_machine_attribute (name
, args
, decl
, type
)
534 && ! (* valid_lang_attribute
) (name
, args
, decl
, type
))
535 warning ("`%s' attribute directive ignored",
536 IDENTIFIER_POINTER (name
));
538 type
= TREE_TYPE (decl
);
541 else if (attrtab
[i
].decl_req
&& decl
== 0)
543 warning ("`%s' attribute does not apply to types",
544 IDENTIFIER_POINTER (name
));
547 else if (list_length (args
) < attrtab
[i
].min
548 || list_length (args
) > attrtab
[i
].max
)
550 error ("wrong number of arguments specified for `%s' attribute",
551 IDENTIFIER_POINTER (name
));
560 TYPE_PACKED (type
) = 1;
561 else if (TREE_CODE (decl
) == FIELD_DECL
)
562 DECL_PACKED (decl
) = 1;
563 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
564 used for DECL_REGISTER. It wouldn't mean anything anyway. */
566 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
570 if (TREE_CODE (decl
) == VAR_DECL
)
571 DECL_COMMON (decl
) = 0;
573 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
577 if (TREE_CODE (decl
) == VAR_DECL
)
578 DECL_COMMON (decl
) = 1;
580 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
584 if (TREE_CODE (decl
) == FUNCTION_DECL
)
585 TREE_THIS_VOLATILE (decl
) = 1;
586 else if (TREE_CODE (type
) == POINTER_TYPE
587 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
588 TREE_TYPE (decl
) = type
590 (build_type_variant (TREE_TYPE (type
),
591 TREE_READONLY (TREE_TYPE (type
)), 1));
593 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
597 if (TREE_CODE (decl
) == FUNCTION_DECL
)
598 DECL_IS_MALLOC (decl
) = 1;
599 /* ??? TODO: Support types. */
601 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
607 TREE_USED (decl
) = 1;
609 TREE_USED (type
) = 1;
610 else if (TREE_CODE (decl
) == PARM_DECL
611 || TREE_CODE (decl
) == VAR_DECL
612 || TREE_CODE (decl
) == FUNCTION_DECL
613 || TREE_CODE (decl
) == LABEL_DECL
)
614 TREE_USED (decl
) = 1;
616 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
620 if (TREE_CODE (decl
) == FUNCTION_DECL
)
621 TREE_READONLY (decl
) = 1;
622 else if (TREE_CODE (type
) == POINTER_TYPE
623 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
624 TREE_TYPE (decl
) = type
626 (build_type_variant (TREE_TYPE (type
), 1,
627 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
629 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name
));
633 if (TREE_CODE (decl
) == FUNCTION_DECL
)
634 DECL_IS_PURE (decl
) = 1;
635 /* ??? TODO: Support types. */
637 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
643 && TREE_CODE (type
) == UNION_TYPE
645 || (TYPE_FIELDS (type
) != 0
646 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))))
647 TYPE_TRANSPARENT_UNION (type
) = 1;
648 else if (decl
!= 0 && TREE_CODE (decl
) == PARM_DECL
649 && TREE_CODE (type
) == UNION_TYPE
650 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))
651 DECL_TRANSPARENT_UNION (decl
) = 1;
653 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
657 if (TREE_CODE (decl
) == FUNCTION_DECL
658 && TREE_CODE (type
) == FUNCTION_TYPE
659 && decl_function_context (decl
) == 0)
661 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
662 TREE_USED (decl
) = 1;
665 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
669 if (TREE_CODE (decl
) == FUNCTION_DECL
670 && TREE_CODE (type
) == FUNCTION_TYPE
671 && decl_function_context (decl
) == 0)
673 DECL_STATIC_DESTRUCTOR (decl
) = 1;
674 TREE_USED (decl
) = 1;
677 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
681 if (TREE_CODE (TREE_VALUE (args
)) != IDENTIFIER_NODE
)
682 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
686 const char *p
= IDENTIFIER_POINTER (TREE_VALUE (args
));
687 int len
= strlen (p
);
688 enum machine_mode mode
= VOIDmode
;
691 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
692 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
694 char *newp
= (char *) alloca (len
- 1);
696 strcpy (newp
, &p
[2]);
697 newp
[len
- 4] = '\0';
701 /* Give this decl a type with the specified mode.
702 First check for the special modes. */
703 if (! strcmp (p
, "byte"))
705 else if (!strcmp (p
, "word"))
707 else if (! strcmp (p
, "pointer"))
710 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
711 if (!strcmp (p
, GET_MODE_NAME (j
)))
712 mode
= (enum machine_mode
) j
;
714 if (mode
== VOIDmode
)
715 error ("unknown machine mode `%s'", p
);
716 else if (0 == (typefm
= type_for_mode (mode
,
717 TREE_UNSIGNED (type
))))
718 error ("no data type for mode `%s'", p
);
721 TREE_TYPE (decl
) = type
= typefm
;
722 DECL_SIZE (decl
) = DECL_SIZE_UNIT (decl
) = 0;
723 layout_decl (decl
, 0);
729 #ifdef ASM_OUTPUT_SECTION_NAME
730 if ((TREE_CODE (decl
) == FUNCTION_DECL
731 || TREE_CODE (decl
) == VAR_DECL
)
732 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
734 if (TREE_CODE (decl
) == VAR_DECL
735 && current_function_decl
!= NULL_TREE
736 && ! TREE_STATIC (decl
))
737 error_with_decl (decl
,
738 "section attribute cannot be specified for local variables");
739 /* The decl may have already been given a section attribute from
740 a previous declaration. Ensure they match. */
741 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
742 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
743 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
744 error_with_decl (node
,
745 "section of `%s' conflicts with previous declaration");
747 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
750 error_with_decl (node
,
751 "section attribute not allowed for `%s'");
753 error_with_decl (node
,
754 "section attributes are not supported for this target");
761 = (args
? TREE_VALUE (args
)
762 : size_int (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
765 /* Strip any NOPs of any kind. */
766 while (TREE_CODE (align_expr
) == NOP_EXPR
767 || TREE_CODE (align_expr
) == CONVERT_EXPR
768 || TREE_CODE (align_expr
) == NON_LVALUE_EXPR
)
769 align_expr
= TREE_OPERAND (align_expr
, 0);
771 if (TREE_CODE (align_expr
) != INTEGER_CST
)
773 error ("requested alignment is not a constant");
777 if ((i
= tree_log2 (align_expr
)) == -1)
778 error ("requested alignment is not a power of 2");
779 else if (i
> HOST_BITS_PER_INT
- 2)
780 error ("requested alignment is too large");
783 TYPE_ALIGN (type
) = (1 << i
) * BITS_PER_UNIT
;
784 TYPE_USER_ALIGN (type
) = 1;
786 else if (TREE_CODE (decl
) != VAR_DECL
787 && TREE_CODE (decl
) != FIELD_DECL
)
788 error_with_decl (decl
,
789 "alignment may not be specified for `%s'");
792 DECL_ALIGN (decl
) = (1 << i
) * BITS_PER_UNIT
;
793 DECL_USER_ALIGN (decl
) = 1;
800 tree format_type_id
= TREE_VALUE (args
);
801 tree format_num_expr
= TREE_VALUE (TREE_CHAIN (args
));
802 tree first_arg_num_expr
803 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
)));
804 unsigned HOST_WIDE_INT format_num
, first_arg_num
;
805 enum format_type format_type
;
807 unsigned int arg_num
;
809 if (TREE_CODE (decl
) != FUNCTION_DECL
)
811 error_with_decl (decl
,
812 "argument format specified for non-function `%s'");
816 if (TREE_CODE (format_type_id
) != IDENTIFIER_NODE
)
818 error ("unrecognized format specifier");
823 const char *p
= IDENTIFIER_POINTER (format_type_id
);
825 if (!strcmp (p
, "printf") || !strcmp (p
, "__printf__"))
826 format_type
= printf_format_type
;
827 else if (!strcmp (p
, "scanf") || !strcmp (p
, "__scanf__"))
828 format_type
= scanf_format_type
;
829 else if (!strcmp (p
, "strftime")
830 || !strcmp (p
, "__strftime__"))
831 format_type
= strftime_format_type
;
834 warning ("`%s' is an unrecognized format function type", p
);
839 /* Strip any conversions from the string index and first arg number
840 and verify they are constants. */
841 while (TREE_CODE (format_num_expr
) == NOP_EXPR
842 || TREE_CODE (format_num_expr
) == CONVERT_EXPR
843 || TREE_CODE (format_num_expr
) == NON_LVALUE_EXPR
)
844 format_num_expr
= TREE_OPERAND (format_num_expr
, 0);
846 while (TREE_CODE (first_arg_num_expr
) == NOP_EXPR
847 || TREE_CODE (first_arg_num_expr
) == CONVERT_EXPR
848 || TREE_CODE (first_arg_num_expr
) == NON_LVALUE_EXPR
)
849 first_arg_num_expr
= TREE_OPERAND (first_arg_num_expr
, 0);
851 if (TREE_CODE (format_num_expr
) != INTEGER_CST
852 || TREE_INT_CST_HIGH (format_num_expr
) != 0
853 || TREE_CODE (first_arg_num_expr
) != INTEGER_CST
854 || TREE_INT_CST_HIGH (first_arg_num_expr
) != 0)
856 error ("format string has invalid operand number");
860 format_num
= TREE_INT_CST_LOW (format_num_expr
);
861 first_arg_num
= TREE_INT_CST_LOW (first_arg_num_expr
);
862 if (first_arg_num
!= 0 && first_arg_num
<= format_num
)
864 error ("format string arg follows the args to be formatted");
868 /* If a parameter list is specified, verify that the format_num
869 argument is actually a string, in case the format attribute
871 argument
= TYPE_ARG_TYPES (type
);
874 for (arg_num
= 1; argument
!= 0 && arg_num
!= format_num
;
875 ++arg_num
, argument
= TREE_CHAIN (argument
))
879 || TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
880 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument
)))
883 error ("format string arg not a string type");
887 else if (first_arg_num
!= 0)
889 /* Verify that first_arg_num points to the last arg,
892 arg_num
++, argument
= TREE_CHAIN (argument
);
894 if (arg_num
!= first_arg_num
)
896 error ("args to be formatted is not '...'");
902 record_function_format (DECL_NAME (decl
),
903 DECL_ASSEMBLER_NAME (decl
),
904 format_type
, format_num
, first_arg_num
);
910 tree format_num_expr
= TREE_VALUE (args
);
911 unsigned HOST_WIDE_INT format_num
;
912 unsigned int arg_num
;
915 if (TREE_CODE (decl
) != FUNCTION_DECL
)
917 error_with_decl (decl
,
918 "argument format specified for non-function `%s'");
922 /* Strip any conversions from the first arg number and verify it
924 while (TREE_CODE (format_num_expr
) == NOP_EXPR
925 || TREE_CODE (format_num_expr
) == CONVERT_EXPR
926 || TREE_CODE (format_num_expr
) == NON_LVALUE_EXPR
)
927 format_num_expr
= TREE_OPERAND (format_num_expr
, 0);
929 if (TREE_CODE (format_num_expr
) != INTEGER_CST
930 || TREE_INT_CST_HIGH (format_num_expr
) != 0)
932 error ("format string has invalid operand number");
936 format_num
= TREE_INT_CST_LOW (format_num_expr
);
938 /* If a parameter list is specified, verify that the format_num
939 argument is actually a string, in case the format attribute
941 argument
= TYPE_ARG_TYPES (type
);
944 for (arg_num
= 1; argument
!= 0 && arg_num
!= format_num
;
945 ++arg_num
, argument
= TREE_CHAIN (argument
))
949 || TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
950 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument
)))
953 error ("format string arg not a string type");
958 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl
))) != POINTER_TYPE
959 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl
))))
962 error ("function does not return string type");
966 record_international_format (DECL_NAME (decl
),
967 DECL_ASSEMBLER_NAME (decl
),
977 if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
978 || (TREE_CODE (decl
) != FUNCTION_DECL
&& ! DECL_EXTERNAL (decl
)))
979 error_with_decl (decl
,
980 "`%s' defined both normally and as an alias");
981 else if (decl_function_context (decl
) == 0)
985 id
= TREE_VALUE (args
);
986 if (TREE_CODE (id
) != STRING_CST
)
988 error ("alias arg not a string");
991 id
= get_identifier (TREE_STRING_POINTER (id
));
992 /* This counts as a use of the object pointed to. */
995 if (TREE_CODE (decl
) == FUNCTION_DECL
)
996 DECL_INITIAL (decl
) = error_mark_node
;
998 DECL_EXTERNAL (decl
) = 0;
999 assemble_alias (decl
, id
);
1002 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
1005 case A_NO_CHECK_MEMORY_USAGE
:
1006 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1008 error_with_decl (decl
,
1009 "`%s' attribute applies only to functions",
1010 IDENTIFIER_POINTER (name
));
1012 else if (DECL_INITIAL (decl
))
1014 error_with_decl (decl
,
1015 "can't set `%s' attribute after definition",
1016 IDENTIFIER_POINTER (name
));
1019 DECL_NO_CHECK_MEMORY_USAGE (decl
) = 1;
1022 case A_NO_INSTRUMENT_FUNCTION
:
1023 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1025 error_with_decl (decl
,
1026 "`%s' attribute applies only to functions",
1027 IDENTIFIER_POINTER (name
));
1029 else if (DECL_INITIAL (decl
))
1031 error_with_decl (decl
,
1032 "can't set `%s' attribute after definition",
1033 IDENTIFIER_POINTER (name
));
1036 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
1039 case A_NO_LIMIT_STACK
:
1040 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1042 error_with_decl (decl
,
1043 "`%s' attribute applies only to functions",
1044 IDENTIFIER_POINTER (name
));
1046 else if (DECL_INITIAL (decl
))
1048 error_with_decl (decl
,
1049 "can't set `%s' attribute after definition",
1050 IDENTIFIER_POINTER (name
));
1053 DECL_NO_LIMIT_STACK (decl
) = 1;
1059 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1060 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1062 The head of the declspec list is stored in DECLSPECS.
1063 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1065 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1066 the list elements. We drop the containing TREE_LIST nodes and link the
1067 resulting attributes together the way decl_attributes expects them. */
1070 split_specs_attrs (specs_attrs
, declspecs
, prefix_attributes
)
1072 tree
*declspecs
, *prefix_attributes
;
1074 tree t
, s
, a
, next
, specs
, attrs
;
1076 /* This can happen after an __extension__ in pedantic mode. */
1077 if (specs_attrs
!= NULL_TREE
1078 && TREE_CODE (specs_attrs
) == INTEGER_CST
)
1080 *declspecs
= NULL_TREE
;
1081 *prefix_attributes
= NULL_TREE
;
1085 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1086 if (specs_attrs
!= NULL_TREE
1087 && TREE_CODE (specs_attrs
) != TREE_LIST
)
1089 *declspecs
= specs_attrs
;
1090 *prefix_attributes
= NULL_TREE
;
1094 /* Remember to keep the lists in the same order, element-wise. */
1096 specs
= s
= NULL_TREE
;
1097 attrs
= a
= NULL_TREE
;
1098 for (t
= specs_attrs
; t
; t
= next
)
1100 next
= TREE_CHAIN (t
);
1101 /* Declspecs have a non-NULL TREE_VALUE. */
1102 if (TREE_VALUE (t
) != NULL_TREE
)
1104 if (specs
== NULL_TREE
)
1114 if (attrs
== NULL_TREE
)
1115 attrs
= a
= TREE_PURPOSE (t
);
1118 TREE_CHAIN (a
) = TREE_PURPOSE (t
);
1119 a
= TREE_PURPOSE (t
);
1121 /* More attrs can be linked here, move A to the end. */
1122 while (TREE_CHAIN (a
) != NULL_TREE
)
1127 /* Terminate the lists. */
1129 TREE_CHAIN (s
) = NULL_TREE
;
1131 TREE_CHAIN (a
) = NULL_TREE
;
1135 *prefix_attributes
= attrs
;
1138 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1139 This function is used by the parser when a rule will accept attributes
1140 in a particular position, but we don't want to support that just yet.
1142 A warning is issued for every ignored attribute. */
1145 strip_attrs (specs_attrs
)
1150 split_specs_attrs (specs_attrs
, &specs
, &attrs
);
1154 warning ("`%s' attribute ignored",
1155 IDENTIFIER_POINTER (TREE_PURPOSE (attrs
)));
1156 attrs
= TREE_CHAIN (attrs
);
1162 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1163 a parameter list. */
1165 #define T_I &integer_type_node
1166 #define T_L &long_integer_type_node
1167 #define T_LL &long_long_integer_type_node
1168 #define T_S &short_integer_type_node
1169 #define T_UI &unsigned_type_node
1170 #define T_UL &long_unsigned_type_node
1171 #define T_ULL &long_long_unsigned_type_node
1172 #define T_US &short_unsigned_type_node
1173 #define T_F &float_type_node
1174 #define T_D &double_type_node
1175 #define T_LD &long_double_type_node
1176 #define T_C &char_type_node
1177 #define T_UC &unsigned_char_type_node
1178 #define T_V &void_type_node
1179 #define T_W &wchar_type_node
1180 #define T_ST &sizetype
1183 const char *format_chars
;
1185 /* Type of argument if no length modifier is used. */
1187 /* Type of argument if length modifier for shortening to byte is used.
1188 If NULL, then this modifier is not allowed. */
1190 /* Type of argument if length modifier for shortening is used.
1191 If NULL, then this modifier is not allowed. */
1193 /* Type of argument if length modifier `l' is used.
1194 If NULL, then this modifier is not allowed. */
1196 /* Type of argument if length modifier `q' or `ll' is used.
1197 If NULL, then this modifier is not allowed. */
1199 /* Type of argument if length modifier `L' is used.
1200 If NULL, then this modifier is not allowed. */
1202 /* Type of argument if length modifiers 'z' or `Z' is used.
1203 If NULL, then this modifier is not allowed. */
1205 /* List of other modifier characters allowed with these options. */
1206 const char *flag_chars
;
1209 static format_char_info print_char_table
[] = {
1210 { "di", 0, T_I
, T_I
, T_I
, T_L
, T_LL
, T_LL
, T_ST
, "-wp0 +" },
1211 { "oxX", 0, T_UI
, T_UI
, T_UI
, T_UL
, T_ULL
, T_ULL
, T_ST
, "-wp0#" },
1212 { "u", 0, T_UI
, T_UI
, T_UI
, T_UL
, T_ULL
, T_ULL
, T_ST
, "-wp0" },
1213 /* A GNU extension. */
1214 { "m", 0, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-wp" },
1215 { "feEgGaA", 0, T_D
, NULL
, NULL
, NULL
, NULL
, T_LD
, NULL
, "-wp0 +#" },
1216 { "c", 0, T_I
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "-w" },
1217 { "C", 0, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-w" },
1218 { "s", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "-wp" },
1219 { "S", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-wp" },
1220 { "p", 1, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-w" },
1221 { "n", 1, T_I
, NULL
, T_S
, T_L
, T_LL
, NULL
, NULL
, "" },
1222 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1225 static format_char_info scan_char_table
[] = {
1226 { "di", 1, T_I
, T_C
, T_S
, T_L
, T_LL
, T_LL
, NULL
, "*" },
1227 { "ouxX", 1, T_UI
, T_UC
, T_US
, T_UL
, T_ULL
, T_ULL
, NULL
, "*" },
1228 { "efgEGaA", 1, T_F
, NULL
, NULL
, T_D
, NULL
, T_LD
, NULL
, "*" },
1229 { "c", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "*" },
1230 { "s", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "*a" },
1231 { "[", 1, T_C
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*a" },
1232 { "C", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*" },
1233 { "S", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*a" },
1234 { "p", 2, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*" },
1235 { "n", 1, T_I
, T_C
, T_S
, T_L
, T_LL
, NULL
, NULL
, "" },
1236 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1239 /* Handle format characters recognized by glibc's strftime.c.
1240 '2' - MUST do years as only two digits
1241 '3' - MAY do years as only two digits (depending on locale)
1242 'E' - E modifier is acceptable
1243 'O' - O modifier is acceptable to Standard C
1244 'o' - O modifier is acceptable as a GNU extension
1245 'G' - other GNU extensions */
1247 static format_char_info time_char_table
[] = {
1248 { "y", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2EO-_0w" },
1249 { "D", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2" },
1250 { "g", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2O-_0w" },
1251 { "cx", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "3E" },
1252 { "%RTXnrt", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "" },
1253 { "P", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "G" },
1254 { "HIMSUWdemw", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0Ow" },
1255 { "Vju", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0Oow" },
1256 { "Gklsz", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0OGw" },
1257 { "ABZa", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "^#" },
1258 { "p", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "#" },
1259 { "bh", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "^" },
1260 { "CY", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0EOw" },
1261 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1264 typedef struct function_format_info
1266 struct function_format_info
*next
; /* next structure on the list */
1267 tree name
; /* identifier such as "printf" */
1268 tree assembler_name
; /* optional mangled identifier (for C++) */
1269 enum format_type format_type
; /* type of format (printf, scanf, etc.) */
1270 int format_num
; /* number of format argument */
1271 int first_arg_num
; /* number of first arg (zero for varargs) */
1272 } function_format_info
;
1274 static function_format_info
*function_format_list
= NULL
;
1276 typedef struct international_format_info
1278 struct international_format_info
*next
; /* next structure on the list */
1279 tree name
; /* identifier such as "gettext" */
1280 tree assembler_name
; /* optional mangled identifier (for C++) */
1281 int format_num
; /* number of format argument */
1282 } international_format_info
;
1284 static international_format_info
*international_format_list
= NULL
;
1286 static void check_format_info
PARAMS ((function_format_info
*, tree
));
1288 /* Initialize the table of functions to perform format checking on.
1289 The ANSI functions are always checked (whether <stdio.h> is
1290 included or not), since it is common to call printf without
1291 including <stdio.h>. There shouldn't be a problem with this,
1292 since ANSI reserves these function names whether you include the
1293 header file or not. In any case, the checking is harmless.
1295 Also initialize the name of function that modify the format string for
1296 internationalization purposes. */
1299 init_function_format_info ()
1301 record_function_format (get_identifier ("printf"), NULL_TREE
,
1302 printf_format_type
, 1, 2);
1303 record_function_format (get_identifier ("fprintf"), NULL_TREE
,
1304 printf_format_type
, 2, 3);
1305 record_function_format (get_identifier ("sprintf"), NULL_TREE
,
1306 printf_format_type
, 2, 3);
1307 record_function_format (get_identifier ("scanf"), NULL_TREE
,
1308 scanf_format_type
, 1, 2);
1309 record_function_format (get_identifier ("fscanf"), NULL_TREE
,
1310 scanf_format_type
, 2, 3);
1311 record_function_format (get_identifier ("sscanf"), NULL_TREE
,
1312 scanf_format_type
, 2, 3);
1313 record_function_format (get_identifier ("vprintf"), NULL_TREE
,
1314 printf_format_type
, 1, 0);
1315 record_function_format (get_identifier ("vfprintf"), NULL_TREE
,
1316 printf_format_type
, 2, 0);
1317 record_function_format (get_identifier ("vsprintf"), NULL_TREE
,
1318 printf_format_type
, 2, 0);
1319 record_function_format (get_identifier ("strftime"), NULL_TREE
,
1320 strftime_format_type
, 3, 0);
1322 record_international_format (get_identifier ("gettext"), NULL_TREE
, 1);
1323 record_international_format (get_identifier ("dgettext"), NULL_TREE
, 2);
1324 record_international_format (get_identifier ("dcgettext"), NULL_TREE
, 2);
1327 /* Record information for argument format checking. FUNCTION_IDENT is
1328 the identifier node for the name of the function to check (its decl
1329 need not exist yet).
1330 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
1331 of the argument which is the format control string (starting from 1).
1332 FIRST_ARG_NUM is the number of the first actual argument to check
1333 against the format string, or zero if no checking is not be done
1334 (e.g. for varargs such as vfprintf). */
1337 record_function_format (name
, assembler_name
, format_type
,
1338 format_num
, first_arg_num
)
1340 tree assembler_name
;
1341 enum format_type format_type
;
1345 function_format_info
*info
;
1347 /* Re-use existing structure if it's there. */
1349 for (info
= function_format_list
; info
; info
= info
->next
)
1351 if (info
->name
== name
&& info
->assembler_name
== assembler_name
)
1356 info
= (function_format_info
*) xmalloc (sizeof (function_format_info
));
1357 info
->next
= function_format_list
;
1358 function_format_list
= info
;
1361 info
->assembler_name
= assembler_name
;
1364 info
->format_type
= format_type
;
1365 info
->format_num
= format_num
;
1366 info
->first_arg_num
= first_arg_num
;
1369 /* Record information for the names of function that modify the format
1370 argument to format functions. FUNCTION_IDENT is the identifier node for
1371 the name of the function (its decl need not exist yet) and FORMAT_NUM is
1372 the number of the argument which is the format control string (starting
1376 record_international_format (name
, assembler_name
, format_num
)
1378 tree assembler_name
;
1381 international_format_info
*info
;
1383 /* Re-use existing structure if it's there. */
1385 for (info
= international_format_list
; info
; info
= info
->next
)
1387 if (info
->name
== name
&& info
->assembler_name
== assembler_name
)
1394 = (international_format_info
*)
1395 xmalloc (sizeof (international_format_info
));
1396 info
->next
= international_format_list
;
1397 international_format_list
= info
;
1400 info
->assembler_name
= assembler_name
;
1403 info
->format_num
= format_num
;
1409 warning ("too few arguments for format");
1412 /* Check the argument list of a call to printf, scanf, etc.
1413 NAME is the function identifier.
1414 ASSEMBLER_NAME is the function's assembler identifier.
1415 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1416 PARAMS is the list of argument values. */
1419 check_function_format (name
, assembler_name
, params
)
1421 tree assembler_name
;
1424 function_format_info
*info
;
1426 /* See if this function is a format function. */
1427 for (info
= function_format_list
; info
; info
= info
->next
)
1429 if (info
->assembler_name
1430 ? (info
->assembler_name
== assembler_name
)
1431 : (info
->name
== name
))
1433 /* Yup; check it. */
1434 check_format_info (info
, params
);
1440 /* Check the argument list of a call to printf, scanf, etc.
1441 INFO points to the function_format_info structure.
1442 PARAMS is the list of argument values. */
1445 check_format_info (info
, params
)
1446 function_format_info
*info
;
1451 int suppressed
, wide
, precise
;
1452 int length_char
= 0;
1459 tree first_fillin_param
;
1460 const char *format_chars
;
1461 format_char_info
*fci
= NULL
;
1463 int has_operand_number
= 0;
1465 /* Skip to format argument. If the argument isn't available, there's
1466 no work for us to do; prototype checking will catch the problem. */
1467 for (arg_num
= 1; ; ++arg_num
)
1471 if (arg_num
== info
->format_num
)
1473 params
= TREE_CHAIN (params
);
1475 format_tree
= TREE_VALUE (params
);
1476 params
= TREE_CHAIN (params
);
1477 if (format_tree
== 0)
1480 /* We can only check the format if it's a string constant. */
1481 while (TREE_CODE (format_tree
) == NOP_EXPR
)
1482 format_tree
= TREE_OPERAND (format_tree
, 0); /* strip coercion */
1484 if (TREE_CODE (format_tree
) == CALL_EXPR
1485 && TREE_CODE (TREE_OPERAND (format_tree
, 0)) == ADDR_EXPR
1486 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree
, 0), 0))
1489 tree function
= TREE_OPERAND (TREE_OPERAND (format_tree
, 0), 0);
1491 /* See if this is a call to a known internationalization function
1492 that modifies the format arg. */
1493 international_format_info
*info
;
1495 for (info
= international_format_list
; info
; info
= info
->next
)
1496 if (info
->assembler_name
1497 ? (info
->assembler_name
== DECL_ASSEMBLER_NAME (function
))
1498 : (info
->name
== DECL_NAME (function
)))
1503 for (inner_args
= TREE_OPERAND (format_tree
, 1), i
= 1;
1505 inner_args
= TREE_CHAIN (inner_args
), i
++)
1506 if (i
== info
->format_num
)
1508 format_tree
= TREE_VALUE (inner_args
);
1510 while (TREE_CODE (format_tree
) == NOP_EXPR
)
1511 format_tree
= TREE_OPERAND (format_tree
, 0);
1516 if (integer_zerop (format_tree
))
1518 warning ("null format string");
1521 if (TREE_CODE (format_tree
) != ADDR_EXPR
)
1523 /* The user may get multiple warnings if the supplied argument
1524 isn't even a string pointer. */
1525 /* Functions taking a va_list normally pass a non-literal format
1526 string. These functions typically are declared with
1527 first_arg_num == 0, so avoid warning in those cases. */
1528 if (info
->first_arg_num
!= 0 && warn_format
> 1)
1529 warning ("format not a string literal, argument types not checked");
1532 format_tree
= TREE_OPERAND (format_tree
, 0);
1533 if (TREE_CODE (format_tree
) != STRING_CST
)
1535 /* The user may get multiple warnings if the supplied argument
1536 isn't even a string pointer. */
1537 /* Functions taking a va_list normally pass a non-literal format
1538 string. These functions typically are declared with
1539 first_arg_num == 0, so avoid warning in those cases. */
1540 if (info
->first_arg_num
!= 0 && warn_format
> 1)
1541 warning ("format not a string literal, argument types not checked");
1544 format_chars
= TREE_STRING_POINTER (format_tree
);
1545 format_length
= TREE_STRING_LENGTH (format_tree
);
1546 if (format_length
<= 1)
1547 warning ("zero-length format string");
1548 if (format_chars
[--format_length
] != 0)
1550 warning ("unterminated format string");
1553 /* Skip to first argument to check. */
1554 while (arg_num
+ 1 < info
->first_arg_num
)
1558 params
= TREE_CHAIN (params
);
1562 first_fillin_param
= params
;
1566 if (*format_chars
== 0)
1568 if (format_chars
- TREE_STRING_POINTER (format_tree
) != format_length
)
1569 warning ("embedded `\\0' in format");
1570 if (info
->first_arg_num
!= 0 && params
!= 0 && ! has_operand_number
)
1571 warning ("too many arguments for format");
1574 if (*format_chars
++ != '%')
1576 if (*format_chars
== 0)
1578 warning ("spurious trailing `%%' in format");
1581 if (*format_chars
== '%')
1587 suppressed
= wide
= precise
= FALSE
;
1588 if (info
->format_type
== scanf_format_type
)
1590 suppressed
= *format_chars
== '*';
1593 while (ISDIGIT (*format_chars
))
1596 else if (info
->format_type
== strftime_format_type
)
1598 while (*format_chars
!= 0 && index ("_-0^#", *format_chars
) != 0)
1601 warning ("ANSI C does not support the strftime `%c' flag",
1603 if (index (flag_chars
, *format_chars
) != 0)
1605 warning ("repeated `%c' flag in format",
1611 i
= strlen (flag_chars
);
1612 flag_chars
[i
++] = *format_chars
++;
1616 while (ISDIGIT ((unsigned char) *format_chars
))
1621 if (wide
&& pedantic
)
1622 warning ("ANSI C does not support strftime format width");
1623 if (*format_chars
== 'E' || *format_chars
== 'O')
1625 i
= strlen (flag_chars
);
1626 flag_chars
[i
++] = *format_chars
++;
1628 if (*format_chars
== 'E' || *format_chars
== 'O')
1630 warning ("multiple E/O modifiers in format");
1631 while (*format_chars
== 'E' || *format_chars
== 'O')
1636 else if (info
->format_type
== printf_format_type
)
1638 /* See if we have a number followed by a dollar sign. If we do,
1639 it is an operand number, so set PARAMS to that operand. */
1640 if (*format_chars
>= '0' && *format_chars
<= '9')
1642 const char *p
= format_chars
;
1644 while (*p
>= '0' && *p
++ <= '9')
1649 int opnum
= atoi (format_chars
);
1651 params
= first_fillin_param
;
1652 format_chars
= p
+ 1;
1653 has_operand_number
= 1;
1655 for (i
= 1; i
< opnum
&& params
!= 0; i
++)
1656 params
= TREE_CHAIN (params
);
1658 if (opnum
== 0 || params
== 0)
1660 warning ("operand number out of range in format");
1666 while (*format_chars
!= 0 && index (" +#0-", *format_chars
) != 0)
1668 if (index (flag_chars
, *format_chars
) != 0)
1669 warning ("repeated `%c' flag in format", *format_chars
++);
1672 i
= strlen (flag_chars
);
1673 flag_chars
[i
++] = *format_chars
++;
1677 /* "If the space and + flags both appear,
1678 the space flag will be ignored." */
1679 if (index (flag_chars
, ' ') != 0
1680 && index (flag_chars
, '+') != 0)
1681 warning ("use of both ` ' and `+' flags in format");
1682 /* "If the 0 and - flags both appear,
1683 the 0 flag will be ignored." */
1684 if (index (flag_chars
, '0') != 0
1685 && index (flag_chars
, '-') != 0)
1686 warning ("use of both `0' and `-' flags in format");
1687 if (*format_chars
== '*')
1690 /* "...a field width...may be indicated by an asterisk.
1691 In this case, an int argument supplies the field width..." */
1698 if (info
->first_arg_num
!= 0)
1700 cur_param
= TREE_VALUE (params
);
1701 params
= TREE_CHAIN (params
);
1703 /* size_t is generally not valid here.
1704 It will work on most machines, because size_t and int
1705 have the same mode. But might as well warn anyway,
1706 since it will fail on other machines. */
1707 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1708 != integer_type_node
)
1710 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1711 != unsigned_type_node
))
1712 warning ("field width is not type int (arg %d)", arg_num
);
1717 while (ISDIGIT (*format_chars
))
1723 if (*format_chars
== '.')
1727 if (*format_chars
!= '*' && !ISDIGIT (*format_chars
))
1728 warning ("`.' not followed by `*' or digit in format");
1729 /* "...a...precision...may be indicated by an asterisk.
1730 In this case, an int argument supplies the...precision." */
1731 if (*format_chars
== '*')
1733 if (info
->first_arg_num
!= 0)
1741 cur_param
= TREE_VALUE (params
);
1742 params
= TREE_CHAIN (params
);
1744 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1745 != integer_type_node
)
1746 warning ("field width is not type int (arg %d)",
1752 while (ISDIGIT (*format_chars
))
1760 if (info
->format_type
!= strftime_format_type
)
1762 if (*format_chars
== 'h' || *format_chars
== 'l')
1763 length_char
= *format_chars
++;
1764 else if (*format_chars
== 'q' || *format_chars
== 'L')
1766 length_char
= *format_chars
++;
1768 warning ("ANSI C does not support the `%c' length modifier",
1771 else if (*format_chars
== 'Z' || *format_chars
== 'z')
1773 length_char
= *format_chars
++;
1774 if (pedantic
&& (length_char
== 'Z' || !flag_isoc99
))
1775 warning ("ANSI C does not support the `%c' length modifier",
1780 if (length_char
== 'l' && *format_chars
== 'l')
1782 length_char
= 'q', format_chars
++;
1783 if (pedantic
&& !flag_isoc99
)
1784 warning ("ANSI C does not support the `ll' length modifier");
1786 else if (length_char
== 'h' && *format_chars
== 'h')
1788 length_char
= 'H', format_chars
++;
1789 if (pedantic
&& !flag_isoc99
)
1790 warning ("ANSI C does not support the `hh' length modifier");
1792 if (*format_chars
== 'a' && info
->format_type
== scanf_format_type
)
1794 if (format_chars
[1] == 's' || format_chars
[1] == 'S'
1795 || format_chars
[1] == '[')
1797 /* `a' is used as a flag. */
1802 if (suppressed
&& length_char
!= 0)
1803 warning ("use of `*' and `%c' together in format", length_char
);
1805 format_char
= *format_chars
;
1806 if (format_char
== 0
1807 || (info
->format_type
!= strftime_format_type
&& format_char
== '%'))
1809 warning ("conversion lacks type at end of format");
1812 /* The m, C, and S formats are GNU extensions. */
1813 if (pedantic
&& info
->format_type
!= strftime_format_type
1814 && (format_char
== 'm' || format_char
== 'C' || format_char
== 'S'))
1815 warning ("ANSI C does not support the `%c' format", format_char
);
1816 /* The a and A formats are C99 extensions. */
1817 if (pedantic
&& info
->format_type
!= strftime_format_type
1818 && (format_char
== 'a' || format_char
== 'A')
1820 warning ("ANSI C does not support the `%c' format", format_char
);
1822 switch (info
->format_type
)
1824 case printf_format_type
:
1825 fci
= print_char_table
;
1827 case scanf_format_type
:
1828 fci
= scan_char_table
;
1830 case strftime_format_type
:
1831 fci
= time_char_table
;
1836 while (fci
->format_chars
!= 0
1837 && index (fci
->format_chars
, format_char
) == 0)
1839 if (fci
->format_chars
== 0)
1841 if (ISGRAPH(format_char
))
1842 warning ("unknown conversion type character `%c' in format",
1845 warning ("unknown conversion type character 0x%x in format",
1851 if (index (fci
->flag_chars
, 'G') != 0)
1852 warning ("ANSI C does not support `%%%c'", format_char
);
1853 if (index (fci
->flag_chars
, 'o') != 0
1854 && index (flag_chars
, 'O') != 0)
1855 warning ("ANSI C does not support `%%O%c'", format_char
);
1857 if (wide
&& index (fci
->flag_chars
, 'w') == 0)
1858 warning ("width used with `%c' format", format_char
);
1859 if (index (fci
->flag_chars
, '2') != 0)
1860 warning ("`%%%c' yields only last 2 digits of year", format_char
);
1861 else if (index (fci
->flag_chars
, '3') != 0)
1862 warning ("`%%%c' yields only last 2 digits of year in some locales",
1864 if (precise
&& index (fci
->flag_chars
, 'p') == 0)
1865 warning ("precision used with `%c' format", format_char
);
1866 if (aflag
&& index (fci
->flag_chars
, 'a') == 0)
1868 warning ("`a' flag used with `%c' format", format_char
);
1869 /* To simplify the following code. */
1872 /* The a flag is a GNU extension. */
1873 else if (pedantic
&& aflag
)
1874 warning ("ANSI C does not support the `a' flag");
1875 if (info
->format_type
== scanf_format_type
&& format_char
== '[')
1877 /* Skip over scan set, in case it happens to have '%' in it. */
1878 if (*format_chars
== '^')
1880 /* Find closing bracket; if one is hit immediately, then
1881 it's part of the scan set rather than a terminator. */
1882 if (*format_chars
== ']')
1884 while (*format_chars
&& *format_chars
!= ']')
1886 if (*format_chars
!= ']')
1887 /* The end of the format string was reached. */
1888 warning ("no closing `]' for `%%[' format");
1892 if (index (fci
->flag_chars
, '*') == 0)
1893 warning ("suppression of `%c' conversion in format", format_char
);
1896 for (i
= 0; flag_chars
[i
] != 0; ++i
)
1898 if (index (fci
->flag_chars
, flag_chars
[i
]) == 0)
1899 warning ("flag `%c' used with type `%c'",
1900 flag_chars
[i
], format_char
);
1902 if (info
->format_type
== strftime_format_type
)
1904 if (precise
&& index (flag_chars
, '0') != 0
1905 && (format_char
== 'd' || format_char
== 'i'
1906 || format_char
== 'o' || format_char
== 'u'
1907 || format_char
== 'x' || format_char
== 'X'))
1908 warning ("`0' flag ignored with precision specifier and `%c' format",
1910 switch (length_char
)
1912 default: wanted_type
= fci
->nolen
? *(fci
->nolen
) : 0; break;
1913 case 'H': wanted_type
= fci
->hhlen
? *(fci
->hhlen
) : 0; break;
1914 case 'h': wanted_type
= fci
->hlen
? *(fci
->hlen
) : 0; break;
1915 case 'l': wanted_type
= fci
->llen
? *(fci
->llen
) : 0; break;
1916 case 'q': wanted_type
= fci
->qlen
? *(fci
->qlen
) : 0; break;
1917 case 'L': wanted_type
= fci
->bigllen
? *(fci
->bigllen
) : 0; break;
1918 case 'z': case 'Z': wanted_type
= fci
->zlen
? *fci
->zlen
: 0; break;
1920 if (wanted_type
== 0)
1921 warning ("use of `%c' length character with `%c' type character",
1922 length_char
, format_char
);
1924 /* Finally. . .check type of argument against desired type! */
1925 if (info
->first_arg_num
== 0)
1927 if (fci
->pointer_count
== 0 && wanted_type
== void_type_node
)
1928 /* This specifier takes no argument. */
1935 cur_param
= TREE_VALUE (params
);
1936 params
= TREE_CHAIN (params
);
1938 cur_type
= TREE_TYPE (cur_param
);
1940 STRIP_NOPS (cur_param
);
1942 /* Check the types of any additional pointer arguments
1943 that precede the "real" argument. */
1944 for (i
= 0; i
< fci
->pointer_count
+ aflag
; ++i
)
1946 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
1948 cur_type
= TREE_TYPE (cur_type
);
1950 if (cur_param
!= 0 && TREE_CODE (cur_param
) == ADDR_EXPR
)
1951 cur_param
= TREE_OPERAND (cur_param
, 0);
1957 if (TREE_CODE (cur_type
) != ERROR_MARK
)
1959 if (fci
->pointer_count
+ aflag
== 1)
1960 warning ("format argument is not a pointer (arg %d)", arg_num
);
1962 warning ("format argument is not a pointer to a pointer (arg %d)", arg_num
);
1967 /* See if this is an attempt to write into a const type with
1968 scanf or with printf "%n". */
1969 if ((info
->format_type
== scanf_format_type
1970 || (info
->format_type
== printf_format_type
1971 && format_char
== 'n'))
1972 && i
== fci
->pointer_count
+ aflag
1974 && TREE_CODE (cur_type
) != ERROR_MARK
1975 && (TYPE_READONLY (cur_type
)
1977 && (TREE_CODE_CLASS (TREE_CODE (cur_param
)) == 'c'
1978 || (DECL_P (cur_param
) && TREE_READONLY (cur_param
))))))
1979 warning ("writing into constant object (arg %d)", arg_num
);
1981 /* Check the type of the "real" argument, if there's a type we want. */
1982 if (i
== fci
->pointer_count
+ aflag
&& wanted_type
!= 0
1983 && TREE_CODE (cur_type
) != ERROR_MARK
1984 && wanted_type
!= TYPE_MAIN_VARIANT (cur_type
)
1985 /* If we want `void *', allow any pointer type.
1986 (Anything else would already have got a warning.) */
1987 && ! (wanted_type
== void_type_node
1988 && fci
->pointer_count
> 0)
1989 /* Don't warn about differences merely in signedness. */
1990 && !(TREE_CODE (wanted_type
) == INTEGER_TYPE
1991 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type
)) == INTEGER_TYPE
1992 && (TREE_UNSIGNED (wanted_type
)
1993 ? wanted_type
== (cur_type
= unsigned_type (cur_type
))
1994 : wanted_type
== (cur_type
= signed_type (cur_type
))))
1995 /* Likewise, "signed char", "unsigned char" and "char" are
1996 equivalent but the above test won't consider them equivalent. */
1997 && ! (wanted_type
== char_type_node
1998 && (TYPE_MAIN_VARIANT (cur_type
) == signed_char_type_node
1999 || TYPE_MAIN_VARIANT (cur_type
) == unsigned_char_type_node
)))
2001 register const char *this;
2002 register const char *that
;
2004 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type
)));
2006 if (TREE_CODE (cur_type
) != ERROR_MARK
2007 && TYPE_NAME (cur_type
) != 0
2008 && TREE_CODE (cur_type
) != INTEGER_TYPE
2009 && !(TREE_CODE (cur_type
) == POINTER_TYPE
2010 && TREE_CODE (TREE_TYPE (cur_type
)) == INTEGER_TYPE
))
2012 if (TREE_CODE (TYPE_NAME (cur_type
)) == TYPE_DECL
2013 && DECL_NAME (TYPE_NAME (cur_type
)) != 0)
2014 that
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type
)));
2016 that
= IDENTIFIER_POINTER (TYPE_NAME (cur_type
));
2019 /* A nameless type can't possibly match what the format wants.
2020 So there will be a warning for it.
2021 Make up a string to describe vaguely what it is. */
2024 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
2027 that
= "different type";
2030 /* Make the warning better in case of mismatch of int vs long. */
2031 if (TREE_CODE (cur_type
) == INTEGER_TYPE
2032 && TREE_CODE (wanted_type
) == INTEGER_TYPE
2033 && TYPE_PRECISION (cur_type
) == TYPE_PRECISION (wanted_type
)
2034 && TYPE_NAME (cur_type
) != 0
2035 && TREE_CODE (TYPE_NAME (cur_type
)) == TYPE_DECL
)
2036 that
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type
)));
2038 if (strcmp (this, that
) != 0)
2039 warning ("%s format, %s arg (arg %d)", this, that
, arg_num
);
2044 /* Print a warning if a constant expression had overflow in folding.
2045 Invoke this function on every expression that the language
2046 requires to be a constant expression.
2047 Note the ANSI C standard says it is erroneous for a
2048 constant expression to overflow. */
2051 constant_expression_warning (value
)
2054 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
2055 || TREE_CODE (value
) == COMPLEX_CST
)
2056 && TREE_CONSTANT_OVERFLOW (value
) && pedantic
)
2057 pedwarn ("overflow in constant expression");
2060 /* Print a warning if an expression had overflow in folding.
2061 Invoke this function on every expression that
2062 (1) appears in the source code, and
2063 (2) might be a constant expression that overflowed, and
2064 (3) is not already checked by convert_and_check;
2065 however, do not invoke this function on operands of explicit casts. */
2068 overflow_warning (value
)
2071 if ((TREE_CODE (value
) == INTEGER_CST
2072 || (TREE_CODE (value
) == COMPLEX_CST
2073 && TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
))
2074 && TREE_OVERFLOW (value
))
2076 TREE_OVERFLOW (value
) = 0;
2077 if (skip_evaluation
== 0)
2078 warning ("integer overflow in expression");
2080 else if ((TREE_CODE (value
) == REAL_CST
2081 || (TREE_CODE (value
) == COMPLEX_CST
2082 && TREE_CODE (TREE_REALPART (value
)) == REAL_CST
))
2083 && TREE_OVERFLOW (value
))
2085 TREE_OVERFLOW (value
) = 0;
2086 if (skip_evaluation
== 0)
2087 warning ("floating point overflow in expression");
2091 /* Print a warning if a large constant is truncated to unsigned,
2092 or if -Wconversion is used and a constant < 0 is converted to unsigned.
2093 Invoke this function on every expression that might be implicitly
2094 converted to an unsigned type. */
2097 unsigned_conversion_warning (result
, operand
)
2098 tree result
, operand
;
2100 if (TREE_CODE (operand
) == INTEGER_CST
2101 && TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
2102 && TREE_UNSIGNED (TREE_TYPE (result
))
2103 && skip_evaluation
== 0
2104 && !int_fits_type_p (operand
, TREE_TYPE (result
)))
2106 if (!int_fits_type_p (operand
, signed_type (TREE_TYPE (result
))))
2107 /* This detects cases like converting -129 or 256 to unsigned char. */
2108 warning ("large integer implicitly truncated to unsigned type");
2109 else if (warn_conversion
)
2110 warning ("negative integer implicitly converted to unsigned type");
2114 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2115 Invoke this function on every expression that is converted implicitly,
2116 i.e. because of language rules and not because of an explicit cast. */
2119 convert_and_check (type
, expr
)
2122 tree t
= convert (type
, expr
);
2123 if (TREE_CODE (t
) == INTEGER_CST
)
2125 if (TREE_OVERFLOW (t
))
2127 TREE_OVERFLOW (t
) = 0;
2129 /* Do not diagnose overflow in a constant expression merely
2130 because a conversion overflowed. */
2131 TREE_CONSTANT_OVERFLOW (t
) = TREE_CONSTANT_OVERFLOW (expr
);
2133 /* No warning for converting 0x80000000 to int. */
2134 if (!(TREE_UNSIGNED (type
) < TREE_UNSIGNED (TREE_TYPE (expr
))
2135 && TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
2136 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (expr
))))
2137 /* If EXPR fits in the unsigned version of TYPE,
2138 don't warn unless pedantic. */
2140 || TREE_UNSIGNED (type
)
2141 || ! int_fits_type_p (expr
, unsigned_type (type
)))
2142 && skip_evaluation
== 0)
2143 warning ("overflow in implicit constant conversion");
2146 unsigned_conversion_warning (t
, expr
);
2152 c_expand_expr_stmt (expr
)
2155 /* Do default conversion if safe and possibly important,
2156 in case within ({...}). */
2157 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
2158 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
2159 expr
= default_conversion (expr
);
2161 if (TREE_TYPE (expr
) != error_mark_node
2162 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr
))
2163 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
2164 error ("expression statement has incomplete type");
2166 expand_expr_stmt (expr
);
2169 /* Validate the expression after `case' and apply default promotions. */
2172 check_case_value (value
)
2175 if (value
== NULL_TREE
)
2178 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2179 STRIP_TYPE_NOPS (value
);
2181 if (TREE_CODE (value
) != INTEGER_CST
2182 && value
!= error_mark_node
)
2184 error ("case label does not reduce to an integer constant");
2185 value
= error_mark_node
;
2188 /* Promote char or short to int. */
2189 value
= default_conversion (value
);
2191 constant_expression_warning (value
);
2196 /* Return an integer type with BITS bits of precision,
2197 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2200 type_for_size (bits
, unsignedp
)
2204 if (bits
== TYPE_PRECISION (integer_type_node
))
2205 return unsignedp
? unsigned_type_node
: integer_type_node
;
2207 if (bits
== TYPE_PRECISION (signed_char_type_node
))
2208 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2210 if (bits
== TYPE_PRECISION (short_integer_type_node
))
2211 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2213 if (bits
== TYPE_PRECISION (long_integer_type_node
))
2214 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2216 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
2217 return (unsignedp
? long_long_unsigned_type_node
2218 : long_long_integer_type_node
);
2220 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
2221 return (unsignedp
? widest_unsigned_literal_type_node
2222 : widest_integer_literal_type_node
);
2224 if (bits
<= TYPE_PRECISION (intQI_type_node
))
2225 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2227 if (bits
<= TYPE_PRECISION (intHI_type_node
))
2228 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2230 if (bits
<= TYPE_PRECISION (intSI_type_node
))
2231 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2233 if (bits
<= TYPE_PRECISION (intDI_type_node
))
2234 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2239 /* Return a data type that has machine mode MODE.
2240 If the mode is an integer,
2241 then UNSIGNEDP selects between signed and unsigned types. */
2244 type_for_mode (mode
, unsignedp
)
2245 enum machine_mode mode
;
2248 if (mode
== TYPE_MODE (integer_type_node
))
2249 return unsignedp
? unsigned_type_node
: integer_type_node
;
2251 if (mode
== TYPE_MODE (signed_char_type_node
))
2252 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2254 if (mode
== TYPE_MODE (short_integer_type_node
))
2255 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2257 if (mode
== TYPE_MODE (long_integer_type_node
))
2258 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2260 if (mode
== TYPE_MODE (long_long_integer_type_node
))
2261 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2263 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
2264 return unsignedp
? widest_unsigned_literal_type_node
2265 : widest_integer_literal_type_node
;
2267 if (mode
== TYPE_MODE (intQI_type_node
))
2268 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2270 if (mode
== TYPE_MODE (intHI_type_node
))
2271 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2273 if (mode
== TYPE_MODE (intSI_type_node
))
2274 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2276 if (mode
== TYPE_MODE (intDI_type_node
))
2277 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2279 #if HOST_BITS_PER_WIDE_INT >= 64
2280 if (mode
== TYPE_MODE (intTI_type_node
))
2281 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2284 if (mode
== TYPE_MODE (float_type_node
))
2285 return float_type_node
;
2287 if (mode
== TYPE_MODE (double_type_node
))
2288 return double_type_node
;
2290 if (mode
== TYPE_MODE (long_double_type_node
))
2291 return long_double_type_node
;
2293 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
2294 return build_pointer_type (char_type_node
);
2296 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
2297 return build_pointer_type (integer_type_node
);
2302 /* Return an unsigned type the same as TYPE in other respects. */
2304 unsigned_type (type
)
2307 tree type1
= TYPE_MAIN_VARIANT (type
);
2308 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
2309 return unsigned_char_type_node
;
2310 if (type1
== integer_type_node
)
2311 return unsigned_type_node
;
2312 if (type1
== short_integer_type_node
)
2313 return short_unsigned_type_node
;
2314 if (type1
== long_integer_type_node
)
2315 return long_unsigned_type_node
;
2316 if (type1
== long_long_integer_type_node
)
2317 return long_long_unsigned_type_node
;
2318 if (type1
== widest_integer_literal_type_node
)
2319 return widest_unsigned_literal_type_node
;
2320 #if HOST_BITS_PER_WIDE_INT >= 64
2321 if (type1
== intTI_type_node
)
2322 return unsigned_intTI_type_node
;
2324 if (type1
== intDI_type_node
)
2325 return unsigned_intDI_type_node
;
2326 if (type1
== intSI_type_node
)
2327 return unsigned_intSI_type_node
;
2328 if (type1
== intHI_type_node
)
2329 return unsigned_intHI_type_node
;
2330 if (type1
== intQI_type_node
)
2331 return unsigned_intQI_type_node
;
2333 return signed_or_unsigned_type (1, type
);
2336 /* Return a signed type the same as TYPE in other respects. */
2342 tree type1
= TYPE_MAIN_VARIANT (type
);
2343 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
2344 return signed_char_type_node
;
2345 if (type1
== unsigned_type_node
)
2346 return integer_type_node
;
2347 if (type1
== short_unsigned_type_node
)
2348 return short_integer_type_node
;
2349 if (type1
== long_unsigned_type_node
)
2350 return long_integer_type_node
;
2351 if (type1
== long_long_unsigned_type_node
)
2352 return long_long_integer_type_node
;
2353 if (type1
== widest_unsigned_literal_type_node
)
2354 return widest_integer_literal_type_node
;
2355 #if HOST_BITS_PER_WIDE_INT >= 64
2356 if (type1
== unsigned_intTI_type_node
)
2357 return intTI_type_node
;
2359 if (type1
== unsigned_intDI_type_node
)
2360 return intDI_type_node
;
2361 if (type1
== unsigned_intSI_type_node
)
2362 return intSI_type_node
;
2363 if (type1
== unsigned_intHI_type_node
)
2364 return intHI_type_node
;
2365 if (type1
== unsigned_intQI_type_node
)
2366 return intQI_type_node
;
2368 return signed_or_unsigned_type (0, type
);
2371 /* Return a type the same as TYPE except unsigned or
2372 signed according to UNSIGNEDP. */
2375 signed_or_unsigned_type (unsignedp
, type
)
2379 if (! INTEGRAL_TYPE_P (type
)
2380 || TREE_UNSIGNED (type
) == unsignedp
)
2383 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
2384 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2385 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
2386 return unsignedp
? unsigned_type_node
: integer_type_node
;
2387 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
2388 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2389 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
2390 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2391 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
2392 return (unsignedp
? long_long_unsigned_type_node
2393 : long_long_integer_type_node
);
2394 if (TYPE_PRECISION (type
) == TYPE_PRECISION (widest_integer_literal_type_node
))
2395 return (unsignedp
? widest_unsigned_literal_type_node
2396 : widest_integer_literal_type_node
);
2400 /* Return the minimum number of bits needed to represent VALUE in a
2401 signed or unsigned type, UNSIGNEDP says which. */
2404 min_precision (value
, unsignedp
)
2410 /* If the value is negative, compute its negative minus 1. The latter
2411 adjustment is because the absolute value of the largest negative value
2412 is one larger than the largest positive value. This is equivalent to
2413 a bit-wise negation, so use that operation instead. */
2415 if (tree_int_cst_sgn (value
) < 0)
2416 value
= fold (build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
));
2418 /* Return the number of bits needed, taking into account the fact
2419 that we need one more bit for a signed than unsigned type. */
2421 if (integer_zerop (value
))
2424 log
= tree_floor_log2 (value
);
2426 return log
+ 1 + ! unsignedp
;
2429 /* Print an error message for invalid operands to arith operation CODE.
2430 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2433 binary_op_error (code
)
2434 enum tree_code code
;
2436 register const char *opname
;
2441 error ("invalid truth-value expression");
2445 opname
= "+"; break;
2447 opname
= "-"; break;
2449 opname
= "*"; break;
2451 opname
= "max"; break;
2453 opname
= "min"; break;
2455 opname
= "=="; break;
2457 opname
= "!="; break;
2459 opname
= "<="; break;
2461 opname
= ">="; break;
2463 opname
= "<"; break;
2465 opname
= ">"; break;
2467 opname
= "<<"; break;
2469 opname
= ">>"; break;
2470 case TRUNC_MOD_EXPR
:
2471 case FLOOR_MOD_EXPR
:
2472 opname
= "%"; break;
2473 case TRUNC_DIV_EXPR
:
2474 case FLOOR_DIV_EXPR
:
2475 opname
= "/"; break;
2477 opname
= "&"; break;
2479 opname
= "|"; break;
2480 case TRUTH_ANDIF_EXPR
:
2481 opname
= "&&"; break;
2482 case TRUTH_ORIF_EXPR
:
2483 opname
= "||"; break;
2485 opname
= "^"; break;
2488 opname
= "rotate"; break;
2490 opname
= "unknown"; break;
2492 error ("invalid operands to binary %s", opname
);
2495 /* Subroutine of build_binary_op, used for comparison operations.
2496 See if the operands have both been converted from subword integer types
2497 and, if so, perhaps change them both back to their original type.
2498 This function is also responsible for converting the two operands
2499 to the proper common type for comparison.
2501 The arguments of this function are all pointers to local variables
2502 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2503 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2505 If this function returns nonzero, it means that the comparison has
2506 a constant value. What this function returns is an expression for
2510 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
2511 tree
*op0_ptr
, *op1_ptr
;
2513 enum tree_code
*rescode_ptr
;
2516 tree op0
= *op0_ptr
;
2517 tree op1
= *op1_ptr
;
2518 int unsignedp0
, unsignedp1
;
2520 tree primop0
, primop1
;
2521 enum tree_code code
= *rescode_ptr
;
2523 /* Throw away any conversions to wider types
2524 already present in the operands. */
2526 primop0
= get_narrower (op0
, &unsignedp0
);
2527 primop1
= get_narrower (op1
, &unsignedp1
);
2529 /* Handle the case that OP0 does not *contain* a conversion
2530 but it *requires* conversion to FINAL_TYPE. */
2532 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
2533 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
2534 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
2535 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
2537 /* If one of the operands must be floated, we cannot optimize. */
2538 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
2539 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
2541 /* If first arg is constant, swap the args (changing operation
2542 so value is preserved), for canonicalization. Don't do this if
2543 the second arg is 0. */
2545 if (TREE_CONSTANT (primop0
)
2546 && ! integer_zerop (primop1
) && ! real_zerop (primop1
))
2548 register tree tem
= primop0
;
2549 register int temi
= unsignedp0
;
2557 unsignedp0
= unsignedp1
;
2580 *rescode_ptr
= code
;
2583 /* If comparing an integer against a constant more bits wide,
2584 maybe we can deduce a value of 1 or 0 independent of the data.
2585 Or else truncate the constant now
2586 rather than extend the variable at run time.
2588 This is only interesting if the constant is the wider arg.
2589 Also, it is not safe if the constant is unsigned and the
2590 variable arg is signed, since in this case the variable
2591 would be sign-extended and then regarded as unsigned.
2592 Our technique fails in this case because the lowest/highest
2593 possible unsigned results don't follow naturally from the
2594 lowest/highest possible values of the variable operand.
2595 For just EQ_EXPR and NE_EXPR there is another technique that
2596 could be used: see if the constant can be faithfully represented
2597 in the other operand's type, by truncating it and reextending it
2598 and see if that preserves the constant's value. */
2600 if (!real1
&& !real2
2601 && TREE_CODE (primop1
) == INTEGER_CST
2602 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
2604 int min_gt
, max_gt
, min_lt
, max_lt
;
2605 tree maxval
, minval
;
2606 /* 1 if comparison is nominally unsigned. */
2607 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
2610 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
2612 /* If TYPE is an enumeration, then we need to get its min/max
2613 values from it's underlying integral type, not the enumerated
2615 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
2616 type
= type_for_size (TYPE_PRECISION (type
), unsignedp0
);
2618 maxval
= TYPE_MAX_VALUE (type
);
2619 minval
= TYPE_MIN_VALUE (type
);
2621 if (unsignedp
&& !unsignedp0
)
2622 *restype_ptr
= signed_type (*restype_ptr
);
2624 if (TREE_TYPE (primop1
) != *restype_ptr
)
2625 primop1
= convert (*restype_ptr
, primop1
);
2626 if (type
!= *restype_ptr
)
2628 minval
= convert (*restype_ptr
, minval
);
2629 maxval
= convert (*restype_ptr
, maxval
);
2632 if (unsignedp
&& unsignedp0
)
2634 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
2635 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
2636 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
2637 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
2641 min_gt
= INT_CST_LT (primop1
, minval
);
2642 max_gt
= INT_CST_LT (primop1
, maxval
);
2643 min_lt
= INT_CST_LT (minval
, primop1
);
2644 max_lt
= INT_CST_LT (maxval
, primop1
);
2648 /* This used to be a switch, but Genix compiler can't handle that. */
2649 if (code
== NE_EXPR
)
2651 if (max_lt
|| min_gt
)
2652 val
= boolean_true_node
;
2654 else if (code
== EQ_EXPR
)
2656 if (max_lt
|| min_gt
)
2657 val
= boolean_false_node
;
2659 else if (code
== LT_EXPR
)
2662 val
= boolean_true_node
;
2664 val
= boolean_false_node
;
2666 else if (code
== GT_EXPR
)
2669 val
= boolean_true_node
;
2671 val
= boolean_false_node
;
2673 else if (code
== LE_EXPR
)
2676 val
= boolean_true_node
;
2678 val
= boolean_false_node
;
2680 else if (code
== GE_EXPR
)
2683 val
= boolean_true_node
;
2685 val
= boolean_false_node
;
2688 /* If primop0 was sign-extended and unsigned comparison specd,
2689 we did a signed comparison above using the signed type bounds.
2690 But the comparison we output must be unsigned.
2692 Also, for inequalities, VAL is no good; but if the signed
2693 comparison had *any* fixed result, it follows that the
2694 unsigned comparison just tests the sign in reverse
2695 (positive values are LE, negative ones GE).
2696 So we can generate an unsigned comparison
2697 against an extreme value of the signed type. */
2699 if (unsignedp
&& !unsignedp0
)
2706 primop1
= TYPE_MIN_VALUE (type
);
2712 primop1
= TYPE_MAX_VALUE (type
);
2719 type
= unsigned_type (type
);
2722 if (!max_gt
&& !unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2724 /* This is the case of (char)x >?< 0x80, which people used to use
2725 expecting old C compilers to change the 0x80 into -0x80. */
2726 if (val
== boolean_false_node
)
2727 warning ("comparison is always false due to limited range of data type");
2728 if (val
== boolean_true_node
)
2729 warning ("comparison is always true due to limited range of data type");
2732 if (!min_lt
&& unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2734 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2735 if (val
== boolean_false_node
)
2736 warning ("comparison is always false due to limited range of data type");
2737 if (val
== boolean_true_node
)
2738 warning ("comparison is always true due to limited range of data type");
2743 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2744 if (TREE_SIDE_EFFECTS (primop0
))
2745 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
2749 /* Value is not predetermined, but do the comparison
2750 in the type of the operand that is not constant.
2751 TYPE is already properly set. */
2753 else if (real1
&& real2
2754 && (TYPE_PRECISION (TREE_TYPE (primop0
))
2755 == TYPE_PRECISION (TREE_TYPE (primop1
))))
2756 type
= TREE_TYPE (primop0
);
2758 /* If args' natural types are both narrower than nominal type
2759 and both extend in the same manner, compare them
2760 in the type of the wider arg.
2761 Otherwise must actually extend both to the nominal
2762 common type lest different ways of extending
2764 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2766 else if (unsignedp0
== unsignedp1
&& real1
== real2
2767 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
2768 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
2770 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
2771 type
= signed_or_unsigned_type (unsignedp0
2772 || TREE_UNSIGNED (*restype_ptr
),
2774 /* Make sure shorter operand is extended the right way
2775 to match the longer operand. */
2776 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
2778 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
2783 /* Here we must do the comparison on the nominal type
2784 using the args exactly as we received them. */
2785 type
= *restype_ptr
;
2789 if (!real1
&& !real2
&& integer_zerop (primop1
)
2790 && TREE_UNSIGNED (*restype_ptr
))
2796 /* All unsigned values are >= 0, so we warn if extra warnings
2797 are requested. However, if OP0 is a constant that is
2798 >= 0, the signedness of the comparison isn't an issue,
2799 so suppress the warning. */
2801 && ! (TREE_CODE (primop0
) == INTEGER_CST
2802 && ! TREE_OVERFLOW (convert (signed_type (type
),
2804 warning ("comparison of unsigned expression >= 0 is always true");
2805 value
= boolean_true_node
;
2810 && ! (TREE_CODE (primop0
) == INTEGER_CST
2811 && ! TREE_OVERFLOW (convert (signed_type (type
),
2813 warning ("comparison of unsigned expression < 0 is always false");
2814 value
= boolean_false_node
;
2823 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2824 if (TREE_SIDE_EFFECTS (primop0
))
2825 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
2832 *op0_ptr
= convert (type
, primop0
);
2833 *op1_ptr
= convert (type
, primop1
);
2835 *restype_ptr
= boolean_type_node
;
2840 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2841 or validate its data type for an `if' or `while' statement or ?..: exp.
2843 This preparation consists of taking the ordinary
2844 representation of an expression expr and producing a valid tree
2845 boolean expression describing whether expr is nonzero. We could
2846 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2847 but we optimize comparisons, &&, ||, and !.
2849 The resulting type should always be `boolean_type_node'. */
2852 truthvalue_conversion (expr
)
2855 if (TREE_CODE (expr
) == ERROR_MARK
)
2858 #if 0 /* This appears to be wrong for C++. */
2859 /* These really should return error_mark_node after 2.4 is stable.
2860 But not all callers handle ERROR_MARK properly. */
2861 switch (TREE_CODE (TREE_TYPE (expr
)))
2864 error ("struct type value used where scalar is required");
2865 return boolean_false_node
;
2868 error ("union type value used where scalar is required");
2869 return boolean_false_node
;
2872 error ("array type value used where scalar is required");
2873 return boolean_false_node
;
2880 switch (TREE_CODE (expr
))
2883 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
2884 case TRUTH_ANDIF_EXPR
:
2885 case TRUTH_ORIF_EXPR
:
2886 case TRUTH_AND_EXPR
:
2888 case TRUTH_XOR_EXPR
:
2889 case TRUTH_NOT_EXPR
:
2890 TREE_TYPE (expr
) = boolean_type_node
;
2897 return integer_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2900 return real_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2903 /* If we are taking the address of a external decl, it might be zero
2904 if it is weak, so we cannot optimize. */
2905 if (DECL_P (TREE_OPERAND (expr
, 0))
2906 && DECL_EXTERNAL (TREE_OPERAND (expr
, 0)))
2909 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
2910 return build (COMPOUND_EXPR
, boolean_type_node
,
2911 TREE_OPERAND (expr
, 0), boolean_true_node
);
2913 return boolean_true_node
;
2916 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
2917 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
2918 truthvalue_conversion (TREE_OPERAND (expr
, 0)),
2919 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2926 /* These don't change whether an object is non-zero or zero. */
2927 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2931 /* These don't change whether an object is zero or non-zero, but
2932 we can't ignore them if their second arg has side-effects. */
2933 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
2934 return build (COMPOUND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 1),
2935 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
2937 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2940 /* Distribute the conversion into the arms of a COND_EXPR. */
2941 return fold (build (COND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 0),
2942 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2943 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
2946 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2947 since that affects how `default_conversion' will behave. */
2948 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
2949 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
2951 /* fall through... */
2953 /* If this is widening the argument, we can ignore it. */
2954 if (TYPE_PRECISION (TREE_TYPE (expr
))
2955 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
2956 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2960 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2962 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
2963 && TREE_CODE (TREE_TYPE (expr
)) == REAL_TYPE
)
2965 /* fall through... */
2967 /* This and MINUS_EXPR can be changed into a comparison of the
2969 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
2970 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
2971 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
2972 TREE_OPERAND (expr
, 1), 1);
2973 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
2974 fold (build1 (NOP_EXPR
,
2975 TREE_TYPE (TREE_OPERAND (expr
, 0)),
2976 TREE_OPERAND (expr
, 1))), 1);
2979 if (integer_onep (TREE_OPERAND (expr
, 1))
2980 && TREE_TYPE (expr
) != boolean_type_node
)
2981 /* Using convert here would cause infinite recursion. */
2982 return build1 (NOP_EXPR
, boolean_type_node
, expr
);
2986 if (warn_parentheses
&& C_EXP_ORIGINAL_CODE (expr
) == MODIFY_EXPR
)
2987 warning ("suggest parentheses around assignment used as truth value");
2994 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
2996 tree tem
= save_expr (expr
);
2997 return (build_binary_op
2998 ((TREE_SIDE_EFFECTS (expr
)
2999 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
3000 truthvalue_conversion (build_unary_op (REALPART_EXPR
, tem
, 0)),
3001 truthvalue_conversion (build_unary_op (IMAGPART_EXPR
, tem
, 0)),
3005 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
3009 /* Read the rest of a #-directive from input stream FINPUT.
3010 In normal use, the directive name and the white space after it
3011 have already been read, so they won't be included in the result.
3012 We allow for the fact that the directive line may contain
3013 a newline embedded within a character or string literal which forms
3014 a part of the directive.
3016 The value is a string in a reusable buffer. It remains valid
3017 only until the next time this function is called. */
3018 unsigned char *yy_cur
, *yy_lim
;
3020 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
3021 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
3028 parse_in
.limit
= parse_in
.token_buffer
;
3029 cpp_token
= cpp_get_token (&parse_in
);
3030 if (cpp_token
== CPP_EOF
)
3032 yy_lim
= CPP_PWRITTEN (&parse_in
);
3033 yy_cur
= parse_in
.token_buffer
;
3034 if (yy_cur
< yy_lim
)
3040 get_directive_line ()
3042 static char *directive_buffer
= NULL
;
3043 static unsigned buffer_length
= 0;
3045 register char *buffer_limit
;
3046 register int looking_for
= 0;
3047 register int char_escaped
= 0;
3049 if (buffer_length
== 0)
3051 directive_buffer
= (char *)xmalloc (128);
3052 buffer_length
= 128;
3055 buffer_limit
= &directive_buffer
[buffer_length
];
3057 for (p
= directive_buffer
; ; )
3061 /* Make buffer bigger if it is full. */
3062 if (p
>= buffer_limit
)
3064 register unsigned bytes_used
= (p
- directive_buffer
);
3068 = (char *)xrealloc (directive_buffer
, buffer_length
);
3069 p
= &directive_buffer
[bytes_used
];
3070 buffer_limit
= &directive_buffer
[buffer_length
];
3075 /* Discard initial whitespace. */
3076 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
3079 /* Detect the end of the directive. */
3080 if (c
== '\n' && looking_for
== 0)
3089 return directive_buffer
;
3091 /* Handle string and character constant syntax. */
3094 if (looking_for
== c
&& !char_escaped
)
3095 looking_for
= 0; /* Found terminator... stop looking. */
3098 if (c
== '\'' || c
== '"')
3099 looking_for
= c
; /* Don't stop buffering until we see another
3100 another one of these (or an EOF). */
3102 /* Handle backslash. */
3103 char_escaped
= (c
== '\\' && ! char_escaped
);
3107 /* Read the rest of a #-directive from input stream FINPUT.
3108 In normal use, the directive name and the white space after it
3109 have already been read, so they won't be included in the result.
3110 We allow for the fact that the directive line may contain
3111 a newline embedded within a character or string literal which forms
3112 a part of the directive.
3114 The value is a string in a reusable buffer. It remains valid
3115 only until the next time this function is called.
3117 The terminating character ('\n' or EOF) is left in FINPUT for the
3118 caller to re-read. */
3121 get_directive_line (finput
)
3122 register FILE *finput
;
3124 static char *directive_buffer
= NULL
;
3125 static unsigned buffer_length
= 0;
3127 register char *buffer_limit
;
3128 register int looking_for
= 0;
3129 register int char_escaped
= 0;
3131 if (buffer_length
== 0)
3133 directive_buffer
= (char *)xmalloc (128);
3134 buffer_length
= 128;
3137 buffer_limit
= &directive_buffer
[buffer_length
];
3139 for (p
= directive_buffer
; ; )
3143 /* Make buffer bigger if it is full. */
3144 if (p
>= buffer_limit
)
3146 register unsigned bytes_used
= (p
- directive_buffer
);
3150 = (char *)xrealloc (directive_buffer
, buffer_length
);
3151 p
= &directive_buffer
[bytes_used
];
3152 buffer_limit
= &directive_buffer
[buffer_length
];
3157 /* Discard initial whitespace. */
3158 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
3161 /* Detect the end of the directive. */
3162 if (looking_for
== 0
3163 && (c
== '\n' || c
== EOF
))
3172 return directive_buffer
;
3174 /* Handle string and character constant syntax. */
3177 if (looking_for
== c
&& !char_escaped
)
3178 looking_for
= 0; /* Found terminator... stop looking. */
3181 if (c
== '\'' || c
== '"')
3182 looking_for
= c
; /* Don't stop buffering until we see another
3183 one of these (or an EOF). */
3185 /* Handle backslash. */
3186 char_escaped
= (c
== '\\' && ! char_escaped
);
3189 #endif /* !USE_CPPLIB */
3191 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3192 down to the element type of an array. */
3195 c_build_qualified_type (type
, type_quals
)
3199 /* A restrict-qualified pointer type must be a pointer to object or
3200 incomplete type. Note that the use of POINTER_TYPE_P also allows
3201 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
3202 the C++ front-end also use POINTER_TYPE for pointer-to-member
3203 values, so even though it should be illegal to use `restrict'
3204 with such an entity we don't flag that here. Thus, special case
3205 code for that case is required in the C++ front-end. */
3206 if ((type_quals
& TYPE_QUAL_RESTRICT
)
3207 && (!POINTER_TYPE_P (type
)
3208 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
))))
3210 error ("invalid use of `restrict'");
3211 type_quals
&= ~TYPE_QUAL_RESTRICT
;
3214 if (TREE_CODE (type
) == ARRAY_TYPE
)
3215 return build_array_type (c_build_qualified_type (TREE_TYPE (type
),
3217 TYPE_DOMAIN (type
));
3218 return build_qualified_type (type
, type_quals
);
3221 /* Apply the TYPE_QUALS to the new DECL. */
3224 c_apply_type_quals_to_decl (type_quals
, decl
)
3228 if ((type_quals
& TYPE_QUAL_CONST
)
3229 || (TREE_TYPE (decl
)
3230 && TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
))
3231 TREE_READONLY (decl
) = 1;
3232 if (type_quals
& TYPE_QUAL_VOLATILE
)
3234 TREE_SIDE_EFFECTS (decl
) = 1;
3235 TREE_THIS_VOLATILE (decl
) = 1;
3237 if (type_quals
& TYPE_QUAL_RESTRICT
)
3239 if (!TREE_TYPE (decl
)
3240 || !POINTER_TYPE_P (TREE_TYPE (decl
))
3241 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl
))))
3242 error ("invalid use of `restrict'");
3243 else if (flag_strict_aliasing
)
3245 /* No two restricted pointers can point at the same thing.
3246 However, a restricted pointer can point at the same thing
3247 as an unrestricted pointer, if that unrestricted pointer
3248 is based on the restricted pointer. So, we make the
3249 alias set for the restricted pointer a subset of the
3250 alias set for the type pointed to by the type of the
3253 HOST_WIDE_INT pointed_to_alias_set
3254 = get_alias_set (TREE_TYPE (TREE_TYPE (decl
)));
3256 if (pointed_to_alias_set
== 0)
3257 /* It's not legal to make a subset of alias set zero. */
3261 DECL_POINTER_ALIAS_SET (decl
) = new_alias_set ();
3262 record_alias_subset (pointed_to_alias_set
,
3263 DECL_POINTER_ALIAS_SET (decl
));
3270 /* Return the typed-based alias set for T, which may be an expression
3271 or a type. Return -1 if we don't do anything special. */
3274 lang_get_alias_set (t
)
3279 /* Permit type-punning when accessing a union, provided the access
3280 is directly through the union. For example, this code does not
3281 permit taking the address of a union member and then storing
3282 through it. Even the type-punning allowed here is a GCC
3283 extension, albeit a common and useful one; the C standard says
3284 that such accesses have implementation-defined behavior. */
3286 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
3287 u
= TREE_OPERAND (u
, 0))
3288 if (TREE_CODE (u
) == COMPONENT_REF
3289 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
3292 /* If this is a char *, the ANSI C standard says it can alias
3293 anything. Note that all references need do this. */
3294 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 'r'
3295 && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
3296 && TYPE_PRECISION (TREE_TYPE (t
)) == TYPE_PRECISION (char_type_node
))
3299 /* That's all the expressions we handle specially. */
3303 /* The C standard specifically allows aliasing between signed and
3304 unsigned variants of the same type. We treat the signed
3305 variant as canonical. */
3306 if (TREE_CODE (t
) == INTEGER_TYPE
&& TREE_UNSIGNED (t
))
3308 tree t1
= signed_type (t
);
3310 /* t1 == t can happen for boolean nodes which are always unsigned. */
3312 return get_alias_set (t1
);
3314 else if (POINTER_TYPE_P (t
))
3318 /* Unfortunately, there is no canonical form of a pointer type.
3319 In particular, if we have `typedef int I', then `int *', and
3320 `I *' are different types. So, we have to pick a canonical
3321 representative. We do this below.
3323 Technically, this approach is actually more conservative that
3324 it needs to be. In particular, `const int *' and `int *'
3325 chould be in different alias sets, according to the C and C++
3326 standard, since their types are not the same, and so,
3327 technically, an `int **' and `const int **' cannot point at
3330 But, the standard is wrong. In particular, this code is
3335 const int* const* cipp = &ip;
3337 And, it doesn't make sense for that to be legal unless you
3338 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
3339 the pointed-to types. This issue has been reported to the
3341 t1
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
3342 t1
= ((TREE_CODE (t
) == POINTER_TYPE
)
3343 ? build_pointer_type (t1
) : build_reference_type (t1
));
3345 return get_alias_set (t1
);
3347 /* It's not yet safe to use alias sets for classes in C++ because
3348 the TYPE_FIELDs list for a class doesn't mention base classes. */
3349 else if (c_language
== clk_cplusplus
&& AGGREGATE_TYPE_P (t
))
3355 /* Build tree nodes and builtin functions common to both C and C++ language
3357 CPLUS_MODE is nonzero if we are called from the C++ frontend, we generate
3358 some stricter prototypes in that case.
3359 NO_BUILTINS and NO_NONANSI_BUILTINS contain the respective values of
3360 the language frontend flags flag_no_builtin and
3361 flag_no_nonansi_builtin. */
3364 c_common_nodes_and_builtins (cplus_mode
, no_builtins
, no_nonansi_builtins
)
3365 int cplus_mode
, no_builtins
, no_nonansi_builtins
;
3368 tree memcpy_ftype
, memset_ftype
, strlen_ftype
;
3369 tree bzero_ftype
, bcmp_ftype
;
3370 tree endlink
, int_endlink
, double_endlink
, unsigned_endlink
;
3371 tree sizetype_endlink
;
3372 tree ptr_ftype
, ptr_ftype_unsigned
;
3373 tree void_ftype_any
, void_ftype_int
, int_ftype_any
;
3374 tree double_ftype_double
, double_ftype_double_double
;
3375 tree float_ftype_float
, ldouble_ftype_ldouble
;
3376 tree int_ftype_cptr_cptr_sizet
;
3377 tree int_ftype_string_string
, string_ftype_ptr_ptr
;
3378 tree long_ftype_long
;
3379 /* Either char* or void*. */
3380 tree traditional_ptr_type_node
;
3381 /* Either const char* or const void*. */
3382 tree traditional_cptr_type_node
;
3383 tree traditional_len_type_node
;
3384 tree traditional_len_endlink
;
3385 tree va_list_ref_type_node
;
3386 tree va_list_arg_type_node
;
3388 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_va_list"),
3389 va_list_type_node
));
3391 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_ptrdiff_t"),
3392 ptrdiff_type_node
));
3394 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_size_t"),
3397 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
3399 va_list_arg_type_node
= va_list_ref_type_node
=
3400 build_pointer_type (TREE_TYPE (va_list_type_node
));
3404 va_list_arg_type_node
= va_list_type_node
;
3405 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
3408 endlink
= void_list_node
;
3409 int_endlink
= tree_cons (NULL_TREE
, integer_type_node
, endlink
);
3410 double_endlink
= tree_cons (NULL_TREE
, double_type_node
, endlink
);
3411 unsigned_endlink
= tree_cons (NULL_TREE
, unsigned_type_node
, endlink
);
3413 ptr_ftype
= build_function_type (ptr_type_node
, NULL_TREE
);
3414 ptr_ftype_unsigned
= build_function_type (ptr_type_node
, unsigned_endlink
);
3415 sizetype_endlink
= tree_cons (NULL_TREE
, TYPE_DOMAIN (sizetype
), endlink
);
3416 /* We realloc here because sizetype could be int or unsigned. S'ok. */
3417 ptr_ftype_sizetype
= build_function_type (ptr_type_node
, sizetype_endlink
);
3419 int_ftype_any
= build_function_type (integer_type_node
, NULL_TREE
);
3420 void_ftype_any
= build_function_type (void_type_node
, NULL_TREE
);
3421 void_ftype
= build_function_type (void_type_node
, endlink
);
3422 void_ftype_int
= build_function_type (void_type_node
, int_endlink
);
3424 = build_function_type (void_type_node
,
3425 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
3428 = build_function_type (float_type_node
,
3429 tree_cons (NULL_TREE
, float_type_node
, endlink
));
3432 = build_function_type (double_type_node
, double_endlink
);
3434 ldouble_ftype_ldouble
3435 = build_function_type (long_double_type_node
,
3436 tree_cons (NULL_TREE
, long_double_type_node
,
3439 double_ftype_double_double
3440 = build_function_type (double_type_node
,
3441 tree_cons (NULL_TREE
, double_type_node
,
3445 = build_function_type (integer_type_node
, int_endlink
);
3448 = build_function_type (long_integer_type_node
,
3449 tree_cons (NULL_TREE
, long_integer_type_node
,
3452 int_ftype_cptr_cptr_sizet
3453 = build_function_type (integer_type_node
,
3454 tree_cons (NULL_TREE
, const_ptr_type_node
,
3455 tree_cons (NULL_TREE
, const_ptr_type_node
,
3456 tree_cons (NULL_TREE
,
3460 /* Prototype for strcpy. */
3461 string_ftype_ptr_ptr
3462 = build_function_type (string_type_node
,
3463 tree_cons (NULL_TREE
, string_type_node
,
3464 tree_cons (NULL_TREE
,
3465 const_string_type_node
,
3468 traditional_len_type_node
= (flag_traditional
&& ! cplus_mode
3469 ? integer_type_node
: sizetype
);
3470 traditional_len_endlink
= tree_cons (NULL_TREE
, traditional_len_type_node
,
3473 /* Prototype for strcmp. */
3474 int_ftype_string_string
3475 = build_function_type (integer_type_node
,
3476 tree_cons (NULL_TREE
, const_string_type_node
,
3477 tree_cons (NULL_TREE
,
3478 const_string_type_node
,
3481 /* Prototype for strlen. */
3483 = build_function_type (traditional_len_type_node
,
3484 tree_cons (NULL_TREE
, const_string_type_node
,
3487 traditional_ptr_type_node
= (flag_traditional
&& ! cplus_mode
3488 ? string_type_node
: ptr_type_node
);
3489 traditional_cptr_type_node
= (flag_traditional
&& ! cplus_mode
3490 ? const_string_type_node
: const_ptr_type_node
);
3492 /* Prototype for memcpy. */
3494 = build_function_type (traditional_ptr_type_node
,
3495 tree_cons (NULL_TREE
, ptr_type_node
,
3496 tree_cons (NULL_TREE
, const_ptr_type_node
,
3497 sizetype_endlink
)));
3499 /* Prototype for memset. */
3501 = build_function_type (traditional_ptr_type_node
,
3502 tree_cons (NULL_TREE
, ptr_type_node
,
3503 tree_cons (NULL_TREE
, integer_type_node
,
3504 tree_cons (NULL_TREE
,
3508 /* Prototype for bzero. */
3510 = build_function_type (void_type_node
,
3511 tree_cons (NULL_TREE
, traditional_ptr_type_node
,
3512 traditional_len_endlink
));
3514 /* Prototype for bcmp. */
3516 = build_function_type (integer_type_node
,
3517 tree_cons (NULL_TREE
, traditional_cptr_type_node
,
3518 tree_cons (NULL_TREE
,
3519 traditional_cptr_type_node
,
3520 traditional_len_endlink
)));
3522 builtin_function ("__builtin_constant_p", default_function_type
,
3523 BUILT_IN_CONSTANT_P
, BUILT_IN_NORMAL
, NULL_PTR
);
3525 builtin_function ("__builtin_return_address", ptr_ftype_unsigned
,
3526 BUILT_IN_RETURN_ADDRESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3528 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned
,
3529 BUILT_IN_FRAME_ADDRESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3531 builtin_function ("__builtin_alloca", ptr_ftype_sizetype
,
3532 BUILT_IN_ALLOCA
, BUILT_IN_NORMAL
, "alloca");
3533 builtin_function ("__builtin_ffs", int_ftype_int
, BUILT_IN_FFS
,
3534 BUILT_IN_NORMAL
, NULL_PTR
);
3535 /* Define alloca, ffs as builtins.
3536 Declare _exit just to mark it as volatile. */
3537 if (! no_builtins
&& ! no_nonansi_builtins
)
3540 temp
= builtin_function ("alloca", ptr_ftype_sizetype
,
3541 BUILT_IN_ALLOCA
, BUILT_IN_NORMAL
, NULL_PTR
);
3542 /* Suppress error if redefined as a non-function. */
3543 DECL_BUILT_IN_NONANSI (temp
) = 1;
3545 temp
= builtin_function ("ffs", int_ftype_int
, BUILT_IN_FFS
,
3546 BUILT_IN_NORMAL
, NULL_PTR
);
3547 /* Suppress error if redefined as a non-function. */
3548 DECL_BUILT_IN_NONANSI (temp
) = 1;
3549 temp
= builtin_function ("_exit", void_ftype_int
,
3550 0, NOT_BUILT_IN
, NULL_PTR
);
3551 TREE_THIS_VOLATILE (temp
) = 1;
3552 TREE_SIDE_EFFECTS (temp
) = 1;
3553 /* Suppress error if redefined as a non-function. */
3554 DECL_BUILT_IN_NONANSI (temp
) = 1;
3556 /* The system prototypes for these functions have many
3557 variations, so don't specify parameters to avoid conflicts.
3558 The expand_* functions check the argument types anyway. */
3559 temp
= builtin_function ("bzero", void_ftype_any
,
3560 BUILT_IN_BZERO
, BUILT_IN_NORMAL
, NULL_PTR
);
3561 DECL_BUILT_IN_NONANSI (temp
) = 1;
3562 temp
= builtin_function ("bcmp", int_ftype_any
,
3563 BUILT_IN_BCMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3564 DECL_BUILT_IN_NONANSI (temp
) = 1;
3567 builtin_function ("__builtin_abs", int_ftype_int
, BUILT_IN_ABS
,
3568 BUILT_IN_NORMAL
, NULL_PTR
);
3569 builtin_function ("__builtin_fabsf", float_ftype_float
, BUILT_IN_FABS
,
3570 BUILT_IN_NORMAL
, NULL_PTR
);
3571 builtin_function ("__builtin_fabs", double_ftype_double
, BUILT_IN_FABS
,
3572 BUILT_IN_NORMAL
, NULL_PTR
);
3573 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
3574 BUILT_IN_NORMAL
, NULL_PTR
);
3575 builtin_function ("__builtin_labs", long_ftype_long
, BUILT_IN_LABS
,
3576 BUILT_IN_NORMAL
, NULL_PTR
);
3577 builtin_function ("__builtin_saveregs", ptr_ftype
, BUILT_IN_SAVEREGS
,
3578 BUILT_IN_NORMAL
, NULL_PTR
);
3579 builtin_function ("__builtin_classify_type", default_function_type
,
3580 BUILT_IN_CLASSIFY_TYPE
, BUILT_IN_NORMAL
, NULL_PTR
);
3581 builtin_function ("__builtin_next_arg", ptr_ftype
, BUILT_IN_NEXT_ARG
,
3582 BUILT_IN_NORMAL
, NULL_PTR
);
3583 builtin_function ("__builtin_args_info", int_ftype_int
, BUILT_IN_ARGS_INFO
,
3584 BUILT_IN_NORMAL
, NULL_PTR
);
3585 builtin_function ("__builtin_setjmp",
3586 build_function_type (integer_type_node
,
3587 tree_cons (NULL_TREE
, ptr_type_node
,
3589 BUILT_IN_SETJMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3590 builtin_function ("__builtin_longjmp",
3591 build_function_type (void_type_node
,
3592 tree_cons (NULL_TREE
, ptr_type_node
,
3593 tree_cons (NULL_TREE
,
3596 BUILT_IN_LONGJMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3597 builtin_function ("__builtin_trap", void_ftype
, BUILT_IN_TRAP
,
3598 BUILT_IN_NORMAL
, NULL_PTR
);
3600 /* ISO C99 IEEE Unordered compares. */
3601 builtin_function ("__builtin_isgreater", default_function_type
,
3602 BUILT_IN_ISGREATER
, BUILT_IN_NORMAL
, NULL_PTR
);
3603 builtin_function ("__builtin_isgreaterequal", default_function_type
,
3604 BUILT_IN_ISGREATEREQUAL
, BUILT_IN_NORMAL
, NULL_PTR
);
3605 builtin_function ("__builtin_isless", default_function_type
,
3606 BUILT_IN_ISLESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3607 builtin_function ("__builtin_islessequal", default_function_type
,
3608 BUILT_IN_ISLESSEQUAL
, BUILT_IN_NORMAL
, NULL_PTR
);
3609 builtin_function ("__builtin_islessgreater", default_function_type
,
3610 BUILT_IN_ISLESSGREATER
, BUILT_IN_NORMAL
, NULL_PTR
);
3611 builtin_function ("__builtin_isunordered", default_function_type
,
3612 BUILT_IN_ISUNORDERED
, BUILT_IN_NORMAL
, NULL_PTR
);
3614 /* Untyped call and return. */
3615 builtin_function ("__builtin_apply_args", ptr_ftype
,
3616 BUILT_IN_APPLY_ARGS
, BUILT_IN_NORMAL
, NULL_PTR
);
3618 temp
= tree_cons (NULL_TREE
,
3619 build_pointer_type (build_function_type (void_type_node
,
3621 tree_cons (NULL_TREE
,
3623 tree_cons (NULL_TREE
,
3626 builtin_function ("__builtin_apply",
3627 build_function_type (ptr_type_node
, temp
),
3628 BUILT_IN_APPLY
, BUILT_IN_NORMAL
, NULL_PTR
);
3629 builtin_function ("__builtin_return", void_ftype_ptr
,
3630 BUILT_IN_RETURN
, BUILT_IN_NORMAL
, NULL_PTR
);
3632 /* Support for varargs.h and stdarg.h. */
3633 builtin_function ("__builtin_varargs_start",
3634 build_function_type (void_type_node
,
3635 tree_cons (NULL_TREE
,
3636 va_list_ref_type_node
,
3638 BUILT_IN_VARARGS_START
, BUILT_IN_NORMAL
, NULL_PTR
);
3640 builtin_function ("__builtin_stdarg_start",
3641 build_function_type (void_type_node
,
3642 tree_cons (NULL_TREE
,
3643 va_list_ref_type_node
,
3645 BUILT_IN_STDARG_START
, BUILT_IN_NORMAL
, NULL_PTR
);
3647 builtin_function ("__builtin_va_end",
3648 build_function_type (void_type_node
,
3649 tree_cons (NULL_TREE
,
3650 va_list_ref_type_node
,
3652 BUILT_IN_VA_END
, BUILT_IN_NORMAL
, NULL_PTR
);
3654 builtin_function ("__builtin_va_copy",
3655 build_function_type (void_type_node
,
3656 tree_cons (NULL_TREE
,
3657 va_list_ref_type_node
,
3658 tree_cons (NULL_TREE
,
3659 va_list_arg_type_node
,
3661 BUILT_IN_VA_COPY
, BUILT_IN_NORMAL
, NULL_PTR
);
3663 /* ??? Ought to be `T __builtin_expect(T, T)' for any type T. */
3664 builtin_function ("__builtin_expect",
3665 build_function_type (long_integer_type_node
,
3666 tree_cons (NULL_TREE
,
3667 long_integer_type_node
,
3668 tree_cons (NULL_TREE
,
3669 long_integer_type_node
,
3671 BUILT_IN_EXPECT
, BUILT_IN_NORMAL
, NULL_PTR
);
3673 /* Currently under experimentation. */
3674 builtin_function ("__builtin_memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
,
3675 BUILT_IN_NORMAL
, "memcpy");
3676 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet
,
3677 BUILT_IN_MEMCMP
, BUILT_IN_NORMAL
, "memcmp");
3678 builtin_function ("__builtin_memset", memset_ftype
,
3679 BUILT_IN_MEMSET
, BUILT_IN_NORMAL
, "memset");
3680 builtin_function ("__builtin_bzero", bzero_ftype
,
3681 BUILT_IN_BZERO
, BUILT_IN_NORMAL
, "bzero");
3682 builtin_function ("__builtin_bcmp", bcmp_ftype
,
3683 BUILT_IN_BCMP
, BUILT_IN_NORMAL
, "bcmp");
3684 builtin_function ("__builtin_strcmp", int_ftype_string_string
,
3685 BUILT_IN_STRCMP
, BUILT_IN_NORMAL
, "strcmp");
3686 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr
,
3687 BUILT_IN_STRCPY
, BUILT_IN_NORMAL
, "strcpy");
3688 builtin_function ("__builtin_strlen", strlen_ftype
,
3689 BUILT_IN_STRLEN
, BUILT_IN_NORMAL
, "strlen");
3690 builtin_function ("__builtin_sqrtf", float_ftype_float
,
3691 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, "sqrtf");
3692 builtin_function ("__builtin_fsqrt", double_ftype_double
,
3693 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, "sqrt");
3694 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble
,
3695 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, "sqrtl");
3696 builtin_function ("__builtin_sinf", float_ftype_float
,
3697 BUILT_IN_SIN
, BUILT_IN_NORMAL
, "sinf");
3698 builtin_function ("__builtin_sin", double_ftype_double
,
3699 BUILT_IN_SIN
, BUILT_IN_NORMAL
, "sin");
3700 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble
,
3701 BUILT_IN_SIN
, BUILT_IN_NORMAL
, "sinl");
3702 builtin_function ("__builtin_cosf", float_ftype_float
,
3703 BUILT_IN_COS
, BUILT_IN_NORMAL
, "cosf");
3704 builtin_function ("__builtin_cos", double_ftype_double
,
3705 BUILT_IN_COS
, BUILT_IN_NORMAL
, "cos");
3706 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble
,
3707 BUILT_IN_COS
, BUILT_IN_NORMAL
, "cosl");
3711 builtin_function ("abs", int_ftype_int
, BUILT_IN_ABS
,
3712 BUILT_IN_NORMAL
, NULL_PTR
);
3713 builtin_function ("fabsf", float_ftype_float
, BUILT_IN_FABS
,
3714 BUILT_IN_NORMAL
, NULL_PTR
);
3715 builtin_function ("fabs", double_ftype_double
, BUILT_IN_FABS
,
3716 BUILT_IN_NORMAL
, NULL_PTR
);
3717 builtin_function ("fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
3718 BUILT_IN_NORMAL
, NULL_PTR
);
3719 builtin_function ("labs", long_ftype_long
, BUILT_IN_LABS
,
3720 BUILT_IN_NORMAL
, NULL_PTR
);
3721 builtin_function ("memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
,
3722 BUILT_IN_NORMAL
, NULL_PTR
);
3723 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet
, BUILT_IN_MEMCMP
,
3724 BUILT_IN_NORMAL
, NULL_PTR
);
3725 builtin_function ("memset", memset_ftype
, BUILT_IN_MEMSET
,
3726 BUILT_IN_NORMAL
, NULL_PTR
);
3727 builtin_function ("strcmp", int_ftype_string_string
, BUILT_IN_STRCMP
,
3728 BUILT_IN_NORMAL
, NULL_PTR
);
3729 builtin_function ("strcpy", string_ftype_ptr_ptr
, BUILT_IN_STRCPY
,
3730 BUILT_IN_NORMAL
, NULL_PTR
);
3731 builtin_function ("strlen", strlen_ftype
, BUILT_IN_STRLEN
,
3732 BUILT_IN_NORMAL
, NULL_PTR
);
3733 builtin_function ("sqrtf", float_ftype_float
, BUILT_IN_FSQRT
,
3734 BUILT_IN_NORMAL
, NULL_PTR
);
3735 builtin_function ("sqrt", double_ftype_double
, BUILT_IN_FSQRT
,
3736 BUILT_IN_NORMAL
, NULL_PTR
);
3737 builtin_function ("sqrtl", ldouble_ftype_ldouble
, BUILT_IN_FSQRT
,
3738 BUILT_IN_NORMAL
, NULL_PTR
);
3739 builtin_function ("sinf", float_ftype_float
, BUILT_IN_SIN
,
3740 BUILT_IN_NORMAL
, NULL_PTR
);
3741 builtin_function ("sin", double_ftype_double
, BUILT_IN_SIN
,
3742 BUILT_IN_NORMAL
, NULL_PTR
);
3743 builtin_function ("sinl", ldouble_ftype_ldouble
, BUILT_IN_SIN
,
3744 BUILT_IN_NORMAL
, NULL_PTR
);
3745 builtin_function ("cosf", float_ftype_float
, BUILT_IN_COS
,
3746 BUILT_IN_NORMAL
, NULL_PTR
);
3747 builtin_function ("cos", double_ftype_double
, BUILT_IN_COS
,
3748 BUILT_IN_NORMAL
, NULL_PTR
);
3749 builtin_function ("cosl", ldouble_ftype_ldouble
, BUILT_IN_COS
,
3750 BUILT_IN_NORMAL
, NULL_PTR
);
3752 /* Declare these functions volatile
3753 to avoid spurious "control drops through" warnings. */
3754 temp
= builtin_function ("abort", cplus_mode
? void_ftype
: void_ftype_any
,
3755 0, NOT_BUILT_IN
, NULL_PTR
);
3756 TREE_THIS_VOLATILE (temp
) = 1;
3757 TREE_SIDE_EFFECTS (temp
) = 1;
3759 #if 0 /* ??? The C++ frontend used to do this. */
3760 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3762 DECL_BUILT_IN_NONANSI (temp
) = 1;
3764 temp
= builtin_function ("exit",
3765 cplus_mode
? void_ftype_int
: void_ftype_any
,
3766 0, NOT_BUILT_IN
, NULL_PTR
);
3767 TREE_THIS_VOLATILE (temp
) = 1;
3768 TREE_SIDE_EFFECTS (temp
) = 1;
3770 #if 0 /* ??? The C++ frontend used to do this. */
3771 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3773 DECL_BUILT_IN_NONANSI (temp
) = 1;
3778 /* Support for these has not been written in either expand_builtin
3779 or build_function_call. */
3780 builtin_function ("__builtin_div", default_ftype
, BUILT_IN_DIV
,
3781 BUILT_IN_NORMAL
, NULL_PTR
);
3782 builtin_function ("__builtin_ldiv", default_ftype
, BUILT_IN_LDIV
,
3783 BUILT_IN_NORMAL
, NULL_PTR
);
3784 builtin_function ("__builtin_ffloor", double_ftype_double
, BUILT_IN_FFLOOR
,
3785 BUILT_IN_NORMAL
, NULL_PTR
);
3786 builtin_function ("__builtin_fceil", double_ftype_double
, BUILT_IN_FCEIL
,
3787 BUILT_IN_NORMAL
, NULL_PTR
);
3788 builtin_function ("__builtin_fmod", double_ftype_double_double
,
3789 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, NULL_PTR
);
3790 builtin_function ("__builtin_frem", double_ftype_double_double
,
3791 BUILT_IN_FREM
, BUILT_IN_NORMAL
, NULL_PTR
);
3792 builtin_function ("__builtin_getexp", double_ftype_double
, BUILT_IN_GETEXP
,
3793 BUILT_IN_NORMAL
, NULL_PTR
);
3794 builtin_function ("__builtin_getman", double_ftype_double
, BUILT_IN_GETMAN
,
3795 BUILT_IN_NORMAL
, NULL_PTR
);
3798 /* ??? Perhaps there's a better place to do this. But it is related
3799 to __builtin_va_arg, so it isn't that off-the-wall. */
3800 lang_type_promotes_to
= simple_type_promotes_to
;
3804 build_va_arg (expr
, type
)
3807 return build1 (VA_ARG_EXPR
, type
, expr
);
3810 /* Given a type, apply default promotions wrt unnamed function arguments
3811 and return the new type. Return NULL_TREE if no change. */
3812 /* ??? There is a function of the same name in the C++ front end that
3813 does something similar, but is more thorough and does not return NULL
3814 if no change. We could perhaps share code, but it would make the
3815 self_promoting_type property harder to identify. */
3818 simple_type_promotes_to (type
)
3821 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3822 return double_type_node
;
3824 if (C_PROMOTING_INTEGER_TYPE_P (type
))
3826 /* Traditionally, unsignedness is preserved in default promotions.
3827 Also preserve unsignedness if not really getting any wider. */
3828 if (TREE_UNSIGNED (type
)
3829 && (flag_traditional
3830 || TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
3831 return unsigned_type_node
;
3832 return integer_type_node
;
3838 /* Return 1 if PARMS specifies a fixed number of parameters
3839 and none of their types is affected by default promotions. */
3842 self_promoting_args_p (parms
)
3846 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
3848 register tree type
= TREE_VALUE (t
);
3850 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
3856 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3859 if (C_PROMOTING_INTEGER_TYPE_P (type
))
3865 /* Recognize certain built-in functions so we can make tree-codes
3866 other than CALL_EXPR. We do this when it enables fold-const.c
3867 to do something useful. */
3868 /* ??? By rights this should go in builtins.c, but only C and C++
3869 implement build_{binary,unary}_op. Not exactly sure what bits
3870 of functionality are actually needed from those functions, or
3871 where the similar functionality exists in the other front ends. */
3874 expand_tree_builtin (function
, params
, coerced_params
)
3875 tree function
, params
, coerced_params
;
3877 enum tree_code code
;
3879 if (DECL_BUILT_IN_CLASS (function
) != BUILT_IN_NORMAL
)
3882 switch (DECL_FUNCTION_CODE (function
))
3887 if (coerced_params
== 0)
3888 return integer_zero_node
;
3889 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
3891 case BUILT_IN_ISGREATER
:
3892 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3898 case BUILT_IN_ISGREATEREQUAL
:
3899 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3905 case BUILT_IN_ISLESS
:
3906 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3912 case BUILT_IN_ISLESSEQUAL
:
3913 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3919 case BUILT_IN_ISLESSGREATER
:
3920 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3926 case BUILT_IN_ISUNORDERED
:
3927 if (TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
)
3928 return integer_zero_node
;
3929 code
= UNORDERED_EXPR
;
3937 || TREE_CHAIN (params
) == 0)
3939 error ("too few arguments to function `%s'",
3940 IDENTIFIER_POINTER (DECL_NAME (function
)));
3941 return error_mark_node
;
3943 else if (TREE_CHAIN (TREE_CHAIN (params
)) != 0)
3945 error ("too many arguments to function `%s'",
3946 IDENTIFIER_POINTER (DECL_NAME (function
)));
3947 return error_mark_node
;
3950 arg0
= TREE_VALUE (params
);
3951 arg1
= TREE_VALUE (TREE_CHAIN (params
));
3952 arg0
= build_binary_op (code
, arg0
, arg1
, 0);
3953 if (code
!= UNORDERED_EXPR
)
3954 arg0
= build_unary_op (TRUTH_NOT_EXPR
, arg0
, 0);
3966 /* Tree code classes. */
3968 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
3970 static char c_tree_code_type
[] = {
3972 #include "c-common.def"
3976 /* Table indexed by tree code giving number of expression
3977 operands beyond the fixed part of the node structure.
3978 Not used for types or decls. */
3980 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
3982 static int c_tree_code_length
[] = {
3984 #include "c-common.def"
3988 /* Names of tree components.
3989 Used for printing out the tree and error messages. */
3990 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
3992 static const char *c_tree_code_name
[] = {
3994 #include "c-common.def"
3998 /* Adds the tree codes specific to the C front end to the list of all
4004 memcpy (tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4006 (int)LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
);
4007 memcpy (tree_code_length
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4009 (LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (int));
4010 memcpy (tree_code_name
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4012 (LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));