public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/3] analyzer: reorder initialization of state m_invalid in sm-fd.cc [PR106184]
       [not found] <20220706142543.3790-1-mirimmad@outlook.com>
@ 2022-07-06 14:25 ` Immad Mir
  2022-07-06 15:29   ` David Malcolm
  2022-07-06 14:25 ` [PATCH 3/3] analyzer: add a new testcase to demonstrate passsing of a file descriptor to a function that does not emit any warning Immad Mir
  1 sibling, 1 reply; 4+ messages in thread
From: Immad Mir @ 2022-07-06 14:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: dmalcolm, mirimnan017, Immad Mir, Immad Mir

From: Immad Mir <mirimmad17@gmail.com>

This patch reorders the initialization of state m_invalid in sm-fd.cc
to conform with standard practice in C++.

gcc/analyzer/ChangeLog:
	PR analyzer/106184
	* sm-fd.cc (fd_state_machine): Change ordering of initialization
	of state m_invalid.

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

diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
index 8196d33223a..8e4300b06e2 100644
--- a/gcc/analyzer/sm-fd.cc
+++ b/gcc/analyzer/sm-fd.cc
@@ -551,11 +551,12 @@ fd_state_machine::fd_state_machine (logger *logger)
       m_unchecked_read_write (add_state ("fd-unchecked-read-write")),
       m_unchecked_read_only (add_state ("fd-unchecked-read-only")),
       m_unchecked_write_only (add_state ("fd-unchecked-write-only")),
-      m_invalid (add_state ("fd-invalid")),
       m_valid_read_write (add_state ("fd-valid-read-write")),
       m_valid_read_only (add_state ("fd-valid-read-only")),
       m_valid_write_only (add_state ("fd-valid-write-only")),
-      m_closed (add_state ("fd-closed")), m_stop (add_state ("fd-stop"))
+      m_invalid (add_state ("fd-invalid")),
+      m_closed (add_state ("fd-closed")),
+      m_stop (add_state ("fd-stop"))
 {
 }
 
-- 
2.25.1


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

* [PATCH 3/3] analyzer: add a new testcase to demonstrate passsing of a file descriptor to a function that does not emit any warning
       [not found] <20220706142543.3790-1-mirimmad@outlook.com>
  2022-07-06 14:25 ` [PATCH 2/3] analyzer: reorder initialization of state m_invalid in sm-fd.cc [PR106184] Immad Mir
@ 2022-07-06 14:25 ` Immad Mir
  2022-07-06 15:37   ` David Malcolm
  1 sibling, 1 reply; 4+ messages in thread
From: Immad Mir @ 2022-07-06 14:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: dmalcolm, mirimnan017, Immad Mir

gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/fd-4.c: Add a new testcase to demonstrate passsing
	of a file descriptor to a function that does not emit any warning.

Signed-off-by: Immad Mir <mirimmad@outlook.com>
---
 gcc/testsuite/gcc.dg/analyzer/fd-4.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
index c992db619e7..fcfa6168efa 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
 int open(const char *, int mode);
 void close(int fd);
 int write (int fd, void *buf, int nbytes);
@@ -60,3 +62,11 @@ test_4 (const char *path, void *buf)
         /* {dg-message "\\(3\\) 'write' on closed file descriptor 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */
     }
 }
+
+void
+test_5 (const char *path)
+{
+    int fd = open (path, O_RDWR);
+    close(fd);
+    printf("%d", fd); /* { dg-bogus "'printf' on a closed file descriptor 'fd'" } */
+}
\ No newline at end of file
-- 
2.25.1


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

* Re: [PATCH 2/3] analyzer: reorder initialization of state m_invalid in sm-fd.cc [PR106184]
  2022-07-06 14:25 ` [PATCH 2/3] analyzer: reorder initialization of state m_invalid in sm-fd.cc [PR106184] Immad Mir
@ 2022-07-06 15:29   ` David Malcolm
  0 siblings, 0 replies; 4+ messages in thread
From: David Malcolm @ 2022-07-06 15:29 UTC (permalink / raw)
  To: mirimnan017, gcc-patches; +Cc: Immad Mir, Immad Mir

On Wed, 2022-07-06 at 19:55 +0530, Immad Mir wrote:
> From: Immad Mir <mirimmad17@gmail.com>
> 
> This patch reorders the initialization of state m_invalid in sm-fd.cc
> to conform with standard practice in C++.

