Skip to contentSkip to conversation

net: Reorder initialization in ip_route_output to fix gcc warning

PATCH In review Roland Dreier 2 participants 4 messages Jun 11, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Reorder initialization in ip_route_output to fix gcc warning

From: Roland Dreier <[email protected]>

If I build with W=1, for every file that includes <net/route.h>, I get the warning

include/net/route.h: In function 'ip_route_output':
include/net/route.h:135:3: warning: initialized field overwritten [-Woverride-init] include/net/route.h:135:3: warning: (near initialization for 'fl4') [-Woverride-init]

(This is with "gcc (Debian 4.6.3-1) 4.6.3")

A fix seems pretty trivial: move the initialization of .flowi4_tos earlier. As far as I can tell, this has no effect on code generation.

---
 include/net/route.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/route.h +1 -1
index ed2b78e..9870546 100644
@@ -130,9 +130,9 @@ static inline struct rtable *ip_route_output(struct net *net, __be32 daddr,
 {
 	struct flowi4 fl4 = {
 		.flowi4_oif = oif,
+		.flowi4_tos = tos,
 		.daddr = daddr,
 		.saddr = saddr,
-		.flowi4_tos = tos,
 	};
 	return ip_route_output_key(net, &fl4);
 }
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw

From: Roland Dreier <[email protected]>
Date: Sun, 10 Jun 2012 23:05:24 -0700

Quoted 8 lines

From: Roland Dreier <[email protected]>

If I build with W=1, for every file that includes <net/route.h>, I get the warning

include/net/route.h: In function 'ip_route_output':
include/net/route.h:135:3: warning: initialized field overwritten [-Woverride-init] include/net/route.h:135:3: warning: (near initialization for 'fl4') [-Woverride-init]

Quoted 6 lines

(This is with "gcc (Debian 4.6.3-1) 4.6.3")

A fix seems pretty trivial: move the initialization of .flowi4_tos earlier. As far as I can tell, this has no effect on code generation.

I can't figure out what it is actually warning about, can you?

#2 lore raw
Quoted 1 line

I can't figure out what it is actually warning about, can you?

I think gcc thinks it already initialized the __fl_common struct once when it hits the .flowi4_oif initializer (which expands to __fl_common.flowic_oif), and then having the .daddr / .saddr initializers makes it thinks its done with that structure.

So it thinks it's initializing __fl_common.flowic_tos to 0, and then the .flowi4_tos initializer comes along as a surprise.

Hmm, looks like http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52880
which is fixed after gcc 4.7.0. I think it's probably worth working around this gcc issue, since this makes W=1 way noisier in my build.

- R.

maintainer
#3 lore raw

From: Roland Dreier <[email protected]>
Date: Mon, 11 Jun 2012 00:00:51 -0700

Quoted 7 lines
Quoted 1 line

I can't figure out what it is actually warning about, can you?

I think gcc thinks it already initialized the __fl_common struct once when it hits the .flowi4_oif initializer (which expands to __fl_common.flowic_oif), and then having the .daddr / .saddr initializers makes it thinks its done with that structure.

Quoted 7 lines

So it thinks it's initializing __fl_common.flowic_tos to 0, and then the .flowi4_tos initializer comes along as a surprise.

Hmm, looks like http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52880
which is fixed after gcc 4.7.0. I think it's probably worth working around this gcc issue, since this makes W=1 way noisier in my build.

I suspected it was a compiler bug :-)

Anyways, agreed, applied.