Message ID | 328b6145af0d5c1d2c3fc5ef44cb7b747173d021.1736478704.git.sam@gentoo.org |
---|---|
State | New |
Headers | show |
Series | malloc: obscure calloc use in tst-calloc | expand |
On Fri, Jan 10, 2025, 11:12 AM Sam James <sam@gentoo.org> wrote: > Similar to a9944a52c967ce76a5894c30d0274b824df43c7a and > f9493a15ea9cfb63a815c00c23142369ec09d8ce, we need to hide calloc use from > the compiler to accommodate GCC's r15-6566-g804e9d55d9e54c change. > > First, include tst-malloc-aux.h, but then use `volatile` variables > for size. > > The test passes without the tst-malloc-aux.h change but IMO we want > it there for consistency and to avoid future problems (possibly silent). > --- > malloc/tst-calloc.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/malloc/tst-calloc.c b/malloc/tst-calloc.c > index 77a32f8052..122b2cbeaf 100644 > --- a/malloc/tst-calloc.c > +++ b/malloc/tst-calloc.c > @@ -23,6 +23,7 @@ > #include <stdio.h> > #include <libc-diag.h> > > +#include "tst-malloc-aux.h" > > /* Number of samples per size. */ > #define N 50000 > @@ -94,16 +95,19 @@ random_test (void) > static void > null_test (void) > { > + /* Obscure allocation size from the compiler. */ > + volatile size_t max_size = UINT_MAX; > + volatile size_t zero_size = 0; > /* If the size is 0 the result is implementation defined. Just make > sure the program doesn't crash. The result of calloc is > deliberately ignored, so do not warn about that. */ > DIAG_PUSH_NEEDS_COMMENT; > DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result"); > calloc (0, 0); > - calloc (0, UINT_MAX); > - calloc (UINT_MAX, 0); > - calloc (0, ~((size_t) 0)); > - calloc (~((size_t) 0), 0); > + calloc (0, max_size); > + calloc (max_size, 0); > + calloc (0, ~((size_t) zero_size)); > + calloc (~((size_t) zero_size), 0); > DIAG_POP_NEEDS_COMMENT; > } > > > base-commit: dad44389f2f96523080e3b105eee1b1ab8b19722 > prerequisite-patch-id: 6bc066b9be8e3c65fae35848708646513d151266 > -- > 2.48.0.rc2 > LGTM. Thanks. > >
Am Freitag, 10. Januar 2025, 04:40:31 Mitteleuropäische Normalzeit schrieb H.J. Lu: > On Fri, Jan 10, 2025, 11:12 AM Sam James <sam@gentoo.org> wrote: > > > Similar to a9944a52c967ce76a5894c30d0274b824df43c7a and > > f9493a15ea9cfb63a815c00c23142369ec09d8ce, we need to hide calloc use from > > the compiler to accommodate GCC's r15-6566-g804e9d55d9e54c change. > > > > First, include tst-malloc-aux.h, but then use `volatile` variables > > for size. > > > > The test passes without the tst-malloc-aux.h change but IMO we want > > it there for consistency and to avoid future problems (possibly silent). OK for 2.41 (test improvement) > > --- > > malloc/tst-calloc.c | 12 ++++++++---- > > 1 file changed, 8 insertions(+), 4 deletions(-) > > > > diff --git a/malloc/tst-calloc.c b/malloc/tst-calloc.c > > index 77a32f8052..122b2cbeaf 100644 > > --- a/malloc/tst-calloc.c > > +++ b/malloc/tst-calloc.c > > @@ -23,6 +23,7 @@ > > #include <stdio.h> > > #include <libc-diag.h> > > > > +#include "tst-malloc-aux.h" > > > > /* Number of samples per size. */ > > #define N 50000 > > @@ -94,16 +95,19 @@ random_test (void) > > static void > > null_test (void) > > { > > + /* Obscure allocation size from the compiler. */ > > + volatile size_t max_size = UINT_MAX; > > + volatile size_t zero_size = 0; > > /* If the size is 0 the result is implementation defined. Just make > > sure the program doesn't crash. The result of calloc is > > deliberately ignored, so do not warn about that. */ > > DIAG_PUSH_NEEDS_COMMENT; > > DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result"); > > calloc (0, 0); > > - calloc (0, UINT_MAX); > > - calloc (UINT_MAX, 0); > > - calloc (0, ~((size_t) 0)); > > - calloc (~((size_t) 0), 0); > > + calloc (0, max_size); > > + calloc (max_size, 0); > > + calloc (0, ~((size_t) zero_size)); > > + calloc (~((size_t) zero_size), 0); > > DIAG_POP_NEEDS_COMMENT; > > } > > > > > > base-commit: dad44389f2f96523080e3b105eee1b1ab8b19722 > > prerequisite-patch-id: 6bc066b9be8e3c65fae35848708646513d151266 > > -- > > 2.48.0.rc2 > > > > LGTM. > > Thanks. > > > > > > >
On Fri, 10 Jan 2025, Sam James wrote: > diff --git a/malloc/tst-calloc.c b/malloc/tst-calloc.c > index 77a32f8052..122b2cbeaf 100644 > --- a/malloc/tst-calloc.c > +++ b/malloc/tst-calloc.c > @@ -94,16 +95,19 @@ random_test (void) > static void > null_test (void) > { > + /* Obscure allocation size from the compiler. */ > + volatile size_t max_size = UINT_MAX; > + volatile size_t zero_size = 0; > /* If the size is 0 the result is implementation defined. Just make > sure the program doesn't crash. The result of calloc is > deliberately ignored, so do not warn about that. */ > DIAG_PUSH_NEEDS_COMMENT; > DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result"); > calloc (0, 0); > - calloc (0, UINT_MAX); > - calloc (UINT_MAX, 0); > - calloc (0, ~((size_t) 0)); > - calloc (~((size_t) 0), 0); > + calloc (0, max_size); > + calloc (max_size, 0); > + calloc (0, ~((size_t) zero_size)); > + calloc (~((size_t) zero_size), 0); The casts obviously serve no purpose and make no sense anymore. Maciej
"Maciej W. Rozycki" <macro@orcam.me.uk> writes: > On Fri, 10 Jan 2025, Sam James wrote: > >> diff --git a/malloc/tst-calloc.c b/malloc/tst-calloc.c >> index 77a32f8052..122b2cbeaf 100644 >> --- a/malloc/tst-calloc.c >> +++ b/malloc/tst-calloc.c >> @@ -94,16 +95,19 @@ random_test (void) >> static void >> null_test (void) >> { >> + /* Obscure allocation size from the compiler. */ >> + volatile size_t max_size = UINT_MAX; >> + volatile size_t zero_size = 0; >> /* If the size is 0 the result is implementation defined. Just make >> sure the program doesn't crash. The result of calloc is >> deliberately ignored, so do not warn about that. */ >> DIAG_PUSH_NEEDS_COMMENT; >> DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result"); >> calloc (0, 0); >> - calloc (0, UINT_MAX); >> - calloc (UINT_MAX, 0); >> - calloc (0, ~((size_t) 0)); >> - calloc (~((size_t) 0), 0); >> + calloc (0, max_size); >> + calloc (max_size, 0); >> + calloc (0, ~((size_t) zero_size)); >> + calloc (~((size_t) zero_size), 0); > > The casts obviously serve no purpose and make no sense anymore. I'll add that to series of other fixes I'll send later.
diff --git a/malloc/tst-calloc.c b/malloc/tst-calloc.c index 77a32f8052..122b2cbeaf 100644 --- a/malloc/tst-calloc.c +++ b/malloc/tst-calloc.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <libc-diag.h> +#include "tst-malloc-aux.h" /* Number of samples per size. */ #define N 50000 @@ -94,16 +95,19 @@ random_test (void) static void null_test (void) { + /* Obscure allocation size from the compiler. */ + volatile size_t max_size = UINT_MAX; + volatile size_t zero_size = 0; /* If the size is 0 the result is implementation defined. Just make sure the program doesn't crash. The result of calloc is deliberately ignored, so do not warn about that. */ DIAG_PUSH_NEEDS_COMMENT; DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result"); calloc (0, 0); - calloc (0, UINT_MAX); - calloc (UINT_MAX, 0); - calloc (0, ~((size_t) 0)); - calloc (~((size_t) 0), 0); + calloc (0, max_size); + calloc (max_size, 0); + calloc (0, ~((size_t) zero_size)); + calloc (~((size_t) zero_size), 0); DIAG_POP_NEEDS_COMMENT; }