Message ID | 66fe11a5-62b2-3016-c9d6-9ccf28858528@gmail.com |
---|---|
State | New |
Headers | show |
Series | correct __clear_cache signature | expand |
Hi Martin, On Wed, Feb 06, 2019 at 05:28:08PM -0700, Martin Sebor wrote: > void > -__clear_cache (char *beg __attribute__((__unused__)), > - char *end __attribute__((__unused__))) > +__clear_cache (void *beg __attribute__((__unused__)), > + void *end __attribute__((__unused__))) > { > #ifdef CLEAR_INSN_CACHE > - CLEAR_INSN_CACHE (beg, end); > + /* Cast the void* pointers to char* as some implementations > + of the macro assume the pointers can be subtracted from > + one another. */ > + CLEAR_INSN_CACHE ((char *) beg, (char *) end); > #endif /* CLEAR_INSN_CACHE */ > } You can subtract pointers to void in GCC just fine, it's a GNU C extension. See extend.texi: In GNU C, addition and subtraction operations are supported on pointers to @code{void} and on pointers to functions. This is done by treating the size of a @code{void} or of a function as 1. (and libgcc is built with GCC always). Segher
On 2/7/19 2:46 AM, Segher Boessenkool wrote: > Hi Martin, > > On Wed, Feb 06, 2019 at 05:28:08PM -0700, Martin Sebor wrote: >> void >> -__clear_cache (char *beg __attribute__((__unused__)), >> - char *end __attribute__((__unused__))) >> +__clear_cache (void *beg __attribute__((__unused__)), >> + void *end __attribute__((__unused__))) >> { >> #ifdef CLEAR_INSN_CACHE >> - CLEAR_INSN_CACHE (beg, end); >> + /* Cast the void* pointers to char* as some implementations >> + of the macro assume the pointers can be subtracted from >> + one another. */ >> + CLEAR_INSN_CACHE ((char *) beg, (char *) end); >> #endif /* CLEAR_INSN_CACHE */ >> } > > You can subtract pointers to void in GCC just fine, it's a GNU C extension. > See extend.texi: > > In GNU C, addition and subtraction operations are supported on pointers to > @code{void} and on pointers to functions. This is done by treating the > size of a @code{void} or of a function as 1. > > (and libgcc is built with GCC always). Sure. The macro is a no-op on x86_64 where I tested so I didn't want to take any chances this late in stage 4 and end up breaking someone's builds. Martin
Ping: https://gcc.gnu.org/ml/gcc-patches/2019-02/msg00361.html On 2/6/19 5:28 PM, Martin Sebor wrote: > Recent libgcc builds have been triggering -Wbuiltin-declaration-mismatch > due to the declaration of the __clear_cache built-in being incompatible > with how GCC declares it internally. The attached patch adjusts > the libgcc declaration and the one in the manual to match what GCC > expects. > > Tested on x86_64-linux. > > Martin
Martin Sebor <msebor@gmail.com> writes: > Recent libgcc builds have been triggering -Wbuiltin-declaration-mismatch > due to the declaration of the __clear_cache built-in being incompatible > with how GCC declares it internally. The attached patch adjusts > the libgcc declaration and the one in the manual to match what GCC > expects. > > Tested on x86_64-linux. OK, thanks. Richard
libgcc/ChangeLog: * libgcc2.h (__clear_cache): Correct signature. * libgcc2.c (__clear_cache): Same. gcc/ChangeLog: * doc/extend.texi (__clear_cache): Correct signature. gcc/testsuite/ChangeLog: * gcc.dg/Wbuiltin-declaration-mismatch-12.c: New test. Index: libgcc/libgcc2.h =================================================================== --- libgcc/libgcc2.h (revision 268583) +++ libgcc/libgcc2.h (working copy) @@ -30,7 +30,7 @@ see the files COPYING3 and COPYING.RUNTIME respect #endif extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t); -extern void __clear_cache (char *, char *); +extern void __clear_cache (void *, void *); extern void __eprintf (const char *, const char *, unsigned int, const char *) __attribute__ ((__noreturn__)); Index: libgcc/libgcc2.c =================================================================== --- libgcc/libgcc2.c (revision 268583) +++ libgcc/libgcc2.c (working copy) @@ -2162,11 +2162,14 @@ __eprintf (const char *string, const char *express /* Clear part of an instruction cache. */ void -__clear_cache (char *beg __attribute__((__unused__)), - char *end __attribute__((__unused__))) +__clear_cache (void *beg __attribute__((__unused__)), + void *end __attribute__((__unused__))) { #ifdef CLEAR_INSN_CACHE - CLEAR_INSN_CACHE (beg, end); + /* Cast the void* pointers to char* as some implementations + of the macro assume the pointers can be subtracted from + one another. */ + CLEAR_INSN_CACHE ((char *) beg, (char *) end); #endif /* CLEAR_INSN_CACHE */ } Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 268583) +++ gcc/doc/extend.texi (working copy) @@ -13073,7 +13073,7 @@ void foo (void) @end deftypefn -@deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end}) +@deftypefn {Built-in Function} void __builtin___clear_cache (void *@var{begin}, void *@var{end}) This function is used to flush the processor's instruction cache for the region of memory between @var{begin} inclusive and @var{end} exclusive. Some targets require that the instruction cache be Index: gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c =================================================================== --- gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c (nonexistent) +++ gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-12.c (working copy) @@ -0,0 +1,8 @@ +/* Verify that declaring the __clear_cache and __builtin_prefetch + intrinsic functions with the wrong signature is diagnosed. + { dg-do compile } + { dg-options "-Wbuiltin-declaration-mismatch -Wextra" } */ + +extern void __clear_cache (char*, char*); /* { dg-warning "mismatch in argument 1 type of built-in function .__clear_cache.; expected .void \\\*." } */ + +void __builtin_prefetch (const char *, ...); /* { dg-warning "mismatch in argument 1 type of built-in function .__builtin_prefetch.; expected .const void \\\*." } */