From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA25EC3815B for ; Tue, 14 Apr 2020 16:50:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5971206E9 for ; Tue, 14 Apr 2020 16:50:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586883030; bh=8M5iDu5PwoDE1Dny/0OctQ7rhm+19W6g5gJF6xGFJqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=u00r5O7sRnSIXF3qRxNRdLbD/fzD6fDSq8+v1D0c8dTJFItwL0Po0ZQerx9miUzIT a00h2q9F6ywmF4SQyG9ekvX883gVdzvLwxd/S5lJsBwP/ZCw8yesrxoTMdqFcksmUt kPD9sMrPsbrPsMrMd1EHf14uYr/8mPQg+FeQ90DI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502036AbgDNQu3 (ORCPT ); Tue, 14 Apr 2020 12:50:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:56176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2501927AbgDNQtp (ORCPT ); Tue, 14 Apr 2020 12:49:45 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8046D2074D; Tue, 14 Apr 2020 16:49:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586882984; bh=8M5iDu5PwoDE1Dny/0OctQ7rhm+19W6g5gJF6xGFJqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTf/tWOBtQQDXe3of19U7HIJG7EuA3IyNKB/9aZnHzFqpqXtNpr5UUbp4g4ke2XZG V6yRV0s6k5p2yvZbwAGuQwYbyj3zuniP8Xycc4a9N6hFrBlE/nqo3LWMZOPY6FrwXw QrwJB2vSTjL38fw3kq70zs24l98sK3eelzlHaFuM= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter Subject: [PATCH 14/15] tools headers: Adopt verbatim copy of compiletime_assert() from kernel sources Date: Tue, 14 Apr 2020 13:48:53 -0300 Message-Id: <20200414164854.26026-15-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200414164854.26026-1-acme@kernel.org> References: <20200414164854.26026-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo Will be needed when syncing the linux/bits.h header, in the next cset. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/linux/compiler.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 1827c2f973f9..180f7714a5f1 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -10,6 +10,32 @@ # define __compiletime_error(message) #endif +#ifdef __OPTIMIZE__ +# define __compiletime_assert(condition, msg, prefix, suffix) \ + do { \ + extern void prefix ## suffix(void) __compiletime_error(msg); \ + if (!(condition)) \ + prefix ## suffix(); \ + } while (0) +#else +# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) +#endif + +#define _compiletime_assert(condition, msg, prefix, suffix) \ + __compiletime_assert(condition, msg, prefix, suffix) + +/** + * compiletime_assert - break build and emit msg if condition is false + * @condition: a compile-time constant condition to check + * @msg: a message to emit if condition is false + * + * In tradition of POSIX assert, this macro will break the build if the + * supplied condition is *false*, emitting the supplied error message if the + * compiler has support to do so. + */ +#define compiletime_assert(condition, msg) \ + _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) + /* Optimization barrier */ /* The "volatile" is due to gcc bugs */ #define barrier() __asm__ __volatile__("": : :"memory") -- 2.21.1