Deleted Added
sdiff udiff text old ( 110621 ) new ( 117404 )
full compact
1/* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free

--- 8 unchanged lines hidden (view full) ---

17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
22#include "config.h"
23#include "system.h"
24#include "tree.h"
25#include "flags.h"
26#include "toplev.h"
27#include "output.h"
28#include "c-pragma.h"
29#include "rtl.h"
30#include "ggc.h"
31#include "expr.h"
32#include "c-common.h"
33#include "tree-inline.h"
34#include "diagnostic.h"
35#include "tm_p.h"
36#include "obstack.h"
37#include "c-lex.h"
38#include "cpplib.h"
39#include "target.h"
40cpp_reader *parse_in; /* Declared in c-lex.h. */
41
42#undef WCHAR_TYPE_SIZE
43#define WCHAR_TYPE_SIZE TYPE_PRECISION (wchar_type_node)
44
45/* We let tm.h override the types used here, to handle trivial differences
46 such as the choice of unsigned int or long unsigned int for size_t.
47 When machines start needing nontrivial differences in the size type,
48 it would be best to do something here to figure out automatically
49 from other information what type to use. */
50
51#ifndef SIZE_TYPE
52#define SIZE_TYPE "long unsigned int"
53#endif
54
55#ifndef WCHAR_TYPE
56#define WCHAR_TYPE "int"
57#endif
58
59#ifndef PTRDIFF_TYPE
60#define PTRDIFF_TYPE "long int"
61#endif
62
63#ifndef WINT_TYPE
64#define WINT_TYPE "unsigned int"
65#endif
66

--- 8 unchanged lines hidden (view full) ---

75#ifndef UINTMAX_TYPE
76#define UINTMAX_TYPE ((INT_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
77 ? "unsigned int" \
78 : ((LONG_TYPE_SIZE == LONG_LONG_TYPE_SIZE) \
79 ? "long unsigned int" \
80 : "long long unsigned int"))
81#endif
82
83/* The variant of the C language being processed. */
84
85enum c_language_kind c_language;
86
87/* The following symbols are subsumed in the c_global_trees array, and
88 listed here individually for documentation purposes.
89
90 INTEGER_TYPE and REAL_TYPE nodes for the standard data types.

--- 84 unchanged lines hidden (view full) ---

175 Stack of nested function name VAR_DECLs.
176
177 tree saved_function_name_decls;
178
179*/
180
181tree c_global_trees[CTI_MAX];
182
183/* Nonzero means don't recognize the non-ANSI builtin functions. */
184
185int flag_no_builtin;
186
187/* Nonzero means don't recognize the non-ANSI builtin functions.
188 -ansi sets this. */
189
190int flag_no_nonansi_builtin;
191
192/* Nonzero means give `double' the same size as `float'. */
193
194int flag_short_double;
195
196/* Nonzero means give `wchar_t' the same size as `short'. */
197
198int flag_short_wchar;
199
200/* Nonzero means warn about possible violations of sequence point rules. */
201
202int warn_sequence_point;
203
204/* Nonzero means to warn about compile-time division by zero. */
205int warn_div_by_zero = 1;
206
207/* The elements of `ridpointers' are identifier nodes for the reserved
208 type names and storage classes. It is indexed by a RID_... value. */
209tree *ridpointers;
210
211tree (*make_fname_decl) PARAMS ((tree, int));
212
213/* If non-NULL, the address of a language-specific function that
214 returns 1 for language-specific statement codes. */

--- 47 unchanged lines hidden (view full) ---

262static if_elt *if_stack;
263
264/* Amount of space in the if statement stack. */
265static int if_stack_space = 0;
266
267/* Stack pointer. */
268static int if_stack_pointer = 0;
269
270/* Record the start of an if-then, and record the start of it
271 for ambiguous else detection.
272
273 COND is the condition for the if-then statement.
274
275 IF_STMT is the statement node that has already been created for
276 this if-then statement. It is created before parsing the
277 condition to keep line number information accurate. */

--- 200 unchanged lines hidden (view full) ---

478const char *
479fname_as_string (pretty_p)
480 int pretty_p;
481{
482 const char *name = NULL;
483
484 if (pretty_p)
485 name = (current_function_decl
486 ? (*decl_printable_name) (current_function_decl, 2)
487 : "top level");
488 else if (current_function_decl && DECL_NAME (current_function_decl))
489 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
490 else
491 name = "";
492 return name;
493}
494

--- 30 unchanged lines hidden (view full) ---

