From patchwork Tue Oct 4 08:54:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 9361367 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 AEB67607D6 for ; Tue, 4 Oct 2016 08:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A07A2286B1 for ; Tue, 4 Oct 2016 08:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 955BE287A3; Tue, 4 Oct 2016 08:54:50 +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=-6.9 required=2.0 tests=BAYES_00,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 60F7E286B1 for ; Tue, 4 Oct 2016 08:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753936AbcJDIys (ORCPT ); Tue, 4 Oct 2016 04:54:48 -0400 Received: from s3.sipsolutions.net ([5.9.151.49]:40624 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753935AbcJDIys (ORCPT ); Tue, 4 Oct 2016 04:54:48 -0400 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1brLUs-0003ok-UP; Tue, 04 Oct 2016 10:54:47 +0200 From: Johannes Berg To: sparse@chrisli.org Cc: linux-sparse@vger.kernel.org Subject: [PATCH] sparse: make __builtin_object_size argument const Date: Tue, 4 Oct 2016 10:54:45 +0200 Message-Id: <1475571285-18180-1-git-send-email-johannes@sipsolutions.net> X-Mailer: git-send-email 2.8.1 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gcc clearly allows that, and this makes no difference since we can still pass a non-const pointer without warnings. Add a test for it, while at it. Signed-off-by: Johannes Berg --- lib.c | 2 +- validation/builtin_object_size.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 validation/builtin_object_size.c diff --git a/lib.c b/lib.c index 8dc5bcf9dc18..cade28c95a48 100644 --- a/lib.c +++ b/lib.c @@ -877,7 +877,7 @@ void declare_builtin_functions(void) add_pre_buffer("extern int __builtin_isunordered(float, float);\n"); /* And some __FORTIFY_SOURCE ones.. */ - add_pre_buffer ("extern __SIZE_TYPE__ __builtin_object_size(void *, int);\n"); + add_pre_buffer ("extern __SIZE_TYPE__ __builtin_object_size(const void *, int);\n"); add_pre_buffer ("extern void * __builtin___memcpy_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n"); add_pre_buffer ("extern void * __builtin___memmove_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n"); add_pre_buffer ("extern void * __builtin___mempcpy_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n"); diff --git a/validation/builtin_object_size.c b/validation/builtin_object_size.c new file mode 100644 index 000000000000..a7013a80e7fd --- /dev/null +++ b/validation/builtin_object_size.c @@ -0,0 +1,13 @@ +static void fn(void) +{ + static int i; + const void *ptr = (void *)0; + + i = __builtin_object_size(ptr, 0); +} + +/* + * check-name: __builtin_object_size + * check-error-start + * check-error-end + */