diff options
author | David Malcolm <dmalcolm@redhat.com> | 2022-10-26 16:45:17 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2022-10-26 16:45:17 -0400 |
commit | 57bbf3a403bb1e77c5081dc25d2d54e5c3d5aae4 (patch) | |
tree | 47b211413c221db4ed8e57b11323980f98de9165 /gcc/analyzer/sm-fd.cc | |
parent | 593254ae03a6c0db5946e44b2cfd90dbfc707a17 (diff) | |
download | gcc-57bbf3a403bb1e77c5081dc25d2d54e5c3d5aae4.zip gcc-57bbf3a403bb1e77c5081dc25d2d54e5c3d5aae4.tar.gz gcc-57bbf3a403bb1e77c5081dc25d2d54e5c3d5aae4.tar.bz2 |
analyzer: fixes to file-descriptor handling
gcc/analyzer/ChangeLog:
* sm-fd.cc (fd_state_machine::on_open): Transition to "unchecked"
when the mode is symbolic, rather than just on integer constants.
(fd_state_machine::check_for_open_fd): Don't complain about
unchecked values in the start state.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/fd-3.c (test_5): Expect "opened here" message
even when flags are symbolic.
(test_read_from_symbolic_fd): New.
(test_write_to_symbolic_fd): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer/sm-fd.cc')
-rw-r--r-- | gcc/analyzer/sm-fd.cc | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc index 8a4c208..ae846cd 100644 --- a/gcc/analyzer/sm-fd.cc +++ b/gcc/analyzer/sm-fd.cc @@ -940,25 +940,25 @@ fd_state_machine::on_open (sm_context *sm_ctxt, const supernode *node, if (lhs) { tree arg = gimple_call_arg (call, 1); + enum access_mode mode = READ_WRITE; if (TREE_CODE (arg) == INTEGER_CST) { int flag = TREE_INT_CST_LOW (arg); - enum access_mode mode = get_access_mode_from_flag (flag); - - switch (mode) - { - case READ_ONLY: - sm_ctxt->on_transition (node, stmt, lhs, m_start, - m_unchecked_read_only); - break; - case WRITE_ONLY: - sm_ctxt->on_transition (node, stmt, lhs, m_start, - m_unchecked_write_only); - break; - default: - sm_ctxt->on_transition (node, stmt, lhs, m_start, - m_unchecked_read_write); - } + mode = get_access_mode_from_flag (flag); + } + switch (mode) + { + case READ_ONLY: + sm_ctxt->on_transition (node, stmt, lhs, m_start, + m_unchecked_read_only); + break; + case WRITE_ONLY: + sm_ctxt->on_transition (node, stmt, lhs, m_start, + m_unchecked_write_only); + break; + default: + sm_ctxt->on_transition (node, stmt, lhs, m_start, + m_unchecked_read_write); } } else @@ -1096,7 +1096,7 @@ fd_state_machine::check_for_open_fd ( else { - if (!(is_valid_fd_p (state) || (state == m_stop))) + if (!(is_valid_fd_p (state) || state == m_start || state == m_stop)) { if (!is_constant_fd_p (state)) sm_ctxt->warn ( |