525 for (ix = 0; fname_vars[ix].decl; ix++)
526 if (fname_vars[ix].rid == rid)
527 break;
528
529 decl = *fname_vars[ix].decl;
530 if (!decl)
531 {
532 tree saved_last_tree = last_tree;
533
534 decl = (*make_fname_decl) (id, fname_vars[ix].pretty);
535 if (last_tree != saved_last_tree)
536 {
537 /* We created some statement tree for the decl. This belongs
538 at the start of the function, so remove it now and reinsert
539 it after the function is complete. */
540 tree stmts = TREE_CHAIN (saved_last_tree);
541
542 TREE_CHAIN (saved_last_tree) = NULL_TREE;
543 last_tree = saved_last_tree;
544 saved_function_name_decls = tree_cons (decl, stmts,
545 saved_function_name_decls);
546 }
547 *fname_vars[ix].decl = decl;
548 }
549 if (!ix && !current_function_decl)
550 pedwarn_with_decl (decl, "`%s' is not defined outside of function scope");
551
552 return decl;
553}
554
555/* Given a chain of STRING_CST nodes,
556 concatenate them into one STRING_CST
557 and give it a suitable array-of-chars data type. */
558
559tree
560combine_strings (strings)
561 tree strings;
562{
563 tree value, t;
564 int length = 1;
565 int wide_length = 0;
566 int wide_flag = 0;
567 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
568 int nchars;
569 const int nchars_max = flag_isoc99 ? 4095 : 509;
570
571 if (TREE_CHAIN (strings))
572 {
573 /* More than one in the chain, so concatenate. */
574 char *p, *q;
575
576 /* Don't include the \0 at the end of each substring,
577 except for the last one.
578 Count wide strings and ordinary strings separately. */
579 for (t = strings; t; t = TREE_CHAIN (t))
580 {
581 if (TREE_TYPE (t) == wchar_array_type_node)
582 {
583 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
584 wide_flag = 1;
585 }
586 else
587 {
588 length += (TREE_STRING_LENGTH (t) - 1);
589 if (C_ARTIFICIAL_STRING_P (t) && !in_system_header)
590 warning ("concatenation of string literals with __FUNCTION__ is deprecated");
591 }
592 }
593
594 /* If anything is wide, the non-wides will be converted,
595 which makes them take more space. */
596 if (wide_flag)
597 length = length * wchar_bytes + wide_length;
598
599 p = xmalloc (length);
600
601 /* Copy the individual strings into the new combined string.
602 If the combined string is wide, convert the chars to ints
603 for any individual strings that are not wide. */
604
605 q = p;
606 for (t = strings; t; t = TREE_CHAIN (t))
607 {
608 int len = (TREE_STRING_LENGTH (t)
609 - ((TREE_TYPE (t) == wchar_array_type_node)
610 ? wchar_bytes : 1));
611 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
612 {
613 memcpy (q, TREE_STRING_POINTER (t), len);
614 q += len;
615 }
616 else
617 {
618 int i, j;
619 for (i = 0; i < len; i++)
620 {
621 if (BYTES_BIG_ENDIAN)
622 {
623 for (j=0; j<(WCHAR_TYPE_SIZE / BITS_PER_UNIT)-1; j++)
624 *q++ = 0;
625 *q++ = TREE_STRING_POINTER (t)[i];
626 }
627 else
628 {
629 *q++ = TREE_STRING_POINTER (t)[i];
630 for (j=0; j<(WCHAR_TYPE_SIZE / BITS_PER_UNIT)-1; j++)
631 *q++ = 0;
632 }
633 }
634 }
635 }
636 if (wide_flag)
637 {
638 int i;
639 for (i = 0; i < wchar_bytes; i++)
640 *q++ = 0;
641 }
642 else
643 *q = 0;
644
645 value = build_string (length, p);
646 free (p);
647 }
648 else
649 {
650 value = strings;
651 length = TREE_STRING_LENGTH (value);
652 if (TREE_TYPE (value) == wchar_array_type_node)
653 wide_flag = 1;
654 }
655
656 /* Compute the number of elements, for the array type. */
657 nchars = wide_flag ? length / wchar_bytes : length;
658
659 if (pedantic && nchars - 1 > nchars_max && c_language == clk_c)
660 pedwarn ("string length `%d' is greater than the length `%d' ISO C%d compilers are required to support",
661 nchars - 1, nchars_max, flag_isoc99 ? 99 : 89);
662
663 /* Create the array type for the string constant.
664 -Wwrite-strings says make the string constant an array of const char
665 so that copying it to a non-const pointer will get a warning.
666 For C++, this is the standard behavior. */
667 if (flag_const_strings
668 && (! flag_traditional && ! flag_writable_strings))
669 {
670 tree elements
671 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
672 1, 0);
673 TREE_TYPE (value)
674 = build_array_type (elements,
675 build_index_type (build_int_2 (nchars - 1, 0)));
676 }
677 else
678 TREE_TYPE (value)
679 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
680 build_index_type (build_int_2 (nchars - 1, 0)));
681
682 TREE_CONSTANT (value) = 1;
683 TREE_READONLY (value) = ! flag_writable_strings;
684 TREE_STATIC (value) = 1;
685 return value;
686}
687
688static int is_valid_printf_arglist PARAMS ((tree));
689static rtx c_expand_builtin PARAMS ((tree, rtx, enum machine_mode, enum expand_modifier));
690static rtx c_expand_builtin_printf PARAMS ((tree, rtx, enum machine_mode,
691 enum expand_modifier, int, int));
692static rtx c_expand_builtin_fprintf PARAMS ((tree, rtx, enum machine_mode,

--- 57 unchanged lines hidden (view full) ---

750 or if -Wconversion is used and a constant < 0 is converted to unsigned.
751 Invoke this function on every expression that might be implicitly
752 converted to an unsigned type. */
753
754void
755unsigned_conversion_warning (result, operand)
756 tree result, operand;
757{
758 if (TREE_CODE (operand) == INTEGER_CST
759 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
760 && TREE_UNSIGNED (TREE_TYPE (result))
761 && skip_evaluation == 0
762 && !int_fits_type_p (operand, TREE_TYPE (result)))
763 {
764 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
765 /* This detects cases like converting -129 or 256 to unsigned char. */
766 warning ("large integer implicitly truncated to unsigned type");
767 else if (warn_conversion)
768 warning ("negative integer implicitly converted to unsigned type");
769 }
770}
771
772/* Nonzero if constant C has a value that is permissible

--- 32 unchanged lines hidden (view full) ---

805 /* No warning for converting 0x80000000 to int. */
806 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
807 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
808 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
809 /* If EXPR fits in the unsigned version of TYPE,
810 don't warn unless pedantic. */
811 if ((pedantic
812 || TREE_UNSIGNED (type)
813 || ! constant_fits_type_p (expr, unsigned_type (type)))
814 && skip_evaluation == 0)
815 warning ("overflow in implicit constant conversion");
816 }
817 else
818 unsigned_conversion_warning (t, expr);
819 }
820 return t;
821}

--- 385 unchanged lines hidden (view full) ---

1207 merge_tlist (&tmp_nosp, tmp_before, 0);
1208 add_tlist (pno_sp, tmp_nosp, NULL_TREE, 0);
1209 }
1210 break;
1211 }
1212 }
1213}
1214
1215/* Try to warn for undefined behaviour in EXPR due to missing sequence
1216 points. */
1217
1218static void
1219verify_sequence_points (expr)
1220 tree expr;
1221{
1222 struct tlist *before_sp = 0, *after_sp = 0;
1223

--- 71 unchanged lines hidden (view full) ---

1295
1296 return value;
1297}
1298
1299/* Return an integer type with BITS bits of precision,
1300 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
1301
1302tree
1303type_for_size (bits, unsignedp)
1304 unsigned bits;
1305 int unsignedp;
1306{
1307 if (bits == TYPE_PRECISION (integer_type_node))
1308 return unsignedp ? unsigned_type_node : integer_type_node;
1309
1310 if (bits == TYPE_PRECISION (signed_char_type_node))
1311 return unsignedp ? unsigned_char_type_node : signed_char_type_node;

--- 27 unchanged lines hidden (view full) ---

1339 return 0;
1340}
1341
1342/* Return a data type that has machine mode MODE.
1343 If the mode is an integer,
1344 then UNSIGNEDP selects between signed and unsigned types. */
1345
1346tree
1347type_for_mode (mode, unsignedp)
1348 enum machine_mode mode;
1349 int unsignedp;
1350{
1351 if (mode == TYPE_MODE (integer_type_node))
1352 return unsignedp ? unsigned_type_node : integer_type_node;
1353
1354 if (mode == TYPE_MODE (signed_char_type_node))
1355 return unsignedp ? unsigned_char_type_node : signed_char_type_node;

--- 38 unchanged lines hidden (view full) ---

1394 return long_double_type_node;
1395
1396 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
1397 return build_pointer_type (char_type_node);
1398
1399 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
1400 return build_pointer_type (integer_type_node);
1401
1402#ifdef VECTOR_MODE_SUPPORTED_P
1403 if (VECTOR_MODE_SUPPORTED_P (mode))
1404 {
1405 switch (mode)
1406 {
1407 case V16QImode:
1408 return unsignedp ? unsigned_V16QI_type_node : V16QI_type_node;
1409 case V8HImode:
1410 return unsignedp ? unsigned_V8HI_type_node : V8HI_type_node;
1411 case V4SImode:
1412 return unsignedp ? unsigned_V4SI_type_node : V4SI_type_node;
1413 case V2SImode:
1414 return unsignedp ? unsigned_V2SI_type_node : V2SI_type_node;
1415 case V4HImode:
1416 return unsignedp ? unsigned_V4HI_type_node : V4HI_type_node;
1417 case V8QImode:
1418 return unsignedp ? unsigned_V8QI_type_node : V8QI_type_node;
1419 case V16SFmode:
1420 return V16SF_type_node;
1421 case V4SFmode:
1422 return V4SF_type_node;
1423 case V2SFmode:
1424 return V2SF_type_node;
1425 default:
1426 break;
1427 }
1428 }
1429#endif
1430
1431 return 0;
1432}
1433
1434/* Return an unsigned type the same as TYPE in other respects. */
1435tree
1436unsigned_type (type)
1437 tree type;
1438{
1439 tree type1 = TYPE_MAIN_VARIANT (type);
1440 if (type1 == signed_char_type_node || type1 == char_type_node)
1441 return unsigned_char_type_node;
1442 if (type1 == integer_type_node)
1443 return unsigned_type_node;
1444 if (type1 == short_integer_type_node)

--- 12 unchanged lines hidden (view full) ---

1457 return unsigned_intDI_type_node;
1458 if (type1 == intSI_type_node)
1459 return unsigned_intSI_type_node;
1460 if (type1 == intHI_type_node)
1461 return unsigned_intHI_type_node;
1462 if (type1 == intQI_type_node)
1463 return unsigned_intQI_type_node;
1464
1465 return signed_or_unsigned_type (1, type);
1466}
1467
1468/* Return a signed type the same as TYPE in other respects. */
1469
1470tree
1471signed_type (type)
1472 tree type;
1473{
1474 tree type1 = TYPE_MAIN_VARIANT (type);
1475 if (type1 == unsigned_char_type_node || type1 == char_type_node)
1476 return signed_char_type_node;
1477 if (type1 == unsigned_type_node)
1478 return integer_type_node;
1479 if (type1 == short_unsigned_type_node)

--- 12 unchanged lines hidden (view full) ---

1492 return intDI_type_node;
1493 if (type1 == unsigned_intSI_type_node)
1494 return intSI_type_node;
1495 if (type1 == unsigned_intHI_type_node)
1496 return intHI_type_node;
1497 if (type1 == unsigned_intQI_type_node)
1498 return intQI_type_node;
1499
1500 return signed_or_unsigned_type (0, type);
1501}
1502
1503/* Return a type the same as TYPE except unsigned or
1504 signed according to UNSIGNEDP. */
1505
1506tree
1507signed_or_unsigned_type (unsignedp, type)
1508 int unsignedp;
1509 tree type;
1510{
1511 if (! INTEGRAL_TYPE_P (type)
1512 || TREE_UNSIGNED (type) == unsignedp)
1513 return type;
1514
1515 if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))

