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. */
38 cpp_options parse_options
;
39 enum cpp_token cpp_token
;
42 #undef WCHAR_TYPE_SIZE
43 #define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
45 /* The following symbols are subsumed in the c_global_trees array, and
46 listed here individually for documentation purposes.
48 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
50 tree short_integer_type_node;
51 tree long_integer_type_node;
52 tree long_long_integer_type_node;
54 tree short_unsigned_type_node;
55 tree long_unsigned_type_node;
56 tree long_long_unsigned_type_node;
58 tree boolean_type_node;
59 tree boolean_false_node;
60 tree boolean_true_node;
62 tree ptrdiff_type_node;
64 tree unsigned_char_type_node;
65 tree signed_char_type_node;
67 tree signed_wchar_type_node;
68 tree unsigned_wchar_type_node;
71 tree double_type_node;
72 tree long_double_type_node;
74 tree complex_integer_type_node;
75 tree complex_float_type_node;
76 tree complex_double_type_node;
77 tree complex_long_double_type_node;
85 tree unsigned_intQI_type_node;
86 tree unsigned_intHI_type_node;
87 tree unsigned_intSI_type_node;
88 tree unsigned_intDI_type_node;
89 tree unsigned_intTI_type_node;
91 tree widest_integer_literal_type_node;
92 tree widest_unsigned_literal_type_node;
94 Nodes for types `void *' and `const void *'.
96 tree ptr_type_node, const_ptr_type_node;
98 Nodes for types `char *' and `const char *'.
100 tree string_type_node, const_string_type_node;
102 Type `char[SOMENUMBER]'.
103 Used when an array of char is needed and the size is irrelevant.
105 tree char_array_type_node;
107 Type `int[SOMENUMBER]' or something like it.
108 Used when an array of int needed and the size is irrelevant.
110 tree int_array_type_node;
112 Type `wchar_t[SOMENUMBER]' or something like it.
113 Used when a wide string literal is created.
115 tree wchar_array_type_node;
117 Type `int ()' -- used for implicit declaration of functions.
119 tree default_function_type;
121 Function types `int (int)', etc.
127 tree ptr_ftype_sizetype;
129 A VOID_TYPE node, packaged in a TREE_LIST.
135 tree c_global_trees
[CTI_MAX
];
137 /* The elements of `ridpointers' are identifier nodes for the reserved
138 type names and storage classes. It is indexed by a RID_... value. */
141 tree (*make_fname_decl
) PARAMS ((tree
, const char *, int));
143 /* Nonzero means the expression being parsed will never be evaluated.
144 This is a count, since unevaluated expressions can nest. */
147 enum attrs
{A_PACKED
, A_NOCOMMON
, A_COMMON
, A_NORETURN
, A_CONST
, A_T_UNION
,
148 A_NO_CHECK_MEMORY_USAGE
, A_NO_INSTRUMENT_FUNCTION
,
149 A_CONSTRUCTOR
, A_DESTRUCTOR
, A_MODE
, A_SECTION
, A_ALIGNED
,
150 A_UNUSED
, A_FORMAT
, A_FORMAT_ARG
, A_WEAK
, A_ALIAS
, A_MALLOC
,
151 A_NO_LIMIT_STACK
, A_PURE
};
153 enum format_type
{ printf_format_type
, scanf_format_type
,
154 strftime_format_type
};
156 static void add_attribute
PARAMS ((enum attrs
, const char *,
158 static void init_attributes
PARAMS ((void));
159 static void record_function_format
PARAMS ((tree
, tree
, enum format_type
,
161 static void record_international_format
PARAMS ((tree
, tree
, int));
162 static int default_valid_lang_attribute
PARAMS ((tree
, tree
, tree
, tree
));
164 /* Keep a stack of if statements. We record the number of compound
165 statements seen up to the if keyword, as well as the line number
166 and file of the if. If a potentially ambiguous else is seen, that
167 fact is recorded; the warning is issued when we can be sure that
168 the enclosing if statement does not have an else branch. */
176 static void tfaff
PARAMS ((void));
178 static if_elt
*if_stack
;
180 /* Amount of space in the if statement stack. */
181 static int if_stack_space
= 0;
184 static int if_stack_pointer
= 0;
186 /* Generate RTL for the start of an if-then, and record the start of it
187 for ambiguous else detection. */
190 c_expand_start_cond (cond
, exitflag
, compstmt_count
)
195 /* Make sure there is enough space on the stack. */
196 if (if_stack_space
== 0)
199 if_stack
= (if_elt
*)xmalloc (10 * sizeof (if_elt
));
201 else if (if_stack_space
== if_stack_pointer
)
203 if_stack_space
+= 10;
204 if_stack
= (if_elt
*)xrealloc (if_stack
, if_stack_space
* sizeof (if_elt
));
207 /* Record this if statement. */
208 if_stack
[if_stack_pointer
].compstmt_count
= compstmt_count
;
209 if_stack
[if_stack_pointer
].file
= input_filename
;
210 if_stack
[if_stack_pointer
].line
= lineno
;
211 if_stack
[if_stack_pointer
].needs_warning
= 0;
214 expand_start_cond (cond
, exitflag
);
217 /* Generate RTL for the end of an if-then. Optionally warn if a nested
218 if statement had an ambiguous else clause. */
224 if (if_stack
[if_stack_pointer
].needs_warning
)
225 warning_with_file_and_line (if_stack
[if_stack_pointer
].file
,
226 if_stack
[if_stack_pointer
].line
,
227 "suggest explicit braces to avoid ambiguous `else'");
231 /* Generate RTL between the then-clause and the else-clause
232 of an if-then-else. */
235 c_expand_start_else ()
237 /* An ambiguous else warning must be generated for the enclosing if
238 statement, unless we see an else branch for that one, too. */
240 && if_stack_pointer
> 1
241 && (if_stack
[if_stack_pointer
- 1].compstmt_count
242 == if_stack
[if_stack_pointer
- 2].compstmt_count
))
243 if_stack
[if_stack_pointer
- 2].needs_warning
= 1;
245 /* Even if a nested if statement had an else branch, it can't be
246 ambiguous if this one also has an else. So don't warn in that
247 case. Also don't warn for any if statements nested in this else. */
248 if_stack
[if_stack_pointer
- 1].needs_warning
= 0;
249 if_stack
[if_stack_pointer
- 1].compstmt_count
--;
251 expand_start_else ();
254 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
257 declare_function_name ()
259 const char *name
, *printable_name
;
261 if (current_function_decl
== NULL
)
264 printable_name
= "top level";
268 /* Allow functions to be nameless (such as artificial ones). */
269 if (DECL_NAME (current_function_decl
))
270 name
= IDENTIFIER_POINTER (DECL_NAME (current_function_decl
));
273 printable_name
= (*decl_printable_name
) (current_function_decl
, 2);
276 (*make_fname_decl
) (get_identifier ("__FUNCTION__"), name
, 0);
277 (*make_fname_decl
) (get_identifier ("__PRETTY_FUNCTION__"), printable_name
, 1);
278 /* The ISO C people "of course" couldn't use __FUNCTION__ in the
279 ISO C 99 standard; instead a new variable is invented. */
280 (*make_fname_decl
) (get_identifier ("__func__"), name
, 0);
283 /* Given a chain of STRING_CST nodes,
284 concatenate them into one STRING_CST
285 and give it a suitable array-of-chars data type. */
288 combine_strings (strings
)
291 register tree value
, t
;
292 register int length
= 1;
295 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
297 const int nchars_max
= flag_isoc99
? 4095 : 509;
299 if (TREE_CHAIN (strings
))
301 /* More than one in the chain, so concatenate. */
302 register char *p
, *q
;
304 /* Don't include the \0 at the end of each substring,
305 except for the last one.
306 Count wide strings and ordinary strings separately. */
307 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
309 if (TREE_TYPE (t
) == wchar_array_type_node
)
311 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
315 length
+= (TREE_STRING_LENGTH (t
) - 1);
318 /* If anything is wide, the non-wides will be converted,
319 which makes them take more space. */
321 length
= length
* wchar_bytes
+ wide_length
;
323 p
= ggc_alloc_string (NULL
, length
);
325 /* Copy the individual strings into the new combined string.
326 If the combined string is wide, convert the chars to ints
327 for any individual strings that are not wide. */
330 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
332 int len
= (TREE_STRING_LENGTH (t
)
333 - ((TREE_TYPE (t
) == wchar_array_type_node
)
335 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
337 memcpy (q
, TREE_STRING_POINTER (t
), len
);
343 for (i
= 0; i
< len
; i
++)
345 if (WCHAR_TYPE_SIZE
== HOST_BITS_PER_SHORT
)
346 ((short *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
348 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
350 q
+= len
* wchar_bytes
;
356 for (i
= 0; i
< wchar_bytes
; i
++)
362 value
= make_node (STRING_CST
);
363 TREE_STRING_POINTER (value
) = p
;
364 TREE_STRING_LENGTH (value
) = length
;
369 length
= TREE_STRING_LENGTH (value
);
370 if (TREE_TYPE (value
) == wchar_array_type_node
)
374 /* Compute the number of elements, for the array type. */
375 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
377 if (pedantic
&& nchars
> nchars_max
)
378 pedwarn ("string length `%d' is greater than the minimum length `%d' ANSI C is required to support",
381 /* Create the array type for the string constant.
382 -Wwrite-strings says make the string constant an array of const char
383 so that copying it to a non-const pointer will get a warning.
384 For C++, this is the standard behavior. */
385 if (flag_const_strings
386 && (! flag_traditional
&& ! flag_writable_strings
))
389 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
392 = build_array_type (elements
,
393 build_index_type (build_int_2 (nchars
- 1, 0)));
397 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
398 build_index_type (build_int_2 (nchars
- 1, 0)));
400 TREE_CONSTANT (value
) = 1;
401 TREE_READONLY (value
) = ! flag_writable_strings
;
402 TREE_STATIC (value
) = 1;
406 /* To speed up processing of attributes, we maintain an array of
407 IDENTIFIER_NODES and the corresponding attribute types. */
409 /* Array to hold attribute information. */
411 static struct {enum attrs id
; tree name
; int min
, max
, decl_req
;} attrtab
[50];
413 static int attrtab_idx
= 0;
415 /* Add an entry to the attribute table above. */
418 add_attribute (id
, string
, min_len
, max_len
, decl_req
)
421 int min_len
, max_len
;
426 attrtab
[attrtab_idx
].id
= id
;
427 attrtab
[attrtab_idx
].name
= get_identifier (string
);
428 attrtab
[attrtab_idx
].min
= min_len
;
429 attrtab
[attrtab_idx
].max
= max_len
;
430 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
432 sprintf (buf
, "__%s__", string
);
434 attrtab
[attrtab_idx
].id
= id
;
435 attrtab
[attrtab_idx
].name
= get_identifier (buf
);
436 attrtab
[attrtab_idx
].min
= min_len
;
437 attrtab
[attrtab_idx
].max
= max_len
;
438 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
441 /* Initialize attribute table. */
446 add_attribute (A_PACKED
, "packed", 0, 0, 0);
447 add_attribute (A_NOCOMMON
, "nocommon", 0, 0, 1);
448 add_attribute (A_COMMON
, "common", 0, 0, 1);
449 add_attribute (A_NORETURN
, "noreturn", 0, 0, 1);
450 add_attribute (A_NORETURN
, "volatile", 0, 0, 1);
451 add_attribute (A_UNUSED
, "unused", 0, 0, 0);
452 add_attribute (A_CONST
, "const", 0, 0, 1);
453 add_attribute (A_T_UNION
, "transparent_union", 0, 0, 0);
454 add_attribute (A_CONSTRUCTOR
, "constructor", 0, 0, 1);
455 add_attribute (A_DESTRUCTOR
, "destructor", 0, 0, 1);
456 add_attribute (A_MODE
, "mode", 1, 1, 1);
457 add_attribute (A_SECTION
, "section", 1, 1, 1);
458 add_attribute (A_ALIGNED
, "aligned", 0, 1, 0);
459 add_attribute (A_FORMAT
, "format", 3, 3, 1);
460 add_attribute (A_FORMAT_ARG
, "format_arg", 1, 1, 1);
461 add_attribute (A_WEAK
, "weak", 0, 0, 1);
462 add_attribute (A_ALIAS
, "alias", 1, 1, 1);
463 add_attribute (A_NO_INSTRUMENT_FUNCTION
, "no_instrument_function", 0, 0, 1);
464 add_attribute (A_NO_CHECK_MEMORY_USAGE
, "no_check_memory_usage", 0, 0, 1);
465 add_attribute (A_MALLOC
, "malloc", 0, 0, 1);
466 add_attribute (A_NO_LIMIT_STACK
, "no_stack_limit", 0, 0, 1);
467 add_attribute (A_PURE
, "pure", 0, 0, 1);
470 /* Default implementation of valid_lang_attribute, below. By default, there
471 are no language-specific attributes. */
474 default_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
475 tree attr_name ATTRIBUTE_UNUSED
;
476 tree attr_args ATTRIBUTE_UNUSED
;
477 tree decl ATTRIBUTE_UNUSED
;
478 tree type ATTRIBUTE_UNUSED
;
483 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
484 attribute for either declaration DECL or type TYPE and 0 otherwise. */
486 int (*valid_lang_attribute
) PARAMS ((tree
, tree
, tree
, tree
))
487 = default_valid_lang_attribute
;
489 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
490 and install them in NODE, which is either a DECL (including a TYPE_DECL)
491 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
492 and declaration modifiers but before the declaration proper. */
495 decl_attributes (node
, attributes
, prefix_attributes
)
496 tree node
, attributes
, prefix_attributes
;
498 tree decl
= 0, type
= 0;
502 if (attrtab_idx
== 0)
508 type
= TREE_TYPE (decl
);
509 is_type
= TREE_CODE (node
) == TYPE_DECL
;
511 else if (TYPE_P (node
))
512 type
= node
, is_type
= 1;
514 #ifdef PRAGMA_INSERT_ATTRIBUTES
515 /* If the code in c-pragma.c wants to insert some attributes then
516 allow it to do so. Do this before allowing machine back ends to
517 insert attributes, so that they have the opportunity to override
518 anything done here. */
519 PRAGMA_INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
522 #ifdef INSERT_ATTRIBUTES
523 INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
526 attributes
= chainon (prefix_attributes
, attributes
);
528 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
530 tree name
= TREE_PURPOSE (a
);
531 tree args
= TREE_VALUE (a
);
535 for (i
= 0; i
< attrtab_idx
; i
++)
536 if (attrtab
[i
].name
== name
)
539 if (i
== attrtab_idx
)
541 if (! valid_machine_attribute (name
, args
, decl
, type
)
542 && ! (* valid_lang_attribute
) (name
, args
, decl
, type
))
543 warning ("`%s' attribute directive ignored",
544 IDENTIFIER_POINTER (name
));
546 type
= TREE_TYPE (decl
);
549 else if (attrtab
[i
].decl_req
&& decl
== 0)
551 warning ("`%s' attribute does not apply to types",
552 IDENTIFIER_POINTER (name
));
555 else if (list_length (args
) < attrtab
[i
].min
556 || list_length (args
) > attrtab
[i
].max
)
558 error ("wrong number of arguments specified for `%s' attribute",
559 IDENTIFIER_POINTER (name
));
568 TYPE_PACKED (type
) = 1;
569 else if (TREE_CODE (decl
) == FIELD_DECL
)
570 DECL_PACKED (decl
) = 1;
571 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
572 used for DECL_REGISTER. It wouldn't mean anything anyway. */
574 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
578 if (TREE_CODE (decl
) == VAR_DECL
)
579 DECL_COMMON (decl
) = 0;
581 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
585 if (TREE_CODE (decl
) == VAR_DECL
)
586 DECL_COMMON (decl
) = 1;
588 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
592 if (TREE_CODE (decl
) == FUNCTION_DECL
)
593 TREE_THIS_VOLATILE (decl
) = 1;
594 else if (TREE_CODE (type
) == POINTER_TYPE
595 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
596 TREE_TYPE (decl
) = type
598 (build_type_variant (TREE_TYPE (type
),
599 TREE_READONLY (TREE_TYPE (type
)), 1));
601 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
605 if (TREE_CODE (decl
) == FUNCTION_DECL
)
606 DECL_IS_MALLOC (decl
) = 1;
607 /* ??? TODO: Support types. */
609 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
615 TREE_USED (decl
) = 1;
617 TREE_USED (type
) = 1;
618 else if (TREE_CODE (decl
) == PARM_DECL
619 || TREE_CODE (decl
) == VAR_DECL
620 || TREE_CODE (decl
) == FUNCTION_DECL
621 || TREE_CODE (decl
) == LABEL_DECL
)
622 TREE_USED (decl
) = 1;
624 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
628 if (TREE_CODE (decl
) == FUNCTION_DECL
)
629 TREE_READONLY (decl
) = 1;
630 else if (TREE_CODE (type
) == POINTER_TYPE
631 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
632 TREE_TYPE (decl
) = type
634 (build_type_variant (TREE_TYPE (type
), 1,
635 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
637 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name
));
641 if (TREE_CODE (decl
) == FUNCTION_DECL
)
642 DECL_IS_PURE (decl
) = 1;
643 /* ??? TODO: Support types. */
645 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
651 && TREE_CODE (type
) == UNION_TYPE
653 || (TYPE_FIELDS (type
) != 0
654 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))))
655 TYPE_TRANSPARENT_UNION (type
) = 1;
656 else if (decl
!= 0 && TREE_CODE (decl
) == PARM_DECL
657 && TREE_CODE (type
) == UNION_TYPE
658 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))
659 DECL_TRANSPARENT_UNION (decl
) = 1;
661 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
665 if (TREE_CODE (decl
) == FUNCTION_DECL
666 && TREE_CODE (type
) == FUNCTION_TYPE
667 && decl_function_context (decl
) == 0)
669 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
670 TREE_USED (decl
) = 1;
673 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
677 if (TREE_CODE (decl
) == FUNCTION_DECL
678 && TREE_CODE (type
) == FUNCTION_TYPE
679 && decl_function_context (decl
) == 0)
681 DECL_STATIC_DESTRUCTOR (decl
) = 1;
682 TREE_USED (decl
) = 1;
685 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
689 if (TREE_CODE (TREE_VALUE (args
)) != IDENTIFIER_NODE
)
690 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
694 const char *p
= IDENTIFIER_POINTER (TREE_VALUE (args
));
695 int len
= strlen (p
);
696 enum machine_mode mode
= VOIDmode
;
699 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
700 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
702 char *newp
= (char *) alloca (len
- 1);
704 strcpy (newp
, &p
[2]);
705 newp
[len
- 4] = '\0';
709 /* Give this decl a type with the specified mode.
710 First check for the special modes. */
711 if (! strcmp (p
, "byte"))
713 else if (!strcmp (p
, "word"))
715 else if (! strcmp (p
, "pointer"))
718 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
719 if (!strcmp (p
, GET_MODE_NAME (j
)))
720 mode
= (enum machine_mode
) j
;
722 if (mode
== VOIDmode
)
723 error ("unknown machine mode `%s'", p
);
724 else if (0 == (typefm
= type_for_mode (mode
,
725 TREE_UNSIGNED (type
))))
726 error ("no data type for mode `%s'", p
);
729 TREE_TYPE (decl
) = type
= typefm
;
730 DECL_SIZE (decl
) = DECL_SIZE_UNIT (decl
) = 0;
731 layout_decl (decl
, 0);
737 #ifdef ASM_OUTPUT_SECTION_NAME
738 if ((TREE_CODE (decl
) == FUNCTION_DECL
739 || TREE_CODE (decl
) == VAR_DECL
)
740 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
742 if (TREE_CODE (decl
) == VAR_DECL
743 && current_function_decl
!= NULL_TREE
744 && ! TREE_STATIC (decl
))
745 error_with_decl (decl
,
746 "section attribute cannot be specified for local variables");
747 /* The decl may have already been given a section attribute from
748 a previous declaration. Ensure they match. */
749 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
750 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
751 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
752 error_with_decl (node
,
753 "section of `%s' conflicts with previous declaration");
755 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
758 error_with_decl (node
,
759 "section attribute not allowed for `%s'");
761 error_with_decl (node
,
762 "section attributes are not supported for this target");
769 = (args
? TREE_VALUE (args
)
770 : size_int (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
773 /* Strip any NOPs of any kind. */
774 while (TREE_CODE (align_expr
) == NOP_EXPR
775 || TREE_CODE (align_expr
) == CONVERT_EXPR
776 || TREE_CODE (align_expr
) == NON_LVALUE_EXPR
)
777 align_expr
= TREE_OPERAND (align_expr
, 0);
779 if (TREE_CODE (align_expr
) != INTEGER_CST
)
781 error ("requested alignment is not a constant");
785 if ((i
= tree_log2 (align_expr
)) == -1)
786 error ("requested alignment is not a power of 2");
787 else if (i
> HOST_BITS_PER_INT
- 2)
788 error ("requested alignment is too large");
793 DECL_ALIGN (decl
) = (1 << i
) * BITS_PER_UNIT
;
794 DECL_USER_ALIGN (decl
) = 1;
798 TYPE_ALIGN (type
) = (1 << i
) * BITS_PER_UNIT
;
799 TYPE_USER_ALIGN (type
) = 1;
802 else if (TREE_CODE (decl
) != VAR_DECL
803 && TREE_CODE (decl
) != FIELD_DECL
)
804 error_with_decl (decl
,
805 "alignment may not be specified for `%s'");
808 DECL_ALIGN (decl
) = (1 << i
) * BITS_PER_UNIT
;
809 DECL_USER_ALIGN (decl
) = 1;
816 tree format_type_id
= TREE_VALUE (args
);
817 tree format_num_expr
= TREE_VALUE (TREE_CHAIN (args
));
818 tree first_arg_num_expr
819 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
)));
820 unsigned HOST_WIDE_INT format_num
, first_arg_num
;
821 enum format_type format_type
;
823 unsigned int arg_num
;
825 if (TREE_CODE (decl
) != FUNCTION_DECL
)
827 error_with_decl (decl
,
828 "argument format specified for non-function `%s'");
832 if (TREE_CODE (format_type_id
) != IDENTIFIER_NODE
)
834 error ("unrecognized format specifier");
839 const char *p
= IDENTIFIER_POINTER (format_type_id
);
841 if (!strcmp (p
, "printf") || !strcmp (p
, "__printf__"))
842 format_type
= printf_format_type
;
843 else if (!strcmp (p
, "scanf") || !strcmp (p
, "__scanf__"))
844 format_type
= scanf_format_type
;
845 else if (!strcmp (p
, "strftime")
846 || !strcmp (p
, "__strftime__"))
847 format_type
= strftime_format_type
;
850 warning ("`%s' is an unrecognized format function type", p
);
855 /* Strip any conversions from the string index and first arg number
856 and verify they are constants. */
857 while (TREE_CODE (format_num_expr
) == NOP_EXPR
858 || TREE_CODE (format_num_expr
) == CONVERT_EXPR
859 || TREE_CODE (format_num_expr
) == NON_LVALUE_EXPR
)
860 format_num_expr
= TREE_OPERAND (format_num_expr
, 0);
862 while (TREE_CODE (first_arg_num_expr
) == NOP_EXPR
863 || TREE_CODE (first_arg_num_expr
) == CONVERT_EXPR
864 || TREE_CODE (first_arg_num_expr
) == NON_LVALUE_EXPR
)
865 first_arg_num_expr
= TREE_OPERAND (first_arg_num_expr
, 0);
867 if (TREE_CODE (format_num_expr
) != INTEGER_CST
868 || TREE_INT_CST_HIGH (format_num_expr
) != 0
869 || TREE_CODE (first_arg_num_expr
) != INTEGER_CST
870 || TREE_INT_CST_HIGH (first_arg_num_expr
) != 0)
872 error ("format string has invalid operand number");
876 format_num
= TREE_INT_CST_LOW (format_num_expr
);
877 first_arg_num
= TREE_INT_CST_LOW (first_arg_num_expr
);
878 if (first_arg_num
!= 0 && first_arg_num
<= format_num
)
880 error ("format string arg follows the args to be formatted");
884 /* If a parameter list is specified, verify that the format_num
885 argument is actually a string, in case the format attribute
887 argument
= TYPE_ARG_TYPES (type
);
890 for (arg_num
= 1; argument
!= 0 && arg_num
!= format_num
;
891 ++arg_num
, argument
= TREE_CHAIN (argument
))
895 || TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
896 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument
)))
899 error ("format string arg not a string type");
903 else if (first_arg_num
!= 0)
905 /* Verify that first_arg_num points to the last arg,
908 arg_num
++, argument
= TREE_CHAIN (argument
);
910 if (arg_num
!= first_arg_num
)
912 error ("args to be formatted is not '...'");
918 record_function_format (DECL_NAME (decl
),
919 DECL_ASSEMBLER_NAME (decl
),
920 format_type
, format_num
, first_arg_num
);
926 tree format_num_expr
= TREE_VALUE (args
);
927 unsigned HOST_WIDE_INT format_num
;
928 unsigned int arg_num
;
931 if (TREE_CODE (decl
) != FUNCTION_DECL
)
933 error_with_decl (decl
,
934 "argument format specified for non-function `%s'");
938 /* Strip any conversions from the first arg number and verify it
940 while (TREE_CODE (format_num_expr
) == NOP_EXPR
941 || TREE_CODE (format_num_expr
) == CONVERT_EXPR
942 || TREE_CODE (format_num_expr
) == NON_LVALUE_EXPR
)
943 format_num_expr
= TREE_OPERAND (format_num_expr
, 0);
945 if (TREE_CODE (format_num_expr
) != INTEGER_CST
946 || TREE_INT_CST_HIGH (format_num_expr
) != 0)
948 error ("format string has invalid operand number");
952 format_num
= TREE_INT_CST_LOW (format_num_expr
);
954 /* If a parameter list is specified, verify that the format_num
955 argument is actually a string, in case the format attribute
957 argument
= TYPE_ARG_TYPES (type
);
960 for (arg_num
= 1; argument
!= 0 && arg_num
!= format_num
;
961 ++arg_num
, argument
= TREE_CHAIN (argument
))
965 || TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
966 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument
)))
969 error ("format string arg not a string type");
974 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl
))) != POINTER_TYPE
975 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl
))))
978 error ("function does not return string type");
982 record_international_format (DECL_NAME (decl
),
983 DECL_ASSEMBLER_NAME (decl
),
993 if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
994 || (TREE_CODE (decl
) != FUNCTION_DECL
&& ! DECL_EXTERNAL (decl
)))
995 error_with_decl (decl
,
996 "`%s' defined both normally and as an alias");
997 else if (decl_function_context (decl
) == 0)
1001 id
= TREE_VALUE (args
);
1002 if (TREE_CODE (id
) != STRING_CST
)
1004 error ("alias arg not a string");
1007 id
= get_identifier (TREE_STRING_POINTER (id
));
1008 /* This counts as a use of the object pointed to. */
1011 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1012 DECL_INITIAL (decl
) = error_mark_node
;
1014 DECL_EXTERNAL (decl
) = 0;
1015 assemble_alias (decl
, id
);
1018 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
1021 case A_NO_CHECK_MEMORY_USAGE
:
1022 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1024 error_with_decl (decl
,
1025 "`%s' attribute applies only to functions",
1026 IDENTIFIER_POINTER (name
));
1028 else if (DECL_INITIAL (decl
))
1030 error_with_decl (decl
,
1031 "can't set `%s' attribute after definition",
1032 IDENTIFIER_POINTER (name
));
1035 DECL_NO_CHECK_MEMORY_USAGE (decl
) = 1;
1038 case A_NO_INSTRUMENT_FUNCTION
:
1039 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1041 error_with_decl (decl
,
1042 "`%s' attribute applies only to functions",
1043 IDENTIFIER_POINTER (name
));
1045 else if (DECL_INITIAL (decl
))
1047 error_with_decl (decl
,
1048 "can't set `%s' attribute after definition",
1049 IDENTIFIER_POINTER (name
));
1052 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
1055 case A_NO_LIMIT_STACK
:
1056 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1058 error_with_decl (decl
,
1059 "`%s' attribute applies only to functions",
1060 IDENTIFIER_POINTER (name
));
1062 else if (DECL_INITIAL (decl
))
1064 error_with_decl (decl
,
1065 "can't set `%s' attribute after definition",
1066 IDENTIFIER_POINTER (name
));
1069 DECL_NO_LIMIT_STACK (decl
) = 1;
1075 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1076 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1078 The head of the declspec list is stored in DECLSPECS.
1079 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1081 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1082 the list elements. We drop the containing TREE_LIST nodes and link the
1083 resulting attributes together the way decl_attributes expects them. */
1086 split_specs_attrs (specs_attrs
, declspecs
, prefix_attributes
)
1088 tree
*declspecs
, *prefix_attributes
;
1090 tree t
, s
, a
, next
, specs
, attrs
;
1092 /* This can happen after an __extension__ in pedantic mode. */
1093 if (specs_attrs
!= NULL_TREE
1094 && TREE_CODE (specs_attrs
) == INTEGER_CST
)
1096 *declspecs
= NULL_TREE
;
1097 *prefix_attributes
= NULL_TREE
;
1101 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1102 if (specs_attrs
!= NULL_TREE
1103 && TREE_CODE (specs_attrs
) != TREE_LIST
)
1105 *declspecs
= specs_attrs
;
1106 *prefix_attributes
= NULL_TREE
;
1110 /* Remember to keep the lists in the same order, element-wise. */
1112 specs
= s
= NULL_TREE
;
1113 attrs
= a
= NULL_TREE
;
1114 for (t
= specs_attrs
; t
; t
= next
)
1116 next
= TREE_CHAIN (t
);
1117 /* Declspecs have a non-NULL TREE_VALUE. */
1118 if (TREE_VALUE (t
) != NULL_TREE
)
1120 if (specs
== NULL_TREE
)
1130 if (attrs
== NULL_TREE
)
1131 attrs
= a
= TREE_PURPOSE (t
);
1134 TREE_CHAIN (a
) = TREE_PURPOSE (t
);
1135 a
= TREE_PURPOSE (t
);
1137 /* More attrs can be linked here, move A to the end. */
1138 while (TREE_CHAIN (a
) != NULL_TREE
)
1143 /* Terminate the lists. */
1145 TREE_CHAIN (s
) = NULL_TREE
;
1147 TREE_CHAIN (a
) = NULL_TREE
;
1151 *prefix_attributes
= attrs
;
1154 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1155 This function is used by the parser when a rule will accept attributes
1156 in a particular position, but we don't want to support that just yet.
1158 A warning is issued for every ignored attribute. */
1161 strip_attrs (specs_attrs
)
1166 split_specs_attrs (specs_attrs
, &specs
, &attrs
);
1170 warning ("`%s' attribute ignored",
1171 IDENTIFIER_POINTER (TREE_PURPOSE (attrs
)));
1172 attrs
= TREE_CHAIN (attrs
);
1178 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1179 a parameter list. */
1181 #define T_I &integer_type_node
1182 #define T_L &long_integer_type_node
1183 #define T_LL &long_long_integer_type_node
1184 #define T_S &short_integer_type_node
1185 #define T_UI &unsigned_type_node
1186 #define T_UL &long_unsigned_type_node
1187 #define T_ULL &long_long_unsigned_type_node
1188 #define T_US &short_unsigned_type_node
1189 #define T_F &float_type_node
1190 #define T_D &double_type_node
1191 #define T_LD &long_double_type_node
1192 #define T_C &char_type_node
1193 #define T_UC &unsigned_char_type_node
1194 #define T_V &void_type_node
1195 #define T_W &wchar_type_node
1196 #define T_ST &sizetype
1199 const char *format_chars
;
1201 /* Type of argument if no length modifier is used. */
1203 /* Type of argument if length modifier for shortening to byte is used.
1204 If NULL, then this modifier is not allowed. */
1206 /* Type of argument if length modifier for shortening is used.
1207 If NULL, then this modifier is not allowed. */
1209 /* Type of argument if length modifier `l' is used.
1210 If NULL, then this modifier is not allowed. */
1212 /* Type of argument if length modifier `q' or `ll' is used.
1213 If NULL, then this modifier is not allowed. */
1215 /* Type of argument if length modifier `L' is used.
1216 If NULL, then this modifier is not allowed. */
1218 /* Type of argument if length modifiers 'z' or `Z' is used.
1219 If NULL, then this modifier is not allowed. */
1221 /* List of other modifier characters allowed with these options. */
1222 const char *flag_chars
;
1225 static format_char_info print_char_table
[] = {
1226 { "di", 0, T_I
, T_I
, T_I
, T_L
, T_LL
, T_LL
, T_ST
, "-wp0 +" },
1227 { "oxX", 0, T_UI
, T_UI
, T_UI
, T_UL
, T_ULL
, T_ULL
, T_ST
, "-wp0#" },
1228 { "u", 0, T_UI
, T_UI
, T_UI
, T_UL
, T_ULL
, T_ULL
, T_ST
, "-wp0" },
1229 /* A GNU extension. */
1230 { "m", 0, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-wp" },
1231 { "feEgGaA", 0, T_D
, NULL
, NULL
, NULL
, NULL
, T_LD
, NULL
, "-wp0 +#" },
1232 { "c", 0, T_I
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "-w" },
1233 { "C", 0, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-w" },
1234 { "s", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "-wp" },
1235 { "S", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-wp" },
1236 { "p", 1, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-w" },
1237 { "n", 1, T_I
, NULL
, T_S
, T_L
, T_LL
, NULL
, NULL
, "" },
1238 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1241 static format_char_info scan_char_table
[] = {
1242 { "di", 1, T_I
, T_C
, T_S
, T_L
, T_LL
, T_LL
, T_ST
, "*" },
1243 { "ouxX", 1, T_UI
, T_UC
, T_US
, T_UL
, T_ULL
, T_ULL
, T_ST
, "*" },
1244 { "efgEGaA", 1, T_F
, NULL
, NULL
, T_D
, NULL
, T_LD
, NULL
, "*" },
1245 { "c", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "*" },
1246 { "s", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "*a" },
1247 { "[", 1, T_C
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*a" },
1248 { "C", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*" },
1249 { "S", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*a" },
1250 { "p", 2, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*" },
1251 { "n", 1, T_I
, T_C
, T_S
, T_L
, T_LL
, NULL
, T_ST
, "" },
1252 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1255 /* Handle format characters recognized by glibc's strftime.c.
1256 '2' - MUST do years as only two digits
1257 '3' - MAY do years as only two digits (depending on locale)
1258 'E' - E modifier is acceptable
1259 'O' - O modifier is acceptable to Standard C
1260 'o' - O modifier is acceptable as a GNU extension
1261 'G' - other GNU extensions */
1263 static format_char_info time_char_table
[] = {
1264 { "y", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2EO-_0w" },
1265 { "D", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2" },
1266 { "g", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2O-_0w" },
1267 { "cx", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "3E" },
1268 { "%RTXnrt", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "" },
1269 { "P", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "G" },
1270 { "HIMSUWdemw", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0Ow" },
1271 { "Vju", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0Oow" },
1272 { "Gklsz", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0OGw" },
1273 { "ABZa", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "^#" },
1274 { "p", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "#" },
1275 { "bh", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "^" },
1276 { "CY", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0EOw" },
1277 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1280 typedef struct function_format_info
1282 struct function_format_info
*next
; /* next structure on the list */
1283 tree name
; /* identifier such as "printf" */
1284 tree assembler_name
; /* optional mangled identifier (for C++) */
1285 enum format_type format_type
; /* type of format (printf, scanf, etc.) */
1286 int format_num
; /* number of format argument */
1287 int first_arg_num
; /* number of first arg (zero for varargs) */
1288 } function_format_info
;
1290 static function_format_info
*function_format_list
= NULL
;
1292 typedef struct international_format_info
1294 struct international_format_info
*next
; /* next structure on the list */
1295 tree name
; /* identifier such as "gettext" */
1296 tree assembler_name
; /* optional mangled identifier (for C++) */
1297 int format_num
; /* number of format argument */
1298 } international_format_info
;
1300 static international_format_info
*international_format_list
= NULL
;
1302 static void check_format_info
PARAMS ((function_format_info
*, tree
));
1304 /* Initialize the table of functions to perform format checking on.
1305 The ANSI functions are always checked (whether <stdio.h> is
1306 included or not), since it is common to call printf without
1307 including <stdio.h>. There shouldn't be a problem with this,
1308 since ANSI reserves these function names whether you include the
1309 header file or not. In any case, the checking is harmless.
1311 Also initialize the name of function that modify the format string for
1312 internationalization purposes. */
1315 init_function_format_info ()
1317 record_function_format (get_identifier ("printf"), NULL_TREE
,
1318 printf_format_type
, 1, 2);
1319 record_function_format (get_identifier ("fprintf"), NULL_TREE
,
1320 printf_format_type
, 2, 3);
1321 record_function_format (get_identifier ("sprintf"), NULL_TREE
,
1322 printf_format_type
, 2, 3);
1323 record_function_format (get_identifier ("scanf"), NULL_TREE
,
1324 scanf_format_type
, 1, 2);
1325 record_function_format (get_identifier ("fscanf"), NULL_TREE
,
1326 scanf_format_type
, 2, 3);
1327 record_function_format (get_identifier ("sscanf"), NULL_TREE
,
1328 scanf_format_type
, 2, 3);
1329 record_function_format (get_identifier ("vprintf"), NULL_TREE
,
1330 printf_format_type
, 1, 0);
1331 record_function_format (get_identifier ("vfprintf"), NULL_TREE
,
1332 printf_format_type
, 2, 0);
1333 record_function_format (get_identifier ("vsprintf"), NULL_TREE
,
1334 printf_format_type
, 2, 0);
1335 record_function_format (get_identifier ("strftime"), NULL_TREE
,
1336 strftime_format_type
, 3, 0);
1338 record_international_format (get_identifier ("gettext"), NULL_TREE
, 1);
1339 record_international_format (get_identifier ("dgettext"), NULL_TREE
, 2);
1340 record_international_format (get_identifier ("dcgettext"), NULL_TREE
, 2);
1343 /* Record information for argument format checking. FUNCTION_IDENT is
1344 the identifier node for the name of the function to check (its decl
1345 need not exist yet).
1346 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
1347 of the argument which is the format control string (starting from 1).
1348 FIRST_ARG_NUM is the number of the first actual argument to check
1349 against the format string, or zero if no checking is not be done
1350 (e.g. for varargs such as vfprintf). */
1353 record_function_format (name
, assembler_name
, format_type
,
1354 format_num
, first_arg_num
)
1356 tree assembler_name
;
1357 enum format_type format_type
;
1361 function_format_info
*info
;
1363 /* Re-use existing structure if it's there. */
1365 for (info
= function_format_list
; info
; info
= info
->next
)
1367 if (info
->name
== name
&& info
->assembler_name
== assembler_name
)
1372 info
= (function_format_info
*) xmalloc (sizeof (function_format_info
));
1373 info
->next
= function_format_list
;
1374 function_format_list
= info
;
1377 info
->assembler_name
= assembler_name
;
1380 info
->format_type
= format_type
;
1381 info
->format_num
= format_num
;
1382 info
->first_arg_num
= first_arg_num
;
1385 /* Record information for the names of function that modify the format
1386 argument to format functions. FUNCTION_IDENT is the identifier node for
1387 the name of the function (its decl need not exist yet) and FORMAT_NUM is
1388 the number of the argument which is the format control string (starting
1392 record_international_format (name
, assembler_name
, format_num
)
1394 tree assembler_name
;
1397 international_format_info
*info
;
1399 /* Re-use existing structure if it's there. */
1401 for (info
= international_format_list
; info
; info
= info
->next
)
1403 if (info
->name
== name
&& info
->assembler_name
== assembler_name
)
1410 = (international_format_info
*)
1411 xmalloc (sizeof (international_format_info
));
1412 info
->next
= international_format_list
;
1413 international_format_list
= info
;
1416 info
->assembler_name
= assembler_name
;
1419 info
->format_num
= format_num
;
1425 warning ("too few arguments for format");
1428 /* Check the argument list of a call to printf, scanf, etc.
1429 NAME is the function identifier.
1430 ASSEMBLER_NAME is the function's assembler identifier.
1431 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1432 PARAMS is the list of argument values. */
1435 check_function_format (name
, assembler_name
, params
)
1437 tree assembler_name
;
1440 function_format_info
*info
;
1442 /* See if this function is a format function. */
1443 for (info
= function_format_list
; info
; info
= info
->next
)
1445 if (info
->assembler_name
1446 ? (info
->assembler_name
== assembler_name
)
1447 : (info
->name
== name
))
1449 /* Yup; check it. */
1450 check_format_info (info
, params
);
1456 /* Check the argument list of a call to printf, scanf, etc.
1457 INFO points to the function_format_info structure.
1458 PARAMS is the list of argument values. */
1461 check_format_info (info
, params
)
1462 function_format_info
*info
;
1467 int suppressed
, wide
, precise
;
1468 int length_char
= 0;
1475 tree first_fillin_param
;
1476 const char *format_chars
;
1477 format_char_info
*fci
= NULL
;
1479 int has_operand_number
= 0;
1481 /* Skip to format argument. If the argument isn't available, there's
1482 no work for us to do; prototype checking will catch the problem. */
1483 for (arg_num
= 1; ; ++arg_num
)
1487 if (arg_num
== info
->format_num
)
1489 params
= TREE_CHAIN (params
);
1491 format_tree
= TREE_VALUE (params
);
1492 params
= TREE_CHAIN (params
);
1493 if (format_tree
== 0)
1496 /* We can only check the format if it's a string constant. */
1497 while (TREE_CODE (format_tree
) == NOP_EXPR
)
1498 format_tree
= TREE_OPERAND (format_tree
, 0); /* strip coercion */
1500 if (TREE_CODE (format_tree
) == CALL_EXPR
1501 && TREE_CODE (TREE_OPERAND (format_tree
, 0)) == ADDR_EXPR
1502 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree
, 0), 0))
1505 tree function
= TREE_OPERAND (TREE_OPERAND (format_tree
, 0), 0);
1507 /* See if this is a call to a known internationalization function
1508 that modifies the format arg. */
1509 international_format_info
*info
;
1511 for (info
= international_format_list
; info
; info
= info
->next
)
1512 if (info
->assembler_name
1513 ? (info
->assembler_name
== DECL_ASSEMBLER_NAME (function
))
1514 : (info
->name
== DECL_NAME (function
)))
1519 for (inner_args
= TREE_OPERAND (format_tree
, 1), i
= 1;
1521 inner_args
= TREE_CHAIN (inner_args
), i
++)
1522 if (i
== info
->format_num
)
1524 format_tree
= TREE_VALUE (inner_args
);
1526 while (TREE_CODE (format_tree
) == NOP_EXPR
)
1527 format_tree
= TREE_OPERAND (format_tree
, 0);
1532 if (integer_zerop (format_tree
))
1534 warning ("null format string");
1537 if (TREE_CODE (format_tree
) != ADDR_EXPR
)
1539 /* The user may get multiple warnings if the supplied argument
1540 isn't even a string pointer. */
1541 /* Functions taking a va_list normally pass a non-literal format
1542 string. These functions typically are declared with
1543 first_arg_num == 0, so avoid warning in those cases. */
1544 if (info
->first_arg_num
!= 0 && warn_format
> 1)
1545 warning ("format not a string literal, argument types not checked");
1548 format_tree
= TREE_OPERAND (format_tree
, 0);
1549 if (TREE_CODE (format_tree
) != STRING_CST
)
1551 /* The user may get multiple warnings if the supplied argument
1552 isn't even a string pointer. */
1553 /* Functions taking a va_list normally pass a non-literal format
1554 string. These functions typically are declared with
1555 first_arg_num == 0, so avoid warning in those cases. */
1556 if (info
->first_arg_num
!= 0 && warn_format
> 1)
1557 warning ("format not a string literal, argument types not checked");
1560 format_chars
= TREE_STRING_POINTER (format_tree
);
1561 format_length
= TREE_STRING_LENGTH (format_tree
);
1562 if (format_length
<= 1)
1563 warning ("zero-length format string");
1564 if (format_chars
[--format_length
] != 0)
1566 warning ("unterminated format string");
1569 /* Skip to first argument to check. */
1570 while (arg_num
+ 1 < info
->first_arg_num
)
1574 params
= TREE_CHAIN (params
);
1578 first_fillin_param
= params
;
1582 if (*format_chars
== 0)
1584 if (format_chars
- TREE_STRING_POINTER (format_tree
) != format_length
)
1585 warning ("embedded `\\0' in format");
1586 if (info
->first_arg_num
!= 0 && params
!= 0 && ! has_operand_number
)
1587 warning ("too many arguments for format");
1590 if (*format_chars
++ != '%')
1592 if (*format_chars
== 0)
1594 warning ("spurious trailing `%%' in format");
1597 if (*format_chars
== '%')
1603 suppressed
= wide
= precise
= FALSE
;
1604 if (info
->format_type
== scanf_format_type
)
1606 suppressed
= *format_chars
== '*';
1609 while (ISDIGIT (*format_chars
))
1612 else if (info
->format_type
== strftime_format_type
)
1614 while (*format_chars
!= 0 && index ("_-0^#", *format_chars
) != 0)
1617 warning ("ANSI C does not support the strftime `%c' flag",
1619 if (index (flag_chars
, *format_chars
) != 0)
1621 warning ("repeated `%c' flag in format",
1627 i
= strlen (flag_chars
);
1628 flag_chars
[i
++] = *format_chars
++;
1632 while (ISDIGIT ((unsigned char) *format_chars
))
1637 if (wide
&& pedantic
)
1638 warning ("ANSI C does not support strftime format width");
1639 if (*format_chars
== 'E' || *format_chars
== 'O')
1641 i
= strlen (flag_chars
);
1642 flag_chars
[i
++] = *format_chars
++;
1644 if (*format_chars
== 'E' || *format_chars
== 'O')
1646 warning ("multiple E/O modifiers in format");
1647 while (*format_chars
== 'E' || *format_chars
== 'O')
1652 else if (info
->format_type
== printf_format_type
)
1654 /* See if we have a number followed by a dollar sign. If we do,
1655 it is an operand number, so set PARAMS to that operand. */
1656 if (*format_chars
>= '0' && *format_chars
<= '9')
1658 const char *p
= format_chars
;
1660 while (*p
>= '0' && *p
++ <= '9')
1665 int opnum
= atoi (format_chars
);
1667 params
= first_fillin_param
;
1668 format_chars
= p
+ 1;
1669 has_operand_number
= 1;
1671 for (i
= 1; i
< opnum
&& params
!= 0; i
++)
1672 params
= TREE_CHAIN (params
);
1674 if (opnum
== 0 || params
== 0)
1676 warning ("operand number out of range in format");
1682 while (*format_chars
!= 0 && index (" +#0-", *format_chars
) != 0)
1684 if (index (flag_chars
, *format_chars
) != 0)
1685 warning ("repeated `%c' flag in format", *format_chars
++);
1688 i
= strlen (flag_chars
);
1689 flag_chars
[i
++] = *format_chars
++;
1693 /* "If the space and + flags both appear,
1694 the space flag will be ignored." */
1695 if (index (flag_chars
, ' ') != 0
1696 && index (flag_chars
, '+') != 0)
1697 warning ("use of both ` ' and `+' flags in format");
1698 /* "If the 0 and - flags both appear,
1699 the 0 flag will be ignored." */
1700 if (index (flag_chars
, '0') != 0
1701 && index (flag_chars
, '-') != 0)
1702 warning ("use of both `0' and `-' flags in format");
1703 if (*format_chars
== '*')
1706 /* "...a field width...may be indicated by an asterisk.
1707 In this case, an int argument supplies the field width..." */
1714 if (info
->first_arg_num
!= 0)
1716 cur_param
= TREE_VALUE (params
);
1717 params
= TREE_CHAIN (params
);
1719 /* size_t is generally not valid here.
1720 It will work on most machines, because size_t and int
1721 have the same mode. But might as well warn anyway,
1722 since it will fail on other machines. */
1723 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1724 != integer_type_node
)
1726 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1727 != unsigned_type_node
))
1728 warning ("field width is not type int (arg %d)", arg_num
);
1733 while (ISDIGIT (*format_chars
))
1739 if (*format_chars
== '.')
1743 if (*format_chars
!= '*' && !ISDIGIT (*format_chars
))
1744 warning ("`.' not followed by `*' or digit in format");
1745 /* "...a...precision...may be indicated by an asterisk.
1746 In this case, an int argument supplies the...precision." */
1747 if (*format_chars
== '*')
1749 if (info
->first_arg_num
!= 0)
1757 cur_param
= TREE_VALUE (params
);
1758 params
= TREE_CHAIN (params
);
1760 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1761 != integer_type_node
)
1762 warning ("field width is not type int (arg %d)",
1768 while (ISDIGIT (*format_chars
))
1776 if (info
->format_type
!= strftime_format_type
)
1778 if (*format_chars
== 'h' || *format_chars
== 'l')
1779 length_char
= *format_chars
++;
1780 else if (*format_chars
== 'q' || *format_chars
== 'L')
1782 length_char
= *format_chars
++;
1783 if (length_char
== 'q' && pedantic
)
1784 warning ("ANSI C does not support the `%c' length modifier",
1787 else if (*format_chars
== 'Z' || *format_chars
== 'z')
1789 length_char
= *format_chars
++;
1790 if (pedantic
&& (length_char
== 'Z' || !flag_isoc99
))
1791 warning ("ANSI C does not support the `%c' length modifier",
1796 if (length_char
== 'l' && *format_chars
== 'l')
1798 length_char
= 'q', format_chars
++;
1799 if (pedantic
&& !flag_isoc99
)
1800 warning ("ANSI C does not support the `ll' length modifier");
1802 else if (length_char
== 'h' && *format_chars
== 'h')
1804 length_char
= 'H', format_chars
++;
1805 if (pedantic
&& !flag_isoc99
)
1806 warning ("ANSI C does not support the `hh' length modifier");
1808 if (*format_chars
== 'a' && info
->format_type
== scanf_format_type
)
1810 if (format_chars
[1] == 's' || format_chars
[1] == 'S'
1811 || format_chars
[1] == '[')
1813 /* `a' is used as a flag. */
1818 if (suppressed
&& length_char
!= 0)
1819 warning ("use of `*' and `%c' together in format", length_char
);
1821 format_char
= *format_chars
;
1822 if (format_char
== 0
1823 || (info
->format_type
!= strftime_format_type
&& format_char
== '%'))
1825 warning ("conversion lacks type at end of format");
1828 /* The m, C, and S formats are GNU extensions. */
1829 if (pedantic
&& info
->format_type
!= strftime_format_type
1830 && (format_char
== 'm' || format_char
== 'C' || format_char
== 'S'))
1831 warning ("ANSI C does not support the `%c' format", format_char
);
1832 /* The a and A formats are C99 extensions. */
1833 if (pedantic
&& info
->format_type
!= strftime_format_type
1834 && (format_char
== 'a' || format_char
== 'A')
1836 warning ("ANSI C does not support the `%c' format", format_char
);
1838 switch (info
->format_type
)
1840 case printf_format_type
:
1841 fci
= print_char_table
;
1843 case scanf_format_type
:
1844 fci
= scan_char_table
;
1846 case strftime_format_type
:
1847 fci
= time_char_table
;
1852 while (fci
->format_chars
!= 0
1853 && index (fci
->format_chars
, format_char
) == 0)
1855 if (fci
->format_chars
== 0)
1857 if (ISGRAPH(format_char
))
1858 warning ("unknown conversion type character `%c' in format",
1861 warning ("unknown conversion type character 0x%x in format",
1867 if (index (fci
->flag_chars
, 'G') != 0)
1868 warning ("ANSI C does not support `%%%c'", format_char
);
1869 if (index (fci
->flag_chars
, 'o') != 0
1870 && index (flag_chars
, 'O') != 0)
1871 warning ("ANSI C does not support `%%O%c'", format_char
);
1873 if (wide
&& index (fci
->flag_chars
, 'w') == 0)
1874 warning ("width used with `%c' format", format_char
);
1875 if (index (fci
->flag_chars
, '2') != 0)
1876 warning ("`%%%c' yields only last 2 digits of year", format_char
);
1877 else if (index (fci
->flag_chars
, '3') != 0)
1878 warning ("`%%%c' yields only last 2 digits of year in some locales",
1880 if (precise
&& index (fci
->flag_chars
, 'p') == 0)
1881 warning ("precision used with `%c' format", format_char
);
1882 if (aflag
&& index (fci
->flag_chars
, 'a') == 0)
1884 warning ("`a' flag used with `%c' format", format_char
);
1885 /* To simplify the following code. */
1888 /* The a flag is a GNU extension. */
1889 else if (pedantic
&& aflag
)
1890 warning ("ANSI C does not support the `a' flag");
1891 if (info
->format_type
== scanf_format_type
&& format_char
== '[')
1893 /* Skip over scan set, in case it happens to have '%' in it. */
1894 if (*format_chars
== '^')
1896 /* Find closing bracket; if one is hit immediately, then
1897 it's part of the scan set rather than a terminator. */
1898 if (*format_chars
== ']')
1900 while (*format_chars
&& *format_chars
!= ']')
1902 if (*format_chars
!= ']')
1903 /* The end of the format string was reached. */
1904 warning ("no closing `]' for `%%[' format");
1908 if (index (fci
->flag_chars
, '*') == 0)
1909 warning ("suppression of `%c' conversion in format", format_char
);
1912 for (i
= 0; flag_chars
[i
] != 0; ++i
)
1914 if (index (fci
->flag_chars
, flag_chars
[i
]) == 0)
1915 warning ("flag `%c' used with type `%c'",
1916 flag_chars
[i
], format_char
);
1918 if (info
->format_type
== strftime_format_type
)
1920 if (precise
&& index (flag_chars
, '0') != 0
1921 && (format_char
== 'd' || format_char
== 'i'
1922 || format_char
== 'o' || format_char
== 'u'
1923 || format_char
== 'x' || format_char
== 'X'))
1924 warning ("`0' flag ignored with precision specifier and `%c' format",
1926 switch (length_char
)
1928 default: wanted_type
= fci
->nolen
? *(fci
->nolen
) : 0; break;
1929 case 'H': wanted_type
= fci
->hhlen
? *(fci
->hhlen
) : 0; break;
1930 case 'h': wanted_type
= fci
->hlen
? *(fci
->hlen
) : 0; break;
1931 case 'l': wanted_type
= fci
->llen
? *(fci
->llen
) : 0; break;
1932 case 'q': wanted_type
= fci
->qlen
? *(fci
->qlen
) : 0; break;
1933 case 'L': wanted_type
= fci
->bigllen
? *(fci
->bigllen
) : 0; break;
1934 case 'z': case 'Z': wanted_type
= (fci
->zlen
1935 ? (TYPE_DOMAIN (*fci
->zlen
)
1936 ? TYPE_DOMAIN (*fci
->zlen
)
1940 if (wanted_type
== 0)
1941 warning ("use of `%c' length character with `%c' type character",
1942 length_char
, format_char
);
1943 else if (length_char
== 'L' && pedantic
1944 && !(format_char
== 'a' || format_char
== 'A'
1945 || format_char
== 'e' || format_char
== 'E'
1946 || format_char
== 'f' || format_char
== 'F'
1947 || format_char
== 'g' || format_char
== 'G'))
1948 warning ("ANSI C does not support the `L' length modifier with the `%c' type character",
1951 /* Finally. . .check type of argument against desired type! */
1952 if (info
->first_arg_num
== 0)
1954 if (fci
->pointer_count
== 0 && wanted_type
== void_type_node
)
1955 /* This specifier takes no argument. */
1962 cur_param
= TREE_VALUE (params
);
1963 params
= TREE_CHAIN (params
);
1965 cur_type
= TREE_TYPE (cur_param
);
1967 STRIP_NOPS (cur_param
);
1969 /* Check the types of any additional pointer arguments
1970 that precede the "real" argument. */
1971 for (i
= 0; i
< fci
->pointer_count
+ aflag
; ++i
)
1973 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
1975 cur_type
= TREE_TYPE (cur_type
);
1977 if (cur_param
!= 0 && TREE_CODE (cur_param
) == ADDR_EXPR
)
1978 cur_param
= TREE_OPERAND (cur_param
, 0);
1984 if (TREE_CODE (cur_type
) != ERROR_MARK
)
1986 if (fci
->pointer_count
+ aflag
== 1)
1987 warning ("format argument is not a pointer (arg %d)", arg_num
);
1989 warning ("format argument is not a pointer to a pointer (arg %d)", arg_num
);
1994 /* See if this is an attempt to write into a const type with
1995 scanf or with printf "%n". */
1996 if ((info
->format_type
== scanf_format_type
1997 || (info
->format_type
== printf_format_type
1998 && format_char
== 'n'))
1999 && i
== fci
->pointer_count
+ aflag
2001 && TREE_CODE (cur_type
) != ERROR_MARK
2002 && (TYPE_READONLY (cur_type
)
2004 && (TREE_CODE_CLASS (TREE_CODE (cur_param
)) == 'c'
2005 || (DECL_P (cur_param
) && TREE_READONLY (cur_param
))))))
2006 warning ("writing into constant object (arg %d)", arg_num
);
2008 /* Check the type of the "real" argument, if there's a type we want. */
2009 if (i
== fci
->pointer_count
+ aflag
&& wanted_type
!= 0
2010 && TREE_CODE (cur_type
) != ERROR_MARK
2011 && wanted_type
!= TYPE_MAIN_VARIANT (cur_type
)
2012 /* If we want `void *', allow any pointer type.
2013 (Anything else would already have got a warning.) */
2014 && ! (wanted_type
== void_type_node
2015 && fci
->pointer_count
> 0)
2016 /* Don't warn about differences merely in signedness. */
2017 && !(TREE_CODE (wanted_type
) == INTEGER_TYPE
2018 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type
)) == INTEGER_TYPE
2019 && (TREE_UNSIGNED (wanted_type
)
2020 ? wanted_type
== (cur_type
= unsigned_type (cur_type
))
2021 : wanted_type
== (cur_type
= signed_type (cur_type
))))
2022 /* Likewise, "signed char", "unsigned char" and "char" are
2023 equivalent but the above test won't consider them equivalent. */
2024 && ! (wanted_type
== char_type_node
2025 && (TYPE_MAIN_VARIANT (cur_type
) == signed_char_type_node
2026 || TYPE_MAIN_VARIANT (cur_type
) == unsigned_char_type_node
)))
2028 register const char *this;
2029 register const char *that
;
2031 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type
)));
2033 if (TREE_CODE (cur_type
) != ERROR_MARK
2034 && TYPE_NAME (cur_type
) != 0
2035 && TREE_CODE (cur_type
) != INTEGER_TYPE
2036 && !(TREE_CODE (cur_type
) == POINTER_TYPE
2037 && TREE_CODE (TREE_TYPE (cur_type
)) == INTEGER_TYPE
))
2039 if (TREE_CODE (TYPE_NAME (cur_type
)) == TYPE_DECL
2040 && DECL_NAME (TYPE_NAME (cur_type
)) != 0)
2041 that
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type
)));
2043 that
= IDENTIFIER_POINTER (TYPE_NAME (cur_type
));
2046 /* A nameless type can't possibly match what the format wants.
2047 So there will be a warning for it.
2048 Make up a string to describe vaguely what it is. */
2051 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
2054 that
= "different type";
2057 /* Make the warning better in case of mismatch of int vs long. */
2058 if (TREE_CODE (cur_type
) == INTEGER_TYPE
2059 && TREE_CODE (wanted_type
) == INTEGER_TYPE
2060 && TYPE_PRECISION (cur_type
) == TYPE_PRECISION (wanted_type
)
2061 && TYPE_NAME (cur_type
) != 0
2062 && TREE_CODE (TYPE_NAME (cur_type
)) == TYPE_DECL
)
2063 that
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type
)));
2065 if (strcmp (this, that
) != 0)
2066 warning ("%s format, %s arg (arg %d)", this, that
, arg_num
);
2071 /* Print a warning if a constant expression had overflow in folding.
2072 Invoke this function on every expression that the language
2073 requires to be a constant expression.
2074 Note the ANSI C standard says it is erroneous for a
2075 constant expression to overflow. */
2078 constant_expression_warning (value
)
2081 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
2082 || TREE_CODE (value
) == COMPLEX_CST
)
2083 && TREE_CONSTANT_OVERFLOW (value
) && pedantic
)
2084 pedwarn ("overflow in constant expression");
2087 /* Print a warning if an expression had overflow in folding.
2088 Invoke this function on every expression that
2089 (1) appears in the source code, and
2090 (2) might be a constant expression that overflowed, and
2091 (3) is not already checked by convert_and_check;
2092 however, do not invoke this function on operands of explicit casts. */
2095 overflow_warning (value
)
2098 if ((TREE_CODE (value
) == INTEGER_CST
2099 || (TREE_CODE (value
) == COMPLEX_CST
2100 && TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
))
2101 && TREE_OVERFLOW (value
))
2103 TREE_OVERFLOW (value
) = 0;
2104 if (skip_evaluation
== 0)
2105 warning ("integer overflow in expression");
2107 else if ((TREE_CODE (value
) == REAL_CST
2108 || (TREE_CODE (value
) == COMPLEX_CST
2109 && TREE_CODE (TREE_REALPART (value
)) == REAL_CST
))
2110 && TREE_OVERFLOW (value
))
2112 TREE_OVERFLOW (value
) = 0;
2113 if (skip_evaluation
== 0)
2114 warning ("floating point overflow in expression");
2118 /* Print a warning if a large constant is truncated to unsigned,
2119 or if -Wconversion is used and a constant < 0 is converted to unsigned.
2120 Invoke this function on every expression that might be implicitly
2121 converted to an unsigned type. */
2124 unsigned_conversion_warning (result
, operand
)
2125 tree result
, operand
;
2127 if (TREE_CODE (operand
) == INTEGER_CST
2128 && TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
2129 && TREE_UNSIGNED (TREE_TYPE (result
))
2130 && skip_evaluation
== 0
2131 && !int_fits_type_p (operand
, TREE_TYPE (result
)))
2133 if (!int_fits_type_p (operand
, signed_type (TREE_TYPE (result
))))
2134 /* This detects cases like converting -129 or 256 to unsigned char. */
2135 warning ("large integer implicitly truncated to unsigned type");
2136 else if (warn_conversion
)
2137 warning ("negative integer implicitly converted to unsigned type");
2141 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2142 Invoke this function on every expression that is converted implicitly,
2143 i.e. because of language rules and not because of an explicit cast. */
2146 convert_and_check (type
, expr
)
2149 tree t
= convert (type
, expr
);
2150 if (TREE_CODE (t
) == INTEGER_CST
)
2152 if (TREE_OVERFLOW (t
))
2154 TREE_OVERFLOW (t
) = 0;
2156 /* Do not diagnose overflow in a constant expression merely
2157 because a conversion overflowed. */
2158 TREE_CONSTANT_OVERFLOW (t
) = TREE_CONSTANT_OVERFLOW (expr
);
2160 /* No warning for converting 0x80000000 to int. */
2161 if (!(TREE_UNSIGNED (type
) < TREE_UNSIGNED (TREE_TYPE (expr
))
2162 && TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
2163 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (expr
))))
2164 /* If EXPR fits in the unsigned version of TYPE,
2165 don't warn unless pedantic. */
2167 || TREE_UNSIGNED (type
)
2168 || ! int_fits_type_p (expr
, unsigned_type (type
)))
2169 && skip_evaluation
== 0)
2170 warning ("overflow in implicit constant conversion");
2173 unsigned_conversion_warning (t
, expr
);
2179 c_expand_expr_stmt (expr
)
2182 /* Do default conversion if safe and possibly important,
2183 in case within ({...}). */
2184 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
2185 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
2186 expr
= default_conversion (expr
);
2188 if (TREE_TYPE (expr
) != error_mark_node
2189 && !COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (expr
))
2190 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
2191 error ("expression statement has incomplete type");
2193 expand_expr_stmt (expr
);
2196 /* Validate the expression after `case' and apply default promotions. */
2199 check_case_value (value
)
2202 if (value
== NULL_TREE
)
2205 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2206 STRIP_TYPE_NOPS (value
);
2208 if (TREE_CODE (value
) != INTEGER_CST
2209 && value
!= error_mark_node
)
2211 error ("case label does not reduce to an integer constant");
2212 value
= error_mark_node
;
2215 /* Promote char or short to int. */
2216 value
= default_conversion (value
);
2218 constant_expression_warning (value
);
2223 /* Return an integer type with BITS bits of precision,
2224 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2227 type_for_size (bits
, unsignedp
)
2231 if (bits
== TYPE_PRECISION (integer_type_node
))
2232 return unsignedp
? unsigned_type_node
: integer_type_node
;
2234 if (bits
== TYPE_PRECISION (signed_char_type_node
))
2235 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2237 if (bits
== TYPE_PRECISION (short_integer_type_node
))
2238 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2240 if (bits
== TYPE_PRECISION (long_integer_type_node
))
2241 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2243 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
2244 return (unsignedp
? long_long_unsigned_type_node
2245 : long_long_integer_type_node
);
2247 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
2248 return (unsignedp
? widest_unsigned_literal_type_node
2249 : widest_integer_literal_type_node
);
2251 if (bits
<= TYPE_PRECISION (intQI_type_node
))
2252 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2254 if (bits
<= TYPE_PRECISION (intHI_type_node
))
2255 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2257 if (bits
<= TYPE_PRECISION (intSI_type_node
))
2258 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2260 if (bits
<= TYPE_PRECISION (intDI_type_node
))
2261 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2266 /* Return a data type that has machine mode MODE.
2267 If the mode is an integer,
2268 then UNSIGNEDP selects between signed and unsigned types. */
2271 type_for_mode (mode
, unsignedp
)
2272 enum machine_mode mode
;
2275 if (mode
== TYPE_MODE (integer_type_node
))
2276 return unsignedp
? unsigned_type_node
: integer_type_node
;
2278 if (mode
== TYPE_MODE (signed_char_type_node
))
2279 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2281 if (mode
== TYPE_MODE (short_integer_type_node
))
2282 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2284 if (mode
== TYPE_MODE (long_integer_type_node
))
2285 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2287 if (mode
== TYPE_MODE (long_long_integer_type_node
))
2288 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2290 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
2291 return unsignedp
? widest_unsigned_literal_type_node
2292 : widest_integer_literal_type_node
;
2294 if (mode
== TYPE_MODE (intQI_type_node
))
2295 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2297 if (mode
== TYPE_MODE (intHI_type_node
))
2298 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2300 if (mode
== TYPE_MODE (intSI_type_node
))
2301 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2303 if (mode
== TYPE_MODE (intDI_type_node
))
2304 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2306 #if HOST_BITS_PER_WIDE_INT >= 64
2307 if (mode
== TYPE_MODE (intTI_type_node
))
2308 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2311 if (mode
== TYPE_MODE (float_type_node
))
2312 return float_type_node
;
2314 if (mode
== TYPE_MODE (double_type_node
))
2315 return double_type_node
;
2317 if (mode
== TYPE_MODE (long_double_type_node
))
2318 return long_double_type_node
;
2320 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
2321 return build_pointer_type (char_type_node
);
2323 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
2324 return build_pointer_type (integer_type_node
);
2326 #ifdef VECTOR_MODE_SUPPORTED_P
2327 if (mode
== TYPE_MODE (V4SF_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
2328 return V4SF_type_node
;
2329 if (mode
== TYPE_MODE (V4SI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
2330 return V4SI_type_node
;
2331 if (mode
== TYPE_MODE (V2SI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
2332 return V2SI_type_node
;
2333 if (mode
== TYPE_MODE (V4HI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
2334 return V4HI_type_node
;
2335 if (mode
== TYPE_MODE (V8QI_type_node
) && VECTOR_MODE_SUPPORTED_P (mode
))
2336 return V8QI_type_node
;
2342 /* Return an unsigned type the same as TYPE in other respects. */
2344 unsigned_type (type
)
2347 tree type1
= TYPE_MAIN_VARIANT (type
);
2348 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
2349 return unsigned_char_type_node
;
2350 if (type1
== integer_type_node
)
2351 return unsigned_type_node
;
2352 if (type1
== short_integer_type_node
)
2353 return short_unsigned_type_node
;
2354 if (type1
== long_integer_type_node
)
2355 return long_unsigned_type_node
;
2356 if (type1
== long_long_integer_type_node
)
2357 return long_long_unsigned_type_node
;
2358 if (type1
== widest_integer_literal_type_node
)
2359 return widest_unsigned_literal_type_node
;
2360 #if HOST_BITS_PER_WIDE_INT >= 64
2361 if (type1
== intTI_type_node
)
2362 return unsigned_intTI_type_node
;
2364 if (type1
== intDI_type_node
)
2365 return unsigned_intDI_type_node
;
2366 if (type1
== intSI_type_node
)
2367 return unsigned_intSI_type_node
;
2368 if (type1
== intHI_type_node
)
2369 return unsigned_intHI_type_node
;
2370 if (type1
== intQI_type_node
)
2371 return unsigned_intQI_type_node
;
2373 return signed_or_unsigned_type (1, type
);
2376 /* Return a signed type the same as TYPE in other respects. */
2382 tree type1
= TYPE_MAIN_VARIANT (type
);
2383 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
2384 return signed_char_type_node
;
2385 if (type1
== unsigned_type_node
)
2386 return integer_type_node
;
2387 if (type1
== short_unsigned_type_node
)
2388 return short_integer_type_node
;
2389 if (type1
== long_unsigned_type_node
)
2390 return long_integer_type_node
;
2391 if (type1
== long_long_unsigned_type_node
)
2392 return long_long_integer_type_node
;
2393 if (type1
== widest_unsigned_literal_type_node
)
2394 return widest_integer_literal_type_node
;
2395 #if HOST_BITS_PER_WIDE_INT >= 64
2396 if (type1
== unsigned_intTI_type_node
)
2397 return intTI_type_node
;
2399 if (type1
== unsigned_intDI_type_node
)
2400 return intDI_type_node
;
2401 if (type1
== unsigned_intSI_type_node
)
2402 return intSI_type_node
;
2403 if (type1
== unsigned_intHI_type_node
)
2404 return intHI_type_node
;
2405 if (type1
== unsigned_intQI_type_node
)
2406 return intQI_type_node
;
2408 return signed_or_unsigned_type (0, type
);
2411 /* Return a type the same as TYPE except unsigned or
2412 signed according to UNSIGNEDP. */
2415 signed_or_unsigned_type (unsignedp
, type
)
2419 if (! INTEGRAL_TYPE_P (type
)
2420 || TREE_UNSIGNED (type
) == unsignedp
)
2423 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
2424 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2425 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
2426 return unsignedp
? unsigned_type_node
: integer_type_node
;
2427 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
2428 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2429 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
2430 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2431 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
2432 return (unsignedp
? long_long_unsigned_type_node
2433 : long_long_integer_type_node
);
2434 if (TYPE_PRECISION (type
) == TYPE_PRECISION (widest_integer_literal_type_node
))
2435 return (unsignedp
? widest_unsigned_literal_type_node
2436 : widest_integer_literal_type_node
);
2440 /* Return the minimum number of bits needed to represent VALUE in a
2441 signed or unsigned type, UNSIGNEDP says which. */
2444 min_precision (value
, unsignedp
)
2450 /* If the value is negative, compute its negative minus 1. The latter
2451 adjustment is because the absolute value of the largest negative value
2452 is one larger than the largest positive value. This is equivalent to
2453 a bit-wise negation, so use that operation instead. */
2455 if (tree_int_cst_sgn (value
) < 0)
2456 value
= fold (build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
));
2458 /* Return the number of bits needed, taking into account the fact
2459 that we need one more bit for a signed than unsigned type. */
2461 if (integer_zerop (value
))
2464 log
= tree_floor_log2 (value
);
2466 return log
+ 1 + ! unsignedp
;
2469 /* Print an error message for invalid operands to arith operation CODE.
2470 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2473 binary_op_error (code
)
2474 enum tree_code code
;
2476 register const char *opname
;
2481 error ("invalid truth-value expression");
2485 opname
= "+"; break;
2487 opname
= "-"; break;
2489 opname
= "*"; break;
2491 opname
= "max"; break;
2493 opname
= "min"; break;
2495 opname
= "=="; break;
2497 opname
= "!="; break;
2499 opname
= "<="; break;
2501 opname
= ">="; break;
2503 opname
= "<"; break;
2505 opname
= ">"; break;
2507 opname
= "<<"; break;
2509 opname
= ">>"; break;
2510 case TRUNC_MOD_EXPR
:
2511 case FLOOR_MOD_EXPR
:
2512 opname
= "%"; break;
2513 case TRUNC_DIV_EXPR
:
2514 case FLOOR_DIV_EXPR
:
2515 opname
= "/"; break;
2517 opname
= "&"; break;
2519 opname
= "|"; break;
2520 case TRUTH_ANDIF_EXPR
:
2521 opname
= "&&"; break;
2522 case TRUTH_ORIF_EXPR
:
2523 opname
= "||"; break;
2525 opname
= "^"; break;
2528 opname
= "rotate"; break;
2530 opname
= "unknown"; break;
2532 error ("invalid operands to binary %s", opname
);
2535 /* Subroutine of build_binary_op, used for comparison operations.
2536 See if the operands have both been converted from subword integer types
2537 and, if so, perhaps change them both back to their original type.
2538 This function is also responsible for converting the two operands
2539 to the proper common type for comparison.
2541 The arguments of this function are all pointers to local variables
2542 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2543 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2545 If this function returns nonzero, it means that the comparison has
2546 a constant value. What this function returns is an expression for
2550 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
2551 tree
*op0_ptr
, *op1_ptr
;
2553 enum tree_code
*rescode_ptr
;
2556 tree op0
= *op0_ptr
;
2557 tree op1
= *op1_ptr
;
2558 int unsignedp0
, unsignedp1
;
2560 tree primop0
, primop1
;
2561 enum tree_code code
= *rescode_ptr
;
2563 /* Throw away any conversions to wider types
2564 already present in the operands. */
2566 primop0
= get_narrower (op0
, &unsignedp0
);
2567 primop1
= get_narrower (op1
, &unsignedp1
);
2569 /* Handle the case that OP0 does not *contain* a conversion
2570 but it *requires* conversion to FINAL_TYPE. */
2572 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
2573 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
2574 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
2575 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
2577 /* If one of the operands must be floated, we cannot optimize. */
2578 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
2579 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
2581 /* If first arg is constant, swap the args (changing operation
2582 so value is preserved), for canonicalization. Don't do this if
2583 the second arg is 0. */
2585 if (TREE_CONSTANT (primop0
)
2586 && ! integer_zerop (primop1
) && ! real_zerop (primop1
))
2588 register tree tem
= primop0
;
2589 register int temi
= unsignedp0
;
2597 unsignedp0
= unsignedp1
;
2620 *rescode_ptr
= code
;
2623 /* If comparing an integer against a constant more bits wide,
2624 maybe we can deduce a value of 1 or 0 independent of the data.
2625 Or else truncate the constant now
2626 rather than extend the variable at run time.
2628 This is only interesting if the constant is the wider arg.
2629 Also, it is not safe if the constant is unsigned and the
2630 variable arg is signed, since in this case the variable
2631 would be sign-extended and then regarded as unsigned.
2632 Our technique fails in this case because the lowest/highest
2633 possible unsigned results don't follow naturally from the
2634 lowest/highest possible values of the variable operand.
2635 For just EQ_EXPR and NE_EXPR there is another technique that
2636 could be used: see if the constant can be faithfully represented
2637 in the other operand's type, by truncating it and reextending it
2638 and see if that preserves the constant's value. */
2640 if (!real1
&& !real2
2641 && TREE_CODE (primop1
) == INTEGER_CST
2642 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
2644 int min_gt
, max_gt
, min_lt
, max_lt
;
2645 tree maxval
, minval
;
2646 /* 1 if comparison is nominally unsigned. */
2647 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
2650 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
2652 /* If TYPE is an enumeration, then we need to get its min/max
2653 values from it's underlying integral type, not the enumerated
2655 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
2656 type
= type_for_size (TYPE_PRECISION (type
), unsignedp0
);
2658 maxval
= TYPE_MAX_VALUE (type
);
2659 minval
= TYPE_MIN_VALUE (type
);
2661 if (unsignedp
&& !unsignedp0
)
2662 *restype_ptr
= signed_type (*restype_ptr
);
2664 if (TREE_TYPE (primop1
) != *restype_ptr
)
2665 primop1
= convert (*restype_ptr
, primop1
);
2666 if (type
!= *restype_ptr
)
2668 minval
= convert (*restype_ptr
, minval
);
2669 maxval
= convert (*restype_ptr
, maxval
);
2672 if (unsignedp
&& unsignedp0
)
2674 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
2675 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
2676 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
2677 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
2681 min_gt
= INT_CST_LT (primop1
, minval
);
2682 max_gt
= INT_CST_LT (primop1
, maxval
);
2683 min_lt
= INT_CST_LT (minval
, primop1
);
2684 max_lt
= INT_CST_LT (maxval
, primop1
);
2688 /* This used to be a switch, but Genix compiler can't handle that. */
2689 if (code
== NE_EXPR
)
2691 if (max_lt
|| min_gt
)
2692 val
= boolean_true_node
;
2694 else if (code
== EQ_EXPR
)
2696 if (max_lt
|| min_gt
)
2697 val
= boolean_false_node
;
2699 else if (code
== LT_EXPR
)
2702 val
= boolean_true_node
;
2704 val
= boolean_false_node
;
2706 else if (code
== GT_EXPR
)
2709 val
= boolean_true_node
;
2711 val
= boolean_false_node
;
2713 else if (code
== LE_EXPR
)
2716 val
= boolean_true_node
;
2718 val
= boolean_false_node
;
2720 else if (code
== GE_EXPR
)
2723 val
= boolean_true_node
;
2725 val
= boolean_false_node
;
2728 /* If primop0 was sign-extended and unsigned comparison specd,
2729 we did a signed comparison above using the signed type bounds.
2730 But the comparison we output must be unsigned.
2732 Also, for inequalities, VAL is no good; but if the signed
2733 comparison had *any* fixed result, it follows that the
2734 unsigned comparison just tests the sign in reverse
2735 (positive values are LE, negative ones GE).
2736 So we can generate an unsigned comparison
2737 against an extreme value of the signed type. */
2739 if (unsignedp
&& !unsignedp0
)
2746 primop1
= TYPE_MIN_VALUE (type
);
2752 primop1
= TYPE_MAX_VALUE (type
);
2759 type
= unsigned_type (type
);
2762 if (!max_gt
&& !unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2764 /* This is the case of (char)x >?< 0x80, which people used to use
2765 expecting old C compilers to change the 0x80 into -0x80. */
2766 if (val
== boolean_false_node
)
2767 warning ("comparison is always false due to limited range of data type");
2768 if (val
== boolean_true_node
)
2769 warning ("comparison is always true due to limited range of data type");
2772 if (!min_lt
&& unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2774 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2775 if (val
== boolean_false_node
)
2776 warning ("comparison is always false due to limited range of data type");
2777 if (val
== boolean_true_node
)
2778 warning ("comparison is always true due to limited range of data type");
2783 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2784 if (TREE_SIDE_EFFECTS (primop0
))
2785 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
2789 /* Value is not predetermined, but do the comparison
2790 in the type of the operand that is not constant.
2791 TYPE is already properly set. */
2793 else if (real1
&& real2
2794 && (TYPE_PRECISION (TREE_TYPE (primop0
))
2795 == TYPE_PRECISION (TREE_TYPE (primop1
))))
2796 type
= TREE_TYPE (primop0
);
2798 /* If args' natural types are both narrower than nominal type
2799 and both extend in the same manner, compare them
2800 in the type of the wider arg.
2801 Otherwise must actually extend both to the nominal
2802 common type lest different ways of extending
2804 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2806 else if (unsignedp0
== unsignedp1
&& real1
== real2
2807 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
2808 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
2810 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
2811 type
= signed_or_unsigned_type (unsignedp0
2812 || TREE_UNSIGNED (*restype_ptr
),
2814 /* Make sure shorter operand is extended the right way
2815 to match the longer operand. */
2816 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
2818 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
2823 /* Here we must do the comparison on the nominal type
2824 using the args exactly as we received them. */
2825 type
= *restype_ptr
;
2829 if (!real1
&& !real2
&& integer_zerop (primop1
)
2830 && TREE_UNSIGNED (*restype_ptr
))
2836 /* All unsigned values are >= 0, so we warn if extra warnings
2837 are requested. However, if OP0 is a constant that is
2838 >= 0, the signedness of the comparison isn't an issue,
2839 so suppress the warning. */
2840 if (extra_warnings
&& !in_system_header
2841 && ! (TREE_CODE (primop0
) == INTEGER_CST
2842 && ! TREE_OVERFLOW (convert (signed_type (type
),
2844 warning ("comparison of unsigned expression >= 0 is always true");
2845 value
= boolean_true_node
;
2849 if (extra_warnings
&& !in_system_header
2850 && ! (TREE_CODE (primop0
) == INTEGER_CST
2851 && ! TREE_OVERFLOW (convert (signed_type (type
),
2853 warning ("comparison of unsigned expression < 0 is always false");
2854 value
= boolean_false_node
;
2863 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2864 if (TREE_SIDE_EFFECTS (primop0
))
2865 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
2872 *op0_ptr
= convert (type
, primop0
);
2873 *op1_ptr
= convert (type
, primop1
);
2875 *restype_ptr
= boolean_type_node
;
2880 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2881 or validate its data type for an `if' or `while' statement or ?..: exp.
2883 This preparation consists of taking the ordinary
2884 representation of an expression expr and producing a valid tree
2885 boolean expression describing whether expr is nonzero. We could
2886 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2887 but we optimize comparisons, &&, ||, and !.
2889 The resulting type should always be `boolean_type_node'. */
2892 truthvalue_conversion (expr
)
2895 if (TREE_CODE (expr
) == ERROR_MARK
)
2898 #if 0 /* This appears to be wrong for C++. */
2899 /* These really should return error_mark_node after 2.4 is stable.
2900 But not all callers handle ERROR_MARK properly. */
2901 switch (TREE_CODE (TREE_TYPE (expr
)))
2904 error ("struct type value used where scalar is required");
2905 return boolean_false_node
;
2908 error ("union type value used where scalar is required");
2909 return boolean_false_node
;
2912 error ("array type value used where scalar is required");
2913 return boolean_false_node
;
2920 switch (TREE_CODE (expr
))
2923 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
2924 case TRUTH_ANDIF_EXPR
:
2925 case TRUTH_ORIF_EXPR
:
2926 case TRUTH_AND_EXPR
:
2928 case TRUTH_XOR_EXPR
:
2929 case TRUTH_NOT_EXPR
:
2930 TREE_TYPE (expr
) = boolean_type_node
;
2937 return integer_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2940 return real_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2943 /* If we are taking the address of a external decl, it might be zero
2944 if it is weak, so we cannot optimize. */
2945 if (DECL_P (TREE_OPERAND (expr
, 0))
2946 && DECL_EXTERNAL (TREE_OPERAND (expr
, 0)))
2949 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
2950 return build (COMPOUND_EXPR
, boolean_type_node
,
2951 TREE_OPERAND (expr
, 0), boolean_true_node
);
2953 return boolean_true_node
;
2956 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
2957 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
2958 truthvalue_conversion (TREE_OPERAND (expr
, 0)),
2959 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2966 /* These don't change whether an object is non-zero or zero. */
2967 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2971 /* These don't change whether an object is zero or non-zero, but
2972 we can't ignore them if their second arg has side-effects. */
2973 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
2974 return build (COMPOUND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 1),
2975 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
2977 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2980 /* Distribute the conversion into the arms of a COND_EXPR. */
2981 return fold (build (COND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 0),
2982 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2983 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
2986 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2987 since that affects how `default_conversion' will behave. */
2988 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
2989 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
2991 /* fall through... */
2993 /* If this is widening the argument, we can ignore it. */
2994 if (TYPE_PRECISION (TREE_TYPE (expr
))
2995 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
2996 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
3000 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
3002 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
3003 && TREE_CODE (TREE_TYPE (expr
)) == REAL_TYPE
)
3005 /* fall through... */
3007 /* This and MINUS_EXPR can be changed into a comparison of the
3009 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
3010 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
3011 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
3012 TREE_OPERAND (expr
, 1), 1);
3013 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
3014 fold (build1 (NOP_EXPR
,
3015 TREE_TYPE (TREE_OPERAND (expr
, 0)),
3016 TREE_OPERAND (expr
, 1))), 1);
3019 if (integer_onep (TREE_OPERAND (expr
, 1))
3020 && TREE_TYPE (expr
) != boolean_type_node
)
3021 /* Using convert here would cause infinite recursion. */
3022 return build1 (NOP_EXPR
, boolean_type_node
, expr
);
3026 if (warn_parentheses
&& C_EXP_ORIGINAL_CODE (expr
) == MODIFY_EXPR
)
3027 warning ("suggest parentheses around assignment used as truth value");
3034 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
3036 tree tem
= save_expr (expr
);
3037 return (build_binary_op
3038 ((TREE_SIDE_EFFECTS (expr
)
3039 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
3040 truthvalue_conversion (build_unary_op (REALPART_EXPR
, tem
, 0)),
3041 truthvalue_conversion (build_unary_op (IMAGPART_EXPR
, tem
, 0)),
3045 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
3049 /* Read the rest of a #-directive from input stream FINPUT.
3050 In normal use, the directive name and the white space after it
3051 have already been read, so they won't be included in the result.
3052 We allow for the fact that the directive line may contain
3053 a newline embedded within a character or string literal which forms
3054 a part of the directive.
3056 The value is a string in a reusable buffer. It remains valid
3057 only until the next time this function is called. */
3058 unsigned char *yy_cur
, *yy_lim
;
3060 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
3061 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
3068 parse_in
.limit
= parse_in
.token_buffer
;
3069 cpp_token
= cpp_get_token (&parse_in
);
3070 if (cpp_token
== CPP_EOF
)
3072 yy_lim
= CPP_PWRITTEN (&parse_in
);
3073 yy_cur
= parse_in
.token_buffer
;
3074 if (yy_cur
< yy_lim
)
3080 get_directive_line ()
3082 static char *directive_buffer
= NULL
;
3083 static unsigned buffer_length
= 0;
3085 register char *buffer_limit
;
3086 register int looking_for
= 0;
3087 register int char_escaped
= 0;
3089 if (buffer_length
== 0)
3091 directive_buffer
= (char *)xmalloc (128);
3092 buffer_length
= 128;
3095 buffer_limit
= &directive_buffer
[buffer_length
];
3097 for (p
= directive_buffer
; ; )
3101 /* Make buffer bigger if it is full. */
3102 if (p
>= buffer_limit
)
3104 register unsigned bytes_used
= (p
- directive_buffer
);
3108 = (char *)xrealloc (directive_buffer
, buffer_length
);
3109 p
= &directive_buffer
[bytes_used
];
3110 buffer_limit
= &directive_buffer
[buffer_length
];
3115 /* Discard initial whitespace. */
3116 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
3119 /* Detect the end of the directive. */
3120 if (c
== '\n' && looking_for
== 0)
3129 return directive_buffer
;
3131 /* Handle string and character constant syntax. */
3134 if (looking_for
== c
&& !char_escaped
)
3135 looking_for
= 0; /* Found terminator... stop looking. */
3138 if (c
== '\'' || c
== '"')
3139 looking_for
= c
; /* Don't stop buffering until we see another
3140 another one of these (or an EOF). */
3142 /* Handle backslash. */
3143 char_escaped
= (c
== '\\' && ! char_escaped
);
3147 /* Read the rest of a #-directive from input stream FINPUT.
3148 In normal use, the directive name and the white space after it
3149 have already been read, so they won't be included in the result.
3150 We allow for the fact that the directive line may contain
3151 a newline embedded within a character or string literal which forms
3152 a part of the directive.
3154 The value is a string in a reusable buffer. It remains valid
3155 only until the next time this function is called.
3157 The terminating character ('\n' or EOF) is left in FINPUT for the
3158 caller to re-read. */
3161 get_directive_line (finput
)
3162 register FILE *finput
;
3164 static char *directive_buffer
= NULL
;
3165 static unsigned buffer_length
= 0;
3167 register char *buffer_limit
;
3168 register int looking_for
= 0;
3169 register int char_escaped
= 0;
3171 if (buffer_length
== 0)
3173 directive_buffer
= (char *)xmalloc (128);
3174 buffer_length
= 128;
3177 buffer_limit
= &directive_buffer
[buffer_length
];
3179 for (p
= directive_buffer
; ; )
3183 /* Make buffer bigger if it is full. */
3184 if (p
>= buffer_limit
)
3186 register unsigned bytes_used
= (p
- directive_buffer
);
3190 = (char *)xrealloc (directive_buffer
, buffer_length
);
3191 p
= &directive_buffer
[bytes_used
];
3192 buffer_limit
= &directive_buffer
[buffer_length
];
3197 /* Discard initial whitespace. */
3198 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
3201 /* Detect the end of the directive. */
3202 if (looking_for
== 0
3203 && (c
== '\n' || c
== EOF
))
3212 return directive_buffer
;
3214 /* Handle string and character constant syntax. */
3217 if (looking_for
== c
&& !char_escaped
)
3218 looking_for
= 0; /* Found terminator... stop looking. */
3221 if (c
== '\'' || c
== '"')
3222 looking_for
= c
; /* Don't stop buffering until we see another
3223 one of these (or an EOF). */
3225 /* Handle backslash. */
3226 char_escaped
= (c
== '\\' && ! char_escaped
);
3229 #endif /* !USE_CPPLIB */
3231 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3232 down to the element type of an array. */
3235 c_build_qualified_type (type
, type_quals
)
3239 /* A restrict-qualified pointer type must be a pointer to object or
3240 incomplete type. Note that the use of POINTER_TYPE_P also allows
3241 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
3242 the C++ front-end also use POINTER_TYPE for pointer-to-member
3243 values, so even though it should be illegal to use `restrict'
3244 with such an entity we don't flag that here. Thus, special case
3245 code for that case is required in the C++ front-end. */
3246 if ((type_quals
& TYPE_QUAL_RESTRICT
)
3247 && (!POINTER_TYPE_P (type
)
3248 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
))))
3250 error ("invalid use of `restrict'");
3251 type_quals
&= ~TYPE_QUAL_RESTRICT
;
3254 if (TREE_CODE (type
) == ARRAY_TYPE
)
3255 return build_array_type (c_build_qualified_type (TREE_TYPE (type
),
3257 TYPE_DOMAIN (type
));
3258 return build_qualified_type (type
, type_quals
);
3261 /* Apply the TYPE_QUALS to the new DECL. */
3264 c_apply_type_quals_to_decl (type_quals
, decl
)
3268 if ((type_quals
& TYPE_QUAL_CONST
)
3269 || (TREE_TYPE (decl
)
3270 && TREE_CODE (TREE_TYPE (decl
)) == REFERENCE_TYPE
))
3271 TREE_READONLY (decl
) = 1;
3272 if (type_quals
& TYPE_QUAL_VOLATILE
)
3274 TREE_SIDE_EFFECTS (decl
) = 1;
3275 TREE_THIS_VOLATILE (decl
) = 1;
3277 if (type_quals
& TYPE_QUAL_RESTRICT
)
3279 if (!TREE_TYPE (decl
)
3280 || !POINTER_TYPE_P (TREE_TYPE (decl
))
3281 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl
))))
3282 error ("invalid use of `restrict'");
3283 else if (flag_strict_aliasing
)
3285 /* No two restricted pointers can point at the same thing.
3286 However, a restricted pointer can point at the same thing
3287 as an unrestricted pointer, if that unrestricted pointer
3288 is based on the restricted pointer. So, we make the
3289 alias set for the restricted pointer a subset of the
3290 alias set for the type pointed to by the type of the
3293 HOST_WIDE_INT pointed_to_alias_set
3294 = get_alias_set (TREE_TYPE (TREE_TYPE (decl
)));
3296 if (pointed_to_alias_set
== 0)
3297 /* It's not legal to make a subset of alias set zero. */
3301 DECL_POINTER_ALIAS_SET (decl
) = new_alias_set ();
3302 record_alias_subset (pointed_to_alias_set
,
3303 DECL_POINTER_ALIAS_SET (decl
));
3310 /* Return the typed-based alias set for T, which may be an expression
3311 or a type. Return -1 if we don't do anything special. */
3314 lang_get_alias_set (t
)
3319 /* Permit type-punning when accessing a union, provided the access
3320 is directly through the union. For example, this code does not
3321 permit taking the address of a union member and then storing
3322 through it. Even the type-punning allowed here is a GCC
3323 extension, albeit a common and useful one; the C standard says
3324 that such accesses have implementation-defined behavior. */
3326 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
3327 u
= TREE_OPERAND (u
, 0))
3328 if (TREE_CODE (u
) == COMPONENT_REF
3329 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
3332 /* If this is a char *, the ANSI C standard says it can alias
3333 anything. Note that all references need do this. */
3334 if (TREE_CODE_CLASS (TREE_CODE (t
)) == 'r'
3335 && TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
3336 && TYPE_PRECISION (TREE_TYPE (t
)) == TYPE_PRECISION (char_type_node
))
3339 /* That's all the expressions we handle specially. */
3343 /* The C standard specifically allows aliasing between signed and
3344 unsigned variants of the same type. We treat the signed
3345 variant as canonical. */
3346 if (TREE_CODE (t
) == INTEGER_TYPE
&& TREE_UNSIGNED (t
))
3348 tree t1
= signed_type (t
);
3350 /* t1 == t can happen for boolean nodes which are always unsigned. */
3352 return get_alias_set (t1
);
3354 else if (POINTER_TYPE_P (t
))
3358 /* Unfortunately, there is no canonical form of a pointer type.
3359 In particular, if we have `typedef int I', then `int *', and
3360 `I *' are different types. So, we have to pick a canonical
3361 representative. We do this below.
3363 Technically, this approach is actually more conservative that
3364 it needs to be. In particular, `const int *' and `int *'
3365 chould be in different alias sets, according to the C and C++
3366 standard, since their types are not the same, and so,
3367 technically, an `int **' and `const int **' cannot point at
3370 But, the standard is wrong. In particular, this code is
3375 const int* const* cipp = &ip;
3377 And, it doesn't make sense for that to be legal unless you
3378 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
3379 the pointed-to types. This issue has been reported to the
3381 t1
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
3382 t1
= ((TREE_CODE (t
) == POINTER_TYPE
)
3383 ? build_pointer_type (t1
) : build_reference_type (t1
));
3385 return get_alias_set (t1
);
3387 /* It's not yet safe to use alias sets for classes in C++ because
3388 the TYPE_FIELDs list for a class doesn't mention base classes. */
3389 else if (c_language
== clk_cplusplus
&& AGGREGATE_TYPE_P (t
))
3395 /* Build tree nodes and builtin functions common to both C and C++ language
3397 CPLUS_MODE is nonzero if we are called from the C++ frontend, we generate
3398 some stricter prototypes in that case.
3399 NO_BUILTINS and NO_NONANSI_BUILTINS contain the respective values of
3400 the language frontend flags flag_no_builtin and
3401 flag_no_nonansi_builtin. */
3404 c_common_nodes_and_builtins (cplus_mode
, no_builtins
, no_nonansi_builtins
)
3405 int cplus_mode
, no_builtins
, no_nonansi_builtins
;
3408 tree memcpy_ftype
, memset_ftype
, strlen_ftype
;
3409 tree bzero_ftype
, bcmp_ftype
;
3410 tree endlink
, int_endlink
, double_endlink
, unsigned_endlink
;
3411 tree sizetype_endlink
;
3412 tree ptr_ftype
, ptr_ftype_unsigned
;
3413 tree void_ftype_any
, void_ftype_int
, int_ftype_any
;
3414 tree double_ftype_double
, double_ftype_double_double
;
3415 tree float_ftype_float
, ldouble_ftype_ldouble
;
3416 tree int_ftype_cptr_cptr_sizet
;
3417 tree int_ftype_string_string
, string_ftype_ptr_ptr
;
3418 tree long_ftype_long
;
3419 /* Either char* or void*. */
3420 tree traditional_ptr_type_node
;
3421 /* Either const char* or const void*. */
3422 tree traditional_cptr_type_node
;
3423 tree traditional_len_type_node
;
3424 tree traditional_len_endlink
;
3425 tree va_list_ref_type_node
;
3426 tree va_list_arg_type_node
;
3428 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_va_list"),
3429 va_list_type_node
));
3431 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_ptrdiff_t"),
3432 ptrdiff_type_node
));
3434 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_size_t"),
3437 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
3439 va_list_arg_type_node
= va_list_ref_type_node
=
3440 build_pointer_type (TREE_TYPE (va_list_type_node
));
3444 va_list_arg_type_node
= va_list_type_node
;
3445 va_list_ref_type_node
= build_reference_type (va_list_type_node
);
3448 endlink
= void_list_node
;
3449 int_endlink
= tree_cons (NULL_TREE
, integer_type_node
, endlink
);
3450 double_endlink
= tree_cons (NULL_TREE
, double_type_node
, endlink
);
3451 unsigned_endlink
= tree_cons (NULL_TREE
, unsigned_type_node
, endlink
);
3453 ptr_ftype
= build_function_type (ptr_type_node
, NULL_TREE
);
3454 ptr_ftype_unsigned
= build_function_type (ptr_type_node
, unsigned_endlink
);
3455 sizetype_endlink
= tree_cons (NULL_TREE
, TYPE_DOMAIN (sizetype
), endlink
);
3456 /* We realloc here because sizetype could be int or unsigned. S'ok. */
3457 ptr_ftype_sizetype
= build_function_type (ptr_type_node
, sizetype_endlink
);
3459 int_ftype_any
= build_function_type (integer_type_node
, NULL_TREE
);
3460 void_ftype_any
= build_function_type (void_type_node
, NULL_TREE
);
3461 void_ftype
= build_function_type (void_type_node
, endlink
);
3462 void_ftype_int
= build_function_type (void_type_node
, int_endlink
);
3464 = build_function_type (void_type_node
,
3465 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
3468 = build_function_type (float_type_node
,
3469 tree_cons (NULL_TREE
, float_type_node
, endlink
));
3472 = build_function_type (double_type_node
, double_endlink
);
3474 ldouble_ftype_ldouble
3475 = build_function_type (long_double_type_node
,
3476 tree_cons (NULL_TREE
, long_double_type_node
,
3479 double_ftype_double_double
3480 = build_function_type (double_type_node
,
3481 tree_cons (NULL_TREE
, double_type_node
,
3485 = build_function_type (integer_type_node
, int_endlink
);
3488 = build_function_type (long_integer_type_node
,
3489 tree_cons (NULL_TREE
, long_integer_type_node
,
3492 int_ftype_cptr_cptr_sizet
3493 = build_function_type (integer_type_node
,
3494 tree_cons (NULL_TREE
, const_ptr_type_node
,
3495 tree_cons (NULL_TREE
, const_ptr_type_node
,
3496 tree_cons (NULL_TREE
,
3500 /* Prototype for strcpy. */
3501 string_ftype_ptr_ptr
3502 = build_function_type (string_type_node
,
3503 tree_cons (NULL_TREE
, string_type_node
,
3504 tree_cons (NULL_TREE
,
3505 const_string_type_node
,
3508 traditional_len_type_node
= (flag_traditional
&& ! cplus_mode
3509 ? integer_type_node
: sizetype
);
3510 traditional_len_endlink
= tree_cons (NULL_TREE
, traditional_len_type_node
,
3513 /* Prototype for strcmp. */
3514 int_ftype_string_string
3515 = build_function_type (integer_type_node
,
3516 tree_cons (NULL_TREE
, const_string_type_node
,
3517 tree_cons (NULL_TREE
,
3518 const_string_type_node
,
3521 /* Prototype for strlen. */
3523 = build_function_type (traditional_len_type_node
,
3524 tree_cons (NULL_TREE
, const_string_type_node
,
3527 traditional_ptr_type_node
= (flag_traditional
&& ! cplus_mode
3528 ? string_type_node
: ptr_type_node
);
3529 traditional_cptr_type_node
= (flag_traditional
&& ! cplus_mode
3530 ? const_string_type_node
: const_ptr_type_node
);
3532 /* Prototype for memcpy. */
3534 = build_function_type (traditional_ptr_type_node
,
3535 tree_cons (NULL_TREE
, ptr_type_node
,
3536 tree_cons (NULL_TREE
, const_ptr_type_node
,
3537 sizetype_endlink
)));
3539 /* Prototype for memset. */
3541 = build_function_type (traditional_ptr_type_node
,
3542 tree_cons (NULL_TREE
, ptr_type_node
,
3543 tree_cons (NULL_TREE
, integer_type_node
,
3544 tree_cons (NULL_TREE
,
3548 /* Prototype for bzero. */
3550 = build_function_type (void_type_node
,
3551 tree_cons (NULL_TREE
, traditional_ptr_type_node
,
3552 traditional_len_endlink
));
3554 /* Prototype for bcmp. */
3556 = build_function_type (integer_type_node
,
3557 tree_cons (NULL_TREE
, traditional_cptr_type_node
,
3558 tree_cons (NULL_TREE
,
3559 traditional_cptr_type_node
,
3560 traditional_len_endlink
)));
3562 builtin_function ("__builtin_constant_p", default_function_type
,
3563 BUILT_IN_CONSTANT_P
, BUILT_IN_NORMAL
, NULL_PTR
);
3565 builtin_function ("__builtin_return_address", ptr_ftype_unsigned
,
3566 BUILT_IN_RETURN_ADDRESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3568 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned
,
3569 BUILT_IN_FRAME_ADDRESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3571 builtin_function ("__builtin_alloca", ptr_ftype_sizetype
,
3572 BUILT_IN_ALLOCA
, BUILT_IN_NORMAL
, "alloca");
3573 builtin_function ("__builtin_ffs", int_ftype_int
, BUILT_IN_FFS
,
3574 BUILT_IN_NORMAL
, NULL_PTR
);
3575 /* Define alloca, ffs as builtins.
3576 Declare _exit just to mark it as volatile. */
3577 if (! no_builtins
&& ! no_nonansi_builtins
)
3580 temp
= builtin_function ("alloca", ptr_ftype_sizetype
,
3581 BUILT_IN_ALLOCA
, BUILT_IN_NORMAL
, NULL_PTR
);
3582 /* Suppress error if redefined as a non-function. */
3583 DECL_BUILT_IN_NONANSI (temp
) = 1;
3585 temp
= builtin_function ("ffs", int_ftype_int
, BUILT_IN_FFS
,
3586 BUILT_IN_NORMAL
, NULL_PTR
);
3587 /* Suppress error if redefined as a non-function. */
3588 DECL_BUILT_IN_NONANSI (temp
) = 1;
3589 temp
= builtin_function ("_exit", void_ftype_int
,
3590 0, NOT_BUILT_IN
, NULL_PTR
);
3591 TREE_THIS_VOLATILE (temp
) = 1;
3592 TREE_SIDE_EFFECTS (temp
) = 1;
3593 /* Suppress error if redefined as a non-function. */
3594 DECL_BUILT_IN_NONANSI (temp
) = 1;
3596 /* The system prototypes for these functions have many
3597 variations, so don't specify parameters to avoid conflicts.
3598 The expand_* functions check the argument types anyway. */
3599 temp
= builtin_function ("bzero", void_ftype_any
,
3600 BUILT_IN_BZERO
, BUILT_IN_NORMAL
, NULL_PTR
);
3601 DECL_BUILT_IN_NONANSI (temp
) = 1;
3602 temp
= builtin_function ("bcmp", int_ftype_any
,
3603 BUILT_IN_BCMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3604 DECL_BUILT_IN_NONANSI (temp
) = 1;
3607 builtin_function ("__builtin_abs", int_ftype_int
, BUILT_IN_ABS
,
3608 BUILT_IN_NORMAL
, NULL_PTR
);
3609 builtin_function ("__builtin_fabsf", float_ftype_float
, BUILT_IN_FABS
,
3610 BUILT_IN_NORMAL
, NULL_PTR
);
3611 builtin_function ("__builtin_fabs", double_ftype_double
, BUILT_IN_FABS
,
3612 BUILT_IN_NORMAL
, NULL_PTR
);
3613 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
3614 BUILT_IN_NORMAL
, NULL_PTR
);
3615 builtin_function ("__builtin_labs", long_ftype_long
, BUILT_IN_LABS
,
3616 BUILT_IN_NORMAL
, NULL_PTR
);
3617 builtin_function ("__builtin_saveregs", ptr_ftype
, BUILT_IN_SAVEREGS
,
3618 BUILT_IN_NORMAL
, NULL_PTR
);
3619 builtin_function ("__builtin_classify_type", default_function_type
,
3620 BUILT_IN_CLASSIFY_TYPE
, BUILT_IN_NORMAL
, NULL_PTR
);
3621 builtin_function ("__builtin_next_arg", ptr_ftype
, BUILT_IN_NEXT_ARG
,
3622 BUILT_IN_NORMAL
, NULL_PTR
);
3623 builtin_function ("__builtin_args_info", int_ftype_int
, BUILT_IN_ARGS_INFO
,
3624 BUILT_IN_NORMAL
, NULL_PTR
);
3625 builtin_function ("__builtin_setjmp",
3626 build_function_type (integer_type_node
,
3627 tree_cons (NULL_TREE
, ptr_type_node
,
3629 BUILT_IN_SETJMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3630 builtin_function ("__builtin_longjmp",
3631 build_function_type (void_type_node
,
3632 tree_cons (NULL_TREE
, ptr_type_node
,
3633 tree_cons (NULL_TREE
,
3636 BUILT_IN_LONGJMP
, BUILT_IN_NORMAL
, NULL_PTR
);
3637 builtin_function ("__builtin_trap", void_ftype
, BUILT_IN_TRAP
,
3638 BUILT_IN_NORMAL
, NULL_PTR
);
3640 /* ISO C99 IEEE Unordered compares. */
3641 builtin_function ("__builtin_isgreater", default_function_type
,
3642 BUILT_IN_ISGREATER
, BUILT_IN_NORMAL
, NULL_PTR
);
3643 builtin_function ("__builtin_isgreaterequal", default_function_type
,
3644 BUILT_IN_ISGREATEREQUAL
, BUILT_IN_NORMAL
, NULL_PTR
);
3645 builtin_function ("__builtin_isless", default_function_type
,
3646 BUILT_IN_ISLESS
, BUILT_IN_NORMAL
, NULL_PTR
);
3647 builtin_function ("__builtin_islessequal", default_function_type
,
3648 BUILT_IN_ISLESSEQUAL
, BUILT_IN_NORMAL
, NULL_PTR
);
3649 builtin_function ("__builtin_islessgreater", default_function_type
,
3650 BUILT_IN_ISLESSGREATER
, BUILT_IN_NORMAL
, NULL_PTR
);
3651 builtin_function ("__builtin_isunordered", default_function_type
,
3652 BUILT_IN_ISUNORDERED
, BUILT_IN_NORMAL
, NULL_PTR
);
3654 /* Untyped call and return. */
3655 builtin_function ("__builtin_apply_args", ptr_ftype
,
3656 BUILT_IN_APPLY_ARGS
, BUILT_IN_NORMAL
, NULL_PTR
);
3658 temp
= tree_cons (NULL_TREE
,
3659 build_pointer_type (build_function_type (void_type_node
,
3661 tree_cons (NULL_TREE
,
3663 tree_cons (NULL_TREE
,
3666 builtin_function ("__builtin_apply",
3667 build_function_type (ptr_type_node
, temp
),
3668 BUILT_IN_APPLY
, BUILT_IN_NORMAL
, NULL_PTR
);
3669 builtin_function ("__builtin_return", void_ftype_ptr
,
3670 BUILT_IN_RETURN
, BUILT_IN_NORMAL
, NULL_PTR
);
3672 /* Support for varargs.h and stdarg.h. */
3673 builtin_function ("__builtin_varargs_start",
3674 build_function_type (void_type_node
,
3675 tree_cons (NULL_TREE
,
3676 va_list_ref_type_node
,
3678 BUILT_IN_VARARGS_START
, BUILT_IN_NORMAL
, NULL_PTR
);
3680 builtin_function ("__builtin_stdarg_start",
3681 build_function_type (void_type_node
,
3682 tree_cons (NULL_TREE
,
3683 va_list_ref_type_node
,
3685 BUILT_IN_STDARG_START
, BUILT_IN_NORMAL
, NULL_PTR
);
3687 builtin_function ("__builtin_va_end",
3688 build_function_type (void_type_node
,
3689 tree_cons (NULL_TREE
,
3690 va_list_ref_type_node
,
3692 BUILT_IN_VA_END
, BUILT_IN_NORMAL
, NULL_PTR
);
3694 builtin_function ("__builtin_va_copy",
3695 build_function_type (void_type_node
,
3696 tree_cons (NULL_TREE
,
3697 va_list_ref_type_node
,
3698 tree_cons (NULL_TREE
,
3699 va_list_arg_type_node
,
3701 BUILT_IN_VA_COPY
, BUILT_IN_NORMAL
, NULL_PTR
);
3703 /* ??? Ought to be `T __builtin_expect(T, T)' for any type T. */
3704 builtin_function ("__builtin_expect",
3705 build_function_type (long_integer_type_node
,
3706 tree_cons (NULL_TREE
,
3707 long_integer_type_node
,
3708 tree_cons (NULL_TREE
,
3709 long_integer_type_node
,
3711 BUILT_IN_EXPECT
, BUILT_IN_NORMAL
, NULL_PTR
);
3713 /* Currently under experimentation. */
3714 builtin_function ("__builtin_memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
,
3715 BUILT_IN_NORMAL
, "memcpy");
3716 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet
,
3717 BUILT_IN_MEMCMP
, BUILT_IN_NORMAL
, "memcmp");
3718 builtin_function ("__builtin_memset", memset_ftype
,
3719 BUILT_IN_MEMSET
, BUILT_IN_NORMAL
, "memset");
3720 builtin_function ("__builtin_bzero", bzero_ftype
,
3721 BUILT_IN_BZERO
, BUILT_IN_NORMAL
, "bzero");
3722 builtin_function ("__builtin_bcmp", bcmp_ftype
,
3723 BUILT_IN_BCMP
, BUILT_IN_NORMAL
, "bcmp");
3724 builtin_function ("__builtin_strcmp", int_ftype_string_string
,
3725 BUILT_IN_STRCMP
, BUILT_IN_NORMAL
, "strcmp");
3726 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr
,
3727 BUILT_IN_STRCPY
, BUILT_IN_NORMAL
, "strcpy");
3728 builtin_function ("__builtin_strlen", strlen_ftype
,
3729 BUILT_IN_STRLEN
, BUILT_IN_NORMAL
, "strlen");
3730 builtin_function ("__builtin_sqrtf", float_ftype_float
,
3731 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, "sqrtf");
3732 builtin_function ("__builtin_fsqrt", double_ftype_double
,
3733 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, "sqrt");
3734 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble
,
3735 BUILT_IN_FSQRT
, BUILT_IN_NORMAL
, "sqrtl");
3736 builtin_function ("__builtin_sinf", float_ftype_float
,
3737 BUILT_IN_SIN
, BUILT_IN_NORMAL
, "sinf");
3738 builtin_function ("__builtin_sin", double_ftype_double
,
3739 BUILT_IN_SIN
, BUILT_IN_NORMAL
, "sin");
3740 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble
,
3741 BUILT_IN_SIN
, BUILT_IN_NORMAL
, "sinl");
3742 builtin_function ("__builtin_cosf", float_ftype_float
,
3743 BUILT_IN_COS
, BUILT_IN_NORMAL
, "cosf");
3744 builtin_function ("__builtin_cos", double_ftype_double
,
3745 BUILT_IN_COS
, BUILT_IN_NORMAL
, "cos");
3746 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble
,
3747 BUILT_IN_COS
, BUILT_IN_NORMAL
, "cosl");
3751 builtin_function ("abs", int_ftype_int
, BUILT_IN_ABS
,
3752 BUILT_IN_NORMAL
, NULL_PTR
);
3753 builtin_function ("fabsf", float_ftype_float
, BUILT_IN_FABS
,
3754 BUILT_IN_NORMAL
, NULL_PTR
);
3755 builtin_function ("fabs", double_ftype_double
, BUILT_IN_FABS
,
3756 BUILT_IN_NORMAL
, NULL_PTR
);
3757 builtin_function ("fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
3758 BUILT_IN_NORMAL
, NULL_PTR
);
3759 builtin_function ("labs", long_ftype_long
, BUILT_IN_LABS
,
3760 BUILT_IN_NORMAL
, NULL_PTR
);
3761 builtin_function ("memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
,
3762 BUILT_IN_NORMAL
, NULL_PTR
);
3763 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet
, BUILT_IN_MEMCMP
,
3764 BUILT_IN_NORMAL
, NULL_PTR
);
3765 builtin_function ("memset", memset_ftype
, BUILT_IN_MEMSET
,
3766 BUILT_IN_NORMAL
, NULL_PTR
);
3767 builtin_function ("strcmp", int_ftype_string_string
, BUILT_IN_STRCMP
,
3768 BUILT_IN_NORMAL
, NULL_PTR
);
3769 builtin_function ("strcpy", string_ftype_ptr_ptr
, BUILT_IN_STRCPY
,
3770 BUILT_IN_NORMAL
, NULL_PTR
);
3771 builtin_function ("strlen", strlen_ftype
, BUILT_IN_STRLEN
,
3772 BUILT_IN_NORMAL
, NULL_PTR
);
3773 builtin_function ("sqrtf", float_ftype_float
, BUILT_IN_FSQRT
,
3774 BUILT_IN_NORMAL
, NULL_PTR
);
3775 builtin_function ("sqrt", double_ftype_double
, BUILT_IN_FSQRT
,
3776 BUILT_IN_NORMAL
, NULL_PTR
);
3777 builtin_function ("sqrtl", ldouble_ftype_ldouble
, BUILT_IN_FSQRT
,
3778 BUILT_IN_NORMAL
, NULL_PTR
);
3779 builtin_function ("sinf", float_ftype_float
, BUILT_IN_SIN
,
3780 BUILT_IN_NORMAL
, NULL_PTR
);
3781 builtin_function ("sin", double_ftype_double
, BUILT_IN_SIN
,
3782 BUILT_IN_NORMAL
, NULL_PTR
);
3783 builtin_function ("sinl", ldouble_ftype_ldouble
, BUILT_IN_SIN
,
3784 BUILT_IN_NORMAL
, NULL_PTR
);
3785 builtin_function ("cosf", float_ftype_float
, BUILT_IN_COS
,
3786 BUILT_IN_NORMAL
, NULL_PTR
);
3787 builtin_function ("cos", double_ftype_double
, BUILT_IN_COS
,
3788 BUILT_IN_NORMAL
, NULL_PTR
);
3789 builtin_function ("cosl", ldouble_ftype_ldouble
, BUILT_IN_COS
,
3790 BUILT_IN_NORMAL
, NULL_PTR
);
3792 /* Declare these functions volatile
3793 to avoid spurious "control drops through" warnings. */
3794 temp
= builtin_function ("abort", cplus_mode
? void_ftype
: void_ftype_any
,
3795 0, NOT_BUILT_IN
, NULL_PTR
);
3796 TREE_THIS_VOLATILE (temp
) = 1;
3797 TREE_SIDE_EFFECTS (temp
) = 1;
3799 #if 0 /* ??? The C++ frontend used to do this. */
3800 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3802 DECL_BUILT_IN_NONANSI (temp
) = 1;
3804 temp
= builtin_function ("exit",
3805 cplus_mode
? void_ftype_int
: void_ftype_any
,
3806 0, NOT_BUILT_IN
, NULL_PTR
);
3807 TREE_THIS_VOLATILE (temp
) = 1;
3808 TREE_SIDE_EFFECTS (temp
) = 1;
3810 #if 0 /* ??? The C++ frontend used to do this. */
3811 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3813 DECL_BUILT_IN_NONANSI (temp
) = 1;
3818 /* Support for these has not been written in either expand_builtin
3819 or build_function_call. */
3820 builtin_function ("__builtin_div", default_ftype
, BUILT_IN_DIV
,
3821 BUILT_IN_NORMAL
, NULL_PTR
);
3822 builtin_function ("__builtin_ldiv", default_ftype
, BUILT_IN_LDIV
,
3823 BUILT_IN_NORMAL
, NULL_PTR
);
3824 builtin_function ("__builtin_ffloor", double_ftype_double
, BUILT_IN_FFLOOR
,
3825 BUILT_IN_NORMAL
, NULL_PTR
);
3826 builtin_function ("__builtin_fceil", double_ftype_double
, BUILT_IN_FCEIL
,
3827 BUILT_IN_NORMAL
, NULL_PTR
);
3828 builtin_function ("__builtin_fmod", double_ftype_double_double
,
3829 BUILT_IN_FMOD
, BUILT_IN_NORMAL
, NULL_PTR
);
3830 builtin_function ("__builtin_frem", double_ftype_double_double
,
3831 BUILT_IN_FREM
, BUILT_IN_NORMAL
, NULL_PTR
);
3832 builtin_function ("__builtin_getexp", double_ftype_double
, BUILT_IN_GETEXP
,
3833 BUILT_IN_NORMAL
, NULL_PTR
);
3834 builtin_function ("__builtin_getman", double_ftype_double
, BUILT_IN_GETMAN
,
3835 BUILT_IN_NORMAL
, NULL_PTR
);
3838 /* ??? Perhaps there's a better place to do this. But it is related
3839 to __builtin_va_arg, so it isn't that off-the-wall. */
3840 lang_type_promotes_to
= simple_type_promotes_to
;
3844 build_va_arg (expr
, type
)
3847 return build1 (VA_ARG_EXPR
, type
, expr
);
3850 /* Given a type, apply default promotions wrt unnamed function arguments
3851 and return the new type. Return NULL_TREE if no change. */
3852 /* ??? There is a function of the same name in the C++ front end that
3853 does something similar, but is more thorough and does not return NULL
3854 if no change. We could perhaps share code, but it would make the
3855 self_promoting_type property harder to identify. */
3858 simple_type_promotes_to (type
)
3861 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3862 return double_type_node
;
3864 if (C_PROMOTING_INTEGER_TYPE_P (type
))
3866 /* Traditionally, unsignedness is preserved in default promotions.
3867 Also preserve unsignedness if not really getting any wider. */
3868 if (TREE_UNSIGNED (type
)
3869 && (flag_traditional
3870 || TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
3871 return unsigned_type_node
;
3872 return integer_type_node
;
3878 /* Return 1 if PARMS specifies a fixed number of parameters
3879 and none of their types is affected by default promotions. */
3882 self_promoting_args_p (parms
)
3886 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
3888 register tree type
= TREE_VALUE (t
);
3890 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
3896 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3899 if (C_PROMOTING_INTEGER_TYPE_P (type
))
3905 /* Recognize certain built-in functions so we can make tree-codes
3906 other than CALL_EXPR. We do this when it enables fold-const.c
3907 to do something useful. */
3908 /* ??? By rights this should go in builtins.c, but only C and C++
3909 implement build_{binary,unary}_op. Not exactly sure what bits
3910 of functionality are actually needed from those functions, or
3911 where the similar functionality exists in the other front ends. */
3914 expand_tree_builtin (function
, params
, coerced_params
)
3915 tree function
, params
, coerced_params
;
3917 enum tree_code code
;
3919 if (DECL_BUILT_IN_CLASS (function
) != BUILT_IN_NORMAL
)
3922 switch (DECL_FUNCTION_CODE (function
))
3927 if (coerced_params
== 0)
3928 return integer_zero_node
;
3929 return build_unary_op (ABS_EXPR
, TREE_VALUE (coerced_params
), 0);
3931 case BUILT_IN_ISGREATER
:
3932 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3938 case BUILT_IN_ISGREATEREQUAL
:
3939 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3945 case BUILT_IN_ISLESS
:
3946 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3952 case BUILT_IN_ISLESSEQUAL
:
3953 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3959 case BUILT_IN_ISLESSGREATER
:
3960 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
)
3966 case BUILT_IN_ISUNORDERED
:
3967 if (TARGET_FLOAT_FORMAT
!= IEEE_FLOAT_FORMAT
)
3968 return integer_zero_node
;
3969 code
= UNORDERED_EXPR
;
3977 || TREE_CHAIN (params
) == 0)
3979 error ("too few arguments to function `%s'",
3980 IDENTIFIER_POINTER (DECL_NAME (function
)));
3981 return error_mark_node
;
3983 else if (TREE_CHAIN (TREE_CHAIN (params
)) != 0)
3985 error ("too many arguments to function `%s'",
3986 IDENTIFIER_POINTER (DECL_NAME (function
)));
3987 return error_mark_node
;
3990 arg0
= TREE_VALUE (params
);
3991 arg1
= TREE_VALUE (TREE_CHAIN (params
));
3992 arg0
= build_binary_op (code
, arg0
, arg1
, 0);
3993 if (code
!= UNORDERED_EXPR
)
3994 arg0
= build_unary_op (TRUTH_NOT_EXPR
, arg0
, 0);
4006 /* Tree code classes. */
4008 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
4010 static char c_tree_code_type
[] = {
4012 #include "c-common.def"
4016 /* Table indexed by tree code giving number of expression
4017 operands beyond the fixed part of the node structure.
4018 Not used for types or decls. */
4020 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
4022 static int c_tree_code_length
[] = {
4024 #include "c-common.def"
4028 /* Names of tree components.
4029 Used for printing out the tree and error messages. */
4030 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
4032 static const char *c_tree_code_name
[] = {
4034 #include "c-common.def"
4038 /* Adds the tree codes specific to the C front end to the list of all
4044 memcpy (tree_code_type
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4046 (int)LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
);
4047 memcpy (tree_code_length
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4049 (LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (int));
4050 memcpy (tree_code_name
+ (int) LAST_AND_UNUSED_TREE_CODE
,
4052 (LAST_C_TREE_CODE
- (int)LAST_AND_UNUSED_TREE_CODE
) * sizeof (char *));