Might want to reword to say that the order of the initializers is now
the same as the ordering of the fields in the class decl, or somesuch.


I think I already approved this; it's OK to push this to trunk.

Thanks
Dave

> 
> 
> gcc/analyzer/ChangeLog:
>         PR analyzer/106184
>         * sm-fd.cc (fd_state_machine): Change ordering of
> initialization
>         of state m_invalid.
> 
> Signed-off-by: Immad Mir <mirimmad@outlook.com>
> ---
>  gcc/analyzer/sm-fd.cc | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc
> index 8196d33223a..8e4300b06e2 100644
> --- a/gcc/analyzer/sm-fd.cc
> +++ b/gcc/analyzer/sm-fd.cc
> @@ -551,11 +551,12 @@ fd_state_machine::fd_state_machine (logger
> *logger)
>        m_unchecked_read_write (add_state ("fd-unchecked-read-write")),
>        m_unchecked_read_only (add_state ("fd-unchecked-read-only")),
>        m_unchecked_write_only (add_state ("fd-unchecked-write-only")),
> -      m_invalid (add_state ("fd-invalid")),
>        m_valid_read_write (add_state ("fd-valid-read-write")),
>        m_valid_read_only (add_state ("fd-valid-read-only")),
>        m_valid_write_only (add_state ("fd-valid-write-only")),
> -      m_closed (add_state ("fd-closed")), m_stop (add_state ("fd-
> stop"))
> +      m_invalid (add_state ("fd-invalid")),
> +      m_closed (add_state ("fd-closed")),
> +      m_stop (add_state ("fd-stop"))
>  {
>  }
>  



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

* Re: [PATCH 3/3] analyzer: add a new testcase to demonstrate passsing of a file descriptor to a function that does not emit any warning
  2022-07-06 14:25 ` [PATCH 3/3] analyzer: add a new testcase to demonstrate passsing of a file descriptor to a function that does not emit any warning Immad Mir
@ 2022-07-06 15:37   ` David Malcolm
  0 siblings, 0 replies; 4+ messages in thread
From: David Malcolm @ 2022-07-06 15:37 UTC (permalink / raw)
  To: mirimnan017, gcc-patches; +Cc: Immad Mir

On Wed, 2022-07-06 at 19:55 +0530, Immad Mir wrote:
> gcc/testsuite/ChangeLog:
>         * gcc.dg/analyzer/fd-4.c: Add a new testcase to demonstrate
> passsing
>         of a file descriptor to a function that does not emit any
> warning.

The patch itself is OK for trunk, but the initial line of the commit
message is probably too long - this gets used as the title of the
commit in various git UIs.  I can't remember the recommended limit, it
might be 80 chars (which can be hard when the leading "analyzer: "
takes up 10 chars).

Please reduce the length before pushing, maybe to:
  analyzer: add testcase of using closed fd without warning
or somesuch

Thanks
Dave


> 
> Signed-off-by: Immad Mir <mirimmad@outlook.com>
> ---
>  gcc/testsuite/gcc.dg/analyzer/fd-4.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> index c992db619e7..fcfa6168efa 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> @@ -1,3 +1,5 @@
> +#include <stdio.h>
> +
>  int open(const char *, int mode);
>  void close(int fd);
>  int write (int fd, void *buf, int nbytes);
> @@ -60,3 +62,11 @@ test_4 (const char *path, void *buf)
>          /* {dg-message "\\(3\\) 'write' on closed file descriptor
> 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */
>      }
>  }
> +
> +void
> +test_5 (const char *path)
> +{
> +    int fd = open (path, O_RDWR);
> +    close(fd);
> +    printf("%d", fd); /* { dg-bogus "'printf' on a closed file
> descriptor 'fd'" } */
> +}
> \ No newline at end of file



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

end of thread, other threads:[~2022-07-06 15:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220706142543.3790-1-mirimmad@outlook.com>
2022-07-06 14:25 ` [PATCH 2/3] analyzer: reorder initialization of state m_invalid in sm-fd.cc [PR106184] Immad Mir
2022-07-06 15:29   ` David Malcolm
2022-07-06 14:25 ` [PATCH 3/3] analyzer: add a new testcase to demonstrate passsing of a file descriptor to a function that does not emit any warning Immad Mir
2022-07-06 15:37   ` 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).