Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4578679ybb; Tue, 14 Apr 2020 09:59:54 -0700 (PDT) X-Google-Smtp-Source: APiQypLgbrbMsmETrGNS33mm6lnfWJAkhHkgEU8Ozn8ic5iMP00TAhjsYmR8f5lQKJZIv6Rzb68e X-Received: by 2002:aa7:cc81:: with SMTP id p1mr22001182edt.385.1586883594262; Tue, 14 Apr 2020 09:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586883594; cv=none; d=google.com; s=arc-20160816; b=kcF/NWfWvtt/uW2YREifq7HYS0C82Yqi8mC4QbbZu/gEhuIyixWluOhFCcEhEmOGBr qUtCJTmAqjUZDjFTa8tF+efCrK74Jlf0VBPRqjR5yJQyVRQuXYUub3EGr7SUAB+1KW2U LW/1BU0n58SLXAVulJ/rk1ivf7yGQ3xsnoZo187RglOZ737BDZSvVF3t1jzMYzj1mqA5 cv1o3cZOZv04fH2pIcbS69eRHrYerm5oZVpIGlbT/NQdnXcrGUD1I5ugZNmwYBm5Uux4 K5jkIBFdnrz+tBK+nzFGMCpgFxmvVP4ztmzxqTyoqUn6AfUbzhfu+IGH+zvvBtSyf31A 0EEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UY1XvCe8OdrT5akE+OXdiS2g5ZWxjrEQE/Z0Wdxton8=; b=T6iPNO8jXgNyd3PChDScJDZQ8fpEEOk9o11fip/VIlOAYjHojUjVAZY3bAKrKlHQ9I 60xTgBAyuBGAVDqNRF2vB1gDHhsSkxW1hSwwSMslatvhXzmWGUWE/1YGILGJgJBXNMHQ 7fjp39E5x2qFoTui0moDbNDNt2/NXeB1HNfRZgIOw6qHT5SM1HQOMmxvsdF4g+57lLIy O+4BbErqPRwJfA+6WcvjgIL35/7qSxOYHohce/EuW18HqngI8B8+bZ0UozDgUXTZKM+H 7ew0Vutfnv5AK/8zYsj4Kr77hgrD262qb9/UJSOrZXTxx/7p2EUsmDEA1GnQF80ZioCf kAVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="QTf/tWOB"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si4198301ejh.494.2020.04.14.09.59.30; Tue, 14 Apr 2020 09:59:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="QTf/tWOB"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502013AbgDNQu0 (ORCPT + 99 others); Tue, 14 Apr 2020 12:50:26 -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