From patchwork Wed Nov 18 21:11:43 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: 11915871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 6BF14C63798 for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05CCC246B0 for ; Wed, 18 Nov 2020 21:12:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HIP7v6MW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726658AbgKRVLy (ORCPT ); Wed, 18 Nov 2020 16:11:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbgKRVLy (ORCPT ); Wed, 18 Nov 2020 16:11:54 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5991C0613D4 for ; Wed, 18 Nov 2020 13:11:53 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id ay21so3555291edb.2 for ; Wed, 18 Nov 2020 13:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8tB7H+NEvFrt80vPQGak6mXL17G+DOEcOHEXuF8ABzo=; b=HIP7v6MWMp8bBhkyZNTJdh+UaLGvEI6SA3GuLI9yjjdvO0oOd8Moh1ZwNU0a68t3iJ 3UwRqtdLTwWsZUVniADLNtQ9vXZVPm65gWmIGlamITVbIWn2blhpvfPdBy7fLdhvHtG4 T/Ol0vUF7Y1sJuP30gesyY+wfiO7Y6zIBQT2gCiDnN6S0veLovb/2o+lzxyoOBBE34rG uz0HB20RHOb7gx8JblOijIXewZxa7Z9pOJbndlUrnL+fTaDy51hWhDhGRnE5h9Dxc/1k xd8FrOV79aR0PrbgPDTvQmi5i7tUAPowS346KK+ilqButgMXOlFi7pBbcsGjNcIQdPI8 SWHg== 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=8tB7H+NEvFrt80vPQGak6mXL17G+DOEcOHEXuF8ABzo=; b=pS3YiTYGcphgU6b9mM4AP1bjEwJcTYhRwwvrcJjnMq9PXHnsKJt1Y36rKF3Ov1TlHn bMlK8Oc14vYTGv4XSS6BjeyQ6RCZuutDigNsIaVoU6kIyEiD5Jg+F+N+M4yc4GnMIx8O JFOEvvZAiWLN/pMuwFw2zhRR7CHMZCt7LvrICYv333uYYKD6hsQZ+DrJLcnksyU71CSe xy1xeNdx7T7oYlP2mLHKk/wHYY5sB7DSl0eCR1mmddc17PqdIGnnQ0snIImz1JmAU/Rv havBXUW2iDGKPiWDaVY1w0GBZaUfaAccCMUNdxhhmeERqXVTSpltmk7UhwKC25OggxCg q24w== X-Gm-Message-State: AOAM531Zv1kZd7yA+MRMTVIaeii7DF6WsoJ0B9UbxrA8ixie61kDzRkq t9UUr2JViFgzNu5rBwoZL6RAvwqSn+g= X-Google-Smtp-Source: ABdhPJwg8Xqxd/7h+tnxSjVL3oxdzFa1IjUiCE1lMqKueH0CBmesLUM5cBWVGc3kvzf9aXER0Tbuuw== X-Received: by 2002:aa7:c886:: with SMTP id p6mr27087383eds.352.1605733912185; Wed, 18 Nov 2020 13:11:52 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:491a:3e51:301b:6e24]) by smtp.gmail.com with ESMTPSA id rp13sm13510712ejb.79.2020.11.18.13.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:11:51 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Luc Van Oostenryck Subject: [PATCH 1/5] unqual: add testcases Date: Wed, 18 Nov 2020 22:11:43 +0100 Message-Id: <20201118211147.10680-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> References: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Add some testcases related to qualifier dropping / lvalue conversion. Signed-off-by: Luc Van Oostenryck --- validation/eval/unqual-comma.c | 13 +++++++++++++ validation/eval/unqual-postop.c | 23 +++++++++++++++++++++++ validation/eval/unqual-stmt-expr.c | 13 +++++++++++++ validation/eval/unqual02.c | 26 ++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 validation/eval/unqual-comma.c create mode 100644 validation/eval/unqual-postop.c create mode 100644 validation/eval/unqual-stmt-expr.c create mode 100644 validation/eval/unqual02.c diff --git a/validation/eval/unqual-comma.c b/validation/eval/unqual-comma.c new file mode 100644 index 000000000000..e06586cd43e3 --- /dev/null +++ b/validation/eval/unqual-comma.c @@ -0,0 +1,13 @@ +#define __unqual_typeof(x) typeof(((void)0, (x))) + +int *foo(volatile int x); +int *foo(volatile int x) +{ + extern __unqual_typeof(x) y; + return &y; +} + +/* + * check-name: unqual-comma + * check-known-to-fail + */ diff --git a/validation/eval/unqual-postop.c b/validation/eval/unqual-postop.c new file mode 100644 index 000000000000..fb3082dc8836 --- /dev/null +++ b/validation/eval/unqual-postop.c @@ -0,0 +1,23 @@ +static void test_volatile(void) +{ + volatile int x = 0; + int *pp; + + typeof(++x) v1; pp = &v1; // KO + typeof(x++) v2; pp = &v2; // KO +} + +/* + * check-name: unqual-postop + * check-command: sparse -Wno-declaration-after-statement $file + * check-known-to-fail + * + * check-error-start +eval/unqual-postop.c:6:40: warning: incorrect type in assignment (different modifiers) +eval/unqual-postop.c:6:40: expected int *pp +eval/unqual-postop.c:6:40: got int volatile * +eval/unqual-postop.c:7:40: warning: incorrect type in assignment (different modifiers) +eval/unqual-postop.c:7:40: expected int *pp +eval/unqual-postop.c:7:40: got int volatile * + * check-error-end + */ diff --git a/validation/eval/unqual-stmt-expr.c b/validation/eval/unqual-stmt-expr.c new file mode 100644 index 000000000000..bac6cb6b197f --- /dev/null +++ b/validation/eval/unqual-stmt-expr.c @@ -0,0 +1,13 @@ +#define __unqual_typeof(x) typeof(({ x; })) + +int *foo(volatile int x); +int *foo(volatile int x) +{ + extern __unqual_typeof(x) y; + return &y; +} + +/* + * check-name: unqual-stmt-expr + * check-known-to-fail + */ diff --git a/validation/eval/unqual02.c b/validation/eval/unqual02.c new file mode 100644 index 000000000000..f136cbd50510 --- /dev/null +++ b/validation/eval/unqual02.c @@ -0,0 +1,26 @@ +static void test_const(volatile int x) +{ + const int x = 0; + typeof(1?x:x) i3; i3 = 0; // should be OK + typeof(+x) i4; i4 = 0; // should be OK + typeof(-x) i5; i5 = 0; // should be OK + typeof(!x) i6; i6 = 0; // should be OK + typeof(x+x) i7; i7 = 0; // should be OK +} + +static void test_volatile(void) +{ + volatile int x = 0; + int *pp; + + typeof(1?x:x) i3; pp = &i3; // should be OK + typeof(+x) i4; pp = &i4; // should be OK + typeof(-x) i5; pp = &i5; // should be OK + typeof(!x) i6; pp = &i6; // should be OK + typeof(x+x) i7; pp = &i7; // should be OK +} + +/* + * check-name: unqual02 + * check-command: sparse -Wno-declaration-after-statement $file + */ From patchwork Wed Nov 18 21:11:44 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: 11915867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 80FB0C6379F for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46118246B2 for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EWC3sAyV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbgKRVLz (ORCPT ); Wed, 18 Nov 2020 16:11:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbgKRVLy (ORCPT ); Wed, 18 Nov 2020 16:11:54 -0500 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0ADAC0613D4 for ; Wed, 18 Nov 2020 13:11:54 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id m16so3554102edr.3 for ; Wed, 18 Nov 2020 13:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nSlCQnbvubc/6EU5L3H0FzpkYn93JO5457mk026+YyA=; b=EWC3sAyVk6rvEfDfkXDQXsCyaYN61Uc3rurzLD2I9Yuai3C9KD2k4PP1Vz26NGit/s yvpE3TM8p42QPHJFgAX6GfCTDtkhaPzax+Br16kUuefAx2iC7k9OTGvpxBuj/14rWwQI TTJKr3AQEjHsfoUR0SmybJDLWHneV82jiQaznVONHpNspm4ZHXa0pSaiwscbVenmdn56 WWpne8m330mkZGqSNVAK3xYYOADxM34/r88XFT9b5C5n84ZsJGKYVvPH50outmBo+T6I M7g+JorAYEUXlJJSaDrnXKqHOTePqAJs7qXGAjTm0MRFk1UHG5eh+N9FsNMHoV+Qa5eV qb1w== 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=nSlCQnbvubc/6EU5L3H0FzpkYn93JO5457mk026+YyA=; b=Uc9ygDcb6y4dVoU9ClrfF+fK3m2vupDUxqPYngPvY2K9yKhzKjBbmuoISU/6gMgIfT PXQH1fkodg6P1dgn7jPXkTZ1xedQrTnhTSZR0wv751nhTb+jRNkGCE8ZJ86oddo9zHBK p9J8sNBPy0XZeqvHa4Yu6bkRgBy7WWKNuZEVm1XzMJzeYqUj8gBZyi63FKXqKqUmtRBp CD31NGMgI0N/1zjAe/lwWgJvrYeEVC1to2Lv9rQhrOj4qOqUou4WhBdwNeLifhNkYowS Gec7S3YSK69K4KkuUG/4rfVoiWhXde48dJ3pWWjzwvIAOIwdAY1m3eLczLT/GOLOmNj6 sQCA== X-Gm-Message-State: AOAM532Akta9V/PNTQOryl+gyOsVyEGvDTN1K5x8GqUSRcNdYdqKpupd ZSGbYlfc7jjt093beZpSAJzwIKD5+pc= X-Google-Smtp-Source: ABdhPJzeFyYPM5eSZQavaC6pMwTo9Hy6Ml4O5OhxVBUzU8xa29Lo7wnRUWL2mbnahVpM4h3GNclbyg== X-Received: by 2002:a50:b761:: with SMTP id g88mr27900439ede.387.1605733913219; Wed, 18 Nov 2020 13:11:53 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:491a:3e51:301b:6e24]) by smtp.gmail.com with ESMTPSA id rp13sm13510712ejb.79.2020.11.18.13.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:11:52 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Luc Van Oostenryck Subject: [PATCH 2/5] unqual: unqualify_type() should check for null ctypes Date: Wed, 18 Nov 2020 22:11:44 +0100 Message-Id: <20201118211147.10680-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> References: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org It's possible that the input type is NULL, so add a check for it. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/evaluate.c b/evaluate.c index c39f9ec73da9..fd84205c7f2c 100644 --- a/evaluate.c +++ b/evaluate.c @@ -63,6 +63,8 @@ static inline int valid_subexpr_type(struct expression *expr) static struct symbol *unqualify_type(struct symbol *ctype) { + if (!ctype) + return ctype; if (ctype->type == SYM_NODE && (ctype->ctype.modifiers & MOD_QUALIFIER)) { struct symbol *unqual = alloc_symbol(ctype->pos, 0); From patchwork Wed Nov 18 21:11:45 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: 11915875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 D9684C64E69 for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 806E5246B0 for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M8YBfKip" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbgKRVL4 (ORCPT ); Wed, 18 Nov 2020 16:11:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbgKRVL4 (ORCPT ); Wed, 18 Nov 2020 16:11:56 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7928C0613D4 for ; Wed, 18 Nov 2020 13:11:55 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id q16so3518374edv.10 for ; Wed, 18 Nov 2020 13:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=diwXHAZLBE0IQzWJ276Ed2JgGJSuVV259wDFXcX4CVY=; b=M8YBfKipFLd9vmcXywPnPEnkWbKUE9X3JAxXCRY2LdyO7R9Qt+c1x1uGp4Dc7c1oTI +kTfeHlC9sqdrgY71f2XA/zGsJ5u+isinzLvb0wPdnosMFiX4C0C3uh9WEq5yWTtt6Hn yX3Y6kKEBgTbew54qk8GSYR4p12q2FIPaSyjfL7ypfU6NHgJGPzAUwvo0UcoRNGgXCO7 EBAyEWYFhe9EnKKDoXYkHWX3Xeg7rCV3wFzMqDFui3OL5+9DwVNETVQ/ZjLoJLOf0PIa tsh7ia0i1WazOAIx7e0LBjezchIf4rI+pMJ/IpNrUE67osej89Vd2zHon8PWjHZzvgYG izGQ== 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=diwXHAZLBE0IQzWJ276Ed2JgGJSuVV259wDFXcX4CVY=; b=kD+Qj677cQyHMszZ5tRpujIeZPkGqfwPSnknX6BJTZU0jF+wCwWZMpIwFLEO13uz+E +8KGN1qcELtPYmS2tSrWAh9+1U//wn9FjSSANKJOIJ+KiHWxQkfKSAnDbh0tR+at1egC pF3fcjZVQnd2ChL1OoCx1r3x/t/hvQmEzMbztdLrVBM+OEq+5DBkGmT9ewY7zV1aF90o 9MUFCMo4aP6ETUpnUEDc9rOYwo4PqB9PEYytmcOcvSFhkvMIvEegTyO28VjLqZEJwoUo fP3sUGifQR5bR8ihnfbxsgSRqpu4pdSauKvot3pYl5LH9pwh0hdanz6umtkn51DyNGQC DWDw== X-Gm-Message-State: AOAM530IjGyJmVC1LgdMBNScPd2b5ADKyXkvht1c+gKDLuk+KmFdVvD5 VNuh9rdvmVJHweTDL3aFML/3MaVAA0s= X-Google-Smtp-Source: ABdhPJw/7CxVuX6vxYUPllXmWE96M8YlVSMpRJNP/sN2oy+XMOoGo5pVnYT2nIt2/v0h5LogodFcqw== X-Received: by 2002:a50:a40c:: with SMTP id u12mr14871266edb.337.1605733914229; Wed, 18 Nov 2020 13:11:54 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:491a:3e51:301b:6e24]) by smtp.gmail.com with ESMTPSA id rp13sm13510712ejb.79.2020.11.18.13.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:11:53 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Luc Van Oostenryck Subject: [PATCH 3/5] unqual: comma expressions should drop qualifiers Date: Wed, 18 Nov 2020 22:11:45 +0100 Message-Id: <20201118211147.10680-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> References: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Comma expressions should be subjected to lvalue-conversion and thus should drop qualifiers. Fix this by calling unqualify_type() after array-to-pointer conversion. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 2 +- validation/eval/unqual-comma.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index fd84205c7f2c..b6e8477185f4 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1028,7 +1028,7 @@ static struct symbol *evaluate_binop(struct expression *expr) static struct symbol *evaluate_comma(struct expression *expr) { - expr->ctype = degenerate(expr->right); + expr->ctype = unqualify_type(degenerate(expr->right)); if (expr->ctype == &null_ctype) expr->ctype = &ptr_ctype; expr->flags &= expr->left->flags & expr->right->flags; diff --git a/validation/eval/unqual-comma.c b/validation/eval/unqual-comma.c index e06586cd43e3..11546d22348a 100644 --- a/validation/eval/unqual-comma.c +++ b/validation/eval/unqual-comma.c @@ -9,5 +9,4 @@ int *foo(volatile int x) /* * check-name: unqual-comma - * check-known-to-fail */ From patchwork Wed Nov 18 21:11:46 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: 11915873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 1C27FC64E75 for ; Wed, 18 Nov 2020 21:12:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9D95246B2 for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u79TZIQK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgKRVL5 (ORCPT ); Wed, 18 Nov 2020 16:11:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbgKRVL5 (ORCPT ); Wed, 18 Nov 2020 16:11:57 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6645C0613D4 for ; Wed, 18 Nov 2020 13:11:56 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id y4so3545637edy.5 for ; Wed, 18 Nov 2020 13:11:56 -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=z3IZ+i/95LaVNeXZRa1HYtgvIV93YcdAD2zl2Q6dAA4=; b=u79TZIQKdUo3Efn30JM2c3HmhvEzeQjNs/fzoVdbO7DKTqOJLhYaOM3+D1ky91/oR9 hswhjmtnFNLwZT2pn0CpE5c7dI8K7dv8w54r2DKSjOXLGFVKz9LYLDCdoGsqyiQDroWk S9jAI5IeVGRXs4xzBDrhN3a35yy1RYSYfLv7bl29+QoudUuf4umdZzND9GH/osNXNYYD 6+wNST/DX5Tnjesw2RFAomiaru6WKCmZsHQRMA/VL5wmJsBV3vgXLMjVrgfcuASZYIFQ /R70KQAOnu5OFdW6p2vBedfFrSdGu9ahBJdyPaO3nf/K23ogM99kItU2Kfdnr6TxeRch Jjsg== 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=z3IZ+i/95LaVNeXZRa1HYtgvIV93YcdAD2zl2Q6dAA4=; b=L76nuQjAPmMLRWOtSE6qP59MaoXxBNS9konXeRFigpcKwryitAeRCIAoHAffSBc/VW 2dQWdUTkmnZZEQ75+mhDsyubAIVu2nuZxR8DPwnjGWfzCBuafnWKezfN/A6mGT20SBjK Fw98Y5DKrRZlZv23zDkSYxf6BjxXCk3h2QJJiILuTIfVGWNjna6tQyShn+um2IBJHftR fGUVeVjklUP7d7jJ4mJiugZiOyEWqhqM6Ywoo6YYI6n30+Rg46Dflf765lXDR31nKcy2 u0WhB/oS6bjUn52MPVLHY/oh0e+aYKLIzOkUbDZeK7bhpUJ/0a89nC46wsWElu7u0Z9r OonQ== X-Gm-Message-State: AOAM531kgcZsSLLZPH4WyUAcTjt3RRhS3HuoVfCmdD37YTj6AJetYkdX EoaZ57VjW7ESL945CVv5w45ZrqavM4w= X-Google-Smtp-Source: ABdhPJxoBDs4gLjPst6mUSygFFAnB/YeYEXsPrh1QtZfLy4vKtZ96tXQ22/Af0TqFg30Xo84cC2aew== X-Received: by 2002:aa7:d8c4:: with SMTP id k4mr27327864eds.248.1605733915364; Wed, 18 Nov 2020 13:11:55 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:491a:3e51:301b:6e24]) by smtp.gmail.com with ESMTPSA id rp13sm13510712ejb.79.2020.11.18.13.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:11:54 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Luc Van Oostenryck Subject: [PATCH 4/5] unqual: statement expressions should drop qualifiers Date: Wed, 18 Nov 2020 22:11:46 +0100 Message-Id: <20201118211147.10680-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> References: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Statement expressions should be subjected to lvalue-conversion and thus should drop qualifiers. Fix this by calling unqualify_type() after array-to-pointer conversion. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 2 +- validation/eval/unqual-stmt-expr.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index b6e8477185f4..48ce61f0302d 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3950,7 +3950,7 @@ struct symbol *evaluate_statement(struct statement *stmt) return NULL; if (stmt->expression->ctype == &null_ctype) stmt->expression = cast_to(stmt->expression, &ptr_ctype); - return degenerate(stmt->expression); + return unqualify_type(degenerate(stmt->expression)); case STMT_COMPOUND: { struct statement *s; diff --git a/validation/eval/unqual-stmt-expr.c b/validation/eval/unqual-stmt-expr.c index bac6cb6b197f..280c2fe8e36e 100644 --- a/validation/eval/unqual-stmt-expr.c +++ b/validation/eval/unqual-stmt-expr.c @@ -9,5 +9,4 @@ int *foo(volatile int x) /* * check-name: unqual-stmt-expr - * check-known-to-fail */ From patchwork Wed Nov 18 21:11:47 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: 11915877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 3A49EC6379D for ; Wed, 18 Nov 2020 21:12:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01B77246B0 for ; Wed, 18 Nov 2020 21:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mwBUi1N3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726723AbgKRVL6 (ORCPT ); Wed, 18 Nov 2020 16:11:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbgKRVL6 (ORCPT ); Wed, 18 Nov 2020 16:11:58 -0500 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F236CC0613D4 for ; Wed, 18 Nov 2020 13:11:57 -0800 (PST) Received: by mail-ej1-x641.google.com with SMTP id o21so4784691ejb.3 for ; Wed, 18 Nov 2020 13:11:57 -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=JY+fyPbOOZovKigCiTDcuZXpZAz76HCmg1MDGlFGtxw=; b=mwBUi1N3iztb7dM5AQyuARoCg6vYwQtdrjhrJeKUnbHhebJVwedlXZfgiCbGP+toe6 z9OAteiesiK+mJPnCGKgRjjcilfzPK0n1iw8GE9quauyDjoUqguiZZ3LTBZvSiWrml8l Mbqip/23iqIzfBfGp4rpyCGX1HvNRfJluzW7BbgEgvQYMvfS9/VqZhz59pI7bRoy1Uwr Dg6oM/KIKCQEO4GkfX+I1OYfex7AOEF/kSm4NXNgiGdPRgPvdKNdAiU0SIb2MgQCkrBv fsRsmVzFwtuPyqjvoYom3yeqKbf6etiSw6AKpFiGsFsytwECejx2s7JZeUOGkF9wl/xy 9hPA== 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=JY+fyPbOOZovKigCiTDcuZXpZAz76HCmg1MDGlFGtxw=; b=MXxYEeVzOKD1eqhEEtOnuuuqmRAqAyrB5RBPYUhpRb6Gahorf2616TNbvRBvXt04bv kbt21Qp1yt//JH4fbKY6fl2DR7PNfqayD0qK6TOgTA67MW/qqOThG256rcGAIxDMySQT 3LoXRI01fB2nU30xqQx7LzZLoFoPqqPbvE8Gs1n6aRlMXIsLJRWBNqKobHJnv/NZ7dgk pkrZ1f2XukAO798T49ECTpjqu+xDAGk2XuG4H5CmF+27BzB3U13XOdHp5Rhgf6Myyngl bi9rygUPnWTAegEQPklyYZDFyEM68oiGwLAN1xXscgknHBGWHXpwoOhYx59pceP9hOfB FdXQ== X-Gm-Message-State: AOAM532DuIxlSEQKMGU1xgVEyTEhVpcOpRKx9Qzr+y7jO5RFN16qy3vm kdHxKbHJq/6ojWXuOMfuhiQ7O2+XpUs= X-Google-Smtp-Source: ABdhPJz69t4YqMoZx/QaaI8SRHYJQtINyHpzW9Gqlg7C6awrUdH6VMX+HwJs1j0oswVr9rJCTobVXw== X-Received: by 2002:a17:906:2a4b:: with SMTP id k11mr26839131eje.467.1605733916487; Wed, 18 Nov 2020 13:11:56 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:b7fe:f700:491a:3e51:301b:6e24]) by smtp.gmail.com with ESMTPSA id rp13sm13510712ejb.79.2020.11.18.13.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:11:55 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds , Luc Van Oostenryck Subject: [PATCH 5/5] unqual: pre- & post-increment/decrement should *not* drop qualifiers Date: Wed, 18 Nov 2020 22:11:47 +0100 Message-Id: <20201118211147.10680-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> References: <20201118211147.10680-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Increment and decrement expressions are not subjected to lvalue-conversion and thus should *not* drop qualifiers. However, while the lvalue-conversion is not done, the qualifiers are dropped because the type used for the result is the one returned by classify_type() which always return the base type. Fix this by using the type of the operand as the result type. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 3 +-- validation/eval/unqual-postop.c | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/evaluate.c b/evaluate.c index 48ce61f0302d..8599fcee6875 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1935,8 +1935,7 @@ static struct symbol *evaluate_postop(struct expression *expr) if (multiply) { evaluate_assign_to(op, op->ctype); expr->op_value = multiply; - expr->ctype = ctype; - return ctype; + return expr->ctype = op->ctype; } expression_error(expr, "bad argument type for ++/--"); diff --git a/validation/eval/unqual-postop.c b/validation/eval/unqual-postop.c index fb3082dc8836..48b6be8b8508 100644 --- a/validation/eval/unqual-postop.c +++ b/validation/eval/unqual-postop.c @@ -10,7 +10,6 @@ static void test_volatile(void) /* * check-name: unqual-postop * check-command: sparse -Wno-declaration-after-statement $file - * check-known-to-fail * * check-error-start eval/unqual-postop.c:6:40: warning: incorrect type in assignment (different modifiers)