1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 93-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
37 cpp_options parse_options
;
38 enum cpp_token cpp_token
;
41 #ifndef WCHAR_TYPE_SIZE
43 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
45 #define WCHAR_TYPE_SIZE BITS_PER_WORD
49 /* The following symbols are subsumed in the c_global_trees array, and
50 listed here individually for documentation purposes.
52 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
54 tree short_integer_type_node;
55 tree long_integer_type_node;
56 tree long_long_integer_type_node;
58 tree short_unsigned_type_node;
59 tree long_unsigned_type_node;
60 tree long_long_unsigned_type_node;
62 tree boolean_type_node;
63 tree boolean_false_node;
64 tree boolean_true_node;
66 tree ptrdiff_type_node;
68 tree unsigned_char_type_node;
69 tree signed_char_type_node;
71 tree signed_wchar_type_node;
72 tree unsigned_wchar_type_node;
75 tree double_type_node;
76 tree long_double_type_node;
78 tree complex_integer_type_node;
79 tree complex_float_type_node;
80 tree complex_double_type_node;
81 tree complex_long_double_type_node;
89 tree unsigned_intQI_type_node;
90 tree unsigned_intHI_type_node;
91 tree unsigned_intSI_type_node;
92 tree unsigned_intDI_type_node;
93 tree unsigned_intTI_type_node;
95 tree widest_integer_literal_type_node;
96 tree widest_unsigned_literal_type_node;
98 Nodes for types `void *' and `const void *'.
100 tree ptr_type_node, const_ptr_type_node;
102 Nodes for types `char *' and `const char *'.
104 tree string_type_node, const_string_type_node;
106 Type `char[SOMENUMBER]'.
107 Used when an array of char is needed and the size is irrelevant.
109 tree char_array_type_node;
111 Type `int[SOMENUMBER]' or something like it.
112 Used when an array of int needed and the size is irrelevant.
114 tree int_array_type_node;
116 Type `wchar_t[SOMENUMBER]' or something like it.
117 Used when a wide string literal is created.
119 tree wchar_array_type_node;
121 Type `int ()' -- used for implicit declaration of functions.
123 tree default_function_type;
125 Function types `int (int)', etc.
131 tree ptr_ftype_sizetype;
133 A VOID_TYPE node, packaged in a TREE_LIST.
139 tree c_global_trees
[CTI_MAX
];
141 /* Nonzero means the expression being parsed will never be evaluated.
142 This is a count, since unevaluated expressions can nest. */
145 enum attrs
{A_PACKED
, A_NOCOMMON
, A_COMMON
, A_NORETURN
, A_CONST
, A_T_UNION
,
146 A_NO_CHECK_MEMORY_USAGE
, A_NO_INSTRUMENT_FUNCTION
,
147 A_CONSTRUCTOR
, A_DESTRUCTOR
, A_MODE
, A_SECTION
, A_ALIGNED
,
148 A_UNUSED
, A_FORMAT
, A_FORMAT_ARG
, A_WEAK
, A_ALIAS
};
150 enum format_type
{ printf_format_type
, scanf_format_type
,
151 strftime_format_type
};
153 static void declare_hidden_char_array
PROTO((const char *, const char *));
154 static void add_attribute
PROTO((enum attrs
, const char *,
156 static void init_attributes
PROTO((void));
157 static void record_function_format
PROTO((tree
, tree
, enum format_type
,
159 static void record_international_format
PROTO((tree
, tree
, int));
160 static tree c_find_base_decl
PROTO((tree
));
161 static int default_valid_lang_attribute
PROTO ((tree
, tree
, tree
, tree
));
163 /* Keep a stack of if statements. We record the number of compound
164 statements seen up to the if keyword, as well as the line number
165 and file of the if. If a potentially ambiguous else is seen, that
166 fact is recorded; the warning is issued when we can be sure that
167 the enclosing if statement does not have an else branch. */
175 static void tfaff
PROTO((void));
177 static if_elt
*if_stack
;
179 /* Amount of space in the if statement stack. */
180 static int if_stack_space
= 0;
183 static int if_stack_pointer
= 0;
185 /* Generate RTL for the start of an if-then, and record the start of it
186 for ambiguous else detection. */
189 c_expand_start_cond (cond
, exitflag
, compstmt_count
)
194 /* Make sure there is enough space on the stack. */
195 if (if_stack_space
== 0)
198 if_stack
= (if_elt
*)xmalloc (10 * sizeof (if_elt
));
200 else if (if_stack_space
== if_stack_pointer
)
202 if_stack_space
+= 10;
203 if_stack
= (if_elt
*)xrealloc (if_stack
, if_stack_space
* sizeof (if_elt
));
206 /* Record this if statement. */
207 if_stack
[if_stack_pointer
].compstmt_count
= compstmt_count
;
208 if_stack
[if_stack_pointer
].file
= input_filename
;
209 if_stack
[if_stack_pointer
].line
= lineno
;
210 if_stack
[if_stack_pointer
].needs_warning
= 0;
213 expand_start_cond (cond
, exitflag
);
216 /* Generate RTL for the end of an if-then. Optionally warn if a nested
217 if statement had an ambiguous else clause. */
223 if (if_stack
[if_stack_pointer
].needs_warning
)
224 warning_with_file_and_line (if_stack
[if_stack_pointer
].file
,
225 if_stack
[if_stack_pointer
].line
,
226 "suggest explicit braces to avoid ambiguous `else'");
230 /* Generate RTL between the then-clause and the else-clause
231 of an if-then-else. */
234 c_expand_start_else ()
236 /* An ambiguous else warning must be generated for the enclosing if
237 statement, unless we see an else branch for that one, too. */
239 && if_stack_pointer
> 1
240 && (if_stack
[if_stack_pointer
- 1].compstmt_count
241 == if_stack
[if_stack_pointer
- 2].compstmt_count
))
242 if_stack
[if_stack_pointer
- 2].needs_warning
= 1;
244 /* Even if a nested if statement had an else branch, it can't be
245 ambiguous if this one also has an else. So don't warn in that
246 case. Also don't warn for any if statements nested in this else. */
247 if_stack
[if_stack_pointer
- 1].needs_warning
= 0;
248 if_stack
[if_stack_pointer
- 1].compstmt_count
--;
250 expand_start_else ();
253 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
256 declare_function_name ()
258 const char *name
, *printable_name
;
260 if (current_function_decl
== NULL
)
263 printable_name
= "top level";
267 /* Allow functions to be nameless (such as artificial ones). */
268 if (DECL_NAME (current_function_decl
))
269 name
= IDENTIFIER_POINTER (DECL_NAME (current_function_decl
));
272 printable_name
= (*decl_printable_name
) (current_function_decl
, 2);
275 declare_hidden_char_array ("__FUNCTION__", name
);
276 declare_hidden_char_array ("__PRETTY_FUNCTION__", printable_name
);
277 /* The ISO C people "of course" couldn't use __FUNCTION__ in the
278 ISO C 9x standard; instead a new variable is invented. */
279 declare_hidden_char_array ("__func__", name
);
283 declare_hidden_char_array (name
, value
)
284 const char *name
, *value
;
286 tree decl
, type
, init
;
289 /* If the default size of char arrays isn't big enough for the name,
290 or if we want to give warnings for large objects, make a bigger one. */
291 vlen
= strlen (value
) + 1;
292 type
= char_array_type_node
;
293 if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))) < vlen
295 type
= build_array_type (char_type_node
,
296 build_index_type (build_int_2 (vlen
, 0)));
297 push_obstacks_nochange ();
298 decl
= build_decl (VAR_DECL
, get_identifier (name
), type
);
299 TREE_STATIC (decl
) = 1;
300 TREE_READONLY (decl
) = 1;
301 TREE_ASM_WRITTEN (decl
) = 1;
302 DECL_SOURCE_LINE (decl
) = 0;
303 DECL_ARTIFICIAL (decl
) = 1;
304 DECL_IN_SYSTEM_HEADER (decl
) = 1;
305 DECL_IGNORED_P (decl
) = 1;
306 init
= build_string (vlen
, value
);
307 TREE_TYPE (init
) = type
;
308 DECL_INITIAL (decl
) = init
;
309 finish_decl (pushdecl (decl
), init
, NULL_TREE
);
312 /* Given a chain of STRING_CST nodes,
313 concatenate them into one STRING_CST
314 and give it a suitable array-of-chars data type. */
317 combine_strings (strings
)
320 register tree value
, t
;
321 register int length
= 1;
324 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
327 if (TREE_CHAIN (strings
))
329 /* More than one in the chain, so concatenate. */
330 register char *p
, *q
;
332 /* Don't include the \0 at the end of each substring,
333 except for the last one.
334 Count wide strings and ordinary strings separately. */
335 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
337 if (TREE_TYPE (t
) == wchar_array_type_node
)
339 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
343 length
+= (TREE_STRING_LENGTH (t
) - 1);
346 /* If anything is wide, the non-wides will be converted,
347 which makes them take more space. */
349 length
= length
* wchar_bytes
+ wide_length
;
351 p
= ggc_p
? ggc_alloc_string (NULL
, length
) : savealloc (length
);
353 /* Copy the individual strings into the new combined string.
354 If the combined string is wide, convert the chars to ints
355 for any individual strings that are not wide. */
358 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
360 int len
= (TREE_STRING_LENGTH (t
)
361 - ((TREE_TYPE (t
) == wchar_array_type_node
)
363 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
365 memcpy (q
, TREE_STRING_POINTER (t
), len
);
371 for (i
= 0; i
< len
; i
++)
373 if (WCHAR_TYPE_SIZE
== HOST_BITS_PER_SHORT
)
374 ((short *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
376 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
378 q
+= len
* wchar_bytes
;
384 for (i
= 0; i
< wchar_bytes
; i
++)
390 value
= make_node (STRING_CST
);
391 TREE_STRING_POINTER (value
) = p
;
392 TREE_STRING_LENGTH (value
) = length
;
397 length
= TREE_STRING_LENGTH (value
);
398 if (TREE_TYPE (value
) == wchar_array_type_node
)
402 /* Compute the number of elements, for the array type. */
403 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
405 /* Create the array type for the string constant.
406 -Wwrite-strings says make the string constant an array of const char
407 so that copying it to a non-const pointer will get a warning.
408 For C++, this is the standard behavior. */
409 if (flag_const_strings
410 && (! flag_traditional
&& ! flag_writable_strings
))
413 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
416 = build_array_type (elements
,
417 build_index_type (build_int_2 (nchars
- 1, 0)));
421 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
422 build_index_type (build_int_2 (nchars
- 1, 0)));
424 TREE_CONSTANT (value
) = 1;
425 TREE_READONLY (value
) = ! flag_writable_strings
;
426 TREE_STATIC (value
) = 1;
430 /* To speed up processing of attributes, we maintain an array of
431 IDENTIFIER_NODES and the corresponding attribute types. */
433 /* Array to hold attribute information. */
435 static struct {enum attrs id
; tree name
; int min
, max
, decl_req
;} attrtab
[50];
437 static int attrtab_idx
= 0;
439 /* Add an entry to the attribute table above. */
442 add_attribute (id
, string
, min_len
, max_len
, decl_req
)
445 int min_len
, max_len
;
450 attrtab
[attrtab_idx
].id
= id
;
451 attrtab
[attrtab_idx
].name
= get_identifier (string
);
452 attrtab
[attrtab_idx
].min
= min_len
;
453 attrtab
[attrtab_idx
].max
= max_len
;
454 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
456 sprintf (buf
, "__%s__", string
);
458 attrtab
[attrtab_idx
].id
= id
;
459 attrtab
[attrtab_idx
].name
= get_identifier (buf
);
460 attrtab
[attrtab_idx
].min
= min_len
;
461 attrtab
[attrtab_idx
].max
= max_len
;
462 attrtab
[attrtab_idx
++].decl_req
= decl_req
;
465 /* Initialize attribute table. */
470 add_attribute (A_PACKED
, "packed", 0, 0, 0);
471 add_attribute (A_NOCOMMON
, "nocommon", 0, 0, 1);
472 add_attribute (A_COMMON
, "common", 0, 0, 1);
473 add_attribute (A_NORETURN
, "noreturn", 0, 0, 1);
474 add_attribute (A_NORETURN
, "volatile", 0, 0, 1);
475 add_attribute (A_UNUSED
, "unused", 0, 0, 0);
476 add_attribute (A_CONST
, "const", 0, 0, 1);
477 add_attribute (A_T_UNION
, "transparent_union", 0, 0, 0);
478 add_attribute (A_CONSTRUCTOR
, "constructor", 0, 0, 1);
479 add_attribute (A_DESTRUCTOR
, "destructor", 0, 0, 1);
480 add_attribute (A_MODE
, "mode", 1, 1, 1);
481 add_attribute (A_SECTION
, "section", 1, 1, 1);
482 add_attribute (A_ALIGNED
, "aligned", 0, 1, 0);
483 add_attribute (A_FORMAT
, "format", 3, 3, 1);
484 add_attribute (A_FORMAT_ARG
, "format_arg", 1, 1, 1);
485 add_attribute (A_WEAK
, "weak", 0, 0, 1);
486 add_attribute (A_ALIAS
, "alias", 1, 1, 1);
487 add_attribute (A_NO_INSTRUMENT_FUNCTION
, "no_instrument_function", 0, 0, 1);
488 add_attribute (A_NO_CHECK_MEMORY_USAGE
, "no_check_memory_usage", 0, 0, 1);
491 /* Default implementation of valid_lang_attribute, below. By default, there
492 are no language-specific attributes. */
495 default_valid_lang_attribute (attr_name
, attr_args
, decl
, type
)
496 tree attr_name ATTRIBUTE_UNUSED
;
497 tree attr_args ATTRIBUTE_UNUSED
;
498 tree decl ATTRIBUTE_UNUSED
;
499 tree type ATTRIBUTE_UNUSED
;
504 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
505 attribute for either declaration DECL or type TYPE and 0 otherwise. */
507 int (*valid_lang_attribute
) PROTO ((tree
, tree
, tree
, tree
))
508 = default_valid_lang_attribute
;
510 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
511 and install them in NODE, which is either a DECL (including a TYPE_DECL)
512 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
513 and declaration modifiers but before the declaration proper. */
516 decl_attributes (node
, attributes
, prefix_attributes
)
517 tree node
, attributes
, prefix_attributes
;
519 tree decl
= 0, type
= 0;
523 if (attrtab_idx
== 0)
526 if (TREE_CODE_CLASS (TREE_CODE (node
)) == 'd')
529 type
= TREE_TYPE (decl
);
530 is_type
= TREE_CODE (node
) == TYPE_DECL
;
532 else if (TREE_CODE_CLASS (TREE_CODE (node
)) == 't')
533 type
= node
, is_type
= 1;
535 #ifdef PRAGMA_INSERT_ATTRIBUTES
536 /* If the code in c-pragma.c wants to insert some attributes then
537 allow it to do so. Do this before allowing machine back ends to
538 insert attributes, so that they have the opportunity to override
539 anything done here. */
540 PRAGMA_INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
543 #ifdef INSERT_ATTRIBUTES
544 INSERT_ATTRIBUTES (node
, & attributes
, & prefix_attributes
);
547 attributes
= chainon (prefix_attributes
, attributes
);
549 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
551 tree name
= TREE_PURPOSE (a
);
552 tree args
= TREE_VALUE (a
);
556 for (i
= 0; i
< attrtab_idx
; i
++)
557 if (attrtab
[i
].name
== name
)
560 if (i
== attrtab_idx
)
562 if (! valid_machine_attribute (name
, args
, decl
, type
)
563 && ! (* valid_lang_attribute
) (name
, args
, decl
, type
))
564 warning ("`%s' attribute directive ignored",
565 IDENTIFIER_POINTER (name
));
567 type
= TREE_TYPE (decl
);
570 else if (attrtab
[i
].decl_req
&& decl
== 0)
572 warning ("`%s' attribute does not apply to types",
573 IDENTIFIER_POINTER (name
));
576 else if (list_length (args
) < attrtab
[i
].min
577 || list_length (args
) > attrtab
[i
].max
)
579 error ("wrong number of arguments specified for `%s' attribute",
580 IDENTIFIER_POINTER (name
));
589 TYPE_PACKED (type
) = 1;
590 else if (TREE_CODE (decl
) == FIELD_DECL
)
591 DECL_PACKED (decl
) = 1;
592 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
593 used for DECL_REGISTER. It wouldn't mean anything anyway. */
595 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
599 if (TREE_CODE (decl
) == VAR_DECL
)
600 DECL_COMMON (decl
) = 0;
602 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
606 if (TREE_CODE (decl
) == VAR_DECL
)
607 DECL_COMMON (decl
) = 1;
609 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
613 if (TREE_CODE (decl
) == FUNCTION_DECL
)
614 TREE_THIS_VOLATILE (decl
) = 1;
615 else if (TREE_CODE (type
) == POINTER_TYPE
616 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
617 TREE_TYPE (decl
) = type
619 (build_type_variant (TREE_TYPE (type
),
620 TREE_READONLY (TREE_TYPE (type
)), 1));
622 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
627 TREE_USED (type
) = 1;
628 else if (TREE_CODE (decl
) == PARM_DECL
629 || TREE_CODE (decl
) == VAR_DECL
630 || TREE_CODE (decl
) == FUNCTION_DECL
631 || TREE_CODE (decl
) == LABEL_DECL
)
632 TREE_USED (decl
) = 1;
634 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
638 if (TREE_CODE (decl
) == FUNCTION_DECL
)
639 TREE_READONLY (decl
) = 1;
640 else if (TREE_CODE (type
) == POINTER_TYPE
641 && TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
642 TREE_TYPE (decl
) = type
644 (build_type_variant (TREE_TYPE (type
), 1,
645 TREE_THIS_VOLATILE (TREE_TYPE (type
))));
647 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name
));
652 && TREE_CODE (type
) == UNION_TYPE
654 || (TYPE_FIELDS (type
) != 0
655 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))))
656 TYPE_TRANSPARENT_UNION (type
) = 1;
657 else if (decl
!= 0 && TREE_CODE (decl
) == PARM_DECL
658 && TREE_CODE (type
) == UNION_TYPE
659 && TYPE_MODE (type
) == DECL_MODE (TYPE_FIELDS (type
)))
660 DECL_TRANSPARENT_UNION (decl
) = 1;
662 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
666 if (TREE_CODE (decl
) == FUNCTION_DECL
667 && TREE_CODE (type
) == FUNCTION_TYPE
668 && decl_function_context (decl
) == 0)
670 DECL_STATIC_CONSTRUCTOR (decl
) = 1;
671 TREE_USED (decl
) = 1;
674 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
678 if (TREE_CODE (decl
) == FUNCTION_DECL
679 && TREE_CODE (type
) == FUNCTION_TYPE
680 && decl_function_context (decl
) == 0)
682 DECL_STATIC_DESTRUCTOR (decl
) = 1;
683 TREE_USED (decl
) = 1;
686 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
690 if (TREE_CODE (TREE_VALUE (args
)) != IDENTIFIER_NODE
)
691 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
695 const char *p
= IDENTIFIER_POINTER (TREE_VALUE (args
));
696 int len
= strlen (p
);
697 enum machine_mode mode
= VOIDmode
;
700 if (len
> 4 && p
[0] == '_' && p
[1] == '_'
701 && p
[len
- 1] == '_' && p
[len
- 2] == '_')
703 char *newp
= (char *) alloca (len
- 1);
705 strcpy (newp
, &p
[2]);
706 newp
[len
- 4] = '\0';
710 /* Give this decl a type with the specified mode.
711 First check for the special modes. */
712 if (! strcmp (p
, "byte"))
714 else if (!strcmp (p
, "word"))
716 else if (! strcmp (p
, "pointer"))
719 for (j
= 0; j
< NUM_MACHINE_MODES
; j
++)
720 if (!strcmp (p
, GET_MODE_NAME (j
)))
721 mode
= (enum machine_mode
) j
;
723 if (mode
== VOIDmode
)
724 error ("unknown machine mode `%s'", p
);
725 else if (0 == (typefm
= type_for_mode (mode
,
726 TREE_UNSIGNED (type
))))
727 error ("no data type for mode `%s'", p
);
730 TREE_TYPE (decl
) = type
= typefm
;
731 DECL_SIZE (decl
) = 0;
732 layout_decl (decl
, 0);
738 #ifdef ASM_OUTPUT_SECTION_NAME
739 if ((TREE_CODE (decl
) == FUNCTION_DECL
740 || TREE_CODE (decl
) == VAR_DECL
)
741 && TREE_CODE (TREE_VALUE (args
)) == STRING_CST
)
743 if (TREE_CODE (decl
) == VAR_DECL
744 && current_function_decl
!= NULL_TREE
745 && ! TREE_STATIC (decl
))
746 error_with_decl (decl
,
747 "section attribute cannot be specified for local variables");
748 /* The decl may have already been given a section attribute from
749 a previous declaration. Ensure they match. */
750 else if (DECL_SECTION_NAME (decl
) != NULL_TREE
751 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
752 TREE_STRING_POINTER (TREE_VALUE (args
))) != 0)
753 error_with_decl (node
,
754 "section of `%s' conflicts with previous declaration");
756 DECL_SECTION_NAME (decl
) = TREE_VALUE (args
);
759 error_with_decl (node
,
760 "section attribute not allowed for `%s'");
762 error_with_decl (node
,
763 "section attributes are not supported for this target");
770 = (args
? TREE_VALUE (args
)
771 : size_int (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
774 /* Strip any NOPs of any kind. */
775 while (TREE_CODE (align_expr
) == NOP_EXPR
776 || TREE_CODE (align_expr
) == CONVERT_EXPR
777 || TREE_CODE (align_expr
) == NON_LVALUE_EXPR
)
778 align_expr
= TREE_OPERAND (align_expr
, 0);
780 if (TREE_CODE (align_expr
) != INTEGER_CST
)
782 error ("requested alignment is not a constant");
786 align
= TREE_INT_CST_LOW (align_expr
) * BITS_PER_UNIT
;
788 if (exact_log2 (align
) == -1)
789 error ("requested alignment is not a power of 2");
791 TYPE_ALIGN (type
) = align
;
792 else if (TREE_CODE (decl
) != VAR_DECL
793 && TREE_CODE (decl
) != FIELD_DECL
)
794 error_with_decl (decl
,
795 "alignment may not be specified for `%s'");
797 DECL_ALIGN (decl
) = align
;
803 tree format_type_id
= TREE_VALUE (args
);
804 tree format_num_expr
= TREE_VALUE (TREE_CHAIN (args
));
805 tree first_arg_num_expr
806 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args
)));
809 enum format_type format_type
;
813 if (TREE_CODE (decl
) != FUNCTION_DECL
)
815 error_with_decl (decl
,
816 "argument format specified for non-function `%s'");
820 if (TREE_CODE (format_type_id
) != IDENTIFIER_NODE
)
822 error ("unrecognized format specifier");
827 const char *p
= IDENTIFIER_POINTER (format_type_id
);
829 if (!strcmp (p
, "printf") || !strcmp (p
, "__printf__"))
830 format_type
= printf_format_type
;
831 else if (!strcmp (p
, "scanf") || !strcmp (p
, "__scanf__"))
832 format_type
= scanf_format_type
;
833 else if (!strcmp (p
, "strftime")
834 || !strcmp (p
, "__strftime__"))
835 format_type
= strftime_format_type
;
838 warning ("`%s' is an unrecognized format function type", p
);
843 /* Strip any conversions from the string index and first arg number
844 and verify they are constants. */
845 while (TREE_CODE (format_num_expr
) == NOP_EXPR
846 || TREE_CODE (format_num_expr
) == CONVERT_EXPR
847 || TREE_CODE (format_num_expr
) == NON_LVALUE_EXPR
)
848 format_num_expr
= TREE_OPERAND (format_num_expr
, 0);
850 while (TREE_CODE (first_arg_num_expr
) == NOP_EXPR
851 || TREE_CODE (first_arg_num_expr
) == CONVERT_EXPR
852 || TREE_CODE (first_arg_num_expr
) == NON_LVALUE_EXPR
)
853 first_arg_num_expr
= TREE_OPERAND (first_arg_num_expr
, 0);
855 if (TREE_CODE (format_num_expr
) != INTEGER_CST
856 || TREE_CODE (first_arg_num_expr
) != INTEGER_CST
)
858 error ("format string has non-constant operand number");
862 format_num
= TREE_INT_CST_LOW (format_num_expr
);
863 first_arg_num
= TREE_INT_CST_LOW (first_arg_num_expr
);
864 if (first_arg_num
!= 0 && first_arg_num
<= format_num
)
866 error ("format string arg follows the args to be formatted");
870 /* If a parameter list is specified, verify that the format_num
871 argument is actually a string, in case the format attribute
873 argument
= TYPE_ARG_TYPES (type
);
876 for (arg_num
= 1; ; ++arg_num
)
878 if (argument
== 0 || arg_num
== format_num
)
880 argument
= TREE_CHAIN (argument
);
883 || TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
884 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument
)))
887 error ("format string arg not a string type");
890 if (first_arg_num
!= 0)
892 /* Verify that first_arg_num points to the last arg,
895 arg_num
++, argument
= TREE_CHAIN (argument
);
896 if (arg_num
!= first_arg_num
)
898 error ("args to be formatted is not ...");
904 record_function_format (DECL_NAME (decl
),
905 DECL_ASSEMBLER_NAME (decl
),
906 format_type
, format_num
, first_arg_num
);
912 tree format_num_expr
= TREE_VALUE (args
);
913 int format_num
, arg_num
;
916 if (TREE_CODE (decl
) != FUNCTION_DECL
)
918 error_with_decl (decl
,
919 "argument format specified for non-function `%s'");
923 /* Strip any conversions from the first arg number and verify it
925 while (TREE_CODE (format_num_expr
) == NOP_EXPR
926 || TREE_CODE (format_num_expr
) == CONVERT_EXPR
927 || TREE_CODE (format_num_expr
) == NON_LVALUE_EXPR
)
928 format_num_expr
= TREE_OPERAND (format_num_expr
, 0);
930 if (TREE_CODE (format_num_expr
) != INTEGER_CST
)
932 error ("format string has non-constant operand number");
936 format_num
= TREE_INT_CST_LOW (format_num_expr
);
938 /* If a parameter list is specified, verify that the format_num
939 argument is actually a string, in case the format attribute
941 argument
= TYPE_ARG_TYPES (type
);
944 for (arg_num
= 1; ; ++arg_num
)
946 if (argument
== 0 || arg_num
== format_num
)
948 argument
= TREE_CHAIN (argument
);
951 || TREE_CODE (TREE_VALUE (argument
)) != POINTER_TYPE
952 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument
)))
955 error ("format string arg not a string type");
960 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl
))) != POINTER_TYPE
961 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl
))))
964 error ("function does not return string type");
968 record_international_format (DECL_NAME (decl
),
969 DECL_ASSEMBLER_NAME (decl
),
979 if ((TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_INITIAL (decl
))
980 || (TREE_CODE (decl
) != FUNCTION_DECL
&& ! DECL_EXTERNAL (decl
)))
981 error_with_decl (decl
,
982 "`%s' defined both normally and as an alias");
983 else if (decl_function_context (decl
) == 0)
987 id
= TREE_VALUE (args
);
988 if (TREE_CODE (id
) != STRING_CST
)
990 error ("alias arg not a string");
993 id
= get_identifier (TREE_STRING_POINTER (id
));
995 if (TREE_CODE (decl
) == FUNCTION_DECL
)
996 DECL_INITIAL (decl
) = error_mark_node
;
998 DECL_EXTERNAL (decl
) = 0;
999 assemble_alias (decl
, id
);
1002 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name
));
1005 case A_NO_CHECK_MEMORY_USAGE
:
1006 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1008 error_with_decl (decl
,
1009 "`%s' attribute applies only to functions",
1010 IDENTIFIER_POINTER (name
));
1012 else if (DECL_INITIAL (decl
))
1014 error_with_decl (decl
,
1015 "can't set `%s' attribute after definition",
1016 IDENTIFIER_POINTER (name
));
1019 DECL_NO_CHECK_MEMORY_USAGE (decl
) = 1;
1022 case A_NO_INSTRUMENT_FUNCTION
:
1023 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1025 error_with_decl (decl
,
1026 "`%s' attribute applies only to functions",
1027 IDENTIFIER_POINTER (name
));
1029 else if (DECL_INITIAL (decl
))
1031 error_with_decl (decl
,
1032 "can't set `%s' attribute after definition",
1033 IDENTIFIER_POINTER (name
));
1036 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl
) = 1;
1042 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1043 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1045 The head of the declspec list is stored in DECLSPECS.
1046 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1048 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1049 the list elements. We drop the containing TREE_LIST nodes and link the
1050 resulting attributes together the way decl_attributes expects them. */
1053 split_specs_attrs (specs_attrs
, declspecs
, prefix_attributes
)
1055 tree
*declspecs
, *prefix_attributes
;
1057 tree t
, s
, a
, next
, specs
, attrs
;
1059 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1060 if (specs_attrs
!= NULL_TREE
1061 && TREE_CODE (specs_attrs
) != TREE_LIST
)
1063 *declspecs
= specs_attrs
;
1064 *prefix_attributes
= NULL_TREE
;
1068 /* Remember to keep the lists in the same order, element-wise. */
1070 specs
= s
= NULL_TREE
;
1071 attrs
= a
= NULL_TREE
;
1072 for (t
= specs_attrs
; t
; t
= next
)
1074 next
= TREE_CHAIN (t
);
1075 /* Declspecs have a non-NULL TREE_VALUE. */
1076 if (TREE_VALUE (t
) != NULL_TREE
)
1078 if (specs
== NULL_TREE
)
1088 if (attrs
== NULL_TREE
)
1089 attrs
= a
= TREE_PURPOSE (t
);
1092 TREE_CHAIN (a
) = TREE_PURPOSE (t
);
1093 a
= TREE_PURPOSE (t
);
1095 /* More attrs can be linked here, move A to the end. */
1096 while (TREE_CHAIN (a
) != NULL_TREE
)
1101 /* Terminate the lists. */
1103 TREE_CHAIN (s
) = NULL_TREE
;
1105 TREE_CHAIN (a
) = NULL_TREE
;
1109 *prefix_attributes
= attrs
;
1112 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1113 This function is used by the parser when a rule will accept attributes
1114 in a particular position, but we don't want to support that just yet.
1116 A warning is issued for every ignored attribute. */
1119 strip_attrs (specs_attrs
)
1124 split_specs_attrs (specs_attrs
, &specs
, &attrs
);
1128 warning ("`%s' attribute ignored",
1129 IDENTIFIER_POINTER (TREE_PURPOSE (attrs
)));
1130 attrs
= TREE_CHAIN (attrs
);
1136 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1137 a parameter list. */
1139 #define T_I &integer_type_node
1140 #define T_L &long_integer_type_node
1141 #define T_LL &long_long_integer_type_node
1142 #define T_S &short_integer_type_node
1143 #define T_UI &unsigned_type_node
1144 #define T_UL &long_unsigned_type_node
1145 #define T_ULL &long_long_unsigned_type_node
1146 #define T_US &short_unsigned_type_node
1147 #define T_F &float_type_node
1148 #define T_D &double_type_node
1149 #define T_LD &long_double_type_node
1150 #define T_C &char_type_node
1151 #define T_UC &unsigned_char_type_node
1152 #define T_V &void_type_node
1153 #define T_W &wchar_type_node
1154 #define T_ST &sizetype
1157 const char *format_chars
;
1159 /* Type of argument if no length modifier is used. */
1161 /* Type of argument if length modifier for shortening to byte is used.
1162 If NULL, then this modifier is not allowed. */
1164 /* Type of argument if length modifier for shortening is used.
1165 If NULL, then this modifier is not allowed. */
1167 /* Type of argument if length modifier `l' is used.
1168 If NULL, then this modifier is not allowed. */
1170 /* Type of argument if length modifier `q' or `ll' is used.
1171 If NULL, then this modifier is not allowed. */
1173 /* Type of argument if length modifier `L' is used.
1174 If NULL, then this modifier is not allowed. */
1176 /* Type of argument if length modifier `Z' is used.
1177 If NULL, then this modifier is not allowed. */
1179 /* List of other modifier characters allowed with these options. */
1180 const char *flag_chars
;
1183 static format_char_info print_char_table
[] = {
1184 { "di", 0, T_I
, T_I
, T_I
, T_L
, T_LL
, T_LL
, T_ST
, "-wp0 +" },
1185 { "oxX", 0, T_UI
, T_UI
, T_UI
, T_UL
, T_ULL
, T_ULL
, T_ST
, "-wp0#" },
1186 { "u", 0, T_UI
, T_UI
, T_UI
, T_UL
, T_ULL
, T_ULL
, T_ST
, "-wp0" },
1187 /* A GNU extension. */
1188 { "m", 0, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-wp" },
1189 { "feEgGaA", 0, T_D
, NULL
, NULL
, NULL
, NULL
, T_LD
, NULL
, "-wp0 +#" },
1190 { "c", 0, T_I
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "-w" },
1191 { "C", 0, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-w" },
1192 { "s", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "-wp" },
1193 { "S", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-wp" },
1194 { "p", 1, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-w" },
1195 { "n", 1, T_I
, NULL
, T_S
, T_L
, T_LL
, NULL
, NULL
, "" },
1196 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1199 static format_char_info scan_char_table
[] = {
1200 { "di", 1, T_I
, T_C
, T_S
, T_L
, T_LL
, T_LL
, NULL
, "*" },
1201 { "ouxX", 1, T_UI
, T_UC
, T_US
, T_UL
, T_ULL
, T_ULL
, NULL
, "*" },
1202 { "efgEGaA", 1, T_F
, NULL
, NULL
, T_D
, NULL
, T_LD
, NULL
, "*" },
1203 { "c", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "*" },
1204 { "s", 1, T_C
, NULL
, NULL
, T_W
, NULL
, NULL
, NULL
, "*a" },
1205 { "[", 1, T_C
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*a" },
1206 { "C", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*" },
1207 { "S", 1, T_W
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*a" },
1208 { "p", 2, T_V
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "*" },
1209 { "n", 1, T_I
, T_C
, T_S
, T_L
, T_LL
, NULL
, NULL
, "" },
1210 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1213 /* Handle format characters recognized by glibc's strftime.c.
1214 '2' - MUST do years as only two digits
1215 '3' - MAY do years as only two digits (depending on locale)
1216 'E' - E modifier is acceptable
1217 'O' - O modifier is acceptable to Standard C
1218 'o' - O modifier is acceptable as a GNU extension
1219 'G' - other GNU extensions */
1221 static format_char_info time_char_table
[] = {
1222 { "y", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2EO-_0w" },
1223 { "D", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2" },
1224 { "g", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "2O-_0w" },
1225 { "cx", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "3E" },
1226 { "%RTXnrt", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "" },
1227 { "P", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "G" },
1228 { "HIMSUWdemw", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0Ow" },
1229 { "Vju", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0Oow" },
1230 { "Gklsz", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0OGw" },
1231 { "ABZa", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "^#" },
1232 { "p", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "#" },
1233 { "bh", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "^" },
1234 { "CY", 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "-_0EOw" },
1235 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
1238 typedef struct function_format_info
1240 struct function_format_info
*next
; /* next structure on the list */
1241 tree name
; /* identifier such as "printf" */
1242 tree assembler_name
; /* optional mangled identifier (for C++) */
1243 enum format_type format_type
; /* type of format (printf, scanf, etc.) */
1244 int format_num
; /* number of format argument */
1245 int first_arg_num
; /* number of first arg (zero for varargs) */
1246 } function_format_info
;
1248 static function_format_info
*function_format_list
= NULL
;
1250 typedef struct international_format_info
1252 struct international_format_info
*next
; /* next structure on the list */
1253 tree name
; /* identifier such as "gettext" */
1254 tree assembler_name
; /* optional mangled identifier (for C++) */
1255 int format_num
; /* number of format argument */
1256 } international_format_info
;
1258 static international_format_info
*international_format_list
= NULL
;
1260 static void check_format_info
PROTO((function_format_info
*, tree
));
1262 /* Initialize the table of functions to perform format checking on.
1263 The ANSI functions are always checked (whether <stdio.h> is
1264 included or not), since it is common to call printf without
1265 including <stdio.h>. There shouldn't be a problem with this,
1266 since ANSI reserves these function names whether you include the
1267 header file or not. In any case, the checking is harmless.
1269 Also initialize the name of function that modify the format string for
1270 internationalization purposes. */
1273 init_function_format_info ()
1275 record_function_format (get_identifier ("printf"), NULL_TREE
,
1276 printf_format_type
, 1, 2);
1277 record_function_format (get_identifier ("fprintf"), NULL_TREE
,
1278 printf_format_type
, 2, 3);
1279 record_function_format (get_identifier ("sprintf"), NULL_TREE
,
1280 printf_format_type
, 2, 3);
1281 record_function_format (get_identifier ("scanf"), NULL_TREE
,
1282 scanf_format_type
, 1, 2);
1283 record_function_format (get_identifier ("fscanf"), NULL_TREE
,
1284 scanf_format_type
, 2, 3);
1285 record_function_format (get_identifier ("sscanf"), NULL_TREE
,
1286 scanf_format_type
, 2, 3);
1287 record_function_format (get_identifier ("vprintf"), NULL_TREE
,
1288 printf_format_type
, 1, 0);
1289 record_function_format (get_identifier ("vfprintf"), NULL_TREE
,
1290 printf_format_type
, 2, 0);
1291 record_function_format (get_identifier ("vsprintf"), NULL_TREE
,
1292 printf_format_type
, 2, 0);
1293 record_function_format (get_identifier ("strftime"), NULL_TREE
,
1294 strftime_format_type
, 3, 0);
1296 record_international_format (get_identifier ("gettext"), NULL_TREE
, 1);
1297 record_international_format (get_identifier ("dgettext"), NULL_TREE
, 2);
1298 record_international_format (get_identifier ("dcgettext"), NULL_TREE
, 2);
1301 /* Record information for argument format checking. FUNCTION_IDENT is
1302 the identifier node for the name of the function to check (its decl
1303 need not exist yet).
1304 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
1305 of the argument which is the format control string (starting from 1).
1306 FIRST_ARG_NUM is the number of the first actual argument to check
1307 against the format string, or zero if no checking is not be done
1308 (e.g. for varargs such as vfprintf). */
1311 record_function_format (name
, assembler_name
, format_type
,
1312 format_num
, first_arg_num
)
1314 tree assembler_name
;
1315 enum format_type format_type
;
1319 function_format_info
*info
;
1321 /* Re-use existing structure if it's there. */
1323 for (info
= function_format_list
; info
; info
= info
->next
)
1325 if (info
->name
== name
&& info
->assembler_name
== assembler_name
)
1330 info
= (function_format_info
*) xmalloc (sizeof (function_format_info
));
1331 info
->next
= function_format_list
;
1332 function_format_list
= info
;
1335 info
->assembler_name
= assembler_name
;
1338 info
->format_type
= format_type
;
1339 info
->format_num
= format_num
;
1340 info
->first_arg_num
= first_arg_num
;
1343 /* Record information for the names of function that modify the format
1344 argument to format functions. FUNCTION_IDENT is the identifier node for
1345 the name of the function (its decl need not exist yet) and FORMAT_NUM is
1346 the number of the argument which is the format control string (starting
1350 record_international_format (name
, assembler_name
, format_num
)
1352 tree assembler_name
;
1355 international_format_info
*info
;
1357 /* Re-use existing structure if it's there. */
1359 for (info
= international_format_list
; info
; info
= info
->next
)
1361 if (info
->name
== name
&& info
->assembler_name
== assembler_name
)
1368 = (international_format_info
*)
1369 xmalloc (sizeof (international_format_info
));
1370 info
->next
= international_format_list
;
1371 international_format_list
= info
;
1374 info
->assembler_name
= assembler_name
;
1377 info
->format_num
= format_num
;
1383 warning ("too few arguments for format");
1386 /* Check the argument list of a call to printf, scanf, etc.
1387 NAME is the function identifier.
1388 ASSEMBLER_NAME is the function's assembler identifier.
1389 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1390 PARAMS is the list of argument values. */
1393 check_function_format (name
, assembler_name
, params
)
1395 tree assembler_name
;
1398 function_format_info
*info
;
1400 /* See if this function is a format function. */
1401 for (info
= function_format_list
; info
; info
= info
->next
)
1403 if (info
->assembler_name
1404 ? (info
->assembler_name
== assembler_name
)
1405 : (info
->name
== name
))
1407 /* Yup; check it. */
1408 check_format_info (info
, params
);
1414 /* Check the argument list of a call to printf, scanf, etc.
1415 INFO points to the function_format_info structure.
1416 PARAMS is the list of argument values. */
1419 check_format_info (info
, params
)
1420 function_format_info
*info
;
1425 int suppressed
, wide
, precise
;
1426 int length_char
= 0;
1433 tree first_fillin_param
;
1434 const char *format_chars
;
1435 format_char_info
*fci
= NULL
;
1437 int has_operand_number
= 0;
1439 /* Skip to format argument. If the argument isn't available, there's
1440 no work for us to do; prototype checking will catch the problem. */
1441 for (arg_num
= 1; ; ++arg_num
)
1445 if (arg_num
== info
->format_num
)
1447 params
= TREE_CHAIN (params
);
1449 format_tree
= TREE_VALUE (params
);
1450 params
= TREE_CHAIN (params
);
1451 if (format_tree
== 0)
1454 /* We can only check the format if it's a string constant. */
1455 while (TREE_CODE (format_tree
) == NOP_EXPR
)
1456 format_tree
= TREE_OPERAND (format_tree
, 0); /* strip coercion */
1458 if (TREE_CODE (format_tree
) == CALL_EXPR
1459 && TREE_CODE (TREE_OPERAND (format_tree
, 0)) == ADDR_EXPR
1460 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree
, 0), 0))
1463 tree function
= TREE_OPERAND (TREE_OPERAND (format_tree
, 0), 0);
1465 /* See if this is a call to a known internationalization function
1466 that modifies the format arg. */
1467 international_format_info
*info
;
1469 for (info
= international_format_list
; info
; info
= info
->next
)
1470 if (info
->assembler_name
1471 ? (info
->assembler_name
== DECL_ASSEMBLER_NAME (function
))
1472 : (info
->name
== DECL_NAME (function
)))
1477 for (inner_args
= TREE_OPERAND (format_tree
, 1), i
= 1;
1479 inner_args
= TREE_CHAIN (inner_args
), i
++)
1480 if (i
== info
->format_num
)
1482 format_tree
= TREE_VALUE (inner_args
);
1484 while (TREE_CODE (format_tree
) == NOP_EXPR
)
1485 format_tree
= TREE_OPERAND (format_tree
, 0);
1490 if (integer_zerop (format_tree
))
1492 warning ("null format string");
1495 if (TREE_CODE (format_tree
) != ADDR_EXPR
)
1497 format_tree
= TREE_OPERAND (format_tree
, 0);
1498 if (TREE_CODE (format_tree
) != STRING_CST
)
1500 format_chars
= TREE_STRING_POINTER (format_tree
);
1501 format_length
= TREE_STRING_LENGTH (format_tree
);
1502 if (format_length
<= 1)
1503 warning ("zero-length format string");
1504 if (format_chars
[--format_length
] != 0)
1506 warning ("unterminated format string");
1509 /* Skip to first argument to check. */
1510 while (arg_num
+ 1 < info
->first_arg_num
)
1514 params
= TREE_CHAIN (params
);
1518 first_fillin_param
= params
;
1522 if (*format_chars
== 0)
1524 if (format_chars
- TREE_STRING_POINTER (format_tree
) != format_length
)
1525 warning ("embedded `\\0' in format");
1526 if (info
->first_arg_num
!= 0 && params
!= 0 && ! has_operand_number
)
1527 warning ("too many arguments for format");
1530 if (*format_chars
++ != '%')
1532 if (*format_chars
== 0)
1534 warning ("spurious trailing `%%' in format");
1537 if (*format_chars
== '%')
1543 suppressed
= wide
= precise
= FALSE
;
1544 if (info
->format_type
== scanf_format_type
)
1546 suppressed
= *format_chars
== '*';
1549 while (ISDIGIT (*format_chars
))
1552 else if (info
->format_type
== strftime_format_type
)
1554 while (*format_chars
!= 0 && index ("_-0^#", *format_chars
) != 0)
1557 warning ("ANSI C does not support the strftime `%c' flag",
1559 if (index (flag_chars
, *format_chars
) != 0)
1561 warning ("repeated `%c' flag in format",
1567 i
= strlen (flag_chars
);
1568 flag_chars
[i
++] = *format_chars
++;
1572 while (ISDIGIT ((unsigned char) *format_chars
))
1577 if (wide
&& pedantic
)
1578 warning ("ANSI C does not support strftime format width");
1579 if (*format_chars
== 'E' || *format_chars
== 'O')
1581 i
= strlen (flag_chars
);
1582 flag_chars
[i
++] = *format_chars
++;
1584 if (*format_chars
== 'E' || *format_chars
== 'O')
1586 warning ("multiple E/O modifiers in format");
1587 while (*format_chars
== 'E' || *format_chars
== 'O')
1592 else if (info
->format_type
== printf_format_type
)
1594 /* See if we have a number followed by a dollar sign. If we do,
1595 it is an operand number, so set PARAMS to that operand. */
1596 if (*format_chars
>= '0' && *format_chars
<= '9')
1598 const char *p
= format_chars
;
1600 while (*p
>= '0' && *p
++ <= '9')
1605 int opnum
= atoi (format_chars
);
1607 params
= first_fillin_param
;
1608 format_chars
= p
+ 1;
1609 has_operand_number
= 1;
1611 for (i
= 1; i
< opnum
&& params
!= 0; i
++)
1612 params
= TREE_CHAIN (params
);
1614 if (opnum
== 0 || params
== 0)
1616 warning ("operand number out of range in format");
1622 while (*format_chars
!= 0 && index (" +#0-", *format_chars
) != 0)
1624 if (index (flag_chars
, *format_chars
) != 0)
1625 warning ("repeated `%c' flag in format", *format_chars
++);
1628 i
= strlen (flag_chars
);
1629 flag_chars
[i
++] = *format_chars
++;
1633 /* "If the space and + flags both appear,
1634 the space flag will be ignored." */
1635 if (index (flag_chars
, ' ') != 0
1636 && index (flag_chars
, '+') != 0)
1637 warning ("use of both ` ' and `+' flags in format");
1638 /* "If the 0 and - flags both appear,
1639 the 0 flag will be ignored." */
1640 if (index (flag_chars
, '0') != 0
1641 && index (flag_chars
, '-') != 0)
1642 warning ("use of both `0' and `-' flags in format");
1643 if (*format_chars
== '*')
1646 /* "...a field width...may be indicated by an asterisk.
1647 In this case, an int argument supplies the field width..." */
1654 if (info
->first_arg_num
!= 0)
1656 cur_param
= TREE_VALUE (params
);
1657 params
= TREE_CHAIN (params
);
1659 /* size_t is generally not valid here.
1660 It will work on most machines, because size_t and int
1661 have the same mode. But might as well warn anyway,
1662 since it will fail on other machines. */
1663 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1664 != integer_type_node
)
1666 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1667 != unsigned_type_node
))
1668 warning ("field width is not type int (arg %d)", arg_num
);
1673 while (ISDIGIT (*format_chars
))
1679 if (*format_chars
== '.')
1683 if (*format_chars
!= '*' && !ISDIGIT (*format_chars
))
1684 warning ("`.' not followed by `*' or digit in format");
1685 /* "...a...precision...may be indicated by an asterisk.
1686 In this case, an int argument supplies the...precision." */
1687 if (*format_chars
== '*')
1689 if (info
->first_arg_num
!= 0)
1697 cur_param
= TREE_VALUE (params
);
1698 params
= TREE_CHAIN (params
);
1700 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param
))
1701 != integer_type_node
)
1702 warning ("field width is not type int (arg %d)",
1708 while (ISDIGIT (*format_chars
))
1716 if (info
->format_type
!= strftime_format_type
)
1718 if (*format_chars
== 'h' || *format_chars
== 'l')
1719 length_char
= *format_chars
++;
1720 else if (*format_chars
== 'q' || *format_chars
== 'L')
1722 length_char
= *format_chars
++;
1724 warning ("ANSI C does not support the `%c' length modifier",
1727 else if (*format_chars
== 'Z')
1729 length_char
= *format_chars
++;
1731 warning ("ANSI C does not support the `Z' length modifier");
1735 if (length_char
== 'l' && *format_chars
== 'l')
1737 length_char
= 'q', format_chars
++;
1738 /* FIXME: Is allowed in ISO C 9x. */
1740 warning ("ANSI C does not support the `ll' length modifier");
1742 else if (length_char
== 'h' && *format_chars
== 'h')
1744 length_char
= 'H', format_chars
++;
1745 /* FIXME: Is allowed in ISO C 9x. */
1747 warning ("ANSI C does not support the `hh' length modifier");
1749 if (*format_chars
== 'a' && info
->format_type
== scanf_format_type
)
1751 if (format_chars
[1] == 's' || format_chars
[1] == 'S'
1752 || format_chars
[1] == '[')
1754 /* `a' is used as a flag. */
1759 if (suppressed
&& length_char
!= 0)
1760 warning ("use of `*' and `%c' together in format", length_char
);
1762 format_char
= *format_chars
;
1763 if (format_char
== 0
1764 || (info
->format_type
!= strftime_format_type
&& format_char
== '%'))
1766 warning ("conversion lacks type at end of format");
1769 /* The m, C, and S formats are GNU extensions. */
1770 if (pedantic
&& info
->format_type
!= strftime_format_type
1771 && (format_char
== 'm' || format_char
== 'C' || format_char
== 'S'))
1772 warning ("ANSI C does not support the `%c' format", format_char
);
1773 /* ??? The a and A formats are C9X extensions, and should be allowed
1774 when a C9X option is added. */
1775 if (pedantic
&& info
->format_type
!= strftime_format_type
1776 && (format_char
== 'a' || format_char
== 'A'))
1777 warning ("ANSI C does not support the `%c' format", format_char
);
1779 switch (info
->format_type
)
1781 case printf_format_type
:
1782 fci
= print_char_table
;
1784 case scanf_format_type
:
1785 fci
= scan_char_table
;
1787 case strftime_format_type
:
1788 fci
= time_char_table
;
1793 while (fci
->format_chars
!= 0
1794 && index (fci
->format_chars
, format_char
) == 0)
1796 if (fci
->format_chars
== 0)
1798 if (ISGRAPH(format_char
))
1799 warning ("unknown conversion type character `%c' in format",
1802 warning ("unknown conversion type character 0x%x in format",
1808 if (index (fci
->flag_chars
, 'G') != 0)
1809 warning ("ANSI C does not support `%%%c'", format_char
);
1810 if (index (fci
->flag_chars
, 'o') != 0
1811 && index (flag_chars
, 'O') != 0)
1812 warning ("ANSI C does not support `%%O%c'", format_char
);
1814 if (wide
&& index (fci
->flag_chars
, 'w') == 0)
1815 warning ("width used with `%c' format", format_char
);
1816 if (index (fci
->flag_chars
, '2') != 0)
1817 warning ("`%%%c' yields only last 2 digits of year", format_char
);
1818 else if (index (fci
->flag_chars
, '3') != 0)
1819 warning ("`%%%c' yields only last 2 digits of year in some locales",
1821 if (precise
&& index (fci
->flag_chars
, 'p') == 0)
1822 warning ("precision used with `%c' format", format_char
);
1823 if (aflag
&& index (fci
->flag_chars
, 'a') == 0)
1825 warning ("`a' flag used with `%c' format", format_char
);
1826 /* To simplify the following code. */
1829 /* The a flag is a GNU extension. */
1830 else if (pedantic
&& aflag
)
1831 warning ("ANSI C does not support the `a' flag");
1832 if (info
->format_type
== scanf_format_type
&& format_char
== '[')
1834 /* Skip over scan set, in case it happens to have '%' in it. */
1835 if (*format_chars
== '^')
1837 /* Find closing bracket; if one is hit immediately, then
1838 it's part of the scan set rather than a terminator. */
1839 if (*format_chars
== ']')
1841 while (*format_chars
&& *format_chars
!= ']')
1843 if (*format_chars
!= ']')
1844 /* The end of the format string was reached. */
1845 warning ("no closing `]' for `%%[' format");
1849 if (index (fci
->flag_chars
, '*') == 0)
1850 warning ("suppression of `%c' conversion in format", format_char
);
1853 for (i
= 0; flag_chars
[i
] != 0; ++i
)
1855 if (index (fci
->flag_chars
, flag_chars
[i
]) == 0)
1856 warning ("flag `%c' used with type `%c'",
1857 flag_chars
[i
], format_char
);
1859 if (info
->format_type
== strftime_format_type
)
1861 if (precise
&& index (flag_chars
, '0') != 0
1862 && (format_char
== 'd' || format_char
== 'i'
1863 || format_char
== 'o' || format_char
== 'u'
1864 || format_char
== 'x' || format_char
== 'X'))
1865 warning ("`0' flag ignored with precision specifier and `%c' format",
1867 switch (length_char
)
1869 default: wanted_type
= fci
->nolen
? *(fci
->nolen
) : 0; break;
1870 case 'H': wanted_type
= fci
->hhlen
? *(fci
->hhlen
) : 0; break;
1871 case 'h': wanted_type
= fci
->hlen
? *(fci
->hlen
) : 0; break;
1872 case 'l': wanted_type
= fci
->llen
? *(fci
->llen
) : 0; break;
1873 case 'q': wanted_type
= fci
->qlen
? *(fci
->qlen
) : 0; break;
1874 case 'L': wanted_type
= fci
->bigllen
? *(fci
->bigllen
) : 0; break;
1875 case 'Z': wanted_type
= fci
->zlen
? *fci
->zlen
: 0; break;
1877 if (wanted_type
== 0)
1878 warning ("use of `%c' length character with `%c' type character",
1879 length_char
, format_char
);
1881 /* Finally. . .check type of argument against desired type! */
1882 if (info
->first_arg_num
== 0)
1884 if (fci
->pointer_count
== 0 && wanted_type
== void_type_node
)
1885 /* This specifier takes no argument. */
1892 cur_param
= TREE_VALUE (params
);
1893 params
= TREE_CHAIN (params
);
1895 cur_type
= TREE_TYPE (cur_param
);
1897 STRIP_NOPS (cur_param
);
1899 /* Check the types of any additional pointer arguments
1900 that precede the "real" argument. */
1901 for (i
= 0; i
< fci
->pointer_count
+ aflag
; ++i
)
1903 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
1905 cur_type
= TREE_TYPE (cur_type
);
1907 if (cur_param
!= 0 && TREE_CODE (cur_param
) == ADDR_EXPR
)
1908 cur_param
= TREE_OPERAND (cur_param
, 0);
1914 if (TREE_CODE (cur_type
) != ERROR_MARK
)
1915 warning ((fci
->pointer_count
+ aflag
== 1
1916 ? "format argument is not a pointer (arg %d)"
1917 : "format argument is not a pointer to a pointer (arg %d)"),
1922 /* See if this is an attempt to write into a const type with
1923 scanf or with printf "%n". */
1924 if ((info
->format_type
== scanf_format_type
1925 || (info
->format_type
== printf_format_type
1926 && format_char
== 'n'))
1927 && i
== fci
->pointer_count
+ aflag
1929 && TREE_CODE (cur_type
) != ERROR_MARK
1930 && (TYPE_READONLY (cur_type
)
1932 && (TREE_CODE_CLASS (TREE_CODE (cur_param
)) == 'c'
1933 || (TREE_CODE_CLASS (TREE_CODE (cur_param
)) == 'd'
1934 && TREE_READONLY (cur_param
))))))
1935 warning ("writing into constant object (arg %d)", arg_num
);
1937 /* Check the type of the "real" argument, if there's a type we want. */
1938 if (i
== fci
->pointer_count
+ aflag
&& wanted_type
!= 0
1939 && TREE_CODE (cur_type
) != ERROR_MARK
1940 && wanted_type
!= TYPE_MAIN_VARIANT (cur_type
)
1941 /* If we want `void *', allow any pointer type.
1942 (Anything else would already have got a warning.) */
1943 && ! (wanted_type
== void_type_node
1944 && fci
->pointer_count
> 0)
1945 /* Don't warn about differences merely in signedness. */
1946 && !(TREE_CODE (wanted_type
) == INTEGER_TYPE
1947 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type
)) == INTEGER_TYPE
1948 && (TREE_UNSIGNED (wanted_type
)
1949 ? wanted_type
== (cur_type
= unsigned_type (cur_type
))
1950 : wanted_type
== (cur_type
= signed_type (cur_type
))))
1951 /* Likewise, "signed char", "unsigned char" and "char" are
1952 equivalent but the above test won't consider them equivalent. */
1953 && ! (wanted_type
== char_type_node
1954 && (TYPE_MAIN_VARIANT (cur_type
) == signed_char_type_node
1955 || TYPE_MAIN_VARIANT (cur_type
) == unsigned_char_type_node
)))
1957 register const char *this;
1958 register const char *that
;
1960 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type
)));
1962 if (TREE_CODE (cur_type
) != ERROR_MARK
1963 && TYPE_NAME (cur_type
) != 0
1964 && TREE_CODE (cur_type
) != INTEGER_TYPE
1965 && !(TREE_CODE (cur_type
) == POINTER_TYPE
1966 && TREE_CODE (TREE_TYPE (cur_type
)) == INTEGER_TYPE
))
1968 if (TREE_CODE (TYPE_NAME (cur_type
)) == TYPE_DECL
1969 && DECL_NAME (TYPE_NAME (cur_type
)) != 0)
1970 that
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type
)));
1972 that
= IDENTIFIER_POINTER (TYPE_NAME (cur_type
));
1975 /* A nameless type can't possibly match what the format wants.
1976 So there will be a warning for it.
1977 Make up a string to describe vaguely what it is. */
1980 if (TREE_CODE (cur_type
) == POINTER_TYPE
)
1983 that
= "different type";
1986 /* Make the warning better in case of mismatch of int vs long. */
1987 if (TREE_CODE (cur_type
) == INTEGER_TYPE
1988 && TREE_CODE (wanted_type
) == INTEGER_TYPE
1989 && TYPE_PRECISION (cur_type
) == TYPE_PRECISION (wanted_type
)
1990 && TYPE_NAME (cur_type
) != 0
1991 && TREE_CODE (TYPE_NAME (cur_type
)) == TYPE_DECL
)
1992 that
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type
)));
1994 if (strcmp (this, that
) != 0)
1995 warning ("%s format, %s arg (arg %d)", this, that
, arg_num
);
2000 /* Print a warning if a constant expression had overflow in folding.
2001 Invoke this function on every expression that the language
2002 requires to be a constant expression.
2003 Note the ANSI C standard says it is erroneous for a
2004 constant expression to overflow. */
2007 constant_expression_warning (value
)
2010 if ((TREE_CODE (value
) == INTEGER_CST
|| TREE_CODE (value
) == REAL_CST
2011 || TREE_CODE (value
) == COMPLEX_CST
)
2012 && TREE_CONSTANT_OVERFLOW (value
) && pedantic
)
2013 pedwarn ("overflow in constant expression");
2016 /* Print a warning if an expression had overflow in folding.
2017 Invoke this function on every expression that
2018 (1) appears in the source code, and
2019 (2) might be a constant expression that overflowed, and
2020 (3) is not already checked by convert_and_check;
2021 however, do not invoke this function on operands of explicit casts. */
2024 overflow_warning (value
)
2027 if ((TREE_CODE (value
) == INTEGER_CST
2028 || (TREE_CODE (value
) == COMPLEX_CST
2029 && TREE_CODE (TREE_REALPART (value
)) == INTEGER_CST
))
2030 && TREE_OVERFLOW (value
))
2032 TREE_OVERFLOW (value
) = 0;
2033 if (skip_evaluation
== 0)
2034 warning ("integer overflow in expression");
2036 else if ((TREE_CODE (value
) == REAL_CST
2037 || (TREE_CODE (value
) == COMPLEX_CST
2038 && TREE_CODE (TREE_REALPART (value
)) == REAL_CST
))
2039 && TREE_OVERFLOW (value
))
2041 TREE_OVERFLOW (value
) = 0;
2042 if (skip_evaluation
== 0)
2043 warning ("floating point overflow in expression");
2047 /* Print a warning if a large constant is truncated to unsigned,
2048 or if -Wconversion is used and a constant < 0 is converted to unsigned.
2049 Invoke this function on every expression that might be implicitly
2050 converted to an unsigned type. */
2053 unsigned_conversion_warning (result
, operand
)
2054 tree result
, operand
;
2056 if (TREE_CODE (operand
) == INTEGER_CST
2057 && TREE_CODE (TREE_TYPE (result
)) == INTEGER_TYPE
2058 && TREE_UNSIGNED (TREE_TYPE (result
))
2059 && skip_evaluation
== 0
2060 && !int_fits_type_p (operand
, TREE_TYPE (result
)))
2062 if (!int_fits_type_p (operand
, signed_type (TREE_TYPE (result
))))
2063 /* This detects cases like converting -129 or 256 to unsigned char. */
2064 warning ("large integer implicitly truncated to unsigned type");
2065 else if (warn_conversion
)
2066 warning ("negative integer implicitly converted to unsigned type");
2070 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2071 Invoke this function on every expression that is converted implicitly,
2072 i.e. because of language rules and not because of an explicit cast. */
2075 convert_and_check (type
, expr
)
2078 tree t
= convert (type
, expr
);
2079 if (TREE_CODE (t
) == INTEGER_CST
)
2081 if (TREE_OVERFLOW (t
))
2083 TREE_OVERFLOW (t
) = 0;
2085 /* Do not diagnose overflow in a constant expression merely
2086 because a conversion overflowed. */
2087 TREE_CONSTANT_OVERFLOW (t
) = TREE_CONSTANT_OVERFLOW (expr
);
2089 /* No warning for converting 0x80000000 to int. */
2090 if (!(TREE_UNSIGNED (type
) < TREE_UNSIGNED (TREE_TYPE (expr
))
2091 && TREE_CODE (TREE_TYPE (expr
)) == INTEGER_TYPE
2092 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (expr
))))
2093 /* If EXPR fits in the unsigned version of TYPE,
2094 don't warn unless pedantic. */
2096 || TREE_UNSIGNED (type
)
2097 || ! int_fits_type_p (expr
, unsigned_type (type
)))
2098 && skip_evaluation
== 0)
2099 warning ("overflow in implicit constant conversion");
2102 unsigned_conversion_warning (t
, expr
);
2108 c_expand_expr_stmt (expr
)
2111 /* Do default conversion if safe and possibly important,
2112 in case within ({...}). */
2113 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
2114 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
2115 expr
= default_conversion (expr
);
2117 if (TREE_TYPE (expr
) != error_mark_node
2118 && TYPE_SIZE (TREE_TYPE (expr
)) == 0
2119 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
2120 error ("expression statement has incomplete type");
2122 expand_expr_stmt (expr
);
2125 /* Validate the expression after `case' and apply default promotions. */
2128 check_case_value (value
)
2131 if (value
== NULL_TREE
)
2134 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2135 STRIP_TYPE_NOPS (value
);
2137 if (TREE_CODE (value
) != INTEGER_CST
2138 && value
!= error_mark_node
)
2140 error ("case label does not reduce to an integer constant");
2141 value
= error_mark_node
;
2144 /* Promote char or short to int. */
2145 value
= default_conversion (value
);
2147 constant_expression_warning (value
);
2152 /* Return an integer type with BITS bits of precision,
2153 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2156 type_for_size (bits
, unsignedp
)
2160 if (bits
== TYPE_PRECISION (integer_type_node
))
2161 return unsignedp
? unsigned_type_node
: integer_type_node
;
2163 if (bits
== TYPE_PRECISION (signed_char_type_node
))
2164 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2166 if (bits
== TYPE_PRECISION (short_integer_type_node
))
2167 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2169 if (bits
== TYPE_PRECISION (long_integer_type_node
))
2170 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2172 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
2173 return (unsignedp
? long_long_unsigned_type_node
2174 : long_long_integer_type_node
);
2176 if (bits
== TYPE_PRECISION (widest_integer_literal_type_node
))
2177 return (unsignedp
? widest_unsigned_literal_type_node
2178 : widest_integer_literal_type_node
);
2180 if (bits
<= TYPE_PRECISION (intQI_type_node
))
2181 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2183 if (bits
<= TYPE_PRECISION (intHI_type_node
))
2184 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2186 if (bits
<= TYPE_PRECISION (intSI_type_node
))
2187 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2189 if (bits
<= TYPE_PRECISION (intDI_type_node
))
2190 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2195 /* Return a data type that has machine mode MODE.
2196 If the mode is an integer,
2197 then UNSIGNEDP selects between signed and unsigned types. */
2200 type_for_mode (mode
, unsignedp
)
2201 enum machine_mode mode
;
2204 if (mode
== TYPE_MODE (integer_type_node
))
2205 return unsignedp
? unsigned_type_node
: integer_type_node
;
2207 if (mode
== TYPE_MODE (signed_char_type_node
))
2208 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2210 if (mode
== TYPE_MODE (short_integer_type_node
))
2211 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2213 if (mode
== TYPE_MODE (long_integer_type_node
))
2214 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2216 if (mode
== TYPE_MODE (long_long_integer_type_node
))
2217 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
2219 if (mode
== TYPE_MODE (widest_integer_literal_type_node
))
2220 return unsignedp
? widest_unsigned_literal_type_node
2221 : widest_integer_literal_type_node
;
2223 if (mode
== TYPE_MODE (intQI_type_node
))
2224 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2226 if (mode
== TYPE_MODE (intHI_type_node
))
2227 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2229 if (mode
== TYPE_MODE (intSI_type_node
))
2230 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2232 if (mode
== TYPE_MODE (intDI_type_node
))
2233 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2235 #if HOST_BITS_PER_WIDE_INT >= 64
2236 if (mode
== TYPE_MODE (intTI_type_node
))
2237 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2240 if (mode
== TYPE_MODE (float_type_node
))
2241 return float_type_node
;
2243 if (mode
== TYPE_MODE (double_type_node
))
2244 return double_type_node
;
2246 if (mode
== TYPE_MODE (long_double_type_node
))
2247 return long_double_type_node
;
2249 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
2250 return build_pointer_type (char_type_node
);
2252 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
2253 return build_pointer_type (integer_type_node
);
2258 /* Return an unsigned type the same as TYPE in other respects. */
2260 unsigned_type (type
)
2263 tree type1
= TYPE_MAIN_VARIANT (type
);
2264 if (type1
== signed_char_type_node
|| type1
== char_type_node
)
2265 return unsigned_char_type_node
;
2266 if (type1
== integer_type_node
)
2267 return unsigned_type_node
;
2268 if (type1
== short_integer_type_node
)
2269 return short_unsigned_type_node
;
2270 if (type1
== long_integer_type_node
)
2271 return long_unsigned_type_node
;
2272 if (type1
== long_long_integer_type_node
)
2273 return long_long_unsigned_type_node
;
2274 if (type1
== widest_integer_literal_type_node
)
2275 return widest_unsigned_literal_type_node
;
2276 #if HOST_BITS_PER_WIDE_INT >= 64
2277 if (type1
== intTI_type_node
)
2278 return unsigned_intTI_type_node
;
2280 if (type1
== intDI_type_node
)
2281 return unsigned_intDI_type_node
;
2282 if (type1
== intSI_type_node
)
2283 return unsigned_intSI_type_node
;
2284 if (type1
== intHI_type_node
)
2285 return unsigned_intHI_type_node
;
2286 if (type1
== intQI_type_node
)
2287 return unsigned_intQI_type_node
;
2289 return signed_or_unsigned_type (1, type
);
2292 /* Return a signed type the same as TYPE in other respects. */
2298 tree type1
= TYPE_MAIN_VARIANT (type
);
2299 if (type1
== unsigned_char_type_node
|| type1
== char_type_node
)
2300 return signed_char_type_node
;
2301 if (type1
== unsigned_type_node
)
2302 return integer_type_node
;
2303 if (type1
== short_unsigned_type_node
)
2304 return short_integer_type_node
;
2305 if (type1
== long_unsigned_type_node
)
2306 return long_integer_type_node
;
2307 if (type1
== long_long_unsigned_type_node
)
2308 return long_long_integer_type_node
;
2309 if (type1
== widest_unsigned_literal_type_node
)
2310 return widest_integer_literal_type_node
;
2311 #if HOST_BITS_PER_WIDE_INT >= 64
2312 if (type1
== unsigned_intTI_type_node
)
2313 return intTI_type_node
;
2315 if (type1
== unsigned_intDI_type_node
)
2316 return intDI_type_node
;
2317 if (type1
== unsigned_intSI_type_node
)
2318 return intSI_type_node
;
2319 if (type1
== unsigned_intHI_type_node
)
2320 return intHI_type_node
;
2321 if (type1
== unsigned_intQI_type_node
)
2322 return intQI_type_node
;
2324 return signed_or_unsigned_type (0, type
);
2327 /* Return a type the same as TYPE except unsigned or
2328 signed according to UNSIGNEDP. */
2331 signed_or_unsigned_type (unsignedp
, type
)
2335 if (! INTEGRAL_TYPE_P (type
)
2336 || TREE_UNSIGNED (type
) == unsignedp
)
2339 if (TYPE_PRECISION (type
) == TYPE_PRECISION (signed_char_type_node
))
2340 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2341 if (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
))
2342 return unsignedp
? unsigned_type_node
: integer_type_node
;
2343 if (TYPE_PRECISION (type
) == TYPE_PRECISION (short_integer_type_node
))
2344 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2345 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_integer_type_node
))
2346 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2347 if (TYPE_PRECISION (type
) == TYPE_PRECISION (long_long_integer_type_node
))
2348 return (unsignedp
? long_long_unsigned_type_node
2349 : long_long_integer_type_node
);
2350 if (TYPE_PRECISION (type
) == TYPE_PRECISION (widest_integer_literal_type_node
))
2351 return (unsignedp
? widest_unsigned_literal_type_node
2352 : widest_integer_literal_type_node
);
2356 /* Return the minimum number of bits needed to represent VALUE in a
2357 signed or unsigned type, UNSIGNEDP says which. */
2360 min_precision (value
, unsignedp
)
2366 /* If the value is negative, compute its negative minus 1. The latter
2367 adjustment is because the absolute value of the largest negative value
2368 is one larger than the largest positive value. This is equivalent to
2369 a bit-wise negation, so use that operation instead. */
2371 if (tree_int_cst_sgn (value
) < 0)
2372 value
= fold (build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
));
2374 /* Return the number of bits needed, taking into account the fact
2375 that we need one more bit for a signed than unsigned type. */
2377 if (integer_zerop (value
))
2379 else if (TREE_INT_CST_HIGH (value
) != 0)
2380 log
= HOST_BITS_PER_WIDE_INT
+ floor_log2 (TREE_INT_CST_HIGH (value
));
2382 log
= floor_log2 (TREE_INT_CST_LOW (value
));
2384 return log
+ 1 + ! unsignedp
;
2387 /* Print an error message for invalid operands to arith operation CODE.
2388 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2391 binary_op_error (code
)
2392 enum tree_code code
;
2394 register const char *opname
;
2399 error ("invalid truth-value expression");
2403 opname
= "+"; break;
2405 opname
= "-"; break;
2407 opname
= "*"; break;
2409 opname
= "max"; break;
2411 opname
= "min"; break;
2413 opname
= "=="; break;
2415 opname
= "!="; break;
2417 opname
= "<="; break;
2419 opname
= ">="; break;
2421 opname
= "<"; break;
2423 opname
= ">"; break;
2425 opname
= "<<"; break;
2427 opname
= ">>"; break;
2428 case TRUNC_MOD_EXPR
:
2429 case FLOOR_MOD_EXPR
:
2430 opname
= "%"; break;
2431 case TRUNC_DIV_EXPR
:
2432 case FLOOR_DIV_EXPR
:
2433 opname
= "/"; break;
2435 opname
= "&"; break;
2437 opname
= "|"; break;
2438 case TRUTH_ANDIF_EXPR
:
2439 opname
= "&&"; break;
2440 case TRUTH_ORIF_EXPR
:
2441 opname
= "||"; break;
2443 opname
= "^"; break;
2446 opname
= "rotate"; break;
2448 opname
= "unknown"; break;
2450 error ("invalid operands to binary %s", opname
);
2453 /* Subroutine of build_binary_op, used for comparison operations.
2454 See if the operands have both been converted from subword integer types
2455 and, if so, perhaps change them both back to their original type.
2456 This function is also responsible for converting the two operands
2457 to the proper common type for comparison.
2459 The arguments of this function are all pointers to local variables
2460 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2461 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2463 If this function returns nonzero, it means that the comparison has
2464 a constant value. What this function returns is an expression for
2468 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
2469 tree
*op0_ptr
, *op1_ptr
;
2471 enum tree_code
*rescode_ptr
;
2474 tree op0
= *op0_ptr
;
2475 tree op1
= *op1_ptr
;
2476 int unsignedp0
, unsignedp1
;
2478 tree primop0
, primop1
;
2479 enum tree_code code
= *rescode_ptr
;
2481 /* Throw away any conversions to wider types
2482 already present in the operands. */
2484 primop0
= get_narrower (op0
, &unsignedp0
);
2485 primop1
= get_narrower (op1
, &unsignedp1
);
2487 /* Handle the case that OP0 does not *contain* a conversion
2488 but it *requires* conversion to FINAL_TYPE. */
2490 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
2491 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
2492 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
2493 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
2495 /* If one of the operands must be floated, we cannot optimize. */
2496 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
2497 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
2499 /* If first arg is constant, swap the args (changing operation
2500 so value is preserved), for canonicalization. Don't do this if
2501 the second arg is 0. */
2503 if (TREE_CONSTANT (primop0
)
2504 && ! integer_zerop (primop1
) && ! real_zerop (primop1
))
2506 register tree tem
= primop0
;
2507 register int temi
= unsignedp0
;
2515 unsignedp0
= unsignedp1
;
2538 *rescode_ptr
= code
;
2541 /* If comparing an integer against a constant more bits wide,
2542 maybe we can deduce a value of 1 or 0 independent of the data.
2543 Or else truncate the constant now
2544 rather than extend the variable at run time.
2546 This is only interesting if the constant is the wider arg.
2547 Also, it is not safe if the constant is unsigned and the
2548 variable arg is signed, since in this case the variable
2549 would be sign-extended and then regarded as unsigned.
2550 Our technique fails in this case because the lowest/highest
2551 possible unsigned results don't follow naturally from the
2552 lowest/highest possible values of the variable operand.
2553 For just EQ_EXPR and NE_EXPR there is another technique that
2554 could be used: see if the constant can be faithfully represented
2555 in the other operand's type, by truncating it and reextending it
2556 and see if that preserves the constant's value. */
2558 if (!real1
&& !real2
2559 && TREE_CODE (primop1
) == INTEGER_CST
2560 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
2562 int min_gt
, max_gt
, min_lt
, max_lt
;
2563 tree maxval
, minval
;
2564 /* 1 if comparison is nominally unsigned. */
2565 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
2568 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
2570 /* If TYPE is an enumeration, then we need to get its min/max
2571 values from it's underlying integral type, not the enumerated
2573 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
2574 type
= type_for_size (TYPE_PRECISION (type
), unsignedp0
);
2576 maxval
= TYPE_MAX_VALUE (type
);
2577 minval
= TYPE_MIN_VALUE (type
);
2579 if (unsignedp
&& !unsignedp0
)
2580 *restype_ptr
= signed_type (*restype_ptr
);
2582 if (TREE_TYPE (primop1
) != *restype_ptr
)
2583 primop1
= convert (*restype_ptr
, primop1
);
2584 if (type
!= *restype_ptr
)
2586 minval
= convert (*restype_ptr
, minval
);
2587 maxval
= convert (*restype_ptr
, maxval
);
2590 if (unsignedp
&& unsignedp0
)
2592 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
2593 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
2594 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
2595 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
2599 min_gt
= INT_CST_LT (primop1
, minval
);
2600 max_gt
= INT_CST_LT (primop1
, maxval
);
2601 min_lt
= INT_CST_LT (minval
, primop1
);
2602 max_lt
= INT_CST_LT (maxval
, primop1
);
2606 /* This used to be a switch, but Genix compiler can't handle that. */
2607 if (code
== NE_EXPR
)
2609 if (max_lt
|| min_gt
)
2610 val
= boolean_true_node
;
2612 else if (code
== EQ_EXPR
)
2614 if (max_lt
|| min_gt
)
2615 val
= boolean_false_node
;
2617 else if (code
== LT_EXPR
)
2620 val
= boolean_true_node
;
2622 val
= boolean_false_node
;
2624 else if (code
== GT_EXPR
)
2627 val
= boolean_true_node
;
2629 val
= boolean_false_node
;
2631 else if (code
== LE_EXPR
)
2634 val
= boolean_true_node
;
2636 val
= boolean_false_node
;
2638 else if (code
== GE_EXPR
)
2641 val
= boolean_true_node
;
2643 val
= boolean_false_node
;
2646 /* If primop0 was sign-extended and unsigned comparison specd,
2647 we did a signed comparison above using the signed type bounds.
2648 But the comparison we output must be unsigned.
2650 Also, for inequalities, VAL is no good; but if the signed
2651 comparison had *any* fixed result, it follows that the
2652 unsigned comparison just tests the sign in reverse
2653 (positive values are LE, negative ones GE).
2654 So we can generate an unsigned comparison
2655 against an extreme value of the signed type. */
2657 if (unsignedp
&& !unsignedp0
)
2664 primop1
= TYPE_MIN_VALUE (type
);
2670 primop1
= TYPE_MAX_VALUE (type
);
2677 type
= unsigned_type (type
);
2680 if (!max_gt
&& !unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2682 /* This is the case of (char)x >?< 0x80, which people used to use
2683 expecting old C compilers to change the 0x80 into -0x80. */
2684 if (val
== boolean_false_node
)
2685 warning ("comparison is always false due to limited range of data type");
2686 if (val
== boolean_true_node
)
2687 warning ("comparison is always true due to limited range of data type");
2690 if (!min_lt
&& unsignedp0
&& TREE_CODE (primop0
) != INTEGER_CST
)
2692 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2693 if (val
== boolean_false_node
)
2694 warning ("comparison is always false due to limited range of data type");
2695 if (val
== boolean_true_node
)
2696 warning ("comparison is always true due to limited range of data type");
2701 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2702 if (TREE_SIDE_EFFECTS (primop0
))
2703 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
2707 /* Value is not predetermined, but do the comparison
2708 in the type of the operand that is not constant.
2709 TYPE is already properly set. */
2711 else if (real1
&& real2
2712 && (TYPE_PRECISION (TREE_TYPE (primop0
))
2713 == TYPE_PRECISION (TREE_TYPE (primop1
))))
2714 type
= TREE_TYPE (primop0
);
2716 /* If args' natural types are both narrower than nominal type
2717 and both extend in the same manner, compare them
2718 in the type of the wider arg.
2719 Otherwise must actually extend both to the nominal
2720 common type lest different ways of extending
2722 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2724 else if (unsignedp0
== unsignedp1
&& real1
== real2
2725 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
2726 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
2728 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
2729 type
= signed_or_unsigned_type (unsignedp0
2730 || TREE_UNSIGNED (*restype_ptr
),
2732 /* Make sure shorter operand is extended the right way
2733 to match the longer operand. */
2734 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
2736 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
2741 /* Here we must do the comparison on the nominal type
2742 using the args exactly as we received them. */
2743 type
= *restype_ptr
;
2747 if (!real1
&& !real2
&& integer_zerop (primop1
)
2748 && TREE_UNSIGNED (*restype_ptr
))
2754 /* All unsigned values are >= 0, so we warn if extra warnings
2755 are requested. However, if OP0 is a constant that is
2756 >= 0, the signedness of the comparison isn't an issue,
2757 so suppress the warning. */
2759 && ! (TREE_CODE (primop0
) == INTEGER_CST
2760 && ! TREE_OVERFLOW (convert (signed_type (type
),
2762 warning ("comparison of unsigned expression >= 0 is always true");
2763 value
= boolean_true_node
;
2768 && ! (TREE_CODE (primop0
) == INTEGER_CST
2769 && ! TREE_OVERFLOW (convert (signed_type (type
),
2771 warning ("comparison of unsigned expression < 0 is always false");
2772 value
= boolean_false_node
;
2781 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2782 if (TREE_SIDE_EFFECTS (primop0
))
2783 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
2790 *op0_ptr
= convert (type
, primop0
);
2791 *op1_ptr
= convert (type
, primop1
);
2793 *restype_ptr
= boolean_type_node
;
2798 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2799 or validate its data type for an `if' or `while' statement or ?..: exp.
2801 This preparation consists of taking the ordinary
2802 representation of an expression expr and producing a valid tree
2803 boolean expression describing whether expr is nonzero. We could
2804 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2805 but we optimize comparisons, &&, ||, and !.
2807 The resulting type should always be `boolean_type_node'. */
2810 truthvalue_conversion (expr
)
2813 if (TREE_CODE (expr
) == ERROR_MARK
)
2816 #if 0 /* This appears to be wrong for C++. */
2817 /* These really should return error_mark_node after 2.4 is stable.
2818 But not all callers handle ERROR_MARK properly. */
2819 switch (TREE_CODE (TREE_TYPE (expr
)))
2822 error ("struct type value used where scalar is required");
2823 return boolean_false_node
;
2826 error ("union type value used where scalar is required");
2827 return boolean_false_node
;
2830 error ("array type value used where scalar is required");
2831 return boolean_false_node
;
2838 switch (TREE_CODE (expr
))
2840 /* It is simpler and generates better code to have only TRUTH_*_EXPR
2841 or comparison expressions as truth values at this level. */
2844 /* A one-bit unsigned bit-field is already acceptable. */
2845 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr
, 1)))
2846 && TREE_UNSIGNED (TREE_OPERAND (expr
, 1)))
2852 /* It is simpler and generates better code to have only TRUTH_*_EXPR
2853 or comparison expressions as truth values at this level. */
2855 if (integer_zerop (TREE_OPERAND (expr
, 1)))
2856 return build_unary_op (TRUTH_NOT_EXPR
, TREE_OPERAND (expr
, 0), 0);
2858 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
2859 case TRUTH_ANDIF_EXPR
:
2860 case TRUTH_ORIF_EXPR
:
2861 case TRUTH_AND_EXPR
:
2863 case TRUTH_XOR_EXPR
:
2864 case TRUTH_NOT_EXPR
:
2865 TREE_TYPE (expr
) = boolean_type_node
;
2872 return integer_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2875 return real_zerop (expr
) ? boolean_false_node
: boolean_true_node
;
2878 /* If we are taking the address of a external decl, it might be zero
2879 if it is weak, so we cannot optimize. */
2880 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (expr
, 0))) == 'd'
2881 && DECL_EXTERNAL (TREE_OPERAND (expr
, 0)))
2884 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
2885 return build (COMPOUND_EXPR
, boolean_type_node
,
2886 TREE_OPERAND (expr
, 0), boolean_true_node
);
2888 return boolean_true_node
;
2891 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1))
2892 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
2893 truthvalue_conversion (TREE_OPERAND (expr
, 0)),
2894 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2901 /* These don't change whether an object is non-zero or zero. */
2902 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2906 /* These don't change whether an object is zero or non-zero, but
2907 we can't ignore them if their second arg has side-effects. */
2908 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
2909 return build (COMPOUND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 1),
2910 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
2912 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2915 /* Distribute the conversion into the arms of a COND_EXPR. */
2916 return fold (build (COND_EXPR
, boolean_type_node
, TREE_OPERAND (expr
, 0),
2917 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
2918 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
2921 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2922 since that affects how `default_conversion' will behave. */
2923 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
2924 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
2926 /* fall through... */
2928 /* If this is widening the argument, we can ignore it. */
2929 if (TYPE_PRECISION (TREE_TYPE (expr
))
2930 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
2931 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
2935 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2937 if (TARGET_FLOAT_FORMAT
== IEEE_FLOAT_FORMAT
2938 && TREE_CODE (TREE_TYPE (expr
)) == REAL_TYPE
)
2940 /* fall through... */
2942 /* This and MINUS_EXPR can be changed into a comparison of the
2944 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
2945 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
2946 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
2947 TREE_OPERAND (expr
, 1), 1);
2948 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
2949 fold (build1 (NOP_EXPR
,
2950 TREE_TYPE (TREE_OPERAND (expr
, 0)),
2951 TREE_OPERAND (expr
, 1))), 1);
2954 if (integer_onep (TREE_OPERAND (expr
, 1))
2955 && TREE_TYPE (expr
) != boolean_type_node
)
2956 /* Using convert here would cause infinite recursion. */
2957 return build1 (NOP_EXPR
, boolean_type_node
, expr
);
2961 if (warn_parentheses
&& C_EXP_ORIGINAL_CODE (expr
) == MODIFY_EXPR
)
2962 warning ("suggest parentheses around assignment used as truth value");
2969 if (TREE_CODE (TREE_TYPE (expr
)) == COMPLEX_TYPE
)
2971 tree tem
= save_expr (expr
);
2972 return (build_binary_op
2973 ((TREE_SIDE_EFFECTS (expr
)
2974 ? TRUTH_OR_EXPR
: TRUTH_ORIF_EXPR
),
2975 truthvalue_conversion (build_unary_op (REALPART_EXPR
, tem
, 0)),
2976 truthvalue_conversion (build_unary_op (IMAGPART_EXPR
, tem
, 0)),
2980 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
2984 /* Read the rest of a #-directive from input stream FINPUT.
2985 In normal use, the directive name and the white space after it
2986 have already been read, so they won't be included in the result.
2987 We allow for the fact that the directive line may contain
2988 a newline embedded within a character or string literal which forms
2989 a part of the directive.
2991 The value is a string in a reusable buffer. It remains valid
2992 only until the next time this function is called. */
2993 unsigned char *yy_cur
, *yy_lim
;
2995 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
2996 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
3003 parse_in
.limit
= parse_in
.token_buffer
;
3004 cpp_token
= cpp_get_token (&parse_in
);
3005 if (cpp_token
== CPP_EOF
)
3007 yy_lim
= CPP_PWRITTEN (&parse_in
);
3008 yy_cur
= parse_in
.token_buffer
;
3009 if (yy_cur
< yy_lim
)
3015 get_directive_line ()
3017 static char *directive_buffer
= NULL
;
3018 static unsigned buffer_length
= 0;
3020 register char *buffer_limit
;
3021 register int looking_for
= 0;
3022 register int char_escaped
= 0;
3024 if (buffer_length
== 0)
3026 directive_buffer
= (char *)xmalloc (128);
3027 buffer_length
= 128;
3030 buffer_limit
= &directive_buffer
[buffer_length
];
3032 for (p
= directive_buffer
; ; )
3036 /* Make buffer bigger if it is full. */
3037 if (p
>= buffer_limit
)
3039 register unsigned bytes_used
= (p
- directive_buffer
);
3043 = (char *)xrealloc (directive_buffer
, buffer_length
);
3044 p
= &directive_buffer
[bytes_used
];
3045 buffer_limit
= &directive_buffer
[buffer_length
];
3050 /* Discard initial whitespace. */
3051 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
3054 /* Detect the end of the directive. */
3055 if (c
== '\n' && looking_for
== 0)
3064 return directive_buffer
;
3066 /* Handle string and character constant syntax. */
3069 if (looking_for
== c
&& !char_escaped
)
3070 looking_for
= 0; /* Found terminator... stop looking. */
3073 if (c
== '\'' || c
== '"')
3074 looking_for
= c
; /* Don't stop buffering until we see another
3075 another one of these (or an EOF). */
3077 /* Handle backslash. */
3078 char_escaped
= (c
== '\\' && ! char_escaped
);
3082 /* Read the rest of a #-directive from input stream FINPUT.
3083 In normal use, the directive name and the white space after it
3084 have already been read, so they won't be included in the result.
3085 We allow for the fact that the directive line may contain
3086 a newline embedded within a character or string literal which forms
3087 a part of the directive.
3089 The value is a string in a reusable buffer. It remains valid
3090 only until the next time this function is called.
3092 The terminating character ('\n' or EOF) is left in FINPUT for the
3093 caller to re-read. */
3096 get_directive_line (finput
)
3097 register FILE *finput
;
3099 static char *directive_buffer
= NULL
;
3100 static unsigned buffer_length
= 0;
3102 register char *buffer_limit
;
3103 register int looking_for
= 0;
3104 register int char_escaped
= 0;
3106 if (buffer_length
== 0)
3108 directive_buffer
= (char *)xmalloc (128);
3109 buffer_length
= 128;
3112 buffer_limit
= &directive_buffer
[buffer_length
];
3114 for (p
= directive_buffer
; ; )
3118 /* Make buffer bigger if it is full. */
3119 if (p
>= buffer_limit
)
3121 register unsigned bytes_used
= (p
- directive_buffer
);
3125 = (char *)xrealloc (directive_buffer
, buffer_length
);
3126 p
= &directive_buffer
[bytes_used
];
3127 buffer_limit
= &directive_buffer
[buffer_length
];
3132 /* Discard initial whitespace. */
3133 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
3136 /* Detect the end of the directive. */
3137 if (looking_for
== 0
3138 && (c
== '\n' || c
== EOF
))
3147 return directive_buffer
;
3149 /* Handle string and character constant syntax. */
3152 if (looking_for
== c
&& !char_escaped
)
3153 looking_for
= 0; /* Found terminator... stop looking. */
3156 if (c
== '\'' || c
== '"')
3157 looking_for
= c
; /* Don't stop buffering until we see another
3158 one of these (or an EOF). */
3160 /* Handle backslash. */
3161 char_escaped
= (c
== '\\' && ! char_escaped
);
3164 #endif /* !USE_CPPLIB */
3166 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3167 down to the element type of an array. */
3170 c_build_qualified_type (type
, type_quals
)
3174 /* A restrict-qualified pointer type must be a pointer to object or
3175 incomplete type. Note that the use of POINTER_TYPE_P also allows
3176 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
3177 the C++ front-end also use POINTER_TYPE for pointer-to-member
3178 values, so even though it should be illegal to use `restrict'
3179 with such an entity we don't flag that here. Thus, special case
3180 code for that case is required in the C++ front-end. */
3181 if ((type_quals
& TYPE_QUAL_RESTRICT
)
3182 && (!POINTER_TYPE_P (type
)
3183 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type
))))
3185 error ("invalid use of `restrict'");
3186 type_quals
&= ~TYPE_QUAL_RESTRICT
;
3189 if (TREE_CODE (type
) == ARRAY_TYPE
)
3190 return build_array_type (c_build_qualified_type (TREE_TYPE (type
),
3192 TYPE_DOMAIN (type
));
3193 return build_qualified_type (type
, type_quals
);
3196 /* Apply the TYPE_QUALS to the new DECL. */
3199 c_apply_type_quals_to_decl (type_quals
, decl
)
3203 if (type_quals
& TYPE_QUAL_CONST
)
3204 TREE_READONLY (decl
) = 1;
3205 if (type_quals
& TYPE_QUAL_VOLATILE
)
3207 TREE_SIDE_EFFECTS (decl
) = 1;
3208 TREE_THIS_VOLATILE (decl
) = 1;
3210 if (type_quals
& TYPE_QUAL_RESTRICT
)
3212 if (!TREE_TYPE (decl
)
3213 || !POINTER_TYPE_P (TREE_TYPE (decl
))
3214 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl
))))
3215 error ("invalid use of `restrict'");
3216 else if (flag_strict_aliasing
)
3218 /* No two restricted pointers can point at the same thing.
3219 However, a restricted pointer can point at the same thing
3220 as an unrestricted pointer, if that unrestricted pointer
3221 is based on the restricted pointer. So, we make the
3222 alias set for the restricted pointer a subset of the
3223 alias set for the type pointed to by the type of the
3226 int pointed_to_alias_set
3227 = get_alias_set (TREE_TYPE (TREE_TYPE (decl
)));
3229 if (!pointed_to_alias_set
)
3230 /* It's not legal to make a subset of alias set zero. */
3234 DECL_POINTER_ALIAS_SET (decl
) = new_alias_set ();
3235 record_alias_subset (pointed_to_alias_set
,
3236 DECL_POINTER_ALIAS_SET (decl
));
3242 /* T is an expression with pointer type. Find the DECL on which this
3243 expression is based. (For example, in `a[i]' this would be `a'.)
3244 If there is no such DECL, or a unique decl cannot be determined,
3245 NULL_TREE is retured. */
3248 c_find_base_decl (t
)
3254 if (t
== NULL_TREE
|| t
== error_mark_node
)
3257 if (!POINTER_TYPE_P (TREE_TYPE (t
)))
3262 if (TREE_CODE (t
) == FIELD_DECL
3263 || TREE_CODE (t
) == PARM_DECL
3264 || TREE_CODE (t
) == VAR_DECL
)
3265 /* Aha, we found a pointer-typed declaration. */
3268 /* It would be nice to deal with COMPONENT_REFs here. If we could
3269 tell that `a' and `b' were the same, then `a->f' and `b->f' are
3272 /* Handle general expressions. */
3273 switch (TREE_CODE_CLASS (TREE_CODE (t
)))
3278 for (i
= tree_code_length
[(int) TREE_CODE (t
)]; --i
>= 0;)
3280 tree d
= c_find_base_decl (TREE_OPERAND (t
, i
));
3285 else if (d
&& d
!= decl
)
3286 /* Two different declarations. That's confusing; let's
3287 just assume we don't know what's going on. */
3300 /* Return the typed-based alias set for T, which may be an expression
3310 if (t
== error_mark_node
)
3313 type
= (TREE_CODE_CLASS (TREE_CODE (t
)) == 't')
3314 ? t
: TREE_TYPE (t
);
3316 if (type
== error_mark_node
)
3319 /* Deal with special cases first; for certain kinds of references
3320 we're interested in more than just the type. */
3322 if (TREE_CODE (t
) == BIT_FIELD_REF
)
3323 /* Perhaps reads and writes to this piece of data alias fields
3324 neighboring the bitfield. Perhaps that's impossible. For now,
3325 let's just assume that bitfields can alias everything, which is
3326 the conservative assumption. */
3329 /* Permit type-punning when accessing a union, provided the access
3330 is directly through the union. For example, this code does not
3331 permit taking the address of a union member and then storing
3332 through it. Even the type-punning allowed here is a GCC
3333 extension, albeit a common and useful one; the C standard says
3334 that such accesses have implementation-defined behavior. */
3336 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
3337 u
= TREE_OPERAND (u
, 0))
3338 if (TREE_CODE (u
) == COMPONENT_REF
3339 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
3342 if (TREE_CODE (t
) == INDIRECT_REF
)
3344 /* Check for accesses through restrict-qualified pointers. */
3345 tree decl
= c_find_base_decl (TREE_OPERAND (t
, 0));
3347 if (decl
&& DECL_POINTER_ALIAS_SET_KNOWN_P (decl
))
3348 /* We use the alias set indicated in the declaration. */
3349 return DECL_POINTER_ALIAS_SET (decl
);
3352 /* From here on, only the type matters. */
3354 if (TREE_CODE (t
) == COMPONENT_REF
3355 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (t
, 1)))
3356 /* Since build_modify_expr calls get_unwidened for stores to
3357 component references, the type of a bit field can be changed
3358 from (say) `unsigned int : 16' to `unsigned short' or from
3359 `enum E : 16' to `short'. We want the real type of the
3360 bit-field in this case, not some the integral equivalent. */
3361 type
= DECL_BIT_FIELD_TYPE (TREE_OPERAND (t
, 1));
3363 if (TYPE_ALIAS_SET_KNOWN_P (type
))
3364 /* If we've already calculated the value, just return it. */
3365 return TYPE_ALIAS_SET (type
);
3366 else if (TYPE_MAIN_VARIANT (type
) != type
)
3367 /* The C standard specifically allows aliasing between
3368 cv-qualified variants of types. */
3369 TYPE_ALIAS_SET (type
) = c_get_alias_set (TYPE_MAIN_VARIANT (type
));
3370 else if (TREE_CODE (type
) == INTEGER_TYPE
)
3372 tree signed_variant
;
3374 /* The C standard specifically allows aliasing between signed and
3375 unsigned variants of the same type. We treat the signed
3376 variant as canonical. */
3377 signed_variant
= signed_type (type
);
3379 if (signed_variant
!= type
)
3380 TYPE_ALIAS_SET (type
) = c_get_alias_set (signed_variant
);
3381 else if (signed_variant
== signed_char_type_node
)
3382 /* The C standard guarantess that any object may be accessed
3383 via an lvalue that has character type. We don't have to
3384 check for unsigned_char_type_node or char_type_node because
3385 we are specifically looking at the signed variant. */
3386 TYPE_ALIAS_SET (type
) = 0;
3388 else if (TREE_CODE (type
) == ARRAY_TYPE
)
3389 /* Anything that can alias one of the array elements can alias
3390 the entire array as well. */
3391 TYPE_ALIAS_SET (type
) = c_get_alias_set (TREE_TYPE (type
));
3392 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
3393 /* There are no objects of FUNCTION_TYPE, so there's no point in
3394 using up an alias set for them. (There are, of course,
3395 pointers and references to functions, but that's
3397 TYPE_ALIAS_SET (type
) = 0;
3398 else if (TREE_CODE (type
) == RECORD_TYPE
3399 || TREE_CODE (type
) == UNION_TYPE
)
3400 /* If TYPE is a struct or union type then we're reading or
3401 writing an entire struct. Thus, we don't know anything about
3402 aliasing. (In theory, such an access can only alias objects
3403 whose type is the same as one of the fields, recursively, but
3404 we don't yet make any use of that information.) */
3405 TYPE_ALIAS_SET (type
) = 0;
3406 else if (TREE_CODE (type
) == POINTER_TYPE
3407 || TREE_CODE (type
) == REFERENCE_TYPE
)
3411 /* Unfortunately, there is no canonical form of a pointer type.
3412 In particular, if we have `typedef int I', then `int *', and
3413 `I *' are different types. So, we have to pick a canonical
3414 representative. We do this below.
3416 Technically, this approach is actually more conservative that
3417 it needs to be. In particular, `const int *' and `int *'
3418 chould be in different alias sets, according to the C and C++
3419 standard, since their types are not the same, and so,
3420 technically, an `int **' and `const int **' cannot point at
3423 But, the standard is wrong. In particular, this code is
3428 const int* const* cipp = &ip;
3430 And, it doesn't make sense for that to be legal unless you
3431 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
3432 the pointed-to types. This issue has been reported to the
3434 t
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
3435 t
= ((TREE_CODE (type
) == POINTER_TYPE
)
3436 ? build_pointer_type (t
) : build_reference_type (t
));
3438 TYPE_ALIAS_SET (type
) = c_get_alias_set (t
);
3441 if (!TYPE_ALIAS_SET_KNOWN_P (type
))
3443 /* Types that are not allocated on the permanent obstack are not
3444 placed in the type hash table. Thus, there can be multiple
3445 copies of identical types in local scopes. In the long run,
3446 all types should be permanent. */
3447 if (! TREE_PERMANENT (type
))
3448 TYPE_ALIAS_SET (type
) = 0;
3450 /* TYPE is something we haven't seen before. Put it in a new
3452 TYPE_ALIAS_SET (type
) = new_alias_set ();
3455 return TYPE_ALIAS_SET (type
);
3458 /* Build tree nodes and builtin functions common to both C and C++ language
3460 CPLUS_MODE is nonzero if we are called from the C++ frontend, we generate
3461 some stricter prototypes in that case.
3462 NO_BUILTINS and NO_NONANSI_BUILTINS contain the respective values of
3463 the language frontend flags flag_no_builtin and
3464 flag_no_nonansi_builtin. */
3466 c_common_nodes_and_builtins (cplus_mode
, no_builtins
, no_nonansi_builtins
)
3467 int cplus_mode
, no_builtins
, no_nonansi_builtins
;
3470 tree memcpy_ftype
, memset_ftype
, strlen_ftype
;
3471 tree endlink
, int_endlink
, double_endlink
, unsigned_endlink
;
3472 tree sizetype_endlink
;
3473 tree ptr_ftype
, ptr_ftype_unsigned
;
3474 tree void_ftype_any
, void_ftype_int
;
3475 tree double_ftype_double
, double_ftype_double_double
;
3476 tree float_ftype_float
, ldouble_ftype_ldouble
;
3477 tree int_ftype_cptr_cptr_sizet
;
3478 tree int_ftype_string_string
, string_ftype_ptr_ptr
;
3479 tree long_ftype_long
;
3480 /* Either char* or void*. */
3481 tree traditional_ptr_type_node
;
3482 tree va_list_ptr_type_node
;
3483 tree va_list_arg_type_node
;
3485 pushdecl (build_decl (TYPE_DECL
, get_identifier ("__builtin_va_list"),
3486 va_list_type_node
));
3488 va_list_ptr_type_node
= build_pointer_type (va_list_type_node
);
3490 if (TREE_CODE (va_list_type_node
) == ARRAY_TYPE
)
3491 va_list_arg_type_node
= build_pointer_type (TREE_TYPE (va_list_type_node
));
3493 va_list_arg_type_node
= va_list_type_node
;
3495 endlink
= void_list_node
;
3496 int_endlink
= tree_cons (NULL_TREE
, integer_type_node
, endlink
);
3497 double_endlink
= tree_cons (NULL_TREE
, double_type_node
, endlink
);
3498 unsigned_endlink
= tree_cons (NULL_TREE
, unsigned_type_node
, endlink
);
3500 ptr_ftype
= build_function_type (ptr_type_node
, NULL_TREE
);
3501 ptr_ftype_unsigned
= build_function_type (ptr_type_node
, unsigned_endlink
);
3502 sizetype_endlink
= tree_cons (NULL_TREE
, sizetype
, endlink
);
3503 /* We realloc here because sizetype could be int or unsigned. S'ok. */
3504 ptr_ftype_sizetype
= build_function_type (ptr_type_node
, sizetype_endlink
);
3506 void_ftype_any
= build_function_type (void_type_node
, NULL_TREE
);
3507 void_ftype
= build_function_type (void_type_node
, endlink
);
3508 void_ftype_int
= build_function_type (void_type_node
, int_endlink
);
3510 = build_function_type (void_type_node
,
3511 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
3514 = build_function_type (float_type_node
,
3515 tree_cons (NULL_TREE
, float_type_node
, endlink
));
3518 = build_function_type (double_type_node
, double_endlink
);
3520 ldouble_ftype_ldouble
3521 = build_function_type (long_double_type_node
,
3522 tree_cons (NULL_TREE
, long_double_type_node
,
3525 double_ftype_double_double
3526 = build_function_type (double_type_node
,
3527 tree_cons (NULL_TREE
, double_type_node
,
3531 = build_function_type (integer_type_node
, int_endlink
);
3534 = build_function_type (long_integer_type_node
,
3535 tree_cons (NULL_TREE
, long_integer_type_node
,
3538 int_ftype_cptr_cptr_sizet
3539 = build_function_type (integer_type_node
,
3540 tree_cons (NULL_TREE
, const_ptr_type_node
,
3541 tree_cons (NULL_TREE
, const_ptr_type_node
,
3542 tree_cons (NULL_TREE
,
3546 /* Prototype for strcpy. */
3547 string_ftype_ptr_ptr
3548 = build_function_type (string_type_node
,
3549 tree_cons (NULL_TREE
, string_type_node
,
3550 tree_cons (NULL_TREE
,
3551 const_string_type_node
,
3554 /* Prototype for strcmp. */
3555 int_ftype_string_string
3556 = build_function_type (integer_type_node
,
3557 tree_cons (NULL_TREE
, const_string_type_node
,
3558 tree_cons (NULL_TREE
,
3559 const_string_type_node
,
3562 /* Prototype for strlen. */
3564 = build_function_type ((flag_traditional
&& ! cplus_mode
3565 ? integer_type_node
: sizetype
),
3566 tree_cons (NULL_TREE
, const_string_type_node
,
3569 traditional_ptr_type_node
= (flag_traditional
&& ! cplus_mode
3570 ? string_type_node
: ptr_type_node
);
3572 /* Prototype for memcpy. */
3574 = build_function_type (traditional_ptr_type_node
,
3575 tree_cons (NULL_TREE
, ptr_type_node
,
3576 tree_cons (NULL_TREE
, const_ptr_type_node
,
3577 sizetype_endlink
)));
3579 /* Prototype for memset. */
3581 = build_function_type (traditional_ptr_type_node
,
3582 tree_cons (NULL_TREE
, ptr_type_node
,
3583 tree_cons (NULL_TREE
, integer_type_node
,
3584 tree_cons (NULL_TREE
,
3588 builtin_function ("__builtin_constant_p", default_function_type
,
3589 BUILT_IN_CONSTANT_P
, NULL_PTR
);
3591 builtin_function ("__builtin_return_address", ptr_ftype_unsigned
,
3592 BUILT_IN_RETURN_ADDRESS
, NULL_PTR
);
3594 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned
,
3595 BUILT_IN_FRAME_ADDRESS
, NULL_PTR
);
3597 builtin_function ("__builtin_alloca", ptr_ftype_sizetype
,
3598 BUILT_IN_ALLOCA
, "alloca");
3599 builtin_function ("__builtin_ffs", int_ftype_int
, BUILT_IN_FFS
, NULL_PTR
);
3600 /* Define alloca, ffs as builtins.
3601 Declare _exit just to mark it as volatile. */
3602 if (! no_builtins
&& ! no_nonansi_builtins
)
3604 temp
= builtin_function ("alloca", ptr_ftype_sizetype
,
3605 BUILT_IN_ALLOCA
, NULL_PTR
);
3606 /* Suppress error if redefined as a non-function. */
3607 DECL_BUILT_IN_NONANSI (temp
) = 1;
3608 temp
= builtin_function ("ffs", int_ftype_int
, BUILT_IN_FFS
, NULL_PTR
);
3609 /* Suppress error if redefined as a non-function. */
3610 DECL_BUILT_IN_NONANSI (temp
) = 1;
3611 temp
= builtin_function ("_exit", void_ftype_int
,
3612 NOT_BUILT_IN
, NULL_PTR
);
3613 TREE_THIS_VOLATILE (temp
) = 1;
3614 TREE_SIDE_EFFECTS (temp
) = 1;
3615 /* Suppress error if redefined as a non-function. */
3616 DECL_BUILT_IN_NONANSI (temp
) = 1;
3619 builtin_function ("__builtin_abs", int_ftype_int
, BUILT_IN_ABS
, NULL_PTR
);
3620 builtin_function ("__builtin_fabsf", float_ftype_float
, BUILT_IN_FABS
,
3622 builtin_function ("__builtin_fabs", double_ftype_double
, BUILT_IN_FABS
,
3624 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
3626 builtin_function ("__builtin_labs", long_ftype_long
, BUILT_IN_LABS
,
3628 builtin_function ("__builtin_saveregs", ptr_ftype
, BUILT_IN_SAVEREGS
,
3630 builtin_function ("__builtin_classify_type", default_function_type
,
3631 BUILT_IN_CLASSIFY_TYPE
, NULL_PTR
);
3632 builtin_function ("__builtin_next_arg", ptr_ftype
, BUILT_IN_NEXT_ARG
,
3634 builtin_function ("__builtin_args_info", int_ftype_int
, BUILT_IN_ARGS_INFO
,
3636 builtin_function ("__builtin_setjmp",
3637 build_function_type (integer_type_node
,
3638 tree_cons (NULL_TREE
, ptr_type_node
,
3640 BUILT_IN_SETJMP
, NULL_PTR
);
3641 builtin_function ("__builtin_longjmp",
3642 build_function_type (void_type_node
,
3643 tree_cons (NULL_TREE
, ptr_type_node
,
3644 tree_cons (NULL_TREE
,
3647 BUILT_IN_LONGJMP
, NULL_PTR
);
3648 builtin_function ("__builtin_trap", void_ftype
, BUILT_IN_TRAP
, NULL_PTR
);
3650 /* Untyped call and return. */
3651 builtin_function ("__builtin_apply_args", ptr_ftype
,
3652 BUILT_IN_APPLY_ARGS
, NULL_PTR
);
3654 temp
= tree_cons (NULL_TREE
,
3655 build_pointer_type (build_function_type (void_type_node
,
3657 tree_cons (NULL_TREE
,
3659 tree_cons (NULL_TREE
,
3662 builtin_function ("__builtin_apply",
3663 build_function_type (ptr_type_node
, temp
),
3664 BUILT_IN_APPLY
, NULL_PTR
);
3665 builtin_function ("__builtin_return", void_ftype_ptr
,
3666 BUILT_IN_RETURN
, NULL_PTR
);
3668 /* Support for varargs.h and stdarg.h. */
3669 builtin_function ("__builtin_varargs_start",
3670 build_function_type (void_type_node
,
3671 tree_cons (NULL_TREE
,
3672 va_list_ptr_type_node
,
3674 BUILT_IN_VARARGS_START
, NULL_PTR
);
3676 builtin_function ("__builtin_stdarg_start",
3677 build_function_type (void_type_node
,
3678 tree_cons (NULL_TREE
,
3679 va_list_ptr_type_node
,
3681 BUILT_IN_STDARG_START
, NULL_PTR
);
3683 builtin_function ("__builtin_va_end",
3684 build_function_type (void_type_node
,
3685 tree_cons (NULL_TREE
,
3686 va_list_arg_type_node
,
3688 BUILT_IN_VA_END
, NULL_PTR
);
3690 builtin_function ("__builtin_va_copy",
3691 build_function_type (void_type_node
,
3692 tree_cons (NULL_TREE
,
3693 va_list_ptr_type_node
,
3694 tree_cons (NULL_TREE
,
3695 va_list_arg_type_node
,
3697 BUILT_IN_VA_COPY
, NULL_PTR
);
3699 /* Currently under experimentation. */
3700 builtin_function ("__builtin_memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
,
3702 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet
,
3703 BUILT_IN_MEMCMP
, "memcmp");
3704 builtin_function ("__builtin_memset", memset_ftype
, BUILT_IN_MEMSET
,
3706 builtin_function ("__builtin_strcmp", int_ftype_string_string
,
3707 BUILT_IN_STRCMP
, "strcmp");
3708 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr
,
3709 BUILT_IN_STRCPY
, "strcpy");
3710 builtin_function ("__builtin_strlen", strlen_ftype
,
3711 BUILT_IN_STRLEN
, "strlen");
3712 builtin_function ("__builtin_sqrtf", float_ftype_float
,
3713 BUILT_IN_FSQRT
, "sqrtf");
3714 builtin_function ("__builtin_fsqrt", double_ftype_double
,
3715 BUILT_IN_FSQRT
, "sqrt");
3716 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble
,
3717 BUILT_IN_FSQRT
, "sqrtl");
3718 builtin_function ("__builtin_sinf", float_ftype_float
,
3719 BUILT_IN_SIN
, "sinf");
3720 builtin_function ("__builtin_sin", double_ftype_double
,
3721 BUILT_IN_SIN
, "sin");
3722 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble
,
3723 BUILT_IN_SIN
, "sinl");
3724 builtin_function ("__builtin_cosf", float_ftype_float
,
3725 BUILT_IN_COS
, "cosf");
3726 builtin_function ("__builtin_cos", double_ftype_double
,
3727 BUILT_IN_COS
, "cos");
3728 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble
,
3729 BUILT_IN_COS
, "cosl");
3733 builtin_function ("abs", int_ftype_int
, BUILT_IN_ABS
, NULL_PTR
);
3734 builtin_function ("fabsf", float_ftype_float
, BUILT_IN_FABS
, NULL_PTR
);
3735 builtin_function ("fabs", double_ftype_double
, BUILT_IN_FABS
, NULL_PTR
);
3736 builtin_function ("fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
3738 builtin_function ("labs", long_ftype_long
, BUILT_IN_LABS
, NULL_PTR
);
3739 builtin_function ("memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
, NULL_PTR
);
3740 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet
, BUILT_IN_MEMCMP
,
3742 builtin_function ("memset", memset_ftype
, BUILT_IN_MEMSET
, NULL_PTR
);
3743 builtin_function ("strcmp", int_ftype_string_string
, BUILT_IN_STRCMP
,
3745 builtin_function ("strcpy", string_ftype_ptr_ptr
, BUILT_IN_STRCPY
,
3747 builtin_function ("strlen", strlen_ftype
, BUILT_IN_STRLEN
, NULL_PTR
);
3748 builtin_function ("sqrtf", float_ftype_float
, BUILT_IN_FSQRT
, NULL_PTR
);
3749 builtin_function ("sqrt", double_ftype_double
, BUILT_IN_FSQRT
, NULL_PTR
);
3750 builtin_function ("sqrtl", ldouble_ftype_ldouble
, BUILT_IN_FSQRT
,
3752 builtin_function ("sinf", float_ftype_float
, BUILT_IN_SIN
, NULL_PTR
);
3753 builtin_function ("sin", double_ftype_double
, BUILT_IN_SIN
, NULL_PTR
);
3754 builtin_function ("sinl", ldouble_ftype_ldouble
, BUILT_IN_SIN
, NULL_PTR
);
3755 builtin_function ("cosf", float_ftype_float
, BUILT_IN_COS
, NULL_PTR
);
3756 builtin_function ("cos", double_ftype_double
, BUILT_IN_COS
, NULL_PTR
);
3757 builtin_function ("cosl", ldouble_ftype_ldouble
, BUILT_IN_COS
, NULL_PTR
);
3759 /* Declare these functions volatile
3760 to avoid spurious "control drops through" warnings. */
3761 temp
= builtin_function ("abort", cplus_mode
? void_ftype
: void_ftype_any
,
3762 NOT_BUILT_IN
, NULL_PTR
);
3763 TREE_THIS_VOLATILE (temp
) = 1;
3764 TREE_SIDE_EFFECTS (temp
) = 1;
3766 #if 0 /* ??? The C++ frontend used to do this. */
3767 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3769 DECL_BUILT_IN_NONANSI (temp
) = 1;
3771 temp
= builtin_function ("exit",
3772 cplus_mode
? void_ftype_int
: void_ftype_any
,
3773 NOT_BUILT_IN
, NULL_PTR
);
3774 TREE_THIS_VOLATILE (temp
) = 1;
3775 TREE_SIDE_EFFECTS (temp
) = 1;
3777 #if 0 /* ??? The C++ frontend used to do this. */
3778 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3780 DECL_BUILT_IN_NONANSI (temp
) = 1;
3785 /* Support for these has not been written in either expand_builtin
3786 or build_function_call. */
3787 builtin_function ("__builtin_div", default_ftype
, BUILT_IN_DIV
, NULL_PTR
);
3788 builtin_function ("__builtin_ldiv", default_ftype
, BUILT_IN_LDIV
, NULL_PTR
);
3789 builtin_function ("__builtin_ffloor", double_ftype_double
, BUILT_IN_FFLOOR
,
3791 builtin_function ("__builtin_fceil", double_ftype_double
, BUILT_IN_FCEIL
,
3793 builtin_function ("__builtin_fmod", double_ftype_double_double
,
3794 BUILT_IN_FMOD
, NULL_PTR
);
3795 builtin_function ("__builtin_frem", double_ftype_double_double
,
3796 BUILT_IN_FREM
, NULL_PTR
);
3797 builtin_function ("__builtin_getexp", double_ftype_double
, BUILT_IN_GETEXP
,
3799 builtin_function ("__builtin_getman", double_ftype_double
, BUILT_IN_GETMAN
,
3803 /* ??? Perhaps there's a better place to do this. But it is related
3804 to __builtin_va_arg, so it isn't that off-the-wall. */
3805 lang_type_promotes_to
= simple_type_promotes_to
;
3809 build_va_arg (expr
, type
)
3812 return build1 (VA_ARG_EXPR
, type
, expr
);
3815 /* Return nonzero if VALUE is a valid constant-valued expression
3816 for use in initializing a static variable; one that can be an
3817 element of a "constant" initializer.
3819 Return null_pointer_node if the value is absolute;
3820 if it is relocatable, return the variable that determines the relocation.
3821 We assume that VALUE has been folded as much as possible;
3822 therefore, we do not need to check for such things as
3823 arithmetic-combinations of integers. */
3826 initializer_constant_valid_p (value
, endtype
)
3830 switch (TREE_CODE (value
))
3833 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
3834 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
3835 && TREE_CONSTANT (value
)
3836 && CONSTRUCTOR_ELTS (value
))
3838 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
3841 return TREE_STATIC (value
) ? null_pointer_node
: 0;
3847 return null_pointer_node
;
3850 return TREE_OPERAND (value
, 0);
3852 case NON_LVALUE_EXPR
:
3853 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3857 /* Allow conversions between pointer types. */
3858 if (POINTER_TYPE_P (TREE_TYPE (value
))
3859 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3860 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3862 /* Allow conversions between real types. */
3863 if (FLOAT_TYPE_P (TREE_TYPE (value
))
3864 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3865 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3867 /* Allow length-preserving conversions between integer types. */
3868 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3869 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
3870 && (TYPE_PRECISION (TREE_TYPE (value
))
3871 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
3872 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3874 /* Allow conversions between other integer types only if
3876 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3877 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3879 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3881 if (inner
== null_pointer_node
)
3882 return null_pointer_node
;
3886 /* Allow (int) &foo provided int is as wide as a pointer. */
3887 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3888 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
3889 && (TYPE_PRECISION (TREE_TYPE (value
))
3890 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
3891 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3894 /* Likewise conversions from int to pointers, but also allow
3895 conversions from 0. */
3896 if (POINTER_TYPE_P (TREE_TYPE (value
))
3897 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3899 if (integer_zerop (TREE_OPERAND (value
, 0)))
3900 return null_pointer_node
;
3901 else if (TYPE_PRECISION (TREE_TYPE (value
))
3902 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
3903 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3907 /* Allow conversions to union types if the value inside is okay. */
3908 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
3909 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3914 if (! INTEGRAL_TYPE_P (endtype
)
3915 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3917 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3919 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3921 /* If either term is absolute, use the other terms relocation. */
3922 if (valid0
== null_pointer_node
)
3924 if (valid1
== null_pointer_node
)
3930 if (! INTEGRAL_TYPE_P (endtype
)
3931 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3933 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3935 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3937 /* Win if second argument is absolute. */
3938 if (valid1
== null_pointer_node
)
3940 /* Win if both arguments have the same relocation.
3941 Then the value is absolute. */
3942 if (valid0
== valid1
)
3943 return null_pointer_node
;
3946 /* Support differences between labels. */
3947 if (INTEGRAL_TYPE_P (endtype
))
3950 op0
= TREE_OPERAND (value
, 0);
3951 op1
= TREE_OPERAND (value
, 1);
3955 if (TREE_CODE (op0
) == ADDR_EXPR
3956 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
3957 && TREE_CODE (op1
) == ADDR_EXPR
3958 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
3959 return null_pointer_node
;
3970 /* Given a type, apply default promotions wrt unnamed function arguments
3971 and return the new type. Return NULL_TREE if no change. */
3972 /* ??? There is a function of the same name in the C++ front end that
3973 does something similar, but is more thorough and does not return NULL
3974 if no change. We could perhaps share code, but it would make the
3975 self_promoting_type property harder to identify. */
3978 simple_type_promotes_to (type
)
3981 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
3982 return double_type_node
;
3984 if (C_PROMOTING_INTEGER_TYPE_P (type
))
3986 /* Traditionally, unsignedness is preserved in default promotions.
3987 Also preserve unsignedness if not really getting any wider. */
3988 if (TREE_UNSIGNED (type
)
3989 && (flag_traditional
3990 || TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)))
3991 return unsigned_type_node
;
3992 return integer_type_node
;
3998 /* Return 1 if PARMS specifies a fixed number of parameters
3999 and none of their types is affected by default promotions. */
4002 self_promoting_args_p (parms
)
4006 for (t
= parms
; t
; t
= TREE_CHAIN (t
))
4008 register tree type
= TREE_VALUE (t
);
4010 if (TREE_CHAIN (t
) == 0 && type
!= void_type_node
)
4016 if (TYPE_MAIN_VARIANT (type
) == float_type_node
)
4019 if (C_PROMOTING_INTEGER_TYPE_P (type
))