Re: [PATCH] Makefile: enable -Wsparse-error for DEVELOPER build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Junio,

On 31/10/2020 22:22, Junio C Hamano wrote:
> With -Wsparse-error, "make sparse" would fail, instead of just
> giving a warning message.
> 
> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
> ---
>  config.mak.dev | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git c/config.mak.dev w/config.mak.dev
> index 3126a5364d..022fb58218 100644
> --- c/config.mak.dev
> +++ w/config.mak.dev
> @@ -1,5 +1,6 @@
>  ifeq ($(filter no-error,$(DEVOPTS)),)
>  DEVELOPER_CFLAGS += -Werror
> +SPARSE_FLAGS += -Wsparse-error
>  endif
>  ifneq ($(filter pedantic,$(DEVOPTS)),)
>  DEVELOPER_CFLAGS += -pedantic
> 

I certainly wouldn't object to such a patch, but I'm not sure who it
would actually help. ;-)

As you may already know, I 'make sparse >sp-out 2>&1' on the master
branch, use vim to check for warnings/errors, and then diff the
corresponding files for 'next' and 'seen' branches (nsp-out, ssp-out).
Similarly, I 'make -k hdr-check >hcout 2>&1' on the master branch,
use vim ... etc. Note, however, the use of '-k' on the make invocation
to make sure I catch all warnings/errors, since '-Werror' is given with
the DEVELOPER variable set. So, I would have to do the same with the
'make sparse' invocation after this patch [1].

Yes, anybody who just does 'make sparse' will notice the failure, so
that would be a definite improvement. (How many people run 'make sparse'
though?). It probably would help anybody using 'cgcc' to develop, but
this doesn't quite work (I just tried this for the first time in ages
and was surprised to find it almost works for me, YMMV):

  $ git branch -v | grep '^\*'
  * seen         4141ae2199 Merge branch 'dd/upload-pack-stateless-eof' into seen
  $ make clean >/dev/null
  $ 

  $ make CC=cgcc >sout2 2>&1
  $ ./git version
  git version 2.29.2.389.g4141ae2199
  $ git describe
  v2.29.2-389-g4141ae2199
  $ 

  $ grep 'warn' sout2
  pack-revindex.c:66:23: warning: memset with byte count of 262144
  upload-pack.c:1114:86: warning: Using plain integer as NULL pointer
  $ 

So, this would have failed, because some extra flags ('SP_EXTRA_FLAGS' to
be precise) are not being passed to sparse. We can see that:

  $ grep SP_EXTRA_FLAGS Makefile
  SP_EXTRA_FLAGS = -Wno-universal-initializer
  http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SP_EXTRA_FLAGS += \
  pack-revindex.sp: SP_EXTRA_FLAGS += -Wno-memcpy-max-count
  compat/nedmalloc/nedmalloc.sp: SP_EXTRA_FLAGS += -Wno-non-pointer-null
  		$(SPARSE_FLAGS) $(SP_EXTRA_FLAGS) $<
  $ 

(Note that you can't see -DCURL_DISABLE_TYPECHECK being set for all the
libcurl using files). So, either sparse has improved to the point that
the 'typecheck' shenanigans used in the libcurl headers don't cause it
problems anymore, or the headers have changed sufficiently. (Hmm, that
header doesn't seem to have changed much).

I don't build with nedmalloc, but last time I did it was littered with
uses of '0' as a NULL pointer (hence the -Wno-non-pointer-null). Given
that we will probably not re-import that code, I suppose all of those
sparse warnings could be fixed.

Which leaves 'pack-revindex.c'. Unfortunately, I don't see an easy fix
for that (-Wno-universal-initializer is now the default, so we don't
need that anymore). Well, I suppose anybody could add 'CFLAGS+=-Wno-\
memcpy-max-count' to their config.mak file (this '-W' argument is
filtered out by cgcc and not passed to gcc). [EDIT: I just tried this
and, yes, this does work! I'm still surprised about curl headers ;-) ]

Note also that my build slowed down by 14% using CC=cgcc, since it is
running both sparse and gcc on each source file.

I guess it would be most useful on a CI build, but I don't know what
would be involved in setting that up.

ATB,
Ramsay Jones

[1] It took about one month for me to get used to the 'pu'->'seen' change,
    but that was mostly training my fingers to type all of the output
    files that are keyed by the branch name: pout->sout, psp-out->ssp-out,
    psc->ssc, phcout->shcout and ptest-out->stest-out. :D




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux