]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/ChangeLog
38efe591d7a79058f07d15bf34acd1660b429ffe
[thirdparty/gcc.git] / gcc / analyzer / ChangeLog
1 2024-03-21 David Malcolm <dmalcolm@redhat.com>
2
3 PR analyzer/113619
4 * region-model.cc (region_model::eval_condition): Fix
5 cast-handling from r14-3632-ge7b267444045c5 so that if those give
6 an unknown result, we continue trying the constraint manager.
7
8 2024-03-20 David Malcolm <dmalcolm@redhat.com>
9
10 PR analyzer/109251
11 * sm-malloc.cc (deref_before_check::emit): Reject cases where the
12 check is in a loop header within a macro expansion.
13 (deref_before_check::loop_header_p): New.
14
15 2024-03-20 Jakub Jelinek <jakub@redhat.com>
16
17 * constraint-manager.cc (test_range, test_constraint_conditions,
18 test_constant_comparisons, test_constraint_impl, test_purging,
19 test_bits): Use integer_zero_node instead of
20 build_zero_cst (integer_type_node) or
21 build_int_cst (integer_type_node, 0) and integer_one_node instead of
22 build_int_cst (integer_type_node, 1).
23 * region-model.cc (region_model::get_store_value,
24 append_interesting_constants, test_array_1,
25 test_get_representative_tree, test_unique_constants, test_assignment,
26 test_stack_frames, test_constraint_merging, test_widening_constraints,
27 test_iteration_1, test_array_2): Likewise.
28
29 2024-03-19 Jakub Jelinek <jakub@redhat.com>
30
31 PR analyzer/113505
32 * region-model.cc (get_tree_for_byte_offset,
33 region_model::get_representative_path_var_1,
34 test_mem_ref, test_POINTER_PLUS_EXPR_then_MEM_REF): Use
35 char __attribute__((may_alias)) * as type of MEM_REF second argument.
36
37 2024-03-19 David Malcolm <dmalcolm@redhat.com>
38
39 PR analyzer/114286
40 * kf.cc (class kf_atomic_exchange): Reimplement based on signature
41 seen in gimple, rather than user-facing signature.
42 (class kf_atomic_load): Likewise.
43 (class kf_atomic_store): New.
44 (register_atomic_builtins): Register kf_atomic_store.
45
46 2024-03-18 David Malcolm <dmalcolm@redhat.com>
47
48 PR analyzer/110902
49 PR analyzer/110928
50 PR analyzer/111305
51 PR analyzer/111441
52 * access-diagram.cc: Include "analyzer/analyzer-selftests.h".
53 (get_access_size_str): Reimplement for conversion of
54 implmementation of bit_size_expr from tree to const svalue &. Use
55 svalue::maybe_print_for_user rather than tree printing routines.
56 (remove_ssa_names): Make non-static.
57 (bit_size_expr::get_formatted_str): Rename to...
58 (bit_size_expr::maybe_get_formatted_str): ...this, adding "model"
59 param and converting return type to a unique_ptr. Update for
60 conversion of implementation of bit_size_expr from tree to
61 const svalue &. Use svalue::maybe_print_for_user rather than tree
62 printing routines.
63 (bit_size_expr::print): Rename to...
64 (bit_size_expr::maybe_print_for_user): ...this, adding "model"
65 param and converting return type to bool. Update for
66 conversion of implementation of bit_size_expr from tree to
67 const svalue &. Use svalue::maybe_print_for_user rather than tree
68 printing routines.
69 (bit_size_expr::maybe_get_as_bytes): Add "mgr" param and convert
70 return type from tree to const svalue *; reimplement.
71 (access_range::access_range): Call strip_types when on region_offset
72 intializations.
73 (access_range::get_size): Update for conversion of implementation
74 of bit_size_expr from tree to const svalue &.
75 (access_operation::get_valid_bits): Pass manager to access_range
76 ctor.
77 (access_operation::maybe_get_invalid_before_bits): Likewise.
78 (access_operation::maybe_get_invalid_after_bits): Likewise.
79 (boundaries::add): Likewise.
80 (bit_to_table_map::populate): Add "mgr" param and pass it to
81 access_range ctor.
82 (access_diagram_impl::access_diagram_impl): Pass manager to
83 bit_to_table_map::populate.
84 (access_diagram_impl::maybe_add_gap): Use svalue rather than tree
85 for symbolic bit offsets. Port to new bit_size_expr
86 representation.
87 (access_diagram_impl::add_valid_vs_invalid_ruler): Port to new
88 bit_size_expr representation.
89 (selftest::assert_eq_typeless_integer): New.
90 (ASSERT_EQ_TYPELESS_INTEGER): New.
91 (selftest::test_bit_size_expr_to_bytes): New.
92 (selftest::analyzer_access_diagram_cc_tests): New.
93 * access-diagram.h (class bit_size_expr): Reimplement, converting
94 implementation from tree to const svalue &.
95 (access_range::access_range): Add "mgr" param. Call strip_types
96 on region_offset initializations.
97 (access_range::get_size): Update decl for reimplementation.
98 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
99 selftest::analyzer_access_diagram_cc_tests.
100 * analyzer-selftests.h
101 (selftest::analyzer_checker_script_cc_tests): Delete this stray
102 typo.
103 (selftest::analyzer_access_diagram_cc_tests): New decl.
104 * analyzer.h (print_expr_for_user): New decl.
105 (calc_symbolic_bit_offset): Update decl for reimplementation.
106 (strip_types): New decls.
107 (remove_ssa_names): New decl.
108 * bounds-checking.cc (strip_types): New.
109 (region_model::check_symbolic_bounds): Use typeless svalues.
110 * region-model-manager.cc
111 (region_model_manager::get_or_create_constant_svalue): Add "type"
112 param. Add overload with old signature.
113 (region_model_manager::get_or_create_int_cst): Support type being
114 NULL_TREE.
115 (region_model_manager::maybe_fold_unaryop): Gracefully reject folding
116 of casts to NULL_TREE type.
117 (get_code_for_cast): Use NOP_EXPR for "casting" svalues to
118 NULL_TREE type.
119 (region_model_manager::get_or_create_cast): Support "casting"
120 svalues to NULL_TREE type.
121 (region_model_manager::maybe_fold_binop): Don't crash on inputs
122 with NULL_TREE type. Handle folding of binops on constants with
123 NULL_TREE type. Add missing cast from PR analyzer/110902.
124 Support enough folding of other ops on NULL_TREE type to support
125 bounds checking.
126 (region_model_manager::get_or_create_const_fn_result_svalue):
127 Remove assertion that type is nonnull.
128 * region-model-manager.h
129 (region_model_manager::get_or_create_constant_svalue): Add
130 overloaded decl taking a type.
131 (region_model_manager::maybe_fold_binop): Make public.
132 (region_model_manager::constants_map_t): Use
133 constant_svalue::key_t for the key, rather than just tree.
134 * region-model.cc (print_expr_for_user): New.
135 (selftest::test_array_2): Handle casts.
136 * region.cc (region_offset::calc_symbolic_bit_offset): Return
137 const svalue & rather than tree, and reimplement accordingly.
138 (region::calc_offset): Use ptrdiff_type_node for types of byte
139 offsets.
140 (region::maybe_print_for_user): New.
141 (element_region::get_relative_symbolic_offset): Use NULL_TREE for
142 types of bit offsets.
143 (offset_region::get_bit_offset): Likewise.
144 (sized_region::get_bit_size_sval): Likewise for bit sizes.
145 * region.h (region::maybe_print_for_user): New decl.
146 * svalue.cc (class auto_add_parens): New.
147 (svalue::maybe_print_for_user): New.
148 (svalue::cmp_ptr): Support typeless constant svalues.
149 (tristate_from_boolean_tree_node): New, taken from...
150 (constant_svalue::eval_condition): ...here. Handle comparison of
151 typeless integer svalue constants.
152 * svalue.h (svalue::maybe_print_for_user): New decl.
153 (class constant_svalue): Support the type of the svalue being
154 NULL_TREE.
155 (struct default_hash_traits<constant_svalue::key_t>): New.
156
157 2024-03-18 David Malcolm <dmalcolm@redhat.com>
158
159 * access-diagram.cc (remove_ssa_names): Support operands being
160 NULL_TREE, such as e.g. for COMPONENT_REF's operand 2.
161
162 2024-03-07 Jakub Jelinek <jakub@redhat.com>
163
164 * access-diagram.cc: Include diagnostic-core.h before including
165 diagnostic.h or diagnostic-path.h.
166 * sm-malloc.cc: Likewise.
167 * diagnostic-manager.cc: Likewise.
168 * call-summary.cc: Likewise.
169 * record-layout.cc: Likewise.
170
171 2024-02-29 David Malcolm <dmalcolm@redhat.com>
172
173 PR analyzer/114159
174 * analyzer.cc: Include "tree-dfa.h".
175 (get_ssa_default_def): New decl.
176 * analyzer.h (get_ssa_default_def): New.
177 * call-info.cc (call_info::call_info): New ctor taking an explicit
178 called_fn.
179 * call-info.h (call_info::call_info): Likewise.
180 * call-summary.cc (call_summary_replay::call_summary_replay):
181 Convert param from function * to const function &.
182 * call-summary.h (call_summary_replay::call_summary_replay):
183 Likewise.
184 * checker-event.h (state_change_event::get_dest_function):
185 Constify return value.
186 * engine.cc (point_and_state::validate): Update for conversion to
187 const function &.
188 (exploded_node::on_stmt): Likewise.
189 (call_summary_edge_info::call_summary_edge_info): Likewise.
190 Pass in called_fn to call_info ctor.
191 (exploded_node::replay_call_summaries): Update for conversion to
192 const function &. Convert per_function_data from * to &.
193 (exploded_node::replay_call_summary): Update for conversion to
194 const function &.
195 (exploded_graph::add_function_entry): Likewise.
196 (toplevel_function_p): Likewise.
197 (add_tainted_args_callback): Likewise.
198 (exploded_graph::build_initial_worklist): Likewise.
199 (exploded_graph::maybe_create_dynamic_call): Likewise.
200 (maybe_update_for_edge): Likewise.
201 (exploded_graph::on_escaped_function): Likewise.
202 * exploded-graph.h (exploded_node::replay_call_summaries):
203 Likewise.
204 (exploded_node::replay_call_summary): Likewise.
205 (exploded_graph::add_function_entry): Likewise.
206 * program-point.cc (function_point::from_function_entry):
207 Likewise.
208 (program_point::from_function_entry): Likewise.
209 * program-point.h (function_point::from_function_entry): Likewise.
210 (program_point::from_function_entry): Likewise.
211 * program-state.cc (program_state::push_frame): Likewise.
212 (program_state::get_current_function): Constify return type.
213 * program-state.h (program_state::push_frame): Update for
214 conversion to const function &.
215 (program_state::get_current_function): Likewise.
216 * region-model-manager.cc
217 (region_model_manager::get_frame_region): Likewise.
218 * region-model-manager.h
219 (region_model_manager::get_frame_region): Likewise.
220 * region-model.cc (region_model::called_from_main_p): Likewise.
221 (region_model::update_for_gcall): Likewise.
222 (region_model::push_frame): Likewise.
223 (region_model::get_current_function): Constify return type.
224 (region_model::pop_frame): Update for conversion to
225 const function &.
226 (selftest::test_stack_frames): Likewise.
227 (selftest::test_get_representative_path_var): Likewise.
228 (selftest::test_state_merging): Likewise.
229 (selftest::test_alloca): Likewise.
230 * region-model.h (region_model::push_frame): Likewise.
231 (region_model::get_current_function): Likewise.
232 * region.cc (frame_region::dump_to_pp): Likewise.
233 (frame_region::get_region_for_local): Likewise.
234 * region.h (class frame_region): Likewise.
235 * sm-signal.cc (signal_unsafe_call::describe_state_change):
236 Likewise.
237 (update_model_for_signal_handler): Likewise.
238 (signal_delivery_edge_info_t::update_model): Likewise.
239 (register_signal_handler::impl_transition): Likewise.
240 * state-purge.cc (class gimple_op_visitor): Likewise.
241 (state_purge_map::state_purge_map): Likewise.
242 (state_purge_map::get_or_create_data_for_decl): Likewise.
243 (state_purge_per_ssa_name::state_purge_per_ssa_name): Likewise.
244 (state_purge_per_ssa_name::add_to_worklist): Likewise.
245 (state_purge_per_ssa_name::process_point): Likewise.
246 (state_purge_per_decl::add_to_worklist): Likewise.
247 (state_purge_annotator::print_needed): Likewise.
248 * state-purge.h
249 (state_purge_map::get_or_create_data_for_decl): Likewise.
250 (class state_purge_per_tree): Likewise.
251 (class state_purge_per_ssa_name): Likewise.
252 (class state_purge_per_decl): Likewise.
253 * supergraph.cc (supergraph::dump_dot_to_pp): Likewise.
254 * supergraph.h
255 (supergraph::get_node_for_function_entry): Likewise.
256 (supergraph::get_node_for_function_exit): Likewise.
257
258 2024-02-27 David Malcolm <dmalcolm@redhat.com>
259
260 PR analyzer/110483
261 PR analyzer/111802
262 * access-diagram.cc
263 (string_literal_spatial_item::add_column_for_byte): Use %wu for
264 printing unsigned HOST_WIDE_INT.
265
266 2024-02-27 David Malcolm <dmalcolm@redhat.com>
267
268 PR analyzer/111881
269 * constraint-manager.cc (bound::ensure_closed): Assert that
270 m_constant has integral type.
271 (range::add_bound): Bail out on floating point constants.
272
273 2024-02-21 David Malcolm <dmalcolm@redhat.com>
274
275 PR analyzer/113999
276 * analyzer.h (get_string_cst_size): New decl.
277 * region-model-manager.cc (get_string_cst_size): New.
278 (region_model_manager::maybe_get_char_from_string_cst): Treat
279 single-byte accesses within string_cst but beyond
280 TREE_STRING_LENGTH as being 0.
281 * region-model.cc (string_cst_has_null_terminator): Likewise.
282
283 2024-02-21 David Malcolm <dmalcolm@redhat.com>
284
285 PR analyzer/113998
286 * ranges.cc (symbolic_byte_range::intersection): Handle empty ranges.
287 (selftest::test_intersects): Add test coverage for empty ranges.
288
289 2024-02-19 David Malcolm <dmalcolm@redhat.com>
290
291 PR analyzer/111289
292 * varargs.cc (representable_in_integral_type_p): New.
293 (va_arg_compatible_types_p): Add "arg_sval" param. Handle integer
294 types.
295 (kf_va_arg::impl_call_pre): Pass arg_sval to
296 va_arg_compatible_types_p.
297
298 2024-02-19 Andrew Pinski <quic_apinski@quicinc.com>
299
300 PR analyzer/113983
301 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Reject
302 non integral types.
303
304 2024-02-15 David Malcolm <dmalcolm@redhat.com>
305
306 PR analyzer/111266
307 * region.cc (offset_region::get_byte_size_sval): Delete.
308 (offset_region::get_bit_size_sval): Delete.
309 * region.h (region::get_byte_size): Add comment clarifying that
310 this relates to the size of the access, rather than the size
311 that's valid to access.
312 (region::get_bit_size): Likewise.
313 (region::get_byte_size_sval): Likewise.
314 (region::get_bit_size_sval): Likewise.
315 (offset_region::get_byte_size_sval): Delete.
316 (offset_region::get_bit_size_sval): Delete.
317
318 2024-02-13 David Malcolm <dmalcolm@redhat.com>
319
320 * pending-diagnostic.cc (diagnostic_emission_context::warn):
321 Update for renaming of emit_diagnostic_valist overload to
322 emit_diagnostic_valist_meta.
323 (diagnostic_emission_context::inform): Likewise.
324
325 2024-01-31 David Malcolm <dmalcolm@redhat.com>
326
327 PR analyzer/113253
328 * region-model.cc (region_model::on_stmt_pre): Add gcc_unreachable
329 for debug statements.
330 * state-purge.cc
331 (state_purge_per_ssa_name::state_purge_per_ssa_name): Skip any
332 debug stmts in the FOR_EACH_IMM_USE_FAST list.
333 * supergraph.cc (supergraph::supergraph): Don't add debug stmts
334 to the supernodes.
335
336 2024-01-31 David Malcolm <dmalcolm@redhat.com>
337
338 PR analyzer/113509
339 * checker-event.cc (state_change_event::get_desc): Don't assume
340 "var" is non-NULL.
341
342 2024-01-30 David Malcolm <dmalcolm@redhat.com>
343
344 PR analyzer/113654
345 * region-model.cc (is_round_up): New.
346 (is_multiple_p): New.
347 (is_dubious_capacity): New.
348 (region_model::check_region_size): Move usage of size_visitor into
349 is_dubious_capacity.
350
351 2024-01-30 David Malcolm <dmalcolm@redhat.com>
352
353 * region-model.cc
354 (dubious_allocation_size::dubious_allocation_size): Add
355 "capacity_sval" param. Drop unused ctor.
356 (dubious_allocation_size::maybe_add_sarif_properties): New.
357 (dubious_allocation_size::m_capacity_sval): New field.
358 (region_model::check_region_size): Pass capacity svalue to
359 dubious_allocation_size ctor.
360
361 2024-01-25 David Malcolm <dmalcolm@redhat.com>
362
363 PR analyzer/112969
364 * store.cc (binding_cluster::maybe_get_compound_binding): When
365 populating default_map, express the bit-range of the default key
366 for REG relative to REG, rather than to the base region.
367
368 2024-01-24 David Malcolm <dmalcolm@redhat.com>
369
370 PR analyzer/112977
371 * engine.cc (impl_region_model_context::on_liveness_change): Pass
372 m_ext_state to sm_state_map::on_liveness_change.
373 * program-state.cc (sm_state_map::on_svalue_leak): Guard removal
374 of map entry based on can_purge_p.
375 (sm_state_map::on_liveness_change): Add ext_state param. Add
376 workaround for bad interaction between state purging and
377 alt-inherited sm-state.
378 * program-state.h (sm_state_map::on_liveness_change): Add
379 ext_state param.
380 * sm-taint.cc
381 (taint_state_machine::has_alt_get_inherited_state_p): New.
382 (taint_state_machine::can_purge_p): Return false for "has_lb" and
383 "has_ub".
384 * sm.h (state_machine::has_alt_get_inherited_state_p): New vfunc.
385
386 2024-01-18 David Malcolm <dmalcolm@redhat.com>
387
388 PR analyzer/111361
389 * region-model.cc (svalue_byte_range_has_null_terminator_1): The
390 initial byte of an all-zeroes SVAL is a zero byte. Remove
391 gcc_unreachable from SK_CONSTANT for constants that aren't
392 STRING_CST or INTEGER_CST.
393
394 2024-01-18 David Malcolm <dmalcolm@redhat.com>
395
396 PR analyzer/112811
397 * region-model.cc (fragment::dump_to_pp): New.
398 (fragment::has_null_terminator): Convert to...
399 (svalue_byte_range_has_null_terminator_1): ...this new function,
400 updating to use a byte_range relative to the start of the svalue.
401 (svalue_byte_range_has_null_terminator): New.
402 (fragment::string_cst_has_null_terminator): Convert to...
403 (string_cst_has_null_terminator): ...this, updating to use a
404 byte_range relative to the start of the svalue.
405 (iterable_cluster::dump_to_pp): New.
406 (region_model::scan_for_null_terminator): Add logging, moving body
407 to...
408 (region_model::scan_for_null_terminator_1): ...this new function,
409 adding more logging, and updating to use
410 svalue_byte_range_has_null_terminator.
411 * region-model.h (region_model::scan_for_null_terminator_1): New
412 decl.
413
414 2024-01-16 David Malcolm <dmalcolm@redhat.com>
415
416 PR analyzer/106229
417 * analyzer.h (compare_constants): New decl.
418 * constraint-manager.cc (compare_constants): Make non-static.
419 * sm-taint.cc: Add include "fold-const.h".
420 (class concrete_range): New.
421 (get_possible_range): New.
422 (index_can_be_out_of_bounds_p): New.
423 (region_model::check_region_for_taint): Reject
424 -Wanalyzer-tainted-array-index if the type of the value makes it
425 impossible for it to be out-of-bounds of the array.
426
427 2024-01-16 David Malcolm <dmalcolm@redhat.com>
428
429 PR analyzer/113333
430 * region-model-manager.cc
431 (region_model_manager::maybe_fold_unaryop): Casting all zeroes
432 should give all zeroes.
433
434 2024-01-04 David Malcolm <dmalcolm@redhat.com>
435
436 * analyzer.opt.urls: New file, autogenerated by
437 regenerate-opt-urls.py.
438
439 2024-01-04 David Malcolm <dmalcolm@redhat.com>
440
441 * checker-event.cc: Include "diagnostic-format-sarif.h" and
442 "tree-logical-location.h".
443 (checker_event::maybe_add_sarif_properties): New.
444 (superedge_event::maybe_add_sarif_properties): New.
445 (superedge_event::superedge_event): Add comment.
446 * checker-event.h (checker_event::maybe_add_sarif_properties): New
447 decl.
448 (superedge_event::maybe_add_sarif_properties): New decl.
449
450 2024-01-04 David Malcolm <dmalcolm@redhat.com>
451
452 PR analyzer/112790
453 * checker-event.cc (class inlining_info): Move to...
454 * inlining-iterator.h (class inlining_info): ...here.
455 * sm-malloc.cc: Include "analyzer/inlining-iterator.h".
456 (maybe_complain_about_deref_before_check): Reject stmts that were
457 inlined from another function.
458
459 2024-01-04 David Malcolm <dmalcolm@redhat.com>
460
461 PR analyzer/113222
462 * access-diagram.cc (valid_region_spatial_item::add_boundaries):
463 Handle TYPE_DOMAIN being null.
464 (valid_region_spatial_item::add_array_elements_to_table):
465 Likewise.
466
467 2023-12-16 David Malcolm <dmalcolm@redhat.com>
468
469 * analyzer.cc: Include "tree-pretty-print.h" and
470 "diagnostic-event-id.h".
471 (tree_to_json): New.
472 (diagnostic_event_id_to_json): New.
473 (bit_offset_to_json): New.
474 (byte_offset_to_json): New.
475 * analyzer.h (tree_to_json): New decl.
476 (diagnostic_event_id_to_json): New decl.
477 (bit_offset_to_json): New decl.
478 (byte_offset_to_json): New decl.
479 * bounds-checking.cc: Include "diagnostic-format-sarif.h".
480 (out_of_bounds::maybe_add_sarif_properties): New.
481 (concrete_out_of_bounds::maybe_add_sarif_properties): New.
482 (concrete_past_the_end::maybe_add_sarif_properties): New.
483 (symbolic_past_the_end::maybe_add_sarif_properties): New.
484 * region-model.cc (region_to_value_map::to_json): New.
485 (region_model::to_json): New.
486 * region-model.h (region_to_value_map::to_json): New decl.
487 (region_model::to_json): New decl.
488 * store.cc (bit_range::to_json): New.
489 (byte_range::to_json): New.
490 * store.h (bit_range::to_json): New decl.
491 (byte_range::to_json): New decl.
492
493 2023-12-16 David Malcolm <dmalcolm@redhat.com>
494
495 PR analyzer/112792
496 * bounds-checking.cc
497 (out_of_bounds::oob_region_creation_event_capacity): Rename
498 "capacity" to "byte_capacity". Layout fix.
499 (out_of_bounds::::add_region_creation_events): Rename
500 "capacity" to "byte_capacity".
501 (class concrete_out_of_bounds): Rename m_out_of_bounds_range to
502 m_out_of_bounds_bits and convert from a byte_range to a bit_range.
503 (concrete_out_of_bounds::get_out_of_bounds_bytes): New.
504 (concrete_past_the_end::concrete_past_the_end): Rename param
505 "byte_bound" to "bit_bound". Initialize m_byte_bound.
506 (concrete_past_the_end::subclass_equal_p): Update for renaming
507 of m_byte_bound to m_bit_bound.
508 (concrete_past_the_end::m_bit_bound): New field.
509 (concrete_buffer_overflow::concrete_buffer_overflow): Convert
510 param "range" from byte_range to bit_range. Rename param
511 "byte_bound" to "bit_bound".
512 (concrete_buffer_overflow::emit): Update for bits vs bytes.
513 (concrete_buffer_overflow::describe_final_event): Split
514 into...
515 (concrete_buffer_overflow::describe_final_event_as_bytes): ...this
516 (concrete_buffer_overflow::describe_final_event_as_bits): ...and
517 this.
518 (concrete_buffer_over_read::concrete_buffer_over_read): Convert
519 param "range" from byte_range to bit_range. Rename param
520 "byte_bound" to "bit_bound".
521 (concrete_buffer_over_read::emit): Update for bits vs bytes.
522 (concrete_buffer_over_read::describe_final_event): Split into...
523 (concrete_buffer_over_read::describe_final_event_as_bytes):
524 ...this
525 (concrete_buffer_over_read::describe_final_event_as_bits): ...and
526 this.
527 (concrete_buffer_underwrite::concrete_buffer_underwrite): Convert
528 param "range" from byte_range to bit_range.
529 (concrete_buffer_underwrite::describe_final_event): Split into...
530 (concrete_buffer_underwrite::describe_final_event_as_bytes):
531 ...this
532 (concrete_buffer_underwrite::describe_final_event_as_bits): ...and
533 this.
534 (concrete_buffer_under_read::concrete_buffer_under_read): Convert
535 param "range" from byte_range to bit_range.
536 (concrete_buffer_under_read::describe_final_event): Split into...
537 (concrete_buffer_under_read::describe_final_event_as_bytes):
538 ...this
539 (concrete_buffer_under_read::describe_final_event_as_bits): ...and
540 this.
541 (region_model::check_region_bounds): Use bits for concrete values,
542 and rename locals to indicate whether we're dealing with bits or
543 bytes. Specifically, replace "num_bytes_sval" with
544 "num_bits_sval", and get it from reg's "get_bit_size_sval".
545 Replace "num_bytes_tree" with "num_bits_tree". Rename "capacity"
546 to "byte_capacity". Rename "cst_capacity_tree" to
547 "cst_byte_capacity_tree". Replace "offset" and
548 "num_bytes_unsigned" with "bit_offset" and "num_bits_unsigned"
549 respectively, converting from byte_offset_t to bit_offset_t.
550 Replace "out" and "read_bytes" with "bits_outside" and "read_bits"
551 respectively, converting from byte_range to bit_range. Convert
552 "buffer" from byte_range to bit_range. Replace "byte_bound" with
553 "bit_bound".
554 * region.cc (region::get_bit_size_sval): New.
555 (offset_region::get_bit_offset): New.
556 (offset_region::get_bit_size_sval): New.
557 (sized_region::get_bit_size_sval): New.
558 (bit_range_region::get_bit_size_sval): New.
559 * region.h (region::get_bit_size_sval): New vfunc.
560 (offset_region::get_bit_offset): New decl.
561 (offset_region::get_bit_size_sval): New decl.
562 (sized_region::get_bit_size_sval): New decl.
563 (bit_range_region::get_bit_size_sval): New decl.
564 * store.cc (bit_range::intersects_p): New, based on
565 byte_range::intersects_p.
566 (bit_range::exceeds_p): New, based on byte_range::exceeds_p.
567 (bit_range::falls_short_of_p): New, based on
568 byte_range::falls_short_of_p.
569 (byte_range::intersects_p): Delete.
570 (byte_range::exceeds_p): Delete.
571 (byte_range::falls_short_of_p): Delete.
572 * store.h (bit_range::intersects_p): New overload.
573 (bit_range::exceeds_p): New.
574 (bit_range::falls_short_of_p): New.
575 (byte_range::intersects_p): Delete.
576 (byte_range::exceeds_p): Delete.
577 (byte_range::falls_short_of_p): Delete.
578
579 2023-12-14 David Malcolm <dmalcolm@redhat.com>
580
581 PR analyzer/112655
582 * infinite-loop.cc (infinite_loop::infinite_loop): Pass eedges
583 via rvalue reference rather than by value.
584 (starts_infinite_loop_p): Move eedges when constructing an
585 infinite_loop instance.
586 * sm-file.cc (fileptr_state_machine::fileptr_state_machine): Use
587 initializer list for states.
588 * sm-sensitive.cc
589 (sensitive_state_machine::sensitive_state_machine): Likewise.
590 * sm-signal.cc (signal_state_machine::signal_state_machine):
591 Likewise.
592 * sm-taint.cc (taint_state_machine::taint_state_machine):
593 Likewise.
594 * varargs.cc (va_list_state_machine::va_list_state_machine): Likewise.
595
596 2023-12-11 David Malcolm <dmalcolm@redhat.com>
597
598 PR analyzer/112955
599 * engine.cc (feasibility_state::feasibility_state): Initialize
600 m_snodes_visited.
601
602 2023-12-11 Andrew Pinski <apinski@marvell.com>
603
604 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Remove
605 the check for type being unsigned_char_type_node.
606
607 2023-12-08 David Malcolm <dmalcolm@redhat.com>
608
609 * sm-taint.cc (taint_state_machine::alt_get_inherited_state): Fix
610 handling of TRUNC_MOD_EXPR.
611
612 2023-12-08 David Malcolm <dmalcolm@redhat.com>
613
614 * region-model.cc (contains_uninit_p): Only check for
615 svalues that the infoleak warning can handle.
616
617 2023-12-08 David Malcolm <dmalcolm@redhat.com>
618
619 PR analyzer/112889
620 * store.h (concrete_binding::concrete_binding): Strengthen
621 assertion to require size to be be positive, rather than just
622 non-zero.
623 (concrete_binding::mark_deleted): Use size rather than start bit
624 offset.
625 (concrete_binding::mark_empty): Likewise.
626 (concrete_binding::is_deleted): Likewise.
627 (concrete_binding::is_empty): Likewise.
628
629 2023-12-07 Alexandre Oliva <oliva@adacore.com>
630
631 * region-model.cc (has_nondefault_case_for_value_p): Take
632 enumerate type as a parameter.
633 (region_model::apply_constraints_for_gswitch): Cope with
634 integral promotion type casts.
635
636 2023-12-07 David Malcolm <dmalcolm@redhat.com>
637
638 PR analyzer/103546
639 PR analyzer/112850
640 * analyzer.opt (-param=analyzer-max-svalue-depth=): Increase from
641 12 to 18.
642 (Wanalyzer-symbol-too-complex): New.
643 * diagnostic-manager.cc
644 (null_assignment_sm_context::clear_all_per_svalue_state): New.
645 * engine.cc (impl_sm_context::clear_all_per_svalue_state): New.
646 * program-state.cc (sm_state_map::clear_all_per_svalue_state):
647 New.
648 * program-state.h (sm_state_map::clear_all_per_svalue_state): New
649 decl.
650 * region-model-manager.cc
651 (region_model_manager::reject_if_too_complex): Add
652 -Wanalyzer-symbol-too-complex.
653 * sm-taint.cc (taint_state_machine::on_condition): Handle
654 comparisons against UNKNOWN.
655 * sm.h (sm_context::clear_all_per_svalue_state): New.
656
657 2023-12-06 David Malcolm <dmalcolm@redhat.com>
658
659 * engine.cc (dump_analyzer_json): Use
660 flag_diagnostics_json_formatting.
661
662 2023-12-01 David Malcolm <dmalcolm@redhat.com>
663
664 * analyzer.h (class saved_diagnostic): New forward decl.
665 * bounds-checking.cc: Update for changes to
666 pending_diagnostic::emit.
667 * call-details.cc: Likewise.
668 * diagnostic-manager.cc: Include "diagnostic-format-sarif.h".
669 (saved_diagnostic::maybe_add_sarif_properties): New.
670 (class pending_diagnostic_metadata): New.
671 (diagnostic_manager::emit_saved_diagnostic): Create a
672 pending_diagnostic_metadata and a diagnostic_emission_context.
673 Pass the latter to the pending_diagnostic::emit vfunc.
674 * diagnostic-manager.h
675 (saved_diagnostic::maybe_add_sarif_properties): New decl.
676 * engine.cc: Update for changes to pending_diagnostic::emit.
677 * infinite-loop.cc: Likewise.
678 * infinite-recursion.cc: Likewise.
679 * kf-analyzer.cc: Likewise.
680 * kf.cc: Likewise.
681 * pending-diagnostic.cc
682 (diagnostic_emission_context::get_pending_diagnostic): New.
683 (diagnostic_emission_context::warn): New.
684 (diagnostic_emission_context::inform): New.
685 * pending-diagnostic.h (class diagnostic_emission_context): New.
686 (pending_diagnostic::emit): Update params.
687 (pending_diagnostic::maybe_add_sarif_properties): New vfunc.
688 * region.cc: Don't include "diagnostic-metadata.h".
689 * region-model.cc: Include "diagnostic-format-sarif.h". Update
690 for changes to pending_diagnostic::emit.
691 (exposure_through_uninit_copy::maybe_add_sarif_properties): New.
692 * sm-fd.cc: Update for changes to pending_diagnostic::emit.
693 * sm-file.cc: Likewise.
694 * sm-malloc.cc: Likewise.
695 * sm-pattern-test.cc: Likewise.
696 * sm-sensitive.cc: Likewise.
697 * sm-signal.cc: Likewise.
698 * sm-taint.cc: Likewise.
699 * store.cc: Don't include "diagnostic-metadata.h".
700 * varargs.cc: Update for changes to pending_diagnostic::emit.
701
702 2023-11-19 David Malcolm <dmalcolm@redhat.com>
703
704 * analyzer.h: Include "rich-location.h".
705
706 2023-11-19 David Malcolm <dmalcolm@redhat.com>
707
708 PR analyzer/107573
709 * analyzer.h (register_known_functions): Add region_model_manager
710 param.
711 * analyzer.opt (Wanalyzer-undefined-behavior-strtok): New.
712 * call-summary.cc
713 (call_summary_replay::convert_region_from_summary_1): Handle
714 RK_PRIVATE.
715 * engine.cc (impl_run_checkers): Pass model manager to
716 register_known_functions.
717 * kf.cc (class undefined_function_behavior): New.
718 (class kf_strtok): New.
719 (register_known_functions): Add region_model_manager param.
720 Use it to register "strtok".
721 * region-model-manager.cc
722 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
723 param.
724 * region-model-manager.h
725 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
726 param.
727 (region_model_manager::get_root_region): New accessor.
728 * region-model.cc (region_model::scan_for_null_terminator): Handle
729 "expr" being null.
730 (region_model::get_representative_path_var_1): Handle RK_PRIVATE.
731 * region-model.h (region_model::called_from_main_p): Make public.
732 * region.cc (region::get_memory_space): Handle RK_PRIVATE.
733 (region::can_have_initial_svalue_p): Handle MEMSPACE_PRIVATE.
734 (private_region::dump_to_pp): New.
735 * region.h (MEMSPACE_PRIVATE): New.
736 (RK_PRIVATE): New.
737 (class private_region): New.
738 (is_a_helper <const private_region *>::test): New.
739 * store.cc (store::replay_call_summary_cluster): Handle
740 RK_PRIVATE.
741 * svalue.h (struct conjured_svalue::key_t): Add "idx" param to
742 ctor and "m_idx" field.
743 (class conjured_svalue::conjured_svalue): Likewise.
744
745 2023-11-18 David Malcolm <dmalcolm@redhat.com>
746
747 PR analyzer/106147
748 * analyzer.opt (Wanalyzer-infinite-loop): New option.
749 (fdump-analyzer-infinite-loop): New option.
750 * checker-event.h (start_cfg_edge_event::get_desc): Drop "final".
751 (start_cfg_edge_event::maybe_describe_condition): Convert from
752 private to protected.
753 * checker-path.h (checker_path::get_logger): New.
754 * diagnostic-manager.cc (process_worklist_item): Update for
755 new context param of maybe_update_for_edge.
756 * engine.cc
757 (impl_region_model_context::impl_region_model_context): Add
758 out_could_have_done_work param to both ctors and use it to
759 initialize mm_out_could_have_done_work.
760 (impl_region_model_context::maybe_did_work): New vfunc
761 implementation.
762 (exploded_node::on_stmt): Add out_could_have_done_work param and
763 pass to ctxt ctor.
764 (exploded_node::on_stmt_pre): Treat setjmp and longjmp as "doing
765 work".
766 (exploded_node::on_longjmp): Likewise.
767 (exploded_edge::exploded_edge): Add "could_do_work" param and use
768 it to initialize m_could_do_work_p.
769 (exploded_edge::dump_dot_label): Add result of could_do_work_p.
770 (exploded_graph::add_function_entry): Mark edge as doing no work.
771 (exploded_graph::add_edge): Add "could_do_work" param and pass to
772 exploded_edge ctor.
773 (add_tainted_args_callback): Treat as doing no work.
774 (exploded_graph::process_worklist): Likewise when merging nodes.
775 (maybe_process_run_of_before_supernode_enodes::item): Likewise.
776 (exploded_graph::maybe_create_dynamic_call): Likewise.
777 (exploded_graph::process_node): Likewise for phi nodes.
778 Pass in a "could_have_done_work" bool when handling stmts and use
779 when creating edges. Assume work is done at bifurcation.
780 (exploded_path::feasible_p): Update for new context param of
781 maybe_update_for_edge.
782 (feasibility_state::feasibility_state): New ctor.
783 (feasibility_state::operator=): New.
784 (feasibility_state::maybe_update_for_edge): Add ctxt param and use
785 it. Fix missing newline when logging state.
786 (impl_run_checkers): Call exploded_graph::detect_infinite_loops.
787 * exploded-graph.h
788 (impl_region_model_context::impl_region_model_context): Add
789 out_could_have_done_work param to both ctors.
790 (impl_region_model_context::maybe_did_work): New decl.
791 (impl_region_model_context::checking_for_infinite_loop_p): New.
792 (impl_region_model_context::on_unusable_in_infinite_loop): New.
793 (impl_region_model_context::m_out_could_have_done_work): New
794 field.
795 (exploded_node::on_stmt): Add "out_could_have_done_work" param.
796 (exploded_edge::exploded_edge): Add "could_do_work" param.
797 (exploded_edge::could_do_work_p): New accessor.
798 (exploded_edge::m_could_do_work_p): New field.
799 (exploded_graph::add_edge): Add "could_do_work" param.
800 (exploded_graph::detect_infinite_loops): New decl.
801 (feasibility_state::feasibility_state): New ctor.
802 (feasibility_state::operator=): New decl.
803 (feasibility_state::maybe_update_for_edge): Add ctxt param.
804 * infinite-loop.cc: New file.
805 * program-state.cc (program_state::on_edge): Log the rejected
806 constraint when region_model::maybe_update_for_edge fails.
807 * region-model.cc (region_model::on_assignment): Treat any writes
808 other than to the stack as "doing work".
809 (region_model::on_stmt_pre): Treat all asm stmts as "doing work".
810 (region_model::on_call_post): Likewise for all calls to functions
811 with unknown side effects.
812 (region_model::handle_phi): Add svals_changing_meaning param.
813 Mark widening svalue in phi nodes as changing meaning.
814 (unusable_in_infinite_loop_constraint_p): New.
815 (region_model::add_constraint): If we're checking for an infinite
816 loop, bail out on unusable svalues, or if we don't have a definite
817 true/false for the constraint.
818 (region_model::update_for_phis): Gather all svalues changing
819 meaning in phi nodes, and purge constraints involving them.
820 (region_model::replay_call_summary): Treat all call summaries as
821 doing work.
822 (region_model::can_merge_with_p): Purge constraints involving
823 svalues that change meaning.
824 (model_merger::on_widening_reuse): New.
825 (test_iteration_1): Likewise.
826 (selftest::test_iteration_1): Remove assertion that model6 "knows"
827 that i < 157.
828 * region-model.h (region_model::handle_phi): Add
829 svals_changing_meaning param
830 (region_model_context::maybe_did_work): New pure virtual func.
831 (region_model_context::checking_for_infinite_loop_p): Likewise.
832 (region_model_context::on_unusable_in_infinite_loop): Likewise.
833 (noop_region_model_context::maybe_did_work): Implement.
834 (noop_region_model_context::checking_for_infinite_loop_p):
835 Likewise.
836 (noop_region_model_context::on_unusable_in_infinite_loop):
837 Likewise.
838 (region_model_context_decorator::maybe_did_work): Implement.
839 (region_model_context_decorator::checking_for_infinite_loop_p):
840 Likewise.
841 (region_model_context_decorator::on_unusable_in_infinite_loop):
842 Likewise.
843 (model_merger::on_widening_reuse): New decl.
844 (model_merger::m_svals_changing_meaning): New field.
845 * sm-signal.cc (register_signal_handler::impl_transition): Assume
846 the edge "does work".
847 * supergraph.cc (supernode::get_start_location): Use CFG edge's
848 goto_locus if available.
849 (supernode::get_end_location): Likewise.
850 (cfg_superedge::dump_label_to_pp): Dump edges with a "goto_locus"
851 * supergraph.h (cfg_superedge::get_goto_locus): New.
852 * svalue.cc (svalue::can_merge_p): Call on_widening_reuse for
853 widening values.
854 (involvement_visitor::visit_widening_svalue): New.
855 (svalue::involves_p): Update assertion to allow widening svalues.
856
857 2023-11-14 David Malcolm <dmalcolm@redhat.com>
858
859 PR analyzer/103533
860 * sm-taint.cc: Remove "experimental" from comment.
861 * sm.cc (make_checkers): Always add taint state machine.
862
863 2023-11-04 David Malcolm <dmalcolm@redhat.com>
864
865 * bounds-checking.cc: Update for changes to diagnostic_context.
866
867 2023-11-02 David Malcolm <dmalcolm@redhat.com>
868
869 PR analyzer/112317
870 * access-diagram.cc (class x_aligned_x_ruler_widget): Eliminate
871 unused field "m_col_widths".
872 (access_diagram_impl::add_valid_vs_invalid_ruler): Update for
873 above change.
874 * region-model.cc
875 (check_one_function_attr_null_terminated_string_arg): Remove
876 unused variables "cd_unchecked", "strlen_sval", and
877 "limited_sval".
878 * region-model.h (region_model_context_decorator::warn): Add
879 missing "override".
880
881 2023-10-31 David Malcolm <dmalcolm@redhat.com>
882
883 * record-layout.cc: New file, based on material in region-model.cc.
884 * record-layout.h: Likewise.
885 * region-model.cc: Include "analyzer/record-layout.h".
886 (class record_layout): Move to record-layout.cc and .h
887
888 2023-10-26 David Malcolm <dmalcolm@redhat.com>
889
890 * region-model.cc
891 (region_model::check_external_function_for_access_attr): Split
892 out, replacing with...
893 (region_model::check_function_attr_access): ...this new function
894 and...
895 (region_model::check_function_attrs): ...this new function.
896 (region_model::check_one_function_attr_null_terminated_string_arg):
897 New.
898 (region_model::check_function_attr_null_terminated_string_arg):
899 New.
900 (region_model::handle_unrecognized_call): Update for renaming of
901 check_external_function_for_access_attr to check_function_attrs.
902 (region_model::check_for_null_terminated_string_arg): Add return
903 value to one overload. Make both overloads const.
904 * region-model.h: Include "stringpool.h" and "attribs.h".
905 (region_model::check_for_null_terminated_string_arg): Add return
906 value to one overload. Make both overloads const.
907 (region_model::check_external_function_for_access_attr): Delete
908 decl.
909 (region_model::check_function_attr_access): New decl.
910 (region_model::check_function_attr_null_terminated_string_arg):
911 New decl.
912 (region_model::check_one_function_attr_null_terminated_string_arg):
913 New decl.
914 (region_model::check_function_attrs): New decl.
915
916 2023-10-09 David Malcolm <dmalcolm@redhat.com>
917
918 * access-diagram.cc (boundaries::add): Explicitly state
919 "boundaries::" scope for "kind" enum.
920
921 2023-10-08 David Malcolm <dmalcolm@redhat.com>
922
923 PR analyzer/111155
924 * access-diagram.cc (boundaries::boundaries): Add logger param
925 (boundaries::add): Add logging.
926 (boundaries::get_hard_boundaries_in_range): New.
927 (boundaries::m_logger): New field.
928 (boundaries::get_table_x_for_offset): Make public.
929 (class svalue_spatial_item): New.
930 (class compound_svalue_spatial_item): New.
931 (add_ellipsis_to_gaps): New.
932 (valid_region_spatial_item::valid_region_spatial_item): Add theme
933 param. Initialize m_boundaries, m_existing_sval, and
934 m_existing_sval_spatial_item.
935 (valid_region_spatial_item::add_boundaries): Set m_boundaries.
936 Add boundaries for any m_existing_sval_spatial_item.
937 (valid_region_spatial_item::add_array_elements_to_table): Rewrite
938 creation of min/max index in terms of
939 maybe_add_array_index_to_table. Rewrite ellipsis code using
940 add_ellipsis_to_gaps. Add index values for any hard boundaries
941 within the valid region.
942 (valid_region_spatial_item::maybe_add_array_index_to_table): New,
943 based on code formerly in add_array_elements_to_table.
944 (valid_region_spatial_item::make_table): Make use of
945 m_existing_sval_spatial_item, if any.
946 (valid_region_spatial_item::m_boundaries): New field.
947 (valid_region_spatial_item::m_existing_sval): New field.
948 (valid_region_spatial_item::m_existing_sval_spatial_item): New
949 field.
950 (class svalue_spatial_item): Rename to...
951 (class written_svalue_spatial_item): ...this.
952 (class string_region_spatial_item): Rename to..
953 (class string_literal_spatial_item): ...this. Add "kind".
954 (string_literal_spatial_item::add_boundaries): Use m_kind to
955 determine kind of boundary. Update for renaming of m_actual_bits
956 to m_bits.
957 (string_literal_spatial_item::make_table): Likewise. Support not
958 displaying a row for byte indexes, and not displaying a row for
959 the type.
960 (string_literal_spatial_item::add_column_for_byte): Make byte index
961 row optional.
962 (svalue_spatial_item::make): Convert to...
963 (make_written_svalue_spatial_item): ...this.
964 (make_existing_svalue_spatial_item): New.
965 (access_diagram_impl::access_diagram_impl): Pass theme to
966 m_valid_region_spatial_item ctor. Update for renaming of
967 m_svalue_spatial_item.
968 (access_diagram_impl::find_boundaries): Pass logger to boundaries.
969 Update for renaming of...
970 (access_diagram_impl::m_svalue_spatial_item): Rename to...
971 (access_diagram_impl::m_written_svalue_spatial_item): ...this.
972
973 2023-10-03 David Malcolm <dmalcolm@redhat.com>
974
975 * analyzer-logging.cc (logger::log_va_partial): Use text_info
976 ctor.
977 * analyzer.cc (make_label_text): Likewise.
978 (make_label_text_n): Likewise.
979 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
980 Likewise.
981
982 2023-10-02 David Malcolm <dmalcolm@redhat.com>
983
984 * program-point.cc: Update for grouping of source printing fields
985 within diagnostic_context.
986
987 2023-09-15 David Malcolm <dmalcolm@redhat.com>
988
989 * analyzer.cc (get_stmt_location): Handle null stmt.
990 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Copy
991 m_loc from ploc.
992 (saved_diagnostic::operator==): Compare m_loc.
993 (saved_diagnostic::calc_best_epath): Only use m_stmt_finder if
994 m_loc is unknown.
995 (dedupe_key::dedupe_key): Initialize m_loc.
996 (dedupe_key::operator==): Compare m_loc.
997 (dedupe_key::get_location): Use m_loc if it's known.
998 (dedupe_key::m_loc): New field.
999 (diagnostic_manager::emit_saved_diagnostic): Only call
1000 get_emission_location if m_loc is unknown, preferring to use m_loc
1001 if it's available.
1002 * diagnostic-manager.h (saved_diagnostic::m_loc): New field.
1003 (pending_location::pending_location): Initialize m_loc. Add
1004 overload taking a location_t rather than a stmt/stmt_finder.
1005 (pending_location::m_loc): New field.
1006
1007 2023-09-15 David Malcolm <dmalcolm@redhat.com>
1008
1009 * analyzer.h (struct pending_location): New forward decl.
1010 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
1011 Replace params "enode", "snode", "stmt", and "stmt_finder" with
1012 "ploc".
1013 (diagnostic_manager::add_diagnostic): Likewise for both overloads.
1014 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
1015 Likewise.
1016 (struct pending_location): New.
1017 (diagnostic_manager::add_diagnostic): Replace params "enode",
1018 "snode", "stmt", and "stmt_finder" with "ploc".
1019 * engine.cc (impl_region_model_context::warn): Update call to
1020 add_diagnostic for above change.
1021 (impl_sm_context::warn): Likewise.
1022 (impl_region_model_context::on_state_leak): Likewise.
1023 * infinite-recursion.cc
1024 (exploded_graph::detect_infinite_recursion): Likewise.
1025
1026 2023-09-15 David Malcolm <dmalcolm@redhat.com>
1027
1028 * region-model.cc (region_model::get_gassign_result): Handle
1029 volatile ops by using a conjured_svalue.
1030
1031 2023-09-14 David Malcolm <dmalcolm@redhat.com>
1032
1033 * checker-event.h (checker_event::get_thread_id): New.
1034 * checker-path.h (class checker_path): Implement thread-related
1035 vfuncs via a single simple_diagnostic_thread instance named
1036 "main".
1037
1038 2023-09-14 David Malcolm <dmalcolm@redhat.com>
1039
1040 * diagnostic-manager.cc (compatible_epath_p): Fix missing return.
1041
1042 2023-09-14 David Malcolm <dmalcolm@redhat.com>
1043
1044 * diagnostic-manager.cc (process_worklist_item): Use
1045 std::unique_ptr rather than plain rejected_constraint *.
1046 * engine.cc (exploded_path::feasible_p): Likewise.
1047 (feasibility_state::maybe_update_for_edge): Likewise.
1048 * exploded-graph.h (feasibility_problem::feasibility_problem):
1049 Likewise.
1050 (feasibility_problem::~feasibility_problem): Delete.
1051 (feasibility_problem::m_rc): Use std::unique_ptr.
1052 (feasibility_state::maybe_update_for_edge): Likewise.
1053 * feasible-graph.cc (feasible_graph::add_feasibility_problem):
1054 Likewise.
1055 * feasible-graph.h (class infeasible_node): Likewise.
1056 (feasible_graph::add_feasibility_problem): Likewise.
1057 * region-model.cc (region_model::add_constraint): Likewise.
1058 (region_model::maybe_update_for_edge): Likewise.
1059 (region_model::apply_constraints_for_gcond): Likewise.
1060 (region_model::apply_constraints_for_gswitch): Likewise.
1061 (region_model::apply_constraints_for_exception): Likewise.
1062 * region-model.h (class region_model): Likewise for decls.
1063
1064 2023-09-09 benjamin priour <vultkayn@gcc.gnu.org>
1065
1066 PR analyzer/96395
1067 * region-model.cc
1068 (region_model::add_constraints_from_binop): binop_svalues around
1069 LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR are now unwrapped.
1070
1071 2023-09-07 David Malcolm <dmalcolm@redhat.com>
1072
1073 PR analyzer/110529
1074 * program-point.cc (program_point::on_edge): Don't reject
1075 EDGE_ABNORMAL for computed gotos.
1076 * region-model.cc (region_model::maybe_update_for_edge): Handle
1077 computed goto statements.
1078 (region_model::apply_constraints_for_ggoto): New.
1079 * region-model.h (region_model::apply_constraints_for_ggoto): New decl.
1080 * supergraph.cc (supernode::get_label): New.
1081 * supergraph.h (supernode::get_label): New decl.
1082
1083 2023-09-07 benjamin priour <vultkayn@gcc.gnu.org>
1084 David Malcolm <dmalcolm@redhat.com>
1085
1086 PR analyzer/110830
1087 * diagnostic-manager.cc
1088 (compatible_epaths_p): New function.
1089 (saved_diagnostic::supercedes_p): Now calls the above
1090 to determine if the diagnostics do overlap and the superseding
1091 may proceed.
1092
1093 2023-09-07 David Malcolm <dmalcolm@redhat.com>
1094
1095 * region-model.h: fix -Wunused-parameter warnings
1096
1097 2023-09-06 David Malcolm <dmalcolm@redhat.com>
1098
1099 PR analyzer/105899
1100 * kf.cc (class kf_strstr): New.
1101 (kf_strstr::impl_call_post): New.
1102 (register_known_functions): Register it.
1103
1104 2023-09-06 David Malcolm <dmalcolm@redhat.com>
1105
1106 PR analyzer/105899
1107 * kf.cc (class kf_strncpy): New.
1108 (kf_strncpy::impl_call_post): New.
1109 (register_known_functions): Register it.
1110 * region-model.cc (region_model::read_bytes): Handle unknown
1111 number of bytes.
1112
1113 2023-09-06 David Malcolm <dmalcolm@redhat.com>
1114
1115 * kf.cc (kf_calloc::impl_call_pre): Pass ctxt to zero_fill_region.
1116 (kf_memset::impl_call_pre): Move responsibility for calling
1117 check_region_for_write to fill_region.
1118 * region-model.cc (region_model::on_assignment): Pass ctxt to
1119 zero_fill_region.
1120 (region_model::fill_region): Add "ctxt" param, using it to call
1121 check_region_for_write.
1122 (region_model::zero_fill_region): Likewise.
1123 * region-model.h (region_model::fill_region): Add "ctxt" param.
1124 (region_model::zero_fill_region): Likewise.
1125
1126 2023-09-01 benjamin priour <priour.be@gmail.com>
1127
1128 PR analyzer/105948
1129 PR analyzer/94355
1130 * analyzer.h (is_placement_new_p): New declaration.
1131 * call-details.cc
1132 (call_details::deref_ptr_arg): New function.
1133 Dereference the argument at given index if possible.
1134 * call-details.h: Declaration of the above function.
1135 * kf-lang-cp.cc (is_placement_new_p): Returns true if the gcall
1136 is recognized as a placement new.
1137 (kf_operator_delete::impl_call_post): Unbinding a region and its
1138 descendents now poisons with POISON_KIND_DELETED.
1139 (register_known_functions_lang_cp): Known function "operator
1140 delete" is now registered only once independently of its number of
1141 arguments.
1142 * region-model.cc (region_model::eval_condition): Now
1143 recursively calls itself if any of the operand is wrapped in a
1144 cast.
1145 * sm-malloc.cc (malloc_state_machine::on_stmt):
1146 Add placement new recognition.
1147 * svalue.cc (poison_kind_to_str): Wording for the new PK.
1148 * svalue.h (enum poison_kind): Add value POISON_KIND_DELETED.
1149
1150 2023-08-31 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
1151
1152 * kf.cc: Change spelling to macOS.
1153
1154 2023-08-30 Eric Feng <ef2648@columbia.edu>
1155
1156 PR analyzer/107646
1157 * engine.cc (impl_region_model_context::warn): New optional
1158 parameter.
1159 * exploded-graph.h (class impl_region_model_context): Likewise.
1160 * region-model.cc (region_model::pop_frame): New callback
1161 feature for region_model::pop_frame.
1162 * region-model.h (struct append_regions_cb_data): Likewise.
1163 (class region_model): Likewise.
1164 (class region_model_context): New optional parameter.
1165 (class region_model_context_decorator): Likewise.
1166
1167 2023-08-30 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
1168
1169 * region-model.cc: Define INCLUDE_ALGORITHM.
1170
1171 2023-08-29 David Malcolm <dmalcolm@redhat.com>
1172
1173 PR analyzer/99860
1174 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
1175 selftest::analyzer_ranges_cc_tests.
1176 * analyzer-selftests.h (selftest::run_analyzer_selftests): New
1177 decl.
1178 * analyzer.opt (Wanalyzer-overlapping-buffers): New option.
1179 * call-details.cc: Include "analyzer/ranges.h" and "make-unique.h".
1180 (class overlapping_buffers): New.
1181 (call_details::complain_about_overlap): New.
1182 * call-details.h (call_details::complain_about_overlap): New decl.
1183 * kf.cc (kf_memcpy_memmove::impl_call_pre): Call
1184 cd.complain_about_overlap for memcpy and memcpy_chk.
1185 (kf_strcat::impl_call_pre): Call cd.complain_about_overlap.
1186 (kf_strcpy::impl_call_pre): Likewise.
1187 * ranges.cc: New file.
1188 * ranges.h: New file.
1189
1190 2023-08-29 David Malcolm <dmalcolm@redhat.com>
1191
1192 PR analyzer/105899
1193 * kf.cc (kf_strdup::impl_call_pre): Set size of
1194 dynamically-allocated buffer. Simulate copying the string from
1195 the source region to the new buffer.
1196
1197 2023-08-27 benjamin priour <vultkayn@gcc.gnu.org>
1198
1199 PR analyzer/96395
1200 * analyzer.h (class known_function): Add virtual casts
1201 to builtin_known_function.
1202 (class builtin_known_function): New subclass of known_function
1203 for builtins.
1204 * kf.cc (class kf_alloca): Now derived from
1205 builtin_known_function.
1206 (class kf_calloc): Likewise.
1207 (class kf_free): Likewise.
1208 (class kf_malloc): Likewise.
1209 (class kf_memcpy_memmove): Likewise.
1210 (class kf_memset): Likewise.
1211 (class kf_realloc): Likewise.
1212 (class kf_strchr): Likewise.
1213 (class kf_sprintf): Likewise.
1214 (class kf_strcat): Likewise.
1215 (class kf_strcpy): Likewise.
1216 (class kf_strdup): Likewise.
1217 (class kf_strlen): Likewise.
1218 (class kf_strndup): Likewise.
1219 (register_known_functions): Builtins are now registered as
1220 known_functions by name rather than by their BUILTIN_CODE.
1221 * known-function-manager.cc (get_normal_builtin): New overload.
1222 * known-function-manager.h: New overload declaration.
1223 * region-model.cc (region_model::get_builtin_kf): New function.
1224 * region-model.h (class region_model): Add declaration of
1225 get_builtin_kf.
1226 * sm-fd.cc: For called recognized as builtins, use the
1227 attributes of that builtin as defined in gcc/builtins.def
1228 rather than the user's.
1229 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
1230
1231 2023-08-25 David Malcolm <dmalcolm@redhat.com>
1232
1233 * access-diagram.cc (class string_region_spatial_item): Remove
1234 assumption that the string is written to the start of the cluster.
1235
1236 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1237
1238 PR analyzer/105899
1239 * call-details.cc
1240 (call_details::check_for_null_terminated_string_arg): Split into
1241 overloads, one taking just an arg_idx, the other a new
1242 "include_terminator" param.
1243 * call-details.h: Likewise.
1244 * kf.cc (class kf_strcat): New.
1245 (kf_strcpy::impl_call_pre): Update for change to
1246 check_for_null_terminated_string_arg.
1247 (register_known_functions): Register kf_strcat.
1248 * region-model.cc
1249 (region_model::check_for_null_terminated_string_arg): Split into
1250 overloads, one taking just an arg_idx, the other a new
1251 "include_terminator" param. When returning an svalue, handle
1252 "include_terminator" being false by subtracting one.
1253 * region-model.h
1254 (region_model::check_for_null_terminated_string_arg): Split into
1255 overloads, one taking just an arg_idx, the other a new
1256 "include_terminator" param.
1257
1258 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1259
1260 PR analyzer/105899
1261 * region-model.cc (fragment::has_null_terminator): Handle
1262 SK_BITS_WITHIN.
1263
1264 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1265
1266 PR analyzer/105899
1267 * region-model-manager.cc
1268 (region_model_manager::get_or_create_initial_value): Simplify
1269 INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) to
1270 CONSTANT_SVAL(STRING[N]).
1271
1272 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1273
1274 PR analyzer/105899
1275 * region-model.cc (fragment::has_null_terminator): Move STRING_CST
1276 handling to fragment::string_cst_has_null_terminator; also use it to
1277 handle INIT_VAL(STRING_REG).
1278 (fragment::string_cst_has_null_terminator): New, from above.
1279
1280 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1281
1282 * kf.cc (kf_memcpy_memmove::impl_call_pre): Reimplement using
1283 region_model::copy_bytes.
1284 * region-model.cc (region_model::read_bytes): New.
1285 (region_model::copy_bytes): New.
1286 * region-model.h (region_model::read_bytes): New decl.
1287 (region_model::copy_bytes): New decl.
1288
1289 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1290
1291 PR analyzer/105899
1292 * region-model.cc (region_model::get_string_size): Delete both.
1293 * region-model.h (region_model::get_string_size): Delete both
1294 decls.
1295
1296 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1297
1298 PR analyzer/105899
1299 * kf.cc (kf_strcpy::impl_call_pre): Reimplement using
1300 check_for_null_terminated_string_arg.
1301 * region-model.cc (region_model::get_store_bytes): Shortcut
1302 reading all of a string_region.
1303 (region_model::scan_for_null_terminator): Use get_store_value for
1304 the bytes rather than "unknown" when returning an unknown length.
1305 (region_model::write_bytes): New.
1306 * region-model.h (region_model::write_bytes): New decl.
1307
1308 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1309
1310 PR analyzer/105899
1311 * region-model.cc (iterable_cluster::iterable_cluster): Add
1312 symbolic binding keys to m_symbolic_bindings.
1313 (iterable_cluster::has_symbolic_bindings_p): New.
1314 (iterable_cluster::m_symbolic_bindings): New field.
1315 (region_model::scan_for_null_terminator): Treat clusters with
1316 symbolic bindings as having unknown strlen.
1317
1318 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1319
1320 * engine.cc (impl_path_context::impl_path_context): Add logger
1321 param.
1322 (impl_path_context::bifurcate): Add log message.
1323 (impl_path_context::terminate_path): Likewise.
1324 (impl_path_context::m_logger): New field.
1325 (exploded_graph::process_node): Pass logger to path_ctxt ctor.
1326
1327 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1328
1329 PR analyzer/105899
1330 * kf-analyzer.cc (class kf_analyzer_get_strlen): Move to kf.cc.
1331 (register_known_analyzer_functions): Use make_kf_strlen.
1332 * kf.cc (class kf_strlen::impl_call_pre): Replace with
1333 implementation of kf_analyzer_get_strlen from kf-analyzer.cc.
1334 Handle "UNKNOWN" return from check_for_null_terminated_string_arg
1335 by falling back to a conjured svalue.
1336 (make_kf_strlen): New.
1337 (register_known_functions): Use make_kf_strlen.
1338 * known-function-manager.h (make_kf_strlen): New decl.
1339
1340 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1341
1342 PR analyzer/105899
1343 * call-details.cc (call_details::call_details): New ctor.
1344 * call-details.h (call_details::call_details): New ctor decl.
1345 (struct call_arg_details): Move here from region-model.cc.
1346 * region-model.cc (region_model::check_call_format_attr): New.
1347 (region_model::check_call_args): Call it.
1348 (struct call_arg_details): Move it to call-details.h.
1349 * region-model.h (region_model::check_call_format_attr): New decl.
1350
1351 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1352
1353 * kf.cc (class kf_fopen): New.
1354 (register_known_functions): Register it.
1355
1356 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1357
1358 PR analyzer/105899
1359 * analyzer.opt (Wanalyzer-unterminated-string): Delete.
1360 * call-details.cc
1361 (call_details::check_for_null_terminated_string_arg): Convert
1362 return type from void to const svalue *. Add param "out_sval".
1363 * call-details.h
1364 (call_details::check_for_null_terminated_string_arg): Likewise.
1365 * kf-analyzer.cc (kf_analyzer_get_strlen::impl_call_pre): Wire up
1366 to result of check_for_null_terminated_string_arg.
1367 * region-model.cc (get_strlen): Delete.
1368 (class unterminated_string_arg): Delete.
1369 (struct fragment): New.
1370 (class iterable_cluster): New.
1371 (region_model::get_store_bytes): New.
1372 (get_tree_for_byte_offset): New.
1373 (region_model::scan_for_null_terminator): New.
1374 (region_model::check_for_null_terminated_string_arg): Convert
1375 return type from void to const svalue *. Add param "out_sval".
1376 Reimplement in terms of scan_for_null_terminator, dropping the
1377 special-case for -Wanalyzer-unterminated-string.
1378 * region-model.h (region_model::get_store_bytes): New decl.
1379 (region_model::scan_for_null_terminator): New decl.
1380 (region_model::check_for_null_terminated_string_arg): Convert
1381 return type from void to const svalue *. Add param "out_sval".
1382 * store.cc (concrete_binding::get_byte_range): New.
1383 * store.h (concrete_binding::get_byte_range): New decl.
1384 (store_manager::get_concrete_binding): New overload.
1385
1386 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1387
1388 * region-model.cc (region_model_context_decorator::add_event):
1389 Handle m_inner being NULL.
1390 * region-model.h (class region_model_context_decorator): Likewise.
1391 (annotating_context::warn): Likewise.
1392
1393 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1394
1395 * diagnostic-manager.cc (saved_diagnostic::add_event): New.
1396 (saved_diagnostic::add_any_saved_events): New.
1397 (diagnostic_manager::add_event): New.
1398 (dedupe_winners::emit_best): New.
1399 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
1400 non-const. Call saved_diagnostic::add_any_saved_events.
1401 * diagnostic-manager.h (saved_diagnostic::add_event): New decl.
1402 (saved_diagnostic::add_any_saved_events): New decl.
1403 (saved_diagnostic::m_saved_events): New field.
1404 (diagnostic_manager::add_event): New decl.
1405 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
1406 non-const.
1407 * engine.cc (impl_region_model_context::add_event): New.
1408 * exploded-graph.h (impl_region_model_context::add_event): New decl.
1409 * region-model.cc
1410 (noop_region_model_context::add_event): New.
1411 (region_model_context_decorator::add_event): New.
1412 * region-model.h (region_model_context::add_event): New vfunc.
1413 (noop_region_model_context::add_event): New decl.
1414 (region_model_context_decorator::add_event): New decl.
1415
1416 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1417
1418 * region-model.cc
1419 (class check_external_function_for_access_attr::annotating_ctxt):
1420 Convert to an annotating_context.
1421 * region-model.h (class note_adding_context): Rename to...
1422 (class annotating_context): ...this, updating the "warn" method.
1423 (note_adding_context::make_note): Replace with...
1424 (annotating_context::add_annotations): ...this.
1425
1426 2023-08-14 benjamin priour <vultkayn@gcc.gnu.org>
1427
1428 PR analyzer/110543
1429 * analyzer.opt: Add new option.
1430 * diagnostic-manager.cc
1431 (diagnostic_manager::prune_path): Call prune_system_headers.
1432 (prune_frame): New function that deletes all events in a frame.
1433 (diagnostic_manager::prune_system_headers): New function.
1434 * diagnostic-manager.h: Add prune_system_headers declaration.
1435
1436 2023-08-11 David Malcolm <dmalcolm@redhat.com>
1437
1438 PR analyzer/105899
1439 * analyzer.opt (Wanalyzer-unterminated-string): New.
1440 * call-details.cc
1441 (call_details::check_for_null_terminated_string_arg): New.
1442 * call-details.h
1443 (call_details::check_for_null_terminated_string_arg): New decl.
1444 * kf-analyzer.cc (class kf_analyzer_get_strlen): New.
1445 (register_known_analyzer_functions): Register it.
1446 * kf.cc (kf_error::impl_call_pre): Check that format arg is a
1447 valid null-terminated string.
1448 (kf_putenv::impl_call_pre): Likewise for the sole param.
1449 (kf_strchr::impl_call_pre): Likewise for the first param.
1450 (kf_strcpy::impl_call_pre): Likewise for the second param.
1451 (kf_strdup::impl_call_pre): Likewise for the sole param.
1452 * region-model.cc (get_strlen): New.
1453 (struct call_arg_details): New.
1454 (inform_about_expected_null_terminated_string_arg): New.
1455 (class unterminated_string_arg): New.
1456 (region_model::check_for_null_terminated_string_arg): New.
1457 * region-model.h
1458 (region_model::check_for_null_terminated_string_arg): New decl.
1459
1460 2023-08-11 Eric Feng <ef2648@columbia.edu>
1461
1462 PR analyzer/107646
1463 * call-details.h: New function.
1464 * region-model.cc (region_model::get_or_create_region_for_heap_alloc):
1465 New optional parameters.
1466 * region-model.h (class region_model): New optional parameters.
1467 * sm-malloc.cc (on_realloc_with_move): New function.
1468 (region_model::transition_ptr_sval_non_null): New function.
1469
1470 2023-08-09 David Malcolm <dmalcolm@redhat.com>
1471
1472 * analyzer.h (class pure_known_function_with_default_return): New
1473 subclass.
1474 * call-details.cc (const_fn_p): Move here from region-model.cc.
1475 (maybe_get_const_fn_result): Likewise.
1476 (get_result_size_in_bytes): Likewise.
1477 (call_details::set_any_lhs_with_defaults): New function, based on
1478 code in region_model::on_call_pre.
1479 * call-details.h (call_details::set_any_lhs_with_defaults): New
1480 decl.
1481 * diagnostic-manager.cc
1482 (diagnostic_manager::emit_saved_diagnostic): Log the index of the
1483 saved_diagnostic.
1484 * kf.cc (pure_known_function_with_default_return::impl_call_pre):
1485 New.
1486 (kf_memset::impl_call_pre): Set the LHS to the first param.
1487 (kf_putenv::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1488 (kf_sprintf::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1489 (class kf_stack_restore): Derive from
1490 pure_known_function_with_default_return.
1491 (class kf_stack_save): Likewise.
1492 (kf_strlen::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1493 * region-model-reachability.cc (reachable_regions::handle_sval):
1494 Remove logic for symbolic regions for pointers.
1495 * region-model.cc (region_model::canonicalize): Remove purging of
1496 dynamic extents workaround for surplus values from
1497 region_model::on_call_pre's default LHS code.
1498 (const_fn_p): Move to call-details.cc.
1499 (maybe_get_const_fn_result): Likewise.
1500 (get_result_size_in_bytes): Likewise.
1501 (region_model::update_for_nonzero_return): Call
1502 cd.set_any_lhs_with_defaults.
1503 (region_model::on_call_pre): Remove the assignment to the LHS of a
1504 default return value, instead requiring all known_function
1505 implementations to write to any LHS of the call. Use
1506 cd.set_any_lhs_with_defaults on the non-kf paths.
1507 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Use
1508 cd.set_any_lhs_with_defaults when failing to get at fd state.
1509 (kf_bind::outcome_of_bind::update_model): Likewise.
1510 (kf_listen::outcome_of_listen::update_model): Likewise.
1511 (kf_accept::outcome_of_accept::update_model): Likewise.
1512 (kf_connect::outcome_of_connect::update_model): Likewise.
1513 (kf_read::impl_call_pre): Use cd.set_any_lhs_with_defaults.
1514 * sm-file.cc (class kf_stdio_output_fn): Derive from
1515 pure_known_function_with_default_return.
1516 (class kf_ferror): Likewise.
1517 (class kf_fileno): Likewise.
1518 (kf_fgets::impl_call_pre): Use cd.set_any_lhs_with_defaults.
1519 (kf_read::impl_call_pre): Likewise.
1520 (class kf_getc): Derive from
1521 pure_known_function_with_default_return.
1522 (class kf_getchar): Likewise.
1523 * varargs.cc (kf_va_arg::impl_call_pre): Use
1524 cd.set_any_lhs_with_defaults.
1525
1526 2023-08-04 David Malcolm <dmalcolm@redhat.com>
1527
1528 PR analyzer/110426
1529 * bounds-checking.cc (region_model::check_region_bounds): Handle
1530 symbolic base regions.
1531 * call-details.cc: Include "stringpool.h" and "attribs.h".
1532 (call_details::lookup_function_attribute): New function.
1533 * call-details.h (call_details::lookup_function_attribute): New
1534 function decl.
1535 * region-model-manager.cc
1536 (region_model_manager::maybe_fold_binop): Add reference to
1537 PR analyzer/110902.
1538 * region-model-reachability.cc (reachable_regions::handle_sval):
1539 Add symbolic regions for pointers that are conjured svalues for
1540 the LHS of a stmt.
1541 * region-model.cc (region_model::canonicalize): Purge dynamic
1542 extents for regions that aren't referenced.
1543 (get_result_size_in_bytes): New function.
1544 (region_model::on_call_pre): Use get_result_size_in_bytes and
1545 potentially set the dynamic extents of the region pointed to by
1546 the return value.
1547 (region_model::deref_rvalue): Add param "add_nonnull_constraint"
1548 and use it to conditionalize adding the constraint.
1549 (pending_diagnostic_subclass::dubious_allocation_size): Add "stmt"
1550 param to both ctors and use it to initialize new "m_stmt" field.
1551 (pending_diagnostic_subclass::operator==): Use m_stmt; don't use
1552 m_lhs or m_rhs.
1553 (pending_diagnostic_subclass::m_stmt): New field.
1554 (region_model::check_region_size): Generalize to any kind of
1555 pointer svalue by using deref_rvalue rather than checking for
1556 region_svalue. Pass stmt to dubious_allocation_size ctor.
1557 * region-model.h (region_model::deref_rvalue): Add param
1558 "add_nonnull_constraint".
1559 * svalue.cc (conjured_svalue::lhs_value_p): New function.
1560 * svalue.h (conjured_svalue::lhs_value_p): New decl.
1561
1562 2023-08-04 David Malcolm <dmalcolm@redhat.com>
1563
1564 * svalue.cc (region_svalue::dump_to_pp): Support NULL type.
1565 (constant_svalue::dump_to_pp): Likewise.
1566 (initial_svalue::dump_to_pp): Likewise.
1567 (conjured_svalue::dump_to_pp): Likewise. Fix missing print of the
1568 type.
1569
1570 2023-08-03 David Malcolm <dmalcolm@redhat.com>
1571
1572 PR analyzer/110882
1573 * region.cc (int_size_in_bits): Fail on zero-sized types.
1574
1575 2023-08-02 Eric Feng <ef2648@columbia.edu>
1576
1577 PR analyzer/107646
1578 * analyzer-language.cc (run_callbacks): New function.
1579 (on_finish_translation_unit): New function.
1580 * analyzer-language.h (GCC_ANALYZER_LANGUAGE_H): New include.
1581 (class translation_unit): New vfuncs.
1582
1583 2023-07-26 David Malcolm <dmalcolm@redhat.com>
1584
1585 PR analyzer/104940
1586 * region-model-manager.cc
1587 (region_model_manager::region_model_manager): Update for
1588 generalizing region ids to also cover svalues.
1589 (region_model_manager::get_or_create_constant_svalue): Likewise.
1590 (region_model_manager::get_or_create_unknown_svalue): Likewise.
1591 (region_model_manager::create_unique_svalue): Likewise.
1592 (region_model_manager::get_or_create_initial_value): Likewise.
1593 (region_model_manager::get_or_create_setjmp_svalue): Likewise.
1594 (region_model_manager::get_or_create_poisoned_svalue): Likewise.
1595 (region_model_manager::get_ptr_svalue): Likewise.
1596 (region_model_manager::get_or_create_unaryop): Likewise.
1597 (region_model_manager::get_or_create_binop): Likewise.
1598 (region_model_manager::get_or_create_sub_svalue): Likewise.
1599 (region_model_manager::get_or_create_repeated_svalue): Likewise.
1600 (region_model_manager::get_or_create_bits_within): Likewise.
1601 (region_model_manager::get_or_create_unmergeable): Likewise.
1602 (region_model_manager::get_or_create_widening_svalue): Likewise.
1603 (region_model_manager::get_or_create_compound_svalue): Likewise.
1604 (region_model_manager::get_or_create_conjured_svalue): Likewise.
1605 (region_model_manager::get_or_create_asm_output_svalue): Likewise.
1606 (region_model_manager::get_or_create_const_fn_result_svalue):
1607 Likewise.
1608 (region_model_manager::get_region_for_fndecl): Likewise.
1609 (region_model_manager::get_region_for_label): Likewise.
1610 (region_model_manager::get_region_for_global): Likewise.
1611 (region_model_manager::get_field_region): Likewise.
1612 (region_model_manager::get_element_region): Likewise.
1613 (region_model_manager::get_offset_region): Likewise.
1614 (region_model_manager::get_sized_region): Likewise.
1615 (region_model_manager::get_cast_region): Likewise.
1616 (region_model_manager::get_frame_region): Likewise.
1617 (region_model_manager::get_symbolic_region): Likewise.
1618 (region_model_manager::get_region_for_string): Likewise.
1619 (region_model_manager::get_bit_range): Likewise.
1620 (region_model_manager::get_var_arg_region): Likewise.
1621 (region_model_manager::get_region_for_unexpected_tree_code):
1622 Likewise.
1623 (region_model_manager::get_or_create_region_for_heap_alloc):
1624 Likewise.
1625 (region_model_manager::create_region_for_alloca): Likewise.
1626 (region_model_manager::log_stats): Likewise.
1627 * region-model-manager.h (region_model_manager::get_num_regions):
1628 Replace with...
1629 (region_model_manager::get_num_symbols): ...this.
1630 (region_model_manager::alloc_region_id): Replace with...
1631 (region_model_manager::alloc_symbol_id): ...this.
1632 (region_model_manager::m_next_region_id): Replace with...
1633 (region_model_manager::m_next_symbol_id): ...this.
1634 * region-model.cc (selftest::test_get_representative_tree): Update
1635 for generalizing region ids to also cover svalues.
1636 (selftest::test_binop_svalue_folding): Likewise.
1637 (selftest::test_state_merging): Likewise.
1638 * region.cc (region::cmp_ids): Delete, in favor of
1639 symbol::cmp_ids.
1640 (region::region): Update for introduction of symbol base class.
1641 (frame_region::get_region_for_local): Likewise.
1642 (root_region::root_region): Likewise.
1643 (symbolic_region::symbolic_region): Likewise.
1644 * region.h: Replace include of "analyzer/complexity.h" with
1645 "analyzer/symbol.h".
1646 (class region): Make a subclass of symbol.
1647 (region::get_id): Delete in favor of symbol::get_id.
1648 (region::cmp_ids): Delete in favor of symbol::cmp_ids.
1649 (region::get_complexity): Delete in favor of
1650 symbol::get_complexity.
1651 (region::region): Use symbol::id_t for "id" param.
1652 (region::m_complexity): Move field to symbol base class.
1653 (region::m_id): Likewise.
1654 (space_region::space_region): Use symbol::id_t for "id" param.
1655 (frame_region::frame_region): Likewise.
1656 (globals_region::globals_region): Likewise.
1657 (code_region::code_region): Likewise.
1658 (function_region::function_region): Likewise.
1659 (label_region::label_region): Likewise.
1660 (stack_region::stack_region): Likewise.
1661 (heap_region::heap_region): Likewise.
1662 (thread_local_region::thread_local_region): Likewise.
1663 (root_region::root_region): Likewise.
1664 (symbolic_region::symbolic_region): Likewise.
1665 (decl_region::decl_region): Likewise.
1666 (field_region::field_region): Likewise.
1667 (element_region::element_region): Likewise.
1668 (offset_region::offset_region): Likewise.
1669 (sized_region::sized_region): Likewise.
1670 (cast_region::cast_region): Likewise.
1671 (heap_allocated_region::heap_allocated_region): Likewise.
1672 (alloca_region::alloca_region): Likewise.
1673 (string_region::string_region): Likewise.
1674 (bit_range_region::bit_range_region): Likewise.
1675 (var_arg_region::var_arg_region): Likewise.
1676 (errno_region::errno_region): Likewise.
1677 (unknown_region::unknown_region): Likewise.
1678 * svalue.cc (sub_svalue::sub_svalue): Add symbol::id_t param.
1679 (repeated_svalue::repeated_svalue): Likewise.
1680 (bits_within_svalue::bits_within_svalue): Likewise.
1681 (compound_svalue::compound_svalue): Likewise.
1682 * svalue.h: Replace include of "analyzer/complexity.h" with
1683 "analyzer/symbol.h".
1684 (class svalue): Make a subclass of symbol.
1685 (svalue::get_complexity): Delete in favor of
1686 symbol::get_complexity.
1687 (svalue::svalue): Add symbol::id_t param. Update for new base
1688 class.
1689 (svalue::m_complexity): Delete in favor of
1690 symbol::m_complexity.
1691 (region_svalue::region_svalue): Add symbol::id_t param
1692 (constant_svalue::constant_svalue): Likewise.
1693 (unknown_svalue::unknown_svalue): Likewise.
1694 (poisoned_svalue::poisoned_svalue): Likewise.
1695 (setjmp_svalue::setjmp_svalue): Likewise.
1696 (initial_svalue::initial_svalue): Likewise.
1697 (unaryop_svalue::unaryop_svalue): Likewise.
1698 (binop_svalue::binop_svalue): Likewise.
1699 (sub_svalue::sub_svalue): Likewise.
1700 (repeated_svalue::repeated_svalue): Likewise.
1701 (bits_within_svalue::bits_within_svalue): Likewise.
1702 (unmergeable_svalue::unmergeable_svalue): Likewise.
1703 (placeholder_svalue::placeholder_svalue): Likewise.
1704 (widening_svalue::widening_svalue): Likewise.
1705 (compound_svalue::compound_svalue): Likewise.
1706 (conjured_svalue::conjured_svalue): Likewise.
1707 (asm_output_svalue::asm_output_svalue): Likewise.
1708 (const_fn_result_svalue::const_fn_result_svalue): Likewise.
1709 * symbol.cc: New file.
1710 * symbol.h: New file.
1711
1712 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1713
1714 PR analyzer/110455
1715 * region-model.cc (region_model::get_gassign_result): Only check
1716 for bad shift counts when dealing with an integral type.
1717
1718 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1719
1720 PR analyzer/110433
1721 PR middle-end/110612
1722 * access-diagram.cc (class spatial_item): Add virtual dtor.
1723
1724 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1725
1726 PR analyzer/110387
1727 * region.h (struct cast_region::key_t): Support "m_type" being
1728 null by using "m_original_region" for empty/deleted slots.
1729
1730 2023-07-19 David Malcolm <dmalcolm@redhat.com>
1731
1732 PR analyzer/110700
1733 * region-model-manager.cc
1734 (region_model_manager::get_or_create_int_cst): Assert that we have
1735 an integral or pointer type.
1736 * sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
1737 Don't check non-integral types.
1738
1739 2023-06-29 benjamin priour <priour.be@gmail.com>
1740
1741 PR analyzer/110198
1742 * region-model-manager.cc
1743 (region_model_manager::get_or_create_initial_value): Take an
1744 optional boolean value to bypass poisoning checks
1745 * region-model-manager.h: Update declaration of the above function.
1746 * region-model.cc (region_model::get_store_value): No longer returns
1747 on OOB, but rather gives a boolean to get_or_create_initial_value.
1748 (region_model::check_region_access): Update docstring.
1749 (region_model::check_region_for_write): Update docstring.
1750
1751 2023-06-24 David Malcolm <dmalcolm@redhat.com>
1752
1753 * access-diagram.cc: Add #define INCLUDE_VECTOR.
1754 * bounds-checking.cc: Likewise.
1755
1756 2023-06-22 David Malcolm <dmalcolm@redhat.com>
1757
1758 PR analyzer/106626
1759 * access-diagram.cc: New file.
1760 * access-diagram.h: New file.
1761 * analyzer.h (class region_offset): Add default ctor.
1762 (region_offset::make_byte_offset): New decl.
1763 (region_offset::concrete_p): New.
1764 (region_offset::get_concrete_byte_offset): New.
1765 (region_offset::calc_symbolic_bit_offset): New decl.
1766 (region_offset::calc_symbolic_byte_offset): New decl.
1767 (region_offset::dump_to_pp): New decl.
1768 (region_offset::dump): New decl.
1769 (operator<, operator<=, operator>, operator>=): New decls for
1770 region_offset.
1771 * analyzer.opt
1772 (-param=analyzer-text-art-string-ellipsis-threshold=): New.
1773 (-param=analyzer-text-art-string-ellipsis-head-len=): New.
1774 (-param=analyzer-text-art-string-ellipsis-tail-len=): New.
1775 (-param=analyzer-text-art-ideal-canvas-width=): New.
1776 (fanalyzer-debug-text-art): New.
1777 * bounds-checking.cc: Include "intl.h", "diagnostic-diagram.h",
1778 and "analyzer/access-diagram.h".
1779 (class out_of_bounds::oob_region_creation_event_capacity): New.
1780 (out_of_bounds::out_of_bounds): Add "model" and "sval_hint"
1781 params.
1782 (out_of_bounds::mark_interesting_stuff): Use the base region.
1783 (out_of_bounds::add_region_creation_events): Use
1784 oob_region_creation_event_capacity.
1785 (out_of_bounds::get_dir): New pure vfunc.
1786 (out_of_bounds::maybe_show_notes): New.
1787 (out_of_bounds::maybe_show_diagram): New.
1788 (out_of_bounds::make_access_diagram): New.
1789 (out_of_bounds::m_model): New field.
1790 (out_of_bounds::m_sval_hint): New field.
1791 (out_of_bounds::m_region_creation_event_id): New field.
1792 (concrete_out_of_bounds::concrete_out_of_bounds): Update for new
1793 fields.
1794 (concrete_past_the_end::concrete_past_the_end): Likewise.
1795 (concrete_past_the_end::add_region_creation_events): Use
1796 oob_region_creation_event_capacity.
1797 (concrete_buffer_overflow::concrete_buffer_overflow): Update for
1798 new fields.
1799 (concrete_buffer_overflow::emit): Replace call to
1800 maybe_describe_array_bounds with maybe_show_notes.
1801 (concrete_buffer_overflow::get_dir): New.
1802 (concrete_buffer_over_read::concrete_buffer_over_read): Update for
1803 new fields.
1804 (concrete_buffer_over_read::emit): Replace call to
1805 maybe_describe_array_bounds with maybe_show_notes.
1806 (concrete_buffer_overflow::get_dir): New.
1807 (concrete_buffer_underwrite::concrete_buffer_underwrite): Update
1808 for new fields.
1809 (concrete_buffer_underwrite::emit): Replace call to
1810 maybe_describe_array_bounds with maybe_show_notes.
1811 (concrete_buffer_underwrite::get_dir): New.
1812 (concrete_buffer_under_read::concrete_buffer_under_read): Update
1813 for new fields.
1814 (concrete_buffer_under_read::emit): Replace call to
1815 maybe_describe_array_bounds with maybe_show_notes.
1816 (concrete_buffer_under_read::get_dir): New.
1817 (symbolic_past_the_end::symbolic_past_the_end): Update for new
1818 fields.
1819 (symbolic_buffer_overflow::symbolic_buffer_overflow): Likewise.
1820 (symbolic_buffer_overflow::emit): Call maybe_show_notes.
1821 (symbolic_buffer_overflow::get_dir): New.
1822 (symbolic_buffer_over_read::symbolic_buffer_over_read): Update for
1823 new fields.
1824 (symbolic_buffer_over_read::emit): Call maybe_show_notes.
1825 (symbolic_buffer_over_read::get_dir): New.
1826 (region_model::check_symbolic_bounds): Add "sval_hint" param. Pass
1827 it and sized_offset_reg to diagnostics.
1828 (region_model::check_region_bounds): Add "sval_hint" param, passing
1829 it to diagnostics.
1830 * diagnostic-manager.cc
1831 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
1832 pending_diagnostic::emit.
1833 * engine.cc: Add logger param to pending_diagnostic::emit
1834 implementations.
1835 * infinite-recursion.cc: Likewise.
1836 * kf-analyzer.cc: Likewise.
1837 * kf.cc: Likewise. Add nullptr for new param of
1838 check_region_for_write.
1839 * pending-diagnostic.h: Likewise in decl.
1840 * region-model-manager.cc
1841 (region_model_manager::get_or_create_int_cst): Convert param from
1842 poly_int64 to const poly_wide_int_ref &.
1843 (region_model_manager::maybe_fold_binop): Support type being NULL
1844 when checking for floating-point types.
1845 Check for (X + Y) - X => Y. Be less strict about types when folding
1846 associative ops. Check for (X + Y) * CST => (X * CST) + (Y * CST).
1847 * region-model-manager.h
1848 (region_model_manager::get_or_create_int_cst): Convert param from
1849 poly_int64 to const poly_wide_int_ref &.
1850 * region-model.cc: Add logger param to pending_diagnostic::emit
1851 implementations.
1852 (region_model::check_external_function_for_access_attr): Update
1853 for new param of check_region_for_write.
1854 (region_model::deref_rvalue): Use nullptr rather than NULL.
1855 (region_model::get_capacity): Handle RK_STRING.
1856 (region_model::check_region_access): Add "sval_hint" param; pass it to
1857 check_region_bounds.
1858 (region_model::check_region_for_write): Add "sval_hint" param;
1859 pass it to check_region_access.
1860 (region_model::check_region_for_read): Add NULL for new param to
1861 check_region_access.
1862 (region_model::set_value): Pass rhs_sval to
1863 check_region_for_write.
1864 (region_model::get_representative_path_var_1): Handle SK_CONSTANT
1865 in the check for infinite recursion.
1866 * region-model.h (region_model::check_region_for_write): Add
1867 "sval_hint" param.
1868 (region_model::check_region_access): Likewise.
1869 (region_model::check_symbolic_bounds): Likewise.
1870 (region_model::check_region_bounds): Likewise.
1871 * region.cc (region_offset::make_byte_offset): New.
1872 (region_offset::calc_symbolic_bit_offset): New.
1873 (region_offset::calc_symbolic_byte_offset): New.
1874 (region_offset::dump_to_pp): New.
1875 (region_offset::dump): New.
1876 (struct linear_op): New.
1877 (operator<, operator<=, operator>, operator>=): New, for
1878 region_offset.
1879 (region::get_next_offset): New.
1880 (region::get_relative_symbolic_offset): Use ptrdiff_type_node.
1881 (field_region::get_relative_symbolic_offset): Likewise.
1882 (element_region::get_relative_symbolic_offset): Likewise.
1883 (bit_range_region::get_relative_symbolic_offset): Likewise.
1884 * region.h (region::get_next_offset): New decl.
1885 * sm-fd.cc: Add logger param to pending_diagnostic::emit
1886 implementations.
1887 * sm-file.cc: Likewise.
1888 * sm-malloc.cc: Likewise.
1889 * sm-pattern-test.cc: Likewise.
1890 * sm-sensitive.cc: Likewise.
1891 * sm-signal.cc: Likewise.
1892 * sm-taint.cc: Likewise.
1893 * store.cc (bit_range::contains_p): Allow "out" to be null.
1894 * store.h (byte_range::get_start_bit_offset): New.
1895 (byte_range::get_next_bit_offset): New.
1896 * varargs.cc: Add logger param to pending_diagnostic::emit
1897 implementations.
1898
1899 2023-06-10 Tim Lange <mail@tim-lange.me>
1900
1901 PR analyzer/109577
1902 * constraint-manager.cc (class sval_finder): Visitor to find
1903 childs in svalue trees.
1904 (constraint_manager::sval_constrained_p): Add new function to
1905 check whether a sval might be part of an constraint.
1906 * constraint-manager.h: Add sval_constrained_p function.
1907 * region-model.cc (class size_visitor): Reverse behavior to not
1908 emit a warning on not explicitly considered cases.
1909 (region_model::check_region_size):
1910 Adapt to size_visitor changes.
1911
1912 2023-06-09 David Malcolm <dmalcolm@redhat.com>
1913
1914 PR analyzer/110112
1915 * region-model.cc (region_model::get_initial_value_for_global):
1916 Move code to region::calc_initial_value_at_main.
1917 * region.cc (region::get_initial_value_at_main): New function.
1918 (region::calc_initial_value_at_main): New function, based on code
1919 in region_model::get_initial_value_for_global.
1920 (region::region): Initialize m_cached_init_sval_at_main.
1921 (decl_region::get_svalue_for_constructor): Add a cache, splitting
1922 out body to...
1923 (decl_region::calc_svalue_for_constructor): ...this new function.
1924 * region.h (region::get_initial_value_at_main): New decl.
1925 (region::calc_initial_value_at_main): New decl.
1926 (region::m_cached_init_sval_at_main): New field.
1927 (decl_region::decl_region): Initialize m_ctor_svalue.
1928 (decl_region::calc_svalue_for_constructor): New decl.
1929 (decl_region::m_ctor_svalue): New field.
1930
1931 2023-06-08 Benjamin Priour <vultkayn@gcc.gnu.org>
1932
1933 * bounds-checking.cc (region_model::check_symbolic_bounds): Returns whether the BASE_REG
1934 region access was OOB.
1935 (region_model::check_region_bounds): Likewise.
1936 * region-model.cc (region_model::get_store_value): Creates an
1937 unknown svalue on OOB-read access to REG.
1938 (region_model::check_region_access): Returns whether an unknown svalue needs be created.
1939 (region_model::check_region_for_read): Passes check_region_access return value.
1940 * region-model.h: Update prior function definitions.
1941
1942 2023-06-02 David Malcolm <dmalcolm@redhat.com>
1943
1944 PR analyzer/109015
1945 * kf.cc (class kf_atomic_exchange): New.
1946 (class kf_atomic_exchange_n): New.
1947 (class kf_atomic_fetch_op): New.
1948 (class kf_atomic_op_fetch): New.
1949 (class kf_atomic_load): New.
1950 (class kf_atomic_load_n): New.
1951 (class kf_atomic_store_n): New.
1952 (register_atomic_builtins): New function.
1953 (register_known_functions): Call register_atomic_builtins.
1954
1955 2023-06-02 David Malcolm <dmalcolm@redhat.com>
1956
1957 * store.cc (store::eval_alias_1): Regions in different memory
1958 spaces can't alias.
1959
1960 2023-05-18 Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
1961
1962 * region-model-manager.cc (get_code_for_cast): Use _P defines from
1963 tree.h.
1964 (region_model_manager::get_or_create_cast): Ditto.
1965 (region_model_manager::get_region_for_global): Ditto.
1966 * region-model.cc (region_model::get_lvalue_1): Ditto.
1967 * region.cc (decl_region::maybe_get_constant_value): Ditto.
1968
1969 2023-03-22 David Malcolm <dmalcolm@redhat.com>
1970
1971 PR analyzer/109239
1972 * program-point.cc: Include "analyzer/inlining-iterator.h".
1973 (program_point::effectively_intraprocedural_p): New function.
1974 * program-point.h (program_point::effectively_intraprocedural_p):
1975 New decl.
1976 * sm-malloc.cc (deref_before_check::emit): Use it when rejecting
1977 interprocedural cases, so that we reject interprocedural cases
1978 that have become intraprocedural due to inlining.
1979
1980 2023-03-18 David Malcolm <dmalcolm@redhat.com>
1981
1982 PR analyzer/109094
1983 * region-model.cc (region_model::on_longjmp): Pass false for
1984 new "eval_return_svalue" param of pop_frame.
1985 (region_model::pop_frame): Add new "eval_return_svalue" param and
1986 use it to suppress the call to get_rvalue on the result when
1987 needed by on_longjmp.
1988 * region-model.h (region_model::pop_frame): Add new
1989 "eval_return_svalue" param.
1990
1991 2023-03-10 David Malcolm <dmalcolm@redhat.com>
1992
1993 PR analyzer/109059
1994 * region-model.cc (region_model::mark_region_as_unknown): Gather a
1995 set of maybe-live svalues and call on_maybe_live_values with it.
1996 * store.cc (binding_map::remove_overlapping_bindings): Add new
1997 "maybe_live_values" param; add any removed svalues to it.
1998 (binding_cluster::clobber_region): Add NULL as new param of
1999 remove_overlapping_bindings.
2000 (binding_cluster::mark_region_as_unknown): Add "maybe_live_values"
2001 param and pass it to remove_overlapping_bindings.
2002 (binding_cluster::maybe_get_compound_binding): Add NULL for new
2003 param of binding_map::remove_overlapping_bindings.
2004 (binding_cluster::remove_overlapping_bindings): Add
2005 "maybe_live_values" param and pass to
2006 binding_map::remove_overlapping_bindings.
2007 (store::set_value): Capture a set of maybe-live svalues, and call
2008 on_maybe_live_values with it.
2009 (store::on_maybe_live_values): New.
2010 (store::mark_region_as_unknown): Add "maybe_live_values" param
2011 and pass it to binding_cluster::mark_region_as_unknown.
2012 (store::remove_overlapping_bindings): Pass NULL for new param of
2013 binding_cluster::remove_overlapping_bindings.
2014 * store.h (binding_map::remove_overlapping_bindings): Add
2015 "maybe_live_values" param.
2016 (binding_cluster::mark_region_as_unknown): Likewise.
2017 (binding_cluster::remove_overlapping_bindings): Likewise.
2018 (store::mark_region_as_unknown): Likewise.
2019 (store::on_maybe_live_values): New decl.
2020
2021 2023-03-10 David Malcolm <dmalcolm@redhat.com>
2022
2023 PR analyzer/108475
2024 PR analyzer/109060
2025 * sm-malloc.cc (deref_before_check::deref_before_check):
2026 Initialize new field m_deref_expr. Assert that arg is non-NULL.
2027 (deref_before_check::emit): Reject cases where the spelling of the
2028 thing that was dereferenced differs from that of what is checked,
2029 or if the dereference expression was not found. Remove code to
2030 handle NULL m_arg.
2031 (deref_before_check::describe_state_change): Remove code to handle
2032 NULL m_arg.
2033 (deref_before_check::describe_final_event): Likewise.
2034 (deref_before_check::sufficiently_similar_p): New.
2035 (deref_before_check::m_deref_expr): New field.
2036 (malloc_state_machine::maybe_complain_about_deref_before_check):
2037 Don't warn if the diag_ptr is NULL.
2038
2039 2023-03-03 David Malcolm <dmalcolm@redhat.com>
2040
2041 * kf.cc (class kf_sprintf): New.
2042 (register_known_functions): Register it.
2043
2044 2023-03-02 David Malcolm <dmalcolm@redhat.com>
2045
2046 PR analyzer/108968
2047 * region-model.cc (region_model::get_rvalue_1): Handle VAR_DECLs
2048 with a DECL_HARD_REGISTER by returning UNKNOWN.
2049
2050 2023-03-02 Hans-Peter Nilsson <hp@axis.com>
2051
2052 * kf.cc (register_known_functions): Add __errno function for newlib.
2053
2054 2023-03-01 David Malcolm <dmalcolm@redhat.com>
2055
2056 PR analyzer/107565
2057 * region-model.cc (region_model::on_call_pre): Flatten logic by
2058 returning early. Consolidate logic for detecting const and pure
2059 functions. When considering whether an unhandled built-in
2060 function has side-effects, consider all kinds of builtin, rather
2061 than just BUILT_IN_NORMAL, and don't require
2062 gimple_builtin_call_types_compatible_p.
2063
2064 2023-03-01 David Malcolm <dmalcolm@redhat.com>
2065
2066 PR analyzer/108935
2067 * infinite-recursion.cc (contains_unknown_p): New.
2068 (sufficiently_different_region_binding_p): New function, splitting
2069 out inner loop from...
2070 (sufficiently_different_p): ...here. Extend detection of unknown
2071 svalues to also include svalues that contain unknown. Treat
2072 changes in frames below the entry to the recursion as being
2073 sufficiently different to reject being an infinite recursion.
2074
2075 2023-02-21 David Malcolm <dmalcolm@redhat.com>
2076
2077 PR analyzer/108830
2078 * analyzer.opt (fanalyzer-suppress-followups): New option.
2079 * engine.cc (impl_region_model_context::warn): Terminate the path
2080 if the diagnostic's terminate_path_p vfunc returns true and
2081 -fanalyzer-suppress-followups is true (the default).
2082 (impl_sm_context::warn): Likewise, for both overloads.
2083 * pending-diagnostic.h (pending_diagnostic::terminate_path_p): New
2084 vfunc.
2085 * program-state.cc (program_state::on_edge): Terminate the path if
2086 the ctxt requests it during updating the edge.
2087 * region-model.cc (poisoned_value_diagnostic::terminate_path_p):
2088 New vfunc.
2089 * sm-malloc.cc (null_deref::terminate_path_p): New vfunc.
2090 (null_arg::terminate_path_p): New vfunc.
2091
2092 2023-02-16 David Malcolm <dmalcolm@redhat.com>
2093
2094 PR analyzer/108806
2095 * constraint-manager.cc (bounded_range::dump_to_pp): Use
2096 bounded_range::singleton_p.
2097 (constraint_manager::add_bounded_ranges): Handle singleton ranges
2098 by adding an EQ_EXPR constraint.
2099 (constraint_manager::impossible_derived_conditions_p): New.
2100 (constraint_manager::eval_condition): Reject EQ_EXPR when it would
2101 imply impossible derived conditions.
2102 (selftest::test_bits): New.
2103 (selftest::run_constraint_manager_tests): Run it.
2104 * constraint-manager.h (bounded_range::singleton_p): New.
2105 (constraint_manager::impossible_derived_conditions_p): New decl.
2106 * region-model.cc (region_model::get_rvalue_1): Handle
2107 BIT_AND_EXPR, BIT_IOR_EXPR, and BIT_XOR_EXPR.
2108
2109 2023-02-15 David Malcolm <dmalcolm@redhat.com>
2110
2111 PR analyzer/108664
2112 PR analyzer/108666
2113 PR analyzer/108725
2114 * diagnostic-manager.cc (epath_finder::get_best_epath): Add
2115 "target_stmt" param.
2116 (epath_finder::explore_feasible_paths): Likewise.
2117 (epath_finder::process_worklist_item): Likewise.
2118 (saved_diagnostic::calc_best_epath): Pass m_stmt to
2119 epath_finder::get_best_epath.
2120 * engine.cc (feasibility_state::maybe_update_for_edge): Move
2121 per-stmt logic to...
2122 (feasibility_state::update_for_stmt): ...this new function.
2123 * exploded-graph.h (feasibility_state::update_for_stmt): New decl.
2124 * feasible-graph.cc (feasible_node::get_state_at_stmt): New.
2125 * feasible-graph.h: Include "analyzer/exploded-graph.h".
2126 (feasible_node::get_state_at_stmt): New decl.
2127 * infinite-recursion.cc
2128 (infinite_recursion_diagnostic::check_valid_fpath_p): Update for
2129 vfunc signature change.
2130 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
2131 Convert first param to a reference. Add stmt param.
2132 * region-model.cc: Include "analyzer/feasible-graph.h".
2133 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
2134 "check_expr" param.
2135 (poisoned_value_diagnostic::check_valid_fpath_p): New.
2136 (poisoned_value_diagnostic::m_check_expr): New field.
2137 (region_model::check_for_poison): Attempt to supply a check_expr
2138 to the diagnostic
2139 (region_model::deref_rvalue): Add NULL for new check_expr param
2140 of poisoned_value_diagnostic.
2141 (region_model::get_or_create_region_for_heap_alloc): Don't reuse
2142 regions that are marked as TOUCHED.
2143
2144 2023-02-10 David Malcolm <dmalcolm@redhat.com>
2145
2146 PR analyzer/108745
2147 * sm-malloc.cc (deref_before_check::emit): Reject the warning if
2148 the check occurs within a macro defintion.
2149
2150 2023-02-09 David Malcolm <dmalcolm@redhat.com>
2151
2152 PR analyzer/108733
2153 * state-purge.cc (get_candidate_for_purging): Add ADDR_EXPR
2154 and MEM_REF.
2155
2156 2023-02-08 David Malcolm <dmalcolm@redhat.com>
2157
2158 PR analyzer/108704
2159 * state-purge.cc (state_purge_per_decl::process_point_backwards):
2160 Don't stop processing the decl if it's fully overwritten by
2161 this stmt if it's also used by this stmt.
2162
2163 2023-02-07 David Malcolm <dmalcolm@redhat.com>
2164
2165 PR analyzer/108661
2166 * sm-fd.cc (class kf_read): New.
2167 (register_known_fd_functions): Register "read".
2168 * sm-file.cc (class kf_fread): Update comment.
2169
2170 2023-02-02 David Malcolm <dmalcolm@redhat.com>
2171
2172 PR analyzer/108633
2173 * sm-fd.cc (fd_state_machine::check_for_fd_attrs): Add missing
2174 "continue".
2175 (fd_state_machine::on_listen): Don't issue phase-mismatch or
2176 type-mismatch warnings for the "invalid" state.
2177
2178 2023-02-01 David Malcolm <dmalcolm@redhat.com>
2179
2180 PR analyzer/108616
2181 * pending-diagnostic.cc (fixup_location_in_macro_p): Add "alloca"
2182 to macros that we shouldn't unwind inside.
2183
2184 2023-01-26 David Malcolm <dmalcolm@redhat.com>
2185
2186 PR analyzer/108524
2187 * analyzer.h (class feasible_node): New forward decl.
2188 * diagnostic-manager.cc (epath_finder::get_best_epath): Add "pd"
2189 param.
2190 (epath_finder::explore_feasible_paths): Likewise.
2191 (epath_finder::process_worklist_item): Likewise. Use it to call
2192 pending_diagnostic::check_valid_fpath_p on the final fpath to
2193 give pending_diagnostic a way to add additional restrictions on
2194 feasibility.
2195 (saved_diagnostic::calc_best_epath): Pass pending_diagnostic to
2196 epath_finder::get_best_epath.
2197 * infinite-recursion.cc: Include "analyzer/feasible-graph.h".
2198 (infinite_recursion_diagnostic::check_valid_fpath_p): New.
2199 (infinite_recursion_diagnostic::fedge_uses_conjured_svalue_p): New.
2200 (infinite_recursion_diagnostic::expr_uses_conjured_svalue_p): New.
2201 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
2202 New vfunc.
2203
2204 2023-01-19 David Malcolm <dmalcolm@redhat.com>
2205
2206 PR analyzer/108455
2207 * analyzer.h (class checker_event): New forward decl.
2208 (class state_change_event): Indent.
2209 (class warning_event): New forward decl.
2210 * checker-event.cc (state_change_event::state_change_event): Add
2211 "enode" param.
2212 (warning_event::get_desc): Update for new param of
2213 evdesc::final_event ctor.
2214 * checker-event.h (state_change_event::state_change_event): Add
2215 "enode" param.
2216 (state_change_event::get_exploded_node): New accessor.
2217 (state_change_event::m_enode): New field.
2218 (warning_event::warning_event): New "enode" param.
2219 (warning_event::get_exploded_node): New accessor.
2220 (warning_event::m_enode): New field.
2221 * diagnostic-manager.cc
2222 (state_change_event_creator::on_global_state_change): Pass
2223 src_node to state_change_event ctor.
2224 (state_change_event_creator::on_state_change): Likewise.
2225 (null_assignment_sm_context::set_next_state): Pass NULL for
2226 new param of state_change_event ctor.
2227 * infinite-recursion.cc
2228 (infinite_recursion_diagnostic::add_final_event): Update for new
2229 param of warning_event ctor.
2230 * pending-diagnostic.cc (pending_diagnostic::add_final_event):
2231 Pass enode to warning_event ctor.
2232 * pending-diagnostic.h (evdesc::final_event): Add reference to
2233 warning_event.
2234 * sm-malloc.cc: Include "analyzer/checker-event.h" and
2235 "analyzer/exploded-graph.h".
2236 (deref_before_check::deref_before_check): Initialize new fields.
2237 (deref_before_check::emit): Reject warnings in which we were
2238 unable to determine the enodes of the dereference and the check.
2239 Reject warnings interprocedural warnings. Reject warnings in which
2240 the dereference doesn't dominate the check.
2241 (deref_before_check::describe_state_change): Set m_deref_enode.
2242 (deref_before_check::describe_final_event): Set m_check_enode.
2243 (deref_before_check::m_deref_enode): New field.
2244 (deref_before_check::m_check_enode): New field.
2245
2246 2023-01-13 David Malcolm <dmalcolm@redhat.com>
2247
2248 PR analyzer/105273
2249 * region-model.cc (has_nondefault_case_for_value_p): New.
2250 (has_nondefault_cases_for_all_enum_values_p): New.
2251 (region_model::apply_constraints_for_gswitch): Skip
2252 implicitly-created "default" when switching on an enum
2253 and all enum values have non-default cases.
2254 (rejected_default_case::dump_to_pp): New.
2255 * region-model.h (region_model_context::possibly_tainted_p): New
2256 decl.
2257 (class rejected_default_case): New.
2258 * sm-taint.cc (region_model_context::possibly_tainted_p): New.
2259 * supergraph.cc (switch_cfg_superedge::dump_label_to_pp): Dump
2260 when implicitly_created_default_p.
2261 (switch_cfg_superedge::implicitly_created_default_p): New.
2262 * supergraph.h
2263 (switch_cfg_superedge::implicitly_created_default_p): New decl.
2264
2265 2023-01-11 David Malcolm <dmalcolm@redhat.com>
2266
2267 PR analyzer/108252
2268 * kf.cc (class kf_strdup): New.
2269 (class kf_strndup): New.
2270 (register_known_functions): Register them.
2271 * region-model.cc (region_model::on_call_pre): Use
2272 &HEAP_ALLOCATED_REGION for the default result of an external
2273 function with the "malloc" attribute, rather than CONJURED_SVALUE.
2274 (region_model::get_or_create_region_for_heap_alloc): Allow
2275 "size_in_bytes" to be NULL.
2276 * store.cc (store::set_value): When handling *UNKNOWN = VAL,
2277 mark VAL as "maybe bound".
2278
2279 2022-12-16 David Malcolm <dmalcolm@redhat.com>
2280
2281 PR analyzer/106479
2282 * kf.cc (kf_memcpy_memmove::impl_call_pre): Pass in source region
2283 to region_model::check_for_poison.
2284 * region-model-asm.cc (region_model::on_asm_stmt): Pass NULL
2285 region to region_model::check_for_poison.
2286 * region-model.cc (region_model::check_for_poison): Add
2287 "src_region" param, and pass it to poisoned_value_diagnostic.
2288 (region_model::on_assignment): Pass NULL region to
2289 region_model::check_for_poison.
2290 (region_model::get_rvalue): Likewise.
2291 * region-model.h (region_model::check_for_poison): Add
2292 "src_region" param.
2293 * sm-fd.cc (fd_state_machine::on_accept): Pass in source region
2294 to region_model::check_for_poison.
2295 * varargs.cc (kf_va_copy::impl_call_pre): Pass NULL region to
2296 region_model::check_for_poison.
2297 (kf_va_arg::impl_call_pre): Pass in source region to
2298 region_model::check_for_poison.
2299
2300 2022-12-14 David Malcolm <dmalcolm@redhat.com>
2301
2302 PR analyzer/108065
2303 * region.cc (decl_region::get_svalue_for_initializer): Bail out to
2304 avoid calling binding_key::make with an empty region.
2305 * store.cc (binding_map::apply_ctor_val_to_range): Likewise.
2306 (binding_map::apply_ctor_pair_to_child_region): Likewise.
2307 (binding_cluster::bind): Likewise.
2308 (binding_cluster::purge_region): Likewise.
2309 (binding_cluster::maybe_get_compound_binding): Likewise.
2310 (binding_cluster::maybe_get_simple_value): Likewise.
2311
2312 2022-12-09 David Malcolm <dmalcolm@redhat.com>
2313
2314 * analyzer.h (class known_function): Expand comment.
2315 * region-model-impl-calls.cc: Rename to...
2316 * kf.cc: ...this.
2317 * known-function-manager.h (class known_function_manager): Add
2318 leading comment.
2319
2320 2022-12-09 David Malcolm <dmalcolm@redhat.com>
2321
2322 PR analyzer/108003
2323 * call-summary.cc
2324 (call_summary_replay::convert_region_from_summary_1): Convert
2325 heap_regs_in_use from auto_sbitmap to auto_bitmap.
2326 * region-model-manager.cc
2327 (region_model_manager::get_or_create_region_for_heap_alloc):
2328 Convert from sbitmap to bitmap.
2329 * region-model-manager.h: Likewise.
2330 * region-model.cc
2331 (region_model::get_or_create_region_for_heap_alloc): Convert from
2332 auto_sbitmap to auto_bitmap.
2333 (region_model::get_referenced_base_regions): Likewise.
2334 * region-model.h: Include "bitmap.h" rather than "sbitmap.h".
2335 (region_model::get_referenced_base_regions): Convert from
2336 auto_sbitmap to auto_bitmap.
2337
2338 2022-12-09 David Malcolm <dmalcolm@redhat.com>
2339
2340 * region-model-impl-calls.cc (class kf_memcpy): Rename to...
2341 (class kf_memcpy_memmove): ...this.
2342 (kf_memcpy::impl_call_pre): Rename to...
2343 (kf_memcpy_memmove::impl_call_pre): ...this, and check the src for
2344 poison.
2345 (register_known_functions): Update for above renaming, and
2346 register BUILT_IN_MEMMOVE and BUILT_IN_MEMMOVE_CHK.
2347
2348 2022-12-06 David Malcolm <dmalcolm@redhat.com>
2349
2350 PR analyzer/107882
2351 * region-model.cc (region_model::get_store_value): Return an
2352 unknown value for empty regions.
2353 (region_model::set_value): Bail on empty regions.
2354 * region.cc (region::empty_p): New.
2355 * region.h (region::empty_p): New decl.
2356 * state-purge.cc (same_binding_p): Bail if either region is empty.
2357 * store.cc (binding_key::make): Assert that a concrete binding's
2358 bit_size must be > 0.
2359 (binding_cluster::mark_region_as_unknown): Bail on empty regions.
2360 (binding_cluster::get_binding): Likewise.
2361 (binding_cluster::remove_overlapping_bindings): Likewise.
2362 (binding_cluster::on_unknown_fncall): Don't conjure values for
2363 empty regions.
2364 (store::fill_region): Bail on empty regions.
2365 * store.h (class concrete_binding): Update comment to reflect that
2366 the range of bits must be non-empty.
2367 (concrete_binding::concrete_binding): Assert that bit range is
2368 non-empty.
2369
2370 2022-12-06 David Malcolm <dmalcolm@redhat.com>
2371
2372 PR analyzer/106325
2373 * region-model-manager.cc
2374 (region_model_manager::get_or_create_null_ptr): New.
2375 * region-model-manager.h
2376 (region_model_manager::get_or_create_null_ptr): New decl.
2377 * region-model.cc (region_model::on_top_level_param): Add
2378 "nonnull" param and make use of it.
2379 (region_model::push_frame): When handling a top-level entrypoint
2380 to the analysis, determine which params __attribute__((nonnull))
2381 applies to, and pass to on_top_level_param.
2382 * region-model.h (region_model::on_top_level_param): Add "nonnull"
2383 param.
2384
2385 2022-12-06 David Malcolm <dmalcolm@redhat.com>
2386
2387 * analyzer.h (register_known_analyzer_functions): New decl.
2388 (register_known_functions_lang_cp): New decl.
2389 * call-details.cc: New file, split out from
2390 region-model-impl-calls.cc.
2391 * call-details.h: New file, split out from region-model.h.
2392 * call-info.cc: Include "analyzer/call-details.h".
2393 * call-summary.h: Likewise.
2394 * kf-analyzer.cc: New file, split out from
2395 region-model-impl-calls.cc.
2396 * kf-lang-cp.cc: Likewise.
2397 * known-function-manager.cc: Include "analyzer/call-details.h".
2398 * region-model-impl-calls.cc: Move definitions of call_details's
2399 member functions to call-details.cc. Move class kf_analyzer_* to
2400 kf-analyzer.cc. Move kf_operator_new and kf_operator_delete to
2401 kf-lang-cp.cc. Refresh #includes accordingly.
2402 (register_known_functions): Replace registration of __analyzer_*
2403 functions with a call to register_known_analyzer_functions.
2404 Replace registration of C++ support functions with a call to
2405 register_known_functions_lang_cp.
2406 * region-model.h (class call_details): Move to new call-details.h.
2407 * sm-fd.cc: Include "analyzer/call-details.h".
2408 * sm-file.cc: Likewise.
2409 * sm-malloc.cc: Likewise.
2410 * varargs.cc: Likewise.
2411
2412 2022-12-02 David Malcolm <dmalcolm@redhat.com>
2413
2414 * analyzer.h (struct event_loc_info): New forward decl.
2415 * bounds-checking.cc: Use event_loc_info throughout to bundle the
2416 loc, fndecl, depth triples.
2417 * call-info.cc: Likewise.
2418 * checker-event.cc: Likewise.
2419 * checker-event.h (struct event_loc_info): New decl. Use it
2420 throughout to bundle the loc, fndecl, depth triples.
2421 * checker-path.cc: Likewise.
2422 * checker-path.h: Likewise.
2423 * diagnostic-manager.cc: Likewise.
2424 * engine.cc: Likewise.
2425 * infinite-recursion.cc: Likewise.
2426 * pending-diagnostic.cc: Likewise.
2427 * pending-diagnostic.h: Likewise.
2428 * region-model.cc: Likewise.
2429 * sm-signal.cc: Likewise.
2430 * varargs.cc: Likewise.
2431
2432 2022-12-02 David Malcolm <dmalcolm@redhat.com>
2433
2434 PR analyzer/107851
2435 * analyzer.cc (make_label_text_n): Convert param "n" from int to
2436 unsigned HOST_WIDE_INT.
2437 * analyzer.h (make_label_text_n): Likewise for decl.
2438 * bounds-checking.cc: Include "analyzer/checker-event.h" and
2439 "analyzer/checker-path.h".
2440 (out_of_bounds::add_region_creation_events): New.
2441 (concrete_past_the_end::describe_region_creation_event): Replace
2442 with...
2443 (concrete_past_the_end::add_region_creation_events): ...this.
2444 (symbolic_past_the_end::describe_region_creation_event): Delete.
2445 * checker-event.cc (region_creation_event::region_creation_event):
2446 Update for dropping all member data.
2447 (region_creation_event::get_desc): Delete, splitting out into
2448 region_creation_event_memory_space::get_desc,
2449 region_creation_event_capacity::get_desc, and
2450 region_creation_event_debug::get_desc.
2451 (region_creation_event_memory_space::get_desc): New.
2452 (region_creation_event_capacity::get_desc): New.
2453 (region_creation_event_allocation_size::get_desc): New.
2454 (region_creation_event_debug::get_desc): New.
2455 * checker-event.h: Include "analyzer/program-state.h".
2456 (enum rce_kind): Delete.
2457 (class region_creation_event): Drop all member data.
2458 (region_creation_event::region_creation_event): Make protected.
2459 (region_creation_event::get_desc): Delete.
2460 (class region_creation_event_memory_space): New.
2461 (class region_creation_event_capacity): New.
2462 (class region_creation_event_allocation_size): New.
2463 (class region_creation_event_debug): New.
2464 * checker-path.cc (checker_path::add_region_creation_events): Add
2465 "pd" param. Call pending_diangnostic::add_region_creation_events.
2466 Update for conversion of RCE_DEBUG to region_creation_event_debug.
2467 * checker-path.h (checker_path::add_region_creation_events): Add
2468 "pd" param.
2469 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
2470 Pass pending_diagnostic to
2471 emission_path::add_region_creation_events.
2472 (diagnostic_manager::build_emission_path): Pass path_builder to
2473 add_event_on_final_node.
2474 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
2475 Pass pending_diagnostic to
2476 emission_path::add_region_creation_events.
2477 (diagnostic_manager::add_events_for_eedge): Pass
2478 pending_diagnostic to emission_path::add_region_creation_events.
2479 * diagnostic-manager.h
2480 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
2481 * pending-diagnostic.cc
2482 (pending_diagnostic::add_region_creation_events): New.
2483 * pending-diagnostic.h (struct region_creation): Delete.
2484 (pending_diagnostic::describe_region_creation_event): Delete.
2485 (pending_diagnostic::add_region_creation_events): New vfunc.
2486 * region-model.cc: Include "analyzer/checker-event.h" and
2487 "analyzer/checker-path.h".
2488 (dubious_allocation_size::dubious_allocation_size): Initialize
2489 m_has_allocation_event.
2490 (dubious_allocation_size::describe_region_creation_event): Delete.
2491 (dubious_allocation_size::describe_final_event): Update for
2492 replacement of m_allocation_event with m_has_allocation_event.
2493 (dubious_allocation_size::add_region_creation_events): New.
2494 (dubious_allocation_size::m_allocation_event): Replace with...
2495 (dubious_allocation_size::m_has_allocation_event): ...this.
2496
2497 2022-12-02 David Malcolm <dmalcolm@redhat.com>
2498
2499 PR analyzer/107948
2500 * region-model-manager.cc
2501 (region_model_manager::maybe_fold_binop): Fold (0 - VAL) to -VAL.
2502 * region-model.cc (region_model::eval_condition): Handle e.g.
2503 "-X <= 0" as equivalent to X >= 0".
2504
2505 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2506
2507 PR analyzer/106626
2508 * bounds-checking.cc
2509 (symbolic_past_the_end::describe_final_event): Delete, moving to
2510 symbolic_buffer_overflow::describe_final_event and
2511 symbolic_buffer_over_read::describe_final_event, eliminating
2512 composition of text strings via "byte_str" and "m_dir_str".
2513 (symbolic_past_the_end::m_dir_str): Delete field.
2514 (symbolic_buffer_overflow::symbolic_buffer_overflow): Drop
2515 m_dir_str.
2516 (symbolic_buffer_overflow::describe_final_event): New, as noted
2517 above.
2518 (symbolic_buffer_over_read::symbolic_buffer_overflow): Drop
2519 m_dir_str.
2520 (symbolic_buffer_over_read::describe_final_event): New, as noted
2521 above.
2522
2523 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2524
2525 * bounds-checking.cc (class out_of_bounds): Split out from...
2526 (class concrete_out_of_bounds): New abstract subclass.
2527 (class past_the_end): Rename to...
2528 (class concrete_past_the_end): ...this, and make a subclass of
2529 concrete_out_of_bounds.
2530 (class buffer_overflow): Rename to...
2531 (class concrete_buffer_overflow): ...this, and make a subclass of
2532 concrete_past_the_end.
2533 (class buffer_over_read): Rename to...
2534 (class concrete_buffer_over_read): ...this, and make a subclass of
2535 concrete_past_the_end.
2536 (class buffer_underwrite): Rename to...
2537 (class concrete_buffer_underwrite): ...this, and make a subclass
2538 of concrete_out_of_bounds.
2539 (class buffer_under_read): Rename to...
2540 (class concrete_buffer_under_read): ...this, and make a subclass
2541 of concrete_out_of_bounds.
2542 (class symbolic_past_the_end): Convert to a subclass of
2543 out_of_bounds.
2544 (symbolic_buffer_overflow::get_kind): New.
2545 (symbolic_buffer_over_read::get_kind): New.
2546 (region_model::check_region_bounds): Update for renamings.
2547 * engine.cc (impl_sm_context::set_next_state): Eliminate
2548 "new_ctxt", passing NULL to get_rvalue instead.
2549 (impl_sm_context::warn): Likewise.
2550
2551 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2552
2553 PR analyzer/106626
2554 * bounds-checking.cc (out_of_bounds::get_memory_space): New.
2555 (buffer_overflow::emit): Use it.
2556 (class buffer_overread): Rename to...
2557 (class buffer_over_read): ...this.
2558 (buffer_over_read::emit): Specify which memory space the read is
2559 from, where known. Change "overread" to "over-read".
2560 (class buffer_underflow): Rename to...
2561 (class buffer_underwrite): ...this.
2562 (buffer_underwrite::emit): Specify which memory space the write is
2563 to, where known. Change "underflow" to "underwrite".
2564 (class buffer_underread): Rename to...
2565 (class buffer_under_read): Rename to...
2566 (buffer_under_read::emit): Specify which memory space the read is
2567 from, where known. Change "underread" to "under-read".
2568 (symbolic_past_the_end::get_memory_space): New.
2569 (symbolic_buffer_overflow::emit): Use it.
2570 (class symbolic_buffer_overread): Rename to...
2571 (class symbolic_buffer_over_read): ...this.
2572 (symbolic_buffer_over_read::emit): Specify which memory space the
2573 read is from, where known. Change "overread" to "over-read".
2574 (region_model::check_symbolic_bounds): Update for class renaming.
2575 (region_model::check_region_bounds): Likewise.
2576
2577 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2578
2579 PR analyzer/106626
2580 * bounds-checking.cc (out_of_bounds::maybe_describe_array_bounds):
2581 New.
2582 (buffer_overflow::emit): Call maybe_describe_array_bounds.
2583 (buffer_overread::emit): Likewise.
2584 (buffer_underflow::emit): Likewise.
2585 (buffer_underread::emit): Likewise.
2586
2587 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2588
2589 PR analyzer/106626
2590 * bounds-checking.cc (buffer_overflow::emit): Use inform_n.
2591 Update wording to clarify that we're talking about the size of
2592 the bad access, rather than its position.
2593 (buffer_overread::emit): Likewise.
2594
2595 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2596
2597 * bounds-checking.cc: New file, taken from region-model.cc.
2598 * region-model.cc (class out_of_bounds): Move to
2599 bounds-checking.cc.
2600 (class past_the_end): Likewise.
2601 (class buffer_overflow): Likewise.
2602 (class buffer_overread): Likewise.
2603 (class buffer_underflow): Likewise.
2604 (class buffer_underread): Likewise.
2605 (class symbolic_past_the_end): Likewise.
2606 (class symbolic_buffer_overflow): Likewise.
2607 (class symbolic_buffer_overread): Likewise.
2608 (region_model::check_symbolic_bounds): Likewise.
2609 (maybe_get_integer_cst_tree): Likewise.
2610 (region_model::check_region_bounds): Likewise.
2611 * region-model.h: Add comment.
2612
2613 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2614
2615 PR analyzer/107928
2616 * sm-fd.cc (fd_state_machine::on_bind): Handle m_constant_fd in
2617 the "success" outcome.
2618 (fd_state_machine::on_connect): Likewise.
2619 * sm-fd.dot: Add "constant_fd" state and its transitions.
2620
2621 2022-11-30 David Malcolm <dmalcolm@redhat.com>
2622
2623 * region-model-impl-calls.cc (class kf_fgets): Move to sm-file.cc.
2624 (kf_fgets::impl_call_pre): Likewise.
2625 (class kf_fread): Likewise.
2626 (kf_fread::impl_call_pre): Likewise.
2627 (class kf_getchar): Likewise.
2628 (class kf_stdio_output_fn): Likewise.
2629 (register_known_functions): Move registration of
2630 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2631 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2632 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2633 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2634 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2635 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
2636 "getchar", "fgets", "fgets_unlocked", and "fread" to
2637 register_known_file_functions.
2638 * sm-file.cc (class kf_stdio_output_fn): Move here from
2639 region-model-impl-calls.cc.
2640 (class kf_fgets): Likewise.
2641 (class kf_fread): Likewise.
2642 (class kf_getchar): Likewise.
2643 (register_known_file_functions): Move registration of
2644 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2645 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2646 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2647 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2648 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2649 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
2650 "fgets", "fgets_unlocked", "fread", and "getchar" to here from
2651 register_known_functions.
2652
2653 2022-11-30 David Malcolm <dmalcolm@redhat.com>
2654
2655 PR analyzer/103546
2656 * analyzer.h (register_known_file_functions): New decl.
2657 * program-state.cc (sm_state_map::replay_call_summary): Rejct
2658 attempts to store sm-state for caller_sval that can't have
2659 associated state.
2660 * region-model-impl-calls.cc (register_known_functions): Call
2661 register_known_file_functions.
2662 * sm-fd.cc (class kf_isatty): New.
2663 (register_known_fd_functions): Register it.
2664 * sm-file.cc (class kf_ferror): New.
2665 (class kf_fileno): New.
2666 (class kf_getc): New.
2667 (register_known_file_functions): New.
2668
2669 2022-11-30 David Malcolm <dmalcolm@redhat.com>
2670
2671 PR analyzer/105784
2672 * region-model-manager.cc
2673 (region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
2674 PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
2675 type matches that of arg0 in favor of a cast.
2676
2677 2022-11-24 Martin Liska <mliska@suse.cz>
2678
2679 * varargs.cc: Fix Clang warnings.
2680
2681 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2682
2683 PR analyzer/106473
2684 * call-summary.cc
2685 (call_summary_replay::convert_region_from_summary_1): Update for
2686 change to creation of heap-allocated regions.
2687 * program-state.cc (test_program_state_1): Likewise.
2688 (test_program_state_merging): Likewise.
2689 * region-model-impl-calls.cc (kf_calloc::impl_call_pre): Likewise.
2690 (kf_malloc::impl_call_pre): Likewise.
2691 (kf_operator_new::impl_call_pre): Likewise.
2692 (kf_realloc::impl_call_postsuccess_with_move::update_model): Likewise.
2693 * region-model-manager.cc
2694 (region_model_manager::create_region_for_heap_alloc): Convert
2695 to...
2696 (region_model_manager::get_or_create_region_for_heap_alloc):
2697 ...this, reusing an existing region if it's unreferenced in the
2698 client state.
2699 * region-model-manager.h (region_model_manager::get_num_regions): New.
2700 (region_model_manager::create_region_for_heap_alloc): Convert to...
2701 (region_model_manager::get_or_create_region_for_heap_alloc): ...this.
2702 * region-model.cc (region_to_value_map::can_merge_with_p): Reject
2703 merger when the values are different.
2704 (region_model::create_region_for_heap_alloc): Convert to...
2705 (region_model::get_or_create_region_for_heap_alloc): ...this.
2706 (region_model::get_referenced_base_regions): New.
2707 (selftest::test_state_merging): Update for change to creation of
2708 heap-allocated regions.
2709 (selftest::test_malloc_constraints): Likewise.
2710 (selftest::test_malloc): Likewise.
2711 * region-model.h: Include "sbitmap.h".
2712 (region_model::create_region_for_heap_alloc): Convert to...
2713 (region_model::get_or_create_region_for_heap_alloc): ...this.
2714 (region_model::get_referenced_base_regions): New decl.
2715 * store.cc (store::canonicalize): Don't purge a heap-allocated region
2716 that's been marked as escaping.
2717
2718 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2719
2720 * checker-path.cc (checker_path::inject_any_inlined_call_events):
2721 Don't dump the address of the block when -fdump-noaddr.
2722
2723 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2724
2725 * region-model.h (region_model::on_socket): Delete decl.
2726 (region_model::on_bind): Likewise.
2727 (region_model::on_listen): Likewise.
2728 (region_model::on_accept): Likewise.
2729 (region_model::on_connect): Likewise.
2730 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
2731 of region_model::on_socket into here, ...
2732 (region_model::on_socket): ...eliminating this function.
2733 (kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
2734 (region_model::on_bind): ...eliminating this function.
2735 (kf_listen::outcome_of_listen::update_model): Likewise fo
2736 on_listen...
2737 (region_model::on_listen): ...eliminating this function.
2738 (kf_accept::outcome_of_accept::update_model): Likewise fo
2739 on_accept...
2740 (region_model::on_accept): ...eliminating this function.
2741 (kf_connect::outcome_of_connect::update_model): Likewise fo
2742 on_connect...
2743 (region_model::on_connect): ...eliminating this function.
2744
2745 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2746
2747 * analyzer.h (register_known_fd_functions): New decl.
2748 * region-model-impl-calls.cc (class kf_accept): Move to sm-fd.cc.
2749 (class kf_bind): Likewise.
2750 (class kf_connect): Likewise.
2751 (class kf_listen): Likewise.
2752 (class kf_pipe): Likewise.
2753 (class kf_socket): Likewise.
2754 (register_known_functions): Remove registration of the above
2755 functions, instead calling register_known_fd_functions.
2756 * sm-fd.cc: Include "analyzer/call-info.h".
2757 (class kf_socket): Move here from region-model-impl-calls.cc.
2758 (class kf_bind): Likewise.
2759 (class kf_listen): Likewise.
2760 (class kf_accept): Likewise.
2761 (class kf_connect): Likewise.
2762 (class kf_pipe): Likewise.
2763 (register_known_fd_functions): New.
2764
2765 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2766
2767 PR analyzer/107788
2768 * known-function-manager.cc (known_function_manager::get_match):
2769 Don't look up fndecls by name when they're not in the root
2770 namespace.
2771
2772 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2773
2774 PR analyzer/107783
2775 * sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
2776 complain when old state is "fd-constant".
2777 (fd_state_machine::on_listen): Likewise.
2778 (fd_state_machine::on_accept): Likewise.
2779
2780 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2781
2782 PR analyzer/107807
2783 * region-model-impl-calls.cc (register_known_functions): Register
2784 "___errno" and "__error" as synonyms for "__errno_location".
2785
2786 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2787
2788 * analyzer.h (class internal_known_function): New.
2789 (register_varargs_builtins): New decl.
2790 * engine.cc (exploded_node::on_stmt_pre): Remove
2791 "out_terminate_path" param from call to region_model::on_stmt_pre.
2792 (feasibility_state::maybe_update_for_edge): Likewise.
2793 * known-function-manager.cc: Include "basic-block.h", "gimple.h",
2794 and "analyzer/region-model.h".
2795 (known_function_manager::known_function_manager): Initialize
2796 m_combined_fns_arr.
2797 (known_function_manager::~known_function_manager): Clean up
2798 m_combined_fns_arr.
2799 (known_function_manager::get_by_identifier): Make const.
2800 (known_function_manager::add): New overloaded definitions for
2801 enum built_in_function and enum internal_fn.
2802 (known_function_manager::get_by_fndecl): Delete.
2803 (known_function_manager::get_match): New.
2804 (known_function_manager::get_internal_fn): New.
2805 (known_function_manager::get_normal_builtin): New.
2806 * known-function-manager.h
2807 (known_function_manager::get_by_identifier): Make private and
2808 add const qualifier.
2809 (known_function_manager::get_by_fndecl): Delete.
2810 (known_function_manager::add): Add overloaded decls for
2811 enum built_in_function name and enum internal_fn.
2812 (known_function_manager::get_match): New decl.
2813 (known_function_manager::get_internal_fn): New decl.
2814 (known_function_manager::get_normal_builtin): New decl.
2815 (known_function_manager::m_combined_fns_arr): New field.
2816 * region-model-impl-calls.cc (call_details::arg_is_size_p): New.
2817 (class kf_alloca): New.
2818 (region_model::impl_call_alloca): Convert to...
2819 (kf_alloca::impl_call_pre): ...this.
2820 (kf_analyzer_dump_capacity::matches_call_types_p): Rewrite check
2821 to use call_details::arg_is_pointer_p.
2822 (region_model::impl_call_builtin_expect): Convert to...
2823 (class kf_expect): ...this.
2824 (class kf_calloc): New, adding check that both arguments are
2825 size_t.
2826 (region_model::impl_call_calloc): Convert to...
2827 (kf_calloc::impl_call_pre): ...this.
2828 (kf_connect::matches_call_types_p): Rewrite check to use
2829 call_details::arg_is_pointer_p.
2830 (region_model::impl_call_error): Convert to...
2831 (class kf_error): ...this, and...
2832 (kf_error::impl_call_pre): ...this.
2833 (class kf_fgets): New, adding checks that args 0 and 2 are
2834 pointers.
2835 (region_model::impl_call_fgets): Convert to...
2836 (kf_fgets::impl_call_pre): ...this.
2837 (class kf_fread): New, adding checks on the argument types.
2838 (region_model::impl_call_fread): Convert to...
2839 (kf_fread::impl_call_pre): ...this.
2840 (class kf_free): New, adding check that the argument is a pointer.
2841 (region_model::impl_call_free): Convert to...
2842 (kf_free::impl_call_post): ...this.
2843 (class kf_getchar): New.
2844 (class kf_malloc): New, adding check that the argument is a
2845 size_t.
2846 (region_model::impl_call_malloc): Convert to...
2847 (kf_malloc::impl_call_pre): ...this.
2848 (class kf_memcpy): New, adding checks on arguments.
2849 (region_model::impl_call_memcpy): Convert to...
2850 (kf_memcpy::impl_call_pre): ...this.
2851 (class kf_memset): New.
2852 (region_model::impl_call_memset): Convert to...
2853 (kf_memset::impl_call_pre): ...this.
2854 (kf_pipe::matches_call_types_p): Rewrite check to use
2855 call_details::arg_is_pointer_p.
2856 (kf_putenv::matches_call_types_p): Likewise.
2857 (class kf_realloc): New, adding checks on the argument types.
2858 (region_model::impl_call_realloc): Convert to...
2859 (kf_realloc::impl_call_post): ...this.
2860 (class kf_strchr): New.
2861 (region_model::impl_call_strchr): Convert to...
2862 (kf_strchr::impl_call_post): ...this.
2863 (class kf_stack_restore): New.
2864 (class kf_stack_save): New.
2865 (class kf_stdio_output_fn): New.
2866 (class kf_strcpy): New,
2867 (region_model::impl_call_strcpy): Convert to...
2868 (kf_strcpy::impl_call_pre): ...this.
2869 (class kf_strlen): New.
2870 (region_model::impl_call_strlen): Convert to...
2871 (kf_strlen::impl_call_pre): ...this.
2872 (class kf_ubsan_bounds): New.
2873 (region_model::impl_deallocation_call): Reimplement to avoid call
2874 to impl_call_free.
2875 (register_known_functions): Add handlers for IFN_BUILTIN_EXPECT
2876 and IFN_UBSAN_BOUNDS. Add handlers for BUILT_IN_ALLOCA,
2877 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
2878 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FPRINTF,
2879 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2880 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2881 BUILT_IN_FREE, BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED,
2882 BUILT_IN_MALLOC, BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK,
2883 BUILT_IN_MEMSET, BUILT_IN_MEMSET_CHK, BUILT_IN_PRINTF,
2884 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2885 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2886 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_REALLOC, BUILT_IN_STACK_RESTORE,
2887 BUILT_IN_STACK_SAVE, BUILT_IN_STRCHR, BUILT_IN_STRCPY,
2888 BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN, BUILT_IN_VFPRINTF, and
2889 BUILT_IN_VPRINTF. Call register_varargs_builtins. Add handlers
2890 for "getchar", "memset", "fgets", "fgets_unlocked", "fread",
2891 "error", and "error_at_line".
2892 * region-model.cc (region_model::on_stmt_pre): Drop
2893 "out_terminate_path" param.
2894 (region_model::get_known_function): Reimplement by calling
2895 known_function_manager::get_match, passing new "cd" param.
2896 Add overload taking enum internal_fn.
2897 (region_model::on_call_pre): Drop "out_terminate_path" param.
2898 Remove special-case handling of internal fns IFN_BUILTIN_EXPECT,
2899 IFN_UBSAN_BOUNDS, and IFN_VA_ARG, of built-in fns BUILT_IN_ALLOCA,
2900 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
2901 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FREE, BUILT_IN_MALLOC,
2902 BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMSET,
2903 BUILT_IN_MEMSET_CHK, BUILT_IN_REALLOC, BUILT_IN_STRCHR,
2904 BUILT_IN_STRCPY, BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN,
2905 BUILT_IN_STACK_SAVE, BUILT_IN_STACK_RESTORE, BUILT_IN_FPRINTF,
2906 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED,
2907 BUILT_IN_FPUTC, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS,
2908 BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE,
2909 BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2910 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
2911 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
2912 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF, BUILT_IN_VA_START, and
2913 BUILT_IN_VA_COPY, and of named functions "malloc", "calloc",
2914 "alloca", "realloc", "error", "error_at_line", "fgets",
2915 "fgets_unlocked", "fread", "getchar", "memset", "strchr", and
2916 "strlen". Replace all this special-casing with calls to
2917 get_known_function for internal fns and for fn decls.
2918 (region_model::on_call_post): Remove special-casing handling for
2919 "free" and "strchr", and for BUILT_IN_REALLOC, BUILT_IN_STRCHR,
2920 and BUILT_IN_VA_END. Replace by consolidating on usage of
2921 get_known_function.
2922 * region-model.h (call_details::arg_is_size_p): New.
2923 (region_model::on_stmt_pre): Drop "out_terminate_path" param.
2924 (region_model::on_call_pre): Likewise.
2925 (region_model::impl_call_alloca): Delete.
2926 (region_model::impl_call_builtin_expect): Delete.
2927 (region_model::impl_call_calloc): Delete.
2928 (region_model::impl_call_error): Delete.
2929 (region_model::impl_call_fgets): Delete.
2930 (region_model::impl_call_fread): Delete.
2931 (region_model::impl_call_free): Delete.
2932 (region_model::impl_call_malloc): Delete.
2933 (region_model::impl_call_memcpy): Delete.
2934 (region_model::impl_call_memset): Delete.
2935 (region_model::impl_call_realloc): Delete.
2936 (region_model::impl_call_strchr): Delete.
2937 (region_model::impl_call_strcpy): Delete.
2938 (region_model::impl_call_strlen): Delete.
2939 (region_model::impl_call_va_start): Delete.
2940 (region_model::impl_call_va_copy): Delete.
2941 (region_model::impl_call_va_arg): Delete.
2942 (region_model::impl_call_va_end): Delete.
2943 (region_model::check_region_for_write): Public.
2944 (region_model::get_known_function): Add "cd" param. Add
2945 overloaded decl taking enum internal_fn.
2946 * sm-malloc.cc: Update comments.
2947 * varargs.cc (class kf_va_start): New.
2948 (region_model::impl_call_va_start): Convert to...
2949 (kf_va_start::impl_call_pre): ...this.
2950 (class kf_va_copy): New.
2951 (region_model::impl_call_va_copy): Convert to...
2952 (kf_va_copy::impl_call_pre): ...this.
2953 (class kf_va_arg): New.
2954 (region_model::impl_call_va_arg): Convert to...
2955 (kf_va_arg::impl_call_pre): ...this.
2956 (class kf_va_end): New.
2957 (region_model::impl_call_va_end): Delete.
2958 (register_varargs_builtins): New.
2959
2960 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2961
2962 PR analyzer/107788
2963 * region-model.cc (region_model::update_for_int_cst_return):
2964 Require that the return type be an integer type.
2965 (region_model::update_for_nonzero_return): Likewise.
2966
2967 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2968
2969 PR analyzer/107783
2970 * region-model-impl-calls.cc (kf_accept::matches_call_types_p):
2971 Require that args 1 and 2 be pointers.
2972 (kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
2973 * region-model.h (call_details::arg_is_pointer_p): New
2974
2975 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2976
2977 PR analyzer/107777
2978 * call-summary.cc
2979 (call_summary_replay::convert_region_from_summary_1): Handle
2980 RK_THREAD_LOCAL and RK_ERRNO in switch.
2981 * region-model.cc (region_model::get_representative_path_var_1):
2982 Likewise.
2983
2984 2022-11-19 David Malcolm <dmalcolm@redhat.com>
2985
2986 PR analyzer/107582
2987 * engine.cc (dynamic_call_info_t::update_model): Update the model
2988 by pushing or pop a frame, rather than by clobbering it with the
2989 model from the exploded_node's state.
2990
2991 2022-11-18 David Malcolm <dmalcolm@redhat.com>
2992
2993 * analyzer.cc (is_pipe_call_p): Delete.
2994 * analyzer.h (is_pipe_call_p): Delete.
2995 * region-model-impl-calls.cc (call_details::get_location): New.
2996 (class kf_analyzer_break): New, adapted from
2997 region_model::on_stmt_pre.
2998 (region_model::impl_call_analyzer_describe): Convert to...
2999 (class kf_analyzer_describe): ...this.
3000 (region_model::impl_call_analyzer_dump_capacity): Convert to...
3001 (class kf_analyzer_dump_capacity): ...this.
3002 (region_model::impl_call_analyzer_dump_escaped): Convert to...
3003 (class kf_analyzer_dump_escaped): ...this.
3004 (class kf_analyzer_dump_exploded_nodes): New.
3005 (region_model::impl_call_analyzer_dump_named_constant): Convert
3006 to...
3007 (class kf_analyzer_dump_named_constant): ...this.
3008 (class dump_path_diagnostic): Move here from region-model.cc.
3009 (class kf_analyzer_dump_path) New, adapted from
3010 region_model::on_stmt_pre.
3011 (class kf_analyzer_dump_region_model): Likewise.
3012 (region_model::impl_call_analyzer_eval): Convert to...
3013 (class kf_analyzer_eval): ...this.
3014 (region_model::impl_call_analyzer_get_unknown_ptr): Convert to...
3015 (class kf_analyzer_get_unknown_ptr): ...this.
3016 (class known_function_accept): Rename to...
3017 (class kf_accept): ...this.
3018 (class known_function_bind): Rename to...
3019 (class kf_bind): ...this.
3020 (class known_function_connect): Rename to...
3021 (class kf_connect): ...this.
3022 (region_model::impl_call_errno_location): Convert to...
3023 (class kf_errno_location): ...this.
3024 (class known_function_listen): Rename to...
3025 (class kf_listen): ...this.
3026 (region_model::impl_call_pipe): Convert to...
3027 (class kf_pipe): ...this.
3028 (region_model::impl_call_putenv): Convert to...
3029 (class kf_putenv): ...this.
3030 (region_model::impl_call_operator_new): Convert to...
3031 (class kf_operator_new): ...this.
3032 (region_model::impl_call_operator_delete): Convert to...
3033 (class kf_operator_delete): ...this.
3034 (class known_function_socket): Rename to...
3035 (class kf_socket): ...this.
3036 (register_known_functions): Rename param to KFM. Break out
3037 existing known functions into a "POSIX" section, and add "pipe",
3038 "pipe2", and "putenv". Add debugging functions
3039 "__analyzer_break", "__analyzer_describe",
3040 "__analyzer_dump_capacity", "__analyzer_dump_escaped",
3041 "__analyzer_dump_exploded_nodes",
3042 "__analyzer_dump_named_constant", "__analyzer_dump_path",
3043 "__analyzer_dump_region_model", "__analyzer_eval",
3044 "__analyzer_get_unknown_ptr". Add C++ support functions
3045 "operator new", "operator new []", "operator delete", and
3046 "operator delete []".
3047 * region-model.cc (class dump_path_diagnostic): Move to
3048 region-model-impl-calls.cc.
3049 (region_model::on_stmt_pre): Eliminate special-casing of
3050 "__analyzer_describe", "__analyzer_dump_capacity",
3051 "__analyzer_dump_escaped", "__analyzer_dump_named_constant",
3052 "__analyzer_dump_path", "__analyzer_dump_region_model",
3053 "__analyzer_eval", "__analyzer_break",
3054 "__analyzer_dump_exploded_nodes", "__analyzer_get_unknown_ptr",
3055 "__errno_location", "pipe", "pipe2", "putenv", "operator new",
3056 "operator new []", "operator delete", "operator delete []"
3057 "pipe" and "pipe2", handling them instead via the known_functions
3058 mechanism.
3059 * region-model.h (call_details::get_location): New decl.
3060 (region_model::impl_call_analyzer_describe): Delete decl.
3061 (region_model::impl_call_analyzer_dump_capacity): Delete decl.
3062 (region_model::impl_call_analyzer_dump_escaped): Delete decl.
3063 (region_model::impl_call_analyzer_dump_named_constant): Delete decl.
3064 (region_model::impl_call_analyzer_eval): Delete decl.
3065 (region_model::impl_call_analyzer_get_unknown_ptr): Delete decl.
3066 (region_model::impl_call_errno_location): Delete decl.
3067 (region_model::impl_call_pipe): Delete decl.
3068 (region_model::impl_call_putenv): Delete decl.
3069 (region_model::impl_call_operator_new): Delete decl.
3070 (region_model::impl_call_operator_delete): Delete decl.
3071 * sm-fd.cc: Update comments.
3072
3073 2022-11-16 David Malcolm <dmalcolm@redhat.com>
3074
3075 PR analyzer/107711
3076 * analyzer-language.cc: Include "diagnostic.h".
3077 (maybe_stash_named_constant): Add logger param and use it to log
3078 the name being looked up, and the result.
3079 (stash_named_constants): New, splitting out from...
3080 (on_finish_translation_unit): ...this function. Call
3081 get_or_create_logfile and use the result to create a logger
3082 instance, passing it to stash_named_constants.
3083 * analyzer.h (get_or_create_any_logfile): New decl.
3084 * engine.cc (dump_fout, owns_dump_fout): New globals, split out
3085 from run_checkers.
3086 (get_or_create_any_logfile): New function, split out from...
3087 (run_checkers): ...here, so that the logfile can be opened by
3088 on_finish_translation_unit. Clear the globals when closing the
3089 dump file.
3090
3091 2022-11-16 David Malcolm <dmalcolm@redhat.com>
3092
3093 * analyzer.h (known_function::matches_call_types_p): New vfunc.
3094 (known_function::impl_call_pre): Provide base implementation.
3095 (known_function::impl_call_post): New vfunc.
3096 (register_known_functions): New.
3097 * engine.cc (impl_run_checkers): Call register_known_functions.
3098 * region-model-impl-calls.cc (region_model::impl_call_accept):
3099 Convert to...
3100 (class known_function_accept): ...this.
3101 (region_model::impl_call_bind): Convert to...
3102 (class known_function_bind): ...this.
3103 (region_model::impl_call_connect): Convert to...
3104 (class known_function_connect): ...this.
3105 (region_model::impl_call_listen): Convert to...
3106 (class known_function_listen): ...this.
3107 (region_model::impl_call_socket): Convert to...
3108 (class known_function_socket): ...this.
3109 (register_known_functions): New.
3110 * region-model.cc (region_model::on_call_pre): Remove special
3111 case for "bind" in favor of the known_function-handling dispatch.
3112 Add call to known_function::matches_call_types_p to latter.
3113 (region_model::on_call_post): Remove special cases for "accept",
3114 "bind", "connect", "listen", and "socket" in favor of dispatch
3115 to known_function::impl_call_post.
3116 * region-model.h (region_model::impl_call_accept): Delete decl.
3117 (region_model::impl_call_bind): Delete decl.
3118 (region_model::impl_call_connect): Delete decl.
3119 (region_model::impl_call_listen): Delete decl.
3120 (region_model::impl_call_socket): Delete decl.
3121 * sm-fd.cc: Update comments.
3122
3123 2022-11-16 David Malcolm <dmalcolm@redhat.com>
3124
3125 * checker-event.cc: New file, split out from...
3126 * checker-path.cc: ...this file.
3127
3128 2022-11-15 David Malcolm <dmalcolm@redhat.com>
3129
3130 PR analyzer/106140
3131 * analyzer-language.cc (on_finish_translation_unit): Stash named
3132 constants "SOCK_STREAM" and "SOCK_DGRAM".
3133 * analyzer.opt (Wanalyzer-fd-phase-mismatch): New.
3134 (Wanalyzer-fd-type-mismatch): New.
3135 * engine.cc (impl_region_model_context::get_state_map_by_name):
3136 Add "out_sm_context" param. Allow out_sm_idx to be NULL.
3137 * exploded-graph.h
3138 (impl_region_model_context::get_state_map_by_name):
3139 Add "out_sm_context" param.
3140 * region-model-impl-calls.cc (region_model::impl_call_accept): New.
3141 (region_model::impl_call_bind): New.
3142 (region_model::impl_call_connect): New.
3143 (region_model::impl_call_listen): New.
3144 (region_model::impl_call_socket): New.
3145 * region-model.cc (region_model::on_call_pre): Special-case
3146 "bind".
3147 (region_model::on_call_post): Special-case "accept", "bind",
3148 "connect", "listen", and "socket".
3149 * region-model.h (region_model::impl_call_accept): New decl.
3150 (region_model::impl_call_bind): New decl.
3151 (region_model::impl_call_connect): New decl.
3152 (region_model::impl_call_listen): New decl.
3153 (region_model::impl_call_socket): New decl.
3154 (region_model::on_socket): New decl.
3155 (region_model::on_bind): New decl.
3156 (region_model::on_listen): New decl.
3157 (region_model::on_accept): New decl.
3158 (region_model::on_connect): New decl.
3159 (region_model::add_constraint): Make public.
3160 (region_model::check_for_poison): Make public.
3161 (region_model_context::get_state_map_by_name): Add out_sm_context param.
3162 (region_model_context::get_fd_map): Likewise.
3163 (region_model_context::get_malloc_map): Likewise.
3164 (region_model_context::get_taint_map): Likewise.
3165 (noop_region_model_context::get_state_map_by_name): Likewise.
3166 (region_model_context_decorator::get_state_map_by_name): Likewise.
3167 * sm-fd.cc: Include "analyzer/supergraph.h" and
3168 "analyzer/analyzer-language.h".
3169 (enum expected_phase): New enum.
3170 (fd_state_machine::m_new_datagram_socket): New.
3171 (fd_state_machine::m_new_stream_socket): New.
3172 (fd_state_machine::m_new_unknown_socket): New.
3173 (fd_state_machine::m_bound_datagram_socket): New.
3174 (fd_state_machine::m_bound_stream_socket): New.
3175 (fd_state_machine::m_bound_unknown_socket): New.
3176 (fd_state_machine::m_listening_stream_socket): New.
3177 (fd_state_machine::m_m_connected_stream_socket): New.
3178 (fd_state_machine::m_SOCK_STREAM): New.
3179 (fd_state_machine::m_SOCK_DGRAM): New.
3180 (fd_diagnostic::describe_state_change): Handle socket states.
3181 (fd_diagnostic::get_meaning_for_state_change): Likewise.
3182 (class fd_phase_mismatch): New.
3183 (enum expected_type): New enum.
3184 (class fd_type_mismatch): New.
3185 (fd_state_machine::fd_state_machine): Initialize new states and
3186 stashed named constants.
3187 (fd_state_machine::is_socket_fd_p): New.
3188 (fd_state_machine::is_datagram_socket_fd_p): New.
3189 (fd_state_machine::is_stream_socket_fd_p): New.
3190 (fd_state_machine::on_close): Handle the socket states.
3191 (fd_state_machine::check_for_open_fd): Complain about fncalls on
3192 sockets in the wrong phase. Support socket FDs.
3193 (add_constraint_ge_zero): New.
3194 (fd_state_machine::get_state_for_socket_type): New.
3195 (fd_state_machine::on_socket): New.
3196 (fd_state_machine::check_for_socket_fd): New.
3197 (fd_state_machine::check_for_new_socket_fd): New.
3198 (fd_state_machine::on_bind): New.
3199 (fd_state_machine::on_listen): New.
3200 (fd_state_machine::on_accept): New.
3201 (fd_state_machine::on_connect): New.
3202 (fd_state_machine::can_purge_p): Don't purge socket values.
3203 (get_fd_state): New.
3204 (region_model::mark_as_valid_fd): Use get_fd_state.
3205 (region_model::on_socket): New.
3206 (region_model::on_bind): New.
3207 (region_model::on_listen): New.
3208 (region_model::on_accept): New.
3209 (region_model::on_connect): New.
3210 * sm-fd.dot: Update to reflect sm-fd.cc changes.
3211
3212 2022-11-15 David Malcolm <dmalcolm@redhat.com>
3213
3214 PR analyzer/106302
3215 * analyzer-language.cc: New file.
3216 * analyzer-language.h: New file.
3217 * analyzer.h (get_stashed_constant_by_name): New decl.
3218 (log_stashed_constants): New decl.
3219 * engine.cc (impl_run_checkers): Call log_stashed_constants.
3220 * region-model-impl-calls.cc
3221 (region_model::impl_call_analyzer_dump_named_constant): New.
3222 * region-model.cc (region_model::on_stmt_pre): Handle
3223 __analyzer_dump_named_constant.
3224 * region-model.h
3225 (region_model::impl_call_analyzer_dump_named_constant): New decl.
3226 * sm-fd.cc (fd_state_machine::m_O_ACCMODE): New.
3227 (fd_state_machine::m_O_RDONLY): New.
3228 (fd_state_machine::m_O_WRONLY): New.
3229 (fd_state_machine::fd_state_machine): Initialize the new fields.
3230 (fd_state_machine::get_access_mode_from_flag): Use the new fields,
3231 rather than using the host values.
3232
3233 2022-11-13 David Malcolm <dmalcolm@redhat.com>
3234
3235 PR analyzer/106235
3236 * analyzer.opt (Wanalyzer-tainted-assertion): New.
3237 * checker-path.cc (checker_path::fixup_locations): Pass false to
3238 pending_diagnostic::fixup_location.
3239 * diagnostic-manager.cc (get_emission_location): Pass true to
3240 pending_diagnostic::fixup_location.
3241 * pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
3242 bool param.
3243 * pending-diagnostic.h (pending_diagnostic::fixup_location): Add
3244 bool param to decl.
3245 * sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
3246 (taint_diagnostic::describe_state_change): Drop "final".
3247 (class tainted_assertion): New.
3248 (taint_state_machine::taint_state_machine): Initialize
3249 m_tainted_control_flow.
3250 (taint_state_machine::alt_get_inherited_state): Support
3251 comparisons being tainted, based on their arguments.
3252 (is_assertion_failure_handler_p): New.
3253 (taint_state_machine::on_stmt): Complain about calls to assertion
3254 failure handlers guarded by an attacker-controller conditional.
3255 Detect attacker-controlled gcond conditionals and gswitch index
3256 values.
3257 (taint_state_machine::check_control_flow_arg_for_taint): New.
3258
3259 2022-11-11 David Malcolm <dmalcolm@redhat.com>
3260
3261 * sm-fd.dot: Fix typo in comment.
3262 * sm-file.dot: New file.
3263 * varargs.cc: Fix typo in comment.
3264 * varargs.dot: New file.
3265
3266 2022-11-11 David Malcolm <dmalcolm@redhat.com>
3267
3268 * checker-path.h: Split out checker_event and its subclasses to...
3269 * checker-event.h: ...this new header.
3270
3271 2022-11-11 David Malcolm <dmalcolm@redhat.com>
3272
3273 PR analyzer/106147
3274 * analyzer.opt (Wanalyzer-infinite-recursion): New.
3275 * call-string.cc (call_string::count_occurrences_of_function):
3276 New.
3277 * call-string.h (call_string::count_occurrences_of_function): New
3278 decl.
3279 * checker-path.cc (function_entry_event::function_entry_event):
3280 New ctor.
3281 (checker_path::add_final_event): Delete.
3282 * checker-path.h (function_entry_event::function_entry_event): New
3283 ctor.
3284 (function_entry_event::get_desc): Drop "final".
3285 (checker_path::add_final_event): Delete.
3286 * diagnostic-manager.cc
3287 (diagnostic_manager::emit_saved_diagnostic): Create the final
3288 event via a new pending_diagnostic::add_final_event vfunc, rather
3289 than checker_path::add_final_event.
3290 (diagnostic_manager::add_events_for_eedge): Create function entry
3291 events via a new pending_diagnostic::add_function_entry_event
3292 vfunc.
3293 * engine.cc (exploded_graph::process_node): When creating a new
3294 PK_BEFORE_SUPERNODE node, call
3295 exploded_graph::detect_infinite_recursion on it after adding the
3296 in-edge.
3297 * exploded-graph.h (exploded_graph::detect_infinite_recursion):
3298 New decl.
3299 (exploded_graph::find_previous_entry_to): New decl.
3300 * infinite-recursion.cc: New file.
3301 * pending-diagnostic.cc
3302 (pending_diagnostic::add_function_entry_event): New.
3303 (pending_diagnostic::add_final_event): New.
3304 * pending-diagnostic.h
3305 (pending_diagnostic::add_function_entry_event): New vfunc.
3306 (pending_diagnostic::add_final_event): New vfunc.
3307
3308 2022-11-10 David Malcolm <dmalcolm@redhat.com>
3309
3310 PR analyzer/99671
3311 * analyzer.opt (Wanalyzer-deref-before-check): New warning.
3312 * diagnostic-manager.cc
3313 (null_assignment_sm_context::set_next_state): Only add state
3314 change events for transition to "null" state.
3315 (null_assignment_sm_context::is_transition_to_null): New.
3316 * engine.cc (impl_region_model_context::on_pop_frame): New.
3317 * exploded-graph.h (impl_region_model_context::on_pop_frame): New
3318 decl.
3319 * program-state.cc (sm_state_map::clear_any_state): New.
3320 (sm_state_map::can_merge_with_p): New.
3321 (program_state::can_merge_with_p): Replace requirement that
3322 sm-states be equal in favor of an attempt to merge them.
3323 * program-state.h (sm_state_map::clear_any_state): New decl.
3324 (sm_state_map::can_merge_with_p): New decl.
3325 * region-model.cc (region_model::eval_condition): Make const.
3326 (region_model::pop_frame): Call ctxt->on_pop_frame.
3327 * region-model.h (region_model::eval_condition): Make const.
3328 (region_model_context::on_pop_frame): New vfunc.
3329 (noop_region_model_context::on_pop_frame): New.
3330 (region_model_context_decorator::on_pop_frame): New.
3331 * sm-malloc.cc (enum resource_state): Add RS_ASSUMED_NON_NULL.
3332 (allocation_state::dump_to_pp): Drop "final".
3333 (struct assumed_non_null_state): New subclass.
3334 (malloc_state_machine::m_assumed_non_null): New.
3335 (assumed_non_null_p): New.
3336 (class deref_before_check): New.
3337 (assumed_non_null_state::dump_to_pp): New.
3338 (malloc_state_machine::get_or_create_assumed_non_null_state_for_frame):
3339 New.
3340 (malloc_state_machine::maybe_assume_non_null): New.
3341 (malloc_state_machine::on_stmt): Transition from start state to
3342 "assumed-non-null" state for pointers passed to
3343 __attribute__((nonnull)) arguments, and for pointers explicitly
3344 dereferenced. Call maybe_complain_about_deref_before_check for
3345 pointers explicitly compared against NULL.
3346 (malloc_state_machine::maybe_complain_about_deref_before_check):
3347 New.
3348 (malloc_state_machine::on_deallocator_call): Also transition
3349 "assumed-non-null" states to "freed".
3350 (malloc_state_machine::on_pop_frame): New.
3351 (malloc_state_machine::maybe_get_merged_states_nonequal): New.
3352 * sm-malloc.dot: Update for changes to sm-malloc.cc.
3353 * sm.h (state_machine::on_pop_frame): New.
3354 (state_machine::maybe_get_merged_state): New.
3355 (state_machine::maybe_get_merged_states_nonequal): New.
3356
3357 2022-11-09 David Malcolm <dmalcolm@redhat.com>
3358
3359 * checker-path.cc (checker_event::debug): New.
3360 (checker_path::add_event): Move here from checker-path.h. Add
3361 logging.
3362 * checker-path.h (checker_event::debug): New decl.
3363 (checker_path::checker_path): Add logger param.
3364 (checker_path::add_event): Move definition from here to
3365 checker-path.cc.
3366 (checker_path::m_logger): New field.
3367 * diagnostic-manager.cc
3368 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
3369 checker_path ctor.
3370 (diagnostic_manager::add_events_for_eedge): Log scope when
3371 processing a run of stmts.
3372
3373 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3374
3375 PR analyzer/101962
3376 * region-model-impl-calls.cc: Update comment.
3377 * region-model.cc (region_model::check_symbolic_bounds): Fix
3378 layout of "void" return. Replace usage of
3379 eval_condition_without_cm with eval_condition.
3380 (region_model::eval_condition): Take over body of...
3381 (region_model::eval_condition_without_cm): ...this subroutine,
3382 dropping the latter. Eliminating this distinction avoids issues
3383 where constraints were not considered when recursing.
3384 (region_model::compare_initial_and_pointer): Update comment.
3385 (region_model::symbolic_greater_than): Replace usage of
3386 eval_condition_without_cm with eval_condition.
3387 * region-model.h
3388 (region_model::eval_condition_without_cm): Delete decl.
3389
3390 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3391
3392 * region-model-impl-calls.cc
3393 (region_model::impl_call_errno_location): New.
3394 * region-model-manager.cc
3395 (region_model_manager::region_model_manager): Initialize
3396 m_thread_local_region and m_errno_region.
3397 * region-model-manager.h (region_model_manager::get_errno_region):
3398 New accessor.
3399 (region_model_manager::m_thread_local_region): New.
3400 (region_model_manager::m_errno_region): New.
3401 * region-model.cc (region_model::on_call_pre): Special-case
3402 "__errno_location".
3403 (region_model::set_errno): New.
3404 * region-model.h (impl_call_errno_location): New decl.
3405 (region_model::set_errno): New decl.
3406 * region.cc (thread_local_region::dump_to_pp): New.
3407 (errno_region::dump_to_pp): New.
3408 * region.h (enum memory_space): Add MEMSPACE_THREAD_LOCAL.
3409 (enum region_kind): Add RK_THREAD_LOCAL and RK_ERRNO.
3410 (class thread_local_region): New.
3411 (is_a_helper <const thread_local_region *>::test): New.
3412 (class errno_region): New.
3413 (is_a_helper <const errno_region *>::test): New.
3414 * store.cc (binding_cluster::escaped_p): New.
3415 (store::escaped_p): Treat errno as always having escaped.
3416 (store::replay_call_summary_cluster): Handle RK_THREAD_LOCAL and
3417 RK_ERRNO.
3418 * store.h (binding_cluster::escaped_p): Remove definition.
3419
3420 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3421
3422 * call-info.cc (success_call_info::get_desc): Delete.
3423 (failed_call_info::get_desc): Likewise.
3424 (succeed_or_fail_call_info::get_desc): New.
3425 * call-info.h (class succeed_or_fail_call_info): New.
3426 (class success_call_info): Convert to a subclass of
3427 succeed_or_fail_call_info.
3428 (class failed_call_info): Likewise.
3429
3430 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3431
3432 * region-model-impl-calls.cc (region_model::impl_call_strchr):
3433 Move to on_call_post. Handle both outcomes using bifurcation,
3434 rather than just the "not found" case.
3435 * region-model.cc (region_model::on_call_pre): Move
3436 BUILT_IN_STRCHR and "strchr" to...
3437 (region_model::on_call_post): ...here.
3438
3439 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3440
3441 * analyzer.h: Use std::unique_ptr for state machines from plugins.
3442 * engine.cc: Likewise.
3443
3444 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3445
3446 * analyzer.h: Use std::unique_ptr for known functions.
3447 * engine.cc: Likewise.
3448 * known-function-manager.cc: Likewise.
3449 * known-function-manager.h: Likewise.
3450
3451 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3452
3453 * analysis-plan.cc: Define INCLUDE_MEMORY before including
3454 system.h.
3455 * analyzer-pass.cc: Likewise.
3456 * analyzer-selftests.cc: Likewise.
3457 * analyzer.cc: Likewise.
3458 * analyzer.h: Use std::unique_ptr in bifurcation code.
3459 * call-string.cc: Define INCLUDE_MEMORY before including system.h.
3460 * complexity.cc: Likewise.
3461 * engine.cc: Use std::unique_ptr in bifurcation code.
3462 * exploded-graph.h: Likewise.
3463 * known-function-manager.cc: Define INCLUDE_MEMORY before
3464 including system.h.
3465 * region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
3466 code.
3467 * region-model.cc: Likewise.
3468 * region-model.h: Likewise.
3469 * supergraph.cc: Define INCLUDE_MEMORY before including system.h.
3470
3471 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3472
3473 * call-info.cc: Use std::unique_ptr for checker_event.
3474 * checker-path.cc: Likewise.
3475 * checker-path.h: Likewise.
3476 * diagnostic-manager.cc: Likewise.
3477 * engine.cc: Likewise.
3478 * pending-diagnostic.cc: Likewise.
3479 * sm-signal.cc: Likewise.
3480 * varargs.cc: Likewise.
3481
3482 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3483
3484 * diagnostic-manager.cc: Include "make-unique.h".
3485 Use std::unique_ptr for feasibility_problems and exploded_path.
3486 Delete explicit saved_diagnostic dtor.
3487 * diagnostic-manager.h: Likewise.
3488 * engine.cc: Likewise.
3489 * exploded-graph.h: Likewise.
3490 * feasible-graph.cc: Likewise.
3491 * feasible-graph.h: Likewise.
3492
3493 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3494
3495 * checker-path.cc (rewind_event::rewind_event): Update for usage of
3496 std::unique_ptr on custom_edge_info.
3497 * engine.cc (exploded_node::on_longjmp): Likewise.
3498 (exploded_edge::exploded_edge): Likewise.
3499 (exploded_edge::~exploded_edge): Delete.
3500 (exploded_graph::add_function_entry): Update for usage of
3501 std::unique_ptr on custom_edge_info.
3502 (exploded_graph::add_edge): Likewise.
3503 (add_tainted_args_callback): Likewise.
3504 (exploded_graph::maybe_create_dynamic_call): Likewise.
3505 (exploded_graph::process_node): Likewise.
3506 * exploded-graph.h (exploded_edge::~exploded_edge): Delete.
3507 (exploded_edge::m_custom_info): Use std::unique_ptr.
3508 (exploded_edge::add_edge): Likewise.
3509 * sm-signal.cc (register_signal_handler::impl_transition): Use
3510 make_unique.
3511
3512 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3513
3514 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Make
3515 stmt_finder const.
3516 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of
3517 m_stmt_finder.
3518 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
3519 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
3520 Likewise.
3521 (saved_diagnostic::m_stmt_finder): Convert to std::unique_ptr.
3522 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
3523 * engine.cc (impl_sm_context::impl_sm_context): Likewise.
3524 (impl_sm_context::m_stmt_finder): Likewise.
3525 (leak_stmt_finder::clone): Convert return type to std::unique_ptr.
3526 * exploded-graph.h (stmt_finder::clone): Likewise.
3527
3528 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3529
3530 * call-info.cc: Add define of INCLUDE_MEMORY.
3531 * call-summary.cc: Likewise.
3532 * checker-path.cc: Likewise.
3533 * constraint-manager.cc: Likewise.
3534 * diagnostic-manager.cc: Likewise.
3535 (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for
3536 param d and field m_d.
3537 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d.
3538 (saved_diagnostic::add_note): Use std::unique_ptr for
3539 param pn.
3540 (saved_diagnostic::get_pending_diagnostic): Update for conversion
3541 of m_sd.m_d to unique_ptr.
3542 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
3543 param d. Remove explicit deletion.
3544 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
3545 (diagnostic_manager::emit_saved_diagnostic): Update for conversion
3546 of m_sd.m_d to unique_ptr.
3547 (null_assignment_sm_context::warn): Use std::unique_ptr for
3548 param d. Remove explicit deletion.
3549 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use
3550 std::unique_ptr for param d.
3551 (saved_diagnostic::add_note): Likewise for param pn.
3552 (saved_diagnostic::m_d): Likewise.
3553 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
3554 param d.
3555 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
3556 * engine.cc: Include "make-unique.h".
3557 (impl_region_model_context::warn): Update to use std::unique_ptr
3558 for param, removing explicit deletion.
3559 (impl_region_model_context::add_note): Likewise.
3560 (impl_sm_context::warn): Update to use std::unique_ptr
3561 for param.
3562 (impl_region_model_context::on_state_leak): Likewise for result of
3563 on_leak.
3564 (exploded_node::on_longjmp): Use make_unique when creating
3565 pending_diagnostic.
3566 (exploded_graph::process_node): Likewise.
3567 * exploded-graph.h (impl_region_model_context::warn): Update to
3568 use std::unique_ptr for param.
3569 (impl_region_model_context::add_note): Likewise.
3570 * feasible-graph.cc: Add define of INCLUDE_MEMORY.
3571 * pending-diagnostic.cc: Likewise.
3572 * pending-diagnostic.h: Include analyzer.sm.h"
3573 * program-point.cc: Add define of INCLUDE_MEMORY.
3574 * program-state.cc: Likewise.
3575 * region-model-asm.cc: Likewise.
3576 * region-model-impl-calls.cc: Likewise. Include "make-unique.h".
3577 (region_model::impl_call_putenv): Use make_unique when creating
3578 pending_diagnostic.
3579 * region-model-manager.cc: Add define of INCLUDE_MEMORY.
3580 * region-model-reachability.cc: Likewise.
3581 * region-model.cc: Likewise. Include "make-unique.h".
3582 (region_model::get_gassign_result): Use make_unique when creating
3583 pending_diagnostic.
3584 (region_model::check_for_poison): Likewise.
3585 (region_model::on_stmt_pre): Likewise.
3586 (region_model::check_symbolic_bounds): Likewise.
3587 (region_model::check_region_bounds): Likewise.
3588 (annotating_ctxt: make_note): Use std::unique_ptr for result.
3589 (region_model::deref_rvalue): Use make_unique when creating
3590 pending_diagnostic.
3591 (region_model::check_for_writable_region): Likewise.
3592 (region_model::check_region_size): Likewise.
3593 (region_model::check_dynamic_size_for_floats): Likewise.
3594 (region_model::maybe_complain_about_infoleak): Likewise.
3595 (noop_region_model_context::add_note): Use std::unique_ptr for
3596 param. Remove explicit deletion.
3597 * region-model.h: Include "analyzer/pending-diagnostic.h".
3598 (region_model_context::warn): Convert param to std::unique_ptr.
3599 (region_model_context::add_note): Likewise.
3600 (noop_region_model_context::warn): Likewise.
3601 (noop_region_model_context::add_note): Likewise.
3602 (region_model_context_decorator::warn): Likewise.
3603 (region_model_context_decorator::add_note): Likewise.
3604 (note_adding_context::warn): Likewise.
3605 (note_adding_context::make_note): Likewise for return type.
3606 (test_region_model_context::warn): Convert param to
3607 std::unique_ptr.
3608 * region.cc: Add define of INCLUDE_MEMORY.
3609 * sm-fd.cc: Likewise. Include "make-unique.h".
3610 (fd_state_machine::check_for_fd_attrs): Use make_unique when
3611 creating pending_diagnostics.
3612 (fd_state_machine::on_open): Likewise.
3613 (fd_state_machine::on_creat): Likewise.
3614 (fd_state_machine::check_for_dup): Likewise.
3615 (fd_state_machine::on_close): Likewise.
3616 (fd_state_machine::check_for_open_fd): Likewise.
3617 (fd_state_machine::on_leak): Likewise, converting return type to
3618 std::unique_ptr.
3619 * sm-file.cc: Add define of INCLUDE_MEMORY. Include
3620 "make-unique.h".
3621 (fileptr_state_machine::on_stmt): Use make_unique when creating
3622 pending_diagnostic.
3623 (fileptr_state_machine::on_leak): Likewise, converting return type
3624 to std::unique_ptr.
3625 * sm-malloc.cc: Add define of INCLUDE_MEMORY. Include
3626 "make-unique.h".
3627 (malloc_state_machine::on_stmt): Use make_unique when creating
3628 pending_diagnostic.
3629 (malloc_state_machine::handle_free_of_non_heap): Likewise.
3630 (malloc_state_machine::on_deallocator_call): Likewise.
3631 (malloc_state_machine::on_realloc_call): Likewise.
3632 (malloc_state_machine::on_leak): Likewise, converting return type
3633 to std::unique_ptr.
3634 * sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include
3635 "make-unique.h".
3636 (pattern_test_state_machine::on_condition): Use make_unique when
3637 creating pending_diagnostic.
3638 * sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include
3639 "make-unique.h".
3640 (sensitive_state_machine::warn_for_any_exposure): Use make_unique
3641 when creating pending_diagnostic.
3642 * sm-signal.cc: Add define of INCLUDE_MEMORY. Include
3643 "make-unique.h".
3644 (signal_state_machine::on_stmt): Use make_unique when creating
3645 pending_diagnostic.
3646 * sm-taint.cc: Add define of INCLUDE_MEMORY. Include
3647 "make-unique.h".
3648 (taint_state_machine::check_for_tainted_size_arg): Use make_unique
3649 when creating pending_diagnostic.
3650 (taint_state_machine::check_for_tainted_divisor): Likewise.
3651 (region_model::check_region_for_taint): Likewise.
3652 (region_model::check_dynamic_size_for_taint): Likewise.
3653 * sm.cc: Add define of INCLUDE_MEMORY. Include
3654 "analyzer/pending-diagnostic.h".
3655 (state_machine::on_leak): Move here from sm.h, changing return
3656 type to std::unique_ptr.
3657 * sm.h (state_machine::on_leak): Change return type to
3658 std::unique_ptr. Move defn of base impl to sm.cc
3659 (sm_context::warn): Convert param d to std_unique_ptr.
3660 * state-purge.cc: Add define of INCLUDE_MEMORY.
3661 * store.cc: Likewise.
3662 * svalue.cc: Likewise.
3663 * trimmed-graph.cc: Likewise.
3664 * varargs.cc: Likewise. Include "make-unique.h".
3665 (va_list_state_machine::check_for_ended_va_list): Use make_unique
3666 when creating pending_diagnostic.
3667 (va_list_state_machine::on_leak): Likewise, converting return type
3668 to std::unique_ptr.
3669 (region_model::impl_call_va_arg): Use make_unique when creating
3670 pending_diagnostic.
3671
3672 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3673
3674 PR analyzer/107486
3675 * analyzer.cc (is_pipe_call_p): New.
3676 * analyzer.h (is_pipe_call_p): New decl.
3677 * region-model.cc (region_model::on_call_pre): Use it.
3678 (region_model::on_call_post): Likewise.
3679
3680 2022-10-26 David Malcolm <dmalcolm@redhat.com>
3681
3682 * sm-fd.cc (fd_state_machine::on_open): Transition to "unchecked"
3683 when the mode is symbolic, rather than just on integer constants.
3684 (fd_state_machine::check_for_open_fd): Don't complain about
3685 unchecked values in the start state.
3686
3687 2022-10-26 David Malcolm <dmalcolm@redhat.com>
3688
3689 * sm-fd.dot: New file.
3690
3691 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3692
3693 PR analyzer/107349
3694 * varargs.cc (get_va_copy_arg): Fix the non-pointer case.
3695
3696 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3697
3698 PR analyzer/107345
3699 * region-model.cc (region_model::eval_condition_without_cm):
3700 Ensure that constants are on the right-hand side before checking
3701 for them.
3702
3703 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3704
3705 * engine.cc (impl_region_model_context::get_malloc_map): Replace
3706 with...
3707 (impl_region_model_context::get_state_map_by_name): ...this.
3708 (impl_region_model_context::get_fd_map): Delete.
3709 (impl_region_model_context::get_taint_map): Delete.
3710 * exploded-graph.h (impl_region_model_context::get_fd_map):
3711 Delete.
3712 (impl_region_model_context::get_malloc_map): Delete.
3713 (impl_region_model_context::get_taint_map): Delete.
3714 (impl_region_model_context::get_state_map_by_name): New.
3715 * region-model.h (region_model_context::get_state_map_by_name):
3716 New vfunc.
3717 (region_model_context::get_fd_map): Convert from vfunc to
3718 function.
3719 (region_model_context::get_malloc_map): Likewise.
3720 (region_model_context::get_taint_map): Likewise.
3721 (noop_region_model_context::get_state_map_by_name): New.
3722 (noop_region_model_context::get_fd_map): Delete.
3723 (noop_region_model_context::get_malloc_map): Delete.
3724 (noop_region_model_context::get_taint_map): Delete.
3725 (region_model_context_decorator::get_state_map_by_name): New.
3726 (region_model_context_decorator::get_fd_map): Delete.
3727 (region_model_context_decorator::get_malloc_map): Delete.
3728 (region_model_context_decorator::get_taint_map): Delete.
3729
3730 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3731
3732 PR analyzer/106300
3733 * engine.cc (impl_region_model_context::get_fd_map): New.
3734 * exploded-graph.h (impl_region_model_context::get_fd_map): New
3735 decl.
3736 * region-model-impl-calls.cc (region_model::impl_call_pipe): New.
3737 * region-model.cc (region_model::update_for_int_cst_return): New,
3738 based on...
3739 (region_model::update_for_zero_return): ...this. Reimplement in
3740 terms of the former.
3741 (region_model::on_call_pre): Handle "pipe" and "pipe2".
3742 (region_model::on_call_post): Likewise.
3743 * region-model.h (region_model::impl_call_pipe): New decl.
3744 (region_model::update_for_int_cst_return): New decl.
3745 (region_model::mark_as_valid_fd): New decl.
3746 (region_model_context::get_fd_map): New pure virtual fn.
3747 (noop_region_model_context::get_fd_map): New.
3748 (region_model_context_decorator::get_fd_map): New.
3749 * sm-fd.cc: Include "analyzer/program-state.h".
3750 (fd_state_machine::describe_state_change): Handle transitions from
3751 start state to valid states.
3752 (fd_state_machine::mark_as_valid_fd): New.
3753 (fd_state_machine::on_stmt): Add missing return for "creat".
3754 (region_model::mark_as_valid_fd): New.
3755
3756 2022-10-19 David Malcolm <dmalcolm@redhat.com>
3757
3758 PR analyzer/105765
3759 * varargs.cc (get_BT_VALIST_ARG): Rename to...
3760 (get_va_copy_arg): ...this, and update logic for determining level
3761 of indirection of va_copy's argument to use type of argument,
3762 rather than looking at va_list_type_node, to correctly handle
3763 __builtin_ms_va_copy.
3764 (get_stateful_BT_VALIST_ARG): Rename to...
3765 (get_stateful_va_copy_arg): ...this.
3766 (va_list_state_machine::on_va_copy): Update for renaming.
3767 (region_model::impl_call_va_copy): Likewise.
3768
3769 2022-10-13 David Malcolm <dmalcolm@redhat.com>
3770
3771 PR analyzer/107210
3772 * svalue.cc (constant_svalue::maybe_fold_bits_within): Only
3773 attempt to extract individual bits when tree_fits_uhwi_p.
3774
3775 2022-10-07 David Malcolm <dmalcolm@redhat.com>
3776
3777 PR analyzer/105783
3778 * region-model.cc (selftest::get_bit): New function.
3779 (selftest::test_bits_within_svalue_folding): New.
3780 (selfftest::analyzer_region_model_cc_tests): Call it.
3781 * svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
3782 case of extracting a single bit.
3783
3784 2022-10-06 David Malcolm <dmalcolm@redhat.com>
3785
3786 PR analyzer/107158
3787 * store.cc (store::replay_call_summary_cluster): Eliminate
3788 special-casing of RK_HEAP_ALLOCATED in favor of sharing code with
3789 RK_DECL, avoiding an ICE due to attempting to bind a
3790 compound_svalue into a binding_cluster when an svalue in the
3791 summary cluster converts to a compound_svalue in the caller.
3792
3793 2022-10-06 David Malcolm <dmalcolm@redhat.com>
3794
3795 * call-summary.cc (call_summary_replay::dump_to_pp): Bulletproof
3796 against NULL caller regions/svalues.
3797
3798 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3799
3800 * analysis-plan.cc: Simplify includes.
3801 * analyzer-pass.cc: Likewise.
3802 * analyzer-selftests.cc: Likewise.
3803 * analyzer.cc: Likewise.
3804 * analyzer.h: Add includes of "json.h" and "tristate.h".
3805 * call-info.cc: Simplify includes.
3806 * call-string.cc: Likewise.
3807 * call-summary.cc: Likewise.
3808 * checker-path.cc: Likewise.
3809 * complexity.cc: Likewise.
3810 * constraint-manager.cc: Likewise.
3811 * diagnostic-manager.cc: Likewise.
3812 * engine.cc: Likewise.
3813 * feasible-graph.cc: Likewise.
3814 * known-function-manager.cc: Likewise.
3815 * pending-diagnostic.cc: Likewise.
3816 * program-point.cc: Likewise.
3817 * program-state.cc: Likewise.
3818 * region-model-asm.cc: Likewise.
3819 * region-model-impl-calls.cc: Likewise.
3820 * region-model-manager.cc: Likewise.
3821 * region-model-reachability.cc: Likewise.
3822 * region-model.cc: Likewise.
3823 * region-model.h: Include "selftest.h".
3824 * region.cc: Simplify includes.
3825 * sm-fd.cc: Likewise.
3826 * sm-file.cc: Likewise.
3827 * sm-malloc.cc: Likewise.
3828 * sm-pattern-test.cc: Likewise.
3829 * sm-sensitive.cc: Likewise.
3830 * sm-signal.cc: Likewise.
3831 * sm-taint.cc: Likewise.
3832 * sm.cc: Likewise.
3833 * state-purge.cc: Likewise.
3834 * store.cc: Likewise.
3835 * store.h: Likewise.
3836 * supergraph.cc: Likewise.
3837 * svalue.cc: Likewise.
3838 * svalue.h: Likewise.
3839 * trimmed-graph.cc: Likewise.
3840 * varargs.cc: Likewise.
3841
3842 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3843
3844 PR analyzer/107060
3845 * call-summary.cc
3846 (call_summary_replay::convert_svalue_from_summary_1): Handle NULL
3847 results from convert_svalue_from_summary in SK_UNARY_OP and
3848 SK_BIN_OP.
3849 * engine.cc (impl_region_model_context::on_unknown_change): Bail
3850 out on svalues that can't have associated state.
3851 * region-model-impl-calls.cc
3852 (region_model::impl_call_analyzer_get_unknown_ptr): New.
3853 * region-model.cc (region_model::on_stmt_pre): Handle
3854 "__analyzer_get_unknown_ptr".
3855 * region-model.h
3856 (region_model::impl_call_analyzer_get_unknown_ptr): New decl.
3857 * store.cc (store::replay_call_summary_cluster): Avoid trying to
3858 create binding clusters for base regions that shouldn't have them.
3859
3860 2022-10-05 Martin Liska <mliska@suse.cz>
3861
3862 * call-summary.cc (call_summary_replay::call_summary_replay):
3863 Remove unused variable and arguments.
3864 * call-summary.h: Likewise.
3865 * engine.cc (exploded_node::on_stmt): Likewise.
3866 (exploded_node::replay_call_summaries): Likewise.
3867 (exploded_node::replay_call_summary): Likewise.
3868 * exploded-graph.h (class exploded_node): Likewise.
3869
3870 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3871
3872 PR analyzer/107072
3873 * analyzer-logging.h: Include "diagnostic-core.h".
3874 * analyzer.h: Include "function.h".
3875 (class call_summary): New forward decl.
3876 (class call_summary_replay): New forward decl.
3877 (struct per_function_data): New forward decl.
3878 (struct interesting_t): New forward decl.
3879 (custom_edge_info::update_state): New vfunc.
3880 * call-info.cc (custom_edge_info::update_state): New.
3881 * call-summary.cc: New file.
3882 * call-summary.h: New file.
3883 * constraint-manager.cc: Include "analyzer/call-summary.h".
3884 (class replay_fact_visitor): New.
3885 (constraint_manager::replay_call_summary): New.
3886 * constraint-manager.h (constraint_manager::replay_call_summary):
3887 New.
3888 * engine.cc: Include "analyzer/call-summary.h".
3889 (exploded_node::on_stmt): Handle call summaries.
3890 (class call_summary_edge_info): New.
3891 (exploded_node::replay_call_summaries): New.
3892 (exploded_node::replay_call_summary): New.
3893 (per_function_data::~per_function_data): New.
3894 (per_function_data::add_call_summary): Move here from header and
3895 reimplement.
3896 (exploded_graph::process_node): Call update_state rather than
3897 update_model when handling bifurcation
3898 (viz_callgraph_node::dump_dot): Use a regular label rather
3899 than an HTML table; add summaries to dump.
3900 * exploded-graph.h: Include "alloc-pool.h", "fibonacci_heap.h",
3901 "supergraph.h", "sbitmap.h", "shortest-paths.h", "analyzer/sm.h",
3902 "analyzer/program-state.h", and "analyzer/diagnostic-manager.h".
3903 (exploded_node::replay_call_summaries): New decl.
3904 (exploded_node::replay_call_summary): New decl.
3905 (per_function_data::~per_function_data): New decl.
3906 (per_function_data::add_call_summary): Move implemention from
3907 header.
3908 (per_function_data::m_summaries): Update type of element.
3909 * known-function-manager.h: Include "analyzer/analyzer-logging.h".
3910 * program-point.h: Include "pretty-print.h" and
3911 "analyzer/call-string.h".
3912 * program-state.cc: Include "analyzer/call-summary.h".
3913 (sm_state_map::replay_call_summary): New.
3914 (program_state::replay_call_summary): New.
3915 * program-state.h (sm_state_map::replay_call_summary): New decl.
3916 (program_state::replay_call_summary): New decl.
3917 * region-model-manager.cc
3918 (region_model_manager::get_or_create_asm_output_svalue): New
3919 overload.
3920 * region-model-manager.h
3921 (region_model_manager::get_or_create_asm_output_svalue): New
3922 overload decl.
3923 * region-model.cc: Include "analyzer/call-summary.h".
3924 (region_model::maybe_update_for_edge): Remove call to
3925 region_model::update_for_call_summary on
3926 SUPEREDGE_INTRAPROCEDURAL_CALL.
3927 (region_model::update_for_call_summary): Delete.
3928 (region_model::replay_call_summary): New.
3929 * region-model.h (region_model::replay_call_summary): New decl.
3930 (region_model::update_for_call_summary): Delete decl.
3931 * store.cc: Include "analyzer/call-summary.h".
3932 (store::replay_call_summary): New.
3933 (store::replay_call_summary_cluster): New.
3934 * store.h: Include "tristate.h".
3935 (is_a_helper <const ana::concrete_binding *>::test): New.
3936 (store::replay_call_summary): New decl.
3937 (store::replay_call_summary_cluster): New decl.
3938 * supergraph.cc (get_ultimate_function_for_cgraph_edge): Remove
3939 "static" from decl.
3940 (supergraph_call_edge): Make stmt param const.
3941 * supergraph.h: Include "ordered-hash-map.h", "cfg.h",
3942 "basic-block.h", "gimple.h", "gimple-iterator.h", and "digraph.h".
3943 (supergraph_call_edge): Make stmt param const.
3944 (get_ultimate_function_for_cgraph_edge): New decl.
3945 * svalue.cc (compound_svalue::compound_svalue): Assert that we're
3946 not nesting compound_svalues.
3947 * svalue.h: Include "json.h", "analyzer/store.h", and
3948 "analyzer/program-point.h".
3949 (asm_output_svalue::get_num_outputs): New accessor.
3950
3951 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3952
3953 * region-model.h: Include "analyzer/region-model-manager.h"
3954 (class region_model_manager): Move decl to...
3955 * region-model-manager.h: ...this new file.
3956
3957 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3958
3959 * region-model-manager.cc
3960 (region_model_manager::maybe_fold_unaryop): Fold -(-(VAL)) to VAL.
3961
3962 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3963
3964 * region-model-manager.cc
3965 (region_model_manager::get_or_create_widening_svalue): Use a
3966 function_point rather than a program_point.
3967 * region-model.cc (selftest::test_widening_constraints): Likewise.
3968 * region-model.h
3969 (region_model_manager::get_or_create_widening_svalue): Likewise.
3970 (model_merger::get_function_point): New.
3971 * svalue.cc (svalue::can_merge_p): Use a function_point rather
3972 than a program_point.
3973 (svalue::can_merge_p): Likewise.
3974 * svalue.h (widening_svalue::key_t): Likewise.
3975 (widening_svalue::widening_svalue): Likewise.
3976
3977 2022-09-12 Martin Liska <mliska@suse.cz>
3978
3979 * region-model.cc (region_model::maybe_complain_about_infoleak):
3980 Remove unused fields.
3981
3982 2022-09-11 Tim Lange <mail@tim-lange.me>
3983
3984 PR analyzer/106845
3985 * region-model.cc (region_model::check_region_bounds):
3986 Bail out if 0 bytes were accessed.
3987 * store.cc (byte_range::dump_to_pp):
3988 Add special case for empty ranges.
3989 (byte_range::exceeds_p): Restrict to non-empty ranges.
3990 (byte_range::falls_short_of_p): Restrict to non-empty ranges.
3991 * store.h (bit_range::empty_p): New function.
3992 (bit_range::get_last_byte_offset): Restrict to non-empty ranges.
3993 (byte_range::empty_p): New function.
3994 (byte_range::get_last_byte_offset): Restrict to non-empty ranges.
3995
3996 2022-09-09 David Malcolm <dmalcolm@redhat.com>
3997
3998 * analyzer.opt (Wanalyzer-exposure-through-uninit-copy): New.
3999 * checker-path.cc (region_creation_event::region_creation_event):
4000 Add "capacity" and "kind" params.
4001 (region_creation_event::get_desc): Generalize to different kinds
4002 of event.
4003 (checker_path::add_region_creation_event): Convert to...
4004 (checker_path::add_region_creation_events): ...this.
4005 * checker-path.h (enum rce_kind): New.
4006 (region_creation_event::region_creation_event): Add "capacity" and
4007 "kind" params.
4008 (region_creation_event::m_capacity): New field.
4009 (region_creation_event::m_rce_kind): New field.
4010 (checker_path::add_region_creation_event): Convert to...
4011 (checker_path::add_region_creation_events): ...this.
4012 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
4013 Update for multiple region creation events.
4014 (diagnostic_manager::add_event_on_final_node): Likewise.
4015 (diagnostic_manager::add_events_for_eedge): Likewise.
4016 * region-model-impl-calls.cc (call_details::get_logger): New.
4017 * region-model.cc: Define INCLUDE_MEMORY before including
4018 "system.h". Include "gcc-rich-location.h".
4019 (class record_layout): New.
4020 (class exposure_through_uninit_copy): New.
4021 (contains_uninit_p): New.
4022 (region_model::maybe_complain_about_infoleak): New.
4023 * region-model.h (call_details::get_logger): New decl.
4024 (region_model::maybe_complain_about_infoleak): New decl.
4025 (region_model::mark_as_tainted): New decl.
4026 * sm-taint.cc (region_model::mark_as_tainted): New.
4027
4028 2022-09-09 David Malcolm <dmalcolm@redhat.com>
4029
4030 * analyzer.h (class known_function_manager): New forward decl.
4031 (class known_function): New.
4032 (plugin_analyzer_init_iface::register_known_function): New.
4033 * engine.cc: Include "analyzer/known-function-manager.h".
4034 (plugin_analyzer_init_impl::plugin_analyzer_init_impl): Add
4035 known_fn_mgr param.
4036 (plugin_analyzer_init_impl::register_state_machine): Add
4037 LOC_SCOPE.
4038 (plugin_analyzer_init_impl::register_known_function): New.
4039 (plugin_analyzer_init_impl::m_known_fn_mgr): New.
4040 (impl_run_checkers): Update plugin callback invocation to use
4041 eng's known_function_manager.
4042 * known-function-manager.cc: New file.
4043 * known-function-manager.h: New file.
4044 * region-model-manager.cc
4045 (region_model_manager::region_model_manager): Pass logger to
4046 m_known_fn_mgr's ctor.
4047 * region-model.cc (region_model::update_for_zero_return): New.
4048 (region_model::update_for_nonzero_return): New.
4049 (maybe_simplify_upper_bound): New.
4050 (region_model::maybe_get_copy_bounds): New.
4051 (region_model::get_known_function): New.
4052 (region_model::on_call_pre): Handle plugin-supplied known
4053 functions.
4054 * region-model.h: Include "analyzer/known-function-manager.h".
4055 (region_model_manager::get_known_function_manager): New.
4056 (region_model_manager::m_known_fn_mgr): New.
4057 (call_details::get_model): New accessor.
4058 (region_model::maybe_get_copy_bounds): New decl.
4059 (region_model::update_for_zero_return): New decl.
4060 (region_model::update_for_nonzero_return): New decl.
4061 (region_model::get_known_function): New decl.
4062 (region_model::get_known_function_manager): New.
4063
4064 2022-09-08 Tim Lange <mail@tim-lange.me>
4065
4066 PR analyzer/106625
4067 * analyzer.h (region_offset): Eliminate m_is_symbolic member.
4068 * region-model-impl-calls.cc (region_model::impl_call_realloc):
4069 Refine implementation to be more precise.
4070 * region-model.cc (class symbolic_past_the_end):
4071 Abstract diagnostic class to complain about accesses past the end
4072 with symbolic values.
4073 (class symbolic_buffer_overflow):
4074 Concrete diagnostic class to complain about buffer overflows with
4075 symbolic values.
4076 (class symbolic_buffer_overread):
4077 Concrete diagnostic class to complain about buffer overreads with
4078 symbolic values.
4079 (region_model::check_symbolic_bounds): New function.
4080 (maybe_get_integer_cst_tree): New helper function.
4081 (region_model::check_region_bounds):
4082 Add call to check_symbolic_bounds if offset is not concrete.
4083 (region_model::eval_condition_without_cm):
4084 Add support for EQ_EXPR and GT_EXPR with binaryop_svalues.
4085 (is_positive_svalue): New hleper function.
4086 (region_model::symbolic_greater_than):
4087 New function to handle GT_EXPR comparisons with symbolic values.
4088 (region_model::structural_equality): New function to compare
4089 whether two svalues are structured the same, i.e. evaluate to
4090 the same value.
4091 (test_struct): Reflect changes to region::calc_offset.
4092 (test_var): Likewise.
4093 (test_array_2): Likewise and add selftest with symbolic i.
4094 * region-model.h (class region_model): Add check_symbolic_bounds,
4095 symbolic_greater_than and structural_equality.
4096 * region.cc (region::get_offset):
4097 Reflect changes to region::calc_offset.
4098 (region::calc_offset):
4099 Compute the symbolic offset if the offset is not concrete.
4100 (region::get_relative_symbolic_offset): New function to return the
4101 symbolic offset in bytes relative to its parent.
4102 (field_region::get_relative_symbolic_offset): Likewise.
4103 (element_region::get_relative_symbolic_offset): Likewise.
4104 (offset_region::get_relative_symbolic_offset): Likewise.
4105 (bit_range_region::get_relative_symbolic_offset): Likewise.
4106 * region.h: Add get_relative_symbolic_offset.
4107 * store.cc (binding_key::make):
4108 Reflect changes to region::calc_offset.
4109 (binding_map::apply_ctor_val_to_range): Likewise.
4110 (binding_map::apply_ctor_pair_to_child_region): Likewise.
4111 (binding_cluster::bind_compound_sval): Likewise.
4112 (binding_cluster::get_any_binding): Likewise.
4113 (binding_cluster::maybe_get_compound_binding): Likewise.
4114
4115 2022-09-05 Tim Lange <mail@tim-lange.me>
4116
4117 * region-model-impl-calls.cc (region_model::impl_call_strcpy):
4118 Handle the constant string case.
4119 * region-model.cc (region_model::get_string_size):
4120 New function to get the string size from a region or svalue.
4121 * region-model.h (class region_model): Add get_string_size.
4122
4123 2022-09-05 Tim Lange <mail@tim-lange.me>
4124
4125 * region.cc (cast_region::get_relative_concrete_offset):
4126 New overloaded method.
4127 * region.h: Add cast_region::get_relative_concrete_offset.
4128
4129 2022-08-22 Martin Liska <mliska@suse.cz>
4130
4131 * region-model.cc: Add missing final keyword.
4132
4133 2022-08-18 Tim Lange <mail@tim-lange.me>
4134
4135 PR analyzer/106181
4136 * analyzer.opt: Add Wanalyzer-imprecise-floating-point-arithmetic.
4137 * region-model.cc (is_any_cast_p): Formatting.
4138 (region_model::check_region_size): Ensure precondition.
4139 (class imprecise_floating_point_arithmetic): New abstract
4140 diagnostic class for all floating-point related warnings.
4141 (class float_as_size_arg): Concrete diagnostic class to complain
4142 about floating-point operands inside the size argument.
4143 (class contains_floating_point_visitor):
4144 New visitor to find floating-point operands inside svalues.
4145 (region_model::check_dynamic_size_for_floats): New function.
4146 (region_model::set_dynamic_extents):
4147 Call to check_dynamic_size_for_floats.
4148 * region-model.h (class region_model):
4149 Add region_model::check_dynamic_size_for_floats.
4150
4151 2022-08-16 Martin Liska <mliska@suse.cz>
4152
4153 * region-model.cc: Fix -Winconsistent-missing-override clang
4154 warning.
4155 * region.h: Likewise.
4156
4157 2022-08-15 David Malcolm <dmalcolm@redhat.com>
4158
4159 PR analyzer/106626
4160 * region-model.cc (buffer_overread::emit): Fix copy&paste error in
4161 direction of the access in the note.
4162
4163 2022-08-15 David Malcolm <dmalcolm@redhat.com>
4164
4165 PR analyzer/106573
4166 * region-model.cc (region_model::on_call_pre): Use check_call_args
4167 when ensuring that we call get_arg_svalue on all args. Remove
4168 redundant call from handling for stdio builtins.
4169
4170 2022-08-15 Immad Mir <mirimmad@outlook.com>
4171
4172 PR analyzer/106551
4173 * sm-fd.cc (check_for_dup): exit early if first
4174 argument is invalid for all dup functions.
4175
4176 2022-08-12 Tim Lange <mail@tim-lange.me>
4177
4178 PR analyzer/106000
4179 * analyzer.opt: Add Wanalyzer-out-of-bounds.
4180 * region-model.cc (class out_of_bounds): Diagnostics base class
4181 for all out-of-bounds diagnostics.
4182 (class past_the_end): Base class derived from out_of_bounds for
4183 the buffer_overflow and buffer_overread diagnostics.
4184 (class buffer_overflow): Buffer overflow diagnostics.
4185 (class buffer_overread): Buffer overread diagnostics.
4186 (class buffer_underflow): Buffer underflow diagnostics.
4187 (class buffer_underread): Buffer overread diagnostics.
4188 (region_model::check_region_bounds): New function to check region
4189 bounds for out-of-bounds accesses.
4190 (region_model::check_region_access):
4191 Add call to check_region_bounds.
4192 (region_model::get_representative_tree): New function that accepts
4193 a region instead of an svalue.
4194 * region-model.h (class region_model):
4195 Add region_model::check_region_bounds.
4196 * region.cc (region::symbolic_p): New predicate.
4197 (offset_region::get_byte_size_sval): Only return the remaining
4198 byte size on offset_regions.
4199 * region.h: Add region::symbolic_p.
4200 * store.cc (byte_range::intersects_p):
4201 Add new function equivalent to bit_range::intersects_p.
4202 (byte_range::exceeds_p): New function.
4203 (byte_range::falls_short_of_p): New function.
4204 * store.h (struct byte_range): Add byte_range::intersects_p,
4205 byte_range::exceeds_p and byte_range::falls_short_of_p.
4206
4207 2022-08-12 Tim Lange <mail@tim-lange.me>
4208
4209 PR analyzer/106539
4210 * region-model-impl-calls.cc (region_model::impl_call_realloc):
4211 Use the result of get_copied_size as the size for the
4212 sized_regions in realloc.
4213 (success_with_move::get_copied_size): New function.
4214
4215 2022-08-11 Immad Mir <mirimmad@outlook.com>
4216
4217 PR analyzer/106551
4218 * sm-fd.cc (check_for_dup): handle the m_start
4219 state when transitioning the state of LHS
4220 of dup, dup2 and dup3 call.
4221
4222 2022-08-09 David Malcolm <dmalcolm@redhat.com>
4223
4224 PR analyzer/106573
4225 * region-model.cc (region_model::on_call_pre): Ensure that we call
4226 get_arg_svalue on all arguments.
4227
4228 2022-08-05 David Malcolm <dmalcolm@redhat.com>
4229
4230 PR analyzer/105947
4231 * analyzer.opt (Wanalyzer-jump-through-null): New option.
4232 * engine.cc (class jump_through_null): New.
4233 (exploded_graph::process_node): Complain about jumps through NULL
4234 function pointers.
4235
4236 2022-08-02 Immad Mir <mirimmad@outlook.com>
4237
4238 PR analyzer/106298
4239 * sm-fd.cc (fd_state_machine::on_open): Add
4240 creat, dup, dup2 and dup3 functions.
4241 (enum dup): New.
4242 (fd_state_machine::valid_to_unchecked_state): New.
4243 (fd_state_machine::on_creat): New.
4244 (fd_state_machine::on_dup): New.
4245
4246 2022-07-28 David Malcolm <dmalcolm@redhat.com>
4247
4248 PR analyzer/105893
4249 * analyzer.opt (Wanalyzer-putenv-of-auto-var): New.
4250 * region-model-impl-calls.cc (class putenv_of_auto_var): New.
4251 (region_model::impl_call_putenv): New.
4252 * region-model.cc (region_model::on_call_pre): Handle putenv.
4253 * region-model.h (region_model::impl_call_putenv): New decl.
4254
4255 2022-07-28 David Malcolm <dmalcolm@redhat.com>
4256
4257 * sm-malloc.cc (free_of_non_heap::emit): Add comment about CWE.
4258 * sm-taint.cc (tainted_size::emit): Likewise.
4259
4260 2022-07-28 David Malcolm <dmalcolm@redhat.com>
4261
4262 * region.h: Add notes to the comment describing the region
4263 class hierarchy.
4264
4265 2022-07-27 Immad Mir <mirimmad@outlook.com>
4266
4267 PR analyzer/106286
4268 * sm-fd.cc:
4269 (fd_diagnostic::get_meaning_for_state_change): New.
4270
4271 2022-07-26 David Malcolm <dmalcolm@redhat.com>
4272
4273 PR analyzer/106319
4274 * store.cc (store::set_value): Don't strip away casts if the
4275 region has NULL type.
4276
4277 2022-07-26 David Malcolm <dmalcolm@redhat.com>
4278
4279 * region.h (code_region::get_element): Remove stray decl.
4280 (function_region::get_element): Likewise.
4281
4282 2022-07-25 Martin Liska <mliska@suse.cz>
4283
4284 * sm-fd.cc: Run dos2unix and fix coding style issues.
4285
4286 2022-07-23 Immad Mir <mirimmad@outlook.com>
4287
4288 * sm-fd.cc (fd_param_diagnostic): New diagnostic class.
4289 (fd_access_mode_mismatch): Change inheritance from fd_diagnostic
4290 to fd_param_diagnostic. Add new overloaded constructor.
4291 (fd_use_after_close): Likewise.
4292 (unchecked_use_of_fd): Likewise and also change name to fd_use_without_check.
4293 (double_close): Change name to fd_double_close.
4294 (enum access_directions): New.
4295 (fd_state_machine::on_stmt): Handle calls to function with the
4296 new three function attributes.
4297 (fd_state_machine::check_for_fd_attrs): New.
4298 (fd_state_machine::on_open): Use the new overloaded constructors
4299 of diagnostic classes.
4300
4301 2022-07-22 David Malcolm <dmalcolm@redhat.com>
4302
4303 PR analyzer/106413
4304 * varargs.cc (region_model::impl_call_va_start): Avoid iterating
4305 through non-existant variadic arguments by initializing the
4306 impl_region to "UNKNOWN" if the va_start occurs in the top-level
4307 function to the analysis.
4308
4309 2022-07-22 David Malcolm <dmalcolm@redhat.com>
4310
4311 PR analyzer/106401
4312 * store.cc (binding_cluster::binding_cluster): Remove overzealous
4313 assertion; we're checking for tracked_p in
4314 store::get_or_create_cluster.
4315
4316 2022-07-22 Tim Lange <mail@tim-lange.me>
4317
4318 PR analyzer/106394
4319 * region-model.cc (capacity_compatible_with_type): Always return true
4320 if alloc_size is zero.
4321
4322 2022-07-21 David Malcolm <dmalcolm@redhat.com>
4323
4324 PR analyzer/106383
4325 * varargs.cc (region_model::impl_call_va_arg): When determining if
4326 we're doing interprocedural analysis, use the stack depth of the
4327 frame in which va_start was called, rather than the current stack
4328 depth.
4329
4330 2022-07-21 David Malcolm <dmalcolm@redhat.com>
4331
4332 * sm-taint.cc (tainted_array_index::emit): Bulletproof against
4333 NULL m_arg.
4334 (tainted_array_index::describe_final_event): Likewise.
4335 (tainted_size::emit): Likewise.
4336 (tainted_size::describe_final_event): Likewise.
4337
4338 2022-07-21 David Malcolm <dmalcolm@redhat.com>
4339
4340 PR analyzer/106374
4341 * region.cc (decl_region::get_svalue_for_initializer): Bail out on
4342 untracked regions.
4343
4344 2022-07-20 David Malcolm <dmalcolm@redhat.com>
4345
4346 PR analyzer/106373
4347 * sm-taint.cc (taint_state_machine::on_condition): Potentially
4348 update the state of the RHS as well as the LHS.
4349
4350 2022-07-20 David Malcolm <dmalcolm@redhat.com>
4351
4352 PR analyzer/106359
4353 * region.h (string_region::tracked_p): New.
4354 * store.cc (binding_cluster::binding_cluster): Move here from
4355 store.h. Add assertion that base_region is tracked_p.
4356 * store.h (binding_cluster::binding_cluster): Move to store.cc.
4357
4358 2022-07-19 David Malcolm <dmalcolm@redhat.com>
4359
4360 PR analyzer/106321
4361 * constraint-manager.h (bounded_ranges::get_count): New.
4362 (bounded_ranges::get_range): New.
4363 * engine.cc (impl_region_model_context::on_bounded_ranges): New.
4364 * exploded-graph.h (impl_region_model_context::on_bounded_ranges):
4365 New decl.
4366 * region-model.cc (region_model::apply_constraints_for_gswitch):
4367 Potentially call ctxt->on_bounded_ranges.
4368 * region-model.h (region_model_context::on_bounded_ranges): New
4369 vfunc.
4370 (noop_region_model_context::on_bounded_ranges): New.
4371 (region_model_context_decorator::on_bounded_ranges): New.
4372 * sm-taint.cc: Include "analyzer/constraint-manager.h".
4373 (taint_state_machine::on_bounded_ranges): New.
4374 * sm.h (state_machine::on_bounded_ranges): New.
4375
4376 2022-07-19 David Malcolm <dmalcolm@redhat.com>
4377
4378 * engine.cc (exploded_graph::process_node): Show any description
4379 of the out-edge when logging it for consideration.
4380
4381 2022-07-15 David Malcolm <dmalcolm@redhat.com>
4382
4383 PR analyzer/106284
4384 * sm-taint.cc (taint_state_machine::on_condition): Handle range
4385 checks optimized by build_range_check.
4386
4387 2022-07-15 Jonathan Wakely <jwakely@redhat.com>
4388
4389 * call-info.cc (call_info::print): Adjust to new label_text API.
4390 * checker-path.cc (checker_event::dump): Likewise.
4391 (region_creation_event::get_desc): Likewise.
4392 (state_change_event::get_desc): Likewise.
4393 (superedge_event::should_filter_p): Likewise.
4394 (start_cfg_edge_event::get_desc): Likewise.
4395 (call_event::get_desc): Likewise.
4396 (return_event::get_desc): Likewise.
4397 (warning_event::get_desc): Likewise.
4398 (checker_path::dump): Likewise.
4399 (checker_path::debug): Likewise.
4400 * diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic):
4401 Likewise.
4402 (diagnostic_manager::prune_interproc_events): Likewise.
4403 * engine.cc (feasibility_state::maybe_update_for_edge):
4404 Likewise.
4405 * program-state.cc (sm_state_map::to_json): Likewise.
4406 * region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise.
4407 (region_model::impl_call_analyzer_dump_capacity): Likewise.
4408 * region.cc (region::to_json): Likewise.
4409 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
4410 * store.cc (binding_map::to_json): Likewise.
4411 (store::to_json): Likewise.
4412 * supergraph.cc (superedge::dump): Likewise.
4413 * svalue.cc (svalue::to_json): Likewise.
4414
4415 2022-07-07 David Malcolm <dmalcolm@redhat.com>
4416
4417 * checker-path.cc (start_cfg_edge_event::get_desc): Update for
4418 superedge::get_description returning a label_text.
4419 * engine.cc (feasibility_state::maybe_update_for_edge): Likewise.
4420 * supergraph.cc (superedge::dump): Likewise.
4421 (superedge::get_description): Convert return type from char * to
4422 label_text.
4423 * supergraph.h (superedge::get_description): Likewise.
4424
4425 2022-07-07 David Malcolm <dmalcolm@redhat.com>
4426
4427 * call-info.cc (call_info::print): Update for removal of
4428 label_text::maybe_free in favor of automatic memory management.
4429 * checker-path.cc (checker_event::dump): Likewise.
4430 (checker_event::prepare_for_emission): Likewise.
4431 (state_change_event::get_desc): Likewise.
4432 (superedge_event::should_filter_p): Likewise.
4433 (start_cfg_edge_event::get_desc): Likewise.
4434 (warning_event::get_desc): Likewise.
4435 (checker_path::dump): Likewise.
4436 (checker_path::debug): Likewise.
4437 * diagnostic-manager.cc
4438 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
4439 (diagnostic_manager::prune_interproc_events): Likewise.
4440 * program-state.cc (sm_state_map::to_json): Likewise.
4441 * region.cc (region::to_json): Likewise.
4442 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
4443 * store.cc (binding_map::to_json): Likewise.
4444 (store::to_json): Likewise.
4445 * svalue.cc (svalue::to_json): Likewise.
4446
4447 2022-07-07 David Malcolm <dmalcolm@redhat.com>
4448
4449 PR analyzer/106225
4450 * sm-taint.cc (taint_state_machine::on_stmt): Move handling of
4451 assignments from division to...
4452 (taint_state_machine::check_for_tainted_divisor): ...this new
4453 function. Reject warning when the divisor is known to be non-zero.
4454 * sm.cc: Include "analyzer/program-state.h".
4455 (sm_context::get_old_region_model): New.
4456 * sm.h (sm_context::get_old_region_model): New decl.
4457
4458 2022-07-06 Immad Mir <mirimmad@outlook.com>
4459
4460 PR analyzer/106184
4461 * sm-fd.cc (fd_state_machine): Change ordering of initialization
4462 of state m_invalid so that the order of initializers is same as
4463 the ordering of the fields in the class decl.
4464
4465 2022-07-06 Immad Mir <mirimmad@outlook.com>
4466
4467 * sm-fd.cc (use_after_close): save the "close" event and
4468 show it where possible.
4469
4470 2022-07-06 David Malcolm <dmalcolm@redhat.com>
4471
4472 PR analyzer/106204
4473 * region-model.cc (within_short_circuited_stmt_p): Move extraction
4474 of assign_stmt to caller.
4475 (due_to_ifn_deferred_init_p): New.
4476 (region_model::check_for_poison): Move extraction of assign_stmt
4477 from within_short_circuited_stmt_p to here. Share logic with
4478 call to due_to_ifn_deferred_init_p.
4479
4480 2022-07-02 Tim Lange <mail@tim-lange.me>
4481
4482 PR analyzer/105900
4483 * analyzer.opt: Added Wanalyzer-allocation-size.
4484 * checker-path.cc (region_creation_event::get_desc): Added call to new
4485 virtual function pending_diagnostic::describe_region_creation_event.
4486 * checker-path.h: Added region_creation_event::get_desc.
4487 * diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
4488 New function.
4489 * diagnostic-manager.h:
4490 Added diagnostic_manager::add_event_on_final_node.
4491 * pending-diagnostic.h (struct region_creation): New event_desc struct.
4492 (pending_diagnostic::describe_region_creation_event): Added virtual
4493 function to overwrite description of a region creation.
4494 * region-model.cc (class dubious_allocation_size): New class.
4495 (capacity_compatible_with_type): New helper function.
4496 (class size_visitor): New class.
4497 (struct_or_union_with_inheritance_p): New helper function.
4498 (is_any_cast_p): New helper function.
4499 (region_model::check_region_size): New function.
4500 (region_model::set_value): Added call to
4501 region_model::check_region_size.
4502 * region-model.h (class region_model): New function check_region_size.
4503 * svalue.cc (region_svalue::accept): Changed to post-order traversal.
4504 (initial_svalue::accept): Likewise.
4505 (unaryop_svalue::accept): Likewise.
4506 (binop_svalue::accept): Likewise.
4507 (sub_svalue::accept): Likewise.
4508 (repeated_svalue::accept): Likewise.
4509 (bits_within_svalue::accept): Likewise.
4510 (widening_svalue::accept): Likewise.
4511 (unmergeable_svalue::accept): Likewise.
4512 (compound_svalue::accept): Likewise.
4513 (conjured_svalue::accept): Likewise.
4514 (asm_output_svalue::accept): Likewise.
4515 (const_fn_result_svalue::accept): Likewise.
4516
4517 2022-07-02 Immad Mir <mirimmad17@gmail.com>
4518
4519 PR analyzer/106003
4520 * analyzer.opt (Wanalyzer-fd-leak): New option.
4521 (Wanalyzer-fd-access-mode-mismatch): New option.
4522 (Wanalyzer-fd-use-without-check): New option.
4523 (Wanalyzer-fd-double-close): New option.
4524 (Wanalyzer-fd-use-after-close): New option.
4525 * sm.h (make_fd_state_machine): New decl.
4526 * sm.cc (make_checkers): Call make_fd_state_machine.
4527 * sm-fd.cc: New file.
4528
4529 2022-06-24 David Malcolm <dmalcolm@redhat.com>
4530
4531 * call-string.cc: Add includes of "analyzer/analyzer.h"
4532 and "analyzer/analyzer-logging.h".
4533 (call_string::call_string): Delete copy ctor.
4534 (call_string::operator=): Delete.
4535 (call_string::operator==): Delete.
4536 (call_string::hash): Delete.
4537 (call_string::push_call): Make const, returning the resulting
4538 call_string.
4539 (call_string::pop): Delete.
4540 (call_string::cmp_ptr_ptr): New.
4541 (call_string::validate): Assert that m_parent is non-NULL, or
4542 m_elements is empty.
4543 (call_string::call_string): Move default ctor here from
4544 call-string.h and reimplement. Add ctor taking a parent
4545 and an element.
4546 (call_string::~call_string): New.
4547 (call_string::recursive_log): New.
4548 * call-string.h (call_string::call_string): Move default ctor's
4549 defn to call-string.cc. Delete copy ctor. Add ctor taking a
4550 parent and an element.
4551 (call_string::operator=): Delete.
4552 (call_string::operator==): Delete.
4553 (call_string::hash): Delete.
4554 (call_string::push_call): Make const, returning the resulting
4555 call_string.
4556 (call_string::pop): Delete decl.
4557 (call_string::get_parent): New.
4558 (call_string::cmp_ptr_ptr): New decl.
4559 (call_string::get_top_of_stack): New.
4560 (struct call_string::hashmap_traits_t): New.
4561 (class call_string): Add friend class region_model_manager. Add
4562 DISABLE_COPY_AND_ASSIGN.
4563 (call_string::~call_string): New decl.
4564 (call_string::recursive_log): New decl.
4565 (call_string::m_parent): New field.
4566 (call_string::m_children): New field.
4567 * constraint-manager.cc (selftest::test_many_constants): Pass
4568 model manager to program_point::origin.
4569 * engine.cc (exploded_graph::exploded_graph): Likewise.
4570 (exploded_graph::add_function_entry): Likewise for
4571 program_point::from_function_entry.
4572 (add_tainted_args_callback): Likewise.
4573 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
4574 Update for change to program_point.get_call_string.
4575 (exploded_graph::process_node): Likewise.
4576 (class function_call_string_cluster): Convert m_cs from a
4577 call_string to a const call_string &.
4578 (struct function_call_string): Likewise.
4579 (pod_hash_traits<function_call_string>::hash): Use pointer_hash
4580 for m_cs.
4581 (pod_hash_traits<function_call_string>::equal): Update for change
4582 to m_cs.
4583 (root_cluster::add_node): Update for change to
4584 function_call_string.
4585 (viz_callgraph_node::dump_dot): Update for change to call_string.
4586 * exploded-graph.h (per_call_string_data::m_key): Convert to a
4587 reference.
4588 (struct eg_call_string_hash_map_traits): Delete.
4589 (exploded_graph::call_string_data_map_t): Remove traits class.
4590 * program-point.cc: Move include of "analyzer/call-string.h" to
4591 after "analyzer/analyzer-logging.h".
4592 (program_point::print): Update for conversion of m_call_string to
4593 a pointer.
4594 (program_point::to_json): Likewise.
4595 (program_point::push_to_call_stack): Update for immutability of
4596 call strings.
4597 (program_point::pop_from_call_stack): Likewise.
4598 (program_point::hash): Use pointer hashing for m_call_string.
4599 (program_point::get_function_at_depth): Update for change to
4600 m_call_string.
4601 (program_point::validate): Update for changes to call_string.
4602 (program_point::on_edge): Likewise.
4603 (program_point::origin): Move here from call-string.h. Add
4604 region_model_manager param and use it to get empty call string.
4605 (program_point::from_function_entry): Likewise.
4606 (selftest::test_function_point_ordering): Likewise.
4607 (selftest::test_function_point_ordering): Likewise.
4608 * program-point.h (program_point::program_point): Update for
4609 change to m_call_string.
4610 (program_point::get_call_string): Likewise.
4611 (program_point::get_stack_depth): Likewise.
4612 (program_point::origin): Add region_model_manager param, and move
4613 defn to call-string.cc.
4614 (program_point::from_function_entry): Likewise.
4615 (program_point::empty): Drop call_string.
4616 (program_point::deleted): Likewise.
4617 (program_point::program_point): New private ctor.
4618 (program_point::m_call_string): Convert from call_string to const
4619 call_string *.
4620 * program-state.cc (selftest::test_program_state_merging): Update
4621 for call_string changes.
4622 (selftest::test_program_state_merging_2): Likewise.
4623 * region-model-manager.cc
4624 (region_model_manager::region_model_manager): Construct
4625 m_empty_call_string.
4626 (region_model_manager::log_stats): Log the call strings.
4627 * region-model.cc (assert_region_models_merge): Pass the
4628 region_model_manager when creating program_point instances.
4629 (selftest::test_state_merging): Likewise.
4630 (selftest::test_constraint_merging): Likewise.
4631 (selftest::test_widening_constraints): Likewise.
4632 (selftest::test_iteration_1): Likewise.
4633 * region-model.h (region_model_manager::get_empty_call_string):
4634 New.
4635 (region_model_manager::m_empty_call_string): New.
4636 * sm-signal.cc (register_signal_handler::impl_transition): Update
4637 for changes to call_string.
4638
4639 2022-06-24 David Malcolm <dmalcolm@redhat.com>
4640
4641 * call-string.cc (call_string::calc_recursion_depth): Whitespace
4642 cleanups.
4643 (call_string::cmp): Likewise.
4644 (call_string::get_caller_node): Likewise.
4645 (call_string::validate): Likewise.
4646 * engine.cc (dynamic_call_info_t::add_events_to_path): Likewise.
4647 (exploded_graph::get_per_function_data): Likewise.
4648 (exploded_graph::maybe_create_dynamic_call): Likewise.
4649 (exploded_graph::maybe_create_dynamic_call): Likewise.
4650 (exploded_graph::process_node): Likewise.
4651
4652 2022-06-16 David Malcolm <dmalcolm@redhat.com>
4653
4654 * varargs.cc (va_arg_type_mismatch::emit): Associate the warning
4655 with CWE-686 ("Function Call With Incorrect Argument Type").
4656
4657 2022-06-16 David Malcolm <dmalcolm@redhat.com>
4658
4659 * varargs.cc: Include "diagnostic-metadata.h".
4660 (va_list_exhausted::emit): Associate the warning with
4661 CWE-685 ("Function Call With Incorrect Number of Arguments").
4662
4663 2022-06-16 David Malcolm <dmalcolm@redhat.com>
4664
4665 * sm-file.cc (double_fclose::emit): Associate the warning with
4666 CWE-1341 ("Multiple Releases of Same Resource or Handle").
4667
4668 2022-06-15 David Malcolm <dmalcolm@redhat.com>
4669
4670 PR analyzer/105962
4671 * analyzer.opt (fanalyzer-undo-inlining): New option.
4672 * checker-path.cc: Include "diagnostic-core.h" and
4673 "inlining-iterator.h".
4674 (event_kind_to_string): Handle EK_INLINED_CALL.
4675 (class inlining_info): New class.
4676 (checker_event::checker_event): Move here from checker-path.h.
4677 Store original fndecl and depth, and calculate effective fndecl
4678 and depth based on inlining information.
4679 (checker_event::dump): Emit original depth as well as effective
4680 depth when they differ; likewise for fndecl.
4681 (region_creation_event::get_desc): Use m_effective_fndecl.
4682 (inlined_call_event::get_desc): New.
4683 (inlined_call_event::get_meaning): New.
4684 (checker_path::inject_any_inlined_call_events): New.
4685 * checker-path.h (enum event_kind): Add EK_INLINED_CALL.
4686 (checker_event::checker_event): Make protected, and move
4687 definition to checker-path.cc.
4688 (checker_event::get_fndecl): Use effective fndecl.
4689 (checker_event::get_stack_depth): Use effective stack depth.
4690 (checker_event::get_logical_location): Use effective stack depth.
4691 (checker_event::get_original_stack_depth): New.
4692 (checker_event::m_fndecl): Rename to...
4693 (checker_event::m_original_fndecl): ...this.
4694 (checker_event::m_depth): Rename to...
4695 (checker_event::m_original_depth): ...this.
4696 (checker_event::m_effective_fndecl): New field.
4697 (checker_event::m_effective_depth): New field.
4698 (class inlined_call_event): New checker_event subclass.
4699 (checker_path::inject_any_inlined_call_events): New decl.
4700 * diagnostic-manager.cc: Include "inlining-iterator.h".
4701 (diagnostic_manager::emit_saved_diagnostic): Call
4702 checker_path::inject_any_inlined_call_events.
4703 (diagnostic_manager::prune_for_sm_diagnostic): Handle
4704 EK_INLINED_CALL.
4705 * engine.cc (tainted_args_function_custom_event::get_desc): Use
4706 effective fndecl.
4707 * inlining-iterator.h: New file.
4708
4709 2022-06-15 David Malcolm <dmalcolm@redhat.com>
4710
4711 * diagnostic-manager.cc (saved_diagnostic::dump_dot_id): New.
4712 (saved_diagnostic::dump_as_dot_node): New.
4713 * diagnostic-manager.h (saved_diagnostic::dump_dot_id): New decl.
4714 (saved_diagnostic::dump_as_dot_node): New decl.
4715 * engine.cc (exploded_node::dump_dot): Add nodes for saved
4716 diagnostics.
4717
4718 2022-06-02 David Malcolm <dmalcolm@redhat.com>
4719
4720 * checker-path.cc (checker_event::get_meaning): New.
4721 (function_entry_event::get_meaning): New.
4722 (state_change_event::get_desc): Add dump of meaning of the event
4723 to the -fanalyzer-verbose-state-changes output.
4724 (state_change_event::get_meaning): New.
4725 (cfg_edge_event::get_meaning): New.
4726 (call_event::get_meaning): New.
4727 (return_event::get_meaning): New.
4728 (start_consolidated_cfg_edges_event::get_meaning): New.
4729 (warning_event::get_meaning): New.
4730 * checker-path.h: Include "tree-logical-location.h".
4731 (checker_event::checker_event): Construct m_logical_loc.
4732 (checker_event::get_logical_location): New.
4733 (checker_event::get_meaning): New decl.
4734 (checker_event::m_logical_loc): New.
4735 (function_entry_event::get_meaning): New decl.
4736 (state_change_event::get_meaning): New decl.
4737 (cfg_edge_event::get_meaning): New decl.
4738 (call_event::get_meaning): New decl.
4739 (return_event::get_meaning): New decl.
4740 (start_consolidated_cfg_edges_event::get_meaning): New.
4741 (warning_event::get_meaning): New decl.
4742 * pending-diagnostic.h: Include "diagnostic-path.h".
4743 (pending_diagnostic::get_meaning_for_state_change): New vfunc.
4744 * sm-file.cc (file_diagnostic::get_meaning_for_state_change): New
4745 vfunc impl.
4746 * sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
4747 Likewise.
4748 * sm-sensitive.cc
4749 (exposure_through_output_file::get_meaning_for_state_change):
4750 Likewise.
4751 * sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
4752 Likewise.
4753 * varargs.cc
4754 (va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.
4755
4756 2022-05-23 David Malcolm <dmalcolm@redhat.com>
4757
4758 * call-info.cc: Add "final" and "override" to all vfunc
4759 implementations that were missing them, as appropriate.
4760 * engine.cc: Likewise.
4761 * region-model.cc: Likewise.
4762 * sm-malloc.cc: Likewise.
4763 * supergraph.h: Likewise.
4764 * svalue.cc: Likewise.
4765 * varargs.cc: Likewise.
4766
4767 2022-05-20 David Malcolm <dmalcolm@redhat.com>
4768
4769 * analyzer-pass.cc: Replace uses of "FINAL" and "OVERRIDE" with
4770 "final" and "override".
4771 * call-info.h: Likewise.
4772 * checker-path.h: Likewise.
4773 * constraint-manager.cc: Likewise.
4774 * diagnostic-manager.cc: Likewise.
4775 * engine.cc: Likewise.
4776 * exploded-graph.h: Likewise.
4777 * feasible-graph.h: Likewise.
4778 * pending-diagnostic.h: Likewise.
4779 * region-model-impl-calls.cc: Likewise.
4780 * region-model.cc: Likewise.
4781 * region-model.h: Likewise.
4782 * region.h: Likewise.
4783 * sm-file.cc: Likewise.
4784 * sm-malloc.cc: Likewise.
4785 * sm-pattern-test.cc: Likewise.
4786 * sm-sensitive.cc: Likewise.
4787 * sm-signal.cc: Likewise.
4788 * sm-taint.cc: Likewise.
4789 * state-purge.h: Likewise.
4790 * store.cc: Likewise.
4791 * store.h: Likewise.
4792 * supergraph.h: Likewise.
4793 * svalue.h: Likewise.
4794 * trimmed-graph.h: Likewise.
4795 * varargs.cc: Likewise.
4796
4797 2022-05-16 David Malcolm <dmalcolm@redhat.com>
4798
4799 PR analyzer/105103
4800 * analyzer.cc (make_label_text_n): New.
4801 * analyzer.h (class var_arg_region): New forward decl.
4802 (make_label_text_n): New decl.
4803 * analyzer.opt (Wanalyzer-va-arg-type-mismatch): New option.
4804 (Wanalyzer-va-list-exhausted): New option.
4805 (Wanalyzer-va-list-leak): New option.
4806 (Wanalyzer-va-list-use-after-va-end): New option.
4807 * checker-path.cc (call_event::get_desc): Split out decl access
4808 into..
4809 (call_event::get_caller_fndecl): ...this new function and...
4810 (call_event::get_callee_fndecl): ...this new function.
4811 * checker-path.h (call_event::get_desc): Drop "FINAL".
4812 (call_event::get_caller_fndecl): New decl.
4813 (call_event::get_callee_fndecl): New decl.
4814 (class call_event): Make fields protected.
4815 * diagnostic-manager.cc (null_assignment_sm_context::warn): New
4816 overload.
4817 (null_assignment_sm_context::get_new_program_state): New.
4818 (diagnostic_manager::add_events_for_superedge): Move case
4819 SUPEREDGE_CALL to a new pending_diagnostic::add_call_event vfunc.
4820 * engine.cc (impl_sm_context::warn): Implement new override.
4821 (impl_sm_context::get_new_program_state): New.
4822 * pending-diagnostic.cc: Include "analyzer/diagnostic-manager.h",
4823 "cpplib.h", "digraph.h", "ordered-hash-map.h", "cfg.h",
4824 "basic-block.h", "gimple.h", "gimple-iterator.h", "cgraph.h"
4825 "analyzer/supergraph.h", "analyzer/program-state.h",
4826 "alloc-pool.h", "fibonacci_heap.h", "shortest-paths.h",
4827 "sbitmap.h", "analyzer/exploded-graph.h", "diagnostic-path.h",
4828 and "analyzer/checker-path.h".
4829 (ht_ident_eq): New.
4830 (fixup_location_in_macro_p): New.
4831 (pending_diagnostic::fixup_location): New.
4832 (pending_diagnostic::add_call_event): New.
4833 * pending-diagnostic.h (pending_diagnostic::fixup_location): Drop
4834 no-op inline implementation in favor of the more complex
4835 implementation above.
4836 (pending_diagnostic::add_call_event): New vfunc.
4837 * region-model-impl-calls.cc: Include "analyzer/sm.h",
4838 "diagnostic-path.h", and "analyzer/pending-diagnostic.h".
4839 * region-model-manager.cc
4840 (region_model_manager::get_var_arg_region): New.
4841 (region_model_manager::log_stats): Log m_var_arg_regions.
4842 * region-model.cc (region_model::on_call_pre): Handle IFN_VA_ARG,
4843 BUILT_IN_VA_START, and BUILT_IN_VA_COPY.
4844 (region_model::on_call_post): Handle BUILT_IN_VA_END.
4845 (region_model::get_representative_path_var_1): Handle RK_VAR_ARG.
4846 (region_model::push_frame): Push variadic arguments.
4847 * region-model.h (region_model_manager::get_var_arg_region): New
4848 decl.
4849 (region_model_manager::m_var_arg_regions): New field.
4850 (region_model::impl_call_va_start): New decl.
4851 (region_model::impl_call_va_copy): New decl.
4852 (region_model::impl_call_va_arg): New decl.
4853 (region_model::impl_call_va_end): New decl.
4854 * region.cc (alloca_region::dump_to_pp): Dump the id.
4855 (var_arg_region::dump_to_pp): New.
4856 (var_arg_region::get_frame_region): New.
4857 * region.h (enum region_kind): Add RK_VAR_ARG.
4858 (region::dyn_cast_var_arg_region): New.
4859 (class var_arg_region): New.
4860 (is_a_helper <const var_arg_region *>::test): New.
4861 (struct default_hash_traits<var_arg_region::key_t>): New.
4862 * sm.cc (make_checkers): Call make_va_list_state_machine.
4863 * sm.h (sm_context::warn): New vfunc.
4864 (sm_context::get_old_svalue): Drop unused decl.
4865 (sm_context::get_new_program_state): New vfunc.
4866 (make_va_list_state_machine): New decl.
4867 * varargs.cc: New file.
4868
4869 2022-05-16 Martin Liska <mliska@suse.cz>
4870
4871 * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
4872 * function-set.cc (test_stdio_example): Likewise.
4873 * sm-file.cc (get_file_using_fns): Likewise.
4874 * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
4875 * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
4876
4877 2022-05-13 Richard Biener <rguenther@suse.de>
4878
4879 * supergraph.cc: Re-order gimple-fold.h include.
4880
4881 2022-05-11 David Malcolm <dmalcolm@redhat.com>
4882
4883 * checker-path.cc (state_change_event::get_desc): Call maybe_free
4884 on label_text temporaries.
4885 * diagnostic-manager.cc
4886 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
4887 * engine.cc (exploded_graph::~exploded_graph): Fix leak of
4888 m_per_point_data and m_per_call_string_data values. Simplify
4889 cleanup of m_per_function_stats and m_per_point_data values.
4890 (feasibility_state::maybe_update_for_edge): Fix leak of result of
4891 superedge::get_description.
4892 * region-model-manager.cc
4893 (region_model_manager::~region_model_manager): Move cleanup of
4894 m_setjmp_values to match the ordering of the fields within
4895 region_model_manager. Fix leak of values within
4896 m_repeated_values_map, m_bits_within_values_map,
4897 m_asm_output_values_map, and m_const_fn_result_values_map.
4898
4899 2022-04-28 David Malcolm <dmalcolm@redhat.com>
4900
4901 PR analyzer/105285
4902 * store.cc (binding_cluster::get_any_binding): Handle accessing
4903 sub_svalues of clusters where the base region has a symbolic
4904 binding.
4905
4906 2022-04-28 David Malcolm <dmalcolm@redhat.com>
4907
4908 * diagnostic-manager.cc (epath_finder::process_worklist_item):
4909 Call dump_feasible_path when a path that reaches the the target
4910 enode is found.
4911 (epath_finder::dump_feasible_path): New.
4912 * engine.cc (feasibility_state::dump_to_pp): New.
4913 * exploded-graph.h (feasibility_state::dump_to_pp): New decl.
4914 * feasible-graph.cc (feasible_graph::dump_feasible_path): New.
4915 * feasible-graph.h (feasible_graph::dump_feasible_path): New
4916 decls.
4917 * program-point.cc (function_point::print): Fix missing trailing
4918 newlines.
4919 * program-point.h (program_point::print_source_line): Remove
4920 unimplemented decl.
4921
4922 2022-04-25 David Malcolm <dmalcolm@redhat.com>
4923
4924 PR analyzer/105365
4925 PR analyzer/105366
4926 * svalue.cc
4927 (cmp_cst): Rename to...
4928 (cmp_csts_same_type): ...this. Convert all recursive calls to
4929 calls to...
4930 (cmp_csts_and_types): ....this new function.
4931 (svalue::cmp_ptr): Update for renaming of cmp_cst
4932
4933 2022-04-14 David Malcolm <dmalcolm@redhat.com>
4934
4935 PR analyzer/105264
4936 * region-model-reachability.cc (reachable_regions::handle_parm):
4937 Use maybe_get_deref_base_region rather than just region_svalue, to
4938 handle pointer arithmetic also.
4939 * svalue.cc (svalue::maybe_get_deref_base_region): New.
4940 * svalue.h (svalue::maybe_get_deref_base_region): New decl.
4941
4942 2022-04-14 David Malcolm <dmalcolm@redhat.com>
4943
4944 PR analyzer/105252
4945 * svalue.cc (cmp_cst): When comparing VECTOR_CSTs, compare the
4946 types of the encoded elements before calling cmp_cst on them.
4947
4948 2022-04-09 David Malcolm <dmalcolm@redhat.com>
4949
4950 PR analyzer/103892
4951 * region-model-manager.cc
4952 (region_model_manager::get_unknown_symbolic_region): New,
4953 extracted from...
4954 (region_model_manager::get_field_region): ...here.
4955 (region_model_manager::get_element_region): Use it here.
4956 (region_model_manager::get_offset_region): Likewise.
4957 (region_model_manager::get_sized_region): Likewise.
4958 (region_model_manager::get_cast_region): Likewise.
4959 (region_model_manager::get_bit_range): Likewise.
4960 * region-model.h
4961 (region_model_manager::get_unknown_symbolic_region): New decl.
4962 * region.cc (symbolic_region::symbolic_region): Handle sval_ptr
4963 having NULL type.
4964 (symbolic_region::dump_to_pp): Handle having NULL type.
4965
4966 2022-04-07 David Malcolm <dmalcolm@redhat.com>
4967
4968 PR analyzer/102208
4969 * store.cc (binding_map::remove_overlapping_bindings): Add
4970 "always_overlap" param, using it to generalize to the case where
4971 we want to remove all bindings. Update "uncertainty" logic to
4972 only record maybe-bound values for cases where there is a symbolic
4973 write involved.
4974 (binding_cluster::mark_region_as_unknown): Split param "reg" into
4975 "reg_to_bind" and "reg_for_overlap".
4976 (binding_cluster::maybe_get_compound_binding): Pass "false" to
4977 binding_map::remove_overlapping_bindings new "always_overlap" param.
4978 (binding_cluster::remove_overlapping_bindings): Determine
4979 "always_overlap" and pass it to
4980 binding_map::remove_overlapping_bindings.
4981 (store::set_value): Pass uncertainty to remove_overlapping_bindings
4982 call. Update for new param of
4983 binding_cluster::mark_region_as_unknown, passing both the base
4984 region of the iter_cluster, and the lhs_reg.
4985 (store::mark_region_as_unknown): Update for new param of
4986 binding_cluster::mark_region_as_unknown, passing "reg" for both.
4987 (store::remove_overlapping_bindings): Add param "uncertainty", and
4988 pass it on to call to
4989 binding_cluster::remove_overlapping_bindings.
4990 * store.h (binding_map::remove_overlapping_bindings): Add
4991 "always_overlap" param.
4992 (binding_cluster::mark_region_as_unknown): Split param "reg" into
4993 "reg_to_bind" and "reg_for_overlap".
4994 (store::remove_overlapping_bindings): Add param "uncertainty".
4995
4996 2022-03-29 David Malcolm <dmalcolm@redhat.com>
4997
4998 PR testsuite/105085
4999 * region-model-manager.cc (dump_untracked_region): Skip decls in
5000 the constant pool.
5001
5002 2022-03-29 David Malcolm <dmalcolm@redhat.com>
5003
5004 PR analyzer/105087
5005 * analyzer.h (class conjured_purge): New forward decl.
5006 * region-model-asm.cc (region_model::on_asm_stmt): Add
5007 conjured_purge param to calls binding_cluster::on_asm and
5008 region_model_manager::get_or_create_conjured_svalue.
5009 * region-model-impl-calls.cc
5010 (call_details::get_or_create_conjured_svalue): Likewise for call
5011 to region_model_manager::get_or_create_conjured_svalue.
5012 (region_model::impl_call_fgets): Remove call to
5013 region_model::purge_state_involving, as this is now done
5014 implicitly by call_details::get_or_create_conjured_svalue.
5015 (region_model::impl_call_fread): Likewise.
5016 (region_model::impl_call_strchr): Pass conjured_purge param to
5017 call to region_model_manager::get_or_create_conjured_svalue.
5018 * region-model-manager.cc (conjured_purge::purge): New.
5019 (region_model_manager::get_or_create_conjured_svalue): Add
5020 param "p". Use it to purge state when reusing an existing
5021 conjured_svalue.
5022 * region-model.cc (region_model::on_call_pre): Replace call to
5023 region_model::purge_state_involving with passing conjured_purge
5024 to region_model_manager::get_or_create_conjured_svalue.
5025 (region_model::handle_unrecognized_call): Pass conjured_purge to
5026 store::on_unknown_fncall.
5027 * region-model.h
5028 (region_model_manager::get_or_create_conjured_svalue): Add param
5029 "p".
5030 * store.cc (binding_cluster::on_unknown_fncall): Likewise. Pass
5031 it on to region_model_manager::get_or_create_conjured_svalue.
5032 (binding_cluster::on_asm): Likewise.
5033 (store::on_unknown_fncall): Add param "p" and pass it on to
5034 binding_cluster::on_unknown_fncall.
5035 * store.h (binding_cluster::on_unknown_fncall): Add param p.
5036 (binding_cluster::on_asm): Likewise.
5037 (store::on_unknown_fncall): Likewise.
5038 * svalue.h (class conjured_purge): New.
5039
5040 2022-03-29 David Malcolm <dmalcolm@redhat.com>
5041
5042 PR analyzer/105074
5043 * region.cc (ipa_ref_requires_tracking): Drop "context_fndecl",
5044 instead using the ref->referring to get the cgraph node of the
5045 caller.
5046 (symnode_requires_tracking_p): Likewise.
5047
5048 2022-03-26 David Malcolm <dmalcolm@redhat.com>
5049
5050 PR analyzer/105057
5051 * store.cc (binding_cluster::make_unknown_relative_to): Reject
5052 attempts to create a cluster for untracked base regions.
5053 (store::set_value): Likewise.
5054 (store::fill_region): Likewise.
5055 (store::mark_region_as_unknown): Likewise.
5056
5057 2022-03-25 David Malcolm <dmalcolm@redhat.com>
5058
5059 PR analyzer/104954
5060 * analyzer.opt (-fdump-analyzer-untracked): New option.
5061 * engine.cc (impl_run_checkers): Handle it.
5062 * region-model-asm.cc (region_model::on_asm_stmt): Don't attempt
5063 to clobber regions with !tracked_p ().
5064 * region-model-manager.cc (dump_untracked_region): New.
5065 (region_model_manager::dump_untracked_regions): New.
5066 (frame_region::dump_untracked_regions): New.
5067 * region-model.h (region_model_manager::dump_untracked_regions):
5068 New decl.
5069 * region.cc (ipa_ref_requires_tracking): New.
5070 (symnode_requires_tracking_p): New.
5071 (decl_region::calc_tracked_p): New.
5072 * region.h (region::tracked_p): New vfunc.
5073 (frame_region::dump_untracked_regions): New decl.
5074 (class decl_region): Note that this is also used fo SSA names.
5075 (decl_region::decl_region): Initialize m_tracked.
5076 (decl_region::tracked_p): New.
5077 (decl_region::calc_tracked_p): New decl.
5078 (decl_region::m_tracked): New.
5079 * store.cc (store::get_or_create_cluster): Assert that we
5080 don't try to create clusters for base regions that aren't
5081 trackable.
5082 (store::mark_as_escaped): Don't mark base regions that we're not
5083 tracking.
5084
5085 2022-03-23 David Malcolm <dmalcolm@redhat.com>
5086
5087 PR analyzer/104979
5088 * engine.cc (impl_run_checkers): Create the engine after the
5089 supergraph, and pass the supergraph to the engine.
5090 * region-model.cc (region_model::get_lvalue_1): Pass ctxt to
5091 frame_region::get_region_for_local.
5092 (region_model::update_for_return_gcall): Pass the lvalue for the
5093 result to pop_frame as a tree, rather than as a region.
5094 (region_model::pop_frame): Update for above change, determining
5095 the destination region after the frame is popped and thus with
5096 respect to the caller frame rather than the called frame.
5097 Likewise, set the value of the region to the return value after
5098 the frame is popped.
5099 (engine::engine): Add supergraph pointer.
5100 (selftest::test_stack_frames): Set the DECL_CONTECT of PARM_DECLs.
5101 (selftest::test_get_representative_path_var): Likewise.
5102 (selftest::test_state_merging): Likewise.
5103 * region-model.h (region_model::pop_frame): Convert first param
5104 from a const region * to a tree.
5105 (engine::engine): Add param "sg".
5106 (engine::m_sg): New field.
5107 * region.cc: Include "analyzer/sm.h" and
5108 "analyzer/program-state.h".
5109 (frame_region::get_region_for_local): Add "ctxt" param.
5110 Add assertions that VAR_DECLs are locals, and that expr is for the
5111 correct function.
5112 * region.h (frame_region::get_region_for_local): Add "ctxt" param.
5113
5114 2022-03-23 David Malcolm <dmalcolm@redhat.com>
5115
5116 PR analyzer/105017
5117 * sm-taint.cc (taint_diagnostic::subclass_equal_p): Check
5118 m_has_bounds as well as m_arg.
5119 (tainted_allocation_size::subclass_equal_p): Chain up to base
5120 class implementation. Also check m_mem_space.
5121 (tainted_allocation_size::emit): Add note showing stack-based vs
5122 heap-based allocations.
5123
5124 2022-03-23 David Malcolm <dmalcolm@redhat.com>
5125
5126 PR analyzer/104997
5127 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic):
5128 Convert return type from "void" to "bool", reporting success vs
5129 failure to caller, for both overloads.
5130 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
5131 Likewise.
5132 * engine.cc (impl_region_model_context::warn): Propagate return
5133 value from diagnostic_manager::add_diagnostic.
5134
5135 2022-03-18 David Malcolm <dmalcolm@redhat.com>
5136
5137 PR analyzer/104943
5138 PR analyzer/104954
5139 PR analyzer/103533
5140 * analyzer.h (class state_purge_per_decl): New forward decl.
5141 * engine.cc (impl_run_checkers): Pass region_model_manager to
5142 state_purge_map ctor.
5143 * program-point.cc (function_point::final_stmt_p): New.
5144 (function_point::get_next): New.
5145 * program-point.h (function_point::final_stmt_p): New decl.
5146 (function_point::get_next): New decl.
5147 * program-state.cc (program_state::prune_for_point): Generalize to
5148 purge local decls as well as SSA names.
5149 (program_state::can_purge_base_region_p): New.
5150 * program-state.h (program_state::can_purge_base_region_p): New
5151 decl.
5152 * region-model.cc (struct append_ssa_names_cb_data): Rename to...
5153 (struct append_regions_cb_data): ...this.
5154 (region_model::get_ssa_name_regions_for_current_frame): Rename
5155 to...
5156 (region_model::get_regions_for_current_frame): ...this, updating
5157 for other renamings.
5158 (region_model::append_ssa_names_cb): Rename to...
5159 (region_model::append_regions_cb): ...this, and drop the requirement
5160 that the subregion be a SSA name.
5161 * region-model.h (struct append_ssa_names_cb_data): Rename decl
5162 to...
5163 (struct append_regions_cb_data): ...this.
5164 (region_model::get_ssa_name_regions_for_current_frame): Rename
5165 decl to...
5166 (region_model::get_regions_for_current_frame): ...this.
5167 (region_model::append_ssa_names_cb): Rename decl to...
5168 (region_model::append_regions_cb): ...this.
5169 * state-purge.cc: Include "tristate.h", "selftest.h",
5170 "analyzer/store.h", "analyzer/region-model.h", and
5171 "gimple-walk.h".
5172 (get_candidate_for_purging): New.
5173 (class gimple_op_visitor): New.
5174 (my_load_cb): New.
5175 (my_store_cb): New.
5176 (my_addr_cb): New.
5177 (state_purge_map::state_purge_map): Add "mgr" param. Update for
5178 renamings. Find uses of local variables.
5179 (state_purge_map::~state_purge_map): Update for renaming of m_map
5180 to m_ssa_map. Clean up m_decl_map.
5181 (state_purge_map::get_or_create_data_for_decl): New.
5182 (state_purge_per_ssa_name::state_purge_per_ssa_name): Update for
5183 inheriting from state_purge_per_tree.
5184 (state_purge_per_ssa_name::add_to_worklist): Likewise.
5185 (state_purge_per_decl::state_purge_per_decl): New.
5186 (state_purge_per_decl::add_needed_at): New.
5187 (state_purge_per_decl::add_pointed_to_at): New.
5188 (state_purge_per_decl::process_worklists): New.
5189 (state_purge_per_decl::add_to_worklist): New.
5190 (same_binding_p): New.
5191 (fully_overwrites_p): New.
5192 (state_purge_per_decl::process_point_backwards): New.
5193 (state_purge_per_decl::process_point_forwards): New.
5194 (state_purge_per_decl::needed_at_point_p): New.
5195 (state_purge_annotator::print_needed): Generalize to print local
5196 decls as well as SSA names.
5197 * state-purge.h (class state_purge_map): Update leading comment.
5198 (state_purge_map::map_t): Rename to...
5199 (state_purge_map::ssa_map_t): ...this.
5200 (state_purge_map::iterator): Rename to...
5201 (state_purge_map::ssa_iterator): ...this.
5202 (state_purge_map::decl_map_t): New typedef.
5203 (state_purge_map::decl_iterator): New typedef.
5204 (state_purge_map::state_purge_map): Add "mgr" param.
5205 (state_purge_map::get_data_for_ssa_name): Update for renaming.
5206 (state_purge_map::get_any_data_for_decl): New.
5207 (state_purge_map::get_or_create_data_for_decl): New decl.
5208 (state_purge_map::begin): Rename to...
5209 (state_purge_map::begin_ssas): ...this.
5210 (state_purge_map::end): Rename to...
5211 (state_purge_map::end_ssa): ...this.
5212 (state_purge_map::begin_decls): New.
5213 (state_purge_map::end_decls): New.
5214 (state_purge_map::m_map): Rename to...
5215 (state_purge_map::m_ssa_map): ...this.
5216 (state_purge_map::m_decl_map): New field.
5217 (class state_purge_per_tree): New class.
5218 (class state_purge_per_ssa_name): Inherit from state_purge_per_tree.
5219 (state_purge_per_ssa_name::get_function): Move to base class.
5220 (state_purge_per_ssa_name::point_set_t): Likewise.
5221 (state_purge_per_ssa_name::m_fun): Likewise.
5222 (class state_purge_per_decl): New.
5223
5224 2022-03-17 David Malcolm <dmalcolm@redhat.com>
5225
5226 * state-purge.cc (state_purge_annotator::add_node_annotations):
5227 Avoid duplicate before-supernode annotations when returning from
5228 an interprocedural call. Show after-supernode annotations.
5229
5230 2022-03-17 David Malcolm <dmalcolm@redhat.com>
5231
5232 * program-point.cc (program_point::get_next): Fix missing
5233 increment of index.
5234
5235 2022-03-16 David Malcolm <dmalcolm@redhat.com>
5236
5237 PR analyzer/104955
5238 * diagnostic-manager.cc (get_emission_location): New.
5239 (diagnostic_manager::diagnostic_manager): Initialize
5240 m_num_disabled_diagnostics.
5241 (diagnostic_manager::add_diagnostic): Reject diagnostics that
5242 will eventually be rejected due to being disabled.
5243 (diagnostic_manager::emit_saved_diagnostics): Log the number
5244 of disabled diagnostics.
5245 (diagnostic_manager::emit_saved_diagnostic): Split out logic for
5246 determining emission location to get_emission_location.
5247 * diagnostic-manager.h
5248 (diagnostic_manager::m_num_disabled_diagnostics): New field.
5249 * engine.cc (stale_jmp_buf::get_controlling_option): New.
5250 (stale_jmp_buf::emit): Use it.
5251 * pending-diagnostic.h
5252 (pending_diagnostic::get_controlling_option): New vfunc.
5253 * region-model.cc
5254 (poisoned_value_diagnostic::get_controlling_option): New.
5255 (poisoned_value_diagnostic::emit): Use it.
5256 (shift_count_negative_diagnostic::get_controlling_option): New.
5257 (shift_count_negative_diagnostic::emit): Use it.
5258 (shift_count_overflow_diagnostic::get_controlling_option): New.
5259 (shift_count_overflow_diagnostic::emit): Use it.
5260 (dump_path_diagnostic::get_controlling_option): New.
5261 (dump_path_diagnostic::emit): Use it.
5262 (write_to_const_diagnostic::get_controlling_option): New.
5263 (write_to_const_diagnostic::emit): Use it.
5264 (write_to_string_literal_diagnostic::get_controlling_option): New.
5265 (write_to_string_literal_diagnostic::emit): Use it.
5266 * sm-file.cc (double_fclose::get_controlling_option): New.
5267 (double_fclose::emit): Use it.
5268 (file_leak::get_controlling_option): New.
5269 (file_leak::emit): Use it.
5270 * sm-malloc.cc (mismatching_deallocation::get_controlling_option):
5271 New.
5272 (mismatching_deallocation::emit): Use it.
5273 (double_free::get_controlling_option): New.
5274 (double_free::emit): Use it.
5275 (possible_null_deref::get_controlling_option): New.
5276 (possible_null_deref::emit): Use it.
5277 (possible_null_arg::get_controlling_option): New.
5278 (possible_null_arg::emit): Use it.
5279 (null_deref::get_controlling_option): New.
5280 (null_deref::emit): Use it.
5281 (null_arg::get_controlling_option): New.
5282 (null_arg::emit): Use it.
5283 (use_after_free::get_controlling_option): New.
5284 (use_after_free::emit): Use it.
5285 (malloc_leak::get_controlling_option): New.
5286 (malloc_leak::emit): Use it.
5287 (free_of_non_heap::get_controlling_option): New.
5288 (free_of_non_heap::emit): Use it.
5289 * sm-pattern-test.cc (pattern_match::get_controlling_option): New.
5290 (pattern_match::emit): Use it.
5291 * sm-sensitive.cc
5292 (exposure_through_output_file::get_controlling_option): New.
5293 (exposure_through_output_file::emit): Use it.
5294 * sm-signal.cc (signal_unsafe_call::get_controlling_option): New.
5295 (signal_unsafe_call::emit): Use it.
5296 * sm-taint.cc (tainted_array_index::get_controlling_option): New.
5297 (tainted_array_index::emit): Use it.
5298 (tainted_offset::get_controlling_option): New.
5299 (tainted_offset::emit): Use it.
5300 (tainted_size::get_controlling_option): New.
5301 (tainted_size::emit): Use it.
5302 (tainted_divisor::get_controlling_option): New.
5303 (tainted_divisor::emit): Use it.
5304 (tainted_allocation_size::get_controlling_option): New.
5305 (tainted_allocation_size::emit): Use it.
5306
5307 2022-03-15 David Malcolm <dmalcolm@redhat.com>
5308
5309 * store.cc (store::store): Presize m_cluster_map.
5310
5311 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5312
5313 PR analyzer/104863
5314 * constraint-manager.cc (constraint_manager::add_constraint):
5315 Refresh the EC IDs when adding constraints implied by offsets.
5316
5317 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5318
5319 PR analyzer/104793
5320 * analyzer.h (class pending_note): New forward decl.
5321 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
5322 Initialize m_notes.
5323 (saved_diagnostic::operator==): Compare m_notes.
5324 (saved_diagnostic::add_note): New.
5325 (saved_diagnostic::emit_any_notes): New.
5326 (diagnostic_manager::add_note): New.
5327 (diagnostic_manager::emit_saved_diagnostic): Call emit_any_notes
5328 after emitting the warning.
5329 * diagnostic-manager.h (saved_diagnostic::add_note): New decl.
5330 (saved_diagnostic::emit_any_notes): New decl.
5331 (saved_diagnostic::m_notes): New field.
5332 (diagnostic_manager::add_note): New decl.
5333 * engine.cc (impl_region_model_context::add_note): New.
5334 * exploded-graph.h (impl_region_model_context::add_note): New
5335 decl.
5336 * pending-diagnostic.h (class pending_note): New.
5337 (class pending_note_subclass): New template.
5338 * region-model.cc (class reason_attr_access): New.
5339 (check_external_function_for_access_attr): Add class
5340 annotating_ctxt and use it when checking region.
5341 (noop_region_model_context::add_note): New.
5342 * region-model.h (region_model_context::add_note): New vfunc.
5343 (noop_region_model_context::add_note): New decl.
5344 (class region_model_context_decorator): New.
5345 (class note_adding_context): New.
5346
5347 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5348
5349 PR analyzer/104793
5350 * region-model.cc
5351 (region_model::check_external_function_for_access_attr): New.
5352 (region_model::handle_unrecognized_call): Call it.
5353 * region-model.h
5354 (region_model::check_external_function_for_access_attr): New decl.
5355 (region_model::handle_unrecognized_call): New decl.
5356
5357 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5358
5359 * sm-taint.cc (taint_state_machine::check_for_tainted_size_arg):
5360 Avoid generating duplicate saved_diagnostics by only handling the
5361 rdwr_map entry for the ptrarg, not the duplicate entry for the
5362 sizarg.
5363
5364 2022-03-07 David Malcolm <dmalcolm@redhat.com>
5365
5366 PR analyzer/101983
5367 * engine.cc (returning_from_function_p): New.
5368 (impl_region_model_context::on_state_leak): Use it when rejecting
5369 leaks at the return from "main".
5370
5371 2022-03-07 Jakub Jelinek <jakub@redhat.com>
5372
5373 * store.cc: Fix up duplicated word issue in a comment.
5374 * analyzer.cc: Likewise.
5375 * engine.cc: Likewise.
5376 * sm-taint.cc: Likewise.
5377
5378 2022-03-04 David Malcolm <dmalcolm@redhat.com>
5379
5380 PR analyzer/103521
5381 * analyzer.opt (-param=analyzer-max-svalue-depth=): Reduce from 13
5382 to 12.
5383
5384 2022-02-23 David Malcolm <dmalcolm@redhat.com>
5385
5386 PR analyzer/104434
5387 * analyzer.h (class const_fn_result_svalue): New decl.
5388 * region-model-impl-calls.cc (call_details::get_manager): New.
5389 * region-model-manager.cc
5390 (region_model_manager::get_or_create_const_fn_result_svalue): New.
5391 (region_model_manager::log_stats): Log
5392 m_const_fn_result_values_map.
5393 * region-model.cc (const_fn_p): New.
5394 (maybe_get_const_fn_result): New.
5395 (region_model::on_call_pre): Handle fndecls with
5396 __attribute__((const)) by calling the above rather than making
5397 a conjured_svalue.
5398 * region-model.h (visitor::visit_const_fn_result_svalue): New.
5399 (region_model_manager::get_or_create_const_fn_result_svalue): New
5400 decl.
5401 (region_model_manager::const_fn_result_values_map_t): New typedef.
5402 (region_model_manager::m_const_fn_result_values_map): New field.
5403 (call_details::get_manager): New decl.
5404 * svalue.cc (svalue::cmp_ptr): Handle SK_CONST_FN_RESULT.
5405 (const_fn_result_svalue::dump_to_pp): New.
5406 (const_fn_result_svalue::dump_input): New.
5407 (const_fn_result_svalue::accept): New.
5408 * svalue.h (enum svalue_kind): Add SK_CONST_FN_RESULT.
5409 (svalue::dyn_cast_const_fn_result_svalue): New.
5410 (class const_fn_result_svalue): New.
5411 (is_a_helper <const const_fn_result_svalue *>::test): New.
5412 (template <> struct default_hash_traits<const_fn_result_svalue::key_t>):
5413 New.
5414
5415 2022-02-17 David Malcolm <dmalcolm@redhat.com>
5416
5417 PR analyzer/104576
5418 * region-model.cc: Include "calls.h".
5419 (region_model::on_call_pre): Use flags_from_decl_or_type to
5420 generalize check for DECL_PURE_P to also check for ECF_CONST.
5421
5422 2022-02-16 David Malcolm <dmalcolm@redhat.com>
5423
5424 PR analyzer/104560
5425 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
5426 Add region creation events for globals of interest.
5427 (null_assignment_sm_context::get_old_program_state): New.
5428 (diagnostic_manager::add_events_for_eedge): Move check for
5429 changing dynamic extents from PK_BEFORE_STMT case to after the
5430 switch on the dst_point's kind so that we can emit them for the
5431 final stmt in a basic block.
5432 * engine.cc (impl_sm_context::get_old_program_state): New.
5433 * sm-malloc.cc (malloc_state_machine::get_default_state): Rewrite
5434 detection of m_non_heap to use get_memory_space.
5435 (free_of_non_heap::free_of_non_heap): Add freed_reg param.
5436 (free_of_non_heap::subclass_equal_p): Update for changes to
5437 fields.
5438 (free_of_non_heap::emit): Drop m_kind in favor of
5439 get_memory_space.
5440 (free_of_non_heap::describe_state_change): Remove logic for
5441 detecting alloca.
5442 (free_of_non_heap::mark_interesting_stuff): Add region-creation of
5443 m_freed_reg.
5444 (free_of_non_heap::get_memory_space): New.
5445 (free_of_non_heap::kind): Drop enum.
5446 (free_of_non_heap::m_freed_reg): New field.
5447 (free_of_non_heap::m_kind): Drop field.
5448 (malloc_state_machine::on_stmt): Drop transition to m_non_heap.
5449 (malloc_state_machine::handle_free_of_non_heap): New function,
5450 split out from on_deallocator_call and on_realloc_call, adding
5451 detection of the freed region.
5452 (malloc_state_machine::on_deallocator_call): Use it.
5453 (malloc_state_machine::on_realloc_call): Likewise.
5454 * sm.h (sm_context::get_old_program_state): New vfunc.
5455
5456 2022-02-15 David Malcolm <dmalcolm@redhat.com>
5457
5458 PR analyzer/104524
5459 * region-model-manager.cc
5460 (region_model_manager::maybe_fold_sub_svalue): Only call
5461 get_or_create_cast if type is non-NULL.
5462
5463 2022-02-15 David Malcolm <dmalcolm@redhat.com>
5464
5465 PR analyzer/102692
5466 * exploded-graph.h (impl_region_model_context::get_stmt): New.
5467 * region-model.cc: Include "gimple-ssa.h", "tree-phinodes.h",
5468 "tree-ssa-operands.h", and "ssa-iterators.h".
5469 (within_short_circuited_stmt_p): New.
5470 (region_model::check_for_poison): Don't warn about uninit values
5471 if within_short_circuited_stmt_p.
5472 * region-model.h (region_model_context::get_stmt): New vfunc.
5473 (noop_region_model_context::get_stmt): New.
5474
5475 2022-02-11 David Malcolm <dmalcolm@redhat.com>
5476
5477 PR analyzer/104274
5478 * region-model.cc (region_model::check_for_poison): Ignore
5479 uninitialized uses of empty types.
5480
5481 2022-02-10 David Malcolm <dmalcolm@redhat.com>
5482
5483 PR analyzer/98797
5484 * region-model-manager.cc
5485 (region_model_manager::maybe_fold_sub_svalue): Generalize getting
5486 individual chars of a STRING_CST from element_region to any
5487 subregion which is a concrete access of a single byte from its
5488 parent region.
5489 * region.cc (region::get_relative_concrete_byte_range): New.
5490 * region.h (region::get_relative_concrete_byte_range): New decl.
5491
5492 2022-02-09 David Malcolm <dmalcolm@redhat.com>
5493
5494 PR analyzer/104452
5495 * region-model.cc (selftest::test_bit_range_regions): New.
5496 (selftest::analyzer_region_model_cc_tests): Call it.
5497 * region.h (bit_range_region::key_t::hash): Fix hashing of m_bits
5498 to avoid using uninitialized data.
5499
5500 2022-02-07 David Malcolm <dmalcolm@redhat.com>
5501
5502 PR analyzer/104417
5503 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
5504 Remove overzealous assertion.
5505 (tainted_allocation_size::emit): Likewise.
5506 (region_model::check_dynamic_size_for_taint): Likewise.
5507
5508 2022-02-07 David Malcolm <dmalcolm@redhat.com>
5509
5510 PR analyzer/103872
5511 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
5512 Reimplement in terms of a get_store_value followed by a set_value.
5513
5514 2022-02-03 David Malcolm <dmalcolm@redhat.com>
5515
5516 PR analyzer/104369
5517 * engine.cc (exploded_graph::process_node): Use the node for any
5518 diagnostics, avoiding ICE if a bifurcation update adds a
5519 saved_diagnostic, such as for a tainted realloc size.
5520 * region-model-impl-calls.cc
5521 (region_model::impl_call_realloc::success_no_move::update_model):
5522 Require the old pointer to be non-NULL to be able successfully
5523 grow in place. Use model->deref_rvalue rather than maybe_get_region
5524 to support the old pointer being symbolic.
5525 (region_model::impl_call_realloc::success_with_move::update_model):
5526 Likewise. Add a constraint that the new pointer != the old pointer.
5527 Use a sized_region when setting the value of the new region.
5528 Handle the case where we don't know the dynamic size of the old
5529 region by marking the new region as unknown.
5530 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
5531 Update assertion to also allow for MEMSPACE_UNKNOWN.
5532 (tainted_allocation_size::emit): Likewise.
5533 (region_model::check_dynamic_size_for_taint): Likewise.
5534
5535 2022-02-03 David Malcolm <dmalcolm@redhat.com>
5536
5537 * region-model-impl-calls.cc (region_model::impl_call_calloc): Use
5538 a sized_region when calling zero_fill_region.
5539
5540 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5541
5542 * region-model.cc (region_model::on_return): Replace usage of
5543 copy_region with get_rvalue/set_value pair.
5544 (region_model::pop_frame): Likewise.
5545 (selftest::test_compound_assignment): Likewise.
5546 * region-model.h (region_model::copy_region): Delete decl.
5547 * region.cc (region_model::copy_region): Delete.
5548
5549 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5550
5551 * region.cc (region::calc_offset): Consolidate effectively
5552 identical cases.
5553
5554 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5555
5556 * analyzer.h (class bit_range_region): New forward decl.
5557 * region-model-manager.cc (region_model_manager::get_bit_range):
5558 New.
5559 (region_model_manager::log_stats): Handle m_bit_range_regions.
5560 * region-model.cc (region_model::get_lvalue_1): Handle
5561 BIT_FIELD_REF.
5562 * region-model.h (region_model_manager::get_bit_range): New decl.
5563 (region_model_manager::m_bit_range_regions): New field.
5564 * region.cc (region::get_base_region): Handle RK_BIT_RANGE.
5565 (region::base_region_p): Likewise.
5566 (region::calc_offset): Likewise.
5567 (bit_range_region::dump_to_pp): New.
5568 (bit_range_region::get_byte_size): New.
5569 (bit_range_region::get_bit_size): New.
5570 (bit_range_region::get_byte_size_sval): New.
5571 (bit_range_region::get_relative_concrete_offset): New.
5572 * region.h (enum region_kind): Add RK_BIT_RANGE.
5573 (region::dyn_cast_bit_range_region): New vfunc.
5574 (class bit_range_region): New.
5575 (is_a_helper <const bit_range_region *>::test): New.
5576 (default_hash_traits<bit_range_region::key_t>): New.
5577
5578 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5579
5580 PR analyzer/104270
5581 * region-model.cc (region_model::on_call_pre): Handle
5582 IFN_DEFERRED_INIT.
5583
5584 2022-01-27 David Malcolm <dmalcolm@redhat.com>
5585
5586 * checker-path.cc (event_kind_to_string): Handle
5587 EK_REGION_CREATION.
5588 (region_creation_event::region_creation_event): New.
5589 (region_creation_event::get_desc): New.
5590 (checker_path::add_region_creation_event): New.
5591 * checker-path.h (enum event_kind): Add EK_REGION_CREATION.
5592 (class region_creation_event): New subclass.
5593 (checker_path::add_region_creation_event): New decl.
5594 * diagnostic-manager.cc
5595 (diagnostic_manager::emit_saved_diagnostic): Pass NULL for new
5596 param to add_events_for_eedge when handling trailing eedge.
5597 (diagnostic_manager::build_emission_path): Create an interesting_t
5598 instance, allow the pending diagnostic to populate it, and pass it
5599 to the calls to add_events_for_eedge.
5600 (diagnostic_manager::add_events_for_eedge): Add "interest" param.
5601 Use it to add region_creation_events for on-stack regions created
5602 within at function entry, and when pertinent dynamically-sized
5603 regions are created.
5604 (diagnostic_manager::prune_for_sm_diagnostic): Add case for
5605 EK_REGION_CREATION.
5606 * diagnostic-manager.h (diagnostic_manager::add_events_for_eedge):
5607 Add "interest" param.
5608 * pending-diagnostic.cc: Include "selftest.h", "tristate.h",
5609 "analyzer/call-string.h", "analyzer/program-point.h",
5610 "analyzer/store.h", and "analyzer/region-model.h".
5611 (interesting_t::add_region_creation): New.
5612 (interesting_t::dump_to_pp): New.
5613 * pending-diagnostic.h (struct interesting_t): New.
5614 (pending_diagnostic::mark_interesting_stuff): New vfunc.
5615 * region-model.cc
5616 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
5617 (poisoned_value_diagnostic::operator==): Compare m_pkind and
5618 m_src_region fields.
5619 (poisoned_value_diagnostic::mark_interesting_stuff): New.
5620 (poisoned_value_diagnostic::m_src_region): New.
5621 (region_model::check_for_poison): Call
5622 get_region_for_poisoned_expr for uninit values and pass the resul
5623 to the diagnostic.
5624 (region_model::get_region_for_poisoned_expr): New.
5625 (region_model::deref_rvalue): Pass NULL for
5626 poisoned_value_diagnostic's src_region.
5627 * region-model.h (region_model::get_region_for_poisoned_expr): New
5628 decl.
5629 * region.h (frame_region::get_fndecl): New.
5630
5631 2022-01-27 Martin Liska <mliska@suse.cz>
5632
5633 PR analyzer/104247
5634 * constraint-manager.cc (bounded_ranges_manager::log_stats):
5635 Cast to long for format purpose.
5636 * region-model-manager.cc (log_uniq_map): Likewise.
5637
5638 2022-01-26 David Malcolm <dmalcolm@redhat.com>
5639
5640 PR analyzer/104224
5641 * region-model.cc (region_model::check_call_args): New.
5642 (region_model::on_call_pre): Call it when ignoring stdio builtins.
5643 * region-model.h (region_model::check_call_args): New decl
5644
5645 2022-01-26 David Malcolm <dmalcolm@redhat.com>
5646
5647 PR analyzer/94362
5648 * constraint-manager.cc (range::add_bound): Fix tests for
5649 discarding redundant constraints. Perform test for rejecting
5650 unsatisfiable constraints earlier so that they don't update
5651 the object on failure.
5652 (selftest::test_range): New.
5653 (selftest::test_constant_comparisons): Add test coverage for
5654 existing constraints becoming narrower until they are
5655 unsatisfiable.
5656 (selftest::run_constraint_manager_tests): Call test_range.
5657
5658 2022-01-22 David Malcolm <dmalcolm@redhat.com>
5659
5660 PR analyzer/104159
5661 * region-model-manager.cc
5662 (region_model_manager::get_or_create_cast): Bail out if the types
5663 are the same. Don't attempt to handle casts involving vector
5664 types.
5665
5666 2022-01-20 David Malcolm <dmalcolm@redhat.com>
5667
5668 PR analyzer/94362
5669 * constraint-manager.cc (bound::ensure_closed): Convert param to
5670 enum bound_kind.
5671 (range::constrained_to_single_element): Likewise.
5672 (range::add_bound): New.
5673 (constraint_manager::add_constraint): Handle SVAL + OFFSET
5674 compared to a constant.
5675 (constraint_manager::get_ec_bounds): Rewrite in terms of
5676 range::add_bound.
5677 (constraint_manager::eval_condition): Reject if range::add_bound
5678 fails.
5679 (selftest::test_constant_comparisons): Add test coverage for
5680 various impossible combinations of integer comparisons.
5681 * constraint-manager.h (enum bound_kind): New.
5682 (struct bound): Likewise.
5683 (bound::ensure_closed): Convert to param to enum bound_kind.
5684 (struct range): Convert to...
5685 (class range): ...this, making fields private.
5686 (range::add_bound): New decls.
5687 * region-model.cc (region_model::add_constraint): Fail if
5688 constraint_manager::add_constraint fails.
5689
5690 2022-01-18 David Malcolm <dmalcolm@redhat.com>
5691
5692 PR analyzer/104089
5693 * region-model-manager.cc
5694 (region_model_manager::get_or_create_constant_svalue): Assert that
5695 we have a CONSTANT_CLASS_P.
5696 (region_model_manager::maybe_fold_unaryop): Only fold a constant
5697 when fold_unary's result is a constant or a cast of a constant.
5698
5699 2022-01-18 David Malcolm <dmalcolm@redhat.com>
5700
5701 PR analyzer/104062
5702 * region-model-manager.cc
5703 (region_model_manager::maybe_fold_sub_svalue): Avoid casting to
5704 NULL type when folding access to repeated svalue.
5705
5706 2022-01-17 Martin Liska <mliska@suse.cz>
5707
5708 * analyzer.cc (is_special_named_call_p): Rename .c names to .cc.
5709 (is_named_call_p): Likewise.
5710 * region-model-asm.cc (deterministic_p): Likewise.
5711 * region.cc (field_region::get_relative_concrete_offset): Likewise.
5712 * sm-malloc.cc (method_p): Likewise.
5713 * supergraph.cc (superedge::dump_dot): Likewise.
5714
5715 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5716
5717 * sm-taint.cc (taint_state_machine::combine_states): Handle combination
5718 of has_ub and has_lb.
5719
5720 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5721
5722 PR analyzer/104029
5723 * sm-taint.cc (taint_state_machine::alt_get_inherited_state):
5724 Remove gcc_unreachable from default case for unary ops.
5725
5726 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5727
5728 * engine.cc: Include "stringpool.h", "attribs.h", and
5729 "tree-dfa.h".
5730 (mark_params_as_tainted): New.
5731 (class tainted_args_function_custom_event): New.
5732 (class tainted_args_function_info): New.
5733 (exploded_graph::add_function_entry): Handle functions with
5734 "tainted_args" attribute.
5735 (class tainted_args_field_custom_event): New.
5736 (class tainted_args_callback_custom_event): New.
5737 (class tainted_args_call_info): New.
5738 (add_tainted_args_callback): New.
5739 (add_any_callbacks): New.
5740 (exploded_graph::build_initial_worklist): Likewise.
5741 (exploded_graph::build_initial_worklist): Find callbacks that are
5742 reachable from global initializers, calling add_any_callbacks on
5743 them.
5744
5745 2022-01-12 David Malcolm <dmalcolm@redhat.com>
5746
5747 PR analyzer/103940
5748 * engine.cc (impl_sm_context::impl_sm_context): Add
5749 "unknown_side_effects" param and use it to initialize
5750 new m_unknown_side_effects field.
5751 (impl_sm_context::unknown_side_effects_p): New.
5752 (impl_sm_context::m_unknown_side_effects): New.
5753 (exploded_node::on_stmt): Pass unknown_side_effects to sm_ctxt
5754 ctor.
5755 * sm-taint.cc: Include "stringpool.h" and "attribs.h".
5756 (tainted_size::tainted_size): Drop "dir" param.
5757 (tainted_size::get_kind): Drop "FINAL".
5758 (tainted_size::emit): Likewise.
5759 (tainted_size::m_dir): Drop unused field.
5760 (class tainted_access_attrib_size): New subclass.
5761 (taint_state_machine::on_stmt): Call check_for_tainted_size_arg on
5762 external functions with unknown side effects.
5763 (taint_state_machine::check_for_tainted_size_arg): New.
5764 (region_model::check_region_for_taint): Drop "dir" param from
5765 tainted_size ctor.
5766 * sm.h (sm_context::unknown_side_effects_p): New.
5767
5768 2022-01-11 David Malcolm <dmalcolm@redhat.com>
5769
5770 PR analyzer/102692
5771 * diagnostic-manager.cc
5772 (class auto_disable_complexity_checks): Rename to...
5773 (class auto_checking_feasibility): ...this, updating
5774 the calls accordingly.
5775 (epath_finder::explore_feasible_paths): Update for renaming.
5776 * region-model-manager.cc
5777 (region_model_manager::region_model_manager): Update for change from
5778 m_check_complexity to m_checking_feasibility.
5779 (region_model_manager::reject_if_too_complex): Likewise.
5780 (region_model_manager::get_or_create_unknown_svalue): Handle
5781 m_checking_feasibility.
5782 (region_model_manager::create_unique_svalue): New.
5783 (region_model_manager::maybe_fold_binop): Handle BIT_AND_EXPR and
5784 BIT_IOR_EXPRs on booleans where we know the result.
5785 * region-model.cc (test_binop_svalue_folding): Add test coverage
5786 for the above.
5787 * region-model.h (region_model_manager::create_unique_svalue): New
5788 decl.
5789 (region_model_manager::enable_complexity_check): Replace with...
5790 (region_model_manager::begin_checking_feasibility): ...this.
5791 (region_model_manager::disable_complexity_check): Replace with...
5792 (region_model_manager::end_checking_feasibility): ...this.
5793 (region_model_manager::m_check_complexity): Replace with...
5794 (region_model_manager::m_checking_feasibility): ...this.
5795 (region_model_manager::m_managed_dynamic_svalues): New field.
5796
5797 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5798
5799 * engine.cc (impl_run_checkers): Pass logger to engine ctor.
5800 * region-model-manager.cc
5801 (region_model_manager::region_model_manager): Add logger param and
5802 use it to initialize m_logger.
5803 * region-model.cc (engine::engine): New.
5804 * region-model.h (region_model_manager::region_model_manager):
5805 Add logger param.
5806 (region_model_manager::get_logger): New.
5807 (region_model_manager::m_logger): New field.
5808 (engine::engine): New.
5809 * store.cc (store_manager::get_logger): New.
5810 (store::set_value): Log scope. Log when marking a cluster as
5811 unknown due to possible aliasing.
5812 * store.h (store_manager::get_logger): New decl.
5813
5814 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5815
5816 * region-model-impl-calls.cc (cmp_decls): New.
5817 (cmp_decls_ptr_ptr): New.
5818 (region_model::impl_call_analyzer_dump_escaped): New.
5819 * region-model.cc (region_model::on_stmt_pre): Handle
5820 __analyzer_dump_escaped.
5821 * region-model.h (region_model::impl_call_analyzer_dump_escaped):
5822 New decl.
5823 * store.h (binding_cluster::get_base_region): New accessor.
5824
5825 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5826
5827 * region.cc (region::is_named_decl_p): New.
5828 * region.h (region::is_named_decl_p): New decl.
5829
5830 2022-01-06 David Malcolm <dmalcolm@redhat.com>
5831
5832 PR analyzer/103546
5833 * store.cc (store::eval_alias_1): Refactor handling of decl
5834 regions, adding a test for may_be_aliased, rejecting those for
5835 which it returns false.
5836
5837 2021-12-12 Jonathan Wakely <jwakely@redhat.com>
5838
5839 * engine.cc: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
5840
5841 2021-12-06 David Malcolm <dmalcolm@redhat.com>
5842
5843 PR analyzer/103533
5844 * constraint-manager.cc (equiv_class::contains_non_constant_p):
5845 New.
5846 (constraint_manager::canonicalize): Call it when determining
5847 redundant ECs.
5848 (selftest::test_purging): New selftest.
5849 (selftest::run_constraint_manager_tests): Likewise.
5850 * constraint-manager.h (equiv_class::contains_non_constant_p):
5851 New decl.
5852
5853 2021-12-01 David Malcolm <dmalcolm@redhat.com>
5854
5855 PR analyzer/102471
5856 * region-model-reachability.cc (reachable_regions::handle_parm):
5857 Treat all svalues within a compound parm has reachable, and those
5858 wrapped in a cast.
5859
5860 2021-11-29 David Malcolm <dmalcolm@redhat.com>
5861
5862 PR analyzer/103217
5863 * store.cc (binding_cluster::can_merge_p): For the "key is bound"
5864 vs "key is not bound" merger case, check that the bound svalue
5865 is mergeable before merging it to "unknown", rejecting the merger
5866 otherwise.
5867
5868 2021-11-19 David Malcolm <dmalcolm@redhat.com>
5869
5870 PR analyzer/103217
5871 * engine.cc (exploded_graph::get_or_create_node): Pass in
5872 m_ext_state to program_state::can_merge_with_p.
5873 (exploded_graph::process_worklist): Likewise.
5874 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
5875 Likewise.
5876 (exploded_graph::process_node): Add missing call to detect_leaks
5877 when handling phi nodes.
5878 * program-state.cc (program_state::can_merge_with_p): Add
5879 "ext_state" param. Pass it and state ptrs to
5880 region_model::can_merge_with_p.
5881 (selftest::test_program_state_merging): Update for new ext_state
5882 param of program_state::can_merge_with_p.
5883 (selftest::test_program_state_merging_2): Likewise.
5884 * program-state.h (program_state::can_purge_p): Make const.
5885 (program_state::can_merge_with_p): Add "ext_state" param.
5886 * region-model.cc: Include "analyzer/program-state.h".
5887 (region_model::can_merge_with_p): Add params "ext_state",
5888 "state_a", and "state_b", use them when creating model_merger
5889 object.
5890 (model_merger::mergeable_svalue_p): New.
5891 * region-model.h (region_model::can_merge_with_p): Add params
5892 "ext_state", "state_a", and "state_b".
5893 (model_merger::model_merger) Likewise, initializing new fields.
5894 (model_merger::mergeable_svalue_p): New decl.
5895 (model_merger::m_ext_state): New field.
5896 (model_merger::m_state_a): New field.
5897 (model_merger::m_state_b): New field.
5898 * svalue.cc (svalue::can_merge_p): Call
5899 model_merger::mergeable_svalue_p on both states and reject the
5900 merger accordingly.
5901
5902 2021-11-17 David Malcolm <dmalcolm@redhat.com>
5903
5904 PR analyzer/102695
5905 * region-model-impl-calls.cc (region_model::impl_call_strchr): New.
5906 * region-model-manager.cc
5907 (region_model_manager::maybe_fold_unaryop): Simplify cast to
5908 pointer type of an existing pointer to a region.
5909 * region-model.cc (region_model::on_call_pre): Handle
5910 BUILT_IN_STRCHR and "strchr".
5911 (write_to_const_diagnostic::emit): Add auto_diagnostic_group. Add
5912 alternate wordings for functions and labels.
5913 (write_to_const_diagnostic::describe_final_event): Add alternate
5914 wordings for functions and labels.
5915 (region_model::check_for_writable_region): Handle RK_FUNCTION and
5916 RK_LABEL.
5917 * region-model.h (region_model::impl_call_strchr): New decl.
5918
5919 2021-11-16 David Malcolm <dmalcolm@redhat.com>
5920
5921 PR analyzer/102662
5922 * constraint-manager.cc (bounded_range::operator==): Require the
5923 types to be the same for equality.
5924
5925 2021-11-13 David Malcolm <dmalcolm@redhat.com>
5926
5927 * analyzer.opt (Wanalyzer-tainted-allocation-size): New.
5928 (Wanalyzer-tainted-divisor): New.
5929 (Wanalyzer-tainted-offset): New.
5930 (Wanalyzer-tainted-size): New.
5931 * engine.cc (impl_region_model_context::get_taint_map): New.
5932 * exploded-graph.h (impl_region_model_context::get_taint_map):
5933 New decl.
5934 * program-state.cc (sm_state_map::get_state): Call
5935 alt_get_inherited_state.
5936 (sm_state_map::impl_set_state): Modify states within
5937 compound svalues.
5938 (program_state::impl_call_analyzer_dump_state): Undo casts.
5939 (selftest::test_program_state_1): Update for new context param of
5940 create_region_for_heap_alloc.
5941 (selftest::test_program_state_merging): Likewise.
5942 * region-model-impl-calls.cc (region_model::impl_call_alloca):
5943 Likewise.
5944 (region_model::impl_call_calloc): Likewise.
5945 (region_model::impl_call_malloc): Likewise.
5946 (region_model::impl_call_operator_new): Likewise.
5947 (region_model::impl_call_realloc): Likewise.
5948 * region-model.cc (region_model::check_region_access): Call
5949 check_region_for_taint.
5950 (region_model::get_representative_path_var_1): Handle binops.
5951 (region_model::create_region_for_heap_alloc): Add "ctxt" param and
5952 pass it to set_dynamic_extents.
5953 (region_model::create_region_for_alloca): Likewise.
5954 (region_model::set_dynamic_extents): Add "ctxt" param and use it
5955 to call check_dynamic_size_for_taint.
5956 (selftest::test_state_merging): Update for new context param of
5957 create_region_for_heap_alloc.
5958 (selftest::test_malloc_constraints): Likewise.
5959 (selftest::test_malloc): Likewise.
5960 (selftest::test_alloca): Likewise for create_region_for_alloca.
5961 * region-model.h (region_model::create_region_for_heap_alloc): Add
5962 "ctxt" param.
5963 (region_model::create_region_for_alloca): Likewise.
5964 (region_model::set_dynamic_extents): Likewise.
5965 (region_model::check_dynamic_size_for_taint): New decl.
5966 (region_model::check_region_for_taint): New decl.
5967 (region_model_context::get_taint_map): New vfunc.
5968 (noop_region_model_context::get_taint_map): New.
5969 * sm-taint.cc: Remove include of "diagnostic-event-id.h"; add
5970 includes of "gimple-iterator.h", "tristate.h", "selftest.h",
5971 "ordered-hash-map.h", "cgraph.h", "cfg.h", "digraph.h",
5972 "analyzer/supergraph.h", "analyzer/call-string.h",
5973 "analyzer/program-point.h", "analyzer/store.h",
5974 "analyzer/region-model.h", and "analyzer/program-state.h".
5975 (enum bounds): Move to top of file.
5976 (class taint_diagnostic): New.
5977 (class tainted_array_index): Convert to subclass of taint_diagnostic.
5978 (tainted_array_index::emit): Add CWE-129. Reword warning to use
5979 "attacker-controlled" rather than "tainted".
5980 (tainted_array_index::describe_state_change): Move to
5981 taint_diagnostic::describe_state_change.
5982 (tainted_array_index::describe_final_event): Reword to use
5983 "attacker-controlled" rather than "tainted".
5984 (class tainted_offset): New.
5985 (class tainted_size): New.
5986 (class tainted_divisor): New.
5987 (class tainted_allocation_size): New.
5988 (taint_state_machine::alt_get_inherited_state): New.
5989 (taint_state_machine::on_stmt): In assignment handling, remove
5990 ARRAY_REF handling in favor of check_region_for_taint. Add
5991 detection of tainted divisors.
5992 (taint_state_machine::get_taint): New.
5993 (taint_state_machine::combine_states): New.
5994 (region_model::check_region_for_taint): New.
5995 (region_model::check_dynamic_size_for_taint): New.
5996 * sm.h (state_machine::alt_get_inherited_state): New.
5997
5998 2021-11-12 David Malcolm <dmalcolm@redhat.com>
5999
6000 * engine.cc (exploded_node::on_stmt_pre): Return when handling
6001 "__analyzer_dump_state".
6002
6003 2021-11-11 Richard Biener <rguenther@suse.de>
6004
6005 * supergraph.cc: Include bitmap.h.
6006
6007 2021-11-04 David Malcolm <dmalcolm@redhat.com>
6008
6009 * program-state.cc (sm_state_map::dump): Use default_tree_printer
6010 as format decoder.
6011
6012 2021-09-16 Maxim Blinov <maxim.blinov@embecosm.com>
6013
6014 PR bootstrap/102242
6015 * engine.cc (INCLUDE_UNIQUE_PTR): Define.
6016
6017 2021-09-08 David Malcolm <dmalcolm@redhat.com>
6018
6019 PR analyzer/102225
6020 * analyzer.h (compat_types_p): New decl.
6021 * constraint-manager.cc
6022 (constraint_manager::get_or_add_equiv_class): Guard against NULL
6023 type when checking for pointer types.
6024 * region-model-impl-calls.cc (region_model::impl_call_realloc):
6025 Guard against NULL lhs type/region. Guard against the size value
6026 not being of a compatible type for dynamic extents.
6027 * region-model.cc (compat_types_p): Make non-static.
6028
6029 2021-08-30 David Malcolm <dmalcolm@redhat.com>
6030
6031 PR analyzer/99260
6032 * analyzer.h (class custom_edge_info): New class, adapted from
6033 exploded_edge::custom_info_t. Make member functions const.
6034 Make update_model return bool, converting edge param from
6035 reference to a pointer, and adding a ctxt param.
6036 (class path_context): New class.
6037 * call-info.cc: New file.
6038 * call-info.h: New file.
6039 * engine.cc: Include "analyzer/call-info.h" and <memory>.
6040 (impl_region_model_context::impl_region_model_context): Update for
6041 new m_path_ctxt field.
6042 (impl_region_model_context::bifurcate): New.
6043 (impl_region_model_context::terminate_path): New.
6044 (impl_region_model_context::get_malloc_map): New.
6045 (impl_sm_context::impl_sm_context): Update for new m_path_ctxt
6046 field.
6047 (impl_sm_context::get_fndecl_for_call): Likewise.
6048 (impl_sm_context::set_next_state): Likewise.
6049 (impl_sm_context::warn): Likewise.
6050 (impl_sm_context::is_zero_assignment): Likewise.
6051 (impl_sm_context::get_path_context): New.
6052 (impl_sm_context::m_path_ctxt): New.
6053 (impl_region_model_context::on_condition): Update for new
6054 path_ctxt param. Handle m_enode_for_diag being NULL.
6055 (impl_region_model_context::on_phi): Update for new path_ctxt
6056 param.
6057 (exploded_node::on_stmt): Add path_ctxt param, updating ctor calls
6058 to use it as necessary. Use it to bail out after sm-handling,
6059 if needed.
6060 (exploded_node::detect_leaks): Update for new path_ctxt param.
6061 (dynamic_call_info_t::update_model): Update for conversion of
6062 exploded_edge::custom_info_t to custom_edge_info.
6063 (dynamic_call_info_t::add_events_to_path): Likewise.
6064 (rewind_info_t::update_model): Likewise.
6065 (rewind_info_t::add_events_to_path): Likewise.
6066 (exploded_edge::exploded_edge): Likewise.
6067 (exploded_graph::add_edge): Likewise.
6068 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
6069 Update for new path_ctxt param.
6070 (class impl_path_context): New.
6071 (exploded_graph::process_node): Update for new path_ctxt param.
6072 Create an impl_path_context and pass it to exploded_node::on_stmt.
6073 Use it to terminate iterating stmts if terminate_path is called
6074 on it. After processing a run of stmts, query path_ctxt to
6075 potentially terminate the analysis path, and/or to "bifurcate" the
6076 analysis into multiple additional paths.
6077 (feasibility_state::maybe_update_for_edge): Update for new
6078 update_model ctxt param.
6079 * exploded-graph.h
6080 (impl_region_model_context::impl_region_model_context): Add
6081 path_ctxt param.
6082 (impl_region_model_context::bifurcate): New.
6083 (impl_region_model_context::terminate_path): New
6084 (impl_region_model_context::get_ext_state): New.
6085 (impl_region_model_context::get_malloc_map): New.
6086 (impl_region_model_context::m_path_ctxt): New field.
6087 (exploded_node::on_stmt): Add path_ctxt param.
6088 (class exploded_edge::custom_info_t): Move to analyzer.h, renaming
6089 to custom_edge_info, and making the changes as noted in analyzer.h
6090 above.
6091 (exploded_edge::exploded_edge): Update for these changes to
6092 exploded_edge::custom_info_t.
6093 (exploded_edge::m_custom_info): Likewise.
6094 (class dynamic_call_info_t): Likewise.
6095 (class rewind_info_t): Likewise.
6096 (exploded_graph::add_edge): Likewise.
6097 * program-state.cc (program_state::on_edge): Update for new
6098 path_ctxt param.
6099 (program_state::push_call): Likewise.
6100 (program_state::returning_call): Likewise.
6101 (program_state::prune_for_point): Likewise.
6102 * region-model-impl-calls.cc: Include "analyzer/call-info.h".
6103 (call_details::get_fndecl_for_call): New.
6104 (region_model::impl_call_realloc): Reimplement.
6105 * region-model.cc (region_model::on_call_pre): Move call to
6106 impl_call_realloc to...
6107 (region_model::on_call_post): ...here. Consolidate creation
6108 of call_details instance.
6109 (noop_region_model_context::bifurcate): New.
6110 (noop_region_model_context::terminate_path): New.
6111 * region-model.h (call_details::get_call_stmt): New.
6112 (call_details::get_fndecl_for_call): New.
6113 (region_model::on_realloc_with_move): New.
6114 (region_model_context::bifurcate): New.
6115 (region_model_context::terminate_path): New.
6116 (region_model_context::get_ext_state): New.
6117 (region_model_context::get_malloc_map): New.
6118 (noop_region_model_context::bifurcate): New.
6119 (noop_region_model_context::terminate_path): New.
6120 (noop_region_model_context::get_ext_state): New.
6121 (noop_region_model_context::get_malloc_map): New.
6122 * sm-malloc.cc: Include "analyzer/program-state.h".
6123 (malloc_state_machine::on_realloc_call): Reimplement.
6124 (malloc_state_machine::on_realloc_with_move): New.
6125 (region_model::on_realloc_with_move): New.
6126 * sm-signal.cc (class signal_delivery_edge_info_t): Update for
6127 conversion from exploded_edge::custom_info_t to custom_edge_info.
6128 * sm.h (sm_context::get_path_context): New.
6129 * svalue.cc (svalue::maybe_get_constant): Call
6130 unwrap_any_unmergeable.
6131
6132 2021-08-25 Ankur Saini <arsenic@sourceware.org>
6133
6134 PR analyzer/101980
6135 * engine.cc (exploded_graph::maybe_create_dynamic_call): Don't create
6136 calls if max recursion limit is reached.
6137
6138 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6139
6140 * analyzer.h (struct rejected_constraint): Convert to...
6141 (class rejected_constraint): ...this.
6142 (class bounded_ranges): New forward decl.
6143 (class bounded_ranges_manager): New forward decl.
6144 * constraint-manager.cc: Include "analyzer/analyzer-logging.h" and
6145 "tree-pretty-print.h".
6146 (can_plus_one_p): New.
6147 (plus_one): New.
6148 (can_minus_one_p): New.
6149 (minus_one): New.
6150 (bounded_range::bounded_range): New.
6151 (dump_cst): New.
6152 (bounded_range::dump_to_pp): New.
6153 (bounded_range::dump): New.
6154 (bounded_range::to_json): New.
6155 (bounded_range::set_json_attr): New.
6156 (bounded_range::contains_p): New.
6157 (bounded_range::intersects_p): New.
6158 (bounded_range::operator==): New.
6159 (bounded_range::cmp): New.
6160 (bounded_ranges::bounded_ranges): New.
6161 (bounded_ranges::bounded_ranges): New.
6162 (bounded_ranges::bounded_ranges): New.
6163 (bounded_ranges::canonicalize): New.
6164 (bounded_ranges::validate): New.
6165 (bounded_ranges::operator==): New.
6166 (bounded_ranges::dump_to_pp): New.
6167 (bounded_ranges::dump): New.
6168 (bounded_ranges::to_json): New.
6169 (bounded_ranges::eval_condition): New.
6170 (bounded_ranges::contain_p): New.
6171 (bounded_ranges::cmp): New.
6172 (bounded_ranges_manager::~bounded_ranges_manager): New.
6173 (bounded_ranges_manager::get_or_create_empty): New.
6174 (bounded_ranges_manager::get_or_create_point): New.
6175 (bounded_ranges_manager::get_or_create_range): New.
6176 (bounded_ranges_manager::get_or_create_union): New.
6177 (bounded_ranges_manager::get_or_create_intersection): New.
6178 (bounded_ranges_manager::get_or_create_inverse): New.
6179 (bounded_ranges_manager::consolidate): New.
6180 (bounded_ranges_manager::get_or_create_ranges_for_switch): New.
6181 (bounded_ranges_manager::create_ranges_for_switch): New.
6182 (bounded_ranges_manager::make_case_label_ranges): New.
6183 (bounded_ranges_manager::log_stats): New.
6184 (bounded_ranges_constraint::print): New.
6185 (bounded_ranges_constraint::to_json): New.
6186 (bounded_ranges_constraint::operator==): New.
6187 (bounded_ranges_constraint::add_to_hash): New.
6188 (constraint_manager::constraint_manager): Update for new field
6189 m_bounded_ranges_constraints.
6190 (constraint_manager::operator=): Likewise.
6191 (constraint_manager::hash): Likewise.
6192 (constraint_manager::operator==): Likewise.
6193 (constraint_manager::print): Likewise.
6194 (constraint_manager::dump_to_pp): Likewise.
6195 (constraint_manager::to_json): Likewise.
6196 (constraint_manager::add_unknown_constraint): Update the lhs_ec_id
6197 if necessary in existing constraints when combining equivalence
6198 classes. Add similar code for handling
6199 m_bounded_ranges_constraints.
6200 (constraint_manager::add_constraint_internal): Add comment.
6201 (constraint_manager::add_bounded_ranges): New.
6202 (constraint_manager::eval_condition): Use new field
6203 m_bounded_ranges_constraints.
6204 (constraint_manager::purge): Update bounded_ranges_constraint
6205 instances.
6206 (constraint_manager::canonicalize): Update for new field.
6207 (merger_fact_visitor::on_ranges): New.
6208 (constraint_manager::for_each_fact): Use new field
6209 m_bounded_ranges_constraints.
6210 (constraint_manager::validate): Fix off-by-one error needed due
6211 to bug fixed above in add_unknown_constraint. Validate the EC IDs
6212 in m_bounded_ranges_constraints.
6213 (constraint_manager::get_range_manager): New.
6214 (selftest::assert_dump_bounded_range_eq): New.
6215 (ASSERT_DUMP_BOUNDED_RANGE_EQ): New.
6216 (selftest::test_bounded_range): New.
6217 (selftest::assert_dump_bounded_ranges_eq): New.
6218 (ASSERT_DUMP_BOUNDED_RANGES_EQ): New.
6219 (selftest::test_bounded_ranges): New.
6220 (selftest::run_constraint_manager_tests): Call the new selftests.
6221 * constraint-manager.h (struct bounded_range): New.
6222 (struct bounded_ranges): New.
6223 (template <> struct default_hash_traits<bounded_ranges::key_t>): New.
6224 (class bounded_ranges_manager): New.
6225 (fact_visitor::on_ranges): New pure virtual function.
6226 (class bounded_ranges_constraint): New.
6227 (constraint_manager::add_bounded_ranges): New decl.
6228 (constraint_manager::get_range_manager): New decl.
6229 (constraint_manager::m_bounded_ranges_constraints): New field.
6230 * diagnostic-manager.cc (epath_finder::process_worklist_item):
6231 Transfer ownership of rc to add_feasibility_problem.
6232 * engine.cc (feasibility_problem::dump_to_pp): Use get_model.
6233 * feasible-graph.cc (infeasible_node::dump_dot): Update for
6234 conversion of m_rc to a pointer.
6235 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
6236 take ownership.
6237 * feasible-graph.h (infeasible_node::infeasible_node): Pass RC by
6238 pointer and take ownership.
6239 (infeasible_node::~infeasible_node): New.
6240 (infeasible_node::m_rc): Convert to a pointer.
6241 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
6242 take ownership.
6243 * region-model-manager.cc: Include
6244 "analyzer/constraint-manager.h".
6245 (region_model_manager::region_model_manager): Initializer new
6246 field m_range_mgr.
6247 (region_model_manager::~region_model_manager): Delete it.
6248 (region_model_manager::log_stats): Call log_stats on it.
6249 * region-model.cc (region_model::add_constraint): Use new subclass
6250 rejected_op_constraint.
6251 (region_model::apply_constraints_for_gswitch): Reimplement using
6252 bounded_ranges_manager.
6253 (rejected_constraint::dump_to_pp): Convert to...
6254 (rejected_op_constraint::dump_to_pp): ...this.
6255 (rejected_ranges_constraint::dump_to_pp): New.
6256 * region-model.h (struct purge_stats): Add field
6257 m_num_bounded_ranges_constraints.
6258 (region_model_manager::get_range_manager): New.
6259 (region_model_manager::m_range_mgr): New.
6260 (region_model::get_range_manager): New.
6261 (struct rejected_constraint): Split into...
6262 (class rejected_constraint):...this new abstract base class,
6263 and...
6264 (class rejected_op_constraint): ...this new concrete subclass.
6265 (class rejected_ranges_constraint): New.
6266 * supergraph.cc: Include "tree-cfg.h".
6267 (supergraph::supergraph): Drop idx param from add_cfg_edge.
6268 (supergraph::add_cfg_edge): Drop idx param.
6269 (switch_cfg_superedge::switch_cfg_superedge): Move here from
6270 header. Populate m_case_labels with all cases which go to DST.
6271 (switch_cfg_superedge::dump_label_to_pp): Reimplement to use
6272 m_case_labels.
6273 (switch_cfg_superedge::get_case_label): Delete.
6274 * supergraph.h (supergraphadd_cfg_edge): Drop "idx" param.
6275 (switch_cfg_superedge::switch_cfg_superedge): Drop idx param and
6276 move implementation to supergraph.cc.
6277 (switch_cfg_superedge::get_case_label): Delete.
6278 (switch_cfg_superedge::get_case_labels): New.
6279 (switch_cfg_superedge::m_idx): Delete.
6280 (switch_cfg_superedge::m_case_labels): New field.
6281
6282 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6283
6284 PR analyzer/101875
6285 * sm-file.cc (file_diagnostic::describe_state_change): Handle
6286 change.m_expr being NULL.
6287
6288 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6289
6290 PR analyzer/101837
6291 * analyzer.cc (maybe_reconstruct_from_def_stmt): Bail if fn is
6292 NULL, and assert that it's non-NULL before passing it to
6293 build_call_array_loc.
6294
6295 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6296
6297 PR analyzer/101962
6298 * region-model.cc (region_model::eval_condition_without_cm):
6299 Refactor comparison against zero, adding a check for
6300 POINTER_PLUS_EXPR of non-NULL.
6301
6302 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6303
6304 * store.cc (bit_range::intersects_p): New overload.
6305 (bit_range::operator-): New.
6306 (binding_cluster::maybe_get_compound_binding): Handle the partial
6307 overlap case.
6308 (selftest::test_bit_range_intersects_p): Add test coverage for
6309 new overload of bit_range::intersects_p.
6310 * store.h (bit_range::intersects_p): New overload.
6311 (bit_range::operator-): New.
6312
6313 2021-08-23 Ankur Saini <arsenic@sourceware.org>
6314
6315 PR analyzer/102020
6316 * diagnostic-manager.cc
6317 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Fix typo.
6318
6319 2021-08-21 Ankur Saini <arsenic@sourceware.org>
6320
6321 PR analyzer/101980
6322 * diagnostic-manager.cc
6323 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Use
6324 caller_model only when the supergraph_edge doesn't exixt.
6325 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
6326 Likewise.
6327 * engine.cc (exploded_graph::create_dynamic_call): Rename to...
6328 (exploded_graph::maybe_create_dynamic_call): ...this, return call
6329 creation status.
6330 (exploded_graph::process_node): Handle calls which were not dynamically
6331 discovered.
6332 * exploded-graph.h (exploded_graph::create_dynamic_call): Rename to...
6333 (exploded_graph::maybe_create_dynamic_call): ...this.
6334 * region-model.cc (region_model::update_for_gcall): New param, use it
6335 to push call to frame.
6336 (region_model::update_for_call_superedge): Pass callee function to
6337 update_for_gcall.
6338 * region-model.h (region_model::update_for_gcall): New param.
6339
6340 2021-08-18 Ankur Saini <arsenic@sourceware.org>
6341
6342 PR analyzer/97114
6343 * region-model.cc (region_model::get_rvalue_1): Add case for
6344 OBJ_TYPE_REF.
6345
6346 2021-08-18 Ankur Saini <arsenic@sourceware.org>
6347
6348 PR analyzer/100546
6349 * analysis-plan.cc (analysis_plan::use_summary_p): Don't use call
6350 summaries if there is no callgraph edge
6351 * checker-path.cc (call_event::call_event): Handle calls events that
6352 are not represented by a supergraph call edge
6353 (return_event::return_event): Likewise.
6354 (call_event::get_desc): Work with new call_event structure.
6355 (return_event::get_desc): Likeise.
6356 * checker-path.h (call_event::m_src_snode): New field.
6357 (call_event::m_dest_snode): New field.
6358 (return_event::m_src_snode): New field.
6359 (return_event::m_dest_snode): New field.
6360 * diagnostic-manager.cc
6361 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>:
6362 Refactor to work with edges without callgraph edge.
6363 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
6364 Likewise.
6365 * engine.cc (dynamic_call_info_t::update_model): New function.
6366 (dynamic_call_info_t::add_events_to_path): New function.
6367 (exploded_graph::create_dynamic_call): New function.
6368 (exploded_graph::process_node): Work with dynamically discovered calls.
6369 * exploded-graph.h (class dynamic_call_info_t): New class.
6370 (exploded_graph::create_dynamic_call): New decl.
6371 * program-point.cc (program_point::push_to_call_stack): New function.
6372 (program_point::pop_from_call_stack): New function.
6373 * program-point.h (program_point::push_to_call_stack): New decl.
6374 (program_point::pop_from_call_stack): New decl.
6375 * program-state.cc (program_state::push_call): New function.
6376 (program_state::returning_call): New function.
6377 * program-state.h (program_state::push_call): New decl.
6378 (program_state::returning_call): New decl.
6379 * region-model.cc (region_model::update_for_gcall) New function.
6380 (region_model::update_for_return_gcall): New function.
6381 (egion_model::update_for_call_superedge): Get the underlying gcall and
6382 update for gcall.
6383 (region_model::update_for_return_superedge): Likewise.
6384 * region-model.h (region_model::update_for_gcall): New decl.
6385 (region_model::update_for_return_gcall): New decl.
6386 * state-purge.cc (state_purge_per_ssa_name::process_point): Update to
6387 work with calls without underlying cgraph edge.
6388 * supergraph.cc (supergraph::supergraph) Split snodes at every callsite.
6389 * supergraph.h (supernode::get_returning_call) New accessor.
6390
6391 2021-08-04 David Malcolm <dmalcolm@redhat.com>
6392
6393 PR analyzer/101570
6394 * analyzer.cc (maybe_reconstruct_from_def_stmt): Add GIMPLE_ASM
6395 case.
6396 * analyzer.h (class asm_output_svalue): New forward decl.
6397 (class reachable_regions): New forward decl.
6398 * complexity.cc (complexity::from_vec_svalue): New.
6399 * complexity.h (complexity::from_vec_svalue): New decl.
6400 * engine.cc (feasibility_state::maybe_update_for_edge): Handle
6401 asm stmts by calling on_asm_stmt.
6402 * region-model-asm.cc: New file.
6403 * region-model-manager.cc
6404 (region_model_manager::maybe_fold_asm_output_svalue): New.
6405 (region_model_manager::get_or_create_asm_output_svalue): New.
6406 (region_model_manager::log_stats): Log m_asm_output_values_map.
6407 * region-model.cc (region_model::on_stmt_pre): Handle GIMPLE_ASM.
6408 * region-model.h (visitor::visit_asm_output_svalue): New.
6409 (region_model_manager::get_or_create_asm_output_svalue): New decl.
6410 (region_model_manager::maybe_fold_asm_output_svalue): New decl.
6411 (region_model_manager::asm_output_values_map_t): New typedef.
6412 (region_model_manager::m_asm_output_values_map): New field.
6413 (region_model::on_asm_stmt): New.
6414 * store.cc (binding_cluster::on_asm): New.
6415 * store.h (binding_cluster::on_asm): New decl.
6416 * svalue.cc (svalue::cmp_ptr): Handle SK_ASM_OUTPUT.
6417 (asm_output_svalue::dump_to_pp): New.
6418 (asm_output_svalue::dump_input): New.
6419 (asm_output_svalue::input_idx_to_asm_idx): New.
6420 (asm_output_svalue::accept): New.
6421 * svalue.h (enum svalue_kind): Add SK_ASM_OUTPUT.
6422 (svalue::dyn_cast_asm_output_svalue): New.
6423 (class asm_output_svalue): New.
6424 (is_a_helper <const asm_output_svalue *>::test): New.
6425 (struct default_hash_traits<asm_output_svalue::key_t>): New.
6426
6427 2021-08-03 Jakub Jelinek <jakub@redhat.com>
6428
6429 PR analyzer/101721
6430 * sm-malloc.cc (known_allocator_p): Only check DECL_FUNCTION_CODE on
6431 BUILT_IN_NORMAL builtins.
6432
6433 2021-07-29 Ankur Saini <arsenic@sourceware.org>
6434
6435 * call-string.cc (call_string::element_t::operator==): New operator.
6436 (call_String::element_t::operator!=): New operator.
6437 (call_string::element_t::get_caller_function): New function.
6438 (call_string::element_t::get_callee_function): New function.
6439 (call_string::call_string): Refactor to Initialise m_elements.
6440 (call_string::operator=): Refactor to work with m_elements.
6441 (call_string::operator==): Likewise.
6442 (call_string::to_json): Likewise.
6443 (call_string::hash): Refactor to hash e.m_caller.
6444 (call_string::push_call): Refactor to work with m_elements.
6445 (call_string::push_call): New overload to push call via supernodes.
6446 (call_string::pop): Refactor to work with m_elements.
6447 (call_string::calc_recursion_depth): Likewise.
6448 (call_string::cmp): Likewise.
6449 (call_string::validate): Likewise.
6450 (call_string::operator[]): Likewise.
6451 * call-string.h (class supernode): New forward decl.
6452 (struct call_string::element_t): New struct.
6453 (call_string::call_string): Refactor to initialise m_elements.
6454 (call_string::bool empty_p): Refactor to work with m_elements.
6455 (call_string::get_callee_node): New decl.
6456 (call_string::get_caller_node): New decl.
6457 (m_elements): Replaces m_return_edges.
6458 * program-point.cc (program_point::get_function_at_depth): Refactor to
6459 work with new call-string format.
6460 (program_point::validate): Likewise.
6461 (program_point::on_edge): Likewise.
6462
6463 2021-07-28 David Malcolm <dmalcolm@redhat.com>
6464
6465 * region-model.cc (region_model::on_call_pre): Treat
6466 IFN_UBSAN_BOUNDS, BUILT_IN_STACK_SAVE, and BUILT_IN_STACK_RESTORE
6467 as no-ops, rather than handling them as unknown functions.
6468
6469 2021-07-28 David Malcolm <dmalcolm@redhat.com>
6470
6471 * region-model-impl-calls.cc (region_model::impl_call_alloca):
6472 Drop redundant return value.
6473 (region_model::impl_call_builtin_expect): Likewise.
6474 (region_model::impl_call_calloc): Likewise.
6475 (region_model::impl_call_malloc): Likewise.
6476 (region_model::impl_call_memset): Likewise.
6477 (region_model::impl_call_operator_new): Likewise.
6478 (region_model::impl_call_operator_delete): Likewise.
6479 (region_model::impl_call_strlen): Likewise.
6480 * region-model.cc (region_model::on_call_pre): Fix return value of
6481 known functions that don't have unknown side-effects.
6482 * region-model.h (region_model::impl_call_alloca): Drop redundant
6483 return value.
6484 (region_model::impl_call_builtin_expect): Likewise.
6485 (region_model::impl_call_calloc): Likewise.
6486 (region_model::impl_call_malloc): Likewise.
6487 (region_model::impl_call_memset): Likewise.
6488 (region_model::impl_call_strlen): Likewise.
6489 (region_model::impl_call_operator_new): Likewise.
6490 (region_model::impl_call_operator_delete): Likewise.
6491
6492 2021-07-28 Siddhesh Poyarekar <siddhesh@gotplt.org>
6493
6494 * analyzer.cc (is_named_call_p, is_std_named_call_p): Make
6495 first argument a const_tree.
6496 * analyzer.h (is_named_call_p, -s_std_named_call_p): Likewise.
6497 * sm-malloc.cc (known_allocator_p): New function.
6498 (malloc_state_machine::on_stmt): Use it.
6499
6500 2021-07-28 Siddhesh Poyarekar <siddhesh@gotplt.org>
6501
6502 * sm-malloc.cc
6503 (malloc_state_machine::get_or_create_deallocator): Recognize
6504 __builtin_free.
6505
6506 2021-07-26 David Malcolm <dmalcolm@redhat.com>
6507
6508 * region-model.cc (region_model::on_call_pre): Always set conjured
6509 LHS, not just for SSA names.
6510
6511 2021-07-23 David Malcolm <dmalcolm@redhat.com>
6512
6513 * diagnostic-manager.cc
6514 (class auto_disable_complexity_checks): New.
6515 (epath_finder::explore_feasible_paths): Use it to disable
6516 complexity checks whilst processing the worklist.
6517 * region-model-manager.cc
6518 (region_model_manager::region_model_manager): Initialize
6519 m_check_complexity.
6520 (region_model_manager::reject_if_too_complex): Bail if
6521 m_check_complexity is false.
6522 * region-model.h
6523 (region_model_manager::enable_complexity_check): New.
6524 (region_model_manager::disable_complexity_check): New.
6525 (region_model_manager::m_check_complexity): New.
6526
6527 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6528
6529 PR analyzer/101547
6530 * sm-file.cc (file_leak::emit): Handle m_arg being NULL.
6531 (file_leak::describe_final_event): Handle ev.m_expr being NULL.
6532
6533 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6534
6535 PR analyzer/101522
6536 * store.cc (binding_cluster::purge_state_involving): Don't change
6537 m_map whilst iterating through it.
6538
6539 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6540
6541 * region-model.cc (region_model::handle_phi): Add "old_state"
6542 param and use it.
6543 (region_model::update_for_phis): Update so that all of the phi
6544 stmts are effectively handled simultaneously, rather than in
6545 order.
6546 * region-model.h (region_model::handle_phi): Add "old_state"
6547 param.
6548 * state-purge.cc (self_referential_phi_p): Replace with...
6549 (name_used_by_phis_p): ...this new function.
6550 (state_purge_per_ssa_name::process_point): Update to use the
6551 above, so that all phi stmts at a basic block are effectively
6552 considered simultaneously, and only consider the phi arguments for
6553 the pertinent in-edge.
6554 * supergraph.cc (cfg_superedge::get_phi_arg_idx): New.
6555 (cfg_superedge::get_phi_arg): Use the above.
6556 * supergraph.h (cfg_superedge::get_phi_arg_idx): New decl.
6557
6558 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6559
6560 * state-purge.cc (state_purge_annotator::add_node_annotations):
6561 Rather than erroneously always using the NULL in-edge, determine
6562 each relevant in-edge, and print the appropriate data for each
6563 in-edge. Use print_needed to print the data as comma-separated
6564 lists of SSA names.
6565 (print_vec_of_names): Add "within_table" param and use it.
6566 (state_purge_annotator::add_stmt_annotations): Factor out
6567 collation and printing code into...
6568 (state_purge_annotator::print_needed): ...this new function.
6569 * state-purge.h (state_purge_annotator::print_needed): New decl.
6570
6571 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6572
6573 * program-point.cc (function_point::print): Show src BB index at
6574 BEFORE_SUPERNODE.
6575
6576 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6577
6578 * svalue.cc (infix_p): New.
6579 (binop_svalue::dump_to_pp): Use it to print MIN_EXPR and MAX_EXPR
6580 in prefix form, rather than infix.
6581
6582 2021-07-19 David Malcolm <dmalcolm@redhat.com>
6583
6584 PR analyzer/101503
6585 * constraint-manager.cc (constraint_manager::add_constraint): Use
6586 can_have_associated_state_p rather than testing for unknown.
6587 (constraint_manager::get_or_add_equiv_class): Likewise.
6588 * program-state.cc (sm_state_map::set_state): Likewise.
6589 (sm_state_map::impl_set_state): Add assertion.
6590 * region-model-manager.cc
6591 (region_model_manager::maybe_fold_unaryop): Handle poisoned
6592 values.
6593 (region_model_manager::maybe_fold_binop): Move handling of unknown
6594 values...
6595 (region_model_manager::get_or_create_binop): ...to here, and
6596 generalize to use can_have_associated_state_p.
6597 (region_model_manager::maybe_fold_sub_svalue): Use
6598 can_have_associated_state_p rather than testing for unknown.
6599 (region_model_manager::maybe_fold_repeated_svalue): Use unknown
6600 when the size or repeated value is "unknown"/"poisoned".
6601 * region-model.cc (region_model::purge_state_involving): Reject
6602 attempts to purge unknown/poisoned svalues, as these svalues
6603 should not have state associated with them.
6604 * svalue.cc (sub_svalue::sub_svalue): Assert that we're building
6605 on top of an svalue with can_have_associated_state_p.
6606 (repeated_svalue::repeated_svalue): Likewise.
6607 (bits_within_svalue::bits_within_svalue): Likewise.
6608 * svalue.h (svalue::can_have_associated_state_p): New.
6609 (unknown_svalue::can_have_associated_state_p): New.
6610 (poisoned_svalue::can_have_associated_state_p): New.
6611 (unaryop_svalue::unaryop_svalue): Assert that we're building on
6612 top of an svalue with can_have_associated_state_p.
6613 (binop_svalue::binop_svalue): Likewise.
6614 (widening_svalue::widening_svalue): Likewise.
6615
6616 2021-07-16 David Malcolm <dmalcolm@redhat.com>
6617
6618 * analyzer.h (enum access_direction): New.
6619 * engine.cc (exploded_node::on_longjmp): Update for new param of
6620 get_store_value.
6621 * program-state.cc (program_state::prune_for_point): Likewise.
6622 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
6623 Replace call to check_for_writable_region with call to
6624 check_region_for_write.
6625 (region_model::impl_call_memset): Likewise.
6626 (region_model::impl_call_strcpy): Likewise.
6627 * region-model-reachability.cc (reachable_regions::add): Update
6628 for new param of get_store_value.
6629 * region-model.cc (region_model::get_rvalue_1): Likewise, also for
6630 get_rvalue_for_bits.
6631 (region_model::get_store_value): Add ctxt param and use it to call
6632 check_region_for_read.
6633 (region_model::get_rvalue_for_bits): Add ctxt param and use it to
6634 call get_store_value.
6635 (region_model::check_region_access): New.
6636 (region_model::check_region_for_write): New.
6637 (region_model::check_region_for_read): New.
6638 (region_model::set_value): Update comment. Replace call to
6639 check_for_writable_region with call to check_region_for_write.
6640 * region-model.h (region_model::get_rvalue_for_bits): Add ctxt
6641 param.
6642 (region_model::get_store_value): Add ctxt param.
6643 (region_model::check_region_access): New decl.
6644 (region_model::check_region_for_write): New decl.
6645 (region_model::check_region_for_read): New decl.
6646 * region.cc (region_model::copy_region): Update call to
6647 get_store_value.
6648 * svalue.cc (initial_svalue::implicitly_live_p): Likewise.
6649
6650 2021-07-16 David Malcolm <dmalcolm@redhat.com>
6651
6652 * engine.cc (exploded_node::on_stmt_pre): Handle
6653 __analyzer_dump_state.
6654 * program-state.cc (extrinsic_state::get_sm_idx_by_name): New.
6655 (program_state::impl_call_analyzer_dump_state): New.
6656 * program-state.h (extrinsic_state::get_sm_idx_by_name): New decl.
6657 (program_state::impl_call_analyzer_dump_state): New decl.
6658 * region-model-impl-calls.cc
6659 (call_details::get_arg_string_literal): New.
6660 * region-model.h (call_details::get_arg_string_literal): New decl.
6661
6662 2021-07-16 David Malcolm <dmalcolm@redhat.com>
6663
6664 * program-state.cc (program_state::detect_leaks): Simplify using
6665 svalue::maybe_get_region.
6666 * region-model-impl-calls.cc (region_model::impl_call_fgets): Likewise.
6667 (region_model::impl_call_fread): Likewise.
6668 (region_model::impl_call_free): Likewise.
6669 (region_model::impl_call_operator_delete): Likewise.
6670 * region-model.cc (selftest::test_stack_frames): Likewise.
6671 (selftest::test_state_merging): Likewise.
6672 * svalue.cc (svalue::maybe_get_region): New.
6673 * svalue.h (svalue::maybe_get_region): New decl.
6674
6675 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6676
6677 * svalue.h (is_a_helper <placeholder_svalue *>::test): Make
6678 param and template param const.
6679 (is_a_helper <widening_svalue *>::test): Likewise.
6680 (is_a_helper <compound_svalue *>::test): Likewise.
6681 (is_a_helper <conjured_svalue *>::test): Likewise.
6682
6683 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6684
6685 PR analyzer/95006
6686 PR analyzer/94713
6687 PR analyzer/94714
6688 * analyzer.cc (maybe_reconstruct_from_def_stmt): Split out
6689 GIMPLE_ASSIGN case into...
6690 (get_diagnostic_tree_for_gassign_1): New.
6691 (get_diagnostic_tree_for_gassign): New.
6692 * analyzer.h (get_diagnostic_tree_for_gassign): New decl.
6693 * analyzer.opt (Wanalyzer-write-to-string-literal): New.
6694 * constraint-manager.cc (class svalue_purger): New.
6695 (constraint_manager::purge_state_involving): New.
6696 * constraint-manager.h
6697 (constraint_manager::purge_state_involving): New.
6698 * diagnostic-manager.cc (saved_diagnostic::supercedes_p): New.
6699 (dedupe_winners::handle_interactions): New.
6700 (diagnostic_manager::emit_saved_diagnostics): Call it.
6701 * diagnostic-manager.h (saved_diagnostic::supercedes_p): New decl.
6702 * engine.cc (impl_region_model_context::warn): Convert return type
6703 to bool. Return false if the diagnostic isn't saved.
6704 (impl_region_model_context::purge_state_involving): New.
6705 (impl_sm_context::get_state): Use NULL ctxt when querying old
6706 rvalue.
6707 (impl_sm_context::set_next_state): Use new sval when querying old
6708 state.
6709 (class dump_path_diagnostic): Move to region-model.cc
6710 (exploded_node::on_stmt): Move to on_stmt_pre and on_stmt_post.
6711 Remove call to purge_state_involving.
6712 (exploded_node::on_stmt_pre): New, based on the above. Move most
6713 of it to region_model::on_stmt_pre.
6714 (exploded_node::on_stmt_post): Likewise, moving to
6715 region_model::on_stmt_post.
6716 (class stale_jmp_buf): Fix parent class to use curiously recurring
6717 template pattern.
6718 (feasibility_state::maybe_update_for_edge): Call on_call_pre and
6719 on_call_post on gcalls.
6720 * exploded-graph.h (impl_region_model_context::warn): Return bool.
6721 (impl_region_model_context::purge_state_involving): New decl.
6722 (exploded_node::on_stmt_pre): New decl.
6723 (exploded_node::on_stmt_post): New decl.
6724 * pending-diagnostic.h (pending_diagnostic::use_of_uninit_p): New.
6725 (pending_diagnostic::supercedes_p): New.
6726 * program-state.cc (sm_state_map::get_state): Inherit state for
6727 conjured_svalue as well as initial_svalue.
6728 (sm_state_map::purge_state_involving): Also support SK_CONJURED.
6729 * region-model-impl-calls.cc (call_details::get_uncertainty):
6730 Handle m_ctxt being NULL.
6731 (call_details::get_or_create_conjured_svalue): New.
6732 (region_model::impl_call_fgets): New.
6733 (region_model::impl_call_fread): New.
6734 * region-model-manager.cc
6735 (region_model_manager::get_or_create_initial_value): Return an
6736 uninitialized poisoned value for regions that can't have initial
6737 values.
6738 * region-model-reachability.cc
6739 (reachable_regions::mark_escaped_clusters): Handle ctxt being
6740 NULL.
6741 * region-model.cc (region_to_value_map::purge_state_involving): New.
6742 (poisoned_value_diagnostic::use_of_uninit_p): New.
6743 (poisoned_value_diagnostic::emit): Handle POISON_KIND_UNINIT.
6744 (poisoned_value_diagnostic::describe_final_event): Likewise.
6745 (region_model::check_for_poison): New.
6746 (region_model::on_assignment): Call it.
6747 (class dump_path_diagnostic): Move here from engine.cc.
6748 (region_model::on_stmt_pre): New, based on exploded_node::on_stmt.
6749 (region_model::on_call_pre): Move the setting of the LHS to a
6750 conjured svalue to before the checks for specific functions.
6751 Handle "fgets", "fgets_unlocked", and "fread".
6752 (region_model::purge_state_involving): New.
6753 (region_model::handle_unrecognized_call): Handle ctxt being NULL.
6754 (region_model::get_rvalue): Call check_for_poison.
6755 (selftest::test_stack_frames): Use NULL for context when getting
6756 uninitialized rvalue.
6757 (selftest::test_alloca): Likewise.
6758 * region-model.h (region_to_value_map::purge_state_involving): New
6759 decl.
6760 (call_details::get_or_create_conjured_svalue): New decl.
6761 (region_model::on_stmt_pre): New decl.
6762 (region_model::purge_state_involving): New decl.
6763 (region_model::impl_call_fgets): New decl.
6764 (region_model::impl_call_fread): New decl.
6765 (region_model::check_for_poison): New decl.
6766 (region_model_context::warn): Return bool.
6767 (region_model_context::purge_state_involving): New.
6768 (noop_region_model_context::warn): Return bool.
6769 (noop_region_model_context::purge_state_involving): New.
6770 (test_region_model_context:: warn): Return bool.
6771 * region.cc (region::get_memory_space): New.
6772 (region::can_have_initial_svalue_p): New.
6773 (region::involves_p): New.
6774 * region.h (enum memory_space): New.
6775 (region::get_memory_space): New decl.
6776 (region::can_have_initial_svalue_p): New decl.
6777 (region::involves_p): New decl.
6778 * sm-malloc.cc (use_after_free::supercedes_p): New.
6779 * store.cc (binding_cluster::purge_state_involving): New.
6780 (store::purge_state_involving): New.
6781 * store.h (class symbolic_binding): New forward decl.
6782 (binding_key::dyn_cast_symbolic_binding): New.
6783 (symbolic_binding::dyn_cast_symbolic_binding): New.
6784 (binding_cluster::purge_state_involving): New.
6785 (store::purge_state_involving): New.
6786 * svalue.cc (svalue::can_merge_p): Reject attempts to merge
6787 poisoned svalues with other svalues, so that we identify
6788 paths in which a variable is conditionally uninitialized.
6789 (involvement_visitor::visit_conjured_svalue): New.
6790 (svalue::involves_p): Also handle SK_CONJURED.
6791 (poison_kind_to_str): Handle POISON_KIND_UNINIT.
6792 (poisoned_svalue::maybe_fold_bits_within): New.
6793 * svalue.h (enum poison_kind): Add POISON_KIND_UNINIT.
6794 (poisoned_svalue::maybe_fold_bits_within): New decl.
6795
6796 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6797
6798 * analyzer.opt (fdump-analyzer-exploded-paths): New.
6799 * diagnostic-manager.cc
6800 (diagnostic_manager::emit_saved_diagnostic): Implement it.
6801 * engine.cc (exploded_path::dump_to_pp): Add ext_state param and
6802 use it to dump states if non-NULL.
6803 (exploded_path::dump): Likewise.
6804 (exploded_path::dump_to_file): New.
6805 * exploded-graph.h (exploded_path::dump_to_pp): Add ext_state
6806 param.
6807 (exploded_path::dump): Likewise.
6808 (exploded_path::dump): Likewise.
6809 (exploded_path::dump_to_file): New.
6810
6811 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6812
6813 * analyzer.cc (fixup_tree_for_diagnostic_1): Use DECL_DEBUG_EXPR
6814 if it's available.
6815 * engine.cc (readability): Likewise.
6816
6817 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6818
6819 * state-purge.cc (self_referential_phi_p): New.
6820 (state_purge_per_ssa_name::process_point): Don't purge an SSA name
6821 at its def-stmt if the def-stmt is self-referential.
6822
6823 2021-07-07 David Malcolm <dmalcolm@redhat.com>
6824
6825 * diagnostic-manager.cc (null_assignment_sm_context::get_state):
6826 New overload.
6827 (null_assignment_sm_context::set_next_state): New overload.
6828 (null_assignment_sm_context::get_diagnostic_tree): New.
6829 * engine.cc (impl_sm_context::get_state): New overload.
6830 (impl_sm_context::set_next_state): New overload.
6831 (impl_sm_context::get_diagnostic_tree): New overload.
6832 (impl_region_model_context::on_condition): Convert params from
6833 tree to const svalue *.
6834 * exploded-graph.h (impl_region_model_context::on_condition):
6835 Likewise.
6836 * region-model.cc (region_model::on_call_pre): Move handling of
6837 internal calls to before checking for get_fndecl_for_call.
6838 (region_model::add_constraints_from_binop): New.
6839 (region_model::add_constraint): Split out into a new overload
6840 working on const svalue * rather than tree. Call
6841 add_constraints_from_binop. Drop call to
6842 add_any_constraints_from_ssa_def_stmt.
6843 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6844 (region_model::add_any_constraints_from_gassign): Delete.
6845 (region_model::add_any_constraints_from_gcall): Delete.
6846 * region-model.h
6847 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6848 (region_model::add_any_constraints_from_gassign): Delete.
6849 (region_model::add_any_constraints_from_gcall): Delete.
6850 (region_model::add_constraint): Add overload decl.
6851 (region_model::add_constraints_from_binop): New decl.
6852 (region_model_context::on_condition): Convert params from tree to
6853 const svalue *.
6854 (noop_region_model_context::on_condition): Likewise.
6855 * sm-file.cc (fileptr_state_machine::condition): Likewise.
6856 * sm-malloc.cc (malloc_state_machine::on_condition): Likewise.
6857 * sm-pattern-test.cc: Include tristate.h, selftest.h,
6858 analyzer/call-string.h, analyzer/program-point.h,
6859 analyzer/store.h, and analyzer/region-model.h.
6860 (pattern_test_state_machine::on_condition): Convert params from tree to
6861 const svalue *.
6862 * sm-sensitive.cc (sensitive_state_machine::on_condition): Delete.
6863 * sm-signal.cc (signal_state_machine::on_condition): Delete.
6864 * sm-taint.cc (taint_state_machine::on_condition): Convert params
6865 from tree to const svalue *.
6866 * sm.cc: Include tristate.h, selftest.h, analyzer/call-string.h,
6867 analyzer/program-point.h, analyzer/store.h, and
6868 analyzer/region-model.h.
6869 (any_pointer_p): Add overload taking const svalue *sval.
6870 * sm.h (any_pointer_p): Add overload taking const svalue *sval.
6871 (state_machine::on_condition): Convert params from tree to
6872 const svalue *. Provide no-op default implementation.
6873 (sm_context::get_state): Add overload taking const svalue *sval.
6874 (sm_context::set_next_state): Likewise.
6875 (sm_context::on_transition): Likewise.
6876 (sm_context::get_diagnostic_tree): Likewise.
6877 * svalue.cc (svalue::all_zeroes_p): New.
6878 (constant_svalue::all_zeroes_p): New.
6879 (repeated_svalue::all_zeroes_p): Convert to vfunc.
6880 * svalue.h (svalue::all_zeroes_p): New decl.
6881 (constant_svalue::all_zeroes_p): New decl.
6882 (repeated_svalue::all_zeroes_p): Convert decl to vfunc.
6883
6884 2021-06-30 David Malcolm <dmalcolm@redhat.com>
6885
6886 PR analyzer/95006
6887 * analyzer.h (class repeated_svalue): New forward decl.
6888 (class bits_within_svalue): New forward decl.
6889 (class sized_region): New forward decl.
6890 (get_field_at_bit_offset): New forward decl.
6891 * engine.cc (exploded_graph::get_or_create_node): Validate the
6892 merged state.
6893 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
6894 Validate the states at each stage.
6895 * program-state.cc (program_state::validate): Validate
6896 m_region_model.
6897 * region-model-impl-calls.cc (region_model::impl_call_memset):
6898 Replace special-case logic for handling constant sizes with
6899 a call to fill_region of a sized_region with the given fill value.
6900 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
6901 Drop DK_direct.
6902 (region_model_manager::maybe_fold_sub_svalue): Fold element-based
6903 subregions of an initial value into initial values of an element.
6904 Fold subvalues of repeated svalues.
6905 (region_model_manager::maybe_fold_repeated_svalue): New.
6906 (region_model_manager::get_or_create_repeated_svalue): New.
6907 (get_bit_range_for_field): New.
6908 (get_byte_range_for_field): New.
6909 (get_field_at_byte_range): New.
6910 (region_model_manager::maybe_fold_bits_within_svalue): New.
6911 (region_model_manager::get_or_create_bits_within): New.
6912 (region_model_manager::get_sized_region): New.
6913 (region_model_manager::log_stats): Update for addition of
6914 m_repeated_values_map, m_bits_within_values_map, and
6915 m_sized_regions.
6916 * region-model.cc (region_model::validate): New.
6917 (region_model::on_assignment): Drop enum binding_kind.
6918 (region_model::get_initial_value_for_global): Likewise.
6919 (region_model::get_rvalue_for_bits): Replace body with call to
6920 get_or_create_bits_within.
6921 (region_model::get_capacity): Handle RK_SIZED.
6922 (region_model::set_value): Drop enum binding_kind.
6923 (region_model::fill_region): New.
6924 (region_model::get_representative_path_var_1): Handle RK_SIZED.
6925 * region-model.h (visitor::visit_repeated_svalue): New.
6926 (visitor::visit_bits_within_svalue): New.
6927 (region_model_manager::get_or_create_repeated_svalue): New decl.
6928 (region_model_manager::get_or_create_bits_within): New decl.
6929 (region_model_manager::get_sized_region): New decl.
6930 (region_model_manager::maybe_fold_repeated_svalue): New decl.
6931 (region_model_manager::maybe_fold_bits_within_svalue): New decl.
6932 (region_model_manager::repeated_values_map_t): New typedef.
6933 (region_model_manager::m_repeated_values_map): New field.
6934 (region_model_manager::bits_within_values_map_t): New typedef.
6935 (region_model_manager::m_bits_within_values_map): New field.
6936 (region_model_manager::m_sized_regions): New field.
6937 (region_model::fill_region): New decl.
6938 * region.cc (region::get_base_region): Handle RK_SIZED.
6939 (region::base_region_p): Likewise.
6940 (region::get_byte_size_sval): New.
6941 (get_field_at_bit_offset): Make non-static.
6942 (region::calc_offset): Move implementation of cases to
6943 get_relative_concrete_offset vfunc implementations. Handle
6944 RK_SIZED.
6945 (region::get_relative_concrete_offset): New.
6946 (decl_region::get_svalue_for_initializer): Drop enum binding_kind.
6947 (field_region::get_relative_concrete_offset): New, from
6948 region::calc_offset.
6949 (element_region::get_relative_concrete_offset): Likewise.
6950 (offset_region::get_relative_concrete_offset): Likewise.
6951 (sized_region::accept): New.
6952 (sized_region::dump_to_pp): New.
6953 (sized_region::get_byte_size): New.
6954 (sized_region::get_bit_size): New.
6955 * region.h (enum region_kind): Add RK_SIZED.
6956 (region::dyn_cast_sized_region): New.
6957 (region::get_byte_size): Make virtual.
6958 (region::get_bit_size): Likewise.
6959 (region::get_byte_size_sval): New decl.
6960 (region::get_relative_concrete_offset): New decl.
6961 (field_region::get_relative_concrete_offset): New decl.
6962 (element_region::get_relative_concrete_offset): Likewise.
6963 (offset_region::get_relative_concrete_offset): Likewise.
6964 (class sized_region): New.
6965 * store.cc (binding_kind_to_string): Delete.
6966 (binding_key::make): Drop enum binding_kind.
6967 (binding_key::dump_to_pp): Delete.
6968 (binding_key::cmp_ptrs): Drop enum binding_kind.
6969 (bit_range::contains_p): New.
6970 (byte_range::dump): New.
6971 (byte_range::contains_p): New.
6972 (byte_range::cmp): New.
6973 (concrete_binding::dump_to_pp): Drop enum binding_kind.
6974 (concrete_binding::cmp_ptr_ptr): Likewise.
6975 (symbolic_binding::dump_to_pp): Likewise.
6976 (symbolic_binding::cmp_ptr_ptr): Likewise.
6977 (binding_map::apply_ctor_val_to_range): Likewise.
6978 (binding_map::apply_ctor_pair_to_child_region): Likewise.
6979 (binding_map::get_overlapping_bindings): New.
6980 (binding_map::remove_overlapping_bindings): New.
6981 (binding_cluster::validate): New.
6982 (binding_cluster::bind): Drop enum binding_kind.
6983 (binding_cluster::bind_compound_sval): Likewise.
6984 (binding_cluster::purge_region): Likewise.
6985 (binding_cluster::zero_fill_region): Reimplement in terms of...
6986 (binding_cluster::fill_region): New.
6987 (binding_cluster::mark_region_as_unknown): Drop enum binding_kind.
6988 (binding_cluster::get_binding): Likewise.
6989 (binding_cluster::get_binding_recursive): Likewise.
6990 (binding_cluster::get_any_binding): Likewise.
6991 (binding_cluster::maybe_get_compound_binding): Reimplement.
6992 (binding_cluster::get_overlapping_bindings): Delete.
6993 (binding_cluster::remove_overlapping_bindings): Reimplement in
6994 terms of binding_map::remove_overlapping_bindings.
6995 (binding_cluster::can_merge_p): Update for removal of
6996 enum binding_kind.
6997 (binding_cluster::on_unknown_fncall): Drop enum binding_kind.
6998 (binding_cluster::maybe_get_simple_value): Likewise.
6999 (store_manager::get_concrete_binding): Likewise.
7000 (store_manager::get_symbolic_binding): Likewise.
7001 (store::validate): New.
7002 (store::set_value): Drop enum binding_kind.
7003 (store::zero_fill_region): Reimplement in terms of...
7004 (store::fill_region): New.
7005 (selftest::test_binding_key_overlap): Drop enum binding_kind.
7006 * store.h (enum binding_kind): Delete.
7007 (binding_kind_to_string): Delete decl.
7008 (binding_key::make): Drop enum binding_kind.
7009 (binding_key::dump_to_pp): Make pure virtual.
7010 (binding_key::get_kind): Delete.
7011 (binding_key::mark_deleted): Delete.
7012 (binding_key::mark_empty): Delete.
7013 (binding_key::is_deleted): Delete.
7014 (binding_key::is_empty): Delete.
7015 (binding_key::binding_key): Delete.
7016 (binding_key::impl_hash): Delete.
7017 (binding_key::impl_eq): Delete.
7018 (binding_key::m_kind): Delete.
7019 (bit_range::get_last_bit_offset): New.
7020 (bit_range::contains_p): New.
7021 (byte_range::contains_p): New.
7022 (byte_range::operator==): New.
7023 (byte_range::get_start_byte_offset): New.
7024 (byte_range::get_next_byte_offset): New.
7025 (byte_range::get_last_byte_offset): New.
7026 (byte_range::as_bit_range): New.
7027 (byte_range::cmp): New.
7028 (concrete_binding::concrete_binding): Drop enum binding_kind.
7029 (concrete_binding::hash): Likewise.
7030 (concrete_binding::operator==): Likewise.
7031 (concrete_binding::mark_deleted): New.
7032 (concrete_binding::mark_empty): New.
7033 (concrete_binding::is_deleted): New.
7034 (concrete_binding::is_empty): New.
7035 (default_hash_traits<ana::concrete_binding>::empty_zero_p): Make false.
7036 (symbolic_binding::symbolic_binding): Drop enum binding_kind.
7037 (symbolic_binding::hash): Likewise.
7038 (symbolic_binding::operator==): Likewise.
7039 (symbolic_binding::mark_deleted): New.
7040 (symbolic_binding::mark_empty): New.
7041 (symbolic_binding::is_deleted): New.
7042 (symbolic_binding::is_empty): New.
7043 (binding_map::remove_overlapping_bindings): New decl.
7044 (binding_map::get_overlapping_bindings): New decl.
7045 (binding_cluster::validate): New decl.
7046 (binding_cluster::bind): Drop enum binding_kind.
7047 (binding_cluster::fill_region): New decl.
7048 (binding_cluster::get_binding): Drop enum binding_kind.
7049 (binding_cluster::get_binding_recursive): Likewise.
7050 (binding_cluster::get_overlapping_bindings): Delete.
7051 (store::validate): New decl.
7052 (store::set_value): Drop enum binding_kind.
7053 (store::fill_region): New decl.
7054 (store_manager::get_concrete_binding): Drop enum binding_kind.
7055 (store_manager::get_symbolic_binding): Likewise.
7056 * svalue.cc (svalue::cmp_ptr): Handle SK_REPEATED and
7057 SK_BITS_WITHIN.
7058 (svalue::extract_bit_range): New.
7059 (svalue::maybe_fold_bits_within): New.
7060 (constant_svalue::maybe_fold_bits_within): New.
7061 (unknown_svalue::maybe_fold_bits_within): New.
7062 (unaryop_svalue::maybe_fold_bits_within): New.
7063 (repeated_svalue::repeated_svalue): New.
7064 (repeated_svalue::dump_to_pp): New.
7065 (repeated_svalue::accept): New.
7066 (repeated_svalue::all_zeroes_p): New.
7067 (repeated_svalue::maybe_fold_bits_within): New.
7068 (bits_within_svalue::bits_within_svalue): New.
7069 (bits_within_svalue::dump_to_pp): New.
7070 (bits_within_svalue::maybe_fold_bits_within): New.
7071 (bits_within_svalue::accept): New.
7072 (bits_within_svalue::implicitly_live_p): New.
7073 (compound_svalue::maybe_fold_bits_within): New.
7074 * svalue.h (enum svalue_kind): Add SK_REPEATED and SK_BITS_WITHIN.
7075 (svalue::dyn_cast_repeated_svalue): New.
7076 (svalue::dyn_cast_bits_within_svalue): New.
7077 (svalue::extract_bit_range): New decl.
7078 (svalue::maybe_fold_bits_within): New vfunc decl.
7079 (region_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7080 (region_svalue::key_t::is_empty): Likewise.
7081 (default_hash_traits<region_svalue::key_t>::empty_zero_p): Make false.
7082 (constant_svalue::maybe_fold_bits_within): New.
7083 (unknown_svalue::maybe_fold_bits_within): New.
7084 (poisoned_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7085 (poisoned_svalue::key_t::is_empty): Likewise.
7086 (default_hash_traits<poisoned_svalue::key_t>::empty_zero_p): Make
7087 false.
7088 (setjmp_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7089 (setjmp_svalue::key_t::is_empty): Likewise.
7090 (default_hash_traits<setjmp_svalue::key_t>::empty_zero_p): Make
7091 false.
7092 (unaryop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7093 (unaryop_svalue::key_t::is_empty): Likewise.
7094 (unaryop_svalue::maybe_fold_bits_within): New.
7095 (default_hash_traits<unaryop_svalue::key_t>::empty_zero_p): Make
7096 false.
7097 (binop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7098 (binop_svalue::key_t::is_empty): Likewise.
7099 (default_hash_traits<binop_svalue::key_t>::empty_zero_p): Make
7100 false.
7101 (sub_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7102 (sub_svalue::key_t::is_empty): Likewise.
7103 (default_hash_traits<sub_svalue::key_t>::empty_zero_p): Make
7104 false.
7105 (class repeated_svalue): New.
7106 (is_a_helper <const repeated_svalue *>::test): New.
7107 (struct default_hash_traits<repeated_svalue::key_t>): New.
7108 (class bits_within_svalue): New.
7109 (is_a_helper <const bits_within_svalue *>::test): New.
7110 (struct default_hash_traits<bits_within_svalue::key_t>): New.
7111 (widening_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7112 (widening_svalue::key_t::is_empty): Likewise.
7113 (default_hash_traits<widening_svalue::key_t>::empty_zero_p): Make
7114 false.
7115 (compound_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7116 (compound_svalue::key_t::is_empty): Likewise.
7117 (compound_svalue::maybe_fold_bits_within): New.
7118 (default_hash_traits<compound_svalue::key_t>::empty_zero_p): Make
7119 false.
7120
7121 2021-06-28 David Malcolm <dmalcolm@redhat.com>
7122
7123 * analyzer.h (byte_offset_t): New typedef.
7124 * store.cc (bit_range::dump_to_pp): Dump as a byte range if
7125 possible.
7126 (bit_range::as_byte_range): New.
7127 (byte_range::dump_to_pp): New.
7128 * store.h (class byte_range): New forward decl.
7129 (struct bit_range): Add comment.
7130 (bit_range::as_byte_range): New decl.
7131 (struct byte_range): New.
7132
7133 2021-06-22 David Malcolm <dmalcolm@redhat.com>
7134
7135 PR analyzer/101143
7136 * region-model.cc (compat_types_p): New function.
7137 (region_model::create_region_for_heap_alloc): Convert assertion to
7138 an error check.
7139 (region_model::create_region_for_alloca): Likewise.
7140
7141 2021-06-18 David Malcolm <dmalcolm@redhat.com>
7142
7143 * store.cc (binding_cluster::get_any_binding): Make symbolic reads
7144 from a cluster with concrete bindings return unknown.
7145
7146 2021-06-18 David Malcolm <dmalcolm@redhat.com>
7147
7148 * region-model-manager.cc
7149 (region_model_manager::get_or_create_int_cst): New.
7150 (region_model_manager::maybe_undo_optimize_bit_field_compare): Use
7151 it to simplify away a local tree.
7152 * region-model.cc (region_model::on_setjmp): Likewise.
7153 (region_model::on_longjmp): Likewise.
7154 * region-model.h (region_model_manager::get_or_create_int_cst):
7155 New decl.
7156 * store.cc (binding_cluster::zero_fill_region): Use it to simplify
7157 away a local tree.
7158
7159 2021-06-18 David Malcolm <dmalcolm@redhat.com>
7160
7161 * checker-path.cc (class custom_event): Make abstract to allow for
7162 custom vfuncs, splitting existing implementation into...
7163 (class precanned_custom_event): New subclass.
7164 (custom_event::get_desc): Move to...
7165 (precanned_custom_event::get_desc): ...subclass.
7166 * checker-path.h (class custom_event): Make abstract to allow for
7167 custom vfuncs, splitting existing implementation into...
7168 (class precanned_custom_event): New subclass.
7169 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
7170 Use precanned_custom_event.
7171 * engine.cc
7172 (stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise.
7173 * sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path):
7174 Likewise.
7175
7176 2021-06-15 David Malcolm <dmalcolm@redhat.com>
7177
7178 PR analyzer/99212
7179 PR analyzer/101082
7180 * engine.cc: Include "target.h".
7181 (impl_run_checkers): Log BITS_BIG_ENDIAN, BYTES_BIG_ENDIAN, and
7182 WORDS_BIG_ENDIAN.
7183 * region-model-manager.cc
7184 (region_model_manager::maybe_fold_binop): Move support for masking
7185 via ARG0 & CST into...
7186 (region_model_manager::maybe_undo_optimize_bit_field_compare):
7187 ...this new function. Flatten by converting from nested
7188 conditionals to a series of early return statements to reject
7189 failures. Reject if type is not unsigned_char_type_node.
7190 Handle BYTES_BIG_ENDIAN when determining which bits are bound
7191 in the binding_map.
7192 * region-model.h
7193 (region_model_manager::maybe_undo_optimize_bit_field_compare):
7194 New decl.
7195 * store.cc (bit_range::dump): New function.
7196 * store.h (bit_range::dump): New decl.
7197
7198 2021-06-15 David Malcolm <dmalcolm@redhat.com>
7199
7200 * engine.cc (exploded_node::on_stmt): Handle __analyzer_dump_capacity.
7201 (exploded_node::on_stmt): Drop m_sm_changes from on_stmt_flags.
7202 (state_change_requires_new_enode_p): New function...
7203 (exploded_graph::process_node): Call it, rather than querying
7204 flags.m_sm_changes, so that dynamic-extent differences can also
7205 trigger the splitting of nodes.
7206 * exploded-graph.h (struct on_stmt_flags): Drop field m_sm_changes.
7207 * program-state.cc (program_state::detect_leaks): Purge dead
7208 heap-allocated regions from dynamic extents.
7209 (selftest::test_program_state_1): Fix type of "size_in_bytes".
7210 (selftest::test_program_state_merging): Likewise.
7211 * region-model-impl-calls.cc
7212 (region_model::impl_call_analyzer_dump_capacity): New.
7213 (region_model::impl_call_free): Remove dynamic extents from the
7214 freed region.
7215 * region-model-reachability.h
7216 (reachable_regions::begin_mutable_base_regs): New.
7217 (reachable_regions::end_mutable_base_regs): New.
7218 * region-model.cc: Include "tree-object-size.h".
7219 (region_model::region_model): Support new field m_dynamic_extents.
7220 (region_model::operator=): Likewise.
7221 (region_model::operator==): Likewise.
7222 (region_model::dump_to_pp): Dump sizes of dynamic regions.
7223 (region_model::handle_unrecognized_call): Purge dynamic extents
7224 from any regions that have escaped mutably:.
7225 (region_model::get_capacity): New function.
7226 (region_model::add_constraint): Unset dynamic extents when a
7227 heap-allocated region's address is NULL.
7228 (region_model::unbind_region_and_descendents): Purge dynamic
7229 extents of unbound regions.
7230 (region_model::can_merge_with_p): Call
7231 m_dynamic_extents.can_merge_with_p.
7232 (region_model::create_region_for_heap_alloc): Assert that
7233 size_in_bytes's type is compatible with size_type_node. Update
7234 for renaming of record_dynamic_extents to set_dynamic_extents.
7235 (region_model::create_region_for_alloca): Likewise.
7236 (region_model::record_dynamic_extents): Rename to...
7237 (region_model::set_dynamic_extents): ...this. Assert that
7238 size_in_bytes's type is compatible with size_type_node. Add it
7239 to the m_dynamic_extents map.
7240 (region_model::get_dynamic_extents): New.
7241 (region_model::unset_dynamic_extents): New.
7242 (selftest::test_state_merging): Fix type of "size".
7243 (selftest::test_malloc_constraints): Likewise.
7244 (selftest::test_malloc): Verify dynamic extents.
7245 (selftest::test_alloca): Likewise.
7246 * region-model.h (region_to_value_map::is_empty): New.
7247 (region_model::dynamic_extents_t): New typedef.
7248 (region_model::impl_call_analyzer_dump_capacity): New decl.
7249 (region_model::get_dynamic_extents): New function.
7250 (region_model::get_dynamic_extents): New decl.
7251 (region_model::set_dynamic_extents): New decl.
7252 (region_model::unset_dynamic_extents): New decl.
7253 (region_model::get_capacity): New decl.
7254 (region_model::record_dynamic_extents): Rename to set_dynamic_extents.
7255 (region_model::m_dynamic_extents): New field.
7256
7257 2021-06-15 David Malcolm <dmalcolm@redhat.com>
7258
7259 * region-model.cc (region_to_value_map::operator=): New.
7260 (region_to_value_map::operator==): New.
7261 (region_to_value_map::dump_to_pp): New.
7262 (region_to_value_map::dump): New.
7263 (region_to_value_map::can_merge_with_p): New.
7264 * region-model.h (class region_to_value_map): New class.
7265
7266 2021-06-13 Trevor Saunders <tbsaunde@tbsaunde.org>
7267
7268 * call-string.cc (call_string::call_string): Use range based for
7269 to iterate over vec<>.
7270 (call_string::to_json): Likewise.
7271 (call_string::hash): Likewise.
7272 (call_string::calc_recursion_depth): Likewise.
7273 * checker-path.cc (checker_path::fixup_locations): Likewise.
7274 * constraint-manager.cc (equiv_class::equiv_class): Likewise.
7275 (equiv_class::to_json): Likewise.
7276 (equiv_class::hash): Likewise.
7277 (constraint_manager::to_json): Likewise.
7278 * engine.cc (impl_region_model_context::on_svalue_leak):
7279 Likewise.
7280 (on_liveness_change): Likewise.
7281 (impl_region_model_context::on_unknown_change): Likewise.
7282 * program-state.cc (sm_state_map::set_state): Likewise.
7283 * region-model.cc (test_canonicalization_4): Likewise.
7284
7285 2021-06-11 David Malcolm <dmalcolm@redhat.com>
7286
7287 * engine.cc (worklist::key_t::cmp): Move sort by call_string to
7288 before SCC.
7289
7290 2021-06-09 David Malcolm <dmalcolm@redhat.com>
7291
7292 * region-model.cc (region_model::get_lvalue_1): Make const.
7293 (region_model::get_lvalue): Likewise.
7294 (region_model::get_rvalue_1): Likewise.
7295 (region_model::get_rvalue): Likewise.
7296 (region_model::deref_rvalue): Likewise.
7297 (region_model::get_rvalue_for_bits): Likewise.
7298 * region-model.h (region_model::get_lvalue): Likewise.
7299 (region_model::get_rvalue): Likewise.
7300 (region_model::deref_rvalue): Likewise.
7301 (region_model::get_rvalue_for_bits): Likewise.
7302 (region_model::get_lvalue_1): Likewise.
7303 (region_model::get_rvalue_1): Likewise.
7304
7305 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7306
7307 PR analyzer/99212
7308 * region-model-manager.cc
7309 (region_model_manager::maybe_fold_binop): Add support for folding
7310 BIT_AND_EXPR of compound_svalue and a mask constant.
7311 * region-model.cc (region_model::get_rvalue_1): Implement
7312 BIT_FIELD_REF in terms of...
7313 (region_model::get_rvalue_for_bits): New function.
7314 * region-model.h (region_model::get_rvalue_for_bits): New decl.
7315 * store.cc (bit_range::from_mask): New function.
7316 (selftest::test_bit_range_intersects_p): New selftest.
7317 (selftest::assert_bit_range_from_mask_eq): New.
7318 (ASSERT_BIT_RANGE_FROM_MASK_EQ): New macro.
7319 (selftest::assert_no_bit_range_from_mask_eq): New.
7320 (ASSERT_NO_BIT_RANGE_FROM_MASK): New macro.
7321 (selftest::test_bit_range_from_mask): New selftest.
7322 (selftest::analyzer_store_cc_tests): Call the new selftests.
7323 * store.h (bit_range::intersects_p): New.
7324 (bit_range::from_mask): New decl.
7325 (concrete_binding::get_bit_range): New accessor.
7326 (store_manager::get_concrete_binding): New overload taking
7327 const bit_range &.
7328
7329 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7330
7331 * analyzer.h (int_size_in_bits): New decl.
7332 * region.cc (int_size_in_bits): New function.
7333 (region::get_bit_size): Reimplement in terms of the above.
7334
7335 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7336
7337 * store.cc (concrete_binding::dump_to_pp): Move bulk of
7338 implementation to...
7339 (bit_range::dump_to_pp): ...this new function.
7340 (bit_range::cmp): New.
7341 (concrete_binding::overlaps_p): Update for use of bit_range.
7342 (concrete_binding::cmp_ptr_ptr): Likewise.
7343 * store.h (struct bit_range): New.
7344 (class concrete_binding): Replace fields m_start_bit_offset and
7345 m_size_in_bits with new field m_bit_range.
7346
7347 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7348
7349 * svalue.h (conjured_svalue::iterator_t): Delete.
7350
7351 2021-06-03 David Malcolm <dmalcolm@redhat.com>
7352
7353 * store.h (store::get_direct_binding): Remove unused decl.
7354 (store::get_default_binding): Likewise.
7355
7356 2021-06-03 David Malcolm <dmalcolm@redhat.com>
7357
7358 * svalue.cc (poisoned_svalue::dump_to_pp): Dump type.
7359 (compound_svalue::dump_to_pp): Dump any type.
7360
7361 2021-05-18 David Malcolm <dmalcolm@redhat.com>
7362
7363 PR analyzer/100615
7364 * sm-malloc.cc: Include "analyzer/function-set.h".
7365 (malloc_state_machine::on_stmt): Call unaffected_by_call_p and
7366 bail on the functions it recognizes.
7367 (malloc_state_machine::unaffected_by_call_p): New.
7368
7369 2021-05-10 Martin Liska <mliska@suse.cz>
7370
7371 * sm-file.cc (is_file_using_fn_p): Use startswith
7372 function instead of strncmp.
7373
7374 2021-05-10 Martin Liska <mliska@suse.cz>
7375
7376 * program-state.cc (program_state::operator=): Remove
7377 __cplusplus >= 201103.
7378 (program_state::program_state): Likewise.
7379 * program-state.h: Likewise.
7380 * region-model.h (class region_model): Remove dead code.
7381
7382 2021-04-24 David Malcolm <dmalcolm@redhat.com>
7383
7384 PR analyzer/100244
7385 * sm-malloc.cc (free_of_non_heap::describe_state_change):
7386 Bulletproof against change.m_expr being NULL.
7387
7388 2021-04-13 David Malcolm <dmalcolm@redhat.com>
7389
7390 PR analyzer/98599
7391 * supergraph.cc (saved_uids::make_uid_unique): New.
7392 (saved_uids::restore_uids): New.
7393 (supergraph::supergraph): Replace assignments to stmt->uid with
7394 calls to m_stmt_uids.make_uid_unique.
7395 (supergraph::~supergraph): New.
7396 * supergraph.h (class saved_uids): New.
7397 (supergraph::~supergraph): New decl.
7398 (supergraph::m_stmt_uids): New field.
7399
7400 2021-04-10 David Malcolm <dmalcolm@redhat.com>
7401
7402 PR analyzer/100011
7403 * region-model.cc (region_model::on_assignment): Avoid NULL
7404 dereference if ctxt is NULL when assigning from a STRING_CST.
7405
7406 2021-04-08 David Malcolm <dmalcolm@redhat.com>
7407
7408 PR analyzer/99042
7409 PR analyzer/99774
7410 * engine.cc
7411 (impl_region_model_context::impl_region_model_context): Add
7412 uncertainty param and use it to initialize m_uncertainty.
7413 (impl_region_model_context::get_uncertainty): New.
7414 (impl_sm_context::get_fndecl_for_call): Add NULL for new
7415 uncertainty param when constructing impl_region_model_context.
7416 (impl_sm_context::get_state): Likewise.
7417 (impl_sm_context::set_next_state): Likewise.
7418 (impl_sm_context::warn): Likewise.
7419 (exploded_node::on_stmt): Add uncertainty param
7420 and use it when constructing impl_region_model_context.
7421 (exploded_node::on_edge): Add uncertainty param and pass
7422 to on_edge call.
7423 (exploded_node::detect_leaks): Create uncertainty_t and pass to
7424 impl_region_model_context.
7425 (exploded_graph::get_or_create_node): Create uncertainty_t and
7426 pass to prune_for_point.
7427 (maybe_process_run_of_before_supernode_enodes): Create
7428 uncertainty_t and pass to impl_region_model_context.
7429 (exploded_graph::process_node): Create uncertainty_t instances and
7430 pass around as needed.
7431 * exploded-graph.h
7432 (impl_region_model_context::impl_region_model_context): Add
7433 uncertainty param.
7434 (impl_region_model_context::get_uncertainty): New decl.
7435 (impl_region_model_context::m_uncertainty): New field.
7436 (exploded_node::on_stmt): Add uncertainty param.
7437 (exploded_node::on_edge): Likewise.
7438 * program-state.cc (sm_state_map::on_liveness_change): Get
7439 uncertainty from context and use it to unset sm-state from
7440 svalues as appropriate.
7441 (program_state::on_edge): Add uncertainty param and use it when
7442 constructing impl_region_model_context. Fix indentation.
7443 (program_state::prune_for_point): Add uncertainty param and use it
7444 when constructing impl_region_model_context.
7445 (program_state::detect_leaks): Get any uncertainty from ctxt and
7446 use it to get maybe-live svalues for dest_state, rather than
7447 definitely-live ones; use this when determining which svalues
7448 have leaked.
7449 (selftest::test_program_state_merging): Create uncertainty_t and
7450 pass to impl_region_model_context.
7451 * program-state.h (program_state::on_edge): Add uncertainty param.
7452 (program_state::prune_for_point): Likewise.
7453 * region-model-impl-calls.cc (call_details::get_uncertainty): New.
7454 (region_model::impl_call_memcpy): Pass uncertainty to
7455 mark_region_as_unknown call.
7456 (region_model::impl_call_memset): Likewise.
7457 (region_model::impl_call_strcpy): Likewise.
7458 * region-model-reachability.cc (reachable_regions::handle_sval):
7459 Also add sval to m_mutable_svals.
7460 * region-model.cc (region_model::on_assignment): Pass any
7461 uncertainty from ctxt to the store::set_value call.
7462 (region_model::handle_unrecognized_call): Get any uncertainty from
7463 ctxt and use it to record mutable svalues at the unknown call.
7464 (region_model::get_reachable_svalues): Add uncertainty param and
7465 use it to mark any maybe-bound svalues as being reachable.
7466 (region_model::set_value): Pass any uncertainty from ctxt to the
7467 store::set_value call.
7468 (region_model::mark_region_as_unknown): Add uncertainty param and
7469 pass it on to the store::mark_region_as_unknown call.
7470 (region_model::update_for_call_summary): Add uncertainty param and
7471 pass it on to the region_model::mark_region_as_unknown call.
7472 * region-model.h (call_details::get_uncertainty): New decl.
7473 (region_model::get_reachable_svalues): Add uncertainty param.
7474 (region_model::mark_region_as_unknown): Add uncertainty param.
7475 (region_model_context::get_uncertainty): New vfunc.
7476 (noop_region_model_context::get_uncertainty): New vfunc
7477 implementation.
7478 * store.cc (dump_svalue_set): New.
7479 (uncertainty_t::dump_to_pp): New.
7480 (uncertainty_t::dump): New.
7481 (binding_cluster::clobber_region): Pass NULL for uncertainty to
7482 remove_overlapping_bindings.
7483 (binding_cluster::mark_region_as_unknown): Add uncertainty param
7484 and pass it to remove_overlapping_bindings.
7485 (binding_cluster::remove_overlapping_bindings): Add uncertainty param.
7486 Use it to record any svalues that were in clobbered bindings.
7487 (store::set_value): Add uncertainty param. Pass it to
7488 binding_cluster::mark_region_as_unknown when handling symbolic
7489 regions.
7490 (store::mark_region_as_unknown): Add uncertainty param and pass it
7491 to binding_cluster::mark_region_as_unknown.
7492 (store::remove_overlapping_bindings): Add uncertainty param and
7493 pass it to binding_cluster::remove_overlapping_bindings.
7494 * store.h (binding_cluster::mark_region_as_unknown): Add
7495 uncertainty param.
7496 (binding_cluster::remove_overlapping_bindings): Likewise.
7497 (store::set_value): Likewise.
7498 (store::mark_region_as_unknown): Likewise.
7499
7500 2021-04-05 David Malcolm <dmalcolm@redhat.com>
7501
7502 PR analyzer/99906
7503 * analyzer.cc (maybe_reconstruct_from_def_stmt): Fix NULL
7504 dereference on calls with zero arguments.
7505 * sm-malloc.cc (malloc_state_machine::on_stmt): When handling
7506 __attribute__((nonnull)), only call get_diagnostic_tree if the
7507 result will be used.
7508
7509 2021-04-05 David Malcolm <dmalcolm@redhat.com>
7510
7511 PR analyzer/99886
7512 * diagnostic-manager.cc
7513 (diagnostic_manager::prune_interproc_events): Use signed integers
7514 when subtracting one from path->num_events ().
7515 (diagnostic_manager::consolidate_conditions): Likewise. Convert
7516 next_idx to a signed int.
7517
7518 2021-04-01 David Malcolm <dmalcolm@redhat.com>
7519
7520 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic): Make
7521 enode param non-constant, and call add_diagnostic on it. Add
7522 enode index to log message.
7523 (diagnostic_manager::add_diagnostic): Make enode param
7524 non-constant.
7525 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
7526 Likewise for both decls.
7527 * engine.cc
7528 (impl_region_model_context::impl_region_model_context): Likewise
7529 for enode_for_diag.
7530 (impl_sm_context::impl_sm_context): Likewise.
7531 (impl_sm_context::m_enode_for_diag): Likewise.
7532 (exploded_node::dump_dot): Don't pass the diagnostic manager
7533 to dump_saved_diagnostics.
7534 (exploded_node::dump_saved_diagnostics): Drop param. Iterate
7535 directly through all saved diagnostics for the enode, rather
7536 than all saved diagnostics in the diagnostic_manager and
7537 filtering.
7538 (exploded_node::on_stmt): Make non-const.
7539 (exploded_node::on_edge): Likewise.
7540 (exploded_node::on_longjmp): Likewise.
7541 (exploded_node::detect_leaks): Likewise.
7542 (exploded_graph::get_or_create_node): Make enode_for_diag param
7543 non-const.
7544 (exploded_graph_annotator::print_enode): Iterate
7545 directly through all saved diagnostics for the enode, rather
7546 than all saved diagnostics in the diagnostic_manager and
7547 filtering.
7548 * exploded-graph.h
7549 (impl_region_model_context::impl_region_model_context): Make
7550 enode_for_diag param non-constant.
7551 (impl_region_model_context::m_enode_for_diag): Likewise.
7552 (exploded_node::dump_saved_diagnostics): Drop param.
7553 (exploded_node::on_stmt): Make non-const.
7554 (exploded_node::on_edge): Likewise.
7555 (exploded_node::on_longjmp): Likewise.
7556 (exploded_node::detect_leaks): Likewise.
7557 (exploded_node::add_diagnostic): New.
7558 (exploded_node::get_num_diagnostics): New.
7559 (exploded_node::get_saved_diagnostic): New.
7560 (exploded_node::m_saved_diagnostics): New.
7561 (exploded_graph::get_or_create_node): Make enode_for_diag param
7562 non-constant.
7563 * feasible-graph.cc (feasible_node::dump_dot): Drop
7564 diagnostic_manager from call to dump_saved_diagnostics.
7565 * program-state.cc (program_state::on_edge): Convert enode param
7566 to non-const pointer.
7567 (program_state::prune_for_point): Likewise for enode_for_diag
7568 param.
7569 * program-state.h (program_state::on_edge): Convert enode param
7570 to non-const pointer.
7571 (program_state::prune_for_point): Likewise for enode_for_diag
7572 param.
7573
7574 2021-03-31 David Malcolm <dmalcolm@redhat.com>
7575
7576 PR analyzer/99771
7577 * analyzer.cc (maybe_reconstruct_from_def_stmt): New.
7578 (fixup_tree_for_diagnostic_1): New.
7579 (fixup_tree_for_diagnostic): New.
7580 * analyzer.h (fixup_tree_for_diagnostic): New decl.
7581 * checker-path.cc (call_event::get_desc): Call
7582 fixup_tree_for_diagnostic and use it for the call_with_state call.
7583 (warning_event::get_desc): Likewise for the final_event and
7584 make_label_text calls.
7585 * engine.cc (impl_region_model_context::on_state_leak): Likewise
7586 for the on_leak and add_diagnostic calls.
7587 * region-model.cc (region_model::get_representative_tree):
7588 Likewise for the result.
7589
7590 2021-03-30 David Malcolm <dmalcolm@redhat.com>
7591
7592 * region.h (region::dump_to_pp): Remove old decl.
7593
7594 2021-03-30 David Malcolm <dmalcolm@redhat.com>
7595
7596 * sm-file.cc (fileptr_state_machine::on_stmt): Only call
7597 get_diagnostic_tree if the result will be used.
7598 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
7599 (malloc_state_machine::on_deallocator_call): Likewise.
7600 (malloc_state_machine::on_realloc_call): Likewise.
7601 (malloc_state_machine::on_realloc_call): Likewise.
7602 * sm-sensitive.cc
7603 (sensitive_state_machine::warn_for_any_exposure): Likewise.
7604 * sm-taint.cc (taint_state_machine::on_stmt): Likewise.
7605
7606 2021-03-25 David Malcolm <dmalcolm@redhat.com>
7607
7608 PR analyzer/93695
7609 PR analyzer/99044
7610 PR analyzer/99716
7611 * engine.cc (exploded_node::on_stmt): Clear sm-state involving
7612 an SSA name at the def-stmt of that SSA name.
7613 * program-state.cc (sm_state_map::purge_state_involving): New.
7614 * program-state.h (sm_state_map::purge_state_involving): New decl.
7615 * region-model.cc (selftest::test_involves_p): New.
7616 (selftest::analyzer_region_model_cc_tests): Call it.
7617 * svalue.cc (class involvement_visitor): New class
7618 (svalue::involves_p): New.
7619 * svalue.h (svalue::involves_p): New decl.
7620
7621 2021-03-19 David Malcolm <dmalcolm@redhat.com>
7622
7623 PR analyzer/99614
7624 * diagnostic-manager.cc (class epath_finder): Add
7625 DISABLE_COPY_AND_ASSIGN.
7626
7627 2021-03-15 Martin Liska <mliska@suse.cz>
7628
7629 * sm-file.cc (get_file_using_fns): Add missing comma in initializer.
7630
7631 2021-03-11 David Malcolm <dmalcolm@redhat.com>
7632
7633 PR analyzer/96374
7634 * analyzer.opt (-param=analyzer-max-infeasible-edges=): New param.
7635 (fdump-analyzer-feasibility): New flag.
7636 * diagnostic-manager.cc: Include "analyzer/trimmed-graph.h" and
7637 "analyzer/feasible-graph.h".
7638 (epath_finder::epath_finder): Convert m_sep to a pointer and
7639 only create it if !flag_analyzer_feasibility.
7640 (epath_finder::~epath_finder): New.
7641 (epath_finder::m_sep): Convert to a pointer.
7642 (epath_finder::get_best_epath): Add param "diag_idx" and use it
7643 when logging. Rather than finding the shortest path and then
7644 checking feasibility, instead use explore_feasible_paths unless
7645 !flag_analyzer_feasibility, in which case simply use the shortest
7646 path, and note if it is infeasible. Update for m_sep becoming a
7647 pointer.
7648 (class feasible_worklist): New.
7649 (epath_finder::explore_feasible_paths): New.
7650 (epath_finder::process_worklist_item): New.
7651 (class dump_eg_with_shortest_path): New.
7652 (epath_finder::dump_trimmed_graph): New.
7653 (epath_finder::dump_feasible_graph): New.
7654 (saved_diagnostic::saved_diagnostic): Add "idx" param, using it
7655 on new field m_idx.
7656 (saved_diagnostic::to_json): Dump m_idx.
7657 (saved_diagnostic::calc_best_epath): Pass m_idx to get_best_epath.
7658 Remove assertion that m_problem was set when m_best_epath is NULL.
7659 (diagnostic_manager::add_diagnostic): Pass an index when created
7660 saved_diagnostic instances.
7661 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add
7662 "idx" param.
7663 (saved_diagnostic::get_index): New accessor.
7664 (saved_diagnostic::m_idx): New field.
7665 * engine.cc (exploded_node::dump_dot): Call args.dump_extra_info.
7666 Move code to...
7667 (exploded_node::dump_processed_stmts): ...this new function and...
7668 (exploded_node::dump_saved_diagnostics): ...this new function.
7669 Add index of each diagnostic.
7670 (exploded_edge::dump_dot): Move bulk of code to...
7671 (exploded_edge::dump_dot_label): ...this new function.
7672 * exploded-graph.h (eg_traits::dump_args_t::dump_extra_info): New
7673 vfunc.
7674 (exploded_node::dump_processed_stmts): New decl.
7675 (exploded_node::dump_saved_diagnostics): New decl.
7676 (exploded_edge::dump_dot_label): New decl.
7677 * feasible-graph.cc: New file.
7678 * feasible-graph.h: New file.
7679 * trimmed-graph.cc: New file.
7680 * trimmed-graph.h: New file.
7681
7682 2021-03-11 David Malcolm <dmalcolm@redhat.com>
7683
7684 * diagnostic-manager.cc (epath_finder::epath_finder):
7685 Update shortest_paths init for new param.
7686
7687 2021-03-10 David Malcolm <dmalcolm@redhat.com>
7688
7689 PR analyzer/96374
7690 * engine.cc (exploded_path::feasible_p): Move "snodes_visited" and
7691 "model" locals into a new class feasibility_state. Move heart
7692 of per-edge processing into
7693 feasibility_state::maybe_update_for_edge.
7694 (feasibility_state::feasibility_state): New.
7695 (feasibility_state::maybe_update_for_edge): New, based on loop
7696 body in exploded_path::feasible_p.
7697 * exploded-graph.h (class feasibility_state): New.
7698
7699 2021-03-10 David Malcolm <dmalcolm@redhat.com>
7700
7701 * supergraph.h
7702 (callgraph_superedge::dyn_cast_callgraph_superedge): New.
7703 (call_superedge::dyn_cast_callgraph_superedge): Delete.
7704 (return_superedge::dyn_cast_callgraph_superedge): Delete.
7705
7706 2021-03-02 Martin Liska <mliska@suse.cz>
7707
7708 * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostics):
7709 Do not pass engine.
7710
7711 2021-02-26 David Malcolm <dmalcolm@redhat.com>
7712
7713 * engine.cc (exploded_path::exploded_path): New copy-ctor.
7714 * exploded-graph.h (exploded_path::operator=): Drop decl.
7715
7716 2021-02-26 David Malcolm <dmalcolm@redhat.com>
7717
7718 PR analyzer/96374
7719 * diagnostic-manager.cc (class epath_finder): New.
7720 (epath_finder::get_best_epath): New.
7721 (saved_diagnostic::saved_diagnostic): Update for replacement of
7722 m_state and m_epath_length with m_best_epath.
7723 (saved_diagnostic::~saved_diagnostic): Delete m_best_epath.
7724 (saved_diagnostic::to_json): Update "path_length" to be optional.
7725 (saved_diagnostic::calc_best_epath): New, based on
7726 dedupe_winners::add and parts of dedupe_key::dedupe_key.
7727 (saved_diagnostic::get_epath_length): New.
7728 (saved_diagnostic::add_duplicate): New.
7729 (dedupe_key::dedupe_key): Drop epath param. Move invocation of
7730 stmt_finder to saved_diagnostic::calc_best_epath.
7731 (class dedupe_candidate): Delete.
7732 (class dedupe_hash_map_traits): Update to use saved_diagnotic *
7733 rather than dedupe_candidate * as the value_type/compare_type.
7734 (dedupe_winners::~dedupe_winners): Don't delete the values.
7735 (dedupe_winners::add): Convert param from shortest_exploded_paths to
7736 epath_finder. Drop "eg" param. Drop dedupe_candidate, moving
7737 path generation and feasiblity checking to
7738 epath_finder::get_best_epath. Update winner-selection for move
7739 of epaths from dedupe_candidate to saved_diagnostic.
7740 (dedupe_winners::emit_best): Update for removal of class
7741 dedupe_candidate.
7742 (dedupe_winners::map_t): Update to use saved_diagnotic * rather
7743 than dedupe_candidate * as the value_type/compare_type.
7744 (diagnostic_manager::emit_saved_diagnostics): Move
7745 shortest_exploded_paths instance into epath_finder and pass that
7746 around instead.
7747 (diagnostic_manager::emit_saved_diagnostic): Drop epath, stmt
7748 and num_dupes params, instead getting these from the
7749 saved_diagnostic. Use correct location in inform_n call.
7750 * diagnostic-manager.h (class epath_finder): New forward decl.
7751 (saved_diagnostic::status): Drop enum.
7752 (saved_diagnostic::set_feasible): Drop.
7753 (saved_diagnostic::set_infeasible): Drop.
7754 (saved_diagnostic::get_status): Drop.
7755 (saved_diagnostic::calc_best_epath): New decl.
7756 (saved_diagnostic::get_best_epath): New decl.
7757 (saved_diagnostic::get_epath_length): New decl.
7758 (saved_diagnostic::set_epath_length): Drop.
7759 (saved_diagnostic::get_epath_length): Drop inline implementation.
7760 (saved_diagnostic::add_duplicate): New.
7761 (saved_diagnostic::get_num_dupes): New.
7762 (saved_diagnostic::m_d): Document ownership.
7763 (saved_diagnostic::m_trailing_eedge): Make const.
7764 (saved_diagnostic::m_status): Drop field.
7765 (saved_diagnostic::m_epath_length): Drop field.
7766 (saved_diagnostic::m_best_epath): New field.
7767 (saved_diagnostic::m_problem): Document ownership.
7768 (saved_diagnostic::m_duplicates): New field.
7769 (diagnostic_manager::emit_saved_diagnostic): Drop params epath,
7770 stmt, and num_dupes.
7771 * engine.cc (exploded_graph_annotator::print_saved_diagnostic):
7772 Update for changes to saved_diagnostic class.
7773 * exploded-graph.h (exploded_path::feasible_p): Drop unused
7774 overloaded decl.
7775
7776 2021-02-25 David Malcolm <dmalcolm@redhat.com>
7777
7778 PR analyzer/99193
7779 * region-model-impl-calls.cc (region_model::impl_call_realloc): New.
7780 * region-model.cc (region_model::on_call_pre): Call it.
7781 * region-model.h (region_model::impl_call_realloc): New decl.
7782 * sm-malloc.cc (enum wording): Add WORDING_REALLOCATED.
7783 (malloc_state_machine::m_realloc): New field.
7784 (use_after_free::describe_state_change): Add case for
7785 WORDING_REALLOCATED.
7786 (use_after_free::describe_final_event): Likewise.
7787 (malloc_state_machine::malloc_state_machine): Initialize
7788 m_realloc.
7789 (malloc_state_machine::on_stmt): Handle realloc by calling...
7790 (malloc_state_machine::on_realloc_call): New.
7791
7792 2021-02-22 David Malcolm <dmalcolm@redhat.com>
7793
7794 PR analyzer/99196
7795 * engine.cc (exploded_node::on_stmt): Provide terminate_path
7796 flag as a way for on_call_pre to terminate the current analysis
7797 path.
7798 * region-model-impl-calls.cc (call_details::num_args): New.
7799 (region_model::impl_call_error): New.
7800 * region-model.cc (region_model::on_call_pre): Add param
7801 "out_terminate_path". Handle "error" and "error_at_line".
7802 * region-model.h (call_details::num_args): New decl.
7803 (region_model::on_call_pre): Add param "out_terminate_path".
7804 (region_model::impl_call_error): New decl.
7805
7806 2021-02-17 David Malcolm <dmalcolm@redhat.com>
7807
7808 PR analyzer/98969
7809 * constraint-manager.cc (dead_svalue_purger::should_purge_p):
7810 Update for change to svalue::live_p.
7811 * program-state.cc (sm_state_map::on_liveness_change): Likewise.
7812 (program_state::detect_leaks): Likewise.
7813 * region-model-reachability.cc (reachable_regions::init_cluster):
7814 When dealing with a symbolic region, if the underlying pointer is
7815 implicitly live, add the region to the reachable regions.
7816 * region-model.cc (region_model::compare_initial_and_pointer):
7817 Move logic for detecting initial values of params to
7818 initial_svalue::initial_value_of_param_p.
7819 * svalue.cc (svalue::live_p): Convert "live_svalues" from a
7820 reference to a pointer; support it being NULL.
7821 (svalue::implicitly_live_p): Convert first param from a
7822 refererence to a pointer.
7823 (region_svalue::implicitly_live_p): Likewise.
7824 (constant_svalue::implicitly_live_p): Likewise.
7825 (initial_svalue::implicitly_live_p): Likewise. Treat the initial
7826 values of params for the top level frame as still live.
7827 (initial_svalue::initial_value_of_param_p): New function, taken
7828 from a test in region_model::compare_initial_and_pointer.
7829 (unaryop_svalue::implicitly_live_p): Convert first param from a
7830 refererence to a pointer.
7831 (binop_svalue::implicitly_live_p): Likewise.
7832 (sub_svalue::implicitly_live_p): Likewise.
7833 (unmergeable_svalue::implicitly_live_p): Likewise.
7834 * svalue.h (svalue::live_p): Likewise.
7835 (svalue::implicitly_live_p): Likewise.
7836 (region_svalue::implicitly_live_p): Likewise.
7837 (constant_svalue::implicitly_live_p): Likewise.
7838 (initial_svalue::implicitly_live_p): Likewise.
7839 (initial_svalue::initial_value_of_param_p): New decl.
7840 (unaryop_svalue::implicitly_live_p): Convert first param from a
7841 refererence to a pointer.
7842 (binop_svalue::implicitly_live_p): Likewise.
7843 (sub_svalue::implicitly_live_p): Likewise.
7844 (unmergeable_svalue::implicitly_live_p): Likewise.
7845
7846 2021-02-12 David Malcolm <dmalcolm@redhat.com>
7847
7848 PR analyzer/98969
7849 * engine.cc (readability): Add names for the various arbitrary
7850 values. Handle NOP_EXPR and INTEGER_CST.
7851 (readability_comparator): Combine the readability tests for
7852 tree and stack depth, rather than performing them sequentially.
7853 (impl_region_model_context::on_state_leak): Strip off top-level
7854 casts.
7855 * region-model.cc (region_model::get_representative_path_var): Add
7856 type-checking, moving the bulk of the implementation to...
7857 (region_model::get_representative_path_var_1): ...here. Respect
7858 types in casts by recursing and re-adding the cast, rather than
7859 merely stripping them off. Use the correct type when handling
7860 region_svalue.
7861 (region_model::get_representative_tree): Strip off any top-level
7862 cast.
7863 (region_model::get_representative_path_var): Add type-checking,
7864 moving the bulk of the implementation to...
7865 (region_model::get_representative_path_var_1): ...here.
7866 * region-model.h (region_model::get_representative_path_var_1):
7867 New decl
7868 (region_model::get_representative_path_var_1): New decl.
7869 * store.cc (append_pathvar_with_type): New.
7870 (binding_cluster::get_representative_path_vars): Cast path_vars
7871 to the correct type when adding them to *OUT_PVS.
7872
7873 2021-02-09 David Malcolm <dmalcolm@redhat.com>
7874
7875 PR analyzer/98575
7876 * sm-file.cc (is_file_using_fn_p): Support "_IO_"-prefixed
7877 variants.
7878
7879 2021-02-09 David Malcolm <dmalcolm@redhat.com>
7880
7881 PR analyzer/98575
7882 * store.cc (store::set_value): Treat a pointer written to *UNKNOWN
7883 as having escaped.
7884
7885 2021-02-02 David Malcolm <dmalcolm@redhat.com>
7886
7887 PR analyzer/93355
7888 PR analyzer/96374
7889 * engine.cc (toplevel_function_p): Simplify so that
7890 we only reject functions with a "__analyzer_" prefix.
7891 (add_any_callbacks): Delete.
7892 (exploded_graph::build_initial_worklist): Update for
7893 dropped param of toplevel_function_p.
7894 (exploded_graph::build_initial_worklist): Don't bother
7895 looking for callbacks that are reachable from global
7896 initializers.
7897
7898 2021-02-01 David Malcolm <dmalcolm@redhat.com>
7899
7900 PR analyzer/98918
7901 * region-model-manager.cc
7902 (region_model_manager::get_or_create_initial_value):
7903 Fold the initial value of *UNKNOWN_PTR to an UNKNOWN value.
7904 (region_model_manager::get_field_region): Fold the value
7905 of UNKNOWN_PTR->FIELD to *UNKNOWN_PTR_OF_&FIELD_TYPE.
7906
7907 2021-01-29 David Malcolm <dmalcolm@redhat.com>
7908
7909 * checker-path.cc (event_kind_to_string): Handle
7910 EK_START_CONSOLIDATED_CFG_EDGES and
7911 EK_END_CONSOLIDATED_CFG_EDGES.
7912 (start_consolidated_cfg_edges_event::get_desc): New.
7913 (checker_path::cfg_edge_pair_at_p): New.
7914 * checker-path.h (enum event_kind): Add
7915 EK_START_CONSOLIDATED_CFG_EDGES and
7916 EK_END_CONSOLIDATED_CFG_EDGES.
7917 (class start_consolidated_cfg_edges_event): New class.
7918 (class end_consolidated_cfg_edges_event): New class.
7919 (checker_path::delete_events): New.
7920 (checker_path::replace_event): New.
7921 (checker_path::cfg_edge_pair_at_p): New decl.
7922 * diagnostic-manager.cc (diagnostic_manager::prune_path): Call
7923 consolidate_conditions.
7924 (same_line_as_p): New.
7925 (diagnostic_manager::consolidate_conditions): New.
7926 * diagnostic-manager.h
7927 (diagnostic_manager::consolidate_conditions): New decl.
7928
7929 2021-01-18 David Malcolm <dmalcolm@redhat.com>
7930
7931 * analyzer.h (is_std_named_call_p): New decl.
7932 * diagnostic-manager.cc (path_builder::get_sm): New.
7933 (state_change_event_creator::state_change_event_creator): Add "pb"
7934 param.
7935 (state_change_event_creator::on_global_state_change): Don't consider
7936 state changes affecting other state_machines.
7937 (state_change_event_creator::on_state_change): Likewise.
7938 (state_change_event_creator::m_pb): New field.
7939 (diagnostic_manager::add_events_for_eedge): Pass pb to visitor
7940 ctor.
7941 * region-model-impl-calls.cc
7942 (region_model::impl_deallocation_call): New.
7943 * region-model.cc: Include "attribs.h".
7944 (region_model::on_call_post): Handle fndecls referenced by
7945 __attribute__((deallocated_by(FOO))).
7946 * region-model.h (region_model::impl_deallocation_call): New decl.
7947 * sm-malloc.cc: Include "stringpool.h" and "attribs.h". Add
7948 leading comment.
7949 (class api): Delete.
7950 (enum resource_state): Update comment for change from api to
7951 deallocator and deallocator_set.
7952 (allocation_state::allocation_state): Drop api param. Add
7953 "deallocators" and "deallocator".
7954 (allocation_state::m_api): Drop field in favor of...
7955 (allocation_state::m_deallocators): New field.
7956 (allocation_state::m_deallocator): New field.
7957 (enum wording): Add WORDING_DEALLOCATED.
7958 (struct deallocator): New.
7959 (struct standard_deallocator): New.
7960 (struct custom_deallocator): New.
7961 (struct deallocator_set): New.
7962 (struct custom_deallocator_set): New.
7963 (struct standard_deallocator_set): New.
7964 (struct deallocator_set_map_traits): New.
7965 (malloc_state_machine::m_malloc): Drop field
7966 (malloc_state_machine::m_scalar_new): Likewise.
7967 (malloc_state_machine::m_vector_new): Likewise.
7968 (malloc_state_machine::m_free): New field
7969 (malloc_state_machine::m_scalar_delete): Likewise.
7970 (malloc_state_machine::m_vector_delete): Likewise.
7971 (malloc_state_machine::deallocator_map_t): New typedef.
7972 (malloc_state_machine::m_deallocator_map): New field.
7973 (malloc_state_machine::deallocator_set_cache_t): New typedef.
7974 (malloc_state_machine::m_custom_deallocator_set_cache): New field.
7975 (malloc_state_machine::custom_deallocator_set_map_t): New typedef.
7976 (malloc_state_machine::m_custom_deallocator_set_map): New field.
7977 (malloc_state_machine::m_dynamic_sets): New field.
7978 (malloc_state_machine::m_dynamic_deallocators): New field.
7979 (api::api): Delete.
7980 (deallocator::deallocator): New ctor.
7981 (deallocator::hash): New.
7982 (deallocator::dump_to_pp): New.
7983 (deallocator::cmp): New.
7984 (deallocator::cmp_ptr_ptr): New.
7985 (standard_deallocator::standard_deallocator): New ctor.
7986 (deallocator_set::deallocator_set): New ctor.
7987 (deallocator_set::dump): New.
7988 (custom_deallocator_set::custom_deallocator_set): New ctor.
7989 (custom_deallocator_set::contains_p): New.
7990 (custom_deallocator_set::maybe_get_single): New.
7991 (custom_deallocator_set::dump_to_pp): New.
7992 (standard_deallocator_set::standard_deallocator_set): New ctor.
7993 (standard_deallocator_set::contains_p): New.
7994 (standard_deallocator_set::maybe_get_single): New.
7995 (standard_deallocator_set::dump_to_pp): New.
7996 (start_p): New.
7997 (class mismatching_deallocation): Update for conversion from api
7998 to deallocator_set and deallocator.
7999 (double_free::emit): Use %qs.
8000 (class use_after_free): Update for conversion from api to
8001 deallocator_set and deallocator.
8002 (malloc_leak::describe_state_change): Only emit "allocated here" on
8003 a start->nonnull transition, rather than on other transitions to
8004 nonnull.
8005 (allocation_state::dump_to_pp): Update for conversion from api to
8006 deallocator_set.
8007 (allocation_state::get_nonnull): Likewise.
8008 (malloc_state_machine::malloc_state_machine): Likewise.
8009 (malloc_state_machine::~malloc_state_machine): New.
8010 (malloc_state_machine::add_state): Update for conversion from api
8011 to deallocator_set.
8012 (malloc_state_machine::get_or_create_custom_deallocator_set): New.
8013 (malloc_state_machine::maybe_create_custom_deallocator_set): New.
8014 (malloc_state_machine::get_or_create_deallocator): New.
8015 (malloc_state_machine::on_stmt): Update for conversion from api
8016 to deallocator_set. Handle "__attribute__((malloc(FOO)))", and
8017 the special attribute set on FOO.
8018 (malloc_state_machine::on_allocator_call): Update for conversion
8019 from api to deallocator_set. Add "returns_nonnull" param and use
8020 it to affect which state to transition to.
8021 (malloc_state_machine::on_deallocator_call): Update for conversion
8022 from api to deallocator_set.
8023
8024 2021-01-14 David Malcolm <dmalcolm@redhat.com>
8025
8026 * engine.cc (strongly_connected_components::to_json): New.
8027 (worklist::to_json): New.
8028 (exploded_graph::to_json): JSON-ify the worklist.
8029 * exploded-graph.h (strongly_connected_components::to_json): New
8030 decl.
8031 (worklist::to_json): New decl.
8032 * store.cc (store::to_json): Fix comment.
8033 * supergraph.cc (supernode::to_json): Fix reference to
8034 "returning_call" in comment. Add optional "fun" to JSON.
8035 (edge_kind_to_string): New.
8036 (superedge::to_json): Add "kind" to JSON.
8037
8038 2021-01-14 David Malcolm <dmalcolm@redhat.com>
8039
8040 PR analyzer/98679
8041 * analyzer.h (region_offset::operator==): Make const.
8042 * pending-diagnostic.h (pending_diagnostic::equal_p): Likewise.
8043 * store.h (binding_cluster::for_each_value): Likewise.
8044 (binding_cluster::for_each_binding): Likewise.
8045
8046 2021-01-12 David Malcolm <dmalcolm@redhat.com>
8047
8048 PR analyzer/98628
8049 * store.cc (binding_cluster::make_unknown_relative_to): Don't mark
8050 dereferenced unknown pointers as having escaped.
8051
8052 2021-01-07 David Malcolm <dmalcolm@redhat.com>
8053
8054 PR analyzer/98580
8055 * region.cc (decl_region::get_svalue_for_initializer): Gracefully
8056 handle when LTO writes out DECL_INITIAL as error_mark_node.
8057
8058 2021-01-07 David Malcolm <dmalcolm@redhat.com>
8059
8060 PR analyzer/97074
8061 * store.cc (binding_cluster::can_merge_p): Add "out_store" param
8062 and pass to calls to binding_cluster::make_unknown_relative_to.
8063 (binding_cluster::make_unknown_relative_to): Add "out_store"
8064 param. Use it to mark base regions that are pointed to by
8065 pointers that become unknown as having escaped.
8066 (store::can_merge_p): Pass out_store to
8067 binding_cluster::can_merge_p.
8068 * store.h (binding_cluster::can_merge_p): Add "out_store" param.
8069 (binding_cluster::make_unknown_relative_to): Likewise.
8070 * svalue.cc (region_svalue::implicitly_live_p): New vfunc.
8071 * svalue.h (region_svalue::implicitly_live_p): New vfunc decl.
8072
8073 2021-01-07 David Malcolm <dmalcolm@redhat.com>
8074
8075 PR analyzer/98564
8076 * engine.cc (exploded_path::feasible_p): Add missing call to
8077 bitmap_clear.
8078
8079 2021-01-06 David Malcolm <dmalcolm@redhat.com>
8080
8081 PR analyzer/97072
8082 * region-model-reachability.cc (reachable_regions::init_cluster):
8083 Convert symbolic region handling to a switch statement. Add cases
8084 to handle SK_UNKNOWN and SK_CONJURED.
8085
8086 2021-01-05 David Malcolm <dmalcolm@redhat.com>
8087
8088 PR analyzer/98293
8089 * store.cc (binding_map::apply_ctor_to_region): When "index" is
8090 NULL, iterate through the fields for RECORD_TYPEs, rather than
8091 creating an INTEGER_CST index.
8092
8093 2020-11-30 David Malcolm <dmalcolm@redhat.com>
8094
8095 * analyzer-pass.cc: Include "analyzer/analyzer.h" for the
8096 declaration of sorry_no_analyzer; include "tree.h" and
8097 "function.h" as these are needed by it.
8098
8099 2020-11-30 David Malcolm <dmalcolm@redhat.com>
8100
8101 * analyzer-pass.cc (pass_analyzer::execute): Move sorry call to...
8102 (sorry_no_analyzer): New.
8103 * analyzer.h (class state_machine): New forward decl.
8104 (class logger): New forward decl.
8105 (class plugin_analyzer_init_iface): New.
8106 (sorry_no_analyzer): New decl.
8107 * checker-path.cc (checker_path::fixup_locations): New.
8108 * checker-path.h (checker_event::set_location): New.
8109 (checker_path::fixup_locations): New decl.
8110 * diagnostic-manager.cc
8111 (diagnostic_manager::emit_saved_diagnostic): Call
8112 checker_path::fixup_locations, and call fixup_location
8113 on the primary location.
8114 * engine.cc: Include "plugin.h".
8115 (class plugin_analyzer_init_impl): New.
8116 (impl_run_checkers): Invoke PLUGIN_ANALYZER_INIT callbacks.
8117 * pending-diagnostic.h (pending_diagnostic::fixup_location): New
8118 vfunc.
8119
8120 2020-11-18 David Malcolm <dmalcolm@redhat.com>
8121
8122 PR analyzer/97893
8123 * sm-malloc.cc (null_deref::emit): Use CWE-476 rather than
8124 CWE-690, as this isn't due to an unchecked return value.
8125 (null_arg::emit): Likewise.
8126
8127 2020-11-12 David Malcolm <dmalcolm@redhat.com>
8128
8129 * checker-path.h (checker_event::get_id_ptr): New.
8130 * diagnostic-manager.cc (path_builder::path_builder): Add "sd"
8131 param and use it to initialize new field "m_sd".
8132 (path_builder::get_pending_diagnostic): New.
8133 (path_builder::m_sd): New field.
8134 (diagnostic_manager::emit_saved_diagnostic): Pass sd to
8135 path_builder ctor.
8136 (diagnostic_manager::add_events_for_superedge): Call new
8137 maybe_add_custom_events_for_superedge vfunc.
8138 * engine.cc (stale_jmp_buf::stale_jmp_buf): Add "setjmp_point"
8139 param and use it to initialize new field "m_setjmp_point".
8140 Initialize new field "m_stack_pop_event".
8141 (stale_jmp_buf::maybe_add_custom_events_for_superedge): New vfunc
8142 implementation.
8143 (stale_jmp_buf::describe_final_event): New vfunc implementation.
8144 (stale_jmp_buf::m_setjmp_point): New field.
8145 (stale_jmp_buf::m_stack_pop_event): New field.
8146 (exploded_node::on_longjmp): Pass setjmp_point to stale_jmp_buf
8147 ctor.
8148 * pending-diagnostic.h
8149 (pending_diagnostic::maybe_add_custom_events_for_superedge): New
8150 vfunc.
8151
8152 2020-11-12 David Malcolm <dmalcolm@redhat.com>
8153
8154 PR tree-optimization/97424
8155 * analyzer.opt (Wanalyzer-shift-count-negative): New.
8156 (Wanalyzer-shift-count-overflow): New.
8157 * region-model.cc (class shift_count_negative_diagnostic): New.
8158 (class shift_count_overflow_diagnostic): New.
8159 (region_model::get_gassign_result): Complain about shift counts that
8160 are negative or are >= the operand's type's width.
8161
8162 2020-11-10 Martin Liska <mliska@suse.cz>
8163
8164 * constraint-manager.cc (constraint_manager::merge): Remove
8165 unused code.
8166 * constraint-manager.h: Likewise.
8167 * program-state.cc (sm_state_map::sm_state_map): Likewise.
8168 (program_state::program_state): Likewise.
8169 (test_sm_state_map): Likewise.
8170 * program-state.h: Likewise.
8171 * region-model-reachability.cc (reachable_regions::reachable_regions): Likewise.
8172 * region-model-reachability.h: Likewise.
8173 * region-model.cc (region_model::handle_unrecognized_call): Likewise.
8174 (region_model::get_reachable_svalues): Likewise.
8175 (region_model::can_merge_with_p): Likewise.
8176
8177 2020-11-05 David Malcolm <dmalcolm@redhat.com>
8178
8179 PR analyzer/97668
8180 * svalue.cc (cmp_cst): Handle COMPLEX_CST.
8181
8182 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8183
8184 * program-state.cc (sm_state_map::on_liveness_change): Sort the
8185 leaking svalues before calling on_state_leak.
8186 (program_state::detect_leaks): Likewise when calling
8187 on_svalue_leak.
8188 * region-model-reachability.cc
8189 (reachable_regions::mark_escaped_clusters): Likewise when
8190 calling on_escaped_function.
8191
8192 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8193
8194 PR analyzer/97608
8195 * region-model-reachability.cc (reachable_regions::handle_sval):
8196 Operands of reachable reversible operations are reachable.
8197
8198 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8199
8200 * analyzer.h (class state_machine): New forward decl.
8201 (class logger): Likewise.
8202 (class visitor): Likewise.
8203 * complexity.cc: New file, taken from svalue.cc.
8204 * complexity.h: New file, taken from region-model.h.
8205 * region-model.h: Include "analyzer/svalue.h" and
8206 "analyzer/region.h". Move struct complexity to complexity.h.
8207 Move svalue, its subclasses and supporting decls to svalue.h.
8208 Move region, its subclasses and supporting decls to region.h.
8209 * region.cc: Include "analyzer/region.h".
8210 (symbolic_region::symbolic_region): Move here from region-model.h.
8211 * region.h: New file, based on material from region-model.h.
8212 * svalue.cc: Include "analyzer/svalue.h".
8213 (complexity::complexity): Move to complexity.cc.
8214 (complexity::from_pair): Likewise.
8215 * svalue.h: New file, based on material from region-model.h.
8216
8217 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8218
8219 * program-state.cc (sm_state_map::print): Guard the printing of
8220 the origin pointer with !flag_dump_noaddr.
8221 * region.cc (string_region::dump_to_pp): Likewise for
8222 m_string_cst.
8223
8224 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8225
8226 PR analyzer/97568
8227 * region-model.cc (region_model::get_initial_value_for_global):
8228 Move check that !DECL_EXTERNAL from here to...
8229 * region.cc (decl_region::get_svalue_for_initializer): ...here,
8230 using it to reject zero initialization.
8231
8232 2020-10-27 Markus Böck <markus.boeck02@gmail.com>
8233
8234 PR analyzer/96608
8235 * store.h (hash): Cast to intptr_t instead of long
8236
8237 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8238
8239 * constraint-manager.cc (svalue_cmp_by_ptr): Delete.
8240 (equiv_class::canonicalize): Use svalue::cmp_ptr_ptr instead.
8241 (equiv_class_cmp): Eliminate pointer comparison.
8242 * diagnostic-manager.cc (dedupe_key::comparator): If they are at
8243 the same location, also compare epath ength and pending_diagnostic
8244 kind.
8245 * engine.cc (readability_comparator): If two path_vars have the
8246 same readability, then impose an arbitrary ordering on them.
8247 (worklist::key_t::cmp): If two points have the same plan ordering,
8248 continue the comparison. Call sm_state_map::cmp rather than
8249 comparing hash values.
8250 * program-state.cc (sm_state_map::entry_t::cmp): New.
8251 (sm_state_map::cmp): New.
8252 * program-state.h (sm_state_map::entry_t::cmp): New decl.
8253 (sm_state_map::elements): New.
8254 (sm_state_map::cmp): New.
8255
8256 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8257
8258 * engine.cc (setjmp_record::cmp): New.
8259 (supernode_cluster::dump_dot): Avoid embedding pointer in cluster
8260 name.
8261 (supernode_cluster::cmp_ptr_ptr): New.
8262 (function_call_string_cluster::dump_dot): Avoid embedding pointer
8263 in cluster name. Sort m_map when dumping child clusters.
8264 (function_call_string_cluster::cmp_ptr_ptr): New.
8265 (root_cluster::dump_dot): Sort m_map when dumping child clusters.
8266 * program-point.cc (function_point::cmp): New.
8267 (function_point::cmp_ptr): New.
8268 * program-point.h (function_point::cmp): New decl.
8269 (function_point::cmp_ptr): New decl.
8270 * program-state.cc (sm_state_map::print): Sort the values. Guard
8271 the printing of pointers with !flag_dump_noaddr.
8272 (program_state::prune_for_point): Sort the regions.
8273 (log_set_of_svalues): Sort the values. Guard the printing of
8274 pointers with !flag_dump_noaddr.
8275 * region-model-manager.cc (log_uniq_map): Sort the values.
8276 * region-model-reachability.cc (dump_set): New function template.
8277 (reachable_regions::dump_to_pp): Use it.
8278 * region-model.h (svalue::cmp_ptr): New decl.
8279 (svalue::cmp_ptr_ptr): New decl.
8280 (setjmp_record::cmp): New decl.
8281 (placeholder_svalue::get_name): New accessor.
8282 (widening_svalue::get_point): New accessor.
8283 (compound_svalue::get_map): New accessor.
8284 (conjured_svalue::get_stmt): New accessor.
8285 (conjured_svalue::get_id_region): New accessor.
8286 (region::cmp_ptrs): Rename to...
8287 (region::cmp_ptr_ptr): ...this.
8288 * region.cc (region::cmp_ptrs): Rename to...
8289 (region::cmp_ptr_ptr): ...this.
8290 * state-purge.cc
8291 (state_purge_per_ssa_name::state_purge_per_ssa_name): Sort
8292 m_points_needing_name when dumping.
8293 * store.cc (concrete_binding::cmp_ptr_ptr): New.
8294 (symbolic_binding::cmp_ptr_ptr): New.
8295 (binding_map::cmp): New.
8296 (get_sorted_parent_regions): Update for renaming of
8297 region::cmp_ptrs to region::cmp_ptr_ptr.
8298 (store::dump_to_pp): Likewise.
8299 (store::to_json): Likewise.
8300 (store::can_merge_p): Sort the base regions before considering
8301 them.
8302 * store.h (concrete_binding::cmp_ptr_ptr): New decl.
8303 (symbolic_binding::cmp_ptr_ptr): New decl.
8304 (binding_map::cmp): New decl.
8305 * supergraph.cc (supergraph::supergraph): Assign UIDs to the
8306 gimple stmts.
8307 * svalue.cc (cmp_cst): New.
8308 (svalue::cmp_ptr): New.
8309 (svalue::cmp_ptr_ptr): New.
8310
8311 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8312
8313 * engine.cc (exploded_graph::get_or_create_node): Fix off-by-one
8314 when imposing param_analyzer_max_enodes_per_program_point limit.
8315
8316 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8317
8318 * region-model.cc (region_model::get_representative_path_var):
8319 Implement case RK_LABEL.
8320 * region-model.h (label_region::get_label): New accessor.
8321
8322 2020-10-22 David Malcolm <dmalcolm@redhat.com>
8323
8324 PR analyzer/97514
8325 * engine.cc (exploded_graph::add_function_entry): Handle failure
8326 to create an enode, rather than asserting.
8327
8328 2020-10-22 David Malcolm <dmalcolm@redhat.com>
8329
8330 PR analyzer/97489
8331 * engine.cc (exploded_graph::add_function_entry): Assert that we
8332 have a function body.
8333 (exploded_graph::on_escaped_function): Reject fndecls that don't
8334 have a function body.
8335
8336 2020-10-14 David Malcolm <dmalcolm@redhat.com>
8337
8338 PR analyzer/93388
8339 * region-model.cc (region_model::get_initial_value_for_global):
8340 Fall back to returning an initial_svalue if
8341 decl_region::get_svalue_for_initializer fails.
8342 * region.cc (decl_region::get_svalue_for_initializer): Don't
8343 attempt to create a compound_svalue if the region has an unknown
8344 size.
8345
8346 2020-10-14 David Malcolm <dmalcolm@redhat.com>
8347
8348 PR analyzer/93723
8349 * store.cc (binding_map::apply_ctor_to_region): Remove redundant
8350 assertion.
8351
8352 2020-10-12 David Malcolm <dmalcolm@redhat.com>
8353
8354 PR analyzer/97258
8355 * engine.cc (impl_region_model_context::on_escaped_function): New
8356 vfunc.
8357 (exploded_graph::add_function_entry): Use m_functions_with_enodes
8358 to implement idempotency.
8359 (add_any_callbacks): New.
8360 (exploded_graph::build_initial_worklist): Use the above to find
8361 callbacks that are reachable from global initializers.
8362 (exploded_graph::on_escaped_function): New.
8363 * exploded-graph.h
8364 (impl_region_model_context::on_escaped_function): New decl.
8365 (exploded_graph::on_escaped_function): New decl.
8366 (exploded_graph::m_functions_with_enodes): New field.
8367 * region-model-reachability.cc
8368 (reachable_regions::reachable_regions): Replace "store" param with
8369 "model" param; use it to initialize m_model.
8370 (reachable_regions::add): When getting the svalue for the region,
8371 call get_store_value on the model rather than using an initial
8372 value.
8373 (reachable_regions::mark_escaped_clusters): Add ctxt param and
8374 use it to call on_escaped_function when a function_region escapes.
8375 * region-model-reachability.h
8376 (reachable_regions::reachable_regions): Replace "store" param with
8377 "model" param.
8378 (reachable_regions::mark_escaped_clusters): Add ctxt param.
8379 (reachable_regions::m_model): New field.
8380 * region-model.cc (region_model::handle_unrecognized_call): Update
8381 for change in reachable_regions ctor.
8382 (region_model::handle_unrecognized_call): Pass ctxt to
8383 mark_escaped_clusters.
8384 (region_model::get_reachable_svalues): Update for change in
8385 reachable_regions ctor.
8386 (region_model::get_initial_value_for_global): Read-only variables
8387 keep their initial values.
8388 * region-model.h (region_model_context::on_escaped_function): New
8389 vfunc.
8390 (noop_region_model_context::on_escaped_function): New.
8391
8392 2020-10-12 David Malcolm <dmalcolm@redhat.com>
8393
8394 * analyzer.opt (Wanalyzer-write-to-const): New.
8395 (Wanalyzer-write-to-string-literal): New.
8396 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8397 Call check_for_writable_region.
8398 (region_model::impl_call_memset): Likewise.
8399 (region_model::impl_call_strcpy): Likewise.
8400 * region-model.cc (class write_to_const_diagnostic): New.
8401 (class write_to_string_literal_diagnostic): New.
8402 (region_model::check_for_writable_region): New.
8403 (region_model::set_value): Call check_for_writable_region.
8404 * region-model.h (region_model::check_for_writable_region): New
8405 decl.
8406
8407 2020-10-07 David Malcolm <dmalcolm@redhat.com>
8408
8409 PR analyzer/97116
8410 * sm-malloc.cc (method_p): New.
8411 (describe_argument_index): New.
8412 (inform_nonnull_attribute): Use describe_argument_index.
8413 (possible_null_arg::describe_final_event): Likewise.
8414 (null_arg::describe_final_event): Likewise.
8415
8416 2020-09-29 David Malcolm <dmalcolm@redhat.com>
8417
8418 PR analyzer/95188
8419 * engine.cc (stmt_requires_new_enode_p): Split enodes before
8420 "signal" calls.
8421
8422 2020-09-29 David Malcolm <dmalcolm@redhat.com>
8423
8424 * constraint-manager.cc
8425 (constraint_manager::add_constraint_internal): Whitespace fixes.
8426 Silence -Wsign-compare warning.
8427 * engine.cc (maybe_process_run_of_before_supernode_enodes):
8428 Silence -Wsign-compare warning.
8429
8430 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8431
8432 * region-model.h (binop_svalue::dyn_cast_binop_svalue): Remove
8433 redundant "virtual". Add FINAL OVERRIDE.
8434 (widening_svalue::dyn_cast_widening_svalue): Add FINAL OVERRIDE.
8435 (compound_svalue::dyn_cast_compound_svalue): Likewise.
8436 (conjured_svalue::dyn_cast_conjured_svalue): Likewise.
8437
8438 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8439
8440 * diagnostic-manager.cc (null_assignment_sm_context::m_visitor):
8441 Remove unused field.
8442
8443 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8444
8445 PR analyzer/97233
8446 * analyzer.cc (is_longjmp_call_p): Require the initial argument
8447 to be a pointer.
8448 * engine.cc (exploded_node::on_longjmp): Likewise.
8449
8450 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8451
8452 * program-state.cc (sm_state_map::print): Update check
8453 for m_global_state being the start state.
8454
8455 2020-09-26 David Malcolm <dmalcolm@redhat.com>
8456
8457 PR analyzer/96646
8458 PR analyzer/96841
8459 * region-model.cc (region_model::get_representative_path_var):
8460 When handling offset_region, wrap the MEM_REF's first argument in
8461 an ADDR_EXPR of pointer type, rather than simply using the tree
8462 for the parent region. Require the MEM_REF's second argument to
8463 be an integer constant.
8464
8465 2020-09-24 David Malcolm <dmalcolm@redhat.com>
8466
8467 * analyzer.h (struct rejected_constraint): New decl.
8468 * analyzer.opt (fanalyzer-feasibility): New option.
8469 * diagnostic-manager.cc (path_builder::path_builder): Add
8470 "problem" param and use it to initialize new field.
8471 (path_builder::get_feasibility_problem): New accessor.
8472 (path_builder::m_feasibility_problem): New field.
8473 (dedupe_winners::add): Remove inversion of logic in "if" clause,
8474 swapping if/else suites. In the !feasible_p suite, inspect
8475 flag_analyzer_feasibility and add code to handle when this
8476 is off, accepting the infeasible path, but recording the
8477 feasibility_problem.
8478 (diagnostic_manager::emit_saved_diagnostic): Pass the
8479 feasibility_problem to the path_builder.
8480 (diagnostic_manager::add_events_for_eedge): If we have
8481 a feasibility_problem at this edge, use it to add a custom event.
8482 * engine.cc (exploded_path::feasible_p): Pass a
8483 rejected_constraint ** to model.maybe_update_for_edge and transfer
8484 ownership of any created instance to any feasibility_problem.
8485 (feasibility_problem::dump_to_pp): New.
8486 * exploded-graph.h (feasibility_problem::feasibility_problem):
8487 Drop "model" param; add rejected_constraint * param.
8488 (feasibility_problem::~feasibility_problem): New.
8489 (feasibility_problem::dump_to_pp): New decl.
8490 (feasibility_problem::m_model): Drop field.
8491 (feasibility_problem::m_rc): New field.
8492 * program-point.cc (function_point::get_location): Handle
8493 PK_BEFORE_SUPERNODE and PK_AFTER_SUPERNODE.
8494 * program-state.cc (program_state::on_edge): Pass NULL to new
8495 param of region_model::maybe_update_for_edge.
8496 * region-model.cc (region_model::add_constraint): New overload
8497 adding a rejected_constraint ** param.
8498 (region_model::maybe_update_for_edge): Add rejected_constraint **
8499 param and pass it to the various apply_constraints_for_ calls.
8500 (region_model::apply_constraints_for_gcond): Add
8501 rejected_constraint ** param and pass it to add_constraint calls.
8502 (region_model::apply_constraints_for_gswitch): Likewise.
8503 (region_model::apply_constraints_for_exception): Likewise.
8504 (rejected_constraint::dump_to_pp): New.
8505 * region-model.h (region_model::maybe_update_for_edge):
8506 Add rejected_constraint ** param.
8507 (region_model::add_constraint): New overload adding a
8508 rejected_constraint ** param.
8509 (region_model::apply_constraints_for_gcond): Add
8510 rejected_constraint ** param.
8511 (region_model::apply_constraints_for_gswitch): Likewise.
8512 (region_model::apply_constraints_for_exception): Likewise.
8513 (struct rejected_constraint): New.
8514
8515 2020-09-23 David Malcolm <dmalcolm@redhat.com>
8516
8517 PR analyzer/97178
8518 * engine.cc (impl_run_checkers): Update for change to ext_state
8519 ctor.
8520 * program-state.cc (selftest::test_sm_state_map): Pass an engine
8521 instance to ext_state ctor.
8522 (selftest::test_program_state_1): Likewise.
8523 (selftest::test_program_state_2): Likewise.
8524 (selftest::test_program_state_merging): Likewise.
8525 (selftest::test_program_state_merging_2): Likewise.
8526 * program-state.h (extrinsic_state::extrinsic_state): Remove NULL
8527 default value for "eng" param.
8528
8529 2020-09-23 Tobias Burnus <tobias@codesourcery.com>
8530
8531 * analyzer-logging.cc: Guard '#pragma ... ignored "-Wformat-diag"'
8532 by '#if __GNUC__ >= 10'
8533 * analyzer.h: Likewise.
8534 * call-string.cc: Likewise.
8535
8536 2020-09-23 David Malcolm <dmalcolm@redhat.com>
8537
8538 * engine.cc (exploded_node::on_stmt): Replace sequence of dyn_cast
8539 with switch.
8540
8541 2020-09-22 David Malcolm <dmalcolm@redhat.com>
8542
8543 * analysis-plan.cc: Include "json.h".
8544 * analyzer.opt (fdump-analyzer-json): New.
8545 * call-string.cc: Include "json.h".
8546 (call_string::to_json): New.
8547 * call-string.h (call_string::to_json): New decl.
8548 * checker-path.cc: Include "json.h".
8549 * constraint-manager.cc: Include "json.h".
8550 (equiv_class::to_json): New.
8551 (constraint::to_json): New.
8552 (constraint_manager::to_json): New.
8553 * constraint-manager.h (equiv_class::to_json): New decl.
8554 (constraint::to_json): New decl.
8555 (constraint_manager::to_json): New decl.
8556 * diagnostic-manager.cc: Include "json.h".
8557 (saved_diagnostic::to_json): New.
8558 (diagnostic_manager::to_json): New.
8559 * diagnostic-manager.h (saved_diagnostic::to_json): New decl.
8560 (diagnostic_manager::to_json): New decl.
8561 * engine.cc: Include "json.h", <zlib.h>.
8562 (exploded_node::status_to_str): New.
8563 (exploded_node::to_json): New.
8564 (exploded_edge::to_json): New.
8565 (exploded_graph::to_json): New.
8566 (dump_analyzer_json): New.
8567 (impl_run_checkers): Call it.
8568 * exploded-graph.h (exploded_node::status_to_str): New decl.
8569 (exploded_node::to_json): New.
8570 (exploded_edge::to_json): New.
8571 (exploded_graph::to_json): New.
8572 * pending-diagnostic.cc: Include "json.h".
8573 * program-point.cc: Include "json.h".
8574 (program_point::to_json): New.
8575 * program-point.h (program_point::to_json): New decl.
8576 * program-state.cc: Include "json.h".
8577 (extrinsic_state::to_json): New.
8578 (sm_state_map::to_json): New.
8579 (program_state::to_json): New.
8580 * program-state.h (extrinsic_state::to_json): New decl.
8581 (sm_state_map::to_json): New decl.
8582 (program_state::to_json): New decl.
8583 * region-model-impl-calls.cc: Include "json.h".
8584 * region-model-manager.cc: Include "json.h".
8585 * region-model-reachability.cc: Include "json.h".
8586 * region-model.cc: Include "json.h".
8587 * region-model.h (svalue::to_json): New decl.
8588 (region::to_json): New decl.
8589 * region.cc: Include "json.h".
8590 (region::to_json: New.
8591 * sm-file.cc: Include "json.h".
8592 * sm-malloc.cc: Include "json.h".
8593 * sm-pattern-test.cc: Include "json.h".
8594 * sm-sensitive.cc: Include "json.h".
8595 * sm-signal.cc: Include "json.h".
8596 (signal_delivery_edge_info_t::to_json): New.
8597 * sm-taint.cc: Include "json.h".
8598 * sm.cc: Include "diagnostic.h", "tree-diagnostic.h", and
8599 "json.h".
8600 (state_machine::state::to_json): New.
8601 (state_machine::to_json): New.
8602 * sm.h (state_machine::state::to_json): New.
8603 (state_machine::to_json): New.
8604 * state-purge.cc: Include "json.h".
8605 * store.cc: Include "json.h".
8606 (binding_key::get_desc): New.
8607 (binding_map::to_json): New.
8608 (binding_cluster::to_json): New.
8609 (store::to_json): New.
8610 * store.h (binding_key::get_desc): New decl.
8611 (binding_map::to_json): New decl.
8612 (binding_cluster::to_json): New decl.
8613 (store::to_json): New decl.
8614 * supergraph.cc: Include "json.h".
8615 (supergraph::to_json): New.
8616 (supernode::to_json): New.
8617 (superedge::to_json): New.
8618 * supergraph.h (supergraph::to_json): New decl.
8619 (supernode::to_json): New decl.
8620 (superedge::to_json): New decl.
8621 * svalue.cc: Include "json.h".
8622 (svalue::to_json): New.
8623
8624 2020-09-21 David Malcolm <dmalcolm@redhat.com>
8625
8626 PR analyzer/97130
8627 * region-model-impl-calls.cc (call_details::get_arg_type): New.
8628 * region-model.cc (region_model::on_call_pre): Check that the
8629 initial arg is a pointer before calling impl_call_memset and
8630 impl_call_strlen.
8631 * region-model.h (call_details::get_arg_type): New decl.
8632
8633 2020-09-21 David Malcolm <dmalcolm@redhat.com>
8634
8635 PR analyzer/93355
8636 * sm-malloc.cc (malloc_state_machine::get_default_state): Look at
8637 the base region when considering pointers. Treat pointers to
8638 decls as being non-heap.
8639
8640 2020-09-18 David Malcolm <dmalcolm@redhat.com>
8641
8642 * checker-path.cc (warning_event::get_desc): Handle global state
8643 changes.
8644
8645 2020-09-18 David Malcolm <dmalcolm@redhat.com>
8646
8647 * sm-malloc.cc (malloc_state_machine::on_stmt): Handle strdup and
8648 strndup as being malloc-like allocators.
8649
8650 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8651
8652 * engine.cc (strongly_connected_components::strong_connect): Only
8653 consider intraprocedural edges when creating SCCs.
8654 (worklist::key_t::cmp): Add comment. Treat call_string
8655 differences as more important than differences of program_point
8656 within a supernode.
8657
8658 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8659
8660 * engine.cc (supernode_cluster::dump_dot): Show the SCC id
8661 in the per-supernode clusters in FILENAME.eg.dot output.
8662 (exploded_graph_annotator::add_node_annotations):
8663 Show the SCC of the supernode in FILENAME.supernode.eg.dot output.
8664 * exploded-graph.h (worklist::scc_id): New.
8665 (exploded_graph::get_scc_id): New.
8666
8667 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8668
8669 * engine.cc (exploded_node::dump_dot): Show STATUS_BULK_MERGED.
8670 (exploded_graph::process_worklist): Call
8671 maybe_process_run_of_before_supernode_enodes.
8672 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
8673 New.
8674 (exploded_graph_annotator::print_enode): Show STATUS_BULK_MERGED.
8675 * exploded-graph.h (enum exploded_node::status): Add
8676 STATUS_BULK_MERGED.
8677
8678 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8679
8680 * engine.cc
8681 (exploded_graph::process_node) <case PK_BEFORE_SUPERNODE>:
8682 Simplify by using program_point::get_next.
8683 * program-point.cc (program_point::get_next): New.
8684 * program-point.h (program_point::get_next): New decl.
8685
8686 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8687
8688 * engine.cc (exploded_graph::get_or_create_node): Show the
8689 program point when issuing -Wanalyzer-too-complex due to hitting
8690 the per-program-point limit.
8691
8692 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8693
8694 * region-model.cc (region_model::on_call_pre): Treat getchar as
8695 having no side-effects.
8696
8697 2020-09-15 David Malcolm <dmalcolm@redhat.com>
8698
8699 PR analyzer/96650
8700 * constraint-manager.cc (merger_fact_visitor::on_fact): Replace
8701 assertion that add_constraint succeeded with an assertion that
8702 if it fails, -fanalyzer-transitivity is off.
8703
8704 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8705
8706 * analyzer.opt (-param=analyzer-max-constraints=): New param.
8707 * constraint-manager.cc
8708 (constraint_manager::add_constraint_internal): Silently reject
8709 attempts to add constraints when the above limit is reached.
8710
8711 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8712
8713 PR analyzer/96653
8714 * constraint-manager.cc
8715 (constraint_manager::get_or_add_equiv_class): Don't accumulate
8716 transitive closure of all constraints on constants.
8717
8718 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8719
8720 PR analyzer/97029
8721 * analyzer.cc (is_setjmp_call_p): Require the initial arg to be a
8722 pointer.
8723 * region-model.cc (region_model::deref_rvalue): Assert that the
8724 svalue is of pointer type.
8725
8726 2020-09-11 David Malcolm <dmalcolm@redhat.com>
8727
8728 PR analyzer/96798
8729 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8730 New.
8731 (region_model::impl_call_strcpy): New.
8732 * region-model.cc (region_model::on_call_pre): Flag unhandled
8733 builtins that are non-pure as having unknown side-effects.
8734 Implement BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_STRCPY,
8735 BUILT_IN_STRCPY_CHK, BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED,
8736 BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_FPUTC,
8737 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
8738 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
8739 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
8740 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
8741 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF.
8742 * region-model.h (region_model::impl_call_memcpy): New decl.
8743 (region_model::impl_call_strcpy): New decl.
8744
8745 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8746
8747 PR analyzer/94355
8748 * analyzer.opt (Wanalyzer-mismatching-deallocation): New warning.
8749 * region-model-impl-calls.cc
8750 (region_model::impl_call_operator_new): New.
8751 (region_model::impl_call_operator_delete): New.
8752 * region-model.cc (region_model::on_call_pre): Detect operator new
8753 and operator delete.
8754 (region_model::on_call_post): Likewise.
8755 (region_model::maybe_update_for_edge): Detect EH edges and call...
8756 (region_model::apply_constraints_for_exception): New function.
8757 * region-model.h (region_model::impl_call_operator_new): New decl.
8758 (region_model::impl_call_operator_delete): New decl.
8759 (region_model::apply_constraints_for_exception): New decl.
8760 * sm-malloc.cc (enum resource_state): New.
8761 (struct allocation_state): New state subclass.
8762 (enum wording): New.
8763 (struct api): New.
8764 (malloc_state_machine::custom_data_t): New typedef.
8765 (malloc_state_machine::add_state): New decl.
8766 (malloc_state_machine::m_unchecked)
8767 (malloc_state_machine::m_nonnull)
8768 (malloc_state_machine::m_freed): Delete these states in favor
8769 of...
8770 (malloc_state_machine::m_malloc)
8771 (malloc_state_machine::m_scalar_new)
8772 (malloc_state_machine::m_vector_new): ...this new api instances,
8773 which own their own versions of these states.
8774 (malloc_state_machine::on_allocator_call): New decl.
8775 (malloc_state_machine::on_deallocator_call): New decl.
8776 (api::api): New ctor.
8777 (dyn_cast_allocation_state): New.
8778 (as_a_allocation_state): New.
8779 (get_rs): New.
8780 (unchecked_p): New.
8781 (nonnull_p): New.
8782 (freed_p): New.
8783 (malloc_diagnostic::describe_state_change): Use unchecked_p and
8784 nonnull_p.
8785 (class mismatching_deallocation): New.
8786 (double_free::double_free): Add funcname param for initializing
8787 m_funcname.
8788 (double_free::emit): Use m_funcname in warning message rather
8789 than hardcoding "free".
8790 (double_free::describe_state_change): Likewise. Use freed_p.
8791 (double_free::describe_call_with_state): Use freed_p.
8792 (double_free::describe_final_event): Use m_funcname in message
8793 rather than hardcoding "free".
8794 (double_free::m_funcname): New field.
8795 (possible_null::describe_state_change): Use unchecked_p.
8796 (possible_null::describe_return_of_state): Likewise.
8797 (use_after_free::use_after_free): Add param for initializing m_api.
8798 (use_after_free::emit): Use m_api->m_dealloc_funcname in message
8799 rather than hardcoding "free".
8800 (use_after_free::describe_state_change): Use freed_p. Change the
8801 wording of the message based on the API.
8802 (use_after_free::describe_final_event): Use
8803 m_api->m_dealloc_funcname in message rather than hardcoding
8804 "free". Change the wording of the message based on the API.
8805 (use_after_free::m_api): New field.
8806 (malloc_leak::describe_state_change): Use unchecked_p. Update
8807 for renaming of m_malloc_event to m_alloc_event.
8808 (malloc_leak::describe_final_event): Update for renaming of
8809 m_malloc_event to m_alloc_event.
8810 (malloc_leak::m_malloc_event): Rename...
8811 (malloc_leak::m_alloc_event): ...to this.
8812 (free_of_non_heap::free_of_non_heap): Add param for initializing
8813 m_funcname.
8814 (free_of_non_heap::emit): Use m_funcname in message rather than
8815 hardcoding "free".
8816 (free_of_non_heap::describe_final_event): Likewise.
8817 (free_of_non_heap::m_funcname): New field.
8818 (allocation_state::dump_to_pp): New.
8819 (allocation_state::get_nonnull): New.
8820 (malloc_state_machine::malloc_state_machine): Update for changes
8821 to state fields and new api fields.
8822 (malloc_state_machine::add_state): New.
8823 (malloc_state_machine::on_stmt): Move malloc/calloc handling to
8824 on_allocator_call and call it, passing in the API pointer.
8825 Likewise for free, moving it to on_deallocator_call. Handle calls
8826 to operator new and delete in an analogous way. Use unchecked_p
8827 when testing for possibly-null-arg and possibly-null-deref, and
8828 transition to the non-null for the correct API. Remove redundant
8829 node param from call to on_zero_assignment. Use freed_p for
8830 use-after-free check, and pass in API.
8831 (malloc_state_machine::on_allocator_call): New, based on code in
8832 on_stmt.
8833 (malloc_state_machine::on_deallocator_call): Likewise.
8834 (malloc_state_machine::on_phi): Mark node param with
8835 ATTRIBUTE_UNUSED; don't pass it to on_zero_assignment.
8836 (malloc_state_machine::on_condition): Mark node param with
8837 ATTRIBUTE_UNUSED. Replace on_transition calls with get_state and
8838 set_next_state pairs, transitioning to the non-null state for the
8839 appropriate API.
8840 (malloc_state_machine::can_purge_p): Port to new state approach.
8841 (malloc_state_machine::on_zero_assignment): Replace on_transition
8842 calls with get_state and set_next_state pairs. Drop redundant
8843 node param.
8844 * sm.h (state_machine::add_custom_state): New.
8845
8846 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8847
8848 * diagnostic-manager.cc
8849 (null_assignment_sm_context::warn_for_state): Replace with...
8850 (null_assignment_sm_context::warn): ...this.
8851 * engine.cc (impl_sm_context::warn_for_state): Replace with...
8852 (impl_sm_context::warn): ...this.
8853 * sm-file.cc (fileptr_state_machine::on_stmt): Replace
8854 warn_for_state and on_transition calls with a get_state
8855 test guarding warn and set_next_state calls.
8856 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
8857 * sm-pattern-test.cc (pattern_test_state_machine::on_condition):
8858 Replace warn_for_state call with warn call.
8859 * sm-sensitive.cc
8860 (sensitive_state_machine::warn_for_any_exposure): Replace
8861 warn_for_state call with a get_state test guarding a warn call.
8862 * sm-signal.cc (signal_state_machine::on_stmt): Likewise.
8863 * sm-taint.cc (taint_state_machine::on_stmt): Replace
8864 warn_for_state and on_transition calls with a get_state
8865 test guarding warn and set_next_state calls.
8866 * sm.h (sm_context::warn_for_state): Replace with...
8867 (sm_context::warn): ...this.
8868
8869 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8870
8871 * diagnostic-manager.cc
8872 (null_assignment_sm_context::null_assignment_sm_context): Add old_state
8873 and ext_state params, initializing m_old_state and m_ext_state.
8874 (null_assignment_sm_context::on_transition): Split into...
8875 (null_assignment_sm_context::get_state): ...this new vfunc
8876 implementation and...
8877 (null_assignment_sm_context::set_next_state): ...this new vfunc
8878 implementation.
8879 (null_assignment_sm_context::m_old_state): New field.
8880 (null_assignment_sm_context::m_ext_state): New field.
8881 (diagnostic_manager::add_events_for_eedge): Pass in old state and
8882 ext_state when creating sm_ctxt.
8883 * engine.cc (impl_sm_context::on_transition): Split into...
8884 (impl_sm_context::get_state): ...this new vfunc
8885 implementation and...
8886 (impl_sm_context::set_next_state): ...this new vfunc
8887 implementation.
8888 * sm.h (sm_context::get_state): New pure virtual function.
8889 (sm_context::set_next_state): Likewise.
8890 (sm_context::on_transition): Convert from a pure virtual function
8891 to a regular function implemented in terms of get_state and
8892 set_next_state.
8893
8894 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8895
8896 * checker-path.cc (state_change_event::get_desc): Update
8897 state_machine::get_state_name calls to state::get_name.
8898 (warning_event::get_desc): Likewise.
8899 * diagnostic-manager.cc
8900 (null_assignment_sm_context::on_transition): Update comparison
8901 against 0 with comparison with m_sm.get_start_state.
8902 (diagnostic_manager::prune_for_sm_diagnostic): Update
8903 state_machine::get_state_name calls to state::get_name.
8904 * engine.cc (impl_sm_context::on_transition): Likewise.
8905 (exploded_node::get_dot_fillcolor): Use get_id when summing
8906 the sm states.
8907 * program-state.cc (sm_state_map::sm_state_map): Don't hardcode
8908 0 as the start state when initializing m_global_state.
8909 (sm_state_map::print): Use dump_to_pp rather than get_state_name
8910 when dumping states.
8911 (sm_state_map::is_empty_p): Don't hardcode 0 as the start state
8912 when examining m_global_state.
8913 (sm_state_map::hash): Use get_id when hashing states.
8914 (selftest::test_sm_state_map): Use state objects rather than
8915 arbitrary hardcoded integers.
8916 (selftest::test_program_state_merging): Likewise.
8917 (selftest::test_program_state_merging_2): Likewise.
8918 * sm-file.cc (fileptr_state_machine::m_start): Move to base class.
8919 (file_diagnostic::describe_state_change): Use get_start_state.
8920 (fileptr_state_machine::fileptr_state_machine): Drop m_start
8921 initialization.
8922 * sm-malloc.cc (malloc_state_machine::m_start): Move to base
8923 class.
8924 (malloc_diagnostic::describe_state_change): Use get_start_state.
8925 (possible_null::describe_state_change): Likewise.
8926 (malloc_state_machine::malloc_state_machine): Drop m_start
8927 initialization.
8928 * sm-pattern-test.cc (pattern_test_state_machine::m_start): Move
8929 to base class.
8930 (pattern_test_state_machine::pattern_test_state_machine): Drop
8931 m_start initialization.
8932 * sm-sensitive.cc (sensitive_state_machine::m_start): Move to base
8933 class.
8934 (sensitive_state_machine::sensitive_state_machine): Drop m_start
8935 initialization.
8936 * sm-signal.cc (signal_state_machine::m_start): Move to base
8937 class.
8938 (signal_state_machine::signal_state_machine): Drop m_start
8939 initialization.
8940 * sm-taint.cc (taint_state_machine::m_start): Move to base class.
8941 (taint_state_machine::taint_state_machine): Drop m_start
8942 initialization.
8943 * sm.cc (state_machine::state::dump_to_pp): New.
8944 (state_machine::state_machine): Move here from sm.h. Initialize
8945 m_next_state_id and m_start.
8946 (state_machine::add_state): Reimplement in terms of state objects.
8947 (state_machine::get_state_name): Delete.
8948 (state_machine::get_state_by_name): Reimplement in terms of state
8949 objects. Make const.
8950 (state_machine::validate): Delete.
8951 (state_machine::dump_to_pp): Reimplement in terms of state
8952 objects.
8953 * sm.h (state_machine::state): New class.
8954 (state_machine::state_t): Convert typedef from "unsigned" to
8955 "const state_machine::state *".
8956 (state_machine::state_machine): Move to sm.cc.
8957 (state_machine::get_default_state): Use m_start rather than
8958 hardcoding 0.
8959 (state_machine::get_state_name): Delete.
8960 (state_machine::get_state_by_name): Make const.
8961 (state_machine::get_start_state): New accessor.
8962 (state_machine::alloc_state_id): New.
8963 (state_machine::m_state_names): Drop in favor of...
8964 (state_machine::m_states): New field
8965 (state_machine::m_start): New field
8966 (start_start_p): Delete.
8967
8968 2020-09-08 David Malcolm <dmalcolm@redhat.com>
8969
8970 PR analyzer/96949
8971 * store.cc (binding_map::apply_ctor_val_to_range): Add
8972 error-handling for the cases where we have symbolic offsets.
8973
8974 2020-09-08 David Malcolm <dmalcolm@redhat.com>
8975
8976 PR analyzer/96950
8977 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
8978 where min_index == max_index.
8979 (binding_map::apply_ctor_val_to_range): Replace assertion that we
8980 don't have a CONSTRUCTOR value with error-handling.
8981
8982 2020-09-08 David Malcolm <dmalcolm@redhat.com>
8983
8984 PR analyzer/96962
8985 * region-model.cc (region_model::on_call_pre): Fix guard on switch
8986 on built-ins to only consider BUILT_IN_NORMAL, rather than other
8987 kinds of build-ins.
8988
8989 2020-09-01 David Malcolm <dmalcolm@redhat.com>
8990
8991 PR analyzer/96792
8992 * region-model.cc (region_model::deref_rvalue): Add the constraint
8993 that PTR_SVAL is non-NULL.
8994
8995 2020-08-31 David Malcolm <dmalcolm@redhat.com>
8996
8997 PR analyzer/96798
8998 * region-model.cc (region_model::on_call_pre): Handle
8999 BUILT_IN_MEMSET_CHK.
9000
9001 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9002
9003 * region-model.cc (region_model::on_call_pre): Gather handling of
9004 builtins and of internal fns into switch statements. Handle
9005 "alloca" and BUILT_IN_ALLOCA_WITH_ALIGN.
9006
9007 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9008
9009 PR analyzer/96860
9010 * region.cc (decl_region::get_svalue_for_constructor): Support
9011 apply_ctor_to_region failing.
9012 * store.cc (binding_map::apply_ctor_to_region): Add failure
9013 handling.
9014 (binding_map::apply_ctor_val_to_range): Likewise.
9015 (binding_map::apply_ctor_pair_to_child_region): Likewise. Replace
9016 assertion that child_base_offset is not symbolic with error
9017 handling.
9018 * store.h (binding_map::apply_ctor_to_region): Convert return type
9019 from void to bool.
9020 (binding_map::apply_ctor_val_to_range): Likewise.
9021 (binding_map::apply_ctor_pair_to_child_region): Likewise.
9022
9023 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9024
9025 PR analyzer/96763
9026 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
9027 by calling a new binding_map::apply_ctor_val_to_range subroutine.
9028 Split out the existing non-CONSTRUCTOR-handling code to a new
9029 apply_ctor_pair_to_child_region subroutine.
9030 (binding_map::apply_ctor_val_to_range): New.
9031 (binding_map::apply_ctor_pair_to_child_region): New, split out
9032 from binding_map::apply_ctor_to_region as noted above.
9033 * store.h (binding_map::apply_ctor_val_to_range): New decl.
9034 (binding_map::apply_ctor_pair_to_child_region): New decl.
9035
9036 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9037
9038 PR analyzer/96764
9039 * region-model-manager.cc
9040 (region_model_manager::maybe_fold_unaryop): Handle VIEW_CONVERT_EXPR.
9041 (region_model_manager::get_or_create_cast): Move logic for
9042 real->integer casting to...
9043 (get_code_for_cast): ...this new function, and add logic for
9044 real->non-integer casts.
9045 (region_model_manager::maybe_fold_sub_svalue): Handle
9046 VIEW_CONVERT_EXPR.
9047 * region-model.cc
9048 (region_model::add_any_constraints_from_gassign): Likewise.
9049 * svalue.cc (svalue::maybe_undo_cast): Likewise.
9050 (unaryop_svalue::dump_to_pp): Likewise.
9051
9052 2020-08-26 David Malcolm <dmalcolm@redhat.com>
9053
9054 PR analyzer/94858
9055 * region-model-manager.cc
9056 (region_model_manager::get_or_create_widening_svalue): Assert that
9057 neither of the inputs are themselves widenings.
9058 * store.cc (store::eval_alias_1): The initial value of a pointer
9059 can't point to a region that was allocated on the heap after the
9060 beginning of the path. A widened pointer value can't alias anything
9061 that the initial pointer value can't alias.
9062 * svalue.cc (svalue::can_merge_p): Merge BINOP (X, OP, CST) with X
9063 to a widening svalue. Merge
9064 BINOP(WIDENING(BASE, BINOP(BASE, X)), X) and BINOP(BASE, X) to
9065 to the LHS of the first BINOP.
9066
9067 2020-08-26 David Malcolm <dmalcolm@redhat.com>
9068
9069 PR analyzer/96777
9070 * region-model.h (class compound_svalue): Document that all keys
9071 must be concrete.
9072 (compound_svalue::compound_svalue): Move definition to svalue.cc.
9073 * store.cc (binding_map::apply_ctor_to_region): Handle
9074 initializers for trailing arrays with incomplete size.
9075 * svalue.cc (compound_svalue::compound_svalue): Move definition
9076 here from region-model.h. Add assertion that all keys are
9077 concrete.
9078
9079 2020-08-22 David Malcolm <dmalcolm@redhat.com>
9080
9081 PR analyzer/94851
9082 * region-model-manager.cc
9083 (region_model_manager::maybe_fold_binop): Fold bitwise "& 0" to 0.
9084
9085 2020-08-22 David Malcolm <dmalcolm@redhat.com>
9086
9087 * store.cc (store::eval_alias): Make const. Split out 2nd half
9088 into store::eval_alias_1 and call it twice for symmetry, avoiding
9089 test duplication.
9090 (store::eval_alias_1): New function, split out from the above.
9091 * store.h (store::eval_alias): Make const.
9092 (store::eval_alias_1): New decl.
9093
9094 2020-08-22 David Malcolm <dmalcolm@redhat.com>
9095
9096 * region-model.cc (region_model::push_frame): Bind the default
9097 SSA name for each parm if it exists, falling back to the parm
9098 itself otherwise, rather than doing both.
9099
9100 2020-08-20 David Malcolm <dmalcolm@redhat.com>
9101
9102 PR analyzer/96723
9103 * region-model-manager.cc
9104 (region_model_manager::get_field_region): Assert that field is a
9105 FIELD_DECL.
9106 * region.cc (region::get_subregions_for_binding): In
9107 union-handling, filter the TYPE_FIELDS traversal to just FIELD_DECLs.
9108
9109 2020-08-20 David Malcolm <dmalcolm@redhat.com>
9110
9111 PR analyzer/96713
9112 * region-model.cc (region_model::get_gassign_result): For
9113 comparisons, only use eval_condition when the lhs has boolean
9114 type, and use get_or_create_constant_svalue on the boolean
9115 constants directly rather than via get_rvalue.
9116
9117 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9118
9119 PR analyzer/96643
9120 * region-model.cc (region_model::deref_rvalue): Rather than
9121 attempting to handle all svalue kinds in the switch, only cover
9122 the special cases, and move symbolic-region handling to after
9123 the switch, thus implicitly handling the missing case SK_COMPOUND.
9124
9125 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9126
9127 PR analyzer/96705
9128 * region-model-manager.cc
9129 (region_model_manager::maybe_fold_binop): Check that we have an
9130 integral type before calling build_int_cst.
9131
9132 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9133
9134 PR analyzer/96699
9135 * region-model-manager.cc
9136 (region_model_manager::get_or_create_cast): Use FIX_TRUNC_EXPR for
9137 casting from REAL_TYPE to INTEGER_TYPE.
9138
9139 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9140
9141 PR analyzer/96651
9142 * region-model.cc (region_model::called_from_main_p): New.
9143 (region_model::get_store_value): Move handling for globals into...
9144 (region_model::get_initial_value_for_global): ...this new
9145 function, and add logic for extracting values from decl
9146 initializers.
9147 * region-model.h (decl_region::get_svalue_for_constructor): New
9148 decl.
9149 (decl_region::get_svalue_for_initializer): New decl.
9150 (region_model::called_from_main_p): New decl.
9151 (region_model::get_initial_value_for_global): New.
9152 * region.cc (decl_region::maybe_get_constant_value): Move logic
9153 for getting an svalue from a CONSTRUCTOR node to...
9154 (decl_region::get_svalue_for_constructor): ...this new function.
9155 (decl_region::get_svalue_for_initializer): New.
9156 * store.cc (get_svalue_for_ctor_val): Rewrite in terms of
9157 region_model::get_rvalue.
9158 * store.h (binding_cluster::get_map): New accessor.
9159
9160 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9161
9162 PR analyzer/96648
9163 * region.cc (get_field_at_bit_offset): Gracefully handle negative
9164 values for bit_offset.
9165
9166 2020-08-18 David Malcolm <dmalcolm@redhat.com>
9167
9168 * region-model.cc (region_model::get_rvalue_1): Fix name of local.
9169
9170 2020-08-18 David Malcolm <dmalcolm@redhat.com>
9171
9172 PR analyzer/96641
9173 * region-model.cc (region_model::get_rvalue_1): Handle
9174 unrecognized tree codes by returning "UNKNOWN.
9175
9176 2020-08-18 David Malcolm <dmalcolm@redhat.com>
9177
9178 PR analyzer/96640
9179 * region-model.cc (region_model::get_gassign_result): Handle various
9180 VEC_* tree codes by returning UNKNOWN.
9181 (region_model::on_assignment): Handle unrecognized tree codes by
9182 setting lhs to an unknown value, rather than issuing a "sorry" and
9183 asserting.
9184
9185 2020-08-17 David Malcolm <dmalcolm@redhat.com>
9186
9187 PR analyzer/96644
9188 * region-model-manager.cc (get_region_for_unexpected_tree_code):
9189 Handle ctxt being NULL.
9190
9191 2020-08-17 David Malcolm <dmalcolm@redhat.com>
9192
9193 PR analyzer/96639
9194 * region.cc (region::get_subregions_for_binding): Check for "type"
9195 being NULL.
9196
9197 2020-08-17 David Malcolm <dmalcolm@redhat.com>
9198
9199 PR analyzer/96642
9200 * store.cc (get_svalue_for_ctor_val): New.
9201 (binding_map::apply_ctor_to_region): Call it.
9202
9203 2020-08-14 David Malcolm <dmalcolm@redhat.com>
9204
9205 PR testsuite/96609
9206 PR analyzer/96616
9207 * region-model.cc (region_model::get_store_value): Call
9208 maybe_get_constant_value on decl_regions first.
9209 * region-model.h (decl_region::maybe_get_constant_value): New decl.
9210 * region.cc (decl_region::get_stack_depth): Likewise.
9211 (decl_region::maybe_get_constant_value): New.
9212 * store.cc (get_subregion_within_ctor): New.
9213 (binding_map::apply_ctor_to_region): New.
9214 * store.h (binding_map::apply_ctor_to_region): New decl.
9215
9216 2020-08-14 David Malcolm <dmalcolm@redhat.com>
9217
9218 PR analyzer/96611
9219 * store.cc (store::mark_as_escaped): Reject attempts to
9220 get a cluster for an unknown pointer.
9221
9222 2020-08-13 David Malcolm <dmalcolm@redhat.com>
9223
9224 PR analyzer/93032
9225 PR analyzer/93938
9226 PR analyzer/94011
9227 PR analyzer/94099
9228 PR analyzer/94399
9229 PR analyzer/94458
9230 PR analyzer/94503
9231 PR analyzer/94640
9232 PR analyzer/94688
9233 PR analyzer/94689
9234 PR analyzer/94839
9235 PR analyzer/95026
9236 PR analyzer/95042
9237 PR analyzer/95240
9238 * analyzer-logging.cc: Ignore "-Wformat-diag".
9239 (logger::enter_scope): Use inc_indent in both overloads.
9240 (logger::exit_scope): Use dec_indent.
9241 * analyzer-logging.h (logger::inc_indent): New.
9242 (logger::dec_indent): New.
9243 * analyzer-selftests.cc (run_analyzer_selftests): Call
9244 analyzer_store_cc_tests.
9245 * analyzer-selftests.h (analyzer_store_cc_tests): New decl.
9246 * analyzer.cc (get_stmt_location): New function.
9247 * analyzer.h (class initial_svalue): New forward decl.
9248 (class unaryop_svalue): New forward decl.
9249 (class binop_svalue): New forward decl.
9250 (class sub_svalue): New forward decl.
9251 (class unmergeable_svalue): New forward decl.
9252 (class placeholder_svalue): New forward decl.
9253 (class widening_svalue): New forward decl.
9254 (class compound_svalue): New forward decl.
9255 (class conjured_svalue): New forward decl.
9256 (svalue_set): New typedef.
9257 (class map_region): Delete.
9258 (class array_region): Delete.
9259 (class frame_region): New forward decl.
9260 (class function_region): New forward decl.
9261 (class label_region): New forward decl.
9262 (class decl_region): New forward decl.
9263 (class element_region): New forward decl.
9264 (class offset_region): New forward decl.
9265 (class cast_region): New forward decl.
9266 (class field_region): New forward decl.
9267 (class string_region): New forward decl.
9268 (class region_model_manager): New forward decl.
9269 (class store_manager): New forward decl.
9270 (class store): New forward decl.
9271 (class call_details): New forward decl.
9272 (struct svalue_id_merger_mapping): Delete.
9273 (struct canonicalization): Delete.
9274 (class function_point): New forward decl.
9275 (class engine): New forward decl.
9276 (dump_tree): New function decl.
9277 (print_quoted_type): New function decl.
9278 (readability_comparator): New function decl.
9279 (tree_cmp): New function decl.
9280 (class path_var): Move here from region-model.h
9281 (bit_offset_t, bit_size_t, byte_size_t): New typedefs.
9282 (class region_offset): New class.
9283 (get_stmt_location): New decl.
9284 (struct member_function_hash_traits): New struct.
9285 (class consolidation_map): New class.
9286 Ignore "-Wformat-diag".
9287 * analyzer.opt (-param=analyzer-max-svalue-depth=): New param.
9288 (-param=analyzer-max-enodes-for-full-dump=): New param.
9289 * call-string.cc: Ignore -Wformat-diag.
9290 * checker-path.cc: Move includes of "analyzer/call-string.h" and
9291 "analyzer/program-point.h" to before "analyzer/region-model.h",
9292 and also include "analyzer/store.h" before it.
9293 (state_change_event::state_change_event): Replace "tree var" param
9294 with "const svalue *sval". Convert "origin" param from tree to
9295 "const svalue *".
9296 (state_change_event::get_desc): Call get_representative_tree to
9297 convert the var and origin from const svalue * to tree. Use
9298 svalue::get_desc rather than %qE when describing state changes.
9299 (checker_path::add_final_event): Use get_stmt_location.
9300 * checker-path.h (state_change_event::state_change_event): Port
9301 from tree to const svalue *.
9302 (state_change_event::get_lvalue): Delete.
9303 (state_change_event::get_dest_function): New.
9304 (state_change_event::m_var): Replace with...
9305 (state_change_event::m_sval): ...this.
9306 (state_change_event::m_origin): Convert from tree to
9307 const svalue *.
9308 * constraint-manager.cc: Include "analyzer/call-string.h",
9309 "analyzer/program-point.h", and "analyzer/store.h" before
9310 "analyzer/region-model.h".
9311 (struct bound, struct range): Move to constraint-manager.h.
9312 (compare_constants): New function.
9313 (range::dump): Rename to...
9314 (range::dump_to_pp): ...this. Support NULL constants.
9315 (range::dump): Reintroduce for dumping to stderr.
9316 (range::constrained_to_single_element): Return result, rather than
9317 writing to *OUT.
9318 (range::eval_condition): New.
9319 (range::below_lower_bound): New.
9320 (range::above_upper_bound): New.
9321 (equiv_class::equiv_class): Port from svalue_id to const svalue *.
9322 (equiv_class::print): Likewise.
9323 (equiv_class::hash): Likewise.
9324 (equiv_class::operator==): Port from svalue_id to const svalue *.
9325 (equiv_class::add): Port from svalue_id to const svalue *. Drop
9326 "cm" param.
9327 (equiv_class::del): Port from svalue_id to const svalue *.
9328 (equiv_class::get_representative): Likewise.
9329 (equiv_class::remap_svalue_ids): Delete.
9330 (svalue_id_cmp_by_id): Rename to...
9331 (svalue_cmp_by_ptr): ...this, porting from svalue_id to
9332 const svalue *.
9333 (equiv_class::canonicalize): Update qsort comparator.
9334 (constraint::implied_by): New.
9335 (constraint_manager::constraint_manager): Copy m_mgr in copy ctor.
9336 (constraint_manager::dump_to_pp): Add "multiline" param
9337 (constraint_manager::dump): Pass "true" for "multiline".
9338 (constraint_manager::add_constraint): Port from svalue_id to
9339 const svalue *. Split out second part into...
9340 (constraint_manager::add_unknown_constraint): ...this new
9341 function. Remove self-constraints when merging equivalence
9342 classes.
9343 (constraint_manager::add_constraint_internal): Remove constraints
9344 that would be implied by the new constraint. Port from svalue_id
9345 to const svalue *.
9346 (constraint_manager::get_equiv_class_by_sid): Rename to...
9347 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
9348 from svalue_id to const svalue *.
9349 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
9350 to const svalue *.
9351 (constraint_manager::eval_condition): Make const. Call
9352 compare_constants and return early if it provides a known result.
9353 (constraint_manager::get_ec_bounds): New.
9354 (constraint_manager::eval_condition): New overloads. Make
9355 existing one const, and use compare_constants.
9356 (constraint_manager::purge): Convert "p" param to a template
9357 rather that an abstract base class. Port from svalue_id to
9358 const svalue *.
9359 (class dead_svalue_purger): New class.
9360 (constraint_manager::remap_svalue_ids): Delete.
9361 (constraint_manager::on_liveness_change): New.
9362 (equiv_class_cmp): Port from svalue_id to const svalue *.
9363 (constraint_manager::canonicalize): Likewise. Combine with
9364 purging of redundant equivalence classes and constraints.
9365 (class cleaned_constraint_manager): Delete.
9366 (class merger_fact_visitor): Make "m_cm_b" const. Add "m_merger"
9367 field.
9368 (merger_fact_visitor::fact): Port from svalue_id to const svalue *.
9369 Add special case for widening.
9370 (constraint_manager::merge): Port from svalue_id to const svalue *.
9371 (constraint_manager::clean_merger_input): Delete.
9372 (constraint_manager::for_each_fact): Port from svalue_id to
9373 const svalue *.
9374 (constraint_manager::validate): Likewise.
9375 (selftest::test_constraint_conditions): Provide a
9376 region_model_manager when creating region_model instances.
9377 Add test for self-equality not creating equivalence classes.
9378 (selftest::test_transitivity): Provide a region_model_manager when
9379 creating region_model instances. Verify that EC-merging happens
9380 when constraints are implied.
9381 (selftest::test_constant_comparisons): Provide a
9382 region_model_manager when creating region_model instances.
9383 (selftest::test_constraint_impl): Likewise. Remove over-specified
9384 assertions.
9385 (selftest::test_equality): Provide a region_model_manager when
9386 creating region_model instances.
9387 (selftest::test_many_constants): Likewise. Provide a
9388 program_point when testing merging.
9389 (selftest::run_constraint_manager_tests): Move call to
9390 test_constant_comparisons to outside the transitivity guard.
9391 * constraint-manager.h (struct bound): Move here from
9392 constraint-manager.cc.
9393 (struct range): Likewise.
9394 (struct::eval_condition): New decl.
9395 (struct::below_lower_bound): New decl.
9396 (struct::above_upper_bound): New decl.
9397 (equiv_class::add): Port from svalue_id to const svalue *.
9398 (equiv_class::del): Likewise.
9399 (equiv_class::get_representative): Likewise.
9400 (equiv_class::remap_svalue_ids): Drop.
9401 (equiv_class::m_cst_sid): Convert to..
9402 (equiv_class::m_cst_sval): ...this.
9403 (equiv_class::m_vars): Port from svalue_id to const svalue *.
9404 (constraint::bool implied_by): New decl.
9405 (fact_visitor::on_fact): Port from svalue_id to const svalue *.
9406 (constraint_manager::constraint_manager): Add mgr param.
9407 (constraint_manager::clone): Delete.
9408 (constraint_manager::maybe_get_constant): Delete.
9409 (constraint_manager::get_sid_for_constant): Delete.
9410 (constraint_manager::get_num_svalues): Delete.
9411 (constraint_manager::dump_to_pp): Add "multiline" param.
9412 (constraint_manager::get_equiv_class): Port from svalue_id to
9413 const svalue *.
9414 (constraint_manager::add_constraint): Likewise.
9415 (constraint_manager::get_equiv_class_by_sid): Rename to...
9416 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
9417 from svalue_id to const svalue *.
9418 (constraint_manager::add_unknown_constraint): New decl.
9419 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
9420 to const svalue *.
9421 (constraint_manager::eval_condition): Likewise. Add overloads.
9422 (constraint_manager::get_ec_bounds): New decl.
9423 (constraint_manager::purge): Convert to template.
9424 (constraint_manager::remap_svalue_ids): Delete.
9425 (constraint_manager::on_liveness_change): New decl.
9426 (constraint_manager::canonicalize): Drop param.
9427 (constraint_manager::clean_merger_input): Delete.
9428 (constraint_manager::m_mgr): New field.
9429 * diagnostic-manager.cc: Move includes of
9430 "analyzer/call-string.h" and "analyzer/program-point.h" to before
9431 "analyzer/region-model.h", and also include "analyzer/store.h"
9432 before it.
9433 (saved_diagnostic::saved_diagnostic): Add "sval" param.
9434 (diagnostic_manager::diagnostic_manager): Add engine param.
9435 (diagnostic_manager::add_diagnostic): Add "sval" param, passing it
9436 to saved_diagnostic ctor. Update overload to pass NULL for it.
9437 (dedupe_winners::dedupe_winners): Add engine param.
9438 (dedupe_winners::add): Add "eg" param. Pass m_engine to
9439 feasible_p.
9440 (dedupe_winner::m_engine): New field.
9441 (diagnostic_manager::emit_saved_diagnostics): Pass engine to
9442 dedupe_winners. Pass &eg when adding candidates. Pass svalue
9443 rather than tree to prune_path. Use get_stmt_location to get
9444 primary location of diagnostic.
9445 (diagnostic_manager::emit_saved_diagnostic): Likewise.
9446 (get_any_origin): Drop.
9447 (state_change_event_creator::on_global_state_change): Pass NULL
9448 const svalue * rather than NULL_TREE trees to state_change_event
9449 ctor.
9450 (state_change_event_creator::on_state_change): Port from tree and
9451 svalue_id to const svalue *.
9452 (for_each_state_change): Port from svalue_id to const svalue *.
9453 (struct null_assignment_sm_context): New.
9454 (diagnostic_manager::add_events_for_eedge): Add state change
9455 events for assignment to NULL.
9456 (diagnostic_manager::prune_path): Update param from tree to
9457 const svalue *.
9458 (diagnostic_manager::prune_for_sm_diagnostic): Port from tracking
9459 by tree to by const svalue *.
9460 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add sval
9461 param.
9462 (saved_diagnostic::m_sval): New field.
9463 (diagnostic_manager::diagnostic_manager): Add engine param.
9464 (diagnostic_manager::get_engine): New.
9465 (diagnostic_manager::add_diagnostic): Add "sval" param.
9466 (diagnostic_manager::prune_path): Likewise.
9467 (diagnostic_manager::prune_for_sm_diagnostic): New overload.
9468 (diagnostic_manager::m_eng): New field.
9469 * engine.cc: Move includes of "analyzer/call-string.h" and
9470 "analyzer/program-point.h" to before "analyzer/region-model.h",
9471 and also include "analyzer/store.h" before it.
9472 (impl_region_model_context::impl_region_model_context): Update for
9473 removal of m_change field.
9474 (impl_region_model_context::remap_svalue_ids): Delete.
9475 (impl_region_model_context::on_svalue_leak): New.
9476 (impl_region_model_context::on_svalue_purge): Delete.
9477 (impl_region_model_context::on_liveness_change): New.
9478 (impl_region_model_context::on_unknown_change): Update param
9479 from svalue_id to const svalue *. Add is_mutable param.
9480 (setjmp_svalue::compare_fields): Delete.
9481 (setjmp_svalue::accept): New.
9482 (setjmp_svalue::add_to_hash): Delete.
9483 (setjmp_svalue::dump_to_pp): New.
9484 (setjmp_svalue::print_details): Delete.
9485 (impl_sm_context::impl_sm_context): Drop "change" param.
9486 (impl_sm_context::get_fndecl_for_call): Drop "m_change".
9487 (impl_sm_context::on_transition): Drop ATTRIBUTE_UNUSED from
9488 "stmt" param. Drop m_change. Port from svalue_id to
9489 const svalue *.
9490 (impl_sm_context::warn_for_state): Drop m_change. Port from
9491 svalue_id to const svalue *.
9492 (impl_sm_context::get_readable_tree): Rename to...
9493 (impl_sm_context::get_diagnostic_tree): ...this. Port from
9494 svalue_id to const svalue *.
9495 (impl_sm_context::is_zero_assignment): New.
9496 (impl_sm_context::m_change): Delete field.
9497 (leak_stmt_finder::find_stmt): Handle m_var being NULL.
9498 (readability): Increase penalty for MEM_REF. For SSA_NAMEs,
9499 slightly favor the underlying var over the SSA name. Heavily
9500 penalize temporaries. Handle RESULT_DECL.
9501 (readability_comparator): Make non-static. Consider stack depths.
9502 (impl_region_model_context::on_state_leak): Convert from svalue_id
9503 to const svalue *, updating for region_model changes. Use
9504 id_equal.
9505 (impl_region_model_context::on_inherited_svalue): Delete.
9506 (impl_region_model_context::on_cast): Delete.
9507 (impl_region_model_context::on_condition): Drop m_change.
9508 (impl_region_model_context::on_phi): Likewise.
9509 (impl_region_model_context::on_unexpected_tree_code): Handle t
9510 being NULL.
9511 (point_and_state::validate): Update stack checking for
9512 region_model changes.
9513 (eg_traits::dump_args_t::show_enode_details_p): New.
9514 (exploded_node::exploded_node): Initialize m_num_processed_stmts.
9515 (exploded_node::get_processed_stmt): New function.
9516 (exploded_node::get_dot_fillcolor): Add more colors.
9517 (exploded_node::dump_dot): Guard the printing of the point and
9518 state with show_enode_details_p. Print the processed stmts for
9519 this enode after the initial state.
9520 (exploded_node::dump_to_pp): Pass true for new multiline param
9521 of program_state::dump_to_pp.
9522 (exploded_node::on_stmt): Drop "change" param. Log the stmt.
9523 Set input_location. Implement __analyzer_describe. Update
9524 implementation of __analyzer_dump and __analyzer_eval.
9525 Remove purging of sm-state for unknown fncalls from here.
9526 (exploded_node::on_edge): Drop "change" param.
9527 (exploded_node::on_longjmp): Port from region_id/svalue_id to
9528 const region */const svalue *. Call program_state::detect_leaks.
9529 Drop state_change.
9530 (exploded_node::detect_leaks): Update for changes to region_model.
9531 Call program_state::detect_leaks.
9532 (exploded_edge::exploded_edge): Drop ext_state and change params.
9533 (exploded_edge::dump_dot): "args" is no longer used. Drop dumping
9534 of m_change.
9535 (exploded_graph::exploded_graph): Pass engine to
9536 m_diagnostic_manager ctor. Use program_point::origin.
9537 (exploded_graph::add_function_entry): Drop ctxt. Use
9538 program_state::push_frame. Drop state_change.
9539 (exploded_graph::get_or_create_node): Drop "change" param. Add
9540 "enode_for_diag" param. Update dumping calls for API changes.
9541 Pass point to can_merge_with_p. Show enode indices
9542 within -Wanalyzer-too-complex diagnostic for hitting the per-point
9543 limit.
9544 (exploded_graph::add_edge): Drop "change" param. Log which nodes
9545 are being connected. Update for changes to exploded_edge ctor.
9546 (exploded_graph::get_per_program_point_data): New.
9547 (exploded_graph::process_worklist): Pass point to
9548 can_merge_with_p. Drop state_change. Update dumping call for API
9549 change.
9550 (exploded_graph::process_node): Drop state_change. Split the
9551 node in-place if an sm-state-change occurs. Update
9552 m_num_processed_stmts. Update dumping calls for API change.
9553 (exploded_graph::log_stats): Call engine::log_stats.
9554 (exploded_graph::dump_states_for_supernode): Update dumping
9555 call.
9556 (exploded_path::feasible_p): Add "eng" and "eg" params.
9557 Rename "i" to "end_idx". Pass the manager to the region_model
9558 ctor. Update for every processed stmt in the enode, not just the
9559 first. Keep track of which snodes have been visited, and call
9560 loop_replay_fixup when revisiting one.
9561 (enode_label::get_text): Update dump call for new param.
9562 (exploded_graph::dump_exploded_nodes): Likewise.
9563 (exploded_graph::get_node_by_index): New.
9564 (impl_run_checkers): Create engine instance and pass its address
9565 to extrinsic_state ctor.
9566 * exploded-graph.h
9567 (impl_region_model_context::impl_region_model_context): Drop
9568 "change" params.
9569 (impl_region_model_context::void remap_svalue_ids): Delete.
9570 (impl_region_model_context::on_svalue_purge): Delete.
9571 (impl_region_model_context::on_svalue_leak): New.
9572 (impl_region_model_context::on_liveness_change): New.
9573 (impl_region_model_context::on_state_leak): Update signature.
9574 (impl_region_model_context::on_inherited_svalue): Delete.
9575 (impl_region_model_context::on_cast): Delete.
9576 (impl_region_model_context::on_unknown_change): Update signature.
9577 (impl_region_model_context::m_change): Delete.
9578 (eg_traits::dump_args_t::show_enode_details_p): New.
9579 (exploded_node::on_stmt): Drop "change" param.
9580 (exploded_node::on_edge): Likewise.
9581 (exploded_node::get_processed_stmt): New decl.
9582 (exploded_node::m_num_processed_stmts): New field.
9583 (exploded_edge::exploded_edge): Drop ext_state and change params.
9584 (exploded_edge::m_change): Delete.
9585 (exploded_graph::get_engine): New accessor.
9586 (exploded_graph::get_or_create_node): Drop "change" param. Add
9587 "enode_for_diag" param.
9588 (exploded_graph::add_edge): Drop "change" param.
9589 (exploded_graph::get_per_program_point_data): New decl.
9590 (exploded_graph::get_node_by_index): New decl.
9591 (exploded_path::feasible_p): Add "eng" and "eg" params.
9592 * program-point.cc: Include "analyzer/store.h" before including
9593 "analyzer/region-model.h".
9594 (function_point::function_point): Move here from
9595 program-point.h.
9596 (function_point::get_function): Likewise.
9597 (function_point::from_function_entry): Likewise.
9598 (function_point::before_supernode): Likewise.
9599 (function_point::next_stmt): New function.
9600 * program-point.h (function_point::function_point): Move
9601 implementation from here to program-point.cc.
9602 (function_point::get_function): Likewise.
9603 (function_point::from_function_entry): Likewise.
9604 (function_point::before_supernode): Likewise.
9605 (function_point::next_stmt): New decl.
9606 (program_point::operator!=): New.
9607 (program_point::origin): New.
9608 (program_point::next_stmt): New.
9609 (program_point::m_function_point): Make non-const.
9610 * program-state.cc: Move includes of "analyzer/call-string.h" and
9611 "analyzer/program-point.h" to before "analyzer/region-model.h",
9612 and also include "analyzer/store.h" before it.
9613 (extrinsic_state::get_model_manager): New.
9614 (sm_state_map::sm_state_map): Pass in sm and sm_idx to ctor,
9615 rather than pass the around.
9616 (sm_state_map::clone_with_remapping): Delete.
9617 (sm_state_map::print): Remove "sm" param in favor of "m_sm". Add
9618 "simple" and "multiline" params and support multiline vs single
9619 line dumping.
9620 (sm_state_map::dump): Remove "sm" param in favor of "m_sm". Add
9621 "simple" param.
9622 (sm_state_map::hash): Port from svalue_id to const svalue *.
9623 (sm_state_map::operator==): Likewise.
9624 (sm_state_map::get_state): Likewise. Call canonicalize_svalue on
9625 input. Handle inheritance of sm-state. Call get_default_state.
9626 (sm_state_map::get_origin): Port from svalue_id to const svalue *.
9627 (sm_state_map::set_state): Likewise. Pass in ext_state. Reject
9628 attempts to set state on UNKNOWN.
9629 (sm_state_map::impl_set_state): Port from svalue_id to
9630 const svalue *. Pass in ext_state. Call canonicalize_svalue on
9631 input.
9632 (sm_state_map::purge_for_unknown_fncall): Delete.
9633 (sm_state_map::on_svalue_leak): New.
9634 (sm_state_map::remap_svalue_ids): Delete.
9635 (sm_state_map::on_liveness_change): New.
9636 (sm_state_map::on_unknown_change): Reimplement.
9637 (sm_state_map::on_svalue_purge): Delete.
9638 (sm_state_map::on_inherited_svalue): Delete.
9639 (sm_state_map::on_cast): Delete.
9640 (sm_state_map::validate): Delete.
9641 (sm_state_map::canonicalize_svalue): New.
9642 (program_state::program_state): Update to pass manager to
9643 region_model's ctor. Constify num_states and pass state machine
9644 and index to sm_state_map ctor.
9645 (program_state::print): Update for changes to dump API.
9646 (program_state::dump_to_pp): Ignore the summarize param. Add
9647 "multiline" param.
9648 (program_state::dump_to_file): Add "multiline" param.
9649 (program_state::dump): Pass "true" for new "multiline" param.
9650 (program_state::push_frame): New.
9651 (program_state::on_edge): Drop "change" param. Call
9652 program_state::detect_leaks.
9653 (program_state::prune_for_point): Add enode_for_diag param.
9654 Reimplement based on store class. Call detect_leaks
9655 (program_state::remap_svalue_ids): Delete.
9656 (program_state::get_representative_tree): Port from svalue_id to
9657 const svalue *.
9658 (program_state::can_merge_with_p): Add "point" param. Add early
9659 reject for sm-differences. Drop id remapping.
9660 (program_state::validate): Drop region model and sm_state_map
9661 validation.
9662 (state_change::sm_change::dump): Delete.
9663 (state_change::sm_change::remap_svalue_ids): Delete.
9664 (state_change::sm_change::on_svalue_purge): Delete.
9665 (log_set_of_svalues): New.
9666 (state_change::sm_change::validate): Delete.
9667 (state_change::state_change): Delete.
9668 (state_change::add_sm_change): Delete.
9669 (state_change::affects_p): Delete.
9670 (state_change::dump): Delete.
9671 (state_change::remap_svalue_ids): Delete.
9672 (state_change::on_svalue_purge): Delete.
9673 (state_change::validate): Delete.
9674 (selftest::assert_dump_eq): Delete.
9675 (ASSERT_DUMP_EQ): Delete.
9676 (selftest::test_sm_state_map): Update for changes to region_model
9677 and sm_state_map, porting from svalue_id to const svalue *.
9678 (selftest::test_program_state_dumping): Likewise. Drop test of
9679 dumping, renaming to...
9680 (selftest::test_program_state_1): ...this.
9681 (selftest::test_program_state_dumping_2): Likewise, renaming to...
9682 (selftest::test_program_state_2): ...this.
9683 (selftest::test_program_state_merging): Update for changes to
9684 region_model.
9685 (selftest::test_program_state_merging_2): Likewise.
9686 (selftest::analyzer_program_state_cc_tests): Update for renamed
9687 tests.
9688 * program-state.h (extrinsic_state::extrinsic_state): Add logger
9689 and engine params.
9690 (extrinsic_state::get_logger): New accessor.
9691 (extrinsic_state::get_engine): New accessor.
9692 (extrinsic_state::get_model_manager): New accessor.
9693 (extrinsic_state::m_logger): New field.
9694 (extrinsic_state::m_engine): New field.
9695 (struct default_hash_traits<svalue_id>): Delete.
9696 (pod_hash_traits<svalue_id>::hash): Delete.
9697 (pod_hash_traits<svalue_id>::equal): Delete.
9698 (pod_hash_traits<svalue_id>::mark_deleted): Delete.
9699 (pod_hash_traits<svalue_id>::mark_empty): Delete.
9700 (pod_hash_traits<svalue_id>::is_deleted): Delete.
9701 (pod_hash_traits<svalue_id>::is_empty): Delete.
9702 (sm_state_map::entry_t::entry_t): Port from svalue_id to
9703 const svalue *.
9704 (sm_state_map::entry_t::m_origin): Likewise.
9705 (sm_state_map::map_t): Likewise.
9706 (sm_state_map::sm_state_map): Add state_machine and index params.
9707 (sm_state_map::clone_with_remapping): Delete.
9708 (sm_state_map::print): Drop sm param; add simple and multiline
9709 params.
9710 (sm_state_map::dump): Drop sm param; add simple param.
9711 (sm_state_map::get_state): Port from svalue_id to const svalue *.
9712 Add ext_state param.
9713 (sm_state_map::get_origin): Likewise.
9714 (sm_state_map::set_state): Likewise.
9715 (sm_state_map::impl_set_state): Likewise.
9716 (sm_state_map::purge_for_unknown_fncall): Delete.
9717 (sm_state_map::remap_svalue_ids): Delete.
9718 (sm_state_map::on_svalue_purge): Delete.
9719 (sm_state_map::on_svalue_leak): New.
9720 (sm_state_map::on_liveness_change): New.
9721 (sm_state_map::on_inherited_svalue): Delete.
9722 (sm_state_map::on_cast): Delete.
9723 (sm_state_map::validate): Delete.
9724 (sm_state_map::on_unknown_change): Port from svalue_id to
9725 const svalue *. Add is_mutable and ext_state params.
9726 (sm_state_map::canonicalize_svalue): New.
9727 (sm_state_map::m_sm): New field.
9728 (sm_state_map::m_sm_idx): New field.
9729 (program_state::operator=): Delete.
9730 (program_state::dump_to_pp): Drop "summarize" param, adding
9731 "simple" and "multiline".
9732 (program_state::dump_to_file): Likewise.
9733 (program_state::dump): Rename "summarize" to "simple".
9734 (program_state::push_frame): New.
9735 (program_state::get_current_function): New.
9736 (program_state::on_edge): Drop "change" param.
9737 (program_state::prune_for_point): Likewise. Add enode_for_diag
9738 param.
9739 (program_state::remap_svalue_ids): Delete.
9740 (program_state::get_representative_tree): Port from svalue_id to
9741 const svalue *.
9742 (program_state::can_purge_p): Likewise. Pass ext_state to get_state.
9743 (program_state::can_merge_with_p): Add point param.
9744 (program_state::detect_leaks): New.
9745 (state_change_visitor::on_state_change): Port from tree and
9746 svalue_id to a pair of const svalue *.
9747 (class state_change): Delete.
9748 * region.cc: New file.
9749 * region-model-impl-calls.cc: New file.
9750 * region-model-manager.cc: New file.
9751 * region-model-reachability.cc: New file.
9752 * region-model-reachability.h: New file.
9753 * region-model.cc: Include "analyzer/call-string.h",
9754 "analyzer/program-point.h", and "analyzer/store.h" before
9755 "analyzer/region-model.h". Include
9756 "analyzer/region-model-reachability.h".
9757 (dump_tree): Make non-static.
9758 (dump_quoted_tree): Make non-static.
9759 (print_quoted_type): Make non-static.
9760 (path_var::dump): Delete.
9761 (dump_separator): Delete.
9762 (class impl_constraint_manager): Delete.
9763 (svalue_id::print): Delete.
9764 (svalue_id::dump_node_name_to_pp): Delete.
9765 (svalue_id::validate): Delete.
9766 (region_id::print): Delete.
9767 (region_id::dump_node_name_to_pp): Delete.
9768 (region_id::validate): Delete.
9769 (region_id_set::region_id_set): Delete.
9770 (svalue_id_set::svalue_id_set): Delete.
9771 (svalue::operator==): Delete.
9772 (svalue::hash): Delete.
9773 (svalue::print): Delete.
9774 (svalue::dump_dot_to_pp): Delete.
9775 (svalue::remap_region_ids): Delete.
9776 (svalue::walk_for_canonicalization): Delete.
9777 (svalue::get_child_sid): Delete.
9778 (svalue::maybe_get_constant): Delete.
9779 (region_svalue::compare_fields): Delete.
9780 (region_svalue::add_to_hash): Delete.
9781 (region_svalue::print_details): Delete.
9782 (region_svalue::dump_dot_to_pp): Delete.
9783 (region_svalue::remap_region_ids): Delete.
9784 (region_svalue::merge_values): Delete.
9785 (region_svalue::walk_for_canonicalization): Delete.
9786 (region_svalue::eval_condition): Delete.
9787 (constant_svalue::compare_fields): Delete.
9788 (constant_svalue::add_to_hash): Delete.
9789 (constant_svalue::merge_values): Delete.
9790 (constant_svalue::eval_condition): Move to svalue.cc.
9791 (constant_svalue::print_details): Delete.
9792 (constant_svalue::get_child_sid): Delete.
9793 (unknown_svalue::compare_fields): Delete.
9794 (unknown_svalue::add_to_hash): Delete.
9795 (unknown_svalue::print_details): Delete.
9796 (poison_kind_to_str): Move to svalue.cc.
9797 (poisoned_svalue::compare_fields): Delete.
9798 (poisoned_svalue::add_to_hash): Delete.
9799 (poisoned_svalue::print_details): Delete.
9800 (region_kind_to_str): Move to region.cc and reimplement.
9801 (region::operator==): Delete.
9802 (region::get_parent_region): Delete.
9803 (region::set_value): Delete.
9804 (region::become_active_view): Delete.
9805 (region::deactivate_any_active_view): Delete.
9806 (region::deactivate_view): Delete.
9807 (region::get_value): Delete.
9808 (region::get_inherited_child_sid): Delete.
9809 (region_model::copy_region): Delete.
9810 (region_model::copy_struct_region): Delete.
9811 (region_model::copy_union_region): Delete.
9812 (region_model::copy_array_region): Delete.
9813 (region::hash): Delete.
9814 (region::print): Delete.
9815 (region::dump_dot_to_pp): Delete.
9816 (region::dump_to_pp): Delete.
9817 (region::dump_child_label): Delete.
9818 (region::validate): Delete.
9819 (region::remap_svalue_ids): Delete.
9820 (region::remap_region_ids): Delete.
9821 (region::add_view): Delete.
9822 (region::get_view): Delete.
9823 (region::region): Move to region.cc.
9824 (region::add_to_hash): Delete.
9825 (region::print_fields): Delete.
9826 (region::non_null_p): Delete.
9827 (primitive_region::clone): Delete.
9828 (primitive_region::walk_for_canonicalization): Delete.
9829 (map_region::map_region): Delete.
9830 (map_region::compare_fields): Delete.
9831 (map_region::print_fields): Delete.
9832 (map_region::validate): Delete.
9833 (map_region::dump_dot_to_pp): Delete.
9834 (map_region::dump_child_label): Delete.
9835 (map_region::get_or_create): Delete.
9836 (map_region::get): Delete.
9837 (map_region::add_to_hash): Delete.
9838 (map_region::remap_region_ids): Delete.
9839 (map_region::unbind): Delete.
9840 (map_region::get_tree_for_child_region): Delete.
9841 (map_region::get_tree_for_child_region): Delete.
9842 (tree_cmp): Move to region.cc.
9843 (map_region::can_merge_p): Delete.
9844 (map_region::walk_for_canonicalization): Delete.
9845 (map_region::get_value_by_name): Delete.
9846 (struct_or_union_region::valid_key_p): Delete.
9847 (struct_or_union_region::compare_fields): Delete.
9848 (struct_region::clone): Delete.
9849 (struct_region::compare_fields): Delete.
9850 (union_region::clone): Delete.
9851 (union_region::compare_fields): Delete.
9852 (frame_region::compare_fields): Delete.
9853 (frame_region::clone): Delete.
9854 (frame_region::valid_key_p): Delete.
9855 (frame_region::print_fields): Delete.
9856 (frame_region::add_to_hash): Delete.
9857 (globals_region::compare_fields): Delete.
9858 (globals_region::clone): Delete.
9859 (globals_region::valid_key_p): Delete.
9860 (code_region::compare_fields): Delete.
9861 (code_region::clone): Delete.
9862 (code_region::valid_key_p): Delete.
9863 (array_region::array_region): Delete.
9864 (array_region::get_element): Delete.
9865 (array_region::clone): Delete.
9866 (array_region::compare_fields): Delete.
9867 (array_region::print_fields): Delete.
9868 (array_region::validate): Delete.
9869 (array_region::dump_dot_to_pp): Delete.
9870 (array_region::dump_child_label): Delete.
9871 (array_region::get_or_create): Delete.
9872 (array_region::get): Delete.
9873 (array_region::add_to_hash): Delete.
9874 (array_region::remap_region_ids): Delete.
9875 (array_region::get_key_for_child_region): Delete.
9876 (array_region::key_cmp): Delete.
9877 (array_region::walk_for_canonicalization): Delete.
9878 (array_region::key_from_constant): Delete.
9879 (array_region::constant_from_key): Delete.
9880 (function_region::compare_fields): Delete.
9881 (function_region::clone): Delete.
9882 (function_region::valid_key_p): Delete.
9883 (stack_region::stack_region): Delete.
9884 (stack_region::compare_fields): Delete.
9885 (stack_region::clone): Delete.
9886 (stack_region::print_fields): Delete.
9887 (stack_region::dump_child_label): Delete.
9888 (stack_region::validate): Delete.
9889 (stack_region::push_frame): Delete.
9890 (stack_region::get_current_frame_id): Delete.
9891 (stack_region::pop_frame): Delete.
9892 (stack_region::add_to_hash): Delete.
9893 (stack_region::remap_region_ids): Delete.
9894 (stack_region::can_merge_p): Delete.
9895 (stack_region::walk_for_canonicalization): Delete.
9896 (stack_region::get_value_by_name): Delete.
9897 (heap_region::heap_region): Delete.
9898 (heap_region::compare_fields): Delete.
9899 (heap_region::clone): Delete.
9900 (heap_region::walk_for_canonicalization): Delete.
9901 (root_region::root_region): Delete.
9902 (root_region::compare_fields): Delete.
9903 (root_region::clone): Delete.
9904 (root_region::print_fields): Delete.
9905 (root_region::validate): Delete.
9906 (root_region::dump_child_label): Delete.
9907 (root_region::push_frame): Delete.
9908 (root_region::get_current_frame_id): Delete.
9909 (root_region::pop_frame): Delete.
9910 (root_region::ensure_stack_region): Delete.
9911 (root_region::get_stack_region): Delete.
9912 (root_region::ensure_globals_region): Delete.
9913 (root_region::get_code_region): Delete.
9914 (root_region::ensure_code_region): Delete.
9915 (root_region::get_globals_region): Delete.
9916 (root_region::ensure_heap_region): Delete.
9917 (root_region::get_heap_region): Delete.
9918 (root_region::remap_region_ids): Delete.
9919 (root_region::can_merge_p): Delete.
9920 (root_region::add_to_hash): Delete.
9921 (root_region::walk_for_canonicalization): Delete.
9922 (root_region::get_value_by_name): Delete.
9923 (symbolic_region::symbolic_region): Delete.
9924 (symbolic_region::compare_fields): Delete.
9925 (symbolic_region::clone): Delete.
9926 (symbolic_region::walk_for_canonicalization): Delete.
9927 (symbolic_region::print_fields): Delete.
9928 (region_model::region_model): Add region_model_manager * param.
9929 Reimplement in terms of store, dropping impl_constraint_manager
9930 subclass.
9931 (region_model::operator=): Reimplement in terms of store
9932 (region_model::operator==): Likewise.
9933 (region_model::hash): Likewise.
9934 (region_model::print): Delete.
9935 (region_model::print_svalue): Delete.
9936 (region_model::dump_dot_to_pp): Delete.
9937 (region_model::dump_dot_to_file): Delete.
9938 (region_model::dump_dot): Delete.
9939 (region_model::dump_to_pp): Replace "summarize" param with
9940 "simple" and "multiline". Port to store-based implementation.
9941 (region_model::dump): Replace "summarize" param with "simple" and
9942 "multiline".
9943 (dump_vec_of_tree): Delete.
9944 (region_model::dump_summary_of_rep_path_vars): Delete.
9945 (region_model::validate): Delete.
9946 (svalue_id_cmp_by_constant_svalue_model): Delete.
9947 (svalue_id_cmp_by_constant_svalue): Delete.
9948 (region_model::canonicalize): Drop "ctxt" param. Reimplement in
9949 terms of store and constraints.
9950 (region_model::canonicalized_p): Remove NULL arg to canonicalize.
9951 (region_model::loop_replay_fixup): New.
9952 (poisoned_value_diagnostic::emit): Tweak wording of warnings.
9953 (region_model::check_for_poison): Delete.
9954 (region_model::get_gassign_result): New.
9955 (region_model::on_assignment): Port to store-based implementation.
9956 (region_model::on_call_pre): Delete calls to check_for_poison.
9957 Move implementations to region-model-impl-calls.c and port to
9958 store-based implementation.
9959 (region_model::on_call_post): Likewise.
9960 (class reachable_regions): Move to region-model-reachability.h/cc
9961 and port to store-based implementation.
9962 (region_model::handle_unrecognized_call): Port to store-based
9963 implementation.
9964 (region_model::get_reachable_svalues): New.
9965 (region_model::on_setjmp): Port to store-based implementation.
9966 (region_model::on_longjmp): Likewise.
9967 (region_model::handle_phi): Drop is_back_edge param and the logic
9968 using it.
9969 (region_model::get_lvalue_1): Port from region_id to const region *.
9970 (region_model::make_region_for_unexpected_tree_code): Delete.
9971 (assert_compat_types): If the check fails, use internal_error to
9972 show the types.
9973 (region_model::get_lvalue): Port from region_id to const region *.
9974 (region_model::get_rvalue_1): Port from svalue_id to const svalue *.
9975 (region_model::get_rvalue): Likewise.
9976 (region_model::get_or_create_ptr_svalue): Delete.
9977 (region_model::get_or_create_constant_svalue): Delete.
9978 (region_model::get_svalue_for_fndecl): Delete.
9979 (region_model::get_region_for_fndecl): Delete.
9980 (region_model::get_svalue_for_label): Delete.
9981 (region_model::get_region_for_label): Delete.
9982 (build_cast): Delete.
9983 (region_model::maybe_cast_1): Delete.
9984 (region_model::maybe_cast): Delete.
9985 (region_model::get_field_region): Delete.
9986 (region_model::get_store_value): New.
9987 (region_model::region_exists_p): New.
9988 (region_model::deref_rvalue): Port from svalue_id to const svalue *.
9989 (region_model::set_value): Likewise.
9990 (region_model::clobber_region): New.
9991 (region_model::purge_region): New.
9992 (region_model::zero_fill_region): New.
9993 (region_model::mark_region_as_unknown): New.
9994 (region_model::eval_condition): Port from svalue_id to
9995 const svalue *.
9996 (region_model::eval_condition_without_cm): Likewise.
9997 (region_model::compare_initial_and_pointer): New.
9998 (region_model::add_constraint): Port from svalue_id to
9999 const svalue *.
10000 (region_model::maybe_get_constant): Delete.
10001 (region_model::get_representative_path_var): New.
10002 (region_model::add_new_malloc_region): Delete.
10003 (region_model::get_representative_tree): Port to const svalue *.
10004 (region_model::get_representative_path_var): Port to
10005 const region *.
10006 (region_model::get_path_vars_for_svalue): Delete.
10007 (region_model::set_to_new_unknown_value): Delete.
10008 (region_model::update_for_phis): Don't pass is_back_edge to handle_phi.
10009 (region_model::update_for_call_superedge): Port from svalue_id to
10010 const svalue *.
10011 (region_model::update_for_return_superedge): Port to store-based
10012 implementation.
10013 (region_model::update_for_call_summary): Replace
10014 set_to_new_unknown_value with mark_region_as_unknown.
10015 (region_model::get_root_region): Delete.
10016 (region_model::get_stack_region_id): Delete.
10017 (region_model::push_frame): Delete.
10018 (region_model::get_current_frame_id): Delete.
10019 (region_model::get_current_function): Delete.
10020 (region_model::pop_frame): Delete.
10021 (region_model::on_top_level_param): New.
10022 (region_model::get_stack_depth): Delete.
10023 (region_model::get_function_at_depth): Delete.
10024 (region_model::get_globals_region_id): Delete.
10025 (region_model::add_svalue): Delete.
10026 (region_model::replace_svalue): Delete.
10027 (region_model::add_region): Delete.
10028 (region_model::get_svalue): Delete.
10029 (region_model::get_region): Delete.
10030 (make_region_for_type): Delete.
10031 (region_model::add_region_for_type): Delete.
10032 (region_model::on_top_level_param): New.
10033 (class restrict_to_used_svalues): Delete.
10034 (region_model::purge_unused_svalues): Delete.
10035 (region_model::push_frame): New.
10036 (region_model::remap_svalue_ids): Delete.
10037 (region_model::remap_region_ids): Delete.
10038 (region_model::purge_regions): Delete.
10039 (region_model::get_descendents): Delete.
10040 (region_model::delete_region_and_descendents): Delete.
10041 (region_model::poison_any_pointers_to_bad_regions): Delete.
10042 (region_model::can_merge_with_p): Delete.
10043 (region_model::get_current_function): New.
10044 (region_model::get_value_by_name): Delete.
10045 (region_model::convert_byte_offset_to_array_index): Delete.
10046 (region_model::pop_frame): New.
10047 (region_model::get_or_create_mem_ref): Delete.
10048 (region_model::get_stack_depth): New.
10049 (region_model::get_frame_at_index): New.
10050 (region_model::unbind_region_and_descendents): New.
10051 (struct bad_pointer_finder): New.
10052 (region_model::get_or_create_pointer_plus_expr): Delete.
10053 (region_model::poison_any_pointers_to_descendents): New.
10054 (region_model::get_or_create_view): Delete.
10055 (region_model::can_merge_with_p): New.
10056 (region_model::get_fndecl_for_call): Port from svalue_id to
10057 const svalue *.
10058 (struct append_ssa_names_cb_data): New.
10059 (get_ssa_name_regions_for_current_frame): New.
10060 (region_model::append_ssa_names_cb): New.
10061 (model_merger::dump_to_pp): Add "simple" param. Drop dumping of
10062 remappings.
10063 (model_merger::dump): Add "simple" param to both overloads.
10064 (model_merger::can_merge_values_p): Delete.
10065 (model_merger::record_regions): Delete.
10066 (model_merger::record_svalues): Delete.
10067 (svalue_id_merger_mapping::svalue_id_merger_mapping): Delete.
10068 (svalue_id_merger_mapping::dump_to_pp): Delete.
10069 (svalue_id_merger_mapping::dump): Delete.
10070 (region_model::create_region_for_heap_alloc): New.
10071 (region_model::create_region_for_alloca): New.
10072 (region_model::record_dynamic_extents): New.
10073 (canonicalization::canonicalization): Delete.
10074 (canonicalization::walk_rid): Delete.
10075 (canonicalization::walk_sid): Delete.
10076 (canonicalization::dump_to_pp): Delete.
10077 (canonicalization::dump): Delete.
10078 (inchash::add): Delete overloads for svalue_id and region_id.
10079 (engine::log_stats): New.
10080 (assert_condition): Add overload comparing svalues.
10081 (assert_dump_eq): Pass "true" for multiline.
10082 (selftest::test_dump): Update for rewrite of region_model.
10083 (selftest::test_dump_2): Rename to...
10084 (selftest::test_struct): ...this. Provide a region_model_manager
10085 when creating region_model instance. Remove dump test. Add
10086 checks for get_offset.
10087 (selftest::test_dump_3): Rename to...
10088 (selftest::test_array_1): ...this. Provide a region_model_manager
10089 when creating region_model instance. Remove dump test.
10090 (selftest::test_get_representative_tree): Port from svalue_id to
10091 new API. Add test coverage for various expressions.
10092 (selftest::test_unique_constants): Provide a region_model_manager
10093 for the region_model. Add test coverage for comparing const vs
10094 non-const.
10095 (selftest::test_svalue_equality): Delete.
10096 (selftest::test_region_equality): Delete.
10097 (selftest::test_unique_unknowns): New.
10098 (class purge_all_svalue_ids): Delete.
10099 (class purge_one_svalue_id): Delete.
10100 (selftest::test_purging_by_criteria): Delete.
10101 (selftest::test_initial_svalue_folding): New.
10102 (selftest::test_unaryop_svalue_folding): New.
10103 (selftest::test_binop_svalue_folding): New.
10104 (selftest::test_sub_svalue_folding): New.
10105 (selftest::test_purge_unused_svalues): Delete.
10106 (selftest::test_descendent_of_p): New.
10107 (selftest::test_assignment): Provide a region_model_manager for
10108 the region_model. Drop the dump test.
10109 (selftest::test_compound_assignment): Likewise.
10110 (selftest::test_stack_frames): Port to new implementation.
10111 (selftest::test_get_representative_path_var): Likewise.
10112 (selftest::test_canonicalization_1): Rename to...
10113 (selftest::test_equality_1): ...this. Port to new API, and add
10114 (selftest::test_canonicalization_2): Provide a
10115 region_model_manager when creating region_model instances.
10116 Remove redundant canicalization.
10117 (selftest::test_canonicalization_3): Provide a
10118 region_model_manager when creating region_model instances.
10119 Remove param from calls to region_model::canonicalize.
10120 (selftest::test_canonicalization_4): Likewise.
10121 (selftest::assert_region_models_merge): Constify
10122 out_merged_svalue. Port to new API.
10123 (selftest::test_state_merging): Provide a
10124 region_model_manager when creating region_model instances.
10125 Provide a program_point point when merging them. Replace
10126 set_to_new_unknown_value with usage of placeholder_svalues.
10127 Drop get_value_by_name. Port from svalue_id to const svalue *.
10128 Add test of heap allocation.
10129 (selftest::test_constraint_merging): Provide a
10130 region_model_manager when creating region_model instances.
10131 Provide a program_point point when merging them. Eliminate use
10132 of set_to_new_unknown_value.
10133 (selftest::test_widening_constraints): New.
10134 (selftest::test_iteration_1): New.
10135 (selftest::test_malloc_constraints): Port to store-based
10136 implementation.
10137 (selftest::test_var): New test.
10138 (selftest::test_array_2): New test.
10139 (selftest::test_mem_ref): New test.
10140 (selftest::test_POINTER_PLUS_EXPR_then_MEM_REF): New.
10141 (selftest::test_malloc): New.
10142 (selftest::test_alloca): New.
10143 (selftest::analyzer_region_model_cc_tests): Update for renamings.
10144 Call new functions.
10145 * region-model.h (class path_var): Move to analyzer.h.
10146 (class svalue_id): Delete.
10147 (class region_id): Delete.
10148 (class id_map): Delete.
10149 (svalue_id_map): Delete.
10150 (region_id_map): Delete.
10151 (id_map<T>::id_map): Delete.
10152 (id_map<T>::put): Delete.
10153 (id_map<T>::get_dst_for_src): Delete.
10154 (id_map<T>::get_src_for_dst): Delete.
10155 (id_map<T>::dump_to_pp): Delete.
10156 (id_map<T>::dump): Delete.
10157 (id_map<T>::update): Delete.
10158 (one_way_svalue_id_map): Delete.
10159 (one_way_region_id_map): Delete.
10160 (class region_id_set): Delete.
10161 (class svalue_id_set): Delete.
10162 (struct complexity): New.
10163 (class visitor): New.
10164 (enum svalue_kind): Add SK_SETJMP, SK_INITIAL, SK_UNARYOP,
10165 SK_BINOP, SK_SUB,SK_UNMERGEABLE, SK_PLACEHOLDER, SK_WIDENING,
10166 SK_COMPOUND, and SK_CONJURED.
10167 (svalue::operator==): Delete.
10168 (svalue::operator!=): Delete.
10169 (svalue::clone): Delete.
10170 (svalue::hash): Delete.
10171 (svalue::dump_dot_to_pp): Delete.
10172 (svalue::dump_to_pp): New.
10173 (svalue::dump): New.
10174 (svalue::get_desc): New.
10175 (svalue::dyn_cast_initial_svalue): New.
10176 (svalue::dyn_cast_unaryop_svalue): New.
10177 (svalue::dyn_cast_binop_svalue): New.
10178 (svalue::dyn_cast_sub_svalue): New.
10179 (svalue::dyn_cast_unmergeable_svalue): New.
10180 (svalue::dyn_cast_widening_svalue): New.
10181 (svalue::dyn_cast_compound_svalue): New.
10182 (svalue::dyn_cast_conjured_svalue): New.
10183 (svalue::maybe_undo_cast): New.
10184 (svalue::unwrap_any_unmergeable): New.
10185 (svalue::remap_region_ids): Delete
10186 (svalue::can_merge_p): New.
10187 (svalue::walk_for_canonicalization): Delete
10188 (svalue::get_complexity): New.
10189 (svalue::get_child_sid): Delete
10190 (svalue::accept): New.
10191 (svalue::live_p): New.
10192 (svalue::implicitly_live_p): New.
10193 (svalue::svalue): Add complexity param.
10194 (svalue::add_to_hash): Delete
10195 (svalue::print_details): Delete
10196 (svalue::m_complexity): New field.
10197 (region_svalue::key_t): New struct.
10198 (region_svalue::region_svalue): Port from region_id to
10199 const region_id *. Add complexity.
10200 (region_svalue::compare_fields): Delete.
10201 (region_svalue::clone): Delete.
10202 (region_svalue::dump_dot_to_pp): Delete.
10203 (region_svalue::get_pointee): Port from region_id to
10204 const region_id *.
10205 (region_svalue::remap_region_ids): Delete.
10206 (region_svalue::merge_values): Delete.
10207 (region_svalue::dump_to_pp): New.
10208 (region_svalue::accept): New.
10209 (region_svalue::walk_for_canonicalization): Delete.
10210 (region_svalue::eval_condition): Make params const.
10211 (region_svalue::add_to_hash): Delete.
10212 (region_svalue::print_details): Delete.
10213 (region_svalue::m_rid): Replace with...
10214 (region_svalue::m_reg): ...this.
10215 (is_a_helper <region_svalue *>::test): Convert to...
10216 (is_a_helper <const region_svalue *>::test): ...this.
10217 (template <> struct default_hash_traits<region_svalue::key_t>):
10218 New.
10219 (constant_svalue::constant_svalue): Add complexity.
10220 (constant_svalue::compare_fields): Delete.
10221 (constant_svalue::clone): Delete.
10222 (constant_svalue::add_to_hash): Delete.
10223 (constant_svalue::dump_to_pp): New.
10224 (constant_svalue::accept): New.
10225 (constant_svalue::implicitly_live_p): New.
10226 (constant_svalue::merge_values): Delete.
10227 (constant_svalue::eval_condition): Make params const.
10228 (constant_svalue::get_child_sid): Delete.
10229 (constant_svalue::print_details): Delete.
10230 (is_a_helper <constant_svalue *>::test): Convert to...
10231 (is_a_helper <const constant_svalue *>::test): ...this.
10232 (class unknown_svalue): Update leading comment.
10233 (unknown_svalue::unknown_svalue): Add complexity.
10234 (unknown_svalue::compare_fields): Delete.
10235 (unknown_svalue::add_to_hash): Delete.
10236 (unknown_svalue::dyn_cast_unknown_svalue): Delete.
10237 (unknown_svalue::print_details): Delete.
10238 (unknown_svalue::dump_to_pp): New.
10239 (unknown_svalue::accept): New.
10240 (poisoned_svalue::key_t): New struct.
10241 (poisoned_svalue::poisoned_svalue): Add complexity.
10242 (poisoned_svalue::compare_fields): Delete.
10243 (poisoned_svalue::clone): Delete.
10244 (poisoned_svalue::add_to_hash): Delete.
10245 (poisoned_svalue::dump_to_pp): New.
10246 (poisoned_svalue::accept): New.
10247 (poisoned_svalue::print_details): Delete.
10248 (is_a_helper <poisoned_svalue *>::test): Convert to...
10249 (is_a_helper <const poisoned_svalue *>::test): ...this.
10250 (template <> struct default_hash_traits<poisoned_svalue::key_t>):
10251 New.
10252 (setjmp_record::add_to_hash): New.
10253 (setjmp_svalue::key_t): New struct.
10254 (setjmp_svalue::compare_fields): Delete.
10255 (setjmp_svalue::clone): Delete.
10256 (setjmp_svalue::add_to_hash): Delete.
10257 (setjmp_svalue::setjmp_svalue): Add complexity.
10258 (setjmp_svalue::dump_to_pp): New.
10259 (setjmp_svalue::accept): New.
10260 (setjmp_svalue::void print_details): Delete.
10261 (is_a_helper <const setjmp_svalue *>::test): New.
10262 (template <> struct default_hash_traits<setjmp_svalue::key_t>): New.
10263 (class initial_svalue : public svalue): New.
10264 (is_a_helper <const initial_svalue *>::test): New.
10265 (class unaryop_svalue): New.
10266 (is_a_helper <const unaryop_svalue *>::test): New.
10267 (template <> struct default_hash_traits<unaryop_svalue::key_t>): New.
10268 (class binop_svalue): New.
10269 (is_a_helper <const binop_svalue *>::test): New.
10270 (template <> struct default_hash_traits<binop_svalue::key_t>): New.
10271 (class sub_svalue): New.
10272 (is_a_helper <const sub_svalue *>::test): New.
10273 (template <> struct default_hash_traits<sub_svalue::key_t>): New.
10274 (class unmergeable_svalue): New.
10275 (is_a_helper <const unmergeable_svalue *>::test): New.
10276 (class placeholder_svalue): New.
10277 (is_a_helper <placeholder_svalue *>::test): New.
10278 (class widening_svalue): New.
10279 (is_a_helper <widening_svalue *>::test): New.
10280 (template <> struct default_hash_traits<widening_svalue::key_t>): New.
10281 (class compound_svalue): New.
10282 (is_a_helper <compound_svalue *>::test): New.
10283 (template <> struct default_hash_traits<compound_svalue::key_t>): New.
10284 (class conjured_svalue): New.
10285 (is_a_helper <conjured_svalue *>::test): New.
10286 (template <> struct default_hash_traits<conjured_svalue::key_t>): New.
10287 (enum region_kind): Delete RK_PRIMITIVE, RK_STRUCT, RK_UNION, and
10288 RK_ARRAY. Add RK_LABEL, RK_DECL, RK_FIELD, RK_ELEMENT, RK_OFFSET,
10289 RK_CAST, RK_HEAP_ALLOCATED, RK_ALLOCA, RK_STRING, and RK_UNKNOWN.
10290 (region_kind_to_str): Delete.
10291 (region::~region): Move implementation to region.cc.
10292 (region::operator==): Delete.
10293 (region::operator!=): Delete.
10294 (region::clone): Delete.
10295 (region::get_id): New.
10296 (region::cmp_ids): New.
10297 (region::dyn_cast_map_region): Delete.
10298 (region::dyn_cast_array_region): Delete.
10299 (region::region_id get_parent): Delete.
10300 (region::get_parent_region): Convert to a simple accessor.
10301 (region::void set_value): Delete.
10302 (region::svalue_id get_value): Delete.
10303 (region::svalue_id get_value_direct): Delete.
10304 (region::svalue_id get_inherited_child_sid): Delete.
10305 (region::dyn_cast_frame_region): New.
10306 (region::dyn_cast_function_region): New.
10307 (region::dyn_cast_decl_region): New.
10308 (region::dyn_cast_field_region): New.
10309 (region::dyn_cast_element_region): New.
10310 (region::dyn_cast_offset_region): New.
10311 (region::dyn_cast_cast_region): New.
10312 (region::dyn_cast_string_region): New.
10313 (region::accept): New.
10314 (region::get_base_region): New.
10315 (region::base_region_p): New.
10316 (region::descendent_of_p): New.
10317 (region::maybe_get_frame_region): New.
10318 (region::maybe_get_decl): New.
10319 (region::hash): Delete.
10320 (region::rint): Delete.
10321 (region::dump_dot_to_pp): Delete.
10322 (region::get_desc): New.
10323 (region::dump_to_pp): Convert to vfunc, changing signature.
10324 (region::dump_child_label): Delete.
10325 (region::remap_svalue_ids): Delete.
10326 (region::remap_region_ids): Delete.
10327 (region::dump): New.
10328 (region::walk_for_canonicalization): Delete.
10329 (region::non_null_p): Drop region_model param.
10330 (region::add_view): Delete.
10331 (region::get_view): Delete.
10332 (region::get_active_view): Delete.
10333 (region::is_view_p): Delete.
10334 (region::cmp_ptrs): New.
10335 (region::validate): Delete.
10336 (region::get_offset): New.
10337 (region::get_byte_size): New.
10338 (region::get_bit_size): New.
10339 (region::get_subregions_for_binding): New.
10340 (region::region): Add complexity param. Convert parent from
10341 region_id to const region *. Drop svalue_id. Drop copy ctor.
10342 (region::symbolic_for_unknown_ptr_p): New.
10343 (region::add_to_hash): Delete.
10344 (region::print_fields): Delete.
10345 (region::get_complexity): New accessor.
10346 (region::become_active_view): Delete.
10347 (region::deactivate_any_active_view): Delete.
10348 (region::deactivate_view): Delete.
10349 (region::calc_offset): New.
10350 (region::m_parent_rid): Delete.
10351 (region::m_sval_id): Delete.
10352 (region::m_complexity): New.
10353 (region::m_id): New.
10354 (region::m_parent): New.
10355 (region::m_view_rids): Delete.
10356 (region::m_is_view): Delete.
10357 (region::m_active_view_rid): Delete.
10358 (region::m_cached_offset): New.
10359 (is_a_helper <region *>::test): Convert to...
10360 (is_a_helper <const region *>::test): ... this.
10361 (class primitive_region): Delete.
10362 (class space_region): New.
10363 (class map_region): Delete.
10364 (is_a_helper <map_region *>::test): Delete.
10365 (class frame_region): Reimplement.
10366 (template <> struct default_hash_traits<frame_region::key_t>):
10367 New.
10368 (class globals_region): Reimplement.
10369 (is_a_helper <globals_region *>::test): Convert to...
10370 (is_a_helper <const globals_region *>::test): ...this.
10371 (class struct_or_union_region): Delete.
10372 (is_a_helper <struct_or_union_region *>::test): Delete.
10373 (class code_region): Reimplement.
10374 (is_a_helper <const code_region *>::test): New.
10375 (class struct_region): Delete.
10376 (is_a_helper <struct_region *>::test): Delete.
10377 (class function_region): Reimplement.
10378 (is_a_helper <function_region *>::test): Convert to...
10379 (is_a_helper <const function_region *>::test): ...this.
10380 (class union_region): Delete.
10381 (is_a_helper <union_region *>::test): Delete.
10382 (class label_region): New.
10383 (is_a_helper <const label_region *>::test): New.
10384 (class scope_region): Delete.
10385 (class stack_region): Reimplement.
10386 (is_a_helper <stack_region *>::test): Convert to...
10387 (is_a_helper <const stack_region *>::test): ...this.
10388 (class heap_region): Reimplement.
10389 (is_a_helper <heap_region *>::test): Convert to...
10390 (is_a_helper <const heap_region *>::test): ...this.
10391 (class root_region): Reimplement.
10392 (is_a_helper <root_region *>::test): Convert to...
10393 (is_a_helper <const root_region *>::test): ...this.
10394 (class symbolic_region): Reimplement.
10395 (is_a_helper <const symbolic_region *>::test): New.
10396 (template <> struct default_hash_traits<symbolic_region::key_t>):
10397 New.
10398 (class decl_region): New.
10399 (is_a_helper <const decl_region *>::test): New.
10400 (class field_region): New.
10401 (template <> struct default_hash_traits<field_region::key_t>): New.
10402 (class array_region): Delete.
10403 (class element_region): New.
10404 (is_a_helper <array_region *>::test): Delete.
10405 (is_a_helper <const element_region *>::test): New.
10406 (template <> struct default_hash_traits<element_region::key_t>):
10407 New.
10408 (class offset_region): New.
10409 (is_a_helper <const offset_region *>::test): New.
10410 (template <> struct default_hash_traits<offset_region::key_t>):
10411 New.
10412 (class cast_region): New.
10413 (is_a_helper <const cast_region *>::test): New.
10414 (template <> struct default_hash_traits<cast_region::key_t>): New.
10415 (class heap_allocated_region): New.
10416 (class alloca_region): New.
10417 (class string_region): New.
10418 (is_a_helper <const string_region *>::test): New.
10419 (class unknown_region): New.
10420 (class region_model_manager): New.
10421 (struct append_ssa_names_cb_data): New.
10422 (class call_details): New.
10423 (region_model::region_model): Add region_model_manager param.
10424 (region_model::print_svalue): Delete.
10425 (region_model::dump_dot_to_pp): Delete.
10426 (region_model::dump_dot_to_file): Delete.
10427 (region_model::dump_dot): Delete.
10428 (region_model::dump_to_pp): Drop summarize param in favor of
10429 simple and multiline.
10430 (region_model::dump): Likewise.
10431 (region_model::summarize_to_pp): Delete.
10432 (region_model::summarize): Delete.
10433 (region_model::void canonicalize): Drop ctxt param.
10434 (region_model::void check_for_poison): Delete.
10435 (region_model::get_gassign_result): New.
10436 (region_model::impl_call_alloca): New.
10437 (region_model::impl_call_analyzer_describe): New.
10438 (region_model::impl_call_analyzer_eval): New.
10439 (region_model::impl_call_builtin_expect): New.
10440 (region_model::impl_call_calloc): New.
10441 (region_model::impl_call_free): New.
10442 (region_model::impl_call_malloc): New.
10443 (region_model::impl_call_memset): New.
10444 (region_model::impl_call_strlen): New.
10445 (region_model::get_reachable_svalues): New.
10446 (region_model::handle_phi): Drop is_back_edge param.
10447 (region_model::region_id get_root_rid): Delete.
10448 (region_model::root_region *get_root_region): Delete.
10449 (region_model::region_id get_stack_region_id): Delete.
10450 (region_model::push_frame): Convert from region_id and svalue_id
10451 to const region * and const svalue *.
10452 (region_model::get_current_frame_id): Replace with...
10453 (region_model::get_current_frame): ...this.
10454 (region_model::pop_frame): Convert from region_id to
10455 const region *. Drop purge and stats param. Add out_result.
10456 (region_model::function *get_function_at_depth): Delete.
10457 (region_model::get_globals_region_id): Delete.
10458 (region_model::add_svalue): Delete.
10459 (region_model::replace_svalue): Delete.
10460 (region_model::add_region): Delete.
10461 (region_model::add_region_for_type): Delete.
10462 (region_model::get_svalue): Delete.
10463 (region_model::get_region): Delete.
10464 (region_model::get_lvalue): Convert from region_id to
10465 const region *.
10466 (region_model::get_rvalue): Convert from svalue_id to
10467 const svalue *.
10468 (region_model::get_or_create_ptr_svalue): Delete.
10469 (region_model::get_or_create_constant_svalue): Delete.
10470 (region_model::get_svalue_for_fndecl): Delete.
10471 (region_model::get_svalue_for_label): Delete.
10472 (region_model::get_region_for_fndecl): Delete.
10473 (region_model::get_region_for_label): Delete.
10474 (region_model::get_frame_at_index (int index) const;): New.
10475 (region_model::maybe_cast): Delete.
10476 (region_model::maybe_cast_1): Delete.
10477 (region_model::get_field_region): Delete.
10478 (region_model::id deref_rvalue): Convert from region_id and
10479 svalue_id to const region * and const svalue *. Drop overload,
10480 passing in both a tree and an svalue.
10481 (region_model::set_value): Convert from region_id and svalue_id to
10482 const region * and const svalue *.
10483 (region_model::set_to_new_unknown_value): Delete.
10484 (region_model::clobber_region (const region *reg);): New.
10485 (region_model::purge_region (const region *reg);): New.
10486 (region_model::zero_fill_region (const region *reg);): New.
10487 (region_model::mark_region_as_unknown (const region *reg);): New.
10488 (region_model::copy_region): Convert from region_id to
10489 const region *.
10490 (region_model::eval_condition): Convert from svalue_id to
10491 const svalue *.
10492 (region_model::eval_condition_without_cm): Likewise.
10493 (region_model::compare_initial_and_pointer): New.
10494 (region_model:maybe_get_constant): Delete.
10495 (region_model::add_new_malloc_region): Delete.
10496 (region_model::get_representative_tree): Convert from svalue_id to
10497 const svalue *.
10498 (region_model::get_representative_path_var): Delete decl taking a
10499 region_id in favor of two decls, for svalue vs region, with an
10500 svalue_set to ensure termination.
10501 (region_model::get_path_vars_for_svalue): Delete.
10502 (region_model::create_region_for_heap_alloc): New.
10503 (region_model::create_region_for_alloca): New.
10504 (region_model::purge_unused_svalues): Delete.
10505 (region_model::remap_svalue_ids): Delete.
10506 (region_model::remap_region_ids): Delete.
10507 (region_model::purge_regions): Delete.
10508 (region_model::get_num_svalues): Delete.
10509 (region_model::get_num_regions): Delete.
10510 (region_model::get_descendents): Delete.
10511 (region_model::get_store): New.
10512 (region_model::delete_region_and_descendents): Delete.
10513 (region_model::get_manager): New.
10514 (region_model::unbind_region_and_descendents): New.
10515 (region_model::can_merge_with_p): Add point param. Drop
10516 svalue_id_merger_mapping.
10517 (region_model::get_value_by_name): Delete.
10518 (region_model::convert_byte_offset_to_array_index): Delete.
10519 (region_model::get_or_create_mem_ref): Delete.
10520 (region_model::get_or_create_pointer_plus_expr): Delete.
10521 (region_model::get_or_create_view): Delete.
10522 (region_model::get_lvalue_1): Convert from region_id to
10523 const region *.
10524 (region_model::get_rvalue_1): Convert from svalue_id to
10525 const svalue *.
10526 (region_model::get_ssa_name_regions_for_current_frame): New.
10527 (region_model::append_ssa_names_cb): New.
10528 (region_model::get_store_value): New.
10529 (region_model::copy_struct_region): Delete.
10530 (region_model::copy_union_region): Delete.
10531 (region_model::copy_array_region): Delete.
10532 (region_model::region_exists_p): New.
10533 (region_model::make_region_for_unexpected_tree_code): Delete.
10534 (region_model::loop_replay_fixup): New.
10535 (region_model::poison_any_pointers_to_bad_regions): Delete.
10536 (region_model::poison_any_pointers_to_descendents): New.
10537 (region_model::dump_summary_of_rep_path_vars): Delete.
10538 (region_model::on_top_level_param): New.
10539 (region_model::record_dynamic_extents): New.
10540 (region_model::m_mgr;): New.
10541 (region_model::m_store;): New.
10542 (region_model::m_svalues;): Delete.
10543 (region_model::m_regions;): Delete.
10544 (region_model::m_root_rid;): Delete.
10545 (region_model::m_current_frame;): New.
10546 (region_model_context::remap_svalue_ids): Delete.
10547 (region_model_context::can_purge_p): Delete.
10548 (region_model_context::on_svalue_leak): New.
10549 (region_model_context::on_svalue_purge): Delete.
10550 (region_model_context::on_liveness_change): New.
10551 (region_model_context::on_inherited_svalue): Delete.
10552 (region_model_context::on_cast): Delete.
10553 (region_model_context::on_unknown_change): Convert from svalue_id to
10554 const svalue * and add is_mutable.
10555 (class noop_region_model_context): Update for region_model_context
10556 changes.
10557 (model_merger::model_merger): Add program_point. Drop
10558 svalue_id_merger_mapping.
10559 (model_merger::dump_to_pp): Add "simple" param.
10560 (model_merger::dump): Likewise.
10561 (model_merger::get_region_a): Delete.
10562 (model_merger::get_region_b): Delete.
10563 (model_merger::can_merge_values_p): Delete.
10564 (model_merger::record_regions): Delete.
10565 (model_merger::record_svalues): Delete.
10566 (model_merger::m_point): New field.
10567 (model_merger::m_map_regions_from_a_to_m): Delete.
10568 (model_merger::m_map_regions_from_b_to_m): Delete.
10569 (model_merger::m_sid_mapping): Delete.
10570 (struct svalue_id_merger_mapping): Delete.
10571 (class engine): New.
10572 (struct canonicalization): Delete.
10573 (inchash::add): Delete decls for hashing svalue_id and region_id.
10574 (test_region_model_context::on_unexpected_tree_code): Require t to
10575 be non-NULL.
10576 (selftest::assert_condition): Add overload comparing a pair of
10577 const svalue *.
10578 * sm-file.cc: Include "tristate.h", "selftest.h",
10579 "analyzer/call-string.h", "analyzer/program-point.h",
10580 "analyzer/store.h", and "analyzer/region-model.h".
10581 (fileptr_state_machine::get_default_state): New.
10582 (fileptr_state_machine::on_stmt): Remove calls to
10583 get_readable_tree in favor of get_diagnostic_tree.
10584 * sm-malloc.cc: Include "tristate.h", "selftest.h",
10585 "analyzer/call-string.h", "analyzer/program-point.h",
10586 "analyzer/store.h", and "analyzer/region-model.h".
10587 (malloc_state_machine::get_default_state): New.
10588 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New.
10589 (malloc_diagnostic::describe_state_change): Handle change.m_expr
10590 being NULL.
10591 (null_arg::emit): Avoid printing "NULL '0'".
10592 (null_arg::describe_final_event): Avoid printing "(0) NULL".
10593 (malloc_leak::emit): Handle m_arg being NULL.
10594 (malloc_leak::describe_final_event): Handle ev.m_expr being NULL.
10595 (malloc_state_machine::on_stmt): Don't call get_readable_tree.
10596 Call get_diagnostic_tree when creating pending diagnostics.
10597 Update for is_zero_assignment becoming a member function of
10598 sm_ctxt.
10599 Don't transition to m_non_heap for ADDR_EXPR(MEM_REF()).
10600 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New
10601 vfunc implementation.
10602 * sm-sensitive.cc (sensitive_state_machine::warn_for_any_exposure): Call
10603 get_diagnostic_tree and pass the result to warn_for_state.
10604 * sm-signal.cc: Move includes of "analyzer/call-string.h" and
10605 "analyzer/program-point.h" to before "analyzer/region-model.h",
10606 and also include "analyzer/store.h" before it.
10607 (signal_unsafe_call::describe_state_change): Use
10608 get_dest_function to get handler.
10609 (update_model_for_signal_handler): Pass manager to region_model
10610 ctor.
10611 (register_signal_handler::impl_transition): Update for changes to
10612 get_or_create_node and add_edge.
10613 * sm-taint.cc (taint_state_machine::on_stmt): Remove calls to
10614 get_readable_tree, replacing them when calling warn_for_state with
10615 calls to get_diagnostic_tree.
10616 * sm.cc (is_zero_assignment): Delete.
10617 (any_pointer_p): Move to within namespace ana.
10618 * sm.h (is_zero_assignment): Remove decl.
10619 (any_pointer_p): Move decl to within namespace ana.
10620 (state_machine::get_default_state): New vfunc.
10621 (state_machine::reset_when_passed_to_unknown_fn_p): New vfunc.
10622 (sm_context::get_readable_tree): Rename to...
10623 (sm_context::get_diagnostic_tree): ...this.
10624 (sm_context::is_zero_assignment): New vfunc.
10625 * store.cc: New file.
10626 * store.h: New file.
10627 * svalue.cc: New file.
10628
10629 2020-05-22 Mark Wielaard <mark@klomp.org>
10630
10631 * sm-signal.cc(signal_unsafe_call::emit): Possibly add
10632 gcc_rich_location note for replacement.
10633 (signal_unsafe_call::get_replacement_fn): New private function.
10634 (get_async_signal_unsafe_fns): Add "exit".
10635
10636 2020-04-28 David Malcolm <dmalcolm@redhat.com>
10637
10638 PR analyzer/94816
10639 * engine.cc (impl_region_model_context::on_unexpected_tree_code):
10640 Handle NULL tree.
10641 * region-model.cc (region_model::add_region_for_type): Handle
10642 NULL type.
10643 * region-model.h
10644 (test_region_model_context::on_unexpected_tree_code): Handle NULL
10645 tree.
10646
10647 2020-04-28 David Malcolm <dmalcolm@redhat.com>
10648
10649 PR analyzer/94447
10650 PR analyzer/94639
10651 PR analyzer/94732
10652 PR analyzer/94754
10653 * analyzer.opt (Wanalyzer-use-of-uninitialized-value): Delete.
10654 * program-state.cc (selftest::test_program_state_dumping): Update
10655 expected dump result for removal of "uninit".
10656 * region-model.cc (poison_kind_to_str): Delete POISON_KIND_UNINIT
10657 case.
10658 (root_region::ensure_stack_region): Initialize stack with null
10659 svalue_id rather than with a typeless POISON_KIND_UNINIT value.
10660 (root_region::ensure_heap_region): Likewise for the heap.
10661 (region_model::dump_summary_of_rep_path_vars): Remove
10662 summarization of uninit values.
10663 (region_model::validate): Remove check that the stack has a
10664 POISON_KIND_UNINIT value.
10665 (poisoned_value_diagnostic::emit): Remove POISON_KIND_UNINIT
10666 case.
10667 (poisoned_value_diagnostic::describe_final_event): Likewise.
10668 (selftest::test_dump): Update expected dump result for removal of
10669 "uninit".
10670 (selftest::test_svalue_equality): Remove "uninit" and "freed".
10671 * region-model.h (enum poison_kind): Remove POISON_KIND_UNINIT.
10672
10673 2020-04-01 David Malcolm <dmalcolm@redhat.com>
10674
10675 PR analyzer/94378
10676 * checker-path.cc: Include "bitmap.h".
10677 * constraint-manager.cc: Likewise.
10678 * diagnostic-manager.cc: Likewise.
10679 * engine.cc: Likewise.
10680 (exploded_node::detect_leaks): Pass null region_id to pop_frame.
10681 * program-point.cc: Include "bitmap.h".
10682 * program-state.cc: Likewise.
10683 * region-model.cc (id_set<region_id>::id_set): Convert to...
10684 (region_id_set::region_id_set): ...this.
10685 (svalue_id_set::svalue_id_set): New ctor.
10686 (region_model::copy_region): New function.
10687 (region_model::copy_struct_region): New function.
10688 (region_model::copy_union_region): New function.
10689 (region_model::copy_array_region): New function.
10690 (stack_region::pop_frame): Drop return value. Add
10691 "result_dst_rid" param; if it is non-null, use copy_region to copy
10692 the result to it. Rather than capture and pass a single "known
10693 used" return value to be used by purge_unused_values, instead
10694 gather and pass a set of known used return values.
10695 (root_region::pop_frame): Drop return value. Add "result_dst_rid"
10696 param.
10697 (region_model::on_assignment): Use copy_region.
10698 (region_model::on_return): Likewise for the result.
10699 (region_model::on_longjmp): Pass null for pop_frame's
10700 result_dst_rid.
10701 (region_model::update_for_return_superedge): Pass the region for the
10702 return value of the call, if any, to pop_frame, rather than setting
10703 the lvalue for the lhs of the result.
10704 (region_model::pop_frame): Drop return value. Add
10705 "result_dst_rid" param.
10706 (region_model::purge_unused_svalues): Convert third param from an
10707 svalue_id * to an svalue_id_set *, updating the initial populating
10708 of the "used" bitmap accordingly. Don't remap it when done.
10709 (struct selftest::coord_test): New selftest fixture, extracted from...
10710 (selftest::test_dump_2): ...here.
10711 (selftest::test_compound_assignment): New selftest.
10712 (selftest::test_stack_frames): Pass null to new param of pop_frame.
10713 (selftest::analyzer_region_model_cc_tests): Call the new selftest.
10714 * region-model.h (class id_set): Delete template.
10715 (class region_id_set): Reimplement, using old id_set implementation.
10716 (class svalue_id_set): Likewise. Convert from auto_sbitmap to
10717 auto_bitmap.
10718 (region::get_active_view): New accessor.
10719 (stack_region::pop_frame): Drop return value. Add
10720 "result_dst_rid" param.
10721 (root_region::pop_frame): Likewise.
10722 (region_model::pop_frame): Likewise.
10723 (region_model::copy_region): New decl.
10724 (region_model::purge_unused_svalues): Convert third param from an
10725 svalue_id * to an svalue_id_set *.
10726 (region_model::copy_struct_region): New decl.
10727 (region_model::copy_union_region): New decl.
10728 (region_model::copy_array_region): New decl.
10729
10730 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10731
10732 * program-state.cc (selftest::test_program_state_dumping): Update
10733 expected dump to include symbolic_region's possibly_null field.
10734 * region-model.cc (symbolic_region::print_fields): New vfunc
10735 implementation.
10736 (region_model::add_constraint): Clear m_possibly_null from
10737 symbolic_regions now known to be non-NULL.
10738 (selftest::test_malloc_constraints): New selftest.
10739 (selftest::analyzer_region_model_cc_tests): Call it.
10740 * region-model.h (region::dyn_cast_symbolic_region): Add non-const
10741 overload.
10742 (symbolic_region::dyn_cast_symbolic_region): Implement it.
10743 (symbolic_region::print_fields): New vfunc override decl.
10744
10745 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10746
10747 * analyzer.h (class feasibility_problem): New forward decl.
10748 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
10749 Initialize new fields m_status, m_epath_length, and m_problem.
10750 (saved_diagnostic::~saved_diagnostic): Delete m_problem.
10751 (dedupe_candidate::dedupe_candidate): Convert "sd" param from a
10752 const ref to a mutable ptr.
10753 (dedupe_winners::add): Convert "sd" param from a const ref to a
10754 mutable ptr. Record the length of the exploded_path. Record the
10755 feasibility/infeasibility of sd into sd, capturing a
10756 feasibility_problem when feasible_p fails, and storing it in sd.
10757 (diagnostic_manager::emit_saved_diagnostics): Update for pass by
10758 ptr rather than by const ref.
10759 * diagnostic-manager.h (class saved_diagnostic): Add new enum
10760 status. Add fields m_status, m_epath_length and m_problem.
10761 (saved_diagnostic::set_feasible): New member function.
10762 (saved_diagnostic::set_infeasible): New member function.
10763 (saved_diagnostic::get_feasibility_problem): New accessor.
10764 (saved_diagnostic::get_status): New accessor.
10765 (saved_diagnostic::set_epath_length): New member function.
10766 (saved_diagnostic::get_epath_length): New accessor.
10767 * engine.cc: Include "gimple-pretty-print.h".
10768 (exploded_path::feasible_p): Add OUT param and, if non-NULL, write
10769 a new feasibility_problem to it on failure.
10770 (viz_callgraph_node::dump_dot): Convert begin_tr calls to
10771 begin_trtd. Convert end_tr calls to end_tdtr.
10772 (class exploded_graph_annotator): New subclass of dot_annotator.
10773 (impl_run_checkers): Add a second -fdump-analyzer-supergraph dump
10774 after the analysis runs, using exploded_graph_annotator. dumping
10775 to DUMP_BASE_NAME.supergraph-eg.dot.
10776 * exploded-graph.h (exploded_node::get_dot_fillcolor): Make
10777 public.
10778 (exploded_path::feasible_p): Add OUT param.
10779 (class feasibility_problem): New class.
10780 * state-purge.cc (state_purge_annotator::add_node_annotations):
10781 Return a bool, add a "within_table" param.
10782 (print_vec_of_names): Convert begin_tr calls to begin_trtd.
10783 Convert end_tr calls to end_tdtr.
10784 (state_purge_annotator::add_stmt_annotations): Add "within_row"
10785 param.
10786 * state-purge.h ((state_purge_annotator::add_node_annotations):
10787 Return a bool, add a "within_table" param.
10788 (state_purge_annotator::add_stmt_annotations): Add "within_row"
10789 param.
10790 * supergraph.cc (supernode::dump_dot): Call add_node_annotations
10791 twice: as before, passing false for "within_table", then again
10792 with true when within the TABLE element. Convert some begin_tr
10793 calls to begin_trtd, and some end_tr calls to end_tdtr.
10794 Repeat each add_stmt_annotations call, distinguishing between
10795 calls that add TRs and those that add TDs to an existing TR.
10796 Add a call to add_after_node_annotations.
10797 * supergraph.h (dot_annotator::add_node_annotations): Add a
10798 "within_table" param.
10799 (dot_annotator::add_stmt_annotations): Add a "within_row" param.
10800 (dot_annotator::add_after_node_annotations): New vfunc.
10801
10802 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10803
10804 * diagnostic-manager.cc (dedupe_winners::add): Show the
10805 exploded_node index in the log messages.
10806 (diagnostic_manager::emit_saved_diagnostics): Log a summary of
10807 m_saved_diagnostics at entry.
10808
10809 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10810
10811 * supergraph.cc (superedge::dump): Add space before description;
10812 move newline to non-pretty_printer overload.
10813
10814 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10815
10816 * region-model.cc: Include "stor-layout.h".
10817 (region_model::dump_to_pp): Rather than calling
10818 dump_summary_of_map on each of the current frame and the globals,
10819 instead get a vec of representative path_vars for all regions,
10820 and then dump a summary of all of them.
10821 (region_model::dump_summary_of_map): Delete, rewriting into...
10822 (region_model::dump_summary_of_rep_path_vars): ...this new
10823 function, working on a vec of path_vars.
10824 (region_model::set_value): New overload.
10825 (region_model::get_representative_path_var): Rename
10826 "parent_region" local to "parent_reg" and consolidate with other
10827 local. Guard test for grandparent being stack on parent_reg being
10828 non-NULL. Move handling for parent being an array_region to
10829 within guard for parent_reg being non-NULL.
10830 (selftest::make_test_compound_type): New function.
10831 (selftest::test_dump_2): New selftest.
10832 (selftest::test_dump_3): New selftest.
10833 (selftest::test_stack_frames): Update expected output from
10834 simplified dump to show "a" and "b" from parent frame and "y" in
10835 child frame.
10836 (selftest::analyzer_region_model_cc_tests): Call test_dump_2 and
10837 test_dump_3.
10838 * region-model.h (region_model::set_value): New overload decl.
10839 (region_model::dump_summary_of_map): Delete.
10840 (region_model::dump_summary_of_rep_path_vars): New.
10841
10842 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10843
10844 * region-model.h (class noop_region_model_context): New subclass
10845 of region_model_context.
10846 (class tentative_region_model_context): Inherit from
10847 noop_region_model_context rather than from region_model_context;
10848 drop redundant vfunc implementations.
10849 (class test_region_model_context): Likewise.
10850
10851 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10852
10853 * engine.cc (exploded_node::exploded_node): Move implementation
10854 here from header; accept point_and_state by const reference rather
10855 than by value.
10856 * exploded-graph.h (exploded_node::exploded_node): Pass
10857 point_and_state by const reference rather than by value. Move
10858 body to engine.cc.
10859
10860 2020-03-18 Jakub Jelinek <jakub@redhat.com>
10861
10862 * sm-malloc.cc (malloc_state_machine::on_stmt): Fix up duplicated word
10863 issue in a comment.
10864 * region-model.cc (region_model::make_region_for_unexpected_tree_code,
10865 region_model::delete_region_and_descendents): Likewise.
10866 * engine.cc (class exploded_cluster): Likewise.
10867 * diagnostic-manager.cc (class path_builder): Likewise.
10868
10869 2020-03-13 David Malcolm <dmalcolm@redhat.com>
10870
10871 PR analyzer/94099
10872 PR analyzer/94105
10873 * diagnostic-manager.cc (for_each_state_change): Bulletproof
10874 against errors in get_rvalue by passing a
10875 tentative_region_model_context and rejecting if there's an error.
10876 * region-model.cc (region_model::get_lvalue_1): When handling
10877 ARRAY_REF, handle results of error-handling. Handle NOP_EXPR.
10878
10879 2020-03-06 David Malcolm <dmalcolm@redhat.com>
10880
10881 * analyzer.h (class array_region): New forward decl.
10882 * program-state.cc (selftest::test_program_state_dumping_2): New.
10883 (selftest::analyzer_program_state_cc_tests): Call it.
10884 * region-model.cc (array_region::constant_from_key): New.
10885 (region_model::get_representative_tree): Handle region_svalue by
10886 generating an ADDR_EXPR.
10887 (region_model::get_representative_path_var): In view handling,
10888 remove erroneous TREE_TYPE when determining the type of the tree.
10889 Handle array regions and STRING_CST.
10890 (selftest::assert_dump_tree_eq): New.
10891 (ASSERT_DUMP_TREE_EQ): New macro.
10892 (selftest::test_get_representative_tree): New selftest.
10893 (selftest::analyzer_region_model_cc_tests): Call it.
10894 * region-model.h (region::dyn_cast_array_region): New vfunc.
10895 (array_region::dyn_cast_array_region): New vfunc implementation.
10896 (array_region::constant_from_key): New decl.
10897
10898 2020-03-06 David Malcolm <dmalcolm@redhat.com>
10899
10900 * analyzer.h (dump_quoted_tree): New decl.
10901 * engine.cc (exploded_node::dump_dot): Pass region model to
10902 sm_state_map::print.
10903 * program-state.cc: Include diagnostic-core.h.
10904 (sm_state_map::print): Add "model" param and use it to print
10905 representative trees. Only print origin information if non-null.
10906 (sm_state_map::dump): Pass NULL for model to print call.
10907 (program_state::print): Pass region model to sm_state_map::print.
10908 (program_state::dump_to_pp): Use spaces rather than newlines when
10909 summarizing. Pass region_model to sm_state_map::print.
10910 (ana::selftest::assert_dump_eq): New function.
10911 (ASSERT_DUMP_EQ): New macro.
10912 (ana::selftest::test_program_state_dumping): New function.
10913 (ana::selftest::analyzer_program_state_cc_tests): Call it.
10914 * program-state.h (program_state::print): Add model param.
10915 * region-model.cc (dump_quoted_tree): New function.
10916 (map_region::print_fields): Use dump_quoted_tree rather than
10917 %qE to avoid lang-dependent output.
10918 (map_region::dump_child_label): Likewise.
10919 (region_model::dump_summary_of_map): For SK_REGION, when
10920 get_representative_path_var fails, print the region id rather than
10921 erroneously printing NULL.
10922 * sm.cc (state_machine::get_state_by_name): New function.
10923 * sm.h (state_machine::get_state_by_name): New decl.
10924
10925 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10926
10927 * region-model.cc (region::validate): Convert model param from ptr
10928 to reference. Update comment to reflect that it's now a vfunc.
10929 (map_region::validate): New vfunc implementation.
10930 (array_region::validate): New vfunc implementation.
10931 (stack_region::validate): New vfunc implementation.
10932 (root_region::validate): New vfunc implementation.
10933 (region_model::validate): Pass a reference rather than a pointer
10934 to the region::validate vfunc.
10935 * region-model.h (region::validate): Make virtual. Convert model
10936 param from ptr to reference.
10937 (map_region::validate): New vfunc decl.
10938 (array_region::validate): New vfunc decl.
10939 (stack_region::validate): New vfunc decl.
10940 (root_region::validate): New vfunc decl.
10941
10942 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10943
10944 PR analyzer/93993
10945 * region-model.cc (region_model::on_call_pre): Handle
10946 BUILT_IN_EXPECT and its variants.
10947 (region_model::add_any_constraints_from_ssa_def_stmt): Split out
10948 gassign handling into add_any_constraints_from_gassign; add gcall
10949 handling.
10950 (region_model::add_any_constraints_from_gassign): New function,
10951 based on the above. Add handling for NOP_EXPR.
10952 (region_model::add_any_constraints_from_gcall): New function.
10953 (region_model::get_representative_path_var): Handle views.
10954 * region-model.h
10955 (region_model::add_any_constraints_from_ssa_def_stmt): New decl.
10956 (region_model::add_any_constraints_from_gassign): New decl.
10957
10958 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10959
10960 PR analyzer/93993
10961 * checker-path.h (state_change_event::get_lvalue): Add ctxt param
10962 and pass it to region_model::get_value call.
10963 * diagnostic-manager.cc (get_any_origin): Pass a
10964 tentative_region_model_context to the calls to get_lvalue and reject
10965 the comparison if errors occur.
10966 (can_be_expr_of_interest_p): New function.
10967 (diagnostic_manager::prune_for_sm_diagnostic): Replace checks for
10968 CONSTANT_CLASS_P with calls to update_for_unsuitable_sm_exprs.
10969 Pass a tentative_region_model_context to the calls to
10970 state_change_event::get_lvalue and reject the comparison if errors
10971 occur.
10972 (diagnostic_manager::update_for_unsuitable_sm_exprs): New.
10973 * diagnostic-manager.h
10974 (diagnostic_manager::update_for_unsuitable_sm_exprs): New decl.
10975 * region-model.h (class tentative_region_model_context): New class.
10976
10977 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10978
10979 * engine.cc (worklist::worklist): Remove unused field m_eg.
10980 (class viz_callgraph_edge): Remove unused field m_call_sedge.
10981 (class viz_callgraph): Remove unused field m_sg.
10982 * exploded-graph.h (worklist::::m_eg): Remove unused field.
10983
10984 2020-03-02 David Malcolm <dmalcolm@redhat.com>
10985
10986 * analyzer.opt (fanalyzer-show-duplicate-count): New option.
10987 * diagnostic-manager.cc
10988 (diagnostic_manager::emit_saved_diagnostic): Use the above to
10989 guard the printing of the duplicate count.
10990
10991 2020-03-02 David Malcolm <dmalcolm@redhat.com>
10992
10993 PR analyzer/93959
10994 * analyzer.cc (is_std_function_p): New function.
10995 (is_std_named_call_p): New functions.
10996 * analyzer.h (is_std_named_call_p): New decl.
10997 * sm-malloc.cc (malloc_state_machine::on_stmt): Check for "std::"
10998 variants when checking for malloc, calloc and free.
10999
11000 2020-02-26 David Malcolm <dmalcolm@redhat.com>
11001
11002 PR analyzer/93950
11003 * diagnostic-manager.cc
11004 (diagnostic_manager::prune_for_sm_diagnostic): Assert that var is
11005 either NULL or not a constant. When updating var, bulletproof
11006 against constant values.
11007
11008 2020-02-26 David Malcolm <dmalcolm@redhat.com>
11009
11010 PR analyzer/93947
11011 * region-model.cc (region_model::get_fndecl_for_call): Gracefully
11012 fail for fn_decls that don't have a cgraph_node.
11013
11014 2020-02-26 David Malcolm <dmalcolm@redhat.com>
11015
11016 * bar-chart.cc: New file.
11017 * bar-chart.h: New file.
11018 * engine.cc: Include "analyzer/bar-chart.h".
11019 (stats::log): Only log the m_num_nodes kinds that are non-zero.
11020 (stats::dump): Likewise when dumping.
11021 (stats::get_total_enodes): New.
11022 (exploded_graph::get_or_create_node): Increment the per-point-data
11023 m_excess_enodes when hitting the per-program-point limit on
11024 enodes.
11025 (exploded_graph::print_bar_charts): New.
11026 (exploded_graph::log_stats): Log the number of unprocessed enodes
11027 in the worklist. Call print_bar_charts.
11028 (exploded_graph::dump_stats): Print the number of unprocessed
11029 enodes in the worklist.
11030 * exploded-graph.h (stats::get_total_enodes): New decl.
11031 (struct per_program_point_data): Add field m_excess_enodes.
11032 (exploded_graph::print_bar_charts): New decl.
11033 * supergraph.cc (superedge::dump): New.
11034 (superedge::dump): New.
11035 * supergraph.h (supernode::get_function): New.
11036 (superedge::dump): New decl.
11037 (superedge::dump): New decl.
11038
11039 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11040
11041 * engine.cc (exploded_graph::get_or_create_node): Dump the
11042 program_state to the pp, rather than to stderr.
11043
11044 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11045
11046 PR analyzer/93032
11047 * sm.cc (make_checkers): Require the "taint" checker to be
11048 explicitly enabled.
11049
11050 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11051
11052 PR analyzer/93899
11053 * engine.cc
11054 (impl_region_model_context::impl_region_model_context): Add logger
11055 param.
11056 * engine.cc (exploded_graph::add_function_entry): Create an
11057 impl_region_model_context and pass it to the push_frame call.
11058 Bail if the resulting state is invalid.
11059 (exploded_graph::build_initial_worklist): Likewise.
11060 (exploded_graph::build_initial_worklist): Handle the case where
11061 add_function_entry fails.
11062 * exploded-graph.h
11063 (impl_region_model_context::impl_region_model_context): Add logger
11064 param.
11065 * region-model.cc (map_region::get_or_create): Add ctxt param and
11066 pass it to add_region_for_type.
11067 (map_region::can_merge_p): Pass NULL as a ctxt to call to
11068 get_or_create.
11069 (array_region::get_element): Pass ctxt to call to get_or_create.
11070 (array_region::get_or_create): Add ctxt param and pass it to
11071 add_region_for_type.
11072 (root_region::push_frame): Pass ctxt to get_or_create calls.
11073 (region_model::get_lvalue_1): Likewise.
11074 (region_model::make_region_for_unexpected_tree_code): Assert that
11075 ctxt is non-NULL.
11076 (region_model::get_rvalue_1): Pass ctxt to get_svalue_for_fndecl
11077 and get_svalue_for_label calls.
11078 (region_model::get_svalue_for_fndecl): Add ctxt param and pass it
11079 to get_region_for_fndecl.
11080 (region_model::get_region_for_fndecl): Add ctxt param and pass it
11081 to get_or_create.
11082 (region_model::get_svalue_for_label): Add ctxt param and pass it
11083 to get_region_for_label.
11084 (region_model::get_region_for_label): Add ctxt param and pass it
11085 to get_region_for_fndecl and get_or_create.
11086 (region_model::get_field_region): Add ctxt param and pass it to
11087 get_or_create_view and get_or_create.
11088 (make_region_for_type): Replace gcc_unreachable with return NULL.
11089 (region_model::add_region_for_type): Add ctxt param. Handle a
11090 return of NULL from make_region_for_type by calling
11091 make_region_for_unexpected_tree_code.
11092 (region_model::get_or_create_mem_ref): Pass ctxt to calls to
11093 get_or_create_view.
11094 (region_model::get_or_create_view): Add ctxt param and pass it to
11095 add_region_for_type.
11096 (selftest::test_state_merging): Pass ctxt to get_or_create_view.
11097 * region-model.h (region_model::get_or_create): Add ctxt param.
11098 (region_model::add_region_for_type): Likewise.
11099 (region_model::get_svalue_for_fndecl): Likewise.
11100 (region_model::get_svalue_for_label): Likewise.
11101 (region_model::get_region_for_fndecl): Likewise.
11102 (region_model::get_region_for_label): Likewise.
11103 (region_model::get_field_region): Likewise.
11104 (region_model::get_or_create_view): Likewise.
11105
11106 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11107
11108 * checker-path.cc (superedge_event::should_filter_p): Update
11109 filter for empty descriptions to cover verbosity level 3 as well
11110 as 2.
11111 * diagnostic-manager.cc: Include "analyzer/reachability.h".
11112 (class path_builder): New class.
11113 (diagnostic_manager::emit_saved_diagnostic): Create a path_builder
11114 and pass it to build_emission_path, rather passing eg; similarly
11115 for add_events_for_eedge and ext_state.
11116 (diagnostic_manager::build_emission_path): Replace "eg" param
11117 with a path_builder, pass it to add_events_for_eedge.
11118 (diagnostic_manager::add_events_for_eedge): Replace ext_state
11119 param with path_builder; pass it to add_events_for_superedge.
11120 (diagnostic_manager::significant_edge_p): New.
11121 (diagnostic_manager::add_events_for_superedge): Add path_builder
11122 param. Reject insignificant edges at verbosity levels below 3.
11123 (diagnostic_manager::prune_for_sm_diagnostic): Update highest
11124 verbosity level to 4.
11125 * diagnostic-manager.h (class path_builder): New forward decl.
11126 (diagnostic_manager::build_emission_path): Replace "eg" param
11127 with a path_builder.
11128 (diagnostic_manager::add_events_for_eedge): Replace ext_state
11129 param with path_builder.
11130 (diagnostic_manager::significant_edge_p): New.
11131 (diagnostic_manager::add_events_for_superedge): Add path_builder
11132 param.
11133 * reachability.h: New file.
11134
11135 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11136
11137 PR analyzer/93692
11138 * analyzer.opt (fdump-analyzer-callgraph): Rewrite description.
11139
11140 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11141
11142 PR analyzer/93777
11143 * region-model.cc (region_model::maybe_cast_1): Replace assertion
11144 that build_cast returns non-NULL with a conditional, falling
11145 through to the logic which returns a new unknown value of the
11146 desired type if it fails.
11147
11148 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11149
11150 PR analyzer/93778
11151 * engine.cc (impl_region_model_context::on_unknown_tree_code):
11152 Rename to...
11153 (impl_region_model_context::on_unexpected_tree_code): ...this and
11154 convert first argument from path_var to tree.
11155 (exploded_node::on_stmt): Pass ctxt to purge_for_unknown_fncall.
11156 * exploded-graph.h (region_model_context::on_unknown_tree_code):
11157 Rename to...
11158 (region_model_context::on_unexpected_tree_code): ...this and
11159 convert first argument from path_var to tree.
11160 * program-state.cc (sm_state_map::purge_for_unknown_fncall): Add
11161 ctxt param and pass on to calls to get_rvalue.
11162 * program-state.h (sm_state_map::purge_for_unknown_fncall): Add
11163 ctxt param.
11164 * region-model.cc (region_model::handle_unrecognized_call): Pass
11165 ctxt on to call to get_rvalue.
11166 (region_model::get_lvalue_1): Move body of default case to
11167 region_model::make_region_for_unexpected_tree_code and call it.
11168 Within COMPONENT_REF case, reject attempts to handle types other
11169 than RECORD_TYPE and UNION_TYPE.
11170 (region_model::make_region_for_unexpected_tree_code): New
11171 function, based on default case of region_model::get_lvalue_1.
11172 * region-model.h
11173 (region_model::make_region_for_unexpected_tree_code): New decl.
11174 (region_model::on_unknown_tree_code): Rename to...
11175 (region_model::on_unexpected_tree_code): ...this and convert first
11176 argument from path_var to tree.
11177 (class test_region_model_context): Update vfunc implementation for
11178 above change.
11179
11180 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11181
11182 PR analyzer/93774
11183 * region-model.cc
11184 (region_model::convert_byte_offset_to_array_index): Use
11185 int_size_in_bytes before calling size_in_bytes, to gracefully fail
11186 on incomplete types.
11187
11188 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11189
11190 PR analyzer/93775
11191 * region-model.cc (region_model::get_fndecl_for_call): Handle the
11192 case where the code_region's get_tree_for_child_region returns
11193 NULL.
11194
11195 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11196
11197 PR analyzer/93388
11198 * engine.cc (impl_region_model_context::on_unknown_tree_code):
11199 New.
11200 (exploded_graph::get_or_create_node): Reject invalid states.
11201 * exploded-graph.h
11202 (impl_region_model_context::on_unknown_tree_code): New decl.
11203 (point_and_state::point_and_state): Assert that the state is
11204 valid.
11205 * program-state.cc (program_state::program_state): Initialize
11206 m_valid to true.
11207 (program_state::operator=): Copy m_valid.
11208 (program_state::program_state): Likewise for move constructor.
11209 (program_state::print): Print m_valid.
11210 (program_state::dump_to_pp): Likewise.
11211 * program-state.h (program_state::m_valid): New field.
11212 * region-model.cc (region_model::get_lvalue_1): Implement the
11213 default case by returning a new symbolic region and calling
11214 the context's on_unknown_tree_code, rather than issuing an
11215 internal_error. Implement VIEW_CONVERT_EXPR.
11216 * region-model.h (region_model_context::on_unknown_tree_code): New
11217 vfunc.
11218 (test_region_model_context::on_unknown_tree_code): New.
11219
11220 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11221
11222 * sm-malloc.cc (malloc_diagnostic::describe_state_change): For
11223 transition to the "null" state, only say "assuming" when
11224 transitioning from the "unchecked" state.
11225
11226 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11227
11228 * diagnostic-manager.h (diagnostic_manager::get_saved_diagnostic):
11229 Add const overload.
11230 * engine.cc (exploded_node::dump_dot): Dump saved_diagnostics.
11231 * exploded-graph.h (exploded_graph::get_diagnostic_manager): Add
11232 const overload.
11233
11234 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11235
11236 PR analyzer/93288
11237 * analysis-plan.cc (analysis_plan::use_summary_p): Look through
11238 the ultimate_alias_target when getting the called function.
11239 * engine.cc (exploded_node::on_stmt): Rename second "ctxt" to
11240 "sm_ctxt". Use the region_model's get_fndecl_for_call rather than
11241 gimple_call_fndecl.
11242 * region-model.cc (region_model::get_fndecl_for_call): Use
11243 ultimate_alias_target on fndecl.
11244 * supergraph.cc (get_ultimate_function_for_cgraph_edge): New
11245 function.
11246 (supergraph_call_edge): Use it when rejecting edges without
11247 functions.
11248 (supergraph::supergraph): Use it to get the function for the
11249 cgraph_edge when building interprocedural superedges.
11250 (callgraph_superedge::get_callee_function): Use it.
11251 * supergraph.h (supergraph::get_num_snodes): Make param const.
11252 (supergraph::function_to_num_snodes_t): Make first type param
11253 const.
11254
11255 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11256
11257 PR analyzer/93374
11258 * engine.cc (exploded_edge::exploded_edge): Add ext_state param
11259 and pass it to change.validate.
11260 (exploded_graph::get_or_create_node): Move purging of change
11261 svalues to also cover the case of reusing an existing enode.
11262 (exploded_graph::add_edge): Pass m_ext_state to exploded_edge's
11263 ctor.
11264 * exploded-graph.h (exploded_edge::exploded_edge): Add ext_state
11265 param.
11266 * program-state.cc (state_change::sm_change::validate): Likewise.
11267 Assert that m_sm_idx is sane. Use ext_state to validate
11268 m_old_state and m_new_state.
11269 (state_change::validate): Add ext_state param and pass it to
11270 the sm_change validate calls.
11271 * program-state.h (state_change::sm_change::validate): Add
11272 ext_state param.
11273 (state_change::validate): Likewise.
11274
11275 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11276
11277 PR analyzer/93669
11278 * engine.cc (exploded_graph::dump_exploded_nodes): Handle missing
11279 case of STATUS_WORKLIST in implementation of
11280 "__analyzer_dump_exploded_nodes".
11281
11282 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11283
11284 PR analyzer/93649
11285 * constraint-manager.cc (constraint_manager::add_constraint): When
11286 merging equivalence classes and updating m_constant, also update
11287 m_cst_sid.
11288 (constraint_manager::validate): If m_constant is non-NULL assert
11289 that m_cst_sid is non-null and is valid.
11290
11291 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11292
11293 PR analyzer/93657
11294 * analyzer.opt (fdump-analyzer): Reword description.
11295 (fdump-analyzer-stderr): Likewise.
11296
11297 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11298
11299 * region-model.cc (print_quoted_type): New function.
11300 (svalue::print): Use it to replace %qT.
11301 (region::dump_to_pp): Likewise.
11302 (region::dump_child_label): Likewise.
11303 (region::print_fields): Likewise.
11304
11305 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11306
11307 PR analyzer/93659
11308 * analyzer.opt (-param=analyzer-max-recursion-depth=): Fix "tha"
11309 -> "that" typo.
11310 (Wanalyzer-use-of-uninitialized-value): Fix "initialized" ->
11311 "uninitialized" typo.
11312
11313 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11314
11315 PR analyzer/93350
11316 * region-model.cc (region_model::get_lvalue_1):
11317 Handle BIT_FIELD_REF.
11318 (make_region_for_type): Handle VECTOR_TYPE.
11319
11320 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11321
11322 PR analyzer/93647
11323 * diagnostic-manager.cc
11324 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof against
11325 VAR being constant.
11326 * region-model.cc (region_model::get_lvalue_1): Provide a better
11327 error message when encountering an unhandled tree code.
11328
11329 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11330
11331 PR analyzer/93405
11332 * region-model.cc (region_model::get_lvalue_1): Implement
11333 CONST_DECL.
11334
11335 2020-02-06 David Malcolm <dmalcolm@redhat.com>
11336
11337 * region-model.cc (region_model::maybe_cast_1): Attempt to provide
11338 a region_svalue if either type is a pointer, rather than if both
11339 types are pointers.
11340
11341 2020-02-05 David Malcolm <dmalcolm@redhat.com>
11342
11343 * engine.cc (exploded_node::dump_dot): Show merger enodes.
11344 (worklist::add_node): Assert that the node's m_status is
11345 STATUS_WORKLIST.
11346 (exploded_graph::process_worklist): Likewise for nodes from the
11347 worklist. Set status of merged nodes to STATUS_MERGER.
11348 (exploded_graph::process_node): Set status of node to
11349 STATUS_PROCESSED.
11350 (exploded_graph::dump_exploded_nodes): Rework handling of
11351 "__analyzer_dump_exploded_nodes", splitting enodes by status into
11352 "processed" and "merger", showing the count of just the processed
11353 enodes at the call, rather than the count of all enodes.
11354 * exploded-graph.h (exploded_node::status): New enum.
11355 (exploded_node::exploded_node): Initialize m_status to
11356 STATUS_WORKLIST.
11357 (exploded_node::get_status): New getter.
11358 (exploded_node::set_status): New setter.
11359
11360 2020-02-04 David Malcolm <dmalcolm@redhat.com>
11361
11362 PR analyzer/93543
11363 * engine.cc (pod_hash_traits<function_call_string>::mark_empty):
11364 Eliminate reinterpret_cast.
11365 (pod_hash_traits<function_call_string>::is_empty): Likewise.
11366
11367 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11368
11369 * constraint-manager.cc (range::constrained_to_single_element):
11370 Replace fold_build2 with fold_binary. Remove unnecessary newline.
11371 (constraint_manager::get_or_add_equiv_class): Replace fold_build2
11372 with fold_binary in two places, and remove out-of-date comment.
11373 (constraint_manager::eval_condition): Replace fold_build2 with
11374 fold_binary.
11375 * region-model.cc (constant_svalue::eval_condition): Likewise.
11376 (region_model::on_assignment): Likewise.
11377
11378 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11379
11380 PR analyzer/93544
11381 * diagnostic-manager.cc
11382 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof
11383 against bad choices due to bad paths.
11384 * engine.cc (impl_region_model_context::on_phi): New.
11385 * exploded-graph.h (impl_region_model_context::on_phi): New decl.
11386 * region-model.cc (region_model::on_longjmp): Likewise.
11387 (region_model::handle_phi): Add phi param. Call the ctxt's on_phi
11388 vfunc.
11389 (region_model::update_for_phis): Pass phi to handle_phi.
11390 * region-model.h (region_model::handle_phi): Add phi param.
11391 (region_model_context::on_phi): New vfunc.
11392 (test_region_model_context::on_phi): New.
11393 * sm-malloc.cc (malloc_state_machine::on_phi): New.
11394 (malloc_state_machine::on_zero_assignment): New.
11395 * sm.h (state_machine::on_phi): New vfunc.
11396
11397 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11398
11399 * engine.cc (supernode_cluster::dump_dot): Show BB index as
11400 well as SN index.
11401 * supergraph.cc (supernode::dump_dot): Likewise.
11402
11403 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11404
11405 PR analyzer/93546
11406 * region-model.cc (region_model::on_call_pre): Update for new
11407 param of symbolic_region ctor.
11408 (region_model::deref_rvalue): Likewise.
11409 (region_model::add_new_malloc_region): Likewise.
11410 (make_region_for_type): Likewise, preserving type.
11411 * region-model.h (symbolic_region::symbolic_region): Add "type"
11412 param and pass it to base class ctor.
11413
11414 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11415
11416 PR analyzer/93547
11417 * constraint-manager.cc
11418 (constraint_manager::get_or_add_equiv_class): Ensure types are
11419 compatible before comparing constants.
11420
11421 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11422
11423 PR analyzer/93457
11424 * region-model.cc (make_region_for_type): Use VOID_TYPE_P rather
11425 than checking against void_type_node.
11426
11427 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11428
11429 PR analyzer/93373
11430 * region-model.cc (ASSERT_COMPAT_TYPES): Convert to...
11431 (assert_compat_types): ...this, and bail when either type is NULL,
11432 or when VOID_TYPE_P (dst_type).
11433 (region_model::get_lvalue): Update for above conversion.
11434 (region_model::get_rvalue): Likewise.
11435
11436 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11437
11438 PR analyzer/93379
11439 * region-model.cc (region_model::update_for_return_superedge):
11440 Move check for null result so that it also guards setting the
11441 lhs.
11442
11443 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11444
11445 PR analyzer/93438
11446 * region-model.cc (stack_region::can_merge_p): Split into a two
11447 pass approach, creating all stack regions first, then populating
11448 them.
11449 (selftest::test_state_merging): Add test coverage for (a) the case
11450 of self-merging a model in which a local in an older stack frame
11451 points to a local in a more recent stack frame (which previously
11452 would ICE), and (b) the case of self-merging a model in which a
11453 local points to a global (which previously worked OK).
11454
11455 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11456
11457 * analyzer.cc (is_named_call_p): Replace tests for fndecl being
11458 extern at file scope and having a non-NULL DECL_NAME with a call
11459 to maybe_special_function_p.
11460 * function-set.cc (function_set::contains_decl_p): Add call to
11461 maybe_special_function_p.
11462
11463 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11464
11465 PR analyzer/93450
11466 * constraint-manager.cc
11467 (constraint_manager::get_or_add_equiv_class): Only compare constants
11468 if their types are compatible.
11469 * region-model.cc (constant_svalue::eval_condition): Replace check
11470 for identical types with call to types_compatible_p.
11471
11472 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11473
11474 * program-state.cc (extrinsic_state::dump_to_pp): New.
11475 (extrinsic_state::dump_to_file): New.
11476 (extrinsic_state::dump): New.
11477 * program-state.h (extrinsic_state::dump_to_pp): New decl.
11478 (extrinsic_state::dump_to_file): New decl.
11479 (extrinsic_state::dump): New decl.
11480 * sm.cc: Include "pretty-print.h".
11481 (state_machine::dump_to_pp): New.
11482 * sm.h (state_machine::dump_to_pp): New decl.
11483
11484 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11485
11486 * diagnostic-manager.cc (for_each_state_change): Use
11487 extrinsic_state::get_num_checkers rather than accessing m_checkers
11488 directly.
11489 * program-state.cc (program_state::program_state): Likewise.
11490 * program-state.h (extrinsic_state::m_checkers): Make private.
11491
11492 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11493
11494 PR analyzer/93356
11495 * region-model.cc (region_model::eval_condition): In both
11496 overloads, bail out immediately on floating-point types.
11497 (region_model::eval_condition_without_cm): Likewise.
11498 (region_model::add_constraint): Likewise.
11499
11500 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11501
11502 PR analyzer/93450
11503 * program-state.cc (sm_state_map::set_state): For the overload
11504 taking an svalue_id, bail out if the set_state on the ec does
11505 nothing. Convert the latter's return type from void to bool,
11506 returning true if anything changed.
11507 (sm_state_map::impl_set_state): Convert the return type from void
11508 to bool, returning true if the state changed.
11509 * program-state.h (sm_state_map::set_state): Convert return type
11510 from void to bool.
11511 (sm_state_map::impl_set_state): Likewise.
11512 * region-model.cc (constant_svalue::eval_condition): Only call
11513 fold_build2 if the types are the same.
11514
11515 2020-01-29 Jakub Jelinek <jakub@redhat.com>
11516
11517 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Remove.
11518 * constraint-manager.cc: Include diagnostic-core.h before graphviz.h.
11519 (range::dump, equiv_class::print): Don't use PUSH_IGNORE_WFORMAT or
11520 POP_IGNORE_WFORMAT.
11521 * state-purge.cc: Include diagnostic-core.h before
11522 gimple-pretty-print.h.
11523 (state_purge_annotator::add_node_annotations, print_vec_of_names):
11524 Don't use PUSH_IGNORE_WFORMAT or POP_IGNORE_WFORMAT.
11525 * region-model.cc: Move diagnostic-core.h include before graphviz.h.
11526 (path_var::dump, svalue::print, constant_svalue::print_details,
11527 region::dump_to_pp, region::dump_child_label, region::print_fields,
11528 map_region::print_fields, map_region::dump_dot_to_pp,
11529 map_region::dump_child_label, array_region::print_fields,
11530 array_region::dump_dot_to_pp): Don't use PUSH_IGNORE_WFORMAT or
11531 POP_IGNORE_WFORMAT.
11532
11533 2020-01-28 David Malcolm <dmalcolm@redhat.com>
11534
11535 PR analyzer/93316
11536 * engine.cc (rewind_info_t::update_model): Get the longjmp call
11537 stmt via get_longjmp_call () rather than assuming it is the last
11538 stmt in the longjmp's supernode.
11539 (rewind_info_t::add_events_to_path): Get the location_t for the
11540 rewind_from_longjmp_event via get_longjmp_call () rather than from
11541 the supernode's get_end_location ().
11542
11543 2020-01-28 David Malcolm <dmalcolm@redhat.com>
11544
11545 * region-model.cc (poisoned_value_diagnostic::emit): Update for
11546 renaming of warning_at overload to warning_meta.
11547 * sm-file.cc (file_leak::emit): Likewise.
11548 * sm-malloc.cc (double_free::emit): Likewise.
11549 (possible_null_deref::emit): Likewise.
11550 (possible_null_arg::emit): Likewise.
11551 (null_deref::emit): Likewise.
11552 (null_arg::emit): Likewise.
11553 (use_after_free::emit): Likewise.
11554 (malloc_leak::emit): Likewise.
11555 (free_of_non_heap::emit): Likewise.
11556 * sm-sensitive.cc (exposure_through_output_file::emit): Likewise.
11557 * sm-signal.cc (signal_unsafe_call::emit): Likewise.
11558 * sm-taint.cc (tainted_array_index::emit): Likewise.
11559
11560 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11561
11562 PR analyzer/93451
11563 * region-model.cc (tree_cmp): For the REAL_CST case, impose an
11564 arbitrary order on NaNs relative to other NaNs and to non-NaNs;
11565 const-correctness tweak.
11566 (ana::selftests::build_real_cst_from_string): New function.
11567 (ana::selftests::append_interesting_constants): New function.
11568 (ana::selftests::test_tree_cmp_on_constants): New test.
11569 (ana::selftests::test_canonicalization_4): New test.
11570 (ana::selftests::analyzer_region_model_cc_tests): Call the new
11571 tests.
11572
11573 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11574
11575 PR analyzer/93349
11576 * engine.cc (run_checkers): Save and restore input_location.
11577
11578 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11579
11580 * call-string.cc (call_string::cmp_1): Delete, moving body to...
11581 (call_string::cmp): ...here.
11582 * call-string.h (call_string::cmp_1): Delete decl.
11583 * engine.cc (worklist::key_t::cmp_1): Delete, moving body to...
11584 (worklist::key_t::cmp): ...here. Implement hash comparisons
11585 via comparison rather than subtraction to avoid overflow issues.
11586 * exploded-graph.h (worklist::key_t::cmp_1): Delete decl.
11587 * region-model.cc (tree_cmp): Eliminate buggy checking for
11588 symmetry.
11589
11590 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11591
11592 * analyzer.cc (is_named_call_p): Check that fndecl is "extern"
11593 and at file scope. Potentially disregard prefix _ or __ in
11594 fndecl's name. Bail if the identifier is NULL.
11595 (is_setjmp_call_p): Expect a gcall rather than plain gimple.
11596 Remove special-case check for leading prefix, and also check for
11597 sigsetjmp.
11598 (is_longjmp_call_p): Also check for siglongjmp.
11599 (get_user_facing_name): New function.
11600 * analyzer.h (is_setjmp_call_p): Expect a gcall rather than plain
11601 gimple.
11602 (get_user_facing_name): New decl.
11603 * checker-path.cc (setjmp_event::get_desc): Use
11604 get_user_facing_name to avoid hardcoding the function name.
11605 (rewind_event::rewind_event): Add rewind_info param, using it to
11606 initialize new m_rewind_info field, and strengthen the assertion.
11607 (rewind_from_longjmp_event::get_desc): Use get_user_facing_name to
11608 avoid hardcoding the function name.
11609 (rewind_to_setjmp_event::get_desc): Likewise.
11610 * checker-path.h (setjmp_event::setjmp_event): Add setjmp_call
11611 param and use it to initialize...
11612 (setjmp_event::m_setjmp_call): New field.
11613 (rewind_event::rewind_event): Add rewind_info param.
11614 (rewind_event::m_rewind_info): New protected field.
11615 (rewind_from_longjmp_event::rewind_from_longjmp_event): Add
11616 rewind_info param.
11617 (class rewind_to_setjmp_event): Move rewind_info field to parent
11618 class.
11619 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
11620 Update setjmp-handling for is_setjmp_call_p requiring a gcall;
11621 pass the call to the new setjmp_event.
11622 * engine.cc (exploded_node::on_stmt): Update for is_setjmp_call_p
11623 requiring a gcall.
11624 (stale_jmp_buf::emit): Use get_user_facing_name to avoid
11625 hardcoding the function names.
11626 (exploded_node::on_longjmp): Pass the longjmp_call when
11627 constructing rewind_info.
11628 (rewind_info_t::add_events_to_path): Pass the rewind_info_t to the
11629 rewind_from_longjmp_event's ctor.
11630 * exploded-graph.h (rewind_info_t::rewind_info_t): Add
11631 longjmp_call param.
11632 (rewind_info_t::get_longjmp_call): New.
11633 (rewind_info_t::m_longjmp_call): New.
11634 * region-model.cc (region_model::on_setjmp): Update comment to
11635 indicate this is also for sigsetjmp.
11636 * region-model.h (struct setjmp_record): Likewise.
11637 (class setjmp_svalue): Likewise.
11638
11639 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11640
11641 PR analyzer/93276
11642 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Guard these
11643 macros with GCC_VERSION >= 4006, making them no-op otherwise.
11644 * engine.cc (exploded_edge::exploded_edge): Specify template for
11645 base class initializer.
11646 (exploded_graph::add_edge): Specify template when chaining up to
11647 base class add_edge implementation.
11648 (viz_callgraph_node::dump_dot): Drop redundant "typename".
11649 (viz_callgraph_edge::viz_callgraph_edge): Specify template for
11650 base class initializer.
11651 * program-state.cc (sm_state_map::clone_with_remapping): Drop
11652 redundant "typename".
11653 (sm_state_map::print): Likewise.
11654 (sm_state_map::hash): Likewise.
11655 (sm_state_map::operator==): Likewise.
11656 (sm_state_map::remap_svalue_ids): Likewise.
11657 (sm_state_map::on_svalue_purge): Likewise.
11658 (sm_state_map::validate): Likewise.
11659 * program-state.h (sm_state_map::iterator_t): Likewise.
11660 * supergraph.h (superedge::superedge): Specify template for base
11661 class initializer.
11662
11663 2020-01-23 David Malcolm <dmalcolm@redhat.com>
11664
11665 PR analyzer/93375
11666 * supergraph.cc (callgraph_superedge::get_arg_for_parm): Fail
11667 gracefully is the number of parameters at the callee exceeds the
11668 number of arguments at the call stmt.
11669 (callgraph_superedge::get_parm_for_arg): Likewise.
11670
11671 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11672
11673 PR analyzer/93382
11674 * program-state.cc (sm_state_map::on_svalue_purge): If the
11675 entry survives, but the origin is being purged, then reset the
11676 origin to null.
11677
11678 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11679
11680 * sm-signal.cc: Fix nesting of CHECKING_P and namespace ana.
11681
11682 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11683
11684 PR analyzer/93378
11685 * engine.cc (setjmp_svalue::compare_fields): Update for
11686 replacement of m_enode with m_setjmp_record.
11687 (setjmp_svalue::add_to_hash): Likewise.
11688 (setjmp_svalue::get_index): Rename...
11689 (setjmp_svalue::get_enode_index): ...to this.
11690 (setjmp_svalue::print_details): Update for replacement of m_enode
11691 with m_setjmp_record.
11692 (exploded_node::on_longjmp): Likewise.
11693 * exploded-graph.h (rewind_info_t::m_enode_origin): Replace...
11694 (rewind_info_t::m_setjmp_record): ...with this.
11695 (rewind_info_t::rewind_info_t): Update for replacement of m_enode
11696 with m_setjmp_record.
11697 (rewind_info_t::get_setjmp_point): Likewise.
11698 (rewind_info_t::get_setjmp_call): Likewise.
11699 * region-model.cc (region_model::dump_summary_of_map): Likewise.
11700 (region_model::on_setjmp): Likewise.
11701 * region-model.h (struct setjmp_record): New struct.
11702 (setjmp_svalue::m_enode): Replace...
11703 (setjmp_svalue::m_setjmp_record): ...with this.
11704 (setjmp_svalue::setjmp_svalue): Update for replacement of m_enode
11705 with m_setjmp_record.
11706 (setjmp_svalue::clone): Likewise.
11707 (setjmp_svalue::get_index): Rename...
11708 (setjmp_svalue::get_enode_index): ...to this.
11709 (setjmp_svalue::get_exploded_node): Replace...
11710 (setjmp_svalue::get_setjmp_record): ...with this.
11711
11712 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11713
11714 PR analyzer/93316
11715 * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as
11716 "_setjmp".
11717
11718 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11719
11720 PR analyzer/93307
11721 * analysis-plan.h: Wrap everything namespace "ana".
11722 * analyzer-logging.cc: Likewise.
11723 * analyzer-logging.h: Likewise.
11724 * analyzer-pass.cc (pass_analyzer::execute): Update for "ana"
11725 namespace.
11726 * analyzer-selftests.cc: Wrap everything namespace "ana".
11727 * analyzer-selftests.h: Likewise.
11728 * analyzer.h: Likewise for forward decls of types.
11729 * call-string.h: Likewise.
11730 * checker-path.cc: Likewise.
11731 * checker-path.h: Likewise.
11732 * constraint-manager.cc: Likewise.
11733 * constraint-manager.h: Likewise.
11734 * diagnostic-manager.cc: Likewise.
11735 * diagnostic-manager.h: Likewise.
11736 * engine.cc: Likewise.
11737 * engine.h: Likewise.
11738 * exploded-graph.h: Likewise.
11739 * function-set.cc: Likewise.
11740 * function-set.h: Likewise.
11741 * pending-diagnostic.cc: Likewise.
11742 * pending-diagnostic.h: Likewise.
11743 * program-point.cc: Likewise.
11744 * program-point.h: Likewise.
11745 * program-state.cc: Likewise.
11746 * program-state.h: Likewise.
11747 * region-model.cc: Likewise.
11748 * region-model.h: Likewise.
11749 * sm-file.cc: Likewise.
11750 * sm-malloc.cc: Likewise.
11751 * sm-pattern-test.cc: Likewise.
11752 * sm-sensitive.cc: Likewise.
11753 * sm-signal.cc: Likewise.
11754 * sm-taint.cc: Likewise.
11755 * sm.cc: Likewise.
11756 * sm.h: Likewise.
11757 * state-purge.h: Likewise.
11758 * supergraph.cc: Likewise.
11759 * supergraph.h: Likewise.
11760
11761 2020-01-21 David Malcolm <dmalcolm@redhat.com>
11762
11763 PR analyzer/93352
11764 * region-model.cc (int_cmp): Rename to...
11765 (array_region::key_cmp): ...this, using key_t rather than int.
11766 Rewrite in terms of comparisons rather than subtraction to
11767 ensure qsort is anti-symmetric when handling extreme values.
11768 (array_region::walk_for_canonicalization): Update for above
11769 renaming.
11770 * region-model.h (array_region::key_cmp): New decl.
11771
11772 2020-01-17 David Malcolm <dmalcolm@redhat.com>
11773
11774 PR analyzer/93290
11775 * region-model.cc (region_model::eval_condition_without_cm): Avoid
11776 gcc_unreachable for unexpected operations for the case where
11777 we're comparing an svalue against itself.
11778
11779 2020-01-17 David Malcolm <dmalcolm@redhat.com>
11780
11781 PR analyzer/93281
11782 * region-model.cc
11783 (region_model::convert_byte_offset_to_array_index): Convert to
11784 ssizetype before dividing by byte_size. Use fold_binary rather
11785 than fold_build2 to avoid needlessly constructing a tree for the
11786 non-const case.
11787
11788 2020-01-15 David Malcolm <dmalcolm@redhat.com>
11789
11790 * engine.cc (class impl_region_model_context): Fix comment.
11791
11792 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11793
11794 PR analyzer/93212
11795 * region-model.cc (make_region_for_type): Use
11796 FUNC_OR_METHOD_TYPE_P rather than comparing against FUNCTION_TYPE.
11797 * region-model.h (function_region::function_region): Likewise.
11798
11799 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11800
11801 * program-state.cc (sm_state_map::clone_with_remapping): Copy
11802 m_global_state.
11803 (selftest::test_program_state_merging_2): New selftest.
11804 (selftest::analyzer_program_state_cc_tests): Call it.
11805
11806 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11807
11808 * checker-path.h (checker_path::get_checker_event): New function.
11809 (checker_path): Add DISABLE_COPY_AND_ASSIGN; make fields private.
11810 * diagnostic-manager.cc
11811 (diagnostic_manager::prune_for_sm_diagnostic): Replace direct
11812 access to checker_path::m_events with accessor functions. Fix
11813 overlong line.
11814 (diagnostic_manager::prune_interproc_events): Replace direct
11815 access to checker_path::m_events with accessor functions.
11816 (diagnostic_manager::finish_pruning): Likewise.
11817
11818 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11819
11820 * checker-path.h (checker_event::clone): Delete vfunc decl.
11821 (debug_event::clone): Delete vfunc impl.
11822 (custom_event::clone): Delete vfunc impl.
11823 (statement_event::clone): Delete vfunc impl.
11824 (function_entry_event::clone): Delete vfunc impl.
11825 (state_change_event::clone): Delete vfunc impl.
11826 (start_cfg_edge_event::clone): Delete vfunc impl.
11827 (end_cfg_edge_event::clone): Delete vfunc impl.
11828 (call_event::clone): Delete vfunc impl.
11829 (return_event::clone): Delete vfunc impl.
11830 (setjmp_event::clone): Delete vfunc impl.
11831 (rewind_from_longjmp_event::clone): Delete vfunc impl.
11832 (rewind_to_setjmp_event::clone): Delete vfunc impl.
11833 (warning_event::clone): Delete vfunc impl.
11834
11835 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11836
11837 * supergraph.cc (supernode::dump_dot): Ensure that the TABLE
11838 element has at least one TR.
11839
11840 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11841
11842 PR analyzer/58237
11843 * engine.cc (leak_stmt_finder::find_stmt): Use get_pure_location
11844 when comparing against UNKNOWN_LOCATION.
11845 (stmt_requires_new_enode_p): Likewise.
11846 (exploded_graph::dump_exploded_nodes): Likewise.
11847 * supergraph.cc (supernode::get_start_location): Likewise.
11848 (supernode::get_end_location): Likewise.
11849
11850 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11851
11852 PR analyzer/58237
11853 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11854 selftest::analyzer_sm_file_cc_tests.
11855 * analyzer-selftests.h (selftest::analyzer_sm_file_cc_tests): New
11856 decl.
11857 * sm-file.cc: Include "analyzer/function-set.h" and
11858 "analyzer/analyzer-selftests.h".
11859 (get_file_using_fns): New function.
11860 (is_file_using_fn_p): New function.
11861 (fileptr_state_machine::on_stmt): Return true for known functions.
11862 (selftest::analyzer_sm_file_cc_tests): New function.
11863
11864 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11865
11866 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11867 selftest::analyzer_sm_signal_cc_tests.
11868 * analyzer-selftests.h (selftest::analyzer_sm_signal_cc_tests):
11869 New decl.
11870 * sm-signal.cc: Include "analyzer/function-set.h" and
11871 "analyzer/analyzer-selftests.h".
11872 (get_async_signal_unsafe_fns): New function.
11873 (signal_unsafe_p): Reimplement in terms of the above.
11874 (selftest::analyzer_sm_signal_cc_tests): New function.
11875
11876 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11877
11878 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11879 selftest::analyzer_function_set_cc_tests.
11880 * analyzer-selftests.h (selftest::analyzer_function_set_cc_tests):
11881 New decl.
11882 * function-set.cc: New file.
11883 * function-set.h: New file.
11884
11885 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11886
11887 * analyzer.h (fndecl_has_gimple_body_p): New decl.
11888 * engine.cc (impl_region_model_context::on_unknown_change): New
11889 function.
11890 (fndecl_has_gimple_body_p): Make non-static.
11891 (exploded_node::on_stmt): Treat __analyzer_dump_exploded_nodes as
11892 known. Track whether we have a call with unknown side-effects and
11893 pass it to on_call_post.
11894 * exploded-graph.h (impl_region_model_context::on_unknown_change):
11895 New decl.
11896 * program-state.cc (sm_state_map::on_unknown_change): New function.
11897 * program-state.h (sm_state_map::on_unknown_change): New decl.
11898 * region-model.cc: Include "bitmap.h".
11899 (region_model::on_call_pre): Return a bool, capturing whether the
11900 call has unknown side effects.
11901 (region_model::on_call_post): Add arg "bool unknown_side_effects"
11902 and if true, call handle_unrecognized_call.
11903 (class reachable_regions): New class.
11904 (region_model::handle_unrecognized_call): New function.
11905 * region-model.h (region_model::on_call_pre): Return a bool.
11906 (region_model::on_call_post): Add arg "bool unknown_side_effects".
11907 (region_model::handle_unrecognized_call): New decl.
11908 (region_model_context::on_unknown_change): New vfunc.
11909 (test_region_model_context::on_unknown_change): New function.
11910
11911 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11912
11913 * diagnostic-manager.cc (saved_diagnostic::operator==): Move here
11914 from header. Replace pointer equality test on m_var with call to
11915 pending_diagnostic::same_tree_p.
11916 * diagnostic-manager.h (saved_diagnostic::operator==): Move to
11917 diagnostic-manager.cc.
11918 * pending-diagnostic.cc (pending_diagnostic::same_tree_p): New.
11919 * pending-diagnostic.h (pending_diagnostic::same_tree_p): New.
11920 * sm-file.cc (file_diagnostic::subclass_equal_p): Replace pointer
11921 equality on m_arg with call to pending_diagnostic::same_tree_p.
11922 * sm-malloc.cc (malloc_diagnostic::subclass_equal_p): Likewise.
11923 (possible_null_arg::subclass_equal_p): Likewise.
11924 (null_arg::subclass_equal_p): Likewise.
11925 (free_of_non_heap::subclass_equal_p): Likewise.
11926 * sm-pattern-test.cc (pattern_match::operator==): Likewise.
11927 * sm-sensitive.cc (exposure_through_output_file::operator==):
11928 Likewise.
11929 * sm-taint.cc (tainted_array_index::operator==): Likewise.
11930
11931 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11932
11933 * diagnostic-manager.cc (dedupe_winners::add): Add logging
11934 of deduplication decisions made.
11935
11936 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11937
11938 * ChangeLog: New file.
11939 * analyzer-selftests.cc: New file.
11940 * analyzer-selftests.h: New file.
11941 * analyzer.opt: New file.
11942 * analysis-plan.cc: New file.
11943 * analysis-plan.h: New file.
11944 * analyzer-logging.cc: New file.
11945 * analyzer-logging.h: New file.
11946 * analyzer-pass.cc: New file.
11947 * analyzer.cc: New file.
11948 * analyzer.h: New file.
11949 * call-string.cc: New file.
11950 * call-string.h: New file.
11951 * checker-path.cc: New file.
11952 * checker-path.h: New file.
11953 * constraint-manager.cc: New file.
11954 * constraint-manager.h: New file.
11955 * diagnostic-manager.cc: New file.
11956 * diagnostic-manager.h: New file.
11957 * engine.cc: New file.
11958 * engine.h: New file.
11959 * exploded-graph.h: New file.
11960 * pending-diagnostic.cc: New file.
11961 * pending-diagnostic.h: New file.
11962 * program-point.cc: New file.
11963 * program-point.h: New file.
11964 * program-state.cc: New file.
11965 * program-state.h: New file.
11966 * region-model.cc: New file.
11967 * region-model.h: New file.
11968 * sm-file.cc: New file.
11969 * sm-malloc.cc: New file.
11970 * sm-malloc.dot: New file.
11971 * sm-pattern-test.cc: New file.
11972 * sm-sensitive.cc: New file.
11973 * sm-signal.cc: New file.
11974 * sm-taint.cc: New file.
11975 * sm.cc: New file.
11976 * sm.h: New file.
11977 * state-purge.cc: New file.
11978 * state-purge.h: New file.
11979 * supergraph.cc: New file.
11980 * supergraph.h: New file.
11981
11982 2019-12-13 David Malcolm <dmalcolm@redhat.com>
11983
11984 * Initial creation
11985
11986 \f
11987 Copyright (C) 2019-2024 Free Software Foundation, Inc.
11988
11989 Copying and distribution of this file, with or without modification,
11990 are permitted in any medium without royalty provided the copyright
11991 notice and this notice are preserved.