annotate gcc/c-family/c-gimplify.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Tree lowering pass. This pass gimplifies the tree representation built
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 by the C-based front ends. The structure of gimplified, or
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 language-independent, trees is dictated by the grammar described in this
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 file.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
5 Copyright (C) 2002-2018 Free Software Foundation, Inc.
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 Lowering of expressions contributed by Sebastian Pop <s.pop@laposte.net>
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 Re-written to support lowering of whole function trees, documentation
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 and miscellaneous cleanups by Diego Novillo <dnovillo@redhat.com>
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 This file is part of GCC.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is free software; you can redistribute it and/or modify it under
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 the terms of the GNU General Public License as published by the Free
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 Software Foundation; either version 3, or (at your option) any later
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 version.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 WARRANTY; without even the implied warranty of MERCHANTABILITY or
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 for more details.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 You should have received a copy of the GNU General Public License
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 along with GCC; see the file COPYING3. If not see
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "config.h"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "system.h"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "coretypes.h"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "tm.h"
111
kono
parents: 68
diff changeset
30 #include "function.h"
kono
parents: 68
diff changeset
31 #include "basic-block.h"
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "tree.h"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #include "gimple.h"
111
kono
parents: 68
diff changeset
34 #include "cgraph.h"
kono
parents: 68
diff changeset
35 #include "c-pretty-print.h"
kono
parents: 68
diff changeset
36 #include "gimplify.h"
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 #include "langhooks.h"
111
kono
parents: 68
diff changeset
38 #include "dumpfile.h"
kono
parents: 68
diff changeset
39 #include "c-ubsan.h"
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 /* The gimplification pass converts the language-dependent trees
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 (ld-trees) emitted by the parser into language-independent trees
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 (li-trees) that are the target of SSA analysis and transformations.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 Language-independent trees are based on the SIMPLE intermediate
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 representation used in the McCAT compiler framework:
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 "Designing the McCAT Compiler Based on a Family of Structured
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 Intermediate Representations,"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 L. Hendren, C. Donawa, M. Emami, G. Gao, Justiani, and B. Sridharan,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 Proceedings of the 5th International Workshop on Languages and
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 Compilers for Parallel Computing, no. 757 in Lecture Notes in
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 Computer Science, New Haven, Connecticut, pp. 406-420,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 Springer-Verlag, August 3-5, 1992.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 http://www-acaps.cs.mcgill.ca/info/McCAT/McCAT.html
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 Basically, we walk down gimplifying the nodes that we encounter. As we
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 walk back up, we check that they fit our constraints, and copy them
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 into temporaries if not. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
111
kono
parents: 68
diff changeset
62 /* Callback for c_genericize. */
kono
parents: 68
diff changeset
63
kono
parents: 68
diff changeset
64 static tree
kono
parents: 68
diff changeset
65 ubsan_walk_array_refs_r (tree *tp, int *walk_subtrees, void *data)
kono
parents: 68
diff changeset
66 {
kono
parents: 68
diff changeset
67 hash_set<tree> *pset = (hash_set<tree> *) data;
kono
parents: 68
diff changeset
68
kono
parents: 68
diff changeset
69 if (TREE_CODE (*tp) == BIND_EXPR)
kono
parents: 68
diff changeset
70 {
kono
parents: 68
diff changeset
71 /* Since walk_tree doesn't call the callback function on the decls
kono
parents: 68
diff changeset
72 in BIND_EXPR_VARS, we have to walk them manually, so we can avoid
kono
parents: 68
diff changeset
73 instrumenting DECL_INITIAL of TREE_STATIC vars. */
kono
parents: 68
diff changeset
74 *walk_subtrees = 0;
kono
parents: 68
diff changeset
75 for (tree decl = BIND_EXPR_VARS (*tp); decl; decl = DECL_CHAIN (decl))
kono
parents: 68
diff changeset
76 {
kono
parents: 68
diff changeset
77 if (TREE_STATIC (decl))
kono
parents: 68
diff changeset
78 continue;
kono
parents: 68
diff changeset
79 walk_tree (&DECL_INITIAL (decl), ubsan_walk_array_refs_r, pset,
kono
parents: 68
diff changeset
80 pset);
kono
parents: 68
diff changeset
81 walk_tree (&DECL_SIZE (decl), ubsan_walk_array_refs_r, pset, pset);
kono
parents: 68
diff changeset
82 walk_tree (&DECL_SIZE_UNIT (decl), ubsan_walk_array_refs_r, pset,
kono
parents: 68
diff changeset
83 pset);
kono
parents: 68
diff changeset
84 }
kono
parents: 68
diff changeset
85 walk_tree (&BIND_EXPR_BODY (*tp), ubsan_walk_array_refs_r, pset, pset);
kono
parents: 68
diff changeset
86 }
kono
parents: 68
diff changeset
87 else if (TREE_CODE (*tp) == ADDR_EXPR
kono
parents: 68
diff changeset
88 && TREE_CODE (TREE_OPERAND (*tp, 0)) == ARRAY_REF)
kono
parents: 68
diff changeset
89 {
kono
parents: 68
diff changeset
90 ubsan_maybe_instrument_array_ref (&TREE_OPERAND (*tp, 0), true);
kono
parents: 68
diff changeset
91 /* Make sure ubsan_maybe_instrument_array_ref is not called again
kono
parents: 68
diff changeset
92 on the ARRAY_REF, the above call might not instrument anything
kono
parents: 68
diff changeset
93 as the index might be constant or masked, so ensure it is not
kono
parents: 68
diff changeset
94 walked again and walk its subtrees manually. */
kono
parents: 68
diff changeset
95 tree aref = TREE_OPERAND (*tp, 0);
kono
parents: 68
diff changeset
96 pset->add (aref);
kono
parents: 68
diff changeset
97 *walk_subtrees = 0;
kono
parents: 68
diff changeset
98 walk_tree (&TREE_OPERAND (aref, 0), ubsan_walk_array_refs_r, pset, pset);
kono
parents: 68
diff changeset
99 walk_tree (&TREE_OPERAND (aref, 1), ubsan_walk_array_refs_r, pset, pset);
kono
parents: 68
diff changeset
100 walk_tree (&TREE_OPERAND (aref, 2), ubsan_walk_array_refs_r, pset, pset);
kono
parents: 68
diff changeset
101 walk_tree (&TREE_OPERAND (aref, 3), ubsan_walk_array_refs_r, pset, pset);
kono
parents: 68
diff changeset
102 }
kono
parents: 68
diff changeset
103 else if (TREE_CODE (*tp) == ARRAY_REF)
kono
parents: 68
diff changeset
104 ubsan_maybe_instrument_array_ref (tp, false);
kono
parents: 68
diff changeset
105 return NULL_TREE;
kono
parents: 68
diff changeset
106 }
kono
parents: 68
diff changeset
107
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 /* Gimplification of statement trees. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 /* Convert the tree representation of FNDECL from C frontend trees to
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 GENERIC. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 void
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 c_genericize (tree fndecl)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 FILE *dump_orig;
111
kono
parents: 68
diff changeset
117 dump_flags_t local_dump_flags;
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 struct cgraph_node *cgn;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
111
kono
parents: 68
diff changeset
120 if (flag_sanitize & SANITIZE_BOUNDS)
kono
parents: 68
diff changeset
121 {
kono
parents: 68
diff changeset
122 hash_set<tree> pset;
kono
parents: 68
diff changeset
123 walk_tree (&DECL_SAVED_TREE (fndecl), ubsan_walk_array_refs_r, &pset,
kono
parents: 68
diff changeset
124 &pset);
kono
parents: 68
diff changeset
125 }
kono
parents: 68
diff changeset
126
kono
parents: 68
diff changeset
127 if (warn_duplicated_branches)
kono
parents: 68
diff changeset
128 walk_tree_without_duplicates (&DECL_SAVED_TREE (fndecl),
kono
parents: 68
diff changeset
129 do_warn_duplicated_branches_r, NULL);
kono
parents: 68
diff changeset
130
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 /* Dump the C-specific tree IR. */
111
kono
parents: 68
diff changeset
132 dump_orig = get_dump_info (TDI_original, &local_dump_flags);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 if (dump_orig)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 fprintf (dump_orig, "\n;; Function %s",
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 lang_hooks.decl_printable_name (fndecl, 2));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 fprintf (dump_orig, " (%s)\n",
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 (!DECL_ASSEMBLER_NAME_SET_P (fndecl) ? "null"
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 : IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl))));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 fprintf (dump_orig, ";; enabled by -%s\n", dump_flag_name (TDI_original));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 fprintf (dump_orig, "\n");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 if (local_dump_flags & TDF_RAW)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 dump_node (DECL_SAVED_TREE (fndecl),
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 TDF_SLIM | local_dump_flags, dump_orig);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 print_c_tree (dump_orig, DECL_SAVED_TREE (fndecl));
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 fprintf (dump_orig, "\n");
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 /* Dump all nested functions now. */
111
kono
parents: 68
diff changeset
152 cgn = cgraph_node::get_create (fndecl);
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 c_genericize (cgn->decl);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 static void
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 add_block_to_enclosing (tree block)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 unsigned i;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 tree enclosing;
111
kono
parents: 68
diff changeset
162 gbind *bind;
kono
parents: 68
diff changeset
163 vec<gbind *> stack = gimple_bind_expr_stack ();
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164
111
kono
parents: 68
diff changeset
165 FOR_EACH_VEC_ELT (stack, i, bind)
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 if (gimple_bind_block (bind))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 break;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 enclosing = gimple_bind_block (bind);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 BLOCK_SUBBLOCKS (enclosing) = chainon (BLOCK_SUBBLOCKS (enclosing), block);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 /* Genericize a scope by creating a new BIND_EXPR.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 BLOCK is either a BLOCK representing the scope or a chain of _DECLs.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 In the latter case, we need to create a new BLOCK and add it to the
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 BLOCK_SUBBLOCKS of the enclosing block.
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 BODY is a chain of C _STMT nodes for the contents of the scope, to be
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 genericized. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 tree
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 c_build_bind_expr (location_t loc, tree block, tree body)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 tree decls, bind;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 if (block == NULL_TREE)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 decls = NULL_TREE;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 else if (TREE_CODE (block) == BLOCK)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 decls = BLOCK_VARS (block);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 decls = block;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 if (DECL_ARTIFICIAL (decls))
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 block = NULL_TREE;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 block = make_node (BLOCK);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 BLOCK_VARS (block) = decls;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 add_block_to_enclosing (block);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 if (!body)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 body = build_empty_stmt (loc);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 if (decls || block)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 bind = build3 (BIND_EXPR, void_type_node, decls, body, block);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 TREE_SIDE_EFFECTS (bind) = 1;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 SET_EXPR_LOCATION (bind, loc);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 else
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 bind = body;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 return bind;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 }
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 /* Gimplification of expression trees. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 /* Do C-specific gimplification on *EXPR_P. PRE_P and POST_P are as in
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 gimplify_expr. */
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 int
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 c_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 gimple_seq *post_p ATTRIBUTE_UNUSED)
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 {
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 enum tree_code code = TREE_CODE (*expr_p);
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
111
kono
parents: 68
diff changeset
227 switch (code)
kono
parents: 68
diff changeset
228 {
kono
parents: 68
diff changeset
229 case LSHIFT_EXPR:
kono
parents: 68
diff changeset
230 case RSHIFT_EXPR:
kono
parents: 68
diff changeset
231 case LROTATE_EXPR:
kono
parents: 68
diff changeset
232 case RROTATE_EXPR:
kono
parents: 68
diff changeset
233 {
kono
parents: 68
diff changeset
234 /* We used to convert the right operand of a shift-expression
kono
parents: 68
diff changeset
235 to an integer_type_node in the FEs. But it is unnecessary
kono
parents: 68
diff changeset
236 and not desirable for diagnostics and sanitizers. We keep
kono
parents: 68
diff changeset
237 this here to not pessimize the code, but we convert to an
kono
parents: 68
diff changeset
238 unsigned type, because negative shift counts are undefined
kono
parents: 68
diff changeset
239 anyway.
kono
parents: 68
diff changeset
240 We should get rid of this conversion when we have a proper
kono
parents: 68
diff changeset
241 type demotion/promotion pass. */
kono
parents: 68
diff changeset
242 tree *op1_p = &TREE_OPERAND (*expr_p, 1);
kono
parents: 68
diff changeset
243 if (!VECTOR_TYPE_P (TREE_TYPE (*op1_p))
kono
parents: 68
diff changeset
244 && !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
kono
parents: 68
diff changeset
245 unsigned_type_node)
kono
parents: 68
diff changeset
246 && !types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (*op1_p)),
kono
parents: 68
diff changeset
247 integer_type_node))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
248 /* Make sure to unshare the result, tree sharing is invalid
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
249 during gimplification. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
250 *op1_p = unshare_expr (convert (unsigned_type_node, *op1_p));
111
kono
parents: 68
diff changeset
251 break;
kono
parents: 68
diff changeset
252 }
kono
parents: 68
diff changeset
253
kono
parents: 68
diff changeset
254 case DECL_EXPR:
kono
parents: 68
diff changeset
255 /* This is handled mostly by gimplify.c, but we have to deal with
kono
parents: 68
diff changeset
256 not warning about int x = x; as it is a GCC extension to turn off
kono
parents: 68
diff changeset
257 this warning but only if warn_init_self is zero. */
kono
parents: 68
diff changeset
258 if (VAR_P (DECL_EXPR_DECL (*expr_p))
kono
parents: 68
diff changeset
259 && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p))
kono
parents: 68
diff changeset
260 && !TREE_STATIC (DECL_EXPR_DECL (*expr_p))
kono
parents: 68
diff changeset
261 && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p))
kono
parents: 68
diff changeset
262 && !warn_init_self)
kono
parents: 68
diff changeset
263 TREE_NO_WARNING (DECL_EXPR_DECL (*expr_p)) = 1;
kono
parents: 68
diff changeset
264 break;
kono
parents: 68
diff changeset
265
kono
parents: 68
diff changeset
266 case PREINCREMENT_EXPR:
kono
parents: 68
diff changeset
267 case PREDECREMENT_EXPR:
kono
parents: 68
diff changeset
268 case POSTINCREMENT_EXPR:
kono
parents: 68
diff changeset
269 case POSTDECREMENT_EXPR:
kono
parents: 68
diff changeset
270 {
kono
parents: 68
diff changeset
271 tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0));
kono
parents: 68
diff changeset
272 if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type))
kono
parents: 68
diff changeset
273 {
kono
parents: 68
diff changeset
274 if (!TYPE_OVERFLOW_WRAPS (type))
kono
parents: 68
diff changeset
275 type = unsigned_type_for (type);
kono
parents: 68
diff changeset
276 return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type);
kono
parents: 68
diff changeset
277 }
kono
parents: 68
diff changeset
278 break;
kono
parents: 68
diff changeset
279 }
kono
parents: 68
diff changeset
280
kono
parents: 68
diff changeset
281 default:;
kono
parents: 68
diff changeset
282 }
68
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 return GS_UNHANDLED;
561a7518be6b update gcc-4.6
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 }