public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Jan Engelhardt <jengelh@linux01.gwdg.de>
Cc: lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andi Kleen <ak@suse.de>
Subject: Re: [PATCH] Use more gcc extensions in the Linux headers
Date: Sun, 11 Mar 2007 13:50:37 +1100	[thread overview]
Message-ID: <1173581437.32234.168.camel@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.61.0703100156490.8799@yvahk01.tjqt.qr>

On Sat, 2007-03-10 at 02:04 +0100, Jan Engelhardt wrote:
> Getting back at the macro, how would you like to have it merged?

Well, this is what I sent to Linus and Andrew (many thanks to those who
made appropriately whimsical *or* useful comments):

diff -r 1ccdf46b0f41 include/linux/compiler-gcc.h
--- a/include/linux/compiler-gcc.h	Sat Mar 10 09:55:29 2007 +1100
+++ b/include/linux/compiler-gcc.h	Sat Mar 10 11:06:35 2007 +1100
@@ -22,6 +22,9 @@
     __asm__ ("" : "=r"(__ptr) : "0"(ptr));		\
     (typeof(ptr)) (__ptr + (off)); })
 
+/* &a[0] degrades to a pointer: a different type from an array */
+#define __must_be_array(a) \
+  BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
 
 #define inline		inline		__attribute__((always_inline))
 #define __inline__	__inline__	__attribute__((always_inline))
diff -r 1ccdf46b0f41 include/linux/compiler-intel.h
--- a/include/linux/compiler-intel.h	Sat Mar 10 09:55:29 2007 +1100
+++ b/include/linux/compiler-intel.h	Sat Mar 10 11:06:25 2007 +1100
@@ -21,4 +21,7 @@
      __ptr = (unsigned long) (ptr);				\
     (typeof(ptr)) (__ptr + (off)); })
 
+/* Intel ECC compiler doesn't support __builtin_types_compatible_p() */
+#define __must_be_array(a) 0
+
 #endif
diff -r 1ccdf46b0f41 include/linux/kernel.h
--- a/include/linux/kernel.h	Sat Mar 10 09:55:29 2007 +1100
+++ b/include/linux/kernel.h	Sat Mar 10 11:06:16 2007 +1100
@@ -35,7 +35,8 @@ extern const char linux_proc_banner[];
 #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
 #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))



  reply	other threads:[~2007-03-11  2:51 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-09  5:56 [PATCH] Use more gcc extensions in the Linux headers Rusty Russell
2007-03-09  6:22 ` Stephen Rothwell
2007-03-09  6:35 ` Linus Torvalds
2007-03-09  6:50 ` Andrey Panin
2007-03-09  7:53   ` Christoph Hellwig
2007-03-09  9:02     ` Andrey Panin
2007-03-09  9:05       ` Christoph Hellwig
2007-03-09 17:47         ` Linus Torvalds
2007-03-10 20:36           ` Trent Piepho
2007-03-09  7:52 ` Christoph Hellwig
2007-03-09  8:35   ` Jarek Poplawski
2007-03-09 11:27 ` Theodore Ts'o
2007-03-09 16:52 ` Andi Kleen
2007-03-09 22:57 ` Rusty Russell
2007-03-09 23:02   ` Randy Dunlap
2007-03-09 23:09   ` Robert P. J. Day
2007-03-09 23:12   ` Roland Dreier
2007-03-10  1:04   ` Jan Engelhardt
2007-03-11  2:50     ` Rusty Russell [this message]
2007-03-11  2:58       ` Jan Engelhardt
2007-03-11  3:19         ` Rusty Russell
2007-03-11 21:40       ` Valdis.Kletnieks
2007-03-10  4:03   ` Valdis.Kletnieks
2007-03-10  4:24     ` Randy Dunlap
2007-03-11 15:56       ` Valdis.Kletnieks
2007-03-10  5:19     ` Nigel Cunningham
2007-03-10 14:01       ` Jan Engelhardt
2007-03-10 15:18         ` Andreas Schwab
2007-03-10 16:53           ` Jan Engelhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1173581437.32234.168.camel@localhost.localdomain \
    --to=rusty@rustcorp.com.au \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=jengelh@linux01.gwdg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox