From patchwork Sat Apr 14 01:18:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jasmin J." X-Patchwork-Id: 10340871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 373F8601C2 for ; Sat, 14 Apr 2018 01:18:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1690A28A5F for ; Sat, 14 Apr 2018 01:18:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A23028A62; Sat, 14 Apr 2018 01:18:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52CEB28A5F for ; Sat, 14 Apr 2018 01:18:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751032AbeDNBS1 (ORCPT ); Fri, 13 Apr 2018 21:18:27 -0400 Received: from mail.anw.at ([195.234.101.228]:35957 "EHLO mail.anw.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750867AbeDNBS0 (ORCPT ); Fri, 13 Apr 2018 21:18:26 -0400 Received: from [192.168.23.40] (anwhome.anw.at [195.234.103.23]) by mail.anw.at (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id w3E1INxN002193; Sat, 14 Apr 2018 03:18:23 +0200 From: "Jasmin J." Subject: Re: Smatch and sparse errors To: Mauro Carvalho Chehab , Hans Verkuil Cc: LMML References: <20180411122728.52e6fa9a@vento.lan> Message-ID: Date: Sat, 14 Apr 2018 03:18:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180411122728.52e6fa9a@vento.lan> Content-Language: en-GB X-Antivirus: checked in 0.049sec at mail.anw.at ([195.234.102.72]) by smf-clamd v1.2.1 - http://smfs.sf.net/ Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello Mauro/Hans! > There is already an upstream patch for hidding it: The patch from https://patchwork.kernel.org/patch/10334353 will not apply at the smatch tree. Attached is an updated version for smatch. Even with the patched tools, sparse still complains: CC drivers/media/cec/cec-core.o /opt/media_test/media-git/include/linux/mm.h:533:24: warning: constant 0xffffc90000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:533:48: warning: constant 0xffffc90000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:624:29: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:1098:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:1795:27: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:1887:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:151:25: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:236:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:387:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:387:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/dma-mapping.h:235:35: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/dma-mapping.h:238:33: warning: constant 0xffffea0000000000 is so big it is unsigned long CC drivers/media/usb/gspca/gl860/gl860-mi2020.o /opt/media_test/media-git/include/linux/mm.h:533:24: warning: constant 0xffffc90000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:533:48: warning: constant 0xffffc90000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:624:29: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:1098:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:1795:27: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/mm.h:1887:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:151:25: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:236:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:387:16: warning: constant 0xffffea0000000000 is so big it is unsigned long /opt/media_test/media-git/include/linux/scatterlist.h:387:16: warning: constant 0xffffea0000000000 is so big it is unsigned long But other warnings are gone with the patch. The daily build is running on a machine of Hans. He need to update the tools there. @Hans: Until this patches are in upstream, we need to patch smatch/sparse on the fly in build.sh after pulling the last tools version. BR, Jasmin diff --git a/evaluate.c b/evaluate.c index 1533730..815e7e1 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2090,7 +2090,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) size = type->bit_size; if (size < 0 && is_void_type(type)) { - warning(expr->pos, "expression using sizeof(void)"); + if (Wpointer_arith) + warning(expr->pos, "expression using sizeof(void)"); size = bits_in_char; } @@ -2101,7 +2102,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) } if (is_function(type->ctype.base_type)) { - warning(expr->pos, "expression using sizeof on a function"); + if (Wpointer_arith) + warning(expr->pos, "expression using sizeof on a function"); size = bits_in_char; } diff --git a/lib.c b/lib.c index 69b5ab8..ed4a74f 100644 --- a/lib.c +++ b/lib.c @@ -234,6 +234,7 @@ int Wnon_pointer_null = 1; int Wold_initializer = 1; int Wone_bit_signed_bitfield = 1; int Wparen_string = 0; +int Wpointer_arith = 0; int Wptr_subtraction_blows = 0; int Wreturn_void = 0; int Wshadow = 0; @@ -453,6 +454,7 @@ static const struct warning { { "return-void", &Wreturn_void }, { "shadow", &Wshadow }, { "sizeof-bool", &Wsizeof_bool }, + { "pointer-arith", &Wpointer_arith }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign }, { "undef", &Wundef }, diff --git a/lib.h b/lib.h index 0838342..a86615b 100644 --- a/lib.h +++ b/lib.h @@ -120,6 +120,7 @@ extern int Wnon_pointer_null; extern int Wold_initializer; extern int Wone_bit_signed_bitfield; extern int Wparen_string; +extern int Wpointer_arith; extern int Wptr_subtraction_blows; extern int Wreturn_void; extern int Wshadow; diff --git a/sparse.1 b/sparse.1 index acdce53..53eff87 100644 --- a/sparse.1 +++ b/sparse.1 @@ -265,6 +265,19 @@ initializer. GCC allows this syntax as an extension. With Sparse does not issue these warnings by default. . .TP +.B \-Wpointer\-arith +Warn about anything that depends on the \fBsizeof\fR a void or function type. + +C99 does not allow the \fBsizeof\fR operator to be applied to function types +or to incomplete types such as void. GCC allows \fBsizeof\fR to be applied to +these types as an extension and assigns these types a size of \fI1\fR. With +\fB\-pointer\-arith\fR, Sparse will warn about pointer arithmetic on void +or function pointers, as well as expressions which directly apply the +\fBsizeof\fR operator to void or function types. + +Sparse does not issue these warnings by default. +. +.TP .B \-Wptr\-subtraction\-blows Warn when subtracting two pointers to a type with a non-power-of-two size.