Move *-*-gnu* pattern below *-*-linux*.
[official-gcc.git] / gcc / c-common.c
blob217f32d120c82178eacbf3e0c385634412cd9483
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)
9 any later version.
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. */
21 #include "config.h"
22 #include "system.h"
23 #include "tree.h"
24 #include "c-lex.h"
25 #include "c-tree.h"
26 #include "flags.h"
27 #include "obstack.h"
28 #include "toplev.h"
29 #include "output.h"
30 #include "c-pragma.h"
31 #include "rtl.h"
33 #if USE_CPPLIB
34 #include "cpplib.h"
35 cpp_reader parse_in;
36 cpp_options parse_options;
37 enum cpp_token cpp_token;
38 #endif
40 #ifndef WCHAR_TYPE_SIZE
41 #ifdef INT_TYPE_SIZE
42 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
43 #else
44 #define WCHAR_TYPE_SIZE BITS_PER_WORD
45 #endif
46 #endif
48 /* The following symbols are subsumed in the c_global_trees array, and
49 listed here individually for documentation purposes.
51 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.
53 tree short_integer_type_node;
54 tree long_integer_type_node;
55 tree long_long_integer_type_node;
57 tree short_unsigned_type_node;
58 tree long_unsigned_type_node;
59 tree long_long_unsigned_type_node;
61 tree boolean_type_node;
62 tree boolean_false_node;
63 tree boolean_true_node;
65 tree ptrdiff_type_node;
67 tree unsigned_char_type_node;
68 tree signed_char_type_node;
69 tree wchar_type_node;
70 tree signed_wchar_type_node;
71 tree unsigned_wchar_type_node;
73 tree float_type_node;
74 tree double_type_node;
75 tree long_double_type_node;
77 tree complex_integer_type_node;
78 tree complex_float_type_node;
79 tree complex_double_type_node;
80 tree complex_long_double_type_node;
82 tree intQI_type_node;
83 tree intHI_type_node;
84 tree intSI_type_node;
85 tree intDI_type_node;
86 tree intTI_type_node;
88 tree unsigned_intQI_type_node;
89 tree unsigned_intHI_type_node;
90 tree unsigned_intSI_type_node;
91 tree unsigned_intDI_type_node;
92 tree unsigned_intTI_type_node;
94 tree widest_integer_literal_type_node;
95 tree widest_unsigned_literal_type_node;
97 Nodes for types `void *' and `const void *'.
99 tree ptr_type_node, const_ptr_type_node;
101 Nodes for types `char *' and `const char *'.
103 tree string_type_node, const_string_type_node;
105 Type `char[SOMENUMBER]'.
106 Used when an array of char is needed and the size is irrelevant.
108 tree char_array_type_node;
110 Type `int[SOMENUMBER]' or something like it.
111 Used when an array of int needed and the size is irrelevant.
113 tree int_array_type_node;
115 Type `wchar_t[SOMENUMBER]' or something like it.
116 Used when a wide string literal is created.
118 tree wchar_array_type_node;
120 Type `int ()' -- used for implicit declaration of functions.
122 tree default_function_type;
124 Function types `int (int)', etc.
126 tree int_ftype_int;
127 tree void_ftype;
128 tree void_ftype_ptr;
129 tree int_ftype_int;
130 tree ptr_ftype_sizetype;
132 A VOID_TYPE node, packaged in a TREE_LIST.
134 tree void_list_node;
138 tree c_global_trees[CTI_MAX];
140 /* Nonzero means the expression being parsed will never be evaluated.
141 This is a count, since unevaluated expressions can nest. */
142 int skip_evaluation;
144 enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION,
145 A_NO_CHECK_MEMORY_USAGE, A_NO_INSTRUMENT_FUNCTION,
146 A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED,
147 A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS};
149 enum format_type { printf_format_type, scanf_format_type,
150 strftime_format_type };
152 static void declare_hidden_char_array PROTO((const char *, const char *));
153 static void add_attribute PROTO((enum attrs, const char *,
154 int, int, int));
155 static void init_attributes PROTO((void));
156 static void record_function_format PROTO((tree, tree, enum format_type,
157 int, int));
158 static void record_international_format PROTO((tree, tree, int));
159 static tree c_find_base_decl PROTO((tree));
160 static int default_valid_lang_attribute PROTO ((tree, tree, tree, tree));
162 /* Keep a stack of if statements. We record the number of compound
163 statements seen up to the if keyword, as well as the line number
164 and file of the if. If a potentially ambiguous else is seen, that
165 fact is recorded; the warning is issued when we can be sure that
166 the enclosing if statement does not have an else branch. */
167 typedef struct
169 int compstmt_count;
170 int line;
171 const char *file;
172 int needs_warning;
173 } if_elt;
174 static void tfaff PROTO((void));
176 static if_elt *if_stack;
178 /* Amount of space in the if statement stack. */
179 static int if_stack_space = 0;
181 /* Stack pointer. */
182 static int if_stack_pointer = 0;
184 /* Generate RTL for the start of an if-then, and record the start of it
185 for ambiguous else detection. */
187 void
188 c_expand_start_cond (cond, exitflag, compstmt_count)
189 tree cond;
190 int exitflag;
191 int compstmt_count;
193 /* Make sure there is enough space on the stack. */
194 if (if_stack_space == 0)
196 if_stack_space = 10;
197 if_stack = (if_elt *)xmalloc (10 * sizeof (if_elt));
199 else if (if_stack_space == if_stack_pointer)
201 if_stack_space += 10;
202 if_stack = (if_elt *)xrealloc (if_stack, if_stack_space * sizeof (if_elt));
205 /* Record this if statement. */
206 if_stack[if_stack_pointer].compstmt_count = compstmt_count;
207 if_stack[if_stack_pointer].file = input_filename;
208 if_stack[if_stack_pointer].line = lineno;
209 if_stack[if_stack_pointer].needs_warning = 0;
210 if_stack_pointer++;
212 expand_start_cond (cond, exitflag);
215 /* Generate RTL for the end of an if-then. Optionally warn if a nested
216 if statement had an ambiguous else clause. */
218 void
219 c_expand_end_cond ()
221 if_stack_pointer--;
222 if (if_stack[if_stack_pointer].needs_warning)
223 warning_with_file_and_line (if_stack[if_stack_pointer].file,
224 if_stack[if_stack_pointer].line,
225 "suggest explicit braces to avoid ambiguous `else'");
226 expand_end_cond ();
229 /* Generate RTL between the then-clause and the else-clause
230 of an if-then-else. */
232 void
233 c_expand_start_else ()
235 /* An ambiguous else warning must be generated for the enclosing if
236 statement, unless we see an else branch for that one, too. */
237 if (warn_parentheses
238 && if_stack_pointer > 1
239 && (if_stack[if_stack_pointer - 1].compstmt_count
240 == if_stack[if_stack_pointer - 2].compstmt_count))
241 if_stack[if_stack_pointer - 2].needs_warning = 1;
243 /* Even if a nested if statement had an else branch, it can't be
244 ambiguous if this one also has an else. So don't warn in that
245 case. Also don't warn for any if statements nested in this else. */
246 if_stack[if_stack_pointer - 1].needs_warning = 0;
247 if_stack[if_stack_pointer - 1].compstmt_count--;
249 expand_start_else ();
252 /* Make bindings for __FUNCTION__, __PRETTY_FUNCTION__, and __func__. */
254 void
255 declare_function_name ()
257 const char *name, *printable_name;
259 if (current_function_decl == NULL)
261 name = "";
262 printable_name = "top level";
264 else
266 /* Allow functions to be nameless (such as artificial ones). */
267 if (DECL_NAME (current_function_decl))
268 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
269 else
270 name = "";
271 printable_name = (*decl_printable_name) (current_function_decl, 2);
274 declare_hidden_char_array ("__FUNCTION__", name);
275 declare_hidden_char_array ("__PRETTY_FUNCTION__", printable_name);
276 /* The ISO C people "of course" couldn't use __FUNCTION__ in the
277 ISO C 9x standard; instead a new variable is invented. */
278 declare_hidden_char_array ("__func__", name);
281 static void
282 declare_hidden_char_array (name, value)
283 const char *name, *value;
285 tree decl, type, init;
286 int vlen;
288 /* If the default size of char arrays isn't big enough for the name,
289 or if we want to give warnings for large objects, make a bigger one. */
290 vlen = strlen (value) + 1;
291 type = char_array_type_node;
292 if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < vlen
293 || warn_larger_than)
294 type = build_array_type (char_type_node,
295 build_index_type (build_int_2 (vlen, 0)));
296 push_obstacks_nochange ();
297 decl = build_decl (VAR_DECL, get_identifier (name), type);
298 TREE_STATIC (decl) = 1;
299 TREE_READONLY (decl) = 1;
300 TREE_ASM_WRITTEN (decl) = 1;
301 DECL_SOURCE_LINE (decl) = 0;
302 DECL_ARTIFICIAL (decl) = 1;
303 DECL_IN_SYSTEM_HEADER (decl) = 1;
304 DECL_IGNORED_P (decl) = 1;
305 init = build_string (vlen, value);
306 TREE_TYPE (init) = type;
307 DECL_INITIAL (decl) = init;
308 finish_decl (pushdecl (decl), init, NULL_TREE);
311 /* Given a chain of STRING_CST nodes,
312 concatenate them into one STRING_CST
313 and give it a suitable array-of-chars data type. */
315 tree
316 combine_strings (strings)
317 tree strings;
319 register tree value, t;
320 register int length = 1;
321 int wide_length = 0;
322 int wide_flag = 0;
323 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
324 int nchars;
326 if (TREE_CHAIN (strings))
328 /* More than one in the chain, so concatenate. */
329 register char *p, *q;
331 /* Don't include the \0 at the end of each substring,
332 except for the last one.
333 Count wide strings and ordinary strings separately. */
334 for (t = strings; t; t = TREE_CHAIN (t))
336 if (TREE_TYPE (t) == wchar_array_type_node)
338 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
339 wide_flag = 1;
341 else
342 length += (TREE_STRING_LENGTH (t) - 1);
345 /* If anything is wide, the non-wides will be converted,
346 which makes them take more space. */
347 if (wide_flag)
348 length = length * wchar_bytes + wide_length;
350 p = savealloc (length);
352 /* Copy the individual strings into the new combined string.
353 If the combined string is wide, convert the chars to ints
354 for any individual strings that are not wide. */
356 q = p;
357 for (t = strings; t; t = TREE_CHAIN (t))
359 int len = (TREE_STRING_LENGTH (t)
360 - ((TREE_TYPE (t) == wchar_array_type_node)
361 ? wchar_bytes : 1));
362 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
364 memcpy (q, TREE_STRING_POINTER (t), len);
365 q += len;
367 else
369 int i;
370 for (i = 0; i < len; i++)
372 if (WCHAR_TYPE_SIZE == HOST_BITS_PER_SHORT)
373 ((short *) q)[i] = TREE_STRING_POINTER (t)[i];
374 else
375 ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
377 q += len * wchar_bytes;
380 if (wide_flag)
382 int i;
383 for (i = 0; i < wchar_bytes; i++)
384 *q++ = 0;
386 else
387 *q = 0;
389 value = make_node (STRING_CST);
390 TREE_STRING_POINTER (value) = p;
391 TREE_STRING_LENGTH (value) = length;
393 else
395 value = strings;
396 length = TREE_STRING_LENGTH (value);
397 if (TREE_TYPE (value) == wchar_array_type_node)
398 wide_flag = 1;
401 /* Compute the number of elements, for the array type. */
402 nchars = wide_flag ? length / wchar_bytes : length;
404 /* Create the array type for the string constant.
405 -Wwrite-strings says make the string constant an array of const char
406 so that copying it to a non-const pointer will get a warning.
407 For C++, this is the standard behavior. */
408 if (flag_const_strings
409 && (! flag_traditional && ! flag_writable_strings))
411 tree elements
412 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
413 1, 0);
414 TREE_TYPE (value)
415 = build_array_type (elements,
416 build_index_type (build_int_2 (nchars - 1, 0)));
418 else
419 TREE_TYPE (value)
420 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
421 build_index_type (build_int_2 (nchars - 1, 0)));
423 TREE_CONSTANT (value) = 1;
424 TREE_READONLY (value) = ! flag_writable_strings;
425 TREE_STATIC (value) = 1;
426 return value;
429 /* To speed up processing of attributes, we maintain an array of
430 IDENTIFIER_NODES and the corresponding attribute types. */
432 /* Array to hold attribute information. */
434 static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50];
436 static int attrtab_idx = 0;
438 /* Add an entry to the attribute table above. */
440 static void
441 add_attribute (id, string, min_len, max_len, decl_req)
442 enum attrs id;
443 const char *string;
444 int min_len, max_len;
445 int decl_req;
447 char buf[100];
449 attrtab[attrtab_idx].id = id;
450 attrtab[attrtab_idx].name = get_identifier (string);
451 attrtab[attrtab_idx].min = min_len;
452 attrtab[attrtab_idx].max = max_len;
453 attrtab[attrtab_idx++].decl_req = decl_req;
455 sprintf (buf, "__%s__", string);
457 attrtab[attrtab_idx].id = id;
458 attrtab[attrtab_idx].name = get_identifier (buf);
459 attrtab[attrtab_idx].min = min_len;
460 attrtab[attrtab_idx].max = max_len;
461 attrtab[attrtab_idx++].decl_req = decl_req;
464 /* Initialize attribute table. */
466 static void
467 init_attributes ()
469 add_attribute (A_PACKED, "packed", 0, 0, 0);
470 add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1);
471 add_attribute (A_COMMON, "common", 0, 0, 1);
472 add_attribute (A_NORETURN, "noreturn", 0, 0, 1);
473 add_attribute (A_NORETURN, "volatile", 0, 0, 1);
474 add_attribute (A_UNUSED, "unused", 0, 0, 0);
475 add_attribute (A_CONST, "const", 0, 0, 1);
476 add_attribute (A_T_UNION, "transparent_union", 0, 0, 0);
477 add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1);
478 add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1);
479 add_attribute (A_MODE, "mode", 1, 1, 1);
480 add_attribute (A_SECTION, "section", 1, 1, 1);
481 add_attribute (A_ALIGNED, "aligned", 0, 1, 0);
482 add_attribute (A_FORMAT, "format", 3, 3, 1);
483 add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1);
484 add_attribute (A_WEAK, "weak", 0, 0, 1);
485 add_attribute (A_ALIAS, "alias", 1, 1, 1);
486 add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1);
487 add_attribute (A_NO_CHECK_MEMORY_USAGE, "no_check_memory_usage", 0, 0, 1);
490 /* Default implementation of valid_lang_attribute, below. By default, there
491 are no language-specific attributes. */
493 static int
494 default_valid_lang_attribute (attr_name, attr_args, decl, type)
495 tree attr_name ATTRIBUTE_UNUSED;
496 tree attr_args ATTRIBUTE_UNUSED;
497 tree decl ATTRIBUTE_UNUSED;
498 tree type ATTRIBUTE_UNUSED;
500 return 0;
503 /* Return a 1 if ATTR_NAME and ATTR_ARGS denote a valid language-specific
504 attribute for either declaration DECL or type TYPE and 0 otherwise. */
506 int (*valid_lang_attribute) PROTO ((tree, tree, tree, tree))
507 = default_valid_lang_attribute;
509 /* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES
510 and install them in NODE, which is either a DECL (including a TYPE_DECL)
511 or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers
512 and declaration modifiers but before the declaration proper. */
514 void
515 decl_attributes (node, attributes, prefix_attributes)
516 tree node, attributes, prefix_attributes;
518 tree decl = 0, type = 0;
519 int is_type = 0;
520 tree a;
522 if (attrtab_idx == 0)
523 init_attributes ();
525 if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd')
527 decl = node;
528 type = TREE_TYPE (decl);
529 is_type = TREE_CODE (node) == TYPE_DECL;
531 else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't')
532 type = node, is_type = 1;
534 #ifdef PRAGMA_INSERT_ATTRIBUTES
535 /* If the code in c-pragma.c wants to insert some attributes then
536 allow it to do so. Do this before allowing machine back ends to
537 insert attributes, so that they have the opportunity to override
538 anything done here. */
539 PRAGMA_INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
540 #endif
542 #ifdef INSERT_ATTRIBUTES
543 INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
544 #endif
546 attributes = chainon (prefix_attributes, attributes);
548 for (a = attributes; a; a = TREE_CHAIN (a))
550 tree name = TREE_PURPOSE (a);
551 tree args = TREE_VALUE (a);
552 int i;
553 enum attrs id;
555 for (i = 0; i < attrtab_idx; i++)
556 if (attrtab[i].name == name)
557 break;
559 if (i == attrtab_idx)
561 if (! valid_machine_attribute (name, args, decl, type)
562 && ! (* valid_lang_attribute) (name, args, decl, type))
563 warning ("`%s' attribute directive ignored",
564 IDENTIFIER_POINTER (name));
565 else if (decl != 0)
566 type = TREE_TYPE (decl);
567 continue;
569 else if (attrtab[i].decl_req && decl == 0)
571 warning ("`%s' attribute does not apply to types",
572 IDENTIFIER_POINTER (name));
573 continue;
575 else if (list_length (args) < attrtab[i].min
576 || list_length (args) > attrtab[i].max)
578 error ("wrong number of arguments specified for `%s' attribute",
579 IDENTIFIER_POINTER (name));
580 continue;
583 id = attrtab[i].id;
584 switch (id)
586 case A_PACKED:
587 if (is_type)
588 TYPE_PACKED (type) = 1;
589 else if (TREE_CODE (decl) == FIELD_DECL)
590 DECL_PACKED (decl) = 1;
591 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
592 used for DECL_REGISTER. It wouldn't mean anything anyway. */
593 else
594 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
595 break;
597 case A_NOCOMMON:
598 if (TREE_CODE (decl) == VAR_DECL)
599 DECL_COMMON (decl) = 0;
600 else
601 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
602 break;
604 case A_COMMON:
605 if (TREE_CODE (decl) == VAR_DECL)
606 DECL_COMMON (decl) = 1;
607 else
608 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
609 break;
611 case A_NORETURN:
612 if (TREE_CODE (decl) == FUNCTION_DECL)
613 TREE_THIS_VOLATILE (decl) = 1;
614 else if (TREE_CODE (type) == POINTER_TYPE
615 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
616 TREE_TYPE (decl) = type
617 = build_pointer_type
618 (build_type_variant (TREE_TYPE (type),
619 TREE_READONLY (TREE_TYPE (type)), 1));
620 else
621 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
622 break;
624 case A_UNUSED:
625 if (is_type)
626 TREE_USED (type) = 1;
627 else if (TREE_CODE (decl) == PARM_DECL
628 || TREE_CODE (decl) == VAR_DECL
629 || TREE_CODE (decl) == FUNCTION_DECL
630 || TREE_CODE (decl) == LABEL_DECL)
631 TREE_USED (decl) = 1;
632 else
633 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
634 break;
636 case A_CONST:
637 if (TREE_CODE (decl) == FUNCTION_DECL)
638 TREE_READONLY (decl) = 1;
639 else if (TREE_CODE (type) == POINTER_TYPE
640 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
641 TREE_TYPE (decl) = type
642 = build_pointer_type
643 (build_type_variant (TREE_TYPE (type), 1,
644 TREE_THIS_VOLATILE (TREE_TYPE (type))));
645 else
646 warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name));
647 break;
649 case A_T_UNION:
650 if (is_type
651 && TREE_CODE (type) == UNION_TYPE
652 && (decl == 0
653 || (TYPE_FIELDS (type) != 0
654 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))))
655 TYPE_TRANSPARENT_UNION (type) = 1;
656 else if (decl != 0 && TREE_CODE (decl) == PARM_DECL
657 && TREE_CODE (type) == UNION_TYPE
658 && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))
659 DECL_TRANSPARENT_UNION (decl) = 1;
660 else
661 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
662 break;
664 case A_CONSTRUCTOR:
665 if (TREE_CODE (decl) == FUNCTION_DECL
666 && TREE_CODE (type) == FUNCTION_TYPE
667 && decl_function_context (decl) == 0)
669 DECL_STATIC_CONSTRUCTOR (decl) = 1;
670 TREE_USED (decl) = 1;
672 else
673 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
674 break;
676 case A_DESTRUCTOR:
677 if (TREE_CODE (decl) == FUNCTION_DECL
678 && TREE_CODE (type) == FUNCTION_TYPE
679 && decl_function_context (decl) == 0)
681 DECL_STATIC_DESTRUCTOR (decl) = 1;
682 TREE_USED (decl) = 1;
684 else
685 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
686 break;
688 case A_MODE:
689 if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE)
690 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
691 else
693 int j;
694 const char *p = IDENTIFIER_POINTER (TREE_VALUE (args));
695 int len = strlen (p);
696 enum machine_mode mode = VOIDmode;
697 tree typefm;
699 if (len > 4 && p[0] == '_' && p[1] == '_'
700 && p[len - 1] == '_' && p[len - 2] == '_')
702 char *newp = (char *) alloca (len - 1);
704 strcpy (newp, &p[2]);
705 newp[len - 4] = '\0';
706 p = newp;
709 /* Give this decl a type with the specified mode.
710 First check for the special modes. */
711 if (! strcmp (p, "byte"))
712 mode = byte_mode;
713 else if (!strcmp (p, "word"))
714 mode = word_mode;
715 else if (! strcmp (p, "pointer"))
716 mode = ptr_mode;
717 else
718 for (j = 0; j < NUM_MACHINE_MODES; j++)
719 if (!strcmp (p, GET_MODE_NAME (j)))
720 mode = (enum machine_mode) j;
722 if (mode == VOIDmode)
723 error ("unknown machine mode `%s'", p);
724 else if (0 == (typefm = type_for_mode (mode,
725 TREE_UNSIGNED (type))))
726 error ("no data type for mode `%s'", p);
727 else
729 TREE_TYPE (decl) = type = typefm;
730 DECL_SIZE (decl) = 0;
731 layout_decl (decl, 0);
734 break;
736 case A_SECTION:
737 #ifdef ASM_OUTPUT_SECTION_NAME
738 if ((TREE_CODE (decl) == FUNCTION_DECL
739 || TREE_CODE (decl) == VAR_DECL)
740 && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
742 if (TREE_CODE (decl) == VAR_DECL
743 && current_function_decl != NULL_TREE
744 && ! TREE_STATIC (decl))
745 error_with_decl (decl,
746 "section attribute cannot be specified for local variables");
747 /* The decl may have already been given a section attribute from
748 a previous declaration. Ensure they match. */
749 else if (DECL_SECTION_NAME (decl) != NULL_TREE
750 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
751 TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
752 error_with_decl (node,
753 "section of `%s' conflicts with previous declaration");
754 else
755 DECL_SECTION_NAME (decl) = TREE_VALUE (args);
757 else
758 error_with_decl (node,
759 "section attribute not allowed for `%s'");
760 #else
761 error_with_decl (node,
762 "section attributes are not supported for this target");
763 #endif
764 break;
766 case A_ALIGNED:
768 tree align_expr
769 = (args ? TREE_VALUE (args)
770 : size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
771 int align;
773 /* Strip any NOPs of any kind. */
774 while (TREE_CODE (align_expr) == NOP_EXPR
775 || TREE_CODE (align_expr) == CONVERT_EXPR
776 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
777 align_expr = TREE_OPERAND (align_expr, 0);
779 if (TREE_CODE (align_expr) != INTEGER_CST)
781 error ("requested alignment is not a constant");
782 continue;
785 align = TREE_INT_CST_LOW (align_expr) * BITS_PER_UNIT;
787 if (exact_log2 (align) == -1)
788 error ("requested alignment is not a power of 2");
789 else if (is_type)
790 TYPE_ALIGN (type) = align;
791 else if (TREE_CODE (decl) != VAR_DECL
792 && TREE_CODE (decl) != FIELD_DECL)
793 error_with_decl (decl,
794 "alignment may not be specified for `%s'");
795 else
796 DECL_ALIGN (decl) = align;
798 break;
800 case A_FORMAT:
802 tree format_type_id = TREE_VALUE (args);
803 tree format_num_expr = TREE_VALUE (TREE_CHAIN (args));
804 tree first_arg_num_expr
805 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)));
806 int format_num;
807 int first_arg_num;
808 enum format_type format_type;
809 tree argument;
810 int arg_num;
812 if (TREE_CODE (decl) != FUNCTION_DECL)
814 error_with_decl (decl,
815 "argument format specified for non-function `%s'");
816 continue;
819 if (TREE_CODE (format_type_id) != IDENTIFIER_NODE)
821 error ("unrecognized format specifier");
822 continue;
824 else
826 const char *p = IDENTIFIER_POINTER (format_type_id);
828 if (!strcmp (p, "printf") || !strcmp (p, "__printf__"))
829 format_type = printf_format_type;
830 else if (!strcmp (p, "scanf") || !strcmp (p, "__scanf__"))
831 format_type = scanf_format_type;
832 else if (!strcmp (p, "strftime")
833 || !strcmp (p, "__strftime__"))
834 format_type = strftime_format_type;
835 else
837 warning ("`%s' is an unrecognized format function type", p);
838 continue;
842 /* Strip any conversions from the string index and first arg number
843 and verify they are constants. */
844 while (TREE_CODE (format_num_expr) == NOP_EXPR
845 || TREE_CODE (format_num_expr) == CONVERT_EXPR
846 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
847 format_num_expr = TREE_OPERAND (format_num_expr, 0);
849 while (TREE_CODE (first_arg_num_expr) == NOP_EXPR
850 || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR
851 || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR)
852 first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0);
854 if (TREE_CODE (format_num_expr) != INTEGER_CST
855 || TREE_CODE (first_arg_num_expr) != INTEGER_CST)
857 error ("format string has non-constant operand number");
858 continue;
861 format_num = TREE_INT_CST_LOW (format_num_expr);
862 first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr);
863 if (first_arg_num != 0 && first_arg_num <= format_num)
865 error ("format string arg follows the args to be formatted");
866 continue;
869 /* If a parameter list is specified, verify that the format_num
870 argument is actually a string, in case the format attribute
871 is in error. */
872 argument = TYPE_ARG_TYPES (type);
873 if (argument)
875 for (arg_num = 1; ; ++arg_num)
877 if (argument == 0 || arg_num == format_num)
878 break;
879 argument = TREE_CHAIN (argument);
881 if (! argument
882 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
883 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
884 != char_type_node))
886 error ("format string arg not a string type");
887 continue;
889 if (first_arg_num != 0)
891 /* Verify that first_arg_num points to the last arg,
892 the ... */
893 while (argument)
894 arg_num++, argument = TREE_CHAIN (argument);
895 if (arg_num != first_arg_num)
897 error ("args to be formatted is not ...");
898 continue;
903 record_function_format (DECL_NAME (decl),
904 DECL_ASSEMBLER_NAME (decl),
905 format_type, format_num, first_arg_num);
906 break;
909 case A_FORMAT_ARG:
911 tree format_num_expr = TREE_VALUE (args);
912 int format_num, arg_num;
913 tree argument;
915 if (TREE_CODE (decl) != FUNCTION_DECL)
917 error_with_decl (decl,
918 "argument format specified for non-function `%s'");
919 continue;
922 /* Strip any conversions from the first arg number and verify it
923 is a constant. */
924 while (TREE_CODE (format_num_expr) == NOP_EXPR
925 || TREE_CODE (format_num_expr) == CONVERT_EXPR
926 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
927 format_num_expr = TREE_OPERAND (format_num_expr, 0);
929 if (TREE_CODE (format_num_expr) != INTEGER_CST)
931 error ("format string has non-constant operand number");
932 continue;
935 format_num = TREE_INT_CST_LOW (format_num_expr);
937 /* If a parameter list is specified, verify that the format_num
938 argument is actually a string, in case the format attribute
939 is in error. */
940 argument = TYPE_ARG_TYPES (type);
941 if (argument)
943 for (arg_num = 1; ; ++arg_num)
945 if (argument == 0 || arg_num == format_num)
946 break;
947 argument = TREE_CHAIN (argument);
949 if (! argument
950 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
951 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
952 != char_type_node))
954 error ("format string arg not a string type");
955 continue;
959 if (TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != POINTER_TYPE
960 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (TREE_TYPE (decl))))
961 != char_type_node))
963 error ("function does not return string type");
964 continue;
967 record_international_format (DECL_NAME (decl),
968 DECL_ASSEMBLER_NAME (decl),
969 format_num);
970 break;
973 case A_WEAK:
974 declare_weak (decl);
975 break;
977 case A_ALIAS:
978 if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl))
979 || (TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)))
980 error_with_decl (decl,
981 "`%s' defined both normally and as an alias");
982 else if (decl_function_context (decl) == 0)
984 tree id;
986 id = TREE_VALUE (args);
987 if (TREE_CODE (id) != STRING_CST)
989 error ("alias arg not a string");
990 break;
992 id = get_identifier (TREE_STRING_POINTER (id));
994 if (TREE_CODE (decl) == FUNCTION_DECL)
995 DECL_INITIAL (decl) = error_mark_node;
996 else
997 DECL_EXTERNAL (decl) = 0;
998 assemble_alias (decl, id);
1000 else
1001 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
1002 break;
1004 case A_NO_CHECK_MEMORY_USAGE:
1005 if (TREE_CODE (decl) != FUNCTION_DECL)
1007 error_with_decl (decl,
1008 "`%s' attribute applies only to functions",
1009 IDENTIFIER_POINTER (name));
1011 else if (DECL_INITIAL (decl))
1013 error_with_decl (decl,
1014 "can't set `%s' attribute after definition",
1015 IDENTIFIER_POINTER (name));
1017 else
1018 DECL_NO_CHECK_MEMORY_USAGE (decl) = 1;
1019 break;
1021 case A_NO_INSTRUMENT_FUNCTION:
1022 if (TREE_CODE (decl) != FUNCTION_DECL)
1024 error_with_decl (decl,
1025 "`%s' attribute applies only to functions",
1026 IDENTIFIER_POINTER (name));
1028 else if (DECL_INITIAL (decl))
1030 error_with_decl (decl,
1031 "can't set `%s' attribute after definition",
1032 IDENTIFIER_POINTER (name));
1034 else
1035 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
1036 break;
1041 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
1042 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
1044 The head of the declspec list is stored in DECLSPECS.
1045 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
1047 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
1048 the list elements. We drop the containing TREE_LIST nodes and link the
1049 resulting attributes together the way decl_attributes expects them. */
1051 void
1052 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
1053 tree specs_attrs;
1054 tree *declspecs, *prefix_attributes;
1056 tree t, s, a, next, specs, attrs;
1058 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
1059 if (specs_attrs != NULL_TREE
1060 && TREE_CODE (specs_attrs) != TREE_LIST)
1062 *declspecs = specs_attrs;
1063 *prefix_attributes = NULL_TREE;
1064 return;
1067 /* Remember to keep the lists in the same order, element-wise. */
1069 specs = s = NULL_TREE;
1070 attrs = a = NULL_TREE;
1071 for (t = specs_attrs; t; t = next)
1073 next = TREE_CHAIN (t);
1074 /* Declspecs have a non-NULL TREE_VALUE. */
1075 if (TREE_VALUE (t) != NULL_TREE)
1077 if (specs == NULL_TREE)
1078 specs = s = t;
1079 else
1081 TREE_CHAIN (s) = t;
1082 s = t;
1085 else
1087 if (attrs == NULL_TREE)
1088 attrs = a = TREE_PURPOSE (t);
1089 else
1091 TREE_CHAIN (a) = TREE_PURPOSE (t);
1092 a = TREE_PURPOSE (t);
1094 /* More attrs can be linked here, move A to the end. */
1095 while (TREE_CHAIN (a) != NULL_TREE)
1096 a = TREE_CHAIN (a);
1100 /* Terminate the lists. */
1101 if (s != NULL_TREE)
1102 TREE_CHAIN (s) = NULL_TREE;
1103 if (a != NULL_TREE)
1104 TREE_CHAIN (a) = NULL_TREE;
1106 /* All done. */
1107 *declspecs = specs;
1108 *prefix_attributes = attrs;
1111 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
1112 This function is used by the parser when a rule will accept attributes
1113 in a particular position, but we don't want to support that just yet.
1115 A warning is issued for every ignored attribute. */
1117 tree
1118 strip_attrs (specs_attrs)
1119 tree specs_attrs;
1121 tree specs, attrs;
1123 split_specs_attrs (specs_attrs, &specs, &attrs);
1125 while (attrs)
1127 warning ("`%s' attribute ignored",
1128 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
1129 attrs = TREE_CHAIN (attrs);
1132 return specs;
1135 /* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
1136 a parameter list. */
1138 #define T_I &integer_type_node
1139 #define T_L &long_integer_type_node
1140 #define T_LL &long_long_integer_type_node
1141 #define T_S &short_integer_type_node
1142 #define T_UI &unsigned_type_node
1143 #define T_UL &long_unsigned_type_node
1144 #define T_ULL &long_long_unsigned_type_node
1145 #define T_US &short_unsigned_type_node
1146 #define T_F &float_type_node
1147 #define T_D &double_type_node
1148 #define T_LD &long_double_type_node
1149 #define T_C &char_type_node
1150 #define T_UC &unsigned_char_type_node
1151 #define T_V &void_type_node
1152 #define T_W &wchar_type_node
1153 #define T_ST &sizetype
1155 typedef struct {
1156 const char *format_chars;
1157 int pointer_count;
1158 /* Type of argument if no length modifier is used. */
1159 tree *nolen;
1160 /* Type of argument if length modifier for shortening to byte is used.
1161 If NULL, then this modifier is not allowed. */
1162 tree *hhlen;
1163 /* Type of argument if length modifier for shortening is used.
1164 If NULL, then this modifier is not allowed. */
1165 tree *hlen;
1166 /* Type of argument if length modifier `l' is used.
1167 If NULL, then this modifier is not allowed. */
1168 tree *llen;
1169 /* Type of argument if length modifier `q' or `ll' is used.
1170 If NULL, then this modifier is not allowed. */
1171 tree *qlen;
1172 /* Type of argument if length modifier `L' is used.
1173 If NULL, then this modifier is not allowed. */
1174 tree *bigllen;
1175 /* Type of argument if length modifier `Z' is used.
1176 If NULL, then this modifier is not allowed. */
1177 tree *zlen;
1178 /* List of other modifier characters allowed with these options. */
1179 const char *flag_chars;
1180 } format_char_info;
1182 static format_char_info print_char_table[] = {
1183 { "di", 0, T_I, T_I, T_I, T_L, T_LL, T_LL, T_ST, "-wp0 +" },
1184 { "oxX", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, "-wp0#" },
1185 { "u", 0, T_UI, T_UI, T_UI, T_UL, T_ULL, T_ULL, T_ST, "-wp0" },
1186 /* A GNU extension. */
1187 { "m", 0, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
1188 { "feEgGaA", 0, T_D, NULL, NULL, NULL, NULL, T_LD, NULL, "-wp0 +#" },
1189 { "c", 0, T_I, NULL, NULL, T_W, NULL, NULL, NULL, "-w" },
1190 { "C", 0, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
1191 { "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "-wp" },
1192 { "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "-wp" },
1193 { "p", 1, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "-w" },
1194 { "n", 1, T_I, NULL, T_S, T_L, T_LL, NULL, NULL, "" },
1195 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1198 static format_char_info scan_char_table[] = {
1199 { "di", 1, T_I, T_C, T_S, T_L, T_LL, T_LL, NULL, "*" },
1200 { "ouxX", 1, T_UI, T_UC, T_US, T_UL, T_ULL, T_ULL, NULL, "*" },
1201 { "efgEGaA", 1, T_F, NULL, NULL, T_D, NULL, T_LD, NULL, "*" },
1202 { "c", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "*" },
1203 { "s", 1, T_C, NULL, NULL, T_W, NULL, NULL, NULL, "*a" },
1204 { "[", 1, T_C, NULL, NULL, NULL, NULL, NULL, NULL, "*a" },
1205 { "C", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "*" },
1206 { "S", 1, T_W, NULL, NULL, NULL, NULL, NULL, NULL, "*a" },
1207 { "p", 2, T_V, NULL, NULL, NULL, NULL, NULL, NULL, "*" },
1208 { "n", 1, T_I, T_C, T_S, T_L, T_LL, NULL, NULL, "" },
1209 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1212 /* Handle format characters recognized by glibc's strftime.c.
1213 '2' - MUST do years as only two digits
1214 '3' - MAY do years as only two digits (depending on locale)
1215 'E' - E modifier is acceptable
1216 'O' - O modifier is acceptable to Standard C
1217 'o' - O modifier is acceptable as a GNU extension
1218 'G' - other GNU extensions */
1220 static format_char_info time_char_table[] = {
1221 { "y", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2EO-_0w" },
1222 { "D", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2" },
1223 { "g", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "2O-_0w" },
1224 { "cx", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "3E" },
1225 { "%RTXnrt", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "" },
1226 { "P", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "G" },
1227 { "HIMSUWdemw", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Ow" },
1228 { "Vju", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow" },
1229 { "Gklsz", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0OGw" },
1230 { "ABZa", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^#" },
1231 { "p", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "#" },
1232 { "bh", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^" },
1233 { "CY", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0EOw" },
1234 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1237 typedef struct function_format_info
1239 struct function_format_info *next; /* next structure on the list */
1240 tree name; /* identifier such as "printf" */
1241 tree assembler_name; /* optional mangled identifier (for C++) */
1242 enum format_type format_type; /* type of format (printf, scanf, etc.) */
1243 int format_num; /* number of format argument */
1244 int first_arg_num; /* number of first arg (zero for varargs) */
1245 } function_format_info;
1247 static function_format_info *function_format_list = NULL;
1249 typedef struct international_format_info
1251 struct international_format_info *next; /* next structure on the list */
1252 tree name; /* identifier such as "gettext" */
1253 tree assembler_name; /* optional mangled identifier (for C++) */
1254 int format_num; /* number of format argument */
1255 } international_format_info;
1257 static international_format_info *international_format_list = NULL;
1259 static void check_format_info PROTO((function_format_info *, tree));
1261 /* Initialize the table of functions to perform format checking on.
1262 The ANSI functions are always checked (whether <stdio.h> is
1263 included or not), since it is common to call printf without
1264 including <stdio.h>. There shouldn't be a problem with this,
1265 since ANSI reserves these function names whether you include the
1266 header file or not. In any case, the checking is harmless.
1268 Also initialize the name of function that modify the format string for
1269 internationalization purposes. */
1271 void
1272 init_function_format_info ()
1274 record_function_format (get_identifier ("printf"), NULL_TREE,
1275 printf_format_type, 1, 2);
1276 record_function_format (get_identifier ("fprintf"), NULL_TREE,
1277 printf_format_type, 2, 3);
1278 record_function_format (get_identifier ("sprintf"), NULL_TREE,
1279 printf_format_type, 2, 3);
1280 record_function_format (get_identifier ("scanf"), NULL_TREE,
1281 scanf_format_type, 1, 2);
1282 record_function_format (get_identifier ("fscanf"), NULL_TREE,
1283 scanf_format_type, 2, 3);
1284 record_function_format (get_identifier ("sscanf"), NULL_TREE,
1285 scanf_format_type, 2, 3);
1286 record_function_format (get_identifier ("vprintf"), NULL_TREE,
1287 printf_format_type, 1, 0);
1288 record_function_format (get_identifier ("vfprintf"), NULL_TREE,
1289 printf_format_type, 2, 0);
1290 record_function_format (get_identifier ("vsprintf"), NULL_TREE,
1291 printf_format_type, 2, 0);
1292 record_function_format (get_identifier ("strftime"), NULL_TREE,
1293 strftime_format_type, 3, 0);
1295 record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
1296 record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
1297 record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
1300 /* Record information for argument format checking. FUNCTION_IDENT is
1301 the identifier node for the name of the function to check (its decl
1302 need not exist yet).
1303 FORMAT_TYPE specifies the type of format checking. FORMAT_NUM is the number
1304 of the argument which is the format control string (starting from 1).
1305 FIRST_ARG_NUM is the number of the first actual argument to check
1306 against the format string, or zero if no checking is not be done
1307 (e.g. for varargs such as vfprintf). */
1309 static void
1310 record_function_format (name, assembler_name, format_type,
1311 format_num, first_arg_num)
1312 tree name;
1313 tree assembler_name;
1314 enum format_type format_type;
1315 int format_num;
1316 int first_arg_num;
1318 function_format_info *info;
1320 /* Re-use existing structure if it's there. */
1322 for (info = function_format_list; info; info = info->next)
1324 if (info->name == name && info->assembler_name == assembler_name)
1325 break;
1327 if (! info)
1329 info = (function_format_info *) xmalloc (sizeof (function_format_info));
1330 info->next = function_format_list;
1331 function_format_list = info;
1333 info->name = name;
1334 info->assembler_name = assembler_name;
1337 info->format_type = format_type;
1338 info->format_num = format_num;
1339 info->first_arg_num = first_arg_num;
1342 /* Record information for the names of function that modify the format
1343 argument to format functions. FUNCTION_IDENT is the identifier node for
1344 the name of the function (its decl need not exist yet) and FORMAT_NUM is
1345 the number of the argument which is the format control string (starting
1346 from 1). */
1348 static void
1349 record_international_format (name, assembler_name, format_num)
1350 tree name;
1351 tree assembler_name;
1352 int format_num;
1354 international_format_info *info;
1356 /* Re-use existing structure if it's there. */
1358 for (info = international_format_list; info; info = info->next)
1360 if (info->name == name && info->assembler_name == assembler_name)
1361 break;
1364 if (! info)
1366 info
1367 = (international_format_info *)
1368 xmalloc (sizeof (international_format_info));
1369 info->next = international_format_list;
1370 international_format_list = info;
1372 info->name = name;
1373 info->assembler_name = assembler_name;
1376 info->format_num = format_num;
1379 static void
1380 tfaff ()
1382 warning ("too few arguments for format");
1385 /* Check the argument list of a call to printf, scanf, etc.
1386 NAME is the function identifier.
1387 ASSEMBLER_NAME is the function's assembler identifier.
1388 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
1389 PARAMS is the list of argument values. */
1391 void
1392 check_function_format (name, assembler_name, params)
1393 tree name;
1394 tree assembler_name;
1395 tree params;
1397 function_format_info *info;
1399 /* See if this function is a format function. */
1400 for (info = function_format_list; info; info = info->next)
1402 if (info->assembler_name
1403 ? (info->assembler_name == assembler_name)
1404 : (info->name == name))
1406 /* Yup; check it. */
1407 check_format_info (info, params);
1408 break;
1413 /* Check the argument list of a call to printf, scanf, etc.
1414 INFO points to the function_format_info structure.
1415 PARAMS is the list of argument values. */
1417 static void
1418 check_format_info (info, params)
1419 function_format_info *info;
1420 tree params;
1422 int i;
1423 int arg_num;
1424 int suppressed, wide, precise;
1425 int length_char = 0;
1426 int format_char;
1427 int format_length;
1428 tree format_tree;
1429 tree cur_param;
1430 tree cur_type;
1431 tree wanted_type;
1432 tree first_fillin_param;
1433 const char *format_chars;
1434 format_char_info *fci = NULL;
1435 char flag_chars[8];
1436 int has_operand_number = 0;
1438 /* Skip to format argument. If the argument isn't available, there's
1439 no work for us to do; prototype checking will catch the problem. */
1440 for (arg_num = 1; ; ++arg_num)
1442 if (params == 0)
1443 return;
1444 if (arg_num == info->format_num)
1445 break;
1446 params = TREE_CHAIN (params);
1448 format_tree = TREE_VALUE (params);
1449 params = TREE_CHAIN (params);
1450 if (format_tree == 0)
1451 return;
1453 /* We can only check the format if it's a string constant. */
1454 while (TREE_CODE (format_tree) == NOP_EXPR)
1455 format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
1457 if (TREE_CODE (format_tree) == CALL_EXPR
1458 && TREE_CODE (TREE_OPERAND (format_tree, 0)) == ADDR_EXPR
1459 && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0))
1460 == FUNCTION_DECL))
1462 tree function = TREE_OPERAND (TREE_OPERAND (format_tree, 0), 0);
1464 /* See if this is a call to a known internationalization function
1465 that modifies the format arg. */
1466 international_format_info *info;
1468 for (info = international_format_list; info; info = info->next)
1469 if (info->assembler_name
1470 ? (info->assembler_name == DECL_ASSEMBLER_NAME (function))
1471 : (info->name == DECL_NAME (function)))
1473 tree inner_args;
1474 int i;
1476 for (inner_args = TREE_OPERAND (format_tree, 1), i = 1;
1477 inner_args != 0;
1478 inner_args = TREE_CHAIN (inner_args), i++)
1479 if (i == info->format_num)
1481 format_tree = TREE_VALUE (inner_args);
1483 while (TREE_CODE (format_tree) == NOP_EXPR)
1484 format_tree = TREE_OPERAND (format_tree, 0);
1489 if (integer_zerop (format_tree))
1491 warning ("null format string");
1492 return;
1494 if (TREE_CODE (format_tree) != ADDR_EXPR)
1495 return;
1496 format_tree = TREE_OPERAND (format_tree, 0);
1497 if (TREE_CODE (format_tree) != STRING_CST)
1498 return;
1499 format_chars = TREE_STRING_POINTER (format_tree);
1500 format_length = TREE_STRING_LENGTH (format_tree);
1501 if (format_length <= 1)
1502 warning ("zero-length format string");
1503 if (format_chars[--format_length] != 0)
1505 warning ("unterminated format string");
1506 return;
1508 /* Skip to first argument to check. */
1509 while (arg_num + 1 < info->first_arg_num)
1511 if (params == 0)
1512 return;
1513 params = TREE_CHAIN (params);
1514 ++arg_num;
1517 first_fillin_param = params;
1518 while (1)
1520 int aflag;
1521 if (*format_chars == 0)
1523 if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
1524 warning ("embedded `\\0' in format");
1525 if (info->first_arg_num != 0 && params != 0 && ! has_operand_number)
1526 warning ("too many arguments for format");
1527 return;
1529 if (*format_chars++ != '%')
1530 continue;
1531 if (*format_chars == 0)
1533 warning ("spurious trailing `%%' in format");
1534 continue;
1536 if (*format_chars == '%')
1538 ++format_chars;
1539 continue;
1541 flag_chars[0] = 0;
1542 suppressed = wide = precise = FALSE;
1543 if (info->format_type == scanf_format_type)
1545 suppressed = *format_chars == '*';
1546 if (suppressed)
1547 ++format_chars;
1548 while (ISDIGIT (*format_chars))
1549 ++format_chars;
1551 else if (info->format_type == strftime_format_type)
1553 while (*format_chars != 0 && index ("_-0^#", *format_chars) != 0)
1555 if (pedantic)
1556 warning ("ANSI C does not support the strftime `%c' flag",
1557 *format_chars);
1558 if (index (flag_chars, *format_chars) != 0)
1560 warning ("repeated `%c' flag in format",
1561 *format_chars);
1562 ++format_chars;
1564 else
1566 i = strlen (flag_chars);
1567 flag_chars[i++] = *format_chars++;
1568 flag_chars[i] = 0;
1571 while (ISDIGIT ((unsigned char) *format_chars))
1573 wide = TRUE;
1574 ++format_chars;
1576 if (wide && pedantic)
1577 warning ("ANSI C does not support strftime format width");
1578 if (*format_chars == 'E' || *format_chars == 'O')
1580 i = strlen (flag_chars);
1581 flag_chars[i++] = *format_chars++;
1582 flag_chars[i] = 0;
1583 if (*format_chars == 'E' || *format_chars == 'O')
1585 warning ("multiple E/O modifiers in format");
1586 while (*format_chars == 'E' || *format_chars == 'O')
1587 ++format_chars;
1591 else if (info->format_type == printf_format_type)
1593 /* See if we have a number followed by a dollar sign. If we do,
1594 it is an operand number, so set PARAMS to that operand. */
1595 if (*format_chars >= '0' && *format_chars <= '9')
1597 const char *p = format_chars;
1599 while (*p >= '0' && *p++ <= '9')
1602 if (*p == '$')
1604 int opnum = atoi (format_chars);
1606 params = first_fillin_param;
1607 format_chars = p + 1;
1608 has_operand_number = 1;
1610 for (i = 1; i < opnum && params != 0; i++)
1611 params = TREE_CHAIN (params);
1613 if (opnum == 0 || params == 0)
1615 warning ("operand number out of range in format");
1616 return;
1621 while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
1623 if (index (flag_chars, *format_chars) != 0)
1624 warning ("repeated `%c' flag in format", *format_chars++);
1625 else
1627 i = strlen (flag_chars);
1628 flag_chars[i++] = *format_chars++;
1629 flag_chars[i] = 0;
1632 /* "If the space and + flags both appear,
1633 the space flag will be ignored." */
1634 if (index (flag_chars, ' ') != 0
1635 && index (flag_chars, '+') != 0)
1636 warning ("use of both ` ' and `+' flags in format");
1637 /* "If the 0 and - flags both appear,
1638 the 0 flag will be ignored." */
1639 if (index (flag_chars, '0') != 0
1640 && index (flag_chars, '-') != 0)
1641 warning ("use of both `0' and `-' flags in format");
1642 if (*format_chars == '*')
1644 wide = TRUE;
1645 /* "...a field width...may be indicated by an asterisk.
1646 In this case, an int argument supplies the field width..." */
1647 ++format_chars;
1648 if (params == 0)
1650 tfaff ();
1651 return;
1653 if (info->first_arg_num != 0)
1655 cur_param = TREE_VALUE (params);
1656 params = TREE_CHAIN (params);
1657 ++arg_num;
1658 /* size_t is generally not valid here.
1659 It will work on most machines, because size_t and int
1660 have the same mode. But might as well warn anyway,
1661 since it will fail on other machines. */
1662 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1663 != integer_type_node)
1665 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1666 != unsigned_type_node))
1667 warning ("field width is not type int (arg %d)", arg_num);
1670 else
1672 while (ISDIGIT (*format_chars))
1674 wide = TRUE;
1675 ++format_chars;
1678 if (*format_chars == '.')
1680 precise = TRUE;
1681 ++format_chars;
1682 if (*format_chars != '*' && !ISDIGIT (*format_chars))
1683 warning ("`.' not followed by `*' or digit in format");
1684 /* "...a...precision...may be indicated by an asterisk.
1685 In this case, an int argument supplies the...precision." */
1686 if (*format_chars == '*')
1688 if (info->first_arg_num != 0)
1690 ++format_chars;
1691 if (params == 0)
1693 tfaff ();
1694 return;
1696 cur_param = TREE_VALUE (params);
1697 params = TREE_CHAIN (params);
1698 ++arg_num;
1699 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
1700 != integer_type_node)
1701 warning ("field width is not type int (arg %d)",
1702 arg_num);
1705 else
1707 while (ISDIGIT (*format_chars))
1708 ++format_chars;
1713 aflag = 0;
1715 if (info->format_type != strftime_format_type)
1717 if (*format_chars == 'h' || *format_chars == 'l')
1718 length_char = *format_chars++;
1719 else if (*format_chars == 'q' || *format_chars == 'L')
1721 length_char = *format_chars++;
1722 if (pedantic)
1723 warning ("ANSI C does not support the `%c' length modifier",
1724 length_char);
1726 else if (*format_chars == 'Z')
1728 length_char = *format_chars++;
1729 if (pedantic)
1730 warning ("ANSI C does not support the `Z' length modifier");
1732 else
1733 length_char = 0;
1734 if (length_char == 'l' && *format_chars == 'l')
1736 length_char = 'q', format_chars++;
1737 /* FIXME: Is allowed in ISO C 9x. */
1738 if (pedantic)
1739 warning ("ANSI C does not support the `ll' length modifier");
1741 else if (length_char == 'h' && *format_chars == 'h')
1743 length_char = 'H', format_chars++;
1744 /* FIXME: Is allowed in ISO C 9x. */
1745 if (pedantic)
1746 warning ("ANSI C does not support the `hh' length modifier");
1748 if (*format_chars == 'a' && info->format_type == scanf_format_type)
1750 if (format_chars[1] == 's' || format_chars[1] == 'S'
1751 || format_chars[1] == '[')
1753 /* `a' is used as a flag. */
1754 aflag = 1;
1755 format_chars++;
1758 if (suppressed && length_char != 0)
1759 warning ("use of `*' and `%c' together in format", length_char);
1761 format_char = *format_chars;
1762 if (format_char == 0
1763 || (info->format_type != strftime_format_type && format_char == '%'))
1765 warning ("conversion lacks type at end of format");
1766 continue;
1768 /* The m, C, and S formats are GNU extensions. */
1769 if (pedantic && info->format_type != strftime_format_type
1770 && (format_char == 'm' || format_char == 'C' || format_char == 'S'))
1771 warning ("ANSI C does not support the `%c' format", format_char);
1772 /* ??? The a and A formats are C9X extensions, and should be allowed
1773 when a C9X option is added. */
1774 if (pedantic && info->format_type != strftime_format_type
1775 && (format_char == 'a' || format_char == 'A'))
1776 warning ("ANSI C does not support the `%c' format", format_char);
1777 format_chars++;
1778 switch (info->format_type)
1780 case printf_format_type:
1781 fci = print_char_table;
1782 break;
1783 case scanf_format_type:
1784 fci = scan_char_table;
1785 break;
1786 case strftime_format_type:
1787 fci = time_char_table;
1788 break;
1789 default:
1790 abort ();
1792 while (fci->format_chars != 0
1793 && index (fci->format_chars, format_char) == 0)
1794 ++fci;
1795 if (fci->format_chars == 0)
1797 if (format_char >= 040 && format_char < 0177)
1798 warning ("unknown conversion type character `%c' in format",
1799 format_char);
1800 else
1801 warning ("unknown conversion type character 0x%x in format",
1802 format_char);
1803 continue;
1805 if (pedantic)
1807 if (index (fci->flag_chars, 'G') != 0)
1808 warning ("ANSI C does not support `%%%c'", format_char);
1809 if (index (fci->flag_chars, 'o') != 0
1810 && index (flag_chars, 'O') != 0)
1811 warning ("ANSI C does not support `%%O%c'", format_char);
1813 if (wide && index (fci->flag_chars, 'w') == 0)
1814 warning ("width used with `%c' format", format_char);
1815 if (index (fci->flag_chars, '2') != 0)
1816 warning ("`%%%c' yields only last 2 digits of year", format_char);
1817 else if (index (fci->flag_chars, '3') != 0)
1818 warning ("`%%%c' yields only last 2 digits of year in some locales",
1819 format_char);
1820 if (precise && index (fci->flag_chars, 'p') == 0)
1821 warning ("precision used with `%c' format", format_char);
1822 if (aflag && index (fci->flag_chars, 'a') == 0)
1824 warning ("`a' flag used with `%c' format", format_char);
1825 /* To simplify the following code. */
1826 aflag = 0;
1828 /* The a flag is a GNU extension. */
1829 else if (pedantic && aflag)
1830 warning ("ANSI C does not support the `a' flag");
1831 if (info->format_type == scanf_format_type && format_char == '[')
1833 /* Skip over scan set, in case it happens to have '%' in it. */
1834 if (*format_chars == '^')
1835 ++format_chars;
1836 /* Find closing bracket; if one is hit immediately, then
1837 it's part of the scan set rather than a terminator. */
1838 if (*format_chars == ']')
1839 ++format_chars;
1840 while (*format_chars && *format_chars != ']')
1841 ++format_chars;
1842 if (*format_chars != ']')
1843 /* The end of the format string was reached. */
1844 warning ("no closing `]' for `%%[' format");
1846 if (suppressed)
1848 if (index (fci->flag_chars, '*') == 0)
1849 warning ("suppression of `%c' conversion in format", format_char);
1850 continue;
1852 for (i = 0; flag_chars[i] != 0; ++i)
1854 if (index (fci->flag_chars, flag_chars[i]) == 0)
1855 warning ("flag `%c' used with type `%c'",
1856 flag_chars[i], format_char);
1858 if (info->format_type == strftime_format_type)
1859 continue;
1860 if (precise && index (flag_chars, '0') != 0
1861 && (format_char == 'd' || format_char == 'i'
1862 || format_char == 'o' || format_char == 'u'
1863 || format_char == 'x' || format_char == 'X'))
1864 warning ("`0' flag ignored with precision specifier and `%c' format",
1865 format_char);
1866 switch (length_char)
1868 default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
1869 case 'H': wanted_type = fci->hhlen ? *(fci->hhlen) : 0; break;
1870 case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
1871 case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
1872 case 'q': wanted_type = fci->qlen ? *(fci->qlen) : 0; break;
1873 case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
1874 case 'Z': wanted_type = fci->zlen ? *fci->zlen : 0; break;
1876 if (wanted_type == 0)
1877 warning ("use of `%c' length character with `%c' type character",
1878 length_char, format_char);
1880 /* Finally. . .check type of argument against desired type! */
1881 if (info->first_arg_num == 0)
1882 continue;
1883 if (fci->pointer_count == 0 && wanted_type == void_type_node)
1884 /* This specifier takes no argument. */
1885 continue;
1886 if (params == 0)
1888 tfaff ();
1889 return;
1891 cur_param = TREE_VALUE (params);
1892 params = TREE_CHAIN (params);
1893 ++arg_num;
1894 cur_type = TREE_TYPE (cur_param);
1896 STRIP_NOPS (cur_param);
1898 /* Check the types of any additional pointer arguments
1899 that precede the "real" argument. */
1900 for (i = 0; i < fci->pointer_count + aflag; ++i)
1902 if (TREE_CODE (cur_type) == POINTER_TYPE)
1904 cur_type = TREE_TYPE (cur_type);
1906 if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
1907 cur_param = TREE_OPERAND (cur_param, 0);
1908 else
1909 cur_param = 0;
1911 continue;
1913 if (TREE_CODE (cur_type) != ERROR_MARK)
1914 warning ((fci->pointer_count + aflag == 1
1915 ? "format argument is not a pointer (arg %d)"
1916 : "format argument is not a pointer to a pointer (arg %d)"),
1917 arg_num);
1918 break;
1921 /* See if this is an attempt to write into a const type with
1922 scanf or with printf "%n". */
1923 if ((info->format_type == scanf_format_type
1924 || (info->format_type == printf_format_type
1925 && format_char == 'n'))
1926 && i == fci->pointer_count + aflag
1927 && wanted_type != 0
1928 && TREE_CODE (cur_type) != ERROR_MARK
1929 && (TYPE_READONLY (cur_type)
1930 || (cur_param != 0
1931 && (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
1932 || (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'd'
1933 && TREE_READONLY (cur_param))))))
1934 warning ("writing into constant object (arg %d)", arg_num);
1936 /* Check the type of the "real" argument, if there's a type we want. */
1937 if (i == fci->pointer_count + aflag && wanted_type != 0
1938 && TREE_CODE (cur_type) != ERROR_MARK
1939 && wanted_type != TYPE_MAIN_VARIANT (cur_type)
1940 /* If we want `void *', allow any pointer type.
1941 (Anything else would already have got a warning.) */
1942 && ! (wanted_type == void_type_node
1943 && fci->pointer_count > 0)
1944 /* Don't warn about differences merely in signedness. */
1945 && !(TREE_CODE (wanted_type) == INTEGER_TYPE
1946 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type)) == INTEGER_TYPE
1947 && (TREE_UNSIGNED (wanted_type)
1948 ? wanted_type == (cur_type = unsigned_type (cur_type))
1949 : wanted_type == (cur_type = signed_type (cur_type))))
1950 /* Likewise, "signed char", "unsigned char" and "char" are
1951 equivalent but the above test won't consider them equivalent. */
1952 && ! (wanted_type == char_type_node
1953 && (TYPE_MAIN_VARIANT (cur_type) == signed_char_type_node
1954 || TYPE_MAIN_VARIANT (cur_type) == unsigned_char_type_node)))
1956 register const char *this;
1957 register const char *that;
1959 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
1960 that = 0;
1961 if (TREE_CODE (cur_type) != ERROR_MARK
1962 && TYPE_NAME (cur_type) != 0
1963 && TREE_CODE (cur_type) != INTEGER_TYPE
1964 && !(TREE_CODE (cur_type) == POINTER_TYPE
1965 && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE))
1967 if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL
1968 && DECL_NAME (TYPE_NAME (cur_type)) != 0)
1969 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1970 else
1971 that = IDENTIFIER_POINTER (TYPE_NAME (cur_type));
1974 /* A nameless type can't possibly match what the format wants.
1975 So there will be a warning for it.
1976 Make up a string to describe vaguely what it is. */
1977 if (that == 0)
1979 if (TREE_CODE (cur_type) == POINTER_TYPE)
1980 that = "pointer";
1981 else
1982 that = "different type";
1985 /* Make the warning better in case of mismatch of int vs long. */
1986 if (TREE_CODE (cur_type) == INTEGER_TYPE
1987 && TREE_CODE (wanted_type) == INTEGER_TYPE
1988 && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type)
1989 && TYPE_NAME (cur_type) != 0
1990 && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL)
1991 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1993 if (strcmp (this, that) != 0)
1994 warning ("%s format, %s arg (arg %d)", this, that, arg_num);
1999 /* Print a warning if a constant expression had overflow in folding.
2000 Invoke this function on every expression that the language
2001 requires to be a constant expression.
2002 Note the ANSI C standard says it is erroneous for a
2003 constant expression to overflow. */
2005 void
2006 constant_expression_warning (value)
2007 tree value;
2009 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
2010 || TREE_CODE (value) == COMPLEX_CST)
2011 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
2012 pedwarn ("overflow in constant expression");
2015 /* Print a warning if an expression had overflow in folding.
2016 Invoke this function on every expression that
2017 (1) appears in the source code, and
2018 (2) might be a constant expression that overflowed, and
2019 (3) is not already checked by convert_and_check;
2020 however, do not invoke this function on operands of explicit casts. */
2022 void
2023 overflow_warning (value)
2024 tree value;
2026 if ((TREE_CODE (value) == INTEGER_CST
2027 || (TREE_CODE (value) == COMPLEX_CST
2028 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
2029 && TREE_OVERFLOW (value))
2031 TREE_OVERFLOW (value) = 0;
2032 if (skip_evaluation == 0)
2033 warning ("integer overflow in expression");
2035 else if ((TREE_CODE (value) == REAL_CST
2036 || (TREE_CODE (value) == COMPLEX_CST
2037 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
2038 && TREE_OVERFLOW (value))
2040 TREE_OVERFLOW (value) = 0;
2041 if (skip_evaluation == 0)
2042 warning ("floating point overflow in expression");
2046 /* Print a warning if a large constant is truncated to unsigned,
2047 or if -Wconversion is used and a constant < 0 is converted to unsigned.
2048 Invoke this function on every expression that might be implicitly
2049 converted to an unsigned type. */
2051 void
2052 unsigned_conversion_warning (result, operand)
2053 tree result, operand;
2055 if (TREE_CODE (operand) == INTEGER_CST
2056 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
2057 && TREE_UNSIGNED (TREE_TYPE (result))
2058 && skip_evaluation == 0
2059 && !int_fits_type_p (operand, TREE_TYPE (result)))
2061 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
2062 /* This detects cases like converting -129 or 256 to unsigned char. */
2063 warning ("large integer implicitly truncated to unsigned type");
2064 else if (warn_conversion)
2065 warning ("negative integer implicitly converted to unsigned type");
2069 /* Convert EXPR to TYPE, warning about conversion problems with constants.
2070 Invoke this function on every expression that is converted implicitly,
2071 i.e. because of language rules and not because of an explicit cast. */
2073 tree
2074 convert_and_check (type, expr)
2075 tree type, expr;
2077 tree t = convert (type, expr);
2078 if (TREE_CODE (t) == INTEGER_CST)
2080 if (TREE_OVERFLOW (t))
2082 TREE_OVERFLOW (t) = 0;
2084 /* Do not diagnose overflow in a constant expression merely
2085 because a conversion overflowed. */
2086 TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr);
2088 /* No warning for converting 0x80000000 to int. */
2089 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
2090 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
2091 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
2092 /* If EXPR fits in the unsigned version of TYPE,
2093 don't warn unless pedantic. */
2094 if ((pedantic
2095 || TREE_UNSIGNED (type)
2096 || ! int_fits_type_p (expr, unsigned_type (type)))
2097 && skip_evaluation == 0)
2098 warning ("overflow in implicit constant conversion");
2100 else
2101 unsigned_conversion_warning (t, expr);
2103 return t;
2106 void
2107 c_expand_expr_stmt (expr)
2108 tree expr;
2110 /* Do default conversion if safe and possibly important,
2111 in case within ({...}). */
2112 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
2113 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
2114 expr = default_conversion (expr);
2116 if (TREE_TYPE (expr) != error_mark_node
2117 && TYPE_SIZE (TREE_TYPE (expr)) == 0
2118 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
2119 error ("expression statement has incomplete type");
2121 expand_expr_stmt (expr);
2124 /* Validate the expression after `case' and apply default promotions. */
2126 tree
2127 check_case_value (value)
2128 tree value;
2130 if (value == NULL_TREE)
2131 return value;
2133 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
2134 STRIP_TYPE_NOPS (value);
2136 if (TREE_CODE (value) != INTEGER_CST
2137 && value != error_mark_node)
2139 error ("case label does not reduce to an integer constant");
2140 value = error_mark_node;
2142 else
2143 /* Promote char or short to int. */
2144 value = default_conversion (value);
2146 constant_expression_warning (value);
2148 return value;
2151 /* Return an integer type with BITS bits of precision,
2152 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
2154 tree
2155 type_for_size (bits, unsignedp)
2156 unsigned bits;
2157 int unsignedp;
2159 if (bits == TYPE_PRECISION (integer_type_node))
2160 return unsignedp ? unsigned_type_node : integer_type_node;
2162 if (bits == TYPE_PRECISION (signed_char_type_node))
2163 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2165 if (bits == TYPE_PRECISION (short_integer_type_node))
2166 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2168 if (bits == TYPE_PRECISION (long_integer_type_node))
2169 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2171 if (bits == TYPE_PRECISION (long_long_integer_type_node))
2172 return (unsignedp ? long_long_unsigned_type_node
2173 : long_long_integer_type_node);
2175 if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
2176 return (unsignedp ? widest_unsigned_literal_type_node
2177 : widest_integer_literal_type_node);
2179 if (bits <= TYPE_PRECISION (intQI_type_node))
2180 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2182 if (bits <= TYPE_PRECISION (intHI_type_node))
2183 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2185 if (bits <= TYPE_PRECISION (intSI_type_node))
2186 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2188 if (bits <= TYPE_PRECISION (intDI_type_node))
2189 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2191 return 0;
2194 /* Return a data type that has machine mode MODE.
2195 If the mode is an integer,
2196 then UNSIGNEDP selects between signed and unsigned types. */
2198 tree
2199 type_for_mode (mode, unsignedp)
2200 enum machine_mode mode;
2201 int unsignedp;
2203 if (mode == TYPE_MODE (integer_type_node))
2204 return unsignedp ? unsigned_type_node : integer_type_node;
2206 if (mode == TYPE_MODE (signed_char_type_node))
2207 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2209 if (mode == TYPE_MODE (short_integer_type_node))
2210 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2212 if (mode == TYPE_MODE (long_integer_type_node))
2213 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2215 if (mode == TYPE_MODE (long_long_integer_type_node))
2216 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
2218 if (mode == TYPE_MODE (widest_integer_literal_type_node))
2219 return unsignedp ? widest_unsigned_literal_type_node
2220 : widest_integer_literal_type_node;
2222 if (mode == TYPE_MODE (intQI_type_node))
2223 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
2225 if (mode == TYPE_MODE (intHI_type_node))
2226 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
2228 if (mode == TYPE_MODE (intSI_type_node))
2229 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
2231 if (mode == TYPE_MODE (intDI_type_node))
2232 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
2234 #if HOST_BITS_PER_WIDE_INT >= 64
2235 if (mode == TYPE_MODE (intTI_type_node))
2236 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
2237 #endif
2239 if (mode == TYPE_MODE (float_type_node))
2240 return float_type_node;
2242 if (mode == TYPE_MODE (double_type_node))
2243 return double_type_node;
2245 if (mode == TYPE_MODE (long_double_type_node))
2246 return long_double_type_node;
2248 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
2249 return build_pointer_type (char_type_node);
2251 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
2252 return build_pointer_type (integer_type_node);
2254 return 0;
2257 /* Return an unsigned type the same as TYPE in other respects. */
2258 tree
2259 unsigned_type (type)
2260 tree type;
2262 tree type1 = TYPE_MAIN_VARIANT (type);
2263 if (type1 == signed_char_type_node || type1 == char_type_node)
2264 return unsigned_char_type_node;
2265 if (type1 == integer_type_node)
2266 return unsigned_type_node;
2267 if (type1 == short_integer_type_node)
2268 return short_unsigned_type_node;
2269 if (type1 == long_integer_type_node)
2270 return long_unsigned_type_node;
2271 if (type1 == long_long_integer_type_node)
2272 return long_long_unsigned_type_node;
2273 if (type1 == widest_integer_literal_type_node)
2274 return widest_unsigned_literal_type_node;
2275 #if HOST_BITS_PER_WIDE_INT >= 64
2276 if (type1 == intTI_type_node)
2277 return unsigned_intTI_type_node;
2278 #endif
2279 if (type1 == intDI_type_node)
2280 return unsigned_intDI_type_node;
2281 if (type1 == intSI_type_node)
2282 return unsigned_intSI_type_node;
2283 if (type1 == intHI_type_node)
2284 return unsigned_intHI_type_node;
2285 if (type1 == intQI_type_node)
2286 return unsigned_intQI_type_node;
2288 return signed_or_unsigned_type (1, type);
2291 /* Return a signed type the same as TYPE in other respects. */
2293 tree
2294 signed_type (type)
2295 tree type;
2297 tree type1 = TYPE_MAIN_VARIANT (type);
2298 if (type1 == unsigned_char_type_node || type1 == char_type_node)
2299 return signed_char_type_node;
2300 if (type1 == unsigned_type_node)
2301 return integer_type_node;
2302 if (type1 == short_unsigned_type_node)
2303 return short_integer_type_node;
2304 if (type1 == long_unsigned_type_node)
2305 return long_integer_type_node;
2306 if (type1 == long_long_unsigned_type_node)
2307 return long_long_integer_type_node;
2308 if (type1 == widest_unsigned_literal_type_node)
2309 return widest_integer_literal_type_node;
2310 #if HOST_BITS_PER_WIDE_INT >= 64
2311 if (type1 == unsigned_intTI_type_node)
2312 return intTI_type_node;
2313 #endif
2314 if (type1 == unsigned_intDI_type_node)
2315 return intDI_type_node;
2316 if (type1 == unsigned_intSI_type_node)
2317 return intSI_type_node;
2318 if (type1 == unsigned_intHI_type_node)
2319 return intHI_type_node;
2320 if (type1 == unsigned_intQI_type_node)
2321 return intQI_type_node;
2323 return signed_or_unsigned_type (0, type);
2326 /* Return a type the same as TYPE except unsigned or
2327 signed according to UNSIGNEDP. */
2329 tree
2330 signed_or_unsigned_type (unsignedp, type)
2331 int unsignedp;
2332 tree type;
2334 if (! INTEGRAL_TYPE_P (type)
2335 || TREE_UNSIGNED (type) == unsignedp)
2336 return type;
2338 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
2339 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
2340 if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
2341 return unsignedp ? unsigned_type_node : integer_type_node;
2342 if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
2343 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
2344 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
2345 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
2346 if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
2347 return (unsignedp ? long_long_unsigned_type_node
2348 : long_long_integer_type_node);
2349 if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
2350 return (unsignedp ? widest_unsigned_literal_type_node
2351 : widest_integer_literal_type_node);
2352 return type;
2355 /* Return the minimum number of bits needed to represent VALUE in a
2356 signed or unsigned type, UNSIGNEDP says which. */
2359 min_precision (value, unsignedp)
2360 tree value;
2361 int unsignedp;
2363 int log;
2365 /* If the value is negative, compute its negative minus 1. The latter
2366 adjustment is because the absolute value of the largest negative value
2367 is one larger than the largest positive value. This is equivalent to
2368 a bit-wise negation, so use that operation instead. */
2370 if (tree_int_cst_sgn (value) < 0)
2371 value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value));
2373 /* Return the number of bits needed, taking into account the fact
2374 that we need one more bit for a signed than unsigned type. */
2376 if (integer_zerop (value))
2377 log = 0;
2378 else if (TREE_INT_CST_HIGH (value) != 0)
2379 log = HOST_BITS_PER_WIDE_INT + floor_log2 (TREE_INT_CST_HIGH (value));
2380 else
2381 log = floor_log2 (TREE_INT_CST_LOW (value));
2383 return log + 1 + ! unsignedp;
2386 /* Print an error message for invalid operands to arith operation CODE.
2387 NOP_EXPR is used as a special case (see truthvalue_conversion). */
2389 void
2390 binary_op_error (code)
2391 enum tree_code code;
2393 register const char *opname;
2395 switch (code)
2397 case NOP_EXPR:
2398 error ("invalid truth-value expression");
2399 return;
2401 case PLUS_EXPR:
2402 opname = "+"; break;
2403 case MINUS_EXPR:
2404 opname = "-"; break;
2405 case MULT_EXPR:
2406 opname = "*"; break;
2407 case MAX_EXPR:
2408 opname = "max"; break;
2409 case MIN_EXPR:
2410 opname = "min"; break;
2411 case EQ_EXPR:
2412 opname = "=="; break;
2413 case NE_EXPR:
2414 opname = "!="; break;
2415 case LE_EXPR:
2416 opname = "<="; break;
2417 case GE_EXPR:
2418 opname = ">="; break;
2419 case LT_EXPR:
2420 opname = "<"; break;
2421 case GT_EXPR:
2422 opname = ">"; break;
2423 case LSHIFT_EXPR:
2424 opname = "<<"; break;
2425 case RSHIFT_EXPR:
2426 opname = ">>"; break;
2427 case TRUNC_MOD_EXPR:
2428 case FLOOR_MOD_EXPR:
2429 opname = "%"; break;
2430 case TRUNC_DIV_EXPR:
2431 case FLOOR_DIV_EXPR:
2432 opname = "/"; break;
2433 case BIT_AND_EXPR:
2434 opname = "&"; break;
2435 case BIT_IOR_EXPR:
2436 opname = "|"; break;
2437 case TRUTH_ANDIF_EXPR:
2438 opname = "&&"; break;
2439 case TRUTH_ORIF_EXPR:
2440 opname = "||"; break;
2441 case BIT_XOR_EXPR:
2442 opname = "^"; break;
2443 case LROTATE_EXPR:
2444 case RROTATE_EXPR:
2445 opname = "rotate"; break;
2446 default:
2447 opname = "unknown"; break;
2449 error ("invalid operands to binary %s", opname);
2452 /* Subroutine of build_binary_op, used for comparison operations.
2453 See if the operands have both been converted from subword integer types
2454 and, if so, perhaps change them both back to their original type.
2455 This function is also responsible for converting the two operands
2456 to the proper common type for comparison.
2458 The arguments of this function are all pointers to local variables
2459 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
2460 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
2462 If this function returns nonzero, it means that the comparison has
2463 a constant value. What this function returns is an expression for
2464 that value. */
2466 tree
2467 shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
2468 tree *op0_ptr, *op1_ptr;
2469 tree *restype_ptr;
2470 enum tree_code *rescode_ptr;
2472 register tree type;
2473 tree op0 = *op0_ptr;
2474 tree op1 = *op1_ptr;
2475 int unsignedp0, unsignedp1;
2476 int real1, real2;
2477 tree primop0, primop1;
2478 enum tree_code code = *rescode_ptr;
2480 /* Throw away any conversions to wider types
2481 already present in the operands. */
2483 primop0 = get_narrower (op0, &unsignedp0);
2484 primop1 = get_narrower (op1, &unsignedp1);
2486 /* Handle the case that OP0 does not *contain* a conversion
2487 but it *requires* conversion to FINAL_TYPE. */
2489 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
2490 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
2491 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
2492 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
2494 /* If one of the operands must be floated, we cannot optimize. */
2495 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
2496 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
2498 /* If first arg is constant, swap the args (changing operation
2499 so value is preserved), for canonicalization. Don't do this if
2500 the second arg is 0. */
2502 if (TREE_CONSTANT (primop0)
2503 && ! integer_zerop (primop1) && ! real_zerop (primop1))
2505 register tree tem = primop0;
2506 register int temi = unsignedp0;
2507 primop0 = primop1;
2508 primop1 = tem;
2509 tem = op0;
2510 op0 = op1;
2511 op1 = tem;
2512 *op0_ptr = op0;
2513 *op1_ptr = op1;
2514 unsignedp0 = unsignedp1;
2515 unsignedp1 = temi;
2516 temi = real1;
2517 real1 = real2;
2518 real2 = temi;
2520 switch (code)
2522 case LT_EXPR:
2523 code = GT_EXPR;
2524 break;
2525 case GT_EXPR:
2526 code = LT_EXPR;
2527 break;
2528 case LE_EXPR:
2529 code = GE_EXPR;
2530 break;
2531 case GE_EXPR:
2532 code = LE_EXPR;
2533 break;
2534 default:
2535 break;
2537 *rescode_ptr = code;
2540 /* If comparing an integer against a constant more bits wide,
2541 maybe we can deduce a value of 1 or 0 independent of the data.
2542 Or else truncate the constant now
2543 rather than extend the variable at run time.
2545 This is only interesting if the constant is the wider arg.
2546 Also, it is not safe if the constant is unsigned and the
2547 variable arg is signed, since in this case the variable
2548 would be sign-extended and then regarded as unsigned.
2549 Our technique fails in this case because the lowest/highest
2550 possible unsigned results don't follow naturally from the
2551 lowest/highest possible values of the variable operand.
2552 For just EQ_EXPR and NE_EXPR there is another technique that
2553 could be used: see if the constant can be faithfully represented
2554 in the other operand's type, by truncating it and reextending it
2555 and see if that preserves the constant's value. */
2557 if (!real1 && !real2
2558 && TREE_CODE (primop1) == INTEGER_CST
2559 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
2561 int min_gt, max_gt, min_lt, max_lt;
2562 tree maxval, minval;
2563 /* 1 if comparison is nominally unsigned. */
2564 int unsignedp = TREE_UNSIGNED (*restype_ptr);
2565 tree val;
2567 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
2569 /* If TYPE is an enumeration, then we need to get its min/max
2570 values from it's underlying integral type, not the enumerated
2571 type itself. */
2572 if (TREE_CODE (type) == ENUMERAL_TYPE)
2573 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
2575 maxval = TYPE_MAX_VALUE (type);
2576 minval = TYPE_MIN_VALUE (type);
2578 if (unsignedp && !unsignedp0)
2579 *restype_ptr = signed_type (*restype_ptr);
2581 if (TREE_TYPE (primop1) != *restype_ptr)
2582 primop1 = convert (*restype_ptr, primop1);
2583 if (type != *restype_ptr)
2585 minval = convert (*restype_ptr, minval);
2586 maxval = convert (*restype_ptr, maxval);
2589 if (unsignedp && unsignedp0)
2591 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
2592 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
2593 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
2594 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
2596 else
2598 min_gt = INT_CST_LT (primop1, minval);
2599 max_gt = INT_CST_LT (primop1, maxval);
2600 min_lt = INT_CST_LT (minval, primop1);
2601 max_lt = INT_CST_LT (maxval, primop1);
2604 val = 0;
2605 /* This used to be a switch, but Genix compiler can't handle that. */
2606 if (code == NE_EXPR)
2608 if (max_lt || min_gt)
2609 val = boolean_true_node;
2611 else if (code == EQ_EXPR)
2613 if (max_lt || min_gt)
2614 val = boolean_false_node;
2616 else if (code == LT_EXPR)
2618 if (max_lt)
2619 val = boolean_true_node;
2620 if (!min_lt)
2621 val = boolean_false_node;
2623 else if (code == GT_EXPR)
2625 if (min_gt)
2626 val = boolean_true_node;
2627 if (!max_gt)
2628 val = boolean_false_node;
2630 else if (code == LE_EXPR)
2632 if (!max_gt)
2633 val = boolean_true_node;
2634 if (min_gt)
2635 val = boolean_false_node;
2637 else if (code == GE_EXPR)
2639 if (!min_lt)
2640 val = boolean_true_node;
2641 if (max_lt)
2642 val = boolean_false_node;
2645 /* If primop0 was sign-extended and unsigned comparison specd,
2646 we did a signed comparison above using the signed type bounds.
2647 But the comparison we output must be unsigned.
2649 Also, for inequalities, VAL is no good; but if the signed
2650 comparison had *any* fixed result, it follows that the
2651 unsigned comparison just tests the sign in reverse
2652 (positive values are LE, negative ones GE).
2653 So we can generate an unsigned comparison
2654 against an extreme value of the signed type. */
2656 if (unsignedp && !unsignedp0)
2658 if (val != 0)
2659 switch (code)
2661 case LT_EXPR:
2662 case GE_EXPR:
2663 primop1 = TYPE_MIN_VALUE (type);
2664 val = 0;
2665 break;
2667 case LE_EXPR:
2668 case GT_EXPR:
2669 primop1 = TYPE_MAX_VALUE (type);
2670 val = 0;
2671 break;
2673 default:
2674 break;
2676 type = unsigned_type (type);
2679 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2681 /* This is the case of (char)x >?< 0x80, which people used to use
2682 expecting old C compilers to change the 0x80 into -0x80. */
2683 if (val == boolean_false_node)
2684 warning ("comparison is always false due to limited range of data type");
2685 if (val == boolean_true_node)
2686 warning ("comparison is always true due to limited range of data type");
2689 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
2691 /* This is the case of (unsigned char)x >?< -1 or < 0. */
2692 if (val == boolean_false_node)
2693 warning ("comparison is always false due to limited range of data type");
2694 if (val == boolean_true_node)
2695 warning ("comparison is always true due to limited range of data type");
2698 if (val != 0)
2700 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2701 if (TREE_SIDE_EFFECTS (primop0))
2702 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
2703 return val;
2706 /* Value is not predetermined, but do the comparison
2707 in the type of the operand that is not constant.
2708 TYPE is already properly set. */
2710 else if (real1 && real2
2711 && (TYPE_PRECISION (TREE_TYPE (primop0))
2712 == TYPE_PRECISION (TREE_TYPE (primop1))))
2713 type = TREE_TYPE (primop0);
2715 /* If args' natural types are both narrower than nominal type
2716 and both extend in the same manner, compare them
2717 in the type of the wider arg.
2718 Otherwise must actually extend both to the nominal
2719 common type lest different ways of extending
2720 alter the result.
2721 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
2723 else if (unsignedp0 == unsignedp1 && real1 == real2
2724 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
2725 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
2727 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
2728 type = signed_or_unsigned_type (unsignedp0
2729 || TREE_UNSIGNED (*restype_ptr),
2730 type);
2731 /* Make sure shorter operand is extended the right way
2732 to match the longer operand. */
2733 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
2734 primop0);
2735 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
2736 primop1);
2738 else
2740 /* Here we must do the comparison on the nominal type
2741 using the args exactly as we received them. */
2742 type = *restype_ptr;
2743 primop0 = op0;
2744 primop1 = op1;
2746 if (!real1 && !real2 && integer_zerop (primop1)
2747 && TREE_UNSIGNED (*restype_ptr))
2749 tree value = 0;
2750 switch (code)
2752 case GE_EXPR:
2753 /* All unsigned values are >= 0, so we warn if extra warnings
2754 are requested. However, if OP0 is a constant that is
2755 >= 0, the signedness of the comparison isn't an issue,
2756 so suppress the warning. */
2757 if (extra_warnings
2758 && ! (TREE_CODE (primop0) == INTEGER_CST
2759 && ! TREE_OVERFLOW (convert (signed_type (type),
2760 primop0))))
2761 warning ("comparison of unsigned expression >= 0 is always true");
2762 value = boolean_true_node;
2763 break;
2765 case LT_EXPR:
2766 if (extra_warnings
2767 && ! (TREE_CODE (primop0) == INTEGER_CST
2768 && ! TREE_OVERFLOW (convert (signed_type (type),
2769 primop0))))
2770 warning ("comparison of unsigned expression < 0 is always false");
2771 value = boolean_false_node;
2772 break;
2774 default:
2775 break;
2778 if (value != 0)
2780 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
2781 if (TREE_SIDE_EFFECTS (primop0))
2782 return build (COMPOUND_EXPR, TREE_TYPE (value),
2783 primop0, value);
2784 return value;
2789 *op0_ptr = convert (type, primop0);
2790 *op1_ptr = convert (type, primop1);
2792 *restype_ptr = boolean_type_node;
2794 return 0;
2797 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
2798 or validate its data type for an `if' or `while' statement or ?..: exp.
2800 This preparation consists of taking the ordinary
2801 representation of an expression expr and producing a valid tree
2802 boolean expression describing whether expr is nonzero. We could
2803 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2804 but we optimize comparisons, &&, ||, and !.
2806 The resulting type should always be `boolean_type_node'. */
2808 tree
2809 truthvalue_conversion (expr)
2810 tree expr;
2812 if (TREE_CODE (expr) == ERROR_MARK)
2813 return expr;
2815 #if 0 /* This appears to be wrong for C++. */
2816 /* These really should return error_mark_node after 2.4 is stable.
2817 But not all callers handle ERROR_MARK properly. */
2818 switch (TREE_CODE (TREE_TYPE (expr)))
2820 case RECORD_TYPE:
2821 error ("struct type value used where scalar is required");
2822 return boolean_false_node;
2824 case UNION_TYPE:
2825 error ("union type value used where scalar is required");
2826 return boolean_false_node;
2828 case ARRAY_TYPE:
2829 error ("array type value used where scalar is required");
2830 return boolean_false_node;
2832 default:
2833 break;
2835 #endif /* 0 */
2837 switch (TREE_CODE (expr))
2839 /* It is simpler and generates better code to have only TRUTH_*_EXPR
2840 or comparison expressions as truth values at this level. */
2841 #if 0
2842 case COMPONENT_REF:
2843 /* A one-bit unsigned bit-field is already acceptable. */
2844 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
2845 && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
2846 return expr;
2847 break;
2848 #endif
2850 case EQ_EXPR:
2851 /* It is simpler and generates better code to have only TRUTH_*_EXPR
2852 or comparison expressions as truth values at this level. */
2853 #if 0
2854 if (integer_zerop (TREE_OPERAND (expr, 1)))
2855 return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0);
2856 #endif
2857 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
2858 case TRUTH_ANDIF_EXPR:
2859 case TRUTH_ORIF_EXPR:
2860 case TRUTH_AND_EXPR:
2861 case TRUTH_OR_EXPR:
2862 case TRUTH_XOR_EXPR:
2863 case TRUTH_NOT_EXPR:
2864 TREE_TYPE (expr) = boolean_type_node;
2865 return expr;
2867 case ERROR_MARK:
2868 return expr;
2870 case INTEGER_CST:
2871 return integer_zerop (expr) ? boolean_false_node : boolean_true_node;
2873 case REAL_CST:
2874 return real_zerop (expr) ? boolean_false_node : boolean_true_node;
2876 case ADDR_EXPR:
2877 /* If we are taking the address of a external decl, it might be zero
2878 if it is weak, so we cannot optimize. */
2879 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (expr, 0))) == 'd'
2880 && DECL_EXTERNAL (TREE_OPERAND (expr, 0)))
2881 break;
2883 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
2884 return build (COMPOUND_EXPR, boolean_type_node,
2885 TREE_OPERAND (expr, 0), boolean_true_node);
2886 else
2887 return boolean_true_node;
2889 case COMPLEX_EXPR:
2890 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2891 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2892 truthvalue_conversion (TREE_OPERAND (expr, 0)),
2893 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2896 case NEGATE_EXPR:
2897 case ABS_EXPR:
2898 case FLOAT_EXPR:
2899 case FFS_EXPR:
2900 /* These don't change whether an object is non-zero or zero. */
2901 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2903 case LROTATE_EXPR:
2904 case RROTATE_EXPR:
2905 /* These don't change whether an object is zero or non-zero, but
2906 we can't ignore them if their second arg has side-effects. */
2907 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2908 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2909 truthvalue_conversion (TREE_OPERAND (expr, 0)));
2910 else
2911 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2913 case COND_EXPR:
2914 /* Distribute the conversion into the arms of a COND_EXPR. */
2915 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2916 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2917 truthvalue_conversion (TREE_OPERAND (expr, 2))));
2919 case CONVERT_EXPR:
2920 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2921 since that affects how `default_conversion' will behave. */
2922 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2923 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2924 break;
2925 /* fall through... */
2926 case NOP_EXPR:
2927 /* If this is widening the argument, we can ignore it. */
2928 if (TYPE_PRECISION (TREE_TYPE (expr))
2929 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2930 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2931 break;
2933 case MINUS_EXPR:
2934 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2935 this case. */
2936 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2937 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2938 break;
2939 /* fall through... */
2940 case BIT_XOR_EXPR:
2941 /* This and MINUS_EXPR can be changed into a comparison of the
2942 two objects. */
2943 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2944 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2945 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2946 TREE_OPERAND (expr, 1), 1);
2947 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
2948 fold (build1 (NOP_EXPR,
2949 TREE_TYPE (TREE_OPERAND (expr, 0)),
2950 TREE_OPERAND (expr, 1))), 1);
2952 case BIT_AND_EXPR:
2953 if (integer_onep (TREE_OPERAND (expr, 1))
2954 && TREE_TYPE (expr) != boolean_type_node)
2955 /* Using convert here would cause infinite recursion. */
2956 return build1 (NOP_EXPR, boolean_type_node, expr);
2957 break;
2959 case MODIFY_EXPR:
2960 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
2961 warning ("suggest parentheses around assignment used as truth value");
2962 break;
2964 default:
2965 break;
2968 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2970 tree tem = save_expr (expr);
2971 return (build_binary_op
2972 ((TREE_SIDE_EFFECTS (expr)
2973 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2974 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
2975 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
2976 0));
2979 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
2982 #if USE_CPPLIB
2983 /* Read the rest of a #-directive from input stream FINPUT.
2984 In normal use, the directive name and the white space after it
2985 have already been read, so they won't be included in the result.
2986 We allow for the fact that the directive line may contain
2987 a newline embedded within a character or string literal which forms
2988 a part of the directive.
2990 The value is a string in a reusable buffer. It remains valid
2991 only until the next time this function is called. */
2992 unsigned char *yy_cur, *yy_lim;
2994 #define GETC() (yy_cur < yy_lim ? *yy_cur++ : yy_get_token ())
2995 #define UNGETC(c) ((c) == EOF ? 0 : yy_cur--)
2998 yy_get_token ()
3000 for (;;)
3002 parse_in.limit = parse_in.token_buffer;
3003 cpp_token = cpp_get_token (&parse_in);
3004 if (cpp_token == CPP_EOF)
3005 return -1;
3006 yy_lim = CPP_PWRITTEN (&parse_in);
3007 yy_cur = parse_in.token_buffer;
3008 if (yy_cur < yy_lim)
3009 return *yy_cur++;
3013 char *
3014 get_directive_line ()
3016 static char *directive_buffer = NULL;
3017 static unsigned buffer_length = 0;
3018 register char *p;
3019 register char *buffer_limit;
3020 register int looking_for = 0;
3021 register int char_escaped = 0;
3023 if (buffer_length == 0)
3025 directive_buffer = (char *)xmalloc (128);
3026 buffer_length = 128;
3029 buffer_limit = &directive_buffer[buffer_length];
3031 for (p = directive_buffer; ; )
3033 int c;
3035 /* Make buffer bigger if it is full. */
3036 if (p >= buffer_limit)
3038 register unsigned bytes_used = (p - directive_buffer);
3040 buffer_length *= 2;
3041 directive_buffer
3042 = (char *)xrealloc (directive_buffer, buffer_length);
3043 p = &directive_buffer[bytes_used];
3044 buffer_limit = &directive_buffer[buffer_length];
3047 c = GETC ();
3049 /* Discard initial whitespace. */
3050 if ((c == ' ' || c == '\t') && p == directive_buffer)
3051 continue;
3053 /* Detect the end of the directive. */
3054 if (c == '\n' && looking_for == 0)
3056 UNGETC (c);
3057 c = '\0';
3060 *p++ = c;
3062 if (c == 0)
3063 return directive_buffer;
3065 /* Handle string and character constant syntax. */
3066 if (looking_for)
3068 if (looking_for == c && !char_escaped)
3069 looking_for = 0; /* Found terminator... stop looking. */
3071 else
3072 if (c == '\'' || c == '"')
3073 looking_for = c; /* Don't stop buffering until we see another
3074 another one of these (or an EOF). */
3076 /* Handle backslash. */
3077 char_escaped = (c == '\\' && ! char_escaped);
3080 #else
3081 /* Read the rest of a #-directive from input stream FINPUT.
3082 In normal use, the directive name and the white space after it
3083 have already been read, so they won't be included in the result.
3084 We allow for the fact that the directive line may contain
3085 a newline embedded within a character or string literal which forms
3086 a part of the directive.
3088 The value is a string in a reusable buffer. It remains valid
3089 only until the next time this function is called.
3091 The terminating character ('\n' or EOF) is left in FINPUT for the
3092 caller to re-read. */
3094 char *
3095 get_directive_line (finput)
3096 register FILE *finput;
3098 static char *directive_buffer = NULL;
3099 static unsigned buffer_length = 0;
3100 register char *p;
3101 register char *buffer_limit;
3102 register int looking_for = 0;
3103 register int char_escaped = 0;
3105 if (buffer_length == 0)
3107 directive_buffer = (char *)xmalloc (128);
3108 buffer_length = 128;
3111 buffer_limit = &directive_buffer[buffer_length];
3113 for (p = directive_buffer; ; )
3115 int c;
3117 /* Make buffer bigger if it is full. */
3118 if (p >= buffer_limit)
3120 register unsigned bytes_used = (p - directive_buffer);
3122 buffer_length *= 2;
3123 directive_buffer
3124 = (char *)xrealloc (directive_buffer, buffer_length);
3125 p = &directive_buffer[bytes_used];
3126 buffer_limit = &directive_buffer[buffer_length];
3129 c = getc (finput);
3131 /* Discard initial whitespace. */
3132 if ((c == ' ' || c == '\t') && p == directive_buffer)
3133 continue;
3135 /* Detect the end of the directive. */
3136 if (looking_for == 0
3137 && (c == '\n' || c == EOF))
3139 ungetc (c, finput);
3140 c = '\0';
3143 *p++ = c;
3145 if (c == 0)
3146 return directive_buffer;
3148 /* Handle string and character constant syntax. */
3149 if (looking_for)
3151 if (looking_for == c && !char_escaped)
3152 looking_for = 0; /* Found terminator... stop looking. */
3154 else
3155 if (c == '\'' || c == '"')
3156 looking_for = c; /* Don't stop buffering until we see another
3157 one of these (or an EOF). */
3159 /* Handle backslash. */
3160 char_escaped = (c == '\\' && ! char_escaped);
3163 #endif /* !USE_CPPLIB */
3165 /* Make a variant type in the proper way for C/C++, propagating qualifiers
3166 down to the element type of an array. */
3168 tree
3169 c_build_qualified_type (type, type_quals)
3170 tree type;
3171 int type_quals;
3173 /* A restrict-qualified pointer type must be a pointer to object or
3174 incomplete type. Note that the use of POINTER_TYPE_P also allows
3175 REFERENCE_TYPEs, which is appropriate for C++. Unfortunately,
3176 the C++ front-end also use POINTER_TYPE for pointer-to-member
3177 values, so even though it should be illegal to use `restrict'
3178 with such an entity we don't flag that here. Thus, special case
3179 code for that case is required in the C++ front-end. */
3180 if ((type_quals & TYPE_QUAL_RESTRICT)
3181 && (!POINTER_TYPE_P (type)
3182 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (type))))
3184 error ("invalid use of `restrict'");
3185 type_quals &= ~TYPE_QUAL_RESTRICT;
3188 if (TREE_CODE (type) == ARRAY_TYPE)
3189 return build_array_type (c_build_qualified_type (TREE_TYPE (type),
3190 type_quals),
3191 TYPE_DOMAIN (type));
3192 return build_qualified_type (type, type_quals);
3195 /* Apply the TYPE_QUALS to the new DECL. */
3197 void
3198 c_apply_type_quals_to_decl (type_quals, decl)
3199 int type_quals;
3200 tree decl;
3202 if (type_quals & TYPE_QUAL_CONST)
3203 TREE_READONLY (decl) = 1;
3204 if (type_quals & TYPE_QUAL_VOLATILE)
3206 TREE_SIDE_EFFECTS (decl) = 1;
3207 TREE_THIS_VOLATILE (decl) = 1;
3209 if (type_quals & TYPE_QUAL_RESTRICT)
3211 if (!TREE_TYPE (decl)
3212 || !POINTER_TYPE_P (TREE_TYPE (decl))
3213 || !C_TYPE_OBJECT_OR_INCOMPLETE_P (TREE_TYPE (TREE_TYPE (decl))))
3214 error ("invalid use of `restrict'");
3215 else if (flag_strict_aliasing)
3217 /* No two restricted pointers can point at the same thing.
3218 However, a restricted pointer can point at the same thing
3219 as an unrestricted pointer, if that unrestricted pointer
3220 is based on the restricted pointer. So, we make the
3221 alias set for the restricted pointer a subset of the
3222 alias set for the type pointed to by the type of the
3223 decl. */
3225 int pointed_to_alias_set
3226 = get_alias_set (TREE_TYPE (TREE_TYPE (decl)));
3228 if (!pointed_to_alias_set)
3229 /* It's not legal to make a subset of alias set zero. */
3231 else
3233 DECL_POINTER_ALIAS_SET (decl) = new_alias_set ();
3234 record_alias_subset (pointed_to_alias_set,
3235 DECL_POINTER_ALIAS_SET (decl));
3241 /* T is an expression with pointer type. Find the DECL on which this
3242 expression is based. (For example, in `a[i]' this would be `a'.)
3243 If there is no such DECL, or a unique decl cannot be determined,
3244 NULL_TREE is retured. */
3246 static tree
3247 c_find_base_decl (t)
3248 tree t;
3250 int i;
3251 tree decl;
3253 if (t == NULL_TREE || t == error_mark_node)
3254 return NULL_TREE;
3256 if (!POINTER_TYPE_P (TREE_TYPE (t)))
3257 return NULL_TREE;
3259 decl = NULL_TREE;
3261 if (TREE_CODE (t) == FIELD_DECL
3262 || TREE_CODE (t) == PARM_DECL
3263 || TREE_CODE (t) == VAR_DECL)
3264 /* Aha, we found a pointer-typed declaration. */
3265 return t;
3267 /* It would be nice to deal with COMPONENT_REFs here. If we could
3268 tell that `a' and `b' were the same, then `a->f' and `b->f' are
3269 also the same. */
3271 /* Handle general expressions. */
3272 switch (TREE_CODE_CLASS (TREE_CODE (t)))
3274 case '1':
3275 case '2':
3276 case '3':
3277 for (i = tree_code_length [(int) TREE_CODE (t)]; --i >= 0;)
3279 tree d = c_find_base_decl (TREE_OPERAND (t, i));
3280 if (d)
3282 if (!decl)
3283 decl = d;
3284 else if (d && d != decl)
3285 /* Two different declarations. That's confusing; let's
3286 just assume we don't know what's going on. */
3287 decl = NULL_TREE;
3290 break;
3292 default:
3293 break;
3296 return decl;
3299 /* Return the typed-based alias set for T, which may be an expression
3300 or a type. */
3303 c_get_alias_set (t)
3304 tree t;
3306 tree type;
3307 tree u;
3309 if (t == error_mark_node)
3310 return 0;
3312 type = (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
3313 ? t : TREE_TYPE (t);
3315 if (type == error_mark_node)
3316 return 0;
3318 /* Deal with special cases first; for certain kinds of references
3319 we're interested in more than just the type. */
3321 if (TREE_CODE (t) == BIT_FIELD_REF)
3322 /* Perhaps reads and writes to this piece of data alias fields
3323 neighboring the bitfield. Perhaps that's impossible. For now,
3324 let's just assume that bitfields can alias everything, which is
3325 the conservative assumption. */
3326 return 0;
3328 /* Permit type-punning when accessing a union, provided the access
3329 is directly through the union. For example, this code does not
3330 permit taking the address of a union member and then storing
3331 through it. Even the type-punning allowed here is a GCC
3332 extension, albeit a common and useful one; the C standard says
3333 that such accesses have implementation-defined behavior. */
3334 for (u = t;
3335 TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF;
3336 u = TREE_OPERAND (u, 0))
3337 if (TREE_CODE (u) == COMPONENT_REF
3338 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE)
3339 return 0;
3341 if (TREE_CODE (t) == INDIRECT_REF)
3343 /* Check for accesses through restrict-qualified pointers. */
3344 tree decl = c_find_base_decl (TREE_OPERAND (t, 0));
3346 if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
3347 /* We use the alias set indicated in the declaration. */
3348 return DECL_POINTER_ALIAS_SET (decl);
3351 /* From here on, only the type matters. */
3353 if (TREE_CODE (t) == COMPONENT_REF
3354 && DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1)))
3355 /* Since build_modify_expr calls get_unwidened for stores to
3356 component references, the type of a bit field can be changed
3357 from (say) `unsigned int : 16' to `unsigned short' or from
3358 `enum E : 16' to `short'. We want the real type of the
3359 bit-field in this case, not some the integral equivalent. */
3360 type = DECL_BIT_FIELD_TYPE (TREE_OPERAND (t, 1));
3362 if (TYPE_ALIAS_SET_KNOWN_P (type))
3363 /* If we've already calculated the value, just return it. */
3364 return TYPE_ALIAS_SET (type);
3365 else if (TYPE_MAIN_VARIANT (type) != type)
3366 /* The C standard specifically allows aliasing between
3367 cv-qualified variants of types. */
3368 TYPE_ALIAS_SET (type) = c_get_alias_set (TYPE_MAIN_VARIANT (type));
3369 else if (TREE_CODE (type) == INTEGER_TYPE)
3371 tree signed_variant;
3373 /* The C standard specifically allows aliasing between signed and
3374 unsigned variants of the same type. We treat the signed
3375 variant as canonical. */
3376 signed_variant = signed_type (type);
3378 if (signed_variant != type)
3379 TYPE_ALIAS_SET (type) = c_get_alias_set (signed_variant);
3380 else if (signed_variant == signed_char_type_node)
3381 /* The C standard guarantess that any object may be accessed
3382 via an lvalue that has character type. We don't have to
3383 check for unsigned_char_type_node or char_type_node because
3384 we are specifically looking at the signed variant. */
3385 TYPE_ALIAS_SET (type) = 0;
3387 else if (TREE_CODE (type) == ARRAY_TYPE)
3388 /* Anything that can alias one of the array elements can alias
3389 the entire array as well. */
3390 TYPE_ALIAS_SET (type) = c_get_alias_set (TREE_TYPE (type));
3391 else if (TREE_CODE (type) == FUNCTION_TYPE)
3392 /* There are no objects of FUNCTION_TYPE, so there's no point in
3393 using up an alias set for them. (There are, of course,
3394 pointers and references to functions, but that's
3395 different.) */
3396 TYPE_ALIAS_SET (type) = 0;
3397 else if (TREE_CODE (type) == RECORD_TYPE
3398 || TREE_CODE (type) == UNION_TYPE)
3399 /* If TYPE is a struct or union type then we're reading or
3400 writing an entire struct. Thus, we don't know anything about
3401 aliasing. (In theory, such an access can only alias objects
3402 whose type is the same as one of the fields, recursively, but
3403 we don't yet make any use of that information.) */
3404 TYPE_ALIAS_SET (type) = 0;
3405 else if (TREE_CODE (type) == POINTER_TYPE
3406 || TREE_CODE (type) == REFERENCE_TYPE)
3408 tree t;
3410 /* Unfortunately, there is no canonical form of a pointer type.
3411 In particular, if we have `typedef int I', then `int *', and
3412 `I *' are different types. So, we have to pick a canonical
3413 representative. We do this below.
3415 Technically, this approach is actually more conservative that
3416 it needs to be. In particular, `const int *' and `int *'
3417 chould be in different alias sets, according to the C and C++
3418 standard, since their types are not the same, and so,
3419 technically, an `int **' and `const int **' cannot point at
3420 the same thing.
3422 But, the standard is wrong. In particular, this code is
3423 legal C++:
3425 int *ip;
3426 int **ipp = &ip;
3427 const int* const* cipp = &ip;
3429 And, it doesn't make sense for that to be legal unless you
3430 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
3431 the pointed-to types. This issue has been reported to the
3432 C++ committee. */
3433 t = TYPE_MAIN_VARIANT (TREE_TYPE (type));
3434 t = ((TREE_CODE (type) == POINTER_TYPE)
3435 ? build_pointer_type (t) : build_reference_type (t));
3436 if (t != type)
3437 TYPE_ALIAS_SET (type) = c_get_alias_set (t);
3440 if (!TYPE_ALIAS_SET_KNOWN_P (type))
3442 /* Types that are not allocated on the permanent obstack are not
3443 placed in the type hash table. Thus, there can be multiple
3444 copies of identical types in local scopes. In the long run,
3445 all types should be permanent. */
3446 if (! TREE_PERMANENT (type))
3447 TYPE_ALIAS_SET (type) = 0;
3448 else
3449 /* TYPE is something we haven't seen before. Put it in a new
3450 alias set. */
3451 TYPE_ALIAS_SET (type) = new_alias_set ();
3454 return TYPE_ALIAS_SET (type);
3457 /* Build tree nodes and builtin functions common to both C and C++ language
3458 frontends.
3459 CPLUS_MODE is nonzero if we are called from the C++ frontend, we generate
3460 some stricter prototypes in that case.
3461 NO_BUILTINS and NO_NONANSI_BUILTINS contain the respective values of
3462 the language frontend flags flag_no_builtin and
3463 flag_no_nonansi_builtin. */
3464 void
3465 c_common_nodes_and_builtins (cplus_mode, no_builtins, no_nonansi_builtins)
3466 int cplus_mode, no_builtins, no_nonansi_builtins;
3468 tree temp;
3469 tree memcpy_ftype, memset_ftype, strlen_ftype;
3470 tree endlink, int_endlink, double_endlink, unsigned_endlink;
3471 tree sizetype_endlink;
3472 tree ptr_ftype, ptr_ftype_unsigned;
3473 tree void_ftype_any, void_ftype_int;
3474 tree double_ftype_double, double_ftype_double_double;
3475 tree float_ftype_float, ldouble_ftype_ldouble;
3476 tree int_ftype_cptr_cptr_sizet;
3477 tree int_ftype_string_string, string_ftype_ptr_ptr;
3478 tree long_ftype_long;
3479 /* Either char* or void*. */
3480 tree traditional_ptr_type_node;
3481 tree va_list_ptr_type_node;
3482 tree va_list_arg_type_node;
3484 #ifdef BUILD_VA_LIST_TYPE
3485 BUILD_VA_LIST_TYPE(va_list_type_node);
3486 #else
3487 va_list_type_node = ptr_type_node;
3488 #endif
3489 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
3490 va_list_type_node));
3492 va_list_ptr_type_node = build_pointer_type (va_list_type_node);
3494 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
3495 va_list_arg_type_node = build_pointer_type (TREE_TYPE (va_list_type_node));
3496 else
3497 va_list_arg_type_node = va_list_type_node;
3499 endlink = void_list_node;
3500 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
3501 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
3502 unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink);
3504 ptr_ftype = build_function_type (ptr_type_node, NULL_TREE);
3505 ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink);
3506 sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink);
3507 /* We realloc here because sizetype could be int or unsigned. S'ok. */
3508 ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink);
3510 void_ftype_any = build_function_type (void_type_node, NULL_TREE);
3511 void_ftype = build_function_type (void_type_node, endlink);
3512 void_ftype_int = build_function_type (void_type_node, int_endlink);
3513 void_ftype_ptr
3514 = build_function_type (void_type_node,
3515 tree_cons (NULL_TREE, ptr_type_node, endlink));
3517 float_ftype_float
3518 = build_function_type (float_type_node,
3519 tree_cons (NULL_TREE, float_type_node, endlink));
3521 double_ftype_double
3522 = build_function_type (double_type_node, double_endlink);
3524 ldouble_ftype_ldouble
3525 = build_function_type (long_double_type_node,
3526 tree_cons (NULL_TREE, long_double_type_node,
3527 endlink));
3529 double_ftype_double_double
3530 = build_function_type (double_type_node,
3531 tree_cons (NULL_TREE, double_type_node,
3532 double_endlink));
3534 int_ftype_int
3535 = build_function_type (integer_type_node, int_endlink);
3537 long_ftype_long
3538 = build_function_type (long_integer_type_node,
3539 tree_cons (NULL_TREE, long_integer_type_node,
3540 endlink));
3542 int_ftype_cptr_cptr_sizet
3543 = build_function_type (integer_type_node,
3544 tree_cons (NULL_TREE, const_ptr_type_node,
3545 tree_cons (NULL_TREE, const_ptr_type_node,
3546 tree_cons (NULL_TREE,
3547 sizetype,
3548 endlink))));
3550 /* Prototype for strcpy. */
3551 string_ftype_ptr_ptr
3552 = build_function_type (string_type_node,
3553 tree_cons (NULL_TREE, string_type_node,
3554 tree_cons (NULL_TREE,
3555 const_string_type_node,
3556 endlink)));
3558 /* Prototype for strcmp. */
3559 int_ftype_string_string
3560 = build_function_type (integer_type_node,
3561 tree_cons (NULL_TREE, const_string_type_node,
3562 tree_cons (NULL_TREE,
3563 const_string_type_node,
3564 endlink)));
3566 /* Prototype for strlen. */
3567 strlen_ftype
3568 = build_function_type ((flag_traditional && ! cplus_mode
3569 ? integer_type_node : sizetype),
3570 tree_cons (NULL_TREE, const_string_type_node,
3571 endlink));
3573 traditional_ptr_type_node = (flag_traditional && ! cplus_mode
3574 ? string_type_node : ptr_type_node);
3576 /* Prototype for memcpy. */
3577 memcpy_ftype
3578 = build_function_type (traditional_ptr_type_node,
3579 tree_cons (NULL_TREE, ptr_type_node,
3580 tree_cons (NULL_TREE, const_ptr_type_node,
3581 sizetype_endlink)));
3583 /* Prototype for memset. */
3584 memset_ftype
3585 = build_function_type (traditional_ptr_type_node,
3586 tree_cons (NULL_TREE, ptr_type_node,
3587 tree_cons (NULL_TREE, integer_type_node,
3588 tree_cons (NULL_TREE,
3589 sizetype,
3590 endlink))));
3592 builtin_function ("__builtin_constant_p", default_function_type,
3593 BUILT_IN_CONSTANT_P, NULL_PTR);
3595 builtin_function ("__builtin_return_address", ptr_ftype_unsigned,
3596 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
3598 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned,
3599 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
3601 builtin_function ("__builtin_alloca", ptr_ftype_sizetype,
3602 BUILT_IN_ALLOCA, "alloca");
3603 builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
3604 /* Define alloca, ffs as builtins.
3605 Declare _exit just to mark it as volatile. */
3606 if (! no_builtins && ! no_nonansi_builtins)
3608 temp = builtin_function ("alloca", ptr_ftype_sizetype,
3609 BUILT_IN_ALLOCA, NULL_PTR);
3610 /* Suppress error if redefined as a non-function. */
3611 DECL_BUILT_IN_NONANSI (temp) = 1;
3612 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
3613 /* Suppress error if redefined as a non-function. */
3614 DECL_BUILT_IN_NONANSI (temp) = 1;
3615 temp = builtin_function ("_exit", void_ftype_int,
3616 NOT_BUILT_IN, NULL_PTR);
3617 TREE_THIS_VOLATILE (temp) = 1;
3618 TREE_SIDE_EFFECTS (temp) = 1;
3619 /* Suppress error if redefined as a non-function. */
3620 DECL_BUILT_IN_NONANSI (temp) = 1;
3623 builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
3624 builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS,
3625 NULL_PTR);
3626 builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
3627 NULL_PTR);
3628 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3629 NULL_PTR);
3630 builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS,
3631 NULL_PTR);
3632 builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS,
3633 NULL_PTR);
3634 builtin_function ("__builtin_classify_type", default_function_type,
3635 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
3636 builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG,
3637 NULL_PTR);
3638 builtin_function ("__builtin_args_info", int_ftype_int, BUILT_IN_ARGS_INFO,
3639 NULL_PTR);
3640 builtin_function ("__builtin_setjmp",
3641 build_function_type (integer_type_node,
3642 tree_cons (NULL_TREE, ptr_type_node,
3643 endlink)),
3644 BUILT_IN_SETJMP, NULL_PTR);
3645 builtin_function ("__builtin_longjmp",
3646 build_function_type (void_type_node,
3647 tree_cons (NULL_TREE, ptr_type_node,
3648 tree_cons (NULL_TREE,
3649 integer_type_node,
3650 endlink))),
3651 BUILT_IN_LONGJMP, NULL_PTR);
3652 builtin_function ("__builtin_trap", void_ftype, BUILT_IN_TRAP, NULL_PTR);
3654 /* Untyped call and return. */
3655 builtin_function ("__builtin_apply_args", ptr_ftype,
3656 BUILT_IN_APPLY_ARGS, NULL_PTR);
3658 temp = tree_cons (NULL_TREE,
3659 build_pointer_type (build_function_type (void_type_node,
3660 NULL_TREE)),
3661 tree_cons (NULL_TREE,
3662 ptr_type_node,
3663 tree_cons (NULL_TREE,
3664 sizetype,
3665 endlink)));
3666 builtin_function ("__builtin_apply",
3667 build_function_type (ptr_type_node, temp),
3668 BUILT_IN_APPLY, NULL_PTR);
3669 builtin_function ("__builtin_return", void_ftype_ptr,
3670 BUILT_IN_RETURN, NULL_PTR);
3672 /* Support for varargs.h and stdarg.h. */
3673 builtin_function ("__builtin_varargs_start",
3674 build_function_type (void_type_node,
3675 tree_cons (NULL_TREE,
3676 va_list_ptr_type_node,
3677 endlink)),
3678 BUILT_IN_VARARGS_START, NULL_PTR);
3680 builtin_function ("__builtin_stdarg_start",
3681 build_function_type (void_type_node,
3682 tree_cons (NULL_TREE,
3683 va_list_ptr_type_node,
3684 NULL_TREE)),
3685 BUILT_IN_STDARG_START, NULL_PTR);
3687 builtin_function ("__builtin_va_end",
3688 build_function_type (void_type_node,
3689 tree_cons (NULL_TREE,
3690 va_list_arg_type_node,
3691 endlink)),
3692 BUILT_IN_VA_END, NULL_PTR);
3694 builtin_function ("__builtin_va_copy",
3695 build_function_type (void_type_node,
3696 tree_cons (NULL_TREE,
3697 va_list_ptr_type_node,
3698 tree_cons (NULL_TREE,
3699 va_list_arg_type_node,
3700 endlink))),
3701 BUILT_IN_VA_COPY, NULL_PTR);
3703 /* Currently under experimentation. */
3704 builtin_function ("__builtin_memcpy", memcpy_ftype, BUILT_IN_MEMCPY,
3705 "memcpy");
3706 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
3707 BUILT_IN_MEMCMP, "memcmp");
3708 builtin_function ("__builtin_memset", memset_ftype, BUILT_IN_MEMSET,
3709 "memset");
3710 builtin_function ("__builtin_strcmp", int_ftype_string_string,
3711 BUILT_IN_STRCMP, "strcmp");
3712 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
3713 BUILT_IN_STRCPY, "strcpy");
3714 builtin_function ("__builtin_strlen", strlen_ftype,
3715 BUILT_IN_STRLEN, "strlen");
3716 builtin_function ("__builtin_sqrtf", float_ftype_float,
3717 BUILT_IN_FSQRT, "sqrtf");
3718 builtin_function ("__builtin_fsqrt", double_ftype_double,
3719 BUILT_IN_FSQRT, "sqrt");
3720 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
3721 BUILT_IN_FSQRT, "sqrtl");
3722 builtin_function ("__builtin_sinf", float_ftype_float,
3723 BUILT_IN_SIN, "sinf");
3724 builtin_function ("__builtin_sin", double_ftype_double,
3725 BUILT_IN_SIN, "sin");
3726 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
3727 BUILT_IN_SIN, "sinl");
3728 builtin_function ("__builtin_cosf", float_ftype_float,
3729 BUILT_IN_COS, "cosf");
3730 builtin_function ("__builtin_cos", double_ftype_double,
3731 BUILT_IN_COS, "cos");
3732 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
3733 BUILT_IN_COS, "cosl");
3735 if (! no_builtins)
3737 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
3738 builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR);
3739 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
3740 builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS,
3741 NULL_PTR);
3742 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
3743 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
3744 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
3745 NULL_PTR);
3746 builtin_function ("memset", memset_ftype, BUILT_IN_MEMSET, NULL_PTR);
3747 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
3748 NULL_PTR);
3749 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
3750 NULL_PTR);
3751 builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR);
3752 builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR);
3753 builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR);
3754 builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT,
3755 NULL_PTR);
3756 builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR);
3757 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
3758 builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR);
3759 builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR);
3760 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
3761 builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR);
3763 /* Declare these functions volatile
3764 to avoid spurious "control drops through" warnings. */
3765 temp = builtin_function ("abort", cplus_mode ? void_ftype : void_ftype_any,
3766 NOT_BUILT_IN, NULL_PTR);
3767 TREE_THIS_VOLATILE (temp) = 1;
3768 TREE_SIDE_EFFECTS (temp) = 1;
3770 #if 0 /* ??? The C++ frontend used to do this. */
3771 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3772 them... */
3773 DECL_BUILT_IN_NONANSI (temp) = 1;
3774 #endif
3775 temp = builtin_function ("exit",
3776 cplus_mode ? void_ftype_int : void_ftype_any,
3777 NOT_BUILT_IN, NULL_PTR);
3778 TREE_THIS_VOLATILE (temp) = 1;
3779 TREE_SIDE_EFFECTS (temp) = 1;
3781 #if 0 /* ??? The C++ frontend used to do this. */
3782 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
3783 them... */
3784 DECL_BUILT_IN_NONANSI (temp) = 1;
3785 #endif
3788 #if 0
3789 /* Support for these has not been written in either expand_builtin
3790 or build_function_call. */
3791 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
3792 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
3793 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
3794 NULL_PTR);
3795 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
3796 NULL_PTR);
3797 builtin_function ("__builtin_fmod", double_ftype_double_double,
3798 BUILT_IN_FMOD, NULL_PTR);
3799 builtin_function ("__builtin_frem", double_ftype_double_double,
3800 BUILT_IN_FREM, NULL_PTR);
3801 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
3802 NULL_PTR);
3803 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
3804 NULL_PTR);
3805 #endif
3808 tree
3809 build_va_arg (expr, type)
3810 tree 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. */
3825 tree
3826 initializer_constant_valid_p (value, endtype)
3827 tree value;
3828 tree endtype;
3830 switch (TREE_CODE (value))
3832 case CONSTRUCTOR:
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))
3837 return
3838 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
3839 endtype);
3841 return TREE_STATIC (value) ? null_pointer_node : 0;
3843 case INTEGER_CST:
3844 case REAL_CST:
3845 case STRING_CST:
3846 case COMPLEX_CST:
3847 return null_pointer_node;
3849 case ADDR_EXPR:
3850 return TREE_OPERAND (value, 0);
3852 case NON_LVALUE_EXPR:
3853 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3855 case CONVERT_EXPR:
3856 case NOP_EXPR:
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
3875 explicit value. */
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),
3880 endtype);
3881 if (inner == null_pointer_node)
3882 return null_pointer_node;
3883 break;
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),
3892 endtype);
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),
3904 endtype);
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),
3910 endtype);
3911 break;
3913 case PLUS_EXPR:
3914 if (! INTEGRAL_TYPE_P (endtype)
3915 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3917 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3918 endtype);
3919 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3920 endtype);
3921 /* If either term is absolute, use the other terms relocation. */
3922 if (valid0 == null_pointer_node)
3923 return valid1;
3924 if (valid1 == null_pointer_node)
3925 return valid0;
3927 break;
3929 case MINUS_EXPR:
3930 if (! INTEGRAL_TYPE_P (endtype)
3931 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3933 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3934 endtype);
3935 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3936 endtype);
3937 /* Win if second argument is absolute. */
3938 if (valid1 == null_pointer_node)
3939 return valid0;
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))
3949 tree op0, op1;
3950 op0 = TREE_OPERAND (value, 0);
3951 op1 = TREE_OPERAND (value, 1);
3952 STRIP_NOPS (op0);
3953 STRIP_NOPS (op1);
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;
3961 break;
3963 default:
3964 break;
3967 return 0;