--- 51 unchanged lines hidden (view full) ---

1567 if (integer_zerop (value))
1568 log = 0;
1569 else
1570 log = tree_floor_log2 (value);
1571
1572 return log + 1 + ! unsignedp;
1573}
1574
1575/* Print an error message for invalid operands to arith operation CODE.
1576 NOP_EXPR is used as a special case (see truthvalue_conversion). */
1577
1578void
1579binary_op_error (code)
1580 enum tree_code code;
1581{
1582 const char *opname;
1583
1584 switch (code)

--- 163 unchanged lines hidden (view full) ---

1748 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
1749 {
1750 int min_gt, max_gt, min_lt, max_lt;
1751 tree maxval, minval;
1752 /* 1 if comparison is nominally unsigned. */
1753 int unsignedp = TREE_UNSIGNED (*restype_ptr);
1754 tree val;
1755
1756 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
1757
1758 /* If TYPE is an enumeration, then we need to get its min/max
1759 values from it's underlying integral type, not the enumerated
1760 type itself. */
1761 if (TREE_CODE (type) == ENUMERAL_TYPE)
1762 type = type_for_size (TYPE_PRECISION (type), unsignedp0);
1763
1764 maxval = TYPE_MAX_VALUE (type);
1765 minval = TYPE_MIN_VALUE (type);
1766
1767 if (unsignedp && !unsignedp0)
1768 *restype_ptr = signed_type (*restype_ptr);
1769
1770 if (TREE_TYPE (primop1) != *restype_ptr)
1771 primop1 = convert (*restype_ptr, primop1);
1772 if (type != *restype_ptr)
1773 {
1774 minval = convert (*restype_ptr, minval);
1775 maxval = convert (*restype_ptr, maxval);
1776 }

--- 80 unchanged lines hidden (view full) ---

1857 case GT_EXPR:
1858 primop1 = TYPE_MAX_VALUE (type);
1859 val = 0;
1860 break;
1861
1862 default:
1863 break;
1864 }
1865 type = unsigned_type (type);
1866 }
1867
1868 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
1869 {
1870 /* This is the case of (char)x >?< 0x80, which people used to use
1871 expecting old C compilers to change the 0x80 into -0x80. */
1872 if (val == boolean_false_node)
1873 warning ("comparison is always false due to limited range of data type");
1874 if (val == boolean_true_node)
1875 warning ("comparison is always true due to limited range of data type");
1876 }
1877
1878 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
1879 {
1880 /* This is the case of (unsigned char)x >?< -1 or < 0. */
1881 if (val == boolean_false_node)
1882 warning ("comparison is always false due to limited range of data type");
1883 if (val == boolean_true_node)
1884 warning ("comparison is always true due to limited range of data type");
1885 }
1886
1887 if (val != 0)
1888 {
1889 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
1890 if (TREE_SIDE_EFFECTS (primop0))
1891 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
1892 return val;
1893 }
1894

--- 14 unchanged lines hidden (view full) ---

1909 alter the result.
1910 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
1911
1912 else if (unsignedp0 == unsignedp1 && real1 == real2
1913 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
1914 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
1915 {
1916 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
1917 type = signed_or_unsigned_type (unsignedp0
1918 || TREE_UNSIGNED (*restype_ptr),
1919 type);
1920 /* Make sure shorter operand is extended the right way
1921 to match the longer operand. */
1922 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
1923 primop0);
1924 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
1925 primop1);
1926 }
1927 else
1928 {
1929 /* Here we must do the comparison on the nominal type
1930 using the args exactly as we received them. */
1931 type = *restype_ptr;
1932 primop0 = op0;
1933 primop1 = op1;

--- 6 unchanged lines hidden (view full) ---

1940 {
1941 case GE_EXPR:
1942 /* All unsigned values are >= 0, so we warn if extra warnings
1943 are requested. However, if OP0 is a constant that is
1944 >= 0, the signedness of the comparison isn't an issue,
1945 so suppress the warning. */
1946 if (extra_warnings && !in_system_header
1947 && ! (TREE_CODE (primop0) == INTEGER_CST
1948 && ! TREE_OVERFLOW (convert (signed_type (type),
1949 primop0))))
1950 warning ("comparison of unsigned expression >= 0 is always true");
1951 value = boolean_true_node;
1952 break;
1953
1954 case LT_EXPR:
1955 if (extra_warnings && !in_system_header
1956 && ! (TREE_CODE (primop0) == INTEGER_CST
1957 && ! TREE_OVERFLOW (convert (signed_type (type),
1958 primop0))))
1959 warning ("comparison of unsigned expression < 0 is always false");
1960 value = boolean_false_node;
1961 break;
1962
1963 default:
1964 break;
1965 }

--- 92 unchanged lines hidden (view full) ---

2058 intop = convert (int_type, TREE_OPERAND (intop, 0));
2059 }
2060
2061 /* Convert the integer argument to a type the same size as sizetype
2062 so the multiply won't overflow spuriously. */
2063
2064 if (TYPE_PRECISION (TREE_TYPE (intop)) != TYPE_PRECISION (sizetype)
2065 || TREE_UNSIGNED (TREE_TYPE (intop)) != TREE_UNSIGNED (sizetype))
2066 intop = convert (type_for_size (TYPE_PRECISION (sizetype),
2067 TREE_UNSIGNED (sizetype)), intop);
2068
2069 /* Replace the integer argument with a suitable product by the object size.
2070 Do this multiplication as signed, then convert to the appropriate
2071 pointer type (actually unsigned integral). */
2072
2073 intop = convert (result_type,
2074 build_binary_op (MULT_EXPR, intop,
2075 convert (TREE_TYPE (intop), size_exp), 1));

--- 15 unchanged lines hidden (view full) ---

