diff mbox series

[analyzer,testsuite] avoid unexpected null dereference warning

Message ID orwmlshwy4.fsf@lxoliva.fsfla.org
State New
Headers show
Series [analyzer,testsuite] avoid unexpected null dereference warning | expand

Commit Message

Alexandre Oliva July 11, 2024, 1:36 p.m. UTC
The analyzer testsuite, on a customer's own operating system, reports
a potential NULL pointer dereference in flex-without-call-summaries.c.
I'm not sure why it shows up on that system, but not on others, but
the test is not meant to test for that warning, so I'm silencing it.

Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
aarch64.  Ok to install?


for  gcc/testsuite/ChangeLog

	* c-c++-common/analyzer/flex-without-call-summaries.c: Disable
	null dereference analyzer warnings.
---
 .../analyzer/flex-without-call-summaries.c         |    1 +
 1 file changed, 1 insertion(+)

Comments

David Malcolm July 11, 2024, 7:18 p.m. UTC | #1
On Thu, 2024-07-11 at 10:36 -0300, Alexandre Oliva wrote:
> 
> The analyzer testsuite, on a customer's own operating system, reports
> a potential NULL pointer dereference in flex-without-call-
> summaries.c.
> I'm not sure why it shows up on that system, but not on others, but
> the test is not meant to test for that warning, so I'm silencing it.

Hi Alex

I intended that particular test as an integration test, to try to make
sure that -fanalyzer is silent on the result of a minimal "flex"
script.  So if we're actually getting warnings, that's undesirable, and
I'm not sure the approach in your patch is the right one.

Given that the testcase includes various C headers, there's going to be
some variability with different configurations.  Are you able to share
the preprocessed sources with me?  Maybe we should eliminate those
#includes from that test and convert it to something that's more
config-independent?

Thanks
Dave


> 
> Regstrapped on x86_64-linux-gnu, also tested with gcc-13 targeting
> aarch64.  Ok to install?
> 
> 
> for  gcc/testsuite/ChangeLog
> 
>         * c-c++-common/analyzer/flex-without-call-summaries.c:
> Disable
>         null dereference analyzer warnings.
> ---
>  .../analyzer/flex-without-call-summaries.c         |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gcc/testsuite/c-c++-common/analyzer/flex-without-call-
> summaries.c b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-
> summaries.c
> index c6ecb25d25d59..1aad2bc896b7e 100644
> --- a/gcc/testsuite/c-c++-common/analyzer/flex-without-call-
> summaries.c
> +++ b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-
> summaries.c
> @@ -3,6 +3,7 @@
>  
>  /* { dg-additional-options "-fno-analyzer-call-summaries" } */
>  
> +/* { dg-additional-options "-Wno-analyzer-null-dereference" } */
>  /* { dg-additional-options "-Wno-analyzer-too-complex" } */
>  /* { dg-additional-options "-D_POSIX_SOURCE" } */
>  
>
Alexandre Oliva July 12, 2024, 8:02 a.m. UTC | #2
On Jul 11, 2024, David Malcolm <dmalcolm@redhat.com> wrote:

> I intended that particular test as an integration test, to try to make
> sure that -fanalyzer is silent on the result of a minimal "flex"
> script.  So if we're actually getting warnings, that's undesirable, and
> I'm not sure the approach in your patch is the right one.

Understood, thanks, patch withdrawn.

> Given that the testcase includes various C headers, there's going to be
> some variability with different configurations.  Are you able to share
> the preprocessed sources with me?

I'm not sure, but I don't think that will be needed.  Just replacing the
includes with standard declarations and definitions used in the program
was enough to trigger the warning.

> Maybe we should eliminate those #includes from that test and convert
> it to something that's more config-independent?

Here's what I got.  I tried some __builtin_-prefixing, particularly on
exit, hoping that it would bring some noreturn into effect, but that
didn't get rid of the warning, so I left it at that.

diff --git a/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
index c6ecb25d25d59..41ad3359370ee 100644
--- a/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
+++ b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
@@ -14,10 +14,31 @@
 /* First, we deal with  platform-specific or compiler-specific issues. */
 
 /* begin standard C headers. */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
+/* #include <stdio.h> */
+#define EOF -1
+typedef __SIZE_TYPE__ size_t;
+typedef struct FILE FILE;
+extern FILE *stdin, *stdout, *stderr;
+int getc(FILE *);
+int ferror(FILE *);
+size_t fread (void *, size_t, size_t, FILE *);
+size_t fwrite (void *, size_t, size_t, FILE *);
+void clearerr(FILE *);
+int fileno(FILE *);
+int fprintf(FILE *, const char *, ...);
+/* #include <string.h> */
+void *memset(void *, int, size_t);
+size_t strlen(const char *);
+/* #include <errno.h> */
+extern int *__get_errno (void);
+#define errno (*__get_errno ())
+#define EINTR 42
+/* #include <stdlib.h> */
+#define NULL 0
+void exit(int);
+void *malloc(size_t);
+void *realloc(void *, size_t);
+void free(void *);
 
 /* end standard C headers. */
diff mbox series

Patch

diff --git a/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
index c6ecb25d25d59..1aad2bc896b7e 100644
--- a/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
+++ b/gcc/testsuite/c-c++-common/analyzer/flex-without-call-summaries.c
@@ -3,6 +3,7 @@ 
 
 /* { dg-additional-options "-fno-analyzer-call-summaries" } */
 
+/* { dg-additional-options "-Wno-analyzer-null-dereference" } */
 /* { dg-additional-options "-Wno-analyzer-too-complex" } */
 /* { dg-additional-options "-D_POSIX_SOURCE" } */