1*e4b17023SJohn Marino /* C-compiler utilities for types and variables storage layout
2*e4b17023SJohn Marino Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1996, 1998,
3*e4b17023SJohn Marino 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4*e4b17023SJohn Marino 2011 Free Software Foundation, Inc.
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino
23*e4b17023SJohn Marino #include "config.h"
24*e4b17023SJohn Marino #include "system.h"
25*e4b17023SJohn Marino #include "coretypes.h"
26*e4b17023SJohn Marino #include "tm.h"
27*e4b17023SJohn Marino #include "tree.h"
28*e4b17023SJohn Marino #include "rtl.h"
29*e4b17023SJohn Marino #include "tm_p.h"
30*e4b17023SJohn Marino #include "flags.h"
31*e4b17023SJohn Marino #include "function.h"
32*e4b17023SJohn Marino #include "expr.h"
33*e4b17023SJohn Marino #include "output.h"
34*e4b17023SJohn Marino #include "diagnostic-core.h"
35*e4b17023SJohn Marino #include "ggc.h"
36*e4b17023SJohn Marino #include "target.h"
37*e4b17023SJohn Marino #include "langhooks.h"
38*e4b17023SJohn Marino #include "regs.h"
39*e4b17023SJohn Marino #include "params.h"
40*e4b17023SJohn Marino #include "cgraph.h"
41*e4b17023SJohn Marino #include "tree-inline.h"
42*e4b17023SJohn Marino #include "tree-dump.h"
43*e4b17023SJohn Marino #include "gimple.h"
44*e4b17023SJohn Marino
45*e4b17023SJohn Marino /* Data type for the expressions representing sizes of data types.
46*e4b17023SJohn Marino It is the first integer type laid out. */
47*e4b17023SJohn Marino tree sizetype_tab[(int) TYPE_KIND_LAST];
48*e4b17023SJohn Marino
49*e4b17023SJohn Marino /* If nonzero, this is an upper limit on alignment of structure fields.
50*e4b17023SJohn Marino The value is measured in bits. */
51*e4b17023SJohn Marino unsigned int maximum_field_alignment = TARGET_DEFAULT_PACK_STRUCT * BITS_PER_UNIT;
52*e4b17023SJohn Marino
53*e4b17023SJohn Marino /* Nonzero if all REFERENCE_TYPEs are internal and hence should be allocated
54*e4b17023SJohn Marino in the address spaces' address_mode, not pointer_mode. Set only by
55*e4b17023SJohn Marino internal_reference_types called only by a front end. */
56*e4b17023SJohn Marino static int reference_types_internal = 0;
57*e4b17023SJohn Marino
58*e4b17023SJohn Marino static tree self_referential_size (tree);
59*e4b17023SJohn Marino static void finalize_record_size (record_layout_info);
60*e4b17023SJohn Marino static void finalize_type_size (tree);
61*e4b17023SJohn Marino static void place_union_field (record_layout_info, tree);
62*e4b17023SJohn Marino #if defined (PCC_BITFIELD_TYPE_MATTERS) || defined (BITFIELD_NBYTES_LIMITED)
63*e4b17023SJohn Marino static int excess_unit_span (HOST_WIDE_INT, HOST_WIDE_INT, HOST_WIDE_INT,
64*e4b17023SJohn Marino HOST_WIDE_INT, tree);
65*e4b17023SJohn Marino #endif
66*e4b17023SJohn Marino extern void debug_rli (record_layout_info);
67*e4b17023SJohn Marino
68*e4b17023SJohn Marino /* Show that REFERENCE_TYPES are internal and should use address_mode.
69*e4b17023SJohn Marino Called only by front end. */
70*e4b17023SJohn Marino
71*e4b17023SJohn Marino void
internal_reference_types(void)72*e4b17023SJohn Marino internal_reference_types (void)
73*e4b17023SJohn Marino {
74*e4b17023SJohn Marino reference_types_internal = 1;
75*e4b17023SJohn Marino }
76*e4b17023SJohn Marino
77*e4b17023SJohn Marino /* Given a size SIZE that may not be a constant, return a SAVE_EXPR
78*e4b17023SJohn Marino to serve as the actual size-expression for a type or decl. */
79*e4b17023SJohn Marino
80*e4b17023SJohn Marino tree
variable_size(tree size)81*e4b17023SJohn Marino variable_size (tree size)
82*e4b17023SJohn Marino {
83*e4b17023SJohn Marino /* Obviously. */
84*e4b17023SJohn Marino if (TREE_CONSTANT (size))
85*e4b17023SJohn Marino return size;
86*e4b17023SJohn Marino
87*e4b17023SJohn Marino /* If the size is self-referential, we can't make a SAVE_EXPR (see
88*e4b17023SJohn Marino save_expr for the rationale). But we can do something else. */
89*e4b17023SJohn Marino if (CONTAINS_PLACEHOLDER_P (size))
90*e4b17023SJohn Marino return self_referential_size (size);
91*e4b17023SJohn Marino
92*e4b17023SJohn Marino /* If we are in the global binding level, we can't make a SAVE_EXPR
93*e4b17023SJohn Marino since it may end up being shared across functions, so it is up
94*e4b17023SJohn Marino to the front-end to deal with this case. */
95*e4b17023SJohn Marino if (lang_hooks.decls.global_bindings_p ())
96*e4b17023SJohn Marino return size;
97*e4b17023SJohn Marino
98*e4b17023SJohn Marino return save_expr (size);
99*e4b17023SJohn Marino }
100*e4b17023SJohn Marino
101*e4b17023SJohn Marino /* An array of functions used for self-referential size computation. */
102*e4b17023SJohn Marino static GTY(()) VEC (tree, gc) *size_functions;
103*e4b17023SJohn Marino
104*e4b17023SJohn Marino /* Look inside EXPR into simple arithmetic operations involving constants.
105*e4b17023SJohn Marino Return the outermost non-arithmetic or non-constant node. */
106*e4b17023SJohn Marino
107*e4b17023SJohn Marino static tree
skip_simple_constant_arithmetic(tree expr)108*e4b17023SJohn Marino skip_simple_constant_arithmetic (tree expr)
109*e4b17023SJohn Marino {
110*e4b17023SJohn Marino while (true)
111*e4b17023SJohn Marino {
112*e4b17023SJohn Marino if (UNARY_CLASS_P (expr))
113*e4b17023SJohn Marino expr = TREE_OPERAND (expr, 0);
114*e4b17023SJohn Marino else if (BINARY_CLASS_P (expr))
115*e4b17023SJohn Marino {
116*e4b17023SJohn Marino if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
117*e4b17023SJohn Marino expr = TREE_OPERAND (expr, 0);
118*e4b17023SJohn Marino else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
119*e4b17023SJohn Marino expr = TREE_OPERAND (expr, 1);
120*e4b17023SJohn Marino else
121*e4b17023SJohn Marino break;
122*e4b17023SJohn Marino }
123*e4b17023SJohn Marino else
124*e4b17023SJohn Marino break;
125*e4b17023SJohn Marino }
126*e4b17023SJohn Marino
127*e4b17023SJohn Marino return expr;
128*e4b17023SJohn Marino }
129*e4b17023SJohn Marino
130*e4b17023SJohn Marino /* Similar to copy_tree_r but do not copy component references involving
131*e4b17023SJohn Marino PLACEHOLDER_EXPRs. These nodes are spotted in find_placeholder_in_expr
132*e4b17023SJohn Marino and substituted in substitute_in_expr. */
133*e4b17023SJohn Marino
134*e4b17023SJohn Marino static tree
copy_self_referential_tree_r(tree * tp,int * walk_subtrees,void * data)135*e4b17023SJohn Marino copy_self_referential_tree_r (tree *tp, int *walk_subtrees, void *data)
136*e4b17023SJohn Marino {
137*e4b17023SJohn Marino enum tree_code code = TREE_CODE (*tp);
138*e4b17023SJohn Marino
139*e4b17023SJohn Marino /* Stop at types, decls, constants like copy_tree_r. */
140*e4b17023SJohn Marino if (TREE_CODE_CLASS (code) == tcc_type
141*e4b17023SJohn Marino || TREE_CODE_CLASS (code) == tcc_declaration
142*e4b17023SJohn Marino || TREE_CODE_CLASS (code) == tcc_constant)
143*e4b17023SJohn Marino {
144*e4b17023SJohn Marino *walk_subtrees = 0;
145*e4b17023SJohn Marino return NULL_TREE;
146*e4b17023SJohn Marino }
147*e4b17023SJohn Marino
148*e4b17023SJohn Marino /* This is the pattern built in ada/make_aligning_type. */
149*e4b17023SJohn Marino else if (code == ADDR_EXPR
150*e4b17023SJohn Marino && TREE_CODE (TREE_OPERAND (*tp, 0)) == PLACEHOLDER_EXPR)
151*e4b17023SJohn Marino {
152*e4b17023SJohn Marino *walk_subtrees = 0;
153*e4b17023SJohn Marino return NULL_TREE;
154*e4b17023SJohn Marino }
155*e4b17023SJohn Marino
156*e4b17023SJohn Marino /* Default case: the component reference. */
157*e4b17023SJohn Marino else if (code == COMPONENT_REF)
158*e4b17023SJohn Marino {
159*e4b17023SJohn Marino tree inner;
160*e4b17023SJohn Marino for (inner = TREE_OPERAND (*tp, 0);
161*e4b17023SJohn Marino REFERENCE_CLASS_P (inner);
162*e4b17023SJohn Marino inner = TREE_OPERAND (inner, 0))
163*e4b17023SJohn Marino ;
164*e4b17023SJohn Marino
165*e4b17023SJohn Marino if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
166*e4b17023SJohn Marino {
167*e4b17023SJohn Marino *walk_subtrees = 0;
168*e4b17023SJohn Marino return NULL_TREE;
169*e4b17023SJohn Marino }
170*e4b17023SJohn Marino }
171*e4b17023SJohn Marino
172*e4b17023SJohn Marino /* We're not supposed to have them in self-referential size trees
173*e4b17023SJohn Marino because we wouldn't properly control when they are evaluated.
174*e4b17023SJohn Marino However, not creating superfluous SAVE_EXPRs requires accurate
175*e4b17023SJohn Marino tracking of readonly-ness all the way down to here, which we
176*e4b17023SJohn Marino cannot always guarantee in practice. So punt in this case. */
177*e4b17023SJohn Marino else if (code == SAVE_EXPR)
178*e4b17023SJohn Marino return error_mark_node;
179*e4b17023SJohn Marino
180*e4b17023SJohn Marino else if (code == STATEMENT_LIST)
181*e4b17023SJohn Marino gcc_unreachable ();
182*e4b17023SJohn Marino
183*e4b17023SJohn Marino return copy_tree_r (tp, walk_subtrees, data);
184*e4b17023SJohn Marino }
185*e4b17023SJohn Marino
186*e4b17023SJohn Marino /* Given a SIZE expression that is self-referential, return an equivalent
187*e4b17023SJohn Marino expression to serve as the actual size expression for a type. */
188*e4b17023SJohn Marino
189*e4b17023SJohn Marino static tree
self_referential_size(tree size)190*e4b17023SJohn Marino self_referential_size (tree size)
191*e4b17023SJohn Marino {
192*e4b17023SJohn Marino static unsigned HOST_WIDE_INT fnno = 0;
193*e4b17023SJohn Marino VEC (tree, heap) *self_refs = NULL;
194*e4b17023SJohn Marino tree param_type_list = NULL, param_decl_list = NULL;
195*e4b17023SJohn Marino tree t, ref, return_type, fntype, fnname, fndecl;
196*e4b17023SJohn Marino unsigned int i;
197*e4b17023SJohn Marino char buf[128];
198*e4b17023SJohn Marino VEC(tree,gc) *args = NULL;
199*e4b17023SJohn Marino
200*e4b17023SJohn Marino /* Do not factor out simple operations. */
201*e4b17023SJohn Marino t = skip_simple_constant_arithmetic (size);
202*e4b17023SJohn Marino if (TREE_CODE (t) == CALL_EXPR)
203*e4b17023SJohn Marino return size;
204*e4b17023SJohn Marino
205*e4b17023SJohn Marino /* Collect the list of self-references in the expression. */
206*e4b17023SJohn Marino find_placeholder_in_expr (size, &self_refs);
207*e4b17023SJohn Marino gcc_assert (VEC_length (tree, self_refs) > 0);
208*e4b17023SJohn Marino
209*e4b17023SJohn Marino /* Obtain a private copy of the expression. */
210*e4b17023SJohn Marino t = size;
211*e4b17023SJohn Marino if (walk_tree (&t, copy_self_referential_tree_r, NULL, NULL) != NULL_TREE)
212*e4b17023SJohn Marino return size;
213*e4b17023SJohn Marino size = t;
214*e4b17023SJohn Marino
215*e4b17023SJohn Marino /* Build the parameter and argument lists in parallel; also
216*e4b17023SJohn Marino substitute the former for the latter in the expression. */
217*e4b17023SJohn Marino args = VEC_alloc (tree, gc, VEC_length (tree, self_refs));
218*e4b17023SJohn Marino FOR_EACH_VEC_ELT (tree, self_refs, i, ref)
219*e4b17023SJohn Marino {
220*e4b17023SJohn Marino tree subst, param_name, param_type, param_decl;
221*e4b17023SJohn Marino
222*e4b17023SJohn Marino if (DECL_P (ref))
223*e4b17023SJohn Marino {
224*e4b17023SJohn Marino /* We shouldn't have true variables here. */
225*e4b17023SJohn Marino gcc_assert (TREE_READONLY (ref));
226*e4b17023SJohn Marino subst = ref;
227*e4b17023SJohn Marino }
228*e4b17023SJohn Marino /* This is the pattern built in ada/make_aligning_type. */
229*e4b17023SJohn Marino else if (TREE_CODE (ref) == ADDR_EXPR)
230*e4b17023SJohn Marino subst = ref;
231*e4b17023SJohn Marino /* Default case: the component reference. */
232*e4b17023SJohn Marino else
233*e4b17023SJohn Marino subst = TREE_OPERAND (ref, 1);
234*e4b17023SJohn Marino
235*e4b17023SJohn Marino sprintf (buf, "p%d", i);
236*e4b17023SJohn Marino param_name = get_identifier (buf);
237*e4b17023SJohn Marino param_type = TREE_TYPE (ref);
238*e4b17023SJohn Marino param_decl
239*e4b17023SJohn Marino = build_decl (input_location, PARM_DECL, param_name, param_type);
240*e4b17023SJohn Marino if (targetm.calls.promote_prototypes (NULL_TREE)
241*e4b17023SJohn Marino && INTEGRAL_TYPE_P (param_type)
242*e4b17023SJohn Marino && TYPE_PRECISION (param_type) < TYPE_PRECISION (integer_type_node))
243*e4b17023SJohn Marino DECL_ARG_TYPE (param_decl) = integer_type_node;
244*e4b17023SJohn Marino else
245*e4b17023SJohn Marino DECL_ARG_TYPE (param_decl) = param_type;
246*e4b17023SJohn Marino DECL_ARTIFICIAL (param_decl) = 1;
247*e4b17023SJohn Marino TREE_READONLY (param_decl) = 1;
248*e4b17023SJohn Marino
249*e4b17023SJohn Marino size = substitute_in_expr (size, subst, param_decl);
250*e4b17023SJohn Marino
251*e4b17023SJohn Marino param_type_list = tree_cons (NULL_TREE, param_type, param_type_list);
252*e4b17023SJohn Marino param_decl_list = chainon (param_decl, param_decl_list);
253*e4b17023SJohn Marino VEC_quick_push (tree, args, ref);
254*e4b17023SJohn Marino }
255*e4b17023SJohn Marino
256*e4b17023SJohn Marino VEC_free (tree, heap, self_refs);
257*e4b17023SJohn Marino
258*e4b17023SJohn Marino /* Append 'void' to indicate that the number of parameters is fixed. */
259*e4b17023SJohn Marino param_type_list = tree_cons (NULL_TREE, void_type_node, param_type_list);
260*e4b17023SJohn Marino
261*e4b17023SJohn Marino /* The 3 lists have been created in reverse order. */
262*e4b17023SJohn Marino param_type_list = nreverse (param_type_list);
263*e4b17023SJohn Marino param_decl_list = nreverse (param_decl_list);
264*e4b17023SJohn Marino
265*e4b17023SJohn Marino /* Build the function type. */
266*e4b17023SJohn Marino return_type = TREE_TYPE (size);
267*e4b17023SJohn Marino fntype = build_function_type (return_type, param_type_list);
268*e4b17023SJohn Marino
269*e4b17023SJohn Marino /* Build the function declaration. */
270*e4b17023SJohn Marino sprintf (buf, "SZ"HOST_WIDE_INT_PRINT_UNSIGNED, fnno++);
271*e4b17023SJohn Marino fnname = get_file_function_name (buf);
272*e4b17023SJohn Marino fndecl = build_decl (input_location, FUNCTION_DECL, fnname, fntype);
273*e4b17023SJohn Marino for (t = param_decl_list; t; t = DECL_CHAIN (t))
274*e4b17023SJohn Marino DECL_CONTEXT (t) = fndecl;
275*e4b17023SJohn Marino DECL_ARGUMENTS (fndecl) = param_decl_list;
276*e4b17023SJohn Marino DECL_RESULT (fndecl)
277*e4b17023SJohn Marino = build_decl (input_location, RESULT_DECL, 0, return_type);
278*e4b17023SJohn Marino DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
279*e4b17023SJohn Marino
280*e4b17023SJohn Marino /* The function has been created by the compiler and we don't
281*e4b17023SJohn Marino want to emit debug info for it. */
282*e4b17023SJohn Marino DECL_ARTIFICIAL (fndecl) = 1;
283*e4b17023SJohn Marino DECL_IGNORED_P (fndecl) = 1;
284*e4b17023SJohn Marino
285*e4b17023SJohn Marino /* It is supposed to be "const" and never throw. */
286*e4b17023SJohn Marino TREE_READONLY (fndecl) = 1;
287*e4b17023SJohn Marino TREE_NOTHROW (fndecl) = 1;
288*e4b17023SJohn Marino
289*e4b17023SJohn Marino /* We want it to be inlined when this is deemed profitable, as
290*e4b17023SJohn Marino well as discarded if every call has been integrated. */
291*e4b17023SJohn Marino DECL_DECLARED_INLINE_P (fndecl) = 1;
292*e4b17023SJohn Marino
293*e4b17023SJohn Marino /* It is made up of a unique return statement. */
294*e4b17023SJohn Marino DECL_INITIAL (fndecl) = make_node (BLOCK);
295*e4b17023SJohn Marino BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
296*e4b17023SJohn Marino t = build2 (MODIFY_EXPR, return_type, DECL_RESULT (fndecl), size);
297*e4b17023SJohn Marino DECL_SAVED_TREE (fndecl) = build1 (RETURN_EXPR, void_type_node, t);
298*e4b17023SJohn Marino TREE_STATIC (fndecl) = 1;
299*e4b17023SJohn Marino
300*e4b17023SJohn Marino /* Put it onto the list of size functions. */
301*e4b17023SJohn Marino VEC_safe_push (tree, gc, size_functions, fndecl);
302*e4b17023SJohn Marino
303*e4b17023SJohn Marino /* Replace the original expression with a call to the size function. */
304*e4b17023SJohn Marino return build_call_expr_loc_vec (UNKNOWN_LOCATION, fndecl, args);
305*e4b17023SJohn Marino }
306*e4b17023SJohn Marino
307*e4b17023SJohn Marino /* Take, queue and compile all the size functions. It is essential that
308*e4b17023SJohn Marino the size functions be gimplified at the very end of the compilation
309*e4b17023SJohn Marino in order to guarantee transparent handling of self-referential sizes.
310*e4b17023SJohn Marino Otherwise the GENERIC inliner would not be able to inline them back
311*e4b17023SJohn Marino at each of their call sites, thus creating artificial non-constant
312*e4b17023SJohn Marino size expressions which would trigger nasty problems later on. */
313*e4b17023SJohn Marino
314*e4b17023SJohn Marino void
finalize_size_functions(void)315*e4b17023SJohn Marino finalize_size_functions (void)
316*e4b17023SJohn Marino {
317*e4b17023SJohn Marino unsigned int i;
318*e4b17023SJohn Marino tree fndecl;
319*e4b17023SJohn Marino
320*e4b17023SJohn Marino for (i = 0; VEC_iterate(tree, size_functions, i, fndecl); i++)
321*e4b17023SJohn Marino {
322*e4b17023SJohn Marino dump_function (TDI_original, fndecl);
323*e4b17023SJohn Marino gimplify_function_tree (fndecl);
324*e4b17023SJohn Marino dump_function (TDI_generic, fndecl);
325*e4b17023SJohn Marino cgraph_finalize_function (fndecl, false);
326*e4b17023SJohn Marino }
327*e4b17023SJohn Marino
328*e4b17023SJohn Marino VEC_free (tree, gc, size_functions);
329*e4b17023SJohn Marino }
330*e4b17023SJohn Marino
331*e4b17023SJohn Marino /* Return the machine mode to use for a nonscalar of SIZE bits. The
332*e4b17023SJohn Marino mode must be in class MCLASS, and have exactly that many value bits;
333*e4b17023SJohn Marino it may have padding as well. If LIMIT is nonzero, modes of wider
334*e4b17023SJohn Marino than MAX_FIXED_MODE_SIZE will not be used. */
335*e4b17023SJohn Marino
336*e4b17023SJohn Marino enum machine_mode
mode_for_size(unsigned int size,enum mode_class mclass,int limit)337*e4b17023SJohn Marino mode_for_size (unsigned int size, enum mode_class mclass, int limit)
338*e4b17023SJohn Marino {
339*e4b17023SJohn Marino enum machine_mode mode;
340*e4b17023SJohn Marino
341*e4b17023SJohn Marino if (limit && size > MAX_FIXED_MODE_SIZE)
342*e4b17023SJohn Marino return BLKmode;
343*e4b17023SJohn Marino
344*e4b17023SJohn Marino /* Get the first mode which has this size, in the specified class. */
345*e4b17023SJohn Marino for (mode = GET_CLASS_NARROWEST_MODE (mclass); mode != VOIDmode;
346*e4b17023SJohn Marino mode = GET_MODE_WIDER_MODE (mode))
347*e4b17023SJohn Marino if (GET_MODE_PRECISION (mode) == size)
348*e4b17023SJohn Marino return mode;
349*e4b17023SJohn Marino
350*e4b17023SJohn Marino return BLKmode;
351*e4b17023SJohn Marino }
352*e4b17023SJohn Marino
353*e4b17023SJohn Marino /* Similar, except passed a tree node. */
354*e4b17023SJohn Marino
355*e4b17023SJohn Marino enum machine_mode
mode_for_size_tree(const_tree size,enum mode_class mclass,int limit)356*e4b17023SJohn Marino mode_for_size_tree (const_tree size, enum mode_class mclass, int limit)
357*e4b17023SJohn Marino {
358*e4b17023SJohn Marino unsigned HOST_WIDE_INT uhwi;
359*e4b17023SJohn Marino unsigned int ui;
360*e4b17023SJohn Marino
361*e4b17023SJohn Marino if (!host_integerp (size, 1))
362*e4b17023SJohn Marino return BLKmode;
363*e4b17023SJohn Marino uhwi = tree_low_cst (size, 1);
364*e4b17023SJohn Marino ui = uhwi;
365*e4b17023SJohn Marino if (uhwi != ui)
366*e4b17023SJohn Marino return BLKmode;
367*e4b17023SJohn Marino return mode_for_size (ui, mclass, limit);
368*e4b17023SJohn Marino }
369*e4b17023SJohn Marino
370*e4b17023SJohn Marino /* Similar, but never return BLKmode; return the narrowest mode that
371*e4b17023SJohn Marino contains at least the requested number of value bits. */
372*e4b17023SJohn Marino
373*e4b17023SJohn Marino enum machine_mode
smallest_mode_for_size(unsigned int size,enum mode_class mclass)374*e4b17023SJohn Marino smallest_mode_for_size (unsigned int size, enum mode_class mclass)
375*e4b17023SJohn Marino {
376*e4b17023SJohn Marino enum machine_mode mode;
377*e4b17023SJohn Marino
378*e4b17023SJohn Marino /* Get the first mode which has at least this size, in the
379*e4b17023SJohn Marino specified class. */
380*e4b17023SJohn Marino for (mode = GET_CLASS_NARROWEST_MODE (mclass); mode != VOIDmode;
381*e4b17023SJohn Marino mode = GET_MODE_WIDER_MODE (mode))
382*e4b17023SJohn Marino if (GET_MODE_PRECISION (mode) >= size)
383*e4b17023SJohn Marino return mode;
384*e4b17023SJohn Marino
385*e4b17023SJohn Marino gcc_unreachable ();
386*e4b17023SJohn Marino }
387*e4b17023SJohn Marino
388*e4b17023SJohn Marino /* Find an integer mode of the exact same size, or BLKmode on failure. */
389*e4b17023SJohn Marino
390*e4b17023SJohn Marino enum machine_mode
int_mode_for_mode(enum machine_mode mode)391*e4b17023SJohn Marino int_mode_for_mode (enum machine_mode mode)
392*e4b17023SJohn Marino {
393*e4b17023SJohn Marino switch (GET_MODE_CLASS (mode))
394*e4b17023SJohn Marino {
395*e4b17023SJohn Marino case MODE_INT:
396*e4b17023SJohn Marino case MODE_PARTIAL_INT:
397*e4b17023SJohn Marino break;
398*e4b17023SJohn Marino
399*e4b17023SJohn Marino case MODE_COMPLEX_INT:
400*e4b17023SJohn Marino case MODE_COMPLEX_FLOAT:
401*e4b17023SJohn Marino case MODE_FLOAT:
402*e4b17023SJohn Marino case MODE_DECIMAL_FLOAT:
403*e4b17023SJohn Marino case MODE_VECTOR_INT:
404*e4b17023SJohn Marino case MODE_VECTOR_FLOAT:
405*e4b17023SJohn Marino case MODE_FRACT:
406*e4b17023SJohn Marino case MODE_ACCUM:
407*e4b17023SJohn Marino case MODE_UFRACT:
408*e4b17023SJohn Marino case MODE_UACCUM:
409*e4b17023SJohn Marino case MODE_VECTOR_FRACT:
410*e4b17023SJohn Marino case MODE_VECTOR_ACCUM:
411*e4b17023SJohn Marino case MODE_VECTOR_UFRACT:
412*e4b17023SJohn Marino case MODE_VECTOR_UACCUM:
413*e4b17023SJohn Marino mode = mode_for_size (GET_MODE_BITSIZE (mode), MODE_INT, 0);
414*e4b17023SJohn Marino break;
415*e4b17023SJohn Marino
416*e4b17023SJohn Marino case MODE_RANDOM:
417*e4b17023SJohn Marino if (mode == BLKmode)
418*e4b17023SJohn Marino break;
419*e4b17023SJohn Marino
420*e4b17023SJohn Marino /* ... fall through ... */
421*e4b17023SJohn Marino
422*e4b17023SJohn Marino case MODE_CC:
423*e4b17023SJohn Marino default:
424*e4b17023SJohn Marino gcc_unreachable ();
425*e4b17023SJohn Marino }
426*e4b17023SJohn Marino
427*e4b17023SJohn Marino return mode;
428*e4b17023SJohn Marino }
429*e4b17023SJohn Marino
430*e4b17023SJohn Marino /* Find a mode that is suitable for representing a vector with
431*e4b17023SJohn Marino NUNITS elements of mode INNERMODE. Returns BLKmode if there
432*e4b17023SJohn Marino is no suitable mode. */
433*e4b17023SJohn Marino
434*e4b17023SJohn Marino enum machine_mode
mode_for_vector(enum machine_mode innermode,unsigned nunits)435*e4b17023SJohn Marino mode_for_vector (enum machine_mode innermode, unsigned nunits)
436*e4b17023SJohn Marino {
437*e4b17023SJohn Marino enum machine_mode mode;
438*e4b17023SJohn Marino
439*e4b17023SJohn Marino /* First, look for a supported vector type. */
440*e4b17023SJohn Marino if (SCALAR_FLOAT_MODE_P (innermode))
441*e4b17023SJohn Marino mode = MIN_MODE_VECTOR_FLOAT;
442*e4b17023SJohn Marino else if (SCALAR_FRACT_MODE_P (innermode))
443*e4b17023SJohn Marino mode = MIN_MODE_VECTOR_FRACT;
444*e4b17023SJohn Marino else if (SCALAR_UFRACT_MODE_P (innermode))
445*e4b17023SJohn Marino mode = MIN_MODE_VECTOR_UFRACT;
446*e4b17023SJohn Marino else if (SCALAR_ACCUM_MODE_P (innermode))
447*e4b17023SJohn Marino mode = MIN_MODE_VECTOR_ACCUM;
448*e4b17023SJohn Marino else if (SCALAR_UACCUM_MODE_P (innermode))
449*e4b17023SJohn Marino mode = MIN_MODE_VECTOR_UACCUM;
450*e4b17023SJohn Marino else
451*e4b17023SJohn Marino mode = MIN_MODE_VECTOR_INT;
452*e4b17023SJohn Marino
453*e4b17023SJohn Marino /* Do not check vector_mode_supported_p here. We'll do that
454*e4b17023SJohn Marino later in vector_type_mode. */
455*e4b17023SJohn Marino for (; mode != VOIDmode ; mode = GET_MODE_WIDER_MODE (mode))
456*e4b17023SJohn Marino if (GET_MODE_NUNITS (mode) == nunits
457*e4b17023SJohn Marino && GET_MODE_INNER (mode) == innermode)
458*e4b17023SJohn Marino break;
459*e4b17023SJohn Marino
460*e4b17023SJohn Marino /* For integers, try mapping it to a same-sized scalar mode. */
461*e4b17023SJohn Marino if (mode == VOIDmode
462*e4b17023SJohn Marino && GET_MODE_CLASS (innermode) == MODE_INT)
463*e4b17023SJohn Marino mode = mode_for_size (nunits * GET_MODE_BITSIZE (innermode),
464*e4b17023SJohn Marino MODE_INT, 0);
465*e4b17023SJohn Marino
466*e4b17023SJohn Marino if (mode == VOIDmode
467*e4b17023SJohn Marino || (GET_MODE_CLASS (mode) == MODE_INT
468*e4b17023SJohn Marino && !have_regs_of_mode[mode]))
469*e4b17023SJohn Marino return BLKmode;
470*e4b17023SJohn Marino
471*e4b17023SJohn Marino return mode;
472*e4b17023SJohn Marino }
473*e4b17023SJohn Marino
474*e4b17023SJohn Marino /* Return the alignment of MODE. This will be bounded by 1 and
475*e4b17023SJohn Marino BIGGEST_ALIGNMENT. */
476*e4b17023SJohn Marino
477*e4b17023SJohn Marino unsigned int
get_mode_alignment(enum machine_mode mode)478*e4b17023SJohn Marino get_mode_alignment (enum machine_mode mode)
479*e4b17023SJohn Marino {
480*e4b17023SJohn Marino return MIN (BIGGEST_ALIGNMENT, MAX (1, mode_base_align[mode]*BITS_PER_UNIT));
481*e4b17023SJohn Marino }
482*e4b17023SJohn Marino
483*e4b17023SJohn Marino /* Return the natural mode of an array, given that it is SIZE bytes in
484*e4b17023SJohn Marino total and has elements of type ELEM_TYPE. */
485*e4b17023SJohn Marino
486*e4b17023SJohn Marino static enum machine_mode
mode_for_array(tree elem_type,tree size)487*e4b17023SJohn Marino mode_for_array (tree elem_type, tree size)
488*e4b17023SJohn Marino {
489*e4b17023SJohn Marino tree elem_size;
490*e4b17023SJohn Marino unsigned HOST_WIDE_INT int_size, int_elem_size;
491*e4b17023SJohn Marino bool limit_p;
492*e4b17023SJohn Marino
493*e4b17023SJohn Marino /* One-element arrays get the component type's mode. */
494*e4b17023SJohn Marino elem_size = TYPE_SIZE (elem_type);
495*e4b17023SJohn Marino if (simple_cst_equal (size, elem_size))
496*e4b17023SJohn Marino return TYPE_MODE (elem_type);
497*e4b17023SJohn Marino
498*e4b17023SJohn Marino limit_p = true;
499*e4b17023SJohn Marino if (host_integerp (size, 1) && host_integerp (elem_size, 1))
500*e4b17023SJohn Marino {
501*e4b17023SJohn Marino int_size = tree_low_cst (size, 1);
502*e4b17023SJohn Marino int_elem_size = tree_low_cst (elem_size, 1);
503*e4b17023SJohn Marino if (int_elem_size > 0
504*e4b17023SJohn Marino && int_size % int_elem_size == 0
505*e4b17023SJohn Marino && targetm.array_mode_supported_p (TYPE_MODE (elem_type),
506*e4b17023SJohn Marino int_size / int_elem_size))
507*e4b17023SJohn Marino limit_p = false;
508*e4b17023SJohn Marino }
509*e4b17023SJohn Marino return mode_for_size_tree (size, MODE_INT, limit_p);
510*e4b17023SJohn Marino }
511*e4b17023SJohn Marino
512*e4b17023SJohn Marino /* Subroutine of layout_decl: Force alignment required for the data type.
513*e4b17023SJohn Marino But if the decl itself wants greater alignment, don't override that. */
514*e4b17023SJohn Marino
515*e4b17023SJohn Marino static inline void
do_type_align(tree type,tree decl)516*e4b17023SJohn Marino do_type_align (tree type, tree decl)
517*e4b17023SJohn Marino {
518*e4b17023SJohn Marino if (TYPE_ALIGN (type) > DECL_ALIGN (decl))
519*e4b17023SJohn Marino {
520*e4b17023SJohn Marino DECL_ALIGN (decl) = TYPE_ALIGN (type);
521*e4b17023SJohn Marino if (TREE_CODE (decl) == FIELD_DECL)
522*e4b17023SJohn Marino DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
523*e4b17023SJohn Marino }
524*e4b17023SJohn Marino }
525*e4b17023SJohn Marino
526*e4b17023SJohn Marino /* Set the size, mode and alignment of a ..._DECL node.
527*e4b17023SJohn Marino TYPE_DECL does need this for C++.
528*e4b17023SJohn Marino Note that LABEL_DECL and CONST_DECL nodes do not need this,
529*e4b17023SJohn Marino and FUNCTION_DECL nodes have them set up in a special (and simple) way.
530*e4b17023SJohn Marino Don't call layout_decl for them.
531*e4b17023SJohn Marino
532*e4b17023SJohn Marino KNOWN_ALIGN is the amount of alignment we can assume this
533*e4b17023SJohn Marino decl has with no special effort. It is relevant only for FIELD_DECLs
534*e4b17023SJohn Marino and depends on the previous fields.
535*e4b17023SJohn Marino All that matters about KNOWN_ALIGN is which powers of 2 divide it.
536*e4b17023SJohn Marino If KNOWN_ALIGN is 0, it means, "as much alignment as you like":
537*e4b17023SJohn Marino the record will be aligned to suit. */
538*e4b17023SJohn Marino
539*e4b17023SJohn Marino void
layout_decl(tree decl,unsigned int known_align)540*e4b17023SJohn Marino layout_decl (tree decl, unsigned int known_align)
541*e4b17023SJohn Marino {
542*e4b17023SJohn Marino tree type = TREE_TYPE (decl);
543*e4b17023SJohn Marino enum tree_code code = TREE_CODE (decl);
544*e4b17023SJohn Marino rtx rtl = NULL_RTX;
545*e4b17023SJohn Marino location_t loc = DECL_SOURCE_LOCATION (decl);
546*e4b17023SJohn Marino
547*e4b17023SJohn Marino if (code == CONST_DECL)
548*e4b17023SJohn Marino return;
549*e4b17023SJohn Marino
550*e4b17023SJohn Marino gcc_assert (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL
551*e4b17023SJohn Marino || code == TYPE_DECL ||code == FIELD_DECL);
552*e4b17023SJohn Marino
553*e4b17023SJohn Marino rtl = DECL_RTL_IF_SET (decl);
554*e4b17023SJohn Marino
555*e4b17023SJohn Marino if (type == error_mark_node)
556*e4b17023SJohn Marino type = void_type_node;
557*e4b17023SJohn Marino
558*e4b17023SJohn Marino /* Usually the size and mode come from the data type without change,
559*e4b17023SJohn Marino however, the front-end may set the explicit width of the field, so its
560*e4b17023SJohn Marino size may not be the same as the size of its type. This happens with
561*e4b17023SJohn Marino bitfields, of course (an `int' bitfield may be only 2 bits, say), but it
562*e4b17023SJohn Marino also happens with other fields. For example, the C++ front-end creates
563*e4b17023SJohn Marino zero-sized fields corresponding to empty base classes, and depends on
564*e4b17023SJohn Marino layout_type setting DECL_FIELD_BITPOS correctly for the field. Set the
565*e4b17023SJohn Marino size in bytes from the size in bits. If we have already set the mode,
566*e4b17023SJohn Marino don't set it again since we can be called twice for FIELD_DECLs. */
567*e4b17023SJohn Marino
568*e4b17023SJohn Marino DECL_UNSIGNED (decl) = TYPE_UNSIGNED (type);
569*e4b17023SJohn Marino if (DECL_MODE (decl) == VOIDmode)
570*e4b17023SJohn Marino DECL_MODE (decl) = TYPE_MODE (type);
571*e4b17023SJohn Marino
572*e4b17023SJohn Marino if (DECL_SIZE (decl) == 0)
573*e4b17023SJohn Marino {
574*e4b17023SJohn Marino DECL_SIZE (decl) = TYPE_SIZE (type);
575*e4b17023SJohn Marino DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (type);
576*e4b17023SJohn Marino }
577*e4b17023SJohn Marino else if (DECL_SIZE_UNIT (decl) == 0)
578*e4b17023SJohn Marino DECL_SIZE_UNIT (decl)
579*e4b17023SJohn Marino = fold_convert_loc (loc, sizetype,
580*e4b17023SJohn Marino size_binop_loc (loc, CEIL_DIV_EXPR, DECL_SIZE (decl),
581*e4b17023SJohn Marino bitsize_unit_node));
582*e4b17023SJohn Marino
583*e4b17023SJohn Marino if (code != FIELD_DECL)
584*e4b17023SJohn Marino /* For non-fields, update the alignment from the type. */
585*e4b17023SJohn Marino do_type_align (type, decl);
586*e4b17023SJohn Marino else
587*e4b17023SJohn Marino /* For fields, it's a bit more complicated... */
588*e4b17023SJohn Marino {
589*e4b17023SJohn Marino bool old_user_align = DECL_USER_ALIGN (decl);
590*e4b17023SJohn Marino bool zero_bitfield = false;
591*e4b17023SJohn Marino bool packed_p = DECL_PACKED (decl);
592*e4b17023SJohn Marino unsigned int mfa;
593*e4b17023SJohn Marino
594*e4b17023SJohn Marino if (DECL_BIT_FIELD (decl))
595*e4b17023SJohn Marino {
596*e4b17023SJohn Marino DECL_BIT_FIELD_TYPE (decl) = type;
597*e4b17023SJohn Marino
598*e4b17023SJohn Marino /* A zero-length bit-field affects the alignment of the next
599*e4b17023SJohn Marino field. In essence such bit-fields are not influenced by
600*e4b17023SJohn Marino any packing due to #pragma pack or attribute packed. */
601*e4b17023SJohn Marino if (integer_zerop (DECL_SIZE (decl))
602*e4b17023SJohn Marino && ! targetm.ms_bitfield_layout_p (DECL_FIELD_CONTEXT (decl)))
603*e4b17023SJohn Marino {
604*e4b17023SJohn Marino zero_bitfield = true;
605*e4b17023SJohn Marino packed_p = false;
606*e4b17023SJohn Marino #ifdef PCC_BITFIELD_TYPE_MATTERS
607*e4b17023SJohn Marino if (PCC_BITFIELD_TYPE_MATTERS)
608*e4b17023SJohn Marino do_type_align (type, decl);
609*e4b17023SJohn Marino else
610*e4b17023SJohn Marino #endif
611*e4b17023SJohn Marino {
612*e4b17023SJohn Marino #ifdef EMPTY_FIELD_BOUNDARY
613*e4b17023SJohn Marino if (EMPTY_FIELD_BOUNDARY > DECL_ALIGN (decl))
614*e4b17023SJohn Marino {
615*e4b17023SJohn Marino DECL_ALIGN (decl) = EMPTY_FIELD_BOUNDARY;
616*e4b17023SJohn Marino DECL_USER_ALIGN (decl) = 0;
617*e4b17023SJohn Marino }
618*e4b17023SJohn Marino #endif
619*e4b17023SJohn Marino }
620*e4b17023SJohn Marino }
621*e4b17023SJohn Marino
622*e4b17023SJohn Marino /* See if we can use an ordinary integer mode for a bit-field.
623*e4b17023SJohn Marino Conditions are: a fixed size that is correct for another mode,
624*e4b17023SJohn Marino occupying a complete byte or bytes on proper boundary,
625*e4b17023SJohn Marino and not -fstrict-volatile-bitfields. If the latter is set,
626*e4b17023SJohn Marino we unfortunately can't check TREE_THIS_VOLATILE, as a cast
627*e4b17023SJohn Marino may make a volatile object later. */
628*e4b17023SJohn Marino if (TYPE_SIZE (type) != 0
629*e4b17023SJohn Marino && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
630*e4b17023SJohn Marino && GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT
631*e4b17023SJohn Marino && flag_strict_volatile_bitfields <= 0)
632*e4b17023SJohn Marino {
633*e4b17023SJohn Marino enum machine_mode xmode
634*e4b17023SJohn Marino = mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
635*e4b17023SJohn Marino unsigned int xalign = GET_MODE_ALIGNMENT (xmode);
636*e4b17023SJohn Marino
637*e4b17023SJohn Marino if (xmode != BLKmode
638*e4b17023SJohn Marino && !(xalign > BITS_PER_UNIT && DECL_PACKED (decl))
639*e4b17023SJohn Marino && (known_align == 0 || known_align >= xalign))
640*e4b17023SJohn Marino {
641*e4b17023SJohn Marino DECL_ALIGN (decl) = MAX (xalign, DECL_ALIGN (decl));
642*e4b17023SJohn Marino DECL_MODE (decl) = xmode;
643*e4b17023SJohn Marino DECL_BIT_FIELD (decl) = 0;
644*e4b17023SJohn Marino }
645*e4b17023SJohn Marino }
646*e4b17023SJohn Marino
647*e4b17023SJohn Marino /* Turn off DECL_BIT_FIELD if we won't need it set. */
648*e4b17023SJohn Marino if (TYPE_MODE (type) == BLKmode && DECL_MODE (decl) == BLKmode
649*e4b17023SJohn Marino && known_align >= TYPE_ALIGN (type)
650*e4b17023SJohn Marino && DECL_ALIGN (decl) >= TYPE_ALIGN (type))
651*e4b17023SJohn Marino DECL_BIT_FIELD (decl) = 0;
652*e4b17023SJohn Marino }
653*e4b17023SJohn Marino else if (packed_p && DECL_USER_ALIGN (decl))
654*e4b17023SJohn Marino /* Don't touch DECL_ALIGN. For other packed fields, go ahead and
655*e4b17023SJohn Marino round up; we'll reduce it again below. We want packing to
656*e4b17023SJohn Marino supersede USER_ALIGN inherited from the type, but defer to
657*e4b17023SJohn Marino alignment explicitly specified on the field decl. */;
658*e4b17023SJohn Marino else
659*e4b17023SJohn Marino do_type_align (type, decl);
660*e4b17023SJohn Marino
661*e4b17023SJohn Marino /* If the field is packed and not explicitly aligned, give it the
662*e4b17023SJohn Marino minimum alignment. Note that do_type_align may set
663*e4b17023SJohn Marino DECL_USER_ALIGN, so we need to check old_user_align instead. */
664*e4b17023SJohn Marino if (packed_p
665*e4b17023SJohn Marino && !old_user_align)
666*e4b17023SJohn Marino DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
667*e4b17023SJohn Marino
668*e4b17023SJohn Marino if (! packed_p && ! DECL_USER_ALIGN (decl))
669*e4b17023SJohn Marino {
670*e4b17023SJohn Marino /* Some targets (i.e. i386, VMS) limit struct field alignment
671*e4b17023SJohn Marino to a lower boundary than alignment of variables unless
672*e4b17023SJohn Marino it was overridden by attribute aligned. */
673*e4b17023SJohn Marino #ifdef BIGGEST_FIELD_ALIGNMENT
674*e4b17023SJohn Marino DECL_ALIGN (decl)
675*e4b17023SJohn Marino = MIN (DECL_ALIGN (decl), (unsigned) BIGGEST_FIELD_ALIGNMENT);
676*e4b17023SJohn Marino #endif
677*e4b17023SJohn Marino #ifdef ADJUST_FIELD_ALIGN
678*e4b17023SJohn Marino DECL_ALIGN (decl) = ADJUST_FIELD_ALIGN (decl, DECL_ALIGN (decl));
679*e4b17023SJohn Marino #endif
680*e4b17023SJohn Marino }
681*e4b17023SJohn Marino
682*e4b17023SJohn Marino if (zero_bitfield)
683*e4b17023SJohn Marino mfa = initial_max_fld_align * BITS_PER_UNIT;
684*e4b17023SJohn Marino else
685*e4b17023SJohn Marino mfa = maximum_field_alignment;
686*e4b17023SJohn Marino /* Should this be controlled by DECL_USER_ALIGN, too? */
687*e4b17023SJohn Marino if (mfa != 0)
688*e4b17023SJohn Marino DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), mfa);
689*e4b17023SJohn Marino }
690*e4b17023SJohn Marino
691*e4b17023SJohn Marino /* Evaluate nonconstant size only once, either now or as soon as safe. */
692*e4b17023SJohn Marino if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
693*e4b17023SJohn Marino DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
694*e4b17023SJohn Marino if (DECL_SIZE_UNIT (decl) != 0
695*e4b17023SJohn Marino && TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST)
696*e4b17023SJohn Marino DECL_SIZE_UNIT (decl) = variable_size (DECL_SIZE_UNIT (decl));
697*e4b17023SJohn Marino
698*e4b17023SJohn Marino /* If requested, warn about definitions of large data objects. */
699*e4b17023SJohn Marino if (warn_larger_than
700*e4b17023SJohn Marino && (code == VAR_DECL || code == PARM_DECL)
701*e4b17023SJohn Marino && ! DECL_EXTERNAL (decl))
702*e4b17023SJohn Marino {
703*e4b17023SJohn Marino tree size = DECL_SIZE_UNIT (decl);
704*e4b17023SJohn Marino
705*e4b17023SJohn Marino if (size != 0 && TREE_CODE (size) == INTEGER_CST
706*e4b17023SJohn Marino && compare_tree_int (size, larger_than_size) > 0)
707*e4b17023SJohn Marino {
708*e4b17023SJohn Marino int size_as_int = TREE_INT_CST_LOW (size);
709*e4b17023SJohn Marino
710*e4b17023SJohn Marino if (compare_tree_int (size, size_as_int) == 0)
711*e4b17023SJohn Marino warning (OPT_Wlarger_than_, "size of %q+D is %d bytes", decl, size_as_int);
712*e4b17023SJohn Marino else
713*e4b17023SJohn Marino warning (OPT_Wlarger_than_, "size of %q+D is larger than %wd bytes",
714*e4b17023SJohn Marino decl, larger_than_size);
715*e4b17023SJohn Marino }
716*e4b17023SJohn Marino }
717*e4b17023SJohn Marino
718*e4b17023SJohn Marino /* If the RTL was already set, update its mode and mem attributes. */
719*e4b17023SJohn Marino if (rtl)
720*e4b17023SJohn Marino {
721*e4b17023SJohn Marino PUT_MODE (rtl, DECL_MODE (decl));
722*e4b17023SJohn Marino SET_DECL_RTL (decl, 0);
723*e4b17023SJohn Marino set_mem_attributes (rtl, decl, 1);
724*e4b17023SJohn Marino SET_DECL_RTL (decl, rtl);
725*e4b17023SJohn Marino }
726*e4b17023SJohn Marino }
727*e4b17023SJohn Marino
728*e4b17023SJohn Marino /* Given a VAR_DECL, PARM_DECL or RESULT_DECL, clears the results of
729*e4b17023SJohn Marino a previous call to layout_decl and calls it again. */
730*e4b17023SJohn Marino
731*e4b17023SJohn Marino void
relayout_decl(tree decl)732*e4b17023SJohn Marino relayout_decl (tree decl)
733*e4b17023SJohn Marino {
734*e4b17023SJohn Marino DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = 0;
735*e4b17023SJohn Marino DECL_MODE (decl) = VOIDmode;
736*e4b17023SJohn Marino if (!DECL_USER_ALIGN (decl))
737*e4b17023SJohn Marino DECL_ALIGN (decl) = 0;
738*e4b17023SJohn Marino SET_DECL_RTL (decl, 0);
739*e4b17023SJohn Marino
740*e4b17023SJohn Marino layout_decl (decl, 0);
741*e4b17023SJohn Marino }
742*e4b17023SJohn Marino
743*e4b17023SJohn Marino /* Begin laying out type T, which may be a RECORD_TYPE, UNION_TYPE, or
744*e4b17023SJohn Marino QUAL_UNION_TYPE. Return a pointer to a struct record_layout_info which
745*e4b17023SJohn Marino is to be passed to all other layout functions for this record. It is the
746*e4b17023SJohn Marino responsibility of the caller to call `free' for the storage returned.
747*e4b17023SJohn Marino Note that garbage collection is not permitted until we finish laying
748*e4b17023SJohn Marino out the record. */
749*e4b17023SJohn Marino
750*e4b17023SJohn Marino record_layout_info
start_record_layout(tree t)751*e4b17023SJohn Marino start_record_layout (tree t)
752*e4b17023SJohn Marino {
753*e4b17023SJohn Marino record_layout_info rli = XNEW (struct record_layout_info_s);
754*e4b17023SJohn Marino
755*e4b17023SJohn Marino rli->t = t;
756*e4b17023SJohn Marino
757*e4b17023SJohn Marino /* If the type has a minimum specified alignment (via an attribute
758*e4b17023SJohn Marino declaration, for example) use it -- otherwise, start with a
759*e4b17023SJohn Marino one-byte alignment. */
760*e4b17023SJohn Marino rli->record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
761*e4b17023SJohn Marino rli->unpacked_align = rli->record_align;
762*e4b17023SJohn Marino rli->offset_align = MAX (rli->record_align, BIGGEST_ALIGNMENT);
763*e4b17023SJohn Marino
764*e4b17023SJohn Marino #ifdef STRUCTURE_SIZE_BOUNDARY
765*e4b17023SJohn Marino /* Packed structures don't need to have minimum size. */
766*e4b17023SJohn Marino if (! TYPE_PACKED (t))
767*e4b17023SJohn Marino {
768*e4b17023SJohn Marino unsigned tmp;
769*e4b17023SJohn Marino
770*e4b17023SJohn Marino /* #pragma pack overrides STRUCTURE_SIZE_BOUNDARY. */
771*e4b17023SJohn Marino tmp = (unsigned) STRUCTURE_SIZE_BOUNDARY;
772*e4b17023SJohn Marino if (maximum_field_alignment != 0)
773*e4b17023SJohn Marino tmp = MIN (tmp, maximum_field_alignment);
774*e4b17023SJohn Marino rli->record_align = MAX (rli->record_align, tmp);
775*e4b17023SJohn Marino }
776*e4b17023SJohn Marino #endif
777*e4b17023SJohn Marino
778*e4b17023SJohn Marino rli->offset = size_zero_node;
779*e4b17023SJohn Marino rli->bitpos = bitsize_zero_node;
780*e4b17023SJohn Marino rli->prev_field = 0;
781*e4b17023SJohn Marino rli->pending_statics = NULL;
782*e4b17023SJohn Marino rli->packed_maybe_necessary = 0;
783*e4b17023SJohn Marino rli->remaining_in_alignment = 0;
784*e4b17023SJohn Marino
785*e4b17023SJohn Marino return rli;
786*e4b17023SJohn Marino }
787*e4b17023SJohn Marino
788*e4b17023SJohn Marino /* These four routines perform computations that convert between
789*e4b17023SJohn Marino the offset/bitpos forms and byte and bit offsets. */
790*e4b17023SJohn Marino
791*e4b17023SJohn Marino tree
bit_from_pos(tree offset,tree bitpos)792*e4b17023SJohn Marino bit_from_pos (tree offset, tree bitpos)
793*e4b17023SJohn Marino {
794*e4b17023SJohn Marino return size_binop (PLUS_EXPR, bitpos,
795*e4b17023SJohn Marino size_binop (MULT_EXPR,
796*e4b17023SJohn Marino fold_convert (bitsizetype, offset),
797*e4b17023SJohn Marino bitsize_unit_node));
798*e4b17023SJohn Marino }
799*e4b17023SJohn Marino
800*e4b17023SJohn Marino tree
byte_from_pos(tree offset,tree bitpos)801*e4b17023SJohn Marino byte_from_pos (tree offset, tree bitpos)
802*e4b17023SJohn Marino {
803*e4b17023SJohn Marino return size_binop (PLUS_EXPR, offset,
804*e4b17023SJohn Marino fold_convert (sizetype,
805*e4b17023SJohn Marino size_binop (TRUNC_DIV_EXPR, bitpos,
806*e4b17023SJohn Marino bitsize_unit_node)));
807*e4b17023SJohn Marino }
808*e4b17023SJohn Marino
809*e4b17023SJohn Marino void
pos_from_bit(tree * poffset,tree * pbitpos,unsigned int off_align,tree pos)810*e4b17023SJohn Marino pos_from_bit (tree *poffset, tree *pbitpos, unsigned int off_align,
811*e4b17023SJohn Marino tree pos)
812*e4b17023SJohn Marino {
813*e4b17023SJohn Marino *poffset = size_binop (MULT_EXPR,
814*e4b17023SJohn Marino fold_convert (sizetype,
815*e4b17023SJohn Marino size_binop (FLOOR_DIV_EXPR, pos,
816*e4b17023SJohn Marino bitsize_int (off_align))),
817*e4b17023SJohn Marino size_int (off_align / BITS_PER_UNIT));
818*e4b17023SJohn Marino *pbitpos = size_binop (FLOOR_MOD_EXPR, pos, bitsize_int (off_align));
819*e4b17023SJohn Marino }
820*e4b17023SJohn Marino
821*e4b17023SJohn Marino /* Given a pointer to bit and byte offsets and an offset alignment,
822*e4b17023SJohn Marino normalize the offsets so they are within the alignment. */
823*e4b17023SJohn Marino
824*e4b17023SJohn Marino void
normalize_offset(tree * poffset,tree * pbitpos,unsigned int off_align)825*e4b17023SJohn Marino normalize_offset (tree *poffset, tree *pbitpos, unsigned int off_align)
826*e4b17023SJohn Marino {
827*e4b17023SJohn Marino /* If the bit position is now larger than it should be, adjust it
828*e4b17023SJohn Marino downwards. */
829*e4b17023SJohn Marino if (compare_tree_int (*pbitpos, off_align) >= 0)
830*e4b17023SJohn Marino {
831*e4b17023SJohn Marino tree extra_aligns = size_binop (FLOOR_DIV_EXPR, *pbitpos,
832*e4b17023SJohn Marino bitsize_int (off_align));
833*e4b17023SJohn Marino
834*e4b17023SJohn Marino *poffset
835*e4b17023SJohn Marino = size_binop (PLUS_EXPR, *poffset,
836*e4b17023SJohn Marino size_binop (MULT_EXPR,
837*e4b17023SJohn Marino fold_convert (sizetype, extra_aligns),
838*e4b17023SJohn Marino size_int (off_align / BITS_PER_UNIT)));
839*e4b17023SJohn Marino
840*e4b17023SJohn Marino *pbitpos
841*e4b17023SJohn Marino = size_binop (FLOOR_MOD_EXPR, *pbitpos, bitsize_int (off_align));
842*e4b17023SJohn Marino }
843*e4b17023SJohn Marino }
844*e4b17023SJohn Marino
845*e4b17023SJohn Marino /* Print debugging information about the information in RLI. */
846*e4b17023SJohn Marino
847*e4b17023SJohn Marino DEBUG_FUNCTION void
debug_rli(record_layout_info rli)848*e4b17023SJohn Marino debug_rli (record_layout_info rli)
849*e4b17023SJohn Marino {
850*e4b17023SJohn Marino print_node_brief (stderr, "type", rli->t, 0);
851*e4b17023SJohn Marino print_node_brief (stderr, "\noffset", rli->offset, 0);
852*e4b17023SJohn Marino print_node_brief (stderr, " bitpos", rli->bitpos, 0);
853*e4b17023SJohn Marino
854*e4b17023SJohn Marino fprintf (stderr, "\naligns: rec = %u, unpack = %u, off = %u\n",
855*e4b17023SJohn Marino rli->record_align, rli->unpacked_align,
856*e4b17023SJohn Marino rli->offset_align);
857*e4b17023SJohn Marino
858*e4b17023SJohn Marino /* The ms_struct code is the only that uses this. */
859*e4b17023SJohn Marino if (targetm.ms_bitfield_layout_p (rli->t))
860*e4b17023SJohn Marino fprintf (stderr, "remaining in alignment = %u\n", rli->remaining_in_alignment);
861*e4b17023SJohn Marino
862*e4b17023SJohn Marino if (rli->packed_maybe_necessary)
863*e4b17023SJohn Marino fprintf (stderr, "packed may be necessary\n");
864*e4b17023SJohn Marino
865*e4b17023SJohn Marino if (!VEC_empty (tree, rli->pending_statics))
866*e4b17023SJohn Marino {
867*e4b17023SJohn Marino fprintf (stderr, "pending statics:\n");
868*e4b17023SJohn Marino debug_vec_tree (rli->pending_statics);
869*e4b17023SJohn Marino }
870*e4b17023SJohn Marino }
871*e4b17023SJohn Marino
872*e4b17023SJohn Marino /* Given an RLI with a possibly-incremented BITPOS, adjust OFFSET and
873*e4b17023SJohn Marino BITPOS if necessary to keep BITPOS below OFFSET_ALIGN. */
874*e4b17023SJohn Marino
875*e4b17023SJohn Marino void
normalize_rli(record_layout_info rli)876*e4b17023SJohn Marino normalize_rli (record_layout_info rli)
877*e4b17023SJohn Marino {
878*e4b17023SJohn Marino normalize_offset (&rli->offset, &rli->bitpos, rli->offset_align);
879*e4b17023SJohn Marino }
880*e4b17023SJohn Marino
881*e4b17023SJohn Marino /* Returns the size in bytes allocated so far. */
882*e4b17023SJohn Marino
883*e4b17023SJohn Marino tree
rli_size_unit_so_far(record_layout_info rli)884*e4b17023SJohn Marino rli_size_unit_so_far (record_layout_info rli)
885*e4b17023SJohn Marino {
886*e4b17023SJohn Marino return byte_from_pos (rli->offset, rli->bitpos);
887*e4b17023SJohn Marino }
888*e4b17023SJohn Marino
889*e4b17023SJohn Marino /* Returns the size in bits allocated so far. */
890*e4b17023SJohn Marino
891*e4b17023SJohn Marino tree
rli_size_so_far(record_layout_info rli)892*e4b17023SJohn Marino rli_size_so_far (record_layout_info rli)
893*e4b17023SJohn Marino {
894*e4b17023SJohn Marino return bit_from_pos (rli->offset, rli->bitpos);
895*e4b17023SJohn Marino }
896*e4b17023SJohn Marino
897*e4b17023SJohn Marino /* FIELD is about to be added to RLI->T. The alignment (in bits) of
898*e4b17023SJohn Marino the next available location within the record is given by KNOWN_ALIGN.
899*e4b17023SJohn Marino Update the variable alignment fields in RLI, and return the alignment
900*e4b17023SJohn Marino to give the FIELD. */
901*e4b17023SJohn Marino
902*e4b17023SJohn Marino unsigned int
update_alignment_for_field(record_layout_info rli,tree field,unsigned int known_align)903*e4b17023SJohn Marino update_alignment_for_field (record_layout_info rli, tree field,
904*e4b17023SJohn Marino unsigned int known_align)
905*e4b17023SJohn Marino {
906*e4b17023SJohn Marino /* The alignment required for FIELD. */
907*e4b17023SJohn Marino unsigned int desired_align;
908*e4b17023SJohn Marino /* The type of this field. */
909*e4b17023SJohn Marino tree type = TREE_TYPE (field);
910*e4b17023SJohn Marino /* True if the field was explicitly aligned by the user. */
911*e4b17023SJohn Marino bool user_align;
912*e4b17023SJohn Marino bool is_bitfield;
913*e4b17023SJohn Marino
914*e4b17023SJohn Marino /* Do not attempt to align an ERROR_MARK node */
915*e4b17023SJohn Marino if (TREE_CODE (type) == ERROR_MARK)
916*e4b17023SJohn Marino return 0;
917*e4b17023SJohn Marino
918*e4b17023SJohn Marino /* Lay out the field so we know what alignment it needs. */
919*e4b17023SJohn Marino layout_decl (field, known_align);
920*e4b17023SJohn Marino desired_align = DECL_ALIGN (field);
921*e4b17023SJohn Marino user_align = DECL_USER_ALIGN (field);
922*e4b17023SJohn Marino
923*e4b17023SJohn Marino is_bitfield = (type != error_mark_node
924*e4b17023SJohn Marino && DECL_BIT_FIELD_TYPE (field)
925*e4b17023SJohn Marino && ! integer_zerop (TYPE_SIZE (type)));
926*e4b17023SJohn Marino
927*e4b17023SJohn Marino /* Record must have at least as much alignment as any field.
928*e4b17023SJohn Marino Otherwise, the alignment of the field within the record is
929*e4b17023SJohn Marino meaningless. */
930*e4b17023SJohn Marino if (targetm.ms_bitfield_layout_p (rli->t))
931*e4b17023SJohn Marino {
932*e4b17023SJohn Marino /* Here, the alignment of the underlying type of a bitfield can
933*e4b17023SJohn Marino affect the alignment of a record; even a zero-sized field
934*e4b17023SJohn Marino can do this. The alignment should be to the alignment of
935*e4b17023SJohn Marino the type, except that for zero-size bitfields this only
936*e4b17023SJohn Marino applies if there was an immediately prior, nonzero-size
937*e4b17023SJohn Marino bitfield. (That's the way it is, experimentally.) */
938*e4b17023SJohn Marino if ((!is_bitfield && !DECL_PACKED (field))
939*e4b17023SJohn Marino || ((DECL_SIZE (field) == NULL_TREE
940*e4b17023SJohn Marino || !integer_zerop (DECL_SIZE (field)))
941*e4b17023SJohn Marino ? !DECL_PACKED (field)
942*e4b17023SJohn Marino : (rli->prev_field
943*e4b17023SJohn Marino && DECL_BIT_FIELD_TYPE (rli->prev_field)
944*e4b17023SJohn Marino && ! integer_zerop (DECL_SIZE (rli->prev_field)))))
945*e4b17023SJohn Marino {
946*e4b17023SJohn Marino unsigned int type_align = TYPE_ALIGN (type);
947*e4b17023SJohn Marino type_align = MAX (type_align, desired_align);
948*e4b17023SJohn Marino if (maximum_field_alignment != 0)
949*e4b17023SJohn Marino type_align = MIN (type_align, maximum_field_alignment);
950*e4b17023SJohn Marino rli->record_align = MAX (rli->record_align, type_align);
951*e4b17023SJohn Marino rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
952*e4b17023SJohn Marino }
953*e4b17023SJohn Marino }
954*e4b17023SJohn Marino #ifdef PCC_BITFIELD_TYPE_MATTERS
955*e4b17023SJohn Marino else if (is_bitfield && PCC_BITFIELD_TYPE_MATTERS)
956*e4b17023SJohn Marino {
957*e4b17023SJohn Marino /* Named bit-fields cause the entire structure to have the
958*e4b17023SJohn Marino alignment implied by their type. Some targets also apply the same
959*e4b17023SJohn Marino rules to unnamed bitfields. */
960*e4b17023SJohn Marino if (DECL_NAME (field) != 0
961*e4b17023SJohn Marino || targetm.align_anon_bitfield ())
962*e4b17023SJohn Marino {
963*e4b17023SJohn Marino unsigned int type_align = TYPE_ALIGN (type);
964*e4b17023SJohn Marino
965*e4b17023SJohn Marino #ifdef ADJUST_FIELD_ALIGN
966*e4b17023SJohn Marino if (! TYPE_USER_ALIGN (type))
967*e4b17023SJohn Marino type_align = ADJUST_FIELD_ALIGN (field, type_align);
968*e4b17023SJohn Marino #endif
969*e4b17023SJohn Marino
970*e4b17023SJohn Marino /* Targets might chose to handle unnamed and hence possibly
971*e4b17023SJohn Marino zero-width bitfield. Those are not influenced by #pragmas
972*e4b17023SJohn Marino or packed attributes. */
973*e4b17023SJohn Marino if (integer_zerop (DECL_SIZE (field)))
974*e4b17023SJohn Marino {
975*e4b17023SJohn Marino if (initial_max_fld_align)
976*e4b17023SJohn Marino type_align = MIN (type_align,
977*e4b17023SJohn Marino initial_max_fld_align * BITS_PER_UNIT);
978*e4b17023SJohn Marino }
979*e4b17023SJohn Marino else if (maximum_field_alignment != 0)
980*e4b17023SJohn Marino type_align = MIN (type_align, maximum_field_alignment);
981*e4b17023SJohn Marino else if (DECL_PACKED (field))
982*e4b17023SJohn Marino type_align = MIN (type_align, BITS_PER_UNIT);
983*e4b17023SJohn Marino
984*e4b17023SJohn Marino /* The alignment of the record is increased to the maximum
985*e4b17023SJohn Marino of the current alignment, the alignment indicated on the
986*e4b17023SJohn Marino field (i.e., the alignment specified by an __aligned__
987*e4b17023SJohn Marino attribute), and the alignment indicated by the type of
988*e4b17023SJohn Marino the field. */
989*e4b17023SJohn Marino rli->record_align = MAX (rli->record_align, desired_align);
990*e4b17023SJohn Marino rli->record_align = MAX (rli->record_align, type_align);
991*e4b17023SJohn Marino
992*e4b17023SJohn Marino if (warn_packed)
993*e4b17023SJohn Marino rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
994*e4b17023SJohn Marino user_align |= TYPE_USER_ALIGN (type);
995*e4b17023SJohn Marino }
996*e4b17023SJohn Marino }
997*e4b17023SJohn Marino #endif
998*e4b17023SJohn Marino else
999*e4b17023SJohn Marino {
1000*e4b17023SJohn Marino rli->record_align = MAX (rli->record_align, desired_align);
1001*e4b17023SJohn Marino rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
1002*e4b17023SJohn Marino }
1003*e4b17023SJohn Marino
1004*e4b17023SJohn Marino TYPE_USER_ALIGN (rli->t) |= user_align;
1005*e4b17023SJohn Marino
1006*e4b17023SJohn Marino return desired_align;
1007*e4b17023SJohn Marino }
1008*e4b17023SJohn Marino
1009*e4b17023SJohn Marino /* Called from place_field to handle unions. */
1010*e4b17023SJohn Marino
1011*e4b17023SJohn Marino static void
place_union_field(record_layout_info rli,tree field)1012*e4b17023SJohn Marino place_union_field (record_layout_info rli, tree field)
1013*e4b17023SJohn Marino {
1014*e4b17023SJohn Marino update_alignment_for_field (rli, field, /*known_align=*/0);
1015*e4b17023SJohn Marino
1016*e4b17023SJohn Marino DECL_FIELD_OFFSET (field) = size_zero_node;
1017*e4b17023SJohn Marino DECL_FIELD_BIT_OFFSET (field) = bitsize_zero_node;
1018*e4b17023SJohn Marino SET_DECL_OFFSET_ALIGN (field, BIGGEST_ALIGNMENT);
1019*e4b17023SJohn Marino
1020*e4b17023SJohn Marino /* If this is an ERROR_MARK return *after* having set the
1021*e4b17023SJohn Marino field at the start of the union. This helps when parsing
1022*e4b17023SJohn Marino invalid fields. */
1023*e4b17023SJohn Marino if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK)
1024*e4b17023SJohn Marino return;
1025*e4b17023SJohn Marino
1026*e4b17023SJohn Marino /* We assume the union's size will be a multiple of a byte so we don't
1027*e4b17023SJohn Marino bother with BITPOS. */
1028*e4b17023SJohn Marino if (TREE_CODE (rli->t) == UNION_TYPE)
1029*e4b17023SJohn Marino rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field));
1030*e4b17023SJohn Marino else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE)
1031*e4b17023SJohn Marino rli->offset = fold_build3 (COND_EXPR, sizetype, DECL_QUALIFIER (field),
1032*e4b17023SJohn Marino DECL_SIZE_UNIT (field), rli->offset);
1033*e4b17023SJohn Marino }
1034*e4b17023SJohn Marino
1035*e4b17023SJohn Marino #if defined (PCC_BITFIELD_TYPE_MATTERS) || defined (BITFIELD_NBYTES_LIMITED)
1036*e4b17023SJohn Marino /* A bitfield of SIZE with a required access alignment of ALIGN is allocated
1037*e4b17023SJohn Marino at BYTE_OFFSET / BIT_OFFSET. Return nonzero if the field would span more
1038*e4b17023SJohn Marino units of alignment than the underlying TYPE. */
1039*e4b17023SJohn Marino static int
excess_unit_span(HOST_WIDE_INT byte_offset,HOST_WIDE_INT bit_offset,HOST_WIDE_INT size,HOST_WIDE_INT align,tree type)1040*e4b17023SJohn Marino excess_unit_span (HOST_WIDE_INT byte_offset, HOST_WIDE_INT bit_offset,
1041*e4b17023SJohn Marino HOST_WIDE_INT size, HOST_WIDE_INT align, tree type)
1042*e4b17023SJohn Marino {
1043*e4b17023SJohn Marino /* Note that the calculation of OFFSET might overflow; we calculate it so
1044*e4b17023SJohn Marino that we still get the right result as long as ALIGN is a power of two. */
1045*e4b17023SJohn Marino unsigned HOST_WIDE_INT offset = byte_offset * BITS_PER_UNIT + bit_offset;
1046*e4b17023SJohn Marino
1047*e4b17023SJohn Marino offset = offset % align;
1048*e4b17023SJohn Marino return ((offset + size + align - 1) / align
1049*e4b17023SJohn Marino > ((unsigned HOST_WIDE_INT) tree_low_cst (TYPE_SIZE (type), 1)
1050*e4b17023SJohn Marino / align));
1051*e4b17023SJohn Marino }
1052*e4b17023SJohn Marino #endif
1053*e4b17023SJohn Marino
1054*e4b17023SJohn Marino /* RLI contains information about the layout of a RECORD_TYPE. FIELD
1055*e4b17023SJohn Marino is a FIELD_DECL to be added after those fields already present in
1056*e4b17023SJohn Marino T. (FIELD is not actually added to the TYPE_FIELDS list here;
1057*e4b17023SJohn Marino callers that desire that behavior must manually perform that step.) */
1058*e4b17023SJohn Marino
1059*e4b17023SJohn Marino void
place_field(record_layout_info rli,tree field)1060*e4b17023SJohn Marino place_field (record_layout_info rli, tree field)
1061*e4b17023SJohn Marino {
1062*e4b17023SJohn Marino /* The alignment required for FIELD. */
1063*e4b17023SJohn Marino unsigned int desired_align;
1064*e4b17023SJohn Marino /* The alignment FIELD would have if we just dropped it into the
1065*e4b17023SJohn Marino record as it presently stands. */
1066*e4b17023SJohn Marino unsigned int known_align;
1067*e4b17023SJohn Marino unsigned int actual_align;
1068*e4b17023SJohn Marino /* The type of this field. */
1069*e4b17023SJohn Marino tree type = TREE_TYPE (field);
1070*e4b17023SJohn Marino
1071*e4b17023SJohn Marino gcc_assert (TREE_CODE (field) != ERROR_MARK);
1072*e4b17023SJohn Marino
1073*e4b17023SJohn Marino /* If FIELD is static, then treat it like a separate variable, not
1074*e4b17023SJohn Marino really like a structure field. If it is a FUNCTION_DECL, it's a
1075*e4b17023SJohn Marino method. In both cases, all we do is lay out the decl, and we do
1076*e4b17023SJohn Marino it *after* the record is laid out. */
1077*e4b17023SJohn Marino if (TREE_CODE (field) == VAR_DECL)
1078*e4b17023SJohn Marino {
1079*e4b17023SJohn Marino VEC_safe_push (tree, gc, rli->pending_statics, field);
1080*e4b17023SJohn Marino return;
1081*e4b17023SJohn Marino }
1082*e4b17023SJohn Marino
1083*e4b17023SJohn Marino /* Enumerators and enum types which are local to this class need not
1084*e4b17023SJohn Marino be laid out. Likewise for initialized constant fields. */
1085*e4b17023SJohn Marino else if (TREE_CODE (field) != FIELD_DECL)
1086*e4b17023SJohn Marino return;
1087*e4b17023SJohn Marino
1088*e4b17023SJohn Marino /* Unions are laid out very differently than records, so split
1089*e4b17023SJohn Marino that code off to another function. */
1090*e4b17023SJohn Marino else if (TREE_CODE (rli->t) != RECORD_TYPE)
1091*e4b17023SJohn Marino {
1092*e4b17023SJohn Marino place_union_field (rli, field);
1093*e4b17023SJohn Marino return;
1094*e4b17023SJohn Marino }
1095*e4b17023SJohn Marino
1096*e4b17023SJohn Marino else if (TREE_CODE (type) == ERROR_MARK)
1097*e4b17023SJohn Marino {
1098*e4b17023SJohn Marino /* Place this field at the current allocation position, so we
1099*e4b17023SJohn Marino maintain monotonicity. */
1100*e4b17023SJohn Marino DECL_FIELD_OFFSET (field) = rli->offset;
1101*e4b17023SJohn Marino DECL_FIELD_BIT_OFFSET (field) = rli->bitpos;
1102*e4b17023SJohn Marino SET_DECL_OFFSET_ALIGN (field, rli->offset_align);
1103*e4b17023SJohn Marino return;
1104*e4b17023SJohn Marino }
1105*e4b17023SJohn Marino
1106*e4b17023SJohn Marino /* Work out the known alignment so far. Note that A & (-A) is the
1107*e4b17023SJohn Marino value of the least-significant bit in A that is one. */
1108*e4b17023SJohn Marino if (! integer_zerop (rli->bitpos))
1109*e4b17023SJohn Marino known_align = (tree_low_cst (rli->bitpos, 1)
1110*e4b17023SJohn Marino & - tree_low_cst (rli->bitpos, 1));
1111*e4b17023SJohn Marino else if (integer_zerop (rli->offset))
1112*e4b17023SJohn Marino known_align = 0;
1113*e4b17023SJohn Marino else if (host_integerp (rli->offset, 1))
1114*e4b17023SJohn Marino known_align = (BITS_PER_UNIT
1115*e4b17023SJohn Marino * (tree_low_cst (rli->offset, 1)
1116*e4b17023SJohn Marino & - tree_low_cst (rli->offset, 1)));
1117*e4b17023SJohn Marino else
1118*e4b17023SJohn Marino known_align = rli->offset_align;
1119*e4b17023SJohn Marino
1120*e4b17023SJohn Marino desired_align = update_alignment_for_field (rli, field, known_align);
1121*e4b17023SJohn Marino if (known_align == 0)
1122*e4b17023SJohn Marino known_align = MAX (BIGGEST_ALIGNMENT, rli->record_align);
1123*e4b17023SJohn Marino
1124*e4b17023SJohn Marino if (warn_packed && DECL_PACKED (field))
1125*e4b17023SJohn Marino {
1126*e4b17023SJohn Marino if (known_align >= TYPE_ALIGN (type))
1127*e4b17023SJohn Marino {
1128*e4b17023SJohn Marino if (TYPE_ALIGN (type) > desired_align)
1129*e4b17023SJohn Marino {
1130*e4b17023SJohn Marino if (STRICT_ALIGNMENT)
1131*e4b17023SJohn Marino warning (OPT_Wattributes, "packed attribute causes "
1132*e4b17023SJohn Marino "inefficient alignment for %q+D", field);
1133*e4b17023SJohn Marino /* Don't warn if DECL_PACKED was set by the type. */
1134*e4b17023SJohn Marino else if (!TYPE_PACKED (rli->t))
1135*e4b17023SJohn Marino warning (OPT_Wattributes, "packed attribute is "
1136*e4b17023SJohn Marino "unnecessary for %q+D", field);
1137*e4b17023SJohn Marino }
1138*e4b17023SJohn Marino }
1139*e4b17023SJohn Marino else
1140*e4b17023SJohn Marino rli->packed_maybe_necessary = 1;
1141*e4b17023SJohn Marino }
1142*e4b17023SJohn Marino
1143*e4b17023SJohn Marino /* Does this field automatically have alignment it needs by virtue
1144*e4b17023SJohn Marino of the fields that precede it and the record's own alignment? */
1145*e4b17023SJohn Marino if (known_align < desired_align)
1146*e4b17023SJohn Marino {
1147*e4b17023SJohn Marino /* No, we need to skip space before this field.
1148*e4b17023SJohn Marino Bump the cumulative size to multiple of field alignment. */
1149*e4b17023SJohn Marino
1150*e4b17023SJohn Marino if (!targetm.ms_bitfield_layout_p (rli->t)
1151*e4b17023SJohn Marino && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION)
1152*e4b17023SJohn Marino warning (OPT_Wpadded, "padding struct to align %q+D", field);
1153*e4b17023SJohn Marino
1154*e4b17023SJohn Marino /* If the alignment is still within offset_align, just align
1155*e4b17023SJohn Marino the bit position. */
1156*e4b17023SJohn Marino if (desired_align < rli->offset_align)
1157*e4b17023SJohn Marino rli->bitpos = round_up (rli->bitpos, desired_align);
1158*e4b17023SJohn Marino else
1159*e4b17023SJohn Marino {
1160*e4b17023SJohn Marino /* First adjust OFFSET by the partial bits, then align. */
1161*e4b17023SJohn Marino rli->offset
1162*e4b17023SJohn Marino = size_binop (PLUS_EXPR, rli->offset,
1163*e4b17023SJohn Marino fold_convert (sizetype,
1164*e4b17023SJohn Marino size_binop (CEIL_DIV_EXPR, rli->bitpos,
1165*e4b17023SJohn Marino bitsize_unit_node)));
1166*e4b17023SJohn Marino rli->bitpos = bitsize_zero_node;
1167*e4b17023SJohn Marino
1168*e4b17023SJohn Marino rli->offset = round_up (rli->offset, desired_align / BITS_PER_UNIT);
1169*e4b17023SJohn Marino }
1170*e4b17023SJohn Marino
1171*e4b17023SJohn Marino if (! TREE_CONSTANT (rli->offset))
1172*e4b17023SJohn Marino rli->offset_align = desired_align;
1173*e4b17023SJohn Marino if (targetm.ms_bitfield_layout_p (rli->t))
1174*e4b17023SJohn Marino rli->prev_field = NULL;
1175*e4b17023SJohn Marino }
1176*e4b17023SJohn Marino
1177*e4b17023SJohn Marino /* Handle compatibility with PCC. Note that if the record has any
1178*e4b17023SJohn Marino variable-sized fields, we need not worry about compatibility. */
1179*e4b17023SJohn Marino #ifdef PCC_BITFIELD_TYPE_MATTERS
1180*e4b17023SJohn Marino if (PCC_BITFIELD_TYPE_MATTERS
1181*e4b17023SJohn Marino && ! targetm.ms_bitfield_layout_p (rli->t)
1182*e4b17023SJohn Marino && TREE_CODE (field) == FIELD_DECL
1183*e4b17023SJohn Marino && type != error_mark_node
1184*e4b17023SJohn Marino && DECL_BIT_FIELD (field)
1185*e4b17023SJohn Marino && (! DECL_PACKED (field)
1186*e4b17023SJohn Marino /* Enter for these packed fields only to issue a warning. */
1187*e4b17023SJohn Marino || TYPE_ALIGN (type) <= BITS_PER_UNIT)
1188*e4b17023SJohn Marino && maximum_field_alignment == 0
1189*e4b17023SJohn Marino && ! integer_zerop (DECL_SIZE (field))
1190*e4b17023SJohn Marino && host_integerp (DECL_SIZE (field), 1)
1191*e4b17023SJohn Marino && host_integerp (rli->offset, 1)
1192*e4b17023SJohn Marino && host_integerp (TYPE_SIZE (type), 1))
1193*e4b17023SJohn Marino {
1194*e4b17023SJohn Marino unsigned int type_align = TYPE_ALIGN (type);
1195*e4b17023SJohn Marino tree dsize = DECL_SIZE (field);
1196*e4b17023SJohn Marino HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
1197*e4b17023SJohn Marino HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
1198*e4b17023SJohn Marino HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
1199*e4b17023SJohn Marino
1200*e4b17023SJohn Marino #ifdef ADJUST_FIELD_ALIGN
1201*e4b17023SJohn Marino if (! TYPE_USER_ALIGN (type))
1202*e4b17023SJohn Marino type_align = ADJUST_FIELD_ALIGN (field, type_align);
1203*e4b17023SJohn Marino #endif
1204*e4b17023SJohn Marino
1205*e4b17023SJohn Marino /* A bit field may not span more units of alignment of its type
1206*e4b17023SJohn Marino than its type itself. Advance to next boundary if necessary. */
1207*e4b17023SJohn Marino if (excess_unit_span (offset, bit_offset, field_size, type_align, type))
1208*e4b17023SJohn Marino {
1209*e4b17023SJohn Marino if (DECL_PACKED (field))
1210*e4b17023SJohn Marino {
1211*e4b17023SJohn Marino if (warn_packed_bitfield_compat == 1)
1212*e4b17023SJohn Marino inform
1213*e4b17023SJohn Marino (input_location,
1214*e4b17023SJohn Marino "offset of packed bit-field %qD has changed in GCC 4.4",
1215*e4b17023SJohn Marino field);
1216*e4b17023SJohn Marino }
1217*e4b17023SJohn Marino else
1218*e4b17023SJohn Marino rli->bitpos = round_up (rli->bitpos, type_align);
1219*e4b17023SJohn Marino }
1220*e4b17023SJohn Marino
1221*e4b17023SJohn Marino if (! DECL_PACKED (field))
1222*e4b17023SJohn Marino TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type);
1223*e4b17023SJohn Marino }
1224*e4b17023SJohn Marino #endif
1225*e4b17023SJohn Marino
1226*e4b17023SJohn Marino #ifdef BITFIELD_NBYTES_LIMITED
1227*e4b17023SJohn Marino if (BITFIELD_NBYTES_LIMITED
1228*e4b17023SJohn Marino && ! targetm.ms_bitfield_layout_p (rli->t)
1229*e4b17023SJohn Marino && TREE_CODE (field) == FIELD_DECL
1230*e4b17023SJohn Marino && type != error_mark_node
1231*e4b17023SJohn Marino && DECL_BIT_FIELD_TYPE (field)
1232*e4b17023SJohn Marino && ! DECL_PACKED (field)
1233*e4b17023SJohn Marino && ! integer_zerop (DECL_SIZE (field))
1234*e4b17023SJohn Marino && host_integerp (DECL_SIZE (field), 1)
1235*e4b17023SJohn Marino && host_integerp (rli->offset, 1)
1236*e4b17023SJohn Marino && host_integerp (TYPE_SIZE (type), 1))
1237*e4b17023SJohn Marino {
1238*e4b17023SJohn Marino unsigned int type_align = TYPE_ALIGN (type);
1239*e4b17023SJohn Marino tree dsize = DECL_SIZE (field);
1240*e4b17023SJohn Marino HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
1241*e4b17023SJohn Marino HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
1242*e4b17023SJohn Marino HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
1243*e4b17023SJohn Marino
1244*e4b17023SJohn Marino #ifdef ADJUST_FIELD_ALIGN
1245*e4b17023SJohn Marino if (! TYPE_USER_ALIGN (type))
1246*e4b17023SJohn Marino type_align = ADJUST_FIELD_ALIGN (field, type_align);
1247*e4b17023SJohn Marino #endif
1248*e4b17023SJohn Marino
1249*e4b17023SJohn Marino if (maximum_field_alignment != 0)
1250*e4b17023SJohn Marino type_align = MIN (type_align, maximum_field_alignment);
1251*e4b17023SJohn Marino /* ??? This test is opposite the test in the containing if
1252*e4b17023SJohn Marino statement, so this code is unreachable currently. */
1253*e4b17023SJohn Marino else if (DECL_PACKED (field))
1254*e4b17023SJohn Marino type_align = MIN (type_align, BITS_PER_UNIT);
1255*e4b17023SJohn Marino
1256*e4b17023SJohn Marino /* A bit field may not span the unit of alignment of its type.
1257*e4b17023SJohn Marino Advance to next boundary if necessary. */
1258*e4b17023SJohn Marino if (excess_unit_span (offset, bit_offset, field_size, type_align, type))
1259*e4b17023SJohn Marino rli->bitpos = round_up (rli->bitpos, type_align);
1260*e4b17023SJohn Marino
1261*e4b17023SJohn Marino TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type);
1262*e4b17023SJohn Marino }
1263*e4b17023SJohn Marino #endif
1264*e4b17023SJohn Marino
1265*e4b17023SJohn Marino /* See the docs for TARGET_MS_BITFIELD_LAYOUT_P for details.
1266*e4b17023SJohn Marino A subtlety:
1267*e4b17023SJohn Marino When a bit field is inserted into a packed record, the whole
1268*e4b17023SJohn Marino size of the underlying type is used by one or more same-size
1269*e4b17023SJohn Marino adjacent bitfields. (That is, if its long:3, 32 bits is
1270*e4b17023SJohn Marino used in the record, and any additional adjacent long bitfields are
1271*e4b17023SJohn Marino packed into the same chunk of 32 bits. However, if the size
1272*e4b17023SJohn Marino changes, a new field of that size is allocated.) In an unpacked
1273*e4b17023SJohn Marino record, this is the same as using alignment, but not equivalent
1274*e4b17023SJohn Marino when packing.
1275*e4b17023SJohn Marino
1276*e4b17023SJohn Marino Note: for compatibility, we use the type size, not the type alignment
1277*e4b17023SJohn Marino to determine alignment, since that matches the documentation */
1278*e4b17023SJohn Marino
1279*e4b17023SJohn Marino if (targetm.ms_bitfield_layout_p (rli->t))
1280*e4b17023SJohn Marino {
1281*e4b17023SJohn Marino tree prev_saved = rli->prev_field;
1282*e4b17023SJohn Marino tree prev_type = prev_saved ? DECL_BIT_FIELD_TYPE (prev_saved) : NULL;
1283*e4b17023SJohn Marino
1284*e4b17023SJohn Marino /* This is a bitfield if it exists. */
1285*e4b17023SJohn Marino if (rli->prev_field)
1286*e4b17023SJohn Marino {
1287*e4b17023SJohn Marino /* If both are bitfields, nonzero, and the same size, this is
1288*e4b17023SJohn Marino the middle of a run. Zero declared size fields are special
1289*e4b17023SJohn Marino and handled as "end of run". (Note: it's nonzero declared
1290*e4b17023SJohn Marino size, but equal type sizes!) (Since we know that both
1291*e4b17023SJohn Marino the current and previous fields are bitfields by the
1292*e4b17023SJohn Marino time we check it, DECL_SIZE must be present for both.) */
1293*e4b17023SJohn Marino if (DECL_BIT_FIELD_TYPE (field)
1294*e4b17023SJohn Marino && !integer_zerop (DECL_SIZE (field))
1295*e4b17023SJohn Marino && !integer_zerop (DECL_SIZE (rli->prev_field))
1296*e4b17023SJohn Marino && host_integerp (DECL_SIZE (rli->prev_field), 0)
1297*e4b17023SJohn Marino && host_integerp (TYPE_SIZE (type), 0)
1298*e4b17023SJohn Marino && simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (prev_type)))
1299*e4b17023SJohn Marino {
1300*e4b17023SJohn Marino /* We're in the middle of a run of equal type size fields; make
1301*e4b17023SJohn Marino sure we realign if we run out of bits. (Not decl size,
1302*e4b17023SJohn Marino type size!) */
1303*e4b17023SJohn Marino HOST_WIDE_INT bitsize = tree_low_cst (DECL_SIZE (field), 1);
1304*e4b17023SJohn Marino
1305*e4b17023SJohn Marino if (rli->remaining_in_alignment < bitsize)
1306*e4b17023SJohn Marino {
1307*e4b17023SJohn Marino HOST_WIDE_INT typesize = tree_low_cst (TYPE_SIZE (type), 1);
1308*e4b17023SJohn Marino
1309*e4b17023SJohn Marino /* out of bits; bump up to next 'word'. */
1310*e4b17023SJohn Marino rli->bitpos
1311*e4b17023SJohn Marino = size_binop (PLUS_EXPR, rli->bitpos,
1312*e4b17023SJohn Marino bitsize_int (rli->remaining_in_alignment));
1313*e4b17023SJohn Marino rli->prev_field = field;
1314*e4b17023SJohn Marino if (typesize < bitsize)
1315*e4b17023SJohn Marino rli->remaining_in_alignment = 0;
1316*e4b17023SJohn Marino else
1317*e4b17023SJohn Marino rli->remaining_in_alignment = typesize - bitsize;
1318*e4b17023SJohn Marino }
1319*e4b17023SJohn Marino else
1320*e4b17023SJohn Marino rli->remaining_in_alignment -= bitsize;
1321*e4b17023SJohn Marino }
1322*e4b17023SJohn Marino else
1323*e4b17023SJohn Marino {
1324*e4b17023SJohn Marino /* End of a run: if leaving a run of bitfields of the same type
1325*e4b17023SJohn Marino size, we have to "use up" the rest of the bits of the type
1326*e4b17023SJohn Marino size.
1327*e4b17023SJohn Marino
1328*e4b17023SJohn Marino Compute the new position as the sum of the size for the prior
1329*e4b17023SJohn Marino type and where we first started working on that type.
1330*e4b17023SJohn Marino Note: since the beginning of the field was aligned then
1331*e4b17023SJohn Marino of course the end will be too. No round needed. */
1332*e4b17023SJohn Marino
1333*e4b17023SJohn Marino if (!integer_zerop (DECL_SIZE (rli->prev_field)))
1334*e4b17023SJohn Marino {
1335*e4b17023SJohn Marino rli->bitpos
1336*e4b17023SJohn Marino = size_binop (PLUS_EXPR, rli->bitpos,
1337*e4b17023SJohn Marino bitsize_int (rli->remaining_in_alignment));
1338*e4b17023SJohn Marino }
1339*e4b17023SJohn Marino else
1340*e4b17023SJohn Marino /* We "use up" size zero fields; the code below should behave
1341*e4b17023SJohn Marino as if the prior field was not a bitfield. */
1342*e4b17023SJohn Marino prev_saved = NULL;
1343*e4b17023SJohn Marino
1344*e4b17023SJohn Marino /* Cause a new bitfield to be captured, either this time (if
1345*e4b17023SJohn Marino currently a bitfield) or next time we see one. */
1346*e4b17023SJohn Marino if (!DECL_BIT_FIELD_TYPE(field)
1347*e4b17023SJohn Marino || integer_zerop (DECL_SIZE (field)))
1348*e4b17023SJohn Marino rli->prev_field = NULL;
1349*e4b17023SJohn Marino }
1350*e4b17023SJohn Marino
1351*e4b17023SJohn Marino normalize_rli (rli);
1352*e4b17023SJohn Marino }
1353*e4b17023SJohn Marino
1354*e4b17023SJohn Marino /* If we're starting a new run of same size type bitfields
1355*e4b17023SJohn Marino (or a run of non-bitfields), set up the "first of the run"
1356*e4b17023SJohn Marino fields.
1357*e4b17023SJohn Marino
1358*e4b17023SJohn Marino That is, if the current field is not a bitfield, or if there
1359*e4b17023SJohn Marino was a prior bitfield the type sizes differ, or if there wasn't
1360*e4b17023SJohn Marino a prior bitfield the size of the current field is nonzero.
1361*e4b17023SJohn Marino
1362*e4b17023SJohn Marino Note: we must be sure to test ONLY the type size if there was
1363*e4b17023SJohn Marino a prior bitfield and ONLY for the current field being zero if
1364*e4b17023SJohn Marino there wasn't. */
1365*e4b17023SJohn Marino
1366*e4b17023SJohn Marino if (!DECL_BIT_FIELD_TYPE (field)
1367*e4b17023SJohn Marino || (prev_saved != NULL
1368*e4b17023SJohn Marino ? !simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (prev_type))
1369*e4b17023SJohn Marino : !integer_zerop (DECL_SIZE (field)) ))
1370*e4b17023SJohn Marino {
1371*e4b17023SJohn Marino /* Never smaller than a byte for compatibility. */
1372*e4b17023SJohn Marino unsigned int type_align = BITS_PER_UNIT;
1373*e4b17023SJohn Marino
1374*e4b17023SJohn Marino /* (When not a bitfield), we could be seeing a flex array (with
1375*e4b17023SJohn Marino no DECL_SIZE). Since we won't be using remaining_in_alignment
1376*e4b17023SJohn Marino until we see a bitfield (and come by here again) we just skip
1377*e4b17023SJohn Marino calculating it. */
1378*e4b17023SJohn Marino if (DECL_SIZE (field) != NULL
1379*e4b17023SJohn Marino && host_integerp (TYPE_SIZE (TREE_TYPE (field)), 1)
1380*e4b17023SJohn Marino && host_integerp (DECL_SIZE (field), 1))
1381*e4b17023SJohn Marino {
1382*e4b17023SJohn Marino unsigned HOST_WIDE_INT bitsize
1383*e4b17023SJohn Marino = tree_low_cst (DECL_SIZE (field), 1);
1384*e4b17023SJohn Marino unsigned HOST_WIDE_INT typesize
1385*e4b17023SJohn Marino = tree_low_cst (TYPE_SIZE (TREE_TYPE (field)), 1);
1386*e4b17023SJohn Marino
1387*e4b17023SJohn Marino if (typesize < bitsize)
1388*e4b17023SJohn Marino rli->remaining_in_alignment = 0;
1389*e4b17023SJohn Marino else
1390*e4b17023SJohn Marino rli->remaining_in_alignment = typesize - bitsize;
1391*e4b17023SJohn Marino }
1392*e4b17023SJohn Marino
1393*e4b17023SJohn Marino /* Now align (conventionally) for the new type. */
1394*e4b17023SJohn Marino type_align = TYPE_ALIGN (TREE_TYPE (field));
1395*e4b17023SJohn Marino
1396*e4b17023SJohn Marino if (maximum_field_alignment != 0)
1397*e4b17023SJohn Marino type_align = MIN (type_align, maximum_field_alignment);
1398*e4b17023SJohn Marino
1399*e4b17023SJohn Marino rli->bitpos = round_up (rli->bitpos, type_align);
1400*e4b17023SJohn Marino
1401*e4b17023SJohn Marino /* If we really aligned, don't allow subsequent bitfields
1402*e4b17023SJohn Marino to undo that. */
1403*e4b17023SJohn Marino rli->prev_field = NULL;
1404*e4b17023SJohn Marino }
1405*e4b17023SJohn Marino }
1406*e4b17023SJohn Marino
1407*e4b17023SJohn Marino /* Offset so far becomes the position of this field after normalizing. */
1408*e4b17023SJohn Marino normalize_rli (rli);
1409*e4b17023SJohn Marino DECL_FIELD_OFFSET (field) = rli->offset;
1410*e4b17023SJohn Marino DECL_FIELD_BIT_OFFSET (field) = rli->bitpos;
1411*e4b17023SJohn Marino SET_DECL_OFFSET_ALIGN (field, rli->offset_align);
1412*e4b17023SJohn Marino
1413*e4b17023SJohn Marino /* If this field ended up more aligned than we thought it would be (we
1414*e4b17023SJohn Marino approximate this by seeing if its position changed), lay out the field
1415*e4b17023SJohn Marino again; perhaps we can use an integral mode for it now. */
1416*e4b17023SJohn Marino if (! integer_zerop (DECL_FIELD_BIT_OFFSET (field)))
1417*e4b17023SJohn Marino actual_align = (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
1418*e4b17023SJohn Marino & - tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1));
1419*e4b17023SJohn Marino else if (integer_zerop (DECL_FIELD_OFFSET (field)))
1420*e4b17023SJohn Marino actual_align = MAX (BIGGEST_ALIGNMENT, rli->record_align);
1421*e4b17023SJohn Marino else if (host_integerp (DECL_FIELD_OFFSET (field), 1))
1422*e4b17023SJohn Marino actual_align = (BITS_PER_UNIT
1423*e4b17023SJohn Marino * (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
1424*e4b17023SJohn Marino & - tree_low_cst (DECL_FIELD_OFFSET (field), 1)));
1425*e4b17023SJohn Marino else
1426*e4b17023SJohn Marino actual_align = DECL_OFFSET_ALIGN (field);
1427*e4b17023SJohn Marino /* ACTUAL_ALIGN is still the actual alignment *within the record* .
1428*e4b17023SJohn Marino store / extract bit field operations will check the alignment of the
1429*e4b17023SJohn Marino record against the mode of bit fields. */
1430*e4b17023SJohn Marino
1431*e4b17023SJohn Marino if (known_align != actual_align)
1432*e4b17023SJohn Marino layout_decl (field, actual_align);
1433*e4b17023SJohn Marino
1434*e4b17023SJohn Marino if (rli->prev_field == NULL && DECL_BIT_FIELD_TYPE (field))
1435*e4b17023SJohn Marino rli->prev_field = field;
1436*e4b17023SJohn Marino
1437*e4b17023SJohn Marino /* Now add size of this field to the size of the record. If the size is
1438*e4b17023SJohn Marino not constant, treat the field as being a multiple of bytes and just
1439*e4b17023SJohn Marino adjust the offset, resetting the bit position. Otherwise, apportion the
1440*e4b17023SJohn Marino size amongst the bit position and offset. First handle the case of an
1441*e4b17023SJohn Marino unspecified size, which can happen when we have an invalid nested struct
1442*e4b17023SJohn Marino definition, such as struct j { struct j { int i; } }. The error message
1443*e4b17023SJohn Marino is printed in finish_struct. */
1444*e4b17023SJohn Marino if (DECL_SIZE (field) == 0)
1445*e4b17023SJohn Marino /* Do nothing. */;
1446*e4b17023SJohn Marino else if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST
1447*e4b17023SJohn Marino || TREE_OVERFLOW (DECL_SIZE (field)))
1448*e4b17023SJohn Marino {
1449*e4b17023SJohn Marino rli->offset
1450*e4b17023SJohn Marino = size_binop (PLUS_EXPR, rli->offset,
1451*e4b17023SJohn Marino fold_convert (sizetype,
1452*e4b17023SJohn Marino size_binop (CEIL_DIV_EXPR, rli->bitpos,
1453*e4b17023SJohn Marino bitsize_unit_node)));
1454*e4b17023SJohn Marino rli->offset
1455*e4b17023SJohn Marino = size_binop (PLUS_EXPR, rli->offset, DECL_SIZE_UNIT (field));
1456*e4b17023SJohn Marino rli->bitpos = bitsize_zero_node;
1457*e4b17023SJohn Marino rli->offset_align = MIN (rli->offset_align, desired_align);
1458*e4b17023SJohn Marino }
1459*e4b17023SJohn Marino else if (targetm.ms_bitfield_layout_p (rli->t))
1460*e4b17023SJohn Marino {
1461*e4b17023SJohn Marino rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field));
1462*e4b17023SJohn Marino
1463*e4b17023SJohn Marino /* If we ended a bitfield before the full length of the type then
1464*e4b17023SJohn Marino pad the struct out to the full length of the last type. */
1465*e4b17023SJohn Marino if ((DECL_CHAIN (field) == NULL
1466*e4b17023SJohn Marino || TREE_CODE (DECL_CHAIN (field)) != FIELD_DECL)
1467*e4b17023SJohn Marino && DECL_BIT_FIELD_TYPE (field)
1468*e4b17023SJohn Marino && !integer_zerop (DECL_SIZE (field)))
1469*e4b17023SJohn Marino rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos,
1470*e4b17023SJohn Marino bitsize_int (rli->remaining_in_alignment));
1471*e4b17023SJohn Marino
1472*e4b17023SJohn Marino normalize_rli (rli);
1473*e4b17023SJohn Marino }
1474*e4b17023SJohn Marino else
1475*e4b17023SJohn Marino {
1476*e4b17023SJohn Marino rli->bitpos = size_binop (PLUS_EXPR, rli->bitpos, DECL_SIZE (field));
1477*e4b17023SJohn Marino normalize_rli (rli);
1478*e4b17023SJohn Marino }
1479*e4b17023SJohn Marino }
1480*e4b17023SJohn Marino
1481*e4b17023SJohn Marino /* Assuming that all the fields have been laid out, this function uses
1482*e4b17023SJohn Marino RLI to compute the final TYPE_SIZE, TYPE_ALIGN, etc. for the type
1483*e4b17023SJohn Marino indicated by RLI. */
1484*e4b17023SJohn Marino
1485*e4b17023SJohn Marino static void
finalize_record_size(record_layout_info rli)1486*e4b17023SJohn Marino finalize_record_size (record_layout_info rli)
1487*e4b17023SJohn Marino {
1488*e4b17023SJohn Marino tree unpadded_size, unpadded_size_unit;
1489*e4b17023SJohn Marino
1490*e4b17023SJohn Marino /* Now we want just byte and bit offsets, so set the offset alignment
1491*e4b17023SJohn Marino to be a byte and then normalize. */
1492*e4b17023SJohn Marino rli->offset_align = BITS_PER_UNIT;
1493*e4b17023SJohn Marino normalize_rli (rli);
1494*e4b17023SJohn Marino
1495*e4b17023SJohn Marino /* Determine the desired alignment. */
1496*e4b17023SJohn Marino #ifdef ROUND_TYPE_ALIGN
1497*e4b17023SJohn Marino TYPE_ALIGN (rli->t) = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t),
1498*e4b17023SJohn Marino rli->record_align);
1499*e4b17023SJohn Marino #else
1500*e4b17023SJohn Marino TYPE_ALIGN (rli->t) = MAX (TYPE_ALIGN (rli->t), rli->record_align);
1501*e4b17023SJohn Marino #endif
1502*e4b17023SJohn Marino
1503*e4b17023SJohn Marino /* Compute the size so far. Be sure to allow for extra bits in the
1504*e4b17023SJohn Marino size in bytes. We have guaranteed above that it will be no more
1505*e4b17023SJohn Marino than a single byte. */
1506*e4b17023SJohn Marino unpadded_size = rli_size_so_far (rli);
1507*e4b17023SJohn Marino unpadded_size_unit = rli_size_unit_so_far (rli);
1508*e4b17023SJohn Marino if (! integer_zerop (rli->bitpos))
1509*e4b17023SJohn Marino unpadded_size_unit
1510*e4b17023SJohn Marino = size_binop (PLUS_EXPR, unpadded_size_unit, size_one_node);
1511*e4b17023SJohn Marino
1512*e4b17023SJohn Marino /* Round the size up to be a multiple of the required alignment. */
1513*e4b17023SJohn Marino TYPE_SIZE (rli->t) = round_up (unpadded_size, TYPE_ALIGN (rli->t));
1514*e4b17023SJohn Marino TYPE_SIZE_UNIT (rli->t)
1515*e4b17023SJohn Marino = round_up (unpadded_size_unit, TYPE_ALIGN_UNIT (rli->t));
1516*e4b17023SJohn Marino
1517*e4b17023SJohn Marino if (TREE_CONSTANT (unpadded_size)
1518*e4b17023SJohn Marino && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0
1519*e4b17023SJohn Marino && input_location != BUILTINS_LOCATION)
1520*e4b17023SJohn Marino warning (OPT_Wpadded, "padding struct size to alignment boundary");
1521*e4b17023SJohn Marino
1522*e4b17023SJohn Marino if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE
1523*e4b17023SJohn Marino && TYPE_PACKED (rli->t) && ! rli->packed_maybe_necessary
1524*e4b17023SJohn Marino && TREE_CONSTANT (unpadded_size))
1525*e4b17023SJohn Marino {
1526*e4b17023SJohn Marino tree unpacked_size;
1527*e4b17023SJohn Marino
1528*e4b17023SJohn Marino #ifdef ROUND_TYPE_ALIGN
1529*e4b17023SJohn Marino rli->unpacked_align
1530*e4b17023SJohn Marino = ROUND_TYPE_ALIGN (rli->t, TYPE_ALIGN (rli->t), rli->unpacked_align);
1531*e4b17023SJohn Marino #else
1532*e4b17023SJohn Marino rli->unpacked_align = MAX (TYPE_ALIGN (rli->t), rli->unpacked_align);
1533*e4b17023SJohn Marino #endif
1534*e4b17023SJohn Marino
1535*e4b17023SJohn Marino unpacked_size = round_up (TYPE_SIZE (rli->t), rli->unpacked_align);
1536*e4b17023SJohn Marino if (simple_cst_equal (unpacked_size, TYPE_SIZE (rli->t)))
1537*e4b17023SJohn Marino {
1538*e4b17023SJohn Marino if (TYPE_NAME (rli->t))
1539*e4b17023SJohn Marino {
1540*e4b17023SJohn Marino tree name;
1541*e4b17023SJohn Marino
1542*e4b17023SJohn Marino if (TREE_CODE (TYPE_NAME (rli->t)) == IDENTIFIER_NODE)
1543*e4b17023SJohn Marino name = TYPE_NAME (rli->t);
1544*e4b17023SJohn Marino else
1545*e4b17023SJohn Marino name = DECL_NAME (TYPE_NAME (rli->t));
1546*e4b17023SJohn Marino
1547*e4b17023SJohn Marino if (STRICT_ALIGNMENT)
1548*e4b17023SJohn Marino warning (OPT_Wpacked, "packed attribute causes inefficient "
1549*e4b17023SJohn Marino "alignment for %qE", name);
1550*e4b17023SJohn Marino else
1551*e4b17023SJohn Marino warning (OPT_Wpacked,
1552*e4b17023SJohn Marino "packed attribute is unnecessary for %qE", name);
1553*e4b17023SJohn Marino }
1554*e4b17023SJohn Marino else
1555*e4b17023SJohn Marino {
1556*e4b17023SJohn Marino if (STRICT_ALIGNMENT)
1557*e4b17023SJohn Marino warning (OPT_Wpacked,
1558*e4b17023SJohn Marino "packed attribute causes inefficient alignment");
1559*e4b17023SJohn Marino else
1560*e4b17023SJohn Marino warning (OPT_Wpacked, "packed attribute is unnecessary");
1561*e4b17023SJohn Marino }
1562*e4b17023SJohn Marino }
1563*e4b17023SJohn Marino }
1564*e4b17023SJohn Marino }
1565*e4b17023SJohn Marino
1566*e4b17023SJohn Marino /* Compute the TYPE_MODE for the TYPE (which is a RECORD_TYPE). */
1567*e4b17023SJohn Marino
1568*e4b17023SJohn Marino void
compute_record_mode(tree type)1569*e4b17023SJohn Marino compute_record_mode (tree type)
1570*e4b17023SJohn Marino {
1571*e4b17023SJohn Marino tree field;
1572*e4b17023SJohn Marino enum machine_mode mode = VOIDmode;
1573*e4b17023SJohn Marino
1574*e4b17023SJohn Marino /* Most RECORD_TYPEs have BLKmode, so we start off assuming that.
1575*e4b17023SJohn Marino However, if possible, we use a mode that fits in a register
1576*e4b17023SJohn Marino instead, in order to allow for better optimization down the
1577*e4b17023SJohn Marino line. */
1578*e4b17023SJohn Marino SET_TYPE_MODE (type, BLKmode);
1579*e4b17023SJohn Marino
1580*e4b17023SJohn Marino if (! host_integerp (TYPE_SIZE (type), 1))
1581*e4b17023SJohn Marino return;
1582*e4b17023SJohn Marino
1583*e4b17023SJohn Marino /* A record which has any BLKmode members must itself be
1584*e4b17023SJohn Marino BLKmode; it can't go in a register. Unless the member is
1585*e4b17023SJohn Marino BLKmode only because it isn't aligned. */
1586*e4b17023SJohn Marino for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
1587*e4b17023SJohn Marino {
1588*e4b17023SJohn Marino if (TREE_CODE (field) != FIELD_DECL)
1589*e4b17023SJohn Marino continue;
1590*e4b17023SJohn Marino
1591*e4b17023SJohn Marino if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK
1592*e4b17023SJohn Marino || (TYPE_MODE (TREE_TYPE (field)) == BLKmode
1593*e4b17023SJohn Marino && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field))
1594*e4b17023SJohn Marino && !(TYPE_SIZE (TREE_TYPE (field)) != 0
1595*e4b17023SJohn Marino && integer_zerop (TYPE_SIZE (TREE_TYPE (field)))))
1596*e4b17023SJohn Marino || ! host_integerp (bit_position (field), 1)
1597*e4b17023SJohn Marino || DECL_SIZE (field) == 0
1598*e4b17023SJohn Marino || ! host_integerp (DECL_SIZE (field), 1))
1599*e4b17023SJohn Marino return;
1600*e4b17023SJohn Marino
1601*e4b17023SJohn Marino /* If this field is the whole struct, remember its mode so
1602*e4b17023SJohn Marino that, say, we can put a double in a class into a DF
1603*e4b17023SJohn Marino register instead of forcing it to live in the stack. */
1604*e4b17023SJohn Marino if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field)))
1605*e4b17023SJohn Marino mode = DECL_MODE (field);
1606*e4b17023SJohn Marino
1607*e4b17023SJohn Marino #ifdef MEMBER_TYPE_FORCES_BLK
1608*e4b17023SJohn Marino /* With some targets, eg. c4x, it is sub-optimal
1609*e4b17023SJohn Marino to access an aligned BLKmode structure as a scalar. */
1610*e4b17023SJohn Marino
1611*e4b17023SJohn Marino if (MEMBER_TYPE_FORCES_BLK (field, mode))
1612*e4b17023SJohn Marino return;
1613*e4b17023SJohn Marino #endif /* MEMBER_TYPE_FORCES_BLK */
1614*e4b17023SJohn Marino }
1615*e4b17023SJohn Marino
1616*e4b17023SJohn Marino /* If we only have one real field; use its mode if that mode's size
1617*e4b17023SJohn Marino matches the type's size. This only applies to RECORD_TYPE. This
1618*e4b17023SJohn Marino does not apply to unions. */
1619*e4b17023SJohn Marino if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode
1620*e4b17023SJohn Marino && host_integerp (TYPE_SIZE (type), 1)
1621*e4b17023SJohn Marino && GET_MODE_BITSIZE (mode) == TREE_INT_CST_LOW (TYPE_SIZE (type)))
1622*e4b17023SJohn Marino SET_TYPE_MODE (type, mode);
1623*e4b17023SJohn Marino else
1624*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1));
1625*e4b17023SJohn Marino
1626*e4b17023SJohn Marino /* If structure's known alignment is less than what the scalar
1627*e4b17023SJohn Marino mode would need, and it matters, then stick with BLKmode. */
1628*e4b17023SJohn Marino if (TYPE_MODE (type) != BLKmode
1629*e4b17023SJohn Marino && STRICT_ALIGNMENT
1630*e4b17023SJohn Marino && ! (TYPE_ALIGN (type) >= BIGGEST_ALIGNMENT
1631*e4b17023SJohn Marino || TYPE_ALIGN (type) >= GET_MODE_ALIGNMENT (TYPE_MODE (type))))
1632*e4b17023SJohn Marino {
1633*e4b17023SJohn Marino /* If this is the only reason this type is BLKmode, then
1634*e4b17023SJohn Marino don't force containing types to be BLKmode. */
1635*e4b17023SJohn Marino TYPE_NO_FORCE_BLK (type) = 1;
1636*e4b17023SJohn Marino SET_TYPE_MODE (type, BLKmode);
1637*e4b17023SJohn Marino }
1638*e4b17023SJohn Marino }
1639*e4b17023SJohn Marino
1640*e4b17023SJohn Marino /* Compute TYPE_SIZE and TYPE_ALIGN for TYPE, once it has been laid
1641*e4b17023SJohn Marino out. */
1642*e4b17023SJohn Marino
1643*e4b17023SJohn Marino static void
finalize_type_size(tree type)1644*e4b17023SJohn Marino finalize_type_size (tree type)
1645*e4b17023SJohn Marino {
1646*e4b17023SJohn Marino /* Normally, use the alignment corresponding to the mode chosen.
1647*e4b17023SJohn Marino However, where strict alignment is not required, avoid
1648*e4b17023SJohn Marino over-aligning structures, since most compilers do not do this
1649*e4b17023SJohn Marino alignment. */
1650*e4b17023SJohn Marino
1651*e4b17023SJohn Marino if (TYPE_MODE (type) != BLKmode && TYPE_MODE (type) != VOIDmode
1652*e4b17023SJohn Marino && (STRICT_ALIGNMENT
1653*e4b17023SJohn Marino || (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
1654*e4b17023SJohn Marino && TREE_CODE (type) != QUAL_UNION_TYPE
1655*e4b17023SJohn Marino && TREE_CODE (type) != ARRAY_TYPE)))
1656*e4b17023SJohn Marino {
1657*e4b17023SJohn Marino unsigned mode_align = GET_MODE_ALIGNMENT (TYPE_MODE (type));
1658*e4b17023SJohn Marino
1659*e4b17023SJohn Marino /* Don't override a larger alignment requirement coming from a user
1660*e4b17023SJohn Marino alignment of one of the fields. */
1661*e4b17023SJohn Marino if (mode_align >= TYPE_ALIGN (type))
1662*e4b17023SJohn Marino {
1663*e4b17023SJohn Marino TYPE_ALIGN (type) = mode_align;
1664*e4b17023SJohn Marino TYPE_USER_ALIGN (type) = 0;
1665*e4b17023SJohn Marino }
1666*e4b17023SJohn Marino }
1667*e4b17023SJohn Marino
1668*e4b17023SJohn Marino /* Do machine-dependent extra alignment. */
1669*e4b17023SJohn Marino #ifdef ROUND_TYPE_ALIGN
1670*e4b17023SJohn Marino TYPE_ALIGN (type)
1671*e4b17023SJohn Marino = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (type), BITS_PER_UNIT);
1672*e4b17023SJohn Marino #endif
1673*e4b17023SJohn Marino
1674*e4b17023SJohn Marino /* If we failed to find a simple way to calculate the unit size
1675*e4b17023SJohn Marino of the type, find it by division. */
1676*e4b17023SJohn Marino if (TYPE_SIZE_UNIT (type) == 0 && TYPE_SIZE (type) != 0)
1677*e4b17023SJohn Marino /* TYPE_SIZE (type) is computed in bitsizetype. After the division, the
1678*e4b17023SJohn Marino result will fit in sizetype. We will get more efficient code using
1679*e4b17023SJohn Marino sizetype, so we force a conversion. */
1680*e4b17023SJohn Marino TYPE_SIZE_UNIT (type)
1681*e4b17023SJohn Marino = fold_convert (sizetype,
1682*e4b17023SJohn Marino size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (type),
1683*e4b17023SJohn Marino bitsize_unit_node));
1684*e4b17023SJohn Marino
1685*e4b17023SJohn Marino if (TYPE_SIZE (type) != 0)
1686*e4b17023SJohn Marino {
1687*e4b17023SJohn Marino TYPE_SIZE (type) = round_up (TYPE_SIZE (type), TYPE_ALIGN (type));
1688*e4b17023SJohn Marino TYPE_SIZE_UNIT (type)
1689*e4b17023SJohn Marino = round_up (TYPE_SIZE_UNIT (type), TYPE_ALIGN_UNIT (type));
1690*e4b17023SJohn Marino }
1691*e4b17023SJohn Marino
1692*e4b17023SJohn Marino /* Evaluate nonconstant sizes only once, either now or as soon as safe. */
1693*e4b17023SJohn Marino if (TYPE_SIZE (type) != 0 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1694*e4b17023SJohn Marino TYPE_SIZE (type) = variable_size (TYPE_SIZE (type));
1695*e4b17023SJohn Marino if (TYPE_SIZE_UNIT (type) != 0
1696*e4b17023SJohn Marino && TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST)
1697*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = variable_size (TYPE_SIZE_UNIT (type));
1698*e4b17023SJohn Marino
1699*e4b17023SJohn Marino /* Also layout any other variants of the type. */
1700*e4b17023SJohn Marino if (TYPE_NEXT_VARIANT (type)
1701*e4b17023SJohn Marino || type != TYPE_MAIN_VARIANT (type))
1702*e4b17023SJohn Marino {
1703*e4b17023SJohn Marino tree variant;
1704*e4b17023SJohn Marino /* Record layout info of this variant. */
1705*e4b17023SJohn Marino tree size = TYPE_SIZE (type);
1706*e4b17023SJohn Marino tree size_unit = TYPE_SIZE_UNIT (type);
1707*e4b17023SJohn Marino unsigned int align = TYPE_ALIGN (type);
1708*e4b17023SJohn Marino unsigned int user_align = TYPE_USER_ALIGN (type);
1709*e4b17023SJohn Marino enum machine_mode mode = TYPE_MODE (type);
1710*e4b17023SJohn Marino
1711*e4b17023SJohn Marino /* Copy it into all variants. */
1712*e4b17023SJohn Marino for (variant = TYPE_MAIN_VARIANT (type);
1713*e4b17023SJohn Marino variant != 0;
1714*e4b17023SJohn Marino variant = TYPE_NEXT_VARIANT (variant))
1715*e4b17023SJohn Marino {
1716*e4b17023SJohn Marino TYPE_SIZE (variant) = size;
1717*e4b17023SJohn Marino TYPE_SIZE_UNIT (variant) = size_unit;
1718*e4b17023SJohn Marino TYPE_ALIGN (variant) = align;
1719*e4b17023SJohn Marino TYPE_USER_ALIGN (variant) = user_align;
1720*e4b17023SJohn Marino SET_TYPE_MODE (variant, mode);
1721*e4b17023SJohn Marino }
1722*e4b17023SJohn Marino }
1723*e4b17023SJohn Marino }
1724*e4b17023SJohn Marino
1725*e4b17023SJohn Marino /* Return a new underlying object for a bitfield started with FIELD. */
1726*e4b17023SJohn Marino
1727*e4b17023SJohn Marino static tree
start_bitfield_representative(tree field)1728*e4b17023SJohn Marino start_bitfield_representative (tree field)
1729*e4b17023SJohn Marino {
1730*e4b17023SJohn Marino tree repr = make_node (FIELD_DECL);
1731*e4b17023SJohn Marino DECL_FIELD_OFFSET (repr) = DECL_FIELD_OFFSET (field);
1732*e4b17023SJohn Marino /* Force the representative to begin at a BITS_PER_UNIT aligned
1733*e4b17023SJohn Marino boundary - C++ may use tail-padding of a base object to
1734*e4b17023SJohn Marino continue packing bits so the bitfield region does not start
1735*e4b17023SJohn Marino at bit zero (see g++.dg/abi/bitfield5.C for example).
1736*e4b17023SJohn Marino Unallocated bits may happen for other reasons as well,
1737*e4b17023SJohn Marino for example Ada which allows explicit bit-granular structure layout. */
1738*e4b17023SJohn Marino DECL_FIELD_BIT_OFFSET (repr)
1739*e4b17023SJohn Marino = size_binop (BIT_AND_EXPR,
1740*e4b17023SJohn Marino DECL_FIELD_BIT_OFFSET (field),
1741*e4b17023SJohn Marino bitsize_int (~(BITS_PER_UNIT - 1)));
1742*e4b17023SJohn Marino SET_DECL_OFFSET_ALIGN (repr, DECL_OFFSET_ALIGN (field));
1743*e4b17023SJohn Marino DECL_SIZE (repr) = DECL_SIZE (field);
1744*e4b17023SJohn Marino DECL_SIZE_UNIT (repr) = DECL_SIZE_UNIT (field);
1745*e4b17023SJohn Marino DECL_PACKED (repr) = DECL_PACKED (field);
1746*e4b17023SJohn Marino DECL_CONTEXT (repr) = DECL_CONTEXT (field);
1747*e4b17023SJohn Marino return repr;
1748*e4b17023SJohn Marino }
1749*e4b17023SJohn Marino
1750*e4b17023SJohn Marino /* Finish up a bitfield group that was started by creating the underlying
1751*e4b17023SJohn Marino object REPR with the last field in the bitfield group FIELD. */
1752*e4b17023SJohn Marino
1753*e4b17023SJohn Marino static void
finish_bitfield_representative(tree repr,tree field)1754*e4b17023SJohn Marino finish_bitfield_representative (tree repr, tree field)
1755*e4b17023SJohn Marino {
1756*e4b17023SJohn Marino unsigned HOST_WIDE_INT bitsize, maxbitsize;
1757*e4b17023SJohn Marino enum machine_mode mode;
1758*e4b17023SJohn Marino tree nextf, size;
1759*e4b17023SJohn Marino
1760*e4b17023SJohn Marino size = size_diffop (DECL_FIELD_OFFSET (field),
1761*e4b17023SJohn Marino DECL_FIELD_OFFSET (repr));
1762*e4b17023SJohn Marino gcc_assert (host_integerp (size, 1));
1763*e4b17023SJohn Marino bitsize = (tree_low_cst (size, 1) * BITS_PER_UNIT
1764*e4b17023SJohn Marino + tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
1765*e4b17023SJohn Marino - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1)
1766*e4b17023SJohn Marino + tree_low_cst (DECL_SIZE (field), 1));
1767*e4b17023SJohn Marino
1768*e4b17023SJohn Marino /* Round up bitsize to multiples of BITS_PER_UNIT. */
1769*e4b17023SJohn Marino bitsize = (bitsize + BITS_PER_UNIT - 1) & ~(BITS_PER_UNIT - 1);
1770*e4b17023SJohn Marino
1771*e4b17023SJohn Marino /* Now nothing tells us how to pad out bitsize ... */
1772*e4b17023SJohn Marino nextf = DECL_CHAIN (field);
1773*e4b17023SJohn Marino while (nextf && TREE_CODE (nextf) != FIELD_DECL)
1774*e4b17023SJohn Marino nextf = DECL_CHAIN (nextf);
1775*e4b17023SJohn Marino if (nextf)
1776*e4b17023SJohn Marino {
1777*e4b17023SJohn Marino tree maxsize;
1778*e4b17023SJohn Marino /* If there was an error, the field may be not laid out
1779*e4b17023SJohn Marino correctly. Don't bother to do anything. */
1780*e4b17023SJohn Marino if (TREE_TYPE (nextf) == error_mark_node)
1781*e4b17023SJohn Marino return;
1782*e4b17023SJohn Marino maxsize = size_diffop (DECL_FIELD_OFFSET (nextf),
1783*e4b17023SJohn Marino DECL_FIELD_OFFSET (repr));
1784*e4b17023SJohn Marino if (host_integerp (maxsize, 1))
1785*e4b17023SJohn Marino {
1786*e4b17023SJohn Marino maxbitsize = (tree_low_cst (maxsize, 1) * BITS_PER_UNIT
1787*e4b17023SJohn Marino + tree_low_cst (DECL_FIELD_BIT_OFFSET (nextf), 1)
1788*e4b17023SJohn Marino - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
1789*e4b17023SJohn Marino /* If the group ends within a bitfield nextf does not need to be
1790*e4b17023SJohn Marino aligned to BITS_PER_UNIT. Thus round up. */
1791*e4b17023SJohn Marino maxbitsize = (maxbitsize + BITS_PER_UNIT - 1) & ~(BITS_PER_UNIT - 1);
1792*e4b17023SJohn Marino }
1793*e4b17023SJohn Marino else
1794*e4b17023SJohn Marino maxbitsize = bitsize;
1795*e4b17023SJohn Marino }
1796*e4b17023SJohn Marino else
1797*e4b17023SJohn Marino {
1798*e4b17023SJohn Marino /* ??? If you consider that tail-padding of this struct might be
1799*e4b17023SJohn Marino re-used when deriving from it we cannot really do the following
1800*e4b17023SJohn Marino and thus need to set maxsize to bitsize? Also we cannot
1801*e4b17023SJohn Marino generally rely on maxsize to fold to an integer constant, so
1802*e4b17023SJohn Marino use bitsize as fallback for this case. */
1803*e4b17023SJohn Marino tree maxsize = size_diffop (TYPE_SIZE_UNIT (DECL_CONTEXT (field)),
1804*e4b17023SJohn Marino DECL_FIELD_OFFSET (repr));
1805*e4b17023SJohn Marino if (host_integerp (maxsize, 1))
1806*e4b17023SJohn Marino maxbitsize = (tree_low_cst (maxsize, 1) * BITS_PER_UNIT
1807*e4b17023SJohn Marino - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
1808*e4b17023SJohn Marino else
1809*e4b17023SJohn Marino maxbitsize = bitsize;
1810*e4b17023SJohn Marino }
1811*e4b17023SJohn Marino
1812*e4b17023SJohn Marino /* Only if we don't artificially break up the representative in
1813*e4b17023SJohn Marino the middle of a large bitfield with different possibly
1814*e4b17023SJohn Marino overlapping representatives. And all representatives start
1815*e4b17023SJohn Marino at byte offset. */
1816*e4b17023SJohn Marino gcc_assert (maxbitsize % BITS_PER_UNIT == 0);
1817*e4b17023SJohn Marino
1818*e4b17023SJohn Marino /* Find the smallest nice mode to use. */
1819*e4b17023SJohn Marino for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
1820*e4b17023SJohn Marino mode = GET_MODE_WIDER_MODE (mode))
1821*e4b17023SJohn Marino if (GET_MODE_BITSIZE (mode) >= bitsize)
1822*e4b17023SJohn Marino break;
1823*e4b17023SJohn Marino if (mode != VOIDmode
1824*e4b17023SJohn Marino && (GET_MODE_BITSIZE (mode) > maxbitsize
1825*e4b17023SJohn Marino || GET_MODE_BITSIZE (mode) > MAX_FIXED_MODE_SIZE))
1826*e4b17023SJohn Marino mode = VOIDmode;
1827*e4b17023SJohn Marino
1828*e4b17023SJohn Marino if (mode == VOIDmode)
1829*e4b17023SJohn Marino {
1830*e4b17023SJohn Marino /* We really want a BLKmode representative only as a last resort,
1831*e4b17023SJohn Marino considering the member b in
1832*e4b17023SJohn Marino struct { int a : 7; int b : 17; int c; } __attribute__((packed));
1833*e4b17023SJohn Marino Otherwise we simply want to split the representative up
1834*e4b17023SJohn Marino allowing for overlaps within the bitfield region as required for
1835*e4b17023SJohn Marino struct { int a : 7; int b : 7;
1836*e4b17023SJohn Marino int c : 10; int d; } __attribute__((packed));
1837*e4b17023SJohn Marino [0, 15] HImode for a and b, [8, 23] HImode for c. */
1838*e4b17023SJohn Marino DECL_SIZE (repr) = bitsize_int (bitsize);
1839*e4b17023SJohn Marino DECL_SIZE_UNIT (repr) = size_int (bitsize / BITS_PER_UNIT);
1840*e4b17023SJohn Marino DECL_MODE (repr) = BLKmode;
1841*e4b17023SJohn Marino TREE_TYPE (repr) = build_array_type_nelts (unsigned_char_type_node,
1842*e4b17023SJohn Marino bitsize / BITS_PER_UNIT);
1843*e4b17023SJohn Marino }
1844*e4b17023SJohn Marino else
1845*e4b17023SJohn Marino {
1846*e4b17023SJohn Marino unsigned HOST_WIDE_INT modesize = GET_MODE_BITSIZE (mode);
1847*e4b17023SJohn Marino DECL_SIZE (repr) = bitsize_int (modesize);
1848*e4b17023SJohn Marino DECL_SIZE_UNIT (repr) = size_int (modesize / BITS_PER_UNIT);
1849*e4b17023SJohn Marino DECL_MODE (repr) = mode;
1850*e4b17023SJohn Marino TREE_TYPE (repr) = lang_hooks.types.type_for_mode (mode, 1);
1851*e4b17023SJohn Marino }
1852*e4b17023SJohn Marino
1853*e4b17023SJohn Marino /* Remember whether the bitfield group is at the end of the
1854*e4b17023SJohn Marino structure or not. */
1855*e4b17023SJohn Marino DECL_CHAIN (repr) = nextf;
1856*e4b17023SJohn Marino }
1857*e4b17023SJohn Marino
1858*e4b17023SJohn Marino /* Compute and set FIELD_DECLs for the underlying objects we should
1859*e4b17023SJohn Marino use for bitfield access for the structure laid out with RLI. */
1860*e4b17023SJohn Marino
1861*e4b17023SJohn Marino static void
finish_bitfield_layout(record_layout_info rli)1862*e4b17023SJohn Marino finish_bitfield_layout (record_layout_info rli)
1863*e4b17023SJohn Marino {
1864*e4b17023SJohn Marino tree field, prev;
1865*e4b17023SJohn Marino tree repr = NULL_TREE;
1866*e4b17023SJohn Marino
1867*e4b17023SJohn Marino /* Unions would be special, for the ease of type-punning optimizations
1868*e4b17023SJohn Marino we could use the underlying type as hint for the representative
1869*e4b17023SJohn Marino if the bitfield would fit and the representative would not exceed
1870*e4b17023SJohn Marino the union in size. */
1871*e4b17023SJohn Marino if (TREE_CODE (rli->t) != RECORD_TYPE)
1872*e4b17023SJohn Marino return;
1873*e4b17023SJohn Marino
1874*e4b17023SJohn Marino for (prev = NULL_TREE, field = TYPE_FIELDS (rli->t);
1875*e4b17023SJohn Marino field; field = DECL_CHAIN (field))
1876*e4b17023SJohn Marino {
1877*e4b17023SJohn Marino if (TREE_CODE (field) != FIELD_DECL)
1878*e4b17023SJohn Marino continue;
1879*e4b17023SJohn Marino
1880*e4b17023SJohn Marino /* In the C++ memory model, consecutive bit fields in a structure are
1881*e4b17023SJohn Marino considered one memory location and updating a memory location
1882*e4b17023SJohn Marino may not store into adjacent memory locations. */
1883*e4b17023SJohn Marino if (!repr
1884*e4b17023SJohn Marino && DECL_BIT_FIELD_TYPE (field))
1885*e4b17023SJohn Marino {
1886*e4b17023SJohn Marino /* Start new representative. */
1887*e4b17023SJohn Marino repr = start_bitfield_representative (field);
1888*e4b17023SJohn Marino }
1889*e4b17023SJohn Marino else if (repr
1890*e4b17023SJohn Marino && ! DECL_BIT_FIELD_TYPE (field))
1891*e4b17023SJohn Marino {
1892*e4b17023SJohn Marino /* Finish off new representative. */
1893*e4b17023SJohn Marino finish_bitfield_representative (repr, prev);
1894*e4b17023SJohn Marino repr = NULL_TREE;
1895*e4b17023SJohn Marino }
1896*e4b17023SJohn Marino else if (DECL_BIT_FIELD_TYPE (field))
1897*e4b17023SJohn Marino {
1898*e4b17023SJohn Marino gcc_assert (repr != NULL_TREE);
1899*e4b17023SJohn Marino
1900*e4b17023SJohn Marino /* Zero-size bitfields finish off a representative and
1901*e4b17023SJohn Marino do not have a representative themselves. This is
1902*e4b17023SJohn Marino required by the C++ memory model. */
1903*e4b17023SJohn Marino if (integer_zerop (DECL_SIZE (field)))
1904*e4b17023SJohn Marino {
1905*e4b17023SJohn Marino finish_bitfield_representative (repr, prev);
1906*e4b17023SJohn Marino repr = NULL_TREE;
1907*e4b17023SJohn Marino }
1908*e4b17023SJohn Marino
1909*e4b17023SJohn Marino /* We assume that either DECL_FIELD_OFFSET of the representative
1910*e4b17023SJohn Marino and each bitfield member is a constant or they are equal.
1911*e4b17023SJohn Marino This is because we need to be able to compute the bit-offset
1912*e4b17023SJohn Marino of each field relative to the representative in get_bit_range
1913*e4b17023SJohn Marino during RTL expansion.
1914*e4b17023SJohn Marino If these constraints are not met, simply force a new
1915*e4b17023SJohn Marino representative to be generated. That will at most
1916*e4b17023SJohn Marino generate worse code but still maintain correctness with
1917*e4b17023SJohn Marino respect to the C++ memory model. */
1918*e4b17023SJohn Marino else if (!((host_integerp (DECL_FIELD_OFFSET (repr), 1)
1919*e4b17023SJohn Marino && host_integerp (DECL_FIELD_OFFSET (field), 1))
1920*e4b17023SJohn Marino || operand_equal_p (DECL_FIELD_OFFSET (repr),
1921*e4b17023SJohn Marino DECL_FIELD_OFFSET (field), 0)))
1922*e4b17023SJohn Marino {
1923*e4b17023SJohn Marino finish_bitfield_representative (repr, prev);
1924*e4b17023SJohn Marino repr = start_bitfield_representative (field);
1925*e4b17023SJohn Marino }
1926*e4b17023SJohn Marino }
1927*e4b17023SJohn Marino else
1928*e4b17023SJohn Marino continue;
1929*e4b17023SJohn Marino
1930*e4b17023SJohn Marino if (repr)
1931*e4b17023SJohn Marino DECL_BIT_FIELD_REPRESENTATIVE (field) = repr;
1932*e4b17023SJohn Marino
1933*e4b17023SJohn Marino prev = field;
1934*e4b17023SJohn Marino }
1935*e4b17023SJohn Marino
1936*e4b17023SJohn Marino if (repr)
1937*e4b17023SJohn Marino finish_bitfield_representative (repr, prev);
1938*e4b17023SJohn Marino }
1939*e4b17023SJohn Marino
1940*e4b17023SJohn Marino /* Do all of the work required to layout the type indicated by RLI,
1941*e4b17023SJohn Marino once the fields have been laid out. This function will call `free'
1942*e4b17023SJohn Marino for RLI, unless FREE_P is false. Passing a value other than false
1943*e4b17023SJohn Marino for FREE_P is bad practice; this option only exists to support the
1944*e4b17023SJohn Marino G++ 3.2 ABI. */
1945*e4b17023SJohn Marino
1946*e4b17023SJohn Marino void
finish_record_layout(record_layout_info rli,int free_p)1947*e4b17023SJohn Marino finish_record_layout (record_layout_info rli, int free_p)
1948*e4b17023SJohn Marino {
1949*e4b17023SJohn Marino tree variant;
1950*e4b17023SJohn Marino
1951*e4b17023SJohn Marino /* Compute the final size. */
1952*e4b17023SJohn Marino finalize_record_size (rli);
1953*e4b17023SJohn Marino
1954*e4b17023SJohn Marino /* Compute the TYPE_MODE for the record. */
1955*e4b17023SJohn Marino compute_record_mode (rli->t);
1956*e4b17023SJohn Marino
1957*e4b17023SJohn Marino /* Perform any last tweaks to the TYPE_SIZE, etc. */
1958*e4b17023SJohn Marino finalize_type_size (rli->t);
1959*e4b17023SJohn Marino
1960*e4b17023SJohn Marino /* Compute bitfield representatives. */
1961*e4b17023SJohn Marino finish_bitfield_layout (rli);
1962*e4b17023SJohn Marino
1963*e4b17023SJohn Marino /* Propagate TYPE_PACKED to variants. With C++ templates,
1964*e4b17023SJohn Marino handle_packed_attribute is too early to do this. */
1965*e4b17023SJohn Marino for (variant = TYPE_NEXT_VARIANT (rli->t); variant;
1966*e4b17023SJohn Marino variant = TYPE_NEXT_VARIANT (variant))
1967*e4b17023SJohn Marino TYPE_PACKED (variant) = TYPE_PACKED (rli->t);
1968*e4b17023SJohn Marino
1969*e4b17023SJohn Marino /* Lay out any static members. This is done now because their type
1970*e4b17023SJohn Marino may use the record's type. */
1971*e4b17023SJohn Marino while (!VEC_empty (tree, rli->pending_statics))
1972*e4b17023SJohn Marino layout_decl (VEC_pop (tree, rli->pending_statics), 0);
1973*e4b17023SJohn Marino
1974*e4b17023SJohn Marino /* Clean up. */
1975*e4b17023SJohn Marino if (free_p)
1976*e4b17023SJohn Marino {
1977*e4b17023SJohn Marino VEC_free (tree, gc, rli->pending_statics);
1978*e4b17023SJohn Marino free (rli);
1979*e4b17023SJohn Marino }
1980*e4b17023SJohn Marino }
1981*e4b17023SJohn Marino
1982*e4b17023SJohn Marino
1983*e4b17023SJohn Marino /* Finish processing a builtin RECORD_TYPE type TYPE. It's name is
1984*e4b17023SJohn Marino NAME, its fields are chained in reverse on FIELDS.
1985*e4b17023SJohn Marino
1986*e4b17023SJohn Marino If ALIGN_TYPE is non-null, it is given the same alignment as
1987*e4b17023SJohn Marino ALIGN_TYPE. */
1988*e4b17023SJohn Marino
1989*e4b17023SJohn Marino void
finish_builtin_struct(tree type,const char * name,tree fields,tree align_type)1990*e4b17023SJohn Marino finish_builtin_struct (tree type, const char *name, tree fields,
1991*e4b17023SJohn Marino tree align_type)
1992*e4b17023SJohn Marino {
1993*e4b17023SJohn Marino tree tail, next;
1994*e4b17023SJohn Marino
1995*e4b17023SJohn Marino for (tail = NULL_TREE; fields; tail = fields, fields = next)
1996*e4b17023SJohn Marino {
1997*e4b17023SJohn Marino DECL_FIELD_CONTEXT (fields) = type;
1998*e4b17023SJohn Marino next = DECL_CHAIN (fields);
1999*e4b17023SJohn Marino DECL_CHAIN (fields) = tail;
2000*e4b17023SJohn Marino }
2001*e4b17023SJohn Marino TYPE_FIELDS (type) = tail;
2002*e4b17023SJohn Marino
2003*e4b17023SJohn Marino if (align_type)
2004*e4b17023SJohn Marino {
2005*e4b17023SJohn Marino TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2006*e4b17023SJohn Marino TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (align_type);
2007*e4b17023SJohn Marino }
2008*e4b17023SJohn Marino
2009*e4b17023SJohn Marino layout_type (type);
2010*e4b17023SJohn Marino #if 0 /* not yet, should get fixed properly later */
2011*e4b17023SJohn Marino TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2012*e4b17023SJohn Marino #else
2013*e4b17023SJohn Marino TYPE_NAME (type) = build_decl (BUILTINS_LOCATION,
2014*e4b17023SJohn Marino TYPE_DECL, get_identifier (name), type);
2015*e4b17023SJohn Marino #endif
2016*e4b17023SJohn Marino TYPE_STUB_DECL (type) = TYPE_NAME (type);
2017*e4b17023SJohn Marino layout_decl (TYPE_NAME (type), 0);
2018*e4b17023SJohn Marino }
2019*e4b17023SJohn Marino
2020*e4b17023SJohn Marino /* Calculate the mode, size, and alignment for TYPE.
2021*e4b17023SJohn Marino For an array type, calculate the element separation as well.
2022*e4b17023SJohn Marino Record TYPE on the chain of permanent or temporary types
2023*e4b17023SJohn Marino so that dbxout will find out about it.
2024*e4b17023SJohn Marino
2025*e4b17023SJohn Marino TYPE_SIZE of a type is nonzero if the type has been laid out already.
2026*e4b17023SJohn Marino layout_type does nothing on such a type.
2027*e4b17023SJohn Marino
2028*e4b17023SJohn Marino If the type is incomplete, its TYPE_SIZE remains zero. */
2029*e4b17023SJohn Marino
2030*e4b17023SJohn Marino void
layout_type(tree type)2031*e4b17023SJohn Marino layout_type (tree type)
2032*e4b17023SJohn Marino {
2033*e4b17023SJohn Marino gcc_assert (type);
2034*e4b17023SJohn Marino
2035*e4b17023SJohn Marino if (type == error_mark_node)
2036*e4b17023SJohn Marino return;
2037*e4b17023SJohn Marino
2038*e4b17023SJohn Marino /* Do nothing if type has been laid out before. */
2039*e4b17023SJohn Marino if (TYPE_SIZE (type))
2040*e4b17023SJohn Marino return;
2041*e4b17023SJohn Marino
2042*e4b17023SJohn Marino switch (TREE_CODE (type))
2043*e4b17023SJohn Marino {
2044*e4b17023SJohn Marino case LANG_TYPE:
2045*e4b17023SJohn Marino /* This kind of type is the responsibility
2046*e4b17023SJohn Marino of the language-specific code. */
2047*e4b17023SJohn Marino gcc_unreachable ();
2048*e4b17023SJohn Marino
2049*e4b17023SJohn Marino case BOOLEAN_TYPE: /* Used for Java, Pascal, and Chill. */
2050*e4b17023SJohn Marino if (TYPE_PRECISION (type) == 0)
2051*e4b17023SJohn Marino TYPE_PRECISION (type) = 1; /* default to one byte/boolean. */
2052*e4b17023SJohn Marino
2053*e4b17023SJohn Marino /* ... fall through ... */
2054*e4b17023SJohn Marino
2055*e4b17023SJohn Marino case INTEGER_TYPE:
2056*e4b17023SJohn Marino case ENUMERAL_TYPE:
2057*e4b17023SJohn Marino if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
2058*e4b17023SJohn Marino && tree_int_cst_sgn (TYPE_MIN_VALUE (type)) >= 0)
2059*e4b17023SJohn Marino TYPE_UNSIGNED (type) = 1;
2060*e4b17023SJohn Marino
2061*e4b17023SJohn Marino SET_TYPE_MODE (type,
2062*e4b17023SJohn Marino smallest_mode_for_size (TYPE_PRECISION (type), MODE_INT));
2063*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
2064*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
2065*e4b17023SJohn Marino break;
2066*e4b17023SJohn Marino
2067*e4b17023SJohn Marino case REAL_TYPE:
2068*e4b17023SJohn Marino SET_TYPE_MODE (type,
2069*e4b17023SJohn Marino mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0));
2070*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
2071*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
2072*e4b17023SJohn Marino break;
2073*e4b17023SJohn Marino
2074*e4b17023SJohn Marino case FIXED_POINT_TYPE:
2075*e4b17023SJohn Marino /* TYPE_MODE (type) has been set already. */
2076*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
2077*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
2078*e4b17023SJohn Marino break;
2079*e4b17023SJohn Marino
2080*e4b17023SJohn Marino case COMPLEX_TYPE:
2081*e4b17023SJohn Marino TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TREE_TYPE (type));
2082*e4b17023SJohn Marino SET_TYPE_MODE (type,
2083*e4b17023SJohn Marino mode_for_size (2 * TYPE_PRECISION (TREE_TYPE (type)),
2084*e4b17023SJohn Marino (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE
2085*e4b17023SJohn Marino ? MODE_COMPLEX_FLOAT : MODE_COMPLEX_INT),
2086*e4b17023SJohn Marino 0));
2087*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
2088*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
2089*e4b17023SJohn Marino break;
2090*e4b17023SJohn Marino
2091*e4b17023SJohn Marino case VECTOR_TYPE:
2092*e4b17023SJohn Marino {
2093*e4b17023SJohn Marino int nunits = TYPE_VECTOR_SUBPARTS (type);
2094*e4b17023SJohn Marino tree innertype = TREE_TYPE (type);
2095*e4b17023SJohn Marino
2096*e4b17023SJohn Marino gcc_assert (!(nunits & (nunits - 1)));
2097*e4b17023SJohn Marino
2098*e4b17023SJohn Marino /* Find an appropriate mode for the vector type. */
2099*e4b17023SJohn Marino if (TYPE_MODE (type) == VOIDmode)
2100*e4b17023SJohn Marino SET_TYPE_MODE (type,
2101*e4b17023SJohn Marino mode_for_vector (TYPE_MODE (innertype), nunits));
2102*e4b17023SJohn Marino
2103*e4b17023SJohn Marino TYPE_SATURATING (type) = TYPE_SATURATING (TREE_TYPE (type));
2104*e4b17023SJohn Marino TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TREE_TYPE (type));
2105*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = int_const_binop (MULT_EXPR,
2106*e4b17023SJohn Marino TYPE_SIZE_UNIT (innertype),
2107*e4b17023SJohn Marino size_int (nunits));
2108*e4b17023SJohn Marino TYPE_SIZE (type) = int_const_binop (MULT_EXPR, TYPE_SIZE (innertype),
2109*e4b17023SJohn Marino bitsize_int (nunits));
2110*e4b17023SJohn Marino
2111*e4b17023SJohn Marino /* For vector types, we do not default to the mode's alignment.
2112*e4b17023SJohn Marino Instead, query a target hook, defaulting to natural alignment.
2113*e4b17023SJohn Marino This prevents ABI changes depending on whether or not native
2114*e4b17023SJohn Marino vector modes are supported. */
2115*e4b17023SJohn Marino TYPE_ALIGN (type) = targetm.vector_alignment (type);
2116*e4b17023SJohn Marino
2117*e4b17023SJohn Marino /* However, if the underlying mode requires a bigger alignment than
2118*e4b17023SJohn Marino what the target hook provides, we cannot use the mode. For now,
2119*e4b17023SJohn Marino simply reject that case. */
2120*e4b17023SJohn Marino gcc_assert (TYPE_ALIGN (type)
2121*e4b17023SJohn Marino >= GET_MODE_ALIGNMENT (TYPE_MODE (type)));
2122*e4b17023SJohn Marino break;
2123*e4b17023SJohn Marino }
2124*e4b17023SJohn Marino
2125*e4b17023SJohn Marino case VOID_TYPE:
2126*e4b17023SJohn Marino /* This is an incomplete type and so doesn't have a size. */
2127*e4b17023SJohn Marino TYPE_ALIGN (type) = 1;
2128*e4b17023SJohn Marino TYPE_USER_ALIGN (type) = 0;
2129*e4b17023SJohn Marino SET_TYPE_MODE (type, VOIDmode);
2130*e4b17023SJohn Marino break;
2131*e4b17023SJohn Marino
2132*e4b17023SJohn Marino case OFFSET_TYPE:
2133*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (POINTER_SIZE);
2134*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (POINTER_SIZE / BITS_PER_UNIT);
2135*e4b17023SJohn Marino /* A pointer might be MODE_PARTIAL_INT,
2136*e4b17023SJohn Marino but ptrdiff_t must be integral. */
2137*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size (POINTER_SIZE, MODE_INT, 0));
2138*e4b17023SJohn Marino TYPE_PRECISION (type) = POINTER_SIZE;
2139*e4b17023SJohn Marino break;
2140*e4b17023SJohn Marino
2141*e4b17023SJohn Marino case FUNCTION_TYPE:
2142*e4b17023SJohn Marino case METHOD_TYPE:
2143*e4b17023SJohn Marino /* It's hard to see what the mode and size of a function ought to
2144*e4b17023SJohn Marino be, but we do know the alignment is FUNCTION_BOUNDARY, so
2145*e4b17023SJohn Marino make it consistent with that. */
2146*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size (FUNCTION_BOUNDARY, MODE_INT, 0));
2147*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (FUNCTION_BOUNDARY);
2148*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
2149*e4b17023SJohn Marino break;
2150*e4b17023SJohn Marino
2151*e4b17023SJohn Marino case POINTER_TYPE:
2152*e4b17023SJohn Marino case REFERENCE_TYPE:
2153*e4b17023SJohn Marino {
2154*e4b17023SJohn Marino enum machine_mode mode = TYPE_MODE (type);
2155*e4b17023SJohn Marino if (TREE_CODE (type) == REFERENCE_TYPE && reference_types_internal)
2156*e4b17023SJohn Marino {
2157*e4b17023SJohn Marino addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
2158*e4b17023SJohn Marino mode = targetm.addr_space.address_mode (as);
2159*e4b17023SJohn Marino }
2160*e4b17023SJohn Marino
2161*e4b17023SJohn Marino TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode));
2162*e4b17023SJohn Marino TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (mode));
2163*e4b17023SJohn Marino TYPE_UNSIGNED (type) = 1;
2164*e4b17023SJohn Marino TYPE_PRECISION (type) = GET_MODE_BITSIZE (mode);
2165*e4b17023SJohn Marino }
2166*e4b17023SJohn Marino break;
2167*e4b17023SJohn Marino
2168*e4b17023SJohn Marino case ARRAY_TYPE:
2169*e4b17023SJohn Marino {
2170*e4b17023SJohn Marino tree index = TYPE_DOMAIN (type);
2171*e4b17023SJohn Marino tree element = TREE_TYPE (type);
2172*e4b17023SJohn Marino
2173*e4b17023SJohn Marino build_pointer_type (element);
2174*e4b17023SJohn Marino
2175*e4b17023SJohn Marino /* We need to know both bounds in order to compute the size. */
2176*e4b17023SJohn Marino if (index && TYPE_MAX_VALUE (index) && TYPE_MIN_VALUE (index)
2177*e4b17023SJohn Marino && TYPE_SIZE (element))
2178*e4b17023SJohn Marino {
2179*e4b17023SJohn Marino tree ub = TYPE_MAX_VALUE (index);
2180*e4b17023SJohn Marino tree lb = TYPE_MIN_VALUE (index);
2181*e4b17023SJohn Marino tree element_size = TYPE_SIZE (element);
2182*e4b17023SJohn Marino tree length;
2183*e4b17023SJohn Marino
2184*e4b17023SJohn Marino /* Make sure that an array of zero-sized element is zero-sized
2185*e4b17023SJohn Marino regardless of its extent. */
2186*e4b17023SJohn Marino if (integer_zerop (element_size))
2187*e4b17023SJohn Marino length = size_zero_node;
2188*e4b17023SJohn Marino
2189*e4b17023SJohn Marino /* The computation should happen in the original signedness so
2190*e4b17023SJohn Marino that (possible) negative values are handled appropriately
2191*e4b17023SJohn Marino when determining overflow. */
2192*e4b17023SJohn Marino else
2193*e4b17023SJohn Marino length
2194*e4b17023SJohn Marino = fold_convert (sizetype,
2195*e4b17023SJohn Marino size_binop (PLUS_EXPR,
2196*e4b17023SJohn Marino build_int_cst (TREE_TYPE (lb), 1),
2197*e4b17023SJohn Marino size_binop (MINUS_EXPR, ub, lb)));
2198*e4b17023SJohn Marino
2199*e4b17023SJohn Marino TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
2200*e4b17023SJohn Marino fold_convert (bitsizetype,
2201*e4b17023SJohn Marino length));
2202*e4b17023SJohn Marino
2203*e4b17023SJohn Marino /* If we know the size of the element, calculate the total size
2204*e4b17023SJohn Marino directly, rather than do some division thing below. This
2205*e4b17023SJohn Marino optimization helps Fortran assumed-size arrays (where the
2206*e4b17023SJohn Marino size of the array is determined at runtime) substantially. */
2207*e4b17023SJohn Marino if (TYPE_SIZE_UNIT (element))
2208*e4b17023SJohn Marino TYPE_SIZE_UNIT (type)
2209*e4b17023SJohn Marino = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (element), length);
2210*e4b17023SJohn Marino }
2211*e4b17023SJohn Marino
2212*e4b17023SJohn Marino /* Now round the alignment and size,
2213*e4b17023SJohn Marino using machine-dependent criteria if any. */
2214*e4b17023SJohn Marino
2215*e4b17023SJohn Marino #ifdef ROUND_TYPE_ALIGN
2216*e4b17023SJohn Marino TYPE_ALIGN (type)
2217*e4b17023SJohn Marino = ROUND_TYPE_ALIGN (type, TYPE_ALIGN (element), BITS_PER_UNIT);
2218*e4b17023SJohn Marino #else
2219*e4b17023SJohn Marino TYPE_ALIGN (type) = MAX (TYPE_ALIGN (element), BITS_PER_UNIT);
2220*e4b17023SJohn Marino #endif
2221*e4b17023SJohn Marino TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (element);
2222*e4b17023SJohn Marino SET_TYPE_MODE (type, BLKmode);
2223*e4b17023SJohn Marino if (TYPE_SIZE (type) != 0
2224*e4b17023SJohn Marino #ifdef MEMBER_TYPE_FORCES_BLK
2225*e4b17023SJohn Marino && ! MEMBER_TYPE_FORCES_BLK (type, VOIDmode)
2226*e4b17023SJohn Marino #endif
2227*e4b17023SJohn Marino /* BLKmode elements force BLKmode aggregate;
2228*e4b17023SJohn Marino else extract/store fields may lose. */
2229*e4b17023SJohn Marino && (TYPE_MODE (TREE_TYPE (type)) != BLKmode
2230*e4b17023SJohn Marino || TYPE_NO_FORCE_BLK (TREE_TYPE (type))))
2231*e4b17023SJohn Marino {
2232*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_array (TREE_TYPE (type),
2233*e4b17023SJohn Marino TYPE_SIZE (type)));
2234*e4b17023SJohn Marino if (TYPE_MODE (type) != BLKmode
2235*e4b17023SJohn Marino && STRICT_ALIGNMENT && TYPE_ALIGN (type) < BIGGEST_ALIGNMENT
2236*e4b17023SJohn Marino && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (TYPE_MODE (type)))
2237*e4b17023SJohn Marino {
2238*e4b17023SJohn Marino TYPE_NO_FORCE_BLK (type) = 1;
2239*e4b17023SJohn Marino SET_TYPE_MODE (type, BLKmode);
2240*e4b17023SJohn Marino }
2241*e4b17023SJohn Marino }
2242*e4b17023SJohn Marino /* When the element size is constant, check that it is at least as
2243*e4b17023SJohn Marino large as the element alignment. */
2244*e4b17023SJohn Marino if (TYPE_SIZE_UNIT (element)
2245*e4b17023SJohn Marino && TREE_CODE (TYPE_SIZE_UNIT (element)) == INTEGER_CST
2246*e4b17023SJohn Marino /* If TYPE_SIZE_UNIT overflowed, then it is certainly larger than
2247*e4b17023SJohn Marino TYPE_ALIGN_UNIT. */
2248*e4b17023SJohn Marino && !TREE_OVERFLOW (TYPE_SIZE_UNIT (element))
2249*e4b17023SJohn Marino && !integer_zerop (TYPE_SIZE_UNIT (element))
2250*e4b17023SJohn Marino && compare_tree_int (TYPE_SIZE_UNIT (element),
2251*e4b17023SJohn Marino TYPE_ALIGN_UNIT (element)) < 0)
2252*e4b17023SJohn Marino error ("alignment of array elements is greater than element size");
2253*e4b17023SJohn Marino break;
2254*e4b17023SJohn Marino }
2255*e4b17023SJohn Marino
2256*e4b17023SJohn Marino case RECORD_TYPE:
2257*e4b17023SJohn Marino case UNION_TYPE:
2258*e4b17023SJohn Marino case QUAL_UNION_TYPE:
2259*e4b17023SJohn Marino {
2260*e4b17023SJohn Marino tree field;
2261*e4b17023SJohn Marino record_layout_info rli;
2262*e4b17023SJohn Marino
2263*e4b17023SJohn Marino /* Initialize the layout information. */
2264*e4b17023SJohn Marino rli = start_record_layout (type);
2265*e4b17023SJohn Marino
2266*e4b17023SJohn Marino /* If this is a QUAL_UNION_TYPE, we want to process the fields
2267*e4b17023SJohn Marino in the reverse order in building the COND_EXPR that denotes
2268*e4b17023SJohn Marino its size. We reverse them again later. */
2269*e4b17023SJohn Marino if (TREE_CODE (type) == QUAL_UNION_TYPE)
2270*e4b17023SJohn Marino TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
2271*e4b17023SJohn Marino
2272*e4b17023SJohn Marino /* Place all the fields. */
2273*e4b17023SJohn Marino for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
2274*e4b17023SJohn Marino place_field (rli, field);
2275*e4b17023SJohn Marino
2276*e4b17023SJohn Marino if (TREE_CODE (type) == QUAL_UNION_TYPE)
2277*e4b17023SJohn Marino TYPE_FIELDS (type) = nreverse (TYPE_FIELDS (type));
2278*e4b17023SJohn Marino
2279*e4b17023SJohn Marino /* Finish laying out the record. */
2280*e4b17023SJohn Marino finish_record_layout (rli, /*free_p=*/true);
2281*e4b17023SJohn Marino }
2282*e4b17023SJohn Marino break;
2283*e4b17023SJohn Marino
2284*e4b17023SJohn Marino default:
2285*e4b17023SJohn Marino gcc_unreachable ();
2286*e4b17023SJohn Marino }
2287*e4b17023SJohn Marino
2288*e4b17023SJohn Marino /* Compute the final TYPE_SIZE, TYPE_ALIGN, etc. for TYPE. For
2289*e4b17023SJohn Marino records and unions, finish_record_layout already called this
2290*e4b17023SJohn Marino function. */
2291*e4b17023SJohn Marino if (TREE_CODE (type) != RECORD_TYPE
2292*e4b17023SJohn Marino && TREE_CODE (type) != UNION_TYPE
2293*e4b17023SJohn Marino && TREE_CODE (type) != QUAL_UNION_TYPE)
2294*e4b17023SJohn Marino finalize_type_size (type);
2295*e4b17023SJohn Marino
2296*e4b17023SJohn Marino /* We should never see alias sets on incomplete aggregates. And we
2297*e4b17023SJohn Marino should not call layout_type on not incomplete aggregates. */
2298*e4b17023SJohn Marino if (AGGREGATE_TYPE_P (type))
2299*e4b17023SJohn Marino gcc_assert (!TYPE_ALIAS_SET_KNOWN_P (type));
2300*e4b17023SJohn Marino }
2301*e4b17023SJohn Marino
2302*e4b17023SJohn Marino /* Vector types need to re-check the target flags each time we report
2303*e4b17023SJohn Marino the machine mode. We need to do this because attribute target can
2304*e4b17023SJohn Marino change the result of vector_mode_supported_p and have_regs_of_mode
2305*e4b17023SJohn Marino on a per-function basis. Thus the TYPE_MODE of a VECTOR_TYPE can
2306*e4b17023SJohn Marino change on a per-function basis. */
2307*e4b17023SJohn Marino /* ??? Possibly a better solution is to run through all the types
2308*e4b17023SJohn Marino referenced by a function and re-compute the TYPE_MODE once, rather
2309*e4b17023SJohn Marino than make the TYPE_MODE macro call a function. */
2310*e4b17023SJohn Marino
2311*e4b17023SJohn Marino enum machine_mode
vector_type_mode(const_tree t)2312*e4b17023SJohn Marino vector_type_mode (const_tree t)
2313*e4b17023SJohn Marino {
2314*e4b17023SJohn Marino enum machine_mode mode;
2315*e4b17023SJohn Marino
2316*e4b17023SJohn Marino gcc_assert (TREE_CODE (t) == VECTOR_TYPE);
2317*e4b17023SJohn Marino
2318*e4b17023SJohn Marino mode = t->type_common.mode;
2319*e4b17023SJohn Marino if (VECTOR_MODE_P (mode)
2320*e4b17023SJohn Marino && (!targetm.vector_mode_supported_p (mode)
2321*e4b17023SJohn Marino || !have_regs_of_mode[mode]))
2322*e4b17023SJohn Marino {
2323*e4b17023SJohn Marino enum machine_mode innermode = TREE_TYPE (t)->type_common.mode;
2324*e4b17023SJohn Marino
2325*e4b17023SJohn Marino /* For integers, try mapping it to a same-sized scalar mode. */
2326*e4b17023SJohn Marino if (GET_MODE_CLASS (innermode) == MODE_INT)
2327*e4b17023SJohn Marino {
2328*e4b17023SJohn Marino mode = mode_for_size (TYPE_VECTOR_SUBPARTS (t)
2329*e4b17023SJohn Marino * GET_MODE_BITSIZE (innermode), MODE_INT, 0);
2330*e4b17023SJohn Marino
2331*e4b17023SJohn Marino if (mode != VOIDmode && have_regs_of_mode[mode])
2332*e4b17023SJohn Marino return mode;
2333*e4b17023SJohn Marino }
2334*e4b17023SJohn Marino
2335*e4b17023SJohn Marino return BLKmode;
2336*e4b17023SJohn Marino }
2337*e4b17023SJohn Marino
2338*e4b17023SJohn Marino return mode;
2339*e4b17023SJohn Marino }
2340*e4b17023SJohn Marino
2341*e4b17023SJohn Marino /* Create and return a type for signed integers of PRECISION bits. */
2342*e4b17023SJohn Marino
2343*e4b17023SJohn Marino tree
make_signed_type(int precision)2344*e4b17023SJohn Marino make_signed_type (int precision)
2345*e4b17023SJohn Marino {
2346*e4b17023SJohn Marino tree type = make_node (INTEGER_TYPE);
2347*e4b17023SJohn Marino
2348*e4b17023SJohn Marino TYPE_PRECISION (type) = precision;
2349*e4b17023SJohn Marino
2350*e4b17023SJohn Marino fixup_signed_type (type);
2351*e4b17023SJohn Marino return type;
2352*e4b17023SJohn Marino }
2353*e4b17023SJohn Marino
2354*e4b17023SJohn Marino /* Create and return a type for unsigned integers of PRECISION bits. */
2355*e4b17023SJohn Marino
2356*e4b17023SJohn Marino tree
make_unsigned_type(int precision)2357*e4b17023SJohn Marino make_unsigned_type (int precision)
2358*e4b17023SJohn Marino {
2359*e4b17023SJohn Marino tree type = make_node (INTEGER_TYPE);
2360*e4b17023SJohn Marino
2361*e4b17023SJohn Marino TYPE_PRECISION (type) = precision;
2362*e4b17023SJohn Marino
2363*e4b17023SJohn Marino fixup_unsigned_type (type);
2364*e4b17023SJohn Marino return type;
2365*e4b17023SJohn Marino }
2366*e4b17023SJohn Marino
2367*e4b17023SJohn Marino /* Create and return a type for fract of PRECISION bits, UNSIGNEDP,
2368*e4b17023SJohn Marino and SATP. */
2369*e4b17023SJohn Marino
2370*e4b17023SJohn Marino tree
make_fract_type(int precision,int unsignedp,int satp)2371*e4b17023SJohn Marino make_fract_type (int precision, int unsignedp, int satp)
2372*e4b17023SJohn Marino {
2373*e4b17023SJohn Marino tree type = make_node (FIXED_POINT_TYPE);
2374*e4b17023SJohn Marino
2375*e4b17023SJohn Marino TYPE_PRECISION (type) = precision;
2376*e4b17023SJohn Marino
2377*e4b17023SJohn Marino if (satp)
2378*e4b17023SJohn Marino TYPE_SATURATING (type) = 1;
2379*e4b17023SJohn Marino
2380*e4b17023SJohn Marino /* Lay out the type: set its alignment, size, etc. */
2381*e4b17023SJohn Marino if (unsignedp)
2382*e4b17023SJohn Marino {
2383*e4b17023SJohn Marino TYPE_UNSIGNED (type) = 1;
2384*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size (precision, MODE_UFRACT, 0));
2385*e4b17023SJohn Marino }
2386*e4b17023SJohn Marino else
2387*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size (precision, MODE_FRACT, 0));
2388*e4b17023SJohn Marino layout_type (type);
2389*e4b17023SJohn Marino
2390*e4b17023SJohn Marino return type;
2391*e4b17023SJohn Marino }
2392*e4b17023SJohn Marino
2393*e4b17023SJohn Marino /* Create and return a type for accum of PRECISION bits, UNSIGNEDP,
2394*e4b17023SJohn Marino and SATP. */
2395*e4b17023SJohn Marino
2396*e4b17023SJohn Marino tree
make_accum_type(int precision,int unsignedp,int satp)2397*e4b17023SJohn Marino make_accum_type (int precision, int unsignedp, int satp)
2398*e4b17023SJohn Marino {
2399*e4b17023SJohn Marino tree type = make_node (FIXED_POINT_TYPE);
2400*e4b17023SJohn Marino
2401*e4b17023SJohn Marino TYPE_PRECISION (type) = precision;
2402*e4b17023SJohn Marino
2403*e4b17023SJohn Marino if (satp)
2404*e4b17023SJohn Marino TYPE_SATURATING (type) = 1;
2405*e4b17023SJohn Marino
2406*e4b17023SJohn Marino /* Lay out the type: set its alignment, size, etc. */
2407*e4b17023SJohn Marino if (unsignedp)
2408*e4b17023SJohn Marino {
2409*e4b17023SJohn Marino TYPE_UNSIGNED (type) = 1;
2410*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size (precision, MODE_UACCUM, 0));
2411*e4b17023SJohn Marino }
2412*e4b17023SJohn Marino else
2413*e4b17023SJohn Marino SET_TYPE_MODE (type, mode_for_size (precision, MODE_ACCUM, 0));
2414*e4b17023SJohn Marino layout_type (type);
2415*e4b17023SJohn Marino
2416*e4b17023SJohn Marino return type;
2417*e4b17023SJohn Marino }
2418*e4b17023SJohn Marino
2419*e4b17023SJohn Marino /* Initialize sizetypes so layout_type can use them. */
2420*e4b17023SJohn Marino
2421*e4b17023SJohn Marino void
initialize_sizetypes(void)2422*e4b17023SJohn Marino initialize_sizetypes (void)
2423*e4b17023SJohn Marino {
2424*e4b17023SJohn Marino int precision, bprecision;
2425*e4b17023SJohn Marino
2426*e4b17023SJohn Marino /* Get sizetypes precision from the SIZE_TYPE target macro. */
2427*e4b17023SJohn Marino if (strcmp (SIZE_TYPE, "unsigned int") == 0)
2428*e4b17023SJohn Marino precision = INT_TYPE_SIZE;
2429*e4b17023SJohn Marino else if (strcmp (SIZE_TYPE, "long unsigned int") == 0)
2430*e4b17023SJohn Marino precision = LONG_TYPE_SIZE;
2431*e4b17023SJohn Marino else if (strcmp (SIZE_TYPE, "long long unsigned int") == 0)
2432*e4b17023SJohn Marino precision = LONG_LONG_TYPE_SIZE;
2433*e4b17023SJohn Marino else if (strcmp (SIZE_TYPE, "short unsigned int") == 0)
2434*e4b17023SJohn Marino precision = SHORT_TYPE_SIZE;
2435*e4b17023SJohn Marino else
2436*e4b17023SJohn Marino gcc_unreachable ();
2437*e4b17023SJohn Marino
2438*e4b17023SJohn Marino bprecision
2439*e4b17023SJohn Marino = MIN (precision + BITS_PER_UNIT_LOG + 1, MAX_FIXED_MODE_SIZE);
2440*e4b17023SJohn Marino bprecision
2441*e4b17023SJohn Marino = GET_MODE_PRECISION (smallest_mode_for_size (bprecision, MODE_INT));
2442*e4b17023SJohn Marino if (bprecision > HOST_BITS_PER_WIDE_INT * 2)
2443*e4b17023SJohn Marino bprecision = HOST_BITS_PER_WIDE_INT * 2;
2444*e4b17023SJohn Marino
2445*e4b17023SJohn Marino /* Create stubs for sizetype and bitsizetype so we can create constants. */
2446*e4b17023SJohn Marino sizetype = make_node (INTEGER_TYPE);
2447*e4b17023SJohn Marino TYPE_NAME (sizetype) = get_identifier ("sizetype");
2448*e4b17023SJohn Marino TYPE_PRECISION (sizetype) = precision;
2449*e4b17023SJohn Marino TYPE_UNSIGNED (sizetype) = 1;
2450*e4b17023SJohn Marino TYPE_IS_SIZETYPE (sizetype) = 1;
2451*e4b17023SJohn Marino bitsizetype = make_node (INTEGER_TYPE);
2452*e4b17023SJohn Marino TYPE_NAME (bitsizetype) = get_identifier ("bitsizetype");
2453*e4b17023SJohn Marino TYPE_PRECISION (bitsizetype) = bprecision;
2454*e4b17023SJohn Marino TYPE_UNSIGNED (bitsizetype) = 1;
2455*e4b17023SJohn Marino TYPE_IS_SIZETYPE (bitsizetype) = 1;
2456*e4b17023SJohn Marino
2457*e4b17023SJohn Marino /* Now layout both types manually. */
2458*e4b17023SJohn Marino SET_TYPE_MODE (sizetype, smallest_mode_for_size (precision, MODE_INT));
2459*e4b17023SJohn Marino TYPE_ALIGN (sizetype) = GET_MODE_ALIGNMENT (TYPE_MODE (sizetype));
2460*e4b17023SJohn Marino TYPE_SIZE (sizetype) = bitsize_int (precision);
2461*e4b17023SJohn Marino TYPE_SIZE_UNIT (sizetype) = size_int (GET_MODE_SIZE (TYPE_MODE (sizetype)));
2462*e4b17023SJohn Marino set_min_and_max_values_for_integral_type (sizetype, precision,
2463*e4b17023SJohn Marino /*is_unsigned=*/true);
2464*e4b17023SJohn Marino /* sizetype is unsigned but we need to fix TYPE_MAX_VALUE so that it is
2465*e4b17023SJohn Marino sign-extended in a way consistent with force_fit_type. */
2466*e4b17023SJohn Marino TYPE_MAX_VALUE (sizetype)
2467*e4b17023SJohn Marino = double_int_to_tree (sizetype,
2468*e4b17023SJohn Marino tree_to_double_int (TYPE_MAX_VALUE (sizetype)));
2469*e4b17023SJohn Marino
2470*e4b17023SJohn Marino SET_TYPE_MODE (bitsizetype, smallest_mode_for_size (bprecision, MODE_INT));
2471*e4b17023SJohn Marino TYPE_ALIGN (bitsizetype) = GET_MODE_ALIGNMENT (TYPE_MODE (bitsizetype));
2472*e4b17023SJohn Marino TYPE_SIZE (bitsizetype) = bitsize_int (bprecision);
2473*e4b17023SJohn Marino TYPE_SIZE_UNIT (bitsizetype)
2474*e4b17023SJohn Marino = size_int (GET_MODE_SIZE (TYPE_MODE (bitsizetype)));
2475*e4b17023SJohn Marino set_min_and_max_values_for_integral_type (bitsizetype, bprecision,
2476*e4b17023SJohn Marino /*is_unsigned=*/true);
2477*e4b17023SJohn Marino /* bitsizetype is unsigned but we need to fix TYPE_MAX_VALUE so that it is
2478*e4b17023SJohn Marino sign-extended in a way consistent with force_fit_type. */
2479*e4b17023SJohn Marino TYPE_MAX_VALUE (bitsizetype)
2480*e4b17023SJohn Marino = double_int_to_tree (bitsizetype,
2481*e4b17023SJohn Marino tree_to_double_int (TYPE_MAX_VALUE (bitsizetype)));
2482*e4b17023SJohn Marino
2483*e4b17023SJohn Marino /* Create the signed variants of *sizetype. */
2484*e4b17023SJohn Marino ssizetype = make_signed_type (TYPE_PRECISION (sizetype));
2485*e4b17023SJohn Marino TYPE_NAME (ssizetype) = get_identifier ("ssizetype");
2486*e4b17023SJohn Marino TYPE_IS_SIZETYPE (ssizetype) = 1;
2487*e4b17023SJohn Marino sbitsizetype = make_signed_type (TYPE_PRECISION (bitsizetype));
2488*e4b17023SJohn Marino TYPE_NAME (sbitsizetype) = get_identifier ("sbitsizetype");
2489*e4b17023SJohn Marino TYPE_IS_SIZETYPE (sbitsizetype) = 1;
2490*e4b17023SJohn Marino }
2491*e4b17023SJohn Marino
2492*e4b17023SJohn Marino /* TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE
2493*e4b17023SJohn Marino or BOOLEAN_TYPE. Set TYPE_MIN_VALUE and TYPE_MAX_VALUE
2494*e4b17023SJohn Marino for TYPE, based on the PRECISION and whether or not the TYPE
2495*e4b17023SJohn Marino IS_UNSIGNED. PRECISION need not correspond to a width supported
2496*e4b17023SJohn Marino natively by the hardware; for example, on a machine with 8-bit,
2497*e4b17023SJohn Marino 16-bit, and 32-bit register modes, PRECISION might be 7, 23, or
2498*e4b17023SJohn Marino 61. */
2499*e4b17023SJohn Marino
2500*e4b17023SJohn Marino void
set_min_and_max_values_for_integral_type(tree type,int precision,bool is_unsigned)2501*e4b17023SJohn Marino set_min_and_max_values_for_integral_type (tree type,
2502*e4b17023SJohn Marino int precision,
2503*e4b17023SJohn Marino bool is_unsigned)
2504*e4b17023SJohn Marino {
2505*e4b17023SJohn Marino tree min_value;
2506*e4b17023SJohn Marino tree max_value;
2507*e4b17023SJohn Marino
2508*e4b17023SJohn Marino if (is_unsigned)
2509*e4b17023SJohn Marino {
2510*e4b17023SJohn Marino min_value = build_int_cst (type, 0);
2511*e4b17023SJohn Marino max_value
2512*e4b17023SJohn Marino = build_int_cst_wide (type, precision - HOST_BITS_PER_WIDE_INT >= 0
2513*e4b17023SJohn Marino ? -1
2514*e4b17023SJohn Marino : ((HOST_WIDE_INT) 1 << precision) - 1,
2515*e4b17023SJohn Marino precision - HOST_BITS_PER_WIDE_INT > 0
2516*e4b17023SJohn Marino ? ((unsigned HOST_WIDE_INT) ~0
2517*e4b17023SJohn Marino >> (HOST_BITS_PER_WIDE_INT
2518*e4b17023SJohn Marino - (precision - HOST_BITS_PER_WIDE_INT)))
2519*e4b17023SJohn Marino : 0);
2520*e4b17023SJohn Marino }
2521*e4b17023SJohn Marino else
2522*e4b17023SJohn Marino {
2523*e4b17023SJohn Marino min_value
2524*e4b17023SJohn Marino = build_int_cst_wide (type,
2525*e4b17023SJohn Marino (precision - HOST_BITS_PER_WIDE_INT > 0
2526*e4b17023SJohn Marino ? 0
2527*e4b17023SJohn Marino : (HOST_WIDE_INT) (-1) << (precision - 1)),
2528*e4b17023SJohn Marino (((HOST_WIDE_INT) (-1)
2529*e4b17023SJohn Marino << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
2530*e4b17023SJohn Marino ? precision - HOST_BITS_PER_WIDE_INT - 1
2531*e4b17023SJohn Marino : 0))));
2532*e4b17023SJohn Marino max_value
2533*e4b17023SJohn Marino = build_int_cst_wide (type,
2534*e4b17023SJohn Marino (precision - HOST_BITS_PER_WIDE_INT > 0
2535*e4b17023SJohn Marino ? -1
2536*e4b17023SJohn Marino : ((HOST_WIDE_INT) 1 << (precision - 1)) - 1),
2537*e4b17023SJohn Marino (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
2538*e4b17023SJohn Marino ? (((HOST_WIDE_INT) 1
2539*e4b17023SJohn Marino << (precision - HOST_BITS_PER_WIDE_INT - 1))) - 1
2540*e4b17023SJohn Marino : 0));
2541*e4b17023SJohn Marino }
2542*e4b17023SJohn Marino
2543*e4b17023SJohn Marino TYPE_MIN_VALUE (type) = min_value;
2544*e4b17023SJohn Marino TYPE_MAX_VALUE (type) = max_value;
2545*e4b17023SJohn Marino }
2546*e4b17023SJohn Marino
2547*e4b17023SJohn Marino /* Set the extreme values of TYPE based on its precision in bits,
2548*e4b17023SJohn Marino then lay it out. Used when make_signed_type won't do
2549*e4b17023SJohn Marino because the tree code is not INTEGER_TYPE.
2550*e4b17023SJohn Marino E.g. for Pascal, when the -fsigned-char option is given. */
2551*e4b17023SJohn Marino
2552*e4b17023SJohn Marino void
fixup_signed_type(tree type)2553*e4b17023SJohn Marino fixup_signed_type (tree type)
2554*e4b17023SJohn Marino {
2555*e4b17023SJohn Marino int precision = TYPE_PRECISION (type);
2556*e4b17023SJohn Marino
2557*e4b17023SJohn Marino /* We can not represent properly constants greater then
2558*e4b17023SJohn Marino 2 * HOST_BITS_PER_WIDE_INT, still we need the types
2559*e4b17023SJohn Marino as they are used by i386 vector extensions and friends. */
2560*e4b17023SJohn Marino if (precision > HOST_BITS_PER_WIDE_INT * 2)
2561*e4b17023SJohn Marino precision = HOST_BITS_PER_WIDE_INT * 2;
2562*e4b17023SJohn Marino
2563*e4b17023SJohn Marino set_min_and_max_values_for_integral_type (type, precision,
2564*e4b17023SJohn Marino /*is_unsigned=*/false);
2565*e4b17023SJohn Marino
2566*e4b17023SJohn Marino /* Lay out the type: set its alignment, size, etc. */
2567*e4b17023SJohn Marino layout_type (type);
2568*e4b17023SJohn Marino }
2569*e4b17023SJohn Marino
2570*e4b17023SJohn Marino /* Set the extreme values of TYPE based on its precision in bits,
2571*e4b17023SJohn Marino then lay it out. This is used both in `make_unsigned_type'
2572*e4b17023SJohn Marino and for enumeral types. */
2573*e4b17023SJohn Marino
2574*e4b17023SJohn Marino void
fixup_unsigned_type(tree type)2575*e4b17023SJohn Marino fixup_unsigned_type (tree type)
2576*e4b17023SJohn Marino {
2577*e4b17023SJohn Marino int precision = TYPE_PRECISION (type);
2578*e4b17023SJohn Marino
2579*e4b17023SJohn Marino /* We can not represent properly constants greater then
2580*e4b17023SJohn Marino 2 * HOST_BITS_PER_WIDE_INT, still we need the types
2581*e4b17023SJohn Marino as they are used by i386 vector extensions and friends. */
2582*e4b17023SJohn Marino if (precision > HOST_BITS_PER_WIDE_INT * 2)
2583*e4b17023SJohn Marino precision = HOST_BITS_PER_WIDE_INT * 2;
2584*e4b17023SJohn Marino
2585*e4b17023SJohn Marino TYPE_UNSIGNED (type) = 1;
2586*e4b17023SJohn Marino
2587*e4b17023SJohn Marino set_min_and_max_values_for_integral_type (type, precision,
2588*e4b17023SJohn Marino /*is_unsigned=*/true);
2589*e4b17023SJohn Marino
2590*e4b17023SJohn Marino /* Lay out the type: set its alignment, size, etc. */
2591*e4b17023SJohn Marino layout_type (type);
2592*e4b17023SJohn Marino }
2593*e4b17023SJohn Marino
2594*e4b17023SJohn Marino /* Find the best machine mode to use when referencing a bit field of length
2595*e4b17023SJohn Marino BITSIZE bits starting at BITPOS.
2596*e4b17023SJohn Marino
2597*e4b17023SJohn Marino BITREGION_START is the bit position of the first bit in this
2598*e4b17023SJohn Marino sequence of bit fields. BITREGION_END is the last bit in this
2599*e4b17023SJohn Marino sequence. If these two fields are non-zero, we should restrict the
2600*e4b17023SJohn Marino memory access to a maximum sized chunk of
2601*e4b17023SJohn Marino BITREGION_END - BITREGION_START + 1. Otherwise, we are allowed to touch
2602*e4b17023SJohn Marino any adjacent non bit-fields.
2603*e4b17023SJohn Marino
2604*e4b17023SJohn Marino The underlying object is known to be aligned to a boundary of ALIGN bits.
2605*e4b17023SJohn Marino If LARGEST_MODE is not VOIDmode, it means that we should not use a mode
2606*e4b17023SJohn Marino larger than LARGEST_MODE (usually SImode).
2607*e4b17023SJohn Marino
2608*e4b17023SJohn Marino If no mode meets all these conditions, we return VOIDmode.
2609*e4b17023SJohn Marino
2610*e4b17023SJohn Marino If VOLATILEP is false and SLOW_BYTE_ACCESS is false, we return the
2611*e4b17023SJohn Marino smallest mode meeting these conditions.
2612*e4b17023SJohn Marino
2613*e4b17023SJohn Marino If VOLATILEP is false and SLOW_BYTE_ACCESS is true, we return the
2614*e4b17023SJohn Marino largest mode (but a mode no wider than UNITS_PER_WORD) that meets
2615*e4b17023SJohn Marino all the conditions.
2616*e4b17023SJohn Marino
2617*e4b17023SJohn Marino If VOLATILEP is true the narrow_volatile_bitfields target hook is used to
2618*e4b17023SJohn Marino decide which of the above modes should be used. */
2619*e4b17023SJohn Marino
2620*e4b17023SJohn Marino enum machine_mode
get_best_mode(int bitsize,int bitpos,unsigned HOST_WIDE_INT bitregion_start,unsigned HOST_WIDE_INT bitregion_end,unsigned int align,enum machine_mode largest_mode,int volatilep)2621*e4b17023SJohn Marino get_best_mode (int bitsize, int bitpos,
2622*e4b17023SJohn Marino unsigned HOST_WIDE_INT bitregion_start,
2623*e4b17023SJohn Marino unsigned HOST_WIDE_INT bitregion_end,
2624*e4b17023SJohn Marino unsigned int align,
2625*e4b17023SJohn Marino enum machine_mode largest_mode, int volatilep)
2626*e4b17023SJohn Marino {
2627*e4b17023SJohn Marino enum machine_mode mode;
2628*e4b17023SJohn Marino unsigned int unit = 0;
2629*e4b17023SJohn Marino unsigned HOST_WIDE_INT maxbits;
2630*e4b17023SJohn Marino
2631*e4b17023SJohn Marino /* If unset, no restriction. */
2632*e4b17023SJohn Marino if (!bitregion_end)
2633*e4b17023SJohn Marino maxbits = MAX_FIXED_MODE_SIZE;
2634*e4b17023SJohn Marino else
2635*e4b17023SJohn Marino maxbits = bitregion_end - bitregion_start + 1;
2636*e4b17023SJohn Marino
2637*e4b17023SJohn Marino /* Find the narrowest integer mode that contains the bit field. */
2638*e4b17023SJohn Marino for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2639*e4b17023SJohn Marino mode = GET_MODE_WIDER_MODE (mode))
2640*e4b17023SJohn Marino {
2641*e4b17023SJohn Marino unit = GET_MODE_BITSIZE (mode);
2642*e4b17023SJohn Marino if (unit == GET_MODE_PRECISION (mode)
2643*e4b17023SJohn Marino && (bitpos % unit) + bitsize <= unit)
2644*e4b17023SJohn Marino break;
2645*e4b17023SJohn Marino }
2646*e4b17023SJohn Marino
2647*e4b17023SJohn Marino if (mode == VOIDmode
2648*e4b17023SJohn Marino /* It is tempting to omit the following line
2649*e4b17023SJohn Marino if STRICT_ALIGNMENT is true.
2650*e4b17023SJohn Marino But that is incorrect, since if the bitfield uses part of 3 bytes
2651*e4b17023SJohn Marino and we use a 4-byte mode, we could get a spurious segv
2652*e4b17023SJohn Marino if the extra 4th byte is past the end of memory.
2653*e4b17023SJohn Marino (Though at least one Unix compiler ignores this problem:
2654*e4b17023SJohn Marino that on the Sequent 386 machine. */
2655*e4b17023SJohn Marino || MIN (unit, BIGGEST_ALIGNMENT) > align
2656*e4b17023SJohn Marino || (largest_mode != VOIDmode && unit > GET_MODE_BITSIZE (largest_mode))
2657*e4b17023SJohn Marino || unit > maxbits
2658*e4b17023SJohn Marino || (bitregion_end
2659*e4b17023SJohn Marino && bitpos - (bitpos % unit) + unit > bitregion_end + 1))
2660*e4b17023SJohn Marino return VOIDmode;
2661*e4b17023SJohn Marino
2662*e4b17023SJohn Marino if ((SLOW_BYTE_ACCESS && ! volatilep)
2663*e4b17023SJohn Marino || (volatilep && !targetm.narrow_volatile_bitfield ()))
2664*e4b17023SJohn Marino {
2665*e4b17023SJohn Marino enum machine_mode wide_mode = VOIDmode, tmode;
2666*e4b17023SJohn Marino
2667*e4b17023SJohn Marino for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT); tmode != VOIDmode;
2668*e4b17023SJohn Marino tmode = GET_MODE_WIDER_MODE (tmode))
2669*e4b17023SJohn Marino {
2670*e4b17023SJohn Marino unit = GET_MODE_BITSIZE (tmode);
2671*e4b17023SJohn Marino if (unit == GET_MODE_PRECISION (tmode)
2672*e4b17023SJohn Marino && bitpos / unit == (bitpos + bitsize - 1) / unit
2673*e4b17023SJohn Marino && unit <= BITS_PER_WORD
2674*e4b17023SJohn Marino && unit <= MIN (align, BIGGEST_ALIGNMENT)
2675*e4b17023SJohn Marino && unit <= maxbits
2676*e4b17023SJohn Marino && (largest_mode == VOIDmode
2677*e4b17023SJohn Marino || unit <= GET_MODE_BITSIZE (largest_mode))
2678*e4b17023SJohn Marino && (bitregion_end == 0
2679*e4b17023SJohn Marino || bitpos - (bitpos % unit) + unit <= bitregion_end + 1))
2680*e4b17023SJohn Marino wide_mode = tmode;
2681*e4b17023SJohn Marino }
2682*e4b17023SJohn Marino
2683*e4b17023SJohn Marino if (wide_mode != VOIDmode)
2684*e4b17023SJohn Marino return wide_mode;
2685*e4b17023SJohn Marino }
2686*e4b17023SJohn Marino
2687*e4b17023SJohn Marino return mode;
2688*e4b17023SJohn Marino }
2689*e4b17023SJohn Marino
2690*e4b17023SJohn Marino /* Gets minimal and maximal values for MODE (signed or unsigned depending on
2691*e4b17023SJohn Marino SIGN). The returned constants are made to be usable in TARGET_MODE. */
2692*e4b17023SJohn Marino
2693*e4b17023SJohn Marino void
get_mode_bounds(enum machine_mode mode,int sign,enum machine_mode target_mode,rtx * mmin,rtx * mmax)2694*e4b17023SJohn Marino get_mode_bounds (enum machine_mode mode, int sign,
2695*e4b17023SJohn Marino enum machine_mode target_mode,
2696*e4b17023SJohn Marino rtx *mmin, rtx *mmax)
2697*e4b17023SJohn Marino {
2698*e4b17023SJohn Marino unsigned size = GET_MODE_BITSIZE (mode);
2699*e4b17023SJohn Marino unsigned HOST_WIDE_INT min_val, max_val;
2700*e4b17023SJohn Marino
2701*e4b17023SJohn Marino gcc_assert (size <= HOST_BITS_PER_WIDE_INT);
2702*e4b17023SJohn Marino
2703*e4b17023SJohn Marino if (sign)
2704*e4b17023SJohn Marino {
2705*e4b17023SJohn Marino min_val = -((unsigned HOST_WIDE_INT) 1 << (size - 1));
2706*e4b17023SJohn Marino max_val = ((unsigned HOST_WIDE_INT) 1 << (size - 1)) - 1;
2707*e4b17023SJohn Marino }
2708*e4b17023SJohn Marino else
2709*e4b17023SJohn Marino {
2710*e4b17023SJohn Marino min_val = 0;
2711*e4b17023SJohn Marino max_val = ((unsigned HOST_WIDE_INT) 1 << (size - 1) << 1) - 1;
2712*e4b17023SJohn Marino }
2713*e4b17023SJohn Marino
2714*e4b17023SJohn Marino *mmin = gen_int_mode (min_val, target_mode);
2715*e4b17023SJohn Marino *mmax = gen_int_mode (max_val, target_mode);
2716*e4b17023SJohn Marino }
2717*e4b17023SJohn Marino
2718*e4b17023SJohn Marino #include "gt-stor-layout.h"
2719