2091 representation of an expression expr and producing a valid tree
2092 boolean expression describing whether expr is nonzero. We could
2093 simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1),
2094 but we optimize comparisons, &&, ||, and !.
2095
2096 The resulting type should always be `boolean_type_node'. */
2097
2098tree
2099truthvalue_conversion (expr)
2100 tree expr;
2101{
2102 if (TREE_CODE (expr) == ERROR_MARK)
2103 return expr;
2104
2105#if 0 /* This appears to be wrong for C++. */
2106 /* These really should return error_mark_node after 2.4 is stable.
2107 But not all callers handle ERROR_MARK properly. */

--- 49 unchanged lines hidden (view full) ---

2157 return build (COMPOUND_EXPR, boolean_type_node,
2158 TREE_OPERAND (expr, 0), boolean_true_node);
2159 else
2160 return boolean_true_node;
2161
2162 case COMPLEX_EXPR:
2163 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
2164 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2165 truthvalue_conversion (TREE_OPERAND (expr, 0)),
2166 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2167 0);
2168
2169 case NEGATE_EXPR:
2170 case ABS_EXPR:
2171 case FLOAT_EXPR:
2172 case FFS_EXPR:
2173 /* These don't change whether an object is non-zero or zero. */
2174 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2175
2176 case LROTATE_EXPR:
2177 case RROTATE_EXPR:
2178 /* These don't change whether an object is zero or non-zero, but
2179 we can't ignore them if their second arg has side-effects. */
2180 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
2181 return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1),
2182 truthvalue_conversion (TREE_OPERAND (expr, 0)));
2183 else
2184 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2185
2186 case COND_EXPR:
2187 /* Distribute the conversion into the arms of a COND_EXPR. */
2188 return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0),
2189 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2190 truthvalue_conversion (TREE_OPERAND (expr, 2))));
2191
2192 case CONVERT_EXPR:
2193 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
2194 since that affects how `default_conversion' will behave. */
2195 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
2196 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
2197 break;
2198 /* fall through... */
2199 case NOP_EXPR:
2200 /* If this is widening the argument, we can ignore it. */
2201 if (TYPE_PRECISION (TREE_TYPE (expr))
2202 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
2203 return truthvalue_conversion (TREE_OPERAND (expr, 0));
2204 break;
2205
2206 case MINUS_EXPR:
2207 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
2208 this case. */
2209 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
2210 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
2211 break;
2212 /* fall through... */
2213 case BIT_XOR_EXPR:
2214 /* This and MINUS_EXPR can be changed into a comparison of the
2215 two objects. */
2216 if (TREE_TYPE (TREE_OPERAND (expr, 0))
2217 == TREE_TYPE (TREE_OPERAND (expr, 1)))
2218 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),

--- 16 unchanged lines hidden (view full) ---

2235 break;
2236
2237 default:
2238 break;
2239 }
2240
2241 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
2242 {
2243 tree tem = save_expr (expr);
2244 return (build_binary_op
2245 ((TREE_SIDE_EFFECTS (expr)
2246 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2247 truthvalue_conversion (build_unary_op (REALPART_EXPR, tem, 0)),
2248 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, tem, 0)),
2249 0));
2250 }
2251
2252 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
2253}
2254
2255static tree builtin_function_2 PARAMS ((const char *, const char *, tree, tree,
2256 int, enum built_in_class, int, int,
2257 int));
2258
2259/* Make a variant type in the proper way for C/C++, propagating qualifiers
2260 down to the element type of an array. */
2261
2262tree
2263c_build_qualified_type (type, type_quals)
2264 tree type;
2265 int type_quals;

--- 45 unchanged lines hidden (view full) ---

2311 else if (flag_strict_aliasing)
2312 /* Indicate we need to make a unique alias set for this pointer.
2313 We can't do it here because it might be pointing to an
2314 incomplete type. */
2315 DECL_POINTER_ALIAS_SET (decl) = -2;
2316 }
2317}
2318
2319
2320/* Return the typed-based alias set for T, which may be an expression
2321 or a type. Return -1 if we don't do anything special. */
2322
2323HOST_WIDE_INT
2324c_common_get_alias_set (t)
2325 tree t;
2326{
2327 tree u;

--- 16 unchanged lines hidden (view full) ---

2344 return -1;
2345
2346 /* The C standard guarantess that any object may be accessed via an
2347 lvalue that has character type. */
2348 if (t == char_type_node
2349 || t == signed_char_type_node
2350 || t == unsigned_char_type_node)
2351 return 0;
2352
2353 /* The C standard specifically allows aliasing between signed and
2354 unsigned variants of the same type. We treat the signed
2355 variant as canonical. */
2356 if (TREE_CODE (t) == INTEGER_TYPE && TREE_UNSIGNED (t))
2357 {
2358 tree t1 = signed_type (t);
2359
2360 /* t1 == t can happen for boolean nodes which are always unsigned. */
2361 if (t1 != t)
2362 return get_alias_set (t1);
2363 }
2364 else if (POINTER_TYPE_P (t))
2365 {
2366 tree t1;

--- 24 unchanged lines hidden (view full) ---

2391 t1 = build_type_no_quals (t);
2392 if (t1 != t)
2393 return get_alias_set (t1);
2394 }
2395
2396 return -1;
2397}
2398
2399/* Implement the __alignof keyword: Return the minimum required
2400 alignment of TYPE, measured in bytes. */
2401
2402tree
2403c_alignof (type)
2404 tree type;
2405{
2406 enum tree_code code = TREE_CODE (type);
2407 tree t;
2408
2409 /* In C++, sizeof applies to the referent. Handle alignof the same way. */
2410 if (code == REFERENCE_TYPE)
2411 {
2412 type = TREE_TYPE (type);
2413 code = TREE_CODE (type);
2414 }
2415
2416 if (code == FUNCTION_TYPE)
2417 t = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2418 else if (code == VOID_TYPE || code == ERROR_MARK)
2419 t = size_one_node;
2420 else if (!COMPLETE_TYPE_P (type))
2421 {
2422 error ("__alignof__ applied to an incomplete type");
2423 t = size_zero_node;
2424 }
2425 else
2426 t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
2427
2428 return fold (build1 (NOP_EXPR, size_type_node, t));
2429}
2430
2431/* Implement the __alignof keyword: Return the minimum required
2432 alignment of EXPR, measured in bytes. For VAR_DECL's and
2433 FIELD_DECL's return DECL_ALIGN (which can be set from an
2434 "aligned" __attribute__ specification). */
2435
2436tree

--- 34 unchanged lines hidden (view full) ---

