From patchwork Thu Dec 31 10:10:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5297AC433E0 for ; Thu, 31 Dec 2020 10:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 280B7207A3 for ; Thu, 31 Dec 2020 10:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726524AbgLaKLX (ORCPT ); Thu, 31 Dec 2020 05:11:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726517AbgLaKLX (ORCPT ); Thu, 31 Dec 2020 05:11:23 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C269C061575 for ; Thu, 31 Dec 2020 02:10:42 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id r7so19702143wrc.5 for ; Thu, 31 Dec 2020 02:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rn8kVi3Pl/IgeqSmKaQFydn5Edh0dedaqIMn7SModZg=; b=M5u3ALe11S7ja5+ERI9qPF0Z0b8GODI7DTsExsXyFB7EMEkvLWCHRTWx903sOQ8XRQ xZyt8D5LkZzwOxQhuK1qH9wVEzpZxdsITSkNZ9cI5hiUnbNZCF19G8lbFJHq8PhLeRfj oxBqrj0LIrzCm6KIzcQTSdSaCTsHIMMFzf2542Bv+dnWuofA7gzIfZeGuEo5Uzlnsukr XB+XqyD9DJ493bWpYZNVtK/wCm4w9aVx6QDg8bpl4plV8Ox71NOMqzRE3Gsvi2hkH3kk glSKLcgAB7624/JI2dQhv+i832fw5e65Ra40S2yoQoKz7/sHK1732d59kyWRGQ+6poki Slhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rn8kVi3Pl/IgeqSmKaQFydn5Edh0dedaqIMn7SModZg=; b=mmj94Om+1udlbOWTu6mxtmFkgGuo9L2AcDqFzGaUbRNj3DnFBDzHYikrd5QOfRwxig +QmhhC04ntKToBM0/7eAdXW98RpYYDjJiox+Vw92wf/1+lhABG51gytMzSsCljwpcoip Yatgvmz11kJrsyz4gXo0XvuN5dSUMM6ulWmevGzIZZ0UJvb9QLIgzlMGBtaU8q7L3bqi hZUF8LmAEkFNZ+YN/eQFd/h/ubHsqC3e97Ra8Y9EZs91ntlDfQZX0h0D5isbtwfPhEzL EYOxhrY/ggqgch1j3hmME97rfncsQGZ3llc1wMtpwdDz25NgIhz5aIVFj6kaCuanZoH8 DrZA== X-Gm-Message-State: AOAM530xgOELfn8IqKwfVq6Y9mrQEoyeRhP2FXUVUyPZ98M8VNb9jM1D O7tpfbd6Hv3PGsFJyAZkfugXka3Dv/U= X-Google-Smtp-Source: ABdhPJw51kQffid9SeB/zx9d2LfGViEAukzGSZa9dYW20S+1e59/GgrpgEqRt1MYWFq3tN5zEe2YFA== X-Received: by 2002:a05:6000:1043:: with SMTP id c3mr62789102wrx.34.1609409440982; Thu, 31 Dec 2020 02:10:40 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:40 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 01/16] add testcases for dubious enum values Date: Thu, 31 Dec 2020 11:10:19 +0100 Message-Id: <20201231101034.59978-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org sparse accept any type of integral value for enumerators but address constants are also accepted, which is 'strange'. Add a testcase for such 'enums'. Signed-off-by: Luc Van Oostenryck --- validation/enum-type-dubious.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 validation/enum-type-dubious.c diff --git a/validation/enum-type-dubious.c b/validation/enum-type-dubious.c new file mode 100644 index 000000000000..f2cb39fcdbff --- /dev/null +++ b/validation/enum-type-dubious.c @@ -0,0 +1,18 @@ +enum foobar { + FOO = (void*)0, + BAR = (void*)1, + BAZ = (int*)0, + QUX = (int*)123, +}; + +/* + * check-name: enum-type-dubious + * check-known-to-fail + * + * check-error-start +validation/enum-type-dubious.c:2:8: error: enumerator value for 'FOO' is not an integer constant +validation/enum-type-dubious.c:3:8: error: enumerator value for 'BAR' is not an integer constant +validation/enum-type-dubious.c:4:8: error: enumerator value for 'BAZ' is not an integer constant +validation/enum-type-dubious.c:5:8: error: enumerator value for 'QUX' is not an integer constant + * check-error-end + */ From patchwork Thu Dec 31 10:10:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E7C9C433DB for ; Thu, 31 Dec 2020 10:11:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BF42207A3 for ; Thu, 31 Dec 2020 10:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726517AbgLaKLY (ORCPT ); Thu, 31 Dec 2020 05:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbgLaKLX (ORCPT ); Thu, 31 Dec 2020 05:11:23 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDC38C061799 for ; Thu, 31 Dec 2020 02:10:42 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id q18so19751599wrn.1 for ; Thu, 31 Dec 2020 02:10:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QOpZROY4T6jf1pyt6op8rBT8oi/2DDtRed21rNFCYV8=; b=pRBZznpiuicUx4unLI3qZHsCdTYChjYeJ+tHtnyayf3HUDbDBAuJvHmaPZyZp1Vf28 CsMJCO7cazm9J8DDjyxB8yUcM/AiLH/PoH95fUVwHgu68jsvbMi3vLBM1yvBGh4BhcDw P8D+NCepkSsomAg9XYpHJSvLJdn+Sp9uJyH7RY3Xx2sV1MfLuGxdbSyvjx4l+Y52oBq2 vBEmy6i6nR8ifM9559XohQQtkG+IXwC1cuOSOF31oyoHJqHipcWgKBKpG7OJ6pGlZ/wB VzVB20EKIM1MgEWvozjaHHvQfZwDgZUluIcKQ7CoJpZlVGAKGCklkAfFw3uP38DG11DN h5rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QOpZROY4T6jf1pyt6op8rBT8oi/2DDtRed21rNFCYV8=; b=JrG0YK8ggQzqn2213k3HbMRARGbKWGdUe6c/LkSBUMPktjZJ3fZezAeYDTjhLaUyEl rqrvh+eZG8RzP5jNeuvKMRlPsHLSUOUOMLqRkIdVvCjbc3EpVM6KW3dHFGRbqw2UNNzK qOItBT+YivagyOpLuTuEL4l9c69vaW1su26umKIfROGg5TmDxtiLvwzAu7bsdqKy5WsC sjpPbdewk4LUrMVp5tP1gswUxWeUescSe560qHIX5PjAMLjJ0hKP8dZ3NzAQt9i3bP8t +NbfXWPcG9gMi3xz/qsjd7yPDQVKSZkCwZKFwFNjmDb28aZWDD53C+x82bVxmxhZxLbm QMpA== X-Gm-Message-State: AOAM531BsLrheWyA4nfUBY0cY2WWMXISeXp5Dcx5eQfJW5lgxarP1YOZ saAd46y6ARLvcxXjYAvtyp7SA15pAbQ= X-Google-Smtp-Source: ABdhPJxdmFm8ALis4W/R8OL/d6L3s8zBJeByUjycPrSfaBeFRSnc++PIE5BysM/4CBwA3aSs8+3eHA== X-Received: by 2002:a5d:50c3:: with SMTP id f3mr63463630wrt.287.1609409441722; Thu, 31 Dec 2020 02:10:41 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:41 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 02/16] add testcases for exotic enum values Date: Thu, 31 Dec 2020 11:10:20 +0100 Message-Id: <20201231101034.59978-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org There is more than one complexity in the evaluation of enums. Add a test for enums with 'exotic' values not covered in other tests. Signed-off-by: Luc Van Oostenryck --- validation/enum-type-exotic.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 validation/enum-type-exotic.c diff --git a/validation/enum-type-exotic.c b/validation/enum-type-exotic.c new file mode 100644 index 000000000000..a17ca0ad48ef --- /dev/null +++ b/validation/enum-type-exotic.c @@ -0,0 +1,28 @@ +enum foobar { + C = (unsigned char)0, + L = 1L, +}; + +unsigned int foo(void); +unsigned int foo(void) +{ +#ifdef __CHECKER__ + _Static_assert([typeof(C)] == [enum foobar], "enum type"); + _Static_assert([typeof(C)] != [unsigned char], "char type"); +#endif + + typeof(C) v = ~0; + return v; +} + +/* + * check-name: enum-type-exotic + * check-description: + * GCC type's for C is 'int' or maybe 'unsigned int' + * but certainly not 'unsigned char' like here. + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: ret\\.32 *\\$255 + */ From patchwork Thu Dec 31 10:10:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05C34C433E6 for ; Thu, 31 Dec 2020 10:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D03AD207A3 for ; Thu, 31 Dec 2020 10:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726525AbgLaKLY (ORCPT ); Thu, 31 Dec 2020 05:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbgLaKLY (ORCPT ); Thu, 31 Dec 2020 05:11:24 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A9AC06179B for ; Thu, 31 Dec 2020 02:10:43 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id y17so19692592wrr.10 for ; Thu, 31 Dec 2020 02:10:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BFJdvKn92/GbKfPYvhWYQ4d/ziGHTHFbZbzDhbkWBEo=; b=DFsaIOvsDv4b/eqkqv1RugrVFJ45RBQzXKAp1ja8T9zFqGPMeUXjdW+aZ0ulSbbh+n gif2y2PezTJpNRGn7Mkz/Yz/nN/H1ajUef/oz99gzHK7Gf1J4b9wqSzqAwSUTkyxmDPN A87+YSUGLLyJdlUJFooHQiVSMSxbCvmyEzO0JMhUbmVwdcOtUZwZLzXZZ8l0jzGP4bTf Hk1AnR1qR4iOHoPVM0cjFGSKj5LI1J2IeIzhWtHC14H7AFQlHrm1+LqnrWKdVNnYrSg1 NjjVhTBQ44iCA+rifvwshAaOtsEsLbWJviTsBWnNYxlnb3OKl+XrL3bJvNMhSLgFt9bR b8Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFJdvKn92/GbKfPYvhWYQ4d/ziGHTHFbZbzDhbkWBEo=; b=HlpKCKfSZw/KZ9Bc5fhuq5c/eZVNcr0PXfS/sTDI2YKvmOH6lMH6GFjHF6ObKfPBEu UXXnWkpMD0rILnmUrId+u9ESZ1s1MMI/a4vEqQCAJKxEaJVHDPzSh3edssskgpYwQlK1 IvUVLFtudeV8RK9/Vwd3+pDxHCT5n4fvLqcEl2jHdZhWk50wlpj3NWaR8P4ccl6JXXcY wgJq5UyOjvykPLAZlVVL8E57bc0kHxK9H6hC3L/jNYGU2N3k6sPjrPiv1YKGbfmI5FAL +ipAgBOinR+oSf/yss6AH3gW5uewDOL0/geO76nJZIZ1ORkehQyoznBcpeKWXDd3JtO1 xv9Q== X-Gm-Message-State: AOAM531jqF+TbvSNyzOudzuqMlqTRKQU8svq3niC1Usf4pjER2FRbfiA KTi8vRJYwCs4NKq0wwKEInfBl3Z+EYY= X-Google-Smtp-Source: ABdhPJwSRZt4KPuBAXfaT5bqLnDYeNtdia8V/eCMFlNhnEUGcvIkSo4K+V9IE7c3bnvKjJqvr83BRQ== X-Received: by 2002:adf:fd41:: with SMTP id h1mr65044513wrs.284.1609409442545; Thu, 31 Dec 2020 02:10:42 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:42 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 03/16] add testcases for enum attributes Date: Thu, 31 Dec 2020 11:10:21 +0100 Message-Id: <20201231101034.59978-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Signed-off-by: Luc Van Oostenryck --- validation/parsing/enum-attr.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 validation/parsing/enum-attr.c diff --git a/validation/parsing/enum-attr.c b/validation/parsing/enum-attr.c new file mode 100644 index 000000000000..a962d8b417af --- /dev/null +++ b/validation/parsing/enum-attr.c @@ -0,0 +1,29 @@ +#define __attr __attribute__((deprecated)) + +enum { + old __attr, + cur __attr = 42, + new, +}; + +enum odd { + odd = __attr 33, +}; + +enum bad { + bad = 43 __attr, +}; + +/* + * check-name: enum-attr + * + * check-error-start +parsing/enum-attr.c:10:15: error: typename in expression +parsing/enum-attr.c:10:15: error: undefined identifier '__attribute__' +parsing/enum-attr.c:10:15: error: bad constant expression type +parsing/enum-attr.c:10:22: error: Expected } at end of struct-union-enum-specifier +parsing/enum-attr.c:10:22: error: got 33 +parsing/enum-attr.c:14:18: error: Expected } at end of struct-union-enum-specifier +parsing/enum-attr.c:14:18: error: got __attribute__ + * check-error-end + */ From patchwork Thu Dec 31 10:10:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C60BDC43381 for ; Thu, 31 Dec 2020 10:11:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 94339207A3 for ; Thu, 31 Dec 2020 10:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726529AbgLaKLZ (ORCPT ); Thu, 31 Dec 2020 05:11:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbgLaKLZ (ORCPT ); Thu, 31 Dec 2020 05:11:25 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D9EC06179C for ; Thu, 31 Dec 2020 02:10:44 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id w5so19682270wrm.11 for ; Thu, 31 Dec 2020 02:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mf7zjX5KmM5k3fF3eJhd5hveKy9U4QqMRckHW+fXhmI=; b=NieNwFR6k0VBr1tWDHAMNpTht6QmK99f9QunsQLOwGPQbIXxQIcX5EggDSfLh8WEnE Q/YN6xRYBVfjxx48ZwI46SGSqaIkKlDBVfKwGD2a58ed6FipPYiAiVwMAlbTA+ufFTm3 d7GG9Te+MoNVeybzYzx6Ovbp5rIzM0esP5r/CX0fQ5b074VAgYE9XWth0lh9qD5D6uBQ gWIxHwLdkhQZqR1sKrqLneZV90h/i6qHCDM9YGyNaT0Xe2vcxk59DqON8XFl9EwGhUg1 mKctSoyH+0gflFiAGU1ofO1TarO2rGDJSz0qxZpPsKYdn+JI/kV1L1Wm5PlHgQIuSzIf 6XIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mf7zjX5KmM5k3fF3eJhd5hveKy9U4QqMRckHW+fXhmI=; b=rG9mk9arGnTikDv+0cp1lmnpwWlc5Fk5v8P4+Qffih30Ch07jbfdB+47bGgiWmI+Y3 i4Kn1VfECjp3evQprlYZHzTQeAtyELwSSNfsuFcuYloB6NWzVs5wxLXarI463sf79tIY HM+4PkVmDxynsnNFhWRPgK83bSHfkvgPOiwRqwtBItdaRBdKswnNBqELZht+qf0288PH sIbkmvQ0+ZoO0rjh+Zd5fSoYyds3cQ1a5C9f/i53gQPJkCifI7HmKgDIrAAqX1c/rQRG hSO5fKgp003MpW2kW5QQl5o2XBGTB1oNKxgFTZJ+Tl027JsaCviMaq+yIGpqlDXMptVu eU5Q== X-Gm-Message-State: AOAM530VdLhALtw2V8E5el9I2ZF1UJh0hNCTBhqmFq4h2hM5FmWx7kL9 +ct9HFAOiHB8IpCbyQHz1RPxB9iosxg= X-Google-Smtp-Source: ABdhPJxSn7YwivmxWUPpwrde/qcM8ghYHoCwbEtqkyWHCY5ZinsvFjoNe4a00TJlXeQI6qd/w3N6Fg== X-Received: by 2002:a05:6000:1152:: with SMTP id d18mr64443132wrx.6.1609409443453; Thu, 31 Dec 2020 02:10:43 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:42 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 04/16] add testcases for type attributes Date: Thu, 31 Dec 2020 11:10:22 +0100 Message-Id: <20201231101034.59978-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, type attributes are not handled correctly. Add some testcases for them. Signed-off-by: Luc Van Oostenryck --- validation/type-attribute-align.c | 20 ++++++++++++++++++ validation/type-attribute-as.c | 34 +++++++++++++++++++++++++++++++ validation/type-attribute-mod.c | 22 ++++++++++++++++++++ validation/type-attribute-qual.c | 15 ++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 validation/type-attribute-align.c create mode 100644 validation/type-attribute-as.c create mode 100644 validation/type-attribute-mod.c create mode 100644 validation/type-attribute-qual.c diff --git a/validation/type-attribute-align.c b/validation/type-attribute-align.c new file mode 100644 index 000000000000..d9358bff8327 --- /dev/null +++ b/validation/type-attribute-align.c @@ -0,0 +1,20 @@ +#define __aligned(N) __attribute__((aligned(N))) +#define alignof(X) __alignof__(X) + +struct s { + short a, b, c; +} __aligned(2*sizeof(short)); + +static int fs(void) { return sizeof(struct s); } +static int fa(void) { return alignof(struct s); } + +void main(void) +{ + _Static_assert( sizeof(struct s) == 4 * sizeof(short), "size"); + _Static_assert(alignof(struct s) == 2 * sizeof(short), "alignment"); +} + +/* + * check-name: type-attribute-align + * check-known-to-fail + */ diff --git a/validation/type-attribute-as.c b/validation/type-attribute-as.c new file mode 100644 index 000000000000..b40b4e7dddf5 --- /dev/null +++ b/validation/type-attribute-as.c @@ -0,0 +1,34 @@ +#define __as __attribute__((address_space(__as))) + +struct s { + int i; +} __as; + + +extern void use0(void *); +extern void use1(void __as *); + +void main(void) +{ + struct s s; + int i; + + use0(&s); // KO + use0(&i); // OK + use1(&s); // OK + use1(&i); // KO +} + +/* + * check-name: type-attribute-as + * check-known-to-fail + * + * check-error-start +type-attribute-as.c:16:15: warning: incorrect type in argument 1 (different address spaces) +type-attribute-as.c:16:15: expected void * +type-attribute-as.c:16:15: got struct s __as * +type-attribute-as.c:19:15: warning: incorrect type in argument 1 (different address spaces) +type-attribute-as.c:19:15: expected void __as * +type-attribute-as.c:19:15: got int * + * check-error-end + */ diff --git a/validation/type-attribute-mod.c b/validation/type-attribute-mod.c new file mode 100644 index 000000000000..0e7b166a4aec --- /dev/null +++ b/validation/type-attribute-mod.c @@ -0,0 +1,22 @@ +#define __noderef __attribute__((noderef)) + +struct s { + int i; +} __noderef; + + +void main(void) +{ + struct s s; + + s.i = 0; +} + +/* + * check-name: type-attribute-mod + * check-known-to-fail + * + * check-error-start +type-attribute-mod.c:12:9: warning: dereference of noderef expression + * check-error-end + */ diff --git a/validation/type-attribute-qual.c b/validation/type-attribute-qual.c new file mode 100644 index 000000000000..62d8b98ee3df --- /dev/null +++ b/validation/type-attribute-qual.c @@ -0,0 +1,15 @@ +static const struct s { + int x; +} map[2]; + +static void foo(struct s *p, int v) +{ + p->x += v; +} + +/* + * check-name: type-attribute-qual + * check-description: When declaring a type and a variable in the same + * declaration, ensure that type qualifiers apply to the variable + * and not to the type. + */ From patchwork Thu Dec 31 10:10:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEE92C433DB for ; Thu, 31 Dec 2020 10:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AACFE207A3 for ; Thu, 31 Dec 2020 10:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726463AbgLaKMC (ORCPT ); Thu, 31 Dec 2020 05:12:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726348AbgLaKMC (ORCPT ); Thu, 31 Dec 2020 05:12:02 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF8DC06179E for ; Thu, 31 Dec 2020 02:10:45 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id 91so19687595wrj.7 for ; Thu, 31 Dec 2020 02:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HciWNsu0XUVwo2wrDpSIyJKTI8j86Rfxagit+VDsIm8=; b=jPWDiDLk5ullTB2s0uyd/wQuJsNTm4bcWMX4kWSVMLqSc6uYPq4Kg43FWxEGjFN6vS JYJQ20SxoAouiyTDZqB0yYjKQJYq7Z2ZFAeqCrJSAzCi/TpAf4iZbmarKOrBVL3MMNk2 OFmsBCMgkP9+jZ77XqnQLNtEn6kPb3k9DzQtkgTuzyAXS5wUWj7jdsbxRj8GTiSQzgpa MCuwWh+cAfH2WOXiPYh11PjDk7PDh4R5/ioXe3WF0celMAX1181d3nxHnhC3u+tNW3i6 xaIvgH4oXiouf4BdpFcWtFrV+KJP3KkGMfonT1dQDSl3pGAJMJZC3PDx6wDKniylx/Hx 3O7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HciWNsu0XUVwo2wrDpSIyJKTI8j86Rfxagit+VDsIm8=; b=haBeRBM68pS4YpVPgsOVPo5R9lpAcODqXv3arfiDTMcwnW3dDIkeyDMhBHya1NldPG 7YrTJMrGijLNlXlDi6UAlk6EoT/RVglGPjx6JAqRqPbpwndt1Sens9Tp3EEH4oa+8VoN r13Ge9heWUaEGAKlbM60WsweBvgXLGDfx509QWOSjahFJLiDQ/uUC2uBPqO1FgrZYX3o LOPirj4T/fpnr7sGrH1gIwL79NvBrOAsL935/TA18fHCDtcgZWHAzx60BNfy8FBJfzXB cTM68cMTJkTW1bYljk/BohhZOzKiF1MNU/BeRZbe2wA9Iyi8/vQdwxXWkMc460wQgkbd 3+ag== X-Gm-Message-State: AOAM531dgR1Zkpe62bWtg5f6PKb4h4qiRUzHdfnqiG4Pp5SOvGdpe7Uj 2GkdsU0p4jLATwHSGjmVsmljmmG3VwA= X-Google-Smtp-Source: ABdhPJwMLNCeL+e5cIuZqvU6NGADyEwqMOe1LZENqdb4HYiK95Drzci+fovbjkzLWY1Ct6d3CIPyjA== X-Received: by 2002:adf:d085:: with SMTP id y5mr65574413wrh.41.1609409444296; Thu, 31 Dec 2020 02:10:44 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:43 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 05/16] add testcases for packed structures Date: Thu, 31 Dec 2020 11:10:23 +0100 Message-Id: <20201231101034.59978-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, packed structs are not handled correctly. Add some testcases for them. Signed-off-by: Luc Van Oostenryck --- validation/packed-deref0.c | 24 ++++++++++++++++++++++++ validation/packed-struct.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 validation/packed-deref0.c create mode 100644 validation/packed-struct.c diff --git a/validation/packed-deref0.c b/validation/packed-deref0.c new file mode 100644 index 000000000000..865ad68a4f37 --- /dev/null +++ b/validation/packed-deref0.c @@ -0,0 +1,24 @@ +#define __packed __attribute__((packed)) + +typedef struct { + __INT8_TYPE__ a; + __INT16_TYPE__ b; + __INT32_TYPE__ c; +} __packed obj_t; + +_Static_assert(sizeof(obj_t) == 7, "sizeof packed struct"); + +static void foo(obj_t *ptr, int val) +{ + ptr->c = val; +} + +static void bar(obj_t o) +{ + foo(&o, 0); +} + +/* + * check-name: packed-deref0 + * check-known-to-fail + */ diff --git a/validation/packed-struct.c b/validation/packed-struct.c new file mode 100644 index 000000000000..e21d11538639 --- /dev/null +++ b/validation/packed-struct.c @@ -0,0 +1,33 @@ +#define __packed __attribute__((packed)) + +typedef unsigned char u8; +typedef __UINT16_TYPE__ u16; +typedef __UINT32_TYPE__ u32; +typedef __UINT64_TYPE__ u64; + +struct a { + u8 a; + u8 b; + u16 c; +} __packed; +_Static_assert(__alignof(struct a) == 1, "align struct"); +_Static_assert( sizeof(struct a) == 4, " size struct"); + +struct b { + u32 a; + u32 b; +} __packed; +_Static_assert(__alignof(struct b) == 1, "align struct"); +_Static_assert( sizeof(struct b) == 8, "size struct"); + +struct c { + u16 a; + u32 b; +} __packed; +_Static_assert(__alignof(struct c) == 1, "align struct"); +_Static_assert( sizeof(struct c) == 6, "size struct"); + +/* + * check-name: packed-struct + * check-known-to-fail + */ From patchwork Thu Dec 31 10:10:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A2F3C433E0 for ; Thu, 31 Dec 2020 10:12:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D396C2158C for ; Thu, 31 Dec 2020 10:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726348AbgLaKMC (ORCPT ); Thu, 31 Dec 2020 05:12:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgLaKMC (ORCPT ); Thu, 31 Dec 2020 05:12:02 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A3CC06179F for ; Thu, 31 Dec 2020 02:10:46 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id v14so6990287wml.1 for ; Thu, 31 Dec 2020 02:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TSMbSIKTnRV9WGZmjxMKLs9z1Fl3BYZ/dX1qJ9TdcSM=; b=IxiWamIIrbHPJdyfUrRC6NZQKlCXgin7mtnEuAemLEATs6ElBRz264dMksz7gZmWkV tlospVu+r0VXC/CRBUfCZV8AsXmoHer0WCy4qaPE9fM0ss4kJhwu9zPVmyJrhcGNbT4b /DcB/J4gglkyNNyH9cY3FfWIwqdtcu82AQLt9Ylmxfb+PJamw3yYN1/yWkn1aCpUEW4P zBFFXiuNS0GpR9rQRIvxH7o+wtDVAZ18gX24jU8avH+/hKilnqfLZ24ZeMKAb22RyX87 etL+dVlbXd6yXMsltTYEkifn3gdU5zlEIliNK+ykykVuYJRmDpZEh5wlu5kX6x6MdoXv 6IIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TSMbSIKTnRV9WGZmjxMKLs9z1Fl3BYZ/dX1qJ9TdcSM=; b=fxVhkNar4RTuZT0/nX+GuieJuGTGS5QTL5icSBGRzXCboAXeNd53KLE+JNcuSHD0sU 9YkgxqgLpMbfjFQUi69PvvdMUTLSzh6y+UwtmeXH8id1m7a8G1vBNN1qMOn43GqfQsib BNvKLJTPK/dAilHLzMXey4EaOf1Wxwt+kEb6GVxfOr+CY/AN+Wg/eZwZac0X8i46wAai YBeiF0ImQ13iGakptTPfN4rNTk1/CDw8n/vTSQvo8lYMgKj7Ig8FApeUBm+s1jpFyD9h 1seQFR2qjO4G4uxWH4i2+CXVsvVgS2BOWKm6675W44xzfy8mCsPUXXhJFYBEgViV/7TE JGSw== X-Gm-Message-State: AOAM531IIgwcYhJaVQUPVHPjavB9WrOdkKumjVmvGRK50jwOJLOKGTzn cTScUkL7++kGFsRRIlKGrqM/47nA8iY= X-Google-Smtp-Source: ABdhPJxeOV1/N3XV6s6kqFYaIqPC3tgtRpJYcDLD6RyM0JHHdmqF+mD4cXj/zVwNJI5PApCh5fLPZQ== X-Received: by 2002:a1c:6484:: with SMTP id y126mr11157710wmb.76.1609409445233; Thu, 31 Dec 2020 02:10:45 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:44 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 06/16] add testcases for packed bitfields Date: Thu, 31 Dec 2020 11:10:24 +0100 Message-Id: <20201231101034.59978-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, packed bitfields are not handled correctly. Add some testcases for them. Signed-off-by: Luc Van Oostenryck --- validation/packed-bitfield0.c | 59 +++++++++++++++++++++++++++++++++++ validation/packed-bitfield1.c | 28 +++++++++++++++++ validation/packed-bitfield2.c | 16 ++++++++++ validation/packed-bitfield3.c | 29 +++++++++++++++++ validation/packed-bitfield4.c | 19 +++++++++++ validation/packed-bitfield5.c | 21 +++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 validation/packed-bitfield0.c create mode 100644 validation/packed-bitfield1.c create mode 100644 validation/packed-bitfield2.c create mode 100644 validation/packed-bitfield3.c create mode 100644 validation/packed-bitfield4.c create mode 100644 validation/packed-bitfield5.c diff --git a/validation/packed-bitfield0.c b/validation/packed-bitfield0.c new file mode 100644 index 000000000000..f84e7b904a82 --- /dev/null +++ b/validation/packed-bitfield0.c @@ -0,0 +1,59 @@ +#define alignof(X) __alignof__(X) +#define __packed __attribute__((packed)) + +struct sa { + int a:7; + int c:10; + int b:2; +} __packed; +_Static_assert(alignof(struct sa) == 1, "alignof(struct sa)"); +_Static_assert( sizeof(struct sa) == 3, "sizeof(struct sa)"); + + +static int get_size(void) +{ + return sizeof(struct sa); +} + +static void chk_align(struct sa sa, struct sa *p) +{ + _Static_assert(alignof(sa) == 1, "alignof(sa)"); + _Static_assert(alignof(*p) == 1, "alignof(*p)"); +} + +static int fp0(struct sa *sa) +{ + return sa->c; +} + +static int fpx(struct sa *sa, int idx) +{ + return sa[idx].c; +} + +static int fglobal(void) +{ + extern struct sa g; + return g.c; +} + +static struct sa l; +static int flocal(void) +{ + return l.c; +} + + +int main(void) +{ + extern void fun(struct sa *); + struct sa sa = { 0 }; + + fun(&sa); + return 0; +} + +/* + * check-name: packed-bitfield0 + * check-known-to-fail + */ diff --git a/validation/packed-bitfield1.c b/validation/packed-bitfield1.c new file mode 100644 index 000000000000..208a3dc5127c --- /dev/null +++ b/validation/packed-bitfield1.c @@ -0,0 +1,28 @@ +#define __packed __attribute__((packed)) + +struct s { + unsigned int f0:1; + unsigned int f1:1; + unsigned int pad:6; +} __packed; +_Static_assert(sizeof(struct s) == 1, "sizeof(struct s)"); + +extern struct s g; + +static int foo(struct s *ptr) +{ + int f = 0; + + f += g.f0; + f += g.f1; + + f += ptr->f0; + f += ptr->f1; + + return f; +} + +/* + * check-name: packed-bitfield1 + * check-known-to-fail + */ diff --git a/validation/packed-bitfield2.c b/validation/packed-bitfield2.c new file mode 100644 index 000000000000..4587ebec5c90 --- /dev/null +++ b/validation/packed-bitfield2.c @@ -0,0 +1,16 @@ +struct bf2 { + unsigned p1:2; + unsigned i1:32; + unsigned p2:2; + unsigned s9:9; + unsigned s9:9; + unsigned s9:9; + unsigned b1:1; +} __attribute__((packed)); + +_Static_assert(sizeof(struct bf2) == 8); + +/* + * check-name: packed-bitfield2 + * check-known-to-fail + */ diff --git a/validation/packed-bitfield3.c b/validation/packed-bitfield3.c new file mode 100644 index 000000000000..c06e7c41cbcd --- /dev/null +++ b/validation/packed-bitfield3.c @@ -0,0 +1,29 @@ +#define __packed __attribute__((packed)) + +typedef unsigned char u8; +typedef __UINT16_TYPE__ u16; +typedef __UINT32_TYPE__ u32; +typedef __UINT64_TYPE__ u64; + +struct b { + u32 a:1; + u32 b:2; + u32 c:4; + u32 d:8; + u32 e:16; +} __packed; +_Static_assert(__alignof(struct b) == 1); +_Static_assert( sizeof(struct b) == 4); + +struct c { + u8 a; + u8 b; + u64 c:48; +} __packed; +_Static_assert(__alignof(struct c) == 1); +_Static_assert( sizeof(struct c) == 8); + +/* + * check-name: packed-bitfield3 + * check-known-to-fail + */ diff --git a/validation/packed-bitfield4.c b/validation/packed-bitfield4.c new file mode 100644 index 000000000000..0342b2414b6e --- /dev/null +++ b/validation/packed-bitfield4.c @@ -0,0 +1,19 @@ +#define __packed __attribute__((packed)) + +typedef __UINT32_TYPE__ u32; + +struct s { + u32 f:24; +} __packed; +_Static_assert(sizeof(struct s) == 3); + +static int ld(struct s *s) +{ + return s->f; +} + +/* + * check-name: packed-bitfield4 + * check-description: Is check_access() OK with short packed bitfields? + * check-known-to-fail + */ diff --git a/validation/packed-bitfield5.c b/validation/packed-bitfield5.c new file mode 100644 index 000000000000..8f44d4c2c277 --- /dev/null +++ b/validation/packed-bitfield5.c @@ -0,0 +1,21 @@ +#define __packed __attribute__((packed)) + +typedef __UINT32_TYPE__ u32; + +struct s { + u32 a:5; + u32 f:30; + u32 z:5; +} __packed; +_Static_assert(sizeof(struct s) == 5); + +static int ld(struct s *s) +{ + return s->f; +} + +/* + * check-name: packed-bitfield5 + * check-description: is check_access() OK with 'overlapping' packed bitfields? + * check-known-to-fail + */ From patchwork Thu Dec 31 10:10:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DAEBC433E6 for ; Thu, 31 Dec 2020 10:12:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 768D5207A3 for ; Thu, 31 Dec 2020 10:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726520AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgLaKMD (ORCPT ); Thu, 31 Dec 2020 05:12:03 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3484DC0617A0 for ; Thu, 31 Dec 2020 02:10:47 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id d13so19673813wrc.13 for ; Thu, 31 Dec 2020 02:10:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HwLxfE7uXS2gjxFHIROlHvoXuyp2AwlqFqstUvCTsew=; b=VzvyWS5mRl2mpPXxTRSQ2v6mCJx2qPtihXHdFYwzlR+EJANi8SvyRfGiaicxfJao2U dBR9/N+RAQ0VmvGRYpVpfVzC5t3mewRau/OYkKT9x3cauyd40uH6isbPXy7MI2RF+9I2 FBwfwUvNUZFDin8wmbXI+3BWwhAmjXI+1O9VRDJABEH42979ph5weQR2pFkBTkKHu4Vr pVx+PDRC0c/YIhGs/Etvs3BlU8BHZ0MC4nb35vHjth1udnZSOW2b60wCopm9XC99w2uW oFBppo+GGpcfAEatlu0ftcJsasVb+cZdF1v6bQTNtJu0W5RHgv1vI3dVo4oRJzqjDgva fofg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HwLxfE7uXS2gjxFHIROlHvoXuyp2AwlqFqstUvCTsew=; b=JaM+xa2QOu4HLc/VMJNsNBBQYrE93xILDGE4y17GHBMWQ3TdepX120zkbsY8sFZ6Hc YhgYqIQDQmPtkVAwRC6bH3V9Dpbzy/yQNAQSEyd9NL+UzHfZos6mdL4VNPPCnoY34P9x v8TF1p8iiE9jiM8Yf6vpWn9wlX6/jUBKB2KQAGW2Lb2kSwLGTgQqMWb02K2tGktcoqQa 7dlWhNn6iUVpT5aYNWL9VuFI8VzH4Z/WGXGNRApzCE1ToOrQR1D5gDC7L7Oi2wMrRVg1 PDx/pIqX2a5qRw7ig5nnwAejb06SxnI7qXulH2h/OQ6ucOHwcWvku33bkOwwSA22dF3+ WbfQ== X-Gm-Message-State: AOAM5312j7tbnO5wuGmrC7eFUnu2FJkzzC9ykEYRSGVvWL6HMNF1bPnX lV6rAQR2Wl1j8aJ/89ExL8YRSg1PB6U= X-Google-Smtp-Source: ABdhPJz/jUpJ/a21Q1uf5P7VexCmS1TMkR/D3YfyXywtDNmOhr5sC+7bapKnLZiLu3q8sE3dlka45g== X-Received: by 2002:adf:f989:: with SMTP id f9mr63035041wrr.299.1609409446071; Thu, 31 Dec 2020 02:10:46 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:45 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 07/16] apply_ctype: use self-explanatory argument name Date: Thu, 31 Dec 2020 11:10:25 +0100 Message-Id: <20201231101034.59978-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org apply_ctype() is used to copy/apply things like modifiers and address space from one type to another one. But the names used for the two types are: 'ctype' & 'thistype' which doesn't help at all to know which one is the 'source' type and which one is the 'destination' type. Change this by renaming these arguments to 'src' & 'dst'. Signed-off-by: Luc Van Oostenryck --- parse.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/parse.c b/parse.c index 0b2685707b82..402214212d77 100644 --- a/parse.c +++ b/parse.c @@ -1043,7 +1043,7 @@ static struct token *enum_specifier(struct token *token, struct symbol *sym, str return ret; } -static void apply_ctype(struct position pos, struct ctype *thistype, struct ctype *ctype); +static void apply_ctype(struct position pos, struct ctype *src, struct ctype *dst); static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) { @@ -1427,24 +1427,24 @@ static struct token *generic_qualifier(struct token *next, struct symbol *sym, s return next; } -static void apply_ctype(struct position pos, struct ctype *thistype, struct ctype *ctype) +static void apply_ctype(struct position pos, struct ctype *src, struct ctype *dst) { - unsigned long mod = thistype->modifiers; + unsigned long mod = src->modifiers; if (mod) - apply_qualifier(&pos, ctype, mod); + apply_qualifier(&pos, dst, mod); /* Context */ - concat_ptr_list((struct ptr_list *)thistype->contexts, - (struct ptr_list **)&ctype->contexts); + concat_ptr_list((struct ptr_list *)src->contexts, + (struct ptr_list **)&dst->contexts); /* Alignment */ - if (thistype->alignment > ctype->alignment) - ctype->alignment = thistype->alignment; + if (src->alignment > dst->alignment) + dst->alignment = src->alignment; /* Address space */ - if (thistype->as) - ctype->as = thistype->as; + if (src->as) + dst->as = src->as; } static void specifier_conflict(struct position pos, int what, struct ident *new) From patchwork Thu Dec 31 10:10:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB01EC433DB for ; Thu, 31 Dec 2020 10:12:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A43442158C for ; Thu, 31 Dec 2020 10:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbgLaKMD (ORCPT ); Thu, 31 Dec 2020 05:12:03 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E0EFC0617A1 for ; Thu, 31 Dec 2020 02:10:48 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id g185so6897598wmf.3 for ; Thu, 31 Dec 2020 02:10:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wvsuPwsxL0b/wkNe56FvL8uVufKWln1fnBpwmsu4ro0=; b=Hv0kX6jdEbtc+iQJ5FwK9v2hWSVQpw6nwPD5qbKIOr+0y1FHsCLGzXI0a/KTaCyr9X A44AHZLIDkuabWlgxcDAoRfXP88O09DEnOdtmD82vy8rce+GCLkq222cbTpCQTQ9YUWo ayuiEwyk7wFSuxcVH6/djT2gt7fL5yR1GOtqQEavAl77Dcci6fHu14Yc73GjNG4qdKw0 +c0cs78h7ejzCvPCRwWgKdFfoK2/695pJnJdWHCYqWhi+j04nNooqm0Avuprbc9bXcQG I3gGUyQRSTozHAeNOxy/W5ltNgtNOGxx9sSlatLDFdx/LJacH3x7an6cwGXVkKc5B6z1 jLNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wvsuPwsxL0b/wkNe56FvL8uVufKWln1fnBpwmsu4ro0=; b=VvI+U7suJUlrNv7ZhmTRFcdR8uVEZnmkm/Qll7+e0mqfjLUsac1usAqaOJbKfdVznl HWI85FY0wArK1YkFQMjXWzm+UY9c3ZSE2vN05dCEWThocpc8LDbdV3ywDtW7E1VZs6/1 d8HConoD9btKbcdxPugEtdpNZBdRp20XJHCO18THQKRWuKk6ABcXWEHY511jNVEV4TdH J/NHm2meOZkun19/O0mgYgn4jUqfIAzC+UPtQZIZ9xzmr4VGkiy2lurY2bmGeycjlotE Qwj2JGu7B5MwxYtcYF96tcVLrkVhf9eAyrIFQoFAmG379OxO1hKBbfI7svRSfBVc6TxP C3kQ== X-Gm-Message-State: AOAM533aO/EdOPxntMt1aV/0bmbSw+3uqedWBHr+BMa0dSJZxeb6+3iU gUTDxyepo1DrpHKLmTO4PSSGEKLkuOU= X-Google-Smtp-Source: ABdhPJwtrLQTzugg5IXyYGaxXq9vjWUAVC1l+XP/WfCCp7uejL1Rhfs06cvtvEIxzcXDzDwg8oz8Bg== X-Received: by 2002:a7b:c0c8:: with SMTP id s8mr11338063wmh.123.1609409446888; Thu, 31 Dec 2020 02:10:46 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:46 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 08/16] apply_ctype: reverse the order of arguments Date: Thu, 31 Dec 2020 11:10:26 +0100 Message-Id: <20201231101034.59978-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org apply_ctype()'s argument order confuse me endlessly as I'm much more used to have the destination first and the source next (the so called 'assignment order' used for assignments but also in memcpy() and in many sparse or library functions). So, change the argument order of apply_ctype() to mimic the order of memcpy()/assignment, to hopefully reduce my confusion. Signed-off-by: Luc Van Oostenryck --- parse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/parse.c b/parse.c index 402214212d77..f106444f75d8 100644 --- a/parse.c +++ b/parse.c @@ -1043,7 +1043,7 @@ static struct token *enum_specifier(struct token *token, struct symbol *sym, str return ret; } -static void apply_ctype(struct position pos, struct ctype *src, struct ctype *dst); +static void apply_ctype(struct position pos, struct ctype *dst, struct ctype *src); static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) { @@ -1056,7 +1056,7 @@ static struct token *typeof_specifier(struct token *token, struct symbol *sym, s struct symbol *sym; token = typename(token->next, &sym, NULL); ctx->ctype.base_type = sym->ctype.base_type; - apply_ctype(token->pos, &sym->ctype, &ctx->ctype); + apply_ctype(token->pos, &ctx->ctype, &sym->ctype); } else { struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF); token = parse_expression(token->next, &typeof_sym->initializer); @@ -1427,7 +1427,7 @@ static struct token *generic_qualifier(struct token *next, struct symbol *sym, s return next; } -static void apply_ctype(struct position pos, struct ctype *src, struct ctype *dst) +static void apply_ctype(struct position pos, struct ctype *dst, struct ctype *src) { unsigned long mod = src->modifiers; @@ -1529,7 +1529,7 @@ static struct token *declaration_specifiers(struct token *token, struct decl_sta break; seen |= Set_S | Set_T; ctx->ctype.base_type = s->ctype.base_type; - apply_ctype(token->pos, &s->ctype, &ctx->ctype); + apply_ctype(token->pos, &ctx->ctype, &s->ctype); token = token->next; continue; } From patchwork Thu Dec 31 10:10:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2335FC433E9 for ; Thu, 31 Dec 2020 10:12:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE09D207A3 for ; Thu, 31 Dec 2020 10:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726531AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726499AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6F6EC0617A2 for ; Thu, 31 Dec 2020 02:10:48 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id d13so19673871wrc.13 for ; Thu, 31 Dec 2020 02:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uyQF353lYq1izEYPKpY3ieFNMCf34amRJhpkdo3ktuA=; b=miLhgQnZ7pRHiE/vJQOZGXP87GIutYpE/Q4oIMjtY3i84D2Wpc7pXMV+j0TLpmYaGF U+4ho+qnf08K5gQRFlj4y6S0P2tg8eBbfobYx3s9O6PpXdvexOQIrdOdl3Hl2aTvbAX3 uXMjyVkNxDJCkkeFAjcwoBQyPKDSvBrrDMH4ia4rzjWzdLhpDOlvMmdfKAAuissc8o5W AquoiQl+1yqrUI2vIJaOuovjNwH1o1kfA576+EX6D6Z+N2uakfGSGP3a1uh0dLS5NXA7 3RVh7w1XEaT82vZcT3gBUWg9Ld9J+uCypevskYp0lFSn7aNbJo6v7yCbReyFq2LJAHvz RtWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uyQF353lYq1izEYPKpY3ieFNMCf34amRJhpkdo3ktuA=; b=i0Y7T3hYs/nxYCB8JIskAwyT8nrpluT/lZyLanXFLmesalf5YkYvt4entwsMI0Uz/y sRH2/auJfuGDaPGsdtkW7bvTdULFEpkb3/KBFYzdXEbbK0LnGqBVe10furd4/DV88I8F L49AvZkhPhmlL+baNkyGT6huUUt/NThEK6ZtOybmetorWGPTsKTgK27SR7CeTJZeqX2P PWwLc6kLToXy3QNsSVVTtaMnkHaIao3G4S3wZ2gCchpxPfb5yFM2Q3CzYrjKEIQZngEG 7r7EEE2e/csn/D2BZFbqdHAWOacHIGqUpvdz38/rN1075fB6EqEm0CTaC9AXU/pj9NH0 1kWg== X-Gm-Message-State: AOAM530w80fNOqBVH5Lhk+niwWobTAxgyeIkj6jh4t2OVfqcvx5ThDXo tqV2MC+JO41FmrDnE1/cRA/YJIFbE2c= X-Google-Smtp-Source: ABdhPJyXEII9h1yWpwazVpshcbWdq1+gP42l6jyOiNvLVjE9PJM4Ii2yF5XZz2xk/+kTUbWdBiOdKw== X-Received: by 2002:adf:8185:: with SMTP id 5mr62134760wra.44.1609409447678; Thu, 31 Dec 2020 02:10:47 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:47 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 09/16] apply_ctype: move up its declaration Date: Thu, 31 Dec 2020 11:10:27 +0100 Message-Id: <20201231101034.59978-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org apply_ctype() will be needed earlier in the code. So, move it's prototype up. Signed-off-by: Luc Van Oostenryck --- parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parse.c b/parse.c index f106444f75d8..d6343f0e48bf 100644 --- a/parse.c +++ b/parse.c @@ -669,6 +669,8 @@ struct statement *alloc_statement(struct position pos, int type) static struct token *struct_declaration_list(struct token *token, struct symbol_list **list); +static void apply_ctype(struct position pos, struct ctype *dst, struct ctype *src); + static void apply_modifiers(struct position pos, struct decl_state *ctx) { struct symbol *ctype; @@ -1043,8 +1045,6 @@ static struct token *enum_specifier(struct token *token, struct symbol *sym, str return ret; } -static void apply_ctype(struct position pos, struct ctype *dst, struct ctype *src); - static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) { From patchwork Thu Dec 31 10:10:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E10BC433E0 for ; Thu, 31 Dec 2020 10:12:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FA182158C for ; Thu, 31 Dec 2020 10:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726499AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C157BC0617A3 for ; Thu, 31 Dec 2020 02:10:49 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id q75so6899009wme.2 for ; Thu, 31 Dec 2020 02:10:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U+epDQOkwFtZusIzEyGRmFVIO1WJ7cBVcLRDq+IwgRA=; b=DLZEkKOmeX5P/xBtuOI9Hq0knWZMInfEuh6d/ZydsSXjsHjW9Y9Ud4iUQ2+DhhOIYN FIbjItMKQM1n37mE7TddmHVj9+K2fAuNp2q7Ygx9B0NULj4YtqhNQdo8ibJTJkrflQXJ gvkSiO9MEh1WU00fIfzXPDJ5nwig4l4O2YNaVPr+u7SdCrU72h6mzLHhvIeGa0g6JqQu /UCw2Y8RkHOg6XXOBRf5yNHlw+JHsN+wSoxHUs1pYxE/APxS0boKTJtuXAWZK2Suf/XT 4I7c1T+caB07hYtWr/EIPtubYclH1UeEBvwuZVpks9/F1xLSKZffHnzpn27g/Rebt7+B h4qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U+epDQOkwFtZusIzEyGRmFVIO1WJ7cBVcLRDq+IwgRA=; b=qYDSnfhwKD+WT0ZPhYS+9ftC9PbAhObTetg7ax9jTwmzHgpgXr5rI9rCP72NMMU285 kk6KJTNxYBA/e51e9qBjEeCCwVB2AY72vnFoCYpnSm8Zeti3Ah2PGsNFL/57+SZLNRzS aPkso98AulieRAy+lI4hJVcpOZaKS7UYhgihUyP/i8L5F58U9Qk4LPYGKzcGpLxJiRvC jaVAWa4WDZiXlwEVHhxI5Ega3h5lPydfQXkkCHFeb7D5c3PsVeCRPcDlY0cFM/2lTzcU Ym9o7we2BcqRx+Pr+frMyhGkpgQ3bJTiLa48koqo4SADD3JIxA7taTNaTg4cTS0yS2Pa vGLg== X-Gm-Message-State: AOAM530fvbhftmtHLqqv2LG+RWx4CwgHuZK3hcTGkMzjUZ76ymZSMfrw UmT/BFDv50q/XGDKvSf3OR6oOH+nzIw= X-Google-Smtp-Source: ABdhPJw9vbxyKOFdH6o4zkU0KNRG6iJN/wrOUG53a1l3V9qWg/RC8g2sF5AGJ7fRhJY98iw+VILZ3A== X-Received: by 2002:a1c:3b02:: with SMTP id i2mr11085660wma.141.1609409448525; Thu, 31 Dec 2020 02:10:48 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:48 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 10/16] struct-attr: prepare to handle attributes at the end of struct definitions (1) Date: Thu, 31 Dec 2020 11:10:28 +0100 Message-Id: <20201231101034.59978-11-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Type attributes for struct can be placed either just after the keyword 'struct' or after the '}' ending its definition but this later case is currently ignored. Prepare the handling of this by factoring the code common to both cases in a single place. Signed-off-by: Luc Van Oostenryck --- parse.c | 10 +++++----- validation/parsing/enum-attr.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/parse.c b/parse.c index d6343f0e48bf..41d3eb1ff4f8 100644 --- a/parse.c +++ b/parse.c @@ -745,12 +745,10 @@ static struct token *struct_union_enum_specifier(enum type type, if (sym->symbol_list) error_die(token->pos, "redefinition of %s", show_typename (sym)); sym->pos = *repos; - token = parse(token->next, sym); - token = expect(token, '}', "at end of struct-union-enum-specifier"); // Mark the structure as needing re-examination sym->examined = 0; - sym->endpos = token->pos; + goto end; } return token; } @@ -764,9 +762,11 @@ static struct token *struct_union_enum_specifier(enum type type, sym = alloc_symbol(token->pos, type); set_current_scope(sym); // used by dissect - token = parse(token->next, sym); ctx->ctype.base_type = sym; - token = expect(token, '}', "at end of specifier"); +end: + token = parse(token->next, sym); + token = expect(token, '}', "at end of specifier"); + sym->endpos = token->pos; return token; diff --git a/validation/parsing/enum-attr.c b/validation/parsing/enum-attr.c index a962d8b417af..8d851a162135 100644 --- a/validation/parsing/enum-attr.c +++ b/validation/parsing/enum-attr.c @@ -21,9 +21,9 @@ enum bad { parsing/enum-attr.c:10:15: error: typename in expression parsing/enum-attr.c:10:15: error: undefined identifier '__attribute__' parsing/enum-attr.c:10:15: error: bad constant expression type -parsing/enum-attr.c:10:22: error: Expected } at end of struct-union-enum-specifier +parsing/enum-attr.c:10:22: error: Expected } at end of specifier parsing/enum-attr.c:10:22: error: got 33 -parsing/enum-attr.c:14:18: error: Expected } at end of struct-union-enum-specifier +parsing/enum-attr.c:14:18: error: Expected } at end of specifier parsing/enum-attr.c:14:18: error: got __attribute__ * check-error-end */ From patchwork Thu Dec 31 10:10:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E204CC433E6 for ; Thu, 31 Dec 2020 10:12:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1FE9207A3 for ; Thu, 31 Dec 2020 10:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726539AbgLaKMG (ORCPT ); Thu, 31 Dec 2020 05:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3194C0617A4 for ; Thu, 31 Dec 2020 02:10:50 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id g25so3653067wmh.1 for ; Thu, 31 Dec 2020 02:10:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sEYr+yB+gBcqyoBI7qwL7888Chcih5LwZx7EcfBOhzo=; b=IEg392W53SYNfN/BJBehWRT5Gx9ijQNtfAgzR4Du+yaKmo8e41PnFTBFTCWa0qGJSd uHTztu1TsFjtPYYKI68p+XFq3CwkyAeQTsvcUDkQ4qTKxaX/TbVZsUzSDq4g/xrnsQrE tSEJU1N3QUD6bts8Eva31gOjSRwvi2iOsfZ+cI5gn0iY86JC8Q79xsfc5Kx8s+NZuHLV wi6tPANqHKpi/Az952kafC9AWKqpxx5b8G4h0ff8t3yskx2BvPTE0TxBxR6uWpVpJ3Dp 2vZswz8T07sXtHAdBspQqfg6cEUW0qjh1QMarS2k42NoE6nFuRsbhYrh7Qa4yk2MYWrQ Y1PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sEYr+yB+gBcqyoBI7qwL7888Chcih5LwZx7EcfBOhzo=; b=hZZWsd937rojvb6UETtDH1y56jarriivSqqHmnszGYcq04B0jqdNfc981ae06vU3IF DbHyRUUgA/RvD2ketWdFQ43xKezw6F9zxqIA5Mb88zusVvRdUXLF4rqMAoO00/hZIa0i TwuUTJ8E0QuWq4a9pf659cs8D4JnNYxWbOVu7FQajOsUMj2nGw2rbxw4HfHUz4rYoEuQ /NPRGhHDAD9sgInDmPya1giuYRi1SwNhPJxmj/W5Djsjseebd8+4AMM+3NxMyXAENGg0 81FCGIvtwC2rIr2DF6Up7FigDUrFLUgyGPlSg93o50J6QPHv4mI9IH3baZPhMoBbsH82 oCaw== X-Gm-Message-State: AOAM531wXwSZ0zaiFuWQPFQCABr9k41pXRnHKnSMdSU7zE+eYm2dy8KP BARxm+PbAGSnhff/iyET5aAI3qhHaJY= X-Google-Smtp-Source: ABdhPJwaRsUMYYztj+F0RzZvVnN4rnIiZkdeVOC++TeNKdzDppRy+RaRXF+Q28IfVLic/2yGjfLPzg== X-Received: by 2002:a1c:ac86:: with SMTP id v128mr11051661wme.76.1609409449751; Thu, 31 Dec 2020 02:10:49 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:49 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 11/16] struct-attr: prepare to handle attributes at the end of struct definitions (2) Date: Thu, 31 Dec 2020 11:10:29 +0100 Message-Id: <20201231101034.59978-12-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Type attributes for struct can be placed either just after the keyword 'struct' or after the '}' ending its definition but this later case is currently ignored. Prepare the handling of this by restructuring the code handling struct specifiers, namely inverting the condition so that the function can return early to make next patch's job easier. Signed-off-by: Luc Van Oostenryck --- parse.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/parse.c b/parse.c index 41d3eb1ff4f8..663f2141dbf4 100644 --- a/parse.c +++ b/parse.c @@ -738,19 +738,19 @@ static struct token *struct_union_enum_specifier(enum type type, ctx->ctype.base_type = sym; repos = &token->pos; token = token->next; - if (match_op(token, '{')) { - // The following test is actually wrong for empty - // structs, but (1) they are not C99, (2) gcc does - // the same thing, and (3) it's easier. - if (sym->symbol_list) - error_die(token->pos, "redefinition of %s", show_typename (sym)); - sym->pos = *repos; - - // Mark the structure as needing re-examination - sym->examined = 0; - goto end; - } - return token; + if (!match_op(token, '{')) + return token; + + // The following test is actually wrong for empty + // structs, but (1) they are not C99, (2) gcc does + // the same thing, and (3) it's easier. + if (sym->symbol_list) + error_die(token->pos, "redefinition of %s", show_typename (sym)); + sym->pos = *repos; + + // Mark the structure as needing re-examination + sym->examined = 0; + goto end; } // private struct/union/enum type From patchwork Thu Dec 31 10:10:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C454C433DB for ; Thu, 31 Dec 2020 10:12:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAF5D2158C for ; Thu, 31 Dec 2020 10:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726485AbgLaKMG (ORCPT ); Thu, 31 Dec 2020 05:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbgLaKME (ORCPT ); Thu, 31 Dec 2020 05:12:04 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA88BC0617A5 for ; Thu, 31 Dec 2020 02:10:51 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id w5so19682512wrm.11 for ; Thu, 31 Dec 2020 02:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lbx6ALZgE4iV9qDOFG81hFqrC8lHYFit6Y2RR8bYoL0=; b=DBvxmlveUwllrJ8V+Wou/JgN1tizk5OYlSgJYGPBTnOqRFDM6fd1QeF/TOn3HXM4J7 uyDDoUW4Dsw7q9XCLHPSqN5UjPp3QgAZ4l58nWxhZ9NGX7E0ypQfq9eSzR1CU9r2CJIH xIsX7/Sjp5hu4TO4geR5IivzUCrJqswmSopdPo4SY67WrD1HSbrdmRHbAWSWC/uV47IX r6712UYAuY4yZGBS1qgJhhoWo4WPduNwBOowHInipPIsjFtyz6FIDcvUug2pSwpMCN0z t2mSZgiMBeMS19AfeBES9tPYlJDv53yZGrs52ycN+ZY1wrm1eWmv6i7UgKhca+XNW9cn k/Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lbx6ALZgE4iV9qDOFG81hFqrC8lHYFit6Y2RR8bYoL0=; b=XQNcwiM87ycpxXsTd2ElAA+daqyp6dKHAz9KHFvk6hBqFexSPg9Ir1OsX7KoKnD8ef p3Xc2bxjJxaGBMob+HnQIQZBsxyCYJn6BsR3OAHm9UphNFIuLKUr0uiRLGR5/41fhpxU /wCL3jwYca3Qwz9K24sCC4ARcVNQwhC0ZGNvSoLvkg0so1yuOQuOD6Ia6F4HZ/uQOVM2 b9R+Su1xx1qUE3uaoq4mWWDahPWBmFMvMqy2j68igNMcH6oNpb5L1PISTcpWhhDSRsd+ JfXPX5TERu427HHDaIYy97UnNd1Hr9HjPtimIz3LcSVl2ZLA0bcteT/4uOJ3+eziM+RV DffQ== X-Gm-Message-State: AOAM533TxNzBBgskZa/8iXat4bJn7zvFF/kH9xAulqfYuIZBVtKyADRv cYQtKXcteQWc/TWB5BZlKyeO5sas2B8= X-Google-Smtp-Source: ABdhPJxX+B3x+yxvrh5gfv1Pi2z89pTabKydA16bmGIKK7OEFqL92KiJKE724HIsnLQgWVn9g3WGeg== X-Received: by 2002:adf:9d48:: with SMTP id o8mr54209715wre.408.1609409450798; Thu, 31 Dec 2020 02:10:50 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:50 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 12/16] struct-attr: prepare to handle attributes at the end of struct definitions (3) Date: Thu, 31 Dec 2020 11:10:30 +0100 Message-Id: <20201231101034.59978-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Type attributes for struct can be placed either just after the keyword 'struct' or after the '}' ending its definition but this later case is currently ignored. Prepare the handling of this by having the 3 following cases in sequence: 1) a tag is present 2) no tag present but is followed by an opening brace 3) neither of these, so it's an error. Signed-off-by: Luc Van Oostenryck --- parse.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/parse.c b/parse.c index 663f2141dbf4..69bfc2e0fe57 100644 --- a/parse.c +++ b/parse.c @@ -750,20 +750,17 @@ static struct token *struct_union_enum_specifier(enum type type, // Mark the structure as needing re-examination sym->examined = 0; - goto end; - } - - // private struct/union/enum type - if (!match_op(token, '{')) { + } else if (match_op(token, '{')) { + // private struct/union/enum type + sym = alloc_symbol(token->pos, type); + set_current_scope(sym); // used by dissect + ctx->ctype.base_type = sym; + } else { sparse_error(token->pos, "expected declaration"); ctx->ctype.base_type = &bad_ctype; return token; } - sym = alloc_symbol(token->pos, type); - set_current_scope(sym); // used by dissect - ctx->ctype.base_type = sym; -end: token = parse(token->next, sym); token = expect(token, '}', "at end of specifier"); From patchwork Thu Dec 31 10:10:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C375C43381 for ; Thu, 31 Dec 2020 10:12:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10B6D207A3 for ; Thu, 31 Dec 2020 10:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbgLaKMG (ORCPT ); Thu, 31 Dec 2020 05:12:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726503AbgLaKMF (ORCPT ); Thu, 31 Dec 2020 05:12:05 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7E3C0617A6 for ; Thu, 31 Dec 2020 02:10:53 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id v14so6990494wml.1 for ; Thu, 31 Dec 2020 02:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sS3CtCv1mfx7U74EhcAnKmNrWaxczz5yzmoqqiME4XA=; b=El1VW+25rRRRbBM/OIDWtRXtLzXGnDpniWGXyDTu8HdgfJ2pD+dWb1uOp2DgxALT2W 3gZqyZlxWaC+NYcE6Td/QRKlVRRPun9u1NYKBZ1GfDUAGe1Bq9UtfrODT61kYfFqzsrc vEHEEc661zFsS9OAPfntYfJmVDvWzzweUrbB0+DOFbfTQT/2bjKjcu9caVo2DxSZpqc5 MqUDpBifYs5lbMFbLuAyaPYTdqQQdXtDucJjB3OLx8hFAVVBdy5YBrveg01/YpLux+XN fonYFXI1K0QWIjXMbS0sANsl62g5yDdrb4CNQX+RiBzHmxD8KriX9I/nzWNK4N3SIk9J K14g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sS3CtCv1mfx7U74EhcAnKmNrWaxczz5yzmoqqiME4XA=; b=KqHC3wuP0tv1NbRAWQCjaTdS40YiFbbnpVgbUEWpbj1Ffhn/8j8cUlqhm/tzMhF3el 1ZTWGnLnvIDIJjEDO/hM3+cmvuKHJf8ZPuMJb4be9ugAV2eWGrMwm3MTzuwRoK0lLlHm 0jkUoL7bUwhI4g2Syb3kmuEzR/8KWcA3ssQNyt6QrMSGeerxbXXIk/TpJAURWpnU56Xt x40Bz3vBBQcp5KXx1bmw9Zn8oXhyjoxnDbiXX6QypxQXrKKgOxFr+Pz7WKp/5255Gohn q4BRqTmgMyjaE0/Kkl+Q9mGRNuT6GRKvX4MlsUxJgZKiEbrD4KQYRmh7e9QvUuYDjakt bQLQ== X-Gm-Message-State: AOAM530+hrta9gBlWnHBzaWnf1frA6v3Cklier0mScUKBTNX8rh1vz38 MlLN/kqkg9mmpKERAIr3xLdXC04BSUA= X-Google-Smtp-Source: ABdhPJyT9ZBuJQCcvvswcd5yozHdXq5Z8whL31JhidTfr02NtiuoHEcK79op7nfduRppTlnEvzGzqQ== X-Received: by 2002:a7b:c091:: with SMTP id r17mr11492471wmh.129.1609409451892; Thu, 31 Dec 2020 02:10:51 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:51 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 13/16] struct-attr: fix type attribute like 'struct __attr { ... }' Date: Thu, 31 Dec 2020 11:10:31 +0100 Message-Id: <20201231101034.59978-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org In a declaration like: struct { ... } the attribute belong to the type but is currently handled as belonging to the whole declaration. Fix this by handling such attributes in a local 'decl_state' and applying them once the closing '}' is reached. Signed-off-by: Luc Van Oostenryck --- parse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parse.c b/parse.c index 69bfc2e0fe57..b38615b8d61d 100644 --- a/parse.c +++ b/parse.c @@ -719,10 +719,11 @@ static struct token *struct_union_enum_specifier(enum type type, struct token *token, struct decl_state *ctx, struct token *(*parse)(struct token *, struct symbol *)) { + struct decl_state attr = { }; struct symbol *sym; struct position *repos; - token = handle_attributes(token, ctx); + token = handle_attributes(token, &attr); if (token_type(token) == TOKEN_IDENT) { sym = lookup_symbol(token->ident, NS_STRUCT); if (!sym || @@ -763,6 +764,7 @@ static struct token *struct_union_enum_specifier(enum type type, token = parse(token->next, sym); token = expect(token, '}', "at end of specifier"); + apply_ctype(token->pos, &sym->ctype, &attr.ctype); sym->endpos = token->pos; From patchwork Thu Dec 31 10:10:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FBB9C433E9 for ; Thu, 31 Dec 2020 10:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8E29207A3 for ; Thu, 31 Dec 2020 10:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726503AbgLaKMH (ORCPT ); Thu, 31 Dec 2020 05:12:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbgLaKMF (ORCPT ); Thu, 31 Dec 2020 05:12:05 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1938C0617A7 for ; Thu, 31 Dec 2020 02:10:53 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id d26so19664625wrb.12 for ; Thu, 31 Dec 2020 02:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uzs0PRBDwTm5xhuPVtkISBci8qATErI9BQqOhnyKri4=; b=reOKdHltC1FhxtC4W8/y/wnEBBz97gdd34O+GWdypgxjhwW4RxRGTX+PBkhzWi32lO +rVn6RABWUnxJGctCDnFMdK5HC38Z/sPlIvhRTUcsHZstA09zcCv4IKG5m1gfz/2NViL mnQBPp0rFgEavUw9U850APRaci736u/K7xctaPba0Fb8l9pFUvE+vJwJq43u57dKSFq1 4MzXfr5sTcxYyiOOy6/pbGQrCsvFr0RS5NLTlg4JrR9FLUGCDvsgI6XgReH/4gU1e7ZZ I7WSdwwZpDx6OOaY9BlafzA5u1/BGNjiZTTOyV5odfBLhvXPLco72DSZfi9enrg3f0Gf JEAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uzs0PRBDwTm5xhuPVtkISBci8qATErI9BQqOhnyKri4=; b=HFcF76oK1wv46c6ybniPoPpKQ14Rn3wcMLx3WdKCEEW1OlW3OEjCD4sChsnwaFHdQF 7bxj6XX1AJkeaoYEtZLQwOW2tlKrc6wDjnvmkvXi4FP/py/Nb3qQvS4RmVT15eCsthzi e79OJkDhQEPX0lfvNPRubGxYcrV+dcKyQUf+yQrrjE8WVKrZh5gujYgok9I6JAG2484s Gd2oMjnjVsTJlXY+Evo+TCOv4ktnpaMComRkO/3qebR58M3XggzS7kXo0mZAv1LLIoXH kytOeDIckYg68tr6n2v5gqw0UNRblVgWdcqVQYjCrwXiqywkPX9/tSrJgQ9tEd/cH/yZ A49g== X-Gm-Message-State: AOAM530dgPgyRypWkHYTLwKcalUTZheJD1RrHY1vqtlF36xHxGIrdpI4 vdflYuWtrEI5AX9ZuLlihNcHTrKi4BM= X-Google-Smtp-Source: ABdhPJxEI8XVbGQwYiTyYNm8t/YAM6yCVevz5ApvZlGf/nMivoo7PDhxd52wLSe9zM5bKqpj7p4Vcw== X-Received: by 2002:a5d:6cc9:: with SMTP id c9mr62675452wrc.411.1609409452677; Thu, 31 Dec 2020 02:10:52 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:52 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 14/16] struct-attr: fix: do not ignore struct/union/enum type attributes Date: Thu, 31 Dec 2020 11:10:32 +0100 Message-Id: <20201231101034.59978-15-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org GCC's syntax for type attributes is specified as: An attribute specifier list may appear as part of a struct, union or enum specifier. It may go either immediately after the struct, union or enum keyword, or after the closing brace. The former syntax is preferred. Where attribute specifiers follow the closing brace, they are considered to relate to the structure, union or enumerated type defined, not to any enclosing declaration the type specifier appears in, and the type defined is not complete until after the attribute specifiers. In the section about type attributes, it's also said: You may specify type attributes in an enum, struct or union type declaration or definition by placing them immediately after the struct, union or enum keyword. A less preferred syntax is to place them just past the closing curly brace of the definition. So, while placing the attribute after the closing curly is not preferred, it is cleary legal (and it seems to be much more popular than placing them just after the struct, union or enum keyword). However, currently sparse doesn't handle this correctly: - these attributes are parsed in declaration_specifiers() and added to the current decl_state - when the ';' ending the type declaration is reached, the plain struct/union/enum is used and the content of the decl_state is simply ignored. - if the declaration is for a variable, then those attributes are assigned to the variable (but not to the type). Fix this by calling handle_attribute() once we have reached the closing '}' of a struct/union/enum definition and applying these attributes, if any, directly to the current base type. Signed-off-by: Luc Van Oostenryck --- parse.c | 2 ++ validation/packed-bitfield3.c | 1 - validation/packed-bitfield4.c | 1 - validation/type-attribute-align.c | 1 - validation/type-attribute-as.c | 1 - validation/type-attribute-mod.c | 1 - 6 files changed, 2 insertions(+), 5 deletions(-) diff --git a/parse.c b/parse.c index b38615b8d61d..338e525f46b9 100644 --- a/parse.c +++ b/parse.c @@ -764,6 +764,8 @@ static struct token *struct_union_enum_specifier(enum type type, token = parse(token->next, sym); token = expect(token, '}', "at end of specifier"); + attr.ctype.base_type = sym; + token = handle_attributes(token, &attr); apply_ctype(token->pos, &sym->ctype, &attr.ctype); sym->endpos = token->pos; diff --git a/validation/packed-bitfield3.c b/validation/packed-bitfield3.c index c06e7c41cbcd..13368c84469e 100644 --- a/validation/packed-bitfield3.c +++ b/validation/packed-bitfield3.c @@ -25,5 +25,4 @@ _Static_assert( sizeof(struct c) == 8); /* * check-name: packed-bitfield3 - * check-known-to-fail */ diff --git a/validation/packed-bitfield4.c b/validation/packed-bitfield4.c index 0342b2414b6e..1a956344f2d3 100644 --- a/validation/packed-bitfield4.c +++ b/validation/packed-bitfield4.c @@ -15,5 +15,4 @@ static int ld(struct s *s) /* * check-name: packed-bitfield4 * check-description: Is check_access() OK with short packed bitfields? - * check-known-to-fail */ diff --git a/validation/type-attribute-align.c b/validation/type-attribute-align.c index d9358bff8327..5f3db14aceb1 100644 --- a/validation/type-attribute-align.c +++ b/validation/type-attribute-align.c @@ -16,5 +16,4 @@ void main(void) /* * check-name: type-attribute-align - * check-known-to-fail */ diff --git a/validation/type-attribute-as.c b/validation/type-attribute-as.c index b40b4e7dddf5..38f06b374e25 100644 --- a/validation/type-attribute-as.c +++ b/validation/type-attribute-as.c @@ -21,7 +21,6 @@ void main(void) /* * check-name: type-attribute-as - * check-known-to-fail * * check-error-start type-attribute-as.c:16:15: warning: incorrect type in argument 1 (different address spaces) diff --git a/validation/type-attribute-mod.c b/validation/type-attribute-mod.c index 0e7b166a4aec..d55011dfa09a 100644 --- a/validation/type-attribute-mod.c +++ b/validation/type-attribute-mod.c @@ -14,7 +14,6 @@ void main(void) /* * check-name: type-attribute-mod - * check-known-to-fail * * check-error-start type-attribute-mod.c:12:9: warning: dereference of noderef expression From patchwork Thu Dec 31 10:10:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1FF9C433DB for ; Thu, 31 Dec 2020 10:12:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC83B207A3 for ; Thu, 31 Dec 2020 10:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbgLaKMR (ORCPT ); Thu, 31 Dec 2020 05:12:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbgLaKMR (ORCPT ); Thu, 31 Dec 2020 05:12:17 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9681C0617A9 for ; Thu, 31 Dec 2020 02:10:54 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id d13so19674071wrc.13 for ; Thu, 31 Dec 2020 02:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hjiJHB3wV4XVzP2HATK56U+TgeS3+lb5sAu2Ag4G5+I=; b=lmyij2dqgsFB+zkd3myTvVZ5whrc5Rxa6fucakzvNCAunJtgbzgiEPPFjhT6aILJCu MMqSuD29sgDaKmGanPex0zT71Uz563I6vpGvjr8wjabrsdNY0M/huYsMNmoyto7OMEj0 JJpevPyghJk36ydUMrL1nmAIhH0+mS0rWY6Yg7FYmxl4AgCD98bJ84/8FJ5RCnuGWz8Y 1smkpzL12DgmuR5kma/hTHQRXZJzjca6TYJLAwRnSxL8woQyfCGmIv7Q5tJe8sEx+1c2 Hx0oUYLPGBrGxrlgnzJmETRwCwxWXoi09NZdatoonx/GnusKjUqOxYFQ1z+6HhBfe5gt Y8sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hjiJHB3wV4XVzP2HATK56U+TgeS3+lb5sAu2Ag4G5+I=; b=IzmvUh9q3zp0VMxk3iZgX68+lv9sJ1dTEpcVU3Sm1XFRpp2gNvr2TaBZCZT+lPXQbs atVTskPDOp5QkEah6ritcujTiEBprjsEf6QhdyraFIjMC3HckuucdSVdhZGVjZLivlEU QR64ZuybN3w7YSpUHkzWoQ7zzVOVaWhQRU5XJennTCuxVbOxv+Q0FXZp/8zxAi1jPORR GFoLQAhLPqleqr8yVCcgeXks6PLhY/04R/enJm9eGNCJEcc6P6jxvL+z0cFnAkzWyASw UEG80MiHI1Z3Y4yJMCeC/7Ndh4PHfQbNAL2y49YbXkBXUa6VZ1oJPQoj4zj5w67Tyb6V dKng== X-Gm-Message-State: AOAM532i5PyuSz1d3metjDTmbzId4J8KnOt2U/RCD02ZNldsXMCsgX44 i7dlGoIAZkRWlJiZLX9Qv5EOwfRm3n4= X-Google-Smtp-Source: ABdhPJz7SMwnuzHaC3AFIUx9iX/vMzeTBtGWtIuHyxzPqOE2+rQI5srJmuIvExAwtAGjgLSHw4riKQ== X-Received: by 2002:a5d:610d:: with SMTP id v13mr64668782wrt.425.1609409453527; Thu, 31 Dec 2020 02:10:53 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:53 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 15/16] packed: no out-of-bound access of packed bitfields Date: Thu, 31 Dec 2020 11:10:33 +0100 Message-Id: <20201231101034.59978-16-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org There is (at least) 2 ways by which packed bitfields doesn't follow normal layout/access rules and as consequence can't (always) be accessed the usual way (load the whole underlying word, then shift and mask to isolate the bitfield). At least two different cases are a concern: 1) there is no padding at the end of a bitfield sequence. For example, the following struct is only 3 bytes width: struct s { int f:24; } __packed; So, trying to access the bitfield by first doing a 32-bit load will create an out-of-bound access. 2) a bitfield smaller than one word may need more than one word to be accessed. For example, with the following struct struct { int a:5; int f:30; int z:5; } __packed; the bitfield 'f', while smaller than one 32-bit word, can't be accessed with a single 32-bit access. At machine level, these bitfields should be accessed with several, possibly smaller, loads and their corresponding values reconstructed from these, making things much more complicated than for non-packed bitfields. But at IR level, things can be a little more flexible and things can stay simple by using sub-word or super-word accesses (until these need to be lowered to be usable at machine level). In other words, the example here can be safely accessed with respectively a 24-bit and a 40-bit load. This is what is done in this patch. Signed-off-by: Luc Van Oostenryck --- linearize.c | 13 +++++++++++-- symbol.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/linearize.c b/linearize.c index 0250c6bb17ef..e80715ab2458 100644 --- a/linearize.c +++ b/linearize.c @@ -977,8 +977,17 @@ static struct symbol *bitfield_base_type(struct symbol *sym) if (sym) { if (sym->type == SYM_NODE) base = base->ctype.base_type; - if (base->type == SYM_BITFIELD) - return base->ctype.base_type; + if (base->type == SYM_BITFIELD) { + base = base->ctype.base_type; + if (sym->packed) { + int size = bits_to_bytes(sym->bit_offset + sym->bit_size); + sym = __alloc_symbol(0); + *sym = *base; + sym->bit_size = bytes_to_bits(size); + return sym; + } + return base; + } } return sym; } diff --git a/symbol.h b/symbol.h index 5c5a7f12affa..866d57522f49 100644 --- a/symbol.h +++ b/symbol.h @@ -192,6 +192,7 @@ struct symbol { accessed:1, builtin:1, torename:1, + packed:1, transparent_union:1; int rank:3; // arithmetic's rank struct expression *array_size; From patchwork Thu Dec 31 10:10:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11993941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35A2CC433E0 for ; Thu, 31 Dec 2020 10:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0093D207A3 for ; Thu, 31 Dec 2020 10:12:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726536AbgLaKMm (ORCPT ); Thu, 31 Dec 2020 05:12:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726302AbgLaKMm (ORCPT ); Thu, 31 Dec 2020 05:12:42 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4EE6C0617AA for ; Thu, 31 Dec 2020 02:10:55 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id m5so19666909wrx.9 for ; Thu, 31 Dec 2020 02:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JGW6FJwES63xtm07iFWxDQNsy+/z0YE7i/K5kFahARI=; b=aRod3xk9euYzMx6gs8ArSIxz6O52q2GHEd3DVXTS12gJ7VpJnt6nRaoUzrLbX13c7Q Uhj7xtEvCBAv79BVgt+UbypfO0x3GVL1gLhO9/w+BcIwkHW5PVeAnW+L1EYbH/Q5yb1u +i9RBkLDJQHjqZJsofjAFI5kFSYXt25vmZbgXsg8W00VgjBiCh9xiZoQPlh1/Tq5v0Mj QCy8VZyls7bAlsww+wkqN/gV+iRucvN+ViHVuHZkpSjDVAF6noxbrz+1HNi4+P2p0MHO SOkHAMzDTOH7wWFdrr3hT1a0NjL1p6WgYHXtc9JAL9F5t8/mHZNdaeWOalTGCDTaSBPr f95w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JGW6FJwES63xtm07iFWxDQNsy+/z0YE7i/K5kFahARI=; b=eSZwuuLnqgov/VBM2xiRHpgl8znKn3CufZCZRCRVhEBvLTA4Kos6XdUSzkNcY0voVd YWJbovxzDscWCiq31n9js3oShi0ulaaDwhK/VkQzqYTTkVS+WXuBlf/eg8Gxdn2BgW9f 8Ba8iCm1KomOai7fTrs6VlhxWj40hafI4cNB8eJmHeWMttJT/kQotLSas9YfNVURl6l0 +bGCz7IpJ+h35FSlVV5pYBkR7QE69Eg1fHqmcWtPonnaOz313GdSbZVxJorTmGqZPzSk sMrLpI4jSRKLMOh0FhoDM3QtGjqA+vyAFexoeqBQZS2mes6ae/u+b1Dg/2q91Y6qZKiS wl4Q== X-Gm-Message-State: AOAM533BYGMLE8FRePyJxclt43GBU3ETdixcLmAlG3ZvOJIk/wg87s4u sxxfByERrsbMyG0TPw2SZeJqAWelAsQ= X-Google-Smtp-Source: ABdhPJw4p7hD+iZXrj7Opn7qOawAZSAmpWCAC1XlB8GfNWXgA7hnaBcto2x6JFRUXC6LWXfgON+2Vg== X-Received: by 2002:adf:82c8:: with SMTP id 66mr63377683wrc.420.1609409454461; Thu, 31 Dec 2020 02:10:54 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:7c8c:1eb2:47fd:b5e7]) by smtp.gmail.com with ESMTPSA id n3sm66161019wrw.61.2020.12.31.02.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Dec 2020 02:10:54 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 16/16] packed: add support for __packed struct Date: Thu, 31 Dec 2020 11:10:34 +0100 Message-Id: <20201231101034.59978-17-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> References: <20201231101034.59978-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Now that the 'packed' attribute is parsed and propagated into the type system, adapt the layout of structures. Signed-off-by: Luc Van Oostenryck --- Documentation/TODO.md | 3 --- parse.c | 5 ++++- symbol.c | 12 +++++++++--- symbol.h | 1 + validation/packed-bitfield0.c | 1 - validation/packed-bitfield1.c | 1 - validation/packed-bitfield2.c | 1 - validation/packed-bitfield5.c | 1 - validation/packed-deref0.c | 1 - validation/packed-struct.c | 1 - 10 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Documentation/TODO.md b/Documentation/TODO.md index 4dc9e63ab207..3f00bb1104d1 100644 --- a/Documentation/TODO.md +++ b/Documentation/TODO.md @@ -4,9 +4,6 @@ TODO Essential --------- * SSA is broken by simplify_loads() & branches rewriting/simplification -* attributes of struct, union & enums are ignored (and maybe others too). - This requires correct support for __packed which itself needs partial - and unaligned loads & stores (wip) * add support for bitwise enums (wip) Documentation diff --git a/parse.c b/parse.c index 338e525f46b9..70be616c45ae 100644 --- a/parse.c +++ b/parse.c @@ -767,6 +767,7 @@ static struct token *struct_union_enum_specifier(enum type type, attr.ctype.base_type = sym; token = handle_attributes(token, &attr); apply_ctype(token->pos, &sym->ctype, &attr.ctype); + sym->packed = attr.packed; sym->endpos = token->pos; @@ -1089,8 +1090,10 @@ static struct token *ignore_attribute(struct token *token, struct symbol *attr, static struct token *attribute_packed(struct token *token, struct symbol *attr, struct decl_state *ctx) { - if (!ctx->ctype.alignment) + if (!ctx->ctype.alignment) { ctx->ctype.alignment = 1; + ctx->packed = 1; + } return token; } diff --git a/symbol.c b/symbol.c index 1a083fb8432c..aa02c8c5ad80 100644 --- a/symbol.c +++ b/symbol.c @@ -88,6 +88,7 @@ struct struct_union_info { unsigned long bit_size; int align_size; char has_flex_array; + bool packed; struct symbol *flex_array; }; @@ -120,6 +121,7 @@ static int bitfield_base_size(struct symbol *sym) static void lay_out_struct(struct symbol *sym, struct struct_union_info *info) { unsigned long bit_size, align_bit_mask; + unsigned long alignment; int base_size; bit_size = info->bit_size; @@ -136,7 +138,8 @@ static void lay_out_struct(struct symbol *sym, struct struct_union_info *info) info->flex_array = sym; } - align_bit_mask = bytes_to_bits(sym->ctype.alignment) - 1; + alignment = info->packed ? 1 : sym->ctype.alignment; + align_bit_mask = bytes_to_bits(alignment) - 1; /* * Bitfields have some very special rules.. @@ -147,7 +150,7 @@ static void lay_out_struct(struct symbol *sym, struct struct_union_info *info) // Zero-width fields just fill up the unit. int width = base_size ? : (bit_offset ? room : 0); - if (width > room) { + if (width > room && !info->packed) { bit_size = (bit_size + align_bit_mask) & ~align_bit_mask; bit_offset = 0; } @@ -157,6 +160,8 @@ static void lay_out_struct(struct symbol *sym, struct struct_union_info *info) info->bit_size = bit_size + width; // warning (sym->pos, "bitfield: offset=%d:%d size=:%d", sym->offset, sym->bit_offset, width); + if (info->packed && sym->type == SYM_NODE) + sym->packed = 1; return; } @@ -173,6 +178,7 @@ static void lay_out_struct(struct symbol *sym, struct struct_union_info *info) static struct symbol * examine_struct_union_type(struct symbol *sym, int advance) { struct struct_union_info info = { + .packed = sym->packed, .max_align = 1, .bit_size = 0, .align_size = 1 @@ -191,7 +197,7 @@ static struct symbol * examine_struct_union_type(struct symbol *sym, int advance sparse_error(info.flex_array->pos, "flexible array member '%s' is not last", show_ident(info.flex_array->ident)); examine_symbol_type(member); - if (member->ctype.alignment > info.max_align) { + if (member->ctype.alignment > info.max_align && !sym->packed) { // Unnamed bitfields do not affect alignment. if (member->ident || !is_bitfield_type(member)) info.max_align = member->ctype.alignment; diff --git a/symbol.h b/symbol.h index 866d57522f49..15b21452c934 100644 --- a/symbol.h +++ b/symbol.h @@ -112,6 +112,7 @@ struct decl_state { unsigned char prefer_abstract; unsigned char autotype; unsigned char forced; + unsigned char packed; }; struct pseudo; diff --git a/validation/packed-bitfield0.c b/validation/packed-bitfield0.c index f84e7b904a82..2e20916176f1 100644 --- a/validation/packed-bitfield0.c +++ b/validation/packed-bitfield0.c @@ -55,5 +55,4 @@ int main(void) /* * check-name: packed-bitfield0 - * check-known-to-fail */ diff --git a/validation/packed-bitfield1.c b/validation/packed-bitfield1.c index 208a3dc5127c..b7b575ce6922 100644 --- a/validation/packed-bitfield1.c +++ b/validation/packed-bitfield1.c @@ -24,5 +24,4 @@ static int foo(struct s *ptr) /* * check-name: packed-bitfield1 - * check-known-to-fail */ diff --git a/validation/packed-bitfield2.c b/validation/packed-bitfield2.c index 4587ebec5c90..244204c2dd35 100644 --- a/validation/packed-bitfield2.c +++ b/validation/packed-bitfield2.c @@ -12,5 +12,4 @@ _Static_assert(sizeof(struct bf2) == 8); /* * check-name: packed-bitfield2 - * check-known-to-fail */ diff --git a/validation/packed-bitfield5.c b/validation/packed-bitfield5.c index 8f44d4c2c277..87dbf9c221a1 100644 --- a/validation/packed-bitfield5.c +++ b/validation/packed-bitfield5.c @@ -17,5 +17,4 @@ static int ld(struct s *s) /* * check-name: packed-bitfield5 * check-description: is check_access() OK with 'overlapping' packed bitfields? - * check-known-to-fail */ diff --git a/validation/packed-deref0.c b/validation/packed-deref0.c index 865ad68a4f37..d48ad1ac7505 100644 --- a/validation/packed-deref0.c +++ b/validation/packed-deref0.c @@ -20,5 +20,4 @@ static void bar(obj_t o) /* * check-name: packed-deref0 - * check-known-to-fail */ diff --git a/validation/packed-struct.c b/validation/packed-struct.c index e21d11538639..dad22791060b 100644 --- a/validation/packed-struct.c +++ b/validation/packed-struct.c @@ -29,5 +29,4 @@ _Static_assert( sizeof(struct c) == 6, "size struct"); /* * check-name: packed-struct - * check-known-to-fail */