{"id":813391,"url":"http://patchwork.ozlabs.org/api/patches/813391/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/1505303106-9780-6-git-send-email-yamada.masahiro@socionext.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/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":"<1505303106-9780-6-git-send-email-yamada.masahiro@socionext.com>","list_archive_url":null,"date":"2017-09-13T11:45:05","name":"[U-Boot,5/6] bug.h: sync BUILD_BUG stuff with Linux 4.13","commit_ref":null,"pull_url":null,"state":"deferred","archived":false,"hash":"9a2a46dc810087ea47584ab0af242c0af2eccbff","submitter":{"id":65882,"url":"http://patchwork.ozlabs.org/api/people/65882/?format=json","name":"Masahiro Yamada","email":"yamada.masahiro@socionext.com"},"delegate":{"id":38701,"url":"http://patchwork.ozlabs.org/api/users/38701/?format=json","username":"masahir0y","first_name":"Masahiro","last_name":"Yamada","email":"yamada.m@jp.panasonic.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/1505303106-9780-6-git-send-email-yamada.masahiro@socionext.com/mbox/","series":[{"id":2896,"url":"http://patchwork.ozlabs.org/api/series/2896/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=2896","date":"2017-09-13T11:45:01","name":"Sync and consolidate Linux-derived printk, BUILD_BUG, BUG, WARN, etc.","version":1,"mbox":"http://patchwork.ozlabs.org/series/2896/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/813391/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/813391/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=\"OhCFZgBP\"; dkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xsfzS50THz9sPk\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 21:47:32 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 77AF3C22484; Wed, 13 Sep 2017 11:46:09 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 88ED9C224D8;\n\tWed, 13 Sep 2017 11:45:42 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 9DB9BC22531; Wed, 13 Sep 2017 11:45:32 +0000 (UTC)","from conuserg-10.nifty.com (conuserg-10.nifty.com [210.131.2.77])\n\tby lists.denx.de (Postfix) with ESMTPS id 12E7FC220DF\n\tfor <u-boot@lists.denx.de>; Wed, 13 Sep 2017 11:45:31 +0000 (UTC)","from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp\n\t[153.142.97.92]) (authenticated)\n\tby conuserg-10.nifty.com with ESMTP id v8DBjE4s018351;\n\tWed, 13 Sep 2017 20:45:19 +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-10.nifty.com v8DBjE4s018351","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com;\n\ts=dec2015msa; t=1505303120;\n\tbh=0NFn0QwgQ6PUqeK4c0hfIAUzA2LIW7IFbh0x/jFxz0g=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OhCFZgBP9iDz1+Ds6NbuVN/xXMf1D0fX4PNqwkV0yW5dAOIYxDw1WgJlpcuZ/t5MN\n\tx0jxFcBi7YkojZv9I8UnD63tuWzGZ/b5rt061EABehQkffD3ECDwK3mQmxWArsljNk\n\t3fHsJaDOHnmsS0gRfmbdBWSFY78zlV76wMJ9rhpdMJm1eFV7v7mVdCt+2iB3KyprDP\n\tBnrbsdPbJPIGFNjk1dPa8nt74qAJqQcUakMEyzXH+jojCcFBlvDFP9oY2+PfScb1R8\n\t1OfI9Svqyw27BZfWt4qYN2DT0DYwr0H3GOdEn8USmLWpLYtbrF6d60LxR6yZDZ3HRe\n\tYnct2p4T1NPoA==","X-Nifty-SrcIP":"[153.142.97.92]","From":"Masahiro Yamada <yamada.masahiro@socionext.com>","To":"u-boot@lists.denx.de","Date":"Wed, 13 Sep 2017 20:45:05 +0900","Message-Id":"<1505303106-9780-6-git-send-email-yamada.masahiro@socionext.com>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1505303106-9780-1-git-send-email-yamada.masahiro@socionext.com>","References":"<1505303106-9780-1-git-send-email-yamada.masahiro@socionext.com>","Subject":"[U-Boot] [PATCH 5/6] 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 is related\nto platform code, so it makes 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\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 920e379..133544c 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 0000000..b7d22d6\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 020ad16..0ea6c8f 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","5/6"]}