public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] analyzer: fix for ICE in sm-fd.cc [PR106551]
@ 2022-08-15  8:32 Immad Mir
  2022-08-15 15:48 ` David Malcolm
  0 siblings, 1 reply; 2+ messages in thread
From: Immad Mir @ 2022-08-15  8:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: dmalcolm, Immad Mir

This patch fixes the ICE caused by valid_to_unchecked_state
in sm-fd.cc by exiting early if first argument of any "dup"
functions is invalid.

gcc/analyzer/ChangeLog:
	PR analyzer/106551
	* sm-fd.cc (check_for_dup): exit early if first
	argument is invalid for all dup functions.

gcc/testsuite/ChangeLog:
	PR analyzer/106551
	* gcc.dg/analyzer/fd-dup-1.c: New testcase.

Signed-off-by: Immad Mir <mirimmad@outlook.com>
---
 gcc/analyzer/sm-fd.cc                    |  3 +--
 gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c | 11 +++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index e02b86baad1..505d598f3f0 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -976,8 +976,7 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node,
     {
       check_for_open_fd (sm_ctxt, node, stmt, call, callee_fndecl,
 			 DIRS_READ_WRITE);
-      if (kind == DUP_1)
-	return;
+      return;
     }
   switch (kind)
     {
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c b/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c
index b971d31b1c7..b4f43e7f0ef 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-dup-1.c
@@ -245,4 +245,15 @@ test_22 (int flags)
     close (fd);
 }
 
+void do_something();
+void
+test_23 ()
+{
+    int nullfd = -1;
+    int fd = 1;
+    if (dup2 (nullfd, fd) < 0) /* { dg-warning "'dup2' on possibly invalid file descriptor 'nullfd'" } */
+    {
+        do_something();
+    }
+}
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] analyzer: fix for ICE in sm-fd.cc [PR106551]
  2022-08-15  8:32 [PATCH] analyzer: fix for ICE in sm-fd.cc [PR106551] Immad Mir
@ 2022-08-15 15:48 ` David Malcolm
  0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2022-08-15 15:48 UTC (permalink / raw)
  To: mirimnan017, gcc-patches; +Cc: Immad Mir

On Mon, 2022-08-15 at 14:02 +0530, Immad Mir wrote:
> This patch fixes the ICE caused by valid_to_unchecked_state
> in sm-fd.cc by exiting early if first argument of any "dup"
> functions is invalid.
> 
> gcc/analyzer/ChangeLog:
>         PR analyzer/106551
>         * sm-fd.cc (check_for_dup): exit early if first
>         argument is invalid for all dup functions.
> 
> gcc/testsuite/ChangeLog:
>         PR analyzer/106551
>         * gcc.dg/analyzer/fd-dup-1.c: New testcase.
> 
> Signed-off-by: Immad Mir <mirimmad@outlook.com>

Thanks; looks good to me.

Dave


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-15 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15  8:32 [PATCH] analyzer: fix for ICE in sm-fd.cc [PR106551] Immad Mir
2022-08-15 15:48 ` David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).