2471 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
2472 }
2473 else
2474 return c_alignof (TREE_TYPE (expr));
2475
2476 return fold (build1 (NOP_EXPR, size_type_node, t));
2477}
2478
2479/* Give the specifications for the format attributes, used by C and all
2480 descendents. */
2481
2482static const struct attribute_spec c_format_attribute_table[] =
2483{
2484 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2485 { "format", 3, 3, false, true, true,
2486 handle_format_attribute },
2487 { "format_arg", 1, 1, false, true, true,
2488 handle_format_arg_attribute },
2489 { NULL, 0, 0, false, false, false, NULL }
2490};
2491
2492/* Build tree nodes and builtin functions common to both C and C++ language
2493 frontends. */
2494
2495void
2496c_common_nodes_and_builtins ()
2497{
2498 enum builtin_type
2499 {
2500#define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME,
2501#define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME,
2502#define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME,
2503#define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME,
2504#define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME,
2505#define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME,
2506#define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME,
2507#define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME,
2508#define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME,
2509#define DEF_POINTER_TYPE(NAME, TYPE) NAME,
2510#include "builtin-types.def"
2511#undef DEF_PRIMITIVE_TYPE
2512#undef DEF_FUNCTION_TYPE_0
2513#undef DEF_FUNCTION_TYPE_1
2514#undef DEF_FUNCTION_TYPE_2
2515#undef DEF_FUNCTION_TYPE_3
2516#undef DEF_FUNCTION_TYPE_4
2517#undef DEF_FUNCTION_TYPE_VAR_0
2518#undef DEF_FUNCTION_TYPE_VAR_1
2519#undef DEF_FUNCTION_TYPE_VAR_2
2520#undef DEF_POINTER_TYPE
2521 BT_LAST
2522 };
2523
2524 typedef enum builtin_type builtin_type;
2525
2526 tree builtin_types[(int) BT_LAST];
2527 int wchar_type_size;
2528 tree array_domain_type;
2529 /* Either char* or void*. */
2530 tree traditional_ptr_type_node;
2531 /* Either const char* or const void*. */
2532 tree traditional_cptr_type_node;
2533 tree traditional_len_type_node;
2534 tree va_list_ref_type_node;
2535 tree va_list_arg_type_node;
2536
2537 /* We must initialize this before any builtin functions (which might have
2538 attributes) are declared. (c_common_init is too late.) */
2539 format_attribute_table = c_format_attribute_table;
2540
2541 /* Define `int' and `char' first so that dbx will output them first. */
2542 record_builtin_type (RID_INT, NULL, integer_type_node);
2543 record_builtin_type (RID_CHAR, "char", char_type_node);
2544
2545 /* `signed' is the same as `int'. FIXME: the declarations of "signed",
2546 "unsigned long", "long long unsigned" and "unsigned short" were in C++
2547 but not C. Are the conditionals here needed? */
2548 if (c_language == clk_cplusplus)

--- 17 unchanged lines hidden (view full) ---

2566 if (c_language == clk_cplusplus)
2567 record_builtin_type (RID_MAX, "unsigned short",
2568 short_unsigned_type_node);
2569
2570 /* Define both `signed char' and `unsigned char'. */
2571 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
2572 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
2573
2574 /* These are types that type_for_size and type_for_mode use. */
2575 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
2576 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
2577 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
2578 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
2579#if HOST_BITS_PER_WIDE_INT >= 64
2580 pushdecl (build_decl (TYPE_DECL, get_identifier ("__int128_t"), intTI_type_node));
2581#endif
2582 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
2583 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
2584 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
2585 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
2586#if HOST_BITS_PER_WIDE_INT >= 64
2587 pushdecl (build_decl (TYPE_DECL, get_identifier ("__uint128_t"), unsigned_intTI_type_node));
2588#endif
2589
2590 /* Create the widest literal types. */
2591 widest_integer_literal_type_node
2592 = make_signed_type (HOST_BITS_PER_WIDE_INT * 2);
2593 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2594 widest_integer_literal_type_node));
2595
2596 widest_unsigned_literal_type_node
2597 = make_unsigned_type (HOST_BITS_PER_WIDE_INT * 2);
2598 pushdecl (build_decl (TYPE_DECL, NULL_TREE,
2599 widest_unsigned_literal_type_node));
2600
2601 /* `unsigned long' is the standard type for sizeof.
2602 Note that stddef.h uses `unsigned long',
2603 and this must agree, even if long and int are the same size. */
2604 size_type_node =
2605 TREE_TYPE (identifier_global_value (get_identifier (SIZE_TYPE)));
2606 signed_size_type_node = signed_type (size_type_node);
2607 if (flag_traditional)
2608 size_type_node = signed_size_type_node;
2609 set_sizetype (size_type_node);
2610
2611 build_common_tree_nodes_2 (flag_short_double);
2612
2613 record_builtin_type (RID_FLOAT, NULL, float_type_node);
2614 record_builtin_type (RID_DOUBLE, NULL, double_type_node);
2615 record_builtin_type (RID_MAX, "long double", long_double_type_node);
2616
2617 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"),
2618 complex_integer_type_node));
2619 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"),
2620 complex_float_type_node));
2621 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"),
2622 complex_double_type_node));
2623 pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"),
2624 complex_long_double_type_node));
2625
2626 /* Types which are common to the fortran compiler and libf2c. When
2627 changing these, you also need to be concerned with f/com.h. */
2628
2629 if (TYPE_PRECISION (float_type_node)
2630 == TYPE_PRECISION (long_integer_type_node))
2631 {
2632 g77_integer_type_node = long_integer_type_node;

--- 5 unchanged lines hidden (view full) ---

2638 g77_integer_type_node = integer_type_node;
2639 g77_uinteger_type_node = unsigned_type_node;
2640 }
2641 else
2642 g77_integer_type_node = g77_uinteger_type_node = NULL_TREE;
2643
2644 if (g77_integer_type_node != NULL_TREE)
2645 {
2646 pushdecl (build_decl (TYPE_DECL,
2647 get_identifier ("__g77_integer"),
2648 g77_integer_type_node));
2649 pushdecl (build_decl (TYPE_DECL,
2650 get_identifier ("__g77_uinteger"),
2651 g77_uinteger_type_node));
2652 }
2653
2654 if (TYPE_PRECISION (float_type_node) * 2
2655 == TYPE_PRECISION (long_integer_type_node))
2656 {
2657 g77_longint_type_node = long_integer_type_node;
2658 g77_ulongint_type_node = long_unsigned_type_node;
2659 }
2660 else if (TYPE_PRECISION (float_type_node) * 2
2661 == TYPE_PRECISION (long_long_integer_type_node))
2662 {
2663 g77_longint_type_node = long_long_integer_type_node;
2664 g77_ulongint_type_node = long_long_unsigned_type_node;
2665 }
2666 else
2667 g77_longint_type_node = g77_ulongint_type_node = NULL_TREE;
2668
2669 if (g77_longint_type_node != NULL_TREE)
2670 {
2671 pushdecl (build_decl (TYPE_DECL,
2672 get_identifier ("__g77_longint"),
2673 g77_longint_type_node));
2674 pushdecl (build_decl (TYPE_DECL,
2675 get_identifier ("__g77_ulongint"),
2676 g77_ulongint_type_node));
2677 }
2678
2679 record_builtin_type (RID_VOID, NULL, void_type_node);
2680
2681 void_zero_node = build_int_2 (0, 0);
2682 TREE_TYPE (void_zero_node) = void_type_node;
2683
2684 void_list_node = build_void_list_node ();

--- 15 unchanged lines hidden (view full) ---

2700 int_array_type_node
2701 = build_array_type (integer_type_node, array_domain_type);
2702
2703 string_type_node = build_pointer_type (char_type_node);
2704 const_string_type_node
2705 = build_pointer_type (build_qualified_type
2706 (char_type_node, TYPE_QUAL_CONST));
2707
2708 traditional_ptr_type_node = ((flag_traditional &&
2709 c_language != clk_cplusplus)
2710 ? string_type_node : ptr_type_node);
2711 traditional_cptr_type_node = ((flag_traditional &&
2712 c_language != clk_cplusplus)
2713 ? const_string_type_node : const_ptr_type_node);
2714
2715 (*targetm.init_builtins) ();
2716
2717 /* This is special for C++ so functions can be overloaded. */
2718 wchar_type_node = get_identifier (flag_short_wchar
2719 ? "short unsigned int"
2720 : WCHAR_TYPE);
2721 wchar_type_node = TREE_TYPE (identifier_global_value (wchar_type_node));
2722 wchar_type_size = TYPE_PRECISION (wchar_type_node);
2723 if (c_language == clk_cplusplus)
2724 {
2725 if (TREE_UNSIGNED (wchar_type_node))
2726 wchar_type_node = make_unsigned_type (wchar_type_size);
2727 else
2728 wchar_type_node = make_signed_type (wchar_type_size);
2729 record_builtin_type (RID_WCHAR, "wchar_t", wchar_type_node);
2730 }
2731 else
2732 {
2733 signed_wchar_type_node = signed_type (wchar_type_node);
2734 unsigned_wchar_type_node = unsigned_type (wchar_type_node);
2735 }
2736
2737 /* This is for wide string constants. */
2738 wchar_array_type_node
2739 = build_array_type (wchar_type_node, array_domain_type);
2740
2741 wint_type_node =
2742 TREE_TYPE (identifier_global_value (get_identifier (WINT_TYPE)));
2743
2744 intmax_type_node =
2745 TREE_TYPE (identifier_global_value (get_identifier (INTMAX_TYPE)));
2746 uintmax_type_node =
2747 TREE_TYPE (identifier_global_value (get_identifier (UINTMAX_TYPE)));
2748
2749 default_function_type = build_function_type (integer_type_node, NULL_TREE);
2750 ptrdiff_type_node
2751 = TREE_TYPE (identifier_global_value (get_identifier (PTRDIFF_TYPE)));
2752 unsigned_ptrdiff_type_node = unsigned_type (ptrdiff_type_node);
2753
2754 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_va_list"),
2755 va_list_type_node));
2756
2757 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_ptrdiff_t"),
2758 ptrdiff_type_node));
2759
2760 pushdecl (build_decl (TYPE_DECL, get_identifier ("__builtin_size_t"),
2761 sizetype));
2762
2763 if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
2764 {
2765 va_list_arg_type_node = va_list_ref_type_node =
2766 build_pointer_type (TREE_TYPE (va_list_type_node));
2767 }
2768 else
2769 {
2770 va_list_arg_type_node = va_list_type_node;
2771 va_list_ref_type_node = build_reference_type (va_list_type_node);
2772 }
2773
2774 traditional_len_type_node = ((flag_traditional &&
2775 c_language != clk_cplusplus)
2776 ? integer_type_node : sizetype);
2777
2778#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
2779 builtin_types[(int) ENUM] = VALUE;
2780#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
2781 builtin_types[(int) ENUM] \
2782 = build_function_type (builtin_types[(int) RETURN], \
2783 void_list_node);
2784#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
2785 builtin_types[(int) ENUM] \

