Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2688486imu; Mon, 19 Nov 2018 04:40:13 -0800 (PST) X-Google-Smtp-Source: AJdET5czL56JKSHyD7t7t/c1Vve3Q0sxO1Zff2nWbY4avTNIoe8Riar9BuhiK4xDOCMCmIgAOEdE X-Received: by 2002:a63:9a52:: with SMTP id e18mr19845755pgo.14.1542631213434; Mon, 19 Nov 2018 04:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542631213; cv=none; d=google.com; s=arc-20160816; b=v1dNw43IxSlufhqMgdNZf3ikMqdWggT67JS7YMh8U4fvqQOGk+pR4RUJ/3lF7YfeQO sde4vGwl+cIj/wMdjxcTQTx8iwHNZFVglg4BqgiIuf91n9/yNCS+uoBet5uKDiQC9vyG Jv5ehg+4y2HPwIfLvaw6JuZfUflohY9Vgdlx/qIyvm/x4JMoyvpRH7lnPfv27Mf5p2vX wuKyvp16fdKYs9Xr+PwUmU92rrsENu277d9yzRdfzvfaYUv3l7NkWuJRr+Bkj7/1AR/F Alhg0/4L27YcLB22GbyADhrmeQnwCOIiWVWHvpQMxMpy9rnhM8xWQPJZ+ygrGXNX20it VwLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uerP6zERXnXOELK7KdfQ8/C1wBZMRrgOAy1qLZQVpIU=; b=Bkc803m5oltFnND9DDLiECdrYhhjecpMl0r6xSszU7qhKym7f0+u7+j0PnFlVhPgo/ C1Vh1f7jPKRsXOnyaFNm+ZNxSO6oUI3q5Qs2Ve8Aqh5e8E4QPVzC0AC6odHCfRIRp1SH cYksntADL47Vth76jBlSXR3gIvqDDbvZbYLOrl6lkCIkOa6mDq4HsnLYVqc0nnzscAIA 0xwdSEmvCcSqCIpFmRRiyz5xv3tSUJ4QzVKBNNBfx8le3ncV6U+ydMZ+9nXLCnhTs77c IQXW8UIBrlSL9SOZlLWydVTeHYOrD1PRaTDW8Rrn+GTurA0JM/m13eKphoF2L5wAOlsM 7E3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Jad4LtkQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y73si37685434pgd.478.2018.11.19.04.39.58; Mon, 19 Nov 2018 04:40:13 -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=@gmail.com header.s=20161025 header.b=Jad4LtkQ; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728848AbeKSXBH (ORCPT + 99 others); Mon, 19 Nov 2018 18:01:07 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:34756 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728724AbeKSXBH (ORCPT ); Mon, 19 Nov 2018 18:01:07 -0500 Received: by mail-ed1-f68.google.com with SMTP id b3so2523283ede.1 for ; Mon, 19 Nov 2018 04:37:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=uerP6zERXnXOELK7KdfQ8/C1wBZMRrgOAy1qLZQVpIU=; b=Jad4LtkQCHXmxMRzrwOgl64u9JcaFMUAtlDltdcXGHMch7IDR7BBcHhtrvlTScHYzw uUaiKsOA0slRHRscZxPzMw43caO6/FYTfSt+WSigT2PsLiikS7QTiUwCV8+pfHp34v4v r2A7aXTiHrIS49DNG7UNdTPq+eAyhfoH6bSUqjyHoFyZ353S+bJET0QoN4hUi4x2rDzc KpRLVaaVQiLjc1V4umGVBKbct+VMQ0ARnHzSVtcW377+5KOc0ASyvVN9SMvI0snd5OMH Cl61mfe9UNy7PZ4zYQQlLoP6+DhIFroS9fCinvL08Uq0Oa72PXhofRetyuCrl3Gc9y2u S3xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=uerP6zERXnXOELK7KdfQ8/C1wBZMRrgOAy1qLZQVpIU=; b=mkcU7o9XqAMOoXwmMtSFXvSjj6lBWrEt7lWevWgWdUZSe7ghN9Nwk1SDL3bI4QBn/f U1kKthtYIroiAyGLtHnGtE5dAVVAqVjmEQRcpjEXfKbV7qceYfCSp8W6bB3CuMcZfe00 SFfCMRrLZkgdFBHfbZZnHAi0bnfHkOTXx+pG3ha+u1P7T0E+ivFc4JLB3bvBhl19Sxy0 J00aIuIV+rLOGSNeDm38opLXgH1dsBKNDj0FeAD/AglFSl/L4DfOVV3A2sJ+QA7hmRZq Jcd+hzV7zjylG+bJh1Y6xV8waQohxcbV6vWqgE7BIy59AlOTEWz1+7GhAa5fs1F1kC6q jNAw== X-Gm-Message-State: AGRZ1gJ0sNF6UymzEbEmu/LA4n9GN3qUJU1Y0UsxO7j94Hncgudy4y5L 4Sik1cb6yZwQnY8LHjVs/tY= X-Received: by 2002:a17:906:16ca:: with SMTP id t10-v6mr16563323ejd.200.1542631055489; Mon, 19 Nov 2018 04:37:35 -0800 (PST) Received: from ltop.local ([2a02:a03f:40bc:4d00:b8ae:204:75e7:9858]) by smtp.gmail.com with ESMTPSA id b49sm8584204edb.73.2018.11.19.04.37.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 04:37:35 -0800 (PST) Date: Mon, 19 Nov 2018 13:37:33 +0100 From: Luc Van Oostenryck To: Masahiro Yamada Cc: Andrew Morton , Nick Desaulniers , Kees Cook , Josh Triplett , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/3] build_bug.h: remove most of dummy BUILD_BUG_ON stubs for sparse Message-ID: <20181119123732.zcb6axl25bixgtly@ltop.local> References: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> <1542623503-3755-3-git-send-email-yamada.masahiro@socionext.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1542623503-3755-3-git-send-email-yamada.masahiro@socionext.com> User-Agent: NeoMutt/20180622 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 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