]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/gcc-interface/misc.c
PR ada/37139
[thirdparty/gcc.git] / gcc / ada / gcc-interface / misc.c
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * M I S C *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2016, Free Software Foundation, Inc. *
10 * *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 3, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING3. If not see *
19 * <http://www.gnu.org/licenses/>. *
20 * *
21 * GNAT was originally developed by the GNAT team at New York University. *
22 * Extensive contributions were provided by Ada Core Technologies Inc. *
23 * *
24 ****************************************************************************/
25
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "target.h"
30 #include "tree.h"
31 #include "diagnostic.h"
32 #include "opts.h"
33 #include "alias.h"
34 #include "fold-const.h"
35 #include "stor-layout.h"
36 #include "print-tree.h"
37 #include "toplev.h"
38 #include "langhooks.h"
39 #include "langhooks-def.h"
40 #include "plugin.h"
41 #include "calls.h" /* For pass_by_reference. */
42 #include "dwarf2out.h"
43
44 #include "ada.h"
45 #include "adadecode.h"
46 #include "types.h"
47 #include "atree.h"
48 #include "namet.h"
49 #include "nlists.h"
50 #include "uintp.h"
51 #include "fe.h"
52 #include "sinfo.h"
53 #include "einfo.h"
54 #include "ada-tree.h"
55 #include "gigi.h"
56
57 /* This symbol needs to be defined for the front-end. */
58 void *callgraph_info_file = NULL;
59
60 /* Command-line argc and argv. These variables are global since they are
61 imported in back_end.adb. */
62 unsigned int save_argc;
63 const char **save_argv;
64
65 /* GNAT argc and argv generated by the binder for all Ada programs. */
66 extern int gnat_argc;
67 extern const char **gnat_argv;
68
69 /* Ada code requires variables for these settings rather than elements
70 of the global_options structure because they are imported. */
71 #undef gnat_encodings
72 enum dwarf_gnat_encodings gnat_encodings = DWARF_GNAT_ENCODINGS_DEFAULT;
73
74 #undef optimize
75 int optimize;
76
77 #undef optimize_size
78 int optimize_size;
79
80 #undef flag_compare_debug
81 int flag_compare_debug;
82
83 #undef flag_short_enums
84 int flag_short_enums;
85
86 #undef flag_stack_check
87 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
88
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92
93 /* Declare functions we use as part of startup. */
94 extern void __gnat_initialize (void *);
95 extern void __gnat_install_SEH_handler (void *);
96 extern void adainit (void);
97 extern void _ada_gnat1drv (void);
98
99 #ifdef __cplusplus
100 }
101 #endif
102
103 /* The parser for the language. For us, we process the GNAT tree. */
104
105 static void
106 gnat_parse_file (void)
107 {
108 int seh[2];
109
110 /* Call the target specific initializations. */
111 __gnat_initialize (NULL);
112
113 /* ??? Call the SEH initialization routine. This is to workaround
114 a bootstrap path problem. The call below should be removed at some
115 point and the SEH pointer passed to __gnat_initialize above. */
116 __gnat_install_SEH_handler ((void *)seh);
117
118 /* Call the front-end elaboration procedures. */
119 adainit ();
120
121 /* Call the front end. */
122 _ada_gnat1drv ();
123
124 /* Write the global declarations. */
125 gnat_write_global_declarations ();
126 }
127
128 /* Return language mask for option processing. */
129
130 static unsigned int
131 gnat_option_lang_mask (void)
132 {
133 return CL_Ada;
134 }
135
136 /* Decode all the language specific options that cannot be decoded by GCC.
137 The option decoding phase of GCC calls this routine on the flags that
138 are marked as Ada-specific. Return true on success or false on failure. */
139
140 static bool
141 gnat_handle_option (size_t scode, const char *arg, int value, int kind,
142 location_t loc, const struct cl_option_handlers *handlers)
143 {
144 enum opt_code code = (enum opt_code) scode;
145
146 switch (code)
147 {
148 case OPT_Wall:
149 handle_generated_option (&global_options, &global_options_set,
150 OPT_Wunused, NULL, value,
151 gnat_option_lang_mask (), kind, loc,
152 handlers, global_dc);
153 warn_uninitialized = value;
154 warn_maybe_uninitialized = value;
155 break;
156
157 case OPT_gant:
158 warning (0, "%<-gnat%> misspelled as %<-gant%>");
159
160 /* ... fall through ... */
161
162 case OPT_gnat:
163 case OPT_gnatO:
164 case OPT_fRTS_:
165 case OPT_I:
166 case OPT_nostdinc:
167 case OPT_nostdlib:
168 /* These are handled by the front-end. */
169 break;
170
171 case OPT_fshort_enums:
172 case OPT_fsigned_char:
173 /* These are handled by the middle-end. */
174 break;
175
176 case OPT_fbuiltin_printf:
177 /* This is ignored in Ada but needs to be accepted so it can be
178 defaulted. */
179 break;
180
181 default:
182 gcc_unreachable ();
183 }
184
185 Ada_handle_option_auto (&global_options, &global_options_set,
186 scode, arg, value,
187 gnat_option_lang_mask (), kind, loc,
188 handlers, global_dc);
189 return true;
190 }
191
192 /* Initialize options structure OPTS. */
193
194 static void
195 gnat_init_options_struct (struct gcc_options *opts)
196 {
197 /* Uninitialized really means uninitialized in Ada. */
198 opts->x_flag_zero_initialized_in_bss = 0;
199
200 /* We don't care about errno in Ada and it causes __builtin_sqrt to
201 call the libm function rather than do it inline. */
202 opts->x_flag_errno_math = 0;
203 opts->frontend_set_flag_errno_math = true;
204 }
205
206 /* Initialize for option processing. */
207
208 static void
209 gnat_init_options (unsigned int decoded_options_count,
210 struct cl_decoded_option *decoded_options)
211 {
212 /* Reconstruct an argv array for use of back_end.adb.
213
214 ??? back_end.adb should not rely on this; instead, it should work with
215 decoded options without such reparsing, to ensure consistency in how
216 options are decoded. */
217 save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1);
218 save_argc = 0;
219 for (unsigned int i = 0; i < decoded_options_count; i++)
220 {
221 size_t num_elements = decoded_options[i].canonical_option_num_elements;
222
223 if (decoded_options[i].errors
224 || decoded_options[i].opt_index == OPT_SPECIAL_unknown
225 || num_elements == 0)
226 continue;
227
228 /* Deal with -I- specially since it must be a single switch. */
229 if (decoded_options[i].opt_index == OPT_I
230 && num_elements == 2
231 && decoded_options[i].canonical_option[1][0] == '-'
232 && decoded_options[i].canonical_option[1][1] == '\0')
233 save_argv[save_argc++] = "-I-";
234 else
235 {
236 gcc_assert (num_elements >= 1 && num_elements <= 2);
237 save_argv[save_argc++] = decoded_options[i].canonical_option[0];
238 if (num_elements >= 2)
239 save_argv[save_argc++] = decoded_options[i].canonical_option[1];
240 }
241 }
242 save_argv[save_argc] = NULL;
243
244 /* Pass just the name of the command through the regular channel. */
245 gnat_argv = (const char **) xmalloc (sizeof (char *));
246 gnat_argv[0] = xstrdup (save_argv[0]);
247 gnat_argc = 1;
248 }
249
250 /* Settings adjustments after switches processing by the back-end.
251 Note that the front-end switches processing (Scan_Compiler_Arguments)
252 has not been done yet at this point! */
253
254 static bool
255 gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
256 {
257 /* Excess precision other than "fast" requires front-end support. */
258 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
259 sorry ("-fexcess-precision=standard for Ada");
260 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
261
262 /* No psABI change warnings for Ada. */
263 warn_psabi = 0;
264
265 /* No caret by default for Ada. */
266 if (!global_options_set.x_flag_diagnostics_show_caret)
267 global_dc->show_caret = false;
268
269 /* Set strict overflow by default for Ada. */
270 if (!global_options_set.x_flag_strict_overflow)
271 global_options.x_flag_strict_overflow = true;
272
273 /* Warn only if STABS is not the default: we don't want to emit a warning if
274 the user did not use a -gstabs option. */
275 if (PREFERRED_DEBUGGING_TYPE != DBX_DEBUG && write_symbols == DBX_DEBUG)
276 warning (0, "STABS debugging information for Ada is obsolete and not "
277 "supported anymore");
278
279 /* Copy global settings to local versions. */
280 gnat_encodings = global_options.x_gnat_encodings;
281 optimize = global_options.x_optimize;
282 optimize_size = global_options.x_optimize_size;
283 flag_compare_debug = global_options.x_flag_compare_debug;
284 flag_stack_check = global_options.x_flag_stack_check;
285 flag_short_enums = global_options.x_flag_short_enums;
286
287 /* Unfortunately the post_options hook is called before the value of
288 flag_short_enums is autodetected, if need be. Mimic the process
289 for our private flag_short_enums. */
290 if (flag_short_enums == 2)
291 flag_short_enums = targetm.default_short_enums ();
292
293 return false;
294 }
295
296 /* Here is the function to handle the compiler error processing in GCC. */
297
298 static void
299 internal_error_function (diagnostic_context *context, const char *msgid,
300 va_list *ap)
301 {
302 text_info tinfo;
303 char *buffer, *p, *loc;
304 String_Template temp, temp_loc;
305 String_Pointer sp, sp_loc;
306 expanded_location xloc;
307
308 /* Warn if plugins present. */
309 warn_if_plugins ();
310
311 /* Reset the pretty-printer. */
312 pp_clear_output_area (context->printer);
313
314 /* Format the message into the pretty-printer. */
315 tinfo.format_spec = msgid;
316 tinfo.args_ptr = ap;
317 tinfo.err_no = errno;
318 pp_format_verbatim (context->printer, &tinfo);
319
320 /* Extract a (writable) pointer to the formatted text. */
321 buffer = xstrdup (pp_formatted_text (context->printer));
322
323 /* Go up to the first newline. */
324 for (p = buffer; *p; p++)
325 if (*p == '\n')
326 {
327 *p = '\0';
328 break;
329 }
330
331 temp.Low_Bound = 1;
332 temp.High_Bound = p - buffer;
333 sp.Bounds = &temp;
334 sp.Array = buffer;
335
336 xloc = expand_location (input_location);
337 if (context->show_column && xloc.column != 0)
338 loc = xasprintf ("%s:%d:%d", xloc.file, xloc.line, xloc.column);
339 else
340 loc = xasprintf ("%s:%d", xloc.file, xloc.line);
341 temp_loc.Low_Bound = 1;
342 temp_loc.High_Bound = strlen (loc);
343 sp_loc.Bounds = &temp_loc;
344 sp_loc.Array = loc;
345
346 Current_Error_Node = error_gnat_node;
347 Compiler_Abort (sp, sp_loc, true);
348 }
349
350 /* Perform all the initialization steps that are language-specific. */
351
352 static bool
353 gnat_init (void)
354 {
355 /* Do little here, most of the standard declarations are set up after the
356 front-end has been run. Use the same `char' as C for Interfaces.C. */
357 build_common_tree_nodes (flag_signed_char);
358
359 /* In Ada, we use an unsigned 8-bit type for the default boolean type. */
360 boolean_type_node = make_unsigned_type (8);
361 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
362 SET_TYPE_RM_MAX_VALUE (boolean_type_node,
363 build_int_cst (boolean_type_node, 1));
364 SET_TYPE_RM_SIZE (boolean_type_node, bitsize_int (1));
365 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
366 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
367
368 sbitsize_one_node = sbitsize_int (1);
369 sbitsize_unit_node = sbitsize_int (BITS_PER_UNIT);
370
371 /* Register our internal error function. */
372 global_dc->internal_error = &internal_error_function;
373
374 return true;
375 }
376
377 /* Initialize the GCC support for exception handling. */
378
379 void
380 gnat_init_gcc_eh (void)
381 {
382 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
383 though. This could for instance lead to the emission of tables with
384 references to symbols (such as the Ada eh personality routine) within
385 libraries we won't link against. */
386 if (No_Exception_Handlers_Set ())
387 return;
388
389 /* Tell GCC we are handling cleanup actions through exception propagation.
390 This opens possibilities that we don't take advantage of yet, but is
391 nonetheless necessary to ensure that fixup code gets assigned to the
392 right exception regions. */
393 using_eh_for_cleanups ();
394
395 /* Turn on -fexceptions, -fnon-call-exceptions and -fdelete-dead-exceptions.
396 The first one triggers the generation of the necessary exception tables.
397 The second one is useful for two reasons: 1/ we map some asynchronous
398 signals like SEGV to exceptions, so we need to ensure that the insns
399 which can lead to such signals are correctly attached to the exception
400 region they pertain to, 2/ some calls to pure subprograms are handled as
401 libcall blocks and then marked as "cannot trap" if the flag is not set
402 (see emit_libcall_block). We should not let this be since it is possible
403 for such calls to actually raise in Ada.
404 The third one is an optimization that makes it possible to delete dead
405 instructions that may throw exceptions, most notably loads and stores,
406 as permitted in Ada. */
407 flag_exceptions = 1;
408 flag_non_call_exceptions = 1;
409 flag_delete_dead_exceptions = 1;
410
411 init_eh ();
412 }
413
414 /* Initialize the GCC support for floating-point operations. */
415
416 void
417 gnat_init_gcc_fp (void)
418 {
419 /* Disable FP optimizations that ignore the signedness of zero if
420 S'Signed_Zeros is true, but don't override the user if not. */
421 if (Signed_Zeros_On_Target)
422 flag_signed_zeros = 1;
423 else if (!global_options_set.x_flag_signed_zeros)
424 flag_signed_zeros = 0;
425
426 /* Assume that FP operations can trap if S'Machine_Overflow is true,
427 but don't override the user if not. */
428 if (Machine_Overflows_On_Target)
429 flag_trapping_math = 1;
430 else if (!global_options_set.x_flag_trapping_math)
431 flag_trapping_math = 0;
432 }
433
434 /* Print language-specific items in declaration NODE. */
435
436 static void
437 gnat_print_decl (FILE *file, tree node, int indent)
438 {
439 switch (TREE_CODE (node))
440 {
441 case CONST_DECL:
442 print_node (file, "corresponding var",
443 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
444 break;
445
446 case FIELD_DECL:
447 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
448 indent + 4);
449 break;
450
451 case VAR_DECL:
452 if (DECL_LOOP_PARM_P (node))
453 print_node (file, "induction var", DECL_INDUCTION_VAR (node),
454 indent + 4);
455 else
456 print_node (file, "renamed object", DECL_RENAMED_OBJECT (node),
457 indent + 4);
458 break;
459
460 default:
461 break;
462 }
463 }
464
465 /* Print language-specific items in type NODE. */
466
467 static void
468 gnat_print_type (FILE *file, tree node, int indent)
469 {
470 switch (TREE_CODE (node))
471 {
472 case FUNCTION_TYPE:
473 print_node (file, "ci/co list", TYPE_CI_CO_LIST (node), indent + 4);
474 break;
475
476 case INTEGER_TYPE:
477 if (TYPE_MODULAR_P (node))
478 print_node_brief (file, "modulus", TYPE_MODULUS (node), indent + 4);
479 else if (TYPE_FIXED_POINT_P (node))
480 print_node (file, "scale factor", TYPE_SCALE_FACTOR (node),
481 indent + 4);
482 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
483 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
484 indent + 4);
485 else
486 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
487
488 /* ... fall through ... */
489
490 case ENUMERAL_TYPE:
491 case BOOLEAN_TYPE:
492 print_node_brief (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
493
494 /* ... fall through ... */
495
496 case REAL_TYPE:
497 print_node_brief (file, "RM min", TYPE_RM_MIN_VALUE (node), indent + 4);
498 print_node_brief (file, "RM max", TYPE_RM_MAX_VALUE (node), indent + 4);
499 break;
500
501 case ARRAY_TYPE:
502 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
503 break;
504
505 case VECTOR_TYPE:
506 print_node (file,"representative array",
507 TYPE_REPRESENTATIVE_ARRAY (node), indent + 4);
508 break;
509
510 case RECORD_TYPE:
511 if (TYPE_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
512 print_node (file, "unconstrained array",
513 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
514 else
515 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
516 break;
517
518 case UNION_TYPE:
519 case QUAL_UNION_TYPE:
520 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
521 break;
522
523 default:
524 break;
525 }
526
527 if (TYPE_CAN_HAVE_DEBUG_TYPE_P (node) && TYPE_DEBUG_TYPE (node))
528 print_node_brief (file, "debug type", TYPE_DEBUG_TYPE (node), indent + 4);
529
530 if (TYPE_IMPL_PACKED_ARRAY_P (node) && TYPE_ORIGINAL_PACKED_ARRAY (node))
531 print_node_brief (file, "original packed array",
532 TYPE_ORIGINAL_PACKED_ARRAY (node), indent + 4);
533 }
534
535 /* Return the name to be printed for DECL. */
536
537 static const char *
538 gnat_printable_name (tree decl, int verbosity)
539 {
540 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
541 char *ada_name = (char *) ggc_alloc_atomic (strlen (coded_name) * 2 + 60);
542
543 __gnat_decode (coded_name, ada_name, 0);
544
545 if (verbosity == 2 && !DECL_IS_BUILTIN (decl))
546 {
547 Set_Identifier_Casing (ada_name, DECL_SOURCE_FILE (decl));
548 return ggc_strdup (Name_Buffer);
549 }
550
551 return ada_name;
552 }
553
554 /* Return the name to be used in DWARF debug info for DECL. */
555
556 static const char *
557 gnat_dwarf_name (tree decl, int verbosity ATTRIBUTE_UNUSED)
558 {
559 gcc_assert (DECL_P (decl));
560 return (const char *) IDENTIFIER_POINTER (DECL_NAME (decl));
561 }
562
563 /* Return the descriptive type associated with TYPE, if any. */
564
565 static tree
566 gnat_descriptive_type (const_tree type)
567 {
568 if (TYPE_STUB_DECL (type))
569 return DECL_PARALLEL_TYPE (TYPE_STUB_DECL (type));
570 else
571 return NULL_TREE;
572 }
573
574 /* Return the underlying base type of an enumeration type. */
575
576 static tree
577 gnat_enum_underlying_base_type (const_tree)
578 {
579 /* Enumeration types are base types in Ada. */
580 return void_type_node;
581 }
582
583 /* Return the type to be used for debugging information instead of TYPE or
584 NULL_TREE if TYPE is fine. */
585
586 static tree
587 gnat_get_debug_type (const_tree type)
588 {
589 if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type) && TYPE_DEBUG_TYPE (type))
590 {
591 type = TYPE_DEBUG_TYPE (type);
592
593 /* ??? The get_debug_type language hook is processed after the array
594 descriptor language hook, so if there is an array behind this type,
595 the latter is supposed to handle it. Still, we can get here with
596 a type we are not supposed to handle (e.g. when the DWARF back-end
597 processes the type of a variable), so keep this guard. */
598 if (type && TYPE_CAN_HAVE_DEBUG_TYPE_P (type))
599 return const_cast<tree> (type);
600 }
601
602 return NULL_TREE;
603 }
604
605 /* Provide information in INFO for debugging output about the TYPE fixed-point
606 type. Return whether TYPE is handled. */
607
608 static bool
609 gnat_get_fixed_point_type_info (const_tree type,
610 struct fixed_point_type_info *info)
611 {
612 tree scale_factor;
613
614 /* GDB cannot handle fixed-point types yet, so rely on GNAT encodings
615 instead for it. */
616 if (!TYPE_IS_FIXED_POINT_P (type)
617 || gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
618 return false;
619
620 scale_factor = TYPE_SCALE_FACTOR (type);
621
622 /* We expect here only a finite set of pattern. See fixed-point types
623 handling in gnat_to_gnu_entity. */
624
625 /* Put invalid values when compiler internals cannot represent the scale
626 factor. */
627 if (scale_factor == integer_zero_node)
628 {
629 info->scale_factor_kind = fixed_point_scale_factor_arbitrary;
630 info->scale_factor.arbitrary.numerator = 0;
631 info->scale_factor.arbitrary.denominator = 0;
632 return true;
633 }
634
635 if (TREE_CODE (scale_factor) == RDIV_EXPR)
636 {
637 const tree num = TREE_OPERAND (scale_factor, 0);
638 const tree den = TREE_OPERAND (scale_factor, 1);
639
640 /* See if we have a binary or decimal scale. */
641 if (TREE_CODE (den) == POWER_EXPR)
642 {
643 const tree base = TREE_OPERAND (den, 0);
644 const tree exponent = TREE_OPERAND (den, 1);
645
646 /* We expect the scale factor to be 1 / 2 ** N or 1 / 10 ** N. */
647 gcc_assert (num == integer_one_node
648 && TREE_CODE (base) == INTEGER_CST
649 && TREE_CODE (exponent) == INTEGER_CST);
650
651 switch (tree_to_shwi (base))
652 {
653 case 2:
654 info->scale_factor_kind = fixed_point_scale_factor_binary;
655 info->scale_factor.binary = -tree_to_shwi (exponent);
656 return true;
657
658 case 10:
659 info->scale_factor_kind = fixed_point_scale_factor_decimal;
660 info->scale_factor.decimal = -tree_to_shwi (exponent);
661 return true;
662
663 default:
664 gcc_unreachable ();
665 }
666 }
667
668 /* If we reach this point, we are handling an arbitrary scale factor. We
669 expect N / D with constant operands. */
670 gcc_assert (TREE_CODE (num) == INTEGER_CST
671 && TREE_CODE (den) == INTEGER_CST);
672
673 info->scale_factor_kind = fixed_point_scale_factor_arbitrary;
674 info->scale_factor.arbitrary.numerator = tree_to_uhwi (num);
675 info->scale_factor.arbitrary.denominator = tree_to_shwi (den);
676 return true;
677 }
678
679 gcc_unreachable ();
680 }
681
682 /* Return true if types T1 and T2 are identical for type hashing purposes.
683 Called only after doing all language independent checks. At present,
684 this function is only called when both types are FUNCTION_TYPE. */
685
686 static bool
687 gnat_type_hash_eq (const_tree t1, const_tree t2)
688 {
689 gcc_assert (TREE_CODE (t1) == FUNCTION_TYPE);
690 return fntype_same_flags_p (t1, TYPE_CI_CO_LIST (t2),
691 TYPE_RETURN_UNCONSTRAINED_P (t2),
692 TYPE_RETURN_BY_DIRECT_REF_P (t2),
693 TREE_ADDRESSABLE (t2));
694 }
695
696 /* Do nothing (return the tree node passed). */
697
698 static tree
699 gnat_return_tree (tree t)
700 {
701 return t;
702 }
703
704 /* Get the alias set corresponding to a type or expression. */
705
706 static alias_set_type
707 gnat_get_alias_set (tree type)
708 {
709 /* If this is a padding type, use the type of the first field. */
710 if (TYPE_IS_PADDING_P (type))
711 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
712
713 /* If the type is an unconstrained array, use the type of the
714 self-referential array we make. */
715 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
716 return
717 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
718
719 /* If the type can alias any other types, return the alias set 0. */
720 else if (TYPE_P (type)
721 && !TYPE_IS_DUMMY_P (type)
722 && TYPE_UNIVERSAL_ALIASING_P (type))
723 return 0;
724
725 return -1;
726 }
727
728 /* GNU_TYPE is a type. Return its maximum size in bytes, if known,
729 as a constant when possible. */
730
731 static tree
732 gnat_type_max_size (const_tree gnu_type)
733 {
734 /* First see what we can get from TYPE_SIZE_UNIT, which might not
735 be constant even for simple expressions if it has already been
736 elaborated and possibly replaced by a VAR_DECL. */
737 tree max_unitsize = max_size (TYPE_SIZE_UNIT (gnu_type), true);
738
739 /* If we don't have a constant, see what we can get from TYPE_ADA_SIZE,
740 which should stay untouched. */
741 if (!tree_fits_uhwi_p (max_unitsize)
742 && RECORD_OR_UNION_TYPE_P (gnu_type)
743 && !TYPE_FAT_POINTER_P (gnu_type)
744 && TYPE_ADA_SIZE (gnu_type))
745 {
746 tree max_adasize = max_size (TYPE_ADA_SIZE (gnu_type), true);
747
748 /* If we have succeeded in finding a constant, round it up to the
749 type's alignment and return the result in units. */
750 if (tree_fits_uhwi_p (max_adasize))
751 max_unitsize
752 = size_binop (CEIL_DIV_EXPR,
753 round_up (max_adasize, TYPE_ALIGN (gnu_type)),
754 bitsize_unit_node);
755 }
756
757 return max_unitsize;
758 }
759
760 static tree get_array_bit_stride (tree);
761
762 /* Provide information in INFO for debug output about the TYPE array type.
763 Return whether TYPE is handled. */
764
765 static bool
766 gnat_get_array_descr_info (const_tree const_type,
767 struct array_descr_info *info)
768 {
769 bool convention_fortran_p;
770 bool is_array = false;
771 bool is_fat_ptr = false;
772 bool is_packed_array = false;
773 tree type = const_cast<tree> (const_type);
774 const_tree first_dimen = NULL_TREE;
775 const_tree last_dimen = NULL_TREE;
776 const_tree dimen;
777 int i;
778
779 /* Temporaries created in the first pass and used in the second one for thin
780 pointers. The first one is an expression that yields the template record
781 from the base address (i.e. the PLACEHOLDER_EXPR). The second one is just
782 a cursor through this record's fields. */
783 tree thinptr_template_expr = NULL_TREE;
784 tree thinptr_bound_field = NULL_TREE;
785
786 /* ??? See gnat_get_debug_type. */
787 type = maybe_debug_type (type);
788
789 /* If we have an implementation type for a packed array, get the orignial
790 array type. */
791 if (TYPE_IMPL_PACKED_ARRAY_P (type) && TYPE_ORIGINAL_PACKED_ARRAY (type))
792 {
793 type = TYPE_ORIGINAL_PACKED_ARRAY (type);
794 is_packed_array = true;
795 }
796
797 /* First pass: gather all information about this array except everything
798 related to dimensions. */
799
800 /* Only handle ARRAY_TYPE nodes that come from GNAT. */
801 if (TREE_CODE (type) == ARRAY_TYPE
802 && TYPE_DOMAIN (type)
803 && TYPE_INDEX_TYPE (TYPE_DOMAIN (type)))
804 {
805 is_array = true;
806 first_dimen = type;
807 info->data_location = NULL_TREE;
808 }
809
810 else if (TYPE_IS_FAT_POINTER_P (type)
811 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
812 {
813 const tree ua_type = TYPE_UNCONSTRAINED_ARRAY (type);
814
815 /* This will be our base object address. */
816 const tree placeholder_expr = build0 (PLACEHOLDER_EXPR, type);
817
818 /* We assume below that maybe_unconstrained_array returns an INDIRECT_REF
819 node. */
820 const tree ua_val
821 = maybe_unconstrained_array (build_unary_op (INDIRECT_REF,
822 ua_type,
823 placeholder_expr));
824
825 is_fat_ptr = true;
826 first_dimen = TREE_TYPE (ua_val);
827
828 /* Get the *address* of the array, not the array itself. */
829 info->data_location = TREE_OPERAND (ua_val, 0);
830 }
831
832 /* Unlike fat pointers (which appear for unconstrained arrays passed in
833 argument), thin pointers are used only for array access types, so we want
834 them to appear in the debug info as pointers to an array type. That's why
835 we match only the RECORD_TYPE here instead of the POINTER_TYPE with the
836 TYPE_IS_THIN_POINTER_P predicate. */
837 else if (TREE_CODE (type) == RECORD_TYPE
838 && TYPE_CONTAINS_TEMPLATE_P (type)
839 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
840 {
841 /* This will be our base object address. Note that we assume that
842 pointers to these will actually point to the array field (thin
843 pointers are shifted). */
844 const tree placeholder_expr = build0 (PLACEHOLDER_EXPR, type);
845 const tree placeholder_addr
846 = build_unary_op (ADDR_EXPR, NULL_TREE, placeholder_expr);
847
848 const tree bounds_field = TYPE_FIELDS (type);
849 const tree bounds_type = TREE_TYPE (bounds_field);
850 const tree array_field = DECL_CHAIN (bounds_field);
851 const tree array_type = TREE_TYPE (array_field);
852
853 /* Shift the thin pointer address to get the address of the template. */
854 const tree shift_amount
855 = fold_build1 (NEGATE_EXPR, sizetype, byte_position (array_field));
856 tree template_addr
857 = build_binary_op (POINTER_PLUS_EXPR, TREE_TYPE (placeholder_addr),
858 placeholder_addr, shift_amount);
859 template_addr
860 = fold_convert (TYPE_POINTER_TO (bounds_type), template_addr);
861
862 first_dimen = array_type;
863
864 /* The thin pointer is already the pointer to the array data, so there's
865 no need for a specific "data location" expression. */
866 info->data_location = NULL_TREE;
867
868 thinptr_template_expr = build_unary_op (INDIRECT_REF,
869 bounds_type,
870 template_addr);
871 thinptr_bound_field = TYPE_FIELDS (bounds_type);
872 }
873 else
874 return false;
875
876 /* Second pass: compute the remaining information: dimensions and
877 corresponding bounds. */
878
879 if (TYPE_PACKED (first_dimen))
880 is_packed_array = true;
881 /* If this array has fortran convention, it's arranged in column-major
882 order, so our view here has reversed dimensions. */
883 convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (first_dimen);
884 /* ??? For row major ordering, we probably want to emit nothing and
885 instead specify it as the default in Dw_TAG_compile_unit. */
886 info->ordering = (convention_fortran_p
887 ? array_descr_ordering_column_major
888 : array_descr_ordering_row_major);
889
890 /* Count how many dimensions this array has. */
891 for (i = 0, dimen = first_dimen; ; ++i, dimen = TREE_TYPE (dimen))
892 {
893 if (i > 0
894 && (TREE_CODE (dimen) != ARRAY_TYPE
895 || !TYPE_MULTI_ARRAY_P (dimen)))
896 break;
897 last_dimen = dimen;
898 }
899
900 info->ndimensions = i;
901
902 /* Too many dimensions? Give up generating proper description: yield instead
903 nested arrays. Note that in this case, this hook is invoked once on each
904 intermediate array type: be consistent and output nested arrays for all
905 dimensions. */
906 if (info->ndimensions > DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
907 || TYPE_MULTI_ARRAY_P (first_dimen))
908 {
909 info->ndimensions = 1;
910 last_dimen = first_dimen;
911 }
912
913 info->element_type = TREE_TYPE (last_dimen);
914
915 /* Now iterate over all dimensions in source-order and fill the info
916 structure. */
917 for (i = (convention_fortran_p ? info->ndimensions - 1 : 0),
918 dimen = first_dimen;
919 0 <= i && i < info->ndimensions;
920 i += (convention_fortran_p ? -1 : 1),
921 dimen = TREE_TYPE (dimen))
922 {
923 /* We are interested in the stored bounds for the debug info. */
924 tree index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (dimen));
925
926 if (is_array || is_fat_ptr)
927 {
928 /* GDB does not handle very well the self-referencial bound
929 expressions we are able to generate here for XUA types (they are
930 used only by XUP encodings) so avoid them in this case. Note that
931 there are two cases where we generate self-referencial bound
932 expressions: arrays that are constrained by record discriminants
933 and XUA types. */
934 if (TYPE_CONTEXT (first_dimen)
935 && TREE_CODE (TYPE_CONTEXT (first_dimen)) != RECORD_TYPE
936 && CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (index_type))
937 && gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
938 {
939 info->dimen[i].lower_bound = NULL_TREE;
940 info->dimen[i].upper_bound = NULL_TREE;
941 }
942 else
943 {
944 info->dimen[i].lower_bound
945 = maybe_character_value (TYPE_MIN_VALUE (index_type));
946 info->dimen[i].upper_bound
947 = maybe_character_value (TYPE_MAX_VALUE (index_type));
948 }
949 }
950
951 /* This is a thin pointer. */
952 else
953 {
954 info->dimen[i].lower_bound
955 = build_component_ref (thinptr_template_expr, thinptr_bound_field,
956 false);
957 thinptr_bound_field = DECL_CHAIN (thinptr_bound_field);
958
959 info->dimen[i].upper_bound
960 = build_component_ref (thinptr_template_expr, thinptr_bound_field,
961 false);
962 thinptr_bound_field = DECL_CHAIN (thinptr_bound_field);
963 }
964
965 /* The DWARF back-end will output BOUNDS_TYPE as the base type of
966 the array index, so get to the base type of INDEX_TYPE. */
967 while (TREE_TYPE (index_type))
968 index_type = TREE_TYPE (index_type);
969
970 info->dimen[i].bounds_type = maybe_debug_type (index_type);
971 info->dimen[i].stride = NULL_TREE;
972 }
973
974 /* These are Fortran-specific fields. They make no sense here. */
975 info->allocated = NULL_TREE;
976 info->associated = NULL_TREE;
977
978 if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
979 {
980 /* When arrays contain dynamically-sized elements, we usually wrap them
981 in padding types, or we create constrained types for them. Then, if
982 such types are stripped in the debugging information output, the
983 debugger needs a way to know the size that is reserved for each
984 element. This is why we emit a stride in such situations. */
985 tree source_element_type = info->element_type;
986
987 while (true)
988 {
989 if (TYPE_DEBUG_TYPE (source_element_type))
990 source_element_type = TYPE_DEBUG_TYPE (source_element_type);
991 else if (TYPE_IS_PADDING_P (source_element_type))
992 source_element_type
993 = TREE_TYPE (TYPE_FIELDS (source_element_type));
994 else
995 break;
996 }
997
998 if (TREE_CODE (TYPE_SIZE_UNIT (source_element_type)) != INTEGER_CST)
999 {
1000 info->stride = TYPE_SIZE_UNIT (info->element_type);
1001 info->stride_in_bits = false;
1002 }
1003
1004 /* We need to specify a bit stride when it does not correspond to the
1005 natural size of the contained elements. ??? Note that we do not
1006 support packed records and nested packed arrays. */
1007 else if (is_packed_array)
1008 {
1009 info->stride = get_array_bit_stride (info->element_type);
1010 info->stride_in_bits = true;
1011 }
1012 }
1013
1014 return true;
1015 }
1016
1017 /* Given the component type COMP_TYPE of a packed array, return an expression
1018 that computes the bit stride of this packed array. Return NULL_TREE when
1019 unsuccessful. */
1020
1021 static tree
1022 get_array_bit_stride (tree comp_type)
1023 {
1024 struct array_descr_info info;
1025 tree stride;
1026
1027 /* Simple case: the array contains an integral type: return its RM size. */
1028 if (INTEGRAL_TYPE_P (comp_type))
1029 return TYPE_RM_SIZE (comp_type);
1030
1031 /* Otherwise, see if this is an array we can analyze; if it's not, punt. */
1032 memset (&info, 0, sizeof (info));
1033 if (!gnat_get_array_descr_info (comp_type, &info) || !info.stride)
1034 return NULL_TREE;
1035
1036 /* Otherwise, the array stride is the inner array's stride multiplied by the
1037 number of elements it contains. Note that if the inner array is not
1038 packed, then the stride is "natural" and thus does not deserve an
1039 attribute. */
1040 stride = info.stride;
1041 if (!info.stride_in_bits)
1042 {
1043 stride = fold_convert (bitsizetype, stride);
1044 stride = build_binary_op (MULT_EXPR, bitsizetype,
1045 stride, build_int_cst (bitsizetype, 8));
1046 }
1047
1048 for (int i = 0; i < info.ndimensions; ++i)
1049 {
1050 tree count;
1051
1052 if (!info.dimen[i].lower_bound || !info.dimen[i].upper_bound)
1053 return NULL_TREE;
1054
1055 /* Put in count an expression that computes the length of this
1056 dimension. */
1057 count = build_binary_op (MINUS_EXPR, sbitsizetype,
1058 fold_convert (sbitsizetype,
1059 info.dimen[i].upper_bound),
1060 fold_convert (sbitsizetype,
1061 info.dimen[i].lower_bound)),
1062 count = build_binary_op (PLUS_EXPR, sbitsizetype,
1063 count, build_int_cst (sbitsizetype, 1));
1064 count = build_binary_op (MAX_EXPR, sbitsizetype,
1065 count,
1066 build_int_cst (sbitsizetype, 0));
1067 count = fold_convert (bitsizetype, count);
1068 stride = build_binary_op (MULT_EXPR, bitsizetype, stride, count);
1069 }
1070
1071 return stride;
1072 }
1073
1074 /* GNU_TYPE is a subtype of an integral type. Set LOWVAL to the low bound
1075 and HIGHVAL to the high bound, respectively. */
1076
1077 static void
1078 gnat_get_subrange_bounds (const_tree gnu_type, tree *lowval, tree *highval)
1079 {
1080 *lowval = TYPE_MIN_VALUE (gnu_type);
1081 *highval = TYPE_MAX_VALUE (gnu_type);
1082 }
1083
1084 /* Return the bias of GNU_TYPE, if any. */
1085
1086 static tree
1087 gnat_get_type_bias (const_tree gnu_type)
1088 {
1089 if (TREE_CODE (gnu_type) == INTEGER_TYPE
1090 && TYPE_BIASED_REPRESENTATION_P (gnu_type)
1091 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
1092 return TYPE_RM_MIN_VALUE (gnu_type);
1093
1094 return NULL_TREE;
1095 }
1096
1097 /* GNU_TYPE is the type of a subprogram parameter. Determine if it should be
1098 passed by reference by default. */
1099
1100 bool
1101 default_pass_by_ref (tree gnu_type)
1102 {
1103 /* We pass aggregates by reference if they are sufficiently large for
1104 their alignment. The ratio is somewhat arbitrary. We also pass by
1105 reference if the target machine would either pass or return by
1106 reference. Strictly speaking, we need only check the return if this
1107 is an In Out parameter, but it's probably best to err on the side of
1108 passing more things by reference. */
1109
1110 if (pass_by_reference (NULL, TYPE_MODE (gnu_type), gnu_type, true))
1111 return true;
1112
1113 if (targetm.calls.return_in_memory (gnu_type, NULL_TREE))
1114 return true;
1115
1116 if (AGGREGATE_TYPE_P (gnu_type)
1117 && (!valid_constant_size_p (TYPE_SIZE_UNIT (gnu_type))
1118 || 0 < compare_tree_int (TYPE_SIZE_UNIT (gnu_type),
1119 TYPE_ALIGN (gnu_type))))
1120 return true;
1121
1122 return false;
1123 }
1124
1125 /* GNU_TYPE is the type of a subprogram parameter. Determine if it must be
1126 passed by reference. */
1127
1128 bool
1129 must_pass_by_ref (tree gnu_type)
1130 {
1131 /* We pass only unconstrained objects, those required by the language
1132 to be passed by reference, and objects of variable size. The latter
1133 is more efficient, avoids problems with variable size temporaries,
1134 and does not produce compatibility problems with C, since C does
1135 not have such objects. */
1136 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
1137 || TYPE_IS_BY_REFERENCE_P (gnu_type)
1138 || (TYPE_SIZE_UNIT (gnu_type)
1139 && TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) != INTEGER_CST));
1140 }
1141
1142 /* This function is called by the front-end to enumerate all the supported
1143 modes for the machine, as well as some predefined C types. F is a function
1144 which is called back with the parameters as listed below, first a string,
1145 then seven ints. The name is any arbitrary null-terminated string and has
1146 no particular significance, except for the case of predefined C types, where
1147 it should be the name of the C type. For integer types, only signed types
1148 should be listed, unsigned versions are assumed. The order of types should
1149 be in order of preference, with the smallest/cheapest types first.
1150
1151 In particular, C predefined types should be listed before other types,
1152 binary floating point types before decimal ones, and narrower/cheaper
1153 type versions before more expensive ones. In type selection the first
1154 matching variant will be used.
1155
1156 NAME pointer to first char of type name
1157 DIGS number of decimal digits for floating-point modes, else 0
1158 COMPLEX_P nonzero is this represents a complex mode
1159 COUNT count of number of items, nonzero for vector mode
1160 FLOAT_REP Float_Rep_Kind for FP, otherwise undefined
1161 PRECISION number of bits used to store data
1162 SIZE number of bits occupied by the mode
1163 ALIGN number of bits to which mode is aligned. */
1164
1165 void
1166 enumerate_modes (void (*f) (const char *, int, int, int, int, int, int, int))
1167 {
1168 const tree c_types[]
1169 = { float_type_node, double_type_node, long_double_type_node };
1170 const char *const c_names[]
1171 = { "float", "double", "long double" };
1172 int iloop;
1173
1174 /* We are going to compute it below. */
1175 fp_arith_may_widen = false;
1176
1177 for (iloop = 0; iloop < NUM_MACHINE_MODES; iloop++)
1178 {
1179 machine_mode i = (machine_mode) iloop;
1180 machine_mode inner_mode = i;
1181 bool float_p = false;
1182 bool complex_p = false;
1183 bool vector_p = false;
1184 bool skip_p = false;
1185 int digs = 0;
1186 unsigned int nameloop;
1187 Float_Rep_Kind float_rep = IEEE_Binary; /* Until proven otherwise */
1188
1189 switch (GET_MODE_CLASS (i))
1190 {
1191 case MODE_INT:
1192 break;
1193 case MODE_FLOAT:
1194 float_p = true;
1195 break;
1196 case MODE_COMPLEX_INT:
1197 complex_p = true;
1198 inner_mode = GET_MODE_INNER (i);
1199 break;
1200 case MODE_COMPLEX_FLOAT:
1201 float_p = true;
1202 complex_p = true;
1203 inner_mode = GET_MODE_INNER (i);
1204 break;
1205 case MODE_VECTOR_INT:
1206 vector_p = true;
1207 inner_mode = GET_MODE_INNER (i);
1208 break;
1209 case MODE_VECTOR_FLOAT:
1210 float_p = true;
1211 vector_p = true;
1212 inner_mode = GET_MODE_INNER (i);
1213 break;
1214 default:
1215 skip_p = true;
1216 }
1217
1218 if (float_p)
1219 {
1220 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
1221
1222 /* ??? Cope with the ghost XFmode of the ARM port. */
1223 if (!fmt)
1224 continue;
1225
1226 /* Be conservative and consider that floating-point arithmetics may
1227 use wider intermediate results as soon as there is an extended
1228 Motorola or Intel mode supported by the machine. */
1229 if (fmt == &ieee_extended_motorola_format
1230 || fmt == &ieee_extended_intel_96_format
1231 || fmt == &ieee_extended_intel_96_round_53_format
1232 || fmt == &ieee_extended_intel_128_format)
1233 {
1234 #ifdef TARGET_FPMATH_DEFAULT
1235 if (TARGET_FPMATH_DEFAULT == FPMATH_387)
1236 #endif
1237 fp_arith_may_widen = true;
1238 }
1239
1240 if (fmt->b == 2)
1241 digs = (fmt->p - 1) * 1233 / 4096; /* scale by log (2) */
1242
1243 else if (fmt->b == 10)
1244 digs = fmt->p;
1245
1246 else
1247 gcc_unreachable ();
1248 }
1249
1250 /* First register any C types for this mode that the front end
1251 may need to know about, unless the mode should be skipped. */
1252 if (!skip_p && !vector_p)
1253 for (nameloop = 0; nameloop < ARRAY_SIZE (c_types); nameloop++)
1254 {
1255 tree type = c_types[nameloop];
1256 const char *name = c_names[nameloop];
1257
1258 if (TYPE_MODE (type) == i)
1259 {
1260 f (name, digs, complex_p, 0, float_rep, TYPE_PRECISION (type),
1261 TREE_INT_CST_LOW (TYPE_SIZE (type)), TYPE_ALIGN (type));
1262 skip_p = true;
1263 }
1264 }
1265
1266 /* If no predefined C types were found, register the mode itself. */
1267 if (!skip_p)
1268 f (GET_MODE_NAME (i), digs, complex_p,
1269 vector_p ? GET_MODE_NUNITS (i) : 0, float_rep,
1270 GET_MODE_PRECISION (i), GET_MODE_BITSIZE (i),
1271 GET_MODE_ALIGNMENT (i));
1272 }
1273 }
1274
1275 /* Return the size of the FP mode with precision PREC. */
1276
1277 int
1278 fp_prec_to_size (int prec)
1279 {
1280 machine_mode mode;
1281
1282 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
1283 mode = GET_MODE_WIDER_MODE (mode))
1284 if (GET_MODE_PRECISION (mode) == prec)
1285 return GET_MODE_BITSIZE (mode);
1286
1287 gcc_unreachable ();
1288 }
1289
1290 /* Return the precision of the FP mode with size SIZE. */
1291
1292 int
1293 fp_size_to_prec (int size)
1294 {
1295 machine_mode mode;
1296
1297 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
1298 mode = GET_MODE_WIDER_MODE (mode))
1299 if (GET_MODE_BITSIZE (mode) == size)
1300 return GET_MODE_PRECISION (mode);
1301
1302 gcc_unreachable ();
1303 }
1304
1305 static GTY(()) tree gnat_eh_personality_decl;
1306
1307 /* Return the GNAT personality function decl. */
1308
1309 static tree
1310 gnat_eh_personality (void)
1311 {
1312 if (!gnat_eh_personality_decl)
1313 gnat_eh_personality_decl = build_personality_function ("gnat");
1314 return gnat_eh_personality_decl;
1315 }
1316
1317 /* Initialize language-specific bits of tree_contains_struct. */
1318
1319 static void
1320 gnat_init_ts (void)
1321 {
1322 MARK_TS_COMMON (UNCONSTRAINED_ARRAY_TYPE);
1323
1324 MARK_TS_TYPED (UNCONSTRAINED_ARRAY_REF);
1325 MARK_TS_TYPED (NULL_EXPR);
1326 MARK_TS_TYPED (PLUS_NOMOD_EXPR);
1327 MARK_TS_TYPED (MINUS_NOMOD_EXPR);
1328 MARK_TS_TYPED (POWER_EXPR);
1329 MARK_TS_TYPED (ATTR_ADDR_EXPR);
1330 MARK_TS_TYPED (STMT_STMT);
1331 MARK_TS_TYPED (LOOP_STMT);
1332 MARK_TS_TYPED (EXIT_STMT);
1333 }
1334
1335 /* Return the lang specific structure attached to NODE. Allocate it (cleared)
1336 if needed. */
1337
1338 struct lang_type *
1339 get_lang_specific (tree node)
1340 {
1341 if (!TYPE_LANG_SPECIFIC (node))
1342 TYPE_LANG_SPECIFIC (node) = ggc_cleared_alloc<struct lang_type> ();
1343 return TYPE_LANG_SPECIFIC (node);
1344 }
1345
1346 /* Definitions for our language-specific hooks. */
1347
1348 #undef LANG_HOOKS_NAME
1349 #define LANG_HOOKS_NAME "GNU Ada"
1350 #undef LANG_HOOKS_IDENTIFIER_SIZE
1351 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
1352 #undef LANG_HOOKS_INIT
1353 #define LANG_HOOKS_INIT gnat_init
1354 #undef LANG_HOOKS_OPTION_LANG_MASK
1355 #define LANG_HOOKS_OPTION_LANG_MASK gnat_option_lang_mask
1356 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1357 #define LANG_HOOKS_INIT_OPTIONS_STRUCT gnat_init_options_struct
1358 #undef LANG_HOOKS_INIT_OPTIONS
1359 #define LANG_HOOKS_INIT_OPTIONS gnat_init_options
1360 #undef LANG_HOOKS_HANDLE_OPTION
1361 #define LANG_HOOKS_HANDLE_OPTION gnat_handle_option
1362 #undef LANG_HOOKS_POST_OPTIONS
1363 #define LANG_HOOKS_POST_OPTIONS gnat_post_options
1364 #undef LANG_HOOKS_PARSE_FILE
1365 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
1366 #undef LANG_HOOKS_TYPE_HASH_EQ
1367 #define LANG_HOOKS_TYPE_HASH_EQ gnat_type_hash_eq
1368 #undef LANG_HOOKS_GETDECLS
1369 #define LANG_HOOKS_GETDECLS hook_tree_void_null
1370 #undef LANG_HOOKS_PUSHDECL
1371 #define LANG_HOOKS_PUSHDECL gnat_return_tree
1372 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
1373 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL hook_bool_const_tree_false
1374 #undef LANG_HOOKS_GET_ALIAS_SET
1375 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
1376 #undef LANG_HOOKS_PRINT_DECL
1377 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
1378 #undef LANG_HOOKS_PRINT_TYPE
1379 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
1380 #undef LANG_HOOKS_TYPE_MAX_SIZE
1381 #define LANG_HOOKS_TYPE_MAX_SIZE gnat_type_max_size
1382 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
1383 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
1384 #undef LANG_HOOKS_DWARF_NAME
1385 #define LANG_HOOKS_DWARF_NAME gnat_dwarf_name
1386 #undef LANG_HOOKS_GIMPLIFY_EXPR
1387 #define LANG_HOOKS_GIMPLIFY_EXPR gnat_gimplify_expr
1388 #undef LANG_HOOKS_TYPE_FOR_MODE
1389 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
1390 #undef LANG_HOOKS_TYPE_FOR_SIZE
1391 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
1392 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1393 #define LANG_HOOKS_TYPES_COMPATIBLE_P gnat_types_compatible_p
1394 #undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
1395 #define LANG_HOOKS_GET_ARRAY_DESCR_INFO gnat_get_array_descr_info
1396 #undef LANG_HOOKS_GET_SUBRANGE_BOUNDS
1397 #define LANG_HOOKS_GET_SUBRANGE_BOUNDS gnat_get_subrange_bounds
1398 #undef LANG_HOOKS_GET_TYPE_BIAS
1399 #define LANG_HOOKS_GET_TYPE_BIAS gnat_get_type_bias
1400 #undef LANG_HOOKS_DESCRIPTIVE_TYPE
1401 #define LANG_HOOKS_DESCRIPTIVE_TYPE gnat_descriptive_type
1402 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
1403 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE gnat_enum_underlying_base_type
1404 #undef LANG_HOOKS_GET_DEBUG_TYPE
1405 #define LANG_HOOKS_GET_DEBUG_TYPE gnat_get_debug_type
1406 #undef LANG_HOOKS_GET_FIXED_POINT_TYPE_INFO
1407 #define LANG_HOOKS_GET_FIXED_POINT_TYPE_INFO gnat_get_fixed_point_type_info
1408 #undef LANG_HOOKS_ATTRIBUTE_TABLE
1409 #define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table
1410 #undef LANG_HOOKS_BUILTIN_FUNCTION
1411 #define LANG_HOOKS_BUILTIN_FUNCTION gnat_builtin_function
1412 #undef LANG_HOOKS_INIT_TS
1413 #define LANG_HOOKS_INIT_TS gnat_init_ts
1414 #undef LANG_HOOKS_EH_PERSONALITY
1415 #define LANG_HOOKS_EH_PERSONALITY gnat_eh_personality
1416 #undef LANG_HOOKS_DEEP_UNSHARING
1417 #define LANG_HOOKS_DEEP_UNSHARING true
1418 #undef LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
1419 #define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
1420
1421 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1422
1423 #include "gt-ada-misc.h"