Re: [next:akpm 129/309] net/core/sock.c:274:36: error: initializerelement is not constant

From: Fengguang Wu
Date: Thu Aug 02 2012 - 11:02:19 EST


On Thu, Jul 26, 2012 at 10:06:41AM -0700, Tony Luck wrote:
> On Tue, Jul 24, 2012 at 10:10 PM, James Bottomley
> <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx> wrote:
> >> Here is the line in sock.i:
> >>
> >> struct static_key memalloc_socks = ((struct static_key) { .enabled =
> >> ((atomic_t) { (0) }) });
> >
> > The above line contains two compound literals. It also uses a designated
> > initializer to initialize the field enabled. A compound literal is not a
> > constant expression.
>
> Seeing the same thing on ia64 building next-20120726. Same fix works
> for me ... so I'll steal this whole changelog and attributes.

I got the same error for alpha, the same fix applies.
---
From: Mel Gorman <mgorman@xxxxxxx>
Subject: [PATCH] [ALPHA] Redefine ATOMIC_INIT and ATOMIC64_INIT to drop the casts

The following build error occurred during an alpha build:

net/core/sock.c:274:36: error: initializer element is not constant

Dave Anglin says:
> Here is the line in sock.i:
>
> struct static_key memalloc_socks = ((struct static_key) { .enabled =
> ((atomic_t) { (0) }) });

The above line contains two compound literals. It also uses a designated
initializer to initialize the field enabled. A compound literal is not a
constant expression.

The location of the above statement isn't fully clear, but if a compound
literal occurs outside the body of a function, the initializer list must
consist of constant expressions.

Reported-by: Fengguang Wu <fengguang.wu@xxxxxxxxx>
Signed-off-by: Mel Gorman <mgorman@xxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx>
---
arch/alpha/include/asm/atomic.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- linux.orig/arch/alpha/include/asm/atomic.h 2012-05-24 19:03:06.000000000 +0800
+++ linux/arch/alpha/include/asm/atomic.h 2012-08-02 23:01:02.243224220 +0800
@@ -14,8 +14,8 @@
*/


-#define ATOMIC_INIT(i) ( (atomic_t) { (i) } )
-#define ATOMIC64_INIT(i) ( (atomic64_t) { (i) } )
+#define ATOMIC_INIT(i) ( { (i) } )
+#define ATOMIC64_INIT(i) ( { (i) } )

#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic64_read(v) (*(volatile long *)&(v)->counter)
--
To unsubscribe from this list: send the line "unsubscribe linux-alpha" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html