analyzer: convert tests with dos2unix

Message ID 3bbb9882-a8c9-98f1-3d4e-1efe0b688b1e@suse.cz
State New, archived
Headers
Series analyzer: convert tests with dos2unix |

Commit Message

Martin Liška July 25, 2022, 6:45 a.m. UTC
  Ready for master?
Thanks,
Martin

gcc/testsuite/ChangeLog:

	* gcc.dg/analyzer/fd-2.c: Convert Windows endlines to Unix
	style.
	* gcc.dg/analyzer/fd-3.c: Likewise.
	* gcc.dg/analyzer/fd-4.c: Likewise.
	* gcc.dg/analyzer/fd-5.c: Likewise.
	* c-c++-common/attr-fd.c: Likewise.
---
 gcc/testsuite/c-c++-common/attr-fd.c |  36 +++---
 gcc/testsuite/gcc.dg/analyzer/fd-2.c |  96 +++++++--------
 gcc/testsuite/gcc.dg/analyzer/fd-3.c | 168 +++++++++++++--------------
 gcc/testsuite/gcc.dg/analyzer/fd-4.c | 142 +++++++++++-----------
 gcc/testsuite/gcc.dg/analyzer/fd-5.c | 104 ++++++++---------
 5 files changed, 273 insertions(+), 273 deletions(-)
  

Comments

David Malcolm July 25, 2022, 3:53 p.m. UTC | #1
On Mon, 2022-07-25 at 08:45 +0200, Martin Liška wrote:
> Ready for master?

Yes, thanks.
Dave


