comparison gcc/varasm.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents 3bfb6c00c1e0
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
1 /* Output variables, constants and external declarations, for GNU compiler. 1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 2010 Free Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free 9 the terms of the GNU General Public License as published by the Free
40 #include "regs.h" 40 #include "regs.h"
41 #include "real.h" 41 #include "real.h"
42 #include "output.h" 42 #include "output.h"
43 #include "toplev.h" 43 #include "toplev.h"
44 #include "hashtab.h" 44 #include "hashtab.h"
45 #include "c-pragma.h"
46 #include "ggc.h" 45 #include "ggc.h"
47 #include "langhooks.h" 46 #include "langhooks.h"
48 #include "tm_p.h" 47 #include "tm_p.h"
49 #include "debug.h" 48 #include "debug.h"
50 #include "target.h" 49 #include "target.h"
113 static tree copy_constant (tree); 112 static tree copy_constant (tree);
114 static void output_constant_def_contents (rtx); 113 static void output_constant_def_contents (rtx);
115 static void output_addressed_constants (tree); 114 static void output_addressed_constants (tree);
116 static unsigned HOST_WIDE_INT array_size_for_constructor (tree); 115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
117 static unsigned min_align (unsigned, unsigned); 116 static unsigned min_align (unsigned, unsigned);
118 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
119 static void globalize_decl (tree); 117 static void globalize_decl (tree);
120 #ifdef BSS_SECTION_ASM_OP 118 #ifdef BSS_SECTION_ASM_OP
121 #ifdef ASM_OUTPUT_BSS 119 #ifdef ASM_OUTPUT_BSS
122 static void asm_output_bss (FILE *, tree, const char *, 120 static void asm_output_bss (FILE *, tree, const char *,
123 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT); 121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
215 prefix_name (const char *prefix, tree name) 213 prefix_name (const char *prefix, tree name)
216 { 214 {
217 unsigned plen = strlen (prefix); 215 unsigned plen = strlen (prefix);
218 unsigned nlen = strlen (IDENTIFIER_POINTER (name)); 216 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
219 char *toname = (char *) alloca (plen + nlen + 1); 217 char *toname = (char *) alloca (plen + nlen + 1);
220 218
221 memcpy (toname, prefix, plen); 219 memcpy (toname, prefix, plen);
222 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1); 220 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
223 221
224 return get_identifier (toname); 222 return get_identifier (toname);
225 } 223 }
238 236
239 tree 237 tree
240 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED) 238 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
241 { 239 {
242 tree word_type_node, field, next_field; 240 tree word_type_node, field, next_field;
243 241
244 field = build_decl (FIELD_DECL, get_identifier ("__templ"), ptr_type_node); 242 field = build_decl (UNKNOWN_LOCATION,
243 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
245 DECL_CONTEXT (field) = type; 244 DECL_CONTEXT (field) = type;
246 next_field = field; 245 next_field = field;
247 246
248 field = build_decl (FIELD_DECL, get_identifier ("__offset"), 247 field = build_decl (UNKNOWN_LOCATION,
248 FIELD_DECL, get_identifier ("__offset"),
249 ptr_type_node); 249 ptr_type_node);
250 DECL_CONTEXT (field) = type; 250 DECL_CONTEXT (field) = type;
251 TREE_CHAIN (field) = next_field; 251 TREE_CHAIN (field) = next_field;
252 next_field = field; 252 next_field = field;
253 253
254 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1); 254 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
255 field = build_decl (FIELD_DECL, get_identifier ("__align"), 255 field = build_decl (UNKNOWN_LOCATION,
256 FIELD_DECL, get_identifier ("__align"),
256 word_type_node); 257 word_type_node);
257 DECL_CONTEXT (field) = type; 258 DECL_CONTEXT (field) = type;
258 TREE_CHAIN (field) = next_field; 259 TREE_CHAIN (field) = next_field;
259 next_field = field; 260 next_field = field;
260 261
261 field = build_decl (FIELD_DECL, get_identifier ("__size"), word_type_node); 262 field = build_decl (UNKNOWN_LOCATION,
263 FIELD_DECL, get_identifier ("__size"), word_type_node);
262 DECL_CONTEXT (field) = type; 264 DECL_CONTEXT (field) = type;
263 TREE_CHAIN (field) = next_field; 265 TREE_CHAIN (field) = next_field;
264 266
265 return field; 267 return field;
266 } 268 }
280 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE); 282 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
281 type_name = NULL; 283 type_name = NULL;
282 field = targetm.emutls.var_fields (type, &type_name); 284 field = targetm.emutls.var_fields (type, &type_name);
283 if (!type_name) 285 if (!type_name)
284 type_name = get_identifier ("__emutls_object"); 286 type_name = get_identifier ("__emutls_object");
285 type_name = build_decl (TYPE_DECL, type_name, type); 287 type_name = build_decl (UNKNOWN_LOCATION,
288 TYPE_DECL, type_name, type);
286 TYPE_NAME (type) = type_name; 289 TYPE_NAME (type) = type_name;
287 TYPE_FIELDS (type) = field; 290 TYPE_FIELDS (type) = field;
288 layout_type (type); 291 layout_type (type);
289 292
290 return type; 293 return type;
295 298
296 static tree 299 static tree
297 get_emutls_init_templ_addr (tree decl) 300 get_emutls_init_templ_addr (tree decl)
298 { 301 {
299 tree name, to; 302 tree name, to;
300 303
301 if (targetm.emutls.register_common && !DECL_INITIAL (decl) 304 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
302 && !DECL_SECTION_NAME (decl)) 305 && !DECL_SECTION_NAME (decl))
303 return null_pointer_node; 306 return null_pointer_node;
304 307
305 name = DECL_ASSEMBLER_NAME (decl); 308 name = DECL_ASSEMBLER_NAME (decl);
309 ? targetm.emutls.tmpl_prefix 312 ? targetm.emutls.tmpl_prefix
310 : "__emutls_t" EMUTLS_SEPARATOR); 313 : "__emutls_t" EMUTLS_SEPARATOR);
311 name = prefix_name (prefix, name); 314 name = prefix_name (prefix, name);
312 } 315 }
313 316
314 to = build_decl (VAR_DECL, name, TREE_TYPE (decl)); 317 to = build_decl (DECL_SOURCE_LOCATION (decl),
318 VAR_DECL, name, TREE_TYPE (decl));
315 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to)); 319 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
316 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED; 320 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
317 DECL_ARTIFICIAL (to) = 1; 321 DECL_ARTIFICIAL (to) = 1;
318 TREE_USED (to) = TREE_USED (decl); 322 TREE_USED (to) = TREE_USED (decl);
319 TREE_READONLY (to) = 1; 323 TREE_READONLY (to) = 1;
320 DECL_IGNORED_P (to) = 1; 324 DECL_IGNORED_P (to) = 1;
321 DECL_CONTEXT (to) = DECL_CONTEXT (decl); 325 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
322 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl); 326 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
323 327
324 DECL_WEAK (to) = DECL_WEAK (decl); 328 DECL_WEAK (to) = DECL_WEAK (decl);
325 if (DECL_ONE_ONLY (decl)) 329 if (DECL_ONE_ONLY (decl))
326 { 330 {
327 make_decl_one_only (to); 331 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
328 TREE_STATIC (to) = TREE_STATIC (decl); 332 TREE_STATIC (to) = TREE_STATIC (decl);
329 TREE_PUBLIC (to) = TREE_PUBLIC (decl); 333 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
330 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl); 334 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
331 } 335 }
332 else 336 else
369 h = (struct tree_map *) *loc; 373 h = (struct tree_map *) *loc;
370 if (h != NULL) 374 if (h != NULL)
371 to = h->to; 375 to = h->to;
372 else 376 else
373 { 377 {
374 to = build_decl (VAR_DECL, get_emutls_object_name (name), 378 to = build_decl (DECL_SOURCE_LOCATION (decl),
379 VAR_DECL, get_emutls_object_name (name),
375 get_emutls_object_type ()); 380 get_emutls_object_type ());
376 381
377 h = GGC_NEW (struct tree_map); 382 h = GGC_NEW (struct tree_map);
378 h->hash = in.hash; 383 h->hash = in.hash;
379 h->base.from = decl; 384 h->base.from = decl;
384 DECL_ARTIFICIAL (to) = 1; 389 DECL_ARTIFICIAL (to) = 1;
385 DECL_IGNORED_P (to) = 1; 390 DECL_IGNORED_P (to) = 1;
386 TREE_READONLY (to) = 0; 391 TREE_READONLY (to) = 0;
387 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to)); 392 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
388 if (DECL_ONE_ONLY (decl)) 393 if (DECL_ONE_ONLY (decl))
389 make_decl_one_only (to); 394 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
390 DECL_CONTEXT (to) = DECL_CONTEXT (decl); 395 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
391 if (targetm.emutls.var_align_fixed) 396 if (targetm.emutls.var_align_fixed)
392 /* If we're not allowed to change the proxy object's 397 /* If we're not allowed to change the proxy object's
393 alignment, pretend it's been set by the user. */ 398 alignment, pretend it's been set by the user. */
394 DECL_USER_ALIGN (to) = 1; 399 DECL_USER_ALIGN (to) = 1;
438 args = tree_cons (NULL, x, args); 443 args = tree_cons (NULL, x, args);
439 x = build_fold_addr_expr (h->to); 444 x = build_fold_addr_expr (h->to);
440 args = tree_cons (NULL, x, args); 445 args = tree_cons (NULL, x, args);
441 446
442 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON]; 447 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
443 x = build_function_call_expr (x, args); 448 x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
444 449
445 append_to_statement_list (x, pstmts); 450 append_to_statement_list (x, pstmts);
446 return 1; 451 return 1;
447 } 452 }
448 453
457 return; 462 return;
458 463
459 htab_traverse_noresize (emutls_htab, emutls_common_1, &body); 464 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
460 if (body == NULL_TREE) 465 if (body == NULL_TREE)
461 return; 466 return;
462 467
463 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY); 468 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
464 } 469 }
465 } 470 }
466 471
467 /* Helper routines for maintaining section_htab. */ 472 /* Helper routines for maintaining section_htab. */
867 { 872 {
868 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); 873 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
869 874
870 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP) 875 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
871 { 876 {
872 size_t len = strlen (name) + 3; 877 const char *dot;
873 char* rname = (char *) alloca (len); 878 size_t len;
879 char* rname;
880
881 dot = strchr (name + 1, '.');
882 if (!dot)
883 dot = name;
884 len = strlen (dot) + 8;
885 rname = (char *) alloca (len);
874 886
875 strcpy (rname, ".rodata"); 887 strcpy (rname, ".rodata");
876 strcat (rname, name + 5); 888 strcat (rname, dot);
877 return get_section (rname, SECTION_LINKONCE, decl); 889 return get_section (rname, SECTION_LINKONCE, decl);
878 } 890 }
879 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */ 891 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
880 else if (DECL_ONE_ONLY (decl) 892 else if (DECL_ONE_ONLY (decl)
881 && strncmp (name, ".gnu.linkonce.t.", 16) == 0) 893 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
1154 section should be used wherever possible. */ 1166 section should be used wherever possible. */
1155 1167
1156 static section * 1168 static section *
1157 get_variable_section (tree decl, bool prefer_noswitch_p) 1169 get_variable_section (tree decl, bool prefer_noswitch_p)
1158 { 1170 {
1171 addr_space_t as = ADDR_SPACE_GENERIC;
1159 int reloc; 1172 int reloc;
1160 1173
1161 /* If the decl has been given an explicit section name, then it 1174 if (TREE_TYPE (decl) != error_mark_node)
1162 isn't common, and shouldn't be handled as such. */ 1175 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1163 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL) 1176
1177 /* If the decl has been given an explicit section name, or it resides
1178 in a non-generic address space, then it isn't common, and shouldn't
1179 be handled as such. */
1180 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL
1181 && ADDR_SPACE_GENERIC_P (as))
1164 { 1182 {
1165 if (DECL_THREAD_LOCAL_P (decl)) 1183 if (DECL_THREAD_LOCAL_P (decl))
1166 return tls_comm_section; 1184 return tls_comm_section;
1167 /* This cannot be common bss for an emulated TLS object without 1185 /* This cannot be common bss for an emulated TLS object without
1168 a register_common hook. */ 1186 a register_common hook. */
1182 1200
1183 resolve_unique_section (decl, reloc, flag_data_sections); 1201 resolve_unique_section (decl, reloc, flag_data_sections);
1184 if (IN_NAMED_SECTION (decl)) 1202 if (IN_NAMED_SECTION (decl))
1185 return get_named_section (decl, NULL, reloc); 1203 return get_named_section (decl, NULL, reloc);
1186 1204
1187 if (!DECL_THREAD_LOCAL_P (decl) 1205 if (ADDR_SPACE_GENERIC_P (as)
1206 && !DECL_THREAD_LOCAL_P (decl)
1188 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections) 1207 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1189 && bss_initializer_p (decl)) 1208 && bss_initializer_p (decl))
1190 { 1209 {
1191 if (!TREE_PUBLIC (decl)) 1210 if (!TREE_PUBLIC (decl))
1192 return lcomm_section; 1211 return lcomm_section;
1426 DECL_COMMON (decl) = 0; 1445 DECL_COMMON (decl) = 0;
1427 1446
1428 if (use_object_blocks_p () && use_blocks_for_decl_p (decl)) 1447 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1429 x = create_block_symbol (name, get_block_for_decl (decl), -1); 1448 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1430 else 1449 else
1431 x = gen_rtx_SYMBOL_REF (Pmode, name); 1450 {
1451 enum machine_mode address_mode = Pmode;
1452 if (TREE_TYPE (decl) != error_mark_node)
1453 {
1454 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1455 address_mode = targetm.addr_space.address_mode (as);
1456 }
1457 x = gen_rtx_SYMBOL_REF (address_mode, name);
1458 }
1432 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl); 1459 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1433 SET_SYMBOL_REF_DECL (x, decl); 1460 SET_SYMBOL_REF_DECL (x, decl);
1434 1461
1435 x = gen_rtx_MEM (DECL_MODE (decl), x); 1462 x = gen_rtx_MEM (DECL_MODE (decl), x);
1436 if (TREE_CODE (decl) != FUNCTION_DECL) 1463 if (TREE_CODE (decl) != FUNCTION_DECL)
1480 sorry ("global destructors not supported on this target"); 1507 sorry ("global destructors not supported on this target");
1481 #endif 1508 #endif
1482 } 1509 }
1483 1510
1484 /* Write the address of the entity given by SYMBOL to SEC. */ 1511 /* Write the address of the entity given by SYMBOL to SEC. */
1485 void 1512 void
1486 assemble_addr_to_section (rtx symbol, section *sec) 1513 assemble_addr_to_section (rtx symbol, section *sec)
1487 { 1514 {
1488 switch_to_section (sec); 1515 switch_to_section (sec);
1489 assemble_align (POINTER_SIZE); 1516 assemble_align (POINTER_SIZE);
1490 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); 1517 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1511 default_named_section_asm_out_destructor (rtx symbol, int priority) 1538 default_named_section_asm_out_destructor (rtx symbol, int priority)
1512 { 1539 {
1513 section *sec; 1540 section *sec;
1514 1541
1515 if (priority != DEFAULT_INIT_PRIORITY) 1542 if (priority != DEFAULT_INIT_PRIORITY)
1516 sec = get_cdtor_priority_section (priority, 1543 sec = get_cdtor_priority_section (priority,
1517 /*constructor_p=*/false); 1544 /*constructor_p=*/false);
1518 else 1545 else
1519 sec = get_section (".dtors", SECTION_WRITE, NULL); 1546 sec = get_section (".dtors", SECTION_WRITE, NULL);
1520 1547
1521 assemble_addr_to_section (symbol, sec); 1548 assemble_addr_to_section (symbol, sec);
1551 default_named_section_asm_out_constructor (rtx symbol, int priority) 1578 default_named_section_asm_out_constructor (rtx symbol, int priority)
1552 { 1579 {
1553 section *sec; 1580 section *sec;
1554 1581
1555 if (priority != DEFAULT_INIT_PRIORITY) 1582 if (priority != DEFAULT_INIT_PRIORITY)
1556 sec = get_cdtor_priority_section (priority, 1583 sec = get_cdtor_priority_section (priority,
1557 /*constructor_p=*/true); 1584 /*constructor_p=*/true);
1558 else 1585 else
1559 sec = get_section (".ctors", SECTION_WRITE, NULL); 1586 sec = get_section (".ctors", SECTION_WRITE, NULL);
1560 1587
1561 assemble_addr_to_section (symbol, sec); 1588 assemble_addr_to_section (symbol, sec);
1735 1762
1736 #ifdef ASM_OUTPUT_FUNCTION_PREFIX 1763 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1737 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname); 1764 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1738 #endif 1765 #endif
1739 1766
1740 (*debug_hooks->begin_function) (decl); 1767 if (!DECL_IGNORED_P (decl))
1768 (*debug_hooks->begin_function) (decl);
1741 1769
1742 /* Make function name accessible from other files, if appropriate. */ 1770 /* Make function name accessible from other files, if appropriate. */
1743 1771
1744 if (TREE_PUBLIC (decl)) 1772 if (TREE_PUBLIC (decl))
1745 { 1773 {
2002 { 2030 {
2003 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4); 2031 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2004 constructor_elt *elt; 2032 constructor_elt *elt;
2005 tree type = TREE_TYPE (to); 2033 tree type = TREE_TYPE (to);
2006 tree field = TYPE_FIELDS (type); 2034 tree field = TYPE_FIELDS (type);
2007 2035
2008 elt = VEC_quick_push (constructor_elt, v, NULL); 2036 elt = VEC_quick_push (constructor_elt, v, NULL);
2009 elt->index = field; 2037 elt->index = field;
2010 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl)); 2038 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2011 2039
2012 elt = VEC_quick_push (constructor_elt, v, NULL); 2040 elt = VEC_quick_push (constructor_elt, v, NULL);
2013 field = TREE_CHAIN (field); 2041 field = TREE_CHAIN (field);
2014 elt->index = field; 2042 elt->index = field;
2015 elt->value = build_int_cst (TREE_TYPE (field), 2043 elt->value = build_int_cst (TREE_TYPE (field),
2016 DECL_ALIGN_UNIT (decl)); 2044 DECL_ALIGN_UNIT (decl));
2017 2045
2018 elt = VEC_quick_push (constructor_elt, v, NULL); 2046 elt = VEC_quick_push (constructor_elt, v, NULL);
2019 field = TREE_CHAIN (field); 2047 field = TREE_CHAIN (field);
2020 elt->index = field; 2048 elt->index = field;
2021 elt->value = null_pointer_node; 2049 elt->value = null_pointer_node;
2022 2050
2023 elt = VEC_quick_push (constructor_elt, v, NULL); 2051 elt = VEC_quick_push (constructor_elt, v, NULL);
2024 field = TREE_CHAIN (field); 2052 field = TREE_CHAIN (field);
2025 elt->index = field; 2053 elt->index = field;
2026 elt->value = proxy; 2054 elt->value = proxy;
2027 2055
2028 return build_constructor (type, v); 2056 return build_constructor (type, v);
2029 } 2057 }
2030 2058
2031 /* Assemble everything that is needed for a variable or function declaration. 2059 /* Assemble everything that is needed for a variable or function declaration.
2032 Not used for automatic variables, and not used for function definitions. 2060 Not used for automatic variables, and not used for function definitions.
2067 2095
2068 /* Make sure the template is marked as needed early enough. 2096 /* Make sure the template is marked as needed early enough.
2069 Without this, if the variable is placed in a 2097 Without this, if the variable is placed in a
2070 section-anchored block, the template will only be marked 2098 section-anchored block, the template will only be marked
2071 when it's too late. */ 2099 when it's too late. */
2072 record_references_in_initializer (to); 2100 record_references_in_initializer (to, false);
2073 } 2101 }
2074 2102
2075 decl = to; 2103 decl = to;
2076 } 2104 }
2077 2105
2247 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL 2275 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2248 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA) 2276 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2249 return true; 2277 return true;
2250 2278
2251 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 2279 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2252 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0) 2280 if (is_builtin_name (name))
2253 return true; 2281 return true;
2254 } 2282 }
2255 return false; 2283 return false;
2256 } 2284 }
2257 2285
2307 return; 2335 return;
2308 2336
2309 /* We want to output annotation for weak and external symbols at 2337 /* We want to output annotation for weak and external symbols at
2310 very last to check if they are references or not. */ 2338 very last to check if they are references or not. */
2311 2339
2312 if (SUPPORTS_WEAK 2340 if (SUPPORTS_WEAK && DECL_WEAK (decl)
2313 && DECL_WEAK (decl)
2314 /* TREE_STATIC is a weird and abused creature which is not 2341 /* TREE_STATIC is a weird and abused creature which is not
2315 generally the right test for whether an entity has been 2342 generally the right test for whether an entity has been
2316 locally emitted, inlined or otherwise not-really-extern, but 2343 locally emitted, inlined or otherwise not-really-extern, but
2317 for declarations that can be weak, it happens to be 2344 for declarations that can be weak, it happens to be
2318 match. */ 2345 match. */
2319 && !TREE_STATIC (decl) 2346 && !TREE_STATIC (decl)
2320 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))) 2347 && value_member (decl, weak_decls) == NULL_TREE)
2321 weak_decls = tree_cons (NULL, decl, weak_decls); 2348 weak_decls = tree_cons (NULL, decl, weak_decls);
2322 2349
2323 #ifdef ASM_OUTPUT_EXTERNAL 2350 #ifdef ASM_OUTPUT_EXTERNAL
2324 pending_assemble_externals = tree_cons (0, decl, 2351 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2325 pending_assemble_externals); 2352 pending_assemble_externals = tree_cons (NULL, decl,
2353 pending_assemble_externals);
2326 #endif 2354 #endif
2327 } 2355 }
2328 2356
2329 /* Similar, for calling a library function FUN. */ 2357 /* Similar, for calling a library function FUN. */
2330 2358
2492 This is done at most once per compilation. 2520 This is done at most once per compilation.
2493 Returns an RTX for the address of the template. */ 2521 Returns an RTX for the address of the template. */
2494 2522
2495 static GTY(()) rtx initial_trampoline; 2523 static GTY(()) rtx initial_trampoline;
2496 2524
2497 #ifdef TRAMPOLINE_TEMPLATE
2498 rtx 2525 rtx
2499 assemble_trampoline_template (void) 2526 assemble_trampoline_template (void)
2500 { 2527 {
2501 char label[256]; 2528 char label[256];
2502 const char *name; 2529 const char *name;
2503 int align; 2530 int align;
2504 rtx symbol; 2531 rtx symbol;
2532
2533 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2505 2534
2506 if (initial_trampoline) 2535 if (initial_trampoline)
2507 return initial_trampoline; 2536 return initial_trampoline;
2508 2537
2509 /* By default, put trampoline templates in read-only data section. */ 2538 /* By default, put trampoline templates in read-only data section. */
2515 #endif 2544 #endif
2516 2545
2517 /* Write the assembler code to define one. */ 2546 /* Write the assembler code to define one. */
2518 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); 2547 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2519 if (align > 0) 2548 if (align > 0)
2520 { 2549 ASM_OUTPUT_ALIGN (asm_out_file, align);
2521 ASM_OUTPUT_ALIGN (asm_out_file, align);
2522 }
2523 2550
2524 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0); 2551 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2525 TRAMPOLINE_TEMPLATE (asm_out_file); 2552 targetm.asm_out.trampoline_template (asm_out_file);
2526 2553
2527 /* Record the rtl to refer to it. */ 2554 /* Record the rtl to refer to it. */
2528 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0); 2555 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2529 name = ggc_strdup (label); 2556 name = ggc_strdup (label);
2530 symbol = gen_rtx_SYMBOL_REF (Pmode, name); 2557 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2531 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL; 2558 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2532 2559
2533 initial_trampoline = gen_rtx_MEM (BLKmode, symbol); 2560 initial_trampoline = gen_const_mem (BLKmode, symbol);
2534 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT); 2561 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2562 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2535 2563
2536 return initial_trampoline; 2564 return initial_trampoline;
2537 } 2565 }
2538 #endif
2539 2566
2540 /* A and B are either alignments or offsets. Return the minimum alignment 2567 /* A and B are either alignments or offsets. Return the minimum alignment
2541 that may be assumed after adding the two together. */ 2568 that may be assumed after adding the two together. */
2542 2569
2543 static inline unsigned 2570 static inline unsigned
2628 if (size > 1) 2655 if (size > 1)
2629 { 2656 {
2630 enum machine_mode omode, imode; 2657 enum machine_mode omode, imode;
2631 unsigned int subalign; 2658 unsigned int subalign;
2632 unsigned int subsize, i; 2659 unsigned int subsize, i;
2633 unsigned char mclass; 2660 enum mode_class mclass;
2634 2661
2635 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1; 2662 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2636 subalign = MIN (align, subsize * BITS_PER_UNIT); 2663 subalign = MIN (align, subsize * BITS_PER_UNIT);
2637 if (GET_CODE (x) == CONST_FIXED) 2664 if (GET_CODE (x) == CONST_FIXED)
2638 mclass = GET_MODE_CLASS (GET_MODE (x)); 2665 mclass = GET_MODE_CLASS (GET_MODE (x));
2704 /* Given an expression EXP with a constant value, 2731 /* Given an expression EXP with a constant value,
2705 reduce it to the sum of an assembler symbol and an integer. 2732 reduce it to the sum of an assembler symbol and an integer.
2706 Store them both in the structure *VALUE. 2733 Store them both in the structure *VALUE.
2707 EXP must be reducible. */ 2734 EXP must be reducible. */
2708 2735
2709 struct addr_const GTY(()) 2736 struct GTY(()) addr_const {
2710 {
2711 rtx base; 2737 rtx base;
2712 HOST_WIDE_INT offset; 2738 HOST_WIDE_INT offset;
2713 }; 2739 };
2714 2740
2715 static void 2741 static void
2769 2795
2770 value->base = x; 2796 value->base = x;
2771 value->offset = offset; 2797 value->offset = offset;
2772 } 2798 }
2773 2799
2774 /* Uniquize all constants that appear in memory.
2775 Each constant in memory thus far output is recorded
2776 in `const_desc_table'. */
2777
2778 struct constant_descriptor_tree GTY(())
2779 {
2780 /* A MEM for the constant. */
2781 rtx rtl;
2782
2783 /* The value of the constant. */
2784 tree value;
2785
2786 /* Hash of value. Computing the hash from value each time
2787 hashfn is called can't work properly, as that means recursive
2788 use of the hash table during hash table expansion. */
2789 hashval_t hash;
2790 };
2791 2800
2792 static GTY((param_is (struct constant_descriptor_tree))) 2801 static GTY((param_is (struct constant_descriptor_tree)))
2793 htab_t const_desc_htab; 2802 htab_t const_desc_htab;
2794 2803
2795 static struct constant_descriptor_tree * build_constant_desc (tree); 2804 static struct constant_descriptor_tree * build_constant_desc (tree);
2796 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int); 2805 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2806
2807 /* Constant pool accessor function. */
2808
2809 htab_t
2810 constant_pool_htab (void)
2811 {
2812 return const_desc_htab;
2813 }
2797 2814
2798 /* Compute a hash code for a constant expression. */ 2815 /* Compute a hash code for a constant expression. */
2799 2816
2800 static hashval_t 2817 static hashval_t
2801 const_desc_hash (const void *ptr) 2818 const_desc_hash (const void *ptr)
3196 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol); 3213 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3197 set_mem_attributes (rtl, exp, 1); 3214 set_mem_attributes (rtl, exp, 1);
3198 set_mem_alias_set (rtl, 0); 3215 set_mem_alias_set (rtl, 0);
3199 set_mem_alias_set (rtl, const_alias_set); 3216 set_mem_alias_set (rtl, const_alias_set);
3200 3217
3218 /* We cannot share RTX'es in pool entries.
3219 Mark this piece of RTL as required for unsharing. */
3220 RTX_FLAG (rtl, used) = 1;
3221
3201 /* Set flags or add text to the name to record information, such as 3222 /* Set flags or add text to the name to record information, such as
3202 that it is a local symbol. If the name is changed, the macro 3223 that it is a local symbol. If the name is changed, the macro
3203 ASM_OUTPUT_LABELREF will have to know how to strip this 3224 ASM_OUTPUT_LABELREF will have to know how to strip this
3204 information. This call might invalidate our local variable 3225 information. This call might invalidate our local variable
3205 SYMBOL; we can't use it afterward. */ 3226 SYMBOL; we can't use it afterward. */
3359 are output once per function, not once per file. */ 3380 are output once per function, not once per file. */
3360 /* ??? Only a few targets need per-function constant pools. Most 3381 /* ??? Only a few targets need per-function constant pools. Most
3361 can use one per-file pool. Should add a targetm bit to tell the 3382 can use one per-file pool. Should add a targetm bit to tell the
3362 difference. */ 3383 difference. */
3363 3384
3364 struct rtx_constant_pool GTY(()) 3385 struct GTY(()) rtx_constant_pool {
3365 {
3366 /* Pointers to first and last constant in pool, as ordered by offset. */ 3386 /* Pointers to first and last constant in pool, as ordered by offset. */
3367 struct constant_descriptor_rtx *first; 3387 struct constant_descriptor_rtx *first;
3368 struct constant_descriptor_rtx *last; 3388 struct constant_descriptor_rtx *last;
3369 3389
3370 /* Hash facility for making memory-constants from constant rtl-expressions. 3390 /* Hash facility for making memory-constants from constant rtl-expressions.
3376 /* Current offset in constant pool (does not include any 3396 /* Current offset in constant pool (does not include any
3377 machine-specific header). */ 3397 machine-specific header). */
3378 HOST_WIDE_INT offset; 3398 HOST_WIDE_INT offset;
3379 }; 3399 };
3380 3400
3381 struct constant_descriptor_rtx GTY((chain_next ("%h.next"))) 3401 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3382 {
3383 struct constant_descriptor_rtx *next; 3402 struct constant_descriptor_rtx *next;
3384 rtx mem; 3403 rtx mem;
3385 rtx sym; 3404 rtx sym;
3386 rtx constant; 3405 rtx constant;
3387 HOST_WIDE_INT offset; 3406 HOST_WIDE_INT offset;
3435 { 3454 {
3436 case CONST_INT: 3455 case CONST_INT:
3437 hwi = INTVAL (x); 3456 hwi = INTVAL (x);
3438 fold_hwi: 3457 fold_hwi:
3439 { 3458 {
3440 const int shift = sizeof (hashval_t) * CHAR_BIT; 3459 int shift = sizeof (hashval_t) * CHAR_BIT;
3441 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t); 3460 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3442 int i; 3461 int i;
3443 3462
3444 h ^= (hashval_t) hwi; 3463 h ^= (hashval_t) hwi;
3445 for (i = 1; i < n; ++i) 3464 for (i = 1; i < n; ++i)
4070 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE 4089 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4071 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE) 4090 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4072 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor))); 4091 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4073 } 4092 }
4074 4093
4075 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4076 tree *cache);
4077
4078 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR, 4094 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4079 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE 4095 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4080 which are valid when ENDTYPE is an integer of any size; in 4096 which are valid when ENDTYPE is an integer of any size; in
4081 particular, this does not accept a pointer minus a constant. This 4097 particular, this does not accept a pointer minus a constant. This
4082 returns null_pointer_node if the VALUE is an absolute constant 4098 returns null_pointer_node if the VALUE is an absolute constant
4083 which can be used to initialize a static variable. Otherwise it 4099 which can be used to initialize a static variable. Otherwise it
4084 returns NULL. */ 4100 returns NULL. */
4085 4101
4086 static tree 4102 static tree
4087 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache) 4103 narrowing_initializer_constant_valid_p (tree value, tree endtype)
4088 { 4104 {
4089 tree op0, op1; 4105 tree op0, op1;
4090 4106
4091 if (!INTEGRAL_TYPE_P (endtype)) 4107 if (!INTEGRAL_TYPE_P (endtype))
4092 return NULL_TREE; 4108 return NULL_TREE;
4121 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) 4137 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4122 break; 4138 break;
4123 op1 = inner; 4139 op1 = inner;
4124 } 4140 }
4125 4141
4126 op0 = initializer_constant_valid_p_1 (op0, endtype, cache); 4142 op0 = initializer_constant_valid_p (op0, endtype);
4127 if (!op0) 4143 op1 = initializer_constant_valid_p (op1, endtype);
4128 return NULL_TREE; 4144
4129
4130 op1 = initializer_constant_valid_p_1 (op1, endtype,
4131 cache ? cache + 2 : NULL);
4132 /* Both initializers must be known. */ 4145 /* Both initializers must be known. */
4133 if (op1) 4146 if (op0 && op1)
4134 { 4147 {
4135 if (op0 == op1 4148 if (op0 == op1
4136 && (op0 == null_pointer_node 4149 && (op0 == null_pointer_node
4137 || TREE_CODE (value) == MINUS_EXPR)) 4150 || TREE_CODE (value) == MINUS_EXPR))
4138 return null_pointer_node; 4151 return null_pointer_node;
4149 } 4162 }
4150 4163
4151 return NULL_TREE; 4164 return NULL_TREE;
4152 } 4165 }
4153 4166
4154 /* Helper function of initializer_constant_valid_p. 4167 /* Return nonzero if VALUE is a valid constant-valued expression
4155 Return nonzero if VALUE is a valid constant-valued expression
4156 for use in initializing a static variable; one that can be an 4168 for use in initializing a static variable; one that can be an
4157 element of a "constant" initializer. 4169 element of a "constant" initializer.
4158 4170
4159 Return null_pointer_node if the value is absolute; 4171 Return null_pointer_node if the value is absolute;
4160 if it is relocatable, return the variable that determines the relocation. 4172 if it is relocatable, return the variable that determines the relocation.
4161 We assume that VALUE has been folded as much as possible; 4173 We assume that VALUE has been folded as much as possible;
4162 therefore, we do not need to check for such things as 4174 therefore, we do not need to check for such things as
4163 arithmetic-combinations of integers. 4175 arithmetic-combinations of integers. */
4164 4176
4165 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */ 4177 tree
4166 4178 initializer_constant_valid_p (tree value, tree endtype)
4167 static tree
4168 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4169 { 4179 {
4170 tree ret; 4180 tree ret;
4171 4181
4172 switch (TREE_CODE (value)) 4182 switch (TREE_CODE (value))
4173 { 4183 {
4176 { 4186 {
4177 unsigned HOST_WIDE_INT idx; 4187 unsigned HOST_WIDE_INT idx;
4178 tree elt; 4188 tree elt;
4179 bool absolute = true; 4189 bool absolute = true;
4180 4190
4181 if (cache && cache[0] == value)
4182 return cache[1];
4183 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt) 4191 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4184 { 4192 {
4185 tree reloc; 4193 tree reloc;
4186 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt), 4194 reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt));
4187 NULL);
4188 if (!reloc) 4195 if (!reloc)
4189 { 4196 return NULL_TREE;
4190 if (cache)
4191 {
4192 cache[0] = value;
4193 cache[1] = NULL_TREE;
4194 }
4195 return NULL_TREE;
4196 }
4197 if (reloc != null_pointer_node) 4197 if (reloc != null_pointer_node)
4198 absolute = false; 4198 absolute = false;
4199 } 4199 }
4200 /* For a non-absolute relocation, there is no single 4200 /* For a non-absolute relocation, there is no single
4201 variable that can be "the variable that determines the 4201 variable that can be "the variable that determines the
4202 relocation." */ 4202 relocation." */
4203 if (cache)
4204 {
4205 cache[0] = value;
4206 cache[1] = absolute ? null_pointer_node : error_mark_node;
4207 }
4208 return absolute ? null_pointer_node : error_mark_node; 4203 return absolute ? null_pointer_node : error_mark_node;
4209 } 4204 }
4210 4205
4211 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE; 4206 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4212 4207
4230 && TREE_CONSTANT (TREE_OPERAND (op0, 0))) 4225 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4231 return null_pointer_node; 4226 return null_pointer_node;
4232 /* Taking the address of a nested function involves a trampoline, 4227 /* Taking the address of a nested function involves a trampoline,
4233 unless we don't need or want one. */ 4228 unless we don't need or want one. */
4234 if (TREE_CODE (op0) == FUNCTION_DECL 4229 if (TREE_CODE (op0) == FUNCTION_DECL
4235 && decl_function_context (op0) 4230 && DECL_STATIC_CHAIN (op0)
4236 && !DECL_NO_STATIC_CHAIN (op0)
4237 && !TREE_NO_TRAMPOLINE (value)) 4231 && !TREE_NO_TRAMPOLINE (value))
4238 return NULL_TREE; 4232 return NULL_TREE;
4239 /* "&{...}" requires a temporary to hold the constructed 4233 /* "&{...}" requires a temporary to hold the constructed
4240 object. */ 4234 object. */
4241 if (TREE_CODE (op0) == CONSTRUCTOR) 4235 if (TREE_CODE (op0) == CONSTRUCTOR)
4243 } 4237 }
4244 return op0; 4238 return op0;
4245 } 4239 }
4246 4240
4247 case NON_LVALUE_EXPR: 4241 case NON_LVALUE_EXPR:
4248 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0), 4242 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4249 endtype, cache);
4250 4243
4251 case VIEW_CONVERT_EXPR: 4244 case VIEW_CONVERT_EXPR:
4252 { 4245 {
4253 tree src = TREE_OPERAND (value, 0); 4246 tree src = TREE_OPERAND (value, 0);
4254 tree src_type = TREE_TYPE (src); 4247 tree src_type = TREE_TYPE (src);
4259 RTL expander won't be able to apply a subsequent transformation 4252 RTL expander won't be able to apply a subsequent transformation
4260 to the underlying constructor. */ 4253 to the underlying constructor. */
4261 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type)) 4254 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4262 { 4255 {
4263 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type)) 4256 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4264 return initializer_constant_valid_p_1 (src, endtype, cache); 4257 return initializer_constant_valid_p (src, endtype);
4265 else 4258 else
4266 return NULL_TREE; 4259 return NULL_TREE;
4267 } 4260 }
4268 4261
4269 /* Allow all other kinds of view-conversion. */ 4262 /* Allow all other kinds of view-conversion. */
4270 return initializer_constant_valid_p_1 (src, endtype, cache); 4263 return initializer_constant_valid_p (src, endtype);
4271 } 4264 }
4272 4265
4273 CASE_CONVERT: 4266 CASE_CONVERT:
4274 { 4267 {
4275 tree src = TREE_OPERAND (value, 0); 4268 tree src = TREE_OPERAND (value, 0);
4280 types, and offset types. */ 4273 types, and offset types. */
4281 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)) 4274 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4282 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type)) 4275 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4283 || (TREE_CODE (dest_type) == OFFSET_TYPE 4276 || (TREE_CODE (dest_type) == OFFSET_TYPE
4284 && TREE_CODE (src_type) == OFFSET_TYPE)) 4277 && TREE_CODE (src_type) == OFFSET_TYPE))
4285 return initializer_constant_valid_p_1 (src, endtype, cache); 4278 return initializer_constant_valid_p (src, endtype);
4286 4279
4287 /* Allow length-preserving conversions between integer types. */ 4280 /* Allow length-preserving conversions between integer types. */
4288 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type) 4281 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4289 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type))) 4282 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4290 return initializer_constant_valid_p_1 (src, endtype, cache); 4283 return initializer_constant_valid_p (src, endtype);
4291 4284
4292 /* Allow conversions between other integer types only if 4285 /* Allow conversions between other integer types only if
4293 explicit value. */ 4286 explicit value. */
4294 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)) 4287 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4295 { 4288 {
4296 tree inner = initializer_constant_valid_p_1 (src, endtype, cache); 4289 tree inner = initializer_constant_valid_p (src, endtype);
4297 if (inner == null_pointer_node) 4290 if (inner == null_pointer_node)
4298 return null_pointer_node; 4291 return null_pointer_node;
4299 break; 4292 break;
4300 } 4293 }
4301 4294
4302 /* Allow (int) &foo provided int is as wide as a pointer. */ 4295 /* Allow (int) &foo provided int is as wide as a pointer. */
4303 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type) 4296 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4304 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))) 4297 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4305 return initializer_constant_valid_p_1 (src, endtype, cache); 4298 return initializer_constant_valid_p (src, endtype);
4306 4299
4307 /* Likewise conversions from int to pointers, but also allow 4300 /* Likewise conversions from int to pointers, but also allow
4308 conversions from 0. */ 4301 conversions from 0. */
4309 if ((POINTER_TYPE_P (dest_type) 4302 if ((POINTER_TYPE_P (dest_type)
4310 || TREE_CODE (dest_type) == OFFSET_TYPE) 4303 || TREE_CODE (dest_type) == OFFSET_TYPE)
4314 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)) 4307 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4315 return null_pointer_node; 4308 return null_pointer_node;
4316 if (integer_zerop (src)) 4309 if (integer_zerop (src))
4317 return null_pointer_node; 4310 return null_pointer_node;
4318 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)) 4311 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4319 return initializer_constant_valid_p_1 (src, endtype, cache); 4312 return initializer_constant_valid_p (src, endtype);
4320 } 4313 }
4321 4314
4322 /* Allow conversions to struct or union types if the value 4315 /* Allow conversions to struct or union types if the value
4323 inside is okay. */ 4316 inside is okay. */
4324 if (TREE_CODE (dest_type) == RECORD_TYPE 4317 if (TREE_CODE (dest_type) == RECORD_TYPE
4325 || TREE_CODE (dest_type) == UNION_TYPE) 4318 || TREE_CODE (dest_type) == UNION_TYPE)
4326 return initializer_constant_valid_p_1 (src, endtype, cache); 4319 return initializer_constant_valid_p (src, endtype);
4327 } 4320 }
4328 break; 4321 break;
4329 4322
4330 case POINTER_PLUS_EXPR: 4323 case POINTER_PLUS_EXPR:
4331 case PLUS_EXPR: 4324 case PLUS_EXPR:
4332 /* Any valid floating-point constants will have been folded by now; 4325 /* Any valid floating-point constants will have been folded by now;
4333 with -frounding-math we hit this with addition of two constants. */ 4326 with -frounding-math we hit this with addition of two constants. */
4334 if (TREE_CODE (endtype) == REAL_TYPE) 4327 if (TREE_CODE (endtype) == REAL_TYPE)
4335 return NULL_TREE; 4328 return NULL_TREE;
4336 if (cache && cache[0] == value)
4337 return cache[1];
4338 if (! INTEGRAL_TYPE_P (endtype) 4329 if (! INTEGRAL_TYPE_P (endtype)
4339 || TYPE_PRECISION (endtype) >= POINTER_SIZE) 4330 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4340 { 4331 {
4341 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE }; 4332 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4342 tree valid0 4333 endtype);
4343 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0), 4334 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4344 endtype, ncache); 4335 endtype);
4345 tree valid1
4346 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4347 endtype, ncache + 2);
4348 /* If either term is absolute, use the other term's relocation. */ 4336 /* If either term is absolute, use the other term's relocation. */
4349 if (valid0 == null_pointer_node) 4337 if (valid0 == null_pointer_node)
4350 ret = valid1; 4338 return valid1;
4351 else if (valid1 == null_pointer_node) 4339 if (valid1 == null_pointer_node)
4352 ret = valid0; 4340 return valid0;
4353 /* Support narrowing pointer differences. */
4354 else
4355 ret = narrowing_initializer_constant_valid_p (value, endtype,
4356 ncache);
4357 } 4341 }
4358 else 4342
4359 /* Support narrowing pointer differences. */ 4343 /* Support narrowing pointer differences. */
4360 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL); 4344 ret = narrowing_initializer_constant_valid_p (value, endtype);
4361 if (cache) 4345 if (ret != NULL_TREE)
4362 { 4346 return ret;
4363 cache[0] = value; 4347
4364 cache[1] = ret; 4348 break;
4365 }
4366 return ret;
4367 4349
4368 case MINUS_EXPR: 4350 case MINUS_EXPR:
4369 if (TREE_CODE (endtype) == REAL_TYPE) 4351 if (TREE_CODE (endtype) == REAL_TYPE)
4370 return NULL_TREE; 4352 return NULL_TREE;
4371 if (cache && cache[0] == value)
4372 return cache[1];
4373 if (! INTEGRAL_TYPE_P (endtype) 4353 if (! INTEGRAL_TYPE_P (endtype)
4374 || TYPE_PRECISION (endtype) >= POINTER_SIZE) 4354 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4375 { 4355 {
4376 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE }; 4356 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4377 tree valid0 4357 endtype);
4378 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0), 4358 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4379 endtype, ncache); 4359 endtype);
4380 tree valid1
4381 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4382 endtype, ncache + 2);
4383 /* Win if second argument is absolute. */ 4360 /* Win if second argument is absolute. */
4384 if (valid1 == null_pointer_node) 4361 if (valid1 == null_pointer_node)
4385 ret = valid0; 4362 return valid0;
4386 /* Win if both arguments have the same relocation. 4363 /* Win if both arguments have the same relocation.
4387 Then the value is absolute. */ 4364 Then the value is absolute. */
4388 else if (valid0 == valid1 && valid0 != 0) 4365 if (valid0 == valid1 && valid0 != 0)
4389 ret = null_pointer_node; 4366 return null_pointer_node;
4367
4390 /* Since GCC guarantees that string constants are unique in the 4368 /* Since GCC guarantees that string constants are unique in the
4391 generated code, a subtraction between two copies of the same 4369 generated code, a subtraction between two copies of the same
4392 constant string is absolute. */ 4370 constant string is absolute. */
4393 else if (valid0 && TREE_CODE (valid0) == STRING_CST 4371 if (valid0 && TREE_CODE (valid0) == STRING_CST
4394 && valid1 && TREE_CODE (valid1) == STRING_CST 4372 && valid1 && TREE_CODE (valid1) == STRING_CST
4395 && operand_equal_p (valid0, valid1, 1)) 4373 && operand_equal_p (valid0, valid1, 1))
4396 ret = null_pointer_node; 4374 return null_pointer_node;
4397 /* Support narrowing differences. */
4398 else
4399 ret = narrowing_initializer_constant_valid_p (value, endtype,
4400 ncache);
4401 } 4375 }
4402 else 4376
4403 /* Support narrowing differences. */ 4377 /* Support narrowing differences. */
4404 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL); 4378 ret = narrowing_initializer_constant_valid_p (value, endtype);
4405 if (cache) 4379 if (ret != NULL_TREE)
4406 { 4380 return ret;
4407 cache[0] = value; 4381
4408 cache[1] = ret; 4382 break;
4409 }
4410 return ret;
4411 4383
4412 default: 4384 default:
4413 break; 4385 break;
4414 } 4386 }
4415 4387
4416 return NULL_TREE; 4388 return 0;
4417 }
4418
4419 /* Return nonzero if VALUE is a valid constant-valued expression
4420 for use in initializing a static variable; one that can be an
4421 element of a "constant" initializer.
4422
4423 Return null_pointer_node if the value is absolute;
4424 if it is relocatable, return the variable that determines the relocation.
4425 We assume that VALUE has been folded as much as possible;
4426 therefore, we do not need to check for such things as
4427 arithmetic-combinations of integers. */
4428 tree
4429 initializer_constant_valid_p (tree value, tree endtype)
4430 {
4431 return initializer_constant_valid_p_1 (value, endtype, NULL);
4432 } 4389 }
4433 4390
4391 /* Return true if VALUE is a valid constant-valued expression
4392 for use in initializing a static bit-field; one that can be
4393 an element of a "constant" initializer. */
4394
4395 bool
4396 initializer_constant_valid_for_bitfield_p (tree value)
4397 {
4398 /* For bitfields we support integer constants or possibly nested aggregates
4399 of such. */
4400 switch (TREE_CODE (value))
4401 {
4402 case CONSTRUCTOR:
4403 {
4404 unsigned HOST_WIDE_INT idx;
4405 tree elt;
4406
4407 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4408 if (!initializer_constant_valid_for_bitfield_p (elt))
4409 return false;
4410 return true;
4411 }
4412
4413 case INTEGER_CST:
4414 return true;
4415
4416 case VIEW_CONVERT_EXPR:
4417 case NON_LVALUE_EXPR:
4418 return
4419 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
4420
4421 default:
4422 break;
4423 }
4424
4425 return false;
4426 }
4427
4428 /* output_constructor outer state of relevance in recursive calls, typically
4429 for nested aggregate bitfields. */
4430
4431 typedef struct {
4432 unsigned int bit_offset; /* current position in ... */
4433 int byte; /* ... the outer byte buffer. */
4434 } oc_outer_state;
4435
4436 static unsigned HOST_WIDE_INT
4437 output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int,
4438 oc_outer_state *);
4439
4434 /* Output assembler code for constant EXP to FILE, with no label. 4440 /* Output assembler code for constant EXP to FILE, with no label.
4435 This includes the pseudo-op such as ".int" or ".byte", and a newline. 4441 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4436 Assumes output_addressed_constants has been done on EXP already. 4442 Assumes output_addressed_constants has been done on EXP already.
4437 4443
4438 Generate exactly SIZE bytes of assembler data, padding at the end 4444 Generate exactly SIZE bytes of assembler data, padding at the end
4464 to the address of some declaration somewhere. If the target says 4470 to the address of some declaration somewhere. If the target says
4465 the mode is valid for pointers, assume the target has a way of 4471 the mode is valid for pointers, assume the target has a way of
4466 resolving it. */ 4472 resolving it. */
4467 if (TREE_CODE (exp) == NOP_EXPR 4473 if (TREE_CODE (exp) == NOP_EXPR
4468 && POINTER_TYPE_P (TREE_TYPE (exp)) 4474 && POINTER_TYPE_P (TREE_TYPE (exp))
4469 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp)))) 4475 && targetm.addr_space.valid_pointer_mode
4476 (TYPE_MODE (TREE_TYPE (exp)),
4477 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4470 { 4478 {
4471 tree saved_type = TREE_TYPE (exp); 4479 tree saved_type = TREE_TYPE (exp);
4472 4480
4473 /* Peel off any intermediate conversions-to-pointer for valid 4481 /* Peel off any intermediate conversions-to-pointer for valid
4474 pointer modes. */ 4482 pointer modes. */
4475 while (TREE_CODE (exp) == NOP_EXPR 4483 while (TREE_CODE (exp) == NOP_EXPR
4476 && POINTER_TYPE_P (TREE_TYPE (exp)) 4484 && POINTER_TYPE_P (TREE_TYPE (exp))
4477 && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp)))) 4485 && targetm.addr_space.valid_pointer_mode
4486 (TYPE_MODE (TREE_TYPE (exp)),
4487 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
4478 exp = TREE_OPERAND (exp, 0); 4488 exp = TREE_OPERAND (exp, 0);
4479 4489
4480 /* If what we're left with is the address of something, we can 4490 /* If what we're left with is the address of something, we can
4481 convert the address to the final type and output it that 4491 convert the address to the final type and output it that
4482 way. */ 4492 way. */
4484 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0)); 4494 exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
4485 /* Likewise for constant ints. */ 4495 /* Likewise for constant ints. */
4486 else if (TREE_CODE (exp) == INTEGER_CST) 4496 else if (TREE_CODE (exp) == INTEGER_CST)
4487 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp), 4497 exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp),
4488 TREE_INT_CST_HIGH (exp)); 4498 TREE_INT_CST_HIGH (exp));
4489 4499
4490 } 4500 }
4491 4501
4492 /* Eliminate any conversions since we'll be outputting the underlying 4502 /* Eliminate any conversions since we'll be outputting the underlying
4493 constant. */ 4503 constant. */
4494 while (CONVERT_EXPR_P (exp) 4504 while (CONVERT_EXPR_P (exp)
4567 case ARRAY_TYPE: 4577 case ARRAY_TYPE:
4568 case VECTOR_TYPE: 4578 case VECTOR_TYPE:
4569 switch (TREE_CODE (exp)) 4579 switch (TREE_CODE (exp))
4570 { 4580 {
4571 case CONSTRUCTOR: 4581 case CONSTRUCTOR:
4572 output_constructor (exp, size, align); 4582 output_constructor (exp, size, align, NULL);
4573 return; 4583 return;
4574 case STRING_CST: 4584 case STRING_CST:
4575 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp), 4585 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4576 size); 4586 size);
4577 assemble_string (TREE_STRING_POINTER (exp), thissize); 4587 assemble_string (TREE_STRING_POINTER (exp), thissize);
4605 break; 4615 break;
4606 4616
4607 case RECORD_TYPE: 4617 case RECORD_TYPE:
4608 case UNION_TYPE: 4618 case UNION_TYPE:
4609 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR); 4619 gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4610 output_constructor (exp, size, align); 4620 output_constructor (exp, size, align, NULL);
4611 return; 4621 return;
4612 4622
4613 case ERROR_MARK: 4623 case ERROR_MARK:
4614 return; 4624 return;
4615 4625
4661 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val)))); 4671 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4662 4672
4663 return tree_low_cst (i, 1); 4673 return tree_low_cst (i, 1);
4664 } 4674 }
4665 4675
4676 /* Other datastructures + helpers for output_constructor. */
4677
4678 /* output_constructor local state to support interaction with helpers. */
4679
4680 typedef struct {
4681
4682 /* Received arguments. */
4683 tree exp; /* Constructor expression. */
4684 unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
4685 unsigned int align; /* Known initial alignment. */
4686
4687 /* Constructor expression data. */
4688 tree type; /* Expression type. */
4689 tree field; /* Current field decl in a record. */
4690 tree min_index; /* Lower bound if specified for an array. */
4691
4692 /* Output processing state. */
4693 HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
4694 bool byte_buffer_in_use; /* Whether byte ... */
4695 int byte; /* ... contains part of a bitfield byte yet to
4696 be output. */
4697
4698 int last_relative_index; /* Implicit or explicit index of the last
4699 array element output within a bitfield. */
4700 /* Current element. */
4701 tree val; /* Current element value. */
4702 tree index; /* Current element index. */
4703
4704 } oc_local_state;
4705
4706 /* Helper for output_constructor. From the current LOCAL state, output a
4707 RANGE_EXPR element. */
4708
4709 static void
4710 output_constructor_array_range (oc_local_state *local)
4711 {
4712 unsigned HOST_WIDE_INT fieldsize
4713 = int_size_in_bytes (TREE_TYPE (local->type));
4714
4715 HOST_WIDE_INT lo_index
4716 = tree_low_cst (TREE_OPERAND (local->index, 0), 0);
4717 HOST_WIDE_INT hi_index
4718 = tree_low_cst (TREE_OPERAND (local->index, 1), 0);
4719 HOST_WIDE_INT index;
4720
4721 unsigned int align2
4722 = min_align (local->align, fieldsize * BITS_PER_UNIT);
4723
4724 for (index = lo_index; index <= hi_index; index++)
4725 {
4726 /* Output the element's initial value. */
4727 if (local->val == NULL_TREE)
4728 assemble_zeros (fieldsize);
4729 else
4730 output_constant (local->val, fieldsize, align2);
4731
4732 /* Count its size. */
4733 local->total_bytes += fieldsize;
4734 }
4735 }
4736
4737 /* Helper for output_constructor. From the current LOCAL state, output a
4738 field element that is not true bitfield or part of an outer one. */
4739
4740 static void
4741 output_constructor_regular_field (oc_local_state *local)
4742 {
4743 /* Field size and position. Since this structure is static, we know the
4744 positions are constant. */
4745 unsigned HOST_WIDE_INT fieldsize;
4746 HOST_WIDE_INT fieldpos;
4747
4748 unsigned int align2;
4749
4750 if (local->index != NULL_TREE)
4751 fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1)
4752 * ((tree_low_cst (local->index, 0)
4753 - tree_low_cst (local->min_index, 0))));
4754 else if (local->field != NULL_TREE)
4755 fieldpos = int_byte_position (local->field);
4756 else
4757 fieldpos = 0;
4758
4759 /* Output any buffered-up bit-fields preceding this element. */
4760 if (local->byte_buffer_in_use)
4761 {
4762 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4763 local->total_bytes++;
4764 local->byte_buffer_in_use = false;
4765 }
4766
4767 /* Advance to offset of this element.
4768 Note no alignment needed in an array, since that is guaranteed
4769 if each element has the proper size. */
4770 if ((local->field != NULL_TREE || local->index != NULL_TREE)
4771 && fieldpos != local->total_bytes)
4772 {
4773 gcc_assert (fieldpos >= local->total_bytes);
4774 assemble_zeros (fieldpos - local->total_bytes);
4775 local->total_bytes = fieldpos;
4776 }
4777
4778 /* Find the alignment of this element. */
4779 align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
4780
4781 /* Determine size this element should occupy. */
4782 if (local->field)
4783 {
4784 fieldsize = 0;
4785
4786 /* If this is an array with an unspecified upper bound,
4787 the initializer determines the size. */
4788 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4789 but we cannot do this until the deprecated support for
4790 initializing zero-length array members is removed. */
4791 if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
4792 && TYPE_DOMAIN (TREE_TYPE (local->field))
4793 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field))))
4794 {
4795 fieldsize = array_size_for_constructor (local->val);
4796 /* Given a non-empty initialization, this field had
4797 better be last. */
4798 gcc_assert (!fieldsize || !TREE_CHAIN (local->field));
4799 }
4800 else if (DECL_SIZE_UNIT (local->field))
4801 {
4802 /* ??? This can't be right. If the decl size overflows
4803 a host integer we will silently emit no data. */
4804 if (host_integerp (DECL_SIZE_UNIT (local->field), 1))
4805 fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1);
4806 }
4807 }
4808 else
4809 fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
4810
4811 /* Output the element's initial value. */
4812 if (local->val == NULL_TREE)
4813 assemble_zeros (fieldsize);
4814 else
4815 output_constant (local->val, fieldsize, align2);
4816
4817 /* Count its size. */
4818 local->total_bytes += fieldsize;
4819 }
4820
4821 /* Helper for output_constructor. From the current LOCAL and OUTER states,
4822 output an element that is a true bitfield or part of an outer one. */
4823
4824 static void
4825 output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer)
4826 {
4827 /* Bit size of this element. */
4828 HOST_WIDE_INT ebitsize
4829 = (local->field
4830 ? tree_low_cst (DECL_SIZE (local->field), 1)
4831 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1));
4832
4833 /* Relative index of this element if this is an array component. */
4834 HOST_WIDE_INT relative_index
4835 = (!local->field
4836 ? (local->index
4837 ? (tree_low_cst (local->index, 0)
4838 - tree_low_cst (local->min_index, 0))
4839 : local->last_relative_index + 1)
4840 : 0);
4841
4842 /* Bit position of this element from the start of the containing
4843 constructor. */
4844 HOST_WIDE_INT constructor_relative_ebitpos
4845 = (local->field
4846 ? int_bit_position (local->field)
4847 : ebitsize * relative_index);
4848
4849 /* Bit position of this element from the start of a possibly ongoing
4850 outer byte buffer. */
4851 HOST_WIDE_INT byte_relative_ebitpos
4852 = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos);
4853
4854 /* From the start of a possibly ongoing outer byte buffer, offsets to
4855 the first bit of this element and to the first bit past the end of
4856 this element. */
4857 HOST_WIDE_INT next_offset = byte_relative_ebitpos;
4858 HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
4859
4860 local->last_relative_index = relative_index;
4861
4862 if (local->val == NULL_TREE)
4863 local->val = integer_zero_node;
4864
4865 while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
4866 || TREE_CODE (local->val) == NON_LVALUE_EXPR)
4867 local->val = TREE_OPERAND (local->val, 0);
4868
4869 if (TREE_CODE (local->val) != INTEGER_CST
4870 && TREE_CODE (local->val) != CONSTRUCTOR)
4871 {
4872 error ("invalid initial value for member %qE", DECL_NAME (local->field));
4873 return;
4874 }
4875
4876 /* If this field does not start in this (or, next) byte,
4877 skip some bytes. */
4878 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4879 {
4880 /* Output remnant of any bit field in previous bytes. */
4881 if (local->byte_buffer_in_use)
4882 {
4883 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4884 local->total_bytes++;
4885 local->byte_buffer_in_use = false;
4886 }
4887
4888 /* If still not at proper byte, advance to there. */
4889 if (next_offset / BITS_PER_UNIT != local->total_bytes)
4890 {
4891 gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
4892 assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
4893 local->total_bytes = next_offset / BITS_PER_UNIT;
4894 }
4895 }
4896
4897 /* Set up the buffer if necessary. */
4898 if (!local->byte_buffer_in_use)
4899 {
4900 local->byte = 0;
4901 if (ebitsize > 0)
4902 local->byte_buffer_in_use = true;
4903 }
4904
4905 /* If this is nested constructor, recurse passing the bit offset and the
4906 pending data, then retrieve the new pending data afterwards. */
4907 if (TREE_CODE (local->val) == CONSTRUCTOR)
4908 {
4909 oc_outer_state output_state;
4910
4911 output_state.bit_offset = next_offset % BITS_PER_UNIT;
4912 output_state.byte = local->byte;
4913 local->total_bytes
4914 += output_constructor (local->val, 0, 0, &output_state);
4915 local->byte = output_state.byte;
4916 return;
4917 }
4918
4919 /* Otherwise, we must split the element into pieces that fall within
4920 separate bytes, and combine each byte with previous or following
4921 bit-fields. */
4922 while (next_offset < end_offset)
4923 {
4924 int this_time;
4925 int shift;
4926 HOST_WIDE_INT value;
4927 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4928 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4929
4930 /* Advance from byte to byte
4931 within this element when necessary. */
4932 while (next_byte != local->total_bytes)
4933 {
4934 assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
4935 local->total_bytes++;
4936 local->byte = 0;
4937 }
4938
4939 /* Number of bits we can process at once
4940 (all part of the same byte). */
4941 this_time = MIN (end_offset - next_offset,
4942 BITS_PER_UNIT - next_bit);
4943 if (BYTES_BIG_ENDIAN)
4944 {
4945 /* On big-endian machine, take the most significant bits
4946 first (of the bits that are significant)
4947 and put them into bytes from the most significant end. */
4948 shift = end_offset - next_offset - this_time;
4949
4950 /* Don't try to take a bunch of bits that cross
4951 the word boundary in the INTEGER_CST. We can
4952 only select bits from the LOW or HIGH part
4953 not from both. */
4954 if (shift < HOST_BITS_PER_WIDE_INT
4955 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4956 {
4957 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4958 shift = HOST_BITS_PER_WIDE_INT;
4959 }
4960
4961 /* Now get the bits from the appropriate constant word. */
4962 if (shift < HOST_BITS_PER_WIDE_INT)
4963 value = TREE_INT_CST_LOW (local->val);
4964 else
4965 {
4966 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4967 value = TREE_INT_CST_HIGH (local->val);
4968 shift -= HOST_BITS_PER_WIDE_INT;
4969 }
4970
4971 /* Get the result. This works only when:
4972 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4973 local->byte |= (((value >> shift)
4974 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4975 << (BITS_PER_UNIT - this_time - next_bit));
4976 }
4977 else
4978 {
4979 /* On little-endian machines,
4980 take first the least significant bits of the value
4981 and pack them starting at the least significant
4982 bits of the bytes. */
4983 shift = next_offset - byte_relative_ebitpos;
4984
4985 /* Don't try to take a bunch of bits that cross
4986 the word boundary in the INTEGER_CST. We can
4987 only select bits from the LOW or HIGH part
4988 not from both. */
4989 if (shift < HOST_BITS_PER_WIDE_INT
4990 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4991 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4992
4993 /* Now get the bits from the appropriate constant word. */
4994 if (shift < HOST_BITS_PER_WIDE_INT)
4995 value = TREE_INT_CST_LOW (local->val);
4996 else
4997 {
4998 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4999 value = TREE_INT_CST_HIGH (local->val);
5000 shift -= HOST_BITS_PER_WIDE_INT;
5001 }
5002
5003 /* Get the result. This works only when:
5004 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5005 local->byte |= (((value >> shift)
5006 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5007 << next_bit);
5008 }
5009
5010 next_offset += this_time;
5011 local->byte_buffer_in_use = true;
5012 }
5013 }
5014
4666 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants). 5015 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4667 Generate at least SIZE bytes, padding if necessary. */ 5016 Generate at least SIZE bytes, padding if necessary. OUTER designates the
4668 5017 caller output state of relevance in recursive invocations. */
4669 static void 5018
5019 static unsigned HOST_WIDE_INT
4670 output_constructor (tree exp, unsigned HOST_WIDE_INT size, 5020 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
4671 unsigned int align) 5021 unsigned int align, oc_outer_state * outer)
4672 { 5022 {
4673 tree type = TREE_TYPE (exp);
4674 tree field = 0;
4675 tree min_index = 0;
4676 /* Number of bytes output or skipped so far.
4677 In other words, current position within the constructor. */
4678 HOST_WIDE_INT total_bytes = 0;
4679 /* Nonzero means BYTE contains part of a byte, to be output. */
4680 int byte_buffer_in_use = 0;
4681 int byte = 0;
4682 unsigned HOST_WIDE_INT cnt; 5023 unsigned HOST_WIDE_INT cnt;
4683 constructor_elt *ce; 5024 constructor_elt *ce;
4684 5025
5026 oc_local_state local;
5027
5028 /* Setup our local state to communicate with helpers. */
5029 local.exp = exp;
5030 local.size = size;
5031 local.align = align;
5032
5033 local.total_bytes = 0;
5034 local.byte_buffer_in_use = outer != NULL;
5035 local.byte = outer ? outer->byte : 0;
5036
5037 local.type = TREE_TYPE (exp);
5038
5039 local.last_relative_index = -1;
5040
5041 local.min_index = NULL_TREE;
5042 if (TREE_CODE (local.type) == ARRAY_TYPE
5043 && TYPE_DOMAIN (local.type) != NULL_TREE)
5044 local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
5045
4685 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT); 5046 gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
4686 5047
4687 if (TREE_CODE (type) == RECORD_TYPE) 5048 /* As CE goes through the elements of the constant, FIELD goes through the
4688 field = TYPE_FIELDS (type); 5049 structure fields if the constant is a structure. If the constant is a
4689 5050 union, we override this by getting the field from the TREE_LIST element.
4690 if (TREE_CODE (type) == ARRAY_TYPE
4691 && TYPE_DOMAIN (type) != 0)
4692 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4693
4694 /* As LINK goes through the elements of the constant,
4695 FIELD goes through the structure fields, if the constant is a structure.
4696 if the constant is a union, then we override this,
4697 by getting the field from the TREE_LIST element.
4698 But the constant could also be an array. Then FIELD is zero. 5051 But the constant could also be an array. Then FIELD is zero.
4699 5052
4700 There is always a maximum of one element in the chain LINK for unions 5053 There is always a maximum of one element in the chain LINK for unions
4701 (even if the initializer in a source program incorrectly contains 5054 (even if the initializer in a source program incorrectly contains
4702 more one). */ 5055 more one). */
5056
5057 local.field = NULL_TREE;
5058 if (TREE_CODE (local.type) == RECORD_TYPE)
5059 local.field = TYPE_FIELDS (local.type);
5060
4703 for (cnt = 0; 5061 for (cnt = 0;
4704 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce); 5062 VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce);
4705 cnt++, field = field ? TREE_CHAIN (field) : 0) 5063 cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0)
4706 { 5064 {
4707 tree val = ce->value; 5065 local.val = ce->value;
4708 tree index = 0; 5066 local.index = NULL_TREE;
4709 5067
4710 /* The element in a union constructor specifies the proper field 5068 /* The element in a union constructor specifies the proper field
4711 or index. */ 5069 or index. */
4712 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE 5070 if ((TREE_CODE (local.type) == RECORD_TYPE
4713 || TREE_CODE (type) == QUAL_UNION_TYPE) 5071 || TREE_CODE (local.type) == UNION_TYPE
4714 && ce->index != 0) 5072 || TREE_CODE (local.type) == QUAL_UNION_TYPE)
4715 field = ce->index; 5073 && ce->index != NULL_TREE)
4716 5074 local.field = ce->index;
4717 else if (TREE_CODE (type) == ARRAY_TYPE) 5075
4718 index = ce->index; 5076 else if (TREE_CODE (local.type) == ARRAY_TYPE)
5077 local.index = ce->index;
4719 5078
4720 #ifdef ASM_COMMENT_START 5079 #ifdef ASM_COMMENT_START
4721 if (field && flag_verbose_asm) 5080 if (local.field && flag_verbose_asm)
4722 fprintf (asm_out_file, "%s %s:\n", 5081 fprintf (asm_out_file, "%s %s:\n",
4723 ASM_COMMENT_START, 5082 ASM_COMMENT_START,
4724 DECL_NAME (field) 5083 DECL_NAME (local.field)
4725 ? IDENTIFIER_POINTER (DECL_NAME (field)) 5084 ? IDENTIFIER_POINTER (DECL_NAME (local.field))
4726 : "<anonymous>"); 5085 : "<anonymous>");
4727 #endif 5086 #endif
4728 5087
4729 /* Eliminate the marker that makes a cast not be an lvalue. */ 5088 /* Eliminate the marker that makes a cast not be an lvalue. */
4730 if (val != 0) 5089 if (local.val != NULL_TREE)
4731 STRIP_NOPS (val); 5090 STRIP_NOPS (local.val);
4732 5091
4733 if (index && TREE_CODE (index) == RANGE_EXPR) 5092 /* Output the current element, using the appropriate helper ... */
5093
5094 /* For an array slice not part of an outer bitfield. */
5095 if (!outer
5096 && local.index != NULL_TREE
5097 && TREE_CODE (local.index) == RANGE_EXPR)
5098 output_constructor_array_range (&local);
5099
5100 /* For a field that is neither a true bitfield nor part of an outer one,
5101 known to be at least byte aligned and multiple-of-bytes long. */
5102 else if (!outer
5103 && (local.field == NULL_TREE
5104 || !CONSTRUCTOR_BITFIELD_P (local.field)))
5105 output_constructor_regular_field (&local);
5106
5107 /* For a true bitfield or part of an outer one. */
5108 else
5109 output_constructor_bitfield (&local, outer);
5110 }
5111
5112 /* If we are not at toplevel, save the pending data for our caller.
5113 Otherwise output the pending data and padding zeros as needed. */
5114 if (outer)
5115 outer->byte = local.byte;
5116 else
5117 {
5118 if (local.byte_buffer_in_use)
4734 { 5119 {
4735 unsigned HOST_WIDE_INT fieldsize 5120 assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
4736 = int_size_in_bytes (TREE_TYPE (type)); 5121 local.total_bytes++;
4737 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4738 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4739 HOST_WIDE_INT index;
4740 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4741
4742 for (index = lo_index; index <= hi_index; index++)
4743 {
4744 /* Output the element's initial value. */
4745 if (val == 0)
4746 assemble_zeros (fieldsize);
4747 else
4748 output_constant (val, fieldsize, align2);
4749
4750 /* Count its size. */
4751 total_bytes += fieldsize;
4752 }
4753 } 5122 }
4754 else if (field == 0 || !DECL_BIT_FIELD (field)) 5123
5124 if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
4755 { 5125 {
4756 /* An element that is not a bit-field. */ 5126 assemble_zeros (local.size - local.total_bytes);
4757 5127 local.total_bytes = local.size;
4758 unsigned HOST_WIDE_INT fieldsize;
4759 /* Since this structure is static,
4760 we know the positions are constant. */
4761 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4762 unsigned int align2;
4763
4764 if (index != 0)
4765 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4766 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4767
4768 /* Output any buffered-up bit-fields preceding this element. */
4769 if (byte_buffer_in_use)
4770 {
4771 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4772 total_bytes++;
4773 byte_buffer_in_use = 0;
4774 }
4775
4776 /* Advance to offset of this element.
4777 Note no alignment needed in an array, since that is guaranteed
4778 if each element has the proper size. */
4779 if ((field != 0 || index != 0) && pos != total_bytes)
4780 {
4781 gcc_assert (pos >= total_bytes);
4782 assemble_zeros (pos - total_bytes);
4783 total_bytes = pos;
4784 }
4785
4786 /* Find the alignment of this element. */
4787 align2 = min_align (align, BITS_PER_UNIT * pos);
4788
4789 /* Determine size this element should occupy. */
4790 if (field)
4791 {
4792 fieldsize = 0;
4793
4794 /* If this is an array with an unspecified upper bound,
4795 the initializer determines the size. */
4796 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4797 but we cannot do this until the deprecated support for
4798 initializing zero-length array members is removed. */
4799 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4800 && TYPE_DOMAIN (TREE_TYPE (field))
4801 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4802 {
4803 fieldsize = array_size_for_constructor (val);
4804 /* Given a non-empty initialization, this field had
4805 better be last. */
4806 gcc_assert (!fieldsize || !TREE_CHAIN (field));
4807 }
4808 else if (DECL_SIZE_UNIT (field))
4809 {
4810 /* ??? This can't be right. If the decl size overflows
4811 a host integer we will silently emit no data. */
4812 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4813 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4814 }
4815 }
4816 else
4817 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4818
4819 /* Output the element's initial value. */
4820 if (val == 0)
4821 assemble_zeros (fieldsize);
4822 else
4823 output_constant (val, fieldsize, align2);
4824
4825 /* Count its size. */
4826 total_bytes += fieldsize;
4827 } 5128 }
4828 else if (val != 0 && TREE_CODE (val) != INTEGER_CST) 5129 }
4829 error ("invalid initial value for member %qs", 5130
4830 IDENTIFIER_POINTER (DECL_NAME (field))); 5131 return local.total_bytes;
4831 else
4832 {
4833 /* Element that is a bit-field. */
4834
4835 HOST_WIDE_INT next_offset = int_bit_position (field);
4836 HOST_WIDE_INT end_offset
4837 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4838
4839 if (val == 0)
4840 val = integer_zero_node;
4841
4842 /* If this field does not start in this (or, next) byte,
4843 skip some bytes. */
4844 if (next_offset / BITS_PER_UNIT != total_bytes)
4845 {
4846 /* Output remnant of any bit field in previous bytes. */
4847 if (byte_buffer_in_use)
4848 {
4849 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4850 total_bytes++;
4851 byte_buffer_in_use = 0;
4852 }
4853
4854 /* If still not at proper byte, advance to there. */
4855 if (next_offset / BITS_PER_UNIT != total_bytes)
4856 {
4857 gcc_assert (next_offset / BITS_PER_UNIT >= total_bytes);
4858 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4859 total_bytes = next_offset / BITS_PER_UNIT;
4860 }
4861 }
4862
4863 if (! byte_buffer_in_use)
4864 byte = 0;
4865
4866 /* We must split the element into pieces that fall within
4867 separate bytes, and combine each byte with previous or
4868 following bit-fields. */
4869
4870 /* next_offset is the offset n fbits from the beginning of
4871 the structure to the next bit of this element to be processed.
4872 end_offset is the offset of the first bit past the end of
4873 this element. */
4874 while (next_offset < end_offset)
4875 {
4876 int this_time;
4877 int shift;
4878 HOST_WIDE_INT value;
4879 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4880 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4881
4882 /* Advance from byte to byte
4883 within this element when necessary. */
4884 while (next_byte != total_bytes)
4885 {
4886 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4887 total_bytes++;
4888 byte = 0;
4889 }
4890
4891 /* Number of bits we can process at once
4892 (all part of the same byte). */
4893 this_time = MIN (end_offset - next_offset,
4894 BITS_PER_UNIT - next_bit);
4895 if (BYTES_BIG_ENDIAN)
4896 {
4897 /* On big-endian machine, take the most significant bits
4898 first (of the bits that are significant)
4899 and put them into bytes from the most significant end. */
4900 shift = end_offset - next_offset - this_time;
4901
4902 /* Don't try to take a bunch of bits that cross
4903 the word boundary in the INTEGER_CST. We can
4904 only select bits from the LOW or HIGH part
4905 not from both. */
4906 if (shift < HOST_BITS_PER_WIDE_INT
4907 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4908 {
4909 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4910 shift = HOST_BITS_PER_WIDE_INT;
4911 }
4912
4913 /* Now get the bits from the appropriate constant word. */
4914 if (shift < HOST_BITS_PER_WIDE_INT)
4915 value = TREE_INT_CST_LOW (val);
4916 else
4917 {
4918 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4919 value = TREE_INT_CST_HIGH (val);
4920 shift -= HOST_BITS_PER_WIDE_INT;
4921 }
4922
4923 /* Get the result. This works only when:
4924 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4925 byte |= (((value >> shift)
4926 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4927 << (BITS_PER_UNIT - this_time - next_bit));
4928 }
4929 else
4930 {
4931 /* On little-endian machines,
4932 take first the least significant bits of the value
4933 and pack them starting at the least significant
4934 bits of the bytes. */
4935 shift = next_offset - int_bit_position (field);
4936
4937 /* Don't try to take a bunch of bits that cross
4938 the word boundary in the INTEGER_CST. We can
4939 only select bits from the LOW or HIGH part
4940 not from both. */
4941 if (shift < HOST_BITS_PER_WIDE_INT
4942 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4943 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4944
4945 /* Now get the bits from the appropriate constant word. */
4946 if (shift < HOST_BITS_PER_WIDE_INT)
4947 value = TREE_INT_CST_LOW (val);
4948 else
4949 {
4950 gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT);
4951 value = TREE_INT_CST_HIGH (val);
4952 shift -= HOST_BITS_PER_WIDE_INT;
4953 }
4954
4955 /* Get the result. This works only when:
4956 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4957 byte |= (((value >> shift)
4958 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4959 << next_bit);
4960 }
4961
4962 next_offset += this_time;
4963 byte_buffer_in_use = 1;
4964 }
4965 }
4966 }
4967
4968 if (byte_buffer_in_use)
4969 {
4970 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4971 total_bytes++;
4972 }
4973
4974 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4975 assemble_zeros (size - total_bytes);
4976 } 5132 }
4977 5133
4978 /* Mark DECL as weak. */ 5134 /* Mark DECL as weak. */
4979 5135
4980 static void 5136 static void
5069 error ("weak declaration of %q+D must precede definition", decl); 5225 error ("weak declaration of %q+D must precede definition", decl);
5070 else if (!SUPPORTS_WEAK) 5226 else if (!SUPPORTS_WEAK)
5071 warning (0, "weak declaration of %q+D not supported", decl); 5227 warning (0, "weak declaration of %q+D not supported", decl);
5072 5228
5073 mark_weak (decl); 5229 mark_weak (decl);
5074 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5075 DECL_ATTRIBUTES (decl)
5076 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5077 } 5230 }
5078 5231
5079 static void 5232 static void
5080 weak_finish_1 (tree decl) 5233 weak_finish_1 (tree decl)
5081 { 5234 {
5141 # else 5294 # else
5142 tree decl = find_decl_and_mark_needed (alias_decl, target); 5295 tree decl = find_decl_and_mark_needed (alias_decl, target);
5143 5296
5144 if (! decl) 5297 if (! decl)
5145 { 5298 {
5146 decl = build_decl (TREE_CODE (alias_decl), target, 5299 decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
5300 TREE_CODE (alias_decl), target,
5147 TREE_TYPE (alias_decl)); 5301 TREE_TYPE (alias_decl));
5148 5302
5149 DECL_EXTERNAL (decl) = 1; 5303 DECL_EXTERNAL (decl) = 1;
5150 TREE_PUBLIC (decl) = 1; 5304 TREE_PUBLIC (decl) = 1;
5151 DECL_ARTIFICIAL (decl) = 1; 5305 DECL_ARTIFICIAL (decl) = 1;
5237 #endif 5391 #endif
5238 5392
5239 targetm.asm_out.globalize_decl_name (asm_out_file, decl); 5393 targetm.asm_out.globalize_decl_name (asm_out_file, decl);
5240 } 5394 }
5241 5395
5242 /* We have to be able to tell cgraph about the needed-ness of the target 5396 VEC(alias_pair,gc) *alias_pairs;
5243 of an alias. This requires that the decl have been defined. Aliases
5244 that precede their definition have to be queued for later processing. */
5245
5246 typedef struct alias_pair GTY(())
5247 {
5248 tree decl;
5249 tree target;
5250 } alias_pair;
5251
5252 /* Define gc'd vector type. */
5253 DEF_VEC_O(alias_pair);
5254 DEF_VEC_ALLOC_O(alias_pair,gc);
5255
5256 static GTY(()) VEC(alias_pair,gc) *alias_pairs;
5257 5397
5258 /* Given an assembly name, find the decl it is associated with. At the 5398 /* Given an assembly name, find the decl it is associated with. At the
5259 same time, mark it needed for cgraph. */ 5399 same time, mark it needed for cgraph. */
5260 5400
5261 static tree 5401 static tree
5277 fnode = cgraph_node_for_asm (target); 5417 fnode = cgraph_node_for_asm (target);
5278 } 5418 }
5279 5419
5280 if (fnode) 5420 if (fnode)
5281 { 5421 {
5282 /* We can't mark function nodes as used after cgraph global info 5422 cgraph_mark_needed_node (fnode);
5283 is finished. This wouldn't generally be necessary, but C++
5284 virtual table thunks are introduced late in the game and
5285 might seem like they need marking, although in fact they
5286 don't. */
5287 if (! cgraph_global_info_ready)
5288 cgraph_mark_needed_node (fnode);
5289 return fnode->decl; 5423 return fnode->decl;
5290 } 5424 }
5291 else if (vnode) 5425 else if (vnode)
5292 { 5426 {
5293 varpool_mark_needed_node (vnode); 5427 varpool_mark_needed_node (vnode);
5330 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 5464 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
5331 IDENTIFIER_POINTER (target)); 5465 IDENTIFIER_POINTER (target));
5332 #else 5466 #else
5333 if (!SUPPORTS_WEAK) 5467 if (!SUPPORTS_WEAK)
5334 { 5468 {
5335 error ("%Jweakref is not supported in this configuration", decl); 5469 error_at (DECL_SOURCE_LOCATION (decl),
5470 "weakref is not supported in this configuration");
5336 return; 5471 return;
5337 } 5472 }
5338 #endif 5473 #endif
5339 return; 5474 return;
5340 } 5475 }
5394 } 5529 }
5395 } 5530 }
5396 #endif 5531 #endif
5397 } 5532 }
5398 5533
5534
5535 /* Remove the alias pairing for functions that are no longer in the call
5536 graph. */
5537
5538 void
5539 remove_unreachable_alias_pairs (void)
5540 {
5541 unsigned i;
5542 alias_pair *p;
5543
5544 if (alias_pairs == NULL)
5545 return;
5546
5547 for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); )
5548 {
5549 if (!DECL_EXTERNAL (p->decl))
5550 {
5551 struct cgraph_node *fnode = NULL;
5552 struct varpool_node *vnode = NULL;
5553 fnode = cgraph_node_for_asm (p->target);
5554 vnode = (fnode == NULL) ? varpool_node_for_asm (p->target) : NULL;
5555 if (fnode == NULL && vnode == NULL)
5556 {
5557 VEC_unordered_remove (alias_pair, alias_pairs, i);
5558 continue;
5559 }
5560 }
5561
5562 i++;
5563 }
5564 }
5565
5566
5399 /* First pass of completing pending aliases. Make sure that cgraph knows 5567 /* First pass of completing pending aliases. Make sure that cgraph knows
5400 which symbols will be required. */ 5568 which symbols will be required. */
5401 5569
5402 void 5570 void
5403 finish_aliases_1 (void) 5571 finish_aliases_1 (void)
5411 5579
5412 target_decl = find_decl_and_mark_needed (p->decl, p->target); 5580 target_decl = find_decl_and_mark_needed (p->decl, p->target);
5413 if (target_decl == NULL) 5581 if (target_decl == NULL)
5414 { 5582 {
5415 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl))) 5583 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5416 error ("%q+D aliased to undefined symbol %qs", 5584 error ("%q+D aliased to undefined symbol %qE",
5417 p->decl, IDENTIFIER_POINTER (p->target)); 5585 p->decl, p->target);
5418 } 5586 }
5419 else if (DECL_EXTERNAL (target_decl) 5587 else if (DECL_EXTERNAL (target_decl)
5588 /* We use local aliases for C++ thunks to force the tailcall
5589 to bind locally. Of course this is a hack - to keep it
5590 working do the following (which is not strictly correct). */
5591 && (! TREE_CODE (target_decl) == FUNCTION_DECL
5592 || ! DECL_VIRTUAL_P (target_decl))
5420 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl))) 5593 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl)))
5421 error ("%q+D aliased to external symbol %qs", 5594 error ("%q+D aliased to external symbol %qE",
5422 p->decl, IDENTIFIER_POINTER (p->target)); 5595 p->decl, p->target);
5423 } 5596 }
5424 } 5597 }
5425 5598
5426 /* Second pass of completing pending aliases. Emit the actual assembly. 5599 /* Second pass of completing pending aliases. Emit the actual assembly.
5427 This happens at the end of compilation and thus it is assured that the 5600 This happens at the end of compilation and thus it is assured that the
5470 } 5643 }
5471 else 5644 else
5472 { 5645 {
5473 #if !defined (ASM_OUTPUT_DEF) 5646 #if !defined (ASM_OUTPUT_DEF)
5474 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL) 5647 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5475 error ("%Jalias definitions not supported in this configuration", decl); 5648 error_at (DECL_SOURCE_LOCATION (decl),
5649 "alias definitions not supported in this configuration");
5476 return; 5650 return;
5477 # else 5651 # else
5478 if (!DECL_WEAK (decl)) 5652 if (!DECL_WEAK (decl))
5479 { 5653 {
5480 error ("%Jonly weak aliases are supported in this configuration", decl); 5654 error_at (DECL_SOURCE_LOCATION (decl),
5655 "only weak aliases are supported in this configuration");
5481 return; 5656 return;
5482 } 5657 }
5483 # endif 5658 # endif
5484 #endif 5659 #endif
5485 } 5660 }
5573 5748
5574 /* Set up DECL as a public symbol that can be defined in multiple 5749 /* Set up DECL as a public symbol that can be defined in multiple
5575 translation units without generating a linker error. */ 5750 translation units without generating a linker error. */
5576 5751
5577 void 5752 void
5578 make_decl_one_only (tree decl) 5753 make_decl_one_only (tree decl, tree comdat_group)
5579 { 5754 {
5580 gcc_assert (TREE_CODE (decl) == VAR_DECL 5755 gcc_assert (TREE_CODE (decl) == VAR_DECL
5581 || TREE_CODE (decl) == FUNCTION_DECL); 5756 || TREE_CODE (decl) == FUNCTION_DECL);
5582 5757
5583 TREE_PUBLIC (decl) = 1; 5758 TREE_PUBLIC (decl) = 1;
5585 if (SUPPORTS_ONE_ONLY) 5760 if (SUPPORTS_ONE_ONLY)
5586 { 5761 {
5587 #ifdef MAKE_DECL_ONE_ONLY 5762 #ifdef MAKE_DECL_ONE_ONLY
5588 MAKE_DECL_ONE_ONLY (decl); 5763 MAKE_DECL_ONE_ONLY (decl);
5589 #endif 5764 #endif
5590 DECL_ONE_ONLY (decl) = 1; 5765 DECL_COMDAT_GROUP (decl) = comdat_group;
5591 } 5766 }
5592 else if (TREE_CODE (decl) == VAR_DECL 5767 else if (TREE_CODE (decl) == VAR_DECL
5593 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)) 5768 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5594 DECL_COMMON (decl) = 1; 5769 DECL_COMMON (decl) = 1;
5595 else 5770 else
5845 fprintf (asm_out_file, format, type); 6020 fprintf (asm_out_file, format, type);
5846 6021
5847 if (flags & SECTION_ENTSIZE) 6022 if (flags & SECTION_ENTSIZE)
5848 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE); 6023 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
5849 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) 6024 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5850 fprintf (asm_out_file, ",%s,comdat", 6025 {
5851 lang_hooks.decls.comdat_group (decl)); 6026 if (TREE_CODE (decl) == IDENTIFIER_NODE)
6027 fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
6028 else
6029 fprintf (asm_out_file, ",%s,comdat",
6030 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
6031 }
5852 } 6032 }
5853 6033
5854 putc ('\n', asm_out_file); 6034 putc ('\n', asm_out_file);
5855 } 6035 }
5856 6036
6163 name = targetm.strip_name_encoding (name); 6343 name = targetm.strip_name_encoding (name);
6164 6344
6165 /* If we're using one_only, then there needs to be a .gnu.linkonce 6345 /* If we're using one_only, then there needs to be a .gnu.linkonce
6166 prefix to the section name. */ 6346 prefix to the section name. */
6167 linkonce = one_only ? ".gnu.linkonce" : ""; 6347 linkonce = one_only ? ".gnu.linkonce" : "";
6168 6348
6169 string = ACONCAT ((linkonce, prefix, ".", name, NULL)); 6349 string = ACONCAT ((linkonce, prefix, ".", name, NULL));
6170 6350
6171 DECL_SECTION_NAME (decl) = build_string (strlen (string), string); 6351 DECL_SECTION_NAME (decl) = build_string (strlen (string), string);
6172 } 6352 }
6173 6353
6263 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO; 6443 flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
6264 if (TREE_CODE (decl) == FUNCTION_DECL) 6444 if (TREE_CODE (decl) == FUNCTION_DECL)
6265 flags |= SYMBOL_FLAG_FUNCTION; 6445 flags |= SYMBOL_FLAG_FUNCTION;
6266 if (targetm.binds_local_p (decl)) 6446 if (targetm.binds_local_p (decl))
6267 flags |= SYMBOL_FLAG_LOCAL; 6447 flags |= SYMBOL_FLAG_LOCAL;
6268 if (targetm.have_tls && TREE_CODE (decl) == VAR_DECL 6448 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)
6269 && DECL_THREAD_LOCAL_P (decl)) 6449 && DECL_TLS_MODEL (decl) != TLS_MODEL_EMULATED)
6270 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT; 6450 flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
6271 else if (targetm.in_small_data_p (decl)) 6451 else if (targetm.in_small_data_p (decl))
6272 flags |= SYMBOL_FLAG_SMALL; 6452 flags |= SYMBOL_FLAG_SMALL;
6273 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without 6453 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6274 being PUBLIC, the thing *must* be defined in this translation unit. 6454 being PUBLIC, the thing *must* be defined in this translation unit.
6398 local_p = true; 6578 local_p = true;
6399 6579
6400 return local_p; 6580 return local_p;
6401 } 6581 }
6402 6582
6403 /* Determine whether or not a pointer mode is valid. Assume defaults
6404 of ptr_mode or Pmode - can be overridden. */
6405 bool
6406 default_valid_pointer_mode (enum machine_mode mode)
6407 {
6408 return (mode == ptr_mode || mode == Pmode);
6409 }
6410
6411 /* Default function to output code that will globalize a label. A 6583 /* Default function to output code that will globalize a label. A
6412 target must define GLOBAL_ASM_OP or provide its own function to 6584 target must define GLOBAL_ASM_OP or provide its own function to
6413 globalize a label. */ 6585 globalize a label. */
6414 #ifdef GLOBAL_ASM_OP 6586 #ifdef GLOBAL_ASM_OP
6415 void 6587 void