]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/gcc-interface/misc.c
tree-core.h: Include symtab.h.
[thirdparty/gcc.git] / gcc / ada / gcc-interface / misc.c
CommitLineData
a1ab4c31
AC
1/****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * M I S C *
6 * *
7 * C Implementation File *
8 * *
6a0a7f07 9 * Copyright (C) 1992-2015, Free Software Foundation, Inc. *
a1ab4c31
AC
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- *
748086b7 13 * ware Foundation; either version 3, or (at your option) any later ver- *
a1ab4c31
AC
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 *
748086b7
JJ
18 * Public License distributed with GNAT; see file COPYING3. If not see *
19 * <http://www.gnu.org/licenses/>. *
a1ab4c31
AC
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
a1ab4c31
AC
26#include "config.h"
27#include "system.h"
28#include "coretypes.h"
f2bc201f
MLI
29#include "opts.h"
30#include "options.h"
a1ab4c31 31#include "tm.h"
40e23961 32#include "vec.h"
40e23961 33#include "alias.h"
a1ab4c31 34#include "tree.h"
c7131fb2 35#include "inchash.h"
40e23961 36#include "fold-const.h"
d8a2d370
DN
37#include "stor-layout.h"
38#include "print-tree.h"
a1ab4c31 39#include "diagnostic.h"
8713b7e4 40#include "target.h"
a1ab4c31
AC
41#include "ggc.h"
42#include "flags.h"
43#include "debug.h"
a1ab4c31 44#include "toplev.h"
a1ab4c31
AC
45#include "langhooks.h"
46#include "langhooks-def.h"
a13812e2 47#include "plugin.h"
83685514 48#include "hashtab.h"
83685514 49#include "hard-reg-set.h"
16a16ec7 50#include "calls.h" /* For pass_by_reference. */
ce37c297 51#include "dwarf2out.h"
a1ab4c31
AC
52
53#include "ada.h"
8713b7e4 54#include "adadecode.h"
a1ab4c31
AC
55#include "types.h"
56#include "atree.h"
57#include "elists.h"
58#include "namet.h"
59#include "nlists.h"
60#include "stringt.h"
61#include "uintp.h"
62#include "fe.h"
63#include "sinfo.h"
64#include "einfo.h"
65#include "ada-tree.h"
66#include "gigi.h"
a1ab4c31 67
c88f5c49
JM
68/* This symbol needs to be defined for the front-end. */
69void *callgraph_info_file = NULL;
70
c6282415
EB
71/* Command-line argc and argv. These variables are global since they are
72 imported in back_end.adb. */
a1ab4c31
AC
73unsigned int save_argc;
74const char **save_argv;
75
feec4372 76/* GNAT argc and argv. */
a1ab4c31
AC
77extern int gnat_argc;
78extern char **gnat_argv;
79
9e9bd455
LG
80#ifdef __cplusplus
81extern "C" {
82#endif
83
a1ab4c31 84/* Declare functions we use as part of startup. */
c6282415
EB
85extern void __gnat_initialize (void *);
86extern void __gnat_install_SEH_handler (void *);
87extern void adainit (void);
88extern void _ada_gnat1drv (void);
a1ab4c31 89
9e9bd455
LG
90#ifdef __cplusplus
91}
92#endif
93
a1ab4c31
AC
94/* The parser for the language. For us, we process the GNAT tree. */
95
96static void
b37421c6 97gnat_parse_file (void)
a1ab4c31
AC
98{
99 int seh[2];
100
101 /* Call the target specific initializations. */
102 __gnat_initialize (NULL);
103
104 /* ??? Call the SEH initialization routine. This is to workaround
105 a bootstrap path problem. The call below should be removed at some
106 point and the SEH pointer passed to __gnat_initialize() above. */
107 __gnat_install_SEH_handler((void *)seh);
108
109 /* Call the front-end elaboration procedures. */
110 adainit ();
111
112 /* Call the front end. */
113 _ada_gnat1drv ();
d7438551 114
a22b794d
EB
115 /* Write the global declarations. */
116 gnat_write_global_declarations ();
a1ab4c31
AC
117}
118
7d5a5747
MLI
119/* Return language mask for option processing. */
120
121static unsigned int
122gnat_option_lang_mask (void)
123{
124 return CL_Ada;
125}
126
a1ab4c31
AC
127/* Decode all the language specific options that cannot be decoded by GCC.
128 The option decoding phase of GCC calls this routine on the flags that
5f20c657 129 are marked as Ada-specific. Return true on success or false on failure. */
a1ab4c31 130
5f20c657
JM
131static bool
132gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value,
a4d8c676 133 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
5f20c657 134 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
a1ab4c31 135{
a1ab4c31 136 enum opt_code code = (enum opt_code) scode;
a1ab4c31 137
a1ab4c31
AC
138 switch (code)
139 {
a1ab4c31 140 case OPT_Wall:
7d5a5747
MLI
141 handle_generated_option (&global_options, &global_options_set,
142 OPT_Wunused, NULL, value,
143 gnat_option_lang_mask (), kind, loc,
144 handlers, global_dc);
fa36ce9c 145 warn_uninitialized = value;
fa5e5a76 146 warn_maybe_uninitialized = value;
a1ab4c31
AC
147 break;
148
a1ab4c31
AC
149 case OPT_gant:
150 warning (0, "%<-gnat%> misspelled as %<-gant%>");
151
152 /* ... fall through ... */
153
154 case OPT_gnat:
a1ab4c31 155 case OPT_gnatO:
2334baf4
EB
156 case OPT_fRTS_:
157 case OPT_I:
158 case OPT_nostdinc:
159 case OPT_nostdlib:
160 /* These are handled by the front-end. */
a1ab4c31
AC
161 break;
162
c51f5910
AC
163 case OPT_fshort_enums:
164 /* This is handled by the middle-end. */
165 break;
166
a1ab4c31
AC
167 default:
168 gcc_unreachable ();
169 }
170
c80c1ce9
EB
171 Ada_handle_option_auto (&global_options, &global_options_set,
172 scode, arg, value,
173 gnat_option_lang_mask (), kind,
174 loc, handlers, global_dc);
5f20c657 175 return true;
a1ab4c31
AC
176}
177
a75bfaa6
JM
178/* Initialize options structure OPTS. */
179
180static void
181gnat_init_options_struct (struct gcc_options *opts)
182{
183 /* Uninitialized really means uninitialized in Ada. */
184 opts->x_flag_zero_initialized_in_bss = 0;
2da02156 185
98ae260d
EB
186 /* We don't care about errno in Ada and it causes __builtin_sqrt to
187 call the libm function rather than do it inline. */
188 opts->x_flag_errno_math = 0;
189 opts->frontend_set_flag_errno_math = true;
a75bfaa6
JM
190}
191
7a9bf9a4
JM
192/* Initialize for option processing. */
193
194static void
195gnat_init_options (unsigned int decoded_options_count,
196 struct cl_decoded_option *decoded_options)
197{
198 /* Reconstruct an argv array for use of back_end.adb.
199
c6282415
EB
200 ??? back_end.adb should not rely on this; instead, it should work with
201 decoded options without such reparsing, to ensure consistency in how
202 options are decoded. */
7a9bf9a4
JM
203 unsigned int i;
204
205 save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1);
206 save_argc = 0;
207 for (i = 0; i < decoded_options_count; i++)
208 {
c6282415
EB
209 size_t num_elements = decoded_options[i].canonical_option_num_elements;
210
eea13ead 211 if (decoded_options[i].errors
ffb7f675 212 || decoded_options[i].opt_index == OPT_SPECIAL_unknown
c6282415 213 || num_elements == 0)
eea13ead 214 continue;
c6282415 215
400a2d24
EB
216 /* Deal with -I- specially since it must be a single switch. */
217 if (decoded_options[i].opt_index == OPT_I
218 && num_elements == 2
219 && decoded_options[i].canonical_option[1][0] == '-'
220 && decoded_options[i].canonical_option[1][1] == '\0')
221 save_argv[save_argc++] = "-I-";
ffb7f675
JM
222 else
223 {
c6282415 224 gcc_assert (num_elements >= 1 && num_elements <= 2);
ffb7f675 225 save_argv[save_argc++] = decoded_options[i].canonical_option[0];
c6282415 226 if (num_elements >= 2)
ffb7f675
JM
227 save_argv[save_argc++] = decoded_options[i].canonical_option[1];
228 }
7a9bf9a4
JM
229 }
230 save_argv[save_argc] = NULL;
a1ab4c31 231
7a9bf9a4
JM
232 gnat_argv = (char **) xmalloc (sizeof (save_argv[0]));
233 gnat_argv[0] = xstrdup (save_argv[0]); /* name of the command */
234 gnat_argc = 1;
a1ab4c31
AC
235}
236
51be162e
JM
237/* Ada code requires variables for these settings rather than elements
238 of the global_options structure. */
239#undef optimize
240#undef optimize_size
5e471ea6 241#undef flag_compare_debug
bff2d234 242#undef flag_short_enums
5e471ea6 243#undef flag_stack_check
1572e2c3 244int gnat_encodings = 0;
51be162e
JM
245int optimize;
246int optimize_size;
5e471ea6 247int flag_compare_debug;
bff2d234 248int flag_short_enums;
5e471ea6 249enum stack_check_type flag_stack_check = NO_STACK_CHECK;
51be162e 250
8ed7930e
AC
251/* Settings adjustments after switches processing by the back-end.
252 Note that the front-end switches processing (Scan_Compiler_Arguments)
253 has not been done yet at this point! */
a1ab4c31 254
523e82a7 255static bool
a1ab4c31
AC
256gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
257{
d9d7a26c 258 /* Excess precision other than "fast" requires front-end support. */
8ce94e44
JM
259 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
260 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
261 sorry ("-fexcess-precision=standard for Ada");
262 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
263
e98c0739
L
264 /* No psABI change warnings for Ada. */
265 warn_psabi = 0;
266
1a5b6cd2
EB
267 /* No caret by default for Ada. */
268 if (!global_options_set.x_flag_diagnostics_show_caret)
269 global_dc->show_caret = false;
270
51be162e
JM
271 optimize = global_options.x_optimize;
272 optimize_size = global_options.x_optimize_size;
5e471ea6
JM
273 flag_compare_debug = global_options.x_flag_compare_debug;
274 flag_stack_check = global_options.x_flag_stack_check;
bff2d234
TG
275 flag_short_enums = global_options.x_flag_short_enums;
276
c51f5910
AC
277 /* Unfortunately the post_options hook is called before the value of
278 flag_short_enums is autodetected, if need be. Mimic the process
279 for our private flag_short_enums. */
280 if (flag_short_enums == 2)
281 flag_short_enums = targetm.default_short_enums ();
282
a1ab4c31
AC
283 return false;
284}
285
286/* Here is the function to handle the compiler error processing in GCC. */
287
288static void
a13812e2
JM
289internal_error_function (diagnostic_context *context,
290 const char *msgid, va_list *ap)
a1ab4c31
AC
291{
292 text_info tinfo;
293 char *buffer, *p, *loc;
294 String_Template temp, temp_loc;
93582885
EB
295 String_Pointer sp, sp_loc;
296 expanded_location xloc;
a1ab4c31 297
a13812e2
JM
298 /* Warn if plugins present. */
299 warn_if_plugins ();
300
a1ab4c31 301 /* Reset the pretty-printer. */
a13812e2 302 pp_clear_output_area (context->printer);
a1ab4c31
AC
303
304 /* Format the message into the pretty-printer. */
305 tinfo.format_spec = msgid;
306 tinfo.args_ptr = ap;
307 tinfo.err_no = errno;
a13812e2 308 pp_format_verbatim (context->printer, &tinfo);
a1ab4c31
AC
309
310 /* Extract a (writable) pointer to the formatted text. */
a13812e2 311 buffer = xstrdup (pp_formatted_text (context->printer));
a1ab4c31
AC
312
313 /* Go up to the first newline. */
314 for (p = buffer; *p; p++)
315 if (*p == '\n')
316 {
317 *p = '\0';
318 break;
319 }
320
321 temp.Low_Bound = 1;
322 temp.High_Bound = p - buffer;
93582885
EB
323 sp.Bounds = &temp;
324 sp.Array = buffer;
a1ab4c31 325
93582885
EB
326 xloc = expand_location (input_location);
327 if (context->show_column && xloc.column != 0)
1a78ef4c 328 loc = xasprintf ("%s:%d:%d", xloc.file, xloc.line, xloc.column);
a1ab4c31 329 else
1a78ef4c 330 loc = xasprintf ("%s:%d", xloc.file, xloc.line);
a1ab4c31
AC
331 temp_loc.Low_Bound = 1;
332 temp_loc.High_Bound = strlen (loc);
93582885
EB
333 sp_loc.Bounds = &temp_loc;
334 sp_loc.Array = loc;
a1ab4c31
AC
335
336 Current_Error_Node = error_gnat_node;
93582885 337 Compiler_Abort (sp, sp_loc, true);
a1ab4c31
AC
338}
339
340/* Perform all the initialization steps that are language-specific. */
341
342static bool
343gnat_init (void)
344{
86060344 345 /* Do little here, most of the standard declarations are set up after the
6936c61a
EB
346 front-end has been run. Use the same `char' as C, this doesn't really
347 matter since we'll use the explicit `unsigned char' for Character. */
1a072294 348 build_common_tree_nodes (flag_signed_char, false);
728936bb 349
86060344
EB
350 /* In Ada, we use an unsigned 8-bit type for the default boolean type. */
351 boolean_type_node = make_unsigned_type (8);
352 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
353 SET_TYPE_RM_MAX_VALUE (boolean_type_node,
354 build_int_cst (boolean_type_node, 1));
355 SET_TYPE_RM_SIZE (boolean_type_node, bitsize_int (1));
8384ac41
EB
356 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
357 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
86060344 358
1081f5a7
EB
359 sbitsize_one_node = sbitsize_int (1);
360 sbitsize_unit_node = sbitsize_int (BITS_PER_UNIT);
86060344 361
86060344
EB
362 /* Show that REFERENCE_TYPEs are internal and should be Pmode. */
363 internal_reference_types ();
a1ab4c31 364
86060344 365 /* Register our internal error function. */
a1ab4c31
AC
366 global_dc->internal_error = &internal_error_function;
367
a1ab4c31
AC
368 return true;
369}
370
df09b22c 371/* Initialize the GCC support for exception handling. */
a1ab4c31
AC
372
373void
374gnat_init_gcc_eh (void)
375{
a1ab4c31
AC
376 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
377 though. This could for instance lead to the emission of tables with
378 references to symbols (such as the Ada eh personality routine) within
379 libraries we won't link against. */
380 if (No_Exception_Handlers_Set ())
381 return;
382
383 /* Tell GCC we are handling cleanup actions through exception propagation.
384 This opens possibilities that we don't take advantage of yet, but is
385 nonetheless necessary to ensure that fixup code gets assigned to the
386 right exception regions. */
387 using_eh_for_cleanups ();
388
98ae260d
EB
389 /* Turn on -fexceptions, -fnon-call-exceptions and -fdelete-dead-exceptions.
390 The first one triggers the generation of the necessary exception tables.
391 The second one is useful for two reasons: 1/ we map some asynchronous
392 signals like SEGV to exceptions, so we need to ensure that the insns
393 which can lead to such signals are correctly attached to the exception
394 region they pertain to, 2/ some calls to pure subprograms are handled as
395 libcall blocks and then marked as "cannot trap" if the flag is not set
396 (see emit_libcall_block). We should not let this be since it is possible
397 for such calls to actually raise in Ada.
398 The third one is an optimization that makes it possible to delete dead
399 instructions that may throw exceptions, most notably loads and stores,
400 as permitted in Ada. */
a1ab4c31
AC
401 flag_exceptions = 1;
402 flag_non_call_exceptions = 1;
98ae260d 403 flag_delete_dead_exceptions = 1;
a1ab4c31
AC
404
405 init_eh ();
a1ab4c31
AC
406}
407
df09b22c
EB
408/* Initialize the GCC support for floating-point operations. */
409
410void
411gnat_init_gcc_fp (void)
412{
413 /* Disable FP optimizations that ignore the signedness of zero if
78df6221 414 S'Signed_Zeros is true, but don't override the user if not. */
df09b22c
EB
415 if (Signed_Zeros_On_Target)
416 flag_signed_zeros = 1;
417 else if (!global_options_set.x_flag_signed_zeros)
418 flag_signed_zeros = 0;
419
78df6221 420 /* Assume that FP operations can trap if S'Machine_Overflow is true,
1eb58520
AC
421 but don't override the user if not. */
422 if (Machine_Overflows_On_Target)
df09b22c
EB
423 flag_trapping_math = 1;
424 else if (!global_options_set.x_flag_trapping_math)
425 flag_trapping_math = 0;
426}
427
feec4372 428/* Print language-specific items in declaration NODE. */
a1ab4c31
AC
429
430static void
431gnat_print_decl (FILE *file, tree node, int indent)
432{
433 switch (TREE_CODE (node))
434 {
435 case CONST_DECL:
7635b357 436 print_node (file, "corresponding var",
a1ab4c31
AC
437 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
438 break;
439
440 case FIELD_DECL:
7635b357 441 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
a1ab4c31
AC
442 indent + 4);
443 break;
444
445 case VAR_DECL:
15bf7d19
EB
446 if (DECL_LOOP_PARM_P (node))
447 print_node (file, "induction var", DECL_INDUCTION_VAR (node),
448 indent + 4);
449 else
450 print_node (file, "renamed object", DECL_RENAMED_OBJECT (node),
451 indent + 4);
a1ab4c31
AC
452 break;
453
454 default:
455 break;
456 }
457}
458
feec4372
EB
459/* Print language-specific items in type NODE. */
460
a1ab4c31
AC
461static void
462gnat_print_type (FILE *file, tree node, int indent)
463{
464 switch (TREE_CODE (node))
465 {
466 case FUNCTION_TYPE:
7635b357 467 print_node (file, "ci/co list", TYPE_CI_CO_LIST (node), indent + 4);
a1ab4c31
AC
468 break;
469
a1ab4c31
AC
470 case INTEGER_TYPE:
471 if (TYPE_MODULAR_P (node))
c1abd261 472 print_node_brief (file, "modulus", TYPE_MODULUS (node), indent + 4);
a1ab4c31
AC
473 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
474 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
475 indent + 4);
a1ab4c31
AC
476 else
477 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
478
feec4372
EB
479 /* ... fall through ... */
480
481 case ENUMERAL_TYPE:
482 case BOOLEAN_TYPE:
c1abd261 483 print_node_brief (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
84fb43a1
EB
484
485 /* ... fall through ... */
486
487 case REAL_TYPE:
488 print_node_brief (file, "RM min", TYPE_RM_MIN_VALUE (node), indent + 4);
489 print_node_brief (file, "RM max", TYPE_RM_MAX_VALUE (node), indent + 4);
a1ab4c31
AC
490 break;
491
492 case ARRAY_TYPE:
493 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
494 break;
495
7948ae37
OH
496 case VECTOR_TYPE:
497 print_node (file,"representative array",
498 TYPE_REPRESENTATIVE_ARRAY (node), indent + 4);
499 break;
500
a1ab4c31 501 case RECORD_TYPE:
315cff15 502 if (TYPE_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
a1ab4c31
AC
503 print_node (file, "unconstrained array",
504 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
505 else
506 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
507 break;
508
509 case UNION_TYPE:
510 case QUAL_UNION_TYPE:
511 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
512 break;
513
514 default:
515 break;
516 }
517}
518
feec4372 519/* Return the name to be printed for DECL. */
a1ab4c31
AC
520
521static const char *
522gnat_printable_name (tree decl, int verbosity)
523{
524 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
a9429e29 525 char *ada_name = (char *) ggc_alloc_atomic (strlen (coded_name) * 2 + 60);
a1ab4c31
AC
526
527 __gnat_decode (coded_name, ada_name, 0);
528
10069d53 529 if (verbosity == 2 && !DECL_IS_BUILTIN (decl))
a1ab4c31 530 {
18e6d56a 531 Set_Identifier_Casing (ada_name, DECL_SOURCE_FILE (decl));
baf6e6a8 532 return ggc_strdup (Name_Buffer);
a1ab4c31 533 }
feec4372
EB
534
535 return ada_name;
536}
537
538/* Return the name to be used in DWARF debug info for DECL. */
539
540static const char *
541gnat_dwarf_name (tree decl, int verbosity ATTRIBUTE_UNUSED)
542{
543 gcc_assert (DECL_P (decl));
544 return (const char *) IDENTIFIER_POINTER (DECL_NAME (decl));
a1ab4c31
AC
545}
546
2a9d769a
OH
547/* Return the descriptive type associated with TYPE, if any. */
548
549static tree
550gnat_descriptive_type (const_tree type)
551{
552 if (TYPE_STUB_DECL (type))
553 return DECL_PARALLEL_TYPE (TYPE_STUB_DECL (type));
554 else
555 return NULL_TREE;
556}
557
523e82a7
EB
558/* Return true if types T1 and T2 are identical for type hashing purposes.
559 Called only after doing all language independent checks. At present,
560 this function is only called when both types are FUNCTION_TYPE. */
561
562static bool
563gnat_type_hash_eq (const_tree t1, const_tree t2)
564{
565 gcc_assert (TREE_CODE (t1) == FUNCTION_TYPE);
566 return fntype_same_flags_p (t1, TYPE_CI_CO_LIST (t2),
567 TYPE_RETURN_UNCONSTRAINED_P (t2),
568 TYPE_RETURN_BY_DIRECT_REF_P (t2),
569 TREE_ADDRESSABLE (t2));
570}
571
a1ab4c31
AC
572/* Do nothing (return the tree node passed). */
573
574static tree
575gnat_return_tree (tree t)
576{
577 return t;
578}
579
a1ab4c31
AC
580/* Get the alias set corresponding to a type or expression. */
581
582static alias_set_type
583gnat_get_alias_set (tree type)
584{
585 /* If this is a padding type, use the type of the first field. */
315cff15 586 if (TYPE_IS_PADDING_P (type))
a1ab4c31
AC
587 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
588
589 /* If the type is an unconstrained array, use the type of the
590 self-referential array we make. */
591 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
592 return
593 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
594
595 /* If the type can alias any other types, return the alias set 0. */
f797c2b7 596 else if (TYPE_P (type) && TYPE_UNIVERSAL_ALIASING_P (type))
a1ab4c31
AC
597 return 0;
598
599 return -1;
600}
601
602/* GNU_TYPE is a type. Return its maximum size in bytes, if known,
603 as a constant when possible. */
604
605static tree
606gnat_type_max_size (const_tree gnu_type)
607{
608 /* First see what we can get from TYPE_SIZE_UNIT, which might not
609 be constant even for simple expressions if it has already been
610 elaborated and possibly replaced by a VAR_DECL. */
611 tree max_unitsize = max_size (TYPE_SIZE_UNIT (gnu_type), true);
612
613 /* If we don't have a constant, see what we can get from TYPE_ADA_SIZE,
614 which should stay untouched. */
cc269bb6 615 if (!tree_fits_uhwi_p (max_unitsize)
e1e5852c
EB
616 && RECORD_OR_UNION_TYPE_P (gnu_type)
617 && !TYPE_FAT_POINTER_P (gnu_type)
a1ab4c31
AC
618 && TYPE_ADA_SIZE (gnu_type))
619 {
620 tree max_adasize = max_size (TYPE_ADA_SIZE (gnu_type), true);
621
622 /* If we have succeeded in finding a constant, round it up to the
623 type's alignment and return the result in units. */
cc269bb6 624 if (tree_fits_uhwi_p (max_adasize))
a1ab4c31
AC
625 max_unitsize
626 = size_binop (CEIL_DIV_EXPR,
627 round_up (max_adasize, TYPE_ALIGN (gnu_type)),
628 bitsize_unit_node);
629 }
630
631 return max_unitsize;
632}
633
ce37c297
PMR
634/* Provide information in INFO for debug output about the TYPE array type.
635 Return whether TYPE is handled. */
636
637static bool
638gnat_get_array_descr_info (const_tree type, struct array_descr_info *info)
639{
640 bool convention_fortran_p;
641 tree index_type;
642
643 const_tree dimen = NULL_TREE;
644 const_tree last_dimen = NULL_TREE;
645 int i;
646
647 if (TREE_CODE (type) != ARRAY_TYPE
648 || !TYPE_DOMAIN (type)
649 || !TYPE_INDEX_TYPE (TYPE_DOMAIN (type)))
650 return false;
651
652 /* Count how many dimentions this array has. */
653 for (i = 0, dimen = type; ; ++i, dimen = TREE_TYPE (dimen))
654 if (i > 0
655 && (TREE_CODE (dimen) != ARRAY_TYPE
656 || !TYPE_MULTI_ARRAY_P (dimen)))
657 break;
658 info->ndimensions = i;
659 convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (type);
660
86a8ba5b 661 /* TODO: For row major ordering, we probably want to emit nothing and
ce37c297
PMR
662 instead specify it as the default in Dw_TAG_compile_unit. */
663 info->ordering = (convention_fortran_p
664 ? array_descr_ordering_column_major
665 : array_descr_ordering_row_major);
666 info->base_decl = NULL_TREE;
667 info->data_location = NULL_TREE;
668 info->allocated = NULL_TREE;
669 info->associated = NULL_TREE;
670
671 for (i = (convention_fortran_p ? info->ndimensions - 1 : 0),
672 dimen = type;
673
674 0 <= i && i < info->ndimensions;
675
676 i += (convention_fortran_p ? -1 : 1),
677 dimen = TREE_TYPE (dimen))
678 {
679 /* We are interested in the stored bounds for the debug info. */
680 index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (dimen));
681
682 info->dimen[i].bounds_type = index_type;
683 info->dimen[i].lower_bound = TYPE_MIN_VALUE (index_type);
684 info->dimen[i].upper_bound = TYPE_MAX_VALUE (index_type);
685 last_dimen = dimen;
686 }
687
688 info->element_type = TREE_TYPE (last_dimen);
689
690 return true;
691}
692
84fb43a1
EB
693/* GNU_TYPE is a subtype of an integral type. Set LOWVAL to the low bound
694 and HIGHVAL to the high bound, respectively. */
695
696static void
697gnat_get_subrange_bounds (const_tree gnu_type, tree *lowval, tree *highval)
698{
456976d8
EB
699 *lowval = TYPE_MIN_VALUE (gnu_type);
700 *highval = TYPE_MAX_VALUE (gnu_type);
84fb43a1
EB
701}
702
0c700259
EB
703/* GNU_TYPE is the type of a subprogram parameter. Determine if it should be
704 passed by reference by default. */
a1ab4c31
AC
705
706bool
707default_pass_by_ref (tree gnu_type)
708{
ce3da0d0
EB
709 /* We pass aggregates by reference if they are sufficiently large for
710 their alignment. The ratio is somewhat arbitrary. We also pass by
a1ab4c31
AC
711 reference if the target machine would either pass or return by
712 reference. Strictly speaking, we need only check the return if this
713 is an In Out parameter, but it's probably best to err on the side of
714 passing more things by reference. */
715
0c700259 716 if (pass_by_reference (NULL, TYPE_MODE (gnu_type), gnu_type, true))
a1ab4c31
AC
717 return true;
718
719 if (targetm.calls.return_in_memory (gnu_type, NULL_TREE))
720 return true;
721
722 if (AGGREGATE_TYPE_P (gnu_type)
ce3da0d0
EB
723 && (!valid_constant_size_p (TYPE_SIZE_UNIT (gnu_type))
724 || 0 < compare_tree_int (TYPE_SIZE_UNIT (gnu_type),
725 TYPE_ALIGN (gnu_type))))
a1ab4c31
AC
726 return true;
727
728 return false;
729}
730
0c700259
EB
731/* GNU_TYPE is the type of a subprogram parameter. Determine if it must be
732 passed by reference. */
a1ab4c31
AC
733
734bool
735must_pass_by_ref (tree gnu_type)
736{
737 /* We pass only unconstrained objects, those required by the language
738 to be passed by reference, and objects of variable size. The latter
739 is more efficient, avoids problems with variable size temporaries,
740 and does not produce compatibility problems with C, since C does
741 not have such objects. */
742 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
a0b8b1b7 743 || TYPE_IS_BY_REFERENCE_P (gnu_type)
ce3da0d0
EB
744 || (TYPE_SIZE_UNIT (gnu_type)
745 && TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) != INTEGER_CST));
a1ab4c31
AC
746}
747
002bdd68
AC
748/* This function is called by the front-end to enumerate all the supported
749 modes for the machine, as well as some predefined C types. F is a function
750 which is called back with the parameters as listed below, first a string,
00c5acd3 751 then seven ints. The name is any arbitrary null-terminated string and has
002bdd68
AC
752 no particular significance, except for the case of predefined C types, where
753 it should be the name of the C type. For integer types, only signed types
754 should be listed, unsigned versions are assumed. The order of types should
755 be in order of preference, with the smallest/cheapest types first.
756
757 In particular, C predefined types should be listed before other types,
758 binary floating point types before decimal ones, and narrower/cheaper
759 type versions before more expensive ones. In type selection the first
760 matching variant will be used.
761
762 NAME pointer to first char of type name
763 DIGS number of decimal digits for floating-point modes, else 0
764 COMPLEX_P nonzero is this represents a complex mode
765 COUNT count of number of items, nonzero for vector mode
766 FLOAT_REP Float_Rep_Kind for FP, otherwise undefined
00c5acd3
EB
767 PRECISION number of bits used to store data
768 SIZE number of bits occupied by the mode
002bdd68
AC
769 ALIGN number of bits to which mode is aligned. */
770
771void
00c5acd3 772enumerate_modes (void (*f) (const char *, int, int, int, int, int, int, int))
002bdd68
AC
773{
774 const tree c_types[]
775 = { float_type_node, double_type_node, long_double_type_node };
776 const char *const c_names[]
777 = { "float", "double", "long double" };
778 int iloop;
779
24228312
AC
780 /* We are going to compute it below. */
781 fp_arith_may_widen = false;
782
002bdd68
AC
783 for (iloop = 0; iloop < NUM_MACHINE_MODES; iloop++)
784 {
ef4bddc2
RS
785 machine_mode i = (machine_mode) iloop;
786 machine_mode inner_mode = i;
002bdd68
AC
787 bool float_p = false;
788 bool complex_p = false;
789 bool vector_p = false;
790 bool skip_p = false;
791 int digs = 0;
792 unsigned int nameloop;
793 Float_Rep_Kind float_rep = IEEE_Binary; /* Until proven otherwise */
794
795 switch (GET_MODE_CLASS (i))
796 {
797 case MODE_INT:
798 break;
799 case MODE_FLOAT:
800 float_p = true;
801 break;
802 case MODE_COMPLEX_INT:
803 complex_p = true;
804 inner_mode = GET_MODE_INNER (i);
805 break;
806 case MODE_COMPLEX_FLOAT:
807 float_p = true;
808 complex_p = true;
809 inner_mode = GET_MODE_INNER (i);
810 break;
811 case MODE_VECTOR_INT:
812 vector_p = true;
813 inner_mode = GET_MODE_INNER (i);
814 break;
815 case MODE_VECTOR_FLOAT:
816 float_p = true;
817 vector_p = true;
818 inner_mode = GET_MODE_INNER (i);
819 break;
820 default:
821 skip_p = true;
822 }
823
824 if (float_p)
825 {
826 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
827
56e94186
AC
828 /* ??? Cope with the ghost XFmode of the ARM port. */
829 if (!fmt)
830 continue;
831
24228312
AC
832 /* Be conservative and consider that floating-point arithmetics may
833 use wider intermediate results as soon as there is an extended
834 Motorola or Intel mode supported by the machine. */
835 if (fmt == &ieee_extended_motorola_format
836 || fmt == &ieee_extended_intel_96_format
837 || fmt == &ieee_extended_intel_96_round_53_format
838 || fmt == &ieee_extended_intel_128_format)
c68cdfac
EB
839 {
840#ifdef TARGET_FPMATH_DEFAULT
841 if (TARGET_FPMATH_DEFAULT == FPMATH_387)
842#endif
843 fp_arith_may_widen = true;
844 }
24228312 845
002bdd68
AC
846 if (fmt->b == 2)
847 digs = (fmt->p - 1) * 1233 / 4096; /* scale by log (2) */
848
849 else if (fmt->b == 10)
850 digs = fmt->p;
851
852 else
853 gcc_unreachable();
002bdd68
AC
854 }
855
856 /* First register any C types for this mode that the front end
857 may need to know about, unless the mode should be skipped. */
00c5acd3 858 if (!skip_p && !vector_p)
002bdd68
AC
859 for (nameloop = 0; nameloop < ARRAY_SIZE (c_types); nameloop++)
860 {
00c5acd3
EB
861 tree type = c_types[nameloop];
862 const char *name = c_names[nameloop];
002bdd68 863
00c5acd3 864 if (TYPE_MODE (type) == i)
002bdd68 865 {
00c5acd3
EB
866 f (name, digs, complex_p, 0, float_rep, TYPE_PRECISION (type),
867 TREE_INT_CST_LOW (TYPE_SIZE (type)), TYPE_ALIGN (type));
002bdd68
AC
868 skip_p = true;
869 }
870 }
871
872 /* If no predefined C types were found, register the mode itself. */
002bdd68
AC
873 if (!skip_p)
874 f (GET_MODE_NAME (i), digs, complex_p,
875 vector_p ? GET_MODE_NUNITS (i) : 0, float_rep,
00c5acd3
EB
876 GET_MODE_PRECISION (i), GET_MODE_BITSIZE (i),
877 GET_MODE_ALIGNMENT (i));
002bdd68
AC
878 }
879}
880
feec4372
EB
881/* Return the size of the FP mode with precision PREC. */
882
a1ab4c31
AC
883int
884fp_prec_to_size (int prec)
885{
ef4bddc2 886 machine_mode mode;
a1ab4c31
AC
887
888 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
889 mode = GET_MODE_WIDER_MODE (mode))
890 if (GET_MODE_PRECISION (mode) == prec)
891 return GET_MODE_BITSIZE (mode);
892
893 gcc_unreachable ();
894}
895
feec4372
EB
896/* Return the precision of the FP mode with size SIZE. */
897
a1ab4c31
AC
898int
899fp_size_to_prec (int size)
900{
ef4bddc2 901 machine_mode mode;
a1ab4c31
AC
902
903 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
904 mode = GET_MODE_WIDER_MODE (mode))
905 if (GET_MODE_BITSIZE (mode) == size)
906 return GET_MODE_PRECISION (mode);
907
908 gcc_unreachable ();
909}
f9417da1
RG
910
911static GTY(()) tree gnat_eh_personality_decl;
912
c6282415
EB
913/* Return the GNAT personality function decl. */
914
f9417da1
RG
915static tree
916gnat_eh_personality (void)
917{
918 if (!gnat_eh_personality_decl)
bde8a146 919 gnat_eh_personality_decl = build_personality_function ("gnat");
f9417da1
RG
920 return gnat_eh_personality_decl;
921}
922
81f653d6
NF
923/* Initialize language-specific bits of tree_contains_struct. */
924
925static void
926gnat_init_ts (void)
927{
928 MARK_TS_COMMON (UNCONSTRAINED_ARRAY_TYPE);
929
930 MARK_TS_TYPED (UNCONSTRAINED_ARRAY_REF);
931 MARK_TS_TYPED (NULL_EXPR);
932 MARK_TS_TYPED (PLUS_NOMOD_EXPR);
933 MARK_TS_TYPED (MINUS_NOMOD_EXPR);
934 MARK_TS_TYPED (ATTR_ADDR_EXPR);
935 MARK_TS_TYPED (STMT_STMT);
936 MARK_TS_TYPED (LOOP_STMT);
937 MARK_TS_TYPED (EXIT_STMT);
938}
939
c6282415
EB
940/* Definitions for our language-specific hooks. */
941
942#undef LANG_HOOKS_NAME
943#define LANG_HOOKS_NAME "GNU Ada"
944#undef LANG_HOOKS_IDENTIFIER_SIZE
945#define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
946#undef LANG_HOOKS_INIT
947#define LANG_HOOKS_INIT gnat_init
948#undef LANG_HOOKS_OPTION_LANG_MASK
949#define LANG_HOOKS_OPTION_LANG_MASK gnat_option_lang_mask
950#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
951#define LANG_HOOKS_INIT_OPTIONS_STRUCT gnat_init_options_struct
952#undef LANG_HOOKS_INIT_OPTIONS
953#define LANG_HOOKS_INIT_OPTIONS gnat_init_options
954#undef LANG_HOOKS_HANDLE_OPTION
955#define LANG_HOOKS_HANDLE_OPTION gnat_handle_option
956#undef LANG_HOOKS_POST_OPTIONS
957#define LANG_HOOKS_POST_OPTIONS gnat_post_options
958#undef LANG_HOOKS_PARSE_FILE
959#define LANG_HOOKS_PARSE_FILE gnat_parse_file
960#undef LANG_HOOKS_TYPE_HASH_EQ
961#define LANG_HOOKS_TYPE_HASH_EQ gnat_type_hash_eq
962#undef LANG_HOOKS_GETDECLS
963#define LANG_HOOKS_GETDECLS lhd_return_null_tree_v
964#undef LANG_HOOKS_PUSHDECL
965#define LANG_HOOKS_PUSHDECL gnat_return_tree
c6282415
EB
966#undef LANG_HOOKS_GET_ALIAS_SET
967#define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
968#undef LANG_HOOKS_PRINT_DECL
969#define LANG_HOOKS_PRINT_DECL gnat_print_decl
970#undef LANG_HOOKS_PRINT_TYPE
971#define LANG_HOOKS_PRINT_TYPE gnat_print_type
972#undef LANG_HOOKS_TYPE_MAX_SIZE
973#define LANG_HOOKS_TYPE_MAX_SIZE gnat_type_max_size
974#undef LANG_HOOKS_DECL_PRINTABLE_NAME
975#define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
976#undef LANG_HOOKS_DWARF_NAME
977#define LANG_HOOKS_DWARF_NAME gnat_dwarf_name
978#undef LANG_HOOKS_GIMPLIFY_EXPR
979#define LANG_HOOKS_GIMPLIFY_EXPR gnat_gimplify_expr
980#undef LANG_HOOKS_TYPE_FOR_MODE
981#define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
982#undef LANG_HOOKS_TYPE_FOR_SIZE
983#define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
984#undef LANG_HOOKS_TYPES_COMPATIBLE_P
985#define LANG_HOOKS_TYPES_COMPATIBLE_P gnat_types_compatible_p
ce37c297
PMR
986#undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
987#define LANG_HOOKS_GET_ARRAY_DESCR_INFO gnat_get_array_descr_info
c6282415
EB
988#undef LANG_HOOKS_GET_SUBRANGE_BOUNDS
989#define LANG_HOOKS_GET_SUBRANGE_BOUNDS gnat_get_subrange_bounds
2a9d769a
OH
990#undef LANG_HOOKS_DESCRIPTIVE_TYPE
991#define LANG_HOOKS_DESCRIPTIVE_TYPE gnat_descriptive_type
c6282415
EB
992#undef LANG_HOOKS_ATTRIBUTE_TABLE
993#define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table
994#undef LANG_HOOKS_BUILTIN_FUNCTION
995#define LANG_HOOKS_BUILTIN_FUNCTION gnat_builtin_function
996#undef LANG_HOOKS_EH_PERSONALITY
997#define LANG_HOOKS_EH_PERSONALITY gnat_eh_personality
998#undef LANG_HOOKS_DEEP_UNSHARING
999#define LANG_HOOKS_DEEP_UNSHARING true
81f653d6
NF
1000#undef LANG_HOOKS_INIT_TS
1001#define LANG_HOOKS_INIT_TS gnat_init_ts
034e7d49
EB
1002#undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
1003#define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL hook_bool_const_tree_false
c6282415
EB
1004
1005struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1006
f9417da1 1007#include "gt-ada-misc.h"