annotate gcc/gimple-ssa-warn-alloca.c @ 132:d34655255c78

update gcc-8.2
author mir3636
date Thu, 25 Oct 2018 10:21:07 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Warn on problematic uses of alloca and variable length arrays.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Aldy Hernandez <aldyh@redhat.com>.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "backend.h"
kono
parents:
diff changeset
25 #include "tree.h"
kono
parents:
diff changeset
26 #include "gimple.h"
kono
parents:
diff changeset
27 #include "tree-pass.h"
kono
parents:
diff changeset
28 #include "ssa.h"
kono
parents:
diff changeset
29 #include "gimple-pretty-print.h"
kono
parents:
diff changeset
30 #include "diagnostic-core.h"
kono
parents:
diff changeset
31 #include "fold-const.h"
kono
parents:
diff changeset
32 #include "gimple-iterator.h"
kono
parents:
diff changeset
33 #include "tree-ssa.h"
kono
parents:
diff changeset
34 #include "params.h"
kono
parents:
diff changeset
35 #include "tree-cfg.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
36 #include "builtins.h"
111
kono
parents:
diff changeset
37 #include "calls.h"
kono
parents:
diff changeset
38 #include "cfgloop.h"
kono
parents:
diff changeset
39 #include "intl.h"
kono
parents:
diff changeset
40
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41 static unsigned HOST_WIDE_INT adjusted_warn_limit (bool);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42
111
kono
parents:
diff changeset
43 const pass_data pass_data_walloca = {
kono
parents:
diff changeset
44 GIMPLE_PASS,
kono
parents:
diff changeset
45 "walloca",
kono
parents:
diff changeset
46 OPTGROUP_NONE,
kono
parents:
diff changeset
47 TV_NONE,
kono
parents:
diff changeset
48 PROP_cfg, // properties_required
kono
parents:
diff changeset
49 0, // properties_provided
kono
parents:
diff changeset
50 0, // properties_destroyed
kono
parents:
diff changeset
51 0, // properties_start
kono
parents:
diff changeset
52 0, // properties_finish
kono
parents:
diff changeset
53 };
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 class pass_walloca : public gimple_opt_pass
kono
parents:
diff changeset
56 {
kono
parents:
diff changeset
57 public:
kono
parents:
diff changeset
58 pass_walloca (gcc::context *ctxt)
kono
parents:
diff changeset
59 : gimple_opt_pass(pass_data_walloca, ctxt), first_time_p (false)
kono
parents:
diff changeset
60 {}
kono
parents:
diff changeset
61 opt_pass *clone () { return new pass_walloca (m_ctxt); }
kono
parents:
diff changeset
62 void set_pass_param (unsigned int n, bool param)
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 gcc_assert (n == 0);
kono
parents:
diff changeset
65 first_time_p = param;
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67 virtual bool gate (function *);
kono
parents:
diff changeset
68 virtual unsigned int execute (function *);
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 private:
kono
parents:
diff changeset
71 // Set to TRUE the first time we run this pass on a function.
kono
parents:
diff changeset
72 bool first_time_p;
kono
parents:
diff changeset
73 };
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 bool
kono
parents:
diff changeset
76 pass_walloca::gate (function *fun ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
77 {
kono
parents:
diff changeset
78 // The first time this pass is called, it is called before
kono
parents:
diff changeset
79 // optimizations have been run and range information is unavailable,
kono
parents:
diff changeset
80 // so we can only perform strict alloca checking.
kono
parents:
diff changeset
81 if (first_time_p)
kono
parents:
diff changeset
82 return warn_alloca != 0;
kono
parents:
diff changeset
83
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84 // Warning is disabled when its size limit is greater than PTRDIFF_MAX
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85 // for the target maximum, which makes the limit negative since when
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 // represented in signed HOST_WIDE_INT.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 unsigned HOST_WIDE_INT max = tree_to_uhwi (TYPE_MAX_VALUE (ptrdiff_type_node));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88 return (adjusted_warn_limit (false) <= max
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89 || adjusted_warn_limit (true) <= max);
111
kono
parents:
diff changeset
90 }
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 // Possible problematic uses of alloca.
kono
parents:
diff changeset
93 enum alloca_type {
kono
parents:
diff changeset
94 // Alloca argument is within known bounds that are appropriate.
kono
parents:
diff changeset
95 ALLOCA_OK,
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 // Alloca argument is KNOWN to have a value that is too large.
kono
parents:
diff changeset
98 ALLOCA_BOUND_DEFINITELY_LARGE,
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 // Alloca argument may be too large.
kono
parents:
diff changeset
101 ALLOCA_BOUND_MAYBE_LARGE,
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 // Alloca argument is bounded but of an indeterminate size.
kono
parents:
diff changeset
104 ALLOCA_BOUND_UNKNOWN,
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 // Alloca argument was casted from a signed integer.
kono
parents:
diff changeset
107 ALLOCA_CAST_FROM_SIGNED,
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 // Alloca appears in a loop.
kono
parents:
diff changeset
110 ALLOCA_IN_LOOP,
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 // Alloca argument is 0.
kono
parents:
diff changeset
113 ALLOCA_ARG_IS_ZERO,
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 // Alloca call is unbounded. That is, there is no controlling
kono
parents:
diff changeset
116 // predicate for its argument.
kono
parents:
diff changeset
117 ALLOCA_UNBOUNDED
kono
parents:
diff changeset
118 };
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 // Type of an alloca call with its corresponding limit, if applicable.
kono
parents:
diff changeset
121 struct alloca_type_and_limit {
kono
parents:
diff changeset
122 enum alloca_type type;
kono
parents:
diff changeset
123 // For ALLOCA_BOUND_MAYBE_LARGE and ALLOCA_BOUND_DEFINITELY_LARGE
kono
parents:
diff changeset
124 // types, this field indicates the assumed limit if known or
kono
parents:
diff changeset
125 // integer_zero_node if unknown. For any other alloca types, this
kono
parents:
diff changeset
126 // field is undefined.
kono
parents:
diff changeset
127 wide_int limit;
kono
parents:
diff changeset
128 alloca_type_and_limit ();
kono
parents:
diff changeset
129 alloca_type_and_limit (enum alloca_type type,
kono
parents:
diff changeset
130 wide_int i) : type(type), limit(i) { }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131 alloca_type_and_limit (enum alloca_type type) : type(type)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 { if (type == ALLOCA_BOUND_MAYBE_LARGE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133 || type == ALLOCA_BOUND_DEFINITELY_LARGE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134 limit = wi::to_wide (integer_zero_node);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 }
111
kono
parents:
diff changeset
136 };
kono
parents:
diff changeset
137
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 /* Return the value of the argument N to -Walloca-larger-than= or
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139 -Wvla-larger-than= adjusted for the target data model so that
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140 when N == HOST_WIDE_INT_MAX, the adjusted value is set to
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
141 PTRDIFF_MAX on the target. This is done to prevent warnings
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
142 for unknown/unbounded allocations in the "permissive mode"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
143 while still diagnosing excessive and necessarily invalid
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
144 allocations. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
145
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
146 static unsigned HOST_WIDE_INT
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
147 adjusted_warn_limit (bool idx)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
148 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
149 static HOST_WIDE_INT limits[2];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
150 if (limits[idx])
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
151 return limits[idx];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
152
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
153 limits[idx] = idx ? warn_vla_limit : warn_alloca_limit;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
154 if (limits[idx] != HOST_WIDE_INT_MAX)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
155 return limits[idx];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
156
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
157 limits[idx] = tree_to_shwi (TYPE_MAX_VALUE (ptrdiff_type_node));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
158 return limits[idx];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
159 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
160
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
161
111
kono
parents:
diff changeset
162 // NOTE: When we get better range info, this entire function becomes
kono
parents:
diff changeset
163 // irrelevant, as it should be possible to get range info for an SSA
kono
parents:
diff changeset
164 // name at any point in the program.
kono
parents:
diff changeset
165 //
kono
parents:
diff changeset
166 // We have a few heuristics up our sleeve to determine if a call to
kono
parents:
diff changeset
167 // alloca() is within bounds. Try them out and return the type of
kono
parents:
diff changeset
168 // alloca call with its assumed limit (if applicable).
kono
parents:
diff changeset
169 //
kono
parents:
diff changeset
170 // Given a known argument (ARG) to alloca() and an EDGE (E)
kono
parents:
diff changeset
171 // calculating said argument, verify that the last statement in the BB
kono
parents:
diff changeset
172 // in E->SRC is a gate comparing ARG to an acceptable bound for
kono
parents:
diff changeset
173 // alloca(). See examples below.
kono
parents:
diff changeset
174 //
kono
parents:
diff changeset
175 // If set, ARG_CASTED is the possible unsigned argument to which ARG
kono
parents:
diff changeset
176 // was casted to. This is to handle cases where the controlling
kono
parents:
diff changeset
177 // predicate is looking at a casted value, not the argument itself.
kono
parents:
diff changeset
178 // arg_casted = (size_t) arg;
kono
parents:
diff changeset
179 // if (arg_casted < N)
kono
parents:
diff changeset
180 // goto bb3;
kono
parents:
diff changeset
181 // else
kono
parents:
diff changeset
182 // goto bb5;
kono
parents:
diff changeset
183 //
kono
parents:
diff changeset
184 // MAX_SIZE is WARN_ALLOCA= adjusted for VLAs. It is the maximum size
kono
parents:
diff changeset
185 // in bytes we allow for arg.
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 static struct alloca_type_and_limit
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
188 alloca_call_type_by_arg (tree arg, tree arg_casted, edge e,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
189 unsigned HOST_WIDE_INT max_size)
111
kono
parents:
diff changeset
190 {
kono
parents:
diff changeset
191 basic_block bb = e->src;
kono
parents:
diff changeset
192 gimple_stmt_iterator gsi = gsi_last_bb (bb);
kono
parents:
diff changeset
193 gimple *last = gsi_stmt (gsi);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
194
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
195 const offset_int maxobjsize = tree_to_shwi (max_object_size ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
196
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 /* When MAX_SIZE is greater than or equal to PTRDIFF_MAX treat
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
198 allocations that aren't visibly constrained as OK, otherwise
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
199 report them as (potentially) unbounded. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
200 alloca_type unbounded_result = (max_size < maxobjsize.to_uhwi ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
201 ? ALLOCA_UNBOUNDED : ALLOCA_OK);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
202
111
kono
parents:
diff changeset
203 if (!last || gimple_code (last) != GIMPLE_COND)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
204 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
205 return alloca_type_and_limit (unbounded_result);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
206 }
111
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 enum tree_code cond_code = gimple_cond_code (last);
kono
parents:
diff changeset
209 if (e->flags & EDGE_TRUE_VALUE)
kono
parents:
diff changeset
210 ;
kono
parents:
diff changeset
211 else if (e->flags & EDGE_FALSE_VALUE)
kono
parents:
diff changeset
212 cond_code = invert_tree_comparison (cond_code, false);
kono
parents:
diff changeset
213 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
214 return alloca_type_and_limit (unbounded_result);
111
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 // Check for:
kono
parents:
diff changeset
217 // if (ARG .COND. N)
kono
parents:
diff changeset
218 // goto <bb 3>;
kono
parents:
diff changeset
219 // else
kono
parents:
diff changeset
220 // goto <bb 4>;
kono
parents:
diff changeset
221 // <bb 3>:
kono
parents:
diff changeset
222 // alloca(ARG);
kono
parents:
diff changeset
223 if ((cond_code == LE_EXPR
kono
parents:
diff changeset
224 || cond_code == LT_EXPR
kono
parents:
diff changeset
225 || cond_code == GT_EXPR
kono
parents:
diff changeset
226 || cond_code == GE_EXPR)
kono
parents:
diff changeset
227 && (gimple_cond_lhs (last) == arg
kono
parents:
diff changeset
228 || gimple_cond_lhs (last) == arg_casted))
kono
parents:
diff changeset
229 {
kono
parents:
diff changeset
230 if (TREE_CODE (gimple_cond_rhs (last)) == INTEGER_CST)
kono
parents:
diff changeset
231 {
kono
parents:
diff changeset
232 tree rhs = gimple_cond_rhs (last);
kono
parents:
diff changeset
233 int tst = wi::cmpu (wi::to_widest (rhs), max_size);
kono
parents:
diff changeset
234 if ((cond_code == LT_EXPR && tst == -1)
kono
parents:
diff changeset
235 || (cond_code == LE_EXPR && (tst == -1 || tst == 0)))
kono
parents:
diff changeset
236 return alloca_type_and_limit (ALLOCA_OK);
kono
parents:
diff changeset
237 else
kono
parents:
diff changeset
238 {
kono
parents:
diff changeset
239 // Let's not get too specific as to how large the limit
kono
parents:
diff changeset
240 // may be. Someone's clearly an idiot when things
kono
parents:
diff changeset
241 // degrade into "if (N > Y) alloca(N)".
kono
parents:
diff changeset
242 if (cond_code == GT_EXPR || cond_code == GE_EXPR)
kono
parents:
diff changeset
243 rhs = integer_zero_node;
kono
parents:
diff changeset
244 return alloca_type_and_limit (ALLOCA_BOUND_MAYBE_LARGE,
kono
parents:
diff changeset
245 wi::to_wide (rhs));
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
249 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
250 /* Analogous to ALLOCA_UNBOUNDED, when MAX_SIZE is greater
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
251 than or equal to PTRDIFF_MAX, treat allocations with
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
252 an unknown bound as OK. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
253 alloca_type unknown_result
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
254 = (max_size < maxobjsize.to_uhwi ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
255 ? ALLOCA_BOUND_UNKNOWN : ALLOCA_OK);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
256 return alloca_type_and_limit (unknown_result);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
257 }
111
kono
parents:
diff changeset
258 }
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 // Similarly, but check for a comparison with an unknown LIMIT.
kono
parents:
diff changeset
261 // if (LIMIT .COND. ARG)
kono
parents:
diff changeset
262 // alloca(arg);
kono
parents:
diff changeset
263 //
kono
parents:
diff changeset
264 // Where LIMIT has a bound of unknown range.
kono
parents:
diff changeset
265 //
kono
parents:
diff changeset
266 // Note: All conditions of the form (ARG .COND. XXXX) where covered
kono
parents:
diff changeset
267 // by the previous check above, so we only need to look for (LIMIT
kono
parents:
diff changeset
268 // .COND. ARG) here.
kono
parents:
diff changeset
269 tree limit = gimple_cond_lhs (last);
kono
parents:
diff changeset
270 if ((gimple_cond_rhs (last) == arg
kono
parents:
diff changeset
271 || gimple_cond_rhs (last) == arg_casted)
kono
parents:
diff changeset
272 && TREE_CODE (limit) == SSA_NAME)
kono
parents:
diff changeset
273 {
kono
parents:
diff changeset
274 wide_int min, max;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
275 value_range_kind range_type = get_range_info (limit, &min, &max);
111
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 if (range_type == VR_UNDEFINED || range_type == VR_VARYING)
kono
parents:
diff changeset
278 return alloca_type_and_limit (ALLOCA_BOUND_UNKNOWN);
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 // ?? It looks like the above `if' is unnecessary, as we never
kono
parents:
diff changeset
281 // get any VR_RANGE or VR_ANTI_RANGE here. If we had a range
kono
parents:
diff changeset
282 // for LIMIT, I suppose we would have taken care of it in
kono
parents:
diff changeset
283 // alloca_call_type(), or handled above where we handle (ARG .COND. N).
kono
parents:
diff changeset
284 //
kono
parents:
diff changeset
285 // If this ever triggers, we should probably figure out why and
kono
parents:
diff changeset
286 // handle it, though it is likely to be just an ALLOCA_UNBOUNDED.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
287 return alloca_type_and_limit (unbounded_result);
111
kono
parents:
diff changeset
288 }
kono
parents:
diff changeset
289
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
290 return alloca_type_and_limit (unbounded_result);
111
kono
parents:
diff changeset
291 }
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 // Return TRUE if SSA's definition is a cast from a signed type.
kono
parents:
diff changeset
294 // If so, set *INVALID_CASTED_TYPE to the signed type.
kono
parents:
diff changeset
295
kono
parents:
diff changeset
296 static bool
kono
parents:
diff changeset
297 cast_from_signed_p (tree ssa, tree *invalid_casted_type)
kono
parents:
diff changeset
298 {
kono
parents:
diff changeset
299 gimple *def = SSA_NAME_DEF_STMT (ssa);
kono
parents:
diff changeset
300 if (def
kono
parents:
diff changeset
301 && !gimple_nop_p (def)
kono
parents:
diff changeset
302 && gimple_assign_cast_p (def)
kono
parents:
diff changeset
303 && !TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def))))
kono
parents:
diff changeset
304 {
kono
parents:
diff changeset
305 *invalid_casted_type = TREE_TYPE (gimple_assign_rhs1 (def));
kono
parents:
diff changeset
306 return true;
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308 return false;
kono
parents:
diff changeset
309 }
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 // Return TRUE if X has a maximum range of MAX, basically covering the
kono
parents:
diff changeset
312 // entire domain, in which case it's no range at all.
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 static bool
kono
parents:
diff changeset
315 is_max (tree x, wide_int max)
kono
parents:
diff changeset
316 {
kono
parents:
diff changeset
317 return wi::max_value (TREE_TYPE (x)) == max;
kono
parents:
diff changeset
318 }
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 // Analyze the alloca call in STMT and return the alloca type with its
kono
parents:
diff changeset
321 // corresponding limit (if applicable). IS_VLA is set if the alloca
kono
parents:
diff changeset
322 // call was created by the gimplifier for a VLA.
kono
parents:
diff changeset
323 //
kono
parents:
diff changeset
324 // If the alloca call may be too large because of a cast from a signed
kono
parents:
diff changeset
325 // type to an unsigned type, set *INVALID_CASTED_TYPE to the
kono
parents:
diff changeset
326 // problematic signed type.
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 static struct alloca_type_and_limit
kono
parents:
diff changeset
329 alloca_call_type (gimple *stmt, bool is_vla, tree *invalid_casted_type)
kono
parents:
diff changeset
330 {
kono
parents:
diff changeset
331 gcc_assert (gimple_alloca_call_p (stmt));
kono
parents:
diff changeset
332 bool tentative_cast_from_signed = false;
kono
parents:
diff changeset
333 tree len = gimple_call_arg (stmt, 0);
kono
parents:
diff changeset
334 tree len_casted = NULL;
kono
parents:
diff changeset
335 wide_int min, max;
kono
parents:
diff changeset
336 edge_iterator ei;
kono
parents:
diff changeset
337 edge e;
kono
parents:
diff changeset
338
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
339 gcc_assert (!is_vla || warn_vla_limit >= 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
340 gcc_assert (is_vla || warn_alloca_limit >= 0);
111
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 // Adjust warn_alloca_max_size for VLAs, by taking the underlying
kono
parents:
diff changeset
343 // type into account.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 unsigned HOST_WIDE_INT max_size = adjusted_warn_limit (is_vla);
111
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 // Check for the obviously bounded case.
kono
parents:
diff changeset
347 if (TREE_CODE (len) == INTEGER_CST)
kono
parents:
diff changeset
348 {
kono
parents:
diff changeset
349 if (tree_to_uhwi (len) > max_size)
kono
parents:
diff changeset
350 return alloca_type_and_limit (ALLOCA_BOUND_DEFINITELY_LARGE,
kono
parents:
diff changeset
351 wi::to_wide (len));
kono
parents:
diff changeset
352 if (integer_zerop (len))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
353 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
354 const offset_int maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
355 = wi::to_offset (max_object_size ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
356 alloca_type result = (max_size < maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
357 ? ALLOCA_ARG_IS_ZERO : ALLOCA_OK);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
358 return alloca_type_and_limit (result);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
359 }
111
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 return alloca_type_and_limit (ALLOCA_OK);
kono
parents:
diff changeset
362 }
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 // Check the range info if available.
kono
parents:
diff changeset
365 if (TREE_CODE (len) == SSA_NAME)
kono
parents:
diff changeset
366 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
367 value_range_kind range_type = get_range_info (len, &min, &max);
111
kono
parents:
diff changeset
368 if (range_type == VR_RANGE)
kono
parents:
diff changeset
369 {
kono
parents:
diff changeset
370 if (wi::leu_p (max, max_size))
kono
parents:
diff changeset
371 return alloca_type_and_limit (ALLOCA_OK);
kono
parents:
diff changeset
372 else
kono
parents:
diff changeset
373 {
kono
parents:
diff changeset
374 // A cast may have created a range we don't care
kono
parents:
diff changeset
375 // about. For instance, a cast from 16-bit to
kono
parents:
diff changeset
376 // 32-bit creates a range of 0..65535, even if there
kono
parents:
diff changeset
377 // is not really a determinable range in the
kono
parents:
diff changeset
378 // underlying code. In this case, look through the
kono
parents:
diff changeset
379 // cast at the original argument, and fall through
kono
parents:
diff changeset
380 // to look at other alternatives.
kono
parents:
diff changeset
381 //
kono
parents:
diff changeset
382 // We only look at through the cast when its from
kono
parents:
diff changeset
383 // unsigned to unsigned, otherwise we may risk
kono
parents:
diff changeset
384 // looking at SIGNED_INT < N, which is clearly not
kono
parents:
diff changeset
385 // what we want. In this case, we'd be interested
kono
parents:
diff changeset
386 // in a VR_RANGE of [0..N].
kono
parents:
diff changeset
387 //
kono
parents:
diff changeset
388 // Note: None of this is perfect, and should all go
kono
parents:
diff changeset
389 // away with better range information. But it gets
kono
parents:
diff changeset
390 // most of the cases.
kono
parents:
diff changeset
391 gimple *def = SSA_NAME_DEF_STMT (len);
kono
parents:
diff changeset
392 if (gimple_assign_cast_p (def))
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 tree rhs1 = gimple_assign_rhs1 (def);
kono
parents:
diff changeset
395 tree rhs1type = TREE_TYPE (rhs1);
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 // Bail if the argument type is not valid.
kono
parents:
diff changeset
398 if (!INTEGRAL_TYPE_P (rhs1type))
kono
parents:
diff changeset
399 return alloca_type_and_limit (ALLOCA_OK);
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 if (TYPE_UNSIGNED (rhs1type))
kono
parents:
diff changeset
402 {
kono
parents:
diff changeset
403 len_casted = rhs1;
kono
parents:
diff changeset
404 range_type = get_range_info (len_casted, &min, &max);
kono
parents:
diff changeset
405 }
kono
parents:
diff changeset
406 }
kono
parents:
diff changeset
407 // An unknown range or a range of the entire domain is
kono
parents:
diff changeset
408 // really no range at all.
kono
parents:
diff changeset
409 if (range_type == VR_VARYING
kono
parents:
diff changeset
410 || (!len_casted && is_max (len, max))
kono
parents:
diff changeset
411 || (len_casted && is_max (len_casted, max)))
kono
parents:
diff changeset
412 {
kono
parents:
diff changeset
413 // Fall through.
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415 else if (range_type == VR_ANTI_RANGE)
kono
parents:
diff changeset
416 return alloca_type_and_limit (ALLOCA_UNBOUNDED);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
417
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
418 if (range_type != VR_VARYING)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
419 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
420 const offset_int maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
421 = wi::to_offset (max_object_size ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
422 alloca_type result = (max_size < maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
423 ? ALLOCA_BOUND_MAYBE_LARGE : ALLOCA_OK);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
424 return alloca_type_and_limit (result, max);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
425 }
111
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427 }
kono
parents:
diff changeset
428 else if (range_type == VR_ANTI_RANGE)
kono
parents:
diff changeset
429 {
kono
parents:
diff changeset
430 // There may be some wrapping around going on. Catch it
kono
parents:
diff changeset
431 // with this heuristic. Hopefully, this VR_ANTI_RANGE
kono
parents:
diff changeset
432 // nonsense will go away, and we won't have to catch the
kono
parents:
diff changeset
433 // sign conversion problems with this crap.
kono
parents:
diff changeset
434 //
kono
parents:
diff changeset
435 // This is here to catch things like:
kono
parents:
diff changeset
436 // void foo(signed int n) {
kono
parents:
diff changeset
437 // if (n < 100)
kono
parents:
diff changeset
438 // alloca(n);
kono
parents:
diff changeset
439 // ...
kono
parents:
diff changeset
440 // }
kono
parents:
diff changeset
441 if (cast_from_signed_p (len, invalid_casted_type))
kono
parents:
diff changeset
442 {
kono
parents:
diff changeset
443 // Unfortunately this also triggers:
kono
parents:
diff changeset
444 //
kono
parents:
diff changeset
445 // __SIZE_TYPE__ n = (__SIZE_TYPE__)blah;
kono
parents:
diff changeset
446 // if (n < 100)
kono
parents:
diff changeset
447 // alloca(n);
kono
parents:
diff changeset
448 //
kono
parents:
diff changeset
449 // ...which is clearly bounded. So, double check that
kono
parents:
diff changeset
450 // the paths leading up to the size definitely don't
kono
parents:
diff changeset
451 // have a bound.
kono
parents:
diff changeset
452 tentative_cast_from_signed = true;
kono
parents:
diff changeset
453 }
kono
parents:
diff changeset
454 }
kono
parents:
diff changeset
455 // No easily determined range and try other things.
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 // If we couldn't find anything, try a few heuristics for things we
kono
parents:
diff changeset
459 // can easily determine. Check these misc cases but only accept
kono
parents:
diff changeset
460 // them if all predecessors have a known bound.
kono
parents:
diff changeset
461 struct alloca_type_and_limit ret = alloca_type_and_limit (ALLOCA_OK);
kono
parents:
diff changeset
462 FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->preds)
kono
parents:
diff changeset
463 {
kono
parents:
diff changeset
464 gcc_assert (!len_casted || TYPE_UNSIGNED (TREE_TYPE (len_casted)));
kono
parents:
diff changeset
465 ret = alloca_call_type_by_arg (len, len_casted, e, max_size);
kono
parents:
diff changeset
466 if (ret.type != ALLOCA_OK)
kono
parents:
diff changeset
467 break;
kono
parents:
diff changeset
468 }
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 if (ret.type != ALLOCA_OK && tentative_cast_from_signed)
kono
parents:
diff changeset
471 ret = alloca_type_and_limit (ALLOCA_CAST_FROM_SIGNED);
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 // If we have a declared maximum size, we can take it into account.
kono
parents:
diff changeset
474 if (ret.type != ALLOCA_OK
kono
parents:
diff changeset
475 && gimple_call_builtin_p (stmt, BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX))
kono
parents:
diff changeset
476 {
kono
parents:
diff changeset
477 tree arg = gimple_call_arg (stmt, 2);
kono
parents:
diff changeset
478 if (compare_tree_int (arg, max_size) <= 0)
kono
parents:
diff changeset
479 ret = alloca_type_and_limit (ALLOCA_OK);
kono
parents:
diff changeset
480 else
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
481 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
482 const offset_int maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
483 = wi::to_offset (max_object_size ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
484 alloca_type result = (max_size < maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
485 ? ALLOCA_BOUND_MAYBE_LARGE : ALLOCA_OK);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
486 ret = alloca_type_and_limit (result, wi::to_wide (arg));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
487 }
111
kono
parents:
diff changeset
488 }
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 return ret;
kono
parents:
diff changeset
491 }
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 // Return TRUE if STMT is in a loop, otherwise return FALSE.
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 static bool
kono
parents:
diff changeset
496 in_loop_p (gimple *stmt)
kono
parents:
diff changeset
497 {
kono
parents:
diff changeset
498 basic_block bb = gimple_bb (stmt);
kono
parents:
diff changeset
499 return
kono
parents:
diff changeset
500 bb->loop_father && bb->loop_father->header != ENTRY_BLOCK_PTR_FOR_FN (cfun);
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 unsigned int
kono
parents:
diff changeset
504 pass_walloca::execute (function *fun)
kono
parents:
diff changeset
505 {
kono
parents:
diff changeset
506 basic_block bb;
kono
parents:
diff changeset
507 FOR_EACH_BB_FN (bb, fun)
kono
parents:
diff changeset
508 {
kono
parents:
diff changeset
509 for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
kono
parents:
diff changeset
510 gsi_next (&si))
kono
parents:
diff changeset
511 {
kono
parents:
diff changeset
512 gimple *stmt = gsi_stmt (si);
kono
parents:
diff changeset
513 location_t loc = gimple_location (stmt);
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 if (!gimple_alloca_call_p (stmt))
kono
parents:
diff changeset
516 continue;
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 const bool is_vla
kono
parents:
diff changeset
519 = gimple_call_alloca_for_var_p (as_a <gcall *> (stmt));
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 // Strict mode whining for VLAs is handled by the front-end,
kono
parents:
diff changeset
522 // so we can safely ignore this case. Also, ignore VLAs if
kono
parents:
diff changeset
523 // the user doesn't care about them.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
524 if (is_vla)
111
kono
parents:
diff changeset
525 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
526 if (warn_vla > 0 || warn_vla_limit < 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
527 continue;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
528 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
529 else if (warn_alloca)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
530 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
531 warning_at (loc, OPT_Walloca, G_("use of %<alloca%>"));
111
kono
parents:
diff changeset
532 continue;
kono
parents:
diff changeset
533 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
534 else if (warn_alloca_limit < 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
535 continue;
111
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 tree invalid_casted_type = NULL;
kono
parents:
diff changeset
538 struct alloca_type_and_limit t
kono
parents:
diff changeset
539 = alloca_call_type (stmt, is_vla, &invalid_casted_type);
kono
parents:
diff changeset
540
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
541 unsigned HOST_WIDE_INT adjusted_alloca_limit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
542 = adjusted_warn_limit (false);
111
kono
parents:
diff changeset
543 // Even if we think the alloca call is OK, make sure it's not in a
kono
parents:
diff changeset
544 // loop, except for a VLA, since VLAs are guaranteed to be cleaned
kono
parents:
diff changeset
545 // up when they go out of scope, including in a loop.
kono
parents:
diff changeset
546 if (t.type == ALLOCA_OK && !is_vla && in_loop_p (stmt))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
547 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
548 /* As in other instances, only diagnose this when the limit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
549 is less than the maximum valid object size. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
550 const offset_int maxobjsize
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
551 = wi::to_offset (max_object_size ());
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
552 if (adjusted_alloca_limit < maxobjsize.to_uhwi ())
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
553 t = alloca_type_and_limit (ALLOCA_IN_LOOP);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
554 }
111
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 enum opt_code wcode
kono
parents:
diff changeset
557 = is_vla ? OPT_Wvla_larger_than_ : OPT_Walloca_larger_than_;
kono
parents:
diff changeset
558 char buff[WIDE_INT_MAX_PRECISION / 4 + 4];
kono
parents:
diff changeset
559 switch (t.type)
kono
parents:
diff changeset
560 {
kono
parents:
diff changeset
561 case ALLOCA_OK:
kono
parents:
diff changeset
562 break;
kono
parents:
diff changeset
563 case ALLOCA_BOUND_MAYBE_LARGE:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
564 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
565 auto_diagnostic_group d;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
566 if (warning_at (loc, wcode,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
567 is_vla ? G_("argument to variable-length "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
568 "array may be too large")
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
569 : G_("argument to %<alloca%> may be too "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
570 "large"))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
571 && t.limit != 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
572 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
573 print_decu (t.limit, buff);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
574 inform (loc, G_("limit is %wu bytes, but argument "
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
575 "may be as large as %s"),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
576 is_vla ? warn_vla_limit : adjusted_alloca_limit,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
577 buff);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
578 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
579 }
111
kono
parents:
diff changeset
580 break;
kono
parents:
diff changeset
581 case ALLOCA_BOUND_DEFINITELY_LARGE:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
582 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
583 auto_diagnostic_group d;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
584 if (warning_at (loc, wcode,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
585 is_vla ? G_("argument to variable-length"
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
586 " array is too large")
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
587 : G_("argument to %<alloca%> is too large"))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
588 && t.limit != 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
589 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
590 print_decu (t.limit, buff);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
591 inform (loc, G_("limit is %wu bytes, but argument is %s"),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
592 is_vla ? warn_vla_limit : adjusted_alloca_limit,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
593 buff);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
594 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
595 }
111
kono
parents:
diff changeset
596 break;
kono
parents:
diff changeset
597 case ALLOCA_BOUND_UNKNOWN:
kono
parents:
diff changeset
598 warning_at (loc, wcode,
kono
parents:
diff changeset
599 is_vla ? G_("variable-length array bound is unknown")
kono
parents:
diff changeset
600 : G_("%<alloca%> bound is unknown"));
kono
parents:
diff changeset
601 break;
kono
parents:
diff changeset
602 case ALLOCA_UNBOUNDED:
kono
parents:
diff changeset
603 warning_at (loc, wcode,
kono
parents:
diff changeset
604 is_vla ? G_("unbounded use of variable-length array")
kono
parents:
diff changeset
605 : G_("unbounded use of %<alloca%>"));
kono
parents:
diff changeset
606 break;
kono
parents:
diff changeset
607 case ALLOCA_IN_LOOP:
kono
parents:
diff changeset
608 gcc_assert (!is_vla);
kono
parents:
diff changeset
609 warning_at (loc, wcode, G_("use of %<alloca%> within a loop"));
kono
parents:
diff changeset
610 break;
kono
parents:
diff changeset
611 case ALLOCA_CAST_FROM_SIGNED:
kono
parents:
diff changeset
612 gcc_assert (invalid_casted_type != NULL_TREE);
kono
parents:
diff changeset
613 warning_at (loc, wcode,
kono
parents:
diff changeset
614 is_vla ? G_("argument to variable-length array "
kono
parents:
diff changeset
615 "may be too large due to "
kono
parents:
diff changeset
616 "conversion from %qT to %qT")
kono
parents:
diff changeset
617 : G_("argument to %<alloca%> may be too large "
kono
parents:
diff changeset
618 "due to conversion from %qT to %qT"),
kono
parents:
diff changeset
619 invalid_casted_type, size_type_node);
kono
parents:
diff changeset
620 break;
kono
parents:
diff changeset
621 case ALLOCA_ARG_IS_ZERO:
kono
parents:
diff changeset
622 warning_at (loc, wcode,
kono
parents:
diff changeset
623 is_vla ? G_("argument to variable-length array "
kono
parents:
diff changeset
624 "is zero")
kono
parents:
diff changeset
625 : G_("argument to %<alloca%> is zero"));
kono
parents:
diff changeset
626 break;
kono
parents:
diff changeset
627 default:
kono
parents:
diff changeset
628 gcc_unreachable ();
kono
parents:
diff changeset
629 }
kono
parents:
diff changeset
630 }
kono
parents:
diff changeset
631 }
kono
parents:
diff changeset
632 return 0;
kono
parents:
diff changeset
633 }
kono
parents:
diff changeset
634
kono
parents:
diff changeset
635 gimple_opt_pass *
kono
parents:
diff changeset
636 make_pass_walloca (gcc::context *ctxt)
kono
parents:
diff changeset
637 {
kono
parents:
diff changeset
638 return new pass_walloca (ctxt);
kono
parents:
diff changeset
639 }