]>
Commit | Line | Data |
---|---|---|
a1ab4c31 AC |
1 | /**************************************************************************** |
2 | * * | |
3 | * GNAT COMPILER COMPONENTS * | |
4 | * * | |
5 | * U T I L S * | |
6 | * * | |
7 | * C Implementation File * | |
8 | * * | |
88a94e2b | 9 | * Copyright (C) 1992-2012, 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- * | |
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 along with GCC; see the 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 | ||
a1ab4c31 AC |
26 | #include "config.h" |
27 | #include "system.h" | |
28 | #include "coretypes.h" | |
29 | #include "tm.h" | |
30 | #include "tree.h" | |
31 | #include "flags.h" | |
a1ab4c31 | 32 | #include "toplev.h" |
718f9c0f | 33 | #include "diagnostic-core.h" |
a1ab4c31 AC |
34 | #include "output.h" |
35 | #include "ggc.h" | |
36 | #include "debug.h" | |
37 | #include "convert.h" | |
38 | #include "target.h" | |
677f3fa8 | 39 | #include "common/common-target.h" |
8713b7e4 | 40 | #include "langhooks.h" |
a1ab4c31 | 41 | #include "cgraph.h" |
10e4d056 | 42 | #include "diagnostic.h" |
8713b7e4 | 43 | #include "tree-dump.h" |
a1ab4c31 AC |
44 | #include "tree-inline.h" |
45 | #include "tree-iterator.h" | |
a1ab4c31 AC |
46 | |
47 | #include "ada.h" | |
48 | #include "types.h" | |
49 | #include "atree.h" | |
50 | #include "elists.h" | |
51 | #include "namet.h" | |
52 | #include "nlists.h" | |
53 | #include "stringt.h" | |
54 | #include "uintp.h" | |
55 | #include "fe.h" | |
56 | #include "sinfo.h" | |
57 | #include "einfo.h" | |
58 | #include "ada-tree.h" | |
59 | #include "gigi.h" | |
60 | ||
a1ab4c31 AC |
61 | #ifndef MAX_BITS_PER_WORD |
62 | #define MAX_BITS_PER_WORD BITS_PER_WORD | |
63 | #endif | |
64 | ||
65 | /* If nonzero, pretend we are allocating at global level. */ | |
66 | int force_global; | |
67 | ||
caa9d12a EB |
68 | /* The default alignment of "double" floating-point types, i.e. floating |
69 | point types whose size is equal to 64 bits, or 0 if this alignment is | |
70 | not specifically capped. */ | |
71 | int double_float_alignment; | |
72 | ||
73 | /* The default alignment of "double" or larger scalar types, i.e. scalar | |
74 | types whose size is greater or equal to 64 bits, or 0 if this alignment | |
75 | is not specifically capped. */ | |
76 | int double_scalar_alignment; | |
77 | ||
a1ab4c31 AC |
78 | /* Tree nodes for the various types and decls we create. */ |
79 | tree gnat_std_decls[(int) ADT_LAST]; | |
80 | ||
81 | /* Functions to call for each of the possible raise reasons. */ | |
82 | tree gnat_raise_decls[(int) LAST_REASON_CODE + 1]; | |
83 | ||
ca8e13e8 | 84 | /* Likewise, but with extra info for each of the possible raise reasons. */ |
437f8c1e AC |
85 | tree gnat_raise_decls_ext[(int) LAST_REASON_CODE + 1]; |
86 | ||
a1ab4c31 AC |
87 | /* Forward declarations for handlers of attributes. */ |
88 | static tree handle_const_attribute (tree *, tree, tree, int, bool *); | |
89 | static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *); | |
90 | static tree handle_pure_attribute (tree *, tree, tree, int, bool *); | |
91 | static tree handle_novops_attribute (tree *, tree, tree, int, bool *); | |
92 | static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *); | |
93 | static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *); | |
94 | static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *); | |
0d6e14fd | 95 | static tree handle_leaf_attribute (tree *, tree, tree, int, bool *); |
a1ab4c31 AC |
96 | static tree handle_malloc_attribute (tree *, tree, tree, int, bool *); |
97 | static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); | |
2724e58f | 98 | static tree handle_vector_size_attribute (tree *, tree, tree, int, bool *); |
7948ae37 | 99 | static tree handle_vector_type_attribute (tree *, tree, tree, int, bool *); |
a1ab4c31 AC |
100 | |
101 | /* Fake handler for attributes we don't properly support, typically because | |
102 | they'd require dragging a lot of the common-c front-end circuitry. */ | |
103 | static tree fake_attribute_handler (tree *, tree, tree, int, bool *); | |
104 | ||
105 | /* Table of machine-independent internal attributes for Ada. We support | |
106 | this minimal set of attributes to accommodate the needs of builtins. */ | |
107 | const struct attribute_spec gnat_internal_attribute_table[] = | |
108 | { | |
62d784f7 KT |
109 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, |
110 | affects_type_identity } */ | |
111 | { "const", 0, 0, true, false, false, handle_const_attribute, | |
112 | false }, | |
113 | { "nothrow", 0, 0, true, false, false, handle_nothrow_attribute, | |
114 | false }, | |
115 | { "pure", 0, 0, true, false, false, handle_pure_attribute, | |
116 | false }, | |
117 | { "no vops", 0, 0, true, false, false, handle_novops_attribute, | |
118 | false }, | |
119 | { "nonnull", 0, -1, false, true, true, handle_nonnull_attribute, | |
120 | false }, | |
121 | { "sentinel", 0, 1, false, true, true, handle_sentinel_attribute, | |
122 | false }, | |
123 | { "noreturn", 0, 0, true, false, false, handle_noreturn_attribute, | |
124 | false }, | |
125 | { "leaf", 0, 0, true, false, false, handle_leaf_attribute, | |
126 | false }, | |
127 | { "malloc", 0, 0, true, false, false, handle_malloc_attribute, | |
128 | false }, | |
129 | { "type generic", 0, 0, false, true, true, handle_type_generic_attribute, | |
130 | false }, | |
131 | ||
132 | { "vector_size", 1, 1, false, true, false, handle_vector_size_attribute, | |
133 | false }, | |
134 | { "vector_type", 0, 0, false, true, false, handle_vector_type_attribute, | |
135 | false }, | |
136 | { "may_alias", 0, 0, false, true, false, NULL, false }, | |
a1ab4c31 AC |
137 | |
138 | /* ??? format and format_arg are heavy and not supported, which actually | |
139 | prevents support for stdio builtins, which we however declare as part | |
140 | of the common builtins.def contents. */ | |
62d784f7 KT |
141 | { "format", 3, 3, false, true, true, fake_attribute_handler, false }, |
142 | { "format_arg", 1, 1, false, true, true, fake_attribute_handler, false }, | |
a1ab4c31 | 143 | |
62d784f7 | 144 | { NULL, 0, 0, false, false, false, NULL, false } |
a1ab4c31 AC |
145 | }; |
146 | ||
147 | /* Associates a GNAT tree node to a GCC tree node. It is used in | |
148 | `save_gnu_tree', `get_gnu_tree' and `present_gnu_tree'. See documentation | |
149 | of `save_gnu_tree' for more info. */ | |
150 | static GTY((length ("max_gnat_nodes"))) tree *associate_gnat_to_gnu; | |
151 | ||
152 | #define GET_GNU_TREE(GNAT_ENTITY) \ | |
153 | associate_gnat_to_gnu[(GNAT_ENTITY) - First_Node_Id] | |
154 | ||
155 | #define SET_GNU_TREE(GNAT_ENTITY,VAL) \ | |
156 | associate_gnat_to_gnu[(GNAT_ENTITY) - First_Node_Id] = (VAL) | |
157 | ||
158 | #define PRESENT_GNU_TREE(GNAT_ENTITY) \ | |
159 | (associate_gnat_to_gnu[(GNAT_ENTITY) - First_Node_Id] != NULL_TREE) | |
160 | ||
161 | /* Associates a GNAT entity to a GCC tree node used as a dummy, if any. */ | |
162 | static GTY((length ("max_gnat_nodes"))) tree *dummy_node_table; | |
163 | ||
164 | #define GET_DUMMY_NODE(GNAT_ENTITY) \ | |
165 | dummy_node_table[(GNAT_ENTITY) - First_Node_Id] | |
166 | ||
167 | #define SET_DUMMY_NODE(GNAT_ENTITY,VAL) \ | |
168 | dummy_node_table[(GNAT_ENTITY) - First_Node_Id] = (VAL) | |
169 | ||
170 | #define PRESENT_DUMMY_NODE(GNAT_ENTITY) \ | |
171 | (dummy_node_table[(GNAT_ENTITY) - First_Node_Id] != NULL_TREE) | |
172 | ||
173 | /* This variable keeps a table for types for each precision so that we only | |
174 | allocate each of them once. Signed and unsigned types are kept separate. | |
175 | ||
176 | Note that these types are only used when fold-const requests something | |
177 | special. Perhaps we should NOT share these types; we'll see how it | |
178 | goes later. */ | |
179 | static GTY(()) tree signed_and_unsigned_types[2 * MAX_BITS_PER_WORD + 1][2]; | |
180 | ||
181 | /* Likewise for float types, but record these by mode. */ | |
182 | static GTY(()) tree float_types[NUM_MACHINE_MODES]; | |
183 | ||
184 | /* For each binding contour we allocate a binding_level structure to indicate | |
185 | the binding depth. */ | |
186 | ||
d1b38208 | 187 | struct GTY((chain_next ("%h.chain"))) gnat_binding_level { |
a1ab4c31 AC |
188 | /* The binding level containing this one (the enclosing binding level). */ |
189 | struct gnat_binding_level *chain; | |
190 | /* The BLOCK node for this level. */ | |
191 | tree block; | |
192 | /* If nonzero, the setjmp buffer that needs to be updated for any | |
193 | variable-sized definition within this context. */ | |
194 | tree jmpbuf_decl; | |
195 | }; | |
196 | ||
197 | /* The binding level currently in effect. */ | |
198 | static GTY(()) struct gnat_binding_level *current_binding_level; | |
199 | ||
200 | /* A chain of gnat_binding_level structures awaiting reuse. */ | |
201 | static GTY((deletable)) struct gnat_binding_level *free_binding_level; | |
202 | ||
228ee426 EB |
203 | /* The context to be used for global declarations. */ |
204 | static GTY(()) tree global_context; | |
205 | ||
a1ab4c31 AC |
206 | /* An array of global declarations. */ |
207 | static GTY(()) VEC(tree,gc) *global_decls; | |
208 | ||
209 | /* An array of builtin function declarations. */ | |
210 | static GTY(()) VEC(tree,gc) *builtin_decls; | |
211 | ||
212 | /* An array of global renaming pointers. */ | |
213 | static GTY(()) VEC(tree,gc) *global_renaming_pointers; | |
214 | ||
215 | /* A chain of unused BLOCK nodes. */ | |
216 | static GTY((deletable)) tree free_block_chain; | |
217 | ||
a1ab4c31 AC |
218 | static tree merge_sizes (tree, tree, tree, bool, bool); |
219 | static tree compute_related_constant (tree, tree); | |
220 | static tree split_plus (tree, tree *); | |
a1ab4c31 AC |
221 | static tree float_type_for_precision (int, enum machine_mode); |
222 | static tree convert_to_fat_pointer (tree, tree); | |
a1ab4c31 | 223 | static bool potential_alignment_gap (tree, tree, tree); |
58c8f770 | 224 | static void process_attributes (tree, struct attrib *); |
a1ab4c31 AC |
225 | \f |
226 | /* Initialize the association of GNAT nodes to GCC trees. */ | |
227 | ||
228 | void | |
229 | init_gnat_to_gnu (void) | |
230 | { | |
a9429e29 | 231 | associate_gnat_to_gnu = ggc_alloc_cleared_vec_tree (max_gnat_nodes); |
a1ab4c31 AC |
232 | } |
233 | ||
a1d8cc63 EB |
234 | /* GNAT_ENTITY is a GNAT tree node for an entity. Associate GNU_DECL, a GCC |
235 | tree node, with GNAT_ENTITY. If GNU_DECL is not a ..._DECL node, abort. | |
236 | If NO_CHECK is true, the latter check is suppressed. | |
a1ab4c31 | 237 | |
a1d8cc63 | 238 | If GNU_DECL is zero, reset a previous association. */ |
a1ab4c31 AC |
239 | |
240 | void | |
241 | save_gnu_tree (Entity_Id gnat_entity, tree gnu_decl, bool no_check) | |
242 | { | |
243 | /* Check that GNAT_ENTITY is not already defined and that it is being set | |
a1d8cc63 | 244 | to something which is a decl. If that is not the case, this usually |
a1ab4c31 AC |
245 | means GNAT_ENTITY is defined twice, but occasionally is due to some |
246 | Gigi problem. */ | |
247 | gcc_assert (!(gnu_decl | |
248 | && (PRESENT_GNU_TREE (gnat_entity) | |
249 | || (!no_check && !DECL_P (gnu_decl))))); | |
250 | ||
251 | SET_GNU_TREE (gnat_entity, gnu_decl); | |
252 | } | |
253 | ||
a1d8cc63 EB |
254 | /* GNAT_ENTITY is a GNAT tree node for an entity. Return the GCC tree node |
255 | that was associated with it. If there is no such tree node, abort. | |
a1ab4c31 AC |
256 | |
257 | In some cases, such as delayed elaboration or expressions that need to | |
258 | be elaborated only once, GNAT_ENTITY is really not an entity. */ | |
259 | ||
260 | tree | |
261 | get_gnu_tree (Entity_Id gnat_entity) | |
262 | { | |
263 | gcc_assert (PRESENT_GNU_TREE (gnat_entity)); | |
264 | return GET_GNU_TREE (gnat_entity); | |
265 | } | |
266 | ||
267 | /* Return nonzero if a GCC tree has been associated with GNAT_ENTITY. */ | |
268 | ||
269 | bool | |
270 | present_gnu_tree (Entity_Id gnat_entity) | |
271 | { | |
272 | return PRESENT_GNU_TREE (gnat_entity); | |
273 | } | |
274 | \f | |
275 | /* Initialize the association of GNAT nodes to GCC trees as dummies. */ | |
276 | ||
277 | void | |
278 | init_dummy_type (void) | |
279 | { | |
a9429e29 | 280 | dummy_node_table = ggc_alloc_cleared_vec_tree (max_gnat_nodes); |
a1ab4c31 AC |
281 | } |
282 | ||
283 | /* Make a dummy type corresponding to GNAT_TYPE. */ | |
284 | ||
285 | tree | |
286 | make_dummy_type (Entity_Id gnat_type) | |
287 | { | |
288 | Entity_Id gnat_underlying = Gigi_Equivalent_Type (gnat_type); | |
289 | tree gnu_type; | |
290 | ||
291 | /* If there is an equivalent type, get its underlying type. */ | |
292 | if (Present (gnat_underlying)) | |
a0b8b1b7 | 293 | gnat_underlying = Gigi_Equivalent_Type (Underlying_Type (gnat_underlying)); |
a1ab4c31 AC |
294 | |
295 | /* If there was no equivalent type (can only happen when just annotating | |
296 | types) or underlying type, go back to the original type. */ | |
297 | if (No (gnat_underlying)) | |
298 | gnat_underlying = gnat_type; | |
299 | ||
300 | /* If it there already a dummy type, use that one. Else make one. */ | |
301 | if (PRESENT_DUMMY_NODE (gnat_underlying)) | |
302 | return GET_DUMMY_NODE (gnat_underlying); | |
303 | ||
304 | /* If this is a record, make a RECORD_TYPE or UNION_TYPE; else make | |
305 | an ENUMERAL_TYPE. */ | |
306 | gnu_type = make_node (Is_Record_Type (gnat_underlying) | |
307 | ? tree_code_for_record_type (gnat_underlying) | |
308 | : ENUMERAL_TYPE); | |
309 | TYPE_NAME (gnu_type) = get_entity_name (gnat_type); | |
310 | TYPE_DUMMY_P (gnu_type) = 1; | |
10069d53 EB |
311 | TYPE_STUB_DECL (gnu_type) |
312 | = create_type_stub_decl (TYPE_NAME (gnu_type), gnu_type); | |
a0b8b1b7 EB |
313 | if (Is_By_Reference_Type (gnat_underlying)) |
314 | TYPE_BY_REFERENCE_P (gnu_type) = 1; | |
a1ab4c31 AC |
315 | |
316 | SET_DUMMY_NODE (gnat_underlying, gnu_type); | |
317 | ||
318 | return gnu_type; | |
319 | } | |
e3edbd56 EB |
320 | |
321 | /* Return the dummy type that was made for GNAT_TYPE, if any. */ | |
322 | ||
323 | tree | |
324 | get_dummy_type (Entity_Id gnat_type) | |
325 | { | |
326 | return GET_DUMMY_NODE (gnat_type); | |
327 | } | |
328 | ||
329 | /* Build dummy fat and thin pointer types whose designated type is specified | |
330 | by GNAT_DESIG_TYPE/GNU_DESIG_TYPE and attach them to the latter. */ | |
331 | ||
332 | void | |
333 | build_dummy_unc_pointer_types (Entity_Id gnat_desig_type, tree gnu_desig_type) | |
334 | { | |
335 | tree gnu_template_type, gnu_ptr_template, gnu_array_type, gnu_ptr_array; | |
336 | tree gnu_fat_type, fields, gnu_object_type; | |
337 | ||
338 | gnu_template_type = make_node (RECORD_TYPE); | |
339 | TYPE_NAME (gnu_template_type) = create_concat_name (gnat_desig_type, "XUB"); | |
340 | TYPE_DUMMY_P (gnu_template_type) = 1; | |
341 | gnu_ptr_template = build_pointer_type (gnu_template_type); | |
342 | ||
343 | gnu_array_type = make_node (ENUMERAL_TYPE); | |
344 | TYPE_NAME (gnu_array_type) = create_concat_name (gnat_desig_type, "XUA"); | |
345 | TYPE_DUMMY_P (gnu_array_type) = 1; | |
346 | gnu_ptr_array = build_pointer_type (gnu_array_type); | |
347 | ||
348 | gnu_fat_type = make_node (RECORD_TYPE); | |
349 | /* Build a stub DECL to trigger the special processing for fat pointer types | |
350 | in gnat_pushdecl. */ | |
351 | TYPE_NAME (gnu_fat_type) | |
352 | = create_type_stub_decl (create_concat_name (gnat_desig_type, "XUP"), | |
353 | gnu_fat_type); | |
354 | fields = create_field_decl (get_identifier ("P_ARRAY"), gnu_ptr_array, | |
355 | gnu_fat_type, NULL_TREE, NULL_TREE, 0, 0); | |
356 | DECL_CHAIN (fields) | |
357 | = create_field_decl (get_identifier ("P_BOUNDS"), gnu_ptr_template, | |
358 | gnu_fat_type, NULL_TREE, NULL_TREE, 0, 0); | |
359 | finish_fat_pointer_type (gnu_fat_type, fields); | |
360 | SET_TYPE_UNCONSTRAINED_ARRAY (gnu_fat_type, gnu_desig_type); | |
361 | /* Suppress debug info until after the type is completed. */ | |
362 | TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (gnu_fat_type)) = 1; | |
363 | ||
364 | gnu_object_type = make_node (RECORD_TYPE); | |
365 | TYPE_NAME (gnu_object_type) = create_concat_name (gnat_desig_type, "XUT"); | |
366 | TYPE_DUMMY_P (gnu_object_type) = 1; | |
367 | ||
368 | TYPE_POINTER_TO (gnu_desig_type) = gnu_fat_type; | |
369 | TYPE_OBJECT_RECORD_TYPE (gnu_desig_type) = gnu_object_type; | |
370 | } | |
a1ab4c31 | 371 | \f |
c99c0026 | 372 | /* Return true if we are in the global binding level. */ |
a1ab4c31 | 373 | |
c99c0026 | 374 | bool |
a1ab4c31 AC |
375 | global_bindings_p (void) |
376 | { | |
c99c0026 | 377 | return force_global || current_function_decl == NULL_TREE; |
a1ab4c31 AC |
378 | } |
379 | ||
a09d56d8 | 380 | /* Enter a new binding level. */ |
a1ab4c31 AC |
381 | |
382 | void | |
c6bd4220 | 383 | gnat_pushlevel (void) |
a1ab4c31 AC |
384 | { |
385 | struct gnat_binding_level *newlevel = NULL; | |
386 | ||
387 | /* Reuse a struct for this binding level, if there is one. */ | |
388 | if (free_binding_level) | |
389 | { | |
390 | newlevel = free_binding_level; | |
391 | free_binding_level = free_binding_level->chain; | |
392 | } | |
393 | else | |
a9429e29 | 394 | newlevel = ggc_alloc_gnat_binding_level (); |
a1ab4c31 AC |
395 | |
396 | /* Use a free BLOCK, if any; otherwise, allocate one. */ | |
397 | if (free_block_chain) | |
398 | { | |
399 | newlevel->block = free_block_chain; | |
400 | free_block_chain = BLOCK_CHAIN (free_block_chain); | |
401 | BLOCK_CHAIN (newlevel->block) = NULL_TREE; | |
402 | } | |
403 | else | |
404 | newlevel->block = make_node (BLOCK); | |
405 | ||
406 | /* Point the BLOCK we just made to its parent. */ | |
407 | if (current_binding_level) | |
408 | BLOCK_SUPERCONTEXT (newlevel->block) = current_binding_level->block; | |
409 | ||
a09d56d8 EB |
410 | BLOCK_VARS (newlevel->block) = NULL_TREE; |
411 | BLOCK_SUBBLOCKS (newlevel->block) = NULL_TREE; | |
a1ab4c31 AC |
412 | TREE_USED (newlevel->block) = 1; |
413 | ||
a09d56d8 | 414 | /* Add this level to the front of the chain (stack) of active levels. */ |
a1ab4c31 AC |
415 | newlevel->chain = current_binding_level; |
416 | newlevel->jmpbuf_decl = NULL_TREE; | |
417 | current_binding_level = newlevel; | |
418 | } | |
419 | ||
420 | /* Set SUPERCONTEXT of the BLOCK for the current binding level to FNDECL | |
421 | and point FNDECL to this BLOCK. */ | |
422 | ||
423 | void | |
424 | set_current_block_context (tree fndecl) | |
425 | { | |
426 | BLOCK_SUPERCONTEXT (current_binding_level->block) = fndecl; | |
427 | DECL_INITIAL (fndecl) = current_binding_level->block; | |
a09d56d8 | 428 | set_block_for_group (current_binding_level->block); |
a1ab4c31 AC |
429 | } |
430 | ||
431 | /* Set the jmpbuf_decl for the current binding level to DECL. */ | |
432 | ||
433 | void | |
434 | set_block_jmpbuf_decl (tree decl) | |
435 | { | |
436 | current_binding_level->jmpbuf_decl = decl; | |
437 | } | |
438 | ||
439 | /* Get the jmpbuf_decl, if any, for the current binding level. */ | |
440 | ||
441 | tree | |
c6bd4220 | 442 | get_block_jmpbuf_decl (void) |
a1ab4c31 AC |
443 | { |
444 | return current_binding_level->jmpbuf_decl; | |
445 | } | |
446 | ||
a09d56d8 | 447 | /* Exit a binding level. Set any BLOCK into the current code group. */ |
a1ab4c31 AC |
448 | |
449 | void | |
c6bd4220 | 450 | gnat_poplevel (void) |
a1ab4c31 AC |
451 | { |
452 | struct gnat_binding_level *level = current_binding_level; | |
453 | tree block = level->block; | |
454 | ||
455 | BLOCK_VARS (block) = nreverse (BLOCK_VARS (block)); | |
72ac05b0 | 456 | BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block)); |
a1ab4c31 AC |
457 | |
458 | /* If this is a function-level BLOCK don't do anything. Otherwise, if there | |
459 | are no variables free the block and merge its subblocks into those of its | |
a09d56d8 | 460 | parent block. Otherwise, add it to the list of its parent. */ |
a1ab4c31 AC |
461 | if (TREE_CODE (BLOCK_SUPERCONTEXT (block)) == FUNCTION_DECL) |
462 | ; | |
463 | else if (BLOCK_VARS (block) == NULL_TREE) | |
464 | { | |
465 | BLOCK_SUBBLOCKS (level->chain->block) | |
61e46a7d NF |
466 | = block_chainon (BLOCK_SUBBLOCKS (block), |
467 | BLOCK_SUBBLOCKS (level->chain->block)); | |
a1ab4c31 AC |
468 | BLOCK_CHAIN (block) = free_block_chain; |
469 | free_block_chain = block; | |
470 | } | |
471 | else | |
472 | { | |
473 | BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (level->chain->block); | |
474 | BLOCK_SUBBLOCKS (level->chain->block) = block; | |
475 | TREE_USED (block) = 1; | |
476 | set_block_for_group (block); | |
477 | } | |
478 | ||
479 | /* Free this binding structure. */ | |
480 | current_binding_level = level->chain; | |
481 | level->chain = free_binding_level; | |
482 | free_binding_level = level; | |
483 | } | |
484 | ||
2231f17f EB |
485 | /* Exit a binding level and discard the associated BLOCK. */ |
486 | ||
487 | void | |
488 | gnat_zaplevel (void) | |
489 | { | |
490 | struct gnat_binding_level *level = current_binding_level; | |
491 | tree block = level->block; | |
492 | ||
493 | BLOCK_CHAIN (block) = free_block_chain; | |
494 | free_block_chain = block; | |
495 | ||
496 | /* Free this binding structure. */ | |
497 | current_binding_level = level->chain; | |
498 | level->chain = free_binding_level; | |
499 | free_binding_level = level; | |
500 | } | |
a1ab4c31 | 501 | \f |
228ee426 EB |
502 | /* Record DECL as belonging to the current lexical scope and use GNAT_NODE |
503 | for location information and flag propagation. */ | |
a1ab4c31 AC |
504 | |
505 | void | |
506 | gnat_pushdecl (tree decl, Node_Id gnat_node) | |
507 | { | |
228ee426 | 508 | /* If DECL is public external or at top level, it has global context. */ |
bd9c7fb9 | 509 | if ((TREE_PUBLIC (decl) && DECL_EXTERNAL (decl)) || global_bindings_p ()) |
228ee426 EB |
510 | { |
511 | if (!global_context) | |
512 | global_context = build_translation_unit_decl (NULL_TREE); | |
513 | DECL_CONTEXT (decl) = global_context; | |
514 | } | |
a1ab4c31 AC |
515 | else |
516 | { | |
517 | DECL_CONTEXT (decl) = current_function_decl; | |
518 | ||
9f62cb92 JJ |
519 | /* Functions imported in another function are not really nested. |
520 | For really nested functions mark them initially as needing | |
521 | a static chain for uses of that flag before unnesting; | |
522 | lower_nested_functions will then recompute it. */ | |
523 | if (TREE_CODE (decl) == FUNCTION_DECL && !TREE_PUBLIC (decl)) | |
524 | DECL_STATIC_CHAIN (decl) = 1; | |
a1ab4c31 AC |
525 | } |
526 | ||
228ee426 | 527 | TREE_NO_WARNING (decl) = (No (gnat_node) || Warnings_Off (gnat_node)); |
a1ab4c31 AC |
528 | |
529 | /* Set the location of DECL and emit a declaration for it. */ | |
530 | if (Present (gnat_node)) | |
531 | Sloc_to_locus (Sloc (gnat_node), &DECL_SOURCE_LOCATION (decl)); | |
228ee426 | 532 | |
a1ab4c31 AC |
533 | add_decl_expr (decl, gnat_node); |
534 | ||
535 | /* Put the declaration on the list. The list of declarations is in reverse | |
2231f17f EB |
536 | order. The list will be reversed later. Put global declarations in the |
537 | globals list and local ones in the current block. But skip TYPE_DECLs | |
538 | for UNCONSTRAINED_ARRAY_TYPE in both cases, as they will cause trouble | |
539 | with the debugger and aren't needed anyway. */ | |
540 | if (!(TREE_CODE (decl) == TYPE_DECL | |
541 | && TREE_CODE (TREE_TYPE (decl)) == UNCONSTRAINED_ARRAY_TYPE)) | |
a1ab4c31 AC |
542 | { |
543 | if (global_bindings_p ()) | |
544 | { | |
545 | VEC_safe_push (tree, gc, global_decls, decl); | |
546 | ||
547 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)) | |
548 | VEC_safe_push (tree, gc, builtin_decls, decl); | |
549 | } | |
2231f17f | 550 | else if (!DECL_EXTERNAL (decl)) |
a1ab4c31 | 551 | { |
a963da4d EB |
552 | DECL_CHAIN (decl) = BLOCK_VARS (current_binding_level->block); |
553 | BLOCK_VARS (current_binding_level->block) = decl; | |
a1ab4c31 AC |
554 | } |
555 | } | |
556 | ||
557 | /* For the declaration of a type, set its name if it either is not already | |
10069d53 | 558 | set or if the previous type name was not derived from a source name. |
a1ab4c31 AC |
559 | We'd rather have the type named with a real name and all the pointer |
560 | types to the same object have the same POINTER_TYPE node. Code in the | |
561 | equivalent function of c-decl.c makes a copy of the type node here, but | |
562 | that may cause us trouble with incomplete types. We make an exception | |
563 | for fat pointer types because the compiler automatically builds them | |
564 | for unconstrained array types and the debugger uses them to represent | |
565 | both these and pointers to these. */ | |
566 | if (TREE_CODE (decl) == TYPE_DECL && DECL_NAME (decl)) | |
567 | { | |
568 | tree t = TREE_TYPE (decl); | |
569 | ||
10069d53 | 570 | if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)) |
1aeb40dd | 571 | { |
4cb12a90 | 572 | /* Array and pointer types aren't "tagged" types so we force the |
1aeb40dd EB |
573 | type to be associated with its typedef in the DWARF back-end, |
574 | in order to make sure that the latter is always preserved. */ | |
4cb12a90 EB |
575 | if (!DECL_ARTIFICIAL (decl) |
576 | && (TREE_CODE (t) == ARRAY_TYPE | |
577 | || TREE_CODE (t) == POINTER_TYPE)) | |
1aeb40dd EB |
578 | { |
579 | tree tt = build_distinct_type_copy (t); | |
4cb12a90 EB |
580 | if (TREE_CODE (t) == POINTER_TYPE) |
581 | TYPE_NEXT_PTR_TO (t) = tt; | |
1aeb40dd EB |
582 | TYPE_NAME (tt) = DECL_NAME (decl); |
583 | TYPE_STUB_DECL (tt) = TYPE_STUB_DECL (t); | |
584 | DECL_ORIGINAL_TYPE (decl) = tt; | |
585 | } | |
586 | } | |
315cff15 | 587 | else if (TYPE_IS_FAT_POINTER_P (t)) |
a1ab4c31 | 588 | { |
e3edbd56 | 589 | /* We need a variant for the placeholder machinery to work. */ |
a1ab4c31 AC |
590 | tree tt = build_variant_type_copy (t); |
591 | TYPE_NAME (tt) = decl; | |
592 | TREE_USED (tt) = TREE_USED (t); | |
593 | TREE_TYPE (decl) = tt; | |
40c88b94 EB |
594 | if (DECL_ORIGINAL_TYPE (TYPE_NAME (t))) |
595 | DECL_ORIGINAL_TYPE (decl) = DECL_ORIGINAL_TYPE (TYPE_NAME (t)); | |
596 | else | |
597 | DECL_ORIGINAL_TYPE (decl) = t; | |
40c88b94 | 598 | DECL_ARTIFICIAL (decl) = 0; |
e3edbd56 | 599 | t = NULL_TREE; |
a1ab4c31 AC |
600 | } |
601 | else if (DECL_ARTIFICIAL (TYPE_NAME (t)) && !DECL_ARTIFICIAL (decl)) | |
602 | ; | |
603 | else | |
604 | t = NULL_TREE; | |
605 | ||
e3edbd56 EB |
606 | /* Propagate the name to all the anonymous variants. This is needed |
607 | for the type qualifiers machinery to work properly. */ | |
a1ab4c31 AC |
608 | if (t) |
609 | for (t = TYPE_MAIN_VARIANT (t); t; t = TYPE_NEXT_VARIANT (t)) | |
e3edbd56 EB |
610 | if (!(TYPE_NAME (t) && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)) |
611 | TYPE_NAME (t) = decl; | |
a1ab4c31 AC |
612 | } |
613 | } | |
614 | \f | |
1aeb40dd EB |
615 | /* Record TYPE as a builtin type for Ada. NAME is the name of the type. |
616 | ARTIFICIAL_P is true if it's a type that was generated by the compiler. */ | |
a1ab4c31 AC |
617 | |
618 | void | |
1aeb40dd | 619 | record_builtin_type (const char *name, tree type, bool artificial_p) |
a1ab4c31 | 620 | { |
c172df28 AH |
621 | tree type_decl = build_decl (input_location, |
622 | TYPE_DECL, get_identifier (name), type); | |
1aeb40dd | 623 | DECL_ARTIFICIAL (type_decl) = artificial_p; |
bc712852 | 624 | TYPE_ARTIFICIAL (type) = artificial_p; |
10069d53 | 625 | gnat_pushdecl (type_decl, Empty); |
a1ab4c31 | 626 | |
10069d53 EB |
627 | if (debug_hooks->type_decl) |
628 | debug_hooks->type_decl (type_decl, false); | |
a1ab4c31 AC |
629 | } |
630 | \f | |
e3edbd56 EB |
631 | /* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST, |
632 | finish constructing the record type as a fat pointer type. */ | |
633 | ||
634 | void | |
635 | finish_fat_pointer_type (tree record_type, tree field_list) | |
636 | { | |
637 | /* Make sure we can put it into a register. */ | |
638 | TYPE_ALIGN (record_type) = MIN (BIGGEST_ALIGNMENT, 2 * POINTER_SIZE); | |
639 | ||
640 | /* Show what it really is. */ | |
641 | TYPE_FAT_POINTER_P (record_type) = 1; | |
642 | ||
643 | /* Do not emit debug info for it since the types of its fields may still be | |
644 | incomplete at this point. */ | |
645 | finish_record_type (record_type, field_list, 0, false); | |
646 | ||
647 | /* Force type_contains_placeholder_p to return true on it. Although the | |
648 | PLACEHOLDER_EXPRs are referenced only indirectly, this isn't a pointer | |
649 | type but the representation of the unconstrained array. */ | |
650 | TYPE_CONTAINS_PLACEHOLDER_INTERNAL (record_type) = 2; | |
651 | } | |
652 | ||
032d1b71 | 653 | /* Given a record type RECORD_TYPE and a list of FIELD_DECL nodes FIELD_LIST, |
a1ab4c31 AC |
654 | finish constructing the record or union type. If REP_LEVEL is zero, this |
655 | record has no representation clause and so will be entirely laid out here. | |
656 | If REP_LEVEL is one, this record has a representation clause and has been | |
657 | laid out already; only set the sizes and alignment. If REP_LEVEL is two, | |
658 | this record is derived from a parent record and thus inherits its layout; | |
032d1b71 EB |
659 | only make a pass on the fields to finalize them. DEBUG_INFO_P is true if |
660 | we need to write debug information about this type. */ | |
a1ab4c31 AC |
661 | |
662 | void | |
032d1b71 EB |
663 | finish_record_type (tree record_type, tree field_list, int rep_level, |
664 | bool debug_info_p) | |
a1ab4c31 AC |
665 | { |
666 | enum tree_code code = TREE_CODE (record_type); | |
667 | tree name = TYPE_NAME (record_type); | |
668 | tree ada_size = bitsize_zero_node; | |
669 | tree size = bitsize_zero_node; | |
670 | bool had_size = TYPE_SIZE (record_type) != 0; | |
671 | bool had_size_unit = TYPE_SIZE_UNIT (record_type) != 0; | |
672 | bool had_align = TYPE_ALIGN (record_type) != 0; | |
673 | tree field; | |
674 | ||
032d1b71 | 675 | TYPE_FIELDS (record_type) = field_list; |
a1ab4c31 | 676 | |
10069d53 EB |
677 | /* Always attach the TYPE_STUB_DECL for a record type. It is required to |
678 | generate debug info and have a parallel type. */ | |
679 | if (name && TREE_CODE (name) == TYPE_DECL) | |
680 | name = DECL_NAME (name); | |
681 | TYPE_STUB_DECL (record_type) = create_type_stub_decl (name, record_type); | |
a1ab4c31 AC |
682 | |
683 | /* Globally initialize the record first. If this is a rep'ed record, | |
684 | that just means some initializations; otherwise, layout the record. */ | |
685 | if (rep_level > 0) | |
686 | { | |
687 | TYPE_ALIGN (record_type) = MAX (BITS_PER_UNIT, TYPE_ALIGN (record_type)); | |
a1ab4c31 AC |
688 | |
689 | if (!had_size_unit) | |
690 | TYPE_SIZE_UNIT (record_type) = size_zero_node; | |
b1fa9126 | 691 | |
a1ab4c31 AC |
692 | if (!had_size) |
693 | TYPE_SIZE (record_type) = bitsize_zero_node; | |
694 | ||
695 | /* For all-repped records with a size specified, lay the QUAL_UNION_TYPE | |
696 | out just like a UNION_TYPE, since the size will be fixed. */ | |
697 | else if (code == QUAL_UNION_TYPE) | |
698 | code = UNION_TYPE; | |
699 | } | |
700 | else | |
701 | { | |
702 | /* Ensure there isn't a size already set. There can be in an error | |
703 | case where there is a rep clause but all fields have errors and | |
704 | no longer have a position. */ | |
705 | TYPE_SIZE (record_type) = 0; | |
706 | layout_type (record_type); | |
707 | } | |
708 | ||
709 | /* At this point, the position and size of each field is known. It was | |
710 | either set before entry by a rep clause, or by laying out the type above. | |
711 | ||
712 | We now run a pass over the fields (in reverse order for QUAL_UNION_TYPEs) | |
713 | to compute the Ada size; the GCC size and alignment (for rep'ed records | |
714 | that are not padding types); and the mode (for rep'ed records). We also | |
715 | clear the DECL_BIT_FIELD indication for the cases we know have not been | |
716 | handled yet, and adjust DECL_NONADDRESSABLE_P accordingly. */ | |
717 | ||
718 | if (code == QUAL_UNION_TYPE) | |
032d1b71 | 719 | field_list = nreverse (field_list); |
a1ab4c31 | 720 | |
910ad8de | 721 | for (field = field_list; field; field = DECL_CHAIN (field)) |
a1ab4c31 AC |
722 | { |
723 | tree type = TREE_TYPE (field); | |
724 | tree pos = bit_position (field); | |
725 | tree this_size = DECL_SIZE (field); | |
726 | tree this_ada_size; | |
727 | ||
e1e5852c | 728 | if (RECORD_OR_UNION_TYPE_P (type) |
315cff15 | 729 | && !TYPE_FAT_POINTER_P (type) |
a1ab4c31 AC |
730 | && !TYPE_CONTAINS_TEMPLATE_P (type) |
731 | && TYPE_ADA_SIZE (type)) | |
732 | this_ada_size = TYPE_ADA_SIZE (type); | |
733 | else | |
734 | this_ada_size = this_size; | |
735 | ||
736 | /* Clear DECL_BIT_FIELD for the cases layout_decl does not handle. */ | |
737 | if (DECL_BIT_FIELD (field) | |
738 | && operand_equal_p (this_size, TYPE_SIZE (type), 0)) | |
739 | { | |
740 | unsigned int align = TYPE_ALIGN (type); | |
741 | ||
742 | /* In the general case, type alignment is required. */ | |
743 | if (value_factor_p (pos, align)) | |
744 | { | |
745 | /* The enclosing record type must be sufficiently aligned. | |
746 | Otherwise, if no alignment was specified for it and it | |
747 | has been laid out already, bump its alignment to the | |
748 | desired one if this is compatible with its size. */ | |
749 | if (TYPE_ALIGN (record_type) >= align) | |
750 | { | |
751 | DECL_ALIGN (field) = MAX (DECL_ALIGN (field), align); | |
752 | DECL_BIT_FIELD (field) = 0; | |
753 | } | |
754 | else if (!had_align | |
755 | && rep_level == 0 | |
756 | && value_factor_p (TYPE_SIZE (record_type), align)) | |
757 | { | |
758 | TYPE_ALIGN (record_type) = align; | |
759 | DECL_ALIGN (field) = MAX (DECL_ALIGN (field), align); | |
760 | DECL_BIT_FIELD (field) = 0; | |
761 | } | |
762 | } | |
763 | ||
764 | /* In the non-strict alignment case, only byte alignment is. */ | |
765 | if (!STRICT_ALIGNMENT | |
766 | && DECL_BIT_FIELD (field) | |
767 | && value_factor_p (pos, BITS_PER_UNIT)) | |
768 | DECL_BIT_FIELD (field) = 0; | |
769 | } | |
770 | ||
c1abd261 EB |
771 | /* If we still have DECL_BIT_FIELD set at this point, we know that the |
772 | field is technically not addressable. Except that it can actually | |
773 | be addressed if it is BLKmode and happens to be properly aligned. */ | |
774 | if (DECL_BIT_FIELD (field) | |
775 | && !(DECL_MODE (field) == BLKmode | |
776 | && value_factor_p (pos, BITS_PER_UNIT))) | |
777 | DECL_NONADDRESSABLE_P (field) = 1; | |
a1ab4c31 AC |
778 | |
779 | /* A type must be as aligned as its most aligned field that is not | |
780 | a bit-field. But this is already enforced by layout_type. */ | |
781 | if (rep_level > 0 && !DECL_BIT_FIELD (field)) | |
782 | TYPE_ALIGN (record_type) | |
783 | = MAX (TYPE_ALIGN (record_type), DECL_ALIGN (field)); | |
784 | ||
785 | switch (code) | |
786 | { | |
787 | case UNION_TYPE: | |
788 | ada_size = size_binop (MAX_EXPR, ada_size, this_ada_size); | |
789 | size = size_binop (MAX_EXPR, size, this_size); | |
790 | break; | |
791 | ||
792 | case QUAL_UNION_TYPE: | |
793 | ada_size | |
794 | = fold_build3 (COND_EXPR, bitsizetype, DECL_QUALIFIER (field), | |
795 | this_ada_size, ada_size); | |
796 | size = fold_build3 (COND_EXPR, bitsizetype, DECL_QUALIFIER (field), | |
797 | this_size, size); | |
798 | break; | |
799 | ||
800 | case RECORD_TYPE: | |
801 | /* Since we know here that all fields are sorted in order of | |
802 | increasing bit position, the size of the record is one | |
803 | higher than the ending bit of the last field processed | |
804 | unless we have a rep clause, since in that case we might | |
805 | have a field outside a QUAL_UNION_TYPE that has a higher ending | |
806 | position. So use a MAX in that case. Also, if this field is a | |
807 | QUAL_UNION_TYPE, we need to take into account the previous size in | |
808 | the case of empty variants. */ | |
809 | ada_size | |
810 | = merge_sizes (ada_size, pos, this_ada_size, | |
811 | TREE_CODE (type) == QUAL_UNION_TYPE, rep_level > 0); | |
812 | size | |
813 | = merge_sizes (size, pos, this_size, | |
814 | TREE_CODE (type) == QUAL_UNION_TYPE, rep_level > 0); | |
815 | break; | |
816 | ||
817 | default: | |
818 | gcc_unreachable (); | |
819 | } | |
820 | } | |
821 | ||
822 | if (code == QUAL_UNION_TYPE) | |
032d1b71 | 823 | nreverse (field_list); |
a1ab4c31 AC |
824 | |
825 | if (rep_level < 2) | |
826 | { | |
827 | /* If this is a padding record, we never want to make the size smaller | |
828 | than what was specified in it, if any. */ | |
315cff15 | 829 | if (TYPE_IS_PADDING_P (record_type) && TYPE_SIZE (record_type)) |
a1ab4c31 AC |
830 | size = TYPE_SIZE (record_type); |
831 | ||
832 | /* Now set any of the values we've just computed that apply. */ | |
315cff15 | 833 | if (!TYPE_FAT_POINTER_P (record_type) |
a1ab4c31 AC |
834 | && !TYPE_CONTAINS_TEMPLATE_P (record_type)) |
835 | SET_TYPE_ADA_SIZE (record_type, ada_size); | |
836 | ||
837 | if (rep_level > 0) | |
838 | { | |
839 | tree size_unit = had_size_unit | |
840 | ? TYPE_SIZE_UNIT (record_type) | |
841 | : convert (sizetype, | |
842 | size_binop (CEIL_DIV_EXPR, size, | |
843 | bitsize_unit_node)); | |
844 | unsigned int align = TYPE_ALIGN (record_type); | |
845 | ||
846 | TYPE_SIZE (record_type) = variable_size (round_up (size, align)); | |
847 | TYPE_SIZE_UNIT (record_type) | |
848 | = variable_size (round_up (size_unit, align / BITS_PER_UNIT)); | |
849 | ||
850 | compute_record_mode (record_type); | |
851 | } | |
852 | } | |
853 | ||
032d1b71 | 854 | if (debug_info_p) |
a1ab4c31 AC |
855 | rest_of_record_type_compilation (record_type); |
856 | } | |
857 | ||
a5695aa2 EB |
858 | /* Append PARALLEL_TYPE on the chain of parallel types of TYPE. */ |
859 | ||
860 | void | |
861 | add_parallel_type (tree type, tree parallel_type) | |
862 | { | |
863 | tree decl = TYPE_STUB_DECL (type); | |
864 | ||
865 | while (DECL_PARALLEL_TYPE (decl)) | |
866 | decl = TYPE_STUB_DECL (DECL_PARALLEL_TYPE (decl)); | |
867 | ||
868 | SET_DECL_PARALLEL_TYPE (decl, parallel_type); | |
869 | } | |
870 | ||
871 | /* Return true if TYPE has a parallel type. */ | |
872 | ||
873 | static bool | |
874 | has_parallel_type (tree type) | |
875 | { | |
876 | tree decl = TYPE_STUB_DECL (type); | |
877 | ||
878 | return DECL_PARALLEL_TYPE (decl) != NULL_TREE; | |
879 | } | |
880 | ||
032d1b71 EB |
881 | /* Wrap up compilation of RECORD_TYPE, i.e. output all the debug information |
882 | associated with it. It need not be invoked directly in most cases since | |
883 | finish_record_type takes care of doing so, but this can be necessary if | |
884 | a parallel type is to be attached to the record type. */ | |
a1ab4c31 AC |
885 | |
886 | void | |
887 | rest_of_record_type_compilation (tree record_type) | |
888 | { | |
a1ab4c31 | 889 | bool var_size = false; |
fb88e1dd | 890 | tree field; |
a1ab4c31 | 891 | |
fb88e1dd EB |
892 | /* If this is a padded type, the bulk of the debug info has already been |
893 | generated for the field's type. */ | |
894 | if (TYPE_IS_PADDING_P (record_type)) | |
895 | return; | |
896 | ||
a5695aa2 EB |
897 | /* If the type already has a parallel type (XVS type), then we're done. */ |
898 | if (has_parallel_type (record_type)) | |
899 | return; | |
900 | ||
fb88e1dd | 901 | for (field = TYPE_FIELDS (record_type); field; field = DECL_CHAIN (field)) |
a1ab4c31 AC |
902 | { |
903 | /* We need to make an XVE/XVU record if any field has variable size, | |
904 | whether or not the record does. For example, if we have a union, | |
905 | it may be that all fields, rounded up to the alignment, have the | |
906 | same size, in which case we'll use that size. But the debug | |
907 | output routines (except Dwarf2) won't be able to output the fields, | |
908 | so we need to make the special record. */ | |
909 | if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST | |
910 | /* If a field has a non-constant qualifier, the record will have | |
911 | variable size too. */ | |
fb88e1dd | 912 | || (TREE_CODE (record_type) == QUAL_UNION_TYPE |
a1ab4c31 AC |
913 | && TREE_CODE (DECL_QUALIFIER (field)) != INTEGER_CST)) |
914 | { | |
915 | var_size = true; | |
916 | break; | |
917 | } | |
918 | } | |
919 | ||
fb88e1dd EB |
920 | /* If this record type is of variable size, make a parallel record type that |
921 | will tell the debugger how the former is laid out (see exp_dbug.ads). */ | |
922 | if (var_size) | |
a1ab4c31 AC |
923 | { |
924 | tree new_record_type | |
925 | = make_node (TREE_CODE (record_type) == QUAL_UNION_TYPE | |
926 | ? UNION_TYPE : TREE_CODE (record_type)); | |
0fb2335d | 927 | tree orig_name = TYPE_NAME (record_type), new_name; |
a1ab4c31 | 928 | tree last_pos = bitsize_zero_node; |
0fb2335d | 929 | tree old_field, prev_old_field = NULL_TREE; |
a1ab4c31 | 930 | |
0fb2335d EB |
931 | if (TREE_CODE (orig_name) == TYPE_DECL) |
932 | orig_name = DECL_NAME (orig_name); | |
933 | ||
934 | new_name | |
935 | = concat_name (orig_name, TREE_CODE (record_type) == QUAL_UNION_TYPE | |
936 | ? "XVU" : "XVE"); | |
937 | TYPE_NAME (new_record_type) = new_name; | |
a1ab4c31 AC |
938 | TYPE_ALIGN (new_record_type) = BIGGEST_ALIGNMENT; |
939 | TYPE_STUB_DECL (new_record_type) | |
0fb2335d | 940 | = create_type_stub_decl (new_name, new_record_type); |
a1ab4c31 AC |
941 | DECL_IGNORED_P (TYPE_STUB_DECL (new_record_type)) |
942 | = DECL_IGNORED_P (TYPE_STUB_DECL (record_type)); | |
943 | TYPE_SIZE (new_record_type) = size_int (TYPE_ALIGN (record_type)); | |
944 | TYPE_SIZE_UNIT (new_record_type) | |
945 | = size_int (TYPE_ALIGN (record_type) / BITS_PER_UNIT); | |
946 | ||
a1ab4c31 AC |
947 | /* Now scan all the fields, replacing each field with a new |
948 | field corresponding to the new encoding. */ | |
949 | for (old_field = TYPE_FIELDS (record_type); old_field; | |
910ad8de | 950 | old_field = DECL_CHAIN (old_field)) |
a1ab4c31 AC |
951 | { |
952 | tree field_type = TREE_TYPE (old_field); | |
953 | tree field_name = DECL_NAME (old_field); | |
954 | tree new_field; | |
955 | tree curpos = bit_position (old_field); | |
956 | bool var = false; | |
957 | unsigned int align = 0; | |
958 | tree pos; | |
959 | ||
960 | /* See how the position was modified from the last position. | |
961 | ||
962 | There are two basic cases we support: a value was added | |
963 | to the last position or the last position was rounded to | |
964 | a boundary and they something was added. Check for the | |
965 | first case first. If not, see if there is any evidence | |
966 | of rounding. If so, round the last position and try | |
967 | again. | |
968 | ||
969 | If this is a union, the position can be taken as zero. */ | |
970 | ||
971 | /* Some computations depend on the shape of the position expression, | |
972 | so strip conversions to make sure it's exposed. */ | |
973 | curpos = remove_conversions (curpos, true); | |
974 | ||
975 | if (TREE_CODE (new_record_type) == UNION_TYPE) | |
976 | pos = bitsize_zero_node, align = 0; | |
977 | else | |
978 | pos = compute_related_constant (curpos, last_pos); | |
979 | ||
980 | if (!pos && TREE_CODE (curpos) == MULT_EXPR | |
981 | && host_integerp (TREE_OPERAND (curpos, 1), 1)) | |
982 | { | |
983 | tree offset = TREE_OPERAND (curpos, 0); | |
984 | align = tree_low_cst (TREE_OPERAND (curpos, 1), 1); | |
985 | ||
986 | /* An offset which is a bitwise AND with a negative power of 2 | |
728936bb EB |
987 | means an alignment corresponding to this power of 2. Note |
988 | that, as sizetype is sign-extended but nonetheless unsigned, | |
989 | we don't directly use tree_int_cst_sgn. */ | |
a1ab4c31 AC |
990 | offset = remove_conversions (offset, true); |
991 | if (TREE_CODE (offset) == BIT_AND_EXPR | |
992 | && host_integerp (TREE_OPERAND (offset, 1), 0) | |
728936bb | 993 | && TREE_INT_CST_HIGH (TREE_OPERAND (offset, 1)) < 0) |
a1ab4c31 AC |
994 | { |
995 | unsigned int pow | |
996 | = - tree_low_cst (TREE_OPERAND (offset, 1), 0); | |
997 | if (exact_log2 (pow) > 0) | |
998 | align *= pow; | |
999 | } | |
1000 | ||
1001 | pos = compute_related_constant (curpos, | |
1002 | round_up (last_pos, align)); | |
1003 | } | |
1004 | else if (!pos && TREE_CODE (curpos) == PLUS_EXPR | |
1005 | && TREE_CODE (TREE_OPERAND (curpos, 1)) == INTEGER_CST | |
1006 | && TREE_CODE (TREE_OPERAND (curpos, 0)) == MULT_EXPR | |
1007 | && host_integerp (TREE_OPERAND | |
1008 | (TREE_OPERAND (curpos, 0), 1), | |
1009 | 1)) | |
1010 | { | |
1011 | align | |
1012 | = tree_low_cst | |
1013 | (TREE_OPERAND (TREE_OPERAND (curpos, 0), 1), 1); | |
1014 | pos = compute_related_constant (curpos, | |
1015 | round_up (last_pos, align)); | |
1016 | } | |
1017 | else if (potential_alignment_gap (prev_old_field, old_field, | |
1018 | pos)) | |
1019 | { | |
1020 | align = TYPE_ALIGN (field_type); | |
1021 | pos = compute_related_constant (curpos, | |
1022 | round_up (last_pos, align)); | |
1023 | } | |
1024 | ||
1025 | /* If we can't compute a position, set it to zero. | |
1026 | ||
1027 | ??? We really should abort here, but it's too much work | |
1028 | to get this correct for all cases. */ | |
1029 | ||
1030 | if (!pos) | |
1031 | pos = bitsize_zero_node; | |
1032 | ||
1033 | /* See if this type is variable-sized and make a pointer type | |
1034 | and indicate the indirection if so. Beware that the debug | |
1035 | back-end may adjust the position computed above according | |
1036 | to the alignment of the field type, i.e. the pointer type | |
1037 | in this case, if we don't preventively counter that. */ | |
1038 | if (TREE_CODE (DECL_SIZE (old_field)) != INTEGER_CST) | |
1039 | { | |
1040 | field_type = build_pointer_type (field_type); | |
1041 | if (align != 0 && TYPE_ALIGN (field_type) > align) | |
1042 | { | |
1043 | field_type = copy_node (field_type); | |
1044 | TYPE_ALIGN (field_type) = align; | |
1045 | } | |
1046 | var = true; | |
1047 | } | |
1048 | ||
1049 | /* Make a new field name, if necessary. */ | |
1050 | if (var || align != 0) | |
1051 | { | |
1052 | char suffix[16]; | |
1053 | ||
1054 | if (align != 0) | |
1055 | sprintf (suffix, "XV%c%u", var ? 'L' : 'A', | |
1056 | align / BITS_PER_UNIT); | |
1057 | else | |
1058 | strcpy (suffix, "XVL"); | |
1059 | ||
0fb2335d | 1060 | field_name = concat_name (field_name, suffix); |
a1ab4c31 AC |
1061 | } |
1062 | ||
da01bfee EB |
1063 | new_field |
1064 | = create_field_decl (field_name, field_type, new_record_type, | |
1065 | DECL_SIZE (old_field), pos, 0, 0); | |
910ad8de | 1066 | DECL_CHAIN (new_field) = TYPE_FIELDS (new_record_type); |
a1ab4c31 AC |
1067 | TYPE_FIELDS (new_record_type) = new_field; |
1068 | ||
1069 | /* If old_field is a QUAL_UNION_TYPE, take its size as being | |
1070 | zero. The only time it's not the last field of the record | |
1071 | is when there are other components at fixed positions after | |
1072 | it (meaning there was a rep clause for every field) and we | |
1073 | want to be able to encode them. */ | |
1074 | last_pos = size_binop (PLUS_EXPR, bit_position (old_field), | |
1075 | (TREE_CODE (TREE_TYPE (old_field)) | |
1076 | == QUAL_UNION_TYPE) | |
1077 | ? bitsize_zero_node | |
1078 | : DECL_SIZE (old_field)); | |
1079 | prev_old_field = old_field; | |
1080 | } | |
1081 | ||
fb88e1dd | 1082 | TYPE_FIELDS (new_record_type) = nreverse (TYPE_FIELDS (new_record_type)); |
a1ab4c31 | 1083 | |
a5695aa2 | 1084 | add_parallel_type (record_type, new_record_type); |
a1ab4c31 | 1085 | } |
a1ab4c31 AC |
1086 | } |
1087 | ||
a1ab4c31 | 1088 | /* Utility function of above to merge LAST_SIZE, the previous size of a record |
1e17ef87 EB |
1089 | with FIRST_BIT and SIZE that describe a field. SPECIAL is true if this |
1090 | represents a QUAL_UNION_TYPE in which case we must look for COND_EXPRs and | |
1091 | replace a value of zero with the old size. If HAS_REP is true, we take the | |
1092 | MAX of the end position of this field with LAST_SIZE. In all other cases, | |
1093 | we use FIRST_BIT plus SIZE. Return an expression for the size. */ | |
a1ab4c31 AC |
1094 | |
1095 | static tree | |
1096 | merge_sizes (tree last_size, tree first_bit, tree size, bool special, | |
1097 | bool has_rep) | |
1098 | { | |
1099 | tree type = TREE_TYPE (last_size); | |
c6bd4220 | 1100 | tree new_size; |
a1ab4c31 AC |
1101 | |
1102 | if (!special || TREE_CODE (size) != COND_EXPR) | |
1103 | { | |
c6bd4220 | 1104 | new_size = size_binop (PLUS_EXPR, first_bit, size); |
a1ab4c31 | 1105 | if (has_rep) |
c6bd4220 | 1106 | new_size = size_binop (MAX_EXPR, last_size, new_size); |
a1ab4c31 AC |
1107 | } |
1108 | ||
1109 | else | |
c6bd4220 EB |
1110 | new_size = fold_build3 (COND_EXPR, type, TREE_OPERAND (size, 0), |
1111 | integer_zerop (TREE_OPERAND (size, 1)) | |
1112 | ? last_size : merge_sizes (last_size, first_bit, | |
1113 | TREE_OPERAND (size, 1), | |
1114 | 1, has_rep), | |
1115 | integer_zerop (TREE_OPERAND (size, 2)) | |
1116 | ? last_size : merge_sizes (last_size, first_bit, | |
1117 | TREE_OPERAND (size, 2), | |
1118 | 1, has_rep)); | |
a1ab4c31 AC |
1119 | |
1120 | /* We don't need any NON_VALUE_EXPRs and they can confuse us (especially | |
1121 | when fed through substitute_in_expr) into thinking that a constant | |
1122 | size is not constant. */ | |
c6bd4220 EB |
1123 | while (TREE_CODE (new_size) == NON_LVALUE_EXPR) |
1124 | new_size = TREE_OPERAND (new_size, 0); | |
a1ab4c31 | 1125 | |
c6bd4220 | 1126 | return new_size; |
a1ab4c31 AC |
1127 | } |
1128 | ||
1129 | /* Utility function of above to see if OP0 and OP1, both of SIZETYPE, are | |
1130 | related by the addition of a constant. Return that constant if so. */ | |
1131 | ||
1132 | static tree | |
1133 | compute_related_constant (tree op0, tree op1) | |
1134 | { | |
1135 | tree op0_var, op1_var; | |
1136 | tree op0_con = split_plus (op0, &op0_var); | |
1137 | tree op1_con = split_plus (op1, &op1_var); | |
1138 | tree result = size_binop (MINUS_EXPR, op0_con, op1_con); | |
1139 | ||
1140 | if (operand_equal_p (op0_var, op1_var, 0)) | |
1141 | return result; | |
1142 | else if (operand_equal_p (op0, size_binop (PLUS_EXPR, op1_var, result), 0)) | |
1143 | return result; | |
1144 | else | |
1145 | return 0; | |
1146 | } | |
1147 | ||
1148 | /* Utility function of above to split a tree OP which may be a sum, into a | |
1149 | constant part, which is returned, and a variable part, which is stored | |
1150 | in *PVAR. *PVAR may be bitsize_zero_node. All operations must be of | |
1151 | bitsizetype. */ | |
1152 | ||
1153 | static tree | |
1154 | split_plus (tree in, tree *pvar) | |
1155 | { | |
722356ce EB |
1156 | /* Strip conversions in order to ease the tree traversal and maximize the |
1157 | potential for constant or plus/minus discovery. We need to be careful | |
a1ab4c31 AC |
1158 | to always return and set *pvar to bitsizetype trees, but it's worth |
1159 | the effort. */ | |
722356ce | 1160 | in = remove_conversions (in, false); |
a1ab4c31 AC |
1161 | |
1162 | *pvar = convert (bitsizetype, in); | |
1163 | ||
1164 | if (TREE_CODE (in) == INTEGER_CST) | |
1165 | { | |
1166 | *pvar = bitsize_zero_node; | |
1167 | return convert (bitsizetype, in); | |
1168 | } | |
1169 | else if (TREE_CODE (in) == PLUS_EXPR || TREE_CODE (in) == MINUS_EXPR) | |
1170 | { | |
1171 | tree lhs_var, rhs_var; | |
1172 | tree lhs_con = split_plus (TREE_OPERAND (in, 0), &lhs_var); | |
1173 | tree rhs_con = split_plus (TREE_OPERAND (in, 1), &rhs_var); | |
1174 | ||
1175 | if (lhs_var == TREE_OPERAND (in, 0) | |
1176 | && rhs_var == TREE_OPERAND (in, 1)) | |
1177 | return bitsize_zero_node; | |
1178 | ||
1179 | *pvar = size_binop (TREE_CODE (in), lhs_var, rhs_var); | |
1180 | return size_binop (TREE_CODE (in), lhs_con, rhs_con); | |
1181 | } | |
1182 | else | |
1183 | return bitsize_zero_node; | |
1184 | } | |
1185 | \f | |
d47d0a8d EB |
1186 | /* Return a FUNCTION_TYPE node. RETURN_TYPE is the type returned by the |
1187 | subprogram. If it is VOID_TYPE, then we are dealing with a procedure, | |
1188 | otherwise we are dealing with a function. PARAM_DECL_LIST is a list of | |
1189 | PARM_DECL nodes that are the subprogram parameters. CICO_LIST is the | |
1190 | copy-in/copy-out list to be stored into the TYPE_CICO_LIST field. | |
1191 | RETURN_UNCONSTRAINED_P is true if the function returns an unconstrained | |
1192 | object. RETURN_BY_DIRECT_REF_P is true if the function returns by direct | |
1193 | reference. RETURN_BY_INVISI_REF_P is true if the function returns by | |
1194 | invisible reference. */ | |
a1ab4c31 AC |
1195 | |
1196 | tree | |
1197 | create_subprog_type (tree return_type, tree param_decl_list, tree cico_list, | |
d47d0a8d EB |
1198 | bool return_unconstrained_p, bool return_by_direct_ref_p, |
1199 | bool return_by_invisi_ref_p) | |
a1ab4c31 | 1200 | { |
e5b00edf NF |
1201 | /* A list of the data type nodes of the subprogram formal parameters. |
1202 | This list is generated by traversing the input list of PARM_DECL | |
1203 | nodes. */ | |
1204 | VEC(tree,gc) *param_type_list = NULL; | |
d47d0a8d | 1205 | tree t, type; |
a1ab4c31 | 1206 | |
910ad8de | 1207 | for (t = param_decl_list; t; t = DECL_CHAIN (t)) |
e5b00edf | 1208 | VEC_safe_push (tree, gc, param_type_list, TREE_TYPE (t)); |
a1ab4c31 | 1209 | |
e5b00edf | 1210 | type = build_function_type_vec (return_type, param_type_list); |
a1ab4c31 | 1211 | |
d47d0a8d EB |
1212 | /* TYPE may have been shared since GCC hashes types. If it has a different |
1213 | CICO_LIST, make a copy. Likewise for the various flags. */ | |
523e82a7 EB |
1214 | if (!fntype_same_flags_p (type, cico_list, return_unconstrained_p, |
1215 | return_by_direct_ref_p, return_by_invisi_ref_p)) | |
d47d0a8d EB |
1216 | { |
1217 | type = copy_type (type); | |
1218 | TYPE_CI_CO_LIST (type) = cico_list; | |
1219 | TYPE_RETURN_UNCONSTRAINED_P (type) = return_unconstrained_p; | |
1220 | TYPE_RETURN_BY_DIRECT_REF_P (type) = return_by_direct_ref_p; | |
1221 | TREE_ADDRESSABLE (type) = return_by_invisi_ref_p; | |
1222 | } | |
a1ab4c31 | 1223 | |
a1ab4c31 AC |
1224 | return type; |
1225 | } | |
1226 | \f | |
1227 | /* Return a copy of TYPE but safe to modify in any way. */ | |
1228 | ||
1229 | tree | |
1230 | copy_type (tree type) | |
1231 | { | |
c6bd4220 | 1232 | tree new_type = copy_node (type); |
a1ab4c31 | 1233 | |
90dcfecb EB |
1234 | /* Unshare the language-specific data. */ |
1235 | if (TYPE_LANG_SPECIFIC (type)) | |
1236 | { | |
1237 | TYPE_LANG_SPECIFIC (new_type) = NULL; | |
1238 | SET_TYPE_LANG_SPECIFIC (new_type, GET_TYPE_LANG_SPECIFIC (type)); | |
1239 | } | |
1240 | ||
1241 | /* And the contents of the language-specific slot if needed. */ | |
1242 | if ((INTEGRAL_TYPE_P (type) || TREE_CODE (type) == REAL_TYPE) | |
1243 | && TYPE_RM_VALUES (type)) | |
1244 | { | |
1245 | TYPE_RM_VALUES (new_type) = NULL_TREE; | |
1246 | SET_TYPE_RM_SIZE (new_type, TYPE_RM_SIZE (type)); | |
1247 | SET_TYPE_RM_MIN_VALUE (new_type, TYPE_RM_MIN_VALUE (type)); | |
1248 | SET_TYPE_RM_MAX_VALUE (new_type, TYPE_RM_MAX_VALUE (type)); | |
1249 | } | |
1250 | ||
a1ab4c31 AC |
1251 | /* copy_node clears this field instead of copying it, because it is |
1252 | aliased with TREE_CHAIN. */ | |
c6bd4220 | 1253 | TYPE_STUB_DECL (new_type) = TYPE_STUB_DECL (type); |
a1ab4c31 | 1254 | |
c6bd4220 EB |
1255 | TYPE_POINTER_TO (new_type) = 0; |
1256 | TYPE_REFERENCE_TO (new_type) = 0; | |
1257 | TYPE_MAIN_VARIANT (new_type) = new_type; | |
1258 | TYPE_NEXT_VARIANT (new_type) = 0; | |
a1ab4c31 | 1259 | |
c6bd4220 | 1260 | return new_type; |
a1ab4c31 AC |
1261 | } |
1262 | \f | |
c1abd261 EB |
1263 | /* Return a subtype of sizetype with range MIN to MAX and whose |
1264 | TYPE_INDEX_TYPE is INDEX. GNAT_NODE is used for the position | |
1265 | of the associated TYPE_DECL. */ | |
a1ab4c31 AC |
1266 | |
1267 | tree | |
1268 | create_index_type (tree min, tree max, tree index, Node_Id gnat_node) | |
1269 | { | |
1270 | /* First build a type for the desired range. */ | |
523e82a7 | 1271 | tree type = build_nonshared_range_type (sizetype, min, max); |
a1ab4c31 | 1272 | |
523e82a7 | 1273 | /* Then set the index type. */ |
a1ab4c31 AC |
1274 | SET_TYPE_INDEX_TYPE (type, index); |
1275 | create_type_decl (NULL_TREE, type, NULL, true, false, gnat_node); | |
c1abd261 | 1276 | |
a1ab4c31 AC |
1277 | return type; |
1278 | } | |
84fb43a1 EB |
1279 | |
1280 | /* Return a subtype of TYPE with range MIN to MAX. If TYPE is NULL, | |
1281 | sizetype is used. */ | |
1282 | ||
1283 | tree | |
1284 | create_range_type (tree type, tree min, tree max) | |
1285 | { | |
1286 | tree range_type; | |
1287 | ||
1288 | if (type == NULL_TREE) | |
1289 | type = sizetype; | |
1290 | ||
1291 | /* First build a type with the base range. */ | |
523e82a7 EB |
1292 | range_type = build_nonshared_range_type (type, TYPE_MIN_VALUE (type), |
1293 | TYPE_MAX_VALUE (type)); | |
84fb43a1 EB |
1294 | |
1295 | /* Then set the actual range. */ | |
523e82a7 EB |
1296 | SET_TYPE_RM_MIN_VALUE (range_type, convert (type, min)); |
1297 | SET_TYPE_RM_MAX_VALUE (range_type, convert (type, max)); | |
84fb43a1 EB |
1298 | |
1299 | return range_type; | |
1300 | } | |
a1ab4c31 | 1301 | \f |
10069d53 EB |
1302 | /* Return a TYPE_DECL node suitable for the TYPE_STUB_DECL field of a type. |
1303 | TYPE_NAME gives the name of the type and TYPE is a ..._TYPE node giving | |
1304 | its data type. */ | |
1305 | ||
1306 | tree | |
1307 | create_type_stub_decl (tree type_name, tree type) | |
1308 | { | |
1309 | /* Using a named TYPE_DECL ensures that a type name marker is emitted in | |
1310 | STABS while setting DECL_ARTIFICIAL ensures that no DW_TAG_typedef is | |
1311 | emitted in DWARF. */ | |
c172df28 AH |
1312 | tree type_decl = build_decl (input_location, |
1313 | TYPE_DECL, type_name, type); | |
10069d53 | 1314 | DECL_ARTIFICIAL (type_decl) = 1; |
bc712852 | 1315 | TYPE_ARTIFICIAL (type) = 1; |
10069d53 EB |
1316 | return type_decl; |
1317 | } | |
1318 | ||
1319 | /* Return a TYPE_DECL node. TYPE_NAME gives the name of the type and TYPE | |
1320 | is a ..._TYPE node giving its data type. ARTIFICIAL_P is true if this | |
1321 | is a declaration that was generated by the compiler. DEBUG_INFO_P is | |
1322 | true if we need to write debug information about this type. GNAT_NODE | |
1323 | is used for the position of the decl. */ | |
a1ab4c31 AC |
1324 | |
1325 | tree | |
1326 | create_type_decl (tree type_name, tree type, struct attrib *attr_list, | |
1327 | bool artificial_p, bool debug_info_p, Node_Id gnat_node) | |
1328 | { | |
a1ab4c31 | 1329 | enum tree_code code = TREE_CODE (type); |
10069d53 EB |
1330 | bool named = TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL; |
1331 | tree type_decl; | |
a1ab4c31 | 1332 | |
10069d53 EB |
1333 | /* Only the builtin TYPE_STUB_DECL should be used for dummy types. */ |
1334 | gcc_assert (!TYPE_IS_DUMMY_P (type)); | |
a1ab4c31 | 1335 | |
10069d53 EB |
1336 | /* If the type hasn't been named yet, we're naming it; preserve an existing |
1337 | TYPE_STUB_DECL that has been attached to it for some purpose. */ | |
1338 | if (!named && TYPE_STUB_DECL (type)) | |
1339 | { | |
1340 | type_decl = TYPE_STUB_DECL (type); | |
1341 | DECL_NAME (type_decl) = type_name; | |
1342 | } | |
1343 | else | |
c172df28 AH |
1344 | type_decl = build_decl (input_location, |
1345 | TYPE_DECL, type_name, type); | |
a1ab4c31 | 1346 | |
10069d53 | 1347 | DECL_ARTIFICIAL (type_decl) = artificial_p; |
bc712852 | 1348 | TYPE_ARTIFICIAL (type) = artificial_p; |
58c8f770 EB |
1349 | |
1350 | /* Add this decl to the current binding level. */ | |
10069d53 | 1351 | gnat_pushdecl (type_decl, gnat_node); |
58c8f770 | 1352 | |
a1ab4c31 AC |
1353 | process_attributes (type_decl, attr_list); |
1354 | ||
10069d53 EB |
1355 | /* If we're naming the type, equate the TYPE_STUB_DECL to the name. |
1356 | This causes the name to be also viewed as a "tag" by the debug | |
1357 | back-end, with the advantage that no DW_TAG_typedef is emitted | |
1358 | for artificial "tagged" types in DWARF. */ | |
1359 | if (!named) | |
1360 | TYPE_STUB_DECL (type) = type_decl; | |
1361 | ||
50741117 EB |
1362 | /* Do not generate debug info for UNCONSTRAINED_ARRAY_TYPE that the |
1363 | back-end doesn't support, and for others if we don't need to. */ | |
a1ab4c31 AC |
1364 | if (code == UNCONSTRAINED_ARRAY_TYPE || !debug_info_p) |
1365 | DECL_IGNORED_P (type_decl) = 1; | |
a1ab4c31 AC |
1366 | |
1367 | return type_decl; | |
1368 | } | |
10069d53 | 1369 | \f |
a1ab4c31 AC |
1370 | /* Return a VAR_DECL or CONST_DECL node. |
1371 | ||
1372 | VAR_NAME gives the name of the variable. ASM_NAME is its assembler name | |
1373 | (if provided). TYPE is its data type (a GCC ..._TYPE node). VAR_INIT is | |
1374 | the GCC tree for an optional initial expression; NULL_TREE if none. | |
1375 | ||
1376 | CONST_FLAG is true if this variable is constant, in which case we might | |
1377 | return a CONST_DECL node unless CONST_DECL_ALLOWED_P is false. | |
1378 | ||
1379 | PUBLIC_FLAG is true if this is for a reference to a public entity or for a | |
1380 | definition to be made visible outside of the current compilation unit, for | |
1381 | instance variable definitions in a package specification. | |
1382 | ||
1e17ef87 | 1383 | EXTERN_FLAG is true when processing an external variable declaration (as |
a1ab4c31 AC |
1384 | opposed to a definition: no storage is to be allocated for the variable). |
1385 | ||
1386 | STATIC_FLAG is only relevant when not at top level. In that case | |
1387 | it indicates whether to always allocate storage to the variable. | |
1388 | ||
1389 | GNAT_NODE is used for the position of the decl. */ | |
1390 | ||
1391 | tree | |
1392 | create_var_decl_1 (tree var_name, tree asm_name, tree type, tree var_init, | |
1393 | bool const_flag, bool public_flag, bool extern_flag, | |
1394 | bool static_flag, bool const_decl_allowed_p, | |
1395 | struct attrib *attr_list, Node_Id gnat_node) | |
1396 | { | |
50179d58 EB |
1397 | /* Whether the initializer is a constant initializer. At the global level |
1398 | or for an external object or an object to be allocated in static memory, | |
1399 | we check that it is a valid constant expression for use in initializing | |
1400 | a static variable; otherwise, we only check that it is constant. */ | |
a1ab4c31 AC |
1401 | bool init_const |
1402 | = (var_init != 0 | |
1403 | && gnat_types_compatible_p (type, TREE_TYPE (var_init)) | |
50179d58 | 1404 | && (global_bindings_p () || extern_flag || static_flag |
a1ab4c31 AC |
1405 | ? initializer_constant_valid_p (var_init, TREE_TYPE (var_init)) != 0 |
1406 | : TREE_CONSTANT (var_init))); | |
1407 | ||
1408 | /* Whether we will make TREE_CONSTANT the DECL we produce here, in which | |
1409 | case the initializer may be used in-lieu of the DECL node (as done in | |
1410 | Identifier_to_gnu). This is useful to prevent the need of elaboration | |
1411 | code when an identifier for which such a decl is made is in turn used as | |
1412 | an initializer. We used to rely on CONST vs VAR_DECL for this purpose, | |
1413 | but extra constraints apply to this choice (see below) and are not | |
1414 | relevant to the distinction we wish to make. */ | |
1415 | bool constant_p = const_flag && init_const; | |
1416 | ||
1417 | /* The actual DECL node. CONST_DECL was initially intended for enumerals | |
1418 | and may be used for scalars in general but not for aggregates. */ | |
1419 | tree var_decl | |
c172df28 AH |
1420 | = build_decl (input_location, |
1421 | (constant_p && const_decl_allowed_p | |
a1ab4c31 AC |
1422 | && !AGGREGATE_TYPE_P (type)) ? CONST_DECL : VAR_DECL, |
1423 | var_name, type); | |
1424 | ||
1425 | /* If this is external, throw away any initializations (they will be done | |
1426 | elsewhere) unless this is a constant for which we would like to remain | |
1427 | able to get the initializer. If we are defining a global here, leave a | |
1428 | constant initialization and save any variable elaborations for the | |
1429 | elaboration routine. If we are just annotating types, throw away the | |
1430 | initialization if it isn't a constant. */ | |
1431 | if ((extern_flag && !constant_p) | |
1432 | || (type_annotate_only && var_init && !TREE_CONSTANT (var_init))) | |
1433 | var_init = NULL_TREE; | |
1434 | ||
1435 | /* At the global level, an initializer requiring code to be generated | |
1436 | produces elaboration statements. Check that such statements are allowed, | |
1437 | that is, not violating a No_Elaboration_Code restriction. */ | |
3b9e8343 | 1438 | if (global_bindings_p () && var_init != 0 && !init_const) |
a1ab4c31 | 1439 | Check_Elaboration_Code_Allowed (gnat_node); |
3b9e8343 | 1440 | |
8b7b0c36 JH |
1441 | DECL_INITIAL (var_decl) = var_init; |
1442 | TREE_READONLY (var_decl) = const_flag; | |
1443 | DECL_EXTERNAL (var_decl) = extern_flag; | |
1444 | TREE_PUBLIC (var_decl) = public_flag || extern_flag; | |
1445 | TREE_CONSTANT (var_decl) = constant_p; | |
1446 | TREE_THIS_VOLATILE (var_decl) = TREE_SIDE_EFFECTS (var_decl) | |
1447 | = TYPE_VOLATILE (type); | |
a1ab4c31 AC |
1448 | |
1449 | /* Ada doesn't feature Fortran-like COMMON variables so we shouldn't | |
1450 | try to fiddle with DECL_COMMON. However, on platforms that don't | |
1451 | support global BSS sections, uninitialized global variables would | |
1452 | go in DATA instead, thus increasing the size of the executable. */ | |
1453 | if (!flag_no_common | |
1454 | && TREE_CODE (var_decl) == VAR_DECL | |
3b9e8343 | 1455 | && TREE_PUBLIC (var_decl) |
a1ab4c31 AC |
1456 | && !have_global_bss_p ()) |
1457 | DECL_COMMON (var_decl) = 1; | |
a1ab4c31 | 1458 | |
2231f17f EB |
1459 | /* At the global binding level, we need to allocate static storage for the |
1460 | variable if it isn't external. Otherwise, we allocate automatic storage | |
1461 | unless requested not to. */ | |
a1ab4c31 | 1462 | TREE_STATIC (var_decl) |
2231f17f | 1463 | = !extern_flag && (static_flag || global_bindings_p ()); |
a1ab4c31 | 1464 | |
5225a138 EB |
1465 | /* For an external constant whose initializer is not absolute, do not emit |
1466 | debug info. In DWARF this would mean a global relocation in a read-only | |
c01fe451 | 1467 | section which runs afoul of the PE-COFF run-time relocation mechanism. */ |
5225a138 EB |
1468 | if (extern_flag |
1469 | && constant_p | |
50179d58 | 1470 | && var_init |
5225a138 EB |
1471 | && initializer_constant_valid_p (var_init, TREE_TYPE (var_init)) |
1472 | != null_pointer_node) | |
1473 | DECL_IGNORED_P (var_decl) = 1; | |
1474 | ||
a1ab4c31 AC |
1475 | /* Add this decl to the current binding level. */ |
1476 | gnat_pushdecl (var_decl, gnat_node); | |
1477 | ||
1478 | if (TREE_SIDE_EFFECTS (var_decl)) | |
1479 | TREE_ADDRESSABLE (var_decl) = 1; | |
1480 | ||
58c8f770 | 1481 | if (TREE_CODE (var_decl) == VAR_DECL) |
a1ab4c31 | 1482 | { |
58c8f770 EB |
1483 | if (asm_name) |
1484 | SET_DECL_ASSEMBLER_NAME (var_decl, asm_name); | |
1485 | process_attributes (var_decl, attr_list); | |
a1ab4c31 AC |
1486 | if (global_bindings_p ()) |
1487 | rest_of_decl_compilation (var_decl, true, 0); | |
1488 | } | |
1489 | else | |
1490 | expand_decl (var_decl); | |
1491 | ||
1492 | return var_decl; | |
1493 | } | |
1494 | \f | |
1495 | /* Return true if TYPE, an aggregate type, contains (or is) an array. */ | |
1496 | ||
1497 | static bool | |
1498 | aggregate_type_contains_array_p (tree type) | |
1499 | { | |
1500 | switch (TREE_CODE (type)) | |
1501 | { | |
1502 | case RECORD_TYPE: | |
1503 | case UNION_TYPE: | |
1504 | case QUAL_UNION_TYPE: | |
1505 | { | |
1506 | tree field; | |
910ad8de | 1507 | for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
a1ab4c31 AC |
1508 | if (AGGREGATE_TYPE_P (TREE_TYPE (field)) |
1509 | && aggregate_type_contains_array_p (TREE_TYPE (field))) | |
1510 | return true; | |
1511 | return false; | |
1512 | } | |
1513 | ||
1514 | case ARRAY_TYPE: | |
1515 | return true; | |
1516 | ||
1517 | default: | |
1518 | gcc_unreachable (); | |
1519 | } | |
1520 | } | |
1521 | ||
62f9f3ce | 1522 | /* Return a FIELD_DECL node. FIELD_NAME is the field's name, FIELD_TYPE is |
da01bfee EB |
1523 | its type and RECORD_TYPE is the type of the enclosing record. If SIZE is |
1524 | nonzero, it is the specified size of the field. If POS is nonzero, it is | |
1525 | the bit position. PACKED is 1 if the enclosing record is packed, -1 if it | |
1526 | has Component_Alignment of Storage_Unit. If ADDRESSABLE is nonzero, it | |
62f9f3ce EB |
1527 | means we are allowed to take the address of the field; if it is negative, |
1528 | we should not make a bitfield, which is used by make_aligning_type. */ | |
a1ab4c31 AC |
1529 | |
1530 | tree | |
1531 | create_field_decl (tree field_name, tree field_type, tree record_type, | |
da01bfee | 1532 | tree size, tree pos, int packed, int addressable) |
a1ab4c31 | 1533 | { |
c172df28 AH |
1534 | tree field_decl = build_decl (input_location, |
1535 | FIELD_DECL, field_name, field_type); | |
a1ab4c31 AC |
1536 | |
1537 | DECL_CONTEXT (field_decl) = record_type; | |
1538 | TREE_READONLY (field_decl) = TYPE_READONLY (field_type); | |
1539 | ||
1540 | /* If FIELD_TYPE is BLKmode, we must ensure this is aligned to at least a | |
1541 | byte boundary since GCC cannot handle less-aligned BLKmode bitfields. | |
1542 | Likewise for an aggregate without specified position that contains an | |
1543 | array, because in this case slices of variable length of this array | |
1544 | must be handled by GCC and variable-sized objects need to be aligned | |
1545 | to at least a byte boundary. */ | |
1546 | if (packed && (TYPE_MODE (field_type) == BLKmode | |
1547 | || (!pos | |
1548 | && AGGREGATE_TYPE_P (field_type) | |
1549 | && aggregate_type_contains_array_p (field_type)))) | |
1550 | DECL_ALIGN (field_decl) = BITS_PER_UNIT; | |
1551 | ||
1552 | /* If a size is specified, use it. Otherwise, if the record type is packed | |
1553 | compute a size to use, which may differ from the object's natural size. | |
1554 | We always set a size in this case to trigger the checks for bitfield | |
1555 | creation below, which is typically required when no position has been | |
1556 | specified. */ | |
1557 | if (size) | |
1558 | size = convert (bitsizetype, size); | |
1559 | else if (packed == 1) | |
1560 | { | |
1561 | size = rm_size (field_type); | |
62f9f3ce EB |
1562 | if (TYPE_MODE (field_type) == BLKmode) |
1563 | size = round_up (size, BITS_PER_UNIT); | |
a1ab4c31 AC |
1564 | } |
1565 | ||
1566 | /* If we may, according to ADDRESSABLE, make a bitfield if a size is | |
1567 | specified for two reasons: first if the size differs from the natural | |
1568 | size. Second, if the alignment is insufficient. There are a number of | |
1569 | ways the latter can be true. | |
1570 | ||
1571 | We never make a bitfield if the type of the field has a nonconstant size, | |
1572 | because no such entity requiring bitfield operations should reach here. | |
1573 | ||
1574 | We do *preventively* make a bitfield when there might be the need for it | |
1575 | but we don't have all the necessary information to decide, as is the case | |
1576 | of a field with no specified position in a packed record. | |
1577 | ||
1578 | We also don't look at STRICT_ALIGNMENT here, and rely on later processing | |
1579 | in layout_decl or finish_record_type to clear the bit_field indication if | |
1580 | it is in fact not needed. */ | |
1581 | if (addressable >= 0 | |
1582 | && size | |
1583 | && TREE_CODE (size) == INTEGER_CST | |
1584 | && TREE_CODE (TYPE_SIZE (field_type)) == INTEGER_CST | |
1585 | && (!tree_int_cst_equal (size, TYPE_SIZE (field_type)) | |
1586 | || (pos && !value_factor_p (pos, TYPE_ALIGN (field_type))) | |
1587 | || packed | |
1588 | || (TYPE_ALIGN (record_type) != 0 | |
1589 | && TYPE_ALIGN (record_type) < TYPE_ALIGN (field_type)))) | |
1590 | { | |
1591 | DECL_BIT_FIELD (field_decl) = 1; | |
1592 | DECL_SIZE (field_decl) = size; | |
1593 | if (!packed && !pos) | |
feec4372 EB |
1594 | { |
1595 | if (TYPE_ALIGN (record_type) != 0 | |
1596 | && TYPE_ALIGN (record_type) < TYPE_ALIGN (field_type)) | |
1597 | DECL_ALIGN (field_decl) = TYPE_ALIGN (record_type); | |
1598 | else | |
1599 | DECL_ALIGN (field_decl) = TYPE_ALIGN (field_type); | |
1600 | } | |
a1ab4c31 AC |
1601 | } |
1602 | ||
1603 | DECL_PACKED (field_decl) = pos ? DECL_BIT_FIELD (field_decl) : packed; | |
1604 | ||
1605 | /* Bump the alignment if need be, either for bitfield/packing purposes or | |
1606 | to satisfy the type requirements if no such consideration applies. When | |
1607 | we get the alignment from the type, indicate if this is from an explicit | |
1608 | user request, which prevents stor-layout from lowering it later on. */ | |
1609 | { | |
d9223014 | 1610 | unsigned int bit_align |
a1ab4c31 AC |
1611 | = (DECL_BIT_FIELD (field_decl) ? 1 |
1612 | : packed && TYPE_MODE (field_type) != BLKmode ? BITS_PER_UNIT : 0); | |
1613 | ||
1614 | if (bit_align > DECL_ALIGN (field_decl)) | |
1615 | DECL_ALIGN (field_decl) = bit_align; | |
1616 | else if (!bit_align && TYPE_ALIGN (field_type) > DECL_ALIGN (field_decl)) | |
1617 | { | |
1618 | DECL_ALIGN (field_decl) = TYPE_ALIGN (field_type); | |
1619 | DECL_USER_ALIGN (field_decl) = TYPE_USER_ALIGN (field_type); | |
1620 | } | |
1621 | } | |
1622 | ||
1623 | if (pos) | |
1624 | { | |
1625 | /* We need to pass in the alignment the DECL is known to have. | |
1626 | This is the lowest-order bit set in POS, but no more than | |
1627 | the alignment of the record, if one is specified. Note | |
1628 | that an alignment of 0 is taken as infinite. */ | |
1629 | unsigned int known_align; | |
1630 | ||
1631 | if (host_integerp (pos, 1)) | |
1632 | known_align = tree_low_cst (pos, 1) & - tree_low_cst (pos, 1); | |
1633 | else | |
1634 | known_align = BITS_PER_UNIT; | |
1635 | ||
1636 | if (TYPE_ALIGN (record_type) | |
1637 | && (known_align == 0 || known_align > TYPE_ALIGN (record_type))) | |
1638 | known_align = TYPE_ALIGN (record_type); | |
1639 | ||
1640 | layout_decl (field_decl, known_align); | |
1641 | SET_DECL_OFFSET_ALIGN (field_decl, | |
1642 | host_integerp (pos, 1) ? BIGGEST_ALIGNMENT | |
1643 | : BITS_PER_UNIT); | |
1644 | pos_from_bit (&DECL_FIELD_OFFSET (field_decl), | |
1645 | &DECL_FIELD_BIT_OFFSET (field_decl), | |
1646 | DECL_OFFSET_ALIGN (field_decl), pos); | |
a1ab4c31 AC |
1647 | } |
1648 | ||
1649 | /* In addition to what our caller says, claim the field is addressable if we | |
1650 | know that its type is not suitable. | |
1651 | ||
1652 | The field may also be "technically" nonaddressable, meaning that even if | |
1653 | we attempt to take the field's address we will actually get the address | |
1654 | of a copy. This is the case for true bitfields, but the DECL_BIT_FIELD | |
1655 | value we have at this point is not accurate enough, so we don't account | |
1656 | for this here and let finish_record_type decide. */ | |
4c5a0615 | 1657 | if (!addressable && !type_for_nonaliased_component_p (field_type)) |
a1ab4c31 AC |
1658 | addressable = 1; |
1659 | ||
1660 | DECL_NONADDRESSABLE_P (field_decl) = !addressable; | |
1661 | ||
1662 | return field_decl; | |
1663 | } | |
1664 | \f | |
a8e05f92 EB |
1665 | /* Return a PARM_DECL node. PARAM_NAME is the name of the parameter and |
1666 | PARAM_TYPE is its type. READONLY is true if the parameter is readonly | |
1667 | (either an In parameter or an address of a pass-by-ref parameter). */ | |
a1ab4c31 AC |
1668 | |
1669 | tree | |
1670 | create_param_decl (tree param_name, tree param_type, bool readonly) | |
1671 | { | |
c172df28 AH |
1672 | tree param_decl = build_decl (input_location, |
1673 | PARM_DECL, param_name, param_type); | |
a1ab4c31 | 1674 | |
a8e05f92 EB |
1675 | /* Honor TARGET_PROMOTE_PROTOTYPES like the C compiler, as not doing so |
1676 | can lead to various ABI violations. */ | |
1677 | if (targetm.calls.promote_prototypes (NULL_TREE) | |
1678 | && INTEGRAL_TYPE_P (param_type) | |
a1ab4c31 AC |
1679 | && TYPE_PRECISION (param_type) < TYPE_PRECISION (integer_type_node)) |
1680 | { | |
1681 | /* We have to be careful about biased types here. Make a subtype | |
1682 | of integer_type_node with the proper biasing. */ | |
1683 | if (TREE_CODE (param_type) == INTEGER_TYPE | |
1684 | && TYPE_BIASED_REPRESENTATION_P (param_type)) | |
1685 | { | |
84fb43a1 EB |
1686 | tree subtype |
1687 | = make_unsigned_type (TYPE_PRECISION (integer_type_node)); | |
c1abd261 EB |
1688 | TREE_TYPE (subtype) = integer_type_node; |
1689 | TYPE_BIASED_REPRESENTATION_P (subtype) = 1; | |
84fb43a1 EB |
1690 | SET_TYPE_RM_MIN_VALUE (subtype, TYPE_MIN_VALUE (param_type)); |
1691 | SET_TYPE_RM_MAX_VALUE (subtype, TYPE_MAX_VALUE (param_type)); | |
c1abd261 | 1692 | param_type = subtype; |
a1ab4c31 AC |
1693 | } |
1694 | else | |
1695 | param_type = integer_type_node; | |
1696 | } | |
1697 | ||
1698 | DECL_ARG_TYPE (param_decl) = param_type; | |
1699 | TREE_READONLY (param_decl) = readonly; | |
1700 | return param_decl; | |
1701 | } | |
1702 | \f | |
1703 | /* Given a DECL and ATTR_LIST, process the listed attributes. */ | |
1704 | ||
58c8f770 | 1705 | static void |
a1ab4c31 AC |
1706 | process_attributes (tree decl, struct attrib *attr_list) |
1707 | { | |
1708 | for (; attr_list; attr_list = attr_list->next) | |
1709 | switch (attr_list->type) | |
1710 | { | |
1711 | case ATTR_MACHINE_ATTRIBUTE: | |
58c8f770 | 1712 | input_location = DECL_SOURCE_LOCATION (decl); |
a1ab4c31 AC |
1713 | decl_attributes (&decl, tree_cons (attr_list->name, attr_list->args, |
1714 | NULL_TREE), | |
1715 | ATTR_FLAG_TYPE_IN_PLACE); | |
1716 | break; | |
1717 | ||
1718 | case ATTR_LINK_ALIAS: | |
1719 | if (! DECL_EXTERNAL (decl)) | |
1720 | { | |
1721 | TREE_STATIC (decl) = 1; | |
1722 | assemble_alias (decl, attr_list->name); | |
1723 | } | |
1724 | break; | |
1725 | ||
1726 | case ATTR_WEAK_EXTERNAL: | |
1727 | if (SUPPORTS_WEAK) | |
1728 | declare_weak (decl); | |
1729 | else | |
1730 | post_error ("?weak declarations not supported on this target", | |
1731 | attr_list->error_point); | |
1732 | break; | |
1733 | ||
1734 | case ATTR_LINK_SECTION: | |
677f3fa8 | 1735 | if (targetm_common.have_named_sections) |
a1ab4c31 AC |
1736 | { |
1737 | DECL_SECTION_NAME (decl) | |
1738 | = build_string (IDENTIFIER_LENGTH (attr_list->name), | |
1739 | IDENTIFIER_POINTER (attr_list->name)); | |
1740 | DECL_COMMON (decl) = 0; | |
1741 | } | |
1742 | else | |
1743 | post_error ("?section attributes are not supported for this target", | |
1744 | attr_list->error_point); | |
1745 | break; | |
1746 | ||
1747 | case ATTR_LINK_CONSTRUCTOR: | |
1748 | DECL_STATIC_CONSTRUCTOR (decl) = 1; | |
1749 | TREE_USED (decl) = 1; | |
1750 | break; | |
1751 | ||
1752 | case ATTR_LINK_DESTRUCTOR: | |
1753 | DECL_STATIC_DESTRUCTOR (decl) = 1; | |
1754 | TREE_USED (decl) = 1; | |
1755 | break; | |
40a14772 TG |
1756 | |
1757 | case ATTR_THREAD_LOCAL_STORAGE: | |
62298c61 TG |
1758 | DECL_TLS_MODEL (decl) = decl_default_tls_model (decl); |
1759 | DECL_COMMON (decl) = 0; | |
40a14772 | 1760 | break; |
a1ab4c31 AC |
1761 | } |
1762 | } | |
1763 | \f | |
feec4372 | 1764 | /* Record DECL as a global renaming pointer. */ |
a1ab4c31 AC |
1765 | |
1766 | void | |
1767 | record_global_renaming_pointer (tree decl) | |
1768 | { | |
15bf7d19 | 1769 | gcc_assert (!DECL_LOOP_PARM_P (decl) && DECL_RENAMED_OBJECT (decl)); |
a1ab4c31 AC |
1770 | VEC_safe_push (tree, gc, global_renaming_pointers, decl); |
1771 | } | |
1772 | ||
1773 | /* Invalidate the global renaming pointers. */ | |
1774 | ||
1775 | void | |
1776 | invalidate_global_renaming_pointers (void) | |
1777 | { | |
1778 | unsigned int i; | |
1779 | tree iter; | |
1780 | ||
ac47786e | 1781 | FOR_EACH_VEC_ELT (tree, global_renaming_pointers, i, iter) |
a1ab4c31 AC |
1782 | SET_DECL_RENAMED_OBJECT (iter, NULL_TREE); |
1783 | ||
1784 | VEC_free (tree, gc, global_renaming_pointers); | |
1785 | } | |
1786 | ||
1787 | /* Return true if VALUE is a known to be a multiple of FACTOR, which must be | |
1788 | a power of 2. */ | |
1789 | ||
1790 | bool | |
1791 | value_factor_p (tree value, HOST_WIDE_INT factor) | |
1792 | { | |
1793 | if (host_integerp (value, 1)) | |
1794 | return tree_low_cst (value, 1) % factor == 0; | |
1795 | ||
1796 | if (TREE_CODE (value) == MULT_EXPR) | |
1797 | return (value_factor_p (TREE_OPERAND (value, 0), factor) | |
1798 | || value_factor_p (TREE_OPERAND (value, 1), factor)); | |
1799 | ||
1800 | return false; | |
1801 | } | |
1802 | ||
7d7fcb08 | 1803 | /* Given two consecutive field decls PREV_FIELD and CURR_FIELD, return true |
a1ab4c31 AC |
1804 | unless we can prove these 2 fields are laid out in such a way that no gap |
1805 | exist between the end of PREV_FIELD and the beginning of CURR_FIELD. OFFSET | |
1806 | is the distance in bits between the end of PREV_FIELD and the starting | |
1807 | position of CURR_FIELD. It is ignored if null. */ | |
1808 | ||
1809 | static bool | |
1810 | potential_alignment_gap (tree prev_field, tree curr_field, tree offset) | |
1811 | { | |
1812 | /* If this is the first field of the record, there cannot be any gap */ | |
1813 | if (!prev_field) | |
1814 | return false; | |
1815 | ||
1816 | /* If the previous field is a union type, then return False: The only | |
1817 | time when such a field is not the last field of the record is when | |
1818 | there are other components at fixed positions after it (meaning there | |
1819 | was a rep clause for every field), in which case we don't want the | |
1820 | alignment constraint to override them. */ | |
1821 | if (TREE_CODE (TREE_TYPE (prev_field)) == QUAL_UNION_TYPE) | |
1822 | return false; | |
1823 | ||
1824 | /* If the distance between the end of prev_field and the beginning of | |
1825 | curr_field is constant, then there is a gap if the value of this | |
1826 | constant is not null. */ | |
1827 | if (offset && host_integerp (offset, 1)) | |
1828 | return !integer_zerop (offset); | |
1829 | ||
1830 | /* If the size and position of the previous field are constant, | |
1831 | then check the sum of this size and position. There will be a gap | |
1832 | iff it is not multiple of the current field alignment. */ | |
1833 | if (host_integerp (DECL_SIZE (prev_field), 1) | |
1834 | && host_integerp (bit_position (prev_field), 1)) | |
1835 | return ((tree_low_cst (bit_position (prev_field), 1) | |
1836 | + tree_low_cst (DECL_SIZE (prev_field), 1)) | |
1837 | % DECL_ALIGN (curr_field) != 0); | |
1838 | ||
1839 | /* If both the position and size of the previous field are multiples | |
1840 | of the current field alignment, there cannot be any gap. */ | |
1841 | if (value_factor_p (bit_position (prev_field), DECL_ALIGN (curr_field)) | |
1842 | && value_factor_p (DECL_SIZE (prev_field), DECL_ALIGN (curr_field))) | |
1843 | return false; | |
1844 | ||
1845 | /* Fallback, return that there may be a potential gap */ | |
1846 | return true; | |
1847 | } | |
1848 | ||
88a94e2b EB |
1849 | /* Return a LABEL_DECL with LABEL_NAME. GNAT_NODE is used for the position |
1850 | of the decl. */ | |
a1ab4c31 AC |
1851 | |
1852 | tree | |
88a94e2b | 1853 | create_label_decl (tree label_name, Node_Id gnat_node) |
a1ab4c31 | 1854 | { |
88a94e2b EB |
1855 | tree label_decl |
1856 | = build_decl (input_location, LABEL_DECL, label_name, void_type_node); | |
a1ab4c31 | 1857 | |
88a94e2b EB |
1858 | DECL_MODE (label_decl) = VOIDmode; |
1859 | ||
1860 | /* Add this decl to the current binding level. */ | |
1861 | gnat_pushdecl (label_decl, gnat_node); | |
a1ab4c31 AC |
1862 | |
1863 | return label_decl; | |
1864 | } | |
1865 | \f | |
7d7fcb08 | 1866 | /* Return a FUNCTION_DECL node. SUBPROG_NAME is the name of the subprogram, |
a1ab4c31 AC |
1867 | ASM_NAME is its assembler name, SUBPROG_TYPE is its type (a FUNCTION_TYPE |
1868 | node), PARAM_DECL_LIST is the list of the subprogram arguments (a list of | |
7d76717d | 1869 | PARM_DECL nodes chained through the DECL_CHAIN field). |
a1ab4c31 | 1870 | |
7d7fcb08 EB |
1871 | INLINE_FLAG, PUBLIC_FLAG, EXTERN_FLAG, ARTIFICIAL_FLAG and ATTR_LIST are |
1872 | used to set the appropriate fields in the FUNCTION_DECL. GNAT_NODE is | |
1873 | used for the position of the decl. */ | |
a1ab4c31 AC |
1874 | |
1875 | tree | |
7d7fcb08 EB |
1876 | create_subprog_decl (tree subprog_name, tree asm_name, tree subprog_type, |
1877 | tree param_decl_list, bool inline_flag, bool public_flag, | |
1878 | bool extern_flag, bool artificial_flag, | |
1879 | struct attrib *attr_list, Node_Id gnat_node) | |
a1ab4c31 | 1880 | { |
d47d0a8d EB |
1881 | tree subprog_decl = build_decl (input_location, FUNCTION_DECL, subprog_name, |
1882 | subprog_type); | |
1883 | tree result_decl = build_decl (input_location, RESULT_DECL, NULL_TREE, | |
1884 | TREE_TYPE (subprog_type)); | |
7d7fcb08 | 1885 | DECL_ARGUMENTS (subprog_decl) = param_decl_list; |
a1ab4c31 | 1886 | |
d84b344a EB |
1887 | /* If this is a non-inline function nested inside an inlined external |
1888 | function, we cannot honor both requests without cloning the nested | |
1889 | function in the current unit since it is private to the other unit. | |
1890 | We could inline the nested function as well but it's probably better | |
1891 | to err on the side of too little inlining. */ | |
1892 | if (!inline_flag | |
5daed84a | 1893 | && !public_flag |
d84b344a EB |
1894 | && current_function_decl |
1895 | && DECL_DECLARED_INLINE_P (current_function_decl) | |
a1ab4c31 | 1896 | && DECL_EXTERNAL (current_function_decl)) |
d84b344a | 1897 | DECL_DECLARED_INLINE_P (current_function_decl) = 0; |
a1ab4c31 | 1898 | |
7d7fcb08 EB |
1899 | DECL_ARTIFICIAL (subprog_decl) = artificial_flag; |
1900 | DECL_EXTERNAL (subprog_decl) = extern_flag; | |
1901 | DECL_DECLARED_INLINE_P (subprog_decl) = inline_flag; | |
1902 | DECL_NO_INLINE_WARNING_P (subprog_decl) = inline_flag && artificial_flag; | |
1903 | ||
1904 | TREE_PUBLIC (subprog_decl) = public_flag; | |
1905 | TREE_READONLY (subprog_decl) = TYPE_READONLY (subprog_type); | |
a1ab4c31 AC |
1906 | TREE_THIS_VOLATILE (subprog_decl) = TYPE_VOLATILE (subprog_type); |
1907 | TREE_SIDE_EFFECTS (subprog_decl) = TYPE_VOLATILE (subprog_type); | |
a1ab4c31 | 1908 | |
d47d0a8d EB |
1909 | DECL_ARTIFICIAL (result_decl) = 1; |
1910 | DECL_IGNORED_P (result_decl) = 1; | |
1911 | DECL_BY_REFERENCE (result_decl) = TREE_ADDRESSABLE (subprog_type); | |
1912 | DECL_RESULT (subprog_decl) = result_decl; | |
a1ab4c31 | 1913 | |
a1ab4c31 AC |
1914 | if (asm_name) |
1915 | { | |
1916 | SET_DECL_ASSEMBLER_NAME (subprog_decl, asm_name); | |
1917 | ||
1918 | /* The expand_main_function circuitry expects "main_identifier_node" to | |
1919 | designate the DECL_NAME of the 'main' entry point, in turn expected | |
1920 | to be declared as the "main" function literally by default. Ada | |
1921 | program entry points are typically declared with a different name | |
1922 | within the binder generated file, exported as 'main' to satisfy the | |
cfbb663c | 1923 | system expectations. Force main_identifier_node in this case. */ |
a1ab4c31 | 1924 | if (asm_name == main_identifier_node) |
cfbb663c | 1925 | DECL_NAME (subprog_decl) = main_identifier_node; |
a1ab4c31 AC |
1926 | } |
1927 | ||
a1ab4c31 AC |
1928 | /* Add this decl to the current binding level. */ |
1929 | gnat_pushdecl (subprog_decl, gnat_node); | |
1930 | ||
58c8f770 EB |
1931 | process_attributes (subprog_decl, attr_list); |
1932 | ||
a1ab4c31 AC |
1933 | /* Output the assembler code and/or RTL for the declaration. */ |
1934 | rest_of_decl_compilation (subprog_decl, global_bindings_p (), 0); | |
1935 | ||
1936 | return subprog_decl; | |
1937 | } | |
1938 | \f | |
1939 | /* Set up the framework for generating code for SUBPROG_DECL, a subprogram | |
1940 | body. This routine needs to be invoked before processing the declarations | |
1941 | appearing in the subprogram. */ | |
1942 | ||
1943 | void | |
1944 | begin_subprog_body (tree subprog_decl) | |
1945 | { | |
1946 | tree param_decl; | |
1947 | ||
a1ab4c31 AC |
1948 | announce_function (subprog_decl); |
1949 | ||
0ae44446 JR |
1950 | /* This function is being defined. */ |
1951 | TREE_STATIC (subprog_decl) = 1; | |
1952 | ||
58c8f770 EB |
1953 | current_function_decl = subprog_decl; |
1954 | ||
a1ab4c31 AC |
1955 | /* Enter a new binding level and show that all the parameters belong to |
1956 | this function. */ | |
1957 | gnat_pushlevel (); | |
a09d56d8 | 1958 | |
a1ab4c31 | 1959 | for (param_decl = DECL_ARGUMENTS (subprog_decl); param_decl; |
910ad8de | 1960 | param_decl = DECL_CHAIN (param_decl)) |
a1ab4c31 AC |
1961 | DECL_CONTEXT (param_decl) = subprog_decl; |
1962 | ||
1963 | make_decl_rtl (subprog_decl); | |
a1ab4c31 AC |
1964 | } |
1965 | ||
71196d4e | 1966 | /* Finish translating the current subprogram and set its BODY. */ |
a1ab4c31 AC |
1967 | |
1968 | void | |
a406865a | 1969 | end_subprog_body (tree body) |
a1ab4c31 AC |
1970 | { |
1971 | tree fndecl = current_function_decl; | |
1972 | ||
bd9c7fb9 | 1973 | /* Attach the BLOCK for this level to the function and pop the level. */ |
a1ab4c31 AC |
1974 | BLOCK_SUPERCONTEXT (current_binding_level->block) = fndecl; |
1975 | DECL_INITIAL (fndecl) = current_binding_level->block; | |
1976 | gnat_poplevel (); | |
1977 | ||
a1ab4c31 AC |
1978 | /* Mark the RESULT_DECL as being in this subprogram. */ |
1979 | DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; | |
1980 | ||
a963da4d EB |
1981 | /* The body should be a BIND_EXPR whose BLOCK is the top-level one. */ |
1982 | if (TREE_CODE (body) == BIND_EXPR) | |
1983 | { | |
1984 | BLOCK_SUPERCONTEXT (BIND_EXPR_BLOCK (body)) = fndecl; | |
1985 | DECL_INITIAL (fndecl) = BIND_EXPR_BLOCK (body); | |
1986 | } | |
1987 | ||
a1ab4c31 AC |
1988 | DECL_SAVED_TREE (fndecl) = body; |
1989 | ||
228ee426 | 1990 | current_function_decl = decl_function_context (fndecl); |
71196d4e EB |
1991 | } |
1992 | ||
1993 | /* Wrap up compilation of SUBPROG_DECL, a subprogram body. */ | |
a1ab4c31 | 1994 | |
71196d4e EB |
1995 | void |
1996 | rest_of_subprog_body_compilation (tree subprog_decl) | |
1997 | { | |
a1ab4c31 AC |
1998 | /* We cannot track the location of errors past this point. */ |
1999 | error_gnat_node = Empty; | |
2000 | ||
2001 | /* If we're only annotating types, don't actually compile this function. */ | |
2002 | if (type_annotate_only) | |
2003 | return; | |
2004 | ||
a406865a | 2005 | /* Dump functions before gimplification. */ |
71196d4e | 2006 | dump_function (TDI_original, subprog_decl); |
a406865a | 2007 | |
2fa03086 | 2008 | /* ??? This special handling of nested functions is probably obsolete. */ |
228ee426 | 2009 | if (!decl_function_context (subprog_decl)) |
71196d4e | 2010 | cgraph_finalize_function (subprog_decl, false); |
a1ab4c31 AC |
2011 | else |
2012 | /* Register this function with cgraph just far enough to get it | |
2013 | added to our parent's nested function list. */ | |
71196d4e | 2014 | (void) cgraph_get_create_node (subprog_decl); |
a1ab4c31 AC |
2015 | } |
2016 | ||
a1ab4c31 AC |
2017 | tree |
2018 | gnat_builtin_function (tree decl) | |
2019 | { | |
2020 | gnat_pushdecl (decl, Empty); | |
2021 | return decl; | |
2022 | } | |
2023 | ||
2024 | /* Return an integer type with the number of bits of precision given by | |
2025 | PRECISION. UNSIGNEDP is nonzero if the type is unsigned; otherwise | |
2026 | it is a signed type. */ | |
2027 | ||
2028 | tree | |
2029 | gnat_type_for_size (unsigned precision, int unsignedp) | |
2030 | { | |
2031 | tree t; | |
2032 | char type_name[20]; | |
2033 | ||
2034 | if (precision <= 2 * MAX_BITS_PER_WORD | |
2035 | && signed_and_unsigned_types[precision][unsignedp]) | |
2036 | return signed_and_unsigned_types[precision][unsignedp]; | |
2037 | ||
2038 | if (unsignedp) | |
2039 | t = make_unsigned_type (precision); | |
2040 | else | |
2041 | t = make_signed_type (precision); | |
2042 | ||
2043 | if (precision <= 2 * MAX_BITS_PER_WORD) | |
2044 | signed_and_unsigned_types[precision][unsignedp] = t; | |
2045 | ||
2046 | if (!TYPE_NAME (t)) | |
2047 | { | |
2048 | sprintf (type_name, "%sSIGNED_%d", unsignedp ? "UN" : "", precision); | |
2049 | TYPE_NAME (t) = get_identifier (type_name); | |
2050 | } | |
2051 | ||
2052 | return t; | |
2053 | } | |
2054 | ||
2055 | /* Likewise for floating-point types. */ | |
2056 | ||
2057 | static tree | |
2058 | float_type_for_precision (int precision, enum machine_mode mode) | |
2059 | { | |
2060 | tree t; | |
2061 | char type_name[20]; | |
2062 | ||
2063 | if (float_types[(int) mode]) | |
2064 | return float_types[(int) mode]; | |
2065 | ||
2066 | float_types[(int) mode] = t = make_node (REAL_TYPE); | |
2067 | TYPE_PRECISION (t) = precision; | |
2068 | layout_type (t); | |
2069 | ||
2070 | gcc_assert (TYPE_MODE (t) == mode); | |
2071 | if (!TYPE_NAME (t)) | |
2072 | { | |
2073 | sprintf (type_name, "FLOAT_%d", precision); | |
2074 | TYPE_NAME (t) = get_identifier (type_name); | |
2075 | } | |
2076 | ||
2077 | return t; | |
2078 | } | |
2079 | ||
2080 | /* Return a data type that has machine mode MODE. UNSIGNEDP selects | |
2081 | an unsigned type; otherwise a signed type is returned. */ | |
2082 | ||
2083 | tree | |
2084 | gnat_type_for_mode (enum machine_mode mode, int unsignedp) | |
2085 | { | |
2086 | if (mode == BLKmode) | |
2087 | return NULL_TREE; | |
2799d18c EB |
2088 | |
2089 | if (mode == VOIDmode) | |
a1ab4c31 | 2090 | return void_type_node; |
2799d18c EB |
2091 | |
2092 | if (COMPLEX_MODE_P (mode)) | |
a1ab4c31 | 2093 | return NULL_TREE; |
2799d18c EB |
2094 | |
2095 | if (SCALAR_FLOAT_MODE_P (mode)) | |
a1ab4c31 | 2096 | return float_type_for_precision (GET_MODE_PRECISION (mode), mode); |
2799d18c EB |
2097 | |
2098 | if (SCALAR_INT_MODE_P (mode)) | |
a1ab4c31 | 2099 | return gnat_type_for_size (GET_MODE_BITSIZE (mode), unsignedp); |
2799d18c EB |
2100 | |
2101 | if (VECTOR_MODE_P (mode)) | |
2102 | { | |
2103 | enum machine_mode inner_mode = GET_MODE_INNER (mode); | |
2104 | tree inner_type = gnat_type_for_mode (inner_mode, unsignedp); | |
2105 | if (inner_type) | |
2106 | return build_vector_type_for_mode (inner_type, mode); | |
2107 | } | |
2108 | ||
2109 | return NULL_TREE; | |
a1ab4c31 AC |
2110 | } |
2111 | ||
2112 | /* Return the unsigned version of a TYPE_NODE, a scalar type. */ | |
2113 | ||
2114 | tree | |
2115 | gnat_unsigned_type (tree type_node) | |
2116 | { | |
2117 | tree type = gnat_type_for_size (TYPE_PRECISION (type_node), 1); | |
2118 | ||
2119 | if (TREE_CODE (type_node) == INTEGER_TYPE && TYPE_MODULAR_P (type_node)) | |
2120 | { | |
2121 | type = copy_node (type); | |
2122 | TREE_TYPE (type) = type_node; | |
2123 | } | |
2124 | else if (TREE_TYPE (type_node) | |
2125 | && TREE_CODE (TREE_TYPE (type_node)) == INTEGER_TYPE | |
2126 | && TYPE_MODULAR_P (TREE_TYPE (type_node))) | |
2127 | { | |
2128 | type = copy_node (type); | |
2129 | TREE_TYPE (type) = TREE_TYPE (type_node); | |
2130 | } | |
2131 | ||
2132 | return type; | |
2133 | } | |
2134 | ||
2135 | /* Return the signed version of a TYPE_NODE, a scalar type. */ | |
2136 | ||
2137 | tree | |
2138 | gnat_signed_type (tree type_node) | |
2139 | { | |
2140 | tree type = gnat_type_for_size (TYPE_PRECISION (type_node), 0); | |
2141 | ||
2142 | if (TREE_CODE (type_node) == INTEGER_TYPE && TYPE_MODULAR_P (type_node)) | |
2143 | { | |
2144 | type = copy_node (type); | |
2145 | TREE_TYPE (type) = type_node; | |
2146 | } | |
2147 | else if (TREE_TYPE (type_node) | |
2148 | && TREE_CODE (TREE_TYPE (type_node)) == INTEGER_TYPE | |
2149 | && TYPE_MODULAR_P (TREE_TYPE (type_node))) | |
2150 | { | |
2151 | type = copy_node (type); | |
2152 | TREE_TYPE (type) = TREE_TYPE (type_node); | |
2153 | } | |
2154 | ||
2155 | return type; | |
2156 | } | |
2157 | ||
2158 | /* Return 1 if the types T1 and T2 are compatible, i.e. if they can be | |
2159 | transparently converted to each other. */ | |
2160 | ||
2161 | int | |
2162 | gnat_types_compatible_p (tree t1, tree t2) | |
2163 | { | |
2164 | enum tree_code code; | |
2165 | ||
2166 | /* This is the default criterion. */ | |
2167 | if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2)) | |
2168 | return 1; | |
2169 | ||
2170 | /* We only check structural equivalence here. */ | |
2171 | if ((code = TREE_CODE (t1)) != TREE_CODE (t2)) | |
2172 | return 0; | |
2173 | ||
7948ae37 OH |
2174 | /* Vector types are also compatible if they have the same number of subparts |
2175 | and the same form of (scalar) element type. */ | |
2176 | if (code == VECTOR_TYPE | |
2177 | && TYPE_VECTOR_SUBPARTS (t1) == TYPE_VECTOR_SUBPARTS (t2) | |
2178 | && TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)) | |
2179 | && TYPE_PRECISION (TREE_TYPE (t1)) == TYPE_PRECISION (TREE_TYPE (t2))) | |
2180 | return 1; | |
2181 | ||
cfa0bd19 | 2182 | /* Array types are also compatible if they are constrained and have the same |
96bba5e6 | 2183 | domain(s) and the same component type. */ |
a1ab4c31 | 2184 | if (code == ARRAY_TYPE |
0adef32b JJ |
2185 | && (TYPE_DOMAIN (t1) == TYPE_DOMAIN (t2) |
2186 | || (TYPE_DOMAIN (t1) | |
b4680ca1 | 2187 | && TYPE_DOMAIN (t2) |
0adef32b JJ |
2188 | && tree_int_cst_equal (TYPE_MIN_VALUE (TYPE_DOMAIN (t1)), |
2189 | TYPE_MIN_VALUE (TYPE_DOMAIN (t2))) | |
2190 | && tree_int_cst_equal (TYPE_MAX_VALUE (TYPE_DOMAIN (t1)), | |
cfa0bd19 | 2191 | TYPE_MAX_VALUE (TYPE_DOMAIN (t2))))) |
96bba5e6 EB |
2192 | && (TREE_TYPE (t1) == TREE_TYPE (t2) |
2193 | || (TREE_CODE (TREE_TYPE (t1)) == ARRAY_TYPE | |
2194 | && gnat_types_compatible_p (TREE_TYPE (t1), TREE_TYPE (t2))))) | |
a1ab4c31 AC |
2195 | return 1; |
2196 | ||
2197 | /* Padding record types are also compatible if they pad the same | |
2198 | type and have the same constant size. */ | |
2199 | if (code == RECORD_TYPE | |
315cff15 | 2200 | && TYPE_PADDING_P (t1) && TYPE_PADDING_P (t2) |
a1ab4c31 AC |
2201 | && TREE_TYPE (TYPE_FIELDS (t1)) == TREE_TYPE (TYPE_FIELDS (t2)) |
2202 | && tree_int_cst_equal (TYPE_SIZE (t1), TYPE_SIZE (t2))) | |
2203 | return 1; | |
2204 | ||
2205 | return 0; | |
2206 | } | |
523e82a7 | 2207 | |
71196d4e EB |
2208 | /* Return true if EXPR is a useless type conversion. */ |
2209 | ||
2210 | bool | |
2211 | gnat_useless_type_conversion (tree expr) | |
2212 | { | |
2213 | if (CONVERT_EXPR_P (expr) | |
2214 | || TREE_CODE (expr) == VIEW_CONVERT_EXPR | |
2215 | || TREE_CODE (expr) == NON_LVALUE_EXPR) | |
2216 | return gnat_types_compatible_p (TREE_TYPE (expr), | |
2217 | TREE_TYPE (TREE_OPERAND (expr, 0))); | |
2218 | ||
2219 | return false; | |
2220 | } | |
2221 | ||
523e82a7 EB |
2222 | /* Return true if T, a FUNCTION_TYPE, has the specified list of flags. */ |
2223 | ||
2224 | bool | |
2225 | fntype_same_flags_p (const_tree t, tree cico_list, bool return_unconstrained_p, | |
2226 | bool return_by_direct_ref_p, bool return_by_invisi_ref_p) | |
2227 | { | |
2228 | return TYPE_CI_CO_LIST (t) == cico_list | |
2229 | && TYPE_RETURN_UNCONSTRAINED_P (t) == return_unconstrained_p | |
2230 | && TYPE_RETURN_BY_DIRECT_REF_P (t) == return_by_direct_ref_p | |
2231 | && TREE_ADDRESSABLE (t) == return_by_invisi_ref_p; | |
2232 | } | |
a1ab4c31 AC |
2233 | \f |
2234 | /* EXP is an expression for the size of an object. If this size contains | |
2235 | discriminant references, replace them with the maximum (if MAX_P) or | |
2236 | minimum (if !MAX_P) possible value of the discriminant. */ | |
2237 | ||
2238 | tree | |
2239 | max_size (tree exp, bool max_p) | |
2240 | { | |
2241 | enum tree_code code = TREE_CODE (exp); | |
2242 | tree type = TREE_TYPE (exp); | |
2243 | ||
2244 | switch (TREE_CODE_CLASS (code)) | |
2245 | { | |
2246 | case tcc_declaration: | |
2247 | case tcc_constant: | |
2248 | return exp; | |
2249 | ||
2250 | case tcc_vl_exp: | |
2251 | if (code == CALL_EXPR) | |
2252 | { | |
f82a627c EB |
2253 | tree t, *argarray; |
2254 | int n, i; | |
2255 | ||
2256 | t = maybe_inline_call_in_expr (exp); | |
2257 | if (t) | |
2258 | return max_size (t, max_p); | |
a1ab4c31 | 2259 | |
f82a627c EB |
2260 | n = call_expr_nargs (exp); |
2261 | gcc_assert (n > 0); | |
2bb1fc26 | 2262 | argarray = XALLOCAVEC (tree, n); |
a1ab4c31 AC |
2263 | for (i = 0; i < n; i++) |
2264 | argarray[i] = max_size (CALL_EXPR_ARG (exp, i), max_p); | |
2265 | return build_call_array (type, CALL_EXPR_FN (exp), n, argarray); | |
2266 | } | |
2267 | break; | |
2268 | ||
2269 | case tcc_reference: | |
2270 | /* If this contains a PLACEHOLDER_EXPR, it is the thing we want to | |
2271 | modify. Otherwise, we treat it like a variable. */ | |
2272 | if (!CONTAINS_PLACEHOLDER_P (exp)) | |
2273 | return exp; | |
2274 | ||
2275 | type = TREE_TYPE (TREE_OPERAND (exp, 1)); | |
2276 | return | |
2277 | max_size (max_p ? TYPE_MAX_VALUE (type) : TYPE_MIN_VALUE (type), true); | |
2278 | ||
2279 | case tcc_comparison: | |
2280 | return max_p ? size_one_node : size_zero_node; | |
2281 | ||
2282 | case tcc_unary: | |
2283 | case tcc_binary: | |
2284 | case tcc_expression: | |
2285 | switch (TREE_CODE_LENGTH (code)) | |
2286 | { | |
2287 | case 1: | |
722356ce EB |
2288 | if (code == SAVE_EXPR) |
2289 | return exp; | |
2290 | else if (code == NON_LVALUE_EXPR) | |
a1ab4c31 AC |
2291 | return max_size (TREE_OPERAND (exp, 0), max_p); |
2292 | else | |
2293 | return | |
2294 | fold_build1 (code, type, | |
2295 | max_size (TREE_OPERAND (exp, 0), | |
2296 | code == NEGATE_EXPR ? !max_p : max_p)); | |
2297 | ||
2298 | case 2: | |
2299 | if (code == COMPOUND_EXPR) | |
2300 | return max_size (TREE_OPERAND (exp, 1), max_p); | |
2301 | ||
a1ab4c31 AC |
2302 | { |
2303 | tree lhs = max_size (TREE_OPERAND (exp, 0), max_p); | |
2304 | tree rhs = max_size (TREE_OPERAND (exp, 1), | |
2305 | code == MINUS_EXPR ? !max_p : max_p); | |
2306 | ||
2307 | /* Special-case wanting the maximum value of a MIN_EXPR. | |
2308 | In that case, if one side overflows, return the other. | |
2309 | sizetype is signed, but we know sizes are non-negative. | |
2310 | Likewise, handle a MINUS_EXPR or PLUS_EXPR with the LHS | |
586388fd | 2311 | overflowing and the RHS a variable. */ |
a1ab4c31 AC |
2312 | if (max_p |
2313 | && code == MIN_EXPR | |
2314 | && TREE_CODE (rhs) == INTEGER_CST | |
2315 | && TREE_OVERFLOW (rhs)) | |
2316 | return lhs; | |
2317 | else if (max_p | |
2318 | && code == MIN_EXPR | |
2319 | && TREE_CODE (lhs) == INTEGER_CST | |
2320 | && TREE_OVERFLOW (lhs)) | |
2321 | return rhs; | |
2322 | else if ((code == MINUS_EXPR || code == PLUS_EXPR) | |
586388fd EB |
2323 | && TREE_CODE (lhs) == INTEGER_CST |
2324 | && TREE_OVERFLOW (lhs) | |
a1ab4c31 AC |
2325 | && !TREE_CONSTANT (rhs)) |
2326 | return lhs; | |
2327 | else | |
2328 | return fold_build2 (code, type, lhs, rhs); | |
2329 | } | |
2330 | ||
2331 | case 3: | |
722356ce | 2332 | if (code == COND_EXPR) |
a1ab4c31 AC |
2333 | return fold_build2 (max_p ? MAX_EXPR : MIN_EXPR, type, |
2334 | max_size (TREE_OPERAND (exp, 1), max_p), | |
2335 | max_size (TREE_OPERAND (exp, 2), max_p)); | |
2336 | } | |
2337 | ||
2338 | /* Other tree classes cannot happen. */ | |
2339 | default: | |
2340 | break; | |
2341 | } | |
2342 | ||
2343 | gcc_unreachable (); | |
2344 | } | |
2345 | \f | |
2346 | /* Build a template of type TEMPLATE_TYPE from the array bounds of ARRAY_TYPE. | |
2347 | EXPR is an expression that we can use to locate any PLACEHOLDER_EXPRs. | |
2348 | Return a constructor for the template. */ | |
2349 | ||
2350 | tree | |
2351 | build_template (tree template_type, tree array_type, tree expr) | |
2352 | { | |
0e228dd9 | 2353 | VEC(constructor_elt,gc) *template_elts = NULL; |
a1ab4c31 AC |
2354 | tree bound_list = NULL_TREE; |
2355 | tree field; | |
2356 | ||
2357 | while (TREE_CODE (array_type) == RECORD_TYPE | |
315cff15 | 2358 | && (TYPE_PADDING_P (array_type) |
a1ab4c31 AC |
2359 | || TYPE_JUSTIFIED_MODULAR_P (array_type))) |
2360 | array_type = TREE_TYPE (TYPE_FIELDS (array_type)); | |
2361 | ||
2362 | if (TREE_CODE (array_type) == ARRAY_TYPE | |
2363 | || (TREE_CODE (array_type) == INTEGER_TYPE | |
2364 | && TYPE_HAS_ACTUAL_BOUNDS_P (array_type))) | |
2365 | bound_list = TYPE_ACTUAL_BOUNDS (array_type); | |
2366 | ||
2367 | /* First make the list for a CONSTRUCTOR for the template. Go down the | |
2368 | field list of the template instead of the type chain because this | |
2369 | array might be an Ada array of arrays and we can't tell where the | |
2370 | nested arrays stop being the underlying object. */ | |
2371 | ||
2372 | for (field = TYPE_FIELDS (template_type); field; | |
2373 | (bound_list | |
2374 | ? (bound_list = TREE_CHAIN (bound_list)) | |
2375 | : (array_type = TREE_TYPE (array_type))), | |
910ad8de | 2376 | field = DECL_CHAIN (DECL_CHAIN (field))) |
a1ab4c31 AC |
2377 | { |
2378 | tree bounds, min, max; | |
2379 | ||
2380 | /* If we have a bound list, get the bounds from there. Likewise | |
2381 | for an ARRAY_TYPE. Otherwise, if expr is a PARM_DECL with | |
2382 | DECL_BY_COMPONENT_PTR_P, use the bounds of the field in the template. | |
2383 | This will give us a maximum range. */ | |
2384 | if (bound_list) | |
2385 | bounds = TREE_VALUE (bound_list); | |
2386 | else if (TREE_CODE (array_type) == ARRAY_TYPE) | |
2387 | bounds = TYPE_INDEX_TYPE (TYPE_DOMAIN (array_type)); | |
2388 | else if (expr && TREE_CODE (expr) == PARM_DECL | |
2389 | && DECL_BY_COMPONENT_PTR_P (expr)) | |
2390 | bounds = TREE_TYPE (field); | |
2391 | else | |
2392 | gcc_unreachable (); | |
2393 | ||
2394 | min = convert (TREE_TYPE (field), TYPE_MIN_VALUE (bounds)); | |
910ad8de | 2395 | max = convert (TREE_TYPE (DECL_CHAIN (field)), TYPE_MAX_VALUE (bounds)); |
a1ab4c31 AC |
2396 | |
2397 | /* If either MIN or MAX involve a PLACEHOLDER_EXPR, we must | |
2398 | substitute it from OBJECT. */ | |
2399 | min = SUBSTITUTE_PLACEHOLDER_IN_EXPR (min, expr); | |
2400 | max = SUBSTITUTE_PLACEHOLDER_IN_EXPR (max, expr); | |
2401 | ||
0e228dd9 | 2402 | CONSTRUCTOR_APPEND_ELT (template_elts, field, min); |
910ad8de | 2403 | CONSTRUCTOR_APPEND_ELT (template_elts, DECL_CHAIN (field), max); |
a1ab4c31 AC |
2404 | } |
2405 | ||
0e228dd9 | 2406 | return gnat_build_constructor (template_type, template_elts); |
a1ab4c31 AC |
2407 | } |
2408 | \f | |
31a5a547 EB |
2409 | /* Helper routine to make a descriptor field. FIELD_LIST is the list of decls |
2410 | being built; the new decl is chained on to the front of the list. */ | |
2411 | ||
2412 | static tree | |
2413 | make_descriptor_field (const char *name, tree type, tree rec_type, | |
2414 | tree initial, tree field_list) | |
2415 | { | |
2416 | tree field | |
2417 | = create_field_decl (get_identifier (name), type, rec_type, NULL_TREE, | |
2418 | NULL_TREE, 0, 0); | |
2419 | ||
2420 | DECL_INITIAL (field) = initial; | |
2421 | DECL_CHAIN (field) = field_list; | |
2422 | return field; | |
2423 | } | |
2424 | ||
58c8f770 EB |
2425 | /* Build a 32-bit VMS descriptor from a Mechanism_Type, which must specify a |
2426 | descriptor type, and the GCC type of an object. Each FIELD_DECL in the | |
2427 | type contains in its DECL_INITIAL the expression to use when a constructor | |
2428 | is made for the type. GNAT_ENTITY is an entity used to print out an error | |
2429 | message if the mechanism cannot be applied to an object of that type and | |
2430 | also for the name. */ | |
a1ab4c31 AC |
2431 | |
2432 | tree | |
d628c015 | 2433 | build_vms_descriptor32 (tree type, Mechanism_Type mech, Entity_Id gnat_entity) |
a1ab4c31 AC |
2434 | { |
2435 | tree record_type = make_node (RECORD_TYPE); | |
31a5a547 | 2436 | tree pointer32_type, pointer64_type; |
788e5046 | 2437 | tree field_list = NULL_TREE; |
31a5a547 EB |
2438 | int klass, ndim, i, dtype = 0; |
2439 | tree inner_type, tem; | |
a1ab4c31 | 2440 | tree *idx_arr; |
a1ab4c31 AC |
2441 | |
2442 | /* If TYPE is an unconstrained array, use the underlying array type. */ | |
2443 | if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE) | |
2444 | type = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))); | |
2445 | ||
2446 | /* If this is an array, compute the number of dimensions in the array, | |
2447 | get the index types, and point to the inner type. */ | |
2448 | if (TREE_CODE (type) != ARRAY_TYPE) | |
2449 | ndim = 0; | |
2450 | else | |
2451 | for (ndim = 1, inner_type = type; | |
2452 | TREE_CODE (TREE_TYPE (inner_type)) == ARRAY_TYPE | |
2453 | && TYPE_MULTI_ARRAY_P (TREE_TYPE (inner_type)); | |
2454 | ndim++, inner_type = TREE_TYPE (inner_type)) | |
2455 | ; | |
2456 | ||
2bb1fc26 | 2457 | idx_arr = XALLOCAVEC (tree, ndim); |
a1ab4c31 | 2458 | |
d628c015 | 2459 | if (mech != By_Descriptor_NCA && mech != By_Short_Descriptor_NCA |
a1ab4c31 AC |
2460 | && TREE_CODE (type) == ARRAY_TYPE && TYPE_CONVENTION_FORTRAN_P (type)) |
2461 | for (i = ndim - 1, inner_type = type; | |
2462 | i >= 0; | |
2463 | i--, inner_type = TREE_TYPE (inner_type)) | |
2464 | idx_arr[i] = TYPE_DOMAIN (inner_type); | |
2465 | else | |
2466 | for (i = 0, inner_type = type; | |
2467 | i < ndim; | |
2468 | i++, inner_type = TREE_TYPE (inner_type)) | |
2469 | idx_arr[i] = TYPE_DOMAIN (inner_type); | |
2470 | ||
2471 | /* Now get the DTYPE value. */ | |
2472 | switch (TREE_CODE (type)) | |
2473 | { | |
2474 | case INTEGER_TYPE: | |
2475 | case ENUMERAL_TYPE: | |
01ddebf2 | 2476 | case BOOLEAN_TYPE: |
a1ab4c31 AC |
2477 | if (TYPE_VAX_FLOATING_POINT_P (type)) |
2478 | switch (tree_low_cst (TYPE_DIGITS_VALUE (type), 1)) | |
2479 | { | |
2480 | case 6: | |
2481 | dtype = 10; | |
2482 | break; | |
2483 | case 9: | |
2484 | dtype = 11; | |
2485 | break; | |
2486 | case 15: | |
2487 | dtype = 27; | |
2488 | break; | |
2489 | } | |
2490 | else | |
2491 | switch (GET_MODE_BITSIZE (TYPE_MODE (type))) | |
2492 | { | |
2493 | case 8: | |
2494 | dtype = TYPE_UNSIGNED (type) ? 2 : 6; | |
2495 | break; | |
2496 | case 16: | |
2497 | dtype = TYPE_UNSIGNED (type) ? 3 : 7; | |
2498 | break; | |
2499 | case 32: | |
2500 | dtype = TYPE_UNSIGNED (type) ? 4 : 8; | |
2501 | break; | |
2502 | case 64: | |
2503 | dtype = TYPE_UNSIGNED (type) ? 5 : 9; | |
2504 | break; | |
2505 | case 128: | |
2506 | dtype = TYPE_UNSIGNED (type) ? 25 : 26; | |
2507 | break; | |
2508 | } | |
2509 | break; | |
2510 | ||
2511 | case REAL_TYPE: | |
2512 | dtype = GET_MODE_BITSIZE (TYPE_MODE (type)) == 32 ? 52 : 53; | |
2513 | break; | |
2514 | ||
2515 | case COMPLEX_TYPE: | |
2516 | if (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE | |
2517 | && TYPE_VAX_FLOATING_POINT_P (type)) | |
2518 | switch (tree_low_cst (TYPE_DIGITS_VALUE (type), 1)) | |
2519 | { | |
2520 | case 6: | |
2521 | dtype = 12; | |
2522 | break; | |
2523 | case 9: | |
2524 | dtype = 13; | |
2525 | break; | |
2526 | case 15: | |
2527 | dtype = 29; | |
2528 | } | |
2529 | else | |
2530 | dtype = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) == 32 ? 54: 55; | |
2531 | break; | |
2532 | ||
2533 | case ARRAY_TYPE: | |
2534 | dtype = 14; | |
2535 | break; | |
2536 | ||
2537 | default: | |
2538 | break; | |
2539 | } | |
2540 | ||
2541 | /* Get the CLASS value. */ | |
2542 | switch (mech) | |
2543 | { | |
2544 | case By_Descriptor_A: | |
d628c015 | 2545 | case By_Short_Descriptor_A: |
c6bd4220 | 2546 | klass = 4; |
a1ab4c31 AC |
2547 | break; |
2548 | case By_Descriptor_NCA: | |
d628c015 | 2549 | case By_Short_Descriptor_NCA: |
c6bd4220 | 2550 | klass = 10; |
a1ab4c31 AC |
2551 | break; |
2552 | case By_Descriptor_SB: | |
d628c015 | 2553 | case By_Short_Descriptor_SB: |
c6bd4220 | 2554 | klass = 15; |
a1ab4c31 AC |
2555 | break; |
2556 | case By_Descriptor: | |
d628c015 | 2557 | case By_Short_Descriptor: |
a1ab4c31 | 2558 | case By_Descriptor_S: |
d628c015 | 2559 | case By_Short_Descriptor_S: |
a1ab4c31 | 2560 | default: |
c6bd4220 | 2561 | klass = 1; |
a1ab4c31 AC |
2562 | break; |
2563 | } | |
2564 | ||
58c8f770 EB |
2565 | /* Make the type for a descriptor for VMS. The first four fields are the |
2566 | same for all types. */ | |
82b481ed EB |
2567 | field_list |
2568 | = make_descriptor_field ("LENGTH", gnat_type_for_size (16, 1), record_type, | |
2569 | size_in_bytes ((mech == By_Descriptor_A | |
2570 | || mech == By_Short_Descriptor_A) | |
2571 | ? inner_type : type), | |
2572 | field_list); | |
2573 | field_list | |
2574 | = make_descriptor_field ("DTYPE", gnat_type_for_size (8, 1), record_type, | |
2575 | size_int (dtype), field_list); | |
2576 | field_list | |
2577 | = make_descriptor_field ("CLASS", gnat_type_for_size (8, 1), record_type, | |
2578 | size_int (klass), field_list); | |
a1ab4c31 | 2579 | |
a1ab4c31 | 2580 | pointer32_type = build_pointer_type_for_mode (type, SImode, false); |
31a5a547 EB |
2581 | pointer64_type = build_pointer_type_for_mode (type, DImode, false); |
2582 | ||
2583 | /* Ensure that only 32-bit pointers are passed in 32-bit descriptors. Note | |
2584 | that we cannot build a template call to the CE routine as it would get a | |
2585 | wrong source location; instead we use a second placeholder for it. */ | |
2586 | tem = build_unary_op (ADDR_EXPR, pointer64_type, | |
2587 | build0 (PLACEHOLDER_EXPR, type)); | |
2588 | tem = build3 (COND_EXPR, pointer32_type, | |
f542c405 EB |
2589 | Pmode != SImode |
2590 | ? build_binary_op (GE_EXPR, boolean_type_node, tem, | |
2591 | build_int_cstu (pointer64_type, 0x80000000)) | |
2592 | : boolean_false_node, | |
31a5a547 EB |
2593 | build0 (PLACEHOLDER_EXPR, void_type_node), |
2594 | convert (pointer32_type, tem)); | |
a1ab4c31 | 2595 | |
82b481ed | 2596 | field_list |
31a5a547 | 2597 | = make_descriptor_field ("POINTER", pointer32_type, record_type, tem, |
82b481ed | 2598 | field_list); |
a1ab4c31 AC |
2599 | |
2600 | switch (mech) | |
2601 | { | |
2602 | case By_Descriptor: | |
d628c015 | 2603 | case By_Short_Descriptor: |
a1ab4c31 | 2604 | case By_Descriptor_S: |
d628c015 | 2605 | case By_Short_Descriptor_S: |
a1ab4c31 AC |
2606 | break; |
2607 | ||
2608 | case By_Descriptor_SB: | |
d628c015 | 2609 | case By_Short_Descriptor_SB: |
82b481ed EB |
2610 | field_list |
2611 | = make_descriptor_field ("SB_L1", gnat_type_for_size (32, 1), | |
2612 | record_type, | |
2613 | (TREE_CODE (type) == ARRAY_TYPE | |
2614 | ? TYPE_MIN_VALUE (TYPE_DOMAIN (type)) | |
2615 | : size_zero_node), | |
2616 | field_list); | |
2617 | field_list | |
2618 | = make_descriptor_field ("SB_U1", gnat_type_for_size (32, 1), | |
2619 | record_type, | |
2620 | (TREE_CODE (type) == ARRAY_TYPE | |
2621 | ? TYPE_MAX_VALUE (TYPE_DOMAIN (type)) | |
2622 | : size_zero_node), | |
2623 | field_list); | |
a1ab4c31 AC |
2624 | break; |
2625 | ||
2626 | case By_Descriptor_A: | |
d628c015 | 2627 | case By_Short_Descriptor_A: |
a1ab4c31 | 2628 | case By_Descriptor_NCA: |
d628c015 | 2629 | case By_Short_Descriptor_NCA: |
82b481ed EB |
2630 | field_list |
2631 | = make_descriptor_field ("SCALE", gnat_type_for_size (8, 1), | |
2632 | record_type, size_zero_node, field_list); | |
2633 | ||
2634 | field_list | |
2635 | = make_descriptor_field ("DIGITS", gnat_type_for_size (8, 1), | |
2636 | record_type, size_zero_node, field_list); | |
2637 | ||
82b481ed EB |
2638 | field_list |
2639 | = make_descriptor_field ("AFLAGS", gnat_type_for_size (8, 1), | |
2640 | record_type, | |
2641 | size_int ((mech == By_Descriptor_NCA | |
2642 | || mech == By_Short_Descriptor_NCA) | |
2643 | ? 0 | |
2644 | /* Set FL_COLUMN, FL_COEFF, and | |
2645 | FL_BOUNDS. */ | |
2646 | : (TREE_CODE (type) == ARRAY_TYPE | |
2647 | && TYPE_CONVENTION_FORTRAN_P | |
2648 | (type) | |
2649 | ? 224 : 192)), | |
2650 | field_list); | |
2651 | ||
2652 | field_list | |
2653 | = make_descriptor_field ("DIMCT", gnat_type_for_size (8, 1), | |
2654 | record_type, size_int (ndim), field_list); | |
2655 | ||
2656 | field_list | |
2657 | = make_descriptor_field ("ARSIZE", gnat_type_for_size (32, 1), | |
2658 | record_type, size_in_bytes (type), | |
2659 | field_list); | |
a1ab4c31 AC |
2660 | |
2661 | /* Now build a pointer to the 0,0,0... element. */ | |
2662 | tem = build0 (PLACEHOLDER_EXPR, type); | |
2663 | for (i = 0, inner_type = type; i < ndim; | |
2664 | i++, inner_type = TREE_TYPE (inner_type)) | |
2665 | tem = build4 (ARRAY_REF, TREE_TYPE (inner_type), tem, | |
2666 | convert (TYPE_DOMAIN (inner_type), size_zero_node), | |
2667 | NULL_TREE, NULL_TREE); | |
2668 | ||
82b481ed EB |
2669 | field_list |
2670 | = make_descriptor_field ("A0", pointer32_type, record_type, | |
2671 | build1 (ADDR_EXPR, pointer32_type, tem), | |
2672 | field_list); | |
a1ab4c31 AC |
2673 | |
2674 | /* Next come the addressing coefficients. */ | |
2675 | tem = size_one_node; | |
2676 | for (i = 0; i < ndim; i++) | |
2677 | { | |
2678 | char fname[3]; | |
2679 | tree idx_length | |
2680 | = size_binop (MULT_EXPR, tem, | |
2681 | size_binop (PLUS_EXPR, | |
2682 | size_binop (MINUS_EXPR, | |
2683 | TYPE_MAX_VALUE (idx_arr[i]), | |
2684 | TYPE_MIN_VALUE (idx_arr[i])), | |
2685 | size_int (1))); | |
2686 | ||
d628c015 DR |
2687 | fname[0] = ((mech == By_Descriptor_NCA || |
2688 | mech == By_Short_Descriptor_NCA) ? 'S' : 'M'); | |
a1ab4c31 | 2689 | fname[1] = '0' + i, fname[2] = 0; |
82b481ed EB |
2690 | field_list |
2691 | = make_descriptor_field (fname, gnat_type_for_size (32, 1), | |
2692 | record_type, idx_length, field_list); | |
a1ab4c31 | 2693 | |
d628c015 | 2694 | if (mech == By_Descriptor_NCA || mech == By_Short_Descriptor_NCA) |
a1ab4c31 AC |
2695 | tem = idx_length; |
2696 | } | |
2697 | ||
2698 | /* Finally here are the bounds. */ | |
2699 | for (i = 0; i < ndim; i++) | |
2700 | { | |
2701 | char fname[3]; | |
2702 | ||
2703 | fname[0] = 'L', fname[1] = '0' + i, fname[2] = 0; | |
82b481ed EB |
2704 | field_list |
2705 | = make_descriptor_field (fname, gnat_type_for_size (32, 1), | |
2706 | record_type, TYPE_MIN_VALUE (idx_arr[i]), | |
2707 | field_list); | |
a1ab4c31 AC |
2708 | |
2709 | fname[0] = 'U'; | |
82b481ed EB |
2710 | field_list |
2711 | = make_descriptor_field (fname, gnat_type_for_size (32, 1), | |
2712 | record_type, TYPE_MAX_VALUE (idx_arr[i]), | |
2713 | field_list); | |
a1ab4c31 AC |
2714 | } |
2715 | break; | |
2716 | ||
2717 | default: | |
2718 | post_error ("unsupported descriptor type for &", gnat_entity); | |
2719 | } | |
2720 | ||
10069d53 | 2721 | TYPE_NAME (record_type) = create_concat_name (gnat_entity, "DESC"); |
788e5046 | 2722 | finish_record_type (record_type, nreverse (field_list), 0, false); |
a1ab4c31 AC |
2723 | return record_type; |
2724 | } | |
2725 | ||
58c8f770 EB |
2726 | /* Build a 64-bit VMS descriptor from a Mechanism_Type, which must specify a |
2727 | descriptor type, and the GCC type of an object. Each FIELD_DECL in the | |
2728 | type contains in its DECL_INITIAL the expression to use when a constructor | |
2729 | is made for the type. GNAT_ENTITY is an entity used to print out an error | |
2730 | message if the mechanism cannot be applied to an object of that type and | |
2731 | also for the name. */ | |
6ca2b0a0 DR |
2732 | |
2733 | tree | |
d628c015 | 2734 | build_vms_descriptor (tree type, Mechanism_Type mech, Entity_Id gnat_entity) |
6ca2b0a0 | 2735 | { |
31a5a547 | 2736 | tree record_type = make_node (RECORD_TYPE); |
6ca2b0a0 | 2737 | tree pointer64_type; |
31a5a547 EB |
2738 | tree field_list = NULL_TREE; |
2739 | int klass, ndim, i, dtype = 0; | |
2740 | tree inner_type, tem; | |
6ca2b0a0 | 2741 | tree *idx_arr; |
6ca2b0a0 DR |
2742 | |
2743 | /* If TYPE is an unconstrained array, use the underlying array type. */ | |
2744 | if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE) | |
2745 | type = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))); | |
2746 | ||
2747 | /* If this is an array, compute the number of dimensions in the array, | |
2748 | get the index types, and point to the inner type. */ | |
2749 | if (TREE_CODE (type) != ARRAY_TYPE) | |
2750 | ndim = 0; | |
2751 | else | |
2752 | for (ndim = 1, inner_type = type; | |
2753 | TREE_CODE (TREE_TYPE (inner_type)) == ARRAY_TYPE | |
2754 | && TYPE_MULTI_ARRAY_P (TREE_TYPE (inner_type)); | |
2755 | ndim++, inner_type = TREE_TYPE (inner_type)) | |
2756 | ; | |
2757 | ||
2bb1fc26 | 2758 | idx_arr = XALLOCAVEC (tree, ndim); |
6ca2b0a0 DR |
2759 | |
2760 | if (mech != By_Descriptor_NCA | |
2761 | && TREE_CODE (type) == ARRAY_TYPE && TYPE_CONVENTION_FORTRAN_P (type)) | |
2762 | for (i = ndim - 1, inner_type = type; | |
2763 | i >= 0; | |
2764 | i--, inner_type = TREE_TYPE (inner_type)) | |
2765 | idx_arr[i] = TYPE_DOMAIN (inner_type); | |
2766 | else | |
2767 | for (i = 0, inner_type = type; | |
2768 | i < ndim; | |
2769 | i++, inner_type = TREE_TYPE (inner_type)) | |
2770 | idx_arr[i] = TYPE_DOMAIN (inner_type); | |
2771 | ||
2772 | /* Now get the DTYPE value. */ | |
2773 | switch (TREE_CODE (type)) | |
2774 | { | |
2775 | case INTEGER_TYPE: | |
2776 | case ENUMERAL_TYPE: | |
01ddebf2 | 2777 | case BOOLEAN_TYPE: |
6ca2b0a0 DR |
2778 | if (TYPE_VAX_FLOATING_POINT_P (type)) |
2779 | switch (tree_low_cst (TYPE_DIGITS_VALUE (type), 1)) | |
2780 | { | |
2781 | case 6: | |
2782 | dtype = 10; | |
2783 | break; | |
2784 | case 9: | |
2785 | dtype = 11; | |
2786 | break; | |
2787 | case 15: | |
2788 | dtype = 27; | |
2789 | break; | |
2790 | } | |
2791 | else | |
2792 | switch (GET_MODE_BITSIZE (TYPE_MODE (type))) | |
2793 | { | |
2794 | case 8: | |
2795 | dtype = TYPE_UNSIGNED (type) ? 2 : 6; | |
2796 | break; | |
2797 | case 16: | |
2798 | dtype = TYPE_UNSIGNED (type) ? 3 : 7; | |
2799 | break; | |
2800 | case 32: | |
2801 | dtype = TYPE_UNSIGNED (type) ? 4 : 8; | |
2802 | break; | |
2803 | case 64: | |
2804 | dtype = TYPE_UNSIGNED (type) ? 5 : 9; | |
2805 | break; | |
2806 | case 128: | |
2807 | dtype = TYPE_UNSIGNED (type) ? 25 : 26; | |
2808 | break; | |
2809 | } | |
2810 | break; | |
2811 | ||
2812 | case REAL_TYPE: | |
2813 | dtype = GET_MODE_BITSIZE (TYPE_MODE (type)) == 32 ? 52 : 53; | |
2814 | break; | |
2815 | ||
2816 | case COMPLEX_TYPE: | |
2817 | if (TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE | |
2818 | && TYPE_VAX_FLOATING_POINT_P (type)) | |
2819 | switch (tree_low_cst (TYPE_DIGITS_VALUE (type), 1)) | |
2820 | { | |
2821 | case 6: | |
2822 | dtype = 12; | |
2823 | break; | |
2824 | case 9: | |
2825 | dtype = 13; | |
2826 | break; | |
2827 | case 15: | |
2828 | dtype = 29; | |
2829 | } | |
2830 | else | |
2831 | dtype = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) == 32 ? 54: 55; | |
2832 | break; | |
2833 | ||
2834 | case ARRAY_TYPE: | |
2835 | dtype = 14; | |
2836 | break; | |
2837 | ||
2838 | default: | |
2839 | break; | |
2840 | } | |
2841 | ||
2842 | /* Get the CLASS value. */ | |
2843 | switch (mech) | |
2844 | { | |
2845 | case By_Descriptor_A: | |
c6bd4220 | 2846 | klass = 4; |
6ca2b0a0 DR |
2847 | break; |
2848 | case By_Descriptor_NCA: | |
c6bd4220 | 2849 | klass = 10; |
6ca2b0a0 DR |
2850 | break; |
2851 | case By_Descriptor_SB: | |
c6bd4220 | 2852 | klass = 15; |
6ca2b0a0 DR |
2853 | break; |
2854 | case By_Descriptor: | |
2855 | case By_Descriptor_S: | |
2856 | default: | |
c6bd4220 | 2857 | klass = 1; |
6ca2b0a0 DR |
2858 | break; |
2859 | } | |
2860 | ||
58c8f770 | 2861 | /* Make the type for a 64-bit descriptor for VMS. The first six fields |
6ca2b0a0 | 2862 | are the same for all types. */ |
31a5a547 | 2863 | field_list |
788e5046 | 2864 | = make_descriptor_field ("MBO", gnat_type_for_size (16, 1), |
31a5a547 EB |
2865 | record_type, size_int (1), field_list); |
2866 | field_list | |
788e5046 | 2867 | = make_descriptor_field ("DTYPE", gnat_type_for_size (8, 1), |
31a5a547 EB |
2868 | record_type, size_int (dtype), field_list); |
2869 | field_list | |
788e5046 | 2870 | = make_descriptor_field ("CLASS", gnat_type_for_size (8, 1), |
31a5a547 EB |
2871 | record_type, size_int (klass), field_list); |
2872 | field_list | |
788e5046 | 2873 | = make_descriptor_field ("MBMO", gnat_type_for_size (32, 1), |
31a5a547 EB |
2874 | record_type, ssize_int (-1), field_list); |
2875 | field_list | |
788e5046 | 2876 | = make_descriptor_field ("LENGTH", gnat_type_for_size (64, 1), |
31a5a547 | 2877 | record_type, |
788e5046 | 2878 | size_in_bytes (mech == By_Descriptor_A |
82b481ed | 2879 | ? inner_type : type), |
31a5a547 | 2880 | field_list); |
6ca2b0a0 DR |
2881 | |
2882 | pointer64_type = build_pointer_type_for_mode (type, DImode, false); | |
2883 | ||
31a5a547 EB |
2884 | field_list |
2885 | = make_descriptor_field ("POINTER", pointer64_type, record_type, | |
788e5046 | 2886 | build_unary_op (ADDR_EXPR, pointer64_type, |
82b481ed | 2887 | build0 (PLACEHOLDER_EXPR, type)), |
31a5a547 | 2888 | field_list); |
6ca2b0a0 DR |
2889 | |
2890 | switch (mech) | |
2891 | { | |
2892 | case By_Descriptor: | |
2893 | case By_Descriptor_S: | |
2894 | break; | |
2895 | ||
2896 | case By_Descriptor_SB: | |
31a5a547 | 2897 | field_list |
788e5046 | 2898 | = make_descriptor_field ("SB_L1", gnat_type_for_size (64, 1), |
31a5a547 | 2899 | record_type, |
788e5046 NF |
2900 | (TREE_CODE (type) == ARRAY_TYPE |
2901 | ? TYPE_MIN_VALUE (TYPE_DOMAIN (type)) | |
82b481ed | 2902 | : size_zero_node), |
31a5a547 EB |
2903 | field_list); |
2904 | field_list | |
788e5046 | 2905 | = make_descriptor_field ("SB_U1", gnat_type_for_size (64, 1), |
31a5a547 | 2906 | record_type, |
788e5046 NF |
2907 | (TREE_CODE (type) == ARRAY_TYPE |
2908 | ? TYPE_MAX_VALUE (TYPE_DOMAIN (type)) | |
82b481ed | 2909 | : size_zero_node), |
31a5a547 | 2910 | field_list); |
6ca2b0a0 DR |
2911 | break; |
2912 | ||
2913 | case By_Descriptor_A: | |
2914 | case By_Descriptor_NCA: | |
31a5a547 | 2915 | field_list |
788e5046 | 2916 | = make_descriptor_field ("SCALE", gnat_type_for_size (8, 1), |
31a5a547 | 2917 | record_type, size_zero_node, field_list); |
788e5046 | 2918 | |
31a5a547 | 2919 | field_list |
788e5046 | 2920 | = make_descriptor_field ("DIGITS", gnat_type_for_size (8, 1), |
31a5a547 | 2921 | record_type, size_zero_node, field_list); |
788e5046 NF |
2922 | |
2923 | dtype = (mech == By_Descriptor_NCA | |
2924 | ? 0 | |
2925 | /* Set FL_COLUMN, FL_COEFF, and | |
2926 | FL_BOUNDS. */ | |
2927 | : (TREE_CODE (type) == ARRAY_TYPE | |
2928 | && TYPE_CONVENTION_FORTRAN_P (type) | |
2929 | ? 224 : 192)); | |
31a5a547 | 2930 | field_list |
788e5046 | 2931 | = make_descriptor_field ("AFLAGS", gnat_type_for_size (8, 1), |
31a5a547 EB |
2932 | record_type, size_int (dtype), |
2933 | field_list); | |
6ca2b0a0 | 2934 | |
31a5a547 | 2935 | field_list |
788e5046 | 2936 | = make_descriptor_field ("DIMCT", gnat_type_for_size (8, 1), |
31a5a547 | 2937 | record_type, size_int (ndim), field_list); |
788e5046 | 2938 | |
31a5a547 | 2939 | field_list |
788e5046 | 2940 | = make_descriptor_field ("MBZ", gnat_type_for_size (32, 1), |
31a5a547 EB |
2941 | record_type, size_int (0), field_list); |
2942 | field_list | |
788e5046 | 2943 | = make_descriptor_field ("ARSIZE", gnat_type_for_size (64, 1), |
31a5a547 EB |
2944 | record_type, size_in_bytes (type), |
2945 | field_list); | |
6ca2b0a0 DR |
2946 | |
2947 | /* Now build a pointer to the 0,0,0... element. */ | |
2948 | tem = build0 (PLACEHOLDER_EXPR, type); | |
2949 | for (i = 0, inner_type = type; i < ndim; | |
2950 | i++, inner_type = TREE_TYPE (inner_type)) | |
2951 | tem = build4 (ARRAY_REF, TREE_TYPE (inner_type), tem, | |
2952 | convert (TYPE_DOMAIN (inner_type), size_zero_node), | |
2953 | NULL_TREE, NULL_TREE); | |
2954 | ||
31a5a547 EB |
2955 | field_list |
2956 | = make_descriptor_field ("A0", pointer64_type, record_type, | |
788e5046 | 2957 | build1 (ADDR_EXPR, pointer64_type, tem), |
31a5a547 | 2958 | field_list); |
6ca2b0a0 DR |
2959 | |
2960 | /* Next come the addressing coefficients. */ | |
2961 | tem = size_one_node; | |
2962 | for (i = 0; i < ndim; i++) | |
2963 | { | |
2964 | char fname[3]; | |
2965 | tree idx_length | |
2966 | = size_binop (MULT_EXPR, tem, | |
2967 | size_binop (PLUS_EXPR, | |
2968 | size_binop (MINUS_EXPR, | |
2969 | TYPE_MAX_VALUE (idx_arr[i]), | |
2970 | TYPE_MIN_VALUE (idx_arr[i])), | |
2971 | size_int (1))); | |
2972 | ||
2973 | fname[0] = (mech == By_Descriptor_NCA ? 'S' : 'M'); | |
2974 | fname[1] = '0' + i, fname[2] = 0; | |
31a5a547 | 2975 | field_list |
788e5046 | 2976 | = make_descriptor_field (fname, gnat_type_for_size (64, 1), |
31a5a547 | 2977 | record_type, idx_length, field_list); |
6ca2b0a0 DR |
2978 | |
2979 | if (mech == By_Descriptor_NCA) | |
2980 | tem = idx_length; | |
2981 | } | |
2982 | ||
2983 | /* Finally here are the bounds. */ | |
2984 | for (i = 0; i < ndim; i++) | |
2985 | { | |
2986 | char fname[3]; | |
2987 | ||
2988 | fname[0] = 'L', fname[1] = '0' + i, fname[2] = 0; | |
31a5a547 | 2989 | field_list |
788e5046 | 2990 | = make_descriptor_field (fname, gnat_type_for_size (64, 1), |
31a5a547 EB |
2991 | record_type, |
2992 | TYPE_MIN_VALUE (idx_arr[i]), field_list); | |
6ca2b0a0 DR |
2993 | |
2994 | fname[0] = 'U'; | |
31a5a547 | 2995 | field_list |
788e5046 | 2996 | = make_descriptor_field (fname, gnat_type_for_size (64, 1), |
31a5a547 EB |
2997 | record_type, |
2998 | TYPE_MAX_VALUE (idx_arr[i]), field_list); | |
6ca2b0a0 DR |
2999 | } |
3000 | break; | |
3001 | ||
3002 | default: | |
3003 | post_error ("unsupported descriptor type for &", gnat_entity); | |
3004 | } | |
3005 | ||
31a5a547 EB |
3006 | TYPE_NAME (record_type) = create_concat_name (gnat_entity, "DESC64"); |
3007 | finish_record_type (record_type, nreverse (field_list), 0, false); | |
3008 | return record_type; | |
6ca2b0a0 DR |
3009 | } |
3010 | ||
31a5a547 EB |
3011 | /* Fill in a VMS descriptor of GNU_TYPE for GNU_EXPR and return the result. |
3012 | GNAT_ACTUAL is the actual parameter for which the descriptor is built. */ | |
a1ab4c31 | 3013 | |
31a5a547 EB |
3014 | tree |
3015 | fill_vms_descriptor (tree gnu_type, tree gnu_expr, Node_Id gnat_actual) | |
a1ab4c31 | 3016 | { |
31a5a547 EB |
3017 | VEC(constructor_elt,gc) *v = NULL; |
3018 | tree field; | |
a1ab4c31 | 3019 | |
31a5a547 EB |
3020 | gnu_expr = maybe_unconstrained_array (gnu_expr); |
3021 | gnu_expr = gnat_protect_expr (gnu_expr); | |
3022 | gnat_mark_addressable (gnu_expr); | |
3023 | ||
3024 | /* We may need to substitute both GNU_EXPR and a CALL_EXPR to the raise CE | |
3025 | routine in case we have a 32-bit descriptor. */ | |
3026 | gnu_expr = build2 (COMPOUND_EXPR, void_type_node, | |
3027 | build_call_raise (CE_Range_Check_Failed, gnat_actual, | |
3028 | N_Raise_Constraint_Error), | |
3029 | gnu_expr); | |
3030 | ||
3031 | for (field = TYPE_FIELDS (gnu_type); field; field = DECL_CHAIN (field)) | |
3032 | { | |
3033 | tree value | |
3034 | = convert (TREE_TYPE (field), | |
3035 | SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_INITIAL (field), | |
3036 | gnu_expr)); | |
3037 | CONSTRUCTOR_APPEND_ELT (v, field, value); | |
3038 | } | |
3039 | ||
3040 | return gnat_build_constructor (gnu_type, v); | |
a1ab4c31 AC |
3041 | } |
3042 | ||
d628c015 DR |
3043 | /* Convert GNU_EXPR, a pointer to a 64bit VMS descriptor, to GNU_TYPE, a |
3044 | regular pointer or fat pointer type. GNAT_SUBPROG is the subprogram to | |
3045 | which the VMS descriptor is passed. */ | |
a1ab4c31 AC |
3046 | |
3047 | static tree | |
d628c015 DR |
3048 | convert_vms_descriptor64 (tree gnu_type, tree gnu_expr, Entity_Id gnat_subprog) |
3049 | { | |
3050 | tree desc_type = TREE_TYPE (TREE_TYPE (gnu_expr)); | |
3051 | tree desc = build1 (INDIRECT_REF, desc_type, gnu_expr); | |
3052 | /* The CLASS field is the 3rd field in the descriptor. */ | |
910ad8de | 3053 | tree klass = DECL_CHAIN (DECL_CHAIN (TYPE_FIELDS (desc_type))); |
d628c015 | 3054 | /* The POINTER field is the 6th field in the descriptor. */ |
910ad8de | 3055 | tree pointer = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (klass))); |
d628c015 DR |
3056 | |
3057 | /* Retrieve the value of the POINTER field. */ | |
3058 | tree gnu_expr64 | |
58c8f770 | 3059 | = build3 (COMPONENT_REF, TREE_TYPE (pointer), desc, pointer, NULL_TREE); |
d628c015 DR |
3060 | |
3061 | if (POINTER_TYPE_P (gnu_type)) | |
3062 | return convert (gnu_type, gnu_expr64); | |
3063 | ||
315cff15 | 3064 | else if (TYPE_IS_FAT_POINTER_P (gnu_type)) |
d628c015 DR |
3065 | { |
3066 | tree p_array_type = TREE_TYPE (TYPE_FIELDS (gnu_type)); | |
7d76717d | 3067 | tree p_bounds_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type))); |
d628c015 DR |
3068 | tree template_type = TREE_TYPE (p_bounds_type); |
3069 | tree min_field = TYPE_FIELDS (template_type); | |
7d76717d | 3070 | tree max_field = DECL_CHAIN (TYPE_FIELDS (template_type)); |
6bf68a93 | 3071 | tree template_tree, template_addr, aflags, dimct, t, u; |
d628c015 | 3072 | /* See the head comment of build_vms_descriptor. */ |
c6bd4220 | 3073 | int iklass = TREE_INT_CST_LOW (DECL_INITIAL (klass)); |
d628c015 | 3074 | tree lfield, ufield; |
0e228dd9 | 3075 | VEC(constructor_elt,gc) *v; |
d628c015 | 3076 | |
86060344 | 3077 | /* Convert POINTER to the pointer-to-array type. */ |
d628c015 DR |
3078 | gnu_expr64 = convert (p_array_type, gnu_expr64); |
3079 | ||
c6bd4220 | 3080 | switch (iklass) |
d628c015 DR |
3081 | { |
3082 | case 1: /* Class S */ | |
3083 | case 15: /* Class SB */ | |
3084 | /* Build {1, LENGTH} template; LENGTH64 is the 5th field. */ | |
0e228dd9 | 3085 | v = VEC_alloc (constructor_elt, gc, 2); |
910ad8de | 3086 | t = DECL_CHAIN (DECL_CHAIN (klass)); |
d628c015 | 3087 | t = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
0e228dd9 NF |
3088 | CONSTRUCTOR_APPEND_ELT (v, min_field, |
3089 | convert (TREE_TYPE (min_field), | |
3090 | integer_one_node)); | |
3091 | CONSTRUCTOR_APPEND_ELT (v, max_field, | |
3092 | convert (TREE_TYPE (max_field), t)); | |
3093 | template_tree = gnat_build_constructor (template_type, v); | |
6bf68a93 | 3094 | template_addr = build_unary_op (ADDR_EXPR, NULL_TREE, template_tree); |
d628c015 DR |
3095 | |
3096 | /* For class S, we are done. */ | |
c6bd4220 | 3097 | if (iklass == 1) |
d628c015 DR |
3098 | break; |
3099 | ||
3100 | /* Test that we really have a SB descriptor, like DEC Ada. */ | |
c6bd4220 EB |
3101 | t = build3 (COMPONENT_REF, TREE_TYPE (klass), desc, klass, NULL); |
3102 | u = convert (TREE_TYPE (klass), DECL_INITIAL (klass)); | |
1139f2e8 | 3103 | u = build_binary_op (EQ_EXPR, boolean_type_node, t, u); |
d628c015 DR |
3104 | /* If so, there is already a template in the descriptor and |
3105 | it is located right after the POINTER field. The fields are | |
3106 | 64bits so they must be repacked. */ | |
7d76717d | 3107 | t = DECL_CHAIN (pointer); |
d628c015 DR |
3108 | lfield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3109 | lfield = convert (TREE_TYPE (TYPE_FIELDS (template_type)), lfield); | |
3110 | ||
7d76717d | 3111 | t = DECL_CHAIN (t); |
d628c015 DR |
3112 | ufield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3113 | ufield = convert | |
910ad8de | 3114 | (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (template_type))), ufield); |
d628c015 DR |
3115 | |
3116 | /* Build the template in the form of a constructor. */ | |
0e228dd9 NF |
3117 | v = VEC_alloc (constructor_elt, gc, 2); |
3118 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (template_type), lfield); | |
7d76717d | 3119 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (template_type)), |
0e228dd9 NF |
3120 | ufield); |
3121 | template_tree = gnat_build_constructor (template_type, v); | |
d628c015 DR |
3122 | |
3123 | /* Otherwise use the {1, LENGTH} template we build above. */ | |
3124 | template_addr = build3 (COND_EXPR, p_bounds_type, u, | |
3125 | build_unary_op (ADDR_EXPR, p_bounds_type, | |
6bf68a93 | 3126 | template_tree), |
d628c015 DR |
3127 | template_addr); |
3128 | break; | |
3129 | ||
3130 | case 4: /* Class A */ | |
3131 | /* The AFLAGS field is the 3rd field after the pointer in the | |
3132 | descriptor. */ | |
910ad8de | 3133 | t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (pointer))); |
d628c015 DR |
3134 | aflags = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3135 | /* The DIMCT field is the next field in the descriptor after | |
3136 | aflags. */ | |
7d76717d | 3137 | t = DECL_CHAIN (t); |
d628c015 DR |
3138 | dimct = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3139 | /* Raise CONSTRAINT_ERROR if either more than 1 dimension | |
3140 | or FL_COEFF or FL_BOUNDS not set. */ | |
3141 | u = build_int_cst (TREE_TYPE (aflags), 192); | |
1139f2e8 EB |
3142 | u = build_binary_op (TRUTH_OR_EXPR, boolean_type_node, |
3143 | build_binary_op (NE_EXPR, boolean_type_node, | |
d628c015 DR |
3144 | dimct, |
3145 | convert (TREE_TYPE (dimct), | |
3146 | size_one_node)), | |
1139f2e8 | 3147 | build_binary_op (NE_EXPR, boolean_type_node, |
d628c015 DR |
3148 | build2 (BIT_AND_EXPR, |
3149 | TREE_TYPE (aflags), | |
3150 | aflags, u), | |
3151 | u)); | |
3152 | /* There is already a template in the descriptor and it is located | |
3153 | in block 3. The fields are 64bits so they must be repacked. */ | |
910ad8de | 3154 | t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN |
d628c015 DR |
3155 | (t))))); |
3156 | lfield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); | |
3157 | lfield = convert (TREE_TYPE (TYPE_FIELDS (template_type)), lfield); | |
3158 | ||
7d76717d | 3159 | t = DECL_CHAIN (t); |
d628c015 DR |
3160 | ufield = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3161 | ufield = convert | |
910ad8de | 3162 | (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (template_type))), ufield); |
d628c015 DR |
3163 | |
3164 | /* Build the template in the form of a constructor. */ | |
0e228dd9 NF |
3165 | v = VEC_alloc (constructor_elt, gc, 2); |
3166 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (template_type), lfield); | |
910ad8de | 3167 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (template_type)), |
0e228dd9 NF |
3168 | ufield); |
3169 | template_tree = gnat_build_constructor (template_type, v); | |
f76d6e6f | 3170 | template_tree = build3 (COND_EXPR, template_type, u, |
d628c015 DR |
3171 | build_call_raise (CE_Length_Check_Failed, Empty, |
3172 | N_Raise_Constraint_Error), | |
6bf68a93 | 3173 | template_tree); |
c6bd4220 EB |
3174 | template_addr |
3175 | = build_unary_op (ADDR_EXPR, p_bounds_type, template_tree); | |
d628c015 DR |
3176 | break; |
3177 | ||
3178 | case 10: /* Class NCA */ | |
3179 | default: | |
3180 | post_error ("unsupported descriptor type for &", gnat_subprog); | |
3181 | template_addr = integer_zero_node; | |
3182 | break; | |
3183 | } | |
3184 | ||
3185 | /* Build the fat pointer in the form of a constructor. */ | |
0e228dd9 NF |
3186 | v = VEC_alloc (constructor_elt, gc, 2); |
3187 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (gnu_type), gnu_expr64); | |
910ad8de | 3188 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (gnu_type)), |
0e228dd9 NF |
3189 | template_addr); |
3190 | return gnat_build_constructor (gnu_type, v); | |
d628c015 DR |
3191 | } |
3192 | ||
3193 | else | |
3194 | gcc_unreachable (); | |
3195 | } | |
3196 | ||
3197 | /* Convert GNU_EXPR, a pointer to a 32bit VMS descriptor, to GNU_TYPE, a | |
3198 | regular pointer or fat pointer type. GNAT_SUBPROG is the subprogram to | |
3199 | which the VMS descriptor is passed. */ | |
3200 | ||
3201 | static tree | |
3202 | convert_vms_descriptor32 (tree gnu_type, tree gnu_expr, Entity_Id gnat_subprog) | |
a1ab4c31 AC |
3203 | { |
3204 | tree desc_type = TREE_TYPE (TREE_TYPE (gnu_expr)); | |
3205 | tree desc = build1 (INDIRECT_REF, desc_type, gnu_expr); | |
3206 | /* The CLASS field is the 3rd field in the descriptor. */ | |
910ad8de | 3207 | tree klass = DECL_CHAIN (DECL_CHAIN (TYPE_FIELDS (desc_type))); |
a1ab4c31 | 3208 | /* The POINTER field is the 4th field in the descriptor. */ |
910ad8de | 3209 | tree pointer = DECL_CHAIN (klass); |
a1ab4c31 AC |
3210 | |
3211 | /* Retrieve the value of the POINTER field. */ | |
d628c015 | 3212 | tree gnu_expr32 |
a1ab4c31 AC |
3213 | = build3 (COMPONENT_REF, TREE_TYPE (pointer), desc, pointer, NULL_TREE); |
3214 | ||
3215 | if (POINTER_TYPE_P (gnu_type)) | |
d628c015 | 3216 | return convert (gnu_type, gnu_expr32); |
a1ab4c31 | 3217 | |
315cff15 | 3218 | else if (TYPE_IS_FAT_POINTER_P (gnu_type)) |
a1ab4c31 AC |
3219 | { |
3220 | tree p_array_type = TREE_TYPE (TYPE_FIELDS (gnu_type)); | |
7d76717d | 3221 | tree p_bounds_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type))); |
a1ab4c31 AC |
3222 | tree template_type = TREE_TYPE (p_bounds_type); |
3223 | tree min_field = TYPE_FIELDS (template_type); | |
7d76717d | 3224 | tree max_field = DECL_CHAIN (TYPE_FIELDS (template_type)); |
6bf68a93 | 3225 | tree template_tree, template_addr, aflags, dimct, t, u; |
a1ab4c31 | 3226 | /* See the head comment of build_vms_descriptor. */ |
c6bd4220 | 3227 | int iklass = TREE_INT_CST_LOW (DECL_INITIAL (klass)); |
0e228dd9 | 3228 | VEC(constructor_elt,gc) *v; |
a1ab4c31 | 3229 | |
86060344 | 3230 | /* Convert POINTER to the pointer-to-array type. */ |
d628c015 | 3231 | gnu_expr32 = convert (p_array_type, gnu_expr32); |
a1ab4c31 | 3232 | |
c6bd4220 | 3233 | switch (iklass) |
a1ab4c31 AC |
3234 | { |
3235 | case 1: /* Class S */ | |
3236 | case 15: /* Class SB */ | |
3237 | /* Build {1, LENGTH} template; LENGTH is the 1st field. */ | |
0e228dd9 | 3238 | v = VEC_alloc (constructor_elt, gc, 2); |
a1ab4c31 AC |
3239 | t = TYPE_FIELDS (desc_type); |
3240 | t = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); | |
0e228dd9 NF |
3241 | CONSTRUCTOR_APPEND_ELT (v, min_field, |
3242 | convert (TREE_TYPE (min_field), | |
3243 | integer_one_node)); | |
3244 | CONSTRUCTOR_APPEND_ELT (v, max_field, | |
3245 | convert (TREE_TYPE (max_field), t)); | |
3246 | template_tree = gnat_build_constructor (template_type, v); | |
6bf68a93 | 3247 | template_addr = build_unary_op (ADDR_EXPR, NULL_TREE, template_tree); |
a1ab4c31 AC |
3248 | |
3249 | /* For class S, we are done. */ | |
c6bd4220 | 3250 | if (iklass == 1) |
a1ab4c31 AC |
3251 | break; |
3252 | ||
3253 | /* Test that we really have a SB descriptor, like DEC Ada. */ | |
c6bd4220 EB |
3254 | t = build3 (COMPONENT_REF, TREE_TYPE (klass), desc, klass, NULL); |
3255 | u = convert (TREE_TYPE (klass), DECL_INITIAL (klass)); | |
1139f2e8 | 3256 | u = build_binary_op (EQ_EXPR, boolean_type_node, t, u); |
a1ab4c31 AC |
3257 | /* If so, there is already a template in the descriptor and |
3258 | it is located right after the POINTER field. */ | |
7d76717d | 3259 | t = DECL_CHAIN (pointer); |
c6bd4220 EB |
3260 | template_tree |
3261 | = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); | |
a1ab4c31 AC |
3262 | /* Otherwise use the {1, LENGTH} template we build above. */ |
3263 | template_addr = build3 (COND_EXPR, p_bounds_type, u, | |
3264 | build_unary_op (ADDR_EXPR, p_bounds_type, | |
6bf68a93 | 3265 | template_tree), |
a1ab4c31 AC |
3266 | template_addr); |
3267 | break; | |
3268 | ||
3269 | case 4: /* Class A */ | |
3270 | /* The AFLAGS field is the 7th field in the descriptor. */ | |
910ad8de | 3271 | t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (pointer))); |
a1ab4c31 AC |
3272 | aflags = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3273 | /* The DIMCT field is the 8th field in the descriptor. */ | |
7d76717d | 3274 | t = DECL_CHAIN (t); |
a1ab4c31 AC |
3275 | dimct = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); |
3276 | /* Raise CONSTRAINT_ERROR if either more than 1 dimension | |
3277 | or FL_COEFF or FL_BOUNDS not set. */ | |
3278 | u = build_int_cst (TREE_TYPE (aflags), 192); | |
1139f2e8 EB |
3279 | u = build_binary_op (TRUTH_OR_EXPR, boolean_type_node, |
3280 | build_binary_op (NE_EXPR, boolean_type_node, | |
a1ab4c31 AC |
3281 | dimct, |
3282 | convert (TREE_TYPE (dimct), | |
3283 | size_one_node)), | |
1139f2e8 | 3284 | build_binary_op (NE_EXPR, boolean_type_node, |
a1ab4c31 AC |
3285 | build2 (BIT_AND_EXPR, |
3286 | TREE_TYPE (aflags), | |
3287 | aflags, u), | |
3288 | u)); | |
a1ab4c31 AC |
3289 | /* There is already a template in the descriptor and it is |
3290 | located at the start of block 3 (12th field). */ | |
910ad8de | 3291 | t = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (t)))); |
c6bd4220 EB |
3292 | template_tree |
3293 | = build3 (COMPONENT_REF, TREE_TYPE (t), desc, t, NULL_TREE); | |
f76d6e6f | 3294 | template_tree = build3 (COND_EXPR, TREE_TYPE (t), u, |
d628c015 DR |
3295 | build_call_raise (CE_Length_Check_Failed, Empty, |
3296 | N_Raise_Constraint_Error), | |
6bf68a93 | 3297 | template_tree); |
c6bd4220 EB |
3298 | template_addr |
3299 | = build_unary_op (ADDR_EXPR, p_bounds_type, template_tree); | |
a1ab4c31 AC |
3300 | break; |
3301 | ||
3302 | case 10: /* Class NCA */ | |
3303 | default: | |
3304 | post_error ("unsupported descriptor type for &", gnat_subprog); | |
3305 | template_addr = integer_zero_node; | |
3306 | break; | |
3307 | } | |
3308 | ||
3309 | /* Build the fat pointer in the form of a constructor. */ | |
0e228dd9 NF |
3310 | v = VEC_alloc (constructor_elt, gc, 2); |
3311 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (gnu_type), gnu_expr32); | |
910ad8de | 3312 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (gnu_type)), |
0e228dd9 | 3313 | template_addr); |
d628c015 | 3314 | |
0e228dd9 | 3315 | return gnat_build_constructor (gnu_type, v); |
a1ab4c31 AC |
3316 | } |
3317 | ||
3318 | else | |
3319 | gcc_unreachable (); | |
3320 | } | |
3321 | ||
a981c964 EB |
3322 | /* Convert GNU_EXPR, a pointer to a VMS descriptor, to GNU_TYPE, a regular |
3323 | pointer or fat pointer type. GNU_EXPR_ALT_TYPE is the alternate (32-bit) | |
0c700259 EB |
3324 | pointer type of GNU_EXPR. BY_REF is true if the result is to be used by |
3325 | reference. GNAT_SUBPROG is the subprogram to which the VMS descriptor is | |
3326 | passed. */ | |
d628c015 | 3327 | |
f3d34576 | 3328 | tree |
a981c964 | 3329 | convert_vms_descriptor (tree gnu_type, tree gnu_expr, tree gnu_expr_alt_type, |
0c700259 | 3330 | bool by_ref, Entity_Id gnat_subprog) |
d628c015 DR |
3331 | { |
3332 | tree desc_type = TREE_TYPE (TREE_TYPE (gnu_expr)); | |
3333 | tree desc = build1 (INDIRECT_REF, desc_type, gnu_expr); | |
3334 | tree mbo = TYPE_FIELDS (desc_type); | |
3335 | const char *mbostr = IDENTIFIER_POINTER (DECL_NAME (mbo)); | |
910ad8de | 3336 | tree mbmo = DECL_CHAIN (DECL_CHAIN (DECL_CHAIN (mbo))); |
0c700259 EB |
3337 | tree real_type, is64bit, gnu_expr32, gnu_expr64; |
3338 | ||
3339 | if (by_ref) | |
3340 | real_type = TREE_TYPE (gnu_type); | |
3341 | else | |
3342 | real_type = gnu_type; | |
d628c015 | 3343 | |
a981c964 EB |
3344 | /* If the field name is not MBO, it must be 32-bit and no alternate. |
3345 | Otherwise primary must be 64-bit and alternate 32-bit. */ | |
d628c015 | 3346 | if (strcmp (mbostr, "MBO") != 0) |
0c700259 EB |
3347 | { |
3348 | tree ret = convert_vms_descriptor32 (real_type, gnu_expr, gnat_subprog); | |
3349 | if (by_ref) | |
3350 | ret = build_unary_op (ADDR_EXPR, gnu_type, ret); | |
3351 | return ret; | |
3352 | } | |
d628c015 | 3353 | |
a981c964 | 3354 | /* Build the test for 64-bit descriptor. */ |
d628c015 DR |
3355 | mbo = build3 (COMPONENT_REF, TREE_TYPE (mbo), desc, mbo, NULL_TREE); |
3356 | mbmo = build3 (COMPONENT_REF, TREE_TYPE (mbmo), desc, mbmo, NULL_TREE); | |
a981c964 | 3357 | is64bit |
1139f2e8 EB |
3358 | = build_binary_op (TRUTH_ANDIF_EXPR, boolean_type_node, |
3359 | build_binary_op (EQ_EXPR, boolean_type_node, | |
a981c964 EB |
3360 | convert (integer_type_node, mbo), |
3361 | integer_one_node), | |
1139f2e8 | 3362 | build_binary_op (EQ_EXPR, boolean_type_node, |
a981c964 EB |
3363 | convert (integer_type_node, mbmo), |
3364 | integer_minus_one_node)); | |
3365 | ||
3366 | /* Build the 2 possible end results. */ | |
0c700259 EB |
3367 | gnu_expr64 = convert_vms_descriptor64 (real_type, gnu_expr, gnat_subprog); |
3368 | if (by_ref) | |
3369 | gnu_expr64 = build_unary_op (ADDR_EXPR, gnu_type, gnu_expr64); | |
a981c964 | 3370 | gnu_expr = fold_convert (gnu_expr_alt_type, gnu_expr); |
0c700259 EB |
3371 | gnu_expr32 = convert_vms_descriptor32 (real_type, gnu_expr, gnat_subprog); |
3372 | if (by_ref) | |
3373 | gnu_expr32 = build_unary_op (ADDR_EXPR, gnu_type, gnu_expr32); | |
a981c964 EB |
3374 | |
3375 | return build3 (COND_EXPR, gnu_type, is64bit, gnu_expr64, gnu_expr32); | |
d628c015 | 3376 | } |
a1ab4c31 | 3377 | \f |
928dfa4b EB |
3378 | /* Build a type to be used to represent an aliased object whose nominal type |
3379 | is an unconstrained array. This consists of a RECORD_TYPE containing a | |
3380 | field of TEMPLATE_TYPE and a field of OBJECT_TYPE, which is an ARRAY_TYPE. | |
3381 | If ARRAY_TYPE is that of an unconstrained array, this is used to represent | |
3382 | an arbitrary unconstrained object. Use NAME as the name of the record. | |
3383 | DEBUG_INFO_P is true if we need to write debug information for the type. */ | |
a1ab4c31 AC |
3384 | |
3385 | tree | |
928dfa4b EB |
3386 | build_unc_object_type (tree template_type, tree object_type, tree name, |
3387 | bool debug_info_p) | |
a1ab4c31 AC |
3388 | { |
3389 | tree type = make_node (RECORD_TYPE); | |
da01bfee EB |
3390 | tree template_field |
3391 | = create_field_decl (get_identifier ("BOUNDS"), template_type, type, | |
3392 | NULL_TREE, NULL_TREE, 0, 1); | |
3393 | tree array_field | |
3394 | = create_field_decl (get_identifier ("ARRAY"), object_type, type, | |
3395 | NULL_TREE, NULL_TREE, 0, 1); | |
a1ab4c31 AC |
3396 | |
3397 | TYPE_NAME (type) = name; | |
3398 | TYPE_CONTAINS_TEMPLATE_P (type) = 1; | |
910ad8de | 3399 | DECL_CHAIN (template_field) = array_field; |
928dfa4b EB |
3400 | finish_record_type (type, template_field, 0, true); |
3401 | ||
3402 | /* Declare it now since it will never be declared otherwise. This is | |
3403 | necessary to ensure that its subtrees are properly marked. */ | |
3404 | create_type_decl (name, type, NULL, true, debug_info_p, Empty); | |
a1ab4c31 AC |
3405 | |
3406 | return type; | |
3407 | } | |
3408 | ||
3409 | /* Same, taking a thin or fat pointer type instead of a template type. */ | |
3410 | ||
3411 | tree | |
3412 | build_unc_object_type_from_ptr (tree thin_fat_ptr_type, tree object_type, | |
928dfa4b | 3413 | tree name, bool debug_info_p) |
a1ab4c31 AC |
3414 | { |
3415 | tree template_type; | |
3416 | ||
315cff15 | 3417 | gcc_assert (TYPE_IS_FAT_OR_THIN_POINTER_P (thin_fat_ptr_type)); |
a1ab4c31 AC |
3418 | |
3419 | template_type | |
315cff15 | 3420 | = (TYPE_IS_FAT_POINTER_P (thin_fat_ptr_type) |
910ad8de | 3421 | ? TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (thin_fat_ptr_type)))) |
a1ab4c31 | 3422 | : TREE_TYPE (TYPE_FIELDS (TREE_TYPE (thin_fat_ptr_type)))); |
928dfa4b EB |
3423 | |
3424 | return | |
3425 | build_unc_object_type (template_type, object_type, name, debug_info_p); | |
a1ab4c31 | 3426 | } |
a1ab4c31 | 3427 | \f |
229077b0 EB |
3428 | /* Update anything previously pointing to OLD_TYPE to point to NEW_TYPE. |
3429 | In the normal case this is just two adjustments, but we have more to | |
3430 | do if NEW_TYPE is an UNCONSTRAINED_ARRAY_TYPE. */ | |
a1ab4c31 AC |
3431 | |
3432 | void | |
3433 | update_pointer_to (tree old_type, tree new_type) | |
3434 | { | |
3435 | tree ptr = TYPE_POINTER_TO (old_type); | |
3436 | tree ref = TYPE_REFERENCE_TO (old_type); | |
aeecf17c | 3437 | tree t; |
a1ab4c31 AC |
3438 | |
3439 | /* If this is the main variant, process all the other variants first. */ | |
3440 | if (TYPE_MAIN_VARIANT (old_type) == old_type) | |
aeecf17c EB |
3441 | for (t = TYPE_NEXT_VARIANT (old_type); t; t = TYPE_NEXT_VARIANT (t)) |
3442 | update_pointer_to (t, new_type); | |
a1ab4c31 | 3443 | |
229077b0 | 3444 | /* If no pointers and no references, we are done. */ |
a1ab4c31 AC |
3445 | if (!ptr && !ref) |
3446 | return; | |
3447 | ||
3448 | /* Merge the old type qualifiers in the new type. | |
3449 | ||
3450 | Each old variant has qualifiers for specific reasons, and the new | |
229077b0 | 3451 | designated type as well. Each set of qualifiers represents useful |
a1ab4c31 AC |
3452 | information grabbed at some point, and merging the two simply unifies |
3453 | these inputs into the final type description. | |
3454 | ||
3455 | Consider for instance a volatile type frozen after an access to constant | |
229077b0 EB |
3456 | type designating it; after the designated type's freeze, we get here with |
3457 | a volatile NEW_TYPE and a dummy OLD_TYPE with a readonly variant, created | |
3458 | when the access type was processed. We will make a volatile and readonly | |
a1ab4c31 AC |
3459 | designated type, because that's what it really is. |
3460 | ||
229077b0 EB |
3461 | We might also get here for a non-dummy OLD_TYPE variant with different |
3462 | qualifiers than those of NEW_TYPE, for instance in some cases of pointers | |
a1ab4c31 | 3463 | to private record type elaboration (see the comments around the call to |
229077b0 EB |
3464 | this routine in gnat_to_gnu_entity <E_Access_Type>). We have to merge |
3465 | the qualifiers in those cases too, to avoid accidentally discarding the | |
3466 | initial set, and will often end up with OLD_TYPE == NEW_TYPE then. */ | |
3467 | new_type | |
3468 | = build_qualified_type (new_type, | |
3469 | TYPE_QUALS (old_type) | TYPE_QUALS (new_type)); | |
3470 | ||
3471 | /* If old type and new type are identical, there is nothing to do. */ | |
a1ab4c31 AC |
3472 | if (old_type == new_type) |
3473 | return; | |
3474 | ||
3475 | /* Otherwise, first handle the simple case. */ | |
3476 | if (TREE_CODE (new_type) != UNCONSTRAINED_ARRAY_TYPE) | |
3477 | { | |
aeecf17c EB |
3478 | tree new_ptr, new_ref; |
3479 | ||
3480 | /* If pointer or reference already points to new type, nothing to do. | |
3481 | This can happen as update_pointer_to can be invoked multiple times | |
3482 | on the same couple of types because of the type variants. */ | |
3483 | if ((ptr && TREE_TYPE (ptr) == new_type) | |
3484 | || (ref && TREE_TYPE (ref) == new_type)) | |
3485 | return; | |
3486 | ||
3487 | /* Chain PTR and its variants at the end. */ | |
3488 | new_ptr = TYPE_POINTER_TO (new_type); | |
3489 | if (new_ptr) | |
3490 | { | |
3491 | while (TYPE_NEXT_PTR_TO (new_ptr)) | |
3492 | new_ptr = TYPE_NEXT_PTR_TO (new_ptr); | |
3493 | TYPE_NEXT_PTR_TO (new_ptr) = ptr; | |
3494 | } | |
3495 | else | |
3496 | TYPE_POINTER_TO (new_type) = ptr; | |
a1ab4c31 | 3497 | |
aeecf17c | 3498 | /* Now adjust them. */ |
a1ab4c31 | 3499 | for (; ptr; ptr = TYPE_NEXT_PTR_TO (ptr)) |
aeecf17c | 3500 | for (t = TYPE_MAIN_VARIANT (ptr); t; t = TYPE_NEXT_VARIANT (t)) |
50179d58 EB |
3501 | { |
3502 | TREE_TYPE (t) = new_type; | |
3503 | if (TYPE_NULL_BOUNDS (t)) | |
3504 | TREE_TYPE (TREE_OPERAND (TYPE_NULL_BOUNDS (t), 0)) = new_type; | |
3505 | } | |
de9528f0 | 3506 | |
aeecf17c EB |
3507 | /* Chain REF and its variants at the end. */ |
3508 | new_ref = TYPE_REFERENCE_TO (new_type); | |
3509 | if (new_ref) | |
3510 | { | |
3511 | while (TYPE_NEXT_REF_TO (new_ref)) | |
3512 | new_ref = TYPE_NEXT_REF_TO (new_ref); | |
3513 | TYPE_NEXT_REF_TO (new_ref) = ref; | |
3514 | } | |
3515 | else | |
3516 | TYPE_REFERENCE_TO (new_type) = ref; | |
3517 | ||
3518 | /* Now adjust them. */ | |
a1ab4c31 | 3519 | for (; ref; ref = TYPE_NEXT_REF_TO (ref)) |
aeecf17c EB |
3520 | for (t = TYPE_MAIN_VARIANT (ref); t; t = TYPE_NEXT_VARIANT (t)) |
3521 | TREE_TYPE (t) = new_type; | |
de9528f0 EB |
3522 | |
3523 | TYPE_POINTER_TO (old_type) = NULL_TREE; | |
3bd6ca3f | 3524 | TYPE_REFERENCE_TO (old_type) = NULL_TREE; |
a1ab4c31 AC |
3525 | } |
3526 | ||
aeecf17c EB |
3527 | /* Now deal with the unconstrained array case. In this case the pointer |
3528 | is actually a record where both fields are pointers to dummy nodes. | |
e3edbd56 EB |
3529 | Turn them into pointers to the correct types using update_pointer_to. |
3530 | Likewise for the pointer to the object record (thin pointer). */ | |
a1ab4c31 AC |
3531 | else |
3532 | { | |
e3edbd56 | 3533 | tree new_ptr = TYPE_POINTER_TO (new_type); |
aeecf17c EB |
3534 | |
3535 | gcc_assert (TYPE_IS_FAT_POINTER_P (ptr)); | |
3536 | ||
e3edbd56 | 3537 | /* If PTR already points to NEW_TYPE, nothing to do. This can happen |
aeecf17c EB |
3538 | since update_pointer_to can be invoked multiple times on the same |
3539 | couple of types because of the type variants. */ | |
3540 | if (TYPE_UNCONSTRAINED_ARRAY (ptr) == new_type) | |
3541 | return; | |
3542 | ||
a1ab4c31 | 3543 | update_pointer_to |
e3edbd56 EB |
3544 | (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (ptr))), |
3545 | TREE_TYPE (TREE_TYPE (TYPE_FIELDS (new_ptr)))); | |
a1ab4c31 | 3546 | |
a1ab4c31 | 3547 | update_pointer_to |
e3edbd56 EB |
3548 | (TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (ptr)))), |
3549 | TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (new_ptr))))); | |
aeecf17c | 3550 | |
e3edbd56 EB |
3551 | update_pointer_to (TYPE_OBJECT_RECORD_TYPE (old_type), |
3552 | TYPE_OBJECT_RECORD_TYPE (new_type)); | |
a1ab4c31 | 3553 | |
e3edbd56 | 3554 | TYPE_POINTER_TO (old_type) = NULL_TREE; |
a1ab4c31 AC |
3555 | } |
3556 | } | |
3557 | \f | |
8df2e902 EB |
3558 | /* Convert EXPR, a pointer to a constrained array, into a pointer to an |
3559 | unconstrained one. This involves making or finding a template. */ | |
a1ab4c31 AC |
3560 | |
3561 | static tree | |
3562 | convert_to_fat_pointer (tree type, tree expr) | |
3563 | { | |
910ad8de | 3564 | tree template_type = TREE_TYPE (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (type)))); |
8df2e902 | 3565 | tree p_array_type = TREE_TYPE (TYPE_FIELDS (type)); |
a1ab4c31 | 3566 | tree etype = TREE_TYPE (expr); |
6bf68a93 | 3567 | tree template_tree; |
0e228dd9 | 3568 | VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 2); |
a1ab4c31 | 3569 | |
50179d58 EB |
3570 | /* If EXPR is null, make a fat pointer that contains a null pointer to the |
3571 | array (compare_fat_pointers ensures that this is the full discriminant) | |
3572 | and a valid pointer to the bounds. This latter property is necessary | |
3573 | since the compiler can hoist the load of the bounds done through it. */ | |
a1ab4c31 | 3574 | if (integer_zerop (expr)) |
0e228dd9 | 3575 | { |
50179d58 EB |
3576 | tree ptr_template_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (type))); |
3577 | tree null_bounds, t; | |
3578 | ||
3579 | if (TYPE_NULL_BOUNDS (ptr_template_type)) | |
3580 | null_bounds = TYPE_NULL_BOUNDS (ptr_template_type); | |
3581 | else | |
3582 | { | |
3583 | /* The template type can still be dummy at this point so we build an | |
3584 | empty constructor. The middle-end will fill it in with zeros. */ | |
3585 | t = build_constructor (template_type, NULL); | |
3586 | TREE_CONSTANT (t) = TREE_STATIC (t) = 1; | |
3587 | null_bounds = build_unary_op (ADDR_EXPR, NULL_TREE, t); | |
3588 | SET_TYPE_NULL_BOUNDS (ptr_template_type, null_bounds); | |
3589 | } | |
3590 | ||
0e228dd9 | 3591 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), |
50179d58 EB |
3592 | fold_convert (p_array_type, null_pointer_node)); |
3593 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (type)), null_bounds); | |
3594 | t = build_constructor (type, v); | |
3595 | /* Do not set TREE_CONSTANT so as to force T to static memory. */ | |
3596 | TREE_CONSTANT (t) = 0; | |
3597 | TREE_STATIC (t) = 1; | |
3598 | ||
3599 | return t; | |
0e228dd9 | 3600 | } |
a1ab4c31 | 3601 | |
0d7de0e1 EB |
3602 | /* If EXPR is a thin pointer, make template and data from the record. */ |
3603 | if (TYPE_IS_THIN_POINTER_P (etype)) | |
a1ab4c31 | 3604 | { |
0d7de0e1 | 3605 | tree field = TYPE_FIELDS (TREE_TYPE (etype)); |
a1ab4c31 | 3606 | |
7d7a1fe8 | 3607 | expr = gnat_protect_expr (expr); |
a1ab4c31 AC |
3608 | if (TREE_CODE (expr) == ADDR_EXPR) |
3609 | expr = TREE_OPERAND (expr, 0); | |
3610 | else | |
2b45154d EB |
3611 | { |
3612 | /* If we have a TYPE_UNCONSTRAINED_ARRAY attached to the RECORD_TYPE, | |
3613 | the thin pointer value has been shifted so we first need to shift | |
3614 | it back to get the template address. */ | |
3615 | if (TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (etype))) | |
3616 | expr | |
3617 | = build_binary_op (POINTER_PLUS_EXPR, etype, expr, | |
3618 | fold_build1 (NEGATE_EXPR, sizetype, | |
3619 | byte_position | |
3620 | (DECL_CHAIN (field)))); | |
3621 | expr = build1 (INDIRECT_REF, TREE_TYPE (etype), expr); | |
3622 | } | |
a1ab4c31 | 3623 | |
0d7de0e1 | 3624 | template_tree = build_component_ref (expr, NULL_TREE, field, false); |
a1ab4c31 AC |
3625 | expr = build_unary_op (ADDR_EXPR, NULL_TREE, |
3626 | build_component_ref (expr, NULL_TREE, | |
0d7de0e1 | 3627 | DECL_CHAIN (field), false)); |
a1ab4c31 | 3628 | } |
8df2e902 EB |
3629 | |
3630 | /* Otherwise, build the constructor for the template. */ | |
a1ab4c31 | 3631 | else |
6bf68a93 | 3632 | template_tree = build_template (template_type, TREE_TYPE (etype), expr); |
a1ab4c31 | 3633 | |
8df2e902 | 3634 | /* The final result is a constructor for the fat pointer. |
a1ab4c31 | 3635 | |
8df2e902 EB |
3636 | If EXPR is an argument of a foreign convention subprogram, the type it |
3637 | points to is directly the component type. In this case, the expression | |
a1ab4c31 | 3638 | type may not match the corresponding FIELD_DECL type at this point, so we |
8df2e902 | 3639 | call "convert" here to fix that up if necessary. This type consistency is |
a1ab4c31 | 3640 | required, for instance because it ensures that possible later folding of |
8df2e902 | 3641 | COMPONENT_REFs against this constructor always yields something of the |
a1ab4c31 AC |
3642 | same type as the initial reference. |
3643 | ||
8df2e902 EB |
3644 | Note that the call to "build_template" above is still fine because it |
3645 | will only refer to the provided TEMPLATE_TYPE in this case. */ | |
0e228dd9 NF |
3646 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), |
3647 | convert (p_array_type, expr)); | |
910ad8de | 3648 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (type)), |
0e228dd9 NF |
3649 | build_unary_op (ADDR_EXPR, NULL_TREE, |
3650 | template_tree)); | |
3651 | return gnat_build_constructor (type, v); | |
a1ab4c31 AC |
3652 | } |
3653 | \f | |
a1ab4c31 AC |
3654 | /* Create an expression whose value is that of EXPR, |
3655 | converted to type TYPE. The TREE_TYPE of the value | |
3656 | is always TYPE. This function implements all reasonable | |
3657 | conversions; callers should filter out those that are | |
3658 | not permitted by the language being compiled. */ | |
3659 | ||
3660 | tree | |
3661 | convert (tree type, tree expr) | |
3662 | { | |
a1ab4c31 AC |
3663 | tree etype = TREE_TYPE (expr); |
3664 | enum tree_code ecode = TREE_CODE (etype); | |
c34f3839 | 3665 | enum tree_code code = TREE_CODE (type); |
a1ab4c31 | 3666 | |
c34f3839 EB |
3667 | /* If the expression is already of the right type, we are done. */ |
3668 | if (etype == type) | |
a1ab4c31 AC |
3669 | return expr; |
3670 | ||
3671 | /* If both input and output have padding and are of variable size, do this | |
3672 | as an unchecked conversion. Likewise if one is a mere variant of the | |
3673 | other, so we avoid a pointless unpad/repad sequence. */ | |
3674 | else if (code == RECORD_TYPE && ecode == RECORD_TYPE | |
315cff15 | 3675 | && TYPE_PADDING_P (type) && TYPE_PADDING_P (etype) |
a1ab4c31 AC |
3676 | && (!TREE_CONSTANT (TYPE_SIZE (type)) |
3677 | || !TREE_CONSTANT (TYPE_SIZE (etype)) | |
3678 | || gnat_types_compatible_p (type, etype) | |
3679 | || TYPE_NAME (TREE_TYPE (TYPE_FIELDS (type))) | |
3680 | == TYPE_NAME (TREE_TYPE (TYPE_FIELDS (etype))))) | |
3681 | ; | |
3682 | ||
f88facfe EB |
3683 | /* If the output type has padding, convert to the inner type and make a |
3684 | constructor to build the record, unless a variable size is involved. */ | |
315cff15 | 3685 | else if (code == RECORD_TYPE && TYPE_PADDING_P (type)) |
a1ab4c31 | 3686 | { |
0e228dd9 NF |
3687 | VEC(constructor_elt,gc) *v; |
3688 | ||
a1ab4c31 AC |
3689 | /* If we previously converted from another type and our type is |
3690 | of variable size, remove the conversion to avoid the need for | |
f88facfe | 3691 | variable-sized temporaries. Likewise for a conversion between |
a1ab4c31 AC |
3692 | original and packable version. */ |
3693 | if (TREE_CODE (expr) == VIEW_CONVERT_EXPR | |
3694 | && (!TREE_CONSTANT (TYPE_SIZE (type)) | |
3695 | || (ecode == RECORD_TYPE | |
3696 | && TYPE_NAME (etype) | |
3697 | == TYPE_NAME (TREE_TYPE (TREE_OPERAND (expr, 0)))))) | |
3698 | expr = TREE_OPERAND (expr, 0); | |
3699 | ||
3700 | /* If we are just removing the padding from expr, convert the original | |
3701 | object if we have variable size in order to avoid the need for some | |
f88facfe | 3702 | variable-sized temporaries. Likewise if the padding is a variant |
a1ab4c31 AC |
3703 | of the other, so we avoid a pointless unpad/repad sequence. */ |
3704 | if (TREE_CODE (expr) == COMPONENT_REF | |
a1ab4c31 AC |
3705 | && TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (expr, 0))) |
3706 | && (!TREE_CONSTANT (TYPE_SIZE (type)) | |
3707 | || gnat_types_compatible_p (type, | |
3708 | TREE_TYPE (TREE_OPERAND (expr, 0))) | |
3709 | || (ecode == RECORD_TYPE | |
3710 | && TYPE_NAME (etype) | |
3711 | == TYPE_NAME (TREE_TYPE (TYPE_FIELDS (type)))))) | |
3712 | return convert (type, TREE_OPERAND (expr, 0)); | |
3713 | ||
431cfac1 EB |
3714 | /* If the inner type is of self-referential size and the expression type |
3715 | is a record, do this as an unchecked conversion. But first pad the | |
3716 | expression if possible to have the same size on both sides. */ | |
c34f3839 | 3717 | if (ecode == RECORD_TYPE |
f88facfe | 3718 | && CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type)))) |
431cfac1 | 3719 | { |
980a0501 | 3720 | if (TREE_CODE (TYPE_SIZE (etype)) == INTEGER_CST) |
431cfac1 | 3721 | expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty, |
980a0501 EB |
3722 | false, false, false, true), |
3723 | expr); | |
431cfac1 EB |
3724 | return unchecked_convert (type, expr, false); |
3725 | } | |
a1ab4c31 | 3726 | |
f88facfe EB |
3727 | /* If we are converting between array types with variable size, do the |
3728 | final conversion as an unchecked conversion, again to avoid the need | |
3729 | for some variable-sized temporaries. If valid, this conversion is | |
3730 | very likely purely technical and without real effects. */ | |
c34f3839 | 3731 | if (ecode == ARRAY_TYPE |
f88facfe EB |
3732 | && TREE_CODE (TREE_TYPE (TYPE_FIELDS (type))) == ARRAY_TYPE |
3733 | && !TREE_CONSTANT (TYPE_SIZE (etype)) | |
3734 | && !TREE_CONSTANT (TYPE_SIZE (type))) | |
3735 | return unchecked_convert (type, | |
3736 | convert (TREE_TYPE (TYPE_FIELDS (type)), | |
3737 | expr), | |
3738 | false); | |
3739 | ||
0e228dd9 NF |
3740 | v = VEC_alloc (constructor_elt, gc, 1); |
3741 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), | |
3742 | convert (TREE_TYPE (TYPE_FIELDS (type)), expr)); | |
3743 | return gnat_build_constructor (type, v); | |
a1ab4c31 AC |
3744 | } |
3745 | ||
3746 | /* If the input type has padding, remove it and convert to the output type. | |
3747 | The conditions ordering is arranged to ensure that the output type is not | |
3748 | a padding type here, as it is not clear whether the conversion would | |
3749 | always be correct if this was to happen. */ | |
315cff15 | 3750 | else if (ecode == RECORD_TYPE && TYPE_PADDING_P (etype)) |
a1ab4c31 AC |
3751 | { |
3752 | tree unpadded; | |
3753 | ||
3754 | /* If we have just converted to this padded type, just get the | |
3755 | inner expression. */ | |
3756 | if (TREE_CODE (expr) == CONSTRUCTOR | |
3757 | && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (expr)) | |
3758 | && VEC_index (constructor_elt, CONSTRUCTOR_ELTS (expr), 0)->index | |
3759 | == TYPE_FIELDS (etype)) | |
3760 | unpadded | |
3761 | = VEC_index (constructor_elt, CONSTRUCTOR_ELTS (expr), 0)->value; | |
3762 | ||
3763 | /* Otherwise, build an explicit component reference. */ | |
3764 | else | |
3765 | unpadded | |
3766 | = build_component_ref (expr, NULL_TREE, TYPE_FIELDS (etype), false); | |
3767 | ||
3768 | return convert (type, unpadded); | |
3769 | } | |
3770 | ||
3771 | /* If the input is a biased type, adjust first. */ | |
3772 | if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)) | |
3773 | return convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (etype), | |
3774 | fold_convert (TREE_TYPE (etype), | |
3775 | expr), | |
3776 | TYPE_MIN_VALUE (etype))); | |
3777 | ||
3778 | /* If the input is a justified modular type, we need to extract the actual | |
3779 | object before converting it to any other type with the exceptions of an | |
3780 | unconstrained array or of a mere type variant. It is useful to avoid the | |
3781 | extraction and conversion in the type variant case because it could end | |
3782 | up replacing a VAR_DECL expr by a constructor and we might be about the | |
3783 | take the address of the result. */ | |
3784 | if (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype) | |
3785 | && code != UNCONSTRAINED_ARRAY_TYPE | |
3786 | && TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (etype)) | |
3787 | return convert (type, build_component_ref (expr, NULL_TREE, | |
3788 | TYPE_FIELDS (etype), false)); | |
3789 | ||
3790 | /* If converting to a type that contains a template, convert to the data | |
3791 | type and then build the template. */ | |
3792 | if (code == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (type)) | |
3793 | { | |
910ad8de | 3794 | tree obj_type = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (type))); |
0e228dd9 | 3795 | VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 2); |
a1ab4c31 AC |
3796 | |
3797 | /* If the source already has a template, get a reference to the | |
3798 | associated array only, as we are going to rebuild a template | |
3799 | for the target type anyway. */ | |
3800 | expr = maybe_unconstrained_array (expr); | |
3801 | ||
0e228dd9 NF |
3802 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), |
3803 | build_template (TREE_TYPE (TYPE_FIELDS (type)), | |
3804 | obj_type, NULL_TREE)); | |
910ad8de | 3805 | CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (TYPE_FIELDS (type)), |
0e228dd9 NF |
3806 | convert (obj_type, expr)); |
3807 | return gnat_build_constructor (type, v); | |
a1ab4c31 AC |
3808 | } |
3809 | ||
a1c7d797 | 3810 | /* There are some cases of expressions that we process specially. */ |
a1ab4c31 AC |
3811 | switch (TREE_CODE (expr)) |
3812 | { | |
3813 | case ERROR_MARK: | |
3814 | return expr; | |
3815 | ||
3816 | case NULL_EXPR: | |
3817 | /* Just set its type here. For TRANSFORM_EXPR, we will do the actual | |
3818 | conversion in gnat_expand_expr. NULL_EXPR does not represent | |
3819 | and actual value, so no conversion is needed. */ | |
3820 | expr = copy_node (expr); | |
3821 | TREE_TYPE (expr) = type; | |
3822 | return expr; | |
3823 | ||
3824 | case STRING_CST: | |
3825 | /* If we are converting a STRING_CST to another constrained array type, | |
3826 | just make a new one in the proper type. */ | |
3827 | if (code == ecode && AGGREGATE_TYPE_P (etype) | |
3828 | && !(TREE_CODE (TYPE_SIZE (etype)) == INTEGER_CST | |
3829 | && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)) | |
3830 | { | |
3831 | expr = copy_node (expr); | |
3832 | TREE_TYPE (expr) = type; | |
3833 | return expr; | |
3834 | } | |
3835 | break; | |
3836 | ||
7948ae37 OH |
3837 | case VECTOR_CST: |
3838 | /* If we are converting a VECTOR_CST to a mere variant type, just make | |
3839 | a new one in the proper type. */ | |
3840 | if (code == ecode && gnat_types_compatible_p (type, etype)) | |
3841 | { | |
3842 | expr = copy_node (expr); | |
3843 | TREE_TYPE (expr) = type; | |
3844 | return expr; | |
3845 | } | |
3846 | ||
a1ab4c31 AC |
3847 | case CONSTRUCTOR: |
3848 | /* If we are converting a CONSTRUCTOR to a mere variant type, just make | |
3849 | a new one in the proper type. */ | |
3850 | if (code == ecode && gnat_types_compatible_p (type, etype)) | |
3851 | { | |
3852 | expr = copy_node (expr); | |
3853 | TREE_TYPE (expr) = type; | |
6ba4f08f EB |
3854 | CONSTRUCTOR_ELTS (expr) |
3855 | = VEC_copy (constructor_elt, gc, CONSTRUCTOR_ELTS (expr)); | |
a1ab4c31 AC |
3856 | return expr; |
3857 | } | |
3858 | ||
cb3d597d EB |
3859 | /* Likewise for a conversion between original and packable version, or |
3860 | conversion between types of the same size and with the same list of | |
3861 | fields, but we have to work harder to preserve type consistency. */ | |
a1ab4c31 AC |
3862 | if (code == ecode |
3863 | && code == RECORD_TYPE | |
cb3d597d EB |
3864 | && (TYPE_NAME (type) == TYPE_NAME (etype) |
3865 | || tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (etype)))) | |
3866 | ||
a1ab4c31 AC |
3867 | { |
3868 | VEC(constructor_elt,gc) *e = CONSTRUCTOR_ELTS (expr); | |
3869 | unsigned HOST_WIDE_INT len = VEC_length (constructor_elt, e); | |
3870 | VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, len); | |
3871 | tree efield = TYPE_FIELDS (etype), field = TYPE_FIELDS (type); | |
3872 | unsigned HOST_WIDE_INT idx; | |
3873 | tree index, value; | |
3874 | ||
db868e1e OH |
3875 | /* Whether we need to clear TREE_CONSTANT et al. on the output |
3876 | constructor when we convert in place. */ | |
3877 | bool clear_constant = false; | |
3878 | ||
a1ab4c31 AC |
3879 | FOR_EACH_CONSTRUCTOR_ELT(e, idx, index, value) |
3880 | { | |
cb3d597d EB |
3881 | constructor_elt *elt; |
3882 | /* We expect only simple constructors. */ | |
3883 | if (!SAME_FIELD_P (index, efield)) | |
3884 | break; | |
3885 | /* The field must be the same. */ | |
3886 | if (!SAME_FIELD_P (efield, field)) | |
a1ab4c31 | 3887 | break; |
cb3d597d | 3888 | elt = VEC_quick_push (constructor_elt, v, NULL); |
a1ab4c31 AC |
3889 | elt->index = field; |
3890 | elt->value = convert (TREE_TYPE (field), value); | |
db868e1e OH |
3891 | |
3892 | /* If packing has made this field a bitfield and the input | |
3893 | value couldn't be emitted statically any more, we need to | |
3894 | clear TREE_CONSTANT on our output. */ | |
ced57283 EB |
3895 | if (!clear_constant |
3896 | && TREE_CONSTANT (expr) | |
db868e1e OH |
3897 | && !CONSTRUCTOR_BITFIELD_P (efield) |
3898 | && CONSTRUCTOR_BITFIELD_P (field) | |
3899 | && !initializer_constant_valid_for_bitfield_p (value)) | |
3900 | clear_constant = true; | |
3901 | ||
910ad8de NF |
3902 | efield = DECL_CHAIN (efield); |
3903 | field = DECL_CHAIN (field); | |
a1ab4c31 AC |
3904 | } |
3905 | ||
db868e1e OH |
3906 | /* If we have been able to match and convert all the input fields |
3907 | to their output type, convert in place now. We'll fallback to a | |
3908 | view conversion downstream otherwise. */ | |
a1ab4c31 AC |
3909 | if (idx == len) |
3910 | { | |
3911 | expr = copy_node (expr); | |
3912 | TREE_TYPE (expr) = type; | |
3913 | CONSTRUCTOR_ELTS (expr) = v; | |
db868e1e | 3914 | if (clear_constant) |
ced57283 | 3915 | TREE_CONSTANT (expr) = TREE_STATIC (expr) = 0; |
a1ab4c31 AC |
3916 | return expr; |
3917 | } | |
3918 | } | |
7948ae37 OH |
3919 | |
3920 | /* Likewise for a conversion between array type and vector type with a | |
3921 | compatible representative array. */ | |
3922 | else if (code == VECTOR_TYPE | |
3923 | && ecode == ARRAY_TYPE | |
3924 | && gnat_types_compatible_p (TYPE_REPRESENTATIVE_ARRAY (type), | |
3925 | etype)) | |
3926 | { | |
3927 | VEC(constructor_elt,gc) *e = CONSTRUCTOR_ELTS (expr); | |
3928 | unsigned HOST_WIDE_INT len = VEC_length (constructor_elt, e); | |
3929 | VEC(constructor_elt,gc) *v; | |
3930 | unsigned HOST_WIDE_INT ix; | |
3931 | tree value; | |
3932 | ||
3933 | /* Build a VECTOR_CST from a *constant* array constructor. */ | |
3934 | if (TREE_CONSTANT (expr)) | |
3935 | { | |
3936 | bool constant_p = true; | |
3937 | ||
3938 | /* Iterate through elements and check if all constructor | |
3939 | elements are *_CSTs. */ | |
3940 | FOR_EACH_CONSTRUCTOR_VALUE (e, ix, value) | |
3941 | if (!CONSTANT_CLASS_P (value)) | |
3942 | { | |
3943 | constant_p = false; | |
3944 | break; | |
3945 | } | |
3946 | ||
3947 | if (constant_p) | |
3948 | return build_vector_from_ctor (type, | |
3949 | CONSTRUCTOR_ELTS (expr)); | |
3950 | } | |
3951 | ||
3952 | /* Otherwise, build a regular vector constructor. */ | |
3953 | v = VEC_alloc (constructor_elt, gc, len); | |
3954 | FOR_EACH_CONSTRUCTOR_VALUE (e, ix, value) | |
3955 | { | |
3956 | constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL); | |
3957 | elt->index = NULL_TREE; | |
3958 | elt->value = value; | |
3959 | } | |
3960 | expr = copy_node (expr); | |
3961 | TREE_TYPE (expr) = type; | |
3962 | CONSTRUCTOR_ELTS (expr) = v; | |
3963 | return expr; | |
3964 | } | |
a1ab4c31 AC |
3965 | break; |
3966 | ||
3967 | case UNCONSTRAINED_ARRAY_REF: | |
a1c7d797 EB |
3968 | /* First retrieve the underlying array. */ |
3969 | expr = maybe_unconstrained_array (expr); | |
3970 | etype = TREE_TYPE (expr); | |
3971 | ecode = TREE_CODE (etype); | |
3972 | break; | |
a1ab4c31 AC |
3973 | |
3974 | case VIEW_CONVERT_EXPR: | |
3975 | { | |
3976 | /* GCC 4.x is very sensitive to type consistency overall, and view | |
3977 | conversions thus are very frequent. Even though just "convert"ing | |
3978 | the inner operand to the output type is fine in most cases, it | |
3979 | might expose unexpected input/output type mismatches in special | |
3980 | circumstances so we avoid such recursive calls when we can. */ | |
3981 | tree op0 = TREE_OPERAND (expr, 0); | |
3982 | ||
3983 | /* If we are converting back to the original type, we can just | |
3984 | lift the input conversion. This is a common occurrence with | |
3985 | switches back-and-forth amongst type variants. */ | |
3986 | if (type == TREE_TYPE (op0)) | |
3987 | return op0; | |
3988 | ||
7948ae37 OH |
3989 | /* Otherwise, if we're converting between two aggregate or vector |
3990 | types, we might be allowed to substitute the VIEW_CONVERT_EXPR | |
3991 | target type in place or to just convert the inner expression. */ | |
3992 | if ((AGGREGATE_TYPE_P (type) && AGGREGATE_TYPE_P (etype)) | |
3993 | || (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (etype))) | |
a1ab4c31 AC |
3994 | { |
3995 | /* If we are converting between mere variants, we can just | |
3996 | substitute the VIEW_CONVERT_EXPR in place. */ | |
3997 | if (gnat_types_compatible_p (type, etype)) | |
3998 | return build1 (VIEW_CONVERT_EXPR, type, op0); | |
3999 | ||
4000 | /* Otherwise, we may just bypass the input view conversion unless | |
4001 | one of the types is a fat pointer, which is handled by | |
4002 | specialized code below which relies on exact type matching. */ | |
315cff15 EB |
4003 | else if (!TYPE_IS_FAT_POINTER_P (type) |
4004 | && !TYPE_IS_FAT_POINTER_P (etype)) | |
a1ab4c31 AC |
4005 | return convert (type, op0); |
4006 | } | |
ad1d36ba EB |
4007 | |
4008 | break; | |
a1ab4c31 | 4009 | } |
a1ab4c31 | 4010 | |
a1ab4c31 AC |
4011 | default: |
4012 | break; | |
4013 | } | |
4014 | ||
4015 | /* Check for converting to a pointer to an unconstrained array. */ | |
315cff15 | 4016 | if (TYPE_IS_FAT_POINTER_P (type) && !TYPE_IS_FAT_POINTER_P (etype)) |
a1ab4c31 AC |
4017 | return convert_to_fat_pointer (type, expr); |
4018 | ||
7948ae37 OH |
4019 | /* If we are converting between two aggregate or vector types that are mere |
4020 | variants, just make a VIEW_CONVERT_EXPR. Likewise when we are converting | |
4021 | to a vector type from its representative array type. */ | |
4022 | else if ((code == ecode | |
4023 | && (AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type)) | |
4024 | && gnat_types_compatible_p (type, etype)) | |
4025 | || (code == VECTOR_TYPE | |
4026 | && ecode == ARRAY_TYPE | |
4027 | && gnat_types_compatible_p (TYPE_REPRESENTATIVE_ARRAY (type), | |
4028 | etype))) | |
a1ab4c31 AC |
4029 | return build1 (VIEW_CONVERT_EXPR, type, expr); |
4030 | ||
76af763d EB |
4031 | /* If we are converting between tagged types, try to upcast properly. */ |
4032 | else if (ecode == RECORD_TYPE && code == RECORD_TYPE | |
4033 | && TYPE_ALIGN_OK (etype) && TYPE_ALIGN_OK (type)) | |
4034 | { | |
4035 | tree child_etype = etype; | |
4036 | do { | |
4037 | tree field = TYPE_FIELDS (child_etype); | |
4038 | if (DECL_NAME (field) == parent_name_id && TREE_TYPE (field) == type) | |
4039 | return build_component_ref (expr, NULL_TREE, field, false); | |
4040 | child_etype = TREE_TYPE (field); | |
4041 | } while (TREE_CODE (child_etype) == RECORD_TYPE); | |
4042 | } | |
4043 | ||
bb1f7929 EB |
4044 | /* If we are converting from a smaller form of record type back to it, just |
4045 | make a VIEW_CONVERT_EXPR. But first pad the expression to have the same | |
4046 | size on both sides. */ | |
4047 | else if (ecode == RECORD_TYPE && code == RECORD_TYPE | |
4048 | && smaller_form_type_p (etype, type)) | |
4049 | { | |
4050 | expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty, | |
4051 | false, false, false, true), | |
4052 | expr); | |
4053 | return build1 (VIEW_CONVERT_EXPR, type, expr); | |
4054 | } | |
4055 | ||
a1ab4c31 | 4056 | /* In all other cases of related types, make a NOP_EXPR. */ |
86060344 | 4057 | else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (etype)) |
a1ab4c31 AC |
4058 | return fold_convert (type, expr); |
4059 | ||
4060 | switch (code) | |
4061 | { | |
4062 | case VOID_TYPE: | |
4063 | return fold_build1 (CONVERT_EXPR, type, expr); | |
4064 | ||
a1ab4c31 AC |
4065 | case INTEGER_TYPE: |
4066 | if (TYPE_HAS_ACTUAL_BOUNDS_P (type) | |
4067 | && (ecode == ARRAY_TYPE || ecode == UNCONSTRAINED_ARRAY_TYPE | |
4068 | || (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype)))) | |
4069 | return unchecked_convert (type, expr, false); | |
4070 | else if (TYPE_BIASED_REPRESENTATION_P (type)) | |
4071 | return fold_convert (type, | |
4072 | fold_build2 (MINUS_EXPR, TREE_TYPE (type), | |
4073 | convert (TREE_TYPE (type), expr), | |
4074 | TYPE_MIN_VALUE (type))); | |
4075 | ||
4076 | /* ... fall through ... */ | |
4077 | ||
4078 | case ENUMERAL_TYPE: | |
01ddebf2 | 4079 | case BOOLEAN_TYPE: |
a1ab4c31 AC |
4080 | /* If we are converting an additive expression to an integer type |
4081 | with lower precision, be wary of the optimization that can be | |
4082 | applied by convert_to_integer. There are 2 problematic cases: | |
4083 | - if the first operand was originally of a biased type, | |
4084 | because we could be recursively called to convert it | |
4085 | to an intermediate type and thus rematerialize the | |
4086 | additive operator endlessly, | |
4087 | - if the expression contains a placeholder, because an | |
4088 | intermediate conversion that changes the sign could | |
4089 | be inserted and thus introduce an artificial overflow | |
4090 | at compile time when the placeholder is substituted. */ | |
4091 | if (code == INTEGER_TYPE | |
4092 | && ecode == INTEGER_TYPE | |
4093 | && TYPE_PRECISION (type) < TYPE_PRECISION (etype) | |
4094 | && (TREE_CODE (expr) == PLUS_EXPR || TREE_CODE (expr) == MINUS_EXPR)) | |
4095 | { | |
4096 | tree op0 = get_unwidened (TREE_OPERAND (expr, 0), type); | |
4097 | ||
4098 | if ((TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE | |
4099 | && TYPE_BIASED_REPRESENTATION_P (TREE_TYPE (op0))) | |
4100 | || CONTAINS_PLACEHOLDER_P (expr)) | |
4101 | return build1 (NOP_EXPR, type, expr); | |
4102 | } | |
4103 | ||
4104 | return fold (convert_to_integer (type, expr)); | |
4105 | ||
4106 | case POINTER_TYPE: | |
4107 | case REFERENCE_TYPE: | |
0d7de0e1 | 4108 | /* If converting between two thin pointers, adjust if needed to account |
2b45154d EB |
4109 | for differing offsets from the base pointer, depending on whether |
4110 | there is a TYPE_UNCONSTRAINED_ARRAY attached to the record type. */ | |
315cff15 | 4111 | if (TYPE_IS_THIN_POINTER_P (etype) && TYPE_IS_THIN_POINTER_P (type)) |
a1ab4c31 | 4112 | { |
2b45154d EB |
4113 | tree etype_pos |
4114 | = TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (etype)) != NULL_TREE | |
4115 | ? byte_position (DECL_CHAIN (TYPE_FIELDS (TREE_TYPE (etype)))) | |
4116 | : size_zero_node; | |
4117 | tree type_pos | |
4118 | = TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (type)) != NULL_TREE | |
4119 | ? byte_position (DECL_CHAIN (TYPE_FIELDS (TREE_TYPE (type)))) | |
4120 | : size_zero_node; | |
4121 | tree byte_diff = size_diffop (type_pos, etype_pos); | |
0d7de0e1 | 4122 | |
a1ab4c31 | 4123 | expr = build1 (NOP_EXPR, type, expr); |
a1ab4c31 AC |
4124 | if (integer_zerop (byte_diff)) |
4125 | return expr; | |
4126 | ||
4127 | return build_binary_op (POINTER_PLUS_EXPR, type, expr, | |
0d7de0e1 | 4128 | fold_convert (sizetype, byte_diff)); |
a1ab4c31 AC |
4129 | } |
4130 | ||
0d7de0e1 EB |
4131 | /* If converting fat pointer to normal or thin pointer, get the pointer |
4132 | to the array and then convert it. */ | |
4133 | if (TYPE_IS_FAT_POINTER_P (etype)) | |
86060344 EB |
4134 | expr |
4135 | = build_component_ref (expr, NULL_TREE, TYPE_FIELDS (etype), false); | |
a1ab4c31 AC |
4136 | |
4137 | return fold (convert_to_pointer (type, expr)); | |
4138 | ||
4139 | case REAL_TYPE: | |
4140 | return fold (convert_to_real (type, expr)); | |
4141 | ||
4142 | case RECORD_TYPE: | |
4143 | if (TYPE_JUSTIFIED_MODULAR_P (type) && !AGGREGATE_TYPE_P (etype)) | |
0e228dd9 NF |
4144 | { |
4145 | VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 1); | |
4146 | ||
4147 | CONSTRUCTOR_APPEND_ELT (v, TYPE_FIELDS (type), | |
4148 | convert (TREE_TYPE (TYPE_FIELDS (type)), | |
4149 | expr)); | |
4150 | return gnat_build_constructor (type, v); | |
4151 | } | |
a1ab4c31 AC |
4152 | |
4153 | /* ... fall through ... */ | |
4154 | ||
4155 | case ARRAY_TYPE: | |
4156 | /* In these cases, assume the front-end has validated the conversion. | |
4157 | If the conversion is valid, it will be a bit-wise conversion, so | |
4158 | it can be viewed as an unchecked conversion. */ | |
4159 | return unchecked_convert (type, expr, false); | |
4160 | ||
4161 | case UNION_TYPE: | |
4162 | /* This is a either a conversion between a tagged type and some | |
4163 | subtype, which we have to mark as a UNION_TYPE because of | |
4164 | overlapping fields or a conversion of an Unchecked_Union. */ | |
4165 | return unchecked_convert (type, expr, false); | |
4166 | ||
4167 | case UNCONSTRAINED_ARRAY_TYPE: | |
7948ae37 OH |
4168 | /* If the input is a VECTOR_TYPE, convert to the representative |
4169 | array type first. */ | |
4170 | if (ecode == VECTOR_TYPE) | |
4171 | { | |
4172 | expr = convert (TYPE_REPRESENTATIVE_ARRAY (etype), expr); | |
4173 | etype = TREE_TYPE (expr); | |
4174 | ecode = TREE_CODE (etype); | |
4175 | } | |
4176 | ||
a1ab4c31 AC |
4177 | /* If EXPR is a constrained array, take its address, convert it to a |
4178 | fat pointer, and then dereference it. Likewise if EXPR is a | |
4179 | record containing both a template and a constrained array. | |
4180 | Note that a record representing a justified modular type | |
4181 | always represents a packed constrained array. */ | |
4182 | if (ecode == ARRAY_TYPE | |
4183 | || (ecode == INTEGER_TYPE && TYPE_HAS_ACTUAL_BOUNDS_P (etype)) | |
4184 | || (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype)) | |
4185 | || (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype))) | |
4186 | return | |
4187 | build_unary_op | |
4188 | (INDIRECT_REF, NULL_TREE, | |
4189 | convert_to_fat_pointer (TREE_TYPE (type), | |
4190 | build_unary_op (ADDR_EXPR, | |
4191 | NULL_TREE, expr))); | |
4192 | ||
4193 | /* Do something very similar for converting one unconstrained | |
4194 | array to another. */ | |
4195 | else if (ecode == UNCONSTRAINED_ARRAY_TYPE) | |
4196 | return | |
4197 | build_unary_op (INDIRECT_REF, NULL_TREE, | |
4198 | convert (TREE_TYPE (type), | |
4199 | build_unary_op (ADDR_EXPR, | |
4200 | NULL_TREE, expr))); | |
4201 | else | |
4202 | gcc_unreachable (); | |
4203 | ||
4204 | case COMPLEX_TYPE: | |
4205 | return fold (convert_to_complex (type, expr)); | |
4206 | ||
4207 | default: | |
4208 | gcc_unreachable (); | |
4209 | } | |
4210 | } | |
15bf7d19 EB |
4211 | |
4212 | /* Create an expression whose value is that of EXPR converted to the common | |
4213 | index type, which is sizetype. EXPR is supposed to be in the base type | |
4214 | of the GNAT index type. Calling it is equivalent to doing | |
4215 | ||
4216 | convert (sizetype, expr) | |
4217 | ||
4218 | but we try to distribute the type conversion with the knowledge that EXPR | |
4219 | cannot overflow in its type. This is a best-effort approach and we fall | |
4220 | back to the above expression as soon as difficulties are encountered. | |
4221 | ||
4222 | This is necessary to overcome issues that arise when the GNAT base index | |
4223 | type and the GCC common index type (sizetype) don't have the same size, | |
4224 | which is quite frequent on 64-bit architectures. In this case, and if | |
4225 | the GNAT base index type is signed but the iteration type of the loop has | |
4226 | been forced to unsigned, the loop scalar evolution engine cannot compute | |
4227 | a simple evolution for the general induction variables associated with the | |
4228 | array indices, because it will preserve the wrap-around semantics in the | |
4229 | unsigned type of their "inner" part. As a result, many loop optimizations | |
4230 | are blocked. | |
4231 | ||
4232 | The solution is to use a special (basic) induction variable that is at | |
4233 | least as large as sizetype, and to express the aforementioned general | |
4234 | induction variables in terms of this induction variable, eliminating | |
4235 | the problematic intermediate truncation to the GNAT base index type. | |
4236 | This is possible as long as the original expression doesn't overflow | |
4237 | and if the middle-end hasn't introduced artificial overflows in the | |
4238 | course of the various simplification it can make to the expression. */ | |
4239 | ||
4240 | tree | |
4241 | convert_to_index_type (tree expr) | |
4242 | { | |
4243 | enum tree_code code = TREE_CODE (expr); | |
4244 | tree type = TREE_TYPE (expr); | |
4245 | ||
4246 | /* If the type is unsigned, overflow is allowed so we cannot be sure that | |
4247 | EXPR doesn't overflow. Keep it simple if optimization is disabled. */ | |
4248 | if (TYPE_UNSIGNED (type) || !optimize) | |
4249 | return convert (sizetype, expr); | |
4250 | ||
4251 | switch (code) | |
4252 | { | |
4253 | case VAR_DECL: | |
4254 | /* The main effect of the function: replace a loop parameter with its | |
4255 | associated special induction variable. */ | |
4256 | if (DECL_LOOP_PARM_P (expr) && DECL_INDUCTION_VAR (expr)) | |
4257 | expr = DECL_INDUCTION_VAR (expr); | |
4258 | break; | |
4259 | ||
4260 | CASE_CONVERT: | |
4261 | { | |
4262 | tree otype = TREE_TYPE (TREE_OPERAND (expr, 0)); | |
4263 | /* Bail out as soon as we suspect some sort of type frobbing. */ | |
4264 | if (TYPE_PRECISION (type) != TYPE_PRECISION (otype) | |
4265 | || TYPE_UNSIGNED (type) != TYPE_UNSIGNED (otype)) | |
4266 | break; | |
4267 | } | |
4268 | ||
4269 | /* ... fall through ... */ | |
4270 | ||
4271 | case NON_LVALUE_EXPR: | |
4272 | return fold_build1 (code, sizetype, | |
4273 | convert_to_index_type (TREE_OPERAND (expr, 0))); | |
4274 | ||
4275 | case PLUS_EXPR: | |
4276 | case MINUS_EXPR: | |
4277 | case MULT_EXPR: | |
4278 | return fold_build2 (code, sizetype, | |
4279 | convert_to_index_type (TREE_OPERAND (expr, 0)), | |
4280 | convert_to_index_type (TREE_OPERAND (expr, 1))); | |
4281 | ||
4282 | case COMPOUND_EXPR: | |
4283 | return fold_build2 (code, sizetype, TREE_OPERAND (expr, 0), | |
4284 | convert_to_index_type (TREE_OPERAND (expr, 1))); | |
4285 | ||
4286 | case COND_EXPR: | |
4287 | return fold_build3 (code, sizetype, TREE_OPERAND (expr, 0), | |
4288 | convert_to_index_type (TREE_OPERAND (expr, 1)), | |
4289 | convert_to_index_type (TREE_OPERAND (expr, 2))); | |
4290 | ||
4291 | default: | |
4292 | break; | |
4293 | } | |
4294 | ||
4295 | return convert (sizetype, expr); | |
4296 | } | |
a1ab4c31 AC |
4297 | \f |
4298 | /* Remove all conversions that are done in EXP. This includes converting | |
4299 | from a padded type or to a justified modular type. If TRUE_ADDRESS | |
4300 | is true, always return the address of the containing object even if | |
4301 | the address is not bit-aligned. */ | |
4302 | ||
4303 | tree | |
4304 | remove_conversions (tree exp, bool true_address) | |
4305 | { | |
4306 | switch (TREE_CODE (exp)) | |
4307 | { | |
4308 | case CONSTRUCTOR: | |
4309 | if (true_address | |
4310 | && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE | |
4311 | && TYPE_JUSTIFIED_MODULAR_P (TREE_TYPE (exp))) | |
4312 | return | |
4313 | remove_conversions (VEC_index (constructor_elt, | |
4314 | CONSTRUCTOR_ELTS (exp), 0)->value, | |
4315 | true); | |
4316 | break; | |
4317 | ||
4318 | case COMPONENT_REF: | |
315cff15 | 4319 | if (TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (exp, 0)))) |
a1ab4c31 AC |
4320 | return remove_conversions (TREE_OPERAND (exp, 0), true_address); |
4321 | break; | |
4322 | ||
a1ab4c31 | 4323 | CASE_CONVERT: |
722356ce EB |
4324 | case VIEW_CONVERT_EXPR: |
4325 | case NON_LVALUE_EXPR: | |
a1ab4c31 AC |
4326 | return remove_conversions (TREE_OPERAND (exp, 0), true_address); |
4327 | ||
4328 | default: | |
4329 | break; | |
4330 | } | |
4331 | ||
4332 | return exp; | |
4333 | } | |
4334 | \f | |
4335 | /* If EXP's type is an UNCONSTRAINED_ARRAY_TYPE, return an expression that | |
86060344 | 4336 | refers to the underlying array. If it has TYPE_CONTAINS_TEMPLATE_P, |
a1ab4c31 AC |
4337 | likewise return an expression pointing to the underlying array. */ |
4338 | ||
4339 | tree | |
4340 | maybe_unconstrained_array (tree exp) | |
4341 | { | |
4342 | enum tree_code code = TREE_CODE (exp); | |
1aa291f7 | 4343 | tree type = TREE_TYPE (exp); |
a1ab4c31 | 4344 | |
1aa291f7 | 4345 | switch (TREE_CODE (type)) |
a1ab4c31 AC |
4346 | { |
4347 | case UNCONSTRAINED_ARRAY_TYPE: | |
4348 | if (code == UNCONSTRAINED_ARRAY_REF) | |
4349 | { | |
7e169899 | 4350 | const bool read_only = TREE_READONLY (exp); |
a1c7d797 EB |
4351 | const bool no_trap = TREE_THIS_NOTRAP (exp); |
4352 | ||
7e169899 | 4353 | exp = TREE_OPERAND (exp, 0); |
1aa291f7 EB |
4354 | type = TREE_TYPE (exp); |
4355 | ||
7e169899 EB |
4356 | if (TREE_CODE (exp) == COND_EXPR) |
4357 | { | |
4358 | tree op1 | |
4359 | = build_unary_op (INDIRECT_REF, NULL_TREE, | |
4360 | build_component_ref (TREE_OPERAND (exp, 1), | |
4361 | NULL_TREE, | |
1aa291f7 | 4362 | TYPE_FIELDS (type), |
7e169899 EB |
4363 | false)); |
4364 | tree op2 | |
4365 | = build_unary_op (INDIRECT_REF, NULL_TREE, | |
4366 | build_component_ref (TREE_OPERAND (exp, 2), | |
4367 | NULL_TREE, | |
1aa291f7 | 4368 | TYPE_FIELDS (type), |
7e169899 EB |
4369 | false)); |
4370 | ||
4371 | exp = build3 (COND_EXPR, | |
1aa291f7 | 4372 | TREE_TYPE (TREE_TYPE (TYPE_FIELDS (type))), |
7e169899 EB |
4373 | TREE_OPERAND (exp, 0), op1, op2); |
4374 | } | |
4375 | else | |
a1c7d797 EB |
4376 | { |
4377 | exp = build_unary_op (INDIRECT_REF, NULL_TREE, | |
4378 | build_component_ref (exp, NULL_TREE, | |
1aa291f7 | 4379 | TYPE_FIELDS (type), |
a1c7d797 EB |
4380 | false)); |
4381 | TREE_READONLY (exp) = read_only; | |
4382 | TREE_THIS_NOTRAP (exp) = no_trap; | |
4383 | } | |
a1ab4c31 AC |
4384 | } |
4385 | ||
4386 | else if (code == NULL_EXPR) | |
1aa291f7 EB |
4387 | exp = build1 (NULL_EXPR, |
4388 | TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))), | |
4389 | TREE_OPERAND (exp, 0)); | |
4390 | break; | |
a1ab4c31 AC |
4391 | |
4392 | case RECORD_TYPE: | |
1aa291f7 EB |
4393 | /* If this is a padded type and it contains a template, convert to the |
4394 | unpadded type first. */ | |
4395 | if (TYPE_PADDING_P (type) | |
4396 | && TREE_CODE (TREE_TYPE (TYPE_FIELDS (type))) == RECORD_TYPE | |
4397 | && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (TYPE_FIELDS (type)))) | |
a1ab4c31 | 4398 | { |
1aa291f7 EB |
4399 | exp = convert (TREE_TYPE (TYPE_FIELDS (type)), exp); |
4400 | type = TREE_TYPE (exp); | |
4401 | } | |
4402 | ||
4403 | if (TYPE_CONTAINS_TEMPLATE_P (type)) | |
4404 | { | |
4405 | exp = build_component_ref (exp, NULL_TREE, | |
4406 | DECL_CHAIN (TYPE_FIELDS (type)), | |
4407 | false); | |
4408 | type = TREE_TYPE (exp); | |
4409 | ||
4410 | /* If the array type is padded, convert to the unpadded type. */ | |
4411 | if (TYPE_IS_PADDING_P (type)) | |
4412 | exp = convert (TREE_TYPE (TYPE_FIELDS (type)), exp); | |
a1ab4c31 | 4413 | } |
a1ab4c31 AC |
4414 | break; |
4415 | ||
4416 | default: | |
4417 | break; | |
4418 | } | |
4419 | ||
4420 | return exp; | |
4421 | } | |
7948ae37 OH |
4422 | |
4423 | /* If EXP's type is a VECTOR_TYPE, return EXP converted to the associated | |
4424 | TYPE_REPRESENTATIVE_ARRAY. */ | |
4425 | ||
4426 | tree | |
4427 | maybe_vector_array (tree exp) | |
4428 | { | |
4429 | tree etype = TREE_TYPE (exp); | |
4430 | ||
4431 | if (VECTOR_TYPE_P (etype)) | |
4432 | exp = convert (TYPE_REPRESENTATIVE_ARRAY (etype), exp); | |
4433 | ||
4434 | return exp; | |
4435 | } | |
a1ab4c31 | 4436 | \f |
afcea859 | 4437 | /* Return true if EXPR is an expression that can be folded as an operand |
84fb43a1 | 4438 | of a VIEW_CONVERT_EXPR. See ada-tree.h for a complete rationale. */ |
afcea859 EB |
4439 | |
4440 | static bool | |
4441 | can_fold_for_view_convert_p (tree expr) | |
4442 | { | |
4443 | tree t1, t2; | |
4444 | ||
4445 | /* The folder will fold NOP_EXPRs between integral types with the same | |
4446 | precision (in the middle-end's sense). We cannot allow it if the | |
4447 | types don't have the same precision in the Ada sense as well. */ | |
4448 | if (TREE_CODE (expr) != NOP_EXPR) | |
4449 | return true; | |
4450 | ||
4451 | t1 = TREE_TYPE (expr); | |
4452 | t2 = TREE_TYPE (TREE_OPERAND (expr, 0)); | |
4453 | ||
4454 | /* Defer to the folder for non-integral conversions. */ | |
4455 | if (!(INTEGRAL_TYPE_P (t1) && INTEGRAL_TYPE_P (t2))) | |
4456 | return true; | |
4457 | ||
4458 | /* Only fold conversions that preserve both precisions. */ | |
4459 | if (TYPE_PRECISION (t1) == TYPE_PRECISION (t2) | |
4460 | && operand_equal_p (rm_size (t1), rm_size (t2), 0)) | |
4461 | return true; | |
4462 | ||
4463 | return false; | |
4464 | } | |
4465 | ||
a1ab4c31 | 4466 | /* Return an expression that does an unchecked conversion of EXPR to TYPE. |
afcea859 EB |
4467 | If NOTRUNC_P is true, truncation operations should be suppressed. |
4468 | ||
4469 | Special care is required with (source or target) integral types whose | |
4470 | precision is not equal to their size, to make sure we fetch or assign | |
4471 | the value bits whose location might depend on the endianness, e.g. | |
4472 | ||
4473 | Rmsize : constant := 8; | |
4474 | subtype Int is Integer range 0 .. 2 ** Rmsize - 1; | |
4475 | ||
4476 | type Bit_Array is array (1 .. Rmsize) of Boolean; | |
4477 | pragma Pack (Bit_Array); | |
4478 | ||
4479 | function To_Bit_Array is new Unchecked_Conversion (Int, Bit_Array); | |
4480 | ||
4481 | Value : Int := 2#1000_0001#; | |
4482 | Vbits : Bit_Array := To_Bit_Array (Value); | |
4483 | ||
4484 | we expect the 8 bits at Vbits'Address to always contain Value, while | |
4485 | their original location depends on the endianness, at Value'Address | |
84fb43a1 | 4486 | on a little-endian architecture but not on a big-endian one. */ |
a1ab4c31 AC |
4487 | |
4488 | tree | |
4489 | unchecked_convert (tree type, tree expr, bool notrunc_p) | |
4490 | { | |
4491 | tree etype = TREE_TYPE (expr); | |
c34f3839 EB |
4492 | enum tree_code ecode = TREE_CODE (etype); |
4493 | enum tree_code code = TREE_CODE (type); | |
980a0501 | 4494 | int c; |
a1ab4c31 | 4495 | |
c34f3839 | 4496 | /* If the expression is already of the right type, we are done. */ |
a1ab4c31 AC |
4497 | if (etype == type) |
4498 | return expr; | |
4499 | ||
4500 | /* If both types types are integral just do a normal conversion. | |
4501 | Likewise for a conversion to an unconstrained array. */ | |
4502 | if ((((INTEGRAL_TYPE_P (type) | |
c34f3839 | 4503 | && !(code == INTEGER_TYPE && TYPE_VAX_FLOATING_POINT_P (type))) |
0d7de0e1 | 4504 | || (POINTER_TYPE_P (type) && !TYPE_IS_THIN_POINTER_P (type)) |
c34f3839 | 4505 | || (code == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (type))) |
a1ab4c31 | 4506 | && ((INTEGRAL_TYPE_P (etype) |
c34f3839 | 4507 | && !(ecode == INTEGER_TYPE && TYPE_VAX_FLOATING_POINT_P (etype))) |
315cff15 | 4508 | || (POINTER_TYPE_P (etype) && !TYPE_IS_THIN_POINTER_P (etype)) |
c34f3839 EB |
4509 | || (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype)))) |
4510 | || code == UNCONSTRAINED_ARRAY_TYPE) | |
a1ab4c31 | 4511 | { |
c34f3839 | 4512 | if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)) |
a1ab4c31 AC |
4513 | { |
4514 | tree ntype = copy_type (etype); | |
a1ab4c31 AC |
4515 | TYPE_BIASED_REPRESENTATION_P (ntype) = 0; |
4516 | TYPE_MAIN_VARIANT (ntype) = ntype; | |
4517 | expr = build1 (NOP_EXPR, ntype, expr); | |
4518 | } | |
4519 | ||
c34f3839 | 4520 | if (code == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type)) |
a1ab4c31 | 4521 | { |
afcea859 | 4522 | tree rtype = copy_type (type); |
a1ab4c31 AC |
4523 | TYPE_BIASED_REPRESENTATION_P (rtype) = 0; |
4524 | TYPE_MAIN_VARIANT (rtype) = rtype; | |
afcea859 EB |
4525 | expr = convert (rtype, expr); |
4526 | expr = build1 (NOP_EXPR, type, expr); | |
a1ab4c31 | 4527 | } |
afcea859 EB |
4528 | else |
4529 | expr = convert (type, expr); | |
a1ab4c31 AC |
4530 | } |
4531 | ||
afcea859 | 4532 | /* If we are converting to an integral type whose precision is not equal |
416de7d5 EB |
4533 | to its size, first unchecked convert to a record type that contains an |
4534 | field of the given precision. Then extract the field. */ | |
980a0501 EB |
4535 | else if (INTEGRAL_TYPE_P (type) |
4536 | && TYPE_RM_SIZE (type) | |
a1ab4c31 AC |
4537 | && 0 != compare_tree_int (TYPE_RM_SIZE (type), |
4538 | GET_MODE_BITSIZE (TYPE_MODE (type)))) | |
4539 | { | |
4540 | tree rec_type = make_node (RECORD_TYPE); | |
416de7d5 EB |
4541 | unsigned HOST_WIDE_INT prec = TREE_INT_CST_LOW (TYPE_RM_SIZE (type)); |
4542 | tree field_type, field; | |
4543 | ||
4544 | if (TYPE_UNSIGNED (type)) | |
4545 | field_type = make_unsigned_type (prec); | |
4546 | else | |
4547 | field_type = make_signed_type (prec); | |
4548 | SET_TYPE_RM_SIZE (field_type, TYPE_RM_SIZE (type)); | |
4549 | ||
4550 | field = create_field_decl (get_identifier ("OBJ"), field_type, rec_type, | |
4551 | NULL_TREE, NULL_TREE, 1, 0); | |
a1ab4c31 AC |
4552 | |
4553 | TYPE_FIELDS (rec_type) = field; | |
4554 | layout_type (rec_type); | |
4555 | ||
4556 | expr = unchecked_convert (rec_type, expr, notrunc_p); | |
3cd64bab | 4557 | expr = build_component_ref (expr, NULL_TREE, field, false); |
416de7d5 | 4558 | expr = fold_build1 (NOP_EXPR, type, expr); |
a1ab4c31 AC |
4559 | } |
4560 | ||
416de7d5 EB |
4561 | /* Similarly if we are converting from an integral type whose precision is |
4562 | not equal to its size, first copy into a field of the given precision | |
4563 | and unchecked convert the record type. */ | |
980a0501 EB |
4564 | else if (INTEGRAL_TYPE_P (etype) |
4565 | && TYPE_RM_SIZE (etype) | |
4566 | && 0 != compare_tree_int (TYPE_RM_SIZE (etype), | |
4567 | GET_MODE_BITSIZE (TYPE_MODE (etype)))) | |
a1ab4c31 AC |
4568 | { |
4569 | tree rec_type = make_node (RECORD_TYPE); | |
416de7d5 | 4570 | unsigned HOST_WIDE_INT prec = TREE_INT_CST_LOW (TYPE_RM_SIZE (etype)); |
0e228dd9 | 4571 | VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 1); |
416de7d5 EB |
4572 | tree field_type, field; |
4573 | ||
4574 | if (TYPE_UNSIGNED (etype)) | |
4575 | field_type = make_unsigned_type (prec); | |
4576 | else | |
4577 | field_type = make_signed_type (prec); | |
4578 | SET_TYPE_RM_SIZE (field_type, TYPE_RM_SIZE (etype)); | |
4579 | ||
4580 | field = create_field_decl (get_identifier ("OBJ"), field_type, rec_type, | |
4581 | NULL_TREE, NULL_TREE, 1, 0); | |
a1ab4c31 AC |
4582 | |
4583 | TYPE_FIELDS (rec_type) = field; | |
4584 | layout_type (rec_type); | |
4585 | ||
416de7d5 | 4586 | expr = fold_build1 (NOP_EXPR, field_type, expr); |
0e228dd9 NF |
4587 | CONSTRUCTOR_APPEND_ELT (v, field, expr); |
4588 | expr = gnat_build_constructor (rec_type, v); | |
a1ab4c31 AC |
4589 | expr = unchecked_convert (type, expr, notrunc_p); |
4590 | } | |
4591 | ||
980a0501 EB |
4592 | /* If we are converting from a scalar type to a type with a different size, |
4593 | we need to pad to have the same size on both sides. | |
4594 | ||
4595 | ??? We cannot do it unconditionally because unchecked conversions are | |
4596 | used liberally by the front-end to implement polymorphism, e.g. in: | |
4597 | ||
4598 | S191s : constant ada__tags__addr_ptr := ada__tags__addr_ptr!(S190s); | |
4599 | return p___size__4 (p__object!(S191s.all)); | |
4600 | ||
4601 | so we skip all expressions that are references. */ | |
4602 | else if (!REFERENCE_CLASS_P (expr) | |
4603 | && !AGGREGATE_TYPE_P (etype) | |
4604 | && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST | |
4605 | && (c = tree_int_cst_compare (TYPE_SIZE (etype), TYPE_SIZE (type)))) | |
4606 | { | |
4607 | if (c < 0) | |
4608 | { | |
4609 | expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty, | |
4610 | false, false, false, true), | |
4611 | expr); | |
4612 | expr = unchecked_convert (type, expr, notrunc_p); | |
4613 | } | |
4614 | else | |
4615 | { | |
4616 | tree rec_type = maybe_pad_type (type, TYPE_SIZE (etype), 0, Empty, | |
4617 | false, false, false, true); | |
4618 | expr = unchecked_convert (rec_type, expr, notrunc_p); | |
4619 | expr = build_component_ref (expr, NULL_TREE, TYPE_FIELDS (rec_type), | |
4620 | false); | |
4621 | } | |
4622 | } | |
4623 | ||
7948ae37 OH |
4624 | /* We have a special case when we are converting between two unconstrained |
4625 | array types. In that case, take the address, convert the fat pointer | |
4626 | types, and dereference. */ | |
c34f3839 | 4627 | else if (ecode == code && code == UNCONSTRAINED_ARRAY_TYPE) |
a1ab4c31 AC |
4628 | expr = build_unary_op (INDIRECT_REF, NULL_TREE, |
4629 | build1 (VIEW_CONVERT_EXPR, TREE_TYPE (type), | |
4630 | build_unary_op (ADDR_EXPR, NULL_TREE, | |
4631 | expr))); | |
7948ae37 OH |
4632 | |
4633 | /* Another special case is when we are converting to a vector type from its | |
4634 | representative array type; this a regular conversion. */ | |
c34f3839 EB |
4635 | else if (code == VECTOR_TYPE |
4636 | && ecode == ARRAY_TYPE | |
7948ae37 OH |
4637 | && gnat_types_compatible_p (TYPE_REPRESENTATIVE_ARRAY (type), |
4638 | etype)) | |
4639 | expr = convert (type, expr); | |
4640 | ||
a1ab4c31 AC |
4641 | else |
4642 | { | |
4643 | expr = maybe_unconstrained_array (expr); | |
4644 | etype = TREE_TYPE (expr); | |
c34f3839 | 4645 | ecode = TREE_CODE (etype); |
afcea859 EB |
4646 | if (can_fold_for_view_convert_p (expr)) |
4647 | expr = fold_build1 (VIEW_CONVERT_EXPR, type, expr); | |
4648 | else | |
4649 | expr = build1 (VIEW_CONVERT_EXPR, type, expr); | |
a1ab4c31 AC |
4650 | } |
4651 | ||
afcea859 EB |
4652 | /* If the result is an integral type whose precision is not equal to its |
4653 | size, sign- or zero-extend the result. We need not do this if the input | |
4654 | is an integral type of the same precision and signedness or if the output | |
a1ab4c31 AC |
4655 | is a biased type or if both the input and output are unsigned. */ |
4656 | if (!notrunc_p | |
4657 | && INTEGRAL_TYPE_P (type) && TYPE_RM_SIZE (type) | |
c34f3839 | 4658 | && !(code == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type)) |
a1ab4c31 AC |
4659 | && 0 != compare_tree_int (TYPE_RM_SIZE (type), |
4660 | GET_MODE_BITSIZE (TYPE_MODE (type))) | |
4661 | && !(INTEGRAL_TYPE_P (etype) | |
4662 | && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (etype) | |
4663 | && operand_equal_p (TYPE_RM_SIZE (type), | |
4664 | (TYPE_RM_SIZE (etype) != 0 | |
4665 | ? TYPE_RM_SIZE (etype) : TYPE_SIZE (etype)), | |
4666 | 0)) | |
4667 | && !(TYPE_UNSIGNED (type) && TYPE_UNSIGNED (etype))) | |
4668 | { | |
c34f3839 EB |
4669 | tree base_type |
4670 | = gnat_type_for_mode (TYPE_MODE (type), TYPE_UNSIGNED (type)); | |
a1ab4c31 AC |
4671 | tree shift_expr |
4672 | = convert (base_type, | |
4673 | size_binop (MINUS_EXPR, | |
4674 | bitsize_int | |
4675 | (GET_MODE_BITSIZE (TYPE_MODE (type))), | |
4676 | TYPE_RM_SIZE (type))); | |
4677 | expr | |
4678 | = convert (type, | |
4679 | build_binary_op (RSHIFT_EXPR, base_type, | |
4680 | build_binary_op (LSHIFT_EXPR, base_type, | |
4681 | convert (base_type, expr), | |
4682 | shift_expr), | |
4683 | shift_expr)); | |
4684 | } | |
4685 | ||
4686 | /* An unchecked conversion should never raise Constraint_Error. The code | |
4687 | below assumes that GCC's conversion routines overflow the same way that | |
4688 | the underlying hardware does. This is probably true. In the rare case | |
4689 | when it is false, we can rely on the fact that such conversions are | |
4690 | erroneous anyway. */ | |
4691 | if (TREE_CODE (expr) == INTEGER_CST) | |
4692 | TREE_OVERFLOW (expr) = 0; | |
4693 | ||
4694 | /* If the sizes of the types differ and this is an VIEW_CONVERT_EXPR, | |
4695 | show no longer constant. */ | |
4696 | if (TREE_CODE (expr) == VIEW_CONVERT_EXPR | |
4697 | && !operand_equal_p (TYPE_SIZE_UNIT (type), TYPE_SIZE_UNIT (etype), | |
4698 | OEP_ONLY_CONST)) | |
4699 | TREE_CONSTANT (expr) = 0; | |
4700 | ||
4701 | return expr; | |
4702 | } | |
4703 | \f | |
feec4372 | 4704 | /* Return the appropriate GCC tree code for the specified GNAT_TYPE, |
a1ab4c31 AC |
4705 | the latter being a record type as predicated by Is_Record_Type. */ |
4706 | ||
4707 | enum tree_code | |
4708 | tree_code_for_record_type (Entity_Id gnat_type) | |
4709 | { | |
b1a785fb | 4710 | Node_Id component_list, component; |
a1ab4c31 | 4711 | |
b1a785fb EB |
4712 | /* Return UNION_TYPE if it's an Unchecked_Union whose non-discriminant |
4713 | fields are all in the variant part. Otherwise, return RECORD_TYPE. */ | |
a1ab4c31 AC |
4714 | if (!Is_Unchecked_Union (gnat_type)) |
4715 | return RECORD_TYPE; | |
4716 | ||
b1a785fb EB |
4717 | gnat_type = Implementation_Base_Type (gnat_type); |
4718 | component_list | |
4719 | = Component_List (Type_Definition (Declaration_Node (gnat_type))); | |
4720 | ||
a1ab4c31 AC |
4721 | for (component = First_Non_Pragma (Component_Items (component_list)); |
4722 | Present (component); | |
4723 | component = Next_Non_Pragma (component)) | |
4724 | if (Ekind (Defining_Entity (component)) == E_Component) | |
4725 | return RECORD_TYPE; | |
4726 | ||
4727 | return UNION_TYPE; | |
4728 | } | |
4729 | ||
caa9d12a EB |
4730 | /* Return true if GNAT_TYPE is a "double" floating-point type, i.e. whose |
4731 | size is equal to 64 bits, or an array of such a type. Set ALIGN_CLAUSE | |
4732 | according to the presence of an alignment clause on the type or, if it | |
4733 | is an array, on the component type. */ | |
4734 | ||
4735 | bool | |
4736 | is_double_float_or_array (Entity_Id gnat_type, bool *align_clause) | |
4737 | { | |
4738 | gnat_type = Underlying_Type (gnat_type); | |
4739 | ||
4740 | *align_clause = Present (Alignment_Clause (gnat_type)); | |
4741 | ||
4742 | if (Is_Array_Type (gnat_type)) | |
4743 | { | |
4744 | gnat_type = Underlying_Type (Component_Type (gnat_type)); | |
4745 | if (Present (Alignment_Clause (gnat_type))) | |
4746 | *align_clause = true; | |
4747 | } | |
4748 | ||
4749 | if (!Is_Floating_Point_Type (gnat_type)) | |
4750 | return false; | |
4751 | ||
4752 | if (UI_To_Int (Esize (gnat_type)) != 64) | |
4753 | return false; | |
4754 | ||
4755 | return true; | |
4756 | } | |
4757 | ||
4758 | /* Return true if GNAT_TYPE is a "double" or larger scalar type, i.e. whose | |
4759 | size is greater or equal to 64 bits, or an array of such a type. Set | |
4760 | ALIGN_CLAUSE according to the presence of an alignment clause on the | |
4761 | type or, if it is an array, on the component type. */ | |
4762 | ||
4763 | bool | |
4764 | is_double_scalar_or_array (Entity_Id gnat_type, bool *align_clause) | |
4765 | { | |
4766 | gnat_type = Underlying_Type (gnat_type); | |
4767 | ||
4768 | *align_clause = Present (Alignment_Clause (gnat_type)); | |
4769 | ||
4770 | if (Is_Array_Type (gnat_type)) | |
4771 | { | |
4772 | gnat_type = Underlying_Type (Component_Type (gnat_type)); | |
4773 | if (Present (Alignment_Clause (gnat_type))) | |
4774 | *align_clause = true; | |
4775 | } | |
4776 | ||
4777 | if (!Is_Scalar_Type (gnat_type)) | |
4778 | return false; | |
4779 | ||
4780 | if (UI_To_Int (Esize (gnat_type)) < 64) | |
4781 | return false; | |
4782 | ||
4783 | return true; | |
4784 | } | |
4785 | ||
a1ab4c31 AC |
4786 | /* Return true if GNU_TYPE is suitable as the type of a non-aliased |
4787 | component of an aggregate type. */ | |
4788 | ||
4789 | bool | |
4790 | type_for_nonaliased_component_p (tree gnu_type) | |
4791 | { | |
4792 | /* If the type is passed by reference, we may have pointers to the | |
4793 | component so it cannot be made non-aliased. */ | |
4794 | if (must_pass_by_ref (gnu_type) || default_pass_by_ref (gnu_type)) | |
4795 | return false; | |
4796 | ||
4797 | /* We used to say that any component of aggregate type is aliased | |
4798 | because the front-end may take 'Reference of it. The front-end | |
4799 | has been enhanced in the meantime so as to use a renaming instead | |
4800 | in most cases, but the back-end can probably take the address of | |
4801 | such a component too so we go for the conservative stance. | |
4802 | ||
4803 | For instance, we might need the address of any array type, even | |
4804 | if normally passed by copy, to construct a fat pointer if the | |
4805 | component is used as an actual for an unconstrained formal. | |
4806 | ||
4807 | Likewise for record types: even if a specific record subtype is | |
4808 | passed by copy, the parent type might be passed by ref (e.g. if | |
4809 | it's of variable size) and we might take the address of a child | |
4810 | component to pass to a parent formal. We have no way to check | |
4811 | for such conditions here. */ | |
4812 | if (AGGREGATE_TYPE_P (gnu_type)) | |
4813 | return false; | |
4814 | ||
4815 | return true; | |
4816 | } | |
4817 | ||
bb1f7929 EB |
4818 | /* Return true if TYPE is a smaller form of ORIG_TYPE. */ |
4819 | ||
4820 | bool | |
4821 | smaller_form_type_p (tree type, tree orig_type) | |
4822 | { | |
4823 | tree size, osize; | |
4824 | ||
4825 | /* We're not interested in variants here. */ | |
4826 | if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig_type)) | |
4827 | return false; | |
4828 | ||
4829 | /* Like a variant, a packable version keeps the original TYPE_NAME. */ | |
4830 | if (TYPE_NAME (type) != TYPE_NAME (orig_type)) | |
4831 | return false; | |
4832 | ||
4833 | size = TYPE_SIZE (type); | |
4834 | osize = TYPE_SIZE (orig_type); | |
4835 | ||
4836 | if (!(TREE_CODE (size) == INTEGER_CST && TREE_CODE (osize) == INTEGER_CST)) | |
4837 | return false; | |
4838 | ||
4839 | return tree_int_cst_lt (size, osize) != 0; | |
4840 | } | |
4841 | ||
a1ab4c31 AC |
4842 | /* Perform final processing on global variables. */ |
4843 | ||
65444786 EB |
4844 | static GTY (()) tree dummy_global; |
4845 | ||
a1ab4c31 AC |
4846 | void |
4847 | gnat_write_global_declarations (void) | |
4848 | { | |
10e4d056 EB |
4849 | unsigned int i; |
4850 | tree iter; | |
4851 | ||
65444786 EB |
4852 | /* If we have declared types as used at the global level, insert them in |
4853 | the global hash table. We use a dummy variable for this purpose. */ | |
4854 | if (!VEC_empty (tree, types_used_by_cur_var_decl)) | |
4855 | { | |
35e8bcf4 | 4856 | struct varpool_node *node; |
65444786 EB |
4857 | dummy_global |
4858 | = build_decl (BUILTINS_LOCATION, VAR_DECL, NULL_TREE, void_type_node); | |
4859 | TREE_STATIC (dummy_global) = 1; | |
4860 | TREE_ASM_WRITTEN (dummy_global) = 1; | |
35e8bcf4 | 4861 | node = varpool_node (dummy_global); |
ead84f73 | 4862 | node->symbol.force_output = 1; |
65444786 EB |
4863 | |
4864 | while (!VEC_empty (tree, types_used_by_cur_var_decl)) | |
4865 | { | |
4866 | tree t = VEC_pop (tree, types_used_by_cur_var_decl); | |
4867 | types_used_by_var_decl_insert (t, dummy_global); | |
4868 | } | |
4869 | } | |
4870 | ||
10e4d056 EB |
4871 | /* Output debug information for all global type declarations first. This |
4872 | ensures that global types whose compilation hasn't been finalized yet, | |
4873 | for example pointers to Taft amendment types, have their compilation | |
4874 | finalized in the right context. */ | |
4875 | FOR_EACH_VEC_ELT (tree, global_decls, i, iter) | |
4876 | if (TREE_CODE (iter) == TYPE_DECL) | |
4877 | debug_hooks->global_decl (iter); | |
4878 | ||
a1ab4c31 AC |
4879 | /* Proceed to optimize and emit assembly. |
4880 | FIXME: shouldn't be the front end's responsibility to call this. */ | |
a406865a | 4881 | cgraph_finalize_compilation_unit (); |
a1ab4c31 | 4882 | |
10e4d056 EB |
4883 | /* After cgraph has had a chance to emit everything that's going to |
4884 | be emitted, output debug information for the rest of globals. */ | |
4885 | if (!seen_error ()) | |
4886 | { | |
4887 | timevar_push (TV_SYMOUT); | |
4888 | FOR_EACH_VEC_ELT (tree, global_decls, i, iter) | |
4889 | if (TREE_CODE (iter) != TYPE_DECL) | |
4890 | debug_hooks->global_decl (iter); | |
4891 | timevar_pop (TV_SYMOUT); | |
4892 | } | |
a1ab4c31 AC |
4893 | } |
4894 | ||
4895 | /* ************************************************************************ | |
4896 | * * GCC builtins support * | |
4897 | * ************************************************************************ */ | |
4898 | ||
4899 | /* The general scheme is fairly simple: | |
4900 | ||
4901 | For each builtin function/type to be declared, gnat_install_builtins calls | |
4902 | internal facilities which eventually get to gnat_push_decl, which in turn | |
4903 | tracks the so declared builtin function decls in the 'builtin_decls' global | |
4904 | datastructure. When an Intrinsic subprogram declaration is processed, we | |
4905 | search this global datastructure to retrieve the associated BUILT_IN DECL | |
4906 | node. */ | |
4907 | ||
4908 | /* Search the chain of currently available builtin declarations for a node | |
4909 | corresponding to function NAME (an IDENTIFIER_NODE). Return the first node | |
4910 | found, if any, or NULL_TREE otherwise. */ | |
4911 | tree | |
4912 | builtin_decl_for (tree name) | |
4913 | { | |
4914 | unsigned i; | |
4915 | tree decl; | |
4916 | ||
ac47786e | 4917 | FOR_EACH_VEC_ELT (tree, builtin_decls, i, decl) |
a1ab4c31 AC |
4918 | if (DECL_NAME (decl) == name) |
4919 | return decl; | |
4920 | ||
4921 | return NULL_TREE; | |
4922 | } | |
4923 | ||
4924 | /* The code below eventually exposes gnat_install_builtins, which declares | |
4925 | the builtin types and functions we might need, either internally or as | |
4926 | user accessible facilities. | |
4927 | ||
4928 | ??? This is a first implementation shot, still in rough shape. It is | |
4929 | heavily inspired from the "C" family implementation, with chunks copied | |
4930 | verbatim from there. | |
4931 | ||
4932 | Two obvious TODO candidates are | |
4933 | o Use a more efficient name/decl mapping scheme | |
4934 | o Devise a middle-end infrastructure to avoid having to copy | |
4935 | pieces between front-ends. */ | |
4936 | ||
4937 | /* ----------------------------------------------------------------------- * | |
4938 | * BUILTIN ELEMENTARY TYPES * | |
4939 | * ----------------------------------------------------------------------- */ | |
4940 | ||
4941 | /* Standard data types to be used in builtin argument declarations. */ | |
4942 | ||
4943 | enum c_tree_index | |
4944 | { | |
4945 | CTI_SIGNED_SIZE_TYPE, /* For format checking only. */ | |
4946 | CTI_STRING_TYPE, | |
4947 | CTI_CONST_STRING_TYPE, | |
4948 | ||
4949 | CTI_MAX | |
4950 | }; | |
4951 | ||
4952 | static tree c_global_trees[CTI_MAX]; | |
4953 | ||
4954 | #define signed_size_type_node c_global_trees[CTI_SIGNED_SIZE_TYPE] | |
4955 | #define string_type_node c_global_trees[CTI_STRING_TYPE] | |
4956 | #define const_string_type_node c_global_trees[CTI_CONST_STRING_TYPE] | |
4957 | ||
4958 | /* ??? In addition some attribute handlers, we currently don't support a | |
4959 | (small) number of builtin-types, which in turns inhibits support for a | |
4960 | number of builtin functions. */ | |
4961 | #define wint_type_node void_type_node | |
4962 | #define intmax_type_node void_type_node | |
4963 | #define uintmax_type_node void_type_node | |
4964 | ||
4965 | /* Build the void_list_node (void_type_node having been created). */ | |
4966 | ||
4967 | static tree | |
4968 | build_void_list_node (void) | |
4969 | { | |
4970 | tree t = build_tree_list (NULL_TREE, void_type_node); | |
4971 | return t; | |
4972 | } | |
4973 | ||
4974 | /* Used to help initialize the builtin-types.def table. When a type of | |
4975 | the correct size doesn't exist, use error_mark_node instead of NULL. | |
4976 | The later results in segfaults even when a decl using the type doesn't | |
4977 | get invoked. */ | |
4978 | ||
4979 | static tree | |
4980 | builtin_type_for_size (int size, bool unsignedp) | |
4981 | { | |
ced57283 | 4982 | tree type = gnat_type_for_size (size, unsignedp); |
a1ab4c31 AC |
4983 | return type ? type : error_mark_node; |
4984 | } | |
4985 | ||
4986 | /* Build/push the elementary type decls that builtin functions/types | |
4987 | will need. */ | |
4988 | ||
4989 | static void | |
4990 | install_builtin_elementary_types (void) | |
4991 | { | |
728936bb | 4992 | signed_size_type_node = gnat_signed_type (size_type_node); |
a1ab4c31 AC |
4993 | pid_type_node = integer_type_node; |
4994 | void_list_node = build_void_list_node (); | |
4995 | ||
4996 | string_type_node = build_pointer_type (char_type_node); | |
4997 | const_string_type_node | |
4998 | = build_pointer_type (build_qualified_type | |
4999 | (char_type_node, TYPE_QUAL_CONST)); | |
5000 | } | |
5001 | ||
5002 | /* ----------------------------------------------------------------------- * | |
5003 | * BUILTIN FUNCTION TYPES * | |
5004 | * ----------------------------------------------------------------------- */ | |
5005 | ||
5006 | /* Now, builtin function types per se. */ | |
5007 | ||
5008 | enum c_builtin_type | |
5009 | { | |
5010 | #define DEF_PRIMITIVE_TYPE(NAME, VALUE) NAME, | |
5011 | #define DEF_FUNCTION_TYPE_0(NAME, RETURN) NAME, | |
5012 | #define DEF_FUNCTION_TYPE_1(NAME, RETURN, ARG1) NAME, | |
5013 | #define DEF_FUNCTION_TYPE_2(NAME, RETURN, ARG1, ARG2) NAME, | |
5014 | #define DEF_FUNCTION_TYPE_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME, | |
5015 | #define DEF_FUNCTION_TYPE_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME, | |
5016 | #define DEF_FUNCTION_TYPE_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) NAME, | |
5017 | #define DEF_FUNCTION_TYPE_6(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) NAME, | |
5018 | #define DEF_FUNCTION_TYPE_7(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) NAME, | |
5019 | #define DEF_FUNCTION_TYPE_VAR_0(NAME, RETURN) NAME, | |
5020 | #define DEF_FUNCTION_TYPE_VAR_1(NAME, RETURN, ARG1) NAME, | |
5021 | #define DEF_FUNCTION_TYPE_VAR_2(NAME, RETURN, ARG1, ARG2) NAME, | |
5022 | #define DEF_FUNCTION_TYPE_VAR_3(NAME, RETURN, ARG1, ARG2, ARG3) NAME, | |
5023 | #define DEF_FUNCTION_TYPE_VAR_4(NAME, RETURN, ARG1, ARG2, ARG3, ARG4) NAME, | |
5024 | #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \ | |
5025 | NAME, | |
5026 | #define DEF_POINTER_TYPE(NAME, TYPE) NAME, | |
5027 | #include "builtin-types.def" | |
5028 | #undef DEF_PRIMITIVE_TYPE | |
5029 | #undef DEF_FUNCTION_TYPE_0 | |
5030 | #undef DEF_FUNCTION_TYPE_1 | |
5031 | #undef DEF_FUNCTION_TYPE_2 | |
5032 | #undef DEF_FUNCTION_TYPE_3 | |
5033 | #undef DEF_FUNCTION_TYPE_4 | |
5034 | #undef DEF_FUNCTION_TYPE_5 | |
5035 | #undef DEF_FUNCTION_TYPE_6 | |
5036 | #undef DEF_FUNCTION_TYPE_7 | |
5037 | #undef DEF_FUNCTION_TYPE_VAR_0 | |
5038 | #undef DEF_FUNCTION_TYPE_VAR_1 | |
5039 | #undef DEF_FUNCTION_TYPE_VAR_2 | |
5040 | #undef DEF_FUNCTION_TYPE_VAR_3 | |
5041 | #undef DEF_FUNCTION_TYPE_VAR_4 | |
5042 | #undef DEF_FUNCTION_TYPE_VAR_5 | |
5043 | #undef DEF_POINTER_TYPE | |
5044 | BT_LAST | |
5045 | }; | |
5046 | ||
5047 | typedef enum c_builtin_type builtin_type; | |
5048 | ||
5049 | /* A temporary array used in communication with def_fn_type. */ | |
5050 | static GTY(()) tree builtin_types[(int) BT_LAST + 1]; | |
5051 | ||
5052 | /* A helper function for install_builtin_types. Build function type | |
5053 | for DEF with return type RET and N arguments. If VAR is true, then the | |
5054 | function should be variadic after those N arguments. | |
5055 | ||
5056 | Takes special care not to ICE if any of the types involved are | |
5057 | error_mark_node, which indicates that said type is not in fact available | |
5058 | (see builtin_type_for_size). In which case the function type as a whole | |
5059 | should be error_mark_node. */ | |
5060 | ||
5061 | static void | |
5062 | def_fn_type (builtin_type def, builtin_type ret, bool var, int n, ...) | |
5063 | { | |
e5b00edf NF |
5064 | tree t; |
5065 | tree *args = XALLOCAVEC (tree, n); | |
a1ab4c31 AC |
5066 | va_list list; |
5067 | int i; | |
5068 | ||
5069 | va_start (list, n); | |
5070 | for (i = 0; i < n; ++i) | |
5071 | { | |
c6bd4220 | 5072 | builtin_type a = (builtin_type) va_arg (list, int); |
a1ab4c31 AC |
5073 | t = builtin_types[a]; |
5074 | if (t == error_mark_node) | |
5075 | goto egress; | |
e5b00edf | 5076 | args[i] = t; |
a1ab4c31 | 5077 | } |
a1ab4c31 | 5078 | |
a1ab4c31 AC |
5079 | t = builtin_types[ret]; |
5080 | if (t == error_mark_node) | |
5081 | goto egress; | |
e5b00edf NF |
5082 | if (var) |
5083 | t = build_varargs_function_type_array (t, n, args); | |
5084 | else | |
5085 | t = build_function_type_array (t, n, args); | |
a1ab4c31 AC |
5086 | |
5087 | egress: | |
5088 | builtin_types[def] = t; | |
0edf1bb2 | 5089 | va_end (list); |
a1ab4c31 AC |
5090 | } |
5091 | ||
5092 | /* Build the builtin function types and install them in the builtin_types | |
5093 | array for later use in builtin function decls. */ | |
5094 | ||
5095 | static void | |
5096 | install_builtin_function_types (void) | |
5097 | { | |
5098 | tree va_list_ref_type_node; | |
5099 | tree va_list_arg_type_node; | |
5100 | ||
5101 | if (TREE_CODE (va_list_type_node) == ARRAY_TYPE) | |
5102 | { | |
5103 | va_list_arg_type_node = va_list_ref_type_node = | |
5104 | build_pointer_type (TREE_TYPE (va_list_type_node)); | |
5105 | } | |
5106 | else | |
5107 | { | |
5108 | va_list_arg_type_node = va_list_type_node; | |
5109 | va_list_ref_type_node = build_reference_type (va_list_type_node); | |
5110 | } | |
5111 | ||
5112 | #define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \ | |
5113 | builtin_types[ENUM] = VALUE; | |
5114 | #define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \ | |
5115 | def_fn_type (ENUM, RETURN, 0, 0); | |
5116 | #define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \ | |
5117 | def_fn_type (ENUM, RETURN, 0, 1, ARG1); | |
5118 | #define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \ | |
5119 | def_fn_type (ENUM, RETURN, 0, 2, ARG1, ARG2); | |
5120 | #define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \ | |
5121 | def_fn_type (ENUM, RETURN, 0, 3, ARG1, ARG2, ARG3); | |
5122 | #define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \ | |
5123 | def_fn_type (ENUM, RETURN, 0, 4, ARG1, ARG2, ARG3, ARG4); | |
5124 | #define DEF_FUNCTION_TYPE_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ | |
5125 | def_fn_type (ENUM, RETURN, 0, 5, ARG1, ARG2, ARG3, ARG4, ARG5); | |
5126 | #define DEF_FUNCTION_TYPE_6(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ | |
5127 | ARG6) \ | |
5128 | def_fn_type (ENUM, RETURN, 0, 6, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6); | |
5129 | #define DEF_FUNCTION_TYPE_7(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5, \ | |
5130 | ARG6, ARG7) \ | |
5131 | def_fn_type (ENUM, RETURN, 0, 7, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7); | |
5132 | #define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \ | |
5133 | def_fn_type (ENUM, RETURN, 1, 0); | |
5134 | #define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \ | |
5135 | def_fn_type (ENUM, RETURN, 1, 1, ARG1); | |
5136 | #define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \ | |
5137 | def_fn_type (ENUM, RETURN, 1, 2, ARG1, ARG2); | |
5138 | #define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \ | |
5139 | def_fn_type (ENUM, RETURN, 1, 3, ARG1, ARG2, ARG3); | |
5140 | #define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \ | |
5141 | def_fn_type (ENUM, RETURN, 1, 4, ARG1, ARG2, ARG3, ARG4); | |
5142 | #define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4, ARG5) \ | |
5143 | def_fn_type (ENUM, RETURN, 1, 5, ARG1, ARG2, ARG3, ARG4, ARG5); | |
5144 | #define DEF_POINTER_TYPE(ENUM, TYPE) \ | |
5145 | builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]); | |
5146 | ||
5147 | #include "builtin-types.def" | |
5148 | ||
5149 | #undef DEF_PRIMITIVE_TYPE | |
5150 | #undef DEF_FUNCTION_TYPE_1 | |
5151 | #undef DEF_FUNCTION_TYPE_2 | |
5152 | #undef DEF_FUNCTION_TYPE_3 | |
5153 | #undef DEF_FUNCTION_TYPE_4 | |
5154 | #undef DEF_FUNCTION_TYPE_5 | |
5155 | #undef DEF_FUNCTION_TYPE_6 | |
5156 | #undef DEF_FUNCTION_TYPE_VAR_0 | |
5157 | #undef DEF_FUNCTION_TYPE_VAR_1 | |
5158 | #undef DEF_FUNCTION_TYPE_VAR_2 | |
5159 | #undef DEF_FUNCTION_TYPE_VAR_3 | |
5160 | #undef DEF_FUNCTION_TYPE_VAR_4 | |
5161 | #undef DEF_FUNCTION_TYPE_VAR_5 | |
5162 | #undef DEF_POINTER_TYPE | |
5163 | builtin_types[(int) BT_LAST] = NULL_TREE; | |
5164 | } | |
5165 | ||
5166 | /* ----------------------------------------------------------------------- * | |
5167 | * BUILTIN ATTRIBUTES * | |
5168 | * ----------------------------------------------------------------------- */ | |
5169 | ||
5170 | enum built_in_attribute | |
5171 | { | |
5172 | #define DEF_ATTR_NULL_TREE(ENUM) ENUM, | |
5173 | #define DEF_ATTR_INT(ENUM, VALUE) ENUM, | |
5174 | #define DEF_ATTR_IDENT(ENUM, STRING) ENUM, | |
5175 | #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM, | |
5176 | #include "builtin-attrs.def" | |
5177 | #undef DEF_ATTR_NULL_TREE | |
5178 | #undef DEF_ATTR_INT | |
5179 | #undef DEF_ATTR_IDENT | |
5180 | #undef DEF_ATTR_TREE_LIST | |
5181 | ATTR_LAST | |
5182 | }; | |
5183 | ||
5184 | static GTY(()) tree built_in_attributes[(int) ATTR_LAST]; | |
5185 | ||
5186 | static void | |
5187 | install_builtin_attributes (void) | |
5188 | { | |
5189 | /* Fill in the built_in_attributes array. */ | |
5190 | #define DEF_ATTR_NULL_TREE(ENUM) \ | |
5191 | built_in_attributes[(int) ENUM] = NULL_TREE; | |
5192 | #define DEF_ATTR_INT(ENUM, VALUE) \ | |
5193 | built_in_attributes[(int) ENUM] = build_int_cst (NULL_TREE, VALUE); | |
5194 | #define DEF_ATTR_IDENT(ENUM, STRING) \ | |
5195 | built_in_attributes[(int) ENUM] = get_identifier (STRING); | |
5196 | #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \ | |
5197 | built_in_attributes[(int) ENUM] \ | |
5198 | = tree_cons (built_in_attributes[(int) PURPOSE], \ | |
5199 | built_in_attributes[(int) VALUE], \ | |
5200 | built_in_attributes[(int) CHAIN]); | |
5201 | #include "builtin-attrs.def" | |
5202 | #undef DEF_ATTR_NULL_TREE | |
5203 | #undef DEF_ATTR_INT | |
5204 | #undef DEF_ATTR_IDENT | |
5205 | #undef DEF_ATTR_TREE_LIST | |
5206 | } | |
5207 | ||
5208 | /* Handle a "const" attribute; arguments as in | |
5209 | struct attribute_spec.handler. */ | |
5210 | ||
5211 | static tree | |
5212 | handle_const_attribute (tree *node, tree ARG_UNUSED (name), | |
5213 | tree ARG_UNUSED (args), int ARG_UNUSED (flags), | |
5214 | bool *no_add_attrs) | |
5215 | { | |
5216 | if (TREE_CODE (*node) == FUNCTION_DECL) | |
5217 | TREE_READONLY (*node) = 1; | |
5218 | else | |
5219 | *no_add_attrs = true; | |
5220 | ||
5221 | return NULL_TREE; | |
5222 | } | |
5223 | ||
5224 | /* Handle a "nothrow" attribute; arguments as in | |
5225 | struct attribute_spec.handler. */ | |
5226 | ||
5227 | static tree | |
5228 | handle_nothrow_attribute (tree *node, tree ARG_UNUSED (name), | |
5229 | tree ARG_UNUSED (args), int ARG_UNUSED (flags), | |
5230 | bool *no_add_attrs) | |
5231 | { | |
5232 | if (TREE_CODE (*node) == FUNCTION_DECL) | |
5233 | TREE_NOTHROW (*node) = 1; | |
5234 | else | |
5235 | *no_add_attrs = true; | |
5236 | ||
5237 | return NULL_TREE; | |
5238 | } | |
5239 | ||
5240 | /* Handle a "pure" attribute; arguments as in | |
5241 | struct attribute_spec.handler. */ | |
5242 | ||
5243 | static tree | |
5244 | handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED (args), | |
5245 | int ARG_UNUSED (flags), bool *no_add_attrs) | |
5246 | { | |
5247 | if (TREE_CODE (*node) == FUNCTION_DECL) | |
5248 | DECL_PURE_P (*node) = 1; | |
5249 | /* ??? TODO: Support types. */ | |
5250 | else | |
5251 | { | |
7948ae37 OH |
5252 | warning (OPT_Wattributes, "%qs attribute ignored", |
5253 | IDENTIFIER_POINTER (name)); | |
a1ab4c31 AC |
5254 | *no_add_attrs = true; |
5255 | } | |
5256 | ||
5257 | return NULL_TREE; | |
5258 | } | |
5259 | ||
5260 | /* Handle a "no vops" attribute; arguments as in | |
5261 | struct attribute_spec.handler. */ | |
5262 | ||
5263 | static tree | |
5264 | handle_novops_attribute (tree *node, tree ARG_UNUSED (name), | |
5265 | tree ARG_UNUSED (args), int ARG_UNUSED (flags), | |
5266 | bool *ARG_UNUSED (no_add_attrs)) | |
5267 | { | |
5268 | gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); | |
5269 | DECL_IS_NOVOPS (*node) = 1; | |
5270 | return NULL_TREE; | |
5271 | } | |
5272 | ||
5273 | /* Helper for nonnull attribute handling; fetch the operand number | |
5274 | from the attribute argument list. */ | |
5275 | ||
5276 | static bool | |
5277 | get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp) | |
5278 | { | |
5279 | /* Verify the arg number is a constant. */ | |
5280 | if (TREE_CODE (arg_num_expr) != INTEGER_CST | |
5281 | || TREE_INT_CST_HIGH (arg_num_expr) != 0) | |
5282 | return false; | |
5283 | ||
5284 | *valp = TREE_INT_CST_LOW (arg_num_expr); | |
5285 | return true; | |
5286 | } | |
5287 | ||
5288 | /* Handle the "nonnull" attribute. */ | |
5289 | static tree | |
5290 | handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), | |
5291 | tree args, int ARG_UNUSED (flags), | |
5292 | bool *no_add_attrs) | |
5293 | { | |
5294 | tree type = *node; | |
5295 | unsigned HOST_WIDE_INT attr_arg_num; | |
5296 | ||
5297 | /* If no arguments are specified, all pointer arguments should be | |
5298 | non-null. Verify a full prototype is given so that the arguments | |
5299 | will have the correct types when we actually check them later. */ | |
5300 | if (!args) | |
5301 | { | |
f4da8dce | 5302 | if (!prototype_p (type)) |
a1ab4c31 AC |
5303 | { |
5304 | error ("nonnull attribute without arguments on a non-prototype"); | |
5305 | *no_add_attrs = true; | |
5306 | } | |
5307 | return NULL_TREE; | |
5308 | } | |
5309 | ||
5310 | /* Argument list specified. Verify that each argument number references | |
5311 | a pointer argument. */ | |
5312 | for (attr_arg_num = 1; args; args = TREE_CHAIN (args)) | |
5313 | { | |
a1ab4c31 AC |
5314 | unsigned HOST_WIDE_INT arg_num = 0, ck_num; |
5315 | ||
5316 | if (!get_nonnull_operand (TREE_VALUE (args), &arg_num)) | |
5317 | { | |
5318 | error ("nonnull argument has invalid operand number (argument %lu)", | |
5319 | (unsigned long) attr_arg_num); | |
5320 | *no_add_attrs = true; | |
5321 | return NULL_TREE; | |
5322 | } | |
5323 | ||
d7d058c5 | 5324 | if (prototype_p (type)) |
a1ab4c31 | 5325 | { |
d7d058c5 NF |
5326 | function_args_iterator iter; |
5327 | tree argument; | |
5328 | ||
5329 | function_args_iter_init (&iter, type); | |
5330 | for (ck_num = 1; ; ck_num++, function_args_iter_next (&iter)) | |
a1ab4c31 | 5331 | { |
d7d058c5 | 5332 | argument = function_args_iter_cond (&iter); |
a1ab4c31 AC |
5333 | if (!argument || ck_num == arg_num) |
5334 | break; | |
a1ab4c31 AC |
5335 | } |
5336 | ||
5337 | if (!argument | |
d7d058c5 | 5338 | || TREE_CODE (argument) == VOID_TYPE) |
a1ab4c31 | 5339 | { |
58c8f770 EB |
5340 | error ("nonnull argument with out-of-range operand number " |
5341 | "(argument %lu, operand %lu)", | |
a1ab4c31 AC |
5342 | (unsigned long) attr_arg_num, (unsigned long) arg_num); |
5343 | *no_add_attrs = true; | |
5344 | return NULL_TREE; | |
5345 | } | |
5346 | ||
d7d058c5 | 5347 | if (TREE_CODE (argument) != POINTER_TYPE) |
a1ab4c31 | 5348 | { |
58c8f770 EB |
5349 | error ("nonnull argument references non-pointer operand " |
5350 | "(argument %lu, operand %lu)", | |
a1ab4c31 AC |
5351 | (unsigned long) attr_arg_num, (unsigned long) arg_num); |
5352 | *no_add_attrs = true; | |
5353 | return NULL_TREE; | |
5354 | } | |
5355 | } | |
5356 | } | |
5357 | ||
5358 | return NULL_TREE; | |
5359 | } | |
5360 | ||
5361 | /* Handle a "sentinel" attribute. */ | |
5362 | ||
5363 | static tree | |
5364 | handle_sentinel_attribute (tree *node, tree name, tree args, | |
5365 | int ARG_UNUSED (flags), bool *no_add_attrs) | |
5366 | { | |
f4da8dce | 5367 | if (!prototype_p (*node)) |
a1ab4c31 AC |
5368 | { |
5369 | warning (OPT_Wattributes, | |
7948ae37 OH |
5370 | "%qs attribute requires prototypes with named arguments", |
5371 | IDENTIFIER_POINTER (name)); | |
a1ab4c31 AC |
5372 | *no_add_attrs = true; |
5373 | } | |
5374 | else | |
5375 | { | |
dcf0c47e | 5376 | if (!stdarg_p (*node)) |
a1ab4c31 AC |
5377 | { |
5378 | warning (OPT_Wattributes, | |
7948ae37 OH |
5379 | "%qs attribute only applies to variadic functions", |
5380 | IDENTIFIER_POINTER (name)); | |
a1ab4c31 AC |
5381 | *no_add_attrs = true; |
5382 | } | |
5383 | } | |
5384 | ||
5385 | if (args) | |
5386 | { | |
5387 | tree position = TREE_VALUE (args); | |
5388 | ||
5389 | if (TREE_CODE (position) != INTEGER_CST) | |
5390 | { | |
5391 | warning (0, "requested position is not an integer constant"); | |
5392 | *no_add_attrs = true; | |
5393 | } | |
5394 | else | |
5395 | { | |
5396 | if (tree_int_cst_lt (position, integer_zero_node)) | |
5397 | { | |
5398 | warning (0, "requested position is less than zero"); | |
5399 | *no_add_attrs = true; | |
5400 | } | |
5401 | } | |
5402 | } | |
5403 | ||
5404 | return NULL_TREE; | |
5405 | } | |
5406 | ||
5407 | /* Handle a "noreturn" attribute; arguments as in | |
5408 | struct attribute_spec.handler. */ | |
5409 | ||
5410 | static tree | |
5411 | handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args), | |
5412 | int ARG_UNUSED (flags), bool *no_add_attrs) | |
5413 | { | |
5414 | tree type = TREE_TYPE (*node); | |
5415 | ||
5416 | /* See FIXME comment in c_common_attribute_table. */ | |
5417 | if (TREE_CODE (*node) == FUNCTION_DECL) | |
5418 | TREE_THIS_VOLATILE (*node) = 1; | |
5419 | else if (TREE_CODE (type) == POINTER_TYPE | |
5420 | && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) | |
5421 | TREE_TYPE (*node) | |
5422 | = build_pointer_type | |
5423 | (build_type_variant (TREE_TYPE (type), | |
5424 | TYPE_READONLY (TREE_TYPE (type)), 1)); | |
5425 | else | |
5426 | { | |
7948ae37 OH |
5427 | warning (OPT_Wattributes, "%qs attribute ignored", |
5428 | IDENTIFIER_POINTER (name)); | |
a1ab4c31 AC |
5429 | *no_add_attrs = true; |
5430 | } | |
5431 | ||
5432 | return NULL_TREE; | |
5433 | } | |
5434 | ||
0d6e14fd JH |
5435 | /* Handle a "leaf" attribute; arguments as in |
5436 | struct attribute_spec.handler. */ | |
5437 | ||
5438 | static tree | |
5439 | handle_leaf_attribute (tree *node, tree name, | |
5440 | tree ARG_UNUSED (args), | |
5441 | int ARG_UNUSED (flags), bool *no_add_attrs) | |
5442 | { | |
5443 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
5444 | { | |
5445 | warning (OPT_Wattributes, "%qE attribute ignored", name); | |
5446 | *no_add_attrs = true; | |
5447 | } | |
5448 | if (!TREE_PUBLIC (*node)) | |
5449 | { | |
32a5388a | 5450 | warning (OPT_Wattributes, "%qE attribute has no effect", name); |
0d6e14fd JH |
5451 | *no_add_attrs = true; |
5452 | } | |
5453 | ||
5454 | return NULL_TREE; | |
5455 | } | |
5456 | ||
a1ab4c31 AC |
5457 | /* Handle a "malloc" attribute; arguments as in |
5458 | struct attribute_spec.handler. */ | |
5459 | ||
5460 | static tree | |
5461 | handle_malloc_attribute (tree *node, tree name, tree ARG_UNUSED (args), | |
5462 | int ARG_UNUSED (flags), bool *no_add_attrs) | |
5463 | { | |
5464 | if (TREE_CODE (*node) == FUNCTION_DECL | |
5465 | && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))) | |
5466 | DECL_IS_MALLOC (*node) = 1; | |
5467 | else | |
5468 | { | |
7948ae37 OH |
5469 | warning (OPT_Wattributes, "%qs attribute ignored", |
5470 | IDENTIFIER_POINTER (name)); | |
a1ab4c31 AC |
5471 | *no_add_attrs = true; |
5472 | } | |
5473 | ||
5474 | return NULL_TREE; | |
5475 | } | |
5476 | ||
5477 | /* Fake handler for attributes we don't properly support. */ | |
5478 | ||
5479 | tree | |
5480 | fake_attribute_handler (tree * ARG_UNUSED (node), | |
5481 | tree ARG_UNUSED (name), | |
5482 | tree ARG_UNUSED (args), | |
5483 | int ARG_UNUSED (flags), | |
5484 | bool * ARG_UNUSED (no_add_attrs)) | |
5485 | { | |
5486 | return NULL_TREE; | |
5487 | } | |
5488 | ||
5489 | /* Handle a "type_generic" attribute. */ | |
5490 | ||
5491 | static tree | |
5492 | handle_type_generic_attribute (tree *node, tree ARG_UNUSED (name), | |
5493 | tree ARG_UNUSED (args), int ARG_UNUSED (flags), | |
5494 | bool * ARG_UNUSED (no_add_attrs)) | |
5495 | { | |
a1ab4c31 AC |
5496 | /* Ensure we have a function type. */ |
5497 | gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE); | |
b4680ca1 | 5498 | |
a1ab4c31 | 5499 | /* Ensure we have a variadic function. */ |
dcf0c47e | 5500 | gcc_assert (!prototype_p (*node) || stdarg_p (*node)); |
a1ab4c31 AC |
5501 | |
5502 | return NULL_TREE; | |
5503 | } | |
5504 | ||
2724e58f OH |
5505 | /* Handle a "vector_size" attribute; arguments as in |
5506 | struct attribute_spec.handler. */ | |
5507 | ||
5508 | static tree | |
5509 | handle_vector_size_attribute (tree *node, tree name, tree args, | |
5510 | int ARG_UNUSED (flags), | |
5511 | bool *no_add_attrs) | |
5512 | { | |
5513 | unsigned HOST_WIDE_INT vecsize, nunits; | |
5514 | enum machine_mode orig_mode; | |
5515 | tree type = *node, new_type, size; | |
5516 | ||
5517 | *no_add_attrs = true; | |
5518 | ||
5519 | size = TREE_VALUE (args); | |
5520 | ||
5521 | if (!host_integerp (size, 1)) | |
5522 | { | |
7948ae37 OH |
5523 | warning (OPT_Wattributes, "%qs attribute ignored", |
5524 | IDENTIFIER_POINTER (name)); | |
2724e58f OH |
5525 | return NULL_TREE; |
5526 | } | |
5527 | ||
5528 | /* Get the vector size (in bytes). */ | |
5529 | vecsize = tree_low_cst (size, 1); | |
5530 | ||
5531 | /* We need to provide for vector pointers, vector arrays, and | |
5532 | functions returning vectors. For example: | |
5533 | ||
5534 | __attribute__((vector_size(16))) short *foo; | |
5535 | ||
5536 | In this case, the mode is SI, but the type being modified is | |
5537 | HI, so we need to look further. */ | |
5538 | ||
5539 | while (POINTER_TYPE_P (type) | |
5540 | || TREE_CODE (type) == FUNCTION_TYPE | |
132a5459 | 5541 | || TREE_CODE (type) == ARRAY_TYPE) |
2724e58f OH |
5542 | type = TREE_TYPE (type); |
5543 | ||
5544 | /* Get the mode of the type being modified. */ | |
5545 | orig_mode = TYPE_MODE (type); | |
5546 | ||
5547 | if ((!INTEGRAL_TYPE_P (type) | |
5548 | && !SCALAR_FLOAT_TYPE_P (type) | |
5549 | && !FIXED_POINT_TYPE_P (type)) | |
5550 | || (!SCALAR_FLOAT_MODE_P (orig_mode) | |
5551 | && GET_MODE_CLASS (orig_mode) != MODE_INT | |
5552 | && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode)) | |
5553 | || !host_integerp (TYPE_SIZE_UNIT (type), 1) | |
5554 | || TREE_CODE (type) == BOOLEAN_TYPE) | |
5555 | { | |
7948ae37 OH |
5556 | error ("invalid vector type for attribute %qs", |
5557 | IDENTIFIER_POINTER (name)); | |
2724e58f OH |
5558 | return NULL_TREE; |
5559 | } | |
5560 | ||
5561 | if (vecsize % tree_low_cst (TYPE_SIZE_UNIT (type), 1)) | |
5562 | { | |
5563 | error ("vector size not an integral multiple of component size"); | |
5564 | return NULL; | |
5565 | } | |
5566 | ||
5567 | if (vecsize == 0) | |
5568 | { | |
5569 | error ("zero vector size"); | |
5570 | return NULL; | |
5571 | } | |
5572 | ||
5573 | /* Calculate how many units fit in the vector. */ | |
5574 | nunits = vecsize / tree_low_cst (TYPE_SIZE_UNIT (type), 1); | |
5575 | if (nunits & (nunits - 1)) | |
5576 | { | |
5577 | error ("number of components of the vector not a power of two"); | |
5578 | return NULL_TREE; | |
5579 | } | |
5580 | ||
5581 | new_type = build_vector_type (type, nunits); | |
5582 | ||
5583 | /* Build back pointers if needed. */ | |
9b469089 | 5584 | *node = reconstruct_complex_type (*node, new_type); |
2724e58f OH |
5585 | |
5586 | return NULL_TREE; | |
5587 | } | |
5588 | ||
7948ae37 OH |
5589 | /* Handle a "vector_type" attribute; arguments as in |
5590 | struct attribute_spec.handler. */ | |
5591 | ||
5592 | static tree | |
5593 | handle_vector_type_attribute (tree *node, tree name, tree ARG_UNUSED (args), | |
5594 | int ARG_UNUSED (flags), | |
5595 | bool *no_add_attrs) | |
5596 | { | |
5597 | /* Vector representative type and size. */ | |
5598 | tree rep_type = *node; | |
5599 | tree rep_size = TYPE_SIZE_UNIT (rep_type); | |
5600 | tree rep_name; | |
5601 | ||
5602 | /* Vector size in bytes and number of units. */ | |
5603 | unsigned HOST_WIDE_INT vec_bytes, vec_units; | |
5604 | ||
5605 | /* Vector element type and mode. */ | |
5606 | tree elem_type; | |
5607 | enum machine_mode elem_mode; | |
5608 | ||
5609 | *no_add_attrs = true; | |
5610 | ||
5611 | /* Get the representative array type, possibly nested within a | |
5612 | padding record e.g. for alignment purposes. */ | |
5613 | ||
315cff15 | 5614 | if (TYPE_IS_PADDING_P (rep_type)) |
7948ae37 OH |
5615 | rep_type = TREE_TYPE (TYPE_FIELDS (rep_type)); |
5616 | ||
5617 | if (TREE_CODE (rep_type) != ARRAY_TYPE) | |
5618 | { | |
5619 | error ("attribute %qs applies to array types only", | |
5620 | IDENTIFIER_POINTER (name)); | |
5621 | return NULL_TREE; | |
5622 | } | |
5623 | ||
5624 | /* Silently punt on variable sizes. We can't make vector types for them, | |
5625 | need to ignore them on front-end generated subtypes of unconstrained | |
5626 | bases, and this attribute is for binding implementors, not end-users, so | |
5627 | we should never get there from legitimate explicit uses. */ | |
5628 | ||
5629 | if (!host_integerp (rep_size, 1)) | |
5630 | return NULL_TREE; | |
5631 | ||
5632 | /* Get the element type/mode and check this is something we know | |
5633 | how to make vectors of. */ | |
5634 | ||
5635 | elem_type = TREE_TYPE (rep_type); | |
5636 | elem_mode = TYPE_MODE (elem_type); | |
5637 | ||
5638 | if ((!INTEGRAL_TYPE_P (elem_type) | |
5639 | && !SCALAR_FLOAT_TYPE_P (elem_type) | |
5640 | && !FIXED_POINT_TYPE_P (elem_type)) | |
5641 | || (!SCALAR_FLOAT_MODE_P (elem_mode) | |
5642 | && GET_MODE_CLASS (elem_mode) != MODE_INT | |
5643 | && !ALL_SCALAR_FIXED_POINT_MODE_P (elem_mode)) | |
5644 | || !host_integerp (TYPE_SIZE_UNIT (elem_type), 1)) | |
5645 | { | |
5646 | error ("invalid element type for attribute %qs", | |
5647 | IDENTIFIER_POINTER (name)); | |
5648 | return NULL_TREE; | |
5649 | } | |
5650 | ||
5651 | /* Sanity check the vector size and element type consistency. */ | |
5652 | ||
5653 | vec_bytes = tree_low_cst (rep_size, 1); | |
5654 | ||
5655 | if (vec_bytes % tree_low_cst (TYPE_SIZE_UNIT (elem_type), 1)) | |
5656 | { | |
5657 | error ("vector size not an integral multiple of component size"); | |
5658 | return NULL; | |
5659 | } | |
5660 | ||
5661 | if (vec_bytes == 0) | |
5662 | { | |
5663 | error ("zero vector size"); | |
5664 | return NULL; | |
5665 | } | |
5666 | ||
5667 | vec_units = vec_bytes / tree_low_cst (TYPE_SIZE_UNIT (elem_type), 1); | |
5668 | if (vec_units & (vec_units - 1)) | |
5669 | { | |
5670 | error ("number of components of the vector not a power of two"); | |
5671 | return NULL_TREE; | |
5672 | } | |
5673 | ||
5674 | /* Build the vector type and replace. */ | |
5675 | ||
5676 | *node = build_vector_type (elem_type, vec_units); | |
5677 | rep_name = TYPE_NAME (rep_type); | |
5678 | if (TREE_CODE (rep_name) == TYPE_DECL) | |
5679 | rep_name = DECL_NAME (rep_name); | |
5680 | TYPE_NAME (*node) = rep_name; | |
5681 | TYPE_REPRESENTATIVE_ARRAY (*node) = rep_type; | |
5682 | ||
5683 | return NULL_TREE; | |
5684 | } | |
5685 | ||
a1ab4c31 AC |
5686 | /* ----------------------------------------------------------------------- * |
5687 | * BUILTIN FUNCTIONS * | |
5688 | * ----------------------------------------------------------------------- */ | |
5689 | ||
5690 | /* Worker for DEF_BUILTIN. Possibly define a builtin function with one or two | |
5691 | names. Does not declare a non-__builtin_ function if flag_no_builtin, or | |
5692 | if nonansi_p and flag_no_nonansi_builtin. */ | |
5693 | ||
5694 | static void | |
5695 | def_builtin_1 (enum built_in_function fncode, | |
5696 | const char *name, | |
5697 | enum built_in_class fnclass, | |
5698 | tree fntype, tree libtype, | |
5699 | bool both_p, bool fallback_p, | |
5700 | bool nonansi_p ATTRIBUTE_UNUSED, | |
5701 | tree fnattrs, bool implicit_p) | |
5702 | { | |
5703 | tree decl; | |
5704 | const char *libname; | |
5705 | ||
5706 | /* Preserve an already installed decl. It most likely was setup in advance | |
5707 | (e.g. as part of the internal builtins) for specific reasons. */ | |
e79983f4 | 5708 | if (builtin_decl_explicit (fncode) != NULL_TREE) |
a1ab4c31 AC |
5709 | return; |
5710 | ||
5711 | gcc_assert ((!both_p && !fallback_p) | |
5712 | || !strncmp (name, "__builtin_", | |
5713 | strlen ("__builtin_"))); | |
5714 | ||
5715 | libname = name + strlen ("__builtin_"); | |
5716 | decl = add_builtin_function (name, fntype, fncode, fnclass, | |
5717 | (fallback_p ? libname : NULL), | |
5718 | fnattrs); | |
5719 | if (both_p) | |
5720 | /* ??? This is normally further controlled by command-line options | |
5721 | like -fno-builtin, but we don't have them for Ada. */ | |
5722 | add_builtin_function (libname, libtype, fncode, fnclass, | |
5723 | NULL, fnattrs); | |
5724 | ||
e79983f4 | 5725 | set_builtin_decl (fncode, decl, implicit_p); |
a1ab4c31 AC |
5726 | } |
5727 | ||
5728 | static int flag_isoc94 = 0; | |
5729 | static int flag_isoc99 = 0; | |
5730 | ||
5731 | /* Install what the common builtins.def offers. */ | |
5732 | ||
5733 | static void | |
5734 | install_builtin_functions (void) | |
5735 | { | |
5736 | #define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \ | |
5737 | NONANSI_P, ATTRS, IMPLICIT, COND) \ | |
5738 | if (NAME && COND) \ | |
5739 | def_builtin_1 (ENUM, NAME, CLASS, \ | |
5740 | builtin_types[(int) TYPE], \ | |
5741 | builtin_types[(int) LIBTYPE], \ | |
5742 | BOTH_P, FALLBACK_P, NONANSI_P, \ | |
5743 | built_in_attributes[(int) ATTRS], IMPLICIT); | |
5744 | #include "builtins.def" | |
5745 | #undef DEF_BUILTIN | |
5746 | } | |
5747 | ||
5748 | /* ----------------------------------------------------------------------- * | |
5749 | * BUILTIN FUNCTIONS * | |
5750 | * ----------------------------------------------------------------------- */ | |
5751 | ||
5752 | /* Install the builtin functions we might need. */ | |
5753 | ||
5754 | void | |
5755 | gnat_install_builtins (void) | |
5756 | { | |
5757 | install_builtin_elementary_types (); | |
5758 | install_builtin_function_types (); | |
5759 | install_builtin_attributes (); | |
5760 | ||
5761 | /* Install builtins used by generic middle-end pieces first. Some of these | |
5762 | know about internal specificities and control attributes accordingly, for | |
5763 | instance __builtin_alloca vs no-throw and -fstack-check. We will ignore | |
5764 | the generic definition from builtins.def. */ | |
384c400a | 5765 | build_common_builtin_nodes (); |
a1ab4c31 AC |
5766 | |
5767 | /* Now, install the target specific builtins, such as the AltiVec family on | |
5768 | ppc, and the common set as exposed by builtins.def. */ | |
5769 | targetm.init_builtins (); | |
5770 | install_builtin_functions (); | |
5771 | } | |
5772 | ||
5773 | #include "gt-ada-utils.h" | |
5774 | #include "gtype-ada.h" |