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