aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/sm-file.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2022-11-29 19:56:27 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2022-11-29 19:56:27 -0500
commit78a17f4452db9514da7cc8706c654cb98ba0a8e6 (patch)
tree0acd6c93c966982c457ec3c02391901d8fa1aaf8 /gcc/analyzer/sm-file.cc
parent3a32fb2eaa761aac13ffe5424748d5839038ef66 (diff)
downloadgcc-78a17f4452db9514da7cc8706c654cb98ba0a8e6.zip
gcc-78a17f4452db9514da7cc8706c654cb98ba0a8e6.tar.gz
gcc-78a17f4452db9514da7cc8706c654cb98ba0a8e6.tar.bz2
analyzer work on issues with flex-generated lexers [PR103546]
PR analyzer/103546 tracks various false positives seen on flex-generated lexers. Whilst investigating them, I noticed an ICE with -fanalyzer-call-summaries due to attempting to store sm-state for an UNKNOWN svalue, which this patch fixes. This patch also provides known_function implementations of all of the external functions called by the lexer, reducing the number of false positives. The patch doesn't eliminate all false positives, but adds integration tests to try to establish a baseline from which the remaining false positives can be fixed. gcc/analyzer/ChangeLog: PR analyzer/103546 * analyzer.h (register_known_file_functions): New decl. * program-state.cc (sm_state_map::replay_call_summary): Rejct attempts to store sm-state for caller_sval that can't have associated state. * region-model-impl-calls.cc (register_known_functions): Call register_known_file_functions. * sm-fd.cc (class kf_isatty): New. (register_known_fd_functions): Register it. * sm-file.cc (class kf_ferror): New. (class kf_fileno): New. (class kf_getc): New. (register_known_file_functions): New. gcc/ChangeLog: PR analyzer/103546 * doc/invoke.texi (Static Analyzer Options): Add isatty, ferror, fileno, and getc to the list of functions known to the analyzer. gcc/testsuite/ChangeLog: PR analyzer/103546 * gcc.dg/analyzer/ferror-1.c: New test. * gcc.dg/analyzer/fileno-1.c: New test. * gcc.dg/analyzer/flex-with-call-summaries.c: New test. * gcc.dg/analyzer/flex-without-call-summaries.c: New test. * gcc.dg/analyzer/getc-1.c: New test. * gcc.dg/analyzer/isatty-1.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer/sm-file.cc')
-rw-r--r--gcc/analyzer/sm-file.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index cbd1788..083c0ec 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -489,6 +489,59 @@ make_fileptr_state_machine (logger *logger)
return new fileptr_state_machine (logger);
}
+/* Handler for "ferror"". */
+
+class kf_ferror : public known_function
+{
+public:
+ bool matches_call_types_p (const call_details &cd) const final override
+ {
+ return (cd.num_args () == 1
+ && cd.arg_is_pointer_p (0));
+ }
+
+ /* No side effects. */
+};
+
+/* Handler for "fileno"". */
+
+class kf_fileno : public known_function
+{
+public:
+ bool matches_call_types_p (const call_details &cd) const final override
+ {
+ return (cd.num_args () == 1
+ && cd.arg_is_pointer_p (0));
+ }
+
+ /* No side effects. */
+};
+
+/* Handler for "getc"". */
+
+class kf_getc : public known_function
+{
+public:
+ bool matches_call_types_p (const call_details &cd) const final override
+ {
+ return (cd.num_args () == 1
+ && cd.arg_is_pointer_p (0));
+ }
+
+ /* No side effects. */
+};
+
+/* Populate KFM with instances of known functions relating to
+ stdio streams. */
+
+void
+register_known_file_functions (known_function_manager &kfm)
+{
+ kfm.add ("ferror", make_unique<kf_ferror> ());
+ kfm.add ("fileno", make_unique<kf_fileno> ());
+ kfm.add ("getc", make_unique<kf_getc> ());
+}
+
#if CHECKING_P
namespace selftest {