analyzer: log the stashing of named constants [PR107711]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Nov 2022 22:38:24 +0000 (17:38 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Nov 2022 22:38:24 +0000 (17:38 -0500)
commit6e4962810fe5de95b807d1ac675df45a725e31a2
treee36a00964ce29aedea3a2448dac3507470db8dc2
parentbdd784fc48a283d54f5f1e3cc2a0668c14dd3bee
analyzer: log the stashing of named constants [PR107711]

PR analyzer/107711 seems to be a bug in how named constants are looked up
by the analyzer in the C frontend.

To help debug this, this patch extends -fdump-analyzer and
-fdump-analyzer-stderr so that they dump this part of the analyzer's
startup.

gcc/analyzer/ChangeLog:
PR analyzer/107711
* analyzer-language.cc: Include "diagnostic.h".
(maybe_stash_named_constant): Add logger param and use it to log
the name being looked up, and the result.
(stash_named_constants): New, splitting out from...
(on_finish_translation_unit): ...this function.  Call
get_or_create_logfile and use the result to create a logger
instance, passing it to stash_named_constants.
* analyzer.h (get_or_create_any_logfile): New decl.
* engine.cc (dump_fout, owns_dump_fout): New globals, split out
from run_checkers.
(get_or_create_any_logfile): New function, split out from...
(run_checkers): ...here, so that the logfile can be opened by
on_finish_translation_unit.  Clear the globals when closing the
dump file.

gcc/testsuite/ChangeLog:
PR analyzer/107711
* gcc.dg/analyzer/fdump-analyzer-1.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/analyzer-language.cc
gcc/analyzer/analyzer.h
gcc/analyzer/engine.cc
gcc/testsuite/gcc.dg/analyzer/fdump-analyzer-1.c [new file with mode: 0644]