PR c++/65970 - constexpr infinite loop
[platform/upstream/gcc.git] / gcc / cp / cp-gimplify.c
1 /* C++-specific tree lowering bits; see also c-gimplify.c and tree-gimple.c.
2
3    Copyright (C) 2002-2016 Free Software Foundation, Inc.
4    Contributed by Jason Merrill <jason@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "target.h"
26 #include "basic-block.h"
27 #include "cp-tree.h"
28 #include "gimple.h"
29 #include "predict.h"
30 #include "stor-layout.h"
31 #include "tree-iterator.h"
32 #include "gimplify.h"
33 #include "c-family/c-ubsan.h"
34 #include "cilk.h"
35 #include "cp-cilkplus.h"
36
37 /* Forward declarations.  */
38
39 static tree cp_genericize_r (tree *, int *, void *);
40 static tree cp_fold_r (tree *, int *, void *);
41 static void cp_genericize_tree (tree*);
42 static tree cp_fold (tree);
43
44 /* Local declarations.  */
45
46 enum bc_t { bc_break = 0, bc_continue = 1 };
47
48 /* Stack of labels which are targets for "break" or "continue",
49    linked through TREE_CHAIN.  */
50 static tree bc_label[2];
51
52 /* Begin a scope which can be exited by a break or continue statement.  BC
53    indicates which.
54
55    Just creates a label with location LOCATION and pushes it into the current
56    context.  */
57
58 static tree
59 begin_bc_block (enum bc_t bc, location_t location)
60 {
61   tree label = create_artificial_label (location);
62   DECL_CHAIN (label) = bc_label[bc];
63   bc_label[bc] = label;
64   if (bc == bc_break)
65     LABEL_DECL_BREAK (label) = true;
66   else
67     LABEL_DECL_CONTINUE (label) = true;
68   return label;
69 }
70
71 /* Finish a scope which can be exited by a break or continue statement.
72    LABEL was returned from the most recent call to begin_bc_block.  BLOCK is
73    an expression for the contents of the scope.
74
75    If we saw a break (or continue) in the scope, append a LABEL_EXPR to
76    BLOCK.  Otherwise, just forget the label.  */
77
78 static void
79 finish_bc_block (tree *block, enum bc_t bc, tree label)
80 {
81   gcc_assert (label == bc_label[bc]);
82
83   if (TREE_USED (label))
84     append_to_statement_list (build1 (LABEL_EXPR, void_type_node, label),
85                               block);
86
87   bc_label[bc] = DECL_CHAIN (label);
88   DECL_CHAIN (label) = NULL_TREE;
89 }
90
91 /* This function is a wrapper for cilk_gimplify_call_params_in_spawned_fn.
92    *EXPR_P can be a CALL_EXPR, INIT_EXPR, MODIFY_EXPR, AGGR_INIT_EXPR or
93    TARGET_EXPR.  *PRE_P and *POST_P are gimple sequences from the caller
94    of gimplify_cilk_spawn.  */
95
96 static void
97 cilk_cp_gimplify_call_params_in_spawned_fn (tree *expr_p, gimple_seq *pre_p,
98                                             gimple_seq *post_p)
99 {
100   int ii = 0;
101
102   cilk_gimplify_call_params_in_spawned_fn (expr_p, pre_p);
103   if (TREE_CODE (*expr_p) == AGGR_INIT_EXPR)
104     for (ii = 0; ii < aggr_init_expr_nargs (*expr_p); ii++)
105       gimplify_expr (&AGGR_INIT_EXPR_ARG (*expr_p, ii), pre_p, post_p,
106                      is_gimple_reg, fb_rvalue);
107 }
108
109
110 /* Get the LABEL_EXPR to represent a break or continue statement
111    in the current block scope.  BC indicates which.  */
112
113 static tree
114 get_bc_label (enum bc_t bc)
115 {
116   tree label = bc_label[bc];
117
118   /* Mark the label used for finish_bc_block.  */
119   TREE_USED (label) = 1;
120   return label;
121 }
122
123 /* Genericize a TRY_BLOCK.  */
124
125 static void
126 genericize_try_block (tree *stmt_p)
127 {
128   tree body = TRY_STMTS (*stmt_p);
129   tree cleanup = TRY_HANDLERS (*stmt_p);
130
131   *stmt_p = build2 (TRY_CATCH_EXPR, void_type_node, body, cleanup);
132 }
133
134 /* Genericize a HANDLER by converting to a CATCH_EXPR.  */
135
136 static void
137 genericize_catch_block (tree *stmt_p)
138 {
139   tree type = HANDLER_TYPE (*stmt_p);
140   tree body = HANDLER_BODY (*stmt_p);
141
142   /* FIXME should the caught type go in TREE_TYPE?  */
143   *stmt_p = build2 (CATCH_EXPR, void_type_node, type, body);
144 }
145
146 /* A terser interface for building a representation of an exception
147    specification.  */
148
149 static tree
150 build_gimple_eh_filter_tree (tree body, tree allowed, tree failure)
151 {
152   tree t;
153
154   /* FIXME should the allowed types go in TREE_TYPE?  */
155   t = build2 (EH_FILTER_EXPR, void_type_node, allowed, NULL_TREE);
156   append_to_statement_list (failure, &EH_FILTER_FAILURE (t));
157
158   t = build2 (TRY_CATCH_EXPR, void_type_node, NULL_TREE, t);
159   append_to_statement_list (body, &TREE_OPERAND (t, 0));
160
161   return t;
162 }
163
164 /* Genericize an EH_SPEC_BLOCK by converting it to a
165    TRY_CATCH_EXPR/EH_FILTER_EXPR pair.  */
166
167 static void
168 genericize_eh_spec_block (tree *stmt_p)
169 {
170   tree body = EH_SPEC_STMTS (*stmt_p);
171   tree allowed = EH_SPEC_RAISES (*stmt_p);
172   tree failure = build_call_n (call_unexpected_node, 1, build_exc_ptr ());
173
174   *stmt_p = build_gimple_eh_filter_tree (body, allowed, failure);
175   TREE_NO_WARNING (*stmt_p) = true;
176   TREE_NO_WARNING (TREE_OPERAND (*stmt_p, 1)) = true;
177 }
178
179 /* Genericize an IF_STMT by turning it into a COND_EXPR.  */
180
181 static void
182 genericize_if_stmt (tree *stmt_p)
183 {
184   tree stmt, cond, then_, else_;
185   location_t locus = EXPR_LOCATION (*stmt_p);
186
187   stmt = *stmt_p;
188   cond = IF_COND (stmt);
189   then_ = THEN_CLAUSE (stmt);
190   else_ = ELSE_CLAUSE (stmt);
191
192   if (!then_)
193     then_ = build_empty_stmt (locus);
194   if (!else_)
195     else_ = build_empty_stmt (locus);
196
197   if (integer_nonzerop (cond) && !TREE_SIDE_EFFECTS (else_))
198     stmt = then_;
199   else if (integer_zerop (cond) && !TREE_SIDE_EFFECTS (then_))
200     stmt = else_;
201   else
202     stmt = build3 (COND_EXPR, void_type_node, cond, then_, else_);
203   if (!EXPR_HAS_LOCATION (stmt))
204     protected_set_expr_location (stmt, locus);
205   *stmt_p = stmt;
206 }
207
208 /* Build a generic representation of one of the C loop forms.  COND is the
209    loop condition or NULL_TREE.  BODY is the (possibly compound) statement
210    controlled by the loop.  INCR is the increment expression of a for-loop,
211    or NULL_TREE.  COND_IS_FIRST indicates whether the condition is
212    evaluated before the loop body as in while and for loops, or after the
213    loop body as in do-while loops.  */
214
215 static void
216 genericize_cp_loop (tree *stmt_p, location_t start_locus, tree cond, tree body,
217                     tree incr, bool cond_is_first, int *walk_subtrees,
218                     void *data)
219 {
220   tree blab, clab;
221   tree exit = NULL;
222   tree stmt_list = NULL;
223
224   blab = begin_bc_block (bc_break, start_locus);
225   clab = begin_bc_block (bc_continue, start_locus);
226
227   protected_set_expr_location (incr, start_locus);
228
229   cp_walk_tree (&cond, cp_genericize_r, data, NULL);
230   cp_walk_tree (&body, cp_genericize_r, data, NULL);
231   cp_walk_tree (&incr, cp_genericize_r, data, NULL);
232   *walk_subtrees = 0;
233
234   if (cond && TREE_CODE (cond) != INTEGER_CST)
235     {
236       /* If COND is constant, don't bother building an exit.  If it's false,
237          we won't build a loop.  If it's true, any exits are in the body.  */
238       location_t cloc = EXPR_LOC_OR_LOC (cond, start_locus);
239       exit = build1_loc (cloc, GOTO_EXPR, void_type_node,
240                          get_bc_label (bc_break));
241       exit = fold_build3_loc (cloc, COND_EXPR, void_type_node, cond,
242                               build_empty_stmt (cloc), exit);
243     }
244
245   if (exit && cond_is_first)
246     append_to_statement_list (exit, &stmt_list);
247   append_to_statement_list (body, &stmt_list);
248   finish_bc_block (&stmt_list, bc_continue, clab);
249   append_to_statement_list (incr, &stmt_list);
250   if (exit && !cond_is_first)
251     append_to_statement_list (exit, &stmt_list);
252
253   if (!stmt_list)
254     stmt_list = build_empty_stmt (start_locus);
255
256   tree loop;
257   if (cond && integer_zerop (cond))
258     {
259       if (cond_is_first)
260         loop = fold_build3_loc (start_locus, COND_EXPR,
261                                 void_type_node, cond, stmt_list,
262                                 build_empty_stmt (start_locus));
263       else
264         loop = stmt_list;
265     }
266   else
267     loop = build1_loc (start_locus, LOOP_EXPR, void_type_node, stmt_list);
268
269   stmt_list = NULL;
270   append_to_statement_list (loop, &stmt_list);
271   finish_bc_block (&stmt_list, bc_break, blab);
272   if (!stmt_list)
273     stmt_list = build_empty_stmt (start_locus);
274
275   *stmt_p = stmt_list;
276 }
277
278 /* Genericize a FOR_STMT node *STMT_P.  */
279
280 static void
281 genericize_for_stmt (tree *stmt_p, int *walk_subtrees, void *data)
282 {
283   tree stmt = *stmt_p;
284   tree expr = NULL;
285   tree loop;
286   tree init = FOR_INIT_STMT (stmt);
287
288   if (init)
289     {
290       cp_walk_tree (&init, cp_genericize_r, data, NULL);
291       append_to_statement_list (init, &expr);
292     }
293
294   genericize_cp_loop (&loop, EXPR_LOCATION (stmt), FOR_COND (stmt),
295                       FOR_BODY (stmt), FOR_EXPR (stmt), 1, walk_subtrees, data);
296   append_to_statement_list (loop, &expr);
297   if (expr == NULL_TREE)
298     expr = loop;
299   *stmt_p = expr;
300 }
301
302 /* Genericize a WHILE_STMT node *STMT_P.  */
303
304 static void
305 genericize_while_stmt (tree *stmt_p, int *walk_subtrees, void *data)
306 {
307   tree stmt = *stmt_p;
308   genericize_cp_loop (stmt_p, EXPR_LOCATION (stmt), WHILE_COND (stmt),
309                       WHILE_BODY (stmt), NULL_TREE, 1, walk_subtrees, data);
310 }
311
312 /* Genericize a DO_STMT node *STMT_P.  */
313
314 static void
315 genericize_do_stmt (tree *stmt_p, int *walk_subtrees, void *data)
316 {
317   tree stmt = *stmt_p;
318   genericize_cp_loop (stmt_p, EXPR_LOCATION (stmt), DO_COND (stmt),
319                       DO_BODY (stmt), NULL_TREE, 0, walk_subtrees, data);
320 }
321
322 /* Genericize a SWITCH_STMT node *STMT_P by turning it into a SWITCH_EXPR.  */
323
324 static void
325 genericize_switch_stmt (tree *stmt_p, int *walk_subtrees, void *data)
326 {
327   tree stmt = *stmt_p;
328   tree break_block, body, cond, type;
329   location_t stmt_locus = EXPR_LOCATION (stmt);
330
331   break_block = begin_bc_block (bc_break, stmt_locus);
332
333   body = SWITCH_STMT_BODY (stmt);
334   if (!body)
335     body = build_empty_stmt (stmt_locus);
336   cond = SWITCH_STMT_COND (stmt);
337   type = SWITCH_STMT_TYPE (stmt);
338
339   cp_walk_tree (&body, cp_genericize_r, data, NULL);
340   cp_walk_tree (&cond, cp_genericize_r, data, NULL);
341   cp_walk_tree (&type, cp_genericize_r, data, NULL);
342   *walk_subtrees = 0;
343
344   *stmt_p = build3_loc (stmt_locus, SWITCH_EXPR, type, cond, body, NULL_TREE);
345   finish_bc_block (stmt_p, bc_break, break_block);
346 }
347
348 /* Genericize a CONTINUE_STMT node *STMT_P.  */
349
350 static void
351 genericize_continue_stmt (tree *stmt_p)
352 {
353   tree stmt_list = NULL;
354   tree pred = build_predict_expr (PRED_CONTINUE, NOT_TAKEN);
355   tree label = get_bc_label (bc_continue);
356   location_t location = EXPR_LOCATION (*stmt_p);
357   tree jump = build1_loc (location, GOTO_EXPR, void_type_node, label);
358   append_to_statement_list_force (pred, &stmt_list);
359   append_to_statement_list (jump, &stmt_list);
360   *stmt_p = stmt_list;
361 }
362
363 /* Genericize a BREAK_STMT node *STMT_P.  */
364
365 static void
366 genericize_break_stmt (tree *stmt_p)
367 {
368   tree label = get_bc_label (bc_break);
369   location_t location = EXPR_LOCATION (*stmt_p);
370   *stmt_p = build1_loc (location, GOTO_EXPR, void_type_node, label);
371 }
372
373 /* Genericize a OMP_FOR node *STMT_P.  */
374
375 static void
376 genericize_omp_for_stmt (tree *stmt_p, int *walk_subtrees, void *data)
377 {
378   tree stmt = *stmt_p;
379   location_t locus = EXPR_LOCATION (stmt);
380   tree clab = begin_bc_block (bc_continue, locus);
381
382   cp_walk_tree (&OMP_FOR_BODY (stmt), cp_genericize_r, data, NULL);
383   if (TREE_CODE (stmt) != OMP_TASKLOOP)
384     cp_walk_tree (&OMP_FOR_CLAUSES (stmt), cp_genericize_r, data, NULL);
385   cp_walk_tree (&OMP_FOR_INIT (stmt), cp_genericize_r, data, NULL);
386   cp_walk_tree (&OMP_FOR_COND (stmt), cp_genericize_r, data, NULL);
387   cp_walk_tree (&OMP_FOR_INCR (stmt), cp_genericize_r, data, NULL);
388   cp_walk_tree (&OMP_FOR_PRE_BODY (stmt), cp_genericize_r, data, NULL);
389   *walk_subtrees = 0;
390
391   finish_bc_block (&OMP_FOR_BODY (stmt), bc_continue, clab);
392 }
393
394 /* Hook into the middle of gimplifying an OMP_FOR node.  */
395
396 static enum gimplify_status
397 cp_gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
398 {
399   tree for_stmt = *expr_p;
400   gimple_seq seq = NULL;
401
402   /* Protect ourselves from recursion.  */
403   if (OMP_FOR_GIMPLIFYING_P (for_stmt))
404     return GS_UNHANDLED;
405   OMP_FOR_GIMPLIFYING_P (for_stmt) = 1;
406
407   gimplify_and_add (for_stmt, &seq);
408   gimple_seq_add_seq (pre_p, seq);
409
410   OMP_FOR_GIMPLIFYING_P (for_stmt) = 0;
411
412   return GS_ALL_DONE;
413 }
414
415 /*  Gimplify an EXPR_STMT node.  */
416
417 static void
418 gimplify_expr_stmt (tree *stmt_p)
419 {
420   tree stmt = EXPR_STMT_EXPR (*stmt_p);
421
422   if (stmt == error_mark_node)
423     stmt = NULL;
424
425   /* Gimplification of a statement expression will nullify the
426      statement if all its side effects are moved to *PRE_P and *POST_P.
427
428      In this case we will not want to emit the gimplified statement.
429      However, we may still want to emit a warning, so we do that before
430      gimplification.  */
431   if (stmt && warn_unused_value)
432     {
433       if (!TREE_SIDE_EFFECTS (stmt))
434         {
435           if (!IS_EMPTY_STMT (stmt)
436               && !VOID_TYPE_P (TREE_TYPE (stmt))
437               && !TREE_NO_WARNING (stmt))
438             warning (OPT_Wunused_value, "statement with no effect");
439         }
440       else
441         warn_if_unused_value (stmt, input_location);
442     }
443
444   if (stmt == NULL_TREE)
445     stmt = alloc_stmt_list ();
446
447   *stmt_p = stmt;
448 }
449
450 /* Gimplify initialization from an AGGR_INIT_EXPR.  */
451
452 static void
453 cp_gimplify_init_expr (tree *expr_p)
454 {
455   tree from = TREE_OPERAND (*expr_p, 1);
456   tree to = TREE_OPERAND (*expr_p, 0);
457   tree t;
458
459   /* What about code that pulls out the temp and uses it elsewhere?  I
460      think that such code never uses the TARGET_EXPR as an initializer.  If
461      I'm wrong, we'll abort because the temp won't have any RTL.  In that
462      case, I guess we'll need to replace references somehow.  */
463   if (TREE_CODE (from) == TARGET_EXPR)
464     from = TARGET_EXPR_INITIAL (from);
465
466   /* Look through any COMPOUND_EXPRs, since build_compound_expr pushes them
467      inside the TARGET_EXPR.  */
468   for (t = from; t; )
469     {
470       tree sub = TREE_CODE (t) == COMPOUND_EXPR ? TREE_OPERAND (t, 0) : t;
471
472       /* If we are initializing from an AGGR_INIT_EXPR, drop the INIT_EXPR and
473          replace the slot operand with our target.
474
475          Should we add a target parm to gimplify_expr instead?  No, as in this
476          case we want to replace the INIT_EXPR.  */
477       if (TREE_CODE (sub) == AGGR_INIT_EXPR
478           || TREE_CODE (sub) == VEC_INIT_EXPR)
479         {
480           if (TREE_CODE (sub) == AGGR_INIT_EXPR)
481             AGGR_INIT_EXPR_SLOT (sub) = to;
482           else
483             VEC_INIT_EXPR_SLOT (sub) = to;
484           *expr_p = from;
485
486           /* The initialization is now a side-effect, so the container can
487              become void.  */
488           if (from != sub)
489             TREE_TYPE (from) = void_type_node;
490         }
491
492       if (cxx_dialect >= cxx14 && TREE_CODE (sub) == CONSTRUCTOR)
493         /* Handle aggregate NSDMI.  */
494         replace_placeholders (sub, to);
495
496       if (t == sub)
497         break;
498       else
499         t = TREE_OPERAND (t, 1);
500     }
501
502 }
503
504 /* Gimplify a MUST_NOT_THROW_EXPR.  */
505
506 static enum gimplify_status
507 gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p)
508 {
509   tree stmt = *expr_p;
510   tree temp = voidify_wrapper_expr (stmt, NULL);
511   tree body = TREE_OPERAND (stmt, 0);
512   gimple_seq try_ = NULL;
513   gimple_seq catch_ = NULL;
514   gimple *mnt;
515
516   gimplify_and_add (body, &try_);
517   mnt = gimple_build_eh_must_not_throw (terminate_node);
518   gimple_seq_add_stmt_without_update (&catch_, mnt);
519   mnt = gimple_build_try (try_, catch_, GIMPLE_TRY_CATCH);
520
521   gimple_seq_add_stmt_without_update (pre_p, mnt);
522   if (temp)
523     {
524       *expr_p = temp;
525       return GS_OK;
526     }
527
528   *expr_p = NULL;
529   return GS_ALL_DONE;
530 }
531
532 /* Return TRUE if an operand (OP) of a given TYPE being copied is
533    really just an empty class copy.
534
535    Check that the operand has a simple form so that TARGET_EXPRs and
536    non-empty CONSTRUCTORs get reduced properly, and we leave the
537    return slot optimization alone because it isn't a copy.  */
538
539 static bool
540 simple_empty_class_p (tree type, tree op)
541 {
542   return
543     ((TREE_CODE (op) == COMPOUND_EXPR
544       && simple_empty_class_p (type, TREE_OPERAND (op, 1)))
545      || is_gimple_lvalue (op)
546      || INDIRECT_REF_P (op)
547      || (TREE_CODE (op) == CONSTRUCTOR
548          && CONSTRUCTOR_NELTS (op) == 0
549          && !TREE_CLOBBER_P (op))
550      || (TREE_CODE (op) == CALL_EXPR
551          && !CALL_EXPR_RETURN_SLOT_OPT (op)))
552     && is_really_empty_class (type);
553 }
554
555 /* Returns true if evaluating E as an lvalue has side-effects;
556    specifically, a volatile lvalue has TREE_SIDE_EFFECTS, but it doesn't really
557    have side-effects until there is a read or write through it.  */
558
559 static bool
560 lvalue_has_side_effects (tree e)
561 {
562   if (!TREE_SIDE_EFFECTS (e))
563     return false;
564   while (handled_component_p (e))
565     {
566       if (TREE_CODE (e) == ARRAY_REF
567           && TREE_SIDE_EFFECTS (TREE_OPERAND (e, 1)))
568         return true;
569       e = TREE_OPERAND (e, 0);
570     }
571   if (DECL_P (e))
572     /* Just naming a variable has no side-effects.  */
573     return false;
574   else if (INDIRECT_REF_P (e))
575     /* Similarly, indirection has no side-effects.  */
576     return TREE_SIDE_EFFECTS (TREE_OPERAND (e, 0));
577   else
578     /* For anything else, trust TREE_SIDE_EFFECTS.  */
579     return TREE_SIDE_EFFECTS (e);
580 }
581
582 /* Do C++-specific gimplification.  Args are as for gimplify_expr.  */
583
584 int
585 cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
586 {
587   int saved_stmts_are_full_exprs_p = 0;
588   location_t loc = EXPR_LOC_OR_LOC (*expr_p, input_location);
589   enum tree_code code = TREE_CODE (*expr_p);
590   enum gimplify_status ret;
591
592   if (STATEMENT_CODE_P (code))
593     {
594       saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
595       current_stmt_tree ()->stmts_are_full_exprs_p
596         = STMT_IS_FULL_EXPR_P (*expr_p);
597     }
598
599   switch (code)
600     {
601     case AGGR_INIT_EXPR:
602       simplify_aggr_init_expr (expr_p);
603       ret = GS_OK;
604       break;
605
606     case VEC_INIT_EXPR:
607       {
608         location_t loc = input_location;
609         tree init = VEC_INIT_EXPR_INIT (*expr_p);
610         int from_array = (init && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE);
611         gcc_assert (EXPR_HAS_LOCATION (*expr_p));
612         input_location = EXPR_LOCATION (*expr_p);
613         *expr_p = build_vec_init (VEC_INIT_EXPR_SLOT (*expr_p), NULL_TREE,
614                                   init, VEC_INIT_EXPR_VALUE_INIT (*expr_p),
615                                   from_array,
616                                   tf_warning_or_error);
617         hash_set<tree> pset;
618         cp_walk_tree (expr_p, cp_fold_r, &pset, NULL);
619         cp_genericize_tree (expr_p);
620         ret = GS_OK;
621         input_location = loc;
622       }
623       break;
624
625     case THROW_EXPR:
626       /* FIXME communicate throw type to back end, probably by moving
627          THROW_EXPR into ../tree.def.  */
628       *expr_p = TREE_OPERAND (*expr_p, 0);
629       ret = GS_OK;
630       break;
631
632     case MUST_NOT_THROW_EXPR:
633       ret = gimplify_must_not_throw_expr (expr_p, pre_p);
634       break;
635
636       /* We used to do this for MODIFY_EXPR as well, but that's unsafe; the
637          LHS of an assignment might also be involved in the RHS, as in bug
638          25979.  */
639     case INIT_EXPR:
640       if (fn_contains_cilk_spawn_p (cfun))
641         {
642           if (cilk_cp_detect_spawn_and_unwrap (expr_p))
643             {
644               cilk_cp_gimplify_call_params_in_spawned_fn (expr_p,
645                                                           pre_p, post_p);
646               return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
647             }
648           if (seen_error () && contains_cilk_spawn_stmt (*expr_p))
649             return GS_ERROR;
650         }
651
652       cp_gimplify_init_expr (expr_p);
653       if (TREE_CODE (*expr_p) != INIT_EXPR)
654         return GS_OK;
655       /* Otherwise fall through.  */
656     case MODIFY_EXPR:
657     modify_expr_case:
658       {
659         if (fn_contains_cilk_spawn_p (cfun)
660             && cilk_cp_detect_spawn_and_unwrap (expr_p)
661             && !seen_error ())
662           {
663             cilk_cp_gimplify_call_params_in_spawned_fn (expr_p, pre_p, post_p);
664             return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
665           }
666         /* If the back end isn't clever enough to know that the lhs and rhs
667            types are the same, add an explicit conversion.  */
668         tree op0 = TREE_OPERAND (*expr_p, 0);
669         tree op1 = TREE_OPERAND (*expr_p, 1);
670
671         if (!error_operand_p (op0)
672             && !error_operand_p (op1)
673             && (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (op0))
674                 || TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (op1)))
675             && !useless_type_conversion_p (TREE_TYPE (op1), TREE_TYPE (op0)))
676           TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR,
677                                               TREE_TYPE (op0), op1);
678
679         else if (simple_empty_class_p (TREE_TYPE (op0), op1))
680           {
681             /* Remove any copies of empty classes.  Also drop volatile
682                variables on the RHS to avoid infinite recursion from
683                gimplify_expr trying to load the value.  */
684             if (TREE_SIDE_EFFECTS (op1))
685               {
686                 if (TREE_THIS_VOLATILE (op1)
687                     && (REFERENCE_CLASS_P (op1) || DECL_P (op1)))
688                   op1 = build_fold_addr_expr (op1);
689
690                 gimplify_and_add (op1, pre_p);
691               }
692             gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
693                            is_gimple_lvalue, fb_lvalue);
694             *expr_p = TREE_OPERAND (*expr_p, 0);
695           }
696         /* P0145 says that the RHS is sequenced before the LHS.
697            gimplify_modify_expr gimplifies the RHS before the LHS, but that
698            isn't quite strong enough in two cases:
699
700            1) gimplify.c wants to leave a CALL_EXPR on the RHS, which would
701            mean it's evaluated after the LHS.
702
703            2) the value calculation of the RHS is also sequenced before the
704            LHS, so for scalar assignment we need to preevaluate if the
705            RHS could be affected by LHS side-effects even if it has no
706            side-effects of its own.  We don't need this for classes because
707            class assignment takes its RHS by reference.  */
708        else if (flag_strong_eval_order > 1
709                 && TREE_CODE (*expr_p) == MODIFY_EXPR
710                 && lvalue_has_side_effects (op0)
711                 && (TREE_CODE (op1) == CALL_EXPR
712                     || (SCALAR_TYPE_P (TREE_TYPE (op1))
713                         && !TREE_CONSTANT (op1))))
714          TREE_OPERAND (*expr_p, 1) = get_formal_tmp_var (op1, pre_p);
715       }
716       ret = GS_OK;
717       break;
718
719     case EMPTY_CLASS_EXPR:
720       /* We create an empty CONSTRUCTOR with RECORD_TYPE.  */
721       *expr_p = build_constructor (TREE_TYPE (*expr_p), NULL);
722       ret = GS_OK;
723       break;
724
725     case BASELINK:
726       *expr_p = BASELINK_FUNCTIONS (*expr_p);
727       ret = GS_OK;
728       break;
729
730     case TRY_BLOCK:
731       genericize_try_block (expr_p);
732       ret = GS_OK;
733       break;
734
735     case HANDLER:
736       genericize_catch_block (expr_p);
737       ret = GS_OK;
738       break;
739
740     case EH_SPEC_BLOCK:
741       genericize_eh_spec_block (expr_p);
742       ret = GS_OK;
743       break;
744
745     case USING_STMT:
746       gcc_unreachable ();
747
748     case FOR_STMT:
749     case WHILE_STMT:
750     case DO_STMT:
751     case SWITCH_STMT:
752     case CONTINUE_STMT:
753     case BREAK_STMT:
754       gcc_unreachable ();
755
756     case OMP_FOR:
757     case OMP_SIMD:
758     case OMP_DISTRIBUTE:
759     case OMP_TASKLOOP:
760       ret = cp_gimplify_omp_for (expr_p, pre_p);
761       break;
762
763     case EXPR_STMT:
764       gimplify_expr_stmt (expr_p);
765       ret = GS_OK;
766       break;
767
768     case UNARY_PLUS_EXPR:
769       {
770         tree arg = TREE_OPERAND (*expr_p, 0);
771         tree type = TREE_TYPE (*expr_p);
772         *expr_p = (TREE_TYPE (arg) != type) ? fold_convert (type, arg)
773                                             : arg;
774         ret = GS_OK;
775       }
776       break;
777
778     case CILK_SPAWN_STMT:
779       gcc_assert(fn_contains_cilk_spawn_p (cfun)
780                  && cilk_cp_detect_spawn_and_unwrap (expr_p));
781
782       if (!seen_error ())
783         {
784           cilk_cp_gimplify_call_params_in_spawned_fn (expr_p, pre_p, post_p);
785           return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
786         }
787       return GS_ERROR;
788
789     case CALL_EXPR:
790       if (fn_contains_cilk_spawn_p (cfun)
791           && cilk_cp_detect_spawn_and_unwrap (expr_p)
792           && !seen_error ())
793         {
794           cilk_cp_gimplify_call_params_in_spawned_fn (expr_p, pre_p, post_p);
795           return (enum gimplify_status) gimplify_cilk_spawn (expr_p);
796         }
797       ret = GS_OK;
798       if (!CALL_EXPR_FN (*expr_p))
799         /* Internal function call.  */;
800       else if (CALL_EXPR_REVERSE_ARGS (*expr_p))
801         {
802           /* This is a call to a (compound) assignment operator that used
803              the operator syntax; gimplify the RHS first.  */
804           gcc_assert (call_expr_nargs (*expr_p) == 2);
805           gcc_assert (!CALL_EXPR_ORDERED_ARGS (*expr_p));
806           enum gimplify_status t
807             = gimplify_arg (&CALL_EXPR_ARG (*expr_p, 1), pre_p, loc);
808           if (t == GS_ERROR)
809             ret = GS_ERROR;
810         }
811       else if (CALL_EXPR_ORDERED_ARGS (*expr_p))
812         {
813           /* Leave the last argument for gimplify_call_expr, to avoid problems
814              with __builtin_va_arg_pack().  */
815           int nargs = call_expr_nargs (*expr_p) - 1;
816           for (int i = 0; i < nargs; ++i)
817             {
818               enum gimplify_status t
819                 = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p, loc);
820               if (t == GS_ERROR)
821                 ret = GS_ERROR;
822             }
823         }
824       else if (flag_strong_eval_order
825                && !CALL_EXPR_OPERATOR_SYNTAX (*expr_p))
826         {
827           /* If flag_strong_eval_order, evaluate the object argument first.  */
828           tree fntype = TREE_TYPE (CALL_EXPR_FN (*expr_p));
829           if (POINTER_TYPE_P (fntype))
830             fntype = TREE_TYPE (fntype);
831           if (TREE_CODE (fntype) == METHOD_TYPE)
832             {
833               enum gimplify_status t
834                 = gimplify_arg (&CALL_EXPR_ARG (*expr_p, 0), pre_p, loc);
835               if (t == GS_ERROR)
836                 ret = GS_ERROR;
837             }
838         }
839       break;
840
841     case RETURN_EXPR:
842       if (TREE_OPERAND (*expr_p, 0)
843           && (TREE_CODE (TREE_OPERAND (*expr_p, 0)) == INIT_EXPR
844               || TREE_CODE (TREE_OPERAND (*expr_p, 0)) == MODIFY_EXPR))
845         {
846           expr_p = &TREE_OPERAND (*expr_p, 0);
847           code = TREE_CODE (*expr_p);
848           /* Avoid going through the INIT_EXPR case, which can
849              degrade INIT_EXPRs into AGGR_INIT_EXPRs.  */
850           goto modify_expr_case;
851         }
852       /* Fall through.  */
853
854     default:
855       ret = (enum gimplify_status) c_gimplify_expr (expr_p, pre_p, post_p);
856       break;
857     }
858
859   /* Restore saved state.  */
860   if (STATEMENT_CODE_P (code))
861     current_stmt_tree ()->stmts_are_full_exprs_p
862       = saved_stmts_are_full_exprs_p;
863
864   return ret;
865 }
866
867 static inline bool
868 is_invisiref_parm (const_tree t)
869 {
870   return ((TREE_CODE (t) == PARM_DECL || TREE_CODE (t) == RESULT_DECL)
871           && DECL_BY_REFERENCE (t));
872 }
873
874 /* Return true if the uid in both int tree maps are equal.  */
875
876 bool
877 cxx_int_tree_map_hasher::equal (cxx_int_tree_map *a, cxx_int_tree_map *b)
878 {
879   return (a->uid == b->uid);
880 }
881
882 /* Hash a UID in a cxx_int_tree_map.  */
883
884 unsigned int
885 cxx_int_tree_map_hasher::hash (cxx_int_tree_map *item)
886 {
887   return item->uid;
888 }
889
890 /* A stable comparison routine for use with splay trees and DECLs.  */
891
892 static int
893 splay_tree_compare_decl_uid (splay_tree_key xa, splay_tree_key xb)
894 {
895   tree a = (tree) xa;
896   tree b = (tree) xb;
897
898   return DECL_UID (a) - DECL_UID (b);
899 }
900
901 /* OpenMP context during genericization.  */
902
903 struct cp_genericize_omp_taskreg
904 {
905   bool is_parallel;
906   bool default_shared;
907   struct cp_genericize_omp_taskreg *outer;
908   splay_tree variables;
909 };
910
911 /* Return true if genericization should try to determine if
912    DECL is firstprivate or shared within task regions.  */
913
914 static bool
915 omp_var_to_track (tree decl)
916 {
917   tree type = TREE_TYPE (decl);
918   if (is_invisiref_parm (decl))
919     type = TREE_TYPE (type);
920   while (TREE_CODE (type) == ARRAY_TYPE)
921     type = TREE_TYPE (type);
922   if (type == error_mark_node || !CLASS_TYPE_P (type))
923     return false;
924   if (VAR_P (decl) && CP_DECL_THREAD_LOCAL_P (decl))
925     return false;
926   if (cxx_omp_predetermined_sharing (decl) != OMP_CLAUSE_DEFAULT_UNSPECIFIED)
927     return false;
928   return true;
929 }
930
931 /* Note DECL use in OpenMP region OMP_CTX during genericization.  */
932
933 static void
934 omp_cxx_notice_variable (struct cp_genericize_omp_taskreg *omp_ctx, tree decl)
935 {
936   splay_tree_node n = splay_tree_lookup (omp_ctx->variables,
937                                          (splay_tree_key) decl);
938   if (n == NULL)
939     {
940       int flags = OMP_CLAUSE_DEFAULT_SHARED;
941       if (omp_ctx->outer)
942         omp_cxx_notice_variable (omp_ctx->outer, decl);
943       if (!omp_ctx->default_shared)
944         {
945           struct cp_genericize_omp_taskreg *octx;
946
947           for (octx = omp_ctx->outer; octx; octx = octx->outer)
948             {
949               n = splay_tree_lookup (octx->variables, (splay_tree_key) decl);
950               if (n && n->value != OMP_CLAUSE_DEFAULT_SHARED)
951                 {
952                   flags = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
953                   break;
954                 }
955               if (octx->is_parallel)
956                 break;
957             }
958           if (octx == NULL
959               && (TREE_CODE (decl) == PARM_DECL
960                   || (!(TREE_STATIC (decl) || DECL_EXTERNAL (decl))
961                       && DECL_CONTEXT (decl) == current_function_decl)))
962             flags = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
963           if (flags == OMP_CLAUSE_DEFAULT_FIRSTPRIVATE)
964             {
965               /* DECL is implicitly determined firstprivate in
966                  the current task construct.  Ensure copy ctor and
967                  dtor are instantiated, because during gimplification
968                  it will be already too late.  */
969               tree type = TREE_TYPE (decl);
970               if (is_invisiref_parm (decl))
971                 type = TREE_TYPE (type);
972               while (TREE_CODE (type) == ARRAY_TYPE)
973                 type = TREE_TYPE (type);
974               get_copy_ctor (type, tf_none);
975               get_dtor (type, tf_none);
976             }
977         }
978       splay_tree_insert (omp_ctx->variables, (splay_tree_key) decl, flags);
979     }
980 }
981
982 /* Genericization context.  */
983
984 struct cp_genericize_data
985 {
986   hash_set<tree> *p_set;
987   vec<tree> bind_expr_stack;
988   struct cp_genericize_omp_taskreg *omp_ctx;
989   tree try_block;
990   bool no_sanitize_p;
991 };
992
993 /* Perform any pre-gimplification folding of C++ front end trees to
994    GENERIC.
995    Note:  The folding of none-omp cases is something to move into
996      the middle-end.  As for now we have most foldings only on GENERIC
997      in fold-const, we need to perform this before transformation to
998      GIMPLE-form.  */
999
1000 static tree
1001 cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data)
1002 {
1003   tree stmt;
1004   enum tree_code code;
1005
1006   *stmt_p = stmt = cp_fold (*stmt_p);
1007
1008   if (((hash_set<tree> *) data)->add (stmt))
1009     {
1010       /* Don't walk subtrees of stmts we've already walked once, otherwise
1011          we can have exponential complexity with e.g. lots of nested
1012          SAVE_EXPRs or TARGET_EXPRs.  cp_fold uses a cache and will return
1013          always the same tree, which the first time cp_fold_r has been
1014          called on it had the subtrees walked.  */
1015       *walk_subtrees = 0;
1016       return NULL;
1017     }
1018
1019   code = TREE_CODE (stmt);
1020   if (code == OMP_FOR || code == OMP_SIMD || code == OMP_DISTRIBUTE
1021       || code == OMP_TASKLOOP || code == CILK_FOR || code == CILK_SIMD
1022       || code == OACC_LOOP)
1023     {
1024       tree x;
1025       int i, n;
1026
1027       cp_walk_tree (&OMP_FOR_BODY (stmt), cp_fold_r, data, NULL);
1028       cp_walk_tree (&OMP_FOR_CLAUSES (stmt), cp_fold_r, data, NULL);
1029       cp_walk_tree (&OMP_FOR_INIT (stmt), cp_fold_r, data, NULL);
1030       x = OMP_FOR_COND (stmt);
1031       if (x && TREE_CODE_CLASS (TREE_CODE (x)) == tcc_comparison)
1032         {
1033           cp_walk_tree (&TREE_OPERAND (x, 0), cp_fold_r, data, NULL);
1034           cp_walk_tree (&TREE_OPERAND (x, 1), cp_fold_r, data, NULL);
1035         }
1036       else if (x && TREE_CODE (x) == TREE_VEC)
1037         {
1038           n = TREE_VEC_LENGTH (x);
1039           for (i = 0; i < n; i++)
1040             {
1041               tree o = TREE_VEC_ELT (x, i);
1042               if (o && TREE_CODE_CLASS (TREE_CODE (o)) == tcc_comparison)
1043                 cp_walk_tree (&TREE_OPERAND (o, 1), cp_fold_r, data, NULL);
1044             }
1045         }
1046       x = OMP_FOR_INCR (stmt);
1047       if (x && TREE_CODE (x) == TREE_VEC)
1048         {
1049           n = TREE_VEC_LENGTH (x);
1050           for (i = 0; i < n; i++)
1051             {
1052               tree o = TREE_VEC_ELT (x, i);
1053               if (o && TREE_CODE (o) == MODIFY_EXPR)
1054                 o = TREE_OPERAND (o, 1);
1055               if (o && (TREE_CODE (o) == PLUS_EXPR || TREE_CODE (o) == MINUS_EXPR
1056                         || TREE_CODE (o) == POINTER_PLUS_EXPR))
1057                 {
1058                   cp_walk_tree (&TREE_OPERAND (o, 0), cp_fold_r, data, NULL);
1059                   cp_walk_tree (&TREE_OPERAND (o, 1), cp_fold_r, data, NULL);
1060                 }
1061             }
1062         }
1063       cp_walk_tree (&OMP_FOR_PRE_BODY (stmt), cp_fold_r, data, NULL);
1064       *walk_subtrees = 0;
1065     }
1066
1067   return NULL;
1068 }
1069
1070 /* Fold ALL the trees!  FIXME we should be able to remove this, but
1071    apparently that still causes optimization regressions.  */
1072
1073 void
1074 cp_fold_function (tree fndecl)
1075 {
1076   hash_set<tree> pset;
1077   cp_walk_tree (&DECL_SAVED_TREE (fndecl), cp_fold_r, &pset, NULL);
1078 }
1079
1080 /* Perform any pre-gimplification lowering of C++ front end trees to
1081    GENERIC.  */
1082
1083 static tree
1084 cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
1085 {
1086   tree stmt = *stmt_p;
1087   struct cp_genericize_data *wtd = (struct cp_genericize_data *) data;
1088   hash_set<tree> *p_set = wtd->p_set;
1089
1090   /* If in an OpenMP context, note var uses.  */
1091   if (__builtin_expect (wtd->omp_ctx != NULL, 0)
1092       && (VAR_P (stmt)
1093           || TREE_CODE (stmt) == PARM_DECL
1094           || TREE_CODE (stmt) == RESULT_DECL)
1095       && omp_var_to_track (stmt))
1096     omp_cxx_notice_variable (wtd->omp_ctx, stmt);
1097
1098   /* Don't dereference parms in a thunk, pass the references through. */
1099   if ((TREE_CODE (stmt) == CALL_EXPR && CALL_FROM_THUNK_P (stmt))
1100       || (TREE_CODE (stmt) == AGGR_INIT_EXPR && AGGR_INIT_FROM_THUNK_P (stmt)))
1101     {
1102       *walk_subtrees = 0;
1103       return NULL;
1104     }
1105
1106   /* Otherwise, do dereference invisible reference parms.  */
1107   if (is_invisiref_parm (stmt))
1108     {
1109       *stmt_p = convert_from_reference (stmt);
1110       *walk_subtrees = 0;
1111       return NULL;
1112     }
1113
1114   /* Map block scope extern declarations to visible declarations with the
1115      same name and type in outer scopes if any.  */
1116   if (cp_function_chain->extern_decl_map
1117       && VAR_OR_FUNCTION_DECL_P (stmt)
1118       && DECL_EXTERNAL (stmt))
1119     {
1120       struct cxx_int_tree_map *h, in;
1121       in.uid = DECL_UID (stmt);
1122       h = cp_function_chain->extern_decl_map->find_with_hash (&in, in.uid);
1123       if (h)
1124         {
1125           *stmt_p = h->to;
1126           *walk_subtrees = 0;
1127           return NULL;
1128         }
1129     }
1130
1131   /* Other than invisiref parms, don't walk the same tree twice.  */
1132   if (p_set->contains (stmt))
1133     {
1134       *walk_subtrees = 0;
1135       return NULL_TREE;
1136     }
1137
1138   if (TREE_CODE (stmt) == ADDR_EXPR
1139       && is_invisiref_parm (TREE_OPERAND (stmt, 0)))
1140     {
1141       /* If in an OpenMP context, note var uses.  */
1142       if (__builtin_expect (wtd->omp_ctx != NULL, 0)
1143           && omp_var_to_track (TREE_OPERAND (stmt, 0)))
1144         omp_cxx_notice_variable (wtd->omp_ctx, TREE_OPERAND (stmt, 0));
1145       *stmt_p = fold_convert (TREE_TYPE (stmt), TREE_OPERAND (stmt, 0));
1146       *walk_subtrees = 0;
1147     }
1148   else if (TREE_CODE (stmt) == RETURN_EXPR
1149            && TREE_OPERAND (stmt, 0)
1150            && is_invisiref_parm (TREE_OPERAND (stmt, 0)))
1151     /* Don't dereference an invisiref RESULT_DECL inside a RETURN_EXPR.  */
1152     *walk_subtrees = 0;
1153   else if (TREE_CODE (stmt) == OMP_CLAUSE)
1154     switch (OMP_CLAUSE_CODE (stmt))
1155       {
1156       case OMP_CLAUSE_LASTPRIVATE:
1157         /* Don't dereference an invisiref in OpenMP clauses.  */
1158         if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
1159           {
1160             *walk_subtrees = 0;
1161             if (OMP_CLAUSE_LASTPRIVATE_STMT (stmt))
1162               cp_walk_tree (&OMP_CLAUSE_LASTPRIVATE_STMT (stmt),
1163                             cp_genericize_r, data, NULL);
1164           }
1165         break;
1166       case OMP_CLAUSE_PRIVATE:
1167         /* Don't dereference an invisiref in OpenMP clauses.  */
1168         if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
1169           *walk_subtrees = 0;
1170         else if (wtd->omp_ctx != NULL)
1171           {
1172             /* Private clause doesn't cause any references to the
1173                var in outer contexts, avoid calling
1174                omp_cxx_notice_variable for it.  */
1175             struct cp_genericize_omp_taskreg *old = wtd->omp_ctx;
1176             wtd->omp_ctx = NULL;
1177             cp_walk_tree (&OMP_CLAUSE_DECL (stmt), cp_genericize_r,
1178                           data, NULL);
1179             wtd->omp_ctx = old;
1180             *walk_subtrees = 0;
1181           }
1182         break;
1183       case OMP_CLAUSE_SHARED:
1184       case OMP_CLAUSE_FIRSTPRIVATE:
1185       case OMP_CLAUSE_COPYIN:
1186       case OMP_CLAUSE_COPYPRIVATE:
1187         /* Don't dereference an invisiref in OpenMP clauses.  */
1188         if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
1189           *walk_subtrees = 0;
1190         break;
1191       case OMP_CLAUSE_REDUCTION:
1192         /* Don't dereference an invisiref in reduction clause's
1193            OMP_CLAUSE_DECL either.  OMP_CLAUSE_REDUCTION_{INIT,MERGE}
1194            still needs to be genericized.  */
1195         if (is_invisiref_parm (OMP_CLAUSE_DECL (stmt)))
1196           {
1197             *walk_subtrees = 0;
1198             if (OMP_CLAUSE_REDUCTION_INIT (stmt))
1199               cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (stmt),
1200                             cp_genericize_r, data, NULL);
1201             if (OMP_CLAUSE_REDUCTION_MERGE (stmt))
1202               cp_walk_tree (&OMP_CLAUSE_REDUCTION_MERGE (stmt),
1203                             cp_genericize_r, data, NULL);
1204           }
1205         break;
1206       default:
1207         break;
1208       }
1209   else if (IS_TYPE_OR_DECL_P (stmt))
1210     *walk_subtrees = 0;
1211
1212   /* Due to the way voidify_wrapper_expr is written, we don't get a chance
1213      to lower this construct before scanning it, so we need to lower these
1214      before doing anything else.  */
1215   else if (TREE_CODE (stmt) == CLEANUP_STMT)
1216     *stmt_p = build2_loc (EXPR_LOCATION (stmt),
1217                           CLEANUP_EH_ONLY (stmt) ? TRY_CATCH_EXPR
1218                                                  : TRY_FINALLY_EXPR,
1219                           void_type_node,
1220                           CLEANUP_BODY (stmt),
1221                           CLEANUP_EXPR (stmt));
1222
1223   else if (TREE_CODE (stmt) == IF_STMT)
1224     {
1225       genericize_if_stmt (stmt_p);
1226       /* *stmt_p has changed, tail recurse to handle it again.  */
1227       return cp_genericize_r (stmt_p, walk_subtrees, data);
1228     }
1229
1230   /* COND_EXPR might have incompatible types in branches if one or both
1231      arms are bitfields.  Fix it up now.  */
1232   else if (TREE_CODE (stmt) == COND_EXPR)
1233     {
1234       tree type_left
1235         = (TREE_OPERAND (stmt, 1)
1236            ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 1))
1237            : NULL_TREE);
1238       tree type_right
1239         = (TREE_OPERAND (stmt, 2)
1240            ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 2))
1241            : NULL_TREE);
1242       if (type_left
1243           && !useless_type_conversion_p (TREE_TYPE (stmt),
1244                                          TREE_TYPE (TREE_OPERAND (stmt, 1))))
1245         {
1246           TREE_OPERAND (stmt, 1)
1247             = fold_convert (type_left, TREE_OPERAND (stmt, 1));
1248           gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
1249                                                  type_left));
1250         }
1251       if (type_right
1252           && !useless_type_conversion_p (TREE_TYPE (stmt),
1253                                          TREE_TYPE (TREE_OPERAND (stmt, 2))))
1254         {
1255           TREE_OPERAND (stmt, 2)
1256             = fold_convert (type_right, TREE_OPERAND (stmt, 2));
1257           gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
1258                                                  type_right));
1259         }
1260     }
1261
1262   else if (TREE_CODE (stmt) == BIND_EXPR)
1263     {
1264       if (__builtin_expect (wtd->omp_ctx != NULL, 0))
1265         {
1266           tree decl;
1267           for (decl = BIND_EXPR_VARS (stmt); decl; decl = DECL_CHAIN (decl))
1268             if (VAR_P (decl)
1269                 && !DECL_EXTERNAL (decl)
1270                 && omp_var_to_track (decl))
1271               {
1272                 splay_tree_node n
1273                   = splay_tree_lookup (wtd->omp_ctx->variables,
1274                                        (splay_tree_key) decl);
1275                 if (n == NULL)
1276                   splay_tree_insert (wtd->omp_ctx->variables,
1277                                      (splay_tree_key) decl,
1278                                      TREE_STATIC (decl)
1279                                      ? OMP_CLAUSE_DEFAULT_SHARED
1280                                      : OMP_CLAUSE_DEFAULT_PRIVATE);
1281               }
1282         }
1283       if (flag_sanitize
1284           & (SANITIZE_NULL | SANITIZE_ALIGNMENT | SANITIZE_VPTR))
1285         {
1286           /* The point here is to not sanitize static initializers.  */
1287           bool no_sanitize_p = wtd->no_sanitize_p;
1288           wtd->no_sanitize_p = true;
1289           for (tree decl = BIND_EXPR_VARS (stmt);
1290                decl;
1291                decl = DECL_CHAIN (decl))
1292             if (VAR_P (decl)
1293                 && TREE_STATIC (decl)
1294                 && DECL_INITIAL (decl))
1295               cp_walk_tree (&DECL_INITIAL (decl), cp_genericize_r, data, NULL);
1296           wtd->no_sanitize_p = no_sanitize_p;
1297         }
1298       wtd->bind_expr_stack.safe_push (stmt);
1299       cp_walk_tree (&BIND_EXPR_BODY (stmt),
1300                     cp_genericize_r, data, NULL);
1301       wtd->bind_expr_stack.pop ();
1302     }
1303
1304   else if (TREE_CODE (stmt) == USING_STMT)
1305     {
1306       tree block = NULL_TREE;
1307
1308       /* Get the innermost inclosing GIMPLE_BIND that has a non NULL
1309          BLOCK, and append an IMPORTED_DECL to its
1310          BLOCK_VARS chained list.  */
1311       if (wtd->bind_expr_stack.exists ())
1312         {
1313           int i;
1314           for (i = wtd->bind_expr_stack.length () - 1; i >= 0; i--)
1315             if ((block = BIND_EXPR_BLOCK (wtd->bind_expr_stack[i])))
1316               break;
1317         }
1318       if (block)
1319         {
1320           tree using_directive;
1321           gcc_assert (TREE_OPERAND (stmt, 0));
1322
1323           using_directive = make_node (IMPORTED_DECL);
1324           TREE_TYPE (using_directive) = void_type_node;
1325
1326           IMPORTED_DECL_ASSOCIATED_DECL (using_directive)
1327             = TREE_OPERAND (stmt, 0);
1328           DECL_CHAIN (using_directive) = BLOCK_VARS (block);
1329           BLOCK_VARS (block) = using_directive;
1330         }
1331       /* The USING_STMT won't appear in GENERIC.  */
1332       *stmt_p = build1 (NOP_EXPR, void_type_node, integer_zero_node);
1333       *walk_subtrees = 0;
1334     }
1335
1336   else if (TREE_CODE (stmt) == DECL_EXPR
1337            && TREE_CODE (DECL_EXPR_DECL (stmt)) == USING_DECL)
1338     {
1339       /* Using decls inside DECL_EXPRs are just dropped on the floor.  */
1340       *stmt_p = build1 (NOP_EXPR, void_type_node, integer_zero_node);
1341       *walk_subtrees = 0;
1342     }
1343   else if (TREE_CODE (stmt) == DECL_EXPR)
1344     {
1345       tree d = DECL_EXPR_DECL (stmt);
1346       if (TREE_CODE (d) == VAR_DECL)
1347         gcc_assert (CP_DECL_THREAD_LOCAL_P (d) == DECL_THREAD_LOCAL_P (d));
1348     }
1349   else if (TREE_CODE (stmt) == OMP_PARALLEL
1350            || TREE_CODE (stmt) == OMP_TASK
1351            || TREE_CODE (stmt) == OMP_TASKLOOP)
1352     {
1353       struct cp_genericize_omp_taskreg omp_ctx;
1354       tree c, decl;
1355       splay_tree_node n;
1356
1357       *walk_subtrees = 0;
1358       cp_walk_tree (&OMP_CLAUSES (stmt), cp_genericize_r, data, NULL);
1359       omp_ctx.is_parallel = TREE_CODE (stmt) == OMP_PARALLEL;
1360       omp_ctx.default_shared = omp_ctx.is_parallel;
1361       omp_ctx.outer = wtd->omp_ctx;
1362       omp_ctx.variables = splay_tree_new (splay_tree_compare_decl_uid, 0, 0);
1363       wtd->omp_ctx = &omp_ctx;
1364       for (c = OMP_CLAUSES (stmt); c; c = OMP_CLAUSE_CHAIN (c))
1365         switch (OMP_CLAUSE_CODE (c))
1366           {
1367           case OMP_CLAUSE_SHARED:
1368           case OMP_CLAUSE_PRIVATE:
1369           case OMP_CLAUSE_FIRSTPRIVATE:
1370           case OMP_CLAUSE_LASTPRIVATE:
1371             decl = OMP_CLAUSE_DECL (c);
1372             if (decl == error_mark_node || !omp_var_to_track (decl))
1373               break;
1374             n = splay_tree_lookup (omp_ctx.variables, (splay_tree_key) decl);
1375             if (n != NULL)
1376               break;
1377             splay_tree_insert (omp_ctx.variables, (splay_tree_key) decl,
1378                                OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
1379                                ? OMP_CLAUSE_DEFAULT_SHARED
1380                                : OMP_CLAUSE_DEFAULT_PRIVATE);
1381             if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_PRIVATE
1382                 && omp_ctx.outer)
1383               omp_cxx_notice_variable (omp_ctx.outer, decl);
1384             break;
1385           case OMP_CLAUSE_DEFAULT:
1386             if (OMP_CLAUSE_DEFAULT_KIND (c) == OMP_CLAUSE_DEFAULT_SHARED)
1387               omp_ctx.default_shared = true;
1388           default:
1389             break;
1390           }
1391       if (TREE_CODE (stmt) == OMP_TASKLOOP)
1392         genericize_omp_for_stmt (stmt_p, walk_subtrees, data);
1393       else
1394         cp_walk_tree (&OMP_BODY (stmt), cp_genericize_r, data, NULL);
1395       wtd->omp_ctx = omp_ctx.outer;
1396       splay_tree_delete (omp_ctx.variables);
1397     }
1398   else if (TREE_CODE (stmt) == TRY_BLOCK)
1399     {
1400       *walk_subtrees = 0;
1401       tree try_block = wtd->try_block;
1402       wtd->try_block = stmt;
1403       cp_walk_tree (&TRY_STMTS (stmt), cp_genericize_r, data, NULL);
1404       wtd->try_block = try_block;
1405       cp_walk_tree (&TRY_HANDLERS (stmt), cp_genericize_r, data, NULL);
1406     }
1407   else if (TREE_CODE (stmt) == MUST_NOT_THROW_EXPR)
1408     {
1409       /* MUST_NOT_THROW_COND might be something else with TM.  */
1410       if (MUST_NOT_THROW_COND (stmt) == NULL_TREE)
1411         {
1412           *walk_subtrees = 0;
1413           tree try_block = wtd->try_block;
1414           wtd->try_block = stmt;
1415           cp_walk_tree (&TREE_OPERAND (stmt, 0), cp_genericize_r, data, NULL);
1416           wtd->try_block = try_block;
1417         }
1418     }
1419   else if (TREE_CODE (stmt) == THROW_EXPR)
1420     {
1421       location_t loc = location_of (stmt);
1422       if (TREE_NO_WARNING (stmt))
1423         /* Never mind.  */;
1424       else if (wtd->try_block)
1425         {
1426           if (TREE_CODE (wtd->try_block) == MUST_NOT_THROW_EXPR
1427               && warning_at (loc, OPT_Wterminate,
1428                              "throw will always call terminate()")
1429               && cxx_dialect >= cxx11
1430               && DECL_DESTRUCTOR_P (current_function_decl))
1431             inform (loc, "in C++11 destructors default to noexcept");
1432         }
1433       else
1434         {
1435           if (warn_cxx11_compat && cxx_dialect < cxx11
1436               && DECL_DESTRUCTOR_P (current_function_decl)
1437               && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))
1438                   == NULL_TREE)
1439               && (get_defaulted_eh_spec (current_function_decl)
1440                   == empty_except_spec))
1441             warning_at (loc, OPT_Wc__11_compat,
1442                         "in C++11 this throw will terminate because "
1443                         "destructors default to noexcept");
1444         }
1445     }
1446   else if (TREE_CODE (stmt) == CONVERT_EXPR)
1447     gcc_assert (!CONVERT_EXPR_VBASE_PATH (stmt));
1448   else if (TREE_CODE (stmt) == FOR_STMT)
1449     genericize_for_stmt (stmt_p, walk_subtrees, data);
1450   else if (TREE_CODE (stmt) == WHILE_STMT)
1451     genericize_while_stmt (stmt_p, walk_subtrees, data);
1452   else if (TREE_CODE (stmt) == DO_STMT)
1453     genericize_do_stmt (stmt_p, walk_subtrees, data);
1454   else if (TREE_CODE (stmt) == SWITCH_STMT)
1455     genericize_switch_stmt (stmt_p, walk_subtrees, data);
1456   else if (TREE_CODE (stmt) == CONTINUE_STMT)
1457     genericize_continue_stmt (stmt_p);
1458   else if (TREE_CODE (stmt) == BREAK_STMT)
1459     genericize_break_stmt (stmt_p);
1460   else if (TREE_CODE (stmt) == OMP_FOR
1461            || TREE_CODE (stmt) == OMP_SIMD
1462            || TREE_CODE (stmt) == OMP_DISTRIBUTE)
1463     genericize_omp_for_stmt (stmt_p, walk_subtrees, data);
1464   else if (TREE_CODE (stmt) == PTRMEM_CST)
1465     {
1466       /* By the time we get here we're handing off to the back end, so we don't
1467          need or want to preserve PTRMEM_CST anymore.  */
1468       *stmt_p = cplus_expand_constant (stmt);
1469       *walk_subtrees = 0;
1470     }
1471   else if ((flag_sanitize
1472             & (SANITIZE_NULL | SANITIZE_ALIGNMENT | SANITIZE_VPTR))
1473            && !wtd->no_sanitize_p)
1474     {
1475       if ((flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
1476           && TREE_CODE (stmt) == NOP_EXPR
1477           && TREE_CODE (TREE_TYPE (stmt)) == REFERENCE_TYPE)
1478         ubsan_maybe_instrument_reference (stmt);
1479       else if (TREE_CODE (stmt) == CALL_EXPR)
1480         {
1481           tree fn = CALL_EXPR_FN (stmt);
1482           if (fn != NULL_TREE
1483               && !error_operand_p (fn)
1484               && POINTER_TYPE_P (TREE_TYPE (fn))
1485               && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) == METHOD_TYPE)
1486             {
1487               bool is_ctor
1488                 = TREE_CODE (fn) == ADDR_EXPR
1489                   && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
1490                   && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0));
1491               if (flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT))
1492                 ubsan_maybe_instrument_member_call (stmt, is_ctor);
1493               if ((flag_sanitize & SANITIZE_VPTR) && !is_ctor)
1494                 cp_ubsan_maybe_instrument_member_call (stmt);
1495             }
1496         }
1497     }
1498
1499   p_set->add (*stmt_p);
1500
1501   return NULL;
1502 }
1503
1504 /* Lower C++ front end trees to GENERIC in T_P.  */
1505
1506 static void
1507 cp_genericize_tree (tree* t_p)
1508 {
1509   struct cp_genericize_data wtd;
1510
1511   wtd.p_set = new hash_set<tree>;
1512   wtd.bind_expr_stack.create (0);
1513   wtd.omp_ctx = NULL;
1514   wtd.try_block = NULL_TREE;
1515   wtd.no_sanitize_p = false;
1516   cp_walk_tree (t_p, cp_genericize_r, &wtd, NULL);
1517   delete wtd.p_set;
1518   wtd.bind_expr_stack.release ();
1519   if (flag_sanitize & SANITIZE_VPTR)
1520     cp_ubsan_instrument_member_accesses (t_p);
1521 }
1522
1523 /* If a function that should end with a return in non-void
1524    function doesn't obviously end with return, add ubsan
1525    instrumentation code to verify it at runtime.  */
1526
1527 static void
1528 cp_ubsan_maybe_instrument_return (tree fndecl)
1529 {
1530   if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl)))
1531       || DECL_CONSTRUCTOR_P (fndecl)
1532       || DECL_DESTRUCTOR_P (fndecl)
1533       || !targetm.warn_func_return (fndecl))
1534     return;
1535
1536   tree t = DECL_SAVED_TREE (fndecl);
1537   while (t)
1538     {
1539       switch (TREE_CODE (t))
1540         {
1541         case BIND_EXPR:
1542           t = BIND_EXPR_BODY (t);
1543           continue;
1544         case TRY_FINALLY_EXPR:
1545           t = TREE_OPERAND (t, 0);
1546           continue;
1547         case STATEMENT_LIST:
1548           {
1549             tree_stmt_iterator i = tsi_last (t);
1550             if (!tsi_end_p (i))
1551               {
1552                 t = tsi_stmt (i);
1553                 continue;
1554               }
1555           }
1556           break;
1557         case RETURN_EXPR:
1558           return;
1559         default:
1560           break;
1561         }
1562       break;
1563     }
1564   if (t == NULL_TREE)
1565     return;
1566   t = DECL_SAVED_TREE (fndecl);
1567   if (TREE_CODE (t) == BIND_EXPR
1568       && TREE_CODE (BIND_EXPR_BODY (t)) == STATEMENT_LIST)
1569     {
1570       tree_stmt_iterator i = tsi_last (BIND_EXPR_BODY (t));
1571       t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl));
1572       tsi_link_after (&i, t, TSI_NEW_STMT);
1573     }
1574 }
1575
1576 void
1577 cp_genericize (tree fndecl)
1578 {
1579   tree t;
1580
1581   /* Fix up the types of parms passed by invisible reference.  */
1582   for (t = DECL_ARGUMENTS (fndecl); t; t = DECL_CHAIN (t))
1583     if (TREE_ADDRESSABLE (TREE_TYPE (t)))
1584       {
1585         /* If a function's arguments are copied to create a thunk,
1586            then DECL_BY_REFERENCE will be set -- but the type of the
1587            argument will be a pointer type, so we will never get
1588            here.  */
1589         gcc_assert (!DECL_BY_REFERENCE (t));
1590         gcc_assert (DECL_ARG_TYPE (t) != TREE_TYPE (t));
1591         TREE_TYPE (t) = DECL_ARG_TYPE (t);
1592         DECL_BY_REFERENCE (t) = 1;
1593         TREE_ADDRESSABLE (t) = 0;
1594         relayout_decl (t);
1595       }
1596
1597   /* Do the same for the return value.  */
1598   if (TREE_ADDRESSABLE (TREE_TYPE (DECL_RESULT (fndecl))))
1599     {
1600       t = DECL_RESULT (fndecl);
1601       TREE_TYPE (t) = build_reference_type (TREE_TYPE (t));
1602       DECL_BY_REFERENCE (t) = 1;
1603       TREE_ADDRESSABLE (t) = 0;
1604       relayout_decl (t);
1605       if (DECL_NAME (t))
1606         {
1607           /* Adjust DECL_VALUE_EXPR of the original var.  */
1608           tree outer = outer_curly_brace_block (current_function_decl);
1609           tree var;
1610
1611           if (outer)
1612             for (var = BLOCK_VARS (outer); var; var = DECL_CHAIN (var))
1613               if (DECL_NAME (t) == DECL_NAME (var)
1614                   && DECL_HAS_VALUE_EXPR_P (var)
1615                   && DECL_VALUE_EXPR (var) == t)
1616                 {
1617                   tree val = convert_from_reference (t);
1618                   SET_DECL_VALUE_EXPR (var, val);
1619                   break;
1620                 }
1621         }
1622     }
1623
1624   /* If we're a clone, the body is already GIMPLE.  */
1625   if (DECL_CLONED_FUNCTION_P (fndecl))
1626     return;
1627
1628   /* Allow cp_genericize calls to be nested.  */
1629   tree save_bc_label[2];
1630   save_bc_label[bc_break] = bc_label[bc_break];
1631   save_bc_label[bc_continue] = bc_label[bc_continue];
1632   bc_label[bc_break] = NULL_TREE;
1633   bc_label[bc_continue] = NULL_TREE;
1634
1635   /* Expand all the array notations here.  */
1636   if (flag_cilkplus 
1637       && contains_array_notation_expr (DECL_SAVED_TREE (fndecl)))
1638     DECL_SAVED_TREE (fndecl) = 
1639       expand_array_notation_exprs (DECL_SAVED_TREE (fndecl));
1640
1641   /* We do want to see every occurrence of the parms, so we can't just use
1642      walk_tree's hash functionality.  */
1643   cp_genericize_tree (&DECL_SAVED_TREE (fndecl));
1644
1645   if (flag_sanitize & SANITIZE_RETURN
1646       && do_ubsan_in_current_function ())
1647     cp_ubsan_maybe_instrument_return (fndecl);
1648
1649   /* Do everything else.  */
1650   c_genericize (fndecl);
1651
1652   gcc_assert (bc_label[bc_break] == NULL);
1653   gcc_assert (bc_label[bc_continue] == NULL);
1654   bc_label[bc_break] = save_bc_label[bc_break];
1655   bc_label[bc_continue] = save_bc_label[bc_continue];
1656 }
1657 \f
1658 /* Build code to apply FN to each member of ARG1 and ARG2.  FN may be
1659    NULL if there is in fact nothing to do.  ARG2 may be null if FN
1660    actually only takes one argument.  */
1661
1662 static tree
1663 cxx_omp_clause_apply_fn (tree fn, tree arg1, tree arg2)
1664 {
1665   tree defparm, parm, t;
1666   int i = 0;
1667   int nargs;
1668   tree *argarray;
1669
1670   if (fn == NULL)
1671     return NULL;
1672
1673   nargs = list_length (DECL_ARGUMENTS (fn));
1674   argarray = XALLOCAVEC (tree, nargs);
1675
1676   defparm = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fn)));
1677   if (arg2)
1678     defparm = TREE_CHAIN (defparm);
1679
1680   if (TREE_CODE (TREE_TYPE (arg1)) == ARRAY_TYPE)
1681     {
1682       tree inner_type = TREE_TYPE (arg1);
1683       tree start1, end1, p1;
1684       tree start2 = NULL, p2 = NULL;
1685       tree ret = NULL, lab;
1686
1687       start1 = arg1;
1688       start2 = arg2;
1689       do
1690         {
1691           inner_type = TREE_TYPE (inner_type);
1692           start1 = build4 (ARRAY_REF, inner_type, start1,
1693                            size_zero_node, NULL, NULL);
1694           if (arg2)
1695             start2 = build4 (ARRAY_REF, inner_type, start2,
1696                              size_zero_node, NULL, NULL);
1697         }
1698       while (TREE_CODE (inner_type) == ARRAY_TYPE);
1699       start1 = build_fold_addr_expr_loc (input_location, start1);
1700       if (arg2)
1701         start2 = build_fold_addr_expr_loc (input_location, start2);
1702
1703       end1 = TYPE_SIZE_UNIT (TREE_TYPE (arg1));
1704       end1 = fold_build_pointer_plus (start1, end1);
1705
1706       p1 = create_tmp_var (TREE_TYPE (start1));
1707       t = build2 (MODIFY_EXPR, TREE_TYPE (p1), p1, start1);
1708       append_to_statement_list (t, &ret);
1709
1710       if (arg2)
1711         {
1712           p2 = create_tmp_var (TREE_TYPE (start2));
1713           t = build2 (MODIFY_EXPR, TREE_TYPE (p2), p2, start2);
1714           append_to_statement_list (t, &ret);
1715         }
1716
1717       lab = create_artificial_label (input_location);
1718       t = build1 (LABEL_EXPR, void_type_node, lab);
1719       append_to_statement_list (t, &ret);
1720
1721       argarray[i++] = p1;
1722       if (arg2)
1723         argarray[i++] = p2;
1724       /* Handle default arguments.  */
1725       for (parm = defparm; parm && parm != void_list_node;
1726            parm = TREE_CHAIN (parm), i++)
1727         argarray[i] = convert_default_arg (TREE_VALUE (parm),
1728                                            TREE_PURPOSE (parm), fn, i,
1729                                            tf_warning_or_error);
1730       t = build_call_a (fn, i, argarray);
1731       t = fold_convert (void_type_node, t);
1732       t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
1733       append_to_statement_list (t, &ret);
1734
1735       t = fold_build_pointer_plus (p1, TYPE_SIZE_UNIT (inner_type));
1736       t = build2 (MODIFY_EXPR, TREE_TYPE (p1), p1, t);
1737       append_to_statement_list (t, &ret);
1738
1739       if (arg2)
1740         {
1741           t = fold_build_pointer_plus (p2, TYPE_SIZE_UNIT (inner_type));
1742           t = build2 (MODIFY_EXPR, TREE_TYPE (p2), p2, t);
1743           append_to_statement_list (t, &ret);
1744         }
1745
1746       t = build2 (NE_EXPR, boolean_type_node, p1, end1);
1747       t = build3 (COND_EXPR, void_type_node, t, build_and_jump (&lab), NULL);
1748       append_to_statement_list (t, &ret);
1749
1750       return ret;
1751     }
1752   else
1753     {
1754       argarray[i++] = build_fold_addr_expr_loc (input_location, arg1);
1755       if (arg2)
1756         argarray[i++] = build_fold_addr_expr_loc (input_location, arg2);
1757       /* Handle default arguments.  */
1758       for (parm = defparm; parm && parm != void_list_node;
1759            parm = TREE_CHAIN (parm), i++)
1760         argarray[i] = convert_default_arg (TREE_VALUE (parm),
1761                                            TREE_PURPOSE (parm),
1762                                            fn, i, tf_warning_or_error);
1763       t = build_call_a (fn, i, argarray);
1764       t = fold_convert (void_type_node, t);
1765       return fold_build_cleanup_point_expr (TREE_TYPE (t), t);
1766     }
1767 }
1768
1769 /* Return code to initialize DECL with its default constructor, or
1770    NULL if there's nothing to do.  */
1771
1772 tree
1773 cxx_omp_clause_default_ctor (tree clause, tree decl, tree /*outer*/)
1774 {
1775   tree info = CP_OMP_CLAUSE_INFO (clause);
1776   tree ret = NULL;
1777
1778   if (info)
1779     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 0), decl, NULL);
1780
1781   return ret;
1782 }
1783
1784 /* Return code to initialize DST with a copy constructor from SRC.  */
1785
1786 tree
1787 cxx_omp_clause_copy_ctor (tree clause, tree dst, tree src)
1788 {
1789   tree info = CP_OMP_CLAUSE_INFO (clause);
1790   tree ret = NULL;
1791
1792   if (info)
1793     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 0), dst, src);
1794   if (ret == NULL)
1795     ret = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
1796
1797   return ret;
1798 }
1799
1800 /* Similarly, except use an assignment operator instead.  */
1801
1802 tree
1803 cxx_omp_clause_assign_op (tree clause, tree dst, tree src)
1804 {
1805   tree info = CP_OMP_CLAUSE_INFO (clause);
1806   tree ret = NULL;
1807
1808   if (info)
1809     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 2), dst, src);
1810   if (ret == NULL)
1811     ret = build2 (MODIFY_EXPR, TREE_TYPE (dst), dst, src);
1812
1813   return ret;
1814 }
1815
1816 /* Return code to destroy DECL.  */
1817
1818 tree
1819 cxx_omp_clause_dtor (tree clause, tree decl)
1820 {
1821   tree info = CP_OMP_CLAUSE_INFO (clause);
1822   tree ret = NULL;
1823
1824   if (info)
1825     ret = cxx_omp_clause_apply_fn (TREE_VEC_ELT (info, 1), decl, NULL);
1826
1827   return ret;
1828 }
1829
1830 /* True if OpenMP should privatize what this DECL points to rather
1831    than the DECL itself.  */
1832
1833 bool
1834 cxx_omp_privatize_by_reference (const_tree decl)
1835 {
1836   return (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE
1837           || is_invisiref_parm (decl));
1838 }
1839
1840 /* Return true if DECL is const qualified var having no mutable member.  */
1841 bool
1842 cxx_omp_const_qual_no_mutable (tree decl)
1843 {
1844   tree type = TREE_TYPE (decl);
1845   if (TREE_CODE (type) == REFERENCE_TYPE)
1846     {
1847       if (!is_invisiref_parm (decl))
1848         return false;
1849       type = TREE_TYPE (type);
1850
1851       if (TREE_CODE (decl) == RESULT_DECL && DECL_NAME (decl))
1852         {
1853           /* NVR doesn't preserve const qualification of the
1854              variable's type.  */
1855           tree outer = outer_curly_brace_block (current_function_decl);
1856           tree var;
1857
1858           if (outer)
1859             for (var = BLOCK_VARS (outer); var; var = DECL_CHAIN (var))
1860               if (DECL_NAME (decl) == DECL_NAME (var)
1861                   && (TYPE_MAIN_VARIANT (type)
1862                       == TYPE_MAIN_VARIANT (TREE_TYPE (var))))
1863                 {
1864                   if (TYPE_READONLY (TREE_TYPE (var)))
1865                     type = TREE_TYPE (var);
1866                   break;
1867                 }
1868         }
1869     }
1870
1871   if (type == error_mark_node)
1872     return false;
1873
1874   /* Variables with const-qualified type having no mutable member
1875      are predetermined shared.  */
1876   if (TYPE_READONLY (type) && !cp_has_mutable_p (type))
1877     return true;
1878
1879   return false;
1880 }
1881
1882 /* True if OpenMP sharing attribute of DECL is predetermined.  */
1883
1884 enum omp_clause_default_kind
1885 cxx_omp_predetermined_sharing (tree decl)
1886 {
1887   /* Static data members are predetermined shared.  */
1888   if (TREE_STATIC (decl))
1889     {
1890       tree ctx = CP_DECL_CONTEXT (decl);
1891       if (TYPE_P (ctx) && MAYBE_CLASS_TYPE_P (ctx))
1892         return OMP_CLAUSE_DEFAULT_SHARED;
1893     }
1894
1895   /* Const qualified vars having no mutable member are predetermined
1896      shared.  */
1897   if (cxx_omp_const_qual_no_mutable (decl))
1898     return OMP_CLAUSE_DEFAULT_SHARED;
1899
1900   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
1901 }
1902
1903 /* Finalize an implicitly determined clause.  */
1904
1905 void
1906 cxx_omp_finish_clause (tree c, gimple_seq *)
1907 {
1908   tree decl, inner_type;
1909   bool make_shared = false;
1910
1911   if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE)
1912     return;
1913
1914   decl = OMP_CLAUSE_DECL (c);
1915   decl = require_complete_type (decl);
1916   inner_type = TREE_TYPE (decl);
1917   if (decl == error_mark_node)
1918     make_shared = true;
1919   else if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE)
1920     inner_type = TREE_TYPE (inner_type);
1921
1922   /* We're interested in the base element, not arrays.  */
1923   while (TREE_CODE (inner_type) == ARRAY_TYPE)
1924     inner_type = TREE_TYPE (inner_type);
1925
1926   /* Check for special function availability by building a call to one.
1927      Save the results, because later we won't be in the right context
1928      for making these queries.  */
1929   if (!make_shared
1930       && CLASS_TYPE_P (inner_type)
1931       && cxx_omp_create_clause_info (c, inner_type, false, true, false, true))
1932     make_shared = true;
1933
1934   if (make_shared)
1935     OMP_CLAUSE_CODE (c) = OMP_CLAUSE_SHARED;
1936 }
1937
1938 /* Return true if DECL's DECL_VALUE_EXPR (if any) should be
1939    disregarded in OpenMP construct, because it is going to be
1940    remapped during OpenMP lowering.  SHARED is true if DECL
1941    is going to be shared, false if it is going to be privatized.  */
1942
1943 bool
1944 cxx_omp_disregard_value_expr (tree decl, bool shared)
1945 {
1946   return !shared
1947          && VAR_P (decl)
1948          && DECL_HAS_VALUE_EXPR_P (decl)
1949          && DECL_ARTIFICIAL (decl)
1950          && DECL_LANG_SPECIFIC (decl)
1951          && DECL_OMP_PRIVATIZED_MEMBER (decl);
1952 }
1953
1954 /* Perform folding on expression X.  */
1955
1956 tree
1957 cp_fully_fold (tree x)
1958 {
1959   if (processing_template_decl)
1960     return x;
1961   /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't
1962      have to call both.  */
1963   x = maybe_constant_value (x);
1964   return cp_fold (x);
1965 }
1966
1967 /* Fold expression X which is used as an rvalue if RVAL is true.  */
1968
1969 static tree
1970 cp_fold_maybe_rvalue (tree x, bool rval)
1971 {
1972   while (true)
1973     {
1974       x = cp_fold (x);
1975       if (rval && DECL_P (x))
1976         {
1977           tree v = decl_constant_value (x);
1978           if (v != x && v != error_mark_node)
1979             {
1980               x = v;
1981               continue;
1982             }
1983         }
1984       break;
1985     }
1986   return x;
1987 }
1988
1989 /* Fold expression X which is used as an rvalue.  */
1990
1991 static tree
1992 cp_fold_rvalue (tree x)
1993 {
1994   return cp_fold_maybe_rvalue (x, true);
1995 }
1996
1997 /* c-common interface to cp_fold.  If IN_INIT, this is in a static initializer
1998    and certain changes are made to the folding done.  Or should be (FIXME).  We
1999    never touch maybe_const, as it is only used for the C front-end
2000    C_MAYBE_CONST_EXPR.  */
2001
2002 tree
2003 c_fully_fold (tree x, bool /*in_init*/, bool */*maybe_const*/)
2004 {
2005   /* c_fully_fold is only used on rvalues, and we need to fold CONST_DECL to
2006      INTEGER_CST.  */
2007   return cp_fold_rvalue (x);
2008 }
2009
2010 static GTY((deletable)) hash_map<tree, tree> *fold_cache;
2011
2012 /* Dispose of the whole FOLD_CACHE.  */
2013
2014 void
2015 clear_fold_cache (void)
2016 {
2017   if (fold_cache != NULL)
2018     fold_cache->empty ();
2019 }
2020
2021 /*  This function tries to fold an expression X.
2022     To avoid combinatorial explosion, folding results are kept in fold_cache.
2023     If we are processing a template or X is invalid, we don't fold at all.
2024     For performance reasons we don't cache expressions representing a
2025     declaration or constant.
2026     Function returns X or its folded variant.  */
2027
2028 static tree
2029 cp_fold (tree x)
2030 {
2031   tree op0, op1, op2, op3;
2032   tree org_x = x, r = NULL_TREE;
2033   enum tree_code code;
2034   location_t loc;
2035   bool rval_ops = true;
2036
2037   if (!x || x == error_mark_node)
2038     return x;
2039
2040   if (processing_template_decl
2041       || (EXPR_P (x) && (!TREE_TYPE (x) || TREE_TYPE (x) == error_mark_node)))
2042     return x;
2043
2044   /* Don't bother to cache DECLs or constants.  */
2045   if (DECL_P (x) || CONSTANT_CLASS_P (x))
2046     return x;
2047
2048   if (fold_cache == NULL)
2049     fold_cache = hash_map<tree, tree>::create_ggc (101);
2050
2051   if (tree *cached = fold_cache->get (x))
2052     return *cached;
2053
2054   code = TREE_CODE (x);
2055   switch (code)
2056     {
2057     case SIZEOF_EXPR:
2058       x = fold_sizeof_expr (x);
2059       break;
2060
2061     case VIEW_CONVERT_EXPR:
2062       rval_ops = false;
2063     case CONVERT_EXPR:
2064     case NOP_EXPR:
2065     case NON_LVALUE_EXPR:
2066
2067       if (VOID_TYPE_P (TREE_TYPE (x)))
2068         return x;
2069
2070       loc = EXPR_LOCATION (x);
2071       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops);
2072
2073       if (code == CONVERT_EXPR
2074           && SCALAR_TYPE_P (TREE_TYPE (x))
2075           && op0 != void_node)
2076         /* During parsing we used convert_to_*_nofold; re-convert now using the
2077            folding variants, since fold() doesn't do those transformations.  */
2078         x = fold (convert (TREE_TYPE (x), op0));
2079       else if (op0 != TREE_OPERAND (x, 0))
2080         {
2081           if (op0 == error_mark_node)
2082             x = error_mark_node;
2083           else
2084             x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
2085         }
2086       else
2087         x = fold (x);
2088
2089       /* Conversion of an out-of-range value has implementation-defined
2090          behavior; the language considers it different from arithmetic
2091          overflow, which is undefined.  */
2092       if (TREE_CODE (op0) == INTEGER_CST
2093           && TREE_OVERFLOW_P (x) && !TREE_OVERFLOW_P (op0))
2094         TREE_OVERFLOW (x) = false;
2095
2096       break;
2097
2098     case INDIRECT_REF:
2099       /* We don't need the decltype(auto) obfuscation anymore.  */
2100       if (REF_PARENTHESIZED_P (x))
2101         {
2102           tree p = maybe_undo_parenthesized_ref (x);
2103           return cp_fold (p);
2104         }
2105       goto unary;
2106
2107     case ADDR_EXPR:
2108     case REALPART_EXPR:
2109     case IMAGPART_EXPR:
2110       rval_ops = false;
2111     case CONJ_EXPR:
2112     case FIX_TRUNC_EXPR:
2113     case FLOAT_EXPR:
2114     case NEGATE_EXPR:
2115     case ABS_EXPR:
2116     case BIT_NOT_EXPR:
2117     case TRUTH_NOT_EXPR:
2118     case FIXED_CONVERT_EXPR:
2119     unary:
2120
2121       loc = EXPR_LOCATION (x);
2122       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops);
2123
2124       if (op0 != TREE_OPERAND (x, 0))
2125         {
2126           if (op0 == error_mark_node)
2127             x = error_mark_node;
2128           else
2129             {
2130               x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
2131               if (code == INDIRECT_REF
2132                   && (INDIRECT_REF_P (x) || TREE_CODE (x) == MEM_REF))
2133                 {
2134                   TREE_READONLY (x) = TREE_READONLY (org_x);
2135                   TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
2136                   TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
2137                 }
2138             }
2139         }
2140       else
2141         x = fold (x);
2142
2143       gcc_assert (TREE_CODE (x) != COND_EXPR
2144                   || !VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (x, 0))));
2145       break;
2146
2147     case UNARY_PLUS_EXPR:
2148       op0 = cp_fold_rvalue (TREE_OPERAND (x, 0));
2149       if (op0 == error_mark_node)
2150         x = error_mark_node;
2151       else
2152         x = fold_convert (TREE_TYPE (x), op0);
2153       break;
2154
2155     case POSTDECREMENT_EXPR:
2156     case POSTINCREMENT_EXPR:
2157     case INIT_EXPR:
2158     case PREDECREMENT_EXPR:
2159     case PREINCREMENT_EXPR:
2160     case COMPOUND_EXPR:
2161     case MODIFY_EXPR:
2162       rval_ops = false;
2163     case POINTER_PLUS_EXPR:
2164     case PLUS_EXPR:
2165     case MINUS_EXPR:
2166     case MULT_EXPR:
2167     case TRUNC_DIV_EXPR:
2168     case CEIL_DIV_EXPR:
2169     case FLOOR_DIV_EXPR:
2170     case ROUND_DIV_EXPR:
2171     case TRUNC_MOD_EXPR:
2172     case CEIL_MOD_EXPR:
2173     case ROUND_MOD_EXPR:
2174     case RDIV_EXPR:
2175     case EXACT_DIV_EXPR:
2176     case MIN_EXPR:
2177     case MAX_EXPR:
2178     case LSHIFT_EXPR:
2179     case RSHIFT_EXPR:
2180     case LROTATE_EXPR:
2181     case RROTATE_EXPR:
2182     case BIT_AND_EXPR:
2183     case BIT_IOR_EXPR:
2184     case BIT_XOR_EXPR:
2185     case TRUTH_AND_EXPR:
2186     case TRUTH_ANDIF_EXPR:
2187     case TRUTH_OR_EXPR:
2188     case TRUTH_ORIF_EXPR:
2189     case TRUTH_XOR_EXPR:
2190     case LT_EXPR: case LE_EXPR:
2191     case GT_EXPR: case GE_EXPR:
2192     case EQ_EXPR: case NE_EXPR:
2193     case UNORDERED_EXPR: case ORDERED_EXPR:
2194     case UNLT_EXPR: case UNLE_EXPR:
2195     case UNGT_EXPR: case UNGE_EXPR:
2196     case UNEQ_EXPR: case LTGT_EXPR:
2197     case RANGE_EXPR: case COMPLEX_EXPR:
2198
2199       loc = EXPR_LOCATION (x);
2200       op0 = cp_fold_maybe_rvalue (TREE_OPERAND (x, 0), rval_ops);
2201       op1 = cp_fold_rvalue (TREE_OPERAND (x, 1));
2202
2203       if (op0 != TREE_OPERAND (x, 0) || op1 != TREE_OPERAND (x, 1))
2204         {
2205           if (op0 == error_mark_node || op1 == error_mark_node)
2206             x = error_mark_node;
2207           else
2208             x = fold_build2_loc (loc, code, TREE_TYPE (x), op0, op1);
2209         }
2210       else
2211         x = fold (x);
2212
2213       if (TREE_NO_WARNING (org_x)
2214           && warn_nonnull_compare
2215           && COMPARISON_CLASS_P (org_x))
2216         {
2217           if (x == error_mark_node || TREE_CODE (x) == INTEGER_CST)
2218             ;
2219           else if (COMPARISON_CLASS_P (x))
2220             TREE_NO_WARNING (x) = 1;
2221           /* Otherwise give up on optimizing these, let GIMPLE folders
2222              optimize those later on.  */
2223           else if (op0 != TREE_OPERAND (org_x, 0)
2224                    || op1 != TREE_OPERAND (org_x, 1))
2225             {
2226               x = build2_loc (loc, code, TREE_TYPE (org_x), op0, op1);
2227               TREE_NO_WARNING (x) = 1;
2228             }
2229           else
2230             x = org_x;
2231         }
2232       break;
2233
2234     case VEC_COND_EXPR:
2235     case COND_EXPR:
2236
2237       /* Don't bother folding a void condition, since it can't produce a
2238          constant value.  Also, some statement-level uses of COND_EXPR leave
2239          one of the branches NULL, so folding would crash.  */
2240       if (VOID_TYPE_P (TREE_TYPE (x)))
2241         return x;
2242
2243       loc = EXPR_LOCATION (x);
2244       op0 = cp_fold_rvalue (TREE_OPERAND (x, 0));
2245       op1 = cp_fold (TREE_OPERAND (x, 1));
2246       op2 = cp_fold (TREE_OPERAND (x, 2));
2247
2248       if (op0 != TREE_OPERAND (x, 0)
2249           || op1 != TREE_OPERAND (x, 1)
2250           || op2 != TREE_OPERAND (x, 2))
2251         {
2252           if (op0 == error_mark_node
2253               || op1 == error_mark_node
2254               || op2 == error_mark_node)
2255             x = error_mark_node;
2256           else
2257             x = fold_build3_loc (loc, code, TREE_TYPE (x), op0, op1, op2);
2258         }
2259       else
2260         x = fold (x);
2261
2262       /* A COND_EXPR might have incompatible types in branches if one or both
2263          arms are bitfields.  If folding exposed such a branch, fix it up.  */
2264       if (TREE_CODE (x) != code)
2265         if (tree type = is_bitfield_expr_with_lowered_type (x))
2266           x = fold_convert (type, x);
2267
2268       break;
2269
2270     case CALL_EXPR:
2271       {
2272         int i, m, sv = optimize, nw = sv, changed = 0;
2273         tree callee = get_callee_fndecl (x);
2274
2275         /* Some built-in function calls will be evaluated at compile-time in
2276            fold ().  Set optimize to 1 when folding __builtin_constant_p inside
2277            a constexpr function so that fold_builtin_1 doesn't fold it to 0.  */
2278         if (callee && DECL_BUILT_IN (callee) && !optimize
2279             && DECL_IS_BUILTIN_CONSTANT_P (callee)
2280             && current_function_decl
2281             && DECL_DECLARED_CONSTEXPR_P (current_function_decl))
2282           nw = 1;
2283
2284         x = copy_node (x);
2285
2286         m = call_expr_nargs (x);
2287         for (i = 0; i < m; i++)
2288           {
2289             r = cp_fold (CALL_EXPR_ARG (x, i));
2290             if (r != CALL_EXPR_ARG (x, i))
2291               {
2292                 if (r == error_mark_node)
2293                   {
2294                     x = error_mark_node;
2295                     break;
2296                   }
2297                 changed = 1;
2298               }
2299             CALL_EXPR_ARG (x, i) = r;
2300           }
2301         if (x == error_mark_node)
2302           break;
2303
2304         optimize = nw;
2305         r = fold (x);
2306         optimize = sv;
2307
2308         if (TREE_CODE (r) != CALL_EXPR)
2309           {
2310             x = cp_fold (r);
2311             break;
2312           }
2313
2314         optimize = nw;
2315
2316         /* Invoke maybe_constant_value for functions declared
2317            constexpr and not called with AGGR_INIT_EXPRs.
2318            TODO:
2319            Do constexpr expansion of expressions where the call itself is not
2320            constant, but the call followed by an INDIRECT_REF is.  */
2321         if (callee && DECL_DECLARED_CONSTEXPR_P (callee)
2322             && !flag_no_inline)
2323           r = maybe_constant_value (x);
2324         optimize = sv;
2325
2326         if (TREE_CODE (r) != CALL_EXPR)
2327           {
2328             x = r;
2329             break;
2330           }
2331
2332         if (!changed)
2333           x = org_x;
2334         break;
2335       }
2336
2337     case CONSTRUCTOR:
2338       {
2339         unsigned i;
2340         constructor_elt *p;
2341         bool changed = false;
2342         vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (x);
2343         vec<constructor_elt, va_gc> *nelts = NULL;
2344         vec_safe_reserve (nelts, vec_safe_length (elts));
2345         FOR_EACH_VEC_SAFE_ELT (elts, i, p)
2346           {
2347             tree op = cp_fold (p->value);
2348             constructor_elt e = { p->index, op };
2349             nelts->quick_push (e);
2350             if (op != p->value)
2351               {
2352                 if (op == error_mark_node)
2353                   {
2354                     x = error_mark_node;
2355                     changed = false;
2356                     break;
2357                   }
2358                 changed = true;
2359               }
2360           }
2361         if (changed)
2362           x = build_constructor (TREE_TYPE (x), nelts);
2363         else
2364           vec_free (nelts);
2365         break;
2366       }
2367     case TREE_VEC:
2368       {
2369         bool changed = false;
2370         vec<tree, va_gc> *vec = make_tree_vector ();
2371         int i, n = TREE_VEC_LENGTH (x);
2372         vec_safe_reserve (vec, n);
2373
2374         for (i = 0; i < n; i++)
2375           {
2376             tree op = cp_fold (TREE_VEC_ELT (x, i));
2377             vec->quick_push (op);
2378             if (op != TREE_VEC_ELT (x, i))
2379               changed = true;
2380           }
2381
2382         if (changed)
2383           {
2384             r = copy_node (x);
2385             for (i = 0; i < n; i++)
2386               TREE_VEC_ELT (r, i) = (*vec)[i];
2387             x = r;
2388           }
2389
2390         release_tree_vector (vec);
2391       }
2392
2393       break;
2394
2395     case ARRAY_REF:
2396     case ARRAY_RANGE_REF:
2397
2398       loc = EXPR_LOCATION (x);
2399       op0 = cp_fold (TREE_OPERAND (x, 0));
2400       op1 = cp_fold (TREE_OPERAND (x, 1));
2401       op2 = cp_fold (TREE_OPERAND (x, 2));
2402       op3 = cp_fold (TREE_OPERAND (x, 3));
2403
2404       if (op0 != TREE_OPERAND (x, 0)
2405           || op1 != TREE_OPERAND (x, 1)
2406           || op2 != TREE_OPERAND (x, 2)
2407           || op3 != TREE_OPERAND (x, 3))
2408         {
2409           if (op0 == error_mark_node
2410               || op1 == error_mark_node
2411               || op2 == error_mark_node
2412               || op3 == error_mark_node)
2413             x = error_mark_node;
2414           else
2415             {
2416               x = build4_loc (loc, code, TREE_TYPE (x), op0, op1, op2, op3);
2417               TREE_READONLY (x) = TREE_READONLY (org_x);
2418               TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
2419               TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
2420             }
2421         }
2422
2423       x = fold (x);
2424       break;
2425
2426     default:
2427       return org_x;
2428     }
2429
2430   fold_cache->put (org_x, x);
2431   /* Prevent that we try to fold an already folded result again.  */
2432   if (x != org_x)
2433     fold_cache->put (x, x);
2434
2435   return x;
2436 }
2437
2438 #include "gt-cp-cp-gimplify.h"