> Thanks,
> Martin
> 
> gcc/testsuite/ChangeLog:
> 
>         * gcc.dg/analyzer/fd-2.c: Convert Windows endlines to Unix
>         style.
>         * gcc.dg/analyzer/fd-3.c: Likewise.
>         * gcc.dg/analyzer/fd-4.c: Likewise.
>         * gcc.dg/analyzer/fd-5.c: Likewise.
>         * c-c++-common/attr-fd.c: Likewise.
> ---
>  gcc/testsuite/c-c++-common/attr-fd.c |  36 +++---
>  gcc/testsuite/gcc.dg/analyzer/fd-2.c |  96 +++++++--------
>  gcc/testsuite/gcc.dg/analyzer/fd-3.c | 168 +++++++++++++------------
> --
>  gcc/testsuite/gcc.dg/analyzer/fd-4.c | 142 +++++++++++-----------
>  gcc/testsuite/gcc.dg/analyzer/fd-5.c | 104 ++++++++---------
>  5 files changed, 273 insertions(+), 273 deletions(-)
> 
> diff --git a/gcc/testsuite/c-c++-common/attr-fd.c b/gcc/testsuite/c-
> c++-common/attr-fd.c
> index e4bb4ed0374..9f12093c04f 100644
> --- a/gcc/testsuite/c-c++-common/attr-fd.c
> +++ b/gcc/testsuite/c-c++-common/attr-fd.c
> @@ -1,18 +1,18 @@
> -
> -int not_a_fn __attribute__ ((fd_arg(1))); /* { dg-warning "'fd_arg'
> attribute only applies to function types" } */
> -
> -void f (char *p) __attribute__ ((fd_arg(1))); /* { dg-warning
> "'fd_arg' attribute argument value '1' refers to parameter type 'char
> ?\\\*'" } */
> -
> -
> -int not_a_fn_b __attribute__ ((fd_arg_read(1))); /* { dg-warning
> "'fd_arg_read' attribute only applies to function types" } */
> -
> -void g (char *p) __attribute__ ((fd_arg_read(1))); /* { dg-warning
> "'fd_arg_read' attribute argument value '1' refers to parameter type
> 'char ?\\\*'" } */
> -
> -
> -int not_a_fn_c __attribute__ ((fd_arg_write(1))); /* { dg-warning
> "'fd_arg_write' attribute only applies to function types" } */
> -
> -void f (char *p) __attribute__ ((fd_arg_write(1))); /* { dg-warning
> "'fd_arg_write' attribute argument value '1' refers to parameter type
> 'char ?\\\*'" } */
> -
> -
> -void fn_a (int fd) __attribute__ ((fd_arg(0))); /* { dg-warning
> "'fd_arg' attribute argument value '0' does not refer to a function
> parameter" } */
> -void fd_a_1 (int fd) __attribute__ ((fd_arg("notint"))); /* { dg-
> warning "'fd_arg' attribute argument has type ('char\\\[7\\\]'|'const
> char\\\*')" } */
> +
> +int not_a_fn __attribute__ ((fd_arg(1))); /* { dg-warning "'fd_arg'
> attribute only applies to function types" } */
> +
> +void f (char *p) __attribute__ ((fd_arg(1))); /* { dg-warning
> "'fd_arg' attribute argument value '1' refers to parameter type 'char
> ?\\\*'" } */
> +
> +
> +int not_a_fn_b __attribute__ ((fd_arg_read(1))); /* { dg-warning
> "'fd_arg_read' attribute only applies to function types" } */
> +
> +void g (char *p) __attribute__ ((fd_arg_read(1))); /* { dg-warning
> "'fd_arg_read' attribute argument value '1' refers to parameter type
> 'char ?\\\*'" } */
> +
> +
> +int not_a_fn_c __attribute__ ((fd_arg_write(1))); /* { dg-warning
> "'fd_arg_write' attribute only applies to function types" } */
> +
> +void f (char *p) __attribute__ ((fd_arg_write(1))); /* { dg-warning
> "'fd_arg_write' attribute argument value '1' refers to parameter type
> 'char ?\\\*'" } */
> +
> +
> +void fn_a (int fd) __attribute__ ((fd_arg(0))); /* { dg-warning
> "'fd_arg' attribute argument value '0' does not refer to a function
> parameter" } */
> +void fd_a_1 (int fd) __attribute__ ((fd_arg("notint"))); /* { dg-
> warning "'fd_arg' attribute argument has type ('char\\\[7\\\]'|'const
> char\\\*')" } */
> diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-2.c
> b/gcc/testsuite/gcc.dg/analyzer/fd-2.c
> index 96ccf2f7ba8..d794b460a2e 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/fd-2.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/fd-2.c
> @@ -1,49 +1,49 @@
> -int open(const char *, int mode);
> -void close(int fd);
> -#define O_RDONLY 0
> -#define O_WRONLY 1
> -#define O_RDWR 2
> -#define STDIN 0
> -
> -void 
> -test_1 (const char *path)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    close (fd); /* { dg-message "\\(2\\) first 'close' here"
> "event1" } */
> -    close (fd); /* { dg-warning "double 'close' of file descriptor
> 'fd' \\\[CWE-1341\\\]" "warning" } */
> -    /* { dg-message "\\(3\\) second 'close' here; first 'close' was
> at \\(2\\)" "event2" { target *-*-* } .-1 } */
> -}
> -
> -void 
> -test_2 (const char *path)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    if (fd < 0) /* { dg-message "\\(2\\) assuming 'fd' is a valid
> file descriptor \\(>= 0\\)" "event1" } */
> -    /* { dg-message "\\(3\\) following 'false' branch \\(when 'fd >=
> 0'\\)..." "event2" { target *-*-* } .-1 } */
> -        return;
> -    close (fd); /* { dg-message "\\(4\\) ...to here" "event1" } */
> -    /* { dg-message "\\(5\\) first 'close' here" "event2" { target
> *-*-* } .-1 } */
> -    close (fd); /* { dg-warning "double 'close' of file descriptor
> 'fd' \\\[CWE-1341\\\]" "warning" } */
> -    /* {dg-message "\\(6\\) second 'close' here; first was at
> \\(5\\)" "" { target *-*-* } .-1 } */
> -}
> -
> -void
> -test_3 ()
> -{
> -    /* FD 0 is stdin at the entry to "main" and thus read-only, but
> we have no
> -    guarantees here that it hasn't been closed and then reopened for
> -    writing, so we can't issue a warning */
> -    
> -    int fd = STDIN;
> -    close(fd); /* { dg-message "\\(1\\) first 'close' here" } */
> -    close(fd); /* { dg-warning "double 'close' of file descriptor
> 'fd' \\\[CWE-1341\\\]" "warning" } */
> -     /* { dg-message "\\(2\\) second 'close' here; first 'close' was
> at \\(1\\)" "event2" { target *-*-* } .-1 } */
> -}
> -
> -void
> -test_4 ()
> -{
> -    int fd = -1;
> -    close(fd);
> -    close(fd);
> +int open(const char *, int mode);
> +void close(int fd);
> +#define O_RDONLY 0
> +#define O_WRONLY 1
> +#define O_RDWR 2
> +#define STDIN 0
> +
> +void 
> +test_1 (const char *path)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    close (fd); /* { dg-message "\\(2\\) first 'close' here"
> "event1" } */
> +    close (fd); /* { dg-warning "double 'close' of file descriptor
> 'fd' \\\[CWE-1341\\\]" "warning" } */
> +    /* { dg-message "\\(3\\) second 'close' here; first 'close' was
> at \\(2\\)" "event2" { target *-*-* } .-1 } */
> +}
> +
> +void 
> +test_2 (const char *path)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    if (fd < 0) /* { dg-message "\\(2\\) assuming 'fd' is a valid
> file descriptor \\(>= 0\\)" "event1" } */
> +    /* { dg-message "\\(3\\) following 'false' branch \\(when 'fd >=
> 0'\\)..." "event2" { target *-*-* } .-1 } */
> +        return;
> +    close (fd); /* { dg-message "\\(4\\) ...to here" "event1" } */
> +    /* { dg-message "\\(5\\) first 'close' here" "event2" { target
> *-*-* } .-1 } */
> +    close (fd); /* { dg-warning "double 'close' of file descriptor
> 'fd' \\\[CWE-1341\\\]" "warning" } */
> +    /* {dg-message "\\(6\\) second 'close' here; first was at
> \\(5\\)" "" { target *-*-* } .-1 } */
> +}
> +
> +void
> +test_3 ()
> +{
> +    /* FD 0 is stdin at the entry to "main" and thus read-only, but
> we have no
> +    guarantees here that it hasn't been closed and then reopened for
> +    writing, so we can't issue a warning */
> +    
> +    int fd = STDIN;
> +    close(fd); /* { dg-message "\\(1\\) first 'close' here" } */
> +    close(fd); /* { dg-warning "double 'close' of file descriptor
> 'fd' \\\[CWE-1341\\\]" "warning" } */
> +     /* { dg-message "\\(2\\) second 'close' here; first 'close' was
> at \\(1\\)" "event2" { target *-*-* } .-1 } */
> +}
> +
> +void
> +test_4 ()
> +{
> +    int fd = -1;
> +    close(fd);
> +    close(fd);
>  }
> \ No newline at end of file
> diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-3.c
> b/gcc/testsuite/gcc.dg/analyzer/fd-3.c
> index 40fc8af27b5..55e84e3634a 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/fd-3.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/fd-3.c
> @@ -1,85 +1,85 @@
> -int open(const char *, int mode);
> -void close(int fd);
> -int write (int fd, void *buf, int nbytes);
> -int read (int fd, void *buf, int nbytes);
> -int some_condition();
> -
> -#define O_RDONLY 0
> -#define O_WRONLY 1
> -#define O_RDWR 2
> -#define STDIN 0
> -#define O_NOATIME 262144
> -
> -void
> -test_1 (const char *path, void *buf)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    write (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be
> invalid: unchecked value from \\(1\\)" } */
> -    /* { dg-warning "'write' on possibly invalid file descriptor
> 'fd'" "warning" { target *-*-* } .-1 } */
> -    close(fd);
> -}
> -
> -void
> -test_2 (const char *path, void *buf)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    read (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be
> invalid: unchecked value from \\(1\\)" } */
> -    /* { dg-warning "'read' on possibly invalid file descriptor
> 'fd'" "warning" { target *-*-* } .-1 } */
> -    close (fd);
> -}
> -
> -void 
> -test_3 (void *buf)
> -{
> -    int fd = -1;
> -    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid
> file descriptor 'fd'" } */
> -    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-
> * } .-1 } */
> -}
> -
> -void
> -test_4 (void *buf)
> -{
> -    int fd = STDIN;
> -    read (fd, buf, 1);
> -    close(fd);
> -}
> -
> -void
> -test_5 (char *path, void *buf)
> -{
> -    int flags = O_RDONLY;
> -    if (some_condition())
> -        flags |= O_NOATIME;
> -    int fd = open (path, flags);
> -    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid
> file descriptor 'fd'" } */
> -    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-
> * } .-1 } */
> -    close (fd);   
> -}
> -
> -
> -void
> -test_6 (char *path, void *buf)
> -{
> -    int fd = open (path, O_RDONLY);
> -    if (fd != -1)
> -    {
> -        read (fd, buf, 1);
> -    }
> -    close (fd);
> -}
> -
> -
> -void
> -test_7 (char *path, void *buf)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    if (fd != -1) /* { dg-message "\\(2\\) assuming 'fd' is an
> invalid file descriptor \\(< 0\\)" } */
> -    {
> -        read (fd, buf, 1);
> -    } else
> -    {
> -        write (fd, buf, 1); /* { dg-warning "'write' on possibly
> invalid file descriptor 'fd'" } */
> -        
> -    }
> -    close(fd);
> +int open(const char *, int mode);
> +void close(int fd);
> +int write (int fd, void *buf, int nbytes);
> +int read (int fd, void *buf, int nbytes);
> +int some_condition();
> +
> +#define O_RDONLY 0
> +#define O_WRONLY 1
> +#define O_RDWR 2
> +#define STDIN 0
> +#define O_NOATIME 262144
> +
> +void
> +test_1 (const char *path, void *buf)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    write (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be
> invalid: unchecked value from \\(1\\)" } */
> +    /* { dg-warning "'write' on possibly invalid file descriptor
> 'fd'" "warning" { target *-*-* } .-1 } */
> +    close(fd);
> +}
> +
> +void
> +test_2 (const char *path, void *buf)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    read (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be
> invalid: unchecked value from \\(1\\)" } */
> +    /* { dg-warning "'read' on possibly invalid file descriptor
> 'fd'" "warning" { target *-*-* } .-1 } */
> +    close (fd);
> +}
> +
> +void 
> +test_3 (void *buf)
> +{
> +    int fd = -1;
> +    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid
> file descriptor 'fd'" } */
> +    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-
> * } .-1 } */
> +}
> +
> +void
> +test_4 (void *buf)
> +{
> +    int fd = STDIN;
> +    read (fd, buf, 1);
> +    close(fd);
> +}
> +
> +void
> +test_5 (char *path, void *buf)
> +{
> +    int flags = O_RDONLY;
> +    if (some_condition())
> +        flags |= O_NOATIME;
> +    int fd = open (path, flags);
> +    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid
> file descriptor 'fd'" } */
> +    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-
> * } .-1 } */
> +    close (fd);   
> +}
> +
> +
> +void
> +test_6 (char *path, void *buf)
> +{
> +    int fd = open (path, O_RDONLY);
> +    if (fd != -1)
> +    {
> +        read (fd, buf, 1);
> +    }
> +    close (fd);
> +}
> +
> +
> +void
> +test_7 (char *path, void *buf)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    if (fd != -1) /* { dg-message "\\(2\\) assuming 'fd' is an
> invalid file descriptor \\(< 0\\)" } */
> +    {
> +        read (fd, buf, 1);
> +    } else
> +    {
> +        write (fd, buf, 1); /* { dg-warning "'write' on possibly
> invalid file descriptor 'fd'" } */
> +        
> +    }
> +    close(fd);
>  }
> \ No newline at end of file
> diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> index 41263468a6c..ecd787caff7 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> @@ -1,72 +1,72 @@
> -#include <stdio.h>
> -
> -int open(const char *, int mode);
> -void close(int fd);
> -int write (int fd, void *buf, int nbytes);
> -int read (int fd, void *buf, int nbytes);
> -
> -#define O_RDONLY 0
> -#define O_WRONLY 1
> -#define O_RDWR 2
> -
> -
> -void
> -test_1 (const char *path, void *buf)
> -{
> -    int fd = open (path, O_RDONLY); /* { dg-message "opened here as
> read-only" } */
> -    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file
> descriptor \\(>= 0\\)" "event1" } */
> -    /* { dg-message "following 'true' branch \\(when 'fd >=
> 0'\\)..." "event2" { target *-*-* } .-1 } */
> -    {
> -        write (fd, buf, 1); /* { dg-warning "'write' on read-only
> file descriptor 'fd'" "warning" } */
> -        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-*
> } .-1 } */
> -        /* { dg-message "\\(5\\) 'write' on read-only file
> descriptor 'fd'" "event2" { target *-*-* } .-2 } */
> -        close (fd);
> -    }
> -}
> -
> -void
> -test_2 (const char *path, void *buf)
> -{
> -    int fd = open (path, O_WRONLY); /* { dg-message "opened here as
> write-only" } */
> -    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file
> descriptor \\(>= 0\\)" "event1" } */
> -    /* { dg-message "following 'true' branch \\(when 'fd >=
> 0'\\)..." "event2" { target *-*-* } .-1 } */
> -    {
> -        read (fd, buf, 1); /* { dg-warning "'read' on write-only
> file descriptor 'fd'" "warning" } */
> -        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-*
> } .-1 } */
> -        /* { dg-message "\\(5\\) 'read' on write-only file
> descriptor 'fd'" "event2" { target *-*-* } .-2 } */
> -        close (fd);
> -    }
> -}
> -
> -
> -void 
> -test_3 (const char *path, void *buf)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    if (fd >= 0)
> -    {
> -        close(fd); /* {dg-message "\\(2\\) closed here"} */
> -        read(fd, buf, 1); /* { dg-warning "'read' on closed file
> descriptor 'fd'" }  */
> -        /* {dg-message "\\(3\\) 'read' on closed file descriptor
> 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */
> -    }
> -}
> -
> -void 
> -test_4 (const char *path, void *buf)
> -{
> -    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> -    if (fd >= 0)
> -    {
> -        close(fd); /* {dg-message "\\(2\\) closed here"} */
> -        write(fd, buf, 1); /* { dg-warning "'write' on closed file
> descriptor 'fd'" }  */
> -        /* {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'" } */
> +#include <stdio.h>
> +
> +int open(const char *, int mode);
> +void close(int fd);
> +int write (int fd, void *buf, int nbytes);
> +int read (int fd, void *buf, int nbytes);
> +
> +#define O_RDONLY 0
> +#define O_WRONLY 1
> +#define O_RDWR 2
> +
> +
> +void
> +test_1 (const char *path, void *buf)
> +{
> +    int fd = open (path, O_RDONLY); /* { dg-message "opened here as
> read-only" } */
> +    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file
> descriptor \\(>= 0\\)" "event1" } */
> +    /* { dg-message "following 'true' branch \\(when 'fd >=
> 0'\\)..." "event2" { target *-*-* } .-1 } */
> +    {
> +        write (fd, buf, 1); /* { dg-warning "'write' on read-only
> file descriptor 'fd'" "warning" } */
> +        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-*
> } .-1 } */
> +        /* { dg-message "\\(5\\) 'write' on read-only file
> descriptor 'fd'" "event2" { target *-*-* } .-2 } */
> +        close (fd);
> +    }
> +}
> +
> +void
> +test_2 (const char *path, void *buf)
> +{
> +    int fd = open (path, O_WRONLY); /* { dg-message "opened here as
> write-only" } */
> +    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file
> descriptor \\(>= 0\\)" "event1" } */
> +    /* { dg-message "following 'true' branch \\(when 'fd >=
> 0'\\)..." "event2" { target *-*-* } .-1 } */
> +    {
> +        read (fd, buf, 1); /* { dg-warning "'read' on write-only
> file descriptor 'fd'" "warning" } */
> +        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-*
> } .-1 } */
> +        /* { dg-message "\\(5\\) 'read' on write-only file
> descriptor 'fd'" "event2" { target *-*-* } .-2 } */
> +        close (fd);
> +    }
> +}
> +
> +
> +void 
> +test_3 (const char *path, void *buf)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    if (fd >= 0)
> +    {
> +        close(fd); /* {dg-message "\\(2\\) closed here"} */
> +        read(fd, buf, 1); /* { dg-warning "'read' on closed file
> descriptor 'fd'" }  */
> +        /* {dg-message "\\(3\\) 'read' on closed file descriptor
> 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */
> +    }
> +}
> +
> +void 
> +test_4 (const char *path, void *buf)
> +{
> +    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened
> here" } */
> +    if (fd >= 0)
> +    {
> +        close(fd); /* {dg-message "\\(2\\) closed here"} */
> +        write(fd, buf, 1); /* { dg-warning "'write' on closed file
> descriptor 'fd'" }  */
> +        /* {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
> diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-5.c
> b/gcc/testsuite/gcc.dg/analyzer/fd-5.c
> index 8f29c11b3e8..c18b2adcbe5 100644
> --- a/gcc/testsuite/gcc.dg/analyzer/fd-5.c
> +++ b/gcc/testsuite/gcc.dg/analyzer/fd-5.c
> @@ -1,53 +1,53 @@
> -int open(const char *, int mode);
> -void close(int fd);
> -int write (int fd, void *buf, int nbytes);
> -int read (int fd, void *buf, int nbytes);
> -
> -#define O_RDONLY 0
> -#define O_WRONLY 1
> -#define O_RDWR 2
> -
> -void f (int fd) __attribute__((fd_arg(1))); /* { dg-message
> "argument 1 of 'f' must be an open file descriptor, due to
> '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
> -
> -void
> -test_1 (const char *path)
> -{
> -    int fd = open (path, O_RDWR);
> -    close(fd);
> -    f(fd); /* { dg-warning "'f' on closed file descriptor 'fd'" } */
> -      /* { dg-message "\\(3\\) 'f' on closed file descriptor 'fd';
> 'close' was at \\(2\\)" "" { target *-*-* } .-1 } */
> -}
> -
> -void g (int fd) __attribute__((fd_arg_read(1))); /* { dg-message
> "argument 1 of 'g' must be a readable file descriptor, due to
> '__attribute__\\(\\(fd_arg_read\\(1\\)\\)\\)'" } */
> -
> -void
> -test_2 (const char *path)
> -{
> -  int fd = open (path, O_WRONLY);
> -  if (fd != -1)
> -  {
> -    g (fd); /* { dg-warning "'g' on write-only file descriptor 'fd'"
> } */
> -  }
> -  close (fd);
> -}
> -
> -void h (int fd) __attribute__((fd_arg_write(1))); /* { dg-message
> "argument 1 of 'h' must be a writable file descriptor, due to
> '__attribute__\\(\\(fd_arg_write\\(1\\)\\)\\)'" } */
> -void
> -test_3 (const char *path)
> -{
> -  int fd = open (path, O_RDONLY);
> -  if (fd != -1)
> -  {
> -    h (fd); /* { dg-warning "'h' on read-only file descriptor 'fd'"
> } */
> -  }
> -  close(fd);
> -}
> -
> -void ff (int fd) __attribute__((fd_arg(1))); /* { dg-message
> "argument 1 of 'ff' must be an open file descriptor, due to
> '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
> -
> -void test_4 (const char *path)
> -{
> -  int fd = open (path, O_RDWR);
> -  ff (fd); /* { dg-warning "'ff' on possibly invalid file descriptor
> 'fd'" } */
> -  close(fd);
> +int open(const char *, int mode);
> +void close(int fd);
> +int write (int fd, void *buf, int nbytes);
> +int read (int fd, void *buf, int nbytes);
> +
> +#define O_RDONLY 0
> +#define O_WRONLY 1
> +#define O_RDWR 2
> +
> +void f (int fd) __attribute__((fd_arg(1))); /* { dg-message
> "argument 1 of 'f' must be an open file descriptor, due to
> '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
> +
> +void
> +test_1 (const char *path)
> +{
> +    int fd = open (path, O_RDWR);
> +    close(fd);
> +    f(fd); /* { dg-warning "'f' on closed file descriptor 'fd'" } */
> +      /* { dg-message "\\(3\\) 'f' on closed file descriptor 'fd';
> 'close' was at \\(2\\)" "" { target *-*-* } .-1 } */
> +}
> +
> +void g (int fd) __attribute__((fd_arg_read(1))); /* { dg-message
> "argument 1 of 'g' must be a readable file descriptor, due to
> '__attribute__\\(\\(fd_arg_read\\(1\\)\\)\\)'" } */
> +
> +void
> +test_2 (const char *path)
> +{
> +  int fd = open (path, O_WRONLY);
> +  if (fd != -1)
> +  {
> +    g (fd); /* { dg-warning "'g' on write-only file descriptor 'fd'"
> } */
> +  }
> +  close (fd);
> +}
> +
> +void h (int fd) __attribute__((fd_arg_write(1))); /* { dg-message
> "argument 1 of 'h' must be a writable file descriptor, due to
> '__attribute__\\(\\(fd_arg_write\\(1\\)\\)\\)'" } */
> +void
> +test_3 (const char *path)
> +{
> +  int fd = open (path, O_RDONLY);
> +  if (fd != -1)
> +  {
> +    h (fd); /* { dg-warning "'h' on read-only file descriptor 'fd'"
> } */
> +  }
> +  close(fd);
> +}
> +
> +void ff (int fd) __attribute__((fd_arg(1))); /* { dg-message
> "argument 1 of 'ff' must be an open file descriptor, due to
> '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
> +
> +void test_4 (const char *path)
> +{
> +  int fd = open (path, O_RDWR);
> +  ff (fd); /* { dg-warning "'ff' on possibly invalid file descriptor
> 'fd'" } */
> +  close(fd);
>  }
> \ No newline at end of file
  