--- 49 unchanged lines hidden (view full) ---

2835 builtin_types[(int) ENUM] \
2836 = build_function_type \
2837 (builtin_types[(int) RETURN], \
2838 tree_cons (NULL_TREE, \
2839 builtin_types[(int) ARG1], \
2840 tree_cons (NULL_TREE, \
2841 builtin_types[(int) ARG2], \
2842 NULL_TREE)));
2843#define DEF_POINTER_TYPE(ENUM, TYPE) \
2844 builtin_types[(int) ENUM] \
2845 = build_pointer_type (builtin_types[(int) TYPE]);
2846#include "builtin-types.def"
2847#undef DEF_PRIMITIVE_TYPE
2848#undef DEF_FUNCTION_TYPE_1
2849#undef DEF_FUNCTION_TYPE_2
2850#undef DEF_FUNCTION_TYPE_3
2851#undef DEF_FUNCTION_TYPE_4
2852#undef DEF_FUNCTION_TYPE_VAR_0
2853#undef DEF_FUNCTION_TYPE_VAR_1
2854#undef DEF_POINTER_TYPE
2855
2856#define DEF_BUILTIN(ENUM, NAME, CLASS, \
2857 TYPE, LIBTYPE, BOTH_P, FALLBACK_P, NONANSI_P) \
2858 if (NAME) \
2859 { \
2860 tree decl; \
2861 \
2862 if (strncmp (NAME, "__builtin_", strlen ("__builtin_")) != 0) \
2863 abort (); \
2864 \
2865 if (!BOTH_P) \
2866 decl = builtin_function (NAME, builtin_types[TYPE], ENUM, \
2867 CLASS, \
2868 (FALLBACK_P \
2869 ? (NAME + strlen ("__builtin_")) \
2870 : NULL)); \
2871 else \
2872 decl = builtin_function_2 (NAME, \
2873 NAME + strlen ("__builtin_"), \
2874 builtin_types[TYPE], \
2875 builtin_types[LIBTYPE], \
2876 ENUM, \
2877 CLASS, \
2878 FALLBACK_P, \
2879 NONANSI_P, \
2880 /*noreturn_p=*/0); \
2881 \
2882 built_in_decls[(int) ENUM] = decl; \
2883 }
2884#include "builtins.def"
2885#undef DEF_BUILTIN
2886
2887 /* Declare _exit and _Exit just to mark them as non-returning. */
2888 builtin_function_2 (NULL, "_exit", NULL_TREE,
2889 builtin_types[BT_FN_VOID_INT],
2890 0, NOT_BUILT_IN, 0, 1, 1);
2891 builtin_function_2 (NULL, "_Exit", NULL_TREE,
2892 builtin_types[BT_FN_VOID_INT],
2893 0, NOT_BUILT_IN, 0, !flag_isoc99, 1);
2894
2895 /* Declare these functions non-returning
2896 to avoid spurious "control drops through" warnings. */
2897 builtin_function_2 (NULL, "abort",
2898 NULL_TREE, ((c_language == clk_cplusplus)
2899 ? builtin_types[BT_FN_VOID]
2900 : builtin_types[BT_FN_VOID_VAR]),
2901 0, NOT_BUILT_IN, 0, 0, 1);
2902
2903 builtin_function_2 (NULL, "exit",
2904 NULL_TREE, ((c_language == clk_cplusplus)
2905 ? builtin_types[BT_FN_VOID_INT]
2906 : builtin_types[BT_FN_VOID_VAR]),
2907 0, NOT_BUILT_IN, 0, 0, 1);
2908
2909 main_identifier_node = get_identifier ("main");
2910
2911 /* ??? Perhaps there's a better place to do this. But it is related
2912 to __builtin_va_arg, so it isn't that off-the-wall. */
2913 lang_type_promotes_to = simple_type_promotes_to;
2914}
2915
2916tree
2917build_va_arg (expr, type)
2918 tree expr, type;
2919{
2920 return build1 (VA_ARG_EXPR, type, expr);
2921}

--- 50 unchanged lines hidden (view full) ---

2972 is an __builtin_-prefixed name; NAME is the ordinary name; one or both
2973 of these may be NULL (though both being NULL is useless).
2974 BUILTIN_TYPE is the type of the __builtin_-prefixed function;
2975 TYPE is the type of the function with the ordinary name. These
2976 may differ if the ordinary name is declared with a looser type to avoid
2977 conflicts with headers. FUNCTION_CODE and CLASS are as for
2978 builtin_function. If LIBRARY_NAME_P is nonzero, NAME is passed as
2979 the LIBRARY_NAME parameter to builtin_function when declaring BUILTIN_NAME.
2980 If NONANSI_P is nonzero, the name NAME is treated as a non-ANSI name; if
2981 NORETURN_P is nonzero, the function is marked as non-returning.
2982 Returns the declaration of BUILTIN_NAME, if any, otherwise
2983 the declaration of NAME. Does not declare NAME if flag_no_builtin,
2984 or if NONANSI_P and flag_no_nonansi_builtin. */
2985
2986static tree
2987builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
2988 class, library_name_p, nonansi_p, noreturn_p)
2989 const char *builtin_name;
2990 const char *name;
2991 tree builtin_type;
2992 tree type;
2993 int function_code;
2994 enum built_in_class class;
2995 int library_name_p;
2996 int nonansi_p;
2997 int noreturn_p;
2998{
2999 tree bdecl = NULL_TREE;
3000 tree decl = NULL_TREE;
3001 if (builtin_name != 0)
3002 {
3003 bdecl = builtin_function (builtin_name, builtin_type, function_code,
3004 class, library_name_p ? name : NULL);
3005 if (noreturn_p)
3006 {
3007 TREE_THIS_VOLATILE (bdecl) = 1;
3008 TREE_SIDE_EFFECTS (bdecl) = 1;
3009 }
3010 }
3011 if (name != 0 && !flag_no_builtin && !builtin_function_disabled_p (name)
3012 && !(nonansi_p && flag_no_nonansi_builtin))
3013 {
3014 decl = builtin_function (name, type, function_code, class, NULL);
3015 if (nonansi_p)
3016 DECL_BUILT_IN_NONANSI (decl) = 1;
3017 if (noreturn_p)
3018 {
3019 TREE_THIS_VOLATILE (decl) = 1;
3020 TREE_SIDE_EFFECTS (decl) = 1;
3021 }
3022 }
3023 return (bdecl != 0 ? bdecl : decl);
3024}
3025
3026/* Nonzero if the type T promotes to int. This is (nearly) the
3027 integral promotions defined in ISO C99 6.3.1.1/2. */
3028
3029bool

