Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp972611imu; Thu, 22 Nov 2018 08:06:52 -0800 (PST) X-Google-Smtp-Source: AFSGD/WB+p2AgzHn3U48TqCx3dd+HebHNNlhO45/GqyF14D5M/e4wKxHWYZrzD0MjsBASsfWpv5S X-Received: by 2002:a62:4d81:: with SMTP id a123-v6mr1077588pfb.177.1542902812476; Thu, 22 Nov 2018 08:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542902812; cv=none; d=google.com; s=arc-20160816; b=Z0D/pyQMx5VpJ2o/+mu7011JNls7Z3RsFXBnTzJM4i1vplbLLdqFeNVFsyQhFK4iDB wGK0+n+HfM5dminU2X3dWZwRBJUo65eVL4B6s4S0O7svIfVSSrSSaTydAsFCIeQDhcn6 2vC4COY2FbXLXIqvdBv4TY0O+hseSuv0EDfETvWPxeNJZVtMU/i+cQs3tcNuCs9t/V5O b+zoCRLtuh6rQkKT5zxjx0Px7lCB7MqM+I3JDwz/8aiZSr3KK5sSwxCBuI8JbH65KVob qJreypHtxfMNZHiTpWMlnq4WrFFBi64Ufaoj4j1gWJ2x7/eoCq5Kj2m7jL6JL3yq0VEw JNvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=PhO+PXx9f29vDsYbmMZinUspy8MjVFdMSRysGapnTRY=; b=iAXUHdIqF12AUvBq+Xfk15/ciiEFZNJy9z9XV+BzHeNEBjiugsA9yRNgAeiVkx6L8v aOCQnNDmiHnJLMSje+/vG66e65vFAOxhJOA7F0xUPWmlHmcdw/wEBmbNVinKo3UGgWJ5 LgGABlQdSIIvX0ULXYELyYIftnzGM0+PhxjnjSyGnhzI7ozmDgCAwkwb8Kd/4cgN4NnN Nm6MD2Ug/4d1XbF6w9wi7Q1XRlT31KmVie3CXQzjeDnjiVyHbrnhE/50THrTMqyXA+9D GO7svCPeWzbrXk2wmdmySWazKMYkgLu2c6ZIKChB/Olp9KbAy/VLAuggj2cWE/HD83AL Vemg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="1b/iYELC"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si18499032pgf.52.2018.11.22.08.06.35; Thu, 22 Nov 2018 08:06:52 -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=@nifty.com header.s=dec2015msa header.b="1b/iYELC"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391966AbeKVNw6 (ORCPT + 99 others); Thu, 22 Nov 2018 08:52:58 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:51151 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388435AbeKVNw5 (ORCPT ); Thu, 22 Nov 2018 08:52:57 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wAM3EZ3G004964; Thu, 22 Nov 2018 12:14:37 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wAM3EZ3G004964 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1542856477; bh=PhO+PXx9f29vDsYbmMZinUspy8MjVFdMSRysGapnTRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1b/iYELC4BWncKnU+Ljph1/TTJtoa1gAbiaSl5jSf7oZV1H5gs/iYS9dIcKExeI8X BoflL7F1YU49SqvGSfuhkhWfkVaqJsaQJJpB3lKyAbMc2krIu9Qmy2Y2jXKwLm/B7Q AmxlY65F0kMPbdxF74Moer+hvT1QUPln9XIy6ySDdrcK2tm9xXzQpeGexAQv9jvygJ AILw+BdUZylvLZYSS/2biUK9ThbuUH0wdPtJ3uApHwynhgmTTJIvidfiPPtJFNV33D O7I2zBdJndX4at8Eq8wsnjZ76KkcHiYfX7NKHvH10Wz1RSQvmtRy1Jci/cI644+yZJ OlNbb76M63JtQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Andrew Morton Cc: Luc Van Oostenryck , Nick Desaulniers , Kees Cook , Josh Triplett , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] build_bug.h: remove most of dummy BUILD_BUG_ON stubs for Sparse Date: Thu, 22 Nov 2018 12:14:22 +0900 Message-Id: <1542856462-18836-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542856462-18836-1-git-send-email-yamada.masahiro@socionext.com> References: <1542856462-18836-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 enabled only very recently), 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 positives, and noisier than it should be at that time. 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. 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 Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers --- Changes in v4: None Changes in v3: - Add Kees' Acked-by - Clarify log that BUILD_BUG_ON() *was* producing false positives - Keep the stub for BUILD_BUG_ON_ZERO() Changes in v2: - Fix a coding style error (two consecutive blank lines) include/linux/build_bug.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h index d415c64..faeec74 100644 --- a/include/linux/build_bug.h +++ b/include/linux/build_bug.h @@ -5,21 +5,8 @@ #include #ifdef __CHECKER__ -#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) -#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) #define BUILD_BUG_ON_ZERO(e) (0) -#define BUILD_BUG_ON_INVALID(e) (0) -#define BUILD_BUG_ON_MSG(cond, msg) (0) -#define BUILD_BUG_ON(condition) (0) -#define BUILD_BUG() (0) #else /* __CHECKER__ */ - -/* Force a compilation error if a constant expression is not a power of 2 */ -#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \ - BUILD_BUG_ON(((n) & ((n) - 1)) != 0) -#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ - BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) - /* * Force a compilation error if condition is true, but also produce a * result (of value 0 and type size_t), so the expression can be used @@ -27,6 +14,13 @@ * aren't permitted). */ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) +#endif /* __CHECKER__ */ + +/* Force a compilation error if a constant expression is not a power of 2 */ +#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \ + BUILD_BUG_ON(((n) & ((n) - 1)) != 0) +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ + BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) /* * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the @@ -64,6 +58,4 @@ */ #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") -#endif /* __CHECKER__ */ - #endif /* _LINUX_BUILD_BUG_H */ -- 2.7.4