From 3e990d795405b370dc5315da59ce809750173312 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 30 Jan 2020 15:44:59 -0500 Subject: [PATCH] analyzer: avoid using in malloc-1.c This test assumes that memset and strlen have been marked with __attribute__((nonnull)), which isn't necessarily the case for an arbitrary . This likely explains these failures: FAIL: gcc.dg/analyzer/malloc-1.c (test for warnings, line 417) FAIL: gcc.dg/analyzer/malloc-1.c (test for warnings, line 418) FAIL: gcc.dg/analyzer/malloc-1.c (test for warnings, line 425) FAIL: gcc.dg/analyzer/malloc-1.c (test for warnings, line 429) seen in https://gcc.gnu.org/ml/gcc-testresults/2020-01/msg01608.html on x86_64-apple-darwin18. Fix it by using the __builtin_ forms. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/malloc-1.c: Remove include of . Use __builtin_ forms of memset and strlen throughout. --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/analyzer/malloc-1.c | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 77dcc013b3f..e4e612ada92 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-30 David Malcolm + + * gcc.dg/analyzer/malloc-1.c: Remove include of . + Use __builtin_ forms of memset and strlen throughout. + 2020-01-30 David Malcolm * gcc.dg/analyzer/conditionals-2.c: Move to... diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c index e2e279bd7fd..c13170560af 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c @@ -1,6 +1,5 @@ #include #include -#include extern int foo (void); extern int bar (void); @@ -71,7 +70,7 @@ void test_7 (void) void *ptr = malloc(4096); if (!ptr) return; - memset(ptr, 0, 4096); + __builtin_memset(ptr, 0, 4096); free(ptr); } @@ -80,7 +79,7 @@ void *test_8 (void) void *ptr = malloc(4096); if (!ptr) return NULL; - memset(ptr, 0, 4096); + __builtin_memset(ptr, 0, 4096); return ptr; /* This needs phi nodes to affect equivalence classes, or we get a false report of a leak. */ @@ -398,7 +397,7 @@ int test_35 (void) void *ptr = malloc(4096); if (!ptr) return -1; - memset(ptr, 0, 4096); + __builtin_memset(ptr, 0, 4096); free(ptr); return 0; } @@ -408,14 +407,14 @@ void test_36 (void) void *ptr = malloc(4096); if (!ptr) return; - memset(ptr, 0, 4096); + __builtin_memset(ptr, 0, 4096); free(ptr); } void *test_37a (void) { void *ptr = malloc(4096); /* { dg-message "this call could return NULL" } */ - memset(ptr, 0, 4096); /* { dg-warning "use of possibly-NULL 'ptr' where non-null expected" } */ + __builtin_memset(ptr, 0, 4096); /* { dg-warning "use of possibly-NULL 'ptr' where non-null expected" } */ return ptr; } @@ -424,9 +423,9 @@ int test_37b (void) void *p = malloc(4096); void *q = malloc(4096); /* { dg-message "this call could return NULL" } */ if (p) { - memset(p, 0, 4096); /* Not a bug: checked */ + __builtin_memset(p, 0, 4096); /* Not a bug: checked */ } else { - memset(q, 0, 4096); /* { dg-warning "use of possibly-NULL 'q' where non-null expected" } */ + __builtin_memset(q, 0, 4096); /* { dg-warning "use of possibly-NULL 'q' where non-null expected" } */ } free(p); free(q); @@ -579,7 +578,7 @@ int test_47 (void) int retval = maybe_alloc (&p); /* this might write to "p". */ if (retval) return (retval); - p_size = strlen(p); /* { dg-bogus "non-null expected" } */ + p_size = __builtin_strlen(p); /* { dg-bogus "non-null expected" } */ free (p); } return p_size; -- 2.30.2