Debian Codegraph @

gcc/analyzer/ChangeLog

raw
1 2026-06-12 Release Manager
2
3 * GCC 15.3.0 released.
4
5 2026-01-14 David Malcolm <[email protected]>
6
7 Backported from master:
8 2025-12-15 David Malcolm <[email protected]>
9
10 PR analyzer/123085
11 * region-model.cc (region_model::scan_for_null_terminator_1): Use
12 byte offset when accessing string constant.
13
14 2026-01-14 David Malcolm <[email protected]>
15
16 Backported from master:
17 2025-12-15 David Malcolm <[email protected]>
18
19 PR analyzer/122975
20 * region-model-manager.cc (region_model_manager::maybe_fold_binop): Fold
21 X + (-X) to zero.
22
23 2025-08-08 Release Manager
24
25 * GCC 15.2.0 released.
26
27 2025-04-25 Release Manager
28
29 * GCC 15.1.0 released.
30
31 2025-03-14 Jakub Jelinek <[email protected]>
32
33 PR analyzer/119278
34 * svalue.cc (cmp_csts_same_type): For STRING_CST, compare
35 TREE_STRING_LENGTH first just in case and use memcmp rather
36 than strcmp. Handle RAW_DATA_CST.
37
38 2025-03-13 David Malcolm <[email protected]>
39
40 PR analyzer/117262
41 * region-model-manager.cc
42 (region_model_manager::get_or_create_constant_svalue): Use
43 NULL_TREE for the types of constant_svalue for RAW_DATA_CST.
44 (region_model_manager::maybe_fold_sub_svalue): Generalize
45 STRING_CST logic to also handle RAW_DATA_CST.
46 (region_model_manager::maybe_get_char_from_cst): New.
47 (region_model_manager::maybe_get_char_from_raw_data_cst): New.
48 * region-model-manager.h
49 (region_model_manager::maybe_get_char_from_cst): New decl.
50 (region_model_manager::maybe_get_char_from_raw_data_cst): New decl.
51 * region-model.cc (region_model::get_rvalue_1): Handle
52 RAW_DATA_CST.
53 * store.cc (get_subregion_within_ctor_for_ctor_pair): New.
54 (binding_map::apply_ctor_pair_to_child_region): Call
55 get_subregion_within_ctor_for_ctor_pair so that we handle
56 RAW_DATA_CST.
57
58 2025-02-24 Jakub Jelinek <[email protected]>
59
60 PR c/117023
61 * sm-malloc.cc (malloc_state_machine::handle_nonnull): New private
62 method.
63 (malloc_state_machine::on_stmt): Use it for nonnull attribute arguments.
64 Handle also nonnull_if_nonzero attributes.
65
66 2025-02-19 David Malcolm <[email protected]>
67
68 PR analyzer/118300
69 * kf.cc (class kf_ubsan_bounds): Replace this with...
70 (class kf_ubsan_noop): ...this.
71 (register_sanitizer_builtins): Use it to handle IFN_UBSAN_NULL,
72 IFN_UBSAN_BOUNDS, and IFN_UBSAN_PTR as nop-ops.
73 (register_known_functions): Drop handling of IFN_UBSAN_BOUNDS
74 here, as it's now handled by register_sanitizer_builtins above.
75
76 2025-02-18 David Malcolm <[email protected]>
77
78 * diagnostic-manager.cc
79 (saved_diagnostic::maybe_add_sarif_properties): Add various
80 properties for debugging, for m_stmt, m_var, and m_duplicates.
81 Remove stray 'if' statement. Capture the kind of the
82 pending_diagnostic.
83 * region-model.cc
84 (poisoned_value_diagnostic::maybe_add_sarif_properties): New.
85
86 2024-12-06 David Malcolm <[email protected]>
87
88 * region-model.cc: Include "gcc-urlifier.h".
89 (reason_attr_access::emit): Use auto_urlify_attributes.
90 * sm-taint.cc: Include "gcc-urlifier.h".
91 (tainted_access_attrib_size::emit): Use auto_urlify_attributes.
92
93 2024-11-28 David Malcolm <[email protected]>
94
95 * engine.cc (strongly_connected_components::to_json): Avoid naked
96 "new".
97 * infinite-loop.cc (infinite_loop::to_json): Convert return type
98 to unique_ptr. Avoid naked "new".
99 * sm-signal.cc (signal_delivery_edge_info_t::to_json): Delete
100 unused function.
101 * supergraph.cc (supernode::to_json): Avoid naked "new".
102
103 2024-11-28 David Malcolm <[email protected]>
104
105 PR c/104896
106 * sm-malloc.cc: Replace "%<%s%>" with "%qs" in message wording.
107
108 2024-11-23 Lewis Hyatt <[email protected]>
109
110 * checker-event.cc (checker_event::dump): Support printing either
111 32- or 64-bit location_t values.
112 * checker-path.cc (checker_path::inject_any_inlined_call_events):
113 Likewise.
114
115 2024-11-22 Andrew Pinski <[email protected]>
116
117 PR bootstrap/117737
118 * access-diagram.cc (INCLUDE_MEMORY): Remove.
119 * analysis-plan.cc (INCLUDE_MEMORY): Remove.
120 * analyzer-language.cc (INCLUDE_MEMORY): Remove.
121 * analyzer-logging.cc (INCLUDE_MEMORY): Remove.
122 * analyzer-pass.cc (INCLUDE_MEMORY): Remove.
123 * analyzer-selftests.cc (INCLUDE_MEMORY): Remove.
124 * analyzer.cc (INCLUDE_MEMORY): Remove.
125 * bar-chart.cc (INCLUDE_MEMORY): Remove.
126 * bounds-checking.cc (INCLUDE_MEMORY): Remove.
127 * call-details.cc (INCLUDE_MEMORY): Remove.
128 * call-info.cc (INCLUDE_MEMORY): Remove.
129 * call-string.cc (INCLUDE_MEMORY): Remove.
130 * call-summary.cc (INCLUDE_MEMORY): Remove.
131 * checker-event.cc (INCLUDE_MEMORY): Remove.
132 * checker-path.cc (INCLUDE_MEMORY): Remove.
133 * complexity.cc (INCLUDE_MEMORY): Remove.
134 * constraint-manager.cc (INCLUDE_MEMORY): Remove.
135 * diagnostic-manager.cc (INCLUDE_MEMORY): Remove.
136 * engine.cc (INCLUDE_MEMORY): Remove.
137 * feasible-graph.cc (INCLUDE_MEMORY): Remove.
138 * infinite-loop.cc (INCLUDE_MEMORY): Remove.
139 * infinite-recursion.cc (INCLUDE_MEMORY): Remove.
140 * kf-analyzer.cc (INCLUDE_MEMORY): Remove.
141 * kf-lang-cp.cc (INCLUDE_MEMORY): Remove.
142 * kf.cc (INCLUDE_MEMORY): Remove.
143 * known-function-manager.cc (INCLUDE_MEMORY): Remove.
144 * pending-diagnostic.cc (INCLUDE_MEMORY): Remove.
145 * program-point.cc (INCLUDE_MEMORY): Remove.
146 * program-state.cc (INCLUDE_MEMORY): Remove.
147 * ranges.cc (INCLUDE_MEMORY): Remove.
148 * record-layout.cc (INCLUDE_MEMORY): Remove.
149 * region-model-asm.cc (INCLUDE_MEMORY): Remove.
150 * region-model-manager.cc (INCLUDE_MEMORY): Remove.
151 * region-model-reachability.cc (INCLUDE_MEMORY): Remove.
152 * region-model.cc (INCLUDE_MEMORY): Remove.
153 * region.cc (INCLUDE_MEMORY): Remove.
154 * sm-fd.cc (INCLUDE_MEMORY): Remove.
155 * sm-file.cc (INCLUDE_MEMORY): Remove.
156 * sm-malloc.cc (INCLUDE_MEMORY): Remove.
157 * sm-pattern-test.cc (INCLUDE_MEMORY): Remove.
158 * sm-sensitive.cc (INCLUDE_MEMORY): Remove.
159 * sm-signal.cc (INCLUDE_MEMORY): Remove.
160 * sm-taint.cc (INCLUDE_MEMORY): Remove.
161 * sm.cc (INCLUDE_MEMORY): Remove.
162 * state-purge.cc (INCLUDE_MEMORY): Remove.
163 * store.cc (INCLUDE_MEMORY): Remove.
164 * supergraph.cc (INCLUDE_MEMORY): Remove.
165 * svalue.cc (INCLUDE_MEMORY): Remove.
166 * symbol.cc (INCLUDE_MEMORY): Remove.
167 * trimmed-graph.cc (INCLUDE_MEMORY): Remove.
168 * varargs.cc (INCLUDE_MEMORY): Remove.
169
170 2024-11-13 David Malcolm <[email protected]>
171
172 * checker-path.cc (checker_path::debug): Explicitly use
173 global_dc's reference printer.
174 * diagnostic-manager.cc
175 (diagnostic_manager::prune_interproc_events): Likewise.
176 (diagnostic_manager::prune_system_headers): Likewise.
177
178 2024-11-02 David Malcolm <[email protected]>
179
180 * analyzer.cc: Include "make-unique.h". Convert "to_json"
181 functions to use std::unique_ptr.
182 * call-string.cc: Likewise.
183 * constraint-manager.cc: Likewise.
184 * diagnostic-manager.cc: Likewise.
185 * engine.cc: Likewise.
186 * program-point.cc: Likewise.
187 * program-state.cc: Likewise.
188 * ranges.cc: Likewise.
189 * region-model.cc: Likewise.
190 * region.cc: Likewise.
191 * svalue.cc: Likewise.
192 * sm.cc: Likewise.
193 * store.cc: Likewise.
194 * supergraph.cc: Likewise.
195 * analyzer.h: Convert "to_json" functions to return
196 std::unique_ptr.
197 * call-string.h: Likewise.
198 * constraint-manager.h: Likewise.
199 (bounded_range::set_json_attr): Pass "obj" by reference.
200 * diagnostic-manager.h: Convert "to_json" functions to return
201 std::unique_ptr.
202 * exploded-graph.h: Likewise.
203 * program-point.h: Likewise.
204 * program-state.h: Likewise.
205 * ranges.h: Likewise.
206 * region-model.h: Likewise.
207 * region.h: Likewise.
208 * sm.h: Likewise.
209 * store.h: Likewise.
210 * supergraph.h: Likewise.
211 * svalue.h: Likewise.
212
213 2024-11-01 David Malcolm <[email protected]>
214
215 PR analyzer/117373
216 * infinite-loop.cc
217 (infinite_loop_diagnostic::describe_final_event): Fix
218 -Wunused-parameter warning
219
220 2024-10-29 David Malcolm <[email protected]>
221
222 PR other/116613
223 * analyzer-language.cc (on_finish_translation_unit): Update for
224 m_printer becoming reference printer.
225 * engine.cc (run_checkers): Likewise.
226 * program-point.cc (function_point::print_source_line): Likewise.
227
228 2024-10-25 Jakub Jelinek <[email protected]>
229
230 * state-purge.cc: Remove trailing whitespace.
231 * region-model.h: Likewise.
232 * region-model.cc: Likewise.
233 * program-point.cc: Likewise.
234 * exploded-graph.h: Likewise.
235 * program-state.cc: Likewise.
236 * supergraph.cc: Likewise.
237
238 2024-10-24 David Malcolm <[email protected]>
239
240 PR other/116613
241 * bounds-checking.cc
242 (concrete_buffer_overflow::describe_final_event): Convert return
243 type from label_text to bool. Add "pp" param and either print to
244 it and return true, or return false.
245 (concrete_buffer_overflow::describe_final_event_as_bytes): Convert
246 to print to a pp rather than returning a label_text.
247 (concrete_buffer_overflow::describe_final_event_as_bits):
248 Likewise.
249 (class concrete_buffer_over_read): Analogous changes to above.
250 (class concrete_buffer_underwrite): Likewise.
251 (class concrete_buffer_under_read): Likewise.
252 (class symbolic_buffer_overflow): Likewise.
253 (class symbolic_buffer_over_read): Likewise.
254 * call-details.cc (class overlapping_buffers): Likewise.
255 * call-info.cc (call_info::print): Reimplement.
256 (class call_info::add_events_to_path::call_event): Convert
257 "get_desc" vfunc to "print_desc", dropping return type, adding
258 "pp" param, and printing to it.
259 (class succeed_or_fail_call_info): Likewise.
260 * call-info.h (class call_info): Likewise.
261 (class succeed_or_fail_call_info): Likewise.
262 * checker-event.cc (checker_event::dump): Reimplement.
263 (checker_event::prepare_for_emission): Update for change from
264 get_desc to print_desc.
265 (debug_event::get_desc): Convert to...
266 (debug_event::print_desc): ...this.
267 (precanned_custom_event::get_desc): Convert to...
268 (precanned_custom_event::print_desc): ...this.
269 (statement_event::get_desc): Convert to...
270 (statement_event::print_desc): ...this.
271 (region_creation_event_memory_space::get_desc): Convert to...
272 (region_creation_event_memory_space::print_desc): ...this.
273 (region_creation_event_capacity::get_desc): Convert to...
274 (region_creation_event_capacity::print_desc): ...this.
275 (region_creation_event_allocation_size::get_desc): Convert to...
276 (region_creation_event_allocation_size::print_desc): ...this.
277 (region_creation_event_debug::get_desc): Convert to...
278 (region_creation_event_debug::print_desc): ...this.
279 (function_entry_event::get_desc): Convert to...
280 (function_entry_event::print_desc): ...this.
281 (state_change_event::get_desc): Convert to...
282 (state_change_event::print_desc): ...this.
283 (state_change_event::get_meaning): Update for change to
284 pending_diagnostic::get_meaning_for_state_change.
285 (superedge_event::should_filter_p): Convert from usage of get_desc
286 to print_desc.
287 (start_cfg_edge_event::get_desc): Convert to...
288 (start_cfg_edge_event::print_desc): ...this.
289 (call_event::get_desc): Convert to...
290 (call_event::print_desc): ...this.
291 (return_event::get_desc): Convert to...
292 (return_event::print_desc): ...this.
293 (start_consolidated_cfg_edges_event::get_desc): Convert to...
294 (start_consolidated_cfg_edges_event::print_desc): ...this.
295 (inlined_call_event::get_desc): Convert to...
296 (inlined_call_event::print_desc): ...this.
297 (setjmp_event::get_desc): Convert to...
298 (setjmp_event::print_desc): ...this.
299 (rewind_from_longjmp_event::get_desc): Convert to...
300 (rewind_from_longjmp_event::print_desc): ...this.
301 (rewind_to_setjmp_event::get_desc): Convert to...
302 (rewind_to_setjmp_event::print_desc): ...this.
303 (warning_event::get_desc): Convert to...
304 (warning_event::print_desc): ...this.
305 * checker-event.h: Convert the various "get_desc" vfunc decls to
306 "print_desc".
307 * checker-path.cc (checker_path::dump): Convert to usage of
308 checker_event::print_desc.
309 (checker_path::debug): Convert to debug form of
310 checker_event::get_desc.
311 * diagnostic-manager.cc
312 (diagnostic_manager::prune_interproc_events): Likewise.
313 (diagnostic_manager::prune_system_headers): Likewise.
314 * engine.cc (call_summary_edge_info::get_desc): Convert to...
315 (call_summary_edge_info::print_desc): ...this.
316 (stale_jmp_buf::describe_final_event): Update for change to
317 this vfunc.
318 (tainted_args_function_custom_event::get_desc): Convert to...
319 (tainted_args_function_custom_event::print_desc): ...this.
320 (tainted_args_field_custom_event::get_desc): Convert to...
321 (tainted_args_field_custom_event::print_desc): ...this.
322 (tainted_args_callback_custom_event::get_desc): Convert to...
323 (tainted_args_callback_custom_event::print_desc): ...this.
324 (jump_through_null::describe_final_event): Update for change to
325 this vfunc.
326 * infinite-loop.cc (perpetual_start_cfg_edge_event::get_desc):
327 Convert to...
328 (perpetual_start_cfg_edge_event::print_desc): ...this.
329 (looping_back_event::get_desc): Convert to...
330 (looping_back_event::print_desc): ...this.
331 (looping_back_event::describe_final_event): Update for change to
332 this vfunc.
333 * infinite-recursion.cc (class infinite_recursion_diagnostic):
334 Update for changes to pending_diagnostic.
335 * kf.cc (class putenv_of_auto_var): Likewise.
336 (kf_realloc::impl_call_post): Update for changes to call_info.
337 (kf_strchr::impl_call_post): Likewise.
338 (kf_strncpy::impl_call_post): Likewise.
339 (kf_strstr::impl_call_post): Likewise.
340 (class kf_strtok::undefined_behavior): Update for changes to
341 pending_diagnostic.
342 (class strtok_call_info): Update for changes to call_info.
343 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
344 Delete.
345 * pending-diagnostic.h (struct event_desc): Delete.
346 (struct state_change): Drop event_desc base class.
347 (struct call_with_state): Likewise.
348 (struct return_of_state): Likewise.
349 (struct final_event): Likewise.
350 (pending_event::describe_state_change): Convert return
351 type from label_text to bool. Add "pp" param and either print to
352 it and return true, or return false. Do the latter for the base
353 class implementation.
354 (pending_event::describe_call_with_state): Likewise.
355 (pending_event::describe_return_of_state): Likewise.
356 (pending_event::describe_final_event): Likewise.
357 * region-model.cc
358 (poisoned_value_diagnostic::describe_final_event): Update for
359 change to this vfunc.
360 (shift_count_negative_diagnostic::describe_final_event): Likewise.
361 (shift_count_overflow_diagnostic::describe_final_event): Likewise.
362 (ptrdiff_region_creation_event::get_desc): Convert to...
363 (ptrdiff_region_creation_event::print_desc): ...this.
364 (undefined_ptrdiff_diagnostic::describe_final_event): Update for
365 change to this vfunc.
366 (write_to_const_diagnostic::describe_final_event): Likewise.
367 (write_to_string_literal_diagnostic::describe_final_event):
368 Likewise.
369 (dubious_allocation_size::describe_final_event): Likewise.
370 (null_terminator_check_event::get_desc): Convert to...
371 (null_terminator_check_event::print_desc): ...this.
372 (float_as_size_arg::describe_final_event): Update for change to
373 this vfunc.
374 (exposure_through_uninit_copy::describe_final_event): Likewise.
375 * sm-fd.cc: Include "diagnostic-core.h". Update throughout for
376 changes to pending_diagnostic vfuncs.
377 * sm-file.cc: Likewise.
378 * sm-malloc.cc: Likewise.
379 * sm-sensitive.cc: Likewise.
380 * sm-signal.cc: Likewise.
381 * sm-taint.cc: Likewise.
382 * varargs.cc: Likewise.
383
384 2024-10-24 David Malcolm <[email protected]>
385 Gaius Mulley <[email protected]>
386
387 PR other/116613
388 * analyzer-logging.cc: Add #define INCLUDE_MEMORY
389 (logger::logger): Update for m_pp becoming a unique_ptr.
390 (logger::~logger): Likewise.
391 (logger::log_va_partial): Likewise.
392 (logger::end_log_line): Likewise.
393 * analyzer-logging.h (logger::get_printer): Likewise.
394 (logger::m_pp): Convert to a unique_ptr.
395 * analyzer.cc (make_label_text): Use
396 diagnostic_context::clone_printer and use unique_ptr.
397 (make_label_text_n): Likewise.
398 * bar-chart.cc: Add #define INCLUDE_MEMORY
399 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
400 Use diagnostic_context::clone_printer and use unique_ptr.
401 * sm-malloc.cc (sufficiently_similar_p): Likewise.
402 * supergraph.cc (supergraph::dump_dot_to_file): Likewise.
403
404 2024-09-30 David Malcolm <[email protected]>
405
406 PR other/116613
407 * program-point.cc (function_point::print_source_line): Replace
408 call to diagnostic_show_locus with a call to
409 diagnostic_source_print_policy::print.
410
411 2024-09-30 David Malcolm <[email protected]>
412
413 PR other/116613
414 * kf-analyzer.cc: Include "pretty-print-markup.h".
415 (kf_analyzer_dump_escaped::impl_call_pre): Defer colorization
416 choices by eliminating the construction of a intermediate string,
417 replacing it with a new pp_element subclass via "%e".
418
419 2024-09-20 David Malcolm <[email protected]>
420
421 PR other/116613
422 * access-diagram.cc (access_range::dump): Simplify using
423 tree_dump_pretty_printer.
424 * call-details.cc (call_details::dump): Likewise.
425 * call-summary.cc (call_summary::dump): Likewise.
426 (call_summary_replay::dump): Likewise.
427 * checker-event.cc (checker_event::debug): Likewise.
428 * constraint-manager.cc (range::dump): Likewise.
429 (bounded_range::dump): Likewise.
430 (bounded_ranges::dump): Likewise.
431 (constraint_manager::dump): Likewise.
432 * engine.cc (exploded_node::dump): Likewise.
433 (exploded_path::dump): Likewise.
434 * program-point.cc (program_point::dump): Likewise.
435 * program-state.cc (extrinsic_state::dump_to_file): Likewise.
436 (sm_state_map::dump): Likewise.
437 (program_state::dump_to_file): Likewise.
438 * ranges.cc (symbolic_byte_offset::dump): Likewise.
439 (symbolic_byte_range::dump): Likewise.
440 * record-layout.cc (record_layout::dump): Likewise.
441 * region-model-reachability.cc (reachable_regions::dump):
442 Likewise.
443 * region-model.cc (region_to_value_map::dump): Likewise.
444 (region_model::dump): Likewise.
445 (model_merger::dump): Likewise.
446 * region.cc (region_offset::dump): Likewise.
447 (region::dump): Likewise.
448 * sm-malloc.cc (deallocator_set::dump): Likewise.
449 * store.cc (uncertainty_t::dump): Likewise.
450 (binding_key::dump): Likewise.
451 (bit_range::dump): Likewise.
452 (byte_range::dump): Likewise.
453 (binding_map::dump): Likewise.
454 (binding_cluster::dump): Likewise.
455 (store::dump): Likewise.
456 * supergraph.cc (superedge::dump): Likewise.
457 * svalue.cc (svalue::dump): Likewise.
458
459 2024-09-20 David Malcolm <[email protected]>
460
461 PR other/116613
462 * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostic):
463 Remove remove redundant 'pp'.
464
465 2024-09-09 David Malcolm <[email protected]>
466
467 PR other/116613
468 * access-diagram.cc (access_range::dump): Rename
469 diagnostic_context's "printer" field to "m_printer".
470 * analyzer-language.cc (on_finish_translation_unit): Likewise.
471 * analyzer.cc (make_label_text): Likewise.
472 (make_label_text_n): Likewise.
473 * call-details.cc (call_details::dump): Likewise.
474 * call-summary.cc (call_summary::dump): Likewise.
475 (call_summary_replay::dump): Likewise.
476 * checker-event.cc (checker_event::debug): Likewise.
477 * constraint-manager.cc (range::dump): Likewise.
478 (bounded_range::dump): Likewise.
479 (bounded_ranges::dump): Likewise.
480 (constraint_manager::dump): Likewise.
481 * diagnostic-manager.cc
482 (diagnostic_manager::emit_saved_diagnostic): Likewise.
483 * engine.cc (exploded_node::dump): Likewise.
484 (exploded_path::dump): Likewise.
485 (run_checkers): Likewise.
486 * kf-analyzer.cc (kf_analyzer_dump_escaped::impl_call_pre):
487 Likewise.
488 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
489 Likewise.
490 * program-point.cc (function_point::print_source_line): Likewise.
491 (program_point::dump): Likewise.
492 * program-state.cc (extrinsic_state::dump_to_file): Likewise.
493 (sm_state_map::dump): Likewise.
494 (program_state::dump_to_file): Likewise.
495 * ranges.cc (symbolic_byte_offset::dump): Likewise.
496 (symbolic_byte_range::dump): Likewise.
497 * region-model-reachability.cc (reachable_regions::dump): Likewise.
498 * region-model.cc (region_to_value_map::dump): Likewise.
499 (region_model::dump): Likewise.
500 (model_merger::dump): Likewise.
501 * region.cc (region_offset::dump): Likewise.
502 (region::dump): Likewise.
503 * sm-malloc.cc (deallocator_set::dump): Likewise.
504 (sufficiently_similar_p): Likewise.
505 * store.cc (uncertainty_t::dump): Likewise.
506 (binding_key::dump): Likewise.
507 (binding_map::dump): Likewise.
508 (binding_cluster::dump): Likewise.
509 (store::dump): Likewise.
510 * supergraph.cc (supergraph::dump_dot_to_file): Likewise.
511 (superedge::dump): Likewise.
512 * svalue.cc (svalue::dump): Likewise.
513
514 2024-09-09 David Malcolm <[email protected]>
515
516 * call-summary.cc
517 (call_summary_replay::convert_region_from_summary_1): Drop unused
518 local "summary_cast_reg"
519
520 2024-09-03 David Malcolm <[email protected]>
521
522 * analyzer-logging.cc (logger::logger): Prefix all output_buffer
523 fields with "m_".
524
525 2024-07-24 David Malcolm <[email protected]>
526
527 * checker-event.cc (maybe_add_sarif_properties): Update setting
528 of "original_fndecl" to use typesafe unique_ptr variant of
529 json::object::set.
530
531 2024-07-24 David Malcolm <[email protected]>
532
533 * call-string.cc (call_string::to_json): Avoid naked "new".
534 * constraint-manager.cc (bounded_range::set_json_attr): Likewise.
535 (equiv_class::to_json): Likewise.
536 (constraint::to_json): Likewise.
537 (bounded_ranges_constraint::to_json): Likewise.
538 * diagnostic-manager.cc (saved_diagnostic::to_json): Likewise.
539 (saved_diagnostic::maybe_add_sarif_properties): Likewise.
540 * engine.cc (exploded_node::to_json): Likewise.
541 (exploded_edge::to_json): Likewise.
542 * program-point.cc (program_point::to_json): Likewise.
543 * program-state.cc (program_state::to_json): Likewise.
544 * sm.cc (state_machine::to_json): Likewise.
545 * store.cc (binding_cluster::to_json): Likewise.
546 (store::to_json): Likewise.
547 * supergraph.cc (supernode::to_json): Likewise.
548 (superedge::to_json): Likewise.
549
550 2024-07-24 David Malcolm <[email protected]>
551
552 * supergraph.cc (supernode::to_json): Avoid naked "new" by using
553 json::array::append_string.
554 (supernode::to_json): Likewise.
555
556 2024-07-12 Daniel Bertalan <[email protected]>
557
558 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
559 Change NULL to nullptr.
560 (struct null_assignment_sm_context): Likewise.
561 * infinite-loop.cc: Likewise.
562 * infinite-recursion.cc: Likewise.
563 * varargs.cc (va_list_state_machine::on_leak): Likewise.
564
565 2024-07-04 David Malcolm <[email protected]>
566
567 * diagnostic-manager.cc
568 (diagnostic_manager::add_events_for_eedge): Pass sm_ctxt by
569 reference.
570 * engine.cc (impl_region_model_context::on_condition): Likewise.
571 (impl_region_model_context::on_bounded_ranges): Likewise.
572 (impl_region_model_context::on_phi): Likewise.
573 (exploded_node::on_stmt): Likewise.
574 * sm-fd.cc: Update all uses of sm_context * to sm_context &.
575 * sm-file.cc: Likewise.
576 * sm-malloc.cc: Likewise.
577 * sm-pattern-test.cc: Likewise.
578 * sm-sensitive.cc: Likewise.
579 * sm-signal.cc: Likewise.
580 * sm-taint.cc: Likewise.
581 * sm.h: Likewise.
582 * varargs.cc: Likewise.
583
584 2024-07-04 David Malcolm <[email protected]>
585
586 PR analyzer/115724
587 * kf.cc (register_known_functions): Add __error_alias and
588 __error_at_line_alias.
589
590 2024-06-18 David Malcolm <[email protected]>
591
592 * checker-event.h (checker_event::fndecl): Drop "final" and
593 "override", converting from a vfunc implementation to a plain
594 accessor.
595 * checker-path.cc (checker_path::same_function_p): New.
596 * checker-path.h (checker_path::same_function_p): New decl.
597
598 2024-06-18 David Malcolm <[email protected]>
599
600 * checker-path.h: Include "simple-diagnostic-path.h".
601
602 2024-06-18 Jonathan Wakely <[email protected]>
603
604 * constraint-manager.cc (equiv_class::make_dump_widget): Change
605 return type to match return value and do not use std::move on
606 return value.
607 (bounded_ranges_constraint::make_dump_widget): Likewise.
608 (constraint_manager::make_dump_widget): Likewise.
609 * constraint-manager.h (equiv_class::make_dump_widget): Change
610 return type.
611 (bounded_ranges_constraint::make_dump_widget): Likewise.
612 (constraint_manager::make_dump_widget): Likewise.
613 * program-state.cc (sm_state_map::make_dump_widget): Likewise.
614 (program_state::make_dump_widget): Likewise.
615 * program-state.h (sm_state_map::make_dump_widget): Likewise.
616 (program_state::make_dump_widget): Likewise.
617 * region-model.cc (region_to_value_map::make_dump_widget): Likewise.
618 (region_model::make_dump_widget): Likewise.
619 * region-model.h (region_to_value_map::make_dump_widget): Likewise.
620 (region_model::make_dump_widget): Likewise.
621 * region.cc (region::make_dump_widget): Likewise.
622 * region.h (region::make_dump_widget): Likewise.
623 * store.cc (binding_cluster::make_dump_widget): Likewise.
624 (store::make_dump_widget): Likewise.
625 * store.h (binding_cluster::make_dump_widget): Likewise.
626 (store::make_dump_widget): Likewise.
627 * svalue.cc (svalue::make_dump_widget): Likewise.
628 * svalue.h (svalue::make_dump_widget): Likewise.
629
630 2024-06-12 David Malcolm <[email protected]>
631
632 * access-diagram.cc (access_range::dump): Update for fields of
633 pretty_printer becoming private.
634 * call-details.cc (call_details::dump): Likewise.
635 * call-summary.cc (call_summary::dump): Likewise.
636 (call_summary_replay::dump): Likewise.
637 * checker-event.cc (checker_event::debug): Likewise.
638 * constraint-manager.cc (range::dump): Likewise.
639 (bounded_range::dump): Likewise.
640 (constraint_manager::dump): Likewise.
641 * engine.cc (exploded_node::dump): Likewise.
642 (exploded_path::dump): Likewise.
643 (exploded_path::dump_to_file): Likewise.
644 * feasible-graph.cc (feasible_graph::dump_feasible_path): Likewise.
645 * program-point.cc (program_point::dump): Likewise.
646 * program-state.cc (extrinsic_state::dump_to_file): Likewise.
647 (sm_state_map::dump): Likewise.
648 (program_state::dump_to_file): Likewise.
649 * ranges.cc (symbolic_byte_offset::dump): Likewise.
650 (symbolic_byte_range::dump): Likewise.
651 * record-layout.cc (record_layout::dump): Likewise.
652 * region-model-reachability.cc (reachable_regions::dump): Likewise.
653 * region-model.cc (region_to_value_map::dump): Likewise.
654 (region_model::dump): Likewise.
655 (model_merger::dump): Likewise.
656 * region-model.h (one_way_id_map<T>::dump): Likewise.
657 * region.cc (region_offset::dump): Likewise.
658 (region::dump): Likewise.
659 * sm-malloc.cc (deallocator_set::dump): Likewise.
660 * store.cc (uncertainty_t::dump): Likewise.
661 (binding_key::dump): Likewise.
662 (bit_range::dump): Likewise.
663 (byte_range::dump): Likewise.
664 (binding_map::dump): Likewise.
665 (binding_cluster::dump): Likewise.
666 (store::dump): Likewise.
667 * supergraph.cc (supergraph::dump_dot_to_file): Likewise.
668 (superedge::dump): Likewise.
669 * svalue.cc (svalue::dump): Likewise.
670
671 2024-06-08 Roger Sayle <[email protected]>
672
673 * constraint-manager.cc (equiv_class::make_dump_widget): Use
674 std::move to return a std::unique_ptr.
675 (bounded_ranges_constraint::make_dump_widget): Likewise.
676 (constraint_manager::make_dump_widget): Likewise.
677 * program-state.cc (sm_state_map::make_dump_widget): Likewise.
678 (program_state::make_dump_widget): Likewise.
679 * region-model.cc (region_to_value_map::make_dump_widget): Likewise.
680 (region_model::make_dump_widget): Likewise.
681 * region.cc (region::make_dump_widget): Likewise.
682 * store.cc (binding_cluster::make_dump_widget): Likewise.
683 (store::make_dump_widget): Likewise.
684 * svalue.cc (svalue::make_dump_widget): Likewise.
685
686 2024-06-07 David Malcolm <[email protected]>
687
688 * engine.cc (impl_region_model_context::on_state_leak): Pass nullptr
689 to get_representative_path_var.
690 * region-model.cc (region_model::get_representative_path_var_1):
691 Add logger param and use it in both overloads.
692 (region_model::get_representative_path_var): Likewise.
693 (region_model::get_representative_tree): Likewise.
694 (selftest::test_get_representative_path_var): Pass nullptr to
695 get_representative_path_var.
696 * region-model.h (region_model::get_representative_tree): Add
697 optional logger param to both overloads.
698 (region_model::get_representative_path_var): Add logger param to
699 both overloads.
700 (region_model::get_representative_path_var_1): Likewise.
701 * store.cc (binding_cluster::get_representative_path_vars): Add
702 logger param and use it.
703 (store::get_representative_path_vars): Likewise.
704 * store.h (binding_cluster::get_representative_path_vars): Add
705 logger param.
706 (store::get_representative_path_vars): Likewise.
707
708 2024-06-07 David Malcolm <[email protected]>
709
710 * call-summary.cc
711 (call_summary_replay::convert_region_from_summary_1): Update
712 for removal of cast_region::m_original_region.
713 * region-model-manager.cc
714 (region_model_manager::get_or_create_initial_value): Likewise.
715 * region-model.cc (region_model::get_store_value): Likewise.
716 * region.cc (region::get_base_region): Likewise.
717 (region::descendent_of_p): Likewise.
718 (region::maybe_get_frame_region): Likewise.
719 (region::get_memory_space): Likewise.
720 (region::calc_offset): Likewise.
721 (cast_region::accept): Delete.
722 (cast_region::dump_to_pp): Update for removal of
723 cast_region::m_original_region.
724 (cast_region::add_dump_widget_children): Delete.
725 * region.h (struct cast_region::key_t): Rename "original_region"
726 to "parent".
727 (cast_region::cast_region): Likewise. Update for removal of
728 cast_region::m_original_region.
729 (cast_region::accept): Delete.
730 (cast_region::add_dump_widget_children): Delete.
731 (cast_region::get_original_region): Delete.
732 (cast_region::m_original_region): Delete.
733 * sm-taint.cc (region_model::check_region_for_taint): Remove
734 special-casing for RK_CAST.
735
736 2024-06-07 David Malcolm <[email protected]>
737
738 PR analyzer/105892
739 * analyzer.opt (Wanalyzer-undefined-behavior-ptrdiff): New option.
740 * analyzer.opt.urls: Regenerate.
741 * region-model.cc (class undefined_ptrdiff_diagnostic): New.
742 (check_for_invalid_ptrdiff): New.
743 (region_model::get_gassign_result): Call it for POINTER_DIFF_EXPR.
744
745 2024-06-01 David Malcolm <[email protected]>
746
747 PR analyzer/106203
748 * checker-event.h: Include "analyzer/event-loc-info.h".
749 (struct event_loc_info): Move to its own header file.
750 * diagnostic-manager.cc
751 (diagnostic_manager::emit_saved_diagnostic): Move creation of
752 event_loc_info here from add_final_event, and if we have a
753 stmt_finder, call its update_event_loc_info method.
754 * engine.cc (leak_stmt_finder::update_event_loc_info): New.
755 (exploded_node::detect_leaks): Likewise.
756 (exploded_node::detect_leaks): Pass nullptr as call_stmt arg to
757 region_model::pop_frame.
758 * event-loc-info.h: New file, with content taken from
759 checker-event.h.
760 * exploded-graph.h (stmt_finder::update_event_loc_info): New pure
761 virtual function.
762 * infinite-loop.cc (infinite_loop_diagnostic::add_final_event):
763 Update for change to vfunc signature.
764 * infinite-recursion.cc
765 (infinite_recursion_diagnostic::add_final_event): Likewise.
766 * pending-diagnostic.cc (pending_diagnostic::add_final_event):
767 Pass in the event_loc_info from the caller, rather than generating
768 it from a gimple stmt and enode.
769 * pending-diagnostic.h (pending_diagnostic::add_final_event):
770 Likewise.
771 * region-model.cc (region_model::on_longjmp): Pass nullptr as
772 call_stmt arg to region_model::pop_frame.
773 (region_model::update_for_return_gcall): Likewise, but pass
774 call_stmt.
775 (class caller_context): New.
776 (region_model::pop_frame): Add "call_stmt" argument. Use it
777 and the frame_region with a caller_context when setting
778 result_dst_reg's value so that any diagnostic is reported at the
779 call stmt in the caller.
780 (selftest::test_stack_frames): Pass nullptr as call_stmt arg to
781 region_model::pop_frame.
782 (selftest::test_alloca): Likewise.
783 * region-model.h (region_model::pop_frame): Add "call_stmt"
784 argument.
785
786 2024-05-30 David Malcolm <[email protected]>
787
788 * infinite-loop.cc (looping_back_event::get_desc): Fix unused
789 parameter warning introduced by me in r15-636-g770657d02c986c.
790
791 2024-05-30 David Malcolm <[email protected]>
792
793 * call-details.cc: Define INCLUDE_VECTOR.
794 * call-info.cc: Likewise.
795 * call-summary.cc: Likewise.
796 * checker-event.cc: Likewise.
797 * checker-path.cc: Likewise.
798 * complexity.cc: Likewise.
799 * constraint-manager.cc: Likewise.
800 (bounded_range::make_dump_widget): New.
801 (bounded_ranges::add_to_dump_widget): New.
802 (equiv_class::make_dump_widget): New.
803 (constraint::make_dump_widget): New.
804 (bounded_ranges_constraint::make_dump_widget): New.
805 (constraint_manager::make_dump_widget): New.
806 * constraint-manager.h (bounded_range::make_dump_widget): New
807 decl.
808 (bounded_ranges::add_to_dump_widget): New decl.
809 (equiv_class::make_dump_widget): New decl.
810 (constraint::make_dump_widget): New decl.
811 (bounded_ranges_constraint::make_dump_widget): New decl.
812 (constraint_manager::make_dump_widget): New decl.
813 * diagnostic-manager.cc: Define INCLUDE_VECTOR.
814 * engine.cc: Likewise. Include "text-art/dump.h".
815 (setjmp_svalue::print_dump_widget_label): New.
816 (setjmp_svalue::add_dump_widget_children): New.
817 (exploded_graph::dump_exploded_nodes): Use text_art::dump_to_file
818 for -fdump-analyzer-exploded-nodes-2 and
819 -fdump-analyzer-exploded-nodes-3. Fix overlong line.
820 * feasible-graph.cc: Define INCLUDE_VECTOR.
821 * infinite-recursion.cc: Likewise.
822 * kf-analyzer.cc: Likewise.
823 * kf-lang-cp.cc: Likewise.
824 * kf.cc: Likewise.
825 * known-function-manager.cc: Likewise.
826 * pending-diagnostic.cc: Likewise.
827 * program-point.cc: Likewise.
828 * program-state.cc: Likewise. Include "text-art/tree-widget" and
829 "text-art/dump.h".
830 (sm_state_map::make_dump_widget): New.
831 (program_state::dump): New.
832 (program_state::make_dump_widget): New.
833 * program-state.h: Include "text-art/widget.h".
834 (sm_state_map::make_dump_widget): New decl.
835 (program_state::dump): New decl.
836 (program_state::make_dump_widget): New decl.
837 * ranges.cc: Define INCLUDE_VECTOR.
838 * record-layout.cc: Likewise.
839 * region-model-asm.cc: Likewise.
840 * region-model-manager.cc: Likewise.
841 * region-model-reachability.cc: Likewise.
842 * region-model.cc: Likewise. Include "text-art/tree-widget.h".
843 (region_to_value_map::make_dump_widget): New.
844 (region_model::dump): New.
845 (region_model::make_dump_widget): New.
846 (selftest::test_dump): Add test of dump_to_pp<region_model>.
847 * region-model.h: Include "text-art/widget.h" and
848 "text-art/dump.h".
849 (region_to_value_map::make_dump_widget): New decl.
850 (region_model::dump): New decl.
851 (region_model::make_dump_widget): New decl.
852 * region.cc: Define INCLUDE_VECTOR and include "text-art/dump.h".
853 (region::dump): New.
854 (region::make_dump_widget): New.
855 (region::add_dump_widget_children): New.
856 (frame_region::print_dump_widget_label): New.
857 (globals_region::print_dump_widget_label): New.
858 (code_region::print_dump_widget_label): New.
859 (function_region::print_dump_widget_label): New.
860 (label_region::print_dump_widget_label): New.
861 (stack_region::print_dump_widget_label): New.
862 (heap_region::print_dump_widget_label): New.
863 (root_region::print_dump_widget_label): New.
864 (thread_local_region::print_dump_widget_label): New.
865 (symbolic_region::print_dump_widget_label): New.
866 (symbolic_region::add_dump_widget_children): New.
867 (decl_region::print_dump_widget_label): New.
868 (field_region::print_dump_widget_label): New.
869 (element_region::print_dump_widget_label): New.
870 (element_region::add_dump_widget_children): New.
871 (offset_region::print_dump_widget_label): New.
872 (offset_region::add_dump_widget_children): New.
873 (sized_region::print_dump_widget_label): New.
874 (sized_region::add_dump_widget_children): New.
875 (cast_region::print_dump_widget_label): New.
876 (cast_region::add_dump_widget_children): New.
877 (heap_allocated_region::print_dump_widget_label): New.
878 (alloca_region::print_dump_widget_label): New.
879 (string_region::print_dump_widget_label): New.
880 (bit_range_region::print_dump_widget_label): New.
881 (var_arg_region::print_dump_widget_label): New.
882 (errno_region::print_dump_widget_label): New.
883 (private_region::print_dump_widget_label): New.
884 (unknown_region::print_dump_widget_label): New.
885 * region.h: Include "text-art/widget.h".
886 (region::dump): New decl.
887 (region::make_dump_widget): New decl.
888 (region::add_dump_widget_children): New decl.
889 (frame_region::print_dump_widget_label): New decl.
890 (globals_region::print_dump_widget_label): New decl.
891 (code_region::print_dump_widget_label): New decl.
892 (function_region::print_dump_widget_label): New decl.
893 (label_region::print_dump_widget_label): New decl.
894 (stack_region::print_dump_widget_label): New decl.
895 (heap_region::print_dump_widget_label): New decl.
896 (root_region::print_dump_widget_label): New decl.
897 (thread_local_region::print_dump_widget_label): New decl.
898 (symbolic_region::print_dump_widget_label): New decl.
899 (symbolic_region::add_dump_widget_children): New decl.
900 (decl_region::print_dump_widget_label): New decl.
901 (field_region::print_dump_widget_label): New decl.
902 (element_region::print_dump_widget_label): New decl.
903 (element_region::add_dump_widget_children): New decl.
904 (offset_region::print_dump_widget_label): New decl.
905 (offset_region::add_dump_widget_children): New decl.
906 (sized_region::print_dump_widget_label): New decl.
907 (sized_region::add_dump_widget_children): New decl.
908 (cast_region::print_dump_widget_label): New decl.
909 (cast_region::add_dump_widget_children): New decl.
910 (heap_allocated_region::print_dump_widget_label): New decl.
911 (alloca_region::print_dump_widget_label): New decl.
912 (string_region::print_dump_widget_label): New decl.
913 (bit_range_region::print_dump_widget_label): New decl.
914 (var_arg_region::print_dump_widget_label): New decl.
915 (errno_region::print_dump_widget_label): New decl.
916 (private_region::print_dump_widget_label): New decl.
917 (unknown_region::print_dump_widget_label): New decl.
918 * sm-fd.cc: Define INCLUDE_VECTOR.
919 * sm-file.cc: Likewise.
920 * sm-malloc.cc: Likewise.
921 * sm-pattern-test.cc: Likewise.
922 * sm-signal.cc: Likewise.
923 * sm-taint.cc: Likewise.
924 * sm.cc: Likewise.
925 * state-purge.cc: Likewise.
926 * store.cc: Likewise. Include "text-art/tree-widget.h".
927 (add_binding_to_tree_widget): New.
928 (binding_map::add_to_tree_widget): New.
929 (binding_cluster::make_dump_widget): New.
930 (store::make_dump_widget): New.
931 * store.h: Include "text-art/tree-widget.h".
932 (binding_map::add_to_tree_widget): New decl.
933 (binding_cluster::make_dump_widget): New decl.
934 (store::make_dump_widget): New decl.
935 * svalue.cc: Define INCLUDE_VECTOR. Include "make-unique.h" and
936 "text-art/dump.h".
937 (svalue::dump): New.
938 (svalue::make_dump_widget): New.
939 (region_svalue::print_dump_widget_label): New.
940 (region_svalue::add_dump_widget_children): New.
941 (constant_svalue::print_dump_widget_label): New.
942 (constant_svalue::add_dump_widget_children): New.
943 (unknown_svalue::print_dump_widget_label): New.
944 (unknown_svalue::add_dump_widget_children): New.
945 (poisoned_svalue::print_dump_widget_label): New.
946 (poisoned_svalue::add_dump_widget_children): New.
947 (initial_svalue::print_dump_widget_label): New.
948 (initial_svalue::add_dump_widget_children): New.
949 (unaryop_svalue::print_dump_widget_label): New.
950 (unaryop_svalue::add_dump_widget_children): New.
951 (binop_svalue::print_dump_widget_label): New.
952 (binop_svalue::add_dump_widget_children): New.
953 (sub_svalue::print_dump_widget_label): New.
954 (sub_svalue::add_dump_widget_children): New.
955 (repeated_svalue::print_dump_widget_label): New.
956 (repeated_svalue::add_dump_widget_children): New.
957 (bits_within_svalue::print_dump_widget_label): New.
958 (bits_within_svalue::add_dump_widget_children): New.
959 (widening_svalue::print_dump_widget_label): New.
960 (widening_svalue::add_dump_widget_children): New.
961 (placeholder_svalue::print_dump_widget_label): New.
962 (placeholder_svalue::add_dump_widget_children): New.
963 (unmergeable_svalue::print_dump_widget_label): New.
964 (unmergeable_svalue::add_dump_widget_children): New.
965 (compound_svalue::print_dump_widget_label): New.
966 (compound_svalue::add_dump_widget_children): New.
967 (conjured_svalue::print_dump_widget_label): New.
968 (conjured_svalue::add_dump_widget_children): New.
969 (asm_output_svalue::print_dump_widget_label): New.
970 (asm_output_svalue::add_dump_widget_children): New.
971 (const_fn_result_svalue::print_dump_widget_label): New.
972 (const_fn_result_svalue::add_dump_widget_children): New.
973 * svalue.h: Include "text-art/widget.h". Add "using
974 text_art::dump_widget_info".
975 (svalue::dump): New decl.
976 (svalue::make_dump_widget): New decl.
977 (svalue::print_dump_widget_label): New decl.
978 (svalue::print_dump_widget_label): New decl.
979 (svalue::add_dump_widget_children): New decl.
980 (region_svalue::print_dump_widget_label): New decl.
981 (region_svalue::add_dump_widget_children): New decl.
982 (constant_svalue::print_dump_widget_label): New decl.
983 (constant_svalue::add_dump_widget_children): New decl.
984 (unknown_svalue::print_dump_widget_label): New decl.
985 (unknown_svalue::add_dump_widget_children): New decl.
986 (poisoned_svalue::print_dump_widget_label): New decl.
987 (poisoned_svalue::add_dump_widget_children): New decl.
988 (initial_svalue::print_dump_widget_label): New decl.
989 (initial_svalue::add_dump_widget_children): New decl.
990 (unaryop_svalue::print_dump_widget_label): New decl.
991 (unaryop_svalue::add_dump_widget_children): New decl.
992 (binop_svalue::print_dump_widget_label): New decl.
993 (binop_svalue::add_dump_widget_children): New decl.
994 (sub_svalue::print_dump_widget_label): New decl.
995 (sub_svalue::add_dump_widget_children): New decl.
996 (repeated_svalue::print_dump_widget_label): New decl.
997 (repeated_svalue::add_dump_widget_children): New decl.
998 (bits_within_svalue::print_dump_widget_label): New decl.
999 (bits_within_svalue::add_dump_widget_children): New decl.
1000 (widening_svalue::print_dump_widget_label): New decl.
1001 (widening_svalue::add_dump_widget_children): New decl.
1002 (placeholder_svalue::print_dump_widget_label): New decl.
1003 (placeholder_svalue::add_dump_widget_children): New decl.
1004 (unmergeable_svalue::print_dump_widget_label): New decl.
1005 (unmergeable_svalue::add_dump_widget_children): New decl.
1006 (compound_svalue::print_dump_widget_label): New decl.
1007 (compound_svalue::add_dump_widget_children): New decl.
1008 (conjured_svalue::print_dump_widget_label): New decl.
1009 (conjured_svalue::add_dump_widget_children): New decl.
1010 (asm_output_svalue::print_dump_widget_label): New decl.
1011 (asm_output_svalue::add_dump_widget_children): New decl.
1012 (const_fn_result_svalue::print_dump_widget_label): New decl.
1013 (const_fn_result_svalue::add_dump_widget_children): New decl.
1014 * trimmed-graph.cc: Define INCLUDE_VECTOR.
1015 * varargs.cc: Likewise.
1016
1017 2024-05-28 David Malcolm <[email protected]>
1018
1019 * region-model.cc: Include "selftest-tree.h".
1020
1021 2024-05-17 David Malcolm <[email protected]>
1022
1023 * checker-event.h (checker_event::connect_to_next_event_p):
1024 Implement new diagnostic_event::connect_to_next_event_p vfunc.
1025 (start_cfg_edge_event::connect_to_next_event_p): Likewise.
1026 (start_consolidated_cfg_edges_event::connect_to_next_event_p):
1027 Likewise.
1028 * infinite-loop.cc (class looping_back_event): New subclass.
1029 (infinite_loop_diagnostic::add_final_event): Use it.
1030
1031 2024-05-15 David Malcolm <[email protected]>
1032
1033 PR analyzer/114899
1034 * access-diagram.cc
1035 (written_svalue_spatial_item::get_label_string): Bulletproof
1036 against SSA_NAME_VAR being null.
1037
1038 2024-05-03 David Malcolm <[email protected]>
1039
1040 PR analyzer/111475
1041 * analyzer.cc (is_special_named_call_p): Add "look_in_std" param.
1042 (is_std_function_p): Make non-static.
1043 * analyzer.h (is_special_named_call_p): Add optional "look_in_std"
1044 param.
1045 (is_std_function_p): New decl.
1046 * engine.cc (stmt_requires_new_enode_p): Look for both "signal"
1047 and "std::signal".
1048 * kf.cc (register_known_functions): Add various "std::" copies
1049 of the known functions.
1050 * known-function-manager.cc
1051 (known_function_manager::~known_function_manager): Clean up
1052 m_std_ns_map_id_to_kf.
1053 (known_function_manager::add_std_ns): New.
1054 (known_function_manager::get_match): Also look for known "std::"
1055 functions.
1056 (known_function_manager::get_by_identifier_in_std_ns): New.
1057 * known-function-manager.h
1058 (known_function_manager::add_std_ns): New decl.
1059 (known_function_manager::get_by_identifier_in_std_ns): New decl.
1060 (known_function_manager::m_std_ns_map_id_to_kf): New field.
1061 * sm-file.cc (register_known_file_functions): Add various "std::"
1062 copies of the known functions.
1063 * sm-malloc.cc (malloc_state_machine::on_stmt): Handle
1064 "std::realloc".
1065 * sm-signal.cc (signal_unsafe_p): Consider "std::" copies of the
1066 functions as also being async-signal-unsafe.
1067 (signal_state_machine::on_stmt): Consider "std::signal".
1068
1069 2024-04-12 Stefan Schulze Frielinghaus <[email protected]>
1070
1071 * region-model.cc (region_model::check_region_size): Bail out
1072 early on function pointers.
1073
1074 2024-04-10 David Malcolm <[email protected]>
1075
1076 PR analyzer/114472
1077 * access-diagram.cc (bit_size_expr::maybe_get_formatted_str):
1078 Reject attempts to print sizes that are too large.
1079 * region.cc (region_offset::calc_symbolic_bit_offset): Use a
1080 typeless svalue for the bit offset.
1081 * store.cc (bit_range::intersects_p): Replace assertion with
1082 test.
1083 (bit_range::exceeds_p): Likewise.
1084 (bit_range::falls_short_of_p): Likewise.
1085
1086 2024-04-10 David Malcolm <[email protected]>
1087
1088 * infinite-loop.cc: Include "diagnostic-format-sarif.h".
1089 (infinite_loop::to_json): New.
1090 (infinite_loop_diagnostic::maybe_add_sarif_properties): New.
1091
1092 2024-04-10 David Malcolm <[email protected]>
1093
1094 * infinite-recursion.cc: Include "diagnostic-format-sarif.h".
1095 (infinite_recursion_diagnostic::maybe_add_sarif_properties): New.
1096
1097 2024-04-10 David Malcolm <[email protected]>
1098
1099 * call-details.cc: Include "diagnostic-format-sarif.h".
1100 (overlapping_buffers::overlapping_buffers): Add params for new
1101 fields.
1102 (overlapping_buffers::maybe_add_sarif_properties): New.
1103 (overlapping_buffers::m_byte_range_a): New field.
1104 (overlapping_buffers::byte_range_b): New field.
1105 (overlapping_buffers::m_num_bytes_read_sval): New field.
1106 (call_details::complain_about_overlap): Pass new params to
1107 overlapping_buffers ctor.
1108 * ranges.cc (symbolic_byte_offset::to_json): New.
1109 (symbolic_byte_range::to_json): New.
1110 * ranges.h (symbolic_byte_offset::to_json): New decl.
1111 (symbolic_byte_range::to_json): New decl.
1112
1113 2024-04-10 David Malcolm <[email protected]>
1114
1115 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
1116 Add "size_in_bytes" param.
1117 (tainted_allocation_size::maybe_add_sarif_properties): New.
1118 (tainted_allocation_size::m_size_in_bytes): New field.
1119 (region_model::check_dynamic_size_for_taint): Pass size_in_bytes
1120 to tainted_allocation_size ctor.
1121
1122 2024-04-09 Jakub Jelinek <[email protected]>
1123
1124 * analyzer.opt (Wanalyzer-undefined-behavior-strtok): Fix duplicated
1125 words; in in -> in.
1126 * program-state.cc (sm_state_map::replay_call_summary): Fix duplicated
1127 words in comment; to to -> to.
1128 (program_state::replay_call_summary): Likewise.
1129 * region-model.cc (region_model::replay_call_summary): Likewise.
1130
1131 2024-04-05 David Malcolm <[email protected]>
1132
1133 PR analyzer/114588
1134 * access-diagram.cc (access_diagram_impl::access_diagram_impl):
1135 Replace hardcoded colors for valid_style and invalid_style with
1136 calls to text_art::get_style_from_color_cap_name.
1137
1138 2024-04-02 David Malcolm <[email protected]>
1139
1140 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
1141 Guard against null types.
1142 * region-model.cc (apply_constraints_for_gswitch): Likewise.
1143
1144 2024-03-27 David Malcolm <[email protected]>
1145
1146 PR analyzer/114473
1147 * call-summary.cc
1148 (call_summary_replay::convert_svalue_from_summary): Assert that
1149 the types match.
1150 (call_summary_replay::convert_region_from_summary): Likewise.
1151 (call_summary_replay::convert_region_from_summary_1): Add missing
1152 cast for the deref of RK_SYMBOLIC case.
1153
1154 2024-03-23 David Malcolm <[email protected]>
1155
1156 PR analyzer/114408
1157 * engine.cc (impl_run_checkers): Free up any dominance info that
1158 we may have created.
1159 * kf.cc (class kf_ubsan_handler): New.
1160 (register_sanitizer_builtins): New.
1161 (register_known_functions): Call register_sanitizer_builtins.
1162
1163 2024-03-22 David Malcolm <[email protected]>
1164
1165 PR analyzer/112974
1166 PR analyzer/112975
1167 * sm-taint.cc (taint_state_machine::on_condition): Strip away
1168 casts before considering LHS and RHS, to increase the chance of
1169 detecting places where sanitization of a value may have happened.
1170
1171 2024-03-22 David Malcolm <[email protected]>
1172
1173 * sm-taint.cc: Include "diagnostic-format-sarif.h".
1174 (bounds_to_str): New.
1175 (taint_diagnostic::maybe_add_sarif_properties): New.
1176 (tainted_offset::tainted_offset): Add "offset" param.
1177 (tainted_offset::maybe_add_sarif_properties): New.
1178 (tainted_offset::m_offset): New.
1179 (region_model::check_region_for_taint): Pass offset to
1180 tainted_offset ctor.
1181
1182 2024-03-21 David Malcolm <[email protected]>
1183
1184 PR analyzer/113619
1185 * region-model.cc (region_model::eval_condition): Fix
1186 cast-handling from r14-3632-ge7b267444045c5 so that if those give
1187 an unknown result, we continue trying the constraint manager.
1188
1189 2024-03-20 David Malcolm <[email protected]>
1190
1191 PR analyzer/109251
1192 * sm-malloc.cc (deref_before_check::emit): Reject cases where the
1193 check is in a loop header within a macro expansion.
1194 (deref_before_check::loop_header_p): New.
1195
1196 2024-03-20 Jakub Jelinek <[email protected]>
1197
1198 * constraint-manager.cc (test_range, test_constraint_conditions,
1199 test_constant_comparisons, test_constraint_impl, test_purging,
1200 test_bits): Use integer_zero_node instead of
1201 build_zero_cst (integer_type_node) or
1202 build_int_cst (integer_type_node, 0) and integer_one_node instead of
1203 build_int_cst (integer_type_node, 1).
1204 * region-model.cc (region_model::get_store_value,
1205 append_interesting_constants, test_array_1,
1206 test_get_representative_tree, test_unique_constants, test_assignment,
1207 test_stack_frames, test_constraint_merging, test_widening_constraints,
1208 test_iteration_1, test_array_2): Likewise.
1209
1210 2024-03-19 Jakub Jelinek <[email protected]>
1211
1212 PR analyzer/113505
1213 * region-model.cc (get_tree_for_byte_offset,
1214 region_model::get_representative_path_var_1,
1215 test_mem_ref, test_POINTER_PLUS_EXPR_then_MEM_REF): Use
1216 char __attribute__((may_alias)) * as type of MEM_REF second argument.
1217
1218 2024-03-19 David Malcolm <[email protected]>
1219
1220 PR analyzer/114286
1221 * kf.cc (class kf_atomic_exchange): Reimplement based on signature
1222 seen in gimple, rather than user-facing signature.
1223 (class kf_atomic_load): Likewise.
1224 (class kf_atomic_store): New.
1225 (register_atomic_builtins): Register kf_atomic_store.
1226
1227 2024-03-18 David Malcolm <[email protected]>
1228
1229 PR analyzer/110902
1230 PR analyzer/110928
1231 PR analyzer/111305
1232 PR analyzer/111441
1233 * access-diagram.cc: Include "analyzer/analyzer-selftests.h".
1234 (get_access_size_str): Reimplement for conversion of
1235 implmementation of bit_size_expr from tree to const svalue &. Use
1236 svalue::maybe_print_for_user rather than tree printing routines.
1237 (remove_ssa_names): Make non-static.
1238 (bit_size_expr::get_formatted_str): Rename to...
1239 (bit_size_expr::maybe_get_formatted_str): ...this, adding "model"
1240 param and converting return type to a unique_ptr. Update for
1241 conversion of implementation of bit_size_expr from tree to
1242 const svalue &. Use svalue::maybe_print_for_user rather than tree
1243 printing routines.
1244 (bit_size_expr::print): Rename to...
1245 (bit_size_expr::maybe_print_for_user): ...this, adding "model"
1246 param and converting return type to bool. Update for
1247 conversion of implementation of bit_size_expr from tree to
1248 const svalue &. Use svalue::maybe_print_for_user rather than tree
1249 printing routines.
1250 (bit_size_expr::maybe_get_as_bytes): Add "mgr" param and convert
1251 return type from tree to const svalue *; reimplement.
1252 (access_range::access_range): Call strip_types when on region_offset
1253 intializations.
1254 (access_range::get_size): Update for conversion of implementation
1255 of bit_size_expr from tree to const svalue &.
1256 (access_operation::get_valid_bits): Pass manager to access_range
1257 ctor.
1258 (access_operation::maybe_get_invalid_before_bits): Likewise.
1259 (access_operation::maybe_get_invalid_after_bits): Likewise.
1260 (boundaries::add): Likewise.
1261 (bit_to_table_map::populate): Add "mgr" param and pass it to
1262 access_range ctor.
1263 (access_diagram_impl::access_diagram_impl): Pass manager to
1264 bit_to_table_map::populate.
1265 (access_diagram_impl::maybe_add_gap): Use svalue rather than tree
1266 for symbolic bit offsets. Port to new bit_size_expr
1267 representation.
1268 (access_diagram_impl::add_valid_vs_invalid_ruler): Port to new
1269 bit_size_expr representation.
1270 (selftest::assert_eq_typeless_integer): New.
1271 (ASSERT_EQ_TYPELESS_INTEGER): New.
1272 (selftest::test_bit_size_expr_to_bytes): New.
1273 (selftest::analyzer_access_diagram_cc_tests): New.
1274 * access-diagram.h (class bit_size_expr): Reimplement, converting
1275 implementation from tree to const svalue &.
1276 (access_range::access_range): Add "mgr" param. Call strip_types
1277 on region_offset initializations.
1278 (access_range::get_size): Update decl for reimplementation.
1279 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
1280 selftest::analyzer_access_diagram_cc_tests.
1281 * analyzer-selftests.h
1282 (selftest::analyzer_checker_script_cc_tests): Delete this stray
1283 typo.
1284 (selftest::analyzer_access_diagram_cc_tests): New decl.
1285 * analyzer.h (print_expr_for_user): New decl.
1286 (calc_symbolic_bit_offset): Update decl for reimplementation.
1287 (strip_types): New decls.
1288 (remove_ssa_names): New decl.
1289 * bounds-checking.cc (strip_types): New.
1290 (region_model::check_symbolic_bounds): Use typeless svalues.
1291 * region-model-manager.cc
1292 (region_model_manager::get_or_create_constant_svalue): Add "type"
1293 param. Add overload with old signature.
1294 (region_model_manager::get_or_create_int_cst): Support type being
1295 NULL_TREE.
1296 (region_model_manager::maybe_fold_unaryop): Gracefully reject folding
1297 of casts to NULL_TREE type.
1298 (get_code_for_cast): Use NOP_EXPR for "casting" svalues to
1299 NULL_TREE type.
1300 (region_model_manager::get_or_create_cast): Support "casting"
1301 svalues to NULL_TREE type.
1302 (region_model_manager::maybe_fold_binop): Don't crash on inputs
1303 with NULL_TREE type. Handle folding of binops on constants with
1304 NULL_TREE type. Add missing cast from PR analyzer/110902.
1305 Support enough folding of other ops on NULL_TREE type to support
1306 bounds checking.
1307 (region_model_manager::get_or_create_const_fn_result_svalue):
1308 Remove assertion that type is nonnull.
1309 * region-model-manager.h
1310 (region_model_manager::get_or_create_constant_svalue): Add
1311 overloaded decl taking a type.
1312 (region_model_manager::maybe_fold_binop): Make public.
1313 (region_model_manager::constants_map_t): Use
1314 constant_svalue::key_t for the key, rather than just tree.
1315 * region-model.cc (print_expr_for_user): New.
1316 (selftest::test_array_2): Handle casts.
1317 * region.cc (region_offset::calc_symbolic_bit_offset): Return
1318 const svalue & rather than tree, and reimplement accordingly.
1319 (region::calc_offset): Use ptrdiff_type_node for types of byte
1320 offsets.
1321 (region::maybe_print_for_user): New.
1322 (element_region::get_relative_symbolic_offset): Use NULL_TREE for
1323 types of bit offsets.
1324 (offset_region::get_bit_offset): Likewise.
1325 (sized_region::get_bit_size_sval): Likewise for bit sizes.
1326 * region.h (region::maybe_print_for_user): New decl.
1327 * svalue.cc (class auto_add_parens): New.
1328 (svalue::maybe_print_for_user): New.
1329 (svalue::cmp_ptr): Support typeless constant svalues.
1330 (tristate_from_boolean_tree_node): New, taken from...
1331 (constant_svalue::eval_condition): ...here. Handle comparison of
1332 typeless integer svalue constants.
1333 * svalue.h (svalue::maybe_print_for_user): New decl.
1334 (class constant_svalue): Support the type of the svalue being
1335 NULL_TREE.
1336 (struct default_hash_traits<constant_svalue::key_t>): New.
1337
1338 2024-03-18 David Malcolm <[email protected]>
1339
1340 * access-diagram.cc (remove_ssa_names): Support operands being
1341 NULL_TREE, such as e.g. for COMPONENT_REF's operand 2.
1342
1343 2024-03-07 Jakub Jelinek <[email protected]>
1344
1345 * access-diagram.cc: Include diagnostic-core.h before including
1346 diagnostic.h or diagnostic-path.h.
1347 * sm-malloc.cc: Likewise.
1348 * diagnostic-manager.cc: Likewise.
1349 * call-summary.cc: Likewise.
1350 * record-layout.cc: Likewise.
1351
1352 2024-02-29 David Malcolm <[email protected]>
1353
1354 PR analyzer/114159
1355 * analyzer.cc: Include "tree-dfa.h".
1356 (get_ssa_default_def): New decl.
1357 * analyzer.h (get_ssa_default_def): New.
1358 * call-info.cc (call_info::call_info): New ctor taking an explicit
1359 called_fn.
1360 * call-info.h (call_info::call_info): Likewise.
1361 * call-summary.cc (call_summary_replay::call_summary_replay):
1362 Convert param from function * to const function &.
1363 * call-summary.h (call_summary_replay::call_summary_replay):
1364 Likewise.
1365 * checker-event.h (state_change_event::get_dest_function):
1366 Constify return value.
1367 * engine.cc (point_and_state::validate): Update for conversion to
1368 const function &.
1369 (exploded_node::on_stmt): Likewise.
1370 (call_summary_edge_info::call_summary_edge_info): Likewise.
1371 Pass in called_fn to call_info ctor.
1372 (exploded_node::replay_call_summaries): Update for conversion to
1373 const function &. Convert per_function_data from * to &.
1374 (exploded_node::replay_call_summary): Update for conversion to
1375 const function &.
1376 (exploded_graph::add_function_entry): Likewise.
1377 (toplevel_function_p): Likewise.
1378 (add_tainted_args_callback): Likewise.
1379 (exploded_graph::build_initial_worklist): Likewise.
1380 (exploded_graph::maybe_create_dynamic_call): Likewise.
1381 (maybe_update_for_edge): Likewise.
1382 (exploded_graph::on_escaped_function): Likewise.
1383 * exploded-graph.h (exploded_node::replay_call_summaries):
1384 Likewise.
1385 (exploded_node::replay_call_summary): Likewise.
1386 (exploded_graph::add_function_entry): Likewise.
1387 * program-point.cc (function_point::from_function_entry):
1388 Likewise.
1389 (program_point::from_function_entry): Likewise.
1390 * program-point.h (function_point::from_function_entry): Likewise.
1391 (program_point::from_function_entry): Likewise.
1392 * program-state.cc (program_state::push_frame): Likewise.
1393 (program_state::get_current_function): Constify return type.
1394 * program-state.h (program_state::push_frame): Update for
1395 conversion to const function &.
1396 (program_state::get_current_function): Likewise.
1397 * region-model-manager.cc
1398 (region_model_manager::get_frame_region): Likewise.
1399 * region-model-manager.h
1400 (region_model_manager::get_frame_region): Likewise.
1401 * region-model.cc (region_model::called_from_main_p): Likewise.
1402 (region_model::update_for_gcall): Likewise.
1403 (region_model::push_frame): Likewise.
1404 (region_model::get_current_function): Constify return type.
1405 (region_model::pop_frame): Update for conversion to
1406 const function &.
1407 (selftest::test_stack_frames): Likewise.
1408 (selftest::test_get_representative_path_var): Likewise.
1409 (selftest::test_state_merging): Likewise.
1410 (selftest::test_alloca): Likewise.
1411 * region-model.h (region_model::push_frame): Likewise.
1412 (region_model::get_current_function): Likewise.
1413 * region.cc (frame_region::dump_to_pp): Likewise.
1414 (frame_region::get_region_for_local): Likewise.
1415 * region.h (class frame_region): Likewise.
1416 * sm-signal.cc (signal_unsafe_call::describe_state_change):
1417 Likewise.
1418 (update_model_for_signal_handler): Likewise.
1419 (signal_delivery_edge_info_t::update_model): Likewise.
1420 (register_signal_handler::impl_transition): Likewise.
1421 * state-purge.cc (class gimple_op_visitor): Likewise.
1422 (state_purge_map::state_purge_map): Likewise.
1423 (state_purge_map::get_or_create_data_for_decl): Likewise.
1424 (state_purge_per_ssa_name::state_purge_per_ssa_name): Likewise.
1425 (state_purge_per_ssa_name::add_to_worklist): Likewise.
1426 (state_purge_per_ssa_name::process_point): Likewise.
1427 (state_purge_per_decl::add_to_worklist): Likewise.
1428 (state_purge_annotator::print_needed): Likewise.
1429 * state-purge.h
1430 (state_purge_map::get_or_create_data_for_decl): Likewise.
1431 (class state_purge_per_tree): Likewise.
1432 (class state_purge_per_ssa_name): Likewise.
1433 (class state_purge_per_decl): Likewise.
1434 * supergraph.cc (supergraph::dump_dot_to_pp): Likewise.
1435 * supergraph.h
1436 (supergraph::get_node_for_function_entry): Likewise.
1437 (supergraph::get_node_for_function_exit): Likewise.
1438
1439 2024-02-27 David Malcolm <[email protected]>
1440
1441 PR analyzer/110483
1442 PR analyzer/111802
1443 * access-diagram.cc
1444 (string_literal_spatial_item::add_column_for_byte): Use %wu for
1445 printing unsigned HOST_WIDE_INT.
1446
1447 2024-02-27 David Malcolm <[email protected]>
1448
1449 PR analyzer/111881
1450 * constraint-manager.cc (bound::ensure_closed): Assert that
1451 m_constant has integral type.
1452 (range::add_bound): Bail out on floating point constants.
1453
1454 2024-02-21 David Malcolm <[email protected]>
1455
1456 PR analyzer/113999
1457 * analyzer.h (get_string_cst_size): New decl.
1458 * region-model-manager.cc (get_string_cst_size): New.
1459 (region_model_manager::maybe_get_char_from_string_cst): Treat
1460 single-byte accesses within string_cst but beyond
1461 TREE_STRING_LENGTH as being 0.
1462 * region-model.cc (string_cst_has_null_terminator): Likewise.
1463
1464 2024-02-21 David Malcolm <[email protected]>
1465
1466 PR analyzer/113998
1467 * ranges.cc (symbolic_byte_range::intersection): Handle empty ranges.
1468 (selftest::test_intersects): Add test coverage for empty ranges.
1469
1470 2024-02-19 David Malcolm <[email protected]>
1471
1472 PR analyzer/111289
1473 * varargs.cc (representable_in_integral_type_p): New.
1474 (va_arg_compatible_types_p): Add "arg_sval" param. Handle integer
1475 types.
1476 (kf_va_arg::impl_call_pre): Pass arg_sval to
1477 va_arg_compatible_types_p.
1478
1479 2024-02-19 Andrew Pinski <[email protected]>
1480
1481 PR analyzer/113983
1482 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Reject
1483 non integral types.
1484
1485 2024-02-15 David Malcolm <[email protected]>
1486
1487 PR analyzer/111266
1488 * region.cc (offset_region::get_byte_size_sval): Delete.
1489 (offset_region::get_bit_size_sval): Delete.
1490 * region.h (region::get_byte_size): Add comment clarifying that
1491 this relates to the size of the access, rather than the size
1492 that's valid to access.
1493 (region::get_bit_size): Likewise.
1494 (region::get_byte_size_sval): Likewise.
1495 (region::get_bit_size_sval): Likewise.
1496 (offset_region::get_byte_size_sval): Delete.
1497 (offset_region::get_bit_size_sval): Delete.
1498
1499 2024-02-13 David Malcolm <[email protected]>
1500
1501 * pending-diagnostic.cc (diagnostic_emission_context::warn):
1502 Update for renaming of emit_diagnostic_valist overload to
1503 emit_diagnostic_valist_meta.
1504 (diagnostic_emission_context::inform): Likewise.
1505
1506 2024-01-31 David Malcolm <[email protected]>
1507
1508 PR analyzer/113253
1509 * region-model.cc (region_model::on_stmt_pre): Add gcc_unreachable
1510 for debug statements.
1511 * state-purge.cc
1512 (state_purge_per_ssa_name::state_purge_per_ssa_name): Skip any
1513 debug stmts in the FOR_EACH_IMM_USE_FAST list.
1514 * supergraph.cc (supergraph::supergraph): Don't add debug stmts
1515 to the supernodes.
1516
1517 2024-01-31 David Malcolm <[email protected]>
1518
1519 PR analyzer/113509
1520 * checker-event.cc (state_change_event::get_desc): Don't assume
1521 "var" is non-NULL.
1522
1523 2024-01-30 David Malcolm <[email protected]>
1524
1525 PR analyzer/113654
1526 * region-model.cc (is_round_up): New.
1527 (is_multiple_p): New.
1528 (is_dubious_capacity): New.
1529 (region_model::check_region_size): Move usage of size_visitor into
1530 is_dubious_capacity.
1531
1532 2024-01-30 David Malcolm <[email protected]>
1533
1534 * region-model.cc
1535 (dubious_allocation_size::dubious_allocation_size): Add
1536 "capacity_sval" param. Drop unused ctor.
1537 (dubious_allocation_size::maybe_add_sarif_properties): New.
1538 (dubious_allocation_size::m_capacity_sval): New field.
1539 (region_model::check_region_size): Pass capacity svalue to
1540 dubious_allocation_size ctor.
1541
1542 2024-01-25 David Malcolm <[email protected]>
1543
1544 PR analyzer/112969
1545 * store.cc (binding_cluster::maybe_get_compound_binding): When
1546 populating default_map, express the bit-range of the default key
1547 for REG relative to REG, rather than to the base region.
1548
1549 2024-01-24 David Malcolm <[email protected]>
1550
1551 PR analyzer/112977
1552 * engine.cc (impl_region_model_context::on_liveness_change): Pass
1553 m_ext_state to sm_state_map::on_liveness_change.
1554 * program-state.cc (sm_state_map::on_svalue_leak): Guard removal
1555 of map entry based on can_purge_p.
1556 (sm_state_map::on_liveness_change): Add ext_state param. Add
1557 workaround for bad interaction between state purging and
1558 alt-inherited sm-state.
1559 * program-state.h (sm_state_map::on_liveness_change): Add
1560 ext_state param.
1561 * sm-taint.cc
1562 (taint_state_machine::has_alt_get_inherited_state_p): New.
1563 (taint_state_machine::can_purge_p): Return false for "has_lb" and
1564 "has_ub".
1565 * sm.h (state_machine::has_alt_get_inherited_state_p): New vfunc.
1566
1567 2024-01-18 David Malcolm <[email protected]>
1568
1569 PR analyzer/111361
1570 * region-model.cc (svalue_byte_range_has_null_terminator_1): The
1571 initial byte of an all-zeroes SVAL is a zero byte. Remove
1572 gcc_unreachable from SK_CONSTANT for constants that aren't
1573 STRING_CST or INTEGER_CST.
1574
1575 2024-01-18 David Malcolm <[email protected]>
1576
1577 PR analyzer/112811
1578 * region-model.cc (fragment::dump_to_pp): New.
1579 (fragment::has_null_terminator): Convert to...
1580 (svalue_byte_range_has_null_terminator_1): ...this new function,
1581 updating to use a byte_range relative to the start of the svalue.
1582 (svalue_byte_range_has_null_terminator): New.
1583 (fragment::string_cst_has_null_terminator): Convert to...
1584 (string_cst_has_null_terminator): ...this, updating to use a
1585 byte_range relative to the start of the svalue.
1586 (iterable_cluster::dump_to_pp): New.
1587 (region_model::scan_for_null_terminator): Add logging, moving body
1588 to...
1589 (region_model::scan_for_null_terminator_1): ...this new function,
1590 adding more logging, and updating to use
1591 svalue_byte_range_has_null_terminator.
1592 * region-model.h (region_model::scan_for_null_terminator_1): New
1593 decl.
1594
1595 2024-01-16 David Malcolm <[email protected]>
1596
1597 PR analyzer/106229
1598 * analyzer.h (compare_constants): New decl.
1599 * constraint-manager.cc (compare_constants): Make non-static.
1600 * sm-taint.cc: Add include "fold-const.h".
1601 (class concrete_range): New.
1602 (get_possible_range): New.
1603 (index_can_be_out_of_bounds_p): New.
1604 (region_model::check_region_for_taint): Reject
1605 -Wanalyzer-tainted-array-index if the type of the value makes it
1606 impossible for it to be out-of-bounds of the array.
1607
1608 2024-01-16 David Malcolm <[email protected]>
1609
1610 PR analyzer/113333
1611 * region-model-manager.cc
1612 (region_model_manager::maybe_fold_unaryop): Casting all zeroes
1613 should give all zeroes.
1614
1615 2024-01-04 David Malcolm <[email protected]>
1616
1617 * analyzer.opt.urls: New file, autogenerated by
1618 regenerate-opt-urls.py.
1619
1620 2024-01-04 David Malcolm <[email protected]>
1621
1622 * checker-event.cc: Include "diagnostic-format-sarif.h" and
1623 "tree-logical-location.h".
1624 (checker_event::maybe_add_sarif_properties): New.
1625 (superedge_event::maybe_add_sarif_properties): New.
1626 (superedge_event::superedge_event): Add comment.
1627 * checker-event.h (checker_event::maybe_add_sarif_properties): New
1628 decl.
1629 (superedge_event::maybe_add_sarif_properties): New decl.
1630
1631 2024-01-04 David Malcolm <[email protected]>
1632
1633 PR analyzer/112790
1634 * checker-event.cc (class inlining_info): Move to...
1635 * inlining-iterator.h (class inlining_info): ...here.
1636 * sm-malloc.cc: Include "analyzer/inlining-iterator.h".
1637 (maybe_complain_about_deref_before_check): Reject stmts that were
1638 inlined from another function.
1639
1640 2024-01-04 David Malcolm <[email protected]>
1641
1642 PR analyzer/113222
1643 * access-diagram.cc (valid_region_spatial_item::add_boundaries):
1644 Handle TYPE_DOMAIN being null.
1645 (valid_region_spatial_item::add_array_elements_to_table):
1646 Likewise.
1647
1648 2023-12-16 David Malcolm <[email protected]>
1649
1650 * analyzer.cc: Include "tree-pretty-print.h" and
1651 "diagnostic-event-id.h".
1652 (tree_to_json): New.
1653 (diagnostic_event_id_to_json): New.
1654 (bit_offset_to_json): New.
1655 (byte_offset_to_json): New.
1656 * analyzer.h (tree_to_json): New decl.
1657 (diagnostic_event_id_to_json): New decl.
1658 (bit_offset_to_json): New decl.
1659 (byte_offset_to_json): New decl.
1660 * bounds-checking.cc: Include "diagnostic-format-sarif.h".
1661 (out_of_bounds::maybe_add_sarif_properties): New.
1662 (concrete_out_of_bounds::maybe_add_sarif_properties): New.
1663 (concrete_past_the_end::maybe_add_sarif_properties): New.
1664 (symbolic_past_the_end::maybe_add_sarif_properties): New.
1665 * region-model.cc (region_to_value_map::to_json): New.
1666 (region_model::to_json): New.
1667 * region-model.h (region_to_value_map::to_json): New decl.
1668 (region_model::to_json): New decl.
1669 * store.cc (bit_range::to_json): New.
1670 (byte_range::to_json): New.
1671 * store.h (bit_range::to_json): New decl.
1672 (byte_range::to_json): New decl.
1673
1674 2023-12-16 David Malcolm <[email protected]>
1675
1676 PR analyzer/112792
1677 * bounds-checking.cc
1678 (out_of_bounds::oob_region_creation_event_capacity): Rename
1679 "capacity" to "byte_capacity". Layout fix.
1680 (out_of_bounds::::add_region_creation_events): Rename
1681 "capacity" to "byte_capacity".
1682 (class concrete_out_of_bounds): Rename m_out_of_bounds_range to
1683 m_out_of_bounds_bits and convert from a byte_range to a bit_range.
1684 (concrete_out_of_bounds::get_out_of_bounds_bytes): New.
1685 (concrete_past_the_end::concrete_past_the_end): Rename param
1686 "byte_bound" to "bit_bound". Initialize m_byte_bound.
1687 (concrete_past_the_end::subclass_equal_p): Update for renaming
1688 of m_byte_bound to m_bit_bound.
1689 (concrete_past_the_end::m_bit_bound): New field.
1690 (concrete_buffer_overflow::concrete_buffer_overflow): Convert
1691 param "range" from byte_range to bit_range. Rename param
1692 "byte_bound" to "bit_bound".
1693 (concrete_buffer_overflow::emit): Update for bits vs bytes.
1694 (concrete_buffer_overflow::describe_final_event): Split
1695 into...
1696 (concrete_buffer_overflow::describe_final_event_as_bytes): ...this
1697 (concrete_buffer_overflow::describe_final_event_as_bits): ...and
1698 this.
1699 (concrete_buffer_over_read::concrete_buffer_over_read): Convert
1700 param "range" from byte_range to bit_range. Rename param
1701 "byte_bound" to "bit_bound".
1702 (concrete_buffer_over_read::emit): Update for bits vs bytes.
1703 (concrete_buffer_over_read::describe_final_event): Split into...
1704 (concrete_buffer_over_read::describe_final_event_as_bytes):
1705 ...this
1706 (concrete_buffer_over_read::describe_final_event_as_bits): ...and
1707 this.
1708 (concrete_buffer_underwrite::concrete_buffer_underwrite): Convert
1709 param "range" from byte_range to bit_range.
1710 (concrete_buffer_underwrite::describe_final_event): Split into...
1711 (concrete_buffer_underwrite::describe_final_event_as_bytes):
1712 ...this
1713 (concrete_buffer_underwrite::describe_final_event_as_bits): ...and
1714 this.
1715 (concrete_buffer_under_read::concrete_buffer_under_read): Convert
1716 param "range" from byte_range to bit_range.
1717 (concrete_buffer_under_read::describe_final_event): Split into...
1718 (concrete_buffer_under_read::describe_final_event_as_bytes):
1719 ...this
1720 (concrete_buffer_under_read::describe_final_event_as_bits): ...and
1721 this.
1722 (region_model::check_region_bounds): Use bits for concrete values,
1723 and rename locals to indicate whether we're dealing with bits or
1724 bytes. Specifically, replace "num_bytes_sval" with
1725 "num_bits_sval", and get it from reg's "get_bit_size_sval".
1726 Replace "num_bytes_tree" with "num_bits_tree". Rename "capacity"
1727 to "byte_capacity". Rename "cst_capacity_tree" to
1728 "cst_byte_capacity_tree". Replace "offset" and
1729 "num_bytes_unsigned" with "bit_offset" and "num_bits_unsigned"
1730 respectively, converting from byte_offset_t to bit_offset_t.
1731 Replace "out" and "read_bytes" with "bits_outside" and "read_bits"
1732 respectively, converting from byte_range to bit_range. Convert
1733 "buffer" from byte_range to bit_range. Replace "byte_bound" with
1734 "bit_bound".
1735 * region.cc (region::get_bit_size_sval): New.
1736 (offset_region::get_bit_offset): New.
1737 (offset_region::get_bit_size_sval): New.
1738 (sized_region::get_bit_size_sval): New.
1739 (bit_range_region::get_bit_size_sval): New.
1740 * region.h (region::get_bit_size_sval): New vfunc.
1741 (offset_region::get_bit_offset): New decl.
1742 (offset_region::get_bit_size_sval): New decl.
1743 (sized_region::get_bit_size_sval): New decl.
1744 (bit_range_region::get_bit_size_sval): New decl.
1745 * store.cc (bit_range::intersects_p): New, based on
1746 byte_range::intersects_p.
1747 (bit_range::exceeds_p): New, based on byte_range::exceeds_p.
1748 (bit_range::falls_short_of_p): New, based on
1749 byte_range::falls_short_of_p.
1750 (byte_range::intersects_p): Delete.
1751 (byte_range::exceeds_p): Delete.
1752 (byte_range::falls_short_of_p): Delete.
1753 * store.h (bit_range::intersects_p): New overload.
1754 (bit_range::exceeds_p): New.
1755 (bit_range::falls_short_of_p): New.
1756 (byte_range::intersects_p): Delete.
1757 (byte_range::exceeds_p): Delete.
1758 (byte_range::falls_short_of_p): Delete.
1759
1760 2023-12-14 David Malcolm <[email protected]>
1761
1762 PR analyzer/112655
1763 * infinite-loop.cc (infinite_loop::infinite_loop): Pass eedges
1764 via rvalue reference rather than by value.
1765 (starts_infinite_loop_p): Move eedges when constructing an
1766 infinite_loop instance.
1767 * sm-file.cc (fileptr_state_machine::fileptr_state_machine): Use
1768 initializer list for states.
1769 * sm-sensitive.cc
1770 (sensitive_state_machine::sensitive_state_machine): Likewise.
1771 * sm-signal.cc (signal_state_machine::signal_state_machine):
1772 Likewise.
1773 * sm-taint.cc (taint_state_machine::taint_state_machine):
1774 Likewise.
1775 * varargs.cc (va_list_state_machine::va_list_state_machine): Likewise.
1776
1777 2023-12-11 David Malcolm <[email protected]>
1778
1779 PR analyzer/112955
1780 * engine.cc (feasibility_state::feasibility_state): Initialize
1781 m_snodes_visited.
1782
1783 2023-12-11 Andrew Pinski <[email protected]>
1784
1785 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Remove
1786 the check for type being unsigned_char_type_node.
1787
1788 2023-12-08 David Malcolm <[email protected]>
1789
1790 * sm-taint.cc (taint_state_machine::alt_get_inherited_state): Fix
1791 handling of TRUNC_MOD_EXPR.
1792
1793 2023-12-08 David Malcolm <[email protected]>
1794
1795 * region-model.cc (contains_uninit_p): Only check for
1796 svalues that the infoleak warning can handle.
1797
1798 2023-12-08 David Malcolm <[email protected]>
1799
1800 PR analyzer/112889
1801 * store.h (concrete_binding::concrete_binding): Strengthen
1802 assertion to require size to be be positive, rather than just
1803 non-zero.
1804 (concrete_binding::mark_deleted): Use size rather than start bit
1805 offset.
1806 (concrete_binding::mark_empty): Likewise.
1807 (concrete_binding::is_deleted): Likewise.
1808 (concrete_binding::is_empty): Likewise.
1809
1810 2023-12-07 Alexandre Oliva <[email protected]>
1811
1812 * region-model.cc (has_nondefault_case_for_value_p): Take
1813 enumerate type as a parameter.
1814 (region_model::apply_constraints_for_gswitch): Cope with
1815 integral promotion type casts.
1816
1817 2023-12-07 David Malcolm <[email protected]>
1818
1819 PR analyzer/103546
1820 PR analyzer/112850
1821 * analyzer.opt (-param=analyzer-max-svalue-depth=): Increase from
1822 12 to 18.
1823 (Wanalyzer-symbol-too-complex): New.
1824 * diagnostic-manager.cc
1825 (null_assignment_sm_context::clear_all_per_svalue_state): New.
1826 * engine.cc (impl_sm_context::clear_all_per_svalue_state): New.
1827 * program-state.cc (sm_state_map::clear_all_per_svalue_state):
1828 New.
1829 * program-state.h (sm_state_map::clear_all_per_svalue_state): New
1830 decl.
1831 * region-model-manager.cc
1832 (region_model_manager::reject_if_too_complex): Add
1833 -Wanalyzer-symbol-too-complex.
1834 * sm-taint.cc (taint_state_machine::on_condition): Handle
1835 comparisons against UNKNOWN.
1836 * sm.h (sm_context::clear_all_per_svalue_state): New.
1837
1838 2023-12-06 David Malcolm <[email protected]>
1839
1840 * engine.cc (dump_analyzer_json): Use
1841 flag_diagnostics_json_formatting.
1842
1843 2023-12-01 David Malcolm <[email protected]>
1844
1845 * analyzer.h (class saved_diagnostic): New forward decl.
1846 * bounds-checking.cc: Update for changes to
1847 pending_diagnostic::emit.
1848 * call-details.cc: Likewise.
1849 * diagnostic-manager.cc: Include "diagnostic-format-sarif.h".
1850 (saved_diagnostic::maybe_add_sarif_properties): New.
1851 (class pending_diagnostic_metadata): New.
1852 (diagnostic_manager::emit_saved_diagnostic): Create a
1853 pending_diagnostic_metadata and a diagnostic_emission_context.
1854 Pass the latter to the pending_diagnostic::emit vfunc.
1855 * diagnostic-manager.h
1856 (saved_diagnostic::maybe_add_sarif_properties): New decl.
1857 * engine.cc: Update for changes to pending_diagnostic::emit.
1858 * infinite-loop.cc: Likewise.
1859 * infinite-recursion.cc: Likewise.
1860 * kf-analyzer.cc: Likewise.
1861 * kf.cc: Likewise.
1862 * pending-diagnostic.cc
1863 (diagnostic_emission_context::get_pending_diagnostic): New.
1864 (diagnostic_emission_context::warn): New.
1865 (diagnostic_emission_context::inform): New.
1866 * pending-diagnostic.h (class diagnostic_emission_context): New.
1867 (pending_diagnostic::emit): Update params.
1868 (pending_diagnostic::maybe_add_sarif_properties): New vfunc.
1869 * region.cc: Don't include "diagnostic-metadata.h".
1870 * region-model.cc: Include "diagnostic-format-sarif.h". Update
1871 for changes to pending_diagnostic::emit.
1872 (exposure_through_uninit_copy::maybe_add_sarif_properties): New.
1873 * sm-fd.cc: Update for changes to pending_diagnostic::emit.
1874 * sm-file.cc: Likewise.
1875 * sm-malloc.cc: Likewise.
1876 * sm-pattern-test.cc: Likewise.
1877 * sm-sensitive.cc: Likewise.
1878 * sm-signal.cc: Likewise.
1879 * sm-taint.cc: Likewise.
1880 * store.cc: Don't include "diagnostic-metadata.h".
1881 * varargs.cc: Update for changes to pending_diagnostic::emit.
1882
1883 2023-11-19 David Malcolm <[email protected]>
1884
1885 * analyzer.h: Include "rich-location.h".
1886
1887 2023-11-19 David Malcolm <[email protected]>
1888
1889 PR analyzer/107573
1890 * analyzer.h (register_known_functions): Add region_model_manager
1891 param.
1892 * analyzer.opt (Wanalyzer-undefined-behavior-strtok): New.
1893 * call-summary.cc
1894 (call_summary_replay::convert_region_from_summary_1): Handle
1895 RK_PRIVATE.
1896 * engine.cc (impl_run_checkers): Pass model manager to
1897 register_known_functions.
1898 * kf.cc (class undefined_function_behavior): New.
1899 (class kf_strtok): New.
1900 (register_known_functions): Add region_model_manager param.
1901 Use it to register "strtok".
1902 * region-model-manager.cc
1903 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
1904 param.
1905 * region-model-manager.h
1906 (region_model_manager::get_or_create_conjured_svalue): Add "idx"
1907 param.
1908 (region_model_manager::get_root_region): New accessor.
1909 * region-model.cc (region_model::scan_for_null_terminator): Handle
1910 "expr" being null.
1911 (region_model::get_representative_path_var_1): Handle RK_PRIVATE.
1912 * region-model.h (region_model::called_from_main_p): Make public.
1913 * region.cc (region::get_memory_space): Handle RK_PRIVATE.
1914 (region::can_have_initial_svalue_p): Handle MEMSPACE_PRIVATE.
1915 (private_region::dump_to_pp): New.
1916 * region.h (MEMSPACE_PRIVATE): New.
1917 (RK_PRIVATE): New.
1918 (class private_region): New.
1919 (is_a_helper <const private_region *>::test): New.
1920 * store.cc (store::replay_call_summary_cluster): Handle
1921 RK_PRIVATE.
1922 * svalue.h (struct conjured_svalue::key_t): Add "idx" param to
1923 ctor and "m_idx" field.
1924 (class conjured_svalue::conjured_svalue): Likewise.
1925
1926 2023-11-18 David Malcolm <[email protected]>
1927
1928 PR analyzer/106147
1929 * analyzer.opt (Wanalyzer-infinite-loop): New option.
1930 (fdump-analyzer-infinite-loop): New option.
1931 * checker-event.h (start_cfg_edge_event::get_desc): Drop "final".
1932 (start_cfg_edge_event::maybe_describe_condition): Convert from
1933 private to protected.
1934 * checker-path.h (checker_path::get_logger): New.
1935 * diagnostic-manager.cc (process_worklist_item): Update for
1936 new context param of maybe_update_for_edge.
1937 * engine.cc
1938 (impl_region_model_context::impl_region_model_context): Add
1939 out_could_have_done_work param to both ctors and use it to
1940 initialize mm_out_could_have_done_work.
1941 (impl_region_model_context::maybe_did_work): New vfunc
1942 implementation.
1943 (exploded_node::on_stmt): Add out_could_have_done_work param and
1944 pass to ctxt ctor.
1945 (exploded_node::on_stmt_pre): Treat setjmp and longjmp as "doing
1946 work".
1947 (exploded_node::on_longjmp): Likewise.
1948 (exploded_edge::exploded_edge): Add "could_do_work" param and use
1949 it to initialize m_could_do_work_p.
1950 (exploded_edge::dump_dot_label): Add result of could_do_work_p.
1951 (exploded_graph::add_function_entry): Mark edge as doing no work.
1952 (exploded_graph::add_edge): Add "could_do_work" param and pass to
1953 exploded_edge ctor.
1954 (add_tainted_args_callback): Treat as doing no work.
1955 (exploded_graph::process_worklist): Likewise when merging nodes.
1956 (maybe_process_run_of_before_supernode_enodes::item): Likewise.
1957 (exploded_graph::maybe_create_dynamic_call): Likewise.
1958 (exploded_graph::process_node): Likewise for phi nodes.
1959 Pass in a "could_have_done_work" bool when handling stmts and use
1960 when creating edges. Assume work is done at bifurcation.
1961 (exploded_path::feasible_p): Update for new context param of
1962 maybe_update_for_edge.
1963 (feasibility_state::feasibility_state): New ctor.
1964 (feasibility_state::operator=): New.
1965 (feasibility_state::maybe_update_for_edge): Add ctxt param and use
1966 it. Fix missing newline when logging state.
1967 (impl_run_checkers): Call exploded_graph::detect_infinite_loops.
1968 * exploded-graph.h
1969 (impl_region_model_context::impl_region_model_context): Add
1970 out_could_have_done_work param to both ctors.
1971 (impl_region_model_context::maybe_did_work): New decl.
1972 (impl_region_model_context::checking_for_infinite_loop_p): New.
1973 (impl_region_model_context::on_unusable_in_infinite_loop): New.
1974 (impl_region_model_context::m_out_could_have_done_work): New
1975 field.
1976 (exploded_node::on_stmt): Add "out_could_have_done_work" param.
1977 (exploded_edge::exploded_edge): Add "could_do_work" param.
1978 (exploded_edge::could_do_work_p): New accessor.
1979 (exploded_edge::m_could_do_work_p): New field.
1980 (exploded_graph::add_edge): Add "could_do_work" param.
1981 (exploded_graph::detect_infinite_loops): New decl.
1982 (feasibility_state::feasibility_state): New ctor.
1983 (feasibility_state::operator=): New decl.
1984 (feasibility_state::maybe_update_for_edge): Add ctxt param.
1985 * infinite-loop.cc: New file.
1986 * program-state.cc (program_state::on_edge): Log the rejected
1987 constraint when region_model::maybe_update_for_edge fails.
1988 * region-model.cc (region_model::on_assignment): Treat any writes
1989 other than to the stack as "doing work".
1990 (region_model::on_stmt_pre): Treat all asm stmts as "doing work".
1991 (region_model::on_call_post): Likewise for all calls to functions
1992 with unknown side effects.
1993 (region_model::handle_phi): Add svals_changing_meaning param.
1994 Mark widening svalue in phi nodes as changing meaning.
1995 (unusable_in_infinite_loop_constraint_p): New.
1996 (region_model::add_constraint): If we're checking for an infinite
1997 loop, bail out on unusable svalues, or if we don't have a definite
1998 true/false for the constraint.
1999 (region_model::update_for_phis): Gather all svalues changing
2000 meaning in phi nodes, and purge constraints involving them.
2001 (region_model::replay_call_summary): Treat all call summaries as
2002 doing work.
2003 (region_model::can_merge_with_p): Purge constraints involving
2004 svalues that change meaning.
2005 (model_merger::on_widening_reuse): New.
2006 (test_iteration_1): Likewise.
2007 (selftest::test_iteration_1): Remove assertion that model6 "knows"
2008 that i < 157.
2009 * region-model.h (region_model::handle_phi): Add
2010 svals_changing_meaning param
2011 (region_model_context::maybe_did_work): New pure virtual func.
2012 (region_model_context::checking_for_infinite_loop_p): Likewise.
2013 (region_model_context::on_unusable_in_infinite_loop): Likewise.
2014 (noop_region_model_context::maybe_did_work): Implement.
2015 (noop_region_model_context::checking_for_infinite_loop_p):
2016 Likewise.
2017 (noop_region_model_context::on_unusable_in_infinite_loop):
2018 Likewise.
2019 (region_model_context_decorator::maybe_did_work): Implement.
2020 (region_model_context_decorator::checking_for_infinite_loop_p):
2021 Likewise.
2022 (region_model_context_decorator::on_unusable_in_infinite_loop):
2023 Likewise.
2024 (model_merger::on_widening_reuse): New decl.
2025 (model_merger::m_svals_changing_meaning): New field.
2026 * sm-signal.cc (register_signal_handler::impl_transition): Assume
2027 the edge "does work".
2028 * supergraph.cc (supernode::get_start_location): Use CFG edge's
2029 goto_locus if available.
2030 (supernode::get_end_location): Likewise.
2031 (cfg_superedge::dump_label_to_pp): Dump edges with a "goto_locus"
2032 * supergraph.h (cfg_superedge::get_goto_locus): New.
2033 * svalue.cc (svalue::can_merge_p): Call on_widening_reuse for
2034 widening values.
2035 (involvement_visitor::visit_widening_svalue): New.
2036 (svalue::involves_p): Update assertion to allow widening svalues.
2037
2038 2023-11-14 David Malcolm <[email protected]>
2039
2040 PR analyzer/103533
2041 * sm-taint.cc: Remove "experimental" from comment.
2042 * sm.cc (make_checkers): Always add taint state machine.
2043
2044 2023-11-04 David Malcolm <[email protected]>
2045
2046 * bounds-checking.cc: Update for changes to diagnostic_context.
2047
2048 2023-11-02 David Malcolm <[email protected]>
2049
2050 PR analyzer/112317
2051 * access-diagram.cc (class x_aligned_x_ruler_widget): Eliminate
2052 unused field "m_col_widths".
2053 (access_diagram_impl::add_valid_vs_invalid_ruler): Update for
2054 above change.
2055 * region-model.cc
2056 (check_one_function_attr_null_terminated_string_arg): Remove
2057 unused variables "cd_unchecked", "strlen_sval", and
2058 "limited_sval".
2059 * region-model.h (region_model_context_decorator::warn): Add
2060 missing "override".
2061
2062 2023-10-31 David Malcolm <[email protected]>
2063
2064 * record-layout.cc: New file, based on material in region-model.cc.
2065 * record-layout.h: Likewise.
2066 * region-model.cc: Include "analyzer/record-layout.h".
2067 (class record_layout): Move to record-layout.cc and .h
2068
2069 2023-10-26 David Malcolm <[email protected]>
2070
2071 * region-model.cc
2072 (region_model::check_external_function_for_access_attr): Split
2073 out, replacing with...
2074 (region_model::check_function_attr_access): ...this new function
2075 and...
2076 (region_model::check_function_attrs): ...this new function.
2077 (region_model::check_one_function_attr_null_terminated_string_arg):
2078 New.
2079 (region_model::check_function_attr_null_terminated_string_arg):
2080 New.
2081 (region_model::handle_unrecognized_call): Update for renaming of
2082 check_external_function_for_access_attr to check_function_attrs.
2083 (region_model::check_for_null_terminated_string_arg): Add return
2084 value to one overload. Make both overloads const.
2085 * region-model.h: Include "stringpool.h" and "attribs.h".
2086 (region_model::check_for_null_terminated_string_arg): Add return
2087 value to one overload. Make both overloads const.
2088 (region_model::check_external_function_for_access_attr): Delete
2089 decl.
2090 (region_model::check_function_attr_access): New decl.
2091 (region_model::check_function_attr_null_terminated_string_arg):
2092 New decl.
2093 (region_model::check_one_function_attr_null_terminated_string_arg):
2094 New decl.
2095 (region_model::check_function_attrs): New decl.
2096
2097 2023-10-09 David Malcolm <[email protected]>
2098
2099 * access-diagram.cc (boundaries::add): Explicitly state
2100 "boundaries::" scope for "kind" enum.
2101
2102 2023-10-08 David Malcolm <[email protected]>
2103
2104 PR analyzer/111155
2105 * access-diagram.cc (boundaries::boundaries): Add logger param
2106 (boundaries::add): Add logging.
2107 (boundaries::get_hard_boundaries_in_range): New.
2108 (boundaries::m_logger): New field.
2109 (boundaries::get_table_x_for_offset): Make public.
2110 (class svalue_spatial_item): New.
2111 (class compound_svalue_spatial_item): New.
2112 (add_ellipsis_to_gaps): New.
2113 (valid_region_spatial_item::valid_region_spatial_item): Add theme
2114 param. Initialize m_boundaries, m_existing_sval, and
2115 m_existing_sval_spatial_item.
2116 (valid_region_spatial_item::add_boundaries): Set m_boundaries.
2117 Add boundaries for any m_existing_sval_spatial_item.
2118 (valid_region_spatial_item::add_array_elements_to_table): Rewrite
2119 creation of min/max index in terms of
2120 maybe_add_array_index_to_table. Rewrite ellipsis code using
2121 add_ellipsis_to_gaps. Add index values for any hard boundaries
2122 within the valid region.
2123 (valid_region_spatial_item::maybe_add_array_index_to_table): New,
2124 based on code formerly in add_array_elements_to_table.
2125 (valid_region_spatial_item::make_table): Make use of
2126 m_existing_sval_spatial_item, if any.
2127 (valid_region_spatial_item::m_boundaries): New field.
2128 (valid_region_spatial_item::m_existing_sval): New field.
2129 (valid_region_spatial_item::m_existing_sval_spatial_item): New
2130 field.
2131 (class svalue_spatial_item): Rename to...
2132 (class written_svalue_spatial_item): ...this.
2133 (class string_region_spatial_item): Rename to..
2134 (class string_literal_spatial_item): ...this. Add "kind".
2135 (string_literal_spatial_item::add_boundaries): Use m_kind to
2136 determine kind of boundary. Update for renaming of m_actual_bits
2137 to m_bits.
2138 (string_literal_spatial_item::make_table): Likewise. Support not
2139 displaying a row for byte indexes, and not displaying a row for
2140 the type.
2141 (string_literal_spatial_item::add_column_for_byte): Make byte index
2142 row optional.
2143 (svalue_spatial_item::make): Convert to...
2144 (make_written_svalue_spatial_item): ...this.
2145 (make_existing_svalue_spatial_item): New.
2146 (access_diagram_impl::access_diagram_impl): Pass theme to
2147 m_valid_region_spatial_item ctor. Update for renaming of
2148 m_svalue_spatial_item.
2149 (access_diagram_impl::find_boundaries): Pass logger to boundaries.
2150 Update for renaming of...
2151 (access_diagram_impl::m_svalue_spatial_item): Rename to...
2152 (access_diagram_impl::m_written_svalue_spatial_item): ...this.
2153
2154 2023-10-03 David Malcolm <[email protected]>
2155
2156 * analyzer-logging.cc (logger::log_va_partial): Use text_info
2157 ctor.
2158 * analyzer.cc (make_label_text): Likewise.
2159 (make_label_text_n): Likewise.
2160 * pending-diagnostic.cc (evdesc::event_desc::formatted_print):
2161 Likewise.
2162
2163 2023-10-02 David Malcolm <[email protected]>
2164
2165 * program-point.cc: Update for grouping of source printing fields
2166 within diagnostic_context.
2167
2168 2023-09-15 David Malcolm <[email protected]>
2169
2170 * analyzer.cc (get_stmt_location): Handle null stmt.
2171 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Copy
2172 m_loc from ploc.
2173 (saved_diagnostic::operator==): Compare m_loc.
2174 (saved_diagnostic::calc_best_epath): Only use m_stmt_finder if
2175 m_loc is unknown.
2176 (dedupe_key::dedupe_key): Initialize m_loc.
2177 (dedupe_key::operator==): Compare m_loc.
2178 (dedupe_key::get_location): Use m_loc if it's known.
2179 (dedupe_key::m_loc): New field.
2180 (diagnostic_manager::emit_saved_diagnostic): Only call
2181 get_emission_location if m_loc is unknown, preferring to use m_loc
2182 if it's available.
2183 * diagnostic-manager.h (saved_diagnostic::m_loc): New field.
2184 (pending_location::pending_location): Initialize m_loc. Add
2185 overload taking a location_t rather than a stmt/stmt_finder.
2186 (pending_location::m_loc): New field.
2187
2188 2023-09-15 David Malcolm <[email protected]>
2189
2190 * analyzer.h (struct pending_location): New forward decl.
2191 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
2192 Replace params "enode", "snode", "stmt", and "stmt_finder" with
2193 "ploc".
2194 (diagnostic_manager::add_diagnostic): Likewise for both overloads.
2195 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
2196 Likewise.
2197 (struct pending_location): New.
2198 (diagnostic_manager::add_diagnostic): Replace params "enode",
2199 "snode", "stmt", and "stmt_finder" with "ploc".
2200 * engine.cc (impl_region_model_context::warn): Update call to
2201 add_diagnostic for above change.
2202 (impl_sm_context::warn): Likewise.
2203 (impl_region_model_context::on_state_leak): Likewise.
2204 * infinite-recursion.cc
2205 (exploded_graph::detect_infinite_recursion): Likewise.
2206
2207 2023-09-15 David Malcolm <[email protected]>
2208
2209 * region-model.cc (region_model::get_gassign_result): Handle
2210 volatile ops by using a conjured_svalue.
2211
2212 2023-09-14 David Malcolm <[email protected]>
2213
2214 * checker-event.h (checker_event::get_thread_id): New.
2215 * checker-path.h (class checker_path): Implement thread-related
2216 vfuncs via a single simple_diagnostic_thread instance named
2217 "main".
2218
2219 2023-09-14 David Malcolm <[email protected]>
2220
2221 * diagnostic-manager.cc (compatible_epath_p): Fix missing return.
2222
2223 2023-09-14 David Malcolm <[email protected]>
2224
2225 * diagnostic-manager.cc (process_worklist_item): Use
2226 std::unique_ptr rather than plain rejected_constraint *.
2227 * engine.cc (exploded_path::feasible_p): Likewise.
2228 (feasibility_state::maybe_update_for_edge): Likewise.
2229 * exploded-graph.h (feasibility_problem::feasibility_problem):
2230 Likewise.
2231 (feasibility_problem::~feasibility_problem): Delete.
2232 (feasibility_problem::m_rc): Use std::unique_ptr.
2233 (feasibility_state::maybe_update_for_edge): Likewise.
2234 * feasible-graph.cc (feasible_graph::add_feasibility_problem):
2235 Likewise.
2236 * feasible-graph.h (class infeasible_node): Likewise.
2237 (feasible_graph::add_feasibility_problem): Likewise.
2238 * region-model.cc (region_model::add_constraint): Likewise.
2239 (region_model::maybe_update_for_edge): Likewise.
2240 (region_model::apply_constraints_for_gcond): Likewise.
2241 (region_model::apply_constraints_for_gswitch): Likewise.
2242 (region_model::apply_constraints_for_exception): Likewise.
2243 * region-model.h (class region_model): Likewise for decls.
2244
2245 2023-09-09 benjamin priour <[email protected]>
2246
2247 PR analyzer/96395
2248 * region-model.cc
2249 (region_model::add_constraints_from_binop): binop_svalues around
2250 LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR are now unwrapped.
2251
2252 2023-09-07 David Malcolm <[email protected]>
2253
2254 PR analyzer/110529
2255 * program-point.cc (program_point::on_edge): Don't reject
2256 EDGE_ABNORMAL for computed gotos.
2257 * region-model.cc (region_model::maybe_update_for_edge): Handle
2258 computed goto statements.
2259 (region_model::apply_constraints_for_ggoto): New.
2260 * region-model.h (region_model::apply_constraints_for_ggoto): New decl.
2261 * supergraph.cc (supernode::get_label): New.
2262 * supergraph.h (supernode::get_label): New decl.
2263
2264 2023-09-07 benjamin priour <[email protected]>
2265 David Malcolm <[email protected]>
2266
2267 PR analyzer/110830
2268 * diagnostic-manager.cc
2269 (compatible_epaths_p): New function.
2270 (saved_diagnostic::supercedes_p): Now calls the above
2271 to determine if the diagnostics do overlap and the superseding
2272 may proceed.
2273
2274 2023-09-07 David Malcolm <[email protected]>
2275
2276 * region-model.h: fix -Wunused-parameter warnings
2277
2278 2023-09-06 David Malcolm <[email protected]>
2279
2280 PR analyzer/105899
2281 * kf.cc (class kf_strstr): New.
2282 (kf_strstr::impl_call_post): New.
2283 (register_known_functions): Register it.
2284
2285 2023-09-06 David Malcolm <[email protected]>
2286
2287 PR analyzer/105899
2288 * kf.cc (class kf_strncpy): New.
2289 (kf_strncpy::impl_call_post): New.
2290 (register_known_functions): Register it.
2291 * region-model.cc (region_model::read_bytes): Handle unknown
2292 number of bytes.
2293
2294 2023-09-06 David Malcolm <[email protected]>
2295
2296 * kf.cc (kf_calloc::impl_call_pre): Pass ctxt to zero_fill_region.
2297 (kf_memset::impl_call_pre): Move responsibility for calling
2298 check_region_for_write to fill_region.
2299 * region-model.cc (region_model::on_assignment): Pass ctxt to
2300 zero_fill_region.
2301 (region_model::fill_region): Add "ctxt" param, using it to call
2302 check_region_for_write.
2303 (region_model::zero_fill_region): Likewise.
2304 * region-model.h (region_model::fill_region): Add "ctxt" param.
2305 (region_model::zero_fill_region): Likewise.
2306
2307 2023-09-01 benjamin priour <[email protected]>
2308
2309 PR analyzer/105948
2310 PR analyzer/94355
2311 * analyzer.h (is_placement_new_p): New declaration.
2312 * call-details.cc
2313 (call_details::deref_ptr_arg): New function.
2314 Dereference the argument at given index if possible.
2315 * call-details.h: Declaration of the above function.
2316 * kf-lang-cp.cc (is_placement_new_p): Returns true if the gcall
2317 is recognized as a placement new.
2318 (kf_operator_delete::impl_call_post): Unbinding a region and its
2319 descendents now poisons with POISON_KIND_DELETED.
2320 (register_known_functions_lang_cp): Known function "operator
2321 delete" is now registered only once independently of its number of
2322 arguments.
2323 * region-model.cc (region_model::eval_condition): Now
2324 recursively calls itself if any of the operand is wrapped in a
2325 cast.
2326 * sm-malloc.cc (malloc_state_machine::on_stmt):
2327 Add placement new recognition.
2328 * svalue.cc (poison_kind_to_str): Wording for the new PK.
2329 * svalue.h (enum poison_kind): Add value POISON_KIND_DELETED.
2330
2331 2023-08-31 Francois-Xavier Coudert <[email protected]>
2332
2333 * kf.cc: Change spelling to macOS.
2334
2335 2023-08-30 Eric Feng <[email protected]>
2336
2337 PR analyzer/107646
2338 * engine.cc (impl_region_model_context::warn): New optional
2339 parameter.
2340 * exploded-graph.h (class impl_region_model_context): Likewise.
2341 * region-model.cc (region_model::pop_frame): New callback
2342 feature for region_model::pop_frame.
2343 * region-model.h (struct append_regions_cb_data): Likewise.
2344 (class region_model): Likewise.
2345 (class region_model_context): New optional parameter.
2346 (class region_model_context_decorator): Likewise.
2347
2348 2023-08-30 Francois-Xavier Coudert <[email protected]>
2349
2350 * region-model.cc: Define INCLUDE_ALGORITHM.
2351
2352 2023-08-29 David Malcolm <[email protected]>
2353
2354 PR analyzer/99860
2355 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
2356 selftest::analyzer_ranges_cc_tests.
2357 * analyzer-selftests.h (selftest::run_analyzer_selftests): New
2358 decl.
2359 * analyzer.opt (Wanalyzer-overlapping-buffers): New option.
2360 * call-details.cc: Include "analyzer/ranges.h" and "make-unique.h".
2361 (class overlapping_buffers): New.
2362 (call_details::complain_about_overlap): New.
2363 * call-details.h (call_details::complain_about_overlap): New decl.
2364 * kf.cc (kf_memcpy_memmove::impl_call_pre): Call
2365 cd.complain_about_overlap for memcpy and memcpy_chk.
2366 (kf_strcat::impl_call_pre): Call cd.complain_about_overlap.
2367 (kf_strcpy::impl_call_pre): Likewise.
2368 * ranges.cc: New file.
2369 * ranges.h: New file.
2370
2371 2023-08-29 David Malcolm <[email protected]>
2372
2373 PR analyzer/105899
2374 * kf.cc (kf_strdup::impl_call_pre): Set size of
2375 dynamically-allocated buffer. Simulate copying the string from
2376 the source region to the new buffer.
2377
2378 2023-08-27 benjamin priour <[email protected]>
2379
2380 PR analyzer/96395
2381 * analyzer.h (class known_function): Add virtual casts
2382 to builtin_known_function.
2383 (class builtin_known_function): New subclass of known_function
2384 for builtins.
2385 * kf.cc (class kf_alloca): Now derived from
2386 builtin_known_function.
2387 (class kf_calloc): Likewise.
2388 (class kf_free): Likewise.
2389 (class kf_malloc): Likewise.
2390 (class kf_memcpy_memmove): Likewise.
2391 (class kf_memset): Likewise.
2392 (class kf_realloc): Likewise.
2393 (class kf_strchr): Likewise.
2394 (class kf_sprintf): Likewise.
2395 (class kf_strcat): Likewise.
2396 (class kf_strcpy): Likewise.
2397 (class kf_strdup): Likewise.
2398 (class kf_strlen): Likewise.
2399 (class kf_strndup): Likewise.
2400 (register_known_functions): Builtins are now registered as
2401 known_functions by name rather than by their BUILTIN_CODE.
2402 * known-function-manager.cc (get_normal_builtin): New overload.
2403 * known-function-manager.h: New overload declaration.
2404 * region-model.cc (region_model::get_builtin_kf): New function.
2405 * region-model.h (class region_model): Add declaration of
2406 get_builtin_kf.
2407 * sm-fd.cc: For called recognized as builtins, use the
2408 attributes of that builtin as defined in gcc/builtins.def
2409 rather than the user's.
2410 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
2411
2412 2023-08-25 David Malcolm <[email protected]>
2413
2414 * access-diagram.cc (class string_region_spatial_item): Remove
2415 assumption that the string is written to the start of the cluster.
2416
2417 2023-08-24 David Malcolm <[email protected]>
2418
2419 PR analyzer/105899
2420 * call-details.cc
2421 (call_details::check_for_null_terminated_string_arg): Split into
2422 overloads, one taking just an arg_idx, the other a new
2423 "include_terminator" param.
2424 * call-details.h: Likewise.
2425 * kf.cc (class kf_strcat): New.
2426 (kf_strcpy::impl_call_pre): Update for change to
2427 check_for_null_terminated_string_arg.
2428 (register_known_functions): Register kf_strcat.
2429 * region-model.cc
2430 (region_model::check_for_null_terminated_string_arg): Split into
2431 overloads, one taking just an arg_idx, the other a new
2432 "include_terminator" param. When returning an svalue, handle
2433 "include_terminator" being false by subtracting one.
2434 * region-model.h
2435 (region_model::check_for_null_terminated_string_arg): Split into
2436 overloads, one taking just an arg_idx, the other a new
2437 "include_terminator" param.
2438
2439 2023-08-24 David Malcolm <[email protected]>
2440
2441 PR analyzer/105899
2442 * region-model.cc (fragment::has_null_terminator): Handle
2443 SK_BITS_WITHIN.
2444
2445 2023-08-24 David Malcolm <[email protected]>
2446
2447 PR analyzer/105899
2448 * region-model-manager.cc
2449 (region_model_manager::get_or_create_initial_value): Simplify
2450 INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) to
2451 CONSTANT_SVAL(STRING[N]).
2452
2453 2023-08-24 David Malcolm <[email protected]>
2454
2455 PR analyzer/105899
2456 * region-model.cc (fragment::has_null_terminator): Move STRING_CST
2457 handling to fragment::string_cst_has_null_terminator; also use it to
2458 handle INIT_VAL(STRING_REG).
2459 (fragment::string_cst_has_null_terminator): New, from above.
2460
2461 2023-08-24 David Malcolm <[email protected]>
2462
2463 * kf.cc (kf_memcpy_memmove::impl_call_pre): Reimplement using
2464 region_model::copy_bytes.
2465 * region-model.cc (region_model::read_bytes): New.
2466 (region_model::copy_bytes): New.
2467 * region-model.h (region_model::read_bytes): New decl.
2468 (region_model::copy_bytes): New decl.
2469
2470 2023-08-24 David Malcolm <[email protected]>
2471
2472 PR analyzer/105899
2473 * region-model.cc (region_model::get_string_size): Delete both.
2474 * region-model.h (region_model::get_string_size): Delete both
2475 decls.
2476
2477 2023-08-24 David Malcolm <[email protected]>
2478
2479 PR analyzer/105899
2480 * kf.cc (kf_strcpy::impl_call_pre): Reimplement using
2481 check_for_null_terminated_string_arg.
2482 * region-model.cc (region_model::get_store_bytes): Shortcut
2483 reading all of a string_region.
2484 (region_model::scan_for_null_terminator): Use get_store_value for
2485 the bytes rather than "unknown" when returning an unknown length.
2486 (region_model::write_bytes): New.
2487 * region-model.h (region_model::write_bytes): New decl.
2488
2489 2023-08-24 David Malcolm <[email protected]>
2490
2491 PR analyzer/105899
2492 * region-model.cc (iterable_cluster::iterable_cluster): Add
2493 symbolic binding keys to m_symbolic_bindings.
2494 (iterable_cluster::has_symbolic_bindings_p): New.
2495 (iterable_cluster::m_symbolic_bindings): New field.
2496 (region_model::scan_for_null_terminator): Treat clusters with
2497 symbolic bindings as having unknown strlen.
2498
2499 2023-08-24 David Malcolm <[email protected]>
2500
2501 * engine.cc (impl_path_context::impl_path_context): Add logger
2502 param.
2503 (impl_path_context::bifurcate): Add log message.
2504 (impl_path_context::terminate_path): Likewise.
2505 (impl_path_context::m_logger): New field.
2506 (exploded_graph::process_node): Pass logger to path_ctxt ctor.
2507
2508 2023-08-22 David Malcolm <[email protected]>
2509
2510 PR analyzer/105899
2511 * kf-analyzer.cc (class kf_analyzer_get_strlen): Move to kf.cc.
2512 (register_known_analyzer_functions): Use make_kf_strlen.
2513 * kf.cc (class kf_strlen::impl_call_pre): Replace with
2514 implementation of kf_analyzer_get_strlen from kf-analyzer.cc.
2515 Handle "UNKNOWN" return from check_for_null_terminated_string_arg
2516 by falling back to a conjured svalue.
2517 (make_kf_strlen): New.
2518 (register_known_functions): Use make_kf_strlen.
2519 * known-function-manager.h (make_kf_strlen): New decl.
2520
2521 2023-08-22 David Malcolm <[email protected]>
2522
2523 PR analyzer/105899
2524 * call-details.cc (call_details::call_details): New ctor.
2525 * call-details.h (call_details::call_details): New ctor decl.
2526 (struct call_arg_details): Move here from region-model.cc.
2527 * region-model.cc (region_model::check_call_format_attr): New.
2528 (region_model::check_call_args): Call it.
2529 (struct call_arg_details): Move it to call-details.h.
2530 * region-model.h (region_model::check_call_format_attr): New decl.
2531
2532 2023-08-22 David Malcolm <[email protected]>
2533
2534 * kf.cc (class kf_fopen): New.
2535 (register_known_functions): Register it.
2536
2537 2023-08-22 David Malcolm <[email protected]>
2538
2539 PR analyzer/105899
2540 * analyzer.opt (Wanalyzer-unterminated-string): Delete.
2541 * call-details.cc
2542 (call_details::check_for_null_terminated_string_arg): Convert
2543 return type from void to const svalue *. Add param "out_sval".
2544 * call-details.h
2545 (call_details::check_for_null_terminated_string_arg): Likewise.
2546 * kf-analyzer.cc (kf_analyzer_get_strlen::impl_call_pre): Wire up
2547 to result of check_for_null_terminated_string_arg.
2548 * region-model.cc (get_strlen): Delete.
2549 (class unterminated_string_arg): Delete.
2550 (struct fragment): New.
2551 (class iterable_cluster): New.
2552 (region_model::get_store_bytes): New.
2553 (get_tree_for_byte_offset): New.
2554 (region_model::scan_for_null_terminator): New.
2555 (region_model::check_for_null_terminated_string_arg): Convert
2556 return type from void to const svalue *. Add param "out_sval".
2557 Reimplement in terms of scan_for_null_terminator, dropping the
2558 special-case for -Wanalyzer-unterminated-string.
2559 * region-model.h (region_model::get_store_bytes): New decl.
2560 (region_model::scan_for_null_terminator): New decl.
2561 (region_model::check_for_null_terminated_string_arg): Convert
2562 return type from void to const svalue *. Add param "out_sval".
2563 * store.cc (concrete_binding::get_byte_range): New.
2564 * store.h (concrete_binding::get_byte_range): New decl.
2565 (store_manager::get_concrete_binding): New overload.
2566
2567 2023-08-22 David Malcolm <[email protected]>
2568
2569 * region-model.cc (region_model_context_decorator::add_event):
2570 Handle m_inner being NULL.
2571 * region-model.h (class region_model_context_decorator): Likewise.
2572 (annotating_context::warn): Likewise.
2573
2574 2023-08-22 David Malcolm <[email protected]>
2575
2576 * diagnostic-manager.cc (saved_diagnostic::add_event): New.
2577 (saved_diagnostic::add_any_saved_events): New.
2578 (diagnostic_manager::add_event): New.
2579 (dedupe_winners::emit_best): New.
2580 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
2581 non-const. Call saved_diagnostic::add_any_saved_events.
2582 * diagnostic-manager.h (saved_diagnostic::add_event): New decl.
2583 (saved_diagnostic::add_any_saved_events): New decl.
2584 (saved_diagnostic::m_saved_events): New field.
2585 (diagnostic_manager::add_event): New decl.
2586 (diagnostic_manager::emit_saved_diagnostic): Make "sd" param
2587 non-const.
2588 * engine.cc (impl_region_model_context::add_event): New.
2589 * exploded-graph.h (impl_region_model_context::add_event): New decl.
2590 * region-model.cc
2591 (noop_region_model_context::add_event): New.
2592 (region_model_context_decorator::add_event): New.
2593 * region-model.h (region_model_context::add_event): New vfunc.
2594 (noop_region_model_context::add_event): New decl.
2595 (region_model_context_decorator::add_event): New decl.
2596
2597 2023-08-22 David Malcolm <[email protected]>
2598
2599 * region-model.cc
2600 (class check_external_function_for_access_attr::annotating_ctxt):
2601 Convert to an annotating_context.
2602 * region-model.h (class note_adding_context): Rename to...
2603 (class annotating_context): ...this, updating the "warn" method.
2604 (note_adding_context::make_note): Replace with...
2605 (annotating_context::add_annotations): ...this.
2606
2607 2023-08-14 benjamin priour <[email protected]>
2608
2609 PR analyzer/110543
2610 * analyzer.opt: Add new option.
2611 * diagnostic-manager.cc
2612 (diagnostic_manager::prune_path): Call prune_system_headers.
2613 (prune_frame): New function that deletes all events in a frame.
2614 (diagnostic_manager::prune_system_headers): New function.
2615 * diagnostic-manager.h: Add prune_system_headers declaration.
2616
2617 2023-08-11 David Malcolm <[email protected]>
2618
2619 PR analyzer/105899
2620 * analyzer.opt (Wanalyzer-unterminated-string): New.
2621 * call-details.cc
2622 (call_details::check_for_null_terminated_string_arg): New.
2623 * call-details.h
2624 (call_details::check_for_null_terminated_string_arg): New decl.
2625 * kf-analyzer.cc (class kf_analyzer_get_strlen): New.
2626 (register_known_analyzer_functions): Register it.
2627 * kf.cc (kf_error::impl_call_pre): Check that format arg is a
2628 valid null-terminated string.
2629 (kf_putenv::impl_call_pre): Likewise for the sole param.
2630 (kf_strchr::impl_call_pre): Likewise for the first param.
2631 (kf_strcpy::impl_call_pre): Likewise for the second param.
2632 (kf_strdup::impl_call_pre): Likewise for the sole param.
2633 * region-model.cc (get_strlen): New.
2634 (struct call_arg_details): New.
2635 (inform_about_expected_null_terminated_string_arg): New.
2636 (class unterminated_string_arg): New.
2637 (region_model::check_for_null_terminated_string_arg): New.
2638 * region-model.h
2639 (region_model::check_for_null_terminated_string_arg): New decl.
2640
2641 2023-08-11 Eric Feng <[email protected]>
2642
2643 PR analyzer/107646
2644 * call-details.h: New function.
2645 * region-model.cc (region_model::get_or_create_region_for_heap_alloc):
2646 New optional parameters.
2647 * region-model.h (class region_model): New optional parameters.
2648 * sm-malloc.cc (on_realloc_with_move): New function.
2649 (region_model::transition_ptr_sval_non_null): New function.
2650
2651 2023-08-09 David Malcolm <[email protected]>
2652
2653 * analyzer.h (class pure_known_function_with_default_return): New
2654 subclass.
2655 * call-details.cc (const_fn_p): Move here from region-model.cc.
2656 (maybe_get_const_fn_result): Likewise.
2657 (get_result_size_in_bytes): Likewise.
2658 (call_details::set_any_lhs_with_defaults): New function, based on
2659 code in region_model::on_call_pre.
2660 * call-details.h (call_details::set_any_lhs_with_defaults): New
2661 decl.
2662 * diagnostic-manager.cc
2663 (diagnostic_manager::emit_saved_diagnostic): Log the index of the
2664 saved_diagnostic.
2665 * kf.cc (pure_known_function_with_default_return::impl_call_pre):
2666 New.
2667 (kf_memset::impl_call_pre): Set the LHS to the first param.
2668 (kf_putenv::impl_call_pre): Call cd.set_any_lhs_with_defaults.
2669 (kf_sprintf::impl_call_pre): Call cd.set_any_lhs_with_defaults.
2670 (class kf_stack_restore): Derive from
2671 pure_known_function_with_default_return.
2672 (class kf_stack_save): Likewise.
2673 (kf_strlen::impl_call_pre): Call cd.set_any_lhs_with_defaults.
2674 * region-model-reachability.cc (reachable_regions::handle_sval):
2675 Remove logic for symbolic regions for pointers.
2676 * region-model.cc (region_model::canonicalize): Remove purging of
2677 dynamic extents workaround for surplus values from
2678 region_model::on_call_pre's default LHS code.
2679 (const_fn_p): Move to call-details.cc.
2680 (maybe_get_const_fn_result): Likewise.
2681 (get_result_size_in_bytes): Likewise.
2682 (region_model::update_for_nonzero_return): Call
2683 cd.set_any_lhs_with_defaults.
2684 (region_model::on_call_pre): Remove the assignment to the LHS of a
2685 default return value, instead requiring all known_function
2686 implementations to write to any LHS of the call. Use
2687 cd.set_any_lhs_with_defaults on the non-kf paths.
2688 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Use
2689 cd.set_any_lhs_with_defaults when failing to get at fd state.
2690 (kf_bind::outcome_of_bind::update_model): Likewise.
2691 (kf_listen::outcome_of_listen::update_model): Likewise.
2692 (kf_accept::outcome_of_accept::update_model): Likewise.
2693 (kf_connect::outcome_of_connect::update_model): Likewise.
2694 (kf_read::impl_call_pre): Use cd.set_any_lhs_with_defaults.
2695 * sm-file.cc (class kf_stdio_output_fn): Derive from
2696 pure_known_function_with_default_return.
2697 (class kf_ferror): Likewise.
2698 (class kf_fileno): Likewise.
2699 (kf_fgets::impl_call_pre): Use cd.set_any_lhs_with_defaults.
2700 (kf_read::impl_call_pre): Likewise.
2701 (class kf_getc): Derive from
2702 pure_known_function_with_default_return.
2703 (class kf_getchar): Likewise.
2704 * varargs.cc (kf_va_arg::impl_call_pre): Use
2705 cd.set_any_lhs_with_defaults.
2706
2707 2023-08-04 David Malcolm <[email protected]>
2708
2709 PR analyzer/110426
2710 * bounds-checking.cc (region_model::check_region_bounds): Handle
2711 symbolic base regions.
2712 * call-details.cc: Include "stringpool.h" and "attribs.h".
2713 (call_details::lookup_function_attribute): New function.
2714 * call-details.h (call_details::lookup_function_attribute): New
2715 function decl.
2716 * region-model-manager.cc
2717 (region_model_manager::maybe_fold_binop): Add reference to
2718 PR analyzer/110902.
2719 * region-model-reachability.cc (reachable_regions::handle_sval):
2720 Add symbolic regions for pointers that are conjured svalues for
2721 the LHS of a stmt.
2722 * region-model.cc (region_model::canonicalize): Purge dynamic
2723 extents for regions that aren't referenced.
2724 (get_result_size_in_bytes): New function.
2725 (region_model::on_call_pre): Use get_result_size_in_bytes and
2726 potentially set the dynamic extents of the region pointed to by
2727 the return value.
2728 (region_model::deref_rvalue): Add param "add_nonnull_constraint"
2729 and use it to conditionalize adding the constraint.
2730 (pending_diagnostic_subclass::dubious_allocation_size): Add "stmt"
2731 param to both ctors and use it to initialize new "m_stmt" field.
2732 (pending_diagnostic_subclass::operator==): Use m_stmt; don't use
2733 m_lhs or m_rhs.
2734 (pending_diagnostic_subclass::m_stmt): New field.
2735 (region_model::check_region_size): Generalize to any kind of
2736 pointer svalue by using deref_rvalue rather than checking for
2737 region_svalue. Pass stmt to dubious_allocation_size ctor.
2738 * region-model.h (region_model::deref_rvalue): Add param
2739 "add_nonnull_constraint".
2740 * svalue.cc (conjured_svalue::lhs_value_p): New function.
2741 * svalue.h (conjured_svalue::lhs_value_p): New decl.
2742
2743 2023-08-04 David Malcolm <[email protected]>
2744
2745 * svalue.cc (region_svalue::dump_to_pp): Support NULL type.
2746 (constant_svalue::dump_to_pp): Likewise.
2747 (initial_svalue::dump_to_pp): Likewise.
2748 (conjured_svalue::dump_to_pp): Likewise. Fix missing print of the
2749 type.
2750
2751 2023-08-03 David Malcolm <[email protected]>
2752
2753 PR analyzer/110882
2754 * region.cc (int_size_in_bits): Fail on zero-sized types.
2755
2756 2023-08-02 Eric Feng <[email protected]>
2757
2758 PR analyzer/107646
2759 * analyzer-language.cc (run_callbacks): New function.
2760 (on_finish_translation_unit): New function.
2761 * analyzer-language.h (GCC_ANALYZER_LANGUAGE_H): New include.
2762 (class translation_unit): New vfuncs.
2763
2764 2023-07-26 David Malcolm <[email protected]>
2765
2766 PR analyzer/104940
2767 * region-model-manager.cc
2768 (region_model_manager::region_model_manager): Update for
2769 generalizing region ids to also cover svalues.
2770 (region_model_manager::get_or_create_constant_svalue): Likewise.
2771 (region_model_manager::get_or_create_unknown_svalue): Likewise.
2772 (region_model_manager::create_unique_svalue): Likewise.
2773 (region_model_manager::get_or_create_initial_value): Likewise.
2774 (region_model_manager::get_or_create_setjmp_svalue): Likewise.
2775 (region_model_manager::get_or_create_poisoned_svalue): Likewise.
2776 (region_model_manager::get_ptr_svalue): Likewise.
2777 (region_model_manager::get_or_create_unaryop): Likewise.
2778 (region_model_manager::get_or_create_binop): Likewise.
2779 (region_model_manager::get_or_create_sub_svalue): Likewise.
2780 (region_model_manager::get_or_create_repeated_svalue): Likewise.
2781 (region_model_manager::get_or_create_bits_within): Likewise.
2782 (region_model_manager::get_or_create_unmergeable): Likewise.
2783 (region_model_manager::get_or_create_widening_svalue): Likewise.
2784 (region_model_manager::get_or_create_compound_svalue): Likewise.
2785 (region_model_manager::get_or_create_conjured_svalue): Likewise.
2786 (region_model_manager::get_or_create_asm_output_svalue): Likewise.
2787 (region_model_manager::get_or_create_const_fn_result_svalue):
2788 Likewise.
2789 (region_model_manager::get_region_for_fndecl): Likewise.
2790 (region_model_manager::get_region_for_label): Likewise.
2791 (region_model_manager::get_region_for_global): Likewise.
2792 (region_model_manager::get_field_region): Likewise.
2793 (region_model_manager::get_element_region): Likewise.
2794 (region_model_manager::get_offset_region): Likewise.
2795 (region_model_manager::get_sized_region): Likewise.
2796 (region_model_manager::get_cast_region): Likewise.
2797 (region_model_manager::get_frame_region): Likewise.
2798 (region_model_manager::get_symbolic_region): Likewise.
2799 (region_model_manager::get_region_for_string): Likewise.
2800 (region_model_manager::get_bit_range): Likewise.
2801 (region_model_manager::get_var_arg_region): Likewise.
2802 (region_model_manager::get_region_for_unexpected_tree_code):
2803 Likewise.
2804 (region_model_manager::get_or_create_region_for_heap_alloc):
2805 Likewise.
2806 (region_model_manager::create_region_for_alloca): Likewise.
2807 (region_model_manager::log_stats): Likewise.
2808 * region-model-manager.h (region_model_manager::get_num_regions):
2809 Replace with...
2810 (region_model_manager::get_num_symbols): ...this.
2811 (region_model_manager::alloc_region_id): Replace with...
2812 (region_model_manager::alloc_symbol_id): ...this.
2813 (region_model_manager::m_next_region_id): Replace with...
2814 (region_model_manager::m_next_symbol_id): ...this.
2815 * region-model.cc (selftest::test_get_representative_tree): Update
2816 for generalizing region ids to also cover svalues.
2817 (selftest::test_binop_svalue_folding): Likewise.
2818 (selftest::test_state_merging): Likewise.
2819 * region.cc (region::cmp_ids): Delete, in favor of
2820 symbol::cmp_ids.
2821 (region::region): Update for introduction of symbol base class.
2822 (frame_region::get_region_for_local): Likewise.
2823 (root_region::root_region): Likewise.
2824 (symbolic_region::symbolic_region): Likewise.
2825 * region.h: Replace include of "analyzer/complexity.h" with
2826 "analyzer/symbol.h".
2827 (class region): Make a subclass of symbol.
2828 (region::get_id): Delete in favor of symbol::get_id.
2829 (region::cmp_ids): Delete in favor of symbol::cmp_ids.
2830 (region::get_complexity): Delete in favor of
2831 symbol::get_complexity.
2832 (region::region): Use symbol::id_t for "id" param.
2833 (region::m_complexity): Move field to symbol base class.
2834 (region::m_id): Likewise.
2835 (space_region::space_region): Use symbol::id_t for "id" param.
2836 (frame_region::frame_region): Likewise.
2837 (globals_region::globals_region): Likewise.
2838 (code_region::code_region): Likewise.
2839 (function_region::function_region): Likewise.
2840 (label_region::label_region): Likewise.
2841 (stack_region::stack_region): Likewise.
2842 (heap_region::heap_region): Likewise.
2843 (thread_local_region::thread_local_region): Likewise.
2844 (root_region::root_region): Likewise.
2845 (symbolic_region::symbolic_region): Likewise.
2846 (decl_region::decl_region): Likewise.
2847 (field_region::field_region): Likewise.
2848 (element_region::element_region): Likewise.
2849 (offset_region::offset_region): Likewise.
2850 (sized_region::sized_region): Likewise.
2851 (cast_region::cast_region): Likewise.
2852 (heap_allocated_region::heap_allocated_region): Likewise.
2853 (alloca_region::alloca_region): Likewise.
2854 (string_region::string_region): Likewise.
2855 (bit_range_region::bit_range_region): Likewise.
2856 (var_arg_region::var_arg_region): Likewise.
2857 (errno_region::errno_region): Likewise.
2858 (unknown_region::unknown_region): Likewise.
2859 * svalue.cc (sub_svalue::sub_svalue): Add symbol::id_t param.
2860 (repeated_svalue::repeated_svalue): Likewise.
2861 (bits_within_svalue::bits_within_svalue): Likewise.
2862 (compound_svalue::compound_svalue): Likewise.
2863 * svalue.h: Replace include of "analyzer/complexity.h" with
2864 "analyzer/symbol.h".
2865 (class svalue): Make a subclass of symbol.
2866 (svalue::get_complexity): Delete in favor of
2867 symbol::get_complexity.
2868 (svalue::svalue): Add symbol::id_t param. Update for new base
2869 class.
2870 (svalue::m_complexity): Delete in favor of
2871 symbol::m_complexity.
2872 (region_svalue::region_svalue): Add symbol::id_t param
2873 (constant_svalue::constant_svalue): Likewise.
2874 (unknown_svalue::unknown_svalue): Likewise.
2875 (poisoned_svalue::poisoned_svalue): Likewise.
2876 (setjmp_svalue::setjmp_svalue): Likewise.
2877 (initial_svalue::initial_svalue): Likewise.
2878 (unaryop_svalue::unaryop_svalue): Likewise.
2879 (binop_svalue::binop_svalue): Likewise.
2880 (sub_svalue::sub_svalue): Likewise.
2881 (repeated_svalue::repeated_svalue): Likewise.
2882 (bits_within_svalue::bits_within_svalue): Likewise.
2883 (unmergeable_svalue::unmergeable_svalue): Likewise.
2884 (placeholder_svalue::placeholder_svalue): Likewise.
2885 (widening_svalue::widening_svalue): Likewise.
2886 (compound_svalue::compound_svalue): Likewise.
2887 (conjured_svalue::conjured_svalue): Likewise.
2888 (asm_output_svalue::asm_output_svalue): Likewise.
2889 (const_fn_result_svalue::const_fn_result_svalue): Likewise.
2890 * symbol.cc: New file.
2891 * symbol.h: New file.
2892
2893 2023-07-21 David Malcolm <[email protected]>
2894
2895 PR analyzer/110455
2896 * region-model.cc (region_model::get_gassign_result): Only check
2897 for bad shift counts when dealing with an integral type.
2898
2899 2023-07-21 David Malcolm <[email protected]>
2900
2901 PR analyzer/110433
2902 PR middle-end/110612
2903 * access-diagram.cc (class spatial_item): Add virtual dtor.
2904
2905 2023-07-21 David Malcolm <[email protected]>
2906
2907 PR analyzer/110387
2908 * region.h (struct cast_region::key_t): Support "m_type" being
2909 null by using "m_original_region" for empty/deleted slots.
2910
2911 2023-07-19 David Malcolm <[email protected]>
2912
2913 PR analyzer/110700
2914 * region-model-manager.cc
2915 (region_model_manager::get_or_create_int_cst): Assert that we have
2916 an integral or pointer type.
2917 * sm-taint.cc (taint_state_machine::check_for_tainted_divisor):
2918 Don't check non-integral types.
2919
2920 2023-06-29 benjamin priour <[email protected]>
2921
2922 PR analyzer/110198
2923 * region-model-manager.cc
2924 (region_model_manager::get_or_create_initial_value): Take an
2925 optional boolean value to bypass poisoning checks
2926 * region-model-manager.h: Update declaration of the above function.
2927 * region-model.cc (region_model::get_store_value): No longer returns
2928 on OOB, but rather gives a boolean to get_or_create_initial_value.
2929 (region_model::check_region_access): Update docstring.
2930 (region_model::check_region_for_write): Update docstring.
2931
2932 2023-06-24 David Malcolm <[email protected]>
2933
2934 * access-diagram.cc: Add #define INCLUDE_VECTOR.
2935 * bounds-checking.cc: Likewise.
2936
2937 2023-06-22 David Malcolm <[email protected]>
2938
2939 PR analyzer/106626
2940 * access-diagram.cc: New file.
2941 * access-diagram.h: New file.
2942 * analyzer.h (class region_offset): Add default ctor.
2943 (region_offset::make_byte_offset): New decl.
2944 (region_offset::concrete_p): New.
2945 (region_offset::get_concrete_byte_offset): New.
2946 (region_offset::calc_symbolic_bit_offset): New decl.
2947 (region_offset::calc_symbolic_byte_offset): New decl.
2948 (region_offset::dump_to_pp): New decl.
2949 (region_offset::dump): New decl.
2950 (operator<, operator<=, operator>, operator>=): New decls for
2951 region_offset.
2952 * analyzer.opt
2953 (-param=analyzer-text-art-string-ellipsis-threshold=): New.
2954 (-param=analyzer-text-art-string-ellipsis-head-len=): New.
2955 (-param=analyzer-text-art-string-ellipsis-tail-len=): New.
2956 (-param=analyzer-text-art-ideal-canvas-width=): New.
2957 (fanalyzer-debug-text-art): New.
2958 * bounds-checking.cc: Include "intl.h", "diagnostic-diagram.h",
2959 and "analyzer/access-diagram.h".
2960 (class out_of_bounds::oob_region_creation_event_capacity): New.
2961 (out_of_bounds::out_of_bounds): Add "model" and "sval_hint"
2962 params.
2963 (out_of_bounds::mark_interesting_stuff): Use the base region.
2964 (out_of_bounds::add_region_creation_events): Use
2965 oob_region_creation_event_capacity.
2966 (out_of_bounds::get_dir): New pure vfunc.
2967 (out_of_bounds::maybe_show_notes): New.
2968 (out_of_bounds::maybe_show_diagram): New.
2969 (out_of_bounds::make_access_diagram): New.
2970 (out_of_bounds::m_model): New field.
2971 (out_of_bounds::m_sval_hint): New field.
2972 (out_of_bounds::m_region_creation_event_id): New field.
2973 (concrete_out_of_bounds::concrete_out_of_bounds): Update for new
2974 fields.
2975 (concrete_past_the_end::concrete_past_the_end): Likewise.
2976 (concrete_past_the_end::add_region_creation_events): Use
2977 oob_region_creation_event_capacity.
2978 (concrete_buffer_overflow::concrete_buffer_overflow): Update for
2979 new fields.
2980 (concrete_buffer_overflow::emit): Replace call to
2981 maybe_describe_array_bounds with maybe_show_notes.
2982 (concrete_buffer_overflow::get_dir): New.
2983 (concrete_buffer_over_read::concrete_buffer_over_read): Update for
2984 new fields.
2985 (concrete_buffer_over_read::emit): Replace call to
2986 maybe_describe_array_bounds with maybe_show_notes.
2987 (concrete_buffer_overflow::get_dir): New.
2988 (concrete_buffer_underwrite::concrete_buffer_underwrite): Update
2989 for new fields.
2990 (concrete_buffer_underwrite::emit): Replace call to
2991 maybe_describe_array_bounds with maybe_show_notes.
2992 (concrete_buffer_underwrite::get_dir): New.
2993 (concrete_buffer_under_read::concrete_buffer_under_read): Update
2994 for new fields.
2995 (concrete_buffer_under_read::emit): Replace call to
2996 maybe_describe_array_bounds with maybe_show_notes.
2997 (concrete_buffer_under_read::get_dir): New.
2998 (symbolic_past_the_end::symbolic_past_the_end): Update for new
2999 fields.
3000 (symbolic_buffer_overflow::symbolic_buffer_overflow): Likewise.
3001 (symbolic_buffer_overflow::emit): Call maybe_show_notes.
3002 (symbolic_buffer_overflow::get_dir): New.
3003 (symbolic_buffer_over_read::symbolic_buffer_over_read): Update for
3004 new fields.
3005 (symbolic_buffer_over_read::emit): Call maybe_show_notes.
3006 (symbolic_buffer_over_read::get_dir): New.
3007 (region_model::check_symbolic_bounds): Add "sval_hint" param. Pass
3008 it and sized_offset_reg to diagnostics.
3009 (region_model::check_region_bounds): Add "sval_hint" param, passing
3010 it to diagnostics.
3011 * diagnostic-manager.cc
3012 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
3013 pending_diagnostic::emit.
3014 * engine.cc: Add logger param to pending_diagnostic::emit
3015 implementations.
3016 * infinite-recursion.cc: Likewise.
3017 * kf-analyzer.cc: Likewise.
3018 * kf.cc: Likewise. Add nullptr for new param of
3019 check_region_for_write.
3020 * pending-diagnostic.h: Likewise in decl.
3021 * region-model-manager.cc
3022 (region_model_manager::get_or_create_int_cst): Convert param from
3023 poly_int64 to const poly_wide_int_ref &.
3024 (region_model_manager::maybe_fold_binop): Support type being NULL
3025 when checking for floating-point types.
3026 Check for (X + Y) - X => Y. Be less strict about types when folding
3027 associative ops. Check for (X + Y) * CST => (X * CST) + (Y * CST).
3028 * region-model-manager.h
3029 (region_model_manager::get_or_create_int_cst): Convert param from
3030 poly_int64 to const poly_wide_int_ref &.
3031 * region-model.cc: Add logger param to pending_diagnostic::emit
3032 implementations.
3033 (region_model::check_external_function_for_access_attr): Update
3034 for new param of check_region_for_write.
3035 (region_model::deref_rvalue): Use nullptr rather than NULL.
3036 (region_model::get_capacity): Handle RK_STRING.
3037 (region_model::check_region_access): Add "sval_hint" param; pass it to
3038 check_region_bounds.
3039 (region_model::check_region_for_write): Add "sval_hint" param;
3040 pass it to check_region_access.
3041 (region_model::check_region_for_read): Add NULL for new param to
3042 check_region_access.
3043 (region_model::set_value): Pass rhs_sval to
3044 check_region_for_write.
3045 (region_model::get_representative_path_var_1): Handle SK_CONSTANT
3046 in the check for infinite recursion.
3047 * region-model.h (region_model::check_region_for_write): Add
3048 "sval_hint" param.
3049 (region_model::check_region_access): Likewise.
3050 (region_model::check_symbolic_bounds): Likewise.
3051 (region_model::check_region_bounds): Likewise.
3052 * region.cc (region_offset::make_byte_offset): New.
3053 (region_offset::calc_symbolic_bit_offset): New.
3054 (region_offset::calc_symbolic_byte_offset): New.
3055 (region_offset::dump_to_pp): New.
3056 (region_offset::dump): New.
3057 (struct linear_op): New.
3058 (operator<, operator<=, operator>, operator>=): New, for
3059 region_offset.
3060 (region::get_next_offset): New.
3061 (region::get_relative_symbolic_offset): Use ptrdiff_type_node.
3062 (field_region::get_relative_symbolic_offset): Likewise.
3063 (element_region::get_relative_symbolic_offset): Likewise.
3064 (bit_range_region::get_relative_symbolic_offset): Likewise.
3065 * region.h (region::get_next_offset): New decl.
3066 * sm-fd.cc: Add logger param to pending_diagnostic::emit
3067 implementations.
3068 * sm-file.cc: Likewise.
3069 * sm-malloc.cc: Likewise.
3070 * sm-pattern-test.cc: Likewise.
3071 * sm-sensitive.cc: Likewise.
3072 * sm-signal.cc: Likewise.
3073 * sm-taint.cc: Likewise.
3074 * store.cc (bit_range::contains_p): Allow "out" to be null.
3075 * store.h (byte_range::get_start_bit_offset): New.
3076 (byte_range::get_next_bit_offset): New.
3077 * varargs.cc: Add logger param to pending_diagnostic::emit
3078 implementations.
3079
3080 2023-06-10 Tim Lange <[email protected]>
3081
3082 PR analyzer/109577
3083 * constraint-manager.cc (class sval_finder): Visitor to find
3084 childs in svalue trees.
3085 (constraint_manager::sval_constrained_p): Add new function to
3086 check whether a sval might be part of an constraint.
3087 * constraint-manager.h: Add sval_constrained_p function.
3088 * region-model.cc (class size_visitor): Reverse behavior to not
3089 emit a warning on not explicitly considered cases.
3090 (region_model::check_region_size):
3091 Adapt to size_visitor changes.
3092
3093 2023-06-09 David Malcolm <[email protected]>
3094
3095 PR analyzer/110112
3096 * region-model.cc (region_model::get_initial_value_for_global):
3097 Move code to region::calc_initial_value_at_main.
3098 * region.cc (region::get_initial_value_at_main): New function.
3099 (region::calc_initial_value_at_main): New function, based on code
3100 in region_model::get_initial_value_for_global.
3101 (region::region): Initialize m_cached_init_sval_at_main.
3102 (decl_region::get_svalue_for_constructor): Add a cache, splitting
3103 out body to...
3104 (decl_region::calc_svalue_for_constructor): ...this new function.
3105 * region.h (region::get_initial_value_at_main): New decl.
3106 (region::calc_initial_value_at_main): New decl.
3107 (region::m_cached_init_sval_at_main): New field.
3108 (decl_region::decl_region): Initialize m_ctor_svalue.
3109 (decl_region::calc_svalue_for_constructor): New decl.
3110 (decl_region::m_ctor_svalue): New field.
3111
3112 2023-06-08 Benjamin Priour <[email protected]>
3113
3114 * bounds-checking.cc (region_model::check_symbolic_bounds): Returns whether the BASE_REG
3115 region access was OOB.
3116 (region_model::check_region_bounds): Likewise.
3117 * region-model.cc (region_model::get_store_value): Creates an
3118 unknown svalue on OOB-read access to REG.
3119 (region_model::check_region_access): Returns whether an unknown svalue needs be created.
3120 (region_model::check_region_for_read): Passes check_region_access return value.
3121 * region-model.h: Update prior function definitions.
3122
3123 2023-06-02 David Malcolm <[email protected]>
3124
3125 PR analyzer/109015
3126 * kf.cc (class kf_atomic_exchange): New.
3127 (class kf_atomic_exchange_n): New.
3128 (class kf_atomic_fetch_op): New.
3129 (class kf_atomic_op_fetch): New.
3130 (class kf_atomic_load): New.
3131 (class kf_atomic_load_n): New.
3132 (class kf_atomic_store_n): New.
3133 (register_atomic_builtins): New function.
3134 (register_known_functions): Call register_atomic_builtins.
3135
3136 2023-06-02 David Malcolm <[email protected]>
3137
3138 * store.cc (store::eval_alias_1): Regions in different memory
3139 spaces can't alias.
3140
3141 2023-05-18 Bernhard Reutner-Fischer <[email protected]>
3142
3143 * region-model-manager.cc (get_code_for_cast): Use _P defines from
3144 tree.h.
3145 (region_model_manager::get_or_create_cast): Ditto.
3146 (region_model_manager::get_region_for_global): Ditto.
3147 * region-model.cc (region_model::get_lvalue_1): Ditto.
3148 * region.cc (decl_region::maybe_get_constant_value): Ditto.
3149
3150 2023-03-22 David Malcolm <[email protected]>
3151
3152 PR analyzer/109239
3153 * program-point.cc: Include "analyzer/inlining-iterator.h".
3154 (program_point::effectively_intraprocedural_p): New function.
3155 * program-point.h (program_point::effectively_intraprocedural_p):
3156 New decl.
3157 * sm-malloc.cc (deref_before_check::emit): Use it when rejecting
3158 interprocedural cases, so that we reject interprocedural cases
3159 that have become intraprocedural due to inlining.
3160
3161 2023-03-18 David Malcolm <[email protected]>
3162
3163 PR analyzer/109094
3164 * region-model.cc (region_model::on_longjmp): Pass false for
3165 new "eval_return_svalue" param of pop_frame.
3166 (region_model::pop_frame): Add new "eval_return_svalue" param and
3167 use it to suppress the call to get_rvalue on the result when
3168 needed by on_longjmp.
3169 * region-model.h (region_model::pop_frame): Add new
3170 "eval_return_svalue" param.
3171
3172 2023-03-10 David Malcolm <[email protected]>
3173
3174 PR analyzer/109059
3175 * region-model.cc (region_model::mark_region_as_unknown): Gather a
3176 set of maybe-live svalues and call on_maybe_live_values with it.
3177 * store.cc (binding_map::remove_overlapping_bindings): Add new
3178 "maybe_live_values" param; add any removed svalues to it.
3179 (binding_cluster::clobber_region): Add NULL as new param of
3180 remove_overlapping_bindings.
3181 (binding_cluster::mark_region_as_unknown): Add "maybe_live_values"
3182 param and pass it to remove_overlapping_bindings.
3183 (binding_cluster::maybe_get_compound_binding): Add NULL for new
3184 param of binding_map::remove_overlapping_bindings.
3185 (binding_cluster::remove_overlapping_bindings): Add
3186 "maybe_live_values" param and pass to
3187 binding_map::remove_overlapping_bindings.
3188 (store::set_value): Capture a set of maybe-live svalues, and call
3189 on_maybe_live_values with it.
3190 (store::on_maybe_live_values): New.
3191 (store::mark_region_as_unknown): Add "maybe_live_values" param
3192 and pass it to binding_cluster::mark_region_as_unknown.
3193 (store::remove_overlapping_bindings): Pass NULL for new param of
3194 binding_cluster::remove_overlapping_bindings.
3195 * store.h (binding_map::remove_overlapping_bindings): Add
3196 "maybe_live_values" param.
3197 (binding_cluster::mark_region_as_unknown): Likewise.
3198 (binding_cluster::remove_overlapping_bindings): Likewise.
3199 (store::mark_region_as_unknown): Likewise.
3200 (store::on_maybe_live_values): New decl.
3201
3202 2023-03-10 David Malcolm <[email protected]>
3203
3204 PR analyzer/108475
3205 PR analyzer/109060
3206 * sm-malloc.cc (deref_before_check::deref_before_check):
3207 Initialize new field m_deref_expr. Assert that arg is non-NULL.
3208 (deref_before_check::emit): Reject cases where the spelling of the
3209 thing that was dereferenced differs from that of what is checked,
3210 or if the dereference expression was not found. Remove code to
3211 handle NULL m_arg.
3212 (deref_before_check::describe_state_change): Remove code to handle
3213 NULL m_arg.
3214 (deref_before_check::describe_final_event): Likewise.
3215 (deref_before_check::sufficiently_similar_p): New.
3216 (deref_before_check::m_deref_expr): New field.
3217 (malloc_state_machine::maybe_complain_about_deref_before_check):
3218 Don't warn if the diag_ptr is NULL.
3219
3220 2023-03-03 David Malcolm <[email protected]>
3221
3222 * kf.cc (class kf_sprintf): New.
3223 (register_known_functions): Register it.
3224
3225 2023-03-02 David Malcolm <[email protected]>
3226
3227 PR analyzer/108968
3228 * region-model.cc (region_model::get_rvalue_1): Handle VAR_DECLs
3229 with a DECL_HARD_REGISTER by returning UNKNOWN.
3230
3231 2023-03-02 Hans-Peter Nilsson <[email protected]>
3232
3233 * kf.cc (register_known_functions): Add __errno function for newlib.
3234
3235 2023-03-01 David Malcolm <[email protected]>
3236
3237 PR analyzer/107565
3238 * region-model.cc (region_model::on_call_pre): Flatten logic by
3239 returning early. Consolidate logic for detecting const and pure
3240 functions. When considering whether an unhandled built-in
3241 function has side-effects, consider all kinds of builtin, rather
3242 than just BUILT_IN_NORMAL, and don't require
3243 gimple_builtin_call_types_compatible_p.
3244
3245 2023-03-01 David Malcolm <[email protected]>
3246
3247 PR analyzer/108935
3248 * infinite-recursion.cc (contains_unknown_p): New.
3249 (sufficiently_different_region_binding_p): New function, splitting
3250 out inner loop from...
3251 (sufficiently_different_p): ...here. Extend detection of unknown
3252 svalues to also include svalues that contain unknown. Treat
3253 changes in frames below the entry to the recursion as being
3254 sufficiently different to reject being an infinite recursion.
3255
3256 2023-02-21 David Malcolm <[email protected]>
3257
3258 PR analyzer/108830
3259 * analyzer.opt (fanalyzer-suppress-followups): New option.
3260 * engine.cc (impl_region_model_context::warn): Terminate the path
3261 if the diagnostic's terminate_path_p vfunc returns true and
3262 -fanalyzer-suppress-followups is true (the default).
3263 (impl_sm_context::warn): Likewise, for both overloads.
3264 * pending-diagnostic.h (pending_diagnostic::terminate_path_p): New
3265 vfunc.
3266 * program-state.cc (program_state::on_edge): Terminate the path if
3267 the ctxt requests it during updating the edge.
3268 * region-model.cc (poisoned_value_diagnostic::terminate_path_p):
3269 New vfunc.
3270 * sm-malloc.cc (null_deref::terminate_path_p): New vfunc.
3271 (null_arg::terminate_path_p): New vfunc.
3272
3273 2023-02-16 David Malcolm <[email protected]>
3274
3275 PR analyzer/108806
3276 * constraint-manager.cc (bounded_range::dump_to_pp): Use
3277 bounded_range::singleton_p.
3278 (constraint_manager::add_bounded_ranges): Handle singleton ranges
3279 by adding an EQ_EXPR constraint.
3280 (constraint_manager::impossible_derived_conditions_p): New.
3281 (constraint_manager::eval_condition): Reject EQ_EXPR when it would
3282 imply impossible derived conditions.
3283 (selftest::test_bits): New.
3284 (selftest::run_constraint_manager_tests): Run it.
3285 * constraint-manager.h (bounded_range::singleton_p): New.
3286 (constraint_manager::impossible_derived_conditions_p): New decl.
3287 * region-model.cc (region_model::get_rvalue_1): Handle
3288 BIT_AND_EXPR, BIT_IOR_EXPR, and BIT_XOR_EXPR.
3289
3290 2023-02-15 David Malcolm <[email protected]>
3291
3292 PR analyzer/108664
3293 PR analyzer/108666
3294 PR analyzer/108725
3295 * diagnostic-manager.cc (epath_finder::get_best_epath): Add
3296 "target_stmt" param.
3297 (epath_finder::explore_feasible_paths): Likewise.
3298 (epath_finder::process_worklist_item): Likewise.
3299 (saved_diagnostic::calc_best_epath): Pass m_stmt to
3300 epath_finder::get_best_epath.
3301 * engine.cc (feasibility_state::maybe_update_for_edge): Move
3302 per-stmt logic to...
3303 (feasibility_state::update_for_stmt): ...this new function.
3304 * exploded-graph.h (feasibility_state::update_for_stmt): New decl.
3305 * feasible-graph.cc (feasible_node::get_state_at_stmt): New.
3306 * feasible-graph.h: Include "analyzer/exploded-graph.h".
3307 (feasible_node::get_state_at_stmt): New decl.
3308 * infinite-recursion.cc
3309 (infinite_recursion_diagnostic::check_valid_fpath_p): Update for
3310 vfunc signature change.
3311 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
3312 Convert first param to a reference. Add stmt param.
3313 * region-model.cc: Include "analyzer/feasible-graph.h".
3314 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
3315 "check_expr" param.
3316 (poisoned_value_diagnostic::check_valid_fpath_p): New.
3317 (poisoned_value_diagnostic::m_check_expr): New field.
3318 (region_model::check_for_poison): Attempt to supply a check_expr
3319 to the diagnostic
3320 (region_model::deref_rvalue): Add NULL for new check_expr param
3321 of poisoned_value_diagnostic.
3322 (region_model::get_or_create_region_for_heap_alloc): Don't reuse
3323 regions that are marked as TOUCHED.
3324
3325 2023-02-10 David Malcolm <[email protected]>
3326
3327 PR analyzer/108745
3328 * sm-malloc.cc (deref_before_check::emit): Reject the warning if
3329 the check occurs within a macro defintion.
3330
3331 2023-02-09 David Malcolm <[email protected]>
3332
3333 PR analyzer/108733
3334 * state-purge.cc (get_candidate_for_purging): Add ADDR_EXPR
3335 and MEM_REF.
3336
3337 2023-02-08 David Malcolm <[email protected]>
3338
3339 PR analyzer/108704
3340 * state-purge.cc (state_purge_per_decl::process_point_backwards):
3341 Don't stop processing the decl if it's fully overwritten by
3342 this stmt if it's also used by this stmt.
3343
3344 2023-02-07 David Malcolm <[email protected]>
3345
3346 PR analyzer/108661
3347 * sm-fd.cc (class kf_read): New.
3348 (register_known_fd_functions): Register "read".
3349 * sm-file.cc (class kf_fread): Update comment.
3350
3351 2023-02-02 David Malcolm <[email protected]>
3352
3353 PR analyzer/108633
3354 * sm-fd.cc (fd_state_machine::check_for_fd_attrs): Add missing
3355 "continue".
3356 (fd_state_machine::on_listen): Don't issue phase-mismatch or
3357 type-mismatch warnings for the "invalid" state.
3358
3359 2023-02-01 David Malcolm <[email protected]>
3360
3361 PR analyzer/108616
3362 * pending-diagnostic.cc (fixup_location_in_macro_p): Add "alloca"
3363 to macros that we shouldn't unwind inside.
3364
3365 2023-01-26 David Malcolm <[email protected]>
3366
3367 PR analyzer/108524
3368 * analyzer.h (class feasible_node): New forward decl.
3369 * diagnostic-manager.cc (epath_finder::get_best_epath): Add "pd"
3370 param.
3371 (epath_finder::explore_feasible_paths): Likewise.
3372 (epath_finder::process_worklist_item): Likewise. Use it to call
3373 pending_diagnostic::check_valid_fpath_p on the final fpath to
3374 give pending_diagnostic a way to add additional restrictions on
3375 feasibility.
3376 (saved_diagnostic::calc_best_epath): Pass pending_diagnostic to
3377 epath_finder::get_best_epath.
3378 * infinite-recursion.cc: Include "analyzer/feasible-graph.h".
3379 (infinite_recursion_diagnostic::check_valid_fpath_p): New.
3380 (infinite_recursion_diagnostic::fedge_uses_conjured_svalue_p): New.
3381 (infinite_recursion_diagnostic::expr_uses_conjured_svalue_p): New.
3382 * pending-diagnostic.h (pending_diagnostic::check_valid_fpath_p):
3383 New vfunc.
3384
3385 2023-01-19 David Malcolm <[email protected]>
3386
3387 PR analyzer/108455
3388 * analyzer.h (class checker_event): New forward decl.
3389 (class state_change_event): Indent.
3390 (class warning_event): New forward decl.
3391 * checker-event.cc (state_change_event::state_change_event): Add
3392 "enode" param.
3393 (warning_event::get_desc): Update for new param of
3394 evdesc::final_event ctor.
3395 * checker-event.h (state_change_event::state_change_event): Add
3396 "enode" param.
3397 (state_change_event::get_exploded_node): New accessor.
3398 (state_change_event::m_enode): New field.
3399 (warning_event::warning_event): New "enode" param.
3400 (warning_event::get_exploded_node): New accessor.
3401 (warning_event::m_enode): New field.
3402 * diagnostic-manager.cc
3403 (state_change_event_creator::on_global_state_change): Pass
3404 src_node to state_change_event ctor.
3405 (state_change_event_creator::on_state_change): Likewise.
3406 (null_assignment_sm_context::set_next_state): Pass NULL for
3407 new param of state_change_event ctor.
3408 * infinite-recursion.cc
3409 (infinite_recursion_diagnostic::add_final_event): Update for new
3410 param of warning_event ctor.
3411 * pending-diagnostic.cc (pending_diagnostic::add_final_event):
3412 Pass enode to warning_event ctor.
3413 * pending-diagnostic.h (evdesc::final_event): Add reference to
3414 warning_event.
3415 * sm-malloc.cc: Include "analyzer/checker-event.h" and
3416 "analyzer/exploded-graph.h".
3417 (deref_before_check::deref_before_check): Initialize new fields.
3418 (deref_before_check::emit): Reject warnings in which we were
3419 unable to determine the enodes of the dereference and the check.
3420 Reject warnings interprocedural warnings. Reject warnings in which
3421 the dereference doesn't dominate the check.
3422 (deref_before_check::describe_state_change): Set m_deref_enode.
3423 (deref_before_check::describe_final_event): Set m_check_enode.
3424 (deref_before_check::m_deref_enode): New field.
3425 (deref_before_check::m_check_enode): New field.
3426
3427 2023-01-13 David Malcolm <[email protected]>
3428
3429 PR analyzer/105273
3430 * region-model.cc (has_nondefault_case_for_value_p): New.
3431 (has_nondefault_cases_for_all_enum_values_p): New.
3432 (region_model::apply_constraints_for_gswitch): Skip
3433 implicitly-created "default" when switching on an enum
3434 and all enum values have non-default cases.
3435 (rejected_default_case::dump_to_pp): New.
3436 * region-model.h (region_model_context::possibly_tainted_p): New
3437 decl.
3438 (class rejected_default_case): New.
3439 * sm-taint.cc (region_model_context::possibly_tainted_p): New.
3440 * supergraph.cc (switch_cfg_superedge::dump_label_to_pp): Dump
3441 when implicitly_created_default_p.
3442 (switch_cfg_superedge::implicitly_created_default_p): New.
3443 * supergraph.h
3444 (switch_cfg_superedge::implicitly_created_default_p): New decl.
3445
3446 2023-01-11 David Malcolm <[email protected]>
3447
3448 PR analyzer/108252
3449 * kf.cc (class kf_strdup): New.
3450 (class kf_strndup): New.
3451 (register_known_functions): Register them.
3452 * region-model.cc (region_model::on_call_pre): Use
3453 &HEAP_ALLOCATED_REGION for the default result of an external
3454 function with the "malloc" attribute, rather than CONJURED_SVALUE.
3455 (region_model::get_or_create_region_for_heap_alloc): Allow
3456 "size_in_bytes" to be NULL.
3457 * store.cc (store::set_value): When handling *UNKNOWN = VAL,
3458 mark VAL as "maybe bound".
3459
3460 2022-12-16 David Malcolm <[email protected]>
3461
3462 PR analyzer/106479
3463 * kf.cc (kf_memcpy_memmove::impl_call_pre): Pass in source region
3464 to region_model::check_for_poison.
3465 * region-model-asm.cc (region_model::on_asm_stmt): Pass NULL
3466 region to region_model::check_for_poison.
3467 * region-model.cc (region_model::check_for_poison): Add
3468 "src_region" param, and pass it to poisoned_value_diagnostic.
3469 (region_model::on_assignment): Pass NULL region to
3470 region_model::check_for_poison.
3471 (region_model::get_rvalue): Likewise.
3472 * region-model.h (region_model::check_for_poison): Add
3473 "src_region" param.
3474 * sm-fd.cc (fd_state_machine::on_accept): Pass in source region
3475 to region_model::check_for_poison.
3476 * varargs.cc (kf_va_copy::impl_call_pre): Pass NULL region to
3477 region_model::check_for_poison.
3478 (kf_va_arg::impl_call_pre): Pass in source region to
3479 region_model::check_for_poison.
3480
3481 2022-12-14 David Malcolm <[email protected]>
3482
3483 PR analyzer/108065
3484 * region.cc (decl_region::get_svalue_for_initializer): Bail out to
3485 avoid calling binding_key::make with an empty region.
3486 * store.cc (binding_map::apply_ctor_val_to_range): Likewise.
3487 (binding_map::apply_ctor_pair_to_child_region): Likewise.
3488 (binding_cluster::bind): Likewise.
3489 (binding_cluster::purge_region): Likewise.
3490 (binding_cluster::maybe_get_compound_binding): Likewise.
3491 (binding_cluster::maybe_get_simple_value): Likewise.
3492
3493 2022-12-09 David Malcolm <[email protected]>
3494
3495 * analyzer.h (class known_function): Expand comment.
3496 * region-model-impl-calls.cc: Rename to...
3497 * kf.cc: ...this.
3498 * known-function-manager.h (class known_function_manager): Add
3499 leading comment.
3500
3501 2022-12-09 David Malcolm <[email protected]>
3502
3503 PR analyzer/108003
3504 * call-summary.cc
3505 (call_summary_replay::convert_region_from_summary_1): Convert
3506 heap_regs_in_use from auto_sbitmap to auto_bitmap.
3507 * region-model-manager.cc
3508 (region_model_manager::get_or_create_region_for_heap_alloc):
3509 Convert from sbitmap to bitmap.
3510 * region-model-manager.h: Likewise.
3511 * region-model.cc
3512 (region_model::get_or_create_region_for_heap_alloc): Convert from
3513 auto_sbitmap to auto_bitmap.
3514 (region_model::get_referenced_base_regions): Likewise.
3515 * region-model.h: Include "bitmap.h" rather than "sbitmap.h".
3516 (region_model::get_referenced_base_regions): Convert from
3517 auto_sbitmap to auto_bitmap.
3518
3519 2022-12-09 David Malcolm <[email protected]>
3520
3521 * region-model-impl-calls.cc (class kf_memcpy): Rename to...
3522 (class kf_memcpy_memmove): ...this.
3523 (kf_memcpy::impl_call_pre): Rename to...
3524 (kf_memcpy_memmove::impl_call_pre): ...this, and check the src for
3525 poison.
3526 (register_known_functions): Update for above renaming, and
3527 register BUILT_IN_MEMMOVE and BUILT_IN_MEMMOVE_CHK.
3528
3529 2022-12-06 David Malcolm <[email protected]>
3530
3531 PR analyzer/107882
3532 * region-model.cc (region_model::get_store_value): Return an
3533 unknown value for empty regions.
3534 (region_model::set_value): Bail on empty regions.
3535 * region.cc (region::empty_p): New.
3536 * region.h (region::empty_p): New decl.
3537 * state-purge.cc (same_binding_p): Bail if either region is empty.
3538 * store.cc (binding_key::make): Assert that a concrete binding's
3539 bit_size must be > 0.
3540 (binding_cluster::mark_region_as_unknown): Bail on empty regions.
3541 (binding_cluster::get_binding): Likewise.
3542 (binding_cluster::remove_overlapping_bindings): Likewise.
3543 (binding_cluster::on_unknown_fncall): Don't conjure values for
3544 empty regions.
3545 (store::fill_region): Bail on empty regions.
3546 * store.h (class concrete_binding): Update comment to reflect that
3547 the range of bits must be non-empty.
3548 (concrete_binding::concrete_binding): Assert that bit range is
3549 non-empty.
3550
3551 2022-12-06 David Malcolm <[email protected]>
3552
3553 PR analyzer/106325
3554 * region-model-manager.cc
3555 (region_model_manager::get_or_create_null_ptr): New.
3556 * region-model-manager.h
3557 (region_model_manager::get_or_create_null_ptr): New decl.
3558 * region-model.cc (region_model::on_top_level_param): Add
3559 "nonnull" param and make use of it.
3560 (region_model::push_frame): When handling a top-level entrypoint
3561 to the analysis, determine which params __attribute__((nonnull))
3562 applies to, and pass to on_top_level_param.
3563 * region-model.h (region_model::on_top_level_param): Add "nonnull"
3564 param.
3565
3566 2022-12-06 David Malcolm <[email protected]>
3567
3568 * analyzer.h (register_known_analyzer_functions): New decl.
3569 (register_known_functions_lang_cp): New decl.
3570 * call-details.cc: New file, split out from
3571 region-model-impl-calls.cc.
3572 * call-details.h: New file, split out from region-model.h.
3573 * call-info.cc: Include "analyzer/call-details.h".
3574 * call-summary.h: Likewise.
3575 * kf-analyzer.cc: New file, split out from
3576 region-model-impl-calls.cc.
3577 * kf-lang-cp.cc: Likewise.
3578 * known-function-manager.cc: Include "analyzer/call-details.h".
3579 * region-model-impl-calls.cc: Move definitions of call_details's
3580 member functions to call-details.cc. Move class kf_analyzer_* to
3581 kf-analyzer.cc. Move kf_operator_new and kf_operator_delete to
3582 kf-lang-cp.cc. Refresh #includes accordingly.
3583 (register_known_functions): Replace registration of __analyzer_*
3584 functions with a call to register_known_analyzer_functions.
3585 Replace registration of C++ support functions with a call to
3586 register_known_functions_lang_cp.
3587 * region-model.h (class call_details): Move to new call-details.h.
3588 * sm-fd.cc: Include "analyzer/call-details.h".
3589 * sm-file.cc: Likewise.
3590 * sm-malloc.cc: Likewise.
3591 * varargs.cc: Likewise.
3592
3593 2022-12-02 David Malcolm <[email protected]>
3594
3595 * analyzer.h (struct event_loc_info): New forward decl.
3596 * bounds-checking.cc: Use event_loc_info throughout to bundle the
3597 loc, fndecl, depth triples.
3598 * call-info.cc: Likewise.
3599 * checker-event.cc: Likewise.
3600 * checker-event.h (struct event_loc_info): New decl. Use it
3601 throughout to bundle the loc, fndecl, depth triples.
3602 * checker-path.cc: Likewise.
3603 * checker-path.h: Likewise.
3604 * diagnostic-manager.cc: Likewise.
3605 * engine.cc: Likewise.
3606 * infinite-recursion.cc: Likewise.
3607 * pending-diagnostic.cc: Likewise.
3608 * pending-diagnostic.h: Likewise.
3609 * region-model.cc: Likewise.
3610 * sm-signal.cc: Likewise.
3611 * varargs.cc: Likewise.
3612
3613 2022-12-02 David Malcolm <[email protected]>
3614
3615 PR analyzer/107851
3616 * analyzer.cc (make_label_text_n): Convert param "n" from int to
3617 unsigned HOST_WIDE_INT.
3618 * analyzer.h (make_label_text_n): Likewise for decl.
3619 * bounds-checking.cc: Include "analyzer/checker-event.h" and
3620 "analyzer/checker-path.h".
3621 (out_of_bounds::add_region_creation_events): New.
3622 (concrete_past_the_end::describe_region_creation_event): Replace
3623 with...
3624 (concrete_past_the_end::add_region_creation_events): ...this.
3625 (symbolic_past_the_end::describe_region_creation_event): Delete.
3626 * checker-event.cc (region_creation_event::region_creation_event):
3627 Update for dropping all member data.
3628 (region_creation_event::get_desc): Delete, splitting out into
3629 region_creation_event_memory_space::get_desc,
3630 region_creation_event_capacity::get_desc, and
3631 region_creation_event_debug::get_desc.
3632 (region_creation_event_memory_space::get_desc): New.
3633 (region_creation_event_capacity::get_desc): New.
3634 (region_creation_event_allocation_size::get_desc): New.
3635 (region_creation_event_debug::get_desc): New.
3636 * checker-event.h: Include "analyzer/program-state.h".
3637 (enum rce_kind): Delete.
3638 (class region_creation_event): Drop all member data.
3639 (region_creation_event::region_creation_event): Make protected.
3640 (region_creation_event::get_desc): Delete.
3641 (class region_creation_event_memory_space): New.
3642 (class region_creation_event_capacity): New.
3643 (class region_creation_event_allocation_size): New.
3644 (class region_creation_event_debug): New.
3645 * checker-path.cc (checker_path::add_region_creation_events): Add
3646 "pd" param. Call pending_diangnostic::add_region_creation_events.
3647 Update for conversion of RCE_DEBUG to region_creation_event_debug.
3648 * checker-path.h (checker_path::add_region_creation_events): Add
3649 "pd" param.
3650 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
3651 Pass pending_diagnostic to
3652 emission_path::add_region_creation_events.
3653 (diagnostic_manager::build_emission_path): Pass path_builder to
3654 add_event_on_final_node.
3655 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
3656 Pass pending_diagnostic to
3657 emission_path::add_region_creation_events.
3658 (diagnostic_manager::add_events_for_eedge): Pass
3659 pending_diagnostic to emission_path::add_region_creation_events.
3660 * diagnostic-manager.h
3661 (diagnostic_manager::add_event_on_final_node): Add "pb" param.
3662 * pending-diagnostic.cc
3663 (pending_diagnostic::add_region_creation_events): New.
3664 * pending-diagnostic.h (struct region_creation): Delete.
3665 (pending_diagnostic::describe_region_creation_event): Delete.
3666 (pending_diagnostic::add_region_creation_events): New vfunc.
3667 * region-model.cc: Include "analyzer/checker-event.h" and
3668 "analyzer/checker-path.h".
3669 (dubious_allocation_size::dubious_allocation_size): Initialize
3670 m_has_allocation_event.
3671 (dubious_allocation_size::describe_region_creation_event): Delete.
3672 (dubious_allocation_size::describe_final_event): Update for
3673 replacement of m_allocation_event with m_has_allocation_event.
3674 (dubious_allocation_size::add_region_creation_events): New.
3675 (dubious_allocation_size::m_allocation_event): Replace with...
3676 (dubious_allocation_size::m_has_allocation_event): ...this.
3677
3678 2022-12-02 David Malcolm <[email protected]>
3679
3680 PR analyzer/107948
3681 * region-model-manager.cc
3682 (region_model_manager::maybe_fold_binop): Fold (0 - VAL) to -VAL.
3683 * region-model.cc (region_model::eval_condition): Handle e.g.
3684 "-X <= 0" as equivalent to X >= 0".
3685
3686 2022-12-01 David Malcolm <[email protected]>
3687
3688 PR analyzer/106626
3689 * bounds-checking.cc
3690 (symbolic_past_the_end::describe_final_event): Delete, moving to
3691 symbolic_buffer_overflow::describe_final_event and
3692 symbolic_buffer_over_read::describe_final_event, eliminating
3693 composition of text strings via "byte_str" and "m_dir_str".
3694 (symbolic_past_the_end::m_dir_str): Delete field.
3695 (symbolic_buffer_overflow::symbolic_buffer_overflow): Drop
3696 m_dir_str.
3697 (symbolic_buffer_overflow::describe_final_event): New, as noted
3698 above.
3699 (symbolic_buffer_over_read::symbolic_buffer_overflow): Drop
3700 m_dir_str.
3701 (symbolic_buffer_over_read::describe_final_event): New, as noted
3702 above.
3703
3704 2022-12-01 David Malcolm <[email protected]>
3705
3706 * bounds-checking.cc (class out_of_bounds): Split out from...
3707 (class concrete_out_of_bounds): New abstract subclass.
3708 (class past_the_end): Rename to...
3709 (class concrete_past_the_end): ...this, and make a subclass of
3710 concrete_out_of_bounds.
3711 (class buffer_overflow): Rename to...
3712 (class concrete_buffer_overflow): ...this, and make a subclass of
3713 concrete_past_the_end.
3714 (class buffer_over_read): Rename to...
3715 (class concrete_buffer_over_read): ...this, and make a subclass of
3716 concrete_past_the_end.
3717 (class buffer_underwrite): Rename to...
3718 (class concrete_buffer_underwrite): ...this, and make a subclass
3719 of concrete_out_of_bounds.
3720 (class buffer_under_read): Rename to...
3721 (class concrete_buffer_under_read): ...this, and make a subclass
3722 of concrete_out_of_bounds.
3723 (class symbolic_past_the_end): Convert to a subclass of
3724 out_of_bounds.
3725 (symbolic_buffer_overflow::get_kind): New.
3726 (symbolic_buffer_over_read::get_kind): New.
3727 (region_model::check_region_bounds): Update for renamings.
3728 * engine.cc (impl_sm_context::set_next_state): Eliminate
3729 "new_ctxt", passing NULL to get_rvalue instead.
3730 (impl_sm_context::warn): Likewise.
3731
3732 2022-12-01 David Malcolm <[email protected]>
3733
3734 PR analyzer/106626
3735 * bounds-checking.cc (out_of_bounds::get_memory_space): New.
3736 (buffer_overflow::emit): Use it.
3737 (class buffer_overread): Rename to...
3738 (class buffer_over_read): ...this.
3739 (buffer_over_read::emit): Specify which memory space the read is
3740 from, where known. Change "overread" to "over-read".
3741 (class buffer_underflow): Rename to...
3742 (class buffer_underwrite): ...this.
3743 (buffer_underwrite::emit): Specify which memory space the write is
3744 to, where known. Change "underflow" to "underwrite".
3745 (class buffer_underread): Rename to...
3746 (class buffer_under_read): Rename to...
3747 (buffer_under_read::emit): Specify which memory space the read is
3748 from, where known. Change "underread" to "under-read".
3749 (symbolic_past_the_end::get_memory_space): New.
3750 (symbolic_buffer_overflow::emit): Use it.
3751 (class symbolic_buffer_overread): Rename to...
3752 (class symbolic_buffer_over_read): ...this.
3753 (symbolic_buffer_over_read::emit): Specify which memory space the
3754 read is from, where known. Change "overread" to "over-read".
3755 (region_model::check_symbolic_bounds): Update for class renaming.
3756 (region_model::check_region_bounds): Likewise.
3757
3758 2022-12-01 David Malcolm <[email protected]>
3759
3760 PR analyzer/106626
3761 * bounds-checking.cc (out_of_bounds::maybe_describe_array_bounds):
3762 New.
3763 (buffer_overflow::emit): Call maybe_describe_array_bounds.
3764 (buffer_overread::emit): Likewise.
3765 (buffer_underflow::emit): Likewise.
3766 (buffer_underread::emit): Likewise.
3767
3768 2022-12-01 David Malcolm <[email protected]>
3769
3770 PR analyzer/106626
3771 * bounds-checking.cc (buffer_overflow::emit): Use inform_n.
3772 Update wording to clarify that we're talking about the size of
3773 the bad access, rather than its position.
3774 (buffer_overread::emit): Likewise.
3775
3776 2022-12-01 David Malcolm <[email protected]>
3777
3778 * bounds-checking.cc: New file, taken from region-model.cc.
3779 * region-model.cc (class out_of_bounds): Move to
3780 bounds-checking.cc.
3781 (class past_the_end): Likewise.
3782 (class buffer_overflow): Likewise.
3783 (class buffer_overread): Likewise.
3784 (class buffer_underflow): Likewise.
3785 (class buffer_underread): Likewise.
3786 (class symbolic_past_the_end): Likewise.
3787 (class symbolic_buffer_overflow): Likewise.
3788 (class symbolic_buffer_overread): Likewise.
3789 (region_model::check_symbolic_bounds): Likewise.
3790 (maybe_get_integer_cst_tree): Likewise.
3791 (region_model::check_region_bounds): Likewise.
3792 * region-model.h: Add comment.
3793
3794 2022-12-01 David Malcolm <[email protected]>
3795
3796 PR analyzer/107928
3797 * sm-fd.cc (fd_state_machine::on_bind): Handle m_constant_fd in
3798 the "success" outcome.
3799 (fd_state_machine::on_connect): Likewise.
3800 * sm-fd.dot: Add "constant_fd" state and its transitions.
3801
3802 2022-11-30 David Malcolm <[email protected]>
3803
3804 * region-model-impl-calls.cc (class kf_fgets): Move to sm-file.cc.
3805 (kf_fgets::impl_call_pre): Likewise.
3806 (class kf_fread): Likewise.
3807 (kf_fread::impl_call_pre): Likewise.
3808 (class kf_getchar): Likewise.
3809 (class kf_stdio_output_fn): Likewise.
3810 (register_known_functions): Move registration of
3811 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
3812 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
3813 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
3814 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
3815 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
3816 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
3817 "getchar", "fgets", "fgets_unlocked", and "fread" to
3818 register_known_file_functions.
3819 * sm-file.cc (class kf_stdio_output_fn): Move here from
3820 region-model-impl-calls.cc.
3821 (class kf_fgets): Likewise.
3822 (class kf_fread): Likewise.
3823 (class kf_getchar): Likewise.
3824 (register_known_file_functions): Move registration of
3825 BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
3826 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
3827 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
3828 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
3829 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
3830 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF,
3831 "fgets", "fgets_unlocked", "fread", and "getchar" to here from
3832 register_known_functions.
3833
3834 2022-11-30 David Malcolm <[email protected]>
3835
3836 PR analyzer/103546
3837 * analyzer.h (register_known_file_functions): New decl.
3838 * program-state.cc (sm_state_map::replay_call_summary): Rejct
3839 attempts to store sm-state for caller_sval that can't have
3840 associated state.
3841 * region-model-impl-calls.cc (register_known_functions): Call
3842 register_known_file_functions.
3843 * sm-fd.cc (class kf_isatty): New.
3844 (register_known_fd_functions): Register it.
3845 * sm-file.cc (class kf_ferror): New.
3846 (class kf_fileno): New.
3847 (class kf_getc): New.
3848 (register_known_file_functions): New.
3849
3850 2022-11-30 David Malcolm <[email protected]>
3851
3852 PR analyzer/105784
3853 * region-model-manager.cc
3854 (region_model_manager::maybe_fold_binop): For POINTER_PLUS_EXPR,
3855 PLUS_EXPR and MINUS_EXPR, eliminate requirement that the final
3856 type matches that of arg0 in favor of a cast.
3857
3858 2022-11-24 Martin Liska <[email protected]>
3859
3860 * varargs.cc: Fix Clang warnings.
3861
3862 2022-11-24 David Malcolm <[email protected]>
3863
3864 PR analyzer/106473
3865 * call-summary.cc
3866 (call_summary_replay::convert_region_from_summary_1): Update for
3867 change to creation of heap-allocated regions.
3868 * program-state.cc (test_program_state_1): Likewise.
3869 (test_program_state_merging): Likewise.
3870 * region-model-impl-calls.cc (kf_calloc::impl_call_pre): Likewise.
3871 (kf_malloc::impl_call_pre): Likewise.
3872 (kf_operator_new::impl_call_pre): Likewise.
3873 (kf_realloc::impl_call_postsuccess_with_move::update_model): Likewise.
3874 * region-model-manager.cc
3875 (region_model_manager::create_region_for_heap_alloc): Convert
3876 to...
3877 (region_model_manager::get_or_create_region_for_heap_alloc):
3878 ...this, reusing an existing region if it's unreferenced in the
3879 client state.
3880 * region-model-manager.h (region_model_manager::get_num_regions): New.
3881 (region_model_manager::create_region_for_heap_alloc): Convert to...
3882 (region_model_manager::get_or_create_region_for_heap_alloc): ...this.
3883 * region-model.cc (region_to_value_map::can_merge_with_p): Reject
3884 merger when the values are different.
3885 (region_model::create_region_for_heap_alloc): Convert to...
3886 (region_model::get_or_create_region_for_heap_alloc): ...this.
3887 (region_model::get_referenced_base_regions): New.
3888 (selftest::test_state_merging): Update for change to creation of
3889 heap-allocated regions.
3890 (selftest::test_malloc_constraints): Likewise.
3891 (selftest::test_malloc): Likewise.
3892 * region-model.h: Include "sbitmap.h".
3893 (region_model::create_region_for_heap_alloc): Convert to...
3894 (region_model::get_or_create_region_for_heap_alloc): ...this.
3895 (region_model::get_referenced_base_regions): New decl.
3896 * store.cc (store::canonicalize): Don't purge a heap-allocated region
3897 that's been marked as escaping.
3898
3899 2022-11-24 David Malcolm <[email protected]>
3900
3901 * checker-path.cc (checker_path::inject_any_inlined_call_events):
3902 Don't dump the address of the block when -fdump-noaddr.
3903
3904 2022-11-24 David Malcolm <[email protected]>
3905
3906 * region-model.h (region_model::on_socket): Delete decl.
3907 (region_model::on_bind): Likewise.
3908 (region_model::on_listen): Likewise.
3909 (region_model::on_accept): Likewise.
3910 (region_model::on_connect): Likewise.
3911 * sm-fd.cc (kf_socket::outcome_of_socket::update_model): Move body
3912 of region_model::on_socket into here, ...
3913 (region_model::on_socket): ...eliminating this function.
3914 (kf_bind::outcome_of_bind::update_model): Likewise for on_bind...
3915 (region_model::on_bind): ...eliminating this function.
3916 (kf_listen::outcome_of_listen::update_model): Likewise fo
3917 on_listen...
3918 (region_model::on_listen): ...eliminating this function.
3919 (kf_accept::outcome_of_accept::update_model): Likewise fo
3920 on_accept...
3921 (region_model::on_accept): ...eliminating this function.
3922 (kf_connect::outcome_of_connect::update_model): Likewise fo
3923 on_connect...
3924 (region_model::on_connect): ...eliminating this function.
3925
3926 2022-11-24 David Malcolm <[email protected]>
3927
3928 * analyzer.h (register_known_fd_functions): New decl.
3929 * region-model-impl-calls.cc (class kf_accept): Move to sm-fd.cc.
3930 (class kf_bind): Likewise.
3931 (class kf_connect): Likewise.
3932 (class kf_listen): Likewise.
3933 (class kf_pipe): Likewise.
3934 (class kf_socket): Likewise.
3935 (register_known_functions): Remove registration of the above
3936 functions, instead calling register_known_fd_functions.
3937 * sm-fd.cc: Include "analyzer/call-info.h".
3938 (class kf_socket): Move here from region-model-impl-calls.cc.
3939 (class kf_bind): Likewise.
3940 (class kf_listen): Likewise.
3941 (class kf_accept): Likewise.
3942 (class kf_connect): Likewise.
3943 (class kf_pipe): Likewise.
3944 (register_known_fd_functions): New.
3945
3946 2022-11-22 David Malcolm <[email protected]>
3947
3948 PR analyzer/107788
3949 * known-function-manager.cc (known_function_manager::get_match):
3950 Don't look up fndecls by name when they're not in the root
3951 namespace.
3952
3953 2022-11-22 David Malcolm <[email protected]>
3954
3955 PR analyzer/107783
3956 * sm-fd.cc (fd_state_machine::check_for_new_socket_fd): Don't
3957 complain when old state is "fd-constant".
3958 (fd_state_machine::on_listen): Likewise.
3959 (fd_state_machine::on_accept): Likewise.
3960
3961 2022-11-22 David Malcolm <[email protected]>
3962
3963 PR analyzer/107807
3964 * region-model-impl-calls.cc (register_known_functions): Register
3965 "___errno" and "__error" as synonyms for "__errno_location".
3966
3967 2022-11-22 David Malcolm <[email protected]>
3968
3969 * analyzer.h (class internal_known_function): New.
3970 (register_varargs_builtins): New decl.
3971 * engine.cc (exploded_node::on_stmt_pre): Remove
3972 "out_terminate_path" param from call to region_model::on_stmt_pre.
3973 (feasibility_state::maybe_update_for_edge): Likewise.
3974 * known-function-manager.cc: Include "basic-block.h", "gimple.h",
3975 and "analyzer/region-model.h".
3976 (known_function_manager::known_function_manager): Initialize
3977 m_combined_fns_arr.
3978 (known_function_manager::~known_function_manager): Clean up
3979 m_combined_fns_arr.
3980 (known_function_manager::get_by_identifier): Make const.
3981 (known_function_manager::add): New overloaded definitions for
3982 enum built_in_function and enum internal_fn.
3983 (known_function_manager::get_by_fndecl): Delete.
3984 (known_function_manager::get_match): New.
3985 (known_function_manager::get_internal_fn): New.
3986 (known_function_manager::get_normal_builtin): New.
3987 * known-function-manager.h
3988 (known_function_manager::get_by_identifier): Make private and
3989 add const qualifier.
3990 (known_function_manager::get_by_fndecl): Delete.
3991 (known_function_manager::add): Add overloaded decls for
3992 enum built_in_function name and enum internal_fn.
3993 (known_function_manager::get_match): New decl.
3994 (known_function_manager::get_internal_fn): New decl.
3995 (known_function_manager::get_normal_builtin): New decl.
3996 (known_function_manager::m_combined_fns_arr): New field.
3997 * region-model-impl-calls.cc (call_details::arg_is_size_p): New.
3998 (class kf_alloca): New.
3999 (region_model::impl_call_alloca): Convert to...
4000 (kf_alloca::impl_call_pre): ...this.
4001 (kf_analyzer_dump_capacity::matches_call_types_p): Rewrite check
4002 to use call_details::arg_is_pointer_p.
4003 (region_model::impl_call_builtin_expect): Convert to...
4004 (class kf_expect): ...this.
4005 (class kf_calloc): New, adding check that both arguments are
4006 size_t.
4007 (region_model::impl_call_calloc): Convert to...
4008 (kf_calloc::impl_call_pre): ...this.
4009 (kf_connect::matches_call_types_p): Rewrite check to use
4010 call_details::arg_is_pointer_p.
4011 (region_model::impl_call_error): Convert to...
4012 (class kf_error): ...this, and...
4013 (kf_error::impl_call_pre): ...this.
4014 (class kf_fgets): New, adding checks that args 0 and 2 are
4015 pointers.
4016 (region_model::impl_call_fgets): Convert to...
4017 (kf_fgets::impl_call_pre): ...this.
4018 (class kf_fread): New, adding checks on the argument types.
4019 (region_model::impl_call_fread): Convert to...
4020 (kf_fread::impl_call_pre): ...this.
4021 (class kf_free): New, adding check that the argument is a pointer.
4022 (region_model::impl_call_free): Convert to...
4023 (kf_free::impl_call_post): ...this.
4024 (class kf_getchar): New.
4025 (class kf_malloc): New, adding check that the argument is a
4026 size_t.
4027 (region_model::impl_call_malloc): Convert to...
4028 (kf_malloc::impl_call_pre): ...this.
4029 (class kf_memcpy): New, adding checks on arguments.
4030 (region_model::impl_call_memcpy): Convert to...
4031 (kf_memcpy::impl_call_pre): ...this.
4032 (class kf_memset): New.
4033 (region_model::impl_call_memset): Convert to...
4034 (kf_memset::impl_call_pre): ...this.
4035 (kf_pipe::matches_call_types_p): Rewrite check to use
4036 call_details::arg_is_pointer_p.
4037 (kf_putenv::matches_call_types_p): Likewise.
4038 (class kf_realloc): New, adding checks on the argument types.
4039 (region_model::impl_call_realloc): Convert to...
4040 (kf_realloc::impl_call_post): ...this.
4041 (class kf_strchr): New.
4042 (region_model::impl_call_strchr): Convert to...
4043 (kf_strchr::impl_call_post): ...this.
4044 (class kf_stack_restore): New.
4045 (class kf_stack_save): New.
4046 (class kf_stdio_output_fn): New.
4047 (class kf_strcpy): New,
4048 (region_model::impl_call_strcpy): Convert to...
4049 (kf_strcpy::impl_call_pre): ...this.
4050 (class kf_strlen): New.
4051 (region_model::impl_call_strlen): Convert to...
4052 (kf_strlen::impl_call_pre): ...this.
4053 (class kf_ubsan_bounds): New.
4054 (region_model::impl_deallocation_call): Reimplement to avoid call
4055 to impl_call_free.
4056 (register_known_functions): Add handlers for IFN_BUILTIN_EXPECT
4057 and IFN_UBSAN_BOUNDS. Add handlers for BUILT_IN_ALLOCA,
4058 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
4059 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FPRINTF,
4060 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_FPUTC,
4061 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
4062 BUILT_IN_FREE, BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED,
4063 BUILT_IN_MALLOC, BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK,
4064 BUILT_IN_MEMSET, BUILT_IN_MEMSET_CHK, BUILT_IN_PRINTF,
4065 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTCHAR,
4066 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_PUTS,
4067 BUILT_IN_PUTS_UNLOCKED, BUILT_IN_REALLOC, BUILT_IN_STACK_RESTORE,
4068 BUILT_IN_STACK_SAVE, BUILT_IN_STRCHR, BUILT_IN_STRCPY,
4069 BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN, BUILT_IN_VFPRINTF, and
4070 BUILT_IN_VPRINTF. Call register_varargs_builtins. Add handlers
4071 for "getchar", "memset", "fgets", "fgets_unlocked", "fread",
4072 "error", and "error_at_line".
4073 * region-model.cc (region_model::on_stmt_pre): Drop
4074 "out_terminate_path" param.
4075 (region_model::get_known_function): Reimplement by calling
4076 known_function_manager::get_match, passing new "cd" param.
4077 Add overload taking enum internal_fn.
4078 (region_model::on_call_pre): Drop "out_terminate_path" param.
4079 Remove special-case handling of internal fns IFN_BUILTIN_EXPECT,
4080 IFN_UBSAN_BOUNDS, and IFN_VA_ARG, of built-in fns BUILT_IN_ALLOCA,
4081 BUILT_IN_ALLOCA_WITH_ALIGN, BUILT_IN_CALLOC, BUILT_IN_EXPECT,
4082 BUILT_IN_EXPECT_WITH_PROBABILITY, BUILT_IN_FREE, BUILT_IN_MALLOC,
4083 BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMSET,
4084 BUILT_IN_MEMSET_CHK, BUILT_IN_REALLOC, BUILT_IN_STRCHR,
4085 BUILT_IN_STRCPY, BUILT_IN_STRCPY_CHK, BUILT_IN_STRLEN,
4086 BUILT_IN_STACK_SAVE, BUILT_IN_STACK_RESTORE, BUILT_IN_FPRINTF,
4087 BUILT_IN_FPRINTF_UNLOCKED, BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED,
4088 BUILT_IN_FPUTC, BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS,
4089 BUILT_IN_FPUTS_UNLOCKED, BUILT_IN_FWRITE,
4090 BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
4091 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
4092 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
4093 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF, BUILT_IN_VA_START, and
4094 BUILT_IN_VA_COPY, and of named functions "malloc", "calloc",
4095 "alloca", "realloc", "error", "error_at_line", "fgets",
4096 "fgets_unlocked", "fread", "getchar", "memset", "strchr", and
4097 "strlen". Replace all this special-casing with calls to
4098 get_known_function for internal fns and for fn decls.
4099 (region_model::on_call_post): Remove special-casing handling for
4100 "free" and "strchr", and for BUILT_IN_REALLOC, BUILT_IN_STRCHR,
4101 and BUILT_IN_VA_END. Replace by consolidating on usage of
4102 get_known_function.
4103 * region-model.h (call_details::arg_is_size_p): New.
4104 (region_model::on_stmt_pre): Drop "out_terminate_path" param.
4105 (region_model::on_call_pre): Likewise.
4106 (region_model::impl_call_alloca): Delete.
4107 (region_model::impl_call_builtin_expect): Delete.
4108 (region_model::impl_call_calloc): Delete.
4109 (region_model::impl_call_error): Delete.
4110 (region_model::impl_call_fgets): Delete.
4111 (region_model::impl_call_fread): Delete.
4112 (region_model::impl_call_free): Delete.
4113 (region_model::impl_call_malloc): Delete.
4114 (region_model::impl_call_memcpy): Delete.
4115 (region_model::impl_call_memset): Delete.
4116 (region_model::impl_call_realloc): Delete.
4117 (region_model::impl_call_strchr): Delete.
4118 (region_model::impl_call_strcpy): Delete.
4119 (region_model::impl_call_strlen): Delete.
4120 (region_model::impl_call_va_start): Delete.
4121 (region_model::impl_call_va_copy): Delete.
4122 (region_model::impl_call_va_arg): Delete.
4123 (region_model::impl_call_va_end): Delete.
4124 (region_model::check_region_for_write): Public.
4125 (region_model::get_known_function): Add "cd" param. Add
4126 overloaded decl taking enum internal_fn.
4127 * sm-malloc.cc: Update comments.
4128 * varargs.cc (class kf_va_start): New.
4129 (region_model::impl_call_va_start): Convert to...
4130 (kf_va_start::impl_call_pre): ...this.
4131 (class kf_va_copy): New.
4132 (region_model::impl_call_va_copy): Convert to...
4133 (kf_va_copy::impl_call_pre): ...this.
4134 (class kf_va_arg): New.
4135 (region_model::impl_call_va_arg): Convert to...
4136 (kf_va_arg::impl_call_pre): ...this.
4137 (class kf_va_end): New.
4138 (region_model::impl_call_va_end): Delete.
4139 (register_varargs_builtins): New.
4140
4141 2022-11-22 David Malcolm <[email protected]>
4142
4143 PR analyzer/107788
4144 * region-model.cc (region_model::update_for_int_cst_return):
4145 Require that the return type be an integer type.
4146 (region_model::update_for_nonzero_return): Likewise.
4147
4148 2022-11-22 David Malcolm <[email protected]>
4149
4150 PR analyzer/107783
4151 * region-model-impl-calls.cc (kf_accept::matches_call_types_p):
4152 Require that args 1 and 2 be pointers.
4153 (kf_bind::matches_call_types_p): Require that arg 1 be a pointer.
4154 * region-model.h (call_details::arg_is_pointer_p): New
4155
4156 2022-11-22 David Malcolm <[email protected]>
4157
4158 PR analyzer/107777
4159 * call-summary.cc
4160 (call_summary_replay::convert_region_from_summary_1): Handle
4161 RK_THREAD_LOCAL and RK_ERRNO in switch.
4162 * region-model.cc (region_model::get_representative_path_var_1):
4163 Likewise.
4164
4165 2022-11-19 David Malcolm <[email protected]>
4166
4167 PR analyzer/107582
4168 * engine.cc (dynamic_call_info_t::update_model): Update the model
4169 by pushing or pop a frame, rather than by clobbering it with the
4170 model from the exploded_node's state.
4171
4172 2022-11-18 David Malcolm <[email protected]>
4173
4174 * analyzer.cc (is_pipe_call_p): Delete.
4175 * analyzer.h (is_pipe_call_p): Delete.
4176 * region-model-impl-calls.cc (call_details::get_location): New.
4177 (class kf_analyzer_break): New, adapted from
4178 region_model::on_stmt_pre.
4179 (region_model::impl_call_analyzer_describe): Convert to...
4180 (class kf_analyzer_describe): ...this.
4181 (region_model::impl_call_analyzer_dump_capacity): Convert to...
4182 (class kf_analyzer_dump_capacity): ...this.
4183 (region_model::impl_call_analyzer_dump_escaped): Convert to...
4184 (class kf_analyzer_dump_escaped): ...this.
4185 (class kf_analyzer_dump_exploded_nodes): New.
4186 (region_model::impl_call_analyzer_dump_named_constant): Convert
4187 to...
4188 (class kf_analyzer_dump_named_constant): ...this.
4189 (class dump_path_diagnostic): Move here from region-model.cc.
4190 (class kf_analyzer_dump_path) New, adapted from
4191 region_model::on_stmt_pre.
4192 (class kf_analyzer_dump_region_model): Likewise.
4193 (region_model::impl_call_analyzer_eval): Convert to...
4194 (class kf_analyzer_eval): ...this.
4195 (region_model::impl_call_analyzer_get_unknown_ptr): Convert to...
4196 (class kf_analyzer_get_unknown_ptr): ...this.
4197 (class known_function_accept): Rename to...
4198 (class kf_accept): ...this.
4199 (class known_function_bind): Rename to...
4200 (class kf_bind): ...this.
4201 (class known_function_connect): Rename to...
4202 (class kf_connect): ...this.
4203 (region_model::impl_call_errno_location): Convert to...
4204 (class kf_errno_location): ...this.
4205 (class known_function_listen): Rename to...
4206 (class kf_listen): ...this.
4207 (region_model::impl_call_pipe): Convert to...
4208 (class kf_pipe): ...this.
4209 (region_model::impl_call_putenv): Convert to...
4210 (class kf_putenv): ...this.
4211 (region_model::impl_call_operator_new): Convert to...
4212 (class kf_operator_new): ...this.
4213 (region_model::impl_call_operator_delete): Convert to...
4214 (class kf_operator_delete): ...this.
4215 (class known_function_socket): Rename to...
4216 (class kf_socket): ...this.
4217 (register_known_functions): Rename param to KFM. Break out
4218 existing known functions into a "POSIX" section, and add "pipe",
4219 "pipe2", and "putenv". Add debugging functions
4220 "__analyzer_break", "__analyzer_describe",
4221 "__analyzer_dump_capacity", "__analyzer_dump_escaped",
4222 "__analyzer_dump_exploded_nodes",
4223 "__analyzer_dump_named_constant", "__analyzer_dump_path",
4224 "__analyzer_dump_region_model", "__analyzer_eval",
4225 "__analyzer_get_unknown_ptr". Add C++ support functions
4226 "operator new", "operator new []", "operator delete", and
4227 "operator delete []".
4228 * region-model.cc (class dump_path_diagnostic): Move to
4229 region-model-impl-calls.cc.
4230 (region_model::on_stmt_pre): Eliminate special-casing of
4231 "__analyzer_describe", "__analyzer_dump_capacity",
4232 "__analyzer_dump_escaped", "__analyzer_dump_named_constant",
4233 "__analyzer_dump_path", "__analyzer_dump_region_model",
4234 "__analyzer_eval", "__analyzer_break",
4235 "__analyzer_dump_exploded_nodes", "__analyzer_get_unknown_ptr",
4236 "__errno_location", "pipe", "pipe2", "putenv", "operator new",
4237 "operator new []", "operator delete", "operator delete []"
4238 "pipe" and "pipe2", handling them instead via the known_functions
4239 mechanism.
4240 * region-model.h (call_details::get_location): New decl.
4241 (region_model::impl_call_analyzer_describe): Delete decl.
4242 (region_model::impl_call_analyzer_dump_capacity): Delete decl.
4243 (region_model::impl_call_analyzer_dump_escaped): Delete decl.
4244 (region_model::impl_call_analyzer_dump_named_constant): Delete decl.
4245 (region_model::impl_call_analyzer_eval): Delete decl.
4246 (region_model::impl_call_analyzer_get_unknown_ptr): Delete decl.
4247 (region_model::impl_call_errno_location): Delete decl.
4248 (region_model::impl_call_pipe): Delete decl.
4249 (region_model::impl_call_putenv): Delete decl.
4250 (region_model::impl_call_operator_new): Delete decl.
4251 (region_model::impl_call_operator_delete): Delete decl.
4252 * sm-fd.cc: Update comments.
4253
4254 2022-11-16 David Malcolm <[email protected]>
4255
4256 PR analyzer/107711
4257 * analyzer-language.cc: Include "diagnostic.h".
4258 (maybe_stash_named_constant): Add logger param and use it to log
4259 the name being looked up, and the result.
4260 (stash_named_constants): New, splitting out from...
4261 (on_finish_translation_unit): ...this function. Call
4262 get_or_create_logfile and use the result to create a logger
4263 instance, passing it to stash_named_constants.
4264 * analyzer.h (get_or_create_any_logfile): New decl.
4265 * engine.cc (dump_fout, owns_dump_fout): New globals, split out
4266 from run_checkers.
4267 (get_or_create_any_logfile): New function, split out from...
4268 (run_checkers): ...here, so that the logfile can be opened by
4269 on_finish_translation_unit. Clear the globals when closing the
4270 dump file.
4271
4272 2022-11-16 David Malcolm <[email protected]>
4273
4274 * analyzer.h (known_function::matches_call_types_p): New vfunc.
4275 (known_function::impl_call_pre): Provide base implementation.
4276 (known_function::impl_call_post): New vfunc.
4277 (register_known_functions): New.
4278 * engine.cc (impl_run_checkers): Call register_known_functions.
4279 * region-model-impl-calls.cc (region_model::impl_call_accept):
4280 Convert to...
4281 (class known_function_accept): ...this.
4282 (region_model::impl_call_bind): Convert to...
4283 (class known_function_bind): ...this.
4284 (region_model::impl_call_connect): Convert to...
4285 (class known_function_connect): ...this.
4286 (region_model::impl_call_listen): Convert to...
4287 (class known_function_listen): ...this.
4288 (region_model::impl_call_socket): Convert to...
4289 (class known_function_socket): ...this.
4290 (register_known_functions): New.
4291 * region-model.cc (region_model::on_call_pre): Remove special
4292 case for "bind" in favor of the known_function-handling dispatch.
4293 Add call to known_function::matches_call_types_p to latter.
4294 (region_model::on_call_post): Remove special cases for "accept",
4295 "bind", "connect", "listen", and "socket" in favor of dispatch
4296 to known_function::impl_call_post.
4297 * region-model.h (region_model::impl_call_accept): Delete decl.
4298 (region_model::impl_call_bind): Delete decl.
4299 (region_model::impl_call_connect): Delete decl.
4300 (region_model::impl_call_listen): Delete decl.
4301 (region_model::impl_call_socket): Delete decl.
4302 * sm-fd.cc: Update comments.
4303
4304 2022-11-16 David Malcolm <[email protected]>
4305
4306 * checker-event.cc: New file, split out from...
4307 * checker-path.cc: ...this file.
4308
4309 2022-11-15 David Malcolm <[email protected]>
4310
4311 PR analyzer/106140
4312 * analyzer-language.cc (on_finish_translation_unit): Stash named
4313 constants "SOCK_STREAM" and "SOCK_DGRAM".
4314 * analyzer.opt (Wanalyzer-fd-phase-mismatch): New.
4315 (Wanalyzer-fd-type-mismatch): New.
4316 * engine.cc (impl_region_model_context::get_state_map_by_name):
4317 Add "out_sm_context" param. Allow out_sm_idx to be NULL.
4318 * exploded-graph.h
4319 (impl_region_model_context::get_state_map_by_name):
4320 Add "out_sm_context" param.
4321 * region-model-impl-calls.cc (region_model::impl_call_accept): New.
4322 (region_model::impl_call_bind): New.
4323 (region_model::impl_call_connect): New.
4324 (region_model::impl_call_listen): New.
4325 (region_model::impl_call_socket): New.
4326 * region-model.cc (region_model::on_call_pre): Special-case
4327 "bind".
4328 (region_model::on_call_post): Special-case "accept", "bind",
4329 "connect", "listen", and "socket".
4330 * region-model.h (region_model::impl_call_accept): New decl.
4331 (region_model::impl_call_bind): New decl.
4332 (region_model::impl_call_connect): New decl.
4333 (region_model::impl_call_listen): New decl.
4334 (region_model::impl_call_socket): New decl.
4335 (region_model::on_socket): New decl.
4336 (region_model::on_bind): New decl.
4337 (region_model::on_listen): New decl.
4338 (region_model::on_accept): New decl.
4339 (region_model::on_connect): New decl.
4340 (region_model::add_constraint): Make public.
4341 (region_model::check_for_poison): Make public.
4342 (region_model_context::get_state_map_by_name): Add out_sm_context param.
4343 (region_model_context::get_fd_map): Likewise.
4344 (region_model_context::get_malloc_map): Likewise.
4345 (region_model_context::get_taint_map): Likewise.
4346 (noop_region_model_context::get_state_map_by_name): Likewise.
4347 (region_model_context_decorator::get_state_map_by_name): Likewise.
4348 * sm-fd.cc: Include "analyzer/supergraph.h" and
4349 "analyzer/analyzer-language.h".
4350 (enum expected_phase): New enum.
4351 (fd_state_machine::m_new_datagram_socket): New.
4352 (fd_state_machine::m_new_stream_socket): New.
4353 (fd_state_machine::m_new_unknown_socket): New.
4354 (fd_state_machine::m_bound_datagram_socket): New.
4355 (fd_state_machine::m_bound_stream_socket): New.
4356 (fd_state_machine::m_bound_unknown_socket): New.
4357 (fd_state_machine::m_listening_stream_socket): New.
4358 (fd_state_machine::m_m_connected_stream_socket): New.
4359 (fd_state_machine::m_SOCK_STREAM): New.
4360 (fd_state_machine::m_SOCK_DGRAM): New.
4361 (fd_diagnostic::describe_state_change): Handle socket states.
4362 (fd_diagnostic::get_meaning_for_state_change): Likewise.
4363 (class fd_phase_mismatch): New.
4364 (enum expected_type): New enum.
4365 (class fd_type_mismatch): New.
4366 (fd_state_machine::fd_state_machine): Initialize new states and
4367 stashed named constants.
4368 (fd_state_machine::is_socket_fd_p): New.
4369 (fd_state_machine::is_datagram_socket_fd_p): New.
4370 (fd_state_machine::is_stream_socket_fd_p): New.
4371 (fd_state_machine::on_close): Handle the socket states.
4372 (fd_state_machine::check_for_open_fd): Complain about fncalls on
4373 sockets in the wrong phase. Support socket FDs.
4374 (add_constraint_ge_zero): New.
4375 (fd_state_machine::get_state_for_socket_type): New.
4376 (fd_state_machine::on_socket): New.
4377 (fd_state_machine::check_for_socket_fd): New.
4378 (fd_state_machine::check_for_new_socket_fd): New.
4379 (fd_state_machine::on_bind): New.
4380 (fd_state_machine::on_listen): New.
4381 (fd_state_machine::on_accept): New.
4382 (fd_state_machine::on_connect): New.
4383 (fd_state_machine::can_purge_p): Don't purge socket values.
4384 (get_fd_state): New.
4385 (region_model::mark_as_valid_fd): Use get_fd_state.
4386 (region_model::on_socket): New.
4387 (region_model::on_bind): New.
4388 (region_model::on_listen): New.
4389 (region_model::on_accept): New.
4390 (region_model::on_connect): New.
4391 * sm-fd.dot: Update to reflect sm-fd.cc changes.
4392
4393 2022-11-15 David Malcolm <[email protected]>
4394
4395 PR analyzer/106302
4396 * analyzer-language.cc: New file.
4397 * analyzer-language.h: New file.
4398 * analyzer.h (get_stashed_constant_by_name): New decl.
4399 (log_stashed_constants): New decl.
4400 * engine.cc (impl_run_checkers): Call log_stashed_constants.
4401 * region-model-impl-calls.cc
4402 (region_model::impl_call_analyzer_dump_named_constant): New.
4403 * region-model.cc (region_model::on_stmt_pre): Handle
4404 __analyzer_dump_named_constant.
4405 * region-model.h
4406 (region_model::impl_call_analyzer_dump_named_constant): New decl.
4407 * sm-fd.cc (fd_state_machine::m_O_ACCMODE): New.
4408 (fd_state_machine::m_O_RDONLY): New.
4409 (fd_state_machine::m_O_WRONLY): New.
4410 (fd_state_machine::fd_state_machine): Initialize the new fields.
4411 (fd_state_machine::get_access_mode_from_flag): Use the new fields,
4412 rather than using the host values.
4413
4414 2022-11-13 David Malcolm <[email protected]>
4415
4416 PR analyzer/106235
4417 * analyzer.opt (Wanalyzer-tainted-assertion): New.
4418 * checker-path.cc (checker_path::fixup_locations): Pass false to
4419 pending_diagnostic::fixup_location.
4420 * diagnostic-manager.cc (get_emission_location): Pass true to
4421 pending_diagnostic::fixup_location.
4422 * pending-diagnostic.cc (pending_diagnostic::fixup_location): Add
4423 bool param.
4424 * pending-diagnostic.h (pending_diagnostic::fixup_location): Add
4425 bool param to decl.
4426 * sm-taint.cc (taint_state_machine::m_tainted_control_flow): New.
4427 (taint_diagnostic::describe_state_change): Drop "final".
4428 (class tainted_assertion): New.
4429 (taint_state_machine::taint_state_machine): Initialize
4430 m_tainted_control_flow.
4431 (taint_state_machine::alt_get_inherited_state): Support
4432 comparisons being tainted, based on their arguments.
4433 (is_assertion_failure_handler_p): New.
4434 (taint_state_machine::on_stmt): Complain about calls to assertion
4435 failure handlers guarded by an attacker-controller conditional.
4436 Detect attacker-controlled gcond conditionals and gswitch index
4437 values.
4438 (taint_state_machine::check_control_flow_arg_for_taint): New.
4439
4440 2022-11-11 David Malcolm <[email protected]>
4441
4442 * sm-fd.dot: Fix typo in comment.
4443 * sm-file.dot: New file.
4444 * varargs.cc: Fix typo in comment.
4445 * varargs.dot: New file.
4446
4447 2022-11-11 David Malcolm <[email protected]>
4448
4449 * checker-path.h: Split out checker_event and its subclasses to...
4450 * checker-event.h: ...this new header.
4451
4452 2022-11-11 David Malcolm <[email protected]>
4453
4454 PR analyzer/106147
4455 * analyzer.opt (Wanalyzer-infinite-recursion): New.
4456 * call-string.cc (call_string::count_occurrences_of_function):
4457 New.
4458 * call-string.h (call_string::count_occurrences_of_function): New
4459 decl.
4460 * checker-path.cc (function_entry_event::function_entry_event):
4461 New ctor.
4462 (checker_path::add_final_event): Delete.
4463 * checker-path.h (function_entry_event::function_entry_event): New
4464 ctor.
4465 (function_entry_event::get_desc): Drop "final".
4466 (checker_path::add_final_event): Delete.
4467 * diagnostic-manager.cc
4468 (diagnostic_manager::emit_saved_diagnostic): Create the final
4469 event via a new pending_diagnostic::add_final_event vfunc, rather
4470 than checker_path::add_final_event.
4471 (diagnostic_manager::add_events_for_eedge): Create function entry
4472 events via a new pending_diagnostic::add_function_entry_event
4473 vfunc.
4474 * engine.cc (exploded_graph::process_node): When creating a new
4475 PK_BEFORE_SUPERNODE node, call
4476 exploded_graph::detect_infinite_recursion on it after adding the
4477 in-edge.
4478 * exploded-graph.h (exploded_graph::detect_infinite_recursion):
4479 New decl.
4480 (exploded_graph::find_previous_entry_to): New decl.
4481 * infinite-recursion.cc: New file.
4482 * pending-diagnostic.cc
4483 (pending_diagnostic::add_function_entry_event): New.
4484 (pending_diagnostic::add_final_event): New.
4485 * pending-diagnostic.h
4486 (pending_diagnostic::add_function_entry_event): New vfunc.
4487 (pending_diagnostic::add_final_event): New vfunc.
4488
4489 2022-11-10 David Malcolm <[email protected]>
4490
4491 PR analyzer/99671
4492 * analyzer.opt (Wanalyzer-deref-before-check): New warning.
4493 * diagnostic-manager.cc
4494 (null_assignment_sm_context::set_next_state): Only add state
4495 change events for transition to "null" state.
4496 (null_assignment_sm_context::is_transition_to_null): New.
4497 * engine.cc (impl_region_model_context::on_pop_frame): New.
4498 * exploded-graph.h (impl_region_model_context::on_pop_frame): New
4499 decl.
4500 * program-state.cc (sm_state_map::clear_any_state): New.
4501 (sm_state_map::can_merge_with_p): New.
4502 (program_state::can_merge_with_p): Replace requirement that
4503 sm-states be equal in favor of an attempt to merge them.
4504 * program-state.h (sm_state_map::clear_any_state): New decl.
4505 (sm_state_map::can_merge_with_p): New decl.
4506 * region-model.cc (region_model::eval_condition): Make const.
4507 (region_model::pop_frame): Call ctxt->on_pop_frame.
4508 * region-model.h (region_model::eval_condition): Make const.
4509 (region_model_context::on_pop_frame): New vfunc.
4510 (noop_region_model_context::on_pop_frame): New.
4511 (region_model_context_decorator::on_pop_frame): New.
4512 * sm-malloc.cc (enum resource_state): Add RS_ASSUMED_NON_NULL.
4513 (allocation_state::dump_to_pp): Drop "final".
4514 (struct assumed_non_null_state): New subclass.
4515 (malloc_state_machine::m_assumed_non_null): New.
4516 (assumed_non_null_p): New.
4517 (class deref_before_check): New.
4518 (assumed_non_null_state::dump_to_pp): New.
4519 (malloc_state_machine::get_or_create_assumed_non_null_state_for_frame):
4520 New.
4521 (malloc_state_machine::maybe_assume_non_null): New.
4522 (malloc_state_machine::on_stmt): Transition from start state to
4523 "assumed-non-null" state for pointers passed to
4524 __attribute__((nonnull)) arguments, and for pointers explicitly
4525 dereferenced. Call maybe_complain_about_deref_before_check for
4526 pointers explicitly compared against NULL.
4527 (malloc_state_machine::maybe_complain_about_deref_before_check):
4528 New.
4529 (malloc_state_machine::on_deallocator_call): Also transition
4530 "assumed-non-null" states to "freed".
4531 (malloc_state_machine::on_pop_frame): New.
4532 (malloc_state_machine::maybe_get_merged_states_nonequal): New.
4533 * sm-malloc.dot: Update for changes to sm-malloc.cc.
4534 * sm.h (state_machine::on_pop_frame): New.
4535 (state_machine::maybe_get_merged_state): New.
4536 (state_machine::maybe_get_merged_states_nonequal): New.
4537
4538 2022-11-09 David Malcolm <[email protected]>
4539
4540 * checker-path.cc (checker_event::debug): New.
4541 (checker_path::add_event): Move here from checker-path.h. Add
4542 logging.
4543 * checker-path.h (checker_event::debug): New decl.
4544 (checker_path::checker_path): Add logger param.
4545 (checker_path::add_event): Move definition from here to
4546 checker-path.cc.
4547 (checker_path::m_logger): New field.
4548 * diagnostic-manager.cc
4549 (diagnostic_manager::emit_saved_diagnostic): Pass logger to
4550 checker_path ctor.
4551 (diagnostic_manager::add_events_for_eedge): Log scope when
4552 processing a run of stmts.
4553
4554 2022-11-08 David Malcolm <[email protected]>
4555
4556 PR analyzer/101962
4557 * region-model-impl-calls.cc: Update comment.
4558 * region-model.cc (region_model::check_symbolic_bounds): Fix
4559 layout of "void" return. Replace usage of
4560 eval_condition_without_cm with eval_condition.
4561 (region_model::eval_condition): Take over body of...
4562 (region_model::eval_condition_without_cm): ...this subroutine,
4563 dropping the latter. Eliminating this distinction avoids issues
4564 where constraints were not considered when recursing.
4565 (region_model::compare_initial_and_pointer): Update comment.
4566 (region_model::symbolic_greater_than): Replace usage of
4567 eval_condition_without_cm with eval_condition.
4568 * region-model.h
4569 (region_model::eval_condition_without_cm): Delete decl.
4570
4571 2022-11-08 David Malcolm <[email protected]>
4572
4573 * region-model-impl-calls.cc
4574 (region_model::impl_call_errno_location): New.
4575 * region-model-manager.cc
4576 (region_model_manager::region_model_manager): Initialize
4577 m_thread_local_region and m_errno_region.
4578 * region-model-manager.h (region_model_manager::get_errno_region):
4579 New accessor.
4580 (region_model_manager::m_thread_local_region): New.
4581 (region_model_manager::m_errno_region): New.
4582 * region-model.cc (region_model::on_call_pre): Special-case
4583 "__errno_location".
4584 (region_model::set_errno): New.
4585 * region-model.h (impl_call_errno_location): New decl.
4586 (region_model::set_errno): New decl.
4587 * region.cc (thread_local_region::dump_to_pp): New.
4588 (errno_region::dump_to_pp): New.
4589 * region.h (enum memory_space): Add MEMSPACE_THREAD_LOCAL.
4590 (enum region_kind): Add RK_THREAD_LOCAL and RK_ERRNO.
4591 (class thread_local_region): New.
4592 (is_a_helper <const thread_local_region *>::test): New.
4593 (class errno_region): New.
4594 (is_a_helper <const errno_region *>::test): New.
4595 * store.cc (binding_cluster::escaped_p): New.
4596 (store::escaped_p): Treat errno as always having escaped.
4597 (store::replay_call_summary_cluster): Handle RK_THREAD_LOCAL and
4598 RK_ERRNO.
4599 * store.h (binding_cluster::escaped_p): Remove definition.
4600
4601 2022-11-08 David Malcolm <[email protected]>
4602
4603 * call-info.cc (success_call_info::get_desc): Delete.
4604 (failed_call_info::get_desc): Likewise.
4605 (succeed_or_fail_call_info::get_desc): New.
4606 * call-info.h (class succeed_or_fail_call_info): New.
4607 (class success_call_info): Convert to a subclass of
4608 succeed_or_fail_call_info.
4609 (class failed_call_info): Likewise.
4610
4611 2022-11-08 David Malcolm <[email protected]>
4612
4613 * region-model-impl-calls.cc (region_model::impl_call_strchr):
4614 Move to on_call_post. Handle both outcomes using bifurcation,
4615 rather than just the "not found" case.
4616 * region-model.cc (region_model::on_call_pre): Move
4617 BUILT_IN_STRCHR and "strchr" to...
4618 (region_model::on_call_post): ...here.
4619
4620 2022-11-03 David Malcolm <[email protected]>
4621
4622 * analyzer.h: Use std::unique_ptr for state machines from plugins.
4623 * engine.cc: Likewise.
4624
4625 2022-11-03 David Malcolm <[email protected]>
4626
4627 * analyzer.h: Use std::unique_ptr for known functions.
4628 * engine.cc: Likewise.
4629 * known-function-manager.cc: Likewise.
4630 * known-function-manager.h: Likewise.
4631
4632 2022-11-03 David Malcolm <[email protected]>
4633
4634 * analysis-plan.cc: Define INCLUDE_MEMORY before including
4635 system.h.
4636 * analyzer-pass.cc: Likewise.
4637 * analyzer-selftests.cc: Likewise.
4638 * analyzer.cc: Likewise.
4639 * analyzer.h: Use std::unique_ptr in bifurcation code.
4640 * call-string.cc: Define INCLUDE_MEMORY before including system.h.
4641 * complexity.cc: Likewise.
4642 * engine.cc: Use std::unique_ptr in bifurcation code.
4643 * exploded-graph.h: Likewise.
4644 * known-function-manager.cc: Define INCLUDE_MEMORY before
4645 including system.h.
4646 * region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
4647 code.
4648 * region-model.cc: Likewise.
4649 * region-model.h: Likewise.
4650 * supergraph.cc: Define INCLUDE_MEMORY before including system.h.
4651
4652 2022-11-03 David Malcolm <[email protected]>
4653
4654 * call-info.cc: Use std::unique_ptr for checker_event.
4655 * checker-path.cc: Likewise.
4656 * checker-path.h: Likewise.
4657 * diagnostic-manager.cc: Likewise.
4658 * engine.cc: Likewise.
4659 * pending-diagnostic.cc: Likewise.
4660 * sm-signal.cc: Likewise.
4661 * varargs.cc: Likewise.
4662
4663 2022-11-03 David Malcolm <[email protected]>
4664
4665 * diagnostic-manager.cc: Include "make-unique.h".
4666 Use std::unique_ptr for feasibility_problems and exploded_path.
4667 Delete explicit saved_diagnostic dtor.
4668 * diagnostic-manager.h: Likewise.
4669 * engine.cc: Likewise.
4670 * exploded-graph.h: Likewise.
4671 * feasible-graph.cc: Likewise.
4672 * feasible-graph.h: Likewise.
4673
4674 2022-11-03 David Malcolm <[email protected]>
4675
4676 * checker-path.cc (rewind_event::rewind_event): Update for usage of
4677 std::unique_ptr on custom_edge_info.
4678 * engine.cc (exploded_node::on_longjmp): Likewise.
4679 (exploded_edge::exploded_edge): Likewise.
4680 (exploded_edge::~exploded_edge): Delete.
4681 (exploded_graph::add_function_entry): Update for usage of
4682 std::unique_ptr on custom_edge_info.
4683 (exploded_graph::add_edge): Likewise.
4684 (add_tainted_args_callback): Likewise.
4685 (exploded_graph::maybe_create_dynamic_call): Likewise.
4686 (exploded_graph::process_node): Likewise.
4687 * exploded-graph.h (exploded_edge::~exploded_edge): Delete.
4688 (exploded_edge::m_custom_info): Use std::unique_ptr.
4689 (exploded_edge::add_edge): Likewise.
4690 * sm-signal.cc (register_signal_handler::impl_transition): Use
4691 make_unique.
4692
4693 2022-11-03 David Malcolm <[email protected]>
4694
4695 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Make
4696 stmt_finder const.
4697 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of
4698 m_stmt_finder.
4699 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
4700 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic):
4701 Likewise.
4702 (saved_diagnostic::m_stmt_finder): Convert to std::unique_ptr.
4703 (diagnostic_manager::add_diagnostic): Make stmt_finder const.
4704 * engine.cc (impl_sm_context::impl_sm_context): Likewise.
4705 (impl_sm_context::m_stmt_finder): Likewise.
4706 (leak_stmt_finder::clone): Convert return type to std::unique_ptr.
4707 * exploded-graph.h (stmt_finder::clone): Likewise.
4708
4709 2022-11-03 David Malcolm <[email protected]>
4710
4711 * call-info.cc: Add define of INCLUDE_MEMORY.
4712 * call-summary.cc: Likewise.
4713 * checker-path.cc: Likewise.
4714 * constraint-manager.cc: Likewise.
4715 * diagnostic-manager.cc: Likewise.
4716 (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for
4717 param d and field m_d.
4718 (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d.
4719 (saved_diagnostic::add_note): Use std::unique_ptr for
4720 param pn.
4721 (saved_diagnostic::get_pending_diagnostic): Update for conversion
4722 of m_sd.m_d to unique_ptr.
4723 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
4724 param d. Remove explicit deletion.
4725 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
4726 (diagnostic_manager::emit_saved_diagnostic): Update for conversion
4727 of m_sd.m_d to unique_ptr.
4728 (null_assignment_sm_context::warn): Use std::unique_ptr for
4729 param d. Remove explicit deletion.
4730 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use
4731 std::unique_ptr for param d.
4732 (saved_diagnostic::add_note): Likewise for param pn.
4733 (saved_diagnostic::m_d): Likewise.
4734 (diagnostic_manager::add_diagnostic): Use std::unique_ptr for
4735 param d.
4736 (diagnostic_manager::add_note): Use std::unique_ptr for param pn.
4737 * engine.cc: Include "make-unique.h".
4738 (impl_region_model_context::warn): Update to use std::unique_ptr
4739 for param, removing explicit deletion.
4740 (impl_region_model_context::add_note): Likewise.
4741 (impl_sm_context::warn): Update to use std::unique_ptr
4742 for param.
4743 (impl_region_model_context::on_state_leak): Likewise for result of
4744 on_leak.
4745 (exploded_node::on_longjmp): Use make_unique when creating
4746 pending_diagnostic.
4747 (exploded_graph::process_node): Likewise.
4748 * exploded-graph.h (impl_region_model_context::warn): Update to
4749 use std::unique_ptr for param.
4750 (impl_region_model_context::add_note): Likewise.
4751 * feasible-graph.cc: Add define of INCLUDE_MEMORY.
4752 * pending-diagnostic.cc: Likewise.
4753 * pending-diagnostic.h: Include analyzer.sm.h"
4754 * program-point.cc: Add define of INCLUDE_MEMORY.
4755 * program-state.cc: Likewise.
4756 * region-model-asm.cc: Likewise.
4757 * region-model-impl-calls.cc: Likewise. Include "make-unique.h".
4758 (region_model::impl_call_putenv): Use make_unique when creating
4759 pending_diagnostic.
4760 * region-model-manager.cc: Add define of INCLUDE_MEMORY.
4761 * region-model-reachability.cc: Likewise.
4762 * region-model.cc: Likewise. Include "make-unique.h".
4763 (region_model::get_gassign_result): Use make_unique when creating
4764 pending_diagnostic.
4765 (region_model::check_for_poison): Likewise.
4766 (region_model::on_stmt_pre): Likewise.
4767 (region_model::check_symbolic_bounds): Likewise.
4768 (region_model::check_region_bounds): Likewise.
4769 (annotating_ctxt: make_note): Use std::unique_ptr for result.
4770 (region_model::deref_rvalue): Use make_unique when creating
4771 pending_diagnostic.
4772 (region_model::check_for_writable_region): Likewise.
4773 (region_model::check_region_size): Likewise.
4774 (region_model::check_dynamic_size_for_floats): Likewise.
4775 (region_model::maybe_complain_about_infoleak): Likewise.
4776 (noop_region_model_context::add_note): Use std::unique_ptr for
4777 param. Remove explicit deletion.
4778 * region-model.h: Include "analyzer/pending-diagnostic.h".
4779 (region_model_context::warn): Convert param to std::unique_ptr.
4780 (region_model_context::add_note): Likewise.
4781 (noop_region_model_context::warn): Likewise.
4782 (noop_region_model_context::add_note): Likewise.
4783 (region_model_context_decorator::warn): Likewise.
4784 (region_model_context_decorator::add_note): Likewise.
4785 (note_adding_context::warn): Likewise.
4786 (note_adding_context::make_note): Likewise for return type.
4787 (test_region_model_context::warn): Convert param to
4788 std::unique_ptr.
4789 * region.cc: Add define of INCLUDE_MEMORY.
4790 * sm-fd.cc: Likewise. Include "make-unique.h".
4791 (fd_state_machine::check_for_fd_attrs): Use make_unique when
4792 creating pending_diagnostics.
4793 (fd_state_machine::on_open): Likewise.
4794 (fd_state_machine::on_creat): Likewise.
4795 (fd_state_machine::check_for_dup): Likewise.
4796 (fd_state_machine::on_close): Likewise.
4797 (fd_state_machine::check_for_open_fd): Likewise.
4798 (fd_state_machine::on_leak): Likewise, converting return type to
4799 std::unique_ptr.
4800 * sm-file.cc: Add define of INCLUDE_MEMORY. Include
4801 "make-unique.h".
4802 (fileptr_state_machine::on_stmt): Use make_unique when creating
4803 pending_diagnostic.
4804 (fileptr_state_machine::on_leak): Likewise, converting return type
4805 to std::unique_ptr.
4806 * sm-malloc.cc: Add define of INCLUDE_MEMORY. Include
4807 "make-unique.h".
4808 (malloc_state_machine::on_stmt): Use make_unique when creating
4809 pending_diagnostic.
4810 (malloc_state_machine::handle_free_of_non_heap): Likewise.
4811 (malloc_state_machine::on_deallocator_call): Likewise.
4812 (malloc_state_machine::on_realloc_call): Likewise.
4813 (malloc_state_machine::on_leak): Likewise, converting return type
4814 to std::unique_ptr.
4815 * sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include
4816 "make-unique.h".
4817 (pattern_test_state_machine::on_condition): Use make_unique when
4818 creating pending_diagnostic.
4819 * sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include
4820 "make-unique.h".
4821 (sensitive_state_machine::warn_for_any_exposure): Use make_unique
4822 when creating pending_diagnostic.
4823 * sm-signal.cc: Add define of INCLUDE_MEMORY. Include
4824 "make-unique.h".
4825 (signal_state_machine::on_stmt): Use make_unique when creating
4826 pending_diagnostic.
4827 * sm-taint.cc: Add define of INCLUDE_MEMORY. Include
4828 "make-unique.h".
4829 (taint_state_machine::check_for_tainted_size_arg): Use make_unique
4830 when creating pending_diagnostic.
4831 (taint_state_machine::check_for_tainted_divisor): Likewise.
4832 (region_model::check_region_for_taint): Likewise.
4833 (region_model::check_dynamic_size_for_taint): Likewise.
4834 * sm.cc: Add define of INCLUDE_MEMORY. Include
4835 "analyzer/pending-diagnostic.h".
4836 (state_machine::on_leak): Move here from sm.h, changing return
4837 type to std::unique_ptr.
4838 * sm.h (state_machine::on_leak): Change return type to
4839 std::unique_ptr. Move defn of base impl to sm.cc
4840 (sm_context::warn): Convert param d to std_unique_ptr.
4841 * state-purge.cc: Add define of INCLUDE_MEMORY.
4842 * store.cc: Likewise.
4843 * svalue.cc: Likewise.
4844 * trimmed-graph.cc: Likewise.
4845 * varargs.cc: Likewise. Include "make-unique.h".
4846 (va_list_state_machine::check_for_ended_va_list): Use make_unique
4847 when creating pending_diagnostic.
4848 (va_list_state_machine::on_leak): Likewise, converting return type
4849 to std::unique_ptr.
4850 (region_model::impl_call_va_arg): Use make_unique when creating
4851 pending_diagnostic.
4852
4853 2022-11-03 David Malcolm <[email protected]>
4854
4855 PR analyzer/107486
4856 * analyzer.cc (is_pipe_call_p): New.
4857 * analyzer.h (is_pipe_call_p): New decl.
4858 * region-model.cc (region_model::on_call_pre): Use it.
4859 (region_model::on_call_post): Likewise.
4860
4861 2022-10-26 David Malcolm <[email protected]>
4862
4863 * sm-fd.cc (fd_state_machine::on_open): Transition to "unchecked"
4864 when the mode is symbolic, rather than just on integer constants.
4865 (fd_state_machine::check_for_open_fd): Don't complain about
4866 unchecked values in the start state.
4867
4868 2022-10-26 David Malcolm <[email protected]>
4869
4870 * sm-fd.dot: New file.
4871
4872 2022-10-24 David Malcolm <[email protected]>
4873
4874 PR analyzer/107349
4875 * varargs.cc (get_va_copy_arg): Fix the non-pointer case.
4876
4877 2022-10-24 David Malcolm <[email protected]>
4878
4879 PR analyzer/107345
4880 * region-model.cc (region_model::eval_condition_without_cm):
4881 Ensure that constants are on the right-hand side before checking
4882 for them.
4883
4884 2022-10-24 David Malcolm <[email protected]>
4885
4886 * engine.cc (impl_region_model_context::get_malloc_map): Replace
4887 with...
4888 (impl_region_model_context::get_state_map_by_name): ...this.
4889 (impl_region_model_context::get_fd_map): Delete.
4890 (impl_region_model_context::get_taint_map): Delete.
4891 * exploded-graph.h (impl_region_model_context::get_fd_map):
4892 Delete.
4893 (impl_region_model_context::get_malloc_map): Delete.
4894 (impl_region_model_context::get_taint_map): Delete.
4895 (impl_region_model_context::get_state_map_by_name): New.
4896 * region-model.h (region_model_context::get_state_map_by_name):
4897 New vfunc.
4898 (region_model_context::get_fd_map): Convert from vfunc to
4899 function.
4900 (region_model_context::get_malloc_map): Likewise.
4901 (region_model_context::get_taint_map): Likewise.
4902 (noop_region_model_context::get_state_map_by_name): New.
4903 (noop_region_model_context::get_fd_map): Delete.
4904 (noop_region_model_context::get_malloc_map): Delete.
4905 (noop_region_model_context::get_taint_map): Delete.
4906 (region_model_context_decorator::get_state_map_by_name): New.
4907 (region_model_context_decorator::get_fd_map): Delete.
4908 (region_model_context_decorator::get_malloc_map): Delete.
4909 (region_model_context_decorator::get_taint_map): Delete.
4910
4911 2022-10-24 David Malcolm <[email protected]>
4912
4913 PR analyzer/106300
4914 * engine.cc (impl_region_model_context::get_fd_map): New.
4915 * exploded-graph.h (impl_region_model_context::get_fd_map): New
4916 decl.
4917 * region-model-impl-calls.cc (region_model::impl_call_pipe): New.
4918 * region-model.cc (region_model::update_for_int_cst_return): New,
4919 based on...
4920 (region_model::update_for_zero_return): ...this. Reimplement in
4921 terms of the former.
4922 (region_model::on_call_pre): Handle "pipe" and "pipe2".
4923 (region_model::on_call_post): Likewise.
4924 * region-model.h (region_model::impl_call_pipe): New decl.
4925 (region_model::update_for_int_cst_return): New decl.
4926 (region_model::mark_as_valid_fd): New decl.
4927 (region_model_context::get_fd_map): New pure virtual fn.
4928 (noop_region_model_context::get_fd_map): New.
4929 (region_model_context_decorator::get_fd_map): New.
4930 * sm-fd.cc: Include "analyzer/program-state.h".
4931 (fd_state_machine::describe_state_change): Handle transitions from
4932 start state to valid states.
4933 (fd_state_machine::mark_as_valid_fd): New.
4934 (fd_state_machine::on_stmt): Add missing return for "creat".
4935 (region_model::mark_as_valid_fd): New.
4936
4937 2022-10-19 David Malcolm <[email protected]>
4938
4939 PR analyzer/105765
4940 * varargs.cc (get_BT_VALIST_ARG): Rename to...
4941 (get_va_copy_arg): ...this, and update logic for determining level
4942 of indirection of va_copy's argument to use type of argument,
4943 rather than looking at va_list_type_node, to correctly handle
4944 __builtin_ms_va_copy.
4945 (get_stateful_BT_VALIST_ARG): Rename to...
4946 (get_stateful_va_copy_arg): ...this.
4947 (va_list_state_machine::on_va_copy): Update for renaming.
4948 (region_model::impl_call_va_copy): Likewise.
4949
4950 2022-10-13 David Malcolm <[email protected]>
4951
4952 PR analyzer/107210
4953 * svalue.cc (constant_svalue::maybe_fold_bits_within): Only
4954 attempt to extract individual bits when tree_fits_uhwi_p.
4955
4956 2022-10-07 David Malcolm <[email protected]>
4957
4958 PR analyzer/105783
4959 * region-model.cc (selftest::get_bit): New function.
4960 (selftest::test_bits_within_svalue_folding): New.
4961 (selfftest::analyzer_region_model_cc_tests): Call it.
4962 * svalue.cc (constant_svalue::maybe_fold_bits_within): Handle the
4963 case of extracting a single bit.
4964
4965 2022-10-06 David Malcolm <[email protected]>
4966
4967 PR analyzer/107158
4968 * store.cc (store::replay_call_summary_cluster): Eliminate
4969 special-casing of RK_HEAP_ALLOCATED in favor of sharing code with
4970 RK_DECL, avoiding an ICE due to attempting to bind a
4971 compound_svalue into a binding_cluster when an svalue in the
4972 summary cluster converts to a compound_svalue in the caller.
4973
4974 2022-10-06 David Malcolm <[email protected]>
4975
4976 * call-summary.cc (call_summary_replay::dump_to_pp): Bulletproof
4977 against NULL caller regions/svalues.
4978
4979 2022-10-05 David Malcolm <[email protected]>
4980
4981 * analysis-plan.cc: Simplify includes.
4982 * analyzer-pass.cc: Likewise.
4983 * analyzer-selftests.cc: Likewise.
4984 * analyzer.cc: Likewise.
4985 * analyzer.h: Add includes of "json.h" and "tristate.h".
4986 * call-info.cc: Simplify includes.
4987 * call-string.cc: Likewise.
4988 * call-summary.cc: Likewise.
4989 * checker-path.cc: Likewise.
4990 * complexity.cc: Likewise.
4991 * constraint-manager.cc: Likewise.
4992 * diagnostic-manager.cc: Likewise.
4993 * engine.cc: Likewise.
4994 * feasible-graph.cc: Likewise.
4995 * known-function-manager.cc: Likewise.
4996 * pending-diagnostic.cc: Likewise.
4997 * program-point.cc: Likewise.
4998 * program-state.cc: Likewise.
4999 * region-model-asm.cc: Likewise.
5000 * region-model-impl-calls.cc: Likewise.
5001 * region-model-manager.cc: Likewise.
5002 * region-model-reachability.cc: Likewise.
5003 * region-model.cc: Likewise.
5004 * region-model.h: Include "selftest.h".
5005 * region.cc: Simplify includes.
5006 * sm-fd.cc: Likewise.
5007 * sm-file.cc: Likewise.
5008 * sm-malloc.cc: Likewise.
5009 * sm-pattern-test.cc: Likewise.
5010 * sm-sensitive.cc: Likewise.
5011 * sm-signal.cc: Likewise.
5012 * sm-taint.cc: Likewise.
5013 * sm.cc: Likewise.
5014 * state-purge.cc: Likewise.
5015 * store.cc: Likewise.
5016 * store.h: Likewise.
5017 * supergraph.cc: Likewise.
5018 * svalue.cc: Likewise.
5019 * svalue.h: Likewise.
5020 * trimmed-graph.cc: Likewise.
5021 * varargs.cc: Likewise.
5022
5023 2022-10-05 David Malcolm <[email protected]>
5024
5025 PR analyzer/107060
5026 * call-summary.cc
5027 (call_summary_replay::convert_svalue_from_summary_1): Handle NULL
5028 results from convert_svalue_from_summary in SK_UNARY_OP and
5029 SK_BIN_OP.
5030 * engine.cc (impl_region_model_context::on_unknown_change): Bail
5031 out on svalues that can't have associated state.
5032 * region-model-impl-calls.cc
5033 (region_model::impl_call_analyzer_get_unknown_ptr): New.
5034 * region-model.cc (region_model::on_stmt_pre): Handle
5035 "__analyzer_get_unknown_ptr".
5036 * region-model.h
5037 (region_model::impl_call_analyzer_get_unknown_ptr): New decl.
5038 * store.cc (store::replay_call_summary_cluster): Avoid trying to
5039 create binding clusters for base regions that shouldn't have them.
5040
5041 2022-10-05 Martin Liska <[email protected]>
5042
5043 * call-summary.cc (call_summary_replay::call_summary_replay):
5044 Remove unused variable and arguments.
5045 * call-summary.h: Likewise.
5046 * engine.cc (exploded_node::on_stmt): Likewise.
5047 (exploded_node::replay_call_summaries): Likewise.
5048 (exploded_node::replay_call_summary): Likewise.
5049 * exploded-graph.h (class exploded_node): Likewise.
5050
5051 2022-10-05 David Malcolm <[email protected]>
5052
5053 PR analyzer/107072
5054 * analyzer-logging.h: Include "diagnostic-core.h".
5055 * analyzer.h: Include "function.h".
5056 (class call_summary): New forward decl.
5057 (class call_summary_replay): New forward decl.
5058 (struct per_function_data): New forward decl.
5059 (struct interesting_t): New forward decl.
5060 (custom_edge_info::update_state): New vfunc.
5061 * call-info.cc (custom_edge_info::update_state): New.
5062 * call-summary.cc: New file.
5063 * call-summary.h: New file.
5064 * constraint-manager.cc: Include "analyzer/call-summary.h".
5065 (class replay_fact_visitor): New.
5066 (constraint_manager::replay_call_summary): New.
5067 * constraint-manager.h (constraint_manager::replay_call_summary):
5068 New.
5069 * engine.cc: Include "analyzer/call-summary.h".
5070 (exploded_node::on_stmt): Handle call summaries.
5071 (class call_summary_edge_info): New.
5072 (exploded_node::replay_call_summaries): New.
5073 (exploded_node::replay_call_summary): New.
5074 (per_function_data::~per_function_data): New.
5075 (per_function_data::add_call_summary): Move here from header and
5076 reimplement.
5077 (exploded_graph::process_node): Call update_state rather than
5078 update_model when handling bifurcation
5079 (viz_callgraph_node::dump_dot): Use a regular label rather
5080 than an HTML table; add summaries to dump.
5081 * exploded-graph.h: Include "alloc-pool.h", "fibonacci_heap.h",
5082 "supergraph.h", "sbitmap.h", "shortest-paths.h", "analyzer/sm.h",
5083 "analyzer/program-state.h", and "analyzer/diagnostic-manager.h".
5084 (exploded_node::replay_call_summaries): New decl.
5085 (exploded_node::replay_call_summary): New decl.
5086 (per_function_data::~per_function_data): New decl.
5087 (per_function_data::add_call_summary): Move implemention from
5088 header.
5089 (per_function_data::m_summaries): Update type of element.
5090 * known-function-manager.h: Include "analyzer/analyzer-logging.h".
5091 * program-point.h: Include "pretty-print.h" and
5092 "analyzer/call-string.h".
5093 * program-state.cc: Include "analyzer/call-summary.h".
5094 (sm_state_map::replay_call_summary): New.
5095 (program_state::replay_call_summary): New.
5096 * program-state.h (sm_state_map::replay_call_summary): New decl.
5097 (program_state::replay_call_summary): New decl.
5098 * region-model-manager.cc
5099 (region_model_manager::get_or_create_asm_output_svalue): New
5100 overload.
5101 * region-model-manager.h
5102 (region_model_manager::get_or_create_asm_output_svalue): New
5103 overload decl.
5104 * region-model.cc: Include "analyzer/call-summary.h".
5105 (region_model::maybe_update_for_edge): Remove call to
5106 region_model::update_for_call_summary on
5107 SUPEREDGE_INTRAPROCEDURAL_CALL.
5108 (region_model::update_for_call_summary): Delete.
5109 (region_model::replay_call_summary): New.
5110 * region-model.h (region_model::replay_call_summary): New decl.
5111 (region_model::update_for_call_summary): Delete decl.
5112 * store.cc: Include "analyzer/call-summary.h".
5113 (store::replay_call_summary): New.
5114 (store::replay_call_summary_cluster): New.
5115 * store.h: Include "tristate.h".
5116 (is_a_helper <const ana::concrete_binding *>::test): New.
5117 (store::replay_call_summary): New decl.
5118 (store::replay_call_summary_cluster): New decl.
5119 * supergraph.cc (get_ultimate_function_for_cgraph_edge): Remove
5120 "static" from decl.
5121 (supergraph_call_edge): Make stmt param const.
5122 * supergraph.h: Include "ordered-hash-map.h", "cfg.h",
5123 "basic-block.h", "gimple.h", "gimple-iterator.h", and "digraph.h".
5124 (supergraph_call_edge): Make stmt param const.
5125 (get_ultimate_function_for_cgraph_edge): New decl.
5126 * svalue.cc (compound_svalue::compound_svalue): Assert that we're
5127 not nesting compound_svalues.
5128 * svalue.h: Include "json.h", "analyzer/store.h", and
5129 "analyzer/program-point.h".
5130 (asm_output_svalue::get_num_outputs): New accessor.
5131
5132 2022-10-05 David Malcolm <[email protected]>
5133
5134 * region-model.h: Include "analyzer/region-model-manager.h"
5135 (class region_model_manager): Move decl to...
5136 * region-model-manager.h: ...this new file.
5137
5138 2022-10-05 David Malcolm <[email protected]>
5139
5140 * region-model-manager.cc
5141 (region_model_manager::maybe_fold_unaryop): Fold -(-(VAL)) to VAL.
5142
5143 2022-10-05 David Malcolm <[email protected]>
5144
5145 * region-model-manager.cc
5146 (region_model_manager::get_or_create_widening_svalue): Use a
5147 function_point rather than a program_point.
5148 * region-model.cc (selftest::test_widening_constraints): Likewise.
5149 * region-model.h
5150 (region_model_manager::get_or_create_widening_svalue): Likewise.
5151 (model_merger::get_function_point): New.
5152 * svalue.cc (svalue::can_merge_p): Use a function_point rather
5153 than a program_point.
5154 (svalue::can_merge_p): Likewise.
5155 * svalue.h (widening_svalue::key_t): Likewise.
5156 (widening_svalue::widening_svalue): Likewise.
5157
5158 2022-09-12 Martin Liska <[email protected]>
5159
5160 * region-model.cc (region_model::maybe_complain_about_infoleak):
5161 Remove unused fields.
5162
5163 2022-09-11 Tim Lange <[email protected]>
5164
5165 PR analyzer/106845
5166 * region-model.cc (region_model::check_region_bounds):
5167 Bail out if 0 bytes were accessed.
5168 * store.cc (byte_range::dump_to_pp):
5169 Add special case for empty ranges.
5170 (byte_range::exceeds_p): Restrict to non-empty ranges.
5171 (byte_range::falls_short_of_p): Restrict to non-empty ranges.
5172 * store.h (bit_range::empty_p): New function.
5173 (bit_range::get_last_byte_offset): Restrict to non-empty ranges.
5174 (byte_range::empty_p): New function.
5175 (byte_range::get_last_byte_offset): Restrict to non-empty ranges.
5176
5177 2022-09-09 David Malcolm <[email protected]>
5178
5179 * analyzer.opt (Wanalyzer-exposure-through-uninit-copy): New.
5180 * checker-path.cc (region_creation_event::region_creation_event):
5181 Add "capacity" and "kind" params.
5182 (region_creation_event::get_desc): Generalize to different kinds
5183 of event.
5184 (checker_path::add_region_creation_event): Convert to...
5185 (checker_path::add_region_creation_events): ...this.
5186 * checker-path.h (enum rce_kind): New.
5187 (region_creation_event::region_creation_event): Add "capacity" and
5188 "kind" params.
5189 (region_creation_event::m_capacity): New field.
5190 (region_creation_event::m_rce_kind): New field.
5191 (checker_path::add_region_creation_event): Convert to...
5192 (checker_path::add_region_creation_events): ...this.
5193 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
5194 Update for multiple region creation events.
5195 (diagnostic_manager::add_event_on_final_node): Likewise.
5196 (diagnostic_manager::add_events_for_eedge): Likewise.
5197 * region-model-impl-calls.cc (call_details::get_logger): New.
5198 * region-model.cc: Define INCLUDE_MEMORY before including
5199 "system.h". Include "gcc-rich-location.h".
5200 (class record_layout): New.
5201 (class exposure_through_uninit_copy): New.
5202 (contains_uninit_p): New.
5203 (region_model::maybe_complain_about_infoleak): New.
5204 * region-model.h (call_details::get_logger): New decl.
5205 (region_model::maybe_complain_about_infoleak): New decl.
5206 (region_model::mark_as_tainted): New decl.
5207 * sm-taint.cc (region_model::mark_as_tainted): New.
5208
5209 2022-09-09 David Malcolm <[email protected]>
5210
5211 * analyzer.h (class known_function_manager): New forward decl.
5212 (class known_function): New.
5213 (plugin_analyzer_init_iface::register_known_function): New.
5214 * engine.cc: Include "analyzer/known-function-manager.h".
5215 (plugin_analyzer_init_impl::plugin_analyzer_init_impl): Add
5216 known_fn_mgr param.
5217 (plugin_analyzer_init_impl::register_state_machine): Add
5218 LOC_SCOPE.
5219 (plugin_analyzer_init_impl::register_known_function): New.
5220 (plugin_analyzer_init_impl::m_known_fn_mgr): New.
5221 (impl_run_checkers): Update plugin callback invocation to use
5222 eng's known_function_manager.
5223 * known-function-manager.cc: New file.
5224 * known-function-manager.h: New file.
5225 * region-model-manager.cc
5226 (region_model_manager::region_model_manager): Pass logger to
5227 m_known_fn_mgr's ctor.
5228 * region-model.cc (region_model::update_for_zero_return): New.
5229 (region_model::update_for_nonzero_return): New.
5230 (maybe_simplify_upper_bound): New.
5231 (region_model::maybe_get_copy_bounds): New.
5232 (region_model::get_known_function): New.
5233 (region_model::on_call_pre): Handle plugin-supplied known
5234 functions.
5235 * region-model.h: Include "analyzer/known-function-manager.h".
5236 (region_model_manager::get_known_function_manager): New.
5237 (region_model_manager::m_known_fn_mgr): New.
5238 (call_details::get_model): New accessor.
5239 (region_model::maybe_get_copy_bounds): New decl.
5240 (region_model::update_for_zero_return): New decl.
5241 (region_model::update_for_nonzero_return): New decl.
5242 (region_model::get_known_function): New decl.
5243 (region_model::get_known_function_manager): New.
5244
5245 2022-09-08 Tim Lange <[email protected]>
5246
5247 PR analyzer/106625
5248 * analyzer.h (region_offset): Eliminate m_is_symbolic member.
5249 * region-model-impl-calls.cc (region_model::impl_call_realloc):
5250 Refine implementation to be more precise.
5251 * region-model.cc (class symbolic_past_the_end):
5252 Abstract diagnostic class to complain about accesses past the end
5253 with symbolic values.
5254 (class symbolic_buffer_overflow):
5255 Concrete diagnostic class to complain about buffer overflows with
5256 symbolic values.
5257 (class symbolic_buffer_overread):
5258 Concrete diagnostic class to complain about buffer overreads with
5259 symbolic values.
5260 (region_model::check_symbolic_bounds): New function.
5261 (maybe_get_integer_cst_tree): New helper function.
5262 (region_model::check_region_bounds):
5263 Add call to check_symbolic_bounds if offset is not concrete.
5264 (region_model::eval_condition_without_cm):
5265 Add support for EQ_EXPR and GT_EXPR with binaryop_svalues.
5266 (is_positive_svalue): New hleper function.
5267 (region_model::symbolic_greater_than):
5268 New function to handle GT_EXPR comparisons with symbolic values.
5269 (region_model::structural_equality): New function to compare
5270 whether two svalues are structured the same, i.e. evaluate to
5271 the same value.
5272 (test_struct): Reflect changes to region::calc_offset.
5273 (test_var): Likewise.
5274 (test_array_2): Likewise and add selftest with symbolic i.
5275 * region-model.h (class region_model): Add check_symbolic_bounds,
5276 symbolic_greater_than and structural_equality.
5277 * region.cc (region::get_offset):
5278 Reflect changes to region::calc_offset.
5279 (region::calc_offset):
5280 Compute the symbolic offset if the offset is not concrete.
5281 (region::get_relative_symbolic_offset): New function to return the
5282 symbolic offset in bytes relative to its parent.
5283 (field_region::get_relative_symbolic_offset): Likewise.
5284 (element_region::get_relative_symbolic_offset): Likewise.
5285 (offset_region::get_relative_symbolic_offset): Likewise.
5286 (bit_range_region::get_relative_symbolic_offset): Likewise.
5287 * region.h: Add get_relative_symbolic_offset.
5288 * store.cc (binding_key::make):
5289 Reflect changes to region::calc_offset.
5290 (binding_map::apply_ctor_val_to_range): Likewise.
5291 (binding_map::apply_ctor_pair_to_child_region): Likewise.
5292 (binding_cluster::bind_compound_sval): Likewise.
5293 (binding_cluster::get_any_binding): Likewise.
5294 (binding_cluster::maybe_get_compound_binding): Likewise.
5295
5296 2022-09-05 Tim Lange <[email protected]>
5297
5298 * region-model-impl-calls.cc (region_model::impl_call_strcpy):
5299 Handle the constant string case.
5300 * region-model.cc (region_model::get_string_size):
5301 New function to get the string size from a region or svalue.
5302 * region-model.h (class region_model): Add get_string_size.
5303
5304 2022-09-05 Tim Lange <[email protected]>
5305
5306 * region.cc (cast_region::get_relative_concrete_offset):
5307 New overloaded method.
5308 * region.h: Add cast_region::get_relative_concrete_offset.
5309
5310 2022-08-22 Martin Liska <[email protected]>
5311
5312 * region-model.cc: Add missing final keyword.
5313
5314 2022-08-18 Tim Lange <[email protected]>
5315
5316 PR analyzer/106181
5317 * analyzer.opt: Add Wanalyzer-imprecise-floating-point-arithmetic.
5318 * region-model.cc (is_any_cast_p): Formatting.
5319 (region_model::check_region_size): Ensure precondition.
5320 (class imprecise_floating_point_arithmetic): New abstract
5321 diagnostic class for all floating-point related warnings.
5322 (class float_as_size_arg): Concrete diagnostic class to complain
5323 about floating-point operands inside the size argument.
5324 (class contains_floating_point_visitor):
5325 New visitor to find floating-point operands inside svalues.
5326 (region_model::check_dynamic_size_for_floats): New function.
5327 (region_model::set_dynamic_extents):
5328 Call to check_dynamic_size_for_floats.
5329 * region-model.h (class region_model):
5330 Add region_model::check_dynamic_size_for_floats.
5331
5332 2022-08-16 Martin Liska <[email protected]>
5333
5334 * region-model.cc: Fix -Winconsistent-missing-override clang
5335 warning.
5336 * region.h: Likewise.
5337
5338 2022-08-15 David Malcolm <[email protected]>
5339
5340 PR analyzer/106626
5341 * region-model.cc (buffer_overread::emit): Fix copy&paste error in
5342 direction of the access in the note.
5343
5344 2022-08-15 David Malcolm <[email protected]>
5345
5346 PR analyzer/106573
5347 * region-model.cc (region_model::on_call_pre): Use check_call_args
5348 when ensuring that we call get_arg_svalue on all args. Remove
5349 redundant call from handling for stdio builtins.
5350
5351 2022-08-15 Immad Mir <[email protected]>
5352
5353 PR analyzer/106551
5354 * sm-fd.cc (check_for_dup): exit early if first
5355 argument is invalid for all dup functions.
5356
5357 2022-08-12 Tim Lange <[email protected]>
5358
5359 PR analyzer/106000
5360 * analyzer.opt: Add Wanalyzer-out-of-bounds.
5361 * region-model.cc (class out_of_bounds): Diagnostics base class
5362 for all out-of-bounds diagnostics.
5363 (class past_the_end): Base class derived from out_of_bounds for
5364 the buffer_overflow and buffer_overread diagnostics.
5365 (class buffer_overflow): Buffer overflow diagnostics.
5366 (class buffer_overread): Buffer overread diagnostics.
5367 (class buffer_underflow): Buffer underflow diagnostics.
5368 (class buffer_underread): Buffer overread diagnostics.
5369 (region_model::check_region_bounds): New function to check region
5370 bounds for out-of-bounds accesses.
5371 (region_model::check_region_access):
5372 Add call to check_region_bounds.
5373 (region_model::get_representative_tree): New function that accepts
5374 a region instead of an svalue.
5375 * region-model.h (class region_model):
5376 Add region_model::check_region_bounds.
5377 * region.cc (region::symbolic_p): New predicate.
5378 (offset_region::get_byte_size_sval): Only return the remaining
5379 byte size on offset_regions.
5380 * region.h: Add region::symbolic_p.
5381 * store.cc (byte_range::intersects_p):
5382 Add new function equivalent to bit_range::intersects_p.
5383 (byte_range::exceeds_p): New function.
5384 (byte_range::falls_short_of_p): New function.
5385 * store.h (struct byte_range): Add byte_range::intersects_p,
5386 byte_range::exceeds_p and byte_range::falls_short_of_p.
5387
5388 2022-08-12 Tim Lange <[email protected]>
5389
5390 PR analyzer/106539
5391 * region-model-impl-calls.cc (region_model::impl_call_realloc):
5392 Use the result of get_copied_size as the size for the
5393 sized_regions in realloc.
5394 (success_with_move::get_copied_size): New function.
5395
5396 2022-08-11 Immad Mir <[email protected]>
5397
5398 PR analyzer/106551
5399 * sm-fd.cc (check_for_dup): handle the m_start
5400 state when transitioning the state of LHS
5401 of dup, dup2 and dup3 call.
5402
5403 2022-08-09 David Malcolm <[email protected]>
5404
5405 PR analyzer/106573
5406 * region-model.cc (region_model::on_call_pre): Ensure that we call
5407 get_arg_svalue on all arguments.
5408
5409 2022-08-05 David Malcolm <[email protected]>
5410
5411 PR analyzer/105947
5412 * analyzer.opt (Wanalyzer-jump-through-null): New option.
5413 * engine.cc (class jump_through_null): New.
5414 (exploded_graph::process_node): Complain about jumps through NULL
5415 function pointers.
5416
5417 2022-08-02 Immad Mir <[email protected]>
5418
5419 PR analyzer/106298
5420 * sm-fd.cc (fd_state_machine::on_open): Add
5421 creat, dup, dup2 and dup3 functions.
5422 (enum dup): New.
5423 (fd_state_machine::valid_to_unchecked_state): New.
5424 (fd_state_machine::on_creat): New.
5425 (fd_state_machine::on_dup): New.
5426
5427 2022-07-28 David Malcolm <[email protected]>
5428
5429 PR analyzer/105893
5430 * analyzer.opt (Wanalyzer-putenv-of-auto-var): New.
5431 * region-model-impl-calls.cc (class putenv_of_auto_var): New.
5432 (region_model::impl_call_putenv): New.
5433 * region-model.cc (region_model::on_call_pre): Handle putenv.
5434 * region-model.h (region_model::impl_call_putenv): New decl.
5435
5436 2022-07-28 David Malcolm <[email protected]>
5437
5438 * sm-malloc.cc (free_of_non_heap::emit): Add comment about CWE.
5439 * sm-taint.cc (tainted_size::emit): Likewise.
5440
5441 2022-07-28 David Malcolm <[email protected]>
5442
5443 * region.h: Add notes to the comment describing the region
5444 class hierarchy.
5445
5446 2022-07-27 Immad Mir <[email protected]>
5447
5448 PR analyzer/106286
5449 * sm-fd.cc:
5450 (fd_diagnostic::get_meaning_for_state_change): New.
5451
5452 2022-07-26 David Malcolm <[email protected]>
5453
5454 PR analyzer/106319
5455 * store.cc (store::set_value): Don't strip away casts if the
5456 region has NULL type.
5457
5458 2022-07-26 David Malcolm <[email protected]>
5459
5460 * region.h (code_region::get_element): Remove stray decl.
5461 (function_region::get_element): Likewise.
5462
5463 2022-07-25 Martin Liska <[email protected]>
5464
5465 * sm-fd.cc: Run dos2unix and fix coding style issues.
5466
5467 2022-07-23 Immad Mir <[email protected]>
5468
5469 * sm-fd.cc (fd_param_diagnostic): New diagnostic class.
5470 (fd_access_mode_mismatch): Change inheritance from fd_diagnostic
5471 to fd_param_diagnostic. Add new overloaded constructor.
5472 (fd_use_after_close): Likewise.
5473 (unchecked_use_of_fd): Likewise and also change name to fd_use_without_check.
5474 (double_close): Change name to fd_double_close.
5475 (enum access_directions): New.
5476 (fd_state_machine::on_stmt): Handle calls to function with the
5477 new three function attributes.
5478 (fd_state_machine::check_for_fd_attrs): New.
5479 (fd_state_machine::on_open): Use the new overloaded constructors
5480 of diagnostic classes.
5481
5482 2022-07-22 David Malcolm <[email protected]>
5483
5484 PR analyzer/106413
5485 * varargs.cc (region_model::impl_call_va_start): Avoid iterating
5486 through non-existant variadic arguments by initializing the
5487 impl_region to "UNKNOWN" if the va_start occurs in the top-level
5488 function to the analysis.
5489
5490 2022-07-22 David Malcolm <[email protected]>
5491
5492 PR analyzer/106401
5493 * store.cc (binding_cluster::binding_cluster): Remove overzealous
5494 assertion; we're checking for tracked_p in
5495 store::get_or_create_cluster.
5496
5497 2022-07-22 Tim Lange <[email protected]>
5498
5499 PR analyzer/106394
5500 * region-model.cc (capacity_compatible_with_type): Always return true
5501 if alloc_size is zero.
5502
5503 2022-07-21 David Malcolm <[email protected]>
5504
5505 PR analyzer/106383
5506 * varargs.cc (region_model::impl_call_va_arg): When determining if
5507 we're doing interprocedural analysis, use the stack depth of the
5508 frame in which va_start was called, rather than the current stack
5509 depth.
5510
5511 2022-07-21 David Malcolm <[email protected]>
5512
5513 * sm-taint.cc (tainted_array_index::emit): Bulletproof against
5514 NULL m_arg.
5515 (tainted_array_index::describe_final_event): Likewise.
5516 (tainted_size::emit): Likewise.
5517 (tainted_size::describe_final_event): Likewise.
5518
5519 2022-07-21 David Malcolm <[email protected]>
5520
5521 PR analyzer/106374
5522 * region.cc (decl_region::get_svalue_for_initializer): Bail out on
5523 untracked regions.
5524
5525 2022-07-20 David Malcolm <[email protected]>
5526
5527 PR analyzer/106373
5528 * sm-taint.cc (taint_state_machine::on_condition): Potentially
5529 update the state of the RHS as well as the LHS.
5530
5531 2022-07-20 David Malcolm <[email protected]>
5532
5533 PR analyzer/106359
5534 * region.h (string_region::tracked_p): New.
5535 * store.cc (binding_cluster::binding_cluster): Move here from
5536 store.h. Add assertion that base_region is tracked_p.
5537 * store.h (binding_cluster::binding_cluster): Move to store.cc.
5538
5539 2022-07-19 David Malcolm <[email protected]>
5540
5541 PR analyzer/106321
5542 * constraint-manager.h (bounded_ranges::get_count): New.
5543 (bounded_ranges::get_range): New.
5544 * engine.cc (impl_region_model_context::on_bounded_ranges): New.
5545 * exploded-graph.h (impl_region_model_context::on_bounded_ranges):
5546 New decl.
5547 * region-model.cc (region_model::apply_constraints_for_gswitch):
5548 Potentially call ctxt->on_bounded_ranges.
5549 * region-model.h (region_model_context::on_bounded_ranges): New
5550 vfunc.
5551 (noop_region_model_context::on_bounded_ranges): New.
5552 (region_model_context_decorator::on_bounded_ranges): New.
5553 * sm-taint.cc: Include "analyzer/constraint-manager.h".
5554 (taint_state_machine::on_bounded_ranges): New.
5555 * sm.h (state_machine::on_bounded_ranges): New.
5556
5557 2022-07-19 David Malcolm <[email protected]>
5558
5559 * engine.cc (exploded_graph::process_node): Show any description
5560 of the out-edge when logging it for consideration.
5561
5562 2022-07-15 David Malcolm <[email protected]>
5563
5564 PR analyzer/106284
5565 * sm-taint.cc (taint_state_machine::on_condition): Handle range
5566 checks optimized by build_range_check.
5567
5568 2022-07-15 Jonathan Wakely <[email protected]>
5569
5570 * call-info.cc (call_info::print): Adjust to new label_text API.
5571 * checker-path.cc (checker_event::dump): Likewise.
5572 (region_creation_event::get_desc): Likewise.
5573 (state_change_event::get_desc): Likewise.
5574 (superedge_event::should_filter_p): Likewise.
5575 (start_cfg_edge_event::get_desc): Likewise.
5576 (call_event::get_desc): Likewise.
5577 (return_event::get_desc): Likewise.
5578 (warning_event::get_desc): Likewise.
5579 (checker_path::dump): Likewise.
5580 (checker_path::debug): Likewise.
5581 * diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic):
5582 Likewise.
5583 (diagnostic_manager::prune_interproc_events): Likewise.
5584 * engine.cc (feasibility_state::maybe_update_for_edge):
5585 Likewise.
5586 * program-state.cc (sm_state_map::to_json): Likewise.
5587 * region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise.
5588 (region_model::impl_call_analyzer_dump_capacity): Likewise.
5589 * region.cc (region::to_json): Likewise.
5590 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
5591 * store.cc (binding_map::to_json): Likewise.
5592 (store::to_json): Likewise.
5593 * supergraph.cc (superedge::dump): Likewise.
5594 * svalue.cc (svalue::to_json): Likewise.
5595
5596 2022-07-07 David Malcolm <[email protected]>
5597
5598 * checker-path.cc (start_cfg_edge_event::get_desc): Update for
5599 superedge::get_description returning a label_text.
5600 * engine.cc (feasibility_state::maybe_update_for_edge): Likewise.
5601 * supergraph.cc (superedge::dump): Likewise.
5602 (superedge::get_description): Convert return type from char * to
5603 label_text.
5604 * supergraph.h (superedge::get_description): Likewise.
5605
5606 2022-07-07 David Malcolm <[email protected]>
5607
5608 * call-info.cc (call_info::print): Update for removal of
5609 label_text::maybe_free in favor of automatic memory management.
5610 * checker-path.cc (checker_event::dump): Likewise.
5611 (checker_event::prepare_for_emission): Likewise.
5612 (state_change_event::get_desc): Likewise.
5613 (superedge_event::should_filter_p): Likewise.
5614 (start_cfg_edge_event::get_desc): Likewise.
5615 (warning_event::get_desc): Likewise.
5616 (checker_path::dump): Likewise.
5617 (checker_path::debug): Likewise.
5618 * diagnostic-manager.cc
5619 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
5620 (diagnostic_manager::prune_interproc_events): Likewise.
5621 * program-state.cc (sm_state_map::to_json): Likewise.
5622 * region.cc (region::to_json): Likewise.
5623 * sm-malloc.cc (inform_nonnull_attribute): Likewise.
5624 * store.cc (binding_map::to_json): Likewise.
5625 (store::to_json): Likewise.
5626 * svalue.cc (svalue::to_json): Likewise.
5627
5628 2022-07-07 David Malcolm <[email protected]>
5629
5630 PR analyzer/106225
5631 * sm-taint.cc (taint_state_machine::on_stmt): Move handling of
5632 assignments from division to...
5633 (taint_state_machine::check_for_tainted_divisor): ...this new
5634 function. Reject warning when the divisor is known to be non-zero.
5635 * sm.cc: Include "analyzer/program-state.h".
5636 (sm_context::get_old_region_model): New.
5637 * sm.h (sm_context::get_old_region_model): New decl.
5638
5639 2022-07-06 Immad Mir <[email protected]>
5640
5641 PR analyzer/106184
5642 * sm-fd.cc (fd_state_machine): Change ordering of initialization
5643 of state m_invalid so that the order of initializers is same as
5644 the ordering of the fields in the class decl.
5645
5646 2022-07-06 Immad Mir <[email protected]>
5647
5648 * sm-fd.cc (use_after_close): save the "close" event and
5649 show it where possible.
5650
5651 2022-07-06 David Malcolm <[email protected]>
5652
5653 PR analyzer/106204
5654 * region-model.cc (within_short_circuited_stmt_p): Move extraction
5655 of assign_stmt to caller.
5656 (due_to_ifn_deferred_init_p): New.
5657 (region_model::check_for_poison): Move extraction of assign_stmt
5658 from within_short_circuited_stmt_p to here. Share logic with
5659 call to due_to_ifn_deferred_init_p.
5660
5661 2022-07-02 Tim Lange <[email protected]>
5662
5663 PR analyzer/105900
5664 * analyzer.opt: Added Wanalyzer-allocation-size.
5665 * checker-path.cc (region_creation_event::get_desc): Added call to new
5666 virtual function pending_diagnostic::describe_region_creation_event.
5667 * checker-path.h: Added region_creation_event::get_desc.
5668 * diagnostic-manager.cc (diagnostic_manager::add_event_on_final_node):
5669 New function.
5670 * diagnostic-manager.h:
5671 Added diagnostic_manager::add_event_on_final_node.
5672 * pending-diagnostic.h (struct region_creation): New event_desc struct.
5673 (pending_diagnostic::describe_region_creation_event): Added virtual
5674 function to overwrite description of a region creation.
5675 * region-model.cc (class dubious_allocation_size): New class.
5676 (capacity_compatible_with_type): New helper function.
5677 (class size_visitor): New class.
5678 (struct_or_union_with_inheritance_p): New helper function.
5679 (is_any_cast_p): New helper function.
5680 (region_model::check_region_size): New function.
5681 (region_model::set_value): Added call to
5682 region_model::check_region_size.
5683 * region-model.h (class region_model): New function check_region_size.
5684 * svalue.cc (region_svalue::accept): Changed to post-order traversal.
5685 (initial_svalue::accept): Likewise.
5686 (unaryop_svalue::accept): Likewise.
5687 (binop_svalue::accept): Likewise.
5688 (sub_svalue::accept): Likewise.
5689 (repeated_svalue::accept): Likewise.
5690 (bits_within_svalue::accept): Likewise.
5691 (widening_svalue::accept): Likewise.
5692 (unmergeable_svalue::accept): Likewise.
5693 (compound_svalue::accept): Likewise.
5694 (conjured_svalue::accept): Likewise.
5695 (asm_output_svalue::accept): Likewise.
5696 (const_fn_result_svalue::accept): Likewise.
5697
5698 2022-07-02 Immad Mir <[email protected]>
5699
5700 PR analyzer/106003
5701 * analyzer.opt (Wanalyzer-fd-leak): New option.
5702 (Wanalyzer-fd-access-mode-mismatch): New option.
5703 (Wanalyzer-fd-use-without-check): New option.
5704 (Wanalyzer-fd-double-close): New option.
5705 (Wanalyzer-fd-use-after-close): New option.
5706 * sm.h (make_fd_state_machine): New decl.
5707 * sm.cc (make_checkers): Call make_fd_state_machine.
5708 * sm-fd.cc: New file.
5709
5710 2022-06-24 David Malcolm <[email protected]>
5711
5712 * call-string.cc: Add includes of "analyzer/analyzer.h"
5713 and "analyzer/analyzer-logging.h".
5714 (call_string::call_string): Delete copy ctor.
5715 (call_string::operator=): Delete.
5716 (call_string::operator==): Delete.
5717 (call_string::hash): Delete.
5718 (call_string::push_call): Make const, returning the resulting
5719 call_string.
5720 (call_string::pop): Delete.
5721 (call_string::cmp_ptr_ptr): New.
5722 (call_string::validate): Assert that m_parent is non-NULL, or
5723 m_elements is empty.
5724 (call_string::call_string): Move default ctor here from
5725 call-string.h and reimplement. Add ctor taking a parent
5726 and an element.
5727 (call_string::~call_string): New.
5728 (call_string::recursive_log): New.
5729 * call-string.h (call_string::call_string): Move default ctor's
5730 defn to call-string.cc. Delete copy ctor. Add ctor taking a
5731 parent and an element.
5732 (call_string::operator=): Delete.
5733 (call_string::operator==): Delete.
5734 (call_string::hash): Delete.
5735 (call_string::push_call): Make const, returning the resulting
5736 call_string.
5737 (call_string::pop): Delete decl.
5738 (call_string::get_parent): New.
5739 (call_string::cmp_ptr_ptr): New decl.
5740 (call_string::get_top_of_stack): New.
5741 (struct call_string::hashmap_traits_t): New.
5742 (class call_string): Add friend class region_model_manager. Add
5743 DISABLE_COPY_AND_ASSIGN.
5744 (call_string::~call_string): New decl.
5745 (call_string::recursive_log): New decl.
5746 (call_string::m_parent): New field.
5747 (call_string::m_children): New field.
5748 * constraint-manager.cc (selftest::test_many_constants): Pass
5749 model manager to program_point::origin.
5750 * engine.cc (exploded_graph::exploded_graph): Likewise.
5751 (exploded_graph::add_function_entry): Likewise for
5752 program_point::from_function_entry.
5753 (add_tainted_args_callback): Likewise.
5754 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
5755 Update for change to program_point.get_call_string.
5756 (exploded_graph::process_node): Likewise.
5757 (class function_call_string_cluster): Convert m_cs from a
5758 call_string to a const call_string &.
5759 (struct function_call_string): Likewise.
5760 (pod_hash_traits<function_call_string>::hash): Use pointer_hash
5761 for m_cs.
5762 (pod_hash_traits<function_call_string>::equal): Update for change
5763 to m_cs.
5764 (root_cluster::add_node): Update for change to
5765 function_call_string.
5766 (viz_callgraph_node::dump_dot): Update for change to call_string.
5767 * exploded-graph.h (per_call_string_data::m_key): Convert to a
5768 reference.
5769 (struct eg_call_string_hash_map_traits): Delete.
5770 (exploded_graph::call_string_data_map_t): Remove traits class.
5771 * program-point.cc: Move include of "analyzer/call-string.h" to
5772 after "analyzer/analyzer-logging.h".
5773 (program_point::print): Update for conversion of m_call_string to
5774 a pointer.
5775 (program_point::to_json): Likewise.
5776 (program_point::push_to_call_stack): Update for immutability of
5777 call strings.
5778 (program_point::pop_from_call_stack): Likewise.
5779 (program_point::hash): Use pointer hashing for m_call_string.
5780 (program_point::get_function_at_depth): Update for change to
5781 m_call_string.
5782 (program_point::validate): Update for changes to call_string.
5783 (program_point::on_edge): Likewise.
5784 (program_point::origin): Move here from call-string.h. Add
5785 region_model_manager param and use it to get empty call string.
5786 (program_point::from_function_entry): Likewise.
5787 (selftest::test_function_point_ordering): Likewise.
5788 (selftest::test_function_point_ordering): Likewise.
5789 * program-point.h (program_point::program_point): Update for
5790 change to m_call_string.
5791 (program_point::get_call_string): Likewise.
5792 (program_point::get_stack_depth): Likewise.
5793 (program_point::origin): Add region_model_manager param, and move
5794 defn to call-string.cc.
5795 (program_point::from_function_entry): Likewise.
5796 (program_point::empty): Drop call_string.
5797 (program_point::deleted): Likewise.
5798 (program_point::program_point): New private ctor.
5799 (program_point::m_call_string): Convert from call_string to const
5800 call_string *.
5801 * program-state.cc (selftest::test_program_state_merging): Update
5802 for call_string changes.
5803 (selftest::test_program_state_merging_2): Likewise.
5804 * region-model-manager.cc
5805 (region_model_manager::region_model_manager): Construct
5806 m_empty_call_string.
5807 (region_model_manager::log_stats): Log the call strings.
5808 * region-model.cc (assert_region_models_merge): Pass the
5809 region_model_manager when creating program_point instances.
5810 (selftest::test_state_merging): Likewise.
5811 (selftest::test_constraint_merging): Likewise.
5812 (selftest::test_widening_constraints): Likewise.
5813 (selftest::test_iteration_1): Likewise.
5814 * region-model.h (region_model_manager::get_empty_call_string):
5815 New.
5816 (region_model_manager::m_empty_call_string): New.
5817 * sm-signal.cc (register_signal_handler::impl_transition): Update
5818 for changes to call_string.
5819
5820 2022-06-24 David Malcolm <[email protected]>
5821
5822 * call-string.cc (call_string::calc_recursion_depth): Whitespace
5823 cleanups.
5824 (call_string::cmp): Likewise.
5825 (call_string::get_caller_node): Likewise.
5826 (call_string::validate): Likewise.
5827 * engine.cc (dynamic_call_info_t::add_events_to_path): Likewise.
5828 (exploded_graph::get_per_function_data): Likewise.
5829 (exploded_graph::maybe_create_dynamic_call): Likewise.
5830 (exploded_graph::maybe_create_dynamic_call): Likewise.
5831 (exploded_graph::process_node): Likewise.
5832
5833 2022-06-16 David Malcolm <[email protected]>
5834
5835 * varargs.cc (va_arg_type_mismatch::emit): Associate the warning
5836 with CWE-686 ("Function Call With Incorrect Argument Type").
5837
5838 2022-06-16 David Malcolm <[email protected]>
5839
5840 * varargs.cc: Include "diagnostic-metadata.h".
5841 (va_list_exhausted::emit): Associate the warning with
5842 CWE-685 ("Function Call With Incorrect Number of Arguments").
5843
5844 2022-06-16 David Malcolm <[email protected]>
5845
5846 * sm-file.cc (double_fclose::emit): Associate the warning with
5847 CWE-1341 ("Multiple Releases of Same Resource or Handle").
5848
5849 2022-06-15 David Malcolm <[email protected]>
5850
5851 PR analyzer/105962
5852 * analyzer.opt (fanalyzer-undo-inlining): New option.
5853 * checker-path.cc: Include "diagnostic-core.h" and
5854 "inlining-iterator.h".
5855 (event_kind_to_string): Handle EK_INLINED_CALL.
5856 (class inlining_info): New class.
5857 (checker_event::checker_event): Move here from checker-path.h.
5858 Store original fndecl and depth, and calculate effective fndecl
5859 and depth based on inlining information.
5860 (checker_event::dump): Emit original depth as well as effective
5861 depth when they differ; likewise for fndecl.
5862 (region_creation_event::get_desc): Use m_effective_fndecl.
5863 (inlined_call_event::get_desc): New.
5864 (inlined_call_event::get_meaning): New.
5865 (checker_path::inject_any_inlined_call_events): New.
5866 * checker-path.h (enum event_kind): Add EK_INLINED_CALL.
5867 (checker_event::checker_event): Make protected, and move
5868 definition to checker-path.cc.
5869 (checker_event::get_fndecl): Use effective fndecl.
5870 (checker_event::get_stack_depth): Use effective stack depth.
5871 (checker_event::get_logical_location): Use effective stack depth.
5872 (checker_event::get_original_stack_depth): New.
5873 (checker_event::m_fndecl): Rename to...
5874 (checker_event::m_original_fndecl): ...this.
5875 (checker_event::m_depth): Rename to...
5876 (checker_event::m_original_depth): ...this.
5877 (checker_event::m_effective_fndecl): New field.
5878 (checker_event::m_effective_depth): New field.
5879 (class inlined_call_event): New checker_event subclass.
5880 (checker_path::inject_any_inlined_call_events): New decl.
5881 * diagnostic-manager.cc: Include "inlining-iterator.h".
5882 (diagnostic_manager::emit_saved_diagnostic): Call
5883 checker_path::inject_any_inlined_call_events.
5884 (diagnostic_manager::prune_for_sm_diagnostic): Handle
5885 EK_INLINED_CALL.
5886 * engine.cc (tainted_args_function_custom_event::get_desc): Use
5887 effective fndecl.
5888 * inlining-iterator.h: New file.
5889
5890 2022-06-15 David Malcolm <[email protected]>
5891
5892 * diagnostic-manager.cc (saved_diagnostic::dump_dot_id): New.
5893 (saved_diagnostic::dump_as_dot_node): New.
5894 * diagnostic-manager.h (saved_diagnostic::dump_dot_id): New decl.
5895 (saved_diagnostic::dump_as_dot_node): New decl.
5896 * engine.cc (exploded_node::dump_dot): Add nodes for saved
5897 diagnostics.
5898
5899 2022-06-02 David Malcolm <[email protected]>
5900
5901 * checker-path.cc (checker_event::get_meaning): New.
5902 (function_entry_event::get_meaning): New.
5903 (state_change_event::get_desc): Add dump of meaning of the event
5904 to the -fanalyzer-verbose-state-changes output.
5905 (state_change_event::get_meaning): New.
5906 (cfg_edge_event::get_meaning): New.
5907 (call_event::get_meaning): New.
5908 (return_event::get_meaning): New.
5909 (start_consolidated_cfg_edges_event::get_meaning): New.
5910 (warning_event::get_meaning): New.
5911 * checker-path.h: Include "tree-logical-location.h".
5912 (checker_event::checker_event): Construct m_logical_loc.
5913 (checker_event::get_logical_location): New.
5914 (checker_event::get_meaning): New decl.
5915 (checker_event::m_logical_loc): New.
5916 (function_entry_event::get_meaning): New decl.
5917 (state_change_event::get_meaning): New decl.
5918 (cfg_edge_event::get_meaning): New decl.
5919 (call_event::get_meaning): New decl.
5920 (return_event::get_meaning): New decl.
5921 (start_consolidated_cfg_edges_event::get_meaning): New.
5922 (warning_event::get_meaning): New decl.
5923 * pending-diagnostic.h: Include "diagnostic-path.h".
5924 (pending_diagnostic::get_meaning_for_state_change): New vfunc.
5925 * sm-file.cc (file_diagnostic::get_meaning_for_state_change): New
5926 vfunc impl.
5927 * sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
5928 Likewise.
5929 * sm-sensitive.cc
5930 (exposure_through_output_file::get_meaning_for_state_change):
5931 Likewise.
5932 * sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
5933 Likewise.
5934 * varargs.cc
5935 (va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.
5936
5937 2022-05-23 David Malcolm <[email protected]>
5938
5939 * call-info.cc: Add "final" and "override" to all vfunc
5940 implementations that were missing them, as appropriate.
5941 * engine.cc: Likewise.
5942 * region-model.cc: Likewise.
5943 * sm-malloc.cc: Likewise.
5944 * supergraph.h: Likewise.
5945 * svalue.cc: Likewise.
5946 * varargs.cc: Likewise.
5947
5948 2022-05-20 David Malcolm <[email protected]>
5949
5950 * analyzer-pass.cc: Replace uses of "FINAL" and "OVERRIDE" with
5951 "final" and "override".
5952 * call-info.h: Likewise.
5953 * checker-path.h: Likewise.
5954 * constraint-manager.cc: Likewise.
5955 * diagnostic-manager.cc: Likewise.
5956 * engine.cc: Likewise.
5957 * exploded-graph.h: Likewise.
5958 * feasible-graph.h: Likewise.
5959 * pending-diagnostic.h: Likewise.
5960 * region-model-impl-calls.cc: Likewise.
5961 * region-model.cc: Likewise.
5962 * region-model.h: Likewise.
5963 * region.h: Likewise.
5964 * sm-file.cc: Likewise.
5965 * sm-malloc.cc: Likewise.
5966 * sm-pattern-test.cc: Likewise.
5967 * sm-sensitive.cc: Likewise.
5968 * sm-signal.cc: Likewise.
5969 * sm-taint.cc: Likewise.
5970 * state-purge.h: Likewise.
5971 * store.cc: Likewise.
5972 * store.h: Likewise.
5973 * supergraph.h: Likewise.
5974 * svalue.h: Likewise.
5975 * trimmed-graph.h: Likewise.
5976 * varargs.cc: Likewise.
5977
5978 2022-05-16 David Malcolm <[email protected]>
5979
5980 PR analyzer/105103
5981 * analyzer.cc (make_label_text_n): New.
5982 * analyzer.h (class var_arg_region): New forward decl.
5983 (make_label_text_n): New decl.
5984 * analyzer.opt (Wanalyzer-va-arg-type-mismatch): New option.
5985 (Wanalyzer-va-list-exhausted): New option.
5986 (Wanalyzer-va-list-leak): New option.
5987 (Wanalyzer-va-list-use-after-va-end): New option.
5988 * checker-path.cc (call_event::get_desc): Split out decl access
5989 into..
5990 (call_event::get_caller_fndecl): ...this new function and...
5991 (call_event::get_callee_fndecl): ...this new function.
5992 * checker-path.h (call_event::get_desc): Drop "FINAL".
5993 (call_event::get_caller_fndecl): New decl.
5994 (call_event::get_callee_fndecl): New decl.
5995 (class call_event): Make fields protected.
5996 * diagnostic-manager.cc (null_assignment_sm_context::warn): New
5997 overload.
5998 (null_assignment_sm_context::get_new_program_state): New.
5999 (diagnostic_manager::add_events_for_superedge): Move case
6000 SUPEREDGE_CALL to a new pending_diagnostic::add_call_event vfunc.
6001 * engine.cc (impl_sm_context::warn): Implement new override.
6002 (impl_sm_context::get_new_program_state): New.
6003 * pending-diagnostic.cc: Include "analyzer/diagnostic-manager.h",
6004 "cpplib.h", "digraph.h", "ordered-hash-map.h", "cfg.h",
6005 "basic-block.h", "gimple.h", "gimple-iterator.h", "cgraph.h"
6006 "analyzer/supergraph.h", "analyzer/program-state.h",
6007 "alloc-pool.h", "fibonacci_heap.h", "shortest-paths.h",
6008 "sbitmap.h", "analyzer/exploded-graph.h", "diagnostic-path.h",
6009 and "analyzer/checker-path.h".
6010 (ht_ident_eq): New.
6011 (fixup_location_in_macro_p): New.
6012 (pending_diagnostic::fixup_location): New.
6013 (pending_diagnostic::add_call_event): New.
6014 * pending-diagnostic.h (pending_diagnostic::fixup_location): Drop
6015 no-op inline implementation in favor of the more complex
6016 implementation above.
6017 (pending_diagnostic::add_call_event): New vfunc.
6018 * region-model-impl-calls.cc: Include "analyzer/sm.h",
6019 "diagnostic-path.h", and "analyzer/pending-diagnostic.h".
6020 * region-model-manager.cc
6021 (region_model_manager::get_var_arg_region): New.
6022 (region_model_manager::log_stats): Log m_var_arg_regions.
6023 * region-model.cc (region_model::on_call_pre): Handle IFN_VA_ARG,
6024 BUILT_IN_VA_START, and BUILT_IN_VA_COPY.
6025 (region_model::on_call_post): Handle BUILT_IN_VA_END.
6026 (region_model::get_representative_path_var_1): Handle RK_VAR_ARG.
6027 (region_model::push_frame): Push variadic arguments.
6028 * region-model.h (region_model_manager::get_var_arg_region): New
6029 decl.
6030 (region_model_manager::m_var_arg_regions): New field.
6031 (region_model::impl_call_va_start): New decl.
6032 (region_model::impl_call_va_copy): New decl.
6033 (region_model::impl_call_va_arg): New decl.
6034 (region_model::impl_call_va_end): New decl.
6035 * region.cc (alloca_region::dump_to_pp): Dump the id.
6036 (var_arg_region::dump_to_pp): New.
6037 (var_arg_region::get_frame_region): New.
6038 * region.h (enum region_kind): Add RK_VAR_ARG.
6039 (region::dyn_cast_var_arg_region): New.
6040 (class var_arg_region): New.
6041 (is_a_helper <const var_arg_region *>::test): New.
6042 (struct default_hash_traits<var_arg_region::key_t>): New.
6043 * sm.cc (make_checkers): Call make_va_list_state_machine.
6044 * sm.h (sm_context::warn): New vfunc.
6045 (sm_context::get_old_svalue): Drop unused decl.
6046 (sm_context::get_new_program_state): New vfunc.
6047 (make_va_list_state_machine): New decl.
6048 * varargs.cc: New file.
6049
6050 2022-05-16 Martin Liska <[email protected]>
6051
6052 * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
6053 * function-set.cc (test_stdio_example): Likewise.
6054 * sm-file.cc (get_file_using_fns): Likewise.
6055 * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
6056 * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
6057
6058 2022-05-13 Richard Biener <[email protected]>
6059
6060 * supergraph.cc: Re-order gimple-fold.h include.
6061
6062 2022-05-11 David Malcolm <[email protected]>
6063
6064 * checker-path.cc (state_change_event::get_desc): Call maybe_free
6065 on label_text temporaries.
6066 * diagnostic-manager.cc
6067 (diagnostic_manager::prune_for_sm_diagnostic): Likewise.
6068 * engine.cc (exploded_graph::~exploded_graph): Fix leak of
6069 m_per_point_data and m_per_call_string_data values. Simplify
6070 cleanup of m_per_function_stats and m_per_point_data values.
6071 (feasibility_state::maybe_update_for_edge): Fix leak of result of
6072 superedge::get_description.
6073 * region-model-manager.cc
6074 (region_model_manager::~region_model_manager): Move cleanup of
6075 m_setjmp_values to match the ordering of the fields within
6076 region_model_manager. Fix leak of values within
6077 m_repeated_values_map, m_bits_within_values_map,
6078 m_asm_output_values_map, and m_const_fn_result_values_map.
6079
6080 2022-04-28 David Malcolm <[email protected]>
6081
6082 PR analyzer/105285
6083 * store.cc (binding_cluster::get_any_binding): Handle accessing
6084 sub_svalues of clusters where the base region has a symbolic
6085 binding.
6086
6087 2022-04-28 David Malcolm <[email protected]>
6088
6089 * diagnostic-manager.cc (epath_finder::process_worklist_item):
6090 Call dump_feasible_path when a path that reaches the the target
6091 enode is found.
6092 (epath_finder::dump_feasible_path): New.
6093 * engine.cc (feasibility_state::dump_to_pp): New.
6094 * exploded-graph.h (feasibility_state::dump_to_pp): New decl.
6095 * feasible-graph.cc (feasible_graph::dump_feasible_path): New.
6096 * feasible-graph.h (feasible_graph::dump_feasible_path): New
6097 decls.
6098 * program-point.cc (function_point::print): Fix missing trailing
6099 newlines.
6100 * program-point.h (program_point::print_source_line): Remove
6101 unimplemented decl.
6102
6103 2022-04-25 David Malcolm <[email protected]>
6104
6105 PR analyzer/105365
6106 PR analyzer/105366
6107 * svalue.cc
6108 (cmp_cst): Rename to...
6109 (cmp_csts_same_type): ...this. Convert all recursive calls to
6110 calls to...
6111 (cmp_csts_and_types): ....this new function.
6112 (svalue::cmp_ptr): Update for renaming of cmp_cst
6113
6114 2022-04-14 David Malcolm <[email protected]>
6115
6116 PR analyzer/105264
6117 * region-model-reachability.cc (reachable_regions::handle_parm):
6118 Use maybe_get_deref_base_region rather than just region_svalue, to
6119 handle pointer arithmetic also.
6120 * svalue.cc (svalue::maybe_get_deref_base_region): New.
6121 * svalue.h (svalue::maybe_get_deref_base_region): New decl.
6122
6123 2022-04-14 David Malcolm <[email protected]>
6124
6125 PR analyzer/105252
6126 * svalue.cc (cmp_cst): When comparing VECTOR_CSTs, compare the
6127 types of the encoded elements before calling cmp_cst on them.
6128
6129 2022-04-09 David Malcolm <[email protected]>
6130
6131 PR analyzer/103892
6132 * region-model-manager.cc
6133 (region_model_manager::get_unknown_symbolic_region): New,
6134 extracted from...
6135 (region_model_manager::get_field_region): ...here.
6136 (region_model_manager::get_element_region): Use it here.
6137 (region_model_manager::get_offset_region): Likewise.
6138 (region_model_manager::get_sized_region): Likewise.
6139 (region_model_manager::get_cast_region): Likewise.
6140 (region_model_manager::get_bit_range): Likewise.
6141 * region-model.h
6142 (region_model_manager::get_unknown_symbolic_region): New decl.
6143 * region.cc (symbolic_region::symbolic_region): Handle sval_ptr
6144 having NULL type.
6145 (symbolic_region::dump_to_pp): Handle having NULL type.
6146
6147 2022-04-07 David Malcolm <[email protected]>
6148
6149 PR analyzer/102208
6150 * store.cc (binding_map::remove_overlapping_bindings): Add
6151 "always_overlap" param, using it to generalize to the case where
6152 we want to remove all bindings. Update "uncertainty" logic to
6153 only record maybe-bound values for cases where there is a symbolic
6154 write involved.
6155 (binding_cluster::mark_region_as_unknown): Split param "reg" into
6156 "reg_to_bind" and "reg_for_overlap".
6157 (binding_cluster::maybe_get_compound_binding): Pass "false" to
6158 binding_map::remove_overlapping_bindings new "always_overlap" param.
6159 (binding_cluster::remove_overlapping_bindings): Determine
6160 "always_overlap" and pass it to
6161 binding_map::remove_overlapping_bindings.
6162 (store::set_value): Pass uncertainty to remove_overlapping_bindings
6163 call. Update for new param of
6164 binding_cluster::mark_region_as_unknown, passing both the base
6165 region of the iter_cluster, and the lhs_reg.
6166 (store::mark_region_as_unknown): Update for new param of
6167 binding_cluster::mark_region_as_unknown, passing "reg" for both.
6168 (store::remove_overlapping_bindings): Add param "uncertainty", and
6169 pass it on to call to
6170 binding_cluster::remove_overlapping_bindings.
6171 * store.h (binding_map::remove_overlapping_bindings): Add
6172 "always_overlap" param.
6173 (binding_cluster::mark_region_as_unknown): Split param "reg" into
6174 "reg_to_bind" and "reg_for_overlap".
6175 (store::remove_overlapping_bindings): Add param "uncertainty".
6176
6177 2022-03-29 David Malcolm <[email protected]>
6178
6179 PR testsuite/105085
6180 * region-model-manager.cc (dump_untracked_region): Skip decls in
6181 the constant pool.
6182
6183 2022-03-29 David Malcolm <[email protected]>
6184
6185 PR analyzer/105087
6186 * analyzer.h (class conjured_purge): New forward decl.
6187 * region-model-asm.cc (region_model::on_asm_stmt): Add
6188 conjured_purge param to calls binding_cluster::on_asm and
6189 region_model_manager::get_or_create_conjured_svalue.
6190 * region-model-impl-calls.cc
6191 (call_details::get_or_create_conjured_svalue): Likewise for call
6192 to region_model_manager::get_or_create_conjured_svalue.
6193 (region_model::impl_call_fgets): Remove call to
6194 region_model::purge_state_involving, as this is now done
6195 implicitly by call_details::get_or_create_conjured_svalue.
6196 (region_model::impl_call_fread): Likewise.
6197 (region_model::impl_call_strchr): Pass conjured_purge param to
6198 call to region_model_manager::get_or_create_conjured_svalue.
6199 * region-model-manager.cc (conjured_purge::purge): New.
6200 (region_model_manager::get_or_create_conjured_svalue): Add
6201 param "p". Use it to purge state when reusing an existing
6202 conjured_svalue.
6203 * region-model.cc (region_model::on_call_pre): Replace call to
6204 region_model::purge_state_involving with passing conjured_purge
6205 to region_model_manager::get_or_create_conjured_svalue.
6206 (region_model::handle_unrecognized_call): Pass conjured_purge to
6207 store::on_unknown_fncall.
6208 * region-model.h
6209 (region_model_manager::get_or_create_conjured_svalue): Add param
6210 "p".
6211 * store.cc (binding_cluster::on_unknown_fncall): Likewise. Pass
6212 it on to region_model_manager::get_or_create_conjured_svalue.
6213 (binding_cluster::on_asm): Likewise.
6214 (store::on_unknown_fncall): Add param "p" and pass it on to
6215 binding_cluster::on_unknown_fncall.
6216 * store.h (binding_cluster::on_unknown_fncall): Add param p.
6217 (binding_cluster::on_asm): Likewise.
6218 (store::on_unknown_fncall): Likewise.
6219 * svalue.h (class conjured_purge): New.
6220
6221 2022-03-29 David Malcolm <[email protected]>
6222
6223 PR analyzer/105074
6224 * region.cc (ipa_ref_requires_tracking): Drop "context_fndecl",
6225 instead using the ref->referring to get the cgraph node of the
6226 caller.
6227 (symnode_requires_tracking_p): Likewise.
6228
6229 2022-03-26 David Malcolm <[email protected]>
6230
6231 PR analyzer/105057
6232 * store.cc (binding_cluster::make_unknown_relative_to): Reject
6233 attempts to create a cluster for untracked base regions.
6234 (store::set_value): Likewise.
6235 (store::fill_region): Likewise.
6236 (store::mark_region_as_unknown): Likewise.
6237
6238 2022-03-25 David Malcolm <[email protected]>
6239
6240 PR analyzer/104954
6241 * analyzer.opt (-fdump-analyzer-untracked): New option.
6242 * engine.cc (impl_run_checkers): Handle it.
6243 * region-model-asm.cc (region_model::on_asm_stmt): Don't attempt
6244 to clobber regions with !tracked_p ().
6245 * region-model-manager.cc (dump_untracked_region): New.
6246 (region_model_manager::dump_untracked_regions): New.
6247 (frame_region::dump_untracked_regions): New.
6248 * region-model.h (region_model_manager::dump_untracked_regions):
6249 New decl.
6250 * region.cc (ipa_ref_requires_tracking): New.
6251 (symnode_requires_tracking_p): New.
6252 (decl_region::calc_tracked_p): New.
6253 * region.h (region::tracked_p): New vfunc.
6254 (frame_region::dump_untracked_regions): New decl.
6255 (class decl_region): Note that this is also used fo SSA names.
6256 (decl_region::decl_region): Initialize m_tracked.
6257 (decl_region::tracked_p): New.
6258 (decl_region::calc_tracked_p): New decl.
6259 (decl_region::m_tracked): New.
6260 * store.cc (store::get_or_create_cluster): Assert that we
6261 don't try to create clusters for base regions that aren't
6262 trackable.
6263 (store::mark_as_escaped): Don't mark base regions that we're not
6264 tracking.
6265
6266 2022-03-23 David Malcolm <[email protected]>
6267
6268 PR analyzer/104979
6269 * engine.cc (impl_run_checkers): Create the engine after the
6270 supergraph, and pass the supergraph to the engine.
6271 * region-model.cc (region_model::get_lvalue_1): Pass ctxt to
6272 frame_region::get_region_for_local.
6273 (region_model::update_for_return_gcall): Pass the lvalue for the
6274 result to pop_frame as a tree, rather than as a region.
6275 (region_model::pop_frame): Update for above change, determining
6276 the destination region after the frame is popped and thus with
6277 respect to the caller frame rather than the called frame.
6278 Likewise, set the value of the region to the return value after
6279 the frame is popped.
6280 (engine::engine): Add supergraph pointer.
6281 (selftest::test_stack_frames): Set the DECL_CONTECT of PARM_DECLs.
6282 (selftest::test_get_representative_path_var): Likewise.
6283 (selftest::test_state_merging): Likewise.
6284 * region-model.h (region_model::pop_frame): Convert first param
6285 from a const region * to a tree.
6286 (engine::engine): Add param "sg".
6287 (engine::m_sg): New field.
6288 * region.cc: Include "analyzer/sm.h" and
6289 "analyzer/program-state.h".
6290 (frame_region::get_region_for_local): Add "ctxt" param.
6291 Add assertions that VAR_DECLs are locals, and that expr is for the
6292 correct function.
6293 * region.h (frame_region::get_region_for_local): Add "ctxt" param.
6294
6295 2022-03-23 David Malcolm <[email protected]>
6296
6297 PR analyzer/105017
6298 * sm-taint.cc (taint_diagnostic::subclass_equal_p): Check
6299 m_has_bounds as well as m_arg.
6300 (tainted_allocation_size::subclass_equal_p): Chain up to base
6301 class implementation. Also check m_mem_space.
6302 (tainted_allocation_size::emit): Add note showing stack-based vs
6303 heap-based allocations.
6304
6305 2022-03-23 David Malcolm <[email protected]>
6306
6307 PR analyzer/104997
6308 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic):
6309 Convert return type from "void" to "bool", reporting success vs
6310 failure to caller, for both overloads.
6311 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
6312 Likewise.
6313 * engine.cc (impl_region_model_context::warn): Propagate return
6314 value from diagnostic_manager::add_diagnostic.
6315
6316 2022-03-18 David Malcolm <[email protected]>
6317
6318 PR analyzer/104943
6319 PR analyzer/104954
6320 PR analyzer/103533
6321 * analyzer.h (class state_purge_per_decl): New forward decl.
6322 * engine.cc (impl_run_checkers): Pass region_model_manager to
6323 state_purge_map ctor.
6324 * program-point.cc (function_point::final_stmt_p): New.
6325 (function_point::get_next): New.
6326 * program-point.h (function_point::final_stmt_p): New decl.
6327 (function_point::get_next): New decl.
6328 * program-state.cc (program_state::prune_for_point): Generalize to
6329 purge local decls as well as SSA names.
6330 (program_state::can_purge_base_region_p): New.
6331 * program-state.h (program_state::can_purge_base_region_p): New
6332 decl.
6333 * region-model.cc (struct append_ssa_names_cb_data): Rename to...
6334 (struct append_regions_cb_data): ...this.
6335 (region_model::get_ssa_name_regions_for_current_frame): Rename
6336 to...
6337 (region_model::get_regions_for_current_frame): ...this, updating
6338 for other renamings.
6339 (region_model::append_ssa_names_cb): Rename to...
6340 (region_model::append_regions_cb): ...this, and drop the requirement
6341 that the subregion be a SSA name.
6342 * region-model.h (struct append_ssa_names_cb_data): Rename decl
6343 to...
6344 (struct append_regions_cb_data): ...this.
6345 (region_model::get_ssa_name_regions_for_current_frame): Rename
6346 decl to...
6347 (region_model::get_regions_for_current_frame): ...this.
6348 (region_model::append_ssa_names_cb): Rename decl to...
6349 (region_model::append_regions_cb): ...this.
6350 * state-purge.cc: Include "tristate.h", "selftest.h",
6351 "analyzer/store.h", "analyzer/region-model.h", and
6352 "gimple-walk.h".
6353 (get_candidate_for_purging): New.
6354 (class gimple_op_visitor): New.
6355 (my_load_cb): New.
6356 (my_store_cb): New.
6357 (my_addr_cb): New.
6358 (state_purge_map::state_purge_map): Add "mgr" param. Update for
6359 renamings. Find uses of local variables.
6360 (state_purge_map::~state_purge_map): Update for renaming of m_map
6361 to m_ssa_map. Clean up m_decl_map.
6362 (state_purge_map::get_or_create_data_for_decl): New.
6363 (state_purge_per_ssa_name::state_purge_per_ssa_name): Update for
6364 inheriting from state_purge_per_tree.
6365 (state_purge_per_ssa_name::add_to_worklist): Likewise.
6366 (state_purge_per_decl::state_purge_per_decl): New.
6367 (state_purge_per_decl::add_needed_at): New.
6368 (state_purge_per_decl::add_pointed_to_at): New.
6369 (state_purge_per_decl::process_worklists): New.
6370 (state_purge_per_decl::add_to_worklist): New.
6371 (same_binding_p): New.
6372 (fully_overwrites_p): New.
6373 (state_purge_per_decl::process_point_backwards): New.
6374 (state_purge_per_decl::process_point_forwards): New.
6375 (state_purge_per_decl::needed_at_point_p): New.
6376 (state_purge_annotator::print_needed): Generalize to print local
6377 decls as well as SSA names.
6378 * state-purge.h (class state_purge_map): Update leading comment.
6379 (state_purge_map::map_t): Rename to...
6380 (state_purge_map::ssa_map_t): ...this.
6381 (state_purge_map::iterator): Rename to...
6382 (state_purge_map::ssa_iterator): ...this.
6383 (state_purge_map::decl_map_t): New typedef.
6384 (state_purge_map::decl_iterator): New typedef.
6385 (state_purge_map::state_purge_map): Add "mgr" param.
6386 (state_purge_map::get_data_for_ssa_name): Update for renaming.
6387 (state_purge_map::get_any_data_for_decl): New.
6388 (state_purge_map::get_or_create_data_for_decl): New decl.
6389 (state_purge_map::begin): Rename to...
6390 (state_purge_map::begin_ssas): ...this.
6391 (state_purge_map::end): Rename to...
6392 (state_purge_map::end_ssa): ...this.
6393 (state_purge_map::begin_decls): New.
6394 (state_purge_map::end_decls): New.
6395 (state_purge_map::m_map): Rename to...
6396 (state_purge_map::m_ssa_map): ...this.
6397 (state_purge_map::m_decl_map): New field.
6398 (class state_purge_per_tree): New class.
6399 (class state_purge_per_ssa_name): Inherit from state_purge_per_tree.
6400 (state_purge_per_ssa_name::get_function): Move to base class.
6401 (state_purge_per_ssa_name::point_set_t): Likewise.
6402 (state_purge_per_ssa_name::m_fun): Likewise.
6403 (class state_purge_per_decl): New.
6404
6405 2022-03-17 David Malcolm <[email protected]>
6406
6407 * state-purge.cc (state_purge_annotator::add_node_annotations):
6408 Avoid duplicate before-supernode annotations when returning from
6409 an interprocedural call. Show after-supernode annotations.
6410
6411 2022-03-17 David Malcolm <[email protected]>
6412
6413 * program-point.cc (program_point::get_next): Fix missing
6414 increment of index.
6415
6416 2022-03-16 David Malcolm <[email protected]>
6417
6418 PR analyzer/104955
6419 * diagnostic-manager.cc (get_emission_location): New.
6420 (diagnostic_manager::diagnostic_manager): Initialize
6421 m_num_disabled_diagnostics.
6422 (diagnostic_manager::add_diagnostic): Reject diagnostics that
6423 will eventually be rejected due to being disabled.
6424 (diagnostic_manager::emit_saved_diagnostics): Log the number
6425 of disabled diagnostics.
6426 (diagnostic_manager::emit_saved_diagnostic): Split out logic for
6427 determining emission location to get_emission_location.
6428 * diagnostic-manager.h
6429 (diagnostic_manager::m_num_disabled_diagnostics): New field.
6430 * engine.cc (stale_jmp_buf::get_controlling_option): New.
6431 (stale_jmp_buf::emit): Use it.
6432 * pending-diagnostic.h
6433 (pending_diagnostic::get_controlling_option): New vfunc.
6434 * region-model.cc
6435 (poisoned_value_diagnostic::get_controlling_option): New.
6436 (poisoned_value_diagnostic::emit): Use it.
6437 (shift_count_negative_diagnostic::get_controlling_option): New.
6438 (shift_count_negative_diagnostic::emit): Use it.
6439 (shift_count_overflow_diagnostic::get_controlling_option): New.
6440 (shift_count_overflow_diagnostic::emit): Use it.
6441 (dump_path_diagnostic::get_controlling_option): New.
6442 (dump_path_diagnostic::emit): Use it.
6443 (write_to_const_diagnostic::get_controlling_option): New.
6444 (write_to_const_diagnostic::emit): Use it.
6445 (write_to_string_literal_diagnostic::get_controlling_option): New.
6446 (write_to_string_literal_diagnostic::emit): Use it.
6447 * sm-file.cc (double_fclose::get_controlling_option): New.
6448 (double_fclose::emit): Use it.
6449 (file_leak::get_controlling_option): New.
6450 (file_leak::emit): Use it.
6451 * sm-malloc.cc (mismatching_deallocation::get_controlling_option):
6452 New.
6453 (mismatching_deallocation::emit): Use it.
6454 (double_free::get_controlling_option): New.
6455 (double_free::emit): Use it.
6456 (possible_null_deref::get_controlling_option): New.
6457 (possible_null_deref::emit): Use it.
6458 (possible_null_arg::get_controlling_option): New.
6459 (possible_null_arg::emit): Use it.
6460 (null_deref::get_controlling_option): New.
6461 (null_deref::emit): Use it.
6462 (null_arg::get_controlling_option): New.
6463 (null_arg::emit): Use it.
6464 (use_after_free::get_controlling_option): New.
6465 (use_after_free::emit): Use it.
6466 (malloc_leak::get_controlling_option): New.
6467 (malloc_leak::emit): Use it.
6468 (free_of_non_heap::get_controlling_option): New.
6469 (free_of_non_heap::emit): Use it.
6470 * sm-pattern-test.cc (pattern_match::get_controlling_option): New.
6471 (pattern_match::emit): Use it.
6472 * sm-sensitive.cc
6473 (exposure_through_output_file::get_controlling_option): New.
6474 (exposure_through_output_file::emit): Use it.
6475 * sm-signal.cc (signal_unsafe_call::get_controlling_option): New.
6476 (signal_unsafe_call::emit): Use it.
6477 * sm-taint.cc (tainted_array_index::get_controlling_option): New.
6478 (tainted_array_index::emit): Use it.
6479 (tainted_offset::get_controlling_option): New.
6480 (tainted_offset::emit): Use it.
6481 (tainted_size::get_controlling_option): New.
6482 (tainted_size::emit): Use it.
6483 (tainted_divisor::get_controlling_option): New.
6484 (tainted_divisor::emit): Use it.
6485 (tainted_allocation_size::get_controlling_option): New.
6486 (tainted_allocation_size::emit): Use it.
6487
6488 2022-03-15 David Malcolm <[email protected]>
6489
6490 * store.cc (store::store): Presize m_cluster_map.
6491
6492 2022-03-10 David Malcolm <[email protected]>
6493
6494 PR analyzer/104863
6495 * constraint-manager.cc (constraint_manager::add_constraint):
6496 Refresh the EC IDs when adding constraints implied by offsets.
6497
6498 2022-03-10 David Malcolm <[email protected]>
6499
6500 PR analyzer/104793
6501 * analyzer.h (class pending_note): New forward decl.
6502 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
6503 Initialize m_notes.
6504 (saved_diagnostic::operator==): Compare m_notes.
6505 (saved_diagnostic::add_note): New.
6506 (saved_diagnostic::emit_any_notes): New.
6507 (diagnostic_manager::add_note): New.
6508 (diagnostic_manager::emit_saved_diagnostic): Call emit_any_notes
6509 after emitting the warning.
6510 * diagnostic-manager.h (saved_diagnostic::add_note): New decl.
6511 (saved_diagnostic::emit_any_notes): New decl.
6512 (saved_diagnostic::m_notes): New field.
6513 (diagnostic_manager::add_note): New decl.
6514 * engine.cc (impl_region_model_context::add_note): New.
6515 * exploded-graph.h (impl_region_model_context::add_note): New
6516 decl.
6517 * pending-diagnostic.h (class pending_note): New.
6518 (class pending_note_subclass): New template.
6519 * region-model.cc (class reason_attr_access): New.
6520 (check_external_function_for_access_attr): Add class
6521 annotating_ctxt and use it when checking region.
6522 (noop_region_model_context::add_note): New.
6523 * region-model.h (region_model_context::add_note): New vfunc.
6524 (noop_region_model_context::add_note): New decl.
6525 (class region_model_context_decorator): New.
6526 (class note_adding_context): New.
6527
6528 2022-03-10 David Malcolm <[email protected]>
6529
6530 PR analyzer/104793
6531 * region-model.cc
6532 (region_model::check_external_function_for_access_attr): New.
6533 (region_model::handle_unrecognized_call): Call it.
6534 * region-model.h
6535 (region_model::check_external_function_for_access_attr): New decl.
6536 (region_model::handle_unrecognized_call): New decl.
6537
6538 2022-03-10 David Malcolm <[email protected]>
6539
6540 * sm-taint.cc (taint_state_machine::check_for_tainted_size_arg):
6541 Avoid generating duplicate saved_diagnostics by only handling the
6542 rdwr_map entry for the ptrarg, not the duplicate entry for the
6543 sizarg.
6544
6545 2022-03-07 David Malcolm <[email protected]>
6546
6547 PR analyzer/101983
6548 * engine.cc (returning_from_function_p): New.
6549 (impl_region_model_context::on_state_leak): Use it when rejecting
6550 leaks at the return from "main".
6551
6552 2022-03-07 Jakub Jelinek <[email protected]>
6553
6554 * store.cc: Fix up duplicated word issue in a comment.
6555 * analyzer.cc: Likewise.
6556 * engine.cc: Likewise.
6557 * sm-taint.cc: Likewise.
6558
6559 2022-03-04 David Malcolm <[email protected]>
6560
6561 PR analyzer/103521
6562 * analyzer.opt (-param=analyzer-max-svalue-depth=): Reduce from 13
6563 to 12.
6564
6565 2022-02-23 David Malcolm <[email protected]>
6566
6567 PR analyzer/104434
6568 * analyzer.h (class const_fn_result_svalue): New decl.
6569 * region-model-impl-calls.cc (call_details::get_manager): New.
6570 * region-model-manager.cc
6571 (region_model_manager::get_or_create_const_fn_result_svalue): New.
6572 (region_model_manager::log_stats): Log
6573 m_const_fn_result_values_map.
6574 * region-model.cc (const_fn_p): New.
6575 (maybe_get_const_fn_result): New.
6576 (region_model::on_call_pre): Handle fndecls with
6577 __attribute__((const)) by calling the above rather than making
6578 a conjured_svalue.
6579 * region-model.h (visitor::visit_const_fn_result_svalue): New.
6580 (region_model_manager::get_or_create_const_fn_result_svalue): New
6581 decl.
6582 (region_model_manager::const_fn_result_values_map_t): New typedef.
6583 (region_model_manager::m_const_fn_result_values_map): New field.
6584 (call_details::get_manager): New decl.
6585 * svalue.cc (svalue::cmp_ptr): Handle SK_CONST_FN_RESULT.
6586 (const_fn_result_svalue::dump_to_pp): New.
6587 (const_fn_result_svalue::dump_input): New.
6588 (const_fn_result_svalue::accept): New.
6589 * svalue.h (enum svalue_kind): Add SK_CONST_FN_RESULT.
6590 (svalue::dyn_cast_const_fn_result_svalue): New.
6591 (class const_fn_result_svalue): New.
6592 (is_a_helper <const const_fn_result_svalue *>::test): New.
6593 (template <> struct default_hash_traits<const_fn_result_svalue::key_t>):
6594 New.
6595
6596 2022-02-17 David Malcolm <[email protected]>
6597
6598 PR analyzer/104576
6599 * region-model.cc: Include "calls.h".
6600 (region_model::on_call_pre): Use flags_from_decl_or_type to
6601 generalize check for DECL_PURE_P to also check for ECF_CONST.
6602
6603 2022-02-16 David Malcolm <[email protected]>
6604
6605 PR analyzer/104560
6606 * diagnostic-manager.cc (diagnostic_manager::build_emission_path):
6607 Add region creation events for globals of interest.
6608 (null_assignment_sm_context::get_old_program_state): New.
6609 (diagnostic_manager::add_events_for_eedge): Move check for
6610 changing dynamic extents from PK_BEFORE_STMT case to after the
6611 switch on the dst_point's kind so that we can emit them for the
6612 final stmt in a basic block.
6613 * engine.cc (impl_sm_context::get_old_program_state): New.
6614 * sm-malloc.cc (malloc_state_machine::get_default_state): Rewrite
6615 detection of m_non_heap to use get_memory_space.
6616 (free_of_non_heap::free_of_non_heap): Add freed_reg param.
6617 (free_of_non_heap::subclass_equal_p): Update for changes to
6618 fields.
6619 (free_of_non_heap::emit): Drop m_kind in favor of
6620 get_memory_space.
6621 (free_of_non_heap::describe_state_change): Remove logic for
6622 detecting alloca.
6623 (free_of_non_heap::mark_interesting_stuff): Add region-creation of
6624 m_freed_reg.
6625 (free_of_non_heap::get_memory_space): New.
6626 (free_of_non_heap::kind): Drop enum.
6627 (free_of_non_heap::m_freed_reg): New field.
6628 (free_of_non_heap::m_kind): Drop field.
6629 (malloc_state_machine::on_stmt): Drop transition to m_non_heap.
6630 (malloc_state_machine::handle_free_of_non_heap): New function,
6631 split out from on_deallocator_call and on_realloc_call, adding
6632 detection of the freed region.
6633 (malloc_state_machine::on_deallocator_call): Use it.
6634 (malloc_state_machine::on_realloc_call): Likewise.
6635 * sm.h (sm_context::get_old_program_state): New vfunc.
6636
6637 2022-02-15 David Malcolm <[email protected]>
6638
6639 PR analyzer/104524
6640 * region-model-manager.cc
6641 (region_model_manager::maybe_fold_sub_svalue): Only call
6642 get_or_create_cast if type is non-NULL.
6643
6644 2022-02-15 David Malcolm <[email protected]>
6645
6646 PR analyzer/102692
6647 * exploded-graph.h (impl_region_model_context::get_stmt): New.
6648 * region-model.cc: Include "gimple-ssa.h", "tree-phinodes.h",
6649 "tree-ssa-operands.h", and "ssa-iterators.h".
6650 (within_short_circuited_stmt_p): New.
6651 (region_model::check_for_poison): Don't warn about uninit values
6652 if within_short_circuited_stmt_p.
6653 * region-model.h (region_model_context::get_stmt): New vfunc.
6654 (noop_region_model_context::get_stmt): New.
6655
6656 2022-02-11 David Malcolm <[email protected]>
6657
6658 PR analyzer/104274
6659 * region-model.cc (region_model::check_for_poison): Ignore
6660 uninitialized uses of empty types.
6661
6662 2022-02-10 David Malcolm <[email protected]>
6663
6664 PR analyzer/98797
6665 * region-model-manager.cc
6666 (region_model_manager::maybe_fold_sub_svalue): Generalize getting
6667 individual chars of a STRING_CST from element_region to any
6668 subregion which is a concrete access of a single byte from its
6669 parent region.
6670 * region.cc (region::get_relative_concrete_byte_range): New.
6671 * region.h (region::get_relative_concrete_byte_range): New decl.
6672
6673 2022-02-09 David Malcolm <[email protected]>
6674
6675 PR analyzer/104452
6676 * region-model.cc (selftest::test_bit_range_regions): New.
6677 (selftest::analyzer_region_model_cc_tests): Call it.
6678 * region.h (bit_range_region::key_t::hash): Fix hashing of m_bits
6679 to avoid using uninitialized data.
6680
6681 2022-02-07 David Malcolm <[email protected]>
6682
6683 PR analyzer/104417
6684 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
6685 Remove overzealous assertion.
6686 (tainted_allocation_size::emit): Likewise.
6687 (region_model::check_dynamic_size_for_taint): Likewise.
6688
6689 2022-02-07 David Malcolm <[email protected]>
6690
6691 PR analyzer/103872
6692 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
6693 Reimplement in terms of a get_store_value followed by a set_value.
6694
6695 2022-02-03 David Malcolm <[email protected]>
6696
6697 PR analyzer/104369
6698 * engine.cc (exploded_graph::process_node): Use the node for any
6699 diagnostics, avoiding ICE if a bifurcation update adds a
6700 saved_diagnostic, such as for a tainted realloc size.
6701 * region-model-impl-calls.cc
6702 (region_model::impl_call_realloc::success_no_move::update_model):
6703 Require the old pointer to be non-NULL to be able successfully
6704 grow in place. Use model->deref_rvalue rather than maybe_get_region
6705 to support the old pointer being symbolic.
6706 (region_model::impl_call_realloc::success_with_move::update_model):
6707 Likewise. Add a constraint that the new pointer != the old pointer.
6708 Use a sized_region when setting the value of the new region.
6709 Handle the case where we don't know the dynamic size of the old
6710 region by marking the new region as unknown.
6711 * sm-taint.cc (tainted_allocation_size::tainted_allocation_size):
6712 Update assertion to also allow for MEMSPACE_UNKNOWN.
6713 (tainted_allocation_size::emit): Likewise.
6714 (region_model::check_dynamic_size_for_taint): Likewise.
6715
6716 2022-02-03 David Malcolm <[email protected]>
6717
6718 * region-model-impl-calls.cc (region_model::impl_call_calloc): Use
6719 a sized_region when calling zero_fill_region.
6720
6721 2022-02-02 David Malcolm <[email protected]>
6722
6723 * region-model.cc (region_model::on_return): Replace usage of
6724 copy_region with get_rvalue/set_value pair.
6725 (region_model::pop_frame): Likewise.
6726 (selftest::test_compound_assignment): Likewise.
6727 * region-model.h (region_model::copy_region): Delete decl.
6728 * region.cc (region_model::copy_region): Delete.
6729
6730 2022-02-02 David Malcolm <[email protected]>
6731
6732 * region.cc (region::calc_offset): Consolidate effectively
6733 identical cases.
6734
6735 2022-02-02 David Malcolm <[email protected]>
6736
6737 * analyzer.h (class bit_range_region): New forward decl.
6738 * region-model-manager.cc (region_model_manager::get_bit_range):
6739 New.
6740 (region_model_manager::log_stats): Handle m_bit_range_regions.
6741 * region-model.cc (region_model::get_lvalue_1): Handle
6742 BIT_FIELD_REF.
6743 * region-model.h (region_model_manager::get_bit_range): New decl.
6744 (region_model_manager::m_bit_range_regions): New field.
6745 * region.cc (region::get_base_region): Handle RK_BIT_RANGE.
6746 (region::base_region_p): Likewise.
6747 (region::calc_offset): Likewise.
6748 (bit_range_region::dump_to_pp): New.
6749 (bit_range_region::get_byte_size): New.
6750 (bit_range_region::get_bit_size): New.
6751 (bit_range_region::get_byte_size_sval): New.
6752 (bit_range_region::get_relative_concrete_offset): New.
6753 * region.h (enum region_kind): Add RK_BIT_RANGE.
6754 (region::dyn_cast_bit_range_region): New vfunc.
6755 (class bit_range_region): New.
6756 (is_a_helper <const bit_range_region *>::test): New.
6757 (default_hash_traits<bit_range_region::key_t>): New.
6758
6759 2022-02-02 David Malcolm <[email protected]>
6760
6761 PR analyzer/104270
6762 * region-model.cc (region_model::on_call_pre): Handle
6763 IFN_DEFERRED_INIT.
6764
6765 2022-01-27 David Malcolm <[email protected]>
6766
6767 * checker-path.cc (event_kind_to_string): Handle
6768 EK_REGION_CREATION.
6769 (region_creation_event::region_creation_event): New.
6770 (region_creation_event::get_desc): New.
6771 (checker_path::add_region_creation_event): New.
6772 * checker-path.h (enum event_kind): Add EK_REGION_CREATION.
6773 (class region_creation_event): New subclass.
6774 (checker_path::add_region_creation_event): New decl.
6775 * diagnostic-manager.cc
6776 (diagnostic_manager::emit_saved_diagnostic): Pass NULL for new
6777 param to add_events_for_eedge when handling trailing eedge.
6778 (diagnostic_manager::build_emission_path): Create an interesting_t
6779 instance, allow the pending diagnostic to populate it, and pass it
6780 to the calls to add_events_for_eedge.
6781 (diagnostic_manager::add_events_for_eedge): Add "interest" param.
6782 Use it to add region_creation_events for on-stack regions created
6783 within at function entry, and when pertinent dynamically-sized
6784 regions are created.
6785 (diagnostic_manager::prune_for_sm_diagnostic): Add case for
6786 EK_REGION_CREATION.
6787 * diagnostic-manager.h (diagnostic_manager::add_events_for_eedge):
6788 Add "interest" param.
6789 * pending-diagnostic.cc: Include "selftest.h", "tristate.h",
6790 "analyzer/call-string.h", "analyzer/program-point.h",
6791 "analyzer/store.h", and "analyzer/region-model.h".
6792 (interesting_t::add_region_creation): New.
6793 (interesting_t::dump_to_pp): New.
6794 * pending-diagnostic.h (struct interesting_t): New.
6795 (pending_diagnostic::mark_interesting_stuff): New vfunc.
6796 * region-model.cc
6797 (poisoned_value_diagnostic::poisoned_value_diagnostic): Add
6798 (poisoned_value_diagnostic::operator==): Compare m_pkind and
6799 m_src_region fields.
6800 (poisoned_value_diagnostic::mark_interesting_stuff): New.
6801 (poisoned_value_diagnostic::m_src_region): New.
6802 (region_model::check_for_poison): Call
6803 get_region_for_poisoned_expr for uninit values and pass the resul
6804 to the diagnostic.
6805 (region_model::get_region_for_poisoned_expr): New.
6806 (region_model::deref_rvalue): Pass NULL for
6807 poisoned_value_diagnostic's src_region.
6808 * region-model.h (region_model::get_region_for_poisoned_expr): New
6809 decl.
6810 * region.h (frame_region::get_fndecl): New.
6811
6812 2022-01-27 Martin Liska <[email protected]>
6813
6814 PR analyzer/104247
6815 * constraint-manager.cc (bounded_ranges_manager::log_stats):
6816 Cast to long for format purpose.
6817 * region-model-manager.cc (log_uniq_map): Likewise.
6818
6819 2022-01-26 David Malcolm <[email protected]>
6820
6821 PR analyzer/104224
6822 * region-model.cc (region_model::check_call_args): New.
6823 (region_model::on_call_pre): Call it when ignoring stdio builtins.
6824 * region-model.h (region_model::check_call_args): New decl
6825
6826 2022-01-26 David Malcolm <[email protected]>
6827
6828 PR analyzer/94362
6829 * constraint-manager.cc (range::add_bound): Fix tests for
6830 discarding redundant constraints. Perform test for rejecting
6831 unsatisfiable constraints earlier so that they don't update
6832 the object on failure.
6833 (selftest::test_range): New.
6834 (selftest::test_constant_comparisons): Add test coverage for
6835 existing constraints becoming narrower until they are
6836 unsatisfiable.
6837 (selftest::run_constraint_manager_tests): Call test_range.
6838
6839 2022-01-22 David Malcolm <[email protected]>
6840
6841 PR analyzer/104159
6842 * region-model-manager.cc
6843 (region_model_manager::get_or_create_cast): Bail out if the types
6844 are the same. Don't attempt to handle casts involving vector
6845 types.
6846
6847 2022-01-20 David Malcolm <[email protected]>
6848
6849 PR analyzer/94362
6850 * constraint-manager.cc (bound::ensure_closed): Convert param to
6851 enum bound_kind.
6852 (range::constrained_to_single_element): Likewise.
6853 (range::add_bound): New.
6854 (constraint_manager::add_constraint): Handle SVAL + OFFSET
6855 compared to a constant.
6856 (constraint_manager::get_ec_bounds): Rewrite in terms of
6857 range::add_bound.
6858 (constraint_manager::eval_condition): Reject if range::add_bound
6859 fails.
6860 (selftest::test_constant_comparisons): Add test coverage for
6861 various impossible combinations of integer comparisons.
6862 * constraint-manager.h (enum bound_kind): New.
6863 (struct bound): Likewise.
6864 (bound::ensure_closed): Convert to param to enum bound_kind.
6865 (struct range): Convert to...
6866 (class range): ...this, making fields private.
6867 (range::add_bound): New decls.
6868 * region-model.cc (region_model::add_constraint): Fail if
6869 constraint_manager::add_constraint fails.
6870
6871 2022-01-18 David Malcolm <[email protected]>
6872
6873 PR analyzer/104089
6874 * region-model-manager.cc
6875 (region_model_manager::get_or_create_constant_svalue): Assert that
6876 we have a CONSTANT_CLASS_P.
6877 (region_model_manager::maybe_fold_unaryop): Only fold a constant
6878 when fold_unary's result is a constant or a cast of a constant.
6879
6880 2022-01-18 David Malcolm <[email protected]>
6881
6882 PR analyzer/104062
6883 * region-model-manager.cc
6884 (region_model_manager::maybe_fold_sub_svalue): Avoid casting to
6885 NULL type when folding access to repeated svalue.
6886
6887 2022-01-17 Martin Liska <[email protected]>
6888
6889 * analyzer.cc (is_special_named_call_p): Rename .c names to .cc.
6890 (is_named_call_p): Likewise.
6891 * region-model-asm.cc (deterministic_p): Likewise.
6892 * region.cc (field_region::get_relative_concrete_offset): Likewise.
6893 * sm-malloc.cc (method_p): Likewise.
6894 * supergraph.cc (superedge::dump_dot): Likewise.
6895
6896 2022-01-14 David Malcolm <[email protected]>
6897
6898 * sm-taint.cc (taint_state_machine::combine_states): Handle combination
6899 of has_ub and has_lb.
6900
6901 2022-01-14 David Malcolm <[email protected]>
6902
6903 PR analyzer/104029
6904 * sm-taint.cc (taint_state_machine::alt_get_inherited_state):
6905 Remove gcc_unreachable from default case for unary ops.
6906
6907 2022-01-14 David Malcolm <[email protected]>
6908
6909 * engine.cc: Include "stringpool.h", "attribs.h", and
6910 "tree-dfa.h".
6911 (mark_params_as_tainted): New.
6912 (class tainted_args_function_custom_event): New.
6913 (class tainted_args_function_info): New.
6914 (exploded_graph::add_function_entry): Handle functions with
6915 "tainted_args" attribute.
6916 (class tainted_args_field_custom_event): New.
6917 (class tainted_args_callback_custom_event): New.
6918 (class tainted_args_call_info): New.
6919 (add_tainted_args_callback): New.
6920 (add_any_callbacks): New.
6921 (exploded_graph::build_initial_worklist): Likewise.
6922 (exploded_graph::build_initial_worklist): Find callbacks that are
6923 reachable from global initializers, calling add_any_callbacks on
6924 them.
6925
6926 2022-01-12 David Malcolm <[email protected]>
6927
6928 PR analyzer/103940
6929 * engine.cc (impl_sm_context::impl_sm_context): Add
6930 "unknown_side_effects" param and use it to initialize
6931 new m_unknown_side_effects field.
6932 (impl_sm_context::unknown_side_effects_p): New.
6933 (impl_sm_context::m_unknown_side_effects): New.
6934 (exploded_node::on_stmt): Pass unknown_side_effects to sm_ctxt
6935 ctor.
6936 * sm-taint.cc: Include "stringpool.h" and "attribs.h".
6937 (tainted_size::tainted_size): Drop "dir" param.
6938 (tainted_size::get_kind): Drop "FINAL".
6939 (tainted_size::emit): Likewise.
6940 (tainted_size::m_dir): Drop unused field.
6941 (class tainted_access_attrib_size): New subclass.
6942 (taint_state_machine::on_stmt): Call check_for_tainted_size_arg on
6943 external functions with unknown side effects.
6944 (taint_state_machine::check_for_tainted_size_arg): New.
6945 (region_model::check_region_for_taint): Drop "dir" param from
6946 tainted_size ctor.
6947 * sm.h (sm_context::unknown_side_effects_p): New.
6948
6949 2022-01-11 David Malcolm <[email protected]>
6950
6951 PR analyzer/102692
6952 * diagnostic-manager.cc
6953 (class auto_disable_complexity_checks): Rename to...
6954 (class auto_checking_feasibility): ...this, updating
6955 the calls accordingly.
6956 (epath_finder::explore_feasible_paths): Update for renaming.
6957 * region-model-manager.cc
6958 (region_model_manager::region_model_manager): Update for change from
6959 m_check_complexity to m_checking_feasibility.
6960 (region_model_manager::reject_if_too_complex): Likewise.
6961 (region_model_manager::get_or_create_unknown_svalue): Handle
6962 m_checking_feasibility.
6963 (region_model_manager::create_unique_svalue): New.
6964 (region_model_manager::maybe_fold_binop): Handle BIT_AND_EXPR and
6965 BIT_IOR_EXPRs on booleans where we know the result.
6966 * region-model.cc (test_binop_svalue_folding): Add test coverage
6967 for the above.
6968 * region-model.h (region_model_manager::create_unique_svalue): New
6969 decl.
6970 (region_model_manager::enable_complexity_check): Replace with...
6971 (region_model_manager::begin_checking_feasibility): ...this.
6972 (region_model_manager::disable_complexity_check): Replace with...
6973 (region_model_manager::end_checking_feasibility): ...this.
6974 (region_model_manager::m_check_complexity): Replace with...
6975 (region_model_manager::m_checking_feasibility): ...this.
6976 (region_model_manager::m_managed_dynamic_svalues): New field.
6977
6978 2022-01-08 David Malcolm <[email protected]>
6979
6980 * engine.cc (impl_run_checkers): Pass logger to engine ctor.
6981 * region-model-manager.cc
6982 (region_model_manager::region_model_manager): Add logger param and
6983 use it to initialize m_logger.
6984 * region-model.cc (engine::engine): New.
6985 * region-model.h (region_model_manager::region_model_manager):
6986 Add logger param.
6987 (region_model_manager::get_logger): New.
6988 (region_model_manager::m_logger): New field.
6989 (engine::engine): New.
6990 * store.cc (store_manager::get_logger): New.
6991 (store::set_value): Log scope. Log when marking a cluster as
6992 unknown due to possible aliasing.
6993 * store.h (store_manager::get_logger): New decl.
6994
6995 2022-01-08 David Malcolm <[email protected]>
6996
6997 * region-model-impl-calls.cc (cmp_decls): New.
6998 (cmp_decls_ptr_ptr): New.
6999 (region_model::impl_call_analyzer_dump_escaped): New.
7000 * region-model.cc (region_model::on_stmt_pre): Handle
7001 __analyzer_dump_escaped.
7002 * region-model.h (region_model::impl_call_analyzer_dump_escaped):
7003 New decl.
7004 * store.h (binding_cluster::get_base_region): New accessor.
7005
7006 2022-01-08 David Malcolm <[email protected]>
7007
7008 * region.cc (region::is_named_decl_p): New.
7009 * region.h (region::is_named_decl_p): New decl.
7010
7011 2022-01-06 David Malcolm <[email protected]>
7012
7013 PR analyzer/103546
7014 * store.cc (store::eval_alias_1): Refactor handling of decl
7015 regions, adding a test for may_be_aliased, rejecting those for
7016 which it returns false.
7017
7018 2021-12-12 Jonathan Wakely <[email protected]>
7019
7020 * engine.cc: Define INCLUDE_MEMORY instead of INCLUDE_UNIQUE_PTR.
7021
7022 2021-12-06 David Malcolm <[email protected]>
7023
7024 PR analyzer/103533
7025 * constraint-manager.cc (equiv_class::contains_non_constant_p):
7026 New.
7027 (constraint_manager::canonicalize): Call it when determining
7028 redundant ECs.
7029 (selftest::test_purging): New selftest.
7030 (selftest::run_constraint_manager_tests): Likewise.
7031 * constraint-manager.h (equiv_class::contains_non_constant_p):
7032 New decl.
7033
7034 2021-12-01 David Malcolm <[email protected]>
7035
7036 PR analyzer/102471
7037 * region-model-reachability.cc (reachable_regions::handle_parm):
7038 Treat all svalues within a compound parm has reachable, and those
7039 wrapped in a cast.
7040
7041 2021-11-29 David Malcolm <[email protected]>
7042
7043 PR analyzer/103217
7044 * store.cc (binding_cluster::can_merge_p): For the "key is bound"
7045 vs "key is not bound" merger case, check that the bound svalue
7046 is mergeable before merging it to "unknown", rejecting the merger
7047 otherwise.
7048
7049 2021-11-19 David Malcolm <[email protected]>
7050
7051 PR analyzer/103217
7052 * engine.cc (exploded_graph::get_or_create_node): Pass in
7053 m_ext_state to program_state::can_merge_with_p.
7054 (exploded_graph::process_worklist): Likewise.
7055 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
7056 Likewise.
7057 (exploded_graph::process_node): Add missing call to detect_leaks
7058 when handling phi nodes.
7059 * program-state.cc (program_state::can_merge_with_p): Add
7060 "ext_state" param. Pass it and state ptrs to
7061 region_model::can_merge_with_p.
7062 (selftest::test_program_state_merging): Update for new ext_state
7063 param of program_state::can_merge_with_p.
7064 (selftest::test_program_state_merging_2): Likewise.
7065 * program-state.h (program_state::can_purge_p): Make const.
7066 (program_state::can_merge_with_p): Add "ext_state" param.
7067 * region-model.cc: Include "analyzer/program-state.h".
7068 (region_model::can_merge_with_p): Add params "ext_state",
7069 "state_a", and "state_b", use them when creating model_merger
7070 object.
7071 (model_merger::mergeable_svalue_p): New.
7072 * region-model.h (region_model::can_merge_with_p): Add params
7073 "ext_state", "state_a", and "state_b".
7074 (model_merger::model_merger) Likewise, initializing new fields.
7075 (model_merger::mergeable_svalue_p): New decl.
7076 (model_merger::m_ext_state): New field.
7077 (model_merger::m_state_a): New field.
7078 (model_merger::m_state_b): New field.
7079 * svalue.cc (svalue::can_merge_p): Call
7080 model_merger::mergeable_svalue_p on both states and reject the
7081 merger accordingly.
7082
7083 2021-11-17 David Malcolm <[email protected]>
7084
7085 PR analyzer/102695
7086 * region-model-impl-calls.cc (region_model::impl_call_strchr): New.
7087 * region-model-manager.cc
7088 (region_model_manager::maybe_fold_unaryop): Simplify cast to
7089 pointer type of an existing pointer to a region.
7090 * region-model.cc (region_model::on_call_pre): Handle
7091 BUILT_IN_STRCHR and "strchr".
7092 (write_to_const_diagnostic::emit): Add auto_diagnostic_group. Add
7093 alternate wordings for functions and labels.
7094 (write_to_const_diagnostic::describe_final_event): Add alternate
7095 wordings for functions and labels.
7096 (region_model::check_for_writable_region): Handle RK_FUNCTION and
7097 RK_LABEL.
7098 * region-model.h (region_model::impl_call_strchr): New decl.
7099
7100 2021-11-16 David Malcolm <[email protected]>
7101
7102 PR analyzer/102662
7103 * constraint-manager.cc (bounded_range::operator==): Require the
7104 types to be the same for equality.
7105
7106 2021-11-13 David Malcolm <[email protected]>
7107
7108 * analyzer.opt (Wanalyzer-tainted-allocation-size): New.
7109 (Wanalyzer-tainted-divisor): New.
7110 (Wanalyzer-tainted-offset): New.
7111 (Wanalyzer-tainted-size): New.
7112 * engine.cc (impl_region_model_context::get_taint_map): New.
7113 * exploded-graph.h (impl_region_model_context::get_taint_map):
7114 New decl.
7115 * program-state.cc (sm_state_map::get_state): Call
7116 alt_get_inherited_state.
7117 (sm_state_map::impl_set_state): Modify states within
7118 compound svalues.
7119 (program_state::impl_call_analyzer_dump_state): Undo casts.
7120 (selftest::test_program_state_1): Update for new context param of
7121 create_region_for_heap_alloc.
7122 (selftest::test_program_state_merging): Likewise.
7123 * region-model-impl-calls.cc (region_model::impl_call_alloca):
7124 Likewise.
7125 (region_model::impl_call_calloc): Likewise.
7126 (region_model::impl_call_malloc): Likewise.
7127 (region_model::impl_call_operator_new): Likewise.
7128 (region_model::impl_call_realloc): Likewise.
7129 * region-model.cc (region_model::check_region_access): Call
7130 check_region_for_taint.
7131 (region_model::get_representative_path_var_1): Handle binops.
7132 (region_model::create_region_for_heap_alloc): Add "ctxt" param and
7133 pass it to set_dynamic_extents.
7134 (region_model::create_region_for_alloca): Likewise.
7135 (region_model::set_dynamic_extents): Add "ctxt" param and use it
7136 to call check_dynamic_size_for_taint.
7137 (selftest::test_state_merging): Update for new context param of
7138 create_region_for_heap_alloc.
7139 (selftest::test_malloc_constraints): Likewise.
7140 (selftest::test_malloc): Likewise.
7141 (selftest::test_alloca): Likewise for create_region_for_alloca.
7142 * region-model.h (region_model::create_region_for_heap_alloc): Add
7143 "ctxt" param.
7144 (region_model::create_region_for_alloca): Likewise.
7145 (region_model::set_dynamic_extents): Likewise.
7146 (region_model::check_dynamic_size_for_taint): New decl.
7147 (region_model::check_region_for_taint): New decl.
7148 (region_model_context::get_taint_map): New vfunc.
7149 (noop_region_model_context::get_taint_map): New.
7150 * sm-taint.cc: Remove include of "diagnostic-event-id.h"; add
7151 includes of "gimple-iterator.h", "tristate.h", "selftest.h",
7152 "ordered-hash-map.h", "cgraph.h", "cfg.h", "digraph.h",
7153 "analyzer/supergraph.h", "analyzer/call-string.h",
7154 "analyzer/program-point.h", "analyzer/store.h",
7155 "analyzer/region-model.h", and "analyzer/program-state.h".
7156 (enum bounds): Move to top of file.
7157 (class taint_diagnostic): New.
7158 (class tainted_array_index): Convert to subclass of taint_diagnostic.
7159 (tainted_array_index::emit): Add CWE-129. Reword warning to use
7160 "attacker-controlled" rather than "tainted".
7161 (tainted_array_index::describe_state_change): Move to
7162 taint_diagnostic::describe_state_change.
7163 (tainted_array_index::describe_final_event): Reword to use
7164 "attacker-controlled" rather than "tainted".
7165 (class tainted_offset): New.
7166 (class tainted_size): New.
7167 (class tainted_divisor): New.
7168 (class tainted_allocation_size): New.
7169 (taint_state_machine::alt_get_inherited_state): New.
7170 (taint_state_machine::on_stmt): In assignment handling, remove
7171 ARRAY_REF handling in favor of check_region_for_taint. Add
7172 detection of tainted divisors.
7173 (taint_state_machine::get_taint): New.
7174 (taint_state_machine::combine_states): New.
7175 (region_model::check_region_for_taint): New.
7176 (region_model::check_dynamic_size_for_taint): New.
7177 * sm.h (state_machine::alt_get_inherited_state): New.
7178
7179 2021-11-12 David Malcolm <[email protected]>
7180
7181 * engine.cc (exploded_node::on_stmt_pre): Return when handling
7182 "__analyzer_dump_state".
7183
7184 2021-11-11 Richard Biener <[email protected]>
7185
7186 * supergraph.cc: Include bitmap.h.
7187
7188 2021-11-04 David Malcolm <[email protected]>
7189
7190 * program-state.cc (sm_state_map::dump): Use default_tree_printer
7191 as format decoder.
7192
7193 2021-09-16 Maxim Blinov <[email protected]>
7194
7195 PR bootstrap/102242
7196 * engine.cc (INCLUDE_UNIQUE_PTR): Define.
7197
7198 2021-09-08 David Malcolm <[email protected]>
7199
7200 PR analyzer/102225
7201 * analyzer.h (compat_types_p): New decl.
7202 * constraint-manager.cc
7203 (constraint_manager::get_or_add_equiv_class): Guard against NULL
7204 type when checking for pointer types.
7205 * region-model-impl-calls.cc (region_model::impl_call_realloc):
7206 Guard against NULL lhs type/region. Guard against the size value
7207 not being of a compatible type for dynamic extents.
7208 * region-model.cc (compat_types_p): Make non-static.
7209
7210 2021-08-30 David Malcolm <[email protected]>
7211
7212 PR analyzer/99260
7213 * analyzer.h (class custom_edge_info): New class, adapted from
7214 exploded_edge::custom_info_t. Make member functions const.
7215 Make update_model return bool, converting edge param from
7216 reference to a pointer, and adding a ctxt param.
7217 (class path_context): New class.
7218 * call-info.cc: New file.
7219 * call-info.h: New file.
7220 * engine.cc: Include "analyzer/call-info.h" and <memory>.
7221 (impl_region_model_context::impl_region_model_context): Update for
7222 new m_path_ctxt field.
7223 (impl_region_model_context::bifurcate): New.
7224 (impl_region_model_context::terminate_path): New.
7225 (impl_region_model_context::get_malloc_map): New.
7226 (impl_sm_context::impl_sm_context): Update for new m_path_ctxt
7227 field.
7228 (impl_sm_context::get_fndecl_for_call): Likewise.
7229 (impl_sm_context::set_next_state): Likewise.
7230 (impl_sm_context::warn): Likewise.
7231 (impl_sm_context::is_zero_assignment): Likewise.
7232 (impl_sm_context::get_path_context): New.
7233 (impl_sm_context::m_path_ctxt): New.
7234 (impl_region_model_context::on_condition): Update for new
7235 path_ctxt param. Handle m_enode_for_diag being NULL.
7236 (impl_region_model_context::on_phi): Update for new path_ctxt
7237 param.
7238 (exploded_node::on_stmt): Add path_ctxt param, updating ctor calls
7239 to use it as necessary. Use it to bail out after sm-handling,
7240 if needed.
7241 (exploded_node::detect_leaks): Update for new path_ctxt param.
7242 (dynamic_call_info_t::update_model): Update for conversion of
7243 exploded_edge::custom_info_t to custom_edge_info.
7244 (dynamic_call_info_t::add_events_to_path): Likewise.
7245 (rewind_info_t::update_model): Likewise.
7246 (rewind_info_t::add_events_to_path): Likewise.
7247 (exploded_edge::exploded_edge): Likewise.
7248 (exploded_graph::add_edge): Likewise.
7249 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
7250 Update for new path_ctxt param.
7251 (class impl_path_context): New.
7252 (exploded_graph::process_node): Update for new path_ctxt param.
7253 Create an impl_path_context and pass it to exploded_node::on_stmt.
7254 Use it to terminate iterating stmts if terminate_path is called
7255 on it. After processing a run of stmts, query path_ctxt to
7256 potentially terminate the analysis path, and/or to "bifurcate" the
7257 analysis into multiple additional paths.
7258 (feasibility_state::maybe_update_for_edge): Update for new
7259 update_model ctxt param.
7260 * exploded-graph.h
7261 (impl_region_model_context::impl_region_model_context): Add
7262 path_ctxt param.
7263 (impl_region_model_context::bifurcate): New.
7264 (impl_region_model_context::terminate_path): New
7265 (impl_region_model_context::get_ext_state): New.
7266 (impl_region_model_context::get_malloc_map): New.
7267 (impl_region_model_context::m_path_ctxt): New field.
7268 (exploded_node::on_stmt): Add path_ctxt param.
7269 (class exploded_edge::custom_info_t): Move to analyzer.h, renaming
7270 to custom_edge_info, and making the changes as noted in analyzer.h
7271 above.
7272 (exploded_edge::exploded_edge): Update for these changes to
7273 exploded_edge::custom_info_t.
7274 (exploded_edge::m_custom_info): Likewise.
7275 (class dynamic_call_info_t): Likewise.
7276 (class rewind_info_t): Likewise.
7277 (exploded_graph::add_edge): Likewise.
7278 * program-state.cc (program_state::on_edge): Update for new
7279 path_ctxt param.
7280 (program_state::push_call): Likewise.
7281 (program_state::returning_call): Likewise.
7282 (program_state::prune_for_point): Likewise.
7283 * region-model-impl-calls.cc: Include "analyzer/call-info.h".
7284 (call_details::get_fndecl_for_call): New.
7285 (region_model::impl_call_realloc): Reimplement.
7286 * region-model.cc (region_model::on_call_pre): Move call to
7287 impl_call_realloc to...
7288 (region_model::on_call_post): ...here. Consolidate creation
7289 of call_details instance.
7290 (noop_region_model_context::bifurcate): New.
7291 (noop_region_model_context::terminate_path): New.
7292 * region-model.h (call_details::get_call_stmt): New.
7293 (call_details::get_fndecl_for_call): New.
7294 (region_model::on_realloc_with_move): New.
7295 (region_model_context::bifurcate): New.
7296 (region_model_context::terminate_path): New.
7297 (region_model_context::get_ext_state): New.
7298 (region_model_context::get_malloc_map): New.
7299 (noop_region_model_context::bifurcate): New.
7300 (noop_region_model_context::terminate_path): New.
7301 (noop_region_model_context::get_ext_state): New.
7302 (noop_region_model_context::get_malloc_map): New.
7303 * sm-malloc.cc: Include "analyzer/program-state.h".
7304 (malloc_state_machine::on_realloc_call): Reimplement.
7305 (malloc_state_machine::on_realloc_with_move): New.
7306 (region_model::on_realloc_with_move): New.
7307 * sm-signal.cc (class signal_delivery_edge_info_t): Update for
7308 conversion from exploded_edge::custom_info_t to custom_edge_info.
7309 * sm.h (sm_context::get_path_context): New.
7310 * svalue.cc (svalue::maybe_get_constant): Call
7311 unwrap_any_unmergeable.
7312
7313 2021-08-25 Ankur Saini <[email protected]>
7314
7315 PR analyzer/101980
7316 * engine.cc (exploded_graph::maybe_create_dynamic_call): Don't create
7317 calls if max recursion limit is reached.
7318
7319 2021-08-23 David Malcolm <[email protected]>
7320
7321 * analyzer.h (struct rejected_constraint): Convert to...
7322 (class rejected_constraint): ...this.
7323 (class bounded_ranges): New forward decl.
7324 (class bounded_ranges_manager): New forward decl.
7325 * constraint-manager.cc: Include "analyzer/analyzer-logging.h" and
7326 "tree-pretty-print.h".
7327 (can_plus_one_p): New.
7328 (plus_one): New.
7329 (can_minus_one_p): New.
7330 (minus_one): New.
7331 (bounded_range::bounded_range): New.
7332 (dump_cst): New.
7333 (bounded_range::dump_to_pp): New.
7334 (bounded_range::dump): New.
7335 (bounded_range::to_json): New.
7336 (bounded_range::set_json_attr): New.
7337 (bounded_range::contains_p): New.
7338 (bounded_range::intersects_p): New.
7339 (bounded_range::operator==): New.
7340 (bounded_range::cmp): New.
7341 (bounded_ranges::bounded_ranges): New.
7342 (bounded_ranges::bounded_ranges): New.
7343 (bounded_ranges::bounded_ranges): New.
7344 (bounded_ranges::canonicalize): New.
7345 (bounded_ranges::validate): New.
7346 (bounded_ranges::operator==): New.
7347 (bounded_ranges::dump_to_pp): New.
7348 (bounded_ranges::dump): New.
7349 (bounded_ranges::to_json): New.
7350 (bounded_ranges::eval_condition): New.
7351 (bounded_ranges::contain_p): New.
7352 (bounded_ranges::cmp): New.
7353 (bounded_ranges_manager::~bounded_ranges_manager): New.
7354 (bounded_ranges_manager::get_or_create_empty): New.
7355 (bounded_ranges_manager::get_or_create_point): New.
7356 (bounded_ranges_manager::get_or_create_range): New.
7357 (bounded_ranges_manager::get_or_create_union): New.
7358 (bounded_ranges_manager::get_or_create_intersection): New.
7359 (bounded_ranges_manager::get_or_create_inverse): New.
7360 (bounded_ranges_manager::consolidate): New.
7361 (bounded_ranges_manager::get_or_create_ranges_for_switch): New.
7362 (bounded_ranges_manager::create_ranges_for_switch): New.
7363 (bounded_ranges_manager::make_case_label_ranges): New.
7364 (bounded_ranges_manager::log_stats): New.
7365 (bounded_ranges_constraint::print): New.
7366 (bounded_ranges_constraint::to_json): New.
7367 (bounded_ranges_constraint::operator==): New.
7368 (bounded_ranges_constraint::add_to_hash): New.
7369 (constraint_manager::constraint_manager): Update for new field
7370 m_bounded_ranges_constraints.
7371 (constraint_manager::operator=): Likewise.
7372 (constraint_manager::hash): Likewise.
7373 (constraint_manager::operator==): Likewise.
7374 (constraint_manager::print): Likewise.
7375 (constraint_manager::dump_to_pp): Likewise.
7376 (constraint_manager::to_json): Likewise.
7377 (constraint_manager::add_unknown_constraint): Update the lhs_ec_id
7378 if necessary in existing constraints when combining equivalence
7379 classes. Add similar code for handling
7380 m_bounded_ranges_constraints.
7381 (constraint_manager::add_constraint_internal): Add comment.
7382 (constraint_manager::add_bounded_ranges): New.
7383 (constraint_manager::eval_condition): Use new field
7384 m_bounded_ranges_constraints.
7385 (constraint_manager::purge): Update bounded_ranges_constraint
7386 instances.
7387 (constraint_manager::canonicalize): Update for new field.
7388 (merger_fact_visitor::on_ranges): New.
7389 (constraint_manager::for_each_fact): Use new field
7390 m_bounded_ranges_constraints.
7391 (constraint_manager::validate): Fix off-by-one error needed due
7392 to bug fixed above in add_unknown_constraint. Validate the EC IDs
7393 in m_bounded_ranges_constraints.
7394 (constraint_manager::get_range_manager): New.
7395 (selftest::assert_dump_bounded_range_eq): New.
7396 (ASSERT_DUMP_BOUNDED_RANGE_EQ): New.
7397 (selftest::test_bounded_range): New.
7398 (selftest::assert_dump_bounded_ranges_eq): New.
7399 (ASSERT_DUMP_BOUNDED_RANGES_EQ): New.
7400 (selftest::test_bounded_ranges): New.
7401 (selftest::run_constraint_manager_tests): Call the new selftests.
7402 * constraint-manager.h (struct bounded_range): New.
7403 (struct bounded_ranges): New.
7404 (template <> struct default_hash_traits<bounded_ranges::key_t>): New.
7405 (class bounded_ranges_manager): New.
7406 (fact_visitor::on_ranges): New pure virtual function.
7407 (class bounded_ranges_constraint): New.
7408 (constraint_manager::add_bounded_ranges): New decl.
7409 (constraint_manager::get_range_manager): New decl.
7410 (constraint_manager::m_bounded_ranges_constraints): New field.
7411 * diagnostic-manager.cc (epath_finder::process_worklist_item):
7412 Transfer ownership of rc to add_feasibility_problem.
7413 * engine.cc (feasibility_problem::dump_to_pp): Use get_model.
7414 * feasible-graph.cc (infeasible_node::dump_dot): Update for
7415 conversion of m_rc to a pointer.
7416 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
7417 take ownership.
7418 * feasible-graph.h (infeasible_node::infeasible_node): Pass RC by
7419 pointer and take ownership.
7420 (infeasible_node::~infeasible_node): New.
7421 (infeasible_node::m_rc): Convert to a pointer.
7422 (feasible_graph::add_feasibility_problem): Pass RC by pointer and
7423 take ownership.
7424 * region-model-manager.cc: Include
7425 "analyzer/constraint-manager.h".
7426 (region_model_manager::region_model_manager): Initializer new
7427 field m_range_mgr.
7428 (region_model_manager::~region_model_manager): Delete it.
7429 (region_model_manager::log_stats): Call log_stats on it.
7430 * region-model.cc (region_model::add_constraint): Use new subclass
7431 rejected_op_constraint.
7432 (region_model::apply_constraints_for_gswitch): Reimplement using
7433 bounded_ranges_manager.
7434 (rejected_constraint::dump_to_pp): Convert to...
7435 (rejected_op_constraint::dump_to_pp): ...this.
7436 (rejected_ranges_constraint::dump_to_pp): New.
7437 * region-model.h (struct purge_stats): Add field
7438 m_num_bounded_ranges_constraints.
7439 (region_model_manager::get_range_manager): New.
7440 (region_model_manager::m_range_mgr): New.
7441 (region_model::get_range_manager): New.
7442 (struct rejected_constraint): Split into...
7443 (class rejected_constraint):...this new abstract base class,
7444 and...
7445 (class rejected_op_constraint): ...this new concrete subclass.
7446 (class rejected_ranges_constraint): New.
7447 * supergraph.cc: Include "tree-cfg.h".
7448 (supergraph::supergraph): Drop idx param from add_cfg_edge.
7449 (supergraph::add_cfg_edge): Drop idx param.
7450 (switch_cfg_superedge::switch_cfg_superedge): Move here from
7451 header. Populate m_case_labels with all cases which go to DST.
7452 (switch_cfg_superedge::dump_label_to_pp): Reimplement to use
7453 m_case_labels.
7454 (switch_cfg_superedge::get_case_label): Delete.
7455 * supergraph.h (supergraphadd_cfg_edge): Drop "idx" param.
7456 (switch_cfg_superedge::switch_cfg_superedge): Drop idx param and
7457 move implementation to supergraph.cc.
7458 (switch_cfg_superedge::get_case_label): Delete.
7459 (switch_cfg_superedge::get_case_labels): New.
7460 (switch_cfg_superedge::m_idx): Delete.
7461 (switch_cfg_superedge::m_case_labels): New field.
7462
7463 2021-08-23 David Malcolm <[email protected]>
7464
7465 PR analyzer/101875
7466 * sm-file.cc (file_diagnostic::describe_state_change): Handle
7467 change.m_expr being NULL.
7468
7469 2021-08-23 David Malcolm <[email protected]>
7470
7471 PR analyzer/101837
7472 * analyzer.cc (maybe_reconstruct_from_def_stmt): Bail if fn is
7473 NULL, and assert that it's non-NULL before passing it to
7474 build_call_array_loc.
7475
7476 2021-08-23 David Malcolm <[email protected]>
7477
7478 PR analyzer/101962
7479 * region-model.cc (region_model::eval_condition_without_cm):
7480 Refactor comparison against zero, adding a check for
7481 POINTER_PLUS_EXPR of non-NULL.
7482
7483 2021-08-23 David Malcolm <[email protected]>
7484
7485 * store.cc (bit_range::intersects_p): New overload.
7486 (bit_range::operator-): New.
7487 (binding_cluster::maybe_get_compound_binding): Handle the partial
7488 overlap case.
7489 (selftest::test_bit_range_intersects_p): Add test coverage for
7490 new overload of bit_range::intersects_p.
7491 * store.h (bit_range::intersects_p): New overload.
7492 (bit_range::operator-): New.
7493
7494 2021-08-23 Ankur Saini <[email protected]>
7495
7496 PR analyzer/102020
7497 * diagnostic-manager.cc
7498 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Fix typo.
7499
7500 2021-08-21 Ankur Saini <[email protected]>
7501
7502 PR analyzer/101980
7503 * diagnostic-manager.cc
7504 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>: Use
7505 caller_model only when the supergraph_edge doesn't exixt.
7506 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
7507 Likewise.
7508 * engine.cc (exploded_graph::create_dynamic_call): Rename to...
7509 (exploded_graph::maybe_create_dynamic_call): ...this, return call
7510 creation status.
7511 (exploded_graph::process_node): Handle calls which were not dynamically
7512 discovered.
7513 * exploded-graph.h (exploded_graph::create_dynamic_call): Rename to...
7514 (exploded_graph::maybe_create_dynamic_call): ...this.
7515 * region-model.cc (region_model::update_for_gcall): New param, use it
7516 to push call to frame.
7517 (region_model::update_for_call_superedge): Pass callee function to
7518 update_for_gcall.
7519 * region-model.h (region_model::update_for_gcall): New param.
7520
7521 2021-08-18 Ankur Saini <[email protected]>
7522
7523 PR analyzer/97114
7524 * region-model.cc (region_model::get_rvalue_1): Add case for
7525 OBJ_TYPE_REF.
7526
7527 2021-08-18 Ankur Saini <[email protected]>
7528
7529 PR analyzer/100546
7530 * analysis-plan.cc (analysis_plan::use_summary_p): Don't use call
7531 summaries if there is no callgraph edge
7532 * checker-path.cc (call_event::call_event): Handle calls events that
7533 are not represented by a supergraph call edge
7534 (return_event::return_event): Likewise.
7535 (call_event::get_desc): Work with new call_event structure.
7536 (return_event::get_desc): Likeise.
7537 * checker-path.h (call_event::m_src_snode): New field.
7538 (call_event::m_dest_snode): New field.
7539 (return_event::m_src_snode): New field.
7540 (return_event::m_dest_snode): New field.
7541 * diagnostic-manager.cc
7542 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_CALL_EDGE>:
7543 Refactor to work with edges without callgraph edge.
7544 (diagnostic_manager::prune_for_sm_diagnostic)<case EK_RETURN_EDGE>:
7545 Likewise.
7546 * engine.cc (dynamic_call_info_t::update_model): New function.
7547 (dynamic_call_info_t::add_events_to_path): New function.
7548 (exploded_graph::create_dynamic_call): New function.
7549 (exploded_graph::process_node): Work with dynamically discovered calls.
7550 * exploded-graph.h (class dynamic_call_info_t): New class.
7551 (exploded_graph::create_dynamic_call): New decl.
7552 * program-point.cc (program_point::push_to_call_stack): New function.
7553 (program_point::pop_from_call_stack): New function.
7554 * program-point.h (program_point::push_to_call_stack): New decl.
7555 (program_point::pop_from_call_stack): New decl.
7556 * program-state.cc (program_state::push_call): New function.
7557 (program_state::returning_call): New function.
7558 * program-state.h (program_state::push_call): New decl.
7559 (program_state::returning_call): New decl.
7560 * region-model.cc (region_model::update_for_gcall) New function.
7561 (region_model::update_for_return_gcall): New function.
7562 (egion_model::update_for_call_superedge): Get the underlying gcall and
7563 update for gcall.
7564 (region_model::update_for_return_superedge): Likewise.
7565 * region-model.h (region_model::update_for_gcall): New decl.
7566 (region_model::update_for_return_gcall): New decl.
7567 * state-purge.cc (state_purge_per_ssa_name::process_point): Update to
7568 work with calls without underlying cgraph edge.
7569 * supergraph.cc (supergraph::supergraph) Split snodes at every callsite.
7570 * supergraph.h (supernode::get_returning_call) New accessor.
7571
7572 2021-08-04 David Malcolm <[email protected]>
7573
7574 PR analyzer/101570
7575 * analyzer.cc (maybe_reconstruct_from_def_stmt): Add GIMPLE_ASM
7576 case.
7577 * analyzer.h (class asm_output_svalue): New forward decl.
7578 (class reachable_regions): New forward decl.
7579 * complexity.cc (complexity::from_vec_svalue): New.
7580 * complexity.h (complexity::from_vec_svalue): New decl.
7581 * engine.cc (feasibility_state::maybe_update_for_edge): Handle
7582 asm stmts by calling on_asm_stmt.
7583 * region-model-asm.cc: New file.
7584 * region-model-manager.cc
7585 (region_model_manager::maybe_fold_asm_output_svalue): New.
7586 (region_model_manager::get_or_create_asm_output_svalue): New.
7587 (region_model_manager::log_stats): Log m_asm_output_values_map.
7588 * region-model.cc (region_model::on_stmt_pre): Handle GIMPLE_ASM.
7589 * region-model.h (visitor::visit_asm_output_svalue): New.
7590 (region_model_manager::get_or_create_asm_output_svalue): New decl.
7591 (region_model_manager::maybe_fold_asm_output_svalue): New decl.
7592 (region_model_manager::asm_output_values_map_t): New typedef.
7593 (region_model_manager::m_asm_output_values_map): New field.
7594 (region_model::on_asm_stmt): New.
7595 * store.cc (binding_cluster::on_asm): New.
7596 * store.h (binding_cluster::on_asm): New decl.
7597 * svalue.cc (svalue::cmp_ptr): Handle SK_ASM_OUTPUT.
7598 (asm_output_svalue::dump_to_pp): New.
7599 (asm_output_svalue::dump_input): New.
7600 (asm_output_svalue::input_idx_to_asm_idx): New.
7601 (asm_output_svalue::accept): New.
7602 * svalue.h (enum svalue_kind): Add SK_ASM_OUTPUT.
7603 (svalue::dyn_cast_asm_output_svalue): New.
7604 (class asm_output_svalue): New.
7605 (is_a_helper <const asm_output_svalue *>::test): New.
7606 (struct default_hash_traits<asm_output_svalue::key_t>): New.
7607
7608 2021-08-03 Jakub Jelinek <[email protected]>
7609
7610 PR analyzer/101721
7611 * sm-malloc.cc (known_allocator_p): Only check DECL_FUNCTION_CODE on
7612 BUILT_IN_NORMAL builtins.
7613
7614 2021-07-29 Ankur Saini <[email protected]>
7615
7616 * call-string.cc (call_string::element_t::operator==): New operator.
7617 (call_String::element_t::operator!=): New operator.
7618 (call_string::element_t::get_caller_function): New function.
7619 (call_string::element_t::get_callee_function): New function.
7620 (call_string::call_string): Refactor to Initialise m_elements.
7621 (call_string::operator=): Refactor to work with m_elements.
7622 (call_string::operator==): Likewise.
7623 (call_string::to_json): Likewise.
7624 (call_string::hash): Refactor to hash e.m_caller.
7625 (call_string::push_call): Refactor to work with m_elements.
7626 (call_string::push_call): New overload to push call via supernodes.
7627 (call_string::pop): Refactor to work with m_elements.
7628 (call_string::calc_recursion_depth): Likewise.
7629 (call_string::cmp): Likewise.
7630 (call_string::validate): Likewise.
7631 (call_string::operator[]): Likewise.
7632 * call-string.h (class supernode): New forward decl.
7633 (struct call_string::element_t): New struct.
7634 (call_string::call_string): Refactor to initialise m_elements.
7635 (call_string::bool empty_p): Refactor to work with m_elements.
7636 (call_string::get_callee_node): New decl.
7637 (call_string::get_caller_node): New decl.
7638 (m_elements): Replaces m_return_edges.
7639 * program-point.cc (program_point::get_function_at_depth): Refactor to
7640 work with new call-string format.
7641 (program_point::validate): Likewise.
7642 (program_point::on_edge): Likewise.
7643
7644 2021-07-28 David Malcolm <[email protected]>
7645
7646 * region-model.cc (region_model::on_call_pre): Treat
7647 IFN_UBSAN_BOUNDS, BUILT_IN_STACK_SAVE, and BUILT_IN_STACK_RESTORE
7648 as no-ops, rather than handling them as unknown functions.
7649
7650 2021-07-28 David Malcolm <[email protected]>
7651
7652 * region-model-impl-calls.cc (region_model::impl_call_alloca):
7653 Drop redundant return value.
7654 (region_model::impl_call_builtin_expect): Likewise.
7655 (region_model::impl_call_calloc): Likewise.
7656 (region_model::impl_call_malloc): Likewise.
7657 (region_model::impl_call_memset): Likewise.
7658 (region_model::impl_call_operator_new): Likewise.
7659 (region_model::impl_call_operator_delete): Likewise.
7660 (region_model::impl_call_strlen): Likewise.
7661 * region-model.cc (region_model::on_call_pre): Fix return value of
7662 known functions that don't have unknown side-effects.
7663 * region-model.h (region_model::impl_call_alloca): Drop redundant
7664 return value.
7665 (region_model::impl_call_builtin_expect): Likewise.
7666 (region_model::impl_call_calloc): Likewise.
7667 (region_model::impl_call_malloc): Likewise.
7668 (region_model::impl_call_memset): Likewise.
7669 (region_model::impl_call_strlen): Likewise.
7670 (region_model::impl_call_operator_new): Likewise.
7671 (region_model::impl_call_operator_delete): Likewise.
7672
7673 2021-07-28 Siddhesh Poyarekar <[email protected]>
7674
7675 * analyzer.cc (is_named_call_p, is_std_named_call_p): Make
7676 first argument a const_tree.
7677 * analyzer.h (is_named_call_p, -s_std_named_call_p): Likewise.
7678 * sm-malloc.cc (known_allocator_p): New function.
7679 (malloc_state_machine::on_stmt): Use it.
7680
7681 2021-07-28 Siddhesh Poyarekar <[email protected]>
7682
7683 * sm-malloc.cc
7684 (malloc_state_machine::get_or_create_deallocator): Recognize
7685 __builtin_free.
7686
7687 2021-07-26 David Malcolm <[email protected]>
7688
7689 * region-model.cc (region_model::on_call_pre): Always set conjured
7690 LHS, not just for SSA names.
7691
7692 2021-07-23 David Malcolm <[email protected]>
7693
7694 * diagnostic-manager.cc
7695 (class auto_disable_complexity_checks): New.
7696 (epath_finder::explore_feasible_paths): Use it to disable
7697 complexity checks whilst processing the worklist.
7698 * region-model-manager.cc
7699 (region_model_manager::region_model_manager): Initialize
7700 m_check_complexity.
7701 (region_model_manager::reject_if_too_complex): Bail if
7702 m_check_complexity is false.
7703 * region-model.h
7704 (region_model_manager::enable_complexity_check): New.
7705 (region_model_manager::disable_complexity_check): New.
7706 (region_model_manager::m_check_complexity): New.
7707
7708 2021-07-21 David Malcolm <[email protected]>
7709
7710 PR analyzer/101547
7711 * sm-file.cc (file_leak::emit): Handle m_arg being NULL.
7712 (file_leak::describe_final_event): Handle ev.m_expr being NULL.
7713
7714 2021-07-21 David Malcolm <[email protected]>
7715
7716 PR analyzer/101522
7717 * store.cc (binding_cluster::purge_state_involving): Don't change
7718 m_map whilst iterating through it.
7719
7720 2021-07-21 David Malcolm <[email protected]>
7721
7722 * region-model.cc (region_model::handle_phi): Add "old_state"
7723 param and use it.
7724 (region_model::update_for_phis): Update so that all of the phi
7725 stmts are effectively handled simultaneously, rather than in
7726 order.
7727 * region-model.h (region_model::handle_phi): Add "old_state"
7728 param.
7729 * state-purge.cc (self_referential_phi_p): Replace with...
7730 (name_used_by_phis_p): ...this new function.
7731 (state_purge_per_ssa_name::process_point): Update to use the
7732 above, so that all phi stmts at a basic block are effectively
7733 considered simultaneously, and only consider the phi arguments for
7734 the pertinent in-edge.
7735 * supergraph.cc (cfg_superedge::get_phi_arg_idx): New.
7736 (cfg_superedge::get_phi_arg): Use the above.
7737 * supergraph.h (cfg_superedge::get_phi_arg_idx): New decl.
7738
7739 2021-07-21 David Malcolm <[email protected]>
7740
7741 * state-purge.cc (state_purge_annotator::add_node_annotations):
7742 Rather than erroneously always using the NULL in-edge, determine
7743 each relevant in-edge, and print the appropriate data for each
7744 in-edge. Use print_needed to print the data as comma-separated
7745 lists of SSA names.
7746 (print_vec_of_names): Add "within_table" param and use it.
7747 (state_purge_annotator::add_stmt_annotations): Factor out
7748 collation and printing code into...
7749 (state_purge_annotator::print_needed): ...this new function.
7750 * state-purge.h (state_purge_annotator::print_needed): New decl.
7751
7752 2021-07-21 David Malcolm <[email protected]>
7753
7754 * program-point.cc (function_point::print): Show src BB index at
7755 BEFORE_SUPERNODE.
7756
7757 2021-07-21 David Malcolm <[email protected]>
7758
7759 * svalue.cc (infix_p): New.
7760 (binop_svalue::dump_to_pp): Use it to print MIN_EXPR and MAX_EXPR
7761 in prefix form, rather than infix.
7762
7763 2021-07-19 David Malcolm <[email protected]>
7764
7765 PR analyzer/101503
7766 * constraint-manager.cc (constraint_manager::add_constraint): Use
7767 can_have_associated_state_p rather than testing for unknown.
7768 (constraint_manager::get_or_add_equiv_class): Likewise.
7769 * program-state.cc (sm_state_map::set_state): Likewise.
7770 (sm_state_map::impl_set_state): Add assertion.
7771 * region-model-manager.cc
7772 (region_model_manager::maybe_fold_unaryop): Handle poisoned
7773 values.
7774 (region_model_manager::maybe_fold_binop): Move handling of unknown
7775 values...
7776 (region_model_manager::get_or_create_binop): ...to here, and
7777 generalize to use can_have_associated_state_p.
7778 (region_model_manager::maybe_fold_sub_svalue): Use
7779 can_have_associated_state_p rather than testing for unknown.
7780 (region_model_manager::maybe_fold_repeated_svalue): Use unknown
7781 when the size or repeated value is "unknown"/"poisoned".
7782 * region-model.cc (region_model::purge_state_involving): Reject
7783 attempts to purge unknown/poisoned svalues, as these svalues
7784 should not have state associated with them.
7785 * svalue.cc (sub_svalue::sub_svalue): Assert that we're building
7786 on top of an svalue with can_have_associated_state_p.
7787 (repeated_svalue::repeated_svalue): Likewise.
7788 (bits_within_svalue::bits_within_svalue): Likewise.
7789 * svalue.h (svalue::can_have_associated_state_p): New.
7790 (unknown_svalue::can_have_associated_state_p): New.
7791 (poisoned_svalue::can_have_associated_state_p): New.
7792 (unaryop_svalue::unaryop_svalue): Assert that we're building on
7793 top of an svalue with can_have_associated_state_p.
7794 (binop_svalue::binop_svalue): Likewise.
7795 (widening_svalue::widening_svalue): Likewise.
7796
7797 2021-07-16 David Malcolm <[email protected]>
7798
7799 * analyzer.h (enum access_direction): New.
7800 * engine.cc (exploded_node::on_longjmp): Update for new param of
7801 get_store_value.
7802 * program-state.cc (program_state::prune_for_point): Likewise.
7803 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
7804 Replace call to check_for_writable_region with call to
7805 check_region_for_write.
7806 (region_model::impl_call_memset): Likewise.
7807 (region_model::impl_call_strcpy): Likewise.
7808 * region-model-reachability.cc (reachable_regions::add): Update
7809 for new param of get_store_value.
7810 * region-model.cc (region_model::get_rvalue_1): Likewise, also for
7811 get_rvalue_for_bits.
7812 (region_model::get_store_value): Add ctxt param and use it to call
7813 check_region_for_read.
7814 (region_model::get_rvalue_for_bits): Add ctxt param and use it to
7815 call get_store_value.
7816 (region_model::check_region_access): New.
7817 (region_model::check_region_for_write): New.
7818 (region_model::check_region_for_read): New.
7819 (region_model::set_value): Update comment. Replace call to
7820 check_for_writable_region with call to check_region_for_write.
7821 * region-model.h (region_model::get_rvalue_for_bits): Add ctxt
7822 param.
7823 (region_model::get_store_value): Add ctxt param.
7824 (region_model::check_region_access): New decl.
7825 (region_model::check_region_for_write): New decl.
7826 (region_model::check_region_for_read): New decl.
7827 * region.cc (region_model::copy_region): Update call to
7828 get_store_value.
7829 * svalue.cc (initial_svalue::implicitly_live_p): Likewise.
7830
7831 2021-07-16 David Malcolm <[email protected]>
7832
7833 * engine.cc (exploded_node::on_stmt_pre): Handle
7834 __analyzer_dump_state.
7835 * program-state.cc (extrinsic_state::get_sm_idx_by_name): New.
7836 (program_state::impl_call_analyzer_dump_state): New.
7837 * program-state.h (extrinsic_state::get_sm_idx_by_name): New decl.
7838 (program_state::impl_call_analyzer_dump_state): New decl.
7839 * region-model-impl-calls.cc
7840 (call_details::get_arg_string_literal): New.
7841 * region-model.h (call_details::get_arg_string_literal): New decl.
7842
7843 2021-07-16 David Malcolm <[email protected]>
7844
7845 * program-state.cc (program_state::detect_leaks): Simplify using
7846 svalue::maybe_get_region.
7847 * region-model-impl-calls.cc (region_model::impl_call_fgets): Likewise.
7848 (region_model::impl_call_fread): Likewise.
7849 (region_model::impl_call_free): Likewise.
7850 (region_model::impl_call_operator_delete): Likewise.
7851 * region-model.cc (selftest::test_stack_frames): Likewise.
7852 (selftest::test_state_merging): Likewise.
7853 * svalue.cc (svalue::maybe_get_region): New.
7854 * svalue.h (svalue::maybe_get_region): New decl.
7855
7856 2021-07-15 David Malcolm <[email protected]>
7857
7858 * svalue.h (is_a_helper <placeholder_svalue *>::test): Make
7859 param and template param const.
7860 (is_a_helper <widening_svalue *>::test): Likewise.
7861 (is_a_helper <compound_svalue *>::test): Likewise.
7862 (is_a_helper <conjured_svalue *>::test): Likewise.
7863
7864 2021-07-15 David Malcolm <[email protected]>
7865
7866 PR analyzer/95006
7867 PR analyzer/94713
7868 PR analyzer/94714
7869 * analyzer.cc (maybe_reconstruct_from_def_stmt): Split out
7870 GIMPLE_ASSIGN case into...
7871 (get_diagnostic_tree_for_gassign_1): New.
7872 (get_diagnostic_tree_for_gassign): New.
7873 * analyzer.h (get_diagnostic_tree_for_gassign): New decl.
7874 * analyzer.opt (Wanalyzer-write-to-string-literal): New.
7875 * constraint-manager.cc (class svalue_purger): New.
7876 (constraint_manager::purge_state_involving): New.
7877 * constraint-manager.h
7878 (constraint_manager::purge_state_involving): New.
7879 * diagnostic-manager.cc (saved_diagnostic::supercedes_p): New.
7880 (dedupe_winners::handle_interactions): New.
7881 (diagnostic_manager::emit_saved_diagnostics): Call it.
7882 * diagnostic-manager.h (saved_diagnostic::supercedes_p): New decl.
7883 * engine.cc (impl_region_model_context::warn): Convert return type
7884 to bool. Return false if the diagnostic isn't saved.
7885 (impl_region_model_context::purge_state_involving): New.
7886 (impl_sm_context::get_state): Use NULL ctxt when querying old
7887 rvalue.
7888 (impl_sm_context::set_next_state): Use new sval when querying old
7889 state.
7890 (class dump_path_diagnostic): Move to region-model.cc
7891 (exploded_node::on_stmt): Move to on_stmt_pre and on_stmt_post.
7892 Remove call to purge_state_involving.
7893 (exploded_node::on_stmt_pre): New, based on the above. Move most
7894 of it to region_model::on_stmt_pre.
7895 (exploded_node::on_stmt_post): Likewise, moving to
7896 region_model::on_stmt_post.
7897 (class stale_jmp_buf): Fix parent class to use curiously recurring
7898 template pattern.
7899 (feasibility_state::maybe_update_for_edge): Call on_call_pre and
7900 on_call_post on gcalls.
7901 * exploded-graph.h (impl_region_model_context::warn): Return bool.
7902 (impl_region_model_context::purge_state_involving): New decl.
7903 (exploded_node::on_stmt_pre): New decl.
7904 (exploded_node::on_stmt_post): New decl.
7905 * pending-diagnostic.h (pending_diagnostic::use_of_uninit_p): New.
7906 (pending_diagnostic::supercedes_p): New.
7907 * program-state.cc (sm_state_map::get_state): Inherit state for
7908 conjured_svalue as well as initial_svalue.
7909 (sm_state_map::purge_state_involving): Also support SK_CONJURED.
7910 * region-model-impl-calls.cc (call_details::get_uncertainty):
7911 Handle m_ctxt being NULL.
7912 (call_details::get_or_create_conjured_svalue): New.
7913 (region_model::impl_call_fgets): New.
7914 (region_model::impl_call_fread): New.
7915 * region-model-manager.cc
7916 (region_model_manager::get_or_create_initial_value): Return an
7917 uninitialized poisoned value for regions that can't have initial
7918 values.
7919 * region-model-reachability.cc
7920 (reachable_regions::mark_escaped_clusters): Handle ctxt being
7921 NULL.
7922 * region-model.cc (region_to_value_map::purge_state_involving): New.
7923 (poisoned_value_diagnostic::use_of_uninit_p): New.
7924 (poisoned_value_diagnostic::emit): Handle POISON_KIND_UNINIT.
7925 (poisoned_value_diagnostic::describe_final_event): Likewise.
7926 (region_model::check_for_poison): New.
7927 (region_model::on_assignment): Call it.
7928 (class dump_path_diagnostic): Move here from engine.cc.
7929 (region_model::on_stmt_pre): New, based on exploded_node::on_stmt.
7930 (region_model::on_call_pre): Move the setting of the LHS to a
7931 conjured svalue to before the checks for specific functions.
7932 Handle "fgets", "fgets_unlocked", and "fread".
7933 (region_model::purge_state_involving): New.
7934 (region_model::handle_unrecognized_call): Handle ctxt being NULL.
7935 (region_model::get_rvalue): Call check_for_poison.
7936 (selftest::test_stack_frames): Use NULL for context when getting
7937 uninitialized rvalue.
7938 (selftest::test_alloca): Likewise.
7939 * region-model.h (region_to_value_map::purge_state_involving): New
7940 decl.
7941 (call_details::get_or_create_conjured_svalue): New decl.
7942 (region_model::on_stmt_pre): New decl.
7943 (region_model::purge_state_involving): New decl.
7944 (region_model::impl_call_fgets): New decl.
7945 (region_model::impl_call_fread): New decl.
7946 (region_model::check_for_poison): New decl.
7947 (region_model_context::warn): Return bool.
7948 (region_model_context::purge_state_involving): New.
7949 (noop_region_model_context::warn): Return bool.
7950 (noop_region_model_context::purge_state_involving): New.
7951 (test_region_model_context:: warn): Return bool.
7952 * region.cc (region::get_memory_space): New.
7953 (region::can_have_initial_svalue_p): New.
7954 (region::involves_p): New.
7955 * region.h (enum memory_space): New.
7956 (region::get_memory_space): New decl.
7957 (region::can_have_initial_svalue_p): New decl.
7958 (region::involves_p): New decl.
7959 * sm-malloc.cc (use_after_free::supercedes_p): New.
7960 * store.cc (binding_cluster::purge_state_involving): New.
7961 (store::purge_state_involving): New.
7962 * store.h (class symbolic_binding): New forward decl.
7963 (binding_key::dyn_cast_symbolic_binding): New.
7964 (symbolic_binding::dyn_cast_symbolic_binding): New.
7965 (binding_cluster::purge_state_involving): New.
7966 (store::purge_state_involving): New.
7967 * svalue.cc (svalue::can_merge_p): Reject attempts to merge
7968 poisoned svalues with other svalues, so that we identify
7969 paths in which a variable is conditionally uninitialized.
7970 (involvement_visitor::visit_conjured_svalue): New.
7971 (svalue::involves_p): Also handle SK_CONJURED.
7972 (poison_kind_to_str): Handle POISON_KIND_UNINIT.
7973 (poisoned_svalue::maybe_fold_bits_within): New.
7974 * svalue.h (enum poison_kind): Add POISON_KIND_UNINIT.
7975 (poisoned_svalue::maybe_fold_bits_within): New decl.
7976
7977 2021-07-15 David Malcolm <[email protected]>
7978
7979 * analyzer.opt (fdump-analyzer-exploded-paths): New.
7980 * diagnostic-manager.cc
7981 (diagnostic_manager::emit_saved_diagnostic): Implement it.
7982 * engine.cc (exploded_path::dump_to_pp): Add ext_state param and
7983 use it to dump states if non-NULL.
7984 (exploded_path::dump): Likewise.
7985 (exploded_path::dump_to_file): New.
7986 * exploded-graph.h (exploded_path::dump_to_pp): Add ext_state
7987 param.
7988 (exploded_path::dump): Likewise.
7989 (exploded_path::dump): Likewise.
7990 (exploded_path::dump_to_file): New.
7991
7992 2021-07-15 David Malcolm <[email protected]>
7993
7994 * analyzer.cc (fixup_tree_for_diagnostic_1): Use DECL_DEBUG_EXPR
7995 if it's available.
7996 * engine.cc (readability): Likewise.
7997
7998 2021-07-15 David Malcolm <[email protected]>
7999
8000 * state-purge.cc (self_referential_phi_p): New.
8001 (state_purge_per_ssa_name::process_point): Don't purge an SSA name
8002 at its def-stmt if the def-stmt is self-referential.
8003
8004 2021-07-07 David Malcolm <[email protected]>
8005
8006 * diagnostic-manager.cc (null_assignment_sm_context::get_state):
8007 New overload.
8008 (null_assignment_sm_context::set_next_state): New overload.
8009 (null_assignment_sm_context::get_diagnostic_tree): New.
8010 * engine.cc (impl_sm_context::get_state): New overload.
8011 (impl_sm_context::set_next_state): New overload.
8012 (impl_sm_context::get_diagnostic_tree): New overload.
8013 (impl_region_model_context::on_condition): Convert params from
8014 tree to const svalue *.
8015 * exploded-graph.h (impl_region_model_context::on_condition):
8016 Likewise.
8017 * region-model.cc (region_model::on_call_pre): Move handling of
8018 internal calls to before checking for get_fndecl_for_call.
8019 (region_model::add_constraints_from_binop): New.
8020 (region_model::add_constraint): Split out into a new overload
8021 working on const svalue * rather than tree. Call
8022 add_constraints_from_binop. Drop call to
8023 add_any_constraints_from_ssa_def_stmt.
8024 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
8025 (region_model::add_any_constraints_from_gassign): Delete.
8026 (region_model::add_any_constraints_from_gcall): Delete.
8027 * region-model.h
8028 (region_model::add_any_constraints_from_ssa_def_stmt): Delete.
8029 (region_model::add_any_constraints_from_gassign): Delete.
8030 (region_model::add_any_constraints_from_gcall): Delete.
8031 (region_model::add_constraint): Add overload decl.
8032 (region_model::add_constraints_from_binop): New decl.
8033 (region_model_context::on_condition): Convert params from tree to
8034 const svalue *.
8035 (noop_region_model_context::on_condition): Likewise.
8036 * sm-file.cc (fileptr_state_machine::condition): Likewise.
8037 * sm-malloc.cc (malloc_state_machine::on_condition): Likewise.
8038 * sm-pattern-test.cc: Include tristate.h, selftest.h,
8039 analyzer/call-string.h, analyzer/program-point.h,
8040 analyzer/store.h, and analyzer/region-model.h.
8041 (pattern_test_state_machine::on_condition): Convert params from tree to
8042 const svalue *.
8043 * sm-sensitive.cc (sensitive_state_machine::on_condition): Delete.
8044 * sm-signal.cc (signal_state_machine::on_condition): Delete.
8045 * sm-taint.cc (taint_state_machine::on_condition): Convert params
8046 from tree to const svalue *.
8047 * sm.cc: Include tristate.h, selftest.h, analyzer/call-string.h,
8048 analyzer/program-point.h, analyzer/store.h, and
8049 analyzer/region-model.h.
8050 (any_pointer_p): Add overload taking const svalue *sval.
8051 * sm.h (any_pointer_p): Add overload taking const svalue *sval.
8052 (state_machine::on_condition): Convert params from tree to
8053 const svalue *. Provide no-op default implementation.
8054 (sm_context::get_state): Add overload taking const svalue *sval.
8055 (sm_context::set_next_state): Likewise.
8056 (sm_context::on_transition): Likewise.
8057 (sm_context::get_diagnostic_tree): Likewise.
8058 * svalue.cc (svalue::all_zeroes_p): New.
8059 (constant_svalue::all_zeroes_p): New.
8060 (repeated_svalue::all_zeroes_p): Convert to vfunc.
8061 * svalue.h (svalue::all_zeroes_p): New decl.
8062 (constant_svalue::all_zeroes_p): New decl.
8063 (repeated_svalue::all_zeroes_p): Convert decl to vfunc.
8064
8065 2021-06-30 David Malcolm <[email protected]>
8066
8067 PR analyzer/95006
8068 * analyzer.h (class repeated_svalue): New forward decl.
8069 (class bits_within_svalue): New forward decl.
8070 (class sized_region): New forward decl.
8071 (get_field_at_bit_offset): New forward decl.
8072 * engine.cc (exploded_graph::get_or_create_node): Validate the
8073 merged state.
8074 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
8075 Validate the states at each stage.
8076 * program-state.cc (program_state::validate): Validate
8077 m_region_model.
8078 * region-model-impl-calls.cc (region_model::impl_call_memset):
8079 Replace special-case logic for handling constant sizes with
8080 a call to fill_region of a sized_region with the given fill value.
8081 * region-model-manager.cc (maybe_undo_optimize_bit_field_compare):
8082 Drop DK_direct.
8083 (region_model_manager::maybe_fold_sub_svalue): Fold element-based
8084 subregions of an initial value into initial values of an element.
8085 Fold subvalues of repeated svalues.
8086 (region_model_manager::maybe_fold_repeated_svalue): New.
8087 (region_model_manager::get_or_create_repeated_svalue): New.
8088 (get_bit_range_for_field): New.
8089 (get_byte_range_for_field): New.
8090 (get_field_at_byte_range): New.
8091 (region_model_manager::maybe_fold_bits_within_svalue): New.
8092 (region_model_manager::get_or_create_bits_within): New.
8093 (region_model_manager::get_sized_region): New.
8094 (region_model_manager::log_stats): Update for addition of
8095 m_repeated_values_map, m_bits_within_values_map, and
8096 m_sized_regions.
8097 * region-model.cc (region_model::validate): New.
8098 (region_model::on_assignment): Drop enum binding_kind.
8099 (region_model::get_initial_value_for_global): Likewise.
8100 (region_model::get_rvalue_for_bits): Replace body with call to
8101 get_or_create_bits_within.
8102 (region_model::get_capacity): Handle RK_SIZED.
8103 (region_model::set_value): Drop enum binding_kind.
8104 (region_model::fill_region): New.
8105 (region_model::get_representative_path_var_1): Handle RK_SIZED.
8106 * region-model.h (visitor::visit_repeated_svalue): New.
8107 (visitor::visit_bits_within_svalue): New.
8108 (region_model_manager::get_or_create_repeated_svalue): New decl.
8109 (region_model_manager::get_or_create_bits_within): New decl.
8110 (region_model_manager::get_sized_region): New decl.
8111 (region_model_manager::maybe_fold_repeated_svalue): New decl.
8112 (region_model_manager::maybe_fold_bits_within_svalue): New decl.
8113 (region_model_manager::repeated_values_map_t): New typedef.
8114 (region_model_manager::m_repeated_values_map): New field.
8115 (region_model_manager::bits_within_values_map_t): New typedef.
8116 (region_model_manager::m_bits_within_values_map): New field.
8117 (region_model_manager::m_sized_regions): New field.
8118 (region_model::fill_region): New decl.
8119 * region.cc (region::get_base_region): Handle RK_SIZED.
8120 (region::base_region_p): Likewise.
8121 (region::get_byte_size_sval): New.
8122 (get_field_at_bit_offset): Make non-static.
8123 (region::calc_offset): Move implementation of cases to
8124 get_relative_concrete_offset vfunc implementations. Handle
8125 RK_SIZED.
8126 (region::get_relative_concrete_offset): New.
8127 (decl_region::get_svalue_for_initializer): Drop enum binding_kind.
8128 (field_region::get_relative_concrete_offset): New, from
8129 region::calc_offset.
8130 (element_region::get_relative_concrete_offset): Likewise.
8131 (offset_region::get_relative_concrete_offset): Likewise.
8132 (sized_region::accept): New.
8133 (sized_region::dump_to_pp): New.
8134 (sized_region::get_byte_size): New.
8135 (sized_region::get_bit_size): New.
8136 * region.h (enum region_kind): Add RK_SIZED.
8137 (region::dyn_cast_sized_region): New.
8138 (region::get_byte_size): Make virtual.
8139 (region::get_bit_size): Likewise.
8140 (region::get_byte_size_sval): New decl.
8141 (region::get_relative_concrete_offset): New decl.
8142 (field_region::get_relative_concrete_offset): New decl.
8143 (element_region::get_relative_concrete_offset): Likewise.
8144 (offset_region::get_relative_concrete_offset): Likewise.
8145 (class sized_region): New.
8146 * store.cc (binding_kind_to_string): Delete.
8147 (binding_key::make): Drop enum binding_kind.
8148 (binding_key::dump_to_pp): Delete.
8149 (binding_key::cmp_ptrs): Drop enum binding_kind.
8150 (bit_range::contains_p): New.
8151 (byte_range::dump): New.
8152 (byte_range::contains_p): New.
8153 (byte_range::cmp): New.
8154 (concrete_binding::dump_to_pp): Drop enum binding_kind.
8155 (concrete_binding::cmp_ptr_ptr): Likewise.
8156 (symbolic_binding::dump_to_pp): Likewise.
8157 (symbolic_binding::cmp_ptr_ptr): Likewise.
8158 (binding_map::apply_ctor_val_to_range): Likewise.
8159 (binding_map::apply_ctor_pair_to_child_region): Likewise.
8160 (binding_map::get_overlapping_bindings): New.
8161 (binding_map::remove_overlapping_bindings): New.
8162 (binding_cluster::validate): New.
8163 (binding_cluster::bind): Drop enum binding_kind.
8164 (binding_cluster::bind_compound_sval): Likewise.
8165 (binding_cluster::purge_region): Likewise.
8166 (binding_cluster::zero_fill_region): Reimplement in terms of...
8167 (binding_cluster::fill_region): New.
8168 (binding_cluster::mark_region_as_unknown): Drop enum binding_kind.
8169 (binding_cluster::get_binding): Likewise.
8170 (binding_cluster::get_binding_recursive): Likewise.
8171 (binding_cluster::get_any_binding): Likewise.
8172 (binding_cluster::maybe_get_compound_binding): Reimplement.
8173 (binding_cluster::get_overlapping_bindings): Delete.
8174 (binding_cluster::remove_overlapping_bindings): Reimplement in
8175 terms of binding_map::remove_overlapping_bindings.
8176 (binding_cluster::can_merge_p): Update for removal of
8177 enum binding_kind.
8178 (binding_cluster::on_unknown_fncall): Drop enum binding_kind.
8179 (binding_cluster::maybe_get_simple_value): Likewise.
8180 (store_manager::get_concrete_binding): Likewise.
8181 (store_manager::get_symbolic_binding): Likewise.
8182 (store::validate): New.
8183 (store::set_value): Drop enum binding_kind.
8184 (store::zero_fill_region): Reimplement in terms of...
8185 (store::fill_region): New.
8186 (selftest::test_binding_key_overlap): Drop enum binding_kind.
8187 * store.h (enum binding_kind): Delete.
8188 (binding_kind_to_string): Delete decl.
8189 (binding_key::make): Drop enum binding_kind.
8190 (binding_key::dump_to_pp): Make pure virtual.
8191 (binding_key::get_kind): Delete.
8192 (binding_key::mark_deleted): Delete.
8193 (binding_key::mark_empty): Delete.
8194 (binding_key::is_deleted): Delete.
8195 (binding_key::is_empty): Delete.
8196 (binding_key::binding_key): Delete.
8197 (binding_key::impl_hash): Delete.
8198 (binding_key::impl_eq): Delete.
8199 (binding_key::m_kind): Delete.
8200 (bit_range::get_last_bit_offset): New.
8201 (bit_range::contains_p): New.
8202 (byte_range::contains_p): New.
8203 (byte_range::operator==): New.
8204 (byte_range::get_start_byte_offset): New.
8205 (byte_range::get_next_byte_offset): New.
8206 (byte_range::get_last_byte_offset): New.
8207 (byte_range::as_bit_range): New.
8208 (byte_range::cmp): New.
8209 (concrete_binding::concrete_binding): Drop enum binding_kind.
8210 (concrete_binding::hash): Likewise.
8211 (concrete_binding::operator==): Likewise.
8212 (concrete_binding::mark_deleted): New.
8213 (concrete_binding::mark_empty): New.
8214 (concrete_binding::is_deleted): New.
8215 (concrete_binding::is_empty): New.
8216 (default_hash_traits<ana::concrete_binding>::empty_zero_p): Make false.
8217 (symbolic_binding::symbolic_binding): Drop enum binding_kind.
8218 (symbolic_binding::hash): Likewise.
8219 (symbolic_binding::operator==): Likewise.
8220 (symbolic_binding::mark_deleted): New.
8221 (symbolic_binding::mark_empty): New.
8222 (symbolic_binding::is_deleted): New.
8223 (symbolic_binding::is_empty): New.
8224 (binding_map::remove_overlapping_bindings): New decl.
8225 (binding_map::get_overlapping_bindings): New decl.
8226 (binding_cluster::validate): New decl.
8227 (binding_cluster::bind): Drop enum binding_kind.
8228 (binding_cluster::fill_region): New decl.
8229 (binding_cluster::get_binding): Drop enum binding_kind.
8230 (binding_cluster::get_binding_recursive): Likewise.
8231 (binding_cluster::get_overlapping_bindings): Delete.
8232 (store::validate): New decl.
8233 (store::set_value): Drop enum binding_kind.
8234 (store::fill_region): New decl.
8235 (store_manager::get_concrete_binding): Drop enum binding_kind.
8236 (store_manager::get_symbolic_binding): Likewise.
8237 * svalue.cc (svalue::cmp_ptr): Handle SK_REPEATED and
8238 SK_BITS_WITHIN.
8239 (svalue::extract_bit_range): New.
8240 (svalue::maybe_fold_bits_within): New.
8241 (constant_svalue::maybe_fold_bits_within): New.
8242 (unknown_svalue::maybe_fold_bits_within): New.
8243 (unaryop_svalue::maybe_fold_bits_within): New.
8244 (repeated_svalue::repeated_svalue): New.
8245 (repeated_svalue::dump_to_pp): New.
8246 (repeated_svalue::accept): New.
8247 (repeated_svalue::all_zeroes_p): New.
8248 (repeated_svalue::maybe_fold_bits_within): New.
8249 (bits_within_svalue::bits_within_svalue): New.
8250 (bits_within_svalue::dump_to_pp): New.
8251 (bits_within_svalue::maybe_fold_bits_within): New.
8252 (bits_within_svalue::accept): New.
8253 (bits_within_svalue::implicitly_live_p): New.
8254 (compound_svalue::maybe_fold_bits_within): New.
8255 * svalue.h (enum svalue_kind): Add SK_REPEATED and SK_BITS_WITHIN.
8256 (svalue::dyn_cast_repeated_svalue): New.
8257 (svalue::dyn_cast_bits_within_svalue): New.
8258 (svalue::extract_bit_range): New decl.
8259 (svalue::maybe_fold_bits_within): New vfunc decl.
8260 (region_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8261 (region_svalue::key_t::is_empty): Likewise.
8262 (default_hash_traits<region_svalue::key_t>::empty_zero_p): Make false.
8263 (constant_svalue::maybe_fold_bits_within): New.
8264 (unknown_svalue::maybe_fold_bits_within): New.
8265 (poisoned_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8266 (poisoned_svalue::key_t::is_empty): Likewise.
8267 (default_hash_traits<poisoned_svalue::key_t>::empty_zero_p): Make
8268 false.
8269 (setjmp_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8270 (setjmp_svalue::key_t::is_empty): Likewise.
8271 (default_hash_traits<setjmp_svalue::key_t>::empty_zero_p): Make
8272 false.
8273 (unaryop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8274 (unaryop_svalue::key_t::is_empty): Likewise.
8275 (unaryop_svalue::maybe_fold_bits_within): New.
8276 (default_hash_traits<unaryop_svalue::key_t>::empty_zero_p): Make
8277 false.
8278 (binop_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8279 (binop_svalue::key_t::is_empty): Likewise.
8280 (default_hash_traits<binop_svalue::key_t>::empty_zero_p): Make
8281 false.
8282 (sub_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8283 (sub_svalue::key_t::is_empty): Likewise.
8284 (default_hash_traits<sub_svalue::key_t>::empty_zero_p): Make
8285 false.
8286 (class repeated_svalue): New.
8287 (is_a_helper <const repeated_svalue *>::test): New.
8288 (struct default_hash_traits<repeated_svalue::key_t>): New.
8289 (class bits_within_svalue): New.
8290 (is_a_helper <const bits_within_svalue *>::test): New.
8291 (struct default_hash_traits<bits_within_svalue::key_t>): New.
8292 (widening_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8293 (widening_svalue::key_t::is_empty): Likewise.
8294 (default_hash_traits<widening_svalue::key_t>::empty_zero_p): Make
8295 false.
8296 (compound_svalue::key_t::mark_empty): Use 2 rather than NULL_TREE.
8297 (compound_svalue::key_t::is_empty): Likewise.
8298 (compound_svalue::maybe_fold_bits_within): New.
8299 (default_hash_traits<compound_svalue::key_t>::empty_zero_p): Make
8300 false.
8301
8302 2021-06-28 David Malcolm <[email protected]>
8303
8304 * analyzer.h (byte_offset_t): New typedef.
8305 * store.cc (bit_range::dump_to_pp): Dump as a byte range if
8306 possible.
8307 (bit_range::as_byte_range): New.
8308 (byte_range::dump_to_pp): New.
8309 * store.h (class byte_range): New forward decl.
8310 (struct bit_range): Add comment.
8311 (bit_range::as_byte_range): New decl.
8312 (struct byte_range): New.
8313
8314 2021-06-22 David Malcolm <[email protected]>
8315
8316 PR analyzer/101143
8317 * region-model.cc (compat_types_p): New function.
8318 (region_model::create_region_for_heap_alloc): Convert assertion to
8319 an error check.
8320 (region_model::create_region_for_alloca): Likewise.
8321
8322 2021-06-18 David Malcolm <[email protected]>
8323
8324 * store.cc (binding_cluster::get_any_binding): Make symbolic reads
8325 from a cluster with concrete bindings return unknown.
8326
8327 2021-06-18 David Malcolm <[email protected]>
8328
8329 * region-model-manager.cc
8330 (region_model_manager::get_or_create_int_cst): New.
8331 (region_model_manager::maybe_undo_optimize_bit_field_compare): Use
8332 it to simplify away a local tree.
8333 * region-model.cc (region_model::on_setjmp): Likewise.
8334 (region_model::on_longjmp): Likewise.
8335 * region-model.h (region_model_manager::get_or_create_int_cst):
8336 New decl.
8337 * store.cc (binding_cluster::zero_fill_region): Use it to simplify
8338 away a local tree.
8339
8340 2021-06-18 David Malcolm <[email protected]>
8341
8342 * checker-path.cc (class custom_event): Make abstract to allow for
8343 custom vfuncs, splitting existing implementation into...
8344 (class precanned_custom_event): New subclass.
8345 (custom_event::get_desc): Move to...
8346 (precanned_custom_event::get_desc): ...subclass.
8347 * checker-path.h (class custom_event): Make abstract to allow for
8348 custom vfuncs, splitting existing implementation into...
8349 (class precanned_custom_event): New subclass.
8350 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
8351 Use precanned_custom_event.
8352 * engine.cc
8353 (stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise.
8354 * sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path):
8355 Likewise.
8356
8357 2021-06-15 David Malcolm <[email protected]>
8358
8359 PR analyzer/99212
8360 PR analyzer/101082
8361 * engine.cc: Include "target.h".
8362 (impl_run_checkers): Log BITS_BIG_ENDIAN, BYTES_BIG_ENDIAN, and
8363 WORDS_BIG_ENDIAN.
8364 * region-model-manager.cc
8365 (region_model_manager::maybe_fold_binop): Move support for masking
8366 via ARG0 & CST into...
8367 (region_model_manager::maybe_undo_optimize_bit_field_compare):
8368 ...this new function. Flatten by converting from nested
8369 conditionals to a series of early return statements to reject
8370 failures. Reject if type is not unsigned_char_type_node.
8371 Handle BYTES_BIG_ENDIAN when determining which bits are bound
8372 in the binding_map.
8373 * region-model.h
8374 (region_model_manager::maybe_undo_optimize_bit_field_compare):
8375 New decl.
8376 * store.cc (bit_range::dump): New function.
8377 * store.h (bit_range::dump): New decl.
8378
8379 2021-06-15 David Malcolm <[email protected]>
8380
8381 * engine.cc (exploded_node::on_stmt): Handle __analyzer_dump_capacity.
8382 (exploded_node::on_stmt): Drop m_sm_changes from on_stmt_flags.
8383 (state_change_requires_new_enode_p): New function...
8384 (exploded_graph::process_node): Call it, rather than querying
8385 flags.m_sm_changes, so that dynamic-extent differences can also
8386 trigger the splitting of nodes.
8387 * exploded-graph.h (struct on_stmt_flags): Drop field m_sm_changes.
8388 * program-state.cc (program_state::detect_leaks): Purge dead
8389 heap-allocated regions from dynamic extents.
8390 (selftest::test_program_state_1): Fix type of "size_in_bytes".
8391 (selftest::test_program_state_merging): Likewise.
8392 * region-model-impl-calls.cc
8393 (region_model::impl_call_analyzer_dump_capacity): New.
8394 (region_model::impl_call_free): Remove dynamic extents from the
8395 freed region.
8396 * region-model-reachability.h
8397 (reachable_regions::begin_mutable_base_regs): New.
8398 (reachable_regions::end_mutable_base_regs): New.
8399 * region-model.cc: Include "tree-object-size.h".
8400 (region_model::region_model): Support new field m_dynamic_extents.
8401 (region_model::operator=): Likewise.
8402 (region_model::operator==): Likewise.
8403 (region_model::dump_to_pp): Dump sizes of dynamic regions.
8404 (region_model::handle_unrecognized_call): Purge dynamic extents
8405 from any regions that have escaped mutably:.
8406 (region_model::get_capacity): New function.
8407 (region_model::add_constraint): Unset dynamic extents when a
8408 heap-allocated region's address is NULL.
8409 (region_model::unbind_region_and_descendents): Purge dynamic
8410 extents of unbound regions.
8411 (region_model::can_merge_with_p): Call
8412 m_dynamic_extents.can_merge_with_p.
8413 (region_model::create_region_for_heap_alloc): Assert that
8414 size_in_bytes's type is compatible with size_type_node. Update
8415 for renaming of record_dynamic_extents to set_dynamic_extents.
8416 (region_model::create_region_for_alloca): Likewise.
8417 (region_model::record_dynamic_extents): Rename to...
8418 (region_model::set_dynamic_extents): ...this. Assert that
8419 size_in_bytes's type is compatible with size_type_node. Add it
8420 to the m_dynamic_extents map.
8421 (region_model::get_dynamic_extents): New.
8422 (region_model::unset_dynamic_extents): New.
8423 (selftest::test_state_merging): Fix type of "size".
8424 (selftest::test_malloc_constraints): Likewise.
8425 (selftest::test_malloc): Verify dynamic extents.
8426 (selftest::test_alloca): Likewise.
8427 * region-model.h (region_to_value_map::is_empty): New.
8428 (region_model::dynamic_extents_t): New typedef.
8429 (region_model::impl_call_analyzer_dump_capacity): New decl.
8430 (region_model::get_dynamic_extents): New function.
8431 (region_model::get_dynamic_extents): New decl.
8432 (region_model::set_dynamic_extents): New decl.
8433 (region_model::unset_dynamic_extents): New decl.
8434 (region_model::get_capacity): New decl.
8435 (region_model::record_dynamic_extents): Rename to set_dynamic_extents.
8436 (region_model::m_dynamic_extents): New field.
8437
8438 2021-06-15 David Malcolm <[email protected]>
8439
8440 * region-model.cc (region_to_value_map::operator=): New.
8441 (region_to_value_map::operator==): New.
8442 (region_to_value_map::dump_to_pp): New.
8443 (region_to_value_map::dump): New.
8444 (region_to_value_map::can_merge_with_p): New.
8445 * region-model.h (class region_to_value_map): New class.
8446
8447 2021-06-13 Trevor Saunders <[email protected]>
8448
8449 * call-string.cc (call_string::call_string): Use range based for
8450 to iterate over vec<>.
8451 (call_string::to_json): Likewise.
8452 (call_string::hash): Likewise.
8453 (call_string::calc_recursion_depth): Likewise.
8454 * checker-path.cc (checker_path::fixup_locations): Likewise.
8455 * constraint-manager.cc (equiv_class::equiv_class): Likewise.
8456 (equiv_class::to_json): Likewise.
8457 (equiv_class::hash): Likewise.
8458 (constraint_manager::to_json): Likewise.
8459 * engine.cc (impl_region_model_context::on_svalue_leak):
8460 Likewise.
8461 (on_liveness_change): Likewise.
8462 (impl_region_model_context::on_unknown_change): Likewise.
8463 * program-state.cc (sm_state_map::set_state): Likewise.
8464 * region-model.cc (test_canonicalization_4): Likewise.
8465
8466 2021-06-11 David Malcolm <[email protected]>
8467
8468 * engine.cc (worklist::key_t::cmp): Move sort by call_string to
8469 before SCC.
8470
8471 2021-06-09 David Malcolm <[email protected]>
8472
8473 * region-model.cc (region_model::get_lvalue_1): Make const.
8474 (region_model::get_lvalue): Likewise.
8475 (region_model::get_rvalue_1): Likewise.
8476 (region_model::get_rvalue): Likewise.
8477 (region_model::deref_rvalue): Likewise.
8478 (region_model::get_rvalue_for_bits): Likewise.
8479 * region-model.h (region_model::get_lvalue): Likewise.
8480 (region_model::get_rvalue): Likewise.
8481 (region_model::deref_rvalue): Likewise.
8482 (region_model::get_rvalue_for_bits): Likewise.
8483 (region_model::get_lvalue_1): Likewise.
8484 (region_model::get_rvalue_1): Likewise.
8485
8486 2021-06-08 David Malcolm <[email protected]>
8487
8488 PR analyzer/99212
8489 * region-model-manager.cc
8490 (region_model_manager::maybe_fold_binop): Add support for folding
8491 BIT_AND_EXPR of compound_svalue and a mask constant.
8492 * region-model.cc (region_model::get_rvalue_1): Implement
8493 BIT_FIELD_REF in terms of...
8494 (region_model::get_rvalue_for_bits): New function.
8495 * region-model.h (region_model::get_rvalue_for_bits): New decl.
8496 * store.cc (bit_range::from_mask): New function.
8497 (selftest::test_bit_range_intersects_p): New selftest.
8498 (selftest::assert_bit_range_from_mask_eq): New.
8499 (ASSERT_BIT_RANGE_FROM_MASK_EQ): New macro.
8500 (selftest::assert_no_bit_range_from_mask_eq): New.
8501 (ASSERT_NO_BIT_RANGE_FROM_MASK): New macro.
8502 (selftest::test_bit_range_from_mask): New selftest.
8503 (selftest::analyzer_store_cc_tests): Call the new selftests.
8504 * store.h (bit_range::intersects_p): New.
8505 (bit_range::from_mask): New decl.
8506 (concrete_binding::get_bit_range): New accessor.
8507 (store_manager::get_concrete_binding): New overload taking
8508 const bit_range &.
8509
8510 2021-06-08 David Malcolm <[email protected]>
8511
8512 * analyzer.h (int_size_in_bits): New decl.
8513 * region.cc (int_size_in_bits): New function.
8514 (region::get_bit_size): Reimplement in terms of the above.
8515
8516 2021-06-08 David Malcolm <[email protected]>
8517
8518 * store.cc (concrete_binding::dump_to_pp): Move bulk of
8519 implementation to...
8520 (bit_range::dump_to_pp): ...this new function.
8521 (bit_range::cmp): New.
8522 (concrete_binding::overlaps_p): Update for use of bit_range.
8523 (concrete_binding::cmp_ptr_ptr): Likewise.
8524 * store.h (struct bit_range): New.
8525 (class concrete_binding): Replace fields m_start_bit_offset and
8526 m_size_in_bits with new field m_bit_range.
8527
8528 2021-06-08 David Malcolm <[email protected]>
8529
8530 * svalue.h (conjured_svalue::iterator_t): Delete.
8531
8532 2021-06-03 David Malcolm <[email protected]>
8533
8534 * store.h (store::get_direct_binding): Remove unused decl.
8535 (store::get_default_binding): Likewise.
8536
8537 2021-06-03 David Malcolm <[email protected]>
8538
8539 * svalue.cc (poisoned_svalue::dump_to_pp): Dump type.
8540 (compound_svalue::dump_to_pp): Dump any type.
8541
8542 2021-05-18 David Malcolm <[email protected]>
8543
8544 PR analyzer/100615
8545 * sm-malloc.cc: Include "analyzer/function-set.h".
8546 (malloc_state_machine::on_stmt): Call unaffected_by_call_p and
8547 bail on the functions it recognizes.
8548 (malloc_state_machine::unaffected_by_call_p): New.
8549
8550 2021-05-10 Martin Liska <[email protected]>
8551
8552 * sm-file.cc (is_file_using_fn_p): Use startswith
8553 function instead of strncmp.
8554
8555 2021-05-10 Martin Liska <[email protected]>
8556
8557 * program-state.cc (program_state::operator=): Remove
8558 __cplusplus >= 201103.
8559 (program_state::program_state): Likewise.
8560 * program-state.h: Likewise.
8561 * region-model.h (class region_model): Remove dead code.
8562
8563 2021-04-24 David Malcolm <[email protected]>
8564
8565 PR analyzer/100244
8566 * sm-malloc.cc (free_of_non_heap::describe_state_change):
8567 Bulletproof against change.m_expr being NULL.
8568
8569 2021-04-13 David Malcolm <[email protected]>
8570
8571 PR analyzer/98599
8572 * supergraph.cc (saved_uids::make_uid_unique): New.
8573 (saved_uids::restore_uids): New.
8574 (supergraph::supergraph): Replace assignments to stmt->uid with
8575 calls to m_stmt_uids.make_uid_unique.
8576 (supergraph::~supergraph): New.
8577 * supergraph.h (class saved_uids): New.
8578 (supergraph::~supergraph): New decl.
8579 (supergraph::m_stmt_uids): New field.
8580
8581 2021-04-10 David Malcolm <[email protected]>
8582
8583 PR analyzer/100011
8584 * region-model.cc (region_model::on_assignment): Avoid NULL
8585 dereference if ctxt is NULL when assigning from a STRING_CST.
8586
8587 2021-04-08 David Malcolm <[email protected]>
8588
8589 PR analyzer/99042
8590 PR analyzer/99774
8591 * engine.cc
8592 (impl_region_model_context::impl_region_model_context): Add
8593 uncertainty param and use it to initialize m_uncertainty.
8594 (impl_region_model_context::get_uncertainty): New.
8595 (impl_sm_context::get_fndecl_for_call): Add NULL for new
8596 uncertainty param when constructing impl_region_model_context.
8597 (impl_sm_context::get_state): Likewise.
8598 (impl_sm_context::set_next_state): Likewise.
8599 (impl_sm_context::warn): Likewise.
8600 (exploded_node::on_stmt): Add uncertainty param
8601 and use it when constructing impl_region_model_context.
8602 (exploded_node::on_edge): Add uncertainty param and pass
8603 to on_edge call.
8604 (exploded_node::detect_leaks): Create uncertainty_t and pass to
8605 impl_region_model_context.
8606 (exploded_graph::get_or_create_node): Create uncertainty_t and
8607 pass to prune_for_point.
8608 (maybe_process_run_of_before_supernode_enodes): Create
8609 uncertainty_t and pass to impl_region_model_context.
8610 (exploded_graph::process_node): Create uncertainty_t instances and
8611 pass around as needed.
8612 * exploded-graph.h
8613 (impl_region_model_context::impl_region_model_context): Add
8614 uncertainty param.
8615 (impl_region_model_context::get_uncertainty): New decl.
8616 (impl_region_model_context::m_uncertainty): New field.
8617 (exploded_node::on_stmt): Add uncertainty param.
8618 (exploded_node::on_edge): Likewise.
8619 * program-state.cc (sm_state_map::on_liveness_change): Get
8620 uncertainty from context and use it to unset sm-state from
8621 svalues as appropriate.
8622 (program_state::on_edge): Add uncertainty param and use it when
8623 constructing impl_region_model_context. Fix indentation.
8624 (program_state::prune_for_point): Add uncertainty param and use it
8625 when constructing impl_region_model_context.
8626 (program_state::detect_leaks): Get any uncertainty from ctxt and
8627 use it to get maybe-live svalues for dest_state, rather than
8628 definitely-live ones; use this when determining which svalues
8629 have leaked.
8630 (selftest::test_program_state_merging): Create uncertainty_t and
8631 pass to impl_region_model_context.
8632 * program-state.h (program_state::on_edge): Add uncertainty param.
8633 (program_state::prune_for_point): Likewise.
8634 * region-model-impl-calls.cc (call_details::get_uncertainty): New.
8635 (region_model::impl_call_memcpy): Pass uncertainty to
8636 mark_region_as_unknown call.
8637 (region_model::impl_call_memset): Likewise.
8638 (region_model::impl_call_strcpy): Likewise.
8639 * region-model-reachability.cc (reachable_regions::handle_sval):
8640 Also add sval to m_mutable_svals.
8641 * region-model.cc (region_model::on_assignment): Pass any
8642 uncertainty from ctxt to the store::set_value call.
8643 (region_model::handle_unrecognized_call): Get any uncertainty from
8644 ctxt and use it to record mutable svalues at the unknown call.
8645 (region_model::get_reachable_svalues): Add uncertainty param and
8646 use it to mark any maybe-bound svalues as being reachable.
8647 (region_model::set_value): Pass any uncertainty from ctxt to the
8648 store::set_value call.
8649 (region_model::mark_region_as_unknown): Add uncertainty param and
8650 pass it on to the store::mark_region_as_unknown call.
8651 (region_model::update_for_call_summary): Add uncertainty param and
8652 pass it on to the region_model::mark_region_as_unknown call.
8653 * region-model.h (call_details::get_uncertainty): New decl.
8654 (region_model::get_reachable_svalues): Add uncertainty param.
8655 (region_model::mark_region_as_unknown): Add uncertainty param.
8656 (region_model_context::get_uncertainty): New vfunc.
8657 (noop_region_model_context::get_uncertainty): New vfunc
8658 implementation.
8659 * store.cc (dump_svalue_set): New.
8660 (uncertainty_t::dump_to_pp): New.
8661 (uncertainty_t::dump): New.
8662 (binding_cluster::clobber_region): Pass NULL for uncertainty to
8663 remove_overlapping_bindings.
8664 (binding_cluster::mark_region_as_unknown): Add uncertainty param
8665 and pass it to remove_overlapping_bindings.
8666 (binding_cluster::remove_overlapping_bindings): Add uncertainty param.
8667 Use it to record any svalues that were in clobbered bindings.
8668 (store::set_value): Add uncertainty param. Pass it to
8669 binding_cluster::mark_region_as_unknown when handling symbolic
8670 regions.
8671 (store::mark_region_as_unknown): Add uncertainty param and pass it
8672 to binding_cluster::mark_region_as_unknown.
8673 (store::remove_overlapping_bindings): Add uncertainty param and
8674 pass it to binding_cluster::remove_overlapping_bindings.
8675 * store.h (binding_cluster::mark_region_as_unknown): Add
8676 uncertainty param.
8677 (binding_cluster::remove_overlapping_bindings): Likewise.
8678 (store::set_value): Likewise.
8679 (store::mark_region_as_unknown): Likewise.
8680
8681 2021-04-05 David Malcolm <[email protected]>
8682
8683 PR analyzer/99906
8684 * analyzer.cc (maybe_reconstruct_from_def_stmt): Fix NULL
8685 dereference on calls with zero arguments.
8686 * sm-malloc.cc (malloc_state_machine::on_stmt): When handling
8687 __attribute__((nonnull)), only call get_diagnostic_tree if the
8688 result will be used.
8689
8690 2021-04-05 David Malcolm <[email protected]>
8691
8692 PR analyzer/99886
8693 * diagnostic-manager.cc
8694 (diagnostic_manager::prune_interproc_events): Use signed integers
8695 when subtracting one from path->num_events ().
8696 (diagnostic_manager::consolidate_conditions): Likewise. Convert
8697 next_idx to a signed int.
8698
8699 2021-04-01 David Malcolm <[email protected]>
8700
8701 * diagnostic-manager.cc (diagnostic_manager::add_diagnostic): Make
8702 enode param non-constant, and call add_diagnostic on it. Add
8703 enode index to log message.
8704 (diagnostic_manager::add_diagnostic): Make enode param
8705 non-constant.
8706 * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
8707 Likewise for both decls.
8708 * engine.cc
8709 (impl_region_model_context::impl_region_model_context): Likewise
8710 for enode_for_diag.
8711 (impl_sm_context::impl_sm_context): Likewise.
8712 (impl_sm_context::m_enode_for_diag): Likewise.
8713 (exploded_node::dump_dot): Don't pass the diagnostic manager
8714 to dump_saved_diagnostics.
8715 (exploded_node::dump_saved_diagnostics): Drop param. Iterate
8716 directly through all saved diagnostics for the enode, rather
8717 than all saved diagnostics in the diagnostic_manager and
8718 filtering.
8719 (exploded_node::on_stmt): Make non-const.
8720 (exploded_node::on_edge): Likewise.
8721 (exploded_node::on_longjmp): Likewise.
8722 (exploded_node::detect_leaks): Likewise.
8723 (exploded_graph::get_or_create_node): Make enode_for_diag param
8724 non-const.
8725 (exploded_graph_annotator::print_enode): Iterate
8726 directly through all saved diagnostics for the enode, rather
8727 than all saved diagnostics in the diagnostic_manager and
8728 filtering.
8729 * exploded-graph.h
8730 (impl_region_model_context::impl_region_model_context): Make
8731 enode_for_diag param non-constant.
8732 (impl_region_model_context::m_enode_for_diag): Likewise.
8733 (exploded_node::dump_saved_diagnostics): Drop param.
8734 (exploded_node::on_stmt): Make non-const.
8735 (exploded_node::on_edge): Likewise.
8736 (exploded_node::on_longjmp): Likewise.
8737 (exploded_node::detect_leaks): Likewise.
8738 (exploded_node::add_diagnostic): New.
8739 (exploded_node::get_num_diagnostics): New.
8740 (exploded_node::get_saved_diagnostic): New.
8741 (exploded_node::m_saved_diagnostics): New.
8742 (exploded_graph::get_or_create_node): Make enode_for_diag param
8743 non-constant.
8744 * feasible-graph.cc (feasible_node::dump_dot): Drop
8745 diagnostic_manager from call to dump_saved_diagnostics.
8746 * program-state.cc (program_state::on_edge): Convert enode param
8747 to non-const pointer.
8748 (program_state::prune_for_point): Likewise for enode_for_diag
8749 param.
8750 * program-state.h (program_state::on_edge): Convert enode param
8751 to non-const pointer.
8752 (program_state::prune_for_point): Likewise for enode_for_diag
8753 param.
8754
8755 2021-03-31 David Malcolm <[email protected]>
8756
8757 PR analyzer/99771
8758 * analyzer.cc (maybe_reconstruct_from_def_stmt): New.
8759 (fixup_tree_for_diagnostic_1): New.
8760 (fixup_tree_for_diagnostic): New.
8761 * analyzer.h (fixup_tree_for_diagnostic): New decl.
8762 * checker-path.cc (call_event::get_desc): Call
8763 fixup_tree_for_diagnostic and use it for the call_with_state call.
8764 (warning_event::get_desc): Likewise for the final_event and
8765 make_label_text calls.
8766 * engine.cc (impl_region_model_context::on_state_leak): Likewise
8767 for the on_leak and add_diagnostic calls.
8768 * region-model.cc (region_model::get_representative_tree):
8769 Likewise for the result.
8770
8771 2021-03-30 David Malcolm <[email protected]>
8772
8773 * region.h (region::dump_to_pp): Remove old decl.
8774
8775 2021-03-30 David Malcolm <[email protected]>
8776
8777 * sm-file.cc (fileptr_state_machine::on_stmt): Only call
8778 get_diagnostic_tree if the result will be used.
8779 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
8780 (malloc_state_machine::on_deallocator_call): Likewise.
8781 (malloc_state_machine::on_realloc_call): Likewise.
8782 (malloc_state_machine::on_realloc_call): Likewise.
8783 * sm-sensitive.cc
8784 (sensitive_state_machine::warn_for_any_exposure): Likewise.
8785 * sm-taint.cc (taint_state_machine::on_stmt): Likewise.
8786
8787 2021-03-25 David Malcolm <[email protected]>
8788
8789 PR analyzer/93695
8790 PR analyzer/99044
8791 PR analyzer/99716
8792 * engine.cc (exploded_node::on_stmt): Clear sm-state involving
8793 an SSA name at the def-stmt of that SSA name.
8794 * program-state.cc (sm_state_map::purge_state_involving): New.
8795 * program-state.h (sm_state_map::purge_state_involving): New decl.
8796 * region-model.cc (selftest::test_involves_p): New.
8797 (selftest::analyzer_region_model_cc_tests): Call it.
8798 * svalue.cc (class involvement_visitor): New class
8799 (svalue::involves_p): New.
8800 * svalue.h (svalue::involves_p): New decl.
8801
8802 2021-03-19 David Malcolm <[email protected]>
8803
8804 PR analyzer/99614
8805 * diagnostic-manager.cc (class epath_finder): Add
8806 DISABLE_COPY_AND_ASSIGN.
8807
8808 2021-03-15 Martin Liska <[email protected]>
8809
8810 * sm-file.cc (get_file_using_fns): Add missing comma in initializer.
8811
8812 2021-03-11 David Malcolm <[email protected]>
8813
8814 PR analyzer/96374
8815 * analyzer.opt (-param=analyzer-max-infeasible-edges=): New param.
8816 (fdump-analyzer-feasibility): New flag.
8817 * diagnostic-manager.cc: Include "analyzer/trimmed-graph.h" and
8818 "analyzer/feasible-graph.h".
8819 (epath_finder::epath_finder): Convert m_sep to a pointer and
8820 only create it if !flag_analyzer_feasibility.
8821 (epath_finder::~epath_finder): New.
8822 (epath_finder::m_sep): Convert to a pointer.
8823 (epath_finder::get_best_epath): Add param "diag_idx" and use it
8824 when logging. Rather than finding the shortest path and then
8825 checking feasibility, instead use explore_feasible_paths unless
8826 !flag_analyzer_feasibility, in which case simply use the shortest
8827 path, and note if it is infeasible. Update for m_sep becoming a
8828 pointer.
8829 (class feasible_worklist): New.
8830 (epath_finder::explore_feasible_paths): New.
8831 (epath_finder::process_worklist_item): New.
8832 (class dump_eg_with_shortest_path): New.
8833 (epath_finder::dump_trimmed_graph): New.
8834 (epath_finder::dump_feasible_graph): New.
8835 (saved_diagnostic::saved_diagnostic): Add "idx" param, using it
8836 on new field m_idx.
8837 (saved_diagnostic::to_json): Dump m_idx.
8838 (saved_diagnostic::calc_best_epath): Pass m_idx to get_best_epath.
8839 Remove assertion that m_problem was set when m_best_epath is NULL.
8840 (diagnostic_manager::add_diagnostic): Pass an index when created
8841 saved_diagnostic instances.
8842 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add
8843 "idx" param.
8844 (saved_diagnostic::get_index): New accessor.
8845 (saved_diagnostic::m_idx): New field.
8846 * engine.cc (exploded_node::dump_dot): Call args.dump_extra_info.
8847 Move code to...
8848 (exploded_node::dump_processed_stmts): ...this new function and...
8849 (exploded_node::dump_saved_diagnostics): ...this new function.
8850 Add index of each diagnostic.
8851 (exploded_edge::dump_dot): Move bulk of code to...
8852 (exploded_edge::dump_dot_label): ...this new function.
8853 * exploded-graph.h (eg_traits::dump_args_t::dump_extra_info): New
8854 vfunc.
8855 (exploded_node::dump_processed_stmts): New decl.
8856 (exploded_node::dump_saved_diagnostics): New decl.
8857 (exploded_edge::dump_dot_label): New decl.
8858 * feasible-graph.cc: New file.
8859 * feasible-graph.h: New file.
8860 * trimmed-graph.cc: New file.
8861 * trimmed-graph.h: New file.
8862
8863 2021-03-11 David Malcolm <[email protected]>
8864
8865 * diagnostic-manager.cc (epath_finder::epath_finder):
8866 Update shortest_paths init for new param.
8867
8868 2021-03-10 David Malcolm <[email protected]>
8869
8870 PR analyzer/96374
8871 * engine.cc (exploded_path::feasible_p): Move "snodes_visited" and
8872 "model" locals into a new class feasibility_state. Move heart
8873 of per-edge processing into
8874 feasibility_state::maybe_update_for_edge.
8875 (feasibility_state::feasibility_state): New.
8876 (feasibility_state::maybe_update_for_edge): New, based on loop
8877 body in exploded_path::feasible_p.
8878 * exploded-graph.h (class feasibility_state): New.
8879
8880 2021-03-10 David Malcolm <[email protected]>
8881
8882 * supergraph.h
8883 (callgraph_superedge::dyn_cast_callgraph_superedge): New.
8884 (call_superedge::dyn_cast_callgraph_superedge): Delete.
8885 (return_superedge::dyn_cast_callgraph_superedge): Delete.
8886
8887 2021-03-02 Martin Liska <[email protected]>
8888
8889 * diagnostic-manager.cc (diagnostic_manager::emit_saved_diagnostics):
8890 Do not pass engine.
8891
8892 2021-02-26 David Malcolm <[email protected]>
8893
8894 * engine.cc (exploded_path::exploded_path): New copy-ctor.
8895 * exploded-graph.h (exploded_path::operator=): Drop decl.
8896
8897 2021-02-26 David Malcolm <[email protected]>
8898
8899 PR analyzer/96374
8900 * diagnostic-manager.cc (class epath_finder): New.
8901 (epath_finder::get_best_epath): New.
8902 (saved_diagnostic::saved_diagnostic): Update for replacement of
8903 m_state and m_epath_length with m_best_epath.
8904 (saved_diagnostic::~saved_diagnostic): Delete m_best_epath.
8905 (saved_diagnostic::to_json): Update "path_length" to be optional.
8906 (saved_diagnostic::calc_best_epath): New, based on
8907 dedupe_winners::add and parts of dedupe_key::dedupe_key.
8908 (saved_diagnostic::get_epath_length): New.
8909 (saved_diagnostic::add_duplicate): New.
8910 (dedupe_key::dedupe_key): Drop epath param. Move invocation of
8911 stmt_finder to saved_diagnostic::calc_best_epath.
8912 (class dedupe_candidate): Delete.
8913 (class dedupe_hash_map_traits): Update to use saved_diagnotic *
8914 rather than dedupe_candidate * as the value_type/compare_type.
8915 (dedupe_winners::~dedupe_winners): Don't delete the values.
8916 (dedupe_winners::add): Convert param from shortest_exploded_paths to
8917 epath_finder. Drop "eg" param. Drop dedupe_candidate, moving
8918 path generation and feasiblity checking to
8919 epath_finder::get_best_epath. Update winner-selection for move
8920 of epaths from dedupe_candidate to saved_diagnostic.
8921 (dedupe_winners::emit_best): Update for removal of class
8922 dedupe_candidate.
8923 (dedupe_winners::map_t): Update to use saved_diagnotic * rather
8924 than dedupe_candidate * as the value_type/compare_type.
8925 (diagnostic_manager::emit_saved_diagnostics): Move
8926 shortest_exploded_paths instance into epath_finder and pass that
8927 around instead.
8928 (diagnostic_manager::emit_saved_diagnostic): Drop epath, stmt
8929 and num_dupes params, instead getting these from the
8930 saved_diagnostic. Use correct location in inform_n call.
8931 * diagnostic-manager.h (class epath_finder): New forward decl.
8932 (saved_diagnostic::status): Drop enum.
8933 (saved_diagnostic::set_feasible): Drop.
8934 (saved_diagnostic::set_infeasible): Drop.
8935 (saved_diagnostic::get_status): Drop.
8936 (saved_diagnostic::calc_best_epath): New decl.
8937 (saved_diagnostic::get_best_epath): New decl.
8938 (saved_diagnostic::get_epath_length): New decl.
8939 (saved_diagnostic::set_epath_length): Drop.
8940 (saved_diagnostic::get_epath_length): Drop inline implementation.
8941 (saved_diagnostic::add_duplicate): New.
8942 (saved_diagnostic::get_num_dupes): New.
8943 (saved_diagnostic::m_d): Document ownership.
8944 (saved_diagnostic::m_trailing_eedge): Make const.
8945 (saved_diagnostic::m_status): Drop field.
8946 (saved_diagnostic::m_epath_length): Drop field.
8947 (saved_diagnostic::m_best_epath): New field.
8948 (saved_diagnostic::m_problem): Document ownership.
8949 (saved_diagnostic::m_duplicates): New field.
8950 (diagnostic_manager::emit_saved_diagnostic): Drop params epath,
8951 stmt, and num_dupes.
8952 * engine.cc (exploded_graph_annotator::print_saved_diagnostic):
8953 Update for changes to saved_diagnostic class.
8954 * exploded-graph.h (exploded_path::feasible_p): Drop unused
8955 overloaded decl.
8956
8957 2021-02-25 David Malcolm <[email protected]>
8958
8959 PR analyzer/99193
8960 * region-model-impl-calls.cc (region_model::impl_call_realloc): New.
8961 * region-model.cc (region_model::on_call_pre): Call it.
8962 * region-model.h (region_model::impl_call_realloc): New decl.
8963 * sm-malloc.cc (enum wording): Add WORDING_REALLOCATED.
8964 (malloc_state_machine::m_realloc): New field.
8965 (use_after_free::describe_state_change): Add case for
8966 WORDING_REALLOCATED.
8967 (use_after_free::describe_final_event): Likewise.
8968 (malloc_state_machine::malloc_state_machine): Initialize
8969 m_realloc.
8970 (malloc_state_machine::on_stmt): Handle realloc by calling...
8971 (malloc_state_machine::on_realloc_call): New.
8972
8973 2021-02-22 David Malcolm <[email protected]>
8974
8975 PR analyzer/99196
8976 * engine.cc (exploded_node::on_stmt): Provide terminate_path
8977 flag as a way for on_call_pre to terminate the current analysis
8978 path.
8979 * region-model-impl-calls.cc (call_details::num_args): New.
8980 (region_model::impl_call_error): New.
8981 * region-model.cc (region_model::on_call_pre): Add param
8982 "out_terminate_path". Handle "error" and "error_at_line".
8983 * region-model.h (call_details::num_args): New decl.
8984 (region_model::on_call_pre): Add param "out_terminate_path".
8985 (region_model::impl_call_error): New decl.
8986
8987 2021-02-17 David Malcolm <[email protected]>
8988
8989 PR analyzer/98969
8990 * constraint-manager.cc (dead_svalue_purger::should_purge_p):
8991 Update for change to svalue::live_p.
8992 * program-state.cc (sm_state_map::on_liveness_change): Likewise.
8993 (program_state::detect_leaks): Likewise.
8994 * region-model-reachability.cc (reachable_regions::init_cluster):
8995 When dealing with a symbolic region, if the underlying pointer is
8996 implicitly live, add the region to the reachable regions.
8997 * region-model.cc (region_model::compare_initial_and_pointer):
8998 Move logic for detecting initial values of params to
8999 initial_svalue::initial_value_of_param_p.
9000 * svalue.cc (svalue::live_p): Convert "live_svalues" from a
9001 reference to a pointer; support it being NULL.
9002 (svalue::implicitly_live_p): Convert first param from a
9003 refererence to a pointer.
9004 (region_svalue::implicitly_live_p): Likewise.
9005 (constant_svalue::implicitly_live_p): Likewise.
9006 (initial_svalue::implicitly_live_p): Likewise. Treat the initial
9007 values of params for the top level frame as still live.
9008 (initial_svalue::initial_value_of_param_p): New function, taken
9009 from a test in region_model::compare_initial_and_pointer.
9010 (unaryop_svalue::implicitly_live_p): Convert first param from a
9011 refererence to a pointer.
9012 (binop_svalue::implicitly_live_p): Likewise.
9013 (sub_svalue::implicitly_live_p): Likewise.
9014 (unmergeable_svalue::implicitly_live_p): Likewise.
9015 * svalue.h (svalue::live_p): Likewise.
9016 (svalue::implicitly_live_p): Likewise.
9017 (region_svalue::implicitly_live_p): Likewise.
9018 (constant_svalue::implicitly_live_p): Likewise.
9019 (initial_svalue::implicitly_live_p): Likewise.
9020 (initial_svalue::initial_value_of_param_p): New decl.
9021 (unaryop_svalue::implicitly_live_p): Convert first param from a
9022 refererence to a pointer.
9023 (binop_svalue::implicitly_live_p): Likewise.
9024 (sub_svalue::implicitly_live_p): Likewise.
9025 (unmergeable_svalue::implicitly_live_p): Likewise.
9026
9027 2021-02-12 David Malcolm <[email protected]>
9028
9029 PR analyzer/98969
9030 * engine.cc (readability): Add names for the various arbitrary
9031 values. Handle NOP_EXPR and INTEGER_CST.
9032 (readability_comparator): Combine the readability tests for
9033 tree and stack depth, rather than performing them sequentially.
9034 (impl_region_model_context::on_state_leak): Strip off top-level
9035 casts.
9036 * region-model.cc (region_model::get_representative_path_var): Add
9037 type-checking, moving the bulk of the implementation to...
9038 (region_model::get_representative_path_var_1): ...here. Respect
9039 types in casts by recursing and re-adding the cast, rather than
9040 merely stripping them off. Use the correct type when handling
9041 region_svalue.
9042 (region_model::get_representative_tree): Strip off any top-level
9043 cast.
9044 (region_model::get_representative_path_var): Add type-checking,
9045 moving the bulk of the implementation to...
9046 (region_model::get_representative_path_var_1): ...here.
9047 * region-model.h (region_model::get_representative_path_var_1):
9048 New decl
9049 (region_model::get_representative_path_var_1): New decl.
9050 * store.cc (append_pathvar_with_type): New.
9051 (binding_cluster::get_representative_path_vars): Cast path_vars
9052 to the correct type when adding them to *OUT_PVS.
9053
9054 2021-02-09 David Malcolm <[email protected]>
9055
9056 PR analyzer/98575
9057 * sm-file.cc (is_file_using_fn_p): Support "_IO_"-prefixed
9058 variants.
9059
9060 2021-02-09 David Malcolm <[email protected]>
9061
9062 PR analyzer/98575
9063 * store.cc (store::set_value): Treat a pointer written to *UNKNOWN
9064 as having escaped.
9065
9066 2021-02-02 David Malcolm <[email protected]>
9067
9068 PR analyzer/93355
9069 PR analyzer/96374
9070 * engine.cc (toplevel_function_p): Simplify so that
9071 we only reject functions with a "__analyzer_" prefix.
9072 (add_any_callbacks): Delete.
9073 (exploded_graph::build_initial_worklist): Update for
9074 dropped param of toplevel_function_p.
9075 (exploded_graph::build_initial_worklist): Don't bother
9076 looking for callbacks that are reachable from global
9077 initializers.
9078
9079 2021-02-01 David Malcolm <[email protected]>
9080
9081 PR analyzer/98918
9082 * region-model-manager.cc
9083 (region_model_manager::get_or_create_initial_value):
9084 Fold the initial value of *UNKNOWN_PTR to an UNKNOWN value.
9085 (region_model_manager::get_field_region): Fold the value
9086 of UNKNOWN_PTR->FIELD to *UNKNOWN_PTR_OF_&FIELD_TYPE.
9087
9088 2021-01-29 David Malcolm <[email protected]>
9089
9090 * checker-path.cc (event_kind_to_string): Handle
9091 EK_START_CONSOLIDATED_CFG_EDGES and
9092 EK_END_CONSOLIDATED_CFG_EDGES.
9093 (start_consolidated_cfg_edges_event::get_desc): New.
9094 (checker_path::cfg_edge_pair_at_p): New.
9095 * checker-path.h (enum event_kind): Add
9096 EK_START_CONSOLIDATED_CFG_EDGES and
9097 EK_END_CONSOLIDATED_CFG_EDGES.
9098 (class start_consolidated_cfg_edges_event): New class.
9099 (class end_consolidated_cfg_edges_event): New class.
9100 (checker_path::delete_events): New.
9101 (checker_path::replace_event): New.
9102 (checker_path::cfg_edge_pair_at_p): New decl.
9103 * diagnostic-manager.cc (diagnostic_manager::prune_path): Call
9104 consolidate_conditions.
9105 (same_line_as_p): New.
9106 (diagnostic_manager::consolidate_conditions): New.
9107 * diagnostic-manager.h
9108 (diagnostic_manager::consolidate_conditions): New decl.
9109
9110 2021-01-18 David Malcolm <[email protected]>
9111
9112 * analyzer.h (is_std_named_call_p): New decl.
9113 * diagnostic-manager.cc (path_builder::get_sm): New.
9114 (state_change_event_creator::state_change_event_creator): Add "pb"
9115 param.
9116 (state_change_event_creator::on_global_state_change): Don't consider
9117 state changes affecting other state_machines.
9118 (state_change_event_creator::on_state_change): Likewise.
9119 (state_change_event_creator::m_pb): New field.
9120 (diagnostic_manager::add_events_for_eedge): Pass pb to visitor
9121 ctor.
9122 * region-model-impl-calls.cc
9123 (region_model::impl_deallocation_call): New.
9124 * region-model.cc: Include "attribs.h".
9125 (region_model::on_call_post): Handle fndecls referenced by
9126 __attribute__((deallocated_by(FOO))).
9127 * region-model.h (region_model::impl_deallocation_call): New decl.
9128 * sm-malloc.cc: Include "stringpool.h" and "attribs.h". Add
9129 leading comment.
9130 (class api): Delete.
9131 (enum resource_state): Update comment for change from api to
9132 deallocator and deallocator_set.
9133 (allocation_state::allocation_state): Drop api param. Add
9134 "deallocators" and "deallocator".
9135 (allocation_state::m_api): Drop field in favor of...
9136 (allocation_state::m_deallocators): New field.
9137 (allocation_state::m_deallocator): New field.
9138 (enum wording): Add WORDING_DEALLOCATED.
9139 (struct deallocator): New.
9140 (struct standard_deallocator): New.
9141 (struct custom_deallocator): New.
9142 (struct deallocator_set): New.
9143 (struct custom_deallocator_set): New.
9144 (struct standard_deallocator_set): New.
9145 (struct deallocator_set_map_traits): New.
9146 (malloc_state_machine::m_malloc): Drop field
9147 (malloc_state_machine::m_scalar_new): Likewise.
9148 (malloc_state_machine::m_vector_new): Likewise.
9149 (malloc_state_machine::m_free): New field
9150 (malloc_state_machine::m_scalar_delete): Likewise.
9151 (malloc_state_machine::m_vector_delete): Likewise.
9152 (malloc_state_machine::deallocator_map_t): New typedef.
9153 (malloc_state_machine::m_deallocator_map): New field.
9154 (malloc_state_machine::deallocator_set_cache_t): New typedef.
9155 (malloc_state_machine::m_custom_deallocator_set_cache): New field.
9156 (malloc_state_machine::custom_deallocator_set_map_t): New typedef.
9157 (malloc_state_machine::m_custom_deallocator_set_map): New field.
9158 (malloc_state_machine::m_dynamic_sets): New field.
9159 (malloc_state_machine::m_dynamic_deallocators): New field.
9160 (api::api): Delete.
9161 (deallocator::deallocator): New ctor.
9162 (deallocator::hash): New.
9163 (deallocator::dump_to_pp): New.
9164 (deallocator::cmp): New.
9165 (deallocator::cmp_ptr_ptr): New.
9166 (standard_deallocator::standard_deallocator): New ctor.
9167 (deallocator_set::deallocator_set): New ctor.
9168 (deallocator_set::dump): New.
9169 (custom_deallocator_set::custom_deallocator_set): New ctor.
9170 (custom_deallocator_set::contains_p): New.
9171 (custom_deallocator_set::maybe_get_single): New.
9172 (custom_deallocator_set::dump_to_pp): New.
9173 (standard_deallocator_set::standard_deallocator_set): New ctor.
9174 (standard_deallocator_set::contains_p): New.
9175 (standard_deallocator_set::maybe_get_single): New.
9176 (standard_deallocator_set::dump_to_pp): New.
9177 (start_p): New.
9178 (class mismatching_deallocation): Update for conversion from api
9179 to deallocator_set and deallocator.
9180 (double_free::emit): Use %qs.
9181 (class use_after_free): Update for conversion from api to
9182 deallocator_set and deallocator.
9183 (malloc_leak::describe_state_change): Only emit "allocated here" on
9184 a start->nonnull transition, rather than on other transitions to
9185 nonnull.
9186 (allocation_state::dump_to_pp): Update for conversion from api to
9187 deallocator_set.
9188 (allocation_state::get_nonnull): Likewise.
9189 (malloc_state_machine::malloc_state_machine): Likewise.
9190 (malloc_state_machine::~malloc_state_machine): New.
9191 (malloc_state_machine::add_state): Update for conversion from api
9192 to deallocator_set.
9193 (malloc_state_machine::get_or_create_custom_deallocator_set): New.
9194 (malloc_state_machine::maybe_create_custom_deallocator_set): New.
9195 (malloc_state_machine::get_or_create_deallocator): New.
9196 (malloc_state_machine::on_stmt): Update for conversion from api
9197 to deallocator_set. Handle "__attribute__((malloc(FOO)))", and
9198 the special attribute set on FOO.
9199 (malloc_state_machine::on_allocator_call): Update for conversion
9200 from api to deallocator_set. Add "returns_nonnull" param and use
9201 it to affect which state to transition to.
9202 (malloc_state_machine::on_deallocator_call): Update for conversion
9203 from api to deallocator_set.
9204
9205 2021-01-14 David Malcolm <[email protected]>
9206
9207 * engine.cc (strongly_connected_components::to_json): New.
9208 (worklist::to_json): New.
9209 (exploded_graph::to_json): JSON-ify the worklist.
9210 * exploded-graph.h (strongly_connected_components::to_json): New
9211 decl.
9212 (worklist::to_json): New decl.
9213 * store.cc (store::to_json): Fix comment.
9214 * supergraph.cc (supernode::to_json): Fix reference to
9215 "returning_call" in comment. Add optional "fun" to JSON.
9216 (edge_kind_to_string): New.
9217 (superedge::to_json): Add "kind" to JSON.
9218
9219 2021-01-14 David Malcolm <[email protected]>
9220
9221 PR analyzer/98679
9222 * analyzer.h (region_offset::operator==): Make const.
9223 * pending-diagnostic.h (pending_diagnostic::equal_p): Likewise.
9224 * store.h (binding_cluster::for_each_value): Likewise.
9225 (binding_cluster::for_each_binding): Likewise.
9226
9227 2021-01-12 David Malcolm <[email protected]>
9228
9229 PR analyzer/98628
9230 * store.cc (binding_cluster::make_unknown_relative_to): Don't mark
9231 dereferenced unknown pointers as having escaped.
9232
9233 2021-01-07 David Malcolm <[email protected]>
9234
9235 PR analyzer/98580
9236 * region.cc (decl_region::get_svalue_for_initializer): Gracefully
9237 handle when LTO writes out DECL_INITIAL as error_mark_node.
9238
9239 2021-01-07 David Malcolm <[email protected]>
9240
9241 PR analyzer/97074
9242 * store.cc (binding_cluster::can_merge_p): Add "out_store" param
9243 and pass to calls to binding_cluster::make_unknown_relative_to.
9244 (binding_cluster::make_unknown_relative_to): Add "out_store"
9245 param. Use it to mark base regions that are pointed to by
9246 pointers that become unknown as having escaped.
9247 (store::can_merge_p): Pass out_store to
9248 binding_cluster::can_merge_p.
9249 * store.h (binding_cluster::can_merge_p): Add "out_store" param.
9250 (binding_cluster::make_unknown_relative_to): Likewise.
9251 * svalue.cc (region_svalue::implicitly_live_p): New vfunc.
9252 * svalue.h (region_svalue::implicitly_live_p): New vfunc decl.
9253
9254 2021-01-07 David Malcolm <[email protected]>
9255
9256 PR analyzer/98564
9257 * engine.cc (exploded_path::feasible_p): Add missing call to
9258 bitmap_clear.
9259
9260 2021-01-06 David Malcolm <[email protected]>
9261
9262 PR analyzer/97072
9263 * region-model-reachability.cc (reachable_regions::init_cluster):
9264 Convert symbolic region handling to a switch statement. Add cases
9265 to handle SK_UNKNOWN and SK_CONJURED.
9266
9267 2021-01-05 David Malcolm <[email protected]>
9268
9269 PR analyzer/98293
9270 * store.cc (binding_map::apply_ctor_to_region): When "index" is
9271 NULL, iterate through the fields for RECORD_TYPEs, rather than
9272 creating an INTEGER_CST index.
9273
9274 2020-11-30 David Malcolm <[email protected]>
9275
9276 * analyzer-pass.cc: Include "analyzer/analyzer.h" for the
9277 declaration of sorry_no_analyzer; include "tree.h" and
9278 "function.h" as these are needed by it.
9279
9280 2020-11-30 David Malcolm <[email protected]>
9281
9282 * analyzer-pass.cc (pass_analyzer::execute): Move sorry call to...
9283 (sorry_no_analyzer): New.
9284 * analyzer.h (class state_machine): New forward decl.
9285 (class logger): New forward decl.
9286 (class plugin_analyzer_init_iface): New.
9287 (sorry_no_analyzer): New decl.
9288 * checker-path.cc (checker_path::fixup_locations): New.
9289 * checker-path.h (checker_event::set_location): New.
9290 (checker_path::fixup_locations): New decl.
9291 * diagnostic-manager.cc
9292 (diagnostic_manager::emit_saved_diagnostic): Call
9293 checker_path::fixup_locations, and call fixup_location
9294 on the primary location.
9295 * engine.cc: Include "plugin.h".
9296 (class plugin_analyzer_init_impl): New.
9297 (impl_run_checkers): Invoke PLUGIN_ANALYZER_INIT callbacks.
9298 * pending-diagnostic.h (pending_diagnostic::fixup_location): New
9299 vfunc.
9300
9301 2020-11-18 David Malcolm <[email protected]>
9302
9303 PR analyzer/97893
9304 * sm-malloc.cc (null_deref::emit): Use CWE-476 rather than
9305 CWE-690, as this isn't due to an unchecked return value.
9306 (null_arg::emit): Likewise.
9307
9308 2020-11-12 David Malcolm <[email protected]>
9309
9310 * checker-path.h (checker_event::get_id_ptr): New.
9311 * diagnostic-manager.cc (path_builder::path_builder): Add "sd"
9312 param and use it to initialize new field "m_sd".
9313 (path_builder::get_pending_diagnostic): New.
9314 (path_builder::m_sd): New field.
9315 (diagnostic_manager::emit_saved_diagnostic): Pass sd to
9316 path_builder ctor.
9317 (diagnostic_manager::add_events_for_superedge): Call new
9318 maybe_add_custom_events_for_superedge vfunc.
9319 * engine.cc (stale_jmp_buf::stale_jmp_buf): Add "setjmp_point"
9320 param and use it to initialize new field "m_setjmp_point".
9321 Initialize new field "m_stack_pop_event".
9322 (stale_jmp_buf::maybe_add_custom_events_for_superedge): New vfunc
9323 implementation.
9324 (stale_jmp_buf::describe_final_event): New vfunc implementation.
9325 (stale_jmp_buf::m_setjmp_point): New field.
9326 (stale_jmp_buf::m_stack_pop_event): New field.
9327 (exploded_node::on_longjmp): Pass setjmp_point to stale_jmp_buf
9328 ctor.
9329 * pending-diagnostic.h
9330 (pending_diagnostic::maybe_add_custom_events_for_superedge): New
9331 vfunc.
9332
9333 2020-11-12 David Malcolm <[email protected]>
9334
9335 PR tree-optimization/97424
9336 * analyzer.opt (Wanalyzer-shift-count-negative): New.
9337 (Wanalyzer-shift-count-overflow): New.
9338 * region-model.cc (class shift_count_negative_diagnostic): New.
9339 (class shift_count_overflow_diagnostic): New.
9340 (region_model::get_gassign_result): Complain about shift counts that
9341 are negative or are >= the operand's type's width.
9342
9343 2020-11-10 Martin Liska <[email protected]>
9344
9345 * constraint-manager.cc (constraint_manager::merge): Remove
9346 unused code.
9347 * constraint-manager.h: Likewise.
9348 * program-state.cc (sm_state_map::sm_state_map): Likewise.
9349 (program_state::program_state): Likewise.
9350 (test_sm_state_map): Likewise.
9351 * program-state.h: Likewise.
9352 * region-model-reachability.cc (reachable_regions::reachable_regions): Likewise.
9353 * region-model-reachability.h: Likewise.
9354 * region-model.cc (region_model::handle_unrecognized_call): Likewise.
9355 (region_model::get_reachable_svalues): Likewise.
9356 (region_model::can_merge_with_p): Likewise.
9357
9358 2020-11-05 David Malcolm <[email protected]>
9359
9360 PR analyzer/97668
9361 * svalue.cc (cmp_cst): Handle COMPLEX_CST.
9362
9363 2020-10-29 David Malcolm <[email protected]>
9364
9365 * program-state.cc (sm_state_map::on_liveness_change): Sort the
9366 leaking svalues before calling on_state_leak.
9367 (program_state::detect_leaks): Likewise when calling
9368 on_svalue_leak.
9369 * region-model-reachability.cc
9370 (reachable_regions::mark_escaped_clusters): Likewise when
9371 calling on_escaped_function.
9372
9373 2020-10-29 David Malcolm <[email protected]>
9374
9375 PR analyzer/97608
9376 * region-model-reachability.cc (reachable_regions::handle_sval):
9377 Operands of reachable reversible operations are reachable.
9378
9379 2020-10-29 David Malcolm <[email protected]>
9380
9381 * analyzer.h (class state_machine): New forward decl.
9382 (class logger): Likewise.
9383 (class visitor): Likewise.
9384 * complexity.cc: New file, taken from svalue.cc.
9385 * complexity.h: New file, taken from region-model.h.
9386 * region-model.h: Include "analyzer/svalue.h" and
9387 "analyzer/region.h". Move struct complexity to complexity.h.
9388 Move svalue, its subclasses and supporting decls to svalue.h.
9389 Move region, its subclasses and supporting decls to region.h.
9390 * region.cc: Include "analyzer/region.h".
9391 (symbolic_region::symbolic_region): Move here from region-model.h.
9392 * region.h: New file, based on material from region-model.h.
9393 * svalue.cc: Include "analyzer/svalue.h".
9394 (complexity::complexity): Move to complexity.cc.
9395 (complexity::from_pair): Likewise.
9396 * svalue.h: New file, based on material from region-model.h.
9397
9398 2020-10-29 David Malcolm <[email protected]>
9399
9400 * program-state.cc (sm_state_map::print): Guard the printing of
9401 the origin pointer with !flag_dump_noaddr.
9402 * region.cc (string_region::dump_to_pp): Likewise for
9403 m_string_cst.
9404
9405 2020-10-27 David Malcolm <[email protected]>
9406
9407 PR analyzer/97568
9408 * region-model.cc (region_model::get_initial_value_for_global):
9409 Move check that !DECL_EXTERNAL from here to...
9410 * region.cc (decl_region::get_svalue_for_initializer): ...here,
9411 using it to reject zero initialization.
9412
9413 2020-10-27 Markus Böck <[email protected]>
9414
9415 PR analyzer/96608
9416 * store.h (hash): Cast to intptr_t instead of long
9417
9418 2020-10-27 David Malcolm <[email protected]>
9419
9420 * constraint-manager.cc (svalue_cmp_by_ptr): Delete.
9421 (equiv_class::canonicalize): Use svalue::cmp_ptr_ptr instead.
9422 (equiv_class_cmp): Eliminate pointer comparison.
9423 * diagnostic-manager.cc (dedupe_key::comparator): If they are at
9424 the same location, also compare epath ength and pending_diagnostic
9425 kind.
9426 * engine.cc (readability_comparator): If two path_vars have the
9427 same readability, then impose an arbitrary ordering on them.
9428 (worklist::key_t::cmp): If two points have the same plan ordering,
9429 continue the comparison. Call sm_state_map::cmp rather than
9430 comparing hash values.
9431 * program-state.cc (sm_state_map::entry_t::cmp): New.
9432 (sm_state_map::cmp): New.
9433 * program-state.h (sm_state_map::entry_t::cmp): New decl.
9434 (sm_state_map::elements): New.
9435 (sm_state_map::cmp): New.
9436
9437 2020-10-27 David Malcolm <[email protected]>
9438
9439 * engine.cc (setjmp_record::cmp): New.
9440 (supernode_cluster::dump_dot): Avoid embedding pointer in cluster
9441 name.
9442 (supernode_cluster::cmp_ptr_ptr): New.
9443 (function_call_string_cluster::dump_dot): Avoid embedding pointer
9444 in cluster name. Sort m_map when dumping child clusters.
9445 (function_call_string_cluster::cmp_ptr_ptr): New.
9446 (root_cluster::dump_dot): Sort m_map when dumping child clusters.
9447 * program-point.cc (function_point::cmp): New.
9448 (function_point::cmp_ptr): New.
9449 * program-point.h (function_point::cmp): New decl.
9450 (function_point::cmp_ptr): New decl.
9451 * program-state.cc (sm_state_map::print): Sort the values. Guard
9452 the printing of pointers with !flag_dump_noaddr.
9453 (program_state::prune_for_point): Sort the regions.
9454 (log_set_of_svalues): Sort the values. Guard the printing of
9455 pointers with !flag_dump_noaddr.
9456 * region-model-manager.cc (log_uniq_map): Sort the values.
9457 * region-model-reachability.cc (dump_set): New function template.
9458 (reachable_regions::dump_to_pp): Use it.
9459 * region-model.h (svalue::cmp_ptr): New decl.
9460 (svalue::cmp_ptr_ptr): New decl.
9461 (setjmp_record::cmp): New decl.
9462 (placeholder_svalue::get_name): New accessor.
9463 (widening_svalue::get_point): New accessor.
9464 (compound_svalue::get_map): New accessor.
9465 (conjured_svalue::get_stmt): New accessor.
9466 (conjured_svalue::get_id_region): New accessor.
9467 (region::cmp_ptrs): Rename to...
9468 (region::cmp_ptr_ptr): ...this.
9469 * region.cc (region::cmp_ptrs): Rename to...
9470 (region::cmp_ptr_ptr): ...this.
9471 * state-purge.cc
9472 (state_purge_per_ssa_name::state_purge_per_ssa_name): Sort
9473 m_points_needing_name when dumping.
9474 * store.cc (concrete_binding::cmp_ptr_ptr): New.
9475 (symbolic_binding::cmp_ptr_ptr): New.
9476 (binding_map::cmp): New.
9477 (get_sorted_parent_regions): Update for renaming of
9478 region::cmp_ptrs to region::cmp_ptr_ptr.
9479 (store::dump_to_pp): Likewise.
9480 (store::to_json): Likewise.
9481 (store::can_merge_p): Sort the base regions before considering
9482 them.
9483 * store.h (concrete_binding::cmp_ptr_ptr): New decl.
9484 (symbolic_binding::cmp_ptr_ptr): New decl.
9485 (binding_map::cmp): New decl.
9486 * supergraph.cc (supergraph::supergraph): Assign UIDs to the
9487 gimple stmts.
9488 * svalue.cc (cmp_cst): New.
9489 (svalue::cmp_ptr): New.
9490 (svalue::cmp_ptr_ptr): New.
9491
9492 2020-10-27 David Malcolm <[email protected]>
9493
9494 * engine.cc (exploded_graph::get_or_create_node): Fix off-by-one
9495 when imposing param_analyzer_max_enodes_per_program_point limit.
9496
9497 2020-10-27 David Malcolm <[email protected]>
9498
9499 * region-model.cc (region_model::get_representative_path_var):
9500 Implement case RK_LABEL.
9501 * region-model.h (label_region::get_label): New accessor.
9502
9503 2020-10-22 David Malcolm <[email protected]>
9504
9505 PR analyzer/97514
9506 * engine.cc (exploded_graph::add_function_entry): Handle failure
9507 to create an enode, rather than asserting.
9508
9509 2020-10-22 David Malcolm <[email protected]>
9510
9511 PR analyzer/97489
9512 * engine.cc (exploded_graph::add_function_entry): Assert that we
9513 have a function body.
9514 (exploded_graph::on_escaped_function): Reject fndecls that don't
9515 have a function body.
9516
9517 2020-10-14 David Malcolm <[email protected]>
9518
9519 PR analyzer/93388
9520 * region-model.cc (region_model::get_initial_value_for_global):
9521 Fall back to returning an initial_svalue if
9522 decl_region::get_svalue_for_initializer fails.
9523 * region.cc (decl_region::get_svalue_for_initializer): Don't
9524 attempt to create a compound_svalue if the region has an unknown
9525 size.
9526
9527 2020-10-14 David Malcolm <[email protected]>
9528
9529 PR analyzer/93723
9530 * store.cc (binding_map::apply_ctor_to_region): Remove redundant
9531 assertion.
9532
9533 2020-10-12 David Malcolm <[email protected]>
9534
9535 PR analyzer/97258
9536 * engine.cc (impl_region_model_context::on_escaped_function): New
9537 vfunc.
9538 (exploded_graph::add_function_entry): Use m_functions_with_enodes
9539 to implement idempotency.
9540 (add_any_callbacks): New.
9541 (exploded_graph::build_initial_worklist): Use the above to find
9542 callbacks that are reachable from global initializers.
9543 (exploded_graph::on_escaped_function): New.
9544 * exploded-graph.h
9545 (impl_region_model_context::on_escaped_function): New decl.
9546 (exploded_graph::on_escaped_function): New decl.
9547 (exploded_graph::m_functions_with_enodes): New field.
9548 * region-model-reachability.cc
9549 (reachable_regions::reachable_regions): Replace "store" param with
9550 "model" param; use it to initialize m_model.
9551 (reachable_regions::add): When getting the svalue for the region,
9552 call get_store_value on the model rather than using an initial
9553 value.
9554 (reachable_regions::mark_escaped_clusters): Add ctxt param and
9555 use it to call on_escaped_function when a function_region escapes.
9556 * region-model-reachability.h
9557 (reachable_regions::reachable_regions): Replace "store" param with
9558 "model" param.
9559 (reachable_regions::mark_escaped_clusters): Add ctxt param.
9560 (reachable_regions::m_model): New field.
9561 * region-model.cc (region_model::handle_unrecognized_call): Update
9562 for change in reachable_regions ctor.
9563 (region_model::handle_unrecognized_call): Pass ctxt to
9564 mark_escaped_clusters.
9565 (region_model::get_reachable_svalues): Update for change in
9566 reachable_regions ctor.
9567 (region_model::get_initial_value_for_global): Read-only variables
9568 keep their initial values.
9569 * region-model.h (region_model_context::on_escaped_function): New
9570 vfunc.
9571 (noop_region_model_context::on_escaped_function): New.
9572
9573 2020-10-12 David Malcolm <[email protected]>
9574
9575 * analyzer.opt (Wanalyzer-write-to-const): New.
9576 (Wanalyzer-write-to-string-literal): New.
9577 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
9578 Call check_for_writable_region.
9579 (region_model::impl_call_memset): Likewise.
9580 (region_model::impl_call_strcpy): Likewise.
9581 * region-model.cc (class write_to_const_diagnostic): New.
9582 (class write_to_string_literal_diagnostic): New.
9583 (region_model::check_for_writable_region): New.
9584 (region_model::set_value): Call check_for_writable_region.
9585 * region-model.h (region_model::check_for_writable_region): New
9586 decl.
9587
9588 2020-10-07 David Malcolm <[email protected]>
9589
9590 PR analyzer/97116
9591 * sm-malloc.cc (method_p): New.
9592 (describe_argument_index): New.
9593 (inform_nonnull_attribute): Use describe_argument_index.
9594 (possible_null_arg::describe_final_event): Likewise.
9595 (null_arg::describe_final_event): Likewise.
9596
9597 2020-09-29 David Malcolm <[email protected]>
9598
9599 PR analyzer/95188
9600 * engine.cc (stmt_requires_new_enode_p): Split enodes before
9601 "signal" calls.
9602
9603 2020-09-29 David Malcolm <[email protected]>
9604
9605 * constraint-manager.cc
9606 (constraint_manager::add_constraint_internal): Whitespace fixes.
9607 Silence -Wsign-compare warning.
9608 * engine.cc (maybe_process_run_of_before_supernode_enodes):
9609 Silence -Wsign-compare warning.
9610
9611 2020-09-28 David Malcolm <[email protected]>
9612
9613 * region-model.h (binop_svalue::dyn_cast_binop_svalue): Remove
9614 redundant "virtual". Add FINAL OVERRIDE.
9615 (widening_svalue::dyn_cast_widening_svalue): Add FINAL OVERRIDE.
9616 (compound_svalue::dyn_cast_compound_svalue): Likewise.
9617 (conjured_svalue::dyn_cast_conjured_svalue): Likewise.
9618
9619 2020-09-28 David Malcolm <[email protected]>
9620
9621 * diagnostic-manager.cc (null_assignment_sm_context::m_visitor):
9622 Remove unused field.
9623
9624 2020-09-28 David Malcolm <[email protected]>
9625
9626 PR analyzer/97233
9627 * analyzer.cc (is_longjmp_call_p): Require the initial argument
9628 to be a pointer.
9629 * engine.cc (exploded_node::on_longjmp): Likewise.
9630
9631 2020-09-28 David Malcolm <[email protected]>
9632
9633 * program-state.cc (sm_state_map::print): Update check
9634 for m_global_state being the start state.
9635
9636 2020-09-26 David Malcolm <[email protected]>
9637
9638 PR analyzer/96646
9639 PR analyzer/96841
9640 * region-model.cc (region_model::get_representative_path_var):
9641 When handling offset_region, wrap the MEM_REF's first argument in
9642 an ADDR_EXPR of pointer type, rather than simply using the tree
9643 for the parent region. Require the MEM_REF's second argument to
9644 be an integer constant.
9645
9646 2020-09-24 David Malcolm <[email protected]>
9647
9648 * analyzer.h (struct rejected_constraint): New decl.
9649 * analyzer.opt (fanalyzer-feasibility): New option.
9650 * diagnostic-manager.cc (path_builder::path_builder): Add
9651 "problem" param and use it to initialize new field.
9652 (path_builder::get_feasibility_problem): New accessor.
9653 (path_builder::m_feasibility_problem): New field.
9654 (dedupe_winners::add): Remove inversion of logic in "if" clause,
9655 swapping if/else suites. In the !feasible_p suite, inspect
9656 flag_analyzer_feasibility and add code to handle when this
9657 is off, accepting the infeasible path, but recording the
9658 feasibility_problem.
9659 (diagnostic_manager::emit_saved_diagnostic): Pass the
9660 feasibility_problem to the path_builder.
9661 (diagnostic_manager::add_events_for_eedge): If we have
9662 a feasibility_problem at this edge, use it to add a custom event.
9663 * engine.cc (exploded_path::feasible_p): Pass a
9664 rejected_constraint ** to model.maybe_update_for_edge and transfer
9665 ownership of any created instance to any feasibility_problem.
9666 (feasibility_problem::dump_to_pp): New.
9667 * exploded-graph.h (feasibility_problem::feasibility_problem):
9668 Drop "model" param; add rejected_constraint * param.
9669 (feasibility_problem::~feasibility_problem): New.
9670 (feasibility_problem::dump_to_pp): New decl.
9671 (feasibility_problem::m_model): Drop field.
9672 (feasibility_problem::m_rc): New field.
9673 * program-point.cc (function_point::get_location): Handle
9674 PK_BEFORE_SUPERNODE and PK_AFTER_SUPERNODE.
9675 * program-state.cc (program_state::on_edge): Pass NULL to new
9676 param of region_model::maybe_update_for_edge.
9677 * region-model.cc (region_model::add_constraint): New overload
9678 adding a rejected_constraint ** param.
9679 (region_model::maybe_update_for_edge): Add rejected_constraint **
9680 param and pass it to the various apply_constraints_for_ calls.
9681 (region_model::apply_constraints_for_gcond): Add
9682 rejected_constraint ** param and pass it to add_constraint calls.
9683 (region_model::apply_constraints_for_gswitch): Likewise.
9684 (region_model::apply_constraints_for_exception): Likewise.
9685 (rejected_constraint::dump_to_pp): New.
9686 * region-model.h (region_model::maybe_update_for_edge):
9687 Add rejected_constraint ** param.
9688 (region_model::add_constraint): New overload adding a
9689 rejected_constraint ** param.
9690 (region_model::apply_constraints_for_gcond): Add
9691 rejected_constraint ** param.
9692 (region_model::apply_constraints_for_gswitch): Likewise.
9693 (region_model::apply_constraints_for_exception): Likewise.
9694 (struct rejected_constraint): New.
9695
9696 2020-09-23 David Malcolm <[email protected]>
9697
9698 PR analyzer/97178
9699 * engine.cc (impl_run_checkers): Update for change to ext_state
9700 ctor.
9701 * program-state.cc (selftest::test_sm_state_map): Pass an engine
9702 instance to ext_state ctor.
9703 (selftest::test_program_state_1): Likewise.
9704 (selftest::test_program_state_2): Likewise.
9705 (selftest::test_program_state_merging): Likewise.
9706 (selftest::test_program_state_merging_2): Likewise.
9707 * program-state.h (extrinsic_state::extrinsic_state): Remove NULL
9708 default value for "eng" param.
9709
9710 2020-09-23 Tobias Burnus <[email protected]>
9711
9712 * analyzer-logging.cc: Guard '#pragma ... ignored "-Wformat-diag"'
9713 by '#if __GNUC__ >= 10'
9714 * analyzer.h: Likewise.
9715 * call-string.cc: Likewise.
9716
9717 2020-09-23 David Malcolm <[email protected]>
9718
9719 * engine.cc (exploded_node::on_stmt): Replace sequence of dyn_cast
9720 with switch.
9721
9722 2020-09-22 David Malcolm <[email protected]>
9723
9724 * analysis-plan.cc: Include "json.h".
9725 * analyzer.opt (fdump-analyzer-json): New.
9726 * call-string.cc: Include "json.h".
9727 (call_string::to_json): New.
9728 * call-string.h (call_string::to_json): New decl.
9729 * checker-path.cc: Include "json.h".
9730 * constraint-manager.cc: Include "json.h".
9731 (equiv_class::to_json): New.
9732 (constraint::to_json): New.
9733 (constraint_manager::to_json): New.
9734 * constraint-manager.h (equiv_class::to_json): New decl.
9735 (constraint::to_json): New decl.
9736 (constraint_manager::to_json): New decl.
9737 * diagnostic-manager.cc: Include "json.h".
9738 (saved_diagnostic::to_json): New.
9739 (diagnostic_manager::to_json): New.
9740 * diagnostic-manager.h (saved_diagnostic::to_json): New decl.
9741 (diagnostic_manager::to_json): New decl.
9742 * engine.cc: Include "json.h", <zlib.h>.
9743 (exploded_node::status_to_str): New.
9744 (exploded_node::to_json): New.
9745 (exploded_edge::to_json): New.
9746 (exploded_graph::to_json): New.
9747 (dump_analyzer_json): New.
9748 (impl_run_checkers): Call it.
9749 * exploded-graph.h (exploded_node::status_to_str): New decl.
9750 (exploded_node::to_json): New.
9751 (exploded_edge::to_json): New.
9752 (exploded_graph::to_json): New.
9753 * pending-diagnostic.cc: Include "json.h".
9754 * program-point.cc: Include "json.h".
9755 (program_point::to_json): New.
9756 * program-point.h (program_point::to_json): New decl.
9757 * program-state.cc: Include "json.h".
9758 (extrinsic_state::to_json): New.
9759 (sm_state_map::to_json): New.
9760 (program_state::to_json): New.
9761 * program-state.h (extrinsic_state::to_json): New decl.
9762 (sm_state_map::to_json): New decl.
9763 (program_state::to_json): New decl.
9764 * region-model-impl-calls.cc: Include "json.h".
9765 * region-model-manager.cc: Include "json.h".
9766 * region-model-reachability.cc: Include "json.h".
9767 * region-model.cc: Include "json.h".
9768 * region-model.h (svalue::to_json): New decl.
9769 (region::to_json): New decl.
9770 * region.cc: Include "json.h".
9771 (region::to_json: New.
9772 * sm-file.cc: Include "json.h".
9773 * sm-malloc.cc: Include "json.h".
9774 * sm-pattern-test.cc: Include "json.h".
9775 * sm-sensitive.cc: Include "json.h".
9776 * sm-signal.cc: Include "json.h".
9777 (signal_delivery_edge_info_t::to_json): New.
9778 * sm-taint.cc: Include "json.h".
9779 * sm.cc: Include "diagnostic.h", "tree-diagnostic.h", and
9780 "json.h".
9781 (state_machine::state::to_json): New.
9782 (state_machine::to_json): New.
9783 * sm.h (state_machine::state::to_json): New.
9784 (state_machine::to_json): New.
9785 * state-purge.cc: Include "json.h".
9786 * store.cc: Include "json.h".
9787 (binding_key::get_desc): New.
9788 (binding_map::to_json): New.
9789 (binding_cluster::to_json): New.
9790 (store::to_json): New.
9791 * store.h (binding_key::get_desc): New decl.
9792 (binding_map::to_json): New decl.
9793 (binding_cluster::to_json): New decl.
9794 (store::to_json): New decl.
9795 * supergraph.cc: Include "json.h".
9796 (supergraph::to_json): New.
9797 (supernode::to_json): New.
9798 (superedge::to_json): New.
9799 * supergraph.h (supergraph::to_json): New decl.
9800 (supernode::to_json): New decl.
9801 (superedge::to_json): New decl.
9802 * svalue.cc: Include "json.h".
9803 (svalue::to_json): New.
9804
9805 2020-09-21 David Malcolm <[email protected]>
9806
9807 PR analyzer/97130
9808 * region-model-impl-calls.cc (call_details::get_arg_type): New.
9809 * region-model.cc (region_model::on_call_pre): Check that the
9810 initial arg is a pointer before calling impl_call_memset and
9811 impl_call_strlen.
9812 * region-model.h (call_details::get_arg_type): New decl.
9813
9814 2020-09-21 David Malcolm <[email protected]>
9815
9816 PR analyzer/93355
9817 * sm-malloc.cc (malloc_state_machine::get_default_state): Look at
9818 the base region when considering pointers. Treat pointers to
9819 decls as being non-heap.
9820
9821 2020-09-18 David Malcolm <[email protected]>
9822
9823 * checker-path.cc (warning_event::get_desc): Handle global state
9824 changes.
9825
9826 2020-09-18 David Malcolm <[email protected]>
9827
9828 * sm-malloc.cc (malloc_state_machine::on_stmt): Handle strdup and
9829 strndup as being malloc-like allocators.
9830
9831 2020-09-16 David Malcolm <[email protected]>
9832
9833 * engine.cc (strongly_connected_components::strong_connect): Only
9834 consider intraprocedural edges when creating SCCs.
9835 (worklist::key_t::cmp): Add comment. Treat call_string
9836 differences as more important than differences of program_point
9837 within a supernode.
9838
9839 2020-09-16 David Malcolm <[email protected]>
9840
9841 * engine.cc (supernode_cluster::dump_dot): Show the SCC id
9842 in the per-supernode clusters in FILENAME.eg.dot output.
9843 (exploded_graph_annotator::add_node_annotations):
9844 Show the SCC of the supernode in FILENAME.supernode.eg.dot output.
9845 * exploded-graph.h (worklist::scc_id): New.
9846 (exploded_graph::get_scc_id): New.
9847
9848 2020-09-16 David Malcolm <[email protected]>
9849
9850 * engine.cc (exploded_node::dump_dot): Show STATUS_BULK_MERGED.
9851 (exploded_graph::process_worklist): Call
9852 maybe_process_run_of_before_supernode_enodes.
9853 (exploded_graph::maybe_process_run_of_before_supernode_enodes):
9854 New.
9855 (exploded_graph_annotator::print_enode): Show STATUS_BULK_MERGED.
9856 * exploded-graph.h (enum exploded_node::status): Add
9857 STATUS_BULK_MERGED.
9858
9859 2020-09-16 David Malcolm <[email protected]>
9860
9861 * engine.cc
9862 (exploded_graph::process_node) <case PK_BEFORE_SUPERNODE>:
9863 Simplify by using program_point::get_next.
9864 * program-point.cc (program_point::get_next): New.
9865 * program-point.h (program_point::get_next): New decl.
9866
9867 2020-09-16 David Malcolm <[email protected]>
9868
9869 * engine.cc (exploded_graph::get_or_create_node): Show the
9870 program point when issuing -Wanalyzer-too-complex due to hitting
9871 the per-program-point limit.
9872
9873 2020-09-16 David Malcolm <[email protected]>
9874
9875 * region-model.cc (region_model::on_call_pre): Treat getchar as
9876 having no side-effects.
9877
9878 2020-09-15 David Malcolm <[email protected]>
9879
9880 PR analyzer/96650
9881 * constraint-manager.cc (merger_fact_visitor::on_fact): Replace
9882 assertion that add_constraint succeeded with an assertion that
9883 if it fails, -fanalyzer-transitivity is off.
9884
9885 2020-09-14 David Malcolm <[email protected]>
9886
9887 * analyzer.opt (-param=analyzer-max-constraints=): New param.
9888 * constraint-manager.cc
9889 (constraint_manager::add_constraint_internal): Silently reject
9890 attempts to add constraints when the above limit is reached.
9891
9892 2020-09-14 David Malcolm <[email protected]>
9893
9894 PR analyzer/96653
9895 * constraint-manager.cc
9896 (constraint_manager::get_or_add_equiv_class): Don't accumulate
9897 transitive closure of all constraints on constants.
9898
9899 2020-09-14 David Malcolm <[email protected]>
9900
9901 PR analyzer/97029
9902 * analyzer.cc (is_setjmp_call_p): Require the initial arg to be a
9903 pointer.
9904 * region-model.cc (region_model::deref_rvalue): Assert that the
9905 svalue is of pointer type.
9906
9907 2020-09-11 David Malcolm <[email protected]>
9908
9909 PR analyzer/96798
9910 * region-model-impl-calls.cc (region_model::impl_call_memcpy):
9911 New.
9912 (region_model::impl_call_strcpy): New.
9913 * region-model.cc (region_model::on_call_pre): Flag unhandled
9914 builtins that are non-pure as having unknown side-effects.
9915 Implement BUILT_IN_MEMCPY, BUILT_IN_MEMCPY_CHK, BUILT_IN_STRCPY,
9916 BUILT_IN_STRCPY_CHK, BUILT_IN_FPRINTF, BUILT_IN_FPRINTF_UNLOCKED,
9917 BUILT_IN_PUTC, BUILT_IN_PUTC_UNLOCKED, BUILT_IN_FPUTC,
9918 BUILT_IN_FPUTC_UNLOCKED, BUILT_IN_FPUTS, BUILT_IN_FPUTS_UNLOCKED,
9919 BUILT_IN_FWRITE, BUILT_IN_FWRITE_UNLOCKED, BUILT_IN_PRINTF,
9920 BUILT_IN_PRINTF_UNLOCKED, BUILT_IN_PUTCHAR,
9921 BUILT_IN_PUTCHAR_UNLOCKED, BUILT_IN_PUTS, BUILT_IN_PUTS_UNLOCKED,
9922 BUILT_IN_VFPRINTF, BUILT_IN_VPRINTF.
9923 * region-model.h (region_model::impl_call_memcpy): New decl.
9924 (region_model::impl_call_strcpy): New decl.
9925
9926 2020-09-09 David Malcolm <[email protected]>
9927
9928 PR analyzer/94355
9929 * analyzer.opt (Wanalyzer-mismatching-deallocation): New warning.
9930 * region-model-impl-calls.cc
9931 (region_model::impl_call_operator_new): New.
9932 (region_model::impl_call_operator_delete): New.
9933 * region-model.cc (region_model::on_call_pre): Detect operator new
9934 and operator delete.
9935 (region_model::on_call_post): Likewise.
9936 (region_model::maybe_update_for_edge): Detect EH edges and call...
9937 (region_model::apply_constraints_for_exception): New function.
9938 * region-model.h (region_model::impl_call_operator_new): New decl.
9939 (region_model::impl_call_operator_delete): New decl.
9940 (region_model::apply_constraints_for_exception): New decl.
9941 * sm-malloc.cc (enum resource_state): New.
9942 (struct allocation_state): New state subclass.
9943 (enum wording): New.
9944 (struct api): New.
9945 (malloc_state_machine::custom_data_t): New typedef.
9946 (malloc_state_machine::add_state): New decl.
9947 (malloc_state_machine::m_unchecked)
9948 (malloc_state_machine::m_nonnull)
9949 (malloc_state_machine::m_freed): Delete these states in favor
9950 of...
9951 (malloc_state_machine::m_malloc)
9952 (malloc_state_machine::m_scalar_new)
9953 (malloc_state_machine::m_vector_new): ...this new api instances,
9954 which own their own versions of these states.
9955 (malloc_state_machine::on_allocator_call): New decl.
9956 (malloc_state_machine::on_deallocator_call): New decl.
9957 (api::api): New ctor.
9958 (dyn_cast_allocation_state): New.
9959 (as_a_allocation_state): New.
9960 (get_rs): New.
9961 (unchecked_p): New.
9962 (nonnull_p): New.
9963 (freed_p): New.
9964 (malloc_diagnostic::describe_state_change): Use unchecked_p and
9965 nonnull_p.
9966 (class mismatching_deallocation): New.
9967 (double_free::double_free): Add funcname param for initializing
9968 m_funcname.
9969 (double_free::emit): Use m_funcname in warning message rather
9970 than hardcoding "free".
9971 (double_free::describe_state_change): Likewise. Use freed_p.
9972 (double_free::describe_call_with_state): Use freed_p.
9973 (double_free::describe_final_event): Use m_funcname in message
9974 rather than hardcoding "free".
9975 (double_free::m_funcname): New field.
9976 (possible_null::describe_state_change): Use unchecked_p.
9977 (possible_null::describe_return_of_state): Likewise.
9978 (use_after_free::use_after_free): Add param for initializing m_api.
9979 (use_after_free::emit): Use m_api->m_dealloc_funcname in message
9980 rather than hardcoding "free".
9981 (use_after_free::describe_state_change): Use freed_p. Change the
9982 wording of the message based on the API.
9983 (use_after_free::describe_final_event): Use
9984 m_api->m_dealloc_funcname in message rather than hardcoding
9985 "free". Change the wording of the message based on the API.
9986 (use_after_free::m_api): New field.
9987 (malloc_leak::describe_state_change): Use unchecked_p. Update
9988 for renaming of m_malloc_event to m_alloc_event.
9989 (malloc_leak::describe_final_event): Update for renaming of
9990 m_malloc_event to m_alloc_event.
9991 (malloc_leak::m_malloc_event): Rename...
9992 (malloc_leak::m_alloc_event): ...to this.
9993 (free_of_non_heap::free_of_non_heap): Add param for initializing
9994 m_funcname.
9995 (free_of_non_heap::emit): Use m_funcname in message rather than
9996 hardcoding "free".
9997 (free_of_non_heap::describe_final_event): Likewise.
9998 (free_of_non_heap::m_funcname): New field.
9999 (allocation_state::dump_to_pp): New.
10000 (allocation_state::get_nonnull): New.
10001 (malloc_state_machine::malloc_state_machine): Update for changes
10002 to state fields and new api fields.
10003 (malloc_state_machine::add_state): New.
10004 (malloc_state_machine::on_stmt): Move malloc/calloc handling to
10005 on_allocator_call and call it, passing in the API pointer.
10006 Likewise for free, moving it to on_deallocator_call. Handle calls
10007 to operator new and delete in an analogous way. Use unchecked_p
10008 when testing for possibly-null-arg and possibly-null-deref, and
10009 transition to the non-null for the correct API. Remove redundant
10010 node param from call to on_zero_assignment. Use freed_p for
10011 use-after-free check, and pass in API.
10012 (malloc_state_machine::on_allocator_call): New, based on code in
10013 on_stmt.
10014 (malloc_state_machine::on_deallocator_call): Likewise.
10015 (malloc_state_machine::on_phi): Mark node param with
10016 ATTRIBUTE_UNUSED; don't pass it to on_zero_assignment.
10017 (malloc_state_machine::on_condition): Mark node param with
10018 ATTRIBUTE_UNUSED. Replace on_transition calls with get_state and
10019 set_next_state pairs, transitioning to the non-null state for the
10020 appropriate API.
10021 (malloc_state_machine::can_purge_p): Port to new state approach.
10022 (malloc_state_machine::on_zero_assignment): Replace on_transition
10023 calls with get_state and set_next_state pairs. Drop redundant
10024 node param.
10025 * sm.h (state_machine::add_custom_state): New.
10026
10027 2020-09-09 David Malcolm <[email protected]>
10028
10029 * diagnostic-manager.cc
10030 (null_assignment_sm_context::warn_for_state): Replace with...
10031 (null_assignment_sm_context::warn): ...this.
10032 * engine.cc (impl_sm_context::warn_for_state): Replace with...
10033 (impl_sm_context::warn): ...this.
10034 * sm-file.cc (fileptr_state_machine::on_stmt): Replace
10035 warn_for_state and on_transition calls with a get_state
10036 test guarding warn and set_next_state calls.
10037 * sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
10038 * sm-pattern-test.cc (pattern_test_state_machine::on_condition):
10039 Replace warn_for_state call with warn call.
10040 * sm-sensitive.cc
10041 (sensitive_state_machine::warn_for_any_exposure): Replace
10042 warn_for_state call with a get_state test guarding a warn call.
10043 * sm-signal.cc (signal_state_machine::on_stmt): Likewise.
10044 * sm-taint.cc (taint_state_machine::on_stmt): Replace
10045 warn_for_state and on_transition calls with a get_state
10046 test guarding warn and set_next_state calls.
10047 * sm.h (sm_context::warn_for_state): Replace with...
10048 (sm_context::warn): ...this.
10049
10050 2020-09-09 David Malcolm <[email protected]>
10051
10052 * diagnostic-manager.cc
10053 (null_assignment_sm_context::null_assignment_sm_context): Add old_state
10054 and ext_state params, initializing m_old_state and m_ext_state.
10055 (null_assignment_sm_context::on_transition): Split into...
10056 (null_assignment_sm_context::get_state): ...this new vfunc
10057 implementation and...
10058 (null_assignment_sm_context::set_next_state): ...this new vfunc
10059 implementation.
10060 (null_assignment_sm_context::m_old_state): New field.
10061 (null_assignment_sm_context::m_ext_state): New field.
10062 (diagnostic_manager::add_events_for_eedge): Pass in old state and
10063 ext_state when creating sm_ctxt.
10064 * engine.cc (impl_sm_context::on_transition): Split into...
10065 (impl_sm_context::get_state): ...this new vfunc
10066 implementation and...
10067 (impl_sm_context::set_next_state): ...this new vfunc
10068 implementation.
10069 * sm.h (sm_context::get_state): New pure virtual function.
10070 (sm_context::set_next_state): Likewise.
10071 (sm_context::on_transition): Convert from a pure virtual function
10072 to a regular function implemented in terms of get_state and
10073 set_next_state.
10074
10075 2020-09-09 David Malcolm <[email protected]>
10076
10077 * checker-path.cc (state_change_event::get_desc): Update
10078 state_machine::get_state_name calls to state::get_name.
10079 (warning_event::get_desc): Likewise.
10080 * diagnostic-manager.cc
10081 (null_assignment_sm_context::on_transition): Update comparison
10082 against 0 with comparison with m_sm.get_start_state.
10083 (diagnostic_manager::prune_for_sm_diagnostic): Update
10084 state_machine::get_state_name calls to state::get_name.
10085 * engine.cc (impl_sm_context::on_transition): Likewise.
10086 (exploded_node::get_dot_fillcolor): Use get_id when summing
10087 the sm states.
10088 * program-state.cc (sm_state_map::sm_state_map): Don't hardcode
10089 0 as the start state when initializing m_global_state.
10090 (sm_state_map::print): Use dump_to_pp rather than get_state_name
10091 when dumping states.
10092 (sm_state_map::is_empty_p): Don't hardcode 0 as the start state
10093 when examining m_global_state.
10094 (sm_state_map::hash): Use get_id when hashing states.
10095 (selftest::test_sm_state_map): Use state objects rather than
10096 arbitrary hardcoded integers.
10097 (selftest::test_program_state_merging): Likewise.
10098 (selftest::test_program_state_merging_2): Likewise.
10099 * sm-file.cc (fileptr_state_machine::m_start): Move to base class.
10100 (file_diagnostic::describe_state_change): Use get_start_state.
10101 (fileptr_state_machine::fileptr_state_machine): Drop m_start
10102 initialization.
10103 * sm-malloc.cc (malloc_state_machine::m_start): Move to base
10104 class.
10105 (malloc_diagnostic::describe_state_change): Use get_start_state.
10106 (possible_null::describe_state_change): Likewise.
10107 (malloc_state_machine::malloc_state_machine): Drop m_start
10108 initialization.
10109 * sm-pattern-test.cc (pattern_test_state_machine::m_start): Move
10110 to base class.
10111 (pattern_test_state_machine::pattern_test_state_machine): Drop
10112 m_start initialization.
10113 * sm-sensitive.cc (sensitive_state_machine::m_start): Move to base
10114 class.
10115 (sensitive_state_machine::sensitive_state_machine): Drop m_start
10116 initialization.
10117 * sm-signal.cc (signal_state_machine::m_start): Move to base
10118 class.
10119 (signal_state_machine::signal_state_machine): Drop m_start
10120 initialization.
10121 * sm-taint.cc (taint_state_machine::m_start): Move to base class.
10122 (taint_state_machine::taint_state_machine): Drop m_start
10123 initialization.
10124 * sm.cc (state_machine::state::dump_to_pp): New.
10125 (state_machine::state_machine): Move here from sm.h. Initialize
10126 m_next_state_id and m_start.
10127 (state_machine::add_state): Reimplement in terms of state objects.
10128 (state_machine::get_state_name): Delete.
10129 (state_machine::get_state_by_name): Reimplement in terms of state
10130 objects. Make const.
10131 (state_machine::validate): Delete.
10132 (state_machine::dump_to_pp): Reimplement in terms of state
10133 objects.
10134 * sm.h (state_machine::state): New class.
10135 (state_machine::state_t): Convert typedef from "unsigned" to
10136 "const state_machine::state *".
10137 (state_machine::state_machine): Move to sm.cc.
10138 (state_machine::get_default_state): Use m_start rather than
10139 hardcoding 0.
10140 (state_machine::get_state_name): Delete.
10141 (state_machine::get_state_by_name): Make const.
10142 (state_machine::get_start_state): New accessor.
10143 (state_machine::alloc_state_id): New.
10144 (state_machine::m_state_names): Drop in favor of...
10145 (state_machine::m_states): New field
10146 (state_machine::m_start): New field
10147 (start_start_p): Delete.
10148
10149 2020-09-08 David Malcolm <[email protected]>
10150
10151 PR analyzer/96949
10152 * store.cc (binding_map::apply_ctor_val_to_range): Add
10153 error-handling for the cases where we have symbolic offsets.
10154
10155 2020-09-08 David Malcolm <[email protected]>
10156
10157 PR analyzer/96950
10158 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
10159 where min_index == max_index.
10160 (binding_map::apply_ctor_val_to_range): Replace assertion that we
10161 don't have a CONSTRUCTOR value with error-handling.
10162
10163 2020-09-08 David Malcolm <[email protected]>
10164
10165 PR analyzer/96962
10166 * region-model.cc (region_model::on_call_pre): Fix guard on switch
10167 on built-ins to only consider BUILT_IN_NORMAL, rather than other
10168 kinds of build-ins.
10169
10170 2020-09-01 David Malcolm <[email protected]>
10171
10172 PR analyzer/96792
10173 * region-model.cc (region_model::deref_rvalue): Add the constraint
10174 that PTR_SVAL is non-NULL.
10175
10176 2020-08-31 David Malcolm <[email protected]>
10177
10178 PR analyzer/96798
10179 * region-model.cc (region_model::on_call_pre): Handle
10180 BUILT_IN_MEMSET_CHK.
10181
10182 2020-08-31 David Malcolm <[email protected]>
10183
10184 * region-model.cc (region_model::on_call_pre): Gather handling of
10185 builtins and of internal fns into switch statements. Handle
10186 "alloca" and BUILT_IN_ALLOCA_WITH_ALIGN.
10187
10188 2020-08-31 David Malcolm <[email protected]>
10189
10190 PR analyzer/96860
10191 * region.cc (decl_region::get_svalue_for_constructor): Support
10192 apply_ctor_to_region failing.
10193 * store.cc (binding_map::apply_ctor_to_region): Add failure
10194 handling.
10195 (binding_map::apply_ctor_val_to_range): Likewise.
10196 (binding_map::apply_ctor_pair_to_child_region): Likewise. Replace
10197 assertion that child_base_offset is not symbolic with error
10198 handling.
10199 * store.h (binding_map::apply_ctor_to_region): Convert return type
10200 from void to bool.
10201 (binding_map::apply_ctor_val_to_range): Likewise.
10202 (binding_map::apply_ctor_pair_to_child_region): Likewise.
10203
10204 2020-08-31 David Malcolm <[email protected]>
10205
10206 PR analyzer/96763
10207 * store.cc (binding_map::apply_ctor_to_region): Handle RANGE_EXPR
10208 by calling a new binding_map::apply_ctor_val_to_range subroutine.
10209 Split out the existing non-CONSTRUCTOR-handling code to a new
10210 apply_ctor_pair_to_child_region subroutine.
10211 (binding_map::apply_ctor_val_to_range): New.
10212 (binding_map::apply_ctor_pair_to_child_region): New, split out
10213 from binding_map::apply_ctor_to_region as noted above.
10214 * store.h (binding_map::apply_ctor_val_to_range): New decl.
10215 (binding_map::apply_ctor_pair_to_child_region): New decl.
10216
10217 2020-08-31 David Malcolm <[email protected]>
10218
10219 PR analyzer/96764
10220 * region-model-manager.cc
10221 (region_model_manager::maybe_fold_unaryop): Handle VIEW_CONVERT_EXPR.
10222 (region_model_manager::get_or_create_cast): Move logic for
10223 real->integer casting to...
10224 (get_code_for_cast): ...this new function, and add logic for
10225 real->non-integer casts.
10226 (region_model_manager::maybe_fold_sub_svalue): Handle
10227 VIEW_CONVERT_EXPR.
10228 * region-model.cc
10229 (region_model::add_any_constraints_from_gassign): Likewise.
10230 * svalue.cc (svalue::maybe_undo_cast): Likewise.
10231 (unaryop_svalue::dump_to_pp): Likewise.
10232
10233 2020-08-26 David Malcolm <[email protected]>
10234
10235 PR analyzer/94858
10236 * region-model-manager.cc
10237 (region_model_manager::get_or_create_widening_svalue): Assert that
10238 neither of the inputs are themselves widenings.
10239 * store.cc (store::eval_alias_1): The initial value of a pointer
10240 can't point to a region that was allocated on the heap after the
10241 beginning of the path. A widened pointer value can't alias anything
10242 that the initial pointer value can't alias.
10243 * svalue.cc (svalue::can_merge_p): Merge BINOP (X, OP, CST) with X
10244 to a widening svalue. Merge
10245 BINOP(WIDENING(BASE, BINOP(BASE, X)), X) and BINOP(BASE, X) to
10246 to the LHS of the first BINOP.
10247
10248 2020-08-26 David Malcolm <[email protected]>
10249
10250 PR analyzer/96777
10251 * region-model.h (class compound_svalue): Document that all keys
10252 must be concrete.
10253 (compound_svalue::compound_svalue): Move definition to svalue.cc.
10254 * store.cc (binding_map::apply_ctor_to_region): Handle
10255 initializers for trailing arrays with incomplete size.
10256 * svalue.cc (compound_svalue::compound_svalue): Move definition
10257 here from region-model.h. Add assertion that all keys are
10258 concrete.
10259
10260 2020-08-22 David Malcolm <[email protected]>
10261
10262 PR analyzer/94851
10263 * region-model-manager.cc
10264 (region_model_manager::maybe_fold_binop): Fold bitwise "& 0" to 0.
10265
10266 2020-08-22 David Malcolm <[email protected]>
10267
10268 * store.cc (store::eval_alias): Make const. Split out 2nd half
10269 into store::eval_alias_1 and call it twice for symmetry, avoiding
10270 test duplication.
10271 (store::eval_alias_1): New function, split out from the above.
10272 * store.h (store::eval_alias): Make const.
10273 (store::eval_alias_1): New decl.
10274
10275 2020-08-22 David Malcolm <[email protected]>
10276
10277 * region-model.cc (region_model::push_frame): Bind the default
10278 SSA name for each parm if it exists, falling back to the parm
10279 itself otherwise, rather than doing both.
10280
10281 2020-08-20 David Malcolm <[email protected]>
10282
10283 PR analyzer/96723
10284 * region-model-manager.cc
10285 (region_model_manager::get_field_region): Assert that field is a
10286 FIELD_DECL.
10287 * region.cc (region::get_subregions_for_binding): In
10288 union-handling, filter the TYPE_FIELDS traversal to just FIELD_DECLs.
10289
10290 2020-08-20 David Malcolm <[email protected]>
10291
10292 PR analyzer/96713
10293 * region-model.cc (region_model::get_gassign_result): For
10294 comparisons, only use eval_condition when the lhs has boolean
10295 type, and use get_or_create_constant_svalue on the boolean
10296 constants directly rather than via get_rvalue.
10297
10298 2020-08-19 David Malcolm <[email protected]>
10299
10300 PR analyzer/96643
10301 * region-model.cc (region_model::deref_rvalue): Rather than
10302 attempting to handle all svalue kinds in the switch, only cover
10303 the special cases, and move symbolic-region handling to after
10304 the switch, thus implicitly handling the missing case SK_COMPOUND.
10305
10306 2020-08-19 David Malcolm <[email protected]>
10307
10308 PR analyzer/96705
10309 * region-model-manager.cc
10310 (region_model_manager::maybe_fold_binop): Check that we have an
10311 integral type before calling build_int_cst.
10312
10313 2020-08-19 David Malcolm <[email protected]>
10314
10315 PR analyzer/96699
10316 * region-model-manager.cc
10317 (region_model_manager::get_or_create_cast): Use FIX_TRUNC_EXPR for
10318 casting from REAL_TYPE to INTEGER_TYPE.
10319
10320 2020-08-19 David Malcolm <[email protected]>
10321
10322 PR analyzer/96651
10323 * region-model.cc (region_model::called_from_main_p): New.
10324 (region_model::get_store_value): Move handling for globals into...
10325 (region_model::get_initial_value_for_global): ...this new
10326 function, and add logic for extracting values from decl
10327 initializers.
10328 * region-model.h (decl_region::get_svalue_for_constructor): New
10329 decl.
10330 (decl_region::get_svalue_for_initializer): New decl.
10331 (region_model::called_from_main_p): New decl.
10332 (region_model::get_initial_value_for_global): New.
10333 * region.cc (decl_region::maybe_get_constant_value): Move logic
10334 for getting an svalue from a CONSTRUCTOR node to...
10335 (decl_region::get_svalue_for_constructor): ...this new function.
10336 (decl_region::get_svalue_for_initializer): New.
10337 * store.cc (get_svalue_for_ctor_val): Rewrite in terms of
10338 region_model::get_rvalue.
10339 * store.h (binding_cluster::get_map): New accessor.
10340
10341 2020-08-19 David Malcolm <[email protected]>
10342
10343 PR analyzer/96648
10344 * region.cc (get_field_at_bit_offset): Gracefully handle negative
10345 values for bit_offset.
10346
10347 2020-08-18 David Malcolm <[email protected]>
10348
10349 * region-model.cc (region_model::get_rvalue_1): Fix name of local.
10350
10351 2020-08-18 David Malcolm <[email protected]>
10352
10353 PR analyzer/96641
10354 * region-model.cc (region_model::get_rvalue_1): Handle
10355 unrecognized tree codes by returning "UNKNOWN.
10356
10357 2020-08-18 David Malcolm <[email protected]>
10358
10359 PR analyzer/96640
10360 * region-model.cc (region_model::get_gassign_result): Handle various
10361 VEC_* tree codes by returning UNKNOWN.
10362 (region_model::on_assignment): Handle unrecognized tree codes by
10363 setting lhs to an unknown value, rather than issuing a "sorry" and
10364 asserting.
10365
10366 2020-08-17 David Malcolm <[email protected]>
10367
10368 PR analyzer/96644
10369 * region-model-manager.cc (get_region_for_unexpected_tree_code):
10370 Handle ctxt being NULL.
10371
10372 2020-08-17 David Malcolm <[email protected]>
10373
10374 PR analyzer/96639
10375 * region.cc (region::get_subregions_for_binding): Check for "type"
10376 being NULL.
10377
10378 2020-08-17 David Malcolm <[email protected]>
10379
10380 PR analyzer/96642
10381 * store.cc (get_svalue_for_ctor_val): New.
10382 (binding_map::apply_ctor_to_region): Call it.
10383
10384 2020-08-14 David Malcolm <[email protected]>
10385
10386 PR testsuite/96609
10387 PR analyzer/96616
10388 * region-model.cc (region_model::get_store_value): Call
10389 maybe_get_constant_value on decl_regions first.
10390 * region-model.h (decl_region::maybe_get_constant_value): New decl.
10391 * region.cc (decl_region::get_stack_depth): Likewise.
10392 (decl_region::maybe_get_constant_value): New.
10393 * store.cc (get_subregion_within_ctor): New.
10394 (binding_map::apply_ctor_to_region): New.
10395 * store.h (binding_map::apply_ctor_to_region): New decl.
10396
10397 2020-08-14 David Malcolm <[email protected]>
10398
10399 PR analyzer/96611
10400 * store.cc (store::mark_as_escaped): Reject attempts to
10401 get a cluster for an unknown pointer.
10402
10403 2020-08-13 David Malcolm <[email protected]>
10404
10405 PR analyzer/93032
10406 PR analyzer/93938
10407 PR analyzer/94011
10408 PR analyzer/94099
10409 PR analyzer/94399
10410 PR analyzer/94458
10411 PR analyzer/94503
10412 PR analyzer/94640
10413 PR analyzer/94688
10414 PR analyzer/94689
10415 PR analyzer/94839
10416 PR analyzer/95026
10417 PR analyzer/95042
10418 PR analyzer/95240
10419 * analyzer-logging.cc: Ignore "-Wformat-diag".
10420 (logger::enter_scope): Use inc_indent in both overloads.
10421 (logger::exit_scope): Use dec_indent.
10422 * analyzer-logging.h (logger::inc_indent): New.
10423 (logger::dec_indent): New.
10424 * analyzer-selftests.cc (run_analyzer_selftests): Call
10425 analyzer_store_cc_tests.
10426 * analyzer-selftests.h (analyzer_store_cc_tests): New decl.
10427 * analyzer.cc (get_stmt_location): New function.
10428 * analyzer.h (class initial_svalue): New forward decl.
10429 (class unaryop_svalue): New forward decl.
10430 (class binop_svalue): New forward decl.
10431 (class sub_svalue): New forward decl.
10432 (class unmergeable_svalue): New forward decl.
10433 (class placeholder_svalue): New forward decl.
10434 (class widening_svalue): New forward decl.
10435 (class compound_svalue): New forward decl.
10436 (class conjured_svalue): New forward decl.
10437 (svalue_set): New typedef.
10438 (class map_region): Delete.
10439 (class array_region): Delete.
10440 (class frame_region): New forward decl.
10441 (class function_region): New forward decl.
10442 (class label_region): New forward decl.
10443 (class decl_region): New forward decl.
10444 (class element_region): New forward decl.
10445 (class offset_region): New forward decl.
10446 (class cast_region): New forward decl.
10447 (class field_region): New forward decl.
10448 (class string_region): New forward decl.
10449 (class region_model_manager): New forward decl.
10450 (class store_manager): New forward decl.
10451 (class store): New forward decl.
10452 (class call_details): New forward decl.
10453 (struct svalue_id_merger_mapping): Delete.
10454 (struct canonicalization): Delete.
10455 (class function_point): New forward decl.
10456 (class engine): New forward decl.
10457 (dump_tree): New function decl.
10458 (print_quoted_type): New function decl.
10459 (readability_comparator): New function decl.
10460 (tree_cmp): New function decl.
10461 (class path_var): Move here from region-model.h
10462 (bit_offset_t, bit_size_t, byte_size_t): New typedefs.
10463 (class region_offset): New class.
10464 (get_stmt_location): New decl.
10465 (struct member_function_hash_traits): New struct.
10466 (class consolidation_map): New class.
10467 Ignore "-Wformat-diag".
10468 * analyzer.opt (-param=analyzer-max-svalue-depth=): New param.
10469 (-param=analyzer-max-enodes-for-full-dump=): New param.
10470 * call-string.cc: Ignore -Wformat-diag.
10471 * checker-path.cc: Move includes of "analyzer/call-string.h" and
10472 "analyzer/program-point.h" to before "analyzer/region-model.h",
10473 and also include "analyzer/store.h" before it.
10474 (state_change_event::state_change_event): Replace "tree var" param
10475 with "const svalue *sval". Convert "origin" param from tree to
10476 "const svalue *".
10477 (state_change_event::get_desc): Call get_representative_tree to
10478 convert the var and origin from const svalue * to tree. Use
10479 svalue::get_desc rather than %qE when describing state changes.
10480 (checker_path::add_final_event): Use get_stmt_location.
10481 * checker-path.h (state_change_event::state_change_event): Port
10482 from tree to const svalue *.
10483 (state_change_event::get_lvalue): Delete.
10484 (state_change_event::get_dest_function): New.
10485 (state_change_event::m_var): Replace with...
10486 (state_change_event::m_sval): ...this.
10487 (state_change_event::m_origin): Convert from tree to
10488 const svalue *.
10489 * constraint-manager.cc: Include "analyzer/call-string.h",
10490 "analyzer/program-point.h", and "analyzer/store.h" before
10491 "analyzer/region-model.h".
10492 (struct bound, struct range): Move to constraint-manager.h.
10493 (compare_constants): New function.
10494 (range::dump): Rename to...
10495 (range::dump_to_pp): ...this. Support NULL constants.
10496 (range::dump): Reintroduce for dumping to stderr.
10497 (range::constrained_to_single_element): Return result, rather than
10498 writing to *OUT.
10499 (range::eval_condition): New.
10500 (range::below_lower_bound): New.
10501 (range::above_upper_bound): New.
10502 (equiv_class::equiv_class): Port from svalue_id to const svalue *.
10503 (equiv_class::print): Likewise.
10504 (equiv_class::hash): Likewise.
10505 (equiv_class::operator==): Port from svalue_id to const svalue *.
10506 (equiv_class::add): Port from svalue_id to const svalue *. Drop
10507 "cm" param.
10508 (equiv_class::del): Port from svalue_id to const svalue *.
10509 (equiv_class::get_representative): Likewise.
10510 (equiv_class::remap_svalue_ids): Delete.
10511 (svalue_id_cmp_by_id): Rename to...
10512 (svalue_cmp_by_ptr): ...this, porting from svalue_id to
10513 const svalue *.
10514 (equiv_class::canonicalize): Update qsort comparator.
10515 (constraint::implied_by): New.
10516 (constraint_manager::constraint_manager): Copy m_mgr in copy ctor.
10517 (constraint_manager::dump_to_pp): Add "multiline" param
10518 (constraint_manager::dump): Pass "true" for "multiline".
10519 (constraint_manager::add_constraint): Port from svalue_id to
10520 const svalue *. Split out second part into...
10521 (constraint_manager::add_unknown_constraint): ...this new
10522 function. Remove self-constraints when merging equivalence
10523 classes.
10524 (constraint_manager::add_constraint_internal): Remove constraints
10525 that would be implied by the new constraint. Port from svalue_id
10526 to const svalue *.
10527 (constraint_manager::get_equiv_class_by_sid): Rename to...
10528 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
10529 from svalue_id to const svalue *.
10530 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
10531 to const svalue *.
10532 (constraint_manager::eval_condition): Make const. Call
10533 compare_constants and return early if it provides a known result.
10534 (constraint_manager::get_ec_bounds): New.
10535 (constraint_manager::eval_condition): New overloads. Make
10536 existing one const, and use compare_constants.
10537 (constraint_manager::purge): Convert "p" param to a template
10538 rather that an abstract base class. Port from svalue_id to
10539 const svalue *.
10540 (class dead_svalue_purger): New class.
10541 (constraint_manager::remap_svalue_ids): Delete.
10542 (constraint_manager::on_liveness_change): New.
10543 (equiv_class_cmp): Port from svalue_id to const svalue *.
10544 (constraint_manager::canonicalize): Likewise. Combine with
10545 purging of redundant equivalence classes and constraints.
10546 (class cleaned_constraint_manager): Delete.
10547 (class merger_fact_visitor): Make "m_cm_b" const. Add "m_merger"
10548 field.
10549 (merger_fact_visitor::fact): Port from svalue_id to const svalue *.
10550 Add special case for widening.
10551 (constraint_manager::merge): Port from svalue_id to const svalue *.
10552 (constraint_manager::clean_merger_input): Delete.
10553 (constraint_manager::for_each_fact): Port from svalue_id to
10554 const svalue *.
10555 (constraint_manager::validate): Likewise.
10556 (selftest::test_constraint_conditions): Provide a
10557 region_model_manager when creating region_model instances.
10558 Add test for self-equality not creating equivalence classes.
10559 (selftest::test_transitivity): Provide a region_model_manager when
10560 creating region_model instances. Verify that EC-merging happens
10561 when constraints are implied.
10562 (selftest::test_constant_comparisons): Provide a
10563 region_model_manager when creating region_model instances.
10564 (selftest::test_constraint_impl): Likewise. Remove over-specified
10565 assertions.
10566 (selftest::test_equality): Provide a region_model_manager when
10567 creating region_model instances.
10568 (selftest::test_many_constants): Likewise. Provide a
10569 program_point when testing merging.
10570 (selftest::run_constraint_manager_tests): Move call to
10571 test_constant_comparisons to outside the transitivity guard.
10572 * constraint-manager.h (struct bound): Move here from
10573 constraint-manager.cc.
10574 (struct range): Likewise.
10575 (struct::eval_condition): New decl.
10576 (struct::below_lower_bound): New decl.
10577 (struct::above_upper_bound): New decl.
10578 (equiv_class::add): Port from svalue_id to const svalue *.
10579 (equiv_class::del): Likewise.
10580 (equiv_class::get_representative): Likewise.
10581 (equiv_class::remap_svalue_ids): Drop.
10582 (equiv_class::m_cst_sid): Convert to..
10583 (equiv_class::m_cst_sval): ...this.
10584 (equiv_class::m_vars): Port from svalue_id to const svalue *.
10585 (constraint::bool implied_by): New decl.
10586 (fact_visitor::on_fact): Port from svalue_id to const svalue *.
10587 (constraint_manager::constraint_manager): Add mgr param.
10588 (constraint_manager::clone): Delete.
10589 (constraint_manager::maybe_get_constant): Delete.
10590 (constraint_manager::get_sid_for_constant): Delete.
10591 (constraint_manager::get_num_svalues): Delete.
10592 (constraint_manager::dump_to_pp): Add "multiline" param.
10593 (constraint_manager::get_equiv_class): Port from svalue_id to
10594 const svalue *.
10595 (constraint_manager::add_constraint): Likewise.
10596 (constraint_manager::get_equiv_class_by_sid): Rename to...
10597 (constraint_manager::get_equiv_class_by_svalue): ...this, porting
10598 from svalue_id to const svalue *.
10599 (constraint_manager::add_unknown_constraint): New decl.
10600 (constraint_manager::get_or_add_equiv_class): Port from svalue_id
10601 to const svalue *.
10602 (constraint_manager::eval_condition): Likewise. Add overloads.
10603 (constraint_manager::get_ec_bounds): New decl.
10604 (constraint_manager::purge): Convert to template.
10605 (constraint_manager::remap_svalue_ids): Delete.
10606 (constraint_manager::on_liveness_change): New decl.
10607 (constraint_manager::canonicalize): Drop param.
10608 (constraint_manager::clean_merger_input): Delete.
10609 (constraint_manager::m_mgr): New field.
10610 * diagnostic-manager.cc: Move includes of
10611 "analyzer/call-string.h" and "analyzer/program-point.h" to before
10612 "analyzer/region-model.h", and also include "analyzer/store.h"
10613 before it.
10614 (saved_diagnostic::saved_diagnostic): Add "sval" param.
10615 (diagnostic_manager::diagnostic_manager): Add engine param.
10616 (diagnostic_manager::add_diagnostic): Add "sval" param, passing it
10617 to saved_diagnostic ctor. Update overload to pass NULL for it.
10618 (dedupe_winners::dedupe_winners): Add engine param.
10619 (dedupe_winners::add): Add "eg" param. Pass m_engine to
10620 feasible_p.
10621 (dedupe_winner::m_engine): New field.
10622 (diagnostic_manager::emit_saved_diagnostics): Pass engine to
10623 dedupe_winners. Pass &eg when adding candidates. Pass svalue
10624 rather than tree to prune_path. Use get_stmt_location to get
10625 primary location of diagnostic.
10626 (diagnostic_manager::emit_saved_diagnostic): Likewise.
10627 (get_any_origin): Drop.
10628 (state_change_event_creator::on_global_state_change): Pass NULL
10629 const svalue * rather than NULL_TREE trees to state_change_event
10630 ctor.
10631 (state_change_event_creator::on_state_change): Port from tree and
10632 svalue_id to const svalue *.
10633 (for_each_state_change): Port from svalue_id to const svalue *.
10634 (struct null_assignment_sm_context): New.
10635 (diagnostic_manager::add_events_for_eedge): Add state change
10636 events for assignment to NULL.
10637 (diagnostic_manager::prune_path): Update param from tree to
10638 const svalue *.
10639 (diagnostic_manager::prune_for_sm_diagnostic): Port from tracking
10640 by tree to by const svalue *.
10641 * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Add sval
10642 param.
10643 (saved_diagnostic::m_sval): New field.
10644 (diagnostic_manager::diagnostic_manager): Add engine param.
10645 (diagnostic_manager::get_engine): New.
10646 (diagnostic_manager::add_diagnostic): Add "sval" param.
10647 (diagnostic_manager::prune_path): Likewise.
10648 (diagnostic_manager::prune_for_sm_diagnostic): New overload.
10649 (diagnostic_manager::m_eng): New field.
10650 * engine.cc: Move includes of "analyzer/call-string.h" and
10651 "analyzer/program-point.h" to before "analyzer/region-model.h",
10652 and also include "analyzer/store.h" before it.
10653 (impl_region_model_context::impl_region_model_context): Update for
10654 removal of m_change field.
10655 (impl_region_model_context::remap_svalue_ids): Delete.
10656 (impl_region_model_context::on_svalue_leak): New.
10657 (impl_region_model_context::on_svalue_purge): Delete.
10658 (impl_region_model_context::on_liveness_change): New.
10659 (impl_region_model_context::on_unknown_change): Update param
10660 from svalue_id to const svalue *. Add is_mutable param.
10661 (setjmp_svalue::compare_fields): Delete.
10662 (setjmp_svalue::accept): New.
10663 (setjmp_svalue::add_to_hash): Delete.
10664 (setjmp_svalue::dump_to_pp): New.
10665 (setjmp_svalue::print_details): Delete.
10666 (impl_sm_context::impl_sm_context): Drop "change" param.
10667 (impl_sm_context::get_fndecl_for_call): Drop "m_change".
10668 (impl_sm_context::on_transition): Drop ATTRIBUTE_UNUSED from
10669 "stmt" param. Drop m_change. Port from svalue_id to
10670 const svalue *.
10671 (impl_sm_context::warn_for_state): Drop m_change. Port from
10672 svalue_id to const svalue *.
10673 (impl_sm_context::get_readable_tree): Rename to...
10674 (impl_sm_context::get_diagnostic_tree): ...this. Port from
10675 svalue_id to const svalue *.
10676 (impl_sm_context::is_zero_assignment): New.
10677 (impl_sm_context::m_change): Delete field.
10678 (leak_stmt_finder::find_stmt): Handle m_var being NULL.
10679 (readability): Increase penalty for MEM_REF. For SSA_NAMEs,
10680 slightly favor the underlying var over the SSA name. Heavily
10681 penalize temporaries. Handle RESULT_DECL.
10682 (readability_comparator): Make non-static. Consider stack depths.
10683 (impl_region_model_context::on_state_leak): Convert from svalue_id
10684 to const svalue *, updating for region_model changes. Use
10685 id_equal.
10686 (impl_region_model_context::on_inherited_svalue): Delete.
10687 (impl_region_model_context::on_cast): Delete.
10688 (impl_region_model_context::on_condition): Drop m_change.
10689 (impl_region_model_context::on_phi): Likewise.
10690 (impl_region_model_context::on_unexpected_tree_code): Handle t
10691 being NULL.
10692 (point_and_state::validate): Update stack checking for
10693 region_model changes.
10694 (eg_traits::dump_args_t::show_enode_details_p): New.
10695 (exploded_node::exploded_node): Initialize m_num_processed_stmts.
10696 (exploded_node::get_processed_stmt): New function.
10697 (exploded_node::get_dot_fillcolor): Add more colors.
10698 (exploded_node::dump_dot): Guard the printing of the point and
10699 state with show_enode_details_p. Print the processed stmts for
10700 this enode after the initial state.
10701 (exploded_node::dump_to_pp): Pass true for new multiline param
10702 of program_state::dump_to_pp.
10703 (exploded_node::on_stmt): Drop "change" param. Log the stmt.
10704 Set input_location. Implement __analyzer_describe. Update
10705 implementation of __analyzer_dump and __analyzer_eval.
10706 Remove purging of sm-state for unknown fncalls from here.
10707 (exploded_node::on_edge): Drop "change" param.
10708 (exploded_node::on_longjmp): Port from region_id/svalue_id to
10709 const region */const svalue *. Call program_state::detect_leaks.
10710 Drop state_change.
10711 (exploded_node::detect_leaks): Update for changes to region_model.
10712 Call program_state::detect_leaks.
10713 (exploded_edge::exploded_edge): Drop ext_state and change params.
10714 (exploded_edge::dump_dot): "args" is no longer used. Drop dumping
10715 of m_change.
10716 (exploded_graph::exploded_graph): Pass engine to
10717 m_diagnostic_manager ctor. Use program_point::origin.
10718 (exploded_graph::add_function_entry): Drop ctxt. Use
10719 program_state::push_frame. Drop state_change.
10720 (exploded_graph::get_or_create_node): Drop "change" param. Add
10721 "enode_for_diag" param. Update dumping calls for API changes.
10722 Pass point to can_merge_with_p. Show enode indices
10723 within -Wanalyzer-too-complex diagnostic for hitting the per-point
10724 limit.
10725 (exploded_graph::add_edge): Drop "change" param. Log which nodes
10726 are being connected. Update for changes to exploded_edge ctor.
10727 (exploded_graph::get_per_program_point_data): New.
10728 (exploded_graph::process_worklist): Pass point to
10729 can_merge_with_p. Drop state_change. Update dumping call for API
10730 change.
10731 (exploded_graph::process_node): Drop state_change. Split the
10732 node in-place if an sm-state-change occurs. Update
10733 m_num_processed_stmts. Update dumping calls for API change.
10734 (exploded_graph::log_stats): Call engine::log_stats.
10735 (exploded_graph::dump_states_for_supernode): Update dumping
10736 call.
10737 (exploded_path::feasible_p): Add "eng" and "eg" params.
10738 Rename "i" to "end_idx". Pass the manager to the region_model
10739 ctor. Update for every processed stmt in the enode, not just the
10740 first. Keep track of which snodes have been visited, and call
10741 loop_replay_fixup when revisiting one.
10742 (enode_label::get_text): Update dump call for new param.
10743 (exploded_graph::dump_exploded_nodes): Likewise.
10744 (exploded_graph::get_node_by_index): New.
10745 (impl_run_checkers): Create engine instance and pass its address
10746 to extrinsic_state ctor.
10747 * exploded-graph.h
10748 (impl_region_model_context::impl_region_model_context): Drop
10749 "change" params.
10750 (impl_region_model_context::void remap_svalue_ids): Delete.
10751 (impl_region_model_context::on_svalue_purge): Delete.
10752 (impl_region_model_context::on_svalue_leak): New.
10753 (impl_region_model_context::on_liveness_change): New.
10754 (impl_region_model_context::on_state_leak): Update signature.
10755 (impl_region_model_context::on_inherited_svalue): Delete.
10756 (impl_region_model_context::on_cast): Delete.
10757 (impl_region_model_context::on_unknown_change): Update signature.
10758 (impl_region_model_context::m_change): Delete.
10759 (eg_traits::dump_args_t::show_enode_details_p): New.
10760 (exploded_node::on_stmt): Drop "change" param.
10761 (exploded_node::on_edge): Likewise.
10762 (exploded_node::get_processed_stmt): New decl.
10763 (exploded_node::m_num_processed_stmts): New field.
10764 (exploded_edge::exploded_edge): Drop ext_state and change params.
10765 (exploded_edge::m_change): Delete.
10766 (exploded_graph::get_engine): New accessor.
10767 (exploded_graph::get_or_create_node): Drop "change" param. Add
10768 "enode_for_diag" param.
10769 (exploded_graph::add_edge): Drop "change" param.
10770 (exploded_graph::get_per_program_point_data): New decl.
10771 (exploded_graph::get_node_by_index): New decl.
10772 (exploded_path::feasible_p): Add "eng" and "eg" params.
10773 * program-point.cc: Include "analyzer/store.h" before including
10774 "analyzer/region-model.h".
10775 (function_point::function_point): Move here from
10776 program-point.h.
10777 (function_point::get_function): Likewise.
10778 (function_point::from_function_entry): Likewise.
10779 (function_point::before_supernode): Likewise.
10780 (function_point::next_stmt): New function.
10781 * program-point.h (function_point::function_point): Move
10782 implementation from here to program-point.cc.
10783 (function_point::get_function): Likewise.
10784 (function_point::from_function_entry): Likewise.
10785 (function_point::before_supernode): Likewise.
10786 (function_point::next_stmt): New decl.
10787 (program_point::operator!=): New.
10788 (program_point::origin): New.
10789 (program_point::next_stmt): New.
10790 (program_point::m_function_point): Make non-const.
10791 * program-state.cc: Move includes of "analyzer/call-string.h" and
10792 "analyzer/program-point.h" to before "analyzer/region-model.h",
10793 and also include "analyzer/store.h" before it.
10794 (extrinsic_state::get_model_manager): New.
10795 (sm_state_map::sm_state_map): Pass in sm and sm_idx to ctor,
10796 rather than pass the around.
10797 (sm_state_map::clone_with_remapping): Delete.
10798 (sm_state_map::print): Remove "sm" param in favor of "m_sm". Add
10799 "simple" and "multiline" params and support multiline vs single
10800 line dumping.
10801 (sm_state_map::dump): Remove "sm" param in favor of "m_sm". Add
10802 "simple" param.
10803 (sm_state_map::hash): Port from svalue_id to const svalue *.
10804 (sm_state_map::operator==): Likewise.
10805 (sm_state_map::get_state): Likewise. Call canonicalize_svalue on
10806 input. Handle inheritance of sm-state. Call get_default_state.
10807 (sm_state_map::get_origin): Port from svalue_id to const svalue *.
10808 (sm_state_map::set_state): Likewise. Pass in ext_state. Reject
10809 attempts to set state on UNKNOWN.
10810 (sm_state_map::impl_set_state): Port from svalue_id to
10811 const svalue *. Pass in ext_state. Call canonicalize_svalue on
10812 input.
10813 (sm_state_map::purge_for_unknown_fncall): Delete.
10814 (sm_state_map::on_svalue_leak): New.
10815 (sm_state_map::remap_svalue_ids): Delete.
10816 (sm_state_map::on_liveness_change): New.
10817 (sm_state_map::on_unknown_change): Reimplement.
10818 (sm_state_map::on_svalue_purge): Delete.
10819 (sm_state_map::on_inherited_svalue): Delete.
10820 (sm_state_map::on_cast): Delete.
10821 (sm_state_map::validate): Delete.
10822 (sm_state_map::canonicalize_svalue): New.
10823 (program_state::program_state): Update to pass manager to
10824 region_model's ctor. Constify num_states and pass state machine
10825 and index to sm_state_map ctor.
10826 (program_state::print): Update for changes to dump API.
10827 (program_state::dump_to_pp): Ignore the summarize param. Add
10828 "multiline" param.
10829 (program_state::dump_to_file): Add "multiline" param.
10830 (program_state::dump): Pass "true" for new "multiline" param.
10831 (program_state::push_frame): New.
10832 (program_state::on_edge): Drop "change" param. Call
10833 program_state::detect_leaks.
10834 (program_state::prune_for_point): Add enode_for_diag param.
10835 Reimplement based on store class. Call detect_leaks
10836 (program_state::remap_svalue_ids): Delete.
10837 (program_state::get_representative_tree): Port from svalue_id to
10838 const svalue *.
10839 (program_state::can_merge_with_p): Add "point" param. Add early
10840 reject for sm-differences. Drop id remapping.
10841 (program_state::validate): Drop region model and sm_state_map
10842 validation.
10843 (state_change::sm_change::dump): Delete.
10844 (state_change::sm_change::remap_svalue_ids): Delete.
10845 (state_change::sm_change::on_svalue_purge): Delete.
10846 (log_set_of_svalues): New.
10847 (state_change::sm_change::validate): Delete.
10848 (state_change::state_change): Delete.
10849 (state_change::add_sm_change): Delete.
10850 (state_change::affects_p): Delete.
10851 (state_change::dump): Delete.
10852 (state_change::remap_svalue_ids): Delete.
10853 (state_change::on_svalue_purge): Delete.
10854 (state_change::validate): Delete.
10855 (selftest::assert_dump_eq): Delete.
10856 (ASSERT_DUMP_EQ): Delete.
10857 (selftest::test_sm_state_map): Update for changes to region_model
10858 and sm_state_map, porting from svalue_id to const svalue *.
10859 (selftest::test_program_state_dumping): Likewise. Drop test of
10860 dumping, renaming to...
10861 (selftest::test_program_state_1): ...this.
10862 (selftest::test_program_state_dumping_2): Likewise, renaming to...
10863 (selftest::test_program_state_2): ...this.
10864 (selftest::test_program_state_merging): Update for changes to
10865 region_model.
10866 (selftest::test_program_state_merging_2): Likewise.
10867 (selftest::analyzer_program_state_cc_tests): Update for renamed
10868 tests.
10869 * program-state.h (extrinsic_state::extrinsic_state): Add logger
10870 and engine params.
10871 (extrinsic_state::get_logger): New accessor.
10872 (extrinsic_state::get_engine): New accessor.
10873 (extrinsic_state::get_model_manager): New accessor.
10874 (extrinsic_state::m_logger): New field.
10875 (extrinsic_state::m_engine): New field.
10876 (struct default_hash_traits<svalue_id>): Delete.
10877 (pod_hash_traits<svalue_id>::hash): Delete.
10878 (pod_hash_traits<svalue_id>::equal): Delete.
10879 (pod_hash_traits<svalue_id>::mark_deleted): Delete.
10880 (pod_hash_traits<svalue_id>::mark_empty): Delete.
10881 (pod_hash_traits<svalue_id>::is_deleted): Delete.
10882 (pod_hash_traits<svalue_id>::is_empty): Delete.
10883 (sm_state_map::entry_t::entry_t): Port from svalue_id to
10884 const svalue *.
10885 (sm_state_map::entry_t::m_origin): Likewise.
10886 (sm_state_map::map_t): Likewise.
10887 (sm_state_map::sm_state_map): Add state_machine and index params.
10888 (sm_state_map::clone_with_remapping): Delete.
10889 (sm_state_map::print): Drop sm param; add simple and multiline
10890 params.
10891 (sm_state_map::dump): Drop sm param; add simple param.
10892 (sm_state_map::get_state): Port from svalue_id to const svalue *.
10893 Add ext_state param.
10894 (sm_state_map::get_origin): Likewise.
10895 (sm_state_map::set_state): Likewise.
10896 (sm_state_map::impl_set_state): Likewise.
10897 (sm_state_map::purge_for_unknown_fncall): Delete.
10898 (sm_state_map::remap_svalue_ids): Delete.
10899 (sm_state_map::on_svalue_purge): Delete.
10900 (sm_state_map::on_svalue_leak): New.
10901 (sm_state_map::on_liveness_change): New.
10902 (sm_state_map::on_inherited_svalue): Delete.
10903 (sm_state_map::on_cast): Delete.
10904 (sm_state_map::validate): Delete.
10905 (sm_state_map::on_unknown_change): Port from svalue_id to
10906 const svalue *. Add is_mutable and ext_state params.
10907 (sm_state_map::canonicalize_svalue): New.
10908 (sm_state_map::m_sm): New field.
10909 (sm_state_map::m_sm_idx): New field.
10910 (program_state::operator=): Delete.
10911 (program_state::dump_to_pp): Drop "summarize" param, adding
10912 "simple" and "multiline".
10913 (program_state::dump_to_file): Likewise.
10914 (program_state::dump): Rename "summarize" to "simple".
10915 (program_state::push_frame): New.
10916 (program_state::get_current_function): New.
10917 (program_state::on_edge): Drop "change" param.
10918 (program_state::prune_for_point): Likewise. Add enode_for_diag
10919 param.
10920 (program_state::remap_svalue_ids): Delete.
10921 (program_state::get_representative_tree): Port from svalue_id to
10922 const svalue *.
10923 (program_state::can_purge_p): Likewise. Pass ext_state to get_state.
10924 (program_state::can_merge_with_p): Add point param.
10925 (program_state::detect_leaks): New.
10926 (state_change_visitor::on_state_change): Port from tree and
10927 svalue_id to a pair of const svalue *.
10928 (class state_change): Delete.
10929 * region.cc: New file.
10930 * region-model-impl-calls.cc: New file.
10931 * region-model-manager.cc: New file.
10932 * region-model-reachability.cc: New file.
10933 * region-model-reachability.h: New file.
10934 * region-model.cc: Include "analyzer/call-string.h",
10935 "analyzer/program-point.h", and "analyzer/store.h" before
10936 "analyzer/region-model.h". Include
10937 "analyzer/region-model-reachability.h".
10938 (dump_tree): Make non-static.
10939 (dump_quoted_tree): Make non-static.
10940 (print_quoted_type): Make non-static.
10941 (path_var::dump): Delete.
10942 (dump_separator): Delete.
10943 (class impl_constraint_manager): Delete.
10944 (svalue_id::print): Delete.
10945 (svalue_id::dump_node_name_to_pp): Delete.
10946 (svalue_id::validate): Delete.
10947 (region_id::print): Delete.
10948 (region_id::dump_node_name_to_pp): Delete.
10949 (region_id::validate): Delete.
10950 (region_id_set::region_id_set): Delete.
10951 (svalue_id_set::svalue_id_set): Delete.
10952 (svalue::operator==): Delete.
10953 (svalue::hash): Delete.
10954 (svalue::print): Delete.
10955 (svalue::dump_dot_to_pp): Delete.
10956 (svalue::remap_region_ids): Delete.
10957 (svalue::walk_for_canonicalization): Delete.
10958 (svalue::get_child_sid): Delete.
10959 (svalue::maybe_get_constant): Delete.
10960 (region_svalue::compare_fields): Delete.
10961 (region_svalue::add_to_hash): Delete.
10962 (region_svalue::print_details): Delete.
10963 (region_svalue::dump_dot_to_pp): Delete.
10964 (region_svalue::remap_region_ids): Delete.
10965 (region_svalue::merge_values): Delete.
10966 (region_svalue::walk_for_canonicalization): Delete.
10967 (region_svalue::eval_condition): Delete.
10968 (constant_svalue::compare_fields): Delete.
10969 (constant_svalue::add_to_hash): Delete.
10970 (constant_svalue::merge_values): Delete.
10971 (constant_svalue::eval_condition): Move to svalue.cc.
10972 (constant_svalue::print_details): Delete.
10973 (constant_svalue::get_child_sid): Delete.
10974 (unknown_svalue::compare_fields): Delete.
10975 (unknown_svalue::add_to_hash): Delete.
10976 (unknown_svalue::print_details): Delete.
10977 (poison_kind_to_str): Move to svalue.cc.
10978 (poisoned_svalue::compare_fields): Delete.
10979 (poisoned_svalue::add_to_hash): Delete.
10980 (poisoned_svalue::print_details): Delete.
10981 (region_kind_to_str): Move to region.cc and reimplement.
10982 (region::operator==): Delete.
10983 (region::get_parent_region): Delete.
10984 (region::set_value): Delete.
10985 (region::become_active_view): Delete.
10986 (region::deactivate_any_active_view): Delete.
10987 (region::deactivate_view): Delete.
10988 (region::get_value): Delete.
10989 (region::get_inherited_child_sid): Delete.
10990 (region_model::copy_region): Delete.
10991 (region_model::copy_struct_region): Delete.
10992 (region_model::copy_union_region): Delete.
10993 (region_model::copy_array_region): Delete.
10994 (region::hash): Delete.
10995 (region::print): Delete.
10996 (region::dump_dot_to_pp): Delete.
10997 (region::dump_to_pp): Delete.
10998 (region::dump_child_label): Delete.
10999 (region::validate): Delete.
11000 (region::remap_svalue_ids): Delete.
11001 (region::remap_region_ids): Delete.
11002 (region::add_view): Delete.
11003 (region::get_view): Delete.
11004 (region::region): Move to region.cc.
11005 (region::add_to_hash): Delete.
11006 (region::print_fields): Delete.
11007 (region::non_null_p): Delete.
11008 (primitive_region::clone): Delete.
11009 (primitive_region::walk_for_canonicalization): Delete.
11010 (map_region::map_region): Delete.
11011 (map_region::compare_fields): Delete.
11012 (map_region::print_fields): Delete.
11013 (map_region::validate): Delete.
11014 (map_region::dump_dot_to_pp): Delete.
11015 (map_region::dump_child_label): Delete.
11016 (map_region::get_or_create): Delete.
11017 (map_region::get): Delete.
11018 (map_region::add_to_hash): Delete.
11019 (map_region::remap_region_ids): Delete.
11020 (map_region::unbind): Delete.
11021 (map_region::get_tree_for_child_region): Delete.
11022 (map_region::get_tree_for_child_region): Delete.
11023 (tree_cmp): Move to region.cc.
11024 (map_region::can_merge_p): Delete.
11025 (map_region::walk_for_canonicalization): Delete.
11026 (map_region::get_value_by_name): Delete.
11027 (struct_or_union_region::valid_key_p): Delete.
11028 (struct_or_union_region::compare_fields): Delete.
11029 (struct_region::clone): Delete.
11030 (struct_region::compare_fields): Delete.
11031 (union_region::clone): Delete.
11032 (union_region::compare_fields): Delete.
11033 (frame_region::compare_fields): Delete.
11034 (frame_region::clone): Delete.
11035 (frame_region::valid_key_p): Delete.
11036 (frame_region::print_fields): Delete.
11037 (frame_region::add_to_hash): Delete.
11038 (globals_region::compare_fields): Delete.
11039 (globals_region::clone): Delete.
11040 (globals_region::valid_key_p): Delete.
11041 (code_region::compare_fields): Delete.
11042 (code_region::clone): Delete.
11043 (code_region::valid_key_p): Delete.
11044 (array_region::array_region): Delete.
11045 (array_region::get_element): Delete.
11046 (array_region::clone): Delete.
11047 (array_region::compare_fields): Delete.
11048 (array_region::print_fields): Delete.
11049 (array_region::validate): Delete.
11050 (array_region::dump_dot_to_pp): Delete.
11051 (array_region::dump_child_label): Delete.
11052 (array_region::get_or_create): Delete.
11053 (array_region::get): Delete.
11054 (array_region::add_to_hash): Delete.
11055 (array_region::remap_region_ids): Delete.
11056 (array_region::get_key_for_child_region): Delete.
11057 (array_region::key_cmp): Delete.
11058 (array_region::walk_for_canonicalization): Delete.
11059 (array_region::key_from_constant): Delete.
11060 (array_region::constant_from_key): Delete.
11061 (function_region::compare_fields): Delete.
11062 (function_region::clone): Delete.
11063 (function_region::valid_key_p): Delete.
11064 (stack_region::stack_region): Delete.
11065 (stack_region::compare_fields): Delete.
11066 (stack_region::clone): Delete.
11067 (stack_region::print_fields): Delete.
11068 (stack_region::dump_child_label): Delete.
11069 (stack_region::validate): Delete.
11070 (stack_region::push_frame): Delete.
11071 (stack_region::get_current_frame_id): Delete.
11072 (stack_region::pop_frame): Delete.
11073 (stack_region::add_to_hash): Delete.
11074 (stack_region::remap_region_ids): Delete.
11075 (stack_region::can_merge_p): Delete.
11076 (stack_region::walk_for_canonicalization): Delete.
11077 (stack_region::get_value_by_name): Delete.
11078 (heap_region::heap_region): Delete.
11079 (heap_region::compare_fields): Delete.
11080 (heap_region::clone): Delete.
11081 (heap_region::walk_for_canonicalization): Delete.
11082 (root_region::root_region): Delete.
11083 (root_region::compare_fields): Delete.
11084 (root_region::clone): Delete.
11085 (root_region::print_fields): Delete.
11086 (root_region::validate): Delete.
11087 (root_region::dump_child_label): Delete.
11088 (root_region::push_frame): Delete.
11089 (root_region::get_current_frame_id): Delete.
11090 (root_region::pop_frame): Delete.
11091 (root_region::ensure_stack_region): Delete.
11092 (root_region::get_stack_region): Delete.
11093 (root_region::ensure_globals_region): Delete.
11094 (root_region::get_code_region): Delete.
11095 (root_region::ensure_code_region): Delete.
11096 (root_region::get_globals_region): Delete.
11097 (root_region::ensure_heap_region): Delete.
11098 (root_region::get_heap_region): Delete.
11099 (root_region::remap_region_ids): Delete.
11100 (root_region::can_merge_p): Delete.
11101 (root_region::add_to_hash): Delete.
11102 (root_region::walk_for_canonicalization): Delete.
11103 (root_region::get_value_by_name): Delete.
11104 (symbolic_region::symbolic_region): Delete.
11105 (symbolic_region::compare_fields): Delete.
11106 (symbolic_region::clone): Delete.
11107 (symbolic_region::walk_for_canonicalization): Delete.
11108 (symbolic_region::print_fields): Delete.
11109 (region_model::region_model): Add region_model_manager * param.
11110 Reimplement in terms of store, dropping impl_constraint_manager
11111 subclass.
11112 (region_model::operator=): Reimplement in terms of store
11113 (region_model::operator==): Likewise.
11114 (region_model::hash): Likewise.
11115 (region_model::print): Delete.
11116 (region_model::print_svalue): Delete.
11117 (region_model::dump_dot_to_pp): Delete.
11118 (region_model::dump_dot_to_file): Delete.
11119 (region_model::dump_dot): Delete.
11120 (region_model::dump_to_pp): Replace "summarize" param with
11121 "simple" and "multiline". Port to store-based implementation.
11122 (region_model::dump): Replace "summarize" param with "simple" and
11123 "multiline".
11124 (dump_vec_of_tree): Delete.
11125 (region_model::dump_summary_of_rep_path_vars): Delete.
11126 (region_model::validate): Delete.
11127 (svalue_id_cmp_by_constant_svalue_model): Delete.
11128 (svalue_id_cmp_by_constant_svalue): Delete.
11129 (region_model::canonicalize): Drop "ctxt" param. Reimplement in
11130 terms of store and constraints.
11131 (region_model::canonicalized_p): Remove NULL arg to canonicalize.
11132 (region_model::loop_replay_fixup): New.
11133 (poisoned_value_diagnostic::emit): Tweak wording of warnings.
11134 (region_model::check_for_poison): Delete.
11135 (region_model::get_gassign_result): New.
11136 (region_model::on_assignment): Port to store-based implementation.
11137 (region_model::on_call_pre): Delete calls to check_for_poison.
11138 Move implementations to region-model-impl-calls.c and port to
11139 store-based implementation.
11140 (region_model::on_call_post): Likewise.
11141 (class reachable_regions): Move to region-model-reachability.h/cc
11142 and port to store-based implementation.
11143 (region_model::handle_unrecognized_call): Port to store-based
11144 implementation.
11145 (region_model::get_reachable_svalues): New.
11146 (region_model::on_setjmp): Port to store-based implementation.
11147 (region_model::on_longjmp): Likewise.
11148 (region_model::handle_phi): Drop is_back_edge param and the logic
11149 using it.
11150 (region_model::get_lvalue_1): Port from region_id to const region *.
11151 (region_model::make_region_for_unexpected_tree_code): Delete.
11152 (assert_compat_types): If the check fails, use internal_error to
11153 show the types.
11154 (region_model::get_lvalue): Port from region_id to const region *.
11155 (region_model::get_rvalue_1): Port from svalue_id to const svalue *.
11156 (region_model::get_rvalue): Likewise.
11157 (region_model::get_or_create_ptr_svalue): Delete.
11158 (region_model::get_or_create_constant_svalue): Delete.
11159 (region_model::get_svalue_for_fndecl): Delete.
11160 (region_model::get_region_for_fndecl): Delete.
11161 (region_model::get_svalue_for_label): Delete.
11162 (region_model::get_region_for_label): Delete.
11163 (build_cast): Delete.
11164 (region_model::maybe_cast_1): Delete.
11165 (region_model::maybe_cast): Delete.
11166 (region_model::get_field_region): Delete.
11167 (region_model::get_store_value): New.
11168 (region_model::region_exists_p): New.
11169 (region_model::deref_rvalue): Port from svalue_id to const svalue *.
11170 (region_model::set_value): Likewise.
11171 (region_model::clobber_region): New.
11172 (region_model::purge_region): New.
11173 (region_model::zero_fill_region): New.
11174 (region_model::mark_region_as_unknown): New.
11175 (region_model::eval_condition): Port from svalue_id to
11176 const svalue *.
11177 (region_model::eval_condition_without_cm): Likewise.
11178 (region_model::compare_initial_and_pointer): New.
11179 (region_model::add_constraint): Port from svalue_id to
11180 const svalue *.
11181 (region_model::maybe_get_constant): Delete.
11182 (region_model::get_representative_path_var): New.
11183 (region_model::add_new_malloc_region): Delete.
11184 (region_model::get_representative_tree): Port to const svalue *.
11185 (region_model::get_representative_path_var): Port to
11186 const region *.
11187 (region_model::get_path_vars_for_svalue): Delete.
11188 (region_model::set_to_new_unknown_value): Delete.
11189 (region_model::update_for_phis): Don't pass is_back_edge to handle_phi.
11190 (region_model::update_for_call_superedge): Port from svalue_id to
11191 const svalue *.
11192 (region_model::update_for_return_superedge): Port to store-based
11193 implementation.
11194 (region_model::update_for_call_summary): Replace
11195 set_to_new_unknown_value with mark_region_as_unknown.
11196 (region_model::get_root_region): Delete.
11197 (region_model::get_stack_region_id): Delete.
11198 (region_model::push_frame): Delete.
11199 (region_model::get_current_frame_id): Delete.
11200 (region_model::get_current_function): Delete.
11201 (region_model::pop_frame): Delete.
11202 (region_model::on_top_level_param): New.
11203 (region_model::get_stack_depth): Delete.
11204 (region_model::get_function_at_depth): Delete.
11205 (region_model::get_globals_region_id): Delete.
11206 (region_model::add_svalue): Delete.
11207 (region_model::replace_svalue): Delete.
11208 (region_model::add_region): Delete.
11209 (region_model::get_svalue): Delete.
11210 (region_model::get_region): Delete.
11211 (make_region_for_type): Delete.
11212 (region_model::add_region_for_type): Delete.
11213 (region_model::on_top_level_param): New.
11214 (class restrict_to_used_svalues): Delete.
11215 (region_model::purge_unused_svalues): Delete.
11216 (region_model::push_frame): New.
11217 (region_model::remap_svalue_ids): Delete.
11218 (region_model::remap_region_ids): Delete.
11219 (region_model::purge_regions): Delete.
11220 (region_model::get_descendents): Delete.
11221 (region_model::delete_region_and_descendents): Delete.
11222 (region_model::poison_any_pointers_to_bad_regions): Delete.
11223 (region_model::can_merge_with_p): Delete.
11224 (region_model::get_current_function): New.
11225 (region_model::get_value_by_name): Delete.
11226 (region_model::convert_byte_offset_to_array_index): Delete.
11227 (region_model::pop_frame): New.
11228 (region_model::get_or_create_mem_ref): Delete.
11229 (region_model::get_stack_depth): New.
11230 (region_model::get_frame_at_index): New.
11231 (region_model::unbind_region_and_descendents): New.
11232 (struct bad_pointer_finder): New.
11233 (region_model::get_or_create_pointer_plus_expr): Delete.
11234 (region_model::poison_any_pointers_to_descendents): New.
11235 (region_model::get_or_create_view): Delete.
11236 (region_model::can_merge_with_p): New.
11237 (region_model::get_fndecl_for_call): Port from svalue_id to
11238 const svalue *.
11239 (struct append_ssa_names_cb_data): New.
11240 (get_ssa_name_regions_for_current_frame): New.
11241 (region_model::append_ssa_names_cb): New.
11242 (model_merger::dump_to_pp): Add "simple" param. Drop dumping of
11243 remappings.
11244 (model_merger::dump): Add "simple" param to both overloads.
11245 (model_merger::can_merge_values_p): Delete.
11246 (model_merger::record_regions): Delete.
11247 (model_merger::record_svalues): Delete.
11248 (svalue_id_merger_mapping::svalue_id_merger_mapping): Delete.
11249 (svalue_id_merger_mapping::dump_to_pp): Delete.
11250 (svalue_id_merger_mapping::dump): Delete.
11251 (region_model::create_region_for_heap_alloc): New.
11252 (region_model::create_region_for_alloca): New.
11253 (region_model::record_dynamic_extents): New.
11254 (canonicalization::canonicalization): Delete.
11255 (canonicalization::walk_rid): Delete.
11256 (canonicalization::walk_sid): Delete.
11257 (canonicalization::dump_to_pp): Delete.
11258 (canonicalization::dump): Delete.
11259 (inchash::add): Delete overloads for svalue_id and region_id.
11260 (engine::log_stats): New.
11261 (assert_condition): Add overload comparing svalues.
11262 (assert_dump_eq): Pass "true" for multiline.
11263 (selftest::test_dump): Update for rewrite of region_model.
11264 (selftest::test_dump_2): Rename to...
11265 (selftest::test_struct): ...this. Provide a region_model_manager
11266 when creating region_model instance. Remove dump test. Add
11267 checks for get_offset.
11268 (selftest::test_dump_3): Rename to...
11269 (selftest::test_array_1): ...this. Provide a region_model_manager
11270 when creating region_model instance. Remove dump test.
11271 (selftest::test_get_representative_tree): Port from svalue_id to
11272 new API. Add test coverage for various expressions.
11273 (selftest::test_unique_constants): Provide a region_model_manager
11274 for the region_model. Add test coverage for comparing const vs
11275 non-const.
11276 (selftest::test_svalue_equality): Delete.
11277 (selftest::test_region_equality): Delete.
11278 (selftest::test_unique_unknowns): New.
11279 (class purge_all_svalue_ids): Delete.
11280 (class purge_one_svalue_id): Delete.
11281 (selftest::test_purging_by_criteria): Delete.
11282 (selftest::test_initial_svalue_folding): New.
11283 (selftest::test_unaryop_svalue_folding): New.
11284 (selftest::test_binop_svalue_folding): New.
11285 (selftest::test_sub_svalue_folding): New.
11286 (selftest::test_purge_unused_svalues): Delete.
11287 (selftest::test_descendent_of_p): New.
11288 (selftest::test_assignment): Provide a region_model_manager for
11289 the region_model. Drop the dump test.
11290 (selftest::test_compound_assignment): Likewise.
11291 (selftest::test_stack_frames): Port to new implementation.
11292 (selftest::test_get_representative_path_var): Likewise.
11293 (selftest::test_canonicalization_1): Rename to...
11294 (selftest::test_equality_1): ...this. Port to new API, and add
11295 (selftest::test_canonicalization_2): Provide a
11296 region_model_manager when creating region_model instances.
11297 Remove redundant canicalization.
11298 (selftest::test_canonicalization_3): Provide a
11299 region_model_manager when creating region_model instances.
11300 Remove param from calls to region_model::canonicalize.
11301 (selftest::test_canonicalization_4): Likewise.
11302 (selftest::assert_region_models_merge): Constify
11303 out_merged_svalue. Port to new API.
11304 (selftest::test_state_merging): Provide a
11305 region_model_manager when creating region_model instances.
11306 Provide a program_point point when merging them. Replace
11307 set_to_new_unknown_value with usage of placeholder_svalues.
11308 Drop get_value_by_name. Port from svalue_id to const svalue *.
11309 Add test of heap allocation.
11310 (selftest::test_constraint_merging): Provide a
11311 region_model_manager when creating region_model instances.
11312 Provide a program_point point when merging them. Eliminate use
11313 of set_to_new_unknown_value.
11314 (selftest::test_widening_constraints): New.
11315 (selftest::test_iteration_1): New.
11316 (selftest::test_malloc_constraints): Port to store-based
11317 implementation.
11318 (selftest::test_var): New test.
11319 (selftest::test_array_2): New test.
11320 (selftest::test_mem_ref): New test.
11321 (selftest::test_POINTER_PLUS_EXPR_then_MEM_REF): New.
11322 (selftest::test_malloc): New.
11323 (selftest::test_alloca): New.
11324 (selftest::analyzer_region_model_cc_tests): Update for renamings.
11325 Call new functions.
11326 * region-model.h (class path_var): Move to analyzer.h.
11327 (class svalue_id): Delete.
11328 (class region_id): Delete.
11329 (class id_map): Delete.
11330 (svalue_id_map): Delete.
11331 (region_id_map): Delete.
11332 (id_map<T>::id_map): Delete.
11333 (id_map<T>::put): Delete.
11334 (id_map<T>::get_dst_for_src): Delete.
11335 (id_map<T>::get_src_for_dst): Delete.
11336 (id_map<T>::dump_to_pp): Delete.
11337 (id_map<T>::dump): Delete.
11338 (id_map<T>::update): Delete.
11339 (one_way_svalue_id_map): Delete.
11340 (one_way_region_id_map): Delete.
11341 (class region_id_set): Delete.
11342 (class svalue_id_set): Delete.
11343 (struct complexity): New.
11344 (class visitor): New.
11345 (enum svalue_kind): Add SK_SETJMP, SK_INITIAL, SK_UNARYOP,
11346 SK_BINOP, SK_SUB,SK_UNMERGEABLE, SK_PLACEHOLDER, SK_WIDENING,
11347 SK_COMPOUND, and SK_CONJURED.
11348 (svalue::operator==): Delete.
11349 (svalue::operator!=): Delete.
11350 (svalue::clone): Delete.
11351 (svalue::hash): Delete.
11352 (svalue::dump_dot_to_pp): Delete.
11353 (svalue::dump_to_pp): New.
11354 (svalue::dump): New.
11355 (svalue::get_desc): New.
11356 (svalue::dyn_cast_initial_svalue): New.
11357 (svalue::dyn_cast_unaryop_svalue): New.
11358 (svalue::dyn_cast_binop_svalue): New.
11359 (svalue::dyn_cast_sub_svalue): New.
11360 (svalue::dyn_cast_unmergeable_svalue): New.
11361 (svalue::dyn_cast_widening_svalue): New.
11362 (svalue::dyn_cast_compound_svalue): New.
11363 (svalue::dyn_cast_conjured_svalue): New.
11364 (svalue::maybe_undo_cast): New.
11365 (svalue::unwrap_any_unmergeable): New.
11366 (svalue::remap_region_ids): Delete
11367 (svalue::can_merge_p): New.
11368 (svalue::walk_for_canonicalization): Delete
11369 (svalue::get_complexity): New.
11370 (svalue::get_child_sid): Delete
11371 (svalue::accept): New.
11372 (svalue::live_p): New.
11373 (svalue::implicitly_live_p): New.
11374 (svalue::svalue): Add complexity param.
11375 (svalue::add_to_hash): Delete
11376 (svalue::print_details): Delete
11377 (svalue::m_complexity): New field.
11378 (region_svalue::key_t): New struct.
11379 (region_svalue::region_svalue): Port from region_id to
11380 const region_id *. Add complexity.
11381 (region_svalue::compare_fields): Delete.
11382 (region_svalue::clone): Delete.
11383 (region_svalue::dump_dot_to_pp): Delete.
11384 (region_svalue::get_pointee): Port from region_id to
11385 const region_id *.
11386 (region_svalue::remap_region_ids): Delete.
11387 (region_svalue::merge_values): Delete.
11388 (region_svalue::dump_to_pp): New.
11389 (region_svalue::accept): New.
11390 (region_svalue::walk_for_canonicalization): Delete.
11391 (region_svalue::eval_condition): Make params const.
11392 (region_svalue::add_to_hash): Delete.
11393 (region_svalue::print_details): Delete.
11394 (region_svalue::m_rid): Replace with...
11395 (region_svalue::m_reg): ...this.
11396 (is_a_helper <region_svalue *>::test): Convert to...
11397 (is_a_helper <const region_svalue *>::test): ...this.
11398 (template <> struct default_hash_traits<region_svalue::key_t>):
11399 New.
11400 (constant_svalue::constant_svalue): Add complexity.
11401 (constant_svalue::compare_fields): Delete.
11402 (constant_svalue::clone): Delete.
11403 (constant_svalue::add_to_hash): Delete.
11404 (constant_svalue::dump_to_pp): New.
11405 (constant_svalue::accept): New.
11406 (constant_svalue::implicitly_live_p): New.
11407 (constant_svalue::merge_values): Delete.
11408 (constant_svalue::eval_condition): Make params const.
11409 (constant_svalue::get_child_sid): Delete.
11410 (constant_svalue::print_details): Delete.
11411 (is_a_helper <constant_svalue *>::test): Convert to...
11412 (is_a_helper <const constant_svalue *>::test): ...this.
11413 (class unknown_svalue): Update leading comment.
11414 (unknown_svalue::unknown_svalue): Add complexity.
11415 (unknown_svalue::compare_fields): Delete.
11416 (unknown_svalue::add_to_hash): Delete.
11417 (unknown_svalue::dyn_cast_unknown_svalue): Delete.
11418 (unknown_svalue::print_details): Delete.
11419 (unknown_svalue::dump_to_pp): New.
11420 (unknown_svalue::accept): New.
11421 (poisoned_svalue::key_t): New struct.
11422 (poisoned_svalue::poisoned_svalue): Add complexity.
11423 (poisoned_svalue::compare_fields): Delete.
11424 (poisoned_svalue::clone): Delete.
11425 (poisoned_svalue::add_to_hash): Delete.
11426 (poisoned_svalue::dump_to_pp): New.
11427 (poisoned_svalue::accept): New.
11428 (poisoned_svalue::print_details): Delete.
11429 (is_a_helper <poisoned_svalue *>::test): Convert to...
11430 (is_a_helper <const poisoned_svalue *>::test): ...this.
11431 (template <> struct default_hash_traits<poisoned_svalue::key_t>):
11432 New.
11433 (setjmp_record::add_to_hash): New.
11434 (setjmp_svalue::key_t): New struct.
11435 (setjmp_svalue::compare_fields): Delete.
11436 (setjmp_svalue::clone): Delete.
11437 (setjmp_svalue::add_to_hash): Delete.
11438 (setjmp_svalue::setjmp_svalue): Add complexity.
11439 (setjmp_svalue::dump_to_pp): New.
11440 (setjmp_svalue::accept): New.
11441 (setjmp_svalue::void print_details): Delete.
11442 (is_a_helper <const setjmp_svalue *>::test): New.
11443 (template <> struct default_hash_traits<setjmp_svalue::key_t>): New.
11444 (class initial_svalue : public svalue): New.
11445 (is_a_helper <const initial_svalue *>::test): New.
11446 (class unaryop_svalue): New.
11447 (is_a_helper <const unaryop_svalue *>::test): New.
11448 (template <> struct default_hash_traits<unaryop_svalue::key_t>): New.
11449 (class binop_svalue): New.
11450 (is_a_helper <const binop_svalue *>::test): New.
11451 (template <> struct default_hash_traits<binop_svalue::key_t>): New.
11452 (class sub_svalue): New.
11453 (is_a_helper <const sub_svalue *>::test): New.
11454 (template <> struct default_hash_traits<sub_svalue::key_t>): New.
11455 (class unmergeable_svalue): New.
11456 (is_a_helper <const unmergeable_svalue *>::test): New.
11457 (class placeholder_svalue): New.
11458 (is_a_helper <placeholder_svalue *>::test): New.
11459 (class widening_svalue): New.
11460 (is_a_helper <widening_svalue *>::test): New.
11461 (template <> struct default_hash_traits<widening_svalue::key_t>): New.
11462 (class compound_svalue): New.
11463 (is_a_helper <compound_svalue *>::test): New.
11464 (template <> struct default_hash_traits<compound_svalue::key_t>): New.
11465 (class conjured_svalue): New.
11466 (is_a_helper <conjured_svalue *>::test): New.
11467 (template <> struct default_hash_traits<conjured_svalue::key_t>): New.
11468 (enum region_kind): Delete RK_PRIMITIVE, RK_STRUCT, RK_UNION, and
11469 RK_ARRAY. Add RK_LABEL, RK_DECL, RK_FIELD, RK_ELEMENT, RK_OFFSET,
11470 RK_CAST, RK_HEAP_ALLOCATED, RK_ALLOCA, RK_STRING, and RK_UNKNOWN.
11471 (region_kind_to_str): Delete.
11472 (region::~region): Move implementation to region.cc.
11473 (region::operator==): Delete.
11474 (region::operator!=): Delete.
11475 (region::clone): Delete.
11476 (region::get_id): New.
11477 (region::cmp_ids): New.
11478 (region::dyn_cast_map_region): Delete.
11479 (region::dyn_cast_array_region): Delete.
11480 (region::region_id get_parent): Delete.
11481 (region::get_parent_region): Convert to a simple accessor.
11482 (region::void set_value): Delete.
11483 (region::svalue_id get_value): Delete.
11484 (region::svalue_id get_value_direct): Delete.
11485 (region::svalue_id get_inherited_child_sid): Delete.
11486 (region::dyn_cast_frame_region): New.
11487 (region::dyn_cast_function_region): New.
11488 (region::dyn_cast_decl_region): New.
11489 (region::dyn_cast_field_region): New.
11490 (region::dyn_cast_element_region): New.
11491 (region::dyn_cast_offset_region): New.
11492 (region::dyn_cast_cast_region): New.
11493 (region::dyn_cast_string_region): New.
11494 (region::accept): New.
11495 (region::get_base_region): New.
11496 (region::base_region_p): New.
11497 (region::descendent_of_p): New.
11498 (region::maybe_get_frame_region): New.
11499 (region::maybe_get_decl): New.
11500 (region::hash): Delete.
11501 (region::rint): Delete.
11502 (region::dump_dot_to_pp): Delete.
11503 (region::get_desc): New.
11504 (region::dump_to_pp): Convert to vfunc, changing signature.
11505 (region::dump_child_label): Delete.
11506 (region::remap_svalue_ids): Delete.
11507 (region::remap_region_ids): Delete.
11508 (region::dump): New.
11509 (region::walk_for_canonicalization): Delete.
11510 (region::non_null_p): Drop region_model param.
11511 (region::add_view): Delete.
11512 (region::get_view): Delete.
11513 (region::get_active_view): Delete.
11514 (region::is_view_p): Delete.
11515 (region::cmp_ptrs): New.
11516 (region::validate): Delete.
11517 (region::get_offset): New.
11518 (region::get_byte_size): New.
11519 (region::get_bit_size): New.
11520 (region::get_subregions_for_binding): New.
11521 (region::region): Add complexity param. Convert parent from
11522 region_id to const region *. Drop svalue_id. Drop copy ctor.
11523 (region::symbolic_for_unknown_ptr_p): New.
11524 (region::add_to_hash): Delete.
11525 (region::print_fields): Delete.
11526 (region::get_complexity): New accessor.
11527 (region::become_active_view): Delete.
11528 (region::deactivate_any_active_view): Delete.
11529 (region::deactivate_view): Delete.
11530 (region::calc_offset): New.
11531 (region::m_parent_rid): Delete.
11532 (region::m_sval_id): Delete.
11533 (region::m_complexity): New.
11534 (region::m_id): New.
11535 (region::m_parent): New.
11536 (region::m_view_rids): Delete.
11537 (region::m_is_view): Delete.
11538 (region::m_active_view_rid): Delete.
11539 (region::m_cached_offset): New.
11540 (is_a_helper <region *>::test): Convert to...
11541 (is_a_helper <const region *>::test): ... this.
11542 (class primitive_region): Delete.
11543 (class space_region): New.
11544 (class map_region): Delete.
11545 (is_a_helper <map_region *>::test): Delete.
11546 (class frame_region): Reimplement.
11547 (template <> struct default_hash_traits<frame_region::key_t>):
11548 New.
11549 (class globals_region): Reimplement.
11550 (is_a_helper <globals_region *>::test): Convert to...
11551 (is_a_helper <const globals_region *>::test): ...this.
11552 (class struct_or_union_region): Delete.
11553 (is_a_helper <struct_or_union_region *>::test): Delete.
11554 (class code_region): Reimplement.
11555 (is_a_helper <const code_region *>::test): New.
11556 (class struct_region): Delete.
11557 (is_a_helper <struct_region *>::test): Delete.
11558 (class function_region): Reimplement.
11559 (is_a_helper <function_region *>::test): Convert to...
11560 (is_a_helper <const function_region *>::test): ...this.
11561 (class union_region): Delete.
11562 (is_a_helper <union_region *>::test): Delete.
11563 (class label_region): New.
11564 (is_a_helper <const label_region *>::test): New.
11565 (class scope_region): Delete.
11566 (class stack_region): Reimplement.
11567 (is_a_helper <stack_region *>::test): Convert to...
11568 (is_a_helper <const stack_region *>::test): ...this.
11569 (class heap_region): Reimplement.
11570 (is_a_helper <heap_region *>::test): Convert to...
11571 (is_a_helper <const heap_region *>::test): ...this.
11572 (class root_region): Reimplement.
11573 (is_a_helper <root_region *>::test): Convert to...
11574 (is_a_helper <const root_region *>::test): ...this.
11575 (class symbolic_region): Reimplement.
11576 (is_a_helper <const symbolic_region *>::test): New.
11577 (template <> struct default_hash_traits<symbolic_region::key_t>):
11578 New.
11579 (class decl_region): New.
11580 (is_a_helper <const decl_region *>::test): New.
11581 (class field_region): New.
11582 (template <> struct default_hash_traits<field_region::key_t>): New.
11583 (class array_region): Delete.
11584 (class element_region): New.
11585 (is_a_helper <array_region *>::test): Delete.
11586 (is_a_helper <const element_region *>::test): New.
11587 (template <> struct default_hash_traits<element_region::key_t>):
11588 New.
11589 (class offset_region): New.
11590 (is_a_helper <const offset_region *>::test): New.
11591 (template <> struct default_hash_traits<offset_region::key_t>):
11592 New.
11593 (class cast_region): New.
11594 (is_a_helper <const cast_region *>::test): New.
11595 (template <> struct default_hash_traits<cast_region::key_t>): New.
11596 (class heap_allocated_region): New.
11597 (class alloca_region): New.
11598 (class string_region): New.
11599 (is_a_helper <const string_region *>::test): New.
11600 (class unknown_region): New.
11601 (class region_model_manager): New.
11602 (struct append_ssa_names_cb_data): New.
11603 (class call_details): New.
11604 (region_model::region_model): Add region_model_manager param.
11605 (region_model::print_svalue): Delete.
11606 (region_model::dump_dot_to_pp): Delete.
11607 (region_model::dump_dot_to_file): Delete.
11608 (region_model::dump_dot): Delete.
11609 (region_model::dump_to_pp): Drop summarize param in favor of
11610 simple and multiline.
11611 (region_model::dump): Likewise.
11612 (region_model::summarize_to_pp): Delete.
11613 (region_model::summarize): Delete.
11614 (region_model::void canonicalize): Drop ctxt param.
11615 (region_model::void check_for_poison): Delete.
11616 (region_model::get_gassign_result): New.
11617 (region_model::impl_call_alloca): New.
11618 (region_model::impl_call_analyzer_describe): New.
11619 (region_model::impl_call_analyzer_eval): New.
11620 (region_model::impl_call_builtin_expect): New.
11621 (region_model::impl_call_calloc): New.
11622 (region_model::impl_call_free): New.
11623 (region_model::impl_call_malloc): New.
11624 (region_model::impl_call_memset): New.
11625 (region_model::impl_call_strlen): New.
11626 (region_model::get_reachable_svalues): New.
11627 (region_model::handle_phi): Drop is_back_edge param.
11628 (region_model::region_id get_root_rid): Delete.
11629 (region_model::root_region *get_root_region): Delete.
11630 (region_model::region_id get_stack_region_id): Delete.
11631 (region_model::push_frame): Convert from region_id and svalue_id
11632 to const region * and const svalue *.
11633 (region_model::get_current_frame_id): Replace with...
11634 (region_model::get_current_frame): ...this.
11635 (region_model::pop_frame): Convert from region_id to
11636 const region *. Drop purge and stats param. Add out_result.
11637 (region_model::function *get_function_at_depth): Delete.
11638 (region_model::get_globals_region_id): Delete.
11639 (region_model::add_svalue): Delete.
11640 (region_model::replace_svalue): Delete.
11641 (region_model::add_region): Delete.
11642 (region_model::add_region_for_type): Delete.
11643 (region_model::get_svalue): Delete.
11644 (region_model::get_region): Delete.
11645 (region_model::get_lvalue): Convert from region_id to
11646 const region *.
11647 (region_model::get_rvalue): Convert from svalue_id to
11648 const svalue *.
11649 (region_model::get_or_create_ptr_svalue): Delete.
11650 (region_model::get_or_create_constant_svalue): Delete.
11651 (region_model::get_svalue_for_fndecl): Delete.
11652 (region_model::get_svalue_for_label): Delete.
11653 (region_model::get_region_for_fndecl): Delete.
11654 (region_model::get_region_for_label): Delete.
11655 (region_model::get_frame_at_index (int index) const;): New.
11656 (region_model::maybe_cast): Delete.
11657 (region_model::maybe_cast_1): Delete.
11658 (region_model::get_field_region): Delete.
11659 (region_model::id deref_rvalue): Convert from region_id and
11660 svalue_id to const region * and const svalue *. Drop overload,
11661 passing in both a tree and an svalue.
11662 (region_model::set_value): Convert from region_id and svalue_id to
11663 const region * and const svalue *.
11664 (region_model::set_to_new_unknown_value): Delete.
11665 (region_model::clobber_region (const region *reg);): New.
11666 (region_model::purge_region (const region *reg);): New.
11667 (region_model::zero_fill_region (const region *reg);): New.
11668 (region_model::mark_region_as_unknown (const region *reg);): New.
11669 (region_model::copy_region): Convert from region_id to
11670 const region *.
11671 (region_model::eval_condition): Convert from svalue_id to
11672 const svalue *.
11673 (region_model::eval_condition_without_cm): Likewise.
11674 (region_model::compare_initial_and_pointer): New.
11675 (region_model:maybe_get_constant): Delete.
11676 (region_model::add_new_malloc_region): Delete.
11677 (region_model::get_representative_tree): Convert from svalue_id to
11678 const svalue *.
11679 (region_model::get_representative_path_var): Delete decl taking a
11680 region_id in favor of two decls, for svalue vs region, with an
11681 svalue_set to ensure termination.
11682 (region_model::get_path_vars_for_svalue): Delete.
11683 (region_model::create_region_for_heap_alloc): New.
11684 (region_model::create_region_for_alloca): New.
11685 (region_model::purge_unused_svalues): Delete.
11686 (region_model::remap_svalue_ids): Delete.
11687 (region_model::remap_region_ids): Delete.
11688 (region_model::purge_regions): Delete.
11689 (region_model::get_num_svalues): Delete.
11690 (region_model::get_num_regions): Delete.
11691 (region_model::get_descendents): Delete.
11692 (region_model::get_store): New.
11693 (region_model::delete_region_and_descendents): Delete.
11694 (region_model::get_manager): New.
11695 (region_model::unbind_region_and_descendents): New.
11696 (region_model::can_merge_with_p): Add point param. Drop
11697 svalue_id_merger_mapping.
11698 (region_model::get_value_by_name): Delete.
11699 (region_model::convert_byte_offset_to_array_index): Delete.
11700 (region_model::get_or_create_mem_ref): Delete.
11701 (region_model::get_or_create_pointer_plus_expr): Delete.
11702 (region_model::get_or_create_view): Delete.
11703 (region_model::get_lvalue_1): Convert from region_id to
11704 const region *.
11705 (region_model::get_rvalue_1): Convert from svalue_id to
11706 const svalue *.
11707 (region_model::get_ssa_name_regions_for_current_frame): New.
11708 (region_model::append_ssa_names_cb): New.
11709 (region_model::get_store_value): New.
11710 (region_model::copy_struct_region): Delete.
11711 (region_model::copy_union_region): Delete.
11712 (region_model::copy_array_region): Delete.
11713 (region_model::region_exists_p): New.
11714 (region_model::make_region_for_unexpected_tree_code): Delete.
11715 (region_model::loop_replay_fixup): New.
11716 (region_model::poison_any_pointers_to_bad_regions): Delete.
11717 (region_model::poison_any_pointers_to_descendents): New.
11718 (region_model::dump_summary_of_rep_path_vars): Delete.
11719 (region_model::on_top_level_param): New.
11720 (region_model::record_dynamic_extents): New.
11721 (region_model::m_mgr;): New.
11722 (region_model::m_store;): New.
11723 (region_model::m_svalues;): Delete.
11724 (region_model::m_regions;): Delete.
11725 (region_model::m_root_rid;): Delete.
11726 (region_model::m_current_frame;): New.
11727 (region_model_context::remap_svalue_ids): Delete.
11728 (region_model_context::can_purge_p): Delete.
11729 (region_model_context::on_svalue_leak): New.
11730 (region_model_context::on_svalue_purge): Delete.
11731 (region_model_context::on_liveness_change): New.
11732 (region_model_context::on_inherited_svalue): Delete.
11733 (region_model_context::on_cast): Delete.
11734 (region_model_context::on_unknown_change): Convert from svalue_id to
11735 const svalue * and add is_mutable.
11736 (class noop_region_model_context): Update for region_model_context
11737 changes.
11738 (model_merger::model_merger): Add program_point. Drop
11739 svalue_id_merger_mapping.
11740 (model_merger::dump_to_pp): Add "simple" param.
11741 (model_merger::dump): Likewise.
11742 (model_merger::get_region_a): Delete.
11743 (model_merger::get_region_b): Delete.
11744 (model_merger::can_merge_values_p): Delete.
11745 (model_merger::record_regions): Delete.
11746 (model_merger::record_svalues): Delete.
11747 (model_merger::m_point): New field.
11748 (model_merger::m_map_regions_from_a_to_m): Delete.
11749 (model_merger::m_map_regions_from_b_to_m): Delete.
11750 (model_merger::m_sid_mapping): Delete.
11751 (struct svalue_id_merger_mapping): Delete.
11752 (class engine): New.
11753 (struct canonicalization): Delete.
11754 (inchash::add): Delete decls for hashing svalue_id and region_id.
11755 (test_region_model_context::on_unexpected_tree_code): Require t to
11756 be non-NULL.
11757 (selftest::assert_condition): Add overload comparing a pair of
11758 const svalue *.
11759 * sm-file.cc: Include "tristate.h", "selftest.h",
11760 "analyzer/call-string.h", "analyzer/program-point.h",
11761 "analyzer/store.h", and "analyzer/region-model.h".
11762 (fileptr_state_machine::get_default_state): New.
11763 (fileptr_state_machine::on_stmt): Remove calls to
11764 get_readable_tree in favor of get_diagnostic_tree.
11765 * sm-malloc.cc: Include "tristate.h", "selftest.h",
11766 "analyzer/call-string.h", "analyzer/program-point.h",
11767 "analyzer/store.h", and "analyzer/region-model.h".
11768 (malloc_state_machine::get_default_state): New.
11769 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New.
11770 (malloc_diagnostic::describe_state_change): Handle change.m_expr
11771 being NULL.
11772 (null_arg::emit): Avoid printing "NULL '0'".
11773 (null_arg::describe_final_event): Avoid printing "(0) NULL".
11774 (malloc_leak::emit): Handle m_arg being NULL.
11775 (malloc_leak::describe_final_event): Handle ev.m_expr being NULL.
11776 (malloc_state_machine::on_stmt): Don't call get_readable_tree.
11777 Call get_diagnostic_tree when creating pending diagnostics.
11778 Update for is_zero_assignment becoming a member function of
11779 sm_ctxt.
11780 Don't transition to m_non_heap for ADDR_EXPR(MEM_REF()).
11781 (malloc_state_machine::reset_when_passed_to_unknown_fn_p): New
11782 vfunc implementation.
11783 * sm-sensitive.cc (sensitive_state_machine::warn_for_any_exposure): Call
11784 get_diagnostic_tree and pass the result to warn_for_state.
11785 * sm-signal.cc: Move includes of "analyzer/call-string.h" and
11786 "analyzer/program-point.h" to before "analyzer/region-model.h",
11787 and also include "analyzer/store.h" before it.
11788 (signal_unsafe_call::describe_state_change): Use
11789 get_dest_function to get handler.
11790 (update_model_for_signal_handler): Pass manager to region_model
11791 ctor.
11792 (register_signal_handler::impl_transition): Update for changes to
11793 get_or_create_node and add_edge.
11794 * sm-taint.cc (taint_state_machine::on_stmt): Remove calls to
11795 get_readable_tree, replacing them when calling warn_for_state with
11796 calls to get_diagnostic_tree.
11797 * sm.cc (is_zero_assignment): Delete.
11798 (any_pointer_p): Move to within namespace ana.
11799 * sm.h (is_zero_assignment): Remove decl.
11800 (any_pointer_p): Move decl to within namespace ana.
11801 (state_machine::get_default_state): New vfunc.
11802 (state_machine::reset_when_passed_to_unknown_fn_p): New vfunc.
11803 (sm_context::get_readable_tree): Rename to...
11804 (sm_context::get_diagnostic_tree): ...this.
11805 (sm_context::is_zero_assignment): New vfunc.
11806 * store.cc: New file.
11807 * store.h: New file.
11808 * svalue.cc: New file.
11809
11810 2020-05-22 Mark Wielaard <[email protected]>
11811
11812 * sm-signal.cc(signal_unsafe_call::emit): Possibly add
11813 gcc_rich_location note for replacement.
11814 (signal_unsafe_call::get_replacement_fn): New private function.
11815 (get_async_signal_unsafe_fns): Add "exit".
11816
11817 2020-04-28 David Malcolm <[email protected]>
11818
11819 PR analyzer/94816
11820 * engine.cc (impl_region_model_context::on_unexpected_tree_code):
11821 Handle NULL tree.
11822 * region-model.cc (region_model::add_region_for_type): Handle
11823 NULL type.
11824 * region-model.h
11825 (test_region_model_context::on_unexpected_tree_code): Handle NULL
11826 tree.
11827
11828 2020-04-28 David Malcolm <[email protected]>
11829
11830 PR analyzer/94447
11831 PR analyzer/94639
11832 PR analyzer/94732
11833 PR analyzer/94754
11834 * analyzer.opt (Wanalyzer-use-of-uninitialized-value): Delete.
11835 * program-state.cc (selftest::test_program_state_dumping): Update
11836 expected dump result for removal of "uninit".
11837 * region-model.cc (poison_kind_to_str): Delete POISON_KIND_UNINIT
11838 case.
11839 (root_region::ensure_stack_region): Initialize stack with null
11840 svalue_id rather than with a typeless POISON_KIND_UNINIT value.
11841 (root_region::ensure_heap_region): Likewise for the heap.
11842 (region_model::dump_summary_of_rep_path_vars): Remove
11843 summarization of uninit values.
11844 (region_model::validate): Remove check that the stack has a
11845 POISON_KIND_UNINIT value.
11846 (poisoned_value_diagnostic::emit): Remove POISON_KIND_UNINIT
11847 case.
11848 (poisoned_value_diagnostic::describe_final_event): Likewise.
11849 (selftest::test_dump): Update expected dump result for removal of
11850 "uninit".
11851 (selftest::test_svalue_equality): Remove "uninit" and "freed".
11852 * region-model.h (enum poison_kind): Remove POISON_KIND_UNINIT.
11853
11854 2020-04-01 David Malcolm <[email protected]>
11855
11856 PR analyzer/94378
11857 * checker-path.cc: Include "bitmap.h".
11858 * constraint-manager.cc: Likewise.
11859 * diagnostic-manager.cc: Likewise.
11860 * engine.cc: Likewise.
11861 (exploded_node::detect_leaks): Pass null region_id to pop_frame.
11862 * program-point.cc: Include "bitmap.h".
11863 * program-state.cc: Likewise.
11864 * region-model.cc (id_set<region_id>::id_set): Convert to...
11865 (region_id_set::region_id_set): ...this.
11866 (svalue_id_set::svalue_id_set): New ctor.
11867 (region_model::copy_region): New function.
11868 (region_model::copy_struct_region): New function.
11869 (region_model::copy_union_region): New function.
11870 (region_model::copy_array_region): New function.
11871 (stack_region::pop_frame): Drop return value. Add
11872 "result_dst_rid" param; if it is non-null, use copy_region to copy
11873 the result to it. Rather than capture and pass a single "known
11874 used" return value to be used by purge_unused_values, instead
11875 gather and pass a set of known used return values.
11876 (root_region::pop_frame): Drop return value. Add "result_dst_rid"
11877 param.
11878 (region_model::on_assignment): Use copy_region.
11879 (region_model::on_return): Likewise for the result.
11880 (region_model::on_longjmp): Pass null for pop_frame's
11881 result_dst_rid.
11882 (region_model::update_for_return_superedge): Pass the region for the
11883 return value of the call, if any, to pop_frame, rather than setting
11884 the lvalue for the lhs of the result.
11885 (region_model::pop_frame): Drop return value. Add
11886 "result_dst_rid" param.
11887 (region_model::purge_unused_svalues): Convert third param from an
11888 svalue_id * to an svalue_id_set *, updating the initial populating
11889 of the "used" bitmap accordingly. Don't remap it when done.
11890 (struct selftest::coord_test): New selftest fixture, extracted from...
11891 (selftest::test_dump_2): ...here.
11892 (selftest::test_compound_assignment): New selftest.
11893 (selftest::test_stack_frames): Pass null to new param of pop_frame.
11894 (selftest::analyzer_region_model_cc_tests): Call the new selftest.
11895 * region-model.h (class id_set): Delete template.
11896 (class region_id_set): Reimplement, using old id_set implementation.
11897 (class svalue_id_set): Likewise. Convert from auto_sbitmap to
11898 auto_bitmap.
11899 (region::get_active_view): New accessor.
11900 (stack_region::pop_frame): Drop return value. Add
11901 "result_dst_rid" param.
11902 (root_region::pop_frame): Likewise.
11903 (region_model::pop_frame): Likewise.
11904 (region_model::copy_region): New decl.
11905 (region_model::purge_unused_svalues): Convert third param from an
11906 svalue_id * to an svalue_id_set *.
11907 (region_model::copy_struct_region): New decl.
11908 (region_model::copy_union_region): New decl.
11909 (region_model::copy_array_region): New decl.
11910
11911 2020-03-27 David Malcolm <[email protected]>
11912
11913 * program-state.cc (selftest::test_program_state_dumping): Update
11914 expected dump to include symbolic_region's possibly_null field.
11915 * region-model.cc (symbolic_region::print_fields): New vfunc
11916 implementation.
11917 (region_model::add_constraint): Clear m_possibly_null from
11918 symbolic_regions now known to be non-NULL.
11919 (selftest::test_malloc_constraints): New selftest.
11920 (selftest::analyzer_region_model_cc_tests): Call it.
11921 * region-model.h (region::dyn_cast_symbolic_region): Add non-const
11922 overload.
11923 (symbolic_region::dyn_cast_symbolic_region): Implement it.
11924 (symbolic_region::print_fields): New vfunc override decl.
11925
11926 2020-03-27 David Malcolm <[email protected]>
11927
11928 * analyzer.h (class feasibility_problem): New forward decl.
11929 * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic):
11930 Initialize new fields m_status, m_epath_length, and m_problem.
11931 (saved_diagnostic::~saved_diagnostic): Delete m_problem.
11932 (dedupe_candidate::dedupe_candidate): Convert "sd" param from a
11933 const ref to a mutable ptr.
11934 (dedupe_winners::add): Convert "sd" param from a const ref to a
11935 mutable ptr. Record the length of the exploded_path. Record the
11936 feasibility/infeasibility of sd into sd, capturing a
11937 feasibility_problem when feasible_p fails, and storing it in sd.
11938 (diagnostic_manager::emit_saved_diagnostics): Update for pass by
11939 ptr rather than by const ref.
11940 * diagnostic-manager.h (class saved_diagnostic): Add new enum
11941 status. Add fields m_status, m_epath_length and m_problem.
11942 (saved_diagnostic::set_feasible): New member function.
11943 (saved_diagnostic::set_infeasible): New member function.
11944 (saved_diagnostic::get_feasibility_problem): New accessor.
11945 (saved_diagnostic::get_status): New accessor.
11946 (saved_diagnostic::set_epath_length): New member function.
11947 (saved_diagnostic::get_epath_length): New accessor.
11948 * engine.cc: Include "gimple-pretty-print.h".
11949 (exploded_path::feasible_p): Add OUT param and, if non-NULL, write
11950 a new feasibility_problem to it on failure.
11951 (viz_callgraph_node::dump_dot): Convert begin_tr calls to
11952 begin_trtd. Convert end_tr calls to end_tdtr.
11953 (class exploded_graph_annotator): New subclass of dot_annotator.
11954 (impl_run_checkers): Add a second -fdump-analyzer-supergraph dump
11955 after the analysis runs, using exploded_graph_annotator. dumping
11956 to DUMP_BASE_NAME.supergraph-eg.dot.
11957 * exploded-graph.h (exploded_node::get_dot_fillcolor): Make
11958 public.
11959 (exploded_path::feasible_p): Add OUT param.
11960 (class feasibility_problem): New class.
11961 * state-purge.cc (state_purge_annotator::add_node_annotations):
11962 Return a bool, add a "within_table" param.
11963 (print_vec_of_names): Convert begin_tr calls to begin_trtd.
11964 Convert end_tr calls to end_tdtr.
11965 (state_purge_annotator::add_stmt_annotations): Add "within_row"
11966 param.
11967 * state-purge.h ((state_purge_annotator::add_node_annotations):
11968 Return a bool, add a "within_table" param.
11969 (state_purge_annotator::add_stmt_annotations): Add "within_row"
11970 param.
11971 * supergraph.cc (supernode::dump_dot): Call add_node_annotations
11972 twice: as before, passing false for "within_table", then again
11973 with true when within the TABLE element. Convert some begin_tr
11974 calls to begin_trtd, and some end_tr calls to end_tdtr.
11975 Repeat each add_stmt_annotations call, distinguishing between
11976 calls that add TRs and those that add TDs to an existing TR.
11977 Add a call to add_after_node_annotations.
11978 * supergraph.h (dot_annotator::add_node_annotations): Add a
11979 "within_table" param.
11980 (dot_annotator::add_stmt_annotations): Add a "within_row" param.
11981 (dot_annotator::add_after_node_annotations): New vfunc.
11982
11983 2020-03-27 David Malcolm <[email protected]>
11984
11985 * diagnostic-manager.cc (dedupe_winners::add): Show the
11986 exploded_node index in the log messages.
11987 (diagnostic_manager::emit_saved_diagnostics): Log a summary of
11988 m_saved_diagnostics at entry.
11989
11990 2020-03-27 David Malcolm <[email protected]>
11991
11992 * supergraph.cc (superedge::dump): Add space before description;
11993 move newline to non-pretty_printer overload.
11994
11995 2020-03-18 David Malcolm <[email protected]>
11996
11997 * region-model.cc: Include "stor-layout.h".
11998 (region_model::dump_to_pp): Rather than calling
11999 dump_summary_of_map on each of the current frame and the globals,
12000 instead get a vec of representative path_vars for all regions,
12001 and then dump a summary of all of them.
12002 (region_model::dump_summary_of_map): Delete, rewriting into...
12003 (region_model::dump_summary_of_rep_path_vars): ...this new
12004 function, working on a vec of path_vars.
12005 (region_model::set_value): New overload.
12006 (region_model::get_representative_path_var): Rename
12007 "parent_region" local to "parent_reg" and consolidate with other
12008 local. Guard test for grandparent being stack on parent_reg being
12009 non-NULL. Move handling for parent being an array_region to
12010 within guard for parent_reg being non-NULL.
12011 (selftest::make_test_compound_type): New function.
12012 (selftest::test_dump_2): New selftest.
12013 (selftest::test_dump_3): New selftest.
12014 (selftest::test_stack_frames): Update expected output from
12015 simplified dump to show "a" and "b" from parent frame and "y" in
12016 child frame.
12017 (selftest::analyzer_region_model_cc_tests): Call test_dump_2 and
12018 test_dump_3.
12019 * region-model.h (region_model::set_value): New overload decl.
12020 (region_model::dump_summary_of_map): Delete.
12021 (region_model::dump_summary_of_rep_path_vars): New.
12022
12023 2020-03-18 David Malcolm <[email protected]>
12024
12025 * region-model.h (class noop_region_model_context): New subclass
12026 of region_model_context.
12027 (class tentative_region_model_context): Inherit from
12028 noop_region_model_context rather than from region_model_context;
12029 drop redundant vfunc implementations.
12030 (class test_region_model_context): Likewise.
12031
12032 2020-03-18 David Malcolm <[email protected]>
12033
12034 * engine.cc (exploded_node::exploded_node): Move implementation
12035 here from header; accept point_and_state by const reference rather
12036 than by value.
12037 * exploded-graph.h (exploded_node::exploded_node): Pass
12038 point_and_state by const reference rather than by value. Move
12039 body to engine.cc.
12040
12041 2020-03-18 Jakub Jelinek <[email protected]>
12042
12043 * sm-malloc.cc (malloc_state_machine::on_stmt): Fix up duplicated word
12044 issue in a comment.
12045 * region-model.cc (region_model::make_region_for_unexpected_tree_code,
12046 region_model::delete_region_and_descendents): Likewise.
12047 * engine.cc (class exploded_cluster): Likewise.
12048 * diagnostic-manager.cc (class path_builder): Likewise.
12049
12050 2020-03-13 David Malcolm <[email protected]>
12051
12052 PR analyzer/94099
12053 PR analyzer/94105
12054 * diagnostic-manager.cc (for_each_state_change): Bulletproof
12055 against errors in get_rvalue by passing a
12056 tentative_region_model_context and rejecting if there's an error.
12057 * region-model.cc (region_model::get_lvalue_1): When handling
12058 ARRAY_REF, handle results of error-handling. Handle NOP_EXPR.
12059
12060 2020-03-06 David Malcolm <[email protected]>
12061
12062 * analyzer.h (class array_region): New forward decl.
12063 * program-state.cc (selftest::test_program_state_dumping_2): New.
12064 (selftest::analyzer_program_state_cc_tests): Call it.
12065 * region-model.cc (array_region::constant_from_key): New.
12066 (region_model::get_representative_tree): Handle region_svalue by
12067 generating an ADDR_EXPR.
12068 (region_model::get_representative_path_var): In view handling,
12069 remove erroneous TREE_TYPE when determining the type of the tree.
12070 Handle array regions and STRING_CST.
12071 (selftest::assert_dump_tree_eq): New.
12072 (ASSERT_DUMP_TREE_EQ): New macro.
12073 (selftest::test_get_representative_tree): New selftest.
12074 (selftest::analyzer_region_model_cc_tests): Call it.
12075 * region-model.h (region::dyn_cast_array_region): New vfunc.
12076 (array_region::dyn_cast_array_region): New vfunc implementation.
12077 (array_region::constant_from_key): New decl.
12078
12079 2020-03-06 David Malcolm <[email protected]>
12080
12081 * analyzer.h (dump_quoted_tree): New decl.
12082 * engine.cc (exploded_node::dump_dot): Pass region model to
12083 sm_state_map::print.
12084 * program-state.cc: Include diagnostic-core.h.
12085 (sm_state_map::print): Add "model" param and use it to print
12086 representative trees. Only print origin information if non-null.
12087 (sm_state_map::dump): Pass NULL for model to print call.
12088 (program_state::print): Pass region model to sm_state_map::print.
12089 (program_state::dump_to_pp): Use spaces rather than newlines when
12090 summarizing. Pass region_model to sm_state_map::print.
12091 (ana::selftest::assert_dump_eq): New function.
12092 (ASSERT_DUMP_EQ): New macro.
12093 (ana::selftest::test_program_state_dumping): New function.
12094 (ana::selftest::analyzer_program_state_cc_tests): Call it.
12095 * program-state.h (program_state::print): Add model param.
12096 * region-model.cc (dump_quoted_tree): New function.
12097 (map_region::print_fields): Use dump_quoted_tree rather than
12098 %qE to avoid lang-dependent output.
12099 (map_region::dump_child_label): Likewise.
12100 (region_model::dump_summary_of_map): For SK_REGION, when
12101 get_representative_path_var fails, print the region id rather than
12102 erroneously printing NULL.
12103 * sm.cc (state_machine::get_state_by_name): New function.
12104 * sm.h (state_machine::get_state_by_name): New decl.
12105
12106 2020-03-04 David Malcolm <[email protected]>
12107
12108 * region-model.cc (region::validate): Convert model param from ptr
12109 to reference. Update comment to reflect that it's now a vfunc.
12110 (map_region::validate): New vfunc implementation.
12111 (array_region::validate): New vfunc implementation.
12112 (stack_region::validate): New vfunc implementation.
12113 (root_region::validate): New vfunc implementation.
12114 (region_model::validate): Pass a reference rather than a pointer
12115 to the region::validate vfunc.
12116 * region-model.h (region::validate): Make virtual. Convert model
12117 param from ptr to reference.
12118 (map_region::validate): New vfunc decl.
12119 (array_region::validate): New vfunc decl.
12120 (stack_region::validate): New vfunc decl.
12121 (root_region::validate): New vfunc decl.
12122
12123 2020-03-04 David Malcolm <[email protected]>
12124
12125 PR analyzer/93993
12126 * region-model.cc (region_model::on_call_pre): Handle
12127 BUILT_IN_EXPECT and its variants.
12128 (region_model::add_any_constraints_from_ssa_def_stmt): Split out
12129 gassign handling into add_any_constraints_from_gassign; add gcall
12130 handling.
12131 (region_model::add_any_constraints_from_gassign): New function,
12132 based on the above. Add handling for NOP_EXPR.
12133 (region_model::add_any_constraints_from_gcall): New function.
12134 (region_model::get_representative_path_var): Handle views.
12135 * region-model.h
12136 (region_model::add_any_constraints_from_ssa_def_stmt): New decl.
12137 (region_model::add_any_constraints_from_gassign): New decl.
12138
12139 2020-03-04 David Malcolm <[email protected]>
12140
12141 PR analyzer/93993
12142 * checker-path.h (state_change_event::get_lvalue): Add ctxt param
12143 and pass it to region_model::get_value call.
12144 * diagnostic-manager.cc (get_any_origin): Pass a
12145 tentative_region_model_context to the calls to get_lvalue and reject
12146 the comparison if errors occur.
12147 (can_be_expr_of_interest_p): New function.
12148 (diagnostic_manager::prune_for_sm_diagnostic): Replace checks for
12149 CONSTANT_CLASS_P with calls to update_for_unsuitable_sm_exprs.
12150 Pass a tentative_region_model_context to the calls to
12151 state_change_event::get_lvalue and reject the comparison if errors
12152 occur.
12153 (diagnostic_manager::update_for_unsuitable_sm_exprs): New.
12154 * diagnostic-manager.h
12155 (diagnostic_manager::update_for_unsuitable_sm_exprs): New decl.
12156 * region-model.h (class tentative_region_model_context): New class.
12157
12158 2020-03-04 David Malcolm <[email protected]>
12159
12160 * engine.cc (worklist::worklist): Remove unused field m_eg.
12161 (class viz_callgraph_edge): Remove unused field m_call_sedge.
12162 (class viz_callgraph): Remove unused field m_sg.
12163 * exploded-graph.h (worklist::::m_eg): Remove unused field.
12164
12165 2020-03-02 David Malcolm <[email protected]>
12166
12167 * analyzer.opt (fanalyzer-show-duplicate-count): New option.
12168 * diagnostic-manager.cc
12169 (diagnostic_manager::emit_saved_diagnostic): Use the above to
12170 guard the printing of the duplicate count.
12171
12172 2020-03-02 David Malcolm <[email protected]>
12173
12174 PR analyzer/93959
12175 * analyzer.cc (is_std_function_p): New function.
12176 (is_std_named_call_p): New functions.
12177 * analyzer.h (is_std_named_call_p): New decl.
12178 * sm-malloc.cc (malloc_state_machine::on_stmt): Check for "std::"
12179 variants when checking for malloc, calloc and free.
12180
12181 2020-02-26 David Malcolm <[email protected]>
12182
12183 PR analyzer/93950
12184 * diagnostic-manager.cc
12185 (diagnostic_manager::prune_for_sm_diagnostic): Assert that var is
12186 either NULL or not a constant. When updating var, bulletproof
12187 against constant values.
12188
12189 2020-02-26 David Malcolm <[email protected]>
12190
12191 PR analyzer/93947
12192 * region-model.cc (region_model::get_fndecl_for_call): Gracefully
12193 fail for fn_decls that don't have a cgraph_node.
12194
12195 2020-02-26 David Malcolm <[email protected]>
12196
12197 * bar-chart.cc: New file.
12198 * bar-chart.h: New file.
12199 * engine.cc: Include "analyzer/bar-chart.h".
12200 (stats::log): Only log the m_num_nodes kinds that are non-zero.
12201 (stats::dump): Likewise when dumping.
12202 (stats::get_total_enodes): New.
12203 (exploded_graph::get_or_create_node): Increment the per-point-data
12204 m_excess_enodes when hitting the per-program-point limit on
12205 enodes.
12206 (exploded_graph::print_bar_charts): New.
12207 (exploded_graph::log_stats): Log the number of unprocessed enodes
12208 in the worklist. Call print_bar_charts.
12209 (exploded_graph::dump_stats): Print the number of unprocessed
12210 enodes in the worklist.
12211 * exploded-graph.h (stats::get_total_enodes): New decl.
12212 (struct per_program_point_data): Add field m_excess_enodes.
12213 (exploded_graph::print_bar_charts): New decl.
12214 * supergraph.cc (superedge::dump): New.
12215 (superedge::dump): New.
12216 * supergraph.h (supernode::get_function): New.
12217 (superedge::dump): New decl.
12218 (superedge::dump): New decl.
12219
12220 2020-02-24 David Malcolm <[email protected]>
12221
12222 * engine.cc (exploded_graph::get_or_create_node): Dump the
12223 program_state to the pp, rather than to stderr.
12224
12225 2020-02-24 David Malcolm <[email protected]>
12226
12227 PR analyzer/93032
12228 * sm.cc (make_checkers): Require the "taint" checker to be
12229 explicitly enabled.
12230
12231 2020-02-24 David Malcolm <[email protected]>
12232
12233 PR analyzer/93899
12234 * engine.cc
12235 (impl_region_model_context::impl_region_model_context): Add logger
12236 param.
12237 * engine.cc (exploded_graph::add_function_entry): Create an
12238 impl_region_model_context and pass it to the push_frame call.
12239 Bail if the resulting state is invalid.
12240 (exploded_graph::build_initial_worklist): Likewise.
12241 (exploded_graph::build_initial_worklist): Handle the case where
12242 add_function_entry fails.
12243 * exploded-graph.h
12244 (impl_region_model_context::impl_region_model_context): Add logger
12245 param.
12246 * region-model.cc (map_region::get_or_create): Add ctxt param and
12247 pass it to add_region_for_type.
12248 (map_region::can_merge_p): Pass NULL as a ctxt to call to
12249 get_or_create.
12250 (array_region::get_element): Pass ctxt to call to get_or_create.
12251 (array_region::get_or_create): Add ctxt param and pass it to
12252 add_region_for_type.
12253 (root_region::push_frame): Pass ctxt to get_or_create calls.
12254 (region_model::get_lvalue_1): Likewise.
12255 (region_model::make_region_for_unexpected_tree_code): Assert that
12256 ctxt is non-NULL.
12257 (region_model::get_rvalue_1): Pass ctxt to get_svalue_for_fndecl
12258 and get_svalue_for_label calls.
12259 (region_model::get_svalue_for_fndecl): Add ctxt param and pass it
12260 to get_region_for_fndecl.
12261 (region_model::get_region_for_fndecl): Add ctxt param and pass it
12262 to get_or_create.
12263 (region_model::get_svalue_for_label): Add ctxt param and pass it
12264 to get_region_for_label.
12265 (region_model::get_region_for_label): Add ctxt param and pass it
12266 to get_region_for_fndecl and get_or_create.
12267 (region_model::get_field_region): Add ctxt param and pass it to
12268 get_or_create_view and get_or_create.
12269 (make_region_for_type): Replace gcc_unreachable with return NULL.
12270 (region_model::add_region_for_type): Add ctxt param. Handle a
12271 return of NULL from make_region_for_type by calling
12272 make_region_for_unexpected_tree_code.
12273 (region_model::get_or_create_mem_ref): Pass ctxt to calls to
12274 get_or_create_view.
12275 (region_model::get_or_create_view): Add ctxt param and pass it to
12276 add_region_for_type.
12277 (selftest::test_state_merging): Pass ctxt to get_or_create_view.
12278 * region-model.h (region_model::get_or_create): Add ctxt param.
12279 (region_model::add_region_for_type): Likewise.
12280 (region_model::get_svalue_for_fndecl): Likewise.
12281 (region_model::get_svalue_for_label): Likewise.
12282 (region_model::get_region_for_fndecl): Likewise.
12283 (region_model::get_region_for_label): Likewise.
12284 (region_model::get_field_region): Likewise.
12285 (region_model::get_or_create_view): Likewise.
12286
12287 2020-02-24 David Malcolm <[email protected]>
12288
12289 * checker-path.cc (superedge_event::should_filter_p): Update
12290 filter for empty descriptions to cover verbosity level 3 as well
12291 as 2.
12292 * diagnostic-manager.cc: Include "analyzer/reachability.h".
12293 (class path_builder): New class.
12294 (diagnostic_manager::emit_saved_diagnostic): Create a path_builder
12295 and pass it to build_emission_path, rather passing eg; similarly
12296 for add_events_for_eedge and ext_state.
12297 (diagnostic_manager::build_emission_path): Replace "eg" param
12298 with a path_builder, pass it to add_events_for_eedge.
12299 (diagnostic_manager::add_events_for_eedge): Replace ext_state
12300 param with path_builder; pass it to add_events_for_superedge.
12301 (diagnostic_manager::significant_edge_p): New.
12302 (diagnostic_manager::add_events_for_superedge): Add path_builder
12303 param. Reject insignificant edges at verbosity levels below 3.
12304 (diagnostic_manager::prune_for_sm_diagnostic): Update highest
12305 verbosity level to 4.
12306 * diagnostic-manager.h (class path_builder): New forward decl.
12307 (diagnostic_manager::build_emission_path): Replace "eg" param
12308 with a path_builder.
12309 (diagnostic_manager::add_events_for_eedge): Replace ext_state
12310 param with path_builder.
12311 (diagnostic_manager::significant_edge_p): New.
12312 (diagnostic_manager::add_events_for_superedge): Add path_builder
12313 param.
12314 * reachability.h: New file.
12315
12316 2020-02-18 David Malcolm <[email protected]>
12317
12318 PR analyzer/93692
12319 * analyzer.opt (fdump-analyzer-callgraph): Rewrite description.
12320
12321 2020-02-18 David Malcolm <[email protected]>
12322
12323 PR analyzer/93777
12324 * region-model.cc (region_model::maybe_cast_1): Replace assertion
12325 that build_cast returns non-NULL with a conditional, falling
12326 through to the logic which returns a new unknown value of the
12327 desired type if it fails.
12328
12329 2020-02-18 David Malcolm <[email protected]>
12330
12331 PR analyzer/93778
12332 * engine.cc (impl_region_model_context::on_unknown_tree_code):
12333 Rename to...
12334 (impl_region_model_context::on_unexpected_tree_code): ...this and
12335 convert first argument from path_var to tree.
12336 (exploded_node::on_stmt): Pass ctxt to purge_for_unknown_fncall.
12337 * exploded-graph.h (region_model_context::on_unknown_tree_code):
12338 Rename to...
12339 (region_model_context::on_unexpected_tree_code): ...this and
12340 convert first argument from path_var to tree.
12341 * program-state.cc (sm_state_map::purge_for_unknown_fncall): Add
12342 ctxt param and pass on to calls to get_rvalue.
12343 * program-state.h (sm_state_map::purge_for_unknown_fncall): Add
12344 ctxt param.
12345 * region-model.cc (region_model::handle_unrecognized_call): Pass
12346 ctxt on to call to get_rvalue.
12347 (region_model::get_lvalue_1): Move body of default case to
12348 region_model::make_region_for_unexpected_tree_code and call it.
12349 Within COMPONENT_REF case, reject attempts to handle types other
12350 than RECORD_TYPE and UNION_TYPE.
12351 (region_model::make_region_for_unexpected_tree_code): New
12352 function, based on default case of region_model::get_lvalue_1.
12353 * region-model.h
12354 (region_model::make_region_for_unexpected_tree_code): New decl.
12355 (region_model::on_unknown_tree_code): Rename to...
12356 (region_model::on_unexpected_tree_code): ...this and convert first
12357 argument from path_var to tree.
12358 (class test_region_model_context): Update vfunc implementation for
12359 above change.
12360
12361 2020-02-18 David Malcolm <[email protected]>
12362
12363 PR analyzer/93774
12364 * region-model.cc
12365 (region_model::convert_byte_offset_to_array_index): Use
12366 int_size_in_bytes before calling size_in_bytes, to gracefully fail
12367 on incomplete types.
12368
12369 2020-02-17 David Malcolm <[email protected]>
12370
12371 PR analyzer/93775
12372 * region-model.cc (region_model::get_fndecl_for_call): Handle the
12373 case where the code_region's get_tree_for_child_region returns
12374 NULL.
12375
12376 2020-02-17 David Malcolm <[email protected]>
12377
12378 PR analyzer/93388
12379 * engine.cc (impl_region_model_context::on_unknown_tree_code):
12380 New.
12381 (exploded_graph::get_or_create_node): Reject invalid states.
12382 * exploded-graph.h
12383 (impl_region_model_context::on_unknown_tree_code): New decl.
12384 (point_and_state::point_and_state): Assert that the state is
12385 valid.
12386 * program-state.cc (program_state::program_state): Initialize
12387 m_valid to true.
12388 (program_state::operator=): Copy m_valid.
12389 (program_state::program_state): Likewise for move constructor.
12390 (program_state::print): Print m_valid.
12391 (program_state::dump_to_pp): Likewise.
12392 * program-state.h (program_state::m_valid): New field.
12393 * region-model.cc (region_model::get_lvalue_1): Implement the
12394 default case by returning a new symbolic region and calling
12395 the context's on_unknown_tree_code, rather than issuing an
12396 internal_error. Implement VIEW_CONVERT_EXPR.
12397 * region-model.h (region_model_context::on_unknown_tree_code): New
12398 vfunc.
12399 (test_region_model_context::on_unknown_tree_code): New.
12400
12401 2020-02-17 David Malcolm <[email protected]>
12402
12403 * sm-malloc.cc (malloc_diagnostic::describe_state_change): For
12404 transition to the "null" state, only say "assuming" when
12405 transitioning from the "unchecked" state.
12406
12407 2020-02-17 David Malcolm <[email protected]>
12408
12409 * diagnostic-manager.h (diagnostic_manager::get_saved_diagnostic):
12410 Add const overload.
12411 * engine.cc (exploded_node::dump_dot): Dump saved_diagnostics.
12412 * exploded-graph.h (exploded_graph::get_diagnostic_manager): Add
12413 const overload.
12414
12415 2020-02-11 David Malcolm <[email protected]>
12416
12417 PR analyzer/93288
12418 * analysis-plan.cc (analysis_plan::use_summary_p): Look through
12419 the ultimate_alias_target when getting the called function.
12420 * engine.cc (exploded_node::on_stmt): Rename second "ctxt" to
12421 "sm_ctxt". Use the region_model's get_fndecl_for_call rather than
12422 gimple_call_fndecl.
12423 * region-model.cc (region_model::get_fndecl_for_call): Use
12424 ultimate_alias_target on fndecl.
12425 * supergraph.cc (get_ultimate_function_for_cgraph_edge): New
12426 function.
12427 (supergraph_call_edge): Use it when rejecting edges without
12428 functions.
12429 (supergraph::supergraph): Use it to get the function for the
12430 cgraph_edge when building interprocedural superedges.
12431 (callgraph_superedge::get_callee_function): Use it.
12432 * supergraph.h (supergraph::get_num_snodes): Make param const.
12433 (supergraph::function_to_num_snodes_t): Make first type param
12434 const.
12435
12436 2020-02-11 David Malcolm <[email protected]>
12437
12438 PR analyzer/93374
12439 * engine.cc (exploded_edge::exploded_edge): Add ext_state param
12440 and pass it to change.validate.
12441 (exploded_graph::get_or_create_node): Move purging of change
12442 svalues to also cover the case of reusing an existing enode.
12443 (exploded_graph::add_edge): Pass m_ext_state to exploded_edge's
12444 ctor.
12445 * exploded-graph.h (exploded_edge::exploded_edge): Add ext_state
12446 param.
12447 * program-state.cc (state_change::sm_change::validate): Likewise.
12448 Assert that m_sm_idx is sane. Use ext_state to validate
12449 m_old_state and m_new_state.
12450 (state_change::validate): Add ext_state param and pass it to
12451 the sm_change validate calls.
12452 * program-state.h (state_change::sm_change::validate): Add
12453 ext_state param.
12454 (state_change::validate): Likewise.
12455
12456 2020-02-11 David Malcolm <[email protected]>
12457
12458 PR analyzer/93669
12459 * engine.cc (exploded_graph::dump_exploded_nodes): Handle missing
12460 case of STATUS_WORKLIST in implementation of
12461 "__analyzer_dump_exploded_nodes".
12462
12463 2020-02-11 David Malcolm <[email protected]>
12464
12465 PR analyzer/93649
12466 * constraint-manager.cc (constraint_manager::add_constraint): When
12467 merging equivalence classes and updating m_constant, also update
12468 m_cst_sid.
12469 (constraint_manager::validate): If m_constant is non-NULL assert
12470 that m_cst_sid is non-null and is valid.
12471
12472 2020-02-11 David Malcolm <[email protected]>
12473
12474 PR analyzer/93657
12475 * analyzer.opt (fdump-analyzer): Reword description.
12476 (fdump-analyzer-stderr): Likewise.
12477
12478 2020-02-11 David Malcolm <[email protected]>
12479
12480 * region-model.cc (print_quoted_type): New function.
12481 (svalue::print): Use it to replace %qT.
12482 (region::dump_to_pp): Likewise.
12483 (region::dump_child_label): Likewise.
12484 (region::print_fields): Likewise.
12485
12486 2020-02-10 David Malcolm <[email protected]>
12487
12488 PR analyzer/93659
12489 * analyzer.opt (-param=analyzer-max-recursion-depth=): Fix "tha"
12490 -> "that" typo.
12491 (Wanalyzer-use-of-uninitialized-value): Fix "initialized" ->
12492 "uninitialized" typo.
12493
12494 2020-02-10 David Malcolm <[email protected]>
12495
12496 PR analyzer/93350
12497 * region-model.cc (region_model::get_lvalue_1):
12498 Handle BIT_FIELD_REF.
12499 (make_region_for_type): Handle VECTOR_TYPE.
12500
12501 2020-02-10 David Malcolm <[email protected]>
12502
12503 PR analyzer/93647
12504 * diagnostic-manager.cc
12505 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof against
12506 VAR being constant.
12507 * region-model.cc (region_model::get_lvalue_1): Provide a better
12508 error message when encountering an unhandled tree code.
12509
12510 2020-02-10 David Malcolm <[email protected]>
12511
12512 PR analyzer/93405
12513 * region-model.cc (region_model::get_lvalue_1): Implement
12514 CONST_DECL.
12515
12516 2020-02-06 David Malcolm <[email protected]>
12517
12518 * region-model.cc (region_model::maybe_cast_1): Attempt to provide
12519 a region_svalue if either type is a pointer, rather than if both
12520 types are pointers.
12521
12522 2020-02-05 David Malcolm <[email protected]>
12523
12524 * engine.cc (exploded_node::dump_dot): Show merger enodes.
12525 (worklist::add_node): Assert that the node's m_status is
12526 STATUS_WORKLIST.
12527 (exploded_graph::process_worklist): Likewise for nodes from the
12528 worklist. Set status of merged nodes to STATUS_MERGER.
12529 (exploded_graph::process_node): Set status of node to
12530 STATUS_PROCESSED.
12531 (exploded_graph::dump_exploded_nodes): Rework handling of
12532 "__analyzer_dump_exploded_nodes", splitting enodes by status into
12533 "processed" and "merger", showing the count of just the processed
12534 enodes at the call, rather than the count of all enodes.
12535 * exploded-graph.h (exploded_node::status): New enum.
12536 (exploded_node::exploded_node): Initialize m_status to
12537 STATUS_WORKLIST.
12538 (exploded_node::get_status): New getter.
12539 (exploded_node::set_status): New setter.
12540
12541 2020-02-04 David Malcolm <[email protected]>
12542
12543 PR analyzer/93543
12544 * engine.cc (pod_hash_traits<function_call_string>::mark_empty):
12545 Eliminate reinterpret_cast.
12546 (pod_hash_traits<function_call_string>::is_empty): Likewise.
12547
12548 2020-02-03 David Malcolm <[email protected]>
12549
12550 * constraint-manager.cc (range::constrained_to_single_element):
12551 Replace fold_build2 with fold_binary. Remove unnecessary newline.
12552 (constraint_manager::get_or_add_equiv_class): Replace fold_build2
12553 with fold_binary in two places, and remove out-of-date comment.
12554 (constraint_manager::eval_condition): Replace fold_build2 with
12555 fold_binary.
12556 * region-model.cc (constant_svalue::eval_condition): Likewise.
12557 (region_model::on_assignment): Likewise.
12558
12559 2020-02-03 David Malcolm <[email protected]>
12560
12561 PR analyzer/93544
12562 * diagnostic-manager.cc
12563 (diagnostic_manager::prune_for_sm_diagnostic): Bulletproof
12564 against bad choices due to bad paths.
12565 * engine.cc (impl_region_model_context::on_phi): New.
12566 * exploded-graph.h (impl_region_model_context::on_phi): New decl.
12567 * region-model.cc (region_model::on_longjmp): Likewise.
12568 (region_model::handle_phi): Add phi param. Call the ctxt's on_phi
12569 vfunc.
12570 (region_model::update_for_phis): Pass phi to handle_phi.
12571 * region-model.h (region_model::handle_phi): Add phi param.
12572 (region_model_context::on_phi): New vfunc.
12573 (test_region_model_context::on_phi): New.
12574 * sm-malloc.cc (malloc_state_machine::on_phi): New.
12575 (malloc_state_machine::on_zero_assignment): New.
12576 * sm.h (state_machine::on_phi): New vfunc.
12577
12578 2020-02-03 David Malcolm <[email protected]>
12579
12580 * engine.cc (supernode_cluster::dump_dot): Show BB index as
12581 well as SN index.
12582 * supergraph.cc (supernode::dump_dot): Likewise.
12583
12584 2020-02-03 David Malcolm <[email protected]>
12585
12586 PR analyzer/93546
12587 * region-model.cc (region_model::on_call_pre): Update for new
12588 param of symbolic_region ctor.
12589 (region_model::deref_rvalue): Likewise.
12590 (region_model::add_new_malloc_region): Likewise.
12591 (make_region_for_type): Likewise, preserving type.
12592 * region-model.h (symbolic_region::symbolic_region): Add "type"
12593 param and pass it to base class ctor.
12594
12595 2020-02-03 David Malcolm <[email protected]>
12596
12597 PR analyzer/93547
12598 * constraint-manager.cc
12599 (constraint_manager::get_or_add_equiv_class): Ensure types are
12600 compatible before comparing constants.
12601
12602 2020-01-31 David Malcolm <[email protected]>
12603
12604 PR analyzer/93457
12605 * region-model.cc (make_region_for_type): Use VOID_TYPE_P rather
12606 than checking against void_type_node.
12607
12608 2020-01-31 David Malcolm <[email protected]>
12609
12610 PR analyzer/93373
12611 * region-model.cc (ASSERT_COMPAT_TYPES): Convert to...
12612 (assert_compat_types): ...this, and bail when either type is NULL,
12613 or when VOID_TYPE_P (dst_type).
12614 (region_model::get_lvalue): Update for above conversion.
12615 (region_model::get_rvalue): Likewise.
12616
12617 2020-01-31 David Malcolm <[email protected]>
12618
12619 PR analyzer/93379
12620 * region-model.cc (region_model::update_for_return_superedge):
12621 Move check for null result so that it also guards setting the
12622 lhs.
12623
12624 2020-01-31 David Malcolm <[email protected]>
12625
12626 PR analyzer/93438
12627 * region-model.cc (stack_region::can_merge_p): Split into a two
12628 pass approach, creating all stack regions first, then populating
12629 them.
12630 (selftest::test_state_merging): Add test coverage for (a) the case
12631 of self-merging a model in which a local in an older stack frame
12632 points to a local in a more recent stack frame (which previously
12633 would ICE), and (b) the case of self-merging a model in which a
12634 local points to a global (which previously worked OK).
12635
12636 2020-01-31 David Malcolm <[email protected]>
12637
12638 * analyzer.cc (is_named_call_p): Replace tests for fndecl being
12639 extern at file scope and having a non-NULL DECL_NAME with a call
12640 to maybe_special_function_p.
12641 * function-set.cc (function_set::contains_decl_p): Add call to
12642 maybe_special_function_p.
12643
12644 2020-01-31 David Malcolm <[email protected]>
12645
12646 PR analyzer/93450
12647 * constraint-manager.cc
12648 (constraint_manager::get_or_add_equiv_class): Only compare constants
12649 if their types are compatible.
12650 * region-model.cc (constant_svalue::eval_condition): Replace check
12651 for identical types with call to types_compatible_p.
12652
12653 2020-01-30 David Malcolm <[email protected]>
12654
12655 * program-state.cc (extrinsic_state::dump_to_pp): New.
12656 (extrinsic_state::dump_to_file): New.
12657 (extrinsic_state::dump): New.
12658 * program-state.h (extrinsic_state::dump_to_pp): New decl.
12659 (extrinsic_state::dump_to_file): New decl.
12660 (extrinsic_state::dump): New decl.
12661 * sm.cc: Include "pretty-print.h".
12662 (state_machine::dump_to_pp): New.
12663 * sm.h (state_machine::dump_to_pp): New decl.
12664
12665 2020-01-30 David Malcolm <[email protected]>
12666
12667 * diagnostic-manager.cc (for_each_state_change): Use
12668 extrinsic_state::get_num_checkers rather than accessing m_checkers
12669 directly.
12670 * program-state.cc (program_state::program_state): Likewise.
12671 * program-state.h (extrinsic_state::m_checkers): Make private.
12672
12673 2020-01-30 David Malcolm <[email protected]>
12674
12675 PR analyzer/93356
12676 * region-model.cc (region_model::eval_condition): In both
12677 overloads, bail out immediately on floating-point types.
12678 (region_model::eval_condition_without_cm): Likewise.
12679 (region_model::add_constraint): Likewise.
12680
12681 2020-01-30 David Malcolm <[email protected]>
12682
12683 PR analyzer/93450
12684 * program-state.cc (sm_state_map::set_state): For the overload
12685 taking an svalue_id, bail out if the set_state on the ec does
12686 nothing. Convert the latter's return type from void to bool,
12687 returning true if anything changed.
12688 (sm_state_map::impl_set_state): Convert the return type from void
12689 to bool, returning true if the state changed.
12690 * program-state.h (sm_state_map::set_state): Convert return type
12691 from void to bool.
12692 (sm_state_map::impl_set_state): Likewise.
12693 * region-model.cc (constant_svalue::eval_condition): Only call
12694 fold_build2 if the types are the same.
12695
12696 2020-01-29 Jakub Jelinek <[email protected]>
12697
12698 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Remove.
12699 * constraint-manager.cc: Include diagnostic-core.h before graphviz.h.
12700 (range::dump, equiv_class::print): Don't use PUSH_IGNORE_WFORMAT or
12701 POP_IGNORE_WFORMAT.
12702 * state-purge.cc: Include diagnostic-core.h before
12703 gimple-pretty-print.h.
12704 (state_purge_annotator::add_node_annotations, print_vec_of_names):
12705 Don't use PUSH_IGNORE_WFORMAT or POP_IGNORE_WFORMAT.
12706 * region-model.cc: Move diagnostic-core.h include before graphviz.h.
12707 (path_var::dump, svalue::print, constant_svalue::print_details,
12708 region::dump_to_pp, region::dump_child_label, region::print_fields,
12709 map_region::print_fields, map_region::dump_dot_to_pp,
12710 map_region::dump_child_label, array_region::print_fields,
12711 array_region::dump_dot_to_pp): Don't use PUSH_IGNORE_WFORMAT or
12712 POP_IGNORE_WFORMAT.
12713
12714 2020-01-28 David Malcolm <[email protected]>
12715
12716 PR analyzer/93316
12717 * engine.cc (rewind_info_t::update_model): Get the longjmp call
12718 stmt via get_longjmp_call () rather than assuming it is the last
12719 stmt in the longjmp's supernode.
12720 (rewind_info_t::add_events_to_path): Get the location_t for the
12721 rewind_from_longjmp_event via get_longjmp_call () rather than from
12722 the supernode's get_end_location ().
12723
12724 2020-01-28 David Malcolm <[email protected]>
12725
12726 * region-model.cc (poisoned_value_diagnostic::emit): Update for
12727 renaming of warning_at overload to warning_meta.
12728 * sm-file.cc (file_leak::emit): Likewise.
12729 * sm-malloc.cc (double_free::emit): Likewise.
12730 (possible_null_deref::emit): Likewise.
12731 (possible_null_arg::emit): Likewise.
12732 (null_deref::emit): Likewise.
12733 (null_arg::emit): Likewise.
12734 (use_after_free::emit): Likewise.
12735 (malloc_leak::emit): Likewise.
12736 (free_of_non_heap::emit): Likewise.
12737 * sm-sensitive.cc (exposure_through_output_file::emit): Likewise.
12738 * sm-signal.cc (signal_unsafe_call::emit): Likewise.
12739 * sm-taint.cc (tainted_array_index::emit): Likewise.
12740
12741 2020-01-27 David Malcolm <[email protected]>
12742
12743 PR analyzer/93451
12744 * region-model.cc (tree_cmp): For the REAL_CST case, impose an
12745 arbitrary order on NaNs relative to other NaNs and to non-NaNs;
12746 const-correctness tweak.
12747 (ana::selftests::build_real_cst_from_string): New function.
12748 (ana::selftests::append_interesting_constants): New function.
12749 (ana::selftests::test_tree_cmp_on_constants): New test.
12750 (ana::selftests::test_canonicalization_4): New test.
12751 (ana::selftests::analyzer_region_model_cc_tests): Call the new
12752 tests.
12753
12754 2020-01-27 David Malcolm <[email protected]>
12755
12756 PR analyzer/93349
12757 * engine.cc (run_checkers): Save and restore input_location.
12758
12759 2020-01-27 David Malcolm <[email protected]>
12760
12761 * call-string.cc (call_string::cmp_1): Delete, moving body to...
12762 (call_string::cmp): ...here.
12763 * call-string.h (call_string::cmp_1): Delete decl.
12764 * engine.cc (worklist::key_t::cmp_1): Delete, moving body to...
12765 (worklist::key_t::cmp): ...here. Implement hash comparisons
12766 via comparison rather than subtraction to avoid overflow issues.
12767 * exploded-graph.h (worklist::key_t::cmp_1): Delete decl.
12768 * region-model.cc (tree_cmp): Eliminate buggy checking for
12769 symmetry.
12770
12771 2020-01-27 David Malcolm <[email protected]>
12772
12773 * analyzer.cc (is_named_call_p): Check that fndecl is "extern"
12774 and at file scope. Potentially disregard prefix _ or __ in
12775 fndecl's name. Bail if the identifier is NULL.
12776 (is_setjmp_call_p): Expect a gcall rather than plain gimple.
12777 Remove special-case check for leading prefix, and also check for
12778 sigsetjmp.
12779 (is_longjmp_call_p): Also check for siglongjmp.
12780 (get_user_facing_name): New function.
12781 * analyzer.h (is_setjmp_call_p): Expect a gcall rather than plain
12782 gimple.
12783 (get_user_facing_name): New decl.
12784 * checker-path.cc (setjmp_event::get_desc): Use
12785 get_user_facing_name to avoid hardcoding the function name.
12786 (rewind_event::rewind_event): Add rewind_info param, using it to
12787 initialize new m_rewind_info field, and strengthen the assertion.
12788 (rewind_from_longjmp_event::get_desc): Use get_user_facing_name to
12789 avoid hardcoding the function name.
12790 (rewind_to_setjmp_event::get_desc): Likewise.
12791 * checker-path.h (setjmp_event::setjmp_event): Add setjmp_call
12792 param and use it to initialize...
12793 (setjmp_event::m_setjmp_call): New field.
12794 (rewind_event::rewind_event): Add rewind_info param.
12795 (rewind_event::m_rewind_info): New protected field.
12796 (rewind_from_longjmp_event::rewind_from_longjmp_event): Add
12797 rewind_info param.
12798 (class rewind_to_setjmp_event): Move rewind_info field to parent
12799 class.
12800 * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
12801 Update setjmp-handling for is_setjmp_call_p requiring a gcall;
12802 pass the call to the new setjmp_event.
12803 * engine.cc (exploded_node::on_stmt): Update for is_setjmp_call_p
12804 requiring a gcall.
12805 (stale_jmp_buf::emit): Use get_user_facing_name to avoid
12806 hardcoding the function names.
12807 (exploded_node::on_longjmp): Pass the longjmp_call when
12808 constructing rewind_info.
12809 (rewind_info_t::add_events_to_path): Pass the rewind_info_t to the
12810 rewind_from_longjmp_event's ctor.
12811 * exploded-graph.h (rewind_info_t::rewind_info_t): Add
12812 longjmp_call param.
12813 (rewind_info_t::get_longjmp_call): New.
12814 (rewind_info_t::m_longjmp_call): New.
12815 * region-model.cc (region_model::on_setjmp): Update comment to
12816 indicate this is also for sigsetjmp.
12817 * region-model.h (struct setjmp_record): Likewise.
12818 (class setjmp_svalue): Likewise.
12819
12820 2020-01-27 David Malcolm <[email protected]>
12821
12822 PR analyzer/93276
12823 * analyzer.h (PUSH_IGNORE_WFORMAT, POP_IGNORE_WFORMAT): Guard these
12824 macros with GCC_VERSION >= 4006, making them no-op otherwise.
12825 * engine.cc (exploded_edge::exploded_edge): Specify template for
12826 base class initializer.
12827 (exploded_graph::add_edge): Specify template when chaining up to
12828 base class add_edge implementation.
12829 (viz_callgraph_node::dump_dot): Drop redundant "typename".
12830 (viz_callgraph_edge::viz_callgraph_edge): Specify template for
12831 base class initializer.
12832 * program-state.cc (sm_state_map::clone_with_remapping): Drop
12833 redundant "typename".
12834 (sm_state_map::print): Likewise.
12835 (sm_state_map::hash): Likewise.
12836 (sm_state_map::operator==): Likewise.
12837 (sm_state_map::remap_svalue_ids): Likewise.
12838 (sm_state_map::on_svalue_purge): Likewise.
12839 (sm_state_map::validate): Likewise.
12840 * program-state.h (sm_state_map::iterator_t): Likewise.
12841 * supergraph.h (superedge::superedge): Specify template for base
12842 class initializer.
12843
12844 2020-01-23 David Malcolm <[email protected]>
12845
12846 PR analyzer/93375
12847 * supergraph.cc (callgraph_superedge::get_arg_for_parm): Fail
12848 gracefully is the number of parameters at the callee exceeds the
12849 number of arguments at the call stmt.
12850 (callgraph_superedge::get_parm_for_arg): Likewise.
12851
12852 2020-01-22 David Malcolm <[email protected]>
12853
12854 PR analyzer/93382
12855 * program-state.cc (sm_state_map::on_svalue_purge): If the
12856 entry survives, but the origin is being purged, then reset the
12857 origin to null.
12858
12859 2020-01-22 David Malcolm <[email protected]>
12860
12861 * sm-signal.cc: Fix nesting of CHECKING_P and namespace ana.
12862
12863 2020-01-22 David Malcolm <[email protected]>
12864
12865 PR analyzer/93378
12866 * engine.cc (setjmp_svalue::compare_fields): Update for
12867 replacement of m_enode with m_setjmp_record.
12868 (setjmp_svalue::add_to_hash): Likewise.
12869 (setjmp_svalue::get_index): Rename...
12870 (setjmp_svalue::get_enode_index): ...to this.
12871 (setjmp_svalue::print_details): Update for replacement of m_enode
12872 with m_setjmp_record.
12873 (exploded_node::on_longjmp): Likewise.
12874 * exploded-graph.h (rewind_info_t::m_enode_origin): Replace...
12875 (rewind_info_t::m_setjmp_record): ...with this.
12876 (rewind_info_t::rewind_info_t): Update for replacement of m_enode
12877 with m_setjmp_record.
12878 (rewind_info_t::get_setjmp_point): Likewise.
12879 (rewind_info_t::get_setjmp_call): Likewise.
12880 * region-model.cc (region_model::dump_summary_of_map): Likewise.
12881 (region_model::on_setjmp): Likewise.
12882 * region-model.h (struct setjmp_record): New struct.
12883 (setjmp_svalue::m_enode): Replace...
12884 (setjmp_svalue::m_setjmp_record): ...with this.
12885 (setjmp_svalue::setjmp_svalue): Update for replacement of m_enode
12886 with m_setjmp_record.
12887 (setjmp_svalue::clone): Likewise.
12888 (setjmp_svalue::get_index): Rename...
12889 (setjmp_svalue::get_enode_index): ...to this.
12890 (setjmp_svalue::get_exploded_node): Replace...
12891 (setjmp_svalue::get_setjmp_record): ...with this.
12892
12893 2020-01-22 David Malcolm <[email protected]>
12894
12895 PR analyzer/93316
12896 * analyzer.cc (is_setjmp_call_p): Check for "setjmp" as well as
12897 "_setjmp".
12898
12899 2020-01-22 David Malcolm <[email protected]>
12900
12901 PR analyzer/93307
12902 * analysis-plan.h: Wrap everything namespace "ana".
12903 * analyzer-logging.cc: Likewise.
12904 * analyzer-logging.h: Likewise.
12905 * analyzer-pass.cc (pass_analyzer::execute): Update for "ana"
12906 namespace.
12907 * analyzer-selftests.cc: Wrap everything namespace "ana".
12908 * analyzer-selftests.h: Likewise.
12909 * analyzer.h: Likewise for forward decls of types.
12910 * call-string.h: Likewise.
12911 * checker-path.cc: Likewise.
12912 * checker-path.h: Likewise.
12913 * constraint-manager.cc: Likewise.
12914 * constraint-manager.h: Likewise.
12915 * diagnostic-manager.cc: Likewise.
12916 * diagnostic-manager.h: Likewise.
12917 * engine.cc: Likewise.
12918 * engine.h: Likewise.
12919 * exploded-graph.h: Likewise.
12920 * function-set.cc: Likewise.
12921 * function-set.h: Likewise.
12922 * pending-diagnostic.cc: Likewise.
12923 * pending-diagnostic.h: Likewise.
12924 * program-point.cc: Likewise.
12925 * program-point.h: Likewise.
12926 * program-state.cc: Likewise.
12927 * program-state.h: Likewise.
12928 * region-model.cc: Likewise.
12929 * region-model.h: Likewise.
12930 * sm-file.cc: Likewise.
12931 * sm-malloc.cc: Likewise.
12932 * sm-pattern-test.cc: Likewise.
12933 * sm-sensitive.cc: Likewise.
12934 * sm-signal.cc: Likewise.
12935 * sm-taint.cc: Likewise.
12936 * sm.cc: Likewise.
12937 * sm.h: Likewise.
12938 * state-purge.h: Likewise.
12939 * supergraph.cc: Likewise.
12940 * supergraph.h: Likewise.
12941
12942 2020-01-21 David Malcolm <[email protected]>
12943
12944 PR analyzer/93352
12945 * region-model.cc (int_cmp): Rename to...
12946 (array_region::key_cmp): ...this, using key_t rather than int.
12947 Rewrite in terms of comparisons rather than subtraction to
12948 ensure qsort is anti-symmetric when handling extreme values.
12949 (array_region::walk_for_canonicalization): Update for above
12950 renaming.
12951 * region-model.h (array_region::key_cmp): New decl.
12952
12953 2020-01-17 David Malcolm <[email protected]>
12954
12955 PR analyzer/93290
12956 * region-model.cc (region_model::eval_condition_without_cm): Avoid
12957 gcc_unreachable for unexpected operations for the case where
12958 we're comparing an svalue against itself.
12959
12960 2020-01-17 David Malcolm <[email protected]>
12961
12962 PR analyzer/93281
12963 * region-model.cc
12964 (region_model::convert_byte_offset_to_array_index): Convert to
12965 ssizetype before dividing by byte_size. Use fold_binary rather
12966 than fold_build2 to avoid needlessly constructing a tree for the
12967 non-const case.
12968
12969 2020-01-15 David Malcolm <[email protected]>
12970
12971 * engine.cc (class impl_region_model_context): Fix comment.
12972
12973 2020-01-14 David Malcolm <[email protected]>
12974
12975 PR analyzer/93212
12976 * region-model.cc (make_region_for_type): Use
12977 FUNC_OR_METHOD_TYPE_P rather than comparing against FUNCTION_TYPE.
12978 * region-model.h (function_region::function_region): Likewise.
12979
12980 2020-01-14 David Malcolm <[email protected]>
12981
12982 * program-state.cc (sm_state_map::clone_with_remapping): Copy
12983 m_global_state.
12984 (selftest::test_program_state_merging_2): New selftest.
12985 (selftest::analyzer_program_state_cc_tests): Call it.
12986
12987 2020-01-14 David Malcolm <[email protected]>
12988
12989 * checker-path.h (checker_path::get_checker_event): New function.
12990 (checker_path): Add DISABLE_COPY_AND_ASSIGN; make fields private.
12991 * diagnostic-manager.cc
12992 (diagnostic_manager::prune_for_sm_diagnostic): Replace direct
12993 access to checker_path::m_events with accessor functions. Fix
12994 overlong line.
12995 (diagnostic_manager::prune_interproc_events): Replace direct
12996 access to checker_path::m_events with accessor functions.
12997 (diagnostic_manager::finish_pruning): Likewise.
12998
12999 2020-01-14 David Malcolm <[email protected]>
13000
13001 * checker-path.h (checker_event::clone): Delete vfunc decl.
13002 (debug_event::clone): Delete vfunc impl.
13003 (custom_event::clone): Delete vfunc impl.
13004 (statement_event::clone): Delete vfunc impl.
13005 (function_entry_event::clone): Delete vfunc impl.
13006 (state_change_event::clone): Delete vfunc impl.
13007 (start_cfg_edge_event::clone): Delete vfunc impl.
13008 (end_cfg_edge_event::clone): Delete vfunc impl.
13009 (call_event::clone): Delete vfunc impl.
13010 (return_event::clone): Delete vfunc impl.
13011 (setjmp_event::clone): Delete vfunc impl.
13012 (rewind_from_longjmp_event::clone): Delete vfunc impl.
13013 (rewind_to_setjmp_event::clone): Delete vfunc impl.
13014 (warning_event::clone): Delete vfunc impl.
13015
13016 2020-01-14 David Malcolm <[email protected]>
13017
13018 * supergraph.cc (supernode::dump_dot): Ensure that the TABLE
13019 element has at least one TR.
13020
13021 2020-01-14 David Malcolm <[email protected]>
13022
13023 PR analyzer/58237
13024 * engine.cc (leak_stmt_finder::find_stmt): Use get_pure_location
13025 when comparing against UNKNOWN_LOCATION.
13026 (stmt_requires_new_enode_p): Likewise.
13027 (exploded_graph::dump_exploded_nodes): Likewise.
13028 * supergraph.cc (supernode::get_start_location): Likewise.
13029 (supernode::get_end_location): Likewise.
13030
13031 2020-01-14 David Malcolm <[email protected]>
13032
13033 PR analyzer/58237
13034 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
13035 selftest::analyzer_sm_file_cc_tests.
13036 * analyzer-selftests.h (selftest::analyzer_sm_file_cc_tests): New
13037 decl.
13038 * sm-file.cc: Include "analyzer/function-set.h" and
13039 "analyzer/analyzer-selftests.h".
13040 (get_file_using_fns): New function.
13041 (is_file_using_fn_p): New function.
13042 (fileptr_state_machine::on_stmt): Return true for known functions.
13043 (selftest::analyzer_sm_file_cc_tests): New function.
13044
13045 2020-01-14 David Malcolm <[email protected]>
13046
13047 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
13048 selftest::analyzer_sm_signal_cc_tests.
13049 * analyzer-selftests.h (selftest::analyzer_sm_signal_cc_tests):
13050 New decl.
13051 * sm-signal.cc: Include "analyzer/function-set.h" and
13052 "analyzer/analyzer-selftests.h".
13053 (get_async_signal_unsafe_fns): New function.
13054 (signal_unsafe_p): Reimplement in terms of the above.
13055 (selftest::analyzer_sm_signal_cc_tests): New function.
13056
13057 2020-01-14 David Malcolm <[email protected]>
13058
13059 * analyzer-selftests.cc (selftest::run_analyzer_selftests): Call
13060 selftest::analyzer_function_set_cc_tests.
13061 * analyzer-selftests.h (selftest::analyzer_function_set_cc_tests):
13062 New decl.
13063 * function-set.cc: New file.
13064 * function-set.h: New file.
13065
13066 2020-01-14 David Malcolm <[email protected]>
13067
13068 * analyzer.h (fndecl_has_gimple_body_p): New decl.
13069 * engine.cc (impl_region_model_context::on_unknown_change): New
13070 function.
13071 (fndecl_has_gimple_body_p): Make non-static.
13072 (exploded_node::on_stmt): Treat __analyzer_dump_exploded_nodes as
13073 known. Track whether we have a call with unknown side-effects and
13074 pass it to on_call_post.
13075 * exploded-graph.h (impl_region_model_context::on_unknown_change):
13076 New decl.
13077 * program-state.cc (sm_state_map::on_unknown_change): New function.
13078 * program-state.h (sm_state_map::on_unknown_change): New decl.
13079 * region-model.cc: Include "bitmap.h".
13080 (region_model::on_call_pre): Return a bool, capturing whether the
13081 call has unknown side effects.
13082 (region_model::on_call_post): Add arg "bool unknown_side_effects"
13083 and if true, call handle_unrecognized_call.
13084 (class reachable_regions): New class.
13085 (region_model::handle_unrecognized_call): New function.
13086 * region-model.h (region_model::on_call_pre): Return a bool.
13087 (region_model::on_call_post): Add arg "bool unknown_side_effects".
13088 (region_model::handle_unrecognized_call): New decl.
13089 (region_model_context::on_unknown_change): New vfunc.
13090 (test_region_model_context::on_unknown_change): New function.
13091
13092 2020-01-14 David Malcolm <[email protected]>
13093
13094 * diagnostic-manager.cc (saved_diagnostic::operator==): Move here
13095 from header. Replace pointer equality test on m_var with call to
13096 pending_diagnostic::same_tree_p.
13097 * diagnostic-manager.h (saved_diagnostic::operator==): Move to
13098 diagnostic-manager.cc.
13099 * pending-diagnostic.cc (pending_diagnostic::same_tree_p): New.
13100 * pending-diagnostic.h (pending_diagnostic::same_tree_p): New.
13101 * sm-file.cc (file_diagnostic::subclass_equal_p): Replace pointer
13102 equality on m_arg with call to pending_diagnostic::same_tree_p.
13103 * sm-malloc.cc (malloc_diagnostic::subclass_equal_p): Likewise.
13104 (possible_null_arg::subclass_equal_p): Likewise.
13105 (null_arg::subclass_equal_p): Likewise.
13106 (free_of_non_heap::subclass_equal_p): Likewise.
13107 * sm-pattern-test.cc (pattern_match::operator==): Likewise.
13108 * sm-sensitive.cc (exposure_through_output_file::operator==):
13109 Likewise.
13110 * sm-taint.cc (tainted_array_index::operator==): Likewise.
13111
13112 2020-01-14 David Malcolm <[email protected]>
13113
13114 * diagnostic-manager.cc (dedupe_winners::add): Add logging
13115 of deduplication decisions made.
13116
13117 2020-01-14 David Malcolm <[email protected]>
13118
13119 * ChangeLog: New file.
13120 * analyzer-selftests.cc: New file.
13121 * analyzer-selftests.h: New file.
13122 * analyzer.opt: New file.
13123 * analysis-plan.cc: New file.
13124 * analysis-plan.h: New file.
13125 * analyzer-logging.cc: New file.
13126 * analyzer-logging.h: New file.
13127 * analyzer-pass.cc: New file.
13128 * analyzer.cc: New file.
13129 * analyzer.h: New file.
13130 * call-string.cc: New file.
13131 * call-string.h: New file.
13132 * checker-path.cc: New file.
13133 * checker-path.h: New file.
13134 * constraint-manager.cc: New file.
13135 * constraint-manager.h: New file.
13136 * diagnostic-manager.cc: New file.
13137 * diagnostic-manager.h: New file.
13138 * engine.cc: New file.
13139 * engine.h: New file.
13140 * exploded-graph.h: New file.
13141 * pending-diagnostic.cc: New file.
13142 * pending-diagnostic.h: New file.
13143 * program-point.cc: New file.
13144 * program-point.h: New file.
13145 * program-state.cc: New file.
13146 * program-state.h: New file.
13147 * region-model.cc: New file.
13148 * region-model.h: New file.
13149 * sm-file.cc: New file.
13150 * sm-malloc.cc: New file.
13151 * sm-malloc.dot: New file.
13152 * sm-pattern-test.cc: New file.
13153 * sm-sensitive.cc: New file.
13154 * sm-signal.cc: New file.
13155 * sm-taint.cc: New file.
13156 * sm.cc: New file.
13157 * sm.h: New file.
13158 * state-purge.cc: New file.
13159 * state-purge.h: New file.
13160 * supergraph.cc: New file.
13161 * supergraph.h: New file.
13162
13163 2019-12-13 David Malcolm <[email protected]>
13164
13165 * Initial creation
13166
13167 Copyright (C) 2019-2025 Free Software Foundation, Inc.
13168
13169 Copying and distribution of this file, with or without modification,
13170 are permitted in any medium without royalty provided the copyright
13171 notice and this notice are preserved.