1 2023-11-19 David Malcolm <dmalcolm@redhat.com>
3 * analyzer.h: Include "rich-location.h".
5 2023-11-19 David Malcolm <dmalcolm@redhat.com>
8 * analyzer.h (register_known_functions): Add region_model_manager
10 * analyzer.opt (Wanalyzer-undefined-behavior-strtok): New.
12 (call_summary_replay::convert_region_from_summary_1): Handle
14 * engine.cc (impl_run_checkers): Pass model manager to
15 register_known_functions.
16 * kf.cc (class undefined_function_behavior): New.
17 (class kf_strtok): New.
18 (register_known_functions): Add region_model_manager param.
19 Use it to register "strtok".
20 * region-model-manager.cc
21 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
23 * region-model-manager.h
24 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
26 (region_model_manager::get_root_region): New accessor.
27 * region-model.cc (region_model::scan_for_null_terminator): Handle
29 (region_model::get_representative_path_var_1): Handle RK_PRIVATE.
30 * region-model.h (region_model::called_from_main_p): Make public.
31 * region.cc (region::get_memory_space): Handle RK_PRIVATE.
32 (region::can_have_initial_svalue_p): Handle MEMSPACE_PRIVATE.
33 (private_region::dump_to_pp): New.
34 * region.h (MEMSPACE_PRIVATE): New.
36 (class private_region): New.
37 (is_a_helper <const private_region *>::test): New.
38 * store.cc (store::replay_call_summary_cluster): Handle
40 * svalue.h (struct conjured_svalue::key_t): Add "idx" param to
41 ctor and "m_idx" field.
42 (class conjured_svalue::conjured_svalue): Likewise.
44 2023-11-18 David Malcolm <dmalcolm@redhat.com>
47 * analyzer.opt (Wanalyzer-infinite-loop): New option.
48 (fdump-analyzer-infinite-loop): New option.
49 * checker-event.h (start_cfg_edge_event::get_desc): Drop "final".
50 (start_cfg_edge_event::maybe_describe_condition): Convert from
52 * checker-path.h (checker_path::get_logger): New.
53 * diagnostic-manager.cc (process_worklist_item): Update for
54 new context param of maybe_update_for_edge.
56 (impl_region_model_context::impl_region_model_context): Add
57 out_could_have_done_work param to both ctors and use it to
58 initialize mm_out_could_have_done_work.
59 (impl_region_model_context::maybe_did_work): New vfunc
61 (exploded_node::on_stmt): Add out_could_have_done_work param and
63 (exploded_node::on_stmt_pre): Treat setjmp and longjmp as "doing
65 (exploded_node::on_longjmp): Likewise.
66 (exploded_edge::exploded_edge): Add "could_do_work" param and use
67 it to initialize m_could_do_work_p.
68 (exploded_edge::dump_dot_label): Add result of could_do_work_p.
69 (exploded_graph::add_function_entry): Mark edge as doing no work.
70 (exploded_graph::add_edge): Add "could_do_work" param and pass to
72 (add_tainted_args_callback): Treat as doing no work.
73 (exploded_graph::process_worklist): Likewise when merging nodes.
74 (maybe_process_run_of_before_supernode_enodes::item): Likewise.
75 (exploded_graph::maybe_create_dynamic_call): Likewise.
76 (exploded_graph::process_node): Likewise for phi nodes.
77 Pass in a "could_have_done_work" bool when handling stmts and use
78 when creating edges. Assume work is done at bifurcation.
79 (exploded_path::feasible_p): Update for new context param of
80 maybe_update_for_edge.
81 (feasibility_state::feasibility_state): New ctor.
82 (feasibility_state::operator=): New.
83 (feasibility_state::maybe_update_for_edge): Add ctxt param and use
84 it. Fix missing newline when logging state.
85 (impl_run_checkers): Call exploded_graph::detect_infinite_loops.
87 (impl_region_model_context::impl_region_model_context): Add
88 out_could_have_done_work param to both ctors.
89 (impl_region_model_context::maybe_did_work): New decl.
90 (impl_region_model_context::checking_for_infinite_loop_p): New.
91 (impl_region_model_context::on_unusable_in_infinite_loop): New.
92 (impl_region_model_context::m_out_could_have_done_work): New
94 (exploded_node::on_stmt): Add "out_could_have_done_work" param.
95 (exploded_edge::exploded_edge): Add "could_do_work" param.
96 (exploded_edge::could_do_work_p): New accessor.
97 (exploded_edge::m_could_do_work_p): New field.
98 (exploded_graph::add_edge): Add "could_do_work" param.
99 (exploded_graph::detect_infinite_loops): New decl.
100 (feasibility_state::feasibility_state): New ctor.
101 (feasibility_state::operator=): New decl.
102 (feasibility_state::maybe_update_for_edge): Add ctxt param.
103 * infinite-loop.cc: New file.
104 * program-state.cc (program_state::on_edge): Log the rejected
105 constraint when region_model::maybe_update_for_edge fails.
106 * region-model.cc (region_model::on_assignment): Treat any writes
107 other than to the stack as "doing work".
108 (region_model::on_stmt_pre): Treat all asm stmts as "doing work".
109 (region_model::on_call_post): Likewise for all calls to functions
110 with unknown side effects.
111 (region_model::handle_phi): Add svals_changing_meaning param.
112 Mark widening svalue in phi nodes as changing meaning.
113 (unusable_in_infinite_loop_constraint_p): New.
114 (region_model::add_constraint): If we're checking for an infinite
115 loop, bail out on unusable svalues, or if we don't have a definite
116 true/false for the constraint.
117 (region_model::update_for_phis): Gather all svalues changing
118 meaning in phi nodes, and purge constraints involving them.
119 (region_model::replay_call_summary): Treat all call summaries as
121 (region_model::can_merge_with_p): Purge constraints involving
122 svalues that change meaning.
123 (model_merger::on_widening_reuse): New.
124 (test_iteration_1): Likewise.
125 (selftest::test_iteration_1): Remove assertion that model6 "knows"
127 * region-model.h (region_model::handle_phi): Add
128 svals_changing_meaning param
129 (region_model_context::maybe_did_work): New pure virtual func.
130 (region_model_context::checking_for_infinite_loop_p): Likewise.
131 (region_model_context::on_unusable_in_infinite_loop): Likewise.
132 (noop_region_model_context::maybe_did_work): Implement.
133 (noop_region_model_context::checking_for_infinite_loop_p):
135 (noop_region_model_context::on_unusable_in_infinite_loop):
137 (region_model_context_decorator::maybe_did_work): Implement.
138 (region_model_context_decorator::checking_for_infinite_loop_p):
140 (region_model_context_decorator::on_unusable_in_infinite_loop):
142 (model_merger::on_widening_reuse): New decl.
143 (model_merger::m_svals_changing_meaning): New field.
144 * sm-signal.cc (register_signal_handler::impl_transition): Assume
145 the edge "does work".
146 * supergraph.cc (supernode::get_start_location): Use CFG edge's
147 goto_locus if available.
148 (supernode::get_end_location): Likewise.
149 (cfg_superedge::dump_label_to_pp): Dump edges with a "goto_locus"
150 * supergraph.h (cfg_superedge::get_goto_locus): New.
151 * svalue.cc (svalue::can_merge_p): Call on_widening_reuse for
153 (involvement_visitor::visit_widening_svalue): New.
154 (svalue::involves_p): Update assertion to allow widening svalues.
156 2023-11-14 David Malcolm <dmalcolm@redhat.com>
159 * sm-taint.cc: Remove "experimental" from comment.
160 * sm.cc (make_checkers): Always add taint state machine.
162 2023-11-04 David Malcolm <dmalcolm@redhat.com>
164 * bounds-checking.cc: Update for changes to diagnostic_context.
166 2023-11-02 David Malcolm <dmalcolm@redhat.com>
169 * access-diagram.cc (class x_aligned_x_ruler_widget): Eliminate
170 unused field "m_col_widths".
171 (access_diagram_impl::add_valid_vs_invalid_ruler): Update for
174 (check_one_function_attr_null_terminated_string_arg): Remove
175 unused variables "cd_unchecked", "strlen_sval", and
177 * region-model.h (region_model_context_decorator::warn): Add
180 2023-10-31 David Malcolm <dmalcolm@redhat.com>
182 * record-layout.cc: New file, based on material in region-model.cc.
183 * record-layout.h: Likewise.
184 * region-model.cc: Include "analyzer/record-layout.h".
185 (class record_layout): Move to record-layout.cc and .h
187 2023-10-26 David Malcolm <dmalcolm@redhat.com>
190 (region_model::check_external_function_for_access_attr): Split
191 out, replacing with...
192 (region_model::check_function_attr_access): ...this new function
194 (region_model::check_function_attrs): ...this new function.
195 (region_model::check_one_function_attr_null_terminated_string_arg):
197 (region_model::check_function_attr_null_terminated_string_arg):
199 (region_model::handle_unrecognized_call): Update for renaming of
200 check_external_function_for_access_attr to check_function_attrs.
201 (region_model::check_for_null_terminated_string_arg): Add return
202 value to one overload. Make both overloads const.
203 * region-model.h: Include "stringpool.h" and "attribs.h".
204 (region_model::check_for_null_terminated_string_arg): Add return
205 value to one overload. Make both overloads const.
206 (region_model::check_external_function_for_access_attr): Delete
208 (region_model::check_function_attr_access): New decl.
209 (region_model::check_function_attr_null_terminated_string_arg):
211 (region_model::check_one_function_attr_null_terminated_string_arg):
213 (region_model::check_function_attrs): New decl.
215 2023-10-09 David Malcolm <dmalcolm@redhat.com>
217 * access-diagram.cc (boundaries::add): Explicitly state
218 "boundaries::" scope for "kind" enum.
220 2023-10-08 David Malcolm <dmalcolm@redhat.com>
223 * access-diagram.cc (boundaries::boundaries): Add logger param
224 (boundaries::add): Add logging.
225 (boundaries::get_hard_boundaries_in_range): New.
226 (boundaries::m_logger): New field.
227 (boundaries::get_table_x_for_offset): Make public.
228 (class svalue_spatial_item): New.
229 (class compound_svalue_spatial_item): New.
230 (add_ellipsis_to_gaps): New.
231 (valid_region_spatial_item::valid_region_spatial_item): Add theme
232 param. Initialize m_boundaries, m_existing_sval, and
233 m_existing_sval_spatial_item.
234 (valid_region_spatial_item::add_boundaries): Set m_boundaries.
235 Add boundaries for any m_existing_sval_spatial_item.
236 (valid_region_spatial_item::add_array_elements_to_table): Rewrite
237 creation of min/max index in terms of
238 maybe_add_array_index_to_table. Rewrite ellipsis code using
239 add_ellipsis_to_gaps. Add index values for any hard boundaries
240 within the valid region.
241 (valid_region_spatial_item::maybe_add_array_index_to_table): New,
242 based on code formerly in add_array_elements_to_table.
243 (valid_region_spatial_item::make_table): Make use of
244 m_existing_sval_spatial_item, if any.
245 (valid_region_spatial_item::m_boundaries): New field.
246 (valid_region_spatial_item::m_existing_sval): New field.
247 (valid_region_spatial_item::m_existing_sval_spatial_item): New
249 (class svalue_spatial_item): Rename to...
250 (class written_svalue_spatial_item): ...this.
251 (class string_region_spatial_item): Rename to..
252 (class string_literal_spatial_item): ...this. Add "kind".
253 (string_literal_spatial_item::add_boundaries): Use m_kind to
254 determine kind of boundary. Update for renaming of m_actual_bits
256 (string_literal_spatial_item::make_table): Likewise. Support not
257 displaying a row for byte indexes, and not displaying a row for
259 (string_literal_spatial_item::add_column_for_byte): Make byte index
261 (svalue_spatial_item::make): Convert to...
262 (make_written_svalue_spatial_item): ...this.
263 (make_existing_svalue_spatial_item): New.
264 (access_diagram_impl::access_diagram_impl): Pass theme to
265 m_valid_region_spatial_item ctor. Update for renaming of
266 m_svalue_spatial_item.
267 (access_diagram_impl::find_boundaries): Pass logger to boundaries.
268 Update for renaming of...
269 (access_diagram_impl::m_svalue_spatial_item): Rename to...
270 (access_diagram_impl::m_written_svalue_spatial_item): ...this.
272 2023-10-03 David Malcolm <dmalcolm@redhat.com>
274 * analyzer-logging.cc (logger::log_va_partial): Use text_info
276 * analyzer.cc (make_label_text): Likewise.
277 (make_label_text_n): Likewise.
278 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
281 2023-10-02 David Malcolm <dmalcolm@redhat.com>
283 * program-point.cc: Update for grouping of source printing fields
284 within diagnostic_context.
286 2023-09-15 David Malcolm <dmalcolm@redhat.com>
288 * analyzer.cc (get_stmt_location): Handle null stmt.
289 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Copy
291 (saved_diagnostic::operator==): Compare m_loc.
292 (saved_diagnostic::calc_best_epath): Only use m_stmt_finder if
294 (dedupe_key::dedupe_key): Initialize m_loc.
295 (dedupe_key::operator==): Compare m_loc.
296 (dedupe_key::get_location): Use m_loc if it's known.
297 (dedupe_key::m_loc): New field.
298 (diagnostic_manager::emit_saved_diagnostic): Only call
299 get_emission_location if m_loc is unknown, preferring to use m_loc
301 * diagnostic-manager.h (saved_diagnostic::m_loc): New field.
302 (pending_location::pending_location): Initialize m_loc. Add
303 overload taking a location_t rather than a stmt/stmt_finder.
304 (pending_location::m_loc): New field.
306 2023-09-15 David Malcolm <dmalcolm@redhat.com>
308 * analyzer.h (struct pending_location): New forward decl.
309 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
310 Replace params "enode", "snode", "stmt", and "stmt_finder" with
312 (diagnostic_manager::add_diagnostic): Likewise for both overloads.
313 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
315 (struct pending_location): New.
316 (diagnostic_manager::add_diagnostic): Replace params "enode",
317 "snode", "stmt", and "stmt_finder" with "ploc".
318 * engine.cc (impl_region_model_context::warn): Update call to
319 add_diagnostic for above change.
320 (impl_sm_context::warn): Likewise.
321 (impl_region_model_context::on_state_leak): Likewise.
322 * infinite-recursion.cc
323 (exploded_graph::detect_infinite_recursion): Likewise.
325 2023-09-15 David Malcolm <dmalcolm@redhat.com>
327 * region-model.cc (region_model::get_gassign_result): Handle
328 volatile ops by using a conjured_svalue.
330 2023-09-14 David Malcolm <dmalcolm@redhat.com>
332 * checker-event.h (checker_event::get_thread_id): New.
333 * checker-path.h (class checker_path): Implement thread-related
334 vfuncs via a single simple_diagnostic_thread instance named
337 2023-09-14 David Malcolm <dmalcolm@redhat.com>
339 * diagnostic-manager.cc (compatible_epath_p): Fix missing return.
341 2023-09-14 David Malcolm <dmalcolm@redhat.com>
343 * diagnostic-manager.cc (process_worklist_item): Use
344 std::unique_ptr rather than plain rejected_constraint *.
345 * engine.cc (exploded_path::feasible_p): Likewise.
346 (feasibility_state::maybe_update_for_edge): Likewise.
347 * exploded-graph.h (feasibility_problem::feasibility_problem):
349 (feasibility_problem::~feasibility_problem): Delete.
350 (feasibility_problem::m_rc): Use std::unique_ptr.
351 (feasibility_state::maybe_update_for_edge): Likewise.
352 * feasible-graph.cc (feasible_graph::add_feasibility_problem):
354 * feasible-graph.h (class infeasible_node): Likewise.
355 (feasible_graph::add_feasibility_problem): Likewise.
356 * region-model.cc (region_model::add_constraint): Likewise.
357 (region_model::maybe_update_for_edge): Likewise.
358 (region_model::apply_constraints_for_gcond): Likewise.
359 (region_model::apply_constraints_for_gswitch): Likewise.
360 (region_model::apply_constraints_for_exception): Likewise.
361 * region-model.h (class region_model): Likewise for decls.
363 2023-09-09 benjamin priour <vultkayn@gcc.gnu.org>
367 (region_model::add_constraints_from_binop): binop_svalues around
368 LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR are now unwrapped.
370 2023-09-07 David Malcolm <dmalcolm@redhat.com>
373 * program-point.cc (program_point::on_edge): Don't reject
374 EDGE_ABNORMAL for computed gotos.
375 * region-model.cc (region_model::maybe_update_for_edge): Handle
376 computed goto statements.
377 (region_model::apply_constraints_for_ggoto): New.
378 * region-model.h (region_model::apply_constraints_for_ggoto): New decl.
379 * supergraph.cc (supernode::get_label): New.
380 * supergraph.h (supernode::get_label): New decl.
382 2023-09-07 benjamin priour <vultkayn@gcc.gnu.org>
383 David Malcolm <dmalcolm@redhat.com>
386 * diagnostic-manager.cc
387 (compatible_epaths_p): New function.
388 (saved_diagnostic::supercedes_p): Now calls the above
389 to determine if the diagnostics do overlap and the superseding
392 2023-09-07 David Malcolm <dmalcolm@redhat.com>
394 * region-model.h: fix -Wunused-parameter warnings
396 2023-09-06 David Malcolm <dmalcolm@redhat.com>
399 * kf.cc (class kf_strstr): New.
400 (kf_strstr::impl_call_post): New.
401 (register_known_functions): Register it.
403 2023-09-06 David Malcolm <dmalcolm@redhat.com>
406 * kf.cc (class kf_strncpy): New.
407 (kf_strncpy::impl_call_post): New.
408 (register_known_functions): Register it.
409 * region-model.cc (region_model::read_bytes): Handle unknown
412 2023-09-06 David Malcolm <dmalcolm@redhat.com>
414 * kf.cc (kf_calloc::impl_call_pre): Pass ctxt to zero_fill_region.
415 (kf_memset::impl_call_pre): Move responsibility for calling
416 check_region_for_write to fill_region.
417 * region-model.cc (region_model::on_assignment): Pass ctxt to
419 (region_model::fill_region): Add "ctxt" param, using it to call
420 check_region_for_write.
421 (region_model::zero_fill_region): Likewise.
422 * region-model.h (region_model::fill_region): Add "ctxt" param.
423 (region_model::zero_fill_region): Likewise.
425 2023-09-01 benjamin priour <priour.be@gmail.com>
429 * analyzer.h (is_placement_new_p): New declaration.
431 (call_details::deref_ptr_arg): New function.
432 Dereference the argument at given index if possible.
433 * call-details.h: Declaration of the above function.
434 * kf-lang-cp.cc (is_placement_new_p): Returns true if the gcall
435 is recognized as a placement new.
436 (kf_operator_delete::impl_call_post): Unbinding a region and its
437 descendents now poisons with POISON_KIND_DELETED.
438 (register_known_functions_lang_cp): Known function "operator
439 delete" is now registered only once independently of its number of
441 * region-model.cc (region_model::eval_condition): Now
442 recursively calls itself if any of the operand is wrapped in a
444 * sm-malloc.cc (malloc_state_machine::on_stmt):
445 Add placement new recognition.
446 * svalue.cc (poison_kind_to_str): Wording for the new PK.
447 * svalue.h (enum poison_kind): Add value POISON_KIND_DELETED.
449 2023-08-31 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
451 * kf.cc: Change spelling to macOS.
453 2023-08-30 Eric Feng <ef2648@columbia.edu>
456 * engine.cc (impl_region_model_context::warn): New optional
458 * exploded-graph.h (class impl_region_model_context): Likewise.
459 * region-model.cc (region_model::pop_frame): New callback
460 feature for region_model::pop_frame.
461 * region-model.h (struct append_regions_cb_data): Likewise.
462 (class region_model): Likewise.
463 (class region_model_context): New optional parameter.
464 (class region_model_context_decorator): Likewise.
466 2023-08-30 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
468 * region-model.cc: Define INCLUDE_ALGORITHM.
470 2023-08-29 David Malcolm <dmalcolm@redhat.com>
473 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
474 selftest::analyzer_ranges_cc_tests.
475 * analyzer-selftests.h (selftest::run_analyzer_selftests): New
477 * analyzer.opt (Wanalyzer-overlapping-buffers): New option.
478 * call-details.cc: Include "analyzer/ranges.h" and "make-unique.h".
479 (class overlapping_buffers): New.
480 (call_details::complain_about_overlap): New.
481 * call-details.h (call_details::complain_about_overlap): New decl.
482 * kf.cc (kf_memcpy_memmove::impl_call_pre): Call
483 cd.complain_about_overlap for memcpy and memcpy_chk.
484 (kf_strcat::impl_call_pre): Call cd.complain_about_overlap.
485 (kf_strcpy::impl_call_pre): Likewise.
486 * ranges.cc: New file.
487 * ranges.h: New file.
489 2023-08-29 David Malcolm <dmalcolm@redhat.com>
492 * kf.cc (kf_strdup::impl_call_pre): Set size of
493 dynamically-allocated buffer. Simulate copying the string from
494 the source region to the new buffer.
496 2023-08-27 benjamin priour <vultkayn@gcc.gnu.org>
499 * analyzer.h (class known_function): Add virtual casts
500 to builtin_known_function.
501 (class builtin_known_function): New subclass of known_function
503 * kf.cc (class kf_alloca): Now derived from
504 builtin_known_function.
505 (class kf_calloc): Likewise.
506 (class kf_free): Likewise.
507 (class kf_malloc): Likewise.
508 (class kf_memcpy_memmove): Likewise.
509 (class kf_memset): Likewise.
510 (class kf_realloc): Likewise.
511 (class kf_strchr): Likewise.
512 (class kf_sprintf): Likewise.
513 (class kf_strcat): Likewise.
514 (class kf_strcpy): Likewise.
515 (class kf_strdup): Likewise.
516 (class kf_strlen): Likewise.
517 (class kf_strndup): Likewise.
518 (register_known_functions): Builtins are now registered as
519 known_functions by name rather than by their BUILTIN_CODE.
520 * known-function-manager.cc (get_normal_builtin): New overload.
521 * known-function-manager.h: New overload declaration.
522 * region-model.cc (region_model::get_builtin_kf): New function.
523 * region-model.h (class region_model): Add declaration of
525 * sm-fd.cc: For called recognized as builtins, use the
526 attributes of that builtin as defined in gcc/builtins.def
527 rather than the user's.
528 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
530 2023-08-25 David Malcolm <dmalcolm@redhat.com>
532 * access-diagram.cc (class string_region_spatial_item): Remove
533 assumption that the string is written to the start of the cluster.
535 2023-08-24 David Malcolm <dmalcolm@redhat.com>
539 (call_details::check_for_null_terminated_string_arg): Split into
540 overloads, one taking just an arg_idx, the other a new
541 "include_terminator" param.
542 * call-details.h: Likewise.
543 * kf.cc (class kf_strcat): New.
544 (kf_strcpy::impl_call_pre): Update for change to
545 check_for_null_terminated_string_arg.
546 (register_known_functions): Register kf_strcat.
548 (region_model::check_for_null_terminated_string_arg): Split into
549 overloads, one taking just an arg_idx, the other a new
550 "include_terminator" param. When returning an svalue, handle
551 "include_terminator" being false by subtracting one.
553 (region_model::check_for_null_terminated_string_arg): Split into
554 overloads, one taking just an arg_idx, the other a new
555 "include_terminator" param.
557 2023-08-24 David Malcolm <dmalcolm@redhat.com>
560 * region-model.cc (fragment::has_null_terminator): Handle
563 2023-08-24 David Malcolm <dmalcolm@redhat.com>
566 * region-model-manager.cc
567 (region_model_manager::get_or_create_initial_value): Simplify
568 INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) to
569 CONSTANT_SVAL(STRING[N]).
571 2023-08-24 David Malcolm <dmalcolm@redhat.com>
574 * region-model.cc (fragment::has_null_terminator): Move STRING_CST
575 handling to fragment::string_cst_has_null_terminator; also use it to
576 handle INIT_VAL(STRING_REG).
577 (fragment::string_cst_has_null_terminator): New, from above.
579 2023-08-24 David Malcolm <dmalcolm@redhat.com>
581 * kf.cc (kf_memcpy_memmove::impl_call_pre): Reimplement using
582 region_model::copy_bytes.
583 * region-model.cc (region_model::read_bytes): New.
584 (region_model::copy_bytes): New.
585 * region-model.h (region_model::read_bytes): New decl.
586 (region_model::copy_bytes): New decl.
588 2023-08-24 David Malcolm <dmalcolm@redhat.com>
591 * region-model.cc (region_model::get_string_size): Delete both.
592 * region-model.h (region_model::get_string_size): Delete both
595 2023-08-24 David Malcolm <dmalcolm@redhat.com>
598 * kf.cc (kf_strcpy::impl_call_pre): Reimplement using
599 check_for_null_terminated_string_arg.
600 * region-model.cc (region_model::get_store_bytes): Shortcut
601 reading all of a string_region.
602 (region_model::scan_for_null_terminator): Use get_store_value for
603 the bytes rather than "unknown" when returning an unknown length.
604 (region_model::write_bytes): New.
605 * region-model.h (region_model::write_bytes): New decl.
607 2023-08-24 David Malcolm <dmalcolm@redhat.com>
610 * region-model.cc (iterable_cluster::iterable_cluster): Add
611 symbolic binding keys to m_symbolic_bindings.
612 (iterable_cluster::has_symbolic_bindings_p): New.
613 (iterable_cluster::m_symbolic_bindings): New field.
614 (region_model::scan_for_null_terminator): Treat clusters with
615 symbolic bindings as having unknown strlen.
617 2023-08-24 David Malcolm <dmalcolm@redhat.com>
619 * engine.cc (impl_path_context::impl_path_context): Add logger
621 (impl_path_context::bifurcate): Add log message.
622 (impl_path_context::terminate_path): Likewise.
623 (impl_path_context::m_logger): New field.
624 (exploded_graph::process_node): Pass logger to path_ctxt ctor.
626 2023-08-22 David Malcolm <dmalcolm@redhat.com>
629 * kf-analyzer.cc (class kf_analyzer_get_strlen): Move to kf.cc.
630 (register_known_analyzer_functions): Use make_kf_strlen.
631 * kf.cc (class kf_strlen::impl_call_pre): Replace with
632 implementation of kf_analyzer_get_strlen from kf-analyzer.cc.
633 Handle "UNKNOWN" return from check_for_null_terminated_string_arg
634 by falling back to a conjured svalue.
635 (make_kf_strlen): New.
636 (register_known_functions): Use make_kf_strlen.
637 * known-function-manager.h (make_kf_strlen): New decl.
639 2023-08-22 David Malcolm <dmalcolm@redhat.com>
642 * call-details.cc (call_details::call_details): New ctor.
643 * call-details.h (call_details::call_details): New ctor decl.
644 (struct call_arg_details): Move here from region-model.cc.
645 * region-model.cc (region_model::check_call_format_attr): New.
646 (region_model::check_call_args): Call it.
647 (struct call_arg_details): Move it to call-details.h.
648 * region-model.h (region_model::check_call_format_attr): New decl.
650 2023-08-22 David Malcolm <dmalcolm@redhat.com>
652 * kf.cc (class kf_fopen): New.
653 (register_known_functions): Register it.
655 2023-08-22 David Malcolm <dmalcolm@redhat.com>
658 * analyzer.opt (Wanalyzer-unterminated-string): Delete.
660 (call_details::check_for_null_terminated_string_arg): Convert
661 return type from void to const svalue *. Add param "out_sval".
663 (call_details::check_for_null_terminated_string_arg): Likewise.
664 * kf-analyzer.cc (kf_analyzer_get_strlen::impl_call_pre): Wire up
665 to result of check_for_null_terminated_string_arg.
666 * region-model.cc (get_strlen): Delete.
667 (class unterminated_string_arg): Delete.
668 (struct fragment): New.
669 (class iterable_cluster): New.
670 (region_model::get_store_bytes): New.
671 (get_tree_for_byte_offset): New.
672 (region_model::scan_for_null_terminator): New.
673 (region_model::check_for_null_terminated_string_arg): Convert
674 return type from void to const svalue *. Add param "out_sval".
675 Reimplement in terms of scan_for_null_terminator, dropping the
676 special-case for -Wanalyzer-unterminated-string.
677 * region-model.h (region_model::get_store_bytes): New decl.
678 (region_model::scan_for_null_terminator): New decl.
679 (region_model::check_for_null_terminated_string_arg): Convert
680 return type from void to const svalue *. Add param "out_sval".
681 * store.cc (concrete_binding::get_byte_range): New.
682 * store.h (concrete_binding::get_byte_range): New decl.
683 (store_manager::get_concrete_binding): New overload.
685 2023-08-22 David Malcolm <dmalcolm@redhat.com>
687 * region-model.cc (region_model_context_decorator::add_event):
688 Handle m_inner being NULL.
689 * region-model.h (class region_model_context_decorator): Likewise.
690 (annotating_context::warn): Likewise.
692 2023-08-22 David Malcolm <dmalcolm@redhat.com>
694 * diagnostic-manager.cc (saved_diagnostic::add_event): New.
695 (saved_diagnostic::add_any_saved_events): New.
696 (diagnostic_manager::add_event): New.
697 (dedupe_winners::emit_best): New.
698 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
699 non-const. Call saved_diagnostic::add_any_saved_events.
700 * diagnostic-manager.h (saved_diagnostic::add_event): New decl.
701 (saved_diagnostic::add_any_saved_events): New decl.
702 (saved_diagnostic::m_saved_events): New field.
703 (diagnostic_manager::add_event): New decl.
704 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
706 * engine.cc (impl_region_model_context::add_event): New.
707 * exploded-graph.h (impl_region_model_context::add_event): New decl.
709 (noop_region_model_context::add_event): New.
710 (region_model_context_decorator::add_event): New.
711 * region-model.h (region_model_context::add_event): New vfunc.
712 (noop_region_model_context::add_event): New decl.
713 (region_model_context_decorator::add_event): New decl.
715 2023-08-22 David Malcolm <dmalcolm@redhat.com>
718 (class check_external_function_for_access_attr::annotating_ctxt):
719 Convert to an annotating_context.
720 * region-model.h (class note_adding_context): Rename to...
721 (class annotating_context): ...this, updating the "warn" method.
722 (note_adding_context::make_note): Replace with...
723 (annotating_context::add_annotations): ...this.
725 2023-08-14 benjamin priour <vultkayn@gcc.gnu.org>
728 * analyzer.opt: Add new option.
729 * diagnostic-manager.cc
730 (diagnostic_manager::prune_path): Call prune_system_headers.
731 (prune_frame): New function that deletes all events in a frame.
732 (diagnostic_manager::prune_system_headers): New function.
733 * diagnostic-manager.h: Add prune_system_headers declaration.
735 2023-08-11 David Malcolm <dmalcolm@redhat.com>
738 * analyzer.opt (Wanalyzer-unterminated-string): New.
740 (call_details::check_for_null_terminated_string_arg): New.
742 (call_details::check_for_null_terminated_string_arg): New decl.
743 * kf-analyzer.cc (class kf_analyzer_get_strlen): New.
744 (register_known_analyzer_functions): Register it.
745 * kf.cc (kf_error::impl_call_pre): Check that format arg is a
746 valid null-terminated string.
747 (kf_putenv::impl_call_pre): Likewise for the sole param.
748 (kf_strchr::impl_call_pre): Likewise for the first param.
749 (kf_strcpy::impl_call_pre): Likewise for the second param.
750 (kf_strdup::impl_call_pre): Likewise for the sole param.
751 * region-model.cc (get_strlen): New.
752 (struct call_arg_details): New.
753 (inform_about_expected_null_terminated_string_arg): New.
754 (class unterminated_string_arg): New.
755 (region_model::check_for_null_terminated_string_arg): New.
757 (region_model::check_for_null_terminated_string_arg): New decl.
759 2023-08-11 Eric Feng <ef2648@columbia.edu>
762 * call-details.h: New function.
763 * region-model.cc (region_model::get_or_create_region_for_heap_alloc):
764 New optional parameters.
765 * region-model.h (class region_model): New optional parameters.
766 * sm-malloc.cc (on_realloc_with_move): New function.
767 (region_model::transition_ptr_sval_non_null): New function.
769 2023-08-09 David Malcolm <dmalcolm@redhat.com>
771 * analyzer.h (class pure_known_function_with_default_return): New
773 * call-details.cc (const_fn_p): Move here from region-model.cc.
774 (maybe_get_const_fn_result): Likewise.
775 (get_result_size_in_bytes): Likewise.
776 (call_details::set_any_lhs_with_defaults): New function, based on
777 code in region_model::on_call_pre.
778 * call-details.h (call_details::set_any_lhs_with_defaults): New
780 * diagnostic-manager.cc
781 (diagnostic_manager::emit_saved_diagnostic): Log the index of the
783 * kf.cc (pure_known_function_with_default_return::impl_call_pre):
785 (kf_memset::impl_call_pre): Set the LHS to the first param.
786 (kf_putenv::impl_call_pre): Call cd.set_any_lhs_with_defaults.
787 (kf_sprintf::impl_call_pre): Call cd.set_any_lhs_with_defaults.
788 (class kf_stack_restore): Derive from
789 pure_known_function_with_default_return.
790 (class kf_stack_save): Likewise.
791 (kf_strlen::impl_call_pre): Call cd.set_any_lhs_with_defaults.
792 * region-model-reachability.cc (reachable_regions::handle_sval):
793 Remove logic for symbolic regions for pointers.
794 * region-model.cc (region_model::canonicalize): Remove purging of
795 dynamic extents workaround for surplus values from
796 region_model::on_call_pre's default LHS code.
797 (const_fn_p): Move to call-details.cc.
798 (maybe_get_const_fn_result): Likewise.
799 (get_result_size_in_bytes): Likewise.
800 (region_model::update_for_nonzero_return): Call
801 cd.set_any_lhs_with_defaults.
802 (region_model::on_call_pre): Remove the assignment to the LHS of a
803 default return value, instead requiring all known_function
804 implementations to write to any LHS of the call. Use
805 cd.set_any_lhs_with_defaults on the non-kf paths.
806 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Use
807 cd.set_any_lhs_with_defaults when failing to get at fd state.
808 (kf_bind::outcome_of_bind::update_model): Likewise.
809 (kf_listen::outcome_of_listen::update_model): Likewise.
810 (kf_accept::outcome_of_accept::update_model): Likewise.
811 (kf_connect::outcome_of_connect::update_model): Likewise.
812 (kf_read::impl_call_pre): Use cd.set_any_lhs_with_defaults.
813 * sm-file.cc (class kf_stdio_output_fn): Derive from
814 pure_known_function_with_default_return.
815 (class kf_ferror): Likewise.
816 (class kf_fileno): Likewise.
817 (kf_fgets::impl_call_pre): Use cd.set_any_lhs_with_defaults.
818 (kf_read::impl_call_pre): Likewise.
819 (class kf_getc): Derive from
820 pure_known_function_with_default_return.
821 (class kf_getchar): Likewise.
822 * varargs.cc (kf_va_arg::impl_call_pre): Use
823 cd.set_any_lhs_with_defaults.
825 2023-08-04 David Malcolm <dmalcolm@redhat.com>
828 * bounds-checking.cc (region_model::check_region_bounds): Handle
829 symbolic base regions.
830 * call-details.cc: Include "stringpool.h" and "attribs.h".
831 (call_details::lookup_function_attribute): New function.
832 * call-details.h (call_details::lookup_function_attribute): New
834 * region-model-manager.cc
835 (region_model_manager::maybe_fold_binop): Add reference to
837 * region-model-reachability.cc (reachable_regions::handle_sval):
838 Add symbolic regions for pointers that are conjured svalues for
840 * region-model.cc (region_model::canonicalize): Purge dynamic
841 extents for regions that aren't referenced.
842 (get_result_size_in_bytes): New function.
843 (region_model::on_call_pre): Use get_result_size_in_bytes and
844 potentially set the dynamic extents of the region pointed to by
846 (region_model::deref_rvalue): Add param "add_nonnull_constraint"
847 and use it to conditionalize adding the constraint.
848 (pending_diagnostic_subclass::dubious_allocation_size): Add "stmt"
849 param to both ctors and use it to initialize new "m_stmt" field.
850 (pending_diagnostic_subclass::operator==): Use m_stmt; don't use
852 (pending_diagnostic_subclass::m_stmt): New field.
853 (region_model::check_region_size): Generalize to any kind of
854 pointer svalue by using deref_rvalue rather than checking for
855 region_svalue. Pass stmt to dubious_allocation_size ctor.
856 * region-model.h (region_model::deref_rvalue): Add param
857 "add_nonnull_constraint".
858 * svalue.cc (conjured_svalue::lhs_value_p): New function.
859 * svalue.h (conjured_svalue::lhs_value_p): New decl.
861 2023-08-04 David Malcolm <dmalcolm@redhat.com>
863 * svalue.cc (region_svalue::dump_to_pp): Support NULL type.
864 (constant_svalue::dump_to_pp): Likewise.
865 (initial_svalue::dump_to_pp): Likewise.
866 (conjured_svalue::dump_to_pp): Likewise. Fix missing print of the
869 2023-08-03 David Malcolm <dmalcolm@redhat.com>
872 * region.cc (int_size_in_bits): Fail on zero-sized types.
874 2023-08-02 Eric Feng <ef2648@columbia.edu>
877 * analyzer-language.cc (run_callbacks): New function.
878 (on_finish_translation_unit): New function.
879 * analyzer-language.h (GCC_ANALYZER_LANGUAGE_H): New include.
880 (class translation_unit): New vfuncs.
882 2023-07-26 David Malcolm <dmalcolm@redhat.com>
885 * region-model-manager.cc
886 (region_model_manager::region_model_manager): Update for
887 generalizing region ids to also cover svalues.
888 (region_model_manager::get_or_create_constant_svalue): Likewise.
889 (region_model_manager::get_or_create_unknown_svalue): Likewise.
890 (region_model_manager::create_unique_svalue): Likewise.
891 (region_model_manager::get_or_create_initial_value): Likewise.
892 (region_model_manager::get_or_create_setjmp_svalue): Likewise.
893 (region_model_manager::get_or_create_poisoned_svalue): Likewise.
894 (region_model_manager::get_ptr_svalue): Likewise.
895 (region_model_manager::get_or_create_unaryop): Likewise.
896 (region_model_manager::get_or_create_binop): Likewise.
897 (region_model_manager::get_or_create_sub_svalue): Likewise.
898 (region_model_manager::get_or_create_repeated_svalue): Likewise.
899 (region_model_manager::get_or_create_bits_within): Likewise.
900 (region_model_manager::get_or_create_unmergeable): Likewise.
901 (region_model_manager::get_or_create_widening_svalue): Likewise.
902 (region_model_manager::get_or_create_compound_svalue): Likewise.
903 (region_model_manager::get_or_create_conjured_svalue): Likewise.
904 (region_model_manager::get_or_create_asm_output_svalue): Likewise.
905 (region_model_manager::get_or_create_const_fn_result_svalue):
907 (region_model_manager::get_region_for_fndecl): Likewise.
908 (region_model_manager::get_region_for_label): Likewise.
909 (region_model_manager::get_region_for_global): Likewise.
910 (region_model_manager::get_field_region): Likewise.
911 (region_model_manager::get_element_region): Likewise.
912 (region_model_manager::get_offset_region): Likewise.
913 (region_model_manager::get_sized_region): Likewise.
914 (region_model_manager::get_cast_region): Likewise.
915 (region_model_manager::get_frame_region): Likewise.
916 (region_model_manager::get_symbolic_region): Likewise.
917 (region_model_manager::get_region_for_string): Likewise.
918 (region_model_manager::get_bit_range): Likewise.
919 (region_model_manager::get_var_arg_region): Likewise.
920 (region_model_manager::get_region_for_unexpected_tree_code):
922 (region_model_manager::get_or_create_region_for_heap_alloc):
924 (region_model_manager::create_region_for_alloca): Likewise.
925 (region_model_manager::log_stats): Likewise.
926 * region-model-manager.h (region_model_manager::get_num_regions):
928 (region_model_manager::get_num_symbols): ...this.
929 (region_model_manager::alloc_region_id): Replace with...
930 (region_model_manager::alloc_symbol_id): ...this.
931 (region_model_manager::m_next_region_id): Replace with...
932 (region_model_manager::m_next_symbol_id): ...this.
933 * region-model.cc (selftest::test_get_representative_tree): Update
934 for generalizing region ids to also cover svalues.
935 (selftest::test_binop_svalue_folding): Likewise.
936 (selftest::test_state_merging): Likewise.
937 * region.cc (region::cmp_ids): Delete, in favor of
939 (region::region): Update for introduction of symbol base class.
940 (frame_region::get_region_for_local): Likewise.
941 (root_region::root_region): Likewise.
942 (symbolic_region::symbolic_region): Likewise.
943 * region.h: Replace include of "analyzer/complexity.h" with
945 (class region): Make a subclass of symbol.
946 (region::get_id): Delete in favor of symbol::get_id.
947 (region::cmp_ids): Delete in favor of symbol::cmp_ids.
948 (region::get_complexity): Delete in favor of
949 symbol::get_complexity.
950 (region::region): Use symbol::id_t for "id" param.
951 (region::m_complexity): Move field to symbol base class.
952 (region::m_id): Likewise.
953 (space_region::space_region): Use symbol::id_t for "id" param.
954 (frame_region::frame_region): Likewise.
955 (globals_region::globals_region): Likewise.
956 (code_region::code_region): Likewise.
957 (function_region::function_region): Likewise.
958 (label_region::label_region): Likewise.
959 (stack_region::stack_region): Likewise.
960 (heap_region::heap_region): Likewise.
961 (thread_local_region::thread_local_region): Likewise.
962 (root_region::root_region): Likewise.
963 (symbolic_region::symbolic_region): Likewise.
964 (decl_region::decl_region): Likewise.
965 (field_region::field_region): Likewise.
966 (element_region::element_region): Likewise.
967 (offset_region::offset_region): Likewise.
968 (sized_region::sized_region): Likewise.
969 (cast_region::cast_region): Likewise.
970 (heap_allocated_region::heap_allocated_region): Likewise.
971 (alloca_region::alloca_region): Likewise.
972 (string_region::string_region): Likewise.
973 (bit_range_region::bit_range_region): Likewise.
974 (var_arg_region::var_arg_region): Likewise.
975 (errno_region::errno_region): Likewise.
976 (unknown_region::unknown_region): Likewise.
977 * svalue.cc (sub_svalue::sub_svalue): Add symbol::id_t param.
978 (repeated_svalue::repeated_svalue): Likewise.
979 (bits_within_svalue::bits_within_svalue): Likewise.
980 (compound_svalue::compound_svalue): Likewise.
981 * svalue.h: Replace include of "analyzer/complexity.h" with
983 (class svalue): Make a subclass of symbol.
984 (svalue::get_complexity): Delete in favor of
985 symbol::get_complexity.
986 (svalue::svalue): Add symbol::id_t param. Update for new base
988 (svalue::m_complexity): Delete in favor of
989 symbol::m_complexity.
990 (region_svalue::region_svalue): Add symbol::id_t param
991 (constant_svalue::constant_svalue): Likewise.
992 (unknown_svalue::unknown_svalue): Likewise.
993 (poisoned_svalue::poisoned_svalue): Likewise.
994 (setjmp_svalue::setjmp_svalue): Likewise.
995 (initial_svalue::initial_svalue): Likewise.
996 (unaryop_svalue::unaryop_svalue): Likewise.
997 (binop_svalue::binop_svalue): Likewise.
998 (sub_svalue::sub_svalue): Likewise.
999 (repeated_svalue::repeated_svalue): Likewise.
1000 (bits_within_svalue::bits_within_svalue): Likewise.
1001 (unmergeable_svalue::unmergeable_svalue): Likewise.
1002 (placeholder_svalue::placeholder_svalue): Likewise.
1003 (widening_svalue::widening_svalue): Likewise.
1004 (compound_svalue::compound_svalue): Likewise.
1005 (conjured_svalue::conjured_svalue): Likewise.
1006 (asm_output_svalue::asm_output_svalue): Likewise.
1007 (const_fn_result_svalue::const_fn_result_svalue): Likewise.
1008 * symbol.cc: New file.
1009 * symbol.h: New file.
1011 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1014 * region-model.cc (region_model::get_gassign_result): Only check
1015 for bad shift counts when dealing with an integral type.
1017 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1020 PR middle-end/110612
1021 * access-diagram.cc (class spatial_item): Add virtual dtor.
1023 2023-07-21 David Malcolm <dmalcolm@redhat.com>
1026 * region.h (struct cast_region::key_t): Support "m_type" being
1027 null by using "m_original_region" for empty/deleted slots.
1029 2023-07-19 David Malcolm <dmalcolm@redhat.com>
1032 * region-model-manager.cc
1033 (region_model_manager::get_or_create_int_cst): Assert that we have
1034 an integral or pointer type.
1035 * sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
1036 Don't check non-integral types.
1038 2023-06-29 benjamin priour <priour.be@gmail.com>
1041 * region-model-manager.cc
1042 (region_model_manager::get_or_create_initial_value): Take an
1043 optional boolean value to bypass poisoning checks
1044 * region-model-manager.h: Update declaration of the above function.
1045 * region-model.cc (region_model::get_store_value): No longer returns
1046 on OOB, but rather gives a boolean to get_or_create_initial_value.
1047 (region_model::check_region_access): Update docstring.
1048 (region_model::check_region_for_write): Update docstring.
1050 2023-06-24 David Malcolm <dmalcolm@redhat.com>
1052 * access-diagram.cc: Add #define INCLUDE_VECTOR.
1053 * bounds-checking.cc: Likewise.
1055 2023-06-22 David Malcolm <dmalcolm@redhat.com>
1058 * access-diagram.cc: New file.
1059 * access-diagram.h: New file.
1060 * analyzer.h (class region_offset): Add default ctor.
1061 (region_offset::make_byte_offset): New decl.
1062 (region_offset::concrete_p): New.
1063 (region_offset::get_concrete_byte_offset): New.
1064 (region_offset::calc_symbolic_bit_offset): New decl.
1065 (region_offset::calc_symbolic_byte_offset): New decl.
1066 (region_offset::dump_to_pp): New decl.
1067 (region_offset::dump): New decl.
1068 (operator<, operator<=, operator>, operator>=): New decls for
1071 (-param=analyzer-text-art-string-ellipsis-threshold=): New.
1072 (-param=analyzer-text-art-string-ellipsis-head-len=): New.
1073 (-param=analyzer-text-art-string-ellipsis-tail-len=): New.
1074 (-param=analyzer-text-art-ideal-canvas-width=): New.
1075 (fanalyzer-debug-text-art): New.
1076 * bounds-checking.cc: Include "intl.h", "diagnostic-diagram.h",
1077 and "analyzer/access-diagram.h".
1078 (class out_of_bounds::oob_region_creation_event_capacity): New.
1079 (out_of_bounds::out_of_bounds): Add "model" and "sval_hint"
1081 (out_of_bounds::mark_interesting_stuff): Use the base region.
1082 (out_of_bounds::add_region_creation_events): Use
1083 oob_region_creation_event_capacity.
1084 (out_of_bounds::get_dir): New pure vfunc.
1085 (out_of_bounds::maybe_show_notes): New.
1086 (out_of_bounds::maybe_show_diagram): New.
1087 (out_of_bounds::make_access_diagram): New.
1088 (out_of_bounds::m_model): New field.
1089 (out_of_bounds::m_sval_hint): New field.
1090 (out_of_bounds::m_region_creation_event_id): New field.
1091 (concrete_out_of_bounds::concrete_out_of_bounds): Update for new
1093 (concrete_past_the_end::concrete_past_the_end): Likewise.
1094 (concrete_past_the_end::add_region_creation_events): Use
1095 oob_region_creation_event_capacity.
1096 (concrete_buffer_overflow::concrete_buffer_overflow): Update for
1098 (concrete_buffer_overflow::emit): Replace call to
1099 maybe_describe_array_bounds with maybe_show_notes.
1100 (concrete_buffer_overflow::get_dir): New.
1101 (concrete_buffer_over_read::concrete_buffer_over_read): Update for
1103 (concrete_buffer_over_read::emit): Replace call to
1104 maybe_describe_array_bounds with maybe_show_notes.
1105 (concrete_buffer_overflow::get_dir): New.
1106 (concrete_buffer_underwrite::concrete_buffer_underwrite): Update
1108 (concrete_buffer_underwrite::emit): Replace call to
1109 maybe_describe_array_bounds with maybe_show_notes.
1110 (concrete_buffer_underwrite::get_dir): New.
1111 (concrete_buffer_under_read::concrete_buffer_under_read): Update
1113 (concrete_buffer_under_read::emit): Replace call to
1114 maybe_describe_array_bounds with maybe_show_notes.
1115 (concrete_buffer_under_read::get_dir): New.
1116 (symbolic_past_the_end::symbolic_past_the_end): Update for new
1118 (symbolic_buffer_overflow::symbolic_buffer_overflow): Likewise.
1119 (symbolic_buffer_overflow::emit): Call maybe_show_notes.
1120 (symbolic_buffer_overflow::get_dir): New.
1121 (symbolic_buffer_over_read::symbolic_buffer_over_read): Update for
1123 (symbolic_buffer_over_read::emit): Call maybe_show_notes.
1124 (symbolic_buffer_over_read::get_dir): New.
1125 (region_model::check_symbolic_bounds): Add "sval_hint" param. Pass
1126 it and sized_offset_reg to diagnostics.
1127 (region_model::check_region_bounds): Add "sval_hint" param, passing
1129 * diagnostic-manager.cc
1130 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
1131 pending_diagnostic::emit.
1132 * engine.cc: Add logger param to pending_diagnostic::emit
1134 * infinite-recursion.cc: Likewise.
1135 * kf-analyzer.cc: Likewise.
1136 * kf.cc: Likewise. Add nullptr for new param of
1137 check_region_for_write.
1138 * pending-diagnostic.h: Likewise in decl.
1139 * region-model-manager.cc
1140 (region_model_manager::get_or_create_int_cst): Convert param from
1141 poly_int64 to const poly_wide_int_ref &.
1142 (region_model_manager::maybe_fold_binop): Support type being NULL
1143 when checking for floating-point types.
1144 Check for (X + Y) - X => Y. Be less strict about types when folding
1145 associative ops. Check for (X + Y) * CST => (X * CST) + (Y * CST).
1146 * region-model-manager.h
1147 (region_model_manager::get_or_create_int_cst): Convert param from
1148 poly_int64 to const poly_wide_int_ref &.
1149 * region-model.cc: Add logger param to pending_diagnostic::emit
1151 (region_model::check_external_function_for_access_attr): Update
1152 for new param of check_region_for_write.
1153 (region_model::deref_rvalue): Use nullptr rather than NULL.
1154 (region_model::get_capacity): Handle RK_STRING.
1155 (region_model::check_region_access): Add "sval_hint" param; pass it to
1156 check_region_bounds.
1157 (region_model::check_region_for_write): Add "sval_hint" param;
1158 pass it to check_region_access.
1159 (region_model::check_region_for_read): Add NULL for new param to
1160 check_region_access.
1161 (region_model::set_value): Pass rhs_sval to
1162 check_region_for_write.
1163 (region_model::get_representative_path_var_1): Handle SK_CONSTANT
1164 in the check for infinite recursion.
1165 * region-model.h (region_model::check_region_for_write): Add
1167 (region_model::check_region_access): Likewise.
1168 (region_model::check_symbolic_bounds): Likewise.
1169 (region_model::check_region_bounds): Likewise.
1170 * region.cc (region_offset::make_byte_offset): New.
1171 (region_offset::calc_symbolic_bit_offset): New.
1172 (region_offset::calc_symbolic_byte_offset): New.
1173 (region_offset::dump_to_pp): New.
1174 (region_offset::dump): New.
1175 (struct linear_op): New.
1176 (operator<, operator<=, operator>, operator>=): New, for
1178 (region::get_next_offset): New.
1179 (region::get_relative_symbolic_offset): Use ptrdiff_type_node.
1180 (field_region::get_relative_symbolic_offset): Likewise.
1181 (element_region::get_relative_symbolic_offset): Likewise.
1182 (bit_range_region::get_relative_symbolic_offset): Likewise.
1183 * region.h (region::get_next_offset): New decl.
1184 * sm-fd.cc: Add logger param to pending_diagnostic::emit
1186 * sm-file.cc: Likewise.
1187 * sm-malloc.cc: Likewise.
1188 * sm-pattern-test.cc: Likewise.
1189 * sm-sensitive.cc: Likewise.
1190 * sm-signal.cc: Likewise.
1191 * sm-taint.cc: Likewise.
1192 * store.cc (bit_range::contains_p): Allow "out" to be null.
1193 * store.h (byte_range::get_start_bit_offset): New.
1194 (byte_range::get_next_bit_offset): New.
1195 * varargs.cc: Add logger param to pending_diagnostic::emit
1198 2023-06-10 Tim Lange <mail@tim-lange.me>
1201 * constraint-manager.cc (class sval_finder): Visitor to find
1202 childs in svalue trees.
1203 (constraint_manager::sval_constrained_p): Add new function to
1204 check whether a sval might be part of an constraint.
1205 * constraint-manager.h: Add sval_constrained_p function.
1206 * region-model.cc (class size_visitor): Reverse behavior to not
1207 emit a warning on not explicitly considered cases.
1208 (region_model::check_region_size):
1209 Adapt to size_visitor changes.
1211 2023-06-09 David Malcolm <dmalcolm@redhat.com>
1214 * region-model.cc (region_model::get_initial_value_for_global):
1215 Move code to region::calc_initial_value_at_main.
1216 * region.cc (region::get_initial_value_at_main): New function.
1217 (region::calc_initial_value_at_main): New function, based on code
1218 in region_model::get_initial_value_for_global.
1219 (region::region): Initialize m_cached_init_sval_at_main.
1220 (decl_region::get_svalue_for_constructor): Add a cache, splitting
1222 (decl_region::calc_svalue_for_constructor): ...this new function.
1223 * region.h (region::get_initial_value_at_main): New decl.
1224 (region::calc_initial_value_at_main): New decl.
1225 (region::m_cached_init_sval_at_main): New field.
1226 (decl_region::decl_region): Initialize m_ctor_svalue.
1227 (decl_region::calc_svalue_for_constructor): New decl.
1228 (decl_region::m_ctor_svalue): New field.
1230 2023-06-08 Benjamin Priour <vultkayn@gcc.gnu.org>
1232 * bounds-checking.cc (region_model::check_symbolic_bounds): Returns whether the BASE_REG
1233 region access was OOB.
1234 (region_model::check_region_bounds): Likewise.
1235 * region-model.cc (region_model::get_store_value): Creates an
1236 unknown svalue on OOB-read access to REG.
1237 (region_model::check_region_access): Returns whether an unknown svalue needs be created.
1238 (region_model::check_region_for_read): Passes check_region_access return value.
1239 * region-model.h: Update prior function definitions.
1241 2023-06-02 David Malcolm <dmalcolm@redhat.com>
1244 * kf.cc (class kf_atomic_exchange): New.
1245 (class kf_atomic_exchange_n): New.
1246 (class kf_atomic_fetch_op): New.
1247 (class kf_atomic_op_fetch): New.
1248 (class kf_atomic_load): New.
1249 (class kf_atomic_load_n): New.
1250 (class kf_atomic_store_n): New.
1251 (register_atomic_builtins): New function.
1252 (register_known_functions): Call register_atomic_builtins.
1254 2023-06-02 David Malcolm <dmalcolm@redhat.com>
1256 * store.cc (store::eval_alias_1): Regions in different memory
1259 2023-05-18 Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
1261 * region-model-manager.cc (get_code_for_cast): Use _P defines from
1263 (region_model_manager::get_or_create_cast): Ditto.
1264 (region_model_manager::get_region_for_global): Ditto.
1265 * region-model.cc (region_model::get_lvalue_1): Ditto.
1266 * region.cc (decl_region::maybe_get_constant_value): Ditto.
1268 2023-03-22 David Malcolm <dmalcolm@redhat.com>
1271 * program-point.cc: Include "analyzer/inlining-iterator.h".
1272 (program_point::effectively_intraprocedural_p): New function.
1273 * program-point.h (program_point::effectively_intraprocedural_p):
1275 * sm-malloc.cc (deref_before_check::emit): Use it when rejecting
1276 interprocedural cases, so that we reject interprocedural cases
1277 that have become intraprocedural due to inlining.
1279 2023-03-18 David Malcolm <dmalcolm@redhat.com>
1282 * region-model.cc (region_model::on_longjmp): Pass false for
1283 new "eval_return_svalue" param of pop_frame.
1284 (region_model::pop_frame): Add new "eval_return_svalue" param and
1285 use it to suppress the call to get_rvalue on the result when
1286 needed by on_longjmp.
1287 * region-model.h (region_model::pop_frame): Add new
1288 "eval_return_svalue" param.
1290 2023-03-10 David Malcolm <dmalcolm@redhat.com>
1293 * region-model.cc (region_model::mark_region_as_unknown): Gather a
1294 set of maybe-live svalues and call on_maybe_live_values with it.
1295 * store.cc (binding_map::remove_overlapping_bindings): Add new
1296 "maybe_live_values" param; add any removed svalues to it.
1297 (binding_cluster::clobber_region): Add NULL as new param of
1298 remove_overlapping_bindings.
1299 (binding_cluster::mark_region_as_unknown): Add "maybe_live_values"
1300 param and pass it to remove_overlapping_bindings.
1301 (binding_cluster::maybe_get_compound_binding): Add NULL for new
1302 param of binding_map::remove_overlapping_bindings.
1303 (binding_cluster::remove_overlapping_bindings): Add
1304 "maybe_live_values" param and pass to
1305 binding_map::remove_overlapping_bindings.
1306 (store::set_value): Capture a set of maybe-live svalues, and call
1307 on_maybe_live_values with it.
1308 (store::on_maybe_live_values): New.
1309 (store::mark_region_as_unknown): Add "maybe_live_values" param
1310 and pass it to binding_cluster::mark_region_as_unknown.
1311 (store::remove_overlapping_bindings): Pass NULL for new param of
1312 binding_cluster::remove_overlapping_bindings.
1313 * store.h (binding_map::remove_overlapping_bindings): Add
1314 "maybe_live_values" param.
1315 (binding_cluster::mark_region_as_unknown): Likewise.
1316 (binding_cluster::remove_overlapping_bindings): Likewise.
1317 (store::mark_region_as_unknown): Likewise.
1318 (store::on_maybe_live_values): New decl.
1320 2023-03-10 David Malcolm <dmalcolm@redhat.com>
1324 * sm-malloc.cc (deref_before_check::deref_before_check):
1325 Initialize new field m_deref_expr. Assert that arg is non-NULL.
1326 (deref_before_check::emit): Reject cases where the spelling of the
1327 thing that was dereferenced differs from that of what is checked,
1328 or if the dereference expression was not found. Remove code to
1330 (deref_before_check::describe_state_change): Remove code to handle
1332 (deref_before_check::describe_final_event): Likewise.
1333 (deref_before_check::sufficiently_similar_p): New.
1334 (deref_before_check::m_deref_expr): New field.
1335 (malloc_state_machine::maybe_complain_about_deref_before_check):
1336 Don't warn if the diag_ptr is NULL.
1338 2023-03-03 David Malcolm <dmalcolm@redhat.com>
1340 * kf.cc (class kf_sprintf): New.
1341 (register_known_functions): Register it.
1343 2023-03-02 David Malcolm <dmalcolm@redhat.com>
1346 * region-model.cc (region_model::get_rvalue_1): Handle VAR_DECLs
1347 with a DECL_HARD_REGISTER by returning UNKNOWN.
1349 2023-03-02 Hans-Peter Nilsson <hp@axis.com>
1351 * kf.cc (register_known_functions): Add __errno function for newlib.
1353 2023-03-01 David Malcolm <dmalcolm@redhat.com>
1356 * region-model.cc (region_model::on_call_pre): Flatten logic by
1357 returning early. Consolidate logic for detecting const and pure
1358 functions. When considering whether an unhandled built-in
1359 function has side-effects, consider all kinds of builtin, rather
1360 than just BUILT_IN_NORMAL, and don't require
1361 gimple_builtin_call_types_compatible_p.
1363 2023-03-01 David Malcolm <dmalcolm@redhat.com>
1366 * infinite-recursion.cc (contains_unknown_p): New.
1367 (sufficiently_different_region_binding_p): New function, splitting
1368 out inner loop from...
1369 (sufficiently_different_p): ...here. Extend detection of unknown
1370 svalues to also include svalues that contain unknown. Treat
1371 changes in frames below the entry to the recursion as being
1372 sufficiently different to reject being an infinite recursion.
1374 2023-02-21 David Malcolm <dmalcolm@redhat.com>
1377 * analyzer.opt (fanalyzer-suppress-followups): New option.
1378 * engine.cc (impl_region_model_context::warn): Terminate the path
1379 if the diagnostic's terminate_path_p vfunc returns true and
1380 -fanalyzer-suppress-followups is true (the default).
1381 (impl_sm_context::warn): Likewise, for both overloads.
1382 * pending-diagnostic.h (pending_diagnostic::terminate_path_p): New
1384 * program-state.cc (program_state::on_edge): Terminate the path if
1385 the ctxt requests it during updating the edge.
1386 * region-model.cc (poisoned_value_diagnostic::terminate_path_p):
1388 * sm-malloc.cc (null_deref::terminate_path_p): New vfunc.
1389 (null_arg::terminate_path_p): New vfunc.
1391 2023-02-16 David Malcolm <dmalcolm@redhat.com>
1394 * constraint-manager.cc (bounded_range::dump_to_pp): Use
1395 bounded_range::singleton_p.
1396 (constraint_manager::add_bounded_ranges): Handle singleton ranges
1397 by adding an EQ_EXPR constraint.
1398 (constraint_manager::impossible_derived_conditions_p): New.
1399 (constraint_manager::eval_condition): Reject EQ_EXPR when it would
1400 imply impossible derived conditions.
1401 (selftest::test_bits): New.
1402 (selftest::run_constraint_manager_tests): Run it.
1403 * constraint-manager.h (bounded_range::singleton_p): New.
1404 (constraint_manager::impossible_derived_conditions_p): New decl.
1405 * region-model.cc (region_model::get_rvalue_1): Handle
1406 BIT_AND_EXPR, BIT_IOR_EXPR, and BIT_XOR_EXPR.
1408 2023-02-15 David Malcolm <dmalcolm@redhat.com>
1413 * diagnostic-manager.cc (epath_finder::get_best_epath): Add
1414 "target_stmt" param.
1415 (epath_finder::explore_feasible_paths): Likewise.
1416 (epath_finder::process_worklist_item): Likewise.
1417 (saved_diagnostic::calc_best_epath): Pass m_stmt to
1418 epath_finder::get_best_epath.
1419 * engine.cc (feasibility_state::maybe_update_for_edge): Move
1420 per-stmt logic to...
1421 (feasibility_state::update_for_stmt): ...this new function.
1422 * exploded-graph.h (feasibility_state::update_for_stmt): New decl.
1423 * feasible-graph.cc (feasible_node::get_state_at_stmt): New.
1424 * feasible-graph.h: Include "analyzer/exploded-graph.h".
1425 (feasible_node::get_state_at_stmt): New decl.
1426 * infinite-recursion.cc
1427 (infinite_recursion_diagnostic::check_valid_fpath_p): Update for
1428 vfunc signature change.
1429 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
1430 Convert first param to a reference. Add stmt param.
1431 * region-model.cc: Include "analyzer/feasible-graph.h".
1432 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
1434 (poisoned_value_diagnostic::check_valid_fpath_p): New.
1435 (poisoned_value_diagnostic::m_check_expr): New field.
1436 (region_model::check_for_poison): Attempt to supply a check_expr
1438 (region_model::deref_rvalue): Add NULL for new check_expr param
1439 of poisoned_value_diagnostic.
1440 (region_model::get_or_create_region_for_heap_alloc): Don't reuse
1441 regions that are marked as TOUCHED.
1443 2023-02-10 David Malcolm <dmalcolm@redhat.com>
1446 * sm-malloc.cc (deref_before_check::emit): Reject the warning if
1447 the check occurs within a macro defintion.
1449 2023-02-09 David Malcolm <dmalcolm@redhat.com>
1452 * state-purge.cc (get_candidate_for_purging): Add ADDR_EXPR
1455 2023-02-08 David Malcolm <dmalcolm@redhat.com>
1458 * state-purge.cc (state_purge_per_decl::process_point_backwards):
1459 Don't stop processing the decl if it's fully overwritten by
1460 this stmt if it's also used by this stmt.
1462 2023-02-07 David Malcolm <dmalcolm@redhat.com>
1465 * sm-fd.cc (class kf_read): New.
1466 (register_known_fd_functions): Register "read".
1467 * sm-file.cc (class kf_fread): Update comment.
1469 2023-02-02 David Malcolm <dmalcolm@redhat.com>
1472 * sm-fd.cc (fd_state_machine::check_for_fd_attrs): Add missing
1474 (fd_state_machine::on_listen): Don't issue phase-mismatch or
1475 type-mismatch warnings for the "invalid" state.
1477 2023-02-01 David Malcolm <dmalcolm@redhat.com>
1480 * pending-diagnostic.cc (fixup_location_in_macro_p): Add "alloca"
1481 to macros that we shouldn't unwind inside.
1483 2023-01-26 David Malcolm <dmalcolm@redhat.com>
1486 * analyzer.h (class feasible_node): New forward decl.
1487 * diagnostic-manager.cc (epath_finder::get_best_epath): Add "pd"
1489 (epath_finder::explore_feasible_paths): Likewise.
1490 (epath_finder::process_worklist_item): Likewise. Use it to call
1491 pending_diagnostic::check_valid_fpath_p on the final fpath to
1492 give pending_diagnostic a way to add additional restrictions on
1494 (saved_diagnostic::calc_best_epath): Pass pending_diagnostic to
1495 epath_finder::get_best_epath.
1496 * infinite-recursion.cc: Include "analyzer/feasible-graph.h".
1497 (infinite_recursion_diagnostic::check_valid_fpath_p): New.
1498 (infinite_recursion_diagnostic::fedge_uses_conjured_svalue_p): New.
1499 (infinite_recursion_diagnostic::expr_uses_conjured_svalue_p): New.
1500 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
1503 2023-01-19 David Malcolm <dmalcolm@redhat.com>
1506 * analyzer.h (class checker_event): New forward decl.
1507 (class state_change_event): Indent.
1508 (class warning_event): New forward decl.
1509 * checker-event.cc (state_change_event::state_change_event): Add
1511 (warning_event::get_desc): Update for new param of
1512 evdesc::final_event ctor.
1513 * checker-event.h (state_change_event::state_change_event): Add
1515 (state_change_event::get_exploded_node): New accessor.
1516 (state_change_event::m_enode): New field.
1517 (warning_event::warning_event): New "enode" param.
1518 (warning_event::get_exploded_node): New accessor.
1519 (warning_event::m_enode): New field.
1520 * diagnostic-manager.cc
1521 (state_change_event_creator::on_global_state_change): Pass
1522 src_node to state_change_event ctor.
1523 (state_change_event_creator::on_state_change): Likewise.
1524 (null_assignment_sm_context::set_next_state): Pass NULL for
1525 new param of state_change_event ctor.
1526 * infinite-recursion.cc
1527 (infinite_recursion_diagnostic::add_final_event): Update for new
1528 param of warning_event ctor.
1529 * pending-diagnostic.cc (pending_diagnostic::add_final_event):
1530 Pass enode to warning_event ctor.
1531 * pending-diagnostic.h (evdesc::final_event): Add reference to
1533 * sm-malloc.cc: Include "analyzer/checker-event.h" and
1534 "analyzer/exploded-graph.h".
1535 (deref_before_check::deref_before_check): Initialize new fields.
1536 (deref_before_check::emit): Reject warnings in which we were
1537 unable to determine the enodes of the dereference and the check.
1538 Reject warnings interprocedural warnings. Reject warnings in which
1539 the dereference doesn't dominate the check.
1540 (deref_before_check::describe_state_change): Set m_deref_enode.
1541 (deref_before_check::describe_final_event): Set m_check_enode.
1542 (deref_before_check::m_deref_enode): New field.
1543 (deref_before_check::m_check_enode): New field.
1545 2023-01-13 David Malcolm <dmalcolm@redhat.com>
1548 * region-model.cc (has_nondefault_case_for_value_p): New.
1549 (has_nondefault_cases_for_all_enum_values_p): New.
1550 (region_model::apply_constraints_for_gswitch): Skip
1551 implicitly-created "default" when switching on an enum
1552 and all enum values have non-default cases.
1553 (rejected_default_case::dump_to_pp): New.
1554 * region-model.h (region_model_context::possibly_tainted_p): New
1556 (class rejected_default_case): New.
1557 * sm-taint.cc (region_model_context::possibly_tainted_p): New.
1558 * supergraph.cc (switch_cfg_superedge::dump_label_to_pp): Dump
1559 when implicitly_created_default_p.
1560 (switch_cfg_superedge::implicitly_created_default_p): New.
1562 (switch_cfg_superedge::implicitly_created_default_p): New decl.
1564 2023-01-11 David Malcolm <dmalcolm@redhat.com>
1567 * kf.cc (class kf_strdup): New.
1568 (class kf_strndup): New.
1569 (register_known_functions): Register them.
1570 * region-model.cc (region_model::on_call_pre): Use
1571 &HEAP_ALLOCATED_REGION for the default result of an external
1572 function with the "malloc" attribute, rather than CONJURED_SVALUE.
1573 (region_model::get_or_create_region_for_heap_alloc): Allow
1574 "size_in_bytes" to be NULL.
1575 * store.cc (store::set_value): When handling *UNKNOWN = VAL,
1576 mark VAL as "maybe bound".
1578 2022-12-16 David Malcolm <dmalcolm@redhat.com>
1581 * kf.cc (kf_memcpy_memmove::impl_call_pre): Pass in source region
1582 to region_model::check_for_poison.
1583 * region-model-asm.cc (region_model::on_asm_stmt): Pass NULL
1584 region to region_model::check_for_poison.
1585 * region-model.cc (region_model::check_for_poison): Add
1586 "src_region" param, and pass it to poisoned_value_diagnostic.
1587 (region_model::on_assignment): Pass NULL region to
1588 region_model::check_for_poison.
1589 (region_model::get_rvalue): Likewise.
1590 * region-model.h (region_model::check_for_poison): Add
1592 * sm-fd.cc (fd_state_machine::on_accept): Pass in source region
1593 to region_model::check_for_poison.
1594 * varargs.cc (kf_va_copy::impl_call_pre): Pass NULL region to
1595 region_model::check_for_poison.
1596 (kf_va_arg::impl_call_pre): Pass in source region to
1597 region_model::check_for_poison.
1599 2022-12-14 David Malcolm <dmalcolm@redhat.com>
1602 * region.cc (decl_region::get_svalue_for_initializer): Bail out to
1603 avoid calling binding_key::make with an empty region.
1604 * store.cc (binding_map::apply_ctor_val_to_range): Likewise.
1605 (binding_map::apply_ctor_pair_to_child_region): Likewise.
1606 (binding_cluster::bind): Likewise.
1607 (binding_cluster::purge_region): Likewise.
1608 (binding_cluster::maybe_get_compound_binding): Likewise.
1609 (binding_cluster::maybe_get_simple_value): Likewise.
1611 2022-12-09 David Malcolm <dmalcolm@redhat.com>
1613 * analyzer.h (class known_function): Expand comment.
1614 * region-model-impl-calls.cc: Rename to...
1616 * known-function-manager.h (class known_function_manager): Add
1619 2022-12-09 David Malcolm <dmalcolm@redhat.com>
1623 (call_summary_replay::convert_region_from_summary_1): Convert
1624 heap_regs_in_use from auto_sbitmap to auto_bitmap.
1625 * region-model-manager.cc
1626 (region_model_manager::get_or_create_region_for_heap_alloc):
1627 Convert from sbitmap to bitmap.
1628 * region-model-manager.h: Likewise.
1630 (region_model::get_or_create_region_for_heap_alloc): Convert from
1631 auto_sbitmap to auto_bitmap.
1632 (region_model::get_referenced_base_regions): Likewise.
1633 * region-model.h: Include "bitmap.h" rather than "sbitmap.h".
1634 (region_model::get_referenced_base_regions): Convert from
1635 auto_sbitmap to auto_bitmap.
1637 2022-12-09 David Malcolm <dmalcolm@redhat.com>
1639 * region-model-impl-calls.cc (class kf_memcpy): Rename to...
1640 (class kf_memcpy_memmove): ...this.
1641 (kf_memcpy::impl_call_pre): Rename to...
1642 (kf_memcpy_memmove::impl_call_pre): ...this, and check the src for
1644 (register_known_functions): Update for above renaming, and
1645 register BUILT_IN_MEMMOVE and BUILT_IN_MEMMOVE_CHK.
1647 2022-12-06 David Malcolm <dmalcolm@redhat.com>
1650 * region-model.cc (region_model::get_store_value): Return an
1651 unknown value for empty regions.
1652 (region_model::set_value): Bail on empty regions.
1653 * region.cc (region::empty_p): New.
1654 * region.h (region::empty_p): New decl.
1655 * state-purge.cc (same_binding_p): Bail if either region is empty.
1656 * store.cc (binding_key::make): Assert that a concrete binding's
1657 bit_size must be > 0.
1658 (binding_cluster::mark_region_as_unknown): Bail on empty regions.
1659 (binding_cluster::get_binding): Likewise.
1660 (binding_cluster::remove_overlapping_bindings): Likewise.
1661 (binding_cluster::on_unknown_fncall): Don't conjure values for
1663 (store::fill_region): Bail on empty regions.
1664 * store.h (class concrete_binding): Update comment to reflect that
1665 the range of bits must be non-empty.
1666 (concrete_binding::concrete_binding): Assert that bit range is
1669 2022-12-06 David Malcolm <dmalcolm@redhat.com>
1672 * region-model-manager.cc
1673 (region_model_manager::get_or_create_null_ptr): New.
1674 * region-model-manager.h
1675 (region_model_manager::get_or_create_null_ptr): New decl.
1676 * region-model.cc (region_model::on_top_level_param): Add
1677 "nonnull" param and make use of it.
1678 (region_model::push_frame): When handling a top-level entrypoint
1679 to the analysis, determine which params __attribute__((nonnull))
1680 applies to, and pass to on_top_level_param.
1681 * region-model.h (region_model::on_top_level_param): Add "nonnull"
1684 2022-12-06 David Malcolm <dmalcolm@redhat.com>
1686 * analyzer.h (register_known_analyzer_functions): New decl.
1687 (register_known_functions_lang_cp): New decl.
1688 * call-details.cc: New file, split out from
1689 region-model-impl-calls.cc.
1690 * call-details.h: New file, split out from region-model.h.
1691 * call-info.cc: Include "analyzer/call-details.h".
1692 * call-summary.h: Likewise.
1693 * kf-analyzer.cc: New file, split out from
1694 region-model-impl-calls.cc.
1695 * kf-lang-cp.cc: Likewise.
1696 * known-function-manager.cc: Include "analyzer/call-details.h".
1697 * region-model-impl-calls.cc: Move definitions of call_details's
1698 member functions to call-details.cc. Move class kf_analyzer_* to
1699 kf-analyzer.cc. Move kf_operator_new and kf_operator_delete to
1700 kf-lang-cp.cc. Refresh #includes accordingly.
1701 (register_known_functions): Replace registration of __analyzer_*
1702 functions with a call to register_known_analyzer_functions.
1703 Replace registration of C++ support functions with a call to
1704 register_known_functions_lang_cp.
1705 * region-model.h (class call_details): Move to new call-details.h.
1706 * sm-fd.cc: Include "analyzer/call-details.h".
1707 * sm-file.cc: Likewise.
1708 * sm-malloc.cc: Likewise.
1709 * varargs.cc: Likewise.
1711 2022-12-02 David Malcolm <dmalcolm@redhat.com>
1713 * analyzer.h (struct event_loc_info): New forward decl.
1714 * bounds-checking.cc: Use event_loc_info throughout to bundle the
1715 loc, fndecl, depth triples.
1716 * call-info.cc: Likewise.
1717 * checker-event.cc: Likewise.
1718 * checker-event.h (struct event_loc_info): New decl. Use it
1719 throughout to bundle the loc, fndecl, depth triples.
1720 * checker-path.cc: Likewise.
1721 * checker-path.h: Likewise.
1722 * diagnostic-manager.cc: Likewise.
1723 * engine.cc: Likewise.
1724 * infinite-recursion.cc: Likewise.
1725 * pending-diagnostic.cc: Likewise.
1726 * pending-diagnostic.h: Likewise.
1727 * region-model.cc: Likewise.
1728 * sm-signal.cc: Likewise.
1729 * varargs.cc: Likewise.
1731 2022-12-02 David Malcolm <dmalcolm@redhat.com>
1734 * analyzer.cc (make_label_text_n): Convert param "n" from int to
1735 unsigned HOST_WIDE_INT.
1736 * analyzer.h (make_label_text_n): Likewise for decl.
1737 * bounds-checking.cc: Include "analyzer/checker-event.h" and
1738 "analyzer/checker-path.h".
1739 (out_of_bounds::add_region_creation_events): New.
1740 (concrete_past_the_end::describe_region_creation_event): Replace
1742 (concrete_past_the_end::add_region_creation_events): ...this.
1743 (symbolic_past_the_end::describe_region_creation_event): Delete.
1744 * checker-event.cc (region_creation_event::region_creation_event):
1745 Update for dropping all member data.
1746 (region_creation_event::get_desc): Delete, splitting out into
1747 region_creation_event_memory_space::get_desc,
1748 region_creation_event_capacity::get_desc, and
1749 region_creation_event_debug::get_desc.
1750 (region_creation_event_memory_space::get_desc): New.
1751 (region_creation_event_capacity::get_desc): New.
1752 (region_creation_event_allocation_size::get_desc): New.
1753 (region_creation_event_debug::get_desc): New.
1754 * checker-event.h: Include "analyzer/program-state.h".
1755 (enum rce_kind): Delete.
1756 (class region_creation_event): Drop all member data.
1757 (region_creation_event::region_creation_event): Make protected.
1758 (region_creation_event::get_desc): Delete.
1759 (class region_creation_event_memory_space): New.
1760 (class region_creation_event_capacity): New.
1761 (class region_creation_event_allocation_size): New.
1762 (class region_creation_event_debug): New.
1763 * checker-path.cc (checker_path::add_region_creation_events): Add
1764 "pd" param. Call pending_diangnostic::add_region_creation_events.
1765 Update for conversion of RCE_DEBUG to region_creation_event_debug.
1766 * checker-path.h (checker_path::add_region_creation_events): Add
1768 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
1769 Pass pending_diagnostic to
1770 emission_path::add_region_creation_events.
1771 (diagnostic_manager::build_emission_path): Pass path_builder to
1772 add_event_on_final_node.
1773 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
1774 Pass pending_diagnostic to
1775 emission_path::add_region_creation_events.
1776 (diagnostic_manager::add_events_for_eedge): Pass
1777 pending_diagnostic to emission_path::add_region_creation_events.
1778 * diagnostic-manager.h
1779 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
1780 * pending-diagnostic.cc
1781 (pending_diagnostic::add_region_creation_events): New.
1782 * pending-diagnostic.h (struct region_creation): Delete.
1783 (pending_diagnostic::describe_region_creation_event): Delete.
1784 (pending_diagnostic::add_region_creation_events): New vfunc.
1785 * region-model.cc: Include "analyzer/checker-event.h" and
1786 "analyzer/checker-path.h".
1787 (dubious_allocation_size::dubious_allocation_size): Initialize
1788 m_has_allocation_event.
1789 (dubious_allocation_size::describe_region_creation_event): Delete.
1790 (dubious_allocation_size::describe_final_event): Update for
1791 replacement of m_allocation_event with m_has_allocation_event.
1792 (dubious_allocation_size::add_region_creation_events): New.
1793 (dubious_allocation_size::m_allocation_event): Replace with...
1794 (dubious_allocation_size::m_has_allocation_event): ...this.
1796 2022-12-02 David Malcolm <dmalcolm@redhat.com>
1799 * region-model-manager.cc
1800 (region_model_manager::maybe_fold_binop): Fold (0 - VAL) to -VAL.
1801 * region-model.cc (region_model::eval_condition): Handle e.g.
1802 "-X <= 0" as equivalent to X >= 0".
1804 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1807 * bounds-checking.cc
1808 (symbolic_past_the_end::describe_final_event): Delete, moving to
1809 symbolic_buffer_overflow::describe_final_event and
1810 symbolic_buffer_over_read::describe_final_event, eliminating
1811 composition of text strings via "byte_str" and "m_dir_str".
1812 (symbolic_past_the_end::m_dir_str): Delete field.
1813 (symbolic_buffer_overflow::symbolic_buffer_overflow): Drop
1815 (symbolic_buffer_overflow::describe_final_event): New, as noted
1817 (symbolic_buffer_over_read::symbolic_buffer_overflow): Drop
1819 (symbolic_buffer_over_read::describe_final_event): New, as noted
1822 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1824 * bounds-checking.cc (class out_of_bounds): Split out from...
1825 (class concrete_out_of_bounds): New abstract subclass.
1826 (class past_the_end): Rename to...
1827 (class concrete_past_the_end): ...this, and make a subclass of
1828 concrete_out_of_bounds.
1829 (class buffer_overflow): Rename to...
1830 (class concrete_buffer_overflow): ...this, and make a subclass of
1831 concrete_past_the_end.
1832 (class buffer_over_read): Rename to...
1833 (class concrete_buffer_over_read): ...this, and make a subclass of
1834 concrete_past_the_end.
1835 (class buffer_underwrite): Rename to...
1836 (class concrete_buffer_underwrite): ...this, and make a subclass
1837 of concrete_out_of_bounds.
1838 (class buffer_under_read): Rename to...
1839 (class concrete_buffer_under_read): ...this, and make a subclass
1840 of concrete_out_of_bounds.
1841 (class symbolic_past_the_end): Convert to a subclass of
1843 (symbolic_buffer_overflow::get_kind): New.
1844 (symbolic_buffer_over_read::get_kind): New.
1845 (region_model::check_region_bounds): Update for renamings.
1846 * engine.cc (impl_sm_context::set_next_state): Eliminate
1847 "new_ctxt", passing NULL to get_rvalue instead.
1848 (impl_sm_context::warn): Likewise.
1850 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1853 * bounds-checking.cc (out_of_bounds::get_memory_space): New.
1854 (buffer_overflow::emit): Use it.
1855 (class buffer_overread): Rename to...
1856 (class buffer_over_read): ...this.
1857 (buffer_over_read::emit): Specify which memory space the read is
1858 from, where known. Change "overread" to "over-read".
1859 (class buffer_underflow): Rename to...
1860 (class buffer_underwrite): ...this.
1861 (buffer_underwrite::emit): Specify which memory space the write is
1862 to, where known. Change "underflow" to "underwrite".
1863 (class buffer_underread): Rename to...
1864 (class buffer_under_read): Rename to...
1865 (buffer_under_read::emit): Specify which memory space the read is
1866 from, where known. Change "underread" to "under-read".
1867 (symbolic_past_the_end::get_memory_space): New.
1868 (symbolic_buffer_overflow::emit): Use it.
1869 (class symbolic_buffer_overread): Rename to...
1870 (class symbolic_buffer_over_read): ...this.
1871 (symbolic_buffer_over_read::emit): Specify which memory space the
1872 read is from, where known. Change "overread" to "over-read".
1873 (region_model::check_symbolic_bounds): Update for class renaming.
1874 (region_model::check_region_bounds): Likewise.
1876 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1879 * bounds-checking.cc (out_of_bounds::maybe_describe_array_bounds):
1881 (buffer_overflow::emit): Call maybe_describe_array_bounds.
1882 (buffer_overread::emit): Likewise.
1883 (buffer_underflow::emit): Likewise.
1884 (buffer_underread::emit): Likewise.
1886 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1889 * bounds-checking.cc (buffer_overflow::emit): Use inform_n.
1890 Update wording to clarify that we're talking about the size of
1891 the bad access, rather than its position.
1892 (buffer_overread::emit): Likewise.
1894 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1896 * bounds-checking.cc: New file, taken from region-model.cc.
1897 * region-model.cc (class out_of_bounds): Move to
1899 (class past_the_end): Likewise.
1900 (class buffer_overflow): Likewise.
1901 (class buffer_overread): Likewise.
1902 (class buffer_underflow): Likewise.
1903 (class buffer_underread): Likewise.
1904 (class symbolic_past_the_end): Likewise.
1905 (class symbolic_buffer_overflow): Likewise.
1906 (class symbolic_buffer_overread): Likewise.
1907 (region_model::check_symbolic_bounds): Likewise.
1908 (maybe_get_integer_cst_tree): Likewise.
1909 (region_model::check_region_bounds): Likewise.
1910 * region-model.h: Add comment.
1912 2022-12-01 David Malcolm <dmalcolm@redhat.com>
1915 * sm-fd.cc (fd_state_machine::on_bind): Handle m_constant_fd in
1916 the "success" outcome.
1917 (fd_state_machine::on_connect): Likewise.
1918 * sm-fd.dot: Add "constant_fd" state and its transitions.
1920 2022-11-30 David Malcolm <dmalcolm@redhat.com>
1922 * region-model-impl-calls.cc (class kf_fgets): Move to sm-file.cc.
1923 (kf_fgets::impl_call_pre): Likewise.
1924 (class kf_fread): Likewise.
1925 (kf_fread::impl_call_pre): Likewise.
1926 (class kf_getchar): Likewise.
1927 (class kf_stdio_output_fn): Likewise.
1928 (register_known_functions): Move registration of
1929 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
1930 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
1931 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
1932 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
1933 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
1934 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
1935 "getchar", "fgets", "fgets_unlocked", and "fread" to
1936 register_known_file_functions.
1937 * sm-file.cc (class kf_stdio_output_fn): Move here from
1938 region-model-impl-calls.cc.
1939 (class kf_fgets): Likewise.
1940 (class kf_fread): Likewise.
1941 (class kf_getchar): Likewise.
1942 (register_known_file_functions): Move registration of
1943 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
1944 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
1945 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
1946 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
1947 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
1948 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
1949 "fgets", "fgets_unlocked", "fread", and "getchar" to here from
1950 register_known_functions.
1952 2022-11-30 David Malcolm <dmalcolm@redhat.com>
1955 * analyzer.h (register_known_file_functions): New decl.
1956 * program-state.cc (sm_state_map::replay_call_summary): Rejct
1957 attempts to store sm-state for caller_sval that can't have
1959 * region-model-impl-calls.cc (register_known_functions): Call
1960 register_known_file_functions.
1961 * sm-fd.cc (class kf_isatty): New.
1962 (register_known_fd_functions): Register it.
1963 * sm-file.cc (class kf_ferror): New.
1964 (class kf_fileno): New.
1965 (class kf_getc): New.
1966 (register_known_file_functions): New.
1968 2022-11-30 David Malcolm <dmalcolm@redhat.com>
1971 * region-model-manager.cc
1972 (region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
1973 PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
1974 type matches that of arg0 in favor of a cast.
1976 2022-11-24 Martin Liska <mliska@suse.cz>
1978 * varargs.cc: Fix Clang warnings.
1980 2022-11-24 David Malcolm <dmalcolm@redhat.com>
1984 (call_summary_replay::convert_region_from_summary_1): Update for
1985 change to creation of heap-allocated regions.
1986 * program-state.cc (test_program_state_1): Likewise.
1987 (test_program_state_merging): Likewise.
1988 * region-model-impl-calls.cc (kf_calloc::impl_call_pre): Likewise.
1989 (kf_malloc::impl_call_pre): Likewise.
1990 (kf_operator_new::impl_call_pre): Likewise.
1991 (kf_realloc::impl_call_postsuccess_with_move::update_model): Likewise.
1992 * region-model-manager.cc
1993 (region_model_manager::create_region_for_heap_alloc): Convert
1995 (region_model_manager::get_or_create_region_for_heap_alloc):
1996 ...this, reusing an existing region if it's unreferenced in the
1998 * region-model-manager.h (region_model_manager::get_num_regions): New.
1999 (region_model_manager::create_region_for_heap_alloc): Convert to...
2000 (region_model_manager::get_or_create_region_for_heap_alloc): ...this.
2001 * region-model.cc (region_to_value_map::can_merge_with_p): Reject
2002 merger when the values are different.
2003 (region_model::create_region_for_heap_alloc): Convert to...
2004 (region_model::get_or_create_region_for_heap_alloc): ...this.
2005 (region_model::get_referenced_base_regions): New.
2006 (selftest::test_state_merging): Update for change to creation of
2007 heap-allocated regions.
2008 (selftest::test_malloc_constraints): Likewise.
2009 (selftest::test_malloc): Likewise.
2010 * region-model.h: Include "sbitmap.h".
2011 (region_model::create_region_for_heap_alloc): Convert to...
2012 (region_model::get_or_create_region_for_heap_alloc): ...this.
2013 (region_model::get_referenced_base_regions): New decl.
2014 * store.cc (store::canonicalize): Don't purge a heap-allocated region
2015 that's been marked as escaping.
2017 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2019 * checker-path.cc (checker_path::inject_any_inlined_call_events):
2020 Don't dump the address of the block when -fdump-noaddr.
2022 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2024 * region-model.h (region_model::on_socket): Delete decl.
2025 (region_model::on_bind): Likewise.
2026 (region_model::on_listen): Likewise.
2027 (region_model::on_accept): Likewise.
2028 (region_model::on_connect): Likewise.
2029 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
2030 of region_model::on_socket into here, ...
2031 (region_model::on_socket): ...eliminating this function.
2032 (kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
2033 (region_model::on_bind): ...eliminating this function.
2034 (kf_listen::outcome_of_listen::update_model): Likewise fo
2036 (region_model::on_listen): ...eliminating this function.
2037 (kf_accept::outcome_of_accept::update_model): Likewise fo
2039 (region_model::on_accept): ...eliminating this function.
2040 (kf_connect::outcome_of_connect::update_model): Likewise fo
2042 (region_model::on_connect): ...eliminating this function.
2044 2022-11-24 David Malcolm <dmalcolm@redhat.com>
2046 * analyzer.h (register_known_fd_functions): New decl.
2047 * region-model-impl-calls.cc (class kf_accept): Move to sm-fd.cc.
2048 (class kf_bind): Likewise.
2049 (class kf_connect): Likewise.
2050 (class kf_listen): Likewise.
2051 (class kf_pipe): Likewise.
2052 (class kf_socket): Likewise.
2053 (register_known_functions): Remove registration of the above
2054 functions, instead calling register_known_fd_functions.
2055 * sm-fd.cc: Include "analyzer/call-info.h".
2056 (class kf_socket): Move here from region-model-impl-calls.cc.
2057 (class kf_bind): Likewise.
2058 (class kf_listen): Likewise.
2059 (class kf_accept): Likewise.
2060 (class kf_connect): Likewise.
2061 (class kf_pipe): Likewise.
2062 (register_known_fd_functions): New.
2064 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2067 * known-function-manager.cc (known_function_manager::get_match):
2068 Don't look up fndecls by name when they're not in the root
2071 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2074 * sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
2075 complain when old state is "fd-constant".
2076 (fd_state_machine::on_listen): Likewise.
2077 (fd_state_machine::on_accept): Likewise.
2079 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2082 * region-model-impl-calls.cc (register_known_functions): Register
2083 "___errno" and "__error" as synonyms for "__errno_location".
2085 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2087 * analyzer.h (class internal_known_function): New.
2088 (register_varargs_builtins): New decl.
2089 * engine.cc (exploded_node::on_stmt_pre): Remove
2090 "out_terminate_path" param from call to region_model::on_stmt_pre.
2091 (feasibility_state::maybe_update_for_edge): Likewise.
2092 * known-function-manager.cc: Include "basic-block.h", "gimple.h",
2093 and "analyzer/region-model.h".
2094 (known_function_manager::known_function_manager): Initialize
2096 (known_function_manager::~known_function_manager): Clean up
2098 (known_function_manager::get_by_identifier): Make const.
2099 (known_function_manager::add): New overloaded definitions for
2100 enum built_in_function and enum internal_fn.
2101 (known_function_manager::get_by_fndecl): Delete.
2102 (known_function_manager::get_match): New.
2103 (known_function_manager::get_internal_fn): New.
2104 (known_function_manager::get_normal_builtin): New.
2105 * known-function-manager.h
2106 (known_function_manager::get_by_identifier): Make private and
2107 add const qualifier.
2108 (known_function_manager::get_by_fndecl): Delete.
2109 (known_function_manager::add): Add overloaded decls for
2110 enum built_in_function name and enum internal_fn.
2111 (known_function_manager::get_match): New decl.
2112 (known_function_manager::get_internal_fn): New decl.
2113 (known_function_manager::get_normal_builtin): New decl.
2114 (known_function_manager::m_combined_fns_arr): New field.
2115 * region-model-impl-calls.cc (call_details::arg_is_size_p): New.
2116 (class kf_alloca): New.
2117 (region_model::impl_call_alloca): Convert to...
2118 (kf_alloca::impl_call_pre): ...this.
2119 (kf_analyzer_dump_capacity::matches_call_types_p): Rewrite check
2120 to use call_details::arg_is_pointer_p.
2121 (region_model::impl_call_builtin_expect): Convert to...
2122 (class kf_expect): ...this.
2123 (class kf_calloc): New, adding check that both arguments are
2125 (region_model::impl_call_calloc): Convert to...
2126 (kf_calloc::impl_call_pre): ...this.
2127 (kf_connect::matches_call_types_p): Rewrite check to use
2128 call_details::arg_is_pointer_p.
2129 (region_model::impl_call_error): Convert to...
2130 (class kf_error): ...this, and...
2131 (kf_error::impl_call_pre): ...this.
2132 (class kf_fgets): New, adding checks that args 0 and 2 are
2134 (region_model::impl_call_fgets): Convert to...
2135 (kf_fgets::impl_call_pre): ...this.
2136 (class kf_fread): New, adding checks on the argument types.
2137 (region_model::impl_call_fread): Convert to...
2138 (kf_fread::impl_call_pre): ...this.
2139 (class kf_free): New, adding check that the argument is a pointer.
2140 (region_model::impl_call_free): Convert to...
2141 (kf_free::impl_call_post): ...this.
2142 (class kf_getchar): New.
2143 (class kf_malloc): New, adding check that the argument is a
2145 (region_model::impl_call_malloc): Convert to...
2146 (kf_malloc::impl_call_pre): ...this.
2147 (class kf_memcpy): New, adding checks on arguments.
2148 (region_model::impl_call_memcpy): Convert to...
2149 (kf_memcpy::impl_call_pre): ...this.
2150 (class kf_memset): New.
2151 (region_model::impl_call_memset): Convert to...
2152 (kf_memset::impl_call_pre): ...this.
2153 (kf_pipe::matches_call_types_p): Rewrite check to use
2154 call_details::arg_is_pointer_p.
2155 (kf_putenv::matches_call_types_p): Likewise.
2156 (class kf_realloc): New, adding checks on the argument types.
2157 (region_model::impl_call_realloc): Convert to...
2158 (kf_realloc::impl_call_post): ...this.
2159 (class kf_strchr): New.
2160 (region_model::impl_call_strchr): Convert to...
2161 (kf_strchr::impl_call_post): ...this.
2162 (class kf_stack_restore): New.
2163 (class kf_stack_save): New.
2164 (class kf_stdio_output_fn): New.
2165 (class kf_strcpy): New,
2166 (region_model::impl_call_strcpy): Convert to...
2167 (kf_strcpy::impl_call_pre): ...this.
2168 (class kf_strlen): New.
2169 (region_model::impl_call_strlen): Convert to...
2170 (kf_strlen::impl_call_pre): ...this.
2171 (class kf_ubsan_bounds): New.
2172 (region_model::impl_deallocation_call): Reimplement to avoid call
2174 (register_known_functions): Add handlers for IFN_BUILTIN_EXPECT
2175 and IFN_UBSAN_BOUNDS. Add handlers for BUILT_IN_ALLOCA,
2176 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
2177 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FPRINTF,
2178 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
2179 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
2180 BUILT_IN_FREE, BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED,
2181 BUILT_IN_MALLOC, BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK,
2182 BUILT_IN_MEMSET, BUILT_IN_MEMSET_CHK, BUILT_IN_PRINTF,
2183 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
2184 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
2185 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_REALLOC, BUILT_IN_STACK_RESTORE,
2186 BUILT_IN_STACK_SAVE, BUILT_IN_STRCHR, BUILT_IN_STRCPY,
2187 BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN, BUILT_IN_VFPRINTF, and
2188 BUILT_IN_VPRINTF. Call register_varargs_builtins. Add handlers
2189 for "getchar", "memset", "fgets", "fgets_unlocked", "fread",
2190 "error", and "error_at_line".
2191 * region-model.cc (region_model::on_stmt_pre): Drop
2192 "out_terminate_path" param.
2193 (region_model::get_known_function): Reimplement by calling
2194 known_function_manager::get_match, passing new "cd" param.
2195 Add overload taking enum internal_fn.
2196 (region_model::on_call_pre): Drop "out_terminate_path" param.
2197 Remove special-case handling of internal fns IFN_BUILTIN_EXPECT,
2198 IFN_UBSAN_BOUNDS, and IFN_VA_ARG, of built-in fns BUILT_IN_ALLOCA,
2199 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
2200 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FREE, BUILT_IN_MALLOC,
2201 BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMSET,
2202 BUILT_IN_MEMSET_CHK, BUILT_IN_REALLOC, BUILT_IN_STRCHR,
2203 BUILT_IN_STRCPY, BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN,
2204 BUILT_IN_STACK_SAVE, BUILT_IN_STACK_RESTORE, BUILT_IN_FPRINTF,
2205 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED,
2206 BUILT_IN_FPUTC, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS,
2207 BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE,
2208 BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
2209 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
2210 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
2211 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF, BUILT_IN_VA_START, and
2212 BUILT_IN_VA_COPY, and of named functions "malloc", "calloc",
2213 "alloca", "realloc", "error", "error_at_line", "fgets",
2214 "fgets_unlocked", "fread", "getchar", "memset", "strchr", and
2215 "strlen". Replace all this special-casing with calls to
2216 get_known_function for internal fns and for fn decls.
2217 (region_model::on_call_post): Remove special-casing handling for
2218 "free" and "strchr", and for BUILT_IN_REALLOC, BUILT_IN_STRCHR,
2219 and BUILT_IN_VA_END. Replace by consolidating on usage of
2221 * region-model.h (call_details::arg_is_size_p): New.
2222 (region_model::on_stmt_pre): Drop "out_terminate_path" param.
2223 (region_model::on_call_pre): Likewise.
2224 (region_model::impl_call_alloca): Delete.
2225 (region_model::impl_call_builtin_expect): Delete.
2226 (region_model::impl_call_calloc): Delete.
2227 (region_model::impl_call_error): Delete.
2228 (region_model::impl_call_fgets): Delete.
2229 (region_model::impl_call_fread): Delete.
2230 (region_model::impl_call_free): Delete.
2231 (region_model::impl_call_malloc): Delete.
2232 (region_model::impl_call_memcpy): Delete.
2233 (region_model::impl_call_memset): Delete.
2234 (region_model::impl_call_realloc): Delete.
2235 (region_model::impl_call_strchr): Delete.
2236 (region_model::impl_call_strcpy): Delete.
2237 (region_model::impl_call_strlen): Delete.
2238 (region_model::impl_call_va_start): Delete.
2239 (region_model::impl_call_va_copy): Delete.
2240 (region_model::impl_call_va_arg): Delete.
2241 (region_model::impl_call_va_end): Delete.
2242 (region_model::check_region_for_write): Public.
2243 (region_model::get_known_function): Add "cd" param. Add
2244 overloaded decl taking enum internal_fn.
2245 * sm-malloc.cc: Update comments.
2246 * varargs.cc (class kf_va_start): New.
2247 (region_model::impl_call_va_start): Convert to...
2248 (kf_va_start::impl_call_pre): ...this.
2249 (class kf_va_copy): New.
2250 (region_model::impl_call_va_copy): Convert to...
2251 (kf_va_copy::impl_call_pre): ...this.
2252 (class kf_va_arg): New.
2253 (region_model::impl_call_va_arg): Convert to...
2254 (kf_va_arg::impl_call_pre): ...this.
2255 (class kf_va_end): New.
2256 (region_model::impl_call_va_end): Delete.
2257 (register_varargs_builtins): New.
2259 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2262 * region-model.cc (region_model::update_for_int_cst_return):
2263 Require that the return type be an integer type.
2264 (region_model::update_for_nonzero_return): Likewise.
2266 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2269 * region-model-impl-calls.cc (kf_accept::matches_call_types_p):
2270 Require that args 1 and 2 be pointers.
2271 (kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
2272 * region-model.h (call_details::arg_is_pointer_p): New
2274 2022-11-22 David Malcolm <dmalcolm@redhat.com>
2278 (call_summary_replay::convert_region_from_summary_1): Handle
2279 RK_THREAD_LOCAL and RK_ERRNO in switch.
2280 * region-model.cc (region_model::get_representative_path_var_1):
2283 2022-11-19 David Malcolm <dmalcolm@redhat.com>
2286 * engine.cc (dynamic_call_info_t::update_model): Update the model
2287 by pushing or pop a frame, rather than by clobbering it with the
2288 model from the exploded_node's state.
2290 2022-11-18 David Malcolm <dmalcolm@redhat.com>
2292 * analyzer.cc (is_pipe_call_p): Delete.
2293 * analyzer.h (is_pipe_call_p): Delete.
2294 * region-model-impl-calls.cc (call_details::get_location): New.
2295 (class kf_analyzer_break): New, adapted from
2296 region_model::on_stmt_pre.
2297 (region_model::impl_call_analyzer_describe): Convert to...
2298 (class kf_analyzer_describe): ...this.
2299 (region_model::impl_call_analyzer_dump_capacity): Convert to...
2300 (class kf_analyzer_dump_capacity): ...this.
2301 (region_model::impl_call_analyzer_dump_escaped): Convert to...
2302 (class kf_analyzer_dump_escaped): ...this.
2303 (class kf_analyzer_dump_exploded_nodes): New.
2304 (region_model::impl_call_analyzer_dump_named_constant): Convert
2306 (class kf_analyzer_dump_named_constant): ...this.
2307 (class dump_path_diagnostic): Move here from region-model.cc.
2308 (class kf_analyzer_dump_path) New, adapted from
2309 region_model::on_stmt_pre.
2310 (class kf_analyzer_dump_region_model): Likewise.
2311 (region_model::impl_call_analyzer_eval): Convert to...
2312 (class kf_analyzer_eval): ...this.
2313 (region_model::impl_call_analyzer_get_unknown_ptr): Convert to...
2314 (class kf_analyzer_get_unknown_ptr): ...this.
2315 (class known_function_accept): Rename to...
2316 (class kf_accept): ...this.
2317 (class known_function_bind): Rename to...
2318 (class kf_bind): ...this.
2319 (class known_function_connect): Rename to...
2320 (class kf_connect): ...this.
2321 (region_model::impl_call_errno_location): Convert to...
2322 (class kf_errno_location): ...this.
2323 (class known_function_listen): Rename to...
2324 (class kf_listen): ...this.
2325 (region_model::impl_call_pipe): Convert to...
2326 (class kf_pipe): ...this.
2327 (region_model::impl_call_putenv): Convert to...
2328 (class kf_putenv): ...this.
2329 (region_model::impl_call_operator_new): Convert to...
2330 (class kf_operator_new): ...this.
2331 (region_model::impl_call_operator_delete): Convert to...
2332 (class kf_operator_delete): ...this.
2333 (class known_function_socket): Rename to...
2334 (class kf_socket): ...this.
2335 (register_known_functions): Rename param to KFM. Break out
2336 existing known functions into a "POSIX" section, and add "pipe",
2337 "pipe2", and "putenv". Add debugging functions
2338 "__analyzer_break", "__analyzer_describe",
2339 "__analyzer_dump_capacity", "__analyzer_dump_escaped",
2340 "__analyzer_dump_exploded_nodes",
2341 "__analyzer_dump_named_constant", "__analyzer_dump_path",
2342 "__analyzer_dump_region_model", "__analyzer_eval",
2343 "__analyzer_get_unknown_ptr". Add C++ support functions
2344 "operator new", "operator new []", "operator delete", and
2345 "operator delete []".
2346 * region-model.cc (class dump_path_diagnostic): Move to
2347 region-model-impl-calls.cc.
2348 (region_model::on_stmt_pre): Eliminate special-casing of
2349 "__analyzer_describe", "__analyzer_dump_capacity",
2350 "__analyzer_dump_escaped", "__analyzer_dump_named_constant",
2351 "__analyzer_dump_path", "__analyzer_dump_region_model",
2352 "__analyzer_eval", "__analyzer_break",
2353 "__analyzer_dump_exploded_nodes", "__analyzer_get_unknown_ptr",
2354 "__errno_location", "pipe", "pipe2", "putenv", "operator new",
2355 "operator new []", "operator delete", "operator delete []"
2356 "pipe" and "pipe2", handling them instead via the known_functions
2358 * region-model.h (call_details::get_location): New decl.
2359 (region_model::impl_call_analyzer_describe): Delete decl.
2360 (region_model::impl_call_analyzer_dump_capacity): Delete decl.
2361 (region_model::impl_call_analyzer_dump_escaped): Delete decl.
2362 (region_model::impl_call_analyzer_dump_named_constant): Delete decl.
2363 (region_model::impl_call_analyzer_eval): Delete decl.
2364 (region_model::impl_call_analyzer_get_unknown_ptr): Delete decl.
2365 (region_model::impl_call_errno_location): Delete decl.
2366 (region_model::impl_call_pipe): Delete decl.
2367 (region_model::impl_call_putenv): Delete decl.
2368 (region_model::impl_call_operator_new): Delete decl.
2369 (region_model::impl_call_operator_delete): Delete decl.
2370 * sm-fd.cc: Update comments.
2372 2022-11-16 David Malcolm <dmalcolm@redhat.com>
2375 * analyzer-language.cc: Include "diagnostic.h".
2376 (maybe_stash_named_constant): Add logger param and use it to log
2377 the name being looked up, and the result.
2378 (stash_named_constants): New, splitting out from...
2379 (on_finish_translation_unit): ...this function. Call
2380 get_or_create_logfile and use the result to create a logger
2381 instance, passing it to stash_named_constants.
2382 * analyzer.h (get_or_create_any_logfile): New decl.
2383 * engine.cc (dump_fout, owns_dump_fout): New globals, split out
2385 (get_or_create_any_logfile): New function, split out from...
2386 (run_checkers): ...here, so that the logfile can be opened by
2387 on_finish_translation_unit. Clear the globals when closing the
2390 2022-11-16 David Malcolm <dmalcolm@redhat.com>
2392 * analyzer.h (known_function::matches_call_types_p): New vfunc.
2393 (known_function::impl_call_pre): Provide base implementation.
2394 (known_function::impl_call_post): New vfunc.
2395 (register_known_functions): New.
2396 * engine.cc (impl_run_checkers): Call register_known_functions.
2397 * region-model-impl-calls.cc (region_model::impl_call_accept):
2399 (class known_function_accept): ...this.
2400 (region_model::impl_call_bind): Convert to...
2401 (class known_function_bind): ...this.
2402 (region_model::impl_call_connect): Convert to...
2403 (class known_function_connect): ...this.
2404 (region_model::impl_call_listen): Convert to...
2405 (class known_function_listen): ...this.
2406 (region_model::impl_call_socket): Convert to...
2407 (class known_function_socket): ...this.
2408 (register_known_functions): New.
2409 * region-model.cc (region_model::on_call_pre): Remove special
2410 case for "bind" in favor of the known_function-handling dispatch.
2411 Add call to known_function::matches_call_types_p to latter.
2412 (region_model::on_call_post): Remove special cases for "accept",
2413 "bind", "connect", "listen", and "socket" in favor of dispatch
2414 to known_function::impl_call_post.
2415 * region-model.h (region_model::impl_call_accept): Delete decl.
2416 (region_model::impl_call_bind): Delete decl.
2417 (region_model::impl_call_connect): Delete decl.
2418 (region_model::impl_call_listen): Delete decl.
2419 (region_model::impl_call_socket): Delete decl.
2420 * sm-fd.cc: Update comments.
2422 2022-11-16 David Malcolm <dmalcolm@redhat.com>
2424 * checker-event.cc: New file, split out from...
2425 * checker-path.cc: ...this file.
2427 2022-11-15 David Malcolm <dmalcolm@redhat.com>
2430 * analyzer-language.cc (on_finish_translation_unit): Stash named
2431 constants "SOCK_STREAM" and "SOCK_DGRAM".
2432 * analyzer.opt (Wanalyzer-fd-phase-mismatch): New.
2433 (Wanalyzer-fd-type-mismatch): New.
2434 * engine.cc (impl_region_model_context::get_state_map_by_name):
2435 Add "out_sm_context" param. Allow out_sm_idx to be NULL.
2437 (impl_region_model_context::get_state_map_by_name):
2438 Add "out_sm_context" param.
2439 * region-model-impl-calls.cc (region_model::impl_call_accept): New.
2440 (region_model::impl_call_bind): New.
2441 (region_model::impl_call_connect): New.
2442 (region_model::impl_call_listen): New.
2443 (region_model::impl_call_socket): New.
2444 * region-model.cc (region_model::on_call_pre): Special-case
2446 (region_model::on_call_post): Special-case "accept", "bind",
2447 "connect", "listen", and "socket".
2448 * region-model.h (region_model::impl_call_accept): New decl.
2449 (region_model::impl_call_bind): New decl.
2450 (region_model::impl_call_connect): New decl.
2451 (region_model::impl_call_listen): New decl.
2452 (region_model::impl_call_socket): New decl.
2453 (region_model::on_socket): New decl.
2454 (region_model::on_bind): New decl.
2455 (region_model::on_listen): New decl.
2456 (region_model::on_accept): New decl.
2457 (region_model::on_connect): New decl.
2458 (region_model::add_constraint): Make public.
2459 (region_model::check_for_poison): Make public.
2460 (region_model_context::get_state_map_by_name): Add out_sm_context param.
2461 (region_model_context::get_fd_map): Likewise.
2462 (region_model_context::get_malloc_map): Likewise.
2463 (region_model_context::get_taint_map): Likewise.
2464 (noop_region_model_context::get_state_map_by_name): Likewise.
2465 (region_model_context_decorator::get_state_map_by_name): Likewise.
2466 * sm-fd.cc: Include "analyzer/supergraph.h" and
2467 "analyzer/analyzer-language.h".
2468 (enum expected_phase): New enum.
2469 (fd_state_machine::m_new_datagram_socket): New.
2470 (fd_state_machine::m_new_stream_socket): New.
2471 (fd_state_machine::m_new_unknown_socket): New.
2472 (fd_state_machine::m_bound_datagram_socket): New.
2473 (fd_state_machine::m_bound_stream_socket): New.
2474 (fd_state_machine::m_bound_unknown_socket): New.
2475 (fd_state_machine::m_listening_stream_socket): New.
2476 (fd_state_machine::m_m_connected_stream_socket): New.
2477 (fd_state_machine::m_SOCK_STREAM): New.
2478 (fd_state_machine::m_SOCK_DGRAM): New.
2479 (fd_diagnostic::describe_state_change): Handle socket states.
2480 (fd_diagnostic::get_meaning_for_state_change): Likewise.
2481 (class fd_phase_mismatch): New.
2482 (enum expected_type): New enum.
2483 (class fd_type_mismatch): New.
2484 (fd_state_machine::fd_state_machine): Initialize new states and
2485 stashed named constants.
2486 (fd_state_machine::is_socket_fd_p): New.
2487 (fd_state_machine::is_datagram_socket_fd_p): New.
2488 (fd_state_machine::is_stream_socket_fd_p): New.
2489 (fd_state_machine::on_close): Handle the socket states.
2490 (fd_state_machine::check_for_open_fd): Complain about fncalls on
2491 sockets in the wrong phase. Support socket FDs.
2492 (add_constraint_ge_zero): New.
2493 (fd_state_machine::get_state_for_socket_type): New.
2494 (fd_state_machine::on_socket): New.
2495 (fd_state_machine::check_for_socket_fd): New.
2496 (fd_state_machine::check_for_new_socket_fd): New.
2497 (fd_state_machine::on_bind): New.
2498 (fd_state_machine::on_listen): New.
2499 (fd_state_machine::on_accept): New.
2500 (fd_state_machine::on_connect): New.
2501 (fd_state_machine::can_purge_p): Don't purge socket values.
2502 (get_fd_state): New.
2503 (region_model::mark_as_valid_fd): Use get_fd_state.
2504 (region_model::on_socket): New.
2505 (region_model::on_bind): New.
2506 (region_model::on_listen): New.
2507 (region_model::on_accept): New.
2508 (region_model::on_connect): New.
2509 * sm-fd.dot: Update to reflect sm-fd.cc changes.
2511 2022-11-15 David Malcolm <dmalcolm@redhat.com>
2514 * analyzer-language.cc: New file.
2515 * analyzer-language.h: New file.
2516 * analyzer.h (get_stashed_constant_by_name): New decl.
2517 (log_stashed_constants): New decl.
2518 * engine.cc (impl_run_checkers): Call log_stashed_constants.
2519 * region-model-impl-calls.cc
2520 (region_model::impl_call_analyzer_dump_named_constant): New.
2521 * region-model.cc (region_model::on_stmt_pre): Handle
2522 __analyzer_dump_named_constant.
2524 (region_model::impl_call_analyzer_dump_named_constant): New decl.
2525 * sm-fd.cc (fd_state_machine::m_O_ACCMODE): New.
2526 (fd_state_machine::m_O_RDONLY): New.
2527 (fd_state_machine::m_O_WRONLY): New.
2528 (fd_state_machine::fd_state_machine): Initialize the new fields.
2529 (fd_state_machine::get_access_mode_from_flag): Use the new fields,
2530 rather than using the host values.
2532 2022-11-13 David Malcolm <dmalcolm@redhat.com>
2535 * analyzer.opt (Wanalyzer-tainted-assertion): New.
2536 * checker-path.cc (checker_path::fixup_locations): Pass false to
2537 pending_diagnostic::fixup_location.
2538 * diagnostic-manager.cc (get_emission_location): Pass true to
2539 pending_diagnostic::fixup_location.
2540 * pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
2542 * pending-diagnostic.h (pending_diagnostic::fixup_location): Add
2544 * sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
2545 (taint_diagnostic::describe_state_change): Drop "final".
2546 (class tainted_assertion): New.
2547 (taint_state_machine::taint_state_machine): Initialize
2548 m_tainted_control_flow.
2549 (taint_state_machine::alt_get_inherited_state): Support
2550 comparisons being tainted, based on their arguments.
2551 (is_assertion_failure_handler_p): New.
2552 (taint_state_machine::on_stmt): Complain about calls to assertion
2553 failure handlers guarded by an attacker-controller conditional.
2554 Detect attacker-controlled gcond conditionals and gswitch index
2556 (taint_state_machine::check_control_flow_arg_for_taint): New.
2558 2022-11-11 David Malcolm <dmalcolm@redhat.com>
2560 * sm-fd.dot: Fix typo in comment.
2561 * sm-file.dot: New file.
2562 * varargs.cc: Fix typo in comment.
2563 * varargs.dot: New file.
2565 2022-11-11 David Malcolm <dmalcolm@redhat.com>
2567 * checker-path.h: Split out checker_event and its subclasses to...
2568 * checker-event.h: ...this new header.
2570 2022-11-11 David Malcolm <dmalcolm@redhat.com>
2573 * analyzer.opt (Wanalyzer-infinite-recursion): New.
2574 * call-string.cc (call_string::count_occurrences_of_function):
2576 * call-string.h (call_string::count_occurrences_of_function): New
2578 * checker-path.cc (function_entry_event::function_entry_event):
2580 (checker_path::add_final_event): Delete.
2581 * checker-path.h (function_entry_event::function_entry_event): New
2583 (function_entry_event::get_desc): Drop "final".
2584 (checker_path::add_final_event): Delete.
2585 * diagnostic-manager.cc
2586 (diagnostic_manager::emit_saved_diagnostic): Create the final
2587 event via a new pending_diagnostic::add_final_event vfunc, rather
2588 than checker_path::add_final_event.
2589 (diagnostic_manager::add_events_for_eedge): Create function entry
2590 events via a new pending_diagnostic::add_function_entry_event
2592 * engine.cc (exploded_graph::process_node): When creating a new
2593 PK_BEFORE_SUPERNODE node, call
2594 exploded_graph::detect_infinite_recursion on it after adding the
2596 * exploded-graph.h (exploded_graph::detect_infinite_recursion):
2598 (exploded_graph::find_previous_entry_to): New decl.
2599 * infinite-recursion.cc: New file.
2600 * pending-diagnostic.cc
2601 (pending_diagnostic::add_function_entry_event): New.
2602 (pending_diagnostic::add_final_event): New.
2603 * pending-diagnostic.h
2604 (pending_diagnostic::add_function_entry_event): New vfunc.
2605 (pending_diagnostic::add_final_event): New vfunc.
2607 2022-11-10 David Malcolm <dmalcolm@redhat.com>
2610 * analyzer.opt (Wanalyzer-deref-before-check): New warning.
2611 * diagnostic-manager.cc
2612 (null_assignment_sm_context::set_next_state): Only add state
2613 change events for transition to "null" state.
2614 (null_assignment_sm_context::is_transition_to_null): New.
2615 * engine.cc (impl_region_model_context::on_pop_frame): New.
2616 * exploded-graph.h (impl_region_model_context::on_pop_frame): New
2618 * program-state.cc (sm_state_map::clear_any_state): New.
2619 (sm_state_map::can_merge_with_p): New.
2620 (program_state::can_merge_with_p): Replace requirement that
2621 sm-states be equal in favor of an attempt to merge them.
2622 * program-state.h (sm_state_map::clear_any_state): New decl.
2623 (sm_state_map::can_merge_with_p): New decl.
2624 * region-model.cc (region_model::eval_condition): Make const.
2625 (region_model::pop_frame): Call ctxt->on_pop_frame.
2626 * region-model.h (region_model::eval_condition): Make const.
2627 (region_model_context::on_pop_frame): New vfunc.
2628 (noop_region_model_context::on_pop_frame): New.
2629 (region_model_context_decorator::on_pop_frame): New.
2630 * sm-malloc.cc (enum resource_state): Add RS_ASSUMED_NON_NULL.
2631 (allocation_state::dump_to_pp): Drop "final".
2632 (struct assumed_non_null_state): New subclass.
2633 (malloc_state_machine::m_assumed_non_null): New.
2634 (assumed_non_null_p): New.
2635 (class deref_before_check): New.
2636 (assumed_non_null_state::dump_to_pp): New.
2637 (malloc_state_machine::get_or_create_assumed_non_null_state_for_frame):
2639 (malloc_state_machine::maybe_assume_non_null): New.
2640 (malloc_state_machine::on_stmt): Transition from start state to
2641 "assumed-non-null" state for pointers passed to
2642 __attribute__((nonnull)) arguments, and for pointers explicitly
2643 dereferenced. Call maybe_complain_about_deref_before_check for
2644 pointers explicitly compared against NULL.
2645 (malloc_state_machine::maybe_complain_about_deref_before_check):
2647 (malloc_state_machine::on_deallocator_call): Also transition
2648 "assumed-non-null" states to "freed".
2649 (malloc_state_machine::on_pop_frame): New.
2650 (malloc_state_machine::maybe_get_merged_states_nonequal): New.
2651 * sm-malloc.dot: Update for changes to sm-malloc.cc.
2652 * sm.h (state_machine::on_pop_frame): New.
2653 (state_machine::maybe_get_merged_state): New.
2654 (state_machine::maybe_get_merged_states_nonequal): New.
2656 2022-11-09 David Malcolm <dmalcolm@redhat.com>
2658 * checker-path.cc (checker_event::debug): New.
2659 (checker_path::add_event): Move here from checker-path.h. Add
2661 * checker-path.h (checker_event::debug): New decl.
2662 (checker_path::checker_path): Add logger param.
2663 (checker_path::add_event): Move definition from here to
2665 (checker_path::m_logger): New field.
2666 * diagnostic-manager.cc
2667 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
2669 (diagnostic_manager::add_events_for_eedge): Log scope when
2670 processing a run of stmts.
2672 2022-11-08 David Malcolm <dmalcolm@redhat.com>
2675 * region-model-impl-calls.cc: Update comment.
2676 * region-model.cc (region_model::check_symbolic_bounds): Fix
2677 layout of "void" return. Replace usage of
2678 eval_condition_without_cm with eval_condition.
2679 (region_model::eval_condition): Take over body of...
2680 (region_model::eval_condition_without_cm): ...this subroutine,
2681 dropping the latter. Eliminating this distinction avoids issues
2682 where constraints were not considered when recursing.
2683 (region_model::compare_initial_and_pointer): Update comment.
2684 (region_model::symbolic_greater_than): Replace usage of
2685 eval_condition_without_cm with eval_condition.
2687 (region_model::eval_condition_without_cm): Delete decl.
2689 2022-11-08 David Malcolm <dmalcolm@redhat.com>
2691 * region-model-impl-calls.cc
2692 (region_model::impl_call_errno_location): New.
2693 * region-model-manager.cc
2694 (region_model_manager::region_model_manager): Initialize
2695 m_thread_local_region and m_errno_region.
2696 * region-model-manager.h (region_model_manager::get_errno_region):
2698 (region_model_manager::m_thread_local_region): New.
2699 (region_model_manager::m_errno_region): New.
2700 * region-model.cc (region_model::on_call_pre): Special-case
2702 (region_model::set_errno): New.
2703 * region-model.h (impl_call_errno_location): New decl.
2704 (region_model::set_errno): New decl.
2705 * region.cc (thread_local_region::dump_to_pp): New.
2706 (errno_region::dump_to_pp): New.
2707 * region.h (enum memory_space): Add MEMSPACE_THREAD_LOCAL.
2708 (enum region_kind): Add RK_THREAD_LOCAL and RK_ERRNO.
2709 (class thread_local_region): New.
2710 (is_a_helper <const thread_local_region *>::test): New.
2711 (class errno_region): New.
2712 (is_a_helper <const errno_region *>::test): New.
2713 * store.cc (binding_cluster::escaped_p): New.
2714 (store::escaped_p): Treat errno as always having escaped.
2715 (store::replay_call_summary_cluster): Handle RK_THREAD_LOCAL and
2717 * store.h (binding_cluster::escaped_p): Remove definition.
2719 2022-11-08 David Malcolm <dmalcolm@redhat.com>
2721 * call-info.cc (success_call_info::get_desc): Delete.
2722 (failed_call_info::get_desc): Likewise.
2723 (succeed_or_fail_call_info::get_desc): New.
2724 * call-info.h (class succeed_or_fail_call_info): New.
2725 (class success_call_info): Convert to a subclass of
2726 succeed_or_fail_call_info.
2727 (class failed_call_info): Likewise.
2729 2022-11-08 David Malcolm <dmalcolm@redhat.com>
2731 * region-model-impl-calls.cc (region_model::impl_call_strchr):
2732 Move to on_call_post. Handle both outcomes using bifurcation,
2733 rather than just the "not found" case.
2734 * region-model.cc (region_model::on_call_pre): Move
2735 BUILT_IN_STRCHR and "strchr" to...
2736 (region_model::on_call_post): ...here.
2738 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2740 * analyzer.h: Use std::unique_ptr for state machines from plugins.
2741 * engine.cc: Likewise.
2743 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2745 * analyzer.h: Use std::unique_ptr for known functions.
2746 * engine.cc: Likewise.
2747 * known-function-manager.cc: Likewise.
2748 * known-function-manager.h: Likewise.
2750 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2752 * analysis-plan.cc: Define INCLUDE_MEMORY before including
2754 * analyzer-pass.cc: Likewise.
2755 * analyzer-selftests.cc: Likewise.
2756 * analyzer.cc: Likewise.
2757 * analyzer.h: Use std::unique_ptr in bifurcation code.
2758 * call-string.cc: Define INCLUDE_MEMORY before including system.h.
2759 * complexity.cc: Likewise.
2760 * engine.cc: Use std::unique_ptr in bifurcation code.
2761 * exploded-graph.h: Likewise.
2762 * known-function-manager.cc: Define INCLUDE_MEMORY before
2764 * region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
2766 * region-model.cc: Likewise.
2767 * region-model.h: Likewise.
2768 * supergraph.cc: Define INCLUDE_MEMORY before including system.h.
2770 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2772 * call-info.cc: Use std::unique_ptr for checker_event.
2773 * checker-path.cc: Likewise.
2774 * checker-path.h: Likewise.
2775 * diagnostic-manager.cc: Likewise.
2776 * engine.cc: Likewise.
2777 * pending-diagnostic.cc: Likewise.
2778 * sm-signal.cc: Likewise.
2779 * varargs.cc: Likewise.
2781 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2783 * diagnostic-manager.cc: Include "make-unique.h".
2784 Use std::unique_ptr for feasibility_problems and exploded_path.
2785 Delete explicit saved_diagnostic dtor.
2786 * diagnostic-manager.h: Likewise.
2787 * engine.cc: Likewise.
2788 * exploded-graph.h: Likewise.
2789 * feasible-graph.cc: Likewise.
2790 * feasible-graph.h: Likewise.
2792 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2794 * checker-path.cc (rewind_event::rewind_event): Update for usage of
2795 std::unique_ptr on custom_edge_info.
2796 * engine.cc (exploded_node::on_longjmp): Likewise.
2797 (exploded_edge::exploded_edge): Likewise.
2798 (exploded_edge::~exploded_edge): Delete.
2799 (exploded_graph::add_function_entry): Update for usage of
2800 std::unique_ptr on custom_edge_info.
2801 (exploded_graph::add_edge): Likewise.
2802 (add_tainted_args_callback): Likewise.
2803 (exploded_graph::maybe_create_dynamic_call): Likewise.
2804 (exploded_graph::process_node): Likewise.
2805 * exploded-graph.h (exploded_edge::~exploded_edge): Delete.
2806 (exploded_edge::m_custom_info): Use std::unique_ptr.
2807 (exploded_edge::add_edge): Likewise.
2808 * sm-signal.cc (register_signal_handler::impl_transition): Use
2811 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2813 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Make
2815 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of
2817 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
2818 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
2820 (saved_diagnostic::m_stmt_finder): Convert to std::unique_ptr.
2821 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
2822 * engine.cc (impl_sm_context::impl_sm_context): Likewise.
2823 (impl_sm_context::m_stmt_finder): Likewise.
2824 (leak_stmt_finder::clone): Convert return type to std::unique_ptr.
2825 * exploded-graph.h (stmt_finder::clone): Likewise.
2827 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2829 * call-info.cc: Add define of INCLUDE_MEMORY.
2830 * call-summary.cc: Likewise.
2831 * checker-path.cc: Likewise.
2832 * constraint-manager.cc: Likewise.
2833 * diagnostic-manager.cc: Likewise.
2834 (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for
2835 param d and field m_d.
2836 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d.
2837 (saved_diagnostic::add_note): Use std::unique_ptr for
2839 (saved_diagnostic::get_pending_diagnostic): Update for conversion
2840 of m_sd.m_d to unique_ptr.
2841 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
2842 param d. Remove explicit deletion.
2843 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
2844 (diagnostic_manager::emit_saved_diagnostic): Update for conversion
2845 of m_sd.m_d to unique_ptr.
2846 (null_assignment_sm_context::warn): Use std::unique_ptr for
2847 param d. Remove explicit deletion.
2848 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use
2849 std::unique_ptr for param d.
2850 (saved_diagnostic::add_note): Likewise for param pn.
2851 (saved_diagnostic::m_d): Likewise.
2852 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
2854 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
2855 * engine.cc: Include "make-unique.h".
2856 (impl_region_model_context::warn): Update to use std::unique_ptr
2857 for param, removing explicit deletion.
2858 (impl_region_model_context::add_note): Likewise.
2859 (impl_sm_context::warn): Update to use std::unique_ptr
2861 (impl_region_model_context::on_state_leak): Likewise for result of
2863 (exploded_node::on_longjmp): Use make_unique when creating
2865 (exploded_graph::process_node): Likewise.
2866 * exploded-graph.h (impl_region_model_context::warn): Update to
2867 use std::unique_ptr for param.
2868 (impl_region_model_context::add_note): Likewise.
2869 * feasible-graph.cc: Add define of INCLUDE_MEMORY.
2870 * pending-diagnostic.cc: Likewise.
2871 * pending-diagnostic.h: Include analyzer.sm.h"
2872 * program-point.cc: Add define of INCLUDE_MEMORY.
2873 * program-state.cc: Likewise.
2874 * region-model-asm.cc: Likewise.
2875 * region-model-impl-calls.cc: Likewise. Include "make-unique.h".
2876 (region_model::impl_call_putenv): Use make_unique when creating
2878 * region-model-manager.cc: Add define of INCLUDE_MEMORY.
2879 * region-model-reachability.cc: Likewise.
2880 * region-model.cc: Likewise. Include "make-unique.h".
2881 (region_model::get_gassign_result): Use make_unique when creating
2883 (region_model::check_for_poison): Likewise.
2884 (region_model::on_stmt_pre): Likewise.
2885 (region_model::check_symbolic_bounds): Likewise.
2886 (region_model::check_region_bounds): Likewise.
2887 (annotating_ctxt: make_note): Use std::unique_ptr for result.
2888 (region_model::deref_rvalue): Use make_unique when creating
2890 (region_model::check_for_writable_region): Likewise.
2891 (region_model::check_region_size): Likewise.
2892 (region_model::check_dynamic_size_for_floats): Likewise.
2893 (region_model::maybe_complain_about_infoleak): Likewise.
2894 (noop_region_model_context::add_note): Use std::unique_ptr for
2895 param. Remove explicit deletion.
2896 * region-model.h: Include "analyzer/pending-diagnostic.h".
2897 (region_model_context::warn): Convert param to std::unique_ptr.
2898 (region_model_context::add_note): Likewise.
2899 (noop_region_model_context::warn): Likewise.
2900 (noop_region_model_context::add_note): Likewise.
2901 (region_model_context_decorator::warn): Likewise.
2902 (region_model_context_decorator::add_note): Likewise.
2903 (note_adding_context::warn): Likewise.
2904 (note_adding_context::make_note): Likewise for return type.
2905 (test_region_model_context::warn): Convert param to
2907 * region.cc: Add define of INCLUDE_MEMORY.
2908 * sm-fd.cc: Likewise. Include "make-unique.h".
2909 (fd_state_machine::check_for_fd_attrs): Use make_unique when
2910 creating pending_diagnostics.
2911 (fd_state_machine::on_open): Likewise.
2912 (fd_state_machine::on_creat): Likewise.
2913 (fd_state_machine::check_for_dup): Likewise.
2914 (fd_state_machine::on_close): Likewise.
2915 (fd_state_machine::check_for_open_fd): Likewise.
2916 (fd_state_machine::on_leak): Likewise, converting return type to
2918 * sm-file.cc: Add define of INCLUDE_MEMORY. Include
2920 (fileptr_state_machine::on_stmt): Use make_unique when creating
2922 (fileptr_state_machine::on_leak): Likewise, converting return type
2924 * sm-malloc.cc: Add define of INCLUDE_MEMORY. Include
2926 (malloc_state_machine::on_stmt): Use make_unique when creating
2928 (malloc_state_machine::handle_free_of_non_heap): Likewise.
2929 (malloc_state_machine::on_deallocator_call): Likewise.
2930 (malloc_state_machine::on_realloc_call): Likewise.
2931 (malloc_state_machine::on_leak): Likewise, converting return type
2933 * sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include
2935 (pattern_test_state_machine::on_condition): Use make_unique when
2936 creating pending_diagnostic.
2937 * sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include
2939 (sensitive_state_machine::warn_for_any_exposure): Use make_unique
2940 when creating pending_diagnostic.
2941 * sm-signal.cc: Add define of INCLUDE_MEMORY. Include
2943 (signal_state_machine::on_stmt): Use make_unique when creating
2945 * sm-taint.cc: Add define of INCLUDE_MEMORY. Include
2947 (taint_state_machine::check_for_tainted_size_arg): Use make_unique
2948 when creating pending_diagnostic.
2949 (taint_state_machine::check_for_tainted_divisor): Likewise.
2950 (region_model::check_region_for_taint): Likewise.
2951 (region_model::check_dynamic_size_for_taint): Likewise.
2952 * sm.cc: Add define of INCLUDE_MEMORY. Include
2953 "analyzer/pending-diagnostic.h".
2954 (state_machine::on_leak): Move here from sm.h, changing return
2955 type to std::unique_ptr.
2956 * sm.h (state_machine::on_leak): Change return type to
2957 std::unique_ptr. Move defn of base impl to sm.cc
2958 (sm_context::warn): Convert param d to std_unique_ptr.
2959 * state-purge.cc: Add define of INCLUDE_MEMORY.
2960 * store.cc: Likewise.
2961 * svalue.cc: Likewise.
2962 * trimmed-graph.cc: Likewise.
2963 * varargs.cc: Likewise. Include "make-unique.h".
2964 (va_list_state_machine::check_for_ended_va_list): Use make_unique
2965 when creating pending_diagnostic.
2966 (va_list_state_machine::on_leak): Likewise, converting return type
2968 (region_model::impl_call_va_arg): Use make_unique when creating
2971 2022-11-03 David Malcolm <dmalcolm@redhat.com>
2974 * analyzer.cc (is_pipe_call_p): New.
2975 * analyzer.h (is_pipe_call_p): New decl.
2976 * region-model.cc (region_model::on_call_pre): Use it.
2977 (region_model::on_call_post): Likewise.
2979 2022-10-26 David Malcolm <dmalcolm@redhat.com>
2981 * sm-fd.cc (fd_state_machine::on_open): Transition to "unchecked"
2982 when the mode is symbolic, rather than just on integer constants.
2983 (fd_state_machine::check_for_open_fd): Don't complain about
2984 unchecked values in the start state.
2986 2022-10-26 David Malcolm <dmalcolm@redhat.com>
2988 * sm-fd.dot: New file.
2990 2022-10-24 David Malcolm <dmalcolm@redhat.com>
2993 * varargs.cc (get_va_copy_arg): Fix the non-pointer case.
2995 2022-10-24 David Malcolm <dmalcolm@redhat.com>
2998 * region-model.cc (region_model::eval_condition_without_cm):
2999 Ensure that constants are on the right-hand side before checking
3002 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3004 * engine.cc (impl_region_model_context::get_malloc_map): Replace
3006 (impl_region_model_context::get_state_map_by_name): ...this.
3007 (impl_region_model_context::get_fd_map): Delete.
3008 (impl_region_model_context::get_taint_map): Delete.
3009 * exploded-graph.h (impl_region_model_context::get_fd_map):
3011 (impl_region_model_context::get_malloc_map): Delete.
3012 (impl_region_model_context::get_taint_map): Delete.
3013 (impl_region_model_context::get_state_map_by_name): New.
3014 * region-model.h (region_model_context::get_state_map_by_name):
3016 (region_model_context::get_fd_map): Convert from vfunc to
3018 (region_model_context::get_malloc_map): Likewise.
3019 (region_model_context::get_taint_map): Likewise.
3020 (noop_region_model_context::get_state_map_by_name): New.
3021 (noop_region_model_context::get_fd_map): Delete.
3022 (noop_region_model_context::get_malloc_map): Delete.
3023 (noop_region_model_context::get_taint_map): Delete.
3024 (region_model_context_decorator::get_state_map_by_name): New.
3025 (region_model_context_decorator::get_fd_map): Delete.
3026 (region_model_context_decorator::get_malloc_map): Delete.
3027 (region_model_context_decorator::get_taint_map): Delete.
3029 2022-10-24 David Malcolm <dmalcolm@redhat.com>
3032 * engine.cc (impl_region_model_context::get_fd_map): New.
3033 * exploded-graph.h (impl_region_model_context::get_fd_map): New
3035 * region-model-impl-calls.cc (region_model::impl_call_pipe): New.
3036 * region-model.cc (region_model::update_for_int_cst_return): New,
3038 (region_model::update_for_zero_return): ...this. Reimplement in
3039 terms of the former.
3040 (region_model::on_call_pre): Handle "pipe" and "pipe2".
3041 (region_model::on_call_post): Likewise.
3042 * region-model.h (region_model::impl_call_pipe): New decl.
3043 (region_model::update_for_int_cst_return): New decl.
3044 (region_model::mark_as_valid_fd): New decl.
3045 (region_model_context::get_fd_map): New pure virtual fn.
3046 (noop_region_model_context::get_fd_map): New.
3047 (region_model_context_decorator::get_fd_map): New.
3048 * sm-fd.cc: Include "analyzer/program-state.h".
3049 (fd_state_machine::describe_state_change): Handle transitions from
3050 start state to valid states.
3051 (fd_state_machine::mark_as_valid_fd): New.
3052 (fd_state_machine::on_stmt): Add missing return for "creat".
3053 (region_model::mark_as_valid_fd): New.
3055 2022-10-19 David Malcolm <dmalcolm@redhat.com>
3058 * varargs.cc (get_BT_VALIST_ARG): Rename to...
3059 (get_va_copy_arg): ...this, and update logic for determining level
3060 of indirection of va_copy's argument to use type of argument,
3061 rather than looking at va_list_type_node, to correctly handle
3062 __builtin_ms_va_copy.
3063 (get_stateful_BT_VALIST_ARG): Rename to...
3064 (get_stateful_va_copy_arg): ...this.
3065 (va_list_state_machine::on_va_copy): Update for renaming.
3066 (region_model::impl_call_va_copy): Likewise.
3068 2022-10-13 David Malcolm <dmalcolm@redhat.com>
3071 * svalue.cc (constant_svalue::maybe_fold_bits_within): Only
3072 attempt to extract individual bits when tree_fits_uhwi_p.
3074 2022-10-07 David Malcolm <dmalcolm@redhat.com>
3077 * region-model.cc (selftest::get_bit): New function.
3078 (selftest::test_bits_within_svalue_folding): New.
3079 (selfftest::analyzer_region_model_cc_tests): Call it.
3080 * svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
3081 case of extracting a single bit.
3083 2022-10-06 David Malcolm <dmalcolm@redhat.com>
3086 * store.cc (store::replay_call_summary_cluster): Eliminate
3087 special-casing of RK_HEAP_ALLOCATED in favor of sharing code with
3088 RK_DECL, avoiding an ICE due to attempting to bind a
3089 compound_svalue into a binding_cluster when an svalue in the
3090 summary cluster converts to a compound_svalue in the caller.
3092 2022-10-06 David Malcolm <dmalcolm@redhat.com>
3094 * call-summary.cc (call_summary_replay::dump_to_pp): Bulletproof
3095 against NULL caller regions/svalues.
3097 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3099 * analysis-plan.cc: Simplify includes.
3100 * analyzer-pass.cc: Likewise.
3101 * analyzer-selftests.cc: Likewise.
3102 * analyzer.cc: Likewise.
3103 * analyzer.h: Add includes of "json.h" and "tristate.h".
3104 * call-info.cc: Simplify includes.
3105 * call-string.cc: Likewise.
3106 * call-summary.cc: Likewise.
3107 * checker-path.cc: Likewise.
3108 * complexity.cc: Likewise.
3109 * constraint-manager.cc: Likewise.
3110 * diagnostic-manager.cc: Likewise.
3111 * engine.cc: Likewise.
3112 * feasible-graph.cc: Likewise.
3113 * known-function-manager.cc: Likewise.
3114 * pending-diagnostic.cc: Likewise.
3115 * program-point.cc: Likewise.
3116 * program-state.cc: Likewise.
3117 * region-model-asm.cc: Likewise.
3118 * region-model-impl-calls.cc: Likewise.
3119 * region-model-manager.cc: Likewise.
3120 * region-model-reachability.cc: Likewise.
3121 * region-model.cc: Likewise.
3122 * region-model.h: Include "selftest.h".
3123 * region.cc: Simplify includes.
3124 * sm-fd.cc: Likewise.
3125 * sm-file.cc: Likewise.
3126 * sm-malloc.cc: Likewise.
3127 * sm-pattern-test.cc: Likewise.
3128 * sm-sensitive.cc: Likewise.
3129 * sm-signal.cc: Likewise.
3130 * sm-taint.cc: Likewise.
3132 * state-purge.cc: Likewise.
3133 * store.cc: Likewise.
3134 * store.h: Likewise.
3135 * supergraph.cc: Likewise.
3136 * svalue.cc: Likewise.
3137 * svalue.h: Likewise.
3138 * trimmed-graph.cc: Likewise.
3139 * varargs.cc: Likewise.
3141 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3145 (call_summary_replay::convert_svalue_from_summary_1): Handle NULL
3146 results from convert_svalue_from_summary in SK_UNARY_OP and
3148 * engine.cc (impl_region_model_context::on_unknown_change): Bail
3149 out on svalues that can't have associated state.
3150 * region-model-impl-calls.cc
3151 (region_model::impl_call_analyzer_get_unknown_ptr): New.
3152 * region-model.cc (region_model::on_stmt_pre): Handle
3153 "__analyzer_get_unknown_ptr".
3155 (region_model::impl_call_analyzer_get_unknown_ptr): New decl.
3156 * store.cc (store::replay_call_summary_cluster): Avoid trying to
3157 create binding clusters for base regions that shouldn't have them.
3159 2022-10-05 Martin Liska <mliska@suse.cz>
3161 * call-summary.cc (call_summary_replay::call_summary_replay):
3162 Remove unused variable and arguments.
3163 * call-summary.h: Likewise.
3164 * engine.cc (exploded_node::on_stmt): Likewise.
3165 (exploded_node::replay_call_summaries): Likewise.
3166 (exploded_node::replay_call_summary): Likewise.
3167 * exploded-graph.h (class exploded_node): Likewise.
3169 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3172 * analyzer-logging.h: Include "diagnostic-core.h".
3173 * analyzer.h: Include "function.h".
3174 (class call_summary): New forward decl.
3175 (class call_summary_replay): New forward decl.
3176 (struct per_function_data): New forward decl.
3177 (struct interesting_t): New forward decl.
3178 (custom_edge_info::update_state): New vfunc.
3179 * call-info.cc (custom_edge_info::update_state): New.
3180 * call-summary.cc: New file.
3181 * call-summary.h: New file.
3182 * constraint-manager.cc: Include "analyzer/call-summary.h".
3183 (class replay_fact_visitor): New.
3184 (constraint_manager::replay_call_summary): New.
3185 * constraint-manager.h (constraint_manager::replay_call_summary):
3187 * engine.cc: Include "analyzer/call-summary.h".
3188 (exploded_node::on_stmt): Handle call summaries.
3189 (class call_summary_edge_info): New.
3190 (exploded_node::replay_call_summaries): New.
3191 (exploded_node::replay_call_summary): New.
3192 (per_function_data::~per_function_data): New.
3193 (per_function_data::add_call_summary): Move here from header and
3195 (exploded_graph::process_node): Call update_state rather than
3196 update_model when handling bifurcation
3197 (viz_callgraph_node::dump_dot): Use a regular label rather
3198 than an HTML table; add summaries to dump.
3199 * exploded-graph.h: Include "alloc-pool.h", "fibonacci_heap.h",
3200 "supergraph.h", "sbitmap.h", "shortest-paths.h", "analyzer/sm.h",
3201 "analyzer/program-state.h", and "analyzer/diagnostic-manager.h".
3202 (exploded_node::replay_call_summaries): New decl.
3203 (exploded_node::replay_call_summary): New decl.
3204 (per_function_data::~per_function_data): New decl.
3205 (per_function_data::add_call_summary): Move implemention from
3207 (per_function_data::m_summaries): Update type of element.
3208 * known-function-manager.h: Include "analyzer/analyzer-logging.h".
3209 * program-point.h: Include "pretty-print.h" and
3210 "analyzer/call-string.h".
3211 * program-state.cc: Include "analyzer/call-summary.h".
3212 (sm_state_map::replay_call_summary): New.
3213 (program_state::replay_call_summary): New.
3214 * program-state.h (sm_state_map::replay_call_summary): New decl.
3215 (program_state::replay_call_summary): New decl.
3216 * region-model-manager.cc
3217 (region_model_manager::get_or_create_asm_output_svalue): New
3219 * region-model-manager.h
3220 (region_model_manager::get_or_create_asm_output_svalue): New
3222 * region-model.cc: Include "analyzer/call-summary.h".
3223 (region_model::maybe_update_for_edge): Remove call to
3224 region_model::update_for_call_summary on
3225 SUPEREDGE_INTRAPROCEDURAL_CALL.
3226 (region_model::update_for_call_summary): Delete.
3227 (region_model::replay_call_summary): New.
3228 * region-model.h (region_model::replay_call_summary): New decl.
3229 (region_model::update_for_call_summary): Delete decl.
3230 * store.cc: Include "analyzer/call-summary.h".
3231 (store::replay_call_summary): New.
3232 (store::replay_call_summary_cluster): New.
3233 * store.h: Include "tristate.h".
3234 (is_a_helper <const ana::concrete_binding *>::test): New.
3235 (store::replay_call_summary): New decl.
3236 (store::replay_call_summary_cluster): New decl.
3237 * supergraph.cc (get_ultimate_function_for_cgraph_edge): Remove
3239 (supergraph_call_edge): Make stmt param const.
3240 * supergraph.h: Include "ordered-hash-map.h", "cfg.h",
3241 "basic-block.h", "gimple.h", "gimple-iterator.h", and "digraph.h".
3242 (supergraph_call_edge): Make stmt param const.
3243 (get_ultimate_function_for_cgraph_edge): New decl.
3244 * svalue.cc (compound_svalue::compound_svalue): Assert that we're
3245 not nesting compound_svalues.
3246 * svalue.h: Include "json.h", "analyzer/store.h", and
3247 "analyzer/program-point.h".
3248 (asm_output_svalue::get_num_outputs): New accessor.
3250 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3252 * region-model.h: Include "analyzer/region-model-manager.h"
3253 (class region_model_manager): Move decl to...
3254 * region-model-manager.h: ...this new file.
3256 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3258 * region-model-manager.cc
3259 (region_model_manager::maybe_fold_unaryop): Fold -(-(VAL)) to VAL.
3261 2022-10-05 David Malcolm <dmalcolm@redhat.com>
3263 * region-model-manager.cc
3264 (region_model_manager::get_or_create_widening_svalue): Use a
3265 function_point rather than a program_point.
3266 * region-model.cc (selftest::test_widening_constraints): Likewise.
3268 (region_model_manager::get_or_create_widening_svalue): Likewise.
3269 (model_merger::get_function_point): New.
3270 * svalue.cc (svalue::can_merge_p): Use a function_point rather
3271 than a program_point.
3272 (svalue::can_merge_p): Likewise.
3273 * svalue.h (widening_svalue::key_t): Likewise.
3274 (widening_svalue::widening_svalue): Likewise.
3276 2022-09-12 Martin Liska <mliska@suse.cz>
3278 * region-model.cc (region_model::maybe_complain_about_infoleak):
3279 Remove unused fields.
3281 2022-09-11 Tim Lange <mail@tim-lange.me>
3284 * region-model.cc (region_model::check_region_bounds):
3285 Bail out if 0 bytes were accessed.
3286 * store.cc (byte_range::dump_to_pp):
3287 Add special case for empty ranges.
3288 (byte_range::exceeds_p): Restrict to non-empty ranges.
3289 (byte_range::falls_short_of_p): Restrict to non-empty ranges.
3290 * store.h (bit_range::empty_p): New function.
3291 (bit_range::get_last_byte_offset): Restrict to non-empty ranges.
3292 (byte_range::empty_p): New function.
3293 (byte_range::get_last_byte_offset): Restrict to non-empty ranges.
3295 2022-09-09 David Malcolm <dmalcolm@redhat.com>
3297 * analyzer.opt (Wanalyzer-exposure-through-uninit-copy): New.
3298 * checker-path.cc (region_creation_event::region_creation_event):
3299 Add "capacity" and "kind" params.
3300 (region_creation_event::get_desc): Generalize to different kinds
3302 (checker_path::add_region_creation_event): Convert to...
3303 (checker_path::add_region_creation_events): ...this.
3304 * checker-path.h (enum rce_kind): New.
3305 (region_creation_event::region_creation_event): Add "capacity" and
3307 (region_creation_event::m_capacity): New field.
3308 (region_creation_event::m_rce_kind): New field.
3309 (checker_path::add_region_creation_event): Convert to...
3310 (checker_path::add_region_creation_events): ...this.
3311 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
3312 Update for multiple region creation events.
3313 (diagnostic_manager::add_event_on_final_node): Likewise.
3314 (diagnostic_manager::add_events_for_eedge): Likewise.
3315 * region-model-impl-calls.cc (call_details::get_logger): New.
3316 * region-model.cc: Define INCLUDE_MEMORY before including
3317 "system.h". Include "gcc-rich-location.h".
3318 (class record_layout): New.
3319 (class exposure_through_uninit_copy): New.
3320 (contains_uninit_p): New.
3321 (region_model::maybe_complain_about_infoleak): New.
3322 * region-model.h (call_details::get_logger): New decl.
3323 (region_model::maybe_complain_about_infoleak): New decl.
3324 (region_model::mark_as_tainted): New decl.
3325 * sm-taint.cc (region_model::mark_as_tainted): New.
3327 2022-09-09 David Malcolm <dmalcolm@redhat.com>
3329 * analyzer.h (class known_function_manager): New forward decl.
3330 (class known_function): New.
3331 (plugin_analyzer_init_iface::register_known_function): New.
3332 * engine.cc: Include "analyzer/known-function-manager.h".
3333 (plugin_analyzer_init_impl::plugin_analyzer_init_impl): Add
3335 (plugin_analyzer_init_impl::register_state_machine): Add
3337 (plugin_analyzer_init_impl::register_known_function): New.
3338 (plugin_analyzer_init_impl::m_known_fn_mgr): New.
3339 (impl_run_checkers): Update plugin callback invocation to use
3340 eng's known_function_manager.
3341 * known-function-manager.cc: New file.
3342 * known-function-manager.h: New file.
3343 * region-model-manager.cc
3344 (region_model_manager::region_model_manager): Pass logger to
3345 m_known_fn_mgr's ctor.
3346 * region-model.cc (region_model::update_for_zero_return): New.
3347 (region_model::update_for_nonzero_return): New.
3348 (maybe_simplify_upper_bound): New.
3349 (region_model::maybe_get_copy_bounds): New.
3350 (region_model::get_known_function): New.
3351 (region_model::on_call_pre): Handle plugin-supplied known
3353 * region-model.h: Include "analyzer/known-function-manager.h".
3354 (region_model_manager::get_known_function_manager): New.
3355 (region_model_manager::m_known_fn_mgr): New.
3356 (call_details::get_model): New accessor.
3357 (region_model::maybe_get_copy_bounds): New decl.
3358 (region_model::update_for_zero_return): New decl.
3359 (region_model::update_for_nonzero_return): New decl.
3360 (region_model::get_known_function): New decl.
3361 (region_model::get_known_function_manager): New.
3363 2022-09-08 Tim Lange <mail@tim-lange.me>
3366 * analyzer.h (region_offset): Eliminate m_is_symbolic member.
3367 * region-model-impl-calls.cc (region_model::impl_call_realloc):
3368 Refine implementation to be more precise.
3369 * region-model.cc (class symbolic_past_the_end):
3370 Abstract diagnostic class to complain about accesses past the end
3371 with symbolic values.
3372 (class symbolic_buffer_overflow):
3373 Concrete diagnostic class to complain about buffer overflows with
3375 (class symbolic_buffer_overread):
3376 Concrete diagnostic class to complain about buffer overreads with
3378 (region_model::check_symbolic_bounds): New function.
3379 (maybe_get_integer_cst_tree): New helper function.
3380 (region_model::check_region_bounds):
3381 Add call to check_symbolic_bounds if offset is not concrete.
3382 (region_model::eval_condition_without_cm):
3383 Add support for EQ_EXPR and GT_EXPR with binaryop_svalues.
3384 (is_positive_svalue): New hleper function.
3385 (region_model::symbolic_greater_than):
3386 New function to handle GT_EXPR comparisons with symbolic values.
3387 (region_model::structural_equality): New function to compare
3388 whether two svalues are structured the same, i.e. evaluate to
3390 (test_struct): Reflect changes to region::calc_offset.
3391 (test_var): Likewise.
3392 (test_array_2): Likewise and add selftest with symbolic i.
3393 * region-model.h (class region_model): Add check_symbolic_bounds,
3394 symbolic_greater_than and structural_equality.
3395 * region.cc (region::get_offset):
3396 Reflect changes to region::calc_offset.
3397 (region::calc_offset):
3398 Compute the symbolic offset if the offset is not concrete.
3399 (region::get_relative_symbolic_offset): New function to return the
3400 symbolic offset in bytes relative to its parent.
3401 (field_region::get_relative_symbolic_offset): Likewise.
3402 (element_region::get_relative_symbolic_offset): Likewise.
3403 (offset_region::get_relative_symbolic_offset): Likewise.
3404 (bit_range_region::get_relative_symbolic_offset): Likewise.
3405 * region.h: Add get_relative_symbolic_offset.
3406 * store.cc (binding_key::make):
3407 Reflect changes to region::calc_offset.
3408 (binding_map::apply_ctor_val_to_range): Likewise.
3409 (binding_map::apply_ctor_pair_to_child_region): Likewise.
3410 (binding_cluster::bind_compound_sval): Likewise.
3411 (binding_cluster::get_any_binding): Likewise.
3412 (binding_cluster::maybe_get_compound_binding): Likewise.
3414 2022-09-05 Tim Lange <mail@tim-lange.me>
3416 * region-model-impl-calls.cc (region_model::impl_call_strcpy):
3417 Handle the constant string case.
3418 * region-model.cc (region_model::get_string_size):
3419 New function to get the string size from a region or svalue.
3420 * region-model.h (class region_model): Add get_string_size.
3422 2022-09-05 Tim Lange <mail@tim-lange.me>
3424 * region.cc (cast_region::get_relative_concrete_offset):
3425 New overloaded method.
3426 * region.h: Add cast_region::get_relative_concrete_offset.
3428 2022-08-22 Martin Liska <mliska@suse.cz>
3430 * region-model.cc: Add missing final keyword.
3432 2022-08-18 Tim Lange <mail@tim-lange.me>
3435 * analyzer.opt: Add Wanalyzer-imprecise-floating-point-arithmetic.
3436 * region-model.cc (is_any_cast_p): Formatting.
3437 (region_model::check_region_size): Ensure precondition.
3438 (class imprecise_floating_point_arithmetic): New abstract
3439 diagnostic class for all floating-point related warnings.
3440 (class float_as_size_arg): Concrete diagnostic class to complain
3441 about floating-point operands inside the size argument.
3442 (class contains_floating_point_visitor):
3443 New visitor to find floating-point operands inside svalues.
3444 (region_model::check_dynamic_size_for_floats): New function.
3445 (region_model::set_dynamic_extents):
3446 Call to check_dynamic_size_for_floats.
3447 * region-model.h (class region_model):
3448 Add region_model::check_dynamic_size_for_floats.
3450 2022-08-16 Martin Liska <mliska@suse.cz>
3452 * region-model.cc: Fix -Winconsistent-missing-override clang
3454 * region.h: Likewise.
3456 2022-08-15 David Malcolm <dmalcolm@redhat.com>
3459 * region-model.cc (buffer_overread::emit): Fix copy&paste error in
3460 direction of the access in the note.
3462 2022-08-15 David Malcolm <dmalcolm@redhat.com>
3465 * region-model.cc (region_model::on_call_pre): Use check_call_args
3466 when ensuring that we call get_arg_svalue on all args. Remove
3467 redundant call from handling for stdio builtins.
3469 2022-08-15 Immad Mir <mirimmad@outlook.com>
3472 * sm-fd.cc (check_for_dup): exit early if first
3473 argument is invalid for all dup functions.
3475 2022-08-12 Tim Lange <mail@tim-lange.me>
3478 * analyzer.opt: Add Wanalyzer-out-of-bounds.
3479 * region-model.cc (class out_of_bounds): Diagnostics base class
3480 for all out-of-bounds diagnostics.
3481 (class past_the_end): Base class derived from out_of_bounds for
3482 the buffer_overflow and buffer_overread diagnostics.
3483 (class buffer_overflow): Buffer overflow diagnostics.
3484 (class buffer_overread): Buffer overread diagnostics.
3485 (class buffer_underflow): Buffer underflow diagnostics.
3486 (class buffer_underread): Buffer overread diagnostics.
3487 (region_model::check_region_bounds): New function to check region
3488 bounds for out-of-bounds accesses.
3489 (region_model::check_region_access):
3490 Add call to check_region_bounds.
3491 (region_model::get_representative_tree): New function that accepts
3492 a region instead of an svalue.
3493 * region-model.h (class region_model):
3494 Add region_model::check_region_bounds.
3495 * region.cc (region::symbolic_p): New predicate.
3496 (offset_region::get_byte_size_sval): Only return the remaining
3497 byte size on offset_regions.
3498 * region.h: Add region::symbolic_p.
3499 * store.cc (byte_range::intersects_p):
3500 Add new function equivalent to bit_range::intersects_p.
3501 (byte_range::exceeds_p): New function.
3502 (byte_range::falls_short_of_p): New function.
3503 * store.h (struct byte_range): Add byte_range::intersects_p,
3504 byte_range::exceeds_p and byte_range::falls_short_of_p.
3506 2022-08-12 Tim Lange <mail@tim-lange.me>
3509 * region-model-impl-calls.cc (region_model::impl_call_realloc):
3510 Use the result of get_copied_size as the size for the
3511 sized_regions in realloc.
3512 (success_with_move::get_copied_size): New function.
3514 2022-08-11 Immad Mir <mirimmad@outlook.com>
3517 * sm-fd.cc (check_for_dup): handle the m_start
3518 state when transitioning the state of LHS
3519 of dup, dup2 and dup3 call.
3521 2022-08-09 David Malcolm <dmalcolm@redhat.com>
3524 * region-model.cc (region_model::on_call_pre): Ensure that we call
3525 get_arg_svalue on all arguments.
3527 2022-08-05 David Malcolm <dmalcolm@redhat.com>
3530 * analyzer.opt (Wanalyzer-jump-through-null): New option.
3531 * engine.cc (class jump_through_null): New.
3532 (exploded_graph::process_node): Complain about jumps through NULL
3535 2022-08-02 Immad Mir <mirimmad@outlook.com>
3538 * sm-fd.cc (fd_state_machine::on_open): Add
3539 creat, dup, dup2 and dup3 functions.
3541 (fd_state_machine::valid_to_unchecked_state): New.
3542 (fd_state_machine::on_creat): New.
3543 (fd_state_machine::on_dup): New.
3545 2022-07-28 David Malcolm <dmalcolm@redhat.com>
3548 * analyzer.opt (Wanalyzer-putenv-of-auto-var): New.
3549 * region-model-impl-calls.cc (class putenv_of_auto_var): New.
3550 (region_model::impl_call_putenv): New.
3551 * region-model.cc (region_model::on_call_pre): Handle putenv.
3552 * region-model.h (region_model::impl_call_putenv): New decl.
3554 2022-07-28 David Malcolm <dmalcolm@redhat.com>
3556 * sm-malloc.cc (free_of_non_heap::emit): Add comment about CWE.
3557 * sm-taint.cc (tainted_size::emit): Likewise.
3559 2022-07-28 David Malcolm <dmalcolm@redhat.com>
3561 * region.h: Add notes to the comment describing the region
3564 2022-07-27 Immad Mir <mirimmad@outlook.com>
3568 (fd_diagnostic::get_meaning_for_state_change): New.
3570 2022-07-26 David Malcolm <dmalcolm@redhat.com>
3573 * store.cc (store::set_value): Don't strip away casts if the
3574 region has NULL type.
3576 2022-07-26 David Malcolm <dmalcolm@redhat.com>
3578 * region.h (code_region::get_element): Remove stray decl.
3579 (function_region::get_element): Likewise.
3581 2022-07-25 Martin Liska <mliska@suse.cz>
3583 * sm-fd.cc: Run dos2unix and fix coding style issues.
3585 2022-07-23 Immad Mir <mirimmad@outlook.com>
3587 * sm-fd.cc (fd_param_diagnostic): New diagnostic class.
3588 (fd_access_mode_mismatch): Change inheritance from fd_diagnostic
3589 to fd_param_diagnostic. Add new overloaded constructor.
3590 (fd_use_after_close): Likewise.
3591 (unchecked_use_of_fd): Likewise and also change name to fd_use_without_check.
3592 (double_close): Change name to fd_double_close.
3593 (enum access_directions): New.
3594 (fd_state_machine::on_stmt): Handle calls to function with the
3595 new three function attributes.
3596 (fd_state_machine::check_for_fd_attrs): New.
3597 (fd_state_machine::on_open): Use the new overloaded constructors
3598 of diagnostic classes.
3600 2022-07-22 David Malcolm <dmalcolm@redhat.com>
3603 * varargs.cc (region_model::impl_call_va_start): Avoid iterating
3604 through non-existant variadic arguments by initializing the
3605 impl_region to "UNKNOWN" if the va_start occurs in the top-level
3606 function to the analysis.
3608 2022-07-22 David Malcolm <dmalcolm@redhat.com>
3611 * store.cc (binding_cluster::binding_cluster): Remove overzealous
3612 assertion; we're checking for tracked_p in
3613 store::get_or_create_cluster.
3615 2022-07-22 Tim Lange <mail@tim-lange.me>
3618 * region-model.cc (capacity_compatible_with_type): Always return true
3619 if alloc_size is zero.
3621 2022-07-21 David Malcolm <dmalcolm@redhat.com>
3624 * varargs.cc (region_model::impl_call_va_arg): When determining if
3625 we're doing interprocedural analysis, use the stack depth of the
3626 frame in which va_start was called, rather than the current stack
3629 2022-07-21 David Malcolm <dmalcolm@redhat.com>
3631 * sm-taint.cc (tainted_array_index::emit): Bulletproof against
3633 (tainted_array_index::describe_final_event): Likewise.
3634 (tainted_size::emit): Likewise.
3635 (tainted_size::describe_final_event): Likewise.
3637 2022-07-21 David Malcolm <dmalcolm@redhat.com>
3640 * region.cc (decl_region::get_svalue_for_initializer): Bail out on
3643 2022-07-20 David Malcolm <dmalcolm@redhat.com>
3646 * sm-taint.cc (taint_state_machine::on_condition): Potentially
3647 update the state of the RHS as well as the LHS.
3649 2022-07-20 David Malcolm <dmalcolm@redhat.com>
3652 * region.h (string_region::tracked_p): New.
3653 * store.cc (binding_cluster::binding_cluster): Move here from
3654 store.h. Add assertion that base_region is tracked_p.
3655 * store.h (binding_cluster::binding_cluster): Move to store.cc.
3657 2022-07-19 David Malcolm <dmalcolm@redhat.com>
3660 * constraint-manager.h (bounded_ranges::get_count): New.
3661 (bounded_ranges::get_range): New.
3662 * engine.cc (impl_region_model_context::on_bounded_ranges): New.
3663 * exploded-graph.h (impl_region_model_context::on_bounded_ranges):
3665 * region-model.cc (region_model::apply_constraints_for_gswitch):
3666 Potentially call ctxt->on_bounded_ranges.
3667 * region-model.h (region_model_context::on_bounded_ranges): New
3669 (noop_region_model_context::on_bounded_ranges): New.
3670 (region_model_context_decorator::on_bounded_ranges): New.
3671 * sm-taint.cc: Include "analyzer/constraint-manager.h".
3672 (taint_state_machine::on_bounded_ranges): New.
3673 * sm.h (state_machine::on_bounded_ranges): New.
3675 2022-07-19 David Malcolm <dmalcolm@redhat.com>
3677 * engine.cc (exploded_graph::process_node): Show any description
3678 of the out-edge when logging it for consideration.
3680 2022-07-15 David Malcolm <dmalcolm@redhat.com>
3683 * sm-taint.cc (taint_state_machine::on_condition): Handle range
3684 checks optimized by build_range_check.
3686 2022-07-15 Jonathan Wakely <jwakely@redhat.com>
3688 * call-info.cc (call_info::print): Adjust to new label_text API.
3689 * checker-path.cc (checker_event::dump): Likewise.
3690 (region_creation_event::get_desc): Likewise.
3691 (state_change_event::get_desc): Likewise.
3692 (superedge_event::should_filter_p): Likewise.
3693 (start_cfg_edge_event::get_desc): Likewise.
3694 (call_event::get_desc): Likewise.
3695 (return_event::get_desc): Likewise.
3696 (warning_event::get_desc): Likewise.
3697 (checker_path::dump): Likewise.
3698 (checker_path::debug): Likewise.
3699 * diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic):
3701 (diagnostic_manager::prune_interproc_events): Likewise.
3702 * engine.cc (feasibility_state::maybe_update_for_edge):
3704 * program-state.cc (sm_state_map::to_json): Likewise.
3705 * region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise.
3706 (region_model::impl_call_analyzer_dump_capacity): Likewise.
3707 * region.cc (region::to_json): Likewise.
3708 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
3709 * store.cc (binding_map::to_json): Likewise.
3710 (store::to_json): Likewise.
3711 * supergraph.cc (superedge::dump): Likewise.
3712 * svalue.cc (svalue::to_json): Likewise.
3714 2022-07-07 David Malcolm <dmalcolm@redhat.com>
3716 * checker-path.cc (start_cfg_edge_event::get_desc): Update for
3717 superedge::get_description returning a label_text.
3718 * engine.cc (feasibility_state::maybe_update_for_edge): Likewise.
3719 * supergraph.cc (superedge::dump): Likewise.
3720 (superedge::get_description): Convert return type from char * to
3722 * supergraph.h (superedge::get_description): Likewise.
3724 2022-07-07 David Malcolm <dmalcolm@redhat.com>
3726 * call-info.cc (call_info::print): Update for removal of
3727 label_text::maybe_free in favor of automatic memory management.
3728 * checker-path.cc (checker_event::dump): Likewise.
3729 (checker_event::prepare_for_emission): Likewise.
3730 (state_change_event::get_desc): Likewise.
3731 (superedge_event::should_filter_p): Likewise.
3732 (start_cfg_edge_event::get_desc): Likewise.
3733 (warning_event::get_desc): Likewise.
3734 (checker_path::dump): Likewise.
3735 (checker_path::debug): Likewise.
3736 * diagnostic-manager.cc
3737 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
3738 (diagnostic_manager::prune_interproc_events): Likewise.
3739 * program-state.cc (sm_state_map::to_json): Likewise.
3740 * region.cc (region::to_json): Likewise.
3741 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
3742 * store.cc (binding_map::to_json): Likewise.
3743 (store::to_json): Likewise.
3744 * svalue.cc (svalue::to_json): Likewise.
3746 2022-07-07 David Malcolm <dmalcolm@redhat.com>
3749 * sm-taint.cc (taint_state_machine::on_stmt): Move handling of
3750 assignments from division to...
3751 (taint_state_machine::check_for_tainted_divisor): ...this new
3752 function. Reject warning when the divisor is known to be non-zero.
3753 * sm.cc: Include "analyzer/program-state.h".
3754 (sm_context::get_old_region_model): New.
3755 * sm.h (sm_context::get_old_region_model): New decl.
3757 2022-07-06 Immad Mir <mirimmad@outlook.com>
3760 * sm-fd.cc (fd_state_machine): Change ordering of initialization
3761 of state m_invalid so that the order of initializers is same as
3762 the ordering of the fields in the class decl.
3764 2022-07-06 Immad Mir <mirimmad@outlook.com>
3766 * sm-fd.cc (use_after_close): save the "close" event and
3767 show it where possible.
3769 2022-07-06 David Malcolm <dmalcolm@redhat.com>
3772 * region-model.cc (within_short_circuited_stmt_p): Move extraction
3773 of assign_stmt to caller.
3774 (due_to_ifn_deferred_init_p): New.
3775 (region_model::check_for_poison): Move extraction of assign_stmt
3776 from within_short_circuited_stmt_p to here. Share logic with
3777 call to due_to_ifn_deferred_init_p.
3779 2022-07-02 Tim Lange <mail@tim-lange.me>
3782 * analyzer.opt: Added Wanalyzer-allocation-size.
3783 * checker-path.cc (region_creation_event::get_desc): Added call to new
3784 virtual function pending_diagnostic::describe_region_creation_event.
3785 * checker-path.h: Added region_creation_event::get_desc.
3786 * diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
3788 * diagnostic-manager.h:
3789 Added diagnostic_manager::add_event_on_final_node.
3790 * pending-diagnostic.h (struct region_creation): New event_desc struct.
3791 (pending_diagnostic::describe_region_creation_event): Added virtual
3792 function to overwrite description of a region creation.
3793 * region-model.cc (class dubious_allocation_size): New class.
3794 (capacity_compatible_with_type): New helper function.
3795 (class size_visitor): New class.
3796 (struct_or_union_with_inheritance_p): New helper function.
3797 (is_any_cast_p): New helper function.
3798 (region_model::check_region_size): New function.
3799 (region_model::set_value): Added call to
3800 region_model::check_region_size.
3801 * region-model.h (class region_model): New function check_region_size.
3802 * svalue.cc (region_svalue::accept): Changed to post-order traversal.
3803 (initial_svalue::accept): Likewise.
3804 (unaryop_svalue::accept): Likewise.
3805 (binop_svalue::accept): Likewise.
3806 (sub_svalue::accept): Likewise.
3807 (repeated_svalue::accept): Likewise.
3808 (bits_within_svalue::accept): Likewise.
3809 (widening_svalue::accept): Likewise.
3810 (unmergeable_svalue::accept): Likewise.
3811 (compound_svalue::accept): Likewise.
3812 (conjured_svalue::accept): Likewise.
3813 (asm_output_svalue::accept): Likewise.
3814 (const_fn_result_svalue::accept): Likewise.
3816 2022-07-02 Immad Mir <mirimmad17@gmail.com>
3819 * analyzer.opt (Wanalyzer-fd-leak): New option.
3820 (Wanalyzer-fd-access-mode-mismatch): New option.
3821 (Wanalyzer-fd-use-without-check): New option.
3822 (Wanalyzer-fd-double-close): New option.
3823 (Wanalyzer-fd-use-after-close): New option.
3824 * sm.h (make_fd_state_machine): New decl.
3825 * sm.cc (make_checkers): Call make_fd_state_machine.
3826 * sm-fd.cc: New file.
3828 2022-06-24 David Malcolm <dmalcolm@redhat.com>
3830 * call-string.cc: Add includes of "analyzer/analyzer.h"
3831 and "analyzer/analyzer-logging.h".
3832 (call_string::call_string): Delete copy ctor.
3833 (call_string::operator=): Delete.
3834 (call_string::operator==): Delete.
3835 (call_string::hash): Delete.
3836 (call_string::push_call): Make const, returning the resulting
3838 (call_string::pop): Delete.
3839 (call_string::cmp_ptr_ptr): New.
3840 (call_string::validate): Assert that m_parent is non-NULL, or
3841 m_elements is empty.
3842 (call_string::call_string): Move default ctor here from
3843 call-string.h and reimplement. Add ctor taking a parent
3845 (call_string::~call_string): New.
3846 (call_string::recursive_log): New.
3847 * call-string.h (call_string::call_string): Move default ctor's
3848 defn to call-string.cc. Delete copy ctor. Add ctor taking a
3849 parent and an element.
3850 (call_string::operator=): Delete.
3851 (call_string::operator==): Delete.
3852 (call_string::hash): Delete.
3853 (call_string::push_call): Make const, returning the resulting
3855 (call_string::pop): Delete decl.
3856 (call_string::get_parent): New.
3857 (call_string::cmp_ptr_ptr): New decl.
3858 (call_string::get_top_of_stack): New.
3859 (struct call_string::hashmap_traits_t): New.
3860 (class call_string): Add friend class region_model_manager. Add
3861 DISABLE_COPY_AND_ASSIGN.
3862 (call_string::~call_string): New decl.
3863 (call_string::recursive_log): New decl.
3864 (call_string::m_parent): New field.
3865 (call_string::m_children): New field.
3866 * constraint-manager.cc (selftest::test_many_constants): Pass
3867 model manager to program_point::origin.
3868 * engine.cc (exploded_graph::exploded_graph): Likewise.
3869 (exploded_graph::add_function_entry): Likewise for
3870 program_point::from_function_entry.
3871 (add_tainted_args_callback): Likewise.
3872 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
3873 Update for change to program_point.get_call_string.
3874 (exploded_graph::process_node): Likewise.
3875 (class function_call_string_cluster): Convert m_cs from a
3876 call_string to a const call_string &.
3877 (struct function_call_string): Likewise.
3878 (pod_hash_traits<function_call_string>::hash): Use pointer_hash
3880 (pod_hash_traits<function_call_string>::equal): Update for change
3882 (root_cluster::add_node): Update for change to
3883 function_call_string.
3884 (viz_callgraph_node::dump_dot): Update for change to call_string.
3885 * exploded-graph.h (per_call_string_data::m_key): Convert to a
3887 (struct eg_call_string_hash_map_traits): Delete.
3888 (exploded_graph::call_string_data_map_t): Remove traits class.
3889 * program-point.cc: Move include of "analyzer/call-string.h" to
3890 after "analyzer/analyzer-logging.h".
3891 (program_point::print): Update for conversion of m_call_string to
3893 (program_point::to_json): Likewise.
3894 (program_point::push_to_call_stack): Update for immutability of
3896 (program_point::pop_from_call_stack): Likewise.
3897 (program_point::hash): Use pointer hashing for m_call_string.
3898 (program_point::get_function_at_depth): Update for change to
3900 (program_point::validate): Update for changes to call_string.
3901 (program_point::on_edge): Likewise.
3902 (program_point::origin): Move here from call-string.h. Add
3903 region_model_manager param and use it to get empty call string.
3904 (program_point::from_function_entry): Likewise.
3905 (selftest::test_function_point_ordering): Likewise.
3906 (selftest::test_function_point_ordering): Likewise.
3907 * program-point.h (program_point::program_point): Update for
3908 change to m_call_string.
3909 (program_point::get_call_string): Likewise.
3910 (program_point::get_stack_depth): Likewise.
3911 (program_point::origin): Add region_model_manager param, and move
3912 defn to call-string.cc.
3913 (program_point::from_function_entry): Likewise.
3914 (program_point::empty): Drop call_string.
3915 (program_point::deleted): Likewise.
3916 (program_point::program_point): New private ctor.
3917 (program_point::m_call_string): Convert from call_string to const
3919 * program-state.cc (selftest::test_program_state_merging): Update
3920 for call_string changes.
3921 (selftest::test_program_state_merging_2): Likewise.
3922 * region-model-manager.cc
3923 (region_model_manager::region_model_manager): Construct
3924 m_empty_call_string.
3925 (region_model_manager::log_stats): Log the call strings.
3926 * region-model.cc (assert_region_models_merge): Pass the
3927 region_model_manager when creating program_point instances.
3928 (selftest::test_state_merging): Likewise.
3929 (selftest::test_constraint_merging): Likewise.
3930 (selftest::test_widening_constraints): Likewise.
3931 (selftest::test_iteration_1): Likewise.
3932 * region-model.h (region_model_manager::get_empty_call_string):
3934 (region_model_manager::m_empty_call_string): New.
3935 * sm-signal.cc (register_signal_handler::impl_transition): Update
3936 for changes to call_string.
3938 2022-06-24 David Malcolm <dmalcolm@redhat.com>
3940 * call-string.cc (call_string::calc_recursion_depth): Whitespace
3942 (call_string::cmp): Likewise.
3943 (call_string::get_caller_node): Likewise.
3944 (call_string::validate): Likewise.
3945 * engine.cc (dynamic_call_info_t::add_events_to_path): Likewise.
3946 (exploded_graph::get_per_function_data): Likewise.
3947 (exploded_graph::maybe_create_dynamic_call): Likewise.
3948 (exploded_graph::maybe_create_dynamic_call): Likewise.
3949 (exploded_graph::process_node): Likewise.
3951 2022-06-16 David Malcolm <dmalcolm@redhat.com>
3953 * varargs.cc (va_arg_type_mismatch::emit): Associate the warning
3954 with CWE-686 ("Function Call With Incorrect Argument Type").
3956 2022-06-16 David Malcolm <dmalcolm@redhat.com>
3958 * varargs.cc: Include "diagnostic-metadata.h".
3959 (va_list_exhausted::emit): Associate the warning with
3960 CWE-685 ("Function Call With Incorrect Number of Arguments").
3962 2022-06-16 David Malcolm <dmalcolm@redhat.com>
3964 * sm-file.cc (double_fclose::emit): Associate the warning with
3965 CWE-1341 ("Multiple Releases of Same Resource or Handle").
3967 2022-06-15 David Malcolm <dmalcolm@redhat.com>
3970 * analyzer.opt (fanalyzer-undo-inlining): New option.
3971 * checker-path.cc: Include "diagnostic-core.h" and
3972 "inlining-iterator.h".
3973 (event_kind_to_string): Handle EK_INLINED_CALL.
3974 (class inlining_info): New class.
3975 (checker_event::checker_event): Move here from checker-path.h.
3976 Store original fndecl and depth, and calculate effective fndecl
3977 and depth based on inlining information.
3978 (checker_event::dump): Emit original depth as well as effective
3979 depth when they differ; likewise for fndecl.
3980 (region_creation_event::get_desc): Use m_effective_fndecl.
3981 (inlined_call_event::get_desc): New.
3982 (inlined_call_event::get_meaning): New.
3983 (checker_path::inject_any_inlined_call_events): New.
3984 * checker-path.h (enum event_kind): Add EK_INLINED_CALL.
3985 (checker_event::checker_event): Make protected, and move
3986 definition to checker-path.cc.
3987 (checker_event::get_fndecl): Use effective fndecl.
3988 (checker_event::get_stack_depth): Use effective stack depth.
3989 (checker_event::get_logical_location): Use effective stack depth.
3990 (checker_event::get_original_stack_depth): New.
3991 (checker_event::m_fndecl): Rename to...
3992 (checker_event::m_original_fndecl): ...this.
3993 (checker_event::m_depth): Rename to...
3994 (checker_event::m_original_depth): ...this.
3995 (checker_event::m_effective_fndecl): New field.
3996 (checker_event::m_effective_depth): New field.
3997 (class inlined_call_event): New checker_event subclass.
3998 (checker_path::inject_any_inlined_call_events): New decl.
3999 * diagnostic-manager.cc: Include "inlining-iterator.h".
4000 (diagnostic_manager::emit_saved_diagnostic): Call
4001 checker_path::inject_any_inlined_call_events.
4002 (diagnostic_manager::prune_for_sm_diagnostic): Handle
4004 * engine.cc (tainted_args_function_custom_event::get_desc): Use
4006 * inlining-iterator.h: New file.
4008 2022-06-15 David Malcolm <dmalcolm@redhat.com>
4010 * diagnostic-manager.cc (saved_diagnostic::dump_dot_id): New.
4011 (saved_diagnostic::dump_as_dot_node): New.
4012 * diagnostic-manager.h (saved_diagnostic::dump_dot_id): New decl.
4013 (saved_diagnostic::dump_as_dot_node): New decl.
4014 * engine.cc (exploded_node::dump_dot): Add nodes for saved
4017 2022-06-02 David Malcolm <dmalcolm@redhat.com>
4019 * checker-path.cc (checker_event::get_meaning): New.
4020 (function_entry_event::get_meaning): New.
4021 (state_change_event::get_desc): Add dump of meaning of the event
4022 to the -fanalyzer-verbose-state-changes output.
4023 (state_change_event::get_meaning): New.
4024 (cfg_edge_event::get_meaning): New.
4025 (call_event::get_meaning): New.
4026 (return_event::get_meaning): New.
4027 (start_consolidated_cfg_edges_event::get_meaning): New.
4028 (warning_event::get_meaning): New.
4029 * checker-path.h: Include "tree-logical-location.h".
4030 (checker_event::checker_event): Construct m_logical_loc.
4031 (checker_event::get_logical_location): New.
4032 (checker_event::get_meaning): New decl.
4033 (checker_event::m_logical_loc): New.
4034 (function_entry_event::get_meaning): New decl.
4035 (state_change_event::get_meaning): New decl.
4036 (cfg_edge_event::get_meaning): New decl.
4037 (call_event::get_meaning): New decl.
4038 (return_event::get_meaning): New decl.
4039 (start_consolidated_cfg_edges_event::get_meaning): New.
4040 (warning_event::get_meaning): New decl.
4041 * pending-diagnostic.h: Include "diagnostic-path.h".
4042 (pending_diagnostic::get_meaning_for_state_change): New vfunc.
4043 * sm-file.cc (file_diagnostic::get_meaning_for_state_change): New
4045 * sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
4048 (exposure_through_output_file::get_meaning_for_state_change):
4050 * sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
4053 (va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.
4055 2022-05-23 David Malcolm <dmalcolm@redhat.com>
4057 * call-info.cc: Add "final" and "override" to all vfunc
4058 implementations that were missing them, as appropriate.
4059 * engine.cc: Likewise.
4060 * region-model.cc: Likewise.
4061 * sm-malloc.cc: Likewise.
4062 * supergraph.h: Likewise.
4063 * svalue.cc: Likewise.
4064 * varargs.cc: Likewise.
4066 2022-05-20 David Malcolm <dmalcolm@redhat.com>
4068 * analyzer-pass.cc: Replace uses of "FINAL" and "OVERRIDE" with
4069 "final" and "override".
4070 * call-info.h: Likewise.
4071 * checker-path.h: Likewise.
4072 * constraint-manager.cc: Likewise.
4073 * diagnostic-manager.cc: Likewise.
4074 * engine.cc: Likewise.
4075 * exploded-graph.h: Likewise.
4076 * feasible-graph.h: Likewise.
4077 * pending-diagnostic.h: Likewise.
4078 * region-model-impl-calls.cc: Likewise.
4079 * region-model.cc: Likewise.
4080 * region-model.h: Likewise.
4081 * region.h: Likewise.
4082 * sm-file.cc: Likewise.
4083 * sm-malloc.cc: Likewise.
4084 * sm-pattern-test.cc: Likewise.
4085 * sm-sensitive.cc: Likewise.
4086 * sm-signal.cc: Likewise.
4087 * sm-taint.cc: Likewise.
4088 * state-purge.h: Likewise.
4089 * store.cc: Likewise.
4090 * store.h: Likewise.
4091 * supergraph.h: Likewise.
4092 * svalue.h: Likewise.
4093 * trimmed-graph.h: Likewise.
4094 * varargs.cc: Likewise.
4096 2022-05-16 David Malcolm <dmalcolm@redhat.com>
4099 * analyzer.cc (make_label_text_n): New.
4100 * analyzer.h (class var_arg_region): New forward decl.
4101 (make_label_text_n): New decl.
4102 * analyzer.opt (Wanalyzer-va-arg-type-mismatch): New option.
4103 (Wanalyzer-va-list-exhausted): New option.
4104 (Wanalyzer-va-list-leak): New option.
4105 (Wanalyzer-va-list-use-after-va-end): New option.
4106 * checker-path.cc (call_event::get_desc): Split out decl access
4108 (call_event::get_caller_fndecl): ...this new function and...
4109 (call_event::get_callee_fndecl): ...this new function.
4110 * checker-path.h (call_event::get_desc): Drop "FINAL".
4111 (call_event::get_caller_fndecl): New decl.
4112 (call_event::get_callee_fndecl): New decl.
4113 (class call_event): Make fields protected.
4114 * diagnostic-manager.cc (null_assignment_sm_context::warn): New
4116 (null_assignment_sm_context::get_new_program_state): New.
4117 (diagnostic_manager::add_events_for_superedge): Move case
4118 SUPEREDGE_CALL to a new pending_diagnostic::add_call_event vfunc.
4119 * engine.cc (impl_sm_context::warn): Implement new override.
4120 (impl_sm_context::get_new_program_state): New.
4121 * pending-diagnostic.cc: Include "analyzer/diagnostic-manager.h",
4122 "cpplib.h", "digraph.h", "ordered-hash-map.h", "cfg.h",
4123 "basic-block.h", "gimple.h", "gimple-iterator.h", "cgraph.h"
4124 "analyzer/supergraph.h", "analyzer/program-state.h",
4125 "alloc-pool.h", "fibonacci_heap.h", "shortest-paths.h",
4126 "sbitmap.h", "analyzer/exploded-graph.h", "diagnostic-path.h",
4127 and "analyzer/checker-path.h".
4129 (fixup_location_in_macro_p): New.
4130 (pending_diagnostic::fixup_location): New.
4131 (pending_diagnostic::add_call_event): New.
4132 * pending-diagnostic.h (pending_diagnostic::fixup_location): Drop
4133 no-op inline implementation in favor of the more complex
4134 implementation above.
4135 (pending_diagnostic::add_call_event): New vfunc.
4136 * region-model-impl-calls.cc: Include "analyzer/sm.h",
4137 "diagnostic-path.h", and "analyzer/pending-diagnostic.h".
4138 * region-model-manager.cc
4139 (region_model_manager::get_var_arg_region): New.
4140 (region_model_manager::log_stats): Log m_var_arg_regions.
4141 * region-model.cc (region_model::on_call_pre): Handle IFN_VA_ARG,
4142 BUILT_IN_VA_START, and BUILT_IN_VA_COPY.
4143 (region_model::on_call_post): Handle BUILT_IN_VA_END.
4144 (region_model::get_representative_path_var_1): Handle RK_VAR_ARG.
4145 (region_model::push_frame): Push variadic arguments.
4146 * region-model.h (region_model_manager::get_var_arg_region): New
4148 (region_model_manager::m_var_arg_regions): New field.
4149 (region_model::impl_call_va_start): New decl.
4150 (region_model::impl_call_va_copy): New decl.
4151 (region_model::impl_call_va_arg): New decl.
4152 (region_model::impl_call_va_end): New decl.
4153 * region.cc (alloca_region::dump_to_pp): Dump the id.
4154 (var_arg_region::dump_to_pp): New.
4155 (var_arg_region::get_frame_region): New.
4156 * region.h (enum region_kind): Add RK_VAR_ARG.
4157 (region::dyn_cast_var_arg_region): New.
4158 (class var_arg_region): New.
4159 (is_a_helper <const var_arg_region *>::test): New.
4160 (struct default_hash_traits<var_arg_region::key_t>): New.
4161 * sm.cc (make_checkers): Call make_va_list_state_machine.
4162 * sm.h (sm_context::warn): New vfunc.
4163 (sm_context::get_old_svalue): Drop unused decl.
4164 (sm_context::get_new_program_state): New vfunc.
4165 (make_va_list_state_machine): New decl.
4166 * varargs.cc: New file.
4168 2022-05-16 Martin Liska <mliska@suse.cz>
4170 * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
4171 * function-set.cc (test_stdio_example): Likewise.
4172 * sm-file.cc (get_file_using_fns): Likewise.
4173 * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
4174 * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
4176 2022-05-13 Richard Biener <rguenther@suse.de>
4178 * supergraph.cc: Re-order gimple-fold.h include.
4180 2022-05-11 David Malcolm <dmalcolm@redhat.com>
4182 * checker-path.cc (state_change_event::get_desc): Call maybe_free
4183 on label_text temporaries.
4184 * diagnostic-manager.cc
4185 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
4186 * engine.cc (exploded_graph::~exploded_graph): Fix leak of
4187 m_per_point_data and m_per_call_string_data values. Simplify
4188 cleanup of m_per_function_stats and m_per_point_data values.
4189 (feasibility_state::maybe_update_for_edge): Fix leak of result of
4190 superedge::get_description.
4191 * region-model-manager.cc
4192 (region_model_manager::~region_model_manager): Move cleanup of
4193 m_setjmp_values to match the ordering of the fields within
4194 region_model_manager. Fix leak of values within
4195 m_repeated_values_map, m_bits_within_values_map,
4196 m_asm_output_values_map, and m_const_fn_result_values_map.
4198 2022-04-28 David Malcolm <dmalcolm@redhat.com>
4201 * store.cc (binding_cluster::get_any_binding): Handle accessing
4202 sub_svalues of clusters where the base region has a symbolic
4205 2022-04-28 David Malcolm <dmalcolm@redhat.com>
4207 * diagnostic-manager.cc (epath_finder::process_worklist_item):
4208 Call dump_feasible_path when a path that reaches the the target
4210 (epath_finder::dump_feasible_path): New.
4211 * engine.cc (feasibility_state::dump_to_pp): New.
4212 * exploded-graph.h (feasibility_state::dump_to_pp): New decl.
4213 * feasible-graph.cc (feasible_graph::dump_feasible_path): New.
4214 * feasible-graph.h (feasible_graph::dump_feasible_path): New
4216 * program-point.cc (function_point::print): Fix missing trailing
4218 * program-point.h (program_point::print_source_line): Remove
4221 2022-04-25 David Malcolm <dmalcolm@redhat.com>
4226 (cmp_cst): Rename to...
4227 (cmp_csts_same_type): ...this. Convert all recursive calls to
4229 (cmp_csts_and_types): ....this new function.
4230 (svalue::cmp_ptr): Update for renaming of cmp_cst
4232 2022-04-14 David Malcolm <dmalcolm@redhat.com>
4235 * region-model-reachability.cc (reachable_regions::handle_parm):
4236 Use maybe_get_deref_base_region rather than just region_svalue, to
4237 handle pointer arithmetic also.
4238 * svalue.cc (svalue::maybe_get_deref_base_region): New.
4239 * svalue.h (svalue::maybe_get_deref_base_region): New decl.
4241 2022-04-14 David Malcolm <dmalcolm@redhat.com>
4244 * svalue.cc (cmp_cst): When comparing VECTOR_CSTs, compare the
4245 types of the encoded elements before calling cmp_cst on them.
4247 2022-04-09 David Malcolm <dmalcolm@redhat.com>
4250 * region-model-manager.cc
4251 (region_model_manager::get_unknown_symbolic_region): New,
4253 (region_model_manager::get_field_region): ...here.
4254 (region_model_manager::get_element_region): Use it here.
4255 (region_model_manager::get_offset_region): Likewise.
4256 (region_model_manager::get_sized_region): Likewise.
4257 (region_model_manager::get_cast_region): Likewise.
4258 (region_model_manager::get_bit_range): Likewise.
4260 (region_model_manager::get_unknown_symbolic_region): New decl.
4261 * region.cc (symbolic_region::symbolic_region): Handle sval_ptr
4263 (symbolic_region::dump_to_pp): Handle having NULL type.
4265 2022-04-07 David Malcolm <dmalcolm@redhat.com>
4268 * store.cc (binding_map::remove_overlapping_bindings): Add
4269 "always_overlap" param, using it to generalize to the case where
4270 we want to remove all bindings. Update "uncertainty" logic to
4271 only record maybe-bound values for cases where there is a symbolic
4273 (binding_cluster::mark_region_as_unknown): Split param "reg" into
4274 "reg_to_bind" and "reg_for_overlap".
4275 (binding_cluster::maybe_get_compound_binding): Pass "false" to
4276 binding_map::remove_overlapping_bindings new "always_overlap" param.
4277 (binding_cluster::remove_overlapping_bindings): Determine
4278 "always_overlap" and pass it to
4279 binding_map::remove_overlapping_bindings.
4280 (store::set_value): Pass uncertainty to remove_overlapping_bindings
4281 call. Update for new param of
4282 binding_cluster::mark_region_as_unknown, passing both the base
4283 region of the iter_cluster, and the lhs_reg.
4284 (store::mark_region_as_unknown): Update for new param of
4285 binding_cluster::mark_region_as_unknown, passing "reg" for both.
4286 (store::remove_overlapping_bindings): Add param "uncertainty", and
4287 pass it on to call to
4288 binding_cluster::remove_overlapping_bindings.
4289 * store.h (binding_map::remove_overlapping_bindings): Add
4290 "always_overlap" param.
4291 (binding_cluster::mark_region_as_unknown): Split param "reg" into
4292 "reg_to_bind" and "reg_for_overlap".
4293 (store::remove_overlapping_bindings): Add param "uncertainty".
4295 2022-03-29 David Malcolm <dmalcolm@redhat.com>
4298 * region-model-manager.cc (dump_untracked_region): Skip decls in
4301 2022-03-29 David Malcolm <dmalcolm@redhat.com>
4304 * analyzer.h (class conjured_purge): New forward decl.
4305 * region-model-asm.cc (region_model::on_asm_stmt): Add
4306 conjured_purge param to calls binding_cluster::on_asm and
4307 region_model_manager::get_or_create_conjured_svalue.
4308 * region-model-impl-calls.cc
4309 (call_details::get_or_create_conjured_svalue): Likewise for call
4310 to region_model_manager::get_or_create_conjured_svalue.
4311 (region_model::impl_call_fgets): Remove call to
4312 region_model::purge_state_involving, as this is now done
4313 implicitly by call_details::get_or_create_conjured_svalue.
4314 (region_model::impl_call_fread): Likewise.
4315 (region_model::impl_call_strchr): Pass conjured_purge param to
4316 call to region_model_manager::get_or_create_conjured_svalue.
4317 * region-model-manager.cc (conjured_purge::purge): New.
4318 (region_model_manager::get_or_create_conjured_svalue): Add
4319 param "p". Use it to purge state when reusing an existing
4321 * region-model.cc (region_model::on_call_pre): Replace call to
4322 region_model::purge_state_involving with passing conjured_purge
4323 to region_model_manager::get_or_create_conjured_svalue.
4324 (region_model::handle_unrecognized_call): Pass conjured_purge to
4325 store::on_unknown_fncall.
4327 (region_model_manager::get_or_create_conjured_svalue): Add param
4329 * store.cc (binding_cluster::on_unknown_fncall): Likewise. Pass
4330 it on to region_model_manager::get_or_create_conjured_svalue.
4331 (binding_cluster::on_asm): Likewise.
4332 (store::on_unknown_fncall): Add param "p" and pass it on to
4333 binding_cluster::on_unknown_fncall.
4334 * store.h (binding_cluster::on_unknown_fncall): Add param p.
4335 (binding_cluster::on_asm): Likewise.
4336 (store::on_unknown_fncall): Likewise.
4337 * svalue.h (class conjured_purge): New.
4339 2022-03-29 David Malcolm <dmalcolm@redhat.com>
4342 * region.cc (ipa_ref_requires_tracking): Drop "context_fndecl",
4343 instead using the ref->referring to get the cgraph node of the
4345 (symnode_requires_tracking_p): Likewise.
4347 2022-03-26 David Malcolm <dmalcolm@redhat.com>
4350 * store.cc (binding_cluster::make_unknown_relative_to): Reject
4351 attempts to create a cluster for untracked base regions.
4352 (store::set_value): Likewise.
4353 (store::fill_region): Likewise.
4354 (store::mark_region_as_unknown): Likewise.
4356 2022-03-25 David Malcolm <dmalcolm@redhat.com>
4359 * analyzer.opt (-fdump-analyzer-untracked): New option.
4360 * engine.cc (impl_run_checkers): Handle it.
4361 * region-model-asm.cc (region_model::on_asm_stmt): Don't attempt
4362 to clobber regions with !tracked_p ().
4363 * region-model-manager.cc (dump_untracked_region): New.
4364 (region_model_manager::dump_untracked_regions): New.
4365 (frame_region::dump_untracked_regions): New.
4366 * region-model.h (region_model_manager::dump_untracked_regions):
4368 * region.cc (ipa_ref_requires_tracking): New.
4369 (symnode_requires_tracking_p): New.
4370 (decl_region::calc_tracked_p): New.
4371 * region.h (region::tracked_p): New vfunc.
4372 (frame_region::dump_untracked_regions): New decl.
4373 (class decl_region): Note that this is also used fo SSA names.
4374 (decl_region::decl_region): Initialize m_tracked.
4375 (decl_region::tracked_p): New.
4376 (decl_region::calc_tracked_p): New decl.
4377 (decl_region::m_tracked): New.
4378 * store.cc (store::get_or_create_cluster): Assert that we
4379 don't try to create clusters for base regions that aren't
4381 (store::mark_as_escaped): Don't mark base regions that we're not
4384 2022-03-23 David Malcolm <dmalcolm@redhat.com>
4387 * engine.cc (impl_run_checkers): Create the engine after the
4388 supergraph, and pass the supergraph to the engine.
4389 * region-model.cc (region_model::get_lvalue_1): Pass ctxt to
4390 frame_region::get_region_for_local.
4391 (region_model::update_for_return_gcall): Pass the lvalue for the
4392 result to pop_frame as a tree, rather than as a region.
4393 (region_model::pop_frame): Update for above change, determining
4394 the destination region after the frame is popped and thus with
4395 respect to the caller frame rather than the called frame.
4396 Likewise, set the value of the region to the return value after
4397 the frame is popped.
4398 (engine::engine): Add supergraph pointer.
4399 (selftest::test_stack_frames): Set the DECL_CONTECT of PARM_DECLs.
4400 (selftest::test_get_representative_path_var): Likewise.
4401 (selftest::test_state_merging): Likewise.
4402 * region-model.h (region_model::pop_frame): Convert first param
4403 from a const region * to a tree.
4404 (engine::engine): Add param "sg".
4405 (engine::m_sg): New field.
4406 * region.cc: Include "analyzer/sm.h" and
4407 "analyzer/program-state.h".
4408 (frame_region::get_region_for_local): Add "ctxt" param.
4409 Add assertions that VAR_DECLs are locals, and that expr is for the
4411 * region.h (frame_region::get_region_for_local): Add "ctxt" param.
4413 2022-03-23 David Malcolm <dmalcolm@redhat.com>
4416 * sm-taint.cc (taint_diagnostic::subclass_equal_p): Check
4417 m_has_bounds as well as m_arg.
4418 (tainted_allocation_size::subclass_equal_p): Chain up to base
4419 class implementation. Also check m_mem_space.
4420 (tainted_allocation_size::emit): Add note showing stack-based vs
4421 heap-based allocations.
4423 2022-03-23 David Malcolm <dmalcolm@redhat.com>
4426 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic):
4427 Convert return type from "void" to "bool", reporting success vs
4428 failure to caller, for both overloads.
4429 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
4431 * engine.cc (impl_region_model_context::warn): Propagate return
4432 value from diagnostic_manager::add_diagnostic.
4434 2022-03-18 David Malcolm <dmalcolm@redhat.com>
4439 * analyzer.h (class state_purge_per_decl): New forward decl.
4440 * engine.cc (impl_run_checkers): Pass region_model_manager to
4441 state_purge_map ctor.
4442 * program-point.cc (function_point::final_stmt_p): New.
4443 (function_point::get_next): New.
4444 * program-point.h (function_point::final_stmt_p): New decl.
4445 (function_point::get_next): New decl.
4446 * program-state.cc (program_state::prune_for_point): Generalize to
4447 purge local decls as well as SSA names.
4448 (program_state::can_purge_base_region_p): New.
4449 * program-state.h (program_state::can_purge_base_region_p): New
4451 * region-model.cc (struct append_ssa_names_cb_data): Rename to...
4452 (struct append_regions_cb_data): ...this.
4453 (region_model::get_ssa_name_regions_for_current_frame): Rename
4455 (region_model::get_regions_for_current_frame): ...this, updating
4456 for other renamings.
4457 (region_model::append_ssa_names_cb): Rename to...
4458 (region_model::append_regions_cb): ...this, and drop the requirement
4459 that the subregion be a SSA name.
4460 * region-model.h (struct append_ssa_names_cb_data): Rename decl
4462 (struct append_regions_cb_data): ...this.
4463 (region_model::get_ssa_name_regions_for_current_frame): Rename
4465 (region_model::get_regions_for_current_frame): ...this.
4466 (region_model::append_ssa_names_cb): Rename decl to...
4467 (region_model::append_regions_cb): ...this.
4468 * state-purge.cc: Include "tristate.h", "selftest.h",
4469 "analyzer/store.h", "analyzer/region-model.h", and
4471 (get_candidate_for_purging): New.
4472 (class gimple_op_visitor): New.
4476 (state_purge_map::state_purge_map): Add "mgr" param. Update for
4477 renamings. Find uses of local variables.
4478 (state_purge_map::~state_purge_map): Update for renaming of m_map
4479 to m_ssa_map. Clean up m_decl_map.
4480 (state_purge_map::get_or_create_data_for_decl): New.
4481 (state_purge_per_ssa_name::state_purge_per_ssa_name): Update for
4482 inheriting from state_purge_per_tree.
4483 (state_purge_per_ssa_name::add_to_worklist): Likewise.
4484 (state_purge_per_decl::state_purge_per_decl): New.
4485 (state_purge_per_decl::add_needed_at): New.
4486 (state_purge_per_decl::add_pointed_to_at): New.
4487 (state_purge_per_decl::process_worklists): New.
4488 (state_purge_per_decl::add_to_worklist): New.
4489 (same_binding_p): New.
4490 (fully_overwrites_p): New.
4491 (state_purge_per_decl::process_point_backwards): New.
4492 (state_purge_per_decl::process_point_forwards): New.
4493 (state_purge_per_decl::needed_at_point_p): New.
4494 (state_purge_annotator::print_needed): Generalize to print local
4495 decls as well as SSA names.
4496 * state-purge.h (class state_purge_map): Update leading comment.
4497 (state_purge_map::map_t): Rename to...
4498 (state_purge_map::ssa_map_t): ...this.
4499 (state_purge_map::iterator): Rename to...
4500 (state_purge_map::ssa_iterator): ...this.
4501 (state_purge_map::decl_map_t): New typedef.
4502 (state_purge_map::decl_iterator): New typedef.
4503 (state_purge_map::state_purge_map): Add "mgr" param.
4504 (state_purge_map::get_data_for_ssa_name): Update for renaming.
4505 (state_purge_map::get_any_data_for_decl): New.
4506 (state_purge_map::get_or_create_data_for_decl): New decl.
4507 (state_purge_map::begin): Rename to...
4508 (state_purge_map::begin_ssas): ...this.
4509 (state_purge_map::end): Rename to...
4510 (state_purge_map::end_ssa): ...this.
4511 (state_purge_map::begin_decls): New.
4512 (state_purge_map::end_decls): New.
4513 (state_purge_map::m_map): Rename to...
4514 (state_purge_map::m_ssa_map): ...this.
4515 (state_purge_map::m_decl_map): New field.
4516 (class state_purge_per_tree): New class.
4517 (class state_purge_per_ssa_name): Inherit from state_purge_per_tree.
4518 (state_purge_per_ssa_name::get_function): Move to base class.
4519 (state_purge_per_ssa_name::point_set_t): Likewise.
4520 (state_purge_per_ssa_name::m_fun): Likewise.
4521 (class state_purge_per_decl): New.
4523 2022-03-17 David Malcolm <dmalcolm@redhat.com>
4525 * state-purge.cc (state_purge_annotator::add_node_annotations):
4526 Avoid duplicate before-supernode annotations when returning from
4527 an interprocedural call. Show after-supernode annotations.
4529 2022-03-17 David Malcolm <dmalcolm@redhat.com>
4531 * program-point.cc (program_point::get_next): Fix missing
4534 2022-03-16 David Malcolm <dmalcolm@redhat.com>
4537 * diagnostic-manager.cc (get_emission_location): New.
4538 (diagnostic_manager::diagnostic_manager): Initialize
4539 m_num_disabled_diagnostics.
4540 (diagnostic_manager::add_diagnostic): Reject diagnostics that
4541 will eventually be rejected due to being disabled.
4542 (diagnostic_manager::emit_saved_diagnostics): Log the number
4543 of disabled diagnostics.
4544 (diagnostic_manager::emit_saved_diagnostic): Split out logic for
4545 determining emission location to get_emission_location.
4546 * diagnostic-manager.h
4547 (diagnostic_manager::m_num_disabled_diagnostics): New field.
4548 * engine.cc (stale_jmp_buf::get_controlling_option): New.
4549 (stale_jmp_buf::emit): Use it.
4550 * pending-diagnostic.h
4551 (pending_diagnostic::get_controlling_option): New vfunc.
4553 (poisoned_value_diagnostic::get_controlling_option): New.
4554 (poisoned_value_diagnostic::emit): Use it.
4555 (shift_count_negative_diagnostic::get_controlling_option): New.
4556 (shift_count_negative_diagnostic::emit): Use it.
4557 (shift_count_overflow_diagnostic::get_controlling_option): New.
4558 (shift_count_overflow_diagnostic::emit): Use it.
4559 (dump_path_diagnostic::get_controlling_option): New.
4560 (dump_path_diagnostic::emit): Use it.
4561 (write_to_const_diagnostic::get_controlling_option): New.
4562 (write_to_const_diagnostic::emit): Use it.
4563 (write_to_string_literal_diagnostic::get_controlling_option): New.
4564 (write_to_string_literal_diagnostic::emit): Use it.
4565 * sm-file.cc (double_fclose::get_controlling_option): New.
4566 (double_fclose::emit): Use it.
4567 (file_leak::get_controlling_option): New.
4568 (file_leak::emit): Use it.
4569 * sm-malloc.cc (mismatching_deallocation::get_controlling_option):
4571 (mismatching_deallocation::emit): Use it.
4572 (double_free::get_controlling_option): New.
4573 (double_free::emit): Use it.
4574 (possible_null_deref::get_controlling_option): New.
4575 (possible_null_deref::emit): Use it.
4576 (possible_null_arg::get_controlling_option): New.
4577 (possible_null_arg::emit): Use it.
4578 (null_deref::get_controlling_option): New.
4579 (null_deref::emit): Use it.
4580 (null_arg::get_controlling_option): New.
4581 (null_arg::emit): Use it.
4582 (use_after_free::get_controlling_option): New.
4583 (use_after_free::emit): Use it.
4584 (malloc_leak::get_controlling_option): New.
4585 (malloc_leak::emit): Use it.
4586 (free_of_non_heap::get_controlling_option): New.
4587 (free_of_non_heap::emit): Use it.
4588 * sm-pattern-test.cc (pattern_match::get_controlling_option): New.
4589 (pattern_match::emit): Use it.
4591 (exposure_through_output_file::get_controlling_option): New.
4592 (exposure_through_output_file::emit): Use it.
4593 * sm-signal.cc (signal_unsafe_call::get_controlling_option): New.
4594 (signal_unsafe_call::emit): Use it.
4595 * sm-taint.cc (tainted_array_index::get_controlling_option): New.
4596 (tainted_array_index::emit): Use it.
4597 (tainted_offset::get_controlling_option): New.
4598 (tainted_offset::emit): Use it.
4599 (tainted_size::get_controlling_option): New.
4600 (tainted_size::emit): Use it.
4601 (tainted_divisor::get_controlling_option): New.
4602 (tainted_divisor::emit): Use it.
4603 (tainted_allocation_size::get_controlling_option): New.
4604 (tainted_allocation_size::emit): Use it.
4606 2022-03-15 David Malcolm <dmalcolm@redhat.com>
4608 * store.cc (store::store): Presize m_cluster_map.
4610 2022-03-10 David Malcolm <dmalcolm@redhat.com>
4613 * constraint-manager.cc (constraint_manager::add_constraint):
4614 Refresh the EC IDs when adding constraints implied by offsets.
4616 2022-03-10 David Malcolm <dmalcolm@redhat.com>
4619 * analyzer.h (class pending_note): New forward decl.
4620 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
4622 (saved_diagnostic::operator==): Compare m_notes.
4623 (saved_diagnostic::add_note): New.
4624 (saved_diagnostic::emit_any_notes): New.
4625 (diagnostic_manager::add_note): New.
4626 (diagnostic_manager::emit_saved_diagnostic): Call emit_any_notes
4627 after emitting the warning.
4628 * diagnostic-manager.h (saved_diagnostic::add_note): New decl.
4629 (saved_diagnostic::emit_any_notes): New decl.
4630 (saved_diagnostic::m_notes): New field.
4631 (diagnostic_manager::add_note): New decl.
4632 * engine.cc (impl_region_model_context::add_note): New.
4633 * exploded-graph.h (impl_region_model_context::add_note): New
4635 * pending-diagnostic.h (class pending_note): New.
4636 (class pending_note_subclass): New template.
4637 * region-model.cc (class reason_attr_access): New.
4638 (check_external_function_for_access_attr): Add class
4639 annotating_ctxt and use it when checking region.
4640 (noop_region_model_context::add_note): New.
4641 * region-model.h (region_model_context::add_note): New vfunc.
4642 (noop_region_model_context::add_note): New decl.
4643 (class region_model_context_decorator): New.
4644 (class note_adding_context): New.
4646 2022-03-10 David Malcolm <dmalcolm@redhat.com>
4650 (region_model::check_external_function_for_access_attr): New.
4651 (region_model::handle_unrecognized_call): Call it.
4653 (region_model::check_external_function_for_access_attr): New decl.
4654 (region_model::handle_unrecognized_call): New decl.
4656 2022-03-10 David Malcolm <dmalcolm@redhat.com>
4658 * sm-taint.cc (taint_state_machine::check_for_tainted_size_arg):
4659 Avoid generating duplicate saved_diagnostics by only handling the
4660 rdwr_map entry for the ptrarg, not the duplicate entry for the
4663 2022-03-07 David Malcolm <dmalcolm@redhat.com>
4666 * engine.cc (returning_from_function_p): New.
4667 (impl_region_model_context::on_state_leak): Use it when rejecting
4668 leaks at the return from "main".
4670 2022-03-07 Jakub Jelinek <jakub@redhat.com>
4672 * store.cc: Fix up duplicated word issue in a comment.
4673 * analyzer.cc: Likewise.
4674 * engine.cc: Likewise.
4675 * sm-taint.cc: Likewise.
4677 2022-03-04 David Malcolm <dmalcolm@redhat.com>
4680 * analyzer.opt (-param=analyzer-max-svalue-depth=): Reduce from 13
4683 2022-02-23 David Malcolm <dmalcolm@redhat.com>
4686 * analyzer.h (class const_fn_result_svalue): New decl.
4687 * region-model-impl-calls.cc (call_details::get_manager): New.
4688 * region-model-manager.cc
4689 (region_model_manager::get_or_create_const_fn_result_svalue): New.
4690 (region_model_manager::log_stats): Log
4691 m_const_fn_result_values_map.
4692 * region-model.cc (const_fn_p): New.
4693 (maybe_get_const_fn_result): New.
4694 (region_model::on_call_pre): Handle fndecls with
4695 __attribute__((const)) by calling the above rather than making
4697 * region-model.h (visitor::visit_const_fn_result_svalue): New.
4698 (region_model_manager::get_or_create_const_fn_result_svalue): New
4700 (region_model_manager::const_fn_result_values_map_t): New typedef.
4701 (region_model_manager::m_const_fn_result_values_map): New field.
4702 (call_details::get_manager): New decl.
4703 * svalue.cc (svalue::cmp_ptr): Handle SK_CONST_FN_RESULT.
4704 (const_fn_result_svalue::dump_to_pp): New.
4705 (const_fn_result_svalue::dump_input): New.
4706 (const_fn_result_svalue::accept): New.
4707 * svalue.h (enum svalue_kind): Add SK_CONST_FN_RESULT.
4708 (svalue::dyn_cast_const_fn_result_svalue): New.
4709 (class const_fn_result_svalue): New.
4710 (is_a_helper <const const_fn_result_svalue *>::test): New.
4711 (template <> struct default_hash_traits<const_fn_result_svalue::key_t>):
4714 2022-02-17 David Malcolm <dmalcolm@redhat.com>
4717 * region-model.cc: Include "calls.h".
4718 (region_model::on_call_pre): Use flags_from_decl_or_type to
4719 generalize check for DECL_PURE_P to also check for ECF_CONST.
4721 2022-02-16 David Malcolm <dmalcolm@redhat.com>
4724 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
4725 Add region creation events for globals of interest.
4726 (null_assignment_sm_context::get_old_program_state): New.
4727 (diagnostic_manager::add_events_for_eedge): Move check for
4728 changing dynamic extents from PK_BEFORE_STMT case to after the
4729 switch on the dst_point's kind so that we can emit them for the
4730 final stmt in a basic block.
4731 * engine.cc (impl_sm_context::get_old_program_state): New.
4732 * sm-malloc.cc (malloc_state_machine::get_default_state): Rewrite
4733 detection of m_non_heap to use get_memory_space.
4734 (free_of_non_heap::free_of_non_heap): Add freed_reg param.
4735 (free_of_non_heap::subclass_equal_p): Update for changes to
4737 (free_of_non_heap::emit): Drop m_kind in favor of
4739 (free_of_non_heap::describe_state_change): Remove logic for
4741 (free_of_non_heap::mark_interesting_stuff): Add region-creation of
4743 (free_of_non_heap::get_memory_space): New.
4744 (free_of_non_heap::kind): Drop enum.
4745 (free_of_non_heap::m_freed_reg): New field.
4746 (free_of_non_heap::m_kind): Drop field.
4747 (malloc_state_machine::on_stmt): Drop transition to m_non_heap.
4748 (malloc_state_machine::handle_free_of_non_heap): New function,
4749 split out from on_deallocator_call and on_realloc_call, adding
4750 detection of the freed region.
4751 (malloc_state_machine::on_deallocator_call): Use it.
4752 (malloc_state_machine::on_realloc_call): Likewise.
4753 * sm.h (sm_context::get_old_program_state): New vfunc.
4755 2022-02-15 David Malcolm <dmalcolm@redhat.com>
4758 * region-model-manager.cc
4759 (region_model_manager::maybe_fold_sub_svalue): Only call
4760 get_or_create_cast if type is non-NULL.
4762 2022-02-15 David Malcolm <dmalcolm@redhat.com>
4765 * exploded-graph.h (impl_region_model_context::get_stmt): New.
4766 * region-model.cc: Include "gimple-ssa.h", "tree-phinodes.h",
4767 "tree-ssa-operands.h", and "ssa-iterators.h".
4768 (within_short_circuited_stmt_p): New.
4769 (region_model::check_for_poison): Don't warn about uninit values
4770 if within_short_circuited_stmt_p.
4771 * region-model.h (region_model_context::get_stmt): New vfunc.
4772 (noop_region_model_context::get_stmt): New.
4774 2022-02-11 David Malcolm <dmalcolm@redhat.com>
4777 * region-model.cc (region_model::check_for_poison): Ignore
4778 uninitialized uses of empty types.
4780 2022-02-10 David Malcolm <dmalcolm@redhat.com>
4783 * region-model-manager.cc
4784 (region_model_manager::maybe_fold_sub_svalue): Generalize getting
4785 individual chars of a STRING_CST from element_region to any
4786 subregion which is a concrete access of a single byte from its
4788 * region.cc (region::get_relative_concrete_byte_range): New.
4789 * region.h (region::get_relative_concrete_byte_range): New decl.
4791 2022-02-09 David Malcolm <dmalcolm@redhat.com>
4794 * region-model.cc (selftest::test_bit_range_regions): New.
4795 (selftest::analyzer_region_model_cc_tests): Call it.
4796 * region.h (bit_range_region::key_t::hash): Fix hashing of m_bits
4797 to avoid using uninitialized data.
4799 2022-02-07 David Malcolm <dmalcolm@redhat.com>
4802 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
4803 Remove overzealous assertion.
4804 (tainted_allocation_size::emit): Likewise.
4805 (region_model::check_dynamic_size_for_taint): Likewise.
4807 2022-02-07 David Malcolm <dmalcolm@redhat.com>
4810 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
4811 Reimplement in terms of a get_store_value followed by a set_value.
4813 2022-02-03 David Malcolm <dmalcolm@redhat.com>
4816 * engine.cc (exploded_graph::process_node): Use the node for any
4817 diagnostics, avoiding ICE if a bifurcation update adds a
4818 saved_diagnostic, such as for a tainted realloc size.
4819 * region-model-impl-calls.cc
4820 (region_model::impl_call_realloc::success_no_move::update_model):
4821 Require the old pointer to be non-NULL to be able successfully
4822 grow in place. Use model->deref_rvalue rather than maybe_get_region
4823 to support the old pointer being symbolic.
4824 (region_model::impl_call_realloc::success_with_move::update_model):
4825 Likewise. Add a constraint that the new pointer != the old pointer.
4826 Use a sized_region when setting the value of the new region.
4827 Handle the case where we don't know the dynamic size of the old
4828 region by marking the new region as unknown.
4829 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
4830 Update assertion to also allow for MEMSPACE_UNKNOWN.
4831 (tainted_allocation_size::emit): Likewise.
4832 (region_model::check_dynamic_size_for_taint): Likewise.
4834 2022-02-03 David Malcolm <dmalcolm@redhat.com>
4836 * region-model-impl-calls.cc (region_model::impl_call_calloc): Use
4837 a sized_region when calling zero_fill_region.
4839 2022-02-02 David Malcolm <dmalcolm@redhat.com>
4841 * region-model.cc (region_model::on_return): Replace usage of
4842 copy_region with get_rvalue/set_value pair.
4843 (region_model::pop_frame): Likewise.
4844 (selftest::test_compound_assignment): Likewise.
4845 * region-model.h (region_model::copy_region): Delete decl.
4846 * region.cc (region_model::copy_region): Delete.
4848 2022-02-02 David Malcolm <dmalcolm@redhat.com>
4850 * region.cc (region::calc_offset): Consolidate effectively
4853 2022-02-02 David Malcolm <dmalcolm@redhat.com>
4855 * analyzer.h (class bit_range_region): New forward decl.
4856 * region-model-manager.cc (region_model_manager::get_bit_range):
4858 (region_model_manager::log_stats): Handle m_bit_range_regions.
4859 * region-model.cc (region_model::get_lvalue_1): Handle
4861 * region-model.h (region_model_manager::get_bit_range): New decl.
4862 (region_model_manager::m_bit_range_regions): New field.
4863 * region.cc (region::get_base_region): Handle RK_BIT_RANGE.
4864 (region::base_region_p): Likewise.
4865 (region::calc_offset): Likewise.
4866 (bit_range_region::dump_to_pp): New.
4867 (bit_range_region::get_byte_size): New.
4868 (bit_range_region::get_bit_size): New.
4869 (bit_range_region::get_byte_size_sval): New.
4870 (bit_range_region::get_relative_concrete_offset): New.
4871 * region.h (enum region_kind): Add RK_BIT_RANGE.
4872 (region::dyn_cast_bit_range_region): New vfunc.
4873 (class bit_range_region): New.
4874 (is_a_helper <const bit_range_region *>::test): New.
4875 (default_hash_traits<bit_range_region::key_t>): New.
4877 2022-02-02 David Malcolm <dmalcolm@redhat.com>
4880 * region-model.cc (region_model::on_call_pre): Handle
4883 2022-01-27 David Malcolm <dmalcolm@redhat.com>
4885 * checker-path.cc (event_kind_to_string): Handle
4887 (region_creation_event::region_creation_event): New.
4888 (region_creation_event::get_desc): New.
4889 (checker_path::add_region_creation_event): New.
4890 * checker-path.h (enum event_kind): Add EK_REGION_CREATION.
4891 (class region_creation_event): New subclass.
4892 (checker_path::add_region_creation_event): New decl.
4893 * diagnostic-manager.cc
4894 (diagnostic_manager::emit_saved_diagnostic): Pass NULL for new
4895 param to add_events_for_eedge when handling trailing eedge.
4896 (diagnostic_manager::build_emission_path): Create an interesting_t
4897 instance, allow the pending diagnostic to populate it, and pass it
4898 to the calls to add_events_for_eedge.
4899 (diagnostic_manager::add_events_for_eedge): Add "interest" param.
4900 Use it to add region_creation_events for on-stack regions created
4901 within at function entry, and when pertinent dynamically-sized
4902 regions are created.
4903 (diagnostic_manager::prune_for_sm_diagnostic): Add case for
4905 * diagnostic-manager.h (diagnostic_manager::add_events_for_eedge):
4906 Add "interest" param.
4907 * pending-diagnostic.cc: Include "selftest.h", "tristate.h",
4908 "analyzer/call-string.h", "analyzer/program-point.h",
4909 "analyzer/store.h", and "analyzer/region-model.h".
4910 (interesting_t::add_region_creation): New.
4911 (interesting_t::dump_to_pp): New.
4912 * pending-diagnostic.h (struct interesting_t): New.
4913 (pending_diagnostic::mark_interesting_stuff): New vfunc.
4915 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
4916 (poisoned_value_diagnostic::operator==): Compare m_pkind and
4917 m_src_region fields.
4918 (poisoned_value_diagnostic::mark_interesting_stuff): New.
4919 (poisoned_value_diagnostic::m_src_region): New.
4920 (region_model::check_for_poison): Call
4921 get_region_for_poisoned_expr for uninit values and pass the resul
4923 (region_model::get_region_for_poisoned_expr): New.
4924 (region_model::deref_rvalue): Pass NULL for
4925 poisoned_value_diagnostic's src_region.
4926 * region-model.h (region_model::get_region_for_poisoned_expr): New
4928 * region.h (frame_region::get_fndecl): New.
4930 2022-01-27 Martin Liska <mliska@suse.cz>
4933 * constraint-manager.cc (bounded_ranges_manager::log_stats):
4934 Cast to long for format purpose.
4935 * region-model-manager.cc (log_uniq_map): Likewise.
4937 2022-01-26 David Malcolm <dmalcolm@redhat.com>
4940 * region-model.cc (region_model::check_call_args): New.
4941 (region_model::on_call_pre): Call it when ignoring stdio builtins.
4942 * region-model.h (region_model::check_call_args): New decl
4944 2022-01-26 David Malcolm <dmalcolm@redhat.com>
4947 * constraint-manager.cc (range::add_bound): Fix tests for
4948 discarding redundant constraints. Perform test for rejecting
4949 unsatisfiable constraints earlier so that they don't update
4950 the object on failure.
4951 (selftest::test_range): New.
4952 (selftest::test_constant_comparisons): Add test coverage for
4953 existing constraints becoming narrower until they are
4955 (selftest::run_constraint_manager_tests): Call test_range.
4957 2022-01-22 David Malcolm <dmalcolm@redhat.com>
4960 * region-model-manager.cc
4961 (region_model_manager::get_or_create_cast): Bail out if the types
4962 are the same. Don't attempt to handle casts involving vector
4965 2022-01-20 David Malcolm <dmalcolm@redhat.com>
4968 * constraint-manager.cc (bound::ensure_closed): Convert param to
4970 (range::constrained_to_single_element): Likewise.
4971 (range::add_bound): New.
4972 (constraint_manager::add_constraint): Handle SVAL + OFFSET
4973 compared to a constant.
4974 (constraint_manager::get_ec_bounds): Rewrite in terms of
4976 (constraint_manager::eval_condition): Reject if range::add_bound
4978 (selftest::test_constant_comparisons): Add test coverage for
4979 various impossible combinations of integer comparisons.
4980 * constraint-manager.h (enum bound_kind): New.
4981 (struct bound): Likewise.
4982 (bound::ensure_closed): Convert to param to enum bound_kind.
4983 (struct range): Convert to...
4984 (class range): ...this, making fields private.
4985 (range::add_bound): New decls.
4986 * region-model.cc (region_model::add_constraint): Fail if
4987 constraint_manager::add_constraint fails.
4989 2022-01-18 David Malcolm <dmalcolm@redhat.com>
4992 * region-model-manager.cc
4993 (region_model_manager::get_or_create_constant_svalue): Assert that
4994 we have a CONSTANT_CLASS_P.
4995 (region_model_manager::maybe_fold_unaryop): Only fold a constant
4996 when fold_unary's result is a constant or a cast of a constant.
4998 2022-01-18 David Malcolm <dmalcolm@redhat.com>
5001 * region-model-manager.cc
5002 (region_model_manager::maybe_fold_sub_svalue): Avoid casting to
5003 NULL type when folding access to repeated svalue.
5005 2022-01-17 Martin Liska <mliska@suse.cz>
5007 * analyzer.cc (is_special_named_call_p): Rename .c names to .cc.
5008 (is_named_call_p): Likewise.
5009 * region-model-asm.cc (deterministic_p): Likewise.
5010 * region.cc (field_region::get_relative_concrete_offset): Likewise.
5011 * sm-malloc.cc (method_p): Likewise.
5012 * supergraph.cc (superedge::dump_dot): Likewise.
5014 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5016 * sm-taint.cc (taint_state_machine::combine_states): Handle combination
5017 of has_ub and has_lb.
5019 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5022 * sm-taint.cc (taint_state_machine::alt_get_inherited_state):
5023 Remove gcc_unreachable from default case for unary ops.
5025 2022-01-14 David Malcolm <dmalcolm@redhat.com>
5027 * engine.cc: Include "stringpool.h", "attribs.h", and
5029 (mark_params_as_tainted): New.
5030 (class tainted_args_function_custom_event): New.
5031 (class tainted_args_function_info): New.
5032 (exploded_graph::add_function_entry): Handle functions with
5033 "tainted_args" attribute.
5034 (class tainted_args_field_custom_event): New.
5035 (class tainted_args_callback_custom_event): New.
5036 (class tainted_args_call_info): New.
5037 (add_tainted_args_callback): New.
5038 (add_any_callbacks): New.
5039 (exploded_graph::build_initial_worklist): Likewise.
5040 (exploded_graph::build_initial_worklist): Find callbacks that are
5041 reachable from global initializers, calling add_any_callbacks on
5044 2022-01-12 David Malcolm <dmalcolm@redhat.com>
5047 * engine.cc (impl_sm_context::impl_sm_context): Add
5048 "unknown_side_effects" param and use it to initialize
5049 new m_unknown_side_effects field.
5050 (impl_sm_context::unknown_side_effects_p): New.
5051 (impl_sm_context::m_unknown_side_effects): New.
5052 (exploded_node::on_stmt): Pass unknown_side_effects to sm_ctxt
5054 * sm-taint.cc: Include "stringpool.h" and "attribs.h".
5055 (tainted_size::tainted_size): Drop "dir" param.
5056 (tainted_size::get_kind): Drop "FINAL".
5057 (tainted_size::emit): Likewise.
5058 (tainted_size::m_dir): Drop unused field.
5059 (class tainted_access_attrib_size): New subclass.
5060 (taint_state_machine::on_stmt): Call check_for_tainted_size_arg on
5061 external functions with unknown side effects.
5062 (taint_state_machine::check_for_tainted_size_arg): New.
5063 (region_model::check_region_for_taint): Drop "dir" param from
5065 * sm.h (sm_context::unknown_side_effects_p): New.
5067 2022-01-11 David Malcolm <dmalcolm@redhat.com>
5070 * diagnostic-manager.cc
5071 (class auto_disable_complexity_checks): Rename to...
5072 (class auto_checking_feasibility): ...this, updating
5073 the calls accordingly.
5074 (epath_finder::explore_feasible_paths): Update for renaming.
5075 * region-model-manager.cc
5076 (region_model_manager::region_model_manager): Update for change from
5077 m_check_complexity to m_checking_feasibility.
5078 (region_model_manager::reject_if_too_complex): Likewise.
5079 (region_model_manager::get_or_create_unknown_svalue): Handle
5080 m_checking_feasibility.
5081 (region_model_manager::create_unique_svalue): New.
5082 (region_model_manager::maybe_fold_binop): Handle BIT_AND_EXPR and
5083 BIT_IOR_EXPRs on booleans where we know the result.
5084 * region-model.cc (test_binop_svalue_folding): Add test coverage
5086 * region-model.h (region_model_manager::create_unique_svalue): New
5088 (region_model_manager::enable_complexity_check): Replace with...
5089 (region_model_manager::begin_checking_feasibility): ...this.
5090 (region_model_manager::disable_complexity_check): Replace with...
5091 (region_model_manager::end_checking_feasibility): ...this.
5092 (region_model_manager::m_check_complexity): Replace with...
5093 (region_model_manager::m_checking_feasibility): ...this.
5094 (region_model_manager::m_managed_dynamic_svalues): New field.
5096 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5098 * engine.cc (impl_run_checkers): Pass logger to engine ctor.
5099 * region-model-manager.cc
5100 (region_model_manager::region_model_manager): Add logger param and
5101 use it to initialize m_logger.
5102 * region-model.cc (engine::engine): New.
5103 * region-model.h (region_model_manager::region_model_manager):
5105 (region_model_manager::get_logger): New.
5106 (region_model_manager::m_logger): New field.
5107 (engine::engine): New.
5108 * store.cc (store_manager::get_logger): New.
5109 (store::set_value): Log scope. Log when marking a cluster as
5110 unknown due to possible aliasing.
5111 * store.h (store_manager::get_logger): New decl.
5113 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5115 * region-model-impl-calls.cc (cmp_decls): New.
5116 (cmp_decls_ptr_ptr): New.
5117 (region_model::impl_call_analyzer_dump_escaped): New.
5118 * region-model.cc (region_model::on_stmt_pre): Handle
5119 __analyzer_dump_escaped.
5120 * region-model.h (region_model::impl_call_analyzer_dump_escaped):
5122 * store.h (binding_cluster::get_base_region): New accessor.
5124 2022-01-08 David Malcolm <dmalcolm@redhat.com>
5126 * region.cc (region::is_named_decl_p): New.
5127 * region.h (region::is_named_decl_p): New decl.
5129 2022-01-06 David Malcolm <dmalcolm@redhat.com>
5132 * store.cc (store::eval_alias_1): Refactor handling of decl
5133 regions, adding a test for may_be_aliased, rejecting those for
5134 which it returns false.
5136 2021-12-12 Jonathan Wakely <jwakely@redhat.com>
5138 * engine.cc: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
5140 2021-12-06 David Malcolm <dmalcolm@redhat.com>
5143 * constraint-manager.cc (equiv_class::contains_non_constant_p):
5145 (constraint_manager::canonicalize): Call it when determining
5147 (selftest::test_purging): New selftest.
5148 (selftest::run_constraint_manager_tests): Likewise.
5149 * constraint-manager.h (equiv_class::contains_non_constant_p):
5152 2021-12-01 David Malcolm <dmalcolm@redhat.com>
5155 * region-model-reachability.cc (reachable_regions::handle_parm):
5156 Treat all svalues within a compound parm has reachable, and those
5159 2021-11-29 David Malcolm <dmalcolm@redhat.com>
5162 * store.cc (binding_cluster::can_merge_p): For the "key is bound"
5163 vs "key is not bound" merger case, check that the bound svalue
5164 is mergeable before merging it to "unknown", rejecting the merger
5167 2021-11-19 David Malcolm <dmalcolm@redhat.com>
5170 * engine.cc (exploded_graph::get_or_create_node): Pass in
5171 m_ext_state to program_state::can_merge_with_p.
5172 (exploded_graph::process_worklist): Likewise.
5173 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
5175 (exploded_graph::process_node): Add missing call to detect_leaks
5176 when handling phi nodes.
5177 * program-state.cc (program_state::can_merge_with_p): Add
5178 "ext_state" param. Pass it and state ptrs to
5179 region_model::can_merge_with_p.
5180 (selftest::test_program_state_merging): Update for new ext_state
5181 param of program_state::can_merge_with_p.
5182 (selftest::test_program_state_merging_2): Likewise.
5183 * program-state.h (program_state::can_purge_p): Make const.
5184 (program_state::can_merge_with_p): Add "ext_state" param.
5185 * region-model.cc: Include "analyzer/program-state.h".
5186 (region_model::can_merge_with_p): Add params "ext_state",
5187 "state_a", and "state_b", use them when creating model_merger
5189 (model_merger::mergeable_svalue_p): New.
5190 * region-model.h (region_model::can_merge_with_p): Add params
5191 "ext_state", "state_a", and "state_b".
5192 (model_merger::model_merger) Likewise, initializing new fields.
5193 (model_merger::mergeable_svalue_p): New decl.
5194 (model_merger::m_ext_state): New field.
5195 (model_merger::m_state_a): New field.
5196 (model_merger::m_state_b): New field.
5197 * svalue.cc (svalue::can_merge_p): Call
5198 model_merger::mergeable_svalue_p on both states and reject the
5201 2021-11-17 David Malcolm <dmalcolm@redhat.com>
5204 * region-model-impl-calls.cc (region_model::impl_call_strchr): New.
5205 * region-model-manager.cc
5206 (region_model_manager::maybe_fold_unaryop): Simplify cast to
5207 pointer type of an existing pointer to a region.
5208 * region-model.cc (region_model::on_call_pre): Handle
5209 BUILT_IN_STRCHR and "strchr".
5210 (write_to_const_diagnostic::emit): Add auto_diagnostic_group. Add
5211 alternate wordings for functions and labels.
5212 (write_to_const_diagnostic::describe_final_event): Add alternate
5213 wordings for functions and labels.
5214 (region_model::check_for_writable_region): Handle RK_FUNCTION and
5216 * region-model.h (region_model::impl_call_strchr): New decl.
5218 2021-11-16 David Malcolm <dmalcolm@redhat.com>
5221 * constraint-manager.cc (bounded_range::operator==): Require the
5222 types to be the same for equality.
5224 2021-11-13 David Malcolm <dmalcolm@redhat.com>
5226 * analyzer.opt (Wanalyzer-tainted-allocation-size): New.
5227 (Wanalyzer-tainted-divisor): New.
5228 (Wanalyzer-tainted-offset): New.
5229 (Wanalyzer-tainted-size): New.
5230 * engine.cc (impl_region_model_context::get_taint_map): New.
5231 * exploded-graph.h (impl_region_model_context::get_taint_map):
5233 * program-state.cc (sm_state_map::get_state): Call
5234 alt_get_inherited_state.
5235 (sm_state_map::impl_set_state): Modify states within
5237 (program_state::impl_call_analyzer_dump_state): Undo casts.
5238 (selftest::test_program_state_1): Update for new context param of
5239 create_region_for_heap_alloc.
5240 (selftest::test_program_state_merging): Likewise.
5241 * region-model-impl-calls.cc (region_model::impl_call_alloca):
5243 (region_model::impl_call_calloc): Likewise.
5244 (region_model::impl_call_malloc): Likewise.
5245 (region_model::impl_call_operator_new): Likewise.
5246 (region_model::impl_call_realloc): Likewise.
5247 * region-model.cc (region_model::check_region_access): Call
5248 check_region_for_taint.
5249 (region_model::get_representative_path_var_1): Handle binops.
5250 (region_model::create_region_for_heap_alloc): Add "ctxt" param and
5251 pass it to set_dynamic_extents.
5252 (region_model::create_region_for_alloca): Likewise.
5253 (region_model::set_dynamic_extents): Add "ctxt" param and use it
5254 to call check_dynamic_size_for_taint.
5255 (selftest::test_state_merging): Update for new context param of
5256 create_region_for_heap_alloc.
5257 (selftest::test_malloc_constraints): Likewise.
5258 (selftest::test_malloc): Likewise.
5259 (selftest::test_alloca): Likewise for create_region_for_alloca.
5260 * region-model.h (region_model::create_region_for_heap_alloc): Add
5262 (region_model::create_region_for_alloca): Likewise.
5263 (region_model::set_dynamic_extents): Likewise.
5264 (region_model::check_dynamic_size_for_taint): New decl.
5265 (region_model::check_region_for_taint): New decl.
5266 (region_model_context::get_taint_map): New vfunc.
5267 (noop_region_model_context::get_taint_map): New.
5268 * sm-taint.cc: Remove include of "diagnostic-event-id.h"; add
5269 includes of "gimple-iterator.h", "tristate.h", "selftest.h",
5270 "ordered-hash-map.h", "cgraph.h", "cfg.h", "digraph.h",
5271 "analyzer/supergraph.h", "analyzer/call-string.h",
5272 "analyzer/program-point.h", "analyzer/store.h",
5273 "analyzer/region-model.h", and "analyzer/program-state.h".
5274 (enum bounds): Move to top of file.
5275 (class taint_diagnostic): New.
5276 (class tainted_array_index): Convert to subclass of taint_diagnostic.
5277 (tainted_array_index::emit): Add CWE-129. Reword warning to use
5278 "attacker-controlled" rather than "tainted".
5279 (tainted_array_index::describe_state_change): Move to
5280 taint_diagnostic::describe_state_change.
5281 (tainted_array_index::describe_final_event): Reword to use
5282 "attacker-controlled" rather than "tainted".
5283 (class tainted_offset): New.
5284 (class tainted_size): New.
5285 (class tainted_divisor): New.
5286 (class tainted_allocation_size): New.
5287 (taint_state_machine::alt_get_inherited_state): New.
5288 (taint_state_machine::on_stmt): In assignment handling, remove
5289 ARRAY_REF handling in favor of check_region_for_taint. Add
5290 detection of tainted divisors.
5291 (taint_state_machine::get_taint): New.
5292 (taint_state_machine::combine_states): New.
5293 (region_model::check_region_for_taint): New.
5294 (region_model::check_dynamic_size_for_taint): New.
5295 * sm.h (state_machine::alt_get_inherited_state): New.
5297 2021-11-12 David Malcolm <dmalcolm@redhat.com>
5299 * engine.cc (exploded_node::on_stmt_pre): Return when handling
5300 "__analyzer_dump_state".
5302 2021-11-11 Richard Biener <rguenther@suse.de>
5304 * supergraph.cc: Include bitmap.h.
5306 2021-11-04 David Malcolm <dmalcolm@redhat.com>
5308 * program-state.cc (sm_state_map::dump): Use default_tree_printer
5311 2021-09-16 Maxim Blinov <maxim.blinov@embecosm.com>
5314 * engine.cc (INCLUDE_UNIQUE_PTR): Define.
5316 2021-09-08 David Malcolm <dmalcolm@redhat.com>
5319 * analyzer.h (compat_types_p): New decl.
5320 * constraint-manager.cc
5321 (constraint_manager::get_or_add_equiv_class): Guard against NULL
5322 type when checking for pointer types.
5323 * region-model-impl-calls.cc (region_model::impl_call_realloc):
5324 Guard against NULL lhs type/region. Guard against the size value
5325 not being of a compatible type for dynamic extents.
5326 * region-model.cc (compat_types_p): Make non-static.
5328 2021-08-30 David Malcolm <dmalcolm@redhat.com>
5331 * analyzer.h (class custom_edge_info): New class, adapted from
5332 exploded_edge::custom_info_t. Make member functions const.
5333 Make update_model return bool, converting edge param from
5334 reference to a pointer, and adding a ctxt param.
5335 (class path_context): New class.
5336 * call-info.cc: New file.
5337 * call-info.h: New file.
5338 * engine.cc: Include "analyzer/call-info.h" and <memory>.
5339 (impl_region_model_context::impl_region_model_context): Update for
5340 new m_path_ctxt field.
5341 (impl_region_model_context::bifurcate): New.
5342 (impl_region_model_context::terminate_path): New.
5343 (impl_region_model_context::get_malloc_map): New.
5344 (impl_sm_context::impl_sm_context): Update for new m_path_ctxt
5346 (impl_sm_context::get_fndecl_for_call): Likewise.
5347 (impl_sm_context::set_next_state): Likewise.
5348 (impl_sm_context::warn): Likewise.
5349 (impl_sm_context::is_zero_assignment): Likewise.
5350 (impl_sm_context::get_path_context): New.
5351 (impl_sm_context::m_path_ctxt): New.
5352 (impl_region_model_context::on_condition): Update for new
5353 path_ctxt param. Handle m_enode_for_diag being NULL.
5354 (impl_region_model_context::on_phi): Update for new path_ctxt
5356 (exploded_node::on_stmt): Add path_ctxt param, updating ctor calls
5357 to use it as necessary. Use it to bail out after sm-handling,
5359 (exploded_node::detect_leaks): Update for new path_ctxt param.
5360 (dynamic_call_info_t::update_model): Update for conversion of
5361 exploded_edge::custom_info_t to custom_edge_info.
5362 (dynamic_call_info_t::add_events_to_path): Likewise.
5363 (rewind_info_t::update_model): Likewise.
5364 (rewind_info_t::add_events_to_path): Likewise.
5365 (exploded_edge::exploded_edge): Likewise.
5366 (exploded_graph::add_edge): Likewise.
5367 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
5368 Update for new path_ctxt param.
5369 (class impl_path_context): New.
5370 (exploded_graph::process_node): Update for new path_ctxt param.
5371 Create an impl_path_context and pass it to exploded_node::on_stmt.
5372 Use it to terminate iterating stmts if terminate_path is called
5373 on it. After processing a run of stmts, query path_ctxt to
5374 potentially terminate the analysis path, and/or to "bifurcate" the
5375 analysis into multiple additional paths.
5376 (feasibility_state::maybe_update_for_edge): Update for new
5377 update_model ctxt param.
5379 (impl_region_model_context::impl_region_model_context): Add
5381 (impl_region_model_context::bifurcate): New.
5382 (impl_region_model_context::terminate_path): New
5383 (impl_region_model_context::get_ext_state): New.
5384 (impl_region_model_context::get_malloc_map): New.
5385 (impl_region_model_context::m_path_ctxt): New field.
5386 (exploded_node::on_stmt): Add path_ctxt param.
5387 (class exploded_edge::custom_info_t): Move to analyzer.h, renaming
5388 to custom_edge_info, and making the changes as noted in analyzer.h
5390 (exploded_edge::exploded_edge): Update for these changes to
5391 exploded_edge::custom_info_t.
5392 (exploded_edge::m_custom_info): Likewise.
5393 (class dynamic_call_info_t): Likewise.
5394 (class rewind_info_t): Likewise.
5395 (exploded_graph::add_edge): Likewise.
5396 * program-state.cc (program_state::on_edge): Update for new
5398 (program_state::push_call): Likewise.
5399 (program_state::returning_call): Likewise.
5400 (program_state::prune_for_point): Likewise.
5401 * region-model-impl-calls.cc: Include "analyzer/call-info.h".
5402 (call_details::get_fndecl_for_call): New.
5403 (region_model::impl_call_realloc): Reimplement.
5404 * region-model.cc (region_model::on_call_pre): Move call to
5405 impl_call_realloc to...
5406 (region_model::on_call_post): ...here. Consolidate creation
5407 of call_details instance.
5408 (noop_region_model_context::bifurcate): New.
5409 (noop_region_model_context::terminate_path): New.
5410 * region-model.h (call_details::get_call_stmt): New.
5411 (call_details::get_fndecl_for_call): New.
5412 (region_model::on_realloc_with_move): New.
5413 (region_model_context::bifurcate): New.
5414 (region_model_context::terminate_path): New.
5415 (region_model_context::get_ext_state): New.
5416 (region_model_context::get_malloc_map): New.
5417 (noop_region_model_context::bifurcate): New.
5418 (noop_region_model_context::terminate_path): New.
5419 (noop_region_model_context::get_ext_state): New.
5420 (noop_region_model_context::get_malloc_map): New.
5421 * sm-malloc.cc: Include "analyzer/program-state.h".
5422 (malloc_state_machine::on_realloc_call): Reimplement.
5423 (malloc_state_machine::on_realloc_with_move): New.
5424 (region_model::on_realloc_with_move): New.
5425 * sm-signal.cc (class signal_delivery_edge_info_t): Update for
5426 conversion from exploded_edge::custom_info_t to custom_edge_info.
5427 * sm.h (sm_context::get_path_context): New.
5428 * svalue.cc (svalue::maybe_get_constant): Call
5429 unwrap_any_unmergeable.
5431 2021-08-25 Ankur Saini <arsenic@sourceware.org>
5434 * engine.cc (exploded_graph::maybe_create_dynamic_call): Don't create
5435 calls if max recursion limit is reached.
5437 2021-08-23 David Malcolm <dmalcolm@redhat.com>
5439 * analyzer.h (struct rejected_constraint): Convert to...
5440 (class rejected_constraint): ...this.
5441 (class bounded_ranges): New forward decl.
5442 (class bounded_ranges_manager): New forward decl.
5443 * constraint-manager.cc: Include "analyzer/analyzer-logging.h" and
5444 "tree-pretty-print.h".
5445 (can_plus_one_p): New.
5447 (can_minus_one_p): New.
5449 (bounded_range::bounded_range): New.
5451 (bounded_range::dump_to_pp): New.
5452 (bounded_range::dump): New.
5453 (bounded_range::to_json): New.
5454 (bounded_range::set_json_attr): New.
5455 (bounded_range::contains_p): New.
5456 (bounded_range::intersects_p): New.
5457 (bounded_range::operator==): New.
5458 (bounded_range::cmp): New.
5459 (bounded_ranges::bounded_ranges): New.
5460 (bounded_ranges::bounded_ranges): New.
5461 (bounded_ranges::bounded_ranges): New.
5462 (bounded_ranges::canonicalize): New.
5463 (bounded_ranges::validate): New.
5464 (bounded_ranges::operator==): New.
5465 (bounded_ranges::dump_to_pp): New.
5466 (bounded_ranges::dump): New.
5467 (bounded_ranges::to_json): New.
5468 (bounded_ranges::eval_condition): New.
5469 (bounded_ranges::contain_p): New.
5470 (bounded_ranges::cmp): New.
5471 (bounded_ranges_manager::~bounded_ranges_manager): New.
5472 (bounded_ranges_manager::get_or_create_empty): New.
5473 (bounded_ranges_manager::get_or_create_point): New.
5474 (bounded_ranges_manager::get_or_create_range): New.
5475 (bounded_ranges_manager::get_or_create_union): New.
5476 (bounded_ranges_manager::get_or_create_intersection): New.
5477 (bounded_ranges_manager::get_or_create_inverse): New.
5478 (bounded_ranges_manager::consolidate): New.
5479 (bounded_ranges_manager::get_or_create_ranges_for_switch): New.
5480 (bounded_ranges_manager::create_ranges_for_switch): New.
5481 (bounded_ranges_manager::make_case_label_ranges): New.
5482 (bounded_ranges_manager::log_stats): New.
5483 (bounded_ranges_constraint::print): New.
5484 (bounded_ranges_constraint::to_json): New.
5485 (bounded_ranges_constraint::operator==): New.
5486 (bounded_ranges_constraint::add_to_hash): New.
5487 (constraint_manager::constraint_manager): Update for new field
5488 m_bounded_ranges_constraints.
5489 (constraint_manager::operator=): Likewise.
5490 (constraint_manager::hash): Likewise.
5491 (constraint_manager::operator==): Likewise.
5492 (constraint_manager::print): Likewise.
5493 (constraint_manager::dump_to_pp): Likewise.
5494 (constraint_manager::to_json): Likewise.
5495 (constraint_manager::add_unknown_constraint): Update the lhs_ec_id
5496 if necessary in existing constraints when combining equivalence
5497 classes. Add similar code for handling
5498 m_bounded_ranges_constraints.
5499 (constraint_manager::add_constraint_internal): Add comment.
5500 (constraint_manager::add_bounded_ranges): New.
5501 (constraint_manager::eval_condition): Use new field
5502 m_bounded_ranges_constraints.
5503 (constraint_manager::purge): Update bounded_ranges_constraint
5505 (constraint_manager::canonicalize): Update for new field.
5506 (merger_fact_visitor::on_ranges): New.
5507 (constraint_manager::for_each_fact): Use new field
5508 m_bounded_ranges_constraints.
5509 (constraint_manager::validate): Fix off-by-one error needed due
5510 to bug fixed above in add_unknown_constraint. Validate the EC IDs
5511 in m_bounded_ranges_constraints.
5512 (constraint_manager::get_range_manager): New.
5513 (selftest::assert_dump_bounded_range_eq): New.
5514 (ASSERT_DUMP_BOUNDED_RANGE_EQ): New.
5515 (selftest::test_bounded_range): New.
5516 (selftest::assert_dump_bounded_ranges_eq): New.
5517 (ASSERT_DUMP_BOUNDED_RANGES_EQ): New.
5518 (selftest::test_bounded_ranges): New.
5519 (selftest::run_constraint_manager_tests): Call the new selftests.
5520 * constraint-manager.h (struct bounded_range): New.
5521 (struct bounded_ranges): New.
5522 (template <> struct default_hash_traits<bounded_ranges::key_t>): New.
5523 (class bounded_ranges_manager): New.
5524 (fact_visitor::on_ranges): New pure virtual function.
5525 (class bounded_ranges_constraint): New.
5526 (constraint_manager::add_bounded_ranges): New decl.
5527 (constraint_manager::get_range_manager): New decl.
5528 (constraint_manager::m_bounded_ranges_constraints): New field.
5529 * diagnostic-manager.cc (epath_finder::process_worklist_item):
5530 Transfer ownership of rc to add_feasibility_problem.
5531 * engine.cc (feasibility_problem::dump_to_pp): Use get_model.
5532 * feasible-graph.cc (infeasible_node::dump_dot): Update for
5533 conversion of m_rc to a pointer.
5534 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
5536 * feasible-graph.h (infeasible_node::infeasible_node): Pass RC by
5537 pointer and take ownership.
5538 (infeasible_node::~infeasible_node): New.
5539 (infeasible_node::m_rc): Convert to a pointer.
5540 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
5542 * region-model-manager.cc: Include
5543 "analyzer/constraint-manager.h".
5544 (region_model_manager::region_model_manager): Initializer new
5546 (region_model_manager::~region_model_manager): Delete it.
5547 (region_model_manager::log_stats): Call log_stats on it.
5548 * region-model.cc (region_model::add_constraint): Use new subclass
5549 rejected_op_constraint.
5550 (region_model::apply_constraints_for_gswitch): Reimplement using
5551 bounded_ranges_manager.
5552 (rejected_constraint::dump_to_pp): Convert to...
5553 (rejected_op_constraint::dump_to_pp): ...this.
5554 (rejected_ranges_constraint::dump_to_pp): New.
5555 * region-model.h (struct purge_stats): Add field
5556 m_num_bounded_ranges_constraints.
5557 (region_model_manager::get_range_manager): New.
5558 (region_model_manager::m_range_mgr): New.
5559 (region_model::get_range_manager): New.
5560 (struct rejected_constraint): Split into...
5561 (class rejected_constraint):...this new abstract base class,
5563 (class rejected_op_constraint): ...this new concrete subclass.
5564 (class rejected_ranges_constraint): New.
5565 * supergraph.cc: Include "tree-cfg.h".
5566 (supergraph::supergraph): Drop idx param from add_cfg_edge.
5567 (supergraph::add_cfg_edge): Drop idx param.
5568 (switch_cfg_superedge::switch_cfg_superedge): Move here from
5569 header. Populate m_case_labels with all cases which go to DST.
5570 (switch_cfg_superedge::dump_label_to_pp): Reimplement to use
5572 (switch_cfg_superedge::get_case_label): Delete.
5573 * supergraph.h (supergraphadd_cfg_edge): Drop "idx" param.
5574 (switch_cfg_superedge::switch_cfg_superedge): Drop idx param and
5575 move implementation to supergraph.cc.
5576 (switch_cfg_superedge::get_case_label): Delete.
5577 (switch_cfg_superedge::get_case_labels): New.
5578 (switch_cfg_superedge::m_idx): Delete.
5579 (switch_cfg_superedge::m_case_labels): New field.
5581 2021-08-23 David Malcolm <dmalcolm@redhat.com>
5584 * sm-file.cc (file_diagnostic::describe_state_change): Handle
5585 change.m_expr being NULL.
5587 2021-08-23 David Malcolm <dmalcolm@redhat.com>
5590 * analyzer.cc (maybe_reconstruct_from_def_stmt): Bail if fn is
5591 NULL, and assert that it's non-NULL before passing it to
5592 build_call_array_loc.
5594 2021-08-23 David Malcolm <dmalcolm@redhat.com>
5597 * region-model.cc (region_model::eval_condition_without_cm):
5598 Refactor comparison against zero, adding a check for
5599 POINTER_PLUS_EXPR of non-NULL.
5601 2021-08-23 David Malcolm <dmalcolm@redhat.com>
5603 * store.cc (bit_range::intersects_p): New overload.
5604 (bit_range::operator-): New.
5605 (binding_cluster::maybe_get_compound_binding): Handle the partial
5607 (selftest::test_bit_range_intersects_p): Add test coverage for
5608 new overload of bit_range::intersects_p.
5609 * store.h (bit_range::intersects_p): New overload.
5610 (bit_range::operator-): New.
5612 2021-08-23 Ankur Saini <arsenic@sourceware.org>
5615 * diagnostic-manager.cc
5616 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Fix typo.
5618 2021-08-21 Ankur Saini <arsenic@sourceware.org>
5621 * diagnostic-manager.cc
5622 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Use
5623 caller_model only when the supergraph_edge doesn't exixt.
5624 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
5626 * engine.cc (exploded_graph::create_dynamic_call): Rename to...
5627 (exploded_graph::maybe_create_dynamic_call): ...this, return call
5629 (exploded_graph::process_node): Handle calls which were not dynamically
5631 * exploded-graph.h (exploded_graph::create_dynamic_call): Rename to...
5632 (exploded_graph::maybe_create_dynamic_call): ...this.
5633 * region-model.cc (region_model::update_for_gcall): New param, use it
5634 to push call to frame.
5635 (region_model::update_for_call_superedge): Pass callee function to
5637 * region-model.h (region_model::update_for_gcall): New param.
5639 2021-08-18 Ankur Saini <arsenic@sourceware.org>
5642 * region-model.cc (region_model::get_rvalue_1): Add case for
5645 2021-08-18 Ankur Saini <arsenic@sourceware.org>
5648 * analysis-plan.cc (analysis_plan::use_summary_p): Don't use call
5649 summaries if there is no callgraph edge
5650 * checker-path.cc (call_event::call_event): Handle calls events that
5651 are not represented by a supergraph call edge
5652 (return_event::return_event): Likewise.
5653 (call_event::get_desc): Work with new call_event structure.
5654 (return_event::get_desc): Likeise.
5655 * checker-path.h (call_event::m_src_snode): New field.
5656 (call_event::m_dest_snode): New field.
5657 (return_event::m_src_snode): New field.
5658 (return_event::m_dest_snode): New field.
5659 * diagnostic-manager.cc
5660 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>:
5661 Refactor to work with edges without callgraph edge.
5662 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
5664 * engine.cc (dynamic_call_info_t::update_model): New function.
5665 (dynamic_call_info_t::add_events_to_path): New function.
5666 (exploded_graph::create_dynamic_call): New function.
5667 (exploded_graph::process_node): Work with dynamically discovered calls.
5668 * exploded-graph.h (class dynamic_call_info_t): New class.
5669 (exploded_graph::create_dynamic_call): New decl.
5670 * program-point.cc (program_point::push_to_call_stack): New function.
5671 (program_point::pop_from_call_stack): New function.
5672 * program-point.h (program_point::push_to_call_stack): New decl.
5673 (program_point::pop_from_call_stack): New decl.
5674 * program-state.cc (program_state::push_call): New function.
5675 (program_state::returning_call): New function.
5676 * program-state.h (program_state::push_call): New decl.
5677 (program_state::returning_call): New decl.
5678 * region-model.cc (region_model::update_for_gcall) New function.
5679 (region_model::update_for_return_gcall): New function.
5680 (egion_model::update_for_call_superedge): Get the underlying gcall and
5682 (region_model::update_for_return_superedge): Likewise.
5683 * region-model.h (region_model::update_for_gcall): New decl.
5684 (region_model::update_for_return_gcall): New decl.
5685 * state-purge.cc (state_purge_per_ssa_name::process_point): Update to
5686 work with calls without underlying cgraph edge.
5687 * supergraph.cc (supergraph::supergraph) Split snodes at every callsite.
5688 * supergraph.h (supernode::get_returning_call) New accessor.
5690 2021-08-04 David Malcolm <dmalcolm@redhat.com>
5693 * analyzer.cc (maybe_reconstruct_from_def_stmt): Add GIMPLE_ASM
5695 * analyzer.h (class asm_output_svalue): New forward decl.
5696 (class reachable_regions): New forward decl.
5697 * complexity.cc (complexity::from_vec_svalue): New.
5698 * complexity.h (complexity::from_vec_svalue): New decl.
5699 * engine.cc (feasibility_state::maybe_update_for_edge): Handle
5700 asm stmts by calling on_asm_stmt.
5701 * region-model-asm.cc: New file.
5702 * region-model-manager.cc
5703 (region_model_manager::maybe_fold_asm_output_svalue): New.
5704 (region_model_manager::get_or_create_asm_output_svalue): New.
5705 (region_model_manager::log_stats): Log m_asm_output_values_map.
5706 * region-model.cc (region_model::on_stmt_pre): Handle GIMPLE_ASM.
5707 * region-model.h (visitor::visit_asm_output_svalue): New.
5708 (region_model_manager::get_or_create_asm_output_svalue): New decl.
5709 (region_model_manager::maybe_fold_asm_output_svalue): New decl.
5710 (region_model_manager::asm_output_values_map_t): New typedef.
5711 (region_model_manager::m_asm_output_values_map): New field.
5712 (region_model::on_asm_stmt): New.
5713 * store.cc (binding_cluster::on_asm): New.
5714 * store.h (binding_cluster::on_asm): New decl.
5715 * svalue.cc (svalue::cmp_ptr): Handle SK_ASM_OUTPUT.
5716 (asm_output_svalue::dump_to_pp): New.
5717 (asm_output_svalue::dump_input): New.
5718 (asm_output_svalue::input_idx_to_asm_idx): New.
5719 (asm_output_svalue::accept): New.
5720 * svalue.h (enum svalue_kind): Add SK_ASM_OUTPUT.
5721 (svalue::dyn_cast_asm_output_svalue): New.
5722 (class asm_output_svalue): New.
5723 (is_a_helper <const asm_output_svalue *>::test): New.
5724 (struct default_hash_traits<asm_output_svalue::key_t>): New.
5726 2021-08-03 Jakub Jelinek <jakub@redhat.com>
5729 * sm-malloc.cc (known_allocator_p): Only check DECL_FUNCTION_CODE on
5730 BUILT_IN_NORMAL builtins.
5732 2021-07-29 Ankur Saini <arsenic@sourceware.org>
5734 * call-string.cc (call_string::element_t::operator==): New operator.
5735 (call_String::element_t::operator!=): New operator.
5736 (call_string::element_t::get_caller_function): New function.
5737 (call_string::element_t::get_callee_function): New function.
5738 (call_string::call_string): Refactor to Initialise m_elements.
5739 (call_string::operator=): Refactor to work with m_elements.
5740 (call_string::operator==): Likewise.
5741 (call_string::to_json): Likewise.
5742 (call_string::hash): Refactor to hash e.m_caller.
5743 (call_string::push_call): Refactor to work with m_elements.
5744 (call_string::push_call): New overload to push call via supernodes.
5745 (call_string::pop): Refactor to work with m_elements.
5746 (call_string::calc_recursion_depth): Likewise.
5747 (call_string::cmp): Likewise.
5748 (call_string::validate): Likewise.
5749 (call_string::operator[]): Likewise.
5750 * call-string.h (class supernode): New forward decl.
5751 (struct call_string::element_t): New struct.
5752 (call_string::call_string): Refactor to initialise m_elements.
5753 (call_string::bool empty_p): Refactor to work with m_elements.
5754 (call_string::get_callee_node): New decl.
5755 (call_string::get_caller_node): New decl.
5756 (m_elements): Replaces m_return_edges.
5757 * program-point.cc (program_point::get_function_at_depth): Refactor to
5758 work with new call-string format.
5759 (program_point::validate): Likewise.
5760 (program_point::on_edge): Likewise.
5762 2021-07-28 David Malcolm <dmalcolm@redhat.com>
5764 * region-model.cc (region_model::on_call_pre): Treat
5765 IFN_UBSAN_BOUNDS, BUILT_IN_STACK_SAVE, and BUILT_IN_STACK_RESTORE
5766 as no-ops, rather than handling them as unknown functions.
5768 2021-07-28 David Malcolm <dmalcolm@redhat.com>
5770 * region-model-impl-calls.cc (region_model::impl_call_alloca):
5771 Drop redundant return value.
5772 (region_model::impl_call_builtin_expect): Likewise.
5773 (region_model::impl_call_calloc): Likewise.
5774 (region_model::impl_call_malloc): Likewise.
5775 (region_model::impl_call_memset): Likewise.
5776 (region_model::impl_call_operator_new): Likewise.
5777 (region_model::impl_call_operator_delete): Likewise.
5778 (region_model::impl_call_strlen): Likewise.
5779 * region-model.cc (region_model::on_call_pre): Fix return value of
5780 known functions that don't have unknown side-effects.
5781 * region-model.h (region_model::impl_call_alloca): Drop redundant
5783 (region_model::impl_call_builtin_expect): Likewise.
5784 (region_model::impl_call_calloc): Likewise.
5785 (region_model::impl_call_malloc): Likewise.
5786 (region_model::impl_call_memset): Likewise.
5787 (region_model::impl_call_strlen): Likewise.
5788 (region_model::impl_call_operator_new): Likewise.
5789 (region_model::impl_call_operator_delete): Likewise.
5791 2021-07-28 Siddhesh Poyarekar <siddhesh@gotplt.org>
5793 * analyzer.cc (is_named_call_p, is_std_named_call_p): Make
5794 first argument a const_tree.
5795 * analyzer.h (is_named_call_p, -s_std_named_call_p): Likewise.
5796 * sm-malloc.cc (known_allocator_p): New function.
5797 (malloc_state_machine::on_stmt): Use it.
5799 2021-07-28 Siddhesh Poyarekar <siddhesh@gotplt.org>
5802 (malloc_state_machine::get_or_create_deallocator): Recognize
5805 2021-07-26 David Malcolm <dmalcolm@redhat.com>
5807 * region-model.cc (region_model::on_call_pre): Always set conjured
5808 LHS, not just for SSA names.
5810 2021-07-23 David Malcolm <dmalcolm@redhat.com>
5812 * diagnostic-manager.cc
5813 (class auto_disable_complexity_checks): New.
5814 (epath_finder::explore_feasible_paths): Use it to disable
5815 complexity checks whilst processing the worklist.
5816 * region-model-manager.cc
5817 (region_model_manager::region_model_manager): Initialize
5819 (region_model_manager::reject_if_too_complex): Bail if
5820 m_check_complexity is false.
5822 (region_model_manager::enable_complexity_check): New.
5823 (region_model_manager::disable_complexity_check): New.
5824 (region_model_manager::m_check_complexity): New.
5826 2021-07-21 David Malcolm <dmalcolm@redhat.com>
5829 * sm-file.cc (file_leak::emit): Handle m_arg being NULL.
5830 (file_leak::describe_final_event): Handle ev.m_expr being NULL.
5832 2021-07-21 David Malcolm <dmalcolm@redhat.com>
5835 * store.cc (binding_cluster::purge_state_involving): Don't change
5836 m_map whilst iterating through it.
5838 2021-07-21 David Malcolm <dmalcolm@redhat.com>
5840 * region-model.cc (region_model::handle_phi): Add "old_state"
5842 (region_model::update_for_phis): Update so that all of the phi
5843 stmts are effectively handled simultaneously, rather than in
5845 * region-model.h (region_model::handle_phi): Add "old_state"
5847 * state-purge.cc (self_referential_phi_p): Replace with...
5848 (name_used_by_phis_p): ...this new function.
5849 (state_purge_per_ssa_name::process_point): Update to use the
5850 above, so that all phi stmts at a basic block are effectively
5851 considered simultaneously, and only consider the phi arguments for
5852 the pertinent in-edge.
5853 * supergraph.cc (cfg_superedge::get_phi_arg_idx): New.
5854 (cfg_superedge::get_phi_arg): Use the above.
5855 * supergraph.h (cfg_superedge::get_phi_arg_idx): New decl.
5857 2021-07-21 David Malcolm <dmalcolm@redhat.com>
5859 * state-purge.cc (state_purge_annotator::add_node_annotations):
5860 Rather than erroneously always using the NULL in-edge, determine
5861 each relevant in-edge, and print the appropriate data for each
5862 in-edge. Use print_needed to print the data as comma-separated
5864 (print_vec_of_names): Add "within_table" param and use it.
5865 (state_purge_annotator::add_stmt_annotations): Factor out
5866 collation and printing code into...
5867 (state_purge_annotator::print_needed): ...this new function.
5868 * state-purge.h (state_purge_annotator::print_needed): New decl.
5870 2021-07-21 David Malcolm <dmalcolm@redhat.com>
5872 * program-point.cc (function_point::print): Show src BB index at
5875 2021-07-21 David Malcolm <dmalcolm@redhat.com>
5877 * svalue.cc (infix_p): New.
5878 (binop_svalue::dump_to_pp): Use it to print MIN_EXPR and MAX_EXPR
5879 in prefix form, rather than infix.
5881 2021-07-19 David Malcolm <dmalcolm@redhat.com>
5884 * constraint-manager.cc (constraint_manager::add_constraint): Use
5885 can_have_associated_state_p rather than testing for unknown.
5886 (constraint_manager::get_or_add_equiv_class): Likewise.
5887 * program-state.cc (sm_state_map::set_state): Likewise.
5888 (sm_state_map::impl_set_state): Add assertion.
5889 * region-model-manager.cc
5890 (region_model_manager::maybe_fold_unaryop): Handle poisoned
5892 (region_model_manager::maybe_fold_binop): Move handling of unknown
5894 (region_model_manager::get_or_create_binop): ...to here, and
5895 generalize to use can_have_associated_state_p.
5896 (region_model_manager::maybe_fold_sub_svalue): Use
5897 can_have_associated_state_p rather than testing for unknown.
5898 (region_model_manager::maybe_fold_repeated_svalue): Use unknown
5899 when the size or repeated value is "unknown"/"poisoned".
5900 * region-model.cc (region_model::purge_state_involving): Reject
5901 attempts to purge unknown/poisoned svalues, as these svalues
5902 should not have state associated with them.
5903 * svalue.cc (sub_svalue::sub_svalue): Assert that we're building
5904 on top of an svalue with can_have_associated_state_p.
5905 (repeated_svalue::repeated_svalue): Likewise.
5906 (bits_within_svalue::bits_within_svalue): Likewise.
5907 * svalue.h (svalue::can_have_associated_state_p): New.
5908 (unknown_svalue::can_have_associated_state_p): New.
5909 (poisoned_svalue::can_have_associated_state_p): New.
5910 (unaryop_svalue::unaryop_svalue): Assert that we're building on
5911 top of an svalue with can_have_associated_state_p.
5912 (binop_svalue::binop_svalue): Likewise.
5913 (widening_svalue::widening_svalue): Likewise.
5915 2021-07-16 David Malcolm <dmalcolm@redhat.com>
5917 * analyzer.h (enum access_direction): New.
5918 * engine.cc (exploded_node::on_longjmp): Update for new param of
5920 * program-state.cc (program_state::prune_for_point): Likewise.
5921 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
5922 Replace call to check_for_writable_region with call to
5923 check_region_for_write.
5924 (region_model::impl_call_memset): Likewise.
5925 (region_model::impl_call_strcpy): Likewise.
5926 * region-model-reachability.cc (reachable_regions::add): Update
5927 for new param of get_store_value.
5928 * region-model.cc (region_model::get_rvalue_1): Likewise, also for
5929 get_rvalue_for_bits.
5930 (region_model::get_store_value): Add ctxt param and use it to call
5931 check_region_for_read.
5932 (region_model::get_rvalue_for_bits): Add ctxt param and use it to
5933 call get_store_value.
5934 (region_model::check_region_access): New.
5935 (region_model::check_region_for_write): New.
5936 (region_model::check_region_for_read): New.
5937 (region_model::set_value): Update comment. Replace call to
5938 check_for_writable_region with call to check_region_for_write.
5939 * region-model.h (region_model::get_rvalue_for_bits): Add ctxt
5941 (region_model::get_store_value): Add ctxt param.
5942 (region_model::check_region_access): New decl.
5943 (region_model::check_region_for_write): New decl.
5944 (region_model::check_region_for_read): New decl.
5945 * region.cc (region_model::copy_region): Update call to
5947 * svalue.cc (initial_svalue::implicitly_live_p): Likewise.
5949 2021-07-16 David Malcolm <dmalcolm@redhat.com>
5951 * engine.cc (exploded_node::on_stmt_pre): Handle
5952 __analyzer_dump_state.
5953 * program-state.cc (extrinsic_state::get_sm_idx_by_name): New.
5954 (program_state::impl_call_analyzer_dump_state): New.
5955 * program-state.h (extrinsic_state::get_sm_idx_by_name): New decl.
5956 (program_state::impl_call_analyzer_dump_state): New decl.
5957 * region-model-impl-calls.cc
5958 (call_details::get_arg_string_literal): New.
5959 * region-model.h (call_details::get_arg_string_literal): New decl.
5961 2021-07-16 David Malcolm <dmalcolm@redhat.com>
5963 * program-state.cc (program_state::detect_leaks): Simplify using
5964 svalue::maybe_get_region.
5965 * region-model-impl-calls.cc (region_model::impl_call_fgets): Likewise.
5966 (region_model::impl_call_fread): Likewise.
5967 (region_model::impl_call_free): Likewise.
5968 (region_model::impl_call_operator_delete): Likewise.
5969 * region-model.cc (selftest::test_stack_frames): Likewise.
5970 (selftest::test_state_merging): Likewise.
5971 * svalue.cc (svalue::maybe_get_region): New.
5972 * svalue.h (svalue::maybe_get_region): New decl.
5974 2021-07-15 David Malcolm <dmalcolm@redhat.com>
5976 * svalue.h (is_a_helper <placeholder_svalue *>::test): Make
5977 param and template param const.
5978 (is_a_helper <widening_svalue *>::test): Likewise.
5979 (is_a_helper <compound_svalue *>::test): Likewise.
5980 (is_a_helper <conjured_svalue *>::test): Likewise.
5982 2021-07-15 David Malcolm <dmalcolm@redhat.com>
5987 * analyzer.cc (maybe_reconstruct_from_def_stmt): Split out
5988 GIMPLE_ASSIGN case into...
5989 (get_diagnostic_tree_for_gassign_1): New.
5990 (get_diagnostic_tree_for_gassign): New.
5991 * analyzer.h (get_diagnostic_tree_for_gassign): New decl.
5992 * analyzer.opt (Wanalyzer-write-to-string-literal): New.
5993 * constraint-manager.cc (class svalue_purger): New.
5994 (constraint_manager::purge_state_involving): New.
5995 * constraint-manager.h
5996 (constraint_manager::purge_state_involving): New.
5997 * diagnostic-manager.cc (saved_diagnostic::supercedes_p): New.
5998 (dedupe_winners::handle_interactions): New.
5999 (diagnostic_manager::emit_saved_diagnostics): Call it.
6000 * diagnostic-manager.h (saved_diagnostic::supercedes_p): New decl.
6001 * engine.cc (impl_region_model_context::warn): Convert return type
6002 to bool. Return false if the diagnostic isn't saved.
6003 (impl_region_model_context::purge_state_involving): New.
6004 (impl_sm_context::get_state): Use NULL ctxt when querying old
6006 (impl_sm_context::set_next_state): Use new sval when querying old
6008 (class dump_path_diagnostic): Move to region-model.cc
6009 (exploded_node::on_stmt): Move to on_stmt_pre and on_stmt_post.
6010 Remove call to purge_state_involving.
6011 (exploded_node::on_stmt_pre): New, based on the above. Move most
6012 of it to region_model::on_stmt_pre.
6013 (exploded_node::on_stmt_post): Likewise, moving to
6014 region_model::on_stmt_post.
6015 (class stale_jmp_buf): Fix parent class to use curiously recurring
6017 (feasibility_state::maybe_update_for_edge): Call on_call_pre and
6018 on_call_post on gcalls.
6019 * exploded-graph.h (impl_region_model_context::warn): Return bool.
6020 (impl_region_model_context::purge_state_involving): New decl.
6021 (exploded_node::on_stmt_pre): New decl.
6022 (exploded_node::on_stmt_post): New decl.
6023 * pending-diagnostic.h (pending_diagnostic::use_of_uninit_p): New.
6024 (pending_diagnostic::supercedes_p): New.
6025 * program-state.cc (sm_state_map::get_state): Inherit state for
6026 conjured_svalue as well as initial_svalue.
6027 (sm_state_map::purge_state_involving): Also support SK_CONJURED.
6028 * region-model-impl-calls.cc (call_details::get_uncertainty):
6029 Handle m_ctxt being NULL.
6030 (call_details::get_or_create_conjured_svalue): New.
6031 (region_model::impl_call_fgets): New.
6032 (region_model::impl_call_fread): New.
6033 * region-model-manager.cc
6034 (region_model_manager::get_or_create_initial_value): Return an
6035 uninitialized poisoned value for regions that can't have initial
6037 * region-model-reachability.cc
6038 (reachable_regions::mark_escaped_clusters): Handle ctxt being
6040 * region-model.cc (region_to_value_map::purge_state_involving): New.
6041 (poisoned_value_diagnostic::use_of_uninit_p): New.
6042 (poisoned_value_diagnostic::emit): Handle POISON_KIND_UNINIT.
6043 (poisoned_value_diagnostic::describe_final_event): Likewise.
6044 (region_model::check_for_poison): New.
6045 (region_model::on_assignment): Call it.
6046 (class dump_path_diagnostic): Move here from engine.cc.
6047 (region_model::on_stmt_pre): New, based on exploded_node::on_stmt.
6048 (region_model::on_call_pre): Move the setting of the LHS to a
6049 conjured svalue to before the checks for specific functions.
6050 Handle "fgets", "fgets_unlocked", and "fread".
6051 (region_model::purge_state_involving): New.
6052 (region_model::handle_unrecognized_call): Handle ctxt being NULL.
6053 (region_model::get_rvalue): Call check_for_poison.
6054 (selftest::test_stack_frames): Use NULL for context when getting
6055 uninitialized rvalue.
6056 (selftest::test_alloca): Likewise.
6057 * region-model.h (region_to_value_map::purge_state_involving): New
6059 (call_details::get_or_create_conjured_svalue): New decl.
6060 (region_model::on_stmt_pre): New decl.
6061 (region_model::purge_state_involving): New decl.
6062 (region_model::impl_call_fgets): New decl.
6063 (region_model::impl_call_fread): New decl.
6064 (region_model::check_for_poison): New decl.
6065 (region_model_context::warn): Return bool.
6066 (region_model_context::purge_state_involving): New.
6067 (noop_region_model_context::warn): Return bool.
6068 (noop_region_model_context::purge_state_involving): New.
6069 (test_region_model_context:: warn): Return bool.
6070 * region.cc (region::get_memory_space): New.
6071 (region::can_have_initial_svalue_p): New.
6072 (region::involves_p): New.
6073 * region.h (enum memory_space): New.
6074 (region::get_memory_space): New decl.
6075 (region::can_have_initial_svalue_p): New decl.
6076 (region::involves_p): New decl.
6077 * sm-malloc.cc (use_after_free::supercedes_p): New.
6078 * store.cc (binding_cluster::purge_state_involving): New.
6079 (store::purge_state_involving): New.
6080 * store.h (class symbolic_binding): New forward decl.
6081 (binding_key::dyn_cast_symbolic_binding): New.
6082 (symbolic_binding::dyn_cast_symbolic_binding): New.
6083 (binding_cluster::purge_state_involving): New.
6084 (store::purge_state_involving): New.
6085 * svalue.cc (svalue::can_merge_p): Reject attempts to merge
6086 poisoned svalues with other svalues, so that we identify
6087 paths in which a variable is conditionally uninitialized.
6088 (involvement_visitor::visit_conjured_svalue): New.
6089 (svalue::involves_p): Also handle SK_CONJURED.
6090 (poison_kind_to_str): Handle POISON_KIND_UNINIT.
6091 (poisoned_svalue::maybe_fold_bits_within): New.
6092 * svalue.h (enum poison_kind): Add POISON_KIND_UNINIT.
6093 (poisoned_svalue::maybe_fold_bits_within): New decl.
6095 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6097 * analyzer.opt (fdump-analyzer-exploded-paths): New.
6098 * diagnostic-manager.cc
6099 (diagnostic_manager::emit_saved_diagnostic): Implement it.
6100 * engine.cc (exploded_path::dump_to_pp): Add ext_state param and
6101 use it to dump states if non-NULL.
6102 (exploded_path::dump): Likewise.
6103 (exploded_path::dump_to_file): New.
6104 * exploded-graph.h (exploded_path::dump_to_pp): Add ext_state
6106 (exploded_path::dump): Likewise.
6107 (exploded_path::dump): Likewise.
6108 (exploded_path::dump_to_file): New.
6110 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6112 * analyzer.cc (fixup_tree_for_diagnostic_1): Use DECL_DEBUG_EXPR
6114 * engine.cc (readability): Likewise.
6116 2021-07-15 David Malcolm <dmalcolm@redhat.com>
6118 * state-purge.cc (self_referential_phi_p): New.
6119 (state_purge_per_ssa_name::process_point): Don't purge an SSA name
6120 at its def-stmt if the def-stmt is self-referential.
6122 2021-07-07 David Malcolm <dmalcolm@redhat.com>
6124 * diagnostic-manager.cc (null_assignment_sm_context::get_state):
6126 (null_assignment_sm_context::set_next_state): New overload.
6127 (null_assignment_sm_context::get_diagnostic_tree): New.
6128 * engine.cc (impl_sm_context::get_state): New overload.
6129 (impl_sm_context::set_next_state): New overload.
6130 (impl_sm_context::get_diagnostic_tree): New overload.
6131 (impl_region_model_context::on_condition): Convert params from
6132 tree to const svalue *.
6133 * exploded-graph.h (impl_region_model_context::on_condition):
6135 * region-model.cc (region_model::on_call_pre): Move handling of
6136 internal calls to before checking for get_fndecl_for_call.
6137 (region_model::add_constraints_from_binop): New.
6138 (region_model::add_constraint): Split out into a new overload
6139 working on const svalue * rather than tree. Call
6140 add_constraints_from_binop. Drop call to
6141 add_any_constraints_from_ssa_def_stmt.
6142 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6143 (region_model::add_any_constraints_from_gassign): Delete.
6144 (region_model::add_any_constraints_from_gcall): Delete.
6146 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
6147 (region_model::add_any_constraints_from_gassign): Delete.
6148 (region_model::add_any_constraints_from_gcall): Delete.
6149 (region_model::add_constraint): Add overload decl.
6150 (region_model::add_constraints_from_binop): New decl.
6151 (region_model_context::on_condition): Convert params from tree to
6153 (noop_region_model_context::on_condition): Likewise.
6154 * sm-file.cc (fileptr_state_machine::condition): Likewise.
6155 * sm-malloc.cc (malloc_state_machine::on_condition): Likewise.
6156 * sm-pattern-test.cc: Include tristate.h, selftest.h,
6157 analyzer/call-string.h, analyzer/program-point.h,
6158 analyzer/store.h, and analyzer/region-model.h.
6159 (pattern_test_state_machine::on_condition): Convert params from tree to
6161 * sm-sensitive.cc (sensitive_state_machine::on_condition): Delete.
6162 * sm-signal.cc (signal_state_machine::on_condition): Delete.
6163 * sm-taint.cc (taint_state_machine::on_condition): Convert params
6164 from tree to const svalue *.
6165 * sm.cc: Include tristate.h, selftest.h, analyzer/call-string.h,
6166 analyzer/program-point.h, analyzer/store.h, and
6167 analyzer/region-model.h.
6168 (any_pointer_p): Add overload taking const svalue *sval.
6169 * sm.h (any_pointer_p): Add overload taking const svalue *sval.
6170 (state_machine::on_condition): Convert params from tree to
6171 const svalue *. Provide no-op default implementation.
6172 (sm_context::get_state): Add overload taking const svalue *sval.
6173 (sm_context::set_next_state): Likewise.
6174 (sm_context::on_transition): Likewise.
6175 (sm_context::get_diagnostic_tree): Likewise.
6176 * svalue.cc (svalue::all_zeroes_p): New.
6177 (constant_svalue::all_zeroes_p): New.
6178 (repeated_svalue::all_zeroes_p): Convert to vfunc.
6179 * svalue.h (svalue::all_zeroes_p): New decl.
6180 (constant_svalue::all_zeroes_p): New decl.
6181 (repeated_svalue::all_zeroes_p): Convert decl to vfunc.
6183 2021-06-30 David Malcolm <dmalcolm@redhat.com>
6186 * analyzer.h (class repeated_svalue): New forward decl.
6187 (class bits_within_svalue): New forward decl.
6188 (class sized_region): New forward decl.
6189 (get_field_at_bit_offset): New forward decl.
6190 * engine.cc (exploded_graph::get_or_create_node): Validate the
6192 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
6193 Validate the states at each stage.
6194 * program-state.cc (program_state::validate): Validate
6196 * region-model-impl-calls.cc (region_model::impl_call_memset):
6197 Replace special-case logic for handling constant sizes with
6198 a call to fill_region of a sized_region with the given fill value.
6199 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
6201 (region_model_manager::maybe_fold_sub_svalue): Fold element-based
6202 subregions of an initial value into initial values of an element.
6203 Fold subvalues of repeated svalues.
6204 (region_model_manager::maybe_fold_repeated_svalue): New.
6205 (region_model_manager::get_or_create_repeated_svalue): New.
6206 (get_bit_range_for_field): New.
6207 (get_byte_range_for_field): New.
6208 (get_field_at_byte_range): New.
6209 (region_model_manager::maybe_fold_bits_within_svalue): New.
6210 (region_model_manager::get_or_create_bits_within): New.
6211 (region_model_manager::get_sized_region): New.
6212 (region_model_manager::log_stats): Update for addition of
6213 m_repeated_values_map, m_bits_within_values_map, and
6215 * region-model.cc (region_model::validate): New.
6216 (region_model::on_assignment): Drop enum binding_kind.
6217 (region_model::get_initial_value_for_global): Likewise.
6218 (region_model::get_rvalue_for_bits): Replace body with call to
6219 get_or_create_bits_within.
6220 (region_model::get_capacity): Handle RK_SIZED.
6221 (region_model::set_value): Drop enum binding_kind.
6222 (region_model::fill_region): New.
6223 (region_model::get_representative_path_var_1): Handle RK_SIZED.
6224 * region-model.h (visitor::visit_repeated_svalue): New.
6225 (visitor::visit_bits_within_svalue): New.
6226 (region_model_manager::get_or_create_repeated_svalue): New decl.
6227 (region_model_manager::get_or_create_bits_within): New decl.
6228 (region_model_manager::get_sized_region): New decl.
6229 (region_model_manager::maybe_fold_repeated_svalue): New decl.
6230 (region_model_manager::maybe_fold_bits_within_svalue): New decl.
6231 (region_model_manager::repeated_values_map_t): New typedef.
6232 (region_model_manager::m_repeated_values_map): New field.
6233 (region_model_manager::bits_within_values_map_t): New typedef.
6234 (region_model_manager::m_bits_within_values_map): New field.
6235 (region_model_manager::m_sized_regions): New field.
6236 (region_model::fill_region): New decl.
6237 * region.cc (region::get_base_region): Handle RK_SIZED.
6238 (region::base_region_p): Likewise.
6239 (region::get_byte_size_sval): New.
6240 (get_field_at_bit_offset): Make non-static.
6241 (region::calc_offset): Move implementation of cases to
6242 get_relative_concrete_offset vfunc implementations. Handle
6244 (region::get_relative_concrete_offset): New.
6245 (decl_region::get_svalue_for_initializer): Drop enum binding_kind.
6246 (field_region::get_relative_concrete_offset): New, from
6247 region::calc_offset.
6248 (element_region::get_relative_concrete_offset): Likewise.
6249 (offset_region::get_relative_concrete_offset): Likewise.
6250 (sized_region::accept): New.
6251 (sized_region::dump_to_pp): New.
6252 (sized_region::get_byte_size): New.
6253 (sized_region::get_bit_size): New.
6254 * region.h (enum region_kind): Add RK_SIZED.
6255 (region::dyn_cast_sized_region): New.
6256 (region::get_byte_size): Make virtual.
6257 (region::get_bit_size): Likewise.
6258 (region::get_byte_size_sval): New decl.
6259 (region::get_relative_concrete_offset): New decl.
6260 (field_region::get_relative_concrete_offset): New decl.
6261 (element_region::get_relative_concrete_offset): Likewise.
6262 (offset_region::get_relative_concrete_offset): Likewise.
6263 (class sized_region): New.
6264 * store.cc (binding_kind_to_string): Delete.
6265 (binding_key::make): Drop enum binding_kind.
6266 (binding_key::dump_to_pp): Delete.
6267 (binding_key::cmp_ptrs): Drop enum binding_kind.
6268 (bit_range::contains_p): New.
6269 (byte_range::dump): New.
6270 (byte_range::contains_p): New.
6271 (byte_range::cmp): New.
6272 (concrete_binding::dump_to_pp): Drop enum binding_kind.
6273 (concrete_binding::cmp_ptr_ptr): Likewise.
6274 (symbolic_binding::dump_to_pp): Likewise.
6275 (symbolic_binding::cmp_ptr_ptr): Likewise.
6276 (binding_map::apply_ctor_val_to_range): Likewise.
6277 (binding_map::apply_ctor_pair_to_child_region): Likewise.
6278 (binding_map::get_overlapping_bindings): New.
6279 (binding_map::remove_overlapping_bindings): New.
6280 (binding_cluster::validate): New.
6281 (binding_cluster::bind): Drop enum binding_kind.
6282 (binding_cluster::bind_compound_sval): Likewise.
6283 (binding_cluster::purge_region): Likewise.
6284 (binding_cluster::zero_fill_region): Reimplement in terms of...
6285 (binding_cluster::fill_region): New.
6286 (binding_cluster::mark_region_as_unknown): Drop enum binding_kind.
6287 (binding_cluster::get_binding): Likewise.
6288 (binding_cluster::get_binding_recursive): Likewise.
6289 (binding_cluster::get_any_binding): Likewise.
6290 (binding_cluster::maybe_get_compound_binding): Reimplement.
6291 (binding_cluster::get_overlapping_bindings): Delete.
6292 (binding_cluster::remove_overlapping_bindings): Reimplement in
6293 terms of binding_map::remove_overlapping_bindings.
6294 (binding_cluster::can_merge_p): Update for removal of
6296 (binding_cluster::on_unknown_fncall): Drop enum binding_kind.
6297 (binding_cluster::maybe_get_simple_value): Likewise.
6298 (store_manager::get_concrete_binding): Likewise.
6299 (store_manager::get_symbolic_binding): Likewise.
6300 (store::validate): New.
6301 (store::set_value): Drop enum binding_kind.
6302 (store::zero_fill_region): Reimplement in terms of...
6303 (store::fill_region): New.
6304 (selftest::test_binding_key_overlap): Drop enum binding_kind.
6305 * store.h (enum binding_kind): Delete.
6306 (binding_kind_to_string): Delete decl.
6307 (binding_key::make): Drop enum binding_kind.
6308 (binding_key::dump_to_pp): Make pure virtual.
6309 (binding_key::get_kind): Delete.
6310 (binding_key::mark_deleted): Delete.
6311 (binding_key::mark_empty): Delete.
6312 (binding_key::is_deleted): Delete.
6313 (binding_key::is_empty): Delete.
6314 (binding_key::binding_key): Delete.
6315 (binding_key::impl_hash): Delete.
6316 (binding_key::impl_eq): Delete.
6317 (binding_key::m_kind): Delete.
6318 (bit_range::get_last_bit_offset): New.
6319 (bit_range::contains_p): New.
6320 (byte_range::contains_p): New.
6321 (byte_range::operator==): New.
6322 (byte_range::get_start_byte_offset): New.
6323 (byte_range::get_next_byte_offset): New.
6324 (byte_range::get_last_byte_offset): New.
6325 (byte_range::as_bit_range): New.
6326 (byte_range::cmp): New.
6327 (concrete_binding::concrete_binding): Drop enum binding_kind.
6328 (concrete_binding::hash): Likewise.
6329 (concrete_binding::operator==): Likewise.
6330 (concrete_binding::mark_deleted): New.
6331 (concrete_binding::mark_empty): New.
6332 (concrete_binding::is_deleted): New.
6333 (concrete_binding::is_empty): New.
6334 (default_hash_traits<ana::concrete_binding>::empty_zero_p): Make false.
6335 (symbolic_binding::symbolic_binding): Drop enum binding_kind.
6336 (symbolic_binding::hash): Likewise.
6337 (symbolic_binding::operator==): Likewise.
6338 (symbolic_binding::mark_deleted): New.
6339 (symbolic_binding::mark_empty): New.
6340 (symbolic_binding::is_deleted): New.
6341 (symbolic_binding::is_empty): New.
6342 (binding_map::remove_overlapping_bindings): New decl.
6343 (binding_map::get_overlapping_bindings): New decl.
6344 (binding_cluster::validate): New decl.
6345 (binding_cluster::bind): Drop enum binding_kind.
6346 (binding_cluster::fill_region): New decl.
6347 (binding_cluster::get_binding): Drop enum binding_kind.
6348 (binding_cluster::get_binding_recursive): Likewise.
6349 (binding_cluster::get_overlapping_bindings): Delete.
6350 (store::validate): New decl.
6351 (store::set_value): Drop enum binding_kind.
6352 (store::fill_region): New decl.
6353 (store_manager::get_concrete_binding): Drop enum binding_kind.
6354 (store_manager::get_symbolic_binding): Likewise.
6355 * svalue.cc (svalue::cmp_ptr): Handle SK_REPEATED and
6357 (svalue::extract_bit_range): New.
6358 (svalue::maybe_fold_bits_within): New.
6359 (constant_svalue::maybe_fold_bits_within): New.
6360 (unknown_svalue::maybe_fold_bits_within): New.
6361 (unaryop_svalue::maybe_fold_bits_within): New.
6362 (repeated_svalue::repeated_svalue): New.
6363 (repeated_svalue::dump_to_pp): New.
6364 (repeated_svalue::accept): New.
6365 (repeated_svalue::all_zeroes_p): New.
6366 (repeated_svalue::maybe_fold_bits_within): New.
6367 (bits_within_svalue::bits_within_svalue): New.
6368 (bits_within_svalue::dump_to_pp): New.
6369 (bits_within_svalue::maybe_fold_bits_within): New.
6370 (bits_within_svalue::accept): New.
6371 (bits_within_svalue::implicitly_live_p): New.
6372 (compound_svalue::maybe_fold_bits_within): New.
6373 * svalue.h (enum svalue_kind): Add SK_REPEATED and SK_BITS_WITHIN.
6374 (svalue::dyn_cast_repeated_svalue): New.
6375 (svalue::dyn_cast_bits_within_svalue): New.
6376 (svalue::extract_bit_range): New decl.
6377 (svalue::maybe_fold_bits_within): New vfunc decl.
6378 (region_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6379 (region_svalue::key_t::is_empty): Likewise.
6380 (default_hash_traits<region_svalue::key_t>::empty_zero_p): Make false.
6381 (constant_svalue::maybe_fold_bits_within): New.
6382 (unknown_svalue::maybe_fold_bits_within): New.
6383 (poisoned_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6384 (poisoned_svalue::key_t::is_empty): Likewise.
6385 (default_hash_traits<poisoned_svalue::key_t>::empty_zero_p): Make
6387 (setjmp_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6388 (setjmp_svalue::key_t::is_empty): Likewise.
6389 (default_hash_traits<setjmp_svalue::key_t>::empty_zero_p): Make
6391 (unaryop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6392 (unaryop_svalue::key_t::is_empty): Likewise.
6393 (unaryop_svalue::maybe_fold_bits_within): New.
6394 (default_hash_traits<unaryop_svalue::key_t>::empty_zero_p): Make
6396 (binop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6397 (binop_svalue::key_t::is_empty): Likewise.
6398 (default_hash_traits<binop_svalue::key_t>::empty_zero_p): Make
6400 (sub_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6401 (sub_svalue::key_t::is_empty): Likewise.
6402 (default_hash_traits<sub_svalue::key_t>::empty_zero_p): Make
6404 (class repeated_svalue): New.
6405 (is_a_helper <const repeated_svalue *>::test): New.
6406 (struct default_hash_traits<repeated_svalue::key_t>): New.
6407 (class bits_within_svalue): New.
6408 (is_a_helper <const bits_within_svalue *>::test): New.
6409 (struct default_hash_traits<bits_within_svalue::key_t>): New.
6410 (widening_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6411 (widening_svalue::key_t::is_empty): Likewise.
6412 (default_hash_traits<widening_svalue::key_t>::empty_zero_p): Make
6414 (compound_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
6415 (compound_svalue::key_t::is_empty): Likewise.
6416 (compound_svalue::maybe_fold_bits_within): New.
6417 (default_hash_traits<compound_svalue::key_t>::empty_zero_p): Make
6420 2021-06-28 David Malcolm <dmalcolm@redhat.com>
6422 * analyzer.h (byte_offset_t): New typedef.
6423 * store.cc (bit_range::dump_to_pp): Dump as a byte range if
6425 (bit_range::as_byte_range): New.
6426 (byte_range::dump_to_pp): New.
6427 * store.h (class byte_range): New forward decl.
6428 (struct bit_range): Add comment.
6429 (bit_range::as_byte_range): New decl.
6430 (struct byte_range): New.
6432 2021-06-22 David Malcolm <dmalcolm@redhat.com>
6435 * region-model.cc (compat_types_p): New function.
6436 (region_model::create_region_for_heap_alloc): Convert assertion to
6438 (region_model::create_region_for_alloca): Likewise.
6440 2021-06-18 David Malcolm <dmalcolm@redhat.com>
6442 * store.cc (binding_cluster::get_any_binding): Make symbolic reads
6443 from a cluster with concrete bindings return unknown.
6445 2021-06-18 David Malcolm <dmalcolm@redhat.com>
6447 * region-model-manager.cc
6448 (region_model_manager::get_or_create_int_cst): New.
6449 (region_model_manager::maybe_undo_optimize_bit_field_compare): Use
6450 it to simplify away a local tree.
6451 * region-model.cc (region_model::on_setjmp): Likewise.
6452 (region_model::on_longjmp): Likewise.
6453 * region-model.h (region_model_manager::get_or_create_int_cst):
6455 * store.cc (binding_cluster::zero_fill_region): Use it to simplify
6458 2021-06-18 David Malcolm <dmalcolm@redhat.com>
6460 * checker-path.cc (class custom_event): Make abstract to allow for
6461 custom vfuncs, splitting existing implementation into...
6462 (class precanned_custom_event): New subclass.
6463 (custom_event::get_desc): Move to...
6464 (precanned_custom_event::get_desc): ...subclass.
6465 * checker-path.h (class custom_event): Make abstract to allow for
6466 custom vfuncs, splitting existing implementation into...
6467 (class precanned_custom_event): New subclass.
6468 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
6469 Use precanned_custom_event.
6471 (stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise.
6472 * sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path):
6475 2021-06-15 David Malcolm <dmalcolm@redhat.com>
6479 * engine.cc: Include "target.h".
6480 (impl_run_checkers): Log BITS_BIG_ENDIAN, BYTES_BIG_ENDIAN, and
6482 * region-model-manager.cc
6483 (region_model_manager::maybe_fold_binop): Move support for masking
6484 via ARG0 & CST into...
6485 (region_model_manager::maybe_undo_optimize_bit_field_compare):
6486 ...this new function. Flatten by converting from nested
6487 conditionals to a series of early return statements to reject
6488 failures. Reject if type is not unsigned_char_type_node.
6489 Handle BYTES_BIG_ENDIAN when determining which bits are bound
6492 (region_model_manager::maybe_undo_optimize_bit_field_compare):
6494 * store.cc (bit_range::dump): New function.
6495 * store.h (bit_range::dump): New decl.
6497 2021-06-15 David Malcolm <dmalcolm@redhat.com>
6499 * engine.cc (exploded_node::on_stmt): Handle __analyzer_dump_capacity.
6500 (exploded_node::on_stmt): Drop m_sm_changes from on_stmt_flags.
6501 (state_change_requires_new_enode_p): New function...
6502 (exploded_graph::process_node): Call it, rather than querying
6503 flags.m_sm_changes, so that dynamic-extent differences can also
6504 trigger the splitting of nodes.
6505 * exploded-graph.h (struct on_stmt_flags): Drop field m_sm_changes.
6506 * program-state.cc (program_state::detect_leaks): Purge dead
6507 heap-allocated regions from dynamic extents.
6508 (selftest::test_program_state_1): Fix type of "size_in_bytes".
6509 (selftest::test_program_state_merging): Likewise.
6510 * region-model-impl-calls.cc
6511 (region_model::impl_call_analyzer_dump_capacity): New.
6512 (region_model::impl_call_free): Remove dynamic extents from the
6514 * region-model-reachability.h
6515 (reachable_regions::begin_mutable_base_regs): New.
6516 (reachable_regions::end_mutable_base_regs): New.
6517 * region-model.cc: Include "tree-object-size.h".
6518 (region_model::region_model): Support new field m_dynamic_extents.
6519 (region_model::operator=): Likewise.
6520 (region_model::operator==): Likewise.
6521 (region_model::dump_to_pp): Dump sizes of dynamic regions.
6522 (region_model::handle_unrecognized_call): Purge dynamic extents
6523 from any regions that have escaped mutably:.
6524 (region_model::get_capacity): New function.
6525 (region_model::add_constraint): Unset dynamic extents when a
6526 heap-allocated region's address is NULL.
6527 (region_model::unbind_region_and_descendents): Purge dynamic
6528 extents of unbound regions.
6529 (region_model::can_merge_with_p): Call
6530 m_dynamic_extents.can_merge_with_p.
6531 (region_model::create_region_for_heap_alloc): Assert that
6532 size_in_bytes's type is compatible with size_type_node. Update
6533 for renaming of record_dynamic_extents to set_dynamic_extents.
6534 (region_model::create_region_for_alloca): Likewise.
6535 (region_model::record_dynamic_extents): Rename to...
6536 (region_model::set_dynamic_extents): ...this. Assert that
6537 size_in_bytes's type is compatible with size_type_node. Add it
6538 to the m_dynamic_extents map.
6539 (region_model::get_dynamic_extents): New.
6540 (region_model::unset_dynamic_extents): New.
6541 (selftest::test_state_merging): Fix type of "size".
6542 (selftest::test_malloc_constraints): Likewise.
6543 (selftest::test_malloc): Verify dynamic extents.
6544 (selftest::test_alloca): Likewise.
6545 * region-model.h (region_to_value_map::is_empty): New.
6546 (region_model::dynamic_extents_t): New typedef.
6547 (region_model::impl_call_analyzer_dump_capacity): New decl.
6548 (region_model::get_dynamic_extents): New function.
6549 (region_model::get_dynamic_extents): New decl.
6550 (region_model::set_dynamic_extents): New decl.
6551 (region_model::unset_dynamic_extents): New decl.
6552 (region_model::get_capacity): New decl.
6553 (region_model::record_dynamic_extents): Rename to set_dynamic_extents.
6554 (region_model::m_dynamic_extents): New field.
6556 2021-06-15 David Malcolm <dmalcolm@redhat.com>
6558 * region-model.cc (region_to_value_map::operator=): New.
6559 (region_to_value_map::operator==): New.
6560 (region_to_value_map::dump_to_pp): New.
6561 (region_to_value_map::dump): New.
6562 (region_to_value_map::can_merge_with_p): New.
6563 * region-model.h (class region_to_value_map): New class.
6565 2021-06-13 Trevor Saunders <tbsaunde@tbsaunde.org>
6567 * call-string.cc (call_string::call_string): Use range based for
6568 to iterate over vec<>.
6569 (call_string::to_json): Likewise.
6570 (call_string::hash): Likewise.
6571 (call_string::calc_recursion_depth): Likewise.
6572 * checker-path.cc (checker_path::fixup_locations): Likewise.
6573 * constraint-manager.cc (equiv_class::equiv_class): Likewise.
6574 (equiv_class::to_json): Likewise.
6575 (equiv_class::hash): Likewise.
6576 (constraint_manager::to_json): Likewise.
6577 * engine.cc (impl_region_model_context::on_svalue_leak):
6579 (on_liveness_change): Likewise.
6580 (impl_region_model_context::on_unknown_change): Likewise.
6581 * program-state.cc (sm_state_map::set_state): Likewise.
6582 * region-model.cc (test_canonicalization_4): Likewise.
6584 2021-06-11 David Malcolm <dmalcolm@redhat.com>
6586 * engine.cc (worklist::key_t::cmp): Move sort by call_string to
6589 2021-06-09 David Malcolm <dmalcolm@redhat.com>
6591 * region-model.cc (region_model::get_lvalue_1): Make const.
6592 (region_model::get_lvalue): Likewise.
6593 (region_model::get_rvalue_1): Likewise.
6594 (region_model::get_rvalue): Likewise.
6595 (region_model::deref_rvalue): Likewise.
6596 (region_model::get_rvalue_for_bits): Likewise.
6597 * region-model.h (region_model::get_lvalue): Likewise.
6598 (region_model::get_rvalue): Likewise.
6599 (region_model::deref_rvalue): Likewise.
6600 (region_model::get_rvalue_for_bits): Likewise.
6601 (region_model::get_lvalue_1): Likewise.
6602 (region_model::get_rvalue_1): Likewise.
6604 2021-06-08 David Malcolm <dmalcolm@redhat.com>
6607 * region-model-manager.cc
6608 (region_model_manager::maybe_fold_binop): Add support for folding
6609 BIT_AND_EXPR of compound_svalue and a mask constant.
6610 * region-model.cc (region_model::get_rvalue_1): Implement
6611 BIT_FIELD_REF in terms of...
6612 (region_model::get_rvalue_for_bits): New function.
6613 * region-model.h (region_model::get_rvalue_for_bits): New decl.
6614 * store.cc (bit_range::from_mask): New function.
6615 (selftest::test_bit_range_intersects_p): New selftest.
6616 (selftest::assert_bit_range_from_mask_eq): New.
6617 (ASSERT_BIT_RANGE_FROM_MASK_EQ): New macro.
6618 (selftest::assert_no_bit_range_from_mask_eq): New.
6619 (ASSERT_NO_BIT_RANGE_FROM_MASK): New macro.
6620 (selftest::test_bit_range_from_mask): New selftest.
6621 (selftest::analyzer_store_cc_tests): Call the new selftests.
6622 * store.h (bit_range::intersects_p): New.
6623 (bit_range::from_mask): New decl.
6624 (concrete_binding::get_bit_range): New accessor.
6625 (store_manager::get_concrete_binding): New overload taking
6628 2021-06-08 David Malcolm <dmalcolm@redhat.com>
6630 * analyzer.h (int_size_in_bits): New decl.
6631 * region.cc (int_size_in_bits): New function.
6632 (region::get_bit_size): Reimplement in terms of the above.
6634 2021-06-08 David Malcolm <dmalcolm@redhat.com>
6636 * store.cc (concrete_binding::dump_to_pp): Move bulk of
6637 implementation to...
6638 (bit_range::dump_to_pp): ...this new function.
6639 (bit_range::cmp): New.
6640 (concrete_binding::overlaps_p): Update for use of bit_range.
6641 (concrete_binding::cmp_ptr_ptr): Likewise.
6642 * store.h (struct bit_range): New.
6643 (class concrete_binding): Replace fields m_start_bit_offset and
6644 m_size_in_bits with new field m_bit_range.
6646 2021-06-08 David Malcolm <dmalcolm@redhat.com>
6648 * svalue.h (conjured_svalue::iterator_t): Delete.
6650 2021-06-03 David Malcolm <dmalcolm@redhat.com>
6652 * store.h (store::get_direct_binding): Remove unused decl.
6653 (store::get_default_binding): Likewise.
6655 2021-06-03 David Malcolm <dmalcolm@redhat.com>
6657 * svalue.cc (poisoned_svalue::dump_to_pp): Dump type.
6658 (compound_svalue::dump_to_pp): Dump any type.
6660 2021-05-18 David Malcolm <dmalcolm@redhat.com>
6663 * sm-malloc.cc: Include "analyzer/function-set.h".
6664 (malloc_state_machine::on_stmt): Call unaffected_by_call_p and
6665 bail on the functions it recognizes.
6666 (malloc_state_machine::unaffected_by_call_p): New.
6668 2021-05-10 Martin Liska <mliska@suse.cz>
6670 * sm-file.cc (is_file_using_fn_p): Use startswith
6671 function instead of strncmp.
6673 2021-05-10 Martin Liska <mliska@suse.cz>
6675 * program-state.cc (program_state::operator=): Remove
6676 __cplusplus >= 201103.
6677 (program_state::program_state): Likewise.
6678 * program-state.h: Likewise.
6679 * region-model.h (class region_model): Remove dead code.
6681 2021-04-24 David Malcolm <dmalcolm@redhat.com>
6684 * sm-malloc.cc (free_of_non_heap::describe_state_change):
6685 Bulletproof against change.m_expr being NULL.
6687 2021-04-13 David Malcolm <dmalcolm@redhat.com>
6690 * supergraph.cc (saved_uids::make_uid_unique): New.
6691 (saved_uids::restore_uids): New.
6692 (supergraph::supergraph): Replace assignments to stmt->uid with
6693 calls to m_stmt_uids.make_uid_unique.
6694 (supergraph::~supergraph): New.
6695 * supergraph.h (class saved_uids): New.
6696 (supergraph::~supergraph): New decl.
6697 (supergraph::m_stmt_uids): New field.
6699 2021-04-10 David Malcolm <dmalcolm@redhat.com>
6702 * region-model.cc (region_model::on_assignment): Avoid NULL
6703 dereference if ctxt is NULL when assigning from a STRING_CST.
6705 2021-04-08 David Malcolm <dmalcolm@redhat.com>
6710 (impl_region_model_context::impl_region_model_context): Add
6711 uncertainty param and use it to initialize m_uncertainty.
6712 (impl_region_model_context::get_uncertainty): New.
6713 (impl_sm_context::get_fndecl_for_call): Add NULL for new
6714 uncertainty param when constructing impl_region_model_context.
6715 (impl_sm_context::get_state): Likewise.
6716 (impl_sm_context::set_next_state): Likewise.
6717 (impl_sm_context::warn): Likewise.
6718 (exploded_node::on_stmt): Add uncertainty param
6719 and use it when constructing impl_region_model_context.
6720 (exploded_node::on_edge): Add uncertainty param and pass
6722 (exploded_node::detect_leaks): Create uncertainty_t and pass to
6723 impl_region_model_context.
6724 (exploded_graph::get_or_create_node): Create uncertainty_t and
6725 pass to prune_for_point.
6726 (maybe_process_run_of_before_supernode_enodes): Create
6727 uncertainty_t and pass to impl_region_model_context.
6728 (exploded_graph::process_node): Create uncertainty_t instances and
6729 pass around as needed.
6731 (impl_region_model_context::impl_region_model_context): Add
6733 (impl_region_model_context::get_uncertainty): New decl.
6734 (impl_region_model_context::m_uncertainty): New field.
6735 (exploded_node::on_stmt): Add uncertainty param.
6736 (exploded_node::on_edge): Likewise.
6737 * program-state.cc (sm_state_map::on_liveness_change): Get
6738 uncertainty from context and use it to unset sm-state from
6739 svalues as appropriate.
6740 (program_state::on_edge): Add uncertainty param and use it when
6741 constructing impl_region_model_context. Fix indentation.
6742 (program_state::prune_for_point): Add uncertainty param and use it
6743 when constructing impl_region_model_context.
6744 (program_state::detect_leaks): Get any uncertainty from ctxt and
6745 use it to get maybe-live svalues for dest_state, rather than
6746 definitely-live ones; use this when determining which svalues
6748 (selftest::test_program_state_merging): Create uncertainty_t and
6749 pass to impl_region_model_context.
6750 * program-state.h (program_state::on_edge): Add uncertainty param.
6751 (program_state::prune_for_point): Likewise.
6752 * region-model-impl-calls.cc (call_details::get_uncertainty): New.
6753 (region_model::impl_call_memcpy): Pass uncertainty to
6754 mark_region_as_unknown call.
6755 (region_model::impl_call_memset): Likewise.
6756 (region_model::impl_call_strcpy): Likewise.
6757 * region-model-reachability.cc (reachable_regions::handle_sval):
6758 Also add sval to m_mutable_svals.
6759 * region-model.cc (region_model::on_assignment): Pass any
6760 uncertainty from ctxt to the store::set_value call.
6761 (region_model::handle_unrecognized_call): Get any uncertainty from
6762 ctxt and use it to record mutable svalues at the unknown call.
6763 (region_model::get_reachable_svalues): Add uncertainty param and
6764 use it to mark any maybe-bound svalues as being reachable.
6765 (region_model::set_value): Pass any uncertainty from ctxt to the
6766 store::set_value call.
6767 (region_model::mark_region_as_unknown): Add uncertainty param and
6768 pass it on to the store::mark_region_as_unknown call.
6769 (region_model::update_for_call_summary): Add uncertainty param and
6770 pass it on to the region_model::mark_region_as_unknown call.
6771 * region-model.h (call_details::get_uncertainty): New decl.
6772 (region_model::get_reachable_svalues): Add uncertainty param.
6773 (region_model::mark_region_as_unknown): Add uncertainty param.
6774 (region_model_context::get_uncertainty): New vfunc.
6775 (noop_region_model_context::get_uncertainty): New vfunc
6777 * store.cc (dump_svalue_set): New.
6778 (uncertainty_t::dump_to_pp): New.
6779 (uncertainty_t::dump): New.
6780 (binding_cluster::clobber_region): Pass NULL for uncertainty to
6781 remove_overlapping_bindings.
6782 (binding_cluster::mark_region_as_unknown): Add uncertainty param
6783 and pass it to remove_overlapping_bindings.
6784 (binding_cluster::remove_overlapping_bindings): Add uncertainty param.
6785 Use it to record any svalues that were in clobbered bindings.
6786 (store::set_value): Add uncertainty param. Pass it to
6787 binding_cluster::mark_region_as_unknown when handling symbolic
6789 (store::mark_region_as_unknown): Add uncertainty param and pass it
6790 to binding_cluster::mark_region_as_unknown.
6791 (store::remove_overlapping_bindings): Add uncertainty param and
6792 pass it to binding_cluster::remove_overlapping_bindings.
6793 * store.h (binding_cluster::mark_region_as_unknown): Add
6795 (binding_cluster::remove_overlapping_bindings): Likewise.
6796 (store::set_value): Likewise.
6797 (store::mark_region_as_unknown): Likewise.
6799 2021-04-05 David Malcolm <dmalcolm@redhat.com>
6802 * analyzer.cc (maybe_reconstruct_from_def_stmt): Fix NULL
6803 dereference on calls with zero arguments.
6804 * sm-malloc.cc (malloc_state_machine::on_stmt): When handling
6805 __attribute__((nonnull)), only call get_diagnostic_tree if the
6806 result will be used.
6808 2021-04-05 David Malcolm <dmalcolm@redhat.com>
6811 * diagnostic-manager.cc
6812 (diagnostic_manager::prune_interproc_events): Use signed integers
6813 when subtracting one from path->num_events ().
6814 (diagnostic_manager::consolidate_conditions): Likewise. Convert
6815 next_idx to a signed int.
6817 2021-04-01 David Malcolm <dmalcolm@redhat.com>
6819 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic): Make
6820 enode param non-constant, and call add_diagnostic on it. Add
6821 enode index to log message.
6822 (diagnostic_manager::add_diagnostic): Make enode param
6824 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
6825 Likewise for both decls.
6827 (impl_region_model_context::impl_region_model_context): Likewise
6829 (impl_sm_context::impl_sm_context): Likewise.
6830 (impl_sm_context::m_enode_for_diag): Likewise.
6831 (exploded_node::dump_dot): Don't pass the diagnostic manager
6832 to dump_saved_diagnostics.
6833 (exploded_node::dump_saved_diagnostics): Drop param. Iterate
6834 directly through all saved diagnostics for the enode, rather
6835 than all saved diagnostics in the diagnostic_manager and
6837 (exploded_node::on_stmt): Make non-const.
6838 (exploded_node::on_edge): Likewise.
6839 (exploded_node::on_longjmp): Likewise.
6840 (exploded_node::detect_leaks): Likewise.
6841 (exploded_graph::get_or_create_node): Make enode_for_diag param
6843 (exploded_graph_annotator::print_enode): Iterate
6844 directly through all saved diagnostics for the enode, rather
6845 than all saved diagnostics in the diagnostic_manager and
6848 (impl_region_model_context::impl_region_model_context): Make
6849 enode_for_diag param non-constant.
6850 (impl_region_model_context::m_enode_for_diag): Likewise.
6851 (exploded_node::dump_saved_diagnostics): Drop param.
6852 (exploded_node::on_stmt): Make non-const.
6853 (exploded_node::on_edge): Likewise.
6854 (exploded_node::on_longjmp): Likewise.
6855 (exploded_node::detect_leaks): Likewise.
6856 (exploded_node::add_diagnostic): New.
6857 (exploded_node::get_num_diagnostics): New.
6858 (exploded_node::get_saved_diagnostic): New.
6859 (exploded_node::m_saved_diagnostics): New.
6860 (exploded_graph::get_or_create_node): Make enode_for_diag param
6862 * feasible-graph.cc (feasible_node::dump_dot): Drop
6863 diagnostic_manager from call to dump_saved_diagnostics.
6864 * program-state.cc (program_state::on_edge): Convert enode param
6865 to non-const pointer.
6866 (program_state::prune_for_point): Likewise for enode_for_diag
6868 * program-state.h (program_state::on_edge): Convert enode param
6869 to non-const pointer.
6870 (program_state::prune_for_point): Likewise for enode_for_diag
6873 2021-03-31 David Malcolm <dmalcolm@redhat.com>
6876 * analyzer.cc (maybe_reconstruct_from_def_stmt): New.
6877 (fixup_tree_for_diagnostic_1): New.
6878 (fixup_tree_for_diagnostic): New.
6879 * analyzer.h (fixup_tree_for_diagnostic): New decl.
6880 * checker-path.cc (call_event::get_desc): Call
6881 fixup_tree_for_diagnostic and use it for the call_with_state call.
6882 (warning_event::get_desc): Likewise for the final_event and
6883 make_label_text calls.
6884 * engine.cc (impl_region_model_context::on_state_leak): Likewise
6885 for the on_leak and add_diagnostic calls.
6886 * region-model.cc (region_model::get_representative_tree):
6887 Likewise for the result.
6889 2021-03-30 David Malcolm <dmalcolm@redhat.com>
6891 * region.h (region::dump_to_pp): Remove old decl.
6893 2021-03-30 David Malcolm <dmalcolm@redhat.com>
6895 * sm-file.cc (fileptr_state_machine::on_stmt): Only call
6896 get_diagnostic_tree if the result will be used.
6897 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
6898 (malloc_state_machine::on_deallocator_call): Likewise.
6899 (malloc_state_machine::on_realloc_call): Likewise.
6900 (malloc_state_machine::on_realloc_call): Likewise.
6902 (sensitive_state_machine::warn_for_any_exposure): Likewise.
6903 * sm-taint.cc (taint_state_machine::on_stmt): Likewise.
6905 2021-03-25 David Malcolm <dmalcolm@redhat.com>
6910 * engine.cc (exploded_node::on_stmt): Clear sm-state involving
6911 an SSA name at the def-stmt of that SSA name.
6912 * program-state.cc (sm_state_map::purge_state_involving): New.
6913 * program-state.h (sm_state_map::purge_state_involving): New decl.
6914 * region-model.cc (selftest::test_involves_p): New.
6915 (selftest::analyzer_region_model_cc_tests): Call it.
6916 * svalue.cc (class involvement_visitor): New class
6917 (svalue::involves_p): New.
6918 * svalue.h (svalue::involves_p): New decl.
6920 2021-03-19 David Malcolm <dmalcolm@redhat.com>
6923 * diagnostic-manager.cc (class epath_finder): Add
6924 DISABLE_COPY_AND_ASSIGN.
6926 2021-03-15 Martin Liska <mliska@suse.cz>
6928 * sm-file.cc (get_file_using_fns): Add missing comma in initializer.
6930 2021-03-11 David Malcolm <dmalcolm@redhat.com>
6933 * analyzer.opt (-param=analyzer-max-infeasible-edges=): New param.
6934 (fdump-analyzer-feasibility): New flag.
6935 * diagnostic-manager.cc: Include "analyzer/trimmed-graph.h" and
6936 "analyzer/feasible-graph.h".
6937 (epath_finder::epath_finder): Convert m_sep to a pointer and
6938 only create it if !flag_analyzer_feasibility.
6939 (epath_finder::~epath_finder): New.
6940 (epath_finder::m_sep): Convert to a pointer.
6941 (epath_finder::get_best_epath): Add param "diag_idx" and use it
6942 when logging. Rather than finding the shortest path and then
6943 checking feasibility, instead use explore_feasible_paths unless
6944 !flag_analyzer_feasibility, in which case simply use the shortest
6945 path, and note if it is infeasible. Update for m_sep becoming a
6947 (class feasible_worklist): New.
6948 (epath_finder::explore_feasible_paths): New.
6949 (epath_finder::process_worklist_item): New.
6950 (class dump_eg_with_shortest_path): New.
6951 (epath_finder::dump_trimmed_graph): New.
6952 (epath_finder::dump_feasible_graph): New.
6953 (saved_diagnostic::saved_diagnostic): Add "idx" param, using it
6955 (saved_diagnostic::to_json): Dump m_idx.
6956 (saved_diagnostic::calc_best_epath): Pass m_idx to get_best_epath.
6957 Remove assertion that m_problem was set when m_best_epath is NULL.
6958 (diagnostic_manager::add_diagnostic): Pass an index when created
6959 saved_diagnostic instances.
6960 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add
6962 (saved_diagnostic::get_index): New accessor.
6963 (saved_diagnostic::m_idx): New field.
6964 * engine.cc (exploded_node::dump_dot): Call args.dump_extra_info.
6966 (exploded_node::dump_processed_stmts): ...this new function and...
6967 (exploded_node::dump_saved_diagnostics): ...this new function.
6968 Add index of each diagnostic.
6969 (exploded_edge::dump_dot): Move bulk of code to...
6970 (exploded_edge::dump_dot_label): ...this new function.
6971 * exploded-graph.h (eg_traits::dump_args_t::dump_extra_info): New
6973 (exploded_node::dump_processed_stmts): New decl.
6974 (exploded_node::dump_saved_diagnostics): New decl.
6975 (exploded_edge::dump_dot_label): New decl.
6976 * feasible-graph.cc: New file.
6977 * feasible-graph.h: New file.
6978 * trimmed-graph.cc: New file.
6979 * trimmed-graph.h: New file.
6981 2021-03-11 David Malcolm <dmalcolm@redhat.com>
6983 * diagnostic-manager.cc (epath_finder::epath_finder):
6984 Update shortest_paths init for new param.
6986 2021-03-10 David Malcolm <dmalcolm@redhat.com>
6989 * engine.cc (exploded_path::feasible_p): Move "snodes_visited" and
6990 "model" locals into a new class feasibility_state. Move heart
6991 of per-edge processing into
6992 feasibility_state::maybe_update_for_edge.
6993 (feasibility_state::feasibility_state): New.
6994 (feasibility_state::maybe_update_for_edge): New, based on loop
6995 body in exploded_path::feasible_p.
6996 * exploded-graph.h (class feasibility_state): New.
6998 2021-03-10 David Malcolm <dmalcolm@redhat.com>
7001 (callgraph_superedge::dyn_cast_callgraph_superedge): New.
7002 (call_superedge::dyn_cast_callgraph_superedge): Delete.
7003 (return_superedge::dyn_cast_callgraph_superedge): Delete.
7005 2021-03-02 Martin Liska <mliska@suse.cz>
7007 * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostics):
7010 2021-02-26 David Malcolm <dmalcolm@redhat.com>
7012 * engine.cc (exploded_path::exploded_path): New copy-ctor.
7013 * exploded-graph.h (exploded_path::operator=): Drop decl.
7015 2021-02-26 David Malcolm <dmalcolm@redhat.com>
7018 * diagnostic-manager.cc (class epath_finder): New.
7019 (epath_finder::get_best_epath): New.
7020 (saved_diagnostic::saved_diagnostic): Update for replacement of
7021 m_state and m_epath_length with m_best_epath.
7022 (saved_diagnostic::~saved_diagnostic): Delete m_best_epath.
7023 (saved_diagnostic::to_json): Update "path_length" to be optional.
7024 (saved_diagnostic::calc_best_epath): New, based on
7025 dedupe_winners::add and parts of dedupe_key::dedupe_key.
7026 (saved_diagnostic::get_epath_length): New.
7027 (saved_diagnostic::add_duplicate): New.
7028 (dedupe_key::dedupe_key): Drop epath param. Move invocation of
7029 stmt_finder to saved_diagnostic::calc_best_epath.
7030 (class dedupe_candidate): Delete.
7031 (class dedupe_hash_map_traits): Update to use saved_diagnotic *
7032 rather than dedupe_candidate * as the value_type/compare_type.
7033 (dedupe_winners::~dedupe_winners): Don't delete the values.
7034 (dedupe_winners::add): Convert param from shortest_exploded_paths to
7035 epath_finder. Drop "eg" param. Drop dedupe_candidate, moving
7036 path generation and feasiblity checking to
7037 epath_finder::get_best_epath. Update winner-selection for move
7038 of epaths from dedupe_candidate to saved_diagnostic.
7039 (dedupe_winners::emit_best): Update for removal of class
7041 (dedupe_winners::map_t): Update to use saved_diagnotic * rather
7042 than dedupe_candidate * as the value_type/compare_type.
7043 (diagnostic_manager::emit_saved_diagnostics): Move
7044 shortest_exploded_paths instance into epath_finder and pass that
7046 (diagnostic_manager::emit_saved_diagnostic): Drop epath, stmt
7047 and num_dupes params, instead getting these from the
7048 saved_diagnostic. Use correct location in inform_n call.
7049 * diagnostic-manager.h (class epath_finder): New forward decl.
7050 (saved_diagnostic::status): Drop enum.
7051 (saved_diagnostic::set_feasible): Drop.
7052 (saved_diagnostic::set_infeasible): Drop.
7053 (saved_diagnostic::get_status): Drop.
7054 (saved_diagnostic::calc_best_epath): New decl.
7055 (saved_diagnostic::get_best_epath): New decl.
7056 (saved_diagnostic::get_epath_length): New decl.
7057 (saved_diagnostic::set_epath_length): Drop.
7058 (saved_diagnostic::get_epath_length): Drop inline implementation.
7059 (saved_diagnostic::add_duplicate): New.
7060 (saved_diagnostic::get_num_dupes): New.
7061 (saved_diagnostic::m_d): Document ownership.
7062 (saved_diagnostic::m_trailing_eedge): Make const.
7063 (saved_diagnostic::m_status): Drop field.
7064 (saved_diagnostic::m_epath_length): Drop field.
7065 (saved_diagnostic::m_best_epath): New field.
7066 (saved_diagnostic::m_problem): Document ownership.
7067 (saved_diagnostic::m_duplicates): New field.
7068 (diagnostic_manager::emit_saved_diagnostic): Drop params epath,
7069 stmt, and num_dupes.
7070 * engine.cc (exploded_graph_annotator::print_saved_diagnostic):
7071 Update for changes to saved_diagnostic class.
7072 * exploded-graph.h (exploded_path::feasible_p): Drop unused
7075 2021-02-25 David Malcolm <dmalcolm@redhat.com>
7078 * region-model-impl-calls.cc (region_model::impl_call_realloc): New.
7079 * region-model.cc (region_model::on_call_pre): Call it.
7080 * region-model.h (region_model::impl_call_realloc): New decl.
7081 * sm-malloc.cc (enum wording): Add WORDING_REALLOCATED.
7082 (malloc_state_machine::m_realloc): New field.
7083 (use_after_free::describe_state_change): Add case for
7084 WORDING_REALLOCATED.
7085 (use_after_free::describe_final_event): Likewise.
7086 (malloc_state_machine::malloc_state_machine): Initialize
7088 (malloc_state_machine::on_stmt): Handle realloc by calling...
7089 (malloc_state_machine::on_realloc_call): New.
7091 2021-02-22 David Malcolm <dmalcolm@redhat.com>
7094 * engine.cc (exploded_node::on_stmt): Provide terminate_path
7095 flag as a way for on_call_pre to terminate the current analysis
7097 * region-model-impl-calls.cc (call_details::num_args): New.
7098 (region_model::impl_call_error): New.
7099 * region-model.cc (region_model::on_call_pre): Add param
7100 "out_terminate_path". Handle "error" and "error_at_line".
7101 * region-model.h (call_details::num_args): New decl.
7102 (region_model::on_call_pre): Add param "out_terminate_path".
7103 (region_model::impl_call_error): New decl.
7105 2021-02-17 David Malcolm <dmalcolm@redhat.com>
7108 * constraint-manager.cc (dead_svalue_purger::should_purge_p):
7109 Update for change to svalue::live_p.
7110 * program-state.cc (sm_state_map::on_liveness_change): Likewise.
7111 (program_state::detect_leaks): Likewise.
7112 * region-model-reachability.cc (reachable_regions::init_cluster):
7113 When dealing with a symbolic region, if the underlying pointer is
7114 implicitly live, add the region to the reachable regions.
7115 * region-model.cc (region_model::compare_initial_and_pointer):
7116 Move logic for detecting initial values of params to
7117 initial_svalue::initial_value_of_param_p.
7118 * svalue.cc (svalue::live_p): Convert "live_svalues" from a
7119 reference to a pointer; support it being NULL.
7120 (svalue::implicitly_live_p): Convert first param from a
7121 refererence to a pointer.
7122 (region_svalue::implicitly_live_p): Likewise.
7123 (constant_svalue::implicitly_live_p): Likewise.
7124 (initial_svalue::implicitly_live_p): Likewise. Treat the initial
7125 values of params for the top level frame as still live.
7126 (initial_svalue::initial_value_of_param_p): New function, taken
7127 from a test in region_model::compare_initial_and_pointer.
7128 (unaryop_svalue::implicitly_live_p): Convert first param from a
7129 refererence to a pointer.
7130 (binop_svalue::implicitly_live_p): Likewise.
7131 (sub_svalue::implicitly_live_p): Likewise.
7132 (unmergeable_svalue::implicitly_live_p): Likewise.
7133 * svalue.h (svalue::live_p): Likewise.
7134 (svalue::implicitly_live_p): Likewise.
7135 (region_svalue::implicitly_live_p): Likewise.
7136 (constant_svalue::implicitly_live_p): Likewise.
7137 (initial_svalue::implicitly_live_p): Likewise.
7138 (initial_svalue::initial_value_of_param_p): New decl.
7139 (unaryop_svalue::implicitly_live_p): Convert first param from a
7140 refererence to a pointer.
7141 (binop_svalue::implicitly_live_p): Likewise.
7142 (sub_svalue::implicitly_live_p): Likewise.
7143 (unmergeable_svalue::implicitly_live_p): Likewise.
7145 2021-02-12 David Malcolm <dmalcolm@redhat.com>
7148 * engine.cc (readability): Add names for the various arbitrary
7149 values. Handle NOP_EXPR and INTEGER_CST.
7150 (readability_comparator): Combine the readability tests for
7151 tree and stack depth, rather than performing them sequentially.
7152 (impl_region_model_context::on_state_leak): Strip off top-level
7154 * region-model.cc (region_model::get_representative_path_var): Add
7155 type-checking, moving the bulk of the implementation to...
7156 (region_model::get_representative_path_var_1): ...here. Respect
7157 types in casts by recursing and re-adding the cast, rather than
7158 merely stripping them off. Use the correct type when handling
7160 (region_model::get_representative_tree): Strip off any top-level
7162 (region_model::get_representative_path_var): Add type-checking,
7163 moving the bulk of the implementation to...
7164 (region_model::get_representative_path_var_1): ...here.
7165 * region-model.h (region_model::get_representative_path_var_1):
7167 (region_model::get_representative_path_var_1): New decl.
7168 * store.cc (append_pathvar_with_type): New.
7169 (binding_cluster::get_representative_path_vars): Cast path_vars
7170 to the correct type when adding them to *OUT_PVS.
7172 2021-02-09 David Malcolm <dmalcolm@redhat.com>
7175 * sm-file.cc (is_file_using_fn_p): Support "_IO_"-prefixed
7178 2021-02-09 David Malcolm <dmalcolm@redhat.com>
7181 * store.cc (store::set_value): Treat a pointer written to *UNKNOWN
7184 2021-02-02 David Malcolm <dmalcolm@redhat.com>
7188 * engine.cc (toplevel_function_p): Simplify so that
7189 we only reject functions with a "__analyzer_" prefix.
7190 (add_any_callbacks): Delete.
7191 (exploded_graph::build_initial_worklist): Update for
7192 dropped param of toplevel_function_p.
7193 (exploded_graph::build_initial_worklist): Don't bother
7194 looking for callbacks that are reachable from global
7197 2021-02-01 David Malcolm <dmalcolm@redhat.com>
7200 * region-model-manager.cc
7201 (region_model_manager::get_or_create_initial_value):
7202 Fold the initial value of *UNKNOWN_PTR to an UNKNOWN value.
7203 (region_model_manager::get_field_region): Fold the value
7204 of UNKNOWN_PTR->FIELD to *UNKNOWN_PTR_OF_&FIELD_TYPE.
7206 2021-01-29 David Malcolm <dmalcolm@redhat.com>
7208 * checker-path.cc (event_kind_to_string): Handle
7209 EK_START_CONSOLIDATED_CFG_EDGES and
7210 EK_END_CONSOLIDATED_CFG_EDGES.
7211 (start_consolidated_cfg_edges_event::get_desc): New.
7212 (checker_path::cfg_edge_pair_at_p): New.
7213 * checker-path.h (enum event_kind): Add
7214 EK_START_CONSOLIDATED_CFG_EDGES and
7215 EK_END_CONSOLIDATED_CFG_EDGES.
7216 (class start_consolidated_cfg_edges_event): New class.
7217 (class end_consolidated_cfg_edges_event): New class.
7218 (checker_path::delete_events): New.
7219 (checker_path::replace_event): New.
7220 (checker_path::cfg_edge_pair_at_p): New decl.
7221 * diagnostic-manager.cc (diagnostic_manager::prune_path): Call
7222 consolidate_conditions.
7223 (same_line_as_p): New.
7224 (diagnostic_manager::consolidate_conditions): New.
7225 * diagnostic-manager.h
7226 (diagnostic_manager::consolidate_conditions): New decl.
7228 2021-01-18 David Malcolm <dmalcolm@redhat.com>
7230 * analyzer.h (is_std_named_call_p): New decl.
7231 * diagnostic-manager.cc (path_builder::get_sm): New.
7232 (state_change_event_creator::state_change_event_creator): Add "pb"
7234 (state_change_event_creator::on_global_state_change): Don't consider
7235 state changes affecting other state_machines.
7236 (state_change_event_creator::on_state_change): Likewise.
7237 (state_change_event_creator::m_pb): New field.
7238 (diagnostic_manager::add_events_for_eedge): Pass pb to visitor
7240 * region-model-impl-calls.cc
7241 (region_model::impl_deallocation_call): New.
7242 * region-model.cc: Include "attribs.h".
7243 (region_model::on_call_post): Handle fndecls referenced by
7244 __attribute__((deallocated_by(FOO))).
7245 * region-model.h (region_model::impl_deallocation_call): New decl.
7246 * sm-malloc.cc: Include "stringpool.h" and "attribs.h". Add
7248 (class api): Delete.
7249 (enum resource_state): Update comment for change from api to
7250 deallocator and deallocator_set.
7251 (allocation_state::allocation_state): Drop api param. Add
7252 "deallocators" and "deallocator".
7253 (allocation_state::m_api): Drop field in favor of...
7254 (allocation_state::m_deallocators): New field.
7255 (allocation_state::m_deallocator): New field.
7256 (enum wording): Add WORDING_DEALLOCATED.
7257 (struct deallocator): New.
7258 (struct standard_deallocator): New.
7259 (struct custom_deallocator): New.
7260 (struct deallocator_set): New.
7261 (struct custom_deallocator_set): New.
7262 (struct standard_deallocator_set): New.
7263 (struct deallocator_set_map_traits): New.
7264 (malloc_state_machine::m_malloc): Drop field
7265 (malloc_state_machine::m_scalar_new): Likewise.
7266 (malloc_state_machine::m_vector_new): Likewise.
7267 (malloc_state_machine::m_free): New field
7268 (malloc_state_machine::m_scalar_delete): Likewise.
7269 (malloc_state_machine::m_vector_delete): Likewise.
7270 (malloc_state_machine::deallocator_map_t): New typedef.
7271 (malloc_state_machine::m_deallocator_map): New field.
7272 (malloc_state_machine::deallocator_set_cache_t): New typedef.
7273 (malloc_state_machine::m_custom_deallocator_set_cache): New field.
7274 (malloc_state_machine::custom_deallocator_set_map_t): New typedef.
7275 (malloc_state_machine::m_custom_deallocator_set_map): New field.
7276 (malloc_state_machine::m_dynamic_sets): New field.
7277 (malloc_state_machine::m_dynamic_deallocators): New field.
7279 (deallocator::deallocator): New ctor.
7280 (deallocator::hash): New.
7281 (deallocator::dump_to_pp): New.
7282 (deallocator::cmp): New.
7283 (deallocator::cmp_ptr_ptr): New.
7284 (standard_deallocator::standard_deallocator): New ctor.
7285 (deallocator_set::deallocator_set): New ctor.
7286 (deallocator_set::dump): New.
7287 (custom_deallocator_set::custom_deallocator_set): New ctor.
7288 (custom_deallocator_set::contains_p): New.
7289 (custom_deallocator_set::maybe_get_single): New.
7290 (custom_deallocator_set::dump_to_pp): New.
7291 (standard_deallocator_set::standard_deallocator_set): New ctor.
7292 (standard_deallocator_set::contains_p): New.
7293 (standard_deallocator_set::maybe_get_single): New.
7294 (standard_deallocator_set::dump_to_pp): New.
7296 (class mismatching_deallocation): Update for conversion from api
7297 to deallocator_set and deallocator.
7298 (double_free::emit): Use %qs.
7299 (class use_after_free): Update for conversion from api to
7300 deallocator_set and deallocator.
7301 (malloc_leak::describe_state_change): Only emit "allocated here" on
7302 a start->nonnull transition, rather than on other transitions to
7304 (allocation_state::dump_to_pp): Update for conversion from api to
7306 (allocation_state::get_nonnull): Likewise.
7307 (malloc_state_machine::malloc_state_machine): Likewise.
7308 (malloc_state_machine::~malloc_state_machine): New.
7309 (malloc_state_machine::add_state): Update for conversion from api
7311 (malloc_state_machine::get_or_create_custom_deallocator_set): New.
7312 (malloc_state_machine::maybe_create_custom_deallocator_set): New.
7313 (malloc_state_machine::get_or_create_deallocator): New.
7314 (malloc_state_machine::on_stmt): Update for conversion from api
7315 to deallocator_set. Handle "__attribute__((malloc(FOO)))", and
7316 the special attribute set on FOO.
7317 (malloc_state_machine::on_allocator_call): Update for conversion
7318 from api to deallocator_set. Add "returns_nonnull" param and use
7319 it to affect which state to transition to.
7320 (malloc_state_machine::on_deallocator_call): Update for conversion
7321 from api to deallocator_set.
7323 2021-01-14 David Malcolm <dmalcolm@redhat.com>
7325 * engine.cc (strongly_connected_components::to_json): New.
7326 (worklist::to_json): New.
7327 (exploded_graph::to_json): JSON-ify the worklist.
7328 * exploded-graph.h (strongly_connected_components::to_json): New
7330 (worklist::to_json): New decl.
7331 * store.cc (store::to_json): Fix comment.
7332 * supergraph.cc (supernode::to_json): Fix reference to
7333 "returning_call" in comment. Add optional "fun" to JSON.
7334 (edge_kind_to_string): New.
7335 (superedge::to_json): Add "kind" to JSON.
7337 2021-01-14 David Malcolm <dmalcolm@redhat.com>
7340 * analyzer.h (region_offset::operator==): Make const.
7341 * pending-diagnostic.h (pending_diagnostic::equal_p): Likewise.
7342 * store.h (binding_cluster::for_each_value): Likewise.
7343 (binding_cluster::for_each_binding): Likewise.
7345 2021-01-12 David Malcolm <dmalcolm@redhat.com>
7348 * store.cc (binding_cluster::make_unknown_relative_to): Don't mark
7349 dereferenced unknown pointers as having escaped.
7351 2021-01-07 David Malcolm <dmalcolm@redhat.com>
7354 * region.cc (decl_region::get_svalue_for_initializer): Gracefully
7355 handle when LTO writes out DECL_INITIAL as error_mark_node.
7357 2021-01-07 David Malcolm <dmalcolm@redhat.com>
7360 * store.cc (binding_cluster::can_merge_p): Add "out_store" param
7361 and pass to calls to binding_cluster::make_unknown_relative_to.
7362 (binding_cluster::make_unknown_relative_to): Add "out_store"
7363 param. Use it to mark base regions that are pointed to by
7364 pointers that become unknown as having escaped.
7365 (store::can_merge_p): Pass out_store to
7366 binding_cluster::can_merge_p.
7367 * store.h (binding_cluster::can_merge_p): Add "out_store" param.
7368 (binding_cluster::make_unknown_relative_to): Likewise.
7369 * svalue.cc (region_svalue::implicitly_live_p): New vfunc.
7370 * svalue.h (region_svalue::implicitly_live_p): New vfunc decl.
7372 2021-01-07 David Malcolm <dmalcolm@redhat.com>
7375 * engine.cc (exploded_path::feasible_p): Add missing call to
7378 2021-01-06 David Malcolm <dmalcolm@redhat.com>
7381 * region-model-reachability.cc (reachable_regions::init_cluster):
7382 Convert symbolic region handling to a switch statement. Add cases
7383 to handle SK_UNKNOWN and SK_CONJURED.
7385 2021-01-05 David Malcolm <dmalcolm@redhat.com>
7388 * store.cc (binding_map::apply_ctor_to_region): When "index" is
7389 NULL, iterate through the fields for RECORD_TYPEs, rather than
7390 creating an INTEGER_CST index.
7392 2020-11-30 David Malcolm <dmalcolm@redhat.com>
7394 * analyzer-pass.cc: Include "analyzer/analyzer.h" for the
7395 declaration of sorry_no_analyzer; include "tree.h" and
7396 "function.h" as these are needed by it.
7398 2020-11-30 David Malcolm <dmalcolm@redhat.com>
7400 * analyzer-pass.cc (pass_analyzer::execute): Move sorry call to...
7401 (sorry_no_analyzer): New.
7402 * analyzer.h (class state_machine): New forward decl.
7403 (class logger): New forward decl.
7404 (class plugin_analyzer_init_iface): New.
7405 (sorry_no_analyzer): New decl.
7406 * checker-path.cc (checker_path::fixup_locations): New.
7407 * checker-path.h (checker_event::set_location): New.
7408 (checker_path::fixup_locations): New decl.
7409 * diagnostic-manager.cc
7410 (diagnostic_manager::emit_saved_diagnostic): Call
7411 checker_path::fixup_locations, and call fixup_location
7412 on the primary location.
7413 * engine.cc: Include "plugin.h".
7414 (class plugin_analyzer_init_impl): New.
7415 (impl_run_checkers): Invoke PLUGIN_ANALYZER_INIT callbacks.
7416 * pending-diagnostic.h (pending_diagnostic::fixup_location): New
7419 2020-11-18 David Malcolm <dmalcolm@redhat.com>
7422 * sm-malloc.cc (null_deref::emit): Use CWE-476 rather than
7423 CWE-690, as this isn't due to an unchecked return value.
7424 (null_arg::emit): Likewise.
7426 2020-11-12 David Malcolm <dmalcolm@redhat.com>
7428 * checker-path.h (checker_event::get_id_ptr): New.
7429 * diagnostic-manager.cc (path_builder::path_builder): Add "sd"
7430 param and use it to initialize new field "m_sd".
7431 (path_builder::get_pending_diagnostic): New.
7432 (path_builder::m_sd): New field.
7433 (diagnostic_manager::emit_saved_diagnostic): Pass sd to
7435 (diagnostic_manager::add_events_for_superedge): Call new
7436 maybe_add_custom_events_for_superedge vfunc.
7437 * engine.cc (stale_jmp_buf::stale_jmp_buf): Add "setjmp_point"
7438 param and use it to initialize new field "m_setjmp_point".
7439 Initialize new field "m_stack_pop_event".
7440 (stale_jmp_buf::maybe_add_custom_events_for_superedge): New vfunc
7442 (stale_jmp_buf::describe_final_event): New vfunc implementation.
7443 (stale_jmp_buf::m_setjmp_point): New field.
7444 (stale_jmp_buf::m_stack_pop_event): New field.
7445 (exploded_node::on_longjmp): Pass setjmp_point to stale_jmp_buf
7447 * pending-diagnostic.h
7448 (pending_diagnostic::maybe_add_custom_events_for_superedge): New
7451 2020-11-12 David Malcolm <dmalcolm@redhat.com>
7453 PR tree-optimization/97424
7454 * analyzer.opt (Wanalyzer-shift-count-negative): New.
7455 (Wanalyzer-shift-count-overflow): New.
7456 * region-model.cc (class shift_count_negative_diagnostic): New.
7457 (class shift_count_overflow_diagnostic): New.
7458 (region_model::get_gassign_result): Complain about shift counts that
7459 are negative or are >= the operand's type's width.
7461 2020-11-10 Martin Liska <mliska@suse.cz>
7463 * constraint-manager.cc (constraint_manager::merge): Remove
7465 * constraint-manager.h: Likewise.
7466 * program-state.cc (sm_state_map::sm_state_map): Likewise.
7467 (program_state::program_state): Likewise.
7468 (test_sm_state_map): Likewise.
7469 * program-state.h: Likewise.
7470 * region-model-reachability.cc (reachable_regions::reachable_regions): Likewise.
7471 * region-model-reachability.h: Likewise.
7472 * region-model.cc (region_model::handle_unrecognized_call): Likewise.
7473 (region_model::get_reachable_svalues): Likewise.
7474 (region_model::can_merge_with_p): Likewise.
7476 2020-11-05 David Malcolm <dmalcolm@redhat.com>
7479 * svalue.cc (cmp_cst): Handle COMPLEX_CST.
7481 2020-10-29 David Malcolm <dmalcolm@redhat.com>
7483 * program-state.cc (sm_state_map::on_liveness_change): Sort the
7484 leaking svalues before calling on_state_leak.
7485 (program_state::detect_leaks): Likewise when calling
7487 * region-model-reachability.cc
7488 (reachable_regions::mark_escaped_clusters): Likewise when
7489 calling on_escaped_function.
7491 2020-10-29 David Malcolm <dmalcolm@redhat.com>
7494 * region-model-reachability.cc (reachable_regions::handle_sval):
7495 Operands of reachable reversible operations are reachable.
7497 2020-10-29 David Malcolm <dmalcolm@redhat.com>
7499 * analyzer.h (class state_machine): New forward decl.
7500 (class logger): Likewise.
7501 (class visitor): Likewise.
7502 * complexity.cc: New file, taken from svalue.cc.
7503 * complexity.h: New file, taken from region-model.h.
7504 * region-model.h: Include "analyzer/svalue.h" and
7505 "analyzer/region.h". Move struct complexity to complexity.h.
7506 Move svalue, its subclasses and supporting decls to svalue.h.
7507 Move region, its subclasses and supporting decls to region.h.
7508 * region.cc: Include "analyzer/region.h".
7509 (symbolic_region::symbolic_region): Move here from region-model.h.
7510 * region.h: New file, based on material from region-model.h.
7511 * svalue.cc: Include "analyzer/svalue.h".
7512 (complexity::complexity): Move to complexity.cc.
7513 (complexity::from_pair): Likewise.
7514 * svalue.h: New file, based on material from region-model.h.
7516 2020-10-29 David Malcolm <dmalcolm@redhat.com>
7518 * program-state.cc (sm_state_map::print): Guard the printing of
7519 the origin pointer with !flag_dump_noaddr.
7520 * region.cc (string_region::dump_to_pp): Likewise for
7523 2020-10-27 David Malcolm <dmalcolm@redhat.com>
7526 * region-model.cc (region_model::get_initial_value_for_global):
7527 Move check that !DECL_EXTERNAL from here to...
7528 * region.cc (decl_region::get_svalue_for_initializer): ...here,
7529 using it to reject zero initialization.
7531 2020-10-27 Markus Böck <markus.boeck02@gmail.com>
7534 * store.h (hash): Cast to intptr_t instead of long
7536 2020-10-27 David Malcolm <dmalcolm@redhat.com>
7538 * constraint-manager.cc (svalue_cmp_by_ptr): Delete.
7539 (equiv_class::canonicalize): Use svalue::cmp_ptr_ptr instead.
7540 (equiv_class_cmp): Eliminate pointer comparison.
7541 * diagnostic-manager.cc (dedupe_key::comparator): If they are at
7542 the same location, also compare epath ength and pending_diagnostic
7544 * engine.cc (readability_comparator): If two path_vars have the
7545 same readability, then impose an arbitrary ordering on them.
7546 (worklist::key_t::cmp): If two points have the same plan ordering,
7547 continue the comparison. Call sm_state_map::cmp rather than
7548 comparing hash values.
7549 * program-state.cc (sm_state_map::entry_t::cmp): New.
7550 (sm_state_map::cmp): New.
7551 * program-state.h (sm_state_map::entry_t::cmp): New decl.
7552 (sm_state_map::elements): New.
7553 (sm_state_map::cmp): New.
7555 2020-10-27 David Malcolm <dmalcolm@redhat.com>
7557 * engine.cc (setjmp_record::cmp): New.
7558 (supernode_cluster::dump_dot): Avoid embedding pointer in cluster
7560 (supernode_cluster::cmp_ptr_ptr): New.
7561 (function_call_string_cluster::dump_dot): Avoid embedding pointer
7562 in cluster name. Sort m_map when dumping child clusters.
7563 (function_call_string_cluster::cmp_ptr_ptr): New.
7564 (root_cluster::dump_dot): Sort m_map when dumping child clusters.
7565 * program-point.cc (function_point::cmp): New.
7566 (function_point::cmp_ptr): New.
7567 * program-point.h (function_point::cmp): New decl.
7568 (function_point::cmp_ptr): New decl.
7569 * program-state.cc (sm_state_map::print): Sort the values. Guard
7570 the printing of pointers with !flag_dump_noaddr.
7571 (program_state::prune_for_point): Sort the regions.
7572 (log_set_of_svalues): Sort the values. Guard the printing of
7573 pointers with !flag_dump_noaddr.
7574 * region-model-manager.cc (log_uniq_map): Sort the values.
7575 * region-model-reachability.cc (dump_set): New function template.
7576 (reachable_regions::dump_to_pp): Use it.
7577 * region-model.h (svalue::cmp_ptr): New decl.
7578 (svalue::cmp_ptr_ptr): New decl.
7579 (setjmp_record::cmp): New decl.
7580 (placeholder_svalue::get_name): New accessor.
7581 (widening_svalue::get_point): New accessor.
7582 (compound_svalue::get_map): New accessor.
7583 (conjured_svalue::get_stmt): New accessor.
7584 (conjured_svalue::get_id_region): New accessor.
7585 (region::cmp_ptrs): Rename to...
7586 (region::cmp_ptr_ptr): ...this.
7587 * region.cc (region::cmp_ptrs): Rename to...
7588 (region::cmp_ptr_ptr): ...this.
7590 (state_purge_per_ssa_name::state_purge_per_ssa_name): Sort
7591 m_points_needing_name when dumping.
7592 * store.cc (concrete_binding::cmp_ptr_ptr): New.
7593 (symbolic_binding::cmp_ptr_ptr): New.
7594 (binding_map::cmp): New.
7595 (get_sorted_parent_regions): Update for renaming of
7596 region::cmp_ptrs to region::cmp_ptr_ptr.
7597 (store::dump_to_pp): Likewise.
7598 (store::to_json): Likewise.
7599 (store::can_merge_p): Sort the base regions before considering
7601 * store.h (concrete_binding::cmp_ptr_ptr): New decl.
7602 (symbolic_binding::cmp_ptr_ptr): New decl.
7603 (binding_map::cmp): New decl.
7604 * supergraph.cc (supergraph::supergraph): Assign UIDs to the
7606 * svalue.cc (cmp_cst): New.
7607 (svalue::cmp_ptr): New.
7608 (svalue::cmp_ptr_ptr): New.
7610 2020-10-27 David Malcolm <dmalcolm@redhat.com>
7612 * engine.cc (exploded_graph::get_or_create_node): Fix off-by-one
7613 when imposing param_analyzer_max_enodes_per_program_point limit.
7615 2020-10-27 David Malcolm <dmalcolm@redhat.com>
7617 * region-model.cc (region_model::get_representative_path_var):
7618 Implement case RK_LABEL.
7619 * region-model.h (label_region::get_label): New accessor.
7621 2020-10-22 David Malcolm <dmalcolm@redhat.com>
7624 * engine.cc (exploded_graph::add_function_entry): Handle failure
7625 to create an enode, rather than asserting.
7627 2020-10-22 David Malcolm <dmalcolm@redhat.com>
7630 * engine.cc (exploded_graph::add_function_entry): Assert that we
7631 have a function body.
7632 (exploded_graph::on_escaped_function): Reject fndecls that don't
7633 have a function body.
7635 2020-10-14 David Malcolm <dmalcolm@redhat.com>
7638 * region-model.cc (region_model::get_initial_value_for_global):
7639 Fall back to returning an initial_svalue if
7640 decl_region::get_svalue_for_initializer fails.
7641 * region.cc (decl_region::get_svalue_for_initializer): Don't
7642 attempt to create a compound_svalue if the region has an unknown
7645 2020-10-14 David Malcolm <dmalcolm@redhat.com>
7648 * store.cc (binding_map::apply_ctor_to_region): Remove redundant
7651 2020-10-12 David Malcolm <dmalcolm@redhat.com>
7654 * engine.cc (impl_region_model_context::on_escaped_function): New
7656 (exploded_graph::add_function_entry): Use m_functions_with_enodes
7657 to implement idempotency.
7658 (add_any_callbacks): New.
7659 (exploded_graph::build_initial_worklist): Use the above to find
7660 callbacks that are reachable from global initializers.
7661 (exploded_graph::on_escaped_function): New.
7663 (impl_region_model_context::on_escaped_function): New decl.
7664 (exploded_graph::on_escaped_function): New decl.
7665 (exploded_graph::m_functions_with_enodes): New field.
7666 * region-model-reachability.cc
7667 (reachable_regions::reachable_regions): Replace "store" param with
7668 "model" param; use it to initialize m_model.
7669 (reachable_regions::add): When getting the svalue for the region,
7670 call get_store_value on the model rather than using an initial
7672 (reachable_regions::mark_escaped_clusters): Add ctxt param and
7673 use it to call on_escaped_function when a function_region escapes.
7674 * region-model-reachability.h
7675 (reachable_regions::reachable_regions): Replace "store" param with
7677 (reachable_regions::mark_escaped_clusters): Add ctxt param.
7678 (reachable_regions::m_model): New field.
7679 * region-model.cc (region_model::handle_unrecognized_call): Update
7680 for change in reachable_regions ctor.
7681 (region_model::handle_unrecognized_call): Pass ctxt to
7682 mark_escaped_clusters.
7683 (region_model::get_reachable_svalues): Update for change in
7684 reachable_regions ctor.
7685 (region_model::get_initial_value_for_global): Read-only variables
7686 keep their initial values.
7687 * region-model.h (region_model_context::on_escaped_function): New
7689 (noop_region_model_context::on_escaped_function): New.
7691 2020-10-12 David Malcolm <dmalcolm@redhat.com>
7693 * analyzer.opt (Wanalyzer-write-to-const): New.
7694 (Wanalyzer-write-to-string-literal): New.
7695 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
7696 Call check_for_writable_region.
7697 (region_model::impl_call_memset): Likewise.
7698 (region_model::impl_call_strcpy): Likewise.
7699 * region-model.cc (class write_to_const_diagnostic): New.
7700 (class write_to_string_literal_diagnostic): New.
7701 (region_model::check_for_writable_region): New.
7702 (region_model::set_value): Call check_for_writable_region.
7703 * region-model.h (region_model::check_for_writable_region): New
7706 2020-10-07 David Malcolm <dmalcolm@redhat.com>
7709 * sm-malloc.cc (method_p): New.
7710 (describe_argument_index): New.
7711 (inform_nonnull_attribute): Use describe_argument_index.
7712 (possible_null_arg::describe_final_event): Likewise.
7713 (null_arg::describe_final_event): Likewise.
7715 2020-09-29 David Malcolm <dmalcolm@redhat.com>
7718 * engine.cc (stmt_requires_new_enode_p): Split enodes before
7721 2020-09-29 David Malcolm <dmalcolm@redhat.com>
7723 * constraint-manager.cc
7724 (constraint_manager::add_constraint_internal): Whitespace fixes.
7725 Silence -Wsign-compare warning.
7726 * engine.cc (maybe_process_run_of_before_supernode_enodes):
7727 Silence -Wsign-compare warning.
7729 2020-09-28 David Malcolm <dmalcolm@redhat.com>
7731 * region-model.h (binop_svalue::dyn_cast_binop_svalue): Remove
7732 redundant "virtual". Add FINAL OVERRIDE.
7733 (widening_svalue::dyn_cast_widening_svalue): Add FINAL OVERRIDE.
7734 (compound_svalue::dyn_cast_compound_svalue): Likewise.
7735 (conjured_svalue::dyn_cast_conjured_svalue): Likewise.
7737 2020-09-28 David Malcolm <dmalcolm@redhat.com>
7739 * diagnostic-manager.cc (null_assignment_sm_context::m_visitor):
7740 Remove unused field.
7742 2020-09-28 David Malcolm <dmalcolm@redhat.com>
7745 * analyzer.cc (is_longjmp_call_p): Require the initial argument
7747 * engine.cc (exploded_node::on_longjmp): Likewise.
7749 2020-09-28 David Malcolm <dmalcolm@redhat.com>
7751 * program-state.cc (sm_state_map::print): Update check
7752 for m_global_state being the start state.
7754 2020-09-26 David Malcolm <dmalcolm@redhat.com>
7758 * region-model.cc (region_model::get_representative_path_var):
7759 When handling offset_region, wrap the MEM_REF's first argument in
7760 an ADDR_EXPR of pointer type, rather than simply using the tree
7761 for the parent region. Require the MEM_REF's second argument to
7762 be an integer constant.
7764 2020-09-24 David Malcolm <dmalcolm@redhat.com>
7766 * analyzer.h (struct rejected_constraint): New decl.
7767 * analyzer.opt (fanalyzer-feasibility): New option.
7768 * diagnostic-manager.cc (path_builder::path_builder): Add
7769 "problem" param and use it to initialize new field.
7770 (path_builder::get_feasibility_problem): New accessor.
7771 (path_builder::m_feasibility_problem): New field.
7772 (dedupe_winners::add): Remove inversion of logic in "if" clause,
7773 swapping if/else suites. In the !feasible_p suite, inspect
7774 flag_analyzer_feasibility and add code to handle when this
7775 is off, accepting the infeasible path, but recording the
7776 feasibility_problem.
7777 (diagnostic_manager::emit_saved_diagnostic): Pass the
7778 feasibility_problem to the path_builder.
7779 (diagnostic_manager::add_events_for_eedge): If we have
7780 a feasibility_problem at this edge, use it to add a custom event.
7781 * engine.cc (exploded_path::feasible_p): Pass a
7782 rejected_constraint ** to model.maybe_update_for_edge and transfer
7783 ownership of any created instance to any feasibility_problem.
7784 (feasibility_problem::dump_to_pp): New.
7785 * exploded-graph.h (feasibility_problem::feasibility_problem):
7786 Drop "model" param; add rejected_constraint * param.
7787 (feasibility_problem::~feasibility_problem): New.
7788 (feasibility_problem::dump_to_pp): New decl.
7789 (feasibility_problem::m_model): Drop field.
7790 (feasibility_problem::m_rc): New field.
7791 * program-point.cc (function_point::get_location): Handle
7792 PK_BEFORE_SUPERNODE and PK_AFTER_SUPERNODE.
7793 * program-state.cc (program_state::on_edge): Pass NULL to new
7794 param of region_model::maybe_update_for_edge.
7795 * region-model.cc (region_model::add_constraint): New overload
7796 adding a rejected_constraint ** param.
7797 (region_model::maybe_update_for_edge): Add rejected_constraint **
7798 param and pass it to the various apply_constraints_for_ calls.
7799 (region_model::apply_constraints_for_gcond): Add
7800 rejected_constraint ** param and pass it to add_constraint calls.
7801 (region_model::apply_constraints_for_gswitch): Likewise.
7802 (region_model::apply_constraints_for_exception): Likewise.
7803 (rejected_constraint::dump_to_pp): New.
7804 * region-model.h (region_model::maybe_update_for_edge):
7805 Add rejected_constraint ** param.
7806 (region_model::add_constraint): New overload adding a
7807 rejected_constraint ** param.
7808 (region_model::apply_constraints_for_gcond): Add
7809 rejected_constraint ** param.
7810 (region_model::apply_constraints_for_gswitch): Likewise.
7811 (region_model::apply_constraints_for_exception): Likewise.
7812 (struct rejected_constraint): New.
7814 2020-09-23 David Malcolm <dmalcolm@redhat.com>
7817 * engine.cc (impl_run_checkers): Update for change to ext_state
7819 * program-state.cc (selftest::test_sm_state_map): Pass an engine
7820 instance to ext_state ctor.
7821 (selftest::test_program_state_1): Likewise.
7822 (selftest::test_program_state_2): Likewise.
7823 (selftest::test_program_state_merging): Likewise.
7824 (selftest::test_program_state_merging_2): Likewise.
7825 * program-state.h (extrinsic_state::extrinsic_state): Remove NULL
7826 default value for "eng" param.
7828 2020-09-23 Tobias Burnus <tobias@codesourcery.com>
7830 * analyzer-logging.cc: Guard '#pragma ... ignored "-Wformat-diag"'
7831 by '#if __GNUC__ >= 10'
7832 * analyzer.h: Likewise.
7833 * call-string.cc: Likewise.
7835 2020-09-23 David Malcolm <dmalcolm@redhat.com>
7837 * engine.cc (exploded_node::on_stmt): Replace sequence of dyn_cast
7840 2020-09-22 David Malcolm <dmalcolm@redhat.com>
7842 * analysis-plan.cc: Include "json.h".
7843 * analyzer.opt (fdump-analyzer-json): New.
7844 * call-string.cc: Include "json.h".
7845 (call_string::to_json): New.
7846 * call-string.h (call_string::to_json): New decl.
7847 * checker-path.cc: Include "json.h".
7848 * constraint-manager.cc: Include "json.h".
7849 (equiv_class::to_json): New.
7850 (constraint::to_json): New.
7851 (constraint_manager::to_json): New.
7852 * constraint-manager.h (equiv_class::to_json): New decl.
7853 (constraint::to_json): New decl.
7854 (constraint_manager::to_json): New decl.
7855 * diagnostic-manager.cc: Include "json.h".
7856 (saved_diagnostic::to_json): New.
7857 (diagnostic_manager::to_json): New.
7858 * diagnostic-manager.h (saved_diagnostic::to_json): New decl.
7859 (diagnostic_manager::to_json): New decl.
7860 * engine.cc: Include "json.h", <zlib.h>.
7861 (exploded_node::status_to_str): New.
7862 (exploded_node::to_json): New.
7863 (exploded_edge::to_json): New.
7864 (exploded_graph::to_json): New.
7865 (dump_analyzer_json): New.
7866 (impl_run_checkers): Call it.
7867 * exploded-graph.h (exploded_node::status_to_str): New decl.
7868 (exploded_node::to_json): New.
7869 (exploded_edge::to_json): New.
7870 (exploded_graph::to_json): New.
7871 * pending-diagnostic.cc: Include "json.h".
7872 * program-point.cc: Include "json.h".
7873 (program_point::to_json): New.
7874 * program-point.h (program_point::to_json): New decl.
7875 * program-state.cc: Include "json.h".
7876 (extrinsic_state::to_json): New.
7877 (sm_state_map::to_json): New.
7878 (program_state::to_json): New.
7879 * program-state.h (extrinsic_state::to_json): New decl.
7880 (sm_state_map::to_json): New decl.
7881 (program_state::to_json): New decl.
7882 * region-model-impl-calls.cc: Include "json.h".
7883 * region-model-manager.cc: Include "json.h".
7884 * region-model-reachability.cc: Include "json.h".
7885 * region-model.cc: Include "json.h".
7886 * region-model.h (svalue::to_json): New decl.
7887 (region::to_json): New decl.
7888 * region.cc: Include "json.h".
7889 (region::to_json: New.
7890 * sm-file.cc: Include "json.h".
7891 * sm-malloc.cc: Include "json.h".
7892 * sm-pattern-test.cc: Include "json.h".
7893 * sm-sensitive.cc: Include "json.h".
7894 * sm-signal.cc: Include "json.h".
7895 (signal_delivery_edge_info_t::to_json): New.
7896 * sm-taint.cc: Include "json.h".
7897 * sm.cc: Include "diagnostic.h", "tree-diagnostic.h", and
7899 (state_machine::state::to_json): New.
7900 (state_machine::to_json): New.
7901 * sm.h (state_machine::state::to_json): New.
7902 (state_machine::to_json): New.
7903 * state-purge.cc: Include "json.h".
7904 * store.cc: Include "json.h".
7905 (binding_key::get_desc): New.
7906 (binding_map::to_json): New.
7907 (binding_cluster::to_json): New.
7908 (store::to_json): New.
7909 * store.h (binding_key::get_desc): New decl.
7910 (binding_map::to_json): New decl.
7911 (binding_cluster::to_json): New decl.
7912 (store::to_json): New decl.
7913 * supergraph.cc: Include "json.h".
7914 (supergraph::to_json): New.
7915 (supernode::to_json): New.
7916 (superedge::to_json): New.
7917 * supergraph.h (supergraph::to_json): New decl.
7918 (supernode::to_json): New decl.
7919 (superedge::to_json): New decl.
7920 * svalue.cc: Include "json.h".
7921 (svalue::to_json): New.
7923 2020-09-21 David Malcolm <dmalcolm@redhat.com>
7926 * region-model-impl-calls.cc (call_details::get_arg_type): New.
7927 * region-model.cc (region_model::on_call_pre): Check that the
7928 initial arg is a pointer before calling impl_call_memset and
7930 * region-model.h (call_details::get_arg_type): New decl.
7932 2020-09-21 David Malcolm <dmalcolm@redhat.com>
7935 * sm-malloc.cc (malloc_state_machine::get_default_state): Look at
7936 the base region when considering pointers. Treat pointers to
7937 decls as being non-heap.
7939 2020-09-18 David Malcolm <dmalcolm@redhat.com>
7941 * checker-path.cc (warning_event::get_desc): Handle global state
7944 2020-09-18 David Malcolm <dmalcolm@redhat.com>
7946 * sm-malloc.cc (malloc_state_machine::on_stmt): Handle strdup and
7947 strndup as being malloc-like allocators.
7949 2020-09-16 David Malcolm <dmalcolm@redhat.com>
7951 * engine.cc (strongly_connected_components::strong_connect): Only
7952 consider intraprocedural edges when creating SCCs.
7953 (worklist::key_t::cmp): Add comment. Treat call_string
7954 differences as more important than differences of program_point
7957 2020-09-16 David Malcolm <dmalcolm@redhat.com>
7959 * engine.cc (supernode_cluster::dump_dot): Show the SCC id
7960 in the per-supernode clusters in FILENAME.eg.dot output.
7961 (exploded_graph_annotator::add_node_annotations):
7962 Show the SCC of the supernode in FILENAME.supernode.eg.dot output.
7963 * exploded-graph.h (worklist::scc_id): New.
7964 (exploded_graph::get_scc_id): New.
7966 2020-09-16 David Malcolm <dmalcolm@redhat.com>
7968 * engine.cc (exploded_node::dump_dot): Show STATUS_BULK_MERGED.
7969 (exploded_graph::process_worklist): Call
7970 maybe_process_run_of_before_supernode_enodes.
7971 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
7973 (exploded_graph_annotator::print_enode): Show STATUS_BULK_MERGED.
7974 * exploded-graph.h (enum exploded_node::status): Add
7977 2020-09-16 David Malcolm <dmalcolm@redhat.com>
7980 (exploded_graph::process_node) <case PK_BEFORE_SUPERNODE>:
7981 Simplify by using program_point::get_next.
7982 * program-point.cc (program_point::get_next): New.
7983 * program-point.h (program_point::get_next): New decl.
7985 2020-09-16 David Malcolm <dmalcolm@redhat.com>
7987 * engine.cc (exploded_graph::get_or_create_node): Show the
7988 program point when issuing -Wanalyzer-too-complex due to hitting
7989 the per-program-point limit.
7991 2020-09-16 David Malcolm <dmalcolm@redhat.com>
7993 * region-model.cc (region_model::on_call_pre): Treat getchar as
7994 having no side-effects.
7996 2020-09-15 David Malcolm <dmalcolm@redhat.com>
7999 * constraint-manager.cc (merger_fact_visitor::on_fact): Replace
8000 assertion that add_constraint succeeded with an assertion that
8001 if it fails, -fanalyzer-transitivity is off.
8003 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8005 * analyzer.opt (-param=analyzer-max-constraints=): New param.
8006 * constraint-manager.cc
8007 (constraint_manager::add_constraint_internal): Silently reject
8008 attempts to add constraints when the above limit is reached.
8010 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8013 * constraint-manager.cc
8014 (constraint_manager::get_or_add_equiv_class): Don't accumulate
8015 transitive closure of all constraints on constants.
8017 2020-09-14 David Malcolm <dmalcolm@redhat.com>
8020 * analyzer.cc (is_setjmp_call_p): Require the initial arg to be a
8022 * region-model.cc (region_model::deref_rvalue): Assert that the
8023 svalue is of pointer type.
8025 2020-09-11 David Malcolm <dmalcolm@redhat.com>
8028 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
8030 (region_model::impl_call_strcpy): New.
8031 * region-model.cc (region_model::on_call_pre): Flag unhandled
8032 builtins that are non-pure as having unknown side-effects.
8033 Implement BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_STRCPY,
8034 BUILT_IN_STRCPY_CHK, BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED,
8035 BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_FPUTC,
8036 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
8037 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
8038 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
8039 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
8040 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF.
8041 * region-model.h (region_model::impl_call_memcpy): New decl.
8042 (region_model::impl_call_strcpy): New decl.
8044 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8047 * analyzer.opt (Wanalyzer-mismatching-deallocation): New warning.
8048 * region-model-impl-calls.cc
8049 (region_model::impl_call_operator_new): New.
8050 (region_model::impl_call_operator_delete): New.
8051 * region-model.cc (region_model::on_call_pre): Detect operator new
8052 and operator delete.
8053 (region_model::on_call_post): Likewise.
8054 (region_model::maybe_update_for_edge): Detect EH edges and call...
8055 (region_model::apply_constraints_for_exception): New function.
8056 * region-model.h (region_model::impl_call_operator_new): New decl.
8057 (region_model::impl_call_operator_delete): New decl.
8058 (region_model::apply_constraints_for_exception): New decl.
8059 * sm-malloc.cc (enum resource_state): New.
8060 (struct allocation_state): New state subclass.
8061 (enum wording): New.
8063 (malloc_state_machine::custom_data_t): New typedef.
8064 (malloc_state_machine::add_state): New decl.
8065 (malloc_state_machine::m_unchecked)
8066 (malloc_state_machine::m_nonnull)
8067 (malloc_state_machine::m_freed): Delete these states in favor
8069 (malloc_state_machine::m_malloc)
8070 (malloc_state_machine::m_scalar_new)
8071 (malloc_state_machine::m_vector_new): ...this new api instances,
8072 which own their own versions of these states.
8073 (malloc_state_machine::on_allocator_call): New decl.
8074 (malloc_state_machine::on_deallocator_call): New decl.
8075 (api::api): New ctor.
8076 (dyn_cast_allocation_state): New.
8077 (as_a_allocation_state): New.
8082 (malloc_diagnostic::describe_state_change): Use unchecked_p and
8084 (class mismatching_deallocation): New.
8085 (double_free::double_free): Add funcname param for initializing
8087 (double_free::emit): Use m_funcname in warning message rather
8088 than hardcoding "free".
8089 (double_free::describe_state_change): Likewise. Use freed_p.
8090 (double_free::describe_call_with_state): Use freed_p.
8091 (double_free::describe_final_event): Use m_funcname in message
8092 rather than hardcoding "free".
8093 (double_free::m_funcname): New field.
8094 (possible_null::describe_state_change): Use unchecked_p.
8095 (possible_null::describe_return_of_state): Likewise.
8096 (use_after_free::use_after_free): Add param for initializing m_api.
8097 (use_after_free::emit): Use m_api->m_dealloc_funcname in message
8098 rather than hardcoding "free".
8099 (use_after_free::describe_state_change): Use freed_p. Change the
8100 wording of the message based on the API.
8101 (use_after_free::describe_final_event): Use
8102 m_api->m_dealloc_funcname in message rather than hardcoding
8103 "free". Change the wording of the message based on the API.
8104 (use_after_free::m_api): New field.
8105 (malloc_leak::describe_state_change): Use unchecked_p. Update
8106 for renaming of m_malloc_event to m_alloc_event.
8107 (malloc_leak::describe_final_event): Update for renaming of
8108 m_malloc_event to m_alloc_event.
8109 (malloc_leak::m_malloc_event): Rename...
8110 (malloc_leak::m_alloc_event): ...to this.
8111 (free_of_non_heap::free_of_non_heap): Add param for initializing
8113 (free_of_non_heap::emit): Use m_funcname in message rather than
8115 (free_of_non_heap::describe_final_event): Likewise.
8116 (free_of_non_heap::m_funcname): New field.
8117 (allocation_state::dump_to_pp): New.
8118 (allocation_state::get_nonnull): New.
8119 (malloc_state_machine::malloc_state_machine): Update for changes
8120 to state fields and new api fields.
8121 (malloc_state_machine::add_state): New.
8122 (malloc_state_machine::on_stmt): Move malloc/calloc handling to
8123 on_allocator_call and call it, passing in the API pointer.
8124 Likewise for free, moving it to on_deallocator_call. Handle calls
8125 to operator new and delete in an analogous way. Use unchecked_p
8126 when testing for possibly-null-arg and possibly-null-deref, and
8127 transition to the non-null for the correct API. Remove redundant
8128 node param from call to on_zero_assignment. Use freed_p for
8129 use-after-free check, and pass in API.
8130 (malloc_state_machine::on_allocator_call): New, based on code in
8132 (malloc_state_machine::on_deallocator_call): Likewise.
8133 (malloc_state_machine::on_phi): Mark node param with
8134 ATTRIBUTE_UNUSED; don't pass it to on_zero_assignment.
8135 (malloc_state_machine::on_condition): Mark node param with
8136 ATTRIBUTE_UNUSED. Replace on_transition calls with get_state and
8137 set_next_state pairs, transitioning to the non-null state for the
8139 (malloc_state_machine::can_purge_p): Port to new state approach.
8140 (malloc_state_machine::on_zero_assignment): Replace on_transition
8141 calls with get_state and set_next_state pairs. Drop redundant
8143 * sm.h (state_machine::add_custom_state): New.
8145 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8147 * diagnostic-manager.cc
8148 (null_assignment_sm_context::warn_for_state): Replace with...
8149 (null_assignment_sm_context::warn): ...this.
8150 * engine.cc (impl_sm_context::warn_for_state): Replace with...
8151 (impl_sm_context::warn): ...this.
8152 * sm-file.cc (fileptr_state_machine::on_stmt): Replace
8153 warn_for_state and on_transition calls with a get_state
8154 test guarding warn and set_next_state calls.
8155 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
8156 * sm-pattern-test.cc (pattern_test_state_machine::on_condition):
8157 Replace warn_for_state call with warn call.
8159 (sensitive_state_machine::warn_for_any_exposure): Replace
8160 warn_for_state call with a get_state test guarding a warn call.
8161 * sm-signal.cc (signal_state_machine::on_stmt): Likewise.
8162 * sm-taint.cc (taint_state_machine::on_stmt): Replace
8163 warn_for_state and on_transition calls with a get_state
8164 test guarding warn and set_next_state calls.
8165 * sm.h (sm_context::warn_for_state): Replace with...
8166 (sm_context::warn): ...this.
8168 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8170 * diagnostic-manager.cc
8171 (null_assignment_sm_context::null_assignment_sm_context): Add old_state
8172 and ext_state params, initializing m_old_state and m_ext_state.
8173 (null_assignment_sm_context::on_transition): Split into...
8174 (null_assignment_sm_context::get_state): ...this new vfunc
8175 implementation and...
8176 (null_assignment_sm_context::set_next_state): ...this new vfunc
8178 (null_assignment_sm_context::m_old_state): New field.
8179 (null_assignment_sm_context::m_ext_state): New field.
8180 (diagnostic_manager::add_events_for_eedge): Pass in old state and
8181 ext_state when creating sm_ctxt.
8182 * engine.cc (impl_sm_context::on_transition): Split into...
8183 (impl_sm_context::get_state): ...this new vfunc
8184 implementation and...
8185 (impl_sm_context::set_next_state): ...this new vfunc
8187 * sm.h (sm_context::get_state): New pure virtual function.
8188 (sm_context::set_next_state): Likewise.
8189 (sm_context::on_transition): Convert from a pure virtual function
8190 to a regular function implemented in terms of get_state and
8193 2020-09-09 David Malcolm <dmalcolm@redhat.com>
8195 * checker-path.cc (state_change_event::get_desc): Update
8196 state_machine::get_state_name calls to state::get_name.
8197 (warning_event::get_desc): Likewise.
8198 * diagnostic-manager.cc
8199 (null_assignment_sm_context::on_transition): Update comparison
8200 against 0 with comparison with m_sm.get_start_state.
8201 (diagnostic_manager::prune_for_sm_diagnostic): Update
8202 state_machine::get_state_name calls to state::get_name.
8203 * engine.cc (impl_sm_context::on_transition): Likewise.
8204 (exploded_node::get_dot_fillcolor): Use get_id when summing
8206 * program-state.cc (sm_state_map::sm_state_map): Don't hardcode
8207 0 as the start state when initializing m_global_state.
8208 (sm_state_map::print): Use dump_to_pp rather than get_state_name
8209 when dumping states.
8210 (sm_state_map::is_empty_p): Don't hardcode 0 as the start state
8211 when examining m_global_state.
8212 (sm_state_map::hash): Use get_id when hashing states.
8213 (selftest::test_sm_state_map): Use state objects rather than
8214 arbitrary hardcoded integers.
8215 (selftest::test_program_state_merging): Likewise.
8216 (selftest::test_program_state_merging_2): Likewise.
8217 * sm-file.cc (fileptr_state_machine::m_start): Move to base class.
8218 (file_diagnostic::describe_state_change): Use get_start_state.
8219 (fileptr_state_machine::fileptr_state_machine): Drop m_start
8221 * sm-malloc.cc (malloc_state_machine::m_start): Move to base
8223 (malloc_diagnostic::describe_state_change): Use get_start_state.
8224 (possible_null::describe_state_change): Likewise.
8225 (malloc_state_machine::malloc_state_machine): Drop m_start
8227 * sm-pattern-test.cc (pattern_test_state_machine::m_start): Move
8229 (pattern_test_state_machine::pattern_test_state_machine): Drop
8230 m_start initialization.
8231 * sm-sensitive.cc (sensitive_state_machine::m_start): Move to base
8233 (sensitive_state_machine::sensitive_state_machine): Drop m_start
8235 * sm-signal.cc (signal_state_machine::m_start): Move to base
8237 (signal_state_machine::signal_state_machine): Drop m_start
8239 * sm-taint.cc (taint_state_machine::m_start): Move to base class.
8240 (taint_state_machine::taint_state_machine): Drop m_start
8242 * sm.cc (state_machine::state::dump_to_pp): New.
8243 (state_machine::state_machine): Move here from sm.h. Initialize
8244 m_next_state_id and m_start.
8245 (state_machine::add_state): Reimplement in terms of state objects.
8246 (state_machine::get_state_name): Delete.
8247 (state_machine::get_state_by_name): Reimplement in terms of state
8248 objects. Make const.
8249 (state_machine::validate): Delete.
8250 (state_machine::dump_to_pp): Reimplement in terms of state
8252 * sm.h (state_machine::state): New class.
8253 (state_machine::state_t): Convert typedef from "unsigned" to
8254 "const state_machine::state *".
8255 (state_machine::state_machine): Move to sm.cc.
8256 (state_machine::get_default_state): Use m_start rather than
8258 (state_machine::get_state_name): Delete.
8259 (state_machine::get_state_by_name): Make const.
8260 (state_machine::get_start_state): New accessor.
8261 (state_machine::alloc_state_id): New.
8262 (state_machine::m_state_names): Drop in favor of...
8263 (state_machine::m_states): New field
8264 (state_machine::m_start): New field
8265 (start_start_p): Delete.
8267 2020-09-08 David Malcolm <dmalcolm@redhat.com>
8270 * store.cc (binding_map::apply_ctor_val_to_range): Add
8271 error-handling for the cases where we have symbolic offsets.
8273 2020-09-08 David Malcolm <dmalcolm@redhat.com>
8276 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
8277 where min_index == max_index.
8278 (binding_map::apply_ctor_val_to_range): Replace assertion that we
8279 don't have a CONSTRUCTOR value with error-handling.
8281 2020-09-08 David Malcolm <dmalcolm@redhat.com>
8284 * region-model.cc (region_model::on_call_pre): Fix guard on switch
8285 on built-ins to only consider BUILT_IN_NORMAL, rather than other
8288 2020-09-01 David Malcolm <dmalcolm@redhat.com>
8291 * region-model.cc (region_model::deref_rvalue): Add the constraint
8292 that PTR_SVAL is non-NULL.
8294 2020-08-31 David Malcolm <dmalcolm@redhat.com>
8297 * region-model.cc (region_model::on_call_pre): Handle
8298 BUILT_IN_MEMSET_CHK.
8300 2020-08-31 David Malcolm <dmalcolm@redhat.com>
8302 * region-model.cc (region_model::on_call_pre): Gather handling of
8303 builtins and of internal fns into switch statements. Handle
8304 "alloca" and BUILT_IN_ALLOCA_WITH_ALIGN.
8306 2020-08-31 David Malcolm <dmalcolm@redhat.com>
8309 * region.cc (decl_region::get_svalue_for_constructor): Support
8310 apply_ctor_to_region failing.
8311 * store.cc (binding_map::apply_ctor_to_region): Add failure
8313 (binding_map::apply_ctor_val_to_range): Likewise.
8314 (binding_map::apply_ctor_pair_to_child_region): Likewise. Replace
8315 assertion that child_base_offset is not symbolic with error
8317 * store.h (binding_map::apply_ctor_to_region): Convert return type
8319 (binding_map::apply_ctor_val_to_range): Likewise.
8320 (binding_map::apply_ctor_pair_to_child_region): Likewise.
8322 2020-08-31 David Malcolm <dmalcolm@redhat.com>
8325 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
8326 by calling a new binding_map::apply_ctor_val_to_range subroutine.
8327 Split out the existing non-CONSTRUCTOR-handling code to a new
8328 apply_ctor_pair_to_child_region subroutine.
8329 (binding_map::apply_ctor_val_to_range): New.
8330 (binding_map::apply_ctor_pair_to_child_region): New, split out
8331 from binding_map::apply_ctor_to_region as noted above.
8332 * store.h (binding_map::apply_ctor_val_to_range): New decl.
8333 (binding_map::apply_ctor_pair_to_child_region): New decl.
8335 2020-08-31 David Malcolm <dmalcolm@redhat.com>
8338 * region-model-manager.cc
8339 (region_model_manager::maybe_fold_unaryop): Handle VIEW_CONVERT_EXPR.
8340 (region_model_manager::get_or_create_cast): Move logic for
8341 real->integer casting to...
8342 (get_code_for_cast): ...this new function, and add logic for
8343 real->non-integer casts.
8344 (region_model_manager::maybe_fold_sub_svalue): Handle
8347 (region_model::add_any_constraints_from_gassign): Likewise.
8348 * svalue.cc (svalue::maybe_undo_cast): Likewise.
8349 (unaryop_svalue::dump_to_pp): Likewise.
8351 2020-08-26 David Malcolm <dmalcolm@redhat.com>
8354 * region-model-manager.cc
8355 (region_model_manager::get_or_create_widening_svalue): Assert that
8356 neither of the inputs are themselves widenings.
8357 * store.cc (store::eval_alias_1): The initial value of a pointer
8358 can't point to a region that was allocated on the heap after the
8359 beginning of the path. A widened pointer value can't alias anything
8360 that the initial pointer value can't alias.
8361 * svalue.cc (svalue::can_merge_p): Merge BINOP (X, OP, CST) with X
8362 to a widening svalue. Merge
8363 BINOP(WIDENING(BASE, BINOP(BASE, X)), X) and BINOP(BASE, X) to
8364 to the LHS of the first BINOP.
8366 2020-08-26 David Malcolm <dmalcolm@redhat.com>
8369 * region-model.h (class compound_svalue): Document that all keys
8371 (compound_svalue::compound_svalue): Move definition to svalue.cc.
8372 * store.cc (binding_map::apply_ctor_to_region): Handle
8373 initializers for trailing arrays with incomplete size.
8374 * svalue.cc (compound_svalue::compound_svalue): Move definition
8375 here from region-model.h. Add assertion that all keys are
8378 2020-08-22 David Malcolm <dmalcolm@redhat.com>
8381 * region-model-manager.cc
8382 (region_model_manager::maybe_fold_binop): Fold bitwise "& 0" to 0.
8384 2020-08-22 David Malcolm <dmalcolm@redhat.com>
8386 * store.cc (store::eval_alias): Make const. Split out 2nd half
8387 into store::eval_alias_1 and call it twice for symmetry, avoiding
8389 (store::eval_alias_1): New function, split out from the above.
8390 * store.h (store::eval_alias): Make const.
8391 (store::eval_alias_1): New decl.
8393 2020-08-22 David Malcolm <dmalcolm@redhat.com>
8395 * region-model.cc (region_model::push_frame): Bind the default
8396 SSA name for each parm if it exists, falling back to the parm
8397 itself otherwise, rather than doing both.
8399 2020-08-20 David Malcolm <dmalcolm@redhat.com>
8402 * region-model-manager.cc
8403 (region_model_manager::get_field_region): Assert that field is a
8405 * region.cc (region::get_subregions_for_binding): In
8406 union-handling, filter the TYPE_FIELDS traversal to just FIELD_DECLs.
8408 2020-08-20 David Malcolm <dmalcolm@redhat.com>
8411 * region-model.cc (region_model::get_gassign_result): For
8412 comparisons, only use eval_condition when the lhs has boolean
8413 type, and use get_or_create_constant_svalue on the boolean
8414 constants directly rather than via get_rvalue.
8416 2020-08-19 David Malcolm <dmalcolm@redhat.com>
8419 * region-model.cc (region_model::deref_rvalue): Rather than
8420 attempting to handle all svalue kinds in the switch, only cover
8421 the special cases, and move symbolic-region handling to after
8422 the switch, thus implicitly handling the missing case SK_COMPOUND.
8424 2020-08-19 David Malcolm <dmalcolm@redhat.com>
8427 * region-model-manager.cc
8428 (region_model_manager::maybe_fold_binop): Check that we have an
8429 integral type before calling build_int_cst.
8431 2020-08-19 David Malcolm <dmalcolm@redhat.com>
8434 * region-model-manager.cc
8435 (region_model_manager::get_or_create_cast): Use FIX_TRUNC_EXPR for
8436 casting from REAL_TYPE to INTEGER_TYPE.
8438 2020-08-19 David Malcolm <dmalcolm@redhat.com>
8441 * region-model.cc (region_model::called_from_main_p): New.
8442 (region_model::get_store_value): Move handling for globals into...
8443 (region_model::get_initial_value_for_global): ...this new
8444 function, and add logic for extracting values from decl
8446 * region-model.h (decl_region::get_svalue_for_constructor): New
8448 (decl_region::get_svalue_for_initializer): New decl.
8449 (region_model::called_from_main_p): New decl.
8450 (region_model::get_initial_value_for_global): New.
8451 * region.cc (decl_region::maybe_get_constant_value): Move logic
8452 for getting an svalue from a CONSTRUCTOR node to...
8453 (decl_region::get_svalue_for_constructor): ...this new function.
8454 (decl_region::get_svalue_for_initializer): New.
8455 * store.cc (get_svalue_for_ctor_val): Rewrite in terms of
8456 region_model::get_rvalue.
8457 * store.h (binding_cluster::get_map): New accessor.
8459 2020-08-19 David Malcolm <dmalcolm@redhat.com>
8462 * region.cc (get_field_at_bit_offset): Gracefully handle negative
8463 values for bit_offset.
8465 2020-08-18 David Malcolm <dmalcolm@redhat.com>
8467 * region-model.cc (region_model::get_rvalue_1): Fix name of local.
8469 2020-08-18 David Malcolm <dmalcolm@redhat.com>
8472 * region-model.cc (region_model::get_rvalue_1): Handle
8473 unrecognized tree codes by returning "UNKNOWN.
8475 2020-08-18 David Malcolm <dmalcolm@redhat.com>
8478 * region-model.cc (region_model::get_gassign_result): Handle various
8479 VEC_* tree codes by returning UNKNOWN.
8480 (region_model::on_assignment): Handle unrecognized tree codes by
8481 setting lhs to an unknown value, rather than issuing a "sorry" and
8484 2020-08-17 David Malcolm <dmalcolm@redhat.com>
8487 * region-model-manager.cc (get_region_for_unexpected_tree_code):
8488 Handle ctxt being NULL.
8490 2020-08-17 David Malcolm <dmalcolm@redhat.com>
8493 * region.cc (region::get_subregions_for_binding): Check for "type"
8496 2020-08-17 David Malcolm <dmalcolm@redhat.com>
8499 * store.cc (get_svalue_for_ctor_val): New.
8500 (binding_map::apply_ctor_to_region): Call it.
8502 2020-08-14 David Malcolm <dmalcolm@redhat.com>
8506 * region-model.cc (region_model::get_store_value): Call
8507 maybe_get_constant_value on decl_regions first.
8508 * region-model.h (decl_region::maybe_get_constant_value): New decl.
8509 * region.cc (decl_region::get_stack_depth): Likewise.
8510 (decl_region::maybe_get_constant_value): New.
8511 * store.cc (get_subregion_within_ctor): New.
8512 (binding_map::apply_ctor_to_region): New.
8513 * store.h (binding_map::apply_ctor_to_region): New decl.
8515 2020-08-14 David Malcolm <dmalcolm@redhat.com>
8518 * store.cc (store::mark_as_escaped): Reject attempts to
8519 get a cluster for an unknown pointer.
8521 2020-08-13 David Malcolm <dmalcolm@redhat.com>
8537 * analyzer-logging.cc: Ignore "-Wformat-diag".
8538 (logger::enter_scope): Use inc_indent in both overloads.
8539 (logger::exit_scope): Use dec_indent.
8540 * analyzer-logging.h (logger::inc_indent): New.
8541 (logger::dec_indent): New.
8542 * analyzer-selftests.cc (run_analyzer_selftests): Call
8543 analyzer_store_cc_tests.
8544 * analyzer-selftests.h (analyzer_store_cc_tests): New decl.
8545 * analyzer.cc (get_stmt_location): New function.
8546 * analyzer.h (class initial_svalue): New forward decl.
8547 (class unaryop_svalue): New forward decl.
8548 (class binop_svalue): New forward decl.
8549 (class sub_svalue): New forward decl.
8550 (class unmergeable_svalue): New forward decl.
8551 (class placeholder_svalue): New forward decl.
8552 (class widening_svalue): New forward decl.
8553 (class compound_svalue): New forward decl.
8554 (class conjured_svalue): New forward decl.
8555 (svalue_set): New typedef.
8556 (class map_region): Delete.
8557 (class array_region): Delete.
8558 (class frame_region): New forward decl.
8559 (class function_region): New forward decl.
8560 (class label_region): New forward decl.
8561 (class decl_region): New forward decl.
8562 (class element_region): New forward decl.
8563 (class offset_region): New forward decl.
8564 (class cast_region): New forward decl.
8565 (class field_region): New forward decl.
8566 (class string_region): New forward decl.
8567 (class region_model_manager): New forward decl.
8568 (class store_manager): New forward decl.
8569 (class store): New forward decl.
8570 (class call_details): New forward decl.
8571 (struct svalue_id_merger_mapping): Delete.
8572 (struct canonicalization): Delete.
8573 (class function_point): New forward decl.
8574 (class engine): New forward decl.
8575 (dump_tree): New function decl.
8576 (print_quoted_type): New function decl.
8577 (readability_comparator): New function decl.
8578 (tree_cmp): New function decl.
8579 (class path_var): Move here from region-model.h
8580 (bit_offset_t, bit_size_t, byte_size_t): New typedefs.
8581 (class region_offset): New class.
8582 (get_stmt_location): New decl.
8583 (struct member_function_hash_traits): New struct.
8584 (class consolidation_map): New class.
8585 Ignore "-Wformat-diag".
8586 * analyzer.opt (-param=analyzer-max-svalue-depth=): New param.
8587 (-param=analyzer-max-enodes-for-full-dump=): New param.
8588 * call-string.cc: Ignore -Wformat-diag.
8589 * checker-path.cc: Move includes of "analyzer/call-string.h" and
8590 "analyzer/program-point.h" to before "analyzer/region-model.h",
8591 and also include "analyzer/store.h" before it.
8592 (state_change_event::state_change_event): Replace "tree var" param
8593 with "const svalue *sval". Convert "origin" param from tree to
8595 (state_change_event::get_desc): Call get_representative_tree to
8596 convert the var and origin from const svalue * to tree. Use
8597 svalue::get_desc rather than %qE when describing state changes.
8598 (checker_path::add_final_event): Use get_stmt_location.
8599 * checker-path.h (state_change_event::state_change_event): Port
8600 from tree to const svalue *.
8601 (state_change_event::get_lvalue): Delete.
8602 (state_change_event::get_dest_function): New.
8603 (state_change_event::m_var): Replace with...
8604 (state_change_event::m_sval): ...this.
8605 (state_change_event::m_origin): Convert from tree to
8607 * constraint-manager.cc: Include "analyzer/call-string.h",
8608 "analyzer/program-point.h", and "analyzer/store.h" before
8609 "analyzer/region-model.h".
8610 (struct bound, struct range): Move to constraint-manager.h.
8611 (compare_constants): New function.
8612 (range::dump): Rename to...
8613 (range::dump_to_pp): ...this. Support NULL constants.
8614 (range::dump): Reintroduce for dumping to stderr.
8615 (range::constrained_to_single_element): Return result, rather than
8617 (range::eval_condition): New.
8618 (range::below_lower_bound): New.
8619 (range::above_upper_bound): New.
8620 (equiv_class::equiv_class): Port from svalue_id to const svalue *.
8621 (equiv_class::print): Likewise.
8622 (equiv_class::hash): Likewise.
8623 (equiv_class::operator==): Port from svalue_id to const svalue *.
8624 (equiv_class::add): Port from svalue_id to const svalue *. Drop
8626 (equiv_class::del): Port from svalue_id to const svalue *.
8627 (equiv_class::get_representative): Likewise.
8628 (equiv_class::remap_svalue_ids): Delete.
8629 (svalue_id_cmp_by_id): Rename to...
8630 (svalue_cmp_by_ptr): ...this, porting from svalue_id to
8632 (equiv_class::canonicalize): Update qsort comparator.
8633 (constraint::implied_by): New.
8634 (constraint_manager::constraint_manager): Copy m_mgr in copy ctor.
8635 (constraint_manager::dump_to_pp): Add "multiline" param
8636 (constraint_manager::dump): Pass "true" for "multiline".
8637 (constraint_manager::add_constraint): Port from svalue_id to
8638 const svalue *. Split out second part into...
8639 (constraint_manager::add_unknown_constraint): ...this new
8640 function. Remove self-constraints when merging equivalence
8642 (constraint_manager::add_constraint_internal): Remove constraints
8643 that would be implied by the new constraint. Port from svalue_id
8645 (constraint_manager::get_equiv_class_by_sid): Rename to...
8646 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
8647 from svalue_id to const svalue *.
8648 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
8650 (constraint_manager::eval_condition): Make const. Call
8651 compare_constants and return early if it provides a known result.
8652 (constraint_manager::get_ec_bounds): New.
8653 (constraint_manager::eval_condition): New overloads. Make
8654 existing one const, and use compare_constants.
8655 (constraint_manager::purge): Convert "p" param to a template
8656 rather that an abstract base class. Port from svalue_id to
8658 (class dead_svalue_purger): New class.
8659 (constraint_manager::remap_svalue_ids): Delete.
8660 (constraint_manager::on_liveness_change): New.
8661 (equiv_class_cmp): Port from svalue_id to const svalue *.
8662 (constraint_manager::canonicalize): Likewise. Combine with
8663 purging of redundant equivalence classes and constraints.
8664 (class cleaned_constraint_manager): Delete.
8665 (class merger_fact_visitor): Make "m_cm_b" const. Add "m_merger"
8667 (merger_fact_visitor::fact): Port from svalue_id to const svalue *.
8668 Add special case for widening.
8669 (constraint_manager::merge): Port from svalue_id to const svalue *.
8670 (constraint_manager::clean_merger_input): Delete.
8671 (constraint_manager::for_each_fact): Port from svalue_id to
8673 (constraint_manager::validate): Likewise.
8674 (selftest::test_constraint_conditions): Provide a
8675 region_model_manager when creating region_model instances.
8676 Add test for self-equality not creating equivalence classes.
8677 (selftest::test_transitivity): Provide a region_model_manager when
8678 creating region_model instances. Verify that EC-merging happens
8679 when constraints are implied.
8680 (selftest::test_constant_comparisons): Provide a
8681 region_model_manager when creating region_model instances.
8682 (selftest::test_constraint_impl): Likewise. Remove over-specified
8684 (selftest::test_equality): Provide a region_model_manager when
8685 creating region_model instances.
8686 (selftest::test_many_constants): Likewise. Provide a
8687 program_point when testing merging.
8688 (selftest::run_constraint_manager_tests): Move call to
8689 test_constant_comparisons to outside the transitivity guard.
8690 * constraint-manager.h (struct bound): Move here from
8691 constraint-manager.cc.
8692 (struct range): Likewise.
8693 (struct::eval_condition): New decl.
8694 (struct::below_lower_bound): New decl.
8695 (struct::above_upper_bound): New decl.
8696 (equiv_class::add): Port from svalue_id to const svalue *.
8697 (equiv_class::del): Likewise.
8698 (equiv_class::get_representative): Likewise.
8699 (equiv_class::remap_svalue_ids): Drop.
8700 (equiv_class::m_cst_sid): Convert to..
8701 (equiv_class::m_cst_sval): ...this.
8702 (equiv_class::m_vars): Port from svalue_id to const svalue *.
8703 (constraint::bool implied_by): New decl.
8704 (fact_visitor::on_fact): Port from svalue_id to const svalue *.
8705 (constraint_manager::constraint_manager): Add mgr param.
8706 (constraint_manager::clone): Delete.
8707 (constraint_manager::maybe_get_constant): Delete.
8708 (constraint_manager::get_sid_for_constant): Delete.
8709 (constraint_manager::get_num_svalues): Delete.
8710 (constraint_manager::dump_to_pp): Add "multiline" param.
8711 (constraint_manager::get_equiv_class): Port from svalue_id to
8713 (constraint_manager::add_constraint): Likewise.
8714 (constraint_manager::get_equiv_class_by_sid): Rename to...
8715 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
8716 from svalue_id to const svalue *.
8717 (constraint_manager::add_unknown_constraint): New decl.
8718 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
8720 (constraint_manager::eval_condition): Likewise. Add overloads.
8721 (constraint_manager::get_ec_bounds): New decl.
8722 (constraint_manager::purge): Convert to template.
8723 (constraint_manager::remap_svalue_ids): Delete.
8724 (constraint_manager::on_liveness_change): New decl.
8725 (constraint_manager::canonicalize): Drop param.
8726 (constraint_manager::clean_merger_input): Delete.
8727 (constraint_manager::m_mgr): New field.
8728 * diagnostic-manager.cc: Move includes of
8729 "analyzer/call-string.h" and "analyzer/program-point.h" to before
8730 "analyzer/region-model.h", and also include "analyzer/store.h"
8732 (saved_diagnostic::saved_diagnostic): Add "sval" param.
8733 (diagnostic_manager::diagnostic_manager): Add engine param.
8734 (diagnostic_manager::add_diagnostic): Add "sval" param, passing it
8735 to saved_diagnostic ctor. Update overload to pass NULL for it.
8736 (dedupe_winners::dedupe_winners): Add engine param.
8737 (dedupe_winners::add): Add "eg" param. Pass m_engine to
8739 (dedupe_winner::m_engine): New field.
8740 (diagnostic_manager::emit_saved_diagnostics): Pass engine to
8741 dedupe_winners. Pass &eg when adding candidates. Pass svalue
8742 rather than tree to prune_path. Use get_stmt_location to get
8743 primary location of diagnostic.
8744 (diagnostic_manager::emit_saved_diagnostic): Likewise.
8745 (get_any_origin): Drop.
8746 (state_change_event_creator::on_global_state_change): Pass NULL
8747 const svalue * rather than NULL_TREE trees to state_change_event
8749 (state_change_event_creator::on_state_change): Port from tree and
8750 svalue_id to const svalue *.
8751 (for_each_state_change): Port from svalue_id to const svalue *.
8752 (struct null_assignment_sm_context): New.
8753 (diagnostic_manager::add_events_for_eedge): Add state change
8754 events for assignment to NULL.
8755 (diagnostic_manager::prune_path): Update param from tree to
8757 (diagnostic_manager::prune_for_sm_diagnostic): Port from tracking
8758 by tree to by const svalue *.
8759 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add sval
8761 (saved_diagnostic::m_sval): New field.
8762 (diagnostic_manager::diagnostic_manager): Add engine param.
8763 (diagnostic_manager::get_engine): New.
8764 (diagnostic_manager::add_diagnostic): Add "sval" param.
8765 (diagnostic_manager::prune_path): Likewise.
8766 (diagnostic_manager::prune_for_sm_diagnostic): New overload.
8767 (diagnostic_manager::m_eng): New field.
8768 * engine.cc: Move includes of "analyzer/call-string.h" and
8769 "analyzer/program-point.h" to before "analyzer/region-model.h",
8770 and also include "analyzer/store.h" before it.
8771 (impl_region_model_context::impl_region_model_context): Update for
8772 removal of m_change field.
8773 (impl_region_model_context::remap_svalue_ids): Delete.
8774 (impl_region_model_context::on_svalue_leak): New.
8775 (impl_region_model_context::on_svalue_purge): Delete.
8776 (impl_region_model_context::on_liveness_change): New.
8777 (impl_region_model_context::on_unknown_change): Update param
8778 from svalue_id to const svalue *. Add is_mutable param.
8779 (setjmp_svalue::compare_fields): Delete.
8780 (setjmp_svalue::accept): New.
8781 (setjmp_svalue::add_to_hash): Delete.
8782 (setjmp_svalue::dump_to_pp): New.
8783 (setjmp_svalue::print_details): Delete.
8784 (impl_sm_context::impl_sm_context): Drop "change" param.
8785 (impl_sm_context::get_fndecl_for_call): Drop "m_change".
8786 (impl_sm_context::on_transition): Drop ATTRIBUTE_UNUSED from
8787 "stmt" param. Drop m_change. Port from svalue_id to
8789 (impl_sm_context::warn_for_state): Drop m_change. Port from
8790 svalue_id to const svalue *.
8791 (impl_sm_context::get_readable_tree): Rename to...
8792 (impl_sm_context::get_diagnostic_tree): ...this. Port from
8793 svalue_id to const svalue *.
8794 (impl_sm_context::is_zero_assignment): New.
8795 (impl_sm_context::m_change): Delete field.
8796 (leak_stmt_finder::find_stmt): Handle m_var being NULL.
8797 (readability): Increase penalty for MEM_REF. For SSA_NAMEs,
8798 slightly favor the underlying var over the SSA name. Heavily
8799 penalize temporaries. Handle RESULT_DECL.
8800 (readability_comparator): Make non-static. Consider stack depths.
8801 (impl_region_model_context::on_state_leak): Convert from svalue_id
8802 to const svalue *, updating for region_model changes. Use
8804 (impl_region_model_context::on_inherited_svalue): Delete.
8805 (impl_region_model_context::on_cast): Delete.
8806 (impl_region_model_context::on_condition): Drop m_change.
8807 (impl_region_model_context::on_phi): Likewise.
8808 (impl_region_model_context::on_unexpected_tree_code): Handle t
8810 (point_and_state::validate): Update stack checking for
8811 region_model changes.
8812 (eg_traits::dump_args_t::show_enode_details_p): New.
8813 (exploded_node::exploded_node): Initialize m_num_processed_stmts.
8814 (exploded_node::get_processed_stmt): New function.
8815 (exploded_node::get_dot_fillcolor): Add more colors.
8816 (exploded_node::dump_dot): Guard the printing of the point and
8817 state with show_enode_details_p. Print the processed stmts for
8818 this enode after the initial state.
8819 (exploded_node::dump_to_pp): Pass true for new multiline param
8820 of program_state::dump_to_pp.
8821 (exploded_node::on_stmt): Drop "change" param. Log the stmt.
8822 Set input_location. Implement __analyzer_describe. Update
8823 implementation of __analyzer_dump and __analyzer_eval.
8824 Remove purging of sm-state for unknown fncalls from here.
8825 (exploded_node::on_edge): Drop "change" param.
8826 (exploded_node::on_longjmp): Port from region_id/svalue_id to
8827 const region */const svalue *. Call program_state::detect_leaks.
8829 (exploded_node::detect_leaks): Update for changes to region_model.
8830 Call program_state::detect_leaks.
8831 (exploded_edge::exploded_edge): Drop ext_state and change params.
8832 (exploded_edge::dump_dot): "args" is no longer used. Drop dumping
8834 (exploded_graph::exploded_graph): Pass engine to
8835 m_diagnostic_manager ctor. Use program_point::origin.
8836 (exploded_graph::add_function_entry): Drop ctxt. Use
8837 program_state::push_frame. Drop state_change.
8838 (exploded_graph::get_or_create_node): Drop "change" param. Add
8839 "enode_for_diag" param. Update dumping calls for API changes.
8840 Pass point to can_merge_with_p. Show enode indices
8841 within -Wanalyzer-too-complex diagnostic for hitting the per-point
8843 (exploded_graph::add_edge): Drop "change" param. Log which nodes
8844 are being connected. Update for changes to exploded_edge ctor.
8845 (exploded_graph::get_per_program_point_data): New.
8846 (exploded_graph::process_worklist): Pass point to
8847 can_merge_with_p. Drop state_change. Update dumping call for API
8849 (exploded_graph::process_node): Drop state_change. Split the
8850 node in-place if an sm-state-change occurs. Update
8851 m_num_processed_stmts. Update dumping calls for API change.
8852 (exploded_graph::log_stats): Call engine::log_stats.
8853 (exploded_graph::dump_states_for_supernode): Update dumping
8855 (exploded_path::feasible_p): Add "eng" and "eg" params.
8856 Rename "i" to "end_idx". Pass the manager to the region_model
8857 ctor. Update for every processed stmt in the enode, not just the
8858 first. Keep track of which snodes have been visited, and call
8859 loop_replay_fixup when revisiting one.
8860 (enode_label::get_text): Update dump call for new param.
8861 (exploded_graph::dump_exploded_nodes): Likewise.
8862 (exploded_graph::get_node_by_index): New.
8863 (impl_run_checkers): Create engine instance and pass its address
8864 to extrinsic_state ctor.
8866 (impl_region_model_context::impl_region_model_context): Drop
8868 (impl_region_model_context::void remap_svalue_ids): Delete.
8869 (impl_region_model_context::on_svalue_purge): Delete.
8870 (impl_region_model_context::on_svalue_leak): New.
8871 (impl_region_model_context::on_liveness_change): New.
8872 (impl_region_model_context::on_state_leak): Update signature.
8873 (impl_region_model_context::on_inherited_svalue): Delete.
8874 (impl_region_model_context::on_cast): Delete.
8875 (impl_region_model_context::on_unknown_change): Update signature.
8876 (impl_region_model_context::m_change): Delete.
8877 (eg_traits::dump_args_t::show_enode_details_p): New.
8878 (exploded_node::on_stmt): Drop "change" param.
8879 (exploded_node::on_edge): Likewise.
8880 (exploded_node::get_processed_stmt): New decl.
8881 (exploded_node::m_num_processed_stmts): New field.
8882 (exploded_edge::exploded_edge): Drop ext_state and change params.
8883 (exploded_edge::m_change): Delete.
8884 (exploded_graph::get_engine): New accessor.
8885 (exploded_graph::get_or_create_node): Drop "change" param. Add
8886 "enode_for_diag" param.
8887 (exploded_graph::add_edge): Drop "change" param.
8888 (exploded_graph::get_per_program_point_data): New decl.
8889 (exploded_graph::get_node_by_index): New decl.
8890 (exploded_path::feasible_p): Add "eng" and "eg" params.
8891 * program-point.cc: Include "analyzer/store.h" before including
8892 "analyzer/region-model.h".
8893 (function_point::function_point): Move here from
8895 (function_point::get_function): Likewise.
8896 (function_point::from_function_entry): Likewise.
8897 (function_point::before_supernode): Likewise.
8898 (function_point::next_stmt): New function.
8899 * program-point.h (function_point::function_point): Move
8900 implementation from here to program-point.cc.
8901 (function_point::get_function): Likewise.
8902 (function_point::from_function_entry): Likewise.
8903 (function_point::before_supernode): Likewise.
8904 (function_point::next_stmt): New decl.
8905 (program_point::operator!=): New.
8906 (program_point::origin): New.
8907 (program_point::next_stmt): New.
8908 (program_point::m_function_point): Make non-const.
8909 * program-state.cc: Move includes of "analyzer/call-string.h" and
8910 "analyzer/program-point.h" to before "analyzer/region-model.h",
8911 and also include "analyzer/store.h" before it.
8912 (extrinsic_state::get_model_manager): New.
8913 (sm_state_map::sm_state_map): Pass in sm and sm_idx to ctor,
8914 rather than pass the around.
8915 (sm_state_map::clone_with_remapping): Delete.
8916 (sm_state_map::print): Remove "sm" param in favor of "m_sm". Add
8917 "simple" and "multiline" params and support multiline vs single
8919 (sm_state_map::dump): Remove "sm" param in favor of "m_sm". Add
8921 (sm_state_map::hash): Port from svalue_id to const svalue *.
8922 (sm_state_map::operator==): Likewise.
8923 (sm_state_map::get_state): Likewise. Call canonicalize_svalue on
8924 input. Handle inheritance of sm-state. Call get_default_state.
8925 (sm_state_map::get_origin): Port from svalue_id to const svalue *.
8926 (sm_state_map::set_state): Likewise. Pass in ext_state. Reject
8927 attempts to set state on UNKNOWN.
8928 (sm_state_map::impl_set_state): Port from svalue_id to
8929 const svalue *. Pass in ext_state. Call canonicalize_svalue on
8931 (sm_state_map::purge_for_unknown_fncall): Delete.
8932 (sm_state_map::on_svalue_leak): New.
8933 (sm_state_map::remap_svalue_ids): Delete.
8934 (sm_state_map::on_liveness_change): New.
8935 (sm_state_map::on_unknown_change): Reimplement.
8936 (sm_state_map::on_svalue_purge): Delete.
8937 (sm_state_map::on_inherited_svalue): Delete.
8938 (sm_state_map::on_cast): Delete.
8939 (sm_state_map::validate): Delete.
8940 (sm_state_map::canonicalize_svalue): New.
8941 (program_state::program_state): Update to pass manager to
8942 region_model's ctor. Constify num_states and pass state machine
8943 and index to sm_state_map ctor.
8944 (program_state::print): Update for changes to dump API.
8945 (program_state::dump_to_pp): Ignore the summarize param. Add
8947 (program_state::dump_to_file): Add "multiline" param.
8948 (program_state::dump): Pass "true" for new "multiline" param.
8949 (program_state::push_frame): New.
8950 (program_state::on_edge): Drop "change" param. Call
8951 program_state::detect_leaks.
8952 (program_state::prune_for_point): Add enode_for_diag param.
8953 Reimplement based on store class. Call detect_leaks
8954 (program_state::remap_svalue_ids): Delete.
8955 (program_state::get_representative_tree): Port from svalue_id to
8957 (program_state::can_merge_with_p): Add "point" param. Add early
8958 reject for sm-differences. Drop id remapping.
8959 (program_state::validate): Drop region model and sm_state_map
8961 (state_change::sm_change::dump): Delete.
8962 (state_change::sm_change::remap_svalue_ids): Delete.
8963 (state_change::sm_change::on_svalue_purge): Delete.
8964 (log_set_of_svalues): New.
8965 (state_change::sm_change::validate): Delete.
8966 (state_change::state_change): Delete.
8967 (state_change::add_sm_change): Delete.
8968 (state_change::affects_p): Delete.
8969 (state_change::dump): Delete.
8970 (state_change::remap_svalue_ids): Delete.
8971 (state_change::on_svalue_purge): Delete.
8972 (state_change::validate): Delete.
8973 (selftest::assert_dump_eq): Delete.
8974 (ASSERT_DUMP_EQ): Delete.
8975 (selftest::test_sm_state_map): Update for changes to region_model
8976 and sm_state_map, porting from svalue_id to const svalue *.
8977 (selftest::test_program_state_dumping): Likewise. Drop test of
8978 dumping, renaming to...
8979 (selftest::test_program_state_1): ...this.
8980 (selftest::test_program_state_dumping_2): Likewise, renaming to...
8981 (selftest::test_program_state_2): ...this.
8982 (selftest::test_program_state_merging): Update for changes to
8984 (selftest::test_program_state_merging_2): Likewise.
8985 (selftest::analyzer_program_state_cc_tests): Update for renamed
8987 * program-state.h (extrinsic_state::extrinsic_state): Add logger
8989 (extrinsic_state::get_logger): New accessor.
8990 (extrinsic_state::get_engine): New accessor.
8991 (extrinsic_state::get_model_manager): New accessor.
8992 (extrinsic_state::m_logger): New field.
8993 (extrinsic_state::m_engine): New field.
8994 (struct default_hash_traits<svalue_id>): Delete.
8995 (pod_hash_traits<svalue_id>::hash): Delete.
8996 (pod_hash_traits<svalue_id>::equal): Delete.
8997 (pod_hash_traits<svalue_id>::mark_deleted): Delete.
8998 (pod_hash_traits<svalue_id>::mark_empty): Delete.
8999 (pod_hash_traits<svalue_id>::is_deleted): Delete.
9000 (pod_hash_traits<svalue_id>::is_empty): Delete.
9001 (sm_state_map::entry_t::entry_t): Port from svalue_id to
9003 (sm_state_map::entry_t::m_origin): Likewise.
9004 (sm_state_map::map_t): Likewise.
9005 (sm_state_map::sm_state_map): Add state_machine and index params.
9006 (sm_state_map::clone_with_remapping): Delete.
9007 (sm_state_map::print): Drop sm param; add simple and multiline
9009 (sm_state_map::dump): Drop sm param; add simple param.
9010 (sm_state_map::get_state): Port from svalue_id to const svalue *.
9011 Add ext_state param.
9012 (sm_state_map::get_origin): Likewise.
9013 (sm_state_map::set_state): Likewise.
9014 (sm_state_map::impl_set_state): Likewise.
9015 (sm_state_map::purge_for_unknown_fncall): Delete.
9016 (sm_state_map::remap_svalue_ids): Delete.
9017 (sm_state_map::on_svalue_purge): Delete.
9018 (sm_state_map::on_svalue_leak): New.
9019 (sm_state_map::on_liveness_change): New.
9020 (sm_state_map::on_inherited_svalue): Delete.
9021 (sm_state_map::on_cast): Delete.
9022 (sm_state_map::validate): Delete.
9023 (sm_state_map::on_unknown_change): Port from svalue_id to
9024 const svalue *. Add is_mutable and ext_state params.
9025 (sm_state_map::canonicalize_svalue): New.
9026 (sm_state_map::m_sm): New field.
9027 (sm_state_map::m_sm_idx): New field.
9028 (program_state::operator=): Delete.
9029 (program_state::dump_to_pp): Drop "summarize" param, adding
9030 "simple" and "multiline".
9031 (program_state::dump_to_file): Likewise.
9032 (program_state::dump): Rename "summarize" to "simple".
9033 (program_state::push_frame): New.
9034 (program_state::get_current_function): New.
9035 (program_state::on_edge): Drop "change" param.
9036 (program_state::prune_for_point): Likewise. Add enode_for_diag
9038 (program_state::remap_svalue_ids): Delete.
9039 (program_state::get_representative_tree): Port from svalue_id to
9041 (program_state::can_purge_p): Likewise. Pass ext_state to get_state.
9042 (program_state::can_merge_with_p): Add point param.
9043 (program_state::detect_leaks): New.
9044 (state_change_visitor::on_state_change): Port from tree and
9045 svalue_id to a pair of const svalue *.
9046 (class state_change): Delete.
9047 * region.cc: New file.
9048 * region-model-impl-calls.cc: New file.
9049 * region-model-manager.cc: New file.
9050 * region-model-reachability.cc: New file.
9051 * region-model-reachability.h: New file.
9052 * region-model.cc: Include "analyzer/call-string.h",
9053 "analyzer/program-point.h", and "analyzer/store.h" before
9054 "analyzer/region-model.h". Include
9055 "analyzer/region-model-reachability.h".
9056 (dump_tree): Make non-static.
9057 (dump_quoted_tree): Make non-static.
9058 (print_quoted_type): Make non-static.
9059 (path_var::dump): Delete.
9060 (dump_separator): Delete.
9061 (class impl_constraint_manager): Delete.
9062 (svalue_id::print): Delete.
9063 (svalue_id::dump_node_name_to_pp): Delete.
9064 (svalue_id::validate): Delete.
9065 (region_id::print): Delete.
9066 (region_id::dump_node_name_to_pp): Delete.
9067 (region_id::validate): Delete.
9068 (region_id_set::region_id_set): Delete.
9069 (svalue_id_set::svalue_id_set): Delete.
9070 (svalue::operator==): Delete.
9071 (svalue::hash): Delete.
9072 (svalue::print): Delete.
9073 (svalue::dump_dot_to_pp): Delete.
9074 (svalue::remap_region_ids): Delete.
9075 (svalue::walk_for_canonicalization): Delete.
9076 (svalue::get_child_sid): Delete.
9077 (svalue::maybe_get_constant): Delete.
9078 (region_svalue::compare_fields): Delete.
9079 (region_svalue::add_to_hash): Delete.
9080 (region_svalue::print_details): Delete.
9081 (region_svalue::dump_dot_to_pp): Delete.
9082 (region_svalue::remap_region_ids): Delete.
9083 (region_svalue::merge_values): Delete.
9084 (region_svalue::walk_for_canonicalization): Delete.
9085 (region_svalue::eval_condition): Delete.
9086 (constant_svalue::compare_fields): Delete.
9087 (constant_svalue::add_to_hash): Delete.
9088 (constant_svalue::merge_values): Delete.
9089 (constant_svalue::eval_condition): Move to svalue.cc.
9090 (constant_svalue::print_details): Delete.
9091 (constant_svalue::get_child_sid): Delete.
9092 (unknown_svalue::compare_fields): Delete.
9093 (unknown_svalue::add_to_hash): Delete.
9094 (unknown_svalue::print_details): Delete.
9095 (poison_kind_to_str): Move to svalue.cc.
9096 (poisoned_svalue::compare_fields): Delete.
9097 (poisoned_svalue::add_to_hash): Delete.
9098 (poisoned_svalue::print_details): Delete.
9099 (region_kind_to_str): Move to region.cc and reimplement.
9100 (region::operator==): Delete.
9101 (region::get_parent_region): Delete.
9102 (region::set_value): Delete.
9103 (region::become_active_view): Delete.
9104 (region::deactivate_any_active_view): Delete.
9105 (region::deactivate_view): Delete.
9106 (region::get_value): Delete.
9107 (region::get_inherited_child_sid): Delete.
9108 (region_model::copy_region): Delete.
9109 (region_model::copy_struct_region): Delete.
9110 (region_model::copy_union_region): Delete.
9111 (region_model::copy_array_region): Delete.
9112 (region::hash): Delete.
9113 (region::print): Delete.
9114 (region::dump_dot_to_pp): Delete.
9115 (region::dump_to_pp): Delete.
9116 (region::dump_child_label): Delete.
9117 (region::validate): Delete.
9118 (region::remap_svalue_ids): Delete.
9119 (region::remap_region_ids): Delete.
9120 (region::add_view): Delete.
9121 (region::get_view): Delete.
9122 (region::region): Move to region.cc.
9123 (region::add_to_hash): Delete.
9124 (region::print_fields): Delete.
9125 (region::non_null_p): Delete.
9126 (primitive_region::clone): Delete.
9127 (primitive_region::walk_for_canonicalization): Delete.
9128 (map_region::map_region): Delete.
9129 (map_region::compare_fields): Delete.
9130 (map_region::print_fields): Delete.
9131 (map_region::validate): Delete.
9132 (map_region::dump_dot_to_pp): Delete.
9133 (map_region::dump_child_label): Delete.
9134 (map_region::get_or_create): Delete.
9135 (map_region::get): Delete.
9136 (map_region::add_to_hash): Delete.
9137 (map_region::remap_region_ids): Delete.
9138 (map_region::unbind): Delete.
9139 (map_region::get_tree_for_child_region): Delete.
9140 (map_region::get_tree_for_child_region): Delete.
9141 (tree_cmp): Move to region.cc.
9142 (map_region::can_merge_p): Delete.
9143 (map_region::walk_for_canonicalization): Delete.
9144 (map_region::get_value_by_name): Delete.
9145 (struct_or_union_region::valid_key_p): Delete.
9146 (struct_or_union_region::compare_fields): Delete.
9147 (struct_region::clone): Delete.
9148 (struct_region::compare_fields): Delete.
9149 (union_region::clone): Delete.
9150 (union_region::compare_fields): Delete.
9151 (frame_region::compare_fields): Delete.
9152 (frame_region::clone): Delete.
9153 (frame_region::valid_key_p): Delete.
9154 (frame_region::print_fields): Delete.
9155 (frame_region::add_to_hash): Delete.
9156 (globals_region::compare_fields): Delete.
9157 (globals_region::clone): Delete.
9158 (globals_region::valid_key_p): Delete.
9159 (code_region::compare_fields): Delete.
9160 (code_region::clone): Delete.
9161 (code_region::valid_key_p): Delete.
9162 (array_region::array_region): Delete.
9163 (array_region::get_element): Delete.
9164 (array_region::clone): Delete.
9165 (array_region::compare_fields): Delete.
9166 (array_region::print_fields): Delete.
9167 (array_region::validate): Delete.
9168 (array_region::dump_dot_to_pp): Delete.
9169 (array_region::dump_child_label): Delete.
9170 (array_region::get_or_create): Delete.
9171 (array_region::get): Delete.
9172 (array_region::add_to_hash): Delete.
9173 (array_region::remap_region_ids): Delete.
9174 (array_region::get_key_for_child_region): Delete.
9175 (array_region::key_cmp): Delete.
9176 (array_region::walk_for_canonicalization): Delete.
9177 (array_region::key_from_constant): Delete.
9178 (array_region::constant_from_key): Delete.
9179 (function_region::compare_fields): Delete.
9180 (function_region::clone): Delete.
9181 (function_region::valid_key_p): Delete.
9182 (stack_region::stack_region): Delete.
9183 (stack_region::compare_fields): Delete.
9184 (stack_region::clone): Delete.
9185 (stack_region::print_fields): Delete.
9186 (stack_region::dump_child_label): Delete.
9187 (stack_region::validate): Delete.
9188 (stack_region::push_frame): Delete.
9189 (stack_region::get_current_frame_id): Delete.
9190 (stack_region::pop_frame): Delete.
9191 (stack_region::add_to_hash): Delete.
9192 (stack_region::remap_region_ids): Delete.
9193 (stack_region::can_merge_p): Delete.
9194 (stack_region::walk_for_canonicalization): Delete.
9195 (stack_region::get_value_by_name): Delete.
9196 (heap_region::heap_region): Delete.
9197 (heap_region::compare_fields): Delete.
9198 (heap_region::clone): Delete.
9199 (heap_region::walk_for_canonicalization): Delete.
9200 (root_region::root_region): Delete.
9201 (root_region::compare_fields): Delete.
9202 (root_region::clone): Delete.
9203 (root_region::print_fields): Delete.
9204 (root_region::validate): Delete.
9205 (root_region::dump_child_label): Delete.
9206 (root_region::push_frame): Delete.
9207 (root_region::get_current_frame_id): Delete.
9208 (root_region::pop_frame): Delete.
9209 (root_region::ensure_stack_region): Delete.
9210 (root_region::get_stack_region): Delete.
9211 (root_region::ensure_globals_region): Delete.
9212 (root_region::get_code_region): Delete.
9213 (root_region::ensure_code_region): Delete.
9214 (root_region::get_globals_region): Delete.
9215 (root_region::ensure_heap_region): Delete.
9216 (root_region::get_heap_region): Delete.
9217 (root_region::remap_region_ids): Delete.
9218 (root_region::can_merge_p): Delete.
9219 (root_region::add_to_hash): Delete.
9220 (root_region::walk_for_canonicalization): Delete.
9221 (root_region::get_value_by_name): Delete.
9222 (symbolic_region::symbolic_region): Delete.
9223 (symbolic_region::compare_fields): Delete.
9224 (symbolic_region::clone): Delete.
9225 (symbolic_region::walk_for_canonicalization): Delete.
9226 (symbolic_region::print_fields): Delete.
9227 (region_model::region_model): Add region_model_manager * param.
9228 Reimplement in terms of store, dropping impl_constraint_manager
9230 (region_model::operator=): Reimplement in terms of store
9231 (region_model::operator==): Likewise.
9232 (region_model::hash): Likewise.
9233 (region_model::print): Delete.
9234 (region_model::print_svalue): Delete.
9235 (region_model::dump_dot_to_pp): Delete.
9236 (region_model::dump_dot_to_file): Delete.
9237 (region_model::dump_dot): Delete.
9238 (region_model::dump_to_pp): Replace "summarize" param with
9239 "simple" and "multiline". Port to store-based implementation.
9240 (region_model::dump): Replace "summarize" param with "simple" and
9242 (dump_vec_of_tree): Delete.
9243 (region_model::dump_summary_of_rep_path_vars): Delete.
9244 (region_model::validate): Delete.
9245 (svalue_id_cmp_by_constant_svalue_model): Delete.
9246 (svalue_id_cmp_by_constant_svalue): Delete.
9247 (region_model::canonicalize): Drop "ctxt" param. Reimplement in
9248 terms of store and constraints.
9249 (region_model::canonicalized_p): Remove NULL arg to canonicalize.
9250 (region_model::loop_replay_fixup): New.
9251 (poisoned_value_diagnostic::emit): Tweak wording of warnings.
9252 (region_model::check_for_poison): Delete.
9253 (region_model::get_gassign_result): New.
9254 (region_model::on_assignment): Port to store-based implementation.
9255 (region_model::on_call_pre): Delete calls to check_for_poison.
9256 Move implementations to region-model-impl-calls.c and port to
9257 store-based implementation.
9258 (region_model::on_call_post): Likewise.
9259 (class reachable_regions): Move to region-model-reachability.h/cc
9260 and port to store-based implementation.
9261 (region_model::handle_unrecognized_call): Port to store-based
9263 (region_model::get_reachable_svalues): New.
9264 (region_model::on_setjmp): Port to store-based implementation.
9265 (region_model::on_longjmp): Likewise.
9266 (region_model::handle_phi): Drop is_back_edge param and the logic
9268 (region_model::get_lvalue_1): Port from region_id to const region *.
9269 (region_model::make_region_for_unexpected_tree_code): Delete.
9270 (assert_compat_types): If the check fails, use internal_error to
9272 (region_model::get_lvalue): Port from region_id to const region *.
9273 (region_model::get_rvalue_1): Port from svalue_id to const svalue *.
9274 (region_model::get_rvalue): Likewise.
9275 (region_model::get_or_create_ptr_svalue): Delete.
9276 (region_model::get_or_create_constant_svalue): Delete.
9277 (region_model::get_svalue_for_fndecl): Delete.
9278 (region_model::get_region_for_fndecl): Delete.
9279 (region_model::get_svalue_for_label): Delete.
9280 (region_model::get_region_for_label): Delete.
9281 (build_cast): Delete.
9282 (region_model::maybe_cast_1): Delete.
9283 (region_model::maybe_cast): Delete.
9284 (region_model::get_field_region): Delete.
9285 (region_model::get_store_value): New.
9286 (region_model::region_exists_p): New.
9287 (region_model::deref_rvalue): Port from svalue_id to const svalue *.
9288 (region_model::set_value): Likewise.
9289 (region_model::clobber_region): New.
9290 (region_model::purge_region): New.
9291 (region_model::zero_fill_region): New.
9292 (region_model::mark_region_as_unknown): New.
9293 (region_model::eval_condition): Port from svalue_id to
9295 (region_model::eval_condition_without_cm): Likewise.
9296 (region_model::compare_initial_and_pointer): New.
9297 (region_model::add_constraint): Port from svalue_id to
9299 (region_model::maybe_get_constant): Delete.
9300 (region_model::get_representative_path_var): New.
9301 (region_model::add_new_malloc_region): Delete.
9302 (region_model::get_representative_tree): Port to const svalue *.
9303 (region_model::get_representative_path_var): Port to
9305 (region_model::get_path_vars_for_svalue): Delete.
9306 (region_model::set_to_new_unknown_value): Delete.
9307 (region_model::update_for_phis): Don't pass is_back_edge to handle_phi.
9308 (region_model::update_for_call_superedge): Port from svalue_id to
9310 (region_model::update_for_return_superedge): Port to store-based
9312 (region_model::update_for_call_summary): Replace
9313 set_to_new_unknown_value with mark_region_as_unknown.
9314 (region_model::get_root_region): Delete.
9315 (region_model::get_stack_region_id): Delete.
9316 (region_model::push_frame): Delete.
9317 (region_model::get_current_frame_id): Delete.
9318 (region_model::get_current_function): Delete.
9319 (region_model::pop_frame): Delete.
9320 (region_model::on_top_level_param): New.
9321 (region_model::get_stack_depth): Delete.
9322 (region_model::get_function_at_depth): Delete.
9323 (region_model::get_globals_region_id): Delete.
9324 (region_model::add_svalue): Delete.
9325 (region_model::replace_svalue): Delete.
9326 (region_model::add_region): Delete.
9327 (region_model::get_svalue): Delete.
9328 (region_model::get_region): Delete.
9329 (make_region_for_type): Delete.
9330 (region_model::add_region_for_type): Delete.
9331 (region_model::on_top_level_param): New.
9332 (class restrict_to_used_svalues): Delete.
9333 (region_model::purge_unused_svalues): Delete.
9334 (region_model::push_frame): New.
9335 (region_model::remap_svalue_ids): Delete.
9336 (region_model::remap_region_ids): Delete.
9337 (region_model::purge_regions): Delete.
9338 (region_model::get_descendents): Delete.
9339 (region_model::delete_region_and_descendents): Delete.
9340 (region_model::poison_any_pointers_to_bad_regions): Delete.
9341 (region_model::can_merge_with_p): Delete.
9342 (region_model::get_current_function): New.
9343 (region_model::get_value_by_name): Delete.
9344 (region_model::convert_byte_offset_to_array_index): Delete.
9345 (region_model::pop_frame): New.
9346 (region_model::get_or_create_mem_ref): Delete.
9347 (region_model::get_stack_depth): New.
9348 (region_model::get_frame_at_index): New.
9349 (region_model::unbind_region_and_descendents): New.
9350 (struct bad_pointer_finder): New.
9351 (region_model::get_or_create_pointer_plus_expr): Delete.
9352 (region_model::poison_any_pointers_to_descendents): New.
9353 (region_model::get_or_create_view): Delete.
9354 (region_model::can_merge_with_p): New.
9355 (region_model::get_fndecl_for_call): Port from svalue_id to
9357 (struct append_ssa_names_cb_data): New.
9358 (get_ssa_name_regions_for_current_frame): New.
9359 (region_model::append_ssa_names_cb): New.
9360 (model_merger::dump_to_pp): Add "simple" param. Drop dumping of
9362 (model_merger::dump): Add "simple" param to both overloads.
9363 (model_merger::can_merge_values_p): Delete.
9364 (model_merger::record_regions): Delete.
9365 (model_merger::record_svalues): Delete.
9366 (svalue_id_merger_mapping::svalue_id_merger_mapping): Delete.
9367 (svalue_id_merger_mapping::dump_to_pp): Delete.
9368 (svalue_id_merger_mapping::dump): Delete.
9369 (region_model::create_region_for_heap_alloc): New.
9370 (region_model::create_region_for_alloca): New.
9371 (region_model::record_dynamic_extents): New.
9372 (canonicalization::canonicalization): Delete.
9373 (canonicalization::walk_rid): Delete.
9374 (canonicalization::walk_sid): Delete.
9375 (canonicalization::dump_to_pp): Delete.
9376 (canonicalization::dump): Delete.
9377 (inchash::add): Delete overloads for svalue_id and region_id.
9378 (engine::log_stats): New.
9379 (assert_condition): Add overload comparing svalues.
9380 (assert_dump_eq): Pass "true" for multiline.
9381 (selftest::test_dump): Update for rewrite of region_model.
9382 (selftest::test_dump_2): Rename to...
9383 (selftest::test_struct): ...this. Provide a region_model_manager
9384 when creating region_model instance. Remove dump test. Add
9385 checks for get_offset.
9386 (selftest::test_dump_3): Rename to...
9387 (selftest::test_array_1): ...this. Provide a region_model_manager
9388 when creating region_model instance. Remove dump test.
9389 (selftest::test_get_representative_tree): Port from svalue_id to
9390 new API. Add test coverage for various expressions.
9391 (selftest::test_unique_constants): Provide a region_model_manager
9392 for the region_model. Add test coverage for comparing const vs
9394 (selftest::test_svalue_equality): Delete.
9395 (selftest::test_region_equality): Delete.
9396 (selftest::test_unique_unknowns): New.
9397 (class purge_all_svalue_ids): Delete.
9398 (class purge_one_svalue_id): Delete.
9399 (selftest::test_purging_by_criteria): Delete.
9400 (selftest::test_initial_svalue_folding): New.
9401 (selftest::test_unaryop_svalue_folding): New.
9402 (selftest::test_binop_svalue_folding): New.
9403 (selftest::test_sub_svalue_folding): New.
9404 (selftest::test_purge_unused_svalues): Delete.
9405 (selftest::test_descendent_of_p): New.
9406 (selftest::test_assignment): Provide a region_model_manager for
9407 the region_model. Drop the dump test.
9408 (selftest::test_compound_assignment): Likewise.
9409 (selftest::test_stack_frames): Port to new implementation.
9410 (selftest::test_get_representative_path_var): Likewise.
9411 (selftest::test_canonicalization_1): Rename to...
9412 (selftest::test_equality_1): ...this. Port to new API, and add
9413 (selftest::test_canonicalization_2): Provide a
9414 region_model_manager when creating region_model instances.
9415 Remove redundant canicalization.
9416 (selftest::test_canonicalization_3): Provide a
9417 region_model_manager when creating region_model instances.
9418 Remove param from calls to region_model::canonicalize.
9419 (selftest::test_canonicalization_4): Likewise.
9420 (selftest::assert_region_models_merge): Constify
9421 out_merged_svalue. Port to new API.
9422 (selftest::test_state_merging): Provide a
9423 region_model_manager when creating region_model instances.
9424 Provide a program_point point when merging them. Replace
9425 set_to_new_unknown_value with usage of placeholder_svalues.
9426 Drop get_value_by_name. Port from svalue_id to const svalue *.
9427 Add test of heap allocation.
9428 (selftest::test_constraint_merging): Provide a
9429 region_model_manager when creating region_model instances.
9430 Provide a program_point point when merging them. Eliminate use
9431 of set_to_new_unknown_value.
9432 (selftest::test_widening_constraints): New.
9433 (selftest::test_iteration_1): New.
9434 (selftest::test_malloc_constraints): Port to store-based
9436 (selftest::test_var): New test.
9437 (selftest::test_array_2): New test.
9438 (selftest::test_mem_ref): New test.
9439 (selftest::test_POINTER_PLUS_EXPR_then_MEM_REF): New.
9440 (selftest::test_malloc): New.
9441 (selftest::test_alloca): New.
9442 (selftest::analyzer_region_model_cc_tests): Update for renamings.
9444 * region-model.h (class path_var): Move to analyzer.h.
9445 (class svalue_id): Delete.
9446 (class region_id): Delete.
9447 (class id_map): Delete.
9448 (svalue_id_map): Delete.
9449 (region_id_map): Delete.
9450 (id_map<T>::id_map): Delete.
9451 (id_map<T>::put): Delete.
9452 (id_map<T>::get_dst_for_src): Delete.
9453 (id_map<T>::get_src_for_dst): Delete.
9454 (id_map<T>::dump_to_pp): Delete.
9455 (id_map<T>::dump): Delete.
9456 (id_map<T>::update): Delete.
9457 (one_way_svalue_id_map): Delete.
9458 (one_way_region_id_map): Delete.
9459 (class region_id_set): Delete.
9460 (class svalue_id_set): Delete.
9461 (struct complexity): New.
9462 (class visitor): New.
9463 (enum svalue_kind): Add SK_SETJMP, SK_INITIAL, SK_UNARYOP,
9464 SK_BINOP, SK_SUB,SK_UNMERGEABLE, SK_PLACEHOLDER, SK_WIDENING,
9465 SK_COMPOUND, and SK_CONJURED.
9466 (svalue::operator==): Delete.
9467 (svalue::operator!=): Delete.
9468 (svalue::clone): Delete.
9469 (svalue::hash): Delete.
9470 (svalue::dump_dot_to_pp): Delete.
9471 (svalue::dump_to_pp): New.
9472 (svalue::dump): New.
9473 (svalue::get_desc): New.
9474 (svalue::dyn_cast_initial_svalue): New.
9475 (svalue::dyn_cast_unaryop_svalue): New.
9476 (svalue::dyn_cast_binop_svalue): New.
9477 (svalue::dyn_cast_sub_svalue): New.
9478 (svalue::dyn_cast_unmergeable_svalue): New.
9479 (svalue::dyn_cast_widening_svalue): New.
9480 (svalue::dyn_cast_compound_svalue): New.
9481 (svalue::dyn_cast_conjured_svalue): New.
9482 (svalue::maybe_undo_cast): New.
9483 (svalue::unwrap_any_unmergeable): New.
9484 (svalue::remap_region_ids): Delete
9485 (svalue::can_merge_p): New.
9486 (svalue::walk_for_canonicalization): Delete
9487 (svalue::get_complexity): New.
9488 (svalue::get_child_sid): Delete
9489 (svalue::accept): New.
9490 (svalue::live_p): New.
9491 (svalue::implicitly_live_p): New.
9492 (svalue::svalue): Add complexity param.
9493 (svalue::add_to_hash): Delete
9494 (svalue::print_details): Delete
9495 (svalue::m_complexity): New field.
9496 (region_svalue::key_t): New struct.
9497 (region_svalue::region_svalue): Port from region_id to
9498 const region_id *. Add complexity.
9499 (region_svalue::compare_fields): Delete.
9500 (region_svalue::clone): Delete.
9501 (region_svalue::dump_dot_to_pp): Delete.
9502 (region_svalue::get_pointee): Port from region_id to
9504 (region_svalue::remap_region_ids): Delete.
9505 (region_svalue::merge_values): Delete.
9506 (region_svalue::dump_to_pp): New.
9507 (region_svalue::accept): New.
9508 (region_svalue::walk_for_canonicalization): Delete.
9509 (region_svalue::eval_condition): Make params const.
9510 (region_svalue::add_to_hash): Delete.
9511 (region_svalue::print_details): Delete.
9512 (region_svalue::m_rid): Replace with...
9513 (region_svalue::m_reg): ...this.
9514 (is_a_helper <region_svalue *>::test): Convert to...
9515 (is_a_helper <const region_svalue *>::test): ...this.
9516 (template <> struct default_hash_traits<region_svalue::key_t>):
9518 (constant_svalue::constant_svalue): Add complexity.
9519 (constant_svalue::compare_fields): Delete.
9520 (constant_svalue::clone): Delete.
9521 (constant_svalue::add_to_hash): Delete.
9522 (constant_svalue::dump_to_pp): New.
9523 (constant_svalue::accept): New.
9524 (constant_svalue::implicitly_live_p): New.
9525 (constant_svalue::merge_values): Delete.
9526 (constant_svalue::eval_condition): Make params const.
9527 (constant_svalue::get_child_sid): Delete.
9528 (constant_svalue::print_details): Delete.
9529 (is_a_helper <constant_svalue *>::test): Convert to...
9530 (is_a_helper <const constant_svalue *>::test): ...this.
9531 (class unknown_svalue): Update leading comment.
9532 (unknown_svalue::unknown_svalue): Add complexity.
9533 (unknown_svalue::compare_fields): Delete.
9534 (unknown_svalue::add_to_hash): Delete.
9535 (unknown_svalue::dyn_cast_unknown_svalue): Delete.
9536 (unknown_svalue::print_details): Delete.
9537 (unknown_svalue::dump_to_pp): New.
9538 (unknown_svalue::accept): New.
9539 (poisoned_svalue::key_t): New struct.
9540 (poisoned_svalue::poisoned_svalue): Add complexity.
9541 (poisoned_svalue::compare_fields): Delete.
9542 (poisoned_svalue::clone): Delete.
9543 (poisoned_svalue::add_to_hash): Delete.
9544 (poisoned_svalue::dump_to_pp): New.
9545 (poisoned_svalue::accept): New.
9546 (poisoned_svalue::print_details): Delete.
9547 (is_a_helper <poisoned_svalue *>::test): Convert to...
9548 (is_a_helper <const poisoned_svalue *>::test): ...this.
9549 (template <> struct default_hash_traits<poisoned_svalue::key_t>):
9551 (setjmp_record::add_to_hash): New.
9552 (setjmp_svalue::key_t): New struct.
9553 (setjmp_svalue::compare_fields): Delete.
9554 (setjmp_svalue::clone): Delete.
9555 (setjmp_svalue::add_to_hash): Delete.
9556 (setjmp_svalue::setjmp_svalue): Add complexity.
9557 (setjmp_svalue::dump_to_pp): New.
9558 (setjmp_svalue::accept): New.
9559 (setjmp_svalue::void print_details): Delete.
9560 (is_a_helper <const setjmp_svalue *>::test): New.
9561 (template <> struct default_hash_traits<setjmp_svalue::key_t>): New.
9562 (class initial_svalue : public svalue): New.
9563 (is_a_helper <const initial_svalue *>::test): New.
9564 (class unaryop_svalue): New.
9565 (is_a_helper <const unaryop_svalue *>::test): New.
9566 (template <> struct default_hash_traits<unaryop_svalue::key_t>): New.
9567 (class binop_svalue): New.
9568 (is_a_helper <const binop_svalue *>::test): New.
9569 (template <> struct default_hash_traits<binop_svalue::key_t>): New.
9570 (class sub_svalue): New.
9571 (is_a_helper <const sub_svalue *>::test): New.
9572 (template <> struct default_hash_traits<sub_svalue::key_t>): New.
9573 (class unmergeable_svalue): New.
9574 (is_a_helper <const unmergeable_svalue *>::test): New.
9575 (class placeholder_svalue): New.
9576 (is_a_helper <placeholder_svalue *>::test): New.
9577 (class widening_svalue): New.
9578 (is_a_helper <widening_svalue *>::test): New.
9579 (template <> struct default_hash_traits<widening_svalue::key_t>): New.
9580 (class compound_svalue): New.
9581 (is_a_helper <compound_svalue *>::test): New.
9582 (template <> struct default_hash_traits<compound_svalue::key_t>): New.
9583 (class conjured_svalue): New.
9584 (is_a_helper <conjured_svalue *>::test): New.
9585 (template <> struct default_hash_traits<conjured_svalue::key_t>): New.
9586 (enum region_kind): Delete RK_PRIMITIVE, RK_STRUCT, RK_UNION, and
9587 RK_ARRAY. Add RK_LABEL, RK_DECL, RK_FIELD, RK_ELEMENT, RK_OFFSET,
9588 RK_CAST, RK_HEAP_ALLOCATED, RK_ALLOCA, RK_STRING, and RK_UNKNOWN.
9589 (region_kind_to_str): Delete.
9590 (region::~region): Move implementation to region.cc.
9591 (region::operator==): Delete.
9592 (region::operator!=): Delete.
9593 (region::clone): Delete.
9594 (region::get_id): New.
9595 (region::cmp_ids): New.
9596 (region::dyn_cast_map_region): Delete.
9597 (region::dyn_cast_array_region): Delete.
9598 (region::region_id get_parent): Delete.
9599 (region::get_parent_region): Convert to a simple accessor.
9600 (region::void set_value): Delete.
9601 (region::svalue_id get_value): Delete.
9602 (region::svalue_id get_value_direct): Delete.
9603 (region::svalue_id get_inherited_child_sid): Delete.
9604 (region::dyn_cast_frame_region): New.
9605 (region::dyn_cast_function_region): New.
9606 (region::dyn_cast_decl_region): New.
9607 (region::dyn_cast_field_region): New.
9608 (region::dyn_cast_element_region): New.
9609 (region::dyn_cast_offset_region): New.
9610 (region::dyn_cast_cast_region): New.
9611 (region::dyn_cast_string_region): New.
9612 (region::accept): New.
9613 (region::get_base_region): New.
9614 (region::base_region_p): New.
9615 (region::descendent_of_p): New.
9616 (region::maybe_get_frame_region): New.
9617 (region::maybe_get_decl): New.
9618 (region::hash): Delete.
9619 (region::rint): Delete.
9620 (region::dump_dot_to_pp): Delete.
9621 (region::get_desc): New.
9622 (region::dump_to_pp): Convert to vfunc, changing signature.
9623 (region::dump_child_label): Delete.
9624 (region::remap_svalue_ids): Delete.
9625 (region::remap_region_ids): Delete.
9626 (region::dump): New.
9627 (region::walk_for_canonicalization): Delete.
9628 (region::non_null_p): Drop region_model param.
9629 (region::add_view): Delete.
9630 (region::get_view): Delete.
9631 (region::get_active_view): Delete.
9632 (region::is_view_p): Delete.
9633 (region::cmp_ptrs): New.
9634 (region::validate): Delete.
9635 (region::get_offset): New.
9636 (region::get_byte_size): New.
9637 (region::get_bit_size): New.
9638 (region::get_subregions_for_binding): New.
9639 (region::region): Add complexity param. Convert parent from
9640 region_id to const region *. Drop svalue_id. Drop copy ctor.
9641 (region::symbolic_for_unknown_ptr_p): New.
9642 (region::add_to_hash): Delete.
9643 (region::print_fields): Delete.
9644 (region::get_complexity): New accessor.
9645 (region::become_active_view): Delete.
9646 (region::deactivate_any_active_view): Delete.
9647 (region::deactivate_view): Delete.
9648 (region::calc_offset): New.
9649 (region::m_parent_rid): Delete.
9650 (region::m_sval_id): Delete.
9651 (region::m_complexity): New.
9652 (region::m_id): New.
9653 (region::m_parent): New.
9654 (region::m_view_rids): Delete.
9655 (region::m_is_view): Delete.
9656 (region::m_active_view_rid): Delete.
9657 (region::m_cached_offset): New.
9658 (is_a_helper <region *>::test): Convert to...
9659 (is_a_helper <const region *>::test): ... this.
9660 (class primitive_region): Delete.
9661 (class space_region): New.
9662 (class map_region): Delete.
9663 (is_a_helper <map_region *>::test): Delete.
9664 (class frame_region): Reimplement.
9665 (template <> struct default_hash_traits<frame_region::key_t>):
9667 (class globals_region): Reimplement.
9668 (is_a_helper <globals_region *>::test): Convert to...
9669 (is_a_helper <const globals_region *>::test): ...this.
9670 (class struct_or_union_region): Delete.
9671 (is_a_helper <struct_or_union_region *>::test): Delete.
9672 (class code_region): Reimplement.
9673 (is_a_helper <const code_region *>::test): New.
9674 (class struct_region): Delete.
9675 (is_a_helper <struct_region *>::test): Delete.
9676 (class function_region): Reimplement.
9677 (is_a_helper <function_region *>::test): Convert to...
9678 (is_a_helper <const function_region *>::test): ...this.
9679 (class union_region): Delete.
9680 (is_a_helper <union_region *>::test): Delete.
9681 (class label_region): New.
9682 (is_a_helper <const label_region *>::test): New.
9683 (class scope_region): Delete.
9684 (class stack_region): Reimplement.
9685 (is_a_helper <stack_region *>::test): Convert to...
9686 (is_a_helper <const stack_region *>::test): ...this.
9687 (class heap_region): Reimplement.
9688 (is_a_helper <heap_region *>::test): Convert to...
9689 (is_a_helper <const heap_region *>::test): ...this.
9690 (class root_region): Reimplement.
9691 (is_a_helper <root_region *>::test): Convert to...
9692 (is_a_helper <const root_region *>::test): ...this.
9693 (class symbolic_region): Reimplement.
9694 (is_a_helper <const symbolic_region *>::test): New.
9695 (template <> struct default_hash_traits<symbolic_region::key_t>):
9697 (class decl_region): New.
9698 (is_a_helper <const decl_region *>::test): New.
9699 (class field_region): New.
9700 (template <> struct default_hash_traits<field_region::key_t>): New.
9701 (class array_region): Delete.
9702 (class element_region): New.
9703 (is_a_helper <array_region *>::test): Delete.
9704 (is_a_helper <const element_region *>::test): New.
9705 (template <> struct default_hash_traits<element_region::key_t>):
9707 (class offset_region): New.
9708 (is_a_helper <const offset_region *>::test): New.
9709 (template <> struct default_hash_traits<offset_region::key_t>):
9711 (class cast_region): New.
9712 (is_a_helper <const cast_region *>::test): New.
9713 (template <> struct default_hash_traits<cast_region::key_t>): New.
9714 (class heap_allocated_region): New.
9715 (class alloca_region): New.
9716 (class string_region): New.
9717 (is_a_helper <const string_region *>::test): New.
9718 (class unknown_region): New.
9719 (class region_model_manager): New.
9720 (struct append_ssa_names_cb_data): New.
9721 (class call_details): New.
9722 (region_model::region_model): Add region_model_manager param.
9723 (region_model::print_svalue): Delete.
9724 (region_model::dump_dot_to_pp): Delete.
9725 (region_model::dump_dot_to_file): Delete.
9726 (region_model::dump_dot): Delete.
9727 (region_model::dump_to_pp): Drop summarize param in favor of
9728 simple and multiline.
9729 (region_model::dump): Likewise.
9730 (region_model::summarize_to_pp): Delete.
9731 (region_model::summarize): Delete.
9732 (region_model::void canonicalize): Drop ctxt param.
9733 (region_model::void check_for_poison): Delete.
9734 (region_model::get_gassign_result): New.
9735 (region_model::impl_call_alloca): New.
9736 (region_model::impl_call_analyzer_describe): New.
9737 (region_model::impl_call_analyzer_eval): New.
9738 (region_model::impl_call_builtin_expect): New.
9739 (region_model::impl_call_calloc): New.
9740 (region_model::impl_call_free): New.
9741 (region_model::impl_call_malloc): New.
9742 (region_model::impl_call_memset): New.
9743 (region_model::impl_call_strlen): New.
9744 (region_model::get_reachable_svalues): New.
9745 (region_model::handle_phi): Drop is_back_edge param.
9746 (region_model::region_id get_root_rid): Delete.
9747 (region_model::root_region *get_root_region): Delete.
9748 (region_model::region_id get_stack_region_id): Delete.
9749 (region_model::push_frame): Convert from region_id and svalue_id
9750 to const region * and const svalue *.
9751 (region_model::get_current_frame_id): Replace with...
9752 (region_model::get_current_frame): ...this.
9753 (region_model::pop_frame): Convert from region_id to
9754 const region *. Drop purge and stats param. Add out_result.
9755 (region_model::function *get_function_at_depth): Delete.
9756 (region_model::get_globals_region_id): Delete.
9757 (region_model::add_svalue): Delete.
9758 (region_model::replace_svalue): Delete.
9759 (region_model::add_region): Delete.
9760 (region_model::add_region_for_type): Delete.
9761 (region_model::get_svalue): Delete.
9762 (region_model::get_region): Delete.
9763 (region_model::get_lvalue): Convert from region_id to
9765 (region_model::get_rvalue): Convert from svalue_id to
9767 (region_model::get_or_create_ptr_svalue): Delete.
9768 (region_model::get_or_create_constant_svalue): Delete.
9769 (region_model::get_svalue_for_fndecl): Delete.
9770 (region_model::get_svalue_for_label): Delete.
9771 (region_model::get_region_for_fndecl): Delete.
9772 (region_model::get_region_for_label): Delete.
9773 (region_model::get_frame_at_index (int index) const;): New.
9774 (region_model::maybe_cast): Delete.
9775 (region_model::maybe_cast_1): Delete.
9776 (region_model::get_field_region): Delete.
9777 (region_model::id deref_rvalue): Convert from region_id and
9778 svalue_id to const region * and const svalue *. Drop overload,
9779 passing in both a tree and an svalue.
9780 (region_model::set_value): Convert from region_id and svalue_id to
9781 const region * and const svalue *.
9782 (region_model::set_to_new_unknown_value): Delete.
9783 (region_model::clobber_region (const region *reg);): New.
9784 (region_model::purge_region (const region *reg);): New.
9785 (region_model::zero_fill_region (const region *reg);): New.
9786 (region_model::mark_region_as_unknown (const region *reg);): New.
9787 (region_model::copy_region): Convert from region_id to
9789 (region_model::eval_condition): Convert from svalue_id to
9791 (region_model::eval_condition_without_cm): Likewise.
9792 (region_model::compare_initial_and_pointer): New.
9793 (region_model:maybe_get_constant): Delete.
9794 (region_model::add_new_malloc_region): Delete.
9795 (region_model::get_representative_tree): Convert from svalue_id to
9797 (region_model::get_representative_path_var): Delete decl taking a
9798 region_id in favor of two decls, for svalue vs region, with an
9799 svalue_set to ensure termination.
9800 (region_model::get_path_vars_for_svalue): Delete.
9801 (region_model::create_region_for_heap_alloc): New.
9802 (region_model::create_region_for_alloca): New.
9803 (region_model::purge_unused_svalues): Delete.
9804 (region_model::remap_svalue_ids): Delete.
9805 (region_model::remap_region_ids): Delete.
9806 (region_model::purge_regions): Delete.
9807 (region_model::get_num_svalues): Delete.
9808 (region_model::get_num_regions): Delete.
9809 (region_model::get_descendents): Delete.
9810 (region_model::get_store): New.
9811 (region_model::delete_region_and_descendents): Delete.
9812 (region_model::get_manager): New.
9813 (region_model::unbind_region_and_descendents): New.
9814 (region_model::can_merge_with_p): Add point param. Drop
9815 svalue_id_merger_mapping.
9816 (region_model::get_value_by_name): Delete.
9817 (region_model::convert_byte_offset_to_array_index): Delete.
9818 (region_model::get_or_create_mem_ref): Delete.
9819 (region_model::get_or_create_pointer_plus_expr): Delete.
9820 (region_model::get_or_create_view): Delete.
9821 (region_model::get_lvalue_1): Convert from region_id to
9823 (region_model::get_rvalue_1): Convert from svalue_id to
9825 (region_model::get_ssa_name_regions_for_current_frame): New.
9826 (region_model::append_ssa_names_cb): New.
9827 (region_model::get_store_value): New.
9828 (region_model::copy_struct_region): Delete.
9829 (region_model::copy_union_region): Delete.
9830 (region_model::copy_array_region): Delete.
9831 (region_model::region_exists_p): New.
9832 (region_model::make_region_for_unexpected_tree_code): Delete.
9833 (region_model::loop_replay_fixup): New.
9834 (region_model::poison_any_pointers_to_bad_regions): Delete.
9835 (region_model::poison_any_pointers_to_descendents): New.
9836 (region_model::dump_summary_of_rep_path_vars): Delete.
9837 (region_model::on_top_level_param): New.
9838 (region_model::record_dynamic_extents): New.
9839 (region_model::m_mgr;): New.
9840 (region_model::m_store;): New.
9841 (region_model::m_svalues;): Delete.
9842 (region_model::m_regions;): Delete.
9843 (region_model::m_root_rid;): Delete.
9844 (region_model::m_current_frame;): New.
9845 (region_model_context::remap_svalue_ids): Delete.
9846 (region_model_context::can_purge_p): Delete.
9847 (region_model_context::on_svalue_leak): New.
9848 (region_model_context::on_svalue_purge): Delete.
9849 (region_model_context::on_liveness_change): New.
9850 (region_model_context::on_inherited_svalue): Delete.
9851 (region_model_context::on_cast): Delete.
9852 (region_model_context::on_unknown_change): Convert from svalue_id to
9853 const svalue * and add is_mutable.
9854 (class noop_region_model_context): Update for region_model_context
9856 (model_merger::model_merger): Add program_point. Drop
9857 svalue_id_merger_mapping.
9858 (model_merger::dump_to_pp): Add "simple" param.
9859 (model_merger::dump): Likewise.
9860 (model_merger::get_region_a): Delete.
9861 (model_merger::get_region_b): Delete.
9862 (model_merger::can_merge_values_p): Delete.
9863 (model_merger::record_regions): Delete.
9864 (model_merger::record_svalues): Delete.
9865 (model_merger::m_point): New field.
9866 (model_merger::m_map_regions_from_a_to_m): Delete.
9867 (model_merger::m_map_regions_from_b_to_m): Delete.
9868 (model_merger::m_sid_mapping): Delete.
9869 (struct svalue_id_merger_mapping): Delete.
9870 (class engine): New.
9871 (struct canonicalization): Delete.
9872 (inchash::add): Delete decls for hashing svalue_id and region_id.
9873 (test_region_model_context::on_unexpected_tree_code): Require t to
9875 (selftest::assert_condition): Add overload comparing a pair of
9877 * sm-file.cc: Include "tristate.h", "selftest.h",
9878 "analyzer/call-string.h", "analyzer/program-point.h",
9879 "analyzer/store.h", and "analyzer/region-model.h".
9880 (fileptr_state_machine::get_default_state): New.
9881 (fileptr_state_machine::on_stmt): Remove calls to
9882 get_readable_tree in favor of get_diagnostic_tree.
9883 * sm-malloc.cc: Include "tristate.h", "selftest.h",
9884 "analyzer/call-string.h", "analyzer/program-point.h",
9885 "analyzer/store.h", and "analyzer/region-model.h".
9886 (malloc_state_machine::get_default_state): New.
9887 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New.
9888 (malloc_diagnostic::describe_state_change): Handle change.m_expr
9890 (null_arg::emit): Avoid printing "NULL '0'".
9891 (null_arg::describe_final_event): Avoid printing "(0) NULL".
9892 (malloc_leak::emit): Handle m_arg being NULL.
9893 (malloc_leak::describe_final_event): Handle ev.m_expr being NULL.
9894 (malloc_state_machine::on_stmt): Don't call get_readable_tree.
9895 Call get_diagnostic_tree when creating pending diagnostics.
9896 Update for is_zero_assignment becoming a member function of
9898 Don't transition to m_non_heap for ADDR_EXPR(MEM_REF()).
9899 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New
9900 vfunc implementation.
9901 * sm-sensitive.cc (sensitive_state_machine::warn_for_any_exposure): Call
9902 get_diagnostic_tree and pass the result to warn_for_state.
9903 * sm-signal.cc: Move includes of "analyzer/call-string.h" and
9904 "analyzer/program-point.h" to before "analyzer/region-model.h",
9905 and also include "analyzer/store.h" before it.
9906 (signal_unsafe_call::describe_state_change): Use
9907 get_dest_function to get handler.
9908 (update_model_for_signal_handler): Pass manager to region_model
9910 (register_signal_handler::impl_transition): Update for changes to
9911 get_or_create_node and add_edge.
9912 * sm-taint.cc (taint_state_machine::on_stmt): Remove calls to
9913 get_readable_tree, replacing them when calling warn_for_state with
9914 calls to get_diagnostic_tree.
9915 * sm.cc (is_zero_assignment): Delete.
9916 (any_pointer_p): Move to within namespace ana.
9917 * sm.h (is_zero_assignment): Remove decl.
9918 (any_pointer_p): Move decl to within namespace ana.
9919 (state_machine::get_default_state): New vfunc.
9920 (state_machine::reset_when_passed_to_unknown_fn_p): New vfunc.
9921 (sm_context::get_readable_tree): Rename to...
9922 (sm_context::get_diagnostic_tree): ...this.
9923 (sm_context::is_zero_assignment): New vfunc.
9924 * store.cc: New file.
9925 * store.h: New file.
9926 * svalue.cc: New file.
9928 2020-05-22 Mark Wielaard <mark@klomp.org>
9930 * sm-signal.cc(signal_unsafe_call::emit): Possibly add
9931 gcc_rich_location note for replacement.
9932 (signal_unsafe_call::get_replacement_fn): New private function.
9933 (get_async_signal_unsafe_fns): Add "exit".
9935 2020-04-28 David Malcolm <dmalcolm@redhat.com>
9938 * engine.cc (impl_region_model_context::on_unexpected_tree_code):
9940 * region-model.cc (region_model::add_region_for_type): Handle
9943 (test_region_model_context::on_unexpected_tree_code): Handle NULL
9946 2020-04-28 David Malcolm <dmalcolm@redhat.com>
9952 * analyzer.opt (Wanalyzer-use-of-uninitialized-value): Delete.
9953 * program-state.cc (selftest::test_program_state_dumping): Update
9954 expected dump result for removal of "uninit".
9955 * region-model.cc (poison_kind_to_str): Delete POISON_KIND_UNINIT
9957 (root_region::ensure_stack_region): Initialize stack with null
9958 svalue_id rather than with a typeless POISON_KIND_UNINIT value.
9959 (root_region::ensure_heap_region): Likewise for the heap.
9960 (region_model::dump_summary_of_rep_path_vars): Remove
9961 summarization of uninit values.
9962 (region_model::validate): Remove check that the stack has a
9963 POISON_KIND_UNINIT value.
9964 (poisoned_value_diagnostic::emit): Remove POISON_KIND_UNINIT
9966 (poisoned_value_diagnostic::describe_final_event): Likewise.
9967 (selftest::test_dump): Update expected dump result for removal of
9969 (selftest::test_svalue_equality): Remove "uninit" and "freed".
9970 * region-model.h (enum poison_kind): Remove POISON_KIND_UNINIT.
9972 2020-04-01 David Malcolm <dmalcolm@redhat.com>
9975 * checker-path.cc: Include "bitmap.h".
9976 * constraint-manager.cc: Likewise.
9977 * diagnostic-manager.cc: Likewise.
9978 * engine.cc: Likewise.
9979 (exploded_node::detect_leaks): Pass null region_id to pop_frame.
9980 * program-point.cc: Include "bitmap.h".
9981 * program-state.cc: Likewise.
9982 * region-model.cc (id_set<region_id>::id_set): Convert to...
9983 (region_id_set::region_id_set): ...this.
9984 (svalue_id_set::svalue_id_set): New ctor.
9985 (region_model::copy_region): New function.
9986 (region_model::copy_struct_region): New function.
9987 (region_model::copy_union_region): New function.
9988 (region_model::copy_array_region): New function.
9989 (stack_region::pop_frame): Drop return value. Add
9990 "result_dst_rid" param; if it is non-null, use copy_region to copy
9991 the result to it. Rather than capture and pass a single "known
9992 used" return value to be used by purge_unused_values, instead
9993 gather and pass a set of known used return values.
9994 (root_region::pop_frame): Drop return value. Add "result_dst_rid"
9996 (region_model::on_assignment): Use copy_region.
9997 (region_model::on_return): Likewise for the result.
9998 (region_model::on_longjmp): Pass null for pop_frame's
10000 (region_model::update_for_return_superedge): Pass the region for the
10001 return value of the call, if any, to pop_frame, rather than setting
10002 the lvalue for the lhs of the result.
10003 (region_model::pop_frame): Drop return value. Add
10004 "result_dst_rid" param.
10005 (region_model::purge_unused_svalues): Convert third param from an
10006 svalue_id * to an svalue_id_set *, updating the initial populating
10007 of the "used" bitmap accordingly. Don't remap it when done.
10008 (struct selftest::coord_test): New selftest fixture, extracted from...
10009 (selftest::test_dump_2): ...here.
10010 (selftest::test_compound_assignment): New selftest.
10011 (selftest::test_stack_frames): Pass null to new param of pop_frame.
10012 (selftest::analyzer_region_model_cc_tests): Call the new selftest.
10013 * region-model.h (class id_set): Delete template.
10014 (class region_id_set): Reimplement, using old id_set implementation.
10015 (class svalue_id_set): Likewise. Convert from auto_sbitmap to
10017 (region::get_active_view): New accessor.
10018 (stack_region::pop_frame): Drop return value. Add
10019 "result_dst_rid" param.
10020 (root_region::pop_frame): Likewise.
10021 (region_model::pop_frame): Likewise.
10022 (region_model::copy_region): New decl.
10023 (region_model::purge_unused_svalues): Convert third param from an
10024 svalue_id * to an svalue_id_set *.
10025 (region_model::copy_struct_region): New decl.
10026 (region_model::copy_union_region): New decl.
10027 (region_model::copy_array_region): New decl.
10029 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10031 * program-state.cc (selftest::test_program_state_dumping): Update
10032 expected dump to include symbolic_region's possibly_null field.
10033 * region-model.cc (symbolic_region::print_fields): New vfunc
10035 (region_model::add_constraint): Clear m_possibly_null from
10036 symbolic_regions now known to be non-NULL.
10037 (selftest::test_malloc_constraints): New selftest.
10038 (selftest::analyzer_region_model_cc_tests): Call it.
10039 * region-model.h (region::dyn_cast_symbolic_region): Add non-const
10041 (symbolic_region::dyn_cast_symbolic_region): Implement it.
10042 (symbolic_region::print_fields): New vfunc override decl.
10044 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10046 * analyzer.h (class feasibility_problem): New forward decl.
10047 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
10048 Initialize new fields m_status, m_epath_length, and m_problem.
10049 (saved_diagnostic::~saved_diagnostic): Delete m_problem.
10050 (dedupe_candidate::dedupe_candidate): Convert "sd" param from a
10051 const ref to a mutable ptr.
10052 (dedupe_winners::add): Convert "sd" param from a const ref to a
10053 mutable ptr. Record the length of the exploded_path. Record the
10054 feasibility/infeasibility of sd into sd, capturing a
10055 feasibility_problem when feasible_p fails, and storing it in sd.
10056 (diagnostic_manager::emit_saved_diagnostics): Update for pass by
10057 ptr rather than by const ref.
10058 * diagnostic-manager.h (class saved_diagnostic): Add new enum
10059 status. Add fields m_status, m_epath_length and m_problem.
10060 (saved_diagnostic::set_feasible): New member function.
10061 (saved_diagnostic::set_infeasible): New member function.
10062 (saved_diagnostic::get_feasibility_problem): New accessor.
10063 (saved_diagnostic::get_status): New accessor.
10064 (saved_diagnostic::set_epath_length): New member function.
10065 (saved_diagnostic::get_epath_length): New accessor.
10066 * engine.cc: Include "gimple-pretty-print.h".
10067 (exploded_path::feasible_p): Add OUT param and, if non-NULL, write
10068 a new feasibility_problem to it on failure.
10069 (viz_callgraph_node::dump_dot): Convert begin_tr calls to
10070 begin_trtd. Convert end_tr calls to end_tdtr.
10071 (class exploded_graph_annotator): New subclass of dot_annotator.
10072 (impl_run_checkers): Add a second -fdump-analyzer-supergraph dump
10073 after the analysis runs, using exploded_graph_annotator. dumping
10074 to DUMP_BASE_NAME.supergraph-eg.dot.
10075 * exploded-graph.h (exploded_node::get_dot_fillcolor): Make
10077 (exploded_path::feasible_p): Add OUT param.
10078 (class feasibility_problem): New class.
10079 * state-purge.cc (state_purge_annotator::add_node_annotations):
10080 Return a bool, add a "within_table" param.
10081 (print_vec_of_names): Convert begin_tr calls to begin_trtd.
10082 Convert end_tr calls to end_tdtr.
10083 (state_purge_annotator::add_stmt_annotations): Add "within_row"
10085 * state-purge.h ((state_purge_annotator::add_node_annotations):
10086 Return a bool, add a "within_table" param.
10087 (state_purge_annotator::add_stmt_annotations): Add "within_row"
10089 * supergraph.cc (supernode::dump_dot): Call add_node_annotations
10090 twice: as before, passing false for "within_table", then again
10091 with true when within the TABLE element. Convert some begin_tr
10092 calls to begin_trtd, and some end_tr calls to end_tdtr.
10093 Repeat each add_stmt_annotations call, distinguishing between
10094 calls that add TRs and those that add TDs to an existing TR.
10095 Add a call to add_after_node_annotations.
10096 * supergraph.h (dot_annotator::add_node_annotations): Add a
10097 "within_table" param.
10098 (dot_annotator::add_stmt_annotations): Add a "within_row" param.
10099 (dot_annotator::add_after_node_annotations): New vfunc.
10101 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10103 * diagnostic-manager.cc (dedupe_winners::add): Show the
10104 exploded_node index in the log messages.
10105 (diagnostic_manager::emit_saved_diagnostics): Log a summary of
10106 m_saved_diagnostics at entry.
10108 2020-03-27 David Malcolm <dmalcolm@redhat.com>
10110 * supergraph.cc (superedge::dump): Add space before description;
10111 move newline to non-pretty_printer overload.
10113 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10115 * region-model.cc: Include "stor-layout.h".
10116 (region_model::dump_to_pp): Rather than calling
10117 dump_summary_of_map on each of the current frame and the globals,
10118 instead get a vec of representative path_vars for all regions,
10119 and then dump a summary of all of them.
10120 (region_model::dump_summary_of_map): Delete, rewriting into...
10121 (region_model::dump_summary_of_rep_path_vars): ...this new
10122 function, working on a vec of path_vars.
10123 (region_model::set_value): New overload.
10124 (region_model::get_representative_path_var): Rename
10125 "parent_region" local to "parent_reg" and consolidate with other
10126 local. Guard test for grandparent being stack on parent_reg being
10127 non-NULL. Move handling for parent being an array_region to
10128 within guard for parent_reg being non-NULL.
10129 (selftest::make_test_compound_type): New function.
10130 (selftest::test_dump_2): New selftest.
10131 (selftest::test_dump_3): New selftest.
10132 (selftest::test_stack_frames): Update expected output from
10133 simplified dump to show "a" and "b" from parent frame and "y" in
10135 (selftest::analyzer_region_model_cc_tests): Call test_dump_2 and
10137 * region-model.h (region_model::set_value): New overload decl.
10138 (region_model::dump_summary_of_map): Delete.
10139 (region_model::dump_summary_of_rep_path_vars): New.
10141 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10143 * region-model.h (class noop_region_model_context): New subclass
10144 of region_model_context.
10145 (class tentative_region_model_context): Inherit from
10146 noop_region_model_context rather than from region_model_context;
10147 drop redundant vfunc implementations.
10148 (class test_region_model_context): Likewise.
10150 2020-03-18 David Malcolm <dmalcolm@redhat.com>
10152 * engine.cc (exploded_node::exploded_node): Move implementation
10153 here from header; accept point_and_state by const reference rather
10155 * exploded-graph.h (exploded_node::exploded_node): Pass
10156 point_and_state by const reference rather than by value. Move
10159 2020-03-18 Jakub Jelinek <jakub@redhat.com>
10161 * sm-malloc.cc (malloc_state_machine::on_stmt): Fix up duplicated word
10162 issue in a comment.
10163 * region-model.cc (region_model::make_region_for_unexpected_tree_code,
10164 region_model::delete_region_and_descendents): Likewise.
10165 * engine.cc (class exploded_cluster): Likewise.
10166 * diagnostic-manager.cc (class path_builder): Likewise.
10168 2020-03-13 David Malcolm <dmalcolm@redhat.com>
10172 * diagnostic-manager.cc (for_each_state_change): Bulletproof
10173 against errors in get_rvalue by passing a
10174 tentative_region_model_context and rejecting if there's an error.
10175 * region-model.cc (region_model::get_lvalue_1): When handling
10176 ARRAY_REF, handle results of error-handling. Handle NOP_EXPR.
10178 2020-03-06 David Malcolm <dmalcolm@redhat.com>
10180 * analyzer.h (class array_region): New forward decl.
10181 * program-state.cc (selftest::test_program_state_dumping_2): New.
10182 (selftest::analyzer_program_state_cc_tests): Call it.
10183 * region-model.cc (array_region::constant_from_key): New.
10184 (region_model::get_representative_tree): Handle region_svalue by
10185 generating an ADDR_EXPR.
10186 (region_model::get_representative_path_var): In view handling,
10187 remove erroneous TREE_TYPE when determining the type of the tree.
10188 Handle array regions and STRING_CST.
10189 (selftest::assert_dump_tree_eq): New.
10190 (ASSERT_DUMP_TREE_EQ): New macro.
10191 (selftest::test_get_representative_tree): New selftest.
10192 (selftest::analyzer_region_model_cc_tests): Call it.
10193 * region-model.h (region::dyn_cast_array_region): New vfunc.
10194 (array_region::dyn_cast_array_region): New vfunc implementation.
10195 (array_region::constant_from_key): New decl.
10197 2020-03-06 David Malcolm <dmalcolm@redhat.com>
10199 * analyzer.h (dump_quoted_tree): New decl.
10200 * engine.cc (exploded_node::dump_dot): Pass region model to
10201 sm_state_map::print.
10202 * program-state.cc: Include diagnostic-core.h.
10203 (sm_state_map::print): Add "model" param and use it to print
10204 representative trees. Only print origin information if non-null.
10205 (sm_state_map::dump): Pass NULL for model to print call.
10206 (program_state::print): Pass region model to sm_state_map::print.
10207 (program_state::dump_to_pp): Use spaces rather than newlines when
10208 summarizing. Pass region_model to sm_state_map::print.
10209 (ana::selftest::assert_dump_eq): New function.
10210 (ASSERT_DUMP_EQ): New macro.
10211 (ana::selftest::test_program_state_dumping): New function.
10212 (ana::selftest::analyzer_program_state_cc_tests): Call it.
10213 * program-state.h (program_state::print): Add model param.
10214 * region-model.cc (dump_quoted_tree): New function.
10215 (map_region::print_fields): Use dump_quoted_tree rather than
10216 %qE to avoid lang-dependent output.
10217 (map_region::dump_child_label): Likewise.
10218 (region_model::dump_summary_of_map): For SK_REGION, when
10219 get_representative_path_var fails, print the region id rather than
10220 erroneously printing NULL.
10221 * sm.cc (state_machine::get_state_by_name): New function.
10222 * sm.h (state_machine::get_state_by_name): New decl.
10224 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10226 * region-model.cc (region::validate): Convert model param from ptr
10227 to reference. Update comment to reflect that it's now a vfunc.
10228 (map_region::validate): New vfunc implementation.
10229 (array_region::validate): New vfunc implementation.
10230 (stack_region::validate): New vfunc implementation.
10231 (root_region::validate): New vfunc implementation.
10232 (region_model::validate): Pass a reference rather than a pointer
10233 to the region::validate vfunc.
10234 * region-model.h (region::validate): Make virtual. Convert model
10235 param from ptr to reference.
10236 (map_region::validate): New vfunc decl.
10237 (array_region::validate): New vfunc decl.
10238 (stack_region::validate): New vfunc decl.
10239 (root_region::validate): New vfunc decl.
10241 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10244 * region-model.cc (region_model::on_call_pre): Handle
10245 BUILT_IN_EXPECT and its variants.
10246 (region_model::add_any_constraints_from_ssa_def_stmt): Split out
10247 gassign handling into add_any_constraints_from_gassign; add gcall
10249 (region_model::add_any_constraints_from_gassign): New function,
10250 based on the above. Add handling for NOP_EXPR.
10251 (region_model::add_any_constraints_from_gcall): New function.
10252 (region_model::get_representative_path_var): Handle views.
10254 (region_model::add_any_constraints_from_ssa_def_stmt): New decl.
10255 (region_model::add_any_constraints_from_gassign): New decl.
10257 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10260 * checker-path.h (state_change_event::get_lvalue): Add ctxt param
10261 and pass it to region_model::get_value call.
10262 * diagnostic-manager.cc (get_any_origin): Pass a
10263 tentative_region_model_context to the calls to get_lvalue and reject
10264 the comparison if errors occur.
10265 (can_be_expr_of_interest_p): New function.
10266 (diagnostic_manager::prune_for_sm_diagnostic): Replace checks for
10267 CONSTANT_CLASS_P with calls to update_for_unsuitable_sm_exprs.
10268 Pass a tentative_region_model_context to the calls to
10269 state_change_event::get_lvalue and reject the comparison if errors
10271 (diagnostic_manager::update_for_unsuitable_sm_exprs): New.
10272 * diagnostic-manager.h
10273 (diagnostic_manager::update_for_unsuitable_sm_exprs): New decl.
10274 * region-model.h (class tentative_region_model_context): New class.
10276 2020-03-04 David Malcolm <dmalcolm@redhat.com>
10278 * engine.cc (worklist::worklist): Remove unused field m_eg.
10279 (class viz_callgraph_edge): Remove unused field m_call_sedge.
10280 (class viz_callgraph): Remove unused field m_sg.
10281 * exploded-graph.h (worklist::::m_eg): Remove unused field.
10283 2020-03-02 David Malcolm <dmalcolm@redhat.com>
10285 * analyzer.opt (fanalyzer-show-duplicate-count): New option.
10286 * diagnostic-manager.cc
10287 (diagnostic_manager::emit_saved_diagnostic): Use the above to
10288 guard the printing of the duplicate count.
10290 2020-03-02 David Malcolm <dmalcolm@redhat.com>
10293 * analyzer.cc (is_std_function_p): New function.
10294 (is_std_named_call_p): New functions.
10295 * analyzer.h (is_std_named_call_p): New decl.
10296 * sm-malloc.cc (malloc_state_machine::on_stmt): Check for "std::"
10297 variants when checking for malloc, calloc and free.
10299 2020-02-26 David Malcolm <dmalcolm@redhat.com>
10302 * diagnostic-manager.cc
10303 (diagnostic_manager::prune_for_sm_diagnostic): Assert that var is
10304 either NULL or not a constant. When updating var, bulletproof
10305 against constant values.
10307 2020-02-26 David Malcolm <dmalcolm@redhat.com>
10310 * region-model.cc (region_model::get_fndecl_for_call): Gracefully
10311 fail for fn_decls that don't have a cgraph_node.
10313 2020-02-26 David Malcolm <dmalcolm@redhat.com>
10315 * bar-chart.cc: New file.
10316 * bar-chart.h: New file.
10317 * engine.cc: Include "analyzer/bar-chart.h".
10318 (stats::log): Only log the m_num_nodes kinds that are non-zero.
10319 (stats::dump): Likewise when dumping.
10320 (stats::get_total_enodes): New.
10321 (exploded_graph::get_or_create_node): Increment the per-point-data
10322 m_excess_enodes when hitting the per-program-point limit on
10324 (exploded_graph::print_bar_charts): New.
10325 (exploded_graph::log_stats): Log the number of unprocessed enodes
10326 in the worklist. Call print_bar_charts.
10327 (exploded_graph::dump_stats): Print the number of unprocessed
10328 enodes in the worklist.
10329 * exploded-graph.h (stats::get_total_enodes): New decl.
10330 (struct per_program_point_data): Add field m_excess_enodes.
10331 (exploded_graph::print_bar_charts): New decl.
10332 * supergraph.cc (superedge::dump): New.
10333 (superedge::dump): New.
10334 * supergraph.h (supernode::get_function): New.
10335 (superedge::dump): New decl.
10336 (superedge::dump): New decl.
10338 2020-02-24 David Malcolm <dmalcolm@redhat.com>
10340 * engine.cc (exploded_graph::get_or_create_node): Dump the
10341 program_state to the pp, rather than to stderr.
10343 2020-02-24 David Malcolm <dmalcolm@redhat.com>
10346 * sm.cc (make_checkers): Require the "taint" checker to be
10347 explicitly enabled.
10349 2020-02-24 David Malcolm <dmalcolm@redhat.com>
10353 (impl_region_model_context::impl_region_model_context): Add logger
10355 * engine.cc (exploded_graph::add_function_entry): Create an
10356 impl_region_model_context and pass it to the push_frame call.
10357 Bail if the resulting state is invalid.
10358 (exploded_graph::build_initial_worklist): Likewise.
10359 (exploded_graph::build_initial_worklist): Handle the case where
10360 add_function_entry fails.
10362 (impl_region_model_context::impl_region_model_context): Add logger
10364 * region-model.cc (map_region::get_or_create): Add ctxt param and
10365 pass it to add_region_for_type.
10366 (map_region::can_merge_p): Pass NULL as a ctxt to call to
10368 (array_region::get_element): Pass ctxt to call to get_or_create.
10369 (array_region::get_or_create): Add ctxt param and pass it to
10370 add_region_for_type.
10371 (root_region::push_frame): Pass ctxt to get_or_create calls.
10372 (region_model::get_lvalue_1): Likewise.
10373 (region_model::make_region_for_unexpected_tree_code): Assert that
10375 (region_model::get_rvalue_1): Pass ctxt to get_svalue_for_fndecl
10376 and get_svalue_for_label calls.
10377 (region_model::get_svalue_for_fndecl): Add ctxt param and pass it
10378 to get_region_for_fndecl.
10379 (region_model::get_region_for_fndecl): Add ctxt param and pass it
10381 (region_model::get_svalue_for_label): Add ctxt param and pass it
10382 to get_region_for_label.
10383 (region_model::get_region_for_label): Add ctxt param and pass it
10384 to get_region_for_fndecl and get_or_create.
10385 (region_model::get_field_region): Add ctxt param and pass it to
10386 get_or_create_view and get_or_create.
10387 (make_region_for_type): Replace gcc_unreachable with return NULL.
10388 (region_model::add_region_for_type): Add ctxt param. Handle a
10389 return of NULL from make_region_for_type by calling
10390 make_region_for_unexpected_tree_code.
10391 (region_model::get_or_create_mem_ref): Pass ctxt to calls to
10392 get_or_create_view.
10393 (region_model::get_or_create_view): Add ctxt param and pass it to
10394 add_region_for_type.
10395 (selftest::test_state_merging): Pass ctxt to get_or_create_view.
10396 * region-model.h (region_model::get_or_create): Add ctxt param.
10397 (region_model::add_region_for_type): Likewise.
10398 (region_model::get_svalue_for_fndecl): Likewise.
10399 (region_model::get_svalue_for_label): Likewise.
10400 (region_model::get_region_for_fndecl): Likewise.
10401 (region_model::get_region_for_label): Likewise.
10402 (region_model::get_field_region): Likewise.
10403 (region_model::get_or_create_view): Likewise.
10405 2020-02-24 David Malcolm <dmalcolm@redhat.com>
10407 * checker-path.cc (superedge_event::should_filter_p): Update
10408 filter for empty descriptions to cover verbosity level 3 as well
10410 * diagnostic-manager.cc: Include "analyzer/reachability.h".
10411 (class path_builder): New class.
10412 (diagnostic_manager::emit_saved_diagnostic): Create a path_builder
10413 and pass it to build_emission_path, rather passing eg; similarly
10414 for add_events_for_eedge and ext_state.
10415 (diagnostic_manager::build_emission_path): Replace "eg" param
10416 with a path_builder, pass it to add_events_for_eedge.
10417 (diagnostic_manager::add_events_for_eedge): Replace ext_state
10418 param with path_builder; pass it to add_events_for_superedge.
10419 (diagnostic_manager::significant_edge_p): New.
10420 (diagnostic_manager::add_events_for_superedge): Add path_builder
10421 param. Reject insignificant edges at verbosity levels below 3.
10422 (diagnostic_manager::prune_for_sm_diagnostic): Update highest
10423 verbosity level to 4.
10424 * diagnostic-manager.h (class path_builder): New forward decl.
10425 (diagnostic_manager::build_emission_path): Replace "eg" param
10426 with a path_builder.
10427 (diagnostic_manager::add_events_for_eedge): Replace ext_state
10428 param with path_builder.
10429 (diagnostic_manager::significant_edge_p): New.
10430 (diagnostic_manager::add_events_for_superedge): Add path_builder
10432 * reachability.h: New file.
10434 2020-02-18 David Malcolm <dmalcolm@redhat.com>
10437 * analyzer.opt (fdump-analyzer-callgraph): Rewrite description.
10439 2020-02-18 David Malcolm <dmalcolm@redhat.com>
10442 * region-model.cc (region_model::maybe_cast_1): Replace assertion
10443 that build_cast returns non-NULL with a conditional, falling
10444 through to the logic which returns a new unknown value of the
10445 desired type if it fails.
10447 2020-02-18 David Malcolm <dmalcolm@redhat.com>
10450 * engine.cc (impl_region_model_context::on_unknown_tree_code):
10452 (impl_region_model_context::on_unexpected_tree_code): ...this and
10453 convert first argument from path_var to tree.
10454 (exploded_node::on_stmt): Pass ctxt to purge_for_unknown_fncall.
10455 * exploded-graph.h (region_model_context::on_unknown_tree_code):
10457 (region_model_context::on_unexpected_tree_code): ...this and
10458 convert first argument from path_var to tree.
10459 * program-state.cc (sm_state_map::purge_for_unknown_fncall): Add
10460 ctxt param and pass on to calls to get_rvalue.
10461 * program-state.h (sm_state_map::purge_for_unknown_fncall): Add
10463 * region-model.cc (region_model::handle_unrecognized_call): Pass
10464 ctxt on to call to get_rvalue.
10465 (region_model::get_lvalue_1): Move body of default case to
10466 region_model::make_region_for_unexpected_tree_code and call it.
10467 Within COMPONENT_REF case, reject attempts to handle types other
10468 than RECORD_TYPE and UNION_TYPE.
10469 (region_model::make_region_for_unexpected_tree_code): New
10470 function, based on default case of region_model::get_lvalue_1.
10472 (region_model::make_region_for_unexpected_tree_code): New decl.
10473 (region_model::on_unknown_tree_code): Rename to...
10474 (region_model::on_unexpected_tree_code): ...this and convert first
10475 argument from path_var to tree.
10476 (class test_region_model_context): Update vfunc implementation for
10479 2020-02-18 David Malcolm <dmalcolm@redhat.com>
10483 (region_model::convert_byte_offset_to_array_index): Use
10484 int_size_in_bytes before calling size_in_bytes, to gracefully fail
10485 on incomplete types.
10487 2020-02-17 David Malcolm <dmalcolm@redhat.com>
10490 * region-model.cc (region_model::get_fndecl_for_call): Handle the
10491 case where the code_region's get_tree_for_child_region returns
10494 2020-02-17 David Malcolm <dmalcolm@redhat.com>
10497 * engine.cc (impl_region_model_context::on_unknown_tree_code):
10499 (exploded_graph::get_or_create_node): Reject invalid states.
10501 (impl_region_model_context::on_unknown_tree_code): New decl.
10502 (point_and_state::point_and_state): Assert that the state is
10504 * program-state.cc (program_state::program_state): Initialize
10506 (program_state::operator=): Copy m_valid.
10507 (program_state::program_state): Likewise for move constructor.
10508 (program_state::print): Print m_valid.
10509 (program_state::dump_to_pp): Likewise.
10510 * program-state.h (program_state::m_valid): New field.
10511 * region-model.cc (region_model::get_lvalue_1): Implement the
10512 default case by returning a new symbolic region and calling
10513 the context's on_unknown_tree_code, rather than issuing an
10514 internal_error. Implement VIEW_CONVERT_EXPR.
10515 * region-model.h (region_model_context::on_unknown_tree_code): New
10517 (test_region_model_context::on_unknown_tree_code): New.
10519 2020-02-17 David Malcolm <dmalcolm@redhat.com>
10521 * sm-malloc.cc (malloc_diagnostic::describe_state_change): For
10522 transition to the "null" state, only say "assuming" when
10523 transitioning from the "unchecked" state.
10525 2020-02-17 David Malcolm <dmalcolm@redhat.com>
10527 * diagnostic-manager.h (diagnostic_manager::get_saved_diagnostic):
10528 Add const overload.
10529 * engine.cc (exploded_node::dump_dot): Dump saved_diagnostics.
10530 * exploded-graph.h (exploded_graph::get_diagnostic_manager): Add
10533 2020-02-11 David Malcolm <dmalcolm@redhat.com>
10536 * analysis-plan.cc (analysis_plan::use_summary_p): Look through
10537 the ultimate_alias_target when getting the called function.
10538 * engine.cc (exploded_node::on_stmt): Rename second "ctxt" to
10539 "sm_ctxt". Use the region_model's get_fndecl_for_call rather than
10540 gimple_call_fndecl.
10541 * region-model.cc (region_model::get_fndecl_for_call): Use
10542 ultimate_alias_target on fndecl.
10543 * supergraph.cc (get_ultimate_function_for_cgraph_edge): New
10545 (supergraph_call_edge): Use it when rejecting edges without
10547 (supergraph::supergraph): Use it to get the function for the
10548 cgraph_edge when building interprocedural superedges.
10549 (callgraph_superedge::get_callee_function): Use it.
10550 * supergraph.h (supergraph::get_num_snodes): Make param const.
10551 (supergraph::function_to_num_snodes_t): Make first type param
10554 2020-02-11 David Malcolm <dmalcolm@redhat.com>
10557 * engine.cc (exploded_edge::exploded_edge): Add ext_state param
10558 and pass it to change.validate.
10559 (exploded_graph::get_or_create_node): Move purging of change
10560 svalues to also cover the case of reusing an existing enode.
10561 (exploded_graph::add_edge): Pass m_ext_state to exploded_edge's
10563 * exploded-graph.h (exploded_edge::exploded_edge): Add ext_state
10565 * program-state.cc (state_change::sm_change::validate): Likewise.
10566 Assert that m_sm_idx is sane. Use ext_state to validate
10567 m_old_state and m_new_state.
10568 (state_change::validate): Add ext_state param and pass it to
10569 the sm_change validate calls.
10570 * program-state.h (state_change::sm_change::validate): Add
10572 (state_change::validate): Likewise.
10574 2020-02-11 David Malcolm <dmalcolm@redhat.com>
10577 * engine.cc (exploded_graph::dump_exploded_nodes): Handle missing
10578 case of STATUS_WORKLIST in implementation of
10579 "__analyzer_dump_exploded_nodes".
10581 2020-02-11 David Malcolm <dmalcolm@redhat.com>
10584 * constraint-manager.cc (constraint_manager::add_constraint): When
10585 merging equivalence classes and updating m_constant, also update
10587 (constraint_manager::validate): If m_constant is non-NULL assert
10588 that m_cst_sid is non-null and is valid.
10590 2020-02-11 David Malcolm <dmalcolm@redhat.com>
10593 * analyzer.opt (fdump-analyzer): Reword description.
10594 (fdump-analyzer-stderr): Likewise.
10596 2020-02-11 David Malcolm <dmalcolm@redhat.com>
10598 * region-model.cc (print_quoted_type): New function.
10599 (svalue::print): Use it to replace %qT.
10600 (region::dump_to_pp): Likewise.
10601 (region::dump_child_label): Likewise.
10602 (region::print_fields): Likewise.
10604 2020-02-10 David Malcolm <dmalcolm@redhat.com>
10607 * analyzer.opt (-param=analyzer-max-recursion-depth=): Fix "tha"
10609 (Wanalyzer-use-of-uninitialized-value): Fix "initialized" ->
10610 "uninitialized" typo.
10612 2020-02-10 David Malcolm <dmalcolm@redhat.com>
10615 * region-model.cc (region_model::get_lvalue_1):
10616 Handle BIT_FIELD_REF.
10617 (make_region_for_type): Handle VECTOR_TYPE.
10619 2020-02-10 David Malcolm <dmalcolm@redhat.com>
10622 * diagnostic-manager.cc
10623 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof against
10624 VAR being constant.
10625 * region-model.cc (region_model::get_lvalue_1): Provide a better
10626 error message when encountering an unhandled tree code.
10628 2020-02-10 David Malcolm <dmalcolm@redhat.com>
10631 * region-model.cc (region_model::get_lvalue_1): Implement
10634 2020-02-06 David Malcolm <dmalcolm@redhat.com>
10636 * region-model.cc (region_model::maybe_cast_1): Attempt to provide
10637 a region_svalue if either type is a pointer, rather than if both
10638 types are pointers.
10640 2020-02-05 David Malcolm <dmalcolm@redhat.com>
10642 * engine.cc (exploded_node::dump_dot): Show merger enodes.
10643 (worklist::add_node): Assert that the node's m_status is
10645 (exploded_graph::process_worklist): Likewise for nodes from the
10646 worklist. Set status of merged nodes to STATUS_MERGER.
10647 (exploded_graph::process_node): Set status of node to
10649 (exploded_graph::dump_exploded_nodes): Rework handling of
10650 "__analyzer_dump_exploded_nodes", splitting enodes by status into
10651 "processed" and "merger", showing the count of just the processed
10652 enodes at the call, rather than the count of all enodes.
10653 * exploded-graph.h (exploded_node::status): New enum.
10654 (exploded_node::exploded_node): Initialize m_status to
10656 (exploded_node::get_status): New getter.
10657 (exploded_node::set_status): New setter.
10659 2020-02-04 David Malcolm <dmalcolm@redhat.com>
10662 * engine.cc (pod_hash_traits<function_call_string>::mark_empty):
10663 Eliminate reinterpret_cast.
10664 (pod_hash_traits<function_call_string>::is_empty): Likewise.
10666 2020-02-03 David Malcolm <dmalcolm@redhat.com>
10668 * constraint-manager.cc (range::constrained_to_single_element):
10669 Replace fold_build2 with fold_binary. Remove unnecessary newline.
10670 (constraint_manager::get_or_add_equiv_class): Replace fold_build2
10671 with fold_binary in two places, and remove out-of-date comment.
10672 (constraint_manager::eval_condition): Replace fold_build2 with
10674 * region-model.cc (constant_svalue::eval_condition): Likewise.
10675 (region_model::on_assignment): Likewise.
10677 2020-02-03 David Malcolm <dmalcolm@redhat.com>
10680 * diagnostic-manager.cc
10681 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof
10682 against bad choices due to bad paths.
10683 * engine.cc (impl_region_model_context::on_phi): New.
10684 * exploded-graph.h (impl_region_model_context::on_phi): New decl.
10685 * region-model.cc (region_model::on_longjmp): Likewise.
10686 (region_model::handle_phi): Add phi param. Call the ctxt's on_phi
10688 (region_model::update_for_phis): Pass phi to handle_phi.
10689 * region-model.h (region_model::handle_phi): Add phi param.
10690 (region_model_context::on_phi): New vfunc.
10691 (test_region_model_context::on_phi): New.
10692 * sm-malloc.cc (malloc_state_machine::on_phi): New.
10693 (malloc_state_machine::on_zero_assignment): New.
10694 * sm.h (state_machine::on_phi): New vfunc.
10696 2020-02-03 David Malcolm <dmalcolm@redhat.com>
10698 * engine.cc (supernode_cluster::dump_dot): Show BB index as
10700 * supergraph.cc (supernode::dump_dot): Likewise.
10702 2020-02-03 David Malcolm <dmalcolm@redhat.com>
10705 * region-model.cc (region_model::on_call_pre): Update for new
10706 param of symbolic_region ctor.
10707 (region_model::deref_rvalue): Likewise.
10708 (region_model::add_new_malloc_region): Likewise.
10709 (make_region_for_type): Likewise, preserving type.
10710 * region-model.h (symbolic_region::symbolic_region): Add "type"
10711 param and pass it to base class ctor.
10713 2020-02-03 David Malcolm <dmalcolm@redhat.com>
10716 * constraint-manager.cc
10717 (constraint_manager::get_or_add_equiv_class): Ensure types are
10718 compatible before comparing constants.
10720 2020-01-31 David Malcolm <dmalcolm@redhat.com>
10723 * region-model.cc (make_region_for_type): Use VOID_TYPE_P rather
10724 than checking against void_type_node.
10726 2020-01-31 David Malcolm <dmalcolm@redhat.com>
10729 * region-model.cc (ASSERT_COMPAT_TYPES): Convert to...
10730 (assert_compat_types): ...this, and bail when either type is NULL,
10731 or when VOID_TYPE_P (dst_type).
10732 (region_model::get_lvalue): Update for above conversion.
10733 (region_model::get_rvalue): Likewise.
10735 2020-01-31 David Malcolm <dmalcolm@redhat.com>
10738 * region-model.cc (region_model::update_for_return_superedge):
10739 Move check for null result so that it also guards setting the
10742 2020-01-31 David Malcolm <dmalcolm@redhat.com>
10745 * region-model.cc (stack_region::can_merge_p): Split into a two
10746 pass approach, creating all stack regions first, then populating
10748 (selftest::test_state_merging): Add test coverage for (a) the case
10749 of self-merging a model in which a local in an older stack frame
10750 points to a local in a more recent stack frame (which previously
10751 would ICE), and (b) the case of self-merging a model in which a
10752 local points to a global (which previously worked OK).
10754 2020-01-31 David Malcolm <dmalcolm@redhat.com>
10756 * analyzer.cc (is_named_call_p): Replace tests for fndecl being
10757 extern at file scope and having a non-NULL DECL_NAME with a call
10758 to maybe_special_function_p.
10759 * function-set.cc (function_set::contains_decl_p): Add call to
10760 maybe_special_function_p.
10762 2020-01-31 David Malcolm <dmalcolm@redhat.com>
10765 * constraint-manager.cc
10766 (constraint_manager::get_or_add_equiv_class): Only compare constants
10767 if their types are compatible.
10768 * region-model.cc (constant_svalue::eval_condition): Replace check
10769 for identical types with call to types_compatible_p.
10771 2020-01-30 David Malcolm <dmalcolm@redhat.com>
10773 * program-state.cc (extrinsic_state::dump_to_pp): New.
10774 (extrinsic_state::dump_to_file): New.
10775 (extrinsic_state::dump): New.
10776 * program-state.h (extrinsic_state::dump_to_pp): New decl.
10777 (extrinsic_state::dump_to_file): New decl.
10778 (extrinsic_state::dump): New decl.
10779 * sm.cc: Include "pretty-print.h".
10780 (state_machine::dump_to_pp): New.
10781 * sm.h (state_machine::dump_to_pp): New decl.
10783 2020-01-30 David Malcolm <dmalcolm@redhat.com>
10785 * diagnostic-manager.cc (for_each_state_change): Use
10786 extrinsic_state::get_num_checkers rather than accessing m_checkers
10788 * program-state.cc (program_state::program_state): Likewise.
10789 * program-state.h (extrinsic_state::m_checkers): Make private.
10791 2020-01-30 David Malcolm <dmalcolm@redhat.com>
10794 * region-model.cc (region_model::eval_condition): In both
10795 overloads, bail out immediately on floating-point types.
10796 (region_model::eval_condition_without_cm): Likewise.
10797 (region_model::add_constraint): Likewise.
10799 2020-01-30 David Malcolm <dmalcolm@redhat.com>
10802 * program-state.cc (sm_state_map::set_state): For the overload
10803 taking an svalue_id, bail out if the set_state on the ec does
10804 nothing. Convert the latter's return type from void to bool,
10805 returning true if anything changed.
10806 (sm_state_map::impl_set_state): Convert the return type from void
10807 to bool, returning true if the state changed.
10808 * program-state.h (sm_state_map::set_state): Convert return type
10810 (sm_state_map::impl_set_state): Likewise.
10811 * region-model.cc (constant_svalue::eval_condition): Only call
10812 fold_build2 if the types are the same.
10814 2020-01-29 Jakub Jelinek <jakub@redhat.com>
10816 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Remove.
10817 * constraint-manager.cc: Include diagnostic-core.h before graphviz.h.
10818 (range::dump, equiv_class::print): Don't use PUSH_IGNORE_WFORMAT or
10819 POP_IGNORE_WFORMAT.
10820 * state-purge.cc: Include diagnostic-core.h before
10821 gimple-pretty-print.h.
10822 (state_purge_annotator::add_node_annotations, print_vec_of_names):
10823 Don't use PUSH_IGNORE_WFORMAT or POP_IGNORE_WFORMAT.
10824 * region-model.cc: Move diagnostic-core.h include before graphviz.h.
10825 (path_var::dump, svalue::print, constant_svalue::print_details,
10826 region::dump_to_pp, region::dump_child_label, region::print_fields,
10827 map_region::print_fields, map_region::dump_dot_to_pp,
10828 map_region::dump_child_label, array_region::print_fields,
10829 array_region::dump_dot_to_pp): Don't use PUSH_IGNORE_WFORMAT or
10830 POP_IGNORE_WFORMAT.
10832 2020-01-28 David Malcolm <dmalcolm@redhat.com>
10835 * engine.cc (rewind_info_t::update_model): Get the longjmp call
10836 stmt via get_longjmp_call () rather than assuming it is the last
10837 stmt in the longjmp's supernode.
10838 (rewind_info_t::add_events_to_path): Get the location_t for the
10839 rewind_from_longjmp_event via get_longjmp_call () rather than from
10840 the supernode's get_end_location ().
10842 2020-01-28 David Malcolm <dmalcolm@redhat.com>
10844 * region-model.cc (poisoned_value_diagnostic::emit): Update for
10845 renaming of warning_at overload to warning_meta.
10846 * sm-file.cc (file_leak::emit): Likewise.
10847 * sm-malloc.cc (double_free::emit): Likewise.
10848 (possible_null_deref::emit): Likewise.
10849 (possible_null_arg::emit): Likewise.
10850 (null_deref::emit): Likewise.
10851 (null_arg::emit): Likewise.
10852 (use_after_free::emit): Likewise.
10853 (malloc_leak::emit): Likewise.
10854 (free_of_non_heap::emit): Likewise.
10855 * sm-sensitive.cc (exposure_through_output_file::emit): Likewise.
10856 * sm-signal.cc (signal_unsafe_call::emit): Likewise.
10857 * sm-taint.cc (tainted_array_index::emit): Likewise.
10859 2020-01-27 David Malcolm <dmalcolm@redhat.com>
10862 * region-model.cc (tree_cmp): For the REAL_CST case, impose an
10863 arbitrary order on NaNs relative to other NaNs and to non-NaNs;
10864 const-correctness tweak.
10865 (ana::selftests::build_real_cst_from_string): New function.
10866 (ana::selftests::append_interesting_constants): New function.
10867 (ana::selftests::test_tree_cmp_on_constants): New test.
10868 (ana::selftests::test_canonicalization_4): New test.
10869 (ana::selftests::analyzer_region_model_cc_tests): Call the new
10872 2020-01-27 David Malcolm <dmalcolm@redhat.com>
10875 * engine.cc (run_checkers): Save and restore input_location.
10877 2020-01-27 David Malcolm <dmalcolm@redhat.com>
10879 * call-string.cc (call_string::cmp_1): Delete, moving body to...
10880 (call_string::cmp): ...here.
10881 * call-string.h (call_string::cmp_1): Delete decl.
10882 * engine.cc (worklist::key_t::cmp_1): Delete, moving body to...
10883 (worklist::key_t::cmp): ...here. Implement hash comparisons
10884 via comparison rather than subtraction to avoid overflow issues.
10885 * exploded-graph.h (worklist::key_t::cmp_1): Delete decl.
10886 * region-model.cc (tree_cmp): Eliminate buggy checking for
10889 2020-01-27 David Malcolm <dmalcolm@redhat.com>
10891 * analyzer.cc (is_named_call_p): Check that fndecl is "extern"
10892 and at file scope. Potentially disregard prefix _ or __ in
10893 fndecl's name. Bail if the identifier is NULL.
10894 (is_setjmp_call_p): Expect a gcall rather than plain gimple.
10895 Remove special-case check for leading prefix, and also check for
10897 (is_longjmp_call_p): Also check for siglongjmp.
10898 (get_user_facing_name): New function.
10899 * analyzer.h (is_setjmp_call_p): Expect a gcall rather than plain
10901 (get_user_facing_name): New decl.
10902 * checker-path.cc (setjmp_event::get_desc): Use
10903 get_user_facing_name to avoid hardcoding the function name.
10904 (rewind_event::rewind_event): Add rewind_info param, using it to
10905 initialize new m_rewind_info field, and strengthen the assertion.
10906 (rewind_from_longjmp_event::get_desc): Use get_user_facing_name to
10907 avoid hardcoding the function name.
10908 (rewind_to_setjmp_event::get_desc): Likewise.
10909 * checker-path.h (setjmp_event::setjmp_event): Add setjmp_call
10910 param and use it to initialize...
10911 (setjmp_event::m_setjmp_call): New field.
10912 (rewind_event::rewind_event): Add rewind_info param.
10913 (rewind_event::m_rewind_info): New protected field.
10914 (rewind_from_longjmp_event::rewind_from_longjmp_event): Add
10916 (class rewind_to_setjmp_event): Move rewind_info field to parent
10918 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
10919 Update setjmp-handling for is_setjmp_call_p requiring a gcall;
10920 pass the call to the new setjmp_event.
10921 * engine.cc (exploded_node::on_stmt): Update for is_setjmp_call_p
10923 (stale_jmp_buf::emit): Use get_user_facing_name to avoid
10924 hardcoding the function names.
10925 (exploded_node::on_longjmp): Pass the longjmp_call when
10926 constructing rewind_info.
10927 (rewind_info_t::add_events_to_path): Pass the rewind_info_t to the
10928 rewind_from_longjmp_event's ctor.
10929 * exploded-graph.h (rewind_info_t::rewind_info_t): Add
10930 longjmp_call param.
10931 (rewind_info_t::get_longjmp_call): New.
10932 (rewind_info_t::m_longjmp_call): New.
10933 * region-model.cc (region_model::on_setjmp): Update comment to
10934 indicate this is also for sigsetjmp.
10935 * region-model.h (struct setjmp_record): Likewise.
10936 (class setjmp_svalue): Likewise.
10938 2020-01-27 David Malcolm <dmalcolm@redhat.com>
10941 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Guard these
10942 macros with GCC_VERSION >= 4006, making them no-op otherwise.
10943 * engine.cc (exploded_edge::exploded_edge): Specify template for
10944 base class initializer.
10945 (exploded_graph::add_edge): Specify template when chaining up to
10946 base class add_edge implementation.
10947 (viz_callgraph_node::dump_dot): Drop redundant "typename".
10948 (viz_callgraph_edge::viz_callgraph_edge): Specify template for
10949 base class initializer.
10950 * program-state.cc (sm_state_map::clone_with_remapping): Drop
10951 redundant "typename".
10952 (sm_state_map::print): Likewise.
10953 (sm_state_map::hash): Likewise.
10954 (sm_state_map::operator==): Likewise.
10955 (sm_state_map::remap_svalue_ids): Likewise.
10956 (sm_state_map::on_svalue_purge): Likewise.
10957 (sm_state_map::validate): Likewise.
10958 * program-state.h (sm_state_map::iterator_t): Likewise.
10959 * supergraph.h (superedge::superedge): Specify template for base
10962 2020-01-23 David Malcolm <dmalcolm@redhat.com>
10965 * supergraph.cc (callgraph_superedge::get_arg_for_parm): Fail
10966 gracefully is the number of parameters at the callee exceeds the
10967 number of arguments at the call stmt.
10968 (callgraph_superedge::get_parm_for_arg): Likewise.
10970 2020-01-22 David Malcolm <dmalcolm@redhat.com>
10973 * program-state.cc (sm_state_map::on_svalue_purge): If the
10974 entry survives, but the origin is being purged, then reset the
10977 2020-01-22 David Malcolm <dmalcolm@redhat.com>
10979 * sm-signal.cc: Fix nesting of CHECKING_P and namespace ana.
10981 2020-01-22 David Malcolm <dmalcolm@redhat.com>
10984 * engine.cc (setjmp_svalue::compare_fields): Update for
10985 replacement of m_enode with m_setjmp_record.
10986 (setjmp_svalue::add_to_hash): Likewise.
10987 (setjmp_svalue::get_index): Rename...
10988 (setjmp_svalue::get_enode_index): ...to this.
10989 (setjmp_svalue::print_details): Update for replacement of m_enode
10990 with m_setjmp_record.
10991 (exploded_node::on_longjmp): Likewise.
10992 * exploded-graph.h (rewind_info_t::m_enode_origin): Replace...
10993 (rewind_info_t::m_setjmp_record): ...with this.
10994 (rewind_info_t::rewind_info_t): Update for replacement of m_enode
10995 with m_setjmp_record.
10996 (rewind_info_t::get_setjmp_point): Likewise.
10997 (rewind_info_t::get_setjmp_call): Likewise.
10998 * region-model.cc (region_model::dump_summary_of_map): Likewise.
10999 (region_model::on_setjmp): Likewise.
11000 * region-model.h (struct setjmp_record): New struct.
11001 (setjmp_svalue::m_enode): Replace...
11002 (setjmp_svalue::m_setjmp_record): ...with this.
11003 (setjmp_svalue::setjmp_svalue): Update for replacement of m_enode
11004 with m_setjmp_record.
11005 (setjmp_svalue::clone): Likewise.
11006 (setjmp_svalue::get_index): Rename...
11007 (setjmp_svalue::get_enode_index): ...to this.
11008 (setjmp_svalue::get_exploded_node): Replace...
11009 (setjmp_svalue::get_setjmp_record): ...with this.
11011 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11014 * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as
11017 2020-01-22 David Malcolm <dmalcolm@redhat.com>
11020 * analysis-plan.h: Wrap everything namespace "ana".
11021 * analyzer-logging.cc: Likewise.
11022 * analyzer-logging.h: Likewise.
11023 * analyzer-pass.cc (pass_analyzer::execute): Update for "ana"
11025 * analyzer-selftests.cc: Wrap everything namespace "ana".
11026 * analyzer-selftests.h: Likewise.
11027 * analyzer.h: Likewise for forward decls of types.
11028 * call-string.h: Likewise.
11029 * checker-path.cc: Likewise.
11030 * checker-path.h: Likewise.
11031 * constraint-manager.cc: Likewise.
11032 * constraint-manager.h: Likewise.
11033 * diagnostic-manager.cc: Likewise.
11034 * diagnostic-manager.h: Likewise.
11035 * engine.cc: Likewise.
11036 * engine.h: Likewise.
11037 * exploded-graph.h: Likewise.
11038 * function-set.cc: Likewise.
11039 * function-set.h: Likewise.
11040 * pending-diagnostic.cc: Likewise.
11041 * pending-diagnostic.h: Likewise.
11042 * program-point.cc: Likewise.
11043 * program-point.h: Likewise.
11044 * program-state.cc: Likewise.
11045 * program-state.h: Likewise.
11046 * region-model.cc: Likewise.
11047 * region-model.h: Likewise.
11048 * sm-file.cc: Likewise.
11049 * sm-malloc.cc: Likewise.
11050 * sm-pattern-test.cc: Likewise.
11051 * sm-sensitive.cc: Likewise.
11052 * sm-signal.cc: Likewise.
11053 * sm-taint.cc: Likewise.
11056 * state-purge.h: Likewise.
11057 * supergraph.cc: Likewise.
11058 * supergraph.h: Likewise.
11060 2020-01-21 David Malcolm <dmalcolm@redhat.com>
11063 * region-model.cc (int_cmp): Rename to...
11064 (array_region::key_cmp): ...this, using key_t rather than int.
11065 Rewrite in terms of comparisons rather than subtraction to
11066 ensure qsort is anti-symmetric when handling extreme values.
11067 (array_region::walk_for_canonicalization): Update for above
11069 * region-model.h (array_region::key_cmp): New decl.
11071 2020-01-17 David Malcolm <dmalcolm@redhat.com>
11074 * region-model.cc (region_model::eval_condition_without_cm): Avoid
11075 gcc_unreachable for unexpected operations for the case where
11076 we're comparing an svalue against itself.
11078 2020-01-17 David Malcolm <dmalcolm@redhat.com>
11082 (region_model::convert_byte_offset_to_array_index): Convert to
11083 ssizetype before dividing by byte_size. Use fold_binary rather
11084 than fold_build2 to avoid needlessly constructing a tree for the
11087 2020-01-15 David Malcolm <dmalcolm@redhat.com>
11089 * engine.cc (class impl_region_model_context): Fix comment.
11091 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11094 * region-model.cc (make_region_for_type): Use
11095 FUNC_OR_METHOD_TYPE_P rather than comparing against FUNCTION_TYPE.
11096 * region-model.h (function_region::function_region): Likewise.
11098 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11100 * program-state.cc (sm_state_map::clone_with_remapping): Copy
11102 (selftest::test_program_state_merging_2): New selftest.
11103 (selftest::analyzer_program_state_cc_tests): Call it.
11105 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11107 * checker-path.h (checker_path::get_checker_event): New function.
11108 (checker_path): Add DISABLE_COPY_AND_ASSIGN; make fields private.
11109 * diagnostic-manager.cc
11110 (diagnostic_manager::prune_for_sm_diagnostic): Replace direct
11111 access to checker_path::m_events with accessor functions. Fix
11113 (diagnostic_manager::prune_interproc_events): Replace direct
11114 access to checker_path::m_events with accessor functions.
11115 (diagnostic_manager::finish_pruning): Likewise.
11117 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11119 * checker-path.h (checker_event::clone): Delete vfunc decl.
11120 (debug_event::clone): Delete vfunc impl.
11121 (custom_event::clone): Delete vfunc impl.
11122 (statement_event::clone): Delete vfunc impl.
11123 (function_entry_event::clone): Delete vfunc impl.
11124 (state_change_event::clone): Delete vfunc impl.
11125 (start_cfg_edge_event::clone): Delete vfunc impl.
11126 (end_cfg_edge_event::clone): Delete vfunc impl.
11127 (call_event::clone): Delete vfunc impl.
11128 (return_event::clone): Delete vfunc impl.
11129 (setjmp_event::clone): Delete vfunc impl.
11130 (rewind_from_longjmp_event::clone): Delete vfunc impl.
11131 (rewind_to_setjmp_event::clone): Delete vfunc impl.
11132 (warning_event::clone): Delete vfunc impl.
11134 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11136 * supergraph.cc (supernode::dump_dot): Ensure that the TABLE
11137 element has at least one TR.
11139 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11142 * engine.cc (leak_stmt_finder::find_stmt): Use get_pure_location
11143 when comparing against UNKNOWN_LOCATION.
11144 (stmt_requires_new_enode_p): Likewise.
11145 (exploded_graph::dump_exploded_nodes): Likewise.
11146 * supergraph.cc (supernode::get_start_location): Likewise.
11147 (supernode::get_end_location): Likewise.
11149 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11152 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11153 selftest::analyzer_sm_file_cc_tests.
11154 * analyzer-selftests.h (selftest::analyzer_sm_file_cc_tests): New
11156 * sm-file.cc: Include "analyzer/function-set.h" and
11157 "analyzer/analyzer-selftests.h".
11158 (get_file_using_fns): New function.
11159 (is_file_using_fn_p): New function.
11160 (fileptr_state_machine::on_stmt): Return true for known functions.
11161 (selftest::analyzer_sm_file_cc_tests): New function.
11163 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11165 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11166 selftest::analyzer_sm_signal_cc_tests.
11167 * analyzer-selftests.h (selftest::analyzer_sm_signal_cc_tests):
11169 * sm-signal.cc: Include "analyzer/function-set.h" and
11170 "analyzer/analyzer-selftests.h".
11171 (get_async_signal_unsafe_fns): New function.
11172 (signal_unsafe_p): Reimplement in terms of the above.
11173 (selftest::analyzer_sm_signal_cc_tests): New function.
11175 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11177 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
11178 selftest::analyzer_function_set_cc_tests.
11179 * analyzer-selftests.h (selftest::analyzer_function_set_cc_tests):
11181 * function-set.cc: New file.
11182 * function-set.h: New file.
11184 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11186 * analyzer.h (fndecl_has_gimple_body_p): New decl.
11187 * engine.cc (impl_region_model_context::on_unknown_change): New
11189 (fndecl_has_gimple_body_p): Make non-static.
11190 (exploded_node::on_stmt): Treat __analyzer_dump_exploded_nodes as
11191 known. Track whether we have a call with unknown side-effects and
11192 pass it to on_call_post.
11193 * exploded-graph.h (impl_region_model_context::on_unknown_change):
11195 * program-state.cc (sm_state_map::on_unknown_change): New function.
11196 * program-state.h (sm_state_map::on_unknown_change): New decl.
11197 * region-model.cc: Include "bitmap.h".
11198 (region_model::on_call_pre): Return a bool, capturing whether the
11199 call has unknown side effects.
11200 (region_model::on_call_post): Add arg "bool unknown_side_effects"
11201 and if true, call handle_unrecognized_call.
11202 (class reachable_regions): New class.
11203 (region_model::handle_unrecognized_call): New function.
11204 * region-model.h (region_model::on_call_pre): Return a bool.
11205 (region_model::on_call_post): Add arg "bool unknown_side_effects".
11206 (region_model::handle_unrecognized_call): New decl.
11207 (region_model_context::on_unknown_change): New vfunc.
11208 (test_region_model_context::on_unknown_change): New function.
11210 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11212 * diagnostic-manager.cc (saved_diagnostic::operator==): Move here
11213 from header. Replace pointer equality test on m_var with call to
11214 pending_diagnostic::same_tree_p.
11215 * diagnostic-manager.h (saved_diagnostic::operator==): Move to
11216 diagnostic-manager.cc.
11217 * pending-diagnostic.cc (pending_diagnostic::same_tree_p): New.
11218 * pending-diagnostic.h (pending_diagnostic::same_tree_p): New.
11219 * sm-file.cc (file_diagnostic::subclass_equal_p): Replace pointer
11220 equality on m_arg with call to pending_diagnostic::same_tree_p.
11221 * sm-malloc.cc (malloc_diagnostic::subclass_equal_p): Likewise.
11222 (possible_null_arg::subclass_equal_p): Likewise.
11223 (null_arg::subclass_equal_p): Likewise.
11224 (free_of_non_heap::subclass_equal_p): Likewise.
11225 * sm-pattern-test.cc (pattern_match::operator==): Likewise.
11226 * sm-sensitive.cc (exposure_through_output_file::operator==):
11228 * sm-taint.cc (tainted_array_index::operator==): Likewise.
11230 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11232 * diagnostic-manager.cc (dedupe_winners::add): Add logging
11233 of deduplication decisions made.
11235 2020-01-14 David Malcolm <dmalcolm@redhat.com>
11237 * ChangeLog: New file.
11238 * analyzer-selftests.cc: New file.
11239 * analyzer-selftests.h: New file.
11240 * analyzer.opt: New file.
11241 * analysis-plan.cc: New file.
11242 * analysis-plan.h: New file.
11243 * analyzer-logging.cc: New file.
11244 * analyzer-logging.h: New file.
11245 * analyzer-pass.cc: New file.
11246 * analyzer.cc: New file.
11247 * analyzer.h: New file.
11248 * call-string.cc: New file.
11249 * call-string.h: New file.
11250 * checker-path.cc: New file.
11251 * checker-path.h: New file.
11252 * constraint-manager.cc: New file.
11253 * constraint-manager.h: New file.
11254 * diagnostic-manager.cc: New file.
11255 * diagnostic-manager.h: New file.
11256 * engine.cc: New file.
11257 * engine.h: New file.
11258 * exploded-graph.h: New file.
11259 * pending-diagnostic.cc: New file.
11260 * pending-diagnostic.h: New file.
11261 * program-point.cc: New file.
11262 * program-point.h: New file.
11263 * program-state.cc: New file.
11264 * program-state.h: New file.
11265 * region-model.cc: New file.
11266 * region-model.h: New file.
11267 * sm-file.cc: New file.
11268 * sm-malloc.cc: New file.
11269 * sm-malloc.dot: New file.
11270 * sm-pattern-test.cc: New file.
11271 * sm-sensitive.cc: New file.
11272 * sm-signal.cc: New file.
11273 * sm-taint.cc: New file.
11276 * state-purge.cc: New file.
11277 * state-purge.h: New file.
11278 * supergraph.cc: New file.
11279 * supergraph.h: New file.
11281 2019-12-13 David Malcolm <dmalcolm@redhat.com>
11286 Copyright (C) 2019-2023 Free Software Foundation, Inc.
11288 Copying and distribution of this file, with or without modification,
11289 are permitted in any medium without royalty provided the copyright
11290 notice and this notice are preserved.