diff mbox

sparse and anonymous unions

Message ID CA+55aFzs_O780hEowt9vg69-Kxfwzn5j1eL2F2Tzw4C56koeRg@mail.gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Linus Torvalds March 31, 2014, 5:17 p.m. UTC
On Mon, Mar 31, 2014 at 12:51 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>
> Here is a simple test case for this problem:
>
> ====== anon-union.c ======
> struct s {
>         union {
>                 int val;
>         };
> };
>
> static struct s foo = { .val = 5, };

Ok, this fixes the warning, but we seem to still mess up the actual
initializer. It looks like some later phase gets the offset wrong, so
when we lay things out in memory, we'll put things at offset zero
(which is right for your test-case, but not if there was something
before that anonymous union).

Regardless, that only matters for real code generation, not for using
sparse as a semantic checker, so this patch is correct and is an
improvement.

Chris, mind applying this one too? It removes more lines than it adds
while fixing things, by removing the helper function that isn't good
at anoymous unions, and using another one that does this all right..

                  Linus
evaluate.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

Comments

Christopher Li April 3, 2014, 7:15 p.m. UTC | #1
On Mon, Mar 31, 2014 at 10:17 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> Chris, mind applying this one too? It removes more lines than it adds
> while fixing things, by removing the helper function that isn't good
> at anoymous unions, and using another one that does this all right..

The patch is applied. I add the signed off for you too, hope you don't mind.

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

diff --git a/evaluate.c b/evaluate.c
index 8a53b3e884e0..5adfc1e3ff26 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2171,17 +2171,6 @@  static int evaluate_arguments(struct symbol *f, struct symbol *fn, struct expres
 	return 1;
 }
 
-static struct symbol *find_struct_ident(struct symbol *ctype, struct ident *ident)
-{
-	struct symbol *sym;
-
-	FOR_EACH_PTR(ctype->symbol_list, sym) {
-		if (sym->ident == ident)
-			return sym;
-	} END_FOR_EACH_PTR(sym);
-	return NULL;
-}
-
 static void convert_index(struct expression *e)
 {
 	struct expression *child = e->idx_expression;
@@ -2290,11 +2279,12 @@  static struct expression *check_designators(struct expression *e,
 			}
 			e = e->idx_expression;
 		} else if (e->type == EXPR_IDENTIFIER) {
+			int offset = 0;
 			if (ctype->type != SYM_STRUCT && ctype->type != SYM_UNION) {
 				err = "field name not in struct or union";
 				break;
 			}
-			ctype = find_struct_ident(ctype, e->expr_ident);
+			ctype = find_identifier(e->expr_ident, ctype->symbol_list, &offset);
 			if (!ctype) {
 				err = "unknown field name in";
 				break;