Bug Summary

File:build/gcc/tree-vrp.c
Warning:line 1848, column 5
Value stored to 'cst2n' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name tree-vrp.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D IN_GCC -D HAVE_CONFIG_H -I . -I . -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/. -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcpp/include -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libcody -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libdecnumber/bid -I ../libdecnumber -I /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/../libbacktrace -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/x86_64-suse-linux -internal-isystem /usr/bin/../lib64/gcc/x86_64-suse-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-narrowing -Wwrite-strings -Wno-error=format-diag -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -fdeprecated-macro -fdebug-compilation-dir /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/gcc -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=plist-html -analyzer-config silence-checkers=core.NullDereference -faddrsig -o /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/objdir/clang-static-analyzer/2021-01-16-135054-17580-1/report-rse6nj.plist -x c++ /home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c
1/* Support routines for Value Range Propagation (VRP).
2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
3 Contributed by Diego Novillo <dnovillo@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#include "config.h"
22#include "system.h"
23#include "coretypes.h"
24#include "backend.h"
25#include "insn-codes.h"
26#include "rtl.h"
27#include "tree.h"
28#include "gimple.h"
29#include "cfghooks.h"
30#include "tree-pass.h"
31#include "ssa.h"
32#include "optabs-tree.h"
33#include "gimple-pretty-print.h"
34#include "flags.h"
35#include "fold-const.h"
36#include "stor-layout.h"
37#include "calls.h"
38#include "cfganal.h"
39#include "gimple-fold.h"
40#include "tree-eh.h"
41#include "gimple-iterator.h"
42#include "gimple-walk.h"
43#include "tree-cfg.h"
44#include "tree-ssa-loop-manip.h"
45#include "tree-ssa-loop-niter.h"
46#include "tree-ssa-loop.h"
47#include "tree-into-ssa.h"
48#include "tree-ssa.h"
49#include "cfgloop.h"
50#include "tree-scalar-evolution.h"
51#include "tree-ssa-propagate.h"
52#include "tree-chrec.h"
53#include "tree-ssa-threadupdate.h"
54#include "tree-ssa-scopedtables.h"
55#include "tree-ssa-threadedge.h"
56#include "omp-general.h"
57#include "target.h"
58#include "case-cfn-macros.h"
59#include "alloc-pool.h"
60#include "domwalk.h"
61#include "tree-cfgcleanup.h"
62#include "stringpool.h"
63#include "attribs.h"
64#include "vr-values.h"
65#include "builtins.h"
66#include "range-op.h"
67#include "value-range-equiv.h"
68#include "gimple-array-bounds.h"
69
70/* Set of SSA names found live during the RPO traversal of the function
71 for still active basic-blocks. */
72class live_names
73{
74public:
75 live_names ();
76 ~live_names ();
77 void set (tree, basic_block);
78 void clear (tree, basic_block);
79 void merge (basic_block dest, basic_block src);
80 bool live_on_block_p (tree, basic_block);
81 bool live_on_edge_p (tree, edge);
82 bool block_has_live_names_p (basic_block);
83 void clear_block (basic_block);
84
85private:
86 sbitmap *live;
87 unsigned num_blocks;
88 void init_bitmap_if_needed (basic_block);
89};
90
91void
92live_names::init_bitmap_if_needed (basic_block bb)
93{
94 unsigned i = bb->index;
95 if (!live[i])
96 {
97 live[i] = sbitmap_alloc (num_ssa_names(vec_safe_length ((cfun + 0)->gimple_df->ssa_names)));
98 bitmap_clear (live[i]);
99 }
100}
101
102bool
103live_names::block_has_live_names_p (basic_block bb)
104{
105 unsigned i = bb->index;
106 return live[i] && bitmap_empty_p (live[i]);
107}
108
109void
110live_names::clear_block (basic_block bb)
111{
112 unsigned i = bb->index;
113 if (live[i])
114 {
115 sbitmap_free (live[i]);
116 live[i] = NULLnullptr;
117 }
118}
119
120void
121live_names::merge (basic_block dest, basic_block src)
122{
123 init_bitmap_if_needed (dest);
124 init_bitmap_if_needed (src);
125 bitmap_ior (live[dest->index], live[dest->index], live[src->index]);
126}
127
128void
129live_names::set (tree name, basic_block bb)
130{
131 init_bitmap_if_needed (bb);
132 bitmap_set_bit (live[bb->index], SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 132, __FUNCTION__, (SSA_NAME)))->base.u.version
);
133}
134
135void
136live_names::clear (tree name, basic_block bb)
137{
138 unsigned i = bb->index;
139 if (live[i])
140 bitmap_clear_bit (live[i], SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 140, __FUNCTION__, (SSA_NAME)))->base.u.version
);
141}
142
143live_names::live_names ()
144{
145 num_blocks = last_basic_block_for_fn (cfun)(((cfun + 0))->cfg->x_last_basic_block);
146 live = XCNEWVEC (sbitmap, num_blocks)((sbitmap *) xcalloc ((num_blocks), sizeof (sbitmap)));
147}
148
149live_names::~live_names ()
150{
151 for (unsigned i = 0; i < num_blocks; ++i)
152 if (live[i])
153 sbitmap_free (live[i]);
154 XDELETEVEC (live)free ((void*) (live));
155}
156
157bool
158live_names::live_on_block_p (tree name, basic_block bb)
159{
160 return (live[bb->index]
161 && bitmap_bit_p (live[bb->index], SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 161, __FUNCTION__, (SSA_NAME)))->base.u.version
));
162}
163
164/* Return true if the SSA name NAME is live on the edge E. */
165
166bool
167live_names::live_on_edge_p (tree name, edge e)
168{
169 return live_on_block_p (name, e->dest);
170}
171
172
173/* VR_TYPE describes a range with mininum value *MIN and maximum
174 value *MAX. Restrict the range to the set of values that have
175 no bits set outside NONZERO_BITS. Update *MIN and *MAX and
176 return the new range type.
177
178 SGN gives the sign of the values described by the range. */
179
180enum value_range_kind
181intersect_range_with_nonzero_bits (enum value_range_kind vr_type,
182 wide_int *min, wide_int *max,
183 const wide_int &nonzero_bits,
184 signop sgn)
185{
186 if (vr_type == VR_ANTI_RANGE)
187 {
188 /* The VR_ANTI_RANGE is equivalent to the union of the ranges
189 A: [-INF, *MIN) and B: (*MAX, +INF]. First use NONZERO_BITS
190 to create an inclusive upper bound for A and an inclusive lower
191 bound for B. */
192 wide_int a_max = wi::round_down_for_mask (*min - 1, nonzero_bits);
193 wide_int b_min = wi::round_up_for_mask (*max + 1, nonzero_bits);
194
195 /* If the calculation of A_MAX wrapped, A is effectively empty
196 and A_MAX is the highest value that satisfies NONZERO_BITS.
197 Likewise if the calculation of B_MIN wrapped, B is effectively
198 empty and B_MIN is the lowest value that satisfies NONZERO_BITS. */
199 bool a_empty = wi::ge_p (a_max, *min, sgn);
200 bool b_empty = wi::le_p (b_min, *max, sgn);
201
202 /* If both A and B are empty, there are no valid values. */
203 if (a_empty && b_empty)
204 return VR_UNDEFINED;
205
206 /* If exactly one of A or B is empty, return a VR_RANGE for the
207 other one. */
208 if (a_empty || b_empty)
209 {
210 *min = b_min;
211 *max = a_max;
212 gcc_checking_assert (wi::le_p (*min, *max, sgn))((void)(!(wi::le_p (*min, *max, sgn)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 212, __FUNCTION__), 0 : 0))
;
213 return VR_RANGE;
214 }
215
216 /* Update the VR_ANTI_RANGE bounds. */
217 *min = a_max + 1;
218 *max = b_min - 1;
219 gcc_checking_assert (wi::le_p (*min, *max, sgn))((void)(!(wi::le_p (*min, *max, sgn)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 219, __FUNCTION__), 0 : 0))
;
220
221 /* Now check whether the excluded range includes any values that
222 satisfy NONZERO_BITS. If not, switch to a full VR_RANGE. */
223 if (wi::round_up_for_mask (*min, nonzero_bits) == b_min)
224 {
225 unsigned int precision = min->get_precision ();
226 *min = wi::min_value (precision, sgn);
227 *max = wi::max_value (precision, sgn);
228 vr_type = VR_RANGE;
229 }
230 }
231 if (vr_type == VR_RANGE)
232 {
233 *max = wi::round_down_for_mask (*max, nonzero_bits);
234
235 /* Check that the range contains at least one valid value. */
236 if (wi::gt_p (*min, *max, sgn))
237 return VR_UNDEFINED;
238
239 *min = wi::round_up_for_mask (*min, nonzero_bits);
240 gcc_checking_assert (wi::le_p (*min, *max, sgn))((void)(!(wi::le_p (*min, *max, sgn)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 240, __FUNCTION__), 0 : 0))
;
241 }
242 return vr_type;
243}
244
245/* Return true if max and min of VR are INTEGER_CST. It's not necessary
246 a singleton. */
247
248bool
249range_int_cst_p (const value_range *vr)
250{
251 return (vr->kind () == VR_RANGE && range_has_numeric_bounds_p (vr));
252}
253
254/* Return the single symbol (an SSA_NAME) contained in T if any, or NULL_TREE
255 otherwise. We only handle additive operations and set NEG to true if the
256 symbol is negated and INV to the invariant part, if any. */
257
258tree
259get_single_symbol (tree t, bool *neg, tree *inv)
260{
261 bool neg_;
262 tree inv_;
263
264 *inv = NULL_TREE(tree) nullptr;
265 *neg = false;
266
267 if (TREE_CODE (t)((enum tree_code) (t)->base.code) == PLUS_EXPR
268 || TREE_CODE (t)((enum tree_code) (t)->base.code) == POINTER_PLUS_EXPR
269 || TREE_CODE (t)((enum tree_code) (t)->base.code) == MINUS_EXPR)
270 {
271 if (is_gimple_min_invariant (TREE_OPERAND (t, 0)(*((const_cast<tree*> (tree_operand_check ((t), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 271, __FUNCTION__)))))
))
272 {
273 neg_ = (TREE_CODE (t)((enum tree_code) (t)->base.code) == MINUS_EXPR);
274 inv_ = TREE_OPERAND (t, 0)(*((const_cast<tree*> (tree_operand_check ((t), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 274, __FUNCTION__)))))
;
275 t = TREE_OPERAND (t, 1)(*((const_cast<tree*> (tree_operand_check ((t), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 275, __FUNCTION__)))))
;
276 }
277 else if (is_gimple_min_invariant (TREE_OPERAND (t, 1)(*((const_cast<tree*> (tree_operand_check ((t), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 277, __FUNCTION__)))))
))
278 {
279 neg_ = false;
280 inv_ = TREE_OPERAND (t, 1)(*((const_cast<tree*> (tree_operand_check ((t), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 280, __FUNCTION__)))))
;
281 t = TREE_OPERAND (t, 0)(*((const_cast<tree*> (tree_operand_check ((t), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 281, __FUNCTION__)))))
;
282 }
283 else
284 return NULL_TREE(tree) nullptr;
285 }
286 else
287 {
288 neg_ = false;
289 inv_ = NULL_TREE(tree) nullptr;
290 }
291
292 if (TREE_CODE (t)((enum tree_code) (t)->base.code) == NEGATE_EXPR)
293 {
294 t = TREE_OPERAND (t, 0)(*((const_cast<tree*> (tree_operand_check ((t), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 294, __FUNCTION__)))))
;
295 neg_ = !neg_;
296 }
297
298 if (TREE_CODE (t)((enum tree_code) (t)->base.code) != SSA_NAME)
299 return NULL_TREE(tree) nullptr;
300
301 if (inv_ && TREE_OVERFLOW_P (inv_)((tree_code_type[(int) (((enum tree_code) (inv_)->base.code
))] == tcc_constant) && ((tree_class_check ((inv_), (
tcc_constant), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 301, __FUNCTION__))->base.public_flag))
)
302 inv_ = drop_tree_overflow (inv_);
303
304 *neg = neg_;
305 *inv = inv_;
306 return t;
307}
308
309/* The reverse operation: build a symbolic expression with TYPE
310 from symbol SYM, negated according to NEG, and invariant INV. */
311
312static tree
313build_symbolic_expr (tree type, tree sym, bool neg, tree inv)
314{
315 const bool pointer_p = POINTER_TYPE_P (type)(((enum tree_code) (type)->base.code) == POINTER_TYPE || (
(enum tree_code) (type)->base.code) == REFERENCE_TYPE)
;
316 tree t = sym;
317
318 if (neg)
319 t = build1 (NEGATE_EXPR, type, t);
320
321 if (integer_zerop (inv))
322 return t;
323
324 return build2 (pointer_p ? POINTER_PLUS_EXPR : PLUS_EXPR, type, t, inv);
325}
326
327/* Return
328 1 if VAL < VAL2
329 0 if !(VAL < VAL2)
330 -2 if those are incomparable. */
331int
332operand_less_p (tree val, tree val2)
333{
334 /* LT is folded faster than GE and others. Inline the common case. */
335 if (TREE_CODE (val)((enum tree_code) (val)->base.code) == INTEGER_CST && TREE_CODE (val2)((enum tree_code) (val2)->base.code) == INTEGER_CST)
336 return tree_int_cst_lt (val, val2);
337 else if (TREE_CODE (val)((enum tree_code) (val)->base.code) == SSA_NAME && TREE_CODE (val2)((enum tree_code) (val2)->base.code) == SSA_NAME)
338 return val == val2 ? 0 : -2;
339 else
340 {
341 int cmp = compare_values (val, val2);
342 if (cmp == -1)
343 return 1;
344 else if (cmp == 0 || cmp == 1)
345 return 0;
346 else
347 return -2;
348 }
349
350 return 0;
351}
352
353/* Compare two values VAL1 and VAL2. Return
354
355 -2 if VAL1 and VAL2 cannot be compared at compile-time,
356 -1 if VAL1 < VAL2,
357 0 if VAL1 == VAL2,
358 +1 if VAL1 > VAL2, and
359 +2 if VAL1 != VAL2
360
361 This is similar to tree_int_cst_compare but supports pointer values
362 and values that cannot be compared at compile time.
363
364 If STRICT_OVERFLOW_P is not NULL, then set *STRICT_OVERFLOW_P to
365 true if the return value is only valid if we assume that signed
366 overflow is undefined. */
367
368int
369compare_values_warnv (tree val1, tree val2, bool *strict_overflow_p)
370{
371 if (val1 == val2)
372 return 0;
373
374 /* Below we rely on the fact that VAL1 and VAL2 are both pointers or
375 both integers. */
376 gcc_assert (POINTER_TYPE_P (TREE_TYPE (val1))((void)(!((((enum tree_code) (((contains_struct_check ((val1)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 376, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 376, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
) == (((enum tree_code) (((contains_struct_check ((val2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 377, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 377, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 377, __FUNCTION__), 0 : 0))
377 == POINTER_TYPE_P (TREE_TYPE (val2)))((void)(!((((enum tree_code) (((contains_struct_check ((val1)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 376, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 376, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
) == (((enum tree_code) (((contains_struct_check ((val2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 377, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 377, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 377, __FUNCTION__), 0 : 0))
;
378
379 /* Convert the two values into the same type. This is needed because
380 sizetype causes sign extension even for unsigned types. */
381 if (!useless_type_conversion_p (TREE_TYPE (val1)((contains_struct_check ((val1), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 381, __FUNCTION__))->typed.type)
, TREE_TYPE (val2)((contains_struct_check ((val2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 381, __FUNCTION__))->typed.type)
))
382 val2 = fold_convert (TREE_TYPE (val1), val2)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(val1), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 382, __FUNCTION__))->typed.type), val2)
;
383
384 const bool overflow_undefined
385 = INTEGRAL_TYPE_P (TREE_TYPE (val1))(((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 385, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 385, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 385, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
386 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (val1))((((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 386, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 386, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
) ? !global_options.x_flag_wrapv_pointer : (!(any_integral_type_check
((((contains_struct_check ((val1), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 386, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 386, __FUNCTION__))->base.u.bits.unsigned_flag &&
!global_options.x_flag_wrapv && !global_options.x_flag_trapv
))
;
387 tree inv1, inv2;
388 bool neg1, neg2;
389 tree sym1 = get_single_symbol (val1, &neg1, &inv1);
390 tree sym2 = get_single_symbol (val2, &neg2, &inv2);
391
392 /* If VAL1 and VAL2 are of the form '[-]NAME [+ CST]', return -1 or +1
393 accordingly. If VAL1 and VAL2 don't use the same name, return -2. */
394 if (sym1 && sym2)
395 {
396 /* Both values must use the same name with the same sign. */
397 if (sym1 != sym2 || neg1 != neg2)
398 return -2;
399
400 /* [-]NAME + CST == [-]NAME + CST. */
401 if (inv1 == inv2)
402 return 0;
403
404 /* If overflow is defined we cannot simplify more. */
405 if (!overflow_undefined)
406 return -2;
407
408 if (strict_overflow_p != NULLnullptr
409 /* Symbolic range building sets TREE_NO_WARNING to declare
410 that overflow doesn't happen. */
411 && (!inv1 || !TREE_NO_WARNING (val1)((val1)->base.nowarning_flag))
412 && (!inv2 || !TREE_NO_WARNING (val2)((val2)->base.nowarning_flag)))
413 *strict_overflow_p = true;
414
415 if (!inv1)
416 inv1 = build_int_cst (TREE_TYPE (val1)((contains_struct_check ((val1), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 416, __FUNCTION__))->typed.type)
, 0);
417 if (!inv2)
418 inv2 = build_int_cst (TREE_TYPE (val2)((contains_struct_check ((val2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 418, __FUNCTION__))->typed.type)
, 0);
419
420 return wi::cmp (wi::to_wide (inv1), wi::to_wide (inv2),
421 TYPE_SIGN (TREE_TYPE (val1))((signop) ((tree_class_check ((((contains_struct_check ((val1
), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 421, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 421, __FUNCTION__))->base.u.bits.unsigned_flag))
);
422 }
423
424 const bool cst1 = is_gimple_min_invariant (val1);
425 const bool cst2 = is_gimple_min_invariant (val2);
426
427 /* If one is of the form '[-]NAME + CST' and the other is constant, then
428 it might be possible to say something depending on the constants. */
429 if ((sym1 && inv1 && cst2) || (sym2 && inv2 && cst1))
430 {
431 if (!overflow_undefined)
432 return -2;
433
434 if (strict_overflow_p != NULLnullptr
435 /* Symbolic range building sets TREE_NO_WARNING to declare
436 that overflow doesn't happen. */
437 && (!sym1 || !TREE_NO_WARNING (val1)((val1)->base.nowarning_flag))
438 && (!sym2 || !TREE_NO_WARNING (val2)((val2)->base.nowarning_flag)))
439 *strict_overflow_p = true;
440
441 const signop sgn = TYPE_SIGN (TREE_TYPE (val1))((signop) ((tree_class_check ((((contains_struct_check ((val1
), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 441, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 441, __FUNCTION__))->base.u.bits.unsigned_flag))
;
442 tree cst = cst1 ? val1 : val2;
443 tree inv = cst1 ? inv2 : inv1;
444
445 /* Compute the difference between the constants. If it overflows or
446 underflows, this means that we can trivially compare the NAME with
447 it and, consequently, the two values with each other. */
448 wide_int diff = wi::to_wide (cst) - wi::to_wide (inv);
449 if (wi::cmp (0, wi::to_wide (inv), sgn)
450 != wi::cmp (diff, wi::to_wide (cst), sgn))
451 {
452 const int res = wi::cmp (wi::to_wide (cst), wi::to_wide (inv), sgn);
453 return cst1 ? res : -res;
454 }
455
456 return -2;
457 }
458
459 /* We cannot say anything more for non-constants. */
460 if (!cst1 || !cst2)
461 return -2;
462
463 if (!POINTER_TYPE_P (TREE_TYPE (val1))(((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 463, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 463, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
)
464 {
465 /* We cannot compare overflowed values. */
466 if (TREE_OVERFLOW (val1)((tree_class_check ((val1), (tcc_constant), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 466, __FUNCTION__))->base.public_flag)
|| TREE_OVERFLOW (val2)((tree_class_check ((val2), (tcc_constant), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 466, __FUNCTION__))->base.public_flag)
)
467 return -2;
468
469 if (TREE_CODE (val1)((enum tree_code) (val1)->base.code) == INTEGER_CST
470 && TREE_CODE (val2)((enum tree_code) (val2)->base.code) == INTEGER_CST)
471 return tree_int_cst_compare (val1, val2);
472
473 if (poly_int_tree_p (val1) && poly_int_tree_p (val2))
474 {
475 if (known_eq (wi::to_poly_widest (val1),(!maybe_ne (wi::to_poly_widest (val1), wi::to_poly_widest (val2
)))
476 wi::to_poly_widest (val2))(!maybe_ne (wi::to_poly_widest (val1), wi::to_poly_widest (val2
)))
)
477 return 0;
478 if (known_lt (wi::to_poly_widest (val1),(!maybe_le (wi::to_poly_widest (val2), wi::to_poly_widest (val1
)))
479 wi::to_poly_widest (val2))(!maybe_le (wi::to_poly_widest (val2), wi::to_poly_widest (val1
)))
)
480 return -1;
481 if (known_gt (wi::to_poly_widest (val1),(!maybe_le (wi::to_poly_widest (val1), wi::to_poly_widest (val2
)))
482 wi::to_poly_widest (val2))(!maybe_le (wi::to_poly_widest (val1), wi::to_poly_widest (val2
)))
)
483 return 1;
484 }
485
486 return -2;
487 }
488 else
489 {
490 if (TREE_CODE (val1)((enum tree_code) (val1)->base.code) == INTEGER_CST && TREE_CODE (val2)((enum tree_code) (val2)->base.code) == INTEGER_CST)
491 {
492 /* We cannot compare overflowed values. */
493 if (TREE_OVERFLOW (val1)((tree_class_check ((val1), (tcc_constant), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 493, __FUNCTION__))->base.public_flag)
|| TREE_OVERFLOW (val2)((tree_class_check ((val2), (tcc_constant), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 493, __FUNCTION__))->base.public_flag)
)
494 return -2;
495
496 return tree_int_cst_compare (val1, val2);
497 }
498
499 /* First see if VAL1 and VAL2 are not the same. */
500 if (operand_equal_p (val1, val2, 0))
501 return 0;
502
503 fold_defer_overflow_warnings ();
504
505 /* If VAL1 is a lower address than VAL2, return -1. */
506 tree t = fold_binary_to_constant (LT_EXPR, boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], val1, val2);
507 if (t && integer_onep (t))
508 {
509 fold_undefer_and_ignore_overflow_warnings ();
510 return -1;
511 }
512
513 /* If VAL1 is a higher address than VAL2, return +1. */
514 t = fold_binary_to_constant (LT_EXPR, boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], val2, val1);
515 if (t && integer_onep (t))
516 {
517 fold_undefer_and_ignore_overflow_warnings ();
518 return 1;
519 }
520
521 /* If VAL1 is different than VAL2, return +2. */
522 t = fold_binary_to_constant (NE_EXPR, boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], val1, val2);
523 fold_undefer_and_ignore_overflow_warnings ();
524 if (t && integer_onep (t))
525 return 2;
526
527 return -2;
528 }
529}
530
531/* Compare values like compare_values_warnv. */
532
533int
534compare_values (tree val1, tree val2)
535{
536 bool sop;
537 return compare_values_warnv (val1, val2, &sop);
538}
539
540/* If BOUND will include a symbolic bound, adjust it accordingly,
541 otherwise leave it as is.
542
543 CODE is the original operation that combined the bounds (PLUS_EXPR
544 or MINUS_EXPR).
545
546 TYPE is the type of the original operation.
547
548 SYM_OPn is the symbolic for OPn if it has a symbolic.
549
550 NEG_OPn is TRUE if the OPn was negated. */
551
552static void
553adjust_symbolic_bound (tree &bound, enum tree_code code, tree type,
554 tree sym_op0, tree sym_op1,
555 bool neg_op0, bool neg_op1)
556{
557 bool minus_p = (code == MINUS_EXPR);
558 /* If the result bound is constant, we're done; otherwise, build the
559 symbolic lower bound. */
560 if (sym_op0 == sym_op1)
561 ;
562 else if (sym_op0)
563 bound = build_symbolic_expr (type, sym_op0,
564 neg_op0, bound);
565 else if (sym_op1)
566 {
567 /* We may not negate if that might introduce
568 undefined overflow. */
569 if (!minus_p
570 || neg_op1
571 || TYPE_OVERFLOW_WRAPS (type)((((enum tree_code) (type)->base.code) == POINTER_TYPE || (
(enum tree_code) (type)->base.code) == REFERENCE_TYPE) ? global_options
.x_flag_wrapv_pointer : ((any_integral_type_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 571, __FUNCTION__))->base.u.bits.unsigned_flag || global_options
.x_flag_wrapv))
)
572 bound = build_symbolic_expr (type, sym_op1,
573 neg_op1 ^ minus_p, bound);
574 else
575 bound = NULL_TREE(tree) nullptr;
576 }
577}
578
579/* Combine OP1 and OP1, which are two parts of a bound, into one wide
580 int bound according to CODE. CODE is the operation combining the
581 bound (either a PLUS_EXPR or a MINUS_EXPR).
582
583 TYPE is the type of the combine operation.
584
585 WI is the wide int to store the result.
586
587 OVF is -1 if an underflow occurred, +1 if an overflow occurred or 0
588 if over/underflow occurred. */
589
590static void
591combine_bound (enum tree_code code, wide_int &wi, wi::overflow_type &ovf,
592 tree type, tree op0, tree op1)
593{
594 bool minus_p = (code == MINUS_EXPR);
595 const signop sgn = TYPE_SIGN (type)((signop) ((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 595, __FUNCTION__))->base.u.bits.unsigned_flag))
;
596 const unsigned int prec = TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 596, __FUNCTION__))->type_common.precision)
;
597
598 /* Combine the bounds, if any. */
599 if (op0 && op1)
600 {
601 if (minus_p)
602 wi = wi::sub (wi::to_wide (op0), wi::to_wide (op1), sgn, &ovf);
603 else
604 wi = wi::add (wi::to_wide (op0), wi::to_wide (op1), sgn, &ovf);
605 }
606 else if (op0)
607 wi = wi::to_wide (op0);
608 else if (op1)
609 {
610 if (minus_p)
611 wi = wi::neg (wi::to_wide (op1), &ovf);
612 else
613 wi = wi::to_wide (op1);
614 }
615 else
616 wi = wi::shwi (0, prec);
617}
618
619/* Given a range in [WMIN, WMAX], adjust it for possible overflow and
620 put the result in VR.
621
622 TYPE is the type of the range.
623
624 MIN_OVF and MAX_OVF indicate what type of overflow, if any,
625 occurred while originally calculating WMIN or WMAX. -1 indicates
626 underflow. +1 indicates overflow. 0 indicates neither. */
627
628static void
629set_value_range_with_overflow (value_range_kind &kind, tree &min, tree &max,
630 tree type,
631 const wide_int &wmin, const wide_int &wmax,
632 wi::overflow_type min_ovf,
633 wi::overflow_type max_ovf)
634{
635 const signop sgn = TYPE_SIGN (type)((signop) ((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 635, __FUNCTION__))->base.u.bits.unsigned_flag))
;
636 const unsigned int prec = TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 636, __FUNCTION__))->type_common.precision)
;
637
638 /* For one bit precision if max < min, then the swapped
639 range covers all values. */
640 if (prec == 1 && wi::lt_p (wmax, wmin, sgn))
641 {
642 kind = VR_VARYING;
643 return;
644 }
645
646 if (TYPE_OVERFLOW_WRAPS (type)((((enum tree_code) (type)->base.code) == POINTER_TYPE || (
(enum tree_code) (type)->base.code) == REFERENCE_TYPE) ? global_options
.x_flag_wrapv_pointer : ((any_integral_type_check ((type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 646, __FUNCTION__))->base.u.bits.unsigned_flag || global_options
.x_flag_wrapv))
)
647 {
648 /* If overflow wraps, truncate the values and adjust the
649 range kind and bounds appropriately. */
650 wide_int tmin = wide_int::from (wmin, prec, sgn);
651 wide_int tmax = wide_int::from (wmax, prec, sgn);
652 if ((min_ovf != wi::OVF_NONE) == (max_ovf != wi::OVF_NONE))
653 {
654 /* If the limits are swapped, we wrapped around and cover
655 the entire range. */
656 if (wi::gt_p (tmin, tmax, sgn))
657 kind = VR_VARYING;
658 else
659 {
660 kind = VR_RANGE;
661 /* No overflow or both overflow or underflow. The
662 range kind stays VR_RANGE. */
663 min = wide_int_to_tree (type, tmin);
664 max = wide_int_to_tree (type, tmax);
665 }
666 return;
667 }
668 else if ((min_ovf == wi::OVF_UNDERFLOW && max_ovf == wi::OVF_NONE)
669 || (max_ovf == wi::OVF_OVERFLOW && min_ovf == wi::OVF_NONE))
670 {
671 /* Min underflow or max overflow. The range kind
672 changes to VR_ANTI_RANGE. */
673 bool covers = false;
674 wide_int tem = tmin;
675 tmin = tmax + 1;
676 if (wi::cmp (tmin, tmax, sgn) < 0)
677 covers = true;
678 tmax = tem - 1;
679 if (wi::cmp (tmax, tem, sgn) > 0)
680 covers = true;
681 /* If the anti-range would cover nothing, drop to varying.
682 Likewise if the anti-range bounds are outside of the
683 types values. */
684 if (covers || wi::cmp (tmin, tmax, sgn) > 0)
685 {
686 kind = VR_VARYING;
687 return;
688 }
689 kind = VR_ANTI_RANGE;
690 min = wide_int_to_tree (type, tmin);
691 max = wide_int_to_tree (type, tmax);
692 return;
693 }
694 else
695 {
696 /* Other underflow and/or overflow, drop to VR_VARYING. */
697 kind = VR_VARYING;
698 return;
699 }
700 }
701 else
702 {
703 /* If overflow does not wrap, saturate to the types min/max
704 value. */
705 wide_int type_min = wi::min_value (prec, sgn);
706 wide_int type_max = wi::max_value (prec, sgn);
707 kind = VR_RANGE;
708 if (min_ovf == wi::OVF_UNDERFLOW)
709 min = wide_int_to_tree (type, type_min);
710 else if (min_ovf == wi::OVF_OVERFLOW)
711 min = wide_int_to_tree (type, type_max);
712 else
713 min = wide_int_to_tree (type, wmin);
714
715 if (max_ovf == wi::OVF_UNDERFLOW)
716 max = wide_int_to_tree (type, type_min);
717 else if (max_ovf == wi::OVF_OVERFLOW)
718 max = wide_int_to_tree (type, type_max);
719 else
720 max = wide_int_to_tree (type, wmax);
721 }
722}
723
724/* Fold two value range's of a POINTER_PLUS_EXPR into VR. */
725
726static void
727extract_range_from_pointer_plus_expr (value_range *vr,
728 enum tree_code code,
729 tree expr_type,
730 const value_range *vr0,
731 const value_range *vr1)
732{
733 gcc_checking_assert (POINTER_TYPE_P (expr_type)((void)(!((((enum tree_code) (expr_type)->base.code) == POINTER_TYPE
|| ((enum tree_code) (expr_type)->base.code) == REFERENCE_TYPE
) && code == POINTER_PLUS_EXPR) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 734, __FUNCTION__), 0 : 0))
734 && code == POINTER_PLUS_EXPR)((void)(!((((enum tree_code) (expr_type)->base.code) == POINTER_TYPE
|| ((enum tree_code) (expr_type)->base.code) == REFERENCE_TYPE
) && code == POINTER_PLUS_EXPR) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 734, __FUNCTION__), 0 : 0))
;
735 /* For pointer types, we are really only interested in asserting
736 whether the expression evaluates to non-NULL.
737 With -fno-delete-null-pointer-checks we need to be more
738 conservative. As some object might reside at address 0,
739 then some offset could be added to it and the same offset
740 subtracted again and the result would be NULL.
741 E.g.
742 static int a[12]; where &a[0] is NULL and
743 ptr = &a[6];
744 ptr -= 6;
745 ptr will be NULL here, even when there is POINTER_PLUS_EXPR
746 where the first range doesn't include zero and the second one
747 doesn't either. As the second operand is sizetype (unsigned),
748 consider all ranges where the MSB could be set as possible
749 subtractions where the result might be NULL. */
750 if ((!range_includes_zero_p (vr0)
751 || !range_includes_zero_p (vr1))
752 && !TYPE_OVERFLOW_WRAPS (expr_type)((((enum tree_code) (expr_type)->base.code) == POINTER_TYPE
|| ((enum tree_code) (expr_type)->base.code) == REFERENCE_TYPE
) ? global_options.x_flag_wrapv_pointer : ((any_integral_type_check
((expr_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 752, __FUNCTION__))->base.u.bits.unsigned_flag || global_options
.x_flag_wrapv))
753 && (flag_delete_null_pointer_checksglobal_options.x_flag_delete_null_pointer_checks
754 || (range_int_cst_p (vr1)
755 && !tree_int_cst_sign_bit (vr1->max ()))))
756 vr->set_nonzero (expr_type);
757 else if (vr0->zero_p () && vr1->zero_p ())
758 vr->set_zero (expr_type);
759 else
760 vr->set_varying (expr_type);
761}
762
763/* Extract range information from a PLUS/MINUS_EXPR and store the
764 result in *VR. */
765
766static void
767extract_range_from_plus_minus_expr (value_range *vr,
768 enum tree_code code,
769 tree expr_type,
770 const value_range *vr0_,
771 const value_range *vr1_)
772{
773 gcc_checking_assert (code == PLUS_EXPR || code == MINUS_EXPR)((void)(!(code == PLUS_EXPR || code == MINUS_EXPR) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 773, __FUNCTION__), 0 : 0))
;
774
775 value_range vr0 = *vr0_, vr1 = *vr1_;
776 value_range vrtem0, vrtem1;
777
778 /* Now canonicalize anti-ranges to ranges when they are not symbolic
779 and express ~[] op X as ([]' op X) U ([]'' op X). */
780 if (vr0.kind () == VR_ANTI_RANGE
781 && ranges_from_anti_range (&vr0, &vrtem0, &vrtem1))
782 {
783 extract_range_from_plus_minus_expr (vr, code, expr_type, &vrtem0, vr1_);
784 if (!vrtem1.undefined_p ())
785 {
786 value_range vrres;
787 extract_range_from_plus_minus_expr (&vrres, code, expr_type,
788 &vrtem1, vr1_);
789 vr->union_ (&vrres);
790 }
791 return;
792 }
793 /* Likewise for X op ~[]. */
794 if (vr1.kind () == VR_ANTI_RANGE
795 && ranges_from_anti_range (&vr1, &vrtem0, &vrtem1))
796 {
797 extract_range_from_plus_minus_expr (vr, code, expr_type, vr0_, &vrtem0);
798 if (!vrtem1.undefined_p ())
799 {
800 value_range vrres;
801 extract_range_from_plus_minus_expr (&vrres, code, expr_type,
802 vr0_, &vrtem1);
803 vr->union_ (&vrres);
804 }
805 return;
806 }
807
808 value_range_kind kind;
809 value_range_kind vr0_kind = vr0.kind (), vr1_kind = vr1.kind ();
810 tree vr0_min = vr0.min (), vr0_max = vr0.max ();
811 tree vr1_min = vr1.min (), vr1_max = vr1.max ();
812 tree min = NULL_TREE(tree) nullptr, max = NULL_TREE(tree) nullptr;
813
814 /* This will normalize things such that calculating
815 [0,0] - VR_VARYING is not dropped to varying, but is
816 calculated as [MIN+1, MAX]. */
817 if (vr0.varying_p ())
818 {
819 vr0_kind = VR_RANGE;
820 vr0_min = vrp_val_min (expr_type);
821 vr0_max = vrp_val_max (expr_type);
822 }
823 if (vr1.varying_p ())
824 {
825 vr1_kind = VR_RANGE;
826 vr1_min = vrp_val_min (expr_type);
827 vr1_max = vrp_val_max (expr_type);
828 }
829
830 const bool minus_p = (code == MINUS_EXPR);
831 tree min_op0 = vr0_min;
832 tree min_op1 = minus_p ? vr1_max : vr1_min;
833 tree max_op0 = vr0_max;
834 tree max_op1 = minus_p ? vr1_min : vr1_max;
835 tree sym_min_op0 = NULL_TREE(tree) nullptr;
836 tree sym_min_op1 = NULL_TREE(tree) nullptr;
837 tree sym_max_op0 = NULL_TREE(tree) nullptr;
838 tree sym_max_op1 = NULL_TREE(tree) nullptr;
839 bool neg_min_op0, neg_min_op1, neg_max_op0, neg_max_op1;
840
841 neg_min_op0 = neg_min_op1 = neg_max_op0 = neg_max_op1 = false;
842
843 /* If we have a PLUS or MINUS with two VR_RANGEs, either constant or
844 single-symbolic ranges, try to compute the precise resulting range,
845 but only if we know that this resulting range will also be constant
846 or single-symbolic. */
847 if (vr0_kind == VR_RANGE && vr1_kind == VR_RANGE
848 && (TREE_CODE (min_op0)((enum tree_code) (min_op0)->base.code) == INTEGER_CST
849 || (sym_min_op0
850 = get_single_symbol (min_op0, &neg_min_op0, &min_op0)))
851 && (TREE_CODE (min_op1)((enum tree_code) (min_op1)->base.code) == INTEGER_CST
852 || (sym_min_op1
853 = get_single_symbol (min_op1, &neg_min_op1, &min_op1)))
854 && (!(sym_min_op0 && sym_min_op1)
855 || (sym_min_op0 == sym_min_op1
856 && neg_min_op0 == (minus_p ? neg_min_op1 : !neg_min_op1)))
857 && (TREE_CODE (max_op0)((enum tree_code) (max_op0)->base.code) == INTEGER_CST
858 || (sym_max_op0
859 = get_single_symbol (max_op0, &neg_max_op0, &max_op0)))
860 && (TREE_CODE (max_op1)((enum tree_code) (max_op1)->base.code) == INTEGER_CST
861 || (sym_max_op1
862 = get_single_symbol (max_op1, &neg_max_op1, &max_op1)))
863 && (!(sym_max_op0 && sym_max_op1)
864 || (sym_max_op0 == sym_max_op1
865 && neg_max_op0 == (minus_p ? neg_max_op1 : !neg_max_op1))))
866 {
867 wide_int wmin, wmax;
868 wi::overflow_type min_ovf = wi::OVF_NONE;
869 wi::overflow_type max_ovf = wi::OVF_NONE;
870
871 /* Build the bounds. */
872 combine_bound (code, wmin, min_ovf, expr_type, min_op0, min_op1);
873 combine_bound (code, wmax, max_ovf, expr_type, max_op0, max_op1);
874
875 /* If the resulting range will be symbolic, we need to eliminate any
876 explicit or implicit overflow introduced in the above computation
877 because compare_values could make an incorrect use of it. That's
878 why we require one of the ranges to be a singleton. */
879 if ((sym_min_op0 != sym_min_op1 || sym_max_op0 != sym_max_op1)
880 && ((bool)min_ovf || (bool)max_ovf
881 || (min_op0 != max_op0 && min_op1 != max_op1)))
882 {
883 vr->set_varying (expr_type);
884 return;
885 }
886
887 /* Adjust the range for possible overflow. */
888 set_value_range_with_overflow (kind, min, max, expr_type,
889 wmin, wmax, min_ovf, max_ovf);
890 if (kind == VR_VARYING)
891 {
892 vr->set_varying (expr_type);
893 return;
894 }
895
896 /* Build the symbolic bounds if needed. */
897 adjust_symbolic_bound (min, code, expr_type,
898 sym_min_op0, sym_min_op1,
899 neg_min_op0, neg_min_op1);
900 adjust_symbolic_bound (max, code, expr_type,
901 sym_max_op0, sym_max_op1,
902 neg_max_op0, neg_max_op1);
903 }
904 else
905 {
906 /* For other cases, for example if we have a PLUS_EXPR with two
907 VR_ANTI_RANGEs, drop to VR_VARYING. It would take more effort
908 to compute a precise range for such a case.
909 ??? General even mixed range kind operations can be expressed
910 by for example transforming ~[3, 5] + [1, 2] to range-only
911 operations and a union primitive:
912 [-INF, 2] + [1, 2] U [5, +INF] + [1, 2]
913 [-INF+1, 4] U [6, +INF(OVF)]
914 though usually the union is not exactly representable with
915 a single range or anti-range as the above is
916 [-INF+1, +INF(OVF)] intersected with ~[5, 5]
917 but one could use a scheme similar to equivalences for this. */
918 vr->set_varying (expr_type);
919 return;
920 }
921
922 /* If either MIN or MAX overflowed, then set the resulting range to
923 VARYING. */
924 if (min == NULL_TREE(tree) nullptr
925 || TREE_OVERFLOW_P (min)((tree_code_type[(int) (((enum tree_code) (min)->base.code
))] == tcc_constant) && ((tree_class_check ((min), (tcc_constant
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 925, __FUNCTION__))->base.public_flag))
926 || max == NULL_TREE(tree) nullptr
927 || TREE_OVERFLOW_P (max)((tree_code_type[(int) (((enum tree_code) (max)->base.code
))] == tcc_constant) && ((tree_class_check ((max), (tcc_constant
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 927, __FUNCTION__))->base.public_flag))
)
928 {
929 vr->set_varying (expr_type);
930 return;
931 }
932
933 int cmp = compare_values (min, max);
934 if (cmp == -2 || cmp == 1)
935 {
936 /* If the new range has its limits swapped around (MIN > MAX),
937 then the operation caused one of them to wrap around, mark
938 the new range VARYING. */
939 vr->set_varying (expr_type);
940 }
941 else
942 vr->set (min, max, kind);
943}
944
945/* Return the range-ops handler for CODE and EXPR_TYPE. If no
946 suitable operator is found, return NULL and set VR to VARYING. */
947
948static const range_operator *
949get_range_op_handler (value_range *vr,
950 enum tree_code code,
951 tree expr_type)
952{
953 const range_operator *op = range_op_handler (code, expr_type);
954 if (!op)
955 vr->set_varying (expr_type);
956 return op;
957}
958
959/* If the types passed are supported, return TRUE, otherwise set VR to
960 VARYING and return FALSE. */
961
962static bool
963supported_types_p (value_range *vr,
964 tree type0,
965 tree type1 = NULLnullptr)
966{
967 if (!value_range::supports_type_p (type0)
968 || (type1 && !value_range::supports_type_p (type1)))
969 {
970 vr->set_varying (type0);
971 return false;
972 }
973 return true;
974}
975
976/* If any of the ranges passed are defined, return TRUE, otherwise set
977 VR to UNDEFINED and return FALSE. */
978
979static bool
980defined_ranges_p (value_range *vr,
981 const value_range *vr0, const value_range *vr1 = NULLnullptr)
982{
983 if (vr0->undefined_p () && (!vr1 || vr1->undefined_p ()))
984 {
985 vr->set_undefined ();
986 return false;
987 }
988 return true;
989}
990
991static value_range
992drop_undefines_to_varying (const value_range *vr, tree expr_type)
993{
994 if (vr->undefined_p ())
995 return value_range (expr_type);
996 else
997 return *vr;
998}
999
1000/* If any operand is symbolic, perform a binary operation on them and
1001 return TRUE, otherwise return FALSE. */
1002
1003static bool
1004range_fold_binary_symbolics_p (value_range *vr,
1005 tree_code code,
1006 tree expr_type,
1007 const value_range *vr0_,
1008 const value_range *vr1_)
1009{
1010 if (vr0_->symbolic_p () || vr1_->symbolic_p ())
1011 {
1012 value_range vr0 = drop_undefines_to_varying (vr0_, expr_type);
1013 value_range vr1 = drop_undefines_to_varying (vr1_, expr_type);
1014 if ((code == PLUS_EXPR || code == MINUS_EXPR))
1015 {
1016 extract_range_from_plus_minus_expr (vr, code, expr_type,
1017 &vr0, &vr1);
1018 return true;
1019 }
1020 if (POINTER_TYPE_P (expr_type)(((enum tree_code) (expr_type)->base.code) == POINTER_TYPE
|| ((enum tree_code) (expr_type)->base.code) == REFERENCE_TYPE
)
&& code == POINTER_PLUS_EXPR)
1021 {
1022 extract_range_from_pointer_plus_expr (vr, code, expr_type,
1023 &vr0, &vr1);
1024 return true;
1025 }
1026 const range_operator *op = get_range_op_handler (vr, code, expr_type);
1027 vr0.normalize_symbolics ();
1028 vr1.normalize_symbolics ();
1029 return op->fold_range (*vr, expr_type, vr0, vr1);
1030 }
1031 return false;
1032}
1033
1034/* If operand is symbolic, perform a unary operation on it and return
1035 TRUE, otherwise return FALSE. */
1036
1037static bool
1038range_fold_unary_symbolics_p (value_range *vr,
1039 tree_code code,
1040 tree expr_type,
1041 const value_range *vr0)
1042{
1043 if (vr0->symbolic_p ())
1044 {
1045 if (code == NEGATE_EXPR)
1046 {
1047 /* -X is simply 0 - X. */
1048 value_range zero;
1049 zero.set_zero (vr0->type ());
1050 range_fold_binary_expr (vr, MINUS_EXPR, expr_type, &zero, vr0);
1051 return true;
1052 }
1053 if (code == BIT_NOT_EXPR)
1054 {
1055 /* ~X is simply -1 - X. */
1056 value_range minusone;
1057 minusone.set (build_int_cst (vr0->type (), -1));
1058 range_fold_binary_expr (vr, MINUS_EXPR, expr_type, &minusone, vr0);
1059 return true;
1060 }
1061 const range_operator *op = get_range_op_handler (vr, code, expr_type);
1062 value_range vr0_cst (*vr0);
1063 vr0_cst.normalize_symbolics ();
1064 return op->fold_range (*vr, expr_type, vr0_cst, value_range (expr_type));
1065 }
1066 return false;
1067}
1068
1069/* Perform a binary operation on a pair of ranges. */
1070
1071void
1072range_fold_binary_expr (value_range *vr,
1073 enum tree_code code,
1074 tree expr_type,
1075 const value_range *vr0_,
1076 const value_range *vr1_)
1077{
1078 if (!supported_types_p (vr, expr_type)
1079 || !defined_ranges_p (vr, vr0_, vr1_))
1080 return;
1081 const range_operator *op = get_range_op_handler (vr, code, expr_type);
1082 if (!op)
1083 return;
1084
1085 if (range_fold_binary_symbolics_p (vr, code, expr_type, vr0_, vr1_))
1086 return;
1087
1088 value_range vr0 (*vr0_);
1089 value_range vr1 (*vr1_);
1090 if (vr0.undefined_p ())
1091 vr0.set_varying (expr_type);
1092 if (vr1.undefined_p ())
1093 vr1.set_varying (expr_type);
1094 vr0.normalize_addresses ();
1095 vr1.normalize_addresses ();
1096 op->fold_range (*vr, expr_type, vr0, vr1);
1097}
1098
1099/* Perform a unary operation on a range. */
1100
1101void
1102range_fold_unary_expr (value_range *vr,
1103 enum tree_code code, tree expr_type,
1104 const value_range *vr0,
1105 tree vr0_type)
1106{
1107 if (!supported_types_p (vr, expr_type, vr0_type)
1108 || !defined_ranges_p (vr, vr0))
1109 return;
1110 const range_operator *op = get_range_op_handler (vr, code, expr_type);
1111 if (!op)
1112 return;
1113
1114 if (range_fold_unary_symbolics_p (vr, code, expr_type, vr0))
1115 return;
1116
1117 value_range vr0_cst (*vr0);
1118 vr0_cst.normalize_addresses ();
1119 op->fold_range (*vr, expr_type, vr0_cst, value_range (expr_type));
1120}
1121
1122/* If the range of values taken by OP can be inferred after STMT executes,
1123 return the comparison code (COMP_CODE_P) and value (VAL_P) that
1124 describes the inferred range. Return true if a range could be
1125 inferred. */
1126
1127bool
1128infer_value_range (gimple *stmt, tree op, tree_code *comp_code_p, tree *val_p)
1129{
1130 *val_p = NULL_TREE(tree) nullptr;
1131 *comp_code_p = ERROR_MARK;
1132
1133 /* Do not attempt to infer anything in names that flow through
1134 abnormal edges. */
1135 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op)(tree_check ((op), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1135, __FUNCTION__, (SSA_NAME)))->base.asm_written_flag
)
1136 return false;
1137
1138 /* If STMT is the last statement of a basic block with no normal
1139 successors, there is no point inferring anything about any of its
1140 operands. We would not be able to find a proper insertion point
1141 for the assertion, anyway. */
1142 if (stmt_ends_bb_p (stmt))
1143 {
1144 edge_iterator ei;
1145 edge e;
1146
1147 FOR_EACH_EDGE (e, ei, gimple_bb (stmt)->succs)for ((ei) = ei_start_1 (&((gimple_bb (stmt)->succs)));
ei_cond ((ei), &(e)); ei_next (&(ei)))
1148 if (!(e->flags & (EDGE_ABNORMAL|EDGE_EH)))
1149 break;
1150 if (e == NULLnullptr)
1151 return false;
1152 }
1153
1154 if (infer_nonnull_range (stmt, op))
1155 {
1156 *val_p = build_int_cst (TREE_TYPE (op)((contains_struct_check ((op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1156, __FUNCTION__))->typed.type)
, 0);
1157 *comp_code_p = NE_EXPR;
1158 return true;
1159 }
1160
1161 return false;
1162}
1163
1164/* Dump assert_info structure. */
1165
1166void
1167dump_assert_info (FILE *file, const assert_info &assert)
1168{
1169 fprintf (file, "Assert for: ");
1170 print_generic_expr (file, assert.name);
1171 fprintf (file, "\n\tPREDICATE: expr=[");
1172 print_generic_expr (file, assert.expr);
1173 fprintf (file, "] %s ", get_tree_code_name (assert.comp_code));
1174 fprintf (file, "val=[");
1175 print_generic_expr (file, assert.val);
1176 fprintf (file, "]\n\n");
1177}
1178
1179DEBUG_FUNCTION__attribute__ ((__used__)) void
1180debug (const assert_info &assert)
1181{
1182 dump_assert_info (stderrstderr, assert);
1183}
1184
1185/* Dump a vector of assert_info's. */
1186
1187void
1188dump_asserts_info (FILE *file, const vec<assert_info> &asserts)
1189{
1190 for (unsigned i = 0; i < asserts.length (); ++i)
1191 {
1192 dump_assert_info (file, asserts[i]);
1193 fprintf (file, "\n");
1194 }
1195}
1196
1197DEBUG_FUNCTION__attribute__ ((__used__)) void
1198debug (const vec<assert_info> &asserts)
1199{
1200 dump_asserts_info (stderrstderr, asserts);
1201}
1202
1203/* Push the assert info for NAME, EXPR, COMP_CODE and VAL to ASSERTS. */
1204
1205static void
1206add_assert_info (vec<assert_info> &asserts,
1207 tree name, tree expr, enum tree_code comp_code, tree val)
1208{
1209 assert_info info;
1210 info.comp_code = comp_code;
1211 info.name = name;
1212 if (TREE_OVERFLOW_P (val)((tree_code_type[(int) (((enum tree_code) (val)->base.code
))] == tcc_constant) && ((tree_class_check ((val), (tcc_constant
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1212, __FUNCTION__))->base.public_flag))
)
1213 val = drop_tree_overflow (val);
1214 info.val = val;
1215 info.expr = expr;
1216 asserts.safe_push (info);
1217 if (dump_enabled_p ())
1218 dump_printf (MSG_NOTE | MSG_PRIORITY_INTERNALS,
1219 "Adding assert for %T from %T %s %T\n",
1220 name, expr, op_symbol_code (comp_code), val);
1221}
1222
1223/* (COND_OP0 COND_CODE COND_OP1) is a predicate which uses NAME.
1224 Extract a suitable test code and value and store them into *CODE_P and
1225 *VAL_P so the predicate is normalized to NAME *CODE_P *VAL_P.
1226
1227 If no extraction was possible, return FALSE, otherwise return TRUE.
1228
1229 If INVERT is true, then we invert the result stored into *CODE_P. */
1230
1231static bool
1232extract_code_and_val_from_cond_with_ops (tree name, enum tree_code cond_code,
1233 tree cond_op0, tree cond_op1,
1234 bool invert, enum tree_code *code_p,
1235 tree *val_p)
1236{
1237 enum tree_code comp_code;
1238 tree val;
1239
1240 /* Otherwise, we have a comparison of the form NAME COMP VAL
1241 or VAL COMP NAME. */
1242 if (name == cond_op1)
1243 {
1244 /* If the predicate is of the form VAL COMP NAME, flip
1245 COMP around because we need to register NAME as the
1246 first operand in the predicate. */
1247 comp_code = swap_tree_comparison (cond_code);
1248 val = cond_op0;
1249 }
1250 else if (name == cond_op0)
1251 {
1252 /* The comparison is of the form NAME COMP VAL, so the
1253 comparison code remains unchanged. */
1254 comp_code = cond_code;
1255 val = cond_op1;
1256 }
1257 else
1258 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1258, __FUNCTION__))
;
1259
1260 /* Invert the comparison code as necessary. */
1261 if (invert)
1262 comp_code = invert_tree_comparison (comp_code, 0);
1263
1264 /* VRP only handles integral and pointer types. */
1265 if (! INTEGRAL_TYPE_P (TREE_TYPE (val))(((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1265, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1265, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1265, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1266 && ! POINTER_TYPE_P (TREE_TYPE (val))(((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1266, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1266, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
)
1267 return false;
1268
1269 /* Do not register always-false predicates.
1270 FIXME: this works around a limitation in fold() when dealing with
1271 enumerations. Given 'enum { N1, N2 } x;', fold will not
1272 fold 'if (x > N2)' to 'if (0)'. */
1273 if ((comp_code == GT_EXPR || comp_code == LT_EXPR)
1274 && INTEGRAL_TYPE_P (TREE_TYPE (val))(((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1274, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1274, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1274, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
)
1275 {
1276 tree min = TYPE_MIN_VALUE (TREE_TYPE (val))((tree_check5 ((((contains_struct_check ((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1276, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1276, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
)
;
1277 tree max = TYPE_MAX_VALUE (TREE_TYPE (val))((tree_check5 ((((contains_struct_check ((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1277, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1277, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
)
;
1278
1279 if (comp_code == GT_EXPR
1280 && (!max
1281 || compare_values (val, max) == 0))
1282 return false;
1283
1284 if (comp_code == LT_EXPR
1285 && (!min
1286 || compare_values (val, min) == 0))
1287 return false;
1288 }
1289 *code_p = comp_code;
1290 *val_p = val;
1291 return true;
1292}
1293
1294/* Find out smallest RES where RES > VAL && (RES & MASK) == RES, if any
1295 (otherwise return VAL). VAL and MASK must be zero-extended for
1296 precision PREC. If SGNBIT is non-zero, first xor VAL with SGNBIT
1297 (to transform signed values into unsigned) and at the end xor
1298 SGNBIT back. */
1299
1300wide_int
1301masked_increment (const wide_int &val_in, const wide_int &mask,
1302 const wide_int &sgnbit, unsigned int prec)
1303{
1304 wide_int bit = wi::one (prec), res;
1305 unsigned int i;
1306
1307 wide_int val = val_in ^ sgnbit;
1308 for (i = 0; i < prec; i++, bit += bit)
1309 {
1310 res = mask;
1311 if ((res & bit) == 0)
1312 continue;
1313 res = bit - 1;
1314 res = wi::bit_and_not (val + bit, res);
1315 res &= mask;
1316 if (wi::gtu_p (res, val))
1317 return res ^ sgnbit;
1318 }
1319 return val ^ sgnbit;
1320}
1321
1322/* Helper for overflow_comparison_p
1323
1324 OP0 CODE OP1 is a comparison. Examine the comparison and potentially
1325 OP1's defining statement to see if it ultimately has the form
1326 OP0 CODE (OP0 PLUS INTEGER_CST)
1327
1328 If so, return TRUE indicating this is an overflow test and store into
1329 *NEW_CST an updated constant that can be used in a narrowed range test.
1330
1331 REVERSED indicates if the comparison was originally:
1332
1333 OP1 CODE' OP0.
1334
1335 This affects how we build the updated constant. */
1336
1337static bool
1338overflow_comparison_p_1 (enum tree_code code, tree op0, tree op1,
1339 bool follow_assert_exprs, bool reversed, tree *new_cst)
1340{
1341 /* See if this is a relational operation between two SSA_NAMES with
1342 unsigned, overflow wrapping values. If so, check it more deeply. */
1343 if ((code == LT_EXPR || code == LE_EXPR
1344 || code == GE_EXPR || code == GT_EXPR)
1345 && TREE_CODE (op0)((enum tree_code) (op0)->base.code) == SSA_NAME
1346 && TREE_CODE (op1)((enum tree_code) (op1)->base.code) == SSA_NAME
1347 && INTEGRAL_TYPE_P (TREE_TYPE (op0))(((enum tree_code) (((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1347, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1347, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1347, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1348 && TYPE_UNSIGNED (TREE_TYPE (op0))((tree_class_check ((((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1348, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1348, __FUNCTION__))->base.u.bits.unsigned_flag)
1349 && TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0))((((enum tree_code) (((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1349, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1349, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
) ? global_options.x_flag_wrapv_pointer : ((any_integral_type_check
((((contains_struct_check ((op0), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1349, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1349, __FUNCTION__))->base.u.bits.unsigned_flag || global_options
.x_flag_wrapv))
)
1350 {
1351 gimple *op1_def = SSA_NAME_DEF_STMT (op1)(tree_check ((op1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1351, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1352
1353 /* If requested, follow any ASSERT_EXPRs backwards for OP1. */
1354 if (follow_assert_exprs)
1355 {
1356 while (gimple_assign_single_p (op1_def)
1357 && TREE_CODE (gimple_assign_rhs1 (op1_def))((enum tree_code) (gimple_assign_rhs1 (op1_def))->base.code
)
== ASSERT_EXPR)
1358 {
1359 op1 = TREE_OPERAND (gimple_assign_rhs1 (op1_def), 0)(*((const_cast<tree*> (tree_operand_check ((gimple_assign_rhs1
(op1_def)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1359, __FUNCTION__)))))
;
1360 if (TREE_CODE (op1)((enum tree_code) (op1)->base.code) != SSA_NAME)
1361 break;
1362 op1_def = SSA_NAME_DEF_STMT (op1)(tree_check ((op1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1362, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1363 }
1364 }
1365
1366 /* Now look at the defining statement of OP1 to see if it adds
1367 or subtracts a nonzero constant from another operand. */
1368 if (op1_def
1369 && is_gimple_assign (op1_def)
1370 && gimple_assign_rhs_code (op1_def) == PLUS_EXPR
1371 && TREE_CODE (gimple_assign_rhs2 (op1_def))((enum tree_code) (gimple_assign_rhs2 (op1_def))->base.code
)
== INTEGER_CST
1372 && !integer_zerop (gimple_assign_rhs2 (op1_def)))
1373 {
1374 tree target = gimple_assign_rhs1 (op1_def);
1375
1376 /* If requested, follow ASSERT_EXPRs backwards for op0 looking
1377 for one where TARGET appears on the RHS. */
1378 if (follow_assert_exprs)
1379 {
1380 /* Now see if that "other operand" is op0, following the chain
1381 of ASSERT_EXPRs if necessary. */
1382 gimple *op0_def = SSA_NAME_DEF_STMT (op0)(tree_check ((op0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1382, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1383 while (op0 != target
1384 && gimple_assign_single_p (op0_def)
1385 && TREE_CODE (gimple_assign_rhs1 (op0_def))((enum tree_code) (gimple_assign_rhs1 (op0_def))->base.code
)
== ASSERT_EXPR)
1386 {
1387 op0 = TREE_OPERAND (gimple_assign_rhs1 (op0_def), 0)(*((const_cast<tree*> (tree_operand_check ((gimple_assign_rhs1
(op0_def)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1387, __FUNCTION__)))))
;
1388 if (TREE_CODE (op0)((enum tree_code) (op0)->base.code) != SSA_NAME)
1389 break;
1390 op0_def = SSA_NAME_DEF_STMT (op0)(tree_check ((op0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1390, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1391 }
1392 }
1393
1394 /* If we did not find our target SSA_NAME, then this is not
1395 an overflow test. */
1396 if (op0 != target)
1397 return false;
1398
1399 tree type = TREE_TYPE (op0)((contains_struct_check ((op0), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1399, __FUNCTION__))->typed.type)
;
1400 wide_int max = wi::max_value (TYPE_PRECISION (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1400, __FUNCTION__))->type_common.precision)
, UNSIGNED);
1401 tree inc = gimple_assign_rhs2 (op1_def);
1402 if (reversed)
1403 *new_cst = wide_int_to_tree (type, max + wi::to_wide (inc));
1404 else
1405 *new_cst = wide_int_to_tree (type, max - wi::to_wide (inc));
1406 return true;
1407 }
1408 }
1409 return false;
1410}
1411
1412/* OP0 CODE OP1 is a comparison. Examine the comparison and potentially
1413 OP1's defining statement to see if it ultimately has the form
1414 OP0 CODE (OP0 PLUS INTEGER_CST)
1415
1416 If so, return TRUE indicating this is an overflow test and store into
1417 *NEW_CST an updated constant that can be used in a narrowed range test.
1418
1419 These statements are left as-is in the IL to facilitate discovery of
1420 {ADD,SUB}_OVERFLOW sequences later in the optimizer pipeline. But
1421 the alternate range representation is often useful within VRP. */
1422
1423bool
1424overflow_comparison_p (tree_code code, tree name, tree val,
1425 bool use_equiv_p, tree *new_cst)
1426{
1427 if (overflow_comparison_p_1 (code, name, val, use_equiv_p, false, new_cst))
1428 return true;
1429 return overflow_comparison_p_1 (swap_tree_comparison (code), val, name,
1430 use_equiv_p, true, new_cst);
1431}
1432
1433
1434/* Try to register an edge assertion for SSA name NAME on edge E for
1435 the condition COND contributing to the conditional jump pointed to by BSI.
1436 Invert the condition COND if INVERT is true. */
1437
1438static void
1439register_edge_assert_for_2 (tree name, edge e,
1440 enum tree_code cond_code,
1441 tree cond_op0, tree cond_op1, bool invert,
1442 vec<assert_info> &asserts)
1443{
1444 tree val;
1445 enum tree_code comp_code;
1446
1447 if (!extract_code_and_val_from_cond_with_ops (name, cond_code,
1448 cond_op0,
1449 cond_op1,
1450 invert, &comp_code, &val))
1451 return;
1452
1453 /* Queue the assert. */
1454 tree x;
1455 if (overflow_comparison_p (comp_code, name, val, false, &x))
1456 {
1457 enum tree_code new_code = ((comp_code == GT_EXPR || comp_code == GE_EXPR)
1458 ? GT_EXPR : LE_EXPR);
1459 add_assert_info (asserts, name, name, new_code, x);
1460 }
1461 add_assert_info (asserts, name, name, comp_code, val);
1462
1463 /* In the case of NAME <= CST and NAME being defined as
1464 NAME = (unsigned) NAME2 + CST2 we can assert NAME2 >= -CST2
1465 and NAME2 <= CST - CST2. We can do the same for NAME > CST.
1466 This catches range and anti-range tests. */
1467 if ((comp_code == LE_EXPR
1468 || comp_code == GT_EXPR)
1469 && TREE_CODE (val)((enum tree_code) (val)->base.code) == INTEGER_CST
1470 && TYPE_UNSIGNED (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1470, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1470, __FUNCTION__))->base.u.bits.unsigned_flag)
)
1471 {
1472 gimple *def_stmt = SSA_NAME_DEF_STMT (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1472, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1473 tree cst2 = NULL_TREE(tree) nullptr, name2 = NULL_TREE(tree) nullptr, name3 = NULL_TREE(tree) nullptr;
1474
1475 /* Extract CST2 from the (optional) addition. */
1476 if (is_gimple_assign (def_stmt)
1477 && gimple_assign_rhs_code (def_stmt) == PLUS_EXPR)
1478 {
1479 name2 = gimple_assign_rhs1 (def_stmt);
1480 cst2 = gimple_assign_rhs2 (def_stmt);
1481 if (TREE_CODE (name2)((enum tree_code) (name2)->base.code) == SSA_NAME
1482 && TREE_CODE (cst2)((enum tree_code) (cst2)->base.code) == INTEGER_CST)
1483 def_stmt = SSA_NAME_DEF_STMT (name2)(tree_check ((name2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1483, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1484 }
1485
1486 /* Extract NAME2 from the (optional) sign-changing cast. */
1487 if (gimple_assign_cast_p (def_stmt))
1488 {
1489 if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))((gimple_assign_rhs_code (def_stmt)) == NOP_EXPR || (gimple_assign_rhs_code
(def_stmt)) == CONVERT_EXPR)
1490 && ! TYPE_UNSIGNED (TREE_TYPE (gimple_assign_rhs1 (def_stmt)))((tree_class_check ((((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1490, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1490, __FUNCTION__))->base.u.bits.unsigned_flag)
1491 && (TYPE_PRECISION (gimple_expr_type (def_stmt))((tree_class_check ((gimple_expr_type (def_stmt)), (tcc_type)
, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1491, __FUNCTION__))->type_common.precision)
1492 == TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (def_stmt)))((tree_class_check ((((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1492, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1492, __FUNCTION__))->type_common.precision)
))
1493 name3 = gimple_assign_rhs1 (def_stmt);
1494 }
1495
1496 /* If name3 is used later, create an ASSERT_EXPR for it. */
1497 if (name3 != NULL_TREE(tree) nullptr
1498 && TREE_CODE (name3)((enum tree_code) (name3)->base.code) == SSA_NAME
1499 && (cst2 == NULL_TREE(tree) nullptr
1500 || TREE_CODE (cst2)((enum tree_code) (cst2)->base.code) == INTEGER_CST)
1501 && INTEGRAL_TYPE_P (TREE_TYPE (name3))(((enum tree_code) (((contains_struct_check ((name3), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1501, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((name3), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1501, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((name3), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1501, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
)
1502 {
1503 tree tmp;
1504
1505 /* Build an expression for the range test. */
1506 tmp = build1 (NOP_EXPR, TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1506, __FUNCTION__))->typed.type)
, name3);
1507 if (cst2 != NULL_TREE(tree) nullptr)
1508 tmp = build2 (PLUS_EXPR, TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1508, __FUNCTION__))->typed.type)
, tmp, cst2);
1509 add_assert_info (asserts, name3, tmp, comp_code, val);
1510 }
1511
1512 /* If name2 is used later, create an ASSERT_EXPR for it. */
1513 if (name2 != NULL_TREE(tree) nullptr
1514 && TREE_CODE (name2)((enum tree_code) (name2)->base.code) == SSA_NAME
1515 && TREE_CODE (cst2)((enum tree_code) (cst2)->base.code) == INTEGER_CST
1516 && INTEGRAL_TYPE_P (TREE_TYPE (name2))(((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1516, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1516, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1516, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
)
1517 {
1518 tree tmp;
1519
1520 /* Build an expression for the range test. */
1521 tmp = name2;
1522 if (TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1522, __FUNCTION__))->typed.type)
!= TREE_TYPE (name2)((contains_struct_check ((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1522, __FUNCTION__))->typed.type)
)
1523 tmp = build1 (NOP_EXPR, TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1523, __FUNCTION__))->typed.type)
, tmp);
1524 if (cst2 != NULL_TREE(tree) nullptr)
1525 tmp = build2 (PLUS_EXPR, TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1525, __FUNCTION__))->typed.type)
, tmp, cst2);
1526 add_assert_info (asserts, name2, tmp, comp_code, val);
1527 }
1528 }
1529
1530 /* In the case of post-in/decrement tests like if (i++) ... and uses
1531 of the in/decremented value on the edge the extra name we want to
1532 assert for is not on the def chain of the name compared. Instead
1533 it is in the set of use stmts.
1534 Similar cases happen for conversions that were simplified through
1535 fold_{sign_changed,widened}_comparison. */
1536 if ((comp_code == NE_EXPR
1537 || comp_code == EQ_EXPR)
1538 && TREE_CODE (val)((enum tree_code) (val)->base.code) == INTEGER_CST)
1539 {
1540 imm_use_iterator ui;
1541 gimple *use_stmt;
1542 FOR_EACH_IMM_USE_STMT (use_stmt, ui, name)for (struct auto_end_imm_use_stmt_traverse auto_end_imm_use_stmt_traverse
((((use_stmt) = first_imm_use_stmt (&(ui), (name))), &
(ui))); !end_imm_use_stmt_p (&(ui)); (void) ((use_stmt) =
next_imm_use_stmt (&(ui))))
1543 {
1544 if (!is_gimple_assign (use_stmt))
1545 continue;
1546
1547 /* Cut off to use-stmts that are dominating the predecessor. */
1548 if (!dominated_by_p (CDI_DOMINATORS, e->src, gimple_bb (use_stmt)))
1549 continue;
1550
1551 tree name2 = gimple_assign_lhs (use_stmt);
1552 if (TREE_CODE (name2)((enum tree_code) (name2)->base.code) != SSA_NAME)
1553 continue;
1554
1555 enum tree_code code = gimple_assign_rhs_code (use_stmt);
1556 tree cst;
1557 if (code == PLUS_EXPR
1558 || code == MINUS_EXPR)
1559 {
1560 cst = gimple_assign_rhs2 (use_stmt);
1561 if (TREE_CODE (cst)((enum tree_code) (cst)->base.code) != INTEGER_CST)
1562 continue;
1563 cst = int_const_binop (code, val, cst);
1564 }
1565 else if (CONVERT_EXPR_CODE_P (code)((code) == NOP_EXPR || (code) == CONVERT_EXPR))
1566 {
1567 /* For truncating conversions we cannot record
1568 an inequality. */
1569 if (comp_code == NE_EXPR
1570 && (TYPE_PRECISION (TREE_TYPE (name2))((tree_class_check ((((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1570, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1570, __FUNCTION__))->type_common.precision)
1571 < TYPE_PRECISION (TREE_TYPE (name))((tree_class_check ((((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1571, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1571, __FUNCTION__))->type_common.precision)
))
1572 continue;
1573 cst = fold_convert (TREE_TYPE (name2), val)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1573, __FUNCTION__))->typed.type), val)
;
1574 }
1575 else
1576 continue;
1577
1578 if (TREE_OVERFLOW_P (cst)((tree_code_type[(int) (((enum tree_code) (cst)->base.code
))] == tcc_constant) && ((tree_class_check ((cst), (tcc_constant
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1578, __FUNCTION__))->base.public_flag))
)
1579 cst = drop_tree_overflow (cst);
1580 add_assert_info (asserts, name2, name2, comp_code, cst);
1581 }
1582 }
1583
1584 if (TREE_CODE_CLASS (comp_code)tree_code_type[(int) (comp_code)] == tcc_comparison
1585 && TREE_CODE (val)((enum tree_code) (val)->base.code) == INTEGER_CST)
1586 {
1587 gimple *def_stmt = SSA_NAME_DEF_STMT (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1587, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1588 tree name2 = NULL_TREE(tree) nullptr, names[2], cst2 = NULL_TREE(tree) nullptr;
1589 tree val2 = NULL_TREE(tree) nullptr;
1590 unsigned int prec = TYPE_PRECISION (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1590, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1590, __FUNCTION__))->type_common.precision)
;
1591 wide_int mask = wi::zero (prec);
1592 unsigned int nprec = prec;
1593 enum tree_code rhs_code = ERROR_MARK;
1594
1595 if (is_gimple_assign (def_stmt))
1596 rhs_code = gimple_assign_rhs_code (def_stmt);
1597
1598 /* In the case of NAME != CST1 where NAME = A +- CST2 we can
1599 assert that A != CST1 -+ CST2. */
1600 if ((comp_code == EQ_EXPR || comp_code == NE_EXPR)
1601 && (rhs_code == PLUS_EXPR || rhs_code == MINUS_EXPR))
1602 {
1603 tree op0 = gimple_assign_rhs1 (def_stmt);
1604 tree op1 = gimple_assign_rhs2 (def_stmt);
1605 if (TREE_CODE (op0)((enum tree_code) (op0)->base.code) == SSA_NAME
1606 && TREE_CODE (op1)((enum tree_code) (op1)->base.code) == INTEGER_CST)
1607 {
1608 enum tree_code reverse_op = (rhs_code == PLUS_EXPR
1609 ? MINUS_EXPR : PLUS_EXPR);
1610 op1 = int_const_binop (reverse_op, val, op1);
1611 if (TREE_OVERFLOW (op1)((tree_class_check ((op1), (tcc_constant), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1611, __FUNCTION__))->base.public_flag)
)
1612 op1 = drop_tree_overflow (op1);
1613 add_assert_info (asserts, op0, op0, comp_code, op1);
1614 }
1615 }
1616
1617 /* Add asserts for NAME cmp CST and NAME being defined
1618 as NAME = (int) NAME2. */
1619 if (!TYPE_UNSIGNED (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1619, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1619, __FUNCTION__))->base.u.bits.unsigned_flag)
1620 && (comp_code == LE_EXPR || comp_code == LT_EXPR
1621 || comp_code == GT_EXPR || comp_code == GE_EXPR)
1622 && gimple_assign_cast_p (def_stmt))
1623 {
1624 name2 = gimple_assign_rhs1 (def_stmt);
1625 if (CONVERT_EXPR_CODE_P (rhs_code)((rhs_code) == NOP_EXPR || (rhs_code) == CONVERT_EXPR)
1626 && TREE_CODE (name2)((enum tree_code) (name2)->base.code) == SSA_NAME
1627 && INTEGRAL_TYPE_P (TREE_TYPE (name2))(((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1627, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1627, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1627, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1628 && TYPE_UNSIGNED (TREE_TYPE (name2))((tree_class_check ((((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1628, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1628, __FUNCTION__))->base.u.bits.unsigned_flag)
1629 && prec == TYPE_PRECISION (TREE_TYPE (name2))((tree_class_check ((((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1629, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1629, __FUNCTION__))->type_common.precision)
1630 && (comp_code == LE_EXPR || comp_code == GT_EXPR
1631 || !tree_int_cst_equal (val,
1632 TYPE_MIN_VALUE (TREE_TYPE (val))((tree_check5 ((((contains_struct_check ((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1632, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1632, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
)
)))
1633 {
1634 tree tmp, cst;
1635 enum tree_code new_comp_code = comp_code;
1636
1637 cst = fold_convert (TREE_TYPE (name2),fold_convert_loc (((location_t) 0), ((contains_struct_check (
(name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1637, __FUNCTION__))->typed.type), ((tree_check5 ((((contains_struct_check
((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1638, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1638, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
))
1638 TYPE_MIN_VALUE (TREE_TYPE (val)))fold_convert_loc (((location_t) 0), ((contains_struct_check (
(name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1637, __FUNCTION__))->typed.type), ((tree_check5 ((((contains_struct_check
((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1638, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1638, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
))
;
1639 /* Build an expression for the range test. */
1640 tmp = build2 (PLUS_EXPR, TREE_TYPE (name2)((contains_struct_check ((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1640, __FUNCTION__))->typed.type)
, name2, cst);
1641 cst = fold_build2 (PLUS_EXPR, TREE_TYPE (name2), cst,fold_build2_loc (((location_t) 0), PLUS_EXPR, ((contains_struct_check
((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1641, __FUNCTION__))->typed.type), cst, fold_convert_loc
(((location_t) 0), ((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1642, __FUNCTION__))->typed.type), val) )
1642 fold_convert (TREE_TYPE (name2), val))fold_build2_loc (((location_t) 0), PLUS_EXPR, ((contains_struct_check
((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1641, __FUNCTION__))->typed.type), cst, fold_convert_loc
(((location_t) 0), ((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1642, __FUNCTION__))->typed.type), val) )
;
1643 if (comp_code == LT_EXPR || comp_code == GE_EXPR)
1644 {
1645 new_comp_code = comp_code == LT_EXPR ? LE_EXPR : GT_EXPR;
1646 cst = fold_build2 (MINUS_EXPR, TREE_TYPE (name2), cst,fold_build2_loc (((location_t) 0), MINUS_EXPR, ((contains_struct_check
((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1646, __FUNCTION__))->typed.type), cst, build_int_cst ((
(contains_struct_check ((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1647, __FUNCTION__))->typed.type), 1) )
1647 build_int_cst (TREE_TYPE (name2), 1))fold_build2_loc (((location_t) 0), MINUS_EXPR, ((contains_struct_check
((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1646, __FUNCTION__))->typed.type), cst, build_int_cst ((
(contains_struct_check ((name2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1647, __FUNCTION__))->typed.type), 1) )
;
1648 }
1649 add_assert_info (asserts, name2, tmp, new_comp_code, cst);
1650 }
1651 }
1652
1653 /* Add asserts for NAME cmp CST and NAME being defined as
1654 NAME = NAME2 >> CST2.
1655
1656 Extract CST2 from the right shift. */
1657 if (rhs_code == RSHIFT_EXPR)
1658 {
1659 name2 = gimple_assign_rhs1 (def_stmt);
1660 cst2 = gimple_assign_rhs2 (def_stmt);
1661 if (TREE_CODE (name2)((enum tree_code) (name2)->base.code) == SSA_NAME
1662 && tree_fits_uhwi_p (cst2)
1663 && INTEGRAL_TYPE_P (TREE_TYPE (name2))(((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1663, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1663, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1663, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1664 && IN_RANGE (tree_to_uhwi (cst2), 1, prec - 1)((unsigned long) (tree_to_uhwi (cst2)) - (unsigned long) (1) <=
(unsigned long) (prec - 1) - (unsigned long) (1))
1665 && type_has_mode_precision_p (TREE_TYPE (val)((contains_struct_check ((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1665, __FUNCTION__))->typed.type)
))
1666 {
1667 mask = wi::mask (tree_to_uhwi (cst2), false, prec);
1668 val2 = fold_binary (LSHIFT_EXPR, TREE_TYPE (val), val, cst2)fold_binary_loc (((location_t) 0), LSHIFT_EXPR, ((contains_struct_check
((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1668, __FUNCTION__))->typed.type), val, cst2)
;
1669 }
1670 }
1671 if (val2 != NULL_TREE(tree) nullptr
1672 && TREE_CODE (val2)((enum tree_code) (val2)->base.code) == INTEGER_CST
1673 && simple_cst_equal (fold_build2 (RSHIFT_EXPR,fold_build2_loc (((location_t) 0), RSHIFT_EXPR, ((contains_struct_check
((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1674, __FUNCTION__))->typed.type), val2, cst2 )
1674 TREE_TYPE (val),fold_build2_loc (((location_t) 0), RSHIFT_EXPR, ((contains_struct_check
((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1674, __FUNCTION__))->typed.type), val2, cst2 )
1675 val2, cst2)fold_build2_loc (((location_t) 0), RSHIFT_EXPR, ((contains_struct_check
((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1674, __FUNCTION__))->typed.type), val2, cst2 )
, val))
1676 {
1677 enum tree_code new_comp_code = comp_code;
1678 tree tmp, new_val;
1679
1680 tmp = name2;
1681 if (comp_code == EQ_EXPR || comp_code == NE_EXPR)
1682 {
1683 if (!TYPE_UNSIGNED (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1683, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1683, __FUNCTION__))->base.u.bits.unsigned_flag)
)
1684 {
1685 tree type = build_nonstandard_integer_type (prec, 1);
1686 tmp = build1 (NOP_EXPR, type, name2);
1687 val2 = fold_convert (type, val2)fold_convert_loc (((location_t) 0), type, val2);
1688 }
1689 tmp = fold_build2 (MINUS_EXPR, TREE_TYPE (tmp), tmp, val2)fold_build2_loc (((location_t) 0), MINUS_EXPR, ((contains_struct_check
((tmp), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1689, __FUNCTION__))->typed.type), tmp, val2 )
;
1690 new_val = wide_int_to_tree (TREE_TYPE (tmp)((contains_struct_check ((tmp), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1690, __FUNCTION__))->typed.type)
, mask);
1691 new_comp_code = comp_code == EQ_EXPR ? LE_EXPR : GT_EXPR;
1692 }
1693 else if (comp_code == LT_EXPR || comp_code == GE_EXPR)
1694 {
1695 wide_int minval
1696 = wi::min_value (prec, TYPE_SIGN (TREE_TYPE (val))((signop) ((tree_class_check ((((contains_struct_check ((val)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1696, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1696, __FUNCTION__))->base.u.bits.unsigned_flag))
);
1697 new_val = val2;
1698 if (minval == wi::to_wide (new_val))
1699 new_val = NULL_TREE(tree) nullptr;
1700 }
1701 else
1702 {
1703 wide_int maxval
1704 = wi::max_value (prec, TYPE_SIGN (TREE_TYPE (val))((signop) ((tree_class_check ((((contains_struct_check ((val)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1704, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1704, __FUNCTION__))->base.u.bits.unsigned_flag))
);
1705 mask |= wi::to_wide (val2);
1706 if (wi::eq_p (mask, maxval))
1707 new_val = NULL_TREE(tree) nullptr;
1708 else
1709 new_val = wide_int_to_tree (TREE_TYPE (val2)((contains_struct_check ((val2), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1709, __FUNCTION__))->typed.type)
, mask);
1710 }
1711
1712 if (new_val)
1713 add_assert_info (asserts, name2, tmp, new_comp_code, new_val);
1714 }
1715
1716 /* If we have a conversion that doesn't change the value of the source
1717 simply register the same assert for it. */
1718 if (CONVERT_EXPR_CODE_P (rhs_code)((rhs_code) == NOP_EXPR || (rhs_code) == CONVERT_EXPR))
1719 {
1720 wide_int rmin, rmax;
1721 tree rhs1 = gimple_assign_rhs1 (def_stmt);
1722 if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))(((enum tree_code) (((contains_struct_check ((rhs1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1722, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((rhs1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1722, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((rhs1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1722, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1723 && TREE_CODE (rhs1)((enum tree_code) (rhs1)->base.code) == SSA_NAME
1724 /* Make sure the relation preserves the upper/lower boundary of
1725 the range conservatively. */
1726 && (comp_code == NE_EXPR
1727 || comp_code == EQ_EXPR
1728 || (TYPE_SIGN (TREE_TYPE (name))((signop) ((tree_class_check ((((contains_struct_check ((name
), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1728, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1728, __FUNCTION__))->base.u.bits.unsigned_flag))
1729 == TYPE_SIGN (TREE_TYPE (rhs1))((signop) ((tree_class_check ((((contains_struct_check ((rhs1
), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1729, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1729, __FUNCTION__))->base.u.bits.unsigned_flag))
)
1730 || ((comp_code == LE_EXPR
1731 || comp_code == LT_EXPR)
1732 && !TYPE_UNSIGNED (TREE_TYPE (rhs1))((tree_class_check ((((contains_struct_check ((rhs1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1732, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1732, __FUNCTION__))->base.u.bits.unsigned_flag)
)
1733 || ((comp_code == GE_EXPR
1734 || comp_code == GT_EXPR)
1735 && TYPE_UNSIGNED (TREE_TYPE (rhs1))((tree_class_check ((((contains_struct_check ((rhs1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1735, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1735, __FUNCTION__))->base.u.bits.unsigned_flag)
))
1736 /* And the conversion does not alter the value we compare
1737 against and all values in rhs1 can be represented in
1738 the converted to type. */
1739 && int_fits_type_p (val, TREE_TYPE (rhs1)((contains_struct_check ((rhs1), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1739, __FUNCTION__))->typed.type)
)
1740 && ((TYPE_PRECISION (TREE_TYPE (name))((tree_class_check ((((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1740, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1740, __FUNCTION__))->type_common.precision)
1741 > TYPE_PRECISION (TREE_TYPE (rhs1))((tree_class_check ((((contains_struct_check ((rhs1), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1741, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1741, __FUNCTION__))->type_common.precision)
)
1742 || (get_range_info (rhs1, &rmin, &rmax) == VR_RANGE
1743 && wi::fits_to_tree_p
1744 (widest_int::from (rmin,
1745 TYPE_SIGN (TREE_TYPE (rhs1))((signop) ((tree_class_check ((((contains_struct_check ((rhs1
), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1745, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1745, __FUNCTION__))->base.u.bits.unsigned_flag))
),
1746 TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1746, __FUNCTION__))->typed.type)
)
1747 && wi::fits_to_tree_p
1748 (widest_int::from (rmax,
1749 TYPE_SIGN (TREE_TYPE (rhs1))((signop) ((tree_class_check ((((contains_struct_check ((rhs1
), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1749, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1749, __FUNCTION__))->base.u.bits.unsigned_flag))
),
1750 TREE_TYPE (name)((contains_struct_check ((name), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1750, __FUNCTION__))->typed.type)
))))
1751 add_assert_info (asserts, rhs1, rhs1,
1752 comp_code, fold_convert (TREE_TYPE (rhs1), val)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(rhs1), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1752, __FUNCTION__))->typed.type), val)
);
1753 }
1754
1755 /* Add asserts for NAME cmp CST and NAME being defined as
1756 NAME = NAME2 & CST2.
1757
1758 Extract CST2 from the and.
1759
1760 Also handle
1761 NAME = (unsigned) NAME2;
1762 casts where NAME's type is unsigned and has smaller precision
1763 than NAME2's type as if it was NAME = NAME2 & MASK. */
1764 names[0] = NULL_TREE(tree) nullptr;
1765 names[1] = NULL_TREE(tree) nullptr;
1766 cst2 = NULL_TREE(tree) nullptr;
1767 if (rhs_code == BIT_AND_EXPR
1768 || (CONVERT_EXPR_CODE_P (rhs_code)((rhs_code) == NOP_EXPR || (rhs_code) == CONVERT_EXPR)
1769 && INTEGRAL_TYPE_P (TREE_TYPE (val))(((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1769, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1769, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1769, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1770 && TYPE_UNSIGNED (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1770, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1770, __FUNCTION__))->base.u.bits.unsigned_flag)
1771 && TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (def_stmt)))((tree_class_check ((((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1771, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1771, __FUNCTION__))->type_common.precision)
1772 > prec))
1773 {
1774 name2 = gimple_assign_rhs1 (def_stmt);
1775 if (rhs_code == BIT_AND_EXPR)
1776 cst2 = gimple_assign_rhs2 (def_stmt);
1777 else
1778 {
1779 cst2 = TYPE_MAX_VALUE (TREE_TYPE (val))((tree_check5 ((((contains_struct_check ((val), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1779, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1779, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
)
;
1780 nprec = TYPE_PRECISION (TREE_TYPE (name2))((tree_class_check ((((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1780, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1780, __FUNCTION__))->type_common.precision)
;
1781 }
1782 if (TREE_CODE (name2)((enum tree_code) (name2)->base.code) == SSA_NAME
1783 && INTEGRAL_TYPE_P (TREE_TYPE (name2))(((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1783, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1783, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1783, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1784 && TREE_CODE (cst2)((enum tree_code) (cst2)->base.code) == INTEGER_CST
1785 && !integer_zerop (cst2)
1786 && (nprec > 1
1787 || TYPE_UNSIGNED (TREE_TYPE (val))((tree_class_check ((((contains_struct_check ((val), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1787, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1787, __FUNCTION__))->base.u.bits.unsigned_flag)
))
1788 {
1789 gimple *def_stmt2 = SSA_NAME_DEF_STMT (name2)(tree_check ((name2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1789, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
1790 if (gimple_assign_cast_p (def_stmt2))
1791 {
1792 names[1] = gimple_assign_rhs1 (def_stmt2);
1793 if (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt2))((gimple_assign_rhs_code (def_stmt2)) == NOP_EXPR || (gimple_assign_rhs_code
(def_stmt2)) == CONVERT_EXPR)
1794 || TREE_CODE (names[1])((enum tree_code) (names[1])->base.code) != SSA_NAME
1795 || !INTEGRAL_TYPE_P (TREE_TYPE (names[1]))(((enum tree_code) (((contains_struct_check ((names[1]), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1795, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((names[1]), (
TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1795, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((names[1]), (
TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1795, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
1796 || (TYPE_PRECISION (TREE_TYPE (name2))((tree_class_check ((((contains_struct_check ((name2), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1796, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1796, __FUNCTION__))->type_common.precision)
1797 != TYPE_PRECISION (TREE_TYPE (names[1]))((tree_class_check ((((contains_struct_check ((names[1]), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1797, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1797, __FUNCTION__))->type_common.precision)
))
1798 names[1] = NULL_TREE(tree) nullptr;
1799 }
1800 names[0] = name2;
1801 }
1802 }
1803 if (names[0] || names[1])
1804 {
1805 wide_int minv, maxv, valv, cst2v;
1806 wide_int tem, sgnbit;
1807 bool valid_p = false, valn, cst2n;
1808 enum tree_code ccode = comp_code;
1809
1810 valv = wide_int::from (wi::to_wide (val), nprec, UNSIGNED);
1811 cst2v = wide_int::from (wi::to_wide (cst2), nprec, UNSIGNED);
1812 valn = wi::neg_p (valv, TYPE_SIGN (TREE_TYPE (val))((signop) ((tree_class_check ((((contains_struct_check ((val)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1812, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1812, __FUNCTION__))->base.u.bits.unsigned_flag))
);
1813 cst2n = wi::neg_p (cst2v, TYPE_SIGN (TREE_TYPE (val))((signop) ((tree_class_check ((((contains_struct_check ((val)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1813, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1813, __FUNCTION__))->base.u.bits.unsigned_flag))
);
1814 /* If CST2 doesn't have most significant bit set,
1815 but VAL is negative, we have comparison like
1816 if ((x & 0x123) > -4) (always true). Just give up. */
1817 if (!cst2n && valn)
1818 ccode = ERROR_MARK;
1819 if (cst2n)
1820 sgnbit = wi::set_bit_in_zero (nprec - 1, nprec);
1821 else
1822 sgnbit = wi::zero (nprec);
1823 minv = valv & cst2v;
1824 switch (ccode)
1825 {
1826 case EQ_EXPR:
1827 /* Minimum unsigned value for equality is VAL & CST2
1828 (should be equal to VAL, otherwise we probably should
1829 have folded the comparison into false) and
1830 maximum unsigned value is VAL | ~CST2. */
1831 maxv = valv | ~cst2v;
1832 valid_p = true;
1833 break;
1834
1835 case NE_EXPR:
1836 tem = valv | ~cst2v;
1837 /* If VAL is 0, handle (X & CST2) != 0 as (X & CST2) > 0U. */
1838 if (valv == 0)
1839 {
1840 cst2n = false;
1841 sgnbit = wi::zero (nprec);
1842 goto gt_expr;
1843 }
1844 /* If (VAL | ~CST2) is all ones, handle it as
1845 (X & CST2) < VAL. */
1846 if (tem == -1)
1847 {
1848 cst2n = false;
Value stored to 'cst2n' is never read
1849 valn = false;
1850 sgnbit = wi::zero (nprec);
1851 goto lt_expr;
1852 }
1853 if (!cst2n && wi::neg_p (cst2v))
1854 sgnbit = wi::set_bit_in_zero (nprec - 1, nprec);
1855 if (sgnbit != 0)
1856 {
1857 if (valv == sgnbit)
1858 {
1859 cst2n = true;
1860 valn = true;
1861 goto gt_expr;
1862 }
1863 if (tem == wi::mask (nprec - 1, false, nprec))
1864 {
1865 cst2n = true;
1866 goto lt_expr;
1867 }
1868 if (!cst2n)
1869 sgnbit = wi::zero (nprec);
1870 }
1871 break;
1872
1873 case GE_EXPR:
1874 /* Minimum unsigned value for >= if (VAL & CST2) == VAL
1875 is VAL and maximum unsigned value is ~0. For signed
1876 comparison, if CST2 doesn't have most significant bit
1877 set, handle it similarly. If CST2 has MSB set,
1878 the minimum is the same, and maximum is ~0U/2. */
1879 if (minv != valv)
1880 {
1881 /* If (VAL & CST2) != VAL, X & CST2 can't be equal to
1882 VAL. */
1883 minv = masked_increment (valv, cst2v, sgnbit, nprec);
1884 if (minv == valv)
1885 break;
1886 }
1887 maxv = wi::mask (nprec - (cst2n ? 1 : 0), false, nprec);
1888 valid_p = true;
1889 break;
1890
1891 case GT_EXPR:
1892 gt_expr:
1893 /* Find out smallest MINV where MINV > VAL
1894 && (MINV & CST2) == MINV, if any. If VAL is signed and
1895 CST2 has MSB set, compute it biased by 1 << (nprec - 1). */
1896 minv = masked_increment (valv, cst2v, sgnbit, nprec);
1897 if (minv == valv)
1898 break;
1899 maxv = wi::mask (nprec - (cst2n ? 1 : 0), false, nprec);
1900 valid_p = true;
1901 break;
1902
1903 case LE_EXPR:
1904 /* Minimum unsigned value for <= is 0 and maximum
1905 unsigned value is VAL | ~CST2 if (VAL & CST2) == VAL.
1906 Otherwise, find smallest VAL2 where VAL2 > VAL
1907 && (VAL2 & CST2) == VAL2 and use (VAL2 - 1) | ~CST2
1908 as maximum.
1909 For signed comparison, if CST2 doesn't have most
1910 significant bit set, handle it similarly. If CST2 has
1911 MSB set, the maximum is the same and minimum is INT_MIN. */
1912 if (minv == valv)
1913 maxv = valv;
1914 else
1915 {
1916 maxv = masked_increment (valv, cst2v, sgnbit, nprec);
1917 if (maxv == valv)
1918 break;
1919 maxv -= 1;
1920 }
1921 maxv |= ~cst2v;
1922 minv = sgnbit;
1923 valid_p = true;
1924 break;
1925
1926 case LT_EXPR:
1927 lt_expr:
1928 /* Minimum unsigned value for < is 0 and maximum
1929 unsigned value is (VAL-1) | ~CST2 if (VAL & CST2) == VAL.
1930 Otherwise, find smallest VAL2 where VAL2 > VAL
1931 && (VAL2 & CST2) == VAL2 and use (VAL2 - 1) | ~CST2
1932 as maximum.
1933 For signed comparison, if CST2 doesn't have most
1934 significant bit set, handle it similarly. If CST2 has
1935 MSB set, the maximum is the same and minimum is INT_MIN. */
1936 if (minv == valv)
1937 {
1938 if (valv == sgnbit)
1939 break;
1940 maxv = valv;
1941 }
1942 else
1943 {
1944 maxv = masked_increment (valv, cst2v, sgnbit, nprec);
1945 if (maxv == valv)
1946 break;
1947 }
1948 maxv -= 1;
1949 maxv |= ~cst2v;
1950 minv = sgnbit;
1951 valid_p = true;
1952 break;
1953
1954 default:
1955 break;
1956 }
1957 if (valid_p
1958 && (maxv - minv) != -1)
1959 {
1960 tree tmp, new_val, type;
1961 int i;
1962
1963 for (i = 0; i < 2; i++)
1964 if (names[i])
1965 {
1966 wide_int maxv2 = maxv;
1967 tmp = names[i];
1968 type = TREE_TYPE (names[i])((contains_struct_check ((names[i]), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1968, __FUNCTION__))->typed.type)
;
1969 if (!TYPE_UNSIGNED (type)((tree_class_check ((type), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 1969, __FUNCTION__))->base.u.bits.unsigned_flag)
)
1970 {
1971 type = build_nonstandard_integer_type (nprec, 1);
1972 tmp = build1 (NOP_EXPR, type, names[i]);
1973 }
1974 if (minv != 0)
1975 {
1976 tmp = build2 (PLUS_EXPR, type, tmp,
1977 wide_int_to_tree (type, -minv));
1978 maxv2 = maxv - minv;
1979 }
1980 new_val = wide_int_to_tree (type, maxv2);
1981 add_assert_info (asserts, names[i], tmp, LE_EXPR, new_val);
1982 }
1983 }
1984 }
1985 }
1986}
1987
1988/* OP is an operand of a truth value expression which is known to have
1989 a particular value. Register any asserts for OP and for any
1990 operands in OP's defining statement.
1991
1992 If CODE is EQ_EXPR, then we want to register OP is zero (false),
1993 if CODE is NE_EXPR, then we want to register OP is nonzero (true). */
1994
1995static void
1996register_edge_assert_for_1 (tree op, enum tree_code code,
1997 edge e, vec<assert_info> &asserts)
1998{
1999 gimple *op_def;
2000 tree val;
2001 enum tree_code rhs_code;
2002
2003 /* We only care about SSA_NAMEs. */
2004 if (TREE_CODE (op)((enum tree_code) (op)->base.code) != SSA_NAME)
2005 return;
2006
2007 /* We know that OP will have a zero or nonzero value. */
2008 val = build_int_cst (TREE_TYPE (op)((contains_struct_check ((op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2008, __FUNCTION__))->typed.type)
, 0);
2009 add_assert_info (asserts, op, op, code, val);
2010
2011 /* Now look at how OP is set. If it's set from a comparison,
2012 a truth operation or some bit operations, then we may be able
2013 to register information about the operands of that assignment. */
2014 op_def = SSA_NAME_DEF_STMT (op)(tree_check ((op), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2014, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
2015 if (gimple_code (op_def) != GIMPLE_ASSIGN)
2016 return;
2017
2018 rhs_code = gimple_assign_rhs_code (op_def);
2019
2020 if (TREE_CODE_CLASS (rhs_code)tree_code_type[(int) (rhs_code)] == tcc_comparison)
2021 {
2022 bool invert = (code == EQ_EXPR ? true : false);
2023 tree op0 = gimple_assign_rhs1 (op_def);
2024 tree op1 = gimple_assign_rhs2 (op_def);
2025
2026 if (TREE_CODE (op0)((enum tree_code) (op0)->base.code) == SSA_NAME)
2027 register_edge_assert_for_2 (op0, e, rhs_code, op0, op1, invert, asserts);
2028 if (TREE_CODE (op1)((enum tree_code) (op1)->base.code) == SSA_NAME)
2029 register_edge_assert_for_2 (op1, e, rhs_code, op0, op1, invert, asserts);
2030 }
2031 else if ((code == NE_EXPR
2032 && gimple_assign_rhs_code (op_def) == BIT_AND_EXPR)
2033 || (code == EQ_EXPR
2034 && gimple_assign_rhs_code (op_def) == BIT_IOR_EXPR))
2035 {
2036 /* Recurse on each operand. */
2037 tree op0 = gimple_assign_rhs1 (op_def);
2038 tree op1 = gimple_assign_rhs2 (op_def);
2039 if (TREE_CODE (op0)((enum tree_code) (op0)->base.code) == SSA_NAME
2040 && has_single_use (op0))
2041 register_edge_assert_for_1 (op0, code, e, asserts);
2042 if (TREE_CODE (op1)((enum tree_code) (op1)->base.code) == SSA_NAME
2043 && has_single_use (op1))
2044 register_edge_assert_for_1 (op1, code, e, asserts);
2045 }
2046 else if (gimple_assign_rhs_code (op_def) == BIT_NOT_EXPR
2047 && TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (op_def)))((tree_class_check ((((contains_struct_check ((gimple_assign_lhs
(op_def)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2047, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2047, __FUNCTION__))->type_common.precision)
== 1)
2048 {
2049 /* Recurse, flipping CODE. */
2050 code = invert_tree_comparison (code, false);
2051 register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), code, e, asserts);
2052 }
2053 else if (gimple_assign_rhs_code (op_def) == SSA_NAME)
2054 {
2055 /* Recurse through the copy. */
2056 register_edge_assert_for_1 (gimple_assign_rhs1 (op_def), code, e, asserts);
2057 }
2058 else if (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (op_def))((gimple_assign_rhs_code (op_def)) == NOP_EXPR || (gimple_assign_rhs_code
(op_def)) == CONVERT_EXPR)
)
2059 {
2060 /* Recurse through the type conversion, unless it is a narrowing
2061 conversion or conversion from non-integral type. */
2062 tree rhs = gimple_assign_rhs1 (op_def);
2063 if (INTEGRAL_TYPE_P (TREE_TYPE (rhs))(((enum tree_code) (((contains_struct_check ((rhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2063, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((rhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2063, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((rhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2063, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
2064 && (TYPE_PRECISION (TREE_TYPE (rhs))((tree_class_check ((((contains_struct_check ((rhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2064, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2064, __FUNCTION__))->type_common.precision)
2065 <= TYPE_PRECISION (TREE_TYPE (op))((tree_class_check ((((contains_struct_check ((op), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2065, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2065, __FUNCTION__))->type_common.precision)
))
2066 register_edge_assert_for_1 (rhs, code, e, asserts);
2067 }
2068}
2069
2070/* Check if comparison
2071 NAME COND_OP INTEGER_CST
2072 has a form of
2073 (X & 11...100..0) COND_OP XX...X00...0
2074 Such comparison can yield assertions like
2075 X >= XX...X00...0
2076 X <= XX...X11...1
2077 in case of COND_OP being EQ_EXPR or
2078 X < XX...X00...0
2079 X > XX...X11...1
2080 in case of NE_EXPR. */
2081
2082static bool
2083is_masked_range_test (tree name, tree valt, enum tree_code cond_code,
2084 tree *new_name, tree *low, enum tree_code *low_code,
2085 tree *high, enum tree_code *high_code)
2086{
2087 gimple *def_stmt = SSA_NAME_DEF_STMT (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2087, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
2088
2089 if (!is_gimple_assign (def_stmt)
2090 || gimple_assign_rhs_code (def_stmt) != BIT_AND_EXPR)
2091 return false;
2092
2093 tree t = gimple_assign_rhs1 (def_stmt);
2094 tree maskt = gimple_assign_rhs2 (def_stmt);
2095 if (TREE_CODE (t)((enum tree_code) (t)->base.code) != SSA_NAME || TREE_CODE (maskt)((enum tree_code) (maskt)->base.code) != INTEGER_CST)
2096 return false;
2097
2098 wi::tree_to_wide_ref mask = wi::to_wide (maskt);
2099 wide_int inv_mask = ~mask;
2100 /* Must have been removed by now so don't bother optimizing. */
2101 if (mask == 0 || inv_mask == 0)
2102 return false;
2103
2104 /* Assume VALT is INTEGER_CST. */
2105 wi::tree_to_wide_ref val = wi::to_wide (valt);
2106
2107 if ((inv_mask & (inv_mask + 1)) != 0
2108 || (val & mask) != val)
2109 return false;
2110
2111 bool is_range = cond_code == EQ_EXPR;
2112
2113 tree type = TREE_TYPE (t)((contains_struct_check ((t), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2113, __FUNCTION__))->typed.type)
;
2114 wide_int min = wi::min_value (type),
2115 max = wi::max_value (type);
2116
2117 if (is_range)
2118 {
2119 *low_code = val == min ? ERROR_MARK : GE_EXPR;
2120 *high_code = val == max ? ERROR_MARK : LE_EXPR;
2121 }
2122 else
2123 {
2124 /* We can still generate assertion if one of alternatives
2125 is known to always be false. */
2126 if (val == min)
2127 {
2128 *low_code = (enum tree_code) 0;
2129 *high_code = GT_EXPR;
2130 }
2131 else if ((val | inv_mask) == max)
2132 {
2133 *low_code = LT_EXPR;
2134 *high_code = (enum tree_code) 0;
2135 }
2136 else
2137 return false;
2138 }
2139
2140 *new_name = t;
2141 *low = wide_int_to_tree (type, val);
2142 *high = wide_int_to_tree (type, val | inv_mask);
2143
2144 return true;
2145}
2146
2147/* Try to register an edge assertion for SSA name NAME on edge E for
2148 the condition COND contributing to the conditional jump pointed to by
2149 SI. */
2150
2151void
2152register_edge_assert_for (tree name, edge e,
2153 enum tree_code cond_code, tree cond_op0,
2154 tree cond_op1, vec<assert_info> &asserts)
2155{
2156 tree val;
2157 enum tree_code comp_code;
2158 bool is_else_edge = (e->flags & EDGE_FALSE_VALUE) != 0;
2159
2160 /* Do not attempt to infer anything in names that flow through
2161 abnormal edges. */
2162 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2162, __FUNCTION__, (SSA_NAME)))->base.asm_written_flag
)
2163 return;
2164
2165 if (!extract_code_and_val_from_cond_with_ops (name, cond_code,
2166 cond_op0, cond_op1,
2167 is_else_edge,
2168 &comp_code, &val))
2169 return;
2170
2171 /* Register ASSERT_EXPRs for name. */
2172 register_edge_assert_for_2 (name, e, cond_code, cond_op0,
2173 cond_op1, is_else_edge, asserts);
2174
2175
2176 /* If COND is effectively an equality test of an SSA_NAME against
2177 the value zero or one, then we may be able to assert values
2178 for SSA_NAMEs which flow into COND. */
2179
2180 /* In the case of NAME == 1 or NAME != 0, for BIT_AND_EXPR defining
2181 statement of NAME we can assert both operands of the BIT_AND_EXPR
2182 have nonzero value. */
2183 if (((comp_code == EQ_EXPR && integer_onep (val))
2184 || (comp_code == NE_EXPR && integer_zerop (val))))
2185 {
2186 gimple *def_stmt = SSA_NAME_DEF_STMT (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2186, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
2187
2188 if (is_gimple_assign (def_stmt)
2189 && gimple_assign_rhs_code (def_stmt) == BIT_AND_EXPR)
2190 {
2191 tree op0 = gimple_assign_rhs1 (def_stmt);
2192 tree op1 = gimple_assign_rhs2 (def_stmt);
2193 register_edge_assert_for_1 (op0, NE_EXPR, e, asserts);
2194 register_edge_assert_for_1 (op1, NE_EXPR, e, asserts);
2195 }
2196 }
2197
2198 /* In the case of NAME == 0 or NAME != 1, for BIT_IOR_EXPR defining
2199 statement of NAME we can assert both operands of the BIT_IOR_EXPR
2200 have zero value. */
2201 if (((comp_code == EQ_EXPR && integer_zerop (val))
2202 || (comp_code == NE_EXPR && integer_onep (val))))
2203 {
2204 gimple *def_stmt = SSA_NAME_DEF_STMT (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2204, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
2205
2206 /* For BIT_IOR_EXPR only if NAME == 0 both operands have
2207 necessarily zero value, or if type-precision is one. */
2208 if (is_gimple_assign (def_stmt)
2209 && (gimple_assign_rhs_code (def_stmt) == BIT_IOR_EXPR
2210 && (TYPE_PRECISION (TREE_TYPE (name))((tree_class_check ((((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2210, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2210, __FUNCTION__))->type_common.precision)
== 1
2211 || comp_code == EQ_EXPR)))
2212 {
2213 tree op0 = gimple_assign_rhs1 (def_stmt);
2214 tree op1 = gimple_assign_rhs2 (def_stmt);
2215 register_edge_assert_for_1 (op0, EQ_EXPR, e, asserts);
2216 register_edge_assert_for_1 (op1, EQ_EXPR, e, asserts);
2217 }
2218 }
2219
2220 /* Sometimes we can infer ranges from (NAME & MASK) == VALUE. */
2221 if ((comp_code == EQ_EXPR || comp_code == NE_EXPR)
2222 && TREE_CODE (val)((enum tree_code) (val)->base.code) == INTEGER_CST)
2223 {
2224 enum tree_code low_code, high_code;
2225 tree low, high;
2226 if (is_masked_range_test (name, val, comp_code, &name, &low,
2227 &low_code, &high, &high_code))
2228 {
2229 if (low_code != ERROR_MARK)
2230 register_edge_assert_for_2 (name, e, low_code, name,
2231 low, /*invert*/false, asserts);
2232 if (high_code != ERROR_MARK)
2233 register_edge_assert_for_2 (name, e, high_code, name,
2234 high, /*invert*/false, asserts);
2235 }
2236 }
2237}
2238
2239/* Handle
2240 _4 = x_3 & 31;
2241 if (_4 != 0)
2242 goto <bb 6>;
2243 else
2244 goto <bb 7>;
2245 <bb 6>:
2246 __builtin_unreachable ();
2247 <bb 7>:
2248 x_5 = ASSERT_EXPR <x_3, ...>;
2249 If x_3 has no other immediate uses (checked by caller),
2250 var is the x_3 var from ASSERT_EXPR, we can clear low 5 bits
2251 from the non-zero bitmask. */
2252
2253void
2254maybe_set_nonzero_bits (edge e, tree var)
2255{
2256 basic_block cond_bb = e->src;
2257 gimple *stmt = last_stmt (cond_bb);
2258 tree cst;
2259
2260 if (stmt == NULLnullptr
2261 || gimple_code (stmt) != GIMPLE_COND
2262 || gimple_cond_code (stmt) != ((e->flags & EDGE_TRUE_VALUE)
2263 ? EQ_EXPR : NE_EXPR)
2264 || TREE_CODE (gimple_cond_lhs (stmt))((enum tree_code) (gimple_cond_lhs (stmt))->base.code) != SSA_NAME
2265 || !integer_zerop (gimple_cond_rhs (stmt)))
2266 return;
2267
2268 stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (stmt))(tree_check ((gimple_cond_lhs (stmt)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2268, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
2269 if (!is_gimple_assign (stmt)
2270 || gimple_assign_rhs_code (stmt) != BIT_AND_EXPR
2271 || TREE_CODE (gimple_assign_rhs2 (stmt))((enum tree_code) (gimple_assign_rhs2 (stmt))->base.code) != INTEGER_CST)
2272 return;
2273 if (gimple_assign_rhs1 (stmt) != var)
2274 {
2275 gimple *stmt2;
2276
2277 if (TREE_CODE (gimple_assign_rhs1 (stmt))((enum tree_code) (gimple_assign_rhs1 (stmt))->base.code) != SSA_NAME)
2278 return;
2279 stmt2 = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt))(tree_check ((gimple_assign_rhs1 (stmt)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2279, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
2280 if (!gimple_assign_cast_p (stmt2)
2281 || gimple_assign_rhs1 (stmt2) != var
2282 || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt2))((gimple_assign_rhs_code (stmt2)) == NOP_EXPR || (gimple_assign_rhs_code
(stmt2)) == CONVERT_EXPR)
2283 || (TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt)))((tree_class_check ((((contains_struct_check ((gimple_assign_rhs1
(stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2283, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2283, __FUNCTION__))->type_common.precision)
2284 != TYPE_PRECISION (TREE_TYPE (var))((tree_class_check ((((contains_struct_check ((var), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2284, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2284, __FUNCTION__))->type_common.precision)
))
2285 return;
2286 }
2287 cst = gimple_assign_rhs2 (stmt);
2288 set_nonzero_bits (var, wi::bit_and_not (get_nonzero_bits (var),
2289 wi::to_wide (cst)));
2290}
2291
2292/* Return true if STMT is interesting for VRP. */
2293
2294bool
2295stmt_interesting_for_vrp (gimple *stmt)
2296{
2297 if (gimple_code (stmt) == GIMPLE_PHI)
2298 {
2299 tree res = gimple_phi_result (stmt);
2300 return (!virtual_operand_p (res)
2301 && (INTEGRAL_TYPE_P (TREE_TYPE (res))(((enum tree_code) (((contains_struct_check ((res), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2301, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((res), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2301, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((res), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2301, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
2302 || POINTER_TYPE_P (TREE_TYPE (res))(((enum tree_code) (((contains_struct_check ((res), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2302, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((res), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2302, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
));
2303 }
2304 else if (is_gimple_assign (stmt) || is_gimple_call (stmt))
2305 {
2306 tree lhs = gimple_get_lhs (stmt);
2307
2308 /* In general, assignments with virtual operands are not useful
2309 for deriving ranges, with the obvious exception of calls to
2310 builtin functions. */
2311 if (lhs && TREE_CODE (lhs)((enum tree_code) (lhs)->base.code) == SSA_NAME
2312 && (INTEGRAL_TYPE_P (TREE_TYPE (lhs))(((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2312, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2312, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2312, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
2313 || POINTER_TYPE_P (TREE_TYPE (lhs))(((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2313, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2313, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
)
2314 && (is_gimple_call (stmt)
2315 || !gimple_vuse (stmt)))
2316 return true;
2317 else if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
2318 switch (gimple_call_internal_fn (stmt))
2319 {
2320 case IFN_ADD_OVERFLOW:
2321 case IFN_SUB_OVERFLOW:
2322 case IFN_MUL_OVERFLOW:
2323 case IFN_ATOMIC_COMPARE_EXCHANGE:
2324 /* These internal calls return _Complex integer type,
2325 but are interesting to VRP nevertheless. */
2326 if (lhs && TREE_CODE (lhs)((enum tree_code) (lhs)->base.code) == SSA_NAME)
2327 return true;
2328 break;
2329 default:
2330 break;
2331 }
2332 }
2333 else if (gimple_code (stmt) == GIMPLE_COND
2334 || gimple_code (stmt) == GIMPLE_SWITCH)
2335 return true;
2336
2337 return false;
2338}
2339
2340
2341/* Return the LHS of any ASSERT_EXPR where OP appears as the first
2342 argument to the ASSERT_EXPR and in which the ASSERT_EXPR dominates
2343 BB. If no such ASSERT_EXPR is found, return OP. */
2344
2345static tree
2346lhs_of_dominating_assert (tree op, basic_block bb, gimple *stmt)
2347{
2348 imm_use_iterator imm_iter;
2349 gimple *use_stmt;
2350 use_operand_p use_p;
2351
2352 if (TREE_CODE (op)((enum tree_code) (op)->base.code) == SSA_NAME)
2353 {
2354 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)for ((use_p) = first_readonly_imm_use (&(imm_iter), (op))
; !end_readonly_imm_use_p (&(imm_iter)); (void) ((use_p) =
next_readonly_imm_use (&(imm_iter))))
2355 {
2356 use_stmt = USE_STMT (use_p)(use_p)->loc.stmt;
2357 if (use_stmt != stmt
2358 && gimple_assign_single_p (use_stmt)
2359 && TREE_CODE (gimple_assign_rhs1 (use_stmt))((enum tree_code) (gimple_assign_rhs1 (use_stmt))->base.code
)
== ASSERT_EXPR
2360 && TREE_OPERAND (gimple_assign_rhs1 (use_stmt), 0)(*((const_cast<tree*> (tree_operand_check ((gimple_assign_rhs1
(use_stmt)), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2360, __FUNCTION__)))))
== op
2361 && dominated_by_p (CDI_DOMINATORS, bb, gimple_bb (use_stmt)))
2362 return gimple_assign_lhs (use_stmt);
2363 }
2364 }
2365 return op;
2366}
2367
2368/* A hack. */
2369static class vr_values *x_vr_values;
2370
2371/* Searches the case label vector VEC for the index *IDX of the CASE_LABEL
2372 that includes the value VAL. The search is restricted to the range
2373 [START_IDX, n - 1] where n is the size of VEC.
2374
2375 If there is a CASE_LABEL for VAL, its index is placed in IDX and true is
2376 returned.
2377
2378 If there is no CASE_LABEL for VAL and there is one that is larger than VAL,
2379 it is placed in IDX and false is returned.
2380
2381 If VAL is larger than any CASE_LABEL, n is placed on IDX and false is
2382 returned. */
2383
2384bool
2385find_case_label_index (gswitch *stmt, size_t start_idx, tree val, size_t *idx)
2386{
2387 size_t n = gimple_switch_num_labels (stmt);
2388 size_t low, high;
2389
2390 /* Find case label for minimum of the value range or the next one.
2391 At each iteration we are searching in [low, high - 1]. */
2392
2393 for (low = start_idx, high = n; high != low; )
2394 {
2395 tree t;
2396 int cmp;
2397 /* Note that i != high, so we never ask for n. */
2398 size_t i = (high + low) / 2;
2399 t = gimple_switch_label (stmt, i);
2400
2401 /* Cache the result of comparing CASE_LOW and val. */
2402 cmp = tree_int_cst_compare (CASE_LOW (t)(*((const_cast<tree*> (tree_operand_check (((tree_check
((t), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2402, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2402, __FUNCTION__)))))
, val);
2403
2404 if (cmp == 0)
2405 {
2406 /* Ranges cannot be empty. */
2407 *idx = i;
2408 return true;
2409 }
2410 else if (cmp > 0)
2411 high = i;
2412 else
2413 {
2414 low = i + 1;
2415 if (CASE_HIGH (t)(*((const_cast<tree*> (tree_operand_check (((tree_check
((t), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2415, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2415, __FUNCTION__)))))
!= NULLnullptr
2416 && tree_int_cst_compare (CASE_HIGH (t)(*((const_cast<tree*> (tree_operand_check (((tree_check
((t), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2416, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2416, __FUNCTION__)))))
, val) >= 0)
2417 {
2418 *idx = i;
2419 return true;
2420 }
2421 }
2422 }
2423
2424 *idx = high;
2425 return false;
2426}
2427
2428/* Searches the case label vector VEC for the range of CASE_LABELs that is used
2429 for values between MIN and MAX. The first index is placed in MIN_IDX. The
2430 last index is placed in MAX_IDX. If the range of CASE_LABELs is empty
2431 then MAX_IDX < MIN_IDX.
2432 Returns true if the default label is not needed. */
2433
2434bool
2435find_case_label_range (gswitch *stmt, tree min, tree max, size_t *min_idx,
2436 size_t *max_idx)
2437{
2438 size_t i, j;
2439 bool min_take_default = !find_case_label_index (stmt, 1, min, &i);
2440 bool max_take_default = !find_case_label_index (stmt, i, max, &j);
2441
2442 if (i == j
2443 && min_take_default
2444 && max_take_default)
2445 {
2446 /* Only the default case label reached.
2447 Return an empty range. */
2448 *min_idx = 1;
2449 *max_idx = 0;
2450 return false;
2451 }
2452 else
2453 {
2454 bool take_default = min_take_default || max_take_default;
2455 tree low, high;
2456 size_t k;
2457
2458 if (max_take_default)
2459 j--;
2460
2461 /* If the case label range is continuous, we do not need
2462 the default case label. Verify that. */
2463 high = CASE_LOW (gimple_switch_label (stmt, i))(*((const_cast<tree*> (tree_operand_check (((tree_check
((gimple_switch_label (stmt, i)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2463, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2463, __FUNCTION__)))))
;
2464 if (CASE_HIGH (gimple_switch_label (stmt, i))(*((const_cast<tree*> (tree_operand_check (((tree_check
((gimple_switch_label (stmt, i)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2464, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2464, __FUNCTION__)))))
)
2465 high = CASE_HIGH (gimple_switch_label (stmt, i))(*((const_cast<tree*> (tree_operand_check (((tree_check
((gimple_switch_label (stmt, i)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2465, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2465, __FUNCTION__)))))
;
2466 for (k = i + 1; k <= j; ++k)
2467 {
2468 low = CASE_LOW (gimple_switch_label (stmt, k))(*((const_cast<tree*> (tree_operand_check (((tree_check
((gimple_switch_label (stmt, k)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2468, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2468, __FUNCTION__)))))
;
2469 if (!integer_onep (int_const_binop (MINUS_EXPR, low, high)))
2470 {
2471 take_default = true;
2472 break;
2473 }
2474 high = low;
2475 if (CASE_HIGH (gimple_switch_label (stmt, k))(*((const_cast<tree*> (tree_operand_check (((tree_check
((gimple_switch_label (stmt, k)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2475, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2475, __FUNCTION__)))))
)
2476 high = CASE_HIGH (gimple_switch_label (stmt, k))(*((const_cast<tree*> (tree_operand_check (((tree_check
((gimple_switch_label (stmt, k)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2476, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2476, __FUNCTION__)))))
;
2477 }
2478
2479 *min_idx = i;
2480 *max_idx = j;
2481 return !take_default;
2482 }
2483}
2484
2485/* Given a SWITCH_STMT, return the case label that encompasses the
2486 known possible values for the switch operand. RANGE_OF_OP is a
2487 range for the known values of the switch operand. */
2488
2489tree
2490find_case_label_range (gswitch *switch_stmt, const irange *range_of_op)
2491{
2492 if (range_of_op->undefined_p ()
2493 || range_of_op->varying_p ()
2494 || range_of_op->symbolic_p ())
2495 return NULL_TREE(tree) nullptr;
2496
2497 size_t i, j;
2498 tree op = gimple_switch_index (switch_stmt);
2499 tree type = TREE_TYPE (op)((contains_struct_check ((op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2499, __FUNCTION__))->typed.type)
;
2500 tree tmin = wide_int_to_tree (type, range_of_op->lower_bound ());
2501 tree tmax = wide_int_to_tree (type, range_of_op->upper_bound ());
2502 find_case_label_range (switch_stmt, tmin, tmax, &i, &j);
2503 if (i == j)
2504 {
2505 /* Look for exactly one label that encompasses the range of
2506 the operand. */
2507 tree label = gimple_switch_label (switch_stmt, i);
2508 tree case_high
2509 = CASE_HIGH (label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2509, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2509, __FUNCTION__)))))
? CASE_HIGH (label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2509, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2509, __FUNCTION__)))))
: CASE_LOW (label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2509, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2509, __FUNCTION__)))))
;
2510 int_range_max label_range (CASE_LOW (label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2510, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2510, __FUNCTION__)))))
, case_high);
2511 if (!types_compatible_p (label_range.type (), range_of_op->type ()))
2512 range_cast (label_range, range_of_op->type ());
2513 label_range.intersect (range_of_op);
2514 if (label_range == *range_of_op)
2515 return label;
2516 }
2517 else if (i > j)
2518 {
2519 /* If there are no labels at all, take the default. */
2520 return gimple_switch_label (switch_stmt, 0);
2521 }
2522 else
2523 {
2524 /* Otherwise, there are various labels that can encompass
2525 the range of operand. In which case, see if the range of
2526 the operand is entirely *outside* the bounds of all the
2527 (non-default) case labels. If so, take the default. */
2528 unsigned n = gimple_switch_num_labels (switch_stmt);
2529 tree min_label = gimple_switch_label (switch_stmt, 1);
2530 tree max_label = gimple_switch_label (switch_stmt, n - 1);
2531 tree case_high = CASE_HIGH (max_label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((max_label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2531, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2531, __FUNCTION__)))))
;
2532 if (!case_high)
2533 case_high = CASE_LOW (max_label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((max_label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2533, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2533, __FUNCTION__)))))
;
2534 int_range_max label_range (CASE_LOW (min_label)(*((const_cast<tree*> (tree_operand_check (((tree_check
((min_label), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2534, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2534, __FUNCTION__)))))
, case_high);
2535 if (!types_compatible_p (label_range.type (), range_of_op->type ()))
2536 range_cast (label_range, range_of_op->type ());
2537 label_range.intersect (range_of_op);
2538 if (label_range.undefined_p ())
2539 return gimple_switch_label (switch_stmt, 0);
2540 }
2541 return NULL_TREE(tree) nullptr;
2542}
2543
2544struct case_info
2545{
2546 tree expr;
2547 basic_block bb;
2548};
2549
2550/* Location information for ASSERT_EXPRs. Each instance of this
2551 structure describes an ASSERT_EXPR for an SSA name. Since a single
2552 SSA name may have more than one assertion associated with it, these
2553 locations are kept in a linked list attached to the corresponding
2554 SSA name. */
2555struct assert_locus
2556{
2557 /* Basic block where the assertion would be inserted. */
2558 basic_block bb;
2559
2560 /* Some assertions need to be inserted on an edge (e.g., assertions
2561 generated by COND_EXPRs). In those cases, BB will be NULL. */
2562 edge e;
2563
2564 /* Pointer to the statement that generated this assertion. */
2565 gimple_stmt_iterator si;
2566
2567 /* Predicate code for the ASSERT_EXPR. Must be COMPARISON_CLASS_P. */
2568 enum tree_code comp_code;
2569
2570 /* Value being compared against. */
2571 tree val;
2572
2573 /* Expression to compare. */
2574 tree expr;
2575
2576 /* Next node in the linked list. */
2577 assert_locus *next;
2578};
2579
2580/* Class to traverse the flowgraph looking for conditional jumps to
2581 insert ASSERT_EXPR range expressions. These range expressions are
2582 meant to provide information to optimizations that need to reason
2583 in terms of value ranges. They will not be expanded into RTL. */
2584
2585class vrp_asserts
2586{
2587public:
2588 vrp_asserts (struct function *fn) : fun (fn) { }
2589
2590 void insert_range_assertions ();
2591
2592 /* Convert range assertion expressions into the implied copies and
2593 copy propagate away the copies. */
2594 void remove_range_assertions ();
2595
2596 /* Dump all the registered assertions for all the names to FILE. */
2597 void dump (FILE *);
2598
2599 /* Dump all the registered assertions for NAME to FILE. */
2600 void dump (FILE *file, tree name);
2601
2602 /* Dump all the registered assertions for NAME to stderr. */
2603 void debug (tree name)
2604 {
2605 dump (stderrstderr, name);
2606 }
2607
2608 /* Dump all the registered assertions for all the names to stderr. */
2609 void debug ()
2610 {
2611 dump (stderrstderr);
2612 }
2613
2614private:
2615 /* Set of SSA names found live during the RPO traversal of the function
2616 for still active basic-blocks. */
2617 live_names live;
2618
2619 /* Function to work on. */
2620 struct function *fun;
2621
2622 /* If bit I is present, it means that SSA name N_i has a list of
2623 assertions that should be inserted in the IL. */
2624 bitmap need_assert_for;
2625
2626 /* Array of locations lists where to insert assertions. ASSERTS_FOR[I]
2627 holds a list of ASSERT_LOCUS_T nodes that describe where
2628 ASSERT_EXPRs for SSA name N_I should be inserted. */
2629 assert_locus **asserts_for;
2630
2631 /* Finish found ASSERTS for E and register them at GSI. */
2632 void finish_register_edge_assert_for (edge e, gimple_stmt_iterator gsi,
2633 vec<assert_info> &asserts);
2634
2635 /* Determine whether the outgoing edges of BB should receive an
2636 ASSERT_EXPR for each of the operands of BB's LAST statement. The
2637 last statement of BB must be a SWITCH_EXPR.
2638
2639 If any of the sub-graphs rooted at BB have an interesting use of
2640 the predicate operands, an assert location node is added to the
2641 list of assertions for the corresponding operands. */
2642 void find_switch_asserts (basic_block bb, gswitch *last);
2643
2644 /* Do an RPO walk over the function computing SSA name liveness
2645 on-the-fly and deciding on assert expressions to insert. */
2646 void find_assert_locations ();
2647
2648 /* Traverse all the statements in block BB looking for statements that
2649 may generate useful assertions for the SSA names in their operand.
2650 See method implementation comentary for more information. */
2651 void find_assert_locations_in_bb (basic_block bb);
2652
2653 /* Determine whether the outgoing edges of BB should receive an
2654 ASSERT_EXPR for each of the operands of BB's LAST statement.
2655 The last statement of BB must be a COND_EXPR.
2656
2657 If any of the sub-graphs rooted at BB have an interesting use of
2658 the predicate operands, an assert location node is added to the
2659 list of assertions for the corresponding operands. */
2660 void find_conditional_asserts (basic_block bb, gcond *last);
2661
2662 /* Process all the insertions registered for every name N_i registered
2663 in NEED_ASSERT_FOR. The list of assertions to be inserted are
2664 found in ASSERTS_FOR[i]. */
2665 void process_assert_insertions ();
2666
2667 /* If NAME doesn't have an ASSERT_EXPR registered for asserting
2668 'EXPR COMP_CODE VAL' at a location that dominates block BB or
2669 E->DEST, then register this location as a possible insertion point
2670 for ASSERT_EXPR <NAME, EXPR COMP_CODE VAL>.
2671
2672 BB, E and SI provide the exact insertion point for the new
2673 ASSERT_EXPR. If BB is NULL, then the ASSERT_EXPR is to be inserted
2674 on edge E. Otherwise, if E is NULL, the ASSERT_EXPR is inserted on
2675 BB. If SI points to a COND_EXPR or a SWITCH_EXPR statement, then E
2676 must not be NULL. */
2677 void register_new_assert_for (tree name, tree expr,
2678 enum tree_code comp_code,
2679 tree val, basic_block bb,
2680 edge e, gimple_stmt_iterator si);
2681
2682 /* Given a COND_EXPR COND of the form 'V OP W', and an SSA name V,
2683 create a new SSA name N and return the assertion assignment
2684 'N = ASSERT_EXPR <V, V OP W>'. */
2685 gimple *build_assert_expr_for (tree cond, tree v);
2686
2687 /* Create an ASSERT_EXPR for NAME and insert it in the location
2688 indicated by LOC. Return true if we made any edge insertions. */
2689 bool process_assert_insertions_for (tree name, assert_locus *loc);
2690
2691 /* Qsort callback for sorting assert locations. */
2692 template <bool stable> static int compare_assert_loc (const void *,
2693 const void *);
2694
2695 /* Return false if EXPR is a predicate expression involving floating
2696 point values. */
2697 bool fp_predicate (gimple *stmt)
2698 {
2699 GIMPLE_CHECK (stmt, GIMPLE_COND)do { const gimple *__gs = (stmt); if (gimple_code (__gs) != (
GIMPLE_COND)) gimple_check_failed (__gs, "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2699, __FUNCTION__, (GIMPLE_COND), ERROR_MARK); } while (0)
;
2700 return FLOAT_TYPE_P (TREE_TYPE (gimple_cond_lhs (stmt)))((((enum tree_code) (((contains_struct_check ((gimple_cond_lhs
(stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2700, __FUNCTION__))->typed.type))->base.code) == REAL_TYPE
) || ((((enum tree_code) (((contains_struct_check ((gimple_cond_lhs
(stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2700, __FUNCTION__))->typed.type))->base.code) == COMPLEX_TYPE
|| (((enum tree_code) (((contains_struct_check ((gimple_cond_lhs
(stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2700, __FUNCTION__))->typed.type))->base.code) == VECTOR_TYPE
)) && (((enum tree_code) (((contains_struct_check (((
(contains_struct_check ((gimple_cond_lhs (stmt)), (TS_TYPED),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2700, __FUNCTION__))->typed.type)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2700, __FUNCTION__))->typed.type))->base.code) == REAL_TYPE
)))
;
2701 }
2702
2703 bool all_imm_uses_in_stmt_or_feed_cond (tree var, gimple *stmt,
2704 basic_block cond_bb);
2705
2706 static int compare_case_labels (const void *, const void *);
2707};
2708
2709/* Given a COND_EXPR COND of the form 'V OP W', and an SSA name V,
2710 create a new SSA name N and return the assertion assignment
2711 'N = ASSERT_EXPR <V, V OP W>'. */
2712
2713gimple *
2714vrp_asserts::build_assert_expr_for (tree cond, tree v)
2715{
2716 tree a;
2717 gassign *assertion;
2718
2719 gcc_assert (TREE_CODE (v) == SSA_NAME((void)(!(((enum tree_code) (v)->base.code) == SSA_NAME &&
(tree_code_type[(int) (((enum tree_code) (cond)->base.code
))] == tcc_comparison)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2720, __FUNCTION__), 0 : 0))
2720 && COMPARISON_CLASS_P (cond))((void)(!(((enum tree_code) (v)->base.code) == SSA_NAME &&
(tree_code_type[(int) (((enum tree_code) (cond)->base.code
))] == tcc_comparison)) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2720, __FUNCTION__), 0 : 0))
;
2721
2722 a = build2 (ASSERT_EXPR, TREE_TYPE (v)((contains_struct_check ((v), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2722, __FUNCTION__))->typed.type)
, v, cond);
2723 assertion = gimple_build_assign (NULL_TREE(tree) nullptr, a);
2724
2725 /* The new ASSERT_EXPR, creates a new SSA name that replaces the
2726 operand of the ASSERT_EXPR. Create it so the new name and the old one
2727 are registered in the replacement table so that we can fix the SSA web
2728 after adding all the ASSERT_EXPRs. */
2729 tree new_def = create_new_def_for (v, assertion, NULLnullptr);
2730 /* Make sure we preserve abnormalness throughout an ASSERT_EXPR chain
2731 given we have to be able to fully propagate those out to re-create
2732 valid SSA when removing the asserts. */
2733 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (v)(tree_check ((v), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2733, __FUNCTION__, (SSA_NAME)))->base.asm_written_flag
)
2734 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_def)(tree_check ((new_def), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2734, __FUNCTION__, (SSA_NAME)))->base.asm_written_flag
= 1;
2735
2736 return assertion;
2737}
2738
2739/* Dump all the registered assertions for NAME to FILE. */
2740
2741void
2742vrp_asserts::dump (FILE *file, tree name)
2743{
2744 assert_locus *loc;
2745
2746 fprintf (file, "Assertions to be inserted for ");
2747 print_generic_expr (file, name);
2748 fprintf (file, "\n");
2749
2750 loc = asserts_for[SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2750, __FUNCTION__, (SSA_NAME)))->base.u.version
];
2751 while (loc)
2752 {
2753 fprintf (file, "\t");
2754 print_gimple_stmt (file, gsi_stmt (loc->si), 0);
2755 fprintf (file, "\n\tBB #%d", loc->bb->index);
2756 if (loc->e)
2757 {
2758 fprintf (file, "\n\tEDGE %d->%d", loc->e->src->index,
2759 loc->e->dest->index);
2760 dump_edge_info (file, loc->e, dump_flags, 0);
2761 }
2762 fprintf (file, "\n\tPREDICATE: ");
2763 print_generic_expr (file, loc->expr);
2764 fprintf (file, " %s ", get_tree_code_name (loc->comp_code));
2765 print_generic_expr (file, loc->val);
2766 fprintf (file, "\n\n");
2767 loc = loc->next;
2768 }
2769
2770 fprintf (file, "\n");
2771}
2772
2773/* Dump all the registered assertions for all the names to FILE. */
2774
2775void
2776vrp_asserts::dump (FILE *file)
2777{
2778 unsigned i;
2779 bitmap_iterator bi;
2780
2781 fprintf (file, "\nASSERT_EXPRs to be inserted\n\n");
2782 EXECUTE_IF_SET_IN_BITMAP (need_assert_for, 0, i, bi)for (bmp_iter_set_init (&(bi), (need_assert_for), (0), &
(i)); bmp_iter_set (&(bi), &(i)); bmp_iter_next (&
(bi), &(i)))
2783 dump (file, ssa_name (i)((*(cfun + 0)->gimple_df->ssa_names)[(i)]));
2784 fprintf (file, "\n");
2785}
2786
2787/* If NAME doesn't have an ASSERT_EXPR registered for asserting
2788 'EXPR COMP_CODE VAL' at a location that dominates block BB or
2789 E->DEST, then register this location as a possible insertion point
2790 for ASSERT_EXPR <NAME, EXPR COMP_CODE VAL>.
2791
2792 BB, E and SI provide the exact insertion point for the new
2793 ASSERT_EXPR. If BB is NULL, then the ASSERT_EXPR is to be inserted
2794 on edge E. Otherwise, if E is NULL, the ASSERT_EXPR is inserted on
2795 BB. If SI points to a COND_EXPR or a SWITCH_EXPR statement, then E
2796 must not be NULL. */
2797
2798void
2799vrp_asserts::register_new_assert_for (tree name, tree expr,
2800 enum tree_code comp_code,
2801 tree val,
2802 basic_block bb,
2803 edge e,
2804 gimple_stmt_iterator si)
2805{
2806 assert_locus *n, *loc, *last_loc;
2807 basic_block dest_bb;
2808
2809 gcc_checking_assert (bb == NULL || e == NULL)((void)(!(bb == nullptr || e == nullptr) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2809, __FUNCTION__), 0 : 0))
;
2810
2811 if (e == NULLnullptr)
2812 gcc_checking_assert (gimple_code (gsi_stmt (si)) != GIMPLE_COND((void)(!(gimple_code (gsi_stmt (si)) != GIMPLE_COND &&
gimple_code (gsi_stmt (si)) != GIMPLE_SWITCH) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2813, __FUNCTION__), 0 : 0))
2813 && gimple_code (gsi_stmt (si)) != GIMPLE_SWITCH)((void)(!(gimple_code (gsi_stmt (si)) != GIMPLE_COND &&
gimple_code (gsi_stmt (si)) != GIMPLE_SWITCH) ? fancy_abort (
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2813, __FUNCTION__), 0 : 0))
;
2814
2815 /* Never build an assert comparing against an integer constant with
2816 TREE_OVERFLOW set. This confuses our undefined overflow warning
2817 machinery. */
2818 if (TREE_OVERFLOW_P (val)((tree_code_type[(int) (((enum tree_code) (val)->base.code
))] == tcc_constant) && ((tree_class_check ((val), (tcc_constant
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2818, __FUNCTION__))->base.public_flag))
)
2819 val = drop_tree_overflow (val);
2820
2821 /* The new assertion A will be inserted at BB or E. We need to
2822 determine if the new location is dominated by a previously
2823 registered location for A. If we are doing an edge insertion,
2824 assume that A will be inserted at E->DEST. Note that this is not
2825 necessarily true.
2826
2827 If E is a critical edge, it will be split. But even if E is
2828 split, the new block will dominate the same set of blocks that
2829 E->DEST dominates.
2830
2831 The reverse, however, is not true, blocks dominated by E->DEST
2832 will not be dominated by the new block created to split E. So,
2833 if the insertion location is on a critical edge, we will not use
2834 the new location to move another assertion previously registered
2835 at a block dominated by E->DEST. */
2836 dest_bb = (bb) ? bb : e->dest;
2837
2838 /* If NAME already has an ASSERT_EXPR registered for COMP_CODE and
2839 VAL at a block dominating DEST_BB, then we don't need to insert a new
2840 one. Similarly, if the same assertion already exists at a block
2841 dominated by DEST_BB and the new location is not on a critical
2842 edge, then update the existing location for the assertion (i.e.,
2843 move the assertion up in the dominance tree).
2844
2845 Note, this is implemented as a simple linked list because there
2846 should not be more than a handful of assertions registered per
2847 name. If this becomes a performance problem, a table hashed by
2848 COMP_CODE and VAL could be implemented. */
2849 loc = asserts_for[SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2849, __FUNCTION__, (SSA_NAME)))->base.u.version
];
2850 last_loc = loc;
2851 while (loc)
2852 {
2853 if (loc->comp_code == comp_code
2854 && (loc->val == val
2855 || operand_equal_p (loc->val, val, 0))
2856 && (loc->expr == expr
2857 || operand_equal_p (loc->expr, expr, 0)))
2858 {
2859 /* If E is not a critical edge and DEST_BB
2860 dominates the existing location for the assertion, move
2861 the assertion up in the dominance tree by updating its
2862 location information. */
2863 if ((e == NULLnullptr || !EDGE_CRITICAL_P (e)(vec_safe_length ((e)->src->succs) >= 2 && vec_safe_length
((e)->dest->preds) >= 2)
)
2864 && dominated_by_p (CDI_DOMINATORS, loc->bb, dest_bb))
2865 {
2866 loc->bb = dest_bb;
2867 loc->e = e;
2868 loc->si = si;
2869 return;
2870 }
2871 }
2872
2873 /* Update the last node of the list and move to the next one. */
2874 last_loc = loc;
2875 loc = loc->next;
2876 }
2877
2878 /* If we didn't find an assertion already registered for
2879 NAME COMP_CODE VAL, add a new one at the end of the list of
2880 assertions associated with NAME. */
2881 n = XNEW (struct assert_locus)((struct assert_locus *) xmalloc (sizeof (struct assert_locus
)))
;
2882 n->bb = dest_bb;
2883 n->e = e;
2884 n->si = si;
2885 n->comp_code = comp_code;
2886 n->val = val;
2887 n->expr = expr;
2888 n->next = NULLnullptr;
2889
2890 if (last_loc)
2891 last_loc->next = n;
2892 else
2893 asserts_for[SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2893, __FUNCTION__, (SSA_NAME)))->base.u.version
] = n;
2894
2895 bitmap_set_bit (need_assert_for, SSA_NAME_VERSION (name)(tree_check ((name), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2895, __FUNCTION__, (SSA_NAME)))->base.u.version
);
2896}
2897
2898/* Finish found ASSERTS for E and register them at GSI. */
2899
2900void
2901vrp_asserts::finish_register_edge_assert_for (edge e,
2902 gimple_stmt_iterator gsi,
2903 vec<assert_info> &asserts)
2904{
2905 for (unsigned i = 0; i < asserts.length (); ++i)
2906 /* Only register an ASSERT_EXPR if NAME was found in the sub-graph
2907 reachable from E. */
2908 if (live.live_on_edge_p (asserts[i].name, e))
2909 register_new_assert_for (asserts[i].name, asserts[i].expr,
2910 asserts[i].comp_code, asserts[i].val,
2911 NULLnullptr, e, gsi);
2912}
2913
2914/* Determine whether the outgoing edges of BB should receive an
2915 ASSERT_EXPR for each of the operands of BB's LAST statement.
2916 The last statement of BB must be a COND_EXPR.
2917
2918 If any of the sub-graphs rooted at BB have an interesting use of
2919 the predicate operands, an assert location node is added to the
2920 list of assertions for the corresponding operands. */
2921
2922void
2923vrp_asserts::find_conditional_asserts (basic_block bb, gcond *last)
2924{
2925 gimple_stmt_iterator bsi;
2926 tree op;
2927 edge_iterator ei;
2928 edge e;
2929 ssa_op_iter iter;
2930
2931 bsi = gsi_for_stmt (last);
2932
2933 /* Look for uses of the operands in each of the sub-graphs
2934 rooted at BB. We need to check each of the outgoing edges
2935 separately, so that we know what kind of ASSERT_EXPR to
2936 insert. */
2937 FOR_EACH_EDGE (e, ei, bb->succs)for ((ei) = ei_start_1 (&((bb->succs))); ei_cond ((ei)
, &(e)); ei_next (&(ei)))
2938 {
2939 if (e->dest == bb)
2940 continue;
2941
2942 /* Register the necessary assertions for each operand in the
2943 conditional predicate. */
2944 auto_vec<assert_info, 8> asserts;
2945 FOR_EACH_SSA_TREE_OPERAND (op, last, iter, SSA_OP_USE)for (op = op_iter_init_tree (&(iter), last, 0x01); !op_iter_done
(&(iter)); (void) (op = op_iter_next_tree (&(iter)))
)
2946 register_edge_assert_for (op, e,
2947 gimple_cond_code (last),
2948 gimple_cond_lhs (last),
2949 gimple_cond_rhs (last), asserts);
2950 finish_register_edge_assert_for (e, bsi, asserts);
2951 }
2952}
2953
2954/* Compare two case labels sorting first by the destination bb index
2955 and then by the case value. */
2956
2957int
2958vrp_asserts::compare_case_labels (const void *p1, const void *p2)
2959{
2960 const struct case_info *ci1 = (const struct case_info *) p1;
2961 const struct case_info *ci2 = (const struct case_info *) p2;
2962 int idx1 = ci1->bb->index;
2963 int idx2 = ci2->bb->index;
2964
2965 if (idx1 < idx2)
2966 return -1;
2967 else if (idx1 == idx2)
2968 {
2969 /* Make sure the default label is first in a group. */
2970 if (!CASE_LOW (ci1->expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci1->expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2970, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2970, __FUNCTION__)))))
)
2971 return -1;
2972 else if (!CASE_LOW (ci2->expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci2->expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2972, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2972, __FUNCTION__)))))
)
2973 return 1;
2974 else
2975 return tree_int_cst_compare (CASE_LOW (ci1->expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci1->expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2975, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2975, __FUNCTION__)))))
,
2976 CASE_LOW (ci2->expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci2->expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2976, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 2976, __FUNCTION__)))))
);
2977 }
2978 else
2979 return 1;
2980}
2981
2982/* Determine whether the outgoing edges of BB should receive an
2983 ASSERT_EXPR for each of the operands of BB's LAST statement.
2984 The last statement of BB must be a SWITCH_EXPR.
2985
2986 If any of the sub-graphs rooted at BB have an interesting use of
2987 the predicate operands, an assert location node is added to the
2988 list of assertions for the corresponding operands. */
2989
2990void
2991vrp_asserts::find_switch_asserts (basic_block bb, gswitch *last)
2992{
2993 gimple_stmt_iterator bsi;
2994 tree op;
2995 edge e;
2996 struct case_info *ci;
2997 size_t n = gimple_switch_num_labels (last);
2998#if GCC_VERSION(4 * 1000 + 2) >= 4000
2999 unsigned int idx;
3000#else
3001 /* Work around GCC 3.4 bug (PR 37086). */
3002 volatile unsigned int idx;
3003#endif
3004
3005 bsi = gsi_for_stmt (last);
3006 op = gimple_switch_index (last);
3007 if (TREE_CODE (op)((enum tree_code) (op)->base.code) != SSA_NAME)
3008 return;
3009
3010 /* Build a vector of case labels sorted by destination label. */
3011 ci = XNEWVEC (struct case_info, n)((struct case_info *) xmalloc (sizeof (struct case_info) * (n
)))
;
3012 for (idx = 0; idx < n; ++idx)
3013 {
3014 ci[idx].expr = gimple_switch_label (last, idx);
3015 ci[idx].bb = label_to_block (fun, CASE_LABEL (ci[idx].expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci[idx].expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3015, __FUNCTION__, (CASE_LABEL_EXPR)))), (2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3015, __FUNCTION__)))))
);
3016 }
3017 edge default_edge = find_edge (bb, ci[0].bb);
3018 qsort (ci, n, sizeof (struct case_info), compare_case_labels)gcc_qsort (ci, n, sizeof (struct case_info), compare_case_labels
)
;
3019
3020 for (idx = 0; idx < n; ++idx)
3021 {
3022 tree min, max;
3023 tree cl = ci[idx].expr;
3024 basic_block cbb = ci[idx].bb;
3025
3026 min = CASE_LOW (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3026, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3026, __FUNCTION__)))))
;
3027 max = CASE_HIGH (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3027, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3027, __FUNCTION__)))))
;
3028
3029 /* If there are multiple case labels with the same destination
3030 we need to combine them to a single value range for the edge. */
3031 if (idx + 1 < n && cbb == ci[idx + 1].bb)
3032 {
3033 /* Skip labels until the last of the group. */
3034 do {
3035 ++idx;
3036 } while (idx < n && cbb == ci[idx].bb);
3037 --idx;
3038
3039 /* Pick up the maximum of the case label range. */
3040 if (CASE_HIGH (ci[idx].expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci[idx].expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3040, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3040, __FUNCTION__)))))
)
3041 max = CASE_HIGH (ci[idx].expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci[idx].expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3041, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3041, __FUNCTION__)))))
;
3042 else
3043 max = CASE_LOW (ci[idx].expr)(*((const_cast<tree*> (tree_operand_check (((tree_check
((ci[idx].expr), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3043, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3043, __FUNCTION__)))))
;
3044 }
3045
3046 /* Can't extract a useful assertion out of a range that includes the
3047 default label. */
3048 if (min == NULL_TREE(tree) nullptr)
3049 continue;
3050
3051 /* Find the edge to register the assert expr on. */
3052 e = find_edge (bb, cbb);
3053
3054 /* Register the necessary assertions for the operand in the
3055 SWITCH_EXPR. */
3056 auto_vec<assert_info, 8> asserts;
3057 register_edge_assert_for (op, e,
3058 max ? GE_EXPR : EQ_EXPR,
3059 op, fold_convert (TREE_TYPE (op), min)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3059, __FUNCTION__))->typed.type), min)
,
3060 asserts);
3061 if (max)
3062 register_edge_assert_for (op, e, LE_EXPR, op,
3063 fold_convert (TREE_TYPE (op), max)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3063, __FUNCTION__))->typed.type), max)
,
3064 asserts);
3065 finish_register_edge_assert_for (e, bsi, asserts);
3066 }
3067
3068 XDELETEVEC (ci)free ((void*) (ci));
3069
3070 if (!live.live_on_edge_p (op, default_edge))
3071 return;
3072
3073 /* Now register along the default label assertions that correspond to the
3074 anti-range of each label. */
3075 int insertion_limit = param_max_vrp_switch_assertionsglobal_options.x_param_max_vrp_switch_assertions;
3076 if (insertion_limit == 0)
3077 return;
3078
3079 /* We can't do this if the default case shares a label with another case. */
3080 tree default_cl = gimple_switch_default_label (last);
3081 for (idx = 1; idx < n; idx++)
3082 {
3083 tree min, max;
3084 tree cl = gimple_switch_label (last, idx);
3085 if (CASE_LABEL (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3085, __FUNCTION__, (CASE_LABEL_EXPR)))), (2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3085, __FUNCTION__)))))
== CASE_LABEL (default_cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((default_cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3085, __FUNCTION__, (CASE_LABEL_EXPR)))), (2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3085, __FUNCTION__)))))
)
3086 continue;
3087
3088 min = CASE_LOW (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3088, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3088, __FUNCTION__)))))
;
3089 max = CASE_HIGH (cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3089, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3089, __FUNCTION__)))))
;
3090
3091 /* Combine contiguous case ranges to reduce the number of assertions
3092 to insert. */
3093 for (idx = idx + 1; idx < n; idx++)
3094 {
3095 tree next_min, next_max;
3096 tree next_cl = gimple_switch_label (last, idx);
3097 if (CASE_LABEL (next_cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((next_cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3097, __FUNCTION__, (CASE_LABEL_EXPR)))), (2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3097, __FUNCTION__)))))
== CASE_LABEL (default_cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((default_cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3097, __FUNCTION__, (CASE_LABEL_EXPR)))), (2), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3097, __FUNCTION__)))))
)
3098 break;
3099
3100 next_min = CASE_LOW (next_cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((next_cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3100, __FUNCTION__, (CASE_LABEL_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3100, __FUNCTION__)))))
;
3101 next_max = CASE_HIGH (next_cl)(*((const_cast<tree*> (tree_operand_check (((tree_check
((next_cl), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3101, __FUNCTION__, (CASE_LABEL_EXPR)))), (1), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3101, __FUNCTION__)))))
;
3102
3103 wide_int difference = (wi::to_wide (next_min)
3104 - wi::to_wide (max ? max : min));
3105 if (wi::eq_p (difference, 1))
3106 max = next_max ? next_max : next_min;
3107 else
3108 break;
3109 }
3110 idx--;
3111
3112 if (max == NULL_TREE(tree) nullptr)
3113 {
3114 /* Register the assertion OP != MIN. */
3115 auto_vec<assert_info, 8> asserts;
3116 min = fold_convert (TREE_TYPE (op), min)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3116, __FUNCTION__))->typed.type), min)
;
3117 register_edge_assert_for (op, default_edge, NE_EXPR, op, min,
3118 asserts);
3119 finish_register_edge_assert_for (default_edge, bsi, asserts);
3120 }
3121 else
3122 {
3123 /* Register the assertion (unsigned)OP - MIN > (MAX - MIN),
3124 which will give OP the anti-range ~[MIN,MAX]. */
3125 tree uop = fold_convert (unsigned_type_for (TREE_TYPE (op)), op)fold_convert_loc (((location_t) 0), unsigned_type_for (((contains_struct_check
((op), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3125, __FUNCTION__))->typed.type)), op)
;
3126 min = fold_convert (TREE_TYPE (uop), min)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(uop), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3126, __FUNCTION__))->typed.type), min)
;
3127 max = fold_convert (TREE_TYPE (uop), max)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(uop), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3127, __FUNCTION__))->typed.type), max)
;
3128
3129 tree lhs = fold_build2 (MINUS_EXPR, TREE_TYPE (uop), uop, min)fold_build2_loc (((location_t) 0), MINUS_EXPR, ((contains_struct_check
((uop), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3129, __FUNCTION__))->typed.type), uop, min )
;
3130 tree rhs = int_const_binop (MINUS_EXPR, max, min);
3131 register_new_assert_for (op, lhs, GT_EXPR, rhs,
3132 NULLnullptr, default_edge, bsi);
3133 }
3134
3135 if (--insertion_limit == 0)
3136 break;
3137 }
3138}
3139
3140/* Traverse all the statements in block BB looking for statements that
3141 may generate useful assertions for the SSA names in their operand.
3142 If a statement produces a useful assertion A for name N_i, then the
3143 list of assertions already generated for N_i is scanned to
3144 determine if A is actually needed.
3145
3146 If N_i already had the assertion A at a location dominating the
3147 current location, then nothing needs to be done. Otherwise, the
3148 new location for A is recorded instead.
3149
3150 1- For every statement S in BB, all the variables used by S are
3151 added to bitmap FOUND_IN_SUBGRAPH.
3152
3153 2- If statement S uses an operand N in a way that exposes a known
3154 value range for N, then if N was not already generated by an
3155 ASSERT_EXPR, create a new assert location for N. For instance,
3156 if N is a pointer and the statement dereferences it, we can
3157 assume that N is not NULL.
3158
3159 3- COND_EXPRs are a special case of #2. We can derive range
3160 information from the predicate but need to insert different
3161 ASSERT_EXPRs for each of the sub-graphs rooted at the
3162 conditional block. If the last statement of BB is a conditional
3163 expression of the form 'X op Y', then
3164
3165 a) Remove X and Y from the set FOUND_IN_SUBGRAPH.
3166
3167 b) If the conditional is the only entry point to the sub-graph
3168 corresponding to the THEN_CLAUSE, recurse into it. On
3169 return, if X and/or Y are marked in FOUND_IN_SUBGRAPH, then
3170 an ASSERT_EXPR is added for the corresponding variable.
3171
3172 c) Repeat step (b) on the ELSE_CLAUSE.
3173
3174 d) Mark X and Y in FOUND_IN_SUBGRAPH.
3175
3176 For instance,
3177
3178 if (a == 9)
3179 b = a;
3180 else
3181 b = c + 1;
3182
3183 In this case, an assertion on the THEN clause is useful to
3184 determine that 'a' is always 9 on that edge. However, an assertion
3185 on the ELSE clause would be unnecessary.
3186
3187 4- If BB does not end in a conditional expression, then we recurse
3188 into BB's dominator children.
3189
3190 At the end of the recursive traversal, every SSA name will have a
3191 list of locations where ASSERT_EXPRs should be added. When a new
3192 location for name N is found, it is registered by calling
3193 register_new_assert_for. That function keeps track of all the
3194 registered assertions to prevent adding unnecessary assertions.
3195 For instance, if a pointer P_4 is dereferenced more than once in a
3196 dominator tree, only the location dominating all the dereference of
3197 P_4 will receive an ASSERT_EXPR. */
3198
3199void
3200vrp_asserts::find_assert_locations_in_bb (basic_block bb)
3201{
3202 gimple *last;
3203
3204 last = last_stmt (bb);
3205
3206 /* If BB's last statement is a conditional statement involving integer
3207 operands, determine if we need to add ASSERT_EXPRs. */
3208 if (last
3209 && gimple_code (last) == GIMPLE_COND
3210 && !fp_predicate (last)
3211 && !ZERO_SSA_OPERANDS (last, SSA_OP_USE)zero_ssa_operands (last, 0x01))
3212 find_conditional_asserts (bb, as_a <gcond *> (last));
3213
3214 /* If BB's last statement is a switch statement involving integer
3215 operands, determine if we need to add ASSERT_EXPRs. */
3216 if (last
3217 && gimple_code (last) == GIMPLE_SWITCH
3218 && !ZERO_SSA_OPERANDS (last, SSA_OP_USE)zero_ssa_operands (last, 0x01))
3219 find_switch_asserts (bb, as_a <gswitch *> (last));
3220
3221 /* Traverse all the statements in BB marking used names and looking
3222 for statements that may infer assertions for their used operands. */
3223 for (gimple_stmt_iterator si = gsi_last_bb (bb); !gsi_end_p (si);
3224 gsi_prev (&si))
3225 {
3226 gimple *stmt;
3227 tree op;
3228 ssa_op_iter i;
3229
3230 stmt = gsi_stmt (si);
3231
3232 if (is_gimple_debug (stmt))
3233 continue;
3234
3235 /* See if we can derive an assertion for any of STMT's operands. */
3236 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_USE)for (op = op_iter_init_tree (&(i), stmt, 0x01); !op_iter_done
(&(i)); (void) (op = op_iter_next_tree (&(i))))
3237 {
3238 tree value;
3239 enum tree_code comp_code;
3240
3241 /* If op is not live beyond this stmt, do not bother to insert
3242 asserts for it. */
3243 if (!live.live_on_block_p (op, bb))
3244 continue;
3245
3246 /* If OP is used in such a way that we can infer a value
3247 range for it, and we don't find a previous assertion for
3248 it, create a new assertion location node for OP. */
3249 if (infer_value_range (stmt, op, &comp_code, &value))
3250 {
3251 /* If we are able to infer a nonzero value range for OP,
3252 then walk backwards through the use-def chain to see if OP
3253 was set via a typecast.
3254
3255 If so, then we can also infer a nonzero value range
3256 for the operand of the NOP_EXPR. */
3257 if (comp_code == NE_EXPR && integer_zerop (value))
3258 {
3259 tree t = op;
3260 gimple *def_stmt = SSA_NAME_DEF_STMT (t)(tree_check ((t), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3260, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
3261
3262 while (is_gimple_assign (def_stmt)
3263 && CONVERT_EXPR_CODE_P((gimple_assign_rhs_code (def_stmt)) == NOP_EXPR || (gimple_assign_rhs_code
(def_stmt)) == CONVERT_EXPR)
3264 (gimple_assign_rhs_code (def_stmt))((gimple_assign_rhs_code (def_stmt)) == NOP_EXPR || (gimple_assign_rhs_code
(def_stmt)) == CONVERT_EXPR)
3265 && TREE_CODE((enum tree_code) (gimple_assign_rhs1 (def_stmt))->base.code
)
3266 (gimple_assign_rhs1 (def_stmt))((enum tree_code) (gimple_assign_rhs1 (def_stmt))->base.code
)
== SSA_NAME
3267 && POINTER_TYPE_P(((enum tree_code) (((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3268, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3268, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
3268 (TREE_TYPE (gimple_assign_rhs1 (def_stmt)))(((enum tree_code) (((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3268, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((gimple_assign_rhs1
(def_stmt)), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3268, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
)
3269 {
3270 t = gimple_assign_rhs1 (def_stmt);
3271 def_stmt = SSA_NAME_DEF_STMT (t)(tree_check ((t), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3271, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
3272
3273 /* Note we want to register the assert for the
3274 operand of the NOP_EXPR after SI, not after the
3275 conversion. */
3276 if (live.live_on_block_p (t, bb))
3277 register_new_assert_for (t, t, comp_code, value,
3278 bb, NULLnullptr, si);
3279 }
3280 }
3281
3282 register_new_assert_for (op, op, comp_code, value, bb, NULLnullptr, si);
3283 }
3284 }
3285
3286 /* Update live. */
3287 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_USE)for (op = op_iter_init_tree (&(i), stmt, 0x01); !op_iter_done
(&(i)); (void) (op = op_iter_next_tree (&(i))))
3288 live.set (op, bb);
3289 FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF)for (op = op_iter_init_tree (&(i), stmt, 0x02); !op_iter_done
(&(i)); (void) (op = op_iter_next_tree (&(i))))
3290 live.clear (op, bb);
3291 }
3292
3293 /* Traverse all PHI nodes in BB, updating live. */
3294 for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
3295 gsi_next (&si))
3296 {
3297 use_operand_p arg_p;
3298 ssa_op_iter i;
3299 gphi *phi = si.phi ();
3300 tree res = gimple_phi_result (phi);
3301
3302 if (virtual_operand_p (res))
3303 continue;
3304
3305 FOR_EACH_PHI_ARG (arg_p, phi, i, SSA_OP_USE)for ((arg_p) = op_iter_init_phiuse (&(i), phi, 0x01); !op_iter_done
(&(i)); (arg_p) = op_iter_next_use (&(i)))
3306 {
3307 tree arg = USE_FROM_PTR (arg_p)get_use_from_ptr (arg_p);
3308 if (TREE_CODE (arg)((enum tree_code) (arg)->base.code) == SSA_NAME)
3309 live.set (arg, bb);
3310 }
3311
3312 live.clear (res, bb);
3313 }
3314}
3315
3316/* Do an RPO walk over the function computing SSA name liveness
3317 on-the-fly and deciding on assert expressions to insert. */
3318
3319void
3320vrp_asserts::find_assert_locations (void)
3321{
3322 int *rpo = XNEWVEC (int, last_basic_block_for_fn (fun))((int *) xmalloc (sizeof (int) * (((fun)->cfg->x_last_basic_block
))))
;
3323 int *bb_rpo = XNEWVEC (int, last_basic_block_for_fn (fun))((int *) xmalloc (sizeof (int) * (((fun)->cfg->x_last_basic_block
))))
;
3324 int *last_rpo = XCNEWVEC (int, last_basic_block_for_fn (fun))((int *) xcalloc ((((fun)->cfg->x_last_basic_block)), sizeof
(int)))
;
3325 int rpo_cnt, i;
3326
3327 rpo_cnt = pre_and_rev_post_order_compute (NULLnullptr, rpo, false);
3328 for (i = 0; i < rpo_cnt; ++i)
3329 bb_rpo[rpo[i]] = i;
3330
3331 /* Pre-seed loop latch liveness from loop header PHI nodes. Due to
3332 the order we compute liveness and insert asserts we otherwise
3333 fail to insert asserts into the loop latch. */
3334 loop_p loop;
3335 FOR_EACH_LOOP (loop, 0)for (loop_iterator li((cfun + 0), &(loop), 0); (loop); (loop
) = li.next ())
3336 {
3337 i = loop->latch->index;
3338 unsigned int j = single_succ_edge (loop->latch)->dest_idx;
3339 for (gphi_iterator gsi = gsi_start_phis (loop->header);
3340 !gsi_end_p (gsi); gsi_next (&gsi))
3341 {
3342 gphi *phi = gsi.phi ();
3343 if (virtual_operand_p (gimple_phi_result (phi)))
3344 continue;
3345 tree arg = gimple_phi_arg_def (phi, j);
3346 if (TREE_CODE (arg)((enum tree_code) (arg)->base.code) == SSA_NAME)
3347 live.set (arg, loop->latch);
3348 }
3349 }
3350
3351 for (i = rpo_cnt - 1; i >= 0; --i)
3352 {
3353 basic_block bb = BASIC_BLOCK_FOR_FN (fun, rpo[i])((*((fun)->cfg->x_basic_block_info))[(rpo[i])]);
3354 edge e;
3355 edge_iterator ei;
3356
3357 /* Process BB and update the live information with uses in
3358 this block. */
3359 find_assert_locations_in_bb (bb);
3360
3361 /* Merge liveness into the predecessor blocks and free it. */
3362 if (!live.block_has_live_names_p (bb))
3363 {
3364 int pred_rpo = i;
3365 FOR_EACH_EDGE (e, ei, bb->preds)for ((ei) = ei_start_1 (&((bb->preds))); ei_cond ((ei)
, &(e)); ei_next (&(ei)))
3366 {
3367 int pred = e->src->index;
3368 if ((e->flags & EDGE_DFS_BACK) || pred == ENTRY_BLOCK(0))
3369 continue;
3370
3371 live.merge (e->src, bb);
3372
3373 if (bb_rpo[pred] < pred_rpo)
3374 pred_rpo = bb_rpo[pred];
3375 }
3376
3377 /* Record the RPO number of the last visited block that needs
3378 live information from this block. */
3379 last_rpo[rpo[i]] = pred_rpo;
3380 }
3381 else
3382 live.clear_block (bb);
3383
3384 /* We can free all successors live bitmaps if all their
3385 predecessors have been visited already. */
3386 FOR_EACH_EDGE (e, ei, bb->succs)for ((ei) = ei_start_1 (&((bb->succs))); ei_cond ((ei)
, &(e)); ei_next (&(ei)))
3387 if (last_rpo[e->dest->index] == i)
3388 live.clear_block (e->dest);
3389 }
3390
3391 XDELETEVEC (rpo)free ((void*) (rpo));
3392 XDELETEVEC (bb_rpo)free ((void*) (bb_rpo));
3393 XDELETEVEC (last_rpo)free ((void*) (last_rpo));
3394}
3395
3396/* Create an ASSERT_EXPR for NAME and insert it in the location
3397 indicated by LOC. Return true if we made any edge insertions. */
3398
3399bool
3400vrp_asserts::process_assert_insertions_for (tree name, assert_locus *loc)
3401{
3402 /* Build the comparison expression NAME_i COMP_CODE VAL. */
3403 gimple *stmt;
3404 tree cond;
3405 gimple *assert_stmt;
3406 edge_iterator ei;
3407 edge e;
3408
3409 /* If we have X <=> X do not insert an assert expr for that. */
3410 if (loc->expr == loc->val)
3411 return false;
3412
3413 cond = build2 (loc->comp_code, boolean_type_nodeglobal_trees[TI_BOOLEAN_TYPE], loc->expr, loc->val);
3414 assert_stmt = build_assert_expr_for (cond, name);
3415 if (loc->e)
3416 {
3417 /* We have been asked to insert the assertion on an edge. This
3418 is used only by COND_EXPR and SWITCH_EXPR assertions. */
3419 gcc_checking_assert (gimple_code (gsi_stmt (loc->si)) == GIMPLE_COND((void)(!(gimple_code (gsi_stmt (loc->si)) == GIMPLE_COND ||
(gimple_code (gsi_stmt (loc->si)) == GIMPLE_SWITCH)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3421, __FUNCTION__), 0 : 0))
3420 || (gimple_code (gsi_stmt (loc->si))((void)(!(gimple_code (gsi_stmt (loc->si)) == GIMPLE_COND ||
(gimple_code (gsi_stmt (loc->si)) == GIMPLE_SWITCH)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3421, __FUNCTION__), 0 : 0))
3421 == GIMPLE_SWITCH))((void)(!(gimple_code (gsi_stmt (loc->si)) == GIMPLE_COND ||
(gimple_code (gsi_stmt (loc->si)) == GIMPLE_SWITCH)) ? fancy_abort
("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3421, __FUNCTION__), 0 : 0))
;
3422
3423 gsi_insert_on_edge (loc->e, assert_stmt);
3424 return true;
3425 }
3426
3427 /* If the stmt iterator points at the end then this is an insertion
3428 at the beginning of a block. */
3429 if (gsi_end_p (loc->si))
3430 {
3431 gimple_stmt_iterator si = gsi_after_labels (loc->bb);
3432 gsi_insert_before (&si, assert_stmt, GSI_SAME_STMT);
3433 return false;
3434
3435 }
3436 /* Otherwise, we can insert right after LOC->SI iff the
3437 statement must not be the last statement in the block. */
3438 stmt = gsi_stmt (loc->si);
3439 if (!stmt_ends_bb_p (stmt))
3440 {
3441 gsi_insert_after (&loc->si, assert_stmt, GSI_SAME_STMT);
3442 return false;
3443 }
3444
3445 /* If STMT must be the last statement in BB, we can only insert new
3446 assertions on the non-abnormal edge out of BB. Note that since
3447 STMT is not control flow, there may only be one non-abnormal/eh edge
3448 out of BB. */
3449 FOR_EACH_EDGE (e, ei, loc->bb->succs)for ((ei) = ei_start_1 (&((loc->bb->succs))); ei_cond
((ei), &(e)); ei_next (&(ei)))
3450 if (!(e->flags & (EDGE_ABNORMAL|EDGE_EH)))
3451 {
3452 gsi_insert_on_edge (e, assert_stmt);
3453 return true;
3454 }
3455
3456 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3456, __FUNCTION__))
;
3457}
3458
3459/* Qsort helper for sorting assert locations. If stable is true, don't
3460 use iterative_hash_expr because it can be unstable for -fcompare-debug,
3461 on the other side some pointers might be NULL. */
3462
3463template <bool stable>
3464int
3465vrp_asserts::compare_assert_loc (const void *pa, const void *pb)
3466{
3467 assert_locus * const a = *(assert_locus * const *)pa;
3468 assert_locus * const b = *(assert_locus * const *)pb;
3469
3470 /* If stable, some asserts might be optimized away already, sort
3471 them last. */
3472 if (stable)
3473 {
3474 if (a == NULLnullptr)
3475 return b != NULLnullptr;
3476 else if (b == NULLnullptr)
3477 return -1;
3478 }
3479
3480 if (a->e == NULLnullptr && b->e != NULLnullptr)
3481 return 1;
3482 else if (a->e != NULLnullptr && b->e == NULLnullptr)
3483 return -1;
3484
3485 /* After the above checks, we know that (a->e == NULL) == (b->e == NULL),
3486 no need to test both a->e and b->e. */
3487
3488 /* Sort after destination index. */
3489 if (a->e == NULLnullptr)
3490 ;
3491 else if (a->e->dest->index > b->e->dest->index)
3492 return 1;
3493 else if (a->e->dest->index < b->e->dest->index)
3494 return -1;
3495
3496 /* Sort after comp_code. */
3497 if (a->comp_code > b->comp_code)
3498 return 1;
3499 else if (a->comp_code < b->comp_code)
3500 return -1;
3501
3502 hashval_t ha, hb;
3503
3504 /* E.g. if a->val is ADDR_EXPR of a VAR_DECL, iterative_hash_expr
3505 uses DECL_UID of the VAR_DECL, so sorting might differ between
3506 -g and -g0. When doing the removal of redundant assert exprs
3507 and commonization to successors, this does not matter, but for
3508 the final sort needs to be stable. */
3509 if (stable)
3510 {
3511 ha = 0;
3512 hb = 0;
3513 }
3514 else
3515 {
3516 ha = iterative_hash_expr (a->expr, iterative_hash_expr (a->val, 0));
3517 hb = iterative_hash_expr (b->expr, iterative_hash_expr (b->val, 0));
3518 }
3519
3520 /* Break the tie using hashing and source/bb index. */
3521 if (ha == hb)
3522 return (a->e != NULLnullptr
3523 ? a->e->src->index - b->e->src->index
3524 : a->bb->index - b->bb->index);
3525 return ha > hb ? 1 : -1;
3526}
3527
3528/* Process all the insertions registered for every name N_i registered
3529 in NEED_ASSERT_FOR. The list of assertions to be inserted are
3530 found in ASSERTS_FOR[i]. */
3531
3532void
3533vrp_asserts::process_assert_insertions ()
3534{
3535 unsigned i;
3536 bitmap_iterator bi;
3537 bool update_edges_p = false;
3538 int num_asserts = 0;
3539
3540 if (dump_file && (dump_flags & TDF_DETAILS))
3541 dump (dump_file);
3542
3543 EXECUTE_IF_SET_IN_BITMAP (need_assert_for, 0, i, bi)for (bmp_iter_set_init (&(bi), (need_assert_for), (0), &
(i)); bmp_iter_set (&(bi), &(i)); bmp_iter_next (&
(bi), &(i)))
3544 {
3545 assert_locus *loc = asserts_for[i];
3546 gcc_assert (loc)((void)(!(loc) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3546, __FUNCTION__), 0 : 0))
;
3547
3548 auto_vec<assert_locus *, 16> asserts;
3549 for (; loc; loc = loc->next)
3550 asserts.safe_push (loc);
3551 asserts.qsort (compare_assert_loc<false>)qsort (compare_assert_loc<false>);
3552
3553 /* Push down common asserts to successors and remove redundant ones. */
3554 unsigned ecnt = 0;
3555 assert_locus *common = NULLnullptr;
3556 unsigned commonj = 0;
3557 for (unsigned j = 0; j < asserts.length (); ++j)
3558 {
3559 loc = asserts[j];
3560 if (! loc->e)
3561 common = NULLnullptr;
3562 else if (! common
3563 || loc->e->dest != common->e->dest
3564 || loc->comp_code != common->comp_code
3565 || ! operand_equal_p (loc->val, common->val, 0)
3566 || ! operand_equal_p (loc->expr, common->expr, 0))
3567 {
3568 commonj = j;
3569 common = loc;
3570 ecnt = 1;
3571 }
3572 else if (loc->e == asserts[j-1]->e)
3573 {
3574 /* Remove duplicate asserts. */
3575 if (commonj == j - 1)
3576 {
3577 commonj = j;
3578 common = loc;
3579 }
3580 free (asserts[j-1]);
3581 asserts[j-1] = NULLnullptr;
3582 }
3583 else
3584 {
3585 ecnt++;
3586 if (EDGE_COUNT (common->e->dest->preds)vec_safe_length (common->e->dest->preds) == ecnt)
3587 {
3588 /* We have the same assertion on all incoming edges of a BB.
3589 Insert it at the beginning of that block. */
3590 loc->bb = loc->e->dest;
3591 loc->e = NULLnullptr;
3592 loc->si = gsi_none ();
3593 common = NULLnullptr;
3594 /* Clear asserts commoned. */
3595 for (; commonj != j; ++commonj)
3596 if (asserts[commonj])
3597 {
3598 free (asserts[commonj]);
3599 asserts[commonj] = NULLnullptr;
3600 }
3601 }
3602 }
3603 }
3604
3605 /* The asserts vector sorting above might be unstable for
3606 -fcompare-debug, sort again to ensure a stable sort. */
3607 asserts.qsort (compare_assert_loc<true>)qsort (compare_assert_loc<true>);
3608 for (unsigned j = 0; j < asserts.length (); ++j)
3609 {
3610 loc = asserts[j];
3611 if (! loc)
3612 break;
3613 update_edges_p |= process_assert_insertions_for (ssa_name (i)((*(cfun + 0)->gimple_df->ssa_names)[(i)]), loc);
3614 num_asserts++;
3615 free (loc);
3616 }
3617 }
3618
3619 if (update_edges_p)
3620 gsi_commit_edge_inserts ();
3621
3622 statistics_counter_event (fun, "Number of ASSERT_EXPR expressions inserted",
3623 num_asserts);
3624}
3625
3626/* Traverse the flowgraph looking for conditional jumps to insert range
3627 expressions. These range expressions are meant to provide information
3628 to optimizations that need to reason in terms of value ranges. They
3629 will not be expanded into RTL. For instance, given:
3630
3631 x = ...
3632 y = ...
3633 if (x < y)
3634 y = x - 2;
3635 else
3636 x = y + 3;
3637
3638 this pass will transform the code into:
3639
3640 x = ...
3641 y = ...
3642 if (x < y)
3643 {
3644 x = ASSERT_EXPR <x, x < y>
3645 y = x - 2
3646 }
3647 else
3648 {
3649 y = ASSERT_EXPR <y, x >= y>
3650 x = y + 3
3651 }
3652
3653 The idea is that once copy and constant propagation have run, other
3654 optimizations will be able to determine what ranges of values can 'x'
3655 take in different paths of the code, simply by checking the reaching
3656 definition of 'x'. */
3657
3658void
3659vrp_asserts::insert_range_assertions (void)
3660{
3661 need_assert_for = BITMAP_ALLOCbitmap_alloc (NULLnullptr);
3662 asserts_for = XCNEWVEC (assert_locus *, num_ssa_names)((assert_locus * *) xcalloc (((vec_safe_length ((cfun + 0)->
gimple_df->ssa_names))), sizeof (assert_locus *)))
;
3663
3664 calculate_dominance_info (CDI_DOMINATORS);
3665
3666 find_assert_locations ();
3667 if (!bitmap_empty_p (need_assert_for))
3668 {
3669 process_assert_insertions ();
3670 update_ssa (TODO_update_ssa_no_phi(1 << 12));
3671 }
3672
3673 if (dump_file && (dump_flags & TDF_DETAILS))
3674 {
3675 fprintf (dump_file, "\nSSA form after inserting ASSERT_EXPRs\n");
3676 dump_function_to_file (current_function_decl, dump_file, dump_flags);
3677 }
3678
3679 free (asserts_for);
3680 BITMAP_FREE (need_assert_for)((void) (bitmap_obstack_free ((bitmap) need_assert_for), (need_assert_for
) = (bitmap) nullptr))
;
3681}
3682
3683/* Return true if all imm uses of VAR are either in STMT, or
3684 feed (optionally through a chain of single imm uses) GIMPLE_COND
3685 in basic block COND_BB. */
3686
3687bool
3688vrp_asserts::all_imm_uses_in_stmt_or_feed_cond (tree var,
3689 gimple *stmt,
3690 basic_block cond_bb)
3691{
3692 use_operand_p use_p, use2_p;
3693 imm_use_iterator iter;
3694
3695 FOR_EACH_IMM_USE_FAST (use_p, iter, var)for ((use_p) = first_readonly_imm_use (&(iter), (var)); !
end_readonly_imm_use_p (&(iter)); (void) ((use_p) = next_readonly_imm_use
(&(iter))))
3696 if (USE_STMT (use_p)(use_p)->loc.stmt != stmt)
3697 {
3698 gimple *use_stmt = USE_STMT (use_p)(use_p)->loc.stmt, *use_stmt2;
3699 if (is_gimple_debug (use_stmt))
3700 continue;
3701 while (is_gimple_assign (use_stmt)
3702 && TREE_CODE (gimple_assign_lhs (use_stmt))((enum tree_code) (gimple_assign_lhs (use_stmt))->base.code
)
== SSA_NAME
3703 && single_imm_use (gimple_assign_lhs (use_stmt),
3704 &use2_p, &use_stmt2))
3705 use_stmt = use_stmt2;
3706 if (gimple_code (use_stmt) != GIMPLE_COND
3707 || gimple_bb (use_stmt) != cond_bb)
3708 return false;
3709 }
3710 return true;
3711}
3712
3713/* Convert range assertion expressions into the implied copies and
3714 copy propagate away the copies. Doing the trivial copy propagation
3715 here avoids the need to run the full copy propagation pass after
3716 VRP.
3717
3718 FIXME, this will eventually lead to copy propagation removing the
3719 names that had useful range information attached to them. For
3720 instance, if we had the assertion N_i = ASSERT_EXPR <N_j, N_j > 3>,
3721 then N_i will have the range [3, +INF].
3722
3723 However, by converting the assertion into the implied copy
3724 operation N_i = N_j, we will then copy-propagate N_j into the uses
3725 of N_i and lose the range information. We may want to hold on to
3726 ASSERT_EXPRs a little while longer as the ranges could be used in
3727 things like jump threading.
3728
3729 The problem with keeping ASSERT_EXPRs around is that passes after
3730 VRP need to handle them appropriately.
3731
3732 Another approach would be to make the range information a first
3733 class property of the SSA_NAME so that it can be queried from
3734 any pass. This is made somewhat more complex by the need for
3735 multiple ranges to be associated with one SSA_NAME. */
3736
3737void
3738vrp_asserts::remove_range_assertions ()
3739{
3740 basic_block bb;
3741 gimple_stmt_iterator si;
3742 /* 1 if looking at ASSERT_EXPRs immediately at the beginning of
3743 a basic block preceeded by GIMPLE_COND branching to it and
3744 __builtin_trap, -1 if not yet checked, 0 otherwise. */
3745 int is_unreachable;
3746
3747 /* Note that the BSI iterator bump happens at the bottom of the
3748 loop and no bump is necessary if we're removing the statement
3749 referenced by the current BSI. */
3750 FOR_EACH_BB_FN (bb, fun)for (bb = (fun)->cfg->x_entry_block_ptr->next_bb; bb
!= (fun)->cfg->x_exit_block_ptr; bb = bb->next_bb)
3751 for (si = gsi_after_labels (bb), is_unreachable = -1; !gsi_end_p (si);)
3752 {
3753 gimple *stmt = gsi_stmt (si);
3754
3755 if (is_gimple_assign (stmt)
3756 && gimple_assign_rhs_code (stmt) == ASSERT_EXPR)
3757 {
3758 tree lhs = gimple_assign_lhs (stmt);
3759 tree rhs = gimple_assign_rhs1 (stmt);
3760 tree var;
3761
3762 var = ASSERT_EXPR_VAR (rhs)(*((const_cast<tree*> (tree_operand_check (((tree_check
((rhs), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3762, __FUNCTION__, (ASSERT_EXPR)))), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3762, __FUNCTION__)))))
;
3763
3764 if (TREE_CODE (var)((enum tree_code) (var)->base.code) == SSA_NAME
3765 && !POINTER_TYPE_P (TREE_TYPE (lhs))(((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3765, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3765, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
3766 && SSA_NAME_RANGE_INFO (lhs)(tree_check ((lhs), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3766, __FUNCTION__, (SSA_NAME)))->ssa_name.info.range_info
)
3767 {
3768 if (is_unreachable == -1)
3769 {
3770 is_unreachable = 0;
3771 if (single_pred_p (bb)
3772 && assert_unreachable_fallthru_edge_p
3773 (single_pred_edge (bb)))
3774 is_unreachable = 1;
3775 }
3776 /* Handle
3777 if (x_7 >= 10 && x_7 < 20)
3778 __builtin_unreachable ();
3779 x_8 = ASSERT_EXPR <x_7, ...>;
3780 if the only uses of x_7 are in the ASSERT_EXPR and
3781 in the condition. In that case, we can copy the
3782 range info from x_8 computed in this pass also
3783 for x_7. */
3784 if (is_unreachable
3785 && all_imm_uses_in_stmt_or_feed_cond (var, stmt,
3786 single_pred (bb)))
3787 {
3788 set_range_info (var, SSA_NAME_RANGE_TYPE (lhs)((tree_check ((lhs), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3788, __FUNCTION__, (SSA_NAME)))->base.static_flag ? VR_ANTI_RANGE
: VR_RANGE)
,
3789 SSA_NAME_RANGE_INFO (lhs)(tree_check ((lhs), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3789, __FUNCTION__, (SSA_NAME)))->ssa_name.info.range_info
->get_min (),
3790 SSA_NAME_RANGE_INFO (lhs)(tree_check ((lhs), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3790, __FUNCTION__, (SSA_NAME)))->ssa_name.info.range_info
->get_max ());
3791 maybe_set_nonzero_bits (single_pred_edge (bb), var);
3792 }
3793 }
3794
3795 /* Propagate the RHS into every use of the LHS. For SSA names
3796 also propagate abnormals as it merely restores the original
3797 IL in this case (an replace_uses_by would assert). */
3798 if (TREE_CODE (var)((enum tree_code) (var)->base.code) == SSA_NAME)
3799 {
3800 imm_use_iterator iter;
3801 use_operand_p use_p;
3802 gimple *use_stmt;
3803 FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)for (struct auto_end_imm_use_stmt_traverse auto_end_imm_use_stmt_traverse
((((use_stmt) = first_imm_use_stmt (&(iter), (lhs))), &
(iter))); !end_imm_use_stmt_p (&(iter)); (void) ((use_stmt
) = next_imm_use_stmt (&(iter))))
3804 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)for ((use_p) = first_imm_use_on_stmt (&(iter)); !end_imm_use_on_stmt_p
(&(iter)); (void) ((use_p) = next_imm_use_on_stmt (&
(iter))))
3805 SET_USE (use_p, var)set_ssa_use_from_ptr (use_p, var);
3806 }
3807 else
3808 replace_uses_by (lhs, var);
3809
3810 /* And finally, remove the copy, it is not needed. */
3811 gsi_remove (&si, true);
3812 release_defs (stmt);
3813 }
3814 else
3815 {
3816 if (!is_gimple_debug (gsi_stmt (si)))
3817 is_unreachable = 0;
3818 gsi_next (&si);
3819 }
3820 }
3821}
3822
3823class vrp_prop : public ssa_propagation_engine
3824{
3825public:
3826 vrp_prop (vr_values *v)
3827 : ssa_propagation_engine (),
3828 m_vr_values (v) { }
3829
3830 void initialize (struct function *);
3831 void finalize ();
3832
3833private:
3834 enum ssa_prop_result visit_stmt (gimple *, edge *, tree *) FINAL OVERRIDE;
3835 enum ssa_prop_result visit_phi (gphi *) FINAL OVERRIDE;
3836
3837 struct function *fun;
3838 vr_values *m_vr_values;
3839};
3840
3841/* Initialization required by ssa_propagate engine. */
3842
3843void
3844vrp_prop::initialize (struct function *fn)
3845{
3846 basic_block bb;
3847 fun = fn;
3848
3849 FOR_EACH_BB_FN (bb, fun)for (bb = (fun)->cfg->x_entry_block_ptr->next_bb; bb
!= (fun)->cfg->x_exit_block_ptr; bb = bb->next_bb)
3850 {
3851 for (gphi_iterator si = gsi_start_phis (bb); !gsi_end_p (si);
3852 gsi_next (&si))
3853 {
3854 gphi *phi = si.phi ();
3855 if (!stmt_interesting_for_vrp (phi))
3856 {
3857 tree lhs = PHI_RESULT (phi)get_def_from_ptr (gimple_phi_result_ptr (phi));
3858 m_vr_values->set_def_to_varying (lhs);
3859 prop_set_simulate_again (phi, false);
3860 }
3861 else
3862 prop_set_simulate_again (phi, true);
3863 }
3864
3865 for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
3866 gsi_next (&si))
3867 {
3868 gimple *stmt = gsi_stmt (si);
3869
3870 /* If the statement is a control insn, then we do not
3871 want to avoid simulating the statement once. Failure
3872 to do so means that those edges will never get added. */
3873 if (stmt_ends_bb_p (stmt))
3874 prop_set_simulate_again (stmt, true);
3875 else if (!stmt_interesting_for_vrp (stmt))
3876 {
3877 m_vr_values->set_defs_to_varying (stmt);
3878 prop_set_simulate_again (stmt, false);
3879 }
3880 else
3881 prop_set_simulate_again (stmt, true);
3882 }
3883 }
3884}
3885
3886/* Evaluate statement STMT. If the statement produces a useful range,
3887 return SSA_PROP_INTERESTING and record the SSA name with the
3888 interesting range into *OUTPUT_P.
3889
3890 If STMT is a conditional branch and we can determine its truth
3891 value, the taken edge is recorded in *TAKEN_EDGE_P.
3892
3893 If STMT produces a varying value, return SSA_PROP_VARYING. */
3894
3895enum ssa_prop_result
3896vrp_prop::visit_stmt (gimple *stmt, edge *taken_edge_p, tree *output_p)
3897{
3898 tree lhs = gimple_get_lhs (stmt);
3899 value_range_equiv vr;
3900 m_vr_values->extract_range_from_stmt (stmt, taken_edge_p, output_p, &vr);
3901
3902 if (*output_p)
3903 {
3904 if (m_vr_values->update_value_range (*output_p, &vr))
3905 {
3906 if (dump_file && (dump_flags & TDF_DETAILS))
3907 {
3908 fprintf (dump_file, "Found new range for ");
3909 print_generic_expr (dump_file, *output_p);
3910 fprintf (dump_file, ": ");
3911 dump_value_range (dump_file, &vr);
3912 fprintf (dump_file, "\n");
3913 }
3914
3915 if (vr.varying_p ())
3916 return SSA_PROP_VARYING;
3917
3918 return SSA_PROP_INTERESTING;
3919 }
3920 return SSA_PROP_NOT_INTERESTING;
3921 }
3922
3923 if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
3924 switch (gimple_call_internal_fn (stmt))
3925 {
3926 case IFN_ADD_OVERFLOW:
3927 case IFN_SUB_OVERFLOW:
3928 case IFN_MUL_OVERFLOW:
3929 case IFN_ATOMIC_COMPARE_EXCHANGE:
3930 /* These internal calls return _Complex integer type,
3931 which VRP does not track, but the immediate uses
3932 thereof might be interesting. */
3933 if (lhs && TREE_CODE (lhs)((enum tree_code) (lhs)->base.code) == SSA_NAME)
3934 {
3935 imm_use_iterator iter;
3936 use_operand_p use_p;
3937 enum ssa_prop_result res = SSA_PROP_VARYING;
3938
3939 m_vr_values->set_def_to_varying (lhs);
3940
3941 FOR_EACH_IMM_USE_FAST (use_p, iter, lhs)for ((use_p) = first_readonly_imm_use (&(iter), (lhs)); !
end_readonly_imm_use_p (&(iter)); (void) ((use_p) = next_readonly_imm_use
(&(iter))))
3942 {
3943 gimple *use_stmt = USE_STMT (use_p)(use_p)->loc.stmt;
3944 if (!is_gimple_assign (use_stmt))
3945 continue;
3946 enum tree_code rhs_code = gimple_assign_rhs_code (use_stmt);
3947 if (rhs_code != REALPART_EXPR && rhs_code != IMAGPART_EXPR)
3948 continue;
3949 tree rhs1 = gimple_assign_rhs1 (use_stmt);
3950 tree use_lhs = gimple_assign_lhs (use_stmt);
3951 if (TREE_CODE (rhs1)((enum tree_code) (rhs1)->base.code) != rhs_code
3952 || TREE_OPERAND (rhs1, 0)(*((const_cast<tree*> (tree_operand_check ((rhs1), (0),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3952, __FUNCTION__)))))
!= lhs
3953 || TREE_CODE (use_lhs)((enum tree_code) (use_lhs)->base.code) != SSA_NAME
3954 || !stmt_interesting_for_vrp (use_stmt)
3955 || (!INTEGRAL_TYPE_P (TREE_TYPE (use_lhs))(((enum tree_code) (((contains_struct_check ((use_lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3955, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((use_lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3955, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((use_lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3955, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
3956 || !TYPE_MIN_VALUE (TREE_TYPE (use_lhs))((tree_check5 ((((contains_struct_check ((use_lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3956, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3956, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.minval
)
3957 || !TYPE_MAX_VALUE (TREE_TYPE (use_lhs))((tree_check5 ((((contains_struct_check ((use_lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3957, __FUNCTION__))->typed.type)), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 3957, __FUNCTION__, (INTEGER_TYPE), (ENUMERAL_TYPE), (BOOLEAN_TYPE
), (REAL_TYPE), (FIXED_POINT_TYPE)))->type_non_common.maxval
)
))
3958 continue;
3959
3960 /* If there is a change in the value range for any of the
3961 REALPART_EXPR/IMAGPART_EXPR immediate uses, return
3962 SSA_PROP_INTERESTING. If there are any REALPART_EXPR
3963 or IMAGPART_EXPR immediate uses, but none of them have
3964 a change in their value ranges, return
3965 SSA_PROP_NOT_INTERESTING. If there are no
3966 {REAL,IMAG}PART_EXPR uses at all,
3967 return SSA_PROP_VARYING. */
3968 value_range_equiv new_vr;
3969 m_vr_values->extract_range_basic (&new_vr, use_stmt);
3970 const value_range_equiv *old_vr
3971 = m_vr_values->get_value_range (use_lhs);
3972 if (!old_vr->equal_p (new_vr, /*ignore_equivs=*/false))
3973 res = SSA_PROP_INTERESTING;
3974 else
3975 res = SSA_PROP_NOT_INTERESTING;
3976 new_vr.equiv_clear ();
3977 if (res == SSA_PROP_INTERESTING)
3978 {
3979 *output_p = lhs;
3980 return res;
3981 }
3982 }
3983
3984 return res;
3985 }
3986 break;
3987 default:
3988 break;
3989 }
3990
3991 /* All other statements produce nothing of interest for VRP, so mark
3992 their outputs varying and prevent further simulation. */
3993 m_vr_values->set_defs_to_varying (stmt);
3994
3995 return (*taken_edge_p) ? SSA_PROP_INTERESTING : SSA_PROP_VARYING;
3996}
3997
3998/* Visit all arguments for PHI node PHI that flow through executable
3999 edges. If a valid value range can be derived from all the incoming
4000 value ranges, set a new range for the LHS of PHI. */
4001
4002enum ssa_prop_result
4003vrp_prop::visit_phi (gphi *phi)
4004{
4005 tree lhs = PHI_RESULT (phi)get_def_from_ptr (gimple_phi_result_ptr (phi));
4006 value_range_equiv vr_result;
4007 m_vr_values->extract_range_from_phi_node (phi, &vr_result);
4008 if (m_vr_values->update_value_range (lhs, &vr_result))
4009 {
4010 if (dump_file && (dump_flags & TDF_DETAILS))
4011 {
4012 fprintf (dump_file, "Found new range for ");
4013 print_generic_expr (dump_file, lhs);
4014 fprintf (dump_file, ": ");
4015 dump_value_range (dump_file, &vr_result);
4016 fprintf (dump_file, "\n");
4017 }
4018
4019 if (vr_result.varying_p ())
4020 return SSA_PROP_VARYING;
4021
4022 return SSA_PROP_INTERESTING;
4023 }
4024
4025 /* Nothing changed, don't add outgoing edges. */
4026 return SSA_PROP_NOT_INTERESTING;
4027}
4028
4029/* Traverse all the blocks folding conditionals with known ranges. */
4030
4031void
4032vrp_prop::finalize ()
4033{
4034 size_t i;
4035
4036 /* We have completed propagating through the lattice. */
4037 m_vr_values->set_lattice_propagation_complete ();
4038
4039 if (dump_file)
4040 {
4041 fprintf (dump_file, "\nValue ranges after VRP:\n\n");
4042 m_vr_values->dump_all_value_ranges (dump_file);
4043 fprintf (dump_file, "\n");
4044 }
4045
4046 /* Set value range to non pointer SSA_NAMEs. */
4047 for (i = 0; i < num_ssa_names(vec_safe_length ((cfun + 0)->gimple_df->ssa_names)); i++)
4048 {
4049 tree name = ssa_name (i)((*(cfun + 0)->gimple_df->ssa_names)[(i)]);
4050 if (!name)
4051 continue;
4052
4053 const value_range_equiv *vr = m_vr_values->get_value_range (name);
4054 if (!name || !vr->constant_p ())
4055 continue;
4056
4057 if (POINTER_TYPE_P (TREE_TYPE (name))(((enum tree_code) (((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4057, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4057, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
4058 && range_includes_zero_p (vr) == 0)
4059 set_ptr_nonnull (name);
4060 else if (!POINTER_TYPE_P (TREE_TYPE (name))(((enum tree_code) (((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4060, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((name), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4060, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
)
4061 set_range_info (name, *vr);
4062 }
4063}
4064
4065class vrp_folder : public substitute_and_fold_engine
4066{
4067 public:
4068 vrp_folder (vr_values *v)
4069 : substitute_and_fold_engine (/* Fold all stmts. */ true),
4070 m_vr_values (v), simplifier (v)
4071 { }
4072
4073private:
4074 tree value_of_expr (tree name, gimple *stmt) OVERRIDE
4075 {
4076 return m_vr_values->value_of_expr (name, stmt);
4077 }
4078 bool fold_stmt (gimple_stmt_iterator *) FINAL OVERRIDE;
4079 bool fold_predicate_in (gimple_stmt_iterator *);
4080
4081 vr_values *m_vr_values;
4082 simplify_using_ranges simplifier;
4083};
4084
4085/* If the statement pointed by SI has a predicate whose value can be
4086 computed using the value range information computed by VRP, compute
4087 its value and return true. Otherwise, return false. */
4088
4089bool
4090vrp_folder::fold_predicate_in (gimple_stmt_iterator *si)
4091{
4092 bool assignment_p = false;
4093 tree val;
4094 gimple *stmt = gsi_stmt (*si);
4095
4096 if (is_gimple_assign (stmt)
4097 && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt))tree_code_type[(int) (gimple_assign_rhs_code (stmt))] == tcc_comparison)
4098 {
4099 assignment_p = true;
4100 val = simplifier.vrp_evaluate_conditional (gimple_assign_rhs_code (stmt),
4101 gimple_assign_rhs1 (stmt),
4102 gimple_assign_rhs2 (stmt),
4103 stmt);
4104 }
4105 else if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
4106 val = simplifier.vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
4107 gimple_cond_lhs (cond_stmt),
4108 gimple_cond_rhs (cond_stmt),
4109 stmt);
4110 else
4111 return false;
4112
4113 if (val)
4114 {
4115 if (assignment_p)
4116 val = fold_convert (gimple_expr_type (stmt), val)fold_convert_loc (((location_t) 0), gimple_expr_type (stmt), val
)
;
4117
4118 if (dump_file)
4119 {
4120 fprintf (dump_file, "Folding predicate ");
4121 print_gimple_expr (dump_file, stmt, 0);
4122 fprintf (dump_file, " to ");
4123 print_generic_expr (dump_file, val);
4124 fprintf (dump_file, "\n");
4125 }
4126
4127 if (is_gimple_assign (stmt))
4128 gimple_assign_set_rhs_from_tree (si, val);
4129 else
4130 {
4131 gcc_assert (gimple_code (stmt) == GIMPLE_COND)((void)(!(gimple_code (stmt) == GIMPLE_COND) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4131, __FUNCTION__), 0 : 0))
;
4132 gcond *cond_stmt = as_a <gcond *> (stmt);
4133 if (integer_zerop (val))
4134 gimple_cond_make_false (cond_stmt);
4135 else if (integer_onep (val))
4136 gimple_cond_make_true (cond_stmt);
4137 else
4138 gcc_unreachable ()(fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4138, __FUNCTION__))
;
4139 }
4140
4141 return true;
4142 }
4143
4144 return false;
4145}
4146
4147/* Callback for substitute_and_fold folding the stmt at *SI. */
4148
4149bool
4150vrp_folder::fold_stmt (gimple_stmt_iterator *si)
4151{
4152 if (fold_predicate_in (si))
4153 return true;
4154
4155 return simplifier.simplify (si);
4156}
4157
4158/* Blocks which have more than one predecessor and more than
4159 one successor present jump threading opportunities, i.e.,
4160 when the block is reached from a specific predecessor, we
4161 may be able to determine which of the outgoing edges will
4162 be traversed. When this optimization applies, we are able
4163 to avoid conditionals at runtime and we may expose secondary
4164 optimization opportunities.
4165
4166 This class is effectively a driver for the generic jump
4167 threading code. It basically just presents the generic code
4168 with edges that may be suitable for jump threading.
4169
4170 Unlike DOM, we do not iterate VRP if jump threading was successful.
4171 While iterating may expose new opportunities for VRP, it is expected
4172 those opportunities would be very limited and the compile time cost
4173 to expose those opportunities would be significant.
4174
4175 As jump threading opportunities are discovered, they are registered
4176 for later realization. */
4177
4178class vrp_jump_threader : public dom_walker
4179{
4180public:
4181 vrp_jump_threader (struct function *, vr_values *);
4182 ~vrp_jump_threader ();
4183
4184 void thread_jumps ()
4185 {
4186 walk (m_fun->cfg->x_entry_block_ptr);
4187 }
4188
4189private:
4190 static tree simplify_stmt (gimple *stmt, gimple *within_stmt,
4191 avail_exprs_stack *, basic_block);
4192 virtual edge before_dom_children (basic_block);
4193 virtual void after_dom_children (basic_block);
4194
4195 function *m_fun;
4196 vr_values *m_vr_values;
4197 const_and_copies *m_const_and_copies;
4198 avail_exprs_stack *m_avail_exprs_stack;
4199 hash_table<expr_elt_hasher> *m_avail_exprs;
4200 gcond *m_dummy_cond;
4201};
4202
4203vrp_jump_threader::vrp_jump_threader (struct function *fun, vr_values *v)
4204 : dom_walker (CDI_DOMINATORS, REACHABLE_BLOCKS)
4205{
4206 /* Ugh. When substituting values earlier in this pass we can wipe
4207 the dominance information. So rebuild the dominator information
4208 as we need it within the jump threading code. */
4209 calculate_dominance_info (CDI_DOMINATORS);
4210
4211 /* We do not allow VRP information to be used for jump threading
4212 across a back edge in the CFG. Otherwise it becomes too
4213 difficult to avoid eliminating loop exit tests. Of course
4214 EDGE_DFS_BACK is not accurate at this time so we have to
4215 recompute it. */
4216 mark_dfs_back_edges ();
4217
4218 /* Allocate our unwinder stack to unwind any temporary equivalences
4219 that might be recorded. */
4220 m_const_and_copies = new const_and_copies ();
4221
4222 m_dummy_cond = NULLnullptr;
4223 m_fun = fun;
4224 m_vr_values = v;
4225 m_avail_exprs = new hash_table<expr_elt_hasher> (1024);
4226 m_avail_exprs_stack = new avail_exprs_stack (m_avail_exprs);
4227}
4228
4229vrp_jump_threader::~vrp_jump_threader ()
4230{
4231 /* We do not actually update the CFG or SSA graphs at this point as
4232 ASSERT_EXPRs are still in the IL and cfg cleanup code does not
4233 yet handle ASSERT_EXPRs gracefully. */
4234 delete m_const_and_copies;
4235 delete m_avail_exprs;
4236 delete m_avail_exprs_stack;
4237}
4238
4239/* Called before processing dominator children of BB. We want to look
4240 at ASSERT_EXPRs and record information from them in the appropriate
4241 tables.
4242
4243 We could look at other statements here. It's not seen as likely
4244 to significantly increase the jump threads we discover. */
4245
4246edge
4247vrp_jump_threader::before_dom_children (basic_block bb)
4248{
4249 gimple_stmt_iterator gsi;
4250
4251 m_avail_exprs_stack->push_marker ();
4252 m_const_and_copies->push_marker ();
4253 for (gsi = gsi_start_nondebug_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
4254 {
4255 gimple *stmt = gsi_stmt (gsi);
4256 if (gimple_assign_single_p (stmt)
4257 && TREE_CODE (gimple_assign_rhs1 (stmt))((enum tree_code) (gimple_assign_rhs1 (stmt))->base.code) == ASSERT_EXPR)
4258 {
4259 tree rhs1 = gimple_assign_rhs1 (stmt);
4260 tree cond = TREE_OPERAND (rhs1, 1)(*((const_cast<tree*> (tree_operand_check ((rhs1), (1),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4260, __FUNCTION__)))))
;
4261 tree inverted = invert_truthvalue (cond)invert_truthvalue_loc (((location_t) 0), cond);
4262 vec<cond_equivalence> p;
4263 p.create (3);
4264 record_conditions (&p, cond, inverted);
4265 for (unsigned int i = 0; i < p.length (); i++)
4266 m_avail_exprs_stack->record_cond (&p[i]);
4267
4268 tree lhs = gimple_assign_lhs (stmt);
4269 m_const_and_copies->record_const_or_copy (lhs,
4270 TREE_OPERAND (rhs1, 0)(*((const_cast<tree*> (tree_operand_check ((rhs1), (0),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4270, __FUNCTION__)))))
);
4271 p.release ();
4272 continue;
4273 }
4274 break;
4275 }
4276 return NULLnullptr;
4277}
4278
4279/* A trivial wrapper so that we can present the generic jump threading
4280 code with a simple API for simplifying statements. STMT is the
4281 statement we want to simplify, WITHIN_STMT provides the location
4282 for any overflow warnings.
4283
4284 ?? This should be cleaned up. There's a virtually identical copy
4285 of this function in tree-ssa-dom.c. */
4286
4287tree
4288vrp_jump_threader::simplify_stmt (gimple *stmt,
4289 gimple *within_stmt,
4290 avail_exprs_stack *avail_exprs_stack,
4291 basic_block bb)
4292{
4293 /* First see if the conditional is in the hash table. */
4294 tree cached_lhs = avail_exprs_stack->lookup_avail_expr (stmt, false, true);
4295 if (cached_lhs && is_gimple_min_invariant (cached_lhs))
4296 return cached_lhs;
4297
4298 class vr_values *vr_values = x_vr_values;
4299 if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
4300 {
4301 tree op0 = gimple_cond_lhs (cond_stmt);
4302 op0 = lhs_of_dominating_assert (op0, bb, stmt);
4303
4304 tree op1 = gimple_cond_rhs (cond_stmt);
4305 op1 = lhs_of_dominating_assert (op1, bb, stmt);
4306
4307 simplify_using_ranges simplifier (vr_values);
4308 return simplifier.vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
4309 op0, op1, within_stmt);
4310 }
4311
4312 if (gswitch *switch_stmt = dyn_cast <gswitch *> (stmt))
4313 {
4314 tree op = gimple_switch_index (switch_stmt);
4315 if (TREE_CODE (op)((enum tree_code) (op)->base.code) != SSA_NAME)
4316 return NULL_TREE(tree) nullptr;
4317
4318 op = lhs_of_dominating_assert (op, bb, stmt);
4319
4320 const value_range_equiv *vr = vr_values->get_value_range (op);
4321 return find_case_label_range (switch_stmt, vr);
4322 }
4323
4324 if (gassign *assign_stmt = dyn_cast <gassign *> (stmt))
4325 {
4326 tree lhs = gimple_assign_lhs (assign_stmt);
4327 if (TREE_CODE (lhs)((enum tree_code) (lhs)->base.code) == SSA_NAME
4328 && (INTEGRAL_TYPE_P (TREE_TYPE (lhs))(((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4328, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4328, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4328, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
4329 || POINTER_TYPE_P (TREE_TYPE (lhs))(((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4329, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((lhs), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4329, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
)
4330 && stmt_interesting_for_vrp (stmt))
4331 {
4332 edge dummy_e;
4333 tree dummy_tree;
4334 value_range_equiv new_vr;
4335 vr_values->extract_range_from_stmt (stmt, &dummy_e,
4336 &dummy_tree, &new_vr);
4337 tree singleton;
4338 if (new_vr.singleton_p (&singleton))
4339 return singleton;
4340 }
4341 }
4342
4343 return NULL_TREE(tree) nullptr;
4344}
4345
4346/* Called after processing dominator children of BB. This is where we
4347 actually call into the threader. */
4348void
4349vrp_jump_threader::after_dom_children (basic_block bb)
4350{
4351 if (!m_dummy_cond)
4352 m_dummy_cond = gimple_build_cond (NE_EXPR,
4353 integer_zero_nodeglobal_trees[TI_INTEGER_ZERO], integer_zero_nodeglobal_trees[TI_INTEGER_ZERO],
4354 NULLnullptr, NULLnullptr);
4355
4356 x_vr_values = m_vr_values;
4357 thread_outgoing_edges (bb, m_dummy_cond, m_const_and_copies,
4358 m_avail_exprs_stack, NULLnullptr,
4359 simplify_stmt);
4360 x_vr_values = NULLnullptr;
4361
4362 m_avail_exprs_stack->pop_to_marker ();
4363 m_const_and_copies->pop_to_marker ();
4364}
4365
4366/* STMT is a conditional at the end of a basic block.
4367
4368 If the conditional is of the form SSA_NAME op constant and the SSA_NAME
4369 was set via a type conversion, try to replace the SSA_NAME with the RHS
4370 of the type conversion. Doing so makes the conversion dead which helps
4371 subsequent passes. */
4372
4373static void
4374vrp_simplify_cond_using_ranges (vr_values *query, gcond *stmt)
4375{
4376 tree op0 = gimple_cond_lhs (stmt);
4377 tree op1 = gimple_cond_rhs (stmt);
4378
4379 /* If we have a comparison of an SSA_NAME (OP0) against a constant,
4380 see if OP0 was set by a type conversion where the source of
4381 the conversion is another SSA_NAME with a range that fits
4382 into the range of OP0's type.
4383
4384 If so, the conversion is redundant as the earlier SSA_NAME can be
4385 used for the comparison directly if we just massage the constant in the
4386 comparison. */
4387 if (TREE_CODE (op0)((enum tree_code) (op0)->base.code) == SSA_NAME
4388 && TREE_CODE (op1)((enum tree_code) (op1)->base.code) == INTEGER_CST)
4389 {
4390 gimple *def_stmt = SSA_NAME_DEF_STMT (op0)(tree_check ((op0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4390, __FUNCTION__, (SSA_NAME)))->ssa_name.def_stmt
;
4391 tree innerop;
4392
4393 if (!is_gimple_assign (def_stmt)
4394 || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))((gimple_assign_rhs_code (def_stmt)) == NOP_EXPR || (gimple_assign_rhs_code
(def_stmt)) == CONVERT_EXPR)
)
4395 return;
4396
4397 innerop = gimple_assign_rhs1 (def_stmt);
4398
4399 if (TREE_CODE (innerop)((enum tree_code) (innerop)->base.code) == SSA_NAME
4400 && !POINTER_TYPE_P (TREE_TYPE (innerop))(((enum tree_code) (((contains_struct_check ((innerop), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4400, __FUNCTION__))->typed.type))->base.code) == POINTER_TYPE
|| ((enum tree_code) (((contains_struct_check ((innerop), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4400, __FUNCTION__))->typed.type))->base.code) == REFERENCE_TYPE
)
4401 && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop)(tree_check ((innerop), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4401, __FUNCTION__, (SSA_NAME)))->base.asm_written_flag
4402 && desired_pro_or_demotion_p (TREE_TYPE (innerop)((contains_struct_check ((innerop), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4402, __FUNCTION__))->typed.type)
, TREE_TYPE (op0)((contains_struct_check ((op0), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4402, __FUNCTION__))->typed.type)
))
4403 {
4404 const value_range *vr = query->get_value_range (innerop);
4405
4406 if (range_int_cst_p (vr)
4407 && range_fits_type_p (vr,
4408 TYPE_PRECISION (TREE_TYPE (op0))((tree_class_check ((((contains_struct_check ((op0), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4408, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4408, __FUNCTION__))->type_common.precision)
,
4409 TYPE_SIGN (TREE_TYPE (op0))((signop) ((tree_class_check ((((contains_struct_check ((op0)
, (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4409, __FUNCTION__))->typed.type)), (tcc_type), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4409, __FUNCTION__))->base.u.bits.unsigned_flag))
)
4410 && int_fits_type_p (op1, TREE_TYPE (innerop)((contains_struct_check ((innerop), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4410, __FUNCTION__))->typed.type)
))
4411 {
4412 tree newconst = fold_convert (TREE_TYPE (innerop), op1)fold_convert_loc (((location_t) 0), ((contains_struct_check (
(innerop), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4412, __FUNCTION__))->typed.type), op1)
;
4413 gimple_cond_set_lhs (stmt, innerop);
4414 gimple_cond_set_rhs (stmt, newconst);
4415 update_stmt (stmt);
4416 if (dump_file && (dump_flags & TDF_DETAILS))
4417 {
4418 fprintf (dump_file, "Folded into: ");
4419 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
4420 fprintf (dump_file, "\n");
4421 }
4422 }
4423 }
4424 }
4425}
4426
4427/* Main entry point to VRP (Value Range Propagation). This pass is
4428 loosely based on J. R. C. Patterson, ``Accurate Static Branch
4429 Prediction by Value Range Propagation,'' in SIGPLAN Conference on
4430 Programming Language Design and Implementation, pp. 67-78, 1995.
4431 Also available at http://citeseer.ist.psu.edu/patterson95accurate.html
4432
4433 This is essentially an SSA-CCP pass modified to deal with ranges
4434 instead of constants.
4435
4436 While propagating ranges, we may find that two or more SSA name
4437 have equivalent, though distinct ranges. For instance,
4438
4439 1 x_9 = p_3->a;
4440 2 p_4 = ASSERT_EXPR <p_3, p_3 != 0>
4441 3 if (p_4 == q_2)
4442 4 p_5 = ASSERT_EXPR <p_4, p_4 == q_2>;
4443 5 endif
4444 6 if (q_2)
4445
4446 In the code above, pointer p_5 has range [q_2, q_2], but from the
4447 code we can also determine that p_5 cannot be NULL and, if q_2 had
4448 a non-varying range, p_5's range should also be compatible with it.
4449
4450 These equivalences are created by two expressions: ASSERT_EXPR and
4451 copy operations. Since p_5 is an assertion on p_4, and p_4 was the
4452 result of another assertion, then we can use the fact that p_5 and
4453 p_4 are equivalent when evaluating p_5's range.
4454
4455 Together with value ranges, we also propagate these equivalences
4456 between names so that we can take advantage of information from
4457 multiple ranges when doing final replacement. Note that this
4458 equivalency relation is transitive but not symmetric.
4459
4460 In the example above, p_5 is equivalent to p_4, q_2 and p_3, but we
4461 cannot assert that q_2 is equivalent to p_5 because q_2 may be used
4462 in contexts where that assertion does not hold (e.g., in line 6).
4463
4464 TODO, the main difference between this pass and Patterson's is that
4465 we do not propagate edge probabilities. We only compute whether
4466 edges can be taken or not. That is, instead of having a spectrum
4467 of jump probabilities between 0 and 1, we only deal with 0, 1 and
4468 DON'T KNOW. In the future, it may be worthwhile to propagate
4469 probabilities to aid branch prediction. */
4470
4471static unsigned int
4472execute_vrp (struct function *fun, bool warn_array_bounds_p)
4473{
4474 loop_optimizer_init (LOOPS_NORMAL(LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_SIMPLE_LATCHES | LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS
)
| LOOPS_HAVE_RECORDED_EXITS);
4475 rewrite_into_loop_closed_ssa (NULLnullptr, TODO_update_ssa(1 << 11));
4476 scev_initialize ();
4477
4478 /* ??? This ends up using stale EDGE_DFS_BACK for liveness computation.
4479 Inserting assertions may split edges which will invalidate
4480 EDGE_DFS_BACK. */
4481 vrp_asserts assert_engine (fun);
4482 assert_engine.insert_range_assertions ();
4483
4484 threadedge_initialize_values ();
4485
4486 /* For visiting PHI nodes we need EDGE_DFS_BACK computed. */
4487 mark_dfs_back_edges ();
4488
4489 vr_values vrp_vr_values;
4490
4491 class vrp_prop vrp_prop (&vrp_vr_values);
4492 vrp_prop.initialize (fun);
4493 vrp_prop.ssa_propagate ();
4494
4495 /* Instantiate the folder here, so that edge cleanups happen at the
4496 end of this function. */
4497 vrp_folder folder (&vrp_vr_values);
4498 vrp_prop.finalize ();
4499
4500 /* If we're checking array refs, we want to merge information on
4501 the executability of each edge between vrp_folder and the
4502 check_array_bounds_dom_walker: each can clear the
4503 EDGE_EXECUTABLE flag on edges, in different ways.
4504
4505 Hence, if we're going to call check_all_array_refs, set
4506 the flag on every edge now, rather than in
4507 check_array_bounds_dom_walker's ctor; vrp_folder may clear
4508 it from some edges. */
4509 if (warn_array_boundsglobal_options.x_warn_array_bounds && warn_array_bounds_p)
4510 set_all_edges_as_executable (fun);
4511
4512 folder.substitute_and_fold ();
4513
4514 if (warn_array_boundsglobal_options.x_warn_array_bounds && warn_array_bounds_p)
4515 {
4516 array_bounds_checker array_checker (fun, &vrp_vr_values);
4517 array_checker.check ();
4518 }
4519
4520 /* We must identify jump threading opportunities before we release
4521 the datastructures built by VRP. */
4522 vrp_jump_threader threader (fun, &vrp_vr_values);
4523 threader.thread_jumps ();
4524
4525 /* A comparison of an SSA_NAME against a constant where the SSA_NAME
4526 was set by a type conversion can often be rewritten to use the
4527 RHS of the type conversion.
4528
4529 However, doing so inhibits jump threading through the comparison.
4530 So that transformation is not performed until after jump threading
4531 is complete. */
4532 basic_block bb;
4533 FOR_EACH_BB_FN (bb, fun)for (bb = (fun)->cfg->x_entry_block_ptr->next_bb; bb
!= (fun)->cfg->x_exit_block_ptr; bb = bb->next_bb)
4534 {
4535 gimple *last = last_stmt (bb);
4536 if (last && gimple_code (last) == GIMPLE_COND)
4537 vrp_simplify_cond_using_ranges (&vrp_vr_values,
4538 as_a <gcond *> (last));
4539 }
4540
4541 free_numbers_of_iterations_estimates (fun);
4542
4543 /* ASSERT_EXPRs must be removed before finalizing jump threads
4544 as finalizing jump threads calls the CFG cleanup code which
4545 does not properly handle ASSERT_EXPRs. */
4546 assert_engine.remove_range_assertions ();
4547
4548 /* If we exposed any new variables, go ahead and put them into
4549 SSA form now, before we handle jump threading. This simplifies
4550 interactions between rewriting of _DECL nodes into SSA form
4551 and rewriting SSA_NAME nodes into SSA form after block
4552 duplication and CFG manipulation. */
4553 update_ssa (TODO_update_ssa(1 << 11));
4554
4555 /* We identified all the jump threading opportunities earlier, but could
4556 not transform the CFG at that time. This routine transforms the
4557 CFG and arranges for the dominator tree to be rebuilt if necessary.
4558
4559 Note the SSA graph update will occur during the normal TODO
4560 processing by the pass manager. */
4561 thread_through_all_blocks (false);
4562
4563 threadedge_finalize_values ();
4564
4565 scev_finalize ();
4566 loop_optimizer_finalize ();
4567 return 0;
4568}
4569
4570namespace {
4571
4572const pass_data pass_data_vrp =
4573{
4574 GIMPLE_PASS, /* type */
4575 "vrp", /* name */
4576 OPTGROUP_NONE, /* optinfo_flags */
4577 TV_TREE_VRP, /* tv_id */
4578 PROP_ssa(1 << 5), /* properties_required */
4579 0, /* properties_provided */
4580 0, /* properties_destroyed */
4581 0, /* todo_flags_start */
4582 ( TODO_cleanup_cfg(1 << 5) | TODO_update_ssa(1 << 11) ), /* todo_flags_finish */
4583};
4584
4585class pass_vrp : public gimple_opt_pass
4586{
4587public:
4588 pass_vrp (gcc::context *ctxt)
4589 : gimple_opt_pass (pass_data_vrp, ctxt), warn_array_bounds_p (false)
4590 {}
4591
4592 /* opt_pass methods: */
4593 opt_pass * clone () { return new pass_vrp (m_ctxt); }
4594 void set_pass_param (unsigned int n, bool param)
4595 {
4596 gcc_assert (n == 0)((void)(!(n == 0) ? fancy_abort ("/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4596, __FUNCTION__), 0 : 0))
;
4597 warn_array_bounds_p = param;
4598 }
4599 virtual bool gate (function *) { return flag_tree_vrpglobal_options.x_flag_tree_vrp != 0; }
4600 virtual unsigned int execute (function *fun)
4601 { return execute_vrp (fun, warn_array_bounds_p); }
4602
4603 private:
4604 bool warn_array_bounds_p;
4605}; // class pass_vrp
4606
4607} // anon namespace
4608
4609gimple_opt_pass *
4610make_pass_vrp (gcc::context *ctxt)
4611{
4612 return new pass_vrp (ctxt);
4613}
4614
4615
4616/* Worker for determine_value_range. */
4617
4618static void
4619determine_value_range_1 (value_range *vr, tree expr)
4620{
4621 if (BINARY_CLASS_P (expr)(tree_code_type[(int) (((enum tree_code) (expr)->base.code
))] == tcc_binary)
)
4622 {
4623 value_range vr0, vr1;
4624 determine_value_range_1 (&vr0, TREE_OPERAND (expr, 0)(*((const_cast<tree*> (tree_operand_check ((expr), (0),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4624, __FUNCTION__)))))
);
4625 determine_value_range_1 (&vr1, TREE_OPERAND (expr, 1)(*((const_cast<tree*> (tree_operand_check ((expr), (1),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4625, __FUNCTION__)))))
);
4626 range_fold_binary_expr (vr, TREE_CODE (expr)((enum tree_code) (expr)->base.code), TREE_TYPE (expr)((contains_struct_check ((expr), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4626, __FUNCTION__))->typed.type)
,
4627 &vr0, &vr1);
4628 }
4629 else if (UNARY_CLASS_P (expr)(tree_code_type[(int) (((enum tree_code) (expr)->base.code
))] == tcc_unary)
)
4630 {
4631 value_range vr0;
4632 determine_value_range_1 (&vr0, TREE_OPERAND (expr, 0)(*((const_cast<tree*> (tree_operand_check ((expr), (0),
"/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4632, __FUNCTION__)))))
);
4633 range_fold_unary_expr (vr, TREE_CODE (expr)((enum tree_code) (expr)->base.code), TREE_TYPE (expr)((contains_struct_check ((expr), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4633, __FUNCTION__))->typed.type)
,
4634 &vr0, TREE_TYPE (TREE_OPERAND (expr, 0))((contains_struct_check (((*((const_cast<tree*> (tree_operand_check
((expr), (0), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4634, __FUNCTION__)))))), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4634, __FUNCTION__))->typed.type)
);
4635 }
4636 else if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) == INTEGER_CST)
4637 vr->set (expr);
4638 else
4639 {
4640 value_range_kind kind;
4641 wide_int min, max;
4642 /* For SSA names try to extract range info computed by VRP. Otherwise
4643 fall back to varying. */
4644 if (TREE_CODE (expr)((enum tree_code) (expr)->base.code) == SSA_NAME
4645 && INTEGRAL_TYPE_P (TREE_TYPE (expr))(((enum tree_code) (((contains_struct_check ((expr), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4645, __FUNCTION__))->typed.type))->base.code) == ENUMERAL_TYPE
|| ((enum tree_code) (((contains_struct_check ((expr), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4645, __FUNCTION__))->typed.type))->base.code) == BOOLEAN_TYPE
|| ((enum tree_code) (((contains_struct_check ((expr), (TS_TYPED
), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4645, __FUNCTION__))->typed.type))->base.code) == INTEGER_TYPE
)
4646 && (kind = get_range_info (expr, &min, &max)) != VR_VARYING)
4647 vr->set (wide_int_to_tree (TREE_TYPE (expr)((contains_struct_check ((expr), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4647, __FUNCTION__))->typed.type)
, min),
4648 wide_int_to_tree (TREE_TYPE (expr)((contains_struct_check ((expr), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4648, __FUNCTION__))->typed.type)
, max),
4649 kind);
4650 else
4651 vr->set_varying (TREE_TYPE (expr)((contains_struct_check ((expr), (TS_TYPED), "/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-clang-static-analyzer/build/gcc/tree-vrp.c"
, 4651, __FUNCTION__))->typed.type)
);
4652 }
4653}
4654
4655/* Compute a value-range for EXPR and set it in *MIN and *MAX. Return
4656 the determined range type. */
4657
4658value_range_kind
4659determine_value_range (tree expr, wide_int *min, wide_int *max)
4660{
4661 value_range vr;
4662 determine_value_range_1 (&vr, expr);
4663 if (vr.constant_p ())
4664 {
4665 *min = wi::to_wide (vr.min ());
4666 *max = wi::to_wide (vr.max ());
4667 return vr.kind ();
4668 }
4669
4670 return VR_VARYING;
4671}