From patchwork Sat Dec 26 17:51:14 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: 11990395 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 2856FC433DB for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC50B20809 for ; Sat, 26 Dec 2020 17:52:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726260AbgLZRwj (ORCPT ); Sat, 26 Dec 2020 12:52:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgLZRwj (ORCPT ); Sat, 26 Dec 2020 12:52:39 -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 CF1EFC0613C1 for ; Sat, 26 Dec 2020 09:51:58 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id y23so5686065wmi.1 for ; Sat, 26 Dec 2020 09:51:58 -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=vf/seq+nlFd0+4mHYS+UD7twUdJ9+p5i5AIEmDDKy5vWxju+P27uZU535sGdjMUSk7 D4jg7f8R+mQrM01HGh3dPDEH6deV7bZvJTc6NEH13mk7RaALUhDJbwVl3lF6Mc4auwQE 6n/0EbMykVVI5MCCdbpf9zNtDFLznAnSPEIhh0uJYU4A8Tvuxdb7Pdz0Rj+CaVv5qrK6 mJGzkSMj+HYKOQvoAYG7dV11+TSNihXoBJs5vDqiI4FG3yMG3PWlVkiqXIhOL1PGlEnw 4261/T8je3U7P06z5jnZq6jt7isYMNxbKpcNgroycoZy1Vsfd5iW/nZTfrmu10Pnyy6e QJDQ== 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=nZz7gWUdu8BGQO/PI7POpY5LS9bpcDcqvlRXtUi+2HK35RoqUw+iqTCW1f0buuB87K P6jO1YO87/Wd8a1Q/cw1PAo7xS4nLsv88ehSKGlIEclUCaYltryGN/Oy2v2WfMDGgpvd ZwM9MLH7OwpBGOkEiYxn3nNdZVaP1E858NZIvBWTV3SccGwttPRj+zr0TCmUtKH8Asiy O7+f8YnEJCcjI2Ioy051e5Wm6G2J2SB+e0XvW6UA5OE/WMETozP3QOL/skx2+7h0Pa7t ucQQbcQLJlbvK44SXdKnDTYamp/E9xT5LnNP3Z4GpGBCjnyetVzfz/ktjbgDRDu7JDUR ToHg== X-Gm-Message-State: AOAM530hGQj9e7RUuJCfwHouFIy3zbbPszNfcgFcIRJqzKDU7SMKE/9b 4VX9R0b9yOHoc6iVBb2HwVHv9M/6Wlk= X-Google-Smtp-Source: ABdhPJy7Nq+6eJUWygtPLSSTDlVf+459EcExswAIAUA1Vgf7Z4hUAaB9qCcANj0z6ICZvqPbx00E1A== X-Received: by 2002:a1c:cc14:: with SMTP id h20mr13360105wmb.180.1609005117605; Sat, 26 Dec 2020 09:51:57 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:51:57 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 01/16] add testcases for dubious enum values Date: Sat, 26 Dec 2020 18:51:14 +0100 Message-Id: <20201226175129.9621-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 Sat Dec 26 17:51:15 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: 11990393 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 3F845C433E0 for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DB77217A0 for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726309AbgLZRwk (ORCPT ); Sat, 26 Dec 2020 12:52:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgLZRwk (ORCPT ); Sat, 26 Dec 2020 12:52:40 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A088C0613CF for ; Sat, 26 Dec 2020 09:51:59 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id g185so5679987wmf.3 for ; Sat, 26 Dec 2020 09:51:59 -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=igYkLeqnIXBYQCR9l8FdXDALCmYdO0nq7AGpxF7L7EU=; b=aom2lx6vE3/2MHMas+7kDLos0C5GiV6kP5teojmDbbyrpI+Pjp5TLIq9B45HVRhKrx y81UKH63hjhDvzTWr7Xp7fOiLmXgoJWYyVSudMN25bsQcsBNGr7DPd6GLwy538KfTo1C 5+eWYpAZDWKJ+7KB076pnsPsrTmLT6Nwfxiy/7Ui9jBcjokE6YpW5qWB5cPuQ3iV0spT Oa3w92KTNctlM0EgtrlD6ocm5ZGUvt9J1V4W+CrKR3uYY7VkGmo4J29W3YGiYfEn0lMa JuNLz1Ppn2uAi/+vuVLowGYCmpGOharuyxY7ORqlh9WRTlfhqkptw69MIHZg50iMeDzP DqYQ== 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=igYkLeqnIXBYQCR9l8FdXDALCmYdO0nq7AGpxF7L7EU=; b=AQthCIZTR7DaR8qrTqiHjc4vvv9W4l/5FDyL61VtaJouXhyxC+tNgIEWS5n8Uj8dg5 lu3c17xxdbmXXWtp//lYnCi0SSKWyagl9OHe1oayzTVpB/TSTKNwuM18+mXngcfaxZWh KRrte/vQJP7wwvYyzC8myL9GQbP/60xet9UNjQj9IJwdgOurMIccXLtygAnPx+pFS8Dm 0m1xsJrRZJmEGnOpUFJTc04WlRn4NYw84U/KC39HNGKu+q894rItmW0x1JeYJAuR+KoB HU1IbWBSLraejTFDenr5E5VLDls/caXUDY9n7PrbSf5YYgqbIHEw16ytOTDvxu0d3Tgd 0vRw== X-Gm-Message-State: AOAM531gO4hY+RV+ukw4cXcdOaR/mnNDJbdNWgyZ8jsFsFatGaWRMdvA rPY/RJTMFoEaXdKqKaUfdlx2q8IToao= X-Google-Smtp-Source: ABdhPJxnAXUdNw3QMtDzgs9RV2T3LYw/QJlGo4XaUXEV7TMgnSArpqunUoTnE0slpZK540xOS3FQcQ== X-Received: by 2002:a1c:7e02:: with SMTP id z2mr12817978wmc.173.1609005118388; Sat, 26 Dec 2020 09:51:58 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:51:57 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 02/16] add testcases for exotic enum values Date: Sat, 26 Dec 2020 18:51:15 +0100 Message-Id: <20201226175129.9621-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 non-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 Sat Dec 26 17:51:16 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: 11990399 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 508CCC433E6 for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 248762184D for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726340AbgLZRwl (ORCPT ); Sat, 26 Dec 2020 12:52:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgLZRwk (ORCPT ); Sat, 26 Dec 2020 12:52:40 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 684A2C0613ED for ; Sat, 26 Dec 2020 09:52:00 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id n16so5231855wmc.0 for ; Sat, 26 Dec 2020 09:52:00 -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=paLtGJVTOK8GtVybkatpET4VERrgue0kK69XVdC7rShJ3Sxo+vEjygPSkN0euFHQn/ K+YJ0oxOlsm41AEjAC+6pNazzP29+b0ivZEcVwq555ZBaXVPf/x4CEYHj1OD9n3LoYUd ABJVGAsmuNGnyO4580S5hnzuecRrVkcoETp5BfCRoKiBbiLpTEGJlsJTxS6EVI7bz5fa QGZpZmRUh0ZwYB5OXDHJKRfqslJi2IsQlHib34zxOn6v6s8asNoQhqpYmbUoNjLa1mrG DnlUlsUVkcsIkbgZvqcEp/Rs+uUThpGvuLXwcNQe46dGZNE29XPrztTc/uuLMn7HzQ19 R0Vg== 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=CZQ5hUW8x+vVEjQwnPId5nWClcl/KRqEz46V7//TIDUDx6TONnJ4prdZGeYF3gfRC0 YX92m6BvYt6ahHDANkh1M72I62va4nDEqIgKWl4ph4EuNyUzMEWRtUsA2CrUwRArVILJ FROgdpghIgiMxmsr12BJso90jhQ16bAFZqMxgRj16eHj9rBkmNmuWT6/4ONIi0is2COI oD2I+Uxa6yKapngKNFciIWuP+V8hBjqmLDq9vqI5K9xBZpN4ZhDMa6OzqsCiyi/WNY77 /stM7uV8nV60vUpcxySMGQizfPZzGt9HLmlcemxbleNqK7TSnuQU8scw303QMo/dEVt+ 2vIg== X-Gm-Message-State: AOAM530L9XEU3UmVuD+EYgUO2bJecRwWb8ireqJ9F/Qup8vlv072Aw1f LRFPaAqYlyVchqvNjw8SF4NCL1rSS4w= X-Google-Smtp-Source: ABdhPJxqowhv0bciuMyRqyhxZNYuCiKFMrFk4e8Qly0/Lh52J67DCVdriByHIxR/RUItodGy9gd9bw== X-Received: by 2002:a1c:9c52:: with SMTP id f79mr13223810wme.3.1609005119221; Sat, 26 Dec 2020 09:51:59 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:51:58 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 03/16] add testcases for enum attributes Date: Sat, 26 Dec 2020 18:51:16 +0100 Message-Id: <20201226175129.9621-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 Sat Dec 26 17:51:17 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: 11990397 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 60596C433E9 for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3819220809 for ; Sat, 26 Dec 2020 17:52:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbgLZRwm (ORCPT ); Sat, 26 Dec 2020 12:52:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgLZRwl (ORCPT ); Sat, 26 Dec 2020 12:52:41 -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 48A7FC061786 for ; Sat, 26 Dec 2020 09:52:01 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id g185so5680021wmf.3 for ; Sat, 26 Dec 2020 09:52:01 -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=qJbIGhOqDBsJ5wzt+ehYGeYpOmYaV2Urn+P67g4E58E=; b=tVkfOuaZkXgngzgMIiBDUPbvop5qE/4mXXKNS+v1NIuGSHwCcX9kvbKuajXQT3q4Ql bZ917LLQl37fVKeN2RpEx1Fhub91ruhGBieSIV6l1hxW+n/hutOoACub/9FNI9J+K8VS bNR0XblbIB+V7x/2r8nFH9h0jelc1aLsSA/OLq/oZ0yzR0ywzoVG4MKGULXWSIo622XI Fz+qz/YrDWTgPBcyuiW43fJfsTd9QOvhun/viFRLWwvNeH9++YViyL07Jq1u/xzYNBjB p6TD0VGewoVhGDL71D1Xp0lsjFfNIA3NiMPKWKgWuGirfyoG9X8Yp9Rg6AEAD1fz8udm ZFpg== 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=qJbIGhOqDBsJ5wzt+ehYGeYpOmYaV2Urn+P67g4E58E=; b=YlN7y1crphJ5Si+b9XAtN6fOfw3x8ZvmfgakqJbKzGEoZz4UxMfgl/2tBNoFtUB+9G GxTGWo0da4I86OqKKMQWOT2euzb1uqG4f092zctqyYMaCUEELfJ8+lW6pu+BwoPiYkp9 Ukwqry/bm8Bco/dcsGDJmFSomy/iCJGLrjjVLI14lsFq1Iz3WUDlyX/7/ssde6IK8NFe 1rvzrK7xbrsdxtTphmX4qmWJzpgL+UfpTreyqLiyIEq4I93DoNBhoFLz5i/GDL88cmei qU/jBxTs6lTJfBXC8pOMq+PQrHGNViaxHLB5Nh2uETLpkMKVHX/ElIr60uEeVtY/HxT5 /2gg== X-Gm-Message-State: AOAM530AnOWB2ZksAe9xDrFG0ifEPpZd87DsNEABae4Nj6+IC9lkOtHR 2dUfqowx4dWEzX9ckjx6DObhBxFoaa8= X-Google-Smtp-Source: ABdhPJxXdpcu/o4W4bLRf4RFMXBTjQjHfU78SQK4C8+BfGeSLc85HefhQSEoEufbOumQ7feJQ/p4lA== X-Received: by 2002:a1c:4843:: with SMTP id v64mr13260984wma.186.1609005120041; Sat, 26 Dec 2020 09:52:00 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:51:59 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 04/16] add testcases for type attributes Date: Sat, 26 Dec 2020 18:51:17 +0100 Message-Id: <20201226175129.9621-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 | 12 +++++++++++ 4 files changed, 88 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..ab19a605bda1 --- /dev/null +++ b/validation/type-attribute-qual.c @@ -0,0 +1,12 @@ +static const struct s { + int x; +} map[2]; + +static void foo(struct s *p, int v) +{ + p->x += v; +} + +/* + * check-name: type-attribute-qual + */ From patchwork Sat Dec 26 17:51:18 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: 11990401 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 2691CC433E0 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F01FE20809 for ; Sat, 26 Dec 2020 17:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726257AbgLZRxT (ORCPT ); Sat, 26 Dec 2020 12:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgLZRxT (ORCPT ); Sat, 26 Dec 2020 12:53:19 -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 01A9CC061794 for ; Sat, 26 Dec 2020 09:52:02 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id t16so6688261wra.3 for ; Sat, 26 Dec 2020 09:52:01 -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=icXzXvx3BT11l6tSnQMP4QrYjTiQHGS0ErGys3blexM=; b=ibGtxwvURXZsy65MSrIJgfNLckQu6Vu3k89Nf0RBqAJq12ryy+FWxnypTtRy2dMoIL d5a9tkeRja/sZKtgZTyY8xumE5NnaL82xlK2n3tnPRoli6o6w5GmCfvCUzNFnx5gGxd1 70N/8jmnOwfsQ4WEtMo3WehuDvcD6G/KiTvXT4WynsSFGWhCdxrOe4y3fCyLbVK/RX5t +2keljsyhu14Yv11HA1dn8ddim+6Hj+i7+2MATVo2KEo1bF7Zgc7mm0na4WMjiM5U+WK sYgIL61z/oi7zUUe/GW8Xal6qbloGisIn9BjL0MKQSHGvJlWpRsP1AOaWKn7a+++6TYn REaw== 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=icXzXvx3BT11l6tSnQMP4QrYjTiQHGS0ErGys3blexM=; b=sJYswFhAPWNH2PNzXb0YNha+IUog7NhrFfb2O+59gP9BmnUOyst6/vqXoHP7XLTLqm 28WARHD+m0VEC0wSucJSh2X5L8pSEHdhb47pysdzERCpBgBpD1D8d8aN8EIM1038cYF6 8nv5hUCjhK9PUlQa/8CfEAbNwHgTy/GMA1dCHYwTXsLKH/d0VfzpPyEX1B/DWZelpvQA RAD1se609n39YKn9Fs94WLOdIygHLukO70u9qFGHquMrsGOL+dr5Hhzeolqv4TWbgB1Z oOGFnd0v4ZaRNySJUHNB0z6hn/nenzS9vUHjqcvFyOLQTuj2/QTHUgUFpqkyYFoxxyud bu1w== X-Gm-Message-State: AOAM533FA7MKF6I4Sfv77BvCNbRx4AgeFcoW7scfHTWUt3lHa9wqGcwc jIbYAsFYN4g58vDPxrQ6Hw43z2Me1HE= X-Google-Smtp-Source: ABdhPJzzpZUgl43V4NNivJ08Ck3G3zWn0s6GtEUI29T81IeZLUJOL8LpeO1G2GhiNV9DRHcDi+X63Q== X-Received: by 2002:adf:ef06:: with SMTP id e6mr42845117wro.231.1609005120808; Sat, 26 Dec 2020 09:52:00 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:00 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 05/16] add testcases for packed structures Date: Sat, 26 Dec 2020 18:51:18 +0100 Message-Id: <20201226175129.9621-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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..5039be4d0b45 --- /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) == sizeof(u32), " 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 Sat Dec 26 17:51: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: 11990403 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 42D19C433DB for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11D1B217A0 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726167AbgLZRxT (ORCPT ); Sat, 26 Dec 2020 12:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbgLZRxT (ORCPT ); Sat, 26 Dec 2020 12:53:19 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F308BC061795 for ; Sat, 26 Dec 2020 09:52:02 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id c133so5767444wme.4 for ; Sat, 26 Dec 2020 09:52:02 -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=FsgSSJ3L+SQlgN20WsY0uEPVgxCYkCt7Sgya9wWuCy8=; b=h1Z2CUTBPf8uJwFje3ROMuDSDofKBgWr8/8zPJi8iIBGO1/00WoA+MTkjhWPvlfLBv ao03ZCqYnXGQ5DE8wKI/KbZv3Bd3P3FcG8eztsHGLsHoOssvFQLXJHRE26+Zd8o9U6bj N8dG3LO/48Zj60Tqimd6lflTvRpBkXjlPcCzKUJ+RzwP8ALTall7Q7bZHNnmajexDapf yCbCVNpEY0vSwMlqIO/zNicHWLv7Rteu8Aw+KsO/AV57D6QCOwg+65Y2rqHKRaZnf6wb FEpKo3S0yb6lJYqpNtTqR9hYOhV/WadTeq3xtvM53NPWOPYCsOdykJSefJflbmRe5RoI petw== 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=FsgSSJ3L+SQlgN20WsY0uEPVgxCYkCt7Sgya9wWuCy8=; b=UZb3T6c7X1zigUcGdeuxy4v/EKIHhgC9vPpCUa0J/oLxUsAgigIbosJW7VDKRY+TSG 4lhFHB1PzbO72bZ5U2l10Gw+rl6SlYfWciz89bjKRychs3oaBvjiF9ylwxJwkQoBqt7B 6PDmOIjnEMIxJmtrFrQ8m7P5VuvLZVIB/lbDEl5Q1LFx3Gjtqa+UTvOKJ9H7gqTioV6w sEVmbJbArL2he+yyM9h7trAYovXZ/ctniVMdrNgI0WTzmOW+B5H2eqEXgLUdgZotu+lR D6FrVSWK18mBz6ZS8kO6cC56NwMqaYEhdFQqE+y7JeyEEUg7EKuRwmHud1yJhwcG+i3q UrLg== X-Gm-Message-State: AOAM531CL6/lSaRL5wUhOIaOIFgPb4V77QjbFY4DvE7k9UIS/uQWlSpb TzZqwj5OQbafKSdO9i8eKdFLB7tSAec= X-Google-Smtp-Source: ABdhPJz8q2Rhf/YBbLso5CV2CpPDK4P9TkeCDPHMm4OyCn1NDpa/IGdxeI4RNPzHj7NG5Y2LBRmmCA== X-Received: by 2002:a1c:4d0a:: with SMTP id o10mr13603106wmh.185.1609005121740; Sat, 26 Dec 2020 09:52:01 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:01 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 06/16] add testcases for packed bitfields Date: Sat, 26 Dec 2020 18:51:19 +0100 Message-Id: <20201226175129.9621-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 | 67 +++++++++++++++++++++++++++++++++++ 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, 180 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..907500dedbf0 --- /dev/null +++ b/validation/packed-bitfield0.c @@ -0,0 +1,67 @@ +#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)"); + +struct __packed sb { + int a:7; + int c:10; + int b:2; +}; +_Static_assert(alignof(struct sb) == 1, "alignof(struct sb)"); +_Static_assert( sizeof(struct sb) == 3, "sizeof(struct sb)"); + + +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..6acff875299f --- /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) == sizeof(u32)); + +struct c { + u8 a; + u8 b; + u64 c:48; +} __packed; +_Static_assert(__alignof(struct c) == 1); +_Static_assert( sizeof(struct c) == sizeof(u64)); + +/* + * 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 Sat Dec 26 17:51: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: 11990409 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 74087C433E6 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 477C020809 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726240AbgLZRxU (ORCPT ); Sat, 26 Dec 2020 12:53:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726194AbgLZRxT (ORCPT ); Sat, 26 Dec 2020 12:53:19 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09FFFC061796 for ; Sat, 26 Dec 2020 09:52:04 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id q75so5687657wme.2 for ; Sat, 26 Dec 2020 09:52:03 -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=oNutV2WpPqjay/6nt3epmXo6db4L3gkj7RHWDVPxN1fa7xJ/2sQUISJEUQY7RPwuaZ UC/stzGW1Aiddcat5EVI/vL9p74oRK60M80nyB+8TPkKLCUKqDdb2USbpifdtukoxqBr hWXwVXGCGm3aZI+0YKJsK8pKOI+HLug5wDTDnPxGvbjJumjK3v8xjM9xDwUbQKRoZif7 Iet2/meJk2w4eiblSC0H0J2eaRq6SqVBfv9tujE9gkCFXASCOoM1JJ67gB/xCRcE8k5S +QGSaVChkfrSmm3rIXPVdDypDIFEFBq6MCPZyagAHbFfZBgIsjehozfuW0UsaGrPuupo em1w== 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=OjZBZe9fb7UY0fqb07Q8DezG8pRPXpYz0CxrZ56a6OHs/De+r7v5L1WaYc6IBNPZl2 yvis1OcZm3xcDY7wNJfBuKs8daeaqECO1pmUbJ3DQ6RuDiIFMEA1HmyRmyxXzGjogQ1U 3uy6YRkQu4qeLRnWit7/RPV22GQLOyxYQiYg1whA5YNTxlXX5qnH/8CZDjhkWjOxlp3l Y8papujT4mWSKcNY+GFkOTcSd3CPHLk+MSUEBLRhK2ihuhyWWSqqY00SjZwAgbyyy95r W795YcPnoOY4e7SLE0YZybTahAwjRHECQR4sZxdBzEfK3TOPQy6TvIL/3fe7ljABwlvC 6dwg== X-Gm-Message-State: AOAM530x4pqw6o/Fit8By9tH3f8qM7g20lHAEyU2rG1L2odM8TM/krTl 4kHBUh7XWVpYcBqSEhic8a3Q9mFK++Y= X-Google-Smtp-Source: ABdhPJz+6k1kJhowDdfC+Fxrzt6541ZgvEyCbBQEvkZD+41k8aURhdDe1Zx0RLouMbSaw/zywwlITw== X-Received: by 2002:a7b:cc16:: with SMTP id f22mr12861803wmh.131.1609005122843; Sat, 26 Dec 2020 09:52:02 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:02 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 07/16] apply_ctype: use self-explanatory argument name Date: Sat, 26 Dec 2020 18:51:20 +0100 Message-Id: <20201226175129.9621-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 Sat Dec 26 17:51: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: 11990407 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 9DD26C433E9 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D36020809 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726194AbgLZRxU (ORCPT ); Sat, 26 Dec 2020 12:53:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgLZRxT (ORCPT ); Sat, 26 Dec 2020 12:53:19 -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 0B17CC061798 for ; Sat, 26 Dec 2020 09:52:05 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 190so5771064wmz.0 for ; Sat, 26 Dec 2020 09:52:04 -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=Lipu7i6g9gAO9jeyCdrMofgOVQbcXXikXSs19rjetAo=; b=nYuEO5fgnVqC3SH8l5inv3iZkUw+J4v6d16TdUGHsPz/z9BZwod+sM2HgqonIunr53 5CDe4UjrBK/ZlfIQRcfhAjM+5w3hnah8/4G/RU7ES0eKh518Lnphv+RawcRoBIVAoyMI SVV8MueRg5mu0a7AcvOYaA4M+O96tJ0/qI29XgKJgRzvDflH1u5aOrWq5ozviktY3fM4 ATn6fVcMYsrll2sNnC/979CECxmozljKzQqZ5LfYTmh5e9GIo9UgejP1Wh67QQOnAmlA 7GCDxqmpB7G0o6DLy3Yuy7ImXKMQByVQ3CXPyA342UbPqAgv7dbRA39JY+2blGpXBtJs Axrw== 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=Lipu7i6g9gAO9jeyCdrMofgOVQbcXXikXSs19rjetAo=; b=YnIvoJyo/JXglyvMCb2w/uDzbp6Ge3FE+T3fM1fW2ogP/3orD3DaOQVktlRdkE1zoM h5UgvR/ogxxvLxwigsk5CFd2qI3mu/ft+Y70tJLUqKtzQ8Hu7nqV81o3f6b9aubr+/bR bUjWeP++a4pWEZL+tqny3SyEA+u7i1duOjnWuG3tGteZh2uvIvPQz5+nnS66reMS24er FmijzB3YgbKNt3VqNZFVCHMHLsp85cBBsFD8dUEM+g3u65X4QvCeBaaQDoTK0wXYU57G 9B1WEzbJRX0ijbuu+b+G7mLhI6S743BYE32XWeV+ctf3L2JuLVa2PCq82N3Zk+SIBEIq gdmg== X-Gm-Message-State: AOAM533eflp8v+YrgNj93StRg0jv06iQyEYRWXULbFimNafEfQGv2YYj BVmjjvdTFWwIznIvPoIAOyTOkumf7rw= X-Google-Smtp-Source: ABdhPJxreeau2Auu40DZV1/gXCr3yzVk9zWKAkH8hps1GEwMIcZXs0hVOABfr/hN+F5YzfJ/52au+w== X-Received: by 2002:a1c:6a0e:: with SMTP id f14mr12936160wmc.102.1609005123882; Sat, 26 Dec 2020 09:52:03 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:03 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 08/16] apply_ctype: reverse the order of arguments Date: Sat, 26 Dec 2020 18:51:21 +0100 Message-Id: <20201226175129.9621-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 is: src, dst (so the reading direction) but the assignment/memcpy() order is much more used: dst = src; memcpy(dst, src, n); than the order here is confusing. So, change its argument order to comply with the memcpy()/ assignement order and stop the 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 Sat Dec 26 17:51: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: 11990405 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 2B34CC43381 for ; Sat, 26 Dec 2020 17:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC98620809 for ; Sat, 26 Dec 2020 17:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726317AbgLZRxU (ORCPT ); Sat, 26 Dec 2020 12:53:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgLZRxU (ORCPT ); Sat, 26 Dec 2020 12:53:20 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E847C061799 for ; Sat, 26 Dec 2020 09:52:06 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id w5so6645712wrm.11 for ; Sat, 26 Dec 2020 09:52:06 -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=HwDpxD9g2Fw2z5k+PWU8UwIqbnlFbhoVL+VkCuoyx2l5pShQWSnOl/GF6LlEtshfPU jg6k2Nk9OHHWCppvUvRvobSXFxhPCPbih2CJExJaA6fyoZYf3HuDGUNrfxfUhvIeSvfg CdJy5Wvroi0kX8fbI6LudjAM1QNJXJLuPd+5VTEtE6v6wKNIqbdb+I6MmuOswwlYrv4X AKXWXX4GHIOSSqSvVa7Yj4ZKu2tJeIsrgs09Yldk69rD41Gkl0StJGyT8XLcJStZYRxF 2KK3DfVJBWUxb849eqfe6ypzwmsJouDRN5RrHDC0RxBIQB8NI714ExmK212oWRirOEVw kR8g== 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=WZVZ+mLYrUA1gz3zUcxOXilbNBC8RLfSezfC2Y8CIG/feBgX3a35X1L1cd4e7Y5kmk K+H1AakIPVEyEuyKimrN4xG/ms6X6ov+q9ooFoMzNTMpzHJ5KDvAn4XJf0rgMvGc+XEi PCnlQcnQU0kC+BYb9+zbJz22KxC94dYQunjdM77Wbf7JZ9b6QvAbeRr0XOSAy13C/VCd uQRv6UPcNSdh+/4eLZpTpp3WUKQ2yVudWfMV1uV4NYQVe8JWBYGzANRWUH3HegzMHNC9 u1znLZ1ekTNf9a4uH6rN1FqDHLwqOrNynyyB4W4+RFiscQIlqnAAhQfctHSRuVQlwG5z 6AJw== X-Gm-Message-State: AOAM532CmnKMY+RqcDKgkJjX4+mVvCZafNEV1DPP52IMWlBYRDY/u2z8 Iqh0ph37tANTpFG78M3kGypB/I58C+0= X-Google-Smtp-Source: ABdhPJxvReHJAPSfkGOF5E3XaRdnZbwxevhkciXYjusB7McU+Zx4t1I4W6ForQevWsvyjETnNc5IZQ== X-Received: by 2002:a5d:6a83:: with SMTP id s3mr44643262wru.334.1609005125045; Sat, 26 Dec 2020 09:52:05 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:04 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 09/16] apply_ctype: move up its declaration Date: Sat, 26 Dec 2020 18:51:22 +0100 Message-Id: <20201226175129.9621-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 Sat Dec 26 17:51: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: 11990411 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 CCE01C4332B for ; Sat, 26 Dec 2020 17:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1F0920809 for ; Sat, 26 Dec 2020 17:53:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726280AbgLZRxU (ORCPT ); Sat, 26 Dec 2020 12:53:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbgLZRxU (ORCPT ); Sat, 26 Dec 2020 12:53:20 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11AC3C06179A for ; Sat, 26 Dec 2020 09:52:07 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id a6so5764176wmc.2 for ; Sat, 26 Dec 2020 09:52:06 -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=2FwEVZF+/371nFbgxzz7i1U9JlsSybepMtcnC5zhALk=; b=DFpoMFZJGyKSkXdzS8mMU5EyWU7PwOKjSB7asn9R1PvYzk3+fgkuVG1pOPX+dv8+Tb xne1MhSjAQA+HnMMcZQqFUNqS5uWWEtMs4GPXkjewYBfbxfcWFGGkXRTSPZedrmVzwlo 1nJBFJoRhUNldmYN9dgq76DnTo1mETaJXuVN9dZJPmSvnumAi85BFDyk1/7lqznFSiUf cmsZ+vkQi3+3z+u9c/wBnc/xuWwZ1pFy7LnOFOlUN6SN2EPsrbjI29WD8zuUgy4gx94N iE8rha+djY9Zz9djKtLxhVgbbk39noNIvkQZ3ZsxbyMmYZX1SCFkjS9GUrLasL8ooU9N VlNg== 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=2FwEVZF+/371nFbgxzz7i1U9JlsSybepMtcnC5zhALk=; b=cGklDL8OgF86DFkd07CXEoz+9OYzYYWjHdwh0mmMucS27E6WehKJ1z5tLHY1Il+WSX PuCaD5tnHkSoXrBEgxvHYghe04FHn5g3515JvbhdlB0mutqDxG/mzwNIUdKrpXeKQES2 DWbHBzaXd5JkxECMDXTqJ57DrXdLX6gUOjZbvOcBk6w2C95k4RyJJjGoX/bPAyDsbckQ WpYkV67gkSthC9vYW7dp/w4IZrgxlcnw6eSaRs4UiDIn8P/R+imzJMt4nwDNcRaLrzZK tmfgR0VhB8FNhbLICmIAa+tgAvObqOtSkAZCDyrstZeY//bQRY/O8G2/vA1LWCtnjmpw SYmQ== X-Gm-Message-State: AOAM5330XqlP7q6FpJVnFw19g/Jja5G6EOlLyGggRhTWmvLmJex3TaUY 2IRIEYGffI0W+wWx83ds0RsECE+4H6w= X-Google-Smtp-Source: ABdhPJzAnzse3FFBNpprinwl3KyO9vCETF1X12+ZYCeEgmQniOSMUA6VX597cbFYZD8AYp7740OEwQ== X-Received: by 2002:a1c:87:: with SMTP id 129mr13126035wma.183.1609005125884; Sat, 26 Dec 2020 09:52:05 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:05 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 10/16] struct-attr: prepare to handle attributes at the end of struct definitions (1) Date: Sat, 26 Dec 2020 18:51:23 +0100 Message-Id: <20201226175129.9621-11-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 | 11 +++++------ validation/parsing/enum-attr.c | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/parse.c b/parse.c index d6343f0e48bf..99d810910dab 100644 --- a/parse.c +++ b/parse.c @@ -745,12 +745,7 @@ 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; } @@ -763,10 +758,14 @@ static struct token *struct_union_enum_specifier(enum type type, } sym = alloc_symbol(token->pos, type); +end: set_current_scope(sym); // used by dissect token = parse(token->next, sym); ctx->ctype.base_type = sym; token = expect(token, '}', "at end of specifier"); + + // Mark the structure as needing re-examination + sym->examined = 0; 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 Sat Dec 26 17:51: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: 11990413 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 53A31C433E0 for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B76D20809 for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbgLZRxW (ORCPT ); Sat, 26 Dec 2020 12:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbgLZRxV (ORCPT ); Sat, 26 Dec 2020 12:53:21 -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 EC542C06179B for ; Sat, 26 Dec 2020 09:52:07 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id 190so5771138wmz.0 for ; Sat, 26 Dec 2020 09:52:07 -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=hbPRwlT5cGx8c21eE81qDj+4Hc+ScoAnNDKmpU/y/wc=; b=DbJ/3xDPVo72vrIK6kN42ID7fpuL1ug9b7ViAUMHQ1fU/5oYglhhh37kleyY7piFEh S7qSxCm+M0kewWFo292408b4KBrXtuoLinmzCSk0ZZtQiNeCtXp5csYHiDdn9tUhzkVG WXCd7HBCFlYShyUdUVL9rgvw40rXo0k0L6pC0EMEdvau85xPByNkO0OQ2JBaG++1+npm np/RS7yvI7/tAWCX+rzsyLV8kJiKDGEfWzglYXI/ocwKBiEM8tyI8UUvLzWdJfxmBk6W LeCgjDbMU2Ncgb+Ty0I7VDlKmhJPRjf2ToMuTmcdRBQaVm0R671gXPqyRlP4JnGm2kTa HKdg== 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=hbPRwlT5cGx8c21eE81qDj+4Hc+ScoAnNDKmpU/y/wc=; b=laYjM8rgkoB8Vumeu9GKYKHxSf7jXnNCILfEsID+ReLn2klyzFF1SGHM8/YTEHIWgs OB0VCRH/Tdk6ezLqITPuzjHlEN0DosQeYV5gbMk9wuN1QcJ6ElXmcieKVdfgMVCwB7ca eVszWr4ESFueILTNTOfzy3iAfDZQ22asOJ2O5BXbG2I48SIfLGoLtNLQ9PxLV5CnaDQv u1SU/UOHbG4VaqM9cw+rPpSymZgLLEfYXBzkoW/U6CAfcoRUf/MM/dQuyf2y0UmEiYZK sRKQmzkzdA5W2pSvJtHuOb+EvWiYrVIDN05afUcFUGMBX93Bu5iZJebQy0Z/+l4TFLiu 8u/g== X-Gm-Message-State: AOAM532TprnKahqlA4qf49LvvOTl2N/7uVQnEdtV7Q7h/t0+v+3gLE53 y/iid5GEtuFrAo51rZMari9UN+dA57A= X-Google-Smtp-Source: ABdhPJyQoSYU0D9HXostMCpZP0VV7d/vhOpeymVelKvs5hsy1gCygz7/uwzEwU/BbYIZwx+p0mrd1Q== X-Received: by 2002:a7b:c10e:: with SMTP id w14mr13162761wmi.161.1609005126797; Sat, 26 Dec 2020 09:52:06 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:06 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 11/16] struct-attr: prepare to handle attributes at the end of struct definitions (2) Date: Sat, 26 Dec 2020 18:51:24 +0100 Message-Id: <20201226175129.9621-12-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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. --- parse.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/parse.c b/parse.c index 99d810910dab..a90dcf7f7e4a 100644 --- a/parse.c +++ b/parse.c @@ -738,16 +738,16 @@ 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; - 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; + goto end; } // private struct/union/enum type From patchwork Sat Dec 26 17:51: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: 11990417 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 6922BC4332D for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4571E217A0 for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726290AbgLZRxW (ORCPT ); Sat, 26 Dec 2020 12:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgLZRxV (ORCPT ); Sat, 26 Dec 2020 12:53:21 -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 C27C8C06179C for ; Sat, 26 Dec 2020 09:52:08 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id n16so5231964wmc.0 for ; Sat, 26 Dec 2020 09:52:08 -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=4bXVie8ybNT/p+UjZ1bhJZ/QIq8btroN1ur4QMsVIgo=; b=QbKAH0l4ZEF7zXfdoaXl8NV/Rpng9foXgTo5hWDOJRMoR++0td7UVQLs6viQeUofTu 5M4Ys+huaCM0acTLlMEANIXKXB5BlwCI2OY6OBKa4J7H4Q4N+Xan+pAA6FhK9sbMsgzj VohEodHSpKXd7nNWGU482OX8H5pQDQfLn5YKmmHYt2iLLoGmyKvPBqVqfuiUUuf+hnpT Zb62EapW9s4e60zj8blkkeAsS/EBOJFTEmAdy4ZsU5fGcmz4XntO2/6TPOKrB5AyVczE 4qZ7Lb4xwfeCToIxqshPeN5M5PVqCoOEXqiGRrCNtiPpjZmiTuvzyJEAGS/yUMpYQcAB LWUw== 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=4bXVie8ybNT/p+UjZ1bhJZ/QIq8btroN1ur4QMsVIgo=; b=NlwofB0ZXTNCKPNsUlHrMfINsek0i7tEdKHJJHwVNUzE+Q9e1OPRtzc3zugWMQE68r giHUkRQxxWEEXH8BwxqWM1SVaZeCzOq/fZ2gxkTxVC4NXe1izpRMRKYD5lj0GOY1L92k rsOpBTL97mliCON1xB6YySXnv9qhHnyZ5ocg4fcKmXmepzVPq/nzqu9SN4+knGo1Y8hL 0IXndQ7k/adnIfKzm7WpHUzbVUXRV5S+C/31d/2mUD9fGTZpveuUon5ayBo47WpcTFOf KckcEWp4RPvh+C8QkD5P2zdoGZE3payylwRz5dt3/1XKloHLYxdNBnv2r5Qbme+W5g+a C3xQ== X-Gm-Message-State: AOAM531o4yIDlX74dZalgSdgJp78NVD3Jh4BTGUi+E+79g2WeEXbm+U6 s/eyszT37YF68SJmVSxszAzQ+dwMqNo= X-Google-Smtp-Source: ABdhPJy0L7TM6kdPHwgdRZ70zglFSgChPwGohimQDPZ9WYSMgtHZCOIZsy4FS1z5BIRHstJsstj79g== X-Received: by 2002:a1c:6484:: with SMTP id y126mr13186333wmb.76.1609005127573; Sat, 26 Dec 2020 09:52:07 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:07 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 12/16] struct-attr: prepare to handle attributes at the end of struct definitions (3) Date: Sat, 26 Dec 2020 18:51:25 +0100 Message-Id: <20201226175129.9621-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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. --- parse.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/parse.c b/parse.c index a90dcf7f7e4a..a67d567145d0 100644 --- a/parse.c +++ b/parse.c @@ -747,18 +747,15 @@ 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; - 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); + } else { sparse_error(token->pos, "expected declaration"); ctx->ctype.base_type = &bad_ctype; return token; } - sym = alloc_symbol(token->pos, type); -end: set_current_scope(sym); // used by dissect token = parse(token->next, sym); ctx->ctype.base_type = sym; From patchwork Sat Dec 26 17:51: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: 11990415 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 EF6A0C4332E for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C710820809 for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726329AbgLZRxW (ORCPT ); Sat, 26 Dec 2020 12:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgLZRxW (ORCPT ); Sat, 26 Dec 2020 12:53:22 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB41C06179E for ; Sat, 26 Dec 2020 09:52:09 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id a12so6660260wrv.8 for ; Sat, 26 Dec 2020 09:52:09 -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=gJXiqKN0FincI2RnZabMb03+M1rtkN2yeJaFy6afhDs=; b=A2o41Tsw4DS18nK3p1hMnauxQ2PamIKAKVXixBOEZ3qBYnPGFeaqd3ZgUR+xA/MSWw OzGUYqgTIGi9DrYHmMP3MxCmoUn5qDCeGmf/O6AwRzsAQomdn30xGk6xj37hEJpmdMJg vNCRqG5pFfSXTigs/0oHAX/bWZFQyG81L50FBxu34l3CyfDUAKqqAY0L79K34jNXcpPU XA0xBZQbcbovlMZff3ulOYRIzRw5Y4QLv4qik0eiwgA/n7N9dU0aiiRKqKDyzyFfhaTq Ari089WUz1fkUgofPNQxAastGHW7ZGILd0no7saDJ7bwwaEB474W8hOUC9PZjCVxdUyi rowg== 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=gJXiqKN0FincI2RnZabMb03+M1rtkN2yeJaFy6afhDs=; b=aFO4G1qcUsaKbWS5GFu52V7ivha4HxWKUvhvLwbRfHnQGFerj5eFfQCwlNCfWVoC7F LaekC/aPC8jaijCyGCXmknlS77N5BXvPelBPg/wfsGOxfKWOxaDkQGXhHoHweJR/lfOm cA04aH0iksl6PXQkGeJnbRTk8mdL3OoBiIh48vBowq5XtU1L+xjJaafKyKFwABmcmHQV dQaDr6Vs/Mfq9FqXqGbg8vND+eRIXtjrhTQ1WYlz/LbT8Y1W+5aMA/ohggF0zMXVP8o0 515uFo5gP5o6W4ayhw5SBYB3eLi1XS0/ivHOlokX2rRNrRFlOxMoXbTh3Am2hy10E8+M pnrg== X-Gm-Message-State: AOAM533eW5sxOj+a95LjLomKKPtlLggveHZi0umkGobSGq/3OwGCY+45 AkrHZvL+E/Cm/EMaMODo7xDbfkYE9Bw= X-Google-Smtp-Source: ABdhPJwCT6edtl5vnKwPz5DbZJ2uPZg208/X1WzPMsriUIFeopNP8NxVR1L5ADgE+ZC4Xoo7tQSJ0Q== X-Received: by 2002:a5d:6607:: with SMTP id n7mr42065554wru.206.1609005128291; Sat, 26 Dec 2020 09:52:08 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:07 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 13/16] struct-attr: fix type attribute like 'struct __attr { ... }' Date: Sat, 26 Dec 2020 18:51:26 +0100 Message-Id: <20201226175129.9621-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 a67d567145d0..5f33ac178a45 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 || @@ -760,6 +761,7 @@ static struct token *struct_union_enum_specifier(enum type type, token = parse(token->next, sym); ctx->ctype.base_type = sym; token = expect(token, '}', "at end of specifier"); + apply_ctype(token->pos, &sym->ctype, &attr.ctype); // Mark the structure as needing re-examination sym->examined = 0; From patchwork Sat Dec 26 17:51: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: 11990419 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 1FF55C433DB for ; Sat, 26 Dec 2020 17:53:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA16D217A0 for ; Sat, 26 Dec 2020 17:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbgLZRxW (ORCPT ); Sat, 26 Dec 2020 12:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbgLZRxW (ORCPT ); Sat, 26 Dec 2020 12:53:22 -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 59235C06179F for ; Sat, 26 Dec 2020 09:52:10 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id t16so6688425wra.3 for ; Sat, 26 Dec 2020 09:52:10 -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=p4VcEExhsFaRRIZkRJF2C3i3j9qOJH/btzyHWM7ffns=; b=MBmakUrvgbIKn01MCr0KytMNWyblJyCEGAEVBpE9Mcj9648bV8M805uCWIwvBr5p0G bnNUpS1Xtop8ChRXr3fyEhGSBKow9+67f6U/EiL8RO04etSWQzOk8U+ihGkhbLdtryrq RLs+yqTzbWiAw4pUUuI2HAvK8+ZCbBMODuFUFaQnE1foMmYVwVOqk5ANffMD60gNSevE lPoFLn9qfjc2Op6sOqLiV7m0BGoz0pvYij6fgRy4tksl0tia5ayWUgCHdISvXSNpmymc zcztM5iIylutHGgxWR3/OzWV8g4BNG4W/VVZbTQ3+Zw/TuVbOX8/YWBLtLWSreJNhAN4 oPgA== 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=p4VcEExhsFaRRIZkRJF2C3i3j9qOJH/btzyHWM7ffns=; b=sd2GuQ5j0L9bUCsCwchcnWM1Ip+/mSSmgUOcBIqhKYXjUhBPZgLUIP4l10rICJiaQW fBjQ3pDTVDzSGi3gzJH9T6odaGhR5WqQJ2pJandwrC8kj0jW/B8zLcu5M00NxfjY9exE 1REmB7qloGksynk31d9QdwVkx1GghyeVUghAknXa2+iEQqw4oTdErlR6J47zRtC2DekQ HHj7niDsibyAWRPUEFeWnozONKENg54dkRLzOY9Fb6XPzNUueJ9qhAiAh0a6z6hLwxCZ XTAL5q/W1IcEkf0n6du+IegURZbLTSwUR4+8wkxuOxW+xSTLkOjJH/g8NmEFFGRT99qq 1tSg== X-Gm-Message-State: AOAM531nqdbQpL4Ra2Qs1KVN47hJ7KpAVy665VK5IEtAoyl9Bh6+KlqG Ei7WfPJYkaX/Cn2Oc5F6ZhoJ534tKfg= X-Google-Smtp-Source: ABdhPJzuS/HXTykulLmxtzLlScgKYQDVW3Ud5ezCT4aKDQNx3sN9EYGi15x8i9xW9uuMFL8c2VdyaQ== X-Received: by 2002:adf:cd8f:: with SMTP id q15mr42350969wrj.79.1609005129090; Sat, 26 Dec 2020 09:52:09 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:08 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 14/16] struct-attr: fix: do not ignore struct/union/enum type attributes Date: Sat, 26 Dec 2020 18:51:27 +0100 Message-Id: <20201226175129.9621-15-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 5f33ac178a45..0fd2bb473a47 100644 --- a/parse.c +++ b/parse.c @@ -761,6 +761,8 @@ static struct token *struct_union_enum_specifier(enum type type, token = parse(token->next, sym); ctx->ctype.base_type = 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); // Mark the structure as needing re-examination diff --git a/validation/packed-bitfield3.c b/validation/packed-bitfield3.c index 6acff875299f..a8f740700967 100644 --- a/validation/packed-bitfield3.c +++ b/validation/packed-bitfield3.c @@ -25,5 +25,4 @@ _Static_assert( sizeof(struct c) == sizeof(u64)); /* * 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 Sat Dec 26 17:51: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: 11990421 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 38199C433DB for ; Sat, 26 Dec 2020 17:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1163620809 for ; Sat, 26 Dec 2020 17:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbgLZRxe (ORCPT ); Sat, 26 Dec 2020 12:53:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726281AbgLZRxe (ORCPT ); Sat, 26 Dec 2020 12:53:34 -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 5465AC0617A0 for ; Sat, 26 Dec 2020 09:52:11 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id d26so6635491wrb.12 for ; Sat, 26 Dec 2020 09:52:11 -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=DsQLxTrNJcz0R22oO5wwa9iFQjczJUfus8/Hi9D7Q/g=; b=c9ESPmhw7d3bOY1heevHY1rZKFGSZTkGZi34bm66vIioFeZ5kr/XQmWbeSFMZJ37Bo 9BSh15xosVR33LTErnLf5pdXm2GF4rVLcAN586wDcyICKPSKcynWfsHmrdRx98LhqVHo H6tZCZWeK2nAVtGJKb8RdXlMqmk3HqY7QAnFKsnFFfAK3dcMIBNtcQu1SfRmwD4lztRU xk+e0G0ZUBNNjTr7d0z7/akhzOyFNHETuVFqzfL9zBclQNZ27FyAVfvLPEKi7JtGDyII Jc0gZq5OAMw0gN5OJhru0CqLrQgjf0KhAXQbudD5WIIDNe/yA2N/5GYrRqOnKAgC+pAi f5Xw== 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=DsQLxTrNJcz0R22oO5wwa9iFQjczJUfus8/Hi9D7Q/g=; b=SzsuGzreFeAlUyvA0u7b/BN/KkGPDLtMlZn4DhG6NobluXUo3b27HBxfBGGFZ3dEb9 PBDQ1Ih+gnGBt34Y5oJuaN3krqHupRuMPcBfaHdvGrMmcb5auG2n2EMzCdbreOD8hjYp eWM+lEzmCfQlk5LpILX+5GLTequr/ZZDuNKDfuLrHJioyf1chLBlJUCb8D5Vf4uO/a/6 r0W9/DqvSTTh4eOHaDZGIbUJF6NE7ODHMxx74QA4yyYIatcr86sUehrwvtvtWJQe8+lC 9Sf4bchjkDq3f1x37M8E/h41JOFtwN7dp4zFLFnWO3/cEX9k0kfmrpS2qns+ocrBa4i2 VtGQ== X-Gm-Message-State: AOAM533hYH+UuEC/XStNl4P5pyyPM9lAJ6U4cgoEG+ohQnvFPB+n/0P8 es0SEeMNsRaKzrJ1V6Dr+2mEYSwGYVw= X-Google-Smtp-Source: ABdhPJyK1IoGCCMdt+sjvKOzzcYQT0G3t0Tthnjyf1EjZIc2uxdDrenzbhEz1D/KiSRDD8L/bP/S+Q== X-Received: by 2002:a5d:56c3:: with SMTP id m3mr43769295wrw.419.1609005130163; Sat, 26 Dec 2020 09:52:10 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:09 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 15/16] packed: no out-of-bound access of packed bitfields Date: Sat, 26 Dec 2020 18:51:28 +0100 Message-Id: <20201226175129.9621-16-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-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 form 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. --- 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 Sat Dec 26 17:51: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: 11990423 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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 75C85C433E0 for ; Sat, 26 Dec 2020 17:54:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 441D720809 for ; Sat, 26 Dec 2020 17:54:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726318AbgLZRyA (ORCPT ); Sat, 26 Dec 2020 12:54:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbgLZRx7 (ORCPT ); Sat, 26 Dec 2020 12:53:59 -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 25D4CC0617A1 for ; Sat, 26 Dec 2020 09:52:12 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id y23so5686320wmi.1 for ; Sat, 26 Dec 2020 09:52:12 -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=IUrPYZ873WnY7bYzHZqUSa1HoojKkdIB+hKlsBQ7CUM=; b=nNcGda73XlEdsIbwF8AM/wj6RrBytspHYEhERzGfEV8gyXsOH/VUhRpMJ+sM2U+KO2 qxgx6jH9ms2s3Tx2hr34vjBmVoBOErE2sODGJLW8w2FETO7YIQ6r3jQpOJCBq9nGXp4D z2eBgMbmjyiBaBCkq0tNp5BG2BHEw4pt/XhVJub2D527P42ynAgVdRj+DNqYFfgnCmIe B+Dm369TZZFUALHlm7y8ocPlxmptg6gP24MbRvMiq9PyPJY8ooRyzLX1FwaKq33FCU+/ ltlv0crLNly+gD/CkCdGw7uN+yGlULtczYIxzTYgH/9IIzIIk+fL6iF2Xf7OJuS0sytf tZ+w== 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=IUrPYZ873WnY7bYzHZqUSa1HoojKkdIB+hKlsBQ7CUM=; b=gq/o3ZtSrq28hmDBLfz/tySOsEbOnU5QY1giaMRBR86d8cFIAmZ1t2MMV4PSuoP0Ow IU6t51QpIc8UIZ+ETxGQkOa8HH1VVJBPQDDptIytyngQXJ53WE3XojC3ZO+gikFptUFN xuBAjK8LE11ZNipZeqJlqIsFCKffUck9YH1M9qCvVb43SWwExqNMpgSbdec2C54hVahd 4zjwZClay1hbUlg/O9Yj+5++SxRTguDsPf6A/+1PQR+ENlNBgl9LWFMsT1NFe0ticT1l lFUS/oyZ3xD9KXn2TCuXslcnfbTSr17VLyYLQU6DunMXz9AFKAIdxYywc4YIk68VCm6K Gwxg== X-Gm-Message-State: AOAM531/+LaEEk4/Uu2AkDfnHswz9EkVwtxAuE4+Lf+tVQR/hRPtx7Tf mjS7O3SJh8G5znnFfVvWXIg4BMc/uNE= X-Google-Smtp-Source: ABdhPJyIOSdMbo7kCjaroK2Y05ZMMtrFYLxa5cfsywqop7IraUeewsB7P4JgaR8u5YpDhChcqancOA== X-Received: by 2002:a05:600c:208:: with SMTP id 8mr13345932wmi.143.1609005130915; Sat, 26 Dec 2020 09:52:10 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:10a5:37c9:8c28:d3e9]) by smtp.gmail.com with ESMTPSA id c4sm12780813wmf.19.2020.12.26.09.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Dec 2020 09:52:10 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck , Jacob Keller Subject: [PATCH v2 16/16] packed: add support for __packed struct Date: Sat, 26 Dec 2020 18:51:29 +0100 Message-Id: <20201226175129.9621-17-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> References: <20201226175129.9621-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, the attribute 'packed' is ignored --- 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 - 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/parse.c b/parse.c index 0fd2bb473a47..42e48620bd5e 100644 --- a/parse.c +++ b/parse.c @@ -764,6 +764,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; // Mark the structure as needing re-examination sym->examined = 0; @@ -1088,8 +1089,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 907500dedbf0..6d92fb2862eb 100644 --- a/validation/packed-bitfield0.c +++ b/validation/packed-bitfield0.c @@ -63,5 +63,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 5039be4d0b45..253750063ffd 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 */