On Sat, Mar 30, 2019 at 12:29:18AM +0100, Jann Horn wrote: > On Sat, Mar 30, 2019 at 12:25 AM Luc Van Oostenryck > <luc.vanoostenryck@xxxxxxxxx> wrote: > > Sparse will warn on casts removing the address space of a pointer > > if the destination type is not unsigned long. But the special role > > of 'unsigned long' is not explained in the man page. > > > > So, add a small explanation in the description of -Waddress-space. > > > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> > > --- > > sparse.1 | 8 +++++--- > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/sparse.1 b/sparse.1 > > index fae6196bf..a94bf0109 100644 > > --- a/sparse.1 > > +++ b/sparse.1 > > @@ -41,9 +41,11 @@ Sparse allows an extended attribute > > on pointers, which designates a pointer target in address space \fIid\fR (an > > identifier or a constant integer). > > With \fB\-Waddress\-space\fR, Sparse treats pointers with > > -identical target types but different address spaces as distinct types. To > > -override this warning, such as for functions which convert pointers between > > -address spaces, use a type that includes \fB__attribute__((force))\fR. > > +identical target types but different address spaces as distinct types and > > +will warn accordingly. Sparse will also warn on casts which remove the address > > +space (unless the target type is \fBunsigned long\fR and \fB-Wcast\-from\-as\fR > > +is not given). To override these warnings, use a type that includes > > +\fB__attribute__((force))\fR. > > I wonder whether another approach to this might be to have a different > warning string when the target type is a number and isn't `unsigned > long`? It seems to me that a self-explaining error message is > preferable to a clarification in the manpage. Yes, I agree. Have you maybe already something specific in mind? Note that I only tried here to explain the reason for the *absence* of the warning when the cast is to 'unsigned long'. There is also already a(n undocumented) flag -Wpointer-to-int-cast (but which purpose is slightly different) giving a warning when a pointer is cast to an integer of a different size. It would also be good, I think, to have first in the manpage a description of the different extensions that Sparse have to C's type system. This should simplify, the description of the options. -- Luc Van Oostenryck