Patch

diff --git a/gcc/testsuite/c-c++-common/attr-fd.c b/gcc/testsuite/c-c++-common/attr-fd.c
index e4bb4ed0374..9f12093c04f 100644
--- a/gcc/testsuite/c-c++-common/attr-fd.c
+++ b/gcc/testsuite/c-c++-common/attr-fd.c
@@ -1,18 +1,18 @@ 
-
-int not_a_fn __attribute__ ((fd_arg(1))); /* { dg-warning "'fd_arg' attribute only applies to function types" } */
-
-void f (char *p) __attribute__ ((fd_arg(1))); /* { dg-warning "'fd_arg' attribute argument value '1' refers to parameter type 'char ?\\\*'" } */
-
-
-int not_a_fn_b __attribute__ ((fd_arg_read(1))); /* { dg-warning "'fd_arg_read' attribute only applies to function types" } */
-
-void g (char *p) __attribute__ ((fd_arg_read(1))); /* { dg-warning "'fd_arg_read' attribute argument value '1' refers to parameter type 'char ?\\\*'" } */
-
-
-int not_a_fn_c __attribute__ ((fd_arg_write(1))); /* { dg-warning "'fd_arg_write' attribute only applies to function types" } */
-
-void f (char *p) __attribute__ ((fd_arg_write(1))); /* { dg-warning "'fd_arg_write' attribute argument value '1' refers to parameter type 'char ?\\\*'" } */
-
-
-void fn_a (int fd) __attribute__ ((fd_arg(0))); /* { dg-warning "'fd_arg' attribute argument value '0' does not refer to a function parameter" } */
-void fd_a_1 (int fd) __attribute__ ((fd_arg("notint"))); /* { dg-warning "'fd_arg' attribute argument has type ('char\\\[7\\\]'|'const char\\\*')" } */
+
+int not_a_fn __attribute__ ((fd_arg(1))); /* { dg-warning "'fd_arg' attribute only applies to function types" } */
+
+void f (char *p) __attribute__ ((fd_arg(1))); /* { dg-warning "'fd_arg' attribute argument value '1' refers to parameter type 'char ?\\\*'" } */
+
+
+int not_a_fn_b __attribute__ ((fd_arg_read(1))); /* { dg-warning "'fd_arg_read' attribute only applies to function types" } */
+
+void g (char *p) __attribute__ ((fd_arg_read(1))); /* { dg-warning "'fd_arg_read' attribute argument value '1' refers to parameter type 'char ?\\\*'" } */
+
+
+int not_a_fn_c __attribute__ ((fd_arg_write(1))); /* { dg-warning "'fd_arg_write' attribute only applies to function types" } */
+
+void f (char *p) __attribute__ ((fd_arg_write(1))); /* { dg-warning "'fd_arg_write' attribute argument value '1' refers to parameter type 'char ?\\\*'" } */
+
+
+void fn_a (int fd) __attribute__ ((fd_arg(0))); /* { dg-warning "'fd_arg' attribute argument value '0' does not refer to a function parameter" } */
+void fd_a_1 (int fd) __attribute__ ((fd_arg("notint"))); /* { dg-warning "'fd_arg' attribute argument has type ('char\\\[7\\\]'|'const char\\\*')" } */
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-2.c b/gcc/testsuite/gcc.dg/analyzer/fd-2.c
index 96ccf2f7ba8..d794b460a2e 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-2.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-2.c
@@ -1,49 +1,49 @@ 
-int open(const char *, int mode);
-void close(int fd);
-#define O_RDONLY 0
-#define O_WRONLY 1
-#define O_RDWR 2
-#define STDIN 0
-
-void 
-test_1 (const char *path)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    close (fd); /* { dg-message "\\(2\\) first 'close' here" "event1" } */
-    close (fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" "warning" } */
-    /* { dg-message "\\(3\\) second 'close' here; first 'close' was at \\(2\\)" "event2" { target *-*-* } .-1 } */
-}
-
-void 
-test_2 (const char *path)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    if (fd < 0) /* { dg-message "\\(2\\) assuming 'fd' is a valid file descriptor \\(>= 0\\)" "event1" } */
-    /* { dg-message "\\(3\\) following 'false' branch \\(when 'fd >= 0'\\)..." "event2" { target *-*-* } .-1 } */
-        return;
-    close (fd); /* { dg-message "\\(4\\) ...to here" "event1" } */
-    /* { dg-message "\\(5\\) first 'close' here" "event2" { target *-*-* } .-1 } */
-    close (fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" "warning" } */
-    /* {dg-message "\\(6\\) second 'close' here; first was at \\(5\\)" "" { target *-*-* } .-1 } */
-}
-
-void
-test_3 ()
-{
-    /* FD 0 is stdin at the entry to "main" and thus read-only, but we have no
-    guarantees here that it hasn't been closed and then reopened for
-    writing, so we can't issue a warning */
-    
-    int fd = STDIN;
-    close(fd); /* { dg-message "\\(1\\) first 'close' here" } */
-    close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" "warning" } */
-     /* { dg-message "\\(2\\) second 'close' here; first 'close' was at \\(1\\)" "event2" { target *-*-* } .-1 } */
-}
-
-void
-test_4 ()
-{
-    int fd = -1;
-    close(fd);
-    close(fd);
+int open(const char *, int mode);
+void close(int fd);
+#define O_RDONLY 0
+#define O_WRONLY 1
+#define O_RDWR 2
+#define STDIN 0
+
+void 
+test_1 (const char *path)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    close (fd); /* { dg-message "\\(2\\) first 'close' here" "event1" } */
+    close (fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" "warning" } */
+    /* { dg-message "\\(3\\) second 'close' here; first 'close' was at \\(2\\)" "event2" { target *-*-* } .-1 } */
+}
+
+void 
+test_2 (const char *path)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    if (fd < 0) /* { dg-message "\\(2\\) assuming 'fd' is a valid file descriptor \\(>= 0\\)" "event1" } */
+    /* { dg-message "\\(3\\) following 'false' branch \\(when 'fd >= 0'\\)..." "event2" { target *-*-* } .-1 } */
+        return;
+    close (fd); /* { dg-message "\\(4\\) ...to here" "event1" } */
+    /* { dg-message "\\(5\\) first 'close' here" "event2" { target *-*-* } .-1 } */
+    close (fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" "warning" } */
+    /* {dg-message "\\(6\\) second 'close' here; first was at \\(5\\)" "" { target *-*-* } .-1 } */
+}
+
+void
+test_3 ()
+{
+    /* FD 0 is stdin at the entry to "main" and thus read-only, but we have no
+    guarantees here that it hasn't been closed and then reopened for
+    writing, so we can't issue a warning */
+    
+    int fd = STDIN;
+    close(fd); /* { dg-message "\\(1\\) first 'close' here" } */
+    close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" "warning" } */
+     /* { dg-message "\\(2\\) second 'close' here; first 'close' was at \\(1\\)" "event2" { target *-*-* } .-1 } */
+}
+
+void
+test_4 ()
+{
+    int fd = -1;
+    close(fd);
+    close(fd);
 }
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-3.c b/gcc/testsuite/gcc.dg/analyzer/fd-3.c
index 40fc8af27b5..55e84e3634a 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-3.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-3.c
@@ -1,85 +1,85 @@ 
-int open(const char *, int mode);
-void close(int fd);
-int write (int fd, void *buf, int nbytes);
-int read (int fd, void *buf, int nbytes);
-int some_condition();
-
-#define O_RDONLY 0
-#define O_WRONLY 1
-#define O_RDWR 2
-#define STDIN 0
-#define O_NOATIME 262144
-
-void
-test_1 (const char *path, void *buf)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    write (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be invalid: unchecked value from \\(1\\)" } */
-    /* { dg-warning "'write' on possibly invalid file descriptor 'fd'" "warning" { target *-*-* } .-1 } */
-    close(fd);
-}
-
-void
-test_2 (const char *path, void *buf)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    read (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be invalid: unchecked value from \\(1\\)" } */
-    /* { dg-warning "'read' on possibly invalid file descriptor 'fd'" "warning" { target *-*-* } .-1 } */
-    close (fd);
-}
-
-void 
-test_3 (void *buf)
-{
-    int fd = -1;
-    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid file descriptor 'fd'" } */
-    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-* } .-1 } */
-}
-
-void
-test_4 (void *buf)
-{
-    int fd = STDIN;
-    read (fd, buf, 1);
-    close(fd);
-}
-
-void
-test_5 (char *path, void *buf)
-{
-    int flags = O_RDONLY;
-    if (some_condition())
-        flags |= O_NOATIME;
-    int fd = open (path, flags);
-    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid file descriptor 'fd'" } */
-    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-* } .-1 } */
-    close (fd);   
-}
-
-
-void
-test_6 (char *path, void *buf)
-{
-    int fd = open (path, O_RDONLY);
-    if (fd != -1)
-    {
-        read (fd, buf, 1);
-    }
-    close (fd);
-}
-
-
-void
-test_7 (char *path, void *buf)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    if (fd != -1) /* { dg-message "\\(2\\) assuming 'fd' is an invalid file descriptor \\(< 0\\)" } */
-    {
-        read (fd, buf, 1);
-    } else
-    {
-        write (fd, buf, 1); /* { dg-warning "'write' on possibly invalid file descriptor 'fd'" } */
-        
-    }
-    close(fd);
+int open(const char *, int mode);
+void close(int fd);
+int write (int fd, void *buf, int nbytes);
+int read (int fd, void *buf, int nbytes);
+int some_condition();
+
+#define O_RDONLY 0
+#define O_WRONLY 1
+#define O_RDWR 2
+#define STDIN 0
+#define O_NOATIME 262144
+
+void
+test_1 (const char *path, void *buf)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    write (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be invalid: unchecked value from \\(1\\)" } */
+    /* { dg-warning "'write' on possibly invalid file descriptor 'fd'" "warning" { target *-*-* } .-1 } */
+    close(fd);
+}
+
+void
+test_2 (const char *path, void *buf)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    read (fd, buf, 1); /* { dg-message "\\(2\\) 'fd' could be invalid: unchecked value from \\(1\\)" } */
+    /* { dg-warning "'read' on possibly invalid file descriptor 'fd'" "warning" { target *-*-* } .-1 } */
+    close (fd);
+}
+
+void 
+test_3 (void *buf)
+{
+    int fd = -1;
+    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid file descriptor 'fd'" } */
+    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-* } .-1 } */
+}
+
+void
+test_4 (void *buf)
+{
+    int fd = STDIN;
+    read (fd, buf, 1);
+    close(fd);
+}
+
+void
+test_5 (char *path, void *buf)
+{
+    int flags = O_RDONLY;
+    if (some_condition())
+        flags |= O_NOATIME;
+    int fd = open (path, flags);
+    read (fd, buf, 1); /* { dg-warning "'read' on possibly invalid file descriptor 'fd'" } */
+    /* { dg-message "\\(1\\) 'fd' could be invalid" "" { target *-*-* } .-1 } */
+    close (fd);   
+}
+
+
+void
+test_6 (char *path, void *buf)
+{
+    int fd = open (path, O_RDONLY);
+    if (fd != -1)
+    {
+        read (fd, buf, 1);
+    }
+    close (fd);
+}
+
+
+void
+test_7 (char *path, void *buf)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    if (fd != -1) /* { dg-message "\\(2\\) assuming 'fd' is an invalid file descriptor \\(< 0\\)" } */
+    {
+        read (fd, buf, 1);
+    } else
+    {
+        write (fd, buf, 1); /* { dg-warning "'write' on possibly invalid file descriptor 'fd'" } */
+        
+    }
+    close(fd);
 }
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
index 41263468a6c..ecd787caff7 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
@@ -1,72 +1,72 @@ 
-#include <stdio.h>
-
-int open(const char *, int mode);
-void close(int fd);
-int write (int fd, void *buf, int nbytes);
-int read (int fd, void *buf, int nbytes);
-
-#define O_RDONLY 0
-#define O_WRONLY 1
-#define O_RDWR 2
-
-
-void
-test_1 (const char *path, void *buf)
-{
-    int fd = open (path, O_RDONLY); /* { dg-message "opened here as read-only" } */
-    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file descriptor \\(>= 0\\)" "event1" } */
-    /* { dg-message "following 'true' branch \\(when 'fd >= 0'\\)..." "event2" { target *-*-* } .-1 } */
-    {
-        write (fd, buf, 1); /* { dg-warning "'write' on read-only file descriptor 'fd'" "warning" } */
-        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-* } .-1 } */
-        /* { dg-message "\\(5\\) 'write' on read-only file descriptor 'fd'" "event2" { target *-*-* } .-2 } */
-        close (fd);
-    }
-}
-
-void
-test_2 (const char *path, void *buf)
-{
-    int fd = open (path, O_WRONLY); /* { dg-message "opened here as write-only" } */
-    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file descriptor \\(>= 0\\)" "event1" } */
-    /* { dg-message "following 'true' branch \\(when 'fd >= 0'\\)..." "event2" { target *-*-* } .-1 } */
-    {
-        read (fd, buf, 1); /* { dg-warning "'read' on write-only file descriptor 'fd'" "warning" } */
-        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-* } .-1 } */
-        /* { dg-message "\\(5\\) 'read' on write-only file descriptor 'fd'" "event2" { target *-*-* } .-2 } */
-        close (fd);
-    }
-}
-
-
-void 
-test_3 (const char *path, void *buf)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    if (fd >= 0)
-    {
-        close(fd); /* {dg-message "\\(2\\) closed here"} */
-        read(fd, buf, 1); /* { dg-warning "'read' on closed file descriptor 'fd'" }  */
-        /* {dg-message "\\(3\\) 'read' on closed file descriptor 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */
-    }
-}
-
-void 
-test_4 (const char *path, void *buf)
-{
-    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
-    if (fd >= 0)
-    {
-        close(fd); /* {dg-message "\\(2\\) closed here"} */
-        write(fd, buf, 1); /* { dg-warning "'write' on closed file descriptor 'fd'" }  */
-        /* {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'" } */
+#include <stdio.h>
+
+int open(const char *, int mode);
+void close(int fd);
+int write (int fd, void *buf, int nbytes);
+int read (int fd, void *buf, int nbytes);
+
+#define O_RDONLY 0
+#define O_WRONLY 1
+#define O_RDWR 2
+
+
+void
+test_1 (const char *path, void *buf)
+{
+    int fd = open (path, O_RDONLY); /* { dg-message "opened here as read-only" } */
+    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file descriptor \\(>= 0\\)" "event1" } */
+    /* { dg-message "following 'true' branch \\(when 'fd >= 0'\\)..." "event2" { target *-*-* } .-1 } */
+    {
+        write (fd, buf, 1); /* { dg-warning "'write' on read-only file descriptor 'fd'" "warning" } */
+        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-* } .-1 } */
+        /* { dg-message "\\(5\\) 'write' on read-only file descriptor 'fd'" "event2" { target *-*-* } .-2 } */
+        close (fd);
+    }
+}
+
+void
+test_2 (const char *path, void *buf)
+{
+    int fd = open (path, O_WRONLY); /* { dg-message "opened here as write-only" } */
+    if (fd >= 0) /* { dg-message "assuming 'fd' is a valid file descriptor \\(>= 0\\)" "event1" } */
+    /* { dg-message "following 'true' branch \\(when 'fd >= 0'\\)..." "event2" { target *-*-* } .-1 } */
+    {
+        read (fd, buf, 1); /* { dg-warning "'read' on write-only file descriptor 'fd'" "warning" } */
+        /* { dg-message "\\(4\\) ...to here" "event1" { target *-*-* } .-1 } */
+        /* { dg-message "\\(5\\) 'read' on write-only file descriptor 'fd'" "event2" { target *-*-* } .-2 } */
+        close (fd);
+    }
+}
+
+
+void 
+test_3 (const char *path, void *buf)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    if (fd >= 0)
+    {
+        close(fd); /* {dg-message "\\(2\\) closed here"} */
+        read(fd, buf, 1); /* { dg-warning "'read' on closed file descriptor 'fd'" }  */
+        /* {dg-message "\\(3\\) 'read' on closed file descriptor 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */
+    }
+}
+
+void 
+test_4 (const char *path, void *buf)
+{
+    int fd = open (path, O_RDWR); /* { dg-message "\\(1\\) opened here" } */
+    if (fd >= 0)
+    {
+        close(fd); /* {dg-message "\\(2\\) closed here"} */
+        write(fd, buf, 1); /* { dg-warning "'write' on closed file descriptor 'fd'" }  */
+        /* {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
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-5.c b/gcc/testsuite/gcc.dg/analyzer/fd-5.c
index 8f29c11b3e8..c18b2adcbe5 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-5.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-5.c
@@ -1,53 +1,53 @@ 
-int open(const char *, int mode);
-void close(int fd);
-int write (int fd, void *buf, int nbytes);
-int read (int fd, void *buf, int nbytes);
-
-#define O_RDONLY 0
-#define O_WRONLY 1
-#define O_RDWR 2
-
-void f (int fd) __attribute__((fd_arg(1))); /* { dg-message "argument 1 of 'f' must be an open file descriptor, due to '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
-
-void
-test_1 (const char *path)
-{
-    int fd = open (path, O_RDWR);
-    close(fd);
-    f(fd); /* { dg-warning "'f' on closed file descriptor 'fd'" } */
-      /* { dg-message "\\(3\\) 'f' on closed file descriptor 'fd'; 'close' was at \\(2\\)" "" { target *-*-* } .-1 } */
-}
-
-void g (int fd) __attribute__((fd_arg_read(1))); /* { dg-message "argument 1 of 'g' must be a readable file descriptor, due to '__attribute__\\(\\(fd_arg_read\\(1\\)\\)\\)'" } */
-
-void
-test_2 (const char *path)
-{
-  int fd = open (path, O_WRONLY);
-  if (fd != -1)
-  {
-    g (fd); /* { dg-warning "'g' on write-only file descriptor 'fd'" } */
-  }
-  close (fd);
-}
-
-void h (int fd) __attribute__((fd_arg_write(1))); /* { dg-message "argument 1 of 'h' must be a writable file descriptor, due to '__attribute__\\(\\(fd_arg_write\\(1\\)\\)\\)'" } */
-void
-test_3 (const char *path)
-{
-  int fd = open (path, O_RDONLY);
-  if (fd != -1)
-  {
-    h (fd); /* { dg-warning "'h' on read-only file descriptor 'fd'" } */
-  }
-  close(fd);
-}
-
-void ff (int fd) __attribute__((fd_arg(1))); /* { dg-message "argument 1 of 'ff' must be an open file descriptor, due to '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
-
-void test_4 (const char *path)
-{
-  int fd = open (path, O_RDWR);
-  ff (fd); /* { dg-warning "'ff' on possibly invalid file descriptor 'fd'" } */
-  close(fd);
+int open(const char *, int mode);
+void close(int fd);
+int write (int fd, void *buf, int nbytes);
+int read (int fd, void *buf, int nbytes);
+
+#define O_RDONLY 0
+#define O_WRONLY 1
+#define O_RDWR 2
+
+void f (int fd) __attribute__((fd_arg(1))); /* { dg-message "argument 1 of 'f' must be an open file descriptor, due to '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
+
+void
+test_1 (const char *path)
+{
+    int fd = open (path, O_RDWR);
+    close(fd);
+    f(fd); /* { dg-warning "'f' on closed file descriptor 'fd'" } */
+      /* { dg-message "\\(3\\) 'f' on closed file descriptor 'fd'; 'close' was at \\(2\\)" "" { target *-*-* } .-1 } */
+}
+
+void g (int fd) __attribute__((fd_arg_read(1))); /* { dg-message "argument 1 of 'g' must be a readable file descriptor, due to '__attribute__\\(\\(fd_arg_read\\(1\\)\\)\\)'" } */
+
+void
+test_2 (const char *path)
+{
+  int fd = open (path, O_WRONLY);
+  if (fd != -1)
+  {
+    g (fd); /* { dg-warning "'g' on write-only file descriptor 'fd'" } */
+  }
+  close (fd);
+}
+
+void h (int fd) __attribute__((fd_arg_write(1))); /* { dg-message "argument 1 of 'h' must be a writable file descriptor, due to '__attribute__\\(\\(fd_arg_write\\(1\\)\\)\\)'" } */
+void
+test_3 (const char *path)
+{
+  int fd = open (path, O_RDONLY);
+  if (fd != -1)
+  {
+    h (fd); /* { dg-warning "'h' on read-only file descriptor 'fd'" } */
+  }
+  close(fd);
+}
+
+void ff (int fd) __attribute__((fd_arg(1))); /* { dg-message "argument 1 of 'ff' must be an open file descriptor, due to '__attribute__\\(\\(fd_arg\\(1\\)\\)\\)'" } */
+
+void test_4 (const char *path)
+{
+  int fd = open (path, O_RDWR);
+  ff (fd); /* { dg-warning "'ff' on possibly invalid file descriptor 'fd'" } */
+  close(fd);
 }
\ No newline at end of file