1 2024-04-12 Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
3 * region-model.cc (region_model::check_region_size): Bail out
4 early on function pointers.
6 2024-04-10 David Malcolm <dmalcolm@redhat.com>
9 * access-diagram.cc (bit_size_expr::maybe_get_formatted_str):
10 Reject attempts to print sizes that are too large.
11 * region.cc (region_offset::calc_symbolic_bit_offset): Use a
12 typeless svalue for the bit offset.
13 * store.cc (bit_range::intersects_p): Replace assertion with
15 (bit_range::exceeds_p): Likewise.
16 (bit_range::falls_short_of_p): Likewise.
18 2024-04-10 David Malcolm <dmalcolm@redhat.com>
20 * infinite-loop.cc: Include "diagnostic-format-sarif.h".
21 (infinite_loop::to_json): New.
22 (infinite_loop_diagnostic::maybe_add_sarif_properties): New.
24 2024-04-10 David Malcolm <dmalcolm@redhat.com>
26 * infinite-recursion.cc: Include "diagnostic-format-sarif.h".
27 (infinite_recursion_diagnostic::maybe_add_sarif_properties): New.
29 2024-04-10 David Malcolm <dmalcolm@redhat.com>
31 * call-details.cc: Include "diagnostic-format-sarif.h".
32 (overlapping_buffers::overlapping_buffers): Add params for new
34 (overlapping_buffers::maybe_add_sarif_properties): New.
35 (overlapping_buffers::m_byte_range_a): New field.
36 (overlapping_buffers::byte_range_b): New field.
37 (overlapping_buffers::m_num_bytes_read_sval): New field.
38 (call_details::complain_about_overlap): Pass new params to
39 overlapping_buffers ctor.
40 * ranges.cc (symbolic_byte_offset::to_json): New.
41 (symbolic_byte_range::to_json): New.
42 * ranges.h (symbolic_byte_offset::to_json): New decl.
43 (symbolic_byte_range::to_json): New decl.
45 2024-04-10 David Malcolm <dmalcolm@redhat.com>
47 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
48 Add "size_in_bytes" param.
49 (tainted_allocation_size::maybe_add_sarif_properties): New.
50 (tainted_allocation_size::m_size_in_bytes): New field.
51 (region_model::check_dynamic_size_for_taint): Pass size_in_bytes
52 to tainted_allocation_size ctor.
54 2024-04-09 Jakub Jelinek <jakub@redhat.com>
56 * analyzer.opt (Wanalyzer-undefined-behavior-strtok): Fix duplicated
58 * program-state.cc (sm_state_map::replay_call_summary): Fix duplicated
59 words in comment; to to -> to.
60 (program_state::replay_call_summary): Likewise.
61 * region-model.cc (region_model::replay_call_summary): Likewise.
63 2024-04-05 David Malcolm <dmalcolm@redhat.com>
66 * access-diagram.cc (access_diagram_impl::access_diagram_impl):
67 Replace hardcoded colors for valid_style and invalid_style with
68 calls to text_art::get_style_from_color_cap_name.
70 2024-04-02 David Malcolm <dmalcolm@redhat.com>
72 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
73 Guard against null types.
74 * region-model.cc (apply_constraints_for_gswitch): Likewise.
76 2024-03-27 David Malcolm <dmalcolm@redhat.com>
80 (call_summary_replay::convert_svalue_from_summary): Assert that
82 (call_summary_replay::convert_region_from_summary): Likewise.
83 (call_summary_replay::convert_region_from_summary_1): Add missing
84 cast for the deref of RK_SYMBOLIC case.
86 2024-03-23 David Malcolm <dmalcolm@redhat.com>
89 * engine.cc (impl_run_checkers): Free up any dominance info that
91 * kf.cc (class kf_ubsan_handler): New.
92 (register_sanitizer_builtins): New.
93 (register_known_functions): Call register_sanitizer_builtins.
95 2024-03-22 David Malcolm <dmalcolm@redhat.com>
99 * sm-taint.cc (taint_state_machine::on_condition): Strip away
100 casts before considering LHS and RHS, to increase the chance of
101 detecting places where sanitization of a value may have happened.
103 2024-03-22 David Malcolm <dmalcolm@redhat.com>
105 * sm-taint.cc: Include "diagnostic-format-sarif.h".
106 (bounds_to_str): New.
107 (taint_diagnostic::maybe_add_sarif_properties): New.
108 (tainted_offset::tainted_offset): Add "offset" param.
109 (tainted_offset::maybe_add_sarif_properties): New.
110 (tainted_offset::m_offset): New.
111 (region_model::check_region_for_taint): Pass offset to
114 2024-03-21 David Malcolm <dmalcolm@redhat.com>
117 * region-model.cc (region_model::eval_condition): Fix
118 cast-handling from r14-3632-ge7b267444045c5 so that if those give
119 an unknown result, we continue trying the constraint manager.
121 2024-03-20 David Malcolm <dmalcolm@redhat.com>
124 * sm-malloc.cc (deref_before_check::emit): Reject cases where the
125 check is in a loop header within a macro expansion.
126 (deref_before_check::loop_header_p): New.
128 2024-03-20 Jakub Jelinek <jakub@redhat.com>
130 * constraint-manager.cc (test_range, test_constraint_conditions,
131 test_constant_comparisons, test_constraint_impl, test_purging,
132 test_bits): Use integer_zero_node instead of
133 build_zero_cst (integer_type_node) or
134 build_int_cst (integer_type_node, 0) and integer_one_node instead of
135 build_int_cst (integer_type_node, 1).
136 * region-model.cc (region_model::get_store_value,
137 append_interesting_constants, test_array_1,
138 test_get_representative_tree, test_unique_constants, test_assignment,
139 test_stack_frames, test_constraint_merging, test_widening_constraints,
140 test_iteration_1, test_array_2): Likewise.
142 2024-03-19 Jakub Jelinek <jakub@redhat.com>
145 * region-model.cc (get_tree_for_byte_offset,
146 region_model::get_representative_path_var_1,
147 test_mem_ref, test_POINTER_PLUS_EXPR_then_MEM_REF): Use
148 char __attribute__((may_alias)) * as type of MEM_REF second argument.
150 2024-03-19 David Malcolm <dmalcolm@redhat.com>
153 * kf.cc (class kf_atomic_exchange): Reimplement based on signature
154 seen in gimple, rather than user-facing signature.
155 (class kf_atomic_load): Likewise.
156 (class kf_atomic_store): New.
157 (register_atomic_builtins): Register kf_atomic_store.
159 2024-03-18 David Malcolm <dmalcolm@redhat.com>
165 * access-diagram.cc: Include "analyzer/analyzer-selftests.h".
166 (get_access_size_str): Reimplement for conversion of
167 implmementation of bit_size_expr from tree to const svalue &. Use
168 svalue::maybe_print_for_user rather than tree printing routines.
169 (remove_ssa_names): Make non-static.
170 (bit_size_expr::get_formatted_str): Rename to...
171 (bit_size_expr::maybe_get_formatted_str): ...this, adding "model"
172 param and converting return type to a unique_ptr. Update for
173 conversion of implementation of bit_size_expr from tree to
174 const svalue &. Use svalue::maybe_print_for_user rather than tree
176 (bit_size_expr::print): Rename to...
177 (bit_size_expr::maybe_print_for_user): ...this, adding "model"
178 param and converting return type to bool. Update for
179 conversion of implementation of bit_size_expr from tree to
180 const svalue &. Use svalue::maybe_print_for_user rather than tree
182 (bit_size_expr::maybe_get_as_bytes): Add "mgr" param and convert
183 return type from tree to const svalue *; reimplement.
184 (access_range::access_range): Call strip_types when on region_offset
186 (access_range::get_size): Update for conversion of implementation
187 of bit_size_expr from tree to const svalue &.
188 (access_operation::get_valid_bits): Pass manager to access_range
190 (access_operation::maybe_get_invalid_before_bits): Likewise.
191 (access_operation::maybe_get_invalid_after_bits): Likewise.
192 (boundaries::add): Likewise.
193 (bit_to_table_map::populate): Add "mgr" param and pass it to
195 (access_diagram_impl::access_diagram_impl): Pass manager to
196 bit_to_table_map::populate.
197 (access_diagram_impl::maybe_add_gap): Use svalue rather than tree
198 for symbolic bit offsets. Port to new bit_size_expr
200 (access_diagram_impl::add_valid_vs_invalid_ruler): Port to new
201 bit_size_expr representation.
202 (selftest::assert_eq_typeless_integer): New.
203 (ASSERT_EQ_TYPELESS_INTEGER): New.
204 (selftest::test_bit_size_expr_to_bytes): New.
205 (selftest::analyzer_access_diagram_cc_tests): New.
206 * access-diagram.h (class bit_size_expr): Reimplement, converting
207 implementation from tree to const svalue &.
208 (access_range::access_range): Add "mgr" param. Call strip_types
209 on region_offset initializations.
210 (access_range::get_size): Update decl for reimplementation.
211 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
212 selftest::analyzer_access_diagram_cc_tests.
213 * analyzer-selftests.h
214 (selftest::analyzer_checker_script_cc_tests): Delete this stray
216 (selftest::analyzer_access_diagram_cc_tests): New decl.
217 * analyzer.h (print_expr_for_user): New decl.
218 (calc_symbolic_bit_offset): Update decl for reimplementation.
219 (strip_types): New decls.
220 (remove_ssa_names): New decl.
221 * bounds-checking.cc (strip_types): New.
222 (region_model::check_symbolic_bounds): Use typeless svalues.
223 * region-model-manager.cc
224 (region_model_manager::get_or_create_constant_svalue): Add "type"
225 param. Add overload with old signature.
226 (region_model_manager::get_or_create_int_cst): Support type being
228 (region_model_manager::maybe_fold_unaryop): Gracefully reject folding
229 of casts to NULL_TREE type.
230 (get_code_for_cast): Use NOP_EXPR for "casting" svalues to
232 (region_model_manager::get_or_create_cast): Support "casting"
233 svalues to NULL_TREE type.
234 (region_model_manager::maybe_fold_binop): Don't crash on inputs
235 with NULL_TREE type. Handle folding of binops on constants with
236 NULL_TREE type. Add missing cast from PR analyzer/110902.
237 Support enough folding of other ops on NULL_TREE type to support
239 (region_model_manager::get_or_create_const_fn_result_svalue):
240 Remove assertion that type is nonnull.
241 * region-model-manager.h
242 (region_model_manager::get_or_create_constant_svalue): Add
243 overloaded decl taking a type.
244 (region_model_manager::maybe_fold_binop): Make public.
245 (region_model_manager::constants_map_t): Use
246 constant_svalue::key_t for the key, rather than just tree.
247 * region-model.cc (print_expr_for_user): New.
248 (selftest::test_array_2): Handle casts.
249 * region.cc (region_offset::calc_symbolic_bit_offset): Return
250 const svalue & rather than tree, and reimplement accordingly.
251 (region::calc_offset): Use ptrdiff_type_node for types of byte
253 (region::maybe_print_for_user): New.
254 (element_region::get_relative_symbolic_offset): Use NULL_TREE for
255 types of bit offsets.
256 (offset_region::get_bit_offset): Likewise.
257 (sized_region::get_bit_size_sval): Likewise for bit sizes.
258 * region.h (region::maybe_print_for_user): New decl.
259 * svalue.cc (class auto_add_parens): New.
260 (svalue::maybe_print_for_user): New.
261 (svalue::cmp_ptr): Support typeless constant svalues.
262 (tristate_from_boolean_tree_node): New, taken from...
263 (constant_svalue::eval_condition): ...here. Handle comparison of
264 typeless integer svalue constants.
265 * svalue.h (svalue::maybe_print_for_user): New decl.
266 (class constant_svalue): Support the type of the svalue being
268 (struct default_hash_traits<constant_svalue::key_t>): New.
270 2024-03-18 David Malcolm <dmalcolm@redhat.com>
272 * access-diagram.cc (remove_ssa_names): Support operands being
273 NULL_TREE, such as e.g. for COMPONENT_REF's operand 2.
275 2024-03-07 Jakub Jelinek <jakub@redhat.com>
277 * access-diagram.cc: Include diagnostic-core.h before including
278 diagnostic.h or diagnostic-path.h.
279 * sm-malloc.cc: Likewise.
280 * diagnostic-manager.cc: Likewise.
281 * call-summary.cc: Likewise.
282 * record-layout.cc: Likewise.
284 2024-02-29 David Malcolm <dmalcolm@redhat.com>
287 * analyzer.cc: Include "tree-dfa.h".
288 (get_ssa_default_def): New decl.
289 * analyzer.h (get_ssa_default_def): New.
290 * call-info.cc (call_info::call_info): New ctor taking an explicit
292 * call-info.h (call_info::call_info): Likewise.
293 * call-summary.cc (call_summary_replay::call_summary_replay):
294 Convert param from function * to const function &.
295 * call-summary.h (call_summary_replay::call_summary_replay):
297 * checker-event.h (state_change_event::get_dest_function):
298 Constify return value.
299 * engine.cc (point_and_state::validate): Update for conversion to
301 (exploded_node::on_stmt): Likewise.
302 (call_summary_edge_info::call_summary_edge_info): Likewise.
303 Pass in called_fn to call_info ctor.
304 (exploded_node::replay_call_summaries): Update for conversion to
305 const function &. Convert per_function_data from * to &.
306 (exploded_node::replay_call_summary): Update for conversion to
308 (exploded_graph::add_function_entry): Likewise.
309 (toplevel_function_p): Likewise.
310 (add_tainted_args_callback): Likewise.
311 (exploded_graph::build_initial_worklist): Likewise.
312 (exploded_graph::maybe_create_dynamic_call): Likewise.
313 (maybe_update_for_edge): Likewise.
314 (exploded_graph::on_escaped_function): Likewise.
315 * exploded-graph.h (exploded_node::replay_call_summaries):
317 (exploded_node::replay_call_summary): Likewise.
318 (exploded_graph::add_function_entry): Likewise.
319 * program-point.cc (function_point::from_function_entry):
321 (program_point::from_function_entry): Likewise.
322 * program-point.h (function_point::from_function_entry): Likewise.
323 (program_point::from_function_entry): Likewise.
324 * program-state.cc (program_state::push_frame): Likewise.
325 (program_state::get_current_function): Constify return type.
326 * program-state.h (program_state::push_frame): Update for
327 conversion to const function &.
328 (program_state::get_current_function): Likewise.
329 * region-model-manager.cc
330 (region_model_manager::get_frame_region): Likewise.
331 * region-model-manager.h
332 (region_model_manager::get_frame_region): Likewise.
333 * region-model.cc (region_model::called_from_main_p): Likewise.
334 (region_model::update_for_gcall): Likewise.
335 (region_model::push_frame): Likewise.
336 (region_model::get_current_function): Constify return type.
337 (region_model::pop_frame): Update for conversion to
339 (selftest::test_stack_frames): Likewise.
340 (selftest::test_get_representative_path_var): Likewise.
341 (selftest::test_state_merging): Likewise.
342 (selftest::test_alloca): Likewise.
343 * region-model.h (region_model::push_frame): Likewise.
344 (region_model::get_current_function): Likewise.
345 * region.cc (frame_region::dump_to_pp): Likewise.
346 (frame_region::get_region_for_local): Likewise.
347 * region.h (class frame_region): Likewise.
348 * sm-signal.cc (signal_unsafe_call::describe_state_change):
350 (update_model_for_signal_handler): Likewise.
351 (signal_delivery_edge_info_t::update_model): Likewise.
352 (register_signal_handler::impl_transition): Likewise.
353 * state-purge.cc (class gimple_op_visitor): Likewise.
354 (state_purge_map::state_purge_map): Likewise.
355 (state_purge_map::get_or_create_data_for_decl): Likewise.
356 (state_purge_per_ssa_name::state_purge_per_ssa_name): Likewise.
357 (state_purge_per_ssa_name::add_to_worklist): Likewise.
358 (state_purge_per_ssa_name::process_point): Likewise.
359 (state_purge_per_decl::add_to_worklist): Likewise.
360 (state_purge_annotator::print_needed): Likewise.
362 (state_purge_map::get_or_create_data_for_decl): Likewise.
363 (class state_purge_per_tree): Likewise.
364 (class state_purge_per_ssa_name): Likewise.
365 (class state_purge_per_decl): Likewise.
366 * supergraph.cc (supergraph::dump_dot_to_pp): Likewise.
368 (supergraph::get_node_for_function_entry): Likewise.
369 (supergraph::get_node_for_function_exit): Likewise.
371 2024-02-27 David Malcolm <dmalcolm@redhat.com>
376 (string_literal_spatial_item::add_column_for_byte): Use %wu for
377 printing unsigned HOST_WIDE_INT.
379 2024-02-27 David Malcolm <dmalcolm@redhat.com>
382 * constraint-manager.cc (bound::ensure_closed): Assert that
383 m_constant has integral type.
384 (range::add_bound): Bail out on floating point constants.
386 2024-02-21 David Malcolm <dmalcolm@redhat.com>
389 * analyzer.h (get_string_cst_size): New decl.
390 * region-model-manager.cc (get_string_cst_size): New.
391 (region_model_manager::maybe_get_char_from_string_cst): Treat
392 single-byte accesses within string_cst but beyond
393 TREE_STRING_LENGTH as being 0.
394 * region-model.cc (string_cst_has_null_terminator): Likewise.
396 2024-02-21 David Malcolm <dmalcolm@redhat.com>
399 * ranges.cc (symbolic_byte_range::intersection): Handle empty ranges.
400 (selftest::test_intersects): Add test coverage for empty ranges.
402 2024-02-19 David Malcolm <dmalcolm@redhat.com>
405 * varargs.cc (representable_in_integral_type_p): New.
406 (va_arg_compatible_types_p): Add "arg_sval" param. Handle integer
408 (kf_va_arg::impl_call_pre): Pass arg_sval to
409 va_arg_compatible_types_p.
411 2024-02-19 Andrew Pinski <quic_apinski@quicinc.com>
414 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Reject
417 2024-02-15 David Malcolm <dmalcolm@redhat.com>
420 * region.cc (offset_region::get_byte_size_sval): Delete.
421 (offset_region::get_bit_size_sval): Delete.
422 * region.h (region::get_byte_size): Add comment clarifying that
423 this relates to the size of the access, rather than the size
424 that's valid to access.
425 (region::get_bit_size): Likewise.
426 (region::get_byte_size_sval): Likewise.
427 (region::get_bit_size_sval): Likewise.
428 (offset_region::get_byte_size_sval): Delete.
429 (offset_region::get_bit_size_sval): Delete.
431 2024-02-13 David Malcolm <dmalcolm@redhat.com>
433 * pending-diagnostic.cc (diagnostic_emission_context::warn):
434 Update for renaming of emit_diagnostic_valist overload to
435 emit_diagnostic_valist_meta.
436 (diagnostic_emission_context::inform): Likewise.
438 2024-01-31 David Malcolm <dmalcolm@redhat.com>
441 * region-model.cc (region_model::on_stmt_pre): Add gcc_unreachable
442 for debug statements.
444 (state_purge_per_ssa_name::state_purge_per_ssa_name): Skip any
445 debug stmts in the FOR_EACH_IMM_USE_FAST list.
446 * supergraph.cc (supergraph::supergraph): Don't add debug stmts
449 2024-01-31 David Malcolm <dmalcolm@redhat.com>
452 * checker-event.cc (state_change_event::get_desc): Don't assume
455 2024-01-30 David Malcolm <dmalcolm@redhat.com>
458 * region-model.cc (is_round_up): New.
459 (is_multiple_p): New.
460 (is_dubious_capacity): New.
461 (region_model::check_region_size): Move usage of size_visitor into
464 2024-01-30 David Malcolm <dmalcolm@redhat.com>
467 (dubious_allocation_size::dubious_allocation_size): Add
468 "capacity_sval" param. Drop unused ctor.
469 (dubious_allocation_size::maybe_add_sarif_properties): New.
470 (dubious_allocation_size::m_capacity_sval): New field.
471 (region_model::check_region_size): Pass capacity svalue to
472 dubious_allocation_size ctor.
474 2024-01-25 David Malcolm <dmalcolm@redhat.com>
477 * store.cc (binding_cluster::maybe_get_compound_binding): When
478 populating default_map, express the bit-range of the default key
479 for REG relative to REG, rather than to the base region.
481 2024-01-24 David Malcolm <dmalcolm@redhat.com>
484 * engine.cc (impl_region_model_context::on_liveness_change): Pass
485 m_ext_state to sm_state_map::on_liveness_change.
486 * program-state.cc (sm_state_map::on_svalue_leak): Guard removal
487 of map entry based on can_purge_p.
488 (sm_state_map::on_liveness_change): Add ext_state param. Add
489 workaround for bad interaction between state purging and
490 alt-inherited sm-state.
491 * program-state.h (sm_state_map::on_liveness_change): Add
494 (taint_state_machine::has_alt_get_inherited_state_p): New.
495 (taint_state_machine::can_purge_p): Return false for "has_lb" and
497 * sm.h (state_machine::has_alt_get_inherited_state_p): New vfunc.
499 2024-01-18 David Malcolm <dmalcolm@redhat.com>
502 * region-model.cc (svalue_byte_range_has_null_terminator_1): The
503 initial byte of an all-zeroes SVAL is a zero byte. Remove
504 gcc_unreachable from SK_CONSTANT for constants that aren't
505 STRING_CST or INTEGER_CST.
507 2024-01-18 David Malcolm <dmalcolm@redhat.com>
510 * region-model.cc (fragment::dump_to_pp): New.
511 (fragment::has_null_terminator): Convert to...
512 (svalue_byte_range_has_null_terminator_1): ...this new function,
513 updating to use a byte_range relative to the start of the svalue.
514 (svalue_byte_range_has_null_terminator): New.
515 (fragment::string_cst_has_null_terminator): Convert to...
516 (string_cst_has_null_terminator): ...this, updating to use a
517 byte_range relative to the start of the svalue.
518 (iterable_cluster::dump_to_pp): New.
519 (region_model::scan_for_null_terminator): Add logging, moving body
521 (region_model::scan_for_null_terminator_1): ...this new function,
522 adding more logging, and updating to use
523 svalue_byte_range_has_null_terminator.
524 * region-model.h (region_model::scan_for_null_terminator_1): New
527 2024-01-16 David Malcolm <dmalcolm@redhat.com>
530 * analyzer.h (compare_constants): New decl.
531 * constraint-manager.cc (compare_constants): Make non-static.
532 * sm-taint.cc: Add include "fold-const.h".
533 (class concrete_range): New.
534 (get_possible_range): New.
535 (index_can_be_out_of_bounds_p): New.
536 (region_model::check_region_for_taint): Reject
537 -Wanalyzer-tainted-array-index if the type of the value makes it
538 impossible for it to be out-of-bounds of the array.
540 2024-01-16 David Malcolm <dmalcolm@redhat.com>
543 * region-model-manager.cc
544 (region_model_manager::maybe_fold_unaryop): Casting all zeroes
545 should give all zeroes.
547 2024-01-04 David Malcolm <dmalcolm@redhat.com>
549 * analyzer.opt.urls: New file, autogenerated by
550 regenerate-opt-urls.py.
552 2024-01-04 David Malcolm <dmalcolm@redhat.com>
554 * checker-event.cc: Include "diagnostic-format-sarif.h" and
555 "tree-logical-location.h".
556 (checker_event::maybe_add_sarif_properties): New.
557 (superedge_event::maybe_add_sarif_properties): New.
558 (superedge_event::superedge_event): Add comment.
559 * checker-event.h (checker_event::maybe_add_sarif_properties): New
561 (superedge_event::maybe_add_sarif_properties): New decl.
563 2024-01-04 David Malcolm <dmalcolm@redhat.com>
566 * checker-event.cc (class inlining_info): Move to...
567 * inlining-iterator.h (class inlining_info): ...here.
568 * sm-malloc.cc: Include "analyzer/inlining-iterator.h".
569 (maybe_complain_about_deref_before_check): Reject stmts that were
570 inlined from another function.
572 2024-01-04 David Malcolm <dmalcolm@redhat.com>
575 * access-diagram.cc (valid_region_spatial_item::add_boundaries):
576 Handle TYPE_DOMAIN being null.
577 (valid_region_spatial_item::add_array_elements_to_table):
580 2023-12-16 David Malcolm <dmalcolm@redhat.com>
582 * analyzer.cc: Include "tree-pretty-print.h" and
583 "diagnostic-event-id.h".
585 (diagnostic_event_id_to_json): New.
586 (bit_offset_to_json): New.
587 (byte_offset_to_json): New.
588 * analyzer.h (tree_to_json): New decl.
589 (diagnostic_event_id_to_json): New decl.
590 (bit_offset_to_json): New decl.
591 (byte_offset_to_json): New decl.
592 * bounds-checking.cc: Include "diagnostic-format-sarif.h".
593 (out_of_bounds::maybe_add_sarif_properties): New.
594 (concrete_out_of_bounds::maybe_add_sarif_properties): New.
595 (concrete_past_the_end::maybe_add_sarif_properties): New.
596 (symbolic_past_the_end::maybe_add_sarif_properties): New.
597 * region-model.cc (region_to_value_map::to_json): New.
598 (region_model::to_json): New.
599 * region-model.h (region_to_value_map::to_json): New decl.
600 (region_model::to_json): New decl.
601 * store.cc (bit_range::to_json): New.
602 (byte_range::to_json): New.
603 * store.h (bit_range::to_json): New decl.
604 (byte_range::to_json): New decl.
606 2023-12-16 David Malcolm <dmalcolm@redhat.com>
610 (out_of_bounds::oob_region_creation_event_capacity): Rename
611 "capacity" to "byte_capacity". Layout fix.
612 (out_of_bounds::::add_region_creation_events): Rename
613 "capacity" to "byte_capacity".
614 (class concrete_out_of_bounds): Rename m_out_of_bounds_range to
615 m_out_of_bounds_bits and convert from a byte_range to a bit_range.
616 (concrete_out_of_bounds::get_out_of_bounds_bytes): New.
617 (concrete_past_the_end::concrete_past_the_end): Rename param
618 "byte_bound" to "bit_bound". Initialize m_byte_bound.
619 (concrete_past_the_end::subclass_equal_p): Update for renaming
620 of m_byte_bound to m_bit_bound.
621 (concrete_past_the_end::m_bit_bound): New field.
622 (concrete_buffer_overflow::concrete_buffer_overflow): Convert
623 param "range" from byte_range to bit_range. Rename param
624 "byte_bound" to "bit_bound".
625 (concrete_buffer_overflow::emit): Update for bits vs bytes.
626 (concrete_buffer_overflow::describe_final_event): Split
628 (concrete_buffer_overflow::describe_final_event_as_bytes): ...this
629 (concrete_buffer_overflow::describe_final_event_as_bits): ...and
631 (concrete_buffer_over_read::concrete_buffer_over_read): Convert
632 param "range" from byte_range to bit_range. Rename param
633 "byte_bound" to "bit_bound".
634 (concrete_buffer_over_read::emit): Update for bits vs bytes.
635 (concrete_buffer_over_read::describe_final_event): Split into...
636 (concrete_buffer_over_read::describe_final_event_as_bytes):
638 (concrete_buffer_over_read::describe_final_event_as_bits): ...and
640 (concrete_buffer_underwrite::concrete_buffer_underwrite): Convert
641 param "range" from byte_range to bit_range.
642 (concrete_buffer_underwrite::describe_final_event): Split into...
643 (concrete_buffer_underwrite::describe_final_event_as_bytes):
645 (concrete_buffer_underwrite::describe_final_event_as_bits): ...and
647 (concrete_buffer_under_read::concrete_buffer_under_read): Convert
648 param "range" from byte_range to bit_range.
649 (concrete_buffer_under_read::describe_final_event): Split into...
650 (concrete_buffer_under_read::describe_final_event_as_bytes):
652 (concrete_buffer_under_read::describe_final_event_as_bits): ...and
654 (region_model::check_region_bounds): Use bits for concrete values,
655 and rename locals to indicate whether we're dealing with bits or
656 bytes. Specifically, replace "num_bytes_sval" with
657 "num_bits_sval", and get it from reg's "get_bit_size_sval".
658 Replace "num_bytes_tree" with "num_bits_tree". Rename "capacity"
659 to "byte_capacity". Rename "cst_capacity_tree" to
660 "cst_byte_capacity_tree". Replace "offset" and
661 "num_bytes_unsigned" with "bit_offset" and "num_bits_unsigned"
662 respectively, converting from byte_offset_t to bit_offset_t.
663 Replace "out" and "read_bytes" with "bits_outside" and "read_bits"
664 respectively, converting from byte_range to bit_range. Convert
665 "buffer" from byte_range to bit_range. Replace "byte_bound" with
667 * region.cc (region::get_bit_size_sval): New.
668 (offset_region::get_bit_offset): New.
669 (offset_region::get_bit_size_sval): New.
670 (sized_region::get_bit_size_sval): New.
671 (bit_range_region::get_bit_size_sval): New.
672 * region.h (region::get_bit_size_sval): New vfunc.
673 (offset_region::get_bit_offset): New decl.
674 (offset_region::get_bit_size_sval): New decl.
675 (sized_region::get_bit_size_sval): New decl.
676 (bit_range_region::get_bit_size_sval): New decl.
677 * store.cc (bit_range::intersects_p): New, based on
678 byte_range::intersects_p.
679 (bit_range::exceeds_p): New, based on byte_range::exceeds_p.
680 (bit_range::falls_short_of_p): New, based on
681 byte_range::falls_short_of_p.
682 (byte_range::intersects_p): Delete.
683 (byte_range::exceeds_p): Delete.
684 (byte_range::falls_short_of_p): Delete.
685 * store.h (bit_range::intersects_p): New overload.
686 (bit_range::exceeds_p): New.
687 (bit_range::falls_short_of_p): New.
688 (byte_range::intersects_p): Delete.
689 (byte_range::exceeds_p): Delete.
690 (byte_range::falls_short_of_p): Delete.
692 2023-12-14 David Malcolm <dmalcolm@redhat.com>
695 * infinite-loop.cc (infinite_loop::infinite_loop): Pass eedges
696 via rvalue reference rather than by value.
697 (starts_infinite_loop_p): Move eedges when constructing an
698 infinite_loop instance.
699 * sm-file.cc (fileptr_state_machine::fileptr_state_machine): Use
700 initializer list for states.
702 (sensitive_state_machine::sensitive_state_machine): Likewise.
703 * sm-signal.cc (signal_state_machine::signal_state_machine):
705 * sm-taint.cc (taint_state_machine::taint_state_machine):
707 * varargs.cc (va_list_state_machine::va_list_state_machine): Likewise.
709 2023-12-11 David Malcolm <dmalcolm@redhat.com>
712 * engine.cc (feasibility_state::feasibility_state): Initialize
715 2023-12-11 Andrew Pinski <apinski@marvell.com>
717 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Remove
718 the check for type being unsigned_char_type_node.
720 2023-12-08 David Malcolm <dmalcolm@redhat.com>
722 * sm-taint.cc (taint_state_machine::alt_get_inherited_state): Fix
723 handling of TRUNC_MOD_EXPR.
725 2023-12-08 David Malcolm <dmalcolm@redhat.com>
727 * region-model.cc (contains_uninit_p): Only check for
728 svalues that the infoleak warning can handle.
730 2023-12-08 David Malcolm <dmalcolm@redhat.com>
733 * store.h (concrete_binding::concrete_binding): Strengthen
734 assertion to require size to be be positive, rather than just
736 (concrete_binding::mark_deleted): Use size rather than start bit
738 (concrete_binding::mark_empty): Likewise.
739 (concrete_binding::is_deleted): Likewise.
740 (concrete_binding::is_empty): Likewise.
742 2023-12-07 Alexandre Oliva <oliva@adacore.com>
744 * region-model.cc (has_nondefault_case_for_value_p): Take
745 enumerate type as a parameter.
746 (region_model::apply_constraints_for_gswitch): Cope with
747 integral promotion type casts.
749 2023-12-07 David Malcolm <dmalcolm@redhat.com>
753 * analyzer.opt (-param=analyzer-max-svalue-depth=): Increase from
755 (Wanalyzer-symbol-too-complex): New.
756 * diagnostic-manager.cc
757 (null_assignment_sm_context::clear_all_per_svalue_state): New.
758 * engine.cc (impl_sm_context::clear_all_per_svalue_state): New.
759 * program-state.cc (sm_state_map::clear_all_per_svalue_state):
761 * program-state.h (sm_state_map::clear_all_per_svalue_state): New
763 * region-model-manager.cc
764 (region_model_manager::reject_if_too_complex): Add
765 -Wanalyzer-symbol-too-complex.
766 * sm-taint.cc (taint_state_machine::on_condition): Handle
767 comparisons against UNKNOWN.
768 * sm.h (sm_context::clear_all_per_svalue_state): New.
770 2023-12-06 David Malcolm <dmalcolm@redhat.com>
772 * engine.cc (dump_analyzer_json): Use
773 flag_diagnostics_json_formatting.
775 2023-12-01 David Malcolm <dmalcolm@redhat.com>
777 * analyzer.h (class saved_diagnostic): New forward decl.
778 * bounds-checking.cc: Update for changes to
779 pending_diagnostic::emit.
780 * call-details.cc: Likewise.
781 * diagnostic-manager.cc: Include "diagnostic-format-sarif.h".
782 (saved_diagnostic::maybe_add_sarif_properties): New.
783 (class pending_diagnostic_metadata): New.
784 (diagnostic_manager::emit_saved_diagnostic): Create a
785 pending_diagnostic_metadata and a diagnostic_emission_context.
786 Pass the latter to the pending_diagnostic::emit vfunc.
787 * diagnostic-manager.h
788 (saved_diagnostic::maybe_add_sarif_properties): New decl.
789 * engine.cc: Update for changes to pending_diagnostic::emit.
790 * infinite-loop.cc: Likewise.
791 * infinite-recursion.cc: Likewise.
792 * kf-analyzer.cc: Likewise.
794 * pending-diagnostic.cc
795 (diagnostic_emission_context::get_pending_diagnostic): New.
796 (diagnostic_emission_context::warn): New.
797 (diagnostic_emission_context::inform): New.
798 * pending-diagnostic.h (class diagnostic_emission_context): New.
799 (pending_diagnostic::emit): Update params.
800 (pending_diagnostic::maybe_add_sarif_properties): New vfunc.
801 * region.cc: Don't include "diagnostic-metadata.h".
802 * region-model.cc: Include "diagnostic-format-sarif.h". Update
803 for changes to pending_diagnostic::emit.
804 (exposure_through_uninit_copy::maybe_add_sarif_properties): New.
805 * sm-fd.cc: Update for changes to pending_diagnostic::emit.
806 * sm-file.cc: Likewise.
807 * sm-malloc.cc: Likewise.
808 * sm-pattern-test.cc: Likewise.
809 * sm-sensitive.cc: Likewise.
810 * sm-signal.cc: Likewise.
811 * sm-taint.cc: Likewise.
812 * store.cc: Don't include "diagnostic-metadata.h".
813 * varargs.cc: Update for changes to pending_diagnostic::emit.
815 2023-11-19 David Malcolm <dmalcolm@redhat.com>
817 * analyzer.h: Include "rich-location.h".
819 2023-11-19 David Malcolm <dmalcolm@redhat.com>
822 * analyzer.h (register_known_functions): Add region_model_manager
824 * analyzer.opt (Wanalyzer-undefined-behavior-strtok): New.
826 (call_summary_replay::convert_region_from_summary_1): Handle
828 * engine.cc (impl_run_checkers): Pass model manager to
829 register_known_functions.
830 * kf.cc (class undefined_function_behavior): New.
831 (class kf_strtok): New.
832 (register_known_functions): Add region_model_manager param.
833 Use it to register "strtok".
834 * region-model-manager.cc
835 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
837 * region-model-manager.h
838 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
840 (region_model_manager::get_root_region): New accessor.
841 * region-model.cc (region_model::scan_for_null_terminator): Handle
843 (region_model::get_representative_path_var_1): Handle RK_PRIVATE.
844 * region-model.h (region_model::called_from_main_p): Make public.
845 * region.cc (region::get_memory_space): Handle RK_PRIVATE.
846 (region::can_have_initial_svalue_p): Handle MEMSPACE_PRIVATE.
847 (private_region::dump_to_pp): New.
848 * region.h (MEMSPACE_PRIVATE): New.
850 (class private_region): New.
851 (is_a_helper <const private_region *>::test): New.
852 * store.cc (store::replay_call_summary_cluster): Handle
854 * svalue.h (struct conjured_svalue::key_t): Add "idx" param to
855 ctor and "m_idx" field.
856 (class conjured_svalue::conjured_svalue): Likewise.
858 2023-11-18 David Malcolm <dmalcolm@redhat.com>
861 * analyzer.opt (Wanalyzer-infinite-loop): New option.
862 (fdump-analyzer-infinite-loop): New option.
863 * checker-event.h (start_cfg_edge_event::get_desc): Drop "final".
864 (start_cfg_edge_event::maybe_describe_condition): Convert from
865 private to protected.
866 * checker-path.h (checker_path::get_logger): New.
867 * diagnostic-manager.cc (process_worklist_item): Update for
868 new context param of maybe_update_for_edge.
870 (impl_region_model_context::impl_region_model_context): Add
871 out_could_have_done_work param to both ctors and use it to
872 initialize mm_out_could_have_done_work.
873 (impl_region_model_context::maybe_did_work): New vfunc
875 (exploded_node::on_stmt): Add out_could_have_done_work param and
877 (exploded_node::on_stmt_pre): Treat setjmp and longjmp as "doing
879 (exploded_node::on_longjmp): Likewise.
880 (exploded_edge::exploded_edge): Add "could_do_work" param and use
881 it to initialize m_could_do_work_p.
882 (exploded_edge::dump_dot_label): Add result of could_do_work_p.
883 (exploded_graph::add_function_entry): Mark edge as doing no work.
884 (exploded_graph::add_edge): Add "could_do_work" param and pass to
886 (add_tainted_args_callback): Treat as doing no work.
887 (exploded_graph::process_worklist): Likewise when merging nodes.
888 (maybe_process_run_of_before_supernode_enodes::item): Likewise.
889 (exploded_graph::maybe_create_dynamic_call): Likewise.
890 (exploded_graph::process_node): Likewise for phi nodes.
891 Pass in a "could_have_done_work" bool when handling stmts and use
892 when creating edges. Assume work is done at bifurcation.
893 (exploded_path::feasible_p): Update for new context param of
894 maybe_update_for_edge.
895 (feasibility_state::feasibility_state): New ctor.
896 (feasibility_state::operator=): New.
897 (feasibility_state::maybe_update_for_edge): Add ctxt param and use
898 it. Fix missing newline when logging state.
899 (impl_run_checkers): Call exploded_graph::detect_infinite_loops.
901 (impl_region_model_context::impl_region_model_context): Add
902 out_could_have_done_work param to both ctors.
903 (impl_region_model_context::maybe_did_work): New decl.
904 (impl_region_model_context::checking_for_infinite_loop_p): New.
905 (impl_region_model_context::on_unusable_in_infinite_loop): New.
906 (impl_region_model_context::m_out_could_have_done_work): New
908 (exploded_node::on_stmt): Add "out_could_have_done_work" param.
909 (exploded_edge::exploded_edge): Add "could_do_work" param.
910 (exploded_edge::could_do_work_p): New accessor.
911 (exploded_edge::m_could_do_work_p): New field.
912 (exploded_graph::add_edge): Add "could_do_work" param.
913 (exploded_graph::detect_infinite_loops): New decl.
914 (feasibility_state::feasibility_state): New ctor.
915 (feasibility_state::operator=): New decl.
916 (feasibility_state::maybe_update_for_edge): Add ctxt param.
917 * infinite-loop.cc: New file.
918 * program-state.cc (program_state::on_edge): Log the rejected
919 constraint when region_model::maybe_update_for_edge fails.
920 * region-model.cc (region_model::on_assignment): Treat any writes
921 other than to the stack as "doing work".
922 (region_model::on_stmt_pre): Treat all asm stmts as "doing work".
923 (region_model::on_call_post): Likewise for all calls to functions
924 with unknown side effects.
925 (region_model::handle_phi): Add svals_changing_meaning param.
926 Mark widening svalue in phi nodes as changing meaning.
927 (unusable_in_infinite_loop_constraint_p): New.
928 (region_model::add_constraint): If we're checking for an infinite
929 loop, bail out on unusable svalues, or if we don't have a definite
930 true/false for the constraint.
931 (region_model::update_for_phis): Gather all svalues changing
932 meaning in phi nodes, and purge constraints involving them.
933 (region_model::replay_call_summary): Treat all call summaries as
935 (region_model::can_merge_with_p): Purge constraints involving
936 svalues that change meaning.
937 (model_merger::on_widening_reuse): New.
938 (test_iteration_1): Likewise.
939 (selftest::test_iteration_1): Remove assertion that model6 "knows"
941 * region-model.h (region_model::handle_phi): Add
942 svals_changing_meaning param
943 (region_model_context::maybe_did_work): New pure virtual func.
944 (region_model_context::checking_for_infinite_loop_p): Likewise.
945 (region_model_context::on_unusable_in_infinite_loop): Likewise.
946 (noop_region_model_context::maybe_did_work): Implement.
947 (noop_region_model_context::checking_for_infinite_loop_p):
949 (noop_region_model_context::on_unusable_in_infinite_loop):
951 (region_model_context_decorator::maybe_did_work): Implement.
952 (region_model_context_decorator::checking_for_infinite_loop_p):
954 (region_model_context_decorator::on_unusable_in_infinite_loop):
956 (model_merger::on_widening_reuse): New decl.
957 (model_merger::m_svals_changing_meaning): New field.
958 * sm-signal.cc (register_signal_handler::impl_transition): Assume
959 the edge "does work".
960 * supergraph.cc (supernode::get_start_location): Use CFG edge's
961 goto_locus if available.
962 (supernode::get_end_location): Likewise.
963 (cfg_superedge::dump_label_to_pp): Dump edges with a "goto_locus"
964 * supergraph.h (cfg_superedge::get_goto_locus): New.
965 * svalue.cc (svalue::can_merge_p): Call on_widening_reuse for
967 (involvement_visitor::visit_widening_svalue): New.
968 (svalue::involves_p): Update assertion to allow widening svalues.
970 2023-11-14 David Malcolm <dmalcolm@redhat.com>
973 * sm-taint.cc: Remove "experimental" from comment.
974 * sm.cc (make_checkers): Always add taint state machine.
976 2023-11-04 David Malcolm <dmalcolm@redhat.com>
978 * bounds-checking.cc: Update for changes to diagnostic_context.
980 2023-11-02 David Malcolm <dmalcolm@redhat.com>
983 * access-diagram.cc (class x_aligned_x_ruler_widget): Eliminate
984 unused field "m_col_widths".
985 (access_diagram_impl::add_valid_vs_invalid_ruler): Update for
988 (check_one_function_attr_null_terminated_string_arg): Remove
989 unused variables "cd_unchecked", "strlen_sval", and
991 * region-model.h (region_model_context_decorator::warn): Add
994 2023-10-31 David Malcolm <dmalcolm@redhat.com>
996 * record-layout.cc: New file, based on material in region-model.cc.
997 * record-layout.h: Likewise.
998 * region-model.cc: Include "analyzer/record-layout.h".
999 (class record_layout): Move to record-layout.cc and .h
1001 2023-10-26 David Malcolm <dmalcolm@redhat.com>
1004 (region_model::check_external_function_for_access_attr): Split
1005 out, replacing with...
1006 (region_model::check_function_attr_access): ...this new function
1008 (region_model::check_function_attrs): ...this new function.
1009 (region_model::check_one_function_attr_null_terminated_string_arg):
1011 (region_model::check_function_attr_null_terminated_string_arg):
1013 (region_model::handle_unrecognized_call): Update for renaming of
1014 check_external_function_for_access_attr to check_function_attrs.
1015 (region_model::check_for_null_terminated_string_arg): Add return
1016 value to one overload. Make both overloads const.
1017 * region-model.h: Include "stringpool.h" and "attribs.h".
1018 (region_model::check_for_null_terminated_string_arg): Add return
1019 value to one overload. Make both overloads const.
1020 (region_model::check_external_function_for_access_attr): Delete
1022 (region_model::check_function_attr_access): New decl.
1023 (region_model::check_function_attr_null_terminated_string_arg):
1025 (region_model::check_one_function_attr_null_terminated_string_arg):
1027 (region_model::check_function_attrs): New decl.
1029 2023-10-09 David Malcolm <dmalcolm@redhat.com>
1031 * access-diagram.cc (boundaries::add): Explicitly state
1032 "boundaries::" scope for "kind" enum.
1034 2023-10-08 David Malcolm <dmalcolm@redhat.com>
1037 * access-diagram.cc (boundaries::boundaries): Add logger param
1038 (boundaries::add): Add logging.
1039 (boundaries::get_hard_boundaries_in_range): New.
1040 (boundaries::m_logger): New field.
1041 (boundaries::get_table_x_for_offset): Make public.
1042 (class svalue_spatial_item): New.
1043 (class compound_svalue_spatial_item): New.
1044 (add_ellipsis_to_gaps): New.
1045 (valid_region_spatial_item::valid_region_spatial_item): Add theme
1046 param. Initialize m_boundaries, m_existing_sval, and
1047 m_existing_sval_spatial_item.
1048 (valid_region_spatial_item::add_boundaries): Set m_boundaries.
1049 Add boundaries for any m_existing_sval_spatial_item.
1050 (valid_region_spatial_item::add_array_elements_to_table): Rewrite
1051 creation of min/max index in terms of
1052 maybe_add_array_index_to_table. Rewrite ellipsis code using
1053 add_ellipsis_to_gaps. Add index values for any hard boundaries
1054 within the valid region.
1055 (valid_region_spatial_item::maybe_add_array_index_to_table): New,
1056 based on code formerly in add_array_elements_to_table.
1057 (valid_region_spatial_item::make_table): Make use of
1058 m_existing_sval_spatial_item, if any.
1059 (valid_region_spatial_item::m_boundaries): New field.
1060 (valid_region_spatial_item::m_existing_sval): New field.
1061 (valid_region_spatial_item::m_existing_sval_spatial_item): New
1063 (class svalue_spatial_item): Rename to...
1064 (class written_svalue_spatial_item): ...this.
1065 (class string_region_spatial_item): Rename to..
1066 (class string_literal_spatial_item): ...this. Add "kind".
1067 (string_literal_spatial_item::add_boundaries): Use m_kind to
1068 determine kind of boundary. Update for renaming of m_actual_bits
1070 (string_literal_spatial_item::make_table): Likewise. Support not
1071 displaying a row for byte indexes, and not displaying a row for
1073 (string_literal_spatial_item::add_column_for_byte): Make byte index
1075 (svalue_spatial_item::make): Convert to...
1076 (make_written_svalue_spatial_item): ...this.
1077 (make_existing_svalue_spatial_item): New.
1078 (access_diagram_impl::access_diagram_impl): Pass theme to
1079 m_valid_region_spatial_item ctor. Update for renaming of
1080 m_svalue_spatial_item.
1081 (access_diagram_impl::find_boundaries): Pass logger to boundaries.
1082 Update for renaming of...
1083 (access_diagram_impl::m_svalue_spatial_item): Rename to...
1084 (access_diagram_impl::m_written_svalue_spatial_item): ...this.
1086 2023-10-03 David Malcolm <dmalcolm@redhat.com>
1088 * analyzer-logging.cc (logger::log_va_partial): Use text_info
1090 * analyzer.cc (make_label_text): Likewise.
1091 (make_label_text_n): Likewise.
1092 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
1095 2023-10-02 David Malcolm <dmalcolm@redhat.com>
1097 * program-point.cc: Update for grouping of source printing fields
1098 within diagnostic_context.
1100 2023-09-15 David Malcolm <dmalcolm@redhat.com>
1102 * analyzer.cc (get_stmt_location): Handle null stmt.
1103 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Copy
1105 (saved_diagnostic::operator==): Compare m_loc.
1106 (saved_diagnostic::calc_best_epath): Only use m_stmt_finder if
1108 (dedupe_key::dedupe_key): Initialize m_loc.
1109 (dedupe_key::operator==): Compare m_loc.
1110 (dedupe_key::get_location): Use m_loc if it's known.
1111 (dedupe_key::m_loc): New field.
1112 (diagnostic_manager::emit_saved_diagnostic): Only call
1113 get_emission_location if m_loc is unknown, preferring to use m_loc
1115 * diagnostic-manager.h (saved_diagnostic::m_loc): New field.
1116 (pending_location::pending_location): Initialize m_loc. Add
1117 overload taking a location_t rather than a stmt/stmt_finder.
1118 (pending_location::m_loc): New field.
1120 2023-09-15 David Malcolm <dmalcolm@redhat.com>
1122 * analyzer.h (struct pending_location): New forward decl.
1123 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
1124 Replace params "enode", "snode", "stmt", and "stmt_finder" with
1126 (diagnostic_manager::add_diagnostic): Likewise for both overloads.
1127 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
1129 (struct pending_location): New.
1130 (diagnostic_manager::add_diagnostic): Replace params "enode",
1131 "snode", "stmt", and "stmt_finder" with "ploc".
1132 * engine.cc (impl_region_model_context::warn): Update call to
1133 add_diagnostic for above change.
1134 (impl_sm_context::warn): Likewise.
1135 (impl_region_model_context::on_state_leak): Likewise.
1136 * infinite-recursion.cc
1137 (exploded_graph::detect_infinite_recursion): Likewise.
1139 2023-09-15 David Malcolm <dmalcolm@redhat.com>
1141 * region-model.cc (region_model::get_gassign_result): Handle
1142 volatile ops by using a conjured_svalue.
1144 2023-09-14 David Malcolm <dmalcolm@redhat.com>
1146 * checker-event.h (checker_event::get_thread_id): New.
1147 * checker-path.h (class checker_path): Implement thread-related
1148 vfuncs via a single simple_diagnostic_thread instance named
1151 2023-09-14 David Malcolm <dmalcolm@redhat.com>
1153 * diagnostic-manager.cc (compatible_epath_p): Fix missing return.
1155 2023-09-14 David Malcolm <dmalcolm@redhat.com>
1157 * diagnostic-manager.cc (process_worklist_item): Use
1158 std::unique_ptr rather than plain rejected_constraint *.
1159 * engine.cc (exploded_path::feasible_p): Likewise.
1160 (feasibility_state::maybe_update_for_edge): Likewise.
1161 * exploded-graph.h (feasibility_problem::feasibility_problem):
1163 (feasibility_problem::~feasibility_problem): Delete.
1164 (feasibility_problem::m_rc): Use std::unique_ptr.
1165 (feasibility_state::maybe_update_for_edge): Likewise.
1166 * feasible-graph.cc (feasible_graph::add_feasibility_problem):
1168 * feasible-graph.h (class infeasible_node): Likewise.
1169 (feasible_graph::add_feasibility_problem): Likewise.
1170 * region-model.cc (region_model::add_constraint): Likewise.
1171 (region_model::maybe_update_for_edge): Likewise.
1172 (region_model::apply_constraints_for_gcond): Likewise.
1173 (region_model::apply_constraints_for_gswitch): Likewise.
1174 (region_model::apply_constraints_for_exception): Likewise.
1175 * region-model.h (class region_model): Likewise for decls.
1177 2023-09-09 benjamin priour <vultkayn@gcc.gnu.org>
1181 (region_model::add_constraints_from_binop): binop_svalues around
1182 LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR are now unwrapped.
1184 2023-09-07 David Malcolm <dmalcolm@redhat.com>
1187 * program-point.cc (program_point::on_edge): Don't reject
1188 EDGE_ABNORMAL for computed gotos.
1189 * region-model.cc (region_model::maybe_update_for_edge): Handle
1190 computed goto statements.
1191 (region_model::apply_constraints_for_ggoto): New.
1192 * region-model.h (region_model::apply_constraints_for_ggoto): New decl.
1193 * supergraph.cc (supernode::get_label): New.
1194 * supergraph.h (supernode::get_label): New decl.
1196 2023-09-07 benjamin priour <vultkayn@gcc.gnu.org>
1197 David Malcolm <dmalcolm@redhat.com>
1200 * diagnostic-manager.cc
1201 (compatible_epaths_p): New function.
1202 (saved_diagnostic::supercedes_p): Now calls the above
1203 to determine if the diagnostics do overlap and the superseding
1206 2023-09-07 David Malcolm <dmalcolm@redhat.com>
1208 * region-model.h: fix -Wunused-parameter warnings
1210 2023-09-06 David Malcolm <dmalcolm@redhat.com>
1213 * kf.cc (class kf_strstr): New.
1214 (kf_strstr::impl_call_post): New.
1215 (register_known_functions): Register it.
1217 2023-09-06 David Malcolm <dmalcolm@redhat.com>
1220 * kf.cc (class kf_strncpy): New.
1221 (kf_strncpy::impl_call_post): New.
1222 (register_known_functions): Register it.
1223 * region-model.cc (region_model::read_bytes): Handle unknown
1226 2023-09-06 David Malcolm <dmalcolm@redhat.com>
1228 * kf.cc (kf_calloc::impl_call_pre): Pass ctxt to zero_fill_region.
1229 (kf_memset::impl_call_pre): Move responsibility for calling
1230 check_region_for_write to fill_region.
1231 * region-model.cc (region_model::on_assignment): Pass ctxt to
1233 (region_model::fill_region): Add "ctxt" param, using it to call
1234 check_region_for_write.
1235 (region_model::zero_fill_region): Likewise.
1236 * region-model.h (region_model::fill_region): Add "ctxt" param.
1237 (region_model::zero_fill_region): Likewise.
1239 2023-09-01 benjamin priour <priour.be@gmail.com>
1243 * analyzer.h (is_placement_new_p): New declaration.
1245 (call_details::deref_ptr_arg): New function.
1246 Dereference the argument at given index if possible.
1247 * call-details.h: Declaration of the above function.
1248 * kf-lang-cp.cc (is_placement_new_p): Returns true if the gcall
1249 is recognized as a placement new.
1250 (kf_operator_delete::impl_call_post): Unbinding a region and its
1251 descendents now poisons with POISON_KIND_DELETED.
1252 (register_known_functions_lang_cp): Known function "operator
1253 delete" is now registered only once independently of its number of
1255 * region-model.cc (region_model::eval_condition): Now
1256 recursively calls itself if any of the operand is wrapped in a
1258 * sm-malloc.cc (malloc_state_machine::on_stmt):
1259 Add placement new recognition.
1260 * svalue.cc (poison_kind_to_str): Wording for the new PK.
1261 * svalue.h (enum poison_kind): Add value POISON_KIND_DELETED.
1263 2023-08-31 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
1265 * kf.cc: Change spelling to macOS.
1267 2023-08-30 Eric Feng <ef2648@columbia.edu>
1270 * engine.cc (impl_region_model_context::warn): New optional
1272 * exploded-graph.h (class impl_region_model_context): Likewise.
1273 * region-model.cc (region_model::pop_frame): New callback
1274 feature for region_model::pop_frame.
1275 * region-model.h (struct append_regions_cb_data): Likewise.
1276 (class region_model): Likewise.
1277 (class region_model_context): New optional parameter.
1278 (class region_model_context_decorator): Likewise.
1280 2023-08-30 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
1282 * region-model.cc: Define INCLUDE_ALGORITHM.
1284 2023-08-29 David Malcolm <dmalcolm@redhat.com>
1287 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
1288 selftest::analyzer_ranges_cc_tests.
1289 * analyzer-selftests.h (selftest::run_analyzer_selftests): New
1291 * analyzer.opt (Wanalyzer-overlapping-buffers): New option.
1292 * call-details.cc: Include "analyzer/ranges.h" and "make-unique.h".
1293 (class overlapping_buffers): New.
1294 (call_details::complain_about_overlap): New.
1295 * call-details.h (call_details::complain_about_overlap): New decl.
1296 * kf.cc (kf_memcpy_memmove::impl_call_pre): Call
1297 cd.complain_about_overlap for memcpy and memcpy_chk.
1298 (kf_strcat::impl_call_pre): Call cd.complain_about_overlap.
1299 (kf_strcpy::impl_call_pre): Likewise.
1300 * ranges.cc: New file.
1301 * ranges.h: New file.
1303 2023-08-29 David Malcolm <dmalcolm@redhat.com>
1306 * kf.cc (kf_strdup::impl_call_pre): Set size of
1307 dynamically-allocated buffer. Simulate copying the string from
1308 the source region to the new buffer.
1310 2023-08-27 benjamin priour <vultkayn@gcc.gnu.org>
1313 * analyzer.h (class known_function): Add virtual casts
1314 to builtin_known_function.
1315 (class builtin_known_function): New subclass of known_function
1317 * kf.cc (class kf_alloca): Now derived from
1318 builtin_known_function.
1319 (class kf_calloc): Likewise.
1320 (class kf_free): Likewise.
1321 (class kf_malloc): Likewise.
1322 (class kf_memcpy_memmove): Likewise.
1323 (class kf_memset): Likewise.
1324 (class kf_realloc): Likewise.
1325 (class kf_strchr): Likewise.
1326 (class kf_sprintf): Likewise.
1327 (class kf_strcat): Likewise.
1328 (class kf_strcpy): Likewise.
1329 (class kf_strdup): Likewise.
1330 (class kf_strlen): Likewise.
1331 (class kf_strndup): Likewise.
1332 (register_known_functions): Builtins are now registered as
1333 known_functions by name rather than by their BUILTIN_CODE.
1334 * known-function-manager.cc (get_normal_builtin): New overload.
1335 * known-function-manager.h: New overload declaration.
1336 * region-model.cc (region_model::get_builtin_kf): New function.
1337 * region-model.h (class region_model): Add declaration of
1339 * sm-fd.cc: For called recognized as builtins, use the
1340 attributes of that builtin as defined in gcc/builtins.def
1341 rather than the user's.
1342 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
1344 2023-08-25 David Malcolm <dmalcolm@redhat.com>
1346 * access-diagram.cc (class string_region_spatial_item): Remove
1347 assumption that the string is written to the start of the cluster.
1349 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1353 (call_details::check_for_null_terminated_string_arg): Split into
1354 overloads, one taking just an arg_idx, the other a new
1355 "include_terminator" param.
1356 * call-details.h: Likewise.
1357 * kf.cc (class kf_strcat): New.
1358 (kf_strcpy::impl_call_pre): Update for change to
1359 check_for_null_terminated_string_arg.
1360 (register_known_functions): Register kf_strcat.
1362 (region_model::check_for_null_terminated_string_arg): Split into
1363 overloads, one taking just an arg_idx, the other a new
1364 "include_terminator" param. When returning an svalue, handle
1365 "include_terminator" being false by subtracting one.
1367 (region_model::check_for_null_terminated_string_arg): Split into
1368 overloads, one taking just an arg_idx, the other a new
1369 "include_terminator" param.
1371 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1374 * region-model.cc (fragment::has_null_terminator): Handle
1377 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1380 * region-model-manager.cc
1381 (region_model_manager::get_or_create_initial_value): Simplify
1382 INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) to
1383 CONSTANT_SVAL(STRING[N]).
1385 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1388 * region-model.cc (fragment::has_null_terminator): Move STRING_CST
1389 handling to fragment::string_cst_has_null_terminator; also use it to
1390 handle INIT_VAL(STRING_REG).
1391 (fragment::string_cst_has_null_terminator): New, from above.
1393 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1395 * kf.cc (kf_memcpy_memmove::impl_call_pre): Reimplement using
1396 region_model::copy_bytes.
1397 * region-model.cc (region_model::read_bytes): New.
1398 (region_model::copy_bytes): New.
1399 * region-model.h (region_model::read_bytes): New decl.
1400 (region_model::copy_bytes): New decl.
1402 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1405 * region-model.cc (region_model::get_string_size): Delete both.
1406 * region-model.h (region_model::get_string_size): Delete both
1409 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1412 * kf.cc (kf_strcpy::impl_call_pre): Reimplement using
1413 check_for_null_terminated_string_arg.
1414 * region-model.cc (region_model::get_store_bytes): Shortcut
1415 reading all of a string_region.
1416 (region_model::scan_for_null_terminator): Use get_store_value for
1417 the bytes rather than "unknown" when returning an unknown length.
1418 (region_model::write_bytes): New.
1419 * region-model.h (region_model::write_bytes): New decl.
1421 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1424 * region-model.cc (iterable_cluster::iterable_cluster): Add
1425 symbolic binding keys to m_symbolic_bindings.
1426 (iterable_cluster::has_symbolic_bindings_p): New.
1427 (iterable_cluster::m_symbolic_bindings): New field.
1428 (region_model::scan_for_null_terminator): Treat clusters with
1429 symbolic bindings as having unknown strlen.
1431 2023-08-24 David Malcolm <dmalcolm@redhat.com>
1433 * engine.cc (impl_path_context::impl_path_context): Add logger
1435 (impl_path_context::bifurcate): Add log message.
1436 (impl_path_context::terminate_path): Likewise.
1437 (impl_path_context::m_logger): New field.
1438 (exploded_graph::process_node): Pass logger to path_ctxt ctor.
1440 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1443 * kf-analyzer.cc (class kf_analyzer_get_strlen): Move to kf.cc.
1444 (register_known_analyzer_functions): Use make_kf_strlen.
1445 * kf.cc (class kf_strlen::impl_call_pre): Replace with
1446 implementation of kf_analyzer_get_strlen from kf-analyzer.cc.
1447 Handle "UNKNOWN" return from check_for_null_terminated_string_arg
1448 by falling back to a conjured svalue.
1449 (make_kf_strlen): New.
1450 (register_known_functions): Use make_kf_strlen.
1451 * known-function-manager.h (make_kf_strlen): New decl.
1453 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1456 * call-details.cc (call_details::call_details): New ctor.
1457 * call-details.h (call_details::call_details): New ctor decl.
1458 (struct call_arg_details): Move here from region-model.cc.
1459 * region-model.cc (region_model::check_call_format_attr): New.
1460 (region_model::check_call_args): Call it.
1461 (struct call_arg_details): Move it to call-details.h.
1462 * region-model.h (region_model::check_call_format_attr): New decl.
1464 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1466 * kf.cc (class kf_fopen): New.
1467 (register_known_functions): Register it.
1469 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1472 * analyzer.opt (Wanalyzer-unterminated-string): Delete.
1474 (call_details::check_for_null_terminated_string_arg): Convert
1475 return type from void to const svalue *. Add param "out_sval".
1477 (call_details::check_for_null_terminated_string_arg): Likewise.
1478 * kf-analyzer.cc (kf_analyzer_get_strlen::impl_call_pre): Wire up
1479 to result of check_for_null_terminated_string_arg.
1480 * region-model.cc (get_strlen): Delete.
1481 (class unterminated_string_arg): Delete.
1482 (struct fragment): New.
1483 (class iterable_cluster): New.
1484 (region_model::get_store_bytes): New.
1485 (get_tree_for_byte_offset): New.
1486 (region_model::scan_for_null_terminator): New.
1487 (region_model::check_for_null_terminated_string_arg): Convert
1488 return type from void to const svalue *. Add param "out_sval".
1489 Reimplement in terms of scan_for_null_terminator, dropping the
1490 special-case for -Wanalyzer-unterminated-string.
1491 * region-model.h (region_model::get_store_bytes): New decl.
1492 (region_model::scan_for_null_terminator): New decl.
1493 (region_model::check_for_null_terminated_string_arg): Convert
1494 return type from void to const svalue *. Add param "out_sval".
1495 * store.cc (concrete_binding::get_byte_range): New.
1496 * store.h (concrete_binding::get_byte_range): New decl.
1497 (store_manager::get_concrete_binding): New overload.
1499 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1501 * region-model.cc (region_model_context_decorator::add_event):
1502 Handle m_inner being NULL.
1503 * region-model.h (class region_model_context_decorator): Likewise.
1504 (annotating_context::warn): Likewise.
1506 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1508 * diagnostic-manager.cc (saved_diagnostic::add_event): New.
1509 (saved_diagnostic::add_any_saved_events): New.
1510 (diagnostic_manager::add_event): New.
1511 (dedupe_winners::emit_best): New.
1512 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
1513 non-const. Call saved_diagnostic::add_any_saved_events.
1514 * diagnostic-manager.h (saved_diagnostic::add_event): New decl.
1515 (saved_diagnostic::add_any_saved_events): New decl.
1516 (saved_diagnostic::m_saved_events): New field.
1517 (diagnostic_manager::add_event): New decl.
1518 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
1520 * engine.cc (impl_region_model_context::add_event): New.
1521 * exploded-graph.h (impl_region_model_context::add_event): New decl.
1523 (noop_region_model_context::add_event): New.
1524 (region_model_context_decorator::add_event): New.
1525 * region-model.h (region_model_context::add_event): New vfunc.
1526 (noop_region_model_context::add_event): New decl.
1527 (region_model_context_decorator::add_event): New decl.
1529 2023-08-22 David Malcolm <dmalcolm@redhat.com>
1532 (class check_external_function_for_access_attr::annotating_ctxt):
1533 Convert to an annotating_context.
1534 * region-model.h (class note_adding_context): Rename to...
1535 (class annotating_context): ...this, updating the "warn" method.
1536 (note_adding_context::make_note): Replace with...
1537 (annotating_context::add_annotations): ...this.
1539 2023-08-14 benjamin priour <vultkayn@gcc.gnu.org>
1542 * analyzer.opt: Add new option.
1543 * diagnostic-manager.cc
1544 (diagnostic_manager::prune_path): Call prune_system_headers.
1545 (prune_frame): New function that deletes all events in a frame.
1546 (diagnostic_manager::prune_system_headers): New function.
1547 * diagnostic-manager.h: Add prune_system_headers declaration.
1549 2023-08-11 David Malcolm <dmalcolm@redhat.com>
1552 * analyzer.opt (Wanalyzer-unterminated-string): New.
1554 (call_details::check_for_null_terminated_string_arg): New.
1556 (call_details::check_for_null_terminated_string_arg): New decl.
1557 * kf-analyzer.cc (class kf_analyzer_get_strlen): New.
1558 (register_known_analyzer_functions): Register it.
1559 * kf.cc (kf_error::impl_call_pre): Check that format arg is a
1560 valid null-terminated string.
1561 (kf_putenv::impl_call_pre): Likewise for the sole param.
1562 (kf_strchr::impl_call_pre): Likewise for the first param.
1563 (kf_strcpy::impl_call_pre): Likewise for the second param.
1564 (kf_strdup::impl_call_pre): Likewise for the sole param.
1565 * region-model.cc (get_strlen): New.
1566 (struct call_arg_details): New.
1567 (inform_about_expected_null_terminated_string_arg): New.
1568 (class unterminated_string_arg): New.
1569 (region_model::check_for_null_terminated_string_arg): New.
1571 (region_model::check_for_null_terminated_string_arg): New decl.
1573 2023-08-11 Eric Feng <ef2648@columbia.edu>
1576 * call-details.h: New function.
1577 * region-model.cc (region_model::get_or_create_region_for_heap_alloc):
1578 New optional parameters.
1579 * region-model.h (class region_model): New optional parameters.
1580 * sm-malloc.cc (on_realloc_with_move): New function.
1581 (region_model::transition_ptr_sval_non_null): New function.
1583 2023-08-09 David Malcolm <dmalcolm@redhat.com>
1585 * analyzer.h (class pure_known_function_with_default_return): New
1587 * call-details.cc (const_fn_p): Move here from region-model.cc.
1588 (maybe_get_const_fn_result): Likewise.
1589 (get_result_size_in_bytes): Likewise.
1590 (call_details::set_any_lhs_with_defaults): New function, based on
1591 code in region_model::on_call_pre.
1592 * call-details.h (call_details::set_any_lhs_with_defaults): New
1594 * diagnostic-manager.cc
1595 (diagnostic_manager::emit_saved_diagnostic): Log the index of the
1597 * kf.cc (pure_known_function_with_default_return::impl_call_pre):
1599 (kf_memset::impl_call_pre): Set the LHS to the first param.
1600 (kf_putenv::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1601 (kf_sprintf::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1602 (class kf_stack_restore): Derive from
1603 pure_known_function_with_default_return.
1604 (class kf_stack_save): Likewise.
1605 (kf_strlen::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1606 * region-model-reachability.cc (reachable_regions::handle_sval):
1607 Remove logic for symbolic regions for pointers.
1608 * region-model.cc (region_model::canonicalize): Remove purging of
1609 dynamic extents workaround for surplus values from
1610 region_model::on_call_pre's default LHS code.
1611 (const_fn_p): Move to call-details.cc.
1612 (maybe_get_const_fn_result): Likewise.
1613 (get_result_size_in_bytes): Likewise.
1614 (region_model::update_for_nonzero_return): Call
1615 cd.set_any_lhs_with_defaults.
1616 (region_model::on_call_pre): Remove the assignment to the LHS of a
1617 default return value, instead requiring all known_function
1618 implementations to write to any LHS of the call. Use
1619 cd.set_any_lhs_with_defaults on the non-kf paths.
1620 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Use
1621 cd.set_any_lhs_with_defaults when failing to get at fd state.
1622 (kf_bind::outcome_of_bind::update_model): Likewise.
1623 (kf_listen::outcome_of_listen::update_model): Likewise.
1624 (kf_accept::outcome_of_accept::update_model): Likewise.
1625 (kf_connect::outcome_of_connect::update_model): Likewise.
1626 (kf_read::impl_call_pre): Use cd.set_any_lhs_with_defaults.
1627 * sm-file.cc (class kf_stdio_output_fn): Derive from
1628 pure_known_function_with_default_return.
1629 (class kf_ferror): Likewise.
1630 (class kf_fileno): Likewise.
1631 (kf_fgets::impl_call_pre): Use cd.set_any_lhs_with_defaults.
1632 (kf_read::impl_call_pre): Likewise.
1633 (class kf_getc): Derive from
1634 pure_known_function_with_default_return.
1635 (class kf_getchar): Likewise.
1636 * varargs.cc (kf_va_arg::impl_call_pre): Use
1637 cd.set_any_lhs_with_defaults.
1639 2023-08-04 David Malcolm <dmalcolm@redhat.com>
1642 * bounds-checking.cc (region_model::check_region_bounds): Handle
1643 symbolic base regions.
1644 * call-details.cc: Include "stringpool.h" and "attribs.h".
1645 (call_details::lookup_function_attribute): New function.
1646 * call-details.h (call_details::lookup_function_attribute): New
1648 * region-model-manager.cc
1649 (region_model_manager::maybe_fold_binop): Add reference to
1651 * region-model-reachability.cc (reachable_regions::handle_sval):
1652 Add symbolic regions for pointers that are conjured svalues for
1654 * region-model.cc (region_model::canonicalize): Purge dynamic
1655 extents for regions that aren't referenced.
1656 (get_result_size_in_bytes): New function.
1657 (region_model::on_call_pre): Use get_result_size_in_bytes and
1658 potentially set the dynamic extents of the region pointed to by
1660 (region_model::deref_rvalue): Add param "add_nonnull_constraint"
1661 and use it to conditionalize adding the constraint.
1662 (pending_diagnostic_subclass::dubious_allocation_size): Add "stmt"
1663 param to both ctors and use it to initialize new "m_stmt" field.
1664 (pending_diagnostic_subclass::operator==): Use m_stmt; don't use
1666 (pending_diagnostic_subclass::m_stmt): New field.
1667 (region_model::check_region_size): Generalize to any kind of
1668 pointer svalue by using deref_rvalue rather than checking for
1669 region_svalue. Pass stmt to dubious_allocation_size ctor.
1670 * region-model.h (region_model::deref_rvalue): Add param
1671 "add_nonnull_constraint".
1672 * svalue.cc (conjured_svalue::lhs_value_p): New function.
1673 * svalue.h (conjured_svalue::lhs_value_p): New decl.
1675 2023-08-04 David Malcolm <dmalcolm@redhat.com>
1677 * svalue.cc (region_svalue::dump_to_pp): Support NULL type.
1678 (constant_svalue::dump_to_pp): Likewise.
1679 (initial_svalue::dump_to_pp): Likewise.
1680 (conjured_svalue::dump_to_pp): Likewise. Fix missing print of the
1683 2023-08-03 David Malcolm <dmalcolm@redhat.com>
1686 * region.cc (int_size_in_bits): Fail on zero-sized types.
1688 2023-08-02 Eric Feng <ef2648@columbia.edu>
1691 * analyzer-language.cc (run_callbacks): New function.
1692 (on_finish_translation_unit): New function.
1693 * analyzer-language.h (GCC_ANALYZER_LANGUAGE_H): New include.
1694 (class translation_unit): New vfuncs.
1696 2023-07-26 David Malcolm <dmalcolm@redhat.com>
1699 * region-model-manager.cc
1700 (region_model_manager::region_model_manager): Update for
1701 generalizing region ids to also cover svalues.
1702 (region_model_manager::get_or_create_constant_svalue): Likewise.
1703 (region_model_manager::get_or_create_unknown_svalue): Likewise.
1704 (region_model_manager::create_unique_svalue): Likewise.
1705 (region_model_manager::get_or_create_initial_value): Likewise.
1706 (region_model_manager::get_or_create_setjmp_svalue): Likewise.
1707 (region_model_manager::get_or_create_poisoned_svalue): Likewise.
1708 (region_model_manager::get_ptr_svalue): Likewise.
1709 (region_model_manager::get_or_create_unaryop): Likewise.
1710 (region_model_manager::get_or_create_binop): Likewise.
1711 (region_model_manager::get_or_create_sub_svalue): Likewise.
1712 (region_model_manager::get_or_create_repeated_svalue): Likewise.
1713 (region_model_manager::get_or_create_bits_within): Likewise.
1714 (region_model_manager::get_or_create_unmergeable): Likewise.
1715 (region_model_manager::get_or_create_widening_svalue): Likewise.
1716 (region_model_manager::get_or_create_compound_svalue): Likewise.
1717 (region_model_manager::get_or_create_conjured_svalue): Likewise.
1718 (region_model_manager::get_or_create_asm_output_svalue): Likewise.
1719 (region_model_manager::get_or_create_const_fn_result_svalue):
1721 (region_model_manager::get_region_for_fndecl): Likewise.
1722 (region_model_manager::get_region_for_label): Likewise.
1723 (region_model_manager::get_region_for_global): Likewise.
1724 (region_model_manager::get_field_region): Likewise.
1725 (region_model_manager::get_element_region): Likewise.
1726 (region_model_manager::get_offset_region): Likewise.
1727 (region_model_manager::get_sized_region): Likewise.
1728 (region_model_manager::get_cast_region): Likewise.
1729 (region_model_manager::get_frame_region): Likewise.
1730 (region_model_manager::get_symbolic_region): Likewise.
1731 (region_model_manager::get_region_for_string): Likewise.
1732 (region_model_manager::get_bit_range): Likewise.
1733 (region_model_manager::get_var_arg_region): Likewise.
1734 (region_model_manager::get_region_for_unexpected_tree_code):
1736 (region_model_manager::get_or_create_region_for_heap_alloc):
1738 (region_model_manager::create_region_for_alloca): Likewise.
1739 (region_model_manager::log_stats): Likewise.
1740 * region-model-manager.h (region_model_manager::get_num_regions):
1742 (region_model_manager::get_num_symbols): ...this.
1743 (region_model_manager::alloc_region_id): Replace with...
1744 (region_model_manager::alloc_symbol_id): ...this.
1745 (region_model_manager::m_next_region_id): Replace with...
1746 (region_model_manager::m_next_symbol_id): ...this.
1747 * region-model.cc (selftest::test_get_representative_tree): Update
1748 for generalizing region ids to also cover svalues.
1749 (selftest::test_binop_svalue_folding): Likewise.
1750 (selftest::test_state_merging): Likewise.
1751 * region.cc (region::cmp_ids): Delete, in favor of
1753 (region::region): Update for introduction of symbol base class.
1754 (frame_region::get_region_for_local): Likewise.
1755 (root_region::root_region): Likewise.
1756 (symbolic_region::symbolic_region): Likewise.
1757 * region.h: Replace include of "analyzer/complexity.h" with
1758 "analyzer/symbol.h".
1759 (class region): Make a subclass of symbol.
1760 (region::get_id): Delete in favor of symbol::get_id.
1761 (region::cmp_ids): Delete in favor of symbol::cmp_ids.
1762 (region::get_complexity): Delete in favor of
1763 symbol::get_complexity.
1764 (region::region): Use symbol::id_t for "id" param.
1765 (region::m_complexity): Move field to symbol base class.
1766 (region::m_id): Likewise.
1767 (space_region::space_region): Use symbol::id_t for "id" param.
1768 (frame_region::frame_region): Likewise.
1769 (globals_region::globals_region): Likewise.
1770 (code_region::code_region): Likewise.
1771 (function_region::function_region): Likewise.
1772 (label_region::label_region): Likewise.
1773 (stack_region::stack_region): Likewise.
1774 (heap_region::heap_region): Likewise.
1775 (thread_local_region::thread_local_region): Likewise.
1776 (root_region::root_region): Likewise.
1777 (symbolic_region::symbolic_region): Likewise.
1778 (decl_region::decl_region): Likewise.
1779 (field_region::field_region): Likewise.
1780 (element_region::element_region): Likewise.
1781 (offset_region::offset_region): Likewise.
1782 (sized_region::sized_region): Likewise.
1783 (cast_region::cast_region): Likewise.
1784 (heap_allocated_region::heap_allocated_region): Likewise.
1785 (alloca_region::alloca_region): Likewise.
1786 (string_region::string_region): Likewise.
1787 (bit_range_region::bit_range_region): Likewise.
1788 (var_arg_region::var_arg_region): Likewise.
1789 (errno_region::errno_region): Likewise.
1790 (unknown_region::unknown_region): Likewise.
1791 * svalue.cc (sub_svalue::sub_svalue): Add symbol::id_t param.
1792 (repeated_svalue::repeated_svalue): Likewise.
1793 (bits_within_svalue::bits_within_svalue): Likewise.
1794 (compound_svalue::compound_svalue): Likewise.
1795 * svalue.h: Replace include of "analyzer/complexity.h" with
1796 "analyzer/symbol.h".
1797 (class svalue): Make a subclass of symbol.
1798 (svalue::get_complexity): Delete in favor of
1799 symbol::get_complexity.
1800 (svalue::svalue): Add symbol::id_t param. Update for new base
1802 (svalue::m_complexity): Delete in favor of
1803 symbol::m_complexity.
1804 (region_svalue::region_svalue): Add symbol::id_t param
1805 (constant_svalue::constant_svalue): Likewise.
1806 (unknown_svalue::unknown_svalue): Likewise.
1807 (poisoned_svalue::poisoned_svalue): Likewise.
1808 (setjmp_svalue::setjmp_svalue): Likewise.
1809 (initial_svalue::initial_svalue): Likewise.
1810 (unaryop_svalue::unaryop_svalue): Likewise.
1811 (binop_svalue::binop_svalue): Likewise.
1812 (sub_svalue::sub_svalue): Likewise.
1813 (repeated_svalue::repeated_svalue): Likewise.
1814 (bits_within_svalue::bits_within_svalue): Likewise.
1815 (unmergeable_svalue::unmergeable_svalue): Likewise.
1816 (placeholder_svalue::placeholder_svalue): Likewise.
1817 (widening_svalue::widening_svalue): Likewise.
1818 (compound_svalue::compound_svalue): Likewise.
1819 (conjured_svalue::conjured_svalue): Likewise.
1820 (asm_output_svalue::asm_output_svalue): Likewise.
1821 (const_fn_result_svalue::const_fn_result_svalue): Likewise.
1822 * symbol.cc: New file.
1823 * symbol.h: New file.
1825 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1828 * region-model.cc (region_model::get_gassign_result): Only check
1829 for bad shift counts when dealing with an integral type.
1831 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1834 PR middle-end/110612
1835 * access-diagram.cc (class spatial_item): Add virtual dtor.
1837 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1840 * region.h (struct cast_region::key_t): Support "m_type" being
1841 null by using "m_original_region" for empty/deleted slots.
1843 2023-07-19 David Malcolm <dmalcolm@redhat.com>
1846 * region-model-manager.cc
1847 (region_model_manager::get_or_create_int_cst): Assert that we have
1848 an integral or pointer type.
1849 * sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
1850 Don't check non-integral types.
1852 2023-06-29 benjamin priour <priour.be@gmail.com>
1855 * region-model-manager.cc
1856 (region_model_manager::get_or_create_initial_value): Take an
1857 optional boolean value to bypass poisoning checks
1858 * region-model-manager.h: Update declaration of the above function.
1859 * region-model.cc (region_model::get_store_value): No longer returns
1860 on OOB, but rather gives a boolean to get_or_create_initial_value.
1861 (region_model::check_region_access): Update docstring.
1862 (region_model::check_region_for_write): Update docstring.
1864 2023-06-24 David Malcolm <dmalcolm@redhat.com>
1866 * access-diagram.cc: Add #define INCLUDE_VECTOR.
1867 * bounds-checking.cc: Likewise.
1869 2023-06-22 David Malcolm <dmalcolm@redhat.com>
1872 * access-diagram.cc: New file.
1873 * access-diagram.h: New file.
1874 * analyzer.h (class region_offset): Add default ctor.
1875 (region_offset::make_byte_offset): New decl.
1876 (region_offset::concrete_p): New.
1877 (region_offset::get_concrete_byte_offset): New.
1878 (region_offset::calc_symbolic_bit_offset): New decl.
1879 (region_offset::calc_symbolic_byte_offset): New decl.
1880 (region_offset::dump_to_pp): New decl.
1881 (region_offset::dump): New decl.
1882 (operator<, operator<=, operator>, operator>=): New decls for
1885 (-param=analyzer-text-art-string-ellipsis-threshold=): New.
1886 (-param=analyzer-text-art-string-ellipsis-head-len=): New.
1887 (-param=analyzer-text-art-string-ellipsis-tail-len=): New.
1888 (-param=analyzer-text-art-ideal-canvas-width=): New.
1889 (fanalyzer-debug-text-art): New.
1890 * bounds-checking.cc: Include "intl.h", "diagnostic-diagram.h",
1891 and "analyzer/access-diagram.h".
1892 (class out_of_bounds::oob_region_creation_event_capacity): New.
1893 (out_of_bounds::out_of_bounds): Add "model" and "sval_hint"
1895 (out_of_bounds::mark_interesting_stuff): Use the base region.
1896 (out_of_bounds::add_region_creation_events): Use
1897 oob_region_creation_event_capacity.
1898 (out_of_bounds::get_dir): New pure vfunc.
1899 (out_of_bounds::maybe_show_notes): New.
1900 (out_of_bounds::maybe_show_diagram): New.
1901 (out_of_bounds::make_access_diagram): New.
1902 (out_of_bounds::m_model): New field.
1903 (out_of_bounds::m_sval_hint): New field.
1904 (out_of_bounds::m_region_creation_event_id): New field.
1905 (concrete_out_of_bounds::concrete_out_of_bounds): Update for new
1907 (concrete_past_the_end::concrete_past_the_end): Likewise.
1908 (concrete_past_the_end::add_region_creation_events): Use
1909 oob_region_creation_event_capacity.
1910 (concrete_buffer_overflow::concrete_buffer_overflow): Update for
1912 (concrete_buffer_overflow::emit): Replace call to
1913 maybe_describe_array_bounds with maybe_show_notes.
1914 (concrete_buffer_overflow::get_dir): New.
1915 (concrete_buffer_over_read::concrete_buffer_over_read): Update for
1917 (concrete_buffer_over_read::emit): Replace call to
1918 maybe_describe_array_bounds with maybe_show_notes.
1919 (concrete_buffer_overflow::get_dir): New.
1920 (concrete_buffer_underwrite::concrete_buffer_underwrite): Update
1922 (concrete_buffer_underwrite::emit): Replace call to
1923 maybe_describe_array_bounds with maybe_show_notes.
1924 (concrete_buffer_underwrite::get_dir): New.
1925 (concrete_buffer_under_read::concrete_buffer_under_read): Update
1927 (concrete_buffer_under_read::emit): Replace call to
1928 maybe_describe_array_bounds with maybe_show_notes.
1929 (concrete_buffer_under_read::get_dir): New.
1930 (symbolic_past_the_end::symbolic_past_the_end): Update for new
1932 (symbolic_buffer_overflow::symbolic_buffer_overflow): Likewise.
1933 (symbolic_buffer_overflow::emit): Call maybe_show_notes.
1934 (symbolic_buffer_overflow::get_dir): New.
1935 (symbolic_buffer_over_read::symbolic_buffer_over_read): Update for
1937 (symbolic_buffer_over_read::emit): Call maybe_show_notes.
1938 (symbolic_buffer_over_read::get_dir): New.
1939 (region_model::check_symbolic_bounds): Add "sval_hint" param. Pass
1940 it and sized_offset_reg to diagnostics.
1941 (region_model::check_region_bounds): Add "sval_hint" param, passing
1943 * diagnostic-manager.cc
1944 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
1945 pending_diagnostic::emit.
1946 * engine.cc: Add logger param to pending_diagnostic::emit
1948 * infinite-recursion.cc: Likewise.
1949 * kf-analyzer.cc: Likewise.
1950 * kf.cc: Likewise. Add nullptr for new param of
1951 check_region_for_write.
1952 * pending-diagnostic.h: Likewise in decl.
1953 * region-model-manager.cc
1954 (region_model_manager::get_or_create_int_cst): Convert param from
1955 poly_int64 to const poly_wide_int_ref &.
1956 (region_model_manager::maybe_fold_binop): Support type being NULL
1957 when checking for floating-point types.
1958 Check for (X + Y) - X => Y. Be less strict about types when folding
1959 associative ops. Check for (X + Y) * CST => (X * CST) + (Y * CST).
1960 * region-model-manager.h
1961 (region_model_manager::get_or_create_int_cst): Convert param from
1962 poly_int64 to const poly_wide_int_ref &.
1963 * region-model.cc: Add logger param to pending_diagnostic::emit
1965 (region_model::check_external_function_for_access_attr): Update
1966 for new param of check_region_for_write.
1967 (region_model::deref_rvalue): Use nullptr rather than NULL.
1968 (region_model::get_capacity): Handle RK_STRING.
1969 (region_model::check_region_access): Add "sval_hint" param; pass it to
1970 check_region_bounds.
1971 (region_model::check_region_for_write): Add "sval_hint" param;
1972 pass it to check_region_access.
1973 (region_model::check_region_for_read): Add NULL for new param to
1974 check_region_access.
1975 (region_model::set_value): Pass rhs_sval to
1976 check_region_for_write.
1977 (region_model::get_representative_path_var_1): Handle SK_CONSTANT
1978 in the check for infinite recursion.
1979 * region-model.h (region_model::check_region_for_write): Add
1981 (region_model::check_region_access): Likewise.
1982 (region_model::check_symbolic_bounds): Likewise.
1983 (region_model::check_region_bounds): Likewise.
1984 * region.cc (region_offset::make_byte_offset): New.
1985 (region_offset::calc_symbolic_bit_offset): New.
1986 (region_offset::calc_symbolic_byte_offset): New.
1987 (region_offset::dump_to_pp): New.
1988 (region_offset::dump): New.
1989 (struct linear_op): New.
1990 (operator<, operator<=, operator>, operator>=): New, for
1992 (region::get_next_offset): New.
1993 (region::get_relative_symbolic_offset): Use ptrdiff_type_node.
1994 (field_region::get_relative_symbolic_offset): Likewise.
1995 (element_region::get_relative_symbolic_offset): Likewise.
1996 (bit_range_region::get_relative_symbolic_offset): Likewise.
1997 * region.h (region::get_next_offset): New decl.
1998 * sm-fd.cc: Add logger param to pending_diagnostic::emit
2000 * sm-file.cc: Likewise.
2001 * sm-malloc.cc: Likewise.
2002 * sm-pattern-test.cc: Likewise.
2003 * sm-sensitive.cc: Likewise.
2004 * sm-signal.cc: Likewise.
2005 * sm-taint.cc: Likewise.
2006 * store.cc (bit_range::contains_p): Allow "out" to be null.
2007 * store.h (byte_range::get_start_bit_offset): New.
2008 (byte_range::get_next_bit_offset): New.
2009 * varargs.cc: Add logger param to pending_diagnostic::emit
2012 2023-06-10 Tim Lange <mail@tim-lange.me>
2015 * constraint-manager.cc (class sval_finder): Visitor to find
2016 childs in svalue trees.
2017 (constraint_manager::sval_constrained_p): Add new function to
2018 check whether a sval might be part of an constraint.
2019 * constraint-manager.h: Add sval_constrained_p function.
2020 * region-model.cc (class size_visitor): Reverse behavior to not
2021 emit a warning on not explicitly considered cases.
2022 (region_model::check_region_size):
2023 Adapt to size_visitor changes.
2025 2023-06-09 David Malcolm <dmalcolm@redhat.com>
2028 * region-model.cc (region_model::get_initial_value_for_global):
2029 Move code to region::calc_initial_value_at_main.
2030 * region.cc (region::get_initial_value_at_main): New function.
2031 (region::calc_initial_value_at_main): New function, based on code
2032 in region_model::get_initial_value_for_global.
2033 (region::region): Initialize m_cached_init_sval_at_main.
2034 (decl_region::get_svalue_for_constructor): Add a cache, splitting
2036 (decl_region::calc_svalue_for_constructor): ...this new function.
2037 * region.h (region::get_initial_value_at_main): New decl.
2038 (region::calc_initial_value_at_main): New decl.
2039 (region::m_cached_init_sval_at_main): New field.
2040 (decl_region::decl_region): Initialize m_ctor_svalue.
2041 (decl_region::calc_svalue_for_constructor): New decl.
2042 (decl_region::m_ctor_svalue): New field.
2044 2023-06-08 Benjamin Priour <vultkayn@gcc.gnu.org>
2046 * bounds-checking.cc (region_model::check_symbolic_bounds): Returns whether the BASE_REG
2047 region access was OOB.
2048 (region_model::check_region_bounds): Likewise.
2049 * region-model.cc (region_model::get_store_value): Creates an
2050 unknown svalue on OOB-read access to REG.
2051 (region_model::check_region_access): Returns whether an unknown svalue needs be created.
2052 (region_model::check_region_for_read): Passes check_region_access return value.
2053 * region-model.h: Update prior function definitions.
2055 2023-06-02 David Malcolm <dmalcolm@redhat.com>
2058 * kf.cc (class kf_atomic_exchange): New.
2059 (class kf_atomic_exchange_n): New.
2060 (class kf_atomic_fetch_op): New.
2061 (class kf_atomic_op_fetch): New.
2062 (class kf_atomic_load): New.
2063 (class kf_atomic_load_n): New.
2064 (class kf_atomic_store_n): New.
2065 (register_atomic_builtins): New function.
2066 (register_known_functions): Call register_atomic_builtins.
2068 2023-06-02 David Malcolm <dmalcolm@redhat.com>
2070 * store.cc (store::eval_alias_1): Regions in different memory
2073 2023-05-18 Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
2075 * region-model-manager.cc (get_code_for_cast): Use _P defines from
2077 (region_model_manager::get_or_create_cast): Ditto.
2078 (region_model_manager::get_region_for_global): Ditto.
2079 * region-model.cc (region_model::get_lvalue_1): Ditto.
2080 * region.cc (decl_region::maybe_get_constant_value): Ditto.
2082 2023-03-22 David Malcolm <dmalcolm@redhat.com>
2085 * program-point.cc: Include "analyzer/inlining-iterator.h".
2086 (program_point::effectively_intraprocedural_p): New function.
2087 * program-point.h (program_point::effectively_intraprocedural_p):
2089 * sm-malloc.cc (deref_before_check::emit): Use it when rejecting
2090 interprocedural cases, so that we reject interprocedural cases
2091 that have become intraprocedural due to inlining.
2093 2023-03-18 David Malcolm <dmalcolm@redhat.com>
2096 * region-model.cc (region_model::on_longjmp): Pass false for
2097 new "eval_return_svalue" param of pop_frame.
2098 (region_model::pop_frame): Add new "eval_return_svalue" param and
2099 use it to suppress the call to get_rvalue on the result when
2100 needed by on_longjmp.
2101 * region-model.h (region_model::pop_frame): Add new
2102 "eval_return_svalue" param.
2104 2023-03-10 David Malcolm <dmalcolm@redhat.com>
2107 * region-model.cc (region_model::mark_region_as_unknown): Gather a
2108 set of maybe-live svalues and call on_maybe_live_values with it.
2109 * store.cc (binding_map::remove_overlapping_bindings): Add new
2110 "maybe_live_values" param; add any removed svalues to it.
2111 (binding_cluster::clobber_region): Add NULL as new param of
2112 remove_overlapping_bindings.
2113 (binding_cluster::mark_region_as_unknown): Add "maybe_live_values"
2114 param and pass it to remove_overlapping_bindings.
2115 (binding_cluster::maybe_get_compound_binding): Add NULL for new
2116 param of binding_map::remove_overlapping_bindings.
2117 (binding_cluster::remove_overlapping_bindings): Add
2118 "maybe_live_values" param and pass to
2119 binding_map::remove_overlapping_bindings.
2120 (store::set_value): Capture a set of maybe-live svalues, and call
2121 on_maybe_live_values with it.
2122 (store::on_maybe_live_values): New.
2123 (store::mark_region_as_unknown): Add "maybe_live_values" param
2124 and pass it to binding_cluster::mark_region_as_unknown.
2125 (store::remove_overlapping_bindings): Pass NULL for new param of
2126 binding_cluster::remove_overlapping_bindings.
2127 * store.h (binding_map::remove_overlapping_bindings): Add
2128 "maybe_live_values" param.
2129 (binding_cluster::mark_region_as_unknown): Likewise.
2130 (binding_cluster::remove_overlapping_bindings): Likewise.
2131 (store::mark_region_as_unknown): Likewise.
2132 (store::on_maybe_live_values): New decl.
2134 2023-03-10 David Malcolm <dmalcolm@redhat.com>
2138 * sm-malloc.cc (deref_before_check::deref_before_check):
2139 Initialize new field m_deref_expr. Assert that arg is non-NULL.
2140 (deref_before_check::emit): Reject cases where the spelling of the
2141 thing that was dereferenced differs from that of what is checked,
2142 or if the dereference expression was not found. Remove code to
2144 (deref_before_check::describe_state_change): Remove code to handle
2146 (deref_before_check::describe_final_event): Likewise.
2147 (deref_before_check::sufficiently_similar_p): New.
2148 (deref_before_check::m_deref_expr): New field.
2149 (malloc_state_machine::maybe_complain_about_deref_before_check):
2150 Don't warn if the diag_ptr is NULL.
2152 2023-03-03 David Malcolm <dmalcolm@redhat.com>
2154 * kf.cc (class kf_sprintf): New.
2155 (register_known_functions): Register it.
2157 2023-03-02 David Malcolm <dmalcolm@redhat.com>
2160 * region-model.cc (region_model::get_rvalue_1): Handle VAR_DECLs
2161 with a DECL_HARD_REGISTER by returning UNKNOWN.
2163 2023-03-02 Hans-Peter Nilsson <hp@axis.com>
2165 * kf.cc (register_known_functions): Add __errno function for newlib.
2167 2023-03-01 David Malcolm <dmalcolm@redhat.com>
2170 * region-model.cc (region_model::on_call_pre): Flatten logic by
2171 returning early. Consolidate logic for detecting const and pure
2172 functions. When considering whether an unhandled built-in
2173 function has side-effects, consider all kinds of builtin, rather
2174 than just BUILT_IN_NORMAL, and don't require
2175 gimple_builtin_call_types_compatible_p.
2177 2023-03-01 David Malcolm <dmalcolm@redhat.com>
2180 * infinite-recursion.cc (contains_unknown_p): New.
2181 (sufficiently_different_region_binding_p): New function, splitting
2182 out inner loop from...
2183 (sufficiently_different_p): ...here. Extend detection of unknown
2184 svalues to also include svalues that contain unknown. Treat
2185 changes in frames below the entry to the recursion as being
2186 sufficiently different to reject being an infinite recursion.
2188 2023-02-21 David Malcolm <dmalcolm@redhat.com>
2191 * analyzer.opt (fanalyzer-suppress-followups): New option.
2192 * engine.cc (impl_region_model_context::warn): Terminate the path
2193 if the diagnostic's terminate_path_p vfunc returns true and
2194 -fanalyzer-suppress-followups is true (the default).
2195 (impl_sm_context::warn): Likewise, for both overloads.
2196 * pending-diagnostic.h (pending_diagnostic::terminate_path_p): New
2198 * program-state.cc (program_state::on_edge): Terminate the path if
2199 the ctxt requests it during updating the edge.
2200 * region-model.cc (poisoned_value_diagnostic::terminate_path_p):
2202 * sm-malloc.cc (null_deref::terminate_path_p): New vfunc.
2203 (null_arg::terminate_path_p): New vfunc.
2205 2023-02-16 David Malcolm <dmalcolm@redhat.com>
2208 * constraint-manager.cc (bounded_range::dump_to_pp): Use
2209 bounded_range::singleton_p.
2210 (constraint_manager::add_bounded_ranges): Handle singleton ranges
2211 by adding an EQ_EXPR constraint.
2212 (constraint_manager::impossible_derived_conditions_p): New.
2213 (constraint_manager::eval_condition): Reject EQ_EXPR when it would
2214 imply impossible derived conditions.
2215 (selftest::test_bits): New.
2216 (selftest::run_constraint_manager_tests): Run it.
2217 * constraint-manager.h (bounded_range::singleton_p): New.
2218 (constraint_manager::impossible_derived_conditions_p): New decl.
2219 * region-model.cc (region_model::get_rvalue_1): Handle
2220 BIT_AND_EXPR, BIT_IOR_EXPR, and BIT_XOR_EXPR.
2222 2023-02-15 David Malcolm <dmalcolm@redhat.com>
2227 * diagnostic-manager.cc (epath_finder::get_best_epath): Add
2228 "target_stmt" param.
2229 (epath_finder::explore_feasible_paths): Likewise.
2230 (epath_finder::process_worklist_item): Likewise.
2231 (saved_diagnostic::calc_best_epath): Pass m_stmt to
2232 epath_finder::get_best_epath.
2233 * engine.cc (feasibility_state::maybe_update_for_edge): Move
2234 per-stmt logic to...
2235 (feasibility_state::update_for_stmt): ...this new function.
2236 * exploded-graph.h (feasibility_state::update_for_stmt): New decl.
2237 * feasible-graph.cc (feasible_node::get_state_at_stmt): New.
2238 * feasible-graph.h: Include "analyzer/exploded-graph.h".
2239 (feasible_node::get_state_at_stmt): New decl.
2240 * infinite-recursion.cc
2241 (infinite_recursion_diagnostic::check_valid_fpath_p): Update for
2242 vfunc signature change.
2243 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
2244 Convert first param to a reference. Add stmt param.
2245 * region-model.cc: Include "analyzer/feasible-graph.h".
2246 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
2248 (poisoned_value_diagnostic::check_valid_fpath_p): New.
2249 (poisoned_value_diagnostic::m_check_expr): New field.
2250 (region_model::check_for_poison): Attempt to supply a check_expr
2252 (region_model::deref_rvalue): Add NULL for new check_expr param
2253 of poisoned_value_diagnostic.
2254 (region_model::get_or_create_region_for_heap_alloc): Don't reuse
2255 regions that are marked as TOUCHED.
2257 2023-02-10 David Malcolm <dmalcolm@redhat.com>
2260 * sm-malloc.cc (deref_before_check::emit): Reject the warning if
2261 the check occurs within a macro defintion.
2263 2023-02-09 David Malcolm <dmalcolm@redhat.com>
2266 * state-purge.cc (get_candidate_for_purging): Add ADDR_EXPR
2269 2023-02-08 David Malcolm <dmalcolm@redhat.com>
2272 * state-purge.cc (state_purge_per_decl::process_point_backwards):
2273 Don't stop processing the decl if it's fully overwritten by
2274 this stmt if it's also used by this stmt.
2276 2023-02-07 David Malcolm <dmalcolm@redhat.com>
2279 * sm-fd.cc (class kf_read): New.
2280 (register_known_fd_functions): Register "read".
2281 * sm-file.cc (class kf_fread): Update comment.
2283 2023-02-02 David Malcolm <dmalcolm@redhat.com>
2286 * sm-fd.cc (fd_state_machine::check_for_fd_attrs): Add missing
2288 (fd_state_machine::on_listen): Don't issue phase-mismatch or
2289 type-mismatch warnings for the "invalid" state.
2291 2023-02-01 David Malcolm <dmalcolm@redhat.com>
2294 * pending-diagnostic.cc (fixup_location_in_macro_p): Add "alloca"
2295 to macros that we shouldn't unwind inside.
2297 2023-01-26 David Malcolm <dmalcolm@redhat.com>
2300 * analyzer.h (class feasible_node): New forward decl.
2301 * diagnostic-manager.cc (epath_finder::get_best_epath): Add "pd"
2303 (epath_finder::explore_feasible_paths): Likewise.
2304 (epath_finder::process_worklist_item): Likewise. Use it to call
2305 pending_diagnostic::check_valid_fpath_p on the final fpath to
2306 give pending_diagnostic a way to add additional restrictions on
2308 (saved_diagnostic::calc_best_epath): Pass pending_diagnostic to
2309 epath_finder::get_best_epath.
2310 * infinite-recursion.cc: Include "analyzer/feasible-graph.h".
2311 (infinite_recursion_diagnostic::check_valid_fpath_p): New.
2312 (infinite_recursion_diagnostic::fedge_uses_conjured_svalue_p): New.
2313 (infinite_recursion_diagnostic::expr_uses_conjured_svalue_p): New.
2314 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
2317 2023-01-19 David Malcolm <dmalcolm@redhat.com>
2320 * analyzer.h (class checker_event): New forward decl.
2321 (class state_change_event): Indent.
2322 (class warning_event): New forward decl.
2323 * checker-event.cc (state_change_event::state_change_event): Add
2325 (warning_event::get_desc): Update for new param of
2326 evdesc::final_event ctor.
2327 * checker-event.h (state_change_event::state_change_event): Add
2329 (state_change_event::get_exploded_node): New accessor.
2330 (state_change_event::m_enode): New field.
2331 (warning_event::warning_event): New "enode" param.
2332 (warning_event::get_exploded_node): New accessor.
2333 (warning_event::m_enode): New field.
2334 * diagnostic-manager.cc
2335 (state_change_event_creator::on_global_state_change): Pass
2336 src_node to state_change_event ctor.
2337 (state_change_event_creator::on_state_change): Likewise.
2338 (null_assignment_sm_context::set_next_state): Pass NULL for
2339 new param of state_change_event ctor.
2340 * infinite-recursion.cc
2341 (infinite_recursion_diagnostic::add_final_event): Update for new
2342 param of warning_event ctor.
2343 * pending-diagnostic.cc (pending_diagnostic::add_final_event):
2344 Pass enode to warning_event ctor.
2345 * pending-diagnostic.h (evdesc::final_event): Add reference to
2347 * sm-malloc.cc: Include "analyzer/checker-event.h" and
2348 "analyzer/exploded-graph.h".
2349 (deref_before_check::deref_before_check): Initialize new fields.
2350 (deref_before_check::emit): Reject warnings in which we were
2351 unable to determine the enodes of the dereference and the check.
2352 Reject warnings interprocedural warnings. Reject warnings in which
2353 the dereference doesn't dominate the check.
2354 (deref_before_check::describe_state_change): Set m_deref_enode.
2355 (deref_before_check::describe_final_event): Set m_check_enode.
2356 (deref_before_check::m_deref_enode): New field.
2357 (deref_before_check::m_check_enode): New field.
2359 2023-01-13 David Malcolm <dmalcolm@redhat.com>
2362 * region-model.cc (has_nondefault_case_for_value_p): New.
2363 (has_nondefault_cases_for_all_enum_values_p): New.
2364 (region_model::apply_constraints_for_gswitch): Skip
2365 implicitly-created "default" when switching on an enum
2366 and all enum values have non-default cases.
2367 (rejected_default_case::dump_to_pp): New.
2368 * region-model.h (region_model_context::possibly_tainted_p): New
2370 (class rejected_default_case): New.
2371 * sm-taint.cc (region_model_context::possibly_tainted_p): New.
2372 * supergraph.cc (switch_cfg_superedge::dump_label_to_pp): Dump
2373 when implicitly_created_default_p.
2374 (switch_cfg_superedge::implicitly_created_default_p): New.
2376 (switch_cfg_superedge::implicitly_created_default_p): New decl.
2378 2023-01-11 David Malcolm <dmalcolm@redhat.com>
2381 * kf.cc (class kf_strdup): New.
2382 (class kf_strndup): New.
2383 (register_known_functions): Register them.
2384 * region-model.cc (region_model::on_call_pre): Use
2385 &HEAP_ALLOCATED_REGION for the default result of an external
2386 function with the "malloc" attribute, rather than CONJURED_SVALUE.
2387 (region_model::get_or_create_region_for_heap_alloc): Allow
2388 "size_in_bytes" to be NULL.
2389 * store.cc (store::set_value): When handling *UNKNOWN = VAL,
2390 mark VAL as "maybe bound".
2392 2022-12-16 David Malcolm <dmalcolm@redhat.com>
2395 * kf.cc (kf_memcpy_memmove::impl_call_pre): Pass in source region
2396 to region_model::check_for_poison.
2397 * region-model-asm.cc (region_model::on_asm_stmt): Pass NULL
2398 region to region_model::check_for_poison.
2399 * region-model.cc (region_model::check_for_poison): Add
2400 "src_region" param, and pass it to poisoned_value_diagnostic.
2401 (region_model::on_assignment): Pass NULL region to
2402 region_model::check_for_poison.
2403 (region_model::get_rvalue): Likewise.
2404 * region-model.h (region_model::check_for_poison): Add
2406 * sm-fd.cc (fd_state_machine::on_accept): Pass in source region
2407 to region_model::check_for_poison.
2408 * varargs.cc (kf_va_copy::impl_call_pre): Pass NULL region to
2409 region_model::check_for_poison.
2410 (kf_va_arg::impl_call_pre): Pass in source region to
2411 region_model::check_for_poison.
2413 2022-12-14 David Malcolm <dmalcolm@redhat.com>
2416 * region.cc (decl_region::get_svalue_for_initializer): Bail out to
2417 avoid calling binding_key::make with an empty region.
2418 * store.cc (binding_map::apply_ctor_val_to_range): Likewise.
2419 (binding_map::apply_ctor_pair_to_child_region): Likewise.
2420 (binding_cluster::bind): Likewise.
2421 (binding_cluster::purge_region): Likewise.
2422 (binding_cluster::maybe_get_compound_binding): Likewise.
2423 (binding_cluster::maybe_get_simple_value): Likewise.
2425 2022-12-09 David Malcolm <dmalcolm@redhat.com>
2427 * analyzer.h (class known_function): Expand comment.
2428 * region-model-impl-calls.cc: Rename to...
2430 * known-function-manager.h (class known_function_manager): Add
2433 2022-12-09 David Malcolm <dmalcolm@redhat.com>
2437 (call_summary_replay::convert_region_from_summary_1): Convert
2438 heap_regs_in_use from auto_sbitmap to auto_bitmap.
2439 * region-model-manager.cc
2440 (region_model_manager::get_or_create_region_for_heap_alloc):
2441 Convert from sbitmap to bitmap.
2442 * region-model-manager.h: Likewise.
2444 (region_model::get_or_create_region_for_heap_alloc): Convert from
2445 auto_sbitmap to auto_bitmap.
2446 (region_model::get_referenced_base_regions): Likewise.
2447 * region-model.h: Include "bitmap.h" rather than "sbitmap.h".
2448 (region_model::get_referenced_base_regions): Convert from
2449 auto_sbitmap to auto_bitmap.
2451 2022-12-09 David Malcolm <dmalcolm@redhat.com>
2453 * region-model-impl-calls.cc (class kf_memcpy): Rename to...
2454 (class kf_memcpy_memmove): ...this.
2455 (kf_memcpy::impl_call_pre): Rename to...
2456 (kf_memcpy_memmove::impl_call_pre): ...this, and check the src for
2458 (register_known_functions): Update for above renaming, and
2459 register BUILT_IN_MEMMOVE and BUILT_IN_MEMMOVE_CHK.
2461 2022-12-06 David Malcolm <dmalcolm@redhat.com>
2464 * region-model.cc (region_model::get_store_value): Return an
2465 unknown value for empty regions.
2466 (region_model::set_value): Bail on empty regions.
2467 * region.cc (region::empty_p): New.
2468 * region.h (region::empty_p): New decl.
2469 * state-purge.cc (same_binding_p): Bail if either region is empty.
2470 * store.cc (binding_key::make): Assert that a concrete binding's
2471 bit_size must be > 0.
2472 (binding_cluster::mark_region_as_unknown): Bail on empty regions.
2473 (binding_cluster::get_binding): Likewise.
2474 (binding_cluster::remove_overlapping_bindings): Likewise.
2475 (binding_cluster::on_unknown_fncall): Don't conjure values for
2477 (store::fill_region): Bail on empty regions.
2478 * store.h (class concrete_binding): Update comment to reflect that
2479 the range of bits must be non-empty.
2480 (concrete_binding::concrete_binding): Assert that bit range is
2483 2022-12-06 David Malcolm <dmalcolm@redhat.com>
2486 * region-model-manager.cc
2487 (region_model_manager::get_or_create_null_ptr): New.
2488 * region-model-manager.h
2489 (region_model_manager::get_or_create_null_ptr): New decl.
2490 * region-model.cc (region_model::on_top_level_param): Add
2491 "nonnull" param and make use of it.
2492 (region_model::push_frame): When handling a top-level entrypoint
2493 to the analysis, determine which params __attribute__((nonnull))
2494 applies to, and pass to on_top_level_param.
2495 * region-model.h (region_model::on_top_level_param): Add "nonnull"
2498 2022-12-06 David Malcolm <dmalcolm@redhat.com>
2500 * analyzer.h (register_known_analyzer_functions): New decl.
2501 (register_known_functions_lang_cp): New decl.
2502 * call-details.cc: New file, split out from
2503 region-model-impl-calls.cc.
2504 * call-details.h: New file, split out from region-model.h.
2505 * call-info.cc: Include "analyzer/call-details.h".
2506 * call-summary.h: Likewise.
2507 * kf-analyzer.cc: New file, split out from
2508 region-model-impl-calls.cc.
2509 * kf-lang-cp.cc: Likewise.
2510 * known-function-manager.cc: Include "analyzer/call-details.h".
2511 * region-model-impl-calls.cc: Move definitions of call_details's
2512 member functions to call-details.cc. Move class kf_analyzer_* to
2513 kf-analyzer.cc. Move kf_operator_new and kf_operator_delete to
2514 kf-lang-cp.cc. Refresh #includes accordingly.
2515 (register_known_functions): Replace registration of __analyzer_*
2516 functions with a call to register_known_analyzer_functions.
2517 Replace registration of C++ support functions with a call to
2518 register_known_functions_lang_cp.
2519 * region-model.h (class call_details): Move to new call-details.h.
2520 * sm-fd.cc: Include "analyzer/call-details.h".
2521 * sm-file.cc: Likewise.
2522 * sm-malloc.cc: Likewise.
2523 * varargs.cc: Likewise.
2525 2022-12-02 David Malcolm <dmalcolm@redhat.com>
2527 * analyzer.h (struct event_loc_info): New forward decl.
2528 * bounds-checking.cc: Use event_loc_info throughout to bundle the
2529 loc, fndecl, depth triples.
2530 * call-info.cc: Likewise.
2531 * checker-event.cc: Likewise.
2532 * checker-event.h (struct event_loc_info): New decl. Use it
2533 throughout to bundle the loc, fndecl, depth triples.
2534 * checker-path.cc: Likewise.
2535 * checker-path.h: Likewise.
2536 * diagnostic-manager.cc: Likewise.
2537 * engine.cc: Likewise.
2538 * infinite-recursion.cc: Likewise.
2539 * pending-diagnostic.cc: Likewise.
2540 * pending-diagnostic.h: Likewise.
2541 * region-model.cc: Likewise.
2542 * sm-signal.cc: Likewise.
2543 * varargs.cc: Likewise.
2545 2022-12-02 David Malcolm <dmalcolm@redhat.com>
2548 * analyzer.cc (make_label_text_n): Convert param "n" from int to
2549 unsigned HOST_WIDE_INT.
2550 * analyzer.h (make_label_text_n): Likewise for decl.
2551 * bounds-checking.cc: Include "analyzer/checker-event.h" and
2552 "analyzer/checker-path.h".
2553 (out_of_bounds::add_region_creation_events): New.
2554 (concrete_past_the_end::describe_region_creation_event): Replace
2556 (concrete_past_the_end::add_region_creation_events): ...this.
2557 (symbolic_past_the_end::describe_region_creation_event): Delete.
2558 * checker-event.cc (region_creation_event::region_creation_event):
2559 Update for dropping all member data.
2560 (region_creation_event::get_desc): Delete, splitting out into
2561 region_creation_event_memory_space::get_desc,
2562 region_creation_event_capacity::get_desc, and
2563 region_creation_event_debug::get_desc.
2564 (region_creation_event_memory_space::get_desc): New.
2565 (region_creation_event_capacity::get_desc): New.
2566 (region_creation_event_allocation_size::get_desc): New.
2567 (region_creation_event_debug::get_desc): New.
2568 * checker-event.h: Include "analyzer/program-state.h".
2569 (enum rce_kind): Delete.
2570 (class region_creation_event): Drop all member data.
2571 (region_creation_event::region_creation_event): Make protected.
2572 (region_creation_event::get_desc): Delete.
2573 (class region_creation_event_memory_space): New.
2574 (class region_creation_event_capacity): New.
2575 (class region_creation_event_allocation_size): New.
2576 (class region_creation_event_debug): New.
2577 * checker-path.cc (checker_path::add_region_creation_events): Add
2578 "pd" param. Call pending_diangnostic::add_region_creation_events.
2579 Update for conversion of RCE_DEBUG to region_creation_event_debug.
2580 * checker-path.h (checker_path::add_region_creation_events): Add
2582 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
2583 Pass pending_diagnostic to
2584 emission_path::add_region_creation_events.
2585 (diagnostic_manager::build_emission_path): Pass path_builder to
2586 add_event_on_final_node.
2587 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
2588 Pass pending_diagnostic to
2589 emission_path::add_region_creation_events.
2590 (diagnostic_manager::add_events_for_eedge): Pass
2591 pending_diagnostic to emission_path::add_region_creation_events.
2592 * diagnostic-manager.h
2593 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
2594 * pending-diagnostic.cc
2595 (pending_diagnostic::add_region_creation_events): New.
2596 * pending-diagnostic.h (struct region_creation): Delete.
2597 (pending_diagnostic::describe_region_creation_event): Delete.
2598 (pending_diagnostic::add_region_creation_events): New vfunc.
2599 * region-model.cc: Include "analyzer/checker-event.h" and
2600 "analyzer/checker-path.h".
2601 (dubious_allocation_size::dubious_allocation_size): Initialize
2602 m_has_allocation_event.
2603 (dubious_allocation_size::describe_region_creation_event): Delete.
2604 (dubious_allocation_size::describe_final_event): Update for
2605 replacement of m_allocation_event with m_has_allocation_event.
2606 (dubious_allocation_size::add_region_creation_events): New.
2607 (dubious_allocation_size::m_allocation_event): Replace with...
2608 (dubious_allocation_size::m_has_allocation_event): ...this.
2610 2022-12-02 David Malcolm <dmalcolm@redhat.com>
2613 * region-model-manager.cc
2614 (region_model_manager::maybe_fold_binop): Fold (0 - VAL) to -VAL.
2615 * region-model.cc (region_model::eval_condition): Handle e.g.
2616 "-X <= 0" as equivalent to X >= 0".
2618 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2621 * bounds-checking.cc
2622 (symbolic_past_the_end::describe_final_event): Delete, moving to
2623 symbolic_buffer_overflow::describe_final_event and
2624 symbolic_buffer_over_read::describe_final_event, eliminating
2625 composition of text strings via "byte_str" and "m_dir_str".
2626 (symbolic_past_the_end::m_dir_str): Delete field.
2627 (symbolic_buffer_overflow::symbolic_buffer_overflow): Drop
2629 (symbolic_buffer_overflow::describe_final_event): New, as noted
2631 (symbolic_buffer_over_read::symbolic_buffer_overflow): Drop
2633 (symbolic_buffer_over_read::describe_final_event): New, as noted
2636 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2638 * bounds-checking.cc (class out_of_bounds): Split out from...
2639 (class concrete_out_of_bounds): New abstract subclass.
2640 (class past_the_end): Rename to...
2641 (class concrete_past_the_end): ...this, and make a subclass of
2642 concrete_out_of_bounds.
2643 (class buffer_overflow): Rename to...
2644 (class concrete_buffer_overflow): ...this, and make a subclass of
2645 concrete_past_the_end.
2646 (class buffer_over_read): Rename to...
2647 (class concrete_buffer_over_read): ...this, and make a subclass of
2648 concrete_past_the_end.
2649 (class buffer_underwrite): Rename to...
2650 (class concrete_buffer_underwrite): ...this, and make a subclass
2651 of concrete_out_of_bounds.
2652 (class buffer_under_read): Rename to...
2653 (class concrete_buffer_under_read): ...this, and make a subclass
2654 of concrete_out_of_bounds.
2655 (class symbolic_past_the_end): Convert to a subclass of
2657 (symbolic_buffer_overflow::get_kind): New.
2658 (symbolic_buffer_over_read::get_kind): New.
2659 (region_model::check_region_bounds): Update for renamings.
2660 * engine.cc (impl_sm_context::set_next_state): Eliminate
2661 "new_ctxt", passing NULL to get_rvalue instead.
2662 (impl_sm_context::warn): Likewise.
2664 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2667 * bounds-checking.cc (out_of_bounds::get_memory_space): New.
2668 (buffer_overflow::emit): Use it.
2669 (class buffer_overread): Rename to...
2670 (class buffer_over_read): ...this.
2671 (buffer_over_read::emit): Specify which memory space the read is
2672 from, where known. Change "overread" to "over-read".
2673 (class buffer_underflow): Rename to...
2674 (class buffer_underwrite): ...this.
2675 (buffer_underwrite::emit): Specify which memory space the write is
2676 to, where known. Change "underflow" to "underwrite".
2677 (class buffer_underread): Rename to...
2678 (class buffer_under_read): Rename to...
2679 (buffer_under_read::emit): Specify which memory space the read is
2680 from, where known. Change "underread" to "under-read".
2681 (symbolic_past_the_end::get_memory_space): New.
2682 (symbolic_buffer_overflow::emit): Use it.
2683 (class symbolic_buffer_overread): Rename to...
2684 (class symbolic_buffer_over_read): ...this.
2685 (symbolic_buffer_over_read::emit): Specify which memory space the
2686 read is from, where known. Change "overread" to "over-read".
2687 (region_model::check_symbolic_bounds): Update for class renaming.
2688 (region_model::check_region_bounds): Likewise.
2690 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2693 * bounds-checking.cc (out_of_bounds::maybe_describe_array_bounds):
2695 (buffer_overflow::emit): Call maybe_describe_array_bounds.
2696 (buffer_overread::emit): Likewise.
2697 (buffer_underflow::emit): Likewise.
2698 (buffer_underread::emit): Likewise.
2700 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2703 * bounds-checking.cc (buffer_overflow::emit): Use inform_n.
2704 Update wording to clarify that we're talking about the size of
2705 the bad access, rather than its position.
2706 (buffer_overread::emit): Likewise.
2708 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2710 * bounds-checking.cc: New file, taken from region-model.cc.
2711 * region-model.cc (class out_of_bounds): Move to
2713 (class past_the_end): Likewise.
2714 (class buffer_overflow): Likewise.
2715 (class buffer_overread): Likewise.
2716 (class buffer_underflow): Likewise.
2717 (class buffer_underread): Likewise.
2718 (class symbolic_past_the_end): Likewise.
2719 (class symbolic_buffer_overflow): Likewise.
2720 (class symbolic_buffer_overread): Likewise.
2721 (region_model::check_symbolic_bounds): Likewise.
2722 (maybe_get_integer_cst_tree): Likewise.
2723 (region_model::check_region_bounds): Likewise.
2724 * region-model.h: Add comment.
2726 2022-12-01 David Malcolm <dmalcolm@redhat.com>
2729 * sm-fd.cc (fd_state_machine::on_bind): Handle m_constant_fd in
2730 the "success" outcome.
2731 (fd_state_machine::on_connect): Likewise.
2732 * sm-fd.dot: Add "constant_fd" state and its transitions.
2734 2022-11-30 David Malcolm <dmalcolm@redhat.com>
2736 * region-model-impl-calls.cc (class kf_fgets): Move to sm-file.cc.
2737 (kf_fgets::impl_call_pre): Likewise.
2738 (class kf_fread): Likewise.
2739 (kf_fread::impl_call_pre): Likewise.
2740 (class kf_getchar): Likewise.
2741 (class kf_stdio_output_fn): Likewise.
2742 (register_known_functions): Move registration of
2743 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2744 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2745 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2746 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2747 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2748 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
2749 "getchar", "fgets", "fgets_unlocked", and "fread" to
2750 register_known_file_functions.
2751 * sm-file.cc (class kf_stdio_output_fn): Move here from
2752 region-model-impl-calls.cc.
2753 (class kf_fgets): Likewise.
2754 (class kf_fread): Likewise.
2755 (class kf_getchar): Likewise.
2756 (register_known_file_functions): Move registration of
2757 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2758 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2759 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2760 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2761 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2762 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
2763 "fgets", "fgets_unlocked", "fread", and "getchar" to here from
2764 register_known_functions.
2766 2022-11-30 David Malcolm <dmalcolm@redhat.com>
2769 * analyzer.h (register_known_file_functions): New decl.
2770 * program-state.cc (sm_state_map::replay_call_summary): Rejct
2771 attempts to store sm-state for caller_sval that can't have
2773 * region-model-impl-calls.cc (register_known_functions): Call
2774 register_known_file_functions.
2775 * sm-fd.cc (class kf_isatty): New.
2776 (register_known_fd_functions): Register it.
2777 * sm-file.cc (class kf_ferror): New.
2778 (class kf_fileno): New.
2779 (class kf_getc): New.
2780 (register_known_file_functions): New.
2782 2022-11-30 David Malcolm <dmalcolm@redhat.com>
2785 * region-model-manager.cc
2786 (region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
2787 PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
2788 type matches that of arg0 in favor of a cast.
2790 2022-11-24 Martin Liska <mliska@suse.cz>
2792 * varargs.cc: Fix Clang warnings.
2794 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2798 (call_summary_replay::convert_region_from_summary_1): Update for
2799 change to creation of heap-allocated regions.
2800 * program-state.cc (test_program_state_1): Likewise.
2801 (test_program_state_merging): Likewise.
2802 * region-model-impl-calls.cc (kf_calloc::impl_call_pre): Likewise.
2803 (kf_malloc::impl_call_pre): Likewise.
2804 (kf_operator_new::impl_call_pre): Likewise.
2805 (kf_realloc::impl_call_postsuccess_with_move::update_model): Likewise.
2806 * region-model-manager.cc
2807 (region_model_manager::create_region_for_heap_alloc): Convert
2809 (region_model_manager::get_or_create_region_for_heap_alloc):
2810 ...this, reusing an existing region if it's unreferenced in the
2812 * region-model-manager.h (region_model_manager::get_num_regions): New.
2813 (region_model_manager::create_region_for_heap_alloc): Convert to...
2814 (region_model_manager::get_or_create_region_for_heap_alloc): ...this.
2815 * region-model.cc (region_to_value_map::can_merge_with_p): Reject
2816 merger when the values are different.
2817 (region_model::create_region_for_heap_alloc): Convert to...
2818 (region_model::get_or_create_region_for_heap_alloc): ...this.
2819 (region_model::get_referenced_base_regions): New.
2820 (selftest::test_state_merging): Update for change to creation of
2821 heap-allocated regions.
2822 (selftest::test_malloc_constraints): Likewise.
2823 (selftest::test_malloc): Likewise.
2824 * region-model.h: Include "sbitmap.h".
2825 (region_model::create_region_for_heap_alloc): Convert to...
2826 (region_model::get_or_create_region_for_heap_alloc): ...this.
2827 (region_model::get_referenced_base_regions): New decl.
2828 * store.cc (store::canonicalize): Don't purge a heap-allocated region
2829 that's been marked as escaping.
2831 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2833 * checker-path.cc (checker_path::inject_any_inlined_call_events):
2834 Don't dump the address of the block when -fdump-noaddr.
2836 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2838 * region-model.h (region_model::on_socket): Delete decl.
2839 (region_model::on_bind): Likewise.
2840 (region_model::on_listen): Likewise.
2841 (region_model::on_accept): Likewise.
2842 (region_model::on_connect): Likewise.
2843 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
2844 of region_model::on_socket into here, ...
2845 (region_model::on_socket): ...eliminating this function.
2846 (kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
2847 (region_model::on_bind): ...eliminating this function.
2848 (kf_listen::outcome_of_listen::update_model): Likewise fo
2850 (region_model::on_listen): ...eliminating this function.
2851 (kf_accept::outcome_of_accept::update_model): Likewise fo
2853 (region_model::on_accept): ...eliminating this function.
2854 (kf_connect::outcome_of_connect::update_model): Likewise fo
2856 (region_model::on_connect): ...eliminating this function.
2858 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2860 * analyzer.h (register_known_fd_functions): New decl.
2861 * region-model-impl-calls.cc (class kf_accept): Move to sm-fd.cc.
2862 (class kf_bind): Likewise.
2863 (class kf_connect): Likewise.
2864 (class kf_listen): Likewise.
2865 (class kf_pipe): Likewise.
2866 (class kf_socket): Likewise.
2867 (register_known_functions): Remove registration of the above
2868 functions, instead calling register_known_fd_functions.
2869 * sm-fd.cc: Include "analyzer/call-info.h".
2870 (class kf_socket): Move here from region-model-impl-calls.cc.
2871 (class kf_bind): Likewise.
2872 (class kf_listen): Likewise.
2873 (class kf_accept): Likewise.
2874 (class kf_connect): Likewise.
2875 (class kf_pipe): Likewise.
2876 (register_known_fd_functions): New.
2878 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2881 * known-function-manager.cc (known_function_manager::get_match):
2882 Don't look up fndecls by name when they're not in the root
2885 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2888 * sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
2889 complain when old state is "fd-constant".
2890 (fd_state_machine::on_listen): Likewise.
2891 (fd_state_machine::on_accept): Likewise.
2893 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2896 * region-model-impl-calls.cc (register_known_functions): Register
2897 "___errno" and "__error" as synonyms for "__errno_location".
2899 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2901 * analyzer.h (class internal_known_function): New.
2902 (register_varargs_builtins): New decl.
2903 * engine.cc (exploded_node::on_stmt_pre): Remove
2904 "out_terminate_path" param from call to region_model::on_stmt_pre.
2905 (feasibility_state::maybe_update_for_edge): Likewise.
2906 * known-function-manager.cc: Include "basic-block.h", "gimple.h",
2907 and "analyzer/region-model.h".
2908 (known_function_manager::known_function_manager): Initialize
2910 (known_function_manager::~known_function_manager): Clean up
2912 (known_function_manager::get_by_identifier): Make const.
2913 (known_function_manager::add): New overloaded definitions for
2914 enum built_in_function and enum internal_fn.
2915 (known_function_manager::get_by_fndecl): Delete.
2916 (known_function_manager::get_match): New.
2917 (known_function_manager::get_internal_fn): New.
2918 (known_function_manager::get_normal_builtin): New.
2919 * known-function-manager.h
2920 (known_function_manager::get_by_identifier): Make private and
2921 add const qualifier.
2922 (known_function_manager::get_by_fndecl): Delete.
2923 (known_function_manager::add): Add overloaded decls for
2924 enum built_in_function name and enum internal_fn.
2925 (known_function_manager::get_match): New decl.
2926 (known_function_manager::get_internal_fn): New decl.
2927 (known_function_manager::get_normal_builtin): New decl.
2928 (known_function_manager::m_combined_fns_arr): New field.
2929 * region-model-impl-calls.cc (call_details::arg_is_size_p): New.
2930 (class kf_alloca): New.
2931 (region_model::impl_call_alloca): Convert to...
2932 (kf_alloca::impl_call_pre): ...this.
2933 (kf_analyzer_dump_capacity::matches_call_types_p): Rewrite check
2934 to use call_details::arg_is_pointer_p.
2935 (region_model::impl_call_builtin_expect): Convert to...
2936 (class kf_expect): ...this.
2937 (class kf_calloc): New, adding check that both arguments are
2939 (region_model::impl_call_calloc): Convert to...
2940 (kf_calloc::impl_call_pre): ...this.
2941 (kf_connect::matches_call_types_p): Rewrite check to use
2942 call_details::arg_is_pointer_p.
2943 (region_model::impl_call_error): Convert to...
2944 (class kf_error): ...this, and...
2945 (kf_error::impl_call_pre): ...this.
2946 (class kf_fgets): New, adding checks that args 0 and 2 are
2948 (region_model::impl_call_fgets): Convert to...
2949 (kf_fgets::impl_call_pre): ...this.
2950 (class kf_fread): New, adding checks on the argument types.
2951 (region_model::impl_call_fread): Convert to...
2952 (kf_fread::impl_call_pre): ...this.
2953 (class kf_free): New, adding check that the argument is a pointer.
2954 (region_model::impl_call_free): Convert to...
2955 (kf_free::impl_call_post): ...this.
2956 (class kf_getchar): New.
2957 (class kf_malloc): New, adding check that the argument is a
2959 (region_model::impl_call_malloc): Convert to...
2960 (kf_malloc::impl_call_pre): ...this.
2961 (class kf_memcpy): New, adding checks on arguments.
2962 (region_model::impl_call_memcpy): Convert to...
2963 (kf_memcpy::impl_call_pre): ...this.
2964 (class kf_memset): New.
2965 (region_model::impl_call_memset): Convert to...
2966 (kf_memset::impl_call_pre): ...this.
2967 (kf_pipe::matches_call_types_p): Rewrite check to use
2968 call_details::arg_is_pointer_p.
2969 (kf_putenv::matches_call_types_p): Likewise.
2970 (class kf_realloc): New, adding checks on the argument types.
2971 (region_model::impl_call_realloc): Convert to...
2972 (kf_realloc::impl_call_post): ...this.
2973 (class kf_strchr): New.
2974 (region_model::impl_call_strchr): Convert to...
2975 (kf_strchr::impl_call_post): ...this.
2976 (class kf_stack_restore): New.
2977 (class kf_stack_save): New.
2978 (class kf_stdio_output_fn): New.
2979 (class kf_strcpy): New,
2980 (region_model::impl_call_strcpy): Convert to...
2981 (kf_strcpy::impl_call_pre): ...this.
2982 (class kf_strlen): New.
2983 (region_model::impl_call_strlen): Convert to...
2984 (kf_strlen::impl_call_pre): ...this.
2985 (class kf_ubsan_bounds): New.
2986 (region_model::impl_deallocation_call): Reimplement to avoid call
2988 (register_known_functions): Add handlers for IFN_BUILTIN_EXPECT
2989 and IFN_UBSAN_BOUNDS. Add handlers for BUILT_IN_ALLOCA,
2990 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
2991 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FPRINTF,
2992 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2993 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2994 BUILT_IN_FREE, BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED,
2995 BUILT_IN_MALLOC, BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK,
2996 BUILT_IN_MEMSET, BUILT_IN_MEMSET_CHK, BUILT_IN_PRINTF,
2997 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2998 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2999 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_REALLOC, BUILT_IN_STACK_RESTORE,
3000 BUILT_IN_STACK_SAVE, BUILT_IN_STRCHR, BUILT_IN_STRCPY,
3001 BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN, BUILT_IN_VFPRINTF, and
3002 BUILT_IN_VPRINTF. Call register_varargs_builtins. Add handlers
3003 for "getchar", "memset", "fgets", "fgets_unlocked", "fread",
3004 "error", and "error_at_line".
3005 * region-model.cc (region_model::on_stmt_pre): Drop
3006 "out_terminate_path" param.
3007 (region_model::get_known_function): Reimplement by calling
3008 known_function_manager::get_match, passing new "cd" param.
3009 Add overload taking enum internal_fn.
3010 (region_model::on_call_pre): Drop "out_terminate_path" param.
3011 Remove special-case handling of internal fns IFN_BUILTIN_EXPECT,
3012 IFN_UBSAN_BOUNDS, and IFN_VA_ARG, of built-in fns BUILT_IN_ALLOCA,
3013 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
3014 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FREE, BUILT_IN_MALLOC,
3015 BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMSET,
3016 BUILT_IN_MEMSET_CHK, BUILT_IN_REALLOC, BUILT_IN_STRCHR,
3017 BUILT_IN_STRCPY, BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN,
3018 BUILT_IN_STACK_SAVE, BUILT_IN_STACK_RESTORE, BUILT_IN_FPRINTF,
3019 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED,
3020 BUILT_IN_FPUTC, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS,
3021 BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE,
3022 BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
3023 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
3024 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
3025 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF, BUILT_IN_VA_START, and
3026 BUILT_IN_VA_COPY, and of named functions "malloc", "calloc",
3027 "alloca", "realloc", "error", "error_at_line", "fgets",
3028 "fgets_unlocked", "fread", "getchar", "memset", "strchr", and
3029 "strlen". Replace all this special-casing with calls to
3030 get_known_function for internal fns and for fn decls.
3031 (region_model::on_call_post): Remove special-casing handling for
3032 "free" and "strchr", and for BUILT_IN_REALLOC, BUILT_IN_STRCHR,
3033 and BUILT_IN_VA_END. Replace by consolidating on usage of
3035 * region-model.h (call_details::arg_is_size_p): New.
3036 (region_model::on_stmt_pre): Drop "out_terminate_path" param.
3037 (region_model::on_call_pre): Likewise.
3038 (region_model::impl_call_alloca): Delete.
3039 (region_model::impl_call_builtin_expect): Delete.
3040 (region_model::impl_call_calloc): Delete.
3041 (region_model::impl_call_error): Delete.
3042 (region_model::impl_call_fgets): Delete.
3043 (region_model::impl_call_fread): Delete.
3044 (region_model::impl_call_free): Delete.
3045 (region_model::impl_call_malloc): Delete.
3046 (region_model::impl_call_memcpy): Delete.
3047 (region_model::impl_call_memset): Delete.
3048 (region_model::impl_call_realloc): Delete.
3049 (region_model::impl_call_strchr): Delete.
3050 (region_model::impl_call_strcpy): Delete.
3051 (region_model::impl_call_strlen): Delete.
3052 (region_model::impl_call_va_start): Delete.
3053 (region_model::impl_call_va_copy): Delete.
3054 (region_model::impl_call_va_arg): Delete.
3055 (region_model::impl_call_va_end): Delete.
3056 (region_model::check_region_for_write): Public.
3057 (region_model::get_known_function): Add "cd" param. Add
3058 overloaded decl taking enum internal_fn.
3059 * sm-malloc.cc: Update comments.
3060 * varargs.cc (class kf_va_start): New.
3061 (region_model::impl_call_va_start): Convert to...
3062 (kf_va_start::impl_call_pre): ...this.
3063 (class kf_va_copy): New.
3064 (region_model::impl_call_va_copy): Convert to...
3065 (kf_va_copy::impl_call_pre): ...this.
3066 (class kf_va_arg): New.
3067 (region_model::impl_call_va_arg): Convert to...
3068 (kf_va_arg::impl_call_pre): ...this.
3069 (class kf_va_end): New.
3070 (region_model::impl_call_va_end): Delete.
3071 (register_varargs_builtins): New.
3073 2022-11-22 David Malcolm <dmalcolm@redhat.com>
3076 * region-model.cc (region_model::update_for_int_cst_return):
3077 Require that the return type be an integer type.
3078 (region_model::update_for_nonzero_return): Likewise.
3080 2022-11-22 David Malcolm <dmalcolm@redhat.com>
3083 * region-model-impl-calls.cc (kf_accept::matches_call_types_p):
3084 Require that args 1 and 2 be pointers.
3085 (kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
3086 * region-model.h (call_details::arg_is_pointer_p): New
3088 2022-11-22 David Malcolm <dmalcolm@redhat.com>
3092 (call_summary_replay::convert_region_from_summary_1): Handle
3093 RK_THREAD_LOCAL and RK_ERRNO in switch.
3094 * region-model.cc (region_model::get_representative_path_var_1):
3097 2022-11-19 David Malcolm <dmalcolm@redhat.com>
3100 * engine.cc (dynamic_call_info_t::update_model): Update the model
3101 by pushing or pop a frame, rather than by clobbering it with the
3102 model from the exploded_node's state.
3104 2022-11-18 David Malcolm <dmalcolm@redhat.com>
3106 * analyzer.cc (is_pipe_call_p): Delete.
3107 * analyzer.h (is_pipe_call_p): Delete.
3108 * region-model-impl-calls.cc (call_details::get_location): New.
3109 (class kf_analyzer_break): New, adapted from
3110 region_model::on_stmt_pre.
3111 (region_model::impl_call_analyzer_describe): Convert to...
3112 (class kf_analyzer_describe): ...this.
3113 (region_model::impl_call_analyzer_dump_capacity): Convert to...
3114 (class kf_analyzer_dump_capacity): ...this.
3115 (region_model::impl_call_analyzer_dump_escaped): Convert to...
3116 (class kf_analyzer_dump_escaped): ...this.
3117 (class kf_analyzer_dump_exploded_nodes): New.
3118 (region_model::impl_call_analyzer_dump_named_constant): Convert
3120 (class kf_analyzer_dump_named_constant): ...this.
3121 (class dump_path_diagnostic): Move here from region-model.cc.
3122 (class kf_analyzer_dump_path) New, adapted from
3123 region_model::on_stmt_pre.
3124 (class kf_analyzer_dump_region_model): Likewise.
3125 (region_model::impl_call_analyzer_eval): Convert to...
3126 (class kf_analyzer_eval): ...this.
3127 (region_model::impl_call_analyzer_get_unknown_ptr): Convert to...
3128 (class kf_analyzer_get_unknown_ptr): ...this.
3129 (class known_function_accept): Rename to...
3130 (class kf_accept): ...this.
3131 (class known_function_bind): Rename to...
3132 (class kf_bind): ...this.
3133 (class known_function_connect): Rename to...
3134 (class kf_connect): ...this.
3135 (region_model::impl_call_errno_location): Convert to...
3136 (class kf_errno_location): ...this.
3137 (class known_function_listen): Rename to...
3138 (class kf_listen): ...this.
3139 (region_model::impl_call_pipe): Convert to...
3140 (class kf_pipe): ...this.
3141 (region_model::impl_call_putenv): Convert to...
3142 (class kf_putenv): ...this.
3143 (region_model::impl_call_operator_new): Convert to...
3144 (class kf_operator_new): ...this.
3145 (region_model::impl_call_operator_delete): Convert to...
3146 (class kf_operator_delete): ...this.
3147 (class known_function_socket): Rename to...
3148 (class kf_socket): ...this.
3149 (register_known_functions): Rename param to KFM. Break out
3150 existing known functions into a "POSIX" section, and add "pipe",
3151 "pipe2", and "putenv". Add debugging functions
3152 "__analyzer_break", "__analyzer_describe",
3153 "__analyzer_dump_capacity", "__analyzer_dump_escaped",
3154 "__analyzer_dump_exploded_nodes",
3155 "__analyzer_dump_named_constant", "__analyzer_dump_path",
3156 "__analyzer_dump_region_model", "__analyzer_eval",
3157 "__analyzer_get_unknown_ptr". Add C++ support functions
3158 "operator new", "operator new []", "operator delete", and
3159 "operator delete []".
3160 * region-model.cc (class dump_path_diagnostic): Move to
3161 region-model-impl-calls.cc.
3162 (region_model::on_stmt_pre): Eliminate special-casing of
3163 "__analyzer_describe", "__analyzer_dump_capacity",
3164 "__analyzer_dump_escaped", "__analyzer_dump_named_constant",
3165 "__analyzer_dump_path", "__analyzer_dump_region_model",
3166 "__analyzer_eval", "__analyzer_break",
3167 "__analyzer_dump_exploded_nodes", "__analyzer_get_unknown_ptr",
3168 "__errno_location", "pipe", "pipe2", "putenv", "operator new",
3169 "operator new []", "operator delete", "operator delete []"
3170 "pipe" and "pipe2", handling them instead via the known_functions
3172 * region-model.h (call_details::get_location): New decl.
3173 (region_model::impl_call_analyzer_describe): Delete decl.
3174 (region_model::impl_call_analyzer_dump_capacity): Delete decl.
3175 (region_model::impl_call_analyzer_dump_escaped): Delete decl.
3176 (region_model::impl_call_analyzer_dump_named_constant): Delete decl.
3177 (region_model::impl_call_analyzer_eval): Delete decl.
3178 (region_model::impl_call_analyzer_get_unknown_ptr): Delete decl.
3179 (region_model::impl_call_errno_location): Delete decl.
3180 (region_model::impl_call_pipe): Delete decl.
3181 (region_model::impl_call_putenv): Delete decl.
3182 (region_model::impl_call_operator_new): Delete decl.
3183 (region_model::impl_call_operator_delete): Delete decl.
3184 * sm-fd.cc: Update comments.
3186 2022-11-16 David Malcolm <dmalcolm@redhat.com>
3189 * analyzer-language.cc: Include "diagnostic.h".
3190 (maybe_stash_named_constant): Add logger param and use it to log
3191 the name being looked up, and the result.
3192 (stash_named_constants): New, splitting out from...
3193 (on_finish_translation_unit): ...this function. Call
3194 get_or_create_logfile and use the result to create a logger
3195 instance, passing it to stash_named_constants.
3196 * analyzer.h (get_or_create_any_logfile): New decl.
3197 * engine.cc (dump_fout, owns_dump_fout): New globals, split out
3199 (get_or_create_any_logfile): New function, split out from...
3200 (run_checkers): ...here, so that the logfile can be opened by
3201 on_finish_translation_unit. Clear the globals when closing the
3204 2022-11-16 David Malcolm <dmalcolm@redhat.com>
3206 * analyzer.h (known_function::matches_call_types_p): New vfunc.
3207 (known_function::impl_call_pre): Provide base implementation.
3208 (known_function::impl_call_post): New vfunc.
3209 (register_known_functions): New.
3210 * engine.cc (impl_run_checkers): Call register_known_functions.
3211 * region-model-impl-calls.cc (region_model::impl_call_accept):
3213 (class known_function_accept): ...this.
3214 (region_model::impl_call_bind): Convert to...
3215 (class known_function_bind): ...this.
3216 (region_model::impl_call_connect): Convert to...
3217 (class known_function_connect): ...this.
3218 (region_model::impl_call_listen): Convert to...
3219 (class known_function_listen): ...this.
3220 (region_model::impl_call_socket): Convert to...
3221 (class known_function_socket): ...this.
3222 (register_known_functions): New.
3223 * region-model.cc (region_model::on_call_pre): Remove special
3224 case for "bind" in favor of the known_function-handling dispatch.
3225 Add call to known_function::matches_call_types_p to latter.
3226 (region_model::on_call_post): Remove special cases for "accept",
3227 "bind", "connect", "listen", and "socket" in favor of dispatch
3228 to known_function::impl_call_post.
3229 * region-model.h (region_model::impl_call_accept): Delete decl.
3230 (region_model::impl_call_bind): Delete decl.
3231 (region_model::impl_call_connect): Delete decl.
3232 (region_model::impl_call_listen): Delete decl.
3233 (region_model::impl_call_socket): Delete decl.
3234 * sm-fd.cc: Update comments.
3236 2022-11-16 David Malcolm <dmalcolm@redhat.com>
3238 * checker-event.cc: New file, split out from...
3239 * checker-path.cc: ...this file.
3241 2022-11-15 David Malcolm <dmalcolm@redhat.com>
3244 * analyzer-language.cc (on_finish_translation_unit): Stash named
3245 constants "SOCK_STREAM" and "SOCK_DGRAM".
3246 * analyzer.opt (Wanalyzer-fd-phase-mismatch): New.
3247 (Wanalyzer-fd-type-mismatch): New.
3248 * engine.cc (impl_region_model_context::get_state_map_by_name):
3249 Add "out_sm_context" param. Allow out_sm_idx to be NULL.
3251 (impl_region_model_context::get_state_map_by_name):
3252 Add "out_sm_context" param.
3253 * region-model-impl-calls.cc (region_model::impl_call_accept): New.
3254 (region_model::impl_call_bind): New.
3255 (region_model::impl_call_connect): New.
3256 (region_model::impl_call_listen): New.
3257 (region_model::impl_call_socket): New.
3258 * region-model.cc (region_model::on_call_pre): Special-case
3260 (region_model::on_call_post): Special-case "accept", "bind",
3261 "connect", "listen", and "socket".
3262 * region-model.h (region_model::impl_call_accept): New decl.
3263 (region_model::impl_call_bind): New decl.
3264 (region_model::impl_call_connect): New decl.
3265 (region_model::impl_call_listen): New decl.
3266 (region_model::impl_call_socket): New decl.
3267 (region_model::on_socket): New decl.
3268 (region_model::on_bind): New decl.
3269 (region_model::on_listen): New decl.
3270 (region_model::on_accept): New decl.
3271 (region_model::on_connect): New decl.
3272 (region_model::add_constraint): Make public.
3273 (region_model::check_for_poison): Make public.
3274 (region_model_context::get_state_map_by_name): Add out_sm_context param.
3275 (region_model_context::get_fd_map): Likewise.
3276 (region_model_context::get_malloc_map): Likewise.
3277 (region_model_context::get_taint_map): Likewise.
3278 (noop_region_model_context::get_state_map_by_name): Likewise.
3279 (region_model_context_decorator::get_state_map_by_name): Likewise.
3280 * sm-fd.cc: Include "analyzer/supergraph.h" and
3281 "analyzer/analyzer-language.h".
3282 (enum expected_phase): New enum.
3283 (fd_state_machine::m_new_datagram_socket): New.
3284 (fd_state_machine::m_new_stream_socket): New.
3285 (fd_state_machine::m_new_unknown_socket): New.
3286 (fd_state_machine::m_bound_datagram_socket): New.
3287 (fd_state_machine::m_bound_stream_socket): New.
3288 (fd_state_machine::m_bound_unknown_socket): New.
3289 (fd_state_machine::m_listening_stream_socket): New.
3290 (fd_state_machine::m_m_connected_stream_socket): New.
3291 (fd_state_machine::m_SOCK_STREAM): New.
3292 (fd_state_machine::m_SOCK_DGRAM): New.
3293 (fd_diagnostic::describe_state_change): Handle socket states.
3294 (fd_diagnostic::get_meaning_for_state_change): Likewise.
3295 (class fd_phase_mismatch): New.
3296 (enum expected_type): New enum.
3297 (class fd_type_mismatch): New.
3298 (fd_state_machine::fd_state_machine): Initialize new states and
3299 stashed named constants.
3300 (fd_state_machine::is_socket_fd_p): New.
3301 (fd_state_machine::is_datagram_socket_fd_p): New.
3302 (fd_state_machine::is_stream_socket_fd_p): New.
3303 (fd_state_machine::on_close): Handle the socket states.
3304 (fd_state_machine::check_for_open_fd): Complain about fncalls on
3305 sockets in the wrong phase. Support socket FDs.
3306 (add_constraint_ge_zero): New.
3307 (fd_state_machine::get_state_for_socket_type): New.
3308 (fd_state_machine::on_socket): New.
3309 (fd_state_machine::check_for_socket_fd): New.
3310 (fd_state_machine::check_for_new_socket_fd): New.
3311 (fd_state_machine::on_bind): New.
3312 (fd_state_machine::on_listen): New.
3313 (fd_state_machine::on_accept): New.
3314 (fd_state_machine::on_connect): New.
3315 (fd_state_machine::can_purge_p): Don't purge socket values.
3316 (get_fd_state): New.
3317 (region_model::mark_as_valid_fd): Use get_fd_state.
3318 (region_model::on_socket): New.
3319 (region_model::on_bind): New.
3320 (region_model::on_listen): New.
3321 (region_model::on_accept): New.
3322 (region_model::on_connect): New.
3323 * sm-fd.dot: Update to reflect sm-fd.cc changes.
3325 2022-11-15 David Malcolm <dmalcolm@redhat.com>
3328 * analyzer-language.cc: New file.
3329 * analyzer-language.h: New file.
3330 * analyzer.h (get_stashed_constant_by_name): New decl.
3331 (log_stashed_constants): New decl.
3332 * engine.cc (impl_run_checkers): Call log_stashed_constants.
3333 * region-model-impl-calls.cc
3334 (region_model::impl_call_analyzer_dump_named_constant): New.
3335 * region-model.cc (region_model::on_stmt_pre): Handle
3336 __analyzer_dump_named_constant.
3338 (region_model::impl_call_analyzer_dump_named_constant): New decl.
3339 * sm-fd.cc (fd_state_machine::m_O_ACCMODE): New.
3340 (fd_state_machine::m_O_RDONLY): New.
3341 (fd_state_machine::m_O_WRONLY): New.
3342 (fd_state_machine::fd_state_machine): Initialize the new fields.
3343 (fd_state_machine::get_access_mode_from_flag): Use the new fields,
3344 rather than using the host values.
3346 2022-11-13 David Malcolm <dmalcolm@redhat.com>
3349 * analyzer.opt (Wanalyzer-tainted-assertion): New.
3350 * checker-path.cc (checker_path::fixup_locations): Pass false to
3351 pending_diagnostic::fixup_location.
3352 * diagnostic-manager.cc (get_emission_location): Pass true to
3353 pending_diagnostic::fixup_location.
3354 * pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
3356 * pending-diagnostic.h (pending_diagnostic::fixup_location): Add
3358 * sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
3359 (taint_diagnostic::describe_state_change): Drop "final".
3360 (class tainted_assertion): New.
3361 (taint_state_machine::taint_state_machine): Initialize
3362 m_tainted_control_flow.
3363 (taint_state_machine::alt_get_inherited_state): Support
3364 comparisons being tainted, based on their arguments.
3365 (is_assertion_failure_handler_p): New.
3366 (taint_state_machine::on_stmt): Complain about calls to assertion
3367 failure handlers guarded by an attacker-controller conditional.
3368 Detect attacker-controlled gcond conditionals and gswitch index
3370 (taint_state_machine::check_control_flow_arg_for_taint): New.
3372 2022-11-11 David Malcolm <dmalcolm@redhat.com>
3374 * sm-fd.dot: Fix typo in comment.
3375 * sm-file.dot: New file.
3376 * varargs.cc: Fix typo in comment.
3377 * varargs.dot: New file.
3379 2022-11-11 David Malcolm <dmalcolm@redhat.com>
3381 * checker-path.h: Split out checker_event and its subclasses to...
3382 * checker-event.h: ...this new header.
3384 2022-11-11 David Malcolm <dmalcolm@redhat.com>
3387 * analyzer.opt (Wanalyzer-infinite-recursion): New.
3388 * call-string.cc (call_string::count_occurrences_of_function):
3390 * call-string.h (call_string::count_occurrences_of_function): New
3392 * checker-path.cc (function_entry_event::function_entry_event):
3394 (checker_path::add_final_event): Delete.
3395 * checker-path.h (function_entry_event::function_entry_event): New
3397 (function_entry_event::get_desc): Drop "final".
3398 (checker_path::add_final_event): Delete.
3399 * diagnostic-manager.cc
3400 (diagnostic_manager::emit_saved_diagnostic): Create the final
3401 event via a new pending_diagnostic::add_final_event vfunc, rather
3402 than checker_path::add_final_event.
3403 (diagnostic_manager::add_events_for_eedge): Create function entry
3404 events via a new pending_diagnostic::add_function_entry_event
3406 * engine.cc (exploded_graph::process_node): When creating a new
3407 PK_BEFORE_SUPERNODE node, call
3408 exploded_graph::detect_infinite_recursion on it after adding the
3410 * exploded-graph.h (exploded_graph::detect_infinite_recursion):
3412 (exploded_graph::find_previous_entry_to): New decl.
3413 * infinite-recursion.cc: New file.
3414 * pending-diagnostic.cc
3415 (pending_diagnostic::add_function_entry_event): New.
3416 (pending_diagnostic::add_final_event): New.
3417 * pending-diagnostic.h
3418 (pending_diagnostic::add_function_entry_event): New vfunc.
3419 (pending_diagnostic::add_final_event): New vfunc.
3421 2022-11-10 David Malcolm <dmalcolm@redhat.com>
3424 * analyzer.opt (Wanalyzer-deref-before-check): New warning.
3425 * diagnostic-manager.cc
3426 (null_assignment_sm_context::set_next_state): Only add state
3427 change events for transition to "null" state.
3428 (null_assignment_sm_context::is_transition_to_null): New.
3429 * engine.cc (impl_region_model_context::on_pop_frame): New.
3430 * exploded-graph.h (impl_region_model_context::on_pop_frame): New
3432 * program-state.cc (sm_state_map::clear_any_state): New.
3433 (sm_state_map::can_merge_with_p): New.
3434 (program_state::can_merge_with_p): Replace requirement that
3435 sm-states be equal in favor of an attempt to merge them.
3436 * program-state.h (sm_state_map::clear_any_state): New decl.
3437 (sm_state_map::can_merge_with_p): New decl.
3438 * region-model.cc (region_model::eval_condition): Make const.
3439 (region_model::pop_frame): Call ctxt->on_pop_frame.
3440 * region-model.h (region_model::eval_condition): Make const.
3441 (region_model_context::on_pop_frame): New vfunc.
3442 (noop_region_model_context::on_pop_frame): New.
3443 (region_model_context_decorator::on_pop_frame): New.
3444 * sm-malloc.cc (enum resource_state): Add RS_ASSUMED_NON_NULL.
3445 (allocation_state::dump_to_pp): Drop "final".
3446 (struct assumed_non_null_state): New subclass.
3447 (malloc_state_machine::m_assumed_non_null): New.
3448 (assumed_non_null_p): New.
3449 (class deref_before_check): New.
3450 (assumed_non_null_state::dump_to_pp): New.
3451 (malloc_state_machine::get_or_create_assumed_non_null_state_for_frame):
3453 (malloc_state_machine::maybe_assume_non_null): New.
3454 (malloc_state_machine::on_stmt): Transition from start state to
3455 "assumed-non-null" state for pointers passed to
3456 __attribute__((nonnull)) arguments, and for pointers explicitly
3457 dereferenced. Call maybe_complain_about_deref_before_check for
3458 pointers explicitly compared against NULL.
3459 (malloc_state_machine::maybe_complain_about_deref_before_check):
3461 (malloc_state_machine::on_deallocator_call): Also transition
3462 "assumed-non-null" states to "freed".
3463 (malloc_state_machine::on_pop_frame): New.
3464 (malloc_state_machine::maybe_get_merged_states_nonequal): New.
3465 * sm-malloc.dot: Update for changes to sm-malloc.cc.
3466 * sm.h (state_machine::on_pop_frame): New.
3467 (state_machine::maybe_get_merged_state): New.
3468 (state_machine::maybe_get_merged_states_nonequal): New.
3470 2022-11-09 David Malcolm <dmalcolm@redhat.com>
3472 * checker-path.cc (checker_event::debug): New.
3473 (checker_path::add_event): Move here from checker-path.h. Add
3475 * checker-path.h (checker_event::debug): New decl.
3476 (checker_path::checker_path): Add logger param.
3477 (checker_path::add_event): Move definition from here to
3479 (checker_path::m_logger): New field.
3480 * diagnostic-manager.cc
3481 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
3483 (diagnostic_manager::add_events_for_eedge): Log scope when
3484 processing a run of stmts.
3486 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3489 * region-model-impl-calls.cc: Update comment.
3490 * region-model.cc (region_model::check_symbolic_bounds): Fix
3491 layout of "void" return. Replace usage of
3492 eval_condition_without_cm with eval_condition.
3493 (region_model::eval_condition): Take over body of...
3494 (region_model::eval_condition_without_cm): ...this subroutine,
3495 dropping the latter. Eliminating this distinction avoids issues
3496 where constraints were not considered when recursing.
3497 (region_model::compare_initial_and_pointer): Update comment.
3498 (region_model::symbolic_greater_than): Replace usage of
3499 eval_condition_without_cm with eval_condition.
3501 (region_model::eval_condition_without_cm): Delete decl.
3503 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3505 * region-model-impl-calls.cc
3506 (region_model::impl_call_errno_location): New.
3507 * region-model-manager.cc
3508 (region_model_manager::region_model_manager): Initialize
3509 m_thread_local_region and m_errno_region.
3510 * region-model-manager.h (region_model_manager::get_errno_region):
3512 (region_model_manager::m_thread_local_region): New.
3513 (region_model_manager::m_errno_region): New.
3514 * region-model.cc (region_model::on_call_pre): Special-case
3516 (region_model::set_errno): New.
3517 * region-model.h (impl_call_errno_location): New decl.
3518 (region_model::set_errno): New decl.
3519 * region.cc (thread_local_region::dump_to_pp): New.
3520 (errno_region::dump_to_pp): New.
3521 * region.h (enum memory_space): Add MEMSPACE_THREAD_LOCAL.
3522 (enum region_kind): Add RK_THREAD_LOCAL and RK_ERRNO.
3523 (class thread_local_region): New.
3524 (is_a_helper <const thread_local_region *>::test): New.
3525 (class errno_region): New.
3526 (is_a_helper <const errno_region *>::test): New.
3527 * store.cc (binding_cluster::escaped_p): New.
3528 (store::escaped_p): Treat errno as always having escaped.
3529 (store::replay_call_summary_cluster): Handle RK_THREAD_LOCAL and
3531 * store.h (binding_cluster::escaped_p): Remove definition.
3533 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3535 * call-info.cc (success_call_info::get_desc): Delete.
3536 (failed_call_info::get_desc): Likewise.
3537 (succeed_or_fail_call_info::get_desc): New.
3538 * call-info.h (class succeed_or_fail_call_info): New.
3539 (class success_call_info): Convert to a subclass of
3540 succeed_or_fail_call_info.
3541 (class failed_call_info): Likewise.
3543 2022-11-08 David Malcolm <dmalcolm@redhat.com>
3545 * region-model-impl-calls.cc (region_model::impl_call_strchr):
3546 Move to on_call_post. Handle both outcomes using bifurcation,
3547 rather than just the "not found" case.
3548 * region-model.cc (region_model::on_call_pre): Move
3549 BUILT_IN_STRCHR and "strchr" to...
3550 (region_model::on_call_post): ...here.
3552 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3554 * analyzer.h: Use std::unique_ptr for state machines from plugins.
3555 * engine.cc: Likewise.
3557 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3559 * analyzer.h: Use std::unique_ptr for known functions.
3560 * engine.cc: Likewise.
3561 * known-function-manager.cc: Likewise.
3562 * known-function-manager.h: Likewise.
3564 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3566 * analysis-plan.cc: Define INCLUDE_MEMORY before including
3568 * analyzer-pass.cc: Likewise.
3569 * analyzer-selftests.cc: Likewise.
3570 * analyzer.cc: Likewise.
3571 * analyzer.h: Use std::unique_ptr in bifurcation code.
3572 * call-string.cc: Define INCLUDE_MEMORY before including system.h.
3573 * complexity.cc: Likewise.
3574 * engine.cc: Use std::unique_ptr in bifurcation code.
3575 * exploded-graph.h: Likewise.
3576 * known-function-manager.cc: Define INCLUDE_MEMORY before
3578 * region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
3580 * region-model.cc: Likewise.
3581 * region-model.h: Likewise.
3582 * supergraph.cc: Define INCLUDE_MEMORY before including system.h.
3584 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3586 * call-info.cc: Use std::unique_ptr for checker_event.
3587 * checker-path.cc: Likewise.
3588 * checker-path.h: Likewise.
3589 * diagnostic-manager.cc: Likewise.
3590 * engine.cc: Likewise.
3591 * pending-diagnostic.cc: Likewise.
3592 * sm-signal.cc: Likewise.
3593 * varargs.cc: Likewise.
3595 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3597 * diagnostic-manager.cc: Include "make-unique.h".
3598 Use std::unique_ptr for feasibility_problems and exploded_path.
3599 Delete explicit saved_diagnostic dtor.
3600 * diagnostic-manager.h: Likewise.
3601 * engine.cc: Likewise.
3602 * exploded-graph.h: Likewise.
3603 * feasible-graph.cc: Likewise.
3604 * feasible-graph.h: Likewise.
3606 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3608 * checker-path.cc (rewind_event::rewind_event): Update for usage of
3609 std::unique_ptr on custom_edge_info.
3610 * engine.cc (exploded_node::on_longjmp): Likewise.
3611 (exploded_edge::exploded_edge): Likewise.
3612 (exploded_edge::~exploded_edge): Delete.
3613 (exploded_graph::add_function_entry): Update for usage of
3614 std::unique_ptr on custom_edge_info.
3615 (exploded_graph::add_edge): Likewise.
3616 (add_tainted_args_callback): Likewise.
3617 (exploded_graph::maybe_create_dynamic_call): Likewise.
3618 (exploded_graph::process_node): Likewise.
3619 * exploded-graph.h (exploded_edge::~exploded_edge): Delete.
3620 (exploded_edge::m_custom_info): Use std::unique_ptr.
3621 (exploded_edge::add_edge): Likewise.
3622 * sm-signal.cc (register_signal_handler::impl_transition): Use
3625 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3627 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Make
3629 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of
3631 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
3632 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
3634 (saved_diagnostic::m_stmt_finder): Convert to std::unique_ptr.
3635 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
3636 * engine.cc (impl_sm_context::impl_sm_context): Likewise.
3637 (impl_sm_context::m_stmt_finder): Likewise.
3638 (leak_stmt_finder::clone): Convert return type to std::unique_ptr.
3639 * exploded-graph.h (stmt_finder::clone): Likewise.
3641 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3643 * call-info.cc: Add define of INCLUDE_MEMORY.
3644 * call-summary.cc: Likewise.
3645 * checker-path.cc: Likewise.
3646 * constraint-manager.cc: Likewise.
3647 * diagnostic-manager.cc: Likewise.
3648 (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for
3649 param d and field m_d.
3650 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d.
3651 (saved_diagnostic::add_note): Use std::unique_ptr for
3653 (saved_diagnostic::get_pending_diagnostic): Update for conversion
3654 of m_sd.m_d to unique_ptr.
3655 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
3656 param d. Remove explicit deletion.
3657 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
3658 (diagnostic_manager::emit_saved_diagnostic): Update for conversion
3659 of m_sd.m_d to unique_ptr.
3660 (null_assignment_sm_context::warn): Use std::unique_ptr for
3661 param d. Remove explicit deletion.
3662 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use
3663 std::unique_ptr for param d.
3664 (saved_diagnostic::add_note): Likewise for param pn.
3665 (saved_diagnostic::m_d): Likewise.
3666 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
3668 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
3669 * engine.cc: Include "make-unique.h".
3670 (impl_region_model_context::warn): Update to use std::unique_ptr
3671 for param, removing explicit deletion.
3672 (impl_region_model_context::add_note): Likewise.
3673 (impl_sm_context::warn): Update to use std::unique_ptr
3675 (impl_region_model_context::on_state_leak): Likewise for result of
3677 (exploded_node::on_longjmp): Use make_unique when creating
3679 (exploded_graph::process_node): Likewise.
3680 * exploded-graph.h (impl_region_model_context::warn): Update to
3681 use std::unique_ptr for param.
3682 (impl_region_model_context::add_note): Likewise.
3683 * feasible-graph.cc: Add define of INCLUDE_MEMORY.
3684 * pending-diagnostic.cc: Likewise.
3685 * pending-diagnostic.h: Include analyzer.sm.h"
3686 * program-point.cc: Add define of INCLUDE_MEMORY.
3687 * program-state.cc: Likewise.
3688 * region-model-asm.cc: Likewise.
3689 * region-model-impl-calls.cc: Likewise. Include "make-unique.h".
3690 (region_model::impl_call_putenv): Use make_unique when creating
3692 * region-model-manager.cc: Add define of INCLUDE_MEMORY.
3693 * region-model-reachability.cc: Likewise.
3694 * region-model.cc: Likewise. Include "make-unique.h".
3695 (region_model::get_gassign_result): Use make_unique when creating
3697 (region_model::check_for_poison): Likewise.
3698 (region_model::on_stmt_pre): Likewise.
3699 (region_model::check_symbolic_bounds): Likewise.
3700 (region_model::check_region_bounds): Likewise.
3701 (annotating_ctxt: make_note): Use std::unique_ptr for result.
3702 (region_model::deref_rvalue): Use make_unique when creating
3704 (region_model::check_for_writable_region): Likewise.
3705 (region_model::check_region_size): Likewise.
3706 (region_model::check_dynamic_size_for_floats): Likewise.
3707 (region_model::maybe_complain_about_infoleak): Likewise.
3708 (noop_region_model_context::add_note): Use std::unique_ptr for
3709 param. Remove explicit deletion.
3710 * region-model.h: Include "analyzer/pending-diagnostic.h".
3711 (region_model_context::warn): Convert param to std::unique_ptr.
3712 (region_model_context::add_note): Likewise.
3713 (noop_region_model_context::warn): Likewise.
3714 (noop_region_model_context::add_note): Likewise.
3715 (region_model_context_decorator::warn): Likewise.
3716 (region_model_context_decorator::add_note): Likewise.
3717 (note_adding_context::warn): Likewise.
3718 (note_adding_context::make_note): Likewise for return type.
3719 (test_region_model_context::warn): Convert param to
3721 * region.cc: Add define of INCLUDE_MEMORY.
3722 * sm-fd.cc: Likewise. Include "make-unique.h".
3723 (fd_state_machine::check_for_fd_attrs): Use make_unique when
3724 creating pending_diagnostics.
3725 (fd_state_machine::on_open): Likewise.
3726 (fd_state_machine::on_creat): Likewise.
3727 (fd_state_machine::check_for_dup): Likewise.
3728 (fd_state_machine::on_close): Likewise.
3729 (fd_state_machine::check_for_open_fd): Likewise.
3730 (fd_state_machine::on_leak): Likewise, converting return type to
3732 * sm-file.cc: Add define of INCLUDE_MEMORY. Include
3734 (fileptr_state_machine::on_stmt): Use make_unique when creating
3736 (fileptr_state_machine::on_leak): Likewise, converting return type
3738 * sm-malloc.cc: Add define of INCLUDE_MEMORY. Include
3740 (malloc_state_machine::on_stmt): Use make_unique when creating
3742 (malloc_state_machine::handle_free_of_non_heap): Likewise.
3743 (malloc_state_machine::on_deallocator_call): Likewise.
3744 (malloc_state_machine::on_realloc_call): Likewise.
3745 (malloc_state_machine::on_leak): Likewise, converting return type
3747 * sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include
3749 (pattern_test_state_machine::on_condition): Use make_unique when
3750 creating pending_diagnostic.
3751 * sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include
3753 (sensitive_state_machine::warn_for_any_exposure): Use make_unique
3754 when creating pending_diagnostic.
3755 * sm-signal.cc: Add define of INCLUDE_MEMORY. Include
3757 (signal_state_machine::on_stmt): Use make_unique when creating
3759 * sm-taint.cc: Add define of INCLUDE_MEMORY. Include
3761 (taint_state_machine::check_for_tainted_size_arg): Use make_unique
3762 when creating pending_diagnostic.
3763 (taint_state_machine::check_for_tainted_divisor): Likewise.
3764 (region_model::check_region_for_taint): Likewise.
3765 (region_model::check_dynamic_size_for_taint): Likewise.
3766 * sm.cc: Add define of INCLUDE_MEMORY. Include
3767 "analyzer/pending-diagnostic.h".
3768 (state_machine::on_leak): Move here from sm.h, changing return
3769 type to std::unique_ptr.
3770 * sm.h (state_machine::on_leak): Change return type to
3771 std::unique_ptr. Move defn of base impl to sm.cc
3772 (sm_context::warn): Convert param d to std_unique_ptr.
3773 * state-purge.cc: Add define of INCLUDE_MEMORY.
3774 * store.cc: Likewise.
3775 * svalue.cc: Likewise.
3776 * trimmed-graph.cc: Likewise.
3777 * varargs.cc: Likewise. Include "make-unique.h".
3778 (va_list_state_machine::check_for_ended_va_list): Use make_unique
3779 when creating pending_diagnostic.
3780 (va_list_state_machine::on_leak): Likewise, converting return type
3782 (region_model::impl_call_va_arg): Use make_unique when creating
3785 2022-11-03 David Malcolm <dmalcolm@redhat.com>
3788 * analyzer.cc (is_pipe_call_p): New.
3789 * analyzer.h (is_pipe_call_p): New decl.
3790 * region-model.cc (region_model::on_call_pre): Use it.
3791 (region_model::on_call_post): Likewise.
3793 2022-10-26 David Malcolm <dmalcolm@redhat.com>
3795 * sm-fd.cc (fd_state_machine::on_open): Transition to "unchecked"
3796 when the mode is symbolic, rather than just on integer constants.
3797 (fd_state_machine::check_for_open_fd): Don't complain about
3798 unchecked values in the start state.
3800 2022-10-26 David Malcolm <dmalcolm@redhat.com>
3802 * sm-fd.dot: New file.
3804 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3807 * varargs.cc (get_va_copy_arg): Fix the non-pointer case.
3809 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3812 * region-model.cc (region_model::eval_condition_without_cm):
3813 Ensure that constants are on the right-hand side before checking
3816 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3818 * engine.cc (impl_region_model_context::get_malloc_map): Replace
3820 (impl_region_model_context::get_state_map_by_name): ...this.
3821 (impl_region_model_context::get_fd_map): Delete.
3822 (impl_region_model_context::get_taint_map): Delete.
3823 * exploded-graph.h (impl_region_model_context::get_fd_map):
3825 (impl_region_model_context::get_malloc_map): Delete.
3826 (impl_region_model_context::get_taint_map): Delete.
3827 (impl_region_model_context::get_state_map_by_name): New.
3828 * region-model.h (region_model_context::get_state_map_by_name):
3830 (region_model_context::get_fd_map): Convert from vfunc to
3832 (region_model_context::get_malloc_map): Likewise.
3833 (region_model_context::get_taint_map): Likewise.
3834 (noop_region_model_context::get_state_map_by_name): New.
3835 (noop_region_model_context::get_fd_map): Delete.
3836 (noop_region_model_context::get_malloc_map): Delete.
3837 (noop_region_model_context::get_taint_map): Delete.
3838 (region_model_context_decorator::get_state_map_by_name): New.
3839 (region_model_context_decorator::get_fd_map): Delete.
3840 (region_model_context_decorator::get_malloc_map): Delete.
3841 (region_model_context_decorator::get_taint_map): Delete.
3843 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3846 * engine.cc (impl_region_model_context::get_fd_map): New.
3847 * exploded-graph.h (impl_region_model_context::get_fd_map): New
3849 * region-model-impl-calls.cc (region_model::impl_call_pipe): New.
3850 * region-model.cc (region_model::update_for_int_cst_return): New,
3852 (region_model::update_for_zero_return): ...this. Reimplement in
3853 terms of the former.
3854 (region_model::on_call_pre): Handle "pipe" and "pipe2".
3855 (region_model::on_call_post): Likewise.
3856 * region-model.h (region_model::impl_call_pipe): New decl.
3857 (region_model::update_for_int_cst_return): New decl.
3858 (region_model::mark_as_valid_fd): New decl.
3859 (region_model_context::get_fd_map): New pure virtual fn.
3860 (noop_region_model_context::get_fd_map): New.
3861 (region_model_context_decorator::get_fd_map): New.
3862 * sm-fd.cc: Include "analyzer/program-state.h".
3863 (fd_state_machine::describe_state_change): Handle transitions from
3864 start state to valid states.
3865 (fd_state_machine::mark_as_valid_fd): New.
3866 (fd_state_machine::on_stmt): Add missing return for "creat".
3867 (region_model::mark_as_valid_fd): New.
3869 2022-10-19 David Malcolm <dmalcolm@redhat.com>
3872 * varargs.cc (get_BT_VALIST_ARG): Rename to...
3873 (get_va_copy_arg): ...this, and update logic for determining level
3874 of indirection of va_copy's argument to use type of argument,
3875 rather than looking at va_list_type_node, to correctly handle
3876 __builtin_ms_va_copy.
3877 (get_stateful_BT_VALIST_ARG): Rename to...
3878 (get_stateful_va_copy_arg): ...this.
3879 (va_list_state_machine::on_va_copy): Update for renaming.
3880 (region_model::impl_call_va_copy): Likewise.
3882 2022-10-13 David Malcolm <dmalcolm@redhat.com>
3885 * svalue.cc (constant_svalue::maybe_fold_bits_within): Only
3886 attempt to extract individual bits when tree_fits_uhwi_p.
3888 2022-10-07 David Malcolm <dmalcolm@redhat.com>
3891 * region-model.cc (selftest::get_bit): New function.
3892 (selftest::test_bits_within_svalue_folding): New.
3893 (selfftest::analyzer_region_model_cc_tests): Call it.
3894 * svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
3895 case of extracting a single bit.
3897 2022-10-06 David Malcolm <dmalcolm@redhat.com>
3900 * store.cc (store::replay_call_summary_cluster): Eliminate
3901 special-casing of RK_HEAP_ALLOCATED in favor of sharing code with
3902 RK_DECL, avoiding an ICE due to attempting to bind a
3903 compound_svalue into a binding_cluster when an svalue in the
3904 summary cluster converts to a compound_svalue in the caller.
3906 2022-10-06 David Malcolm <dmalcolm@redhat.com>
3908 * call-summary.cc (call_summary_replay::dump_to_pp): Bulletproof
3909 against NULL caller regions/svalues.
3911 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3913 * analysis-plan.cc: Simplify includes.
3914 * analyzer-pass.cc: Likewise.
3915 * analyzer-selftests.cc: Likewise.
3916 * analyzer.cc: Likewise.
3917 * analyzer.h: Add includes of "json.h" and "tristate.h".
3918 * call-info.cc: Simplify includes.
3919 * call-string.cc: Likewise.
3920 * call-summary.cc: Likewise.
3921 * checker-path.cc: Likewise.
3922 * complexity.cc: Likewise.
3923 * constraint-manager.cc: Likewise.
3924 * diagnostic-manager.cc: Likewise.
3925 * engine.cc: Likewise.
3926 * feasible-graph.cc: Likewise.
3927 * known-function-manager.cc: Likewise.
3928 * pending-diagnostic.cc: Likewise.
3929 * program-point.cc: Likewise.
3930 * program-state.cc: Likewise.
3931 * region-model-asm.cc: Likewise.
3932 * region-model-impl-calls.cc: Likewise.
3933 * region-model-manager.cc: Likewise.
3934 * region-model-reachability.cc: Likewise.
3935 * region-model.cc: Likewise.
3936 * region-model.h: Include "selftest.h".
3937 * region.cc: Simplify includes.
3938 * sm-fd.cc: Likewise.
3939 * sm-file.cc: Likewise.
3940 * sm-malloc.cc: Likewise.
3941 * sm-pattern-test.cc: Likewise.
3942 * sm-sensitive.cc: Likewise.
3943 * sm-signal.cc: Likewise.
3944 * sm-taint.cc: Likewise.
3946 * state-purge.cc: Likewise.
3947 * store.cc: Likewise.
3948 * store.h: Likewise.
3949 * supergraph.cc: Likewise.
3950 * svalue.cc: Likewise.
3951 * svalue.h: Likewise.
3952 * trimmed-graph.cc: Likewise.
3953 * varargs.cc: Likewise.
3955 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3959 (call_summary_replay::convert_svalue_from_summary_1): Handle NULL
3960 results from convert_svalue_from_summary in SK_UNARY_OP and
3962 * engine.cc (impl_region_model_context::on_unknown_change): Bail
3963 out on svalues that can't have associated state.
3964 * region-model-impl-calls.cc
3965 (region_model::impl_call_analyzer_get_unknown_ptr): New.
3966 * region-model.cc (region_model::on_stmt_pre): Handle
3967 "__analyzer_get_unknown_ptr".
3969 (region_model::impl_call_analyzer_get_unknown_ptr): New decl.
3970 * store.cc (store::replay_call_summary_cluster): Avoid trying to
3971 create binding clusters for base regions that shouldn't have them.
3973 2022-10-05 Martin Liska <mliska@suse.cz>
3975 * call-summary.cc (call_summary_replay::call_summary_replay):
3976 Remove unused variable and arguments.
3977 * call-summary.h: Likewise.
3978 * engine.cc (exploded_node::on_stmt): Likewise.
3979 (exploded_node::replay_call_summaries): Likewise.
3980 (exploded_node::replay_call_summary): Likewise.
3981 * exploded-graph.h (class exploded_node): Likewise.
3983 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3986 * analyzer-logging.h: Include "diagnostic-core.h".
3987 * analyzer.h: Include "function.h".
3988 (class call_summary): New forward decl.
3989 (class call_summary_replay): New forward decl.
3990 (struct per_function_data): New forward decl.
3991 (struct interesting_t): New forward decl.
3992 (custom_edge_info::update_state): New vfunc.
3993 * call-info.cc (custom_edge_info::update_state): New.
3994 * call-summary.cc: New file.
3995 * call-summary.h: New file.
3996 * constraint-manager.cc: Include "analyzer/call-summary.h".
3997 (class replay_fact_visitor): New.
3998 (constraint_manager::replay_call_summary): New.
3999 * constraint-manager.h (constraint_manager::replay_call_summary):
4001 * engine.cc: Include "analyzer/call-summary.h".
4002 (exploded_node::on_stmt): Handle call summaries.
4003 (class call_summary_edge_info): New.
4004 (exploded_node::replay_call_summaries): New.
4005 (exploded_node::replay_call_summary): New.
4006 (per_function_data::~per_function_data): New.
4007 (per_function_data::add_call_summary): Move here from header and
4009 (exploded_graph::process_node): Call update_state rather than
4010 update_model when handling bifurcation
4011 (viz_callgraph_node::dump_dot): Use a regular label rather
4012 than an HTML table; add summaries to dump.
4013 * exploded-graph.h: Include "alloc-pool.h", "fibonacci_heap.h",
4014 "supergraph.h", "sbitmap.h", "shortest-paths.h", "analyzer/sm.h",
4015 "analyzer/program-state.h", and "analyzer/diagnostic-manager.h".
4016 (exploded_node::replay_call_summaries): New decl.
4017 (exploded_node::replay_call_summary): New decl.
4018 (per_function_data::~per_function_data): New decl.
4019 (per_function_data::add_call_summary): Move implemention from
4021 (per_function_data::m_summaries): Update type of element.
4022 * known-function-manager.h: Include "analyzer/analyzer-logging.h".
4023 * program-point.h: Include "pretty-print.h" and
4024 "analyzer/call-string.h".
4025 * program-state.cc: Include "analyzer/call-summary.h".
4026 (sm_state_map::replay_call_summary): New.
4027 (program_state::replay_call_summary): New.
4028 * program-state.h (sm_state_map::replay_call_summary): New decl.
4029 (program_state::replay_call_summary): New decl.
4030 * region-model-manager.cc
4031 (region_model_manager::get_or_create_asm_output_svalue): New
4033 * region-model-manager.h
4034 (region_model_manager::get_or_create_asm_output_svalue): New
4036 * region-model.cc: Include "analyzer/call-summary.h".
4037 (region_model::maybe_update_for_edge): Remove call to
4038 region_model::update_for_call_summary on
4039 SUPEREDGE_INTRAPROCEDURAL_CALL.
4040 (region_model::update_for_call_summary): Delete.
4041 (region_model::replay_call_summary): New.
4042 * region-model.h (region_model::replay_call_summary): New decl.
4043 (region_model::update_for_call_summary): Delete decl.
4044 * store.cc: Include "analyzer/call-summary.h".
4045 (store::replay_call_summary): New.
4046 (store::replay_call_summary_cluster): New.
4047 * store.h: Include "tristate.h".
4048 (is_a_helper <const ana::concrete_binding *>::test): New.
4049 (store::replay_call_summary): New decl.
4050 (store::replay_call_summary_cluster): New decl.
4051 * supergraph.cc (get_ultimate_function_for_cgraph_edge): Remove
4053 (supergraph_call_edge): Make stmt param const.
4054 * supergraph.h: Include "ordered-hash-map.h", "cfg.h",
4055 "basic-block.h", "gimple.h", "gimple-iterator.h", and "digraph.h".
4056 (supergraph_call_edge): Make stmt param const.
4057 (get_ultimate_function_for_cgraph_edge): New decl.
4058 * svalue.cc (compound_svalue::compound_svalue): Assert that we're
4059 not nesting compound_svalues.
4060 * svalue.h: Include "json.h", "analyzer/store.h", and
4061 "analyzer/program-point.h".
4062 (asm_output_svalue::get_num_outputs): New accessor.
4064 2022-10-05 David Malcolm <dmalcolm@redhat.com>
4066 * region-model.h: Include "analyzer/region-model-manager.h"
4067 (class region_model_manager): Move decl to...
4068 * region-model-manager.h: ...this new file.
4070 2022-10-05 David Malcolm <dmalcolm@redhat.com>
4072 * region-model-manager.cc
4073 (region_model_manager::maybe_fold_unaryop): Fold -(-(VAL)) to VAL.
4075 2022-10-05 David Malcolm <dmalcolm@redhat.com>
4077 * region-model-manager.cc
4078 (region_model_manager::get_or_create_widening_svalue): Use a
4079 function_point rather than a program_point.
4080 * region-model.cc (selftest::test_widening_constraints): Likewise.
4082 (region_model_manager::get_or_create_widening_svalue): Likewise.
4083 (model_merger::get_function_point): New.
4084 * svalue.cc (svalue::can_merge_p): Use a function_point rather
4085 than a program_point.
4086 (svalue::can_merge_p): Likewise.
4087 * svalue.h (widening_svalue::key_t): Likewise.
4088 (widening_svalue::widening_svalue): Likewise.
4090 2022-09-12 Martin Liska <mliska@suse.cz>
4092 * region-model.cc (region_model::maybe_complain_about_infoleak):
4093 Remove unused fields.
4095 2022-09-11 Tim Lange <mail@tim-lange.me>
4098 * region-model.cc (region_model::check_region_bounds):
4099 Bail out if 0 bytes were accessed.
4100 * store.cc (byte_range::dump_to_pp):
4101 Add special case for empty ranges.
4102 (byte_range::exceeds_p): Restrict to non-empty ranges.
4103 (byte_range::falls_short_of_p): Restrict to non-empty ranges.
4104 * store.h (bit_range::empty_p): New function.
4105 (bit_range::get_last_byte_offset): Restrict to non-empty ranges.
4106 (byte_range::empty_p): New function.
4107 (byte_range::get_last_byte_offset): Restrict to non-empty ranges.
4109 2022-09-09 David Malcolm <dmalcolm@redhat.com>
4111 * analyzer.opt (Wanalyzer-exposure-through-uninit-copy): New.
4112 * checker-path.cc (region_creation_event::region_creation_event):
4113 Add "capacity" and "kind" params.
4114 (region_creation_event::get_desc): Generalize to different kinds
4116 (checker_path::add_region_creation_event): Convert to...
4117 (checker_path::add_region_creation_events): ...this.
4118 * checker-path.h (enum rce_kind): New.
4119 (region_creation_event::region_creation_event): Add "capacity" and
4121 (region_creation_event::m_capacity): New field.
4122 (region_creation_event::m_rce_kind): New field.
4123 (checker_path::add_region_creation_event): Convert to...
4124 (checker_path::add_region_creation_events): ...this.
4125 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
4126 Update for multiple region creation events.
4127 (diagnostic_manager::add_event_on_final_node): Likewise.
4128 (diagnostic_manager::add_events_for_eedge): Likewise.
4129 * region-model-impl-calls.cc (call_details::get_logger): New.
4130 * region-model.cc: Define INCLUDE_MEMORY before including
4131 "system.h". Include "gcc-rich-location.h".
4132 (class record_layout): New.
4133 (class exposure_through_uninit_copy): New.
4134 (contains_uninit_p): New.
4135 (region_model::maybe_complain_about_infoleak): New.
4136 * region-model.h (call_details::get_logger): New decl.
4137 (region_model::maybe_complain_about_infoleak): New decl.
4138 (region_model::mark_as_tainted): New decl.
4139 * sm-taint.cc (region_model::mark_as_tainted): New.
4141 2022-09-09 David Malcolm <dmalcolm@redhat.com>
4143 * analyzer.h (class known_function_manager): New forward decl.
4144 (class known_function): New.
4145 (plugin_analyzer_init_iface::register_known_function): New.
4146 * engine.cc: Include "analyzer/known-function-manager.h".
4147 (plugin_analyzer_init_impl::plugin_analyzer_init_impl): Add
4149 (plugin_analyzer_init_impl::register_state_machine): Add
4151 (plugin_analyzer_init_impl::register_known_function): New.
4152 (plugin_analyzer_init_impl::m_known_fn_mgr): New.
4153 (impl_run_checkers): Update plugin callback invocation to use
4154 eng's known_function_manager.
4155 * known-function-manager.cc: New file.
4156 * known-function-manager.h: New file.
4157 * region-model-manager.cc
4158 (region_model_manager::region_model_manager): Pass logger to
4159 m_known_fn_mgr's ctor.
4160 * region-model.cc (region_model::update_for_zero_return): New.
4161 (region_model::update_for_nonzero_return): New.
4162 (maybe_simplify_upper_bound): New.
4163 (region_model::maybe_get_copy_bounds): New.
4164 (region_model::get_known_function): New.
4165 (region_model::on_call_pre): Handle plugin-supplied known
4167 * region-model.h: Include "analyzer/known-function-manager.h".
4168 (region_model_manager::get_known_function_manager): New.
4169 (region_model_manager::m_known_fn_mgr): New.
4170 (call_details::get_model): New accessor.
4171 (region_model::maybe_get_copy_bounds): New decl.
4172 (region_model::update_for_zero_return): New decl.
4173 (region_model::update_for_nonzero_return): New decl.
4174 (region_model::get_known_function): New decl.
4175 (region_model::get_known_function_manager): New.
4177 2022-09-08 Tim Lange <mail@tim-lange.me>
4180 * analyzer.h (region_offset): Eliminate m_is_symbolic member.
4181 * region-model-impl-calls.cc (region_model::impl_call_realloc):
4182 Refine implementation to be more precise.
4183 * region-model.cc (class symbolic_past_the_end):
4184 Abstract diagnostic class to complain about accesses past the end
4185 with symbolic values.
4186 (class symbolic_buffer_overflow):
4187 Concrete diagnostic class to complain about buffer overflows with
4189 (class symbolic_buffer_overread):
4190 Concrete diagnostic class to complain about buffer overreads with
4192 (region_model::check_symbolic_bounds): New function.
4193 (maybe_get_integer_cst_tree): New helper function.
4194 (region_model::check_region_bounds):
4195 Add call to check_symbolic_bounds if offset is not concrete.
4196 (region_model::eval_condition_without_cm):
4197 Add support for EQ_EXPR and GT_EXPR with binaryop_svalues.
4198 (is_positive_svalue): New hleper function.
4199 (region_model::symbolic_greater_than):
4200 New function to handle GT_EXPR comparisons with symbolic values.
4201 (region_model::structural_equality): New function to compare
4202 whether two svalues are structured the same, i.e. evaluate to
4204 (test_struct): Reflect changes to region::calc_offset.
4205 (test_var): Likewise.
4206 (test_array_2): Likewise and add selftest with symbolic i.
4207 * region-model.h (class region_model): Add check_symbolic_bounds,
4208 symbolic_greater_than and structural_equality.
4209 * region.cc (region::get_offset):
4210 Reflect changes to region::calc_offset.
4211 (region::calc_offset):
4212 Compute the symbolic offset if the offset is not concrete.
4213 (region::get_relative_symbolic_offset): New function to return the
4214 symbolic offset in bytes relative to its parent.
4215 (field_region::get_relative_symbolic_offset): Likewise.
4216 (element_region::get_relative_symbolic_offset): Likewise.
4217 (offset_region::get_relative_symbolic_offset): Likewise.
4218 (bit_range_region::get_relative_symbolic_offset): Likewise.
4219 * region.h: Add get_relative_symbolic_offset.
4220 * store.cc (binding_key::make):
4221 Reflect changes to region::calc_offset.
4222 (binding_map::apply_ctor_val_to_range): Likewise.
4223 (binding_map::apply_ctor_pair_to_child_region): Likewise.
4224 (binding_cluster::bind_compound_sval): Likewise.
4225 (binding_cluster::get_any_binding): Likewise.
4226 (binding_cluster::maybe_get_compound_binding): Likewise.
4228 2022-09-05 Tim Lange <mail@tim-lange.me>
4230 * region-model-impl-calls.cc (region_model::impl_call_strcpy):
4231 Handle the constant string case.
4232 * region-model.cc (region_model::get_string_size):
4233 New function to get the string size from a region or svalue.
4234 * region-model.h (class region_model): Add get_string_size.
4236 2022-09-05 Tim Lange <mail@tim-lange.me>
4238 * region.cc (cast_region::get_relative_concrete_offset):
4239 New overloaded method.
4240 * region.h: Add cast_region::get_relative_concrete_offset.
4242 2022-08-22 Martin Liska <mliska@suse.cz>
4244 * region-model.cc: Add missing final keyword.
4246 2022-08-18 Tim Lange <mail@tim-lange.me>
4249 * analyzer.opt: Add Wanalyzer-imprecise-floating-point-arithmetic.
4250 * region-model.cc (is_any_cast_p): Formatting.
4251 (region_model::check_region_size): Ensure precondition.
4252 (class imprecise_floating_point_arithmetic): New abstract
4253 diagnostic class for all floating-point related warnings.
4254 (class float_as_size_arg): Concrete diagnostic class to complain
4255 about floating-point operands inside the size argument.
4256 (class contains_floating_point_visitor):
4257 New visitor to find floating-point operands inside svalues.
4258 (region_model::check_dynamic_size_for_floats): New function.
4259 (region_model::set_dynamic_extents):
4260 Call to check_dynamic_size_for_floats.
4261 * region-model.h (class region_model):
4262 Add region_model::check_dynamic_size_for_floats.
4264 2022-08-16 Martin Liska <mliska@suse.cz>
4266 * region-model.cc: Fix -Winconsistent-missing-override clang
4268 * region.h: Likewise.
4270 2022-08-15 David Malcolm <dmalcolm@redhat.com>
4273 * region-model.cc (buffer_overread::emit): Fix copy&paste error in
4274 direction of the access in the note.
4276 2022-08-15 David Malcolm <dmalcolm@redhat.com>
4279 * region-model.cc (region_model::on_call_pre): Use check_call_args
4280 when ensuring that we call get_arg_svalue on all args. Remove
4281 redundant call from handling for stdio builtins.
4283 2022-08-15 Immad Mir <mirimmad@outlook.com>
4286 * sm-fd.cc (check_for_dup): exit early if first
4287 argument is invalid for all dup functions.
4289 2022-08-12 Tim Lange <mail@tim-lange.me>
4292 * analyzer.opt: Add Wanalyzer-out-of-bounds.
4293 * region-model.cc (class out_of_bounds): Diagnostics base class
4294 for all out-of-bounds diagnostics.
4295 (class past_the_end): Base class derived from out_of_bounds for
4296 the buffer_overflow and buffer_overread diagnostics.
4297 (class buffer_overflow): Buffer overflow diagnostics.
4298 (class buffer_overread): Buffer overread diagnostics.
4299 (class buffer_underflow): Buffer underflow diagnostics.
4300 (class buffer_underread): Buffer overread diagnostics.
4301 (region_model::check_region_bounds): New function to check region
4302 bounds for out-of-bounds accesses.
4303 (region_model::check_region_access):
4304 Add call to check_region_bounds.
4305 (region_model::get_representative_tree): New function that accepts
4306 a region instead of an svalue.
4307 * region-model.h (class region_model):
4308 Add region_model::check_region_bounds.
4309 * region.cc (region::symbolic_p): New predicate.
4310 (offset_region::get_byte_size_sval): Only return the remaining
4311 byte size on offset_regions.
4312 * region.h: Add region::symbolic_p.
4313 * store.cc (byte_range::intersects_p):
4314 Add new function equivalent to bit_range::intersects_p.
4315 (byte_range::exceeds_p): New function.
4316 (byte_range::falls_short_of_p): New function.
4317 * store.h (struct byte_range): Add byte_range::intersects_p,
4318 byte_range::exceeds_p and byte_range::falls_short_of_p.
4320 2022-08-12 Tim Lange <mail@tim-lange.me>
4323 * region-model-impl-calls.cc (region_model::impl_call_realloc):
4324 Use the result of get_copied_size as the size for the
4325 sized_regions in realloc.
4326 (success_with_move::get_copied_size): New function.
4328 2022-08-11 Immad Mir <mirimmad@outlook.com>
4331 * sm-fd.cc (check_for_dup): handle the m_start
4332 state when transitioning the state of LHS
4333 of dup, dup2 and dup3 call.
4335 2022-08-09 David Malcolm <dmalcolm@redhat.com>
4338 * region-model.cc (region_model::on_call_pre): Ensure that we call
4339 get_arg_svalue on all arguments.
4341 2022-08-05 David Malcolm <dmalcolm@redhat.com>
4344 * analyzer.opt (Wanalyzer-jump-through-null): New option.
4345 * engine.cc (class jump_through_null): New.
4346 (exploded_graph::process_node): Complain about jumps through NULL
4349 2022-08-02 Immad Mir <mirimmad@outlook.com>
4352 * sm-fd.cc (fd_state_machine::on_open): Add
4353 creat, dup, dup2 and dup3 functions.
4355 (fd_state_machine::valid_to_unchecked_state): New.
4356 (fd_state_machine::on_creat): New.
4357 (fd_state_machine::on_dup): New.
4359 2022-07-28 David Malcolm <dmalcolm@redhat.com>
4362 * analyzer.opt (Wanalyzer-putenv-of-auto-var): New.
4363 * region-model-impl-calls.cc (class putenv_of_auto_var): New.
4364 (region_model::impl_call_putenv): New.
4365 * region-model.cc (region_model::on_call_pre): Handle putenv.
4366 * region-model.h (region_model::impl_call_putenv): New decl.
4368 2022-07-28 David Malcolm <dmalcolm@redhat.com>
4370 * sm-malloc.cc (free_of_non_heap::emit): Add comment about CWE.
4371 * sm-taint.cc (tainted_size::emit): Likewise.
4373 2022-07-28 David Malcolm <dmalcolm@redhat.com>
4375 * region.h: Add notes to the comment describing the region
4378 2022-07-27 Immad Mir <mirimmad@outlook.com>
4382 (fd_diagnostic::get_meaning_for_state_change): New.
4384 2022-07-26 David Malcolm <dmalcolm@redhat.com>
4387 * store.cc (store::set_value): Don't strip away casts if the
4388 region has NULL type.
4390 2022-07-26 David Malcolm <dmalcolm@redhat.com>
4392 * region.h (code_region::get_element): Remove stray decl.
4393 (function_region::get_element): Likewise.
4395 2022-07-25 Martin Liska <mliska@suse.cz>
4397 * sm-fd.cc: Run dos2unix and fix coding style issues.
4399 2022-07-23 Immad Mir <mirimmad@outlook.com>
4401 * sm-fd.cc (fd_param_diagnostic): New diagnostic class.
4402 (fd_access_mode_mismatch): Change inheritance from fd_diagnostic
4403 to fd_param_diagnostic. Add new overloaded constructor.
4404 (fd_use_after_close): Likewise.
4405 (unchecked_use_of_fd): Likewise and also change name to fd_use_without_check.
4406 (double_close): Change name to fd_double_close.
4407 (enum access_directions): New.
4408 (fd_state_machine::on_stmt): Handle calls to function with the
4409 new three function attributes.
4410 (fd_state_machine::check_for_fd_attrs): New.
4411 (fd_state_machine::on_open): Use the new overloaded constructors
4412 of diagnostic classes.
4414 2022-07-22 David Malcolm <dmalcolm@redhat.com>
4417 * varargs.cc (region_model::impl_call_va_start): Avoid iterating
4418 through non-existant variadic arguments by initializing the
4419 impl_region to "UNKNOWN" if the va_start occurs in the top-level
4420 function to the analysis.
4422 2022-07-22 David Malcolm <dmalcolm@redhat.com>
4425 * store.cc (binding_cluster::binding_cluster): Remove overzealous
4426 assertion; we're checking for tracked_p in
4427 store::get_or_create_cluster.
4429 2022-07-22 Tim Lange <mail@tim-lange.me>
4432 * region-model.cc (capacity_compatible_with_type): Always return true
4433 if alloc_size is zero.
4435 2022-07-21 David Malcolm <dmalcolm@redhat.com>
4438 * varargs.cc (region_model::impl_call_va_arg): When determining if
4439 we're doing interprocedural analysis, use the stack depth of the
4440 frame in which va_start was called, rather than the current stack
4443 2022-07-21 David Malcolm <dmalcolm@redhat.com>
4445 * sm-taint.cc (tainted_array_index::emit): Bulletproof against
4447 (tainted_array_index::describe_final_event): Likewise.
4448 (tainted_size::emit): Likewise.
4449 (tainted_size::describe_final_event): Likewise.
4451 2022-07-21 David Malcolm <dmalcolm@redhat.com>
4454 * region.cc (decl_region::get_svalue_for_initializer): Bail out on
4457 2022-07-20 David Malcolm <dmalcolm@redhat.com>
4460 * sm-taint.cc (taint_state_machine::on_condition): Potentially
4461 update the state of the RHS as well as the LHS.
4463 2022-07-20 David Malcolm <dmalcolm@redhat.com>
4466 * region.h (string_region::tracked_p): New.
4467 * store.cc (binding_cluster::binding_cluster): Move here from
4468 store.h. Add assertion that base_region is tracked_p.
4469 * store.h (binding_cluster::binding_cluster): Move to store.cc.
4471 2022-07-19 David Malcolm <dmalcolm@redhat.com>
4474 * constraint-manager.h (bounded_ranges::get_count): New.
4475 (bounded_ranges::get_range): New.
4476 * engine.cc (impl_region_model_context::on_bounded_ranges): New.
4477 * exploded-graph.h (impl_region_model_context::on_bounded_ranges):
4479 * region-model.cc (region_model::apply_constraints_for_gswitch):
4480 Potentially call ctxt->on_bounded_ranges.
4481 * region-model.h (region_model_context::on_bounded_ranges): New
4483 (noop_region_model_context::on_bounded_ranges): New.
4484 (region_model_context_decorator::on_bounded_ranges): New.
4485 * sm-taint.cc: Include "analyzer/constraint-manager.h".
4486 (taint_state_machine::on_bounded_ranges): New.
4487 * sm.h (state_machine::on_bounded_ranges): New.
4489 2022-07-19 David Malcolm <dmalcolm@redhat.com>
4491 * engine.cc (exploded_graph::process_node): Show any description
4492 of the out-edge when logging it for consideration.
4494 2022-07-15 David Malcolm <dmalcolm@redhat.com>
4497 * sm-taint.cc (taint_state_machine::on_condition): Handle range
4498 checks optimized by build_range_check.
4500 2022-07-15 Jonathan Wakely <jwakely@redhat.com>
4502 * call-info.cc (call_info::print): Adjust to new label_text API.
4503 * checker-path.cc (checker_event::dump): Likewise.
4504 (region_creation_event::get_desc): Likewise.
4505 (state_change_event::get_desc): Likewise.
4506 (superedge_event::should_filter_p): Likewise.
4507 (start_cfg_edge_event::get_desc): Likewise.
4508 (call_event::get_desc): Likewise.
4509 (return_event::get_desc): Likewise.
4510 (warning_event::get_desc): Likewise.
4511 (checker_path::dump): Likewise.
4512 (checker_path::debug): Likewise.
4513 * diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic):
4515 (diagnostic_manager::prune_interproc_events): Likewise.
4516 * engine.cc (feasibility_state::maybe_update_for_edge):
4518 * program-state.cc (sm_state_map::to_json): Likewise.
4519 * region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise.
4520 (region_model::impl_call_analyzer_dump_capacity): Likewise.
4521 * region.cc (region::to_json): Likewise.
4522 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
4523 * store.cc (binding_map::to_json): Likewise.
4524 (store::to_json): Likewise.
4525 * supergraph.cc (superedge::dump): Likewise.
4526 * svalue.cc (svalue::to_json): Likewise.
4528 2022-07-07 David Malcolm <dmalcolm@redhat.com>
4530 * checker-path.cc (start_cfg_edge_event::get_desc): Update for
4531 superedge::get_description returning a label_text.
4532 * engine.cc (feasibility_state::maybe_update_for_edge): Likewise.
4533 * supergraph.cc (superedge::dump): Likewise.
4534 (superedge::get_description): Convert return type from char * to
4536 * supergraph.h (superedge::get_description): Likewise.
4538 2022-07-07 David Malcolm <dmalcolm@redhat.com>
4540 * call-info.cc (call_info::print): Update for removal of
4541 label_text::maybe_free in favor of automatic memory management.
4542 * checker-path.cc (checker_event::dump): Likewise.
4543 (checker_event::prepare_for_emission): Likewise.
4544 (state_change_event::get_desc): Likewise.
4545 (superedge_event::should_filter_p): Likewise.
4546 (start_cfg_edge_event::get_desc): Likewise.
4547 (warning_event::get_desc): Likewise.
4548 (checker_path::dump): Likewise.
4549 (checker_path::debug): Likewise.
4550 * diagnostic-manager.cc
4551 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
4552 (diagnostic_manager::prune_interproc_events): Likewise.
4553 * program-state.cc (sm_state_map::to_json): Likewise.
4554 * region.cc (region::to_json): Likewise.
4555 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
4556 * store.cc (binding_map::to_json): Likewise.
4557 (store::to_json): Likewise.
4558 * svalue.cc (svalue::to_json): Likewise.
4560 2022-07-07 David Malcolm <dmalcolm@redhat.com>
4563 * sm-taint.cc (taint_state_machine::on_stmt): Move handling of
4564 assignments from division to...
4565 (taint_state_machine::check_for_tainted_divisor): ...this new
4566 function. Reject warning when the divisor is known to be non-zero.
4567 * sm.cc: Include "analyzer/program-state.h".
4568 (sm_context::get_old_region_model): New.
4569 * sm.h (sm_context::get_old_region_model): New decl.
4571 2022-07-06 Immad Mir <mirimmad@outlook.com>
4574 * sm-fd.cc (fd_state_machine): Change ordering of initialization
4575 of state m_invalid so that the order of initializers is same as
4576 the ordering of the fields in the class decl.
4578 2022-07-06 Immad Mir <mirimmad@outlook.com>
4580 * sm-fd.cc (use_after_close): save the "close" event and
4581 show it where possible.
4583 2022-07-06 David Malcolm <dmalcolm@redhat.com>
4586 * region-model.cc (within_short_circuited_stmt_p): Move extraction
4587 of assign_stmt to caller.
4588 (due_to_ifn_deferred_init_p): New.
4589 (region_model::check_for_poison): Move extraction of assign_stmt
4590 from within_short_circuited_stmt_p to here. Share logic with
4591 call to due_to_ifn_deferred_init_p.
4593 2022-07-02 Tim Lange <mail@tim-lange.me>
4596 * analyzer.opt: Added Wanalyzer-allocation-size.
4597 * checker-path.cc (region_creation_event::get_desc): Added call to new
4598 virtual function pending_diagnostic::describe_region_creation_event.
4599 * checker-path.h: Added region_creation_event::get_desc.
4600 * diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
4602 * diagnostic-manager.h:
4603 Added diagnostic_manager::add_event_on_final_node.
4604 * pending-diagnostic.h (struct region_creation): New event_desc struct.
4605 (pending_diagnostic::describe_region_creation_event): Added virtual
4606 function to overwrite description of a region creation.
4607 * region-model.cc (class dubious_allocation_size): New class.
4608 (capacity_compatible_with_type): New helper function.
4609 (class size_visitor): New class.
4610 (struct_or_union_with_inheritance_p): New helper function.
4611 (is_any_cast_p): New helper function.
4612 (region_model::check_region_size): New function.
4613 (region_model::set_value): Added call to
4614 region_model::check_region_size.
4615 * region-model.h (class region_model): New function check_region_size.
4616 * svalue.cc (region_svalue::accept): Changed to post-order traversal.
4617 (initial_svalue::accept): Likewise.
4618 (unaryop_svalue::accept): Likewise.
4619 (binop_svalue::accept): Likewise.
4620 (sub_svalue::accept): Likewise.
4621 (repeated_svalue::accept): Likewise.
4622 (bits_within_svalue::accept): Likewise.
4623 (widening_svalue::accept): Likewise.
4624 (unmergeable_svalue::accept): Likewise.
4625 (compound_svalue::accept): Likewise.
4626 (conjured_svalue::accept): Likewise.
4627 (asm_output_svalue::accept): Likewise.
4628 (const_fn_result_svalue::accept): Likewise.
4630 2022-07-02 Immad Mir <mirimmad17@gmail.com>
4633 * analyzer.opt (Wanalyzer-fd-leak): New option.
4634 (Wanalyzer-fd-access-mode-mismatch): New option.
4635 (Wanalyzer-fd-use-without-check): New option.
4636 (Wanalyzer-fd-double-close): New option.
4637 (Wanalyzer-fd-use-after-close): New option.
4638 * sm.h (make_fd_state_machine): New decl.
4639 * sm.cc (make_checkers): Call make_fd_state_machine.
4640 * sm-fd.cc: New file.
4642 2022-06-24 David Malcolm <dmalcolm@redhat.com>
4644 * call-string.cc: Add includes of "analyzer/analyzer.h"
4645 and "analyzer/analyzer-logging.h".
4646 (call_string::call_string): Delete copy ctor.
4647 (call_string::operator=): Delete.
4648 (call_string::operator==): Delete.
4649 (call_string::hash): Delete.
4650 (call_string::push_call): Make const, returning the resulting
4652 (call_string::pop): Delete.
4653 (call_string::cmp_ptr_ptr): New.
4654 (call_string::validate): Assert that m_parent is non-NULL, or
4655 m_elements is empty.
4656 (call_string::call_string): Move default ctor here from
4657 call-string.h and reimplement. Add ctor taking a parent
4659 (call_string::~call_string): New.
4660 (call_string::recursive_log): New.
4661 * call-string.h (call_string::call_string): Move default ctor's
4662 defn to call-string.cc. Delete copy ctor. Add ctor taking a
4663 parent and an element.
4664 (call_string::operator=): Delete.
4665 (call_string::operator==): Delete.
4666 (call_string::hash): Delete.
4667 (call_string::push_call): Make const, returning the resulting
4669 (call_string::pop): Delete decl.
4670 (call_string::get_parent): New.
4671 (call_string::cmp_ptr_ptr): New decl.
4672 (call_string::get_top_of_stack): New.
4673 (struct call_string::hashmap_traits_t): New.
4674 (class call_string): Add friend class region_model_manager. Add
4675 DISABLE_COPY_AND_ASSIGN.
4676 (call_string::~call_string): New decl.
4677 (call_string::recursive_log): New decl.
4678 (call_string::m_parent): New field.
4679 (call_string::m_children): New field.
4680 * constraint-manager.cc (selftest::test_many_constants): Pass
4681 model manager to program_point::origin.
4682 * engine.cc (exploded_graph::exploded_graph): Likewise.
4683 (exploded_graph::add_function_entry): Likewise for
4684 program_point::from_function_entry.
4685 (add_tainted_args_callback): Likewise.
4686 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
4687 Update for change to program_point.get_call_string.
4688 (exploded_graph::process_node): Likewise.
4689 (class function_call_string_cluster): Convert m_cs from a
4690 call_string to a const call_string &.
4691 (struct function_call_string): Likewise.
4692 (pod_hash_traits<function_call_string>::hash): Use pointer_hash
4694 (pod_hash_traits<function_call_string>::equal): Update for change
4696 (root_cluster::add_node): Update for change to
4697 function_call_string.
4698 (viz_callgraph_node::dump_dot): Update for change to call_string.
4699 * exploded-graph.h (per_call_string_data::m_key): Convert to a
4701 (struct eg_call_string_hash_map_traits): Delete.
4702 (exploded_graph::call_string_data_map_t): Remove traits class.
4703 * program-point.cc: Move include of "analyzer/call-string.h" to
4704 after "analyzer/analyzer-logging.h".
4705 (program_point::print): Update for conversion of m_call_string to
4707 (program_point::to_json): Likewise.
4708 (program_point::push_to_call_stack): Update for immutability of
4710 (program_point::pop_from_call_stack): Likewise.
4711 (program_point::hash): Use pointer hashing for m_call_string.
4712 (program_point::get_function_at_depth): Update for change to
4714 (program_point::validate): Update for changes to call_string.
4715 (program_point::on_edge): Likewise.
4716 (program_point::origin): Move here from call-string.h. Add
4717 region_model_manager param and use it to get empty call string.
4718 (program_point::from_function_entry): Likewise.
4719 (selftest::test_function_point_ordering): Likewise.
4720 (selftest::test_function_point_ordering): Likewise.
4721 * program-point.h (program_point::program_point): Update for
4722 change to m_call_string.
4723 (program_point::get_call_string): Likewise.
4724 (program_point::get_stack_depth): Likewise.
4725 (program_point::origin): Add region_model_manager param, and move
4726 defn to call-string.cc.
4727 (program_point::from_function_entry): Likewise.
4728 (program_point::empty): Drop call_string.
4729 (program_point::deleted): Likewise.
4730 (program_point::program_point): New private ctor.
4731 (program_point::m_call_string): Convert from call_string to const
4733 * program-state.cc (selftest::test_program_state_merging): Update
4734 for call_string changes.
4735 (selftest::test_program_state_merging_2): Likewise.
4736 * region-model-manager.cc
4737 (region_model_manager::region_model_manager): Construct
4738 m_empty_call_string.
4739 (region_model_manager::log_stats): Log the call strings.
4740 * region-model.cc (assert_region_models_merge): Pass the
4741 region_model_manager when creating program_point instances.
4742 (selftest::test_state_merging): Likewise.
4743 (selftest::test_constraint_merging): Likewise.
4744 (selftest::test_widening_constraints): Likewise.
4745 (selftest::test_iteration_1): Likewise.
4746 * region-model.h (region_model_manager::get_empty_call_string):
4748 (region_model_manager::m_empty_call_string): New.
4749 * sm-signal.cc (register_signal_handler::impl_transition): Update
4750 for changes to call_string.
4752 2022-06-24 David Malcolm <dmalcolm@redhat.com>
4754 * call-string.cc (call_string::calc_recursion_depth): Whitespace
4756 (call_string::cmp): Likewise.
4757 (call_string::get_caller_node): Likewise.
4758 (call_string::validate): Likewise.
4759 * engine.cc (dynamic_call_info_t::add_events_to_path): Likewise.
4760 (exploded_graph::get_per_function_data): Likewise.
4761 (exploded_graph::maybe_create_dynamic_call): Likewise.
4762 (exploded_graph::maybe_create_dynamic_call): Likewise.
4763 (exploded_graph::process_node): Likewise.
4765 2022-06-16 David Malcolm <dmalcolm@redhat.com>
4767 * varargs.cc (va_arg_type_mismatch::emit): Associate the warning
4768 with CWE-686 ("Function Call With Incorrect Argument Type").
4770 2022-06-16 David Malcolm <dmalcolm@redhat.com>
4772 * varargs.cc: Include "diagnostic-metadata.h".
4773 (va_list_exhausted::emit): Associate the warning with
4774 CWE-685 ("Function Call With Incorrect Number of Arguments").
4776 2022-06-16 David Malcolm <dmalcolm@redhat.com>
4778 * sm-file.cc (double_fclose::emit): Associate the warning with
4779 CWE-1341 ("Multiple Releases of Same Resource or Handle").
4781 2022-06-15 David Malcolm <dmalcolm@redhat.com>
4784 * analyzer.opt (fanalyzer-undo-inlining): New option.
4785 * checker-path.cc: Include "diagnostic-core.h" and
4786 "inlining-iterator.h".
4787 (event_kind_to_string): Handle EK_INLINED_CALL.
4788 (class inlining_info): New class.
4789 (checker_event::checker_event): Move here from checker-path.h.
4790 Store original fndecl and depth, and calculate effective fndecl
4791 and depth based on inlining information.
4792 (checker_event::dump): Emit original depth as well as effective
4793 depth when they differ; likewise for fndecl.
4794 (region_creation_event::get_desc): Use m_effective_fndecl.
4795 (inlined_call_event::get_desc): New.
4796 (inlined_call_event::get_meaning): New.
4797 (checker_path::inject_any_inlined_call_events): New.
4798 * checker-path.h (enum event_kind): Add EK_INLINED_CALL.
4799 (checker_event::checker_event): Make protected, and move
4800 definition to checker-path.cc.
4801 (checker_event::get_fndecl): Use effective fndecl.
4802 (checker_event::get_stack_depth): Use effective stack depth.
4803 (checker_event::get_logical_location): Use effective stack depth.
4804 (checker_event::get_original_stack_depth): New.
4805 (checker_event::m_fndecl): Rename to...
4806 (checker_event::m_original_fndecl): ...this.
4807 (checker_event::m_depth): Rename to...
4808 (checker_event::m_original_depth): ...this.
4809 (checker_event::m_effective_fndecl): New field.
4810 (checker_event::m_effective_depth): New field.
4811 (class inlined_call_event): New checker_event subclass.
4812 (checker_path::inject_any_inlined_call_events): New decl.
4813 * diagnostic-manager.cc: Include "inlining-iterator.h".
4814 (diagnostic_manager::emit_saved_diagnostic): Call
4815 checker_path::inject_any_inlined_call_events.
4816 (diagnostic_manager::prune_for_sm_diagnostic): Handle
4818 * engine.cc (tainted_args_function_custom_event::get_desc): Use
4820 * inlining-iterator.h: New file.
4822 2022-06-15 David Malcolm <dmalcolm@redhat.com>
4824 * diagnostic-manager.cc (saved_diagnostic::dump_dot_id): New.
4825 (saved_diagnostic::dump_as_dot_node): New.
4826 * diagnostic-manager.h (saved_diagnostic::dump_dot_id): New decl.
4827 (saved_diagnostic::dump_as_dot_node): New decl.
4828 * engine.cc (exploded_node::dump_dot): Add nodes for saved
4831 2022-06-02 David Malcolm <dmalcolm@redhat.com>
4833 * checker-path.cc (checker_event::get_meaning): New.
4834 (function_entry_event::get_meaning): New.
4835 (state_change_event::get_desc): Add dump of meaning of the event
4836 to the -fanalyzer-verbose-state-changes output.
4837 (state_change_event::get_meaning): New.
4838 (cfg_edge_event::get_meaning): New.
4839 (call_event::get_meaning): New.
4840 (return_event::get_meaning): New.
4841 (start_consolidated_cfg_edges_event::get_meaning): New.
4842 (warning_event::get_meaning): New.
4843 * checker-path.h: Include "tree-logical-location.h".
4844 (checker_event::checker_event): Construct m_logical_loc.
4845 (checker_event::get_logical_location): New.
4846 (checker_event::get_meaning): New decl.
4847 (checker_event::m_logical_loc): New.
4848 (function_entry_event::get_meaning): New decl.
4849 (state_change_event::get_meaning): New decl.
4850 (cfg_edge_event::get_meaning): New decl.
4851 (call_event::get_meaning): New decl.
4852 (return_event::get_meaning): New decl.
4853 (start_consolidated_cfg_edges_event::get_meaning): New.
4854 (warning_event::get_meaning): New decl.
4855 * pending-diagnostic.h: Include "diagnostic-path.h".
4856 (pending_diagnostic::get_meaning_for_state_change): New vfunc.
4857 * sm-file.cc (file_diagnostic::get_meaning_for_state_change): New
4859 * sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
4862 (exposure_through_output_file::get_meaning_for_state_change):
4864 * sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
4867 (va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.
4869 2022-05-23 David Malcolm <dmalcolm@redhat.com>
4871 * call-info.cc: Add "final" and "override" to all vfunc
4872 implementations that were missing them, as appropriate.
4873 * engine.cc: Likewise.
4874 * region-model.cc: Likewise.
4875 * sm-malloc.cc: Likewise.
4876 * supergraph.h: Likewise.
4877 * svalue.cc: Likewise.
4878 * varargs.cc: Likewise.
4880 2022-05-20 David Malcolm <dmalcolm@redhat.com>
4882 * analyzer-pass.cc: Replace uses of "FINAL" and "OVERRIDE" with
4883 "final" and "override".
4884 * call-info.h: Likewise.
4885 * checker-path.h: Likewise.
4886 * constraint-manager.cc: Likewise.
4887 * diagnostic-manager.cc: Likewise.
4888 * engine.cc: Likewise.
4889 * exploded-graph.h: Likewise.
4890 * feasible-graph.h: Likewise.
4891 * pending-diagnostic.h: Likewise.
4892 * region-model-impl-calls.cc: Likewise.
4893 * region-model.cc: Likewise.
4894 * region-model.h: Likewise.
4895 * region.h: Likewise.
4896 * sm-file.cc: Likewise.
4897 * sm-malloc.cc: Likewise.
4898 * sm-pattern-test.cc: Likewise.
4899 * sm-sensitive.cc: Likewise.
4900 * sm-signal.cc: Likewise.
4901 * sm-taint.cc: Likewise.
4902 * state-purge.h: Likewise.
4903 * store.cc: Likewise.
4904 * store.h: Likewise.
4905 * supergraph.h: Likewise.
4906 * svalue.h: Likewise.
4907 * trimmed-graph.h: Likewise.
4908 * varargs.cc: Likewise.
4910 2022-05-16 David Malcolm <dmalcolm@redhat.com>
4913 * analyzer.cc (make_label_text_n): New.
4914 * analyzer.h (class var_arg_region): New forward decl.
4915 (make_label_text_n): New decl.
4916 * analyzer.opt (Wanalyzer-va-arg-type-mismatch): New option.
4917 (Wanalyzer-va-list-exhausted): New option.
4918 (Wanalyzer-va-list-leak): New option.
4919 (Wanalyzer-va-list-use-after-va-end): New option.
4920 * checker-path.cc (call_event::get_desc): Split out decl access
4922 (call_event::get_caller_fndecl): ...this new function and...
4923 (call_event::get_callee_fndecl): ...this new function.
4924 * checker-path.h (call_event::get_desc): Drop "FINAL".
4925 (call_event::get_caller_fndecl): New decl.
4926 (call_event::get_callee_fndecl): New decl.
4927 (class call_event): Make fields protected.
4928 * diagnostic-manager.cc (null_assignment_sm_context::warn): New
4930 (null_assignment_sm_context::get_new_program_state): New.
4931 (diagnostic_manager::add_events_for_superedge): Move case
4932 SUPEREDGE_CALL to a new pending_diagnostic::add_call_event vfunc.
4933 * engine.cc (impl_sm_context::warn): Implement new override.
4934 (impl_sm_context::get_new_program_state): New.
4935 * pending-diagnostic.cc: Include "analyzer/diagnostic-manager.h",
4936 "cpplib.h", "digraph.h", "ordered-hash-map.h", "cfg.h",
4937 "basic-block.h", "gimple.h", "gimple-iterator.h", "cgraph.h"
4938 "analyzer/supergraph.h", "analyzer/program-state.h",
4939 "alloc-pool.h", "fibonacci_heap.h", "shortest-paths.h",
4940 "sbitmap.h", "analyzer/exploded-graph.h", "diagnostic-path.h",
4941 and "analyzer/checker-path.h".
4943 (fixup_location_in_macro_p): New.
4944 (pending_diagnostic::fixup_location): New.
4945 (pending_diagnostic::add_call_event): New.
4946 * pending-diagnostic.h (pending_diagnostic::fixup_location): Drop
4947 no-op inline implementation in favor of the more complex
4948 implementation above.
4949 (pending_diagnostic::add_call_event): New vfunc.
4950 * region-model-impl-calls.cc: Include "analyzer/sm.h",
4951 "diagnostic-path.h", and "analyzer/pending-diagnostic.h".
4952 * region-model-manager.cc
4953 (region_model_manager::get_var_arg_region): New.
4954 (region_model_manager::log_stats): Log m_var_arg_regions.
4955 * region-model.cc (region_model::on_call_pre): Handle IFN_VA_ARG,
4956 BUILT_IN_VA_START, and BUILT_IN_VA_COPY.
4957 (region_model::on_call_post): Handle BUILT_IN_VA_END.
4958 (region_model::get_representative_path_var_1): Handle RK_VAR_ARG.
4959 (region_model::push_frame): Push variadic arguments.
4960 * region-model.h (region_model_manager::get_var_arg_region): New
4962 (region_model_manager::m_var_arg_regions): New field.
4963 (region_model::impl_call_va_start): New decl.
4964 (region_model::impl_call_va_copy): New decl.
4965 (region_model::impl_call_va_arg): New decl.
4966 (region_model::impl_call_va_end): New decl.
4967 * region.cc (alloca_region::dump_to_pp): Dump the id.
4968 (var_arg_region::dump_to_pp): New.
4969 (var_arg_region::get_frame_region): New.
4970 * region.h (enum region_kind): Add RK_VAR_ARG.
4971 (region::dyn_cast_var_arg_region): New.
4972 (class var_arg_region): New.
4973 (is_a_helper <const var_arg_region *>::test): New.
4974 (struct default_hash_traits<var_arg_region::key_t>): New.
4975 * sm.cc (make_checkers): Call make_va_list_state_machine.
4976 * sm.h (sm_context::warn): New vfunc.
4977 (sm_context::get_old_svalue): Drop unused decl.
4978 (sm_context::get_new_program_state): New vfunc.
4979 (make_va_list_state_machine): New decl.
4980 * varargs.cc: New file.
4982 2022-05-16 Martin Liska <mliska@suse.cz>
4984 * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
4985 * function-set.cc (test_stdio_example): Likewise.
4986 * sm-file.cc (get_file_using_fns): Likewise.
4987 * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
4988 * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
4990 2022-05-13 Richard Biener <rguenther@suse.de>
4992 * supergraph.cc: Re-order gimple-fold.h include.
4994 2022-05-11 David Malcolm <dmalcolm@redhat.com>
4996 * checker-path.cc (state_change_event::get_desc): Call maybe_free
4997 on label_text temporaries.
4998 * diagnostic-manager.cc
4999 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
5000 * engine.cc (exploded_graph::~exploded_graph): Fix leak of
5001 m_per_point_data and m_per_call_string_data values. Simplify
5002 cleanup of m_per_function_stats and m_per_point_data values.
5003 (feasibility_state::maybe_update_for_edge): Fix leak of result of
5004 superedge::get_description.
5005 * region-model-manager.cc
5006 (region_model_manager::~region_model_manager): Move cleanup of
5007 m_setjmp_values to match the ordering of the fields within
5008 region_model_manager. Fix leak of values within
5009 m_repeated_values_map, m_bits_within_values_map,
5010 m_asm_output_values_map, and m_const_fn_result_values_map.
5012 2022-04-28 David Malcolm <dmalcolm@redhat.com>
5015 * store.cc (binding_cluster::get_any_binding): Handle accessing
5016 sub_svalues of clusters where the base region has a symbolic
5019 2022-04-28 David Malcolm <dmalcolm@redhat.com>
5021 * diagnostic-manager.cc (epath_finder::process_worklist_item):
5022 Call dump_feasible_path when a path that reaches the the target
5024 (epath_finder::dump_feasible_path): New.
5025 * engine.cc (feasibility_state::dump_to_pp): New.
5026 * exploded-graph.h (feasibility_state::dump_to_pp): New decl.
5027 * feasible-graph.cc (feasible_graph::dump_feasible_path): New.
5028 * feasible-graph.h (feasible_graph::dump_feasible_path): New
5030 * program-point.cc (function_point::print): Fix missing trailing
5032 * program-point.h (program_point::print_source_line): Remove
5035 2022-04-25 David Malcolm <dmalcolm@redhat.com>
5040 (cmp_cst): Rename to...
5041 (cmp_csts_same_type): ...this. Convert all recursive calls to
5043 (cmp_csts_and_types): ....this new function.
5044 (svalue::cmp_ptr): Update for renaming of cmp_cst
5046 2022-04-14 David Malcolm <dmalcolm@redhat.com>
5049 * region-model-reachability.cc (reachable_regions::handle_parm):
5050 Use maybe_get_deref_base_region rather than just region_svalue, to
5051 handle pointer arithmetic also.
5052 * svalue.cc (svalue::maybe_get_deref_base_region): New.
5053 * svalue.h (svalue::maybe_get_deref_base_region): New decl.
5055 2022-04-14 David Malcolm <dmalcolm@redhat.com>
5058 * svalue.cc (cmp_cst): When comparing VECTOR_CSTs, compare the
5059 types of the encoded elements before calling cmp_cst on them.
5061 2022-04-09 David Malcolm <dmalcolm@redhat.com>
5064 * region-model-manager.cc
5065 (region_model_manager::get_unknown_symbolic_region): New,
5067 (region_model_manager::get_field_region): ...here.
5068 (region_model_manager::get_element_region): Use it here.
5069 (region_model_manager::get_offset_region): Likewise.
5070 (region_model_manager::get_sized_region): Likewise.
5071 (region_model_manager::get_cast_region): Likewise.
5072 (region_model_manager::get_bit_range): Likewise.
5074 (region_model_manager::get_unknown_symbolic_region): New decl.
5075 * region.cc (symbolic_region::symbolic_region): Handle sval_ptr
5077 (symbolic_region::dump_to_pp): Handle having NULL type.
5079 2022-04-07 David Malcolm <dmalcolm@redhat.com>
5082 * store.cc (binding_map::remove_overlapping_bindings): Add
5083 "always_overlap" param, using it to generalize to the case where
5084 we want to remove all bindings. Update "uncertainty" logic to
5085 only record maybe-bound values for cases where there is a symbolic
5087 (binding_cluster::mark_region_as_unknown): Split param "reg" into
5088 "reg_to_bind" and "reg_for_overlap".
5089 (binding_cluster::maybe_get_compound_binding): Pass "false" to
5090 binding_map::remove_overlapping_bindings new "always_overlap" param.
5091 (binding_cluster::remove_overlapping_bindings): Determine
5092 "always_overlap" and pass it to
5093 binding_map::remove_overlapping_bindings.
5094 (store::set_value): Pass uncertainty to remove_overlapping_bindings
5095 call. Update for new param of
5096 binding_cluster::mark_region_as_unknown, passing both the base
5097 region of the iter_cluster, and the lhs_reg.
5098 (store::mark_region_as_unknown): Update for new param of
5099 binding_cluster::mark_region_as_unknown, passing "reg" for both.
5100 (store::remove_overlapping_bindings): Add param "uncertainty", and
5101 pass it on to call to
5102 binding_cluster::remove_overlapping_bindings.
5103 * store.h (binding_map::remove_overlapping_bindings): Add
5104 "always_overlap" param.
5105 (binding_cluster::mark_region_as_unknown): Split param "reg" into
5106 "reg_to_bind" and "reg_for_overlap".
5107 (store::remove_overlapping_bindings): Add param "uncertainty".
5109 2022-03-29 David Malcolm <dmalcolm@redhat.com>
5112 * region-model-manager.cc (dump_untracked_region): Skip decls in
5115 2022-03-29 David Malcolm <dmalcolm@redhat.com>
5118 * analyzer.h (class conjured_purge): New forward decl.
5119 * region-model-asm.cc (region_model::on_asm_stmt): Add
5120 conjured_purge param to calls binding_cluster::on_asm and
5121 region_model_manager::get_or_create_conjured_svalue.
5122 * region-model-impl-calls.cc
5123 (call_details::get_or_create_conjured_svalue): Likewise for call
5124 to region_model_manager::get_or_create_conjured_svalue.
5125 (region_model::impl_call_fgets): Remove call to
5126 region_model::purge_state_involving, as this is now done
5127 implicitly by call_details::get_or_create_conjured_svalue.
5128 (region_model::impl_call_fread): Likewise.
5129 (region_model::impl_call_strchr): Pass conjured_purge param to
5130 call to region_model_manager::get_or_create_conjured_svalue.
5131 * region-model-manager.cc (conjured_purge::purge): New.
5132 (region_model_manager::get_or_create_conjured_svalue): Add
5133 param "p". Use it to purge state when reusing an existing
5135 * region-model.cc (region_model::on_call_pre): Replace call to
5136 region_model::purge_state_involving with passing conjured_purge
5137 to region_model_manager::get_or_create_conjured_svalue.
5138 (region_model::handle_unrecognized_call): Pass conjured_purge to
5139 store::on_unknown_fncall.
5141 (region_model_manager::get_or_create_conjured_svalue): Add param
5143 * store.cc (binding_cluster::on_unknown_fncall): Likewise. Pass
5144 it on to region_model_manager::get_or_create_conjured_svalue.
5145 (binding_cluster::on_asm): Likewise.
5146 (store::on_unknown_fncall): Add param "p" and pass it on to
5147 binding_cluster::on_unknown_fncall.
5148 * store.h (binding_cluster::on_unknown_fncall): Add param p.
5149 (binding_cluster::on_asm): Likewise.
5150 (store::on_unknown_fncall): Likewise.
5151 * svalue.h (class conjured_purge): New.
5153 2022-03-29 David Malcolm <dmalcolm@redhat.com>
5156 * region.cc (ipa_ref_requires_tracking): Drop "context_fndecl",
5157 instead using the ref->referring to get the cgraph node of the
5159 (symnode_requires_tracking_p): Likewise.
5161 2022-03-26 David Malcolm <dmalcolm@redhat.com>
5164 * store.cc (binding_cluster::make_unknown_relative_to): Reject
5165 attempts to create a cluster for untracked base regions.
5166 (store::set_value): Likewise.
5167 (store::fill_region): Likewise.
5168 (store::mark_region_as_unknown): Likewise.
5170 2022-03-25 David Malcolm <dmalcolm@redhat.com>
5173 * analyzer.opt (-fdump-analyzer-untracked): New option.
5174 * engine.cc (impl_run_checkers): Handle it.
5175 * region-model-asm.cc (region_model::on_asm_stmt): Don't attempt
5176 to clobber regions with !tracked_p ().
5177 * region-model-manager.cc (dump_untracked_region): New.
5178 (region_model_manager::dump_untracked_regions): New.
5179 (frame_region::dump_untracked_regions): New.
5180 * region-model.h (region_model_manager::dump_untracked_regions):
5182 * region.cc (ipa_ref_requires_tracking): New.
5183 (symnode_requires_tracking_p): New.
5184 (decl_region::calc_tracked_p): New.
5185 * region.h (region::tracked_p): New vfunc.
5186 (frame_region::dump_untracked_regions): New decl.
5187 (class decl_region): Note that this is also used fo SSA names.
5188 (decl_region::decl_region): Initialize m_tracked.
5189 (decl_region::tracked_p): New.
5190 (decl_region::calc_tracked_p): New decl.
5191 (decl_region::m_tracked): New.
5192 * store.cc (store::get_or_create_cluster): Assert that we
5193 don't try to create clusters for base regions that aren't
5195 (store::mark_as_escaped): Don't mark base regions that we're not
5198 2022-03-23 David Malcolm <dmalcolm@redhat.com>
5201 * engine.cc (impl_run_checkers): Create the engine after the
5202 supergraph, and pass the supergraph to the engine.
5203 * region-model.cc (region_model::get_lvalue_1): Pass ctxt to
5204 frame_region::get_region_for_local.
5205 (region_model::update_for_return_gcall): Pass the lvalue for the
5206 result to pop_frame as a tree, rather than as a region.
5207 (region_model::pop_frame): Update for above change, determining
5208 the destination region after the frame is popped and thus with
5209 respect to the caller frame rather than the called frame.
5210 Likewise, set the value of the region to the return value after
5211 the frame is popped.
5212 (engine::engine): Add supergraph pointer.
5213 (selftest::test_stack_frames): Set the DECL_CONTECT of PARM_DECLs.
5214 (selftest::test_get_representative_path_var): Likewise.
5215 (selftest::test_state_merging): Likewise.
5216 * region-model.h (region_model::pop_frame): Convert first param
5217 from a const region * to a tree.
5218 (engine::engine): Add param "sg".
5219 (engine::m_sg): New field.
5220 * region.cc: Include "analyzer/sm.h" and
5221 "analyzer/program-state.h".
5222 (frame_region::get_region_for_local): Add "ctxt" param.
5223 Add assertions that VAR_DECLs are locals, and that expr is for the
5225 * region.h (frame_region::get_region_for_local): Add "ctxt" param.
5227 2022-03-23 David Malcolm <dmalcolm@redhat.com>
5230 * sm-taint.cc (taint_diagnostic::subclass_equal_p): Check
5231 m_has_bounds as well as m_arg.
5232 (tainted_allocation_size::subclass_equal_p): Chain up to base
5233 class implementation. Also check m_mem_space.
5234 (tainted_allocation_size::emit): Add note showing stack-based vs
5235 heap-based allocations.
5237 2022-03-23 David Malcolm <dmalcolm@redhat.com>
5240 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic):
5241 Convert return type from "void" to "bool", reporting success vs
5242 failure to caller, for both overloads.
5243 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
5245 * engine.cc (impl_region_model_context::warn): Propagate return
5246 value from diagnostic_manager::add_diagnostic.
5248 2022-03-18 David Malcolm <dmalcolm@redhat.com>
5253 * analyzer.h (class state_purge_per_decl): New forward decl.
5254 * engine.cc (impl_run_checkers): Pass region_model_manager to
5255 state_purge_map ctor.
5256 * program-point.cc (function_point::final_stmt_p): New.
5257 (function_point::get_next): New.
5258 * program-point.h (function_point::final_stmt_p): New decl.
5259 (function_point::get_next): New decl.
5260 * program-state.cc (program_state::prune_for_point): Generalize to
5261 purge local decls as well as SSA names.
5262 (program_state::can_purge_base_region_p): New.
5263 * program-state.h (program_state::can_purge_base_region_p): New
5265 * region-model.cc (struct append_ssa_names_cb_data): Rename to...
5266 (struct append_regions_cb_data): ...this.
5267 (region_model::get_ssa_name_regions_for_current_frame): Rename
5269 (region_model::get_regions_for_current_frame): ...this, updating
5270 for other renamings.
5271 (region_model::append_ssa_names_cb): Rename to...
5272 (region_model::append_regions_cb): ...this, and drop the requirement
5273 that the subregion be a SSA name.
5274 * region-model.h (struct append_ssa_names_cb_data): Rename decl
5276 (struct append_regions_cb_data): ...this.
5277 (region_model::get_ssa_name_regions_for_current_frame): Rename
5279 (region_model::get_regions_for_current_frame): ...this.
5280 (region_model::append_ssa_names_cb): Rename decl to...
5281 (region_model::append_regions_cb): ...this.
5282 * state-purge.cc: Include "tristate.h", "selftest.h",
5283 "analyzer/store.h", "analyzer/region-model.h", and
5285 (get_candidate_for_purging): New.
5286 (class gimple_op_visitor): New.
5290 (state_purge_map::state_purge_map): Add "mgr" param. Update for
5291 renamings. Find uses of local variables.
5292 (state_purge_map::~state_purge_map): Update for renaming of m_map
5293 to m_ssa_map. Clean up m_decl_map.
5294 (state_purge_map::get_or_create_data_for_decl): New.
5295 (state_purge_per_ssa_name::state_purge_per_ssa_name): Update for
5296 inheriting from state_purge_per_tree.
5297 (state_purge_per_ssa_name::add_to_worklist): Likewise.
5298 (state_purge_per_decl::state_purge_per_decl): New.
5299 (state_purge_per_decl::add_needed_at): New.
5300 (state_purge_per_decl::add_pointed_to_at): New.
5301 (state_purge_per_decl::process_worklists): New.
5302 (state_purge_per_decl::add_to_worklist): New.
5303 (same_binding_p): New.
5304 (fully_overwrites_p): New.
5305 (state_purge_per_decl::process_point_backwards): New.
5306 (state_purge_per_decl::process_point_forwards): New.
5307 (state_purge_per_decl::needed_at_point_p): New.
5308 (state_purge_annotator::print_needed): Generalize to print local
5309 decls as well as SSA names.
5310 * state-purge.h (class state_purge_map): Update leading comment.
5311 (state_purge_map::map_t): Rename to...
5312 (state_purge_map::ssa_map_t): ...this.
5313 (state_purge_map::iterator): Rename to...
5314 (state_purge_map::ssa_iterator): ...this.
5315 (state_purge_map::decl_map_t): New typedef.
5316 (state_purge_map::decl_iterator): New typedef.
5317 (state_purge_map::state_purge_map): Add "mgr" param.
5318 (state_purge_map::get_data_for_ssa_name): Update for renaming.
5319 (state_purge_map::get_any_data_for_decl): New.
5320 (state_purge_map::get_or_create_data_for_decl): New decl.
5321 (state_purge_map::begin): Rename to...
5322 (state_purge_map::begin_ssas): ...this.
5323 (state_purge_map::end): Rename to...
5324 (state_purge_map::end_ssa): ...this.
5325 (state_purge_map::begin_decls): New.
5326 (state_purge_map::end_decls): New.
5327 (state_purge_map::m_map): Rename to...
5328 (state_purge_map::m_ssa_map): ...this.
5329 (state_purge_map::m_decl_map): New field.
5330 (class state_purge_per_tree): New class.
5331 (class state_purge_per_ssa_name): Inherit from state_purge_per_tree.
5332 (state_purge_per_ssa_name::get_function): Move to base class.
5333 (state_purge_per_ssa_name::point_set_t): Likewise.
5334 (state_purge_per_ssa_name::m_fun): Likewise.
5335 (class state_purge_per_decl): New.
5337 2022-03-17 David Malcolm <dmalcolm@redhat.com>
5339 * state-purge.cc (state_purge_annotator::add_node_annotations):
5340 Avoid duplicate before-supernode annotations when returning from
5341 an interprocedural call. Show after-supernode annotations.
5343 2022-03-17 David Malcolm <dmalcolm@redhat.com>
5345 * program-point.cc (program_point::get_next): Fix missing
5348 2022-03-16 David Malcolm <dmalcolm@redhat.com>
5351 * diagnostic-manager.cc (get_emission_location): New.
5352 (diagnostic_manager::diagnostic_manager): Initialize
5353 m_num_disabled_diagnostics.
5354 (diagnostic_manager::add_diagnostic): Reject diagnostics that
5355 will eventually be rejected due to being disabled.
5356 (diagnostic_manager::emit_saved_diagnostics): Log the number
5357 of disabled diagnostics.
5358 (diagnostic_manager::emit_saved_diagnostic): Split out logic for
5359 determining emission location to get_emission_location.
5360 * diagnostic-manager.h
5361 (diagnostic_manager::m_num_disabled_diagnostics): New field.
5362 * engine.cc (stale_jmp_buf::get_controlling_option): New.
5363 (stale_jmp_buf::emit): Use it.
5364 * pending-diagnostic.h
5365 (pending_diagnostic::get_controlling_option): New vfunc.
5367 (poisoned_value_diagnostic::get_controlling_option): New.
5368 (poisoned_value_diagnostic::emit): Use it.
5369 (shift_count_negative_diagnostic::get_controlling_option): New.
5370 (shift_count_negative_diagnostic::emit): Use it.
5371 (shift_count_overflow_diagnostic::get_controlling_option): New.
5372 (shift_count_overflow_diagnostic::emit): Use it.
5373 (dump_path_diagnostic::get_controlling_option): New.
5374 (dump_path_diagnostic::emit): Use it.
5375 (write_to_const_diagnostic::get_controlling_option): New.
5376 (write_to_const_diagnostic::emit): Use it.
5377 (write_to_string_literal_diagnostic::get_controlling_option): New.
5378 (write_to_string_literal_diagnostic::emit): Use it.
5379 * sm-file.cc (double_fclose::get_controlling_option): New.
5380 (double_fclose::emit): Use it.
5381 (file_leak::get_controlling_option): New.
5382 (file_leak::emit): Use it.
5383 * sm-malloc.cc (mismatching_deallocation::get_controlling_option):
5385 (mismatching_deallocation::emit): Use it.
5386 (double_free::get_controlling_option): New.
5387 (double_free::emit): Use it.
5388 (possible_null_deref::get_controlling_option): New.
5389 (possible_null_deref::emit): Use it.
5390 (possible_null_arg::get_controlling_option): New.
5391 (possible_null_arg::emit): Use it.
5392 (null_deref::get_controlling_option): New.
5393 (null_deref::emit): Use it.
5394 (null_arg::get_controlling_option): New.
5395 (null_arg::emit): Use it.
5396 (use_after_free::get_controlling_option): New.
5397 (use_after_free::emit): Use it.
5398 (malloc_leak::get_controlling_option): New.
5399 (malloc_leak::emit): Use it.
5400 (free_of_non_heap::get_controlling_option): New.
5401 (free_of_non_heap::emit): Use it.
5402 * sm-pattern-test.cc (pattern_match::get_controlling_option): New.
5403 (pattern_match::emit): Use it.
5405 (exposure_through_output_file::get_controlling_option): New.
5406 (exposure_through_output_file::emit): Use it.
5407 * sm-signal.cc (signal_unsafe_call::get_controlling_option): New.
5408 (signal_unsafe_call::emit): Use it.
5409 * sm-taint.cc (tainted_array_index::get_controlling_option): New.
5410 (tainted_array_index::emit): Use it.
5411 (tainted_offset::get_controlling_option): New.
5412 (tainted_offset::emit): Use it.
5413 (tainted_size::get_controlling_option): New.
5414 (tainted_size::emit): Use it.
5415 (tainted_divisor::get_controlling_option): New.
5416 (tainted_divisor::emit): Use it.
5417 (tainted_allocation_size::get_controlling_option): New.
5418 (tainted_allocation_size::emit): Use it.
5420 2022-03-15 David Malcolm <dmalcolm@redhat.com>
5422 * store.cc (store::store): Presize m_cluster_map.
5424 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5427 * constraint-manager.cc (constraint_manager::add_constraint):
5428 Refresh the EC IDs when adding constraints implied by offsets.
5430 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5433 * analyzer.h (class pending_note): New forward decl.
5434 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
5436 (saved_diagnostic::operator==): Compare m_notes.
5437 (saved_diagnostic::add_note): New.
5438 (saved_diagnostic::emit_any_notes): New.
5439 (diagnostic_manager::add_note): New.
5440 (diagnostic_manager::emit_saved_diagnostic): Call emit_any_notes
5441 after emitting the warning.
5442 * diagnostic-manager.h (saved_diagnostic::add_note): New decl.
5443 (saved_diagnostic::emit_any_notes): New decl.
5444 (saved_diagnostic::m_notes): New field.
5445 (diagnostic_manager::add_note): New decl.
5446 * engine.cc (impl_region_model_context::add_note): New.
5447 * exploded-graph.h (impl_region_model_context::add_note): New
5449 * pending-diagnostic.h (class pending_note): New.
5450 (class pending_note_subclass): New template.
5451 * region-model.cc (class reason_attr_access): New.
5452 (check_external_function_for_access_attr): Add class
5453 annotating_ctxt and use it when checking region.
5454 (noop_region_model_context::add_note): New.
5455 * region-model.h (region_model_context::add_note): New vfunc.
5456 (noop_region_model_context::add_note): New decl.
5457 (class region_model_context_decorator): New.
5458 (class note_adding_context): New.
5460 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5464 (region_model::check_external_function_for_access_attr): New.
5465 (region_model::handle_unrecognized_call): Call it.
5467 (region_model::check_external_function_for_access_attr): New decl.
5468 (region_model::handle_unrecognized_call): New decl.
5470 2022-03-10 David Malcolm <dmalcolm@redhat.com>
5472 * sm-taint.cc (taint_state_machine::check_for_tainted_size_arg):
5473 Avoid generating duplicate saved_diagnostics by only handling the
5474 rdwr_map entry for the ptrarg, not the duplicate entry for the
5477 2022-03-07 David Malcolm <dmalcolm@redhat.com>
5480 * engine.cc (returning_from_function_p): New.
5481 (impl_region_model_context::on_state_leak): Use it when rejecting
5482 leaks at the return from "main".
5484 2022-03-07 Jakub Jelinek <jakub@redhat.com>
5486 * store.cc: Fix up duplicated word issue in a comment.
5487 * analyzer.cc: Likewise.
5488 * engine.cc: Likewise.
5489 * sm-taint.cc: Likewise.
5491 2022-03-04 David Malcolm <dmalcolm@redhat.com>
5494 * analyzer.opt (-param=analyzer-max-svalue-depth=): Reduce from 13
5497 2022-02-23 David Malcolm <dmalcolm@redhat.com>
5500 * analyzer.h (class const_fn_result_svalue): New decl.
5501 * region-model-impl-calls.cc (call_details::get_manager): New.
5502 * region-model-manager.cc
5503 (region_model_manager::get_or_create_const_fn_result_svalue): New.
5504 (region_model_manager::log_stats): Log
5505 m_const_fn_result_values_map.
5506 * region-model.cc (const_fn_p): New.
5507 (maybe_get_const_fn_result): New.
5508 (region_model::on_call_pre): Handle fndecls with
5509 __attribute__((const)) by calling the above rather than making
5511 * region-model.h (visitor::visit_const_fn_result_svalue): New.
5512 (region_model_manager::get_or_create_const_fn_result_svalue): New
5514 (region_model_manager::const_fn_result_values_map_t): New typedef.
5515 (region_model_manager::m_const_fn_result_values_map): New field.
5516 (call_details::get_manager): New decl.
5517 * svalue.cc (svalue::cmp_ptr): Handle SK_CONST_FN_RESULT.
5518 (const_fn_result_svalue::dump_to_pp): New.
5519 (const_fn_result_svalue::dump_input): New.
5520 (const_fn_result_svalue::accept): New.
5521 * svalue.h (enum svalue_kind): Add SK_CONST_FN_RESULT.
5522 (svalue::dyn_cast_const_fn_result_svalue): New.
5523 (class const_fn_result_svalue): New.
5524 (is_a_helper <const const_fn_result_svalue *>::test): New.
5525 (template <> struct default_hash_traits<const_fn_result_svalue::key_t>):
5528 2022-02-17 David Malcolm <dmalcolm@redhat.com>
5531 * region-model.cc: Include "calls.h".
5532 (region_model::on_call_pre): Use flags_from_decl_or_type to
5533 generalize check for DECL_PURE_P to also check for ECF_CONST.
5535 2022-02-16 David Malcolm <dmalcolm@redhat.com>
5538 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
5539 Add region creation events for globals of interest.
5540 (null_assignment_sm_context::get_old_program_state): New.
5541 (diagnostic_manager::add_events_for_eedge): Move check for
5542 changing dynamic extents from PK_BEFORE_STMT case to after the
5543 switch on the dst_point's kind so that we can emit them for the
5544 final stmt in a basic block.
5545 * engine.cc (impl_sm_context::get_old_program_state): New.
5546 * sm-malloc.cc (malloc_state_machine::get_default_state): Rewrite
5547 detection of m_non_heap to use get_memory_space.
5548 (free_of_non_heap::free_of_non_heap): Add freed_reg param.
5549 (free_of_non_heap::subclass_equal_p): Update for changes to
5551 (free_of_non_heap::emit): Drop m_kind in favor of
5553 (free_of_non_heap::describe_state_change): Remove logic for
5555 (free_of_non_heap::mark_interesting_stuff): Add region-creation of
5557 (free_of_non_heap::get_memory_space): New.
5558 (free_of_non_heap::kind): Drop enum.
5559 (free_of_non_heap::m_freed_reg): New field.
5560 (free_of_non_heap::m_kind): Drop field.
5561 (malloc_state_machine::on_stmt): Drop transition to m_non_heap.
5562 (malloc_state_machine::handle_free_of_non_heap): New function,
5563 split out from on_deallocator_call and on_realloc_call, adding
5564 detection of the freed region.
5565 (malloc_state_machine::on_deallocator_call): Use it.
5566 (malloc_state_machine::on_realloc_call): Likewise.
5567 * sm.h (sm_context::get_old_program_state): New vfunc.
5569 2022-02-15 David Malcolm <dmalcolm@redhat.com>
5572 * region-model-manager.cc
5573 (region_model_manager::maybe_fold_sub_svalue): Only call
5574 get_or_create_cast if type is non-NULL.
5576 2022-02-15 David Malcolm <dmalcolm@redhat.com>
5579 * exploded-graph.h (impl_region_model_context::get_stmt): New.
5580 * region-model.cc: Include "gimple-ssa.h", "tree-phinodes.h",
5581 "tree-ssa-operands.h", and "ssa-iterators.h".
5582 (within_short_circuited_stmt_p): New.
5583 (region_model::check_for_poison): Don't warn about uninit values
5584 if within_short_circuited_stmt_p.
5585 * region-model.h (region_model_context::get_stmt): New vfunc.
5586 (noop_region_model_context::get_stmt): New.
5588 2022-02-11 David Malcolm <dmalcolm@redhat.com>
5591 * region-model.cc (region_model::check_for_poison): Ignore
5592 uninitialized uses of empty types.
5594 2022-02-10 David Malcolm <dmalcolm@redhat.com>
5597 * region-model-manager.cc
5598 (region_model_manager::maybe_fold_sub_svalue): Generalize getting
5599 individual chars of a STRING_CST from element_region to any
5600 subregion which is a concrete access of a single byte from its
5602 * region.cc (region::get_relative_concrete_byte_range): New.
5603 * region.h (region::get_relative_concrete_byte_range): New decl.
5605 2022-02-09 David Malcolm <dmalcolm@redhat.com>
5608 * region-model.cc (selftest::test_bit_range_regions): New.
5609 (selftest::analyzer_region_model_cc_tests): Call it.
5610 * region.h (bit_range_region::key_t::hash): Fix hashing of m_bits
5611 to avoid using uninitialized data.
5613 2022-02-07 David Malcolm <dmalcolm@redhat.com>
5616 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
5617 Remove overzealous assertion.
5618 (tainted_allocation_size::emit): Likewise.
5619 (region_model::check_dynamic_size_for_taint): Likewise.
5621 2022-02-07 David Malcolm <dmalcolm@redhat.com>
5624 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
5625 Reimplement in terms of a get_store_value followed by a set_value.
5627 2022-02-03 David Malcolm <dmalcolm@redhat.com>
5630 * engine.cc (exploded_graph::process_node): Use the node for any
5631 diagnostics, avoiding ICE if a bifurcation update adds a
5632 saved_diagnostic, such as for a tainted realloc size.
5633 * region-model-impl-calls.cc
5634 (region_model::impl_call_realloc::success_no_move::update_model):
5635 Require the old pointer to be non-NULL to be able successfully
5636 grow in place. Use model->deref_rvalue rather than maybe_get_region
5637 to support the old pointer being symbolic.
5638 (region_model::impl_call_realloc::success_with_move::update_model):
5639 Likewise. Add a constraint that the new pointer != the old pointer.
5640 Use a sized_region when setting the value of the new region.
5641 Handle the case where we don't know the dynamic size of the old
5642 region by marking the new region as unknown.
5643 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
5644 Update assertion to also allow for MEMSPACE_UNKNOWN.
5645 (tainted_allocation_size::emit): Likewise.
5646 (region_model::check_dynamic_size_for_taint): Likewise.
5648 2022-02-03 David Malcolm <dmalcolm@redhat.com>
5650 * region-model-impl-calls.cc (region_model::impl_call_calloc): Use
5651 a sized_region when calling zero_fill_region.
5653 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5655 * region-model.cc (region_model::on_return): Replace usage of
5656 copy_region with get_rvalue/set_value pair.
5657 (region_model::pop_frame): Likewise.
5658 (selftest::test_compound_assignment): Likewise.
5659 * region-model.h (region_model::copy_region): Delete decl.
5660 * region.cc (region_model::copy_region): Delete.
5662 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5664 * region.cc (region::calc_offset): Consolidate effectively
5667 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5669 * analyzer.h (class bit_range_region): New forward decl.
5670 * region-model-manager.cc (region_model_manager::get_bit_range):
5672 (region_model_manager::log_stats): Handle m_bit_range_regions.
5673 * region-model.cc (region_model::get_lvalue_1): Handle
5675 * region-model.h (region_model_manager::get_bit_range): New decl.
5676 (region_model_manager::m_bit_range_regions): New field.
5677 * region.cc (region::get_base_region): Handle RK_BIT_RANGE.
5678 (region::base_region_p): Likewise.
5679 (region::calc_offset): Likewise.
5680 (bit_range_region::dump_to_pp): New.
5681 (bit_range_region::get_byte_size): New.
5682 (bit_range_region::get_bit_size): New.
5683 (bit_range_region::get_byte_size_sval): New.
5684 (bit_range_region::get_relative_concrete_offset): New.
5685 * region.h (enum region_kind): Add RK_BIT_RANGE.
5686 (region::dyn_cast_bit_range_region): New vfunc.
5687 (class bit_range_region): New.
5688 (is_a_helper <const bit_range_region *>::test): New.
5689 (default_hash_traits<bit_range_region::key_t>): New.
5691 2022-02-02 David Malcolm <dmalcolm@redhat.com>
5694 * region-model.cc (region_model::on_call_pre): Handle
5697 2022-01-27 David Malcolm <dmalcolm@redhat.com>
5699 * checker-path.cc (event_kind_to_string): Handle
5701 (region_creation_event::region_creation_event): New.
5702 (region_creation_event::get_desc): New.
5703 (checker_path::add_region_creation_event): New.
5704 * checker-path.h (enum event_kind): Add EK_REGION_CREATION.
5705 (class region_creation_event): New subclass.
5706 (checker_path::add_region_creation_event): New decl.
5707 * diagnostic-manager.cc
5708 (diagnostic_manager::emit_saved_diagnostic): Pass NULL for new
5709 param to add_events_for_eedge when handling trailing eedge.
5710 (diagnostic_manager::build_emission_path): Create an interesting_t
5711 instance, allow the pending diagnostic to populate it, and pass it
5712 to the calls to add_events_for_eedge.
5713 (diagnostic_manager::add_events_for_eedge): Add "interest" param.
5714 Use it to add region_creation_events for on-stack regions created
5715 within at function entry, and when pertinent dynamically-sized
5716 regions are created.
5717 (diagnostic_manager::prune_for_sm_diagnostic): Add case for
5719 * diagnostic-manager.h (diagnostic_manager::add_events_for_eedge):
5720 Add "interest" param.
5721 * pending-diagnostic.cc: Include "selftest.h", "tristate.h",
5722 "analyzer/call-string.h", "analyzer/program-point.h",
5723 "analyzer/store.h", and "analyzer/region-model.h".
5724 (interesting_t::add_region_creation): New.
5725 (interesting_t::dump_to_pp): New.
5726 * pending-diagnostic.h (struct interesting_t): New.
5727 (pending_diagnostic::mark_interesting_stuff): New vfunc.
5729 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
5730 (poisoned_value_diagnostic::operator==): Compare m_pkind and
5731 m_src_region fields.
5732 (poisoned_value_diagnostic::mark_interesting_stuff): New.
5733 (poisoned_value_diagnostic::m_src_region): New.
5734 (region_model::check_for_poison): Call
5735 get_region_for_poisoned_expr for uninit values and pass the resul
5737 (region_model::get_region_for_poisoned_expr): New.
5738 (region_model::deref_rvalue): Pass NULL for
5739 poisoned_value_diagnostic's src_region.
5740 * region-model.h (region_model::get_region_for_poisoned_expr): New
5742 * region.h (frame_region::get_fndecl): New.
5744 2022-01-27 Martin Liska <mliska@suse.cz>
5747 * constraint-manager.cc (bounded_ranges_manager::log_stats):
5748 Cast to long for format purpose.
5749 * region-model-manager.cc (log_uniq_map): Likewise.
5751 2022-01-26 David Malcolm <dmalcolm@redhat.com>
5754 * region-model.cc (region_model::check_call_args): New.
5755 (region_model::on_call_pre): Call it when ignoring stdio builtins.
5756 * region-model.h (region_model::check_call_args): New decl
5758 2022-01-26 David Malcolm <dmalcolm@redhat.com>
5761 * constraint-manager.cc (range::add_bound): Fix tests for
5762 discarding redundant constraints. Perform test for rejecting
5763 unsatisfiable constraints earlier so that they don't update
5764 the object on failure.
5765 (selftest::test_range): New.
5766 (selftest::test_constant_comparisons): Add test coverage for
5767 existing constraints becoming narrower until they are
5769 (selftest::run_constraint_manager_tests): Call test_range.
5771 2022-01-22 David Malcolm <dmalcolm@redhat.com>
5774 * region-model-manager.cc
5775 (region_model_manager::get_or_create_cast): Bail out if the types
5776 are the same. Don't attempt to handle casts involving vector
5779 2022-01-20 David Malcolm <dmalcolm@redhat.com>
5782 * constraint-manager.cc (bound::ensure_closed): Convert param to
5784 (range::constrained_to_single_element): Likewise.
5785 (range::add_bound): New.
5786 (constraint_manager::add_constraint): Handle SVAL + OFFSET
5787 compared to a constant.
5788 (constraint_manager::get_ec_bounds): Rewrite in terms of
5790 (constraint_manager::eval_condition): Reject if range::add_bound
5792 (selftest::test_constant_comparisons): Add test coverage for
5793 various impossible combinations of integer comparisons.
5794 * constraint-manager.h (enum bound_kind): New.
5795 (struct bound): Likewise.
5796 (bound::ensure_closed): Convert to param to enum bound_kind.
5797 (struct range): Convert to...
5798 (class range): ...this, making fields private.
5799 (range::add_bound): New decls.
5800 * region-model.cc (region_model::add_constraint): Fail if
5801 constraint_manager::add_constraint fails.
5803 2022-01-18 David Malcolm <dmalcolm@redhat.com>
5806 * region-model-manager.cc
5807 (region_model_manager::get_or_create_constant_svalue): Assert that
5808 we have a CONSTANT_CLASS_P.
5809 (region_model_manager::maybe_fold_unaryop): Only fold a constant
5810 when fold_unary's result is a constant or a cast of a constant.
5812 2022-01-18 David Malcolm <dmalcolm@redhat.com>
5815 * region-model-manager.cc
5816 (region_model_manager::maybe_fold_sub_svalue): Avoid casting to
5817 NULL type when folding access to repeated svalue.
5819 2022-01-17 Martin Liska <mliska@suse.cz>
5821 * analyzer.cc (is_special_named_call_p): Rename .c names to .cc.
5822 (is_named_call_p): Likewise.
5823 * region-model-asm.cc (deterministic_p): Likewise.
5824 * region.cc (field_region::get_relative_concrete_offset): Likewise.
5825 * sm-malloc.cc (method_p): Likewise.
5826 * supergraph.cc (superedge::dump_dot): Likewise.
5828 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5830 * sm-taint.cc (taint_state_machine::combine_states): Handle combination
5831 of has_ub and has_lb.
5833 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5836 * sm-taint.cc (taint_state_machine::alt_get_inherited_state):
5837 Remove gcc_unreachable from default case for unary ops.
5839 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5841 * engine.cc: Include "stringpool.h", "attribs.h", and
5843 (mark_params_as_tainted): New.
5844 (class tainted_args_function_custom_event): New.
5845 (class tainted_args_function_info): New.
5846 (exploded_graph::add_function_entry): Handle functions with
5847 "tainted_args" attribute.
5848 (class tainted_args_field_custom_event): New.
5849 (class tainted_args_callback_custom_event): New.
5850 (class tainted_args_call_info): New.
5851 (add_tainted_args_callback): New.
5852 (add_any_callbacks): New.
5853 (exploded_graph::build_initial_worklist): Likewise.
5854 (exploded_graph::build_initial_worklist): Find callbacks that are
5855 reachable from global initializers, calling add_any_callbacks on
5858 2022-01-12 David Malcolm <dmalcolm@redhat.com>
5861 * engine.cc (impl_sm_context::impl_sm_context): Add
5862 "unknown_side_effects" param and use it to initialize
5863 new m_unknown_side_effects field.
5864 (impl_sm_context::unknown_side_effects_p): New.
5865 (impl_sm_context::m_unknown_side_effects): New.
5866 (exploded_node::on_stmt): Pass unknown_side_effects to sm_ctxt
5868 * sm-taint.cc: Include "stringpool.h" and "attribs.h".
5869 (tainted_size::tainted_size): Drop "dir" param.
5870 (tainted_size::get_kind): Drop "FINAL".
5871 (tainted_size::emit): Likewise.
5872 (tainted_size::m_dir): Drop unused field.
5873 (class tainted_access_attrib_size): New subclass.
5874 (taint_state_machine::on_stmt): Call check_for_tainted_size_arg on
5875 external functions with unknown side effects.
5876 (taint_state_machine::check_for_tainted_size_arg): New.
5877 (region_model::check_region_for_taint): Drop "dir" param from
5879 * sm.h (sm_context::unknown_side_effects_p): New.
5881 2022-01-11 David Malcolm <dmalcolm@redhat.com>
5884 * diagnostic-manager.cc
5885 (class auto_disable_complexity_checks): Rename to...
5886 (class auto_checking_feasibility): ...this, updating
5887 the calls accordingly.
5888 (epath_finder::explore_feasible_paths): Update for renaming.
5889 * region-model-manager.cc
5890 (region_model_manager::region_model_manager): Update for change from
5891 m_check_complexity to m_checking_feasibility.
5892 (region_model_manager::reject_if_too_complex): Likewise.
5893 (region_model_manager::get_or_create_unknown_svalue): Handle
5894 m_checking_feasibility.
5895 (region_model_manager::create_unique_svalue): New.
5896 (region_model_manager::maybe_fold_binop): Handle BIT_AND_EXPR and
5897 BIT_IOR_EXPRs on booleans where we know the result.
5898 * region-model.cc (test_binop_svalue_folding): Add test coverage
5900 * region-model.h (region_model_manager::create_unique_svalue): New
5902 (region_model_manager::enable_complexity_check): Replace with...
5903 (region_model_manager::begin_checking_feasibility): ...this.
5904 (region_model_manager::disable_complexity_check): Replace with...
5905 (region_model_manager::end_checking_feasibility): ...this.
5906 (region_model_manager::m_check_complexity): Replace with...
5907 (region_model_manager::m_checking_feasibility): ...this.
5908 (region_model_manager::m_managed_dynamic_svalues): New field.
5910 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5912 * engine.cc (impl_run_checkers): Pass logger to engine ctor.
5913 * region-model-manager.cc
5914 (region_model_manager::region_model_manager): Add logger param and
5915 use it to initialize m_logger.
5916 * region-model.cc (engine::engine): New.
5917 * region-model.h (region_model_manager::region_model_manager):
5919 (region_model_manager::get_logger): New.
5920 (region_model_manager::m_logger): New field.
5921 (engine::engine): New.
5922 * store.cc (store_manager::get_logger): New.
5923 (store::set_value): Log scope. Log when marking a cluster as
5924 unknown due to possible aliasing.
5925 * store.h (store_manager::get_logger): New decl.
5927 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5929 * region-model-impl-calls.cc (cmp_decls): New.
5930 (cmp_decls_ptr_ptr): New.
5931 (region_model::impl_call_analyzer_dump_escaped): New.
5932 * region-model.cc (region_model::on_stmt_pre): Handle
5933 __analyzer_dump_escaped.
5934 * region-model.h (region_model::impl_call_analyzer_dump_escaped):
5936 * store.h (binding_cluster::get_base_region): New accessor.
5938 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5940 * region.cc (region::is_named_decl_p): New.
5941 * region.h (region::is_named_decl_p): New decl.
5943 2022-01-06 David Malcolm <dmalcolm@redhat.com>
5946 * store.cc (store::eval_alias_1): Refactor handling of decl
5947 regions, adding a test for may_be_aliased, rejecting those for
5948 which it returns false.
5950 2021-12-12 Jonathan Wakely <jwakely@redhat.com>
5952 * engine.cc: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
5954 2021-12-06 David Malcolm <dmalcolm@redhat.com>
5957 * constraint-manager.cc (equiv_class::contains_non_constant_p):
5959 (constraint_manager::canonicalize): Call it when determining
5961 (selftest::test_purging): New selftest.
5962 (selftest::run_constraint_manager_tests): Likewise.
5963 * constraint-manager.h (equiv_class::contains_non_constant_p):
5966 2021-12-01 David Malcolm <dmalcolm@redhat.com>
5969 * region-model-reachability.cc (reachable_regions::handle_parm):
5970 Treat all svalues within a compound parm has reachable, and those
5973 2021-11-29 David Malcolm <dmalcolm@redhat.com>
5976 * store.cc (binding_cluster::can_merge_p): For the "key is bound"
5977 vs "key is not bound" merger case, check that the bound svalue
5978 is mergeable before merging it to "unknown", rejecting the merger
5981 2021-11-19 David Malcolm <dmalcolm@redhat.com>
5984 * engine.cc (exploded_graph::get_or_create_node): Pass in
5985 m_ext_state to program_state::can_merge_with_p.
5986 (exploded_graph::process_worklist): Likewise.
5987 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
5989 (exploded_graph::process_node): Add missing call to detect_leaks
5990 when handling phi nodes.
5991 * program-state.cc (program_state::can_merge_with_p): Add
5992 "ext_state" param. Pass it and state ptrs to
5993 region_model::can_merge_with_p.
5994 (selftest::test_program_state_merging): Update for new ext_state
5995 param of program_state::can_merge_with_p.
5996 (selftest::test_program_state_merging_2): Likewise.
5997 * program-state.h (program_state::can_purge_p): Make const.
5998 (program_state::can_merge_with_p): Add "ext_state" param.
5999 * region-model.cc: Include "analyzer/program-state.h".
6000 (region_model::can_merge_with_p): Add params "ext_state",
6001 "state_a", and "state_b", use them when creating model_merger
6003 (model_merger::mergeable_svalue_p): New.
6004 * region-model.h (region_model::can_merge_with_p): Add params
6005 "ext_state", "state_a", and "state_b".
6006 (model_merger::model_merger) Likewise, initializing new fields.
6007 (model_merger::mergeable_svalue_p): New decl.
6008 (model_merger::m_ext_state): New field.
6009 (model_merger::m_state_a): New field.
6010 (model_merger::m_state_b): New field.
6011 * svalue.cc (svalue::can_merge_p): Call
6012 model_merger::mergeable_svalue_p on both states and reject the
6015 2021-11-17 David Malcolm <dmalcolm@redhat.com>
6018 * region-model-impl-calls.cc (region_model::impl_call_strchr): New.
6019 * region-model-manager.cc
6020 (region_model_manager::maybe_fold_unaryop): Simplify cast to
6021 pointer type of an existing pointer to a region.
6022 * region-model.cc (region_model::on_call_pre): Handle
6023 BUILT_IN_STRCHR and "strchr".
6024 (write_to_const_diagnostic::emit): Add auto_diagnostic_group. Add
6025 alternate wordings for functions and labels.
6026 (write_to_const_diagnostic::describe_final_event): Add alternate
6027 wordings for functions and labels.
6028 (region_model::check_for_writable_region): Handle RK_FUNCTION and
6030 * region-model.h (region_model::impl_call_strchr): New decl.
6032 2021-11-16 David Malcolm <dmalcolm@redhat.com>
6035 * constraint-manager.cc (bounded_range::operator==): Require the
6036 types to be the same for equality.
6038 2021-11-13 David Malcolm <dmalcolm@redhat.com>
6040 * analyzer.opt (Wanalyzer-tainted-allocation-size): New.
6041 (Wanalyzer-tainted-divisor): New.
6042 (Wanalyzer-tainted-offset): New.
6043 (Wanalyzer-tainted-size): New.
6044 * engine.cc (impl_region_model_context::get_taint_map): New.
6045 * exploded-graph.h (impl_region_model_context::get_taint_map):
6047 * program-state.cc (sm_state_map::get_state): Call
6048 alt_get_inherited_state.
6049 (sm_state_map::impl_set_state): Modify states within
6051 (program_state::impl_call_analyzer_dump_state): Undo casts.
6052 (selftest::test_program_state_1): Update for new context param of
6053 create_region_for_heap_alloc.
6054 (selftest::test_program_state_merging): Likewise.
6055 * region-model-impl-calls.cc (region_model::impl_call_alloca):
6057 (region_model::impl_call_calloc): Likewise.
6058 (region_model::impl_call_malloc): Likewise.
6059 (region_model::impl_call_operator_new): Likewise.
6060 (region_model::impl_call_realloc): Likewise.
6061 * region-model.cc (region_model::check_region_access): Call
6062 check_region_for_taint.
6063 (region_model::get_representative_path_var_1): Handle binops.
6064 (region_model::create_region_for_heap_alloc): Add "ctxt" param and
6065 pass it to set_dynamic_extents.
6066 (region_model::create_region_for_alloca): Likewise.
6067 (region_model::set_dynamic_extents): Add "ctxt" param and use it
6068 to call check_dynamic_size_for_taint.
6069 (selftest::test_state_merging): Update for new context param of
6070 create_region_for_heap_alloc.
6071 (selftest::test_malloc_constraints): Likewise.
6072 (selftest::test_malloc): Likewise.
6073 (selftest::test_alloca): Likewise for create_region_for_alloca.
6074 * region-model.h (region_model::create_region_for_heap_alloc): Add
6076 (region_model::create_region_for_alloca): Likewise.
6077 (region_model::set_dynamic_extents): Likewise.
6078 (region_model::check_dynamic_size_for_taint): New decl.
6079 (region_model::check_region_for_taint): New decl.
6080 (region_model_context::get_taint_map): New vfunc.
6081 (noop_region_model_context::get_taint_map): New.
6082 * sm-taint.cc: Remove include of "diagnostic-event-id.h"; add
6083 includes of "gimple-iterator.h", "tristate.h", "selftest.h",
6084 "ordered-hash-map.h", "cgraph.h", "cfg.h", "digraph.h",
6085 "analyzer/supergraph.h", "analyzer/call-string.h",
6086 "analyzer/program-point.h", "analyzer/store.h",
6087 "analyzer/region-model.h", and "analyzer/program-state.h".
6088 (enum bounds): Move to top of file.
6089 (class taint_diagnostic): New.
6090 (class tainted_array_index): Convert to subclass of taint_diagnostic.
6091 (tainted_array_index::emit): Add CWE-129. Reword warning to use
6092 "attacker-controlled" rather than "tainted".
6093 (tainted_array_index::describe_state_change): Move to
6094 taint_diagnostic::describe_state_change.
6095 (tainted_array_index::describe_final_event): Reword to use
6096 "attacker-controlled" rather than "tainted".
6097 (class tainted_offset): New.
6098 (class tainted_size): New.
6099 (class tainted_divisor): New.
6100 (class tainted_allocation_size): New.
6101 (taint_state_machine::alt_get_inherited_state): New.
6102 (taint_state_machine::on_stmt): In assignment handling, remove
6103 ARRAY_REF handling in favor of check_region_for_taint. Add
6104 detection of tainted divisors.
6105 (taint_state_machine::get_taint): New.
6106 (taint_state_machine::combine_states): New.
6107 (region_model::check_region_for_taint): New.
6108 (region_model::check_dynamic_size_for_taint): New.
6109 * sm.h (state_machine::alt_get_inherited_state): New.
6111 2021-11-12 David Malcolm <dmalcolm@redhat.com>
6113 * engine.cc (exploded_node::on_stmt_pre): Return when handling
6114 "__analyzer_dump_state".
6116 2021-11-11 Richard Biener <rguenther@suse.de>
6118 * supergraph.cc: Include bitmap.h.
6120 2021-11-04 David Malcolm <dmalcolm@redhat.com>
6122 * program-state.cc (sm_state_map::dump): Use default_tree_printer
6125 2021-09-16 Maxim Blinov <maxim.blinov@embecosm.com>
6128 * engine.cc (INCLUDE_UNIQUE_PTR): Define.
6130 2021-09-08 David Malcolm <dmalcolm@redhat.com>
6133 * analyzer.h (compat_types_p): New decl.
6134 * constraint-manager.cc
6135 (constraint_manager::get_or_add_equiv_class): Guard against NULL
6136 type when checking for pointer types.
6137 * region-model-impl-calls.cc (region_model::impl_call_realloc):
6138 Guard against NULL lhs type/region. Guard against the size value
6139 not being of a compatible type for dynamic extents.
6140 * region-model.cc (compat_types_p): Make non-static.
6142 2021-08-30 David Malcolm <dmalcolm@redhat.com>
6145 * analyzer.h (class custom_edge_info): New class, adapted from
6146 exploded_edge::custom_info_t. Make member functions const.
6147 Make update_model return bool, converting edge param from
6148 reference to a pointer, and adding a ctxt param.
6149 (class path_context): New class.
6150 * call-info.cc: New file.
6151 * call-info.h: New file.
6152 * engine.cc: Include "analyzer/call-info.h" and <memory>.
6153 (impl_region_model_context::impl_region_model_context): Update for
6154 new m_path_ctxt field.
6155 (impl_region_model_context::bifurcate): New.
6156 (impl_region_model_context::terminate_path): New.
6157 (impl_region_model_context::get_malloc_map): New.
6158 (impl_sm_context::impl_sm_context): Update for new m_path_ctxt
6160 (impl_sm_context::get_fndecl_for_call): Likewise.
6161 (impl_sm_context::set_next_state): Likewise.
6162 (impl_sm_context::warn): Likewise.
6163 (impl_sm_context::is_zero_assignment): Likewise.
6164 (impl_sm_context::get_path_context): New.
6165 (impl_sm_context::m_path_ctxt): New.
6166 (impl_region_model_context::on_condition): Update for new
6167 path_ctxt param. Handle m_enode_for_diag being NULL.
6168 (impl_region_model_context::on_phi): Update for new path_ctxt
6170 (exploded_node::on_stmt): Add path_ctxt param, updating ctor calls
6171 to use it as necessary. Use it to bail out after sm-handling,
6173 (exploded_node::detect_leaks): Update for new path_ctxt param.
6174 (dynamic_call_info_t::update_model): Update for conversion of
6175 exploded_edge::custom_info_t to custom_edge_info.
6176 (dynamic_call_info_t::add_events_to_path): Likewise.
6177 (rewind_info_t::update_model): Likewise.
6178 (rewind_info_t::add_events_to_path): Likewise.
6179 (exploded_edge::exploded_edge): Likewise.
6180 (exploded_graph::add_edge): Likewise.
6181 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
6182 Update for new path_ctxt param.
6183 (class impl_path_context): New.
6184 (exploded_graph::process_node): Update for new path_ctxt param.
6185 Create an impl_path_context and pass it to exploded_node::on_stmt.
6186 Use it to terminate iterating stmts if terminate_path is called
6187 on it. After processing a run of stmts, query path_ctxt to
6188 potentially terminate the analysis path, and/or to "bifurcate" the
6189 analysis into multiple additional paths.
6190 (feasibility_state::maybe_update_for_edge): Update for new
6191 update_model ctxt param.
6193 (impl_region_model_context::impl_region_model_context): Add
6195 (impl_region_model_context::bifurcate): New.
6196 (impl_region_model_context::terminate_path): New
6197 (impl_region_model_context::get_ext_state): New.
6198 (impl_region_model_context::get_malloc_map): New.
6199 (impl_region_model_context::m_path_ctxt): New field.
6200 (exploded_node::on_stmt): Add path_ctxt param.
6201 (class exploded_edge::custom_info_t): Move to analyzer.h, renaming
6202 to custom_edge_info, and making the changes as noted in analyzer.h
6204 (exploded_edge::exploded_edge): Update for these changes to
6205 exploded_edge::custom_info_t.
6206 (exploded_edge::m_custom_info): Likewise.
6207 (class dynamic_call_info_t): Likewise.
6208 (class rewind_info_t): Likewise.
6209 (exploded_graph::add_edge): Likewise.
6210 * program-state.cc (program_state::on_edge): Update for new
6212 (program_state::push_call): Likewise.
6213 (program_state::returning_call): Likewise.
6214 (program_state::prune_for_point): Likewise.
6215 * region-model-impl-calls.cc: Include "analyzer/call-info.h".
6216 (call_details::get_fndecl_for_call): New.
6217 (region_model::impl_call_realloc): Reimplement.
6218 * region-model.cc (region_model::on_call_pre): Move call to
6219 impl_call_realloc to...
6220 (region_model::on_call_post): ...here. Consolidate creation
6221 of call_details instance.
6222 (noop_region_model_context::bifurcate): New.
6223 (noop_region_model_context::terminate_path): New.
6224 * region-model.h (call_details::get_call_stmt): New.
6225 (call_details::get_fndecl_for_call): New.
6226 (region_model::on_realloc_with_move): New.
6227 (region_model_context::bifurcate): New.
6228 (region_model_context::terminate_path): New.
6229 (region_model_context::get_ext_state): New.
6230 (region_model_context::get_malloc_map): New.
6231 (noop_region_model_context::bifurcate): New.
6232 (noop_region_model_context::terminate_path): New.
6233 (noop_region_model_context::get_ext_state): New.
6234 (noop_region_model_context::get_malloc_map): New.
6235 * sm-malloc.cc: Include "analyzer/program-state.h".
6236 (malloc_state_machine::on_realloc_call): Reimplement.
6237 (malloc_state_machine::on_realloc_with_move): New.
6238 (region_model::on_realloc_with_move): New.
6239 * sm-signal.cc (class signal_delivery_edge_info_t): Update for
6240 conversion from exploded_edge::custom_info_t to custom_edge_info.
6241 * sm.h (sm_context::get_path_context): New.
6242 * svalue.cc (svalue::maybe_get_constant): Call
6243 unwrap_any_unmergeable.
6245 2021-08-25 Ankur Saini <arsenic@sourceware.org>
6248 * engine.cc (exploded_graph::maybe_create_dynamic_call): Don't create
6249 calls if max recursion limit is reached.
6251 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6253 * analyzer.h (struct rejected_constraint): Convert to...
6254 (class rejected_constraint): ...this.
6255 (class bounded_ranges): New forward decl.
6256 (class bounded_ranges_manager): New forward decl.
6257 * constraint-manager.cc: Include "analyzer/analyzer-logging.h" and
6258 "tree-pretty-print.h".
6259 (can_plus_one_p): New.
6261 (can_minus_one_p): New.
6263 (bounded_range::bounded_range): New.
6265 (bounded_range::dump_to_pp): New.
6266 (bounded_range::dump): New.
6267 (bounded_range::to_json): New.
6268 (bounded_range::set_json_attr): New.
6269 (bounded_range::contains_p): New.
6270 (bounded_range::intersects_p): New.
6271 (bounded_range::operator==): New.
6272 (bounded_range::cmp): New.
6273 (bounded_ranges::bounded_ranges): New.
6274 (bounded_ranges::bounded_ranges): New.
6275 (bounded_ranges::bounded_ranges): New.
6276 (bounded_ranges::canonicalize): New.
6277 (bounded_ranges::validate): New.
6278 (bounded_ranges::operator==): New.
6279 (bounded_ranges::dump_to_pp): New.
6280 (bounded_ranges::dump): New.
6281 (bounded_ranges::to_json): New.
6282 (bounded_ranges::eval_condition): New.
6283 (bounded_ranges::contain_p): New.
6284 (bounded_ranges::cmp): New.
6285 (bounded_ranges_manager::~bounded_ranges_manager): New.
6286 (bounded_ranges_manager::get_or_create_empty): New.
6287 (bounded_ranges_manager::get_or_create_point): New.
6288 (bounded_ranges_manager::get_or_create_range): New.
6289 (bounded_ranges_manager::get_or_create_union): New.
6290 (bounded_ranges_manager::get_or_create_intersection): New.
6291 (bounded_ranges_manager::get_or_create_inverse): New.
6292 (bounded_ranges_manager::consolidate): New.
6293 (bounded_ranges_manager::get_or_create_ranges_for_switch): New.
6294 (bounded_ranges_manager::create_ranges_for_switch): New.
6295 (bounded_ranges_manager::make_case_label_ranges): New.
6296 (bounded_ranges_manager::log_stats): New.
6297 (bounded_ranges_constraint::print): New.
6298 (bounded_ranges_constraint::to_json): New.
6299 (bounded_ranges_constraint::operator==): New.
6300 (bounded_ranges_constraint::add_to_hash): New.
6301 (constraint_manager::constraint_manager): Update for new field
6302 m_bounded_ranges_constraints.
6303 (constraint_manager::operator=): Likewise.
6304 (constraint_manager::hash): Likewise.
6305 (constraint_manager::operator==): Likewise.
6306 (constraint_manager::print): Likewise.
6307 (constraint_manager::dump_to_pp): Likewise.
6308 (constraint_manager::to_json): Likewise.
6309 (constraint_manager::add_unknown_constraint): Update the lhs_ec_id
6310 if necessary in existing constraints when combining equivalence
6311 classes. Add similar code for handling
6312 m_bounded_ranges_constraints.
6313 (constraint_manager::add_constraint_internal): Add comment.
6314 (constraint_manager::add_bounded_ranges): New.
6315 (constraint_manager::eval_condition): Use new field
6316 m_bounded_ranges_constraints.
6317 (constraint_manager::purge): Update bounded_ranges_constraint
6319 (constraint_manager::canonicalize): Update for new field.
6320 (merger_fact_visitor::on_ranges): New.
6321 (constraint_manager::for_each_fact): Use new field
6322 m_bounded_ranges_constraints.
6323 (constraint_manager::validate): Fix off-by-one error needed due
6324 to bug fixed above in add_unknown_constraint. Validate the EC IDs
6325 in m_bounded_ranges_constraints.
6326 (constraint_manager::get_range_manager): New.
6327 (selftest::assert_dump_bounded_range_eq): New.
6328 (ASSERT_DUMP_BOUNDED_RANGE_EQ): New.
6329 (selftest::test_bounded_range): New.
6330 (selftest::assert_dump_bounded_ranges_eq): New.
6331 (ASSERT_DUMP_BOUNDED_RANGES_EQ): New.
6332 (selftest::test_bounded_ranges): New.
6333 (selftest::run_constraint_manager_tests): Call the new selftests.
6334 * constraint-manager.h (struct bounded_range): New.
6335 (struct bounded_ranges): New.
6336 (template <> struct default_hash_traits<bounded_ranges::key_t>): New.
6337 (class bounded_ranges_manager): New.
6338 (fact_visitor::on_ranges): New pure virtual function.
6339 (class bounded_ranges_constraint): New.
6340 (constraint_manager::add_bounded_ranges): New decl.
6341 (constraint_manager::get_range_manager): New decl.
6342 (constraint_manager::m_bounded_ranges_constraints): New field.
6343 * diagnostic-manager.cc (epath_finder::process_worklist_item):
6344 Transfer ownership of rc to add_feasibility_problem.
6345 * engine.cc (feasibility_problem::dump_to_pp): Use get_model.
6346 * feasible-graph.cc (infeasible_node::dump_dot): Update for
6347 conversion of m_rc to a pointer.
6348 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
6350 * feasible-graph.h (infeasible_node::infeasible_node): Pass RC by
6351 pointer and take ownership.
6352 (infeasible_node::~infeasible_node): New.
6353 (infeasible_node::m_rc): Convert to a pointer.
6354 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
6356 * region-model-manager.cc: Include
6357 "analyzer/constraint-manager.h".
6358 (region_model_manager::region_model_manager): Initializer new
6360 (region_model_manager::~region_model_manager): Delete it.
6361 (region_model_manager::log_stats): Call log_stats on it.
6362 * region-model.cc (region_model::add_constraint): Use new subclass
6363 rejected_op_constraint.
6364 (region_model::apply_constraints_for_gswitch): Reimplement using
6365 bounded_ranges_manager.
6366 (rejected_constraint::dump_to_pp): Convert to...
6367 (rejected_op_constraint::dump_to_pp): ...this.
6368 (rejected_ranges_constraint::dump_to_pp): New.
6369 * region-model.h (struct purge_stats): Add field
6370 m_num_bounded_ranges_constraints.
6371 (region_model_manager::get_range_manager): New.
6372 (region_model_manager::m_range_mgr): New.
6373 (region_model::get_range_manager): New.
6374 (struct rejected_constraint): Split into...
6375 (class rejected_constraint):...this new abstract base class,
6377 (class rejected_op_constraint): ...this new concrete subclass.
6378 (class rejected_ranges_constraint): New.
6379 * supergraph.cc: Include "tree-cfg.h".
6380 (supergraph::supergraph): Drop idx param from add_cfg_edge.
6381 (supergraph::add_cfg_edge): Drop idx param.
6382 (switch_cfg_superedge::switch_cfg_superedge): Move here from
6383 header. Populate m_case_labels with all cases which go to DST.
6384 (switch_cfg_superedge::dump_label_to_pp): Reimplement to use
6386 (switch_cfg_superedge::get_case_label): Delete.
6387 * supergraph.h (supergraphadd_cfg_edge): Drop "idx" param.
6388 (switch_cfg_superedge::switch_cfg_superedge): Drop idx param and
6389 move implementation to supergraph.cc.
6390 (switch_cfg_superedge::get_case_label): Delete.
6391 (switch_cfg_superedge::get_case_labels): New.
6392 (switch_cfg_superedge::m_idx): Delete.
6393 (switch_cfg_superedge::m_case_labels): New field.
6395 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6398 * sm-file.cc (file_diagnostic::describe_state_change): Handle
6399 change.m_expr being NULL.
6401 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6404 * analyzer.cc (maybe_reconstruct_from_def_stmt): Bail if fn is
6405 NULL, and assert that it's non-NULL before passing it to
6406 build_call_array_loc.
6408 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6411 * region-model.cc (region_model::eval_condition_without_cm):
6412 Refactor comparison against zero, adding a check for
6413 POINTER_PLUS_EXPR of non-NULL.
6415 2021-08-23 David Malcolm <dmalcolm@redhat.com>
6417 * store.cc (bit_range::intersects_p): New overload.
6418 (bit_range::operator-): New.
6419 (binding_cluster::maybe_get_compound_binding): Handle the partial
6421 (selftest::test_bit_range_intersects_p): Add test coverage for
6422 new overload of bit_range::intersects_p.
6423 * store.h (bit_range::intersects_p): New overload.
6424 (bit_range::operator-): New.
6426 2021-08-23 Ankur Saini <arsenic@sourceware.org>
6429 * diagnostic-manager.cc
6430 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Fix typo.
6432 2021-08-21 Ankur Saini <arsenic@sourceware.org>
6435 * diagnostic-manager.cc
6436 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Use
6437 caller_model only when the supergraph_edge doesn't exixt.
6438 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
6440 * engine.cc (exploded_graph::create_dynamic_call): Rename to...
6441 (exploded_graph::maybe_create_dynamic_call): ...this, return call
6443 (exploded_graph::process_node): Handle calls which were not dynamically
6445 * exploded-graph.h (exploded_graph::create_dynamic_call): Rename to...
6446 (exploded_graph::maybe_create_dynamic_call): ...this.
6447 * region-model.cc (region_model::update_for_gcall): New param, use it
6448 to push call to frame.
6449 (region_model::update_for_call_superedge): Pass callee function to
6451 * region-model.h (region_model::update_for_gcall): New param.
6453 2021-08-18 Ankur Saini <arsenic@sourceware.org>
6456 * region-model.cc (region_model::get_rvalue_1): Add case for
6459 2021-08-18 Ankur Saini <arsenic@sourceware.org>
6462 * analysis-plan.cc (analysis_plan::use_summary_p): Don't use call
6463 summaries if there is no callgraph edge
6464 * checker-path.cc (call_event::call_event): Handle calls events that
6465 are not represented by a supergraph call edge
6466 (return_event::return_event): Likewise.
6467 (call_event::get_desc): Work with new call_event structure.
6468 (return_event::get_desc): Likeise.
6469 * checker-path.h (call_event::m_src_snode): New field.
6470 (call_event::m_dest_snode): New field.
6471 (return_event::m_src_snode): New field.
6472 (return_event::m_dest_snode): New field.
6473 * diagnostic-manager.cc
6474 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>:
6475 Refactor to work with edges without callgraph edge.
6476 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
6478 * engine.cc (dynamic_call_info_t::update_model): New function.
6479 (dynamic_call_info_t::add_events_to_path): New function.
6480 (exploded_graph::create_dynamic_call): New function.
6481 (exploded_graph::process_node): Work with dynamically discovered calls.
6482 * exploded-graph.h (class dynamic_call_info_t): New class.
6483 (exploded_graph::create_dynamic_call): New decl.
6484 * program-point.cc (program_point::push_to_call_stack): New function.
6485 (program_point::pop_from_call_stack): New function.
6486 * program-point.h (program_point::push_to_call_stack): New decl.
6487 (program_point::pop_from_call_stack): New decl.
6488 * program-state.cc (program_state::push_call): New function.
6489 (program_state::returning_call): New function.
6490 * program-state.h (program_state::push_call): New decl.
6491 (program_state::returning_call): New decl.
6492 * region-model.cc (region_model::update_for_gcall) New function.
6493 (region_model::update_for_return_gcall): New function.
6494 (egion_model::update_for_call_superedge): Get the underlying gcall and
6496 (region_model::update_for_return_superedge): Likewise.
6497 * region-model.h (region_model::update_for_gcall): New decl.
6498 (region_model::update_for_return_gcall): New decl.
6499 * state-purge.cc (state_purge_per_ssa_name::process_point): Update to
6500 work with calls without underlying cgraph edge.
6501 * supergraph.cc (supergraph::supergraph) Split snodes at every callsite.
6502 * supergraph.h (supernode::get_returning_call) New accessor.
6504 2021-08-04 David Malcolm <dmalcolm@redhat.com>
6507 * analyzer.cc (maybe_reconstruct_from_def_stmt): Add GIMPLE_ASM
6509 * analyzer.h (class asm_output_svalue): New forward decl.
6510 (class reachable_regions): New forward decl.
6511 * complexity.cc (complexity::from_vec_svalue): New.
6512 * complexity.h (complexity::from_vec_svalue): New decl.
6513 * engine.cc (feasibility_state::maybe_update_for_edge): Handle
6514 asm stmts by calling on_asm_stmt.
6515 * region-model-asm.cc: New file.
6516 * region-model-manager.cc
6517 (region_model_manager::maybe_fold_asm_output_svalue): New.
6518 (region_model_manager::get_or_create_asm_output_svalue): New.
6519 (region_model_manager::log_stats): Log m_asm_output_values_map.
6520 * region-model.cc (region_model::on_stmt_pre): Handle GIMPLE_ASM.
6521 * region-model.h (visitor::visit_asm_output_svalue): New.
6522 (region_model_manager::get_or_create_asm_output_svalue): New decl.
6523 (region_model_manager::maybe_fold_asm_output_svalue): New decl.
6524 (region_model_manager::asm_output_values_map_t): New typedef.
6525 (region_model_manager::m_asm_output_values_map): New field.
6526 (region_model::on_asm_stmt): New.
6527 * store.cc (binding_cluster::on_asm): New.
6528 * store.h (binding_cluster::on_asm): New decl.
6529 * svalue.cc (svalue::cmp_ptr): Handle SK_ASM_OUTPUT.
6530 (asm_output_svalue::dump_to_pp): New.
6531 (asm_output_svalue::dump_input): New.
6532 (asm_output_svalue::input_idx_to_asm_idx): New.
6533 (asm_output_svalue::accept): New.
6534 * svalue.h (enum svalue_kind): Add SK_ASM_OUTPUT.
6535 (svalue::dyn_cast_asm_output_svalue): New.
6536 (class asm_output_svalue): New.
6537 (is_a_helper <const asm_output_svalue *>::test): New.
6538 (struct default_hash_traits<asm_output_svalue::key_t>): New.
6540 2021-08-03 Jakub Jelinek <jakub@redhat.com>
6543 * sm-malloc.cc (known_allocator_p): Only check DECL_FUNCTION_CODE on
6544 BUILT_IN_NORMAL builtins.
6546 2021-07-29 Ankur Saini <arsenic@sourceware.org>
6548 * call-string.cc (call_string::element_t::operator==): New operator.
6549 (call_String::element_t::operator!=): New operator.
6550 (call_string::element_t::get_caller_function): New function.
6551 (call_string::element_t::get_callee_function): New function.
6552 (call_string::call_string): Refactor to Initialise m_elements.
6553 (call_string::operator=): Refactor to work with m_elements.
6554 (call_string::operator==): Likewise.
6555 (call_string::to_json): Likewise.
6556 (call_string::hash): Refactor to hash e.m_caller.
6557 (call_string::push_call): Refactor to work with m_elements.
6558 (call_string::push_call): New overload to push call via supernodes.
6559 (call_string::pop): Refactor to work with m_elements.
6560 (call_string::calc_recursion_depth): Likewise.
6561 (call_string::cmp): Likewise.
6562 (call_string::validate): Likewise.
6563 (call_string::operator[]): Likewise.
6564 * call-string.h (class supernode): New forward decl.
6565 (struct call_string::element_t): New struct.
6566 (call_string::call_string): Refactor to initialise m_elements.
6567 (call_string::bool empty_p): Refactor to work with m_elements.
6568 (call_string::get_callee_node): New decl.
6569 (call_string::get_caller_node): New decl.
6570 (m_elements): Replaces m_return_edges.
6571 * program-point.cc (program_point::get_function_at_depth): Refactor to
6572 work with new call-string format.
6573 (program_point::validate): Likewise.
6574 (program_point::on_edge): Likewise.
6576 2021-07-28 David Malcolm <dmalcolm@redhat.com>
6578 * region-model.cc (region_model::on_call_pre): Treat
6579 IFN_UBSAN_BOUNDS, BUILT_IN_STACK_SAVE, and BUILT_IN_STACK_RESTORE
6580 as no-ops, rather than handling them as unknown functions.
6582 2021-07-28 David Malcolm <dmalcolm@redhat.com>
6584 * region-model-impl-calls.cc (region_model::impl_call_alloca):
6585 Drop redundant return value.
6586 (region_model::impl_call_builtin_expect): Likewise.
6587 (region_model::impl_call_calloc): Likewise.
6588 (region_model::impl_call_malloc): Likewise.
6589 (region_model::impl_call_memset): Likewise.
6590 (region_model::impl_call_operator_new): Likewise.
6591 (region_model::impl_call_operator_delete): Likewise.
6592 (region_model::impl_call_strlen): Likewise.
6593 * region-model.cc (region_model::on_call_pre): Fix return value of
6594 known functions that don't have unknown side-effects.
6595 * region-model.h (region_model::impl_call_alloca): Drop redundant
6597 (region_model::impl_call_builtin_expect): Likewise.
6598 (region_model::impl_call_calloc): Likewise.
6599 (region_model::impl_call_malloc): Likewise.
6600 (region_model::impl_call_memset): Likewise.
6601 (region_model::impl_call_strlen): Likewise.
6602 (region_model::impl_call_operator_new): Likewise.
6603 (region_model::impl_call_operator_delete): Likewise.
6605 2021-07-28 Siddhesh Poyarekar <siddhesh@gotplt.org>
6607 * analyzer.cc (is_named_call_p, is_std_named_call_p): Make
6608 first argument a const_tree.
6609 * analyzer.h (is_named_call_p, -s_std_named_call_p): Likewise.
6610 * sm-malloc.cc (known_allocator_p): New function.
6611 (malloc_state_machine::on_stmt): Use it.
6613 2021-07-28 Siddhesh Poyarekar <siddhesh@gotplt.org>
6616 (malloc_state_machine::get_or_create_deallocator): Recognize
6619 2021-07-26 David Malcolm <dmalcolm@redhat.com>
6621 * region-model.cc (region_model::on_call_pre): Always set conjured
6622 LHS, not just for SSA names.
6624 2021-07-23 David Malcolm <dmalcolm@redhat.com>
6626 * diagnostic-manager.cc
6627 (class auto_disable_complexity_checks): New.
6628 (epath_finder::explore_feasible_paths): Use it to disable
6629 complexity checks whilst processing the worklist.
6630 * region-model-manager.cc
6631 (region_model_manager::region_model_manager): Initialize
6633 (region_model_manager::reject_if_too_complex): Bail if
6634 m_check_complexity is false.
6636 (region_model_manager::enable_complexity_check): New.
6637 (region_model_manager::disable_complexity_check): New.
6638 (region_model_manager::m_check_complexity): New.
6640 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6643 * sm-file.cc (file_leak::emit): Handle m_arg being NULL.
6644 (file_leak::describe_final_event): Handle ev.m_expr being NULL.
6646 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6649 * store.cc (binding_cluster::purge_state_involving): Don't change
6650 m_map whilst iterating through it.
6652 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6654 * region-model.cc (region_model::handle_phi): Add "old_state"
6656 (region_model::update_for_phis): Update so that all of the phi
6657 stmts are effectively handled simultaneously, rather than in
6659 * region-model.h (region_model::handle_phi): Add "old_state"
6661 * state-purge.cc (self_referential_phi_p): Replace with...
6662 (name_used_by_phis_p): ...this new function.
6663 (state_purge_per_ssa_name::process_point): Update to use the
6664 above, so that all phi stmts at a basic block are effectively
6665 considered simultaneously, and only consider the phi arguments for
6666 the pertinent in-edge.
6667 * supergraph.cc (cfg_superedge::get_phi_arg_idx): New.
6668 (cfg_superedge::get_phi_arg): Use the above.
6669 * supergraph.h (cfg_superedge::get_phi_arg_idx): New decl.
6671 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6673 * state-purge.cc (state_purge_annotator::add_node_annotations):
6674 Rather than erroneously always using the NULL in-edge, determine
6675 each relevant in-edge, and print the appropriate data for each
6676 in-edge. Use print_needed to print the data as comma-separated
6678 (print_vec_of_names): Add "within_table" param and use it.
6679 (state_purge_annotator::add_stmt_annotations): Factor out
6680 collation and printing code into...
6681 (state_purge_annotator::print_needed): ...this new function.
6682 * state-purge.h (state_purge_annotator::print_needed): New decl.
6684 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6686 * program-point.cc (function_point::print): Show src BB index at
6689 2021-07-21 David Malcolm <dmalcolm@redhat.com>
6691 * svalue.cc (infix_p): New.
6692 (binop_svalue::dump_to_pp): Use it to print MIN_EXPR and MAX_EXPR
6693 in prefix form, rather than infix.
6695 2021-07-19 David Malcolm <dmalcolm@redhat.com>
6698 * constraint-manager.cc (constraint_manager::add_constraint): Use
6699 can_have_associated_state_p rather than testing for unknown.
6700 (constraint_manager::get_or_add_equiv_class): Likewise.
6701 * program-state.cc (sm_state_map::set_state): Likewise.
6702 (sm_state_map::impl_set_state): Add assertion.
6703 * region-model-manager.cc
6704 (region_model_manager::maybe_fold_unaryop): Handle poisoned
6706 (region_model_manager::maybe_fold_binop): Move handling of unknown
6708 (region_model_manager::get_or_create_binop): ...to here, and
6709 generalize to use can_have_associated_state_p.
6710 (region_model_manager::maybe_fold_sub_svalue): Use
6711 can_have_associated_state_p rather than testing for unknown.
6712 (region_model_manager::maybe_fold_repeated_svalue): Use unknown
6713 when the size or repeated value is "unknown"/"poisoned".
6714 * region-model.cc (region_model::purge_state_involving): Reject
6715 attempts to purge unknown/poisoned svalues, as these svalues
6716 should not have state associated with them.
6717 * svalue.cc (sub_svalue::sub_svalue): Assert that we're building
6718 on top of an svalue with can_have_associated_state_p.
6719 (repeated_svalue::repeated_svalue): Likewise.
6720 (bits_within_svalue::bits_within_svalue): Likewise.
6721 * svalue.h (svalue::can_have_associated_state_p): New.
6722 (unknown_svalue::can_have_associated_state_p): New.
6723 (poisoned_svalue::can_have_associated_state_p): New.
6724 (unaryop_svalue::unaryop_svalue): Assert that we're building on
6725 top of an svalue with can_have_associated_state_p.
6726 (binop_svalue::binop_svalue): Likewise.
6727 (widening_svalue::widening_svalue): Likewise.
6729 2021-07-16 David Malcolm <dmalcolm@redhat.com>
6731 * analyzer.h (enum access_direction): New.
6732 * engine.cc (exploded_node::on_longjmp): Update for new param of
6734 * program-state.cc (program_state::prune_for_point): Likewise.
6735 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
6736 Replace call to check_for_writable_region with call to
6737 check_region_for_write.
6738 (region_model::impl_call_memset): Likewise.
6739 (region_model::impl_call_strcpy): Likewise.
6740 * region-model-reachability.cc (reachable_regions::add): Update
6741 for new param of get_store_value.
6742 * region-model.cc (region_model::get_rvalue_1): Likewise, also for
6743 get_rvalue_for_bits.
6744 (region_model::get_store_value): Add ctxt param and use it to call
6745 check_region_for_read.
6746 (region_model::get_rvalue_for_bits): Add ctxt param and use it to
6747 call get_store_value.
6748 (region_model::check_region_access): New.
6749 (region_model::check_region_for_write): New.
6750 (region_model::check_region_for_read): New.
6751 (region_model::set_value): Update comment. Replace call to
6752 check_for_writable_region with call to check_region_for_write.
6753 * region-model.h (region_model::get_rvalue_for_bits): Add ctxt
6755 (region_model::get_store_value): Add ctxt param.
6756 (region_model::check_region_access): New decl.
6757 (region_model::check_region_for_write): New decl.
6758 (region_model::check_region_for_read): New decl.
6759 * region.cc (region_model::copy_region): Update call to
6761 * svalue.cc (initial_svalue::implicitly_live_p): Likewise.
6763 2021-07-16 David Malcolm <dmalcolm@redhat.com>
6765 * engine.cc (exploded_node::on_stmt_pre): Handle
6766 __analyzer_dump_state.
6767 * program-state.cc (extrinsic_state::get_sm_idx_by_name): New.
6768 (program_state::impl_call_analyzer_dump_state): New.
6769 * program-state.h (extrinsic_state::get_sm_idx_by_name): New decl.
6770 (program_state::impl_call_analyzer_dump_state): New decl.
6771 * region-model-impl-calls.cc
6772 (call_details::get_arg_string_literal): New.
6773 * region-model.h (call_details::get_arg_string_literal): New decl.
6775 2021-07-16 David Malcolm <dmalcolm@redhat.com>
6777 * program-state.cc (program_state::detect_leaks): Simplify using
6778 svalue::maybe_get_region.
6779 * region-model-impl-calls.cc (region_model::impl_call_fgets): Likewise.
6780 (region_model::impl_call_fread): Likewise.
6781 (region_model::impl_call_free): Likewise.
6782 (region_model::impl_call_operator_delete): Likewise.
6783 * region-model.cc (selftest::test_stack_frames): Likewise.
6784 (selftest::test_state_merging): Likewise.
6785 * svalue.cc (svalue::maybe_get_region): New.
6786 * svalue.h (svalue::maybe_get_region): New decl.
6788 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6790 * svalue.h (is_a_helper <placeholder_svalue *>::test): Make
6791 param and template param const.
6792 (is_a_helper <widening_svalue *>::test): Likewise.
6793 (is_a_helper <compound_svalue *>::test): Likewise.
6794 (is_a_helper <conjured_svalue *>::test): Likewise.
6796 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6801 * analyzer.cc (maybe_reconstruct_from_def_stmt): Split out
6802 GIMPLE_ASSIGN case into...
6803 (get_diagnostic_tree_for_gassign_1): New.
6804 (get_diagnostic_tree_for_gassign): New.
6805 * analyzer.h (get_diagnostic_tree_for_gassign): New decl.
6806 * analyzer.opt (Wanalyzer-write-to-string-literal): New.
6807 * constraint-manager.cc (class svalue_purger): New.
6808 (constraint_manager::purge_state_involving): New.
6809 * constraint-manager.h
6810 (constraint_manager::purge_state_involving): New.
6811 * diagnostic-manager.cc (saved_diagnostic::supercedes_p): New.
6812 (dedupe_winners::handle_interactions): New.
6813 (diagnostic_manager::emit_saved_diagnostics): Call it.
6814 * diagnostic-manager.h (saved_diagnostic::supercedes_p): New decl.
6815 * engine.cc (impl_region_model_context::warn): Convert return type
6816 to bool. Return false if the diagnostic isn't saved.
6817 (impl_region_model_context::purge_state_involving): New.
6818 (impl_sm_context::get_state): Use NULL ctxt when querying old
6820 (impl_sm_context::set_next_state): Use new sval when querying old
6822 (class dump_path_diagnostic): Move to region-model.cc
6823 (exploded_node::on_stmt): Move to on_stmt_pre and on_stmt_post.
6824 Remove call to purge_state_involving.
6825 (exploded_node::on_stmt_pre): New, based on the above. Move most
6826 of it to region_model::on_stmt_pre.
6827 (exploded_node::on_stmt_post): Likewise, moving to
6828 region_model::on_stmt_post.
6829 (class stale_jmp_buf): Fix parent class to use curiously recurring
6831 (feasibility_state::maybe_update_for_edge): Call on_call_pre and
6832 on_call_post on gcalls.
6833 * exploded-graph.h (impl_region_model_context::warn): Return bool.
6834 (impl_region_model_context::purge_state_involving): New decl.
6835 (exploded_node::on_stmt_pre): New decl.
6836 (exploded_node::on_stmt_post): New decl.
6837 * pending-diagnostic.h (pending_diagnostic::use_of_uninit_p): New.
6838 (pending_diagnostic::supercedes_p): New.
6839 * program-state.cc (sm_state_map::get_state): Inherit state for
6840 conjured_svalue as well as initial_svalue.
6841 (sm_state_map::purge_state_involving): Also support SK_CONJURED.
6842 * region-model-impl-calls.cc (call_details::get_uncertainty):
6843 Handle m_ctxt being NULL.
6844 (call_details::get_or_create_conjured_svalue): New.
6845 (region_model::impl_call_fgets): New.
6846 (region_model::impl_call_fread): New.
6847 * region-model-manager.cc
6848 (region_model_manager::get_or_create_initial_value): Return an
6849 uninitialized poisoned value for regions that can't have initial
6851 * region-model-reachability.cc
6852 (reachable_regions::mark_escaped_clusters): Handle ctxt being
6854 * region-model.cc (region_to_value_map::purge_state_involving): New.
6855 (poisoned_value_diagnostic::use_of_uninit_p): New.
6856 (poisoned_value_diagnostic::emit): Handle POISON_KIND_UNINIT.
6857 (poisoned_value_diagnostic::describe_final_event): Likewise.
6858 (region_model::check_for_poison): New.
6859 (region_model::on_assignment): Call it.
6860 (class dump_path_diagnostic): Move here from engine.cc.
6861 (region_model::on_stmt_pre): New, based on exploded_node::on_stmt.
6862 (region_model::on_call_pre): Move the setting of the LHS to a
6863 conjured svalue to before the checks for specific functions.
6864 Handle "fgets", "fgets_unlocked", and "fread".
6865 (region_model::purge_state_involving): New.
6866 (region_model::handle_unrecognized_call): Handle ctxt being NULL.
6867 (region_model::get_rvalue): Call check_for_poison.
6868 (selftest::test_stack_frames): Use NULL for context when getting
6869 uninitialized rvalue.
6870 (selftest::test_alloca): Likewise.
6871 * region-model.h (region_to_value_map::purge_state_involving): New
6873 (call_details::get_or_create_conjured_svalue): New decl.
6874 (region_model::on_stmt_pre): New decl.
6875 (region_model::purge_state_involving): New decl.
6876 (region_model::impl_call_fgets): New decl.
6877 (region_model::impl_call_fread): New decl.
6878 (region_model::check_for_poison): New decl.
6879 (region_model_context::warn): Return bool.
6880 (region_model_context::purge_state_involving): New.
6881 (noop_region_model_context::warn): Return bool.
6882 (noop_region_model_context::purge_state_involving): New.
6883 (test_region_model_context:: warn): Return bool.
6884 * region.cc (region::get_memory_space): New.
6885 (region::can_have_initial_svalue_p): New.
6886 (region::involves_p): New.
6887 * region.h (enum memory_space): New.
6888 (region::get_memory_space): New decl.
6889 (region::can_have_initial_svalue_p): New decl.
6890 (region::involves_p): New decl.
6891 * sm-malloc.cc (use_after_free::supercedes_p): New.
6892 * store.cc (binding_cluster::purge_state_involving): New.
6893 (store::purge_state_involving): New.
6894 * store.h (class symbolic_binding): New forward decl.
6895 (binding_key::dyn_cast_symbolic_binding): New.
6896 (symbolic_binding::dyn_cast_symbolic_binding): New.
6897 (binding_cluster::purge_state_involving): New.
6898 (store::purge_state_involving): New.
6899 * svalue.cc (svalue::can_merge_p): Reject attempts to merge
6900 poisoned svalues with other svalues, so that we identify
6901 paths in which a variable is conditionally uninitialized.
6902 (involvement_visitor::visit_conjured_svalue): New.
6903 (svalue::involves_p): Also handle SK_CONJURED.
6904 (poison_kind_to_str): Handle POISON_KIND_UNINIT.
6905 (poisoned_svalue::maybe_fold_bits_within): New.
6906 * svalue.h (enum poison_kind): Add POISON_KIND_UNINIT.
6907 (poisoned_svalue::maybe_fold_bits_within): New decl.
6909 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6911 * analyzer.opt (fdump-analyzer-exploded-paths): New.
6912 * diagnostic-manager.cc
6913 (diagnostic_manager::emit_saved_diagnostic): Implement it.
6914 * engine.cc (exploded_path::dump_to_pp): Add ext_state param and
6915 use it to dump states if non-NULL.
6916 (exploded_path::dump): Likewise.
6917 (exploded_path::dump_to_file): New.
6918 * exploded-graph.h (exploded_path::dump_to_pp): Add ext_state
6920 (exploded_path::dump): Likewise.
6921 (exploded_path::dump): Likewise.
6922 (exploded_path::dump_to_file): New.
6924 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6926 * analyzer.cc (fixup_tree_for_diagnostic_1): Use DECL_DEBUG_EXPR
6928 * engine.cc (readability): Likewise.
6930 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6932 * state-purge.cc (self_referential_phi_p): New.
6933 (state_purge_per_ssa_name::process_point): Don't purge an SSA name
6934 at its def-stmt if the def-stmt is self-referential.
6936 2021-07-07 David Malcolm <dmalcolm@redhat.com>
6938 * diagnostic-manager.cc (null_assignment_sm_context::get_state):
6940 (null_assignment_sm_context::set_next_state): New overload.
6941 (null_assignment_sm_context::get_diagnostic_tree): New.
6942 * engine.cc (impl_sm_context::get_state): New overload.
6943 (impl_sm_context::set_next_state): New overload.
6944 (impl_sm_context::get_diagnostic_tree): New overload.
6945 (impl_region_model_context::on_condition): Convert params from
6946 tree to const svalue *.
6947 * exploded-graph.h (impl_region_model_context::on_condition):
6949 * region-model.cc (region_model::on_call_pre): Move handling of
6950 internal calls to before checking for get_fndecl_for_call.
6951 (region_model::add_constraints_from_binop): New.
6952 (region_model::add_constraint): Split out into a new overload
6953 working on const svalue * rather than tree. Call
6954 add_constraints_from_binop. Drop call to
6955 add_any_constraints_from_ssa_def_stmt.
6956 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6957 (region_model::add_any_constraints_from_gassign): Delete.
6958 (region_model::add_any_constraints_from_gcall): Delete.
6960 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6961 (region_model::add_any_constraints_from_gassign): Delete.
6962 (region_model::add_any_constraints_from_gcall): Delete.
6963 (region_model::add_constraint): Add overload decl.
6964 (region_model::add_constraints_from_binop): New decl.
6965 (region_model_context::on_condition): Convert params from tree to
6967 (noop_region_model_context::on_condition): Likewise.
6968 * sm-file.cc (fileptr_state_machine::condition): Likewise.
6969 * sm-malloc.cc (malloc_state_machine::on_condition): Likewise.
6970 * sm-pattern-test.cc: Include tristate.h, selftest.h,
6971 analyzer/call-string.h, analyzer/program-point.h,
6972 analyzer/store.h, and analyzer/region-model.h.
6973 (pattern_test_state_machine::on_condition): Convert params from tree to
6975 * sm-sensitive.cc (sensitive_state_machine::on_condition): Delete.
6976 * sm-signal.cc (signal_state_machine::on_condition): Delete.
6977 * sm-taint.cc (taint_state_machine::on_condition): Convert params
6978 from tree to const svalue *.
6979 * sm.cc: Include tristate.h, selftest.h, analyzer/call-string.h,
6980 analyzer/program-point.h, analyzer/store.h, and
6981 analyzer/region-model.h.
6982 (any_pointer_p): Add overload taking const svalue *sval.
6983 * sm.h (any_pointer_p): Add overload taking const svalue *sval.
6984 (state_machine::on_condition): Convert params from tree to
6985 const svalue *. Provide no-op default implementation.
6986 (sm_context::get_state): Add overload taking const svalue *sval.
6987 (sm_context::set_next_state): Likewise.
6988 (sm_context::on_transition): Likewise.
6989 (sm_context::get_diagnostic_tree): Likewise.
6990 * svalue.cc (svalue::all_zeroes_p): New.
6991 (constant_svalue::all_zeroes_p): New.
6992 (repeated_svalue::all_zeroes_p): Convert to vfunc.
6993 * svalue.h (svalue::all_zeroes_p): New decl.
6994 (constant_svalue::all_zeroes_p): New decl.
6995 (repeated_svalue::all_zeroes_p): Convert decl to vfunc.
6997 2021-06-30 David Malcolm <dmalcolm@redhat.com>
7000 * analyzer.h (class repeated_svalue): New forward decl.
7001 (class bits_within_svalue): New forward decl.
7002 (class sized_region): New forward decl.
7003 (get_field_at_bit_offset): New forward decl.
7004 * engine.cc (exploded_graph::get_or_create_node): Validate the
7006 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
7007 Validate the states at each stage.
7008 * program-state.cc (program_state::validate): Validate
7010 * region-model-impl-calls.cc (region_model::impl_call_memset):
7011 Replace special-case logic for handling constant sizes with
7012 a call to fill_region of a sized_region with the given fill value.
7013 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
7015 (region_model_manager::maybe_fold_sub_svalue): Fold element-based
7016 subregions of an initial value into initial values of an element.
7017 Fold subvalues of repeated svalues.
7018 (region_model_manager::maybe_fold_repeated_svalue): New.
7019 (region_model_manager::get_or_create_repeated_svalue): New.
7020 (get_bit_range_for_field): New.
7021 (get_byte_range_for_field): New.
7022 (get_field_at_byte_range): New.
7023 (region_model_manager::maybe_fold_bits_within_svalue): New.
7024 (region_model_manager::get_or_create_bits_within): New.
7025 (region_model_manager::get_sized_region): New.
7026 (region_model_manager::log_stats): Update for addition of
7027 m_repeated_values_map, m_bits_within_values_map, and
7029 * region-model.cc (region_model::validate): New.
7030 (region_model::on_assignment): Drop enum binding_kind.
7031 (region_model::get_initial_value_for_global): Likewise.
7032 (region_model::get_rvalue_for_bits): Replace body with call to
7033 get_or_create_bits_within.
7034 (region_model::get_capacity): Handle RK_SIZED.
7035 (region_model::set_value): Drop enum binding_kind.
7036 (region_model::fill_region): New.
7037 (region_model::get_representative_path_var_1): Handle RK_SIZED.
7038 * region-model.h (visitor::visit_repeated_svalue): New.
7039 (visitor::visit_bits_within_svalue): New.
7040 (region_model_manager::get_or_create_repeated_svalue): New decl.
7041 (region_model_manager::get_or_create_bits_within): New decl.
7042 (region_model_manager::get_sized_region): New decl.
7043 (region_model_manager::maybe_fold_repeated_svalue): New decl.
7044 (region_model_manager::maybe_fold_bits_within_svalue): New decl.
7045 (region_model_manager::repeated_values_map_t): New typedef.
7046 (region_model_manager::m_repeated_values_map): New field.
7047 (region_model_manager::bits_within_values_map_t): New typedef.
7048 (region_model_manager::m_bits_within_values_map): New field.
7049 (region_model_manager::m_sized_regions): New field.
7050 (region_model::fill_region): New decl.
7051 * region.cc (region::get_base_region): Handle RK_SIZED.
7052 (region::base_region_p): Likewise.
7053 (region::get_byte_size_sval): New.
7054 (get_field_at_bit_offset): Make non-static.
7055 (region::calc_offset): Move implementation of cases to
7056 get_relative_concrete_offset vfunc implementations. Handle
7058 (region::get_relative_concrete_offset): New.
7059 (decl_region::get_svalue_for_initializer): Drop enum binding_kind.
7060 (field_region::get_relative_concrete_offset): New, from
7061 region::calc_offset.
7062 (element_region::get_relative_concrete_offset): Likewise.
7063 (offset_region::get_relative_concrete_offset): Likewise.
7064 (sized_region::accept): New.
7065 (sized_region::dump_to_pp): New.
7066 (sized_region::get_byte_size): New.
7067 (sized_region::get_bit_size): New.
7068 * region.h (enum region_kind): Add RK_SIZED.
7069 (region::dyn_cast_sized_region): New.
7070 (region::get_byte_size): Make virtual.
7071 (region::get_bit_size): Likewise.
7072 (region::get_byte_size_sval): New decl.
7073 (region::get_relative_concrete_offset): New decl.
7074 (field_region::get_relative_concrete_offset): New decl.
7075 (element_region::get_relative_concrete_offset): Likewise.
7076 (offset_region::get_relative_concrete_offset): Likewise.
7077 (class sized_region): New.
7078 * store.cc (binding_kind_to_string): Delete.
7079 (binding_key::make): Drop enum binding_kind.
7080 (binding_key::dump_to_pp): Delete.
7081 (binding_key::cmp_ptrs): Drop enum binding_kind.
7082 (bit_range::contains_p): New.
7083 (byte_range::dump): New.
7084 (byte_range::contains_p): New.
7085 (byte_range::cmp): New.
7086 (concrete_binding::dump_to_pp): Drop enum binding_kind.
7087 (concrete_binding::cmp_ptr_ptr): Likewise.
7088 (symbolic_binding::dump_to_pp): Likewise.
7089 (symbolic_binding::cmp_ptr_ptr): Likewise.
7090 (binding_map::apply_ctor_val_to_range): Likewise.
7091 (binding_map::apply_ctor_pair_to_child_region): Likewise.
7092 (binding_map::get_overlapping_bindings): New.
7093 (binding_map::remove_overlapping_bindings): New.
7094 (binding_cluster::validate): New.
7095 (binding_cluster::bind): Drop enum binding_kind.
7096 (binding_cluster::bind_compound_sval): Likewise.
7097 (binding_cluster::purge_region): Likewise.
7098 (binding_cluster::zero_fill_region): Reimplement in terms of...
7099 (binding_cluster::fill_region): New.
7100 (binding_cluster::mark_region_as_unknown): Drop enum binding_kind.
7101 (binding_cluster::get_binding): Likewise.
7102 (binding_cluster::get_binding_recursive): Likewise.
7103 (binding_cluster::get_any_binding): Likewise.
7104 (binding_cluster::maybe_get_compound_binding): Reimplement.
7105 (binding_cluster::get_overlapping_bindings): Delete.
7106 (binding_cluster::remove_overlapping_bindings): Reimplement in
7107 terms of binding_map::remove_overlapping_bindings.
7108 (binding_cluster::can_merge_p): Update for removal of
7110 (binding_cluster::on_unknown_fncall): Drop enum binding_kind.
7111 (binding_cluster::maybe_get_simple_value): Likewise.
7112 (store_manager::get_concrete_binding): Likewise.
7113 (store_manager::get_symbolic_binding): Likewise.
7114 (store::validate): New.
7115 (store::set_value): Drop enum binding_kind.
7116 (store::zero_fill_region): Reimplement in terms of...
7117 (store::fill_region): New.
7118 (selftest::test_binding_key_overlap): Drop enum binding_kind.
7119 * store.h (enum binding_kind): Delete.
7120 (binding_kind_to_string): Delete decl.
7121 (binding_key::make): Drop enum binding_kind.
7122 (binding_key::dump_to_pp): Make pure virtual.
7123 (binding_key::get_kind): Delete.
7124 (binding_key::mark_deleted): Delete.
7125 (binding_key::mark_empty): Delete.
7126 (binding_key::is_deleted): Delete.
7127 (binding_key::is_empty): Delete.
7128 (binding_key::binding_key): Delete.
7129 (binding_key::impl_hash): Delete.
7130 (binding_key::impl_eq): Delete.
7131 (binding_key::m_kind): Delete.
7132 (bit_range::get_last_bit_offset): New.
7133 (bit_range::contains_p): New.
7134 (byte_range::contains_p): New.
7135 (byte_range::operator==): New.
7136 (byte_range::get_start_byte_offset): New.
7137 (byte_range::get_next_byte_offset): New.
7138 (byte_range::get_last_byte_offset): New.
7139 (byte_range::as_bit_range): New.
7140 (byte_range::cmp): New.
7141 (concrete_binding::concrete_binding): Drop enum binding_kind.
7142 (concrete_binding::hash): Likewise.
7143 (concrete_binding::operator==): Likewise.
7144 (concrete_binding::mark_deleted): New.
7145 (concrete_binding::mark_empty): New.
7146 (concrete_binding::is_deleted): New.
7147 (concrete_binding::is_empty): New.
7148 (default_hash_traits<ana::concrete_binding>::empty_zero_p): Make false.
7149 (symbolic_binding::symbolic_binding): Drop enum binding_kind.
7150 (symbolic_binding::hash): Likewise.
7151 (symbolic_binding::operator==): Likewise.
7152 (symbolic_binding::mark_deleted): New.
7153 (symbolic_binding::mark_empty): New.
7154 (symbolic_binding::is_deleted): New.
7155 (symbolic_binding::is_empty): New.
7156 (binding_map::remove_overlapping_bindings): New decl.
7157 (binding_map::get_overlapping_bindings): New decl.
7158 (binding_cluster::validate): New decl.
7159 (binding_cluster::bind): Drop enum binding_kind.
7160 (binding_cluster::fill_region): New decl.
7161 (binding_cluster::get_binding): Drop enum binding_kind.
7162 (binding_cluster::get_binding_recursive): Likewise.
7163 (binding_cluster::get_overlapping_bindings): Delete.
7164 (store::validate): New decl.
7165 (store::set_value): Drop enum binding_kind.
7166 (store::fill_region): New decl.
7167 (store_manager::get_concrete_binding): Drop enum binding_kind.
7168 (store_manager::get_symbolic_binding): Likewise.
7169 * svalue.cc (svalue::cmp_ptr): Handle SK_REPEATED and
7171 (svalue::extract_bit_range): New.
7172 (svalue::maybe_fold_bits_within): New.
7173 (constant_svalue::maybe_fold_bits_within): New.
7174 (unknown_svalue::maybe_fold_bits_within): New.
7175 (unaryop_svalue::maybe_fold_bits_within): New.
7176 (repeated_svalue::repeated_svalue): New.
7177 (repeated_svalue::dump_to_pp): New.
7178 (repeated_svalue::accept): New.
7179 (repeated_svalue::all_zeroes_p): New.
7180 (repeated_svalue::maybe_fold_bits_within): New.
7181 (bits_within_svalue::bits_within_svalue): New.
7182 (bits_within_svalue::dump_to_pp): New.
7183 (bits_within_svalue::maybe_fold_bits_within): New.
7184 (bits_within_svalue::accept): New.
7185 (bits_within_svalue::implicitly_live_p): New.
7186 (compound_svalue::maybe_fold_bits_within): New.
7187 * svalue.h (enum svalue_kind): Add SK_REPEATED and SK_BITS_WITHIN.
7188 (svalue::dyn_cast_repeated_svalue): New.
7189 (svalue::dyn_cast_bits_within_svalue): New.
7190 (svalue::extract_bit_range): New decl.
7191 (svalue::maybe_fold_bits_within): New vfunc decl.
7192 (region_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7193 (region_svalue::key_t::is_empty): Likewise.
7194 (default_hash_traits<region_svalue::key_t>::empty_zero_p): Make false.
7195 (constant_svalue::maybe_fold_bits_within): New.
7196 (unknown_svalue::maybe_fold_bits_within): New.
7197 (poisoned_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7198 (poisoned_svalue::key_t::is_empty): Likewise.
7199 (default_hash_traits<poisoned_svalue::key_t>::empty_zero_p): Make
7201 (setjmp_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7202 (setjmp_svalue::key_t::is_empty): Likewise.
7203 (default_hash_traits<setjmp_svalue::key_t>::empty_zero_p): Make
7205 (unaryop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7206 (unaryop_svalue::key_t::is_empty): Likewise.
7207 (unaryop_svalue::maybe_fold_bits_within): New.
7208 (default_hash_traits<unaryop_svalue::key_t>::empty_zero_p): Make
7210 (binop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7211 (binop_svalue::key_t::is_empty): Likewise.
7212 (default_hash_traits<binop_svalue::key_t>::empty_zero_p): Make
7214 (sub_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7215 (sub_svalue::key_t::is_empty): Likewise.
7216 (default_hash_traits<sub_svalue::key_t>::empty_zero_p): Make
7218 (class repeated_svalue): New.
7219 (is_a_helper <const repeated_svalue *>::test): New.
7220 (struct default_hash_traits<repeated_svalue::key_t>): New.
7221 (class bits_within_svalue): New.
7222 (is_a_helper <const bits_within_svalue *>::test): New.
7223 (struct default_hash_traits<bits_within_svalue::key_t>): New.
7224 (widening_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7225 (widening_svalue::key_t::is_empty): Likewise.
7226 (default_hash_traits<widening_svalue::key_t>::empty_zero_p): Make
7228 (compound_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7229 (compound_svalue::key_t::is_empty): Likewise.
7230 (compound_svalue::maybe_fold_bits_within): New.
7231 (default_hash_traits<compound_svalue::key_t>::empty_zero_p): Make
7234 2021-06-28 David Malcolm <dmalcolm@redhat.com>
7236 * analyzer.h (byte_offset_t): New typedef.
7237 * store.cc (bit_range::dump_to_pp): Dump as a byte range if
7239 (bit_range::as_byte_range): New.
7240 (byte_range::dump_to_pp): New.
7241 * store.h (class byte_range): New forward decl.
7242 (struct bit_range): Add comment.
7243 (bit_range::as_byte_range): New decl.
7244 (struct byte_range): New.
7246 2021-06-22 David Malcolm <dmalcolm@redhat.com>
7249 * region-model.cc (compat_types_p): New function.
7250 (region_model::create_region_for_heap_alloc): Convert assertion to
7252 (region_model::create_region_for_alloca): Likewise.
7254 2021-06-18 David Malcolm <dmalcolm@redhat.com>
7256 * store.cc (binding_cluster::get_any_binding): Make symbolic reads
7257 from a cluster with concrete bindings return unknown.
7259 2021-06-18 David Malcolm <dmalcolm@redhat.com>
7261 * region-model-manager.cc
7262 (region_model_manager::get_or_create_int_cst): New.
7263 (region_model_manager::maybe_undo_optimize_bit_field_compare): Use
7264 it to simplify away a local tree.
7265 * region-model.cc (region_model::on_setjmp): Likewise.
7266 (region_model::on_longjmp): Likewise.
7267 * region-model.h (region_model_manager::get_or_create_int_cst):
7269 * store.cc (binding_cluster::zero_fill_region): Use it to simplify
7272 2021-06-18 David Malcolm <dmalcolm@redhat.com>
7274 * checker-path.cc (class custom_event): Make abstract to allow for
7275 custom vfuncs, splitting existing implementation into...
7276 (class precanned_custom_event): New subclass.
7277 (custom_event::get_desc): Move to...
7278 (precanned_custom_event::get_desc): ...subclass.
7279 * checker-path.h (class custom_event): Make abstract to allow for
7280 custom vfuncs, splitting existing implementation into...
7281 (class precanned_custom_event): New subclass.
7282 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
7283 Use precanned_custom_event.
7285 (stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise.
7286 * sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path):
7289 2021-06-15 David Malcolm <dmalcolm@redhat.com>
7293 * engine.cc: Include "target.h".
7294 (impl_run_checkers): Log BITS_BIG_ENDIAN, BYTES_BIG_ENDIAN, and
7296 * region-model-manager.cc
7297 (region_model_manager::maybe_fold_binop): Move support for masking
7298 via ARG0 & CST into...
7299 (region_model_manager::maybe_undo_optimize_bit_field_compare):
7300 ...this new function. Flatten by converting from nested
7301 conditionals to a series of early return statements to reject
7302 failures. Reject if type is not unsigned_char_type_node.
7303 Handle BYTES_BIG_ENDIAN when determining which bits are bound
7306 (region_model_manager::maybe_undo_optimize_bit_field_compare):
7308 * store.cc (bit_range::dump): New function.
7309 * store.h (bit_range::dump): New decl.
7311 2021-06-15 David Malcolm <dmalcolm@redhat.com>
7313 * engine.cc (exploded_node::on_stmt): Handle __analyzer_dump_capacity.
7314 (exploded_node::on_stmt): Drop m_sm_changes from on_stmt_flags.
7315 (state_change_requires_new_enode_p): New function...
7316 (exploded_graph::process_node): Call it, rather than querying
7317 flags.m_sm_changes, so that dynamic-extent differences can also
7318 trigger the splitting of nodes.
7319 * exploded-graph.h (struct on_stmt_flags): Drop field m_sm_changes.
7320 * program-state.cc (program_state::detect_leaks): Purge dead
7321 heap-allocated regions from dynamic extents.
7322 (selftest::test_program_state_1): Fix type of "size_in_bytes".
7323 (selftest::test_program_state_merging): Likewise.
7324 * region-model-impl-calls.cc
7325 (region_model::impl_call_analyzer_dump_capacity): New.
7326 (region_model::impl_call_free): Remove dynamic extents from the
7328 * region-model-reachability.h
7329 (reachable_regions::begin_mutable_base_regs): New.
7330 (reachable_regions::end_mutable_base_regs): New.
7331 * region-model.cc: Include "tree-object-size.h".
7332 (region_model::region_model): Support new field m_dynamic_extents.
7333 (region_model::operator=): Likewise.
7334 (region_model::operator==): Likewise.
7335 (region_model::dump_to_pp): Dump sizes of dynamic regions.
7336 (region_model::handle_unrecognized_call): Purge dynamic extents
7337 from any regions that have escaped mutably:.
7338 (region_model::get_capacity): New function.
7339 (region_model::add_constraint): Unset dynamic extents when a
7340 heap-allocated region's address is NULL.
7341 (region_model::unbind_region_and_descendents): Purge dynamic
7342 extents of unbound regions.
7343 (region_model::can_merge_with_p): Call
7344 m_dynamic_extents.can_merge_with_p.
7345 (region_model::create_region_for_heap_alloc): Assert that
7346 size_in_bytes's type is compatible with size_type_node. Update
7347 for renaming of record_dynamic_extents to set_dynamic_extents.
7348 (region_model::create_region_for_alloca): Likewise.
7349 (region_model::record_dynamic_extents): Rename to...
7350 (region_model::set_dynamic_extents): ...this. Assert that
7351 size_in_bytes's type is compatible with size_type_node. Add it
7352 to the m_dynamic_extents map.
7353 (region_model::get_dynamic_extents): New.
7354 (region_model::unset_dynamic_extents): New.
7355 (selftest::test_state_merging): Fix type of "size".
7356 (selftest::test_malloc_constraints): Likewise.
7357 (selftest::test_malloc): Verify dynamic extents.
7358 (selftest::test_alloca): Likewise.
7359 * region-model.h (region_to_value_map::is_empty): New.
7360 (region_model::dynamic_extents_t): New typedef.
7361 (region_model::impl_call_analyzer_dump_capacity): New decl.
7362 (region_model::get_dynamic_extents): New function.
7363 (region_model::get_dynamic_extents): New decl.
7364 (region_model::set_dynamic_extents): New decl.
7365 (region_model::unset_dynamic_extents): New decl.
7366 (region_model::get_capacity): New decl.
7367 (region_model::record_dynamic_extents): Rename to set_dynamic_extents.
7368 (region_model::m_dynamic_extents): New field.
7370 2021-06-15 David Malcolm <dmalcolm@redhat.com>
7372 * region-model.cc (region_to_value_map::operator=): New.
7373 (region_to_value_map::operator==): New.
7374 (region_to_value_map::dump_to_pp): New.
7375 (region_to_value_map::dump): New.
7376 (region_to_value_map::can_merge_with_p): New.
7377 * region-model.h (class region_to_value_map): New class.
7379 2021-06-13 Trevor Saunders <tbsaunde@tbsaunde.org>
7381 * call-string.cc (call_string::call_string): Use range based for
7382 to iterate over vec<>.
7383 (call_string::to_json): Likewise.
7384 (call_string::hash): Likewise.
7385 (call_string::calc_recursion_depth): Likewise.
7386 * checker-path.cc (checker_path::fixup_locations): Likewise.
7387 * constraint-manager.cc (equiv_class::equiv_class): Likewise.
7388 (equiv_class::to_json): Likewise.
7389 (equiv_class::hash): Likewise.
7390 (constraint_manager::to_json): Likewise.
7391 * engine.cc (impl_region_model_context::on_svalue_leak):
7393 (on_liveness_change): Likewise.
7394 (impl_region_model_context::on_unknown_change): Likewise.
7395 * program-state.cc (sm_state_map::set_state): Likewise.
7396 * region-model.cc (test_canonicalization_4): Likewise.
7398 2021-06-11 David Malcolm <dmalcolm@redhat.com>
7400 * engine.cc (worklist::key_t::cmp): Move sort by call_string to
7403 2021-06-09 David Malcolm <dmalcolm@redhat.com>
7405 * region-model.cc (region_model::get_lvalue_1): Make const.
7406 (region_model::get_lvalue): Likewise.
7407 (region_model::get_rvalue_1): Likewise.
7408 (region_model::get_rvalue): Likewise.
7409 (region_model::deref_rvalue): Likewise.
7410 (region_model::get_rvalue_for_bits): Likewise.
7411 * region-model.h (region_model::get_lvalue): Likewise.
7412 (region_model::get_rvalue): Likewise.
7413 (region_model::deref_rvalue): Likewise.
7414 (region_model::get_rvalue_for_bits): Likewise.
7415 (region_model::get_lvalue_1): Likewise.
7416 (region_model::get_rvalue_1): Likewise.
7418 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7421 * region-model-manager.cc
7422 (region_model_manager::maybe_fold_binop): Add support for folding
7423 BIT_AND_EXPR of compound_svalue and a mask constant.
7424 * region-model.cc (region_model::get_rvalue_1): Implement
7425 BIT_FIELD_REF in terms of...
7426 (region_model::get_rvalue_for_bits): New function.
7427 * region-model.h (region_model::get_rvalue_for_bits): New decl.
7428 * store.cc (bit_range::from_mask): New function.
7429 (selftest::test_bit_range_intersects_p): New selftest.
7430 (selftest::assert_bit_range_from_mask_eq): New.
7431 (ASSERT_BIT_RANGE_FROM_MASK_EQ): New macro.
7432 (selftest::assert_no_bit_range_from_mask_eq): New.
7433 (ASSERT_NO_BIT_RANGE_FROM_MASK): New macro.
7434 (selftest::test_bit_range_from_mask): New selftest.
7435 (selftest::analyzer_store_cc_tests): Call the new selftests.
7436 * store.h (bit_range::intersects_p): New.
7437 (bit_range::from_mask): New decl.
7438 (concrete_binding::get_bit_range): New accessor.
7439 (store_manager::get_concrete_binding): New overload taking
7442 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7444 * analyzer.h (int_size_in_bits): New decl.
7445 * region.cc (int_size_in_bits): New function.
7446 (region::get_bit_size): Reimplement in terms of the above.
7448 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7450 * store.cc (concrete_binding::dump_to_pp): Move bulk of
7451 implementation to...
7452 (bit_range::dump_to_pp): ...this new function.
7453 (bit_range::cmp): New.
7454 (concrete_binding::overlaps_p): Update for use of bit_range.
7455 (concrete_binding::cmp_ptr_ptr): Likewise.
7456 * store.h (struct bit_range): New.
7457 (class concrete_binding): Replace fields m_start_bit_offset and
7458 m_size_in_bits with new field m_bit_range.
7460 2021-06-08 David Malcolm <dmalcolm@redhat.com>
7462 * svalue.h (conjured_svalue::iterator_t): Delete.
7464 2021-06-03 David Malcolm <dmalcolm@redhat.com>
7466 * store.h (store::get_direct_binding): Remove unused decl.
7467 (store::get_default_binding): Likewise.
7469 2021-06-03 David Malcolm <dmalcolm@redhat.com>
7471 * svalue.cc (poisoned_svalue::dump_to_pp): Dump type.
7472 (compound_svalue::dump_to_pp): Dump any type.
7474 2021-05-18 David Malcolm <dmalcolm@redhat.com>
7477 * sm-malloc.cc: Include "analyzer/function-set.h".
7478 (malloc_state_machine::on_stmt): Call unaffected_by_call_p and
7479 bail on the functions it recognizes.
7480 (malloc_state_machine::unaffected_by_call_p): New.
7482 2021-05-10 Martin Liska <mliska@suse.cz>
7484 * sm-file.cc (is_file_using_fn_p): Use startswith
7485 function instead of strncmp.
7487 2021-05-10 Martin Liska <mliska@suse.cz>
7489 * program-state.cc (program_state::operator=): Remove
7490 __cplusplus >= 201103.
7491 (program_state::program_state): Likewise.
7492 * program-state.h: Likewise.
7493 * region-model.h (class region_model): Remove dead code.
7495 2021-04-24 David Malcolm <dmalcolm@redhat.com>
7498 * sm-malloc.cc (free_of_non_heap::describe_state_change):
7499 Bulletproof against change.m_expr being NULL.
7501 2021-04-13 David Malcolm <dmalcolm@redhat.com>
7504 * supergraph.cc (saved_uids::make_uid_unique): New.
7505 (saved_uids::restore_uids): New.
7506 (supergraph::supergraph): Replace assignments to stmt->uid with
7507 calls to m_stmt_uids.make_uid_unique.
7508 (supergraph::~supergraph): New.
7509 * supergraph.h (class saved_uids): New.
7510 (supergraph::~supergraph): New decl.
7511 (supergraph::m_stmt_uids): New field.
7513 2021-04-10 David Malcolm <dmalcolm@redhat.com>
7516 * region-model.cc (region_model::on_assignment): Avoid NULL
7517 dereference if ctxt is NULL when assigning from a STRING_CST.
7519 2021-04-08 David Malcolm <dmalcolm@redhat.com>
7524 (impl_region_model_context::impl_region_model_context): Add
7525 uncertainty param and use it to initialize m_uncertainty.
7526 (impl_region_model_context::get_uncertainty): New.
7527 (impl_sm_context::get_fndecl_for_call): Add NULL for new
7528 uncertainty param when constructing impl_region_model_context.
7529 (impl_sm_context::get_state): Likewise.
7530 (impl_sm_context::set_next_state): Likewise.
7531 (impl_sm_context::warn): Likewise.
7532 (exploded_node::on_stmt): Add uncertainty param
7533 and use it when constructing impl_region_model_context.
7534 (exploded_node::on_edge): Add uncertainty param and pass
7536 (exploded_node::detect_leaks): Create uncertainty_t and pass to
7537 impl_region_model_context.
7538 (exploded_graph::get_or_create_node): Create uncertainty_t and
7539 pass to prune_for_point.
7540 (maybe_process_run_of_before_supernode_enodes): Create
7541 uncertainty_t and pass to impl_region_model_context.
7542 (exploded_graph::process_node): Create uncertainty_t instances and
7543 pass around as needed.
7545 (impl_region_model_context::impl_region_model_context): Add
7547 (impl_region_model_context::get_uncertainty): New decl.
7548 (impl_region_model_context::m_uncertainty): New field.
7549 (exploded_node::on_stmt): Add uncertainty param.
7550 (exploded_node::on_edge): Likewise.
7551 * program-state.cc (sm_state_map::on_liveness_change): Get
7552 uncertainty from context and use it to unset sm-state from
7553 svalues as appropriate.
7554 (program_state::on_edge): Add uncertainty param and use it when
7555 constructing impl_region_model_context. Fix indentation.
7556 (program_state::prune_for_point): Add uncertainty param and use it
7557 when constructing impl_region_model_context.
7558 (program_state::detect_leaks): Get any uncertainty from ctxt and
7559 use it to get maybe-live svalues for dest_state, rather than
7560 definitely-live ones; use this when determining which svalues
7562 (selftest::test_program_state_merging): Create uncertainty_t and
7563 pass to impl_region_model_context.
7564 * program-state.h (program_state::on_edge): Add uncertainty param.
7565 (program_state::prune_for_point): Likewise.
7566 * region-model-impl-calls.cc (call_details::get_uncertainty): New.
7567 (region_model::impl_call_memcpy): Pass uncertainty to
7568 mark_region_as_unknown call.
7569 (region_model::impl_call_memset): Likewise.
7570 (region_model::impl_call_strcpy): Likewise.
7571 * region-model-reachability.cc (reachable_regions::handle_sval):
7572 Also add sval to m_mutable_svals.
7573 * region-model.cc (region_model::on_assignment): Pass any
7574 uncertainty from ctxt to the store::set_value call.
7575 (region_model::handle_unrecognized_call): Get any uncertainty from
7576 ctxt and use it to record mutable svalues at the unknown call.
7577 (region_model::get_reachable_svalues): Add uncertainty param and
7578 use it to mark any maybe-bound svalues as being reachable.
7579 (region_model::set_value): Pass any uncertainty from ctxt to the
7580 store::set_value call.
7581 (region_model::mark_region_as_unknown): Add uncertainty param and
7582 pass it on to the store::mark_region_as_unknown call.
7583 (region_model::update_for_call_summary): Add uncertainty param and
7584 pass it on to the region_model::mark_region_as_unknown call.
7585 * region-model.h (call_details::get_uncertainty): New decl.
7586 (region_model::get_reachable_svalues): Add uncertainty param.
7587 (region_model::mark_region_as_unknown): Add uncertainty param.
7588 (region_model_context::get_uncertainty): New vfunc.
7589 (noop_region_model_context::get_uncertainty): New vfunc
7591 * store.cc (dump_svalue_set): New.
7592 (uncertainty_t::dump_to_pp): New.
7593 (uncertainty_t::dump): New.
7594 (binding_cluster::clobber_region): Pass NULL for uncertainty to
7595 remove_overlapping_bindings.
7596 (binding_cluster::mark_region_as_unknown): Add uncertainty param
7597 and pass it to remove_overlapping_bindings.
7598 (binding_cluster::remove_overlapping_bindings): Add uncertainty param.
7599 Use it to record any svalues that were in clobbered bindings.
7600 (store::set_value): Add uncertainty param. Pass it to
7601 binding_cluster::mark_region_as_unknown when handling symbolic
7603 (store::mark_region_as_unknown): Add uncertainty param and pass it
7604 to binding_cluster::mark_region_as_unknown.
7605 (store::remove_overlapping_bindings): Add uncertainty param and
7606 pass it to binding_cluster::remove_overlapping_bindings.
7607 * store.h (binding_cluster::mark_region_as_unknown): Add
7609 (binding_cluster::remove_overlapping_bindings): Likewise.
7610 (store::set_value): Likewise.
7611 (store::mark_region_as_unknown): Likewise.
7613 2021-04-05 David Malcolm <dmalcolm@redhat.com>
7616 * analyzer.cc (maybe_reconstruct_from_def_stmt): Fix NULL
7617 dereference on calls with zero arguments.
7618 * sm-malloc.cc (malloc_state_machine::on_stmt): When handling
7619 __attribute__((nonnull)), only call get_diagnostic_tree if the
7620 result will be used.
7622 2021-04-05 David Malcolm <dmalcolm@redhat.com>
7625 * diagnostic-manager.cc
7626 (diagnostic_manager::prune_interproc_events): Use signed integers
7627 when subtracting one from path->num_events ().
7628 (diagnostic_manager::consolidate_conditions): Likewise. Convert
7629 next_idx to a signed int.
7631 2021-04-01 David Malcolm <dmalcolm@redhat.com>
7633 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic): Make
7634 enode param non-constant, and call add_diagnostic on it. Add
7635 enode index to log message.
7636 (diagnostic_manager::add_diagnostic): Make enode param
7638 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
7639 Likewise for both decls.
7641 (impl_region_model_context::impl_region_model_context): Likewise
7643 (impl_sm_context::impl_sm_context): Likewise.
7644 (impl_sm_context::m_enode_for_diag): Likewise.
7645 (exploded_node::dump_dot): Don't pass the diagnostic manager
7646 to dump_saved_diagnostics.
7647 (exploded_node::dump_saved_diagnostics): Drop param. Iterate
7648 directly through all saved diagnostics for the enode, rather
7649 than all saved diagnostics in the diagnostic_manager and
7651 (exploded_node::on_stmt): Make non-const.
7652 (exploded_node::on_edge): Likewise.
7653 (exploded_node::on_longjmp): Likewise.
7654 (exploded_node::detect_leaks): Likewise.
7655 (exploded_graph::get_or_create_node): Make enode_for_diag param
7657 (exploded_graph_annotator::print_enode): Iterate
7658 directly through all saved diagnostics for the enode, rather
7659 than all saved diagnostics in the diagnostic_manager and
7662 (impl_region_model_context::impl_region_model_context): Make
7663 enode_for_diag param non-constant.
7664 (impl_region_model_context::m_enode_for_diag): Likewise.
7665 (exploded_node::dump_saved_diagnostics): Drop param.
7666 (exploded_node::on_stmt): Make non-const.
7667 (exploded_node::on_edge): Likewise.
7668 (exploded_node::on_longjmp): Likewise.
7669 (exploded_node::detect_leaks): Likewise.
7670 (exploded_node::add_diagnostic): New.
7671 (exploded_node::get_num_diagnostics): New.
7672 (exploded_node::get_saved_diagnostic): New.
7673 (exploded_node::m_saved_diagnostics): New.
7674 (exploded_graph::get_or_create_node): Make enode_for_diag param
7676 * feasible-graph.cc (feasible_node::dump_dot): Drop
7677 diagnostic_manager from call to dump_saved_diagnostics.
7678 * program-state.cc (program_state::on_edge): Convert enode param
7679 to non-const pointer.
7680 (program_state::prune_for_point): Likewise for enode_for_diag
7682 * program-state.h (program_state::on_edge): Convert enode param
7683 to non-const pointer.
7684 (program_state::prune_for_point): Likewise for enode_for_diag
7687 2021-03-31 David Malcolm <dmalcolm@redhat.com>
7690 * analyzer.cc (maybe_reconstruct_from_def_stmt): New.
7691 (fixup_tree_for_diagnostic_1): New.
7692 (fixup_tree_for_diagnostic): New.
7693 * analyzer.h (fixup_tree_for_diagnostic): New decl.
7694 * checker-path.cc (call_event::get_desc): Call
7695 fixup_tree_for_diagnostic and use it for the call_with_state call.
7696 (warning_event::get_desc): Likewise for the final_event and
7697 make_label_text calls.
7698 * engine.cc (impl_region_model_context::on_state_leak): Likewise
7699 for the on_leak and add_diagnostic calls.
7700 * region-model.cc (region_model::get_representative_tree):
7701 Likewise for the result.
7703 2021-03-30 David Malcolm <dmalcolm@redhat.com>
7705 * region.h (region::dump_to_pp): Remove old decl.
7707 2021-03-30 David Malcolm <dmalcolm@redhat.com>
7709 * sm-file.cc (fileptr_state_machine::on_stmt): Only call
7710 get_diagnostic_tree if the result will be used.
7711 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
7712 (malloc_state_machine::on_deallocator_call): Likewise.
7713 (malloc_state_machine::on_realloc_call): Likewise.
7714 (malloc_state_machine::on_realloc_call): Likewise.
7716 (sensitive_state_machine::warn_for_any_exposure): Likewise.
7717 * sm-taint.cc (taint_state_machine::on_stmt): Likewise.
7719 2021-03-25 David Malcolm <dmalcolm@redhat.com>
7724 * engine.cc (exploded_node::on_stmt): Clear sm-state involving
7725 an SSA name at the def-stmt of that SSA name.
7726 * program-state.cc (sm_state_map::purge_state_involving): New.
7727 * program-state.h (sm_state_map::purge_state_involving): New decl.
7728 * region-model.cc (selftest::test_involves_p): New.
7729 (selftest::analyzer_region_model_cc_tests): Call it.
7730 * svalue.cc (class involvement_visitor): New class
7731 (svalue::involves_p): New.
7732 * svalue.h (svalue::involves_p): New decl.
7734 2021-03-19 David Malcolm <dmalcolm@redhat.com>
7737 * diagnostic-manager.cc (class epath_finder): Add
7738 DISABLE_COPY_AND_ASSIGN.
7740 2021-03-15 Martin Liska <mliska@suse.cz>
7742 * sm-file.cc (get_file_using_fns): Add missing comma in initializer.
7744 2021-03-11 David Malcolm <dmalcolm@redhat.com>
7747 * analyzer.opt (-param=analyzer-max-infeasible-edges=): New param.
7748 (fdump-analyzer-feasibility): New flag.
7749 * diagnostic-manager.cc: Include "analyzer/trimmed-graph.h" and
7750 "analyzer/feasible-graph.h".
7751 (epath_finder::epath_finder): Convert m_sep to a pointer and
7752 only create it if !flag_analyzer_feasibility.
7753 (epath_finder::~epath_finder): New.
7754 (epath_finder::m_sep): Convert to a pointer.
7755 (epath_finder::get_best_epath): Add param "diag_idx" and use it
7756 when logging. Rather than finding the shortest path and then
7757 checking feasibility, instead use explore_feasible_paths unless
7758 !flag_analyzer_feasibility, in which case simply use the shortest
7759 path, and note if it is infeasible. Update for m_sep becoming a
7761 (class feasible_worklist): New.
7762 (epath_finder::explore_feasible_paths): New.
7763 (epath_finder::process_worklist_item): New.
7764 (class dump_eg_with_shortest_path): New.
7765 (epath_finder::dump_trimmed_graph): New.
7766 (epath_finder::dump_feasible_graph): New.
7767 (saved_diagnostic::saved_diagnostic): Add "idx" param, using it
7769 (saved_diagnostic::to_json): Dump m_idx.
7770 (saved_diagnostic::calc_best_epath): Pass m_idx to get_best_epath.
7771 Remove assertion that m_problem was set when m_best_epath is NULL.
7772 (diagnostic_manager::add_diagnostic): Pass an index when created
7773 saved_diagnostic instances.
7774 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add
7776 (saved_diagnostic::get_index): New accessor.
7777 (saved_diagnostic::m_idx): New field.
7778 * engine.cc (exploded_node::dump_dot): Call args.dump_extra_info.
7780 (exploded_node::dump_processed_stmts): ...this new function and...
7781 (exploded_node::dump_saved_diagnostics): ...this new function.
7782 Add index of each diagnostic.
7783 (exploded_edge::dump_dot): Move bulk of code to...
7784 (exploded_edge::dump_dot_label): ...this new function.
7785 * exploded-graph.h (eg_traits::dump_args_t::dump_extra_info): New
7787 (exploded_node::dump_processed_stmts): New decl.
7788 (exploded_node::dump_saved_diagnostics): New decl.
7789 (exploded_edge::dump_dot_label): New decl.
7790 * feasible-graph.cc: New file.
7791 * feasible-graph.h: New file.
7792 * trimmed-graph.cc: New file.
7793 * trimmed-graph.h: New file.
7795 2021-03-11 David Malcolm <dmalcolm@redhat.com>
7797 * diagnostic-manager.cc (epath_finder::epath_finder):
7798 Update shortest_paths init for new param.
7800 2021-03-10 David Malcolm <dmalcolm@redhat.com>
7803 * engine.cc (exploded_path::feasible_p): Move "snodes_visited" and
7804 "model" locals into a new class feasibility_state. Move heart
7805 of per-edge processing into
7806 feasibility_state::maybe_update_for_edge.
7807 (feasibility_state::feasibility_state): New.
7808 (feasibility_state::maybe_update_for_edge): New, based on loop
7809 body in exploded_path::feasible_p.
7810 * exploded-graph.h (class feasibility_state): New.
7812 2021-03-10 David Malcolm <dmalcolm@redhat.com>
7815 (callgraph_superedge::dyn_cast_callgraph_superedge): New.
7816 (call_superedge::dyn_cast_callgraph_superedge): Delete.
7817 (return_superedge::dyn_cast_callgraph_superedge): Delete.
7819 2021-03-02 Martin Liska <mliska@suse.cz>
7821 * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostics):
7824 2021-02-26 David Malcolm <dmalcolm@redhat.com>
7826 * engine.cc (exploded_path::exploded_path): New copy-ctor.
7827 * exploded-graph.h (exploded_path::operator=): Drop decl.
7829 2021-02-26 David Malcolm <dmalcolm@redhat.com>
7832 * diagnostic-manager.cc (class epath_finder): New.
7833 (epath_finder::get_best_epath): New.
7834 (saved_diagnostic::saved_diagnostic): Update for replacement of
7835 m_state and m_epath_length with m_best_epath.
7836 (saved_diagnostic::~saved_diagnostic): Delete m_best_epath.
7837 (saved_diagnostic::to_json): Update "path_length" to be optional.
7838 (saved_diagnostic::calc_best_epath): New, based on
7839 dedupe_winners::add and parts of dedupe_key::dedupe_key.
7840 (saved_diagnostic::get_epath_length): New.
7841 (saved_diagnostic::add_duplicate): New.
7842 (dedupe_key::dedupe_key): Drop epath param. Move invocation of
7843 stmt_finder to saved_diagnostic::calc_best_epath.
7844 (class dedupe_candidate): Delete.
7845 (class dedupe_hash_map_traits): Update to use saved_diagnotic *
7846 rather than dedupe_candidate * as the value_type/compare_type.
7847 (dedupe_winners::~dedupe_winners): Don't delete the values.
7848 (dedupe_winners::add): Convert param from shortest_exploded_paths to
7849 epath_finder. Drop "eg" param. Drop dedupe_candidate, moving
7850 path generation and feasiblity checking to
7851 epath_finder::get_best_epath. Update winner-selection for move
7852 of epaths from dedupe_candidate to saved_diagnostic.
7853 (dedupe_winners::emit_best): Update for removal of class
7855 (dedupe_winners::map_t): Update to use saved_diagnotic * rather
7856 than dedupe_candidate * as the value_type/compare_type.
7857 (diagnostic_manager::emit_saved_diagnostics): Move
7858 shortest_exploded_paths instance into epath_finder and pass that
7860 (diagnostic_manager::emit_saved_diagnostic): Drop epath, stmt
7861 and num_dupes params, instead getting these from the
7862 saved_diagnostic. Use correct location in inform_n call.
7863 * diagnostic-manager.h (class epath_finder): New forward decl.
7864 (saved_diagnostic::status): Drop enum.
7865 (saved_diagnostic::set_feasible): Drop.
7866 (saved_diagnostic::set_infeasible): Drop.
7867 (saved_diagnostic::get_status): Drop.
7868 (saved_diagnostic::calc_best_epath): New decl.
7869 (saved_diagnostic::get_best_epath): New decl.
7870 (saved_diagnostic::get_epath_length): New decl.
7871 (saved_diagnostic::set_epath_length): Drop.
7872 (saved_diagnostic::get_epath_length): Drop inline implementation.
7873 (saved_diagnostic::add_duplicate): New.
7874 (saved_diagnostic::get_num_dupes): New.
7875 (saved_diagnostic::m_d): Document ownership.
7876 (saved_diagnostic::m_trailing_eedge): Make const.
7877 (saved_diagnostic::m_status): Drop field.
7878 (saved_diagnostic::m_epath_length): Drop field.
7879 (saved_diagnostic::m_best_epath): New field.
7880 (saved_diagnostic::m_problem): Document ownership.
7881 (saved_diagnostic::m_duplicates): New field.
7882 (diagnostic_manager::emit_saved_diagnostic): Drop params epath,
7883 stmt, and num_dupes.
7884 * engine.cc (exploded_graph_annotator::print_saved_diagnostic):
7885 Update for changes to saved_diagnostic class.
7886 * exploded-graph.h (exploded_path::feasible_p): Drop unused
7889 2021-02-25 David Malcolm <dmalcolm@redhat.com>
7892 * region-model-impl-calls.cc (region_model::impl_call_realloc): New.
7893 * region-model.cc (region_model::on_call_pre): Call it.
7894 * region-model.h (region_model::impl_call_realloc): New decl.
7895 * sm-malloc.cc (enum wording): Add WORDING_REALLOCATED.
7896 (malloc_state_machine::m_realloc): New field.
7897 (use_after_free::describe_state_change): Add case for
7898 WORDING_REALLOCATED.
7899 (use_after_free::describe_final_event): Likewise.
7900 (malloc_state_machine::malloc_state_machine): Initialize
7902 (malloc_state_machine::on_stmt): Handle realloc by calling...
7903 (malloc_state_machine::on_realloc_call): New.
7905 2021-02-22 David Malcolm <dmalcolm@redhat.com>
7908 * engine.cc (exploded_node::on_stmt): Provide terminate_path
7909 flag as a way for on_call_pre to terminate the current analysis
7911 * region-model-impl-calls.cc (call_details::num_args): New.
7912 (region_model::impl_call_error): New.
7913 * region-model.cc (region_model::on_call_pre): Add param
7914 "out_terminate_path". Handle "error" and "error_at_line".
7915 * region-model.h (call_details::num_args): New decl.
7916 (region_model::on_call_pre): Add param "out_terminate_path".
7917 (region_model::impl_call_error): New decl.
7919 2021-02-17 David Malcolm <dmalcolm@redhat.com>
7922 * constraint-manager.cc (dead_svalue_purger::should_purge_p):
7923 Update for change to svalue::live_p.
7924 * program-state.cc (sm_state_map::on_liveness_change): Likewise.
7925 (program_state::detect_leaks): Likewise.
7926 * region-model-reachability.cc (reachable_regions::init_cluster):
7927 When dealing with a symbolic region, if the underlying pointer is
7928 implicitly live, add the region to the reachable regions.
7929 * region-model.cc (region_model::compare_initial_and_pointer):
7930 Move logic for detecting initial values of params to
7931 initial_svalue::initial_value_of_param_p.
7932 * svalue.cc (svalue::live_p): Convert "live_svalues" from a
7933 reference to a pointer; support it being NULL.
7934 (svalue::implicitly_live_p): Convert first param from a
7935 refererence to a pointer.
7936 (region_svalue::implicitly_live_p): Likewise.
7937 (constant_svalue::implicitly_live_p): Likewise.
7938 (initial_svalue::implicitly_live_p): Likewise. Treat the initial
7939 values of params for the top level frame as still live.
7940 (initial_svalue::initial_value_of_param_p): New function, taken
7941 from a test in region_model::compare_initial_and_pointer.
7942 (unaryop_svalue::implicitly_live_p): Convert first param from a
7943 refererence to a pointer.
7944 (binop_svalue::implicitly_live_p): Likewise.
7945 (sub_svalue::implicitly_live_p): Likewise.
7946 (unmergeable_svalue::implicitly_live_p): Likewise.
7947 * svalue.h (svalue::live_p): Likewise.
7948 (svalue::implicitly_live_p): Likewise.
7949 (region_svalue::implicitly_live_p): Likewise.
7950 (constant_svalue::implicitly_live_p): Likewise.
7951 (initial_svalue::implicitly_live_p): Likewise.
7952 (initial_svalue::initial_value_of_param_p): New decl.
7953 (unaryop_svalue::implicitly_live_p): Convert first param from a
7954 refererence to a pointer.
7955 (binop_svalue::implicitly_live_p): Likewise.
7956 (sub_svalue::implicitly_live_p): Likewise.
7957 (unmergeable_svalue::implicitly_live_p): Likewise.
7959 2021-02-12 David Malcolm <dmalcolm@redhat.com>
7962 * engine.cc (readability): Add names for the various arbitrary
7963 values. Handle NOP_EXPR and INTEGER_CST.
7964 (readability_comparator): Combine the readability tests for
7965 tree and stack depth, rather than performing them sequentially.
7966 (impl_region_model_context::on_state_leak): Strip off top-level
7968 * region-model.cc (region_model::get_representative_path_var): Add
7969 type-checking, moving the bulk of the implementation to...
7970 (region_model::get_representative_path_var_1): ...here. Respect
7971 types in casts by recursing and re-adding the cast, rather than
7972 merely stripping them off. Use the correct type when handling
7974 (region_model::get_representative_tree): Strip off any top-level
7976 (region_model::get_representative_path_var): Add type-checking,
7977 moving the bulk of the implementation to...
7978 (region_model::get_representative_path_var_1): ...here.
7979 * region-model.h (region_model::get_representative_path_var_1):
7981 (region_model::get_representative_path_var_1): New decl.
7982 * store.cc (append_pathvar_with_type): New.
7983 (binding_cluster::get_representative_path_vars): Cast path_vars
7984 to the correct type when adding them to *OUT_PVS.
7986 2021-02-09 David Malcolm <dmalcolm@redhat.com>
7989 * sm-file.cc (is_file_using_fn_p): Support "_IO_"-prefixed
7992 2021-02-09 David Malcolm <dmalcolm@redhat.com>
7995 * store.cc (store::set_value): Treat a pointer written to *UNKNOWN
7998 2021-02-02 David Malcolm <dmalcolm@redhat.com>
8002 * engine.cc (toplevel_function_p): Simplify so that
8003 we only reject functions with a "__analyzer_" prefix.
8004 (add_any_callbacks): Delete.
8005 (exploded_graph::build_initial_worklist): Update for
8006 dropped param of toplevel_function_p.
8007 (exploded_graph::build_initial_worklist): Don't bother
8008 looking for callbacks that are reachable from global
8011 2021-02-01 David Malcolm <dmalcolm@redhat.com>
8014 * region-model-manager.cc
8015 (region_model_manager::get_or_create_initial_value):
8016 Fold the initial value of *UNKNOWN_PTR to an UNKNOWN value.
8017 (region_model_manager::get_field_region): Fold the value
8018 of UNKNOWN_PTR->FIELD to *UNKNOWN_PTR_OF_&FIELD_TYPE.
8020 2021-01-29 David Malcolm <dmalcolm@redhat.com>
8022 * checker-path.cc (event_kind_to_string): Handle
8023 EK_START_CONSOLIDATED_CFG_EDGES and
8024 EK_END_CONSOLIDATED_CFG_EDGES.
8025 (start_consolidated_cfg_edges_event::get_desc): New.
8026 (checker_path::cfg_edge_pair_at_p): New.
8027 * checker-path.h (enum event_kind): Add
8028 EK_START_CONSOLIDATED_CFG_EDGES and
8029 EK_END_CONSOLIDATED_CFG_EDGES.
8030 (class start_consolidated_cfg_edges_event): New class.
8031 (class end_consolidated_cfg_edges_event): New class.
8032 (checker_path::delete_events): New.
8033 (checker_path::replace_event): New.
8034 (checker_path::cfg_edge_pair_at_p): New decl.
8035 * diagnostic-manager.cc (diagnostic_manager::prune_path): Call
8036 consolidate_conditions.
8037 (same_line_as_p): New.
8038 (diagnostic_manager::consolidate_conditions): New.
8039 * diagnostic-manager.h
8040 (diagnostic_manager::consolidate_conditions): New decl.
8042 2021-01-18 David Malcolm <dmalcolm@redhat.com>
8044 * analyzer.h (is_std_named_call_p): New decl.
8045 * diagnostic-manager.cc (path_builder::get_sm): New.
8046 (state_change_event_creator::state_change_event_creator): Add "pb"
8048 (state_change_event_creator::on_global_state_change): Don't consider
8049 state changes affecting other state_machines.
8050 (state_change_event_creator::on_state_change): Likewise.
8051 (state_change_event_creator::m_pb): New field.
8052 (diagnostic_manager::add_events_for_eedge): Pass pb to visitor
8054 * region-model-impl-calls.cc
8055 (region_model::impl_deallocation_call): New.
8056 * region-model.cc: Include "attribs.h".
8057 (region_model::on_call_post): Handle fndecls referenced by
8058 __attribute__((deallocated_by(FOO))).
8059 * region-model.h (region_model::impl_deallocation_call): New decl.
8060 * sm-malloc.cc: Include "stringpool.h" and "attribs.h". Add
8062 (class api): Delete.
8063 (enum resource_state): Update comment for change from api to
8064 deallocator and deallocator_set.
8065 (allocation_state::allocation_state): Drop api param. Add
8066 "deallocators" and "deallocator".
8067 (allocation_state::m_api): Drop field in favor of...
8068 (allocation_state::m_deallocators): New field.
8069 (allocation_state::m_deallocator): New field.
8070 (enum wording): Add WORDING_DEALLOCATED.
8071 (struct deallocator): New.
8072 (struct standard_deallocator): New.
8073 (struct custom_deallocator): New.
8074 (struct deallocator_set): New.
8075 (struct custom_deallocator_set): New.
8076 (struct standard_deallocator_set): New.
8077 (struct deallocator_set_map_traits): New.
8078 (malloc_state_machine::m_malloc): Drop field
8079 (malloc_state_machine::m_scalar_new): Likewise.
8080 (malloc_state_machine::m_vector_new): Likewise.
8081 (malloc_state_machine::m_free): New field
8082 (malloc_state_machine::m_scalar_delete): Likewise.
8083 (malloc_state_machine::m_vector_delete): Likewise.
8084 (malloc_state_machine::deallocator_map_t): New typedef.
8085 (malloc_state_machine::m_deallocator_map): New field.
8086 (malloc_state_machine::deallocator_set_cache_t): New typedef.
8087 (malloc_state_machine::m_custom_deallocator_set_cache): New field.
8088 (malloc_state_machine::custom_deallocator_set_map_t): New typedef.
8089 (malloc_state_machine::m_custom_deallocator_set_map): New field.
8090 (malloc_state_machine::m_dynamic_sets): New field.
8091 (malloc_state_machine::m_dynamic_deallocators): New field.
8093 (deallocator::deallocator): New ctor.
8094 (deallocator::hash): New.
8095 (deallocator::dump_to_pp): New.
8096 (deallocator::cmp): New.
8097 (deallocator::cmp_ptr_ptr): New.
8098 (standard_deallocator::standard_deallocator): New ctor.
8099 (deallocator_set::deallocator_set): New ctor.
8100 (deallocator_set::dump): New.
8101 (custom_deallocator_set::custom_deallocator_set): New ctor.
8102 (custom_deallocator_set::contains_p): New.
8103 (custom_deallocator_set::maybe_get_single): New.
8104 (custom_deallocator_set::dump_to_pp): New.
8105 (standard_deallocator_set::standard_deallocator_set): New ctor.
8106 (standard_deallocator_set::contains_p): New.
8107 (standard_deallocator_set::maybe_get_single): New.
8108 (standard_deallocator_set::dump_to_pp): New.
8110 (class mismatching_deallocation): Update for conversion from api
8111 to deallocator_set and deallocator.
8112 (double_free::emit): Use %qs.
8113 (class use_after_free): Update for conversion from api to
8114 deallocator_set and deallocator.
8115 (malloc_leak::describe_state_change): Only emit "allocated here" on
8116 a start->nonnull transition, rather than on other transitions to
8118 (allocation_state::dump_to_pp): Update for conversion from api to
8120 (allocation_state::get_nonnull): Likewise.
8121 (malloc_state_machine::malloc_state_machine): Likewise.
8122 (malloc_state_machine::~malloc_state_machine): New.
8123 (malloc_state_machine::add_state): Update for conversion from api
8125 (malloc_state_machine::get_or_create_custom_deallocator_set): New.
8126 (malloc_state_machine::maybe_create_custom_deallocator_set): New.
8127 (malloc_state_machine::get_or_create_deallocator): New.
8128 (malloc_state_machine::on_stmt): Update for conversion from api
8129 to deallocator_set. Handle "__attribute__((malloc(FOO)))", and
8130 the special attribute set on FOO.
8131 (malloc_state_machine::on_allocator_call): Update for conversion
8132 from api to deallocator_set. Add "returns_nonnull" param and use
8133 it to affect which state to transition to.
8134 (malloc_state_machine::on_deallocator_call): Update for conversion
8135 from api to deallocator_set.
8137 2021-01-14 David Malcolm <dmalcolm@redhat.com>
8139 * engine.cc (strongly_connected_components::to_json): New.
8140 (worklist::to_json): New.
8141 (exploded_graph::to_json): JSON-ify the worklist.
8142 * exploded-graph.h (strongly_connected_components::to_json): New
8144 (worklist::to_json): New decl.
8145 * store.cc (store::to_json): Fix comment.
8146 * supergraph.cc (supernode::to_json): Fix reference to
8147 "returning_call" in comment. Add optional "fun" to JSON.
8148 (edge_kind_to_string): New.
8149 (superedge::to_json): Add "kind" to JSON.
8151 2021-01-14 David Malcolm <dmalcolm@redhat.com>
8154 * analyzer.h (region_offset::operator==): Make const.
8155 * pending-diagnostic.h (pending_diagnostic::equal_p): Likewise.
8156 * store.h (binding_cluster::for_each_value): Likewise.
8157 (binding_cluster::for_each_binding): Likewise.
8159 2021-01-12 David Malcolm <dmalcolm@redhat.com>
8162 * store.cc (binding_cluster::make_unknown_relative_to): Don't mark
8163 dereferenced unknown pointers as having escaped.
8165 2021-01-07 David Malcolm <dmalcolm@redhat.com>
8168 * region.cc (decl_region::get_svalue_for_initializer): Gracefully
8169 handle when LTO writes out DECL_INITIAL as error_mark_node.
8171 2021-01-07 David Malcolm <dmalcolm@redhat.com>
8174 * store.cc (binding_cluster::can_merge_p): Add "out_store" param
8175 and pass to calls to binding_cluster::make_unknown_relative_to.
8176 (binding_cluster::make_unknown_relative_to): Add "out_store"
8177 param. Use it to mark base regions that are pointed to by
8178 pointers that become unknown as having escaped.
8179 (store::can_merge_p): Pass out_store to
8180 binding_cluster::can_merge_p.
8181 * store.h (binding_cluster::can_merge_p): Add "out_store" param.
8182 (binding_cluster::make_unknown_relative_to): Likewise.
8183 * svalue.cc (region_svalue::implicitly_live_p): New vfunc.
8184 * svalue.h (region_svalue::implicitly_live_p): New vfunc decl.
8186 2021-01-07 David Malcolm <dmalcolm@redhat.com>
8189 * engine.cc (exploded_path::feasible_p): Add missing call to
8192 2021-01-06 David Malcolm <dmalcolm@redhat.com>
8195 * region-model-reachability.cc (reachable_regions::init_cluster):
8196 Convert symbolic region handling to a switch statement. Add cases
8197 to handle SK_UNKNOWN and SK_CONJURED.
8199 2021-01-05 David Malcolm <dmalcolm@redhat.com>
8202 * store.cc (binding_map::apply_ctor_to_region): When "index" is
8203 NULL, iterate through the fields for RECORD_TYPEs, rather than
8204 creating an INTEGER_CST index.
8206 2020-11-30 David Malcolm <dmalcolm@redhat.com>
8208 * analyzer-pass.cc: Include "analyzer/analyzer.h" for the
8209 declaration of sorry_no_analyzer; include "tree.h" and
8210 "function.h" as these are needed by it.
8212 2020-11-30 David Malcolm <dmalcolm@redhat.com>
8214 * analyzer-pass.cc (pass_analyzer::execute): Move sorry call to...
8215 (sorry_no_analyzer): New.
8216 * analyzer.h (class state_machine): New forward decl.
8217 (class logger): New forward decl.
8218 (class plugin_analyzer_init_iface): New.
8219 (sorry_no_analyzer): New decl.
8220 * checker-path.cc (checker_path::fixup_locations): New.
8221 * checker-path.h (checker_event::set_location): New.
8222 (checker_path::fixup_locations): New decl.
8223 * diagnostic-manager.cc
8224 (diagnostic_manager::emit_saved_diagnostic): Call
8225 checker_path::fixup_locations, and call fixup_location
8226 on the primary location.
8227 * engine.cc: Include "plugin.h".
8228 (class plugin_analyzer_init_impl): New.
8229 (impl_run_checkers): Invoke PLUGIN_ANALYZER_INIT callbacks.
8230 * pending-diagnostic.h (pending_diagnostic::fixup_location): New
8233 2020-11-18 David Malcolm <dmalcolm@redhat.com>
8236 * sm-malloc.cc (null_deref::emit): Use CWE-476 rather than
8237 CWE-690, as this isn't due to an unchecked return value.
8238 (null_arg::emit): Likewise.
8240 2020-11-12 David Malcolm <dmalcolm@redhat.com>
8242 * checker-path.h (checker_event::get_id_ptr): New.
8243 * diagnostic-manager.cc (path_builder::path_builder): Add "sd"
8244 param and use it to initialize new field "m_sd".
8245 (path_builder::get_pending_diagnostic): New.
8246 (path_builder::m_sd): New field.
8247 (diagnostic_manager::emit_saved_diagnostic): Pass sd to
8249 (diagnostic_manager::add_events_for_superedge): Call new
8250 maybe_add_custom_events_for_superedge vfunc.
8251 * engine.cc (stale_jmp_buf::stale_jmp_buf): Add "setjmp_point"
8252 param and use it to initialize new field "m_setjmp_point".
8253 Initialize new field "m_stack_pop_event".
8254 (stale_jmp_buf::maybe_add_custom_events_for_superedge): New vfunc
8256 (stale_jmp_buf::describe_final_event): New vfunc implementation.
8257 (stale_jmp_buf::m_setjmp_point): New field.
8258 (stale_jmp_buf::m_stack_pop_event): New field.
8259 (exploded_node::on_longjmp): Pass setjmp_point to stale_jmp_buf
8261 * pending-diagnostic.h
8262 (pending_diagnostic::maybe_add_custom_events_for_superedge): New
8265 2020-11-12 David Malcolm <dmalcolm@redhat.com>
8267 PR tree-optimization/97424
8268 * analyzer.opt (Wanalyzer-shift-count-negative): New.
8269 (Wanalyzer-shift-count-overflow): New.
8270 * region-model.cc (class shift_count_negative_diagnostic): New.
8271 (class shift_count_overflow_diagnostic): New.
8272 (region_model::get_gassign_result): Complain about shift counts that
8273 are negative or are >= the operand's type's width.
8275 2020-11-10 Martin Liska <mliska@suse.cz>
8277 * constraint-manager.cc (constraint_manager::merge): Remove
8279 * constraint-manager.h: Likewise.
8280 * program-state.cc (sm_state_map::sm_state_map): Likewise.
8281 (program_state::program_state): Likewise.
8282 (test_sm_state_map): Likewise.
8283 * program-state.h: Likewise.
8284 * region-model-reachability.cc (reachable_regions::reachable_regions): Likewise.
8285 * region-model-reachability.h: Likewise.
8286 * region-model.cc (region_model::handle_unrecognized_call): Likewise.
8287 (region_model::get_reachable_svalues): Likewise.
8288 (region_model::can_merge_with_p): Likewise.
8290 2020-11-05 David Malcolm <dmalcolm@redhat.com>
8293 * svalue.cc (cmp_cst): Handle COMPLEX_CST.
8295 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8297 * program-state.cc (sm_state_map::on_liveness_change): Sort the
8298 leaking svalues before calling on_state_leak.
8299 (program_state::detect_leaks): Likewise when calling
8301 * region-model-reachability.cc
8302 (reachable_regions::mark_escaped_clusters): Likewise when
8303 calling on_escaped_function.
8305 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8308 * region-model-reachability.cc (reachable_regions::handle_sval):
8309 Operands of reachable reversible operations are reachable.
8311 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8313 * analyzer.h (class state_machine): New forward decl.
8314 (class logger): Likewise.
8315 (class visitor): Likewise.
8316 * complexity.cc: New file, taken from svalue.cc.
8317 * complexity.h: New file, taken from region-model.h.
8318 * region-model.h: Include "analyzer/svalue.h" and
8319 "analyzer/region.h". Move struct complexity to complexity.h.
8320 Move svalue, its subclasses and supporting decls to svalue.h.
8321 Move region, its subclasses and supporting decls to region.h.
8322 * region.cc: Include "analyzer/region.h".
8323 (symbolic_region::symbolic_region): Move here from region-model.h.
8324 * region.h: New file, based on material from region-model.h.
8325 * svalue.cc: Include "analyzer/svalue.h".
8326 (complexity::complexity): Move to complexity.cc.
8327 (complexity::from_pair): Likewise.
8328 * svalue.h: New file, based on material from region-model.h.
8330 2020-10-29 David Malcolm <dmalcolm@redhat.com>
8332 * program-state.cc (sm_state_map::print): Guard the printing of
8333 the origin pointer with !flag_dump_noaddr.
8334 * region.cc (string_region::dump_to_pp): Likewise for
8337 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8340 * region-model.cc (region_model::get_initial_value_for_global):
8341 Move check that !DECL_EXTERNAL from here to...
8342 * region.cc (decl_region::get_svalue_for_initializer): ...here,
8343 using it to reject zero initialization.
8345 2020-10-27 Markus Böck <markus.boeck02@gmail.com>
8348 * store.h (hash): Cast to intptr_t instead of long
8350 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8352 * constraint-manager.cc (svalue_cmp_by_ptr): Delete.
8353 (equiv_class::canonicalize): Use svalue::cmp_ptr_ptr instead.
8354 (equiv_class_cmp): Eliminate pointer comparison.
8355 * diagnostic-manager.cc (dedupe_key::comparator): If they are at
8356 the same location, also compare epath ength and pending_diagnostic
8358 * engine.cc (readability_comparator): If two path_vars have the
8359 same readability, then impose an arbitrary ordering on them.
8360 (worklist::key_t::cmp): If two points have the same plan ordering,
8361 continue the comparison. Call sm_state_map::cmp rather than
8362 comparing hash values.
8363 * program-state.cc (sm_state_map::entry_t::cmp): New.
8364 (sm_state_map::cmp): New.
8365 * program-state.h (sm_state_map::entry_t::cmp): New decl.
8366 (sm_state_map::elements): New.
8367 (sm_state_map::cmp): New.
8369 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8371 * engine.cc (setjmp_record::cmp): New.
8372 (supernode_cluster::dump_dot): Avoid embedding pointer in cluster
8374 (supernode_cluster::cmp_ptr_ptr): New.
8375 (function_call_string_cluster::dump_dot): Avoid embedding pointer
8376 in cluster name. Sort m_map when dumping child clusters.
8377 (function_call_string_cluster::cmp_ptr_ptr): New.
8378 (root_cluster::dump_dot): Sort m_map when dumping child clusters.
8379 * program-point.cc (function_point::cmp): New.
8380 (function_point::cmp_ptr): New.
8381 * program-point.h (function_point::cmp): New decl.
8382 (function_point::cmp_ptr): New decl.
8383 * program-state.cc (sm_state_map::print): Sort the values. Guard
8384 the printing of pointers with !flag_dump_noaddr.
8385 (program_state::prune_for_point): Sort the regions.
8386 (log_set_of_svalues): Sort the values. Guard the printing of
8387 pointers with !flag_dump_noaddr.
8388 * region-model-manager.cc (log_uniq_map): Sort the values.
8389 * region-model-reachability.cc (dump_set): New function template.
8390 (reachable_regions::dump_to_pp): Use it.
8391 * region-model.h (svalue::cmp_ptr): New decl.
8392 (svalue::cmp_ptr_ptr): New decl.
8393 (setjmp_record::cmp): New decl.
8394 (placeholder_svalue::get_name): New accessor.
8395 (widening_svalue::get_point): New accessor.
8396 (compound_svalue::get_map): New accessor.
8397 (conjured_svalue::get_stmt): New accessor.
8398 (conjured_svalue::get_id_region): New accessor.
8399 (region::cmp_ptrs): Rename to...
8400 (region::cmp_ptr_ptr): ...this.
8401 * region.cc (region::cmp_ptrs): Rename to...
8402 (region::cmp_ptr_ptr): ...this.
8404 (state_purge_per_ssa_name::state_purge_per_ssa_name): Sort
8405 m_points_needing_name when dumping.
8406 * store.cc (concrete_binding::cmp_ptr_ptr): New.
8407 (symbolic_binding::cmp_ptr_ptr): New.
8408 (binding_map::cmp): New.
8409 (get_sorted_parent_regions): Update for renaming of
8410 region::cmp_ptrs to region::cmp_ptr_ptr.
8411 (store::dump_to_pp): Likewise.
8412 (store::to_json): Likewise.
8413 (store::can_merge_p): Sort the base regions before considering
8415 * store.h (concrete_binding::cmp_ptr_ptr): New decl.
8416 (symbolic_binding::cmp_ptr_ptr): New decl.
8417 (binding_map::cmp): New decl.
8418 * supergraph.cc (supergraph::supergraph): Assign UIDs to the
8420 * svalue.cc (cmp_cst): New.
8421 (svalue::cmp_ptr): New.
8422 (svalue::cmp_ptr_ptr): New.
8424 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8426 * engine.cc (exploded_graph::get_or_create_node): Fix off-by-one
8427 when imposing param_analyzer_max_enodes_per_program_point limit.
8429 2020-10-27 David Malcolm <dmalcolm@redhat.com>
8431 * region-model.cc (region_model::get_representative_path_var):
8432 Implement case RK_LABEL.
8433 * region-model.h (label_region::get_label): New accessor.
8435 2020-10-22 David Malcolm <dmalcolm@redhat.com>
8438 * engine.cc (exploded_graph::add_function_entry): Handle failure
8439 to create an enode, rather than asserting.
8441 2020-10-22 David Malcolm <dmalcolm@redhat.com>
8444 * engine.cc (exploded_graph::add_function_entry): Assert that we
8445 have a function body.
8446 (exploded_graph::on_escaped_function): Reject fndecls that don't
8447 have a function body.
8449 2020-10-14 David Malcolm <dmalcolm@redhat.com>
8452 * region-model.cc (region_model::get_initial_value_for_global):
8453 Fall back to returning an initial_svalue if
8454 decl_region::get_svalue_for_initializer fails.
8455 * region.cc (decl_region::get_svalue_for_initializer): Don't
8456 attempt to create a compound_svalue if the region has an unknown
8459 2020-10-14 David Malcolm <dmalcolm@redhat.com>
8462 * store.cc (binding_map::apply_ctor_to_region): Remove redundant
8465 2020-10-12 David Malcolm <dmalcolm@redhat.com>
8468 * engine.cc (impl_region_model_context::on_escaped_function): New
8470 (exploded_graph::add_function_entry): Use m_functions_with_enodes
8471 to implement idempotency.
8472 (add_any_callbacks): New.
8473 (exploded_graph::build_initial_worklist): Use the above to find
8474 callbacks that are reachable from global initializers.
8475 (exploded_graph::on_escaped_function): New.
8477 (impl_region_model_context::on_escaped_function): New decl.
8478 (exploded_graph::on_escaped_function): New decl.
8479 (exploded_graph::m_functions_with_enodes): New field.
8480 * region-model-reachability.cc
8481 (reachable_regions::reachable_regions): Replace "store" param with
8482 "model" param; use it to initialize m_model.
8483 (reachable_regions::add): When getting the svalue for the region,
8484 call get_store_value on the model rather than using an initial
8486 (reachable_regions::mark_escaped_clusters): Add ctxt param and
8487 use it to call on_escaped_function when a function_region escapes.
8488 * region-model-reachability.h
8489 (reachable_regions::reachable_regions): Replace "store" param with
8491 (reachable_regions::mark_escaped_clusters): Add ctxt param.
8492 (reachable_regions::m_model): New field.
8493 * region-model.cc (region_model::handle_unrecognized_call): Update
8494 for change in reachable_regions ctor.
8495 (region_model::handle_unrecognized_call): Pass ctxt to
8496 mark_escaped_clusters.
8497 (region_model::get_reachable_svalues): Update for change in
8498 reachable_regions ctor.
8499 (region_model::get_initial_value_for_global): Read-only variables
8500 keep their initial values.
8501 * region-model.h (region_model_context::on_escaped_function): New
8503 (noop_region_model_context::on_escaped_function): New.
8505 2020-10-12 David Malcolm <dmalcolm@redhat.com>
8507 * analyzer.opt (Wanalyzer-write-to-const): New.
8508 (Wanalyzer-write-to-string-literal): New.
8509 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8510 Call check_for_writable_region.
8511 (region_model::impl_call_memset): Likewise.
8512 (region_model::impl_call_strcpy): Likewise.
8513 * region-model.cc (class write_to_const_diagnostic): New.
8514 (class write_to_string_literal_diagnostic): New.
8515 (region_model::check_for_writable_region): New.
8516 (region_model::set_value): Call check_for_writable_region.
8517 * region-model.h (region_model::check_for_writable_region): New
8520 2020-10-07 David Malcolm <dmalcolm@redhat.com>
8523 * sm-malloc.cc (method_p): New.
8524 (describe_argument_index): New.
8525 (inform_nonnull_attribute): Use describe_argument_index.
8526 (possible_null_arg::describe_final_event): Likewise.
8527 (null_arg::describe_final_event): Likewise.
8529 2020-09-29 David Malcolm <dmalcolm@redhat.com>
8532 * engine.cc (stmt_requires_new_enode_p): Split enodes before
8535 2020-09-29 David Malcolm <dmalcolm@redhat.com>
8537 * constraint-manager.cc
8538 (constraint_manager::add_constraint_internal): Whitespace fixes.
8539 Silence -Wsign-compare warning.
8540 * engine.cc (maybe_process_run_of_before_supernode_enodes):
8541 Silence -Wsign-compare warning.
8543 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8545 * region-model.h (binop_svalue::dyn_cast_binop_svalue): Remove
8546 redundant "virtual". Add FINAL OVERRIDE.
8547 (widening_svalue::dyn_cast_widening_svalue): Add FINAL OVERRIDE.
8548 (compound_svalue::dyn_cast_compound_svalue): Likewise.
8549 (conjured_svalue::dyn_cast_conjured_svalue): Likewise.
8551 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8553 * diagnostic-manager.cc (null_assignment_sm_context::m_visitor):
8554 Remove unused field.
8556 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8559 * analyzer.cc (is_longjmp_call_p): Require the initial argument
8561 * engine.cc (exploded_node::on_longjmp): Likewise.
8563 2020-09-28 David Malcolm <dmalcolm@redhat.com>
8565 * program-state.cc (sm_state_map::print): Update check
8566 for m_global_state being the start state.
8568 2020-09-26 David Malcolm <dmalcolm@redhat.com>
8572 * region-model.cc (region_model::get_representative_path_var):
8573 When handling offset_region, wrap the MEM_REF's first argument in
8574 an ADDR_EXPR of pointer type, rather than simply using the tree
8575 for the parent region. Require the MEM_REF's second argument to
8576 be an integer constant.
8578 2020-09-24 David Malcolm <dmalcolm@redhat.com>
8580 * analyzer.h (struct rejected_constraint): New decl.
8581 * analyzer.opt (fanalyzer-feasibility): New option.
8582 * diagnostic-manager.cc (path_builder::path_builder): Add
8583 "problem" param and use it to initialize new field.
8584 (path_builder::get_feasibility_problem): New accessor.
8585 (path_builder::m_feasibility_problem): New field.
8586 (dedupe_winners::add): Remove inversion of logic in "if" clause,
8587 swapping if/else suites. In the !feasible_p suite, inspect
8588 flag_analyzer_feasibility and add code to handle when this
8589 is off, accepting the infeasible path, but recording the
8590 feasibility_problem.
8591 (diagnostic_manager::emit_saved_diagnostic): Pass the
8592 feasibility_problem to the path_builder.
8593 (diagnostic_manager::add_events_for_eedge): If we have
8594 a feasibility_problem at this edge, use it to add a custom event.
8595 * engine.cc (exploded_path::feasible_p): Pass a
8596 rejected_constraint ** to model.maybe_update_for_edge and transfer
8597 ownership of any created instance to any feasibility_problem.
8598 (feasibility_problem::dump_to_pp): New.
8599 * exploded-graph.h (feasibility_problem::feasibility_problem):
8600 Drop "model" param; add rejected_constraint * param.
8601 (feasibility_problem::~feasibility_problem): New.
8602 (feasibility_problem::dump_to_pp): New decl.
8603 (feasibility_problem::m_model): Drop field.
8604 (feasibility_problem::m_rc): New field.
8605 * program-point.cc (function_point::get_location): Handle
8606 PK_BEFORE_SUPERNODE and PK_AFTER_SUPERNODE.
8607 * program-state.cc (program_state::on_edge): Pass NULL to new
8608 param of region_model::maybe_update_for_edge.
8609 * region-model.cc (region_model::add_constraint): New overload
8610 adding a rejected_constraint ** param.
8611 (region_model::maybe_update_for_edge): Add rejected_constraint **
8612 param and pass it to the various apply_constraints_for_ calls.
8613 (region_model::apply_constraints_for_gcond): Add
8614 rejected_constraint ** param and pass it to add_constraint calls.
8615 (region_model::apply_constraints_for_gswitch): Likewise.
8616 (region_model::apply_constraints_for_exception): Likewise.
8617 (rejected_constraint::dump_to_pp): New.
8618 * region-model.h (region_model::maybe_update_for_edge):
8619 Add rejected_constraint ** param.
8620 (region_model::add_constraint): New overload adding a
8621 rejected_constraint ** param.
8622 (region_model::apply_constraints_for_gcond): Add
8623 rejected_constraint ** param.
8624 (region_model::apply_constraints_for_gswitch): Likewise.
8625 (region_model::apply_constraints_for_exception): Likewise.
8626 (struct rejected_constraint): New.
8628 2020-09-23 David Malcolm <dmalcolm@redhat.com>
8631 * engine.cc (impl_run_checkers): Update for change to ext_state
8633 * program-state.cc (selftest::test_sm_state_map): Pass an engine
8634 instance to ext_state ctor.
8635 (selftest::test_program_state_1): Likewise.
8636 (selftest::test_program_state_2): Likewise.
8637 (selftest::test_program_state_merging): Likewise.
8638 (selftest::test_program_state_merging_2): Likewise.
8639 * program-state.h (extrinsic_state::extrinsic_state): Remove NULL
8640 default value for "eng" param.
8642 2020-09-23 Tobias Burnus <tobias@codesourcery.com>
8644 * analyzer-logging.cc: Guard '#pragma ... ignored "-Wformat-diag"'
8645 by '#if __GNUC__ >= 10'
8646 * analyzer.h: Likewise.
8647 * call-string.cc: Likewise.
8649 2020-09-23 David Malcolm <dmalcolm@redhat.com>
8651 * engine.cc (exploded_node::on_stmt): Replace sequence of dyn_cast
8654 2020-09-22 David Malcolm <dmalcolm@redhat.com>
8656 * analysis-plan.cc: Include "json.h".
8657 * analyzer.opt (fdump-analyzer-json): New.
8658 * call-string.cc: Include "json.h".
8659 (call_string::to_json): New.
8660 * call-string.h (call_string::to_json): New decl.
8661 * checker-path.cc: Include "json.h".
8662 * constraint-manager.cc: Include "json.h".
8663 (equiv_class::to_json): New.
8664 (constraint::to_json): New.
8665 (constraint_manager::to_json): New.
8666 * constraint-manager.h (equiv_class::to_json): New decl.
8667 (constraint::to_json): New decl.
8668 (constraint_manager::to_json): New decl.
8669 * diagnostic-manager.cc: Include "json.h".
8670 (saved_diagnostic::to_json): New.
8671 (diagnostic_manager::to_json): New.
8672 * diagnostic-manager.h (saved_diagnostic::to_json): New decl.
8673 (diagnostic_manager::to_json): New decl.
8674 * engine.cc: Include "json.h", <zlib.h>.
8675 (exploded_node::status_to_str): New.
8676 (exploded_node::to_json): New.
8677 (exploded_edge::to_json): New.
8678 (exploded_graph::to_json): New.
8679 (dump_analyzer_json): New.
8680 (impl_run_checkers): Call it.
8681 * exploded-graph.h (exploded_node::status_to_str): New decl.
8682 (exploded_node::to_json): New.
8683 (exploded_edge::to_json): New.
8684 (exploded_graph::to_json): New.
8685 * pending-diagnostic.cc: Include "json.h".
8686 * program-point.cc: Include "json.h".
8687 (program_point::to_json): New.
8688 * program-point.h (program_point::to_json): New decl.
8689 * program-state.cc: Include "json.h".
8690 (extrinsic_state::to_json): New.
8691 (sm_state_map::to_json): New.
8692 (program_state::to_json): New.
8693 * program-state.h (extrinsic_state::to_json): New decl.
8694 (sm_state_map::to_json): New decl.
8695 (program_state::to_json): New decl.
8696 * region-model-impl-calls.cc: Include "json.h".
8697 * region-model-manager.cc: Include "json.h".
8698 * region-model-reachability.cc: Include "json.h".
8699 * region-model.cc: Include "json.h".
8700 * region-model.h (svalue::to_json): New decl.
8701 (region::to_json): New decl.
8702 * region.cc: Include "json.h".
8703 (region::to_json: New.
8704 * sm-file.cc: Include "json.h".
8705 * sm-malloc.cc: Include "json.h".
8706 * sm-pattern-test.cc: Include "json.h".
8707 * sm-sensitive.cc: Include "json.h".
8708 * sm-signal.cc: Include "json.h".
8709 (signal_delivery_edge_info_t::to_json): New.
8710 * sm-taint.cc: Include "json.h".
8711 * sm.cc: Include "diagnostic.h", "tree-diagnostic.h", and
8713 (state_machine::state::to_json): New.
8714 (state_machine::to_json): New.
8715 * sm.h (state_machine::state::to_json): New.
8716 (state_machine::to_json): New.
8717 * state-purge.cc: Include "json.h".
8718 * store.cc: Include "json.h".
8719 (binding_key::get_desc): New.
8720 (binding_map::to_json): New.
8721 (binding_cluster::to_json): New.
8722 (store::to_json): New.
8723 * store.h (binding_key::get_desc): New decl.
8724 (binding_map::to_json): New decl.
8725 (binding_cluster::to_json): New decl.
8726 (store::to_json): New decl.
8727 * supergraph.cc: Include "json.h".
8728 (supergraph::to_json): New.
8729 (supernode::to_json): New.
8730 (superedge::to_json): New.
8731 * supergraph.h (supergraph::to_json): New decl.
8732 (supernode::to_json): New decl.
8733 (superedge::to_json): New decl.
8734 * svalue.cc: Include "json.h".
8735 (svalue::to_json): New.
8737 2020-09-21 David Malcolm <dmalcolm@redhat.com>
8740 * region-model-impl-calls.cc (call_details::get_arg_type): New.
8741 * region-model.cc (region_model::on_call_pre): Check that the
8742 initial arg is a pointer before calling impl_call_memset and
8744 * region-model.h (call_details::get_arg_type): New decl.
8746 2020-09-21 David Malcolm <dmalcolm@redhat.com>
8749 * sm-malloc.cc (malloc_state_machine::get_default_state): Look at
8750 the base region when considering pointers. Treat pointers to
8751 decls as being non-heap.
8753 2020-09-18 David Malcolm <dmalcolm@redhat.com>
8755 * checker-path.cc (warning_event::get_desc): Handle global state
8758 2020-09-18 David Malcolm <dmalcolm@redhat.com>
8760 * sm-malloc.cc (malloc_state_machine::on_stmt): Handle strdup and
8761 strndup as being malloc-like allocators.
8763 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8765 * engine.cc (strongly_connected_components::strong_connect): Only
8766 consider intraprocedural edges when creating SCCs.
8767 (worklist::key_t::cmp): Add comment. Treat call_string
8768 differences as more important than differences of program_point
8771 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8773 * engine.cc (supernode_cluster::dump_dot): Show the SCC id
8774 in the per-supernode clusters in FILENAME.eg.dot output.
8775 (exploded_graph_annotator::add_node_annotations):
8776 Show the SCC of the supernode in FILENAME.supernode.eg.dot output.
8777 * exploded-graph.h (worklist::scc_id): New.
8778 (exploded_graph::get_scc_id): New.
8780 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8782 * engine.cc (exploded_node::dump_dot): Show STATUS_BULK_MERGED.
8783 (exploded_graph::process_worklist): Call
8784 maybe_process_run_of_before_supernode_enodes.
8785 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
8787 (exploded_graph_annotator::print_enode): Show STATUS_BULK_MERGED.
8788 * exploded-graph.h (enum exploded_node::status): Add
8791 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8794 (exploded_graph::process_node) <case PK_BEFORE_SUPERNODE>:
8795 Simplify by using program_point::get_next.
8796 * program-point.cc (program_point::get_next): New.
8797 * program-point.h (program_point::get_next): New decl.
8799 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8801 * engine.cc (exploded_graph::get_or_create_node): Show the
8802 program point when issuing -Wanalyzer-too-complex due to hitting
8803 the per-program-point limit.
8805 2020-09-16 David Malcolm <dmalcolm@redhat.com>
8807 * region-model.cc (region_model::on_call_pre): Treat getchar as
8808 having no side-effects.
8810 2020-09-15 David Malcolm <dmalcolm@redhat.com>
8813 * constraint-manager.cc (merger_fact_visitor::on_fact): Replace
8814 assertion that add_constraint succeeded with an assertion that
8815 if it fails, -fanalyzer-transitivity is off.
8817 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8819 * analyzer.opt (-param=analyzer-max-constraints=): New param.
8820 * constraint-manager.cc
8821 (constraint_manager::add_constraint_internal): Silently reject
8822 attempts to add constraints when the above limit is reached.
8824 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8827 * constraint-manager.cc
8828 (constraint_manager::get_or_add_equiv_class): Don't accumulate
8829 transitive closure of all constraints on constants.
8831 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8834 * analyzer.cc (is_setjmp_call_p): Require the initial arg to be a
8836 * region-model.cc (region_model::deref_rvalue): Assert that the
8837 svalue is of pointer type.
8839 2020-09-11 David Malcolm <dmalcolm@redhat.com>
8842 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8844 (region_model::impl_call_strcpy): New.
8845 * region-model.cc (region_model::on_call_pre): Flag unhandled
8846 builtins that are non-pure as having unknown side-effects.
8847 Implement BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_STRCPY,
8848 BUILT_IN_STRCPY_CHK, BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED,
8849 BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_FPUTC,
8850 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
8851 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
8852 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
8853 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
8854 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF.
8855 * region-model.h (region_model::impl_call_memcpy): New decl.
8856 (region_model::impl_call_strcpy): New decl.
8858 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8861 * analyzer.opt (Wanalyzer-mismatching-deallocation): New warning.
8862 * region-model-impl-calls.cc
8863 (region_model::impl_call_operator_new): New.
8864 (region_model::impl_call_operator_delete): New.
8865 * region-model.cc (region_model::on_call_pre): Detect operator new
8866 and operator delete.
8867 (region_model::on_call_post): Likewise.
8868 (region_model::maybe_update_for_edge): Detect EH edges and call...
8869 (region_model::apply_constraints_for_exception): New function.
8870 * region-model.h (region_model::impl_call_operator_new): New decl.
8871 (region_model::impl_call_operator_delete): New decl.
8872 (region_model::apply_constraints_for_exception): New decl.
8873 * sm-malloc.cc (enum resource_state): New.
8874 (struct allocation_state): New state subclass.
8875 (enum wording): New.
8877 (malloc_state_machine::custom_data_t): New typedef.
8878 (malloc_state_machine::add_state): New decl.
8879 (malloc_state_machine::m_unchecked)
8880 (malloc_state_machine::m_nonnull)
8881 (malloc_state_machine::m_freed): Delete these states in favor
8883 (malloc_state_machine::m_malloc)
8884 (malloc_state_machine::m_scalar_new)
8885 (malloc_state_machine::m_vector_new): ...this new api instances,
8886 which own their own versions of these states.
8887 (malloc_state_machine::on_allocator_call): New decl.
8888 (malloc_state_machine::on_deallocator_call): New decl.
8889 (api::api): New ctor.
8890 (dyn_cast_allocation_state): New.
8891 (as_a_allocation_state): New.
8896 (malloc_diagnostic::describe_state_change): Use unchecked_p and
8898 (class mismatching_deallocation): New.
8899 (double_free::double_free): Add funcname param for initializing
8901 (double_free::emit): Use m_funcname in warning message rather
8902 than hardcoding "free".
8903 (double_free::describe_state_change): Likewise. Use freed_p.
8904 (double_free::describe_call_with_state): Use freed_p.
8905 (double_free::describe_final_event): Use m_funcname in message
8906 rather than hardcoding "free".
8907 (double_free::m_funcname): New field.
8908 (possible_null::describe_state_change): Use unchecked_p.
8909 (possible_null::describe_return_of_state): Likewise.
8910 (use_after_free::use_after_free): Add param for initializing m_api.
8911 (use_after_free::emit): Use m_api->m_dealloc_funcname in message
8912 rather than hardcoding "free".
8913 (use_after_free::describe_state_change): Use freed_p. Change the
8914 wording of the message based on the API.
8915 (use_after_free::describe_final_event): Use
8916 m_api->m_dealloc_funcname in message rather than hardcoding
8917 "free". Change the wording of the message based on the API.
8918 (use_after_free::m_api): New field.
8919 (malloc_leak::describe_state_change): Use unchecked_p. Update
8920 for renaming of m_malloc_event to m_alloc_event.
8921 (malloc_leak::describe_final_event): Update for renaming of
8922 m_malloc_event to m_alloc_event.
8923 (malloc_leak::m_malloc_event): Rename...
8924 (malloc_leak::m_alloc_event): ...to this.
8925 (free_of_non_heap::free_of_non_heap): Add param for initializing
8927 (free_of_non_heap::emit): Use m_funcname in message rather than
8929 (free_of_non_heap::describe_final_event): Likewise.
8930 (free_of_non_heap::m_funcname): New field.
8931 (allocation_state::dump_to_pp): New.
8932 (allocation_state::get_nonnull): New.
8933 (malloc_state_machine::malloc_state_machine): Update for changes
8934 to state fields and new api fields.
8935 (malloc_state_machine::add_state): New.
8936 (malloc_state_machine::on_stmt): Move malloc/calloc handling to
8937 on_allocator_call and call it, passing in the API pointer.
8938 Likewise for free, moving it to on_deallocator_call. Handle calls
8939 to operator new and delete in an analogous way. Use unchecked_p
8940 when testing for possibly-null-arg and possibly-null-deref, and
8941 transition to the non-null for the correct API. Remove redundant
8942 node param from call to on_zero_assignment. Use freed_p for
8943 use-after-free check, and pass in API.
8944 (malloc_state_machine::on_allocator_call): New, based on code in
8946 (malloc_state_machine::on_deallocator_call): Likewise.
8947 (malloc_state_machine::on_phi): Mark node param with
8948 ATTRIBUTE_UNUSED; don't pass it to on_zero_assignment.
8949 (malloc_state_machine::on_condition): Mark node param with
8950 ATTRIBUTE_UNUSED. Replace on_transition calls with get_state and
8951 set_next_state pairs, transitioning to the non-null state for the
8953 (malloc_state_machine::can_purge_p): Port to new state approach.
8954 (malloc_state_machine::on_zero_assignment): Replace on_transition
8955 calls with get_state and set_next_state pairs. Drop redundant
8957 * sm.h (state_machine::add_custom_state): New.
8959 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8961 * diagnostic-manager.cc
8962 (null_assignment_sm_context::warn_for_state): Replace with...
8963 (null_assignment_sm_context::warn): ...this.
8964 * engine.cc (impl_sm_context::warn_for_state): Replace with...
8965 (impl_sm_context::warn): ...this.
8966 * sm-file.cc (fileptr_state_machine::on_stmt): Replace
8967 warn_for_state and on_transition calls with a get_state
8968 test guarding warn and set_next_state calls.
8969 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
8970 * sm-pattern-test.cc (pattern_test_state_machine::on_condition):
8971 Replace warn_for_state call with warn call.
8973 (sensitive_state_machine::warn_for_any_exposure): Replace
8974 warn_for_state call with a get_state test guarding a warn call.
8975 * sm-signal.cc (signal_state_machine::on_stmt): Likewise.
8976 * sm-taint.cc (taint_state_machine::on_stmt): Replace
8977 warn_for_state and on_transition calls with a get_state
8978 test guarding warn and set_next_state calls.
8979 * sm.h (sm_context::warn_for_state): Replace with...
8980 (sm_context::warn): ...this.
8982 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8984 * diagnostic-manager.cc
8985 (null_assignment_sm_context::null_assignment_sm_context): Add old_state
8986 and ext_state params, initializing m_old_state and m_ext_state.
8987 (null_assignment_sm_context::on_transition): Split into...
8988 (null_assignment_sm_context::get_state): ...this new vfunc
8989 implementation and...
8990 (null_assignment_sm_context::set_next_state): ...this new vfunc
8992 (null_assignment_sm_context::m_old_state): New field.
8993 (null_assignment_sm_context::m_ext_state): New field.
8994 (diagnostic_manager::add_events_for_eedge): Pass in old state and
8995 ext_state when creating sm_ctxt.
8996 * engine.cc (impl_sm_context::on_transition): Split into...
8997 (impl_sm_context::get_state): ...this new vfunc
8998 implementation and...
8999 (impl_sm_context::set_next_state): ...this new vfunc
9001 * sm.h (sm_context::get_state): New pure virtual function.
9002 (sm_context::set_next_state): Likewise.
9003 (sm_context::on_transition): Convert from a pure virtual function
9004 to a regular function implemented in terms of get_state and
9007 2020-09-09 David Malcolm <dmalcolm@redhat.com>
9009 * checker-path.cc (state_change_event::get_desc): Update
9010 state_machine::get_state_name calls to state::get_name.
9011 (warning_event::get_desc): Likewise.
9012 * diagnostic-manager.cc
9013 (null_assignment_sm_context::on_transition): Update comparison
9014 against 0 with comparison with m_sm.get_start_state.
9015 (diagnostic_manager::prune_for_sm_diagnostic): Update
9016 state_machine::get_state_name calls to state::get_name.
9017 * engine.cc (impl_sm_context::on_transition): Likewise.
9018 (exploded_node::get_dot_fillcolor): Use get_id when summing
9020 * program-state.cc (sm_state_map::sm_state_map): Don't hardcode
9021 0 as the start state when initializing m_global_state.
9022 (sm_state_map::print): Use dump_to_pp rather than get_state_name
9023 when dumping states.
9024 (sm_state_map::is_empty_p): Don't hardcode 0 as the start state
9025 when examining m_global_state.
9026 (sm_state_map::hash): Use get_id when hashing states.
9027 (selftest::test_sm_state_map): Use state objects rather than
9028 arbitrary hardcoded integers.
9029 (selftest::test_program_state_merging): Likewise.
9030 (selftest::test_program_state_merging_2): Likewise.
9031 * sm-file.cc (fileptr_state_machine::m_start): Move to base class.
9032 (file_diagnostic::describe_state_change): Use get_start_state.
9033 (fileptr_state_machine::fileptr_state_machine): Drop m_start
9035 * sm-malloc.cc (malloc_state_machine::m_start): Move to base
9037 (malloc_diagnostic::describe_state_change): Use get_start_state.
9038 (possible_null::describe_state_change): Likewise.
9039 (malloc_state_machine::malloc_state_machine): Drop m_start
9041 * sm-pattern-test.cc (pattern_test_state_machine::m_start): Move
9043 (pattern_test_state_machine::pattern_test_state_machine): Drop
9044 m_start initialization.
9045 * sm-sensitive.cc (sensitive_state_machine::m_start): Move to base
9047 (sensitive_state_machine::sensitive_state_machine): Drop m_start
9049 * sm-signal.cc (signal_state_machine::m_start): Move to base
9051 (signal_state_machine::signal_state_machine): Drop m_start
9053 * sm-taint.cc (taint_state_machine::m_start): Move to base class.
9054 (taint_state_machine::taint_state_machine): Drop m_start
9056 * sm.cc (state_machine::state::dump_to_pp): New.
9057 (state_machine::state_machine): Move here from sm.h. Initialize
9058 m_next_state_id and m_start.
9059 (state_machine::add_state): Reimplement in terms of state objects.
9060 (state_machine::get_state_name): Delete.
9061 (state_machine::get_state_by_name): Reimplement in terms of state
9062 objects. Make const.
9063 (state_machine::validate): Delete.
9064 (state_machine::dump_to_pp): Reimplement in terms of state
9066 * sm.h (state_machine::state): New class.
9067 (state_machine::state_t): Convert typedef from "unsigned" to
9068 "const state_machine::state *".
9069 (state_machine::state_machine): Move to sm.cc.
9070 (state_machine::get_default_state): Use m_start rather than
9072 (state_machine::get_state_name): Delete.
9073 (state_machine::get_state_by_name): Make const.
9074 (state_machine::get_start_state): New accessor.
9075 (state_machine::alloc_state_id): New.
9076 (state_machine::m_state_names): Drop in favor of...
9077 (state_machine::m_states): New field
9078 (state_machine::m_start): New field
9079 (start_start_p): Delete.
9081 2020-09-08 David Malcolm <dmalcolm@redhat.com>
9084 * store.cc (binding_map::apply_ctor_val_to_range): Add
9085 error-handling for the cases where we have symbolic offsets.
9087 2020-09-08 David Malcolm <dmalcolm@redhat.com>
9090 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
9091 where min_index == max_index.
9092 (binding_map::apply_ctor_val_to_range): Replace assertion that we
9093 don't have a CONSTRUCTOR value with error-handling.
9095 2020-09-08 David Malcolm <dmalcolm@redhat.com>
9098 * region-model.cc (region_model::on_call_pre): Fix guard on switch
9099 on built-ins to only consider BUILT_IN_NORMAL, rather than other
9102 2020-09-01 David Malcolm <dmalcolm@redhat.com>
9105 * region-model.cc (region_model::deref_rvalue): Add the constraint
9106 that PTR_SVAL is non-NULL.
9108 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9111 * region-model.cc (region_model::on_call_pre): Handle
9112 BUILT_IN_MEMSET_CHK.
9114 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9116 * region-model.cc (region_model::on_call_pre): Gather handling of
9117 builtins and of internal fns into switch statements. Handle
9118 "alloca" and BUILT_IN_ALLOCA_WITH_ALIGN.
9120 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9123 * region.cc (decl_region::get_svalue_for_constructor): Support
9124 apply_ctor_to_region failing.
9125 * store.cc (binding_map::apply_ctor_to_region): Add failure
9127 (binding_map::apply_ctor_val_to_range): Likewise.
9128 (binding_map::apply_ctor_pair_to_child_region): Likewise. Replace
9129 assertion that child_base_offset is not symbolic with error
9131 * store.h (binding_map::apply_ctor_to_region): Convert return type
9133 (binding_map::apply_ctor_val_to_range): Likewise.
9134 (binding_map::apply_ctor_pair_to_child_region): Likewise.
9136 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9139 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
9140 by calling a new binding_map::apply_ctor_val_to_range subroutine.
9141 Split out the existing non-CONSTRUCTOR-handling code to a new
9142 apply_ctor_pair_to_child_region subroutine.
9143 (binding_map::apply_ctor_val_to_range): New.
9144 (binding_map::apply_ctor_pair_to_child_region): New, split out
9145 from binding_map::apply_ctor_to_region as noted above.
9146 * store.h (binding_map::apply_ctor_val_to_range): New decl.
9147 (binding_map::apply_ctor_pair_to_child_region): New decl.
9149 2020-08-31 David Malcolm <dmalcolm@redhat.com>
9152 * region-model-manager.cc
9153 (region_model_manager::maybe_fold_unaryop): Handle VIEW_CONVERT_EXPR.
9154 (region_model_manager::get_or_create_cast): Move logic for
9155 real->integer casting to...
9156 (get_code_for_cast): ...this new function, and add logic for
9157 real->non-integer casts.
9158 (region_model_manager::maybe_fold_sub_svalue): Handle
9161 (region_model::add_any_constraints_from_gassign): Likewise.
9162 * svalue.cc (svalue::maybe_undo_cast): Likewise.
9163 (unaryop_svalue::dump_to_pp): Likewise.
9165 2020-08-26 David Malcolm <dmalcolm@redhat.com>
9168 * region-model-manager.cc
9169 (region_model_manager::get_or_create_widening_svalue): Assert that
9170 neither of the inputs are themselves widenings.
9171 * store.cc (store::eval_alias_1): The initial value of a pointer
9172 can't point to a region that was allocated on the heap after the
9173 beginning of the path. A widened pointer value can't alias anything
9174 that the initial pointer value can't alias.
9175 * svalue.cc (svalue::can_merge_p): Merge BINOP (X, OP, CST) with X
9176 to a widening svalue. Merge
9177 BINOP(WIDENING(BASE, BINOP(BASE, X)), X) and BINOP(BASE, X) to
9178 to the LHS of the first BINOP.
9180 2020-08-26 David Malcolm <dmalcolm@redhat.com>
9183 * region-model.h (class compound_svalue): Document that all keys
9185 (compound_svalue::compound_svalue): Move definition to svalue.cc.
9186 * store.cc (binding_map::apply_ctor_to_region): Handle
9187 initializers for trailing arrays with incomplete size.
9188 * svalue.cc (compound_svalue::compound_svalue): Move definition
9189 here from region-model.h. Add assertion that all keys are
9192 2020-08-22 David Malcolm <dmalcolm@redhat.com>
9195 * region-model-manager.cc
9196 (region_model_manager::maybe_fold_binop): Fold bitwise "& 0" to 0.
9198 2020-08-22 David Malcolm <dmalcolm@redhat.com>
9200 * store.cc (store::eval_alias): Make const. Split out 2nd half
9201 into store::eval_alias_1 and call it twice for symmetry, avoiding
9203 (store::eval_alias_1): New function, split out from the above.
9204 * store.h (store::eval_alias): Make const.
9205 (store::eval_alias_1): New decl.
9207 2020-08-22 David Malcolm <dmalcolm@redhat.com>
9209 * region-model.cc (region_model::push_frame): Bind the default
9210 SSA name for each parm if it exists, falling back to the parm
9211 itself otherwise, rather than doing both.
9213 2020-08-20 David Malcolm <dmalcolm@redhat.com>
9216 * region-model-manager.cc
9217 (region_model_manager::get_field_region): Assert that field is a
9219 * region.cc (region::get_subregions_for_binding): In
9220 union-handling, filter the TYPE_FIELDS traversal to just FIELD_DECLs.
9222 2020-08-20 David Malcolm <dmalcolm@redhat.com>
9225 * region-model.cc (region_model::get_gassign_result): For
9226 comparisons, only use eval_condition when the lhs has boolean
9227 type, and use get_or_create_constant_svalue on the boolean
9228 constants directly rather than via get_rvalue.
9230 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9233 * region-model.cc (region_model::deref_rvalue): Rather than
9234 attempting to handle all svalue kinds in the switch, only cover
9235 the special cases, and move symbolic-region handling to after
9236 the switch, thus implicitly handling the missing case SK_COMPOUND.
9238 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9241 * region-model-manager.cc
9242 (region_model_manager::maybe_fold_binop): Check that we have an
9243 integral type before calling build_int_cst.
9245 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9248 * region-model-manager.cc
9249 (region_model_manager::get_or_create_cast): Use FIX_TRUNC_EXPR for
9250 casting from REAL_TYPE to INTEGER_TYPE.
9252 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9255 * region-model.cc (region_model::called_from_main_p): New.
9256 (region_model::get_store_value): Move handling for globals into...
9257 (region_model::get_initial_value_for_global): ...this new
9258 function, and add logic for extracting values from decl
9260 * region-model.h (decl_region::get_svalue_for_constructor): New
9262 (decl_region::get_svalue_for_initializer): New decl.
9263 (region_model::called_from_main_p): New decl.
9264 (region_model::get_initial_value_for_global): New.
9265 * region.cc (decl_region::maybe_get_constant_value): Move logic
9266 for getting an svalue from a CONSTRUCTOR node to...
9267 (decl_region::get_svalue_for_constructor): ...this new function.
9268 (decl_region::get_svalue_for_initializer): New.
9269 * store.cc (get_svalue_for_ctor_val): Rewrite in terms of
9270 region_model::get_rvalue.
9271 * store.h (binding_cluster::get_map): New accessor.
9273 2020-08-19 David Malcolm <dmalcolm@redhat.com>
9276 * region.cc (get_field_at_bit_offset): Gracefully handle negative
9277 values for bit_offset.
9279 2020-08-18 David Malcolm <dmalcolm@redhat.com>
9281 * region-model.cc (region_model::get_rvalue_1): Fix name of local.
9283 2020-08-18 David Malcolm <dmalcolm@redhat.com>
9286 * region-model.cc (region_model::get_rvalue_1): Handle
9287 unrecognized tree codes by returning "UNKNOWN.
9289 2020-08-18 David Malcolm <dmalcolm@redhat.com>
9292 * region-model.cc (region_model::get_gassign_result): Handle various
9293 VEC_* tree codes by returning UNKNOWN.
9294 (region_model::on_assignment): Handle unrecognized tree codes by
9295 setting lhs to an unknown value, rather than issuing a "sorry" and
9298 2020-08-17 David Malcolm <dmalcolm@redhat.com>
9301 * region-model-manager.cc (get_region_for_unexpected_tree_code):
9302 Handle ctxt being NULL.
9304 2020-08-17 David Malcolm <dmalcolm@redhat.com>
9307 * region.cc (region::get_subregions_for_binding): Check for "type"
9310 2020-08-17 David Malcolm <dmalcolm@redhat.com>
9313 * store.cc (get_svalue_for_ctor_val): New.
9314 (binding_map::apply_ctor_to_region): Call it.
9316 2020-08-14 David Malcolm <dmalcolm@redhat.com>
9320 * region-model.cc (region_model::get_store_value): Call
9321 maybe_get_constant_value on decl_regions first.
9322 * region-model.h (decl_region::maybe_get_constant_value): New decl.
9323 * region.cc (decl_region::get_stack_depth): Likewise.
9324 (decl_region::maybe_get_constant_value): New.
9325 * store.cc (get_subregion_within_ctor): New.
9326 (binding_map::apply_ctor_to_region): New.
9327 * store.h (binding_map::apply_ctor_to_region): New decl.
9329 2020-08-14 David Malcolm <dmalcolm@redhat.com>
9332 * store.cc (store::mark_as_escaped): Reject attempts to
9333 get a cluster for an unknown pointer.
9335 2020-08-13 David Malcolm <dmalcolm@redhat.com>
9351 * analyzer-logging.cc: Ignore "-Wformat-diag".
9352 (logger::enter_scope): Use inc_indent in both overloads.
9353 (logger::exit_scope): Use dec_indent.
9354 * analyzer-logging.h (logger::inc_indent): New.
9355 (logger::dec_indent): New.
9356 * analyzer-selftests.cc (run_analyzer_selftests): Call
9357 analyzer_store_cc_tests.
9358 * analyzer-selftests.h (analyzer_store_cc_tests): New decl.
9359 * analyzer.cc (get_stmt_location): New function.
9360 * analyzer.h (class initial_svalue): New forward decl.
9361 (class unaryop_svalue): New forward decl.
9362 (class binop_svalue): New forward decl.
9363 (class sub_svalue): New forward decl.
9364 (class unmergeable_svalue): New forward decl.
9365 (class placeholder_svalue): New forward decl.
9366 (class widening_svalue): New forward decl.
9367 (class compound_svalue): New forward decl.
9368 (class conjured_svalue): New forward decl.
9369 (svalue_set): New typedef.
9370 (class map_region): Delete.
9371 (class array_region): Delete.
9372 (class frame_region): New forward decl.
9373 (class function_region): New forward decl.
9374 (class label_region): New forward decl.
9375 (class decl_region): New forward decl.
9376 (class element_region): New forward decl.
9377 (class offset_region): New forward decl.
9378 (class cast_region): New forward decl.
9379 (class field_region): New forward decl.
9380 (class string_region): New forward decl.
9381 (class region_model_manager): New forward decl.
9382 (class store_manager): New forward decl.
9383 (class store): New forward decl.
9384 (class call_details): New forward decl.
9385 (struct svalue_id_merger_mapping): Delete.
9386 (struct canonicalization): Delete.
9387 (class function_point): New forward decl.
9388 (class engine): New forward decl.
9389 (dump_tree): New function decl.
9390 (print_quoted_type): New function decl.
9391 (readability_comparator): New function decl.
9392 (tree_cmp): New function decl.
9393 (class path_var): Move here from region-model.h
9394 (bit_offset_t, bit_size_t, byte_size_t): New typedefs.
9395 (class region_offset): New class.
9396 (get_stmt_location): New decl.
9397 (struct member_function_hash_traits): New struct.
9398 (class consolidation_map): New class.
9399 Ignore "-Wformat-diag".
9400 * analyzer.opt (-param=analyzer-max-svalue-depth=): New param.
9401 (-param=analyzer-max-enodes-for-full-dump=): New param.
9402 * call-string.cc: Ignore -Wformat-diag.
9403 * checker-path.cc: Move includes of "analyzer/call-string.h" and
9404 "analyzer/program-point.h" to before "analyzer/region-model.h",
9405 and also include "analyzer/store.h" before it.
9406 (state_change_event::state_change_event): Replace "tree var" param
9407 with "const svalue *sval". Convert "origin" param from tree to
9409 (state_change_event::get_desc): Call get_representative_tree to
9410 convert the var and origin from const svalue * to tree. Use
9411 svalue::get_desc rather than %qE when describing state changes.
9412 (checker_path::add_final_event): Use get_stmt_location.
9413 * checker-path.h (state_change_event::state_change_event): Port
9414 from tree to const svalue *.
9415 (state_change_event::get_lvalue): Delete.
9416 (state_change_event::get_dest_function): New.
9417 (state_change_event::m_var): Replace with...
9418 (state_change_event::m_sval): ...this.
9419 (state_change_event::m_origin): Convert from tree to
9421 * constraint-manager.cc: Include "analyzer/call-string.h",
9422 "analyzer/program-point.h", and "analyzer/store.h" before
9423 "analyzer/region-model.h".
9424 (struct bound, struct range): Move to constraint-manager.h.
9425 (compare_constants): New function.
9426 (range::dump): Rename to...
9427 (range::dump_to_pp): ...this. Support NULL constants.
9428 (range::dump): Reintroduce for dumping to stderr.
9429 (range::constrained_to_single_element): Return result, rather than
9431 (range::eval_condition): New.
9432 (range::below_lower_bound): New.
9433 (range::above_upper_bound): New.
9434 (equiv_class::equiv_class): Port from svalue_id to const svalue *.
9435 (equiv_class::print): Likewise.
9436 (equiv_class::hash): Likewise.
9437 (equiv_class::operator==): Port from svalue_id to const svalue *.
9438 (equiv_class::add): Port from svalue_id to const svalue *. Drop
9440 (equiv_class::del): Port from svalue_id to const svalue *.
9441 (equiv_class::get_representative): Likewise.
9442 (equiv_class::remap_svalue_ids): Delete.
9443 (svalue_id_cmp_by_id): Rename to...
9444 (svalue_cmp_by_ptr): ...this, porting from svalue_id to
9446 (equiv_class::canonicalize): Update qsort comparator.
9447 (constraint::implied_by): New.
9448 (constraint_manager::constraint_manager): Copy m_mgr in copy ctor.
9449 (constraint_manager::dump_to_pp): Add "multiline" param
9450 (constraint_manager::dump): Pass "true" for "multiline".
9451 (constraint_manager::add_constraint): Port from svalue_id to
9452 const svalue *. Split out second part into...
9453 (constraint_manager::add_unknown_constraint): ...this new
9454 function. Remove self-constraints when merging equivalence
9456 (constraint_manager::add_constraint_internal): Remove constraints
9457 that would be implied by the new constraint. Port from svalue_id
9459 (constraint_manager::get_equiv_class_by_sid): Rename to...
9460 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
9461 from svalue_id to const svalue *.
9462 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
9464 (constraint_manager::eval_condition): Make const. Call
9465 compare_constants and return early if it provides a known result.
9466 (constraint_manager::get_ec_bounds): New.
9467 (constraint_manager::eval_condition): New overloads. Make
9468 existing one const, and use compare_constants.
9469 (constraint_manager::purge): Convert "p" param to a template
9470 rather that an abstract base class. Port from svalue_id to
9472 (class dead_svalue_purger): New class.
9473 (constraint_manager::remap_svalue_ids): Delete.
9474 (constraint_manager::on_liveness_change): New.
9475 (equiv_class_cmp): Port from svalue_id to const svalue *.
9476 (constraint_manager::canonicalize): Likewise. Combine with
9477 purging of redundant equivalence classes and constraints.
9478 (class cleaned_constraint_manager): Delete.
9479 (class merger_fact_visitor): Make "m_cm_b" const. Add "m_merger"
9481 (merger_fact_visitor::fact): Port from svalue_id to const svalue *.
9482 Add special case for widening.
9483 (constraint_manager::merge): Port from svalue_id to const svalue *.
9484 (constraint_manager::clean_merger_input): Delete.
9485 (constraint_manager::for_each_fact): Port from svalue_id to
9487 (constraint_manager::validate): Likewise.
9488 (selftest::test_constraint_conditions): Provide a
9489 region_model_manager when creating region_model instances.
9490 Add test for self-equality not creating equivalence classes.
9491 (selftest::test_transitivity): Provide a region_model_manager when
9492 creating region_model instances. Verify that EC-merging happens
9493 when constraints are implied.
9494 (selftest::test_constant_comparisons): Provide a
9495 region_model_manager when creating region_model instances.
9496 (selftest::test_constraint_impl): Likewise. Remove over-specified
9498 (selftest::test_equality): Provide a region_model_manager when
9499 creating region_model instances.
9500 (selftest::test_many_constants): Likewise. Provide a
9501 program_point when testing merging.
9502 (selftest::run_constraint_manager_tests): Move call to
9503 test_constant_comparisons to outside the transitivity guard.
9504 * constraint-manager.h (struct bound): Move here from
9505 constraint-manager.cc.
9506 (struct range): Likewise.
9507 (struct::eval_condition): New decl.
9508 (struct::below_lower_bound): New decl.
9509 (struct::above_upper_bound): New decl.
9510 (equiv_class::add): Port from svalue_id to const svalue *.
9511 (equiv_class::del): Likewise.
9512 (equiv_class::get_representative): Likewise.
9513 (equiv_class::remap_svalue_ids): Drop.
9514 (equiv_class::m_cst_sid): Convert to..
9515 (equiv_class::m_cst_sval): ...this.
9516 (equiv_class::m_vars): Port from svalue_id to const svalue *.
9517 (constraint::bool implied_by): New decl.
9518 (fact_visitor::on_fact): Port from svalue_id to const svalue *.
9519 (constraint_manager::constraint_manager): Add mgr param.
9520 (constraint_manager::clone): Delete.
9521 (constraint_manager::maybe_get_constant): Delete.
9522 (constraint_manager::get_sid_for_constant): Delete.
9523 (constraint_manager::get_num_svalues): Delete.
9524 (constraint_manager::dump_to_pp): Add "multiline" param.
9525 (constraint_manager::get_equiv_class): Port from svalue_id to
9527 (constraint_manager::add_constraint): Likewise.
9528 (constraint_manager::get_equiv_class_by_sid): Rename to...
9529 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
9530 from svalue_id to const svalue *.
9531 (constraint_manager::add_unknown_constraint): New decl.
9532 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
9534 (constraint_manager::eval_condition): Likewise. Add overloads.
9535 (constraint_manager::get_ec_bounds): New decl.
9536 (constraint_manager::purge): Convert to template.
9537 (constraint_manager::remap_svalue_ids): Delete.
9538 (constraint_manager::on_liveness_change): New decl.
9539 (constraint_manager::canonicalize): Drop param.
9540 (constraint_manager::clean_merger_input): Delete.
9541 (constraint_manager::m_mgr): New field.
9542 * diagnostic-manager.cc: Move includes of
9543 "analyzer/call-string.h" and "analyzer/program-point.h" to before
9544 "analyzer/region-model.h", and also include "analyzer/store.h"
9546 (saved_diagnostic::saved_diagnostic): Add "sval" param.
9547 (diagnostic_manager::diagnostic_manager): Add engine param.
9548 (diagnostic_manager::add_diagnostic): Add "sval" param, passing it
9549 to saved_diagnostic ctor. Update overload to pass NULL for it.
9550 (dedupe_winners::dedupe_winners): Add engine param.
9551 (dedupe_winners::add): Add "eg" param. Pass m_engine to
9553 (dedupe_winner::m_engine): New field.
9554 (diagnostic_manager::emit_saved_diagnostics): Pass engine to
9555 dedupe_winners. Pass &eg when adding candidates. Pass svalue
9556 rather than tree to prune_path. Use get_stmt_location to get
9557 primary location of diagnostic.
9558 (diagnostic_manager::emit_saved_diagnostic): Likewise.
9559 (get_any_origin): Drop.
9560 (state_change_event_creator::on_global_state_change): Pass NULL
9561 const svalue * rather than NULL_TREE trees to state_change_event
9563 (state_change_event_creator::on_state_change): Port from tree and
9564 svalue_id to const svalue *.
9565 (for_each_state_change): Port from svalue_id to const svalue *.
9566 (struct null_assignment_sm_context): New.
9567 (diagnostic_manager::add_events_for_eedge): Add state change
9568 events for assignment to NULL.
9569 (diagnostic_manager::prune_path): Update param from tree to
9571 (diagnostic_manager::prune_for_sm_diagnostic): Port from tracking
9572 by tree to by const svalue *.
9573 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add sval
9575 (saved_diagnostic::m_sval): New field.
9576 (diagnostic_manager::diagnostic_manager): Add engine param.
9577 (diagnostic_manager::get_engine): New.
9578 (diagnostic_manager::add_diagnostic): Add "sval" param.
9579 (diagnostic_manager::prune_path): Likewise.
9580 (diagnostic_manager::prune_for_sm_diagnostic): New overload.
9581 (diagnostic_manager::m_eng): New field.
9582 * engine.cc: Move includes of "analyzer/call-string.h" and
9583 "analyzer/program-point.h" to before "analyzer/region-model.h",
9584 and also include "analyzer/store.h" before it.
9585 (impl_region_model_context::impl_region_model_context): Update for
9586 removal of m_change field.
9587 (impl_region_model_context::remap_svalue_ids): Delete.
9588 (impl_region_model_context::on_svalue_leak): New.
9589 (impl_region_model_context::on_svalue_purge): Delete.
9590 (impl_region_model_context::on_liveness_change): New.
9591 (impl_region_model_context::on_unknown_change): Update param
9592 from svalue_id to const svalue *. Add is_mutable param.
9593 (setjmp_svalue::compare_fields): Delete.
9594 (setjmp_svalue::accept): New.
9595 (setjmp_svalue::add_to_hash): Delete.
9596 (setjmp_svalue::dump_to_pp): New.
9597 (setjmp_svalue::print_details): Delete.
9598 (impl_sm_context::impl_sm_context): Drop "change" param.
9599 (impl_sm_context::get_fndecl_for_call): Drop "m_change".
9600 (impl_sm_context::on_transition): Drop ATTRIBUTE_UNUSED from
9601 "stmt" param. Drop m_change. Port from svalue_id to
9603 (impl_sm_context::warn_for_state): Drop m_change. Port from
9604 svalue_id to const svalue *.
9605 (impl_sm_context::get_readable_tree): Rename to...
9606 (impl_sm_context::get_diagnostic_tree): ...this. Port from
9607 svalue_id to const svalue *.
9608 (impl_sm_context::is_zero_assignment): New.
9609 (impl_sm_context::m_change): Delete field.
9610 (leak_stmt_finder::find_stmt): Handle m_var being NULL.
9611 (readability): Increase penalty for MEM_REF. For SSA_NAMEs,
9612 slightly favor the underlying var over the SSA name. Heavily
9613 penalize temporaries. Handle RESULT_DECL.
9614 (readability_comparator): Make non-static. Consider stack depths.
9615 (impl_region_model_context::on_state_leak): Convert from svalue_id
9616 to const svalue *, updating for region_model changes. Use
9618 (impl_region_model_context::on_inherited_svalue): Delete.
9619 (impl_region_model_context::on_cast): Delete.
9620 (impl_region_model_context::on_condition): Drop m_change.
9621 (impl_region_model_context::on_phi): Likewise.
9622 (impl_region_model_context::on_unexpected_tree_code): Handle t
9624 (point_and_state::validate): Update stack checking for
9625 region_model changes.
9626 (eg_traits::dump_args_t::show_enode_details_p): New.
9627 (exploded_node::exploded_node): Initialize m_num_processed_stmts.
9628 (exploded_node::get_processed_stmt): New function.
9629 (exploded_node::get_dot_fillcolor): Add more colors.
9630 (exploded_node::dump_dot): Guard the printing of the point and
9631 state with show_enode_details_p. Print the processed stmts for
9632 this enode after the initial state.
9633 (exploded_node::dump_to_pp): Pass true for new multiline param
9634 of program_state::dump_to_pp.
9635 (exploded_node::on_stmt): Drop "change" param. Log the stmt.
9636 Set input_location. Implement __analyzer_describe. Update
9637 implementation of __analyzer_dump and __analyzer_eval.
9638 Remove purging of sm-state for unknown fncalls from here.
9639 (exploded_node::on_edge): Drop "change" param.
9640 (exploded_node::on_longjmp): Port from region_id/svalue_id to
9641 const region */const svalue *. Call program_state::detect_leaks.
9643 (exploded_node::detect_leaks): Update for changes to region_model.
9644 Call program_state::detect_leaks.
9645 (exploded_edge::exploded_edge): Drop ext_state and change params.
9646 (exploded_edge::dump_dot): "args" is no longer used. Drop dumping
9648 (exploded_graph::exploded_graph): Pass engine to
9649 m_diagnostic_manager ctor. Use program_point::origin.
9650 (exploded_graph::add_function_entry): Drop ctxt. Use
9651 program_state::push_frame. Drop state_change.
9652 (exploded_graph::get_or_create_node): Drop "change" param. Add
9653 "enode_for_diag" param. Update dumping calls for API changes.
9654 Pass point to can_merge_with_p. Show enode indices
9655 within -Wanalyzer-too-complex diagnostic for hitting the per-point
9657 (exploded_graph::add_edge): Drop "change" param. Log which nodes
9658 are being connected. Update for changes to exploded_edge ctor.
9659 (exploded_graph::get_per_program_point_data): New.
9660 (exploded_graph::process_worklist): Pass point to
9661 can_merge_with_p. Drop state_change. Update dumping call for API
9663 (exploded_graph::process_node): Drop state_change. Split the
9664 node in-place if an sm-state-change occurs. Update
9665 m_num_processed_stmts. Update dumping calls for API change.
9666 (exploded_graph::log_stats): Call engine::log_stats.
9667 (exploded_graph::dump_states_for_supernode): Update dumping
9669 (exploded_path::feasible_p): Add "eng" and "eg" params.
9670 Rename "i" to "end_idx". Pass the manager to the region_model
9671 ctor. Update for every processed stmt in the enode, not just the
9672 first. Keep track of which snodes have been visited, and call
9673 loop_replay_fixup when revisiting one.
9674 (enode_label::get_text): Update dump call for new param.
9675 (exploded_graph::dump_exploded_nodes): Likewise.
9676 (exploded_graph::get_node_by_index): New.
9677 (impl_run_checkers): Create engine instance and pass its address
9678 to extrinsic_state ctor.
9680 (impl_region_model_context::impl_region_model_context): Drop
9682 (impl_region_model_context::void remap_svalue_ids): Delete.
9683 (impl_region_model_context::on_svalue_purge): Delete.
9684 (impl_region_model_context::on_svalue_leak): New.
9685 (impl_region_model_context::on_liveness_change): New.
9686 (impl_region_model_context::on_state_leak): Update signature.
9687 (impl_region_model_context::on_inherited_svalue): Delete.
9688 (impl_region_model_context::on_cast): Delete.
9689 (impl_region_model_context::on_unknown_change): Update signature.
9690 (impl_region_model_context::m_change): Delete.
9691 (eg_traits::dump_args_t::show_enode_details_p): New.
9692 (exploded_node::on_stmt): Drop "change" param.
9693 (exploded_node::on_edge): Likewise.
9694 (exploded_node::get_processed_stmt): New decl.
9695 (exploded_node::m_num_processed_stmts): New field.
9696 (exploded_edge::exploded_edge): Drop ext_state and change params.
9697 (exploded_edge::m_change): Delete.
9698 (exploded_graph::get_engine): New accessor.
9699 (exploded_graph::get_or_create_node): Drop "change" param. Add
9700 "enode_for_diag" param.
9701 (exploded_graph::add_edge): Drop "change" param.
9702 (exploded_graph::get_per_program_point_data): New decl.
9703 (exploded_graph::get_node_by_index): New decl.
9704 (exploded_path::feasible_p): Add "eng" and "eg" params.
9705 * program-point.cc: Include "analyzer/store.h" before including
9706 "analyzer/region-model.h".
9707 (function_point::function_point): Move here from
9709 (function_point::get_function): Likewise.
9710 (function_point::from_function_entry): Likewise.
9711 (function_point::before_supernode): Likewise.
9712 (function_point::next_stmt): New function.
9713 * program-point.h (function_point::function_point): Move
9714 implementation from here to program-point.cc.
9715 (function_point::get_function): Likewise.
9716 (function_point::from_function_entry): Likewise.
9717 (function_point::before_supernode): Likewise.
9718 (function_point::next_stmt): New decl.
9719 (program_point::operator!=): New.
9720 (program_point::origin): New.
9721 (program_point::next_stmt): New.
9722 (program_point::m_function_point): Make non-const.
9723 * program-state.cc: Move includes of "analyzer/call-string.h" and
9724 "analyzer/program-point.h" to before "analyzer/region-model.h",
9725 and also include "analyzer/store.h" before it.
9726 (extrinsic_state::get_model_manager): New.
9727 (sm_state_map::sm_state_map): Pass in sm and sm_idx to ctor,
9728 rather than pass the around.
9729 (sm_state_map::clone_with_remapping): Delete.
9730 (sm_state_map::print): Remove "sm" param in favor of "m_sm". Add
9731 "simple" and "multiline" params and support multiline vs single
9733 (sm_state_map::dump): Remove "sm" param in favor of "m_sm". Add
9735 (sm_state_map::hash): Port from svalue_id to const svalue *.
9736 (sm_state_map::operator==): Likewise.
9737 (sm_state_map::get_state): Likewise. Call canonicalize_svalue on
9738 input. Handle inheritance of sm-state. Call get_default_state.
9739 (sm_state_map::get_origin): Port from svalue_id to const svalue *.
9740 (sm_state_map::set_state): Likewise. Pass in ext_state. Reject
9741 attempts to set state on UNKNOWN.
9742 (sm_state_map::impl_set_state): Port from svalue_id to
9743 const svalue *. Pass in ext_state. Call canonicalize_svalue on
9745 (sm_state_map::purge_for_unknown_fncall): Delete.
9746 (sm_state_map::on_svalue_leak): New.
9747 (sm_state_map::remap_svalue_ids): Delete.
9748 (sm_state_map::on_liveness_change): New.
9749 (sm_state_map::on_unknown_change): Reimplement.
9750 (sm_state_map::on_svalue_purge): Delete.
9751 (sm_state_map::on_inherited_svalue): Delete.
9752 (sm_state_map::on_cast): Delete.
9753 (sm_state_map::validate): Delete.
9754 (sm_state_map::canonicalize_svalue): New.
9755 (program_state::program_state): Update to pass manager to
9756 region_model's ctor. Constify num_states and pass state machine
9757 and index to sm_state_map ctor.
9758 (program_state::print): Update for changes to dump API.
9759 (program_state::dump_to_pp): Ignore the summarize param. Add
9761 (program_state::dump_to_file): Add "multiline" param.
9762 (program_state::dump): Pass "true" for new "multiline" param.
9763 (program_state::push_frame): New.
9764 (program_state::on_edge): Drop "change" param. Call
9765 program_state::detect_leaks.
9766 (program_state::prune_for_point): Add enode_for_diag param.
9767 Reimplement based on store class. Call detect_leaks
9768 (program_state::remap_svalue_ids): Delete.
9769 (program_state::get_representative_tree): Port from svalue_id to
9771 (program_state::can_merge_with_p): Add "point" param. Add early
9772 reject for sm-differences. Drop id remapping.
9773 (program_state::validate): Drop region model and sm_state_map
9775 (state_change::sm_change::dump): Delete.
9776 (state_change::sm_change::remap_svalue_ids): Delete.
9777 (state_change::sm_change::on_svalue_purge): Delete.
9778 (log_set_of_svalues): New.
9779 (state_change::sm_change::validate): Delete.
9780 (state_change::state_change): Delete.
9781 (state_change::add_sm_change): Delete.
9782 (state_change::affects_p): Delete.
9783 (state_change::dump): Delete.
9784 (state_change::remap_svalue_ids): Delete.
9785 (state_change::on_svalue_purge): Delete.
9786 (state_change::validate): Delete.
9787 (selftest::assert_dump_eq): Delete.
9788 (ASSERT_DUMP_EQ): Delete.
9789 (selftest::test_sm_state_map): Update for changes to region_model
9790 and sm_state_map, porting from svalue_id to const svalue *.
9791 (selftest::test_program_state_dumping): Likewise. Drop test of
9792 dumping, renaming to...
9793 (selftest::test_program_state_1): ...this.
9794 (selftest::test_program_state_dumping_2): Likewise, renaming to...
9795 (selftest::test_program_state_2): ...this.
9796 (selftest::test_program_state_merging): Update for changes to
9798 (selftest::test_program_state_merging_2): Likewise.
9799 (selftest::analyzer_program_state_cc_tests): Update for renamed
9801 * program-state.h (extrinsic_state::extrinsic_state): Add logger
9803 (extrinsic_state::get_logger): New accessor.
9804 (extrinsic_state::get_engine): New accessor.
9805 (extrinsic_state::get_model_manager): New accessor.
9806 (extrinsic_state::m_logger): New field.
9807 (extrinsic_state::m_engine): New field.
9808 (struct default_hash_traits<svalue_id>): Delete.
9809 (pod_hash_traits<svalue_id>::hash): Delete.
9810 (pod_hash_traits<svalue_id>::equal): Delete.
9811 (pod_hash_traits<svalue_id>::mark_deleted): Delete.
9812 (pod_hash_traits<svalue_id>::mark_empty): Delete.
9813 (pod_hash_traits<svalue_id>::is_deleted): Delete.
9814 (pod_hash_traits<svalue_id>::is_empty): Delete.
9815 (sm_state_map::entry_t::entry_t): Port from svalue_id to
9817 (sm_state_map::entry_t::m_origin): Likewise.
9818 (sm_state_map::map_t): Likewise.
9819 (sm_state_map::sm_state_map): Add state_machine and index params.
9820 (sm_state_map::clone_with_remapping): Delete.
9821 (sm_state_map::print): Drop sm param; add simple and multiline
9823 (sm_state_map::dump): Drop sm param; add simple param.
9824 (sm_state_map::get_state): Port from svalue_id to const svalue *.
9825 Add ext_state param.
9826 (sm_state_map::get_origin): Likewise.
9827 (sm_state_map::set_state): Likewise.
9828 (sm_state_map::impl_set_state): Likewise.
9829 (sm_state_map::purge_for_unknown_fncall): Delete.
9830 (sm_state_map::remap_svalue_ids): Delete.
9831 (sm_state_map::on_svalue_purge): Delete.
9832 (sm_state_map::on_svalue_leak): New.
9833 (sm_state_map::on_liveness_change): New.
9834 (sm_state_map::on_inherited_svalue): Delete.
9835 (sm_state_map::on_cast): Delete.
9836 (sm_state_map::validate): Delete.
9837 (sm_state_map::on_unknown_change): Port from svalue_id to
9838 const svalue *. Add is_mutable and ext_state params.
9839 (sm_state_map::canonicalize_svalue): New.
9840 (sm_state_map::m_sm): New field.
9841 (sm_state_map::m_sm_idx): New field.
9842 (program_state::operator=): Delete.
9843 (program_state::dump_to_pp): Drop "summarize" param, adding
9844 "simple" and "multiline".
9845 (program_state::dump_to_file): Likewise.
9846 (program_state::dump): Rename "summarize" to "simple".
9847 (program_state::push_frame): New.
9848 (program_state::get_current_function): New.
9849 (program_state::on_edge): Drop "change" param.
9850 (program_state::prune_for_point): Likewise. Add enode_for_diag
9852 (program_state::remap_svalue_ids): Delete.
9853 (program_state::get_representative_tree): Port from svalue_id to
9855 (program_state::can_purge_p): Likewise. Pass ext_state to get_state.
9856 (program_state::can_merge_with_p): Add point param.
9857 (program_state::detect_leaks): New.
9858 (state_change_visitor::on_state_change): Port from tree and
9859 svalue_id to a pair of const svalue *.
9860 (class state_change): Delete.
9861 * region.cc: New file.
9862 * region-model-impl-calls.cc: New file.
9863 * region-model-manager.cc: New file.
9864 * region-model-reachability.cc: New file.
9865 * region-model-reachability.h: New file.
9866 * region-model.cc: Include "analyzer/call-string.h",
9867 "analyzer/program-point.h", and "analyzer/store.h" before
9868 "analyzer/region-model.h". Include
9869 "analyzer/region-model-reachability.h".
9870 (dump_tree): Make non-static.
9871 (dump_quoted_tree): Make non-static.
9872 (print_quoted_type): Make non-static.
9873 (path_var::dump): Delete.
9874 (dump_separator): Delete.
9875 (class impl_constraint_manager): Delete.
9876 (svalue_id::print): Delete.
9877 (svalue_id::dump_node_name_to_pp): Delete.
9878 (svalue_id::validate): Delete.
9879 (region_id::print): Delete.
9880 (region_id::dump_node_name_to_pp): Delete.
9881 (region_id::validate): Delete.
9882 (region_id_set::region_id_set): Delete.
9883 (svalue_id_set::svalue_id_set): Delete.
9884 (svalue::operator==): Delete.
9885 (svalue::hash): Delete.
9886 (svalue::print): Delete.
9887 (svalue::dump_dot_to_pp): Delete.
9888 (svalue::remap_region_ids): Delete.
9889 (svalue::walk_for_canonicalization): Delete.
9890 (svalue::get_child_sid): Delete.
9891 (svalue::maybe_get_constant): Delete.
9892 (region_svalue::compare_fields): Delete.
9893 (region_svalue::add_to_hash): Delete.
9894 (region_svalue::print_details): Delete.
9895 (region_svalue::dump_dot_to_pp): Delete.
9896 (region_svalue::remap_region_ids): Delete.
9897 (region_svalue::merge_values): Delete.
9898 (region_svalue::walk_for_canonicalization): Delete.
9899 (region_svalue::eval_condition): Delete.
9900 (constant_svalue::compare_fields): Delete.
9901 (constant_svalue::add_to_hash): Delete.
9902 (constant_svalue::merge_values): Delete.
9903 (constant_svalue::eval_condition): Move to svalue.cc.
9904 (constant_svalue::print_details): Delete.
9905 (constant_svalue::get_child_sid): Delete.
9906 (unknown_svalue::compare_fields): Delete.
9907 (unknown_svalue::add_to_hash): Delete.
9908 (unknown_svalue::print_details): Delete.
9909 (poison_kind_to_str): Move to svalue.cc.
9910 (poisoned_svalue::compare_fields): Delete.
9911 (poisoned_svalue::add_to_hash): Delete.
9912 (poisoned_svalue::print_details): Delete.
9913 (region_kind_to_str): Move to region.cc and reimplement.
9914 (region::operator==): Delete.
9915 (region::get_parent_region): Delete.
9916 (region::set_value): Delete.
9917 (region::become_active_view): Delete.
9918 (region::deactivate_any_active_view): Delete.
9919 (region::deactivate_view): Delete.
9920 (region::get_value): Delete.
9921 (region::get_inherited_child_sid): Delete.
9922 (region_model::copy_region): Delete.
9923 (region_model::copy_struct_region): Delete.
9924 (region_model::copy_union_region): Delete.
9925 (region_model::copy_array_region): Delete.
9926 (region::hash): Delete.
9927 (region::print): Delete.
9928 (region::dump_dot_to_pp): Delete.
9929 (region::dump_to_pp): Delete.
9930 (region::dump_child_label): Delete.
9931 (region::validate): Delete.
9932 (region::remap_svalue_ids): Delete.
9933 (region::remap_region_ids): Delete.
9934 (region::add_view): Delete.
9935 (region::get_view): Delete.
9936 (region::region): Move to region.cc.
9937 (region::add_to_hash): Delete.
9938 (region::print_fields): Delete.
9939 (region::non_null_p): Delete.
9940 (primitive_region::clone): Delete.
9941 (primitive_region::walk_for_canonicalization): Delete.
9942 (map_region::map_region): Delete.
9943 (map_region::compare_fields): Delete.
9944 (map_region::print_fields): Delete.
9945 (map_region::validate): Delete.
9946 (map_region::dump_dot_to_pp): Delete.
9947 (map_region::dump_child_label): Delete.
9948 (map_region::get_or_create): Delete.
9949 (map_region::get): Delete.
9950 (map_region::add_to_hash): Delete.
9951 (map_region::remap_region_ids): Delete.
9952 (map_region::unbind): Delete.
9953 (map_region::get_tree_for_child_region): Delete.
9954 (map_region::get_tree_for_child_region): Delete.
9955 (tree_cmp): Move to region.cc.
9956 (map_region::can_merge_p): Delete.
9957 (map_region::walk_for_canonicalization): Delete.
9958 (map_region::get_value_by_name): Delete.
9959 (struct_or_union_region::valid_key_p): Delete.
9960 (struct_or_union_region::compare_fields): Delete.
9961 (struct_region::clone): Delete.
9962 (struct_region::compare_fields): Delete.
9963 (union_region::clone): Delete.
9964 (union_region::compare_fields): Delete.
9965 (frame_region::compare_fields): Delete.
9966 (frame_region::clone): Delete.
9967 (frame_region::valid_key_p): Delete.
9968 (frame_region::print_fields): Delete.
9969 (frame_region::add_to_hash): Delete.
9970 (globals_region::compare_fields): Delete.
9971 (globals_region::clone): Delete.
9972 (globals_region::valid_key_p): Delete.
9973 (code_region::compare_fields): Delete.
9974 (code_region::clone): Delete.
9975 (code_region::valid_key_p): Delete.
9976 (array_region::array_region): Delete.
9977 (array_region::get_element): Delete.
9978 (array_region::clone): Delete.
9979 (array_region::compare_fields): Delete.
9980 (array_region::print_fields): Delete.
9981 (array_region::validate): Delete.
9982 (array_region::dump_dot_to_pp): Delete.
9983 (array_region::dump_child_label): Delete.
9984 (array_region::get_or_create): Delete.
9985 (array_region::get): Delete.
9986 (array_region::add_to_hash): Delete.
9987 (array_region::remap_region_ids): Delete.
9988 (array_region::get_key_for_child_region): Delete.
9989 (array_region::key_cmp): Delete.
9990 (array_region::walk_for_canonicalization): Delete.
9991 (array_region::key_from_constant): Delete.
9992 (array_region::constant_from_key): Delete.
9993 (function_region::compare_fields): Delete.
9994 (function_region::clone): Delete.
9995 (function_region::valid_key_p): Delete.
9996 (stack_region::stack_region): Delete.
9997 (stack_region::compare_fields): Delete.
9998 (stack_region::clone): Delete.
9999 (stack_region::print_fields): Delete.
10000 (stack_region::dump_child_label): Delete.
10001 (stack_region::validate): Delete.
10002 (stack_region::push_frame): Delete.
10003 (stack_region::get_current_frame_id): Delete.
10004 (stack_region::pop_frame): Delete.
10005 (stack_region::add_to_hash): Delete.
10006 (stack_region::remap_region_ids): Delete.
10007 (stack_region::can_merge_p): Delete.
10008 (stack_region::walk_for_canonicalization): Delete.
10009 (stack_region::get_value_by_name): Delete.
10010 (heap_region::heap_region): Delete.
10011 (heap_region::compare_fields): Delete.
10012 (heap_region::clone): Delete.
10013 (heap_region::walk_for_canonicalization): Delete.
10014 (root_region::root_region): Delete.
10015 (root_region::compare_fields): Delete.
10016 (root_region::clone): Delete.
10017 (root_region::print_fields): Delete.
10018 (root_region::validate): Delete.
10019 (root_region::dump_child_label): Delete.
10020 (root_region::push_frame): Delete.
10021 (root_region::get_current_frame_id): Delete.
10022 (root_region::pop_frame): Delete.
10023 (root_region::ensure_stack_region): Delete.
10024 (root_region::get_stack_region): Delete.
10025 (root_region::ensure_globals_region): Delete.
10026 (root_region::get_code_region): Delete.
10027 (root_region::ensure_code_region): Delete.
10028 (root_region::get_globals_region): Delete.
10029 (root_region::ensure_heap_region): Delete.
10030 (root_region::get_heap_region): Delete.
10031 (root_region::remap_region_ids): Delete.
10032 (root_region::can_merge_p): Delete.
10033 (root_region::add_to_hash): Delete.
10034 (root_region::walk_for_canonicalization): Delete.
10035 (root_region::get_value_by_name): Delete.
10036 (symbolic_region::symbolic_region): Delete.
10037 (symbolic_region::compare_fields): Delete.
10038 (symbolic_region::clone): Delete.
10039 (symbolic_region::walk_for_canonicalization): Delete.
10040 (symbolic_region::print_fields): Delete.
10041 (region_model::region_model): Add region_model_manager * param.
10042 Reimplement in terms of store, dropping impl_constraint_manager
10044 (region_model::operator=): Reimplement in terms of store
10045 (region_model::operator==): Likewise.
10046 (region_model::hash): Likewise.
10047 (region_model::print): Delete.
10048 (region_model::print_svalue): Delete.
10049 (region_model::dump_dot_to_pp): Delete.
10050 (region_model::dump_dot_to_file): Delete.
10051 (region_model::dump_dot): Delete.
10052 (region_model::dump_to_pp): Replace "summarize" param with
10053 "simple" and "multiline". Port to store-based implementation.
10054 (region_model::dump): Replace "summarize" param with "simple" and
10056 (dump_vec_of_tree): Delete.
10057 (region_model::dump_summary_of_rep_path_vars): Delete.
10058 (region_model::validate): Delete.
10059 (svalue_id_cmp_by_constant_svalue_model): Delete.
10060 (svalue_id_cmp_by_constant_svalue): Delete.
10061 (region_model::canonicalize): Drop "ctxt" param. Reimplement in
10062 terms of store and constraints.
10063 (region_model::canonicalized_p): Remove NULL arg to canonicalize.
10064 (region_model::loop_replay_fixup): New.
10065 (poisoned_value_diagnostic::emit): Tweak wording of warnings.
10066 (region_model::check_for_poison): Delete.
10067 (region_model::get_gassign_result): New.
10068 (region_model::on_assignment): Port to store-based implementation.
10069 (region_model::on_call_pre): Delete calls to check_for_poison.
10070 Move implementations to region-model-impl-calls.c and port to
10071 store-based implementation.
10072 (region_model::on_call_post): Likewise.
10073 (class reachable_regions): Move to region-model-reachability.h/cc
10074 and port to store-based implementation.
10075 (region_model::handle_unrecognized_call): Port to store-based
10077 (region_model::get_reachable_svalues): New.
10078 (region_model::on_setjmp): Port to store-based implementation.
10079 (region_model::on_longjmp): Likewise.
10080 (region_model::handle_phi): Drop is_back_edge param and the logic
10082 (region_model::get_lvalue_1): Port from region_id to const region *.
10083 (region_model::make_region_for_unexpected_tree_code): Delete.
10084 (assert_compat_types): If the check fails, use internal_error to
10086 (region_model::get_lvalue): Port from region_id to const region *.
10087 (region_model::get_rvalue_1): Port from svalue_id to const svalue *.
10088 (region_model::get_rvalue): Likewise.
10089 (region_model::get_or_create_ptr_svalue): Delete.
10090 (region_model::get_or_create_constant_svalue): Delete.
10091 (region_model::get_svalue_for_fndecl): Delete.
10092 (region_model::get_region_for_fndecl): Delete.
10093 (region_model::get_svalue_for_label): Delete.
10094 (region_model::get_region_for_label): Delete.
10095 (build_cast): Delete.
10096 (region_model::maybe_cast_1): Delete.
10097 (region_model::maybe_cast): Delete.
10098 (region_model::get_field_region): Delete.
10099 (region_model::get_store_value): New.
10100 (region_model::region_exists_p): New.
10101 (region_model::deref_rvalue): Port from svalue_id to const svalue *.
10102 (region_model::set_value): Likewise.
10103 (region_model::clobber_region): New.
10104 (region_model::purge_region): New.
10105 (region_model::zero_fill_region): New.
10106 (region_model::mark_region_as_unknown): New.
10107 (region_model::eval_condition): Port from svalue_id to
10109 (region_model::eval_condition_without_cm): Likewise.
10110 (region_model::compare_initial_and_pointer): New.
10111 (region_model::add_constraint): Port from svalue_id to
10113 (region_model::maybe_get_constant): Delete.
10114 (region_model::get_representative_path_var): New.
10115 (region_model::add_new_malloc_region): Delete.
10116 (region_model::get_representative_tree): Port to const svalue *.
10117 (region_model::get_representative_path_var): Port to
10119 (region_model::get_path_vars_for_svalue): Delete.
10120 (region_model::set_to_new_unknown_value): Delete.
10121 (region_model::update_for_phis): Don't pass is_back_edge to handle_phi.
10122 (region_model::update_for_call_superedge): Port from svalue_id to
10124 (region_model::update_for_return_superedge): Port to store-based
10126 (region_model::update_for_call_summary): Replace
10127 set_to_new_unknown_value with mark_region_as_unknown.
10128 (region_model::get_root_region): Delete.
10129 (region_model::get_stack_region_id): Delete.
10130 (region_model::push_frame): Delete.
10131 (region_model::get_current_frame_id): Delete.
10132 (region_model::get_current_function): Delete.
10133 (region_model::pop_frame): Delete.
10134 (region_model::on_top_level_param): New.
10135 (region_model::get_stack_depth): Delete.
10136 (region_model::get_function_at_depth): Delete.
10137 (region_model::get_globals_region_id): Delete.
10138 (region_model::add_svalue): Delete.
10139 (region_model::replace_svalue): Delete.
10140 (region_model::add_region): Delete.
10141 (region_model::get_svalue): Delete.
10142 (region_model::get_region): Delete.
10143 (make_region_for_type): Delete.
10144 (region_model::add_region_for_type): Delete.
10145 (region_model::on_top_level_param): New.
10146 (class restrict_to_used_svalues): Delete.
10147 (region_model::purge_unused_svalues): Delete.
10148 (region_model::push_frame): New.
10149 (region_model::remap_svalue_ids): Delete.
10150 (region_model::remap_region_ids): Delete.
10151 (region_model::purge_regions): Delete.
10152 (region_model::get_descendents): Delete.
10153 (region_model::delete_region_and_descendents): Delete.
10154 (region_model::poison_any_pointers_to_bad_regions): Delete.
10155 (region_model::can_merge_with_p): Delete.
10156 (region_model::get_current_function): New.
10157 (region_model::get_value_by_name): Delete.
10158 (region_model::convert_byte_offset_to_array_index): Delete.
10159 (region_model::pop_frame): New.
10160 (region_model::get_or_create_mem_ref): Delete.
10161 (region_model::get_stack_depth): New.
10162 (region_model::get_frame_at_index): New.
10163 (region_model::unbind_region_and_descendents): New.
10164 (struct bad_pointer_finder): New.
10165 (region_model::get_or_create_pointer_plus_expr): Delete.
10166 (region_model::poison_any_pointers_to_descendents): New.
10167 (region_model::get_or_create_view): Delete.
10168 (region_model::can_merge_with_p): New.
10169 (region_model::get_fndecl_for_call): Port from svalue_id to
10171 (struct append_ssa_names_cb_data): New.
10172 (get_ssa_name_regions_for_current_frame): New.
10173 (region_model::append_ssa_names_cb): New.
10174 (model_merger::dump_to_pp): Add "simple" param. Drop dumping of
10176 (model_merger::dump): Add "simple" param to both overloads.
10177 (model_merger::can_merge_values_p): Delete.
10178 (model_merger::record_regions): Delete.
10179 (model_merger::record_svalues): Delete.
10180 (svalue_id_merger_mapping::svalue_id_merger_mapping): Delete.
10181 (svalue_id_merger_mapping::dump_to_pp): Delete.
10182 (svalue_id_merger_mapping::dump): Delete.
10183 (region_model::create_region_for_heap_alloc): New.
10184 (region_model::create_region_for_alloca): New.
10185 (region_model::record_dynamic_extents): New.
10186 (canonicalization::canonicalization): Delete.
10187 (canonicalization::walk_rid): Delete.
10188 (canonicalization::walk_sid): Delete.
10189 (canonicalization::dump_to_pp): Delete.
10190 (canonicalization::dump): Delete.
10191 (inchash::add): Delete overloads for svalue_id and region_id.
10192 (engine::log_stats): New.
10193 (assert_condition): Add overload comparing svalues.
10194 (assert_dump_eq): Pass "true" for multiline.
10195 (selftest::test_dump): Update for rewrite of region_model.
10196 (selftest::test_dump_2): Rename to...
10197 (selftest::test_struct): ...this. Provide a region_model_manager
10198 when creating region_model instance. Remove dump test. Add
10199 checks for get_offset.
10200 (selftest::test_dump_3): Rename to...
10201 (selftest::test_array_1): ...this. Provide a region_model_manager
10202 when creating region_model instance. Remove dump test.
10203 (selftest::test_get_representative_tree): Port from svalue_id to
10204 new API. Add test coverage for various expressions.
10205 (selftest::test_unique_constants): Provide a region_model_manager
10206 for the region_model. Add test coverage for comparing const vs
10208 (selftest::test_svalue_equality): Delete.
10209 (selftest::test_region_equality): Delete.
10210 (selftest::test_unique_unknowns): New.
10211 (class purge_all_svalue_ids): Delete.
10212 (class purge_one_svalue_id): Delete.
10213 (selftest::test_purging_by_criteria): Delete.
10214 (selftest::test_initial_svalue_folding): New.
10215 (selftest::test_unaryop_svalue_folding): New.
10216 (selftest::test_binop_svalue_folding): New.
10217 (selftest::test_sub_svalue_folding): New.
10218 (selftest::test_purge_unused_svalues): Delete.
10219 (selftest::test_descendent_of_p): New.
10220 (selftest::test_assignment): Provide a region_model_manager for
10221 the region_model. Drop the dump test.
10222 (selftest::test_compound_assignment): Likewise.
10223 (selftest::test_stack_frames): Port to new implementation.
10224 (selftest::test_get_representative_path_var): Likewise.
10225 (selftest::test_canonicalization_1): Rename to...
10226 (selftest::test_equality_1): ...this. Port to new API, and add
10227 (selftest::test_canonicalization_2): Provide a
10228 region_model_manager when creating region_model instances.
10229 Remove redundant canicalization.
10230 (selftest::test_canonicalization_3): Provide a
10231 region_model_manager when creating region_model instances.
10232 Remove param from calls to region_model::canonicalize.
10233 (selftest::test_canonicalization_4): Likewise.
10234 (selftest::assert_region_models_merge): Constify
10235 out_merged_svalue. Port to new API.
10236 (selftest::test_state_merging): Provide a
10237 region_model_manager when creating region_model instances.
10238 Provide a program_point point when merging them. Replace
10239 set_to_new_unknown_value with usage of placeholder_svalues.
10240 Drop get_value_by_name. Port from svalue_id to const svalue *.
10241 Add test of heap allocation.
10242 (selftest::test_constraint_merging): Provide a
10243 region_model_manager when creating region_model instances.
10244 Provide a program_point point when merging them. Eliminate use
10245 of set_to_new_unknown_value.
10246 (selftest::test_widening_constraints): New.
10247 (selftest::test_iteration_1): New.
10248 (selftest::test_malloc_constraints): Port to store-based
10250 (selftest::test_var): New test.
10251 (selftest::test_array_2): New test.
10252 (selftest::test_mem_ref): New test.
10253 (selftest::test_POINTER_PLUS_EXPR_then_MEM_REF): New.
10254 (selftest::test_malloc): New.
10255 (selftest::test_alloca): New.
10256 (selftest::analyzer_region_model_cc_tests): Update for renamings.
10257 Call new functions.
10258 * region-model.h (class path_var): Move to analyzer.h.
10259 (class svalue_id): Delete.
10260 (class region_id): Delete.
10261 (class id_map): Delete.
10262 (svalue_id_map): Delete.
10263 (region_id_map): Delete.
10264 (id_map<T>::id_map): Delete.
10265 (id_map<T>::put): Delete.
10266 (id_map<T>::get_dst_for_src): Delete.
10267 (id_map<T>::get_src_for_dst): Delete.
10268 (id_map<T>::dump_to_pp): Delete.
10269 (id_map<T>::dump): Delete.
10270 (id_map<T>::update): Delete.
10271 (one_way_svalue_id_map): Delete.
10272 (one_way_region_id_map): Delete.
10273 (class region_id_set): Delete.
10274 (class svalue_id_set): Delete.
10275 (struct complexity): New.
10276 (class visitor): New.
10277 (enum svalue_kind): Add SK_SETJMP, SK_INITIAL, SK_UNARYOP,
10278 SK_BINOP, SK_SUB,SK_UNMERGEABLE, SK_PLACEHOLDER, SK_WIDENING,
10279 SK_COMPOUND, and SK_CONJURED.
10280 (svalue::operator==): Delete.
10281 (svalue::operator!=): Delete.
10282 (svalue::clone): Delete.
10283 (svalue::hash): Delete.
10284 (svalue::dump_dot_to_pp): Delete.
10285 (svalue::dump_to_pp): New.
10286 (svalue::dump): New.
10287 (svalue::get_desc): New.
10288 (svalue::dyn_cast_initial_svalue): New.
10289 (svalue::dyn_cast_unaryop_svalue): New.
10290 (svalue::dyn_cast_binop_svalue): New.
10291 (svalue::dyn_cast_sub_svalue): New.
10292 (svalue::dyn_cast_unmergeable_svalue): New.
10293 (svalue::dyn_cast_widening_svalue): New.
10294 (svalue::dyn_cast_compound_svalue): New.
10295 (svalue::dyn_cast_conjured_svalue): New.
10296 (svalue::maybe_undo_cast): New.
10297 (svalue::unwrap_any_unmergeable): New.
10298 (svalue::remap_region_ids): Delete
10299 (svalue::can_merge_p): New.
10300 (svalue::walk_for_canonicalization): Delete
10301 (svalue::get_complexity): New.
10302 (svalue::get_child_sid): Delete
10303 (svalue::accept): New.
10304 (svalue::live_p): New.
10305 (svalue::implicitly_live_p): New.
10306 (svalue::svalue): Add complexity param.
10307 (svalue::add_to_hash): Delete
10308 (svalue::print_details): Delete
10309 (svalue::m_complexity): New field.
10310 (region_svalue::key_t): New struct.
10311 (region_svalue::region_svalue): Port from region_id to
10312 const region_id *. Add complexity.
10313 (region_svalue::compare_fields): Delete.
10314 (region_svalue::clone): Delete.
10315 (region_svalue::dump_dot_to_pp): Delete.
10316 (region_svalue::get_pointee): Port from region_id to
10318 (region_svalue::remap_region_ids): Delete.
10319 (region_svalue::merge_values): Delete.
10320 (region_svalue::dump_to_pp): New.
10321 (region_svalue::accept): New.
10322 (region_svalue::walk_for_canonicalization): Delete.
10323 (region_svalue::eval_condition): Make params const.
10324 (region_svalue::add_to_hash): Delete.
10325 (region_svalue::print_details): Delete.
10326 (region_svalue::m_rid): Replace with...
10327 (region_svalue::m_reg): ...this.
10328 (is_a_helper <region_svalue *>::test): Convert to...
10329 (is_a_helper <const region_svalue *>::test): ...this.
10330 (template <> struct default_hash_traits<region_svalue::key_t>):
10332 (constant_svalue::constant_svalue): Add complexity.
10333 (constant_svalue::compare_fields): Delete.
10334 (constant_svalue::clone): Delete.
10335 (constant_svalue::add_to_hash): Delete.
10336 (constant_svalue::dump_to_pp): New.
10337 (constant_svalue::accept): New.
10338 (constant_svalue::implicitly_live_p): New.
10339 (constant_svalue::merge_values): Delete.
10340 (constant_svalue::eval_condition): Make params const.
10341 (constant_svalue::get_child_sid): Delete.
10342 (constant_svalue::print_details): Delete.
10343 (is_a_helper <constant_svalue *>::test): Convert to...
10344 (is_a_helper <const constant_svalue *>::test): ...this.
10345 (class unknown_svalue): Update leading comment.
10346 (unknown_svalue::unknown_svalue): Add complexity.
10347 (unknown_svalue::compare_fields): Delete.
10348 (unknown_svalue::add_to_hash): Delete.
10349 (unknown_svalue::dyn_cast_unknown_svalue): Delete.
10350 (unknown_svalue::print_details): Delete.
10351 (unknown_svalue::dump_to_pp): New.
10352 (unknown_svalue::accept): New.
10353 (poisoned_svalue::key_t): New struct.
10354 (poisoned_svalue::poisoned_svalue): Add complexity.
10355 (poisoned_svalue::compare_fields): Delete.
10356 (poisoned_svalue::clone): Delete.
10357 (poisoned_svalue::add_to_hash): Delete.
10358 (poisoned_svalue::dump_to_pp): New.
10359 (poisoned_svalue::accept): New.
10360 (poisoned_svalue::print_details): Delete.
10361 (is_a_helper <poisoned_svalue *>::test): Convert to...
10362 (is_a_helper <const poisoned_svalue *>::test): ...this.
10363 (template <> struct default_hash_traits<poisoned_svalue::key_t>):
10365 (setjmp_record::add_to_hash): New.
10366 (setjmp_svalue::key_t): New struct.
10367 (setjmp_svalue::compare_fields): Delete.
10368 (setjmp_svalue::clone): Delete.
10369 (setjmp_svalue::add_to_hash): Delete.
10370 (setjmp_svalue::setjmp_svalue): Add complexity.
10371 (setjmp_svalue::dump_to_pp): New.
10372 (setjmp_svalue::accept): New.
10373 (setjmp_svalue::void print_details): Delete.
10374 (is_a_helper <const setjmp_svalue *>::test): New.
10375 (template <> struct default_hash_traits<setjmp_svalue::key_t>): New.
10376 (class initial_svalue : public svalue): New.
10377 (is_a_helper <const initial_svalue *>::test): New.
10378 (class unaryop_svalue): New.
10379 (is_a_helper <const unaryop_svalue *>::test): New.
10380 (template <> struct default_hash_traits<unaryop_svalue::key_t>): New.
10381 (class binop_svalue): New.
10382 (is_a_helper <const binop_svalue *>::test): New.
10383 (template <> struct default_hash_traits<binop_svalue::key_t>): New.
10384 (class sub_svalue): New.
10385 (is_a_helper <const sub_svalue *>::test): New.
10386 (template <> struct default_hash_traits<sub_svalue::key_t>): New.
10387 (class unmergeable_svalue): New.
10388 (is_a_helper <const unmergeable_svalue *>::test): New.
10389 (class placeholder_svalue): New.
10390 (is_a_helper <placeholder_svalue *>::test): New.
10391 (class widening_svalue): New.
10392 (is_a_helper <widening_svalue *>::test): New.
10393 (template <> struct default_hash_traits<widening_svalue::key_t>): New.
10394 (class compound_svalue): New.
10395 (is_a_helper <compound_svalue *>::test): New.
10396 (template <> struct default_hash_traits<compound_svalue::key_t>): New.
10397 (class conjured_svalue): New.
10398 (is_a_helper <conjured_svalue *>::test): New.
10399 (template <> struct default_hash_traits<conjured_svalue::key_t>): New.
10400 (enum region_kind): Delete RK_PRIMITIVE, RK_STRUCT, RK_UNION, and
10401 RK_ARRAY. Add RK_LABEL, RK_DECL, RK_FIELD, RK_ELEMENT, RK_OFFSET,
10402 RK_CAST, RK_HEAP_ALLOCATED, RK_ALLOCA, RK_STRING, and RK_UNKNOWN.
10403 (region_kind_to_str): Delete.
10404 (region::~region): Move implementation to region.cc.
10405 (region::operator==): Delete.
10406 (region::operator!=): Delete.
10407 (region::clone): Delete.
10408 (region::get_id): New.
10409 (region::cmp_ids): New.
10410 (region::dyn_cast_map_region): Delete.
10411 (region::dyn_cast_array_region): Delete.
10412 (region::region_id get_parent): Delete.
10413 (region::get_parent_region): Convert to a simple accessor.
10414 (region::void set_value): Delete.
10415 (region::svalue_id get_value): Delete.
10416 (region::svalue_id get_value_direct): Delete.
10417 (region::svalue_id get_inherited_child_sid): Delete.
10418 (region::dyn_cast_frame_region): New.
10419 (region::dyn_cast_function_region): New.
10420 (region::dyn_cast_decl_region): New.
10421 (region::dyn_cast_field_region): New.
10422 (region::dyn_cast_element_region): New.
10423 (region::dyn_cast_offset_region): New.
10424 (region::dyn_cast_cast_region): New.
10425 (region::dyn_cast_string_region): New.
10426 (region::accept): New.
10427 (region::get_base_region): New.
10428 (region::base_region_p): New.
10429 (region::descendent_of_p): New.
10430 (region::maybe_get_frame_region): New.
10431 (region::maybe_get_decl): New.
10432 (region::hash): Delete.
10433 (region::rint): Delete.
10434 (region::dump_dot_to_pp): Delete.
10435 (region::get_desc): New.
10436 (region::dump_to_pp): Convert to vfunc, changing signature.
10437 (region::dump_child_label): Delete.
10438 (region::remap_svalue_ids): Delete.
10439 (region::remap_region_ids): Delete.
10440 (region::dump): New.
10441 (region::walk_for_canonicalization): Delete.
10442 (region::non_null_p): Drop region_model param.
10443 (region::add_view): Delete.
10444 (region::get_view): Delete.
10445 (region::get_active_view): Delete.
10446 (region::is_view_p): Delete.
10447 (region::cmp_ptrs): New.
10448 (region::validate): Delete.
10449 (region::get_offset): New.
10450 (region::get_byte_size): New.
10451 (region::get_bit_size): New.
10452 (region::get_subregions_for_binding): New.
10453 (region::region): Add complexity param. Convert parent from
10454 region_id to const region *. Drop svalue_id. Drop copy ctor.
10455 (region::symbolic_for_unknown_ptr_p): New.
10456 (region::add_to_hash): Delete.
10457 (region::print_fields): Delete.
10458 (region::get_complexity): New accessor.
10459 (region::become_active_view): Delete.
10460 (region::deactivate_any_active_view): Delete.
10461 (region::deactivate_view): Delete.
10462 (region::calc_offset): New.
10463 (region::m_parent_rid): Delete.
10464 (region::m_sval_id): Delete.
10465 (region::m_complexity): New.
10466 (region::m_id): New.
10467 (region::m_parent): New.
10468 (region::m_view_rids): Delete.
10469 (region::m_is_view): Delete.
10470 (region::m_active_view_rid): Delete.
10471 (region::m_cached_offset): New.
10472 (is_a_helper <region *>::test): Convert to...
10473 (is_a_helper <const region *>::test): ... this.
10474 (class primitive_region): Delete.
10475 (class space_region): New.
10476 (class map_region): Delete.
10477 (is_a_helper <map_region *>::test): Delete.
10478 (class frame_region): Reimplement.
10479 (template <> struct default_hash_traits<frame_region::key_t>):
10481 (class globals_region): Reimplement.
10482 (is_a_helper <globals_region *>::test): Convert to...
10483 (is_a_helper <const globals_region *>::test): ...this.
10484 (class struct_or_union_region): Delete.
10485 (is_a_helper <struct_or_union_region *>::test): Delete.
10486 (class code_region): Reimplement.
10487 (is_a_helper <const code_region *>::test): New.
10488 (class struct_region): Delete.
10489 (is_a_helper <struct_region *>::test): Delete.
10490 (class function_region): Reimplement.
10491 (is_a_helper <function_region *>::test): Convert to...
10492 (is_a_helper <const function_region *>::test): ...this.
10493 (class union_region): Delete.
10494 (is_a_helper <union_region *>::test): Delete.
10495 (class label_region): New.
10496 (is_a_helper <const label_region *>::test): New.
10497 (class scope_region): Delete.
10498 (class stack_region): Reimplement.
10499 (is_a_helper <stack_region *>::test): Convert to...
10500 (is_a_helper <const stack_region *>::test): ...this.
10501 (class heap_region): Reimplement.
10502 (is_a_helper <heap_region *>::test): Convert to...
10503 (is_a_helper <const heap_region *>::test): ...this.
10504 (class root_region): Reimplement.
10505 (is_a_helper <root_region *>::test): Convert to...
10506 (is_a_helper <const root_region *>::test): ...this.
10507 (class symbolic_region): Reimplement.
10508 (is_a_helper <const symbolic_region *>::test): New.
10509 (template <> struct default_hash_traits<symbolic_region::key_t>):
10511 (class decl_region): New.
10512 (is_a_helper <const decl_region *>::test): New.
10513 (class field_region): New.
10514 (template <> struct default_hash_traits<field_region::key_t>): New.
10515 (class array_region): Delete.
10516 (class element_region): New.
10517 (is_a_helper <array_region *>::test): Delete.
10518 (is_a_helper <const element_region *>::test): New.
10519 (template <> struct default_hash_traits<element_region::key_t>):
10521 (class offset_region): New.
10522 (is_a_helper <const offset_region *>::test): New.
10523 (template <> struct default_hash_traits<offset_region::key_t>):
10525 (class cast_region): New.
10526 (is_a_helper <const cast_region *>::test): New.
10527 (template <> struct default_hash_traits<cast_region::key_t>): New.
10528 (class heap_allocated_region): New.
10529 (class alloca_region): New.
10530 (class string_region): New.
10531 (is_a_helper <const string_region *>::test): New.
10532 (class unknown_region): New.
10533 (class region_model_manager): New.
10534 (struct append_ssa_names_cb_data): New.
10535 (class call_details): New.
10536 (region_model::region_model): Add region_model_manager param.
10537 (region_model::print_svalue): Delete.
10538 (region_model::dump_dot_to_pp): Delete.
10539 (region_model::dump_dot_to_file): Delete.
10540 (region_model::dump_dot): Delete.
10541 (region_model::dump_to_pp): Drop summarize param in favor of
10542 simple and multiline.
10543 (region_model::dump): Likewise.
10544 (region_model::summarize_to_pp): Delete.
10545 (region_model::summarize): Delete.
10546 (region_model::void canonicalize): Drop ctxt param.
10547 (region_model::void check_for_poison): Delete.
10548 (region_model::get_gassign_result): New.
10549 (region_model::impl_call_alloca): New.
10550 (region_model::impl_call_analyzer_describe): New.
10551 (region_model::impl_call_analyzer_eval): New.
10552 (region_model::impl_call_builtin_expect): New.
10553 (region_model::impl_call_calloc): New.
10554 (region_model::impl_call_free): New.
10555 (region_model::impl_call_malloc): New.
10556 (region_model::impl_call_memset): New.
10557 (region_model::impl_call_strlen): New.
10558 (region_model::get_reachable_svalues): New.
10559 (region_model::handle_phi): Drop is_back_edge param.
10560 (region_model::region_id get_root_rid): Delete.
10561 (region_model::root_region *get_root_region): Delete.
10562 (region_model::region_id get_stack_region_id): Delete.
10563 (region_model::push_frame): Convert from region_id and svalue_id
10564 to const region * and const svalue *.
10565 (region_model::get_current_frame_id): Replace with...
10566 (region_model::get_current_frame): ...this.
10567 (region_model::pop_frame): Convert from region_id to
10568 const region *. Drop purge and stats param. Add out_result.
10569 (region_model::function *get_function_at_depth): Delete.
10570 (region_model::get_globals_region_id): Delete.
10571 (region_model::add_svalue): Delete.
10572 (region_model::replace_svalue): Delete.
10573 (region_model::add_region): Delete.
10574 (region_model::add_region_for_type): Delete.
10575 (region_model::get_svalue): Delete.
10576 (region_model::get_region): Delete.
10577 (region_model::get_lvalue): Convert from region_id to
10579 (region_model::get_rvalue): Convert from svalue_id to
10581 (region_model::get_or_create_ptr_svalue): Delete.
10582 (region_model::get_or_create_constant_svalue): Delete.
10583 (region_model::get_svalue_for_fndecl): Delete.
10584 (region_model::get_svalue_for_label): Delete.
10585 (region_model::get_region_for_fndecl): Delete.
10586 (region_model::get_region_for_label): Delete.
10587 (region_model::get_frame_at_index (int index) const;): New.
10588 (region_model::maybe_cast): Delete.
10589 (region_model::maybe_cast_1): Delete.
10590 (region_model::get_field_region): Delete.
10591 (region_model::id deref_rvalue): Convert from region_id and
10592 svalue_id to const region * and const svalue *. Drop overload,
10593 passing in both a tree and an svalue.
10594 (region_model::set_value): Convert from region_id and svalue_id to
10595 const region * and const svalue *.
10596 (region_model::set_to_new_unknown_value): Delete.
10597 (region_model::clobber_region (const region *reg);): New.
10598 (region_model::purge_region (const region *reg);): New.
10599 (region_model::zero_fill_region (const region *reg);): New.
10600 (region_model::mark_region_as_unknown (const region *reg);): New.
10601 (region_model::copy_region): Convert from region_id to
10603 (region_model::eval_condition): Convert from svalue_id to
10605 (region_model::eval_condition_without_cm): Likewise.
10606 (region_model::compare_initial_and_pointer): New.
10607 (region_model:maybe_get_constant): Delete.
10608 (region_model::add_new_malloc_region): Delete.
10609 (region_model::get_representative_tree): Convert from svalue_id to
10611 (region_model::get_representative_path_var): Delete decl taking a
10612 region_id in favor of two decls, for svalue vs region, with an
10613 svalue_set to ensure termination.
10614 (region_model::get_path_vars_for_svalue): Delete.
10615 (region_model::create_region_for_heap_alloc): New.
10616 (region_model::create_region_for_alloca): New.
10617 (region_model::purge_unused_svalues): Delete.
10618 (region_model::remap_svalue_ids): Delete.
10619 (region_model::remap_region_ids): Delete.
10620 (region_model::purge_regions): Delete.
10621 (region_model::get_num_svalues): Delete.
10622 (region_model::get_num_regions): Delete.
10623 (region_model::get_descendents): Delete.
10624 (region_model::get_store): New.
10625 (region_model::delete_region_and_descendents): Delete.
10626 (region_model::get_manager): New.
10627 (region_model::unbind_region_and_descendents): New.
10628 (region_model::can_merge_with_p): Add point param. Drop
10629 svalue_id_merger_mapping.
10630 (region_model::get_value_by_name): Delete.
10631 (region_model::convert_byte_offset_to_array_index): Delete.
10632 (region_model::get_or_create_mem_ref): Delete.
10633 (region_model::get_or_create_pointer_plus_expr): Delete.
10634 (region_model::get_or_create_view): Delete.
10635 (region_model::get_lvalue_1): Convert from region_id to
10637 (region_model::get_rvalue_1): Convert from svalue_id to
10639 (region_model::get_ssa_name_regions_for_current_frame): New.
10640 (region_model::append_ssa_names_cb): New.
10641 (region_model::get_store_value): New.
10642 (region_model::copy_struct_region): Delete.
10643 (region_model::copy_union_region): Delete.
10644 (region_model::copy_array_region): Delete.
10645 (region_model::region_exists_p): New.
10646 (region_model::make_region_for_unexpected_tree_code): Delete.
10647 (region_model::loop_replay_fixup): New.
10648 (region_model::poison_any_pointers_to_bad_regions): Delete.
10649 (region_model::poison_any_pointers_to_descendents): New.
10650 (region_model::dump_summary_of_rep_path_vars): Delete.
10651 (region_model::on_top_level_param): New.
10652 (region_model::record_dynamic_extents): New.
10653 (region_model::m_mgr;): New.
10654 (region_model::m_store;): New.
10655 (region_model::m_svalues;): Delete.
10656 (region_model::m_regions;): Delete.
10657 (region_model::m_root_rid;): Delete.
10658 (region_model::m_current_frame;): New.
10659 (region_model_context::remap_svalue_ids): Delete.
10660 (region_model_context::can_purge_p): Delete.
10661 (region_model_context::on_svalue_leak): New.
10662 (region_model_context::on_svalue_purge): Delete.
10663 (region_model_context::on_liveness_change): New.
10664 (region_model_context::on_inherited_svalue): Delete.
10665 (region_model_context::on_cast): Delete.
10666 (region_model_context::on_unknown_change): Convert from svalue_id to
10667 const svalue * and add is_mutable.
10668 (class noop_region_model_context): Update for region_model_context
10670 (model_merger::model_merger): Add program_point. Drop
10671 svalue_id_merger_mapping.
10672 (model_merger::dump_to_pp): Add "simple" param.
10673 (model_merger::dump): Likewise.
10674 (model_merger::get_region_a): Delete.
10675 (model_merger::get_region_b): Delete.
10676 (model_merger::can_merge_values_p): Delete.
10677 (model_merger::record_regions): Delete.
10678 (model_merger::record_svalues): Delete.
10679 (model_merger::m_point): New field.
10680 (model_merger::m_map_regions_from_a_to_m): Delete.
10681 (model_merger::m_map_regions_from_b_to_m): Delete.
10682 (model_merger::m_sid_mapping): Delete.
10683 (struct svalue_id_merger_mapping): Delete.
10684 (class engine): New.
10685 (struct canonicalization): Delete.
10686 (inchash::add): Delete decls for hashing svalue_id and region_id.
10687 (test_region_model_context::on_unexpected_tree_code): Require t to
10689 (selftest::assert_condition): Add overload comparing a pair of
10691 * sm-file.cc: Include "tristate.h", "selftest.h",
10692 "analyzer/call-string.h", "analyzer/program-point.h",
10693 "analyzer/store.h", and "analyzer/region-model.h".
10694 (fileptr_state_machine::get_default_state): New.
10695 (fileptr_state_machine::on_stmt): Remove calls to
10696 get_readable_tree in favor of get_diagnostic_tree.
10697 * sm-malloc.cc: Include "tristate.h", "selftest.h",
10698 "analyzer/call-string.h", "analyzer/program-point.h",
10699 "analyzer/store.h", and "analyzer/region-model.h".
10700 (malloc_state_machine::get_default_state): New.
10701 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New.
10702 (malloc_diagnostic::describe_state_change): Handle change.m_expr
10704 (null_arg::emit): Avoid printing "NULL '0'".
10705 (null_arg::describe_final_event): Avoid printing "(0) NULL".
10706 (malloc_leak::emit): Handle m_arg being NULL.
10707 (malloc_leak::describe_final_event): Handle ev.m_expr being NULL.
10708 (malloc_state_machine::on_stmt): Don't call get_readable_tree.
10709 Call get_diagnostic_tree when creating pending diagnostics.
10710 Update for is_zero_assignment becoming a member function of
10712 Don't transition to m_non_heap for ADDR_EXPR(MEM_REF()).
10713 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New
10714 vfunc implementation.
10715 * sm-sensitive.cc (sensitive_state_machine::warn_for_any_exposure): Call
10716 get_diagnostic_tree and pass the result to warn_for_state.
10717 * sm-signal.cc: Move includes of "analyzer/call-string.h" and
10718 "analyzer/program-point.h" to before "analyzer/region-model.h",
10719 and also include "analyzer/store.h" before it.
10720 (signal_unsafe_call::describe_state_change): Use
10721 get_dest_function to get handler.
10722 (update_model_for_signal_handler): Pass manager to region_model
10724 (register_signal_handler::impl_transition): Update for changes to
10725 get_or_create_node and add_edge.
10726 * sm-taint.cc (taint_state_machine::on_stmt): Remove calls to
10727 get_readable_tree, replacing them when calling warn_for_state with
10728 calls to get_diagnostic_tree.
10729 * sm.cc (is_zero_assignment): Delete.
10730 (any_pointer_p): Move to within namespace ana.
10731 * sm.h (is_zero_assignment): Remove decl.
10732 (any_pointer_p): Move decl to within namespace ana.
10733 (state_machine::get_default_state): New vfunc.
10734 (state_machine::reset_when_passed_to_unknown_fn_p): New vfunc.
10735 (sm_context::get_readable_tree): Rename to...
10736 (sm_context::get_diagnostic_tree): ...this.
10737 (sm_context::is_zero_assignment): New vfunc.
10738 * store.cc: New file.
10739 * store.h: New file.
10740 * svalue.cc: New file.
10742 2020-05-22 Mark Wielaard <mark@klomp.org>
10744 * sm-signal.cc(signal_unsafe_call::emit): Possibly add
10745 gcc_rich_location note for replacement.
10746 (signal_unsafe_call::get_replacement_fn): New private function.
10747 (get_async_signal_unsafe_fns): Add "exit".
10749 2020-04-28 David Malcolm <dmalcolm@redhat.com>
10752 * engine.cc (impl_region_model_context::on_unexpected_tree_code):
10754 * region-model.cc (region_model::add_region_for_type): Handle
10757 (test_region_model_context::on_unexpected_tree_code): Handle NULL
10760 2020-04-28 David Malcolm <dmalcolm@redhat.com>
10766 * analyzer.opt (Wanalyzer-use-of-uninitialized-value): Delete.
10767 * program-state.cc (selftest::test_program_state_dumping): Update
10768 expected dump result for removal of "uninit".
10769 * region-model.cc (poison_kind_to_str): Delete POISON_KIND_UNINIT
10771 (root_region::ensure_stack_region): Initialize stack with null
10772 svalue_id rather than with a typeless POISON_KIND_UNINIT value.
10773 (root_region::ensure_heap_region): Likewise for the heap.
10774 (region_model::dump_summary_of_rep_path_vars): Remove
10775 summarization of uninit values.
10776 (region_model::validate): Remove check that the stack has a
10777 POISON_KIND_UNINIT value.
10778 (poisoned_value_diagnostic::emit): Remove POISON_KIND_UNINIT
10780 (poisoned_value_diagnostic::describe_final_event): Likewise.
10781 (selftest::test_dump): Update expected dump result for removal of
10783 (selftest::test_svalue_equality): Remove "uninit" and "freed".
10784 * region-model.h (enum poison_kind): Remove POISON_KIND_UNINIT.
10786 2020-04-01 David Malcolm <dmalcolm@redhat.com>
10789 * checker-path.cc: Include "bitmap.h".
10790 * constraint-manager.cc: Likewise.
10791 * diagnostic-manager.cc: Likewise.
10792 * engine.cc: Likewise.
10793 (exploded_node::detect_leaks): Pass null region_id to pop_frame.
10794 * program-point.cc: Include "bitmap.h".
10795 * program-state.cc: Likewise.
10796 * region-model.cc (id_set<region_id>::id_set): Convert to...
10797 (region_id_set::region_id_set): ...this.
10798 (svalue_id_set::svalue_id_set): New ctor.
10799 (region_model::copy_region): New function.
10800 (region_model::copy_struct_region): New function.
10801 (region_model::copy_union_region): New function.
10802 (region_model::copy_array_region): New function.
10803 (stack_region::pop_frame): Drop return value. Add
10804 "result_dst_rid" param; if it is non-null, use copy_region to copy
10805 the result to it. Rather than capture and pass a single "known
10806 used" return value to be used by purge_unused_values, instead
10807 gather and pass a set of known used return values.
10808 (root_region::pop_frame): Drop return value. Add "result_dst_rid"
10810 (region_model::on_assignment): Use copy_region.
10811 (region_model::on_return): Likewise for the result.
10812 (region_model::on_longjmp): Pass null for pop_frame's
10814 (region_model::update_for_return_superedge): Pass the region for the
10815 return value of the call, if any, to pop_frame, rather than setting
10816 the lvalue for the lhs of the result.
10817 (region_model::pop_frame): Drop return value. Add
10818 "result_dst_rid" param.
10819 (region_model::purge_unused_svalues): Convert third param from an
10820 svalue_id * to an svalue_id_set *, updating the initial populating
10821 of the "used" bitmap accordingly. Don't remap it when done.
10822 (struct selftest::coord_test): New selftest fixture, extracted from...
10823 (selftest::test_dump_2): ...here.
10824 (selftest::test_compound_assignment): New selftest.
10825 (selftest::test_stack_frames): Pass null to new param of pop_frame.
10826 (selftest::analyzer_region_model_cc_tests): Call the new selftest.
10827 * region-model.h (class id_set): Delete template.
10828 (class region_id_set): Reimplement, using old id_set implementation.
10829 (class svalue_id_set): Likewise. Convert from auto_sbitmap to
10831 (region::get_active_view): New accessor.
10832 (stack_region::pop_frame): Drop return value. Add
10833 "result_dst_rid" param.
10834 (root_region::pop_frame): Likewise.
10835 (region_model::pop_frame): Likewise.
10836 (region_model::copy_region): New decl.
10837 (region_model::purge_unused_svalues): Convert third param from an
10838 svalue_id * to an svalue_id_set *.
10839 (region_model::copy_struct_region): New decl.
10840 (region_model::copy_union_region): New decl.
10841 (region_model::copy_array_region): New decl.
10843 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10845 * program-state.cc (selftest::test_program_state_dumping): Update
10846 expected dump to include symbolic_region's possibly_null field.
10847 * region-model.cc (symbolic_region::print_fields): New vfunc
10849 (region_model::add_constraint): Clear m_possibly_null from
10850 symbolic_regions now known to be non-NULL.
10851 (selftest::test_malloc_constraints): New selftest.
10852 (selftest::analyzer_region_model_cc_tests): Call it.
10853 * region-model.h (region::dyn_cast_symbolic_region): Add non-const
10855 (symbolic_region::dyn_cast_symbolic_region): Implement it.
10856 (symbolic_region::print_fields): New vfunc override decl.
10858 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10860 * analyzer.h (class feasibility_problem): New forward decl.
10861 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
10862 Initialize new fields m_status, m_epath_length, and m_problem.
10863 (saved_diagnostic::~saved_diagnostic): Delete m_problem.
10864 (dedupe_candidate::dedupe_candidate): Convert "sd" param from a
10865 const ref to a mutable ptr.
10866 (dedupe_winners::add): Convert "sd" param from a const ref to a
10867 mutable ptr. Record the length of the exploded_path. Record the
10868 feasibility/infeasibility of sd into sd, capturing a
10869 feasibility_problem when feasible_p fails, and storing it in sd.
10870 (diagnostic_manager::emit_saved_diagnostics): Update for pass by
10871 ptr rather than by const ref.
10872 * diagnostic-manager.h (class saved_diagnostic): Add new enum
10873 status. Add fields m_status, m_epath_length and m_problem.
10874 (saved_diagnostic::set_feasible): New member function.
10875 (saved_diagnostic::set_infeasible): New member function.
10876 (saved_diagnostic::get_feasibility_problem): New accessor.
10877 (saved_diagnostic::get_status): New accessor.
10878 (saved_diagnostic::set_epath_length): New member function.
10879 (saved_diagnostic::get_epath_length): New accessor.
10880 * engine.cc: Include "gimple-pretty-print.h".
10881 (exploded_path::feasible_p): Add OUT param and, if non-NULL, write
10882 a new feasibility_problem to it on failure.
10883 (viz_callgraph_node::dump_dot): Convert begin_tr calls to
10884 begin_trtd. Convert end_tr calls to end_tdtr.
10885 (class exploded_graph_annotator): New subclass of dot_annotator.
10886 (impl_run_checkers): Add a second -fdump-analyzer-supergraph dump
10887 after the analysis runs, using exploded_graph_annotator. dumping
10888 to DUMP_BASE_NAME.supergraph-eg.dot.
10889 * exploded-graph.h (exploded_node::get_dot_fillcolor): Make
10891 (exploded_path::feasible_p): Add OUT param.
10892 (class feasibility_problem): New class.
10893 * state-purge.cc (state_purge_annotator::add_node_annotations):
10894 Return a bool, add a "within_table" param.
10895 (print_vec_of_names): Convert begin_tr calls to begin_trtd.
10896 Convert end_tr calls to end_tdtr.
10897 (state_purge_annotator::add_stmt_annotations): Add "within_row"
10899 * state-purge.h ((state_purge_annotator::add_node_annotations):
10900 Return a bool, add a "within_table" param.
10901 (state_purge_annotator::add_stmt_annotations): Add "within_row"
10903 * supergraph.cc (supernode::dump_dot): Call add_node_annotations
10904 twice: as before, passing false for "within_table", then again
10905 with true when within the TABLE element. Convert some begin_tr
10906 calls to begin_trtd, and some end_tr calls to end_tdtr.
10907 Repeat each add_stmt_annotations call, distinguishing between
10908 calls that add TRs and those that add TDs to an existing TR.
10909 Add a call to add_after_node_annotations.
10910 * supergraph.h (dot_annotator::add_node_annotations): Add a
10911 "within_table" param.
10912 (dot_annotator::add_stmt_annotations): Add a "within_row" param.
10913 (dot_annotator::add_after_node_annotations): New vfunc.
10915 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10917 * diagnostic-manager.cc (dedupe_winners::add): Show the
10918 exploded_node index in the log messages.
10919 (diagnostic_manager::emit_saved_diagnostics): Log a summary of
10920 m_saved_diagnostics at entry.
10922 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10924 * supergraph.cc (superedge::dump): Add space before description;
10925 move newline to non-pretty_printer overload.
10927 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10929 * region-model.cc: Include "stor-layout.h".
10930 (region_model::dump_to_pp): Rather than calling
10931 dump_summary_of_map on each of the current frame and the globals,
10932 instead get a vec of representative path_vars for all regions,
10933 and then dump a summary of all of them.
10934 (region_model::dump_summary_of_map): Delete, rewriting into...
10935 (region_model::dump_summary_of_rep_path_vars): ...this new
10936 function, working on a vec of path_vars.
10937 (region_model::set_value): New overload.
10938 (region_model::get_representative_path_var): Rename
10939 "parent_region" local to "parent_reg" and consolidate with other
10940 local. Guard test for grandparent being stack on parent_reg being
10941 non-NULL. Move handling for parent being an array_region to
10942 within guard for parent_reg being non-NULL.
10943 (selftest::make_test_compound_type): New function.
10944 (selftest::test_dump_2): New selftest.
10945 (selftest::test_dump_3): New selftest.
10946 (selftest::test_stack_frames): Update expected output from
10947 simplified dump to show "a" and "b" from parent frame and "y" in
10949 (selftest::analyzer_region_model_cc_tests): Call test_dump_2 and
10951 * region-model.h (region_model::set_value): New overload decl.
10952 (region_model::dump_summary_of_map): Delete.
10953 (region_model::dump_summary_of_rep_path_vars): New.
10955 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10957 * region-model.h (class noop_region_model_context): New subclass
10958 of region_model_context.
10959 (class tentative_region_model_context): Inherit from
10960 noop_region_model_context rather than from region_model_context;
10961 drop redundant vfunc implementations.
10962 (class test_region_model_context): Likewise.
10964 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10966 * engine.cc (exploded_node::exploded_node): Move implementation
10967 here from header; accept point_and_state by const reference rather
10969 * exploded-graph.h (exploded_node::exploded_node): Pass
10970 point_and_state by const reference rather than by value. Move
10973 2020-03-18 Jakub Jelinek <jakub@redhat.com>
10975 * sm-malloc.cc (malloc_state_machine::on_stmt): Fix up duplicated word
10976 issue in a comment.
10977 * region-model.cc (region_model::make_region_for_unexpected_tree_code,
10978 region_model::delete_region_and_descendents): Likewise.
10979 * engine.cc (class exploded_cluster): Likewise.
10980 * diagnostic-manager.cc (class path_builder): Likewise.
10982 2020-03-13 David Malcolm <dmalcolm@redhat.com>
10986 * diagnostic-manager.cc (for_each_state_change): Bulletproof
10987 against errors in get_rvalue by passing a
10988 tentative_region_model_context and rejecting if there's an error.
10989 * region-model.cc (region_model::get_lvalue_1): When handling
10990 ARRAY_REF, handle results of error-handling. Handle NOP_EXPR.
10992 2020-03-06 David Malcolm <dmalcolm@redhat.com>
10994 * analyzer.h (class array_region): New forward decl.
10995 * program-state.cc (selftest::test_program_state_dumping_2): New.
10996 (selftest::analyzer_program_state_cc_tests): Call it.
10997 * region-model.cc (array_region::constant_from_key): New.
10998 (region_model::get_representative_tree): Handle region_svalue by
10999 generating an ADDR_EXPR.
11000 (region_model::get_representative_path_var): In view handling,
11001 remove erroneous TREE_TYPE when determining the type of the tree.
11002 Handle array regions and STRING_CST.
11003 (selftest::assert_dump_tree_eq): New.
11004 (ASSERT_DUMP_TREE_EQ): New macro.
11005 (selftest::test_get_representative_tree): New selftest.
11006 (selftest::analyzer_region_model_cc_tests): Call it.
11007 * region-model.h (region::dyn_cast_array_region): New vfunc.
11008 (array_region::dyn_cast_array_region): New vfunc implementation.
11009 (array_region::constant_from_key): New decl.
11011 2020-03-06 David Malcolm <dmalcolm@redhat.com>
11013 * analyzer.h (dump_quoted_tree): New decl.
11014 * engine.cc (exploded_node::dump_dot): Pass region model to
11015 sm_state_map::print.
11016 * program-state.cc: Include diagnostic-core.h.
11017 (sm_state_map::print): Add "model" param and use it to print
11018 representative trees. Only print origin information if non-null.
11019 (sm_state_map::dump): Pass NULL for model to print call.
11020 (program_state::print): Pass region model to sm_state_map::print.
11021 (program_state::dump_to_pp): Use spaces rather than newlines when
11022 summarizing. Pass region_model to sm_state_map::print.
11023 (ana::selftest::assert_dump_eq): New function.
11024 (ASSERT_DUMP_EQ): New macro.
11025 (ana::selftest::test_program_state_dumping): New function.
11026 (ana::selftest::analyzer_program_state_cc_tests): Call it.
11027 * program-state.h (program_state::print): Add model param.
11028 * region-model.cc (dump_quoted_tree): New function.
11029 (map_region::print_fields): Use dump_quoted_tree rather than
11030 %qE to avoid lang-dependent output.
11031 (map_region::dump_child_label): Likewise.
11032 (region_model::dump_summary_of_map): For SK_REGION, when
11033 get_representative_path_var fails, print the region id rather than
11034 erroneously printing NULL.
11035 * sm.cc (state_machine::get_state_by_name): New function.
11036 * sm.h (state_machine::get_state_by_name): New decl.
11038 2020-03-04 David Malcolm <dmalcolm@redhat.com>
11040 * region-model.cc (region::validate): Convert model param from ptr
11041 to reference. Update comment to reflect that it's now a vfunc.
11042 (map_region::validate): New vfunc implementation.
11043 (array_region::validate): New vfunc implementation.
11044 (stack_region::validate): New vfunc implementation.
11045 (root_region::validate): New vfunc implementation.
11046 (region_model::validate): Pass a reference rather than a pointer
11047 to the region::validate vfunc.
11048 * region-model.h (region::validate): Make virtual. Convert model
11049 param from ptr to reference.
11050 (map_region::validate): New vfunc decl.
11051 (array_region::validate): New vfunc decl.
11052 (stack_region::validate): New vfunc decl.
11053 (root_region::validate): New vfunc decl.
11055 2020-03-04 David Malcolm <dmalcolm@redhat.com>
11058 * region-model.cc (region_model::on_call_pre): Handle
11059 BUILT_IN_EXPECT and its variants.
11060 (region_model::add_any_constraints_from_ssa_def_stmt): Split out
11061 gassign handling into add_any_constraints_from_gassign; add gcall
11063 (region_model::add_any_constraints_from_gassign): New function,
11064 based on the above. Add handling for NOP_EXPR.
11065 (region_model::add_any_constraints_from_gcall): New function.
11066 (region_model::get_representative_path_var): Handle views.
11068 (region_model::add_any_constraints_from_ssa_def_stmt): New decl.
11069 (region_model::add_any_constraints_from_gassign): New decl.
11071 2020-03-04 David Malcolm <dmalcolm@redhat.com>
11074 * checker-path.h (state_change_event::get_lvalue): Add ctxt param
11075 and pass it to region_model::get_value call.
11076 * diagnostic-manager.cc (get_any_origin): Pass a
11077 tentative_region_model_context to the calls to get_lvalue and reject
11078 the comparison if errors occur.
11079 (can_be_expr_of_interest_p): New function.
11080 (diagnostic_manager::prune_for_sm_diagnostic): Replace checks for
11081 CONSTANT_CLASS_P with calls to update_for_unsuitable_sm_exprs.
11082 Pass a tentative_region_model_context to the calls to
11083 state_change_event::get_lvalue and reject the comparison if errors
11085 (diagnostic_manager::update_for_unsuitable_sm_exprs): New.
11086 * diagnostic-manager.h
11087 (diagnostic_manager::update_for_unsuitable_sm_exprs): New decl.
11088 * region-model.h (class tentative_region_model_context): New class.
11090 2020-03-04 David Malcolm <dmalcolm@redhat.com>
11092 * engine.cc (worklist::worklist): Remove unused field m_eg.
11093 (class viz_callgraph_edge): Remove unused field m_call_sedge.
11094 (class viz_callgraph): Remove unused field m_sg.
11095 * exploded-graph.h (worklist::::m_eg): Remove unused field.
11097 2020-03-02 David Malcolm <dmalcolm@redhat.com>
11099 * analyzer.opt (fanalyzer-show-duplicate-count): New option.
11100 * diagnostic-manager.cc
11101 (diagnostic_manager::emit_saved_diagnostic): Use the above to
11102 guard the printing of the duplicate count.
11104 2020-03-02 David Malcolm <dmalcolm@redhat.com>
11107 * analyzer.cc (is_std_function_p): New function.
11108 (is_std_named_call_p): New functions.
11109 * analyzer.h (is_std_named_call_p): New decl.
11110 * sm-malloc.cc (malloc_state_machine::on_stmt): Check for "std::"
11111 variants when checking for malloc, calloc and free.
11113 2020-02-26 David Malcolm <dmalcolm@redhat.com>
11116 * diagnostic-manager.cc
11117 (diagnostic_manager::prune_for_sm_diagnostic): Assert that var is
11118 either NULL or not a constant. When updating var, bulletproof
11119 against constant values.
11121 2020-02-26 David Malcolm <dmalcolm@redhat.com>
11124 * region-model.cc (region_model::get_fndecl_for_call): Gracefully
11125 fail for fn_decls that don't have a cgraph_node.
11127 2020-02-26 David Malcolm <dmalcolm@redhat.com>
11129 * bar-chart.cc: New file.
11130 * bar-chart.h: New file.
11131 * engine.cc: Include "analyzer/bar-chart.h".
11132 (stats::log): Only log the m_num_nodes kinds that are non-zero.
11133 (stats::dump): Likewise when dumping.
11134 (stats::get_total_enodes): New.
11135 (exploded_graph::get_or_create_node): Increment the per-point-data
11136 m_excess_enodes when hitting the per-program-point limit on
11138 (exploded_graph::print_bar_charts): New.
11139 (exploded_graph::log_stats): Log the number of unprocessed enodes
11140 in the worklist. Call print_bar_charts.
11141 (exploded_graph::dump_stats): Print the number of unprocessed
11142 enodes in the worklist.
11143 * exploded-graph.h (stats::get_total_enodes): New decl.
11144 (struct per_program_point_data): Add field m_excess_enodes.
11145 (exploded_graph::print_bar_charts): New decl.
11146 * supergraph.cc (superedge::dump): New.
11147 (superedge::dump): New.
11148 * supergraph.h (supernode::get_function): New.
11149 (superedge::dump): New decl.
11150 (superedge::dump): New decl.
11152 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11154 * engine.cc (exploded_graph::get_or_create_node): Dump the
11155 program_state to the pp, rather than to stderr.
11157 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11160 * sm.cc (make_checkers): Require the "taint" checker to be
11161 explicitly enabled.
11163 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11167 (impl_region_model_context::impl_region_model_context): Add logger
11169 * engine.cc (exploded_graph::add_function_entry): Create an
11170 impl_region_model_context and pass it to the push_frame call.
11171 Bail if the resulting state is invalid.
11172 (exploded_graph::build_initial_worklist): Likewise.
11173 (exploded_graph::build_initial_worklist): Handle the case where
11174 add_function_entry fails.
11176 (impl_region_model_context::impl_region_model_context): Add logger
11178 * region-model.cc (map_region::get_or_create): Add ctxt param and
11179 pass it to add_region_for_type.
11180 (map_region::can_merge_p): Pass NULL as a ctxt to call to
11182 (array_region::get_element): Pass ctxt to call to get_or_create.
11183 (array_region::get_or_create): Add ctxt param and pass it to
11184 add_region_for_type.
11185 (root_region::push_frame): Pass ctxt to get_or_create calls.
11186 (region_model::get_lvalue_1): Likewise.
11187 (region_model::make_region_for_unexpected_tree_code): Assert that
11189 (region_model::get_rvalue_1): Pass ctxt to get_svalue_for_fndecl
11190 and get_svalue_for_label calls.
11191 (region_model::get_svalue_for_fndecl): Add ctxt param and pass it
11192 to get_region_for_fndecl.
11193 (region_model::get_region_for_fndecl): Add ctxt param and pass it
11195 (region_model::get_svalue_for_label): Add ctxt param and pass it
11196 to get_region_for_label.
11197 (region_model::get_region_for_label): Add ctxt param and pass it
11198 to get_region_for_fndecl and get_or_create.
11199 (region_model::get_field_region): Add ctxt param and pass it to
11200 get_or_create_view and get_or_create.
11201 (make_region_for_type): Replace gcc_unreachable with return NULL.
11202 (region_model::add_region_for_type): Add ctxt param. Handle a
11203 return of NULL from make_region_for_type by calling
11204 make_region_for_unexpected_tree_code.
11205 (region_model::get_or_create_mem_ref): Pass ctxt to calls to
11206 get_or_create_view.
11207 (region_model::get_or_create_view): Add ctxt param and pass it to
11208 add_region_for_type.
11209 (selftest::test_state_merging): Pass ctxt to get_or_create_view.
11210 * region-model.h (region_model::get_or_create): Add ctxt param.
11211 (region_model::add_region_for_type): Likewise.
11212 (region_model::get_svalue_for_fndecl): Likewise.
11213 (region_model::get_svalue_for_label): Likewise.
11214 (region_model::get_region_for_fndecl): Likewise.
11215 (region_model::get_region_for_label): Likewise.
11216 (region_model::get_field_region): Likewise.
11217 (region_model::get_or_create_view): Likewise.
11219 2020-02-24 David Malcolm <dmalcolm@redhat.com>
11221 * checker-path.cc (superedge_event::should_filter_p): Update
11222 filter for empty descriptions to cover verbosity level 3 as well
11224 * diagnostic-manager.cc: Include "analyzer/reachability.h".
11225 (class path_builder): New class.
11226 (diagnostic_manager::emit_saved_diagnostic): Create a path_builder
11227 and pass it to build_emission_path, rather passing eg; similarly
11228 for add_events_for_eedge and ext_state.
11229 (diagnostic_manager::build_emission_path): Replace "eg" param
11230 with a path_builder, pass it to add_events_for_eedge.
11231 (diagnostic_manager::add_events_for_eedge): Replace ext_state
11232 param with path_builder; pass it to add_events_for_superedge.
11233 (diagnostic_manager::significant_edge_p): New.
11234 (diagnostic_manager::add_events_for_superedge): Add path_builder
11235 param. Reject insignificant edges at verbosity levels below 3.
11236 (diagnostic_manager::prune_for_sm_diagnostic): Update highest
11237 verbosity level to 4.
11238 * diagnostic-manager.h (class path_builder): New forward decl.
11239 (diagnostic_manager::build_emission_path): Replace "eg" param
11240 with a path_builder.
11241 (diagnostic_manager::add_events_for_eedge): Replace ext_state
11242 param with path_builder.
11243 (diagnostic_manager::significant_edge_p): New.
11244 (diagnostic_manager::add_events_for_superedge): Add path_builder
11246 * reachability.h: New file.
11248 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11251 * analyzer.opt (fdump-analyzer-callgraph): Rewrite description.
11253 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11256 * region-model.cc (region_model::maybe_cast_1): Replace assertion
11257 that build_cast returns non-NULL with a conditional, falling
11258 through to the logic which returns a new unknown value of the
11259 desired type if it fails.
11261 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11264 * engine.cc (impl_region_model_context::on_unknown_tree_code):
11266 (impl_region_model_context::on_unexpected_tree_code): ...this and
11267 convert first argument from path_var to tree.
11268 (exploded_node::on_stmt): Pass ctxt to purge_for_unknown_fncall.
11269 * exploded-graph.h (region_model_context::on_unknown_tree_code):
11271 (region_model_context::on_unexpected_tree_code): ...this and
11272 convert first argument from path_var to tree.
11273 * program-state.cc (sm_state_map::purge_for_unknown_fncall): Add
11274 ctxt param and pass on to calls to get_rvalue.
11275 * program-state.h (sm_state_map::purge_for_unknown_fncall): Add
11277 * region-model.cc (region_model::handle_unrecognized_call): Pass
11278 ctxt on to call to get_rvalue.
11279 (region_model::get_lvalue_1): Move body of default case to
11280 region_model::make_region_for_unexpected_tree_code and call it.
11281 Within COMPONENT_REF case, reject attempts to handle types other
11282 than RECORD_TYPE and UNION_TYPE.
11283 (region_model::make_region_for_unexpected_tree_code): New
11284 function, based on default case of region_model::get_lvalue_1.
11286 (region_model::make_region_for_unexpected_tree_code): New decl.
11287 (region_model::on_unknown_tree_code): Rename to...
11288 (region_model::on_unexpected_tree_code): ...this and convert first
11289 argument from path_var to tree.
11290 (class test_region_model_context): Update vfunc implementation for
11293 2020-02-18 David Malcolm <dmalcolm@redhat.com>
11297 (region_model::convert_byte_offset_to_array_index): Use
11298 int_size_in_bytes before calling size_in_bytes, to gracefully fail
11299 on incomplete types.
11301 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11304 * region-model.cc (region_model::get_fndecl_for_call): Handle the
11305 case where the code_region's get_tree_for_child_region returns
11308 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11311 * engine.cc (impl_region_model_context::on_unknown_tree_code):
11313 (exploded_graph::get_or_create_node): Reject invalid states.
11315 (impl_region_model_context::on_unknown_tree_code): New decl.
11316 (point_and_state::point_and_state): Assert that the state is
11318 * program-state.cc (program_state::program_state): Initialize
11320 (program_state::operator=): Copy m_valid.
11321 (program_state::program_state): Likewise for move constructor.
11322 (program_state::print): Print m_valid.
11323 (program_state::dump_to_pp): Likewise.
11324 * program-state.h (program_state::m_valid): New field.
11325 * region-model.cc (region_model::get_lvalue_1): Implement the
11326 default case by returning a new symbolic region and calling
11327 the context's on_unknown_tree_code, rather than issuing an
11328 internal_error. Implement VIEW_CONVERT_EXPR.
11329 * region-model.h (region_model_context::on_unknown_tree_code): New
11331 (test_region_model_context::on_unknown_tree_code): New.
11333 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11335 * sm-malloc.cc (malloc_diagnostic::describe_state_change): For
11336 transition to the "null" state, only say "assuming" when
11337 transitioning from the "unchecked" state.
11339 2020-02-17 David Malcolm <dmalcolm@redhat.com>
11341 * diagnostic-manager.h (diagnostic_manager::get_saved_diagnostic):
11342 Add const overload.
11343 * engine.cc (exploded_node::dump_dot): Dump saved_diagnostics.
11344 * exploded-graph.h (exploded_graph::get_diagnostic_manager): Add
11347 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11350 * analysis-plan.cc (analysis_plan::use_summary_p): Look through
11351 the ultimate_alias_target when getting the called function.
11352 * engine.cc (exploded_node::on_stmt): Rename second "ctxt" to
11353 "sm_ctxt". Use the region_model's get_fndecl_for_call rather than
11354 gimple_call_fndecl.
11355 * region-model.cc (region_model::get_fndecl_for_call): Use
11356 ultimate_alias_target on fndecl.
11357 * supergraph.cc (get_ultimate_function_for_cgraph_edge): New
11359 (supergraph_call_edge): Use it when rejecting edges without
11361 (supergraph::supergraph): Use it to get the function for the
11362 cgraph_edge when building interprocedural superedges.
11363 (callgraph_superedge::get_callee_function): Use it.
11364 * supergraph.h (supergraph::get_num_snodes): Make param const.
11365 (supergraph::function_to_num_snodes_t): Make first type param
11368 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11371 * engine.cc (exploded_edge::exploded_edge): Add ext_state param
11372 and pass it to change.validate.
11373 (exploded_graph::get_or_create_node): Move purging of change
11374 svalues to also cover the case of reusing an existing enode.
11375 (exploded_graph::add_edge): Pass m_ext_state to exploded_edge's
11377 * exploded-graph.h (exploded_edge::exploded_edge): Add ext_state
11379 * program-state.cc (state_change::sm_change::validate): Likewise.
11380 Assert that m_sm_idx is sane. Use ext_state to validate
11381 m_old_state and m_new_state.
11382 (state_change::validate): Add ext_state param and pass it to
11383 the sm_change validate calls.
11384 * program-state.h (state_change::sm_change::validate): Add
11386 (state_change::validate): Likewise.
11388 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11391 * engine.cc (exploded_graph::dump_exploded_nodes): Handle missing
11392 case of STATUS_WORKLIST in implementation of
11393 "__analyzer_dump_exploded_nodes".
11395 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11398 * constraint-manager.cc (constraint_manager::add_constraint): When
11399 merging equivalence classes and updating m_constant, also update
11401 (constraint_manager::validate): If m_constant is non-NULL assert
11402 that m_cst_sid is non-null and is valid.
11404 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11407 * analyzer.opt (fdump-analyzer): Reword description.
11408 (fdump-analyzer-stderr): Likewise.
11410 2020-02-11 David Malcolm <dmalcolm@redhat.com>
11412 * region-model.cc (print_quoted_type): New function.
11413 (svalue::print): Use it to replace %qT.
11414 (region::dump_to_pp): Likewise.
11415 (region::dump_child_label): Likewise.
11416 (region::print_fields): Likewise.
11418 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11421 * analyzer.opt (-param=analyzer-max-recursion-depth=): Fix "tha"
11423 (Wanalyzer-use-of-uninitialized-value): Fix "initialized" ->
11424 "uninitialized" typo.
11426 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11429 * region-model.cc (region_model::get_lvalue_1):
11430 Handle BIT_FIELD_REF.
11431 (make_region_for_type): Handle VECTOR_TYPE.
11433 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11436 * diagnostic-manager.cc
11437 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof against
11438 VAR being constant.
11439 * region-model.cc (region_model::get_lvalue_1): Provide a better
11440 error message when encountering an unhandled tree code.
11442 2020-02-10 David Malcolm <dmalcolm@redhat.com>
11445 * region-model.cc (region_model::get_lvalue_1): Implement
11448 2020-02-06 David Malcolm <dmalcolm@redhat.com>
11450 * region-model.cc (region_model::maybe_cast_1): Attempt to provide
11451 a region_svalue if either type is a pointer, rather than if both
11452 types are pointers.
11454 2020-02-05 David Malcolm <dmalcolm@redhat.com>
11456 * engine.cc (exploded_node::dump_dot): Show merger enodes.
11457 (worklist::add_node): Assert that the node's m_status is
11459 (exploded_graph::process_worklist): Likewise for nodes from the
11460 worklist. Set status of merged nodes to STATUS_MERGER.
11461 (exploded_graph::process_node): Set status of node to
11463 (exploded_graph::dump_exploded_nodes): Rework handling of
11464 "__analyzer_dump_exploded_nodes", splitting enodes by status into
11465 "processed" and "merger", showing the count of just the processed
11466 enodes at the call, rather than the count of all enodes.
11467 * exploded-graph.h (exploded_node::status): New enum.
11468 (exploded_node::exploded_node): Initialize m_status to
11470 (exploded_node::get_status): New getter.
11471 (exploded_node::set_status): New setter.
11473 2020-02-04 David Malcolm <dmalcolm@redhat.com>
11476 * engine.cc (pod_hash_traits<function_call_string>::mark_empty):
11477 Eliminate reinterpret_cast.
11478 (pod_hash_traits<function_call_string>::is_empty): Likewise.
11480 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11482 * constraint-manager.cc (range::constrained_to_single_element):
11483 Replace fold_build2 with fold_binary. Remove unnecessary newline.
11484 (constraint_manager::get_or_add_equiv_class): Replace fold_build2
11485 with fold_binary in two places, and remove out-of-date comment.
11486 (constraint_manager::eval_condition): Replace fold_build2 with
11488 * region-model.cc (constant_svalue::eval_condition): Likewise.
11489 (region_model::on_assignment): Likewise.
11491 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11494 * diagnostic-manager.cc
11495 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof
11496 against bad choices due to bad paths.
11497 * engine.cc (impl_region_model_context::on_phi): New.
11498 * exploded-graph.h (impl_region_model_context::on_phi): New decl.
11499 * region-model.cc (region_model::on_longjmp): Likewise.
11500 (region_model::handle_phi): Add phi param. Call the ctxt's on_phi
11502 (region_model::update_for_phis): Pass phi to handle_phi.
11503 * region-model.h (region_model::handle_phi): Add phi param.
11504 (region_model_context::on_phi): New vfunc.
11505 (test_region_model_context::on_phi): New.
11506 * sm-malloc.cc (malloc_state_machine::on_phi): New.
11507 (malloc_state_machine::on_zero_assignment): New.
11508 * sm.h (state_machine::on_phi): New vfunc.
11510 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11512 * engine.cc (supernode_cluster::dump_dot): Show BB index as
11514 * supergraph.cc (supernode::dump_dot): Likewise.
11516 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11519 * region-model.cc (region_model::on_call_pre): Update for new
11520 param of symbolic_region ctor.
11521 (region_model::deref_rvalue): Likewise.
11522 (region_model::add_new_malloc_region): Likewise.
11523 (make_region_for_type): Likewise, preserving type.
11524 * region-model.h (symbolic_region::symbolic_region): Add "type"
11525 param and pass it to base class ctor.
11527 2020-02-03 David Malcolm <dmalcolm@redhat.com>
11530 * constraint-manager.cc
11531 (constraint_manager::get_or_add_equiv_class): Ensure types are
11532 compatible before comparing constants.
11534 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11537 * region-model.cc (make_region_for_type): Use VOID_TYPE_P rather
11538 than checking against void_type_node.
11540 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11543 * region-model.cc (ASSERT_COMPAT_TYPES): Convert to...
11544 (assert_compat_types): ...this, and bail when either type is NULL,
11545 or when VOID_TYPE_P (dst_type).
11546 (region_model::get_lvalue): Update for above conversion.
11547 (region_model::get_rvalue): Likewise.
11549 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11552 * region-model.cc (region_model::update_for_return_superedge):
11553 Move check for null result so that it also guards setting the
11556 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11559 * region-model.cc (stack_region::can_merge_p): Split into a two
11560 pass approach, creating all stack regions first, then populating
11562 (selftest::test_state_merging): Add test coverage for (a) the case
11563 of self-merging a model in which a local in an older stack frame
11564 points to a local in a more recent stack frame (which previously
11565 would ICE), and (b) the case of self-merging a model in which a
11566 local points to a global (which previously worked OK).
11568 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11570 * analyzer.cc (is_named_call_p): Replace tests for fndecl being
11571 extern at file scope and having a non-NULL DECL_NAME with a call
11572 to maybe_special_function_p.
11573 * function-set.cc (function_set::contains_decl_p): Add call to
11574 maybe_special_function_p.
11576 2020-01-31 David Malcolm <dmalcolm@redhat.com>
11579 * constraint-manager.cc
11580 (constraint_manager::get_or_add_equiv_class): Only compare constants
11581 if their types are compatible.
11582 * region-model.cc (constant_svalue::eval_condition): Replace check
11583 for identical types with call to types_compatible_p.
11585 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11587 * program-state.cc (extrinsic_state::dump_to_pp): New.
11588 (extrinsic_state::dump_to_file): New.
11589 (extrinsic_state::dump): New.
11590 * program-state.h (extrinsic_state::dump_to_pp): New decl.
11591 (extrinsic_state::dump_to_file): New decl.
11592 (extrinsic_state::dump): New decl.
11593 * sm.cc: Include "pretty-print.h".
11594 (state_machine::dump_to_pp): New.
11595 * sm.h (state_machine::dump_to_pp): New decl.
11597 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11599 * diagnostic-manager.cc (for_each_state_change): Use
11600 extrinsic_state::get_num_checkers rather than accessing m_checkers
11602 * program-state.cc (program_state::program_state): Likewise.
11603 * program-state.h (extrinsic_state::m_checkers): Make private.
11605 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11608 * region-model.cc (region_model::eval_condition): In both
11609 overloads, bail out immediately on floating-point types.
11610 (region_model::eval_condition_without_cm): Likewise.
11611 (region_model::add_constraint): Likewise.
11613 2020-01-30 David Malcolm <dmalcolm@redhat.com>
11616 * program-state.cc (sm_state_map::set_state): For the overload
11617 taking an svalue_id, bail out if the set_state on the ec does
11618 nothing. Convert the latter's return type from void to bool,
11619 returning true if anything changed.
11620 (sm_state_map::impl_set_state): Convert the return type from void
11621 to bool, returning true if the state changed.
11622 * program-state.h (sm_state_map::set_state): Convert return type
11624 (sm_state_map::impl_set_state): Likewise.
11625 * region-model.cc (constant_svalue::eval_condition): Only call
11626 fold_build2 if the types are the same.
11628 2020-01-29 Jakub Jelinek <jakub@redhat.com>
11630 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Remove.
11631 * constraint-manager.cc: Include diagnostic-core.h before graphviz.h.
11632 (range::dump, equiv_class::print): Don't use PUSH_IGNORE_WFORMAT or
11633 POP_IGNORE_WFORMAT.
11634 * state-purge.cc: Include diagnostic-core.h before
11635 gimple-pretty-print.h.
11636 (state_purge_annotator::add_node_annotations, print_vec_of_names):
11637 Don't use PUSH_IGNORE_WFORMAT or POP_IGNORE_WFORMAT.
11638 * region-model.cc: Move diagnostic-core.h include before graphviz.h.
11639 (path_var::dump, svalue::print, constant_svalue::print_details,
11640 region::dump_to_pp, region::dump_child_label, region::print_fields,
11641 map_region::print_fields, map_region::dump_dot_to_pp,
11642 map_region::dump_child_label, array_region::print_fields,
11643 array_region::dump_dot_to_pp): Don't use PUSH_IGNORE_WFORMAT or
11644 POP_IGNORE_WFORMAT.
11646 2020-01-28 David Malcolm <dmalcolm@redhat.com>
11649 * engine.cc (rewind_info_t::update_model): Get the longjmp call
11650 stmt via get_longjmp_call () rather than assuming it is the last
11651 stmt in the longjmp's supernode.
11652 (rewind_info_t::add_events_to_path): Get the location_t for the
11653 rewind_from_longjmp_event via get_longjmp_call () rather than from
11654 the supernode's get_end_location ().
11656 2020-01-28 David Malcolm <dmalcolm@redhat.com>
11658 * region-model.cc (poisoned_value_diagnostic::emit): Update for
11659 renaming of warning_at overload to warning_meta.
11660 * sm-file.cc (file_leak::emit): Likewise.
11661 * sm-malloc.cc (double_free::emit): Likewise.
11662 (possible_null_deref::emit): Likewise.
11663 (possible_null_arg::emit): Likewise.
11664 (null_deref::emit): Likewise.
11665 (null_arg::emit): Likewise.
11666 (use_after_free::emit): Likewise.
11667 (malloc_leak::emit): Likewise.
11668 (free_of_non_heap::emit): Likewise.
11669 * sm-sensitive.cc (exposure_through_output_file::emit): Likewise.
11670 * sm-signal.cc (signal_unsafe_call::emit): Likewise.
11671 * sm-taint.cc (tainted_array_index::emit): Likewise.
11673 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11676 * region-model.cc (tree_cmp): For the REAL_CST case, impose an
11677 arbitrary order on NaNs relative to other NaNs and to non-NaNs;
11678 const-correctness tweak.
11679 (ana::selftests::build_real_cst_from_string): New function.
11680 (ana::selftests::append_interesting_constants): New function.
11681 (ana::selftests::test_tree_cmp_on_constants): New test.
11682 (ana::selftests::test_canonicalization_4): New test.
11683 (ana::selftests::analyzer_region_model_cc_tests): Call the new
11686 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11689 * engine.cc (run_checkers): Save and restore input_location.
11691 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11693 * call-string.cc (call_string::cmp_1): Delete, moving body to...
11694 (call_string::cmp): ...here.
11695 * call-string.h (call_string::cmp_1): Delete decl.
11696 * engine.cc (worklist::key_t::cmp_1): Delete, moving body to...
11697 (worklist::key_t::cmp): ...here. Implement hash comparisons
11698 via comparison rather than subtraction to avoid overflow issues.
11699 * exploded-graph.h (worklist::key_t::cmp_1): Delete decl.
11700 * region-model.cc (tree_cmp): Eliminate buggy checking for
11703 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11705 * analyzer.cc (is_named_call_p): Check that fndecl is "extern"
11706 and at file scope. Potentially disregard prefix _ or __ in
11707 fndecl's name. Bail if the identifier is NULL.
11708 (is_setjmp_call_p): Expect a gcall rather than plain gimple.
11709 Remove special-case check for leading prefix, and also check for
11711 (is_longjmp_call_p): Also check for siglongjmp.
11712 (get_user_facing_name): New function.
11713 * analyzer.h (is_setjmp_call_p): Expect a gcall rather than plain
11715 (get_user_facing_name): New decl.
11716 * checker-path.cc (setjmp_event::get_desc): Use
11717 get_user_facing_name to avoid hardcoding the function name.
11718 (rewind_event::rewind_event): Add rewind_info param, using it to
11719 initialize new m_rewind_info field, and strengthen the assertion.
11720 (rewind_from_longjmp_event::get_desc): Use get_user_facing_name to
11721 avoid hardcoding the function name.
11722 (rewind_to_setjmp_event::get_desc): Likewise.
11723 * checker-path.h (setjmp_event::setjmp_event): Add setjmp_call
11724 param and use it to initialize...
11725 (setjmp_event::m_setjmp_call): New field.
11726 (rewind_event::rewind_event): Add rewind_info param.
11727 (rewind_event::m_rewind_info): New protected field.
11728 (rewind_from_longjmp_event::rewind_from_longjmp_event): Add
11730 (class rewind_to_setjmp_event): Move rewind_info field to parent
11732 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
11733 Update setjmp-handling for is_setjmp_call_p requiring a gcall;
11734 pass the call to the new setjmp_event.
11735 * engine.cc (exploded_node::on_stmt): Update for is_setjmp_call_p
11737 (stale_jmp_buf::emit): Use get_user_facing_name to avoid
11738 hardcoding the function names.
11739 (exploded_node::on_longjmp): Pass the longjmp_call when
11740 constructing rewind_info.
11741 (rewind_info_t::add_events_to_path): Pass the rewind_info_t to the
11742 rewind_from_longjmp_event's ctor.
11743 * exploded-graph.h (rewind_info_t::rewind_info_t): Add
11744 longjmp_call param.
11745 (rewind_info_t::get_longjmp_call): New.
11746 (rewind_info_t::m_longjmp_call): New.
11747 * region-model.cc (region_model::on_setjmp): Update comment to
11748 indicate this is also for sigsetjmp.
11749 * region-model.h (struct setjmp_record): Likewise.
11750 (class setjmp_svalue): Likewise.
11752 2020-01-27 David Malcolm <dmalcolm@redhat.com>
11755 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Guard these
11756 macros with GCC_VERSION >= 4006, making them no-op otherwise.
11757 * engine.cc (exploded_edge::exploded_edge): Specify template for
11758 base class initializer.
11759 (exploded_graph::add_edge): Specify template when chaining up to
11760 base class add_edge implementation.
11761 (viz_callgraph_node::dump_dot): Drop redundant "typename".
11762 (viz_callgraph_edge::viz_callgraph_edge): Specify template for
11763 base class initializer.
11764 * program-state.cc (sm_state_map::clone_with_remapping): Drop
11765 redundant "typename".
11766 (sm_state_map::print): Likewise.
11767 (sm_state_map::hash): Likewise.
11768 (sm_state_map::operator==): Likewise.
11769 (sm_state_map::remap_svalue_ids): Likewise.
11770 (sm_state_map::on_svalue_purge): Likewise.
11771 (sm_state_map::validate): Likewise.
11772 * program-state.h (sm_state_map::iterator_t): Likewise.
11773 * supergraph.h (superedge::superedge): Specify template for base
11776 2020-01-23 David Malcolm <dmalcolm@redhat.com>
11779 * supergraph.cc (callgraph_superedge::get_arg_for_parm): Fail
11780 gracefully is the number of parameters at the callee exceeds the
11781 number of arguments at the call stmt.
11782 (callgraph_superedge::get_parm_for_arg): Likewise.
11784 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11787 * program-state.cc (sm_state_map::on_svalue_purge): If the
11788 entry survives, but the origin is being purged, then reset the
11791 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11793 * sm-signal.cc: Fix nesting of CHECKING_P and namespace ana.
11795 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11798 * engine.cc (setjmp_svalue::compare_fields): Update for
11799 replacement of m_enode with m_setjmp_record.
11800 (setjmp_svalue::add_to_hash): Likewise.
11801 (setjmp_svalue::get_index): Rename...
11802 (setjmp_svalue::get_enode_index): ...to this.
11803 (setjmp_svalue::print_details): Update for replacement of m_enode
11804 with m_setjmp_record.
11805 (exploded_node::on_longjmp): Likewise.
11806 * exploded-graph.h (rewind_info_t::m_enode_origin): Replace...
11807 (rewind_info_t::m_setjmp_record): ...with this.
11808 (rewind_info_t::rewind_info_t): Update for replacement of m_enode
11809 with m_setjmp_record.
11810 (rewind_info_t::get_setjmp_point): Likewise.
11811 (rewind_info_t::get_setjmp_call): Likewise.
11812 * region-model.cc (region_model::dump_summary_of_map): Likewise.
11813 (region_model::on_setjmp): Likewise.
11814 * region-model.h (struct setjmp_record): New struct.
11815 (setjmp_svalue::m_enode): Replace...
11816 (setjmp_svalue::m_setjmp_record): ...with this.
11817 (setjmp_svalue::setjmp_svalue): Update for replacement of m_enode
11818 with m_setjmp_record.
11819 (setjmp_svalue::clone): Likewise.
11820 (setjmp_svalue::get_index): Rename...
11821 (setjmp_svalue::get_enode_index): ...to this.
11822 (setjmp_svalue::get_exploded_node): Replace...
11823 (setjmp_svalue::get_setjmp_record): ...with this.
11825 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11828 * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as
11831 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11834 * analysis-plan.h: Wrap everything namespace "ana".
11835 * analyzer-logging.cc: Likewise.
11836 * analyzer-logging.h: Likewise.
11837 * analyzer-pass.cc (pass_analyzer::execute): Update for "ana"
11839 * analyzer-selftests.cc: Wrap everything namespace "ana".
11840 * analyzer-selftests.h: Likewise.
11841 * analyzer.h: Likewise for forward decls of types.
11842 * call-string.h: Likewise.
11843 * checker-path.cc: Likewise.
11844 * checker-path.h: Likewise.
11845 * constraint-manager.cc: Likewise.
11846 * constraint-manager.h: Likewise.
11847 * diagnostic-manager.cc: Likewise.
11848 * diagnostic-manager.h: Likewise.
11849 * engine.cc: Likewise.
11850 * engine.h: Likewise.
11851 * exploded-graph.h: Likewise.
11852 * function-set.cc: Likewise.
11853 * function-set.h: Likewise.
11854 * pending-diagnostic.cc: Likewise.
11855 * pending-diagnostic.h: Likewise.
11856 * program-point.cc: Likewise.
11857 * program-point.h: Likewise.
11858 * program-state.cc: Likewise.
11859 * program-state.h: Likewise.
11860 * region-model.cc: Likewise.
11861 * region-model.h: Likewise.
11862 * sm-file.cc: Likewise.
11863 * sm-malloc.cc: Likewise.
11864 * sm-pattern-test.cc: Likewise.
11865 * sm-sensitive.cc: Likewise.
11866 * sm-signal.cc: Likewise.
11867 * sm-taint.cc: Likewise.
11870 * state-purge.h: Likewise.
11871 * supergraph.cc: Likewise.
11872 * supergraph.h: Likewise.
11874 2020-01-21 David Malcolm <dmalcolm@redhat.com>
11877 * region-model.cc (int_cmp): Rename to...
11878 (array_region::key_cmp): ...this, using key_t rather than int.
11879 Rewrite in terms of comparisons rather than subtraction to
11880 ensure qsort is anti-symmetric when handling extreme values.
11881 (array_region::walk_for_canonicalization): Update for above
11883 * region-model.h (array_region::key_cmp): New decl.
11885 2020-01-17 David Malcolm <dmalcolm@redhat.com>
11888 * region-model.cc (region_model::eval_condition_without_cm): Avoid
11889 gcc_unreachable for unexpected operations for the case where
11890 we're comparing an svalue against itself.
11892 2020-01-17 David Malcolm <dmalcolm@redhat.com>
11896 (region_model::convert_byte_offset_to_array_index): Convert to
11897 ssizetype before dividing by byte_size. Use fold_binary rather
11898 than fold_build2 to avoid needlessly constructing a tree for the
11901 2020-01-15 David Malcolm <dmalcolm@redhat.com>
11903 * engine.cc (class impl_region_model_context): Fix comment.
11905 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11908 * region-model.cc (make_region_for_type): Use
11909 FUNC_OR_METHOD_TYPE_P rather than comparing against FUNCTION_TYPE.
11910 * region-model.h (function_region::function_region): Likewise.
11912 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11914 * program-state.cc (sm_state_map::clone_with_remapping): Copy
11916 (selftest::test_program_state_merging_2): New selftest.
11917 (selftest::analyzer_program_state_cc_tests): Call it.
11919 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11921 * checker-path.h (checker_path::get_checker_event): New function.
11922 (checker_path): Add DISABLE_COPY_AND_ASSIGN; make fields private.
11923 * diagnostic-manager.cc
11924 (diagnostic_manager::prune_for_sm_diagnostic): Replace direct
11925 access to checker_path::m_events with accessor functions. Fix
11927 (diagnostic_manager::prune_interproc_events): Replace direct
11928 access to checker_path::m_events with accessor functions.
11929 (diagnostic_manager::finish_pruning): Likewise.
11931 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11933 * checker-path.h (checker_event::clone): Delete vfunc decl.
11934 (debug_event::clone): Delete vfunc impl.
11935 (custom_event::clone): Delete vfunc impl.
11936 (statement_event::clone): Delete vfunc impl.
11937 (function_entry_event::clone): Delete vfunc impl.
11938 (state_change_event::clone): Delete vfunc impl.
11939 (start_cfg_edge_event::clone): Delete vfunc impl.
11940 (end_cfg_edge_event::clone): Delete vfunc impl.
11941 (call_event::clone): Delete vfunc impl.
11942 (return_event::clone): Delete vfunc impl.
11943 (setjmp_event::clone): Delete vfunc impl.
11944 (rewind_from_longjmp_event::clone): Delete vfunc impl.
11945 (rewind_to_setjmp_event::clone): Delete vfunc impl.
11946 (warning_event::clone): Delete vfunc impl.
11948 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11950 * supergraph.cc (supernode::dump_dot): Ensure that the TABLE
11951 element has at least one TR.
11953 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11956 * engine.cc (leak_stmt_finder::find_stmt): Use get_pure_location
11957 when comparing against UNKNOWN_LOCATION.
11958 (stmt_requires_new_enode_p): Likewise.
11959 (exploded_graph::dump_exploded_nodes): Likewise.
11960 * supergraph.cc (supernode::get_start_location): Likewise.
11961 (supernode::get_end_location): Likewise.
11963 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11966 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11967 selftest::analyzer_sm_file_cc_tests.
11968 * analyzer-selftests.h (selftest::analyzer_sm_file_cc_tests): New
11970 * sm-file.cc: Include "analyzer/function-set.h" and
11971 "analyzer/analyzer-selftests.h".
11972 (get_file_using_fns): New function.
11973 (is_file_using_fn_p): New function.
11974 (fileptr_state_machine::on_stmt): Return true for known functions.
11975 (selftest::analyzer_sm_file_cc_tests): New function.
11977 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11979 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11980 selftest::analyzer_sm_signal_cc_tests.
11981 * analyzer-selftests.h (selftest::analyzer_sm_signal_cc_tests):
11983 * sm-signal.cc: Include "analyzer/function-set.h" and
11984 "analyzer/analyzer-selftests.h".
11985 (get_async_signal_unsafe_fns): New function.
11986 (signal_unsafe_p): Reimplement in terms of the above.
11987 (selftest::analyzer_sm_signal_cc_tests): New function.
11989 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11991 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11992 selftest::analyzer_function_set_cc_tests.
11993 * analyzer-selftests.h (selftest::analyzer_function_set_cc_tests):
11995 * function-set.cc: New file.
11996 * function-set.h: New file.
11998 2020-01-14 David Malcolm <dmalcolm@redhat.com>
12000 * analyzer.h (fndecl_has_gimple_body_p): New decl.
12001 * engine.cc (impl_region_model_context::on_unknown_change): New
12003 (fndecl_has_gimple_body_p): Make non-static.
12004 (exploded_node::on_stmt): Treat __analyzer_dump_exploded_nodes as
12005 known. Track whether we have a call with unknown side-effects and
12006 pass it to on_call_post.
12007 * exploded-graph.h (impl_region_model_context::on_unknown_change):
12009 * program-state.cc (sm_state_map::on_unknown_change): New function.
12010 * program-state.h (sm_state_map::on_unknown_change): New decl.
12011 * region-model.cc: Include "bitmap.h".
12012 (region_model::on_call_pre): Return a bool, capturing whether the
12013 call has unknown side effects.
12014 (region_model::on_call_post): Add arg "bool unknown_side_effects"
12015 and if true, call handle_unrecognized_call.
12016 (class reachable_regions): New class.
12017 (region_model::handle_unrecognized_call): New function.
12018 * region-model.h (region_model::on_call_pre): Return a bool.
12019 (region_model::on_call_post): Add arg "bool unknown_side_effects".
12020 (region_model::handle_unrecognized_call): New decl.
12021 (region_model_context::on_unknown_change): New vfunc.
12022 (test_region_model_context::on_unknown_change): New function.
12024 2020-01-14 David Malcolm <dmalcolm@redhat.com>
12026 * diagnostic-manager.cc (saved_diagnostic::operator==): Move here
12027 from header. Replace pointer equality test on m_var with call to
12028 pending_diagnostic::same_tree_p.
12029 * diagnostic-manager.h (saved_diagnostic::operator==): Move to
12030 diagnostic-manager.cc.
12031 * pending-diagnostic.cc (pending_diagnostic::same_tree_p): New.
12032 * pending-diagnostic.h (pending_diagnostic::same_tree_p): New.
12033 * sm-file.cc (file_diagnostic::subclass_equal_p): Replace pointer
12034 equality on m_arg with call to pending_diagnostic::same_tree_p.
12035 * sm-malloc.cc (malloc_diagnostic::subclass_equal_p): Likewise.
12036 (possible_null_arg::subclass_equal_p): Likewise.
12037 (null_arg::subclass_equal_p): Likewise.
12038 (free_of_non_heap::subclass_equal_p): Likewise.
12039 * sm-pattern-test.cc (pattern_match::operator==): Likewise.
12040 * sm-sensitive.cc (exposure_through_output_file::operator==):
12042 * sm-taint.cc (tainted_array_index::operator==): Likewise.
12044 2020-01-14 David Malcolm <dmalcolm@redhat.com>
12046 * diagnostic-manager.cc (dedupe_winners::add): Add logging
12047 of deduplication decisions made.
12049 2020-01-14 David Malcolm <dmalcolm@redhat.com>
12051 * ChangeLog: New file.
12052 * analyzer-selftests.cc: New file.
12053 * analyzer-selftests.h: New file.
12054 * analyzer.opt: New file.
12055 * analysis-plan.cc: New file.
12056 * analysis-plan.h: New file.
12057 * analyzer-logging.cc: New file.
12058 * analyzer-logging.h: New file.
12059 * analyzer-pass.cc: New file.
12060 * analyzer.cc: New file.
12061 * analyzer.h: New file.
12062 * call-string.cc: New file.
12063 * call-string.h: New file.
12064 * checker-path.cc: New file.
12065 * checker-path.h: New file.
12066 * constraint-manager.cc: New file.
12067 * constraint-manager.h: New file.
12068 * diagnostic-manager.cc: New file.
12069 * diagnostic-manager.h: New file.
12070 * engine.cc: New file.
12071 * engine.h: New file.
12072 * exploded-graph.h: New file.
12073 * pending-diagnostic.cc: New file.
12074 * pending-diagnostic.h: New file.
12075 * program-point.cc: New file.
12076 * program-point.h: New file.
12077 * program-state.cc: New file.
12078 * program-state.h: New file.
12079 * region-model.cc: New file.
12080 * region-model.h: New file.
12081 * sm-file.cc: New file.
12082 * sm-malloc.cc: New file.
12083 * sm-malloc.dot: New file.
12084 * sm-pattern-test.cc: New file.
12085 * sm-sensitive.cc: New file.
12086 * sm-signal.cc: New file.
12087 * sm-taint.cc: New file.
12090 * state-purge.cc: New file.
12091 * state-purge.h: New file.
12092 * supergraph.cc: New file.
12093 * supergraph.h: New file.
12095 2019-12-13 David Malcolm <dmalcolm@redhat.com>
12100 Copyright (C) 2019-2024 Free Software Foundation, Inc.
12102 Copying and distribution of this file, with or without modification,
12103 are permitted in any medium without royalty provided the copyright
12104 notice and this notice are preserved.