--- 19 unchanged lines hidden (view full) ---

3049 case BOOLEAN_TYPE:
3050 return 1;
3051
3052 default:
3053 return 0;
3054 }
3055}
3056
3057/* Given a type, apply default promotions wrt unnamed function arguments
3058 and return the new type. Return NULL_TREE if no change. */
3059/* ??? There is a function of the same name in the C++ front end that
3060 does something similar, but is more thorough and does not return NULL
3061 if no change. We could perhaps share code, but it would make the
3062 self_promoting_type property harder to identify. */
3063
3064tree
3065simple_type_promotes_to (type)
3066 tree type;
3067{
3068 if (TYPE_MAIN_VARIANT (type) == float_type_node)
3069 return double_type_node;
3070
3071 if (c_promoting_integer_type_p (type))
3072 {
3073 /* Traditionally, unsignedness is preserved in default promotions.
3074 Also preserve unsignedness if not really getting any wider. */
3075 if (TREE_UNSIGNED (type)
3076 && (flag_traditional
3077 || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
3078 return unsigned_type_node;
3079 return integer_type_node;
3080 }
3081
3082 return NULL_TREE;
3083}
3084
3085/* Return 1 if PARMS specifies a fixed number of parameters
3086 and none of their types is affected by default promotions. */
3087
3088int
3089self_promoting_args_p (parms)
3090 tree parms;
3091{
3092 tree t;

--- 24 unchanged lines hidden (view full) ---

3117 tree type;
3118{
3119 while (TREE_CODE (type) == ARRAY_TYPE)
3120 type = TREE_TYPE (type);
3121
3122 return type;
3123}
3124
3125/* Recognize certain built-in functions so we can make tree-codes
3126 other than CALL_EXPR. We do this when it enables fold-const.c
3127 to do something useful. */
3128/* ??? By rights this should go in builtins.c, but only C and C++
3129 implement build_{binary,unary}_op. Not exactly sure what bits
3130 of functionality are actually needed from those functions, or
3131 where the similar functionality exists in the other front ends. */
3132
3133tree
3134expand_tree_builtin (function, params, coerced_params)
3135 tree function, params, coerced_params;
3136{
3137 enum tree_code code;
3138
3139 if (DECL_BUILT_IN_CLASS (function) != BUILT_IN_NORMAL)
3140 return NULL_TREE;
3141
3142 switch (DECL_FUNCTION_CODE (function))
3143 {
3144 case BUILT_IN_ABS:
3145 case BUILT_IN_LABS:
3146 case BUILT_IN_LLABS:

--- 22 unchanged lines hidden (view full) ---

3169 case BUILT_IN_CIMAG:
3170 case BUILT_IN_CIMAGF:
3171 case BUILT_IN_CIMAGL:
3172 if (coerced_params == 0)
3173 return integer_zero_node;
3174 return build_unary_op (IMAGPART_EXPR, TREE_VALUE (coerced_params), 0);
3175
3176 case BUILT_IN_ISGREATER:
3177 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3178 code = UNLE_EXPR;
3179 else
3180 code = LE_EXPR;
3181 goto unordered_cmp;
3182
3183 case BUILT_IN_ISGREATEREQUAL:
3184 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3185 code = UNLT_EXPR;
3186 else
3187 code = LT_EXPR;
3188 goto unordered_cmp;
3189
3190 case BUILT_IN_ISLESS:
3191 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3192 code = UNGE_EXPR;
3193 else
3194 code = GE_EXPR;
3195 goto unordered_cmp;
3196
3197 case BUILT_IN_ISLESSEQUAL:
3198 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3199 code = UNGT_EXPR;
3200 else
3201 code = GT_EXPR;
3202 goto unordered_cmp;
3203
3204 case BUILT_IN_ISLESSGREATER:
3205 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT)
3206 code = UNEQ_EXPR;
3207 else
3208 code = EQ_EXPR;
3209 goto unordered_cmp;
3210
3211 case BUILT_IN_ISUNORDERED:
3212 if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT)
3213 return integer_zero_node;
3214 code = UNORDERED_EXPR;
3215 goto unordered_cmp;
3216
3217 unordered_cmp:
3218 {
3219 tree arg0, arg1;
3220
3221 if (params == 0
3222 || TREE_CHAIN (params) == 0)
3223 {
3224 error ("too few arguments to function `%s'",
3225 IDENTIFIER_POINTER (DECL_NAME (function)));
3226 return error_mark_node;
3227 }
3228 else if (TREE_CHAIN (TREE_CHAIN (params)) != 0)
3229 {
3230 error ("too many arguments to function `%s'",
3231 IDENTIFIER_POINTER (DECL_NAME (function)));
3232 return error_mark_node;
3233 }
3234
3235 arg0 = TREE_VALUE (params);
3236 arg1 = TREE_VALUE (TREE_CHAIN (params));
3237 arg0 = build_binary_op (code, arg0, arg1, 0);
3238 if (code != UNORDERED_EXPR)
3239 arg0 = build_unary_op (TRUTH_NOT_EXPR, arg0, 0);
3240 return arg0;
3241 }
3242 break;
3243
3244 default:
3245 break;
3246 }
3247
3248 return NULL_TREE;
3249}
3250
3251/* Returns non-zero if CODE is the code for a statement. */
3252
3253int
3254statement_code_p (code)
3255 enum tree_code code;
3256{
3257 switch (code)
3258 {
3259 case CLEANUP_STMT:

--- 301 unchanged lines hidden (view full) ---

3561 /* The current function in not necessarily uninlinable.
3562 Computed gotos are incompatible with inlining, but the value
3563 here could be used only in a diagnostic, for example. */
3564 }
3565
3566 return result;
3567}
3568
3569/* Mark P (a stmt_tree) for GC. The use of a `void *' for the
3570 parameter allows this function to be used as a GC-marking
3571 function. */
3572
3573void
3574mark_stmt_tree (p)
3575 void *p;
3576{
3577 stmt_tree st = (stmt_tree) p;
3578
3579 ggc_mark_tree (st->x_last_stmt);
3580 ggc_mark_tree (st->x_last_expr_type);
3581}
3582
3583/* Mark LD for GC. */
3584
3585void
3586c_mark_lang_decl (c)
3587 struct c_lang_decl *c ATTRIBUTE_UNUSED;
3588{
3589}
3590
3591/* Mark F for GC. */
3592
3593void
3594mark_c_language_function (f)
3595 struct language_function *f;
3596{
3597 if (!f)
3598 return;
3599
3600 mark_stmt_tree (&f->x_stmt_tree);
3601 ggc_mark_tree (f->x_scope_stmt_stack);
3602}
3603
3604/* Hook used by expand_expr to expand language-specific tree codes. */
3605
3606rtx
3607c_expand_expr (exp, target, tmode, modifier)
3608 tree exp;
3609 rtx target;
3610 enum machine_mode tmode;
3611 enum expand_modifier modifier;
3612{
3613 switch (TREE_CODE (exp))
3614 {
3615 case STMT_EXPR:
3616 {
3617 tree rtl_expr;
3618 rtx result;
3619 bool preserve_result = false;

--- 124 unchanged lines hidden (view full) ---

3744
3745 /* Assume everything else is safe. */
3746 return 1;
3747}
3748
3749/* Hook used by unsafe_for_reeval to handle language-specific tree codes. */
3750
3751int
3752c_unsafe_for_reeval (exp)
3753 tree exp;
3754{
3755 /* Statement expressions may not be reevaluated, likewise compound
3756 literals. */
3757 if (TREE_CODE (exp) == STMT_EXPR
3758 || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
3759 return 2;
3760

--- 8 unchanged lines hidden (view full) ---

3769 tree exp;
3770{
3771 if (TREE_CODE (exp) == COMPOUND_LITERAL_EXPR
3772 && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
3773 return 1;
3774 return 0;
3775}
3776
3777/* Tree code classes. */
3778
3779#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
3780
3781static const char c_tree_code_type[] = {
3782 'x',
3783#include "c-common.def"
3784};
3785#undef DEFTREECODE
3786
3787/* Table indexed by tree code giving number of expression
3788 operands beyond the fixed part of the node structure.
3789 Not used for types or decls. */
3790
3791#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
3792
3793static const int c_tree_code_length[] = {
3794 0,
3795#include "c-common.def"
3796};
3797#undef DEFTREECODE
3798
3799/* Names of tree components.
3800 Used for printing out the tree and error messages. */
3801#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
3802
3803static const char *const c_tree_code_name[] = {
3804 "@@dummy",
3805#include "c-common.def"
3806};
3807#undef DEFTREECODE
3808
3809/* Adds the tree codes specific to the C front end to the list of all
3810 tree codes. */
3811
3812void
3813add_c_tree_codes ()
3814{
3815 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
3816 c_tree_code_type,
3817 (int) LAST_C_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE);
3818 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
3819 c_tree_code_length,
3820 (LAST_C_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
3821 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
3822 c_tree_code_name,
3823 (LAST_C_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
3824 lang_unsafe_for_reeval = c_unsafe_for_reeval;
3825}
3826
3827#define CALLED_AS_BUILT_IN(NODE) \
3828 (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
3829
3830static rtx
3831c_expand_builtin (exp, target, tmode, modifier)
3832 tree exp;
3833 rtx target;
3834 enum machine_mode tmode;

--- 172 unchanged lines hidden (view full) ---

4007 {
4008 /* Create a NULL-terminated string that's one char shorter
4009 than the original, stripping off the trailing '\n'. */
4010 const int newlen = TREE_STRING_LENGTH (stripped_string) - 1;
4011 char *newstr = (char *) alloca (newlen);
4012 memcpy (newstr, TREE_STRING_POINTER (stripped_string), newlen - 1);
4013 newstr[newlen - 1] = 0;
4014
4015 arglist = combine_strings (build_string (newlen, newstr));
4016 arglist = build_tree_list (NULL_TREE, arglist);
4017 fn = fn_puts;
4018 }
4019 else
4020 /* We'd like to arrange to call fputs(string) here, but we
4021 need stdout and don't have a way to get it ... yet. */
4022 return 0;
4023 }

--- 122 unchanged lines hidden (view full) ---

4146 break;
4147 default:
4148 abort ();
4149 }
4150 TREE_SIDE_EFFECTS (val) = 1;
4151 return val;
4152}
4153
4154/* Handle C and C++ default attributes. */
4155
4156enum built_in_attribute
4157{
4158#define DEF_ATTR_NULL_TREE(ENUM) ENUM,
4159#define DEF_ATTR_INT(ENUM, VALUE) ENUM,
4160#define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
4161#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
4162#define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No entry needed in enum. */
4163#include "builtin-attrs.def"
4164#undef DEF_ATTR_NULL_TREE
4165#undef DEF_ATTR_INT
4166#undef DEF_ATTR_IDENT
4167#undef DEF_ATTR_TREE_LIST
4168#undef DEF_FN_ATTR
4169 ATTR_LAST
4170};
4171
4172static tree built_in_attributes[(int) ATTR_LAST];
4173
4174static bool c_attrs_initialized = false;
4175
4176static void c_init_attributes PARAMS ((void));
4177
4178/* Common initialization before parsing options. */
4179void
4180c_common_init_options (lang)
4181 enum c_language_kind lang;
4182{
4183 c_language = lang;
4184 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89:
4185 lang == clk_cplusplus ? CLK_GNUCXX: CLK_OBJC);
4186
4187 /* Mark as "unspecified" (see c_common_post_options). */
4188 flag_bounds_check = -1;
4189}
4190
4191/* Post-switch processing. */
4192void
4193c_common_post_options ()
4194{
4195 cpp_post_options (parse_in);
4196
4197 flag_inline_trees = 1;
4198
4199 /* Use tree inlining if possible. Function instrumentation is only
4200 done in the RTL level, so we disable tree inlining. */
4201 if (! flag_instrument_function_entry_exit)
4202 {
4203 if (!flag_no_inline)
4204 flag_no_inline = 1;
4205 if (flag_inline_functions)
4206 {
4207 flag_inline_trees = 2;
4208 flag_inline_functions = 0;
4209 }
4210 }
4211
4212 /* If still "unspecified", make it match -fbounded-pointers. */
4213 if (flag_bounds_check == -1)
4214 flag_bounds_check = flag_bounded_pointers;
4215
4216 /* Special format checking options don't work without -Wformat; warn if
4217 they are used. */
4218 if (warn_format_y2k && !warn_format)
4219 warning ("-Wformat-y2k ignored without -Wformat");
4220 if (warn_format_extra_args && !warn_format)
4221 warning ("-Wformat-extra-args ignored without -Wformat");
4222 if (warn_format_nonliteral && !warn_format)
4223 warning ("-Wformat-nonliteral ignored without -Wformat");
4224 if (warn_format_security && !warn_format)
4225 warning ("-Wformat-security ignored without -Wformat");
4226 if (warn_missing_format_attribute && !warn_format)
4227 warning ("-Wmissing-format-attribute ignored without -Wformat");
4228
4229 /* If an error has occurred in cpplib, note it so we fail
4230 immediately. */
4231 errorcount += cpp_errors (parse_in);
4232}
4233
4234/* Front end initialization common to C, ObjC and C++. */
4235const char *
4236c_common_init (filename)
4237 const char *filename;
4238{
4239 /* Do this before initializing pragmas, as then cpplib's hash table
4240 has been set up. */
4241 filename = init_c_lex (filename);
4242
4243 init_pragma ();
4244
4245 if (!c_attrs_initialized)
4246 c_init_attributes ();
4247
4248 return filename;
4249}
4250
4251/* Common finish hook for the C, ObjC and C++ front ends. */
4252void
4253c_common_finish ()
4254{
4255 cpp_finish (parse_in);
4256
4257 /* For performance, avoid tearing down cpplib's internal structures.
4258 Call cpp_errors () instead of cpp_destroy (). */
4259 errorcount += cpp_errors (parse_in);
4260}
4261
4262static void
4263c_init_attributes ()
4264{
4265 /* Fill in the built_in_attributes array. */
4266#define DEF_ATTR_NULL_TREE(ENUM) \
4267 built_in_attributes[(int) ENUM] = NULL_TREE;

--- 8 unchanged lines hidden (view full) ---

4276 built_in_attributes[(int) CHAIN]);
4277#define DEF_FN_ATTR(NAME, ATTRS, PREDICATE) /* No initialization needed. */
4278#include "builtin-attrs.def"
4279#undef DEF_ATTR_NULL_TREE
4280#undef DEF_ATTR_INT
4281#undef DEF_ATTR_IDENT
4282#undef DEF_ATTR_TREE_LIST
4283#undef DEF_FN_ATTR
4284 ggc_add_tree_root (built_in_attributes, (int) ATTR_LAST);
4285 c_attrs_initialized = true;
4286}
4287
4288/* Depending on the name of DECL, apply default attributes to it. */
4289
4290void
4291c_common_insert_default_attributes (decl)
4292 tree decl;

--- 27 unchanged lines hidden (view full) ---

4320 tree name, decl;
4321{
4322 warning ("declaration of `%s' shadows %s", IDENTIFIER_POINTER (name), msgid);
4323 warning_with_file_and_line (DECL_SOURCE_FILE (decl),
4324 DECL_SOURCE_LINE (decl),
4325 "shadowed declaration is here");
4326}
4327