comparison gcc/tree.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children d34655255c78 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Language-independent node constructors for parse phase of GNU compiler. 1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. 2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
64 #include "selftest.h" 64 #include "selftest.h"
65 #include "stringpool.h" 65 #include "stringpool.h"
66 #include "attribs.h" 66 #include "attribs.h"
67 #include "rtl.h" 67 #include "rtl.h"
68 #include "regs.h" 68 #include "regs.h"
69 #include "tree-vector-builder.h"
69 70
70 /* Tree code classes. */ 71 /* Tree code classes. */
71 72
72 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, 73 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
73 #define END_OF_BASE_TREE_CODES tcc_exceptional, 74 #define END_OF_BASE_TREE_CODES tcc_exceptional,
126 /* obstack.[ch] explicitly declined to prototype this. */ 127 /* obstack.[ch] explicitly declined to prototype this. */
127 extern int _obstack_allocated_p (struct obstack *h, void *obj); 128 extern int _obstack_allocated_p (struct obstack *h, void *obj);
128 129
129 /* Statistics-gathering stuff. */ 130 /* Statistics-gathering stuff. */
130 131
131 static int tree_code_counts[MAX_TREE_CODES]; 132 static uint64_t tree_code_counts[MAX_TREE_CODES];
132 int tree_node_counts[(int) all_kinds]; 133 uint64_t tree_node_counts[(int) all_kinds];
133 int tree_node_sizes[(int) all_kinds]; 134 uint64_t tree_node_sizes[(int) all_kinds];
134 135
135 /* Keep in sync with tree.h:enum tree_node_kind. */ 136 /* Keep in sync with tree.h:enum tree_node_kind. */
136 static const char * const tree_node_kind_names[] = { 137 static const char * const tree_node_kind_names[] = {
137 "decls", 138 "decls",
138 "types", 139 "types",
200 static hashval_t hash (tree t); 201 static hashval_t hash (tree t);
201 static bool equal (tree x, tree y); 202 static bool equal (tree x, tree y);
202 }; 203 };
203 204
204 static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table; 205 static GTY ((cache)) hash_table<int_cst_hasher> *int_cst_hash_table;
206
207 /* Class and variable for making sure that there is a single POLY_INT_CST
208 for a given value. */
209 struct poly_int_cst_hasher : ggc_cache_ptr_hash<tree_node>
210 {
211 typedef std::pair<tree, const poly_wide_int *> compare_type;
212 static hashval_t hash (tree t);
213 static bool equal (tree x, const compare_type &y);
214 };
215
216 static GTY ((cache)) hash_table<poly_int_cst_hasher> *poly_int_cst_hash_table;
205 217
206 /* Hash table for optimization flags and target option flags. Use the same 218 /* Hash table for optimization flags and target option flags. Use the same
207 hash table for both sets of options. Nodes for building the current 219 hash table for both sets of options. Nodes for building the current
208 optimization and target option nodes. The assumption is most of the time 220 optimization and target option nodes. The assumption is most of the time
209 the options created will already be in the hash table, so we avoid 221 the options created will already be in the hash table, so we avoid
321 0, /* OMP_CLAUSE_SIMD */ 333 0, /* OMP_CLAUSE_SIMD */
322 1, /* OMP_CLAUSE_HINT */ 334 1, /* OMP_CLAUSE_HINT */
323 0, /* OMP_CLAUSE_DEFALTMAP */ 335 0, /* OMP_CLAUSE_DEFALTMAP */
324 1, /* OMP_CLAUSE__SIMDUID_ */ 336 1, /* OMP_CLAUSE__SIMDUID_ */
325 0, /* OMP_CLAUSE__SIMT_ */ 337 0, /* OMP_CLAUSE__SIMT_ */
326 1, /* OMP_CLAUSE__CILK_FOR_COUNT_ */
327 0, /* OMP_CLAUSE_INDEPENDENT */ 338 0, /* OMP_CLAUSE_INDEPENDENT */
328 1, /* OMP_CLAUSE_WORKER */ 339 1, /* OMP_CLAUSE_WORKER */
329 1, /* OMP_CLAUSE_VECTOR */ 340 1, /* OMP_CLAUSE_VECTOR */
330 1, /* OMP_CLAUSE_NUM_GANGS */ 341 1, /* OMP_CLAUSE_NUM_GANGS */
331 1, /* OMP_CLAUSE_NUM_WORKERS */ 342 1, /* OMP_CLAUSE_NUM_WORKERS */
332 1, /* OMP_CLAUSE_VECTOR_LENGTH */ 343 1, /* OMP_CLAUSE_VECTOR_LENGTH */
333 3, /* OMP_CLAUSE_TILE */ 344 3, /* OMP_CLAUSE_TILE */
334 2, /* OMP_CLAUSE__GRIDDIM_ */ 345 2, /* OMP_CLAUSE__GRIDDIM_ */
346 0, /* OMP_CLAUSE_IF_PRESENT */
347 0, /* OMP_CLAUSE_FINALIZE */
335 }; 348 };
336 349
337 const char * const omp_clause_code_name[] = 350 const char * const omp_clause_code_name[] =
338 { 351 {
339 "error_clause", 352 "error_clause",
393 "simd", 406 "simd",
394 "hint", 407 "hint",
395 "defaultmap", 408 "defaultmap",
396 "_simduid_", 409 "_simduid_",
397 "_simt_", 410 "_simt_",
398 "_Cilk_for_count_",
399 "independent", 411 "independent",
400 "worker", 412 "worker",
401 "vector", 413 "vector",
402 "num_gangs", 414 "num_gangs",
403 "num_workers", 415 "num_workers",
404 "vector_length", 416 "vector_length",
405 "tile", 417 "tile",
406 "_griddim_" 418 "_griddim_",
419 "if_present",
420 "finalize",
407 }; 421 };
408 422
409 423
410 /* Return the tree node structure used by tree code CODE. */ 424 /* Return the tree node structure used by tree code CODE. */
411 425
458 switch (code) 472 switch (code)
459 { 473 {
460 /* tcc_constant cases. */ 474 /* tcc_constant cases. */
461 case VOID_CST: return TS_TYPED; 475 case VOID_CST: return TS_TYPED;
462 case INTEGER_CST: return TS_INT_CST; 476 case INTEGER_CST: return TS_INT_CST;
477 case POLY_INT_CST: return TS_POLY_INT_CST;
463 case REAL_CST: return TS_REAL_CST; 478 case REAL_CST: return TS_REAL_CST;
464 case FIXED_CST: return TS_FIXED_CST; 479 case FIXED_CST: return TS_FIXED_CST;
465 case COMPLEX_CST: return TS_COMPLEX; 480 case COMPLEX_CST: return TS_COMPLEX;
466 case VECTOR_CST: return TS_VECTOR; 481 case VECTOR_CST: return TS_VECTOR;
467 case STRING_CST: return TS_STRING; 482 case STRING_CST: return TS_STRING;
515 MARK_TS_BASE (code); 530 MARK_TS_BASE (code);
516 break; 531 break;
517 532
518 case TS_COMMON: 533 case TS_COMMON:
519 case TS_INT_CST: 534 case TS_INT_CST:
535 case TS_POLY_INT_CST:
520 case TS_REAL_CST: 536 case TS_REAL_CST:
521 case TS_FIXED_CST: 537 case TS_FIXED_CST:
522 case TS_VECTOR: 538 case TS_VECTOR:
523 case TS_STRING: 539 case TS_STRING:
524 case TS_COMPLEX: 540 case TS_COMPLEX:
648 value_expr_for_decl 664 value_expr_for_decl
649 = hash_table<tree_decl_map_cache_hasher>::create_ggc (512); 665 = hash_table<tree_decl_map_cache_hasher>::create_ggc (512);
650 666
651 int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024); 667 int_cst_hash_table = hash_table<int_cst_hasher>::create_ggc (1024);
652 668
669 poly_int_cst_hash_table = hash_table<poly_int_cst_hasher>::create_ggc (64);
670
653 int_cst_node = make_int_cst (1, 1); 671 int_cst_node = make_int_cst (1, 1);
654 672
655 cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64); 673 cl_option_hash_table = hash_table<cl_option_hasher>::create_ggc (64);
656 674
657 cl_optimization_node = make_node (OPTIMIZATION_NODE); 675 cl_optimization_node = make_node (OPTIMIZATION_NODE);
670 decl_assembler_name (tree decl) 688 decl_assembler_name (tree decl)
671 { 689 {
672 if (!DECL_ASSEMBLER_NAME_SET_P (decl)) 690 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
673 lang_hooks.set_decl_assembler_name (decl); 691 lang_hooks.set_decl_assembler_name (decl);
674 return DECL_ASSEMBLER_NAME_RAW (decl); 692 return DECL_ASSEMBLER_NAME_RAW (decl);
693 }
694
695 /* The DECL_ASSEMBLER_NAME_RAW of DECL is being explicitly set to NAME
696 (either of which may be NULL). Inform the FE, if this changes the
697 name. */
698
699 void
700 overwrite_decl_assembler_name (tree decl, tree name)
701 {
702 if (DECL_ASSEMBLER_NAME_RAW (decl) != name)
703 lang_hooks.overwrite_decl_assembler_name (decl, name);
675 } 704 }
676 705
677 /* When the target supports COMDAT groups, this indicates which group the 706 /* When the target supports COMDAT groups, this indicates which group the
678 DECL is associated with. This can be either an IDENTIFIER_NODE or a 707 DECL is associated with. This can be either an IDENTIFIER_NODE or a
679 decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */ 708 decl, in which case its DECL_ASSEMBLER_NAME identifies the group. */
800 case ARRAY_TYPE: 829 case ARRAY_TYPE:
801 case RECORD_TYPE: 830 case RECORD_TYPE:
802 case UNION_TYPE: 831 case UNION_TYPE:
803 case QUAL_UNION_TYPE: 832 case QUAL_UNION_TYPE:
804 case VOID_TYPE: 833 case VOID_TYPE:
805 case POINTER_BOUNDS_TYPE:
806 case FUNCTION_TYPE: 834 case FUNCTION_TYPE:
807 case METHOD_TYPE: 835 case METHOD_TYPE:
808 case LANG_TYPE: return sizeof (tree_type_non_common); 836 case LANG_TYPE: return sizeof (tree_type_non_common);
809 default: 837 default:
810 gcc_checking_assert (code >= NUM_TREE_CODES); 838 gcc_checking_assert (code >= NUM_TREE_CODES);
823 case tcc_constant: /* a constant */ 851 case tcc_constant: /* a constant */
824 switch (code) 852 switch (code)
825 { 853 {
826 case VOID_CST: return sizeof (tree_typed); 854 case VOID_CST: return sizeof (tree_typed);
827 case INTEGER_CST: gcc_unreachable (); 855 case INTEGER_CST: gcc_unreachable ();
856 case POLY_INT_CST: return sizeof (tree_poly_int_cst);
828 case REAL_CST: return sizeof (tree_real_cst); 857 case REAL_CST: return sizeof (tree_real_cst);
829 case FIXED_CST: return sizeof (tree_fixed_cst); 858 case FIXED_CST: return sizeof (tree_fixed_cst);
830 case COMPLEX_CST: return sizeof (tree_complex); 859 case COMPLEX_CST: return sizeof (tree_complex);
831 case VECTOR_CST: return sizeof (tree_vector); 860 case VECTOR_CST: gcc_unreachable ();
832 case STRING_CST: gcc_unreachable (); 861 case STRING_CST: gcc_unreachable ();
833 default: 862 default:
834 gcc_checking_assert (code >= NUM_TREE_CODES); 863 gcc_checking_assert (code >= NUM_TREE_CODES);
835 return lang_hooks.tree_size (code); 864 return lang_hooks.tree_size (code);
836 } 865 }
886 return (sizeof (struct tree_vec) 915 return (sizeof (struct tree_vec)
887 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree)); 916 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
888 917
889 case VECTOR_CST: 918 case VECTOR_CST:
890 return (sizeof (struct tree_vector) 919 return (sizeof (struct tree_vector)
891 + (VECTOR_CST_NELTS (node) - 1) * sizeof (tree)); 920 + (vector_cst_encoded_nelts (node) - 1) * sizeof (tree));
892 921
893 case STRING_CST: 922 case STRING_CST:
894 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1; 923 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
895 924
896 case OMP_CLAUSE: 925 case OMP_CLAUSE:
905 else 934 else
906 return tree_code_size (code); 935 return tree_code_size (code);
907 } 936 }
908 } 937 }
909 938
910 /* Record interesting allocation statistics for a tree node with CODE 939 /* Return tree node kind based on tree CODE. */
911 and LENGTH. */ 940
912 941 static tree_node_kind
913 static void 942 get_stats_node_kind (enum tree_code code)
914 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED,
915 size_t length ATTRIBUTE_UNUSED)
916 { 943 {
917 enum tree_code_class type = TREE_CODE_CLASS (code); 944 enum tree_code_class type = TREE_CODE_CLASS (code);
918 tree_node_kind kind;
919
920 if (!GATHER_STATISTICS)
921 return;
922 945
923 switch (type) 946 switch (type)
924 { 947 {
925 case tcc_declaration: /* A decl node */ 948 case tcc_declaration: /* A decl node */
926 kind = d_kind; 949 return d_kind;
927 break;
928
929 case tcc_type: /* a type node */ 950 case tcc_type: /* a type node */
930 kind = t_kind; 951 return t_kind;
931 break;
932
933 case tcc_statement: /* an expression with side effects */ 952 case tcc_statement: /* an expression with side effects */
934 kind = s_kind; 953 return s_kind;
935 break;
936
937 case tcc_reference: /* a reference */ 954 case tcc_reference: /* a reference */
938 kind = r_kind; 955 return r_kind;
939 break;
940
941 case tcc_expression: /* an expression */ 956 case tcc_expression: /* an expression */
942 case tcc_comparison: /* a comparison expression */ 957 case tcc_comparison: /* a comparison expression */
943 case tcc_unary: /* a unary arithmetic expression */ 958 case tcc_unary: /* a unary arithmetic expression */
944 case tcc_binary: /* a binary arithmetic expression */ 959 case tcc_binary: /* a binary arithmetic expression */
945 kind = e_kind; 960 return e_kind;
946 break;
947
948 case tcc_constant: /* a constant */ 961 case tcc_constant: /* a constant */
949 kind = c_kind; 962 return c_kind;
950 break;
951
952 case tcc_exceptional: /* something random, like an identifier. */ 963 case tcc_exceptional: /* something random, like an identifier. */
953 switch (code) 964 switch (code)
954 { 965 {
955 case IDENTIFIER_NODE: 966 case IDENTIFIER_NODE:
956 kind = id_kind; 967 return id_kind;
957 break;
958
959 case TREE_VEC: 968 case TREE_VEC:
960 kind = vec_kind; 969 return vec_kind;
961 break;
962
963 case TREE_BINFO: 970 case TREE_BINFO:
964 kind = binfo_kind; 971 return binfo_kind;
965 break;
966
967 case SSA_NAME: 972 case SSA_NAME:
968 kind = ssa_name_kind; 973 return ssa_name_kind;
969 break;
970
971 case BLOCK: 974 case BLOCK:
972 kind = b_kind; 975 return b_kind;
973 break;
974
975 case CONSTRUCTOR: 976 case CONSTRUCTOR:
976 kind = constr_kind; 977 return constr_kind;
977 break;
978
979 case OMP_CLAUSE: 978 case OMP_CLAUSE:
980 kind = omp_clause_kind; 979 return omp_clause_kind;
981 break;
982
983 default: 980 default:
984 kind = x_kind; 981 return x_kind;
985 break;
986 } 982 }
987 break; 983 break;
988
989 case tcc_vl_exp: 984 case tcc_vl_exp:
990 kind = e_kind; 985 return e_kind;
991 break;
992
993 default: 986 default:
994 gcc_unreachable (); 987 gcc_unreachable ();
995 } 988 }
989 }
990
991 /* Record interesting allocation statistics for a tree node with CODE
992 and LENGTH. */
993
994 static void
995 record_node_allocation_statistics (enum tree_code code, size_t length)
996 {
997 if (!GATHER_STATISTICS)
998 return;
999
1000 tree_node_kind kind = get_stats_node_kind (code);
996 1001
997 tree_code_counts[(int) code]++; 1002 tree_code_counts[(int) code]++;
998 tree_node_counts[(int) kind]++; 1003 tree_node_counts[(int) kind]++;
999 tree_node_sizes[(int) kind] += length; 1004 tree_node_sizes[(int) kind] += length;
1000 } 1005 }
1028 TREE_SET_CODE (t, code); 1033 TREE_SET_CODE (t, code);
1029 1034
1030 switch (type) 1035 switch (type)
1031 { 1036 {
1032 case tcc_statement: 1037 case tcc_statement:
1033 TREE_SIDE_EFFECTS (t) = 1; 1038 if (code != DEBUG_BEGIN_STMT)
1039 TREE_SIDE_EFFECTS (t) = 1;
1034 break; 1040 break;
1035 1041
1036 case tcc_declaration: 1042 case tcc_declaration:
1037 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON)) 1043 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
1038 { 1044 {
1128 free_node (tree node) 1134 free_node (tree node)
1129 { 1135 {
1130 enum tree_code code = TREE_CODE (node); 1136 enum tree_code code = TREE_CODE (node);
1131 if (GATHER_STATISTICS) 1137 if (GATHER_STATISTICS)
1132 { 1138 {
1139 enum tree_node_kind kind = get_stats_node_kind (code);
1140
1141 gcc_checking_assert (tree_code_counts[(int) TREE_CODE (node)] != 0);
1142 gcc_checking_assert (tree_node_counts[(int) kind] != 0);
1143 gcc_checking_assert (tree_node_sizes[(int) kind] >= tree_size (node));
1144
1133 tree_code_counts[(int) TREE_CODE (node)]--; 1145 tree_code_counts[(int) TREE_CODE (node)]--;
1134 tree_node_counts[(int) t_kind]--; 1146 tree_node_counts[(int) kind]--;
1135 tree_node_sizes[(int) t_kind] -= tree_size (node); 1147 tree_node_sizes[(int) kind] -= tree_size (node);
1136 } 1148 }
1137 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR)) 1149 if (CODE_CONTAINS_STRUCT (code, TS_CONSTRUCTOR))
1138 vec_free (CONSTRUCTOR_ELTS (node)); 1150 vec_free (CONSTRUCTOR_ELTS (node));
1139 else if (code == BLOCK) 1151 else if (code == BLOCK)
1140 vec_free (BLOCK_NONLOCALIZED_VARS (node)); 1152 vec_free (BLOCK_NONLOCALIZED_VARS (node));
1204 /* The following is so that the debug code for 1216 /* The following is so that the debug code for
1205 the copy is different from the original type. 1217 the copy is different from the original type.
1206 The two statements usually duplicate each other 1218 The two statements usually duplicate each other
1207 (because they clear fields of the same union), 1219 (because they clear fields of the same union),
1208 but the optimizer should catch that. */ 1220 but the optimizer should catch that. */
1209 TYPE_SYMTAB_POINTER (t) = 0;
1210 TYPE_SYMTAB_ADDRESS (t) = 0; 1221 TYPE_SYMTAB_ADDRESS (t) = 0;
1222 TYPE_SYMTAB_DIE (t) = 0;
1211 1223
1212 /* Do not copy the values cache. */ 1224 /* Do not copy the values cache. */
1213 if (TYPE_CACHED_VALUES_P (t)) 1225 if (TYPE_CACHED_VALUES_P (t))
1214 { 1226 {
1215 TYPE_CACHED_VALUES_P (t) = 0; 1227 TYPE_CACHED_VALUES_P (t) = 0;
1300 TREE_INT_CST_ELT (nt, i) = cst.elt (i); 1312 TREE_INT_CST_ELT (nt, i) = cst.elt (i);
1301 TREE_TYPE (nt) = type; 1313 TREE_TYPE (nt) = type;
1302 return nt; 1314 return nt;
1303 } 1315 }
1304 1316
1305 /* Create an INT_CST node with a LOW value sign extended to TYPE. */ 1317 /* Return a new POLY_INT_CST with coefficients COEFFS and type TYPE. */
1306 1318
1307 tree 1319 static tree
1308 build_int_cst (tree type, HOST_WIDE_INT low) 1320 build_new_poly_int_cst (tree type, tree (&coeffs)[NUM_POLY_INT_COEFFS]
1321 CXX_MEM_STAT_INFO)
1322 {
1323 size_t length = sizeof (struct tree_poly_int_cst);
1324 record_node_allocation_statistics (POLY_INT_CST, length);
1325
1326 tree t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1327
1328 TREE_SET_CODE (t, POLY_INT_CST);
1329 TREE_CONSTANT (t) = 1;
1330 TREE_TYPE (t) = type;
1331 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1332 POLY_INT_CST_COEFF (t, i) = coeffs[i];
1333 return t;
1334 }
1335
1336 /* Create a constant tree that contains CST sign-extended to TYPE. */
1337
1338 tree
1339 build_int_cst (tree type, poly_int64 cst)
1309 { 1340 {
1310 /* Support legacy code. */ 1341 /* Support legacy code. */
1311 if (!type) 1342 if (!type)
1312 type = integer_type_node; 1343 type = integer_type_node;
1313 1344
1314 return wide_int_to_tree (type, wi::shwi (low, TYPE_PRECISION (type))); 1345 return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1315 } 1346 }
1316 1347
1317 tree 1348 /* Create a constant tree that contains CST zero-extended to TYPE. */
1318 build_int_cstu (tree type, unsigned HOST_WIDE_INT cst) 1349
1350 tree
1351 build_int_cstu (tree type, poly_uint64 cst)
1319 { 1352 {
1320 return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type))); 1353 return wide_int_to_tree (type, wi::uhwi (cst, TYPE_PRECISION (type)));
1321 } 1354 }
1322 1355
1323 /* Create an INT_CST node with a LOW value sign extended to TYPE. */ 1356 /* Create a constant tree that contains CST sign-extended to TYPE. */
1324 1357
1325 tree 1358 tree
1326 build_int_cst_type (tree type, HOST_WIDE_INT low) 1359 build_int_cst_type (tree type, poly_int64 cst)
1327 { 1360 {
1328 gcc_assert (type); 1361 gcc_assert (type);
1329 return wide_int_to_tree (type, wi::shwi (low, TYPE_PRECISION (type))); 1362 return wide_int_to_tree (type, wi::shwi (cst, TYPE_PRECISION (type)));
1330 } 1363 }
1331 1364
1332 /* Constructs tree in type TYPE from with value given by CST. Signedness 1365 /* Constructs tree in type TYPE from with value given by CST. Signedness
1333 of CST is assumed to be the same as the signedness of TYPE. */ 1366 of CST is assumed to be the same as the signedness of TYPE. */
1334 1367
1352 We return a new tree node for the extended wide_int. The node 1385 We return a new tree node for the extended wide_int. The node
1353 is shared if no overflow flags are set. */ 1386 is shared if no overflow flags are set. */
1354 1387
1355 1388
1356 tree 1389 tree
1357 force_fit_type (tree type, const wide_int_ref &cst, 1390 force_fit_type (tree type, const poly_wide_int_ref &cst,
1358 int overflowable, bool overflowed) 1391 int overflowable, bool overflowed)
1359 { 1392 {
1360 signop sign = TYPE_SIGN (type); 1393 signop sign = TYPE_SIGN (type);
1361 1394
1362 /* If we need to set overflow flags, return a new unshared node. */ 1395 /* If we need to set overflow flags, return a new unshared node. */
1364 { 1397 {
1365 if (overflowed 1398 if (overflowed
1366 || overflowable < 0 1399 || overflowable < 0
1367 || (overflowable > 0 && sign == SIGNED)) 1400 || (overflowable > 0 && sign == SIGNED))
1368 { 1401 {
1369 wide_int tmp = wide_int::from (cst, TYPE_PRECISION (type), sign); 1402 poly_wide_int tmp = poly_wide_int::from (cst, TYPE_PRECISION (type),
1370 tree t = build_new_int_cst (type, tmp); 1403 sign);
1404 tree t;
1405 if (tmp.is_constant ())
1406 t = build_new_int_cst (type, tmp.coeffs[0]);
1407 else
1408 {
1409 tree coeffs[NUM_POLY_INT_COEFFS];
1410 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1411 {
1412 coeffs[i] = build_new_int_cst (type, tmp.coeffs[i]);
1413 TREE_OVERFLOW (coeffs[i]) = 1;
1414 }
1415 t = build_new_poly_int_cst (type, coeffs);
1416 }
1371 TREE_OVERFLOW (t) = 1; 1417 TREE_OVERFLOW (t) = 1;
1372 return t; 1418 return t;
1373 } 1419 }
1374 } 1420 }
1375 1421
1422 The value is extended from its precision according to the sign of 1468 The value is extended from its precision according to the sign of
1423 the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines 1469 the type to be a multiple of HOST_BITS_PER_WIDE_INT. This defines
1424 the upper bits and ensures that hashing and value equality based 1470 the upper bits and ensures that hashing and value equality based
1425 upon the underlying HOST_WIDE_INTs works without masking. */ 1471 upon the underlying HOST_WIDE_INTs works without masking. */
1426 1472
1427 tree 1473 static tree
1428 wide_int_to_tree (tree type, const wide_int_ref &pcst) 1474 wide_int_to_tree_1 (tree type, const wide_int_ref &pcst)
1429 { 1475 {
1430 tree t; 1476 tree t;
1431 int ix = -1; 1477 int ix = -1;
1432 int limit = 0; 1478 int limit = 0;
1433 1479
1463 gcc_assert (hwi == 0); 1509 gcc_assert (hwi == 0);
1464 /* Fallthru. */ 1510 /* Fallthru. */
1465 1511
1466 case POINTER_TYPE: 1512 case POINTER_TYPE:
1467 case REFERENCE_TYPE: 1513 case REFERENCE_TYPE:
1468 case POINTER_BOUNDS_TYPE:
1469 /* Cache NULL pointer and zero bounds. */ 1514 /* Cache NULL pointer and zero bounds. */
1470 if (hwi == 0) 1515 if (hwi == 0)
1471 { 1516 {
1472 limit = 1; 1517 limit = 1;
1473 ix = 0; 1518 ix = 0;
1563 { 1608 {
1564 /* Insert this one into the hash table. */ 1609 /* Insert this one into the hash table. */
1565 t = nt; 1610 t = nt;
1566 *slot = t; 1611 *slot = t;
1567 } 1612 }
1613 else
1614 ggc_free (nt);
1568 } 1615 }
1569 1616
1570 return t; 1617 return t;
1618 }
1619
1620 hashval_t
1621 poly_int_cst_hasher::hash (tree t)
1622 {
1623 inchash::hash hstate;
1624
1625 hstate.add_int (TYPE_UID (TREE_TYPE (t)));
1626 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1627 hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
1628
1629 return hstate.end ();
1630 }
1631
1632 bool
1633 poly_int_cst_hasher::equal (tree x, const compare_type &y)
1634 {
1635 if (TREE_TYPE (x) != y.first)
1636 return false;
1637 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1638 if (wi::to_wide (POLY_INT_CST_COEFF (x, i)) != y.second->coeffs[i])
1639 return false;
1640 return true;
1641 }
1642
1643 /* Build a POLY_INT_CST node with type TYPE and with the elements in VALUES.
1644 The elements must also have type TYPE. */
1645
1646 tree
1647 build_poly_int_cst (tree type, const poly_wide_int_ref &values)
1648 {
1649 unsigned int prec = TYPE_PRECISION (type);
1650 gcc_assert (prec <= values.coeffs[0].get_precision ());
1651 poly_wide_int c = poly_wide_int::from (values, prec, SIGNED);
1652
1653 inchash::hash h;
1654 h.add_int (TYPE_UID (type));
1655 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1656 h.add_wide_int (c.coeffs[i]);
1657 poly_int_cst_hasher::compare_type comp (type, &c);
1658 tree *slot = poly_int_cst_hash_table->find_slot_with_hash (comp, h.end (),
1659 INSERT);
1660 if (*slot == NULL_TREE)
1661 {
1662 tree coeffs[NUM_POLY_INT_COEFFS];
1663 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
1664 coeffs[i] = wide_int_to_tree_1 (type, c.coeffs[i]);
1665 *slot = build_new_poly_int_cst (type, coeffs);
1666 }
1667 return *slot;
1668 }
1669
1670 /* Create a constant tree with value VALUE in type TYPE. */
1671
1672 tree
1673 wide_int_to_tree (tree type, const poly_wide_int_ref &value)
1674 {
1675 if (value.is_constant ())
1676 return wide_int_to_tree_1 (type, value.coeffs[0]);
1677 return build_poly_int_cst (type, value);
1571 } 1678 }
1572 1679
1573 void 1680 void
1574 cache_integer_cst (tree t) 1681 cache_integer_cst (tree t)
1575 { 1682 {
1695 { 1802 {
1696 return (TREE_CODE (x) == INTEGER_CST 1803 return (TREE_CODE (x) == INTEGER_CST
1697 && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x))); 1804 && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
1698 } 1805 }
1699 1806
1700 /* Build a newly constructed VECTOR_CST node of length LEN. */ 1807 /* Build a newly constructed VECTOR_CST with the given values of
1701 1808 (VECTOR_CST_)LOG2_NPATTERNS and (VECTOR_CST_)NELTS_PER_PATTERN. */
1702 tree 1809
1703 make_vector (unsigned len MEM_STAT_DECL) 1810 tree
1704 { 1811 make_vector (unsigned log2_npatterns,
1812 unsigned int nelts_per_pattern MEM_STAT_DECL)
1813 {
1814 gcc_assert (IN_RANGE (nelts_per_pattern, 1, 3));
1705 tree t; 1815 tree t;
1706 unsigned length = (len - 1) * sizeof (tree) + sizeof (struct tree_vector); 1816 unsigned npatterns = 1 << log2_npatterns;
1817 unsigned encoded_nelts = npatterns * nelts_per_pattern;
1818 unsigned length = (sizeof (struct tree_vector)
1819 + (encoded_nelts - 1) * sizeof (tree));
1707 1820
1708 record_node_allocation_statistics (VECTOR_CST, length); 1821 record_node_allocation_statistics (VECTOR_CST, length);
1709 1822
1710 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT); 1823 t = ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT);
1711 1824
1712 TREE_SET_CODE (t, VECTOR_CST); 1825 TREE_SET_CODE (t, VECTOR_CST);
1713 TREE_CONSTANT (t) = 1; 1826 TREE_CONSTANT (t) = 1;
1714 VECTOR_CST_NELTS (t) = len; 1827 VECTOR_CST_LOG2_NPATTERNS (t) = log2_npatterns;
1828 VECTOR_CST_NELTS_PER_PATTERN (t) = nelts_per_pattern;
1715 1829
1716 return t; 1830 return t;
1717 }
1718
1719 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1720 are given by VALS. */
1721
1722 tree
1723 build_vector (tree type, vec<tree> vals MEM_STAT_DECL)
1724 {
1725 unsigned int nelts = vals.length ();
1726 gcc_assert (nelts == TYPE_VECTOR_SUBPARTS (type));
1727 int over = 0;
1728 unsigned cnt = 0;
1729 tree v = make_vector (nelts);
1730 TREE_TYPE (v) = type;
1731
1732 /* Iterate through elements and check for overflow. */
1733 for (cnt = 0; cnt < nelts; ++cnt)
1734 {
1735 tree value = vals[cnt];
1736
1737 VECTOR_CST_ELT (v, cnt) = value;
1738
1739 /* Don't crash if we get an address constant. */
1740 if (!CONSTANT_CLASS_P (value))
1741 continue;
1742
1743 over |= TREE_OVERFLOW (value);
1744 }
1745
1746 TREE_OVERFLOW (v) = over;
1747 return v;
1748 } 1831 }
1749 1832
1750 /* Return a new VECTOR_CST node whose type is TYPE and whose values 1833 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1751 are extracted from V, a vector of CONSTRUCTOR_ELT. */ 1834 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1752 1835
1753 tree 1836 tree
1754 build_vector_from_ctor (tree type, vec<constructor_elt, va_gc> *v) 1837 build_vector_from_ctor (tree type, vec<constructor_elt, va_gc> *v)
1755 { 1838 {
1756 unsigned int nelts = TYPE_VECTOR_SUBPARTS (type); 1839 unsigned HOST_WIDE_INT idx, nelts;
1757 unsigned HOST_WIDE_INT idx;
1758 tree value; 1840 tree value;
1759 1841
1760 auto_vec<tree, 32> vec (nelts); 1842 /* We can't construct a VECTOR_CST for a variable number of elements. */
1843 nelts = TYPE_VECTOR_SUBPARTS (type).to_constant ();
1844 tree_vector_builder vec (type, nelts, 1);
1761 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) 1845 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1762 { 1846 {
1763 if (TREE_CODE (value) == VECTOR_CST) 1847 if (TREE_CODE (value) == VECTOR_CST)
1764 for (unsigned i = 0; i < VECTOR_CST_NELTS (value); ++i) 1848 {
1765 vec.quick_push (VECTOR_CST_ELT (value, i)); 1849 /* If NELTS is constant then this must be too. */
1850 unsigned int sub_nelts = VECTOR_CST_NELTS (value).to_constant ();
1851 for (unsigned i = 0; i < sub_nelts; ++i)
1852 vec.quick_push (VECTOR_CST_ELT (value, i));
1853 }
1766 else 1854 else
1767 vec.quick_push (value); 1855 vec.quick_push (value);
1768 } 1856 }
1769 while (vec.length () < nelts) 1857 while (vec.length () < nelts)
1770 vec.quick_push (build_zero_cst (TREE_TYPE (type))); 1858 vec.quick_push (build_zero_cst (TREE_TYPE (type)));
1771 1859
1772 return build_vector (type, vec); 1860 return vec.build ();
1773 } 1861 }
1774 1862
1775 /* Build a vector of type VECTYPE where all the elements are SCs. */ 1863 /* Build a vector of type VECTYPE where all the elements are SCs. */
1776 tree 1864 tree
1777 build_vector_from_val (tree vectype, tree sc) 1865 build_vector_from_val (tree vectype, tree sc)
1778 { 1866 {
1779 int i, nunits = TYPE_VECTOR_SUBPARTS (vectype); 1867 unsigned HOST_WIDE_INT i, nunits;
1780 1868
1781 if (sc == error_mark_node) 1869 if (sc == error_mark_node)
1782 return sc; 1870 return sc;
1783 1871
1784 /* Verify that the vector type is suitable for SC. Note that there 1872 /* Verify that the vector type is suitable for SC. Note that there
1790 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)), 1878 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc)),
1791 TREE_TYPE (vectype))); 1879 TREE_TYPE (vectype)));
1792 1880
1793 if (CONSTANT_CLASS_P (sc)) 1881 if (CONSTANT_CLASS_P (sc))
1794 { 1882 {
1795 auto_vec<tree, 32> v (nunits); 1883 tree_vector_builder v (vectype, 1, 1);
1796 for (i = 0; i < nunits; ++i) 1884 v.quick_push (sc);
1797 v.quick_push (sc); 1885 return v.build ();
1798 return build_vector (vectype, v); 1886 }
1799 } 1887 else if (!TYPE_VECTOR_SUBPARTS (vectype).is_constant (&nunits))
1888 return fold_build1 (VEC_DUPLICATE_EXPR, vectype, sc);
1800 else 1889 else
1801 { 1890 {
1802 vec<constructor_elt, va_gc> *v; 1891 vec<constructor_elt, va_gc> *v;
1803 vec_alloc (v, nunits); 1892 vec_alloc (v, nunits);
1804 for (i = 0; i < nunits; ++i) 1893 for (i = 0; i < nunits; ++i)
1805 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc); 1894 CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, sc);
1806 return build_constructor (vectype, v); 1895 return build_constructor (vectype, v);
1807 } 1896 }
1897 }
1898
1899 /* Build a vector series of type TYPE in which element I has the value
1900 BASE + I * STEP. The result is a constant if BASE and STEP are constant
1901 and a VEC_SERIES_EXPR otherwise. */
1902
1903 tree
1904 build_vec_series (tree type, tree base, tree step)
1905 {
1906 if (integer_zerop (step))
1907 return build_vector_from_val (type, base);
1908 if (TREE_CODE (base) == INTEGER_CST && TREE_CODE (step) == INTEGER_CST)
1909 {
1910 tree_vector_builder builder (type, 1, 3);
1911 tree elt1 = wide_int_to_tree (TREE_TYPE (base),
1912 wi::to_wide (base) + wi::to_wide (step));
1913 tree elt2 = wide_int_to_tree (TREE_TYPE (base),
1914 wi::to_wide (elt1) + wi::to_wide (step));
1915 builder.quick_push (base);
1916 builder.quick_push (elt1);
1917 builder.quick_push (elt2);
1918 return builder.build ();
1919 }
1920 return build2 (VEC_SERIES_EXPR, type, base, step);
1921 }
1922
1923 /* Return a vector with the same number of units and number of bits
1924 as VEC_TYPE, but in which the elements are a linear series of unsigned
1925 integers { BASE, BASE + STEP, BASE + STEP * 2, ... }. */
1926
1927 tree
1928 build_index_vector (tree vec_type, poly_uint64 base, poly_uint64 step)
1929 {
1930 tree index_vec_type = vec_type;
1931 tree index_elt_type = TREE_TYPE (vec_type);
1932 poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vec_type);
1933 if (!INTEGRAL_TYPE_P (index_elt_type) || !TYPE_UNSIGNED (index_elt_type))
1934 {
1935 index_elt_type = build_nonstandard_integer_type
1936 (GET_MODE_BITSIZE (SCALAR_TYPE_MODE (index_elt_type)), true);
1937 index_vec_type = build_vector_type (index_elt_type, nunits);
1938 }
1939
1940 tree_vector_builder v (index_vec_type, 1, 3);
1941 for (unsigned int i = 0; i < 3; ++i)
1942 v.quick_push (build_int_cstu (index_elt_type, base + i * step));
1943 return v.build ();
1808 } 1944 }
1809 1945
1810 /* Something has messed with the elements of CONSTRUCTOR C after it was built; 1946 /* Something has messed with the elements of CONSTRUCTOR C after it was built;
1811 calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */ 1947 calculate TREE_CONSTANT and TREE_SIDE_EFFECTS. */
1812 1948
1921 tree value = va_arg (p, tree); 2057 tree value = va_arg (p, tree);
1922 CONSTRUCTOR_APPEND_ELT (v, index, value); 2058 CONSTRUCTOR_APPEND_ELT (v, index, value);
1923 } 2059 }
1924 va_end (p); 2060 va_end (p);
1925 return build_constructor (type, v); 2061 return build_constructor (type, v);
2062 }
2063
2064 /* Return a node of type TYPE for which TREE_CLOBBER_P is true. */
2065
2066 tree
2067 build_clobber (tree type)
2068 {
2069 tree clobber = build_constructor (type, NULL);
2070 TREE_THIS_VOLATILE (clobber) = true;
2071 return clobber;
1926 } 2072 }
1927 2073
1928 /* Return a new FIXED_CST node whose type is TYPE and value is F. */ 2074 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1929 2075
1930 tree 2076 tree
2327 } 2473 }
2328 2474
2329 /* Return 1 if EXPR is the constant zero, whether it is integral, float or 2475 /* Return 1 if EXPR is the constant zero, whether it is integral, float or
2330 fixed, and scalar, complex or vector. */ 2476 fixed, and scalar, complex or vector. */
2331 2477
2332 int 2478 bool
2333 zerop (const_tree expr) 2479 zerop (const_tree expr)
2334 { 2480 {
2335 return (integer_zerop (expr) 2481 return (integer_zerop (expr)
2336 || real_zerop (expr) 2482 || real_zerop (expr)
2337 || fixed_zerop (expr)); 2483 || fixed_zerop (expr));
2338 } 2484 }
2339 2485
2340 /* Return 1 if EXPR is the integer constant zero or a complex constant 2486 /* Return 1 if EXPR is the integer constant zero or a complex constant
2341 of zero. */ 2487 of zero. */
2342 2488
2343 int 2489 bool
2344 integer_zerop (const_tree expr) 2490 integer_zerop (const_tree expr)
2345 { 2491 {
2346 switch (TREE_CODE (expr)) 2492 switch (TREE_CODE (expr))
2347 { 2493 {
2348 case INTEGER_CST: 2494 case INTEGER_CST:
2349 return wi::to_wide (expr) == 0; 2495 return wi::to_wide (expr) == 0;
2350 case COMPLEX_CST: 2496 case COMPLEX_CST:
2351 return (integer_zerop (TREE_REALPART (expr)) 2497 return (integer_zerop (TREE_REALPART (expr))
2352 && integer_zerop (TREE_IMAGPART (expr))); 2498 && integer_zerop (TREE_IMAGPART (expr)));
2353 case VECTOR_CST: 2499 case VECTOR_CST:
2354 { 2500 return (VECTOR_CST_NPATTERNS (expr) == 1
2355 unsigned i; 2501 && VECTOR_CST_DUPLICATE_P (expr)
2356 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2502 && integer_zerop (VECTOR_CST_ENCODED_ELT (expr, 0)));
2357 if (!integer_zerop (VECTOR_CST_ELT (expr, i)))
2358 return false;
2359 return true;
2360 }
2361 default: 2503 default:
2362 return false; 2504 return false;
2363 } 2505 }
2364 } 2506 }
2365 2507
2366 /* Return 1 if EXPR is the integer constant one or the corresponding 2508 /* Return 1 if EXPR is the integer constant one or the corresponding
2367 complex constant. */ 2509 complex constant. */
2368 2510
2369 int 2511 bool
2370 integer_onep (const_tree expr) 2512 integer_onep (const_tree expr)
2371 { 2513 {
2372 switch (TREE_CODE (expr)) 2514 switch (TREE_CODE (expr))
2373 { 2515 {
2374 case INTEGER_CST: 2516 case INTEGER_CST:
2375 return wi::eq_p (wi::to_widest (expr), 1); 2517 return wi::eq_p (wi::to_widest (expr), 1);
2376 case COMPLEX_CST: 2518 case COMPLEX_CST:
2377 return (integer_onep (TREE_REALPART (expr)) 2519 return (integer_onep (TREE_REALPART (expr))
2378 && integer_zerop (TREE_IMAGPART (expr))); 2520 && integer_zerop (TREE_IMAGPART (expr)));
2379 case VECTOR_CST: 2521 case VECTOR_CST:
2380 { 2522 return (VECTOR_CST_NPATTERNS (expr) == 1
2381 unsigned i; 2523 && VECTOR_CST_DUPLICATE_P (expr)
2382 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2524 && integer_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
2383 if (!integer_onep (VECTOR_CST_ELT (expr, i)))
2384 return false;
2385 return true;
2386 }
2387 default: 2525 default:
2388 return false; 2526 return false;
2389 } 2527 }
2390 } 2528 }
2391 2529
2392 /* Return 1 if EXPR is the integer constant one. For complex and vector, 2530 /* Return 1 if EXPR is the integer constant one. For complex and vector,
2393 return 1 if every piece is the integer constant one. */ 2531 return 1 if every piece is the integer constant one. */
2394 2532
2395 int 2533 bool
2396 integer_each_onep (const_tree expr) 2534 integer_each_onep (const_tree expr)
2397 { 2535 {
2398 if (TREE_CODE (expr) == COMPLEX_CST) 2536 if (TREE_CODE (expr) == COMPLEX_CST)
2399 return (integer_onep (TREE_REALPART (expr)) 2537 return (integer_onep (TREE_REALPART (expr))
2400 && integer_onep (TREE_IMAGPART (expr))); 2538 && integer_onep (TREE_IMAGPART (expr)));
2403 } 2541 }
2404 2542
2405 /* Return 1 if EXPR is an integer containing all 1's in as much precision as 2543 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
2406 it contains, or a complex or vector whose subparts are such integers. */ 2544 it contains, or a complex or vector whose subparts are such integers. */
2407 2545
2408 int 2546 bool
2409 integer_all_onesp (const_tree expr) 2547 integer_all_onesp (const_tree expr)
2410 { 2548 {
2411 if (TREE_CODE (expr) == COMPLEX_CST 2549 if (TREE_CODE (expr) == COMPLEX_CST
2412 && integer_all_onesp (TREE_REALPART (expr)) 2550 && integer_all_onesp (TREE_REALPART (expr))
2413 && integer_all_onesp (TREE_IMAGPART (expr))) 2551 && integer_all_onesp (TREE_IMAGPART (expr)))
2414 return 1; 2552 return true;
2415 2553
2416 else if (TREE_CODE (expr) == VECTOR_CST) 2554 else if (TREE_CODE (expr) == VECTOR_CST)
2417 { 2555 return (VECTOR_CST_NPATTERNS (expr) == 1
2418 unsigned i; 2556 && VECTOR_CST_DUPLICATE_P (expr)
2419 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2557 && integer_all_onesp (VECTOR_CST_ENCODED_ELT (expr, 0)));
2420 if (!integer_all_onesp (VECTOR_CST_ELT (expr, i)))
2421 return 0;
2422 return 1;
2423 }
2424 2558
2425 else if (TREE_CODE (expr) != INTEGER_CST) 2559 else if (TREE_CODE (expr) != INTEGER_CST)
2426 return 0; 2560 return false;
2427 2561
2428 return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED) 2562 return (wi::max_value (TYPE_PRECISION (TREE_TYPE (expr)), UNSIGNED)
2429 == wi::to_wide (expr)); 2563 == wi::to_wide (expr));
2430 } 2564 }
2431 2565
2432 /* Return 1 if EXPR is the integer constant minus one. */ 2566 /* Return 1 if EXPR is the integer constant minus one. */
2433 2567
2434 int 2568 bool
2435 integer_minus_onep (const_tree expr) 2569 integer_minus_onep (const_tree expr)
2436 { 2570 {
2437 if (TREE_CODE (expr) == COMPLEX_CST) 2571 if (TREE_CODE (expr) == COMPLEX_CST)
2438 return (integer_all_onesp (TREE_REALPART (expr)) 2572 return (integer_all_onesp (TREE_REALPART (expr))
2439 && integer_zerop (TREE_IMAGPART (expr))); 2573 && integer_zerop (TREE_IMAGPART (expr)));
2442 } 2576 }
2443 2577
2444 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only 2578 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
2445 one bit on). */ 2579 one bit on). */
2446 2580
2447 int 2581 bool
2448 integer_pow2p (const_tree expr) 2582 integer_pow2p (const_tree expr)
2449 { 2583 {
2450 if (TREE_CODE (expr) == COMPLEX_CST 2584 if (TREE_CODE (expr) == COMPLEX_CST
2451 && integer_pow2p (TREE_REALPART (expr)) 2585 && integer_pow2p (TREE_REALPART (expr))
2452 && integer_zerop (TREE_IMAGPART (expr))) 2586 && integer_zerop (TREE_IMAGPART (expr)))
2453 return 1; 2587 return true;
2454 2588
2455 if (TREE_CODE (expr) != INTEGER_CST) 2589 if (TREE_CODE (expr) != INTEGER_CST)
2456 return 0; 2590 return false;
2457 2591
2458 return wi::popcount (wi::to_wide (expr)) == 1; 2592 return wi::popcount (wi::to_wide (expr)) == 1;
2459 } 2593 }
2460 2594
2461 /* Return 1 if EXPR is an integer constant other than zero or a 2595 /* Return 1 if EXPR is an integer constant other than zero or a
2462 complex constant other than zero. */ 2596 complex constant other than zero. */
2463 2597
2464 int 2598 bool
2465 integer_nonzerop (const_tree expr) 2599 integer_nonzerop (const_tree expr)
2466 { 2600 {
2467 return ((TREE_CODE (expr) == INTEGER_CST 2601 return ((TREE_CODE (expr) == INTEGER_CST
2468 && wi::to_wide (expr) != 0) 2602 && wi::to_wide (expr) != 0)
2469 || (TREE_CODE (expr) == COMPLEX_CST 2603 || (TREE_CODE (expr) == COMPLEX_CST
2473 2607
2474 /* Return 1 if EXPR is the integer constant one. For vector, 2608 /* Return 1 if EXPR is the integer constant one. For vector,
2475 return 1 if every piece is the integer constant minus one 2609 return 1 if every piece is the integer constant minus one
2476 (representing the value TRUE). */ 2610 (representing the value TRUE). */
2477 2611
2478 int 2612 bool
2479 integer_truep (const_tree expr) 2613 integer_truep (const_tree expr)
2480 { 2614 {
2481 if (TREE_CODE (expr) == VECTOR_CST) 2615 if (TREE_CODE (expr) == VECTOR_CST)
2482 return integer_all_onesp (expr); 2616 return integer_all_onesp (expr);
2483 return integer_onep (expr); 2617 return integer_onep (expr);
2484 } 2618 }
2485 2619
2486 /* Return 1 if EXPR is the fixed-point constant zero. */ 2620 /* Return 1 if EXPR is the fixed-point constant zero. */
2487 2621
2488 int 2622 bool
2489 fixed_zerop (const_tree expr) 2623 fixed_zerop (const_tree expr)
2490 { 2624 {
2491 return (TREE_CODE (expr) == FIXED_CST 2625 return (TREE_CODE (expr) == FIXED_CST
2492 && TREE_FIXED_CST (expr).data.is_zero ()); 2626 && TREE_FIXED_CST (expr).data.is_zero ());
2493 } 2627 }
2628 } 2762 }
2629 2763
2630 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for 2764 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2631 decimal float constants, so don't return 1 for them. */ 2765 decimal float constants, so don't return 1 for them. */
2632 2766
2633 int 2767 bool
2634 real_zerop (const_tree expr) 2768 real_zerop (const_tree expr)
2635 { 2769 {
2636 switch (TREE_CODE (expr)) 2770 switch (TREE_CODE (expr))
2637 { 2771 {
2638 case REAL_CST: 2772 case REAL_CST:
2641 case COMPLEX_CST: 2775 case COMPLEX_CST:
2642 return real_zerop (TREE_REALPART (expr)) 2776 return real_zerop (TREE_REALPART (expr))
2643 && real_zerop (TREE_IMAGPART (expr)); 2777 && real_zerop (TREE_IMAGPART (expr));
2644 case VECTOR_CST: 2778 case VECTOR_CST:
2645 { 2779 {
2646 unsigned i; 2780 /* Don't simply check for a duplicate because the predicate
2647 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2781 accepts both +0.0 and -0.0. */
2648 if (!real_zerop (VECTOR_CST_ELT (expr, i))) 2782 unsigned count = vector_cst_encoded_nelts (expr);
2783 for (unsigned int i = 0; i < count; ++i)
2784 if (!real_zerop (VECTOR_CST_ENCODED_ELT (expr, i)))
2649 return false; 2785 return false;
2650 return true; 2786 return true;
2651 } 2787 }
2652 default: 2788 default:
2653 return false; 2789 return false;
2656 2792
2657 /* Return 1 if EXPR is the real constant one in real or complex form. 2793 /* Return 1 if EXPR is the real constant one in real or complex form.
2658 Trailing zeroes matter for decimal float constants, so don't return 2794 Trailing zeroes matter for decimal float constants, so don't return
2659 1 for them. */ 2795 1 for them. */
2660 2796
2661 int 2797 bool
2662 real_onep (const_tree expr) 2798 real_onep (const_tree expr)
2663 { 2799 {
2664 switch (TREE_CODE (expr)) 2800 switch (TREE_CODE (expr))
2665 { 2801 {
2666 case REAL_CST: 2802 case REAL_CST:
2668 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))); 2804 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
2669 case COMPLEX_CST: 2805 case COMPLEX_CST:
2670 return real_onep (TREE_REALPART (expr)) 2806 return real_onep (TREE_REALPART (expr))
2671 && real_zerop (TREE_IMAGPART (expr)); 2807 && real_zerop (TREE_IMAGPART (expr));
2672 case VECTOR_CST: 2808 case VECTOR_CST:
2673 { 2809 return (VECTOR_CST_NPATTERNS (expr) == 1
2674 unsigned i; 2810 && VECTOR_CST_DUPLICATE_P (expr)
2675 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2811 && real_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
2676 if (!real_onep (VECTOR_CST_ELT (expr, i)))
2677 return false;
2678 return true;
2679 }
2680 default: 2812 default:
2681 return false; 2813 return false;
2682 } 2814 }
2683 } 2815 }
2684 2816
2685 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes 2817 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2686 matter for decimal float constants, so don't return 1 for them. */ 2818 matter for decimal float constants, so don't return 1 for them. */
2687 2819
2688 int 2820 bool
2689 real_minus_onep (const_tree expr) 2821 real_minus_onep (const_tree expr)
2690 { 2822 {
2691 switch (TREE_CODE (expr)) 2823 switch (TREE_CODE (expr))
2692 { 2824 {
2693 case REAL_CST: 2825 case REAL_CST:
2695 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))); 2827 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
2696 case COMPLEX_CST: 2828 case COMPLEX_CST:
2697 return real_minus_onep (TREE_REALPART (expr)) 2829 return real_minus_onep (TREE_REALPART (expr))
2698 && real_zerop (TREE_IMAGPART (expr)); 2830 && real_zerop (TREE_IMAGPART (expr));
2699 case VECTOR_CST: 2831 case VECTOR_CST:
2700 { 2832 return (VECTOR_CST_NPATTERNS (expr) == 1
2701 unsigned i; 2833 && VECTOR_CST_DUPLICATE_P (expr)
2702 for (i = 0; i < VECTOR_CST_NELTS (expr); ++i) 2834 && real_minus_onep (VECTOR_CST_ENCODED_ELT (expr, 0)));
2703 if (!real_minus_onep (VECTOR_CST_ELT (expr, i)))
2704 return false;
2705 return true;
2706 }
2707 default: 2835 default:
2708 return false; 2836 return false;
2709 } 2837 }
2710 } 2838 }
2711 2839
2712 /* Nonzero if EXP is a constant or a cast of a constant. */ 2840 /* Nonzero if EXP is a constant or a cast of a constant. */
2713 2841
2714 int 2842 bool
2715 really_constant_p (const_tree exp) 2843 really_constant_p (const_tree exp)
2716 { 2844 {
2717 /* This is not quite the same as STRIP_NOPS. It does more. */ 2845 /* This is not quite the same as STRIP_NOPS. It does more. */
2718 while (CONVERT_EXPR_P (exp) 2846 while (CONVERT_EXPR_P (exp)
2719 || TREE_CODE (exp) == NON_LVALUE_EXPR) 2847 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2720 exp = TREE_OPERAND (exp, 0); 2848 exp = TREE_OPERAND (exp, 0);
2721 return TREE_CONSTANT (exp); 2849 return TREE_CONSTANT (exp);
2850 }
2851
2852 /* Return true if T holds a polynomial pointer difference, storing it in
2853 *VALUE if so. A true return means that T's precision is no greater
2854 than 64 bits, which is the largest address space we support, so *VALUE
2855 never loses precision. However, the signedness of the result does
2856 not necessarily match the signedness of T: sometimes an unsigned type
2857 like sizetype is used to encode a value that is actually negative. */
2858
2859 bool
2860 ptrdiff_tree_p (const_tree t, poly_int64_pod *value)
2861 {
2862 if (!t)
2863 return false;
2864 if (TREE_CODE (t) == INTEGER_CST)
2865 {
2866 if (!cst_and_fits_in_hwi (t))
2867 return false;
2868 *value = int_cst_value (t);
2869 return true;
2870 }
2871 if (POLY_INT_CST_P (t))
2872 {
2873 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
2874 if (!cst_and_fits_in_hwi (POLY_INT_CST_COEFF (t, i)))
2875 return false;
2876 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
2877 value->coeffs[i] = int_cst_value (POLY_INT_CST_COEFF (t, i));
2878 return true;
2879 }
2880 return false;
2881 }
2882
2883 poly_int64
2884 tree_to_poly_int64 (const_tree t)
2885 {
2886 gcc_assert (tree_fits_poly_int64_p (t));
2887 if (POLY_INT_CST_P (t))
2888 return poly_int_cst_value (t).force_shwi ();
2889 return TREE_INT_CST_LOW (t);
2890 }
2891
2892 poly_uint64
2893 tree_to_poly_uint64 (const_tree t)
2894 {
2895 gcc_assert (tree_fits_poly_uint64_p (t));
2896 if (POLY_INT_CST_P (t))
2897 return poly_int_cst_value (t).force_uhwi ();
2898 return TREE_INT_CST_LOW (t);
2722 } 2899 }
2723 2900
2724 /* Return first list element whose TREE_VALUE is ELEM. 2901 /* Return first list element whose TREE_VALUE is ELEM.
2725 Return 0 if ELEM is not in LIST. */ 2902 Return 0 if ELEM is not in LIST. */
2726 2903
2775 return chain; 2952 return chain;
2776 } 2953 }
2777 2954
2778 /* Return nonzero if ELEM is part of the chain CHAIN. */ 2955 /* Return nonzero if ELEM is part of the chain CHAIN. */
2779 2956
2780 int 2957 bool
2781 chain_member (const_tree elem, const_tree chain) 2958 chain_member (const_tree elem, const_tree chain)
2782 { 2959 {
2783 while (chain) 2960 while (chain)
2784 { 2961 {
2785 if (elem == chain) 2962 if (elem == chain)
2786 return 1; 2963 return true;
2787 chain = DECL_CHAIN (chain); 2964 chain = DECL_CHAIN (chain);
2788 } 2965 }
2789 2966
2790 return 0; 2967 return false;
2791 } 2968 }
2792 2969
2793 /* Return the length of a chain of nodes chained through TREE_CHAIN. 2970 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2794 We expect a null pointer to mark the end of the chain. 2971 We expect a null pointer to mark the end of the chain.
2795 This is the Lisp primitive `length'. */ 2972 This is the Lisp primitive `length'. */
3606 /* Now do type-specific checks. Note that the last part of the check above 3783 /* Now do type-specific checks. Note that the last part of the check above
3607 greatly limits what we have to do below. */ 3784 greatly limits what we have to do below. */
3608 switch (TREE_CODE (type)) 3785 switch (TREE_CODE (type))
3609 { 3786 {
3610 case VOID_TYPE: 3787 case VOID_TYPE:
3611 case POINTER_BOUNDS_TYPE:
3612 case COMPLEX_TYPE: 3788 case COMPLEX_TYPE:
3613 case ENUMERAL_TYPE: 3789 case ENUMERAL_TYPE:
3614 case BOOLEAN_TYPE: 3790 case BOOLEAN_TYPE:
3615 case POINTER_TYPE: 3791 case POINTER_TYPE:
3616 case OFFSET_TYPE: 3792 case OFFSET_TYPE:
4167 return e; 4343 return e;
4168 4344
4169 switch (TREE_CODE_CLASS (code)) 4345 switch (TREE_CODE_CLASS (code))
4170 { 4346 {
4171 case tcc_exceptional: 4347 case tcc_exceptional:
4348 /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't
4349 have side-effects. */
4350 if (code == STATEMENT_LIST)
4351 return save_expr (e);
4352 /* FALLTHRU */
4172 case tcc_type: 4353 case tcc_type:
4173 case tcc_declaration: 4354 case tcc_declaration:
4174 case tcc_comparison: 4355 case tcc_comparison:
4175 case tcc_statement: 4356 case tcc_statement:
4176 case tcc_expression: 4357 case tcc_expression:
4426 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node); 4607 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
4427 TREE_READONLY (t) = TREE_READONLY (node); 4608 TREE_READONLY (t) = TREE_READONLY (node);
4428 } 4609 }
4429 4610
4430 if (TREE_CODE_CLASS (code) == tcc_statement) 4611 if (TREE_CODE_CLASS (code) == tcc_statement)
4431 TREE_SIDE_EFFECTS (t) = 1; 4612 {
4613 if (code != DEBUG_BEGIN_STMT)
4614 TREE_SIDE_EFFECTS (t) = 1;
4615 }
4432 else switch (code) 4616 else switch (code)
4433 { 4617 {
4434 case VA_ARG_EXPR: 4618 case VA_ARG_EXPR:
4435 /* All of these have side-effects, no matter what their 4619 /* All of these have side-effects, no matter what their
4436 operands are. */ 4620 operands are. */
4668 on the pointer PTR. */ 4852 on the pointer PTR. */
4669 4853
4670 tree 4854 tree
4671 build_simple_mem_ref_loc (location_t loc, tree ptr) 4855 build_simple_mem_ref_loc (location_t loc, tree ptr)
4672 { 4856 {
4673 HOST_WIDE_INT offset = 0; 4857 poly_int64 offset = 0;
4674 tree ptype = TREE_TYPE (ptr); 4858 tree ptype = TREE_TYPE (ptr);
4675 tree tem; 4859 tree tem;
4676 /* For convenience allow addresses that collapse to a simple base 4860 /* For convenience allow addresses that collapse to a simple base
4677 and offset. */ 4861 and offset. */
4678 if (TREE_CODE (ptr) == ADDR_EXPR 4862 if (TREE_CODE (ptr) == ADDR_EXPR
4679 && (handled_component_p (TREE_OPERAND (ptr, 0)) 4863 && (handled_component_p (TREE_OPERAND (ptr, 0))
4680 || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF)) 4864 || TREE_CODE (TREE_OPERAND (ptr, 0)) == MEM_REF))
4681 { 4865 {
4682 ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset); 4866 ptr = get_addr_base_and_unit_offset (TREE_OPERAND (ptr, 0), &offset);
4683 gcc_assert (ptr); 4867 gcc_assert (ptr);
4684 ptr = build_fold_addr_expr (ptr); 4868 if (TREE_CODE (ptr) == MEM_REF)
4869 {
4870 offset += mem_ref_offset (ptr).force_shwi ();
4871 ptr = TREE_OPERAND (ptr, 0);
4872 }
4873 else
4874 ptr = build_fold_addr_expr (ptr);
4685 gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr)); 4875 gcc_assert (is_gimple_reg (ptr) || is_gimple_min_invariant (ptr));
4686 } 4876 }
4687 tem = build2 (MEM_REF, TREE_TYPE (ptype), 4877 tem = build2 (MEM_REF, TREE_TYPE (ptype),
4688 ptr, build_int_cst (ptype, offset)); 4878 ptr, build_int_cst (ptype, offset));
4689 SET_EXPR_LOCATION (tem, loc); 4879 SET_EXPR_LOCATION (tem, loc);
4690 return tem; 4880 return tem;
4691 } 4881 }
4692 4882
4693 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */ 4883 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4694 4884
4695 offset_int 4885 poly_offset_int
4696 mem_ref_offset (const_tree t) 4886 mem_ref_offset (const_tree t)
4697 { 4887 {
4698 return offset_int::from (wi::to_wide (TREE_OPERAND (t, 1)), SIGNED); 4888 return poly_offset_int::from (wi::to_poly_wide (TREE_OPERAND (t, 1)),
4889 SIGNED);
4699 } 4890 }
4700 4891
4701 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE 4892 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4702 offsetted by OFFSET units. */ 4893 offsetted by OFFSET units. */
4703 4894
4704 tree 4895 tree
4705 build_invariant_address (tree type, tree base, HOST_WIDE_INT offset) 4896 build_invariant_address (tree type, tree base, poly_int64 offset)
4706 { 4897 {
4707 tree ref = fold_build2 (MEM_REF, TREE_TYPE (type), 4898 tree ref = fold_build2 (MEM_REF, TREE_TYPE (type),
4708 build_fold_addr_expr (base), 4899 build_fold_addr_expr (base),
4709 build_int_cst (ptr_type_node, offset)); 4900 build_int_cst (ptr_type_node, offset));
4710 tree addr = build1 (ADDR_EXPR, type, ref); 4901 tree addr = build1 (ADDR_EXPR, type, ref);
4880 5071
4881 BINFO_VIRTUALS (binfo) = NULL_TREE; 5072 BINFO_VIRTUALS (binfo) = NULL_TREE;
4882 BINFO_BASE_ACCESSES (binfo) = NULL; 5073 BINFO_BASE_ACCESSES (binfo) = NULL;
4883 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE; 5074 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
4884 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE; 5075 BINFO_SUBVTT_INDEX (binfo) = NULL_TREE;
5076 BINFO_VPTR_FIELD (binfo) = NULL_TREE;
4885 5077
4886 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t) 5078 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo), i, t)
4887 free_lang_data_in_binfo (t); 5079 free_lang_data_in_binfo (t);
4888 } 5080 }
4889 5081
4933 for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p)) 5125 for (tree p = TYPE_ARG_TYPES (type); p; p = TREE_CHAIN (p))
4934 /* C++ FE uses TREE_PURPOSE to store initial values. */ 5126 /* C++ FE uses TREE_PURPOSE to store initial values. */
4935 TREE_PURPOSE (p) = NULL; 5127 TREE_PURPOSE (p) = NULL;
4936 else if (RECORD_OR_UNION_TYPE_P (type)) 5128 else if (RECORD_OR_UNION_TYPE_P (type))
4937 { 5129 {
4938 /* Remove members that are not FIELD_DECLs (and maybe 5130 /* Remove members that are not FIELD_DECLs from the field list
4939 TYPE_DECLs) from the field list of an aggregate. These occur 5131 of an aggregate. These occur in C++. */
4940 in C++. */
4941 for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);) 5132 for (tree *prev = &TYPE_FIELDS (type), member; (member = *prev);)
4942 if (TREE_CODE (member) == FIELD_DECL 5133 if (TREE_CODE (member) == FIELD_DECL)
4943 || (TREE_CODE (member) == TYPE_DECL
4944 && !DECL_IGNORED_P (member)
4945 && debug_info_level > DINFO_LEVEL_TERSE
4946 && !is_redundant_typedef (member)))
4947 prev = &DECL_CHAIN (member); 5134 prev = &DECL_CHAIN (member);
4948 else 5135 else
4949 *prev = DECL_CHAIN (member); 5136 *prev = DECL_CHAIN (member);
4950 5137
4951 /* FIXME: C FE uses TYPE_VFIELD to record C_TYPE_INCOMPLETE_VARS 5138 TYPE_VFIELD (type) = NULL_TREE;
4952 and danagle the pointer from time to time. */
4953 if (TYPE_VFIELD (type) && TREE_CODE (TYPE_VFIELD (type)) != FIELD_DECL)
4954 TYPE_VFIELD (type) = NULL_TREE;
4955 5139
4956 if (TYPE_BINFO (type)) 5140 if (TYPE_BINFO (type))
4957 { 5141 {
4958 free_lang_data_in_binfo (TYPE_BINFO (type)); 5142 free_lang_data_in_binfo (TYPE_BINFO (type));
4959 /* We need to preserve link to bases and virtual table for all 5143 /* We need to preserve link to bases and virtual table for all
4960 polymorphic types to make devirtualization machinery working. 5144 polymorphic types to make devirtualization machinery working. */
4961 Debug output cares only about bases, but output also 5145 if (!BINFO_VTABLE (TYPE_BINFO (type))
4962 virtual table pointers so merging of -fdevirtualize and 5146 || !flag_devirtualize)
4963 -fno-devirtualize units is easier. */
4964 if ((!BINFO_VTABLE (TYPE_BINFO (type))
4965 || !flag_devirtualize)
4966 && ((!BINFO_N_BASE_BINFOS (TYPE_BINFO (type))
4967 && !BINFO_VTABLE (TYPE_BINFO (type)))
4968 || debug_info_level != DINFO_LEVEL_NONE))
4969 TYPE_BINFO (type) = NULL; 5147 TYPE_BINFO (type) = NULL;
4970 } 5148 }
4971 } 5149 }
4972 else if (INTEGRAL_TYPE_P (type) 5150 else if (INTEGRAL_TYPE_P (type)
4973 || SCALAR_FLOAT_TYPE_P (type) 5151 || SCALAR_FLOAT_TYPE_P (type)
4990 { 5168 {
4991 ctx = BLOCK_SUPERCONTEXT (ctx); 5169 ctx = BLOCK_SUPERCONTEXT (ctx);
4992 } 5170 }
4993 while (ctx && TREE_CODE (ctx) == BLOCK); 5171 while (ctx && TREE_CODE (ctx) == BLOCK);
4994 TYPE_CONTEXT (type) = ctx; 5172 TYPE_CONTEXT (type) = ctx;
5173 }
5174
5175 /* Drop TYPE_DECLs in TYPE_NAME in favor of the identifier in the
5176 TYPE_DECL if the type doesn't have linkage. */
5177 if (! type_with_linkage_p (type))
5178 {
5179 TYPE_NAME (type) = TYPE_IDENTIFIER (type);
5180 TYPE_STUB_DECL (type) = NULL;
4995 } 5181 }
4996 } 5182 }
4997 5183
4998 5184
4999 /* Return true if DECL may need an assembler name to be set. */ 5185 /* Return true if DECL may need an assembler name to be set. */
5052 5238
5053 if (TREE_CODE (decl) == FUNCTION_DECL) 5239 if (TREE_CODE (decl) == FUNCTION_DECL)
5054 { 5240 {
5055 /* Do not set assembler name on builtins. Allow RTL expansion to 5241 /* Do not set assembler name on builtins. Allow RTL expansion to
5056 decide whether to expand inline or via a regular call. */ 5242 decide whether to expand inline or via a regular call. */
5057 if (DECL_BUILT_IN (decl) 5243 if (fndecl_built_in_p (decl)
5058 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND) 5244 && DECL_BUILT_IN_CLASS (decl) != BUILT_IN_FRONTEND)
5059 return false; 5245 return false;
5060 5246
5061 /* Functions represented in the callgraph need an assembler name. */ 5247 /* Functions represented in the callgraph need an assembler name. */
5062 if (cgraph_node::get (decl) != NULL) 5248 if (cgraph_node::get (decl) != NULL)
5092 5278
5093 free_lang_data_in_one_sizepos (&DECL_SIZE (decl)); 5279 free_lang_data_in_one_sizepos (&DECL_SIZE (decl));
5094 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl)); 5280 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl));
5095 if (TREE_CODE (decl) == FIELD_DECL) 5281 if (TREE_CODE (decl) == FIELD_DECL)
5096 { 5282 {
5283 DECL_FCONTEXT (decl) = NULL;
5097 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl)); 5284 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl));
5098 if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE) 5285 if (TREE_CODE (DECL_CONTEXT (decl)) == QUAL_UNION_TYPE)
5099 DECL_QUALIFIER (decl) = NULL_TREE; 5286 DECL_QUALIFIER (decl) = NULL_TREE;
5100 } 5287 }
5101 5288
5150 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl)) 5337 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))
5151 && RECORD_OR_UNION_TYPE_P 5338 && RECORD_OR_UNION_TYPE_P
5152 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl)))) 5339 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl))))
5153 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE; 5340 DECL_ABSTRACT_ORIGIN (decl) = NULL_TREE;
5154 5341
5155 /* Sometimes the C++ frontend doesn't manage to transform a temporary 5342 DECL_VINDEX (decl) = NULL_TREE;
5156 DECL_VINDEX referring to itself into a vtable slot number as it
5157 should. Happens with functions that are copied and then forgotten
5158 about. Just clear it, it won't matter anymore. */
5159 if (DECL_VINDEX (decl) && !tree_fits_shwi_p (DECL_VINDEX (decl)))
5160 DECL_VINDEX (decl) = NULL_TREE;
5161 } 5343 }
5162 else if (VAR_P (decl)) 5344 else if (VAR_P (decl))
5163 { 5345 {
5164 if ((DECL_EXTERNAL (decl) 5346 if ((DECL_EXTERNAL (decl)
5165 && (!TREE_STATIC (decl) || !TREE_READONLY (decl))) 5347 && (!TREE_STATIC (decl) || !TREE_READONLY (decl)))
5169 else if (TREE_CODE (decl) == TYPE_DECL) 5351 else if (TREE_CODE (decl) == TYPE_DECL)
5170 { 5352 {
5171 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; 5353 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
5172 DECL_VISIBILITY_SPECIFIED (decl) = 0; 5354 DECL_VISIBILITY_SPECIFIED (decl) = 0;
5173 DECL_INITIAL (decl) = NULL_TREE; 5355 DECL_INITIAL (decl) = NULL_TREE;
5356 DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
5174 } 5357 }
5175 else if (TREE_CODE (decl) == FIELD_DECL) 5358 else if (TREE_CODE (decl) == FIELD_DECL)
5176 DECL_INITIAL (decl) = NULL_TREE; 5359 DECL_INITIAL (decl) = NULL_TREE;
5177 else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL 5360 else if (TREE_CODE (decl) == TRANSLATION_UNIT_DECL
5178 && DECL_INITIAL (decl) 5361 && DECL_INITIAL (decl)
5181 /* Strip builtins from the translation-unit BLOCK. We still have targets 5364 /* Strip builtins from the translation-unit BLOCK. We still have targets
5182 without builtin_decl_explicit support and also builtins are shared 5365 without builtin_decl_explicit support and also builtins are shared
5183 nodes and thus we can't use TREE_CHAIN in multiple lists. */ 5366 nodes and thus we can't use TREE_CHAIN in multiple lists. */
5184 tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl)); 5367 tree *nextp = &BLOCK_VARS (DECL_INITIAL (decl));
5185 while (*nextp) 5368 while (*nextp)
5186 { 5369 {
5187 tree var = *nextp; 5370 tree var = *nextp;
5188 if (TREE_CODE (var) == FUNCTION_DECL 5371 if (fndecl_built_in_p (var))
5189 && DECL_BUILT_IN (var))
5190 *nextp = TREE_CHAIN (var); 5372 *nextp = TREE_CHAIN (var);
5191 else 5373 else
5192 nextp = &TREE_CHAIN (var); 5374 nextp = &TREE_CHAIN (var);
5193 } 5375 }
5194 } 5376 }
5377 /* We need to keep field decls associated with their trees. Otherwise tree
5378 merging may merge some fileds and keep others disjoint wich in turn will
5379 not do well with TREE_CHAIN pointers linking them.
5380
5381 Also do not drop containing types for virtual methods and tables because
5382 these are needed by devirtualization. */
5383 if (TREE_CODE (decl) != FIELD_DECL
5384 && ((TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5385 || !DECL_VIRTUAL_P (decl)))
5386 {
5387 tree ctx = DECL_CONTEXT (decl);
5388 /* Variably modified types are needed for tree_is_indexable to decide
5389 whether the type needs to go to local or global section.
5390 This code is semi-broken but for now it is easiest to keep contexts
5391 as expected. */
5392 if (ctx && TYPE_P (ctx)
5393 && !variably_modified_type_p (ctx, NULL_TREE))
5394 {
5395 while (ctx && TYPE_P (ctx))
5396 ctx = TYPE_CONTEXT (ctx);
5397 DECL_CONTEXT (decl) = ctx;
5398 }
5399 }
5195 } 5400 }
5196 5401
5197 5402
5198 /* Data used when collecting DECLs and TYPEs for language data removal. */ 5403 /* Data used when collecting DECLs and TYPEs for language data removal. */
5199 5404
5213 /* Array of types to process with free_lang_data_in_type. */ 5418 /* Array of types to process with free_lang_data_in_type. */
5214 auto_vec<tree> types; 5419 auto_vec<tree> types;
5215 }; 5420 };
5216 5421
5217 5422
5218 /* Save all language fields needed to generate proper debug information
5219 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
5220
5221 static void
5222 save_debug_info_for_decl (tree t)
5223 {
5224 /*struct saved_debug_info_d *sdi;*/
5225
5226 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && DECL_P (t));
5227
5228 /* FIXME. Partial implementation for saving debug info removed. */
5229 }
5230
5231
5232 /* Save all language fields needed to generate proper debug information
5233 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
5234
5235 static void
5236 save_debug_info_for_type (tree t)
5237 {
5238 /*struct saved_debug_info_d *sdi;*/
5239
5240 gcc_assert (debug_info_level > DINFO_LEVEL_TERSE && t && TYPE_P (t));
5241
5242 /* FIXME. Partial implementation for saving debug info removed. */
5243 }
5244
5245
5246 /* Add type or decl T to one of the list of tree nodes that need their 5423 /* Add type or decl T to one of the list of tree nodes that need their
5247 language data removed. The lists are held inside FLD. */ 5424 language data removed. The lists are held inside FLD. */
5248 5425
5249 static void 5426 static void
5250 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld) 5427 add_tree_to_fld_list (tree t, struct free_lang_data_d *fld)
5251 { 5428 {
5252 if (DECL_P (t)) 5429 if (DECL_P (t))
5253 { 5430 fld->decls.safe_push (t);
5254 fld->decls.safe_push (t);
5255 if (debug_info_level > DINFO_LEVEL_TERSE)
5256 save_debug_info_for_decl (t);
5257 }
5258 else if (TYPE_P (t)) 5431 else if (TYPE_P (t))
5259 { 5432 fld->types.safe_push (t);
5260 fld->types.safe_push (t);
5261 if (debug_info_level > DINFO_LEVEL_TERSE)
5262 save_debug_info_for_type (t);
5263 }
5264 else 5433 else
5265 gcc_unreachable (); 5434 gcc_unreachable ();
5266 } 5435 }
5267 5436
5268 /* Push tree node T into FLD->WORKLIST. */ 5437 /* Push tree node T into FLD->WORKLIST. */
5316 5485
5317 if (TREE_CODE (t) == FUNCTION_DECL) 5486 if (TREE_CODE (t) == FUNCTION_DECL)
5318 { 5487 {
5319 fld_worklist_push (DECL_ARGUMENTS (t), fld); 5488 fld_worklist_push (DECL_ARGUMENTS (t), fld);
5320 fld_worklist_push (DECL_RESULT (t), fld); 5489 fld_worklist_push (DECL_RESULT (t), fld);
5321 }
5322 else if (TREE_CODE (t) == TYPE_DECL)
5323 {
5324 fld_worklist_push (DECL_ORIGINAL_TYPE (t), fld);
5325 } 5490 }
5326 else if (TREE_CODE (t) == FIELD_DECL) 5491 else if (TREE_CODE (t) == FIELD_DECL)
5327 { 5492 {
5328 fld_worklist_push (DECL_FIELD_OFFSET (t), fld); 5493 fld_worklist_push (DECL_FIELD_OFFSET (t), fld);
5329 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld); 5494 fld_worklist_push (DECL_BIT_FIELD_TYPE (t), fld);
5352 fld_worklist_push (TYPE_SIZE_UNIT (t), fld); 5517 fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
5353 fld_worklist_push (TYPE_ATTRIBUTES (t), fld); 5518 fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
5354 fld_worklist_push (TYPE_POINTER_TO (t), fld); 5519 fld_worklist_push (TYPE_POINTER_TO (t), fld);
5355 fld_worklist_push (TYPE_REFERENCE_TO (t), fld); 5520 fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
5356 fld_worklist_push (TYPE_NAME (t), fld); 5521 fld_worklist_push (TYPE_NAME (t), fld);
5357 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream 5522 /* While we do not stream TYPE_POINTER_TO and TYPE_REFERENCE_TO
5358 them and thus do not and want not to reach unused pointer types 5523 lists, we may look types up in these lists and use them while
5359 this way. */ 5524 optimizing the function body. Thus we need to free lang data
5525 in them. */
5526 if (TREE_CODE (t) == POINTER_TYPE)
5527 fld_worklist_push (TYPE_NEXT_PTR_TO (t), fld);
5528 if (TREE_CODE (t) == REFERENCE_TYPE)
5529 fld_worklist_push (TYPE_NEXT_REF_TO (t), fld);
5360 if (!POINTER_TYPE_P (t)) 5530 if (!POINTER_TYPE_P (t))
5361 fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld); 5531 fld_worklist_push (TYPE_MIN_VALUE_RAW (t), fld);
5362 /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */ 5532 /* TYPE_MAX_VALUE_RAW is TYPE_BINFO for record types. */
5363 if (!RECORD_OR_UNION_TYPE_P (t)) 5533 if (!RECORD_OR_UNION_TYPE_P (t))
5364 fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld); 5534 fld_worklist_push (TYPE_MAX_VALUE_RAW (t), fld);
5381 { 5551 {
5382 unsigned i; 5552 unsigned i;
5383 tree tem; 5553 tree tem;
5384 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem) 5554 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t)), i, tem)
5385 fld_worklist_push (TREE_TYPE (tem), fld); 5555 fld_worklist_push (TREE_TYPE (tem), fld);
5386 fld_worklist_push (BINFO_VIRTUALS (TYPE_BINFO (t)), fld); 5556 fld_worklist_push (BINFO_TYPE (TYPE_BINFO (t)), fld);
5557 fld_worklist_push (BINFO_VTABLE (TYPE_BINFO (t)), fld);
5387 } 5558 }
5388 if (RECORD_OR_UNION_TYPE_P (t)) 5559 if (RECORD_OR_UNION_TYPE_P (t))
5389 { 5560 {
5390 tree tem; 5561 tree tem;
5391 /* Push all TYPE_FIELDS - there can be interleaving interesting 5562 /* Push all TYPE_FIELDS - there can be interleaving interesting
5392 and non-interesting things. */ 5563 and non-interesting things. */
5393 tem = TYPE_FIELDS (t); 5564 tem = TYPE_FIELDS (t);
5394 while (tem) 5565 while (tem)
5395 { 5566 {
5396 if (TREE_CODE (tem) == FIELD_DECL 5567 if (TREE_CODE (tem) == FIELD_DECL)
5397 || (TREE_CODE (tem) == TYPE_DECL
5398 && !DECL_IGNORED_P (tem)
5399 && debug_info_level > DINFO_LEVEL_TERSE
5400 && !is_redundant_typedef (tem)))
5401 fld_worklist_push (tem, fld); 5568 fld_worklist_push (tem, fld);
5402 tem = TREE_CHAIN (tem); 5569 tem = TREE_CHAIN (tem);
5403 } 5570 }
5404 } 5571 }
5572 if (FUNC_OR_METHOD_TYPE_P (t))
5573 fld_worklist_push (TYPE_METHOD_BASETYPE (t), fld);
5405 5574
5406 fld_worklist_push (TYPE_STUB_DECL (t), fld); 5575 fld_worklist_push (TYPE_STUB_DECL (t), fld);
5407 *ws = 0; 5576 *ws = 0;
5408 } 5577 }
5409 else if (TREE_CODE (t) == BLOCK) 5578 else if (TREE_CODE (t) == BLOCK)
5410 { 5579 {
5411 tree tem; 5580 for (tree *tem = &BLOCK_VARS (t); *tem; )
5412 for (tem = BLOCK_VARS (t); tem; tem = TREE_CHAIN (tem)) 5581 {
5413 fld_worklist_push (tem, fld); 5582 if (TREE_CODE (*tem) != VAR_DECL
5414 for (tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem)) 5583 || !auto_var_in_fn_p (*tem, DECL_CONTEXT (*tem)))
5584 {
5585 gcc_assert (TREE_CODE (*tem) != RESULT_DECL
5586 && TREE_CODE (*tem) != PARM_DECL);
5587 *tem = TREE_CHAIN (*tem);
5588 }
5589 else
5590 {
5591 fld_worklist_push (*tem, fld);
5592 tem = &TREE_CHAIN (*tem);
5593 }
5594 }
5595 for (tree tem = BLOCK_SUBBLOCKS (t); tem; tem = BLOCK_CHAIN (tem))
5415 fld_worklist_push (tem, fld); 5596 fld_worklist_push (tem, fld);
5416 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld); 5597 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t), fld);
5417 } 5598 }
5418 5599
5419 if (TREE_CODE (t) != IDENTIFIER_NODE 5600 if (TREE_CODE (t) != IDENTIFIER_NODE
5718 make sure we never call decl_assembler_name on local symbols and 5899 make sure we never call decl_assembler_name on local symbols and
5719 devise a separate, middle-end private scheme for it. */ 5900 devise a separate, middle-end private scheme for it. */
5720 5901
5721 /* Reset diagnostic machinery. */ 5902 /* Reset diagnostic machinery. */
5722 tree_diagnostics_defaults (global_dc); 5903 tree_diagnostics_defaults (global_dc);
5904
5905 rebuild_type_inheritance_graph ();
5723 5906
5724 return 0; 5907 return 0;
5725 } 5908 }
5726 5909
5727 5910
6308 hstate.add_object (prec); 6491 hstate.add_object (prec);
6309 break; 6492 break;
6310 } 6493 }
6311 6494
6312 case VECTOR_TYPE: 6495 case VECTOR_TYPE:
6313 { 6496 hstate.add_poly_int (TYPE_VECTOR_SUBPARTS (type));
6314 unsigned nunits = TYPE_VECTOR_SUBPARTS (type); 6497 break;
6315 hstate.add_object (nunits);
6316 break;
6317 }
6318 6498
6319 default: 6499 default:
6320 break; 6500 break;
6321 } 6501 }
6322 6502
6356 case REFERENCE_TYPE: 6536 case REFERENCE_TYPE:
6357 case NULLPTR_TYPE: 6537 case NULLPTR_TYPE:
6358 return 1; 6538 return 1;
6359 6539
6360 case VECTOR_TYPE: 6540 case VECTOR_TYPE:
6361 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type); 6541 return known_eq (TYPE_VECTOR_SUBPARTS (a->type),
6542 TYPE_VECTOR_SUBPARTS (b->type));
6362 6543
6363 case ENUMERAL_TYPE: 6544 case ENUMERAL_TYPE:
6364 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type) 6545 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
6365 && !(TYPE_VALUES (a->type) 6546 && !(TYPE_VALUES (a->type)
6366 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST 6547 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
6473 6654
6474 loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT); 6655 loc = type_hash_table->find_slot_with_hash (&in, hashcode, INSERT);
6475 if (*loc) 6656 if (*loc)
6476 { 6657 {
6477 tree t1 = ((type_hash *) *loc)->type; 6658 tree t1 = ((type_hash *) *loc)->type;
6478 gcc_assert (TYPE_MAIN_VARIANT (t1) == t1); 6659 gcc_assert (TYPE_MAIN_VARIANT (t1) == t1
6660 && t1 != type);
6479 if (TYPE_UID (type) + 1 == next_type_uid) 6661 if (TYPE_UID (type) + 1 == next_type_uid)
6480 --next_type_uid; 6662 --next_type_uid;
6481 /* Free also min/max values and the cache for integer 6663 /* Free also min/max values and the cache for integer
6482 types. This can't be done in free_node, as LTO frees 6664 types. This can't be done in free_node, as LTO frees
6483 those on its own. */ 6665 those on its own. */
6484 if (TREE_CODE (type) == INTEGER_TYPE) 6666 if (TREE_CODE (type) == INTEGER_TYPE)
6485 { 6667 {
6486 if (TYPE_MIN_VALUE (type) 6668 if (TYPE_MIN_VALUE (type)
6487 && TREE_TYPE (TYPE_MIN_VALUE (type)) == type) 6669 && TREE_TYPE (TYPE_MIN_VALUE (type)) == type)
6488 ggc_free (TYPE_MIN_VALUE (type)); 6670 {
6671 /* Zero is always in TYPE_CACHED_VALUES. */
6672 if (! TYPE_UNSIGNED (type))
6673 int_cst_hash_table->remove_elt (TYPE_MIN_VALUE (type));
6674 ggc_free (TYPE_MIN_VALUE (type));
6675 }
6489 if (TYPE_MAX_VALUE (type) 6676 if (TYPE_MAX_VALUE (type)
6490 && TREE_TYPE (TYPE_MAX_VALUE (type)) == type) 6677 && TREE_TYPE (TYPE_MAX_VALUE (type)) == type)
6491 ggc_free (TYPE_MAX_VALUE (type)); 6678 {
6679 int_cst_hash_table->remove_elt (TYPE_MAX_VALUE (type));
6680 ggc_free (TYPE_MAX_VALUE (type));
6681 }
6492 if (TYPE_CACHED_VALUES_P (type)) 6682 if (TYPE_CACHED_VALUES_P (type))
6493 ggc_free (TYPE_CACHED_VALUES (type)); 6683 ggc_free (TYPE_CACHED_VALUES (type));
6494 } 6684 }
6495 free_node (type); 6685 free_node (type);
6496 return t1; 6686 return t1;
6520 /* Given two lists of types 6710 /* Given two lists of types
6521 (chains of TREE_LIST nodes with types in the TREE_VALUE slots) 6711 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6522 return 1 if the lists contain the same types in the same order. 6712 return 1 if the lists contain the same types in the same order.
6523 Also, the TREE_PURPOSEs must match. */ 6713 Also, the TREE_PURPOSEs must match. */
6524 6714
6525 int 6715 bool
6526 type_list_equal (const_tree l1, const_tree l2) 6716 type_list_equal (const_tree l1, const_tree l2)
6527 { 6717 {
6528 const_tree t1, t2; 6718 const_tree t1, t2;
6529 6719
6530 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) 6720 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
6531 if (TREE_VALUE (t1) != TREE_VALUE (t2) 6721 if (TREE_VALUE (t1) != TREE_VALUE (t2)
6532 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2) 6722 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
6533 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)) 6723 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
6534 && (TREE_TYPE (TREE_PURPOSE (t1)) 6724 && (TREE_TYPE (TREE_PURPOSE (t1))
6535 == TREE_TYPE (TREE_PURPOSE (t2)))))) 6725 == TREE_TYPE (TREE_PURPOSE (t2))))))
6536 return 0; 6726 return false;
6537 6727
6538 return t1 == t2; 6728 return t1 == t2;
6539 } 6729 }
6540 6730
6541 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE 6731 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6588 return (t != NULL_TREE 6778 return (t != NULL_TREE
6589 && TREE_CODE (t) == INTEGER_CST 6779 && TREE_CODE (t) == INTEGER_CST
6590 && wi::fits_shwi_p (wi::to_widest (t))); 6780 && wi::fits_shwi_p (wi::to_widest (t)));
6591 } 6781 }
6592 6782
6783 /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6784 value (extended according to TYPE_UNSIGNED) fits in a poly_int64. */
6785
6786 bool
6787 tree_fits_poly_int64_p (const_tree t)
6788 {
6789 if (t == NULL_TREE)
6790 return false;
6791 if (POLY_INT_CST_P (t))
6792 {
6793 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6794 if (!wi::fits_shwi_p (wi::to_wide (POLY_INT_CST_COEFF (t, i))))
6795 return false;
6796 return true;
6797 }
6798 return (TREE_CODE (t) == INTEGER_CST
6799 && wi::fits_shwi_p (wi::to_widest (t)));
6800 }
6801
6593 /* Return true if T is an INTEGER_CST whose numerical value (extended 6802 /* Return true if T is an INTEGER_CST whose numerical value (extended
6594 according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */ 6803 according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
6595 6804
6596 bool 6805 bool
6597 tree_fits_uhwi_p (const_tree t) 6806 tree_fits_uhwi_p (const_tree t)
6598 { 6807 {
6599 return (t != NULL_TREE 6808 return (t != NULL_TREE
6600 && TREE_CODE (t) == INTEGER_CST 6809 && TREE_CODE (t) == INTEGER_CST
6810 && wi::fits_uhwi_p (wi::to_widest (t)));
6811 }
6812
6813 /* Return true if T is an INTEGER_CST or POLY_INT_CST whose numerical
6814 value (extended according to TYPE_UNSIGNED) fits in a poly_uint64. */
6815
6816 bool
6817 tree_fits_poly_uint64_p (const_tree t)
6818 {
6819 if (t == NULL_TREE)
6820 return false;
6821 if (POLY_INT_CST_P (t))
6822 {
6823 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; i++)
6824 if (!wi::fits_uhwi_p (wi::to_widest (POLY_INT_CST_COEFF (t, i))))
6825 return false;
6826 return true;
6827 }
6828 return (TREE_CODE (t) == INTEGER_CST
6601 && wi::fits_uhwi_p (wi::to_widest (t))); 6829 && wi::fits_uhwi_p (wi::to_widest (t)));
6602 } 6830 }
6603 6831
6604 /* T is an INTEGER_CST whose numerical value (extended according to 6832 /* T is an INTEGER_CST whose numerical value (extended according to
6605 TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that 6833 TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
6807 case CONST_DECL: 7035 case CONST_DECL:
6808 case FUNCTION_DECL: 7036 case FUNCTION_DECL:
6809 return 0; 7037 return 0;
6810 7038
6811 default: 7039 default:
7040 if (POLY_INT_CST_P (t1))
7041 /* A false return means maybe_ne rather than known_ne. */
7042 return known_eq (poly_widest_int::from (poly_int_cst_value (t1),
7043 TYPE_SIGN (TREE_TYPE (t1))),
7044 poly_widest_int::from (poly_int_cst_value (t2),
7045 TYPE_SIGN (TREE_TYPE (t2))));
6812 break; 7046 break;
6813 } 7047 }
6814 7048
6815 /* This general rule works for most tree codes. All exceptions should be 7049 /* This general rule works for most tree codes. All exceptions should be
6816 handled above. If this is a language-specific tree code, we can't 7050 handled above. If this is a language-specific tree code, we can't
6866 half of the address-space). */ 7100 half of the address-space). */
6867 7101
6868 bool 7102 bool
6869 valid_constant_size_p (const_tree size) 7103 valid_constant_size_p (const_tree size)
6870 { 7104 {
7105 if (POLY_INT_CST_P (size))
7106 {
7107 if (TREE_OVERFLOW (size))
7108 return false;
7109 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
7110 if (!valid_constant_size_p (POLY_INT_CST_COEFF (size, i)))
7111 return false;
7112 return true;
7113 }
6871 if (! tree_fits_uhwi_p (size) 7114 if (! tree_fits_uhwi_p (size)
6872 || TREE_OVERFLOW (size) 7115 || TREE_OVERFLOW (size)
6873 || tree_int_cst_sign_bit (size) != 0) 7116 || tree_int_cst_sign_bit (size) != 0)
6874 return false; 7117 return false;
6875 return true; 7118 return true;
6957 switch (code) 7200 switch (code)
6958 { 7201 {
6959 case WIDEN_MULT_PLUS_EXPR: 7202 case WIDEN_MULT_PLUS_EXPR:
6960 case WIDEN_MULT_MINUS_EXPR: 7203 case WIDEN_MULT_MINUS_EXPR:
6961 case DOT_PROD_EXPR: 7204 case DOT_PROD_EXPR:
6962 case FMA_EXPR:
6963 return true; 7205 return true;
6964 7206
6965 default: 7207 default:
6966 break; 7208 break;
6967 } 7209 }
7099 inchash::add_expr (TREE_REALPART (t), hstate, flags); 7341 inchash::add_expr (TREE_REALPART (t), hstate, flags);
7100 inchash::add_expr (TREE_IMAGPART (t), hstate, flags); 7342 inchash::add_expr (TREE_IMAGPART (t), hstate, flags);
7101 return; 7343 return;
7102 case VECTOR_CST: 7344 case VECTOR_CST:
7103 { 7345 {
7104 unsigned i; 7346 hstate.add_int (VECTOR_CST_NPATTERNS (t));
7105 for (i = 0; i < VECTOR_CST_NELTS (t); ++i) 7347 hstate.add_int (VECTOR_CST_NELTS_PER_PATTERN (t));
7106 inchash::add_expr (VECTOR_CST_ELT (t, i), hstate, flags); 7348 unsigned int count = vector_cst_encoded_nelts (t);
7349 for (unsigned int i = 0; i < count; ++i)
7350 inchash::add_expr (VECTOR_CST_ENCODED_ELT (t, i), hstate, flags);
7107 return; 7351 return;
7108 } 7352 }
7109 case SSA_NAME: 7353 case SSA_NAME:
7110 /* We can just compare by pointer. */ 7354 /* We can just compare by pointer. */
7111 hstate.add_hwi (SSA_NAME_VERSION (t)); 7355 hstate.add_hwi (SSA_NAME_VERSION (t));
7145 } 7389 }
7146 case TREE_VEC: 7390 case TREE_VEC:
7147 for (i = 0; i < TREE_VEC_LENGTH (t); ++i) 7391 for (i = 0; i < TREE_VEC_LENGTH (t); ++i)
7148 inchash::add_expr (TREE_VEC_ELT (t, i), hstate, flags); 7392 inchash::add_expr (TREE_VEC_ELT (t, i), hstate, flags);
7149 return; 7393 return;
7394 case IDENTIFIER_NODE:
7395 hstate.add_object (IDENTIFIER_HASH_VALUE (t));
7396 return;
7150 case FUNCTION_DECL: 7397 case FUNCTION_DECL:
7151 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form. 7398 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7152 Otherwise nodes that compare equal according to operand_equal_p might 7399 Otherwise nodes that compare equal according to operand_equal_p might
7153 get different hash codes. However, don't do this for machine specific 7400 get different hash codes. However, don't do this for machine specific
7154 or front end builtins, since the function code is overloaded in those 7401 or front end builtins, since the function code is overloaded in those
7159 t = builtin_decl_explicit (DECL_FUNCTION_CODE (t)); 7406 t = builtin_decl_explicit (DECL_FUNCTION_CODE (t));
7160 code = TREE_CODE (t); 7407 code = TREE_CODE (t);
7161 } 7408 }
7162 /* FALL THROUGH */ 7409 /* FALL THROUGH */
7163 default: 7410 default:
7411 if (POLY_INT_CST_P (t))
7412 {
7413 for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
7414 hstate.add_wide_int (wi::to_wide (POLY_INT_CST_COEFF (t, i)));
7415 return;
7416 }
7164 tclass = TREE_CODE_CLASS (code); 7417 tclass = TREE_CODE_CLASS (code);
7165 7418
7166 if (tclass == tcc_declaration) 7419 if (tclass == tcc_declaration)
7167 { 7420 {
7168 /* DECL's have a unique ID */ 7421 /* DECL's have a unique ID */
7235 7488
7236 case COND_EXPR: 7489 case COND_EXPR:
7237 flags &= ~OEP_ADDRESS_OF; 7490 flags &= ~OEP_ADDRESS_OF;
7238 break; 7491 break;
7239 7492
7240 case FMA_EXPR:
7241 case WIDEN_MULT_PLUS_EXPR: 7493 case WIDEN_MULT_PLUS_EXPR:
7242 case WIDEN_MULT_MINUS_EXPR: 7494 case WIDEN_MULT_MINUS_EXPR:
7243 { 7495 {
7244 /* The multiplication operands are commutative. */ 7496 /* The multiplication operands are commutative. */
7245 inchash::hash one, two; 7497 inchash::hash one, two;
7473 fixup_unsigned_type (itype); 7725 fixup_unsigned_type (itype);
7474 else 7726 else
7475 fixup_signed_type (itype); 7727 fixup_signed_type (itype);
7476 7728
7477 ret = itype; 7729 ret = itype;
7478 if (tree_fits_uhwi_p (TYPE_MAX_VALUE (itype))) 7730
7479 ret = type_hash_canon (tree_to_uhwi (TYPE_MAX_VALUE (itype)), itype); 7731 inchash::hash hstate;
7732 inchash::add_expr (TYPE_MAX_VALUE (itype), hstate);
7733 ret = type_hash_canon (hstate.end (), itype);
7480 if (precision <= MAX_INT_CACHED_PREC) 7734 if (precision <= MAX_INT_CACHED_PREC)
7481 nonstandard_integer_type_cache[precision + unsignedp] = ret; 7735 nonstandard_integer_type_cache[precision + unsignedp] = ret;
7482 7736
7483 return ret; 7737 return ret;
7484 } 7738 }
7696 7950
7697 /* Return a representation of ELT_TYPE[NELTS], using indices of type 7951 /* Return a representation of ELT_TYPE[NELTS], using indices of type
7698 sizetype. */ 7952 sizetype. */
7699 7953
7700 tree 7954 tree
7701 build_array_type_nelts (tree elt_type, unsigned HOST_WIDE_INT nelts) 7955 build_array_type_nelts (tree elt_type, poly_uint64 nelts)
7702 { 7956 {
7703 return build_array_type (elt_type, build_index_type (size_int (nelts - 1))); 7957 return build_array_type (elt_type, build_index_type (size_int (nelts - 1)));
7704 } 7958 }
7705 7959
7706 /* Recursively examines the array elements of TYPE, until a non-array 7960 /* Recursively examines the array elements of TYPE, until a non-array
8054 so the DECL_UIDs would not be stable wrt garbage collection. */ 8308 so the DECL_UIDs would not be stable wrt garbage collection. */
8055 8309
8056 tree 8310 tree
8057 build_complex_type (tree component_type, bool named) 8311 build_complex_type (tree component_type, bool named)
8058 { 8312 {
8059 tree t;
8060
8061 gcc_assert (INTEGRAL_TYPE_P (component_type) 8313 gcc_assert (INTEGRAL_TYPE_P (component_type)
8062 || SCALAR_FLOAT_TYPE_P (component_type) 8314 || SCALAR_FLOAT_TYPE_P (component_type)
8063 || FIXED_POINT_TYPE_P (component_type)); 8315 || FIXED_POINT_TYPE_P (component_type));
8064 8316
8065 /* Make a node of the sort we want. */ 8317 /* Make a node of the sort we want. */
8066 t = make_node (COMPLEX_TYPE); 8318 tree probe = make_node (COMPLEX_TYPE);
8067 8319
8068 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type); 8320 TREE_TYPE (probe) = TYPE_MAIN_VARIANT (component_type);
8069 8321
8070 /* If we already have such a type, use the old one. */ 8322 /* If we already have such a type, use the old one. */
8071 hashval_t hash = type_hash_canon_hash (t); 8323 hashval_t hash = type_hash_canon_hash (probe);
8072 t = type_hash_canon (hash, t); 8324 tree t = type_hash_canon (hash, probe);
8073 8325
8074 if (!COMPLETE_TYPE_P (t)) 8326 if (t == probe)
8075 layout_type (t); 8327 {
8076 8328 /* We created a new type. The hash insertion will have laid
8077 if (TYPE_CANONICAL (t) == t) 8329 out the type. We need to check the canonicalization and
8078 { 8330 maybe set the name. */
8079 if (TYPE_STRUCTURAL_EQUALITY_P (component_type)) 8331 gcc_checking_assert (COMPLETE_TYPE_P (t)
8332 && !TYPE_NAME (t)
8333 && TYPE_CANONICAL (t) == t);
8334
8335 if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))
8080 SET_TYPE_STRUCTURAL_EQUALITY (t); 8336 SET_TYPE_STRUCTURAL_EQUALITY (t);
8081 else if (TYPE_CANONICAL (component_type) != component_type) 8337 else if (TYPE_CANONICAL (TREE_TYPE (t)) != TREE_TYPE (t))
8082 TYPE_CANONICAL (t) 8338 TYPE_CANONICAL (t)
8083 = build_complex_type (TYPE_CANONICAL (component_type), named); 8339 = build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named);
8084 } 8340
8085 8341 /* We need to create a name, since complex is a fundamental type. */
8086 /* We need to create a name, since complex is a fundamental type. */ 8342 if (named)
8087 if (!TYPE_NAME (t) && named) 8343 {
8088 { 8344 const char *name = NULL;
8089 const char *name; 8345
8090 if (component_type == char_type_node) 8346 if (TREE_TYPE (t) == char_type_node)
8091 name = "complex char"; 8347 name = "complex char";
8092 else if (component_type == signed_char_type_node) 8348 else if (TREE_TYPE (t) == signed_char_type_node)
8093 name = "complex signed char"; 8349 name = "complex signed char";
8094 else if (component_type == unsigned_char_type_node) 8350 else if (TREE_TYPE (t) == unsigned_char_type_node)
8095 name = "complex unsigned char"; 8351 name = "complex unsigned char";
8096 else if (component_type == short_integer_type_node) 8352 else if (TREE_TYPE (t) == short_integer_type_node)
8097 name = "complex short int"; 8353 name = "complex short int";
8098 else if (component_type == short_unsigned_type_node) 8354 else if (TREE_TYPE (t) == short_unsigned_type_node)
8099 name = "complex short unsigned int"; 8355 name = "complex short unsigned int";
8100 else if (component_type == integer_type_node) 8356 else if (TREE_TYPE (t) == integer_type_node)
8101 name = "complex int"; 8357 name = "complex int";
8102 else if (component_type == unsigned_type_node) 8358 else if (TREE_TYPE (t) == unsigned_type_node)
8103 name = "complex unsigned int"; 8359 name = "complex unsigned int";
8104 else if (component_type == long_integer_type_node) 8360 else if (TREE_TYPE (t) == long_integer_type_node)
8105 name = "complex long int"; 8361 name = "complex long int";
8106 else if (component_type == long_unsigned_type_node) 8362 else if (TREE_TYPE (t) == long_unsigned_type_node)
8107 name = "complex long unsigned int"; 8363 name = "complex long unsigned int";
8108 else if (component_type == long_long_integer_type_node) 8364 else if (TREE_TYPE (t) == long_long_integer_type_node)
8109 name = "complex long long int"; 8365 name = "complex long long int";
8110 else if (component_type == long_long_unsigned_type_node) 8366 else if (TREE_TYPE (t) == long_long_unsigned_type_node)
8111 name = "complex long long unsigned int"; 8367 name = "complex long long unsigned int";
8112 else 8368
8113 name = 0; 8369 if (name != NULL)
8114 8370 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
8115 if (name != 0) 8371 get_identifier (name), t);
8116 TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, 8372 }
8117 get_identifier (name), t);
8118 } 8373 }
8119 8374
8120 return build_qualified_type (t, TYPE_QUALS (component_type)); 8375 return build_qualified_type (t, TYPE_QUALS (component_type));
8121 } 8376 }
8122 8377
8602 variable. */ 8857 variable. */
8603 #define RETURN_TRUE_IF_VAR(T) \ 8858 #define RETURN_TRUE_IF_VAR(T) \
8604 do { tree _t = (T); \ 8859 do { tree _t = (T); \
8605 if (_t != NULL_TREE \ 8860 if (_t != NULL_TREE \
8606 && _t != error_mark_node \ 8861 && _t != error_mark_node \
8607 && TREE_CODE (_t) != INTEGER_CST \ 8862 && !CONSTANT_CLASS_P (_t) \
8608 && TREE_CODE (_t) != PLACEHOLDER_EXPR \ 8863 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8609 && (!fn \ 8864 && (!fn \
8610 || (!TYPE_SIZES_GIMPLIFIED (type) \ 8865 || (!TYPE_SIZES_GIMPLIFIED (type) \
8611 && !is_gimple_sizepos (_t)) \ 8866 && (TREE_CODE (_t) != VAR_DECL \
8867 && !CONTAINS_PLACEHOLDER_P (_t))) \
8612 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \ 8868 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8613 return true; } while (0) 8869 return true; } while (0)
8614 8870
8615 if (type == error_mark_node) 8871 if (type == error_mark_node)
8616 return false; 8872 return false;
8699 get_containing_scope (const_tree t) 8955 get_containing_scope (const_tree t)
8700 { 8956 {
8701 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t)); 8957 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
8702 } 8958 }
8703 8959
8960 /* Returns the ultimate TRANSLATION_UNIT_DECL context of DECL or NULL. */
8961
8962 const_tree
8963 get_ultimate_context (const_tree decl)
8964 {
8965 while (decl && TREE_CODE (decl) != TRANSLATION_UNIT_DECL)
8966 {
8967 if (TREE_CODE (decl) == BLOCK)
8968 decl = BLOCK_SUPERCONTEXT (decl);
8969 else
8970 decl = get_containing_scope (decl);
8971 }
8972 return decl;
8973 }
8974
8704 /* Return the innermost context enclosing DECL that is 8975 /* Return the innermost context enclosing DECL that is
8705 a FUNCTION_DECL, or zero if none. */ 8976 a FUNCTION_DECL, or zero if none. */
8706 8977
8707 tree 8978 tree
8708 decl_function_context (const_tree decl) 8979 decl_function_context (const_tree decl)
8716 where we look up the function at runtime. Such functions always take 8987 where we look up the function at runtime. Such functions always take
8717 a first argument of type 'pointer to real context'. 8988 a first argument of type 'pointer to real context'.
8718 8989
8719 C++ should really be fixed to use DECL_CONTEXT for the real context, 8990 C++ should really be fixed to use DECL_CONTEXT for the real context,
8720 and use something else for the "virtual context". */ 8991 and use something else for the "virtual context". */
8721 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl)) 8992 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
8722 context 8993 context
8723 = TYPE_MAIN_VARIANT 8994 = TYPE_MAIN_VARIANT
8724 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); 8995 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
8725 else 8996 else
8726 context = DECL_CONTEXT (decl); 8997 context = DECL_CONTEXT (decl);
8826 9097
8827 if (!CALL_EXPR_FN (call)) 9098 if (!CALL_EXPR_FN (call))
8828 return as_combined_fn (CALL_EXPR_IFN (call)); 9099 return as_combined_fn (CALL_EXPR_IFN (call));
8829 9100
8830 tree fndecl = get_callee_fndecl (call); 9101 tree fndecl = get_callee_fndecl (call);
8831 if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) 9102 if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
8832 return as_combined_fn (DECL_FUNCTION_CODE (fndecl)); 9103 return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
8833 9104
8834 return CFN_LAST; 9105 return CFN_LAST;
8835 } 9106 }
8836 9107
8843 dump_tree_statistics (void) 9114 dump_tree_statistics (void)
8844 { 9115 {
8845 if (GATHER_STATISTICS) 9116 if (GATHER_STATISTICS)
8846 { 9117 {
8847 int i; 9118 int i;
8848 int total_nodes, total_bytes; 9119 uint64_t total_nodes, total_bytes;
8849 fprintf (stderr, "\nKind Nodes Bytes\n"); 9120 fprintf (stderr, "\nKind Nodes Bytes\n");
8850 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES); 9121 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8851 total_nodes = total_bytes = 0; 9122 total_nodes = total_bytes = 0;
8852 for (i = 0; i < (int) all_kinds; i++) 9123 for (i = 0; i < (int) all_kinds; i++)
8853 { 9124 {
8854 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i], 9125 fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n",
8855 tree_node_counts[i], tree_node_sizes[i]); 9126 tree_node_kind_names[i], tree_node_counts[i],
9127 tree_node_sizes[i]);
8856 total_nodes += tree_node_counts[i]; 9128 total_nodes += tree_node_counts[i];
8857 total_bytes += tree_node_sizes[i]; 9129 total_bytes += tree_node_sizes[i];
8858 } 9130 }
8859 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES); 9131 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8860 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes); 9132 fprintf (stderr, "%-20s %7" PRIu64 " %10" PRIu64 "\n", "Total",
9133 total_nodes, total_bytes);
8861 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES); 9134 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8862 fprintf (stderr, "Code Nodes\n"); 9135 fprintf (stderr, "Code Nodes\n");
8863 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES); 9136 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8864 for (i = 0; i < (int) MAX_TREE_CODES; i++) 9137 for (i = 0; i < (int) MAX_TREE_CODES; i++)
8865 fprintf (stderr, "%-32s %7d\n", get_tree_code_name ((enum tree_code) i), 9138 fprintf (stderr, "%-32s %7" PRIu64 "\n",
8866 tree_code_counts[i]); 9139 get_tree_code_name ((enum tree_code) i), tree_code_counts[i]);
8867 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES); 9140 mem_usage::print_dash_line (TREE_MEM_USAGE_SPACES);
8868 fprintf (stderr, "\n"); 9141 fprintf (stderr, "\n");
8869 ssanames_print_statistics (); 9142 ssanames_print_statistics ();
8870 fprintf (stderr, "\n"); 9143 fprintf (stderr, "\n");
8871 phinodes_print_statistics (); 9144 phinodes_print_statistics ();
9322 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function, 9595 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
9323 trim_filename (file), line); 9596 trim_filename (file), line);
9324 } 9597 }
9325 #endif /* ENABLE_TREE_CHECKING */ 9598 #endif /* ENABLE_TREE_CHECKING */
9326 9599
9327 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE, 9600 /* Create a new vector type node holding NUNITS units of type INNERTYPE,
9328 and mapped to the machine mode MODE. Initialize its fields and build 9601 and mapped to the machine mode MODE. Initialize its fields and build
9329 the information necessary for debugging output. */ 9602 the information necessary for debugging output. */
9330 9603
9331 static tree 9604 static tree
9332 make_vector_type (tree innertype, int nunits, machine_mode mode) 9605 make_vector_type (tree innertype, poly_int64 nunits, machine_mode mode)
9333 { 9606 {
9334 tree t; 9607 tree t;
9335 tree mv_innertype = TYPE_MAIN_VARIANT (innertype); 9608 tree mv_innertype = TYPE_MAIN_VARIANT (innertype);
9336 9609
9337 t = make_node (VECTOR_TYPE); 9610 t = make_node (VECTOR_TYPE);
9544 9817
9545 for (i = 0; i < NUM_INT_N_ENTS; i ++) 9818 for (i = 0; i < NUM_INT_N_ENTS; i ++)
9546 { 9819 {
9547 int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize); 9820 int_n_trees[i].signed_type = make_signed_type (int_n_data[i].bitsize);
9548 int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize); 9821 int_n_trees[i].unsigned_type = make_unsigned_type (int_n_data[i].bitsize);
9549 TYPE_SIZE (int_n_trees[i].signed_type) = bitsize_int (int_n_data[i].bitsize); 9822
9550 TYPE_SIZE (int_n_trees[i].unsigned_type) = bitsize_int (int_n_data[i].bitsize); 9823 if (int_n_enabled_p[i])
9551
9552 if (int_n_data[i].bitsize > LONG_LONG_TYPE_SIZE
9553 && int_n_enabled_p[i])
9554 { 9824 {
9555 integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type; 9825 integer_types[itk_intN_0 + i * 2] = int_n_trees[i].signed_type;
9556 integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type; 9826 integer_types[itk_unsigned_intN_0 + i * 2] = int_n_trees[i].unsigned_type;
9557 } 9827 }
9558 } 9828 }
9667 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node); 9937 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
9668 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node); 9938 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
9669 9939
9670 void_type_node = make_node (VOID_TYPE); 9940 void_type_node = make_node (VOID_TYPE);
9671 layout_type (void_type_node); 9941 layout_type (void_type_node);
9672
9673 pointer_bounds_type_node = targetm.chkp_bound_type ();
9674 9942
9675 /* We are not going to have real types in C with less than byte alignment, 9943 /* We are not going to have real types in C with less than byte alignment,
9676 so we might as well not have any types that claim to have it. */ 9944 so we might as well not have any types that claim to have it. */
9677 SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT); 9945 SET_TYPE_ALIGN (void_type_node, BITS_PER_UNIT);
9678 TYPE_USER_ALIGN (void_type_node) = 0; 9946 TYPE_USER_ALIGN (void_type_node) = 0;
10038 NULL_TREE); 10306 NULL_TREE);
10039 local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ, 10307 local_define_builtin ("__builtin_memcmp_eq", ftype, BUILT_IN_MEMCMP_EQ,
10040 "__builtin_memcmp_eq", 10308 "__builtin_memcmp_eq",
10041 ECF_PURE | ECF_NOTHROW | ECF_LEAF); 10309 ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10042 10310
10311 local_define_builtin ("__builtin_strncmp_eq", ftype, BUILT_IN_STRNCMP_EQ,
10312 "__builtin_strncmp_eq",
10313 ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10314
10315 local_define_builtin ("__builtin_strcmp_eq", ftype, BUILT_IN_STRCMP_EQ,
10316 "__builtin_strcmp_eq",
10317 ECF_PURE | ECF_NOTHROW | ECF_LEAF);
10318
10043 /* If there's a possibility that we might use the ARM EABI, build the 10319 /* If there's a possibility that we might use the ARM EABI, build the
10044 alternate __cxa_end_cleanup node used to resume from C++. */ 10320 alternate __cxa_end_cleanup node used to resume from C++. */
10045 if (targetm.arm_eabi_unwinder) 10321 if (targetm.arm_eabi_unwinder)
10046 { 10322 {
10047 ftype = build_function_type_list (void_type_node, NULL_TREE); 10323 ftype = build_function_type_list (void_type_node, NULL_TREE);
10143 10419
10144 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++) 10420 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
10145 *q = TOLOWER (*p); 10421 *q = TOLOWER (*p);
10146 *q = '\0'; 10422 *q = '\0';
10147 10423
10424 /* For -ftrapping-math these should throw from a former
10425 -fnon-call-exception stmt. */
10148 built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3", 10426 built_in_names[mcode] = concat (prefix, "mul", mode_name_buf, "3",
10149 NULL); 10427 NULL);
10150 local_define_builtin (built_in_names[mcode], ftype, mcode, 10428 local_define_builtin (built_in_names[mcode], ftype, mcode,
10151 built_in_names[mcode], 10429 built_in_names[mcode],
10152 ECF_CONST | ECF_NOTHROW | ECF_LEAF); 10430 ECF_CONST | ECF_LEAF);
10153 10431
10154 built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3", 10432 built_in_names[dcode] = concat (prefix, "div", mode_name_buf, "3",
10155 NULL); 10433 NULL);
10156 local_define_builtin (built_in_names[dcode], ftype, dcode, 10434 local_define_builtin (built_in_names[dcode], ftype, dcode,
10157 built_in_names[dcode], 10435 built_in_names[dcode],
10158 ECF_CONST | ECF_NOTHROW | ECF_LEAF); 10436 ECF_CONST | ECF_LEAF);
10159 } 10437 }
10160 } 10438 }
10161 10439
10162 init_internal_fns (); 10440 init_internal_fns ();
10163 } 10441 }
10225 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and 10503 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10226 the inner type. */ 10504 the inner type. */
10227 tree 10505 tree
10228 build_vector_type_for_mode (tree innertype, machine_mode mode) 10506 build_vector_type_for_mode (tree innertype, machine_mode mode)
10229 { 10507 {
10230 int nunits; 10508 poly_int64 nunits;
10231 unsigned int bitsize; 10509 unsigned int bitsize;
10232 10510
10233 switch (GET_MODE_CLASS (mode)) 10511 switch (GET_MODE_CLASS (mode))
10234 { 10512 {
10513 case MODE_VECTOR_BOOL:
10235 case MODE_VECTOR_INT: 10514 case MODE_VECTOR_INT:
10236 case MODE_VECTOR_FLOAT: 10515 case MODE_VECTOR_FLOAT:
10237 case MODE_VECTOR_FRACT: 10516 case MODE_VECTOR_FRACT:
10238 case MODE_VECTOR_UFRACT: 10517 case MODE_VECTOR_UFRACT:
10239 case MODE_VECTOR_ACCUM: 10518 case MODE_VECTOR_ACCUM:
10257 10536
10258 /* Similarly, but takes the inner type and number of units, which must be 10537 /* Similarly, but takes the inner type and number of units, which must be
10259 a power of two. */ 10538 a power of two. */
10260 10539
10261 tree 10540 tree
10262 build_vector_type (tree innertype, int nunits) 10541 build_vector_type (tree innertype, poly_int64 nunits)
10263 { 10542 {
10264 return make_vector_type (innertype, nunits, VOIDmode); 10543 return make_vector_type (innertype, nunits, VOIDmode);
10265 } 10544 }
10266 10545
10267 /* Build truth vector with specified length and number of units. */ 10546 /* Build truth vector with specified length and number of units. */
10268 10547
10269 tree 10548 tree
10270 build_truth_vector_type (unsigned nunits, unsigned vector_size) 10549 build_truth_vector_type (poly_uint64 nunits, poly_uint64 vector_size)
10271 { 10550 {
10272 machine_mode mask_mode 10551 machine_mode mask_mode
10273 = targetm.vectorize.get_mask_mode (nunits, vector_size).else_blk (); 10552 = targetm.vectorize.get_mask_mode (nunits, vector_size).else_blk ();
10274 10553
10275 unsigned HOST_WIDE_INT vsize; 10554 poly_uint64 vsize;
10276 if (mask_mode == BLKmode) 10555 if (mask_mode == BLKmode)
10277 vsize = vector_size * BITS_PER_UNIT; 10556 vsize = vector_size * BITS_PER_UNIT;
10278 else 10557 else
10279 vsize = GET_MODE_BITSIZE (mask_mode); 10558 vsize = GET_MODE_BITSIZE (mask_mode);
10280 10559
10281 unsigned HOST_WIDE_INT esize = vsize / nunits; 10560 unsigned HOST_WIDE_INT esize = vector_element_size (vsize, nunits);
10282 gcc_assert (esize * nunits == vsize);
10283 10561
10284 tree bool_type = build_nonstandard_boolean_type (esize); 10562 tree bool_type = build_nonstandard_boolean_type (esize);
10285 10563
10286 return make_vector_type (bool_type, nunits, mask_mode); 10564 return make_vector_type (bool_type, nunits, mask_mode);
10287 } 10565 }
10292 build_same_sized_truth_vector_type (tree vectype) 10570 build_same_sized_truth_vector_type (tree vectype)
10293 { 10571 {
10294 if (VECTOR_BOOLEAN_TYPE_P (vectype)) 10572 if (VECTOR_BOOLEAN_TYPE_P (vectype))
10295 return vectype; 10573 return vectype;
10296 10574
10297 unsigned HOST_WIDE_INT size = GET_MODE_SIZE (TYPE_MODE (vectype)); 10575 poly_uint64 size = GET_MODE_SIZE (TYPE_MODE (vectype));
10298 10576
10299 if (!size) 10577 if (known_eq (size, 0U))
10300 size = tree_to_uhwi (TYPE_SIZE_UNIT (vectype)); 10578 size = tree_to_uhwi (TYPE_SIZE_UNIT (vectype));
10301 10579
10302 return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (vectype), size); 10580 return build_truth_vector_type (TYPE_VECTOR_SUBPARTS (vectype), size);
10303 } 10581 }
10304 10582
10305 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */ 10583 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10306 10584
10307 tree 10585 tree
10308 build_opaque_vector_type (tree innertype, int nunits) 10586 build_opaque_vector_type (tree innertype, poly_int64 nunits)
10309 { 10587 {
10310 tree t = make_vector_type (innertype, nunits, VOIDmode); 10588 tree t = make_vector_type (innertype, nunits, VOIDmode);
10311 tree cand; 10589 tree cand;
10312 /* We always build the non-opaque variant before the opaque one, 10590 /* We always build the non-opaque variant before the opaque one,
10313 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */ 10591 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10325 TYPE_NEXT_VARIANT (t) = cand; 10603 TYPE_NEXT_VARIANT (t) = cand;
10326 TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t); 10604 TYPE_MAIN_VARIANT (cand) = TYPE_MAIN_VARIANT (t);
10327 return cand; 10605 return cand;
10328 } 10606 }
10329 10607
10608 /* Return the value of element I of VECTOR_CST T as a wide_int. */
10609
10610 wide_int
10611 vector_cst_int_elt (const_tree t, unsigned int i)
10612 {
10613 /* First handle elements that are directly encoded. */
10614 unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10615 if (i < encoded_nelts)
10616 return wi::to_wide (VECTOR_CST_ENCODED_ELT (t, i));
10617
10618 /* Identify the pattern that contains element I and work out the index of
10619 the last encoded element for that pattern. */
10620 unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10621 unsigned int pattern = i % npatterns;
10622 unsigned int count = i / npatterns;
10623 unsigned int final_i = encoded_nelts - npatterns + pattern;
10624
10625 /* If there are no steps, the final encoded value is the right one. */
10626 if (!VECTOR_CST_STEPPED_P (t))
10627 return wi::to_wide (VECTOR_CST_ENCODED_ELT (t, final_i));
10628
10629 /* Otherwise work out the value from the last two encoded elements. */
10630 tree v1 = VECTOR_CST_ENCODED_ELT (t, final_i - npatterns);
10631 tree v2 = VECTOR_CST_ENCODED_ELT (t, final_i);
10632 wide_int diff = wi::to_wide (v2) - wi::to_wide (v1);
10633 return wi::to_wide (v2) + (count - 2) * diff;
10634 }
10635
10636 /* Return the value of element I of VECTOR_CST T. */
10637
10638 tree
10639 vector_cst_elt (const_tree t, unsigned int i)
10640 {
10641 /* First handle elements that are directly encoded. */
10642 unsigned int encoded_nelts = vector_cst_encoded_nelts (t);
10643 if (i < encoded_nelts)
10644 return VECTOR_CST_ENCODED_ELT (t, i);
10645
10646 /* If there are no steps, the final encoded value is the right one. */
10647 if (!VECTOR_CST_STEPPED_P (t))
10648 {
10649 /* Identify the pattern that contains element I and work out the index of
10650 the last encoded element for that pattern. */
10651 unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
10652 unsigned int pattern = i % npatterns;
10653 unsigned int final_i = encoded_nelts - npatterns + pattern;
10654 return VECTOR_CST_ENCODED_ELT (t, final_i);
10655 }
10656
10657 /* Otherwise work out the value from the last two encoded elements. */
10658 return wide_int_to_tree (TREE_TYPE (TREE_TYPE (t)),
10659 vector_cst_int_elt (t, i));
10660 }
10330 10661
10331 /* Given an initializer INIT, return TRUE if INIT is zero or some 10662 /* Given an initializer INIT, return TRUE if INIT is zero or some
10332 aggregate of zeros. Otherwise return FALSE. */ 10663 aggregate of zeros. Otherwise return FALSE. If NONZERO is not
10664 null, set *NONZERO if and only if INIT is known not to be all
10665 zeros. The combination of return value of false and *NONZERO
10666 false implies that INIT may but need not be all zeros. Other
10667 combinations indicate definitive answers. */
10668
10333 bool 10669 bool
10334 initializer_zerop (const_tree init) 10670 initializer_zerop (const_tree init, bool *nonzero /* = NULL */)
10335 { 10671 {
10336 tree elt; 10672 bool dummy;
10673 if (!nonzero)
10674 nonzero = &dummy;
10675
10676 /* Conservatively clear NONZERO and set it only if INIT is definitely
10677 not all zero. */
10678 *nonzero = false;
10337 10679
10338 STRIP_NOPS (init); 10680 STRIP_NOPS (init);
10339 10681
10682 unsigned HOST_WIDE_INT off = 0;
10683
10340 switch (TREE_CODE (init)) 10684 switch (TREE_CODE (init))
10341 { 10685 {
10342 case INTEGER_CST: 10686 case INTEGER_CST:
10343 return integer_zerop (init); 10687 if (integer_zerop (init))
10688 return true;
10689
10690 *nonzero = true;
10691 return false;
10344 10692
10345 case REAL_CST: 10693 case REAL_CST:
10346 /* ??? Note that this is not correct for C4X float formats. There, 10694 /* ??? Note that this is not correct for C4X float formats. There,
10347 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most 10695 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10348 negative exponent. */ 10696 negative exponent. */
10349 return real_zerop (init) 10697 if (real_zerop (init)
10350 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)); 10698 && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init)))
10699 return true;
10700
10701 *nonzero = true;
10702 return false;
10351 10703
10352 case FIXED_CST: 10704 case FIXED_CST:
10353 return fixed_zerop (init); 10705 if (fixed_zerop (init))
10706 return true;
10707
10708 *nonzero = true;
10709 return false;
10354 10710
10355 case COMPLEX_CST: 10711 case COMPLEX_CST:
10356 return integer_zerop (init) 10712 if (integer_zerop (init)
10357 || (real_zerop (init) 10713 || (real_zerop (init)
10358 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init))) 10714 && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
10359 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))); 10715 && !REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init)))))
10716 return true;
10717
10718 *nonzero = true;
10719 return false;
10360 10720
10361 case VECTOR_CST: 10721 case VECTOR_CST:
10722 if (VECTOR_CST_NPATTERNS (init) == 1
10723 && VECTOR_CST_DUPLICATE_P (init)
10724 && initializer_zerop (VECTOR_CST_ENCODED_ELT (init, 0)))
10725 return true;
10726
10727 *nonzero = true;
10728 return false;
10729
10730 case CONSTRUCTOR:
10362 { 10731 {
10363 unsigned i; 10732 if (TREE_CLOBBER_P (init))
10364 for (i = 0; i < VECTOR_CST_NELTS (init); ++i) 10733 return false;
10365 if (!initializer_zerop (VECTOR_CST_ELT (init, i))) 10734
10735 unsigned HOST_WIDE_INT idx;
10736 tree elt;
10737
10738 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
10739 if (!initializer_zerop (elt, nonzero))
10366 return false; 10740 return false;
10741
10367 return true; 10742 return true;
10368 } 10743 }
10369 10744
10370 case CONSTRUCTOR: 10745 case MEM_REF:
10371 { 10746 {
10372 unsigned HOST_WIDE_INT idx; 10747 tree arg = TREE_OPERAND (init, 0);
10373 10748 if (TREE_CODE (arg) != ADDR_EXPR)
10374 if (TREE_CLOBBER_P (init))
10375 return false; 10749 return false;
10376 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt) 10750 tree offset = TREE_OPERAND (init, 1);
10377 if (!initializer_zerop (elt)) 10751 if (TREE_CODE (offset) != INTEGER_CST
10378 return false; 10752 || !tree_fits_uhwi_p (offset))
10379 return true; 10753 return false;
10754 off = tree_to_uhwi (offset);
10755 if (INT_MAX < off)
10756 return false;
10757 arg = TREE_OPERAND (arg, 0);
10758 if (TREE_CODE (arg) != STRING_CST)
10759 return false;
10760 init = arg;
10380 } 10761 }
10762 /* Fall through. */
10381 10763
10382 case STRING_CST: 10764 case STRING_CST:
10383 { 10765 {
10384 int i; 10766 gcc_assert (off <= INT_MAX);
10767
10768 int i = off;
10769 int n = TREE_STRING_LENGTH (init);
10770 if (n <= i)
10771 return false;
10385 10772
10386 /* We need to loop through all elements to handle cases like 10773 /* We need to loop through all elements to handle cases like
10387 "\0" and "\0foobar". */ 10774 "\0" and "\0foobar". */
10388 for (i = 0; i < TREE_STRING_LENGTH (init); ++i) 10775 for (i = 0; i < n; ++i)
10389 if (TREE_STRING_POINTER (init)[i] != '\0') 10776 if (TREE_STRING_POINTER (init)[i] != '\0')
10390 return false; 10777 {
10778 *nonzero = true;
10779 return false;
10780 }
10391 10781
10392 return true; 10782 return true;
10393 } 10783 }
10394 10784
10395 default: 10785 default:
10403 or NULL_TREE if the vector is not uniform. */ 10793 or NULL_TREE if the vector is not uniform. */
10404 tree 10794 tree
10405 uniform_vector_p (const_tree vec) 10795 uniform_vector_p (const_tree vec)
10406 { 10796 {
10407 tree first, t; 10797 tree first, t;
10408 unsigned i; 10798 unsigned HOST_WIDE_INT i, nelts;
10409 10799
10410 if (vec == NULL_TREE) 10800 if (vec == NULL_TREE)
10411 return NULL_TREE; 10801 return NULL_TREE;
10412 10802
10413 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec))); 10803 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec)));
10414 10804
10415 if (TREE_CODE (vec) == VECTOR_CST) 10805 if (TREE_CODE (vec) == VEC_DUPLICATE_EXPR)
10416 { 10806 return TREE_OPERAND (vec, 0);
10417 first = VECTOR_CST_ELT (vec, 0); 10807
10418 for (i = 1; i < VECTOR_CST_NELTS (vec); ++i) 10808 else if (TREE_CODE (vec) == VECTOR_CST)
10419 if (!operand_equal_p (first, VECTOR_CST_ELT (vec, i), 0)) 10809 {
10420 return NULL_TREE; 10810 if (VECTOR_CST_NPATTERNS (vec) == 1 && VECTOR_CST_DUPLICATE_P (vec))
10421 10811 return VECTOR_CST_ENCODED_ELT (vec, 0);
10422 return first; 10812 return NULL_TREE;
10423 } 10813 }
10424 10814
10425 else if (TREE_CODE (vec) == CONSTRUCTOR) 10815 else if (TREE_CODE (vec) == CONSTRUCTOR
10816 && TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec)).is_constant (&nelts))
10426 { 10817 {
10427 first = error_mark_node; 10818 first = error_mark_node;
10428 10819
10429 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t) 10820 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec), i, t)
10430 { 10821 {
10434 continue; 10825 continue;
10435 } 10826 }
10436 if (!operand_equal_p (first, t, 0)) 10827 if (!operand_equal_p (first, t, 0))
10437 return NULL_TREE; 10828 return NULL_TREE;
10438 } 10829 }
10439 if (i != TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec))) 10830 if (i != nelts)
10440 return NULL_TREE; 10831 return NULL_TREE;
10441 10832
10442 return first; 10833 return first;
10443 } 10834 }
10444 10835
10816 if TYPE is already an integer type of signedness UNSIGNEDP. */ 11207 if TYPE is already an integer type of signedness UNSIGNEDP. */
10817 11208
10818 tree 11209 tree
10819 signed_or_unsigned_type_for (int unsignedp, tree type) 11210 signed_or_unsigned_type_for (int unsignedp, tree type)
10820 { 11211 {
10821 if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type) == unsignedp) 11212 if (ANY_INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) == unsignedp)
10822 return type; 11213 return type;
10823 11214
10824 if (TREE_CODE (type) == VECTOR_TYPE) 11215 if (TREE_CODE (type) == VECTOR_TYPE)
10825 { 11216 {
10826 tree inner = TREE_TYPE (type); 11217 tree inner = TREE_TYPE (type);
10828 if (!inner2) 11219 if (!inner2)
10829 return NULL_TREE; 11220 return NULL_TREE;
10830 if (inner == inner2) 11221 if (inner == inner2)
10831 return type; 11222 return type;
10832 return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type)); 11223 return build_vector_type (inner2, TYPE_VECTOR_SUBPARTS (type));
11224 }
11225
11226 if (TREE_CODE (type) == COMPLEX_TYPE)
11227 {
11228 tree inner = TREE_TYPE (type);
11229 tree inner2 = signed_or_unsigned_type_for (unsignedp, inner);
11230 if (!inner2)
11231 return NULL_TREE;
11232 if (inner == inner2)
11233 return type;
11234 return build_complex_type (inner2);
10833 } 11235 }
10834 11236
10835 if (!INTEGRAL_TYPE_P (type) 11237 if (!INTEGRAL_TYPE_P (type)
10836 && !POINTER_TYPE_P (type) 11238 && !POINTER_TYPE_P (type)
10837 && TREE_CODE (type) != OFFSET_TYPE) 11239 && TREE_CODE (type) != OFFSET_TYPE)
11258 case OMP_CLAUSE_LINK: 11660 case OMP_CLAUSE_LINK:
11259 case OMP_CLAUSE_USE_DEVICE_PTR: 11661 case OMP_CLAUSE_USE_DEVICE_PTR:
11260 case OMP_CLAUSE_IS_DEVICE_PTR: 11662 case OMP_CLAUSE_IS_DEVICE_PTR:
11261 case OMP_CLAUSE__LOOPTEMP_: 11663 case OMP_CLAUSE__LOOPTEMP_:
11262 case OMP_CLAUSE__SIMDUID_: 11664 case OMP_CLAUSE__SIMDUID_:
11263 case OMP_CLAUSE__CILK_FOR_COUNT_:
11264 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0)); 11665 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
11265 /* FALLTHRU */ 11666 /* FALLTHRU */
11266 11667
11267 case OMP_CLAUSE_INDEPENDENT: 11668 case OMP_CLAUSE_INDEPENDENT:
11268 case OMP_CLAUSE_NOWAIT: 11669 case OMP_CLAUSE_NOWAIT:
11282 case OMP_CLAUSE_DEFAULTMAP: 11683 case OMP_CLAUSE_DEFAULTMAP:
11283 case OMP_CLAUSE_AUTO: 11684 case OMP_CLAUSE_AUTO:
11284 case OMP_CLAUSE_SEQ: 11685 case OMP_CLAUSE_SEQ:
11285 case OMP_CLAUSE_TILE: 11686 case OMP_CLAUSE_TILE:
11286 case OMP_CLAUSE__SIMT_: 11687 case OMP_CLAUSE__SIMT_:
11688 case OMP_CLAUSE_IF_PRESENT:
11689 case OMP_CLAUSE_FINALIZE:
11287 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp)); 11690 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
11288 11691
11289 case OMP_CLAUSE_LASTPRIVATE: 11692 case OMP_CLAUSE_LASTPRIVATE:
11290 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp)); 11693 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp));
11291 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp)); 11694 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp));
11570 11973
11571 while (block && TREE_CODE (block) == BLOCK 11974 while (block && TREE_CODE (block) == BLOCK
11572 && BLOCK_ABSTRACT_ORIGIN (block)) 11975 && BLOCK_ABSTRACT_ORIGIN (block))
11573 { 11976 {
11574 tree ao = BLOCK_ABSTRACT_ORIGIN (block); 11977 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
11575
11576 while (TREE_CODE (ao) == BLOCK
11577 && BLOCK_ABSTRACT_ORIGIN (ao)
11578 && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
11579 ao = BLOCK_ABSTRACT_ORIGIN (ao);
11580
11581 if (TREE_CODE (ao) == FUNCTION_DECL) 11978 if (TREE_CODE (ao) == FUNCTION_DECL)
11582 { 11979 {
11583 /* If AO is an artificial inline, point RET to the 11980 /* If AO is an artificial inline, point RET to the
11584 call site locus at which it has been inlined and continue 11981 call site locus at which it has been inlined and continue
11585 the loop, in case AO's caller is also an artificial 11982 the loop, in case AO's caller is also an artificial
11656 bool 12053 bool
11657 cl_option_hasher::equal (tree x, tree y) 12054 cl_option_hasher::equal (tree x, tree y)
11658 { 12055 {
11659 const_tree const xt = x; 12056 const_tree const xt = x;
11660 const_tree const yt = y; 12057 const_tree const yt = y;
11661 const char *xp;
11662 const char *yp;
11663 size_t len;
11664 12058
11665 if (TREE_CODE (xt) != TREE_CODE (yt)) 12059 if (TREE_CODE (xt) != TREE_CODE (yt))
11666 return 0; 12060 return 0;
11667 12061
11668 if (TREE_CODE (xt) == OPTIMIZATION_NODE) 12062 if (TREE_CODE (xt) == OPTIMIZATION_NODE)
11669 { 12063 return cl_optimization_option_eq (TREE_OPTIMIZATION (xt),
11670 xp = (const char *)TREE_OPTIMIZATION (xt); 12064 TREE_OPTIMIZATION (yt));
11671 yp = (const char *)TREE_OPTIMIZATION (yt);
11672 len = sizeof (struct cl_optimization);
11673 }
11674
11675 else if (TREE_CODE (xt) == TARGET_OPTION_NODE) 12065 else if (TREE_CODE (xt) == TARGET_OPTION_NODE)
11676 { 12066 return cl_target_option_eq (TREE_TARGET_OPTION (xt),
11677 return cl_target_option_eq (TREE_TARGET_OPTION (xt), 12067 TREE_TARGET_OPTION (yt));
11678 TREE_TARGET_OPTION (yt));
11679 }
11680
11681 else 12068 else
11682 gcc_unreachable (); 12069 gcc_unreachable ();
11683
11684 return (memcmp (xp, yp, len) == 0);
11685 } 12070 }
11686 12071
11687 /* Build an OPTIMIZATION_NODE based on the options in OPTS. */ 12072 /* Build an OPTIMIZATION_NODE based on the options in OPTS. */
11688 12073
11689 tree 12074 tree
11748 for (; iter != cl_option_hash_table->end (); ++iter) 12133 for (; iter != cl_option_hash_table->end (); ++iter)
11749 if (TREE_CODE (*iter) == TARGET_OPTION_NODE) 12134 if (TREE_CODE (*iter) == TARGET_OPTION_NODE)
11750 TREE_TARGET_GLOBALS (*iter) = NULL; 12135 TREE_TARGET_GLOBALS (*iter) = NULL;
11751 } 12136 }
11752 12137
11753 /* Determine the "ultimate origin" of a block. The block may be an inlined 12138 /* Determine the "ultimate origin" of a block. */
11754 instance of an inlined instance of a block which is local to an inline
11755 function, so we have to trace all of the way back through the origin chain
11756 to find out what sort of node actually served as the original seed for the
11757 given block. */
11758 12139
11759 tree 12140 tree
11760 block_ultimate_origin (const_tree block) 12141 block_ultimate_origin (const_tree block)
11761 { 12142 {
11762 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); 12143 tree origin = BLOCK_ABSTRACT_ORIGIN (block);
11763 12144
11764 /* BLOCK_ABSTRACT_ORIGIN can point to itself; ignore that if 12145 if (origin == NULL_TREE)
11765 we're trying to output the abstract instance of this function. */
11766 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
11767 return NULL_TREE;
11768
11769 if (immediate_origin == NULL_TREE)
11770 return NULL_TREE; 12146 return NULL_TREE;
11771 else 12147 else
11772 { 12148 {
11773 tree ret_val; 12149 gcc_checking_assert ((DECL_P (origin)
11774 tree lookahead = immediate_origin; 12150 && DECL_ORIGIN (origin) == origin)
11775 12151 || BLOCK_ORIGIN (origin) == origin);
11776 do 12152 return origin;
11777 {
11778 ret_val = lookahead;
11779 lookahead = (TREE_CODE (ret_val) == BLOCK
11780 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
11781 }
11782 while (lookahead != NULL && lookahead != ret_val);
11783
11784 /* The block's abstract origin chain may not be the *ultimate* origin of
11785 the block. It could lead to a DECL that has an abstract origin set.
11786 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
11787 will give us if it has one). Note that DECL's abstract origins are
11788 supposed to be the most distant ancestor (or so decl_ultimate_origin
11789 claims), so we don't need to loop following the DECL origins. */
11790 if (DECL_P (ret_val))
11791 return DECL_ORIGIN (ret_val);
11792
11793 return ret_val;
11794 } 12153 }
11795 } 12154 }
11796 12155
11797 /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates 12156 /* Return true iff conversion from INNER_TYPE to OUTER_TYPE generates
11798 no instruction. */ 12157 no instruction. */
11839 static inline bool 12198 static inline bool
11840 tree_nop_conversion (const_tree exp) 12199 tree_nop_conversion (const_tree exp)
11841 { 12200 {
11842 tree outer_type, inner_type; 12201 tree outer_type, inner_type;
11843 12202
12203 if (location_wrapper_p (exp))
12204 return true;
11844 if (!CONVERT_EXPR_P (exp) 12205 if (!CONVERT_EXPR_P (exp)
11845 && TREE_CODE (exp) != NON_LVALUE_EXPR) 12206 && TREE_CODE (exp) != NON_LVALUE_EXPR)
11846 return false; 12207 return false;
11847 if (TREE_OPERAND (exp, 0) == error_mark_node) 12208 if (TREE_OPERAND (exp, 0) == error_mark_node)
11848 return false; 12209 return false;
12050 /* Try to find a base info of BINFO that would have its field decl at offset 12411 /* Try to find a base info of BINFO that would have its field decl at offset
12051 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be 12412 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
12052 found, return, otherwise return NULL_TREE. */ 12413 found, return, otherwise return NULL_TREE. */
12053 12414
12054 tree 12415 tree
12055 get_binfo_at_offset (tree binfo, HOST_WIDE_INT offset, tree expected_type) 12416 get_binfo_at_offset (tree binfo, poly_int64 offset, tree expected_type)
12056 { 12417 {
12057 tree type = BINFO_TYPE (binfo); 12418 tree type = BINFO_TYPE (binfo);
12058 12419
12059 while (true) 12420 while (true)
12060 { 12421 {
12062 tree fld; 12423 tree fld;
12063 int i; 12424 int i;
12064 12425
12065 if (types_same_for_odr (type, expected_type)) 12426 if (types_same_for_odr (type, expected_type))
12066 return binfo; 12427 return binfo;
12067 if (offset < 0) 12428 if (maybe_lt (offset, 0))
12068 return NULL_TREE; 12429 return NULL_TREE;
12069 12430
12070 for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld)) 12431 for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))
12071 { 12432 {
12072 if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld)) 12433 if (TREE_CODE (fld) != FIELD_DECL || !DECL_ARTIFICIAL (fld))
12073 continue; 12434 continue;
12074 12435
12075 pos = int_bit_position (fld); 12436 pos = int_bit_position (fld);
12076 size = tree_to_uhwi (DECL_SIZE (fld)); 12437 size = tree_to_uhwi (DECL_SIZE (fld));
12077 if (pos <= offset && (pos + size) > offset) 12438 if (known_in_range_p (offset, pos, size))
12078 break; 12439 break;
12079 } 12440 }
12080 if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE) 12441 if (!fld || TREE_CODE (TREE_TYPE (fld)) != RECORD_TYPE)
12081 return NULL_TREE; 12442 return NULL_TREE;
12082 12443
12083 /* Offset 0 indicates the primary base, whose vtable contents are 12444 /* Offset 0 indicates the primary base, whose vtable contents are
12084 represented in the binfo for the derived class. */ 12445 represented in the binfo for the derived class. */
12085 else if (offset != 0) 12446 else if (maybe_ne (offset, 0))
12086 { 12447 {
12087 tree found_binfo = NULL, base_binfo; 12448 tree found_binfo = NULL, base_binfo;
12088 /* Offsets in BINFO are in bytes relative to the whole structure 12449 /* Offsets in BINFO are in bytes relative to the whole structure
12089 while POS is in bits relative to the containing field. */ 12450 while POS is in bits relative to the containing field. */
12090 int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos 12451 int binfo_offset = (tree_to_shwi (BINFO_OFFSET (binfo)) + pos
12124 typedef_variant_p (const_tree type) 12485 typedef_variant_p (const_tree type)
12125 { 12486 {
12126 return is_typedef_decl (TYPE_NAME (type)); 12487 return is_typedef_decl (TYPE_NAME (type));
12127 } 12488 }
12128 12489
12129 /* Warn about a use of an identifier which was marked deprecated. */ 12490 /* A class to handle converting a string that might contain
12491 control characters, (eg newline, form-feed, etc), into one
12492 in which contains escape sequences instead. */
12493
12494 class escaped_string
12495 {
12496 public:
12497 escaped_string () { m_owned = false; m_str = NULL; };
12498 ~escaped_string () { if (m_owned) free (m_str); }
12499 operator const char *() const { return (const char *) m_str; }
12500 void escape (const char *);
12501 private:
12502 char *m_str;
12503 bool m_owned;
12504 };
12505
12506 /* PR 84195: Replace control characters in "unescaped" with their
12507 escaped equivalents. Allow newlines if -fmessage-length has
12508 been set to a non-zero value. This is done here, rather than
12509 where the attribute is recorded as the message length can
12510 change between these two locations. */
12511
12130 void 12512 void
12513 escaped_string::escape (const char *unescaped)
12514 {
12515 char *escaped;
12516 size_t i, new_i, len;
12517
12518 if (m_owned)
12519 free (m_str);
12520
12521 m_str = const_cast<char *> (unescaped);
12522 m_owned = false;
12523
12524 if (unescaped == NULL || *unescaped == 0)
12525 return;
12526
12527 len = strlen (unescaped);
12528 escaped = NULL;
12529 new_i = 0;
12530
12531 for (i = 0; i < len; i++)
12532 {
12533 char c = unescaped[i];
12534
12535 if (!ISCNTRL (c))
12536 {
12537 if (escaped)
12538 escaped[new_i++] = c;
12539 continue;
12540 }
12541
12542 if (c != '\n' || !pp_is_wrapping_line (global_dc->printer))
12543 {
12544 if (escaped == NULL)
12545 {
12546 /* We only allocate space for a new string if we
12547 actually encounter a control character that
12548 needs replacing. */
12549 escaped = (char *) xmalloc (len * 2 + 1);
12550 strncpy (escaped, unescaped, i);
12551 new_i = i;
12552 }
12553
12554 escaped[new_i++] = '\\';
12555
12556 switch (c)
12557 {
12558 case '\a': escaped[new_i++] = 'a'; break;
12559 case '\b': escaped[new_i++] = 'b'; break;
12560 case '\f': escaped[new_i++] = 'f'; break;
12561 case '\n': escaped[new_i++] = 'n'; break;
12562 case '\r': escaped[new_i++] = 'r'; break;
12563 case '\t': escaped[new_i++] = 't'; break;
12564 case '\v': escaped[new_i++] = 'v'; break;
12565 default: escaped[new_i++] = '?'; break;
12566 }
12567 }
12568 else if (escaped)
12569 escaped[new_i++] = c;
12570 }
12571
12572 if (escaped)
12573 {
12574 escaped[new_i] = 0;
12575 m_str = escaped;
12576 m_owned = true;
12577 }
12578 }
12579
12580 /* Warn about a use of an identifier which was marked deprecated. Returns
12581 whether a warning was given. */
12582
12583 bool
12131 warn_deprecated_use (tree node, tree attr) 12584 warn_deprecated_use (tree node, tree attr)
12132 { 12585 {
12133 const char *msg; 12586 escaped_string msg;
12134 12587
12135 if (node == 0 || !warn_deprecated_decl) 12588 if (node == 0 || !warn_deprecated_decl)
12136 return; 12589 return false;
12137 12590
12138 if (!attr) 12591 if (!attr)
12139 { 12592 {
12140 if (DECL_P (node)) 12593 if (DECL_P (node))
12141 attr = DECL_ATTRIBUTES (node); 12594 attr = DECL_ATTRIBUTES (node);
12150 12603
12151 if (attr) 12604 if (attr)
12152 attr = lookup_attribute ("deprecated", attr); 12605 attr = lookup_attribute ("deprecated", attr);
12153 12606
12154 if (attr) 12607 if (attr)
12155 msg = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))); 12608 msg.escape (TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
12156 else 12609
12157 msg = NULL; 12610 bool w = false;
12158
12159 bool w;
12160 if (DECL_P (node)) 12611 if (DECL_P (node))
12161 { 12612 {
12613 auto_diagnostic_group d;
12162 if (msg) 12614 if (msg)
12163 w = warning (OPT_Wdeprecated_declarations, 12615 w = warning (OPT_Wdeprecated_declarations,
12164 "%qD is deprecated: %s", node, msg); 12616 "%qD is deprecated: %s", node, (const char *) msg);
12165 else 12617 else
12166 w = warning (OPT_Wdeprecated_declarations, 12618 w = warning (OPT_Wdeprecated_declarations,
12167 "%qD is deprecated", node); 12619 "%qD is deprecated", node);
12168 if (w) 12620 if (w)
12169 inform (DECL_SOURCE_LOCATION (node), "declared here"); 12621 inform (DECL_SOURCE_LOCATION (node), "declared here");
12180 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL 12632 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
12181 && DECL_NAME (TYPE_NAME (node))) 12633 && DECL_NAME (TYPE_NAME (node)))
12182 what = DECL_NAME (TYPE_NAME (node)); 12634 what = DECL_NAME (TYPE_NAME (node));
12183 } 12635 }
12184 12636
12185 if (decl) 12637 auto_diagnostic_group d;
12638 if (what)
12186 { 12639 {
12187 if (what) 12640 if (msg)
12188 { 12641 w = warning (OPT_Wdeprecated_declarations,
12189 if (msg) 12642 "%qE is deprecated: %s", what, (const char *) msg);
12190 w = warning (OPT_Wdeprecated_declarations,
12191 "%qE is deprecated: %s", what, msg);
12192 else
12193 w = warning (OPT_Wdeprecated_declarations,
12194 "%qE is deprecated", what);
12195 }
12196 else 12643 else
12197 { 12644 w = warning (OPT_Wdeprecated_declarations,
12198 if (msg) 12645 "%qE is deprecated", what);
12199 w = warning (OPT_Wdeprecated_declarations,
12200 "type is deprecated: %s", msg);
12201 else
12202 w = warning (OPT_Wdeprecated_declarations,
12203 "type is deprecated");
12204 }
12205 if (w)
12206 inform (DECL_SOURCE_LOCATION (decl), "declared here");
12207 } 12646 }
12208 else 12647 else
12209 { 12648 {
12210 if (what) 12649 if (msg)
12211 { 12650 w = warning (OPT_Wdeprecated_declarations,
12212 if (msg) 12651 "type is deprecated: %s", (const char *) msg);
12213 warning (OPT_Wdeprecated_declarations, "%qE is deprecated: %s",
12214 what, msg);
12215 else
12216 warning (OPT_Wdeprecated_declarations, "%qE is deprecated", what);
12217 }
12218 else 12652 else
12219 { 12653 w = warning (OPT_Wdeprecated_declarations,
12220 if (msg) 12654 "type is deprecated");
12221 warning (OPT_Wdeprecated_declarations, "type is deprecated: %s",
12222 msg);
12223 else
12224 warning (OPT_Wdeprecated_declarations, "type is deprecated");
12225 }
12226 } 12655 }
12227 } 12656
12657 if (w && decl)
12658 inform (DECL_SOURCE_LOCATION (decl), "declared here");
12659 }
12660
12661 return w;
12228 } 12662 }
12229 12663
12230 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration 12664 /* Return true if REF has a COMPONENT_REF with a bit-field field declaration
12231 somewhere in it. */ 12665 somewhere in it. */
12232 12666
12311 /* Easy cases. If the last statement of the block implies 12745 /* Easy cases. If the last statement of the block implies
12312 control transfer, then we can't fall through. */ 12746 control transfer, then we can't fall through. */
12313 return false; 12747 return false;
12314 12748
12315 case SWITCH_EXPR: 12749 case SWITCH_EXPR:
12316 /* If SWITCH_LABELS is set, this is lowered, and represents a 12750 /* If there is a default: label or case labels cover all possible
12317 branch to a selected label and hence can not fall through. 12751 SWITCH_COND values, then the SWITCH_EXPR will transfer control
12318 Otherwise SWITCH_BODY is set, and the switch can fall 12752 to some case label in all cases and all we care is whether the
12319 through. */ 12753 SWITCH_BODY falls through. */
12320 return SWITCH_LABELS (stmt) == NULL_TREE; 12754 if (SWITCH_ALL_CASES_P (stmt))
12755 return block_may_fallthru (SWITCH_BODY (stmt));
12756 return true;
12321 12757
12322 case COND_EXPR: 12758 case COND_EXPR:
12323 if (block_may_fallthru (COND_EXPR_THEN (stmt))) 12759 if (block_may_fallthru (COND_EXPR_THEN (stmt)))
12324 return true; 12760 return true;
12325 return block_may_fallthru (COND_EXPR_ELSE (stmt)); 12761 return block_may_fallthru (COND_EXPR_ELSE (stmt));
12402 drop_tree_overflow (tree t) 12838 drop_tree_overflow (tree t)
12403 { 12839 {
12404 gcc_checking_assert (TREE_OVERFLOW (t)); 12840 gcc_checking_assert (TREE_OVERFLOW (t));
12405 12841
12406 /* For tree codes with a sharing machinery re-build the result. */ 12842 /* For tree codes with a sharing machinery re-build the result. */
12407 if (TREE_CODE (t) == INTEGER_CST) 12843 if (poly_int_tree_p (t))
12408 return wide_int_to_tree (TREE_TYPE (t), wi::to_wide (t)); 12844 return wide_int_to_tree (TREE_TYPE (t), wi::to_poly_wide (t));
12845
12846 /* For VECTOR_CST, remove the overflow bits from the encoded elements
12847 and canonicalize the result. */
12848 if (TREE_CODE (t) == VECTOR_CST)
12849 {
12850 tree_vector_builder builder;
12851 builder.new_unary_operation (TREE_TYPE (t), t, true);
12852 unsigned int count = builder.encoded_nelts ();
12853 for (unsigned int i = 0; i < count; ++i)
12854 {
12855 tree elt = VECTOR_CST_ELT (t, i);
12856 if (TREE_OVERFLOW (elt))
12857 elt = drop_tree_overflow (elt);
12858 builder.quick_push (elt);
12859 }
12860 return builder.build ();
12861 }
12409 12862
12410 /* Otherwise, as all tcc_constants are possibly shared, copy the node 12863 /* Otherwise, as all tcc_constants are possibly shared, copy the node
12411 and drop the flag. */ 12864 and drop the flag. */
12412 t = copy_node (t); 12865 t = copy_node (t);
12413 TREE_OVERFLOW (t) = 0; 12866 TREE_OVERFLOW (t) = 0;
12419 if (TREE_OVERFLOW (TREE_REALPART (t))) 12872 if (TREE_OVERFLOW (TREE_REALPART (t)))
12420 TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t)); 12873 TREE_REALPART (t) = drop_tree_overflow (TREE_REALPART (t));
12421 if (TREE_OVERFLOW (TREE_IMAGPART (t))) 12874 if (TREE_OVERFLOW (TREE_IMAGPART (t)))
12422 TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t)); 12875 TREE_IMAGPART (t) = drop_tree_overflow (TREE_IMAGPART (t));
12423 } 12876 }
12424 if (TREE_CODE (t) == VECTOR_CST) 12877
12425 {
12426 for (unsigned i = 0; i < VECTOR_CST_NELTS (t); ++i)
12427 {
12428 tree& elt = VECTOR_CST_ELT (t, i);
12429 if (TREE_OVERFLOW (elt))
12430 elt = drop_tree_overflow (elt);
12431 }
12432 }
12433 return t; 12878 return t;
12434 } 12879 }
12435 12880
12436 /* Given a memory reference expression T, return its base address. 12881 /* Given a memory reference expression T, return its base address.
12437 The base address of a memory reference expression is the main 12882 The base address of a memory reference expression is the main
12550 return false; 12995 return false;
12551 12996
12552 if (TREE_CODE (ref) == STRING_CST) 12997 if (TREE_CODE (ref) == STRING_CST)
12553 return false; 12998 return false;
12554 12999
13000 tree ref_to_array = ref;
12555 while (handled_component_p (ref)) 13001 while (handled_component_p (ref))
12556 { 13002 {
12557 /* If the reference chain contains a component reference to a 13003 /* If the reference chain contains a component reference to a
12558 non-union type and there follows another field the reference 13004 non-union type and there follows another field the reference
12559 is not at the end of a structure. */ 13005 is not at the end of a structure. */
12588 } 13034 }
12589 13035
12590 /* The array now is at struct end. Treat flexible arrays as 13036 /* The array now is at struct end. Treat flexible arrays as
12591 always subject to extend, even into just padding constrained by 13037 always subject to extend, even into just padding constrained by
12592 an underlying decl. */ 13038 an underlying decl. */
12593 if (! TYPE_SIZE (atype)) 13039 if (! TYPE_SIZE (atype)
13040 || ! TYPE_DOMAIN (atype)
13041 || ! TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
12594 return true; 13042 return true;
12595
12596 tree size = NULL;
12597 13043
12598 if (TREE_CODE (ref) == MEM_REF 13044 if (TREE_CODE (ref) == MEM_REF
12599 && TREE_CODE (TREE_OPERAND (ref, 0)) == ADDR_EXPR) 13045 && TREE_CODE (TREE_OPERAND (ref, 0)) == ADDR_EXPR)
12600 { 13046 ref = TREE_OPERAND (TREE_OPERAND (ref, 0), 0);
12601 size = TYPE_SIZE (TREE_TYPE (ref));
12602 ref = TREE_OPERAND (TREE_OPERAND (ref, 0), 0);
12603 }
12604 13047
12605 /* If the reference is based on a declared entity, the size of the array 13048 /* If the reference is based on a declared entity, the size of the array
12606 is constrained by its given domain. (Do not trust commons PR/69368). */ 13049 is constrained by its given domain. (Do not trust commons PR/69368). */
12607 if (DECL_P (ref) 13050 if (DECL_P (ref)
12608 /* Be sure the size of MEM_REF target match. For example:
12609
12610 char buf[10];
12611 struct foo *str = (struct foo *)&buf;
12612
12613 str->trailin_array[2] = 1;
12614
12615 is valid because BUF allocate enough space. */
12616
12617 && (!size || (DECL_SIZE (ref) != NULL
12618 && operand_equal_p (DECL_SIZE (ref), size, 0)))
12619 && !(flag_unconstrained_commons 13051 && !(flag_unconstrained_commons
12620 && VAR_P (ref) && DECL_COMMON (ref))) 13052 && VAR_P (ref) && DECL_COMMON (ref))
12621 return false; 13053 && DECL_SIZE_UNIT (ref)
13054 && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
13055 {
13056 /* Check whether the array domain covers all of the available
13057 padding. */
13058 poly_int64 offset;
13059 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
13060 || TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST
13061 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) != INTEGER_CST)
13062 return true;
13063 if (! get_addr_base_and_unit_offset (ref_to_array, &offset))
13064 return true;
13065
13066 /* If at least one extra element fits it is a flexarray. */
13067 if (known_le ((wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))
13068 - wi::to_offset (TYPE_MIN_VALUE (TYPE_DOMAIN (atype)))
13069 + 2)
13070 * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (atype))),
13071 wi::to_offset (DECL_SIZE_UNIT (ref)) - offset))
13072 return true;
13073
13074 return false;
13075 }
12622 13076
12623 return true; 13077 return true;
12624 } 13078 }
12625 13079
12626 /* Return a tree representing the offset, in bytes, of the field referenced 13080 /* Return a tree representing the offset, in bytes, of the field referenced
12691 scalar_int_mode innermode; 13145 scalar_int_mode innermode;
12692 13146
12693 /* For integers, try mapping it to a same-sized scalar mode. */ 13147 /* For integers, try mapping it to a same-sized scalar mode. */
12694 if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode)) 13148 if (is_int_mode (TREE_TYPE (t)->type_common.mode, &innermode))
12695 { 13149 {
12696 unsigned int size = (TYPE_VECTOR_SUBPARTS (t) 13150 poly_int64 size = (TYPE_VECTOR_SUBPARTS (t)
12697 * GET_MODE_BITSIZE (innermode)); 13151 * GET_MODE_BITSIZE (innermode));
12698 scalar_int_mode mode; 13152 scalar_int_mode mode;
12699 if (int_mode_for_size (size, 0).exists (&mode) 13153 if (int_mode_for_size (size, 0).exists (&mode)
12700 && have_regs_of_mode[mode]) 13154 && have_regs_of_mode[mode])
12701 return mode; 13155 return mode;
12702 } 13156 }
12736 /* Convenience macro for matching individual fields. */ 13190 /* Convenience macro for matching individual fields. */
12737 #define verify_variant_match(flag) \ 13191 #define verify_variant_match(flag) \
12738 do { \ 13192 do { \
12739 if (flag (tv) != flag (t)) \ 13193 if (flag (tv) != flag (t)) \
12740 { \ 13194 { \
12741 error ("type variant differs by " #flag "."); \ 13195 error ("type variant differs by %s", #flag); \
12742 debug_tree (tv); \ 13196 debug_tree (tv); \
12743 return false; \ 13197 return false; \
12744 } \ 13198 } \
12745 } while (false) 13199 } while (false)
12746 13200
13745 NULL); 14199 NULL);
13746 SET_EXPR_LOCATION (expr, adhoc); 14200 SET_EXPR_LOCATION (expr, adhoc);
13747 return adhoc; 14201 return adhoc;
13748 } 14202 }
13749 14203
14204 /* Return EXPR, potentially wrapped with a node expression LOC,
14205 if !CAN_HAVE_LOCATION_P (expr).
14206
14207 NON_LVALUE_EXPR is used for wrapping constants, apart from STRING_CST.
14208 VIEW_CONVERT_EXPR is used for wrapping non-constants and STRING_CST.
14209
14210 Wrapper nodes can be identified using location_wrapper_p. */
14211
14212 tree
14213 maybe_wrap_with_location (tree expr, location_t loc)
14214 {
14215 if (expr == NULL)
14216 return NULL;
14217 if (loc == UNKNOWN_LOCATION)
14218 return expr;
14219 if (CAN_HAVE_LOCATION_P (expr))
14220 return expr;
14221 /* We should only be adding wrappers for constants and for decls,
14222 or for some exceptional tree nodes (e.g. BASELINK in the C++ FE). */
14223 gcc_assert (CONSTANT_CLASS_P (expr)
14224 || DECL_P (expr)
14225 || EXCEPTIONAL_CLASS_P (expr));
14226
14227 /* For now, don't add wrappers to exceptional tree nodes, to minimize
14228 any impact of the wrapper nodes. */
14229 if (EXCEPTIONAL_CLASS_P (expr))
14230 return expr;
14231
14232 tree_code code
14233 = (((CONSTANT_CLASS_P (expr) && TREE_CODE (expr) != STRING_CST)
14234 || (TREE_CODE (expr) == CONST_DECL && !TREE_STATIC (expr)))
14235 ? NON_LVALUE_EXPR : VIEW_CONVERT_EXPR);
14236 tree wrapper = build1_loc (loc, code, TREE_TYPE (expr), expr);
14237 /* Mark this node as being a wrapper. */
14238 EXPR_LOCATION_WRAPPER_P (wrapper) = 1;
14239 return wrapper;
14240 }
14241
13750 /* Return the name of combined function FN, for debugging purposes. */ 14242 /* Return the name of combined function FN, for debugging purposes. */
13751 14243
13752 const char * 14244 const char *
13753 combined_fn_name (combined_fn fn) 14245 combined_fn_name (combined_fn fn)
13754 { 14246 {
13809 } 14301 }
13810 14302
13811 return argmap; 14303 return argmap;
13812 } 14304 }
13813 14305
14306 /* Returns true if TYPE is a type where it and all of its subobjects
14307 (recursively) are of structure, union, or array type. */
14308
14309 static bool
14310 default_is_empty_type (tree type)
14311 {
14312 if (RECORD_OR_UNION_TYPE_P (type))
14313 {
14314 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
14315 if (TREE_CODE (field) == FIELD_DECL
14316 && !DECL_PADDING_P (field)
14317 && !default_is_empty_type (TREE_TYPE (field)))
14318 return false;
14319 return true;
14320 }
14321 else if (TREE_CODE (type) == ARRAY_TYPE)
14322 return (integer_minus_onep (array_type_nelts (type))
14323 || TYPE_DOMAIN (type) == NULL_TREE
14324 || default_is_empty_type (TREE_TYPE (type)));
14325 return false;
14326 }
14327
14328 /* Implement TARGET_EMPTY_RECORD_P. Return true if TYPE is an empty type
14329 that shouldn't be passed via stack. */
14330
14331 bool
14332 default_is_empty_record (const_tree type)
14333 {
14334 if (!abi_version_at_least (12))
14335 return false;
14336
14337 if (type == error_mark_node)
14338 return false;
14339
14340 if (TREE_ADDRESSABLE (type))
14341 return false;
14342
14343 return default_is_empty_type (TYPE_MAIN_VARIANT (type));
14344 }
14345
14346 /* Like int_size_in_bytes, but handle empty records specially. */
14347
14348 HOST_WIDE_INT
14349 arg_int_size_in_bytes (const_tree type)
14350 {
14351 return TYPE_EMPTY_P (type) ? 0 : int_size_in_bytes (type);
14352 }
14353
14354 /* Like size_in_bytes, but handle empty records specially. */
14355
14356 tree
14357 arg_size_in_bytes (const_tree type)
14358 {
14359 return TYPE_EMPTY_P (type) ? size_zero_node : size_in_bytes (type);
14360 }
14361
14362 /* Return true if an expression with CODE has to have the same result type as
14363 its first operand. */
14364
14365 bool
14366 expr_type_first_operand_type_p (tree_code code)
14367 {
14368 switch (code)
14369 {
14370 case NEGATE_EXPR:
14371 case ABS_EXPR:
14372 case BIT_NOT_EXPR:
14373 case PAREN_EXPR:
14374 case CONJ_EXPR:
14375
14376 case PLUS_EXPR:
14377 case MINUS_EXPR:
14378 case MULT_EXPR:
14379 case TRUNC_DIV_EXPR:
14380 case CEIL_DIV_EXPR:
14381 case FLOOR_DIV_EXPR:
14382 case ROUND_DIV_EXPR:
14383 case TRUNC_MOD_EXPR:
14384 case CEIL_MOD_EXPR:
14385 case FLOOR_MOD_EXPR:
14386 case ROUND_MOD_EXPR:
14387 case RDIV_EXPR:
14388 case EXACT_DIV_EXPR:
14389 case MIN_EXPR:
14390 case MAX_EXPR:
14391 case BIT_IOR_EXPR:
14392 case BIT_XOR_EXPR:
14393 case BIT_AND_EXPR:
14394
14395 case LSHIFT_EXPR:
14396 case RSHIFT_EXPR:
14397 case LROTATE_EXPR:
14398 case RROTATE_EXPR:
14399 return true;
14400
14401 default:
14402 return false;
14403 }
14404 }
14405
14406 /* Return a typenode for the "standard" C type with a given name. */
14407 tree
14408 get_typenode_from_name (const char *name)
14409 {
14410 if (name == NULL || *name == '\0')
14411 return NULL_TREE;
14412
14413 if (strcmp (name, "char") == 0)
14414 return char_type_node;
14415 if (strcmp (name, "unsigned char") == 0)
14416 return unsigned_char_type_node;
14417 if (strcmp (name, "signed char") == 0)
14418 return signed_char_type_node;
14419
14420 if (strcmp (name, "short int") == 0)
14421 return short_integer_type_node;
14422 if (strcmp (name, "short unsigned int") == 0)
14423 return short_unsigned_type_node;
14424
14425 if (strcmp (name, "int") == 0)
14426 return integer_type_node;
14427 if (strcmp (name, "unsigned int") == 0)
14428 return unsigned_type_node;
14429
14430 if (strcmp (name, "long int") == 0)
14431 return long_integer_type_node;
14432 if (strcmp (name, "long unsigned int") == 0)
14433 return long_unsigned_type_node;
14434
14435 if (strcmp (name, "long long int") == 0)
14436 return long_long_integer_type_node;
14437 if (strcmp (name, "long long unsigned int") == 0)
14438 return long_long_unsigned_type_node;
14439
14440 gcc_unreachable ();
14441 }
14442
13814 /* List of pointer types used to declare builtins before we have seen their 14443 /* List of pointer types used to declare builtins before we have seen their
13815 real declaration. 14444 real declaration.
13816 14445
13817 Keep the size up to date in tree.h ! */ 14446 Keep the size up to date in tree.h ! */
13818 const builtin_structptr_type builtin_structptr_types[6] = 14447 const builtin_structptr_type builtin_structptr_types[6] =
13870 identifier, void_type_node); 14499 identifier, void_type_node);
13871 ASSERT_EQ (-1, LABEL_DECL_UID (label_decl)); 14500 ASSERT_EQ (-1, LABEL_DECL_UID (label_decl));
13872 ASSERT_FALSE (FORCED_LABEL (label_decl)); 14501 ASSERT_FALSE (FORCED_LABEL (label_decl));
13873 } 14502 }
13874 14503
14504 /* Return a new VECTOR_CST node whose type is TYPE and whose values
14505 are given by VALS. */
14506
14507 static tree
14508 build_vector (tree type, vec<tree> vals MEM_STAT_DECL)
14509 {
14510 gcc_assert (known_eq (vals.length (), TYPE_VECTOR_SUBPARTS (type)));
14511 tree_vector_builder builder (type, vals.length (), 1);
14512 builder.splice (vals);
14513 return builder.build ();
14514 }
14515
14516 /* Check that VECTOR_CST ACTUAL contains the elements in EXPECTED. */
14517
14518 static void
14519 check_vector_cst (vec<tree> expected, tree actual)
14520 {
14521 ASSERT_KNOWN_EQ (expected.length (),
14522 TYPE_VECTOR_SUBPARTS (TREE_TYPE (actual)));
14523 for (unsigned int i = 0; i < expected.length (); ++i)
14524 ASSERT_EQ (wi::to_wide (expected[i]),
14525 wi::to_wide (vector_cst_elt (actual, i)));
14526 }
14527
14528 /* Check that VECTOR_CST ACTUAL contains NPATTERNS duplicated elements,
14529 and that its elements match EXPECTED. */
14530
14531 static void
14532 check_vector_cst_duplicate (vec<tree> expected, tree actual,
14533 unsigned int npatterns)
14534 {
14535 ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
14536 ASSERT_EQ (1, VECTOR_CST_NELTS_PER_PATTERN (actual));
14537 ASSERT_EQ (npatterns, vector_cst_encoded_nelts (actual));
14538 ASSERT_TRUE (VECTOR_CST_DUPLICATE_P (actual));
14539 ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
14540 check_vector_cst (expected, actual);
14541 }
14542
14543 /* Check that VECTOR_CST ACTUAL contains NPATTERNS foreground elements
14544 and NPATTERNS background elements, and that its elements match
14545 EXPECTED. */
14546
14547 static void
14548 check_vector_cst_fill (vec<tree> expected, tree actual,
14549 unsigned int npatterns)
14550 {
14551 ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
14552 ASSERT_EQ (2, VECTOR_CST_NELTS_PER_PATTERN (actual));
14553 ASSERT_EQ (2 * npatterns, vector_cst_encoded_nelts (actual));
14554 ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
14555 ASSERT_FALSE (VECTOR_CST_STEPPED_P (actual));
14556 check_vector_cst (expected, actual);
14557 }
14558
14559 /* Check that VECTOR_CST ACTUAL contains NPATTERNS stepped patterns,
14560 and that its elements match EXPECTED. */
14561
14562 static void
14563 check_vector_cst_stepped (vec<tree> expected, tree actual,
14564 unsigned int npatterns)
14565 {
14566 ASSERT_EQ (npatterns, VECTOR_CST_NPATTERNS (actual));
14567 ASSERT_EQ (3, VECTOR_CST_NELTS_PER_PATTERN (actual));
14568 ASSERT_EQ (3 * npatterns, vector_cst_encoded_nelts (actual));
14569 ASSERT_FALSE (VECTOR_CST_DUPLICATE_P (actual));
14570 ASSERT_TRUE (VECTOR_CST_STEPPED_P (actual));
14571 check_vector_cst (expected, actual);
14572 }
14573
14574 /* Test the creation of VECTOR_CSTs. */
14575
14576 static void
14577 test_vector_cst_patterns (ALONE_CXX_MEM_STAT_INFO)
14578 {
14579 auto_vec<tree, 8> elements (8);
14580 elements.quick_grow (8);
14581 tree element_type = build_nonstandard_integer_type (16, true);
14582 tree vector_type = build_vector_type (element_type, 8);
14583
14584 /* Test a simple linear series with a base of 0 and a step of 1:
14585 { 0, 1, 2, 3, 4, 5, 6, 7 }. */
14586 for (unsigned int i = 0; i < 8; ++i)
14587 elements[i] = build_int_cst (element_type, i);
14588 tree vector = build_vector (vector_type, elements PASS_MEM_STAT);
14589 check_vector_cst_stepped (elements, vector, 1);
14590
14591 /* Try the same with the first element replaced by 100:
14592 { 100, 1, 2, 3, 4, 5, 6, 7 }. */
14593 elements[0] = build_int_cst (element_type, 100);
14594 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14595 check_vector_cst_stepped (elements, vector, 1);
14596
14597 /* Try a series that wraps around.
14598 { 100, 65531, 65532, 65533, 65534, 65535, 0, 1 }. */
14599 for (unsigned int i = 1; i < 8; ++i)
14600 elements[i] = build_int_cst (element_type, (65530 + i) & 0xffff);
14601 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14602 check_vector_cst_stepped (elements, vector, 1);
14603
14604 /* Try a downward series:
14605 { 100, 79, 78, 77, 76, 75, 75, 73 }. */
14606 for (unsigned int i = 1; i < 8; ++i)
14607 elements[i] = build_int_cst (element_type, 80 - i);
14608 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14609 check_vector_cst_stepped (elements, vector, 1);
14610
14611 /* Try two interleaved series with different bases and steps:
14612 { 100, 53, 66, 206, 62, 212, 58, 218 }. */
14613 elements[1] = build_int_cst (element_type, 53);
14614 for (unsigned int i = 2; i < 8; i += 2)
14615 {
14616 elements[i] = build_int_cst (element_type, 70 - i * 2);
14617 elements[i + 1] = build_int_cst (element_type, 200 + i * 3);
14618 }
14619 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14620 check_vector_cst_stepped (elements, vector, 2);
14621
14622 /* Try a duplicated value:
14623 { 100, 100, 100, 100, 100, 100, 100, 100 }. */
14624 for (unsigned int i = 1; i < 8; ++i)
14625 elements[i] = elements[0];
14626 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14627 check_vector_cst_duplicate (elements, vector, 1);
14628
14629 /* Try an interleaved duplicated value:
14630 { 100, 55, 100, 55, 100, 55, 100, 55 }. */
14631 elements[1] = build_int_cst (element_type, 55);
14632 for (unsigned int i = 2; i < 8; ++i)
14633 elements[i] = elements[i - 2];
14634 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14635 check_vector_cst_duplicate (elements, vector, 2);
14636
14637 /* Try a duplicated value with 2 exceptions
14638 { 41, 97, 100, 55, 100, 55, 100, 55 }. */
14639 elements[0] = build_int_cst (element_type, 41);
14640 elements[1] = build_int_cst (element_type, 97);
14641 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14642 check_vector_cst_fill (elements, vector, 2);
14643
14644 /* Try with and without a step
14645 { 41, 97, 100, 21, 100, 35, 100, 49 }. */
14646 for (unsigned int i = 3; i < 8; i += 2)
14647 elements[i] = build_int_cst (element_type, i * 7);
14648 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14649 check_vector_cst_stepped (elements, vector, 2);
14650
14651 /* Try a fully-general constant:
14652 { 41, 97, 100, 21, 100, 9990, 100, 49 }. */
14653 elements[5] = build_int_cst (element_type, 9990);
14654 vector = build_vector (vector_type, elements PASS_MEM_STAT);
14655 check_vector_cst_fill (elements, vector, 4);
14656 }
14657
14658 /* Verify that STRIP_NOPS (NODE) is EXPECTED.
14659 Helper function for test_location_wrappers, to deal with STRIP_NOPS
14660 modifying its argument in-place. */
14661
14662 static void
14663 check_strip_nops (tree node, tree expected)
14664 {
14665 STRIP_NOPS (node);
14666 ASSERT_EQ (expected, node);
14667 }
14668
14669 /* Verify location wrappers. */
14670
14671 static void
14672 test_location_wrappers ()
14673 {
14674 location_t loc = BUILTINS_LOCATION;
14675
14676 ASSERT_EQ (NULL_TREE, maybe_wrap_with_location (NULL_TREE, loc));
14677
14678 /* Wrapping a constant. */
14679 tree int_cst = build_int_cst (integer_type_node, 42);
14680 ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_cst));
14681 ASSERT_FALSE (location_wrapper_p (int_cst));
14682
14683 tree wrapped_int_cst = maybe_wrap_with_location (int_cst, loc);
14684 ASSERT_TRUE (location_wrapper_p (wrapped_int_cst));
14685 ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_cst));
14686 ASSERT_EQ (int_cst, tree_strip_any_location_wrapper (wrapped_int_cst));
14687
14688 /* We shouldn't add wrapper nodes for UNKNOWN_LOCATION. */
14689 ASSERT_EQ (int_cst, maybe_wrap_with_location (int_cst, UNKNOWN_LOCATION));
14690
14691 /* We shouldn't add wrapper nodes for nodes that CAN_HAVE_LOCATION_P. */
14692 tree cast = build1 (NOP_EXPR, char_type_node, int_cst);
14693 ASSERT_TRUE (CAN_HAVE_LOCATION_P (cast));
14694 ASSERT_EQ (cast, maybe_wrap_with_location (cast, loc));
14695
14696 /* Wrapping a STRING_CST. */
14697 tree string_cst = build_string (4, "foo");
14698 ASSERT_FALSE (CAN_HAVE_LOCATION_P (string_cst));
14699 ASSERT_FALSE (location_wrapper_p (string_cst));
14700
14701 tree wrapped_string_cst = maybe_wrap_with_location (string_cst, loc);
14702 ASSERT_TRUE (location_wrapper_p (wrapped_string_cst));
14703 ASSERT_EQ (VIEW_CONVERT_EXPR, TREE_CODE (wrapped_string_cst));
14704 ASSERT_EQ (loc, EXPR_LOCATION (wrapped_string_cst));
14705 ASSERT_EQ (string_cst, tree_strip_any_location_wrapper (wrapped_string_cst));
14706
14707
14708 /* Wrapping a variable. */
14709 tree int_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
14710 get_identifier ("some_int_var"),
14711 integer_type_node);
14712 ASSERT_FALSE (CAN_HAVE_LOCATION_P (int_var));
14713 ASSERT_FALSE (location_wrapper_p (int_var));
14714
14715 tree wrapped_int_var = maybe_wrap_with_location (int_var, loc);
14716 ASSERT_TRUE (location_wrapper_p (wrapped_int_var));
14717 ASSERT_EQ (loc, EXPR_LOCATION (wrapped_int_var));
14718 ASSERT_EQ (int_var, tree_strip_any_location_wrapper (wrapped_int_var));
14719
14720 /* Verify that "reinterpret_cast<int>(some_int_var)" is not a location
14721 wrapper. */
14722 tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
14723 ASSERT_FALSE (location_wrapper_p (r_cast));
14724 ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
14725
14726 /* Verify that STRIP_NOPS removes wrappers. */
14727 check_strip_nops (wrapped_int_cst, int_cst);
14728 check_strip_nops (wrapped_string_cst, string_cst);
14729 check_strip_nops (wrapped_int_var, int_var);
14730 }
14731
14732 /* Check that string escaping works correctly. */
14733
14734 static void
14735 test_escaped_strings (void)
14736 {
14737 int saved_cutoff;
14738 escaped_string msg;
14739
14740 msg.escape (NULL);
14741 /* ASSERT_STREQ does not accept NULL as a valid test
14742 result, so we have to use ASSERT_EQ instead. */
14743 ASSERT_EQ (NULL, (const char *) msg);
14744
14745 msg.escape ("");
14746 ASSERT_STREQ ("", (const char *) msg);
14747
14748 msg.escape ("foobar");
14749 ASSERT_STREQ ("foobar", (const char *) msg);
14750
14751 /* Ensure that we have -fmessage-length set to 0. */
14752 saved_cutoff = pp_line_cutoff (global_dc->printer);
14753 pp_line_cutoff (global_dc->printer) = 0;
14754
14755 msg.escape ("foo\nbar");
14756 ASSERT_STREQ ("foo\\nbar", (const char *) msg);
14757
14758 msg.escape ("\a\b\f\n\r\t\v");
14759 ASSERT_STREQ ("\\a\\b\\f\\n\\r\\t\\v", (const char *) msg);
14760
14761 /* Now repeat the tests with -fmessage-length set to 5. */
14762 pp_line_cutoff (global_dc->printer) = 5;
14763
14764 /* Note that the newline is not translated into an escape. */
14765 msg.escape ("foo\nbar");
14766 ASSERT_STREQ ("foo\nbar", (const char *) msg);
14767
14768 msg.escape ("\a\b\f\n\r\t\v");
14769 ASSERT_STREQ ("\\a\\b\\f\n\\r\\t\\v", (const char *) msg);
14770
14771 /* Restore the original message length setting. */
14772 pp_line_cutoff (global_dc->printer) = saved_cutoff;
14773 }
14774
13875 /* Run all of the selftests within this file. */ 14775 /* Run all of the selftests within this file. */
13876 14776
13877 void 14777 void
13878 tree_c_tests () 14778 tree_c_tests ()
13879 { 14779 {
13880 test_integer_constants (); 14780 test_integer_constants ();
13881 test_identifiers (); 14781 test_identifiers ();
13882 test_labels (); 14782 test_labels ();
14783 test_vector_cst_patterns ();
14784 test_location_wrappers ();
14785 test_escaped_strings ();
13883 } 14786 }
13884 14787
13885 } // namespace selftest 14788 } // namespace selftest
13886 14789
13887 #endif /* CHECKING_P */ 14790 #endif /* CHECKING_P */