diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-01-30 15:44:59 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2020-01-30 19:12:11 -0500 |
commit | 3e990d795405b370dc5315da59ce809750173312 (patch) | |
tree | 587108294b39b729115d3bfcc05ec0e8c98e28cc /gcc | |
parent | e34ad101a4338eab41e38e624f2c7178d0b83d24 (diff) | |
download | gcc-3e990d795405b370dc5315da59ce809750173312.zip gcc-3e990d795405b370dc5315da59ce809750173312.tar.gz gcc-3e990d795405b370dc5315da59ce809750173312.tar.bz2 |
analyzer: avoid using <string.h> 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 <string.h>. 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 <string.h>.
Use __builtin_ forms of memset and strlen throughout.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | 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 77dcc01..e4e612a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2020-01-30 David Malcolm <dmalcolm@redhat.com> + * gcc.dg/analyzer/malloc-1.c: Remove include of <string.h>. + Use __builtin_ forms of memset and strlen throughout. + +2020-01-30 David Malcolm <dmalcolm@redhat.com> + * gcc.dg/analyzer/conditionals-2.c: Move to... * gcc.dg/analyzer/torture/conditionals-2.c: ...here, converting to a torture test. Remove redundant include. diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c index e2e279b..c131705 100644 --- a/gcc/testsuite/gcc.dg/analyzer/malloc-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-1.c @@ -1,6 +1,5 @@ #include <alloca.h> #include <stdlib.h> -#include <string.h> 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; |