From patchwork Mon Mar 31 17:17:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 3916821 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E5A589F370 for ; Mon, 31 Mar 2014 17:18:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02DD920380 for ; Mon, 31 Mar 2014 17:18:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A899201E7 for ; Mon, 31 Mar 2014 17:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753044AbaCaRSB (ORCPT ); Mon, 31 Mar 2014 13:18:01 -0400 Received: from mail-ve0-f172.google.com ([209.85.128.172]:44972 "EHLO mail-ve0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752640AbaCaRSA (ORCPT ); Mon, 31 Mar 2014 13:18:00 -0400 Received: by mail-ve0-f172.google.com with SMTP id jx11so8362049veb.17 for ; Mon, 31 Mar 2014 10:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=vn3A5D9GwzBMAEBdLoPMUTEEyQhr7dbQCulHau8eJQw=; b=IhEs8ypbokfCvVOEw7jzFy6USjbR1BM6ghQZKNjvmzgfJvlyqpE7p95Gi6yKPiTlOz QMNI8JTBCYdKaFU3GcCB0gJNZgE/lnnqZoa3H23lTr9H2mk3brwn4gZWxMuHG/ymd1dt pK9pBCAllH78b0mpJbUl/wigOuhFQhpXZ7vvwlX12C5GoMCj5eEq6n9TfQPo0u3k8wGX VsyTl3W8bJ9OIVD7Ddb0wJ321xr7JXQvSaOO8xGIumBuZ5lDq64egasafzNbV1dLigTZ IbnhRUvljf5D3auWZIbSFblyeqR0xCAVOqG1dA5vA4RKd7MxDQmS93WLAHekJ53SzP+y XK1w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=vn3A5D9GwzBMAEBdLoPMUTEEyQhr7dbQCulHau8eJQw=; b=UqvAXh8wSKAbnk+t5hP7lZV1bB3h2HcxD2n3MHNqhk7NXuTjUf1kFD2SDTqC4Fj3mp i1B0q1Fz5D4TcV6segLtwvgzW4o8dVIsbdLzqWfY4xQoZcLZ0WbzHmQsaWgGk29gzEzC GmRTOtHLxS6xt45awYv0UybLqjsPeWMtVrIxQ= MIME-Version: 1.0 X-Received: by 10.58.238.35 with SMTP id vh3mr23877666vec.16.1396286279643; Mon, 31 Mar 2014 10:17:59 -0700 (PDT) Received: by 10.220.13.2 with HTTP; Mon, 31 Mar 2014 10:17:59 -0700 (PDT) In-Reply-To: <53391E67.2000306@xs4all.nl> References: <53242AC7.9080301@xs4all.nl> <53391E67.2000306@xs4all.nl> Date: Mon, 31 Mar 2014 10:17:59 -0700 X-Google-Sender-Auth: ew7cx0p1EKvMb2Y4Gg27quOXHuE Message-ID: Subject: Re: sparse and anonymous unions From: Linus Torvalds To: Hans Verkuil , Chris Li Cc: Sparse Mailing-list , Linux Media Mailing List Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Mar 31, 2014 at 12:51 AM, Hans Verkuil 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(-) 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;