diff mbox

Designated initializers for fields in anonymous structs and unions

Message ID CA+55aFxptOTqCR9b0o8sEKwzyQOU0rfKTptRY5s=j5R_X=UdUg@mail.gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Linus Torvalds July 31, 2014, 6:39 p.m. UTC
On Thu, Jul 31, 2014 at 11:10 AM,  <josh@joshtriplett.org> wrote:
> GCC 4.6 and newer support initializing designated initializers for fields in
> anonymous structs and unions.  However, sparse does not.

I sent patches for this back in April, based on a report from Hans
Verkuil. My patches fixed the parsing part, but had a (known) bug with
getting the offsets right, so your test-case actually retulrs in

  t.c:23:6: warning: Initializer entry defined twice
  t.c:24:6:   also defined here

because the offset calculation for "b" was wrong, and as a result
sparse thinks "a" and "b" overlap. John Keeping had a patch that tried
to fix that too.

I think they are all in

   https://github.com/johnkeeping/sparse/

but not in the "official" sparse tree, which hasn't seen any work
since January afaik. Maybe there are other trees than John's..

I'm attaching my set of sparse patches from early April in case
anybody wants to look at them. No guarantees, and as mentioned there's
t least an offset bug, but they should be an improvement, at least.

                    Linus

Comments

Linus Torvalds July 31, 2014, 6:50 p.m. UTC | #1
On Thu, Jul 31, 2014 at 11:39 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> but not in the "official" sparse tree, which hasn't seen any work
> since January afaik.

Ugh, I looked at the old "sparse/sparse.git" tree (and badly at that,
it stopped updating in April, not January). It's
"sparse/chrisl/sparse.git" these days. No wonder I didn't see any
recent work.

The sparse.wiki.kernel.org main page is the first google hit for
"sparse git tree" and mentions that old git repo, not Chris' new one.

That leaves just my last patch ("Fix scoping of extern") as being not
in the sparse tree, and that's irrelevant for the union initializer
thing.

Chris, any particular reason why the url changed?

            Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Josh Triplett July 31, 2014, 8:55 p.m. UTC | #2
On Thu, Jul 31, 2014 at 11:50:30AM -0700, Linus Torvalds wrote:
> On Thu, Jul 31, 2014 at 11:39 AM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > but not in the "official" sparse tree, which hasn't seen any work
> > since January afaik.
> 
> Ugh, I looked at the old "sparse/sparse.git" tree (and badly at that,
> it stopped updating in April, not January). It's
> "sparse/chrisl/sparse.git" these days. No wonder I didn't see any
> recent work.
> 
> The sparse.wiki.kernel.org main page is the first google hit for
> "sparse git tree" and mentions that old git repo, not Chris' new one.
> 
> That leaves just my last patch ("Fix scoping of extern") as being not
> in the sparse tree, and that's irrelevant for the union initializer
> thing.
> 
> Chris, any particular reason why the url changed?

I think Chris has been trying to use chrisl as a staging tree to let
things cook a while, and then moving them over to the sparse tree.
However, I think it'd make more sense to do that as a branch rather than
a separate repo.

- Josh Triplett
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Christopher Li Aug. 2, 2014, 8:27 a.m. UTC | #3
On Thu, Jul 31, 2014 at 11:50 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> That leaves just my last patch ("Fix scoping of extern") as being not
> in the sparse tree, and that's irrelevant for the union initializer
> thing.

I just apply that without the "FIXME" part. That two lines are from an incorrect
fix for the external inline bug. I just remove it for now. Currently
sparse will fail
at the external inline test. I will fix that in a separate patch.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

From c011597ff67765da5dacb472ddbd69dc4b51416d Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Tue, 1 Apr 2014 10:20:34 -0700
Subject: [PATCH 4/4] Fix scoping of extern symbols in block scope

We'd only match them with other symbols marked 'extern', but really, we
should match them with any top-level non-static symbol.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 symbol.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/symbol.c b/symbol.c
index 4b91abd8021e..c5e4784734a8 100644
--- a/symbol.c
+++ b/symbol.c
@@ -576,11 +576,15 @@  void check_declaration(struct symbol *sym)
 			sym->same_symbol = next;
 			return;
 		}
-		if (sym->ctype.modifiers & next->ctype.modifiers & MOD_EXTERN) {
-			if ((sym->ctype.modifiers ^ next->ctype.modifiers) & MOD_INLINE)
-				continue;
-			sym->same_symbol = next;
-			return;
+		/* Extern in block level matches a TOPLEVEL non-static symbol */
+		if (sym->ctype.modifiers & MOD_EXTERN) {
+			if ((next->ctype.modifiers & (MOD_TOPLEVEL|MOD_STATIC)) == MOD_TOPLEVEL) {
+				/* FIXME? Differs in 'inline' only? Why does that matter? */
+				if ((sym->ctype.modifiers ^ next->ctype.modifiers) & MOD_INLINE)
+					continue;
+				sym->same_symbol = next;
+				return;
+			}
 		}
 
 		if (!Wshadow || warned)
-- 
2.0.1.427.gc47372d