From patchwork Tue Feb 4 16:51:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 11364981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E12851395 for ; Tue, 4 Feb 2020 16:51:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF50C20730 for ; Tue, 4 Feb 2020 16:51:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P0XSAo7w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727307AbgBDQvq (ORCPT ); Tue, 4 Feb 2020 11:51:46 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:27067 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727310AbgBDQvq (ORCPT ); Tue, 4 Feb 2020 11:51:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580835105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=NAB4ts7Ahaob6uDSRvzMSPRXPcbM4FmW9IGDGSdyoSA=; b=P0XSAo7w4cKyeAwC7bgoq/jhzdyi+BxKNajpQn3JpjcKOa/piwJqGM+V35rlghXdSWAhGj 1yPM8uTXHZmDDQLaJytmXSEKAo7RfMD5L9R70ob8wfKgNPjq2sbvqXvOJ85IXhmcz8L/yJ FYwUPl2pM0paz+KIBEG31AvIMjtZnNU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-389-1-679skLPeKMoaDiqHxZwQ-1; Tue, 04 Feb 2020 11:51:41 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58009190B2A1; Tue, 4 Feb 2020 16:51:40 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.70]) by smtp.corp.redhat.com (Postfix) with SMTP id 81F9A19C69; Tue, 4 Feb 2020 16:51:39 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 4 Feb 2020 17:51:40 +0100 (CET) Date: Tue, 4 Feb 2020 17:51:38 +0100 From: Oleg Nesterov To: Luc Van Oostenryck Cc: Alexey Gladkov , linux-sparse@vger.kernel.org Subject: [PATCH 1/4] dissect: don't report anonymous members in initializers Message-ID: <20200204165138.GA24340@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200204165119.GA24330@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 1-679skLPeKMoaDiqHxZwQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Change report_member() to not call ->r_member(mem) if !mem->ident. This can only happen in initializer, the output gives no useful info but looks like a bug. Test-case: struct { union { int x; }; } var = { {} }; before this patch: 1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var 6:9 s -w- :var.? union after: 1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var We also need to change no_member() to ensure we still report the bad initializers, this will be cleanuped later. Signed-off-by: Oleg Nesterov --- dissect.c | 4 ++-- test-dissect.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dissect.c b/dissect.c index 14d57bf..ff3a313 100644 --- a/dissect.c +++ b/dissect.c @@ -125,7 +125,7 @@ static inline struct symbol *no_member(struct ident *name) }; sym.ctype.base_type = &bad_ctype; - sym.ident = name; + sym.ident = name ?: built_in_ident("?"); return &sym; } @@ -135,7 +135,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos, { struct symbol *ret = mem->ctype.base_type; - if (reporter->r_member) + if (mem->ident && reporter->r_member) reporter->r_member(fix_mode(ret, mode), pos, type, mem); return ret; diff --git a/test-dissect.c b/test-dissect.c index 266148b..af1212a 100644 --- a/test-dissect.c +++ b/test-dissect.c @@ -56,14 +56,13 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym) static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem) { - struct ident *ni, *si, *mi; + struct ident *si, *mi; print_usage(pos, sym, mode); - ni = built_in_ident("?"); - si = sym->ident ?: ni; + si = sym->ident ?: built_in_ident("?"); /* mem == NULL means entire struct accessed */ - mi = mem ? (mem->ident ?: ni) : built_in_ident("*"); + mi = mem ? mem->ident : built_in_ident("*"); printf("%.*s.%-*.*s %s\n", si->len, si->name, From patchwork Tue Feb 4 16:51:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 11364987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA2501395 for ; Tue, 4 Feb 2020 16:52:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88E9D20730 for ; Tue, 4 Feb 2020 16:52:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h2JUCFti" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727310AbgBDQwC (ORCPT ); Tue, 4 Feb 2020 11:52:02 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58062 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727307AbgBDQwC (ORCPT ); Tue, 4 Feb 2020 11:52:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580835121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=pX/0u06vvgVJyVIdhkgSDT6H2c37kis2VRu6CjvuzJs=; b=h2JUCFtiqSzJaFzdqnWMwKaSi5NTu2R0nC0cfBYdQEyTrcDfG0WfO4IWOYJ1jTyR+lVI01 ezkikWRYptBMtTwFFZ7GWr5lBDPMAeXHfZHXzx9DSo2xacb7Egpn6BiXCd2YMfR/qZ68Qg j48F8+yhK0X4DN5+gH0A7QnmoCXBocc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-19-bVrH_DqqOqqOS9jsalUfwQ-1; Tue, 04 Feb 2020 11:51:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2062D190B2AA; Tue, 4 Feb 2020 16:51:42 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.70]) by smtp.corp.redhat.com (Postfix) with SMTP id 4A57560BF3; Tue, 4 Feb 2020 16:51:41 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 4 Feb 2020 17:51:41 +0100 (CET) Date: Tue, 4 Feb 2020 17:51:40 +0100 From: Oleg Nesterov To: Luc Van Oostenryck Cc: Alexey Gladkov , linux-sparse@vger.kernel.org Subject: [PATCH 2/4] dissect: turn mk_name() into deanon() Message-ID: <20200204165140.GA24343@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200204165119.GA24330@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: bVrH_DqqOqqOS9jsalUfwQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Preparation. Change mk_name() to initialize base->ident itself, simplify it, and rename to deanon(). Also change examine_sym_node() to accept "struct symbol *parent" rather than "struct ident *root". Currently it is only used as ->ident holder, but this will be changed. Signed-off-by: Oleg Nesterov --- dissect.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/dissect.c b/dissect.c index ff3a313..d34b38a 100644 --- a/dissect.c +++ b/dissect.c @@ -190,18 +190,22 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr) return ret; } -static inline struct ident *mk_name(struct ident *root, struct ident *node) +static bool deanon(struct symbol *base, struct ident *node, struct symbol *parent) { + struct ident *pi = parent ? parent->ident : NULL; char name[256]; + if (!node) + return false; + snprintf(name, sizeof(name), "%.*s:%.*s", - root ? root->len : 0, root ? root->name : "", - node ? node->len : 0, node ? node->name : ""); + pi ? pi->len : 0, pi ? pi->name : NULL, node->len, node->name); - return built_in_ident(name); + base->ident = built_in_ident(name); + return true; } -static void examine_sym_node(struct symbol *node, struct ident *root) +static void examine_sym_node(struct symbol *node, struct symbol *parent) { struct symbol *base; struct ident *name; @@ -232,12 +236,12 @@ static void examine_sym_node(struct symbol *node, struct ident *root) return; base->evaluated = 1; - if (!base->ident && name) - base->ident = mk_name(root, name); - if (base->ident && reporter->r_symdef) - reporter->r_symdef(base); + if (base->ident || deanon(base, name, parent)) { + if (reporter->r_symdef) + reporter->r_symdef(base); + } DO_LIST(base->symbol_list, mem, - examine_sym_node(mem, base->ident ?: root)); + examine_sym_node(mem, base->ident ? base : parent)); default: return; } From patchwork Tue Feb 4 16:51:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 11364983 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC167921 for ; Tue, 4 Feb 2020 16:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 912D720730 for ; Tue, 4 Feb 2020 16:51:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gyGedD+8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727321AbgBDQvv (ORCPT ); Tue, 4 Feb 2020 11:51:51 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60002 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727310AbgBDQvv (ORCPT ); Tue, 4 Feb 2020 11:51:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580835110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=xJaXTaBpjvq2ACMl1OOOou58n8Mm758zSo27FmcAo4k=; b=gyGedD+8WehYqD8JZ48gvJOZU37H/TP38gHLHYIbLBoUnh4NCgvLSqHNdiEhWzbo71LsTe K9ZwHcEfWjgKsIBE7wYGP5zhli74dJaETfcl6pKbsG3KR756fV74DZqLRSzTLm+nh4K3hm SZLszLsYI4eYjGG4DRAh2YEMLv4Oz0s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-bIwg5LZ2O9SvCRnzmX-ikQ-1; Tue, 04 Feb 2020 11:51:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9C9E108BD0C; Tue, 4 Feb 2020 16:51:43 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.70]) by smtp.corp.redhat.com (Postfix) with SMTP id 1293860BF3; Tue, 4 Feb 2020 16:51:42 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 4 Feb 2020 17:51:43 +0100 (CET) Date: Tue, 4 Feb 2020 17:51:42 +0100 From: Oleg Nesterov To: Luc Van Oostenryck Cc: Alexey Gladkov , linux-sparse@vger.kernel.org Subject: [PATCH 3/4] dissect: change deanon() to handle the !node case Message-ID: <20200204165142.GA24346@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200204165119.GA24330@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: bIwg5LZ2O9SvCRnzmX-ikQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Change deanon() to always initialize base->ident when parent != NULL but still return false to avoid the pointless ->r_symdef(). Test-case: struct { union { int x; }; } var = { { .x = 0 }, }; before this patch: 1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var 6:12 s -w- ?.x int after: 1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var 6:12 s -w- :var.x int Signed-off-by: Oleg Nesterov --- dissect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dissect.c b/dissect.c index d34b38a..57dcdb2 100644 --- a/dissect.c +++ b/dissect.c @@ -195,8 +195,10 @@ static bool deanon(struct symbol *base, struct ident *node, struct symbol *paren struct ident *pi = parent ? parent->ident : NULL; char name[256]; - if (!node) + if (!node) { + base->ident = pi; return false; + } snprintf(name, sizeof(name), "%.*s:%.*s", pi ? pi->len : 0, pi ? pi->name : NULL, node->len, node->name); From patchwork Tue Feb 4 16:51:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 11364985 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D1451395 for ; Tue, 4 Feb 2020 16:51:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B7D620730 for ; Tue, 4 Feb 2020 16:51:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UwmUWigA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727331AbgBDQvx (ORCPT ); Tue, 4 Feb 2020 11:51:53 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:53535 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727310AbgBDQvx (ORCPT ); Tue, 4 Feb 2020 11:51:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580835111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=kngIGKyAjsTD5aT4u2g/6g/TqiaEXOZRxEBarK8ahJ8=; b=UwmUWigATzCbBKZ9b9ZiBopBOq0Y0LzaueIpTez3BU5hMI+xpBhVhNQRWZOtNTnvgFmWUW bYgDMPWVORwjKk7NArP3J06lWaLqw0qJcx2aPIByoab865X+3x5oqCYDznxBM5kD1wF6ON Y8bXIUqTl3byLrDXUqNQyCaq+mKLpyo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-qBkqYb7AMo6BlEvrp4IpjQ-1; Tue, 04 Feb 2020 11:51:46 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7C0A8C3420; Tue, 4 Feb 2020 16:51:45 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.70]) by smtp.corp.redhat.com (Postfix) with SMTP id D02AC77927; Tue, 4 Feb 2020 16:51:44 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 4 Feb 2020 17:51:45 +0100 (CET) Date: Tue, 4 Feb 2020 17:51:44 +0100 From: Oleg Nesterov To: Luc Van Oostenryck Cc: Alexey Gladkov , linux-sparse@vger.kernel.org Subject: [PATCH 4/4] dissect: disallow NULL pointers in struct reporter Message-ID: <20200204165144.GA24349@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200204165119.GA24330@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: qBkqYb7AMo6BlEvrp4IpjQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This makes dissect.c a bit more readable. Signed-off-by: Oleg Nesterov --- dissect.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/dissect.c b/dissect.c index 57dcdb2..88eaab1 100644 --- a/dissect.c +++ b/dissect.c @@ -135,7 +135,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos, { struct symbol *ret = mem->ctype.base_type; - if (mem->ident && reporter->r_member) + if (mem->ident) reporter->r_member(fix_mode(ret, mode), pos, type, mem); return ret; @@ -146,9 +146,6 @@ static void report_implicit(usage_t mode, struct position *pos, struct symbol *t if (type->type != SYM_STRUCT && type->type != SYM_UNION) return; - if (!reporter->r_member) - return; - if (type->ident != NULL) reporter->r_member(mode, pos, type, NULL); @@ -184,8 +181,7 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr) if (0 && ret->type == SYM_ENUM) return report_member(mode, &expr->pos, ret, expr->symbol); - if (reporter->r_symbol) - reporter->r_symbol(fix_mode(ret, mode), &expr->pos, sym); + reporter->r_symbol(fix_mode(ret, mode), &expr->pos, sym); return ret; } @@ -238,10 +234,8 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent) return; base->evaluated = 1; - if (base->ident || deanon(base, name, parent)) { - if (reporter->r_symdef) - reporter->r_symdef(base); - } + if (base->ident || deanon(base, name, parent)) + reporter->r_symdef(base); DO_LIST(base->symbol_list, mem, examine_sym_node(mem, base->ident ? base : parent)); default: @@ -577,19 +571,15 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *exp static inline struct symbol *do_symbol(struct symbol *sym) { - struct symbol *type; - - type = base_type(sym); + struct symbol *type = base_type(sym); - if (reporter->r_symdef) - reporter->r_symdef(sym); + reporter->r_symdef(sym); switch (type->type) { default: if (!sym->initializer) break; - if (reporter->r_symbol) - reporter->r_symbol(U_W_VAL, &sym->pos, sym); + reporter->r_symbol(U_W_VAL, &sym->pos, sym); do_initializer(type, sym->initializer); break; case SYM_FN: