Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3060777imu; Mon, 19 Nov 2018 10:03:01 -0800 (PST) X-Google-Smtp-Source: AJdET5fKP7jyAIruy9gZFCv5WRdlFxYODVxSL64u4vU3SkZSxpHWkP6pXRCC9pCsiLeKotl7rbKJ X-Received: by 2002:a17:902:a58a:: with SMTP id az10mr24101324plb.151.1542650581489; Mon, 19 Nov 2018 10:03:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542650581; cv=none; d=google.com; s=arc-20160816; b=CYLmHDgrFyBzdn1VncR5nSCvhQ2MvcRjx+ySlEyuRNPl6XYknzsjvHKZ3M8PvEDBRp tVu+JzpYEaS7pQF1xygjbaWnhHyfgA9Q1bVXVoV02l+YHXpvdDUIYEmj0k48X6+NZvAP w/7o5lXajaTP7W0ZiHCULnN03+n9LThMfnIQBAvZKuSjnkKoL9h/cve0PZvb2PBnNyh7 DqCr2J6Xeiwc+9FimyMD9idGF1yYLH0Z7CkOJoDzRDIekEuHtAG28AjEEtOzLeTeNkfx PQqQDKUkdasB2Dolb7llRNvqF2aJUI5IxMGYKJpXQ+itTfyvdr+SGJGEauxZJ0dScLXm 0o4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MgahdtnYV32tyTGT6Q6qYILjgWU8vS94WNHJ16VkQL0=; b=CnluxZWbnv0Yx09wLEoSJ7qsnkVIys+HbshP3W/CEFlEah+6/a0491yFF86JJyy4Gk MmvkRjI4etsAn7HJobDSh3z7SToZr7YhTySFD0RcM3aV3npEN2RynnQA6Mg6epjx0i5K dmZpWw3OZ9fxsq+o1p789NQT5nb0L9qVsR886XNLurcHIMTcha2WY7K6yUgpRcUdotVs BcDvNttW7Qa1I0IKhiTE6sDblWVw4fITKYvKnk8BlYZNJ/ygHx9Yox3PkypvlhEqvIWS rwTyQ17iDJfrddsZXForO/yATrXVhAFx5rdNxTeUpTax8omrlr5YUCNZOXZi7Ff6Qpaj q/xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MsjE8AHq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12-v6si31821282plg.114.2018.11.19.10.02.27; Mon, 19 Nov 2018 10:03:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MsjE8AHq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732164AbeKTEZm (ORCPT + 99 others); Mon, 19 Nov 2018 23:25:42 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34273 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730227AbeKTEZm (ORCPT ); Mon, 19 Nov 2018 23:25:42 -0500 Received: by mail-pf1-f193.google.com with SMTP id h3so8672236pfg.1 for ; Mon, 19 Nov 2018 10:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MgahdtnYV32tyTGT6Q6qYILjgWU8vS94WNHJ16VkQL0=; b=MsjE8AHqOTkfoJWpebl+tpxtfNlNmed5qqOm2Gn0fZ2giDQDEbQcvoZyn4S3T5Miy9 n7l0azdmhCXoaAdY4d3q2MM9ioP4sjGmo0SgACMGRsjWWHHc/U6t5TqG9QTdlQSKBTV5 BxLjox6/HO7azwt961teqQ8sHdDjGXkK7yLJ6N2xAnOdu0P6TrZJVt+O/wtWfIKU4PRy EI+C9Ft9fkuoSt2z0D6RZCs8HIoFswPy1JFiw+dMMrC5h6t3yqz1k3Zff9IaRro8TwW7 V0yplHDIUdK2/jqUqD1Sth1evWmlqKj7g1svgdnSW/mALXPD2f/+nA3arLozfruttbhC S4pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MgahdtnYV32tyTGT6Q6qYILjgWU8vS94WNHJ16VkQL0=; b=mDYR8oUCGwwUGu8EXE2g0+aixoghkUJDrm7HfLrCZE3BgBfZk3mGuHg+TISzFttA6L 9CfoCaEYrRq/ws5gi0CfMEMLzIeJXKc4AW+MCPy1u7AnTASunsxl40cMJc4sKWxMsMD1 X22CN8KQbJkO+wtAyHwYIajUTYqP/o29deedZR0w1K3A1soQX+cuBlV4ngnt5fMDZxWG yDIR0kGg3TbAjqmEzp2enfgybCuKdC5l+PA8ktqmWfdbG43UHX0jPXcQSJA4V55PIrWx S+8Glgw4rxs4CON5g2Y3rLI37eYCsmOJd3bvG3/dFfi0LQLginjEoPGiUBBWh/l24fi4 sqhw== X-Gm-Message-State: AGRZ1gKpGwELZ0iIUci/kIsnpd9BpJBa2egkuuuJxlFd6cE+IyOENJbC nLLbZcqNms86mSKhPM6F6MpQK+YWQFKErBYvlhpxFQ== X-Received: by 2002:a63:e156:: with SMTP id h22mr21165415pgk.255.1542650465972; Mon, 19 Nov 2018 10:01:05 -0800 (PST) MIME-Version: 1.0 References: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> <1542623503-3755-3-git-send-email-yamada.masahiro@socionext.com> <20181119123732.zcb6axl25bixgtly@ltop.local> In-Reply-To: <20181119123732.zcb6axl25bixgtly@ltop.local> From: Nick Desaulniers Date: Mon, 19 Nov 2018 10:00:54 -0800 Message-ID: Subject: Re: [PATCH v3 3/3] build_bug.h: remove most of dummy BUILD_BUG_ON stubs for sparse To: Luc Van Oostenryck Cc: Masahiro Yamada , Andrew Morton , Kees Cook , josh@joshtriplett.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 19, 2018 at 4:37 AM Luc Van Oostenryck wrote: > > On Mon, Nov 19, 2018 at 07:31:43PM +0900, Masahiro Yamada wrote: > > The introduction of these dummy BUILD_BUG_ON stubs dates back to > > commit 903c0c7cdc21 ("sparse: define dummy BUILD_BUG_ON definition > > for sparse"). > > > > At that time, BUILD_BUG_ON() was implemented with the negative array > > trick *and* the link-time trick, like this: > > > > extern int __build_bug_on_failed; > > #define BUILD_BUG_ON(condition) \ > > do { \ > > ((void)sizeof(char[1 - 2*!!(condition)])); \ > > if (condition) __build_bug_on_failed = 1; \ > > } while(0) > > > > Sparse is more strict about the negative array trick than GCC because > > Sparse requires the array length to be really constant. > > > > Here is the simple test code for the macro above: > > > > static const int x = 0; > > BUILD_BUG_ON(x); > > > > GCC is absolutely fine with it (-Wvla was not enabled at that time), > > but Sparse warns like this: > > > > error: bad constant expression > > error: cannot size expression > > > > (If you are using a newer version of Sparse, you will see a different > > warning message, "warning: Variable length array is used".) > > > > Anyway, Sparse was producing many false positive warnings, hence > > silenced. > > > > With the previous commit, the leftover negative array trick is gone. > > Sparse is fine with the current BUILD_BUG_ON(), which is implemented > > by using the 'error' attribute. (assuming your Sparse version supports > > -Wno-unknown-attribute option) > > > > I am keeping the stub for BUILD_BUG_ON_ZERO(). Otherwise, Sparse > > would complain about the following code, which GCC is fine with: > > > > static const int x = 0; > > int y = BUILD_BUG_ON_ZERO(x); > > > > Signed-off-by: Masahiro Yamada > > Acked-by: Kees Cook > > Reviewed-by: Luc Van Oostenryck Clang builds not affected. Tested a quick arm64 defconfig build with Clang + this patch. Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers -- Thanks, ~Nick Desaulniers