analyzer: fix ICE casued by dup2 in sm-fd.cc[PR106551]

Message ID CY4PR1801MB1910BE8FDD5A0BB33AA927A7C6629@CY4PR1801MB1910.namprd18.prod.outlook.com
State New, archived
Headers
Series analyzer: fix ICE casued by dup2 in sm-fd.cc[PR106551] |

Commit Message

Immad Mir Aug. 9, 2022, 7:46 a.m. UTC
  This patch fixes the ICE caused by valid_to_unchecked_state,
at analyzer/sm-fd.cc by handling the m_start state in
check_for_dup.

Tested lightly on x86_64.

gcc/analyzer/ChangeLog:
	PR analyzer/106551
	* sm-fd.cc (check_for_dup): handle the m_start
	state when transitioning the state of LHS
	of dup, dup2 and dup3 call.

Signed-off-by: Immad Mir <mirimmad@outlook.com>
---
 gcc/analyzer/sm-fd.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

David Malcolm Aug. 9, 2022, 3:12 p.m. UTC | #1
On Tue, 2022-08-09 at 13:16 +0530, Immad Mir wrote:
> This patch fixes the ICE caused by valid_to_unchecked_state,
> at analyzer/sm-fd.cc by handling the m_start state in
> check_for_dup.
> 
> Tested lightly on x86_64.
> 
> gcc/analyzer/ChangeLog:
>         PR analyzer/106551
>         * sm-fd.cc (check_for_dup): handle the m_start
>         state when transitioning the state of LHS
>         of dup, dup2 and dup3 call.
> 
> Signed-off-by: Immad Mir <mirimmad@outlook.com>
> ---
>  gcc/analyzer/sm-fd.cc | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
> index 8bb76d72b05..c8b9930a7b6 100644
> --- a/gcc/analyzer/sm-fd.cc
> +++ b/gcc/analyzer/sm-fd.cc
> @@ -983,7 +983,7 @@ fd_state_machine::check_for_dup (sm_context
> *sm_ctxt, const supernode *node,
>      case DUP_1:
>        if (lhs)
>         {
> -         if (is_constant_fd_p (state_arg_1))
> +         if (is_constant_fd_p (state_arg_1) || state_arg_1 ==
> m_start)
>             sm_ctxt->set_next_state (stmt, lhs,
> m_unchecked_read_write);
>           else
>             sm_ctxt->set_next_state (stmt, lhs,
> @@ -1011,7 +1011,7 @@ fd_state_machine::check_for_dup (sm_context
> *sm_ctxt, const supernode *node,
>        file descriptor i.e the first argument.  */
>        if (lhs)
>         {
> -         if (is_constant_fd_p (state_arg_1))
> +         if (is_constant_fd_p (state_arg_1) || state_arg_1 ==
> m_start)
>             sm_ctxt->set_next_state (stmt, lhs,
> m_unchecked_read_write);
>           else
>             sm_ctxt->set_next_state (stmt, lhs,

Thanks.  The fix looks reasonable, but please can the patch also add a
reproducer to the test suite, covering each of the three dup/dup2/dup3
entrypoints - presumably the one from the bug can be used/adapted.

Dave
  
Mir Immad Aug. 9, 2022, 4:14 p.m. UTC | #2
Thanks. I've added few testcases that use uninitialized ints in dup, dup2,
and dup3.

Immad.

On Tue, Aug 9, 2022 at 8:43 PM David Malcolm <dmalcolm@redhat.com> wrote:

> On Tue, 2022-08-09 at 13:16 +0530, Immad Mir wrote:
> > This patch fixes the ICE caused by valid_to_unchecked_state,
> > at analyzer/sm-fd.cc by handling the m_start state in
> > check_for_dup.
> >
> > Tested lightly on x86_64.
> >
> > gcc/analyzer/ChangeLog:
> >         PR analyzer/106551
> >         * sm-fd.cc (check_for_dup): handle the m_start
> >         state when transitioning the state of LHS
> >         of dup, dup2 and dup3 call.
> >
> > Signed-off-by: Immad Mir <mirimmad@outlook.com>
> > ---
> >  gcc/analyzer/sm-fd.cc | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
> > index 8bb76d72b05..c8b9930a7b6 100644
> > --- a/gcc/analyzer/sm-fd.cc
> > +++ b/gcc/analyzer/sm-fd.cc
> > @@ -983,7 +983,7 @@ fd_state_machine::check_for_dup (sm_context
> > *sm_ctxt, const supernode *node,
> >      case DUP_1:
> >        if (lhs)
> >         {
> > -         if (is_constant_fd_p (state_arg_1))
> > +         if (is_constant_fd_p (state_arg_1) || state_arg_1 ==
> > m_start)
> >             sm_ctxt->set_next_state (stmt, lhs,
> > m_unchecked_read_write);
> >           else
> >             sm_ctxt->set_next_state (stmt, lhs,
> > @@ -1011,7 +1011,7 @@ fd_state_machine::check_for_dup (sm_context
> > *sm_ctxt, const supernode *node,
> >        file descriptor i.e the first argument.  */
> >        if (lhs)
> >         {
> > -         if (is_constant_fd_p (state_arg_1))
> > +         if (is_constant_fd_p (state_arg_1) || state_arg_1 ==
> > m_start)
> >             sm_ctxt->set_next_state (stmt, lhs,
> > m_unchecked_read_write);
> >           else
> >             sm_ctxt->set_next_state (stmt, lhs,
>
> Thanks.  The fix looks reasonable, but please can the patch also add a
> reproducer to the test suite, covering each of the three dup/dup2/dup3
> entrypoints - presumably the one from the bug can be used/adapted.
>
> Dave
>
>
  

Patch

diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index 8bb76d72b05..c8b9930a7b6 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -983,7 +983,7 @@  fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
     case DUP_1:
       if (lhs)
 	{
-	  if (is_constant_fd_p (state_arg_1))
+	  if (is_constant_fd_p (state_arg_1) || state_arg_1 == m_start)
 	    sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write);
 	  else
 	    sm_ctxt->set_next_state (stmt, lhs,
@@ -1011,7 +1011,7 @@  fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
       file descriptor i.e the first argument.  */
       if (lhs)
 	{
-	  if (is_constant_fd_p (state_arg_1))
+	  if (is_constant_fd_p (state_arg_1) || state_arg_1 == m_start)
 	    sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write);
 	  else
 	    sm_ctxt->set_next_state (stmt, lhs,