From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031641AbdDTLFo (ORCPT ); Thu, 20 Apr 2017 07:05:44 -0400 Received: from terminus.zytor.com ([65.50.211.136]:57983 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031622AbdDTLFl (ORCPT ); Thu, 20 Apr 2017 07:05:41 -0400 Date: Thu, 20 Apr 2017 04:03:25 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: linux-kernel@vger.kernel.org, adrian.hunter@intel.com, wangnan0@huawei.com, tglx@linutronix.de, hpa@zytor.com, mingo@kernel.org, acme@redhat.com, dsahern@gmail.com, namhyung@kernel.org, jolsa@kernel.org Reply-To: namhyung@kernel.org, jolsa@kernel.org, dsahern@gmail.com, acme@redhat.com, mingo@kernel.org, hpa@zytor.com, wangnan0@huawei.com, tglx@linutronix.de, adrian.hunter@intel.com, linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] tools include: Adopt __same_type() and __must_be_array() from the kernel Git-Commit-ID: f6441aff8946f7fd6ab730d7eb9eba18a9ebeba4 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: f6441aff8946f7fd6ab730d7eb9eba18a9ebeba4 Gitweb: http://git.kernel.org/tip/f6441aff8946f7fd6ab730d7eb9eba18a9ebeba4 Author: Arnaldo Carvalho de Melo AuthorDate: Mon, 17 Apr 2017 11:25:00 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 19 Apr 2017 13:01:42 -0300 tools include: Adopt __same_type() and __must_be_array() from the kernel Will be used to adopt the more stringent version of ARRAY_SIZE(), the one in the kernel sources. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-d85dpvay1hoqscpezlntyd8x@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/linux/compiler-gcc.h | 3 +++ tools/include/linux/compiler.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/tools/include/linux/compiler-gcc.h b/tools/include/linux/compiler-gcc.h index 616935f..825d44f 100644 --- a/tools/include/linux/compiler-gcc.h +++ b/tools/include/linux/compiler-gcc.h @@ -16,3 +16,6 @@ #if GCC_VERSION >= 40300 # define __compiletime_error(message) __attribute__((error(message))) #endif /* GCC_VERSION >= 40300 */ + +/* &a[0] degrades to a pointer: a different type from an array */ +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index c9e65e8..23299d7 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -17,6 +17,11 @@ # define __always_inline inline __attribute__((always_inline)) #endif +/* Are two types/vars the same type (ignoring qualifiers)? */ +#ifndef __same_type +# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) +#endif + #ifdef __ANDROID__ /* * FIXME: Big hammer to get rid of tons of: