1 2002-08-22 Jason Merrill <jason@redhat.com>
3 * langhooks-def.h (LANG_HOOKS_EXPR_SIZE): New macro.
4 * langhooks.c (lhd_expr_size): Define default.
5 * langhooks.h (struct lang_hooks): Add expr_size.
6 * explow.c (expr_size): Call it.
7 (int_expr_size): New fn.
9 * expr.c (expand_expr) [CONSTRUCTOR]: Use it to calculate how
13 * search.c (check_final_overrider): No longer static.
14 * class.c (update_vtable_entry_for_fn): Call it.
17 * cp-lang.c (LANG_HOOKS_EXPR_SIZE): Define.
18 (cp_expr_size): New fn.
19 * call.c (convert_arg_to_ellipsis): Promote non-POD warning to error.
20 * typeck.c (build_modify_expr): Don't use save_expr on an lvalue.
22 --- gcc/cp/call.c.jj 2002-04-15 14:48:51.000000000 +0200
23 +++ gcc/cp/call.c 2002-08-23 13:51:08.000000000 +0200
24 @@ -4022,9 +4022,12 @@ convert_arg_to_ellipsis (arg)
26 if (arg != error_mark_node && ! pod_type_p (TREE_TYPE (arg)))
28 - /* Undefined behaviour [expr.call] 5.2.2/7. */
29 - warning ("cannot pass objects of non-POD type `%#T' through `...'",
31 + /* Undefined behaviour [expr.call] 5.2.2/7. We used to just warn
32 + here and do a bitwise copy, but now cp_expr_size will abort if we
34 + error ("cannot pass objects of non-POD type `%#T' through `...'",
36 + arg = error_mark_node;
40 --- gcc/cp/class.c.jj 2002-08-05 18:30:31.000000000 +0200
41 +++ gcc/cp/class.c 2002-08-23 13:51:08.000000000 +0200
42 @@ -2454,6 +2454,10 @@ update_vtable_entry_for_fn (t, binfo, fn
43 if (overrider == error_mark_node)
46 + /* Check for unsupported covariant returns again now that we've
47 + calculated the base offsets. */
48 + check_final_overrider (TREE_PURPOSE (overrider), fn);
50 /* Assume that we will produce a thunk that convert all the way to
51 the final overrider, and not to an intermediate virtual base. */
52 virtual_base = NULL_TREE;
53 --- gcc/cp/cp-lang.c.jj 2002-05-25 00:02:21.000000000 +0200
54 +++ gcc/cp/cp-lang.c 2002-08-23 13:51:08.000000000 +0200
55 @@ -28,7 +28,8 @@ Boston, MA 02111-1307, USA. */
56 #include "langhooks.h"
57 #include "langhooks-def.h"
59 -static HOST_WIDE_INT cxx_get_alias_set PARAMS ((tree));
60 +static HOST_WIDE_INT cxx_get_alias_set PARAMS ((tree));
61 +static tree cp_expr_size PARAMS ((tree));
63 #undef LANG_HOOKS_NAME
64 #define LANG_HOOKS_NAME "GNU C++"
65 @@ -91,6 +92,8 @@ static HOST_WIDE_INT cxx_get_alias_set P
66 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree
67 #undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN
68 #define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals
69 +#undef LANG_HOOKS_EXPR_SIZE
70 +#define LANG_HOOKS_EXPR_SIZE cp_expr_size
72 /* Each front end provides its own hooks, for toplev.c. */
73 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
74 @@ -108,3 +111,28 @@ cxx_get_alias_set (t)
76 return c_common_get_alias_set (t);
79 +/* Langhook for expr_size: Tell the backend that the value of an expression
80 + of non-POD class type does not include any tail padding; a derived class
81 + might have allocated something there. */
87 + if (CLASS_TYPE_P (TREE_TYPE (exp)))
89 + /* The backend should not be interested in the size of an expression
90 + of a type with both of these set; all copies of such types must go
91 + through a constructor or assignment op. */
92 + if (TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp))
93 + && TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)))
95 + /* This would be wrong for a type with virtual bases, but they are
96 + caught by the abort above. */
97 + return CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp));
100 + /* Use the default code. */
101 + return lhd_expr_size (exp);
103 --- gcc/cp/cp-tree.h.jj 2002-07-27 01:31:05.000000000 +0200
104 +++ gcc/cp/cp-tree.h 2002-08-23 13:51:08.000000000 +0200
105 @@ -4084,6 +4084,7 @@ extern tree lookup_conversions PARAMS
106 extern tree binfo_for_vtable PARAMS ((tree));
107 extern tree binfo_from_vbase PARAMS ((tree));
108 extern tree look_for_overrides_here PARAMS ((tree, tree));
109 +extern int check_final_overrider PARAMS ((tree, tree));
110 extern tree dfs_walk PARAMS ((tree,
111 tree (*) (tree, void *),
112 tree (*) (tree, void *),
113 --- gcc/cp/search.c.jj 2002-04-23 20:29:00.000000000 +0200
114 +++ gcc/cp/search.c 2002-08-23 13:51:08.000000000 +0200
115 @@ -100,7 +100,6 @@ static tree dfs_push_decls PARAMS ((tree
116 static tree dfs_unuse_fields PARAMS ((tree, void *));
117 static tree add_conversions PARAMS ((tree, void *));
118 static int covariant_return_p PARAMS ((tree, tree));
119 -static int check_final_overrider PARAMS ((tree, tree));
120 static int look_for_overrides_r PARAMS ((tree, tree));
121 static struct search_level *push_search_level
122 PARAMS ((struct stack_level *, struct obstack *));
123 @@ -1800,7 +1799,7 @@ covariant_return_p (brettype, drettype)
124 /* Check that virtual overrider OVERRIDER is acceptable for base function
125 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
129 check_final_overrider (overrider, basefn)
130 tree overrider, basefn;
132 --- gcc/cp/typeck.c.jj 2002-07-10 11:37:43.000000000 +0200
133 +++ gcc/cp/typeck.c 2002-08-23 13:51:08.000000000 +0200
134 @@ -5450,7 +5450,10 @@ build_modify_expr (lhs, modifycode, rhs)
135 so the code to compute it is only emitted once. */
138 - rhs = save_expr (rhs);
139 + if (lvalue_p (rhs))
140 + rhs = stabilize_reference (rhs);
142 + rhs = save_expr (rhs);
144 /* Check this here to avoid odd errors when trying to convert
145 a throw to the type of the COND_EXPR. */
146 --- gcc/expr.c.jj 2002-05-07 12:45:49.000000000 +0200
147 +++ gcc/expr.c 2002-08-23 13:51:09.000000000 +0200
148 @@ -6661,8 +6661,7 @@ expand_expr (exp, target, tmode, modifie
149 * TYPE_QUAL_CONST))),
150 0, TREE_ADDRESSABLE (exp), 1);
152 - store_constructor (exp, target, 0,
153 - int_size_in_bytes (TREE_TYPE (exp)));
154 + store_constructor (exp, target, 0, int_expr_size (exp));
158 --- gcc/explow.c.jj 2002-02-22 11:32:03.000000000 +0100
159 +++ gcc/explow.c 2002-08-23 13:51:08.000000000 +0200
160 @@ -34,6 +34,7 @@ Software Foundation, 59 Temple Place - S
161 #include "insn-config.h"
164 +#include "langhooks.h"
166 static rtx break_out_memory_refs PARAMS ((rtx));
167 static void emit_stack_probe PARAMS ((rtx));
168 @@ -285,20 +286,33 @@ rtx
174 - if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
175 - && DECL_SIZE_UNIT (exp) != 0)
176 - size = DECL_SIZE_UNIT (exp);
178 - size = size_in_bytes (TREE_TYPE (exp));
179 + tree size = (*lang_hooks.expr_size) (exp);
181 if (TREE_CODE (size) != INTEGER_CST
182 && contains_placeholder_p (size))
183 size = build (WITH_RECORD_EXPR, sizetype, size, exp);
185 return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), 0);
188 +/* Return a wide integer for the size in bytes of the value of EXP, or -1
189 + if the size can vary or is larger than an integer. */
195 + tree t = (*lang_hooks.expr_size) (exp);
198 + || TREE_CODE (t) != INTEGER_CST
199 + || TREE_OVERFLOW (t)
200 + || TREE_INT_CST_HIGH (t) != 0
201 + /* If the result would appear negative, it's too big to represent. */
202 + || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
205 + return TREE_INT_CST_LOW (t);
208 /* Return a copy of X in which all memory references
209 --- gcc/expr.h.jj 2002-04-02 23:17:24.000000000 +0200
210 +++ gcc/expr.h 2002-08-23 13:51:09.000000000 +0200
211 @@ -548,6 +548,10 @@ extern unsigned int case_values_threshol
212 /* Return an rtx for the size in bytes of the value of an expr. */
213 extern rtx expr_size PARAMS ((tree));
215 +/* Return a wide integer for the size in bytes of the value of EXP, or -1
216 + if the size can vary or is larger than an integer. */
217 +extern HOST_WIDE_INT int_expr_size PARAMS ((tree));
219 extern rtx lookup_static_chain PARAMS ((tree));
221 /* Convert a stack slot address ADDR valid in function FNDECL
222 --- gcc/langhooks-def.h.jj 2002-05-24 23:55:54.000000000 +0200
223 +++ gcc/langhooks-def.h 2002-08-23 13:51:09.000000000 +0200
224 @@ -48,6 +48,7 @@ extern int lhd_staticp PARAMS ((tree));
225 extern void lhd_clear_binding_stack PARAMS ((void));
226 extern void lhd_print_tree_nothing PARAMS ((FILE *, tree, int));
227 extern void lhd_set_yydebug PARAMS ((int));
228 +extern tree lhd_expr_size PARAMS ((tree));
230 /* Declarations of default tree inlining hooks. */
231 tree lhd_tree_inlining_walk_subtrees PARAMS ((tree *, int *,
232 @@ -85,6 +86,7 @@ tree lhd_tree_inlining_convert_parm_for_
233 #define LANG_HOOKS_PRINT_TYPE lhd_print_tree_nothing
234 #define LANG_HOOKS_PRINT_IDENTIFIER lhd_print_tree_nothing
235 #define LANG_HOOKS_SET_YYDEBUG lhd_set_yydebug
236 +#define LANG_HOOKS_EXPR_SIZE lhd_expr_size
238 /* Tree inlining hooks. */
239 #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES lhd_tree_inlining_walk_subtrees
240 @@ -156,6 +158,7 @@ int lhd_tree_dump_type_quals PARAMS ((
241 LANG_HOOKS_PRINT_TYPE, \
242 LANG_HOOKS_PRINT_IDENTIFIER, \
243 LANG_HOOKS_SET_YYDEBUG, \
244 + LANG_HOOKS_EXPR_SIZE, \
245 LANG_HOOKS_TREE_INLINING_INITIALIZER, \
246 LANG_HOOKS_TREE_DUMP_INITIALIZER \
248 --- gcc/langhooks.c.jj 2002-03-23 12:02:51.000000000 +0100
249 +++ gcc/langhooks.c 2002-08-23 13:51:09.000000000 +0200
250 @@ -303,3 +303,16 @@ lhd_tree_dump_type_quals (t)
251 return TYPE_QUALS (t);
254 +/* lang_hooks.expr_size: Determine the size of the value of an expression T
255 + in a language-specific way. Returns a tree for the size in bytes. */
261 + if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
262 + && DECL_SIZE_UNIT (exp) != 0)
263 + return DECL_SIZE_UNIT (exp);
265 + return size_in_bytes (TREE_TYPE (exp));
267 --- gcc/langhooks.h.jj 2002-05-24 23:55:54.000000000 +0200
268 +++ gcc/langhooks.h 2002-08-23 13:51:09.000000000 +0200
269 @@ -156,6 +156,12 @@ struct lang_hooks
270 warning that the front end does not use such a parser. */
271 void (*set_yydebug) PARAMS ((int));
273 + /* Called from expr_size to calculate the size of the value of an
274 + expression in a language-dependent way. Returns a tree for the size
275 + in bytes. A frontend can call lhd_expr_size to get the default
276 + semantics in cases that it doesn't want to handle specially. */
277 + tree (*expr_size) PARAMS ((tree));
279 struct lang_hooks_for_tree_inlining tree_inlining;
281 struct lang_hooks_for_tree_dump tree_dump;