Daily bump.
[official-gcc.git] / gcc / analyzer / ChangeLog
blob7f200cf2071811d7d507576b78b990a913c8bd35
1 2024-04-10  David Malcolm  <dmalcolm@redhat.com>
3         PR analyzer/114472
4         * access-diagram.cc (bit_size_expr::maybe_get_formatted_str):
5         Reject attempts to print sizes that are too large.
6         * region.cc (region_offset::calc_symbolic_bit_offset): Use a
7         typeless svalue for the bit offset.
8         * store.cc (bit_range::intersects_p): Replace assertion with
9         test.
10         (bit_range::exceeds_p): Likewise.
11         (bit_range::falls_short_of_p): Likewise.
13 2024-04-10  David Malcolm  <dmalcolm@redhat.com>
15         * infinite-loop.cc: Include "diagnostic-format-sarif.h".
16         (infinite_loop::to_json): New.
17         (infinite_loop_diagnostic::maybe_add_sarif_properties): New.
19 2024-04-10  David Malcolm  <dmalcolm@redhat.com>
21         * infinite-recursion.cc: Include "diagnostic-format-sarif.h".
22         (infinite_recursion_diagnostic::maybe_add_sarif_properties): New.
24 2024-04-10  David Malcolm  <dmalcolm@redhat.com>
26         * call-details.cc: Include "diagnostic-format-sarif.h".
27         (overlapping_buffers::overlapping_buffers): Add params for new
28         fields.
29         (overlapping_buffers::maybe_add_sarif_properties): New.
30         (overlapping_buffers::m_byte_range_a): New field.
31         (overlapping_buffers::byte_range_b): New field.
32         (overlapping_buffers::m_num_bytes_read_sval): New field.
33         (call_details::complain_about_overlap): Pass new params to
34         overlapping_buffers ctor.
35         * ranges.cc (symbolic_byte_offset::to_json): New.
36         (symbolic_byte_range::to_json): New.
37         * ranges.h (symbolic_byte_offset::to_json): New decl.
38         (symbolic_byte_range::to_json): New decl.
40 2024-04-10  David Malcolm  <dmalcolm@redhat.com>
42         * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
43         Add "size_in_bytes" param.
44         (tainted_allocation_size::maybe_add_sarif_properties): New.
45         (tainted_allocation_size::m_size_in_bytes): New field.
46         (region_model::check_dynamic_size_for_taint): Pass size_in_bytes
47         to tainted_allocation_size ctor.
49 2024-04-09  Jakub Jelinek  <jakub@redhat.com>
51         * analyzer.opt (Wanalyzer-undefined-behavior-strtok): Fix duplicated
52         words; in in -> in.
53         * program-state.cc (sm_state_map::replay_call_summary): Fix duplicated
54         words in comment; to to -> to.
55         (program_state::replay_call_summary): Likewise.
56         * region-model.cc (region_model::replay_call_summary): Likewise.
58 2024-04-05  David Malcolm  <dmalcolm@redhat.com>
60         PR analyzer/114588
61         * access-diagram.cc (access_diagram_impl::access_diagram_impl):
62         Replace hardcoded colors for valid_style and invalid_style with
63         calls to text_art::get_style_from_color_cap_name.
65 2024-04-02  David Malcolm  <dmalcolm@redhat.com>
67         * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
68         Guard against null types.
69         * region-model.cc (apply_constraints_for_gswitch): Likewise.
71 2024-03-27  David Malcolm  <dmalcolm@redhat.com>
73         PR analyzer/114473
74         * call-summary.cc
75         (call_summary_replay::convert_svalue_from_summary): Assert that
76         the types match.
77         (call_summary_replay::convert_region_from_summary): Likewise.
78         (call_summary_replay::convert_region_from_summary_1): Add missing
79         cast for the deref of RK_SYMBOLIC case.
81 2024-03-23  David Malcolm  <dmalcolm@redhat.com>
83         PR analyzer/114408
84         * engine.cc (impl_run_checkers): Free up any dominance info that
85         we may have created.
86         * kf.cc (class kf_ubsan_handler): New.
87         (register_sanitizer_builtins): New.
88         (register_known_functions): Call register_sanitizer_builtins.
90 2024-03-22  David Malcolm  <dmalcolm@redhat.com>
92         PR analyzer/112974
93         PR analyzer/112975
94         * sm-taint.cc (taint_state_machine::on_condition): Strip away
95         casts before considering LHS and RHS, to increase the chance of
96         detecting places where sanitization of a value may have happened.
98 2024-03-22  David Malcolm  <dmalcolm@redhat.com>
100         * sm-taint.cc: Include "diagnostic-format-sarif.h".
101         (bounds_to_str): New.
102         (taint_diagnostic::maybe_add_sarif_properties): New.
103         (tainted_offset::tainted_offset): Add "offset" param.
104         (tainted_offset::maybe_add_sarif_properties): New.
105         (tainted_offset::m_offset): New.
106         (region_model::check_region_for_taint): Pass offset to
107         tainted_offset ctor.
109 2024-03-21  David Malcolm  <dmalcolm@redhat.com>
111         PR analyzer/113619
112         * region-model.cc (region_model::eval_condition): Fix
113         cast-handling from r14-3632-ge7b267444045c5 so that if those give
114         an unknown result, we continue trying the constraint manager.
116 2024-03-20  David Malcolm  <dmalcolm@redhat.com>
118         PR analyzer/109251
119         * sm-malloc.cc (deref_before_check::emit): Reject cases where the
120         check is in a loop header within a macro expansion.
121         (deref_before_check::loop_header_p): New.
123 2024-03-20  Jakub Jelinek  <jakub@redhat.com>
125         * constraint-manager.cc (test_range, test_constraint_conditions,
126         test_constant_comparisons, test_constraint_impl, test_purging,
127         test_bits): Use integer_zero_node instead of
128         build_zero_cst (integer_type_node) or
129         build_int_cst (integer_type_node, 0) and integer_one_node instead of
130         build_int_cst (integer_type_node, 1).
131         * region-model.cc (region_model::get_store_value,
132         append_interesting_constants, test_array_1,
133         test_get_representative_tree, test_unique_constants, test_assignment,
134         test_stack_frames, test_constraint_merging, test_widening_constraints,
135         test_iteration_1, test_array_2): Likewise.
137 2024-03-19  Jakub Jelinek  <jakub@redhat.com>
139         PR analyzer/113505
140         * region-model.cc (get_tree_for_byte_offset,
141         region_model::get_representative_path_var_1,
142         test_mem_ref, test_POINTER_PLUS_EXPR_then_MEM_REF): Use
143         char __attribute__((may_alias)) * as type of MEM_REF second argument.
145 2024-03-19  David Malcolm  <dmalcolm@redhat.com>
147         PR analyzer/114286
148         * kf.cc (class kf_atomic_exchange): Reimplement based on signature
149         seen in gimple, rather than user-facing signature.
150         (class kf_atomic_load): Likewise.
151         (class kf_atomic_store): New.
152         (register_atomic_builtins): Register kf_atomic_store.
154 2024-03-18  David Malcolm  <dmalcolm@redhat.com>
156         PR analyzer/110902
157         PR analyzer/110928
158         PR analyzer/111305
159         PR analyzer/111441
160         * access-diagram.cc: Include "analyzer/analyzer-selftests.h".
161         (get_access_size_str): Reimplement for conversion of
162         implmementation of bit_size_expr from tree to const svalue &.  Use
163         svalue::maybe_print_for_user rather than tree printing routines.
164         (remove_ssa_names): Make non-static.
165         (bit_size_expr::get_formatted_str): Rename to...
166         (bit_size_expr::maybe_get_formatted_str): ...this, adding "model"
167         param and converting return type to a unique_ptr.  Update for
168         conversion of implementation of bit_size_expr from tree to
169         const svalue &.  Use svalue::maybe_print_for_user rather than tree
170         printing routines.
171         (bit_size_expr::print): Rename to...
172         (bit_size_expr::maybe_print_for_user): ...this, adding "model"
173         param and converting return type to bool.  Update for
174         conversion of implementation of bit_size_expr from tree to
175         const svalue &.  Use svalue::maybe_print_for_user rather than tree
176         printing routines.
177         (bit_size_expr::maybe_get_as_bytes): Add "mgr" param and convert
178         return type from tree to const svalue *; reimplement.
179         (access_range::access_range): Call strip_types when on region_offset
180         intializations.
181         (access_range::get_size): Update for conversion of implementation
182         of bit_size_expr from tree to const svalue &.
183         (access_operation::get_valid_bits): Pass manager to access_range
184         ctor.
185         (access_operation::maybe_get_invalid_before_bits): Likewise.
186         (access_operation::maybe_get_invalid_after_bits): Likewise.
187         (boundaries::add): Likewise.
188         (bit_to_table_map::populate): Add "mgr" param and pass it to
189         access_range ctor.
190         (access_diagram_impl::access_diagram_impl): Pass manager to
191         bit_to_table_map::populate.
192         (access_diagram_impl::maybe_add_gap): Use svalue rather than tree
193         for symbolic bit offsets.  Port to new bit_size_expr
194         representation.
195         (access_diagram_impl::add_valid_vs_invalid_ruler): Port to new
196         bit_size_expr representation.
197         (selftest::assert_eq_typeless_integer): New.
198         (ASSERT_EQ_TYPELESS_INTEGER): New.
199         (selftest::test_bit_size_expr_to_bytes): New.
200         (selftest::analyzer_access_diagram_cc_tests): New.
201         * access-diagram.h (class bit_size_expr): Reimplement, converting
202         implementation from tree to const svalue &.
203         (access_range::access_range): Add "mgr" param.  Call strip_types
204         on region_offset initializations.
205         (access_range::get_size): Update decl for reimplementation.
206         * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
207         selftest::analyzer_access_diagram_cc_tests.
208         * analyzer-selftests.h
209         (selftest::analyzer_checker_script_cc_tests): Delete this stray
210         typo.
211         (selftest::analyzer_access_diagram_cc_tests): New decl.
212         * analyzer.h (print_expr_for_user): New decl.
213         (calc_symbolic_bit_offset): Update decl for reimplementation.
214         (strip_types): New decls.
215         (remove_ssa_names): New decl.
216         * bounds-checking.cc (strip_types): New.
217         (region_model::check_symbolic_bounds): Use typeless svalues.
218         * region-model-manager.cc
219         (region_model_manager::get_or_create_constant_svalue): Add "type"
220         param.  Add overload with old signature.
221         (region_model_manager::get_or_create_int_cst): Support type being
222         NULL_TREE.
223         (region_model_manager::maybe_fold_unaryop): Gracefully reject folding
224         of casts to NULL_TREE type.
225         (get_code_for_cast): Use NOP_EXPR for "casting" svalues to
226         NULL_TREE type.
227         (region_model_manager::get_or_create_cast): Support "casting"
228         svalues to NULL_TREE type.
229         (region_model_manager::maybe_fold_binop): Don't crash on inputs
230         with NULL_TREE type.  Handle folding of binops on constants with
231         NULL_TREE type.  Add missing cast from PR analyzer/110902.
232         Support enough folding of other ops on NULL_TREE type to support
233         bounds checking.
234         (region_model_manager::get_or_create_const_fn_result_svalue):
235         Remove assertion that type is nonnull.
236         * region-model-manager.h
237         (region_model_manager::get_or_create_constant_svalue): Add
238         overloaded decl taking a type.
239         (region_model_manager::maybe_fold_binop): Make public.
240         (region_model_manager::constants_map_t): Use
241         constant_svalue::key_t for the key, rather than just tree.
242         * region-model.cc (print_expr_for_user): New.
243         (selftest::test_array_2): Handle casts.
244         * region.cc (region_offset::calc_symbolic_bit_offset): Return
245         const svalue & rather than tree, and reimplement accordingly.
246         (region::calc_offset): Use ptrdiff_type_node for types of byte
247         offsets.
248         (region::maybe_print_for_user): New.
249         (element_region::get_relative_symbolic_offset): Use NULL_TREE for
250         types of bit offsets.
251         (offset_region::get_bit_offset): Likewise.
252         (sized_region::get_bit_size_sval): Likewise for bit sizes.
253         * region.h (region::maybe_print_for_user): New decl.
254         * svalue.cc (class auto_add_parens): New.
255         (svalue::maybe_print_for_user): New.
256         (svalue::cmp_ptr): Support typeless constant svalues.
257         (tristate_from_boolean_tree_node): New, taken from...
258         (constant_svalue::eval_condition): ...here.  Handle comparison of
259         typeless integer svalue constants.
260         * svalue.h (svalue::maybe_print_for_user): New decl.
261         (class constant_svalue): Support the type of the svalue being
262         NULL_TREE.
263         (struct default_hash_traits<constant_svalue::key_t>): New.
265 2024-03-18  David Malcolm  <dmalcolm@redhat.com>
267         * access-diagram.cc (remove_ssa_names): Support operands being
268         NULL_TREE, such as e.g. for COMPONENT_REF's operand 2.
270 2024-03-07  Jakub Jelinek  <jakub@redhat.com>
272         * access-diagram.cc: Include diagnostic-core.h before including
273         diagnostic.h or diagnostic-path.h.
274         * sm-malloc.cc: Likewise.
275         * diagnostic-manager.cc: Likewise.
276         * call-summary.cc: Likewise.
277         * record-layout.cc: Likewise.
279 2024-02-29  David Malcolm  <dmalcolm@redhat.com>
281         PR analyzer/114159
282         * analyzer.cc: Include "tree-dfa.h".
283         (get_ssa_default_def): New decl.
284         * analyzer.h (get_ssa_default_def): New.
285         * call-info.cc (call_info::call_info): New ctor taking an explicit
286         called_fn.
287         * call-info.h (call_info::call_info): Likewise.
288         * call-summary.cc (call_summary_replay::call_summary_replay):
289         Convert param from function * to const function &.
290         * call-summary.h (call_summary_replay::call_summary_replay):
291         Likewise.
292         * checker-event.h (state_change_event::get_dest_function):
293         Constify return value.
294         * engine.cc (point_and_state::validate): Update for conversion to
295         const function &.
296         (exploded_node::on_stmt): Likewise.
297         (call_summary_edge_info::call_summary_edge_info): Likewise.
298         Pass in called_fn to call_info ctor.
299         (exploded_node::replay_call_summaries): Update for conversion to
300         const function &.  Convert per_function_data from * to &.
301         (exploded_node::replay_call_summary): Update for conversion to
302         const function &.
303         (exploded_graph::add_function_entry): Likewise.
304         (toplevel_function_p): Likewise.
305         (add_tainted_args_callback): Likewise.
306         (exploded_graph::build_initial_worklist): Likewise.
307         (exploded_graph::maybe_create_dynamic_call): Likewise.
308         (maybe_update_for_edge): Likewise.
309         (exploded_graph::on_escaped_function): Likewise.
310         * exploded-graph.h (exploded_node::replay_call_summaries):
311         Likewise.
312         (exploded_node::replay_call_summary): Likewise.
313         (exploded_graph::add_function_entry): Likewise.
314         * program-point.cc (function_point::from_function_entry):
315         Likewise.
316         (program_point::from_function_entry): Likewise.
317         * program-point.h (function_point::from_function_entry): Likewise.
318         (program_point::from_function_entry): Likewise.
319         * program-state.cc (program_state::push_frame): Likewise.
320         (program_state::get_current_function): Constify return type.
321         * program-state.h (program_state::push_frame): Update for
322         conversion to const function &.
323         (program_state::get_current_function): Likewise.
324         * region-model-manager.cc
325         (region_model_manager::get_frame_region): Likewise.
326         * region-model-manager.h
327         (region_model_manager::get_frame_region): Likewise.
328         * region-model.cc (region_model::called_from_main_p): Likewise.
329         (region_model::update_for_gcall): Likewise.
330         (region_model::push_frame): Likewise.
331         (region_model::get_current_function): Constify return type.
332         (region_model::pop_frame): Update for conversion to
333         const function &.
334         (selftest::test_stack_frames): Likewise.
335         (selftest::test_get_representative_path_var): Likewise.
336         (selftest::test_state_merging): Likewise.
337         (selftest::test_alloca): Likewise.
338         * region-model.h (region_model::push_frame): Likewise.
339         (region_model::get_current_function): Likewise.
340         * region.cc (frame_region::dump_to_pp): Likewise.
341         (frame_region::get_region_for_local): Likewise.
342         * region.h (class frame_region): Likewise.
343         * sm-signal.cc (signal_unsafe_call::describe_state_change):
344         Likewise.
345         (update_model_for_signal_handler): Likewise.
346         (signal_delivery_edge_info_t::update_model): Likewise.
347         (register_signal_handler::impl_transition): Likewise.
348         * state-purge.cc (class gimple_op_visitor): Likewise.
349         (state_purge_map::state_purge_map): Likewise.
350         (state_purge_map::get_or_create_data_for_decl): Likewise.
351         (state_purge_per_ssa_name::state_purge_per_ssa_name): Likewise.
352         (state_purge_per_ssa_name::add_to_worklist): Likewise.
353         (state_purge_per_ssa_name::process_point): Likewise.
354         (state_purge_per_decl::add_to_worklist): Likewise.
355         (state_purge_annotator::print_needed): Likewise.
356         * state-purge.h
357         (state_purge_map::get_or_create_data_for_decl): Likewise.
358         (class state_purge_per_tree): Likewise.
359         (class state_purge_per_ssa_name): Likewise.
360         (class state_purge_per_decl): Likewise.
361         * supergraph.cc (supergraph::dump_dot_to_pp): Likewise.
362         * supergraph.h
363         (supergraph::get_node_for_function_entry): Likewise.
364         (supergraph::get_node_for_function_exit): Likewise.
366 2024-02-27  David Malcolm  <dmalcolm@redhat.com>
368         PR analyzer/110483
369         PR analyzer/111802
370         * access-diagram.cc
371         (string_literal_spatial_item::add_column_for_byte): Use %wu for
372         printing unsigned HOST_WIDE_INT.
374 2024-02-27  David Malcolm  <dmalcolm@redhat.com>
376         PR analyzer/111881
377         * constraint-manager.cc (bound::ensure_closed): Assert that
378         m_constant has integral type.
379         (range::add_bound): Bail out on floating point constants.
381 2024-02-21  David Malcolm  <dmalcolm@redhat.com>
383         PR analyzer/113999
384         * analyzer.h (get_string_cst_size): New decl.
385         * region-model-manager.cc (get_string_cst_size): New.
386         (region_model_manager::maybe_get_char_from_string_cst): Treat
387         single-byte accesses within string_cst but beyond
388         TREE_STRING_LENGTH as being 0.
389         * region-model.cc (string_cst_has_null_terminator): Likewise.
391 2024-02-21  David Malcolm  <dmalcolm@redhat.com>
393         PR analyzer/113998
394         * ranges.cc (symbolic_byte_range::intersection): Handle empty ranges.
395         (selftest::test_intersects): Add test coverage for empty ranges.
397 2024-02-19  David Malcolm  <dmalcolm@redhat.com>
399         PR analyzer/111289
400         * varargs.cc (representable_in_integral_type_p): New.
401         (va_arg_compatible_types_p): Add "arg_sval" param.  Handle integer
402         types.
403         (kf_va_arg::impl_call_pre): Pass arg_sval to
404         va_arg_compatible_types_p.
406 2024-02-19  Andrew Pinski  <quic_apinski@quicinc.com>
408         PR analyzer/113983
409         * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Reject
410         non integral types.
412 2024-02-15  David Malcolm  <dmalcolm@redhat.com>
414         PR analyzer/111266
415         * region.cc (offset_region::get_byte_size_sval): Delete.
416         (offset_region::get_bit_size_sval): Delete.
417         * region.h (region::get_byte_size): Add comment clarifying that
418         this relates to the size of the access, rather than the size
419         that's valid to access.
420         (region::get_bit_size): Likewise.
421         (region::get_byte_size_sval): Likewise.
422         (region::get_bit_size_sval): Likewise.
423         (offset_region::get_byte_size_sval): Delete.
424         (offset_region::get_bit_size_sval): Delete.
426 2024-02-13  David Malcolm  <dmalcolm@redhat.com>
428         * pending-diagnostic.cc (diagnostic_emission_context::warn):
429         Update for renaming of emit_diagnostic_valist overload to
430         emit_diagnostic_valist_meta.
431         (diagnostic_emission_context::inform): Likewise.
433 2024-01-31  David Malcolm  <dmalcolm@redhat.com>
435         PR analyzer/113253
436         * region-model.cc (region_model::on_stmt_pre): Add gcc_unreachable
437         for debug statements.
438         * state-purge.cc
439         (state_purge_per_ssa_name::state_purge_per_ssa_name): Skip any
440         debug stmts in the FOR_EACH_IMM_USE_FAST list.
441         * supergraph.cc (supergraph::supergraph): Don't add debug stmts
442         to the supernodes.
444 2024-01-31  David Malcolm  <dmalcolm@redhat.com>
446         PR analyzer/113509
447         * checker-event.cc (state_change_event::get_desc): Don't assume
448         "var" is non-NULL.
450 2024-01-30  David Malcolm  <dmalcolm@redhat.com>
452         PR analyzer/113654
453         * region-model.cc (is_round_up): New.
454         (is_multiple_p): New.
455         (is_dubious_capacity): New.
456         (region_model::check_region_size): Move usage of size_visitor into
457         is_dubious_capacity.
459 2024-01-30  David Malcolm  <dmalcolm@redhat.com>
461         * region-model.cc
462         (dubious_allocation_size::dubious_allocation_size): Add
463         "capacity_sval" param.  Drop unused ctor.
464         (dubious_allocation_size::maybe_add_sarif_properties): New.
465         (dubious_allocation_size::m_capacity_sval): New field.
466         (region_model::check_region_size): Pass capacity svalue to
467         dubious_allocation_size ctor.
469 2024-01-25  David Malcolm  <dmalcolm@redhat.com>
471         PR analyzer/112969
472         * store.cc (binding_cluster::maybe_get_compound_binding): When
473         populating default_map, express the bit-range of the default key
474         for REG relative to REG, rather than to the base region.
476 2024-01-24  David Malcolm  <dmalcolm@redhat.com>
478         PR analyzer/112977
479         * engine.cc (impl_region_model_context::on_liveness_change): Pass
480         m_ext_state to sm_state_map::on_liveness_change.
481         * program-state.cc (sm_state_map::on_svalue_leak): Guard removal
482         of map entry based on can_purge_p.
483         (sm_state_map::on_liveness_change): Add ext_state param.  Add
484         workaround for bad interaction between state purging and
485         alt-inherited sm-state.
486         * program-state.h (sm_state_map::on_liveness_change): Add
487         ext_state param.
488         * sm-taint.cc
489         (taint_state_machine::has_alt_get_inherited_state_p): New.
490         (taint_state_machine::can_purge_p): Return false for "has_lb" and
491         "has_ub".
492         * sm.h (state_machine::has_alt_get_inherited_state_p): New vfunc.
494 2024-01-18  David Malcolm  <dmalcolm@redhat.com>
496         PR analyzer/111361
497         * region-model.cc (svalue_byte_range_has_null_terminator_1): The
498         initial byte of an all-zeroes SVAL is a zero byte.  Remove
499         gcc_unreachable from SK_CONSTANT for constants that aren't
500         STRING_CST or INTEGER_CST.
502 2024-01-18  David Malcolm  <dmalcolm@redhat.com>
504         PR analyzer/112811
505         * region-model.cc (fragment::dump_to_pp): New.
506         (fragment::has_null_terminator): Convert to...
507         (svalue_byte_range_has_null_terminator_1): ...this new function,
508         updating to use a byte_range relative to the start of the svalue.
509         (svalue_byte_range_has_null_terminator): New.
510         (fragment::string_cst_has_null_terminator): Convert to...
511         (string_cst_has_null_terminator): ...this, updating to use a
512         byte_range relative to the start of the svalue.
513         (iterable_cluster::dump_to_pp): New.
514         (region_model::scan_for_null_terminator): Add logging, moving body
515         to...
516         (region_model::scan_for_null_terminator_1): ...this new function,
517         adding more logging, and updating to use
518         svalue_byte_range_has_null_terminator.
519         * region-model.h (region_model::scan_for_null_terminator_1): New
520         decl.
522 2024-01-16  David Malcolm  <dmalcolm@redhat.com>
524         PR analyzer/106229
525         * analyzer.h (compare_constants): New decl.
526         * constraint-manager.cc (compare_constants): Make non-static.
527         * sm-taint.cc: Add include "fold-const.h".
528         (class concrete_range): New.
529         (get_possible_range): New.
530         (index_can_be_out_of_bounds_p): New.
531         (region_model::check_region_for_taint): Reject
532         -Wanalyzer-tainted-array-index if the type of the value makes it
533         impossible for it to be out-of-bounds of the array.
535 2024-01-16  David Malcolm  <dmalcolm@redhat.com>
537         PR analyzer/113333
538         * region-model-manager.cc
539         (region_model_manager::maybe_fold_unaryop): Casting all zeroes
540         should give all zeroes.
542 2024-01-04  David Malcolm  <dmalcolm@redhat.com>
544         * analyzer.opt.urls: New file, autogenerated by
545         regenerate-opt-urls.py.
547 2024-01-04  David Malcolm  <dmalcolm@redhat.com>
549         * checker-event.cc: Include "diagnostic-format-sarif.h" and
550         "tree-logical-location.h".
551         (checker_event::maybe_add_sarif_properties): New.
552         (superedge_event::maybe_add_sarif_properties): New.
553         (superedge_event::superedge_event): Add comment.
554         * checker-event.h (checker_event::maybe_add_sarif_properties): New
555         decl.
556         (superedge_event::maybe_add_sarif_properties): New decl.
558 2024-01-04  David Malcolm  <dmalcolm@redhat.com>
560         PR analyzer/112790
561         * checker-event.cc (class inlining_info): Move to...
562         * inlining-iterator.h (class inlining_info): ...here.
563         * sm-malloc.cc: Include "analyzer/inlining-iterator.h".
564         (maybe_complain_about_deref_before_check): Reject stmts that were
565         inlined from another function.
567 2024-01-04  David Malcolm  <dmalcolm@redhat.com>
569         PR analyzer/113222
570         * access-diagram.cc (valid_region_spatial_item::add_boundaries):
571         Handle TYPE_DOMAIN being null.
572         (valid_region_spatial_item::add_array_elements_to_table):
573         Likewise.
575 2023-12-16  David Malcolm  <dmalcolm@redhat.com>
577         * analyzer.cc: Include "tree-pretty-print.h" and
578         "diagnostic-event-id.h".
579         (tree_to_json): New.
580         (diagnostic_event_id_to_json): New.
581         (bit_offset_to_json): New.
582         (byte_offset_to_json): New.
583         * analyzer.h (tree_to_json): New decl.
584         (diagnostic_event_id_to_json): New decl.
585         (bit_offset_to_json): New decl.
586         (byte_offset_to_json): New decl.
587         * bounds-checking.cc: Include "diagnostic-format-sarif.h".
588         (out_of_bounds::maybe_add_sarif_properties): New.
589         (concrete_out_of_bounds::maybe_add_sarif_properties): New.
590         (concrete_past_the_end::maybe_add_sarif_properties): New.
591         (symbolic_past_the_end::maybe_add_sarif_properties): New.
592         * region-model.cc (region_to_value_map::to_json): New.
593         (region_model::to_json): New.
594         * region-model.h (region_to_value_map::to_json): New decl.
595         (region_model::to_json): New decl.
596         * store.cc (bit_range::to_json): New.
597         (byte_range::to_json): New.
598         * store.h (bit_range::to_json): New decl.
599         (byte_range::to_json): New decl.
601 2023-12-16  David Malcolm  <dmalcolm@redhat.com>
603         PR analyzer/112792
604         * bounds-checking.cc
605         (out_of_bounds::oob_region_creation_event_capacity): Rename
606         "capacity" to "byte_capacity".  Layout fix.
607         (out_of_bounds::::add_region_creation_events): Rename
608         "capacity" to "byte_capacity".
609         (class concrete_out_of_bounds): Rename m_out_of_bounds_range to
610         m_out_of_bounds_bits and convert from a byte_range to a bit_range.
611         (concrete_out_of_bounds::get_out_of_bounds_bytes): New.
612         (concrete_past_the_end::concrete_past_the_end): Rename param
613         "byte_bound" to "bit_bound".  Initialize m_byte_bound.
614         (concrete_past_the_end::subclass_equal_p): Update for renaming
615         of m_byte_bound to m_bit_bound.
616         (concrete_past_the_end::m_bit_bound): New field.
617         (concrete_buffer_overflow::concrete_buffer_overflow): Convert
618         param "range" from byte_range to bit_range.  Rename param
619         "byte_bound" to "bit_bound".
620         (concrete_buffer_overflow::emit): Update for bits vs bytes.
621         (concrete_buffer_overflow::describe_final_event): Split
622         into...
623         (concrete_buffer_overflow::describe_final_event_as_bytes): ...this
624         (concrete_buffer_overflow::describe_final_event_as_bits): ...and
625         this.
626         (concrete_buffer_over_read::concrete_buffer_over_read): Convert
627         param "range" from byte_range to bit_range.  Rename param
628         "byte_bound" to "bit_bound".
629         (concrete_buffer_over_read::emit): Update for bits vs bytes.
630         (concrete_buffer_over_read::describe_final_event): Split into...
631         (concrete_buffer_over_read::describe_final_event_as_bytes):
632         ...this
633         (concrete_buffer_over_read::describe_final_event_as_bits): ...and
634         this.
635         (concrete_buffer_underwrite::concrete_buffer_underwrite): Convert
636         param "range" from byte_range to bit_range.
637         (concrete_buffer_underwrite::describe_final_event): Split into...
638         (concrete_buffer_underwrite::describe_final_event_as_bytes):
639         ...this
640         (concrete_buffer_underwrite::describe_final_event_as_bits): ...and
641         this.
642         (concrete_buffer_under_read::concrete_buffer_under_read): Convert
643         param "range" from byte_range to bit_range.
644         (concrete_buffer_under_read::describe_final_event): Split into...
645         (concrete_buffer_under_read::describe_final_event_as_bytes):
646         ...this
647         (concrete_buffer_under_read::describe_final_event_as_bits): ...and
648         this.
649         (region_model::check_region_bounds): Use bits for concrete values,
650         and rename locals to indicate whether we're dealing with bits or
651         bytes.  Specifically, replace "num_bytes_sval" with
652         "num_bits_sval", and get it from reg's "get_bit_size_sval".
653         Replace "num_bytes_tree" with "num_bits_tree".  Rename "capacity"
654         to "byte_capacity".  Rename "cst_capacity_tree" to
655         "cst_byte_capacity_tree".  Replace "offset" and
656         "num_bytes_unsigned" with "bit_offset" and "num_bits_unsigned"
657         respectively, converting from byte_offset_t to bit_offset_t.
658         Replace "out" and "read_bytes" with "bits_outside" and "read_bits"
659         respectively, converting from byte_range to bit_range.  Convert
660         "buffer" from byte_range to bit_range.  Replace "byte_bound" with
661         "bit_bound".
662         * region.cc (region::get_bit_size_sval): New.
663         (offset_region::get_bit_offset): New.
664         (offset_region::get_bit_size_sval): New.
665         (sized_region::get_bit_size_sval): New.
666         (bit_range_region::get_bit_size_sval): New.
667         * region.h (region::get_bit_size_sval): New vfunc.
668         (offset_region::get_bit_offset): New decl.
669         (offset_region::get_bit_size_sval): New decl.
670         (sized_region::get_bit_size_sval): New decl.
671         (bit_range_region::get_bit_size_sval): New decl.
672         * store.cc (bit_range::intersects_p): New, based on
673         byte_range::intersects_p.
674         (bit_range::exceeds_p): New, based on byte_range::exceeds_p.
675         (bit_range::falls_short_of_p): New, based on
676         byte_range::falls_short_of_p.
677         (byte_range::intersects_p): Delete.
678         (byte_range::exceeds_p): Delete.
679         (byte_range::falls_short_of_p): Delete.
680         * store.h (bit_range::intersects_p): New overload.
681         (bit_range::exceeds_p): New.
682         (bit_range::falls_short_of_p): New.
683         (byte_range::intersects_p): Delete.
684         (byte_range::exceeds_p): Delete.
685         (byte_range::falls_short_of_p): Delete.
687 2023-12-14  David Malcolm  <dmalcolm@redhat.com>
689         PR analyzer/112655
690         * infinite-loop.cc (infinite_loop::infinite_loop): Pass eedges
691         via rvalue reference rather than by value.
692         (starts_infinite_loop_p): Move eedges when constructing an
693         infinite_loop instance.
694         * sm-file.cc (fileptr_state_machine::fileptr_state_machine): Use
695         initializer list for states.
696         * sm-sensitive.cc
697         (sensitive_state_machine::sensitive_state_machine): Likewise.
698         * sm-signal.cc (signal_state_machine::signal_state_machine):
699         Likewise.
700         * sm-taint.cc (taint_state_machine::taint_state_machine):
701         Likewise.
702         * varargs.cc (va_list_state_machine::va_list_state_machine): Likewise.
704 2023-12-11  David Malcolm  <dmalcolm@redhat.com>
706         PR analyzer/112955
707         * engine.cc (feasibility_state::feasibility_state): Initialize
708         m_snodes_visited.
710 2023-12-11  Andrew Pinski  <apinski@marvell.com>
712         * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Remove
713         the check for type being unsigned_char_type_node.
715 2023-12-08  David Malcolm  <dmalcolm@redhat.com>
717         * sm-taint.cc (taint_state_machine::alt_get_inherited_state): Fix
718         handling of TRUNC_MOD_EXPR.
720 2023-12-08  David Malcolm  <dmalcolm@redhat.com>
722         * region-model.cc (contains_uninit_p): Only check for
723         svalues that the infoleak warning can handle.
725 2023-12-08  David Malcolm  <dmalcolm@redhat.com>
727         PR analyzer/112889
728         * store.h (concrete_binding::concrete_binding): Strengthen
729         assertion to require size to be be positive, rather than just
730         non-zero.
731         (concrete_binding::mark_deleted): Use size rather than start bit
732         offset.
733         (concrete_binding::mark_empty): Likewise.
734         (concrete_binding::is_deleted): Likewise.
735         (concrete_binding::is_empty): Likewise.
737 2023-12-07  Alexandre Oliva  <oliva@adacore.com>
739         * region-model.cc (has_nondefault_case_for_value_p): Take
740         enumerate type as a parameter.
741         (region_model::apply_constraints_for_gswitch): Cope with
742         integral promotion type casts.
744 2023-12-07  David Malcolm  <dmalcolm@redhat.com>
746         PR analyzer/103546
747         PR analyzer/112850
748         * analyzer.opt (-param=analyzer-max-svalue-depth=): Increase from
749         12 to 18.
750         (Wanalyzer-symbol-too-complex): New.
751         * diagnostic-manager.cc
752         (null_assignment_sm_context::clear_all_per_svalue_state): New.
753         * engine.cc (impl_sm_context::clear_all_per_svalue_state): New.
754         * program-state.cc (sm_state_map::clear_all_per_svalue_state):
755         New.
756         * program-state.h (sm_state_map::clear_all_per_svalue_state): New
757         decl.
758         * region-model-manager.cc
759         (region_model_manager::reject_if_too_complex): Add
760         -Wanalyzer-symbol-too-complex.
761         * sm-taint.cc (taint_state_machine::on_condition): Handle
762         comparisons against UNKNOWN.
763         * sm.h (sm_context::clear_all_per_svalue_state): New.
765 2023-12-06  David Malcolm  <dmalcolm@redhat.com>
767         * engine.cc (dump_analyzer_json): Use
768         flag_diagnostics_json_formatting.
770 2023-12-01  David Malcolm  <dmalcolm@redhat.com>
772         * analyzer.h (class saved_diagnostic): New forward decl.
773         * bounds-checking.cc: Update for changes to
774         pending_diagnostic::emit.
775         * call-details.cc: Likewise.
776         * diagnostic-manager.cc: Include "diagnostic-format-sarif.h".
777         (saved_diagnostic::maybe_add_sarif_properties): New.
778         (class pending_diagnostic_metadata): New.
779         (diagnostic_manager::emit_saved_diagnostic): Create a
780         pending_diagnostic_metadata and a diagnostic_emission_context.
781         Pass the latter to the pending_diagnostic::emit vfunc.
782         * diagnostic-manager.h
783         (saved_diagnostic::maybe_add_sarif_properties): New decl.
784         * engine.cc: Update for changes to pending_diagnostic::emit.
785         * infinite-loop.cc: Likewise.
786         * infinite-recursion.cc: Likewise.
787         * kf-analyzer.cc: Likewise.
788         * kf.cc: Likewise.
789         * pending-diagnostic.cc
790         (diagnostic_emission_context::get_pending_diagnostic): New.
791         (diagnostic_emission_context::warn): New.
792         (diagnostic_emission_context::inform): New.
793         * pending-diagnostic.h (class diagnostic_emission_context): New.
794         (pending_diagnostic::emit): Update params.
795         (pending_diagnostic::maybe_add_sarif_properties): New vfunc.
796         * region.cc: Don't include "diagnostic-metadata.h".
797         * region-model.cc: Include "diagnostic-format-sarif.h".  Update
798         for changes to pending_diagnostic::emit.
799         (exposure_through_uninit_copy::maybe_add_sarif_properties): New.
800         * sm-fd.cc: Update for changes to pending_diagnostic::emit.
801         * sm-file.cc: Likewise.
802         * sm-malloc.cc: Likewise.
803         * sm-pattern-test.cc: Likewise.
804         * sm-sensitive.cc: Likewise.
805         * sm-signal.cc: Likewise.
806         * sm-taint.cc: Likewise.
807         * store.cc: Don't include "diagnostic-metadata.h".
808         * varargs.cc: Update for changes to pending_diagnostic::emit.
810 2023-11-19  David Malcolm  <dmalcolm@redhat.com>
812         * analyzer.h: Include "rich-location.h".
814 2023-11-19  David Malcolm  <dmalcolm@redhat.com>
816         PR analyzer/107573
817         * analyzer.h (register_known_functions): Add region_model_manager
818         param.
819         * analyzer.opt (Wanalyzer-undefined-behavior-strtok): New.
820         * call-summary.cc
821         (call_summary_replay::convert_region_from_summary_1): Handle
822         RK_PRIVATE.
823         * engine.cc (impl_run_checkers): Pass model manager to
824         register_known_functions.
825         * kf.cc (class undefined_function_behavior): New.
826         (class kf_strtok): New.
827         (register_known_functions): Add region_model_manager param.
828         Use it to register "strtok".
829         * region-model-manager.cc
830         (region_model_manager::get_or_create_conjured_svalue): Add "idx"
831         param.
832         * region-model-manager.h
833         (region_model_manager::get_or_create_conjured_svalue): Add "idx"
834         param.
835         (region_model_manager::get_root_region): New accessor.
836         * region-model.cc (region_model::scan_for_null_terminator): Handle
837         "expr" being null.
838         (region_model::get_representative_path_var_1): Handle RK_PRIVATE.
839         * region-model.h (region_model::called_from_main_p): Make public.
840         * region.cc (region::get_memory_space): Handle RK_PRIVATE.
841         (region::can_have_initial_svalue_p): Handle MEMSPACE_PRIVATE.
842         (private_region::dump_to_pp): New.
843         * region.h (MEMSPACE_PRIVATE): New.
844         (RK_PRIVATE): New.
845         (class private_region): New.
846         (is_a_helper <const private_region *>::test): New.
847         * store.cc (store::replay_call_summary_cluster): Handle
848         RK_PRIVATE.
849         * svalue.h (struct conjured_svalue::key_t): Add "idx" param to
850         ctor and "m_idx" field.
851         (class conjured_svalue::conjured_svalue): Likewise.
853 2023-11-18  David Malcolm  <dmalcolm@redhat.com>
855         PR analyzer/106147
856         * analyzer.opt (Wanalyzer-infinite-loop): New option.
857         (fdump-analyzer-infinite-loop): New option.
858         * checker-event.h (start_cfg_edge_event::get_desc): Drop "final".
859         (start_cfg_edge_event::maybe_describe_condition): Convert from
860         private to protected.
861         * checker-path.h (checker_path::get_logger): New.
862         * diagnostic-manager.cc (process_worklist_item): Update for
863         new context param of maybe_update_for_edge.
864         * engine.cc
865         (impl_region_model_context::impl_region_model_context): Add
866         out_could_have_done_work param to both ctors and use it to
867         initialize mm_out_could_have_done_work.
868         (impl_region_model_context::maybe_did_work): New vfunc
869         implementation.
870         (exploded_node::on_stmt): Add out_could_have_done_work param and
871         pass to ctxt ctor.
872         (exploded_node::on_stmt_pre): Treat setjmp and longjmp as "doing
873         work".
874         (exploded_node::on_longjmp): Likewise.
875         (exploded_edge::exploded_edge): Add "could_do_work" param and use
876         it to initialize m_could_do_work_p.
877         (exploded_edge::dump_dot_label): Add result of could_do_work_p.
878         (exploded_graph::add_function_entry): Mark edge as doing no work.
879         (exploded_graph::add_edge): Add "could_do_work" param and pass to
880         exploded_edge ctor.
881         (add_tainted_args_callback): Treat as doing no work.
882         (exploded_graph::process_worklist): Likewise when merging nodes.
883         (maybe_process_run_of_before_supernode_enodes::item): Likewise.
884         (exploded_graph::maybe_create_dynamic_call): Likewise.
885         (exploded_graph::process_node): Likewise for phi nodes.
886         Pass in a "could_have_done_work" bool when handling stmts and use
887         when creating edges.  Assume work is done at bifurcation.
888         (exploded_path::feasible_p): Update for new context param of
889         maybe_update_for_edge.
890         (feasibility_state::feasibility_state): New ctor.
891         (feasibility_state::operator=): New.
892         (feasibility_state::maybe_update_for_edge): Add ctxt param and use
893         it.  Fix missing newline when logging state.
894         (impl_run_checkers): Call exploded_graph::detect_infinite_loops.
895         * exploded-graph.h
896         (impl_region_model_context::impl_region_model_context): Add
897         out_could_have_done_work param to both ctors.
898         (impl_region_model_context::maybe_did_work): New decl.
899         (impl_region_model_context::checking_for_infinite_loop_p): New.
900         (impl_region_model_context::on_unusable_in_infinite_loop): New.
901         (impl_region_model_context::m_out_could_have_done_work): New
902         field.
903         (exploded_node::on_stmt): Add "out_could_have_done_work" param.
904         (exploded_edge::exploded_edge): Add "could_do_work" param.
905         (exploded_edge::could_do_work_p): New accessor.
906         (exploded_edge::m_could_do_work_p): New field.
907         (exploded_graph::add_edge): Add "could_do_work" param.
908         (exploded_graph::detect_infinite_loops): New decl.
909         (feasibility_state::feasibility_state): New ctor.
910         (feasibility_state::operator=): New decl.
911         (feasibility_state::maybe_update_for_edge): Add ctxt param.
912         * infinite-loop.cc: New file.
913         * program-state.cc (program_state::on_edge): Log the rejected
914         constraint when region_model::maybe_update_for_edge fails.
915         * region-model.cc (region_model::on_assignment): Treat any writes
916         other than to the stack as "doing work".
917         (region_model::on_stmt_pre): Treat all asm stmts as "doing work".
918         (region_model::on_call_post): Likewise for all calls to functions
919         with unknown side effects.
920         (region_model::handle_phi): Add svals_changing_meaning param.
921         Mark widening svalue in phi nodes as changing meaning.
922         (unusable_in_infinite_loop_constraint_p): New.
923         (region_model::add_constraint): If we're checking for an infinite
924         loop, bail out on unusable svalues, or if we don't have a definite
925         true/false for the constraint.
926         (region_model::update_for_phis): Gather all svalues changing
927         meaning in phi nodes, and purge constraints involving them.
928         (region_model::replay_call_summary): Treat all call summaries as
929         doing work.
930         (region_model::can_merge_with_p): Purge constraints involving
931         svalues that change meaning.
932         (model_merger::on_widening_reuse): New.
933         (test_iteration_1): Likewise.
934         (selftest::test_iteration_1): Remove assertion that model6 "knows"
935         that i < 157.
936         * region-model.h (region_model::handle_phi): Add
937         svals_changing_meaning param
938         (region_model_context::maybe_did_work): New pure virtual func.
939         (region_model_context::checking_for_infinite_loop_p): Likewise.
940         (region_model_context::on_unusable_in_infinite_loop): Likewise.
941         (noop_region_model_context::maybe_did_work): Implement.
942         (noop_region_model_context::checking_for_infinite_loop_p):
943         Likewise.
944         (noop_region_model_context::on_unusable_in_infinite_loop):
945         Likewise.
946         (region_model_context_decorator::maybe_did_work): Implement.
947         (region_model_context_decorator::checking_for_infinite_loop_p):
948         Likewise.
949         (region_model_context_decorator::on_unusable_in_infinite_loop):
950         Likewise.
951         (model_merger::on_widening_reuse): New decl.
952         (model_merger::m_svals_changing_meaning): New field.
953         * sm-signal.cc (register_signal_handler::impl_transition): Assume
954         the edge "does work".
955         * supergraph.cc (supernode::get_start_location): Use CFG edge's
956         goto_locus if available.
957         (supernode::get_end_location): Likewise.
958         (cfg_superedge::dump_label_to_pp): Dump edges with a "goto_locus"
959         * supergraph.h (cfg_superedge::get_goto_locus): New.
960         * svalue.cc (svalue::can_merge_p): Call on_widening_reuse for
961         widening values.
962         (involvement_visitor::visit_widening_svalue): New.
963         (svalue::involves_p): Update assertion to allow widening svalues.
965 2023-11-14  David Malcolm  <dmalcolm@redhat.com>
967         PR analyzer/103533
968         * sm-taint.cc: Remove "experimental" from comment.
969         * sm.cc (make_checkers): Always add taint state machine.
971 2023-11-04  David Malcolm  <dmalcolm@redhat.com>
973         * bounds-checking.cc: Update for changes to diagnostic_context.
975 2023-11-02  David Malcolm  <dmalcolm@redhat.com>
977         PR analyzer/112317
978         * access-diagram.cc (class x_aligned_x_ruler_widget): Eliminate
979         unused field "m_col_widths".
980         (access_diagram_impl::add_valid_vs_invalid_ruler): Update for
981         above change.
982         * region-model.cc
983         (check_one_function_attr_null_terminated_string_arg): Remove
984         unused variables "cd_unchecked", "strlen_sval", and
985         "limited_sval".
986         * region-model.h (region_model_context_decorator::warn): Add
987         missing "override".
989 2023-10-31  David Malcolm  <dmalcolm@redhat.com>
991         * record-layout.cc: New file, based on material in region-model.cc.
992         * record-layout.h: Likewise.
993         * region-model.cc: Include "analyzer/record-layout.h".
994         (class record_layout): Move to record-layout.cc and .h
996 2023-10-26  David Malcolm  <dmalcolm@redhat.com>
998         * region-model.cc
999         (region_model::check_external_function_for_access_attr): Split
1000         out, replacing with...
1001         (region_model::check_function_attr_access): ...this new function
1002         and...
1003         (region_model::check_function_attrs): ...this new function.
1004         (region_model::check_one_function_attr_null_terminated_string_arg):
1005         New.
1006         (region_model::check_function_attr_null_terminated_string_arg):
1007         New.
1008         (region_model::handle_unrecognized_call): Update for renaming of
1009         check_external_function_for_access_attr to check_function_attrs.
1010         (region_model::check_for_null_terminated_string_arg): Add return
1011         value to one overload.  Make both overloads const.
1012         * region-model.h: Include "stringpool.h" and "attribs.h".
1013         (region_model::check_for_null_terminated_string_arg): Add return
1014         value to one overload.  Make both overloads const.
1015         (region_model::check_external_function_for_access_attr): Delete
1016         decl.
1017         (region_model::check_function_attr_access): New decl.
1018         (region_model::check_function_attr_null_terminated_string_arg):
1019         New decl.
1020         (region_model::check_one_function_attr_null_terminated_string_arg):
1021         New decl.
1022         (region_model::check_function_attrs): New decl.
1024 2023-10-09  David Malcolm  <dmalcolm@redhat.com>
1026         * access-diagram.cc (boundaries::add): Explicitly state
1027         "boundaries::" scope for "kind" enum.
1029 2023-10-08  David Malcolm  <dmalcolm@redhat.com>
1031         PR analyzer/111155
1032         * access-diagram.cc (boundaries::boundaries): Add logger param
1033         (boundaries::add): Add logging.
1034         (boundaries::get_hard_boundaries_in_range): New.
1035         (boundaries::m_logger): New field.
1036         (boundaries::get_table_x_for_offset): Make public.
1037         (class svalue_spatial_item): New.
1038         (class compound_svalue_spatial_item): New.
1039         (add_ellipsis_to_gaps): New.
1040         (valid_region_spatial_item::valid_region_spatial_item): Add theme
1041         param.  Initialize m_boundaries, m_existing_sval, and
1042         m_existing_sval_spatial_item.
1043         (valid_region_spatial_item::add_boundaries): Set m_boundaries.
1044         Add boundaries for any m_existing_sval_spatial_item.
1045         (valid_region_spatial_item::add_array_elements_to_table): Rewrite
1046         creation of min/max index in terms of
1047         maybe_add_array_index_to_table.  Rewrite ellipsis code using
1048         add_ellipsis_to_gaps. Add index values for any hard boundaries
1049         within the valid region.
1050         (valid_region_spatial_item::maybe_add_array_index_to_table): New,
1051         based on code formerly in add_array_elements_to_table.
1052         (valid_region_spatial_item::make_table): Make use of
1053         m_existing_sval_spatial_item, if any.
1054         (valid_region_spatial_item::m_boundaries): New field.
1055         (valid_region_spatial_item::m_existing_sval): New field.
1056         (valid_region_spatial_item::m_existing_sval_spatial_item): New
1057         field.
1058         (class svalue_spatial_item): Rename to...
1059         (class written_svalue_spatial_item): ...this.
1060         (class string_region_spatial_item): Rename to..
1061         (class string_literal_spatial_item): ...this.  Add "kind".
1062         (string_literal_spatial_item::add_boundaries): Use m_kind to
1063         determine kind of boundary.  Update for renaming of m_actual_bits
1064         to m_bits.
1065         (string_literal_spatial_item::make_table): Likewise.  Support not
1066         displaying a row for byte indexes, and not displaying a row for
1067         the type.
1068         (string_literal_spatial_item::add_column_for_byte): Make byte index
1069         row optional.
1070         (svalue_spatial_item::make): Convert to...
1071         (make_written_svalue_spatial_item): ...this.
1072         (make_existing_svalue_spatial_item): New.
1073         (access_diagram_impl::access_diagram_impl): Pass theme to
1074         m_valid_region_spatial_item ctor.  Update for renaming of
1075         m_svalue_spatial_item.
1076         (access_diagram_impl::find_boundaries): Pass logger to boundaries.
1077         Update for renaming of...
1078         (access_diagram_impl::m_svalue_spatial_item): Rename to...
1079         (access_diagram_impl::m_written_svalue_spatial_item): ...this.
1081 2023-10-03  David Malcolm  <dmalcolm@redhat.com>
1083         * analyzer-logging.cc (logger::log_va_partial): Use text_info
1084         ctor.
1085         * analyzer.cc (make_label_text): Likewise.
1086         (make_label_text_n): Likewise.
1087         * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
1088         Likewise.
1090 2023-10-02  David Malcolm  <dmalcolm@redhat.com>
1092         * program-point.cc: Update for grouping of source printing fields
1093         within diagnostic_context.
1095 2023-09-15  David Malcolm  <dmalcolm@redhat.com>
1097         * analyzer.cc (get_stmt_location): Handle null stmt.
1098         * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Copy
1099         m_loc from ploc.
1100         (saved_diagnostic::operator==): Compare m_loc.
1101         (saved_diagnostic::calc_best_epath): Only use m_stmt_finder if
1102         m_loc is unknown.
1103         (dedupe_key::dedupe_key): Initialize m_loc.
1104         (dedupe_key::operator==): Compare m_loc.
1105         (dedupe_key::get_location): Use m_loc if it's known.
1106         (dedupe_key::m_loc): New field.
1107         (diagnostic_manager::emit_saved_diagnostic): Only call
1108         get_emission_location if m_loc is unknown, preferring to use m_loc
1109         if it's available.
1110         * diagnostic-manager.h (saved_diagnostic::m_loc): New field.
1111         (pending_location::pending_location): Initialize m_loc.  Add
1112         overload taking a location_t rather than a stmt/stmt_finder.
1113         (pending_location::m_loc): New field.
1115 2023-09-15  David Malcolm  <dmalcolm@redhat.com>
1117         * analyzer.h (struct pending_location): New forward decl.
1118         * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
1119         Replace params "enode", "snode", "stmt", and "stmt_finder" with
1120         "ploc".
1121         (diagnostic_manager::add_diagnostic): Likewise for both overloads.
1122         * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
1123         Likewise.
1124         (struct pending_location): New.
1125         (diagnostic_manager::add_diagnostic): Replace params "enode",
1126         "snode", "stmt", and "stmt_finder" with "ploc".
1127         * engine.cc (impl_region_model_context::warn): Update call to
1128         add_diagnostic for above change.
1129         (impl_sm_context::warn): Likewise.
1130         (impl_region_model_context::on_state_leak): Likewise.
1131         * infinite-recursion.cc
1132         (exploded_graph::detect_infinite_recursion): Likewise.
1134 2023-09-15  David Malcolm  <dmalcolm@redhat.com>
1136         * region-model.cc (region_model::get_gassign_result): Handle
1137         volatile ops by using a conjured_svalue.
1139 2023-09-14  David Malcolm  <dmalcolm@redhat.com>
1141         * checker-event.h (checker_event::get_thread_id): New.
1142         * checker-path.h (class checker_path): Implement thread-related
1143         vfuncs via a single simple_diagnostic_thread instance named
1144         "main".
1146 2023-09-14  David Malcolm  <dmalcolm@redhat.com>
1148         * diagnostic-manager.cc (compatible_epath_p): Fix missing return.
1150 2023-09-14  David Malcolm  <dmalcolm@redhat.com>
1152         * diagnostic-manager.cc (process_worklist_item): Use
1153         std::unique_ptr rather than plain rejected_constraint *.
1154         * engine.cc (exploded_path::feasible_p): Likewise.
1155         (feasibility_state::maybe_update_for_edge): Likewise.
1156         * exploded-graph.h (feasibility_problem::feasibility_problem):
1157         Likewise.
1158         (feasibility_problem::~feasibility_problem): Delete.
1159         (feasibility_problem::m_rc): Use std::unique_ptr.
1160         (feasibility_state::maybe_update_for_edge): Likewise.
1161         * feasible-graph.cc (feasible_graph::add_feasibility_problem):
1162         Likewise.
1163         * feasible-graph.h (class infeasible_node): Likewise.
1164         (feasible_graph::add_feasibility_problem): Likewise.
1165         * region-model.cc (region_model::add_constraint): Likewise.
1166         (region_model::maybe_update_for_edge): Likewise.
1167         (region_model::apply_constraints_for_gcond): Likewise.
1168         (region_model::apply_constraints_for_gswitch): Likewise.
1169         (region_model::apply_constraints_for_exception): Likewise.
1170         * region-model.h (class region_model): Likewise for decls.
1172 2023-09-09  benjamin priour  <vultkayn@gcc.gnu.org>
1174         PR analyzer/96395
1175         * region-model.cc
1176         (region_model::add_constraints_from_binop): binop_svalues around
1177         LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR are now unwrapped.
1179 2023-09-07  David Malcolm  <dmalcolm@redhat.com>
1181         PR analyzer/110529
1182         * program-point.cc (program_point::on_edge): Don't reject
1183         EDGE_ABNORMAL for computed gotos.
1184         * region-model.cc (region_model::maybe_update_for_edge): Handle
1185         computed goto statements.
1186         (region_model::apply_constraints_for_ggoto): New.
1187         * region-model.h (region_model::apply_constraints_for_ggoto): New decl.
1188         * supergraph.cc (supernode::get_label): New.
1189         * supergraph.h (supernode::get_label): New decl.
1191 2023-09-07  benjamin priour  <vultkayn@gcc.gnu.org>
1192             David Malcolm  <dmalcolm@redhat.com>
1194         PR analyzer/110830
1195         * diagnostic-manager.cc
1196         (compatible_epaths_p): New function.
1197         (saved_diagnostic::supercedes_p): Now calls the above
1198         to determine if the diagnostics do overlap and the superseding
1199         may proceed.
1201 2023-09-07  David Malcolm  <dmalcolm@redhat.com>
1203         * region-model.h: fix -Wunused-parameter warnings
1205 2023-09-06  David Malcolm  <dmalcolm@redhat.com>
1207         PR analyzer/105899
1208         * kf.cc (class kf_strstr): New.
1209         (kf_strstr::impl_call_post): New.
1210         (register_known_functions): Register it.
1212 2023-09-06  David Malcolm  <dmalcolm@redhat.com>
1214         PR analyzer/105899
1215         * kf.cc (class kf_strncpy): New.
1216         (kf_strncpy::impl_call_post): New.
1217         (register_known_functions): Register it.
1218         * region-model.cc (region_model::read_bytes): Handle unknown
1219         number of bytes.
1221 2023-09-06  David Malcolm  <dmalcolm@redhat.com>
1223         * kf.cc (kf_calloc::impl_call_pre): Pass ctxt to zero_fill_region.
1224         (kf_memset::impl_call_pre): Move responsibility for calling
1225         check_region_for_write to fill_region.
1226         * region-model.cc (region_model::on_assignment): Pass ctxt to
1227         zero_fill_region.
1228         (region_model::fill_region): Add "ctxt" param, using it to call
1229         check_region_for_write.
1230         (region_model::zero_fill_region): Likewise.
1231         * region-model.h (region_model::fill_region): Add "ctxt" param.
1232         (region_model::zero_fill_region): Likewise.
1234 2023-09-01  benjamin priour  <priour.be@gmail.com>
1236         PR analyzer/105948
1237         PR analyzer/94355
1238         * analyzer.h (is_placement_new_p): New declaration.
1239         * call-details.cc
1240         (call_details::deref_ptr_arg): New function.
1241         Dereference the argument at given index if possible.
1242         * call-details.h: Declaration of the above function.
1243         * kf-lang-cp.cc (is_placement_new_p): Returns true if the gcall
1244         is recognized as a placement new.
1245         (kf_operator_delete::impl_call_post): Unbinding a region and its
1246         descendents now poisons with POISON_KIND_DELETED.
1247         (register_known_functions_lang_cp): Known function "operator
1248         delete" is now registered only once independently of its number of
1249         arguments.
1250         * region-model.cc (region_model::eval_condition): Now
1251         recursively calls itself if any of the operand is wrapped in a
1252         cast.
1253         * sm-malloc.cc (malloc_state_machine::on_stmt):
1254         Add placement new recognition.
1255         * svalue.cc (poison_kind_to_str): Wording for the new PK.
1256         * svalue.h (enum poison_kind): Add value POISON_KIND_DELETED.
1258 2023-08-31  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
1260         * kf.cc: Change spelling to macOS.
1262 2023-08-30  Eric Feng  <ef2648@columbia.edu>
1264         PR analyzer/107646
1265         * engine.cc (impl_region_model_context::warn): New optional
1266         parameter.
1267         * exploded-graph.h (class impl_region_model_context): Likewise.
1268         * region-model.cc (region_model::pop_frame): New callback
1269         feature for region_model::pop_frame.
1270         * region-model.h (struct append_regions_cb_data): Likewise.
1271         (class region_model): Likewise.
1272         (class region_model_context): New optional parameter.
1273         (class region_model_context_decorator): Likewise.
1275 2023-08-30  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
1277         * region-model.cc: Define INCLUDE_ALGORITHM.
1279 2023-08-29  David Malcolm  <dmalcolm@redhat.com>
1281         PR analyzer/99860
1282         * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
1283         selftest::analyzer_ranges_cc_tests.
1284         * analyzer-selftests.h (selftest::run_analyzer_selftests): New
1285         decl.
1286         * analyzer.opt (Wanalyzer-overlapping-buffers): New option.
1287         * call-details.cc: Include "analyzer/ranges.h" and "make-unique.h".
1288         (class overlapping_buffers): New.
1289         (call_details::complain_about_overlap): New.
1290         * call-details.h (call_details::complain_about_overlap): New decl.
1291         * kf.cc (kf_memcpy_memmove::impl_call_pre): Call
1292         cd.complain_about_overlap for memcpy and memcpy_chk.
1293         (kf_strcat::impl_call_pre): Call cd.complain_about_overlap.
1294         (kf_strcpy::impl_call_pre): Likewise.
1295         * ranges.cc: New file.
1296         * ranges.h: New file.
1298 2023-08-29  David Malcolm  <dmalcolm@redhat.com>
1300         PR analyzer/105899
1301         * kf.cc (kf_strdup::impl_call_pre): Set size of
1302         dynamically-allocated buffer.  Simulate copying the string from
1303         the source region to the new buffer.
1305 2023-08-27  benjamin priour  <vultkayn@gcc.gnu.org>
1307         PR analyzer/96395
1308         * analyzer.h (class known_function): Add virtual casts
1309         to builtin_known_function.
1310         (class builtin_known_function): New subclass of known_function
1311         for builtins.
1312         * kf.cc (class kf_alloca): Now derived from
1313         builtin_known_function.
1314         (class kf_calloc): Likewise.
1315         (class kf_free): Likewise.
1316         (class kf_malloc): Likewise.
1317         (class kf_memcpy_memmove): Likewise.
1318         (class kf_memset): Likewise.
1319         (class kf_realloc): Likewise.
1320         (class kf_strchr): Likewise.
1321         (class kf_sprintf): Likewise.
1322         (class kf_strcat): Likewise.
1323         (class kf_strcpy): Likewise.
1324         (class kf_strdup): Likewise.
1325         (class kf_strlen): Likewise.
1326         (class kf_strndup): Likewise.
1327         (register_known_functions): Builtins are now registered as
1328         known_functions by name rather than by their BUILTIN_CODE.
1329         * known-function-manager.cc (get_normal_builtin): New overload.
1330         * known-function-manager.h: New overload declaration.
1331         * region-model.cc (region_model::get_builtin_kf): New function.
1332         * region-model.h (class region_model): Add declaration of
1333         get_builtin_kf.
1334         * sm-fd.cc: For called recognized as builtins, use the
1335         attributes of that builtin as defined in gcc/builtins.def
1336         rather than the user's.
1337         * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
1339 2023-08-25  David Malcolm  <dmalcolm@redhat.com>
1341         * access-diagram.cc (class string_region_spatial_item): Remove
1342         assumption that the string is written to the start of the cluster.
1344 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1346         PR analyzer/105899
1347         * call-details.cc
1348         (call_details::check_for_null_terminated_string_arg): Split into
1349         overloads, one taking just an arg_idx, the other a new
1350         "include_terminator" param.
1351         * call-details.h: Likewise.
1352         * kf.cc (class kf_strcat): New.
1353         (kf_strcpy::impl_call_pre): Update for change to
1354         check_for_null_terminated_string_arg.
1355         (register_known_functions): Register kf_strcat.
1356         * region-model.cc
1357         (region_model::check_for_null_terminated_string_arg): Split into
1358         overloads, one taking just an arg_idx, the other a new
1359         "include_terminator" param.  When returning an svalue, handle
1360         "include_terminator" being false by subtracting one.
1361         * region-model.h
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.
1366 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1368         PR analyzer/105899
1369         * region-model.cc (fragment::has_null_terminator): Handle
1370         SK_BITS_WITHIN.
1372 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1374         PR analyzer/105899
1375         * region-model-manager.cc
1376         (region_model_manager::get_or_create_initial_value): Simplify
1377         INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) to
1378         CONSTANT_SVAL(STRING[N]).
1380 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1382         PR analyzer/105899
1383         * region-model.cc (fragment::has_null_terminator): Move STRING_CST
1384         handling to fragment::string_cst_has_null_terminator; also use it to
1385         handle INIT_VAL(STRING_REG).
1386         (fragment::string_cst_has_null_terminator): New, from above.
1388 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1390         * kf.cc (kf_memcpy_memmove::impl_call_pre): Reimplement using
1391         region_model::copy_bytes.
1392         * region-model.cc (region_model::read_bytes): New.
1393         (region_model::copy_bytes): New.
1394         * region-model.h (region_model::read_bytes): New decl.
1395         (region_model::copy_bytes): New decl.
1397 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1399         PR analyzer/105899
1400         * region-model.cc (region_model::get_string_size): Delete both.
1401         * region-model.h (region_model::get_string_size): Delete both
1402         decls.
1404 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1406         PR analyzer/105899
1407         * kf.cc (kf_strcpy::impl_call_pre): Reimplement using
1408         check_for_null_terminated_string_arg.
1409         * region-model.cc (region_model::get_store_bytes): Shortcut
1410         reading all of a string_region.
1411         (region_model::scan_for_null_terminator): Use get_store_value for
1412         the bytes rather than "unknown" when returning an unknown length.
1413         (region_model::write_bytes): New.
1414         * region-model.h (region_model::write_bytes): New decl.
1416 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1418         PR analyzer/105899
1419         * region-model.cc (iterable_cluster::iterable_cluster): Add
1420         symbolic binding keys to m_symbolic_bindings.
1421         (iterable_cluster::has_symbolic_bindings_p): New.
1422         (iterable_cluster::m_symbolic_bindings): New field.
1423         (region_model::scan_for_null_terminator): Treat clusters with
1424         symbolic bindings as having unknown strlen.
1426 2023-08-24  David Malcolm  <dmalcolm@redhat.com>
1428         * engine.cc (impl_path_context::impl_path_context): Add logger
1429         param.
1430         (impl_path_context::bifurcate): Add log message.
1431         (impl_path_context::terminate_path): Likewise.
1432         (impl_path_context::m_logger): New field.
1433         (exploded_graph::process_node): Pass logger to path_ctxt ctor.
1435 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1437         PR analyzer/105899
1438         * kf-analyzer.cc (class kf_analyzer_get_strlen): Move to kf.cc.
1439         (register_known_analyzer_functions): Use make_kf_strlen.
1440         * kf.cc (class kf_strlen::impl_call_pre): Replace with
1441         implementation of kf_analyzer_get_strlen from kf-analyzer.cc.
1442         Handle "UNKNOWN" return from check_for_null_terminated_string_arg
1443         by falling back to a conjured svalue.
1444         (make_kf_strlen): New.
1445         (register_known_functions): Use make_kf_strlen.
1446         * known-function-manager.h (make_kf_strlen): New decl.
1448 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1450         PR analyzer/105899
1451         * call-details.cc (call_details::call_details): New ctor.
1452         * call-details.h (call_details::call_details): New ctor decl.
1453         (struct call_arg_details): Move here from region-model.cc.
1454         * region-model.cc (region_model::check_call_format_attr): New.
1455         (region_model::check_call_args): Call it.
1456         (struct call_arg_details): Move it to call-details.h.
1457         * region-model.h (region_model::check_call_format_attr): New decl.
1459 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1461         * kf.cc (class kf_fopen): New.
1462         (register_known_functions): Register it.
1464 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1466         PR analyzer/105899
1467         * analyzer.opt (Wanalyzer-unterminated-string): Delete.
1468         * call-details.cc
1469         (call_details::check_for_null_terminated_string_arg): Convert
1470         return type from void to const svalue *.  Add param "out_sval".
1471         * call-details.h
1472         (call_details::check_for_null_terminated_string_arg): Likewise.
1473         * kf-analyzer.cc (kf_analyzer_get_strlen::impl_call_pre): Wire up
1474         to result of check_for_null_terminated_string_arg.
1475         * region-model.cc (get_strlen): Delete.
1476         (class unterminated_string_arg): Delete.
1477         (struct fragment): New.
1478         (class iterable_cluster): New.
1479         (region_model::get_store_bytes): New.
1480         (get_tree_for_byte_offset): New.
1481         (region_model::scan_for_null_terminator): New.
1482         (region_model::check_for_null_terminated_string_arg): Convert
1483         return type from void to const svalue *.  Add param "out_sval".
1484         Reimplement in terms of scan_for_null_terminator, dropping the
1485         special-case for -Wanalyzer-unterminated-string.
1486         * region-model.h (region_model::get_store_bytes): New decl.
1487         (region_model::scan_for_null_terminator): New decl.
1488         (region_model::check_for_null_terminated_string_arg): Convert
1489         return type from void to const svalue *.  Add param "out_sval".
1490         * store.cc (concrete_binding::get_byte_range): New.
1491         * store.h (concrete_binding::get_byte_range): New decl.
1492         (store_manager::get_concrete_binding): New overload.
1494 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1496         * region-model.cc (region_model_context_decorator::add_event):
1497         Handle m_inner being NULL.
1498         * region-model.h (class region_model_context_decorator): Likewise.
1499         (annotating_context::warn): Likewise.
1501 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1503         * diagnostic-manager.cc (saved_diagnostic::add_event): New.
1504         (saved_diagnostic::add_any_saved_events): New.
1505         (diagnostic_manager::add_event): New.
1506         (dedupe_winners::emit_best): New.
1507         (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
1508         non-const.  Call saved_diagnostic::add_any_saved_events.
1509         * diagnostic-manager.h (saved_diagnostic::add_event): New decl.
1510         (saved_diagnostic::add_any_saved_events): New decl.
1511         (saved_diagnostic::m_saved_events): New field.
1512         (diagnostic_manager::add_event): New decl.
1513         (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
1514         non-const.
1515         * engine.cc (impl_region_model_context::add_event): New.
1516         * exploded-graph.h (impl_region_model_context::add_event): New decl.
1517         * region-model.cc
1518         (noop_region_model_context::add_event): New.
1519         (region_model_context_decorator::add_event): New.
1520         * region-model.h (region_model_context::add_event): New vfunc.
1521         (noop_region_model_context::add_event): New decl.
1522         (region_model_context_decorator::add_event): New decl.
1524 2023-08-22  David Malcolm  <dmalcolm@redhat.com>
1526         * region-model.cc
1527         (class check_external_function_for_access_attr::annotating_ctxt):
1528         Convert to an annotating_context.
1529         * region-model.h (class note_adding_context): Rename to...
1530         (class annotating_context): ...this, updating the "warn" method.
1531         (note_adding_context::make_note): Replace with...
1532         (annotating_context::add_annotations): ...this.
1534 2023-08-14  benjamin priour  <vultkayn@gcc.gnu.org>
1536         PR analyzer/110543
1537         * analyzer.opt: Add new option.
1538         * diagnostic-manager.cc
1539         (diagnostic_manager::prune_path): Call prune_system_headers.
1540         (prune_frame): New function that deletes all events in a frame.
1541         (diagnostic_manager::prune_system_headers): New function.
1542         * diagnostic-manager.h: Add prune_system_headers declaration.
1544 2023-08-11  David Malcolm  <dmalcolm@redhat.com>
1546         PR analyzer/105899
1547         * analyzer.opt (Wanalyzer-unterminated-string): New.
1548         * call-details.cc
1549         (call_details::check_for_null_terminated_string_arg): New.
1550         * call-details.h
1551         (call_details::check_for_null_terminated_string_arg): New decl.
1552         * kf-analyzer.cc (class kf_analyzer_get_strlen): New.
1553         (register_known_analyzer_functions): Register it.
1554         * kf.cc (kf_error::impl_call_pre): Check that format arg is a
1555         valid null-terminated string.
1556         (kf_putenv::impl_call_pre): Likewise for the sole param.
1557         (kf_strchr::impl_call_pre): Likewise for the first param.
1558         (kf_strcpy::impl_call_pre): Likewise for the second param.
1559         (kf_strdup::impl_call_pre): Likewise for the sole param.
1560         * region-model.cc (get_strlen): New.
1561         (struct call_arg_details): New.
1562         (inform_about_expected_null_terminated_string_arg): New.
1563         (class unterminated_string_arg): New.
1564         (region_model::check_for_null_terminated_string_arg): New.
1565         * region-model.h
1566         (region_model::check_for_null_terminated_string_arg): New decl.
1568 2023-08-11  Eric Feng  <ef2648@columbia.edu>
1570         PR analyzer/107646
1571         * call-details.h: New function.
1572         * region-model.cc (region_model::get_or_create_region_for_heap_alloc):
1573         New optional parameters.
1574         * region-model.h (class region_model): New optional parameters.
1575         * sm-malloc.cc (on_realloc_with_move): New function.
1576         (region_model::transition_ptr_sval_non_null): New function.
1578 2023-08-09  David Malcolm  <dmalcolm@redhat.com>
1580         * analyzer.h (class pure_known_function_with_default_return): New
1581         subclass.
1582         * call-details.cc (const_fn_p): Move here from region-model.cc.
1583         (maybe_get_const_fn_result): Likewise.
1584         (get_result_size_in_bytes): Likewise.
1585         (call_details::set_any_lhs_with_defaults): New function, based on
1586         code in region_model::on_call_pre.
1587         * call-details.h (call_details::set_any_lhs_with_defaults): New
1588         decl.
1589         * diagnostic-manager.cc
1590         (diagnostic_manager::emit_saved_diagnostic): Log the index of the
1591         saved_diagnostic.
1592         * kf.cc (pure_known_function_with_default_return::impl_call_pre):
1593         New.
1594         (kf_memset::impl_call_pre): Set the LHS to the first param.
1595         (kf_putenv::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1596         (kf_sprintf::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1597         (class kf_stack_restore): Derive from
1598         pure_known_function_with_default_return.
1599         (class kf_stack_save): Likewise.
1600         (kf_strlen::impl_call_pre): Call cd.set_any_lhs_with_defaults.
1601         * region-model-reachability.cc (reachable_regions::handle_sval):
1602         Remove logic for symbolic regions for pointers.
1603         * region-model.cc (region_model::canonicalize): Remove purging of
1604         dynamic extents workaround for surplus values from
1605         region_model::on_call_pre's default LHS code.
1606         (const_fn_p): Move to call-details.cc.
1607         (maybe_get_const_fn_result): Likewise.
1608         (get_result_size_in_bytes): Likewise.
1609         (region_model::update_for_nonzero_return): Call
1610         cd.set_any_lhs_with_defaults.
1611         (region_model::on_call_pre): Remove the assignment to the LHS of a
1612         default return value, instead requiring all known_function
1613         implementations to write to any LHS of the call.  Use
1614         cd.set_any_lhs_with_defaults on the non-kf paths.
1615         * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Use
1616         cd.set_any_lhs_with_defaults when failing to get at fd state.
1617         (kf_bind::outcome_of_bind::update_model): Likewise.
1618         (kf_listen::outcome_of_listen::update_model): Likewise.
1619         (kf_accept::outcome_of_accept::update_model): Likewise.
1620         (kf_connect::outcome_of_connect::update_model): Likewise.
1621         (kf_read::impl_call_pre): Use cd.set_any_lhs_with_defaults.
1622         * sm-file.cc (class kf_stdio_output_fn): Derive from
1623         pure_known_function_with_default_return.
1624         (class kf_ferror): Likewise.
1625         (class kf_fileno): Likewise.
1626         (kf_fgets::impl_call_pre): Use cd.set_any_lhs_with_defaults.
1627         (kf_read::impl_call_pre): Likewise.
1628         (class kf_getc): Derive from
1629         pure_known_function_with_default_return.
1630         (class kf_getchar): Likewise.
1631         * varargs.cc (kf_va_arg::impl_call_pre): Use
1632         cd.set_any_lhs_with_defaults.
1634 2023-08-04  David Malcolm  <dmalcolm@redhat.com>
1636         PR analyzer/110426
1637         * bounds-checking.cc (region_model::check_region_bounds): Handle
1638         symbolic base regions.
1639         * call-details.cc: Include "stringpool.h" and "attribs.h".
1640         (call_details::lookup_function_attribute): New function.
1641         * call-details.h (call_details::lookup_function_attribute): New
1642         function decl.
1643         * region-model-manager.cc
1644         (region_model_manager::maybe_fold_binop): Add reference to
1645         PR analyzer/110902.
1646         * region-model-reachability.cc (reachable_regions::handle_sval):
1647         Add symbolic regions for pointers that are conjured svalues for
1648         the LHS of a stmt.
1649         * region-model.cc (region_model::canonicalize): Purge dynamic
1650         extents for regions that aren't referenced.
1651         (get_result_size_in_bytes): New function.
1652         (region_model::on_call_pre): Use get_result_size_in_bytes and
1653         potentially set the dynamic extents of the region pointed to by
1654         the return value.
1655         (region_model::deref_rvalue): Add param "add_nonnull_constraint"
1656         and use it to conditionalize adding the constraint.
1657         (pending_diagnostic_subclass::dubious_allocation_size): Add "stmt"
1658         param to both ctors and use it to initialize new "m_stmt" field.
1659         (pending_diagnostic_subclass::operator==): Use m_stmt; don't use
1660         m_lhs or m_rhs.
1661         (pending_diagnostic_subclass::m_stmt): New field.
1662         (region_model::check_region_size): Generalize to any kind of
1663         pointer svalue by using deref_rvalue rather than checking for
1664         region_svalue.  Pass stmt to dubious_allocation_size ctor.
1665         * region-model.h (region_model::deref_rvalue): Add param
1666         "add_nonnull_constraint".
1667         * svalue.cc (conjured_svalue::lhs_value_p): New function.
1668         * svalue.h (conjured_svalue::lhs_value_p): New decl.
1670 2023-08-04  David Malcolm  <dmalcolm@redhat.com>
1672         * svalue.cc (region_svalue::dump_to_pp): Support NULL type.
1673         (constant_svalue::dump_to_pp): Likewise.
1674         (initial_svalue::dump_to_pp): Likewise.
1675         (conjured_svalue::dump_to_pp): Likewise.  Fix missing print of the
1676         type.
1678 2023-08-03  David Malcolm  <dmalcolm@redhat.com>
1680         PR analyzer/110882
1681         * region.cc (int_size_in_bits): Fail on zero-sized types.
1683 2023-08-02  Eric Feng  <ef2648@columbia.edu>
1685         PR analyzer/107646
1686         * analyzer-language.cc (run_callbacks): New function.
1687         (on_finish_translation_unit): New function.
1688         * analyzer-language.h (GCC_ANALYZER_LANGUAGE_H): New include.
1689         (class translation_unit): New vfuncs.
1691 2023-07-26  David Malcolm  <dmalcolm@redhat.com>
1693         PR analyzer/104940
1694         * region-model-manager.cc
1695         (region_model_manager::region_model_manager): Update for
1696         generalizing region ids to also cover svalues.
1697         (region_model_manager::get_or_create_constant_svalue): Likewise.
1698         (region_model_manager::get_or_create_unknown_svalue): Likewise.
1699         (region_model_manager::create_unique_svalue): Likewise.
1700         (region_model_manager::get_or_create_initial_value): Likewise.
1701         (region_model_manager::get_or_create_setjmp_svalue): Likewise.
1702         (region_model_manager::get_or_create_poisoned_svalue): Likewise.
1703         (region_model_manager::get_ptr_svalue): Likewise.
1704         (region_model_manager::get_or_create_unaryop): Likewise.
1705         (region_model_manager::get_or_create_binop): Likewise.
1706         (region_model_manager::get_or_create_sub_svalue): Likewise.
1707         (region_model_manager::get_or_create_repeated_svalue): Likewise.
1708         (region_model_manager::get_or_create_bits_within): Likewise.
1709         (region_model_manager::get_or_create_unmergeable): Likewise.
1710         (region_model_manager::get_or_create_widening_svalue): Likewise.
1711         (region_model_manager::get_or_create_compound_svalue): Likewise.
1712         (region_model_manager::get_or_create_conjured_svalue): Likewise.
1713         (region_model_manager::get_or_create_asm_output_svalue): Likewise.
1714         (region_model_manager::get_or_create_const_fn_result_svalue):
1715         Likewise.
1716         (region_model_manager::get_region_for_fndecl): Likewise.
1717         (region_model_manager::get_region_for_label): Likewise.
1718         (region_model_manager::get_region_for_global): Likewise.
1719         (region_model_manager::get_field_region): Likewise.
1720         (region_model_manager::get_element_region): Likewise.
1721         (region_model_manager::get_offset_region): Likewise.
1722         (region_model_manager::get_sized_region): Likewise.
1723         (region_model_manager::get_cast_region): Likewise.
1724         (region_model_manager::get_frame_region): Likewise.
1725         (region_model_manager::get_symbolic_region): Likewise.
1726         (region_model_manager::get_region_for_string): Likewise.
1727         (region_model_manager::get_bit_range): Likewise.
1728         (region_model_manager::get_var_arg_region): Likewise.
1729         (region_model_manager::get_region_for_unexpected_tree_code):
1730         Likewise.
1731         (region_model_manager::get_or_create_region_for_heap_alloc):
1732         Likewise.
1733         (region_model_manager::create_region_for_alloca): Likewise.
1734         (region_model_manager::log_stats): Likewise.
1735         * region-model-manager.h (region_model_manager::get_num_regions):
1736         Replace with...
1737         (region_model_manager::get_num_symbols): ...this.
1738         (region_model_manager::alloc_region_id): Replace with...
1739         (region_model_manager::alloc_symbol_id): ...this.
1740         (region_model_manager::m_next_region_id): Replace with...
1741         (region_model_manager::m_next_symbol_id): ...this.
1742         * region-model.cc (selftest::test_get_representative_tree): Update
1743         for generalizing region ids to also cover svalues.
1744         (selftest::test_binop_svalue_folding): Likewise.
1745         (selftest::test_state_merging): Likewise.
1746         * region.cc (region::cmp_ids): Delete, in favor of
1747         symbol::cmp_ids.
1748         (region::region): Update for introduction of symbol base class.
1749         (frame_region::get_region_for_local): Likewise.
1750         (root_region::root_region): Likewise.
1751         (symbolic_region::symbolic_region): Likewise.
1752         * region.h: Replace include of "analyzer/complexity.h" with
1753         "analyzer/symbol.h".
1754         (class region): Make a subclass of symbol.
1755         (region::get_id): Delete in favor of symbol::get_id.
1756         (region::cmp_ids): Delete in favor of symbol::cmp_ids.
1757         (region::get_complexity): Delete in favor of
1758         symbol::get_complexity.
1759         (region::region): Use symbol::id_t for "id" param.
1760         (region::m_complexity): Move field to symbol base class.
1761         (region::m_id): Likewise.
1762         (space_region::space_region): Use symbol::id_t for "id" param.
1763         (frame_region::frame_region): Likewise.
1764         (globals_region::globals_region): Likewise.
1765         (code_region::code_region): Likewise.
1766         (function_region::function_region): Likewise.
1767         (label_region::label_region): Likewise.
1768         (stack_region::stack_region): Likewise.
1769         (heap_region::heap_region): Likewise.
1770         (thread_local_region::thread_local_region): Likewise.
1771         (root_region::root_region): Likewise.
1772         (symbolic_region::symbolic_region): Likewise.
1773         (decl_region::decl_region): Likewise.
1774         (field_region::field_region): Likewise.
1775         (element_region::element_region): Likewise.
1776         (offset_region::offset_region): Likewise.
1777         (sized_region::sized_region): Likewise.
1778         (cast_region::cast_region): Likewise.
1779         (heap_allocated_region::heap_allocated_region): Likewise.
1780         (alloca_region::alloca_region): Likewise.
1781         (string_region::string_region): Likewise.
1782         (bit_range_region::bit_range_region): Likewise.
1783         (var_arg_region::var_arg_region): Likewise.
1784         (errno_region::errno_region): Likewise.
1785         (unknown_region::unknown_region): Likewise.
1786         * svalue.cc (sub_svalue::sub_svalue): Add symbol::id_t param.
1787         (repeated_svalue::repeated_svalue): Likewise.
1788         (bits_within_svalue::bits_within_svalue): Likewise.
1789         (compound_svalue::compound_svalue): Likewise.
1790         * svalue.h: Replace include of "analyzer/complexity.h" with
1791         "analyzer/symbol.h".
1792         (class svalue): Make a subclass of symbol.
1793         (svalue::get_complexity): Delete in favor of
1794         symbol::get_complexity.
1795         (svalue::svalue): Add symbol::id_t param.  Update for new base
1796         class.
1797         (svalue::m_complexity): Delete in favor of
1798         symbol::m_complexity.
1799         (region_svalue::region_svalue): Add symbol::id_t param
1800         (constant_svalue::constant_svalue): Likewise.
1801         (unknown_svalue::unknown_svalue): Likewise.
1802         (poisoned_svalue::poisoned_svalue): Likewise.
1803         (setjmp_svalue::setjmp_svalue): Likewise.
1804         (initial_svalue::initial_svalue): Likewise.
1805         (unaryop_svalue::unaryop_svalue): Likewise.
1806         (binop_svalue::binop_svalue): Likewise.
1807         (sub_svalue::sub_svalue): Likewise.
1808         (repeated_svalue::repeated_svalue): Likewise.
1809         (bits_within_svalue::bits_within_svalue): Likewise.
1810         (unmergeable_svalue::unmergeable_svalue): Likewise.
1811         (placeholder_svalue::placeholder_svalue): Likewise.
1812         (widening_svalue::widening_svalue): Likewise.
1813         (compound_svalue::compound_svalue): Likewise.
1814         (conjured_svalue::conjured_svalue): Likewise.
1815         (asm_output_svalue::asm_output_svalue): Likewise.
1816         (const_fn_result_svalue::const_fn_result_svalue): Likewise.
1817         * symbol.cc: New file.
1818         * symbol.h: New file.
1820 2023-07-21  David Malcolm  <dmalcolm@redhat.com>
1822         PR analyzer/110455
1823         * region-model.cc (region_model::get_gassign_result): Only check
1824         for bad shift counts when dealing with an integral type.
1826 2023-07-21  David Malcolm  <dmalcolm@redhat.com>
1828         PR analyzer/110433
1829         PR middle-end/110612
1830         * access-diagram.cc (class spatial_item): Add virtual dtor.
1832 2023-07-21  David Malcolm  <dmalcolm@redhat.com>
1834         PR analyzer/110387
1835         * region.h (struct cast_region::key_t): Support "m_type" being
1836         null by using "m_original_region" for empty/deleted slots.
1838 2023-07-19  David Malcolm  <dmalcolm@redhat.com>
1840         PR analyzer/110700
1841         * region-model-manager.cc
1842         (region_model_manager::get_or_create_int_cst): Assert that we have
1843         an integral or pointer type.
1844         * sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
1845         Don't check non-integral types.
1847 2023-06-29  benjamin priour  <priour.be@gmail.com>
1849         PR analyzer/110198
1850         * region-model-manager.cc
1851         (region_model_manager::get_or_create_initial_value): Take an
1852         optional boolean value to bypass poisoning checks
1853         * region-model-manager.h: Update declaration of the above function.
1854         * region-model.cc (region_model::get_store_value): No longer returns
1855         on OOB, but rather gives a boolean to get_or_create_initial_value.
1856         (region_model::check_region_access): Update docstring.
1857         (region_model::check_region_for_write): Update docstring.
1859 2023-06-24  David Malcolm  <dmalcolm@redhat.com>
1861         * access-diagram.cc: Add #define INCLUDE_VECTOR.
1862         * bounds-checking.cc: Likewise.
1864 2023-06-22  David Malcolm  <dmalcolm@redhat.com>
1866         PR analyzer/106626
1867         * access-diagram.cc: New file.
1868         * access-diagram.h: New file.
1869         * analyzer.h (class region_offset): Add default ctor.
1870         (region_offset::make_byte_offset): New decl.
1871         (region_offset::concrete_p): New.
1872         (region_offset::get_concrete_byte_offset): New.
1873         (region_offset::calc_symbolic_bit_offset): New decl.
1874         (region_offset::calc_symbolic_byte_offset): New decl.
1875         (region_offset::dump_to_pp): New decl.
1876         (region_offset::dump): New decl.
1877         (operator<, operator<=, operator>, operator>=): New decls for
1878         region_offset.
1879         * analyzer.opt
1880         (-param=analyzer-text-art-string-ellipsis-threshold=): New.
1881         (-param=analyzer-text-art-string-ellipsis-head-len=): New.
1882         (-param=analyzer-text-art-string-ellipsis-tail-len=): New.
1883         (-param=analyzer-text-art-ideal-canvas-width=): New.
1884         (fanalyzer-debug-text-art): New.
1885         * bounds-checking.cc: Include "intl.h", "diagnostic-diagram.h",
1886         and "analyzer/access-diagram.h".
1887         (class out_of_bounds::oob_region_creation_event_capacity): New.
1888         (out_of_bounds::out_of_bounds): Add "model" and "sval_hint"
1889         params.
1890         (out_of_bounds::mark_interesting_stuff): Use the base region.
1891         (out_of_bounds::add_region_creation_events): Use
1892         oob_region_creation_event_capacity.
1893         (out_of_bounds::get_dir): New pure vfunc.
1894         (out_of_bounds::maybe_show_notes): New.
1895         (out_of_bounds::maybe_show_diagram): New.
1896         (out_of_bounds::make_access_diagram): New.
1897         (out_of_bounds::m_model): New field.
1898         (out_of_bounds::m_sval_hint): New field.
1899         (out_of_bounds::m_region_creation_event_id): New field.
1900         (concrete_out_of_bounds::concrete_out_of_bounds): Update for new
1901         fields.
1902         (concrete_past_the_end::concrete_past_the_end): Likewise.
1903         (concrete_past_the_end::add_region_creation_events): Use
1904         oob_region_creation_event_capacity.
1905         (concrete_buffer_overflow::concrete_buffer_overflow): Update for
1906         new fields.
1907         (concrete_buffer_overflow::emit): Replace call to
1908         maybe_describe_array_bounds with maybe_show_notes.
1909         (concrete_buffer_overflow::get_dir): New.
1910         (concrete_buffer_over_read::concrete_buffer_over_read): Update for
1911         new fields.
1912         (concrete_buffer_over_read::emit): Replace call to
1913         maybe_describe_array_bounds with maybe_show_notes.
1914         (concrete_buffer_overflow::get_dir): New.
1915         (concrete_buffer_underwrite::concrete_buffer_underwrite): Update
1916         for new fields.
1917         (concrete_buffer_underwrite::emit): Replace call to
1918         maybe_describe_array_bounds with maybe_show_notes.
1919         (concrete_buffer_underwrite::get_dir): New.
1920         (concrete_buffer_under_read::concrete_buffer_under_read): Update
1921         for new fields.
1922         (concrete_buffer_under_read::emit): Replace call to
1923         maybe_describe_array_bounds with maybe_show_notes.
1924         (concrete_buffer_under_read::get_dir): New.
1925         (symbolic_past_the_end::symbolic_past_the_end): Update for new
1926         fields.
1927         (symbolic_buffer_overflow::symbolic_buffer_overflow): Likewise.
1928         (symbolic_buffer_overflow::emit): Call maybe_show_notes.
1929         (symbolic_buffer_overflow::get_dir): New.
1930         (symbolic_buffer_over_read::symbolic_buffer_over_read): Update for
1931         new fields.
1932         (symbolic_buffer_over_read::emit): Call maybe_show_notes.
1933         (symbolic_buffer_over_read::get_dir): New.
1934         (region_model::check_symbolic_bounds): Add "sval_hint" param.  Pass
1935         it and sized_offset_reg to diagnostics.
1936         (region_model::check_region_bounds): Add "sval_hint" param, passing
1937         it to diagnostics.
1938         * diagnostic-manager.cc
1939         (diagnostic_manager::emit_saved_diagnostic): Pass logger to
1940         pending_diagnostic::emit.
1941         * engine.cc: Add logger param to pending_diagnostic::emit
1942         implementations.
1943         * infinite-recursion.cc: Likewise.
1944         * kf-analyzer.cc: Likewise.
1945         * kf.cc: Likewise.  Add nullptr for new param of
1946         check_region_for_write.
1947         * pending-diagnostic.h: Likewise in decl.
1948         * region-model-manager.cc
1949         (region_model_manager::get_or_create_int_cst): Convert param from
1950         poly_int64 to const poly_wide_int_ref &.
1951         (region_model_manager::maybe_fold_binop): Support type being NULL
1952         when checking for floating-point types.
1953         Check for (X + Y) - X => Y.  Be less strict about types when folding
1954         associative ops.  Check for (X + Y) * CST => (X * CST) + (Y * CST).
1955         * region-model-manager.h
1956         (region_model_manager::get_or_create_int_cst): Convert param from
1957         poly_int64 to const poly_wide_int_ref &.
1958         * region-model.cc: Add logger param to pending_diagnostic::emit
1959         implementations.
1960         (region_model::check_external_function_for_access_attr): Update
1961         for new param of check_region_for_write.
1962         (region_model::deref_rvalue): Use nullptr rather than NULL.
1963         (region_model::get_capacity): Handle RK_STRING.
1964         (region_model::check_region_access): Add "sval_hint" param; pass it to
1965         check_region_bounds.
1966         (region_model::check_region_for_write): Add "sval_hint" param;
1967         pass it to check_region_access.
1968         (region_model::check_region_for_read): Add NULL for new param to
1969         check_region_access.
1970         (region_model::set_value): Pass rhs_sval to
1971         check_region_for_write.
1972         (region_model::get_representative_path_var_1): Handle SK_CONSTANT
1973         in the check for infinite recursion.
1974         * region-model.h (region_model::check_region_for_write): Add
1975         "sval_hint" param.
1976         (region_model::check_region_access): Likewise.
1977         (region_model::check_symbolic_bounds): Likewise.
1978         (region_model::check_region_bounds): Likewise.
1979         * region.cc (region_offset::make_byte_offset): New.
1980         (region_offset::calc_symbolic_bit_offset): New.
1981         (region_offset::calc_symbolic_byte_offset): New.
1982         (region_offset::dump_to_pp): New.
1983         (region_offset::dump): New.
1984         (struct linear_op): New.
1985         (operator<, operator<=, operator>, operator>=): New, for
1986         region_offset.
1987         (region::get_next_offset): New.
1988         (region::get_relative_symbolic_offset): Use ptrdiff_type_node.
1989         (field_region::get_relative_symbolic_offset): Likewise.
1990         (element_region::get_relative_symbolic_offset): Likewise.
1991         (bit_range_region::get_relative_symbolic_offset): Likewise.
1992         * region.h (region::get_next_offset): New decl.
1993         * sm-fd.cc: Add logger param to pending_diagnostic::emit
1994         implementations.
1995         * sm-file.cc: Likewise.
1996         * sm-malloc.cc: Likewise.
1997         * sm-pattern-test.cc: Likewise.
1998         * sm-sensitive.cc: Likewise.
1999         * sm-signal.cc: Likewise.
2000         * sm-taint.cc: Likewise.
2001         * store.cc (bit_range::contains_p): Allow "out" to be null.
2002         * store.h (byte_range::get_start_bit_offset): New.
2003         (byte_range::get_next_bit_offset): New.
2004         * varargs.cc: Add logger param to pending_diagnostic::emit
2005         implementations.
2007 2023-06-10  Tim Lange  <mail@tim-lange.me>
2009         PR analyzer/109577
2010         * constraint-manager.cc (class sval_finder): Visitor to find
2011         childs in svalue trees.
2012         (constraint_manager::sval_constrained_p): Add new function to
2013         check whether a sval might be part of an constraint.
2014         * constraint-manager.h: Add sval_constrained_p function.
2015         * region-model.cc (class size_visitor): Reverse behavior to not
2016         emit a warning on not explicitly considered cases.
2017         (region_model::check_region_size):
2018         Adapt to size_visitor changes.
2020 2023-06-09  David Malcolm  <dmalcolm@redhat.com>
2022         PR analyzer/110112
2023         * region-model.cc (region_model::get_initial_value_for_global):
2024         Move code to region::calc_initial_value_at_main.
2025         * region.cc (region::get_initial_value_at_main): New function.
2026         (region::calc_initial_value_at_main): New function, based on code
2027         in region_model::get_initial_value_for_global.
2028         (region::region): Initialize m_cached_init_sval_at_main.
2029         (decl_region::get_svalue_for_constructor): Add a cache, splitting
2030         out body to...
2031         (decl_region::calc_svalue_for_constructor): ...this new function.
2032         * region.h (region::get_initial_value_at_main): New decl.
2033         (region::calc_initial_value_at_main): New decl.
2034         (region::m_cached_init_sval_at_main): New field.
2035         (decl_region::decl_region): Initialize m_ctor_svalue.
2036         (decl_region::calc_svalue_for_constructor): New decl.
2037         (decl_region::m_ctor_svalue): New field.
2039 2023-06-08  Benjamin Priour  <vultkayn@gcc.gnu.org>
2041         * bounds-checking.cc (region_model::check_symbolic_bounds): Returns whether the BASE_REG
2042         region access was OOB.
2043         (region_model::check_region_bounds): Likewise.
2044         * region-model.cc (region_model::get_store_value): Creates an
2045         unknown svalue on OOB-read access to REG.
2046         (region_model::check_region_access): Returns whether an unknown svalue needs be created.
2047         (region_model::check_region_for_read): Passes check_region_access return value.
2048         * region-model.h: Update prior function definitions.
2050 2023-06-02  David Malcolm  <dmalcolm@redhat.com>
2052         PR analyzer/109015
2053         * kf.cc (class kf_atomic_exchange): New.
2054         (class kf_atomic_exchange_n): New.
2055         (class kf_atomic_fetch_op): New.
2056         (class kf_atomic_op_fetch): New.
2057         (class kf_atomic_load): New.
2058         (class kf_atomic_load_n): New.
2059         (class kf_atomic_store_n): New.
2060         (register_atomic_builtins): New function.
2061         (register_known_functions): Call register_atomic_builtins.
2063 2023-06-02  David Malcolm  <dmalcolm@redhat.com>
2065         * store.cc (store::eval_alias_1): Regions in different memory
2066         spaces can't alias.
2068 2023-05-18  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
2070         * region-model-manager.cc (get_code_for_cast): Use _P defines from
2071         tree.h.
2072         (region_model_manager::get_or_create_cast): Ditto.
2073         (region_model_manager::get_region_for_global): Ditto.
2074         * region-model.cc (region_model::get_lvalue_1): Ditto.
2075         * region.cc (decl_region::maybe_get_constant_value): Ditto.
2077 2023-03-22  David Malcolm  <dmalcolm@redhat.com>
2079         PR analyzer/109239
2080         * program-point.cc: Include "analyzer/inlining-iterator.h".
2081         (program_point::effectively_intraprocedural_p): New function.
2082         * program-point.h (program_point::effectively_intraprocedural_p):
2083         New decl.
2084         * sm-malloc.cc (deref_before_check::emit): Use it when rejecting
2085         interprocedural cases, so that we reject interprocedural cases
2086         that have become intraprocedural due to inlining.
2088 2023-03-18  David Malcolm  <dmalcolm@redhat.com>
2090         PR analyzer/109094
2091         * region-model.cc (region_model::on_longjmp): Pass false for
2092         new "eval_return_svalue" param of pop_frame.
2093         (region_model::pop_frame): Add new "eval_return_svalue" param and
2094         use it to suppress the call to get_rvalue on the result when
2095         needed by on_longjmp.
2096         * region-model.h (region_model::pop_frame): Add new
2097         "eval_return_svalue" param.
2099 2023-03-10  David Malcolm  <dmalcolm@redhat.com>
2101         PR analyzer/109059
2102         * region-model.cc (region_model::mark_region_as_unknown): Gather a
2103         set of maybe-live svalues and call on_maybe_live_values with it.
2104         * store.cc (binding_map::remove_overlapping_bindings): Add new
2105         "maybe_live_values" param; add any removed svalues to it.
2106         (binding_cluster::clobber_region): Add NULL as new param of
2107         remove_overlapping_bindings.
2108         (binding_cluster::mark_region_as_unknown): Add "maybe_live_values"
2109         param and pass it to remove_overlapping_bindings.
2110         (binding_cluster::maybe_get_compound_binding): Add NULL for new
2111         param of binding_map::remove_overlapping_bindings.
2112         (binding_cluster::remove_overlapping_bindings): Add
2113         "maybe_live_values" param and pass to
2114         binding_map::remove_overlapping_bindings.
2115         (store::set_value): Capture a set of maybe-live svalues, and call
2116         on_maybe_live_values with it.
2117         (store::on_maybe_live_values): New.
2118         (store::mark_region_as_unknown): Add "maybe_live_values" param
2119         and pass it to binding_cluster::mark_region_as_unknown.
2120         (store::remove_overlapping_bindings): Pass NULL for new param of
2121         binding_cluster::remove_overlapping_bindings.
2122         * store.h (binding_map::remove_overlapping_bindings): Add
2123         "maybe_live_values" param.
2124         (binding_cluster::mark_region_as_unknown): Likewise.
2125         (binding_cluster::remove_overlapping_bindings): Likewise.
2126         (store::mark_region_as_unknown): Likewise.
2127         (store::on_maybe_live_values): New decl.
2129 2023-03-10  David Malcolm  <dmalcolm@redhat.com>
2131         PR analyzer/108475
2132         PR analyzer/109060
2133         * sm-malloc.cc (deref_before_check::deref_before_check):
2134         Initialize new field m_deref_expr.  Assert that arg is non-NULL.
2135         (deref_before_check::emit): Reject cases where the spelling of the
2136         thing that was dereferenced differs from that of what is checked,
2137         or if the dereference expression was not found.  Remove code to
2138         handle NULL m_arg.
2139         (deref_before_check::describe_state_change): Remove code to handle
2140         NULL m_arg.
2141         (deref_before_check::describe_final_event): Likewise.
2142         (deref_before_check::sufficiently_similar_p): New.
2143         (deref_before_check::m_deref_expr): New field.
2144         (malloc_state_machine::maybe_complain_about_deref_before_check):
2145         Don't warn if the diag_ptr is NULL.
2147 2023-03-03  David Malcolm  <dmalcolm@redhat.com>
2149         * kf.cc (class kf_sprintf): New.
2150         (register_known_functions): Register it.
2152 2023-03-02  David Malcolm  <dmalcolm@redhat.com>
2154         PR analyzer/108968
2155         * region-model.cc (region_model::get_rvalue_1): Handle VAR_DECLs
2156         with a DECL_HARD_REGISTER by returning UNKNOWN.
2158 2023-03-02  Hans-Peter Nilsson  <hp@axis.com>
2160         * kf.cc (register_known_functions): Add __errno function for newlib.
2162 2023-03-01  David Malcolm  <dmalcolm@redhat.com>
2164         PR analyzer/107565
2165         * region-model.cc (region_model::on_call_pre): Flatten logic by
2166         returning early.  Consolidate logic for detecting const and pure
2167         functions.  When considering whether an unhandled built-in
2168         function has side-effects, consider all kinds of builtin, rather
2169         than just BUILT_IN_NORMAL, and don't require
2170         gimple_builtin_call_types_compatible_p.
2172 2023-03-01  David Malcolm  <dmalcolm@redhat.com>
2174         PR analyzer/108935
2175         * infinite-recursion.cc (contains_unknown_p): New.
2176         (sufficiently_different_region_binding_p): New function, splitting
2177         out inner loop from...
2178         (sufficiently_different_p): ...here.  Extend detection of unknown
2179         svalues to also include svalues that contain unknown.  Treat
2180         changes in frames below the entry to the recursion as being
2181         sufficiently different to reject being an infinite recursion.
2183 2023-02-21  David Malcolm  <dmalcolm@redhat.com>
2185         PR analyzer/108830
2186         * analyzer.opt (fanalyzer-suppress-followups): New option.
2187         * engine.cc (impl_region_model_context::warn): Terminate the path
2188         if the diagnostic's terminate_path_p vfunc returns true and
2189         -fanalyzer-suppress-followups is true (the default).
2190         (impl_sm_context::warn): Likewise, for both overloads.
2191         * pending-diagnostic.h (pending_diagnostic::terminate_path_p): New
2192         vfunc.
2193         * program-state.cc (program_state::on_edge): Terminate the path if
2194         the ctxt requests it during updating the edge.
2195         * region-model.cc (poisoned_value_diagnostic::terminate_path_p):
2196         New vfunc.
2197         * sm-malloc.cc (null_deref::terminate_path_p): New vfunc.
2198         (null_arg::terminate_path_p): New vfunc.
2200 2023-02-16  David Malcolm  <dmalcolm@redhat.com>
2202         PR analyzer/108806
2203         * constraint-manager.cc (bounded_range::dump_to_pp): Use
2204         bounded_range::singleton_p.
2205         (constraint_manager::add_bounded_ranges): Handle singleton ranges
2206         by adding an EQ_EXPR constraint.
2207         (constraint_manager::impossible_derived_conditions_p): New.
2208         (constraint_manager::eval_condition): Reject EQ_EXPR when it would
2209         imply impossible derived conditions.
2210         (selftest::test_bits): New.
2211         (selftest::run_constraint_manager_tests): Run it.
2212         * constraint-manager.h (bounded_range::singleton_p): New.
2213         (constraint_manager::impossible_derived_conditions_p): New decl.
2214         * region-model.cc (region_model::get_rvalue_1): Handle
2215         BIT_AND_EXPR, BIT_IOR_EXPR, and BIT_XOR_EXPR.
2217 2023-02-15  David Malcolm  <dmalcolm@redhat.com>
2219         PR analyzer/108664
2220         PR analyzer/108666
2221         PR analyzer/108725
2222         * diagnostic-manager.cc (epath_finder::get_best_epath): Add
2223         "target_stmt" param.
2224         (epath_finder::explore_feasible_paths): Likewise.
2225         (epath_finder::process_worklist_item): Likewise.
2226         (saved_diagnostic::calc_best_epath): Pass m_stmt to
2227         epath_finder::get_best_epath.
2228         * engine.cc (feasibility_state::maybe_update_for_edge): Move
2229         per-stmt logic to...
2230         (feasibility_state::update_for_stmt): ...this new function.
2231         * exploded-graph.h (feasibility_state::update_for_stmt): New decl.
2232         * feasible-graph.cc (feasible_node::get_state_at_stmt): New.
2233         * feasible-graph.h: Include "analyzer/exploded-graph.h".
2234         (feasible_node::get_state_at_stmt): New decl.
2235         * infinite-recursion.cc
2236         (infinite_recursion_diagnostic::check_valid_fpath_p): Update for
2237         vfunc signature change.
2238         * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
2239         Convert first param to a reference.  Add stmt param.
2240         * region-model.cc: Include "analyzer/feasible-graph.h".
2241         (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
2242         "check_expr" param.
2243         (poisoned_value_diagnostic::check_valid_fpath_p): New.
2244         (poisoned_value_diagnostic::m_check_expr): New field.
2245         (region_model::check_for_poison): Attempt to supply a check_expr
2246         to the diagnostic
2247         (region_model::deref_rvalue): Add NULL for new check_expr param
2248         of poisoned_value_diagnostic.
2249         (region_model::get_or_create_region_for_heap_alloc): Don't reuse
2250         regions that are marked as TOUCHED.
2252 2023-02-10  David Malcolm  <dmalcolm@redhat.com>
2254         PR analyzer/108745
2255         * sm-malloc.cc (deref_before_check::emit): Reject the warning if
2256         the check occurs within a macro defintion.
2258 2023-02-09  David Malcolm  <dmalcolm@redhat.com>
2260         PR analyzer/108733
2261         * state-purge.cc (get_candidate_for_purging): Add ADDR_EXPR
2262         and MEM_REF.
2264 2023-02-08  David Malcolm  <dmalcolm@redhat.com>
2266         PR analyzer/108704
2267         * state-purge.cc (state_purge_per_decl::process_point_backwards):
2268         Don't stop processing the decl if it's fully overwritten by
2269         this stmt if it's also used by this stmt.
2271 2023-02-07  David Malcolm  <dmalcolm@redhat.com>
2273         PR analyzer/108661
2274         * sm-fd.cc (class kf_read): New.
2275         (register_known_fd_functions): Register "read".
2276         * sm-file.cc (class kf_fread): Update comment.
2278 2023-02-02  David Malcolm  <dmalcolm@redhat.com>
2280         PR analyzer/108633
2281         * sm-fd.cc (fd_state_machine::check_for_fd_attrs): Add missing
2282         "continue".
2283         (fd_state_machine::on_listen): Don't issue phase-mismatch or
2284         type-mismatch warnings for the "invalid" state.
2286 2023-02-01  David Malcolm  <dmalcolm@redhat.com>
2288         PR analyzer/108616
2289         * pending-diagnostic.cc (fixup_location_in_macro_p): Add "alloca"
2290         to macros that we shouldn't unwind inside.
2292 2023-01-26  David Malcolm  <dmalcolm@redhat.com>
2294         PR analyzer/108524
2295         * analyzer.h (class feasible_node): New forward decl.
2296         * diagnostic-manager.cc (epath_finder::get_best_epath): Add "pd"
2297         param.
2298         (epath_finder::explore_feasible_paths): Likewise.
2299         (epath_finder::process_worklist_item): Likewise.  Use it to call
2300         pending_diagnostic::check_valid_fpath_p on the final fpath to
2301         give pending_diagnostic a way to add additional restrictions on
2302         feasibility.
2303         (saved_diagnostic::calc_best_epath): Pass pending_diagnostic to
2304         epath_finder::get_best_epath.
2305         * infinite-recursion.cc: Include "analyzer/feasible-graph.h".
2306         (infinite_recursion_diagnostic::check_valid_fpath_p): New.
2307         (infinite_recursion_diagnostic::fedge_uses_conjured_svalue_p): New.
2308         (infinite_recursion_diagnostic::expr_uses_conjured_svalue_p): New.
2309         * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
2310         New vfunc.
2312 2023-01-19  David Malcolm  <dmalcolm@redhat.com>
2314         PR analyzer/108455
2315         * analyzer.h (class checker_event): New forward decl.
2316         (class state_change_event): Indent.
2317         (class warning_event): New forward decl.
2318         * checker-event.cc (state_change_event::state_change_event): Add
2319         "enode" param.
2320         (warning_event::get_desc): Update for new param of
2321         evdesc::final_event ctor.
2322         * checker-event.h (state_change_event::state_change_event): Add
2323         "enode" param.
2324         (state_change_event::get_exploded_node): New accessor.
2325         (state_change_event::m_enode): New field.
2326         (warning_event::warning_event): New "enode" param.
2327         (warning_event::get_exploded_node): New accessor.
2328         (warning_event::m_enode): New field.
2329         * diagnostic-manager.cc
2330         (state_change_event_creator::on_global_state_change): Pass
2331         src_node to state_change_event ctor.
2332         (state_change_event_creator::on_state_change): Likewise.
2333         (null_assignment_sm_context::set_next_state): Pass NULL for
2334         new param of state_change_event ctor.
2335         * infinite-recursion.cc
2336         (infinite_recursion_diagnostic::add_final_event): Update for new
2337         param of warning_event ctor.
2338         * pending-diagnostic.cc (pending_diagnostic::add_final_event):
2339         Pass enode to warning_event ctor.
2340         * pending-diagnostic.h (evdesc::final_event): Add reference to
2341         warning_event.
2342         * sm-malloc.cc: Include "analyzer/checker-event.h" and
2343         "analyzer/exploded-graph.h".
2344         (deref_before_check::deref_before_check): Initialize new fields.
2345         (deref_before_check::emit): Reject warnings in which we were
2346         unable to determine the enodes of the dereference and the check.
2347         Reject warnings interprocedural warnings. Reject warnings in which
2348         the dereference doesn't dominate the check.
2349         (deref_before_check::describe_state_change): Set m_deref_enode.
2350         (deref_before_check::describe_final_event): Set m_check_enode.
2351         (deref_before_check::m_deref_enode): New field.
2352         (deref_before_check::m_check_enode): New field.
2354 2023-01-13  David Malcolm  <dmalcolm@redhat.com>
2356         PR analyzer/105273
2357         * region-model.cc (has_nondefault_case_for_value_p): New.
2358         (has_nondefault_cases_for_all_enum_values_p): New.
2359         (region_model::apply_constraints_for_gswitch): Skip
2360         implicitly-created "default" when switching on an enum
2361         and all enum values have non-default cases.
2362         (rejected_default_case::dump_to_pp): New.
2363         * region-model.h (region_model_context::possibly_tainted_p): New
2364         decl.
2365         (class rejected_default_case): New.
2366         * sm-taint.cc (region_model_context::possibly_tainted_p): New.
2367         * supergraph.cc (switch_cfg_superedge::dump_label_to_pp): Dump
2368         when implicitly_created_default_p.
2369         (switch_cfg_superedge::implicitly_created_default_p): New.
2370         * supergraph.h
2371         (switch_cfg_superedge::implicitly_created_default_p): New decl.
2373 2023-01-11  David Malcolm  <dmalcolm@redhat.com>
2375         PR analyzer/108252
2376         * kf.cc (class kf_strdup): New.
2377         (class kf_strndup): New.
2378         (register_known_functions): Register them.
2379         * region-model.cc (region_model::on_call_pre): Use
2380         &HEAP_ALLOCATED_REGION for the default result of an external
2381         function with the "malloc" attribute, rather than CONJURED_SVALUE.
2382         (region_model::get_or_create_region_for_heap_alloc): Allow
2383         "size_in_bytes" to be NULL.
2384         * store.cc (store::set_value): When handling *UNKNOWN = VAL,
2385         mark VAL as "maybe bound".
2387 2022-12-16  David Malcolm  <dmalcolm@redhat.com>
2389         PR analyzer/106479
2390         * kf.cc (kf_memcpy_memmove::impl_call_pre): Pass in source region
2391         to region_model::check_for_poison.
2392         * region-model-asm.cc (region_model::on_asm_stmt): Pass NULL
2393         region to region_model::check_for_poison.
2394         * region-model.cc (region_model::check_for_poison): Add
2395         "src_region" param, and pass it to poisoned_value_diagnostic.
2396         (region_model::on_assignment): Pass NULL region to
2397         region_model::check_for_poison.
2398         (region_model::get_rvalue): Likewise.
2399         * region-model.h (region_model::check_for_poison): Add
2400         "src_region" param.
2401         * sm-fd.cc (fd_state_machine::on_accept): Pass in source region
2402         to region_model::check_for_poison.
2403         * varargs.cc (kf_va_copy::impl_call_pre): Pass NULL region to
2404         region_model::check_for_poison.
2405         (kf_va_arg::impl_call_pre): Pass in source region to
2406         region_model::check_for_poison.
2408 2022-12-14  David Malcolm  <dmalcolm@redhat.com>
2410         PR analyzer/108065
2411         * region.cc (decl_region::get_svalue_for_initializer): Bail out to
2412         avoid calling binding_key::make with an empty region.
2413         * store.cc (binding_map::apply_ctor_val_to_range): Likewise.
2414         (binding_map::apply_ctor_pair_to_child_region): Likewise.
2415         (binding_cluster::bind): Likewise.
2416         (binding_cluster::purge_region): Likewise.
2417         (binding_cluster::maybe_get_compound_binding): Likewise.
2418         (binding_cluster::maybe_get_simple_value): Likewise.
2420 2022-12-09  David Malcolm  <dmalcolm@redhat.com>
2422         * analyzer.h (class known_function): Expand comment.
2423         * region-model-impl-calls.cc: Rename to...
2424         * kf.cc: ...this.
2425         * known-function-manager.h (class known_function_manager): Add
2426         leading comment.
2428 2022-12-09  David Malcolm  <dmalcolm@redhat.com>
2430         PR analyzer/108003
2431         * call-summary.cc
2432         (call_summary_replay::convert_region_from_summary_1): Convert
2433         heap_regs_in_use from auto_sbitmap to auto_bitmap.
2434         * region-model-manager.cc
2435         (region_model_manager::get_or_create_region_for_heap_alloc):
2436         Convert from sbitmap to bitmap.
2437         * region-model-manager.h: Likewise.
2438         * region-model.cc
2439         (region_model::get_or_create_region_for_heap_alloc): Convert from
2440         auto_sbitmap to auto_bitmap.
2441         (region_model::get_referenced_base_regions): Likewise.
2442         * region-model.h: Include "bitmap.h" rather than "sbitmap.h".
2443         (region_model::get_referenced_base_regions): Convert from
2444         auto_sbitmap to auto_bitmap.
2446 2022-12-09  David Malcolm  <dmalcolm@redhat.com>
2448         * region-model-impl-calls.cc (class kf_memcpy): Rename to...
2449         (class kf_memcpy_memmove): ...this.
2450         (kf_memcpy::impl_call_pre): Rename to...
2451         (kf_memcpy_memmove::impl_call_pre): ...this, and check the src for
2452         poison.
2453         (register_known_functions): Update for above renaming, and
2454         register BUILT_IN_MEMMOVE and BUILT_IN_MEMMOVE_CHK.
2456 2022-12-06  David Malcolm  <dmalcolm@redhat.com>
2458         PR analyzer/107882
2459         * region-model.cc (region_model::get_store_value): Return an
2460         unknown value for empty regions.
2461         (region_model::set_value): Bail on empty regions.
2462         * region.cc (region::empty_p): New.
2463         * region.h (region::empty_p): New decl.
2464         * state-purge.cc (same_binding_p): Bail if either region is empty.
2465         * store.cc (binding_key::make): Assert that a concrete binding's
2466         bit_size must be > 0.
2467         (binding_cluster::mark_region_as_unknown): Bail on empty regions.
2468         (binding_cluster::get_binding): Likewise.
2469         (binding_cluster::remove_overlapping_bindings): Likewise.
2470         (binding_cluster::on_unknown_fncall): Don't conjure values for
2471         empty regions.
2472         (store::fill_region): Bail on empty regions.
2473         * store.h (class concrete_binding): Update comment to reflect that
2474         the range of bits must be non-empty.
2475         (concrete_binding::concrete_binding): Assert that bit range is
2476         non-empty.
2478 2022-12-06  David Malcolm  <dmalcolm@redhat.com>
2480         PR analyzer/106325
2481         * region-model-manager.cc
2482         (region_model_manager::get_or_create_null_ptr): New.
2483         * region-model-manager.h
2484         (region_model_manager::get_or_create_null_ptr): New decl.
2485         * region-model.cc (region_model::on_top_level_param): Add
2486         "nonnull" param and make use of it.
2487         (region_model::push_frame): When handling a top-level entrypoint
2488         to the analysis, determine which params __attribute__((nonnull))
2489         applies to, and pass to on_top_level_param.
2490         * region-model.h (region_model::on_top_level_param): Add "nonnull"
2491         param.
2493 2022-12-06  David Malcolm  <dmalcolm@redhat.com>
2495         * analyzer.h (register_known_analyzer_functions): New decl.
2496         (register_known_functions_lang_cp): New decl.
2497         * call-details.cc: New file, split out from
2498         region-model-impl-calls.cc.
2499         * call-details.h: New file, split out from region-model.h.
2500         * call-info.cc: Include "analyzer/call-details.h".
2501         * call-summary.h: Likewise.
2502         * kf-analyzer.cc: New file, split out from
2503         region-model-impl-calls.cc.
2504         * kf-lang-cp.cc: Likewise.
2505         * known-function-manager.cc: Include "analyzer/call-details.h".
2506         * region-model-impl-calls.cc: Move definitions of call_details's
2507         member functions to call-details.cc.  Move class kf_analyzer_* to
2508         kf-analyzer.cc.  Move kf_operator_new and kf_operator_delete to
2509         kf-lang-cp.cc.  Refresh #includes accordingly.
2510         (register_known_functions): Replace registration of __analyzer_*
2511         functions with a call to register_known_analyzer_functions.
2512         Replace registration of C++ support functions with a call to
2513         register_known_functions_lang_cp.
2514         * region-model.h (class call_details): Move to new call-details.h.
2515         * sm-fd.cc: Include "analyzer/call-details.h".
2516         * sm-file.cc: Likewise.
2517         * sm-malloc.cc: Likewise.
2518         * varargs.cc: Likewise.
2520 2022-12-02  David Malcolm  <dmalcolm@redhat.com>
2522         * analyzer.h (struct event_loc_info): New forward decl.
2523         * bounds-checking.cc: Use event_loc_info throughout to bundle the
2524         loc, fndecl, depth triples.
2525         * call-info.cc: Likewise.
2526         * checker-event.cc: Likewise.
2527         * checker-event.h (struct event_loc_info): New decl.  Use it
2528         throughout to bundle the loc, fndecl, depth triples.
2529         * checker-path.cc: Likewise.
2530         * checker-path.h: Likewise.
2531         * diagnostic-manager.cc: Likewise.
2532         * engine.cc: Likewise.
2533         * infinite-recursion.cc: Likewise.
2534         * pending-diagnostic.cc: Likewise.
2535         * pending-diagnostic.h: Likewise.
2536         * region-model.cc: Likewise.
2537         * sm-signal.cc: Likewise.
2538         * varargs.cc: Likewise.
2540 2022-12-02  David Malcolm  <dmalcolm@redhat.com>
2542         PR analyzer/107851
2543         * analyzer.cc (make_label_text_n): Convert param "n" from int to
2544         unsigned HOST_WIDE_INT.
2545         * analyzer.h (make_label_text_n): Likewise for decl.
2546         * bounds-checking.cc: Include "analyzer/checker-event.h" and
2547         "analyzer/checker-path.h".
2548         (out_of_bounds::add_region_creation_events): New.
2549         (concrete_past_the_end::describe_region_creation_event): Replace
2550         with...
2551         (concrete_past_the_end::add_region_creation_events): ...this.
2552         (symbolic_past_the_end::describe_region_creation_event): Delete.
2553         * checker-event.cc (region_creation_event::region_creation_event):
2554         Update for dropping all member data.
2555         (region_creation_event::get_desc): Delete, splitting out into
2556         region_creation_event_memory_space::get_desc,
2557         region_creation_event_capacity::get_desc, and
2558         region_creation_event_debug::get_desc.
2559         (region_creation_event_memory_space::get_desc): New.
2560         (region_creation_event_capacity::get_desc): New.
2561         (region_creation_event_allocation_size::get_desc): New.
2562         (region_creation_event_debug::get_desc): New.
2563         * checker-event.h: Include "analyzer/program-state.h".
2564         (enum rce_kind): Delete.
2565         (class region_creation_event): Drop all member data.
2566         (region_creation_event::region_creation_event): Make protected.
2567         (region_creation_event::get_desc): Delete.
2568         (class region_creation_event_memory_space): New.
2569         (class region_creation_event_capacity): New.
2570         (class region_creation_event_allocation_size): New.
2571         (class region_creation_event_debug): New.
2572         * checker-path.cc (checker_path::add_region_creation_events): Add
2573         "pd" param.  Call pending_diangnostic::add_region_creation_events.
2574         Update for conversion of RCE_DEBUG to region_creation_event_debug.
2575         * checker-path.h (checker_path::add_region_creation_events): Add
2576         "pd" param.
2577         * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
2578         Pass pending_diagnostic to
2579         emission_path::add_region_creation_events.
2580         (diagnostic_manager::build_emission_path): Pass path_builder to
2581         add_event_on_final_node.
2582         (diagnostic_manager::add_event_on_final_node): Add "pb" param.
2583         Pass pending_diagnostic to
2584         emission_path::add_region_creation_events.
2585         (diagnostic_manager::add_events_for_eedge): Pass
2586         pending_diagnostic to emission_path::add_region_creation_events.
2587         * diagnostic-manager.h
2588         (diagnostic_manager::add_event_on_final_node): Add "pb" param.
2589         * pending-diagnostic.cc
2590         (pending_diagnostic::add_region_creation_events): New.
2591         * pending-diagnostic.h (struct region_creation): Delete.
2592         (pending_diagnostic::describe_region_creation_event): Delete.
2593         (pending_diagnostic::add_region_creation_events): New vfunc.
2594         * region-model.cc: Include "analyzer/checker-event.h" and
2595         "analyzer/checker-path.h".
2596         (dubious_allocation_size::dubious_allocation_size): Initialize
2597         m_has_allocation_event.
2598         (dubious_allocation_size::describe_region_creation_event): Delete.
2599         (dubious_allocation_size::describe_final_event): Update for
2600         replacement of m_allocation_event with m_has_allocation_event.
2601         (dubious_allocation_size::add_region_creation_events): New.
2602         (dubious_allocation_size::m_allocation_event): Replace with...
2603         (dubious_allocation_size::m_has_allocation_event): ...this.
2605 2022-12-02  David Malcolm  <dmalcolm@redhat.com>
2607         PR analyzer/107948
2608         * region-model-manager.cc
2609         (region_model_manager::maybe_fold_binop): Fold (0 - VAL) to -VAL.
2610         * region-model.cc (region_model::eval_condition): Handle e.g.
2611         "-X <= 0" as equivalent to X >= 0".
2613 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2615         PR analyzer/106626
2616         * bounds-checking.cc
2617         (symbolic_past_the_end::describe_final_event): Delete, moving to
2618         symbolic_buffer_overflow::describe_final_event and
2619         symbolic_buffer_over_read::describe_final_event, eliminating
2620         composition of text strings via "byte_str" and "m_dir_str".
2621         (symbolic_past_the_end::m_dir_str): Delete field.
2622         (symbolic_buffer_overflow::symbolic_buffer_overflow): Drop
2623         m_dir_str.
2624         (symbolic_buffer_overflow::describe_final_event): New, as noted
2625         above.
2626         (symbolic_buffer_over_read::symbolic_buffer_overflow): Drop
2627         m_dir_str.
2628         (symbolic_buffer_over_read::describe_final_event): New, as noted
2629         above.
2631 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2633         * bounds-checking.cc (class out_of_bounds): Split out from...
2634         (class concrete_out_of_bounds): New abstract subclass.
2635         (class past_the_end): Rename to...
2636         (class concrete_past_the_end): ...this, and make a subclass of
2637         concrete_out_of_bounds.
2638         (class buffer_overflow): Rename to...
2639         (class concrete_buffer_overflow): ...this, and make a subclass of
2640         concrete_past_the_end.
2641         (class buffer_over_read): Rename to...
2642         (class concrete_buffer_over_read): ...this, and make a subclass of
2643         concrete_past_the_end.
2644         (class buffer_underwrite): Rename to...
2645         (class concrete_buffer_underwrite): ...this, and make a subclass
2646         of concrete_out_of_bounds.
2647         (class buffer_under_read): Rename to...
2648         (class concrete_buffer_under_read): ...this, and make a subclass
2649         of concrete_out_of_bounds.
2650         (class symbolic_past_the_end): Convert to a subclass of
2651         out_of_bounds.
2652         (symbolic_buffer_overflow::get_kind): New.
2653         (symbolic_buffer_over_read::get_kind): New.
2654         (region_model::check_region_bounds): Update for renamings.
2655         * engine.cc (impl_sm_context::set_next_state): Eliminate
2656         "new_ctxt", passing NULL to get_rvalue instead.
2657         (impl_sm_context::warn): Likewise.
2659 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2661         PR analyzer/106626
2662         * bounds-checking.cc (out_of_bounds::get_memory_space): New.
2663         (buffer_overflow::emit): Use it.
2664         (class buffer_overread): Rename to...
2665         (class buffer_over_read): ...this.
2666         (buffer_over_read::emit): Specify which memory space the read is
2667         from, where known.  Change "overread" to "over-read".
2668         (class buffer_underflow): Rename to...
2669         (class buffer_underwrite): ...this.
2670         (buffer_underwrite::emit): Specify which memory space the write is
2671         to, where known.  Change "underflow" to "underwrite".
2672         (class buffer_underread): Rename to...
2673         (class buffer_under_read): Rename to...
2674         (buffer_under_read::emit): Specify which memory space the read is
2675         from, where known.  Change "underread" to "under-read".
2676         (symbolic_past_the_end::get_memory_space): New.
2677         (symbolic_buffer_overflow::emit): Use it.
2678         (class symbolic_buffer_overread): Rename to...
2679         (class symbolic_buffer_over_read): ...this.
2680         (symbolic_buffer_over_read::emit): Specify which memory space the
2681         read is from, where known.  Change "overread" to "over-read".
2682         (region_model::check_symbolic_bounds): Update for class renaming.
2683         (region_model::check_region_bounds): Likewise.
2685 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2687         PR analyzer/106626
2688         * bounds-checking.cc (out_of_bounds::maybe_describe_array_bounds):
2689         New.
2690         (buffer_overflow::emit): Call maybe_describe_array_bounds.
2691         (buffer_overread::emit): Likewise.
2692         (buffer_underflow::emit): Likewise.
2693         (buffer_underread::emit): Likewise.
2695 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2697         PR analyzer/106626
2698         * bounds-checking.cc (buffer_overflow::emit): Use inform_n.
2699         Update wording to clarify that we're talking about the size of
2700         the bad access, rather than its position.
2701         (buffer_overread::emit): Likewise.
2703 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2705         * bounds-checking.cc: New file, taken from region-model.cc.
2706         * region-model.cc (class out_of_bounds): Move to
2707         bounds-checking.cc.
2708         (class past_the_end): Likewise.
2709         (class buffer_overflow): Likewise.
2710         (class buffer_overread): Likewise.
2711         (class buffer_underflow): Likewise.
2712         (class buffer_underread): Likewise.
2713         (class symbolic_past_the_end): Likewise.
2714         (class symbolic_buffer_overflow): Likewise.
2715         (class symbolic_buffer_overread): Likewise.
2716         (region_model::check_symbolic_bounds): Likewise.
2717         (maybe_get_integer_cst_tree): Likewise.
2718         (region_model::check_region_bounds): Likewise.
2719         * region-model.h: Add comment.
2721 2022-12-01  David Malcolm  <dmalcolm@redhat.com>
2723         PR analyzer/107928
2724         * sm-fd.cc (fd_state_machine::on_bind): Handle m_constant_fd in
2725         the "success" outcome.
2726         (fd_state_machine::on_connect): Likewise.
2727         * sm-fd.dot: Add "constant_fd" state and its transitions.
2729 2022-11-30  David Malcolm  <dmalcolm@redhat.com>
2731         * region-model-impl-calls.cc (class kf_fgets): Move to sm-file.cc.
2732         (kf_fgets::impl_call_pre): Likewise.
2733         (class kf_fread): Likewise.
2734         (kf_fread::impl_call_pre): Likewise.
2735         (class kf_getchar): Likewise.
2736         (class kf_stdio_output_fn): Likewise.
2737         (register_known_functions): Move registration of
2738         BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2739         BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2740         BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2741         BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2742         BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2743         BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
2744         "getchar", "fgets", "fgets_unlocked", and "fread" to
2745         register_known_file_functions.
2746         * sm-file.cc (class kf_stdio_output_fn): Move here from
2747         region-model-impl-calls.cc.
2748         (class kf_fgets): Likewise.
2749         (class kf_fread): Likewise.
2750         (class kf_getchar): Likewise.
2751         (register_known_file_functions): Move registration of
2752         BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2753         BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2754         BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2755         BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2756         BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2757         BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
2758         "fgets", "fgets_unlocked", "fread", and "getchar" to here from
2759         register_known_functions.
2761 2022-11-30  David Malcolm  <dmalcolm@redhat.com>
2763         PR analyzer/103546
2764         * analyzer.h (register_known_file_functions): New decl.
2765         * program-state.cc (sm_state_map::replay_call_summary): Rejct
2766         attempts to store sm-state for caller_sval that can't have
2767         associated state.
2768         * region-model-impl-calls.cc (register_known_functions): Call
2769         register_known_file_functions.
2770         * sm-fd.cc (class kf_isatty): New.
2771         (register_known_fd_functions): Register it.
2772         * sm-file.cc (class kf_ferror): New.
2773         (class kf_fileno): New.
2774         (class kf_getc): New.
2775         (register_known_file_functions): New.
2777 2022-11-30  David Malcolm  <dmalcolm@redhat.com>
2779         PR analyzer/105784
2780         * region-model-manager.cc
2781         (region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
2782         PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
2783         type matches that of arg0 in favor of a cast.
2785 2022-11-24  Martin Liska  <mliska@suse.cz>
2787         * varargs.cc: Fix Clang warnings.
2789 2022-11-24  David Malcolm  <dmalcolm@redhat.com>
2791         PR analyzer/106473
2792         * call-summary.cc
2793         (call_summary_replay::convert_region_from_summary_1): Update for
2794         change to creation of heap-allocated regions.
2795         * program-state.cc (test_program_state_1): Likewise.
2796         (test_program_state_merging): Likewise.
2797         * region-model-impl-calls.cc (kf_calloc::impl_call_pre): Likewise.
2798         (kf_malloc::impl_call_pre): Likewise.
2799         (kf_operator_new::impl_call_pre): Likewise.
2800         (kf_realloc::impl_call_postsuccess_with_move::update_model): Likewise.
2801         * region-model-manager.cc
2802         (region_model_manager::create_region_for_heap_alloc): Convert
2803         to...
2804         (region_model_manager::get_or_create_region_for_heap_alloc):
2805         ...this, reusing an existing region if it's unreferenced in the
2806         client state.
2807         * region-model-manager.h (region_model_manager::get_num_regions): New.
2808          (region_model_manager::create_region_for_heap_alloc): Convert to...
2809          (region_model_manager::get_or_create_region_for_heap_alloc): ...this.
2810         * region-model.cc (region_to_value_map::can_merge_with_p): Reject
2811         merger when the values are different.
2812         (region_model::create_region_for_heap_alloc): Convert to...
2813         (region_model::get_or_create_region_for_heap_alloc): ...this.
2814         (region_model::get_referenced_base_regions): New.
2815         (selftest::test_state_merging):  Update for change to creation of
2816         heap-allocated regions.
2817         (selftest::test_malloc_constraints): Likewise.
2818         (selftest::test_malloc): Likewise.
2819         * region-model.h: Include "sbitmap.h".
2820         (region_model::create_region_for_heap_alloc): Convert to...
2821         (region_model::get_or_create_region_for_heap_alloc): ...this.
2822         (region_model::get_referenced_base_regions): New decl.
2823         * store.cc (store::canonicalize): Don't purge a heap-allocated region
2824         that's been marked as escaping.
2826 2022-11-24  David Malcolm  <dmalcolm@redhat.com>
2828         * checker-path.cc (checker_path::inject_any_inlined_call_events):
2829         Don't dump the address of the block when -fdump-noaddr.
2831 2022-11-24  David Malcolm  <dmalcolm@redhat.com>
2833         * region-model.h (region_model::on_socket): Delete decl.
2834         (region_model::on_bind): Likewise.
2835         (region_model::on_listen): Likewise.
2836         (region_model::on_accept): Likewise.
2837         (region_model::on_connect): Likewise.
2838         * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
2839         of region_model::on_socket into here, ...
2840         (region_model::on_socket): ...eliminating this function.
2841         (kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
2842         (region_model::on_bind): ...eliminating this function.
2843         (kf_listen::outcome_of_listen::update_model): Likewise fo
2844         on_listen...
2845         (region_model::on_listen): ...eliminating this function.
2846         (kf_accept::outcome_of_accept::update_model): Likewise fo
2847         on_accept...
2848         (region_model::on_accept): ...eliminating this function.
2849         (kf_connect::outcome_of_connect::update_model): Likewise fo
2850         on_connect...
2851         (region_model::on_connect): ...eliminating this function.
2853 2022-11-24  David Malcolm  <dmalcolm@redhat.com>
2855         * analyzer.h (register_known_fd_functions): New decl.
2856         * region-model-impl-calls.cc (class kf_accept): Move to sm-fd.cc.
2857         (class kf_bind): Likewise.
2858         (class kf_connect): Likewise.
2859         (class kf_listen): Likewise.
2860         (class kf_pipe): Likewise.
2861         (class kf_socket): Likewise.
2862         (register_known_functions): Remove registration of the above
2863         functions, instead calling register_known_fd_functions.
2864         * sm-fd.cc: Include "analyzer/call-info.h".
2865         (class kf_socket): Move here from region-model-impl-calls.cc.
2866         (class kf_bind): Likewise.
2867         (class kf_listen): Likewise.
2868         (class kf_accept): Likewise.
2869         (class kf_connect): Likewise.
2870         (class kf_pipe): Likewise.
2871         (register_known_fd_functions): New.
2873 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
2875         PR analyzer/107788
2876         * known-function-manager.cc (known_function_manager::get_match):
2877         Don't look up fndecls by name when they're not in the root
2878         namespace.
2880 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
2882         PR analyzer/107783
2883         * sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
2884         complain when old state is "fd-constant".
2885         (fd_state_machine::on_listen): Likewise.
2886         (fd_state_machine::on_accept): Likewise.
2888 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
2890         PR analyzer/107807
2891         * region-model-impl-calls.cc (register_known_functions): Register
2892         "___errno" and "__error" as synonyms  for "__errno_location".
2894 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
2896         * analyzer.h (class internal_known_function): New.
2897         (register_varargs_builtins): New decl.
2898         * engine.cc (exploded_node::on_stmt_pre): Remove
2899         "out_terminate_path" param from call to region_model::on_stmt_pre.
2900         (feasibility_state::maybe_update_for_edge): Likewise.
2901         * known-function-manager.cc: Include "basic-block.h", "gimple.h",
2902         and "analyzer/region-model.h".
2903         (known_function_manager::known_function_manager): Initialize
2904         m_combined_fns_arr.
2905         (known_function_manager::~known_function_manager): Clean up
2906         m_combined_fns_arr.
2907         (known_function_manager::get_by_identifier): Make const.
2908         (known_function_manager::add): New overloaded definitions for
2909         enum built_in_function and enum internal_fn.
2910         (known_function_manager::get_by_fndecl): Delete.
2911         (known_function_manager::get_match): New.
2912         (known_function_manager::get_internal_fn): New.
2913         (known_function_manager::get_normal_builtin): New.
2914         * known-function-manager.h
2915         (known_function_manager::get_by_identifier): Make private and
2916         add const qualifier.
2917         (known_function_manager::get_by_fndecl): Delete.
2918         (known_function_manager::add): Add overloaded decls for
2919         enum built_in_function name and enum internal_fn.
2920         (known_function_manager::get_match): New decl.
2921         (known_function_manager::get_internal_fn): New decl.
2922         (known_function_manager::get_normal_builtin): New decl.
2923         (known_function_manager::m_combined_fns_arr): New field.
2924         * region-model-impl-calls.cc (call_details::arg_is_size_p): New.
2925         (class kf_alloca): New.
2926         (region_model::impl_call_alloca): Convert to...
2927         (kf_alloca::impl_call_pre): ...this.
2928         (kf_analyzer_dump_capacity::matches_call_types_p): Rewrite check
2929         to use call_details::arg_is_pointer_p.
2930         (region_model::impl_call_builtin_expect): Convert to...
2931         (class kf_expect): ...this.
2932         (class kf_calloc): New, adding check that both arguments are
2933         size_t.
2934         (region_model::impl_call_calloc): Convert to...
2935         (kf_calloc::impl_call_pre): ...this.
2936         (kf_connect::matches_call_types_p): Rewrite check to use
2937         call_details::arg_is_pointer_p.
2938         (region_model::impl_call_error): Convert to...
2939         (class kf_error): ...this, and...
2940         (kf_error::impl_call_pre): ...this.
2941         (class kf_fgets): New, adding checks that args 0 and 2 are
2942         pointers.
2943         (region_model::impl_call_fgets): Convert to...
2944         (kf_fgets::impl_call_pre): ...this.
2945         (class kf_fread): New, adding checks on the argument types.
2946         (region_model::impl_call_fread): Convert to...
2947         (kf_fread::impl_call_pre): ...this.
2948         (class kf_free): New, adding check that the argument is a pointer.
2949         (region_model::impl_call_free): Convert to...
2950         (kf_free::impl_call_post): ...this.
2951         (class kf_getchar): New.
2952         (class kf_malloc): New, adding check that the argument is a
2953         size_t.
2954         (region_model::impl_call_malloc): Convert to...
2955         (kf_malloc::impl_call_pre): ...this.
2956         (class kf_memcpy): New, adding checks on arguments.
2957         (region_model::impl_call_memcpy): Convert to...
2958         (kf_memcpy::impl_call_pre): ...this.
2959         (class kf_memset): New.
2960         (region_model::impl_call_memset): Convert to...
2961         (kf_memset::impl_call_pre): ...this.
2962         (kf_pipe::matches_call_types_p): Rewrite check to use
2963         call_details::arg_is_pointer_p.
2964         (kf_putenv::matches_call_types_p): Likewise.
2965         (class kf_realloc): New, adding checks on the argument types.
2966         (region_model::impl_call_realloc): Convert to...
2967         (kf_realloc::impl_call_post): ...this.
2968         (class kf_strchr): New.
2969         (region_model::impl_call_strchr): Convert to...
2970         (kf_strchr::impl_call_post): ...this.
2971         (class kf_stack_restore): New.
2972         (class kf_stack_save): New.
2973         (class kf_stdio_output_fn): New.
2974         (class kf_strcpy): New,
2975         (region_model::impl_call_strcpy): Convert to...
2976         (kf_strcpy::impl_call_pre): ...this.
2977         (class kf_strlen): New.
2978         (region_model::impl_call_strlen): Convert to...
2979         (kf_strlen::impl_call_pre): ...this.
2980         (class kf_ubsan_bounds): New.
2981         (region_model::impl_deallocation_call): Reimplement to avoid call
2982         to impl_call_free.
2983         (register_known_functions): Add handlers for IFN_BUILTIN_EXPECT
2984         and IFN_UBSAN_BOUNDS.  Add handlers for BUILT_IN_ALLOCA,
2985         BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
2986         BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FPRINTF,
2987         BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2988         BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2989         BUILT_IN_FREE, BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED,
2990         BUILT_IN_MALLOC, BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK,
2991         BUILT_IN_MEMSET, BUILT_IN_MEMSET_CHK, BUILT_IN_PRINTF,
2992         BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2993         BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2994         BUILT_IN_PUTS_UNLOCKED, BUILT_IN_REALLOC, BUILT_IN_STACK_RESTORE,
2995         BUILT_IN_STACK_SAVE, BUILT_IN_STRCHR, BUILT_IN_STRCPY,
2996         BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN, BUILT_IN_VFPRINTF, and
2997         BUILT_IN_VPRINTF. Call register_varargs_builtins.  Add handlers
2998         for "getchar", "memset", "fgets", "fgets_unlocked", "fread",
2999         "error", and "error_at_line".
3000         * region-model.cc (region_model::on_stmt_pre): Drop
3001         "out_terminate_path" param.
3002         (region_model::get_known_function): Reimplement by calling
3003         known_function_manager::get_match, passing new "cd" param.
3004         Add overload taking enum internal_fn.
3005         (region_model::on_call_pre): Drop "out_terminate_path" param.
3006         Remove special-case handling of internal fns IFN_BUILTIN_EXPECT,
3007         IFN_UBSAN_BOUNDS, and IFN_VA_ARG, of built-in fns BUILT_IN_ALLOCA,
3008         BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
3009         BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FREE, BUILT_IN_MALLOC,
3010         BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMSET,
3011         BUILT_IN_MEMSET_CHK, BUILT_IN_REALLOC, BUILT_IN_STRCHR,
3012         BUILT_IN_STRCPY, BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN,
3013         BUILT_IN_STACK_SAVE, BUILT_IN_STACK_RESTORE, BUILT_IN_FPRINTF,
3014         BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED,
3015         BUILT_IN_FPUTC, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS,
3016         BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE,
3017         BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
3018         BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
3019         BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
3020         BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF, BUILT_IN_VA_START, and
3021         BUILT_IN_VA_COPY, and of named functions "malloc", "calloc",
3022         "alloca", "realloc", "error", "error_at_line", "fgets",
3023         "fgets_unlocked", "fread", "getchar", "memset", "strchr", and
3024         "strlen".  Replace all this special-casing with calls to
3025         get_known_function for internal fns and for fn decls.
3026         (region_model::on_call_post): Remove special-casing handling for
3027         "free" and "strchr", and for BUILT_IN_REALLOC, BUILT_IN_STRCHR,
3028         and BUILT_IN_VA_END.  Replace by consolidating on usage of
3029         get_known_function.
3030         * region-model.h (call_details::arg_is_size_p): New.
3031         (region_model::on_stmt_pre): Drop "out_terminate_path" param.
3032         (region_model::on_call_pre): Likewise.
3033         (region_model::impl_call_alloca): Delete.
3034         (region_model::impl_call_builtin_expect): Delete.
3035         (region_model::impl_call_calloc): Delete.
3036         (region_model::impl_call_error): Delete.
3037         (region_model::impl_call_fgets): Delete.
3038         (region_model::impl_call_fread): Delete.
3039         (region_model::impl_call_free): Delete.
3040         (region_model::impl_call_malloc): Delete.
3041         (region_model::impl_call_memcpy): Delete.
3042         (region_model::impl_call_memset): Delete.
3043         (region_model::impl_call_realloc): Delete.
3044         (region_model::impl_call_strchr): Delete.
3045         (region_model::impl_call_strcpy): Delete.
3046         (region_model::impl_call_strlen): Delete.
3047         (region_model::impl_call_va_start): Delete.
3048         (region_model::impl_call_va_copy): Delete.
3049         (region_model::impl_call_va_arg): Delete.
3050         (region_model::impl_call_va_end): Delete.
3051         (region_model::check_region_for_write): Public.
3052         (region_model::get_known_function): Add "cd" param.  Add
3053         overloaded decl taking enum internal_fn.
3054         * sm-malloc.cc: Update comments.
3055         * varargs.cc (class kf_va_start): New.
3056         (region_model::impl_call_va_start): Convert to...
3057         (kf_va_start::impl_call_pre): ...this.
3058         (class kf_va_copy): New.
3059         (region_model::impl_call_va_copy): Convert to...
3060         (kf_va_copy::impl_call_pre): ...this.
3061         (class kf_va_arg): New.
3062         (region_model::impl_call_va_arg): Convert to...
3063         (kf_va_arg::impl_call_pre): ...this.
3064         (class kf_va_end): New.
3065         (region_model::impl_call_va_end): Delete.
3066         (register_varargs_builtins): New.
3068 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
3070         PR analyzer/107788
3071         * region-model.cc (region_model::update_for_int_cst_return):
3072         Require that the return type be an integer type.
3073         (region_model::update_for_nonzero_return): Likewise.
3075 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
3077         PR analyzer/107783
3078         * region-model-impl-calls.cc (kf_accept::matches_call_types_p):
3079         Require that args 1 and 2 be pointers.
3080         (kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
3081         * region-model.h (call_details::arg_is_pointer_p): New
3083 2022-11-22  David Malcolm  <dmalcolm@redhat.com>
3085         PR analyzer/107777
3086         * call-summary.cc
3087         (call_summary_replay::convert_region_from_summary_1): Handle
3088         RK_THREAD_LOCAL and RK_ERRNO in switch.
3089         * region-model.cc (region_model::get_representative_path_var_1):
3090         Likewise.
3092 2022-11-19  David Malcolm  <dmalcolm@redhat.com>
3094         PR analyzer/107582
3095         * engine.cc (dynamic_call_info_t::update_model): Update the model
3096         by pushing or pop a frame, rather than by clobbering it with the
3097         model from the exploded_node's state.
3099 2022-11-18  David Malcolm  <dmalcolm@redhat.com>
3101         * analyzer.cc (is_pipe_call_p): Delete.
3102         * analyzer.h (is_pipe_call_p): Delete.
3103         * region-model-impl-calls.cc (call_details::get_location): New.
3104         (class kf_analyzer_break): New, adapted from
3105         region_model::on_stmt_pre.
3106         (region_model::impl_call_analyzer_describe): Convert to...
3107         (class kf_analyzer_describe): ...this.
3108         (region_model::impl_call_analyzer_dump_capacity): Convert to...
3109         (class kf_analyzer_dump_capacity): ...this.
3110         (region_model::impl_call_analyzer_dump_escaped): Convert to...
3111         (class kf_analyzer_dump_escaped): ...this.
3112         (class kf_analyzer_dump_exploded_nodes): New.
3113         (region_model::impl_call_analyzer_dump_named_constant): Convert
3114         to...
3115         (class kf_analyzer_dump_named_constant): ...this.
3116         (class dump_path_diagnostic): Move here from region-model.cc.
3117         (class kf_analyzer_dump_path) New, adapted from
3118         region_model::on_stmt_pre.
3119         (class kf_analyzer_dump_region_model): Likewise.
3120         (region_model::impl_call_analyzer_eval): Convert to...
3121         (class kf_analyzer_eval): ...this.
3122         (region_model::impl_call_analyzer_get_unknown_ptr): Convert to...
3123         (class kf_analyzer_get_unknown_ptr): ...this.
3124         (class known_function_accept): Rename to...
3125         (class kf_accept): ...this.
3126         (class known_function_bind): Rename to...
3127         (class kf_bind): ...this.
3128         (class known_function_connect): Rename to...
3129         (class kf_connect): ...this.
3130         (region_model::impl_call_errno_location): Convert to...
3131         (class kf_errno_location): ...this.
3132         (class known_function_listen): Rename to...
3133         (class kf_listen): ...this.
3134         (region_model::impl_call_pipe): Convert to...
3135         (class kf_pipe): ...this.
3136         (region_model::impl_call_putenv): Convert to...
3137         (class kf_putenv): ...this.
3138         (region_model::impl_call_operator_new): Convert to...
3139         (class kf_operator_new): ...this.
3140         (region_model::impl_call_operator_delete): Convert to...
3141         (class kf_operator_delete): ...this.
3142         (class known_function_socket): Rename to...
3143         (class kf_socket): ...this.
3144         (register_known_functions): Rename param to KFM.  Break out
3145         existing known functions into a "POSIX" section, and add "pipe",
3146         "pipe2", and "putenv".  Add debugging functions
3147         "__analyzer_break", "__analyzer_describe",
3148         "__analyzer_dump_capacity", "__analyzer_dump_escaped",
3149         "__analyzer_dump_exploded_nodes",
3150         "__analyzer_dump_named_constant", "__analyzer_dump_path",
3151         "__analyzer_dump_region_model", "__analyzer_eval",
3152         "__analyzer_get_unknown_ptr".  Add C++ support functions
3153         "operator new", "operator new []", "operator delete", and
3154         "operator delete []".
3155         * region-model.cc (class dump_path_diagnostic): Move to
3156         region-model-impl-calls.cc.
3157         (region_model::on_stmt_pre): Eliminate special-casing of
3158         "__analyzer_describe", "__analyzer_dump_capacity",
3159         "__analyzer_dump_escaped", "__analyzer_dump_named_constant",
3160         "__analyzer_dump_path", "__analyzer_dump_region_model",
3161         "__analyzer_eval", "__analyzer_break",
3162         "__analyzer_dump_exploded_nodes", "__analyzer_get_unknown_ptr",
3163         "__errno_location", "pipe", "pipe2", "putenv", "operator new",
3164         "operator new []", "operator delete", "operator delete []"
3165         "pipe" and "pipe2", handling them instead via the known_functions
3166         mechanism.
3167         * region-model.h (call_details::get_location): New decl.
3168         (region_model::impl_call_analyzer_describe): Delete decl.
3169         (region_model::impl_call_analyzer_dump_capacity): Delete decl.
3170         (region_model::impl_call_analyzer_dump_escaped): Delete decl.
3171         (region_model::impl_call_analyzer_dump_named_constant): Delete decl.
3172         (region_model::impl_call_analyzer_eval): Delete decl.
3173         (region_model::impl_call_analyzer_get_unknown_ptr): Delete decl.
3174         (region_model::impl_call_errno_location): Delete decl.
3175         (region_model::impl_call_pipe): Delete decl.
3176         (region_model::impl_call_putenv): Delete decl.
3177         (region_model::impl_call_operator_new): Delete decl.
3178         (region_model::impl_call_operator_delete): Delete decl.
3179         * sm-fd.cc: Update comments.
3181 2022-11-16  David Malcolm  <dmalcolm@redhat.com>
3183         PR analyzer/107711
3184         * analyzer-language.cc: Include "diagnostic.h".
3185         (maybe_stash_named_constant): Add logger param and use it to log
3186         the name being looked up, and the result.
3187         (stash_named_constants): New, splitting out from...
3188         (on_finish_translation_unit): ...this function.  Call
3189         get_or_create_logfile and use the result to create a logger
3190         instance, passing it to stash_named_constants.
3191         * analyzer.h (get_or_create_any_logfile): New decl.
3192         * engine.cc (dump_fout, owns_dump_fout): New globals, split out
3193         from run_checkers.
3194         (get_or_create_any_logfile): New function, split out from...
3195         (run_checkers): ...here, so that the logfile can be opened by
3196         on_finish_translation_unit.  Clear the globals when closing the
3197         dump file.
3199 2022-11-16  David Malcolm  <dmalcolm@redhat.com>
3201         * analyzer.h (known_function::matches_call_types_p): New vfunc.
3202         (known_function::impl_call_pre): Provide base implementation.
3203         (known_function::impl_call_post): New vfunc.
3204         (register_known_functions): New.
3205         * engine.cc (impl_run_checkers): Call register_known_functions.
3206         * region-model-impl-calls.cc (region_model::impl_call_accept):
3207         Convert to...
3208         (class known_function_accept): ...this.
3209         (region_model::impl_call_bind): Convert to...
3210         (class known_function_bind): ...this.
3211         (region_model::impl_call_connect): Convert to...
3212         (class known_function_connect): ...this.
3213         (region_model::impl_call_listen): Convert to...
3214         (class known_function_listen): ...this.
3215         (region_model::impl_call_socket): Convert to...
3216         (class known_function_socket): ...this.
3217         (register_known_functions): New.
3218         * region-model.cc (region_model::on_call_pre): Remove special
3219         case for "bind" in favor of the known_function-handling dispatch.
3220         Add call to known_function::matches_call_types_p to latter.
3221         (region_model::on_call_post): Remove special cases for "accept",
3222         "bind", "connect", "listen", and "socket" in favor of dispatch
3223         to known_function::impl_call_post.
3224         * region-model.h (region_model::impl_call_accept): Delete decl.
3225         (region_model::impl_call_bind): Delete decl.
3226         (region_model::impl_call_connect): Delete decl.
3227         (region_model::impl_call_listen): Delete decl.
3228         (region_model::impl_call_socket): Delete decl.
3229         * sm-fd.cc: Update comments.
3231 2022-11-16  David Malcolm  <dmalcolm@redhat.com>
3233         * checker-event.cc: New file, split out from...
3234         * checker-path.cc: ...this file.
3236 2022-11-15  David Malcolm  <dmalcolm@redhat.com>
3238         PR analyzer/106140
3239         * analyzer-language.cc (on_finish_translation_unit): Stash named
3240         constants "SOCK_STREAM" and "SOCK_DGRAM".
3241         * analyzer.opt (Wanalyzer-fd-phase-mismatch): New.
3242         (Wanalyzer-fd-type-mismatch): New.
3243         * engine.cc (impl_region_model_context::get_state_map_by_name):
3244         Add "out_sm_context" param.  Allow out_sm_idx to be NULL.
3245         * exploded-graph.h
3246         (impl_region_model_context::get_state_map_by_name):
3247         Add "out_sm_context" param.
3248         * region-model-impl-calls.cc (region_model::impl_call_accept): New.
3249         (region_model::impl_call_bind): New.
3250         (region_model::impl_call_connect): New.
3251         (region_model::impl_call_listen): New.
3252         (region_model::impl_call_socket): New.
3253         * region-model.cc (region_model::on_call_pre): Special-case
3254         "bind".
3255         (region_model::on_call_post): Special-case "accept", "bind",
3256         "connect", "listen", and "socket".
3257         * region-model.h (region_model::impl_call_accept): New decl.
3258         (region_model::impl_call_bind): New decl.
3259         (region_model::impl_call_connect): New decl.
3260         (region_model::impl_call_listen): New decl.
3261         (region_model::impl_call_socket): New decl.
3262         (region_model::on_socket): New decl.
3263         (region_model::on_bind): New decl.
3264         (region_model::on_listen): New decl.
3265         (region_model::on_accept): New decl.
3266         (region_model::on_connect): New decl.
3267         (region_model::add_constraint): Make public.
3268         (region_model::check_for_poison): Make public.
3269         (region_model_context::get_state_map_by_name): Add out_sm_context param.
3270         (region_model_context::get_fd_map): Likewise.
3271         (region_model_context::get_malloc_map): Likewise.
3272         (region_model_context::get_taint_map): Likewise.
3273         (noop_region_model_context::get_state_map_by_name): Likewise.
3274         (region_model_context_decorator::get_state_map_by_name): Likewise.
3275         * sm-fd.cc: Include "analyzer/supergraph.h" and
3276         "analyzer/analyzer-language.h".
3277         (enum expected_phase): New enum.
3278         (fd_state_machine::m_new_datagram_socket): New.
3279         (fd_state_machine::m_new_stream_socket): New.
3280         (fd_state_machine::m_new_unknown_socket): New.
3281         (fd_state_machine::m_bound_datagram_socket): New.
3282         (fd_state_machine::m_bound_stream_socket): New.
3283         (fd_state_machine::m_bound_unknown_socket): New.
3284         (fd_state_machine::m_listening_stream_socket): New.
3285         (fd_state_machine::m_m_connected_stream_socket): New.
3286         (fd_state_machine::m_SOCK_STREAM): New.
3287         (fd_state_machine::m_SOCK_DGRAM): New.
3288         (fd_diagnostic::describe_state_change): Handle socket states.
3289         (fd_diagnostic::get_meaning_for_state_change): Likewise.
3290         (class fd_phase_mismatch): New.
3291         (enum expected_type): New enum.
3292         (class fd_type_mismatch): New.
3293         (fd_state_machine::fd_state_machine): Initialize new states and
3294         stashed named constants.
3295         (fd_state_machine::is_socket_fd_p): New.
3296         (fd_state_machine::is_datagram_socket_fd_p): New.
3297         (fd_state_machine::is_stream_socket_fd_p): New.
3298         (fd_state_machine::on_close): Handle the socket states.
3299         (fd_state_machine::check_for_open_fd): Complain about fncalls on
3300         sockets in the wrong phase.  Support socket FDs.
3301         (add_constraint_ge_zero): New.
3302         (fd_state_machine::get_state_for_socket_type): New.
3303         (fd_state_machine::on_socket): New.
3304         (fd_state_machine::check_for_socket_fd): New.
3305         (fd_state_machine::check_for_new_socket_fd): New.
3306         (fd_state_machine::on_bind): New.
3307         (fd_state_machine::on_listen): New.
3308         (fd_state_machine::on_accept): New.
3309         (fd_state_machine::on_connect): New.
3310         (fd_state_machine::can_purge_p): Don't purge socket values.
3311         (get_fd_state): New.
3312         (region_model::mark_as_valid_fd): Use get_fd_state.
3313         (region_model::on_socket): New.
3314         (region_model::on_bind): New.
3315         (region_model::on_listen): New.
3316         (region_model::on_accept): New.
3317         (region_model::on_connect): New.
3318         * sm-fd.dot: Update to reflect sm-fd.cc changes.
3320 2022-11-15  David Malcolm  <dmalcolm@redhat.com>
3322         PR analyzer/106302
3323         * analyzer-language.cc: New file.
3324         * analyzer-language.h: New file.
3325         * analyzer.h (get_stashed_constant_by_name): New decl.
3326         (log_stashed_constants): New decl.
3327         * engine.cc (impl_run_checkers): Call log_stashed_constants.
3328         * region-model-impl-calls.cc
3329         (region_model::impl_call_analyzer_dump_named_constant): New.
3330         * region-model.cc (region_model::on_stmt_pre): Handle
3331         __analyzer_dump_named_constant.
3332         * region-model.h
3333         (region_model::impl_call_analyzer_dump_named_constant): New decl.
3334         * sm-fd.cc (fd_state_machine::m_O_ACCMODE): New.
3335         (fd_state_machine::m_O_RDONLY): New.
3336         (fd_state_machine::m_O_WRONLY): New.
3337         (fd_state_machine::fd_state_machine): Initialize the new fields.
3338         (fd_state_machine::get_access_mode_from_flag): Use the new fields,
3339         rather than using the host values.
3341 2022-11-13  David Malcolm  <dmalcolm@redhat.com>
3343         PR analyzer/106235
3344         * analyzer.opt (Wanalyzer-tainted-assertion): New.
3345         * checker-path.cc (checker_path::fixup_locations): Pass false to
3346         pending_diagnostic::fixup_location.
3347         * diagnostic-manager.cc (get_emission_location): Pass true to
3348         pending_diagnostic::fixup_location.
3349         * pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
3350         bool param.
3351         * pending-diagnostic.h (pending_diagnostic::fixup_location): Add
3352         bool param to decl.
3353         * sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
3354         (taint_diagnostic::describe_state_change): Drop "final".
3355         (class tainted_assertion): New.
3356         (taint_state_machine::taint_state_machine): Initialize
3357         m_tainted_control_flow.
3358         (taint_state_machine::alt_get_inherited_state): Support
3359         comparisons being tainted, based on their arguments.
3360         (is_assertion_failure_handler_p): New.
3361         (taint_state_machine::on_stmt): Complain about calls to assertion
3362         failure handlers guarded by an attacker-controller conditional.
3363         Detect attacker-controlled gcond conditionals and gswitch index
3364         values.
3365         (taint_state_machine::check_control_flow_arg_for_taint): New.
3367 2022-11-11  David Malcolm  <dmalcolm@redhat.com>
3369         * sm-fd.dot: Fix typo in comment.
3370         * sm-file.dot: New file.
3371         * varargs.cc: Fix typo in comment.
3372         * varargs.dot: New file.
3374 2022-11-11  David Malcolm  <dmalcolm@redhat.com>
3376         * checker-path.h: Split out checker_event and its subclasses to...
3377         * checker-event.h: ...this new header.
3379 2022-11-11  David Malcolm  <dmalcolm@redhat.com>
3381         PR analyzer/106147
3382         * analyzer.opt (Wanalyzer-infinite-recursion): New.
3383         * call-string.cc (call_string::count_occurrences_of_function):
3384         New.
3385         * call-string.h (call_string::count_occurrences_of_function): New
3386         decl.
3387         * checker-path.cc (function_entry_event::function_entry_event):
3388         New ctor.
3389         (checker_path::add_final_event): Delete.
3390         * checker-path.h (function_entry_event::function_entry_event): New
3391         ctor.
3392         (function_entry_event::get_desc): Drop "final".
3393         (checker_path::add_final_event): Delete.
3394         * diagnostic-manager.cc
3395         (diagnostic_manager::emit_saved_diagnostic): Create the final
3396         event via a new pending_diagnostic::add_final_event vfunc, rather
3397         than checker_path::add_final_event.
3398         (diagnostic_manager::add_events_for_eedge): Create function entry
3399         events via a new pending_diagnostic::add_function_entry_event
3400         vfunc.
3401         * engine.cc (exploded_graph::process_node): When creating a new
3402         PK_BEFORE_SUPERNODE node, call
3403         exploded_graph::detect_infinite_recursion on it after adding the
3404         in-edge.
3405         * exploded-graph.h (exploded_graph::detect_infinite_recursion):
3406         New decl.
3407         (exploded_graph::find_previous_entry_to): New decl.
3408         * infinite-recursion.cc: New file.
3409         * pending-diagnostic.cc
3410         (pending_diagnostic::add_function_entry_event): New.
3411         (pending_diagnostic::add_final_event): New.
3412         * pending-diagnostic.h
3413         (pending_diagnostic::add_function_entry_event): New vfunc.
3414         (pending_diagnostic::add_final_event): New vfunc.
3416 2022-11-10  David Malcolm  <dmalcolm@redhat.com>
3418         PR analyzer/99671
3419         * analyzer.opt (Wanalyzer-deref-before-check): New warning.
3420         * diagnostic-manager.cc
3421         (null_assignment_sm_context::set_next_state): Only add state
3422         change events for transition to "null" state.
3423         (null_assignment_sm_context::is_transition_to_null): New.
3424         * engine.cc (impl_region_model_context::on_pop_frame): New.
3425         * exploded-graph.h (impl_region_model_context::on_pop_frame): New
3426         decl.
3427         * program-state.cc (sm_state_map::clear_any_state): New.
3428         (sm_state_map::can_merge_with_p): New.
3429         (program_state::can_merge_with_p): Replace requirement that
3430         sm-states be equal in favor of an attempt to merge them.
3431         * program-state.h (sm_state_map::clear_any_state): New decl.
3432         (sm_state_map::can_merge_with_p): New decl.
3433         * region-model.cc (region_model::eval_condition): Make const.
3434         (region_model::pop_frame): Call ctxt->on_pop_frame.
3435         * region-model.h (region_model::eval_condition): Make const.
3436         (region_model_context::on_pop_frame): New vfunc.
3437         (noop_region_model_context::on_pop_frame): New.
3438         (region_model_context_decorator::on_pop_frame): New.
3439         * sm-malloc.cc (enum resource_state): Add RS_ASSUMED_NON_NULL.
3440         (allocation_state::dump_to_pp): Drop "final".
3441         (struct assumed_non_null_state): New subclass.
3442         (malloc_state_machine::m_assumed_non_null): New.
3443         (assumed_non_null_p): New.
3444         (class deref_before_check): New.
3445         (assumed_non_null_state::dump_to_pp): New.
3446         (malloc_state_machine::get_or_create_assumed_non_null_state_for_frame):
3447         New.
3448         (malloc_state_machine::maybe_assume_non_null): New.
3449         (malloc_state_machine::on_stmt): Transition from start state to
3450         "assumed-non-null" state for pointers passed to
3451         __attribute__((nonnull)) arguments, and for pointers explicitly
3452         dereferenced.  Call maybe_complain_about_deref_before_check for
3453         pointers explicitly compared against NULL.
3454         (malloc_state_machine::maybe_complain_about_deref_before_check):
3455         New.
3456         (malloc_state_machine::on_deallocator_call): Also transition
3457         "assumed-non-null" states to "freed".
3458         (malloc_state_machine::on_pop_frame): New.
3459         (malloc_state_machine::maybe_get_merged_states_nonequal): New.
3460         * sm-malloc.dot: Update for changes to sm-malloc.cc.
3461         * sm.h (state_machine::on_pop_frame): New.
3462         (state_machine::maybe_get_merged_state): New.
3463         (state_machine::maybe_get_merged_states_nonequal): New.
3465 2022-11-09  David Malcolm  <dmalcolm@redhat.com>
3467         * checker-path.cc (checker_event::debug): New.
3468         (checker_path::add_event): Move here from checker-path.h.  Add
3469         logging.
3470         * checker-path.h (checker_event::debug): New decl.
3471         (checker_path::checker_path): Add logger param.
3472         (checker_path::add_event): Move definition from here to
3473         checker-path.cc.
3474         (checker_path::m_logger): New field.
3475         * diagnostic-manager.cc
3476         (diagnostic_manager::emit_saved_diagnostic): Pass logger to
3477         checker_path ctor.
3478         (diagnostic_manager::add_events_for_eedge): Log scope when
3479         processing a run of stmts.
3481 2022-11-08  David Malcolm  <dmalcolm@redhat.com>
3483         PR analyzer/101962
3484         * region-model-impl-calls.cc: Update comment.
3485         * region-model.cc (region_model::check_symbolic_bounds): Fix
3486         layout of "void" return.  Replace usage of
3487         eval_condition_without_cm with eval_condition.
3488         (region_model::eval_condition): Take over body of...
3489         (region_model::eval_condition_without_cm): ...this subroutine,
3490         dropping the latter.  Eliminating this distinction avoids issues
3491         where constraints were not considered when recursing.
3492         (region_model::compare_initial_and_pointer): Update comment.
3493         (region_model::symbolic_greater_than): Replace usage of
3494         eval_condition_without_cm with eval_condition.
3495         * region-model.h
3496         (region_model::eval_condition_without_cm): Delete decl.
3498 2022-11-08  David Malcolm  <dmalcolm@redhat.com>
3500         * region-model-impl-calls.cc
3501         (region_model::impl_call_errno_location): New.
3502         * region-model-manager.cc
3503         (region_model_manager::region_model_manager): Initialize
3504         m_thread_local_region and m_errno_region.
3505         * region-model-manager.h (region_model_manager::get_errno_region):
3506         New accessor.
3507         (region_model_manager::m_thread_local_region): New.
3508         (region_model_manager::m_errno_region): New.
3509         * region-model.cc (region_model::on_call_pre): Special-case
3510         "__errno_location".
3511         (region_model::set_errno): New.
3512         * region-model.h (impl_call_errno_location): New decl.
3513         (region_model::set_errno): New decl.
3514         * region.cc (thread_local_region::dump_to_pp): New.
3515         (errno_region::dump_to_pp): New.
3516         * region.h (enum memory_space): Add MEMSPACE_THREAD_LOCAL.
3517         (enum region_kind): Add RK_THREAD_LOCAL and RK_ERRNO.
3518         (class thread_local_region): New.
3519         (is_a_helper <const thread_local_region *>::test): New.
3520         (class errno_region): New.
3521         (is_a_helper <const errno_region *>::test): New.
3522         * store.cc (binding_cluster::escaped_p): New.
3523         (store::escaped_p): Treat errno as always having escaped.
3524         (store::replay_call_summary_cluster): Handle RK_THREAD_LOCAL and
3525         RK_ERRNO.
3526         * store.h (binding_cluster::escaped_p): Remove definition.
3528 2022-11-08  David Malcolm  <dmalcolm@redhat.com>
3530         * call-info.cc (success_call_info::get_desc): Delete.
3531         (failed_call_info::get_desc): Likewise.
3532         (succeed_or_fail_call_info::get_desc): New.
3533         * call-info.h (class succeed_or_fail_call_info): New.
3534         (class success_call_info): Convert to a subclass of
3535         succeed_or_fail_call_info.
3536         (class failed_call_info): Likewise.
3538 2022-11-08  David Malcolm  <dmalcolm@redhat.com>
3540         * region-model-impl-calls.cc (region_model::impl_call_strchr):
3541         Move to on_call_post.  Handle both outcomes using bifurcation,
3542         rather than just the "not found" case.
3543         * region-model.cc (region_model::on_call_pre): Move
3544         BUILT_IN_STRCHR and "strchr" to...
3545         (region_model::on_call_post): ...here.
3547 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3549         * analyzer.h: Use std::unique_ptr for state machines from plugins.
3550         * engine.cc: Likewise.
3552 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3554         * analyzer.h: Use std::unique_ptr for known functions.
3555         * engine.cc: Likewise.
3556         * known-function-manager.cc: Likewise.
3557         * known-function-manager.h: Likewise.
3559 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3561         * analysis-plan.cc: Define INCLUDE_MEMORY before including
3562         system.h.
3563         * analyzer-pass.cc: Likewise.
3564         * analyzer-selftests.cc: Likewise.
3565         * analyzer.cc: Likewise.
3566         * analyzer.h: Use std::unique_ptr in bifurcation code.
3567         * call-string.cc: Define INCLUDE_MEMORY before including system.h.
3568         * complexity.cc: Likewise.
3569         * engine.cc: Use std::unique_ptr in bifurcation code.
3570         * exploded-graph.h: Likewise.
3571         * known-function-manager.cc: Define INCLUDE_MEMORY before
3572         including system.h.
3573         * region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
3574         code.
3575         * region-model.cc: Likewise.
3576         * region-model.h: Likewise.
3577         * supergraph.cc: Define INCLUDE_MEMORY before including system.h.
3579 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3581         * call-info.cc: Use std::unique_ptr for checker_event.
3582         * checker-path.cc: Likewise.
3583         * checker-path.h: Likewise.
3584         * diagnostic-manager.cc: Likewise.
3585         * engine.cc: Likewise.
3586         * pending-diagnostic.cc: Likewise.
3587         * sm-signal.cc: Likewise.
3588         * varargs.cc: Likewise.
3590 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3592         * diagnostic-manager.cc: Include "make-unique.h".
3593         Use std::unique_ptr for feasibility_problems and exploded_path.
3594         Delete explicit saved_diagnostic dtor.
3595         * diagnostic-manager.h: Likewise.
3596         * engine.cc: Likewise.
3597         * exploded-graph.h: Likewise.
3598         * feasible-graph.cc: Likewise.
3599         * feasible-graph.h: Likewise.
3601 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3603         * checker-path.cc (rewind_event::rewind_event): Update for usage of
3604         std::unique_ptr on custom_edge_info.
3605         * engine.cc (exploded_node::on_longjmp): Likewise.
3606         (exploded_edge::exploded_edge): Likewise.
3607         (exploded_edge::~exploded_edge): Delete.
3608         (exploded_graph::add_function_entry): Update for usage of
3609         std::unique_ptr on custom_edge_info.
3610         (exploded_graph::add_edge): Likewise.
3611         (add_tainted_args_callback): Likewise.
3612         (exploded_graph::maybe_create_dynamic_call): Likewise.
3613         (exploded_graph::process_node): Likewise.
3614         * exploded-graph.h (exploded_edge::~exploded_edge): Delete.
3615         (exploded_edge::m_custom_info): Use std::unique_ptr.
3616         (exploded_edge::add_edge): Likewise.
3617         * sm-signal.cc (register_signal_handler::impl_transition): Use
3618         make_unique.
3620 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3622         * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Make
3623         stmt_finder const.
3624         (saved_diagnostic::~saved_diagnostic): Remove explicit delete of
3625         m_stmt_finder.
3626         (diagnostic_manager::add_diagnostic): Make stmt_finder const.
3627         * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
3628         Likewise.
3629         (saved_diagnostic::m_stmt_finder): Convert to std::unique_ptr.
3630         (diagnostic_manager::add_diagnostic): Make stmt_finder const.
3631         * engine.cc (impl_sm_context::impl_sm_context): Likewise.
3632         (impl_sm_context::m_stmt_finder): Likewise.
3633         (leak_stmt_finder::clone): Convert return type to std::unique_ptr.
3634         * exploded-graph.h (stmt_finder::clone): Likewise.
3636 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3638         * call-info.cc: Add define of INCLUDE_MEMORY.
3639         * call-summary.cc: Likewise.
3640         * checker-path.cc: Likewise.
3641         * constraint-manager.cc: Likewise.
3642         * diagnostic-manager.cc: Likewise.
3643         (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for
3644         param d and field m_d.
3645         (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d.
3646         (saved_diagnostic::add_note): Use std::unique_ptr for
3647         param pn.
3648         (saved_diagnostic::get_pending_diagnostic): Update for conversion
3649         of m_sd.m_d to unique_ptr.
3650         (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
3651         param d.  Remove explicit deletion.
3652         (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
3653         (diagnostic_manager::emit_saved_diagnostic): Update for conversion
3654         of m_sd.m_d to unique_ptr.
3655         (null_assignment_sm_context::warn): Use std::unique_ptr for
3656         param d.  Remove explicit deletion.
3657         * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use
3658         std::unique_ptr for param d.
3659         (saved_diagnostic::add_note): Likewise for param pn.
3660         (saved_diagnostic::m_d): Likewise.
3661         (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
3662         param d.
3663         (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
3664         * engine.cc: Include "make-unique.h".
3665         (impl_region_model_context::warn): Update to use std::unique_ptr
3666         for param, removing explicit deletion.
3667         (impl_region_model_context::add_note): Likewise.
3668         (impl_sm_context::warn): Update to use std::unique_ptr
3669         for param.
3670         (impl_region_model_context::on_state_leak): Likewise for result of
3671         on_leak.
3672         (exploded_node::on_longjmp): Use make_unique when creating
3673         pending_diagnostic.
3674         (exploded_graph::process_node): Likewise.
3675         * exploded-graph.h (impl_region_model_context::warn): Update to
3676         use std::unique_ptr for param.
3677         (impl_region_model_context::add_note): Likewise.
3678         * feasible-graph.cc: Add define of INCLUDE_MEMORY.
3679         * pending-diagnostic.cc: Likewise.
3680         * pending-diagnostic.h: Include analyzer.sm.h"
3681         * program-point.cc: Add define of INCLUDE_MEMORY.
3682         * program-state.cc: Likewise.
3683         * region-model-asm.cc: Likewise.
3684         * region-model-impl-calls.cc: Likewise.  Include "make-unique.h".
3685         (region_model::impl_call_putenv): Use make_unique when creating
3686         pending_diagnostic.
3687         * region-model-manager.cc: Add define of INCLUDE_MEMORY.
3688         * region-model-reachability.cc: Likewise.
3689         * region-model.cc: Likewise.  Include "make-unique.h".
3690         (region_model::get_gassign_result): Use make_unique when creating
3691         pending_diagnostic.
3692         (region_model::check_for_poison): Likewise.
3693         (region_model::on_stmt_pre): Likewise.
3694         (region_model::check_symbolic_bounds): Likewise.
3695         (region_model::check_region_bounds): Likewise.
3696         (annotating_ctxt: make_note): Use std::unique_ptr for result.
3697         (region_model::deref_rvalue): Use make_unique when creating
3698         pending_diagnostic.
3699         (region_model::check_for_writable_region): Likewise.
3700         (region_model::check_region_size): Likewise.
3701         (region_model::check_dynamic_size_for_floats): Likewise.
3702         (region_model::maybe_complain_about_infoleak): Likewise.
3703         (noop_region_model_context::add_note): Use std::unique_ptr for
3704         param.  Remove explicit deletion.
3705         * region-model.h: Include "analyzer/pending-diagnostic.h".
3706         (region_model_context::warn): Convert param to std::unique_ptr.
3707         (region_model_context::add_note): Likewise.
3708         (noop_region_model_context::warn): Likewise.
3709         (noop_region_model_context::add_note): Likewise.
3710         (region_model_context_decorator::warn): Likewise.
3711         (region_model_context_decorator::add_note): Likewise.
3712         (note_adding_context::warn): Likewise.
3713         (note_adding_context::make_note): Likewise for return type.
3714         (test_region_model_context::warn): Convert param to
3715         std::unique_ptr.
3716         * region.cc: Add define of INCLUDE_MEMORY.
3717         * sm-fd.cc: Likewise.  Include "make-unique.h".
3718         (fd_state_machine::check_for_fd_attrs): Use make_unique when
3719         creating pending_diagnostics.
3720         (fd_state_machine::on_open): Likewise.
3721         (fd_state_machine::on_creat): Likewise.
3722         (fd_state_machine::check_for_dup): Likewise.
3723         (fd_state_machine::on_close): Likewise.
3724         (fd_state_machine::check_for_open_fd): Likewise.
3725         (fd_state_machine::on_leak): Likewise, converting return type to
3726         std::unique_ptr.
3727         * sm-file.cc: Add define of INCLUDE_MEMORY.  Include
3728         "make-unique.h".
3729         (fileptr_state_machine::on_stmt): Use make_unique when creating
3730         pending_diagnostic.
3731         (fileptr_state_machine::on_leak): Likewise, converting return type
3732         to std::unique_ptr.
3733         * sm-malloc.cc: Add define of INCLUDE_MEMORY.  Include
3734         "make-unique.h".
3735         (malloc_state_machine::on_stmt): Use make_unique when creating
3736         pending_diagnostic.
3737         (malloc_state_machine::handle_free_of_non_heap): Likewise.
3738         (malloc_state_machine::on_deallocator_call): Likewise.
3739         (malloc_state_machine::on_realloc_call): Likewise.
3740         (malloc_state_machine::on_leak): Likewise, converting return type
3741         to std::unique_ptr.
3742         * sm-pattern-test.cc: Add define of INCLUDE_MEMORY.  Include
3743         "make-unique.h".
3744         (pattern_test_state_machine::on_condition): Use make_unique when
3745         creating pending_diagnostic.
3746         * sm-sensitive.cc: Add define of INCLUDE_MEMORY.  Include
3747         "make-unique.h".
3748         (sensitive_state_machine::warn_for_any_exposure): Use make_unique
3749         when creating pending_diagnostic.
3750         * sm-signal.cc: Add define of INCLUDE_MEMORY.  Include
3751         "make-unique.h".
3752         (signal_state_machine::on_stmt): Use make_unique when creating
3753         pending_diagnostic.
3754         * sm-taint.cc: Add define of INCLUDE_MEMORY.  Include
3755         "make-unique.h".
3756         (taint_state_machine::check_for_tainted_size_arg): Use make_unique
3757         when creating pending_diagnostic.
3758         (taint_state_machine::check_for_tainted_divisor): Likewise.
3759         (region_model::check_region_for_taint): Likewise.
3760         (region_model::check_dynamic_size_for_taint): Likewise.
3761         * sm.cc: Add define of INCLUDE_MEMORY.  Include
3762         "analyzer/pending-diagnostic.h".
3763         (state_machine::on_leak): Move here from sm.h, changing return
3764         type to std::unique_ptr.
3765         * sm.h (state_machine::on_leak): Change return type to
3766         std::unique_ptr.  Move defn of base impl to sm.cc
3767         (sm_context::warn): Convert param d to std_unique_ptr.
3768         * state-purge.cc: Add define of INCLUDE_MEMORY.
3769         * store.cc: Likewise.
3770         * svalue.cc: Likewise.
3771         * trimmed-graph.cc: Likewise.
3772         * varargs.cc: Likewise.  Include "make-unique.h".
3773         (va_list_state_machine::check_for_ended_va_list): Use make_unique
3774         when creating pending_diagnostic.
3775         (va_list_state_machine::on_leak): Likewise, converting return type
3776         to std::unique_ptr.
3777         (region_model::impl_call_va_arg): Use make_unique when creating
3778         pending_diagnostic.
3780 2022-11-03  David Malcolm  <dmalcolm@redhat.com>
3782         PR analyzer/107486
3783         * analyzer.cc (is_pipe_call_p): New.
3784         * analyzer.h (is_pipe_call_p): New decl.
3785         * region-model.cc (region_model::on_call_pre): Use it.
3786         (region_model::on_call_post): Likewise.
3788 2022-10-26  David Malcolm  <dmalcolm@redhat.com>
3790         * sm-fd.cc (fd_state_machine::on_open): Transition to "unchecked"
3791         when the mode is symbolic, rather than just on integer constants.
3792         (fd_state_machine::check_for_open_fd): Don't complain about
3793         unchecked values in the start state.
3795 2022-10-26  David Malcolm  <dmalcolm@redhat.com>
3797         * sm-fd.dot: New file.
3799 2022-10-24  David Malcolm  <dmalcolm@redhat.com>
3801         PR analyzer/107349
3802         * varargs.cc (get_va_copy_arg): Fix the non-pointer case.
3804 2022-10-24  David Malcolm  <dmalcolm@redhat.com>
3806         PR analyzer/107345
3807         * region-model.cc (region_model::eval_condition_without_cm):
3808         Ensure that constants are on the right-hand side before checking
3809         for them.
3811 2022-10-24  David Malcolm  <dmalcolm@redhat.com>
3813         * engine.cc (impl_region_model_context::get_malloc_map): Replace
3814         with...
3815         (impl_region_model_context::get_state_map_by_name): ...this.
3816         (impl_region_model_context::get_fd_map): Delete.
3817         (impl_region_model_context::get_taint_map): Delete.
3818         * exploded-graph.h (impl_region_model_context::get_fd_map):
3819         Delete.
3820         (impl_region_model_context::get_malloc_map): Delete.
3821         (impl_region_model_context::get_taint_map): Delete.
3822         (impl_region_model_context::get_state_map_by_name): New.
3823         * region-model.h (region_model_context::get_state_map_by_name):
3824         New vfunc.
3825         (region_model_context::get_fd_map): Convert from vfunc to
3826         function.
3827         (region_model_context::get_malloc_map): Likewise.
3828         (region_model_context::get_taint_map): Likewise.
3829         (noop_region_model_context::get_state_map_by_name): New.
3830         (noop_region_model_context::get_fd_map): Delete.
3831         (noop_region_model_context::get_malloc_map): Delete.
3832         (noop_region_model_context::get_taint_map): Delete.
3833         (region_model_context_decorator::get_state_map_by_name): New.
3834         (region_model_context_decorator::get_fd_map): Delete.
3835         (region_model_context_decorator::get_malloc_map): Delete.
3836         (region_model_context_decorator::get_taint_map): Delete.
3838 2022-10-24  David Malcolm  <dmalcolm@redhat.com>
3840         PR analyzer/106300
3841         * engine.cc (impl_region_model_context::get_fd_map): New.
3842         * exploded-graph.h (impl_region_model_context::get_fd_map): New
3843         decl.
3844         * region-model-impl-calls.cc (region_model::impl_call_pipe): New.
3845         * region-model.cc (region_model::update_for_int_cst_return): New,
3846         based on...
3847         (region_model::update_for_zero_return): ...this.  Reimplement in
3848         terms of the former.
3849         (region_model::on_call_pre): Handle "pipe" and "pipe2".
3850         (region_model::on_call_post): Likewise.
3851         * region-model.h (region_model::impl_call_pipe): New decl.
3852         (region_model::update_for_int_cst_return): New decl.
3853         (region_model::mark_as_valid_fd): New decl.
3854         (region_model_context::get_fd_map): New pure virtual fn.
3855         (noop_region_model_context::get_fd_map): New.
3856         (region_model_context_decorator::get_fd_map): New.
3857         * sm-fd.cc: Include "analyzer/program-state.h".
3858         (fd_state_machine::describe_state_change): Handle transitions from
3859         start state to valid states.
3860         (fd_state_machine::mark_as_valid_fd): New.
3861         (fd_state_machine::on_stmt): Add missing return for "creat".
3862         (region_model::mark_as_valid_fd): New.
3864 2022-10-19  David Malcolm  <dmalcolm@redhat.com>
3866         PR analyzer/105765
3867         * varargs.cc (get_BT_VALIST_ARG): Rename to...
3868         (get_va_copy_arg): ...this, and update logic for determining level
3869         of indirection of va_copy's argument to use type of argument,
3870         rather than looking at va_list_type_node, to correctly handle
3871         __builtin_ms_va_copy.
3872         (get_stateful_BT_VALIST_ARG): Rename to...
3873         (get_stateful_va_copy_arg): ...this.
3874         (va_list_state_machine::on_va_copy): Update for renaming.
3875         (region_model::impl_call_va_copy): Likewise.
3877 2022-10-13  David Malcolm  <dmalcolm@redhat.com>
3879         PR analyzer/107210
3880         * svalue.cc (constant_svalue::maybe_fold_bits_within): Only
3881         attempt to extract individual bits when tree_fits_uhwi_p.
3883 2022-10-07  David Malcolm  <dmalcolm@redhat.com>
3885         PR analyzer/105783
3886         * region-model.cc (selftest::get_bit): New function.
3887         (selftest::test_bits_within_svalue_folding): New.
3888         (selfftest::analyzer_region_model_cc_tests): Call it.
3889         * svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
3890         case of extracting a single bit.
3892 2022-10-06  David Malcolm  <dmalcolm@redhat.com>
3894         PR analyzer/107158
3895         * store.cc (store::replay_call_summary_cluster): Eliminate
3896         special-casing of RK_HEAP_ALLOCATED in favor of sharing code with
3897         RK_DECL, avoiding an ICE due to attempting to bind a
3898         compound_svalue into a binding_cluster when an svalue in the
3899         summary cluster converts to a compound_svalue in the caller.
3901 2022-10-06  David Malcolm  <dmalcolm@redhat.com>
3903         * call-summary.cc (call_summary_replay::dump_to_pp): Bulletproof
3904         against NULL caller regions/svalues.
3906 2022-10-05  David Malcolm  <dmalcolm@redhat.com>
3908         * analysis-plan.cc: Simplify includes.
3909         * analyzer-pass.cc: Likewise.
3910         * analyzer-selftests.cc: Likewise.
3911         * analyzer.cc: Likewise.
3912         * analyzer.h: Add includes of "json.h" and "tristate.h".
3913         * call-info.cc: Simplify includes.
3914         * call-string.cc: Likewise.
3915         * call-summary.cc: Likewise.
3916         * checker-path.cc: Likewise.
3917         * complexity.cc: Likewise.
3918         * constraint-manager.cc: Likewise.
3919         * diagnostic-manager.cc: Likewise.
3920         * engine.cc: Likewise.
3921         * feasible-graph.cc: Likewise.
3922         * known-function-manager.cc: Likewise.
3923         * pending-diagnostic.cc: Likewise.
3924         * program-point.cc: Likewise.
3925         * program-state.cc: Likewise.
3926         * region-model-asm.cc: Likewise.
3927         * region-model-impl-calls.cc: Likewise.
3928         * region-model-manager.cc: Likewise.
3929         * region-model-reachability.cc: Likewise.
3930         * region-model.cc: Likewise.
3931         * region-model.h: Include "selftest.h".
3932         * region.cc: Simplify includes.
3933         * sm-fd.cc: Likewise.
3934         * sm-file.cc: Likewise.
3935         * sm-malloc.cc: Likewise.
3936         * sm-pattern-test.cc: Likewise.
3937         * sm-sensitive.cc: Likewise.
3938         * sm-signal.cc: Likewise.
3939         * sm-taint.cc: Likewise.
3940         * sm.cc: Likewise.
3941         * state-purge.cc: Likewise.
3942         * store.cc: Likewise.
3943         * store.h: Likewise.
3944         * supergraph.cc: Likewise.
3945         * svalue.cc: Likewise.
3946         * svalue.h: Likewise.
3947         * trimmed-graph.cc: Likewise.
3948         * varargs.cc: Likewise.
3950 2022-10-05  David Malcolm  <dmalcolm@redhat.com>
3952         PR analyzer/107060
3953         * call-summary.cc
3954         (call_summary_replay::convert_svalue_from_summary_1): Handle NULL
3955         results from convert_svalue_from_summary in SK_UNARY_OP and
3956         SK_BIN_OP.
3957         * engine.cc (impl_region_model_context::on_unknown_change): Bail
3958         out on svalues that can't have associated state.
3959         * region-model-impl-calls.cc
3960         (region_model::impl_call_analyzer_get_unknown_ptr): New.
3961         * region-model.cc (region_model::on_stmt_pre): Handle
3962         "__analyzer_get_unknown_ptr".
3963         * region-model.h
3964         (region_model::impl_call_analyzer_get_unknown_ptr): New decl.
3965         * store.cc (store::replay_call_summary_cluster): Avoid trying to
3966         create binding clusters for base regions that shouldn't have them.
3968 2022-10-05  Martin Liska  <mliska@suse.cz>
3970         * call-summary.cc (call_summary_replay::call_summary_replay):
3971         Remove unused variable and arguments.
3972         * call-summary.h: Likewise.
3973         * engine.cc (exploded_node::on_stmt): Likewise.
3974         (exploded_node::replay_call_summaries): Likewise.
3975         (exploded_node::replay_call_summary): Likewise.
3976         * exploded-graph.h (class exploded_node): Likewise.
3978 2022-10-05  David Malcolm  <dmalcolm@redhat.com>
3980         PR analyzer/107072
3981         * analyzer-logging.h: Include "diagnostic-core.h".
3982         * analyzer.h: Include "function.h".
3983         (class call_summary): New forward decl.
3984         (class call_summary_replay): New forward decl.
3985         (struct per_function_data): New forward decl.
3986         (struct interesting_t): New forward decl.
3987         (custom_edge_info::update_state): New vfunc.
3988         * call-info.cc (custom_edge_info::update_state): New.
3989         * call-summary.cc: New file.
3990         * call-summary.h: New file.
3991         * constraint-manager.cc: Include "analyzer/call-summary.h".
3992         (class replay_fact_visitor): New.
3993         (constraint_manager::replay_call_summary): New.
3994         * constraint-manager.h (constraint_manager::replay_call_summary):
3995         New.
3996         * engine.cc: Include "analyzer/call-summary.h".
3997         (exploded_node::on_stmt): Handle call summaries.
3998         (class call_summary_edge_info): New.
3999         (exploded_node::replay_call_summaries): New.
4000         (exploded_node::replay_call_summary): New.
4001         (per_function_data::~per_function_data): New.
4002         (per_function_data::add_call_summary): Move here from header and
4003         reimplement.
4004         (exploded_graph::process_node): Call update_state rather than
4005         update_model when handling bifurcation
4006         (viz_callgraph_node::dump_dot): Use a regular label rather
4007         than an HTML table; add summaries to dump.
4008         * exploded-graph.h: Include "alloc-pool.h", "fibonacci_heap.h",
4009         "supergraph.h", "sbitmap.h", "shortest-paths.h", "analyzer/sm.h",
4010         "analyzer/program-state.h", and "analyzer/diagnostic-manager.h".
4011         (exploded_node::replay_call_summaries): New decl.
4012         (exploded_node::replay_call_summary): New decl.
4013         (per_function_data::~per_function_data): New decl.
4014         (per_function_data::add_call_summary): Move implemention from
4015         header.
4016         (per_function_data::m_summaries): Update type of element.
4017         * known-function-manager.h: Include "analyzer/analyzer-logging.h".
4018         * program-point.h: Include "pretty-print.h" and
4019         "analyzer/call-string.h".
4020         * program-state.cc: Include "analyzer/call-summary.h".
4021         (sm_state_map::replay_call_summary): New.
4022         (program_state::replay_call_summary): New.
4023         * program-state.h (sm_state_map::replay_call_summary): New decl.
4024         (program_state::replay_call_summary): New decl.
4025         * region-model-manager.cc
4026         (region_model_manager::get_or_create_asm_output_svalue): New
4027         overload.
4028         * region-model-manager.h
4029         (region_model_manager::get_or_create_asm_output_svalue): New
4030         overload decl.
4031         * region-model.cc: Include "analyzer/call-summary.h".
4032         (region_model::maybe_update_for_edge): Remove call to
4033         region_model::update_for_call_summary on
4034         SUPEREDGE_INTRAPROCEDURAL_CALL.
4035         (region_model::update_for_call_summary): Delete.
4036         (region_model::replay_call_summary): New.
4037         * region-model.h (region_model::replay_call_summary): New decl.
4038         (region_model::update_for_call_summary): Delete decl.
4039         * store.cc: Include "analyzer/call-summary.h".
4040         (store::replay_call_summary): New.
4041         (store::replay_call_summary_cluster): New.
4042         * store.h: Include "tristate.h".
4043         (is_a_helper <const ana::concrete_binding *>::test): New.
4044         (store::replay_call_summary): New decl.
4045         (store::replay_call_summary_cluster): New decl.
4046         * supergraph.cc (get_ultimate_function_for_cgraph_edge): Remove
4047         "static" from decl.
4048         (supergraph_call_edge): Make stmt param const.
4049         * supergraph.h: Include "ordered-hash-map.h", "cfg.h",
4050         "basic-block.h", "gimple.h", "gimple-iterator.h", and "digraph.h".
4051         (supergraph_call_edge): Make stmt param const.
4052         (get_ultimate_function_for_cgraph_edge): New decl.
4053         * svalue.cc (compound_svalue::compound_svalue): Assert that we're
4054         not nesting compound_svalues.
4055         * svalue.h: Include "json.h", "analyzer/store.h", and
4056         "analyzer/program-point.h".
4057         (asm_output_svalue::get_num_outputs): New accessor.
4059 2022-10-05  David Malcolm  <dmalcolm@redhat.com>
4061         * region-model.h: Include "analyzer/region-model-manager.h"
4062         (class region_model_manager): Move decl to...
4063         * region-model-manager.h: ...this new file.
4065 2022-10-05  David Malcolm  <dmalcolm@redhat.com>
4067         * region-model-manager.cc
4068         (region_model_manager::maybe_fold_unaryop): Fold -(-(VAL)) to VAL.
4070 2022-10-05  David Malcolm  <dmalcolm@redhat.com>
4072         * region-model-manager.cc
4073         (region_model_manager::get_or_create_widening_svalue): Use a
4074         function_point rather than a program_point.
4075         * region-model.cc (selftest::test_widening_constraints): Likewise.
4076         * region-model.h
4077         (region_model_manager::get_or_create_widening_svalue): Likewise.
4078         (model_merger::get_function_point): New.
4079         * svalue.cc (svalue::can_merge_p): Use a function_point rather
4080         than a program_point.
4081         (svalue::can_merge_p): Likewise.
4082         * svalue.h (widening_svalue::key_t): Likewise.
4083         (widening_svalue::widening_svalue): Likewise.
4085 2022-09-12  Martin Liska  <mliska@suse.cz>
4087         * region-model.cc (region_model::maybe_complain_about_infoleak):
4088         Remove unused fields.
4090 2022-09-11  Tim Lange  <mail@tim-lange.me>
4092         PR analyzer/106845
4093         * region-model.cc (region_model::check_region_bounds):
4094         Bail out if 0 bytes were accessed.
4095         * store.cc (byte_range::dump_to_pp):
4096         Add special case for empty ranges.
4097         (byte_range::exceeds_p): Restrict to non-empty ranges.
4098         (byte_range::falls_short_of_p): Restrict to non-empty ranges.
4099         * store.h (bit_range::empty_p): New function.
4100         (bit_range::get_last_byte_offset): Restrict to non-empty ranges.
4101         (byte_range::empty_p): New function.
4102         (byte_range::get_last_byte_offset): Restrict to non-empty ranges.
4104 2022-09-09  David Malcolm  <dmalcolm@redhat.com>
4106         * analyzer.opt (Wanalyzer-exposure-through-uninit-copy): New.
4107         * checker-path.cc (region_creation_event::region_creation_event):
4108         Add "capacity" and "kind" params.
4109         (region_creation_event::get_desc): Generalize to different kinds
4110         of event.
4111         (checker_path::add_region_creation_event): Convert to...
4112         (checker_path::add_region_creation_events): ...this.
4113         * checker-path.h (enum rce_kind): New.
4114         (region_creation_event::region_creation_event): Add "capacity" and
4115         "kind" params.
4116         (region_creation_event::m_capacity): New field.
4117         (region_creation_event::m_rce_kind): New field.
4118         (checker_path::add_region_creation_event): Convert to...
4119         (checker_path::add_region_creation_events): ...this.
4120         * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
4121         Update for multiple region creation events.
4122         (diagnostic_manager::add_event_on_final_node): Likewise.
4123         (diagnostic_manager::add_events_for_eedge): Likewise.
4124         * region-model-impl-calls.cc (call_details::get_logger): New.
4125         * region-model.cc: Define INCLUDE_MEMORY before including
4126         "system.h".  Include "gcc-rich-location.h".
4127         (class record_layout): New.
4128         (class exposure_through_uninit_copy): New.
4129         (contains_uninit_p): New.
4130         (region_model::maybe_complain_about_infoleak): New.
4131         * region-model.h (call_details::get_logger): New decl.
4132         (region_model::maybe_complain_about_infoleak): New decl.
4133         (region_model::mark_as_tainted): New decl.
4134         * sm-taint.cc (region_model::mark_as_tainted): New.
4136 2022-09-09  David Malcolm  <dmalcolm@redhat.com>
4138         * analyzer.h (class known_function_manager): New forward decl.
4139         (class known_function): New.
4140         (plugin_analyzer_init_iface::register_known_function): New.
4141         * engine.cc: Include "analyzer/known-function-manager.h".
4142         (plugin_analyzer_init_impl::plugin_analyzer_init_impl): Add
4143         known_fn_mgr param.
4144         (plugin_analyzer_init_impl::register_state_machine): Add
4145         LOC_SCOPE.
4146         (plugin_analyzer_init_impl::register_known_function): New.
4147         (plugin_analyzer_init_impl::m_known_fn_mgr): New.
4148         (impl_run_checkers): Update plugin callback invocation to use
4149         eng's known_function_manager.
4150         * known-function-manager.cc: New file.
4151         * known-function-manager.h: New file.
4152         * region-model-manager.cc
4153         (region_model_manager::region_model_manager): Pass logger to
4154         m_known_fn_mgr's ctor.
4155         * region-model.cc (region_model::update_for_zero_return): New.
4156         (region_model::update_for_nonzero_return): New.
4157         (maybe_simplify_upper_bound): New.
4158         (region_model::maybe_get_copy_bounds): New.
4159         (region_model::get_known_function): New.
4160         (region_model::on_call_pre): Handle plugin-supplied known
4161         functions.
4162         * region-model.h: Include "analyzer/known-function-manager.h".
4163         (region_model_manager::get_known_function_manager): New.
4164         (region_model_manager::m_known_fn_mgr): New.
4165         (call_details::get_model): New accessor.
4166         (region_model::maybe_get_copy_bounds): New decl.
4167         (region_model::update_for_zero_return): New decl.
4168         (region_model::update_for_nonzero_return): New decl.
4169         (region_model::get_known_function): New decl.
4170         (region_model::get_known_function_manager): New.
4172 2022-09-08  Tim Lange  <mail@tim-lange.me>
4174         PR analyzer/106625
4175         * analyzer.h (region_offset): Eliminate m_is_symbolic member.
4176         * region-model-impl-calls.cc (region_model::impl_call_realloc):
4177         Refine implementation to be more precise.
4178         * region-model.cc (class symbolic_past_the_end):
4179         Abstract diagnostic class to complain about accesses past the end
4180         with symbolic values.
4181         (class symbolic_buffer_overflow):
4182         Concrete diagnostic class to complain about buffer overflows with
4183         symbolic values.
4184         (class symbolic_buffer_overread):
4185         Concrete diagnostic class to complain about buffer overreads with
4186         symbolic values.
4187         (region_model::check_symbolic_bounds): New function.
4188         (maybe_get_integer_cst_tree): New helper function.
4189         (region_model::check_region_bounds):
4190         Add call to check_symbolic_bounds if offset is not concrete.
4191         (region_model::eval_condition_without_cm):
4192         Add support for EQ_EXPR and GT_EXPR with binaryop_svalues.
4193         (is_positive_svalue): New hleper function.
4194         (region_model::symbolic_greater_than):
4195         New function to handle GT_EXPR comparisons with symbolic values.
4196         (region_model::structural_equality): New function to compare
4197         whether two svalues are structured the same, i.e. evaluate to
4198         the same value.
4199         (test_struct): Reflect changes to region::calc_offset.
4200         (test_var): Likewise.
4201         (test_array_2): Likewise and add selftest with symbolic i.
4202         * region-model.h (class region_model): Add check_symbolic_bounds,
4203         symbolic_greater_than and structural_equality.
4204         * region.cc (region::get_offset):
4205         Reflect changes to region::calc_offset.
4206         (region::calc_offset):
4207         Compute the symbolic offset if the offset is not concrete.
4208         (region::get_relative_symbolic_offset): New function to return the
4209         symbolic offset in bytes relative to its parent.
4210         (field_region::get_relative_symbolic_offset): Likewise.
4211         (element_region::get_relative_symbolic_offset): Likewise.
4212         (offset_region::get_relative_symbolic_offset): Likewise.
4213         (bit_range_region::get_relative_symbolic_offset): Likewise.
4214         * region.h: Add get_relative_symbolic_offset.
4215         * store.cc (binding_key::make):
4216         Reflect changes to region::calc_offset.
4217         (binding_map::apply_ctor_val_to_range): Likewise.
4218         (binding_map::apply_ctor_pair_to_child_region): Likewise.
4219         (binding_cluster::bind_compound_sval): Likewise.
4220         (binding_cluster::get_any_binding): Likewise.
4221         (binding_cluster::maybe_get_compound_binding): Likewise.
4223 2022-09-05  Tim Lange  <mail@tim-lange.me>
4225         * region-model-impl-calls.cc (region_model::impl_call_strcpy):
4226         Handle the constant string case.
4227         * region-model.cc (region_model::get_string_size):
4228         New function to get the string size from a region or svalue.
4229         * region-model.h (class region_model): Add get_string_size.
4231 2022-09-05  Tim Lange  <mail@tim-lange.me>
4233         * region.cc (cast_region::get_relative_concrete_offset):
4234         New overloaded method.
4235         * region.h: Add cast_region::get_relative_concrete_offset.
4237 2022-08-22  Martin Liska  <mliska@suse.cz>
4239         * region-model.cc: Add missing final keyword.
4241 2022-08-18  Tim Lange  <mail@tim-lange.me>
4243         PR analyzer/106181
4244         * analyzer.opt: Add Wanalyzer-imprecise-floating-point-arithmetic.
4245         * region-model.cc (is_any_cast_p): Formatting.
4246         (region_model::check_region_size): Ensure precondition.
4247         (class imprecise_floating_point_arithmetic): New abstract
4248         diagnostic class for all floating-point related warnings.
4249         (class float_as_size_arg): Concrete diagnostic class to complain
4250         about floating-point operands inside the size argument.
4251         (class contains_floating_point_visitor):
4252         New visitor to find floating-point operands inside svalues.
4253         (region_model::check_dynamic_size_for_floats): New function.
4254         (region_model::set_dynamic_extents):
4255         Call to check_dynamic_size_for_floats.
4256         * region-model.h (class region_model):
4257         Add region_model::check_dynamic_size_for_floats.
4259 2022-08-16  Martin Liska  <mliska@suse.cz>
4261         * region-model.cc: Fix -Winconsistent-missing-override clang
4262         warning.
4263         * region.h: Likewise.
4265 2022-08-15  David Malcolm  <dmalcolm@redhat.com>
4267         PR analyzer/106626
4268         * region-model.cc (buffer_overread::emit): Fix copy&paste error in
4269         direction of the access in the note.
4271 2022-08-15  David Malcolm  <dmalcolm@redhat.com>
4273         PR analyzer/106573
4274         * region-model.cc (region_model::on_call_pre): Use check_call_args
4275         when ensuring that we call get_arg_svalue on all args.  Remove
4276         redundant call from handling for stdio builtins.
4278 2022-08-15  Immad Mir  <mirimmad@outlook.com>
4280         PR analyzer/106551
4281         * sm-fd.cc (check_for_dup): exit early if first
4282         argument is invalid for all dup functions.
4284 2022-08-12  Tim Lange  <mail@tim-lange.me>
4286         PR analyzer/106000
4287         * analyzer.opt: Add Wanalyzer-out-of-bounds.
4288         * region-model.cc (class out_of_bounds): Diagnostics base class
4289         for all out-of-bounds diagnostics.
4290         (class past_the_end): Base class derived from out_of_bounds for
4291         the buffer_overflow and buffer_overread diagnostics.
4292         (class buffer_overflow): Buffer overflow diagnostics.
4293         (class buffer_overread): Buffer overread diagnostics.
4294         (class buffer_underflow): Buffer underflow diagnostics.
4295         (class buffer_underread): Buffer overread diagnostics.
4296         (region_model::check_region_bounds): New function to check region
4297         bounds for out-of-bounds accesses.
4298         (region_model::check_region_access):
4299         Add call to check_region_bounds.
4300         (region_model::get_representative_tree): New function that accepts
4301         a region instead of an svalue.
4302         * region-model.h (class region_model):
4303         Add region_model::check_region_bounds.
4304         * region.cc (region::symbolic_p): New predicate.
4305         (offset_region::get_byte_size_sval): Only return the remaining
4306         byte size on offset_regions.
4307         * region.h: Add region::symbolic_p.
4308         * store.cc (byte_range::intersects_p):
4309         Add new function equivalent to bit_range::intersects_p.
4310         (byte_range::exceeds_p): New function.
4311         (byte_range::falls_short_of_p): New function.
4312         * store.h (struct byte_range): Add byte_range::intersects_p,
4313         byte_range::exceeds_p and byte_range::falls_short_of_p.
4315 2022-08-12  Tim Lange  <mail@tim-lange.me>
4317         PR analyzer/106539
4318         * region-model-impl-calls.cc (region_model::impl_call_realloc):
4319         Use the result of get_copied_size as the size for the
4320         sized_regions in realloc.
4321         (success_with_move::get_copied_size): New function.
4323 2022-08-11  Immad Mir  <mirimmad@outlook.com>
4325         PR analyzer/106551
4326         * sm-fd.cc (check_for_dup): handle the m_start
4327         state when transitioning the state of LHS
4328         of dup, dup2 and dup3 call.
4330 2022-08-09  David Malcolm  <dmalcolm@redhat.com>
4332         PR analyzer/106573
4333         * region-model.cc (region_model::on_call_pre): Ensure that we call
4334         get_arg_svalue on all arguments.
4336 2022-08-05  David Malcolm  <dmalcolm@redhat.com>
4338         PR analyzer/105947
4339         * analyzer.opt (Wanalyzer-jump-through-null): New option.
4340         * engine.cc (class jump_through_null): New.
4341         (exploded_graph::process_node): Complain about jumps through NULL
4342         function pointers.
4344 2022-08-02  Immad Mir  <mirimmad@outlook.com>
4346         PR analyzer/106298
4347         * sm-fd.cc (fd_state_machine::on_open): Add
4348         creat, dup, dup2 and dup3 functions.
4349         (enum dup): New.
4350         (fd_state_machine::valid_to_unchecked_state): New.
4351         (fd_state_machine::on_creat): New.
4352         (fd_state_machine::on_dup): New.
4354 2022-07-28  David Malcolm  <dmalcolm@redhat.com>
4356         PR analyzer/105893
4357         * analyzer.opt (Wanalyzer-putenv-of-auto-var): New.
4358         * region-model-impl-calls.cc (class putenv_of_auto_var): New.
4359         (region_model::impl_call_putenv): New.
4360         * region-model.cc (region_model::on_call_pre): Handle putenv.
4361         * region-model.h (region_model::impl_call_putenv): New decl.
4363 2022-07-28  David Malcolm  <dmalcolm@redhat.com>
4365         * sm-malloc.cc (free_of_non_heap::emit): Add comment about CWE.
4366         * sm-taint.cc (tainted_size::emit): Likewise.
4368 2022-07-28  David Malcolm  <dmalcolm@redhat.com>
4370         * region.h: Add notes to the comment describing the region
4371         class hierarchy.
4373 2022-07-27  Immad Mir  <mirimmad@outlook.com>
4375         PR analyzer/106286
4376         * sm-fd.cc:
4377         (fd_diagnostic::get_meaning_for_state_change): New.
4379 2022-07-26  David Malcolm  <dmalcolm@redhat.com>
4381         PR analyzer/106319
4382         * store.cc (store::set_value): Don't strip away casts if the
4383         region has NULL type.
4385 2022-07-26  David Malcolm  <dmalcolm@redhat.com>
4387         * region.h (code_region::get_element): Remove stray decl.
4388         (function_region::get_element): Likewise.
4390 2022-07-25  Martin Liska  <mliska@suse.cz>
4392         * sm-fd.cc: Run dos2unix and fix coding style issues.
4394 2022-07-23  Immad Mir  <mirimmad@outlook.com>
4396         * sm-fd.cc (fd_param_diagnostic): New diagnostic class.
4397         (fd_access_mode_mismatch): Change inheritance from fd_diagnostic
4398         to fd_param_diagnostic. Add new overloaded constructor.
4399         (fd_use_after_close): Likewise.
4400         (unchecked_use_of_fd): Likewise and also change name to fd_use_without_check.
4401         (double_close): Change name to fd_double_close.
4402         (enum access_directions): New.
4403         (fd_state_machine::on_stmt): Handle calls to function with the
4404         new three function attributes.
4405         (fd_state_machine::check_for_fd_attrs): New.
4406         (fd_state_machine::on_open): Use the new overloaded constructors
4407         of diagnostic classes.
4409 2022-07-22  David Malcolm  <dmalcolm@redhat.com>
4411         PR analyzer/106413
4412         * varargs.cc (region_model::impl_call_va_start): Avoid iterating
4413         through non-existant variadic arguments by initializing the
4414         impl_region to "UNKNOWN" if the va_start occurs in the top-level
4415         function to the analysis.
4417 2022-07-22  David Malcolm  <dmalcolm@redhat.com>
4419         PR analyzer/106401
4420         * store.cc (binding_cluster::binding_cluster): Remove overzealous
4421         assertion; we're checking for tracked_p in
4422         store::get_or_create_cluster.
4424 2022-07-22  Tim Lange  <mail@tim-lange.me>
4426         PR analyzer/106394
4427         * region-model.cc (capacity_compatible_with_type): Always return true
4428         if alloc_size is zero.
4430 2022-07-21  David Malcolm  <dmalcolm@redhat.com>
4432         PR analyzer/106383
4433         * varargs.cc (region_model::impl_call_va_arg): When determining if
4434         we're doing interprocedural analysis, use the stack depth of the
4435         frame in which va_start was called, rather than the current stack
4436         depth.
4438 2022-07-21  David Malcolm  <dmalcolm@redhat.com>
4440         * sm-taint.cc (tainted_array_index::emit): Bulletproof against
4441         NULL m_arg.
4442         (tainted_array_index::describe_final_event): Likewise.
4443         (tainted_size::emit): Likewise.
4444         (tainted_size::describe_final_event): Likewise.
4446 2022-07-21  David Malcolm  <dmalcolm@redhat.com>
4448         PR analyzer/106374
4449         * region.cc (decl_region::get_svalue_for_initializer): Bail out on
4450         untracked regions.
4452 2022-07-20  David Malcolm  <dmalcolm@redhat.com>
4454         PR analyzer/106373
4455         * sm-taint.cc (taint_state_machine::on_condition): Potentially
4456         update the state of the RHS as well as the LHS.
4458 2022-07-20  David Malcolm  <dmalcolm@redhat.com>
4460         PR analyzer/106359
4461         * region.h (string_region::tracked_p): New.
4462         * store.cc (binding_cluster::binding_cluster): Move here from
4463         store.h.  Add assertion that base_region is tracked_p.
4464         * store.h (binding_cluster::binding_cluster): Move to store.cc.
4466 2022-07-19  David Malcolm  <dmalcolm@redhat.com>
4468         PR analyzer/106321
4469         * constraint-manager.h (bounded_ranges::get_count): New.
4470         (bounded_ranges::get_range): New.
4471         * engine.cc (impl_region_model_context::on_bounded_ranges): New.
4472         * exploded-graph.h (impl_region_model_context::on_bounded_ranges):
4473         New decl.
4474         * region-model.cc (region_model::apply_constraints_for_gswitch):
4475         Potentially call ctxt->on_bounded_ranges.
4476         * region-model.h (region_model_context::on_bounded_ranges): New
4477         vfunc.
4478         (noop_region_model_context::on_bounded_ranges): New.
4479         (region_model_context_decorator::on_bounded_ranges): New.
4480         * sm-taint.cc: Include "analyzer/constraint-manager.h".
4481         (taint_state_machine::on_bounded_ranges): New.
4482         * sm.h (state_machine::on_bounded_ranges): New.
4484 2022-07-19  David Malcolm  <dmalcolm@redhat.com>
4486         * engine.cc (exploded_graph::process_node): Show any description
4487         of the out-edge when logging it for consideration.
4489 2022-07-15  David Malcolm  <dmalcolm@redhat.com>
4491         PR analyzer/106284
4492         * sm-taint.cc (taint_state_machine::on_condition): Handle range
4493         checks optimized by build_range_check.
4495 2022-07-15  Jonathan Wakely  <jwakely@redhat.com>
4497         * call-info.cc (call_info::print): Adjust to new label_text API.
4498         * checker-path.cc (checker_event::dump): Likewise.
4499         (region_creation_event::get_desc): Likewise.
4500         (state_change_event::get_desc): Likewise.
4501         (superedge_event::should_filter_p): Likewise.
4502         (start_cfg_edge_event::get_desc): Likewise.
4503         (call_event::get_desc): Likewise.
4504         (return_event::get_desc): Likewise.
4505         (warning_event::get_desc): Likewise.
4506         (checker_path::dump): Likewise.
4507         (checker_path::debug): Likewise.
4508         * diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic):
4509         Likewise.
4510         (diagnostic_manager::prune_interproc_events): Likewise.
4511         * engine.cc (feasibility_state::maybe_update_for_edge):
4512         Likewise.
4513         * program-state.cc (sm_state_map::to_json): Likewise.
4514         * region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise.
4515         (region_model::impl_call_analyzer_dump_capacity): Likewise.
4516         * region.cc (region::to_json): Likewise.
4517         * sm-malloc.cc (inform_nonnull_attribute): Likewise.
4518         * store.cc (binding_map::to_json): Likewise.
4519         (store::to_json): Likewise.
4520         * supergraph.cc (superedge::dump): Likewise.
4521         * svalue.cc (svalue::to_json): Likewise.
4523 2022-07-07  David Malcolm  <dmalcolm@redhat.com>
4525         * checker-path.cc (start_cfg_edge_event::get_desc): Update for
4526         superedge::get_description returning a label_text.
4527         * engine.cc (feasibility_state::maybe_update_for_edge): Likewise.
4528         * supergraph.cc (superedge::dump): Likewise.
4529         (superedge::get_description): Convert return type from char * to
4530         label_text.
4531         * supergraph.h (superedge::get_description): Likewise.
4533 2022-07-07  David Malcolm  <dmalcolm@redhat.com>
4535         * call-info.cc (call_info::print): Update for removal of
4536         label_text::maybe_free in favor of automatic memory management.
4537         * checker-path.cc (checker_event::dump): Likewise.
4538         (checker_event::prepare_for_emission): Likewise.
4539         (state_change_event::get_desc): Likewise.
4540         (superedge_event::should_filter_p): Likewise.
4541         (start_cfg_edge_event::get_desc): Likewise.
4542         (warning_event::get_desc): Likewise.
4543         (checker_path::dump): Likewise.
4544         (checker_path::debug): Likewise.
4545         * diagnostic-manager.cc
4546         (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
4547         (diagnostic_manager::prune_interproc_events): Likewise.
4548         * program-state.cc (sm_state_map::to_json): Likewise.
4549         * region.cc (region::to_json): Likewise.
4550         * sm-malloc.cc (inform_nonnull_attribute): Likewise.
4551         * store.cc (binding_map::to_json): Likewise.
4552         (store::to_json): Likewise.
4553         * svalue.cc (svalue::to_json): Likewise.
4555 2022-07-07  David Malcolm  <dmalcolm@redhat.com>
4557         PR analyzer/106225
4558         * sm-taint.cc (taint_state_machine::on_stmt): Move handling of
4559         assignments from division to...
4560         (taint_state_machine::check_for_tainted_divisor): ...this new
4561         function.  Reject warning when the divisor is known to be non-zero.
4562         * sm.cc: Include "analyzer/program-state.h".
4563         (sm_context::get_old_region_model): New.
4564         * sm.h (sm_context::get_old_region_model): New decl.
4566 2022-07-06  Immad Mir  <mirimmad@outlook.com>
4568         PR analyzer/106184
4569         * sm-fd.cc (fd_state_machine): Change ordering of initialization
4570         of state m_invalid so that the order of initializers is same as
4571         the ordering of the fields in the class decl.
4573 2022-07-06  Immad Mir  <mirimmad@outlook.com>
4575         * sm-fd.cc (use_after_close): save the "close" event and
4576         show it where possible.
4578 2022-07-06  David Malcolm  <dmalcolm@redhat.com>
4580         PR analyzer/106204
4581         * region-model.cc (within_short_circuited_stmt_p): Move extraction
4582         of assign_stmt to caller.
4583         (due_to_ifn_deferred_init_p): New.
4584         (region_model::check_for_poison): Move extraction of assign_stmt
4585         from within_short_circuited_stmt_p to here.  Share logic with
4586         call to due_to_ifn_deferred_init_p.
4588 2022-07-02  Tim Lange  <mail@tim-lange.me>
4590         PR analyzer/105900
4591         * analyzer.opt: Added Wanalyzer-allocation-size.
4592         * checker-path.cc (region_creation_event::get_desc): Added call to new
4593         virtual function pending_diagnostic::describe_region_creation_event.
4594         * checker-path.h: Added region_creation_event::get_desc.
4595         * diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
4596         New function.
4597         * diagnostic-manager.h:
4598         Added diagnostic_manager::add_event_on_final_node.
4599         * pending-diagnostic.h (struct region_creation): New event_desc struct.
4600         (pending_diagnostic::describe_region_creation_event): Added virtual
4601         function to overwrite description of a region creation.
4602         * region-model.cc (class dubious_allocation_size): New class.
4603         (capacity_compatible_with_type): New helper function.
4604         (class size_visitor): New class.
4605         (struct_or_union_with_inheritance_p): New helper function.
4606         (is_any_cast_p): New helper function.
4607         (region_model::check_region_size): New function.
4608         (region_model::set_value): Added call to
4609         region_model::check_region_size.
4610         * region-model.h (class region_model): New function check_region_size.
4611         * svalue.cc (region_svalue::accept): Changed to post-order traversal.
4612         (initial_svalue::accept): Likewise.
4613         (unaryop_svalue::accept): Likewise.
4614         (binop_svalue::accept): Likewise.
4615         (sub_svalue::accept): Likewise.
4616         (repeated_svalue::accept): Likewise.
4617         (bits_within_svalue::accept): Likewise.
4618         (widening_svalue::accept): Likewise.
4619         (unmergeable_svalue::accept): Likewise.
4620         (compound_svalue::accept): Likewise.
4621         (conjured_svalue::accept): Likewise.
4622         (asm_output_svalue::accept): Likewise.
4623         (const_fn_result_svalue::accept): Likewise.
4625 2022-07-02  Immad Mir  <mirimmad17@gmail.com>
4627         PR analyzer/106003
4628         * analyzer.opt (Wanalyzer-fd-leak): New option.
4629         (Wanalyzer-fd-access-mode-mismatch): New option.
4630         (Wanalyzer-fd-use-without-check): New option.
4631         (Wanalyzer-fd-double-close): New option.
4632         (Wanalyzer-fd-use-after-close): New option.
4633         * sm.h (make_fd_state_machine): New decl.
4634         * sm.cc (make_checkers): Call make_fd_state_machine.
4635         * sm-fd.cc: New file.
4637 2022-06-24  David Malcolm  <dmalcolm@redhat.com>
4639         * call-string.cc: Add includes of "analyzer/analyzer.h"
4640         and "analyzer/analyzer-logging.h".
4641         (call_string::call_string): Delete copy ctor.
4642         (call_string::operator=): Delete.
4643         (call_string::operator==): Delete.
4644         (call_string::hash): Delete.
4645         (call_string::push_call): Make const, returning the resulting
4646         call_string.
4647         (call_string::pop): Delete.
4648         (call_string::cmp_ptr_ptr): New.
4649         (call_string::validate): Assert that m_parent is non-NULL, or
4650         m_elements is empty.
4651         (call_string::call_string): Move default ctor here from
4652         call-string.h and reimplement.  Add ctor taking a parent
4653         and an element.
4654         (call_string::~call_string): New.
4655         (call_string::recursive_log): New.
4656         * call-string.h (call_string::call_string): Move default ctor's
4657         defn to call-string.cc.  Delete copy ctor.  Add ctor taking a
4658         parent and an element.
4659         (call_string::operator=): Delete.
4660         (call_string::operator==): Delete.
4661         (call_string::hash): Delete.
4662         (call_string::push_call): Make const, returning the resulting
4663         call_string.
4664         (call_string::pop): Delete decl.
4665         (call_string::get_parent): New.
4666         (call_string::cmp_ptr_ptr): New decl.
4667         (call_string::get_top_of_stack): New.
4668         (struct call_string::hashmap_traits_t): New.
4669         (class call_string): Add friend class region_model_manager.  Add
4670         DISABLE_COPY_AND_ASSIGN.
4671         (call_string::~call_string): New decl.
4672         (call_string::recursive_log): New decl.
4673         (call_string::m_parent): New field.
4674         (call_string::m_children): New field.
4675         * constraint-manager.cc (selftest::test_many_constants): Pass
4676         model manager to program_point::origin.
4677         * engine.cc (exploded_graph::exploded_graph): Likewise.
4678         (exploded_graph::add_function_entry): Likewise for
4679         program_point::from_function_entry.
4680         (add_tainted_args_callback): Likewise.
4681         (exploded_graph::maybe_process_run_of_before_supernode_enodes):
4682         Update for change to program_point.get_call_string.
4683         (exploded_graph::process_node): Likewise.
4684         (class function_call_string_cluster): Convert m_cs from a
4685         call_string to a const call_string &.
4686         (struct function_call_string): Likewise.
4687         (pod_hash_traits<function_call_string>::hash): Use pointer_hash
4688         for m_cs.
4689         (pod_hash_traits<function_call_string>::equal): Update for change
4690         to m_cs.
4691         (root_cluster::add_node): Update for change to
4692         function_call_string.
4693         (viz_callgraph_node::dump_dot): Update for change to call_string.
4694         * exploded-graph.h (per_call_string_data::m_key): Convert to a
4695         reference.
4696         (struct eg_call_string_hash_map_traits): Delete.
4697         (exploded_graph::call_string_data_map_t): Remove traits class.
4698         * program-point.cc: Move include of "analyzer/call-string.h" to
4699         after "analyzer/analyzer-logging.h".
4700         (program_point::print): Update for conversion of m_call_string to
4701         a pointer.
4702         (program_point::to_json): Likewise.
4703         (program_point::push_to_call_stack): Update for immutability of
4704         call strings.
4705         (program_point::pop_from_call_stack): Likewise.
4706         (program_point::hash): Use pointer hashing for m_call_string.
4707         (program_point::get_function_at_depth): Update for change to
4708         m_call_string.
4709         (program_point::validate): Update for changes to call_string.
4710         (program_point::on_edge): Likewise.
4711         (program_point::origin): Move here from call-string.h.  Add
4712         region_model_manager param and use it to get empty call string.
4713         (program_point::from_function_entry): Likewise.
4714         (selftest::test_function_point_ordering): Likewise.
4715         (selftest::test_function_point_ordering): Likewise.
4716         * program-point.h (program_point::program_point): Update for
4717         change to m_call_string.
4718         (program_point::get_call_string): Likewise.
4719         (program_point::get_stack_depth): Likewise.
4720         (program_point::origin): Add region_model_manager param, and move
4721         defn to call-string.cc.
4722         (program_point::from_function_entry): Likewise.
4723         (program_point::empty): Drop call_string.
4724         (program_point::deleted): Likewise.
4725         (program_point::program_point): New private ctor.
4726         (program_point::m_call_string): Convert from call_string to const
4727         call_string *.
4728         * program-state.cc (selftest::test_program_state_merging): Update
4729         for call_string changes.
4730         (selftest::test_program_state_merging_2): Likewise.
4731         * region-model-manager.cc
4732         (region_model_manager::region_model_manager): Construct
4733         m_empty_call_string.
4734         (region_model_manager::log_stats): Log the call strings.
4735         * region-model.cc (assert_region_models_merge): Pass the
4736         region_model_manager when creating program_point instances.
4737         (selftest::test_state_merging): Likewise.
4738         (selftest::test_constraint_merging): Likewise.
4739         (selftest::test_widening_constraints): Likewise.
4740         (selftest::test_iteration_1): Likewise.
4741         * region-model.h (region_model_manager::get_empty_call_string):
4742         New.
4743         (region_model_manager::m_empty_call_string): New.
4744         * sm-signal.cc (register_signal_handler::impl_transition): Update
4745         for changes to call_string.
4747 2022-06-24  David Malcolm  <dmalcolm@redhat.com>
4749         * call-string.cc (call_string::calc_recursion_depth): Whitespace
4750         cleanups.
4751         (call_string::cmp): Likewise.
4752         (call_string::get_caller_node): Likewise.
4753         (call_string::validate): Likewise.
4754         * engine.cc (dynamic_call_info_t::add_events_to_path): Likewise.
4755         (exploded_graph::get_per_function_data): Likewise.
4756         (exploded_graph::maybe_create_dynamic_call): Likewise.
4757         (exploded_graph::maybe_create_dynamic_call): Likewise.
4758         (exploded_graph::process_node): Likewise.
4760 2022-06-16  David Malcolm  <dmalcolm@redhat.com>
4762         * varargs.cc (va_arg_type_mismatch::emit): Associate the warning
4763         with CWE-686 ("Function Call With Incorrect Argument Type").
4765 2022-06-16  David Malcolm  <dmalcolm@redhat.com>
4767         * varargs.cc: Include "diagnostic-metadata.h".
4768         (va_list_exhausted::emit): Associate the warning with
4769         CWE-685 ("Function Call With Incorrect Number of Arguments").
4771 2022-06-16  David Malcolm  <dmalcolm@redhat.com>
4773         * sm-file.cc (double_fclose::emit): Associate the warning with
4774         CWE-1341 ("Multiple Releases of Same Resource or Handle").
4776 2022-06-15  David Malcolm  <dmalcolm@redhat.com>
4778         PR analyzer/105962
4779         * analyzer.opt (fanalyzer-undo-inlining): New option.
4780         * checker-path.cc: Include "diagnostic-core.h" and
4781         "inlining-iterator.h".
4782         (event_kind_to_string): Handle EK_INLINED_CALL.
4783         (class inlining_info): New class.
4784         (checker_event::checker_event): Move here from checker-path.h.
4785         Store original fndecl and depth, and calculate effective fndecl
4786         and depth based on inlining information.
4787         (checker_event::dump): Emit original depth as well as effective
4788         depth when they differ; likewise for fndecl.
4789         (region_creation_event::get_desc): Use m_effective_fndecl.
4790         (inlined_call_event::get_desc): New.
4791         (inlined_call_event::get_meaning): New.
4792         (checker_path::inject_any_inlined_call_events): New.
4793         * checker-path.h (enum event_kind): Add EK_INLINED_CALL.
4794         (checker_event::checker_event): Make protected, and move
4795         definition to checker-path.cc.
4796         (checker_event::get_fndecl): Use effective fndecl.
4797         (checker_event::get_stack_depth): Use effective stack depth.
4798         (checker_event::get_logical_location): Use effective stack depth.
4799         (checker_event::get_original_stack_depth): New.
4800         (checker_event::m_fndecl): Rename to...
4801         (checker_event::m_original_fndecl): ...this.
4802         (checker_event::m_depth): Rename to...
4803         (checker_event::m_original_depth): ...this.
4804         (checker_event::m_effective_fndecl): New field.
4805         (checker_event::m_effective_depth): New field.
4806         (class inlined_call_event): New checker_event subclass.
4807         (checker_path::inject_any_inlined_call_events): New decl.
4808         * diagnostic-manager.cc: Include "inlining-iterator.h".
4809         (diagnostic_manager::emit_saved_diagnostic): Call
4810         checker_path::inject_any_inlined_call_events.
4811         (diagnostic_manager::prune_for_sm_diagnostic): Handle
4812         EK_INLINED_CALL.
4813         * engine.cc (tainted_args_function_custom_event::get_desc): Use
4814         effective fndecl.
4815         * inlining-iterator.h: New file.
4817 2022-06-15  David Malcolm  <dmalcolm@redhat.com>
4819         * diagnostic-manager.cc (saved_diagnostic::dump_dot_id): New.
4820         (saved_diagnostic::dump_as_dot_node): New.
4821         * diagnostic-manager.h (saved_diagnostic::dump_dot_id): New decl.
4822         (saved_diagnostic::dump_as_dot_node): New decl.
4823         * engine.cc (exploded_node::dump_dot): Add nodes for saved
4824         diagnostics.
4826 2022-06-02  David Malcolm  <dmalcolm@redhat.com>
4828         * checker-path.cc (checker_event::get_meaning): New.
4829         (function_entry_event::get_meaning): New.
4830         (state_change_event::get_desc): Add dump of meaning of the event
4831         to the -fanalyzer-verbose-state-changes output.
4832         (state_change_event::get_meaning): New.
4833         (cfg_edge_event::get_meaning): New.
4834         (call_event::get_meaning): New.
4835         (return_event::get_meaning): New.
4836         (start_consolidated_cfg_edges_event::get_meaning): New.
4837         (warning_event::get_meaning): New.
4838         * checker-path.h: Include "tree-logical-location.h".
4839         (checker_event::checker_event): Construct m_logical_loc.
4840         (checker_event::get_logical_location): New.
4841         (checker_event::get_meaning): New decl.
4842         (checker_event::m_logical_loc): New.
4843         (function_entry_event::get_meaning): New decl.
4844         (state_change_event::get_meaning): New decl.
4845         (cfg_edge_event::get_meaning): New decl.
4846         (call_event::get_meaning): New decl.
4847         (return_event::get_meaning): New decl.
4848         (start_consolidated_cfg_edges_event::get_meaning): New.
4849         (warning_event::get_meaning): New decl.
4850         * pending-diagnostic.h: Include "diagnostic-path.h".
4851         (pending_diagnostic::get_meaning_for_state_change): New vfunc.
4852         * sm-file.cc (file_diagnostic::get_meaning_for_state_change): New
4853         vfunc impl.
4854         * sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
4855         Likewise.
4856         * sm-sensitive.cc
4857         (exposure_through_output_file::get_meaning_for_state_change):
4858         Likewise.
4859         * sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
4860         Likewise.
4861         * varargs.cc
4862         (va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.
4864 2022-05-23  David Malcolm  <dmalcolm@redhat.com>
4866         * call-info.cc: Add "final" and "override" to all vfunc
4867         implementations that were missing them, as appropriate.
4868         * engine.cc: Likewise.
4869         * region-model.cc: Likewise.
4870         * sm-malloc.cc: Likewise.
4871         * supergraph.h: Likewise.
4872         * svalue.cc: Likewise.
4873         * varargs.cc: Likewise.
4875 2022-05-20  David Malcolm  <dmalcolm@redhat.com>
4877         * analyzer-pass.cc: Replace uses of "FINAL" and "OVERRIDE" with
4878         "final" and "override".
4879         * call-info.h: Likewise.
4880         * checker-path.h: Likewise.
4881         * constraint-manager.cc: Likewise.
4882         * diagnostic-manager.cc: Likewise.
4883         * engine.cc: Likewise.
4884         * exploded-graph.h: Likewise.
4885         * feasible-graph.h: Likewise.
4886         * pending-diagnostic.h: Likewise.
4887         * region-model-impl-calls.cc: Likewise.
4888         * region-model.cc: Likewise.
4889         * region-model.h: Likewise.
4890         * region.h: Likewise.
4891         * sm-file.cc: Likewise.
4892         * sm-malloc.cc: Likewise.
4893         * sm-pattern-test.cc: Likewise.
4894         * sm-sensitive.cc: Likewise.
4895         * sm-signal.cc: Likewise.
4896         * sm-taint.cc: Likewise.
4897         * state-purge.h: Likewise.
4898         * store.cc: Likewise.
4899         * store.h: Likewise.
4900         * supergraph.h: Likewise.
4901         * svalue.h: Likewise.
4902         * trimmed-graph.h: Likewise.
4903         * varargs.cc: Likewise.
4905 2022-05-16  David Malcolm  <dmalcolm@redhat.com>
4907         PR analyzer/105103
4908         * analyzer.cc (make_label_text_n): New.
4909         * analyzer.h (class var_arg_region): New forward decl.
4910         (make_label_text_n): New decl.
4911         * analyzer.opt (Wanalyzer-va-arg-type-mismatch): New option.
4912         (Wanalyzer-va-list-exhausted): New option.
4913         (Wanalyzer-va-list-leak): New option.
4914         (Wanalyzer-va-list-use-after-va-end): New option.
4915         * checker-path.cc (call_event::get_desc): Split out decl access
4916         into..
4917         (call_event::get_caller_fndecl): ...this new function and...
4918         (call_event::get_callee_fndecl): ...this new function.
4919         * checker-path.h (call_event::get_desc): Drop "FINAL".
4920         (call_event::get_caller_fndecl): New decl.
4921         (call_event::get_callee_fndecl): New decl.
4922         (class call_event): Make fields protected.
4923         * diagnostic-manager.cc (null_assignment_sm_context::warn): New
4924         overload.
4925         (null_assignment_sm_context::get_new_program_state): New.
4926         (diagnostic_manager::add_events_for_superedge): Move case
4927         SUPEREDGE_CALL to a new pending_diagnostic::add_call_event vfunc.
4928         * engine.cc (impl_sm_context::warn): Implement new override.
4929         (impl_sm_context::get_new_program_state): New.
4930         * pending-diagnostic.cc: Include "analyzer/diagnostic-manager.h",
4931         "cpplib.h", "digraph.h", "ordered-hash-map.h", "cfg.h",
4932         "basic-block.h", "gimple.h", "gimple-iterator.h", "cgraph.h"
4933         "analyzer/supergraph.h", "analyzer/program-state.h",
4934         "alloc-pool.h", "fibonacci_heap.h", "shortest-paths.h",
4935         "sbitmap.h", "analyzer/exploded-graph.h", "diagnostic-path.h",
4936         and "analyzer/checker-path.h".
4937         (ht_ident_eq): New.
4938         (fixup_location_in_macro_p): New.
4939         (pending_diagnostic::fixup_location): New.
4940         (pending_diagnostic::add_call_event): New.
4941         * pending-diagnostic.h (pending_diagnostic::fixup_location): Drop
4942         no-op inline implementation in favor of the more complex
4943         implementation above.
4944         (pending_diagnostic::add_call_event): New vfunc.
4945         * region-model-impl-calls.cc: Include "analyzer/sm.h",
4946         "diagnostic-path.h", and "analyzer/pending-diagnostic.h".
4947         * region-model-manager.cc
4948         (region_model_manager::get_var_arg_region): New.
4949         (region_model_manager::log_stats): Log m_var_arg_regions.
4950         * region-model.cc (region_model::on_call_pre): Handle IFN_VA_ARG,
4951         BUILT_IN_VA_START, and BUILT_IN_VA_COPY.
4952         (region_model::on_call_post): Handle BUILT_IN_VA_END.
4953         (region_model::get_representative_path_var_1): Handle RK_VAR_ARG.
4954         (region_model::push_frame): Push variadic arguments.
4955         * region-model.h (region_model_manager::get_var_arg_region): New
4956         decl.
4957         (region_model_manager::m_var_arg_regions): New field.
4958         (region_model::impl_call_va_start): New decl.
4959         (region_model::impl_call_va_copy): New decl.
4960         (region_model::impl_call_va_arg): New decl.
4961         (region_model::impl_call_va_end): New decl.
4962         * region.cc (alloca_region::dump_to_pp): Dump the id.
4963         (var_arg_region::dump_to_pp): New.
4964         (var_arg_region::get_frame_region): New.
4965         * region.h (enum region_kind): Add RK_VAR_ARG.
4966         (region::dyn_cast_var_arg_region): New.
4967         (class var_arg_region): New.
4968         (is_a_helper <const var_arg_region *>::test): New.
4969         (struct default_hash_traits<var_arg_region::key_t>): New.
4970         * sm.cc (make_checkers): Call make_va_list_state_machine.
4971         * sm.h (sm_context::warn): New vfunc.
4972         (sm_context::get_old_svalue): Drop unused decl.
4973         (sm_context::get_new_program_state): New vfunc.
4974         (make_va_list_state_machine): New decl.
4975         * varargs.cc: New file.
4977 2022-05-16  Martin Liska  <mliska@suse.cz>
4979         * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
4980         * function-set.cc (test_stdio_example): Likewise.
4981         * sm-file.cc (get_file_using_fns): Likewise.
4982         * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
4983         * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
4985 2022-05-13  Richard Biener  <rguenther@suse.de>
4987         * supergraph.cc: Re-order gimple-fold.h include.
4989 2022-05-11  David Malcolm  <dmalcolm@redhat.com>
4991         * checker-path.cc (state_change_event::get_desc): Call maybe_free
4992         on label_text temporaries.
4993         * diagnostic-manager.cc
4994         (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
4995         * engine.cc (exploded_graph::~exploded_graph): Fix leak of
4996         m_per_point_data and m_per_call_string_data values.  Simplify
4997         cleanup of m_per_function_stats and m_per_point_data values.
4998         (feasibility_state::maybe_update_for_edge): Fix leak of result of
4999         superedge::get_description.
5000         * region-model-manager.cc
5001         (region_model_manager::~region_model_manager): Move cleanup of
5002         m_setjmp_values to match the ordering of the fields within
5003         region_model_manager.  Fix leak of values within
5004         m_repeated_values_map, m_bits_within_values_map,
5005         m_asm_output_values_map, and m_const_fn_result_values_map.
5007 2022-04-28  David Malcolm  <dmalcolm@redhat.com>
5009         PR analyzer/105285
5010         * store.cc (binding_cluster::get_any_binding): Handle accessing
5011         sub_svalues of clusters where the base region has a symbolic
5012         binding.
5014 2022-04-28  David Malcolm  <dmalcolm@redhat.com>
5016         * diagnostic-manager.cc (epath_finder::process_worklist_item):
5017         Call dump_feasible_path when a path that reaches the the target
5018         enode is found.
5019         (epath_finder::dump_feasible_path): New.
5020         * engine.cc (feasibility_state::dump_to_pp): New.
5021         * exploded-graph.h (feasibility_state::dump_to_pp): New decl.
5022         * feasible-graph.cc (feasible_graph::dump_feasible_path): New.
5023         * feasible-graph.h (feasible_graph::dump_feasible_path): New
5024         decls.
5025         * program-point.cc (function_point::print): Fix missing trailing
5026         newlines.
5027         * program-point.h (program_point::print_source_line): Remove
5028         unimplemented decl.
5030 2022-04-25  David Malcolm  <dmalcolm@redhat.com>
5032         PR analyzer/105365
5033         PR analyzer/105366
5034         * svalue.cc
5035         (cmp_cst): Rename to...
5036         (cmp_csts_same_type): ...this.  Convert all recursive calls to
5037         calls to...
5038         (cmp_csts_and_types): ....this new function.
5039         (svalue::cmp_ptr): Update for renaming of cmp_cst
5041 2022-04-14  David Malcolm  <dmalcolm@redhat.com>
5043         PR analyzer/105264
5044         * region-model-reachability.cc (reachable_regions::handle_parm):
5045         Use maybe_get_deref_base_region rather than just region_svalue, to
5046         handle pointer arithmetic also.
5047         * svalue.cc (svalue::maybe_get_deref_base_region): New.
5048         * svalue.h (svalue::maybe_get_deref_base_region): New decl.
5050 2022-04-14  David Malcolm  <dmalcolm@redhat.com>
5052         PR analyzer/105252
5053         * svalue.cc (cmp_cst): When comparing VECTOR_CSTs, compare the
5054         types of the encoded elements before calling cmp_cst on them.
5056 2022-04-09  David Malcolm  <dmalcolm@redhat.com>
5058         PR analyzer/103892
5059         * region-model-manager.cc
5060         (region_model_manager::get_unknown_symbolic_region): New,
5061         extracted from...
5062         (region_model_manager::get_field_region): ...here.
5063         (region_model_manager::get_element_region): Use it here.
5064         (region_model_manager::get_offset_region): Likewise.
5065         (region_model_manager::get_sized_region): Likewise.
5066         (region_model_manager::get_cast_region): Likewise.
5067         (region_model_manager::get_bit_range): Likewise.
5068         * region-model.h
5069         (region_model_manager::get_unknown_symbolic_region): New decl.
5070         * region.cc (symbolic_region::symbolic_region): Handle sval_ptr
5071         having NULL type.
5072         (symbolic_region::dump_to_pp): Handle having NULL type.
5074 2022-04-07  David Malcolm  <dmalcolm@redhat.com>
5076         PR analyzer/102208
5077         * store.cc (binding_map::remove_overlapping_bindings): Add
5078         "always_overlap" param, using it to generalize to the case where
5079         we want to remove all bindings.  Update "uncertainty" logic to
5080         only record maybe-bound values for cases where there is a symbolic
5081         write involved.
5082         (binding_cluster::mark_region_as_unknown): Split param "reg" into
5083         "reg_to_bind" and "reg_for_overlap".
5084         (binding_cluster::maybe_get_compound_binding): Pass "false" to
5085         binding_map::remove_overlapping_bindings new "always_overlap" param.
5086         (binding_cluster::remove_overlapping_bindings): Determine
5087         "always_overlap" and pass it to
5088         binding_map::remove_overlapping_bindings.
5089         (store::set_value): Pass uncertainty to remove_overlapping_bindings
5090         call.  Update for new param of
5091         binding_cluster::mark_region_as_unknown, passing both the base
5092         region of the iter_cluster, and the lhs_reg.
5093         (store::mark_region_as_unknown): Update for new param of
5094         binding_cluster::mark_region_as_unknown, passing "reg" for both.
5095         (store::remove_overlapping_bindings): Add param "uncertainty", and
5096         pass it on to call to
5097         binding_cluster::remove_overlapping_bindings.
5098         * store.h (binding_map::remove_overlapping_bindings): Add
5099         "always_overlap" param.
5100         (binding_cluster::mark_region_as_unknown): Split param "reg" into
5101         "reg_to_bind" and "reg_for_overlap".
5102         (store::remove_overlapping_bindings): Add param "uncertainty".
5104 2022-03-29  David Malcolm  <dmalcolm@redhat.com>
5106         PR testsuite/105085
5107         * region-model-manager.cc (dump_untracked_region): Skip decls in
5108         the constant pool.
5110 2022-03-29  David Malcolm  <dmalcolm@redhat.com>
5112         PR analyzer/105087
5113         * analyzer.h (class conjured_purge): New forward decl.
5114         * region-model-asm.cc (region_model::on_asm_stmt): Add
5115         conjured_purge param to calls binding_cluster::on_asm and
5116         region_model_manager::get_or_create_conjured_svalue.
5117         * region-model-impl-calls.cc
5118         (call_details::get_or_create_conjured_svalue): Likewise for call
5119         to region_model_manager::get_or_create_conjured_svalue.
5120         (region_model::impl_call_fgets): Remove call to
5121         region_model::purge_state_involving, as this is now done
5122         implicitly by call_details::get_or_create_conjured_svalue.
5123         (region_model::impl_call_fread): Likewise.
5124         (region_model::impl_call_strchr): Pass conjured_purge param to
5125         call to region_model_manager::get_or_create_conjured_svalue.
5126         * region-model-manager.cc (conjured_purge::purge): New.
5127         (region_model_manager::get_or_create_conjured_svalue): Add
5128         param "p".  Use it to purge state when reusing an existing
5129         conjured_svalue.
5130         * region-model.cc (region_model::on_call_pre): Replace call to
5131         region_model::purge_state_involving with passing conjured_purge
5132         to region_model_manager::get_or_create_conjured_svalue.
5133         (region_model::handle_unrecognized_call): Pass conjured_purge to
5134         store::on_unknown_fncall.
5135         * region-model.h
5136         (region_model_manager::get_or_create_conjured_svalue): Add param
5137         "p".
5138         * store.cc (binding_cluster::on_unknown_fncall): Likewise.  Pass
5139         it on to region_model_manager::get_or_create_conjured_svalue.
5140         (binding_cluster::on_asm): Likewise.
5141         (store::on_unknown_fncall): Add param "p" and pass it on to
5142         binding_cluster::on_unknown_fncall.
5143         * store.h (binding_cluster::on_unknown_fncall): Add param p.
5144         (binding_cluster::on_asm): Likewise.
5145         (store::on_unknown_fncall): Likewise.
5146         * svalue.h (class conjured_purge): New.
5148 2022-03-29  David Malcolm  <dmalcolm@redhat.com>
5150         PR analyzer/105074
5151         * region.cc (ipa_ref_requires_tracking): Drop "context_fndecl",
5152         instead using the ref->referring to get the cgraph node of the
5153         caller.
5154         (symnode_requires_tracking_p): Likewise.
5156 2022-03-26  David Malcolm  <dmalcolm@redhat.com>
5158         PR analyzer/105057
5159         * store.cc (binding_cluster::make_unknown_relative_to): Reject
5160         attempts to create a cluster for untracked base regions.
5161         (store::set_value): Likewise.
5162         (store::fill_region): Likewise.
5163         (store::mark_region_as_unknown): Likewise.
5165 2022-03-25  David Malcolm  <dmalcolm@redhat.com>
5167         PR analyzer/104954
5168         * analyzer.opt (-fdump-analyzer-untracked): New option.
5169         * engine.cc (impl_run_checkers): Handle it.
5170         * region-model-asm.cc (region_model::on_asm_stmt): Don't attempt
5171         to clobber regions with !tracked_p ().
5172         * region-model-manager.cc (dump_untracked_region): New.
5173         (region_model_manager::dump_untracked_regions): New.
5174         (frame_region::dump_untracked_regions): New.
5175         * region-model.h (region_model_manager::dump_untracked_regions):
5176         New decl.
5177         * region.cc (ipa_ref_requires_tracking): New.
5178         (symnode_requires_tracking_p): New.
5179         (decl_region::calc_tracked_p): New.
5180         * region.h (region::tracked_p): New vfunc.
5181         (frame_region::dump_untracked_regions): New decl.
5182         (class decl_region): Note that this is also used fo SSA names.
5183         (decl_region::decl_region): Initialize m_tracked.
5184         (decl_region::tracked_p): New.
5185         (decl_region::calc_tracked_p): New decl.
5186         (decl_region::m_tracked): New.
5187         * store.cc (store::get_or_create_cluster): Assert that we
5188         don't try to create clusters for base regions that aren't
5189         trackable.
5190         (store::mark_as_escaped): Don't mark base regions that we're not
5191         tracking.
5193 2022-03-23  David Malcolm  <dmalcolm@redhat.com>
5195         PR analyzer/104979
5196         * engine.cc (impl_run_checkers): Create the engine after the
5197         supergraph, and pass the supergraph to the engine.
5198         * region-model.cc (region_model::get_lvalue_1): Pass ctxt to
5199         frame_region::get_region_for_local.
5200         (region_model::update_for_return_gcall): Pass the lvalue for the
5201         result to pop_frame as a tree, rather than as a region.
5202         (region_model::pop_frame): Update for above change, determining
5203         the destination region after the frame is popped and thus with
5204         respect to the caller frame rather than the called frame.
5205         Likewise, set the value of the region to the return value after
5206         the frame is popped.
5207         (engine::engine): Add supergraph pointer.
5208         (selftest::test_stack_frames): Set the DECL_CONTECT of PARM_DECLs.
5209         (selftest::test_get_representative_path_var): Likewise.
5210         (selftest::test_state_merging): Likewise.
5211         * region-model.h (region_model::pop_frame): Convert first param
5212         from a const region * to a tree.
5213         (engine::engine): Add param "sg".
5214         (engine::m_sg): New field.
5215         * region.cc: Include "analyzer/sm.h" and
5216         "analyzer/program-state.h".
5217         (frame_region::get_region_for_local): Add "ctxt" param.
5218         Add assertions that VAR_DECLs are locals, and that expr is for the
5219         correct function.
5220         * region.h (frame_region::get_region_for_local): Add "ctxt" param.
5222 2022-03-23  David Malcolm  <dmalcolm@redhat.com>
5224         PR analyzer/105017
5225         * sm-taint.cc (taint_diagnostic::subclass_equal_p): Check
5226         m_has_bounds as well as m_arg.
5227         (tainted_allocation_size::subclass_equal_p): Chain up to base
5228         class implementation.  Also check m_mem_space.
5229         (tainted_allocation_size::emit): Add note showing stack-based vs
5230         heap-based allocations.
5232 2022-03-23  David Malcolm  <dmalcolm@redhat.com>
5234         PR analyzer/104997
5235         * diagnostic-manager.cc (diagnostic_manager::add_diagnostic):
5236         Convert return type from "void" to "bool", reporting success vs
5237         failure to caller, for both overloads.
5238         * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
5239         Likewise.
5240         * engine.cc (impl_region_model_context::warn): Propagate return
5241         value from diagnostic_manager::add_diagnostic.
5243 2022-03-18  David Malcolm  <dmalcolm@redhat.com>
5245         PR analyzer/104943
5246         PR analyzer/104954
5247         PR analyzer/103533
5248         * analyzer.h (class state_purge_per_decl): New forward decl.
5249         * engine.cc (impl_run_checkers): Pass region_model_manager to
5250         state_purge_map ctor.
5251         * program-point.cc (function_point::final_stmt_p): New.
5252         (function_point::get_next): New.
5253         * program-point.h (function_point::final_stmt_p): New decl.
5254         (function_point::get_next): New decl.
5255         * program-state.cc (program_state::prune_for_point): Generalize to
5256         purge local decls as well as SSA names.
5257         (program_state::can_purge_base_region_p): New.
5258         * program-state.h (program_state::can_purge_base_region_p): New
5259         decl.
5260         * region-model.cc (struct append_ssa_names_cb_data): Rename to...
5261         (struct append_regions_cb_data): ...this.
5262         (region_model::get_ssa_name_regions_for_current_frame): Rename
5263         to...
5264         (region_model::get_regions_for_current_frame): ...this, updating
5265         for other renamings.
5266         (region_model::append_ssa_names_cb): Rename to...
5267         (region_model::append_regions_cb): ...this, and drop the requirement
5268         that the subregion be a SSA name.
5269         * region-model.h (struct append_ssa_names_cb_data): Rename decl
5270         to...
5271         (struct append_regions_cb_data): ...this.
5272         (region_model::get_ssa_name_regions_for_current_frame): Rename
5273         decl to...
5274         (region_model::get_regions_for_current_frame): ...this.
5275         (region_model::append_ssa_names_cb): Rename decl to...
5276         (region_model::append_regions_cb): ...this.
5277         * state-purge.cc: Include "tristate.h", "selftest.h",
5278         "analyzer/store.h", "analyzer/region-model.h", and
5279         "gimple-walk.h".
5280         (get_candidate_for_purging): New.
5281         (class gimple_op_visitor): New.
5282         (my_load_cb): New.
5283         (my_store_cb): New.
5284         (my_addr_cb): New.
5285         (state_purge_map::state_purge_map): Add "mgr" param.  Update for
5286         renamings.  Find uses of local variables.
5287         (state_purge_map::~state_purge_map): Update for renaming of m_map
5288         to m_ssa_map.  Clean up m_decl_map.
5289         (state_purge_map::get_or_create_data_for_decl): New.
5290         (state_purge_per_ssa_name::state_purge_per_ssa_name): Update for
5291         inheriting from state_purge_per_tree.
5292         (state_purge_per_ssa_name::add_to_worklist): Likewise.
5293         (state_purge_per_decl::state_purge_per_decl): New.
5294         (state_purge_per_decl::add_needed_at): New.
5295         (state_purge_per_decl::add_pointed_to_at): New.
5296         (state_purge_per_decl::process_worklists): New.
5297         (state_purge_per_decl::add_to_worklist): New.
5298         (same_binding_p): New.
5299         (fully_overwrites_p): New.
5300         (state_purge_per_decl::process_point_backwards): New.
5301         (state_purge_per_decl::process_point_forwards): New.
5302         (state_purge_per_decl::needed_at_point_p): New.
5303         (state_purge_annotator::print_needed): Generalize to print local
5304         decls as well as SSA names.
5305         * state-purge.h (class state_purge_map): Update leading comment.
5306         (state_purge_map::map_t): Rename to...
5307         (state_purge_map::ssa_map_t): ...this.
5308         (state_purge_map::iterator): Rename to...
5309         (state_purge_map::ssa_iterator): ...this.
5310         (state_purge_map::decl_map_t): New typedef.
5311         (state_purge_map::decl_iterator): New typedef.
5312         (state_purge_map::state_purge_map): Add "mgr" param.
5313         (state_purge_map::get_data_for_ssa_name): Update for renaming.
5314         (state_purge_map::get_any_data_for_decl): New.
5315         (state_purge_map::get_or_create_data_for_decl): New decl.
5316         (state_purge_map::begin): Rename to...
5317         (state_purge_map::begin_ssas): ...this.
5318         (state_purge_map::end): Rename to...
5319         (state_purge_map::end_ssa): ...this.
5320         (state_purge_map::begin_decls): New.
5321         (state_purge_map::end_decls): New.
5322         (state_purge_map::m_map): Rename to...
5323         (state_purge_map::m_ssa_map): ...this.
5324         (state_purge_map::m_decl_map): New field.
5325         (class state_purge_per_tree): New class.
5326         (class state_purge_per_ssa_name): Inherit from state_purge_per_tree.
5327         (state_purge_per_ssa_name::get_function): Move to base class.
5328         (state_purge_per_ssa_name::point_set_t): Likewise.
5329         (state_purge_per_ssa_name::m_fun): Likewise.
5330         (class state_purge_per_decl): New.
5332 2022-03-17  David Malcolm  <dmalcolm@redhat.com>
5334         * state-purge.cc (state_purge_annotator::add_node_annotations):
5335         Avoid duplicate before-supernode annotations when returning from
5336         an interprocedural call.  Show after-supernode annotations.
5338 2022-03-17  David Malcolm  <dmalcolm@redhat.com>
5340         * program-point.cc (program_point::get_next): Fix missing
5341         increment of index.
5343 2022-03-16  David Malcolm  <dmalcolm@redhat.com>
5345         PR analyzer/104955
5346         * diagnostic-manager.cc (get_emission_location): New.
5347         (diagnostic_manager::diagnostic_manager): Initialize
5348         m_num_disabled_diagnostics.
5349         (diagnostic_manager::add_diagnostic): Reject diagnostics that
5350         will eventually be rejected due to being disabled.
5351         (diagnostic_manager::emit_saved_diagnostics): Log the number
5352         of disabled diagnostics.
5353         (diagnostic_manager::emit_saved_diagnostic): Split out logic for
5354         determining emission location to get_emission_location.
5355         * diagnostic-manager.h
5356         (diagnostic_manager::m_num_disabled_diagnostics): New field.
5357         * engine.cc (stale_jmp_buf::get_controlling_option): New.
5358         (stale_jmp_buf::emit): Use it.
5359         * pending-diagnostic.h
5360         (pending_diagnostic::get_controlling_option): New vfunc.
5361         * region-model.cc
5362         (poisoned_value_diagnostic::get_controlling_option): New.
5363         (poisoned_value_diagnostic::emit): Use it.
5364         (shift_count_negative_diagnostic::get_controlling_option): New.
5365         (shift_count_negative_diagnostic::emit): Use it.
5366         (shift_count_overflow_diagnostic::get_controlling_option): New.
5367         (shift_count_overflow_diagnostic::emit): Use it.
5368         (dump_path_diagnostic::get_controlling_option): New.
5369         (dump_path_diagnostic::emit): Use it.
5370         (write_to_const_diagnostic::get_controlling_option): New.
5371         (write_to_const_diagnostic::emit): Use it.
5372         (write_to_string_literal_diagnostic::get_controlling_option): New.
5373         (write_to_string_literal_diagnostic::emit): Use it.
5374         * sm-file.cc (double_fclose::get_controlling_option): New.
5375         (double_fclose::emit): Use it.
5376         (file_leak::get_controlling_option): New.
5377         (file_leak::emit): Use it.
5378         * sm-malloc.cc (mismatching_deallocation::get_controlling_option):
5379         New.
5380         (mismatching_deallocation::emit): Use it.
5381         (double_free::get_controlling_option): New.
5382         (double_free::emit): Use it.
5383         (possible_null_deref::get_controlling_option): New.
5384         (possible_null_deref::emit): Use it.
5385         (possible_null_arg::get_controlling_option): New.
5386         (possible_null_arg::emit): Use it.
5387         (null_deref::get_controlling_option): New.
5388         (null_deref::emit): Use it.
5389         (null_arg::get_controlling_option): New.
5390         (null_arg::emit): Use it.
5391         (use_after_free::get_controlling_option): New.
5392         (use_after_free::emit): Use it.
5393         (malloc_leak::get_controlling_option): New.
5394         (malloc_leak::emit): Use it.
5395         (free_of_non_heap::get_controlling_option): New.
5396         (free_of_non_heap::emit): Use it.
5397         * sm-pattern-test.cc (pattern_match::get_controlling_option): New.
5398         (pattern_match::emit): Use it.
5399         * sm-sensitive.cc
5400         (exposure_through_output_file::get_controlling_option): New.
5401         (exposure_through_output_file::emit): Use it.
5402         * sm-signal.cc (signal_unsafe_call::get_controlling_option): New.
5403         (signal_unsafe_call::emit): Use it.
5404         * sm-taint.cc (tainted_array_index::get_controlling_option): New.
5405         (tainted_array_index::emit): Use it.
5406         (tainted_offset::get_controlling_option): New.
5407         (tainted_offset::emit): Use it.
5408         (tainted_size::get_controlling_option): New.
5409         (tainted_size::emit): Use it.
5410         (tainted_divisor::get_controlling_option): New.
5411         (tainted_divisor::emit): Use it.
5412         (tainted_allocation_size::get_controlling_option): New.
5413         (tainted_allocation_size::emit): Use it.
5415 2022-03-15  David Malcolm  <dmalcolm@redhat.com>
5417         * store.cc (store::store): Presize m_cluster_map.
5419 2022-03-10  David Malcolm  <dmalcolm@redhat.com>
5421         PR analyzer/104863
5422         * constraint-manager.cc (constraint_manager::add_constraint):
5423         Refresh the EC IDs when adding constraints implied by offsets.
5425 2022-03-10  David Malcolm  <dmalcolm@redhat.com>
5427         PR analyzer/104793
5428         * analyzer.h (class pending_note): New forward decl.
5429         * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
5430         Initialize m_notes.
5431         (saved_diagnostic::operator==): Compare m_notes.
5432         (saved_diagnostic::add_note): New.
5433         (saved_diagnostic::emit_any_notes): New.
5434         (diagnostic_manager::add_note): New.
5435         (diagnostic_manager::emit_saved_diagnostic): Call emit_any_notes
5436         after emitting the warning.
5437         * diagnostic-manager.h (saved_diagnostic::add_note): New decl.
5438         (saved_diagnostic::emit_any_notes): New decl.
5439         (saved_diagnostic::m_notes): New field.
5440         (diagnostic_manager::add_note): New decl.
5441         * engine.cc (impl_region_model_context::add_note): New.
5442         * exploded-graph.h (impl_region_model_context::add_note): New
5443         decl.
5444         * pending-diagnostic.h (class pending_note): New.
5445         (class pending_note_subclass): New template.
5446         * region-model.cc (class reason_attr_access): New.
5447         (check_external_function_for_access_attr): Add class
5448         annotating_ctxt and use it when checking region.
5449         (noop_region_model_context::add_note): New.
5450         * region-model.h (region_model_context::add_note): New vfunc.
5451         (noop_region_model_context::add_note): New decl.
5452         (class region_model_context_decorator): New.
5453         (class note_adding_context): New.
5455 2022-03-10  David Malcolm  <dmalcolm@redhat.com>
5457         PR analyzer/104793
5458         * region-model.cc
5459         (region_model::check_external_function_for_access_attr): New.
5460         (region_model::handle_unrecognized_call): Call it.
5461         * region-model.h
5462         (region_model::check_external_function_for_access_attr): New decl.
5463         (region_model::handle_unrecognized_call): New decl.
5465 2022-03-10  David Malcolm  <dmalcolm@redhat.com>
5467         * sm-taint.cc (taint_state_machine::check_for_tainted_size_arg):
5468         Avoid generating duplicate saved_diagnostics by only handling the
5469         rdwr_map entry for the ptrarg, not the duplicate entry for the
5470         sizarg.
5472 2022-03-07  David Malcolm  <dmalcolm@redhat.com>
5474         PR analyzer/101983
5475         * engine.cc (returning_from_function_p): New.
5476         (impl_region_model_context::on_state_leak): Use it when rejecting
5477         leaks at the return from "main".
5479 2022-03-07  Jakub Jelinek  <jakub@redhat.com>
5481         * store.cc: Fix up duplicated word issue in a comment.
5482         * analyzer.cc: Likewise.
5483         * engine.cc: Likewise.
5484         * sm-taint.cc: Likewise.
5486 2022-03-04  David Malcolm  <dmalcolm@redhat.com>
5488         PR analyzer/103521
5489         * analyzer.opt (-param=analyzer-max-svalue-depth=): Reduce from 13
5490         to 12.
5492 2022-02-23  David Malcolm  <dmalcolm@redhat.com>
5494         PR analyzer/104434
5495         * analyzer.h (class const_fn_result_svalue): New decl.
5496         * region-model-impl-calls.cc (call_details::get_manager): New.
5497         * region-model-manager.cc
5498         (region_model_manager::get_or_create_const_fn_result_svalue): New.
5499         (region_model_manager::log_stats): Log
5500         m_const_fn_result_values_map.
5501         * region-model.cc (const_fn_p): New.
5502         (maybe_get_const_fn_result): New.
5503         (region_model::on_call_pre): Handle fndecls with
5504         __attribute__((const)) by calling the above rather than making
5505         a conjured_svalue.
5506         * region-model.h (visitor::visit_const_fn_result_svalue): New.
5507         (region_model_manager::get_or_create_const_fn_result_svalue): New
5508         decl.
5509         (region_model_manager::const_fn_result_values_map_t): New typedef.
5510         (region_model_manager::m_const_fn_result_values_map): New field.
5511         (call_details::get_manager): New decl.
5512         * svalue.cc (svalue::cmp_ptr): Handle SK_CONST_FN_RESULT.
5513         (const_fn_result_svalue::dump_to_pp): New.
5514         (const_fn_result_svalue::dump_input): New.
5515         (const_fn_result_svalue::accept): New.
5516         * svalue.h (enum svalue_kind): Add SK_CONST_FN_RESULT.
5517         (svalue::dyn_cast_const_fn_result_svalue): New.
5518         (class const_fn_result_svalue): New.
5519         (is_a_helper <const const_fn_result_svalue *>::test): New.
5520         (template <> struct default_hash_traits<const_fn_result_svalue::key_t>):
5521         New.
5523 2022-02-17  David Malcolm  <dmalcolm@redhat.com>
5525         PR analyzer/104576
5526         * region-model.cc: Include "calls.h".
5527         (region_model::on_call_pre): Use flags_from_decl_or_type to
5528         generalize check for DECL_PURE_P to also check for ECF_CONST.
5530 2022-02-16  David Malcolm  <dmalcolm@redhat.com>
5532         PR analyzer/104560
5533         * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
5534         Add region creation events for globals of interest.
5535         (null_assignment_sm_context::get_old_program_state): New.
5536         (diagnostic_manager::add_events_for_eedge): Move check for
5537         changing dynamic extents from PK_BEFORE_STMT case to after the
5538         switch on the dst_point's kind so that we can emit them for the
5539         final stmt in a basic block.
5540         * engine.cc (impl_sm_context::get_old_program_state): New.
5541         * sm-malloc.cc (malloc_state_machine::get_default_state): Rewrite
5542         detection of m_non_heap to use get_memory_space.
5543         (free_of_non_heap::free_of_non_heap): Add freed_reg param.
5544         (free_of_non_heap::subclass_equal_p): Update for changes to
5545         fields.
5546         (free_of_non_heap::emit): Drop m_kind in favor of
5547         get_memory_space.
5548         (free_of_non_heap::describe_state_change): Remove logic for
5549         detecting alloca.
5550         (free_of_non_heap::mark_interesting_stuff): Add region-creation of
5551         m_freed_reg.
5552         (free_of_non_heap::get_memory_space): New.
5553         (free_of_non_heap::kind): Drop enum.
5554         (free_of_non_heap::m_freed_reg): New field.
5555         (free_of_non_heap::m_kind): Drop field.
5556         (malloc_state_machine::on_stmt): Drop transition to m_non_heap.
5557         (malloc_state_machine::handle_free_of_non_heap): New function,
5558         split out from on_deallocator_call and on_realloc_call, adding
5559         detection of the freed region.
5560         (malloc_state_machine::on_deallocator_call): Use it.
5561         (malloc_state_machine::on_realloc_call): Likewise.
5562         * sm.h (sm_context::get_old_program_state): New vfunc.
5564 2022-02-15  David Malcolm  <dmalcolm@redhat.com>
5566         PR analyzer/104524
5567         * region-model-manager.cc
5568         (region_model_manager::maybe_fold_sub_svalue): Only call
5569         get_or_create_cast if type is non-NULL.
5571 2022-02-15  David Malcolm  <dmalcolm@redhat.com>
5573         PR analyzer/102692
5574         * exploded-graph.h (impl_region_model_context::get_stmt): New.
5575         * region-model.cc: Include "gimple-ssa.h", "tree-phinodes.h",
5576         "tree-ssa-operands.h", and "ssa-iterators.h".
5577         (within_short_circuited_stmt_p): New.
5578         (region_model::check_for_poison): Don't warn about uninit values
5579         if within_short_circuited_stmt_p.
5580         * region-model.h (region_model_context::get_stmt): New vfunc.
5581         (noop_region_model_context::get_stmt): New.
5583 2022-02-11  David Malcolm  <dmalcolm@redhat.com>
5585         PR analyzer/104274
5586         * region-model.cc (region_model::check_for_poison): Ignore
5587         uninitialized uses of empty types.
5589 2022-02-10  David Malcolm  <dmalcolm@redhat.com>
5591         PR analyzer/98797
5592         * region-model-manager.cc
5593         (region_model_manager::maybe_fold_sub_svalue): Generalize getting
5594         individual chars of a STRING_CST from element_region to any
5595         subregion which is a concrete access of a single byte from its
5596         parent region.
5597         * region.cc (region::get_relative_concrete_byte_range): New.
5598         * region.h (region::get_relative_concrete_byte_range): New decl.
5600 2022-02-09  David Malcolm  <dmalcolm@redhat.com>
5602         PR analyzer/104452
5603         * region-model.cc (selftest::test_bit_range_regions): New.
5604         (selftest::analyzer_region_model_cc_tests): Call it.
5605         * region.h (bit_range_region::key_t::hash): Fix hashing of m_bits
5606         to avoid using uninitialized data.
5608 2022-02-07  David Malcolm  <dmalcolm@redhat.com>
5610         PR analyzer/104417
5611         * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
5612         Remove overzealous assertion.
5613         (tainted_allocation_size::emit): Likewise.
5614         (region_model::check_dynamic_size_for_taint): Likewise.
5616 2022-02-07  David Malcolm  <dmalcolm@redhat.com>
5618         PR analyzer/103872
5619         * region-model-impl-calls.cc (region_model::impl_call_memcpy):
5620         Reimplement in terms of a get_store_value followed by a set_value.
5622 2022-02-03  David Malcolm  <dmalcolm@redhat.com>
5624         PR analyzer/104369
5625         * engine.cc (exploded_graph::process_node): Use the node for any
5626         diagnostics, avoiding ICE if a bifurcation update adds a
5627         saved_diagnostic, such as for a tainted realloc size.
5628         * region-model-impl-calls.cc
5629         (region_model::impl_call_realloc::success_no_move::update_model):
5630         Require the old pointer to be non-NULL to be able successfully
5631         grow in place.  Use model->deref_rvalue rather than maybe_get_region
5632         to support the old pointer being symbolic.
5633         (region_model::impl_call_realloc::success_with_move::update_model):
5634         Likewise.  Add a constraint that the new pointer != the old pointer.
5635         Use a sized_region when setting the value of the new region.
5636         Handle the case where we don't know the dynamic size of the old
5637         region by marking the new region as unknown.
5638         * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
5639         Update assertion to also allow for MEMSPACE_UNKNOWN.
5640         (tainted_allocation_size::emit): Likewise.
5641         (region_model::check_dynamic_size_for_taint): Likewise.
5643 2022-02-03  David Malcolm  <dmalcolm@redhat.com>
5645         * region-model-impl-calls.cc (region_model::impl_call_calloc): Use
5646         a sized_region when calling zero_fill_region.
5648 2022-02-02  David Malcolm  <dmalcolm@redhat.com>
5650         * region-model.cc (region_model::on_return): Replace usage of
5651         copy_region with get_rvalue/set_value pair.
5652         (region_model::pop_frame): Likewise.
5653         (selftest::test_compound_assignment): Likewise.
5654         * region-model.h (region_model::copy_region): Delete decl.
5655         * region.cc (region_model::copy_region): Delete.
5657 2022-02-02  David Malcolm  <dmalcolm@redhat.com>
5659         * region.cc (region::calc_offset): Consolidate effectively
5660         identical cases.
5662 2022-02-02  David Malcolm  <dmalcolm@redhat.com>
5664         * analyzer.h (class bit_range_region): New forward decl.
5665         * region-model-manager.cc (region_model_manager::get_bit_range):
5666         New.
5667         (region_model_manager::log_stats): Handle m_bit_range_regions.
5668         * region-model.cc (region_model::get_lvalue_1): Handle
5669         BIT_FIELD_REF.
5670         * region-model.h (region_model_manager::get_bit_range): New decl.
5671         (region_model_manager::m_bit_range_regions): New field.
5672         * region.cc (region::get_base_region): Handle RK_BIT_RANGE.
5673         (region::base_region_p): Likewise.
5674         (region::calc_offset): Likewise.
5675         (bit_range_region::dump_to_pp): New.
5676         (bit_range_region::get_byte_size): New.
5677         (bit_range_region::get_bit_size): New.
5678         (bit_range_region::get_byte_size_sval): New.
5679         (bit_range_region::get_relative_concrete_offset): New.
5680         * region.h (enum region_kind): Add RK_BIT_RANGE.
5681         (region::dyn_cast_bit_range_region): New vfunc.
5682         (class bit_range_region): New.
5683         (is_a_helper <const bit_range_region *>::test): New.
5684         (default_hash_traits<bit_range_region::key_t>): New.
5686 2022-02-02  David Malcolm  <dmalcolm@redhat.com>
5688         PR analyzer/104270
5689         * region-model.cc (region_model::on_call_pre): Handle
5690         IFN_DEFERRED_INIT.
5692 2022-01-27  David Malcolm  <dmalcolm@redhat.com>
5694         * checker-path.cc (event_kind_to_string): Handle
5695         EK_REGION_CREATION.
5696         (region_creation_event::region_creation_event): New.
5697         (region_creation_event::get_desc): New.
5698         (checker_path::add_region_creation_event): New.
5699         * checker-path.h (enum event_kind): Add EK_REGION_CREATION.
5700         (class region_creation_event): New subclass.
5701         (checker_path::add_region_creation_event): New decl.
5702         * diagnostic-manager.cc
5703         (diagnostic_manager::emit_saved_diagnostic): Pass NULL for new
5704         param to add_events_for_eedge when handling trailing eedge.
5705         (diagnostic_manager::build_emission_path): Create an interesting_t
5706         instance, allow the pending diagnostic to populate it, and pass it
5707         to the calls to add_events_for_eedge.
5708         (diagnostic_manager::add_events_for_eedge): Add "interest" param.
5709         Use it to add region_creation_events for on-stack regions created
5710         within at function entry, and when pertinent dynamically-sized
5711         regions are created.
5712         (diagnostic_manager::prune_for_sm_diagnostic): Add case for
5713         EK_REGION_CREATION.
5714         * diagnostic-manager.h (diagnostic_manager::add_events_for_eedge):
5715         Add "interest" param.
5716         * pending-diagnostic.cc: Include "selftest.h", "tristate.h",
5717         "analyzer/call-string.h", "analyzer/program-point.h",
5718         "analyzer/store.h", and "analyzer/region-model.h".
5719         (interesting_t::add_region_creation): New.
5720         (interesting_t::dump_to_pp): New.
5721         * pending-diagnostic.h (struct interesting_t): New.
5722         (pending_diagnostic::mark_interesting_stuff): New vfunc.
5723         * region-model.cc
5724         (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
5725         (poisoned_value_diagnostic::operator==): Compare m_pkind and
5726         m_src_region fields.
5727         (poisoned_value_diagnostic::mark_interesting_stuff): New.
5728         (poisoned_value_diagnostic::m_src_region): New.
5729         (region_model::check_for_poison): Call
5730         get_region_for_poisoned_expr for uninit values and pass the resul
5731         to the diagnostic.
5732         (region_model::get_region_for_poisoned_expr): New.
5733         (region_model::deref_rvalue): Pass NULL for
5734         poisoned_value_diagnostic's src_region.
5735         * region-model.h (region_model::get_region_for_poisoned_expr): New
5736         decl.
5737         * region.h (frame_region::get_fndecl): New.
5739 2022-01-27  Martin Liska  <mliska@suse.cz>
5741         PR analyzer/104247
5742         * constraint-manager.cc (bounded_ranges_manager::log_stats):
5743         Cast to long for format purpose.
5744         * region-model-manager.cc (log_uniq_map): Likewise.
5746 2022-01-26  David Malcolm  <dmalcolm@redhat.com>
5748         PR analyzer/104224
5749         * region-model.cc (region_model::check_call_args): New.
5750         (region_model::on_call_pre): Call it when ignoring stdio builtins.
5751         * region-model.h (region_model::check_call_args): New decl
5753 2022-01-26  David Malcolm  <dmalcolm@redhat.com>
5755         PR analyzer/94362
5756         * constraint-manager.cc (range::add_bound): Fix tests for
5757         discarding redundant constraints.  Perform test for rejecting
5758         unsatisfiable constraints earlier so that they don't update
5759         the object on failure.
5760         (selftest::test_range): New.
5761         (selftest::test_constant_comparisons): Add test coverage for
5762         existing constraints becoming narrower until they are
5763         unsatisfiable.
5764         (selftest::run_constraint_manager_tests): Call test_range.
5766 2022-01-22  David Malcolm  <dmalcolm@redhat.com>
5768         PR analyzer/104159
5769         * region-model-manager.cc
5770         (region_model_manager::get_or_create_cast): Bail out if the types
5771         are the same.  Don't attempt to handle casts involving vector
5772         types.
5774 2022-01-20  David Malcolm  <dmalcolm@redhat.com>
5776         PR analyzer/94362
5777         * constraint-manager.cc (bound::ensure_closed): Convert param to
5778         enum bound_kind.
5779         (range::constrained_to_single_element): Likewise.
5780         (range::add_bound): New.
5781         (constraint_manager::add_constraint): Handle SVAL + OFFSET
5782         compared to a constant.
5783         (constraint_manager::get_ec_bounds): Rewrite in terms of
5784         range::add_bound.
5785         (constraint_manager::eval_condition): Reject if range::add_bound
5786         fails.
5787         (selftest::test_constant_comparisons): Add test coverage for
5788         various impossible combinations of integer comparisons.
5789         * constraint-manager.h (enum bound_kind): New.
5790         (struct bound): Likewise.
5791         (bound::ensure_closed): Convert to param to enum bound_kind.
5792         (struct range): Convert to...
5793         (class range): ...this, making fields private.
5794         (range::add_bound): New decls.
5795         * region-model.cc (region_model::add_constraint): Fail if
5796         constraint_manager::add_constraint fails.
5798 2022-01-18  David Malcolm  <dmalcolm@redhat.com>
5800         PR analyzer/104089
5801         * region-model-manager.cc
5802         (region_model_manager::get_or_create_constant_svalue): Assert that
5803         we have a CONSTANT_CLASS_P.
5804         (region_model_manager::maybe_fold_unaryop): Only fold a constant
5805         when fold_unary's result is a constant or a cast of a constant.
5807 2022-01-18  David Malcolm  <dmalcolm@redhat.com>
5809         PR analyzer/104062
5810         * region-model-manager.cc
5811         (region_model_manager::maybe_fold_sub_svalue): Avoid casting to
5812         NULL type when folding access to repeated svalue.
5814 2022-01-17  Martin Liska  <mliska@suse.cz>
5816         * analyzer.cc (is_special_named_call_p): Rename .c names to .cc.
5817         (is_named_call_p): Likewise.
5818         * region-model-asm.cc (deterministic_p): Likewise.
5819         * region.cc (field_region::get_relative_concrete_offset): Likewise.
5820         * sm-malloc.cc (method_p): Likewise.
5821         * supergraph.cc (superedge::dump_dot): Likewise.
5823 2022-01-14  David Malcolm  <dmalcolm@redhat.com>
5825         * sm-taint.cc (taint_state_machine::combine_states): Handle combination
5826         of has_ub and has_lb.
5828 2022-01-14  David Malcolm  <dmalcolm@redhat.com>
5830         PR analyzer/104029
5831         * sm-taint.cc (taint_state_machine::alt_get_inherited_state):
5832         Remove gcc_unreachable from default case for unary ops.
5834 2022-01-14  David Malcolm  <dmalcolm@redhat.com>
5836         * engine.cc: Include "stringpool.h", "attribs.h", and
5837         "tree-dfa.h".
5838         (mark_params_as_tainted): New.
5839         (class tainted_args_function_custom_event): New.
5840         (class tainted_args_function_info): New.
5841         (exploded_graph::add_function_entry): Handle functions with
5842         "tainted_args" attribute.
5843         (class tainted_args_field_custom_event): New.
5844         (class tainted_args_callback_custom_event): New.
5845         (class tainted_args_call_info): New.
5846         (add_tainted_args_callback): New.
5847         (add_any_callbacks): New.
5848         (exploded_graph::build_initial_worklist): Likewise.
5849         (exploded_graph::build_initial_worklist): Find callbacks that are
5850         reachable from global initializers, calling add_any_callbacks on
5851         them.
5853 2022-01-12  David Malcolm  <dmalcolm@redhat.com>
5855         PR analyzer/103940
5856         * engine.cc (impl_sm_context::impl_sm_context): Add
5857         "unknown_side_effects" param and use it to initialize
5858         new m_unknown_side_effects field.
5859         (impl_sm_context::unknown_side_effects_p): New.
5860         (impl_sm_context::m_unknown_side_effects): New.
5861         (exploded_node::on_stmt): Pass unknown_side_effects to sm_ctxt
5862         ctor.
5863         * sm-taint.cc: Include "stringpool.h" and "attribs.h".
5864         (tainted_size::tainted_size): Drop "dir" param.
5865         (tainted_size::get_kind): Drop "FINAL".
5866         (tainted_size::emit): Likewise.
5867         (tainted_size::m_dir): Drop unused field.
5868         (class tainted_access_attrib_size): New subclass.
5869         (taint_state_machine::on_stmt): Call check_for_tainted_size_arg on
5870         external functions with unknown side effects.
5871         (taint_state_machine::check_for_tainted_size_arg): New.
5872         (region_model::check_region_for_taint): Drop "dir" param from
5873         tainted_size ctor.
5874         * sm.h (sm_context::unknown_side_effects_p): New.
5876 2022-01-11  David Malcolm  <dmalcolm@redhat.com>
5878         PR analyzer/102692
5879         * diagnostic-manager.cc
5880         (class auto_disable_complexity_checks): Rename to...
5881         (class auto_checking_feasibility): ...this, updating
5882         the calls accordingly.
5883         (epath_finder::explore_feasible_paths): Update for renaming.
5884         * region-model-manager.cc
5885         (region_model_manager::region_model_manager): Update for change from
5886         m_check_complexity to m_checking_feasibility.
5887         (region_model_manager::reject_if_too_complex): Likewise.
5888         (region_model_manager::get_or_create_unknown_svalue): Handle
5889         m_checking_feasibility.
5890         (region_model_manager::create_unique_svalue): New.
5891         (region_model_manager::maybe_fold_binop): Handle BIT_AND_EXPR and
5892         BIT_IOR_EXPRs on booleans where we know the result.
5893         * region-model.cc (test_binop_svalue_folding): Add test coverage
5894         for the above.
5895         * region-model.h (region_model_manager::create_unique_svalue): New
5896         decl.
5897         (region_model_manager::enable_complexity_check): Replace with...
5898         (region_model_manager::begin_checking_feasibility): ...this.
5899         (region_model_manager::disable_complexity_check): Replace with...
5900         (region_model_manager::end_checking_feasibility): ...this.
5901         (region_model_manager::m_check_complexity): Replace with...
5902         (region_model_manager::m_checking_feasibility): ...this.
5903         (region_model_manager::m_managed_dynamic_svalues): New field.
5905 2022-01-08  David Malcolm  <dmalcolm@redhat.com>
5907         * engine.cc (impl_run_checkers): Pass logger to engine ctor.
5908         * region-model-manager.cc
5909         (region_model_manager::region_model_manager): Add logger param and
5910         use it to initialize m_logger.
5911         * region-model.cc (engine::engine): New.
5912         * region-model.h (region_model_manager::region_model_manager):
5913         Add logger param.
5914         (region_model_manager::get_logger): New.
5915         (region_model_manager::m_logger): New field.
5916         (engine::engine): New.
5917         * store.cc (store_manager::get_logger): New.
5918         (store::set_value): Log scope.  Log when marking a cluster as
5919         unknown due to possible aliasing.
5920         * store.h (store_manager::get_logger): New decl.
5922 2022-01-08  David Malcolm  <dmalcolm@redhat.com>
5924         * region-model-impl-calls.cc (cmp_decls): New.
5925         (cmp_decls_ptr_ptr): New.
5926         (region_model::impl_call_analyzer_dump_escaped): New.
5927         * region-model.cc (region_model::on_stmt_pre): Handle
5928         __analyzer_dump_escaped.
5929         * region-model.h (region_model::impl_call_analyzer_dump_escaped):
5930         New decl.
5931         * store.h (binding_cluster::get_base_region): New accessor.
5933 2022-01-08  David Malcolm  <dmalcolm@redhat.com>
5935         * region.cc (region::is_named_decl_p): New.
5936         * region.h (region::is_named_decl_p): New decl.
5938 2022-01-06  David Malcolm  <dmalcolm@redhat.com>
5940         PR analyzer/103546
5941         * store.cc (store::eval_alias_1): Refactor handling of decl
5942         regions, adding a test for may_be_aliased, rejecting those for
5943         which it returns false.
5945 2021-12-12  Jonathan Wakely  <jwakely@redhat.com>
5947         * engine.cc: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
5949 2021-12-06  David Malcolm  <dmalcolm@redhat.com>
5951         PR analyzer/103533
5952         * constraint-manager.cc (equiv_class::contains_non_constant_p):
5953         New.
5954         (constraint_manager::canonicalize): Call it when determining
5955         redundant ECs.
5956         (selftest::test_purging): New selftest.
5957         (selftest::run_constraint_manager_tests): Likewise.
5958         * constraint-manager.h (equiv_class::contains_non_constant_p):
5959         New decl.
5961 2021-12-01  David Malcolm  <dmalcolm@redhat.com>
5963         PR analyzer/102471
5964         * region-model-reachability.cc (reachable_regions::handle_parm):
5965         Treat all svalues within a compound parm has reachable, and those
5966         wrapped in a cast.
5968 2021-11-29  David Malcolm  <dmalcolm@redhat.com>
5970         PR analyzer/103217
5971         * store.cc (binding_cluster::can_merge_p): For the "key is bound"
5972         vs "key is not bound" merger case, check that the bound svalue
5973         is mergeable before merging it to "unknown", rejecting the merger
5974         otherwise.
5976 2021-11-19  David Malcolm  <dmalcolm@redhat.com>
5978         PR analyzer/103217
5979         * engine.cc (exploded_graph::get_or_create_node): Pass in
5980         m_ext_state to program_state::can_merge_with_p.
5981         (exploded_graph::process_worklist): Likewise.
5982         (exploded_graph::maybe_process_run_of_before_supernode_enodes):
5983         Likewise.
5984         (exploded_graph::process_node): Add missing call to detect_leaks
5985         when handling phi nodes.
5986         * program-state.cc (program_state::can_merge_with_p): Add
5987         "ext_state" param.  Pass it and state ptrs to
5988         region_model::can_merge_with_p.
5989         (selftest::test_program_state_merging): Update for new ext_state
5990         param of program_state::can_merge_with_p.
5991         (selftest::test_program_state_merging_2): Likewise.
5992         * program-state.h (program_state::can_purge_p): Make const.
5993         (program_state::can_merge_with_p): Add "ext_state" param.
5994         * region-model.cc: Include "analyzer/program-state.h".
5995         (region_model::can_merge_with_p): Add params "ext_state",
5996         "state_a", and "state_b", use them when creating model_merger
5997         object.
5998         (model_merger::mergeable_svalue_p): New.
5999         * region-model.h (region_model::can_merge_with_p): Add params
6000         "ext_state", "state_a", and "state_b".
6001         (model_merger::model_merger) Likewise, initializing new fields.
6002         (model_merger::mergeable_svalue_p): New decl.
6003         (model_merger::m_ext_state): New field.
6004         (model_merger::m_state_a): New field.
6005         (model_merger::m_state_b): New field.
6006         * svalue.cc (svalue::can_merge_p): Call
6007         model_merger::mergeable_svalue_p on both states and reject the
6008         merger accordingly.
6010 2021-11-17  David Malcolm  <dmalcolm@redhat.com>
6012         PR analyzer/102695
6013         * region-model-impl-calls.cc (region_model::impl_call_strchr): New.
6014         * region-model-manager.cc
6015         (region_model_manager::maybe_fold_unaryop): Simplify cast to
6016         pointer type of an existing pointer to a region.
6017         * region-model.cc (region_model::on_call_pre): Handle
6018         BUILT_IN_STRCHR and "strchr".
6019         (write_to_const_diagnostic::emit): Add auto_diagnostic_group.  Add
6020         alternate wordings for functions and labels.
6021         (write_to_const_diagnostic::describe_final_event): Add alternate
6022         wordings for functions and labels.
6023         (region_model::check_for_writable_region): Handle RK_FUNCTION and
6024         RK_LABEL.
6025         * region-model.h (region_model::impl_call_strchr): New decl.
6027 2021-11-16  David Malcolm  <dmalcolm@redhat.com>
6029         PR analyzer/102662
6030         * constraint-manager.cc (bounded_range::operator==): Require the
6031         types to be the same for equality.
6033 2021-11-13  David Malcolm  <dmalcolm@redhat.com>
6035         * analyzer.opt (Wanalyzer-tainted-allocation-size): New.
6036         (Wanalyzer-tainted-divisor): New.
6037         (Wanalyzer-tainted-offset): New.
6038         (Wanalyzer-tainted-size): New.
6039         * engine.cc (impl_region_model_context::get_taint_map): New.
6040         * exploded-graph.h (impl_region_model_context::get_taint_map):
6041         New decl.
6042         * program-state.cc (sm_state_map::get_state): Call
6043         alt_get_inherited_state.
6044         (sm_state_map::impl_set_state): Modify states within
6045         compound svalues.
6046         (program_state::impl_call_analyzer_dump_state): Undo casts.
6047         (selftest::test_program_state_1): Update for new context param of
6048         create_region_for_heap_alloc.
6049         (selftest::test_program_state_merging): Likewise.
6050         * region-model-impl-calls.cc (region_model::impl_call_alloca):
6051         Likewise.
6052         (region_model::impl_call_calloc): Likewise.
6053         (region_model::impl_call_malloc): Likewise.
6054         (region_model::impl_call_operator_new): Likewise.
6055         (region_model::impl_call_realloc): Likewise.
6056         * region-model.cc (region_model::check_region_access): Call
6057         check_region_for_taint.
6058         (region_model::get_representative_path_var_1): Handle binops.
6059         (region_model::create_region_for_heap_alloc): Add "ctxt" param and
6060         pass it to set_dynamic_extents.
6061         (region_model::create_region_for_alloca): Likewise.
6062         (region_model::set_dynamic_extents): Add "ctxt" param and use it
6063         to call check_dynamic_size_for_taint.
6064         (selftest::test_state_merging): Update for new context param of
6065         create_region_for_heap_alloc.
6066         (selftest::test_malloc_constraints): Likewise.
6067         (selftest::test_malloc): Likewise.
6068         (selftest::test_alloca): Likewise for create_region_for_alloca.
6069         * region-model.h (region_model::create_region_for_heap_alloc): Add
6070         "ctxt" param.
6071         (region_model::create_region_for_alloca): Likewise.
6072         (region_model::set_dynamic_extents): Likewise.
6073         (region_model::check_dynamic_size_for_taint): New decl.
6074         (region_model::check_region_for_taint): New decl.
6075         (region_model_context::get_taint_map): New vfunc.
6076         (noop_region_model_context::get_taint_map): New.
6077         * sm-taint.cc: Remove include of "diagnostic-event-id.h"; add
6078         includes of "gimple-iterator.h", "tristate.h", "selftest.h",
6079         "ordered-hash-map.h", "cgraph.h", "cfg.h", "digraph.h",
6080         "analyzer/supergraph.h", "analyzer/call-string.h",
6081         "analyzer/program-point.h", "analyzer/store.h",
6082         "analyzer/region-model.h", and "analyzer/program-state.h".
6083         (enum bounds): Move to top of file.
6084         (class taint_diagnostic): New.
6085         (class tainted_array_index): Convert to subclass of taint_diagnostic.
6086         (tainted_array_index::emit): Add CWE-129.  Reword warning to use
6087         "attacker-controlled" rather than "tainted".
6088         (tainted_array_index::describe_state_change): Move to
6089         taint_diagnostic::describe_state_change.
6090         (tainted_array_index::describe_final_event): Reword to use
6091         "attacker-controlled" rather than "tainted".
6092         (class tainted_offset): New.
6093         (class tainted_size): New.
6094         (class tainted_divisor): New.
6095         (class tainted_allocation_size): New.
6096         (taint_state_machine::alt_get_inherited_state): New.
6097         (taint_state_machine::on_stmt): In assignment handling, remove
6098         ARRAY_REF handling in favor of check_region_for_taint.  Add
6099         detection of tainted divisors.
6100         (taint_state_machine::get_taint): New.
6101         (taint_state_machine::combine_states): New.
6102         (region_model::check_region_for_taint): New.
6103         (region_model::check_dynamic_size_for_taint): New.
6104         * sm.h (state_machine::alt_get_inherited_state): New.
6106 2021-11-12  David Malcolm  <dmalcolm@redhat.com>
6108         * engine.cc (exploded_node::on_stmt_pre): Return when handling
6109         "__analyzer_dump_state".
6111 2021-11-11  Richard Biener  <rguenther@suse.de>
6113         * supergraph.cc: Include bitmap.h.
6115 2021-11-04  David Malcolm  <dmalcolm@redhat.com>
6117         * program-state.cc (sm_state_map::dump): Use default_tree_printer
6118         as format decoder.
6120 2021-09-16  Maxim Blinov  <maxim.blinov@embecosm.com>
6122         PR bootstrap/102242
6123         * engine.cc (INCLUDE_UNIQUE_PTR): Define.
6125 2021-09-08  David Malcolm  <dmalcolm@redhat.com>
6127         PR analyzer/102225
6128         * analyzer.h (compat_types_p): New decl.
6129         * constraint-manager.cc
6130         (constraint_manager::get_or_add_equiv_class): Guard against NULL
6131         type when checking for pointer types.
6132         * region-model-impl-calls.cc (region_model::impl_call_realloc):
6133         Guard against NULL lhs type/region.  Guard against the size value
6134         not being of a compatible type for dynamic extents.
6135         * region-model.cc (compat_types_p): Make non-static.
6137 2021-08-30  David Malcolm  <dmalcolm@redhat.com>
6139         PR analyzer/99260
6140         * analyzer.h (class custom_edge_info): New class, adapted from
6141         exploded_edge::custom_info_t.  Make member functions const.
6142         Make update_model return bool, converting edge param from
6143         reference to a pointer, and adding a ctxt param.
6144         (class path_context): New class.
6145         * call-info.cc: New file.
6146         * call-info.h: New file.
6147         * engine.cc: Include "analyzer/call-info.h" and <memory>.
6148         (impl_region_model_context::impl_region_model_context): Update for
6149         new m_path_ctxt field.
6150         (impl_region_model_context::bifurcate): New.
6151         (impl_region_model_context::terminate_path): New.
6152         (impl_region_model_context::get_malloc_map): New.
6153         (impl_sm_context::impl_sm_context): Update for new m_path_ctxt
6154         field.
6155         (impl_sm_context::get_fndecl_for_call): Likewise.
6156         (impl_sm_context::set_next_state): Likewise.
6157         (impl_sm_context::warn): Likewise.
6158         (impl_sm_context::is_zero_assignment): Likewise.
6159         (impl_sm_context::get_path_context): New.
6160         (impl_sm_context::m_path_ctxt): New.
6161         (impl_region_model_context::on_condition): Update for new
6162         path_ctxt param.  Handle m_enode_for_diag being NULL.
6163         (impl_region_model_context::on_phi): Update for new path_ctxt
6164         param.
6165         (exploded_node::on_stmt): Add path_ctxt param, updating ctor calls
6166         to use it as necessary.  Use it to bail out after sm-handling,
6167         if needed.
6168         (exploded_node::detect_leaks): Update for new path_ctxt param.
6169         (dynamic_call_info_t::update_model): Update for conversion of
6170         exploded_edge::custom_info_t to custom_edge_info.
6171         (dynamic_call_info_t::add_events_to_path): Likewise.
6172         (rewind_info_t::update_model): Likewise.
6173         (rewind_info_t::add_events_to_path): Likewise.
6174         (exploded_edge::exploded_edge): Likewise.
6175         (exploded_graph::add_edge): Likewise.
6176         (exploded_graph::maybe_process_run_of_before_supernode_enodes):
6177         Update for new path_ctxt param.
6178         (class impl_path_context): New.
6179         (exploded_graph::process_node): Update for new path_ctxt param.
6180         Create an impl_path_context and pass it to exploded_node::on_stmt.
6181         Use it to terminate iterating stmts if terminate_path is called
6182         on it.  After processing a run of stmts, query path_ctxt to
6183         potentially terminate the analysis path, and/or to "bifurcate" the
6184         analysis into multiple additional paths.
6185         (feasibility_state::maybe_update_for_edge): Update for new
6186         update_model ctxt param.
6187         * exploded-graph.h
6188         (impl_region_model_context::impl_region_model_context): Add
6189         path_ctxt param.
6190         (impl_region_model_context::bifurcate): New.
6191         (impl_region_model_context::terminate_path): New
6192         (impl_region_model_context::get_ext_state): New.
6193         (impl_region_model_context::get_malloc_map): New.
6194         (impl_region_model_context::m_path_ctxt): New field.
6195         (exploded_node::on_stmt): Add path_ctxt param.
6196         (class exploded_edge::custom_info_t): Move to analyzer.h, renaming
6197         to custom_edge_info, and making the changes as noted in analyzer.h
6198         above.
6199         (exploded_edge::exploded_edge): Update for these changes to
6200         exploded_edge::custom_info_t.
6201         (exploded_edge::m_custom_info): Likewise.
6202         (class dynamic_call_info_t): Likewise.
6203         (class rewind_info_t): Likewise.
6204         (exploded_graph::add_edge): Likewise.
6205         * program-state.cc (program_state::on_edge): Update for new
6206         path_ctxt param.
6207         (program_state::push_call): Likewise.
6208         (program_state::returning_call): Likewise.
6209         (program_state::prune_for_point): Likewise.
6210         * region-model-impl-calls.cc: Include "analyzer/call-info.h".
6211         (call_details::get_fndecl_for_call): New.
6212         (region_model::impl_call_realloc): Reimplement.
6213         * region-model.cc (region_model::on_call_pre): Move call to
6214         impl_call_realloc to...
6215         (region_model::on_call_post): ...here.  Consolidate creation
6216         of call_details instance.
6217         (noop_region_model_context::bifurcate): New.
6218         (noop_region_model_context::terminate_path): New.
6219         * region-model.h (call_details::get_call_stmt): New.
6220         (call_details::get_fndecl_for_call): New.
6221         (region_model::on_realloc_with_move): New.
6222         (region_model_context::bifurcate): New.
6223         (region_model_context::terminate_path): New.
6224         (region_model_context::get_ext_state): New.
6225         (region_model_context::get_malloc_map): New.
6226         (noop_region_model_context::bifurcate): New.
6227         (noop_region_model_context::terminate_path): New.
6228         (noop_region_model_context::get_ext_state): New.
6229         (noop_region_model_context::get_malloc_map): New.
6230         * sm-malloc.cc: Include "analyzer/program-state.h".
6231         (malloc_state_machine::on_realloc_call): Reimplement.
6232         (malloc_state_machine::on_realloc_with_move): New.
6233         (region_model::on_realloc_with_move): New.
6234         * sm-signal.cc (class signal_delivery_edge_info_t): Update for
6235         conversion from exploded_edge::custom_info_t to custom_edge_info.
6236         * sm.h (sm_context::get_path_context): New.
6237         * svalue.cc (svalue::maybe_get_constant): Call
6238         unwrap_any_unmergeable.
6240 2021-08-25  Ankur Saini  <arsenic@sourceware.org>
6242         PR analyzer/101980
6243         * engine.cc (exploded_graph::maybe_create_dynamic_call): Don't create
6244         calls if max recursion limit is reached.
6246 2021-08-23  David Malcolm  <dmalcolm@redhat.com>
6248         * analyzer.h (struct rejected_constraint): Convert to...
6249         (class rejected_constraint): ...this.
6250         (class bounded_ranges): New forward decl.
6251         (class bounded_ranges_manager): New forward decl.
6252         * constraint-manager.cc: Include "analyzer/analyzer-logging.h" and
6253         "tree-pretty-print.h".
6254         (can_plus_one_p): New.
6255         (plus_one): New.
6256         (can_minus_one_p): New.
6257         (minus_one): New.
6258         (bounded_range::bounded_range): New.
6259         (dump_cst): New.
6260         (bounded_range::dump_to_pp): New.
6261         (bounded_range::dump): New.
6262         (bounded_range::to_json): New.
6263         (bounded_range::set_json_attr): New.
6264         (bounded_range::contains_p): New.
6265         (bounded_range::intersects_p): New.
6266         (bounded_range::operator==): New.
6267         (bounded_range::cmp): New.
6268         (bounded_ranges::bounded_ranges): New.
6269         (bounded_ranges::bounded_ranges): New.
6270         (bounded_ranges::bounded_ranges): New.
6271         (bounded_ranges::canonicalize): New.
6272         (bounded_ranges::validate): New.
6273         (bounded_ranges::operator==): New.
6274         (bounded_ranges::dump_to_pp): New.
6275         (bounded_ranges::dump): New.
6276         (bounded_ranges::to_json): New.
6277         (bounded_ranges::eval_condition): New.
6278         (bounded_ranges::contain_p): New.
6279         (bounded_ranges::cmp): New.
6280         (bounded_ranges_manager::~bounded_ranges_manager): New.
6281         (bounded_ranges_manager::get_or_create_empty): New.
6282         (bounded_ranges_manager::get_or_create_point): New.
6283         (bounded_ranges_manager::get_or_create_range): New.
6284         (bounded_ranges_manager::get_or_create_union): New.
6285         (bounded_ranges_manager::get_or_create_intersection): New.
6286         (bounded_ranges_manager::get_or_create_inverse): New.
6287         (bounded_ranges_manager::consolidate): New.
6288         (bounded_ranges_manager::get_or_create_ranges_for_switch): New.
6289         (bounded_ranges_manager::create_ranges_for_switch): New.
6290         (bounded_ranges_manager::make_case_label_ranges): New.
6291         (bounded_ranges_manager::log_stats): New.
6292         (bounded_ranges_constraint::print): New.
6293         (bounded_ranges_constraint::to_json): New.
6294         (bounded_ranges_constraint::operator==): New.
6295         (bounded_ranges_constraint::add_to_hash): New.
6296         (constraint_manager::constraint_manager): Update for new field
6297         m_bounded_ranges_constraints.
6298         (constraint_manager::operator=): Likewise.
6299         (constraint_manager::hash): Likewise.
6300         (constraint_manager::operator==): Likewise.
6301         (constraint_manager::print): Likewise.
6302         (constraint_manager::dump_to_pp): Likewise.
6303         (constraint_manager::to_json): Likewise.
6304         (constraint_manager::add_unknown_constraint): Update the lhs_ec_id
6305         if necessary in existing constraints when combining equivalence
6306         classes.  Add similar code for handling
6307         m_bounded_ranges_constraints.
6308         (constraint_manager::add_constraint_internal): Add comment.
6309         (constraint_manager::add_bounded_ranges): New.
6310         (constraint_manager::eval_condition): Use new field
6311         m_bounded_ranges_constraints.
6312         (constraint_manager::purge): Update bounded_ranges_constraint
6313         instances.
6314         (constraint_manager::canonicalize): Update for new field.
6315         (merger_fact_visitor::on_ranges): New.
6316         (constraint_manager::for_each_fact): Use new field
6317         m_bounded_ranges_constraints.
6318         (constraint_manager::validate):  Fix off-by-one error needed due
6319         to bug fixed above in add_unknown_constraint.  Validate the EC IDs
6320         in m_bounded_ranges_constraints.
6321         (constraint_manager::get_range_manager): New.
6322         (selftest::assert_dump_bounded_range_eq): New.
6323         (ASSERT_DUMP_BOUNDED_RANGE_EQ): New.
6324         (selftest::test_bounded_range): New.
6325         (selftest::assert_dump_bounded_ranges_eq): New.
6326         (ASSERT_DUMP_BOUNDED_RANGES_EQ): New.
6327         (selftest::test_bounded_ranges): New.
6328         (selftest::run_constraint_manager_tests): Call the new selftests.
6329         * constraint-manager.h (struct bounded_range): New.
6330         (struct bounded_ranges): New.
6331         (template <> struct default_hash_traits<bounded_ranges::key_t>): New.
6332         (class bounded_ranges_manager): New.
6333         (fact_visitor::on_ranges): New pure virtual function.
6334         (class bounded_ranges_constraint): New.
6335         (constraint_manager::add_bounded_ranges): New decl.
6336         (constraint_manager::get_range_manager): New decl.
6337         (constraint_manager::m_bounded_ranges_constraints): New field.
6338         * diagnostic-manager.cc (epath_finder::process_worklist_item):
6339         Transfer ownership of rc to add_feasibility_problem.
6340         * engine.cc (feasibility_problem::dump_to_pp): Use get_model.
6341         * feasible-graph.cc (infeasible_node::dump_dot): Update for
6342         conversion of m_rc to a pointer.
6343         (feasible_graph::add_feasibility_problem): Pass RC by pointer and
6344         take ownership.
6345         * feasible-graph.h (infeasible_node::infeasible_node): Pass RC by
6346         pointer and take ownership.
6347         (infeasible_node::~infeasible_node): New.
6348         (infeasible_node::m_rc): Convert to a pointer.
6349         (feasible_graph::add_feasibility_problem): Pass RC by pointer and
6350         take ownership.
6351         * region-model-manager.cc: Include
6352         "analyzer/constraint-manager.h".
6353         (region_model_manager::region_model_manager): Initializer new
6354         field m_range_mgr.
6355         (region_model_manager::~region_model_manager): Delete it.
6356         (region_model_manager::log_stats): Call log_stats on it.
6357         * region-model.cc (region_model::add_constraint): Use new subclass
6358         rejected_op_constraint.
6359         (region_model::apply_constraints_for_gswitch): Reimplement using
6360         bounded_ranges_manager.
6361         (rejected_constraint::dump_to_pp): Convert to...
6362         (rejected_op_constraint::dump_to_pp): ...this.
6363         (rejected_ranges_constraint::dump_to_pp): New.
6364         * region-model.h (struct purge_stats): Add field
6365         m_num_bounded_ranges_constraints.
6366         (region_model_manager::get_range_manager): New.
6367         (region_model_manager::m_range_mgr): New.
6368         (region_model::get_range_manager): New.
6369         (struct rejected_constraint): Split into...
6370         (class rejected_constraint):...this new abstract base class,
6371         and...
6372         (class rejected_op_constraint): ...this new concrete subclass.
6373         (class rejected_ranges_constraint): New.
6374         * supergraph.cc: Include "tree-cfg.h".
6375         (supergraph::supergraph): Drop idx param from add_cfg_edge.
6376         (supergraph::add_cfg_edge): Drop idx param.
6377         (switch_cfg_superedge::switch_cfg_superedge): Move here from
6378         header.  Populate m_case_labels with all cases which go to DST.
6379         (switch_cfg_superedge::dump_label_to_pp): Reimplement to use
6380         m_case_labels.
6381         (switch_cfg_superedge::get_case_label): Delete.
6382         * supergraph.h (supergraphadd_cfg_edge): Drop "idx" param.
6383         (switch_cfg_superedge::switch_cfg_superedge): Drop idx param and
6384         move implementation to supergraph.cc.
6385         (switch_cfg_superedge::get_case_label): Delete.
6386         (switch_cfg_superedge::get_case_labels): New.
6387         (switch_cfg_superedge::m_idx): Delete.
6388         (switch_cfg_superedge::m_case_labels): New field.
6390 2021-08-23  David Malcolm  <dmalcolm@redhat.com>
6392         PR analyzer/101875
6393         * sm-file.cc (file_diagnostic::describe_state_change): Handle
6394         change.m_expr being NULL.
6396 2021-08-23  David Malcolm  <dmalcolm@redhat.com>
6398         PR analyzer/101837
6399         * analyzer.cc (maybe_reconstruct_from_def_stmt): Bail if fn is
6400         NULL, and assert that it's non-NULL before passing it to
6401         build_call_array_loc.
6403 2021-08-23  David Malcolm  <dmalcolm@redhat.com>
6405         PR analyzer/101962
6406         * region-model.cc (region_model::eval_condition_without_cm):
6407         Refactor comparison against zero, adding a check for
6408         POINTER_PLUS_EXPR of non-NULL.
6410 2021-08-23  David Malcolm  <dmalcolm@redhat.com>
6412         * store.cc (bit_range::intersects_p): New overload.
6413         (bit_range::operator-): New.
6414         (binding_cluster::maybe_get_compound_binding): Handle the partial
6415         overlap case.
6416         (selftest::test_bit_range_intersects_p): Add test coverage for
6417         new overload of bit_range::intersects_p.
6418         * store.h (bit_range::intersects_p): New overload.
6419         (bit_range::operator-): New.
6421 2021-08-23  Ankur Saini  <arsenic@sourceware.org>
6423         PR analyzer/102020
6424         * diagnostic-manager.cc
6425         (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Fix typo.
6427 2021-08-21  Ankur Saini  <arsenic@sourceware.org>
6429         PR analyzer/101980
6430         * diagnostic-manager.cc
6431         (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Use
6432         caller_model only when the supergraph_edge doesn't exixt.
6433         (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
6434         Likewise.
6435         * engine.cc (exploded_graph::create_dynamic_call): Rename to...
6436         (exploded_graph::maybe_create_dynamic_call): ...this, return call
6437         creation status.
6438         (exploded_graph::process_node): Handle calls which were not dynamically
6439         discovered.
6440         * exploded-graph.h (exploded_graph::create_dynamic_call): Rename to...
6441         (exploded_graph::maybe_create_dynamic_call): ...this.
6442         * region-model.cc (region_model::update_for_gcall): New param, use it
6443         to push call to frame.
6444         (region_model::update_for_call_superedge): Pass callee function to
6445         update_for_gcall.
6446         * region-model.h (region_model::update_for_gcall): New param.
6448 2021-08-18  Ankur Saini  <arsenic@sourceware.org>
6450         PR analyzer/97114
6451         * region-model.cc (region_model::get_rvalue_1): Add case for
6452         OBJ_TYPE_REF.
6454 2021-08-18  Ankur Saini  <arsenic@sourceware.org>
6456         PR analyzer/100546
6457         * analysis-plan.cc (analysis_plan::use_summary_p): Don't use call
6458         summaries if there is no callgraph edge
6459         * checker-path.cc (call_event::call_event): Handle calls events that
6460         are not represented by a supergraph call edge
6461         (return_event::return_event): Likewise.
6462         (call_event::get_desc): Work with new call_event structure.
6463         (return_event::get_desc): Likeise.
6464         * checker-path.h (call_event::m_src_snode): New field.
6465         (call_event::m_dest_snode): New field.
6466         (return_event::m_src_snode): New field.
6467         (return_event::m_dest_snode): New field.
6468         * diagnostic-manager.cc
6469         (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>:
6470         Refactor to work with edges without callgraph edge.
6471         (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
6472         Likewise.
6473         * engine.cc (dynamic_call_info_t::update_model): New function.
6474         (dynamic_call_info_t::add_events_to_path): New function.
6475         (exploded_graph::create_dynamic_call): New function.
6476         (exploded_graph::process_node): Work with dynamically discovered calls.
6477         * exploded-graph.h (class dynamic_call_info_t): New class.
6478         (exploded_graph::create_dynamic_call): New decl.
6479         * program-point.cc (program_point::push_to_call_stack): New function.
6480         (program_point::pop_from_call_stack): New function.
6481         * program-point.h (program_point::push_to_call_stack): New decl.
6482         (program_point::pop_from_call_stack): New decl.
6483         * program-state.cc (program_state::push_call): New function.
6484         (program_state::returning_call): New function.
6485         * program-state.h (program_state::push_call): New decl.
6486         (program_state::returning_call): New decl.
6487         * region-model.cc (region_model::update_for_gcall) New function.
6488         (region_model::update_for_return_gcall): New function.
6489         (egion_model::update_for_call_superedge): Get the underlying gcall and
6490         update for gcall.
6491         (region_model::update_for_return_superedge): Likewise.
6492         * region-model.h (region_model::update_for_gcall): New decl.
6493         (region_model::update_for_return_gcall): New decl.
6494         * state-purge.cc (state_purge_per_ssa_name::process_point): Update to
6495         work with calls without underlying cgraph edge.
6496         * supergraph.cc (supergraph::supergraph) Split snodes at every callsite.
6497         * supergraph.h (supernode::get_returning_call) New accessor.
6499 2021-08-04  David Malcolm  <dmalcolm@redhat.com>
6501         PR analyzer/101570
6502         * analyzer.cc (maybe_reconstruct_from_def_stmt): Add GIMPLE_ASM
6503         case.
6504         * analyzer.h (class asm_output_svalue): New forward decl.
6505         (class reachable_regions): New forward decl.
6506         * complexity.cc (complexity::from_vec_svalue): New.
6507         * complexity.h (complexity::from_vec_svalue): New decl.
6508         * engine.cc (feasibility_state::maybe_update_for_edge): Handle
6509         asm stmts by calling on_asm_stmt.
6510         * region-model-asm.cc: New file.
6511         * region-model-manager.cc
6512         (region_model_manager::maybe_fold_asm_output_svalue): New.
6513         (region_model_manager::get_or_create_asm_output_svalue): New.
6514         (region_model_manager::log_stats): Log m_asm_output_values_map.
6515         * region-model.cc (region_model::on_stmt_pre): Handle GIMPLE_ASM.
6516         * region-model.h (visitor::visit_asm_output_svalue): New.
6517         (region_model_manager::get_or_create_asm_output_svalue): New decl.
6518         (region_model_manager::maybe_fold_asm_output_svalue): New decl.
6519         (region_model_manager::asm_output_values_map_t): New typedef.
6520         (region_model_manager::m_asm_output_values_map): New field.
6521         (region_model::on_asm_stmt): New.
6522         * store.cc (binding_cluster::on_asm): New.
6523         * store.h (binding_cluster::on_asm): New decl.
6524         * svalue.cc (svalue::cmp_ptr): Handle SK_ASM_OUTPUT.
6525         (asm_output_svalue::dump_to_pp): New.
6526         (asm_output_svalue::dump_input): New.
6527         (asm_output_svalue::input_idx_to_asm_idx): New.
6528         (asm_output_svalue::accept): New.
6529         * svalue.h (enum svalue_kind): Add SK_ASM_OUTPUT.
6530         (svalue::dyn_cast_asm_output_svalue): New.
6531         (class asm_output_svalue): New.
6532         (is_a_helper <const asm_output_svalue *>::test): New.
6533         (struct default_hash_traits<asm_output_svalue::key_t>): New.
6535 2021-08-03  Jakub Jelinek  <jakub@redhat.com>
6537         PR analyzer/101721
6538         * sm-malloc.cc (known_allocator_p): Only check DECL_FUNCTION_CODE on
6539         BUILT_IN_NORMAL builtins.
6541 2021-07-29  Ankur Saini  <arsenic@sourceware.org>
6543         * call-string.cc (call_string::element_t::operator==): New operator.
6544         (call_String::element_t::operator!=): New operator.
6545         (call_string::element_t::get_caller_function): New function.
6546         (call_string::element_t::get_callee_function): New function.
6547         (call_string::call_string): Refactor to Initialise m_elements.
6548         (call_string::operator=): Refactor to work with m_elements.
6549         (call_string::operator==): Likewise.
6550         (call_string::to_json): Likewise.
6551         (call_string::hash): Refactor to hash e.m_caller.
6552         (call_string::push_call): Refactor to work with m_elements.
6553         (call_string::push_call): New overload to push call via supernodes.
6554         (call_string::pop): Refactor to work with m_elements.
6555         (call_string::calc_recursion_depth): Likewise.
6556         (call_string::cmp): Likewise.
6557         (call_string::validate): Likewise.
6558         (call_string::operator[]): Likewise.
6559         * call-string.h (class supernode): New forward decl.
6560         (struct call_string::element_t): New struct.
6561         (call_string::call_string): Refactor to initialise m_elements.
6562         (call_string::bool empty_p): Refactor to work with m_elements.
6563         (call_string::get_callee_node): New decl.
6564         (call_string::get_caller_node): New decl.
6565         (m_elements): Replaces m_return_edges.
6566         * program-point.cc (program_point::get_function_at_depth): Refactor to
6567         work with new call-string format.
6568         (program_point::validate): Likewise.
6569         (program_point::on_edge): Likewise.
6571 2021-07-28  David Malcolm  <dmalcolm@redhat.com>
6573         * region-model.cc (region_model::on_call_pre): Treat
6574         IFN_UBSAN_BOUNDS, BUILT_IN_STACK_SAVE, and BUILT_IN_STACK_RESTORE
6575         as no-ops, rather than handling them as unknown functions.
6577 2021-07-28  David Malcolm  <dmalcolm@redhat.com>
6579         * region-model-impl-calls.cc (region_model::impl_call_alloca):
6580         Drop redundant return value.
6581         (region_model::impl_call_builtin_expect): Likewise.
6582         (region_model::impl_call_calloc): Likewise.
6583         (region_model::impl_call_malloc): Likewise.
6584         (region_model::impl_call_memset): Likewise.
6585         (region_model::impl_call_operator_new): Likewise.
6586         (region_model::impl_call_operator_delete): Likewise.
6587         (region_model::impl_call_strlen): Likewise.
6588         * region-model.cc (region_model::on_call_pre): Fix return value of
6589         known functions that don't have unknown side-effects.
6590         * region-model.h (region_model::impl_call_alloca): Drop redundant
6591         return value.
6592         (region_model::impl_call_builtin_expect): Likewise.
6593         (region_model::impl_call_calloc): Likewise.
6594         (region_model::impl_call_malloc): Likewise.
6595         (region_model::impl_call_memset): Likewise.
6596         (region_model::impl_call_strlen): Likewise.
6597         (region_model::impl_call_operator_new): Likewise.
6598         (region_model::impl_call_operator_delete): Likewise.
6600 2021-07-28  Siddhesh Poyarekar  <siddhesh@gotplt.org>
6602         * analyzer.cc (is_named_call_p, is_std_named_call_p): Make
6603         first argument a const_tree.
6604         * analyzer.h (is_named_call_p, -s_std_named_call_p): Likewise.
6605         * sm-malloc.cc (known_allocator_p): New function.
6606         (malloc_state_machine::on_stmt): Use it.
6608 2021-07-28  Siddhesh Poyarekar  <siddhesh@gotplt.org>
6610         * sm-malloc.cc
6611         (malloc_state_machine::get_or_create_deallocator): Recognize
6612         __builtin_free.
6614 2021-07-26  David Malcolm  <dmalcolm@redhat.com>
6616         * region-model.cc (region_model::on_call_pre): Always set conjured
6617         LHS, not just for SSA names.
6619 2021-07-23  David Malcolm  <dmalcolm@redhat.com>
6621         * diagnostic-manager.cc
6622         (class auto_disable_complexity_checks): New.
6623         (epath_finder::explore_feasible_paths): Use it to disable
6624         complexity checks whilst processing the worklist.
6625         * region-model-manager.cc
6626         (region_model_manager::region_model_manager): Initialize
6627         m_check_complexity.
6628         (region_model_manager::reject_if_too_complex): Bail if
6629         m_check_complexity is false.
6630         * region-model.h
6631         (region_model_manager::enable_complexity_check): New.
6632         (region_model_manager::disable_complexity_check): New.
6633         (region_model_manager::m_check_complexity): New.
6635 2021-07-21  David Malcolm  <dmalcolm@redhat.com>
6637         PR analyzer/101547
6638         * sm-file.cc (file_leak::emit): Handle m_arg being NULL.
6639         (file_leak::describe_final_event): Handle ev.m_expr being NULL.
6641 2021-07-21  David Malcolm  <dmalcolm@redhat.com>
6643         PR analyzer/101522
6644         * store.cc (binding_cluster::purge_state_involving): Don't change
6645         m_map whilst iterating through it.
6647 2021-07-21  David Malcolm  <dmalcolm@redhat.com>
6649         * region-model.cc (region_model::handle_phi): Add "old_state"
6650         param and use it.
6651         (region_model::update_for_phis): Update so that all of the phi
6652         stmts are effectively handled simultaneously, rather than in
6653         order.
6654         * region-model.h (region_model::handle_phi): Add "old_state"
6655         param.
6656         * state-purge.cc (self_referential_phi_p): Replace with...
6657         (name_used_by_phis_p): ...this new function.
6658         (state_purge_per_ssa_name::process_point): Update to use the
6659         above, so that all phi stmts at a basic block are effectively
6660         considered simultaneously, and only consider the phi arguments for
6661         the pertinent in-edge.
6662         * supergraph.cc (cfg_superedge::get_phi_arg_idx): New.
6663         (cfg_superedge::get_phi_arg): Use the above.
6664         * supergraph.h (cfg_superedge::get_phi_arg_idx): New decl.
6666 2021-07-21  David Malcolm  <dmalcolm@redhat.com>
6668         * state-purge.cc (state_purge_annotator::add_node_annotations):
6669         Rather than erroneously always using the NULL in-edge, determine
6670         each relevant in-edge, and print the appropriate data for each
6671         in-edge.  Use print_needed to print the data as comma-separated
6672         lists of SSA names.
6673         (print_vec_of_names): Add "within_table" param and use it.
6674         (state_purge_annotator::add_stmt_annotations): Factor out
6675         collation and printing code into...
6676         (state_purge_annotator::print_needed): ...this new function.
6677         * state-purge.h (state_purge_annotator::print_needed): New decl.
6679 2021-07-21  David Malcolm  <dmalcolm@redhat.com>
6681         * program-point.cc (function_point::print): Show src BB index at
6682         BEFORE_SUPERNODE.
6684 2021-07-21  David Malcolm  <dmalcolm@redhat.com>
6686         * svalue.cc (infix_p): New.
6687         (binop_svalue::dump_to_pp): Use it to print MIN_EXPR and MAX_EXPR
6688         in prefix form, rather than infix.
6690 2021-07-19  David Malcolm  <dmalcolm@redhat.com>
6692         PR analyzer/101503
6693         * constraint-manager.cc (constraint_manager::add_constraint): Use
6694         can_have_associated_state_p rather than testing for unknown.
6695         (constraint_manager::get_or_add_equiv_class): Likewise.
6696         * program-state.cc (sm_state_map::set_state): Likewise.
6697         (sm_state_map::impl_set_state): Add assertion.
6698         * region-model-manager.cc
6699         (region_model_manager::maybe_fold_unaryop): Handle poisoned
6700         values.
6701         (region_model_manager::maybe_fold_binop): Move handling of unknown
6702         values...
6703         (region_model_manager::get_or_create_binop): ...to here, and
6704         generalize to use can_have_associated_state_p.
6705         (region_model_manager::maybe_fold_sub_svalue): Use
6706         can_have_associated_state_p rather than testing for unknown.
6707         (region_model_manager::maybe_fold_repeated_svalue): Use unknown
6708         when the size or repeated value is "unknown"/"poisoned".
6709         * region-model.cc (region_model::purge_state_involving): Reject
6710         attempts to purge unknown/poisoned svalues, as these svalues
6711         should not have state associated with them.
6712         * svalue.cc (sub_svalue::sub_svalue): Assert that we're building
6713         on top of an svalue with can_have_associated_state_p.
6714         (repeated_svalue::repeated_svalue): Likewise.
6715         (bits_within_svalue::bits_within_svalue): Likewise.
6716         * svalue.h (svalue::can_have_associated_state_p): New.
6717         (unknown_svalue::can_have_associated_state_p): New.
6718         (poisoned_svalue::can_have_associated_state_p): New.
6719         (unaryop_svalue::unaryop_svalue): Assert that we're building on
6720         top of an svalue with can_have_associated_state_p.
6721         (binop_svalue::binop_svalue): Likewise.
6722         (widening_svalue::widening_svalue): Likewise.
6724 2021-07-16  David Malcolm  <dmalcolm@redhat.com>
6726         * analyzer.h (enum access_direction): New.
6727         * engine.cc (exploded_node::on_longjmp): Update for new param of
6728         get_store_value.
6729         * program-state.cc (program_state::prune_for_point): Likewise.
6730         * region-model-impl-calls.cc (region_model::impl_call_memcpy):
6731         Replace call to check_for_writable_region with call to
6732         check_region_for_write.
6733         (region_model::impl_call_memset): Likewise.
6734         (region_model::impl_call_strcpy): Likewise.
6735         * region-model-reachability.cc (reachable_regions::add): Update
6736         for new param of get_store_value.
6737         * region-model.cc (region_model::get_rvalue_1): Likewise, also for
6738         get_rvalue_for_bits.
6739         (region_model::get_store_value): Add ctxt param and use it to call
6740         check_region_for_read.
6741         (region_model::get_rvalue_for_bits): Add ctxt param and use it to
6742         call get_store_value.
6743         (region_model::check_region_access): New.
6744         (region_model::check_region_for_write): New.
6745         (region_model::check_region_for_read): New.
6746         (region_model::set_value): Update comment.  Replace call to
6747         check_for_writable_region with call to check_region_for_write.
6748         * region-model.h (region_model::get_rvalue_for_bits): Add ctxt
6749         param.
6750         (region_model::get_store_value): Add ctxt param.
6751         (region_model::check_region_access): New decl.
6752         (region_model::check_region_for_write): New decl.
6753         (region_model::check_region_for_read): New decl.
6754         * region.cc (region_model::copy_region): Update call to
6755         get_store_value.
6756         * svalue.cc (initial_svalue::implicitly_live_p): Likewise.
6758 2021-07-16  David Malcolm  <dmalcolm@redhat.com>
6760         * engine.cc (exploded_node::on_stmt_pre): Handle
6761         __analyzer_dump_state.
6762         * program-state.cc (extrinsic_state::get_sm_idx_by_name): New.
6763         (program_state::impl_call_analyzer_dump_state): New.
6764         * program-state.h (extrinsic_state::get_sm_idx_by_name): New decl.
6765         (program_state::impl_call_analyzer_dump_state): New decl.
6766         * region-model-impl-calls.cc
6767         (call_details::get_arg_string_literal): New.
6768         * region-model.h (call_details::get_arg_string_literal): New decl.
6770 2021-07-16  David Malcolm  <dmalcolm@redhat.com>
6772         * program-state.cc (program_state::detect_leaks): Simplify using
6773         svalue::maybe_get_region.
6774         * region-model-impl-calls.cc (region_model::impl_call_fgets): Likewise.
6775         (region_model::impl_call_fread): Likewise.
6776         (region_model::impl_call_free): Likewise.
6777         (region_model::impl_call_operator_delete): Likewise.
6778         * region-model.cc (selftest::test_stack_frames): Likewise.
6779         (selftest::test_state_merging): Likewise.
6780         * svalue.cc (svalue::maybe_get_region): New.
6781         * svalue.h (svalue::maybe_get_region): New decl.
6783 2021-07-15  David Malcolm  <dmalcolm@redhat.com>
6785         * svalue.h (is_a_helper <placeholder_svalue *>::test): Make
6786         param and template param const.
6787         (is_a_helper <widening_svalue *>::test): Likewise.
6788         (is_a_helper <compound_svalue *>::test): Likewise.
6789         (is_a_helper <conjured_svalue *>::test): Likewise.
6791 2021-07-15  David Malcolm  <dmalcolm@redhat.com>
6793         PR analyzer/95006
6794         PR analyzer/94713
6795         PR analyzer/94714
6796         * analyzer.cc (maybe_reconstruct_from_def_stmt): Split out
6797         GIMPLE_ASSIGN case into...
6798         (get_diagnostic_tree_for_gassign_1): New.
6799         (get_diagnostic_tree_for_gassign): New.
6800         * analyzer.h (get_diagnostic_tree_for_gassign): New decl.
6801         * analyzer.opt (Wanalyzer-write-to-string-literal): New.
6802         * constraint-manager.cc (class svalue_purger): New.
6803         (constraint_manager::purge_state_involving): New.
6804         * constraint-manager.h
6805         (constraint_manager::purge_state_involving): New.
6806         * diagnostic-manager.cc (saved_diagnostic::supercedes_p): New.
6807         (dedupe_winners::handle_interactions): New.
6808         (diagnostic_manager::emit_saved_diagnostics): Call it.
6809         * diagnostic-manager.h (saved_diagnostic::supercedes_p): New decl.
6810         * engine.cc (impl_region_model_context::warn): Convert return type
6811         to bool.  Return false if the diagnostic isn't saved.
6812         (impl_region_model_context::purge_state_involving): New.
6813         (impl_sm_context::get_state): Use NULL ctxt when querying old
6814         rvalue.
6815         (impl_sm_context::set_next_state): Use new sval when querying old
6816         state.
6817         (class dump_path_diagnostic): Move to region-model.cc
6818         (exploded_node::on_stmt): Move to on_stmt_pre and on_stmt_post.
6819         Remove call to purge_state_involving.
6820         (exploded_node::on_stmt_pre): New, based on the above.  Move most
6821         of it to region_model::on_stmt_pre.
6822         (exploded_node::on_stmt_post): Likewise, moving to
6823         region_model::on_stmt_post.
6824         (class stale_jmp_buf): Fix parent class to use curiously recurring
6825         template pattern.
6826         (feasibility_state::maybe_update_for_edge): Call on_call_pre and
6827         on_call_post on gcalls.
6828         * exploded-graph.h (impl_region_model_context::warn): Return bool.
6829         (impl_region_model_context::purge_state_involving): New decl.
6830         (exploded_node::on_stmt_pre): New decl.
6831         (exploded_node::on_stmt_post): New decl.
6832         * pending-diagnostic.h (pending_diagnostic::use_of_uninit_p): New.
6833         (pending_diagnostic::supercedes_p): New.
6834         * program-state.cc (sm_state_map::get_state): Inherit state for
6835         conjured_svalue as well as initial_svalue.
6836         (sm_state_map::purge_state_involving): Also support SK_CONJURED.
6837         * region-model-impl-calls.cc (call_details::get_uncertainty):
6838         Handle m_ctxt being NULL.
6839         (call_details::get_or_create_conjured_svalue): New.
6840         (region_model::impl_call_fgets): New.
6841         (region_model::impl_call_fread): New.
6842         * region-model-manager.cc
6843         (region_model_manager::get_or_create_initial_value): Return an
6844         uninitialized poisoned value for regions that can't have initial
6845         values.
6846         * region-model-reachability.cc
6847         (reachable_regions::mark_escaped_clusters): Handle ctxt being
6848         NULL.
6849         * region-model.cc (region_to_value_map::purge_state_involving): New.
6850         (poisoned_value_diagnostic::use_of_uninit_p): New.
6851         (poisoned_value_diagnostic::emit): Handle POISON_KIND_UNINIT.
6852         (poisoned_value_diagnostic::describe_final_event): Likewise.
6853         (region_model::check_for_poison): New.
6854         (region_model::on_assignment): Call it.
6855         (class dump_path_diagnostic): Move here from engine.cc.
6856         (region_model::on_stmt_pre): New, based on exploded_node::on_stmt.
6857         (region_model::on_call_pre): Move the setting of the LHS to a
6858         conjured svalue to before the checks for specific functions.
6859         Handle "fgets", "fgets_unlocked", and "fread".
6860         (region_model::purge_state_involving): New.
6861         (region_model::handle_unrecognized_call): Handle ctxt being NULL.
6862         (region_model::get_rvalue): Call check_for_poison.
6863         (selftest::test_stack_frames): Use NULL for context when getting
6864         uninitialized rvalue.
6865         (selftest::test_alloca): Likewise.
6866         * region-model.h (region_to_value_map::purge_state_involving): New
6867         decl.
6868         (call_details::get_or_create_conjured_svalue): New decl.
6869         (region_model::on_stmt_pre): New decl.
6870         (region_model::purge_state_involving): New decl.
6871         (region_model::impl_call_fgets): New decl.
6872         (region_model::impl_call_fread): New decl.
6873         (region_model::check_for_poison): New decl.
6874         (region_model_context::warn): Return bool.
6875         (region_model_context::purge_state_involving): New.
6876         (noop_region_model_context::warn): Return bool.
6877         (noop_region_model_context::purge_state_involving): New.
6878         (test_region_model_context:: warn): Return bool.
6879         * region.cc (region::get_memory_space): New.
6880         (region::can_have_initial_svalue_p): New.
6881         (region::involves_p): New.
6882         * region.h (enum memory_space): New.
6883         (region::get_memory_space): New decl.
6884         (region::can_have_initial_svalue_p): New decl.
6885         (region::involves_p): New decl.
6886         * sm-malloc.cc (use_after_free::supercedes_p): New.
6887         * store.cc (binding_cluster::purge_state_involving): New.
6888         (store::purge_state_involving): New.
6889         * store.h (class symbolic_binding): New forward decl.
6890         (binding_key::dyn_cast_symbolic_binding): New.
6891         (symbolic_binding::dyn_cast_symbolic_binding): New.
6892         (binding_cluster::purge_state_involving): New.
6893         (store::purge_state_involving): New.
6894         * svalue.cc (svalue::can_merge_p): Reject attempts to merge
6895         poisoned svalues with other svalues, so that we identify
6896         paths in which a variable is conditionally uninitialized.
6897         (involvement_visitor::visit_conjured_svalue): New.
6898         (svalue::involves_p): Also handle SK_CONJURED.
6899         (poison_kind_to_str): Handle POISON_KIND_UNINIT.
6900         (poisoned_svalue::maybe_fold_bits_within): New.
6901         * svalue.h (enum poison_kind): Add POISON_KIND_UNINIT.
6902         (poisoned_svalue::maybe_fold_bits_within): New decl.
6904 2021-07-15  David Malcolm  <dmalcolm@redhat.com>
6906         * analyzer.opt (fdump-analyzer-exploded-paths): New.
6907         * diagnostic-manager.cc
6908         (diagnostic_manager::emit_saved_diagnostic): Implement it.
6909         * engine.cc (exploded_path::dump_to_pp): Add ext_state param and
6910         use it to dump states if non-NULL.
6911         (exploded_path::dump): Likewise.
6912         (exploded_path::dump_to_file): New.
6913         * exploded-graph.h (exploded_path::dump_to_pp): Add ext_state
6914         param.
6915         (exploded_path::dump): Likewise.
6916         (exploded_path::dump): Likewise.
6917         (exploded_path::dump_to_file): New.
6919 2021-07-15  David Malcolm  <dmalcolm@redhat.com>
6921         * analyzer.cc (fixup_tree_for_diagnostic_1): Use DECL_DEBUG_EXPR
6922         if it's available.
6923         * engine.cc (readability): Likewise.
6925 2021-07-15  David Malcolm  <dmalcolm@redhat.com>
6927         * state-purge.cc (self_referential_phi_p): New.
6928         (state_purge_per_ssa_name::process_point): Don't purge an SSA name
6929         at its def-stmt if the def-stmt is self-referential.
6931 2021-07-07  David Malcolm  <dmalcolm@redhat.com>
6933         * diagnostic-manager.cc (null_assignment_sm_context::get_state):
6934         New overload.
6935         (null_assignment_sm_context::set_next_state): New overload.
6936         (null_assignment_sm_context::get_diagnostic_tree): New.
6937         * engine.cc (impl_sm_context::get_state): New overload.
6938         (impl_sm_context::set_next_state): New overload.
6939         (impl_sm_context::get_diagnostic_tree): New overload.
6940         (impl_region_model_context::on_condition): Convert params from
6941         tree to const svalue *.
6942         * exploded-graph.h (impl_region_model_context::on_condition):
6943         Likewise.
6944         * region-model.cc (region_model::on_call_pre): Move handling of
6945         internal calls to before checking for get_fndecl_for_call.
6946         (region_model::add_constraints_from_binop): New.
6947         (region_model::add_constraint): Split out into a new overload
6948         working on const svalue * rather than tree.  Call
6949         add_constraints_from_binop.  Drop call to
6950         add_any_constraints_from_ssa_def_stmt.
6951         (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6952         (region_model::add_any_constraints_from_gassign): Delete.
6953         (region_model::add_any_constraints_from_gcall): Delete.
6954         * region-model.h
6955         (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6956         (region_model::add_any_constraints_from_gassign): Delete.
6957         (region_model::add_any_constraints_from_gcall): Delete.
6958         (region_model::add_constraint): Add overload decl.
6959         (region_model::add_constraints_from_binop): New decl.
6960         (region_model_context::on_condition): Convert params from tree to
6961         const svalue *.
6962         (noop_region_model_context::on_condition): Likewise.
6963         * sm-file.cc (fileptr_state_machine::condition): Likewise.
6964         * sm-malloc.cc (malloc_state_machine::on_condition): Likewise.
6965         * sm-pattern-test.cc: Include tristate.h, selftest.h,
6966         analyzer/call-string.h, analyzer/program-point.h,
6967         analyzer/store.h, and analyzer/region-model.h.
6968         (pattern_test_state_machine::on_condition): Convert params from tree to
6969         const svalue *.
6970         * sm-sensitive.cc (sensitive_state_machine::on_condition): Delete.
6971         * sm-signal.cc (signal_state_machine::on_condition): Delete.
6972         * sm-taint.cc (taint_state_machine::on_condition): Convert params
6973         from tree to const svalue *.
6974         * sm.cc: Include tristate.h, selftest.h, analyzer/call-string.h,
6975         analyzer/program-point.h, analyzer/store.h, and
6976         analyzer/region-model.h.
6977         (any_pointer_p): Add overload taking const svalue *sval.
6978         * sm.h (any_pointer_p): Add overload taking const svalue *sval.
6979         (state_machine::on_condition): Convert params from tree to
6980         const svalue *.  Provide no-op default implementation.
6981         (sm_context::get_state): Add overload taking const svalue *sval.
6982         (sm_context::set_next_state): Likewise.
6983         (sm_context::on_transition): Likewise.
6984         (sm_context::get_diagnostic_tree): Likewise.
6985         * svalue.cc (svalue::all_zeroes_p): New.
6986         (constant_svalue::all_zeroes_p): New.
6987         (repeated_svalue::all_zeroes_p): Convert to vfunc.
6988         * svalue.h (svalue::all_zeroes_p): New decl.
6989         (constant_svalue::all_zeroes_p): New decl.
6990         (repeated_svalue::all_zeroes_p): Convert decl to vfunc.
6992 2021-06-30  David Malcolm  <dmalcolm@redhat.com>
6994         PR analyzer/95006
6995         * analyzer.h (class repeated_svalue): New forward decl.
6996         (class bits_within_svalue): New forward decl.
6997         (class sized_region): New forward decl.
6998         (get_field_at_bit_offset): New forward decl.
6999         * engine.cc (exploded_graph::get_or_create_node): Validate the
7000         merged state.
7001         (exploded_graph::maybe_process_run_of_before_supernode_enodes):
7002         Validate the states at each stage.
7003         * program-state.cc (program_state::validate): Validate
7004         m_region_model.
7005         * region-model-impl-calls.cc (region_model::impl_call_memset):
7006         Replace special-case logic for handling constant sizes with
7007         a call to fill_region of a sized_region with the given fill value.
7008         * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
7009         Drop DK_direct.
7010         (region_model_manager::maybe_fold_sub_svalue):  Fold element-based
7011         subregions of an initial value into initial values of an element.
7012         Fold subvalues of repeated svalues.
7013         (region_model_manager::maybe_fold_repeated_svalue): New.
7014         (region_model_manager::get_or_create_repeated_svalue): New.
7015         (get_bit_range_for_field): New.
7016         (get_byte_range_for_field): New.
7017         (get_field_at_byte_range): New.
7018         (region_model_manager::maybe_fold_bits_within_svalue): New.
7019         (region_model_manager::get_or_create_bits_within): New.
7020         (region_model_manager::get_sized_region): New.
7021         (region_model_manager::log_stats): Update for addition of
7022         m_repeated_values_map, m_bits_within_values_map, and
7023         m_sized_regions.
7024         * region-model.cc (region_model::validate): New.
7025         (region_model::on_assignment): Drop enum binding_kind.
7026         (region_model::get_initial_value_for_global): Likewise.
7027         (region_model::get_rvalue_for_bits): Replace body with call to
7028         get_or_create_bits_within.
7029         (region_model::get_capacity): Handle RK_SIZED.
7030         (region_model::set_value): Drop enum binding_kind.
7031         (region_model::fill_region): New.
7032         (region_model::get_representative_path_var_1): Handle RK_SIZED.
7033         * region-model.h (visitor::visit_repeated_svalue): New.
7034         (visitor::visit_bits_within_svalue): New.
7035         (region_model_manager::get_or_create_repeated_svalue): New decl.
7036         (region_model_manager::get_or_create_bits_within): New decl.
7037         (region_model_manager::get_sized_region): New decl.
7038         (region_model_manager::maybe_fold_repeated_svalue): New decl.
7039         (region_model_manager::maybe_fold_bits_within_svalue): New decl.
7040         (region_model_manager::repeated_values_map_t): New typedef.
7041         (region_model_manager::m_repeated_values_map): New field.
7042         (region_model_manager::bits_within_values_map_t): New typedef.
7043         (region_model_manager::m_bits_within_values_map): New field.
7044         (region_model_manager::m_sized_regions): New field.
7045         (region_model::fill_region): New decl.
7046         * region.cc (region::get_base_region): Handle RK_SIZED.
7047         (region::base_region_p): Likewise.
7048         (region::get_byte_size_sval): New.
7049         (get_field_at_bit_offset): Make non-static.
7050         (region::calc_offset): Move implementation of cases to
7051         get_relative_concrete_offset vfunc implementations.  Handle
7052         RK_SIZED.
7053         (region::get_relative_concrete_offset): New.
7054         (decl_region::get_svalue_for_initializer): Drop enum binding_kind.
7055         (field_region::get_relative_concrete_offset): New, from
7056         region::calc_offset.
7057         (element_region::get_relative_concrete_offset): Likewise.
7058         (offset_region::get_relative_concrete_offset): Likewise.
7059         (sized_region::accept): New.
7060         (sized_region::dump_to_pp): New.
7061         (sized_region::get_byte_size): New.
7062         (sized_region::get_bit_size): New.
7063         * region.h (enum region_kind): Add RK_SIZED.
7064         (region::dyn_cast_sized_region): New.
7065         (region::get_byte_size): Make virtual.
7066         (region::get_bit_size): Likewise.
7067         (region::get_byte_size_sval): New decl.
7068         (region::get_relative_concrete_offset): New decl.
7069         (field_region::get_relative_concrete_offset): New decl.
7070         (element_region::get_relative_concrete_offset): Likewise.
7071         (offset_region::get_relative_concrete_offset): Likewise.
7072         (class sized_region): New.
7073         * store.cc (binding_kind_to_string): Delete.
7074         (binding_key::make): Drop enum binding_kind.
7075         (binding_key::dump_to_pp): Delete.
7076         (binding_key::cmp_ptrs): Drop enum binding_kind.
7077         (bit_range::contains_p): New.
7078         (byte_range::dump): New.
7079         (byte_range::contains_p): New.
7080         (byte_range::cmp): New.
7081         (concrete_binding::dump_to_pp): Drop enum binding_kind.
7082         (concrete_binding::cmp_ptr_ptr): Likewise.
7083         (symbolic_binding::dump_to_pp): Likewise.
7084         (symbolic_binding::cmp_ptr_ptr): Likewise.
7085         (binding_map::apply_ctor_val_to_range): Likewise.
7086         (binding_map::apply_ctor_pair_to_child_region): Likewise.
7087         (binding_map::get_overlapping_bindings): New.
7088         (binding_map::remove_overlapping_bindings): New.
7089         (binding_cluster::validate): New.
7090         (binding_cluster::bind): Drop enum binding_kind.
7091         (binding_cluster::bind_compound_sval): Likewise.
7092         (binding_cluster::purge_region): Likewise.
7093         (binding_cluster::zero_fill_region): Reimplement in terms of...
7094         (binding_cluster::fill_region): New.
7095         (binding_cluster::mark_region_as_unknown): Drop enum binding_kind.
7096         (binding_cluster::get_binding): Likewise.
7097         (binding_cluster::get_binding_recursive): Likewise.
7098         (binding_cluster::get_any_binding): Likewise.
7099         (binding_cluster::maybe_get_compound_binding): Reimplement.
7100         (binding_cluster::get_overlapping_bindings): Delete.
7101         (binding_cluster::remove_overlapping_bindings): Reimplement in
7102         terms of binding_map::remove_overlapping_bindings.
7103         (binding_cluster::can_merge_p): Update for removal of
7104         enum binding_kind.
7105         (binding_cluster::on_unknown_fncall): Drop enum binding_kind.
7106         (binding_cluster::maybe_get_simple_value): Likewise.
7107         (store_manager::get_concrete_binding): Likewise.
7108         (store_manager::get_symbolic_binding): Likewise.
7109         (store::validate): New.
7110         (store::set_value): Drop enum binding_kind.
7111         (store::zero_fill_region): Reimplement in terms of...
7112         (store::fill_region): New.
7113         (selftest::test_binding_key_overlap): Drop enum binding_kind.
7114         * store.h (enum binding_kind): Delete.
7115         (binding_kind_to_string): Delete decl.
7116         (binding_key::make): Drop enum binding_kind.
7117         (binding_key::dump_to_pp): Make pure virtual.
7118         (binding_key::get_kind): Delete.
7119         (binding_key::mark_deleted): Delete.
7120         (binding_key::mark_empty): Delete.
7121         (binding_key::is_deleted): Delete.
7122         (binding_key::is_empty): Delete.
7123         (binding_key::binding_key): Delete.
7124         (binding_key::impl_hash): Delete.
7125         (binding_key::impl_eq): Delete.
7126         (binding_key::m_kind): Delete.
7127         (bit_range::get_last_bit_offset): New.
7128         (bit_range::contains_p): New.
7129         (byte_range::contains_p): New.
7130         (byte_range::operator==): New.
7131         (byte_range::get_start_byte_offset): New.
7132         (byte_range::get_next_byte_offset): New.
7133         (byte_range::get_last_byte_offset): New.
7134         (byte_range::as_bit_range): New.
7135         (byte_range::cmp): New.
7136         (concrete_binding::concrete_binding): Drop enum binding_kind.
7137         (concrete_binding::hash): Likewise.
7138         (concrete_binding::operator==): Likewise.
7139         (concrete_binding::mark_deleted): New.
7140         (concrete_binding::mark_empty): New.
7141         (concrete_binding::is_deleted): New.
7142         (concrete_binding::is_empty): New.
7143         (default_hash_traits<ana::concrete_binding>::empty_zero_p): Make false.
7144         (symbolic_binding::symbolic_binding): Drop enum binding_kind.
7145         (symbolic_binding::hash): Likewise.
7146         (symbolic_binding::operator==): Likewise.
7147         (symbolic_binding::mark_deleted): New.
7148         (symbolic_binding::mark_empty): New.
7149         (symbolic_binding::is_deleted): New.
7150         (symbolic_binding::is_empty): New.
7151         (binding_map::remove_overlapping_bindings): New decl.
7152         (binding_map::get_overlapping_bindings): New decl.
7153         (binding_cluster::validate): New decl.
7154         (binding_cluster::bind): Drop enum binding_kind.
7155         (binding_cluster::fill_region): New decl.
7156         (binding_cluster::get_binding): Drop enum binding_kind.
7157         (binding_cluster::get_binding_recursive): Likewise.
7158         (binding_cluster::get_overlapping_bindings): Delete.
7159         (store::validate): New decl.
7160         (store::set_value): Drop enum binding_kind.
7161         (store::fill_region): New decl.
7162         (store_manager::get_concrete_binding): Drop enum binding_kind.
7163         (store_manager::get_symbolic_binding): Likewise.
7164         * svalue.cc (svalue::cmp_ptr): Handle SK_REPEATED and
7165         SK_BITS_WITHIN.
7166         (svalue::extract_bit_range): New.
7167         (svalue::maybe_fold_bits_within): New.
7168         (constant_svalue::maybe_fold_bits_within): New.
7169         (unknown_svalue::maybe_fold_bits_within): New.
7170         (unaryop_svalue::maybe_fold_bits_within): New.
7171         (repeated_svalue::repeated_svalue): New.
7172         (repeated_svalue::dump_to_pp): New.
7173         (repeated_svalue::accept): New.
7174         (repeated_svalue::all_zeroes_p): New.
7175         (repeated_svalue::maybe_fold_bits_within): New.
7176         (bits_within_svalue::bits_within_svalue): New.
7177         (bits_within_svalue::dump_to_pp): New.
7178         (bits_within_svalue::maybe_fold_bits_within): New.
7179         (bits_within_svalue::accept): New.
7180         (bits_within_svalue::implicitly_live_p): New.
7181         (compound_svalue::maybe_fold_bits_within): New.
7182         * svalue.h (enum svalue_kind): Add SK_REPEATED and SK_BITS_WITHIN.
7183         (svalue::dyn_cast_repeated_svalue): New.
7184         (svalue::dyn_cast_bits_within_svalue): New.
7185         (svalue::extract_bit_range): New decl.
7186         (svalue::maybe_fold_bits_within): New vfunc decl.
7187         (region_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7188         (region_svalue::key_t::is_empty): Likewise.
7189         (default_hash_traits<region_svalue::key_t>::empty_zero_p): Make false.
7190         (constant_svalue::maybe_fold_bits_within): New.
7191         (unknown_svalue::maybe_fold_bits_within): New.
7192         (poisoned_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7193         (poisoned_svalue::key_t::is_empty): Likewise.
7194         (default_hash_traits<poisoned_svalue::key_t>::empty_zero_p): Make
7195         false.
7196         (setjmp_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7197         (setjmp_svalue::key_t::is_empty): Likewise.
7198         (default_hash_traits<setjmp_svalue::key_t>::empty_zero_p): Make
7199         false.
7200         (unaryop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7201         (unaryop_svalue::key_t::is_empty): Likewise.
7202         (unaryop_svalue::maybe_fold_bits_within): New.
7203         (default_hash_traits<unaryop_svalue::key_t>::empty_zero_p): Make
7204         false.
7205         (binop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7206         (binop_svalue::key_t::is_empty): Likewise.
7207         (default_hash_traits<binop_svalue::key_t>::empty_zero_p): Make
7208         false.
7209         (sub_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7210         (sub_svalue::key_t::is_empty): Likewise.
7211         (default_hash_traits<sub_svalue::key_t>::empty_zero_p): Make
7212         false.
7213         (class repeated_svalue): New.
7214         (is_a_helper <const repeated_svalue *>::test): New.
7215         (struct default_hash_traits<repeated_svalue::key_t>): New.
7216         (class bits_within_svalue): New.
7217         (is_a_helper <const bits_within_svalue *>::test): New.
7218         (struct default_hash_traits<bits_within_svalue::key_t>): New.
7219         (widening_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7220         (widening_svalue::key_t::is_empty): Likewise.
7221         (default_hash_traits<widening_svalue::key_t>::empty_zero_p): Make
7222         false.
7223         (compound_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
7224         (compound_svalue::key_t::is_empty): Likewise.
7225         (compound_svalue::maybe_fold_bits_within): New.
7226         (default_hash_traits<compound_svalue::key_t>::empty_zero_p): Make
7227         false.
7229 2021-06-28  David Malcolm  <dmalcolm@redhat.com>
7231         * analyzer.h (byte_offset_t): New typedef.
7232         * store.cc (bit_range::dump_to_pp): Dump as a byte range if
7233         possible.
7234         (bit_range::as_byte_range): New.
7235         (byte_range::dump_to_pp): New.
7236         * store.h (class byte_range): New forward decl.
7237         (struct bit_range): Add comment.
7238         (bit_range::as_byte_range): New decl.
7239         (struct byte_range): New.
7241 2021-06-22  David Malcolm  <dmalcolm@redhat.com>
7243         PR analyzer/101143
7244         * region-model.cc (compat_types_p): New function.
7245         (region_model::create_region_for_heap_alloc): Convert assertion to
7246         an error check.
7247         (region_model::create_region_for_alloca): Likewise.
7249 2021-06-18  David Malcolm  <dmalcolm@redhat.com>
7251         * store.cc (binding_cluster::get_any_binding): Make symbolic reads
7252         from a cluster with concrete bindings return unknown.
7254 2021-06-18  David Malcolm  <dmalcolm@redhat.com>
7256         * region-model-manager.cc
7257         (region_model_manager::get_or_create_int_cst): New.
7258         (region_model_manager::maybe_undo_optimize_bit_field_compare): Use
7259         it to simplify away a local tree.
7260         * region-model.cc (region_model::on_setjmp): Likewise.
7261         (region_model::on_longjmp): Likewise.
7262         * region-model.h (region_model_manager::get_or_create_int_cst):
7263         New decl.
7264         * store.cc (binding_cluster::zero_fill_region): Use it to simplify
7265         away a local tree.
7267 2021-06-18  David Malcolm  <dmalcolm@redhat.com>
7269         * checker-path.cc (class custom_event): Make abstract to allow for
7270         custom vfuncs, splitting existing implementation into...
7271         (class precanned_custom_event): New subclass.
7272         (custom_event::get_desc): Move to...
7273         (precanned_custom_event::get_desc): ...subclass.
7274         * checker-path.h (class custom_event): Make abstract to allow for
7275         custom vfuncs, splitting existing implementation into...
7276         (class precanned_custom_event): New subclass.
7277         * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
7278         Use precanned_custom_event.
7279         * engine.cc
7280         (stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise.
7281         * sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path):
7282         Likewise.
7284 2021-06-15  David Malcolm  <dmalcolm@redhat.com>
7286         PR analyzer/99212
7287         PR analyzer/101082
7288         * engine.cc: Include "target.h".
7289         (impl_run_checkers): Log BITS_BIG_ENDIAN, BYTES_BIG_ENDIAN, and
7290         WORDS_BIG_ENDIAN.
7291         * region-model-manager.cc
7292         (region_model_manager::maybe_fold_binop): Move support for masking
7293         via ARG0 & CST into...
7294         (region_model_manager::maybe_undo_optimize_bit_field_compare):
7295         ...this new function.  Flatten by converting from nested
7296         conditionals to a series of early return statements to reject
7297         failures.  Reject if type is not unsigned_char_type_node.
7298         Handle BYTES_BIG_ENDIAN when determining which bits are bound
7299         in the binding_map.
7300         * region-model.h
7301         (region_model_manager::maybe_undo_optimize_bit_field_compare):
7302         New decl.
7303         * store.cc (bit_range::dump): New function.
7304         * store.h (bit_range::dump): New decl.
7306 2021-06-15  David Malcolm  <dmalcolm@redhat.com>
7308         * engine.cc (exploded_node::on_stmt): Handle __analyzer_dump_capacity.
7309         (exploded_node::on_stmt): Drop m_sm_changes from on_stmt_flags.
7310         (state_change_requires_new_enode_p): New function...
7311         (exploded_graph::process_node): Call it, rather than querying
7312         flags.m_sm_changes, so that dynamic-extent differences can also
7313         trigger the splitting of nodes.
7314         * exploded-graph.h (struct on_stmt_flags): Drop field m_sm_changes.
7315         * program-state.cc (program_state::detect_leaks): Purge dead
7316         heap-allocated regions from dynamic extents.
7317         (selftest::test_program_state_1): Fix type of "size_in_bytes".
7318         (selftest::test_program_state_merging): Likewise.
7319         * region-model-impl-calls.cc
7320         (region_model::impl_call_analyzer_dump_capacity): New.
7321         (region_model::impl_call_free): Remove dynamic extents from the
7322         freed region.
7323         * region-model-reachability.h
7324         (reachable_regions::begin_mutable_base_regs): New.
7325         (reachable_regions::end_mutable_base_regs): New.
7326         * region-model.cc: Include "tree-object-size.h".
7327         (region_model::region_model): Support new field m_dynamic_extents.
7328         (region_model::operator=): Likewise.
7329         (region_model::operator==): Likewise.
7330         (region_model::dump_to_pp): Dump sizes of dynamic regions.
7331         (region_model::handle_unrecognized_call): Purge dynamic extents
7332         from any regions that have escaped mutably:.
7333         (region_model::get_capacity): New function.
7334         (region_model::add_constraint): Unset dynamic extents when a
7335         heap-allocated region's address is NULL.
7336         (region_model::unbind_region_and_descendents): Purge dynamic
7337         extents of unbound regions.
7338         (region_model::can_merge_with_p): Call
7339         m_dynamic_extents.can_merge_with_p.
7340         (region_model::create_region_for_heap_alloc): Assert that
7341         size_in_bytes's type is compatible with size_type_node.  Update
7342         for renaming of record_dynamic_extents to set_dynamic_extents.
7343         (region_model::create_region_for_alloca): Likewise.
7344         (region_model::record_dynamic_extents): Rename to...
7345         (region_model::set_dynamic_extents): ...this.  Assert that
7346         size_in_bytes's type is compatible with size_type_node.  Add it
7347         to the m_dynamic_extents map.
7348         (region_model::get_dynamic_extents): New.
7349         (region_model::unset_dynamic_extents): New.
7350         (selftest::test_state_merging): Fix type of "size".
7351         (selftest::test_malloc_constraints): Likewise.
7352         (selftest::test_malloc): Verify dynamic extents.
7353         (selftest::test_alloca): Likewise.
7354         * region-model.h (region_to_value_map::is_empty): New.
7355         (region_model::dynamic_extents_t): New typedef.
7356         (region_model::impl_call_analyzer_dump_capacity): New decl.
7357         (region_model::get_dynamic_extents): New function.
7358         (region_model::get_dynamic_extents): New decl.
7359         (region_model::set_dynamic_extents): New decl.
7360         (region_model::unset_dynamic_extents): New decl.
7361         (region_model::get_capacity): New decl.
7362         (region_model::record_dynamic_extents): Rename to set_dynamic_extents.
7363         (region_model::m_dynamic_extents): New field.
7365 2021-06-15  David Malcolm  <dmalcolm@redhat.com>
7367         * region-model.cc (region_to_value_map::operator=): New.
7368         (region_to_value_map::operator==): New.
7369         (region_to_value_map::dump_to_pp): New.
7370         (region_to_value_map::dump): New.
7371         (region_to_value_map::can_merge_with_p): New.
7372         * region-model.h (class region_to_value_map): New class.
7374 2021-06-13  Trevor Saunders  <tbsaunde@tbsaunde.org>
7376         * call-string.cc (call_string::call_string): Use range based for
7377         to iterate over vec<>.
7378         (call_string::to_json): Likewise.
7379         (call_string::hash): Likewise.
7380         (call_string::calc_recursion_depth): Likewise.
7381         * checker-path.cc (checker_path::fixup_locations): Likewise.
7382         * constraint-manager.cc (equiv_class::equiv_class): Likewise.
7383         (equiv_class::to_json): Likewise.
7384         (equiv_class::hash): Likewise.
7385         (constraint_manager::to_json): Likewise.
7386         * engine.cc (impl_region_model_context::on_svalue_leak):
7387         Likewise.
7388         (on_liveness_change): Likewise.
7389         (impl_region_model_context::on_unknown_change): Likewise.
7390         * program-state.cc (sm_state_map::set_state): Likewise.
7391         * region-model.cc (test_canonicalization_4): Likewise.
7393 2021-06-11  David Malcolm  <dmalcolm@redhat.com>
7395         * engine.cc (worklist::key_t::cmp): Move sort by call_string to
7396         before SCC.
7398 2021-06-09  David Malcolm  <dmalcolm@redhat.com>
7400         * region-model.cc (region_model::get_lvalue_1): Make const.
7401         (region_model::get_lvalue): Likewise.
7402         (region_model::get_rvalue_1): Likewise.
7403         (region_model::get_rvalue): Likewise.
7404         (region_model::deref_rvalue): Likewise.
7405         (region_model::get_rvalue_for_bits): Likewise.
7406         * region-model.h (region_model::get_lvalue): Likewise.
7407         (region_model::get_rvalue): Likewise.
7408         (region_model::deref_rvalue): Likewise.
7409         (region_model::get_rvalue_for_bits): Likewise.
7410         (region_model::get_lvalue_1): Likewise.
7411         (region_model::get_rvalue_1): Likewise.
7413 2021-06-08  David Malcolm  <dmalcolm@redhat.com>
7415         PR analyzer/99212
7416         * region-model-manager.cc
7417         (region_model_manager::maybe_fold_binop): Add support for folding
7418         BIT_AND_EXPR of compound_svalue and a mask constant.
7419         * region-model.cc (region_model::get_rvalue_1): Implement
7420         BIT_FIELD_REF in terms of...
7421         (region_model::get_rvalue_for_bits): New function.
7422         * region-model.h (region_model::get_rvalue_for_bits): New decl.
7423         * store.cc (bit_range::from_mask): New function.
7424         (selftest::test_bit_range_intersects_p): New selftest.
7425         (selftest::assert_bit_range_from_mask_eq): New.
7426         (ASSERT_BIT_RANGE_FROM_MASK_EQ): New macro.
7427         (selftest::assert_no_bit_range_from_mask_eq): New.
7428         (ASSERT_NO_BIT_RANGE_FROM_MASK): New macro.
7429         (selftest::test_bit_range_from_mask): New selftest.
7430         (selftest::analyzer_store_cc_tests): Call the new selftests.
7431         * store.h (bit_range::intersects_p): New.
7432         (bit_range::from_mask): New decl.
7433         (concrete_binding::get_bit_range): New accessor.
7434         (store_manager::get_concrete_binding): New overload taking
7435         const bit_range &.
7437 2021-06-08  David Malcolm  <dmalcolm@redhat.com>
7439         * analyzer.h (int_size_in_bits): New decl.
7440         * region.cc (int_size_in_bits): New function.
7441         (region::get_bit_size): Reimplement in terms of the above.
7443 2021-06-08  David Malcolm  <dmalcolm@redhat.com>
7445         * store.cc (concrete_binding::dump_to_pp): Move bulk of
7446         implementation to...
7447         (bit_range::dump_to_pp): ...this new function.
7448         (bit_range::cmp): New.
7449         (concrete_binding::overlaps_p): Update for use of bit_range.
7450         (concrete_binding::cmp_ptr_ptr): Likewise.
7451         * store.h (struct bit_range): New.
7452         (class concrete_binding): Replace fields m_start_bit_offset and
7453         m_size_in_bits with new field m_bit_range.
7455 2021-06-08  David Malcolm  <dmalcolm@redhat.com>
7457         * svalue.h (conjured_svalue::iterator_t): Delete.
7459 2021-06-03  David Malcolm  <dmalcolm@redhat.com>
7461         * store.h (store::get_direct_binding): Remove unused decl.
7462         (store::get_default_binding): Likewise.
7464 2021-06-03  David Malcolm  <dmalcolm@redhat.com>
7466         * svalue.cc (poisoned_svalue::dump_to_pp): Dump type.
7467         (compound_svalue::dump_to_pp): Dump any type.
7469 2021-05-18  David Malcolm  <dmalcolm@redhat.com>
7471         PR analyzer/100615
7472         * sm-malloc.cc: Include "analyzer/function-set.h".
7473         (malloc_state_machine::on_stmt): Call unaffected_by_call_p and
7474         bail on the functions it recognizes.
7475         (malloc_state_machine::unaffected_by_call_p): New.
7477 2021-05-10  Martin Liska  <mliska@suse.cz>
7479         * sm-file.cc (is_file_using_fn_p): Use startswith
7480         function instead of strncmp.
7482 2021-05-10  Martin Liska  <mliska@suse.cz>
7484         * program-state.cc (program_state::operator=): Remove
7485         __cplusplus >= 201103.
7486         (program_state::program_state): Likewise.
7487         * program-state.h: Likewise.
7488         * region-model.h (class region_model): Remove dead code.
7490 2021-04-24  David Malcolm  <dmalcolm@redhat.com>
7492         PR analyzer/100244
7493         * sm-malloc.cc (free_of_non_heap::describe_state_change):
7494         Bulletproof against change.m_expr being NULL.
7496 2021-04-13  David Malcolm  <dmalcolm@redhat.com>
7498         PR analyzer/98599
7499         * supergraph.cc (saved_uids::make_uid_unique): New.
7500         (saved_uids::restore_uids): New.
7501         (supergraph::supergraph): Replace assignments to stmt->uid with
7502         calls to m_stmt_uids.make_uid_unique.
7503         (supergraph::~supergraph): New.
7504         * supergraph.h (class saved_uids): New.
7505         (supergraph::~supergraph): New decl.
7506         (supergraph::m_stmt_uids): New field.
7508 2021-04-10  David Malcolm  <dmalcolm@redhat.com>
7510         PR analyzer/100011
7511         * region-model.cc (region_model::on_assignment): Avoid NULL
7512         dereference if ctxt is NULL when assigning from a STRING_CST.
7514 2021-04-08  David Malcolm  <dmalcolm@redhat.com>
7516         PR analyzer/99042
7517         PR analyzer/99774
7518         * engine.cc
7519         (impl_region_model_context::impl_region_model_context): Add
7520         uncertainty param and use it to initialize m_uncertainty.
7521         (impl_region_model_context::get_uncertainty): New.
7522         (impl_sm_context::get_fndecl_for_call): Add NULL for new
7523         uncertainty param when constructing impl_region_model_context.
7524         (impl_sm_context::get_state): Likewise.
7525         (impl_sm_context::set_next_state): Likewise.
7526         (impl_sm_context::warn): Likewise.
7527         (exploded_node::on_stmt): Add uncertainty param
7528         and use it when constructing impl_region_model_context.
7529         (exploded_node::on_edge): Add uncertainty param and pass
7530         to on_edge call.
7531         (exploded_node::detect_leaks): Create uncertainty_t and pass to
7532         impl_region_model_context.
7533         (exploded_graph::get_or_create_node): Create uncertainty_t and
7534         pass to prune_for_point.
7535         (maybe_process_run_of_before_supernode_enodes): Create
7536         uncertainty_t and pass to impl_region_model_context.
7537         (exploded_graph::process_node): Create uncertainty_t instances and
7538         pass around as needed.
7539         * exploded-graph.h
7540         (impl_region_model_context::impl_region_model_context): Add
7541         uncertainty param.
7542         (impl_region_model_context::get_uncertainty): New decl.
7543         (impl_region_model_context::m_uncertainty): New field.
7544         (exploded_node::on_stmt): Add uncertainty param.
7545         (exploded_node::on_edge): Likewise.
7546         * program-state.cc (sm_state_map::on_liveness_change): Get
7547         uncertainty from context and use it to unset sm-state from
7548         svalues as appropriate.
7549         (program_state::on_edge): Add uncertainty param and use it when
7550         constructing impl_region_model_context.  Fix indentation.
7551         (program_state::prune_for_point): Add uncertainty param and use it
7552         when constructing impl_region_model_context.
7553         (program_state::detect_leaks): Get any uncertainty from ctxt and
7554         use it to get maybe-live svalues for dest_state, rather than
7555         definitely-live ones; use this when determining which svalues
7556         have leaked.
7557         (selftest::test_program_state_merging): Create uncertainty_t and
7558         pass to impl_region_model_context.
7559         * program-state.h (program_state::on_edge): Add uncertainty param.
7560         (program_state::prune_for_point): Likewise.
7561         * region-model-impl-calls.cc (call_details::get_uncertainty): New.
7562         (region_model::impl_call_memcpy): Pass uncertainty to
7563         mark_region_as_unknown call.
7564         (region_model::impl_call_memset): Likewise.
7565         (region_model::impl_call_strcpy): Likewise.
7566         * region-model-reachability.cc (reachable_regions::handle_sval):
7567         Also add sval to m_mutable_svals.
7568         * region-model.cc (region_model::on_assignment): Pass any
7569         uncertainty from ctxt to the store::set_value call.
7570         (region_model::handle_unrecognized_call): Get any uncertainty from
7571         ctxt and use it to record mutable svalues at the unknown call.
7572         (region_model::get_reachable_svalues): Add uncertainty param and
7573         use it to mark any maybe-bound svalues as being reachable.
7574         (region_model::set_value): Pass any uncertainty from ctxt to the
7575         store::set_value call.
7576         (region_model::mark_region_as_unknown): Add uncertainty param and
7577         pass it on to the store::mark_region_as_unknown call.
7578         (region_model::update_for_call_summary): Add uncertainty param and
7579         pass it on to the region_model::mark_region_as_unknown call.
7580         * region-model.h (call_details::get_uncertainty): New decl.
7581         (region_model::get_reachable_svalues): Add uncertainty param.
7582         (region_model::mark_region_as_unknown): Add uncertainty param.
7583         (region_model_context::get_uncertainty): New vfunc.
7584         (noop_region_model_context::get_uncertainty): New vfunc
7585         implementation.
7586         * store.cc (dump_svalue_set): New.
7587         (uncertainty_t::dump_to_pp): New.
7588         (uncertainty_t::dump): New.
7589         (binding_cluster::clobber_region): Pass NULL for uncertainty to
7590         remove_overlapping_bindings.
7591         (binding_cluster::mark_region_as_unknown): Add uncertainty param
7592         and pass it to remove_overlapping_bindings.
7593         (binding_cluster::remove_overlapping_bindings): Add uncertainty param.
7594         Use it to record any svalues that were in clobbered bindings.
7595         (store::set_value): Add uncertainty param.  Pass it to
7596         binding_cluster::mark_region_as_unknown when handling symbolic
7597         regions.
7598         (store::mark_region_as_unknown): Add uncertainty param and pass it
7599         to binding_cluster::mark_region_as_unknown.
7600         (store::remove_overlapping_bindings): Add uncertainty param and
7601         pass it to binding_cluster::remove_overlapping_bindings.
7602         * store.h (binding_cluster::mark_region_as_unknown): Add
7603         uncertainty param.
7604         (binding_cluster::remove_overlapping_bindings): Likewise.
7605         (store::set_value): Likewise.
7606         (store::mark_region_as_unknown): Likewise.
7608 2021-04-05  David Malcolm  <dmalcolm@redhat.com>
7610         PR analyzer/99906
7611         * analyzer.cc (maybe_reconstruct_from_def_stmt): Fix NULL
7612         dereference on calls with zero arguments.
7613         * sm-malloc.cc (malloc_state_machine::on_stmt): When handling
7614         __attribute__((nonnull)), only call get_diagnostic_tree if the
7615         result will be used.
7617 2021-04-05  David Malcolm  <dmalcolm@redhat.com>
7619         PR analyzer/99886
7620         * diagnostic-manager.cc
7621         (diagnostic_manager::prune_interproc_events): Use signed integers
7622         when subtracting one from path->num_events ().
7623         (diagnostic_manager::consolidate_conditions): Likewise.  Convert
7624         next_idx to a signed int.
7626 2021-04-01  David Malcolm  <dmalcolm@redhat.com>
7628         * diagnostic-manager.cc (diagnostic_manager::add_diagnostic): Make
7629         enode param non-constant, and call add_diagnostic on it.  Add
7630         enode index to log message.
7631         (diagnostic_manager::add_diagnostic): Make enode param
7632         non-constant.
7633         * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
7634         Likewise for both decls.
7635         * engine.cc
7636         (impl_region_model_context::impl_region_model_context): Likewise
7637         for enode_for_diag.
7638         (impl_sm_context::impl_sm_context): Likewise.
7639         (impl_sm_context::m_enode_for_diag): Likewise.
7640         (exploded_node::dump_dot): Don't pass the diagnostic manager
7641         to dump_saved_diagnostics.
7642         (exploded_node::dump_saved_diagnostics): Drop param.  Iterate
7643         directly through all saved diagnostics for the enode, rather
7644         than all saved diagnostics in the diagnostic_manager and
7645         filtering.
7646         (exploded_node::on_stmt): Make non-const.
7647         (exploded_node::on_edge): Likewise.
7648         (exploded_node::on_longjmp): Likewise.
7649         (exploded_node::detect_leaks): Likewise.
7650         (exploded_graph::get_or_create_node): Make enode_for_diag param
7651         non-const.
7652         (exploded_graph_annotator::print_enode): Iterate
7653         directly through all saved diagnostics for the enode, rather
7654         than all saved diagnostics in the diagnostic_manager and
7655         filtering.
7656         * exploded-graph.h
7657         (impl_region_model_context::impl_region_model_context): Make
7658         enode_for_diag param non-constant.
7659         (impl_region_model_context::m_enode_for_diag): Likewise.
7660         (exploded_node::dump_saved_diagnostics): Drop param.
7661         (exploded_node::on_stmt): Make non-const.
7662         (exploded_node::on_edge): Likewise.
7663         (exploded_node::on_longjmp): Likewise.
7664         (exploded_node::detect_leaks): Likewise.
7665         (exploded_node::add_diagnostic): New.
7666         (exploded_node::get_num_diagnostics): New.
7667         (exploded_node::get_saved_diagnostic): New.
7668         (exploded_node::m_saved_diagnostics): New.
7669         (exploded_graph::get_or_create_node): Make enode_for_diag param
7670         non-constant.
7671         * feasible-graph.cc (feasible_node::dump_dot): Drop
7672         diagnostic_manager from call to dump_saved_diagnostics.
7673         * program-state.cc (program_state::on_edge): Convert enode param
7674         to non-const pointer.
7675         (program_state::prune_for_point): Likewise for enode_for_diag
7676         param.
7677         * program-state.h (program_state::on_edge): Convert enode param
7678         to non-const pointer.
7679         (program_state::prune_for_point): Likewise for enode_for_diag
7680         param.
7682 2021-03-31  David Malcolm  <dmalcolm@redhat.com>
7684         PR analyzer/99771
7685         * analyzer.cc (maybe_reconstruct_from_def_stmt): New.
7686         (fixup_tree_for_diagnostic_1): New.
7687         (fixup_tree_for_diagnostic): New.
7688         * analyzer.h (fixup_tree_for_diagnostic): New decl.
7689         * checker-path.cc (call_event::get_desc): Call
7690         fixup_tree_for_diagnostic and use it for the call_with_state call.
7691         (warning_event::get_desc): Likewise for the final_event and
7692         make_label_text calls.
7693         * engine.cc (impl_region_model_context::on_state_leak): Likewise
7694         for the on_leak and add_diagnostic calls.
7695         * region-model.cc (region_model::get_representative_tree):
7696         Likewise for the result.
7698 2021-03-30  David Malcolm  <dmalcolm@redhat.com>
7700         * region.h (region::dump_to_pp): Remove old decl.
7702 2021-03-30  David Malcolm  <dmalcolm@redhat.com>
7704         * sm-file.cc (fileptr_state_machine::on_stmt): Only call
7705         get_diagnostic_tree if the result will be used.
7706         * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
7707         (malloc_state_machine::on_deallocator_call): Likewise.
7708         (malloc_state_machine::on_realloc_call): Likewise.
7709         (malloc_state_machine::on_realloc_call): Likewise.
7710         * sm-sensitive.cc
7711         (sensitive_state_machine::warn_for_any_exposure): Likewise.
7712         * sm-taint.cc (taint_state_machine::on_stmt): Likewise.
7714 2021-03-25  David Malcolm  <dmalcolm@redhat.com>
7716         PR analyzer/93695
7717         PR analyzer/99044
7718         PR analyzer/99716
7719         * engine.cc (exploded_node::on_stmt): Clear sm-state involving
7720         an SSA name at the def-stmt of that SSA name.
7721         * program-state.cc (sm_state_map::purge_state_involving): New.
7722         * program-state.h (sm_state_map::purge_state_involving): New decl.
7723         * region-model.cc (selftest::test_involves_p): New.
7724         (selftest::analyzer_region_model_cc_tests): Call it.
7725         * svalue.cc (class involvement_visitor): New class
7726         (svalue::involves_p): New.
7727         * svalue.h (svalue::involves_p): New decl.
7729 2021-03-19  David Malcolm  <dmalcolm@redhat.com>
7731         PR analyzer/99614
7732         * diagnostic-manager.cc (class epath_finder): Add
7733         DISABLE_COPY_AND_ASSIGN.
7735 2021-03-15  Martin Liska  <mliska@suse.cz>
7737         * sm-file.cc (get_file_using_fns): Add missing comma in initializer.
7739 2021-03-11  David Malcolm  <dmalcolm@redhat.com>
7741         PR analyzer/96374
7742         * analyzer.opt (-param=analyzer-max-infeasible-edges=): New param.
7743         (fdump-analyzer-feasibility): New flag.
7744         * diagnostic-manager.cc: Include "analyzer/trimmed-graph.h" and
7745         "analyzer/feasible-graph.h".
7746         (epath_finder::epath_finder): Convert m_sep to a pointer and
7747         only create it if !flag_analyzer_feasibility.
7748         (epath_finder::~epath_finder): New.
7749         (epath_finder::m_sep): Convert to a pointer.
7750         (epath_finder::get_best_epath): Add param "diag_idx" and use it
7751         when logging.  Rather than finding the shortest path and then
7752         checking feasibility, instead use explore_feasible_paths unless
7753         !flag_analyzer_feasibility, in which case simply use the shortest
7754         path, and note if it is infeasible.  Update for m_sep becoming a
7755         pointer.
7756         (class feasible_worklist): New.
7757         (epath_finder::explore_feasible_paths): New.
7758         (epath_finder::process_worklist_item): New.
7759         (class dump_eg_with_shortest_path): New.
7760         (epath_finder::dump_trimmed_graph): New.
7761         (epath_finder::dump_feasible_graph): New.
7762         (saved_diagnostic::saved_diagnostic): Add "idx" param, using it
7763         on new field m_idx.
7764         (saved_diagnostic::to_json): Dump m_idx.
7765         (saved_diagnostic::calc_best_epath): Pass m_idx to get_best_epath.
7766         Remove assertion that m_problem was set when m_best_epath is NULL.
7767         (diagnostic_manager::add_diagnostic): Pass an index when created
7768         saved_diagnostic instances.
7769         * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add
7770         "idx" param.
7771         (saved_diagnostic::get_index): New accessor.
7772         (saved_diagnostic::m_idx): New field.
7773         * engine.cc (exploded_node::dump_dot): Call args.dump_extra_info.
7774         Move code to...
7775         (exploded_node::dump_processed_stmts): ...this new function and...
7776         (exploded_node::dump_saved_diagnostics): ...this new function.
7777         Add index of each diagnostic.
7778         (exploded_edge::dump_dot):  Move bulk of code to...
7779         (exploded_edge::dump_dot_label): ...this new function.
7780         * exploded-graph.h (eg_traits::dump_args_t::dump_extra_info): New
7781         vfunc.
7782         (exploded_node::dump_processed_stmts): New decl.
7783         (exploded_node::dump_saved_diagnostics): New decl.
7784         (exploded_edge::dump_dot_label): New decl.
7785         * feasible-graph.cc: New file.
7786         * feasible-graph.h: New file.
7787         * trimmed-graph.cc: New file.
7788         * trimmed-graph.h: New file.
7790 2021-03-11  David Malcolm  <dmalcolm@redhat.com>
7792         * diagnostic-manager.cc (epath_finder::epath_finder):
7793         Update shortest_paths init for new param.
7795 2021-03-10  David Malcolm  <dmalcolm@redhat.com>
7797         PR analyzer/96374
7798         * engine.cc (exploded_path::feasible_p): Move "snodes_visited" and
7799         "model" locals into a new class feasibility_state.  Move heart
7800         of per-edge processing into
7801         feasibility_state::maybe_update_for_edge.
7802         (feasibility_state::feasibility_state): New.
7803         (feasibility_state::maybe_update_for_edge): New, based on loop
7804         body in exploded_path::feasible_p.
7805         * exploded-graph.h (class feasibility_state): New.
7807 2021-03-10  David Malcolm  <dmalcolm@redhat.com>
7809         * supergraph.h
7810         (callgraph_superedge::dyn_cast_callgraph_superedge): New.
7811         (call_superedge::dyn_cast_callgraph_superedge): Delete.
7812         (return_superedge::dyn_cast_callgraph_superedge): Delete.
7814 2021-03-02  Martin Liska  <mliska@suse.cz>
7816         * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostics):
7817         Do not pass engine.
7819 2021-02-26  David Malcolm  <dmalcolm@redhat.com>
7821         * engine.cc (exploded_path::exploded_path): New copy-ctor.
7822         * exploded-graph.h (exploded_path::operator=): Drop decl.
7824 2021-02-26  David Malcolm  <dmalcolm@redhat.com>
7826         PR analyzer/96374
7827         * diagnostic-manager.cc (class epath_finder): New.
7828         (epath_finder::get_best_epath): New.
7829         (saved_diagnostic::saved_diagnostic): Update for replacement of
7830         m_state and m_epath_length with m_best_epath.
7831         (saved_diagnostic::~saved_diagnostic): Delete m_best_epath.
7832         (saved_diagnostic::to_json): Update "path_length" to be optional.
7833         (saved_diagnostic::calc_best_epath): New, based on
7834         dedupe_winners::add and parts of dedupe_key::dedupe_key.
7835         (saved_diagnostic::get_epath_length): New.
7836         (saved_diagnostic::add_duplicate): New.
7837         (dedupe_key::dedupe_key): Drop epath param.  Move invocation of
7838         stmt_finder to saved_diagnostic::calc_best_epath.
7839         (class dedupe_candidate): Delete.
7840         (class dedupe_hash_map_traits): Update to use saved_diagnotic *
7841         rather than dedupe_candidate * as the value_type/compare_type.
7842         (dedupe_winners::~dedupe_winners): Don't delete the values.
7843         (dedupe_winners::add): Convert param from shortest_exploded_paths to
7844         epath_finder.  Drop "eg" param.  Drop dedupe_candidate, moving
7845         path generation and feasiblity checking to
7846         epath_finder::get_best_epath.  Update winner-selection for move
7847         of epaths from dedupe_candidate to saved_diagnostic.
7848         (dedupe_winners::emit_best):  Update for removal of class
7849         dedupe_candidate.
7850         (dedupe_winners::map_t): Update to use saved_diagnotic * rather
7851         than dedupe_candidate * as the value_type/compare_type.
7852         (diagnostic_manager::emit_saved_diagnostics): Move
7853         shortest_exploded_paths instance into epath_finder and pass that
7854         around instead.
7855         (diagnostic_manager::emit_saved_diagnostic): Drop epath, stmt
7856         and num_dupes params, instead getting these from the
7857         saved_diagnostic.  Use correct location in inform_n call.
7858         * diagnostic-manager.h (class epath_finder): New forward decl.
7859         (saved_diagnostic::status): Drop enum.
7860         (saved_diagnostic::set_feasible): Drop.
7861         (saved_diagnostic::set_infeasible): Drop.
7862         (saved_diagnostic::get_status): Drop.
7863         (saved_diagnostic::calc_best_epath): New decl.
7864         (saved_diagnostic::get_best_epath): New decl.
7865         (saved_diagnostic::get_epath_length): New decl.
7866         (saved_diagnostic::set_epath_length): Drop.
7867         (saved_diagnostic::get_epath_length): Drop inline implementation.
7868         (saved_diagnostic::add_duplicate): New.
7869         (saved_diagnostic::get_num_dupes): New.
7870         (saved_diagnostic::m_d): Document ownership.
7871         (saved_diagnostic::m_trailing_eedge): Make const.
7872         (saved_diagnostic::m_status): Drop field.
7873         (saved_diagnostic::m_epath_length): Drop field.
7874         (saved_diagnostic::m_best_epath): New field.
7875         (saved_diagnostic::m_problem): Document ownership.
7876         (saved_diagnostic::m_duplicates): New field.
7877         (diagnostic_manager::emit_saved_diagnostic): Drop params epath,
7878         stmt, and num_dupes.
7879         * engine.cc (exploded_graph_annotator::print_saved_diagnostic):
7880         Update for changes to saved_diagnostic class.
7881         * exploded-graph.h (exploded_path::feasible_p): Drop unused
7882         overloaded decl.
7884 2021-02-25  David Malcolm  <dmalcolm@redhat.com>
7886         PR analyzer/99193
7887         * region-model-impl-calls.cc (region_model::impl_call_realloc): New.
7888         * region-model.cc (region_model::on_call_pre): Call it.
7889         * region-model.h (region_model::impl_call_realloc): New decl.
7890         * sm-malloc.cc (enum wording): Add WORDING_REALLOCATED.
7891         (malloc_state_machine::m_realloc): New field.
7892         (use_after_free::describe_state_change): Add case for
7893         WORDING_REALLOCATED.
7894         (use_after_free::describe_final_event): Likewise.
7895         (malloc_state_machine::malloc_state_machine): Initialize
7896         m_realloc.
7897         (malloc_state_machine::on_stmt): Handle realloc by calling...
7898         (malloc_state_machine::on_realloc_call): New.
7900 2021-02-22  David Malcolm  <dmalcolm@redhat.com>
7902         PR analyzer/99196
7903         * engine.cc (exploded_node::on_stmt): Provide terminate_path
7904         flag as a way for on_call_pre to terminate the current analysis
7905         path.
7906         * region-model-impl-calls.cc (call_details::num_args): New.
7907         (region_model::impl_call_error): New.
7908         * region-model.cc (region_model::on_call_pre): Add param
7909         "out_terminate_path".  Handle "error" and "error_at_line".
7910         * region-model.h (call_details::num_args): New decl.
7911         (region_model::on_call_pre): Add param "out_terminate_path".
7912         (region_model::impl_call_error): New decl.
7914 2021-02-17  David Malcolm  <dmalcolm@redhat.com>
7916         PR analyzer/98969
7917         * constraint-manager.cc (dead_svalue_purger::should_purge_p):
7918         Update for change to svalue::live_p.
7919         * program-state.cc (sm_state_map::on_liveness_change): Likewise.
7920         (program_state::detect_leaks): Likewise.
7921         * region-model-reachability.cc (reachable_regions::init_cluster):
7922         When dealing with a symbolic region, if the underlying pointer is
7923         implicitly live, add the region to the reachable regions.
7924         * region-model.cc (region_model::compare_initial_and_pointer):
7925         Move logic for detecting initial values of params to
7926         initial_svalue::initial_value_of_param_p.
7927         * svalue.cc (svalue::live_p): Convert "live_svalues" from a
7928         reference to a pointer; support it being NULL.
7929         (svalue::implicitly_live_p): Convert first param from a
7930         refererence to a pointer.
7931         (region_svalue::implicitly_live_p): Likewise.
7932         (constant_svalue::implicitly_live_p): Likewise.
7933         (initial_svalue::implicitly_live_p): Likewise.  Treat the initial
7934         values of params for the top level frame as still live.
7935         (initial_svalue::initial_value_of_param_p): New function, taken
7936         from a test in region_model::compare_initial_and_pointer.
7937         (unaryop_svalue::implicitly_live_p): Convert first param from a
7938         refererence to a pointer.
7939         (binop_svalue::implicitly_live_p): Likewise.
7940         (sub_svalue::implicitly_live_p): Likewise.
7941         (unmergeable_svalue::implicitly_live_p): Likewise.
7942         * svalue.h (svalue::live_p): Likewise.
7943         (svalue::implicitly_live_p): Likewise.
7944         (region_svalue::implicitly_live_p): Likewise.
7945         (constant_svalue::implicitly_live_p): Likewise.
7946         (initial_svalue::implicitly_live_p): Likewise.
7947         (initial_svalue::initial_value_of_param_p): New decl.
7948         (unaryop_svalue::implicitly_live_p): Convert first param from a
7949         refererence to a pointer.
7950         (binop_svalue::implicitly_live_p): Likewise.
7951         (sub_svalue::implicitly_live_p): Likewise.
7952         (unmergeable_svalue::implicitly_live_p): Likewise.
7954 2021-02-12  David Malcolm  <dmalcolm@redhat.com>
7956         PR analyzer/98969
7957         * engine.cc (readability): Add names for the various arbitrary
7958         values.  Handle NOP_EXPR and INTEGER_CST.
7959         (readability_comparator): Combine the readability tests for
7960         tree and stack depth, rather than performing them sequentially.
7961         (impl_region_model_context::on_state_leak): Strip off top-level
7962         casts.
7963         * region-model.cc (region_model::get_representative_path_var): Add
7964         type-checking, moving the bulk of the implementation to...
7965         (region_model::get_representative_path_var_1): ...here.  Respect
7966         types in casts by recursing and re-adding the cast, rather than
7967         merely stripping them off.  Use the correct type when handling
7968         region_svalue.
7969         (region_model::get_representative_tree): Strip off any top-level
7970         cast.
7971         (region_model::get_representative_path_var): Add type-checking,
7972         moving the bulk of the implementation to...
7973         (region_model::get_representative_path_var_1): ...here.
7974         * region-model.h (region_model::get_representative_path_var_1):
7975         New decl
7976         (region_model::get_representative_path_var_1): New decl.
7977         * store.cc (append_pathvar_with_type): New.
7978         (binding_cluster::get_representative_path_vars): Cast path_vars
7979         to the correct type when adding them to *OUT_PVS.
7981 2021-02-09  David Malcolm  <dmalcolm@redhat.com>
7983         PR analyzer/98575
7984         * sm-file.cc (is_file_using_fn_p): Support "_IO_"-prefixed
7985         variants.
7987 2021-02-09  David Malcolm  <dmalcolm@redhat.com>
7989         PR analyzer/98575
7990         * store.cc (store::set_value): Treat a pointer written to *UNKNOWN
7991         as having escaped.
7993 2021-02-02  David Malcolm  <dmalcolm@redhat.com>
7995         PR analyzer/93355
7996         PR analyzer/96374
7997         * engine.cc (toplevel_function_p): Simplify so that
7998         we only reject functions with a "__analyzer_" prefix.
7999         (add_any_callbacks): Delete.
8000         (exploded_graph::build_initial_worklist): Update for
8001         dropped param of toplevel_function_p.
8002         (exploded_graph::build_initial_worklist): Don't bother
8003         looking for callbacks that are reachable from global
8004         initializers.
8006 2021-02-01  David Malcolm  <dmalcolm@redhat.com>
8008         PR analyzer/98918
8009         * region-model-manager.cc
8010         (region_model_manager::get_or_create_initial_value):
8011         Fold the initial value of *UNKNOWN_PTR to an UNKNOWN value.
8012         (region_model_manager::get_field_region): Fold the value
8013         of UNKNOWN_PTR->FIELD to *UNKNOWN_PTR_OF_&FIELD_TYPE.
8015 2021-01-29  David Malcolm  <dmalcolm@redhat.com>
8017         * checker-path.cc (event_kind_to_string): Handle
8018         EK_START_CONSOLIDATED_CFG_EDGES and
8019         EK_END_CONSOLIDATED_CFG_EDGES.
8020         (start_consolidated_cfg_edges_event::get_desc): New.
8021         (checker_path::cfg_edge_pair_at_p): New.
8022         * checker-path.h (enum event_kind): Add
8023         EK_START_CONSOLIDATED_CFG_EDGES and
8024         EK_END_CONSOLIDATED_CFG_EDGES.
8025         (class start_consolidated_cfg_edges_event): New class.
8026         (class end_consolidated_cfg_edges_event): New class.
8027         (checker_path::delete_events): New.
8028         (checker_path::replace_event): New.
8029         (checker_path::cfg_edge_pair_at_p): New decl.
8030         * diagnostic-manager.cc (diagnostic_manager::prune_path): Call
8031         consolidate_conditions.
8032         (same_line_as_p): New.
8033         (diagnostic_manager::consolidate_conditions): New.
8034         * diagnostic-manager.h
8035         (diagnostic_manager::consolidate_conditions): New decl.
8037 2021-01-18  David Malcolm  <dmalcolm@redhat.com>
8039         * analyzer.h (is_std_named_call_p): New decl.
8040         * diagnostic-manager.cc (path_builder::get_sm): New.
8041         (state_change_event_creator::state_change_event_creator): Add "pb"
8042         param.
8043         (state_change_event_creator::on_global_state_change): Don't consider
8044         state changes affecting other state_machines.
8045         (state_change_event_creator::on_state_change): Likewise.
8046         (state_change_event_creator::m_pb): New field.
8047         (diagnostic_manager::add_events_for_eedge): Pass pb to visitor
8048         ctor.
8049         * region-model-impl-calls.cc
8050         (region_model::impl_deallocation_call): New.
8051         * region-model.cc: Include "attribs.h".
8052         (region_model::on_call_post): Handle fndecls referenced by
8053         __attribute__((deallocated_by(FOO))).
8054         * region-model.h (region_model::impl_deallocation_call): New decl.
8055         * sm-malloc.cc: Include "stringpool.h" and "attribs.h".  Add
8056         leading comment.
8057         (class api): Delete.
8058         (enum resource_state): Update comment for change from api to
8059         deallocator and deallocator_set.
8060         (allocation_state::allocation_state): Drop api param.  Add
8061         "deallocators" and "deallocator".
8062         (allocation_state::m_api): Drop field in favor of...
8063         (allocation_state::m_deallocators): New field.
8064         (allocation_state::m_deallocator): New field.
8065         (enum wording): Add WORDING_DEALLOCATED.
8066         (struct deallocator): New.
8067         (struct standard_deallocator): New.
8068         (struct custom_deallocator): New.
8069         (struct deallocator_set): New.
8070         (struct custom_deallocator_set): New.
8071         (struct standard_deallocator_set): New.
8072         (struct deallocator_set_map_traits): New.
8073         (malloc_state_machine::m_malloc): Drop field
8074         (malloc_state_machine::m_scalar_new): Likewise.
8075         (malloc_state_machine::m_vector_new): Likewise.
8076         (malloc_state_machine::m_free): New field
8077         (malloc_state_machine::m_scalar_delete): Likewise.
8078         (malloc_state_machine::m_vector_delete): Likewise.
8079         (malloc_state_machine::deallocator_map_t): New typedef.
8080         (malloc_state_machine::m_deallocator_map): New field.
8081         (malloc_state_machine::deallocator_set_cache_t): New typedef.
8082         (malloc_state_machine::m_custom_deallocator_set_cache): New field.
8083         (malloc_state_machine::custom_deallocator_set_map_t): New typedef.
8084         (malloc_state_machine::m_custom_deallocator_set_map): New field.
8085         (malloc_state_machine::m_dynamic_sets): New field.
8086         (malloc_state_machine::m_dynamic_deallocators): New field.
8087         (api::api): Delete.
8088         (deallocator::deallocator): New ctor.
8089         (deallocator::hash): New.
8090         (deallocator::dump_to_pp): New.
8091         (deallocator::cmp): New.
8092         (deallocator::cmp_ptr_ptr): New.
8093         (standard_deallocator::standard_deallocator): New ctor.
8094         (deallocator_set::deallocator_set): New ctor.
8095         (deallocator_set::dump): New.
8096         (custom_deallocator_set::custom_deallocator_set): New ctor.
8097         (custom_deallocator_set::contains_p): New.
8098         (custom_deallocator_set::maybe_get_single): New.
8099         (custom_deallocator_set::dump_to_pp): New.
8100         (standard_deallocator_set::standard_deallocator_set): New ctor.
8101         (standard_deallocator_set::contains_p): New.
8102         (standard_deallocator_set::maybe_get_single): New.
8103         (standard_deallocator_set::dump_to_pp): New.
8104         (start_p): New.
8105         (class mismatching_deallocation): Update for conversion from api
8106         to deallocator_set and deallocator.
8107         (double_free::emit): Use %qs.
8108         (class use_after_free): Update for conversion from api to
8109         deallocator_set and deallocator.
8110         (malloc_leak::describe_state_change): Only emit "allocated here" on
8111         a start->nonnull transition, rather than on other transitions to
8112         nonnull.
8113         (allocation_state::dump_to_pp): Update for conversion from api to
8114         deallocator_set.
8115         (allocation_state::get_nonnull): Likewise.
8116         (malloc_state_machine::malloc_state_machine): Likewise.
8117         (malloc_state_machine::~malloc_state_machine): New.
8118         (malloc_state_machine::add_state): Update for conversion from api
8119         to deallocator_set.
8120         (malloc_state_machine::get_or_create_custom_deallocator_set): New.
8121         (malloc_state_machine::maybe_create_custom_deallocator_set): New.
8122         (malloc_state_machine::get_or_create_deallocator): New.
8123         (malloc_state_machine::on_stmt): Update for conversion from api
8124         to deallocator_set.  Handle "__attribute__((malloc(FOO)))", and
8125         the special attribute set on FOO.
8126         (malloc_state_machine::on_allocator_call): Update for conversion
8127         from api to deallocator_set.  Add "returns_nonnull" param and use
8128         it to affect which state to transition to.
8129         (malloc_state_machine::on_deallocator_call): Update for conversion
8130         from api to deallocator_set.
8132 2021-01-14  David Malcolm  <dmalcolm@redhat.com>
8134         * engine.cc (strongly_connected_components::to_json): New.
8135         (worklist::to_json): New.
8136         (exploded_graph::to_json): JSON-ify the worklist.
8137         * exploded-graph.h (strongly_connected_components::to_json): New
8138         decl.
8139         (worklist::to_json): New decl.
8140         * store.cc (store::to_json): Fix comment.
8141         * supergraph.cc (supernode::to_json): Fix reference to
8142         "returning_call" in comment.  Add optional "fun" to JSON.
8143         (edge_kind_to_string): New.
8144         (superedge::to_json): Add "kind" to JSON.
8146 2021-01-14  David Malcolm  <dmalcolm@redhat.com>
8148         PR analyzer/98679
8149         * analyzer.h (region_offset::operator==): Make const.
8150         * pending-diagnostic.h (pending_diagnostic::equal_p): Likewise.
8151         * store.h (binding_cluster::for_each_value): Likewise.
8152         (binding_cluster::for_each_binding): Likewise.
8154 2021-01-12  David Malcolm  <dmalcolm@redhat.com>
8156         PR analyzer/98628
8157         * store.cc (binding_cluster::make_unknown_relative_to): Don't mark
8158         dereferenced unknown pointers as having escaped.
8160 2021-01-07  David Malcolm  <dmalcolm@redhat.com>
8162         PR analyzer/98580
8163         * region.cc (decl_region::get_svalue_for_initializer): Gracefully
8164         handle when LTO writes out DECL_INITIAL as error_mark_node.
8166 2021-01-07  David Malcolm  <dmalcolm@redhat.com>
8168         PR analyzer/97074
8169         * store.cc (binding_cluster::can_merge_p): Add "out_store" param
8170         and pass to calls to binding_cluster::make_unknown_relative_to.
8171         (binding_cluster::make_unknown_relative_to): Add "out_store"
8172         param.  Use it to mark base regions that are pointed to by
8173         pointers that become unknown as having escaped.
8174         (store::can_merge_p): Pass out_store to
8175         binding_cluster::can_merge_p.
8176         * store.h (binding_cluster::can_merge_p): Add "out_store" param.
8177         (binding_cluster::make_unknown_relative_to): Likewise.
8178         * svalue.cc (region_svalue::implicitly_live_p): New vfunc.
8179         * svalue.h (region_svalue::implicitly_live_p): New vfunc decl.
8181 2021-01-07  David Malcolm  <dmalcolm@redhat.com>
8183         PR analyzer/98564
8184         * engine.cc (exploded_path::feasible_p): Add missing call to
8185         bitmap_clear.
8187 2021-01-06  David Malcolm  <dmalcolm@redhat.com>
8189         PR analyzer/97072
8190         * region-model-reachability.cc (reachable_regions::init_cluster):
8191         Convert symbolic region handling to a switch statement.  Add cases
8192         to handle SK_UNKNOWN and SK_CONJURED.
8194 2021-01-05  David Malcolm  <dmalcolm@redhat.com>
8196         PR analyzer/98293
8197         * store.cc (binding_map::apply_ctor_to_region): When "index" is
8198         NULL, iterate through the fields for RECORD_TYPEs, rather than
8199         creating an INTEGER_CST index.
8201 2020-11-30  David Malcolm  <dmalcolm@redhat.com>
8203         * analyzer-pass.cc: Include "analyzer/analyzer.h" for the
8204         declaration of sorry_no_analyzer; include "tree.h" and
8205         "function.h" as these are needed by it.
8207 2020-11-30  David Malcolm  <dmalcolm@redhat.com>
8209         * analyzer-pass.cc (pass_analyzer::execute): Move sorry call to...
8210         (sorry_no_analyzer): New.
8211         * analyzer.h (class state_machine): New forward decl.
8212         (class logger): New forward decl.
8213         (class plugin_analyzer_init_iface): New.
8214         (sorry_no_analyzer): New decl.
8215         * checker-path.cc (checker_path::fixup_locations): New.
8216         * checker-path.h (checker_event::set_location): New.
8217         (checker_path::fixup_locations): New decl.
8218         * diagnostic-manager.cc
8219         (diagnostic_manager::emit_saved_diagnostic): Call
8220         checker_path::fixup_locations, and call fixup_location
8221         on the primary location.
8222         * engine.cc: Include "plugin.h".
8223         (class plugin_analyzer_init_impl): New.
8224         (impl_run_checkers): Invoke PLUGIN_ANALYZER_INIT callbacks.
8225         * pending-diagnostic.h (pending_diagnostic::fixup_location): New
8226         vfunc.
8228 2020-11-18  David Malcolm  <dmalcolm@redhat.com>
8230         PR analyzer/97893
8231         * sm-malloc.cc (null_deref::emit): Use CWE-476 rather than
8232         CWE-690, as this isn't due to an unchecked return value.
8233         (null_arg::emit): Likewise.
8235 2020-11-12  David Malcolm  <dmalcolm@redhat.com>
8237         * checker-path.h (checker_event::get_id_ptr): New.
8238         * diagnostic-manager.cc (path_builder::path_builder): Add "sd"
8239         param and use it to initialize new field "m_sd".
8240         (path_builder::get_pending_diagnostic): New.
8241         (path_builder::m_sd): New field.
8242         (diagnostic_manager::emit_saved_diagnostic): Pass sd to
8243         path_builder ctor.
8244         (diagnostic_manager::add_events_for_superedge): Call new
8245         maybe_add_custom_events_for_superedge vfunc.
8246         * engine.cc (stale_jmp_buf::stale_jmp_buf): Add "setjmp_point"
8247         param and use it to initialize new field "m_setjmp_point".
8248         Initialize new field "m_stack_pop_event".
8249         (stale_jmp_buf::maybe_add_custom_events_for_superedge): New vfunc
8250         implementation.
8251         (stale_jmp_buf::describe_final_event): New vfunc implementation.
8252         (stale_jmp_buf::m_setjmp_point): New field.
8253         (stale_jmp_buf::m_stack_pop_event): New field.
8254         (exploded_node::on_longjmp): Pass setjmp_point to stale_jmp_buf
8255         ctor.
8256         * pending-diagnostic.h
8257         (pending_diagnostic::maybe_add_custom_events_for_superedge): New
8258         vfunc.
8260 2020-11-12  David Malcolm  <dmalcolm@redhat.com>
8262         PR tree-optimization/97424
8263         * analyzer.opt (Wanalyzer-shift-count-negative): New.
8264         (Wanalyzer-shift-count-overflow): New.
8265         * region-model.cc (class shift_count_negative_diagnostic): New.
8266         (class shift_count_overflow_diagnostic): New.
8267         (region_model::get_gassign_result): Complain about shift counts that
8268         are negative or are >= the operand's type's width.
8270 2020-11-10  Martin Liska  <mliska@suse.cz>
8272         * constraint-manager.cc (constraint_manager::merge): Remove
8273         unused code.
8274         * constraint-manager.h: Likewise.
8275         * program-state.cc (sm_state_map::sm_state_map): Likewise.
8276         (program_state::program_state): Likewise.
8277         (test_sm_state_map): Likewise.
8278         * program-state.h: Likewise.
8279         * region-model-reachability.cc (reachable_regions::reachable_regions): Likewise.
8280         * region-model-reachability.h: Likewise.
8281         * region-model.cc (region_model::handle_unrecognized_call): Likewise.
8282         (region_model::get_reachable_svalues): Likewise.
8283         (region_model::can_merge_with_p): Likewise.
8285 2020-11-05  David Malcolm  <dmalcolm@redhat.com>
8287         PR analyzer/97668
8288         * svalue.cc (cmp_cst): Handle COMPLEX_CST.
8290 2020-10-29  David Malcolm  <dmalcolm@redhat.com>
8292         * program-state.cc (sm_state_map::on_liveness_change): Sort the
8293         leaking svalues before calling on_state_leak.
8294         (program_state::detect_leaks): Likewise when calling
8295         on_svalue_leak.
8296         * region-model-reachability.cc
8297         (reachable_regions::mark_escaped_clusters): Likewise when
8298         calling on_escaped_function.
8300 2020-10-29  David Malcolm  <dmalcolm@redhat.com>
8302         PR analyzer/97608
8303         * region-model-reachability.cc (reachable_regions::handle_sval):
8304         Operands of reachable reversible operations are reachable.
8306 2020-10-29  David Malcolm  <dmalcolm@redhat.com>
8308         * analyzer.h (class state_machine): New forward decl.
8309         (class logger): Likewise.
8310         (class visitor): Likewise.
8311         * complexity.cc: New file, taken from svalue.cc.
8312         * complexity.h: New file, taken from region-model.h.
8313         * region-model.h: Include "analyzer/svalue.h" and
8314         "analyzer/region.h".  Move struct complexity to complexity.h.
8315         Move svalue, its subclasses and supporting decls to svalue.h.
8316         Move region, its subclasses and supporting decls to region.h.
8317         * region.cc: Include "analyzer/region.h".
8318         (symbolic_region::symbolic_region): Move here from region-model.h.
8319         * region.h: New file, based on material from region-model.h.
8320         * svalue.cc: Include "analyzer/svalue.h".
8321         (complexity::complexity): Move to complexity.cc.
8322         (complexity::from_pair): Likewise.
8323         * svalue.h: New file, based on material from region-model.h.
8325 2020-10-29  David Malcolm  <dmalcolm@redhat.com>
8327         * program-state.cc (sm_state_map::print): Guard the printing of
8328         the origin pointer with !flag_dump_noaddr.
8329         * region.cc (string_region::dump_to_pp): Likewise for
8330         m_string_cst.
8332 2020-10-27  David Malcolm  <dmalcolm@redhat.com>
8334         PR analyzer/97568
8335         * region-model.cc (region_model::get_initial_value_for_global):
8336         Move check that !DECL_EXTERNAL from here to...
8337         * region.cc (decl_region::get_svalue_for_initializer): ...here,
8338         using it to reject zero initialization.
8340 2020-10-27  Markus Böck  <markus.boeck02@gmail.com>
8342         PR analyzer/96608
8343         * store.h (hash): Cast to intptr_t instead of long
8345 2020-10-27  David Malcolm  <dmalcolm@redhat.com>
8347         * constraint-manager.cc (svalue_cmp_by_ptr): Delete.
8348         (equiv_class::canonicalize): Use svalue::cmp_ptr_ptr instead.
8349         (equiv_class_cmp): Eliminate pointer comparison.
8350         * diagnostic-manager.cc (dedupe_key::comparator): If they are at
8351         the same location, also compare epath ength and pending_diagnostic
8352         kind.
8353         * engine.cc (readability_comparator): If two path_vars have the
8354         same readability, then impose an arbitrary ordering on them.
8355         (worklist::key_t::cmp): If two points have the same plan ordering,
8356         continue the comparison.  Call sm_state_map::cmp rather than
8357         comparing hash values.
8358         * program-state.cc (sm_state_map::entry_t::cmp): New.
8359         (sm_state_map::cmp): New.
8360         * program-state.h (sm_state_map::entry_t::cmp): New decl.
8361         (sm_state_map::elements): New.
8362         (sm_state_map::cmp): New.
8364 2020-10-27  David Malcolm  <dmalcolm@redhat.com>
8366         * engine.cc (setjmp_record::cmp): New.
8367         (supernode_cluster::dump_dot): Avoid embedding pointer in cluster
8368         name.
8369         (supernode_cluster::cmp_ptr_ptr): New.
8370         (function_call_string_cluster::dump_dot): Avoid embedding pointer
8371         in cluster name.  Sort m_map when dumping child clusters.
8372         (function_call_string_cluster::cmp_ptr_ptr): New.
8373         (root_cluster::dump_dot): Sort m_map when dumping child clusters.
8374         * program-point.cc (function_point::cmp): New.
8375         (function_point::cmp_ptr): New.
8376         * program-point.h (function_point::cmp): New decl.
8377         (function_point::cmp_ptr): New decl.
8378         * program-state.cc (sm_state_map::print): Sort the values.  Guard
8379         the printing of pointers with !flag_dump_noaddr.
8380         (program_state::prune_for_point): Sort the regions.
8381         (log_set_of_svalues): Sort the values.  Guard the printing of
8382         pointers with !flag_dump_noaddr.
8383         * region-model-manager.cc (log_uniq_map): Sort the values.
8384         * region-model-reachability.cc (dump_set): New function template.
8385         (reachable_regions::dump_to_pp): Use it.
8386         * region-model.h (svalue::cmp_ptr): New decl.
8387         (svalue::cmp_ptr_ptr): New decl.
8388         (setjmp_record::cmp): New decl.
8389         (placeholder_svalue::get_name): New accessor.
8390         (widening_svalue::get_point): New accessor.
8391         (compound_svalue::get_map): New accessor.
8392         (conjured_svalue::get_stmt): New accessor.
8393         (conjured_svalue::get_id_region): New accessor.
8394         (region::cmp_ptrs): Rename to...
8395         (region::cmp_ptr_ptr): ...this.
8396         * region.cc (region::cmp_ptrs): Rename to...
8397         (region::cmp_ptr_ptr): ...this.
8398         * state-purge.cc
8399         (state_purge_per_ssa_name::state_purge_per_ssa_name): Sort
8400         m_points_needing_name when dumping.
8401         * store.cc (concrete_binding::cmp_ptr_ptr): New.
8402         (symbolic_binding::cmp_ptr_ptr): New.
8403         (binding_map::cmp): New.
8404         (get_sorted_parent_regions): Update for renaming of
8405         region::cmp_ptrs to region::cmp_ptr_ptr.
8406         (store::dump_to_pp): Likewise.
8407         (store::to_json): Likewise.
8408         (store::can_merge_p): Sort the base regions before considering
8409         them.
8410         * store.h (concrete_binding::cmp_ptr_ptr): New decl.
8411         (symbolic_binding::cmp_ptr_ptr): New decl.
8412         (binding_map::cmp): New decl.
8413         * supergraph.cc (supergraph::supergraph): Assign UIDs to the
8414         gimple stmts.
8415         * svalue.cc (cmp_cst): New.
8416         (svalue::cmp_ptr): New.
8417         (svalue::cmp_ptr_ptr): New.
8419 2020-10-27  David Malcolm  <dmalcolm@redhat.com>
8421         * engine.cc (exploded_graph::get_or_create_node): Fix off-by-one
8422         when imposing param_analyzer_max_enodes_per_program_point limit.
8424 2020-10-27  David Malcolm  <dmalcolm@redhat.com>
8426         * region-model.cc (region_model::get_representative_path_var):
8427         Implement case RK_LABEL.
8428         * region-model.h (label_region::get_label): New accessor.
8430 2020-10-22  David Malcolm  <dmalcolm@redhat.com>
8432         PR analyzer/97514
8433         * engine.cc (exploded_graph::add_function_entry): Handle failure
8434         to create an enode, rather than asserting.
8436 2020-10-22  David Malcolm  <dmalcolm@redhat.com>
8438         PR analyzer/97489
8439         * engine.cc (exploded_graph::add_function_entry): Assert that we
8440         have a function body.
8441         (exploded_graph::on_escaped_function): Reject fndecls that don't
8442         have a function body.
8444 2020-10-14  David Malcolm  <dmalcolm@redhat.com>
8446         PR analyzer/93388
8447         * region-model.cc (region_model::get_initial_value_for_global):
8448         Fall back to returning an initial_svalue if
8449         decl_region::get_svalue_for_initializer fails.
8450         * region.cc (decl_region::get_svalue_for_initializer): Don't
8451         attempt to create a compound_svalue if the region has an unknown
8452         size.
8454 2020-10-14  David Malcolm  <dmalcolm@redhat.com>
8456         PR analyzer/93723
8457         * store.cc (binding_map::apply_ctor_to_region): Remove redundant
8458         assertion.
8460 2020-10-12  David Malcolm  <dmalcolm@redhat.com>
8462         PR analyzer/97258
8463         * engine.cc (impl_region_model_context::on_escaped_function): New
8464         vfunc.
8465         (exploded_graph::add_function_entry): Use m_functions_with_enodes
8466         to implement idempotency.
8467         (add_any_callbacks): New.
8468         (exploded_graph::build_initial_worklist): Use the above to find
8469         callbacks that are reachable from global initializers.
8470         (exploded_graph::on_escaped_function): New.
8471         * exploded-graph.h
8472         (impl_region_model_context::on_escaped_function): New decl.
8473         (exploded_graph::on_escaped_function): New decl.
8474         (exploded_graph::m_functions_with_enodes): New field.
8475         * region-model-reachability.cc
8476         (reachable_regions::reachable_regions): Replace "store" param with
8477         "model" param; use it to initialize m_model.
8478         (reachable_regions::add): When getting the svalue for the region,
8479         call get_store_value on the model rather than using an initial
8480         value.
8481         (reachable_regions::mark_escaped_clusters): Add ctxt param and
8482         use it to call on_escaped_function when a function_region escapes.
8483         * region-model-reachability.h
8484         (reachable_regions::reachable_regions): Replace "store" param with
8485         "model" param.
8486         (reachable_regions::mark_escaped_clusters): Add ctxt param.
8487         (reachable_regions::m_model): New field.
8488         * region-model.cc (region_model::handle_unrecognized_call): Update
8489         for change in reachable_regions ctor.
8490         (region_model::handle_unrecognized_call): Pass ctxt to
8491         mark_escaped_clusters.
8492         (region_model::get_reachable_svalues): Update for change in
8493         reachable_regions ctor.
8494         (region_model::get_initial_value_for_global): Read-only variables
8495         keep their initial values.
8496         * region-model.h (region_model_context::on_escaped_function): New
8497         vfunc.
8498         (noop_region_model_context::on_escaped_function): New.
8500 2020-10-12  David Malcolm  <dmalcolm@redhat.com>
8502         * analyzer.opt (Wanalyzer-write-to-const): New.
8503         (Wanalyzer-write-to-string-literal): New.
8504         * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8505         Call check_for_writable_region.
8506         (region_model::impl_call_memset): Likewise.
8507         (region_model::impl_call_strcpy): Likewise.
8508         * region-model.cc (class write_to_const_diagnostic): New.
8509         (class write_to_string_literal_diagnostic): New.
8510         (region_model::check_for_writable_region): New.
8511         (region_model::set_value): Call check_for_writable_region.
8512         * region-model.h (region_model::check_for_writable_region): New
8513         decl.
8515 2020-10-07  David Malcolm  <dmalcolm@redhat.com>
8517         PR analyzer/97116
8518         * sm-malloc.cc (method_p): New.
8519         (describe_argument_index): New.
8520         (inform_nonnull_attribute): Use describe_argument_index.
8521         (possible_null_arg::describe_final_event): Likewise.
8522         (null_arg::describe_final_event): Likewise.
8524 2020-09-29  David Malcolm  <dmalcolm@redhat.com>
8526         PR analyzer/95188
8527         * engine.cc (stmt_requires_new_enode_p): Split enodes before
8528         "signal" calls.
8530 2020-09-29  David Malcolm  <dmalcolm@redhat.com>
8532         * constraint-manager.cc
8533         (constraint_manager::add_constraint_internal): Whitespace fixes.
8534         Silence -Wsign-compare warning.
8535         * engine.cc (maybe_process_run_of_before_supernode_enodes):
8536         Silence -Wsign-compare warning.
8538 2020-09-28  David Malcolm  <dmalcolm@redhat.com>
8540         * region-model.h (binop_svalue::dyn_cast_binop_svalue): Remove
8541         redundant "virtual".  Add FINAL OVERRIDE.
8542         (widening_svalue::dyn_cast_widening_svalue): Add FINAL OVERRIDE.
8543         (compound_svalue::dyn_cast_compound_svalue): Likewise.
8544         (conjured_svalue::dyn_cast_conjured_svalue): Likewise.
8546 2020-09-28  David Malcolm  <dmalcolm@redhat.com>
8548         * diagnostic-manager.cc (null_assignment_sm_context::m_visitor):
8549         Remove unused field.
8551 2020-09-28  David Malcolm  <dmalcolm@redhat.com>
8553         PR analyzer/97233
8554         * analyzer.cc (is_longjmp_call_p): Require the initial argument
8555         to be a pointer.
8556         * engine.cc (exploded_node::on_longjmp): Likewise.
8558 2020-09-28  David Malcolm  <dmalcolm@redhat.com>
8560         * program-state.cc (sm_state_map::print): Update check
8561         for m_global_state being the start state.
8563 2020-09-26  David Malcolm  <dmalcolm@redhat.com>
8565         PR analyzer/96646
8566         PR analyzer/96841
8567         * region-model.cc (region_model::get_representative_path_var):
8568         When handling offset_region, wrap the MEM_REF's first argument in
8569         an ADDR_EXPR of pointer type, rather than simply using the tree
8570         for the parent region.  Require the MEM_REF's second argument to
8571         be an integer constant.
8573 2020-09-24  David Malcolm  <dmalcolm@redhat.com>
8575         * analyzer.h (struct rejected_constraint): New decl.
8576         * analyzer.opt (fanalyzer-feasibility): New option.
8577         * diagnostic-manager.cc (path_builder::path_builder): Add
8578         "problem" param and use it to initialize new field.
8579         (path_builder::get_feasibility_problem): New accessor.
8580         (path_builder::m_feasibility_problem): New field.
8581         (dedupe_winners::add): Remove inversion of logic in "if" clause,
8582         swapping if/else suites.  In the !feasible_p suite, inspect
8583         flag_analyzer_feasibility and add code to handle when this
8584         is off, accepting the infeasible path, but recording the
8585         feasibility_problem.
8586         (diagnostic_manager::emit_saved_diagnostic): Pass the
8587         feasibility_problem to the path_builder.
8588         (diagnostic_manager::add_events_for_eedge): If we have
8589         a feasibility_problem at this edge, use it to add a custom event.
8590         * engine.cc (exploded_path::feasible_p): Pass a
8591         rejected_constraint ** to model.maybe_update_for_edge and transfer
8592         ownership of any created instance to any feasibility_problem.
8593         (feasibility_problem::dump_to_pp): New.
8594         * exploded-graph.h (feasibility_problem::feasibility_problem):
8595         Drop "model" param; add rejected_constraint * param.
8596         (feasibility_problem::~feasibility_problem): New.
8597         (feasibility_problem::dump_to_pp): New decl.
8598         (feasibility_problem::m_model): Drop field.
8599         (feasibility_problem::m_rc): New field.
8600         * program-point.cc (function_point::get_location): Handle
8601         PK_BEFORE_SUPERNODE and PK_AFTER_SUPERNODE.
8602         * program-state.cc (program_state::on_edge): Pass NULL to new
8603         param of region_model::maybe_update_for_edge.
8604         * region-model.cc (region_model::add_constraint): New overload
8605         adding a rejected_constraint ** param.
8606         (region_model::maybe_update_for_edge): Add rejected_constraint **
8607         param and pass it to the various apply_constraints_for_ calls.
8608         (region_model::apply_constraints_for_gcond): Add
8609         rejected_constraint ** param and pass it to add_constraint calls.
8610         (region_model::apply_constraints_for_gswitch): Likewise.
8611         (region_model::apply_constraints_for_exception): Likewise.
8612         (rejected_constraint::dump_to_pp): New.
8613         * region-model.h (region_model::maybe_update_for_edge):
8614         Add rejected_constraint ** param.
8615         (region_model::add_constraint): New overload adding a
8616         rejected_constraint ** param.
8617         (region_model::apply_constraints_for_gcond): Add
8618         rejected_constraint ** param.
8619         (region_model::apply_constraints_for_gswitch): Likewise.
8620         (region_model::apply_constraints_for_exception): Likewise.
8621         (struct rejected_constraint): New.
8623 2020-09-23  David Malcolm  <dmalcolm@redhat.com>
8625         PR analyzer/97178
8626         * engine.cc (impl_run_checkers): Update for change to ext_state
8627         ctor.
8628         * program-state.cc (selftest::test_sm_state_map): Pass an engine
8629         instance to ext_state ctor.
8630         (selftest::test_program_state_1): Likewise.
8631         (selftest::test_program_state_2): Likewise.
8632         (selftest::test_program_state_merging): Likewise.
8633         (selftest::test_program_state_merging_2): Likewise.
8634         * program-state.h (extrinsic_state::extrinsic_state): Remove NULL
8635         default value for "eng" param.
8637 2020-09-23  Tobias Burnus  <tobias@codesourcery.com>
8639         * analyzer-logging.cc: Guard '#pragma ... ignored "-Wformat-diag"'
8640         by '#if __GNUC__ >= 10'
8641         * analyzer.h: Likewise.
8642         * call-string.cc: Likewise.
8644 2020-09-23  David Malcolm  <dmalcolm@redhat.com>
8646         * engine.cc (exploded_node::on_stmt): Replace sequence of dyn_cast
8647         with switch.
8649 2020-09-22  David Malcolm  <dmalcolm@redhat.com>
8651         * analysis-plan.cc: Include "json.h".
8652         * analyzer.opt (fdump-analyzer-json): New.
8653         * call-string.cc: Include "json.h".
8654         (call_string::to_json): New.
8655         * call-string.h (call_string::to_json): New decl.
8656         * checker-path.cc: Include "json.h".
8657         * constraint-manager.cc: Include "json.h".
8658         (equiv_class::to_json): New.
8659         (constraint::to_json): New.
8660         (constraint_manager::to_json): New.
8661         * constraint-manager.h (equiv_class::to_json): New decl.
8662         (constraint::to_json): New decl.
8663         (constraint_manager::to_json): New decl.
8664         * diagnostic-manager.cc: Include "json.h".
8665         (saved_diagnostic::to_json): New.
8666         (diagnostic_manager::to_json): New.
8667         * diagnostic-manager.h (saved_diagnostic::to_json): New decl.
8668         (diagnostic_manager::to_json): New decl.
8669         * engine.cc: Include "json.h", <zlib.h>.
8670         (exploded_node::status_to_str): New.
8671         (exploded_node::to_json): New.
8672         (exploded_edge::to_json): New.
8673         (exploded_graph::to_json): New.
8674         (dump_analyzer_json): New.
8675         (impl_run_checkers): Call it.
8676         * exploded-graph.h (exploded_node::status_to_str): New decl.
8677         (exploded_node::to_json): New.
8678         (exploded_edge::to_json): New.
8679         (exploded_graph::to_json): New.
8680         * pending-diagnostic.cc: Include "json.h".
8681         * program-point.cc: Include "json.h".
8682         (program_point::to_json): New.
8683         * program-point.h (program_point::to_json): New decl.
8684         * program-state.cc: Include "json.h".
8685         (extrinsic_state::to_json): New.
8686         (sm_state_map::to_json): New.
8687         (program_state::to_json): New.
8688         * program-state.h (extrinsic_state::to_json): New decl.
8689         (sm_state_map::to_json): New decl.
8690         (program_state::to_json): New decl.
8691         * region-model-impl-calls.cc: Include "json.h".
8692         * region-model-manager.cc: Include "json.h".
8693         * region-model-reachability.cc: Include "json.h".
8694         * region-model.cc: Include "json.h".
8695         * region-model.h (svalue::to_json): New decl.
8696         (region::to_json): New decl.
8697         * region.cc: Include "json.h".
8698         (region::to_json: New.
8699         * sm-file.cc: Include "json.h".
8700         * sm-malloc.cc: Include "json.h".
8701         * sm-pattern-test.cc: Include "json.h".
8702         * sm-sensitive.cc: Include "json.h".
8703         * sm-signal.cc: Include "json.h".
8704         (signal_delivery_edge_info_t::to_json): New.
8705         * sm-taint.cc: Include "json.h".
8706         * sm.cc: Include "diagnostic.h", "tree-diagnostic.h", and
8707         "json.h".
8708         (state_machine::state::to_json): New.
8709         (state_machine::to_json): New.
8710         * sm.h (state_machine::state::to_json): New.
8711         (state_machine::to_json): New.
8712         * state-purge.cc: Include "json.h".
8713         * store.cc: Include "json.h".
8714         (binding_key::get_desc): New.
8715         (binding_map::to_json): New.
8716         (binding_cluster::to_json): New.
8717         (store::to_json): New.
8718         * store.h (binding_key::get_desc): New decl.
8719         (binding_map::to_json): New decl.
8720         (binding_cluster::to_json): New decl.
8721         (store::to_json): New decl.
8722         * supergraph.cc: Include "json.h".
8723         (supergraph::to_json): New.
8724         (supernode::to_json): New.
8725         (superedge::to_json): New.
8726         * supergraph.h (supergraph::to_json): New decl.
8727         (supernode::to_json): New decl.
8728         (superedge::to_json): New decl.
8729         * svalue.cc: Include "json.h".
8730         (svalue::to_json): New.
8732 2020-09-21  David Malcolm  <dmalcolm@redhat.com>
8734         PR analyzer/97130
8735         * region-model-impl-calls.cc (call_details::get_arg_type): New.
8736         * region-model.cc (region_model::on_call_pre): Check that the
8737         initial arg is a pointer before calling impl_call_memset and
8738         impl_call_strlen.
8739         * region-model.h (call_details::get_arg_type): New decl.
8741 2020-09-21  David Malcolm  <dmalcolm@redhat.com>
8743         PR analyzer/93355
8744         * sm-malloc.cc (malloc_state_machine::get_default_state): Look at
8745         the base region when considering pointers.  Treat pointers to
8746         decls as being non-heap.
8748 2020-09-18  David Malcolm  <dmalcolm@redhat.com>
8750         * checker-path.cc (warning_event::get_desc): Handle global state
8751         changes.
8753 2020-09-18  David Malcolm  <dmalcolm@redhat.com>
8755         * sm-malloc.cc (malloc_state_machine::on_stmt): Handle strdup and
8756         strndup as being malloc-like allocators.
8758 2020-09-16  David Malcolm  <dmalcolm@redhat.com>
8760         * engine.cc (strongly_connected_components::strong_connect): Only
8761         consider intraprocedural edges when creating SCCs.
8762         (worklist::key_t::cmp): Add comment.  Treat call_string
8763         differences as more important than differences of program_point
8764         within a supernode.
8766 2020-09-16  David Malcolm  <dmalcolm@redhat.com>
8768         * engine.cc (supernode_cluster::dump_dot): Show the SCC id
8769         in the per-supernode clusters in FILENAME.eg.dot output.
8770         (exploded_graph_annotator::add_node_annotations):
8771         Show the SCC of the supernode in FILENAME.supernode.eg.dot output.
8772         * exploded-graph.h (worklist::scc_id): New.
8773         (exploded_graph::get_scc_id): New.
8775 2020-09-16  David Malcolm  <dmalcolm@redhat.com>
8777         * engine.cc (exploded_node::dump_dot): Show STATUS_BULK_MERGED.
8778         (exploded_graph::process_worklist): Call
8779         maybe_process_run_of_before_supernode_enodes.
8780         (exploded_graph::maybe_process_run_of_before_supernode_enodes):
8781         New.
8782         (exploded_graph_annotator::print_enode): Show STATUS_BULK_MERGED.
8783         * exploded-graph.h (enum exploded_node::status): Add
8784         STATUS_BULK_MERGED.
8786 2020-09-16  David Malcolm  <dmalcolm@redhat.com>
8788         * engine.cc
8789         (exploded_graph::process_node) <case PK_BEFORE_SUPERNODE>:
8790         Simplify by using program_point::get_next.
8791         * program-point.cc (program_point::get_next): New.
8792         * program-point.h (program_point::get_next): New decl.
8794 2020-09-16  David Malcolm  <dmalcolm@redhat.com>
8796         * engine.cc (exploded_graph::get_or_create_node): Show the
8797         program point when issuing -Wanalyzer-too-complex due to hitting
8798         the per-program-point limit.
8800 2020-09-16  David Malcolm  <dmalcolm@redhat.com>
8802         * region-model.cc (region_model::on_call_pre): Treat getchar as
8803         having no side-effects.
8805 2020-09-15  David Malcolm  <dmalcolm@redhat.com>
8807         PR analyzer/96650
8808         * constraint-manager.cc (merger_fact_visitor::on_fact): Replace
8809         assertion that add_constraint succeeded with an assertion that
8810         if it fails, -fanalyzer-transitivity is off.
8812 2020-09-14  David Malcolm  <dmalcolm@redhat.com>
8814         * analyzer.opt (-param=analyzer-max-constraints=): New param.
8815         * constraint-manager.cc
8816         (constraint_manager::add_constraint_internal): Silently reject
8817         attempts to add constraints when the above limit is reached.
8819 2020-09-14  David Malcolm  <dmalcolm@redhat.com>
8821         PR analyzer/96653
8822         * constraint-manager.cc
8823         (constraint_manager::get_or_add_equiv_class): Don't accumulate
8824         transitive closure of all constraints on constants.
8826 2020-09-14  David Malcolm  <dmalcolm@redhat.com>
8828         PR analyzer/97029
8829         * analyzer.cc (is_setjmp_call_p): Require the initial arg to be a
8830         pointer.
8831         * region-model.cc (region_model::deref_rvalue): Assert that the
8832         svalue is of pointer type.
8834 2020-09-11  David Malcolm  <dmalcolm@redhat.com>
8836         PR analyzer/96798
8837         * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8838         New.
8839         (region_model::impl_call_strcpy): New.
8840         * region-model.cc (region_model::on_call_pre): Flag unhandled
8841         builtins that are non-pure as having unknown side-effects.
8842         Implement BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_STRCPY,
8843         BUILT_IN_STRCPY_CHK, BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED,
8844         BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_FPUTC,
8845         BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
8846         BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
8847         BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
8848         BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
8849         BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF.
8850         * region-model.h (region_model::impl_call_memcpy): New decl.
8851         (region_model::impl_call_strcpy): New decl.
8853 2020-09-09  David Malcolm  <dmalcolm@redhat.com>
8855         PR analyzer/94355
8856         * analyzer.opt (Wanalyzer-mismatching-deallocation): New warning.
8857         * region-model-impl-calls.cc
8858         (region_model::impl_call_operator_new): New.
8859         (region_model::impl_call_operator_delete): New.
8860         * region-model.cc (region_model::on_call_pre): Detect operator new
8861         and operator delete.
8862         (region_model::on_call_post): Likewise.
8863         (region_model::maybe_update_for_edge): Detect EH edges and call...
8864         (region_model::apply_constraints_for_exception): New function.
8865         * region-model.h (region_model::impl_call_operator_new): New decl.
8866         (region_model::impl_call_operator_delete): New decl.
8867         (region_model::apply_constraints_for_exception): New decl.
8868         * sm-malloc.cc (enum resource_state): New.
8869         (struct allocation_state): New state subclass.
8870         (enum wording): New.
8871         (struct api): New.
8872         (malloc_state_machine::custom_data_t): New typedef.
8873         (malloc_state_machine::add_state): New decl.
8874         (malloc_state_machine::m_unchecked)
8875         (malloc_state_machine::m_nonnull)
8876         (malloc_state_machine::m_freed): Delete these states in favor
8877         of...
8878         (malloc_state_machine::m_malloc)
8879         (malloc_state_machine::m_scalar_new)
8880         (malloc_state_machine::m_vector_new): ...this new api instances,
8881         which own their own versions of these states.
8882         (malloc_state_machine::on_allocator_call): New decl.
8883         (malloc_state_machine::on_deallocator_call): New decl.
8884         (api::api): New ctor.
8885         (dyn_cast_allocation_state): New.
8886         (as_a_allocation_state): New.
8887         (get_rs): New.
8888         (unchecked_p): New.
8889         (nonnull_p): New.
8890         (freed_p): New.
8891         (malloc_diagnostic::describe_state_change): Use unchecked_p and
8892         nonnull_p.
8893         (class mismatching_deallocation): New.
8894         (double_free::double_free): Add funcname param for initializing
8895         m_funcname.
8896         (double_free::emit): Use m_funcname in warning message rather
8897         than hardcoding "free".
8898         (double_free::describe_state_change): Likewise.  Use freed_p.
8899         (double_free::describe_call_with_state): Use freed_p.
8900         (double_free::describe_final_event): Use m_funcname in message
8901         rather than hardcoding "free".
8902         (double_free::m_funcname): New field.
8903         (possible_null::describe_state_change): Use unchecked_p.
8904         (possible_null::describe_return_of_state): Likewise.
8905         (use_after_free::use_after_free): Add param for initializing m_api.
8906         (use_after_free::emit): Use m_api->m_dealloc_funcname in message
8907         rather than hardcoding "free".
8908         (use_after_free::describe_state_change): Use freed_p.  Change the
8909         wording of the message based on the API.
8910         (use_after_free::describe_final_event): Use
8911         m_api->m_dealloc_funcname in message rather than hardcoding
8912         "free".  Change the wording of the message based on the API.
8913         (use_after_free::m_api): New field.
8914         (malloc_leak::describe_state_change): Use unchecked_p.  Update
8915         for renaming of m_malloc_event to m_alloc_event.
8916         (malloc_leak::describe_final_event): Update for renaming of
8917         m_malloc_event to m_alloc_event.
8918         (malloc_leak::m_malloc_event): Rename...
8919         (malloc_leak::m_alloc_event): ...to this.
8920         (free_of_non_heap::free_of_non_heap): Add param for initializing
8921         m_funcname.
8922         (free_of_non_heap::emit): Use m_funcname in message rather than
8923         hardcoding "free".
8924         (free_of_non_heap::describe_final_event): Likewise.
8925         (free_of_non_heap::m_funcname): New field.
8926         (allocation_state::dump_to_pp): New.
8927         (allocation_state::get_nonnull): New.
8928         (malloc_state_machine::malloc_state_machine): Update for changes
8929         to state fields and new api fields.
8930         (malloc_state_machine::add_state): New.
8931         (malloc_state_machine::on_stmt): Move malloc/calloc handling to
8932         on_allocator_call and call it, passing in the API pointer.
8933         Likewise for free, moving it to on_deallocator_call.  Handle calls
8934         to operator new and delete in an analogous way.  Use unchecked_p
8935         when testing for possibly-null-arg and possibly-null-deref, and
8936         transition to the non-null for the correct API.  Remove redundant
8937         node param from call to on_zero_assignment.  Use freed_p for
8938         use-after-free check, and pass in API.
8939         (malloc_state_machine::on_allocator_call): New, based on code in
8940         on_stmt.
8941         (malloc_state_machine::on_deallocator_call): Likewise.
8942         (malloc_state_machine::on_phi): Mark node param with
8943         ATTRIBUTE_UNUSED; don't pass it to on_zero_assignment.
8944         (malloc_state_machine::on_condition): Mark node param with
8945         ATTRIBUTE_UNUSED.  Replace on_transition calls with get_state and
8946         set_next_state pairs, transitioning to the non-null state for the
8947         appropriate API.
8948         (malloc_state_machine::can_purge_p): Port to new state approach.
8949         (malloc_state_machine::on_zero_assignment): Replace on_transition
8950         calls with get_state and set_next_state pairs.  Drop redundant
8951         node param.
8952         * sm.h (state_machine::add_custom_state): New.
8954 2020-09-09  David Malcolm  <dmalcolm@redhat.com>
8956         * diagnostic-manager.cc
8957         (null_assignment_sm_context::warn_for_state): Replace with...
8958         (null_assignment_sm_context::warn): ...this.
8959         * engine.cc (impl_sm_context::warn_for_state): Replace with...
8960         (impl_sm_context::warn): ...this.
8961         * sm-file.cc (fileptr_state_machine::on_stmt): Replace
8962         warn_for_state and on_transition calls with a get_state
8963         test guarding warn and set_next_state calls.
8964         * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
8965         * sm-pattern-test.cc (pattern_test_state_machine::on_condition):
8966         Replace warn_for_state call with warn call.
8967         * sm-sensitive.cc
8968         (sensitive_state_machine::warn_for_any_exposure): Replace
8969         warn_for_state call with a get_state test guarding a warn call.
8970         * sm-signal.cc (signal_state_machine::on_stmt): Likewise.
8971         * sm-taint.cc (taint_state_machine::on_stmt):  Replace
8972         warn_for_state and on_transition calls with a get_state
8973         test guarding warn and set_next_state calls.
8974         * sm.h (sm_context::warn_for_state): Replace with...
8975         (sm_context::warn): ...this.
8977 2020-09-09  David Malcolm  <dmalcolm@redhat.com>
8979         * diagnostic-manager.cc
8980         (null_assignment_sm_context::null_assignment_sm_context): Add old_state
8981         and ext_state params, initializing m_old_state and m_ext_state.
8982         (null_assignment_sm_context::on_transition): Split into...
8983         (null_assignment_sm_context::get_state): ...this new vfunc
8984         implementation and...
8985         (null_assignment_sm_context::set_next_state): ...this new vfunc
8986         implementation.
8987         (null_assignment_sm_context::m_old_state): New field.
8988         (null_assignment_sm_context::m_ext_state): New field.
8989         (diagnostic_manager::add_events_for_eedge): Pass in old state and
8990         ext_state when creating sm_ctxt.
8991         * engine.cc (impl_sm_context::on_transition): Split into...
8992         (impl_sm_context::get_state): ...this new vfunc
8993         implementation and...
8994         (impl_sm_context::set_next_state): ...this new vfunc
8995         implementation.
8996         * sm.h (sm_context::get_state): New pure virtual function.
8997         (sm_context::set_next_state): Likewise.
8998         (sm_context::on_transition): Convert from a pure virtual function
8999         to a regular function implemented in terms of get_state and
9000         set_next_state.
9002 2020-09-09  David Malcolm  <dmalcolm@redhat.com>
9004         * checker-path.cc (state_change_event::get_desc): Update
9005         state_machine::get_state_name calls to state::get_name.
9006         (warning_event::get_desc): Likewise.
9007         * diagnostic-manager.cc
9008         (null_assignment_sm_context::on_transition): Update comparison
9009         against 0 with comparison with m_sm.get_start_state.
9010         (diagnostic_manager::prune_for_sm_diagnostic): Update
9011         state_machine::get_state_name calls to state::get_name.
9012         * engine.cc (impl_sm_context::on_transition): Likewise.
9013         (exploded_node::get_dot_fillcolor): Use get_id when summing
9014         the sm states.
9015         * program-state.cc (sm_state_map::sm_state_map): Don't hardcode
9016         0 as the start state when initializing m_global_state.
9017         (sm_state_map::print): Use dump_to_pp rather than get_state_name
9018         when dumping states.
9019         (sm_state_map::is_empty_p): Don't hardcode 0 as the start state
9020         when examining m_global_state.
9021         (sm_state_map::hash): Use get_id when hashing states.
9022         (selftest::test_sm_state_map): Use state objects rather than
9023         arbitrary hardcoded integers.
9024         (selftest::test_program_state_merging): Likewise.
9025         (selftest::test_program_state_merging_2): Likewise.
9026         * sm-file.cc (fileptr_state_machine::m_start): Move to base class.
9027         (file_diagnostic::describe_state_change): Use get_start_state.
9028         (fileptr_state_machine::fileptr_state_machine): Drop m_start
9029         initialization.
9030         * sm-malloc.cc (malloc_state_machine::m_start): Move to base
9031         class.
9032         (malloc_diagnostic::describe_state_change): Use get_start_state.
9033         (possible_null::describe_state_change): Likewise.
9034         (malloc_state_machine::malloc_state_machine): Drop m_start
9035         initialization.
9036         * sm-pattern-test.cc (pattern_test_state_machine::m_start): Move
9037         to base class.
9038         (pattern_test_state_machine::pattern_test_state_machine): Drop
9039         m_start initialization.
9040         * sm-sensitive.cc (sensitive_state_machine::m_start): Move to base
9041         class.
9042         (sensitive_state_machine::sensitive_state_machine): Drop m_start
9043         initialization.
9044         * sm-signal.cc (signal_state_machine::m_start): Move to base
9045         class.
9046         (signal_state_machine::signal_state_machine): Drop m_start
9047         initialization.
9048         * sm-taint.cc (taint_state_machine::m_start): Move to base class.
9049         (taint_state_machine::taint_state_machine): Drop m_start
9050         initialization.
9051         * sm.cc (state_machine::state::dump_to_pp): New.
9052         (state_machine::state_machine): Move here from sm.h.  Initialize
9053         m_next_state_id and m_start.
9054         (state_machine::add_state): Reimplement in terms of state objects.
9055         (state_machine::get_state_name): Delete.
9056         (state_machine::get_state_by_name): Reimplement in terms of state
9057         objects.  Make const.
9058         (state_machine::validate): Delete.
9059         (state_machine::dump_to_pp): Reimplement in terms of state
9060         objects.
9061         * sm.h (state_machine::state): New class.
9062         (state_machine::state_t): Convert typedef from "unsigned" to
9063         "const state_machine::state *".
9064         (state_machine::state_machine): Move to sm.cc.
9065         (state_machine::get_default_state): Use m_start rather than
9066         hardcoding 0.
9067         (state_machine::get_state_name): Delete.
9068         (state_machine::get_state_by_name): Make const.
9069         (state_machine::get_start_state): New accessor.
9070         (state_machine::alloc_state_id): New.
9071         (state_machine::m_state_names): Drop in favor of...
9072         (state_machine::m_states): New field
9073         (state_machine::m_start): New field
9074         (start_start_p): Delete.
9076 2020-09-08  David Malcolm  <dmalcolm@redhat.com>
9078         PR analyzer/96949
9079         * store.cc (binding_map::apply_ctor_val_to_range): Add
9080         error-handling for the cases where we have symbolic offsets.
9082 2020-09-08  David Malcolm  <dmalcolm@redhat.com>
9084         PR analyzer/96950
9085         * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
9086         where min_index == max_index.
9087         (binding_map::apply_ctor_val_to_range): Replace assertion that we
9088         don't have a CONSTRUCTOR value with error-handling.
9090 2020-09-08  David Malcolm  <dmalcolm@redhat.com>
9092         PR analyzer/96962
9093         * region-model.cc (region_model::on_call_pre): Fix guard on switch
9094         on built-ins to only consider BUILT_IN_NORMAL, rather than other
9095         kinds of build-ins.
9097 2020-09-01  David Malcolm  <dmalcolm@redhat.com>
9099         PR analyzer/96792
9100         * region-model.cc (region_model::deref_rvalue): Add the constraint
9101         that PTR_SVAL is non-NULL.
9103 2020-08-31  David Malcolm  <dmalcolm@redhat.com>
9105         PR analyzer/96798
9106         * region-model.cc (region_model::on_call_pre): Handle
9107         BUILT_IN_MEMSET_CHK.
9109 2020-08-31  David Malcolm  <dmalcolm@redhat.com>
9111         * region-model.cc (region_model::on_call_pre): Gather handling of
9112         builtins and of internal fns into switch statements.  Handle
9113         "alloca" and BUILT_IN_ALLOCA_WITH_ALIGN.
9115 2020-08-31  David Malcolm  <dmalcolm@redhat.com>
9117         PR analyzer/96860
9118         * region.cc (decl_region::get_svalue_for_constructor): Support
9119         apply_ctor_to_region failing.
9120         * store.cc (binding_map::apply_ctor_to_region): Add failure
9121         handling.
9122         (binding_map::apply_ctor_val_to_range): Likewise.
9123         (binding_map::apply_ctor_pair_to_child_region): Likewise.  Replace
9124         assertion that child_base_offset is not symbolic with error
9125         handling.
9126         * store.h (binding_map::apply_ctor_to_region): Convert return type
9127         from void to bool.
9128         (binding_map::apply_ctor_val_to_range): Likewise.
9129         (binding_map::apply_ctor_pair_to_child_region): Likewise.
9131 2020-08-31  David Malcolm  <dmalcolm@redhat.com>
9133         PR analyzer/96763
9134         * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
9135         by calling a new binding_map::apply_ctor_val_to_range subroutine.
9136         Split out the existing non-CONSTRUCTOR-handling code to a new
9137         apply_ctor_pair_to_child_region subroutine.
9138         (binding_map::apply_ctor_val_to_range): New.
9139         (binding_map::apply_ctor_pair_to_child_region): New, split out
9140         from binding_map::apply_ctor_to_region as noted above.
9141         * store.h (binding_map::apply_ctor_val_to_range): New decl.
9142         (binding_map::apply_ctor_pair_to_child_region): New decl.
9144 2020-08-31  David Malcolm  <dmalcolm@redhat.com>
9146         PR analyzer/96764
9147         * region-model-manager.cc
9148         (region_model_manager::maybe_fold_unaryop): Handle VIEW_CONVERT_EXPR.
9149         (region_model_manager::get_or_create_cast): Move logic for
9150         real->integer casting to...
9151         (get_code_for_cast): ...this new function, and add logic for
9152         real->non-integer casts.
9153         (region_model_manager::maybe_fold_sub_svalue): Handle
9154         VIEW_CONVERT_EXPR.
9155         * region-model.cc
9156         (region_model::add_any_constraints_from_gassign): Likewise.
9157         * svalue.cc (svalue::maybe_undo_cast): Likewise.
9158         (unaryop_svalue::dump_to_pp): Likewise.
9160 2020-08-26  David Malcolm  <dmalcolm@redhat.com>
9162         PR analyzer/94858
9163         * region-model-manager.cc
9164         (region_model_manager::get_or_create_widening_svalue): Assert that
9165         neither of the inputs are themselves widenings.
9166         * store.cc (store::eval_alias_1): The initial value of a pointer
9167         can't point to a region that was allocated on the heap after the
9168         beginning of the path.  A widened pointer value can't alias anything
9169         that the initial pointer value can't alias.
9170         * svalue.cc (svalue::can_merge_p): Merge BINOP (X, OP, CST) with X
9171         to a widening svalue.  Merge
9172         BINOP(WIDENING(BASE, BINOP(BASE, X)), X) and BINOP(BASE, X) to
9173         to the LHS of the first BINOP.
9175 2020-08-26  David Malcolm  <dmalcolm@redhat.com>
9177         PR analyzer/96777
9178         * region-model.h (class compound_svalue): Document that all keys
9179         must be concrete.
9180         (compound_svalue::compound_svalue): Move definition to svalue.cc.
9181         * store.cc (binding_map::apply_ctor_to_region): Handle
9182         initializers for trailing arrays with incomplete size.
9183         * svalue.cc (compound_svalue::compound_svalue): Move definition
9184         here from region-model.h.  Add assertion that all keys are
9185         concrete.
9187 2020-08-22  David Malcolm  <dmalcolm@redhat.com>
9189         PR analyzer/94851
9190         * region-model-manager.cc
9191         (region_model_manager::maybe_fold_binop): Fold bitwise "& 0" to 0.
9193 2020-08-22  David Malcolm  <dmalcolm@redhat.com>
9195         * store.cc (store::eval_alias): Make const.  Split out 2nd half
9196         into store::eval_alias_1 and call it twice for symmetry, avoiding
9197         test duplication.
9198         (store::eval_alias_1): New function, split out from the above.
9199         * store.h (store::eval_alias): Make const.
9200         (store::eval_alias_1): New decl.
9202 2020-08-22  David Malcolm  <dmalcolm@redhat.com>
9204         * region-model.cc (region_model::push_frame): Bind the default
9205         SSA name for each parm if it exists, falling back to the parm
9206         itself otherwise, rather than doing both.
9208 2020-08-20  David Malcolm  <dmalcolm@redhat.com>
9210         PR analyzer/96723
9211         * region-model-manager.cc
9212         (region_model_manager::get_field_region): Assert that field is a
9213         FIELD_DECL.
9214         * region.cc (region::get_subregions_for_binding): In
9215         union-handling, filter the TYPE_FIELDS traversal to just FIELD_DECLs.
9217 2020-08-20  David Malcolm  <dmalcolm@redhat.com>
9219         PR analyzer/96713
9220         * region-model.cc (region_model::get_gassign_result): For
9221         comparisons, only use eval_condition when the lhs has boolean
9222         type, and use get_or_create_constant_svalue on the boolean
9223         constants directly rather than via get_rvalue.
9225 2020-08-19  David Malcolm  <dmalcolm@redhat.com>
9227         PR analyzer/96643
9228         * region-model.cc (region_model::deref_rvalue): Rather than
9229         attempting to handle all svalue kinds in the switch, only cover
9230         the special cases, and move symbolic-region handling to after
9231         the switch, thus implicitly handling the missing case SK_COMPOUND.
9233 2020-08-19  David Malcolm  <dmalcolm@redhat.com>
9235         PR analyzer/96705
9236         * region-model-manager.cc
9237         (region_model_manager::maybe_fold_binop): Check that we have an
9238         integral type before calling build_int_cst.
9240 2020-08-19  David Malcolm  <dmalcolm@redhat.com>
9242         PR analyzer/96699
9243         * region-model-manager.cc
9244         (region_model_manager::get_or_create_cast): Use FIX_TRUNC_EXPR for
9245         casting from REAL_TYPE to INTEGER_TYPE.
9247 2020-08-19  David Malcolm  <dmalcolm@redhat.com>
9249         PR analyzer/96651
9250         * region-model.cc (region_model::called_from_main_p): New.
9251         (region_model::get_store_value): Move handling for globals into...
9252         (region_model::get_initial_value_for_global): ...this new
9253         function, and add logic for extracting values from decl
9254         initializers.
9255         * region-model.h (decl_region::get_svalue_for_constructor): New
9256         decl.
9257         (decl_region::get_svalue_for_initializer): New decl.
9258         (region_model::called_from_main_p): New decl.
9259         (region_model::get_initial_value_for_global): New.
9260         * region.cc (decl_region::maybe_get_constant_value): Move logic
9261         for getting an svalue from a CONSTRUCTOR node to...
9262         (decl_region::get_svalue_for_constructor): ...this new function.
9263         (decl_region::get_svalue_for_initializer): New.
9264         * store.cc (get_svalue_for_ctor_val): Rewrite in terms of
9265         region_model::get_rvalue.
9266         * store.h (binding_cluster::get_map): New accessor.
9268 2020-08-19  David Malcolm  <dmalcolm@redhat.com>
9270         PR analyzer/96648
9271         * region.cc (get_field_at_bit_offset): Gracefully handle negative
9272         values for bit_offset.
9274 2020-08-18  David Malcolm  <dmalcolm@redhat.com>
9276         * region-model.cc (region_model::get_rvalue_1): Fix name of local.
9278 2020-08-18  David Malcolm  <dmalcolm@redhat.com>
9280         PR analyzer/96641
9281         * region-model.cc (region_model::get_rvalue_1): Handle
9282         unrecognized tree codes by returning "UNKNOWN.
9284 2020-08-18  David Malcolm  <dmalcolm@redhat.com>
9286         PR analyzer/96640
9287         * region-model.cc (region_model::get_gassign_result): Handle various
9288         VEC_* tree codes by returning UNKNOWN.
9289         (region_model::on_assignment): Handle unrecognized tree codes by
9290         setting lhs to an unknown value, rather than issuing a "sorry" and
9291         asserting.
9293 2020-08-17  David Malcolm  <dmalcolm@redhat.com>
9295         PR analyzer/96644
9296         * region-model-manager.cc (get_region_for_unexpected_tree_code):
9297         Handle ctxt being NULL.
9299 2020-08-17  David Malcolm  <dmalcolm@redhat.com>
9301         PR analyzer/96639
9302         * region.cc (region::get_subregions_for_binding): Check for "type"
9303         being NULL.
9305 2020-08-17  David Malcolm  <dmalcolm@redhat.com>
9307         PR analyzer/96642
9308         * store.cc (get_svalue_for_ctor_val): New.
9309         (binding_map::apply_ctor_to_region): Call it.
9311 2020-08-14  David Malcolm  <dmalcolm@redhat.com>
9313         PR testsuite/96609
9314         PR analyzer/96616
9315         * region-model.cc (region_model::get_store_value): Call
9316         maybe_get_constant_value on decl_regions first.
9317         * region-model.h (decl_region::maybe_get_constant_value): New decl.
9318         * region.cc (decl_region::get_stack_depth): Likewise.
9319         (decl_region::maybe_get_constant_value): New.
9320         * store.cc (get_subregion_within_ctor): New.
9321         (binding_map::apply_ctor_to_region): New.
9322         * store.h (binding_map::apply_ctor_to_region): New decl.
9324 2020-08-14  David Malcolm  <dmalcolm@redhat.com>
9326         PR analyzer/96611
9327         * store.cc (store::mark_as_escaped): Reject attempts to
9328         get a cluster for an unknown pointer.
9330 2020-08-13  David Malcolm  <dmalcolm@redhat.com>
9332         PR analyzer/93032
9333         PR analyzer/93938
9334         PR analyzer/94011
9335         PR analyzer/94099
9336         PR analyzer/94399
9337         PR analyzer/94458
9338         PR analyzer/94503
9339         PR analyzer/94640
9340         PR analyzer/94688
9341         PR analyzer/94689
9342         PR analyzer/94839
9343         PR analyzer/95026
9344         PR analyzer/95042
9345         PR analyzer/95240
9346         * analyzer-logging.cc: Ignore "-Wformat-diag".
9347         (logger::enter_scope): Use inc_indent in both overloads.
9348         (logger::exit_scope): Use dec_indent.
9349         * analyzer-logging.h (logger::inc_indent): New.
9350         (logger::dec_indent): New.
9351         * analyzer-selftests.cc (run_analyzer_selftests): Call
9352         analyzer_store_cc_tests.
9353         * analyzer-selftests.h (analyzer_store_cc_tests): New decl.
9354         * analyzer.cc (get_stmt_location): New function.
9355         * analyzer.h (class initial_svalue): New forward decl.
9356         (class unaryop_svalue): New forward decl.
9357         (class binop_svalue): New forward decl.
9358         (class sub_svalue): New forward decl.
9359         (class unmergeable_svalue): New forward decl.
9360         (class placeholder_svalue): New forward decl.
9361         (class widening_svalue): New forward decl.
9362         (class compound_svalue): New forward decl.
9363         (class conjured_svalue): New forward decl.
9364         (svalue_set): New typedef.
9365         (class map_region): Delete.
9366         (class array_region): Delete.
9367         (class frame_region): New forward decl.
9368         (class function_region): New forward decl.
9369         (class label_region): New forward decl.
9370         (class decl_region): New forward decl.
9371         (class element_region): New forward decl.
9372         (class offset_region): New forward decl.
9373         (class cast_region): New forward decl.
9374         (class field_region): New forward decl.
9375         (class string_region): New forward decl.
9376         (class region_model_manager): New forward decl.
9377         (class store_manager): New forward decl.
9378         (class store): New forward decl.
9379         (class call_details): New forward decl.
9380         (struct svalue_id_merger_mapping): Delete.
9381         (struct canonicalization): Delete.
9382         (class function_point): New forward decl.
9383         (class engine): New forward decl.
9384         (dump_tree): New function decl.
9385         (print_quoted_type): New function decl.
9386         (readability_comparator): New function decl.
9387         (tree_cmp): New function decl.
9388         (class path_var): Move here from region-model.h
9389         (bit_offset_t, bit_size_t, byte_size_t): New typedefs.
9390         (class region_offset): New class.
9391         (get_stmt_location): New decl.
9392         (struct member_function_hash_traits): New struct.
9393         (class consolidation_map): New class.
9394         Ignore "-Wformat-diag".
9395         * analyzer.opt (-param=analyzer-max-svalue-depth=): New param.
9396         (-param=analyzer-max-enodes-for-full-dump=): New param.
9397         * call-string.cc: Ignore -Wformat-diag.
9398         * checker-path.cc: Move includes of "analyzer/call-string.h" and
9399         "analyzer/program-point.h" to before "analyzer/region-model.h",
9400         and also include "analyzer/store.h" before it.
9401         (state_change_event::state_change_event): Replace "tree var" param
9402         with "const svalue *sval".  Convert "origin" param from tree to
9403         "const svalue *".
9404         (state_change_event::get_desc): Call get_representative_tree to
9405         convert the var and origin from const svalue * to tree.  Use
9406         svalue::get_desc rather than %qE when describing state changes.
9407         (checker_path::add_final_event): Use get_stmt_location.
9408         * checker-path.h (state_change_event::state_change_event): Port
9409         from tree to const svalue *.
9410         (state_change_event::get_lvalue): Delete.
9411         (state_change_event::get_dest_function): New.
9412         (state_change_event::m_var): Replace with...
9413         (state_change_event::m_sval): ...this.
9414         (state_change_event::m_origin): Convert from tree to
9415         const svalue *.
9416         * constraint-manager.cc: Include "analyzer/call-string.h",
9417         "analyzer/program-point.h", and "analyzer/store.h" before
9418         "analyzer/region-model.h".
9419         (struct bound, struct range): Move to constraint-manager.h.
9420         (compare_constants): New function.
9421         (range::dump): Rename to...
9422         (range::dump_to_pp): ...this.  Support NULL constants.
9423         (range::dump): Reintroduce for dumping to stderr.
9424         (range::constrained_to_single_element): Return result, rather than
9425         writing to *OUT.
9426         (range::eval_condition): New.
9427         (range::below_lower_bound): New.
9428         (range::above_upper_bound): New.
9429         (equiv_class::equiv_class): Port from svalue_id to const svalue *.
9430         (equiv_class::print): Likewise.
9431         (equiv_class::hash): Likewise.
9432         (equiv_class::operator==): Port from svalue_id to const svalue *.
9433         (equiv_class::add): Port from svalue_id to const svalue *. Drop
9434         "cm" param.
9435         (equiv_class::del): Port from svalue_id to const svalue *.
9436         (equiv_class::get_representative): Likewise.
9437         (equiv_class::remap_svalue_ids): Delete.
9438         (svalue_id_cmp_by_id): Rename to...
9439         (svalue_cmp_by_ptr): ...this, porting from svalue_id to
9440         const svalue *.
9441         (equiv_class::canonicalize): Update qsort comparator.
9442         (constraint::implied_by): New.
9443         (constraint_manager::constraint_manager): Copy m_mgr in copy ctor.
9444         (constraint_manager::dump_to_pp): Add "multiline" param
9445         (constraint_manager::dump): Pass "true" for "multiline".
9446         (constraint_manager::add_constraint): Port from svalue_id to
9447         const svalue *.  Split out second part into...
9448         (constraint_manager::add_unknown_constraint): ...this new
9449         function.  Remove self-constraints when merging equivalence
9450         classes.
9451         (constraint_manager::add_constraint_internal): Remove constraints
9452         that would be implied by the new constraint.  Port from svalue_id
9453         to const svalue *.
9454         (constraint_manager::get_equiv_class_by_sid): Rename to...
9455         (constraint_manager::get_equiv_class_by_svalue): ...this, porting
9456         from svalue_id to const svalue *.
9457         (constraint_manager::get_or_add_equiv_class): Port from svalue_id
9458         to const svalue *.
9459         (constraint_manager::eval_condition): Make const.  Call
9460         compare_constants and return early if it provides a known result.
9461         (constraint_manager::get_ec_bounds): New.
9462         (constraint_manager::eval_condition): New overloads.  Make
9463         existing one const, and use compare_constants.
9464         (constraint_manager::purge): Convert "p" param to a template
9465         rather that an abstract base class.  Port from svalue_id to
9466         const svalue *.
9467         (class dead_svalue_purger): New class.
9468         (constraint_manager::remap_svalue_ids): Delete.
9469         (constraint_manager::on_liveness_change): New.
9470         (equiv_class_cmp): Port from svalue_id to const svalue *.
9471         (constraint_manager::canonicalize): Likewise.  Combine with
9472         purging of redundant equivalence classes and constraints.
9473         (class cleaned_constraint_manager): Delete.
9474         (class merger_fact_visitor): Make "m_cm_b" const.  Add "m_merger"
9475         field.
9476         (merger_fact_visitor::fact): Port from svalue_id to const svalue *.
9477         Add special case for widening.
9478         (constraint_manager::merge): Port from svalue_id to const svalue *.
9479         (constraint_manager::clean_merger_input): Delete.
9480         (constraint_manager::for_each_fact): Port from svalue_id to
9481         const svalue *.
9482         (constraint_manager::validate): Likewise.
9483         (selftest::test_constraint_conditions): Provide a
9484         region_model_manager when creating region_model instances.
9485         Add test for self-equality not creating equivalence classes.
9486         (selftest::test_transitivity): Provide a region_model_manager when
9487         creating region_model instances.  Verify that EC-merging happens
9488         when constraints are implied.
9489         (selftest::test_constant_comparisons):  Provide a
9490         region_model_manager when creating region_model instances.
9491         (selftest::test_constraint_impl): Likewise.  Remove over-specified
9492         assertions.
9493         (selftest::test_equality): Provide a region_model_manager when
9494         creating region_model instances.
9495         (selftest::test_many_constants): Likewise.  Provide a
9496         program_point when testing merging.
9497         (selftest::run_constraint_manager_tests): Move call to
9498         test_constant_comparisons to outside the transitivity guard.
9499         * constraint-manager.h (struct bound): Move here from
9500         constraint-manager.cc.
9501         (struct range): Likewise.
9502         (struct::eval_condition): New decl.
9503         (struct::below_lower_bound): New decl.
9504         (struct::above_upper_bound): New decl.
9505         (equiv_class::add): Port from svalue_id to const svalue *.
9506         (equiv_class::del): Likewise.
9507         (equiv_class::get_representative): Likewise.
9508         (equiv_class::remap_svalue_ids): Drop.
9509         (equiv_class::m_cst_sid): Convert to..
9510         (equiv_class::m_cst_sval): ...this.
9511         (equiv_class::m_vars): Port from svalue_id to const svalue *.
9512         (constraint::bool implied_by): New decl.
9513         (fact_visitor::on_fact): Port from svalue_id to const svalue *.
9514         (constraint_manager::constraint_manager): Add mgr param.
9515         (constraint_manager::clone): Delete.
9516         (constraint_manager::maybe_get_constant): Delete.
9517         (constraint_manager::get_sid_for_constant): Delete.
9518         (constraint_manager::get_num_svalues): Delete.
9519         (constraint_manager::dump_to_pp): Add "multiline" param.
9520         (constraint_manager::get_equiv_class): Port from svalue_id to
9521         const svalue *.
9522         (constraint_manager::add_constraint):  Likewise.
9523         (constraint_manager::get_equiv_class_by_sid): Rename to...
9524         (constraint_manager::get_equiv_class_by_svalue): ...this, porting
9525         from svalue_id to const svalue *.
9526         (constraint_manager::add_unknown_constraint): New decl.
9527         (constraint_manager::get_or_add_equiv_class): Port from svalue_id
9528         to const svalue *.
9529         (constraint_manager::eval_condition): Likewise.  Add overloads.
9530         (constraint_manager::get_ec_bounds): New decl.
9531         (constraint_manager::purge): Convert to template.
9532         (constraint_manager::remap_svalue_ids): Delete.
9533         (constraint_manager::on_liveness_change): New decl.
9534         (constraint_manager::canonicalize): Drop param.
9535         (constraint_manager::clean_merger_input): Delete.
9536         (constraint_manager::m_mgr): New field.
9537         * diagnostic-manager.cc: Move includes of
9538         "analyzer/call-string.h" and "analyzer/program-point.h" to before
9539         "analyzer/region-model.h", and also include "analyzer/store.h"
9540         before it.
9541         (saved_diagnostic::saved_diagnostic): Add "sval" param.
9542         (diagnostic_manager::diagnostic_manager): Add engine param.
9543         (diagnostic_manager::add_diagnostic): Add "sval" param, passing it
9544         to saved_diagnostic ctor.  Update overload to pass NULL for it.
9545         (dedupe_winners::dedupe_winners): Add engine param.
9546         (dedupe_winners::add): Add "eg" param.  Pass m_engine to
9547         feasible_p.
9548         (dedupe_winner::m_engine): New field.
9549         (diagnostic_manager::emit_saved_diagnostics): Pass engine to
9550         dedupe_winners.  Pass &eg when adding candidates.  Pass svalue
9551         rather than tree to prune_path.  Use get_stmt_location to get
9552         primary location of diagnostic.
9553         (diagnostic_manager::emit_saved_diagnostic): Likewise.
9554         (get_any_origin): Drop.
9555         (state_change_event_creator::on_global_state_change): Pass NULL
9556         const svalue * rather than NULL_TREE trees to state_change_event
9557         ctor.
9558         (state_change_event_creator::on_state_change): Port from tree and
9559         svalue_id to const svalue *.
9560         (for_each_state_change): Port from svalue_id to const svalue *.
9561         (struct null_assignment_sm_context): New.
9562         (diagnostic_manager::add_events_for_eedge):  Add state change
9563         events for assignment to NULL.
9564         (diagnostic_manager::prune_path): Update param from tree to
9565         const svalue *.
9566         (diagnostic_manager::prune_for_sm_diagnostic): Port from tracking
9567         by tree to by const svalue *.
9568         * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add sval
9569         param.
9570         (saved_diagnostic::m_sval): New field.
9571         (diagnostic_manager::diagnostic_manager): Add engine param.
9572         (diagnostic_manager::get_engine): New.
9573         (diagnostic_manager::add_diagnostic): Add "sval" param.
9574         (diagnostic_manager::prune_path): Likewise.
9575         (diagnostic_manager::prune_for_sm_diagnostic): New overload.
9576         (diagnostic_manager::m_eng): New field.
9577         * engine.cc: Move includes of "analyzer/call-string.h" and
9578         "analyzer/program-point.h" to before "analyzer/region-model.h",
9579         and also include "analyzer/store.h" before it.
9580         (impl_region_model_context::impl_region_model_context): Update for
9581         removal of m_change field.
9582         (impl_region_model_context::remap_svalue_ids): Delete.
9583         (impl_region_model_context::on_svalue_leak): New.
9584         (impl_region_model_context::on_svalue_purge): Delete.
9585         (impl_region_model_context::on_liveness_change): New.
9586         (impl_region_model_context::on_unknown_change): Update param
9587         from svalue_id to const svalue *.  Add is_mutable param.
9588         (setjmp_svalue::compare_fields): Delete.
9589         (setjmp_svalue::accept): New.
9590         (setjmp_svalue::add_to_hash): Delete.
9591         (setjmp_svalue::dump_to_pp): New.
9592         (setjmp_svalue::print_details): Delete.
9593         (impl_sm_context::impl_sm_context): Drop "change" param.
9594         (impl_sm_context::get_fndecl_for_call): Drop "m_change".
9595         (impl_sm_context::on_transition): Drop ATTRIBUTE_UNUSED from
9596         "stmt" param.  Drop m_change.  Port from svalue_id to
9597         const svalue *.
9598         (impl_sm_context::warn_for_state): Drop m_change.  Port from
9599         svalue_id to const svalue *.
9600         (impl_sm_context::get_readable_tree): Rename to...
9601         (impl_sm_context::get_diagnostic_tree): ...this.  Port from
9602         svalue_id to const svalue *.
9603         (impl_sm_context::is_zero_assignment): New.
9604         (impl_sm_context::m_change): Delete field.
9605         (leak_stmt_finder::find_stmt): Handle m_var being NULL.
9606         (readability):  Increase penalty for MEM_REF.  For SSA_NAMEs,
9607         slightly favor the underlying var over the SSA name.  Heavily
9608         penalize temporaries.  Handle RESULT_DECL.
9609         (readability_comparator): Make non-static.  Consider stack depths.
9610         (impl_region_model_context::on_state_leak): Convert from svalue_id
9611         to const svalue *, updating for region_model changes.  Use
9612         id_equal.
9613         (impl_region_model_context::on_inherited_svalue): Delete.
9614         (impl_region_model_context::on_cast): Delete.
9615         (impl_region_model_context::on_condition):  Drop m_change.
9616         (impl_region_model_context::on_phi): Likewise.
9617         (impl_region_model_context::on_unexpected_tree_code): Handle t
9618         being NULL.
9619         (point_and_state::validate): Update stack checking for
9620         region_model changes.
9621         (eg_traits::dump_args_t::show_enode_details_p): New.
9622         (exploded_node::exploded_node): Initialize m_num_processed_stmts.
9623         (exploded_node::get_processed_stmt): New function.
9624         (exploded_node::get_dot_fillcolor): Add more colors.
9625         (exploded_node::dump_dot): Guard the printing of the point and
9626         state with show_enode_details_p.  Print the processed stmts for
9627         this enode after the initial state.
9628         (exploded_node::dump_to_pp): Pass true for new multiline param
9629         of program_state::dump_to_pp.
9630         (exploded_node::on_stmt): Drop "change" param.  Log the stmt.
9631         Set input_location.  Implement __analyzer_describe.  Update
9632         implementation of __analyzer_dump and __analyzer_eval.
9633         Remove purging of sm-state for unknown fncalls from here.
9634         (exploded_node::on_edge): Drop "change" param.
9635         (exploded_node::on_longjmp): Port from region_id/svalue_id to
9636         const region */const svalue *.  Call program_state::detect_leaks.
9637         Drop state_change.
9638         (exploded_node::detect_leaks): Update for changes to region_model.
9639         Call program_state::detect_leaks.
9640         (exploded_edge::exploded_edge): Drop ext_state and change params.
9641         (exploded_edge::dump_dot): "args" is no longer used.  Drop dumping
9642         of m_change.
9643         (exploded_graph::exploded_graph): Pass engine to
9644         m_diagnostic_manager ctor.  Use program_point::origin.
9645         (exploded_graph::add_function_entry):  Drop ctxt.  Use
9646         program_state::push_frame.  Drop state_change.
9647         (exploded_graph::get_or_create_node): Drop "change" param.  Add
9648         "enode_for_diag" param.  Update dumping calls for API changes.
9649         Pass point to can_merge_with_p.  Show enode indices
9650         within -Wanalyzer-too-complex diagnostic for hitting the per-point
9651         limit.
9652         (exploded_graph::add_edge): Drop "change" param.  Log which nodes
9653         are being connected.  Update for changes to exploded_edge ctor.
9654         (exploded_graph::get_per_program_point_data): New.
9655         (exploded_graph::process_worklist): Pass point to
9656         can_merge_with_p.  Drop state_change.  Update dumping call for API
9657         change.
9658         (exploded_graph::process_node):  Drop state_change.  Split the
9659         node in-place if an sm-state-change occurs.  Update
9660         m_num_processed_stmts.  Update dumping calls for API change.
9661         (exploded_graph::log_stats): Call engine::log_stats.
9662         (exploded_graph::dump_states_for_supernode): Update dumping
9663         call.
9664         (exploded_path::feasible_p): Add "eng" and "eg" params.
9665         Rename "i" to "end_idx".  Pass the manager to the region_model
9666         ctor.  Update for every processed stmt in the enode, not just the
9667         first.  Keep track of which snodes have been visited, and call
9668         loop_replay_fixup when revisiting one.
9669         (enode_label::get_text): Update dump call for new param.
9670         (exploded_graph::dump_exploded_nodes): Likewise.
9671         (exploded_graph::get_node_by_index): New.
9672         (impl_run_checkers): Create engine instance and pass its address
9673         to extrinsic_state ctor.
9674         * exploded-graph.h
9675         (impl_region_model_context::impl_region_model_context): Drop
9676         "change" params.
9677         (impl_region_model_context::void remap_svalue_ids): Delete.
9678         (impl_region_model_context::on_svalue_purge): Delete.
9679         (impl_region_model_context::on_svalue_leak): New.
9680         (impl_region_model_context::on_liveness_change): New.
9681         (impl_region_model_context::on_state_leak): Update signature.
9682         (impl_region_model_context::on_inherited_svalue): Delete.
9683         (impl_region_model_context::on_cast): Delete.
9684         (impl_region_model_context::on_unknown_change): Update signature.
9685         (impl_region_model_context::m_change): Delete.
9686         (eg_traits::dump_args_t::show_enode_details_p): New.
9687         (exploded_node::on_stmt): Drop "change" param.
9688         (exploded_node::on_edge): Likewise.
9689         (exploded_node::get_processed_stmt): New decl.
9690         (exploded_node::m_num_processed_stmts): New field.
9691         (exploded_edge::exploded_edge): Drop ext_state and change params.
9692         (exploded_edge::m_change): Delete.
9693         (exploded_graph::get_engine): New accessor.
9694         (exploded_graph::get_or_create_node): Drop "change" param.  Add
9695         "enode_for_diag" param.
9696         (exploded_graph::add_edge): Drop "change" param.
9697         (exploded_graph::get_per_program_point_data): New decl.
9698         (exploded_graph::get_node_by_index): New decl.
9699         (exploded_path::feasible_p): Add "eng" and "eg" params.
9700         * program-point.cc: Include "analyzer/store.h" before including
9701         "analyzer/region-model.h".
9702         (function_point::function_point): Move here from
9703         program-point.h.
9704         (function_point::get_function): Likewise.
9705         (function_point::from_function_entry): Likewise.
9706         (function_point::before_supernode): Likewise.
9707         (function_point::next_stmt): New function.
9708         * program-point.h (function_point::function_point): Move
9709         implementation from here to program-point.cc.
9710         (function_point::get_function): Likewise.
9711         (function_point::from_function_entry): Likewise.
9712         (function_point::before_supernode): Likewise.
9713         (function_point::next_stmt): New decl.
9714         (program_point::operator!=): New.
9715         (program_point::origin): New.
9716         (program_point::next_stmt): New.
9717         (program_point::m_function_point): Make non-const.
9718         * program-state.cc: Move includes of "analyzer/call-string.h" and
9719         "analyzer/program-point.h" to before "analyzer/region-model.h",
9720         and also include "analyzer/store.h" before it.
9721         (extrinsic_state::get_model_manager): New.
9722         (sm_state_map::sm_state_map): Pass in sm and sm_idx to ctor,
9723         rather than pass the around.
9724         (sm_state_map::clone_with_remapping): Delete.
9725         (sm_state_map::print): Remove "sm" param in favor of "m_sm".  Add
9726         "simple" and "multiline" params and support multiline vs single
9727         line dumping.
9728         (sm_state_map::dump): Remove "sm" param in favor of "m_sm".  Add
9729         "simple" param.
9730         (sm_state_map::hash): Port from svalue_id to const svalue *.
9731         (sm_state_map::operator==): Likewise.
9732         (sm_state_map::get_state): Likewise.  Call canonicalize_svalue on
9733         input.  Handle inheritance of sm-state.  Call get_default_state.
9734         (sm_state_map::get_origin): Port from svalue_id to const svalue *.
9735         (sm_state_map::set_state): Likewise.  Pass in ext_state.  Reject
9736         attempts to set state on UNKNOWN.
9737         (sm_state_map::impl_set_state): Port from svalue_id to
9738         const svalue *.  Pass in ext_state.  Call canonicalize_svalue on
9739         input.
9740         (sm_state_map::purge_for_unknown_fncall): Delete.
9741         (sm_state_map::on_svalue_leak): New.
9742         (sm_state_map::remap_svalue_ids): Delete.
9743         (sm_state_map::on_liveness_change): New.
9744         (sm_state_map::on_unknown_change): Reimplement.
9745         (sm_state_map::on_svalue_purge): Delete.
9746         (sm_state_map::on_inherited_svalue): Delete.
9747         (sm_state_map::on_cast): Delete.
9748         (sm_state_map::validate): Delete.
9749         (sm_state_map::canonicalize_svalue): New.
9750         (program_state::program_state): Update to pass manager to
9751         region_model's ctor.  Constify num_states and pass state machine
9752         and index to sm_state_map ctor.
9753         (program_state::print): Update for changes to dump API.
9754         (program_state::dump_to_pp): Ignore the summarize param.  Add
9755         "multiline" param.
9756         (program_state::dump_to_file): Add "multiline" param.
9757         (program_state::dump): Pass "true" for new "multiline" param.
9758         (program_state::push_frame): New.
9759         (program_state::on_edge): Drop "change" param.  Call
9760         program_state::detect_leaks.
9761         (program_state::prune_for_point): Add enode_for_diag param.
9762         Reimplement based on store class.  Call detect_leaks
9763         (program_state::remap_svalue_ids): Delete.
9764         (program_state::get_representative_tree): Port from svalue_id to
9765         const svalue *.
9766         (program_state::can_merge_with_p): Add "point" param.  Add early
9767         reject for sm-differences.  Drop id remapping.
9768         (program_state::validate): Drop region model and sm_state_map
9769         validation.
9770         (state_change::sm_change::dump): Delete.
9771         (state_change::sm_change::remap_svalue_ids): Delete.
9772         (state_change::sm_change::on_svalue_purge): Delete.
9773         (log_set_of_svalues): New.
9774         (state_change::sm_change::validate): Delete.
9775         (state_change::state_change): Delete.
9776         (state_change::add_sm_change): Delete.
9777         (state_change::affects_p): Delete.
9778         (state_change::dump): Delete.
9779         (state_change::remap_svalue_ids): Delete.
9780         (state_change::on_svalue_purge): Delete.
9781         (state_change::validate): Delete.
9782         (selftest::assert_dump_eq): Delete.
9783         (ASSERT_DUMP_EQ): Delete.
9784         (selftest::test_sm_state_map): Update for changes to region_model
9785         and sm_state_map, porting from svalue_id to const svalue *.
9786         (selftest::test_program_state_dumping): Likewise.  Drop test of
9787         dumping, renaming to...
9788         (selftest::test_program_state_1): ...this.
9789         (selftest::test_program_state_dumping_2): Likewise, renaming to...
9790         (selftest::test_program_state_2): ...this.
9791         (selftest::test_program_state_merging): Update for changes to
9792         region_model.
9793         (selftest::test_program_state_merging_2): Likewise.
9794         (selftest::analyzer_program_state_cc_tests): Update for renamed
9795         tests.
9796         * program-state.h (extrinsic_state::extrinsic_state): Add logger
9797         and engine params.
9798         (extrinsic_state::get_logger): New accessor.
9799         (extrinsic_state::get_engine): New accessor.
9800         (extrinsic_state::get_model_manager): New accessor.
9801         (extrinsic_state::m_logger): New field.
9802         (extrinsic_state::m_engine): New field.
9803         (struct default_hash_traits<svalue_id>): Delete.
9804         (pod_hash_traits<svalue_id>::hash): Delete.
9805         (pod_hash_traits<svalue_id>::equal): Delete.
9806         (pod_hash_traits<svalue_id>::mark_deleted): Delete.
9807         (pod_hash_traits<svalue_id>::mark_empty): Delete.
9808         (pod_hash_traits<svalue_id>::is_deleted): Delete.
9809         (pod_hash_traits<svalue_id>::is_empty): Delete.
9810         (sm_state_map::entry_t::entry_t): Port from svalue_id to
9811         const svalue *.
9812         (sm_state_map::entry_t::m_origin): Likewise.
9813         (sm_state_map::map_t): Likewise.
9814         (sm_state_map::sm_state_map): Add state_machine and index params.
9815         (sm_state_map::clone_with_remapping): Delete.
9816         (sm_state_map::print):  Drop sm param; add simple and multiline
9817         params.
9818         (sm_state_map::dump): Drop sm param; add simple param.
9819         (sm_state_map::get_state): Port from svalue_id to const svalue *.
9820         Add ext_state param.
9821         (sm_state_map::get_origin): Likewise.
9822         (sm_state_map::set_state): Likewise.
9823         (sm_state_map::impl_set_state): Likewise.
9824         (sm_state_map::purge_for_unknown_fncall): Delete.
9825         (sm_state_map::remap_svalue_ids): Delete.
9826         (sm_state_map::on_svalue_purge): Delete.
9827         (sm_state_map::on_svalue_leak): New.
9828         (sm_state_map::on_liveness_change): New.
9829         (sm_state_map::on_inherited_svalue): Delete.
9830         (sm_state_map::on_cast): Delete.
9831         (sm_state_map::validate): Delete.
9832         (sm_state_map::on_unknown_change): Port from svalue_id to
9833         const svalue *.  Add is_mutable and ext_state params.
9834         (sm_state_map::canonicalize_svalue): New.
9835         (sm_state_map::m_sm): New field.
9836         (sm_state_map::m_sm_idx): New field.
9837         (program_state::operator=): Delete.
9838         (program_state::dump_to_pp): Drop "summarize" param, adding
9839         "simple" and "multiline".
9840         (program_state::dump_to_file): Likewise.
9841         (program_state::dump): Rename "summarize" to "simple".
9842         (program_state::push_frame): New.
9843         (program_state::get_current_function): New.
9844         (program_state::on_edge): Drop "change" param.
9845         (program_state::prune_for_point): Likewise.  Add enode_for_diag
9846         param.
9847         (program_state::remap_svalue_ids): Delete.
9848         (program_state::get_representative_tree): Port from svalue_id to
9849         const svalue *.
9850         (program_state::can_purge_p): Likewise.  Pass ext_state to get_state.
9851         (program_state::can_merge_with_p): Add point param.
9852         (program_state::detect_leaks): New.
9853         (state_change_visitor::on_state_change): Port from tree and
9854         svalue_id to a pair of const svalue *.
9855         (class state_change): Delete.
9856         * region.cc: New file.
9857         * region-model-impl-calls.cc: New file.
9858         * region-model-manager.cc: New file.
9859         * region-model-reachability.cc: New file.
9860         * region-model-reachability.h: New file.
9861         * region-model.cc: Include "analyzer/call-string.h",
9862         "analyzer/program-point.h", and "analyzer/store.h" before
9863         "analyzer/region-model.h".  Include
9864         "analyzer/region-model-reachability.h".
9865         (dump_tree): Make non-static.
9866         (dump_quoted_tree): Make non-static.
9867         (print_quoted_type): Make non-static.
9868         (path_var::dump): Delete.
9869         (dump_separator): Delete.
9870         (class impl_constraint_manager): Delete.
9871         (svalue_id::print): Delete.
9872         (svalue_id::dump_node_name_to_pp): Delete.
9873         (svalue_id::validate): Delete.
9874         (region_id::print): Delete.
9875         (region_id::dump_node_name_to_pp): Delete.
9876         (region_id::validate): Delete.
9877         (region_id_set::region_id_set): Delete.
9878         (svalue_id_set::svalue_id_set): Delete.
9879         (svalue::operator==): Delete.
9880         (svalue::hash): Delete.
9881         (svalue::print): Delete.
9882         (svalue::dump_dot_to_pp): Delete.
9883         (svalue::remap_region_ids): Delete.
9884         (svalue::walk_for_canonicalization): Delete.
9885         (svalue::get_child_sid): Delete.
9886         (svalue::maybe_get_constant): Delete.
9887         (region_svalue::compare_fields): Delete.
9888         (region_svalue::add_to_hash): Delete.
9889         (region_svalue::print_details): Delete.
9890         (region_svalue::dump_dot_to_pp): Delete.
9891         (region_svalue::remap_region_ids): Delete.
9892         (region_svalue::merge_values): Delete.
9893         (region_svalue::walk_for_canonicalization): Delete.
9894         (region_svalue::eval_condition): Delete.
9895         (constant_svalue::compare_fields): Delete.
9896         (constant_svalue::add_to_hash): Delete.
9897         (constant_svalue::merge_values): Delete.
9898         (constant_svalue::eval_condition): Move to svalue.cc.
9899         (constant_svalue::print_details): Delete.
9900         (constant_svalue::get_child_sid): Delete.
9901         (unknown_svalue::compare_fields): Delete.
9902         (unknown_svalue::add_to_hash): Delete.
9903         (unknown_svalue::print_details): Delete.
9904         (poison_kind_to_str): Move to svalue.cc.
9905         (poisoned_svalue::compare_fields): Delete.
9906         (poisoned_svalue::add_to_hash): Delete.
9907         (poisoned_svalue::print_details): Delete.
9908         (region_kind_to_str): Move to region.cc and reimplement.
9909         (region::operator==): Delete.
9910         (region::get_parent_region): Delete.
9911         (region::set_value): Delete.
9912         (region::become_active_view): Delete.
9913         (region::deactivate_any_active_view): Delete.
9914         (region::deactivate_view): Delete.
9915         (region::get_value): Delete.
9916         (region::get_inherited_child_sid): Delete.
9917         (region_model::copy_region): Delete.
9918         (region_model::copy_struct_region): Delete.
9919         (region_model::copy_union_region): Delete.
9920         (region_model::copy_array_region): Delete.
9921         (region::hash): Delete.
9922         (region::print): Delete.
9923         (region::dump_dot_to_pp): Delete.
9924         (region::dump_to_pp): Delete.
9925         (region::dump_child_label): Delete.
9926         (region::validate): Delete.
9927         (region::remap_svalue_ids): Delete.
9928         (region::remap_region_ids): Delete.
9929         (region::add_view): Delete.
9930         (region::get_view): Delete.
9931         (region::region): Move to region.cc.
9932         (region::add_to_hash): Delete.
9933         (region::print_fields): Delete.
9934         (region::non_null_p): Delete.
9935         (primitive_region::clone): Delete.
9936         (primitive_region::walk_for_canonicalization): Delete.
9937         (map_region::map_region): Delete.
9938         (map_region::compare_fields): Delete.
9939         (map_region::print_fields): Delete.
9940         (map_region::validate): Delete.
9941         (map_region::dump_dot_to_pp): Delete.
9942         (map_region::dump_child_label): Delete.
9943         (map_region::get_or_create): Delete.
9944         (map_region::get): Delete.
9945         (map_region::add_to_hash): Delete.
9946         (map_region::remap_region_ids): Delete.
9947         (map_region::unbind): Delete.
9948         (map_region::get_tree_for_child_region): Delete.
9949         (map_region::get_tree_for_child_region): Delete.
9950         (tree_cmp): Move to region.cc.
9951         (map_region::can_merge_p): Delete.
9952         (map_region::walk_for_canonicalization): Delete.
9953         (map_region::get_value_by_name): Delete.
9954         (struct_or_union_region::valid_key_p): Delete.
9955         (struct_or_union_region::compare_fields): Delete.
9956         (struct_region::clone): Delete.
9957         (struct_region::compare_fields): Delete.
9958         (union_region::clone): Delete.
9959         (union_region::compare_fields): Delete.
9960         (frame_region::compare_fields): Delete.
9961         (frame_region::clone): Delete.
9962         (frame_region::valid_key_p): Delete.
9963         (frame_region::print_fields): Delete.
9964         (frame_region::add_to_hash): Delete.
9965         (globals_region::compare_fields): Delete.
9966         (globals_region::clone): Delete.
9967         (globals_region::valid_key_p): Delete.
9968         (code_region::compare_fields): Delete.
9969         (code_region::clone): Delete.
9970         (code_region::valid_key_p): Delete.
9971         (array_region::array_region): Delete.
9972         (array_region::get_element): Delete.
9973         (array_region::clone): Delete.
9974         (array_region::compare_fields): Delete.
9975         (array_region::print_fields): Delete.
9976         (array_region::validate): Delete.
9977         (array_region::dump_dot_to_pp): Delete.
9978         (array_region::dump_child_label): Delete.
9979         (array_region::get_or_create): Delete.
9980         (array_region::get): Delete.
9981         (array_region::add_to_hash): Delete.
9982         (array_region::remap_region_ids): Delete.
9983         (array_region::get_key_for_child_region): Delete.
9984         (array_region::key_cmp): Delete.
9985         (array_region::walk_for_canonicalization): Delete.
9986         (array_region::key_from_constant): Delete.
9987         (array_region::constant_from_key): Delete.
9988         (function_region::compare_fields): Delete.
9989         (function_region::clone): Delete.
9990         (function_region::valid_key_p): Delete.
9991         (stack_region::stack_region): Delete.
9992         (stack_region::compare_fields): Delete.
9993         (stack_region::clone): Delete.
9994         (stack_region::print_fields): Delete.
9995         (stack_region::dump_child_label): Delete.
9996         (stack_region::validate): Delete.
9997         (stack_region::push_frame): Delete.
9998         (stack_region::get_current_frame_id): Delete.
9999         (stack_region::pop_frame): Delete.
10000         (stack_region::add_to_hash): Delete.
10001         (stack_region::remap_region_ids): Delete.
10002         (stack_region::can_merge_p): Delete.
10003         (stack_region::walk_for_canonicalization): Delete.
10004         (stack_region::get_value_by_name): Delete.
10005         (heap_region::heap_region): Delete.
10006         (heap_region::compare_fields): Delete.
10007         (heap_region::clone): Delete.
10008         (heap_region::walk_for_canonicalization): Delete.
10009         (root_region::root_region): Delete.
10010         (root_region::compare_fields): Delete.
10011         (root_region::clone): Delete.
10012         (root_region::print_fields): Delete.
10013         (root_region::validate): Delete.
10014         (root_region::dump_child_label): Delete.
10015         (root_region::push_frame): Delete.
10016         (root_region::get_current_frame_id): Delete.
10017         (root_region::pop_frame): Delete.
10018         (root_region::ensure_stack_region): Delete.
10019         (root_region::get_stack_region): Delete.
10020         (root_region::ensure_globals_region): Delete.
10021         (root_region::get_code_region): Delete.
10022         (root_region::ensure_code_region): Delete.
10023         (root_region::get_globals_region): Delete.
10024         (root_region::ensure_heap_region): Delete.
10025         (root_region::get_heap_region): Delete.
10026         (root_region::remap_region_ids): Delete.
10027         (root_region::can_merge_p): Delete.
10028         (root_region::add_to_hash): Delete.
10029         (root_region::walk_for_canonicalization): Delete.
10030         (root_region::get_value_by_name): Delete.
10031         (symbolic_region::symbolic_region): Delete.
10032         (symbolic_region::compare_fields): Delete.
10033         (symbolic_region::clone): Delete.
10034         (symbolic_region::walk_for_canonicalization): Delete.
10035         (symbolic_region::print_fields): Delete.
10036         (region_model::region_model): Add region_model_manager * param.
10037         Reimplement in terms of store, dropping impl_constraint_manager
10038         subclass.
10039         (region_model::operator=): Reimplement in terms of store
10040         (region_model::operator==): Likewise.
10041         (region_model::hash): Likewise.
10042         (region_model::print): Delete.
10043         (region_model::print_svalue): Delete.
10044         (region_model::dump_dot_to_pp): Delete.
10045         (region_model::dump_dot_to_file): Delete.
10046         (region_model::dump_dot): Delete.
10047         (region_model::dump_to_pp): Replace "summarize" param with
10048         "simple" and "multiline".  Port to store-based implementation.
10049         (region_model::dump): Replace "summarize" param with "simple" and
10050         "multiline".
10051         (dump_vec_of_tree): Delete.
10052         (region_model::dump_summary_of_rep_path_vars): Delete.
10053         (region_model::validate): Delete.
10054         (svalue_id_cmp_by_constant_svalue_model): Delete.
10055         (svalue_id_cmp_by_constant_svalue): Delete.
10056         (region_model::canonicalize): Drop "ctxt" param.  Reimplement in
10057         terms of store and constraints.
10058         (region_model::canonicalized_p): Remove NULL arg to canonicalize.
10059         (region_model::loop_replay_fixup): New.
10060         (poisoned_value_diagnostic::emit): Tweak wording of warnings.
10061         (region_model::check_for_poison): Delete.
10062         (region_model::get_gassign_result): New.
10063         (region_model::on_assignment): Port to store-based implementation.
10064         (region_model::on_call_pre): Delete calls to check_for_poison.
10065         Move implementations to region-model-impl-calls.c and port to
10066         store-based implementation.
10067         (region_model::on_call_post): Likewise.
10068         (class reachable_regions): Move to region-model-reachability.h/cc
10069         and port to store-based implementation.
10070         (region_model::handle_unrecognized_call): Port to store-based
10071         implementation.
10072         (region_model::get_reachable_svalues): New.
10073         (region_model::on_setjmp): Port to store-based implementation.
10074         (region_model::on_longjmp): Likewise.
10075         (region_model::handle_phi): Drop is_back_edge param and the logic
10076         using it.
10077         (region_model::get_lvalue_1): Port from region_id to const region *.
10078         (region_model::make_region_for_unexpected_tree_code): Delete.
10079         (assert_compat_types): If the check fails, use internal_error to
10080         show the types.
10081         (region_model::get_lvalue): Port from region_id to const region *.
10082         (region_model::get_rvalue_1): Port from svalue_id to const svalue *.
10083         (region_model::get_rvalue): Likewise.
10084         (region_model::get_or_create_ptr_svalue): Delete.
10085         (region_model::get_or_create_constant_svalue): Delete.
10086         (region_model::get_svalue_for_fndecl): Delete.
10087         (region_model::get_region_for_fndecl): Delete.
10088         (region_model::get_svalue_for_label): Delete.
10089         (region_model::get_region_for_label): Delete.
10090         (build_cast): Delete.
10091         (region_model::maybe_cast_1): Delete.
10092         (region_model::maybe_cast): Delete.
10093         (region_model::get_field_region): Delete.
10094         (region_model::get_store_value): New.
10095         (region_model::region_exists_p): New.
10096         (region_model::deref_rvalue): Port from svalue_id to const svalue *.
10097         (region_model::set_value): Likewise.
10098         (region_model::clobber_region): New.
10099         (region_model::purge_region): New.
10100         (region_model::zero_fill_region): New.
10101         (region_model::mark_region_as_unknown): New.
10102         (region_model::eval_condition): Port from svalue_id to
10103         const svalue *.
10104         (region_model::eval_condition_without_cm): Likewise.
10105         (region_model::compare_initial_and_pointer): New.
10106         (region_model::add_constraint): Port from svalue_id to
10107         const svalue *.
10108         (region_model::maybe_get_constant): Delete.
10109         (region_model::get_representative_path_var): New.
10110         (region_model::add_new_malloc_region): Delete.
10111         (region_model::get_representative_tree): Port to const svalue *.
10112         (region_model::get_representative_path_var): Port to
10113         const region *.
10114         (region_model::get_path_vars_for_svalue): Delete.
10115         (region_model::set_to_new_unknown_value): Delete.
10116         (region_model::update_for_phis): Don't pass is_back_edge to handle_phi.
10117         (region_model::update_for_call_superedge): Port from svalue_id to
10118         const svalue *.
10119         (region_model::update_for_return_superedge): Port to store-based
10120         implementation.
10121         (region_model::update_for_call_summary): Replace
10122         set_to_new_unknown_value with mark_region_as_unknown.
10123         (region_model::get_root_region): Delete.
10124         (region_model::get_stack_region_id): Delete.
10125         (region_model::push_frame): Delete.
10126         (region_model::get_current_frame_id): Delete.
10127         (region_model::get_current_function): Delete.
10128         (region_model::pop_frame): Delete.
10129         (region_model::on_top_level_param): New.
10130         (region_model::get_stack_depth): Delete.
10131         (region_model::get_function_at_depth): Delete.
10132         (region_model::get_globals_region_id): Delete.
10133         (region_model::add_svalue): Delete.
10134         (region_model::replace_svalue): Delete.
10135         (region_model::add_region): Delete.
10136         (region_model::get_svalue): Delete.
10137         (region_model::get_region): Delete.
10138         (make_region_for_type): Delete.
10139         (region_model::add_region_for_type): Delete.
10140         (region_model::on_top_level_param): New.
10141         (class restrict_to_used_svalues): Delete.
10142         (region_model::purge_unused_svalues): Delete.
10143         (region_model::push_frame): New.
10144         (region_model::remap_svalue_ids): Delete.
10145         (region_model::remap_region_ids): Delete.
10146         (region_model::purge_regions): Delete.
10147         (region_model::get_descendents): Delete.
10148         (region_model::delete_region_and_descendents): Delete.
10149         (region_model::poison_any_pointers_to_bad_regions): Delete.
10150         (region_model::can_merge_with_p): Delete.
10151         (region_model::get_current_function): New.
10152         (region_model::get_value_by_name): Delete.
10153         (region_model::convert_byte_offset_to_array_index): Delete.
10154         (region_model::pop_frame): New.
10155         (region_model::get_or_create_mem_ref): Delete.
10156         (region_model::get_stack_depth): New.
10157         (region_model::get_frame_at_index): New.
10158         (region_model::unbind_region_and_descendents): New.
10159         (struct bad_pointer_finder): New.
10160         (region_model::get_or_create_pointer_plus_expr): Delete.
10161         (region_model::poison_any_pointers_to_descendents): New.
10162         (region_model::get_or_create_view): Delete.
10163         (region_model::can_merge_with_p): New.
10164         (region_model::get_fndecl_for_call):  Port from svalue_id to
10165         const svalue *.
10166         (struct append_ssa_names_cb_data): New.
10167         (get_ssa_name_regions_for_current_frame): New.
10168         (region_model::append_ssa_names_cb): New.
10169         (model_merger::dump_to_pp): Add "simple" param.  Drop dumping of
10170         remappings.
10171         (model_merger::dump): Add "simple" param to both overloads.
10172         (model_merger::can_merge_values_p): Delete.
10173         (model_merger::record_regions): Delete.
10174         (model_merger::record_svalues): Delete.
10175         (svalue_id_merger_mapping::svalue_id_merger_mapping): Delete.
10176         (svalue_id_merger_mapping::dump_to_pp): Delete.
10177         (svalue_id_merger_mapping::dump): Delete.
10178         (region_model::create_region_for_heap_alloc): New.
10179         (region_model::create_region_for_alloca): New.
10180         (region_model::record_dynamic_extents): New.
10181         (canonicalization::canonicalization): Delete.
10182         (canonicalization::walk_rid): Delete.
10183         (canonicalization::walk_sid): Delete.
10184         (canonicalization::dump_to_pp): Delete.
10185         (canonicalization::dump): Delete.
10186         (inchash::add): Delete overloads for svalue_id and region_id.
10187         (engine::log_stats): New.
10188         (assert_condition): Add overload comparing svalues.
10189         (assert_dump_eq): Pass "true" for multiline.
10190         (selftest::test_dump): Update for rewrite of region_model.
10191         (selftest::test_dump_2): Rename to...
10192         (selftest::test_struct): ...this.  Provide a region_model_manager
10193         when creating region_model instance.  Remove dump test.  Add
10194         checks for get_offset.
10195         (selftest::test_dump_3): Rename to...
10196         (selftest::test_array_1): ...this.  Provide a region_model_manager
10197         when creating region_model instance.  Remove dump test.
10198         (selftest::test_get_representative_tree): Port from svalue_id to
10199         new API.  Add test coverage for various expressions.
10200         (selftest::test_unique_constants): Provide a region_model_manager
10201         for the region_model.  Add test coverage for comparing const vs
10202         non-const.
10203         (selftest::test_svalue_equality): Delete.
10204         (selftest::test_region_equality): Delete.
10205         (selftest::test_unique_unknowns): New.
10206         (class purge_all_svalue_ids): Delete.
10207         (class purge_one_svalue_id): Delete.
10208         (selftest::test_purging_by_criteria): Delete.
10209         (selftest::test_initial_svalue_folding): New.
10210         (selftest::test_unaryop_svalue_folding): New.
10211         (selftest::test_binop_svalue_folding): New.
10212         (selftest::test_sub_svalue_folding): New.
10213         (selftest::test_purge_unused_svalues): Delete.
10214         (selftest::test_descendent_of_p): New.
10215         (selftest::test_assignment): Provide a region_model_manager for
10216         the region_model.  Drop the dump test.
10217         (selftest::test_compound_assignment): Likewise.
10218         (selftest::test_stack_frames): Port to new implementation.
10219         (selftest::test_get_representative_path_var): Likewise.
10220         (selftest::test_canonicalization_1): Rename to...
10221         (selftest::test_equality_1): ...this.  Port to new API, and add
10222         (selftest::test_canonicalization_2): Provide a
10223         region_model_manager when creating region_model instances.
10224         Remove redundant canicalization.
10225         (selftest::test_canonicalization_3): Provide a
10226         region_model_manager when creating region_model instances.
10227         Remove param from calls to region_model::canonicalize.
10228         (selftest::test_canonicalization_4): Likewise.
10229         (selftest::assert_region_models_merge): Constify
10230         out_merged_svalue.  Port to new API.
10231         (selftest::test_state_merging): Provide a
10232         region_model_manager when creating region_model instances.
10233         Provide a program_point point when merging them.  Replace
10234         set_to_new_unknown_value with usage of placeholder_svalues.
10235         Drop get_value_by_name.  Port from svalue_id to const svalue *.
10236         Add test of heap allocation.
10237         (selftest::test_constraint_merging):  Provide a
10238         region_model_manager when creating region_model instances.
10239         Provide a program_point point when merging them.  Eliminate use
10240         of set_to_new_unknown_value.
10241         (selftest::test_widening_constraints): New.
10242         (selftest::test_iteration_1): New.
10243         (selftest::test_malloc_constraints): Port to store-based
10244         implementation.
10245         (selftest::test_var): New test.
10246         (selftest::test_array_2): New test.
10247         (selftest::test_mem_ref): New test.
10248         (selftest::test_POINTER_PLUS_EXPR_then_MEM_REF): New.
10249         (selftest::test_malloc): New.
10250         (selftest::test_alloca): New.
10251         (selftest::analyzer_region_model_cc_tests): Update for renamings.
10252         Call new functions.
10253         * region-model.h (class path_var): Move to analyzer.h.
10254         (class svalue_id): Delete.
10255         (class region_id): Delete.
10256         (class id_map): Delete.
10257         (svalue_id_map): Delete.
10258         (region_id_map): Delete.
10259         (id_map<T>::id_map): Delete.
10260         (id_map<T>::put): Delete.
10261         (id_map<T>::get_dst_for_src): Delete.
10262         (id_map<T>::get_src_for_dst): Delete.
10263         (id_map<T>::dump_to_pp): Delete.
10264         (id_map<T>::dump): Delete.
10265         (id_map<T>::update): Delete.
10266         (one_way_svalue_id_map): Delete.
10267         (one_way_region_id_map): Delete.
10268         (class region_id_set): Delete.
10269         (class svalue_id_set): Delete.
10270         (struct complexity): New.
10271         (class visitor): New.
10272         (enum svalue_kind): Add SK_SETJMP, SK_INITIAL, SK_UNARYOP,
10273         SK_BINOP, SK_SUB,SK_UNMERGEABLE, SK_PLACEHOLDER, SK_WIDENING,
10274         SK_COMPOUND, and SK_CONJURED.
10275         (svalue::operator==): Delete.
10276         (svalue::operator!=): Delete.
10277         (svalue::clone): Delete.
10278         (svalue::hash): Delete.
10279         (svalue::dump_dot_to_pp): Delete.
10280         (svalue::dump_to_pp): New.
10281         (svalue::dump): New.
10282         (svalue::get_desc): New.
10283         (svalue::dyn_cast_initial_svalue): New.
10284         (svalue::dyn_cast_unaryop_svalue): New.
10285         (svalue::dyn_cast_binop_svalue): New.
10286         (svalue::dyn_cast_sub_svalue): New.
10287         (svalue::dyn_cast_unmergeable_svalue): New.
10288         (svalue::dyn_cast_widening_svalue): New.
10289         (svalue::dyn_cast_compound_svalue): New.
10290         (svalue::dyn_cast_conjured_svalue): New.
10291         (svalue::maybe_undo_cast): New.
10292         (svalue::unwrap_any_unmergeable): New.
10293         (svalue::remap_region_ids): Delete
10294         (svalue::can_merge_p): New.
10295         (svalue::walk_for_canonicalization): Delete
10296         (svalue::get_complexity): New.
10297         (svalue::get_child_sid): Delete
10298         (svalue::accept): New.
10299         (svalue::live_p): New.
10300         (svalue::implicitly_live_p): New.
10301         (svalue::svalue): Add complexity param.
10302         (svalue::add_to_hash): Delete
10303         (svalue::print_details): Delete
10304         (svalue::m_complexity): New field.
10305         (region_svalue::key_t): New struct.
10306         (region_svalue::region_svalue): Port from region_id to
10307         const region_id *.  Add complexity.
10308         (region_svalue::compare_fields): Delete.
10309         (region_svalue::clone): Delete.
10310         (region_svalue::dump_dot_to_pp): Delete.
10311         (region_svalue::get_pointee): Port from region_id to
10312         const region_id *.
10313         (region_svalue::remap_region_ids): Delete.
10314         (region_svalue::merge_values): Delete.
10315         (region_svalue::dump_to_pp): New.
10316         (region_svalue::accept): New.
10317         (region_svalue::walk_for_canonicalization): Delete.
10318         (region_svalue::eval_condition): Make params const.
10319         (region_svalue::add_to_hash): Delete.
10320         (region_svalue::print_details): Delete.
10321         (region_svalue::m_rid): Replace with...
10322         (region_svalue::m_reg): ...this.
10323         (is_a_helper <region_svalue *>::test): Convert to...
10324         (is_a_helper <const region_svalue *>::test): ...this.
10325         (template <> struct default_hash_traits<region_svalue::key_t>):
10326         New.
10327         (constant_svalue::constant_svalue): Add complexity.
10328         (constant_svalue::compare_fields): Delete.
10329         (constant_svalue::clone): Delete.
10330         (constant_svalue::add_to_hash): Delete.
10331         (constant_svalue::dump_to_pp): New.
10332         (constant_svalue::accept): New.
10333         (constant_svalue::implicitly_live_p): New.
10334         (constant_svalue::merge_values): Delete.
10335         (constant_svalue::eval_condition): Make params const.
10336         (constant_svalue::get_child_sid): Delete.
10337         (constant_svalue::print_details): Delete.
10338         (is_a_helper <constant_svalue *>::test): Convert to...
10339         (is_a_helper <const constant_svalue *>::test): ...this.
10340         (class unknown_svalue): Update leading comment.
10341         (unknown_svalue::unknown_svalue): Add complexity.
10342         (unknown_svalue::compare_fields): Delete.
10343         (unknown_svalue::add_to_hash): Delete.
10344         (unknown_svalue::dyn_cast_unknown_svalue): Delete.
10345         (unknown_svalue::print_details): Delete.
10346         (unknown_svalue::dump_to_pp): New.
10347         (unknown_svalue::accept): New.
10348         (poisoned_svalue::key_t): New struct.
10349         (poisoned_svalue::poisoned_svalue): Add complexity.
10350         (poisoned_svalue::compare_fields): Delete.
10351         (poisoned_svalue::clone): Delete.
10352         (poisoned_svalue::add_to_hash): Delete.
10353         (poisoned_svalue::dump_to_pp): New.
10354         (poisoned_svalue::accept): New.
10355         (poisoned_svalue::print_details): Delete.
10356         (is_a_helper <poisoned_svalue *>::test): Convert to...
10357         (is_a_helper <const poisoned_svalue *>::test): ...this.
10358         (template <> struct default_hash_traits<poisoned_svalue::key_t>):
10359         New.
10360         (setjmp_record::add_to_hash): New.
10361         (setjmp_svalue::key_t): New struct.
10362         (setjmp_svalue::compare_fields): Delete.
10363         (setjmp_svalue::clone): Delete.
10364         (setjmp_svalue::add_to_hash): Delete.
10365         (setjmp_svalue::setjmp_svalue): Add complexity.
10366         (setjmp_svalue::dump_to_pp): New.
10367         (setjmp_svalue::accept): New.
10368         (setjmp_svalue::void print_details): Delete.
10369         (is_a_helper <const setjmp_svalue *>::test): New.
10370         (template <> struct default_hash_traits<setjmp_svalue::key_t>): New.
10371         (class initial_svalue : public svalue): New.
10372         (is_a_helper <const initial_svalue *>::test): New.
10373         (class unaryop_svalue): New.
10374         (is_a_helper <const unaryop_svalue *>::test): New.
10375         (template <> struct default_hash_traits<unaryop_svalue::key_t>): New.
10376         (class binop_svalue): New.
10377         (is_a_helper <const binop_svalue *>::test): New.
10378         (template <> struct default_hash_traits<binop_svalue::key_t>): New.
10379         (class sub_svalue): New.
10380         (is_a_helper <const sub_svalue *>::test): New.
10381         (template <> struct default_hash_traits<sub_svalue::key_t>): New.
10382         (class unmergeable_svalue): New.
10383         (is_a_helper <const unmergeable_svalue *>::test): New.
10384         (class placeholder_svalue): New.
10385         (is_a_helper <placeholder_svalue *>::test): New.
10386         (class widening_svalue): New.
10387         (is_a_helper <widening_svalue *>::test): New.
10388         (template <> struct default_hash_traits<widening_svalue::key_t>): New.
10389         (class compound_svalue): New.
10390         (is_a_helper <compound_svalue *>::test): New.
10391         (template <> struct default_hash_traits<compound_svalue::key_t>): New.
10392         (class conjured_svalue): New.
10393         (is_a_helper <conjured_svalue *>::test): New.
10394         (template <> struct default_hash_traits<conjured_svalue::key_t>): New.
10395         (enum region_kind): Delete RK_PRIMITIVE, RK_STRUCT, RK_UNION, and
10396         RK_ARRAY.  Add RK_LABEL, RK_DECL, RK_FIELD, RK_ELEMENT, RK_OFFSET,
10397         RK_CAST, RK_HEAP_ALLOCATED, RK_ALLOCA, RK_STRING, and RK_UNKNOWN.
10398         (region_kind_to_str): Delete.
10399         (region::~region): Move implementation to region.cc.
10400         (region::operator==): Delete.
10401         (region::operator!=): Delete.
10402         (region::clone): Delete.
10403         (region::get_id): New.
10404         (region::cmp_ids): New.
10405         (region::dyn_cast_map_region): Delete.
10406         (region::dyn_cast_array_region): Delete.
10407         (region::region_id get_parent): Delete.
10408         (region::get_parent_region): Convert to a simple accessor.
10409         (region::void set_value): Delete.
10410         (region::svalue_id get_value): Delete.
10411         (region::svalue_id get_value_direct): Delete.
10412         (region::svalue_id get_inherited_child_sid): Delete.
10413         (region::dyn_cast_frame_region): New.
10414         (region::dyn_cast_function_region): New.
10415         (region::dyn_cast_decl_region): New.
10416         (region::dyn_cast_field_region): New.
10417         (region::dyn_cast_element_region): New.
10418         (region::dyn_cast_offset_region): New.
10419         (region::dyn_cast_cast_region): New.
10420         (region::dyn_cast_string_region): New.
10421         (region::accept): New.
10422         (region::get_base_region): New.
10423         (region::base_region_p): New.
10424         (region::descendent_of_p): New.
10425         (region::maybe_get_frame_region): New.
10426         (region::maybe_get_decl): New.
10427         (region::hash): Delete.
10428         (region::rint): Delete.
10429         (region::dump_dot_to_pp): Delete.
10430         (region::get_desc): New.
10431         (region::dump_to_pp): Convert to vfunc, changing signature.
10432         (region::dump_child_label): Delete.
10433         (region::remap_svalue_ids): Delete.
10434         (region::remap_region_ids): Delete.
10435         (region::dump): New.
10436         (region::walk_for_canonicalization): Delete.
10437         (region::non_null_p): Drop region_model param.
10438         (region::add_view): Delete.
10439         (region::get_view): Delete.
10440         (region::get_active_view): Delete.
10441         (region::is_view_p): Delete.
10442         (region::cmp_ptrs): New.
10443         (region::validate): Delete.
10444         (region::get_offset): New.
10445         (region::get_byte_size): New.
10446         (region::get_bit_size): New.
10447         (region::get_subregions_for_binding): New.
10448         (region::region): Add complexity param.  Convert parent from
10449         region_id to const region *.  Drop svalue_id.  Drop copy ctor.
10450         (region::symbolic_for_unknown_ptr_p): New.
10451         (region::add_to_hash): Delete.
10452         (region::print_fields): Delete.
10453         (region::get_complexity): New accessor.
10454         (region::become_active_view): Delete.
10455         (region::deactivate_any_active_view): Delete.
10456         (region::deactivate_view): Delete.
10457         (region::calc_offset): New.
10458         (region::m_parent_rid): Delete.
10459         (region::m_sval_id): Delete.
10460         (region::m_complexity): New.
10461         (region::m_id): New.
10462         (region::m_parent): New.
10463         (region::m_view_rids): Delete.
10464         (region::m_is_view): Delete.
10465         (region::m_active_view_rid): Delete.
10466         (region::m_cached_offset): New.
10467         (is_a_helper <region *>::test): Convert to...
10468         (is_a_helper <const region *>::test): ... this.
10469         (class primitive_region): Delete.
10470         (class space_region): New.
10471         (class map_region): Delete.
10472         (is_a_helper <map_region *>::test): Delete.
10473         (class frame_region): Reimplement.
10474         (template <> struct default_hash_traits<frame_region::key_t>):
10475         New.
10476         (class globals_region): Reimplement.
10477         (is_a_helper <globals_region *>::test): Convert to...
10478         (is_a_helper <const globals_region *>::test): ...this.
10479         (class struct_or_union_region): Delete.
10480         (is_a_helper <struct_or_union_region *>::test): Delete.
10481         (class code_region): Reimplement.
10482         (is_a_helper <const code_region *>::test): New.
10483         (class struct_region): Delete.
10484         (is_a_helper <struct_region *>::test): Delete.
10485         (class function_region): Reimplement.
10486         (is_a_helper <function_region *>::test): Convert to...
10487         (is_a_helper <const function_region *>::test): ...this.
10488         (class union_region): Delete.
10489         (is_a_helper <union_region *>::test): Delete.
10490         (class label_region): New.
10491         (is_a_helper <const label_region *>::test): New.
10492         (class scope_region): Delete.
10493         (class stack_region): Reimplement.
10494         (is_a_helper <stack_region *>::test): Convert to...
10495         (is_a_helper <const stack_region *>::test): ...this.
10496         (class heap_region): Reimplement.
10497         (is_a_helper <heap_region *>::test): Convert to...
10498         (is_a_helper <const heap_region *>::test): ...this.
10499         (class root_region): Reimplement.
10500         (is_a_helper <root_region *>::test): Convert to...
10501         (is_a_helper <const root_region *>::test): ...this.
10502         (class symbolic_region): Reimplement.
10503         (is_a_helper <const symbolic_region *>::test): New.
10504         (template <> struct default_hash_traits<symbolic_region::key_t>):
10505         New.
10506         (class decl_region): New.
10507         (is_a_helper <const decl_region *>::test): New.
10508         (class field_region): New.
10509         (template <> struct default_hash_traits<field_region::key_t>): New.
10510         (class array_region): Delete.
10511         (class element_region): New.
10512         (is_a_helper <array_region *>::test): Delete.
10513         (is_a_helper <const element_region *>::test): New.
10514         (template <> struct default_hash_traits<element_region::key_t>):
10515         New.
10516         (class offset_region): New.
10517         (is_a_helper <const offset_region *>::test): New.
10518         (template <> struct default_hash_traits<offset_region::key_t>):
10519         New.
10520         (class cast_region): New.
10521         (is_a_helper <const cast_region *>::test): New.
10522         (template <> struct default_hash_traits<cast_region::key_t>): New.
10523         (class heap_allocated_region): New.
10524         (class alloca_region): New.
10525         (class string_region): New.
10526         (is_a_helper <const string_region *>::test): New.
10527         (class unknown_region): New.
10528         (class region_model_manager): New.
10529         (struct append_ssa_names_cb_data): New.
10530         (class call_details): New.
10531         (region_model::region_model): Add region_model_manager param.
10532         (region_model::print_svalue): Delete.
10533         (region_model::dump_dot_to_pp): Delete.
10534         (region_model::dump_dot_to_file): Delete.
10535         (region_model::dump_dot): Delete.
10536         (region_model::dump_to_pp): Drop summarize param in favor of
10537         simple and multiline.
10538         (region_model::dump): Likewise.
10539         (region_model::summarize_to_pp): Delete.
10540         (region_model::summarize): Delete.
10541         (region_model::void canonicalize): Drop ctxt param.
10542         (region_model::void check_for_poison): Delete.
10543         (region_model::get_gassign_result): New.
10544         (region_model::impl_call_alloca): New.
10545         (region_model::impl_call_analyzer_describe): New.
10546         (region_model::impl_call_analyzer_eval): New.
10547         (region_model::impl_call_builtin_expect): New.
10548         (region_model::impl_call_calloc): New.
10549         (region_model::impl_call_free): New.
10550         (region_model::impl_call_malloc): New.
10551         (region_model::impl_call_memset): New.
10552         (region_model::impl_call_strlen): New.
10553         (region_model::get_reachable_svalues): New.
10554         (region_model::handle_phi): Drop is_back_edge param.
10555         (region_model::region_id get_root_rid): Delete.
10556         (region_model::root_region *get_root_region): Delete.
10557         (region_model::region_id get_stack_region_id): Delete.
10558         (region_model::push_frame): Convert from region_id and svalue_id
10559         to const region * and const svalue *.
10560         (region_model::get_current_frame_id): Replace with...
10561         (region_model::get_current_frame): ...this.
10562         (region_model::pop_frame): Convert from region_id to
10563         const region *.  Drop purge and stats param.  Add out_result.
10564         (region_model::function *get_function_at_depth): Delete.
10565         (region_model::get_globals_region_id): Delete.
10566         (region_model::add_svalue): Delete.
10567         (region_model::replace_svalue): Delete.
10568         (region_model::add_region): Delete.
10569         (region_model::add_region_for_type): Delete.
10570         (region_model::get_svalue): Delete.
10571         (region_model::get_region): Delete.
10572         (region_model::get_lvalue): Convert from region_id to
10573         const region *.
10574         (region_model::get_rvalue): Convert from svalue_id to
10575         const svalue *.
10576         (region_model::get_or_create_ptr_svalue): Delete.
10577         (region_model::get_or_create_constant_svalue): Delete.
10578         (region_model::get_svalue_for_fndecl): Delete.
10579         (region_model::get_svalue_for_label): Delete.
10580         (region_model::get_region_for_fndecl): Delete.
10581         (region_model::get_region_for_label): Delete.
10582         (region_model::get_frame_at_index (int index) const;): New.
10583         (region_model::maybe_cast): Delete.
10584         (region_model::maybe_cast_1): Delete.
10585         (region_model::get_field_region): Delete.
10586         (region_model::id deref_rvalue): Convert from region_id and
10587         svalue_id to const region * and const svalue *.  Drop overload,
10588         passing in both a tree and an svalue.
10589         (region_model::set_value): Convert from region_id and svalue_id to
10590         const region * and const svalue *.
10591         (region_model::set_to_new_unknown_value): Delete.
10592         (region_model::clobber_region (const region *reg);): New.
10593         (region_model::purge_region (const region *reg);): New.
10594         (region_model::zero_fill_region (const region *reg);): New.
10595         (region_model::mark_region_as_unknown (const region *reg);): New.
10596         (region_model::copy_region): Convert from region_id to
10597         const region *.
10598         (region_model::eval_condition): Convert from svalue_id to
10599         const svalue *.
10600         (region_model::eval_condition_without_cm): Likewise.
10601         (region_model::compare_initial_and_pointer): New.
10602         (region_model:maybe_get_constant): Delete.
10603         (region_model::add_new_malloc_region): Delete.
10604         (region_model::get_representative_tree): Convert from svalue_id to
10605         const svalue *.
10606         (region_model::get_representative_path_var): Delete decl taking a
10607         region_id in favor of two decls, for svalue vs region, with an
10608         svalue_set to ensure termination.
10609         (region_model::get_path_vars_for_svalue): Delete.
10610         (region_model::create_region_for_heap_alloc): New.
10611         (region_model::create_region_for_alloca): New.
10612         (region_model::purge_unused_svalues): Delete.
10613         (region_model::remap_svalue_ids): Delete.
10614         (region_model::remap_region_ids): Delete.
10615         (region_model::purge_regions): Delete.
10616         (region_model::get_num_svalues): Delete.
10617         (region_model::get_num_regions): Delete.
10618         (region_model::get_descendents): Delete.
10619         (region_model::get_store): New.
10620         (region_model::delete_region_and_descendents): Delete.
10621         (region_model::get_manager): New.
10622         (region_model::unbind_region_and_descendents): New.
10623         (region_model::can_merge_with_p): Add point param.  Drop
10624         svalue_id_merger_mapping.
10625         (region_model::get_value_by_name): Delete.
10626         (region_model::convert_byte_offset_to_array_index): Delete.
10627         (region_model::get_or_create_mem_ref): Delete.
10628         (region_model::get_or_create_pointer_plus_expr): Delete.
10629         (region_model::get_or_create_view): Delete.
10630         (region_model::get_lvalue_1): Convert from region_id to
10631         const region *.
10632         (region_model::get_rvalue_1): Convert from svalue_id to
10633         const svalue *.
10634         (region_model::get_ssa_name_regions_for_current_frame): New.
10635         (region_model::append_ssa_names_cb): New.
10636         (region_model::get_store_value): New.
10637         (region_model::copy_struct_region): Delete.
10638         (region_model::copy_union_region): Delete.
10639         (region_model::copy_array_region): Delete.
10640         (region_model::region_exists_p): New.
10641         (region_model::make_region_for_unexpected_tree_code): Delete.
10642         (region_model::loop_replay_fixup): New.
10643         (region_model::poison_any_pointers_to_bad_regions): Delete.
10644         (region_model::poison_any_pointers_to_descendents): New.
10645         (region_model::dump_summary_of_rep_path_vars): Delete.
10646         (region_model::on_top_level_param): New.
10647         (region_model::record_dynamic_extents): New.
10648         (region_model::m_mgr;): New.
10649         (region_model::m_store;): New.
10650         (region_model::m_svalues;): Delete.
10651         (region_model::m_regions;): Delete.
10652         (region_model::m_root_rid;): Delete.
10653         (region_model::m_current_frame;): New.
10654         (region_model_context::remap_svalue_ids): Delete.
10655         (region_model_context::can_purge_p): Delete.
10656         (region_model_context::on_svalue_leak): New.
10657         (region_model_context::on_svalue_purge): Delete.
10658         (region_model_context::on_liveness_change): New.
10659         (region_model_context::on_inherited_svalue): Delete.
10660         (region_model_context::on_cast): Delete.
10661         (region_model_context::on_unknown_change): Convert from svalue_id to
10662         const svalue * and add is_mutable.
10663         (class noop_region_model_context): Update for region_model_context
10664         changes.
10665         (model_merger::model_merger): Add program_point.  Drop
10666         svalue_id_merger_mapping.
10667         (model_merger::dump_to_pp): Add "simple" param.
10668         (model_merger::dump): Likewise.
10669         (model_merger::get_region_a): Delete.
10670         (model_merger::get_region_b): Delete.
10671         (model_merger::can_merge_values_p): Delete.
10672         (model_merger::record_regions): Delete.
10673         (model_merger::record_svalues): Delete.
10674         (model_merger::m_point): New field.
10675         (model_merger::m_map_regions_from_a_to_m): Delete.
10676         (model_merger::m_map_regions_from_b_to_m): Delete.
10677         (model_merger::m_sid_mapping): Delete.
10678         (struct svalue_id_merger_mapping): Delete.
10679         (class engine): New.
10680         (struct canonicalization): Delete.
10681         (inchash::add): Delete decls for hashing svalue_id and region_id.
10682         (test_region_model_context::on_unexpected_tree_code): Require t to
10683         be non-NULL.
10684         (selftest::assert_condition): Add overload comparing a pair of
10685         const svalue *.
10686         * sm-file.cc: Include "tristate.h", "selftest.h",
10687         "analyzer/call-string.h", "analyzer/program-point.h",
10688         "analyzer/store.h", and "analyzer/region-model.h".
10689         (fileptr_state_machine::get_default_state): New.
10690         (fileptr_state_machine::on_stmt): Remove calls to
10691         get_readable_tree in favor of get_diagnostic_tree.
10692         * sm-malloc.cc: Include "tristate.h", "selftest.h",
10693         "analyzer/call-string.h", "analyzer/program-point.h",
10694         "analyzer/store.h", and "analyzer/region-model.h".
10695         (malloc_state_machine::get_default_state): New.
10696         (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New.
10697         (malloc_diagnostic::describe_state_change): Handle change.m_expr
10698         being NULL.
10699         (null_arg::emit): Avoid printing "NULL '0'".
10700         (null_arg::describe_final_event): Avoid printing "(0) NULL".
10701         (malloc_leak::emit): Handle m_arg being NULL.
10702         (malloc_leak::describe_final_event): Handle ev.m_expr being NULL.
10703         (malloc_state_machine::on_stmt): Don't call get_readable_tree.
10704         Call get_diagnostic_tree when creating pending diagnostics.
10705         Update for is_zero_assignment becoming a member function of
10706         sm_ctxt.
10707         Don't transition to m_non_heap for ADDR_EXPR(MEM_REF()).
10708         (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New
10709         vfunc implementation.
10710         * sm-sensitive.cc (sensitive_state_machine::warn_for_any_exposure): Call
10711         get_diagnostic_tree and pass the result to warn_for_state.
10712         * sm-signal.cc: Move includes of "analyzer/call-string.h" and
10713         "analyzer/program-point.h" to before "analyzer/region-model.h",
10714         and also include "analyzer/store.h" before it.
10715         (signal_unsafe_call::describe_state_change): Use
10716         get_dest_function to get handler.
10717         (update_model_for_signal_handler): Pass manager to region_model
10718         ctor.
10719         (register_signal_handler::impl_transition): Update for changes to
10720         get_or_create_node and add_edge.
10721         * sm-taint.cc (taint_state_machine::on_stmt): Remove calls to
10722         get_readable_tree, replacing them when calling warn_for_state with
10723         calls to get_diagnostic_tree.
10724         * sm.cc (is_zero_assignment): Delete.
10725         (any_pointer_p): Move to within namespace ana.
10726         * sm.h (is_zero_assignment): Remove decl.
10727         (any_pointer_p): Move decl to within namespace ana.
10728         (state_machine::get_default_state): New vfunc.
10729         (state_machine::reset_when_passed_to_unknown_fn_p): New vfunc.
10730         (sm_context::get_readable_tree): Rename to...
10731         (sm_context::get_diagnostic_tree): ...this.
10732         (sm_context::is_zero_assignment): New vfunc.
10733         * store.cc: New file.
10734         * store.h: New file.
10735         * svalue.cc: New file.
10737 2020-05-22  Mark Wielaard  <mark@klomp.org>
10739         * sm-signal.cc(signal_unsafe_call::emit): Possibly add
10740         gcc_rich_location note for replacement.
10741         (signal_unsafe_call::get_replacement_fn): New private function.
10742         (get_async_signal_unsafe_fns): Add "exit".
10744 2020-04-28  David Malcolm  <dmalcolm@redhat.com>
10746         PR analyzer/94816
10747         * engine.cc (impl_region_model_context::on_unexpected_tree_code):
10748         Handle NULL tree.
10749         * region-model.cc (region_model::add_region_for_type): Handle
10750         NULL type.
10751         * region-model.h
10752         (test_region_model_context::on_unexpected_tree_code): Handle NULL
10753         tree.
10755 2020-04-28  David Malcolm  <dmalcolm@redhat.com>
10757         PR analyzer/94447
10758         PR analyzer/94639
10759         PR analyzer/94732
10760         PR analyzer/94754
10761         * analyzer.opt (Wanalyzer-use-of-uninitialized-value): Delete.
10762         * program-state.cc (selftest::test_program_state_dumping): Update
10763         expected dump result for removal of "uninit".
10764         * region-model.cc (poison_kind_to_str): Delete POISON_KIND_UNINIT
10765         case.
10766         (root_region::ensure_stack_region): Initialize stack with null
10767         svalue_id rather than with a typeless POISON_KIND_UNINIT value.
10768         (root_region::ensure_heap_region): Likewise for the heap.
10769         (region_model::dump_summary_of_rep_path_vars): Remove
10770         summarization of uninit values.
10771         (region_model::validate): Remove check that the stack has a
10772         POISON_KIND_UNINIT value.
10773         (poisoned_value_diagnostic::emit): Remove POISON_KIND_UNINIT
10774         case.
10775         (poisoned_value_diagnostic::describe_final_event): Likewise.
10776         (selftest::test_dump): Update expected dump result for removal of
10777         "uninit".
10778         (selftest::test_svalue_equality): Remove "uninit" and "freed".
10779         * region-model.h (enum poison_kind): Remove POISON_KIND_UNINIT.
10781 2020-04-01  David Malcolm  <dmalcolm@redhat.com>
10783         PR analyzer/94378
10784         * checker-path.cc: Include "bitmap.h".
10785         * constraint-manager.cc: Likewise.
10786         * diagnostic-manager.cc: Likewise.
10787         * engine.cc: Likewise.
10788         (exploded_node::detect_leaks): Pass null region_id to pop_frame.
10789         * program-point.cc: Include "bitmap.h".
10790         * program-state.cc: Likewise.
10791         * region-model.cc (id_set<region_id>::id_set): Convert to...
10792         (region_id_set::region_id_set): ...this.
10793         (svalue_id_set::svalue_id_set): New ctor.
10794         (region_model::copy_region): New function.
10795         (region_model::copy_struct_region): New function.
10796         (region_model::copy_union_region): New function.
10797         (region_model::copy_array_region): New function.
10798         (stack_region::pop_frame): Drop return value.  Add
10799         "result_dst_rid" param; if it is non-null, use copy_region to copy
10800         the result to it.  Rather than capture and pass a single "known
10801         used" return value to be used by purge_unused_values, instead
10802         gather and pass a set of known used return values.
10803         (root_region::pop_frame): Drop return value.  Add "result_dst_rid"
10804         param.
10805         (region_model::on_assignment): Use copy_region.
10806         (region_model::on_return): Likewise for the result.
10807         (region_model::on_longjmp): Pass null for pop_frame's
10808         result_dst_rid.
10809         (region_model::update_for_return_superedge): Pass the region for the
10810         return value of the call, if any, to pop_frame, rather than setting
10811         the lvalue for the lhs of the result.
10812         (region_model::pop_frame): Drop return value.  Add
10813         "result_dst_rid" param.
10814         (region_model::purge_unused_svalues): Convert third param from an
10815         svalue_id * to an svalue_id_set *, updating the initial populating
10816         of the "used" bitmap accordingly.  Don't remap it when done.
10817         (struct selftest::coord_test): New selftest fixture, extracted from...
10818         (selftest::test_dump_2): ...here.
10819         (selftest::test_compound_assignment): New selftest.
10820         (selftest::test_stack_frames): Pass null to new param of pop_frame.
10821         (selftest::analyzer_region_model_cc_tests): Call the new selftest.
10822         * region-model.h (class id_set): Delete template.
10823         (class region_id_set): Reimplement, using old id_set implementation.
10824         (class svalue_id_set): Likewise.  Convert from auto_sbitmap to
10825         auto_bitmap.
10826         (region::get_active_view): New accessor.
10827         (stack_region::pop_frame): Drop return value.  Add
10828         "result_dst_rid" param.
10829         (root_region::pop_frame): Likewise.
10830         (region_model::pop_frame): Likewise.
10831         (region_model::copy_region): New decl.
10832         (region_model::purge_unused_svalues): Convert third param from an
10833         svalue_id * to an svalue_id_set *.
10834         (region_model::copy_struct_region): New decl.
10835         (region_model::copy_union_region): New decl.
10836         (region_model::copy_array_region): New decl.
10838 2020-03-27  David Malcolm  <dmalcolm@redhat.com>
10840         * program-state.cc (selftest::test_program_state_dumping): Update
10841         expected dump to include symbolic_region's possibly_null field.
10842         * region-model.cc (symbolic_region::print_fields): New vfunc
10843         implementation.
10844         (region_model::add_constraint): Clear m_possibly_null from
10845         symbolic_regions now known to be non-NULL.
10846         (selftest::test_malloc_constraints): New selftest.
10847         (selftest::analyzer_region_model_cc_tests): Call it.
10848         * region-model.h (region::dyn_cast_symbolic_region): Add non-const
10849         overload.
10850         (symbolic_region::dyn_cast_symbolic_region): Implement it.
10851         (symbolic_region::print_fields): New vfunc override decl.
10853 2020-03-27  David Malcolm  <dmalcolm@redhat.com>
10855         * analyzer.h (class feasibility_problem): New forward decl.
10856         * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
10857         Initialize new fields m_status, m_epath_length, and m_problem.
10858         (saved_diagnostic::~saved_diagnostic): Delete m_problem.
10859         (dedupe_candidate::dedupe_candidate): Convert "sd" param from a
10860         const ref to a mutable ptr.
10861         (dedupe_winners::add): Convert "sd" param from a const ref to a
10862         mutable ptr.  Record the length of the exploded_path.  Record the
10863         feasibility/infeasibility of sd into sd, capturing a
10864         feasibility_problem when feasible_p fails, and storing it in sd.
10865         (diagnostic_manager::emit_saved_diagnostics): Update for pass by
10866         ptr rather than by const ref.
10867         * diagnostic-manager.h (class saved_diagnostic): Add new enum
10868         status.  Add fields m_status, m_epath_length and m_problem.
10869         (saved_diagnostic::set_feasible): New member function.
10870         (saved_diagnostic::set_infeasible): New member function.
10871         (saved_diagnostic::get_feasibility_problem): New accessor.
10872         (saved_diagnostic::get_status): New accessor.
10873         (saved_diagnostic::set_epath_length): New member function.
10874         (saved_diagnostic::get_epath_length): New accessor.
10875         * engine.cc: Include "gimple-pretty-print.h".
10876         (exploded_path::feasible_p): Add OUT param and, if non-NULL, write
10877         a new feasibility_problem to it on failure.
10878         (viz_callgraph_node::dump_dot): Convert begin_tr calls to
10879         begin_trtd.  Convert end_tr calls to end_tdtr.
10880         (class exploded_graph_annotator): New subclass of dot_annotator.
10881         (impl_run_checkers): Add a second -fdump-analyzer-supergraph dump
10882         after the analysis runs, using exploded_graph_annotator. dumping
10883         to DUMP_BASE_NAME.supergraph-eg.dot.
10884         * exploded-graph.h (exploded_node::get_dot_fillcolor): Make
10885         public.
10886         (exploded_path::feasible_p): Add OUT param.
10887         (class feasibility_problem): New class.
10888         * state-purge.cc (state_purge_annotator::add_node_annotations):
10889         Return a bool, add a "within_table" param.
10890         (print_vec_of_names): Convert begin_tr calls to begin_trtd.
10891         Convert end_tr calls to end_tdtr.
10892         (state_purge_annotator::add_stmt_annotations): Add "within_row"
10893         param.
10894         * state-purge.h ((state_purge_annotator::add_node_annotations):
10895         Return a bool, add a "within_table" param.
10896         (state_purge_annotator::add_stmt_annotations): Add "within_row"
10897         param.
10898         * supergraph.cc (supernode::dump_dot): Call add_node_annotations
10899         twice: as before, passing false for "within_table", then again
10900         with true when within the TABLE element.  Convert some begin_tr
10901         calls to begin_trtd, and some end_tr calls to end_tdtr.
10902         Repeat each add_stmt_annotations call, distinguishing between
10903         calls that add TRs and those that add TDs to an existing TR.
10904         Add a call to add_after_node_annotations.
10905         * supergraph.h (dot_annotator::add_node_annotations): Add a
10906         "within_table" param.
10907         (dot_annotator::add_stmt_annotations): Add a "within_row" param.
10908         (dot_annotator::add_after_node_annotations): New vfunc.
10910 2020-03-27  David Malcolm  <dmalcolm@redhat.com>
10912         * diagnostic-manager.cc (dedupe_winners::add): Show the
10913         exploded_node index in the log messages.
10914         (diagnostic_manager::emit_saved_diagnostics): Log a summary of
10915         m_saved_diagnostics at entry.
10917 2020-03-27  David Malcolm  <dmalcolm@redhat.com>
10919         * supergraph.cc (superedge::dump): Add space before description;
10920         move newline to non-pretty_printer overload.
10922 2020-03-18  David Malcolm  <dmalcolm@redhat.com>
10924         * region-model.cc: Include "stor-layout.h".
10925         (region_model::dump_to_pp): Rather than calling
10926         dump_summary_of_map on each of the current frame and the globals,
10927         instead get a vec of representative path_vars for all regions,
10928         and then dump a summary of all of them.
10929         (region_model::dump_summary_of_map): Delete, rewriting into...
10930         (region_model::dump_summary_of_rep_path_vars): ...this new
10931         function, working on a vec of path_vars.
10932         (region_model::set_value): New overload.
10933         (region_model::get_representative_path_var): Rename
10934         "parent_region" local to "parent_reg" and consolidate with other
10935         local.  Guard test for grandparent being stack on parent_reg being
10936         non-NULL.  Move handling for parent being an array_region to
10937         within guard for parent_reg being non-NULL.
10938         (selftest::make_test_compound_type): New function.
10939         (selftest::test_dump_2): New selftest.
10940         (selftest::test_dump_3): New selftest.
10941         (selftest::test_stack_frames): Update expected output from
10942         simplified dump to show "a" and "b" from parent frame and "y" in
10943         child frame.
10944         (selftest::analyzer_region_model_cc_tests): Call test_dump_2 and
10945         test_dump_3.
10946         * region-model.h (region_model::set_value): New overload decl.
10947         (region_model::dump_summary_of_map): Delete.
10948         (region_model::dump_summary_of_rep_path_vars): New.
10950 2020-03-18  David Malcolm  <dmalcolm@redhat.com>
10952         * region-model.h (class noop_region_model_context): New subclass
10953         of region_model_context.
10954         (class tentative_region_model_context): Inherit from
10955         noop_region_model_context rather than from region_model_context;
10956         drop redundant vfunc implementations.
10957         (class test_region_model_context): Likewise.
10959 2020-03-18  David Malcolm  <dmalcolm@redhat.com>
10961         * engine.cc (exploded_node::exploded_node): Move implementation
10962         here from header; accept point_and_state by const reference rather
10963         than by value.
10964         * exploded-graph.h (exploded_node::exploded_node): Pass
10965         point_and_state by const reference rather than by value.  Move
10966         body to engine.cc.
10968 2020-03-18  Jakub Jelinek  <jakub@redhat.com>
10970         * sm-malloc.cc (malloc_state_machine::on_stmt): Fix up duplicated word
10971         issue in a comment.
10972         * region-model.cc (region_model::make_region_for_unexpected_tree_code,
10973         region_model::delete_region_and_descendents): Likewise.
10974         * engine.cc (class exploded_cluster): Likewise.
10975         * diagnostic-manager.cc (class path_builder): Likewise.
10977 2020-03-13  David Malcolm  <dmalcolm@redhat.com>
10979         PR analyzer/94099
10980         PR analyzer/94105
10981         * diagnostic-manager.cc (for_each_state_change): Bulletproof
10982         against errors in get_rvalue by passing a
10983         tentative_region_model_context and rejecting if there's an error.
10984         * region-model.cc (region_model::get_lvalue_1): When handling
10985         ARRAY_REF, handle results of error-handling.  Handle NOP_EXPR.
10987 2020-03-06  David Malcolm  <dmalcolm@redhat.com>
10989         * analyzer.h (class array_region): New forward decl.
10990         * program-state.cc (selftest::test_program_state_dumping_2): New.
10991         (selftest::analyzer_program_state_cc_tests): Call it.
10992         * region-model.cc (array_region::constant_from_key): New.
10993         (region_model::get_representative_tree): Handle region_svalue by
10994         generating an ADDR_EXPR.
10995         (region_model::get_representative_path_var): In view handling,
10996         remove erroneous TREE_TYPE when determining the type of the tree.
10997         Handle array regions and STRING_CST.
10998         (selftest::assert_dump_tree_eq): New.
10999         (ASSERT_DUMP_TREE_EQ): New macro.
11000         (selftest::test_get_representative_tree): New selftest.
11001         (selftest::analyzer_region_model_cc_tests): Call it.
11002         * region-model.h (region::dyn_cast_array_region): New vfunc.
11003         (array_region::dyn_cast_array_region): New vfunc implementation.
11004         (array_region::constant_from_key): New decl.
11006 2020-03-06  David Malcolm  <dmalcolm@redhat.com>
11008         * analyzer.h (dump_quoted_tree): New decl.
11009         * engine.cc (exploded_node::dump_dot): Pass region model to
11010         sm_state_map::print.
11011         * program-state.cc: Include diagnostic-core.h.
11012         (sm_state_map::print): Add "model" param and use it to print
11013         representative trees.  Only print origin information if non-null.
11014         (sm_state_map::dump): Pass NULL for model to print call.
11015         (program_state::print): Pass region model to sm_state_map::print.
11016         (program_state::dump_to_pp): Use spaces rather than newlines when
11017         summarizing.  Pass region_model to sm_state_map::print.
11018         (ana::selftest::assert_dump_eq): New function.
11019         (ASSERT_DUMP_EQ): New macro.
11020         (ana::selftest::test_program_state_dumping): New function.
11021         (ana::selftest::analyzer_program_state_cc_tests): Call it.
11022         * program-state.h (program_state::print): Add model param.
11023         * region-model.cc (dump_quoted_tree): New function.
11024         (map_region::print_fields): Use dump_quoted_tree rather than
11025         %qE to avoid lang-dependent output.
11026         (map_region::dump_child_label): Likewise.
11027         (region_model::dump_summary_of_map): For SK_REGION, when
11028         get_representative_path_var fails, print the region id rather than
11029         erroneously printing NULL.
11030         * sm.cc (state_machine::get_state_by_name): New function.
11031         * sm.h (state_machine::get_state_by_name): New decl.
11033 2020-03-04  David Malcolm  <dmalcolm@redhat.com>
11035         * region-model.cc (region::validate): Convert model param from ptr
11036         to reference.  Update comment to reflect that it's now a vfunc.
11037         (map_region::validate): New vfunc implementation.
11038         (array_region::validate): New vfunc implementation.
11039         (stack_region::validate): New vfunc implementation.
11040         (root_region::validate): New vfunc implementation.
11041         (region_model::validate): Pass a reference rather than a pointer
11042         to the region::validate vfunc.
11043         * region-model.h (region::validate): Make virtual.  Convert model
11044         param from ptr to reference.
11045         (map_region::validate): New vfunc decl.
11046         (array_region::validate): New vfunc decl.
11047         (stack_region::validate): New vfunc decl.
11048         (root_region::validate): New vfunc decl.
11050 2020-03-04  David Malcolm  <dmalcolm@redhat.com>
11052         PR analyzer/93993
11053         * region-model.cc (region_model::on_call_pre): Handle
11054         BUILT_IN_EXPECT and its variants.
11055         (region_model::add_any_constraints_from_ssa_def_stmt): Split out
11056         gassign handling into add_any_constraints_from_gassign; add gcall
11057         handling.
11058         (region_model::add_any_constraints_from_gassign): New function,
11059         based on the above.  Add handling for NOP_EXPR.
11060         (region_model::add_any_constraints_from_gcall): New function.
11061         (region_model::get_representative_path_var): Handle views.
11062         * region-model.h
11063         (region_model::add_any_constraints_from_ssa_def_stmt): New decl.
11064         (region_model::add_any_constraints_from_gassign): New decl.
11066 2020-03-04  David Malcolm  <dmalcolm@redhat.com>
11068         PR analyzer/93993
11069         * checker-path.h (state_change_event::get_lvalue): Add ctxt param
11070         and pass it to region_model::get_value call.
11071         * diagnostic-manager.cc (get_any_origin): Pass a
11072         tentative_region_model_context to the calls to get_lvalue and reject
11073         the comparison if errors occur.
11074         (can_be_expr_of_interest_p): New function.
11075         (diagnostic_manager::prune_for_sm_diagnostic): Replace checks for
11076         CONSTANT_CLASS_P with calls to update_for_unsuitable_sm_exprs.
11077         Pass a tentative_region_model_context to the calls to
11078         state_change_event::get_lvalue and reject the comparison if errors
11079         occur.
11080         (diagnostic_manager::update_for_unsuitable_sm_exprs): New.
11081         * diagnostic-manager.h
11082         (diagnostic_manager::update_for_unsuitable_sm_exprs): New decl.
11083         * region-model.h (class tentative_region_model_context): New class.
11085 2020-03-04  David Malcolm  <dmalcolm@redhat.com>
11087         * engine.cc (worklist::worklist): Remove unused field m_eg.
11088         (class viz_callgraph_edge): Remove unused field m_call_sedge.
11089         (class viz_callgraph): Remove unused field m_sg.
11090         * exploded-graph.h (worklist::::m_eg): Remove unused field.
11092 2020-03-02  David Malcolm  <dmalcolm@redhat.com>
11094         * analyzer.opt (fanalyzer-show-duplicate-count): New option.
11095         * diagnostic-manager.cc
11096         (diagnostic_manager::emit_saved_diagnostic): Use the above to
11097         guard the printing of the duplicate count.
11099 2020-03-02  David Malcolm  <dmalcolm@redhat.com>
11101         PR analyzer/93959
11102         * analyzer.cc (is_std_function_p): New function.
11103         (is_std_named_call_p): New functions.
11104         * analyzer.h (is_std_named_call_p): New decl.
11105         * sm-malloc.cc (malloc_state_machine::on_stmt): Check for "std::"
11106         variants when checking for malloc, calloc and free.
11108 2020-02-26  David Malcolm  <dmalcolm@redhat.com>
11110         PR analyzer/93950
11111         * diagnostic-manager.cc
11112         (diagnostic_manager::prune_for_sm_diagnostic): Assert that var is
11113         either NULL or not a constant.  When updating var, bulletproof
11114         against constant values.
11116 2020-02-26  David Malcolm  <dmalcolm@redhat.com>
11118         PR analyzer/93947
11119         * region-model.cc (region_model::get_fndecl_for_call): Gracefully
11120         fail for fn_decls that don't have a cgraph_node.
11122 2020-02-26  David Malcolm  <dmalcolm@redhat.com>
11124         * bar-chart.cc: New file.
11125         * bar-chart.h: New file.
11126         * engine.cc: Include "analyzer/bar-chart.h".
11127         (stats::log): Only log the m_num_nodes kinds that are non-zero.
11128         (stats::dump): Likewise when dumping.
11129         (stats::get_total_enodes): New.
11130         (exploded_graph::get_or_create_node): Increment the per-point-data
11131         m_excess_enodes when hitting the per-program-point limit on
11132         enodes.
11133         (exploded_graph::print_bar_charts): New.
11134         (exploded_graph::log_stats): Log the number of unprocessed enodes
11135         in the worklist.  Call print_bar_charts.
11136         (exploded_graph::dump_stats): Print the number of unprocessed
11137         enodes in the worklist.
11138         * exploded-graph.h (stats::get_total_enodes): New decl.
11139         (struct per_program_point_data): Add field m_excess_enodes.
11140         (exploded_graph::print_bar_charts): New decl.
11141         * supergraph.cc (superedge::dump): New.
11142         (superedge::dump): New.
11143         * supergraph.h (supernode::get_function): New.
11144         (superedge::dump): New decl.
11145         (superedge::dump): New decl.
11147 2020-02-24  David Malcolm  <dmalcolm@redhat.com>
11149         * engine.cc (exploded_graph::get_or_create_node): Dump the
11150         program_state to the pp, rather than to stderr.
11152 2020-02-24  David Malcolm  <dmalcolm@redhat.com>
11154         PR analyzer/93032
11155         * sm.cc (make_checkers): Require the "taint" checker to be
11156         explicitly enabled.
11158 2020-02-24  David Malcolm  <dmalcolm@redhat.com>
11160         PR analyzer/93899
11161         * engine.cc
11162         (impl_region_model_context::impl_region_model_context): Add logger
11163         param.
11164         * engine.cc (exploded_graph::add_function_entry): Create an
11165         impl_region_model_context and pass it to the push_frame call.
11166         Bail if the resulting state is invalid.
11167         (exploded_graph::build_initial_worklist): Likewise.
11168         (exploded_graph::build_initial_worklist): Handle the case where
11169         add_function_entry fails.
11170         * exploded-graph.h
11171         (impl_region_model_context::impl_region_model_context): Add logger
11172         param.
11173         * region-model.cc (map_region::get_or_create): Add ctxt param and
11174         pass it to add_region_for_type.
11175         (map_region::can_merge_p): Pass NULL as a ctxt to call to
11176         get_or_create.
11177         (array_region::get_element): Pass ctxt to call to get_or_create.
11178         (array_region::get_or_create): Add ctxt param and pass it to
11179         add_region_for_type.
11180         (root_region::push_frame): Pass ctxt to get_or_create calls.
11181         (region_model::get_lvalue_1): Likewise.
11182         (region_model::make_region_for_unexpected_tree_code): Assert that
11183         ctxt is non-NULL.
11184         (region_model::get_rvalue_1): Pass ctxt to get_svalue_for_fndecl
11185         and get_svalue_for_label calls.
11186         (region_model::get_svalue_for_fndecl): Add ctxt param and pass it
11187         to get_region_for_fndecl.
11188         (region_model::get_region_for_fndecl): Add ctxt param and pass it
11189         to get_or_create.
11190         (region_model::get_svalue_for_label): Add ctxt param and pass it
11191         to get_region_for_label.
11192         (region_model::get_region_for_label): Add ctxt param and pass it
11193         to get_region_for_fndecl and get_or_create.
11194         (region_model::get_field_region): Add ctxt param and pass it to
11195         get_or_create_view and get_or_create.
11196         (make_region_for_type): Replace gcc_unreachable with return NULL.
11197         (region_model::add_region_for_type): Add ctxt param.  Handle a
11198         return of NULL from make_region_for_type by calling
11199         make_region_for_unexpected_tree_code.
11200         (region_model::get_or_create_mem_ref): Pass ctxt to calls to
11201         get_or_create_view.
11202         (region_model::get_or_create_view): Add ctxt param and pass it to
11203         add_region_for_type.
11204         (selftest::test_state_merging): Pass ctxt to get_or_create_view.
11205         * region-model.h (region_model::get_or_create): Add ctxt param.
11206         (region_model::add_region_for_type): Likewise.
11207         (region_model::get_svalue_for_fndecl): Likewise.
11208         (region_model::get_svalue_for_label): Likewise.
11209         (region_model::get_region_for_fndecl): Likewise.
11210         (region_model::get_region_for_label): Likewise.
11211         (region_model::get_field_region): Likewise.
11212         (region_model::get_or_create_view): Likewise.
11214 2020-02-24  David Malcolm  <dmalcolm@redhat.com>
11216         * checker-path.cc (superedge_event::should_filter_p): Update
11217         filter for empty descriptions to cover verbosity level 3 as well
11218         as 2.
11219         * diagnostic-manager.cc: Include "analyzer/reachability.h".
11220         (class path_builder): New class.
11221         (diagnostic_manager::emit_saved_diagnostic): Create a path_builder
11222         and pass it to build_emission_path, rather passing eg; similarly
11223         for add_events_for_eedge and ext_state.
11224         (diagnostic_manager::build_emission_path): Replace "eg" param
11225         with a path_builder, pass it to add_events_for_eedge.
11226         (diagnostic_manager::add_events_for_eedge): Replace ext_state
11227         param with path_builder; pass it to add_events_for_superedge.
11228         (diagnostic_manager::significant_edge_p): New.
11229         (diagnostic_manager::add_events_for_superedge): Add path_builder
11230         param.  Reject insignificant edges at verbosity levels below 3.
11231         (diagnostic_manager::prune_for_sm_diagnostic): Update highest
11232         verbosity level to 4.
11233         * diagnostic-manager.h (class path_builder): New forward decl.
11234         (diagnostic_manager::build_emission_path): Replace "eg" param
11235         with a path_builder.
11236         (diagnostic_manager::add_events_for_eedge): Replace ext_state
11237         param with path_builder.
11238         (diagnostic_manager::significant_edge_p): New.
11239         (diagnostic_manager::add_events_for_superedge): Add path_builder
11240         param.
11241         * reachability.h: New file.
11243 2020-02-18  David Malcolm  <dmalcolm@redhat.com>
11245         PR analyzer/93692
11246         * analyzer.opt (fdump-analyzer-callgraph): Rewrite description.
11248 2020-02-18  David Malcolm  <dmalcolm@redhat.com>
11250         PR analyzer/93777
11251         * region-model.cc (region_model::maybe_cast_1): Replace assertion
11252         that build_cast returns non-NULL with a conditional, falling
11253         through to the logic which returns a new unknown value of the
11254         desired type if it fails.
11256 2020-02-18  David Malcolm  <dmalcolm@redhat.com>
11258         PR analyzer/93778
11259         * engine.cc (impl_region_model_context::on_unknown_tree_code):
11260         Rename to...
11261         (impl_region_model_context::on_unexpected_tree_code): ...this and
11262         convert first argument from path_var to tree.
11263         (exploded_node::on_stmt): Pass ctxt to purge_for_unknown_fncall.
11264         * exploded-graph.h (region_model_context::on_unknown_tree_code):
11265         Rename to...
11266         (region_model_context::on_unexpected_tree_code): ...this and
11267         convert first argument from path_var to tree.
11268         * program-state.cc (sm_state_map::purge_for_unknown_fncall): Add
11269         ctxt param and pass on to calls to get_rvalue.
11270         * program-state.h (sm_state_map::purge_for_unknown_fncall): Add
11271         ctxt param.
11272         * region-model.cc (region_model::handle_unrecognized_call): Pass
11273         ctxt on to call to get_rvalue.
11274         (region_model::get_lvalue_1): Move body of default case to
11275         region_model::make_region_for_unexpected_tree_code and call it.
11276         Within COMPONENT_REF case, reject attempts to handle types other
11277         than RECORD_TYPE and UNION_TYPE.
11278         (region_model::make_region_for_unexpected_tree_code): New
11279         function, based on default case of region_model::get_lvalue_1.
11280         * region-model.h
11281         (region_model::make_region_for_unexpected_tree_code): New decl.
11282         (region_model::on_unknown_tree_code): Rename to...
11283         (region_model::on_unexpected_tree_code): ...this and convert first
11284         argument from path_var to tree.
11285         (class test_region_model_context): Update vfunc implementation for
11286         above change.
11288 2020-02-18  David Malcolm  <dmalcolm@redhat.com>
11290         PR analyzer/93774
11291         * region-model.cc
11292         (region_model::convert_byte_offset_to_array_index): Use
11293         int_size_in_bytes before calling size_in_bytes, to gracefully fail
11294         on incomplete types.
11296 2020-02-17  David Malcolm  <dmalcolm@redhat.com>
11298         PR analyzer/93775
11299         * region-model.cc (region_model::get_fndecl_for_call): Handle the
11300         case where the code_region's get_tree_for_child_region returns
11301         NULL.
11303 2020-02-17  David Malcolm  <dmalcolm@redhat.com>
11305         PR analyzer/93388
11306         * engine.cc (impl_region_model_context::on_unknown_tree_code):
11307         New.
11308         (exploded_graph::get_or_create_node): Reject invalid states.
11309         * exploded-graph.h
11310         (impl_region_model_context::on_unknown_tree_code): New decl.
11311         (point_and_state::point_and_state): Assert that the state is
11312         valid.
11313         * program-state.cc (program_state::program_state): Initialize
11314         m_valid to true.
11315         (program_state::operator=): Copy m_valid.
11316         (program_state::program_state): Likewise for move constructor.
11317         (program_state::print): Print m_valid.
11318         (program_state::dump_to_pp): Likewise.
11319         * program-state.h (program_state::m_valid): New field.
11320         * region-model.cc (region_model::get_lvalue_1): Implement the
11321         default case by returning a new symbolic region and calling
11322         the context's on_unknown_tree_code, rather than issuing an
11323         internal_error.  Implement VIEW_CONVERT_EXPR.
11324         * region-model.h (region_model_context::on_unknown_tree_code): New
11325         vfunc.
11326         (test_region_model_context::on_unknown_tree_code): New.
11328 2020-02-17  David Malcolm  <dmalcolm@redhat.com>
11330         * sm-malloc.cc (malloc_diagnostic::describe_state_change): For
11331         transition to the "null" state, only say "assuming" when
11332         transitioning from the "unchecked" state.
11334 2020-02-17  David Malcolm  <dmalcolm@redhat.com>
11336         * diagnostic-manager.h (diagnostic_manager::get_saved_diagnostic):
11337         Add const overload.
11338         * engine.cc (exploded_node::dump_dot): Dump saved_diagnostics.
11339         * exploded-graph.h (exploded_graph::get_diagnostic_manager): Add
11340         const overload.
11342 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
11344         PR analyzer/93288
11345         * analysis-plan.cc (analysis_plan::use_summary_p): Look through
11346         the ultimate_alias_target when getting the called function.
11347         * engine.cc (exploded_node::on_stmt): Rename second "ctxt" to
11348         "sm_ctxt".  Use the region_model's get_fndecl_for_call rather than
11349         gimple_call_fndecl.
11350         * region-model.cc (region_model::get_fndecl_for_call): Use
11351         ultimate_alias_target on fndecl.
11352         * supergraph.cc (get_ultimate_function_for_cgraph_edge): New
11353         function.
11354         (supergraph_call_edge): Use it when rejecting edges without
11355         functions.
11356         (supergraph::supergraph): Use it to get the function for the
11357         cgraph_edge when building interprocedural superedges.
11358         (callgraph_superedge::get_callee_function):  Use it.
11359         * supergraph.h (supergraph::get_num_snodes): Make param const.
11360         (supergraph::function_to_num_snodes_t): Make first type param
11361         const.
11363 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
11365         PR analyzer/93374
11366         * engine.cc (exploded_edge::exploded_edge): Add ext_state param
11367         and pass it to change.validate.
11368         (exploded_graph::get_or_create_node): Move purging of change
11369         svalues to also cover the case of reusing an existing enode.
11370         (exploded_graph::add_edge): Pass m_ext_state to exploded_edge's
11371         ctor.
11372         * exploded-graph.h (exploded_edge::exploded_edge): Add ext_state
11373         param.
11374         * program-state.cc (state_change::sm_change::validate): Likewise.
11375         Assert that m_sm_idx is sane.  Use ext_state to validate
11376         m_old_state and m_new_state.
11377         (state_change::validate): Add ext_state param and pass it to
11378         the sm_change validate calls.
11379         * program-state.h (state_change::sm_change::validate): Add
11380         ext_state param.
11381         (state_change::validate): Likewise.
11383 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
11385         PR analyzer/93669
11386         * engine.cc (exploded_graph::dump_exploded_nodes): Handle missing
11387         case of STATUS_WORKLIST in implementation of
11388         "__analyzer_dump_exploded_nodes".
11390 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
11392         PR analyzer/93649
11393         * constraint-manager.cc (constraint_manager::add_constraint): When
11394         merging equivalence classes and updating m_constant, also update
11395         m_cst_sid.
11396         (constraint_manager::validate): If m_constant is non-NULL assert
11397         that m_cst_sid is non-null and is valid.
11399 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
11401         PR analyzer/93657
11402         * analyzer.opt (fdump-analyzer): Reword description.
11403         (fdump-analyzer-stderr): Likewise.
11405 2020-02-11  David Malcolm  <dmalcolm@redhat.com>
11407         * region-model.cc (print_quoted_type): New function.
11408         (svalue::print): Use it to replace %qT.
11409         (region::dump_to_pp): Likewise.
11410         (region::dump_child_label): Likewise.
11411         (region::print_fields): Likewise.
11413 2020-02-10  David Malcolm  <dmalcolm@redhat.com>
11415         PR analyzer/93659
11416         * analyzer.opt (-param=analyzer-max-recursion-depth=): Fix "tha"
11417         -> "that" typo.
11418         (Wanalyzer-use-of-uninitialized-value): Fix "initialized" ->
11419         "uninitialized" typo.
11421 2020-02-10  David Malcolm  <dmalcolm@redhat.com>
11423         PR analyzer/93350
11424         * region-model.cc (region_model::get_lvalue_1):
11425         Handle BIT_FIELD_REF.
11426         (make_region_for_type): Handle VECTOR_TYPE.
11428 2020-02-10  David Malcolm  <dmalcolm@redhat.com>
11430         PR analyzer/93647
11431         * diagnostic-manager.cc
11432         (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof against
11433         VAR being constant.
11434         * region-model.cc (region_model::get_lvalue_1): Provide a better
11435         error message when encountering an unhandled tree code.
11437 2020-02-10  David Malcolm  <dmalcolm@redhat.com>
11439         PR analyzer/93405
11440         * region-model.cc (region_model::get_lvalue_1): Implement
11441         CONST_DECL.
11443 2020-02-06  David Malcolm  <dmalcolm@redhat.com>
11445         * region-model.cc (region_model::maybe_cast_1): Attempt to provide
11446         a region_svalue if either type is a pointer, rather than if both
11447         types are pointers.
11449 2020-02-05  David Malcolm  <dmalcolm@redhat.com>
11451         * engine.cc (exploded_node::dump_dot): Show merger enodes.
11452         (worklist::add_node): Assert that the node's m_status is
11453         STATUS_WORKLIST.
11454         (exploded_graph::process_worklist): Likewise for nodes from the
11455         worklist.  Set status of merged nodes to STATUS_MERGER.
11456         (exploded_graph::process_node): Set status of node to
11457         STATUS_PROCESSED.
11458         (exploded_graph::dump_exploded_nodes): Rework handling of
11459         "__analyzer_dump_exploded_nodes", splitting enodes by status into
11460         "processed" and "merger", showing the count of just the processed
11461         enodes at the call, rather than the count of all enodes.
11462         * exploded-graph.h (exploded_node::status): New enum.
11463         (exploded_node::exploded_node): Initialize m_status to
11464         STATUS_WORKLIST.
11465         (exploded_node::get_status): New getter.
11466         (exploded_node::set_status): New setter.
11468 2020-02-04  David Malcolm  <dmalcolm@redhat.com>
11470         PR analyzer/93543
11471         * engine.cc (pod_hash_traits<function_call_string>::mark_empty):
11472         Eliminate reinterpret_cast.
11473         (pod_hash_traits<function_call_string>::is_empty): Likewise.
11475 2020-02-03  David Malcolm  <dmalcolm@redhat.com>
11477         * constraint-manager.cc (range::constrained_to_single_element):
11478         Replace fold_build2 with fold_binary.  Remove unnecessary newline.
11479         (constraint_manager::get_or_add_equiv_class): Replace fold_build2
11480         with fold_binary in two places, and remove out-of-date comment.
11481         (constraint_manager::eval_condition): Replace fold_build2 with
11482         fold_binary.
11483         * region-model.cc (constant_svalue::eval_condition): Likewise.
11484         (region_model::on_assignment): Likewise.
11486 2020-02-03  David Malcolm  <dmalcolm@redhat.com>
11488         PR analyzer/93544
11489         * diagnostic-manager.cc
11490         (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof
11491         against bad choices due to bad paths.
11492         * engine.cc (impl_region_model_context::on_phi): New.
11493         * exploded-graph.h (impl_region_model_context::on_phi): New decl.
11494         * region-model.cc (region_model::on_longjmp): Likewise.
11495         (region_model::handle_phi): Add phi param.  Call the ctxt's on_phi
11496         vfunc.
11497         (region_model::update_for_phis): Pass phi to handle_phi.
11498         * region-model.h (region_model::handle_phi): Add phi param.
11499         (region_model_context::on_phi): New vfunc.
11500         (test_region_model_context::on_phi): New.
11501         * sm-malloc.cc (malloc_state_machine::on_phi): New.
11502         (malloc_state_machine::on_zero_assignment): New.
11503         * sm.h (state_machine::on_phi): New vfunc.
11505 2020-02-03  David Malcolm  <dmalcolm@redhat.com>
11507         * engine.cc (supernode_cluster::dump_dot): Show BB index as
11508         well as SN index.
11509         * supergraph.cc (supernode::dump_dot): Likewise.
11511 2020-02-03  David Malcolm  <dmalcolm@redhat.com>
11513         PR analyzer/93546
11514         * region-model.cc (region_model::on_call_pre): Update for new
11515         param of symbolic_region ctor.
11516         (region_model::deref_rvalue): Likewise.
11517         (region_model::add_new_malloc_region): Likewise.
11518         (make_region_for_type): Likewise, preserving type.
11519         * region-model.h (symbolic_region::symbolic_region): Add "type"
11520         param and pass it to base class ctor.
11522 2020-02-03  David Malcolm  <dmalcolm@redhat.com>
11524         PR analyzer/93547
11525         * constraint-manager.cc
11526         (constraint_manager::get_or_add_equiv_class): Ensure types are
11527         compatible before comparing constants.
11529 2020-01-31  David Malcolm  <dmalcolm@redhat.com>
11531         PR analyzer/93457
11532         * region-model.cc (make_region_for_type): Use VOID_TYPE_P rather
11533         than checking against void_type_node.
11535 2020-01-31  David Malcolm  <dmalcolm@redhat.com>
11537         PR analyzer/93373
11538         * region-model.cc (ASSERT_COMPAT_TYPES): Convert to...
11539         (assert_compat_types): ...this, and bail when either type is NULL,
11540         or when VOID_TYPE_P (dst_type).
11541         (region_model::get_lvalue): Update for above conversion.
11542         (region_model::get_rvalue): Likewise.
11544 2020-01-31  David Malcolm  <dmalcolm@redhat.com>
11546         PR analyzer/93379
11547         * region-model.cc (region_model::update_for_return_superedge):
11548         Move check for null result so that it also guards setting the
11549         lhs.
11551 2020-01-31  David Malcolm  <dmalcolm@redhat.com>
11553         PR analyzer/93438
11554         * region-model.cc (stack_region::can_merge_p): Split into a two
11555         pass approach, creating all stack regions first, then populating
11556         them.
11557         (selftest::test_state_merging): Add test coverage for (a) the case
11558         of self-merging a model in which a local in an older stack frame
11559         points to a local in a more recent stack frame (which previously
11560         would ICE), and (b) the case of self-merging a model in which a
11561         local points to a global (which previously worked OK).
11563 2020-01-31  David Malcolm  <dmalcolm@redhat.com>
11565         * analyzer.cc (is_named_call_p): Replace tests for fndecl being
11566         extern at file scope and having a non-NULL DECL_NAME with a call
11567         to maybe_special_function_p.
11568         * function-set.cc (function_set::contains_decl_p): Add call to
11569         maybe_special_function_p.
11571 2020-01-31  David Malcolm  <dmalcolm@redhat.com>
11573         PR analyzer/93450
11574         * constraint-manager.cc
11575         (constraint_manager::get_or_add_equiv_class): Only compare constants
11576         if their types are compatible.
11577         * region-model.cc (constant_svalue::eval_condition): Replace check
11578         for identical types with call to types_compatible_p.
11580 2020-01-30  David Malcolm  <dmalcolm@redhat.com>
11582         * program-state.cc (extrinsic_state::dump_to_pp): New.
11583         (extrinsic_state::dump_to_file): New.
11584         (extrinsic_state::dump): New.
11585         * program-state.h (extrinsic_state::dump_to_pp): New decl.
11586         (extrinsic_state::dump_to_file): New decl.
11587         (extrinsic_state::dump): New decl.
11588         * sm.cc: Include "pretty-print.h".
11589         (state_machine::dump_to_pp): New.
11590         * sm.h (state_machine::dump_to_pp): New decl.
11592 2020-01-30  David Malcolm  <dmalcolm@redhat.com>
11594         * diagnostic-manager.cc (for_each_state_change): Use
11595         extrinsic_state::get_num_checkers rather than accessing m_checkers
11596         directly.
11597         * program-state.cc (program_state::program_state): Likewise.
11598         * program-state.h (extrinsic_state::m_checkers): Make private.
11600 2020-01-30  David Malcolm  <dmalcolm@redhat.com>
11602         PR analyzer/93356
11603         * region-model.cc (region_model::eval_condition): In both
11604         overloads, bail out immediately on floating-point types.
11605         (region_model::eval_condition_without_cm): Likewise.
11606         (region_model::add_constraint): Likewise.
11608 2020-01-30  David Malcolm  <dmalcolm@redhat.com>
11610         PR analyzer/93450
11611         * program-state.cc (sm_state_map::set_state): For the overload
11612         taking an svalue_id, bail out if the set_state on the ec does
11613         nothing.  Convert the latter's return type from void to bool,
11614         returning true if anything changed.
11615         (sm_state_map::impl_set_state): Convert the return type from void
11616         to bool, returning true if the state changed.
11617         * program-state.h (sm_state_map::set_state): Convert return type
11618         from void to bool.
11619         (sm_state_map::impl_set_state): Likewise.
11620         * region-model.cc (constant_svalue::eval_condition): Only call
11621         fold_build2 if the types are the same.
11623 2020-01-29  Jakub Jelinek  <jakub@redhat.com>
11625         * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Remove.
11626         * constraint-manager.cc: Include diagnostic-core.h before graphviz.h.
11627         (range::dump, equiv_class::print): Don't use PUSH_IGNORE_WFORMAT or
11628         POP_IGNORE_WFORMAT.
11629         * state-purge.cc: Include diagnostic-core.h before
11630         gimple-pretty-print.h.
11631         (state_purge_annotator::add_node_annotations, print_vec_of_names):
11632         Don't use PUSH_IGNORE_WFORMAT or POP_IGNORE_WFORMAT.
11633         * region-model.cc: Move diagnostic-core.h include before graphviz.h.
11634         (path_var::dump, svalue::print, constant_svalue::print_details,
11635         region::dump_to_pp, region::dump_child_label, region::print_fields,
11636         map_region::print_fields, map_region::dump_dot_to_pp,
11637         map_region::dump_child_label, array_region::print_fields,
11638         array_region::dump_dot_to_pp): Don't use PUSH_IGNORE_WFORMAT or
11639         POP_IGNORE_WFORMAT.
11641 2020-01-28  David Malcolm  <dmalcolm@redhat.com>
11643         PR analyzer/93316
11644         * engine.cc (rewind_info_t::update_model): Get the longjmp call
11645         stmt via get_longjmp_call () rather than assuming it is the last
11646         stmt in the longjmp's supernode.
11647         (rewind_info_t::add_events_to_path): Get the location_t for the
11648         rewind_from_longjmp_event via get_longjmp_call () rather than from
11649         the supernode's get_end_location ().
11651 2020-01-28  David Malcolm  <dmalcolm@redhat.com>
11653         * region-model.cc (poisoned_value_diagnostic::emit): Update for
11654         renaming of warning_at overload to warning_meta.
11655         * sm-file.cc (file_leak::emit): Likewise.
11656         * sm-malloc.cc (double_free::emit): Likewise.
11657         (possible_null_deref::emit): Likewise.
11658         (possible_null_arg::emit): Likewise.
11659         (null_deref::emit): Likewise.
11660         (null_arg::emit): Likewise.
11661         (use_after_free::emit): Likewise.
11662         (malloc_leak::emit): Likewise.
11663         (free_of_non_heap::emit): Likewise.
11664         * sm-sensitive.cc (exposure_through_output_file::emit): Likewise.
11665         * sm-signal.cc (signal_unsafe_call::emit): Likewise.
11666         * sm-taint.cc (tainted_array_index::emit): Likewise.
11668 2020-01-27  David Malcolm  <dmalcolm@redhat.com>
11670         PR analyzer/93451
11671         * region-model.cc (tree_cmp): For the REAL_CST case, impose an
11672         arbitrary order on NaNs relative to other NaNs and to non-NaNs;
11673         const-correctness tweak.
11674         (ana::selftests::build_real_cst_from_string): New function.
11675         (ana::selftests::append_interesting_constants): New function.
11676         (ana::selftests::test_tree_cmp_on_constants): New test.
11677         (ana::selftests::test_canonicalization_4): New test.
11678         (ana::selftests::analyzer_region_model_cc_tests): Call the new
11679         tests.
11681 2020-01-27  David Malcolm  <dmalcolm@redhat.com>
11683         PR analyzer/93349
11684         * engine.cc (run_checkers): Save and restore input_location.
11686 2020-01-27  David Malcolm  <dmalcolm@redhat.com>
11688         * call-string.cc (call_string::cmp_1): Delete, moving body to...
11689         (call_string::cmp): ...here.
11690         * call-string.h (call_string::cmp_1): Delete decl.
11691         * engine.cc (worklist::key_t::cmp_1): Delete, moving body to...
11692         (worklist::key_t::cmp): ...here.  Implement hash comparisons
11693         via comparison rather than subtraction to avoid overflow issues.
11694         * exploded-graph.h (worklist::key_t::cmp_1): Delete decl.
11695         * region-model.cc (tree_cmp): Eliminate buggy checking for
11696         symmetry.
11698 2020-01-27  David Malcolm  <dmalcolm@redhat.com>
11700         * analyzer.cc  (is_named_call_p): Check that fndecl is "extern"
11701         and at file scope.  Potentially disregard prefix _ or __ in
11702         fndecl's name.  Bail if the identifier is NULL.
11703         (is_setjmp_call_p): Expect a gcall rather than plain gimple.
11704         Remove special-case check for leading prefix, and also check for
11705         sigsetjmp.
11706         (is_longjmp_call_p): Also check for siglongjmp.
11707         (get_user_facing_name): New function.
11708         * analyzer.h (is_setjmp_call_p): Expect a gcall rather than plain
11709         gimple.
11710         (get_user_facing_name): New decl.
11711         * checker-path.cc (setjmp_event::get_desc): Use
11712         get_user_facing_name to avoid hardcoding the function name.
11713         (rewind_event::rewind_event): Add rewind_info param, using it to
11714         initialize new m_rewind_info field, and strengthen the assertion.
11715         (rewind_from_longjmp_event::get_desc): Use get_user_facing_name to
11716         avoid hardcoding the function name.
11717         (rewind_to_setjmp_event::get_desc): Likewise.
11718         * checker-path.h (setjmp_event::setjmp_event): Add setjmp_call
11719         param and use it to initialize...
11720         (setjmp_event::m_setjmp_call): New field.
11721         (rewind_event::rewind_event): Add rewind_info param.
11722         (rewind_event::m_rewind_info): New protected field.
11723         (rewind_from_longjmp_event::rewind_from_longjmp_event): Add
11724         rewind_info param.
11725         (class rewind_to_setjmp_event): Move rewind_info field to parent
11726         class.
11727         * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
11728         Update setjmp-handling for is_setjmp_call_p requiring a gcall;
11729         pass the call to the new setjmp_event.
11730         * engine.cc (exploded_node::on_stmt): Update for is_setjmp_call_p
11731         requiring a gcall.
11732         (stale_jmp_buf::emit): Use get_user_facing_name to avoid
11733         hardcoding the function names.
11734         (exploded_node::on_longjmp): Pass the longjmp_call when
11735         constructing rewind_info.
11736         (rewind_info_t::add_events_to_path): Pass the rewind_info_t to the
11737         rewind_from_longjmp_event's ctor.
11738         * exploded-graph.h (rewind_info_t::rewind_info_t): Add
11739         longjmp_call param.
11740         (rewind_info_t::get_longjmp_call): New.
11741         (rewind_info_t::m_longjmp_call): New.
11742         * region-model.cc (region_model::on_setjmp): Update comment to
11743         indicate this is also for sigsetjmp.
11744         * region-model.h (struct setjmp_record): Likewise.
11745         (class setjmp_svalue): Likewise.
11747 2020-01-27  David Malcolm  <dmalcolm@redhat.com>
11749         PR analyzer/93276
11750         * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Guard these
11751         macros with GCC_VERSION >= 4006, making them no-op otherwise.
11752         * engine.cc (exploded_edge::exploded_edge): Specify template for
11753         base class initializer.
11754         (exploded_graph::add_edge): Specify template when chaining up to
11755         base class add_edge implementation.
11756         (viz_callgraph_node::dump_dot): Drop redundant "typename".
11757         (viz_callgraph_edge::viz_callgraph_edge): Specify template for
11758         base class initializer.
11759         * program-state.cc (sm_state_map::clone_with_remapping): Drop
11760         redundant "typename".
11761         (sm_state_map::print): Likewise.
11762         (sm_state_map::hash): Likewise.
11763         (sm_state_map::operator==): Likewise.
11764         (sm_state_map::remap_svalue_ids): Likewise.
11765         (sm_state_map::on_svalue_purge): Likewise.
11766         (sm_state_map::validate): Likewise.
11767         * program-state.h (sm_state_map::iterator_t): Likewise.
11768         * supergraph.h (superedge::superedge): Specify template for base
11769         class initializer.
11771 2020-01-23  David Malcolm  <dmalcolm@redhat.com>
11773         PR analyzer/93375
11774         * supergraph.cc (callgraph_superedge::get_arg_for_parm): Fail
11775         gracefully is the number of parameters at the callee exceeds the
11776         number of arguments at the call stmt.
11777         (callgraph_superedge::get_parm_for_arg): Likewise.
11779 2020-01-22  David Malcolm  <dmalcolm@redhat.com>
11781         PR analyzer/93382
11782         * program-state.cc (sm_state_map::on_svalue_purge): If the
11783         entry survives, but the origin is being purged, then reset the
11784         origin to null.
11786 2020-01-22  David Malcolm  <dmalcolm@redhat.com>
11788         * sm-signal.cc: Fix nesting of CHECKING_P and namespace ana.
11790 2020-01-22  David Malcolm  <dmalcolm@redhat.com>
11792         PR analyzer/93378
11793         * engine.cc (setjmp_svalue::compare_fields): Update for
11794         replacement of m_enode with m_setjmp_record.
11795         (setjmp_svalue::add_to_hash): Likewise.
11796         (setjmp_svalue::get_index): Rename...
11797         (setjmp_svalue::get_enode_index): ...to this.
11798         (setjmp_svalue::print_details): Update for replacement of m_enode
11799         with m_setjmp_record.
11800         (exploded_node::on_longjmp): Likewise.
11801         * exploded-graph.h (rewind_info_t::m_enode_origin): Replace...
11802         (rewind_info_t::m_setjmp_record): ...with this.
11803         (rewind_info_t::rewind_info_t): Update for replacement of m_enode
11804         with m_setjmp_record.
11805         (rewind_info_t::get_setjmp_point): Likewise.
11806         (rewind_info_t::get_setjmp_call): Likewise.
11807         * region-model.cc (region_model::dump_summary_of_map): Likewise.
11808         (region_model::on_setjmp): Likewise.
11809         * region-model.h (struct setjmp_record): New struct.
11810         (setjmp_svalue::m_enode): Replace...
11811         (setjmp_svalue::m_setjmp_record): ...with this.
11812         (setjmp_svalue::setjmp_svalue): Update for replacement of m_enode
11813         with m_setjmp_record.
11814         (setjmp_svalue::clone): Likewise.
11815         (setjmp_svalue::get_index): Rename...
11816         (setjmp_svalue::get_enode_index): ...to this.
11817         (setjmp_svalue::get_exploded_node): Replace...
11818         (setjmp_svalue::get_setjmp_record): ...with this.
11820 2020-01-22  David Malcolm  <dmalcolm@redhat.com>
11822         PR analyzer/93316
11823         * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as
11824         "_setjmp".
11826 2020-01-22  David Malcolm  <dmalcolm@redhat.com>
11828         PR analyzer/93307
11829         * analysis-plan.h: Wrap everything namespace "ana".
11830         * analyzer-logging.cc: Likewise.
11831         * analyzer-logging.h: Likewise.
11832         * analyzer-pass.cc (pass_analyzer::execute): Update for "ana"
11833         namespace.
11834         * analyzer-selftests.cc: Wrap everything namespace "ana".
11835         * analyzer-selftests.h: Likewise.
11836         * analyzer.h: Likewise for forward decls of types.
11837         * call-string.h: Likewise.
11838         * checker-path.cc: Likewise.
11839         * checker-path.h: Likewise.
11840         * constraint-manager.cc: Likewise.
11841         * constraint-manager.h: Likewise.
11842         * diagnostic-manager.cc: Likewise.
11843         * diagnostic-manager.h: Likewise.
11844         * engine.cc: Likewise.
11845         * engine.h: Likewise.
11846         * exploded-graph.h: Likewise.
11847         * function-set.cc: Likewise.
11848         * function-set.h: Likewise.
11849         * pending-diagnostic.cc: Likewise.
11850         * pending-diagnostic.h: Likewise.
11851         * program-point.cc: Likewise.
11852         * program-point.h: Likewise.
11853         * program-state.cc: Likewise.
11854         * program-state.h: Likewise.
11855         * region-model.cc: Likewise.
11856         * region-model.h: Likewise.
11857         * sm-file.cc: Likewise.
11858         * sm-malloc.cc: Likewise.
11859         * sm-pattern-test.cc: Likewise.
11860         * sm-sensitive.cc: Likewise.
11861         * sm-signal.cc: Likewise.
11862         * sm-taint.cc: Likewise.
11863         * sm.cc: Likewise.
11864         * sm.h: Likewise.
11865         * state-purge.h: Likewise.
11866         * supergraph.cc: Likewise.
11867         * supergraph.h: Likewise.
11869 2020-01-21  David Malcolm  <dmalcolm@redhat.com>
11871         PR analyzer/93352
11872         * region-model.cc (int_cmp): Rename to...
11873         (array_region::key_cmp): ...this, using key_t rather than int.
11874         Rewrite in terms of comparisons rather than subtraction to
11875         ensure qsort is anti-symmetric when handling extreme values.
11876         (array_region::walk_for_canonicalization): Update for above
11877         renaming.
11878         * region-model.h (array_region::key_cmp): New decl.
11880 2020-01-17  David Malcolm  <dmalcolm@redhat.com>
11882         PR analyzer/93290
11883         * region-model.cc (region_model::eval_condition_without_cm): Avoid
11884         gcc_unreachable for unexpected operations for the case where
11885         we're comparing an svalue against itself.
11887 2020-01-17  David Malcolm  <dmalcolm@redhat.com>
11889         PR analyzer/93281
11890         * region-model.cc
11891         (region_model::convert_byte_offset_to_array_index): Convert to
11892         ssizetype before dividing by byte_size.  Use fold_binary rather
11893         than fold_build2 to avoid needlessly constructing a tree for the
11894         non-const case.
11896 2020-01-15  David Malcolm  <dmalcolm@redhat.com>
11898         * engine.cc (class impl_region_model_context): Fix comment.
11900 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11902         PR analyzer/93212
11903         * region-model.cc (make_region_for_type): Use
11904         FUNC_OR_METHOD_TYPE_P rather than comparing against FUNCTION_TYPE.
11905         * region-model.h (function_region::function_region): Likewise.
11907 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11909         * program-state.cc (sm_state_map::clone_with_remapping): Copy
11910         m_global_state.
11911         (selftest::test_program_state_merging_2): New selftest.
11912         (selftest::analyzer_program_state_cc_tests): Call it.
11914 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11916         * checker-path.h (checker_path::get_checker_event): New function.
11917         (checker_path): Add DISABLE_COPY_AND_ASSIGN; make fields private.
11918         * diagnostic-manager.cc
11919         (diagnostic_manager::prune_for_sm_diagnostic): Replace direct
11920         access to checker_path::m_events with accessor functions.  Fix
11921         overlong line.
11922         (diagnostic_manager::prune_interproc_events): Replace direct
11923         access to checker_path::m_events with accessor functions.
11924         (diagnostic_manager::finish_pruning): Likewise.
11926 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11928         * checker-path.h (checker_event::clone): Delete vfunc decl.
11929         (debug_event::clone): Delete vfunc impl.
11930         (custom_event::clone): Delete vfunc impl.
11931         (statement_event::clone): Delete vfunc impl.
11932         (function_entry_event::clone): Delete vfunc impl.
11933         (state_change_event::clone): Delete vfunc impl.
11934         (start_cfg_edge_event::clone): Delete vfunc impl.
11935         (end_cfg_edge_event::clone): Delete vfunc impl.
11936         (call_event::clone): Delete vfunc impl.
11937         (return_event::clone): Delete vfunc impl.
11938         (setjmp_event::clone): Delete vfunc impl.
11939         (rewind_from_longjmp_event::clone): Delete vfunc impl.
11940         (rewind_to_setjmp_event::clone): Delete vfunc impl.
11941         (warning_event::clone): Delete vfunc impl.
11943 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11945         * supergraph.cc (supernode::dump_dot): Ensure that the TABLE
11946         element has at least one TR.
11948 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11950         PR analyzer/58237
11951         * engine.cc (leak_stmt_finder::find_stmt): Use get_pure_location
11952         when comparing against UNKNOWN_LOCATION.
11953         (stmt_requires_new_enode_p): Likewise.
11954         (exploded_graph::dump_exploded_nodes): Likewise.
11955         * supergraph.cc (supernode::get_start_location): Likewise.
11956         (supernode::get_end_location): Likewise.
11958 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11960         PR analyzer/58237
11961         * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11962         selftest::analyzer_sm_file_cc_tests.
11963         * analyzer-selftests.h (selftest::analyzer_sm_file_cc_tests): New
11964         decl.
11965         * sm-file.cc: Include "analyzer/function-set.h" and
11966         "analyzer/analyzer-selftests.h".
11967         (get_file_using_fns): New function.
11968         (is_file_using_fn_p): New function.
11969         (fileptr_state_machine::on_stmt): Return true for known functions.
11970         (selftest::analyzer_sm_file_cc_tests): New function.
11972 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11974         * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11975         selftest::analyzer_sm_signal_cc_tests.
11976         * analyzer-selftests.h (selftest::analyzer_sm_signal_cc_tests):
11977         New decl.
11978         * sm-signal.cc: Include "analyzer/function-set.h" and
11979         "analyzer/analyzer-selftests.h".
11980         (get_async_signal_unsafe_fns): New function.
11981         (signal_unsafe_p): Reimplement in terms of the above.
11982         (selftest::analyzer_sm_signal_cc_tests): New function.
11984 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11986         * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11987         selftest::analyzer_function_set_cc_tests.
11988         * analyzer-selftests.h (selftest::analyzer_function_set_cc_tests):
11989         New decl.
11990         * function-set.cc: New file.
11991         * function-set.h: New file.
11993 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
11995         * analyzer.h (fndecl_has_gimple_body_p): New decl.
11996         * engine.cc (impl_region_model_context::on_unknown_change): New
11997         function.
11998         (fndecl_has_gimple_body_p): Make non-static.
11999         (exploded_node::on_stmt): Treat __analyzer_dump_exploded_nodes as
12000         known.  Track whether we have a call with unknown side-effects and
12001         pass it to on_call_post.
12002         * exploded-graph.h (impl_region_model_context::on_unknown_change):
12003         New decl.
12004         * program-state.cc (sm_state_map::on_unknown_change): New function.
12005         * program-state.h (sm_state_map::on_unknown_change): New decl.
12006         * region-model.cc: Include "bitmap.h".
12007         (region_model::on_call_pre): Return a bool, capturing whether the
12008         call has unknown side effects.
12009         (region_model::on_call_post): Add arg "bool unknown_side_effects"
12010         and if true, call handle_unrecognized_call.
12011         (class reachable_regions): New class.
12012         (region_model::handle_unrecognized_call): New function.
12013         * region-model.h (region_model::on_call_pre): Return a bool.
12014         (region_model::on_call_post): Add arg "bool unknown_side_effects".
12015         (region_model::handle_unrecognized_call): New decl.
12016         (region_model_context::on_unknown_change): New vfunc.
12017         (test_region_model_context::on_unknown_change): New function.
12019 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
12021         * diagnostic-manager.cc (saved_diagnostic::operator==): Move here
12022         from header.  Replace pointer equality test on m_var with call to
12023         pending_diagnostic::same_tree_p.
12024         * diagnostic-manager.h (saved_diagnostic::operator==): Move to
12025         diagnostic-manager.cc.
12026         * pending-diagnostic.cc (pending_diagnostic::same_tree_p): New.
12027         * pending-diagnostic.h (pending_diagnostic::same_tree_p): New.
12028         * sm-file.cc (file_diagnostic::subclass_equal_p): Replace pointer
12029         equality on m_arg with call to pending_diagnostic::same_tree_p.
12030         * sm-malloc.cc (malloc_diagnostic::subclass_equal_p): Likewise.
12031         (possible_null_arg::subclass_equal_p): Likewise.
12032         (null_arg::subclass_equal_p): Likewise.
12033         (free_of_non_heap::subclass_equal_p): Likewise.
12034         * sm-pattern-test.cc (pattern_match::operator==): Likewise.
12035         * sm-sensitive.cc (exposure_through_output_file::operator==):
12036         Likewise.
12037         * sm-taint.cc (tainted_array_index::operator==): Likewise.
12039 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
12041         * diagnostic-manager.cc (dedupe_winners::add): Add logging
12042         of deduplication decisions made.
12044 2020-01-14  David Malcolm  <dmalcolm@redhat.com>
12046         * ChangeLog: New file.
12047         * analyzer-selftests.cc: New file.
12048         * analyzer-selftests.h: New file.
12049         * analyzer.opt: New file.
12050         * analysis-plan.cc: New file.
12051         * analysis-plan.h: New file.
12052         * analyzer-logging.cc: New file.
12053         * analyzer-logging.h: New file.
12054         * analyzer-pass.cc: New file.
12055         * analyzer.cc: New file.
12056         * analyzer.h: New file.
12057         * call-string.cc: New file.
12058         * call-string.h: New file.
12059         * checker-path.cc: New file.
12060         * checker-path.h: New file.
12061         * constraint-manager.cc: New file.
12062         * constraint-manager.h: New file.
12063         * diagnostic-manager.cc: New file.
12064         * diagnostic-manager.h: New file.
12065         * engine.cc: New file.
12066         * engine.h: New file.
12067         * exploded-graph.h: New file.
12068         * pending-diagnostic.cc: New file.
12069         * pending-diagnostic.h: New file.
12070         * program-point.cc: New file.
12071         * program-point.h: New file.
12072         * program-state.cc: New file.
12073         * program-state.h: New file.
12074         * region-model.cc: New file.
12075         * region-model.h: New file.
12076         * sm-file.cc: New file.
12077         * sm-malloc.cc: New file.
12078         * sm-malloc.dot: New file.
12079         * sm-pattern-test.cc: New file.
12080         * sm-sensitive.cc: New file.
12081         * sm-signal.cc: New file.
12082         * sm-taint.cc: New file.
12083         * sm.cc: New file.
12084         * sm.h: New file.
12085         * state-purge.cc: New file.
12086         * state-purge.h: New file.
12087         * supergraph.cc: New file.
12088         * supergraph.h: New file.
12090 2019-12-13  David Malcolm  <dmalcolm@redhat.com>
12092         * Initial creation
12095 Copyright (C) 2019-2024 Free Software Foundation, Inc.
12097 Copying and distribution of this file, with or without modification,
12098 are permitted in any medium without royalty provided the copyright
12099 notice and this notice are preserved.