{"id":814471,"url":"http://patchwork.ozlabs.org/api/1.2/patches/814471/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/1505538646-19191-7-git-send-email-yamada.masahiro@socionext.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.2/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1505538646-19191-7-git-send-email-yamada.masahiro@socionext.com>","list_archive_url":null,"date":"2017-09-16T05:10:44","name":"[U-Boot,v2,6/8] bug.h: sync BUILD_BUG stuff with Linux 4.13","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9a2a46dc810087ea47584ab0af242c0af2eccbff","submitter":{"id":65882,"url":"http://patchwork.ozlabs.org/api/1.2/people/65882/?format=json","name":"Masahiro Yamada","email":"yamada.masahiro@socionext.com"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/1.2/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/1505538646-19191-7-git-send-email-yamada.masahiro@socionext.com/mbox/","series":[{"id":3418,"url":"http://patchwork.ozlabs.org/api/1.2/series/3418/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=3418","date":"2017-09-16T05:10:45","name":"Sync and consolidate Linux-derived printk, BUILD_BUG, BUG, WARN, etc.","version":2,"mbox":"http://patchwork.ozlabs.org/series/3418/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/814471/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/814471/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=nifty.com header.i=@nifty.com\n\theader.b=\"UTlJOvw2\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xvL5n200nz9sRV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat, 16 Sep 2017 15:13:49 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid F2337C21F5B; Sat, 16 Sep 2017 05:12:29 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id D8512C21FA9;\n\tSat, 16 Sep 2017 05:11:23 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid B9FB0C21C8F; Sat, 16 Sep 2017 05:11:18 +0000 (UTC)","from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76])\n\tby lists.denx.de (Postfix) with ESMTPS id D306DC21D75\n\tfor <u-boot@lists.denx.de>; Sat, 16 Sep 2017 05:11:16 +0000 (UTC)","from grover.sesame (FL1-122-131-185-176.osk.mesh.ad.jp\n\t[122.131.185.176]) (authenticated)\n\tby conuserg-09.nifty.com with ESMTP id v8G5Asoq028761;\n\tSat, 16 Sep 2017 14:10:59 +0900"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=0.0 required=5.0 tests=T_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Filter":"OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v8G5Asoq028761","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com;\n\ts=dec2015msa; t=1505538659;\n\tbh=Z8tpfk4MDXbT++gKREjTetQMSvWDgZ1/QaDPyQQRTbw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=UTlJOvw2mohfSVPFvT1vNQutwHAM41wbmdOkyS2lGN2D/CgOROaGeSxzUPnvtxdZ7\n\tncs8dZ1q+qhtj7EnbBukhrNAdH/wGkiK4IiFyyUHv+qfjrrxERpjT4LNGBBFtmZrGo\n\tD7+IHEToai9Z5q5bAdEFOKqPZ1oVsxdMNFYATS6Zo8E+pDuWz2DJZvneK6attSWloF\n\tmC7dq6slWcW+wAQkxdgqpKrWXg/gQ2QsU7Xw8FbgZy51GT/OEqJKpj2vXk21zBZ+MU\n\tl2npcp6QYK3onxPQlnFjTQ+EU68LTMDL51zdXssiBGPkAFxBUNdIPFgmNqNoKOSWuA\n\tTaSZC1wNYQwfg==","X-Nifty-SrcIP":"[122.131.185.176]","From":"Masahiro Yamada <yamada.masahiro@socionext.com>","To":"u-boot@lists.denx.de","Date":"Sat, 16 Sep 2017 14:10:44 +0900","Message-Id":"<1505538646-19191-7-git-send-email-yamada.masahiro@socionext.com>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1505538646-19191-1-git-send-email-yamada.masahiro@socionext.com>","References":"<1505538646-19191-1-git-send-email-yamada.masahiro@socionext.com>","Subject":"[U-Boot] [PATCH v2 6/8] bug.h: sync BUILD_BUG stuff with Linux 4.13","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"},"content":"As commit 84b8bf6d5d2a (\"bug.h: move BUILD_BUG_* defines to\ninclude/linux/bug.h\") noted, include/linux/bug.h was locally\nmodified for U-Boot because the name conflict of error() caused\nbuild errors at that time.\n\nNow error() is gone, so we can fully sync BUILD_BUG* with Linux.\nThese macros are just compile-time utilities.  Nothing depends on\nplatform code, so it should make sense to simply copy Linux's ones.\n\nPlease note Linux split BUILD_BUG stuff out into <linux/build_bug.h>\nby commit bc6245e5efd7.  Let's follow it.\n\nSigned-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>\n---\n\nChanges in v2: None\n\n include/linux/bug.h       | 51 +---------------------------\n include/linux/build_bug.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++\n include/linux/compiler.h  |  6 +++-\n 3 files changed, 90 insertions(+), 51 deletions(-)\n create mode 100644 include/linux/build_bug.h","diff":"diff --git a/include/linux/bug.h b/include/linux/bug.h\nindex 920e3796c38d..133544ca46f0 100644\n--- a/include/linux/bug.h\n+++ b/include/linux/bug.h\n@@ -1,55 +1,6 @@\n #ifndef _LINUX_BUG_H\n #define _LINUX_BUG_H\n \n-#include <linux/compiler.h>\n-\n-#ifdef __CHECKER__\n-#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)\n-#define BUILD_BUG_ON_ZERO(e) (0)\n-#define BUILD_BUG_ON_NULL(e) ((void*)0)\n-#define BUILD_BUG_ON_INVALID(e) (0)\n-#define BUILD_BUG_ON(condition) (0)\n-#define BUILD_BUG() (0)\n-#else /* __CHECKER__ */\n-\n-/* Force a compilation error if a constant expression is not a power of 2 */\n-#define BUILD_BUG_ON_NOT_POWER_OF_2(n)\t\t\t\\\n-\tBUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))\n-\n-/* Force a compilation error if condition is true, but also produce a\n-   result (of value 0 and type size_t), so the expression can be used\n-   e.g. in a structure initializer (or where-ever else comma expressions\n-   aren't permitted). */\n-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))\n-#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))\n-\n-/*\n- * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the\n- * expression but avoids the generation of any code, even if that expression\n- * has side-effects.\n- */\n-#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))\n-\n-/**\n- * BUILD_BUG_ON - break compile if a condition is true.\n- * @condition: the condition which the compiler should know is false.\n- *\n- * If you have some code which relies on certain constants being equal, or\n- * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to\n- * detect if someone changes it.\n- *\n- * The implementation uses gcc's reluctance to create a negative array, but gcc\n- * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to\n- * inline functions).  Luckily, in 4.3 they added the \"error\" function\n- * attribute just for this type of case.  Thus, we use a negative sized array\n- * (should always create an error on gcc versions older than 4.4) and then call\n- * an undefined function with the error attribute (should always create an\n- * error on gcc 4.3 and later).  If for some reason, neither creates a\n- * compile-time error, we'll still have a link-time error, which is harder to\n- * track down.\n- */\n-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))\n-\n-#endif\t/* __CHECKER__ */\n+#include <linux/build_bug.h>\n \n #endif\t/* _LINUX_BUG_H */\ndiff --git a/include/linux/build_bug.h b/include/linux/build_bug.h\nnew file mode 100644\nindex 000000000000..b7d22d60008a\n--- /dev/null\n+++ b/include/linux/build_bug.h\n@@ -0,0 +1,84 @@\n+#ifndef _LINUX_BUILD_BUG_H\n+#define _LINUX_BUILD_BUG_H\n+\n+#include <linux/compiler.h>\n+\n+#ifdef __CHECKER__\n+#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)\n+#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)\n+#define BUILD_BUG_ON_ZERO(e) (0)\n+#define BUILD_BUG_ON_NULL(e) ((void *)0)\n+#define BUILD_BUG_ON_INVALID(e) (0)\n+#define BUILD_BUG_ON_MSG(cond, msg) (0)\n+#define BUILD_BUG_ON(condition) (0)\n+#define BUILD_BUG() (0)\n+#else /* __CHECKER__ */\n+\n+/* Force a compilation error if a constant expression is not a power of 2 */\n+#define __BUILD_BUG_ON_NOT_POWER_OF_2(n)\t\\\n+\tBUILD_BUG_ON(((n) & ((n) - 1)) != 0)\n+#define BUILD_BUG_ON_NOT_POWER_OF_2(n)\t\t\t\\\n+\tBUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))\n+\n+/*\n+ * Force a compilation error if condition is true, but also produce a\n+ * result (of value 0 and type size_t), so the expression can be used\n+ * e.g. in a structure initializer (or where-ever else comma expressions\n+ * aren't permitted).\n+ */\n+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))\n+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:(-!!(e)); }))\n+\n+/*\n+ * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the\n+ * expression but avoids the generation of any code, even if that expression\n+ * has side-effects.\n+ */\n+#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))\n+\n+/**\n+ * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied\n+ *\t\t      error message.\n+ * @condition: the condition which the compiler should know is false.\n+ *\n+ * See BUILD_BUG_ON for description.\n+ */\n+#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)\n+\n+/**\n+ * BUILD_BUG_ON - break compile if a condition is true.\n+ * @condition: the condition which the compiler should know is false.\n+ *\n+ * If you have some code which relies on certain constants being equal, or\n+ * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to\n+ * detect if someone changes it.\n+ *\n+ * The implementation uses gcc's reluctance to create a negative array, but gcc\n+ * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to\n+ * inline functions).  Luckily, in 4.3 they added the \"error\" function\n+ * attribute just for this type of case.  Thus, we use a negative sized array\n+ * (should always create an error on gcc versions older than 4.4) and then call\n+ * an undefined function with the error attribute (should always create an\n+ * error on gcc 4.3 and later).  If for some reason, neither creates a\n+ * compile-time error, we'll still have a link-time error, which is harder to\n+ * track down.\n+ */\n+#ifndef __OPTIMIZE__\n+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))\n+#else\n+#define BUILD_BUG_ON(condition) \\\n+\tBUILD_BUG_ON_MSG(condition, \"BUILD_BUG_ON failed: \" #condition)\n+#endif\n+\n+/**\n+ * BUILD_BUG - break compile if used.\n+ *\n+ * If you have some code that you expect the compiler to eliminate at\n+ * build time, you should use BUILD_BUG to detect if it is\n+ * unexpectedly used.\n+ */\n+#define BUILD_BUG() BUILD_BUG_ON_MSG(1, \"BUILD_BUG failed\")\n+\n+#endif\t/* __CHECKER__ */\n+\n+#endif\t/* _LINUX_BUILD_BUG_H */\ndiff --git a/include/linux/compiler.h b/include/linux/compiler.h\nindex 020ad16a0493..0ea6c8fccaab 100644\n--- a/include/linux/compiler.h\n+++ b/include/linux/compiler.h\n@@ -476,7 +476,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s\n # define __compiletime_error_fallback(condition) do { } while (0)\n #endif\n \n-#define __compiletime_assert(condition, msg, prefix, suffix)\t\t\\\n+#ifdef __OPTIMIZE__\n+# define __compiletime_assert(condition, msg, prefix, suffix)\t\t\\\n \tdo {\t\t\t\t\t\t\t\t\\\n \t\tbool __cond = !(condition);\t\t\t\t\\\n \t\textern void prefix ## suffix(void) __compiletime_error(msg); \\\n@@ -484,6 +485,9 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s\n \t\t\tprefix ## suffix();\t\t\t\t\\\n \t\t__compiletime_error_fallback(__cond);\t\t\t\\\n \t} while (0)\n+#else\n+# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)\n+#endif\n \n #define _compiletime_assert(condition, msg, prefix, suffix) \\\n \t__compiletime_assert(condition, msg, prefix, suffix)\n","prefixes":["U-Boot","v2","6/8"]}