From patchwork Tue Dec 10 22:59:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B74115AB for ; Tue, 10 Dec 2019 22:59:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18A35214AF for ; Tue, 10 Dec 2019 22:59:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G82pAauu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727137AbfLJW7a (ORCPT ); Tue, 10 Dec 2019 17:59:30 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35955 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727308AbfLJW7a (ORCPT ); Tue, 10 Dec 2019 17:59:30 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so5007376wma.1 for ; Tue, 10 Dec 2019 14:59:28 -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=Mp4QZuCv/bRaTlgmXO+s2ke2zrCF1j1W/eYiBLPTEbw=; b=G82pAauuBu5s+uTvRRZ+Y+3G4/pRz1HbZbHLnnUzqZNKQOh8DPXNEU6Kni0RSKi32o QuEqMxh8RMh4ytG+YZKVokDqCuE6Ks5C4JwpNvlFDm1dtjfVe1WheCLBJL0KkBJfXtf9 UUZpBaTP6W7t/cpeaB2BzpFKRkHfKLUzkulCF6/vLYLv6kGz4RAoXRCUsmyOOfnvQdQH LHXgIhdakagVlFUu+qwZE6xRWUcWo4HSJdvp3f7Lz4oybEpYWfk6n+EkO/g1/QGdDWlP Um03U7TkQ+lEZDfjELv2mck9pIEH43+m5DDUT2lXno0wqv2eV2EYwA91l4Md29NCujNo g3wA== 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=Mp4QZuCv/bRaTlgmXO+s2ke2zrCF1j1W/eYiBLPTEbw=; b=M+BT36Py6VRw4VZry2Zc4MUvIqLHreZiBGJ7ZB8t+5AiIqO8YWa0bDAZcf0vH0+l+G ITyfnYOXrLd6spX0X5UIz/ifsti/yKWPgXJbLvo3vUNml5xA4zinsV6d6taKhLvWjHa2 SVJ4BM7MGo3193SsnectdAT/+CK0GanEgM+syrfCQEAmy4RERvQHmJxjliAOTOcb/BPn OzE82GzLyram8j9NQHk7y0knRLqjc+L2ontQnglhl3cI9smuYL13qQroQy3WhdroxXDa RAkZ7Z5Ip+mAl6kr5+UcmTHu5B0HlWLsM2sO55Rz8HosomRmwXTJwj4Vsum1qs5ibqOP DSdg== X-Gm-Message-State: APjAAAWwRVhCb2tpN6OSGoVHAi4/r4IZ8zllEe4F42hr6bBslgzM3tQg ICsN+AI5nbn/xfB9BV1cElc4qoe8 X-Google-Smtp-Source: APXvYqx6hvTcxHxx+e3cmPFzM/dUtNKhdyOo08nSJ0cL8Fou/qZ8Q8Z52PVPZoLm6WGHx/xMe2iUHw== X-Received: by 2002:a1c:407:: with SMTP id 7mr7512264wme.29.1576018767516; Tue, 10 Dec 2019 14:59:27 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:26 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 01/17] split testcases for type punning & constant initializer expansion Date: Tue, 10 Dec 2019 23:59:05 +0100 Message-Id: <20191210225921.94897-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Several issues were covered by the same testcase. Fix this by splitting the testcases. Also, rename these testcases to a more descriptive name. Signed-off-by: Luc Van Oostenryck --- validation/expand/constant-union-flt2int.c | 21 +++++++++++++++++++ validation/expand/constant-union-int2flt.c | 20 ++++++++++++++++++ .../constant-union-size.c} | 6 +++--- .../type-punning-flt2int.c} | 4 ++-- validation/memops/type-punning-int2flt.c | 20 ++++++++++++++++++ 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 validation/expand/constant-union-flt2int.c create mode 100644 validation/expand/constant-union-int2flt.c rename validation/{bug-expand-union0.c => expand/constant-union-size.c} (60%) rename validation/{bug-expand-union1.c => memops/type-punning-flt2int.c} (68%) create mode 100644 validation/memops/type-punning-int2flt.c diff --git a/validation/expand/constant-union-flt2int.c b/validation/expand/constant-union-flt2int.c new file mode 100644 index 000000000000..1c8f480b6c81 --- /dev/null +++ b/validation/expand/constant-union-flt2int.c @@ -0,0 +1,21 @@ +union u { + int i; + float f; +}; + +static int foo(void) +{ + union u u = { .f = 0.123 }; + return u.i; +} + +/* + * check-name: constant-union-float-to-int + * check description: must not infer the int value from the float + * check-command: test-linearize -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): setfval\\. + * check-output-pattern(1): load\\. + */ diff --git a/validation/expand/constant-union-int2flt.c b/validation/expand/constant-union-int2flt.c new file mode 100644 index 000000000000..ff0a642ad67d --- /dev/null +++ b/validation/expand/constant-union-int2flt.c @@ -0,0 +1,20 @@ +union u { + int i; + float f; +}; + +static float foo(void) +{ + union u u = { .i = 3 }; + return u.f; +} + +/* + * check-name: constant-union-int-to-float + * check description: must not infer the float value from the int + * check-command: test-linearize -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-pattern(1): load\\. + */ diff --git a/validation/bug-expand-union0.c b/validation/expand/constant-union-size.c similarity index 60% rename from validation/bug-expand-union0.c rename to validation/expand/constant-union-size.c index dd6d60c3e291..b6c3ac75ae4b 100644 --- a/validation/bug-expand-union0.c +++ b/validation/expand/constant-union-size.c @@ -10,9 +10,9 @@ static int foo(void) } /* - * check-name: bug-expand-union - * check description: must not infer the value from the float - * check-command: test-linearize $file + * check-name: constant-union-size + * check description: the size of the initializer doesn't match + * check-command: test-linearize -fdump-ir $file * check-known-to-fail * * check-output-ignore diff --git a/validation/bug-expand-union1.c b/validation/memops/type-punning-flt2int.c similarity index 68% rename from validation/bug-expand-union1.c rename to validation/memops/type-punning-flt2int.c index 582a1f4f837e..a76c6c1da534 100644 --- a/validation/bug-expand-union1.c +++ b/validation/memops/type-punning-flt2int.c @@ -10,8 +10,8 @@ static int foo(void) } /* - * check-name: bug-expand-union - * check description: must not infer the value from the float + * check-name: type-punning-float-to-int + * check description: must not infer the int value from the float * check-command: test-linearize $file * check-known-to-fail * diff --git a/validation/memops/type-punning-int2flt.c b/validation/memops/type-punning-int2flt.c new file mode 100644 index 000000000000..c05ce252f305 --- /dev/null +++ b/validation/memops/type-punning-int2flt.c @@ -0,0 +1,20 @@ +union u { + int i; + float f; +}; + +static float foo(void) +{ + union u u = { .i = 3 }; + return u.f; +} + +/* + * check-name: type-punning-int-to-float + * check description: must not infer the float value from the int + * check-command: test-linearize $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: load\\. + */ From patchwork Tue Dec 10 22:59:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283501 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C4B9515AB for ; Tue, 10 Dec 2019 22:59:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A342D2073B for ; Tue, 10 Dec 2019 22:59:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KiLhcxTM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbfLJW7c (ORCPT ); Tue, 10 Dec 2019 17:59:32 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35470 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbfLJW7c (ORCPT ); Tue, 10 Dec 2019 17:59:32 -0500 Received: by mail-wr1-f68.google.com with SMTP id g17so21976674wro.2 for ; Tue, 10 Dec 2019 14:59:30 -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=eV6E9o4k7oQg2TyuMgE3WA+OQdQGPvJdxtLgTH97iWo=; b=KiLhcxTMRY9dAVR5yny7ARLWaobQCOcJpmtij1TKRFAxgj02lcYpRGhhv5OCA8Hshe lo5rNty27dHJCggW01TTwndNrbXUisYZty0TY0qC2Wv5bRW2uqybX2E05+aJsP8Ya5// 0ry8xkUM5KCU0IAXYfDVkoksQ32c2vRqiothWpBxAQ+cSS9J+AVhmxOg7KmLszfkmj9P GLVwh8aadb9JtujTXfFF9UcoNgVpeSbZ+XgVkv5kEowXAP7fhvPzd9Z+N7HUzxpLo0hj VxzxHmijDRIEqGapZSga8GQ47zM/nrDcSaIJF10IIuV6bA+TkN/PrLCZCt9Czq1evAda mwLA== 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=eV6E9o4k7oQg2TyuMgE3WA+OQdQGPvJdxtLgTH97iWo=; b=fV9po6pA0Rvvx7glnjUUH3NbVGVgzfZWnSOQtt1/bENFu5zw5TCR5V9QTRuAeDKZbw Bi7qTn0BqGaBlXJQOzc29GaowCjjJB+tCId85k6MqRBFJFyYm4ibXpmgVS4JD+MFh0+E muaxlnUYD/z6+J/V6yaulQrnKmPv3jW/7vi64bo7Lh8bn+JsA1Jbou1Iw6YBvxuToYyv 0WonaK5nUBi/elmcYxqOr31Y1U8DWXdfuWp9j2LIDE8fmZCdQ+d3KrligLU95ASZmbyj B9UzKMKAnOt0Imsu/o1SkexpPw5kKWt6PPN61DzmCvYnXzuhkiHUG6szu8/Gtw3vaDZW ObTg== X-Gm-Message-State: APjAAAWZnJw/pPQXeG41cMZpwf7a968r1HMRS569GYRAR6LicZf2ohi9 vWzgyFQAtAE1G18QW76ltbgT28Nu X-Google-Smtp-Source: APXvYqy/sqFHn9JDlFUzANqeK2NcPhZVMck35RopbUp3kEQSbGpsGCmyj0wte2ZB7wVNB5h2yp4GPg== X-Received: by 2002:adf:9427:: with SMTP id 36mr12034wrq.166.1576018769554; Tue, 10 Dec 2019 14:59:29 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:28 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 02/17] add testcase for expansion of default initializers Date: Tue, 10 Dec 2019 23:59:06 +0100 Message-Id: <20191210225921.94897-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, constant_symbol_value() is doing the expansion of a constant initializer when an explicit one is found but nothing is done for the default/implicit ones. Add a testcase to illustrate this. Signed-off-by: Luc Van Oostenryck --- validation/expand/default-init-array.c | 16 ++++++++++++++++ validation/expand/default-init-struct.c | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 validation/expand/default-init-array.c create mode 100644 validation/expand/default-init-struct.c diff --git a/validation/expand/default-init-array.c b/validation/expand/default-init-array.c new file mode 100644 index 000000000000..b372ea09534b --- /dev/null +++ b/validation/expand/default-init-array.c @@ -0,0 +1,16 @@ +int test_array(int i) +{ + static const int a[3] = { [0] = 1, [2] = 3, }; + + return a[1]; +} + +/* + * check-name: default-init-array + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: phisrc\\..*return.*\\$0 + * check-output-excludes: load\\. + */ diff --git a/validation/expand/default-init-struct.c b/validation/expand/default-init-struct.c new file mode 100644 index 000000000000..c843a1abb960 --- /dev/null +++ b/validation/expand/default-init-struct.c @@ -0,0 +1,23 @@ +struct s { + int a; + int b; + int c; +}; + + +int test_struct(void) +{ + struct s s = { .a = 1, .c = 3, }; + + return s.b; +} + +/* + * check-name: default-init-struct + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: phisrc\\..*return.*\\$0 + * check-output-excludes: load\\. + */ From patchwork Tue Dec 10 22:59:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283503 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78BA214B7 for ; Tue, 10 Dec 2019 22:59:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55B862073B for ; Tue, 10 Dec 2019 22:59:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nZ6wsOc+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727030AbfLJW7e (ORCPT ); Tue, 10 Dec 2019 17:59:34 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35479 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727319AbfLJW7e (ORCPT ); Tue, 10 Dec 2019 17:59:34 -0500 Received: by mail-wm1-f65.google.com with SMTP id p17so646989wmb.0 for ; Tue, 10 Dec 2019 14:59:32 -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=GjiF8yq5WD9voW0x1Hi/KZkZ0S4Kegr+L+6U1f5KOF4=; b=nZ6wsOc+6+Xt7HZQyICD17XHaIf8rz1hUzfl2zMF2wI4STUqJ4EJuDHs64ohatelZQ tu6zMfwIEhWdGRjCON52eRKGWz2rfNFoPp7N+CLjLlMf9oGQ8QMzlj16AusuZfpmvU68 gQ9TP3QnYjlvx7QM/7451erkPuU6v3mmfPXPnI7+Z04NN5Ljk8bXUqQYOZn25uI1NXlj ytK94iJU/Ol84kosbHQc+KSvpijCVZ1ikypkCvggueH/fD19tRxjfOcB1NfBobVwzCHs uegrgjnE7kkOuJaUiYZivGQtI0CjfycSg86NsP8uX/IlaIGySuoznB7d5gdLlQ+uEH+P thLw== 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=GjiF8yq5WD9voW0x1Hi/KZkZ0S4Kegr+L+6U1f5KOF4=; b=Za01I8hP2haZaDVOsVExYYXUZnkzOPP7uiQW7T+IfIf1jbRJmSSS+7xJjEqYF6pBHn 2BLQzABie3pbLpmMj/LqyflSBz/I5TaYeaBQd2usTJ3bKglAb6+KEoQ6ePTq9Bjc6+l1 Tno+mxuoxwR9yHU+3WTJbFCQbG+wuhUMkq8utfcB33H8fnp/OBH5nVeDHjEakfOMYZXi 8knylCoruYF2UR7LNrgMZGkH119xD7ljjoVXTujX/sS538YekhfD1mMrpecS2AeCorml TYTaT6Ve4z03sb6KCAdkf+unZlOId9qp8d+8PdAvnb0x8xPfljFjy/D5A0LUVEhjYrp0 DUUA== X-Gm-Message-State: APjAAAWy5N+bYMljSu9RVLz28tkbtRqIfafuPPM3cmKHv0zR6T3VxvtE /AogkDFPvCcnDnE4BvqR8cvnERpH X-Google-Smtp-Source: APXvYqzMKspU9B1/xVhU/uy/YFzoznV7iwVagkJwlIcbhSIecKXVLrAlfyHNDX0gKm3ta43i1mdGOA== X-Received: by 2002:a7b:c389:: with SMTP id s9mr7792656wmj.7.1576018771328; Tue, 10 Dec 2019 14:59:31 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:30 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 03/17] add testcase for addressability of degenerated symbol Date: Tue, 10 Dec 2019 23:59:07 +0100 Message-Id: <20191210225921.94897-4-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org An array or a function that degenerates into a pointer has its address implicitly taken since the result is equivalent to '&array[0]' or '&fun'. So, the corresponding symbol needs to be marked as addressable, like when its address is explicitly taken. Add a testcase to illustrate this. Signed-off-by: Luc Van Oostenryck --- validation/eval/addressable-degen.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 validation/eval/addressable-degen.c diff --git a/validation/eval/addressable-degen.c b/validation/eval/addressable-degen.c new file mode 100644 index 000000000000..e1dc51079079 --- /dev/null +++ b/validation/eval/addressable-degen.c @@ -0,0 +1,18 @@ +extern void def(void *, unsigned int); + +static int bar(void) +{ + int x[2] = { 1, 2 }; + + def(x, sizeof(x)); + return x[1]; +} + +/* + * check-name: eval/addressable-degen + * check-command: test-linearize -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: load\\. + */ From patchwork Tue Dec 10 22:59:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283505 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 347D914B7 for ; Tue, 10 Dec 2019 22:59:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1301B2073B for ; Tue, 10 Dec 2019 22:59:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OqJlOYlX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727328AbfLJW7f (ORCPT ); Tue, 10 Dec 2019 17:59:35 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39239 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727319AbfLJW7f (ORCPT ); Tue, 10 Dec 2019 17:59:35 -0500 Received: by mail-wm1-f65.google.com with SMTP id d5so3454977wmb.4 for ; Tue, 10 Dec 2019 14:59:34 -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=64dP83aiGdqIfmCSM9FR/z4wEbzzr4BTP8YXJumpLig=; b=OqJlOYlXnLVH/SfZXJ1nmyvLwZNEyQ3noRsM0I9VdL6KjlekQc0p4dC2Z/SuY3y+ML b0Owyh9ZBmuGvOo/3Q3w1rzsXl/CzS4p/jjPUuDXaeHxQ0FCht6LsU1ZWqmz+fL4Q34h TQW3qWSxRfcAbTg+kdVe0mpChfrhJsr6h5+i0BfL5bA+FzSF0RQV1q1TjBmCZQDRbgQK 4Tcggb6o9HMiLHf8BBKvCVUZUsI1k4vTEq3fQD4EGimFMtV6GX4m9WkyryONmo3GE6ar kvepWAjCeyq5k6ffUmuOFzplhZKyUku52A72ZasJrCVGvOv96QcBMwx54LgD4LJdBvWl EYjA== 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=64dP83aiGdqIfmCSM9FR/z4wEbzzr4BTP8YXJumpLig=; b=pL2rK6DRLo6AvfTMi2CG77qC1dNevmd0pUqh2xKRwStUvft73dv6+EdeiLRnKyogsV 81vfdaNgkRHh1MLqxen/lk108W05sObbJ6dNKbPZxPAioyi/DBeMNtOzToLlAk5XJWxR gVIzj3PSdxB8vE/91u2MAb0aYZIEQMloY6SN3oxQHjPi2yQJxbQtneGYOlc6AqzRracH Hxu9lJsrkyoZjW0gkyZlEHYAnZbb2n+k+Bis4ai2y28pz5O7u5invA4i0LPtBTe0sZ7e ui1DTPuVYZrXQHttQKFAl8uiMkyGaOcha5hyj8qVb/zrmx7SvcCEdZklPO8KAL18SPMv 3+oQ== X-Gm-Message-State: APjAAAWMFw+ZPM0Q8yNzDoQEJWVbo5OidOBP465Y/oWmWzZ8NPBRN1WD dGmaw3NBjawqynJFX23ik92oW2zo X-Google-Smtp-Source: APXvYqyzs84161sWuXRM+4G/kZPBBeicceybmf5cgRWeO9nphHDmj4t9aO/e4ZXLMnR1APRsSpHtyg== X-Received: by 2002:a1c:960c:: with SMTP id y12mr7718029wmd.9.1576018773188; Tue, 10 Dec 2019 14:59:33 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:32 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 04/17] add testcase for addressability of 'complex' symbols Date: Tue, 10 Dec 2019 23:59:08 +0100 Message-Id: <20191210225921.94897-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Once a symbol has its address taken, a lot of simplifications must be avoided because the symbol can now be modified via a pointer. This is currently done but the symbol addressability does not take in account the fact that a symbol can be accessed via one of its subfields. Add a testcase to illustrate this. Signed-off-by: Luc Van Oostenryck --- validation/eval/addressable-complex.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 validation/eval/addressable-complex.c diff --git a/validation/eval/addressable-complex.c b/validation/eval/addressable-complex.c new file mode 100644 index 000000000000..62ab59f04cf9 --- /dev/null +++ b/validation/eval/addressable-complex.c @@ -0,0 +1,24 @@ +extern void def(void *); + +struct s1 { + int a; +}; + +int use1(void) +{ + struct s1 s = { 3 }; + + def(&s.a); + + return s.a; +} + +/* + * check-name: eval/addressable-complex + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: load\\. + * check-output-excludes: return\\..*\\$3 + */ From patchwork Tue Dec 10 22:59:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283507 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74882930 for ; Tue, 10 Dec 2019 22:59:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 531102073B for ; Tue, 10 Dec 2019 22:59:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sFmlIKYM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727319AbfLJW7h (ORCPT ); Tue, 10 Dec 2019 17:59:37 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38231 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727313AbfLJW7h (ORCPT ); Tue, 10 Dec 2019 17:59:37 -0500 Received: by mail-wr1-f67.google.com with SMTP id y17so21976899wrh.5 for ; Tue, 10 Dec 2019 14:59:35 -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=0GjbWAwcLKkqwmmp0UchlI/mK05K5fPhHLmCgtC5tzA=; b=sFmlIKYMETgux8y+wzlUxAhPX5tqo6WtRhAMKtFTH0vlXFMXbDOE1Rkem3o7S2S7nM GBy30tHtw8W2NWayM6a/y74dw3QClDtGOvdJTz4gvoRbccJVXrwuS+iGn+a21o7BPPRd cUEDZblZ966xH1N8i1GrBEJNP7KX8p08Lst6fxcQJF9G9my7dWAxwjImZDqn/s3/XyXr YoNRDppF5mmdswqCC0vWFJtOlVidwy0hCoOzfQwCgqIMvO5A8lv7EiIFT3svpIdpA+vU az8FGOWCwsvb3UK4rZR/QsxZ1Ks1Wr9J5kqNsHuhUZyV7M6IpYc8RO8SaHKT1P5u7z2E YVxg== 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=0GjbWAwcLKkqwmmp0UchlI/mK05K5fPhHLmCgtC5tzA=; b=IVIYNzKfd3BU7MmK5aKHF10bptqFr6M4LGZNebg0IXGmywoJy23mjUH7YoBapMEJlU G5sy+uAQ1dwVFNdBgaIU2BEt1U+SOU43U+YmylrZJSxgfjEnogFTHr8ItQ5d5IEpH5Er hqc1gpcB+sTUba64nVZXQjj8ozplJr6ConSZO2mLG4cdcrQ+pZN7emd92v+oaiicPRXO tSYccQRZZwA0VQSoWqZ1+J4OtfHW/p16EMrY2hMK3NEmT45oheJDUojf3Mcf0lo4WUHL modmcss4n9StCsviegl8zI1n8QO/A9MOJSq03+bYsZGIEObYCxVUln7fNmFTv26ok0g1 XxGQ== X-Gm-Message-State: APjAAAXTn6whuSuhc3EdHctL+Dwksft5jrWNOfWcWVu0YlylrWA+fiiF UPw2GRI8nr6RccXgW2BsojLmlID1 X-Google-Smtp-Source: APXvYqzBiAoFtvC0usogovvZ3fSj/GXdHCDLI0VExs7IL9jz+fg3rTbz2YuVw9kSlYsWSLmMAPTxQw== X-Received: by 2002:a05:6000:1044:: with SMTP id c4mr11155wrx.204.1576018774547; Tue, 10 Dec 2019 14:59:34 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:33 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 05/17] add test for union cast Date: Tue, 10 Dec 2019 23:59:09 +0100 Message-Id: <20191210225921.94897-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Sparse can't do this yet. So, add a testcase for it. Signed-off-by: Luc Van Oostenryck --- validation/expand/union-cast.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 validation/expand/union-cast.c diff --git a/validation/expand/union-cast.c b/validation/expand/union-cast.c new file mode 100644 index 000000000000..a28d01f22b92 --- /dev/null +++ b/validation/expand/union-cast.c @@ -0,0 +1,27 @@ +union u { + int i; + struct s { + int a; + } s; +}; + +int foo(void) +{ + struct s s = { 3 }; + union u u = (union u)s; + return u.s.a; +} + +/* + * check-name: union-cast + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: load\\. + * + * check-error-start +union-cast.c:11:22: warning: cast to non-scalar +union-cast.c:11:22: warning: cast from non-scalar + * check-error-end + */ From patchwork Tue Dec 10 22:59:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283509 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 13060930 for ; Tue, 10 Dec 2019 22:59:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5F012073B for ; Tue, 10 Dec 2019 22:59:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uFv0YYzX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727333AbfLJW7i (ORCPT ); Tue, 10 Dec 2019 17:59:38 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54964 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727313AbfLJW7i (ORCPT ); Tue, 10 Dec 2019 17:59:38 -0500 Received: by mail-wm1-f65.google.com with SMTP id b11so5016725wmj.4 for ; Tue, 10 Dec 2019 14:59:37 -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=xOlHcyatID/+Hqqk50CoalJLN9Oe4eJ6EMLnj4fUfsE=; b=uFv0YYzXt2RQ90svAs2TRfJAx2Pb+2A75Sqctd5Zc3hiW723Jj+Vv2/317hjIBC9vN MlIh6X0YZSRvspXS4/By29t7Yc7vWFo0igMjyPUamwObVTtIyndYOwFQe6ecBbjKv5mU CK5MH7j1jdt5BQOZOOdFVpBvg1L/dbvETFp0wxjWJkTtCO6bsxdIPHGiwn9gccXSr31l zT0l4h82gDQqUPro6j0iHQH9VNSiQqTkMhxrQr4Weotd1z8XEI29rv7Mi8DATuX7i1TU 0Lgd9OEVquaruIyBq5yifFO/CxORMpd0OfTmYWcNIEO43kZhB0NVNdnVnth4YfFeZAgk IFbQ== 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=xOlHcyatID/+Hqqk50CoalJLN9Oe4eJ6EMLnj4fUfsE=; b=LHRdBLBtrTi4eLBrIWgKd+Nb0yadl/op593Nt6n9EyNLUclacrEHywOcY/F3qdW+Th ZXbA5bM+2WjfYDcCU9BxWg2Zq3vKJRVlB5rF7cRTuzhVdERkhtevz388cNX5ms4OF1W8 Sg+MNTbEV4IlwWDtUSg+2BE4y8dEnbOwldKtFnXDb1ClLUUr2xoNq8PAiNS8SWO4htZY edkNRJRqHoT4+TNiElXocihOanpzrogPTYNCJHmoUo0bX252HW4es5u6pnHJvNk2UnD5 M1mLA7gm4beIKIhJCNRs/sYyLYQ7UxWrSrJEAsxqHyE1NbefRRPPBdBSibqoVfCQpXNw rP3g== X-Gm-Message-State: APjAAAUF4UU05D5G/98+6t53//WJk7Y+Ck9MzWkm2c4TtuGJIabaYJOE eFjUPuikB+NxQlbwXuYad1HFaJ67 X-Google-Smtp-Source: APXvYqzfibM1F33Yyu5EkzpS8WA5NCmSqefWT0b/exfOUIw0jgo8FL7FoUC86zQnTFv25f1nitFL8w== X-Received: by 2002:a7b:c3d2:: with SMTP id t18mr1372285wmj.90.1576018776203; Tue, 10 Dec 2019 14:59:36 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:35 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 06/17] add test for dereference cost of symbol with complex type Date: Tue, 10 Dec 2019 23:59:10 +0100 Message-Id: <20191210225921.94897-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, in expand_dereference(), the dereference of a symbol with a complex type is considered as costing as high as a non-symbol because it's not recognised it's a symbol. Add a testcase for this. Signed-off-by: Luc Van Oostenryck --- validation/expand/cost-deref-nested.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 validation/expand/cost-deref-nested.c diff --git a/validation/expand/cost-deref-nested.c b/validation/expand/cost-deref-nested.c new file mode 100644 index 000000000000..b09602b6acc6 --- /dev/null +++ b/validation/expand/cost-deref-nested.c @@ -0,0 +1,21 @@ +struct s { + struct { + int u, v; + } a, b; +}; + +static const struct s s; + +static int foo(int c) +{ + return c && s.b.v; +} + +/* + * check-name: cost-deref-nested + * check-command: test-linearize -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: cbr + */ From patchwork Tue Dec 10 22:59:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283511 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A2E714B7 for ; Tue, 10 Dec 2019 22:59:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 28CDA2073B for ; Tue, 10 Dec 2019 22:59:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CrmTGzTS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727340AbfLJW7k (ORCPT ); Tue, 10 Dec 2019 17:59:40 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37893 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfLJW7j (ORCPT ); Tue, 10 Dec 2019 17:59:39 -0500 Received: by mail-wm1-f67.google.com with SMTP id p17so4987685wmi.3 for ; Tue, 10 Dec 2019 14:59:38 -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=yCF2A/nCI7F9g6PGaQnvTgxRRJMrMi2/HrjXDmBgOnY=; b=CrmTGzTSTmKSrzMz9RLip72conwt43ZY3hzyPCDnhd5L0zG4L8tZZZtM3i8CmaG3cX Odt0vfzHT1u5YnfTVzrjEGHeGD45690HCexS2BfvsqNbBfg4QUC/TcT6fXtvNQvyIvku qVelnb4XfTGQ9fgD6/4Zm6bFGVoH0aLoPeFWq1sibMf4Drn2Ndpm6tCjBcqdShUSXobV kYG5RWbh+Ot6yz/b/9pdKf8/71ytP7Kz8nhurGle+szVIynd2KpTpn0pTdkxL1uYxryd C3CnbxyzJbakfSrxQPgq8HkuEh6VsEg3VDqCw0iAKTMjHpLiL/Cf1cwDHGV+y/XNZQwE 7B6Q== 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=yCF2A/nCI7F9g6PGaQnvTgxRRJMrMi2/HrjXDmBgOnY=; b=hGBsM4IuVrYhFEzJ+GfJSvSppg8SEnjjCiDF5GAtYtF8bB2b0M6sHMl34zODWSEK4E aA/rlXX0jzSo+iJt2GqejRGCbuJ9QJ/qPgwsId4me8r9gqqtAJKGbpL78pkGYJtWCF8b OxhXMX65bJYAMyLXA6DwWS1lWcxBrLVs4F+LWPCjlknxafnrl5/Eu4vEv3KLR8dmxdH4 THTdGgS8mF673BGWysz6ho5lASYJCBBCaBTAwMcHz+7QHyoJTx9usx36e5f5LZtNJ1l2 gICPqwYW4fET4BvausaHoNt6YwgD0v9KouDf4iaJIhyYFFOAVMROvIB3ps757k1iuZ0r Jugg== X-Gm-Message-State: APjAAAXcxCTUpXKAY4XMxfCoLT3VYb/sJl4ZwcuHbcV+lBtq1082dU4c FaZbsvBKFnL6sVLGV76gS8XwMHi0 X-Google-Smtp-Source: APXvYqw/Mx6RchGfme8jkwplK/L4DyGyJxQRWRfPeflbdigCegkxh5OQc1XTYt4W884/Jj/ItQaQKw== X-Received: by 2002:a7b:c761:: with SMTP id x1mr7518045wmk.37.1576018777463; Tue, 10 Dec 2019 14:59:37 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:36 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 07/17] add test for constant expansion of complex initializer Date: Tue, 10 Dec 2019 23:59:11 +0100 Message-Id: <20191210225921.94897-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Constant expansion of symbols with a complex type is not done like for simpler ones. Only the first-level EXPR_INITIALIZER is handled. Add some testcases for this. Signed-off-by: Luc Van Oostenryck --- .../expand/constant-init-nested-array.c | 15 ++++++++++++ .../expand/constant-init-nested-struct.c | 23 +++++++++++++++++++ validation/expand/constant-init-string.c | 15 ++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 validation/expand/constant-init-nested-array.c create mode 100644 validation/expand/constant-init-nested-struct.c create mode 100644 validation/expand/constant-init-string.c diff --git a/validation/expand/constant-init-nested-array.c b/validation/expand/constant-init-nested-array.c new file mode 100644 index 000000000000..0d50d955287c --- /dev/null +++ b/validation/expand/constant-init-nested-array.c @@ -0,0 +1,15 @@ +int foo(void) +{ + int a[2][3] = {{0, 1, 2},{3, 4, 5}}; + return a[1][2]; +} + +/* + * check-name: constant-init-nested-array + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: phisrc\\..*\\$5 + * check-output-excludes: load\\. + */ diff --git a/validation/expand/constant-init-nested-struct.c b/validation/expand/constant-init-nested-struct.c new file mode 100644 index 000000000000..f27de556f6c5 --- /dev/null +++ b/validation/expand/constant-init-nested-struct.c @@ -0,0 +1,23 @@ +struct s { + int a; + struct { + int b; + int c; + } s; +}; + +int foo(void) +{ + struct s s = {1, {2, 3}}; + return s.s.c; +} + +/* + * check-name: constant-init-nested-struct + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: phisrc\\..*\\$3 + * check-output-excludes: load\\. + */ diff --git a/validation/expand/constant-init-string.c b/validation/expand/constant-init-string.c new file mode 100644 index 000000000000..42ae9bd3d8a4 --- /dev/null +++ b/validation/expand/constant-init-string.c @@ -0,0 +1,15 @@ +char foo(void) +{ + static const char s[] = "abc?"; + return s[3]; +} + +/* + * check-name: constant-init-nested-array + * check-command: test-linearize -Wno-decl -fdump-ir $file + * check-known-to-fail + * + * check-output-ignore + * check-output-contains: phisrc\\..*\\$63 + * check-output-pattern(0,1): load\\. + */ From patchwork Tue Dec 10 22:59:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283513 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8D9314B7 for ; Tue, 10 Dec 2019 22:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A748B2073B for ; Tue, 10 Dec 2019 22:59:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CTUM8Tw2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727349AbfLJW7l (ORCPT ); Tue, 10 Dec 2019 17:59:41 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50443 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727313AbfLJW7l (ORCPT ); Tue, 10 Dec 2019 17:59:41 -0500 Received: by mail-wm1-f67.google.com with SMTP id p9so5041913wmg.0 for ; Tue, 10 Dec 2019 14:59:39 -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=enqUqKi8TMXrJ+sAE3h1BzmZePnagWROYI3DQK5bfgA=; b=CTUM8Tw2PTxuPEoVS7/21UQS+beOtHCJRThlsw8523tceZ/RVFZgEcUqCMnRdkDtKa QlxXsgIuWENrwdeOXyZByEg99ZHjZlNLjrFKaYZ+BMv5UXwao+iAB4YRWDZe3JdDm4JY qf8J4DQoVby/Dy3tZ6ufeYpyIXHd3AL2LJXtxKJZrFhLG/MzKEHilqBYKTloiEDxcWaT y3TPKwgiNL8M7Ag1k6BeqIvqcbFwLHgxThAyaGuQAUfMnmRKoB1ELj93IAusVGzodwh9 Vv9LJdR9o1z6Jd/cfdrkmSYx54a5vvXFNm0CtWI4Czg4y1y5rFZmj4Ne5Y6mEZiCAtEZ gdFg== 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=enqUqKi8TMXrJ+sAE3h1BzmZePnagWROYI3DQK5bfgA=; b=WafR2MczpnJcymldsgwO3wiEAU1wXE1ud/2YnQHUS4iCabwMM71CRBPRTmhQhPwxif 7Zq9gQ/mcVnosGzYtLv2b3X8xaLG+AcEnVIRHzjDtgnq89NhMM3y60VE3OpKZrFdohkV 5wzUOI9PiLBuQ565xwY2ofN/S/qWT7mmjn6qitxN0XTj8uxCGDIuNr0SPGkzwQ8An8X3 WERwNmBYOI7eAxcLpSdIDL96dOk5n/yKhTLSn9oAmEjF/v3Iq/u2PZaK2VdNvtAL7f+b XZav6dp4LSV4DEBUAsNf2kL+U+akzrgcWPB7pKjO/aOgm9Os0yxKy9wtpvUGa8UZyv2s aMcA== X-Gm-Message-State: APjAAAWLD2InKfajs9UndmRHs5lgRvqJxPL1wkijfy9RRUXRwIkVnhD1 qtrsbnxGG8HLr+JGGcuRWZnEE4ok X-Google-Smtp-Source: APXvYqz4PWcmb6oizNYY9J2H7vClsUm1bWqx+aBWle7YugqCrQSGQEAao3PYxVokJy/B1/xKQyyhTQ== X-Received: by 2002:a1c:5981:: with SMTP id n123mr7386253wmb.52.1576018778579; Tue, 10 Dec 2019 14:59:38 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:37 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 08/17] extract mark_addressable() from evaluate_addressof(). Date: Tue, 10 Dec 2019 23:59:12 +0100 Message-Id: <20191210225921.94897-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org This is just moving the 3 lines of code to mark a symbol as addressable in a speparate function. This is a preparatory step for one of the next patches. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/evaluate.c b/evaluate.c index 19bdab920009..d78de2edf1ed 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1540,6 +1540,14 @@ static int compatible_argument_type(struct expression *expr, struct symbol *targ return compatible_assignment_types(expr, target, rp, where); } +static void mark_addressable(struct expression *expr) +{ + if (expr->type == EXPR_SYMBOL) { + struct symbol *sym = expr->symbol; + sym->ctype.modifiers |= MOD_ADDRESSABLE; + } +} + static void mark_assigned(struct expression *expr) { struct symbol *sym; @@ -1780,10 +1788,7 @@ static struct symbol *evaluate_addressof(struct expression *expr) ctype = op->ctype; *expr = *op->unop; - if (expr->type == EXPR_SYMBOL) { - struct symbol *sym = expr->symbol; - sym->ctype.modifiers |= MOD_ADDRESSABLE; - } + mark_addressable(expr); /* * symbol expression evaluation is lazy about the type From patchwork Tue Dec 10 22:59:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283515 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 782FE930 for ; Tue, 10 Dec 2019 22:59:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 56B442073B for ; Tue, 10 Dec 2019 22:59:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lJpfIo5b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727370AbfLJW7m (ORCPT ); Tue, 10 Dec 2019 17:59:42 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35971 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfLJW7m (ORCPT ); Tue, 10 Dec 2019 17:59:42 -0500 Received: by mail-wm1-f68.google.com with SMTP id p17so5007677wma.1 for ; Tue, 10 Dec 2019 14:59:40 -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=gawWO15ANRZ7k9UQe+4ejl7GJWafn8IHartUbp+8hTs=; b=lJpfIo5b998CagFpDa9i401oBqeBXM4TuszYMx68XBrUxQnKv0eBUKqDg0JEF8bmOd BuOv5VKwOawUf6LYXoZi5PD5yh6gVQn4kYt891sQOZruAjy0WWT83zrTBqf2tKqTbt0L CaTLplpBhsGQqZG9Y5in/rpEmAJI76mdC61GMOhxnEOoQHyCOLnmjL1L5dgmDcltrWuk es9I+5M9BOI/97kCuTrMmQcXxTq1e2YAtrzRI1CKOP4pGk/RX8mwe1TnMZ1xX3vYmFPs zoaB/mDuUwtJTqtjyPSS6kwkwcbpjJMoTowVOOaGrGVKKsobQKCrQ0pfuQNwfac5IQon lV/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=gawWO15ANRZ7k9UQe+4ejl7GJWafn8IHartUbp+8hTs=; b=nwUAKjT1vvT7E7VYmQTHgQCgl8hc6yRX10xcRB0l4I6ww4Wx3lcEAe1OIVhpMxKGNu IW2yTEInG9aG8dy4lTaI1tT99gfZLqNADi+bgf3WYqOl7N+NwhbxF9tvyN8qlWmsHT+l zzZ6/DUp4uhVYJM0aaylmYYOZ0lBKhb5AprOkDGfM/R0P6tLPs7zRLv/jjCJ4RfYakh2 yBnxVGqqhyM2OVp8mj6oRmRW/V8tUWsDAeyRZm+YC7FIuz/PiyQ2o0wtUDCCB9oRxWwb wo+KI901AjhpVWnwML69EWAIPJIDDMIOcG1wMwSMcCk4WTTGrnN0B1q22D3zmTlwV9Lv EjKQ== X-Gm-Message-State: APjAAAX2ITCNGfKKxkHxkzhqS+UdeayzaJnb8QNOrosbZH9KHHkxA+NX JLa6tU2mrdPsao+06Il9PKfv6mME X-Google-Smtp-Source: APXvYqwE8o7Wg8eO04PLYKpsR0nCdQ4bO19rMUGyPFRSUitz/aFhmtmbeEFCFMTApK+LSqTEBmfMvA== X-Received: by 2002:a7b:c757:: with SMTP id w23mr7242709wmk.166.1576018779391; Tue, 10 Dec 2019 14:59:39 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:38 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 09/17] fix addressability marking in evaluate_addressof() Date: Tue, 10 Dec 2019 23:59:13 +0100 Message-Id: <20191210225921.94897-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org mark_addressable() is used to track if a symbol has its address taken but does not take in account the fact that a symbol can be accessed via one of its subfields. A failure occurs in case like: struct { int a; } s = { 3 }; ... def(&s.a); return s.a; where 's' is not marked as being addressable and so the the initializer will be expanded and the return expression will always be replaced by 3, while def() can redefine it. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 2 ++ validation/eval/addressable-complex.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/evaluate.c b/evaluate.c index d78de2edf1ed..c0281e9b10f2 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1542,6 +1542,8 @@ static int compatible_argument_type(struct expression *expr, struct symbol *targ static void mark_addressable(struct expression *expr) { + while (expr->type == EXPR_BINOP && expr->op == '+') + expr = expr->left; if (expr->type == EXPR_SYMBOL) { struct symbol *sym = expr->symbol; sym->ctype.modifiers |= MOD_ADDRESSABLE; diff --git a/validation/eval/addressable-complex.c b/validation/eval/addressable-complex.c index 62ab59f04cf9..e3d4aca49088 100644 --- a/validation/eval/addressable-complex.c +++ b/validation/eval/addressable-complex.c @@ -16,7 +16,6 @@ int use1(void) /* * check-name: eval/addressable-complex * check-command: test-linearize -Wno-decl -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-contains: load\\. From patchwork Tue Dec 10 22:59:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283517 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9F5C14B7 for ; Tue, 10 Dec 2019 22:59:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7B492073B for ; Tue, 10 Dec 2019 22:59:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HwetdMyC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726988AbfLJW7n (ORCPT ); Tue, 10 Dec 2019 17:59:43 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43236 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727313AbfLJW7n (ORCPT ); Tue, 10 Dec 2019 17:59:43 -0500 Received: by mail-wr1-f66.google.com with SMTP id d16so21928600wre.10 for ; Tue, 10 Dec 2019 14:59:41 -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=cVO8dfyonfbXnmx4H8gCH0ESqVER87MBGefYj1Sr7rY=; b=HwetdMyC/5q8Iubx0H7f1YPSKCO9uHh9WJHaDpBVOAlhqvKQlHszFo+qp2QBi1fnLI dYgWogHw9L1EYgR2sL+tpTTaZCSwN4N5jJXgu/PGO5yv3IH75hGoCu7lcF6251NHlAZr rhi2AF4nkALcvFBDYkBcDInshIl8Ii/FooghxeSg5AQfuu7drbRF9snOM2PfHRyw9sSH 4hhkZVDcb3hgcLzNUIDBHCfbQ5JzlMkFm+Bdqaw7ZnnkrvOo47kAoJi+F4AH0KSt03rB rEUdAKglm1MkfiBdWLIzu0n8PTsLvNGtFIAPl0UjXXUKj1FRaYm8DKlOmZEk+wZGw/D1 qSVA== 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=cVO8dfyonfbXnmx4H8gCH0ESqVER87MBGefYj1Sr7rY=; b=E4OP7C77Q9zIc5yrtXiUKz7c6bOGZ5yzyXGKefPpLvspQsvxtrAgq0Fv2/WXWQfQAl f1QlsL25680fhENexvGRSUJ3gpzAN+rgl7GzFvR/ahy+m86eLEFYVU8I8bCGTVDBI8We XPKB99yNfLBoyQPs8t/NTOmjN9Ui7Xtj2sTyC+8aMmXLlQOL6T4nD79JbxU9ww7yKV4K MFzZUjyR7ld8AAbtZVRN9vnvbCHBS+o+KzvpLNBmbV5SOvSBiAwnKdWkr35fo8cnS0b0 fskw3gmUe+jq3B4JFs89Xbnopt1CrbfxoHfwGwPsZZA0GspBMQ4lQ+8DuWPtOSXEIly4 cBZA== X-Gm-Message-State: APjAAAWdtjm8ipdprzUB9MiRWiD2c/NodexDGdDKDNXkuhrK3RX5Ih01 tmcwCnO0VGv+VeUlrV9pwbc4xR6p X-Google-Smtp-Source: APXvYqxMeK8eBNXy79SSPHOb1b6e8q1CovbjCfg/pePyhZPdHYANGiGNM+2skJ7S5of99lawH1ggZw== X-Received: by 2002:adf:8041:: with SMTP id 59mr5650882wrk.257.1576018780663; Tue, 10 Dec 2019 14:59:40 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:39 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 10/17] degenerated arrays & functions are addressable too Date: Tue, 10 Dec 2019 23:59:14 +0100 Message-Id: <20191210225921.94897-11-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Symbols which have their address taken (with the 'addressof' operator: &) are marked as such (with the modifier MOD_ADDRESSABLE). But degenerated arrays and functions have their address implicitly taken. MOD_ADDRESSABLE is used to prevent to replace a symbol dereference nto the value used to initialize to it. For example, in code like: static int foo(void) { int x[2] = { 1, 2 }; return x[1]; } the return expression can be replaced by 2. This is not the case case if the array is first passed in a function call, like here: extern void def(void *, unsigned int); static int bar(void) { int x[2] = { 1, 2 }; def(x, sizeof(x)); return x[1]; } Fix this by marking degenerated arrays (and functions) as also being addressable. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 1 + validation/eval/addressable-degen.c | 1 - validation/expand/constant-init-array.c | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 validation/expand/constant-init-array.c diff --git a/evaluate.c b/evaluate.c index c0281e9b10f2..11ad6a22c32f 100644 --- a/evaluate.c +++ b/evaluate.c @@ -1772,6 +1772,7 @@ static struct symbol *degenerate(struct expression *expr) *expr = *expr->unop; ctype = create_pointer(expr, ctype, 1); expr->ctype = ctype; + mark_addressable(expr); default: /* nothing */; } diff --git a/validation/eval/addressable-degen.c b/validation/eval/addressable-degen.c index e1dc51079079..d420927e0c71 100644 --- a/validation/eval/addressable-degen.c +++ b/validation/eval/addressable-degen.c @@ -11,7 +11,6 @@ static int bar(void) /* * check-name: eval/addressable-degen * check-command: test-linearize -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-contains: load\\. diff --git a/validation/expand/constant-init-array.c b/validation/expand/constant-init-array.c new file mode 100644 index 000000000000..94949be54244 --- /dev/null +++ b/validation/expand/constant-init-array.c @@ -0,0 +1,15 @@ +int test_array(int i) +{ + static const int a[3] = { 1, 2, 3, }; + + return a[1]; +} + +/* + * check-name: constant-init-array + * check-command: test-linearize -Wno-decl -fdump-ir $file + * + * check-output-ignore + * check-output-excludes: phisrc\\..*return.*\\$2 + * check-output-contains: load\\. + */ From patchwork Tue Dec 10 22:59:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBE1114B7 for ; Tue, 10 Dec 2019 22:59:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA6132073B for ; Tue, 10 Dec 2019 22:59:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YIeJR3SM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727378AbfLJW7o (ORCPT ); Tue, 10 Dec 2019 17:59:44 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38240 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfLJW7o (ORCPT ); Tue, 10 Dec 2019 17:59:44 -0500 Received: by mail-wr1-f67.google.com with SMTP id y17so21977077wrh.5 for ; Tue, 10 Dec 2019 14:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PsR62Tb/c3E/HIKOTY7w0ALpqA7AZ3b0zxAqIpRIkzs=; b=YIeJR3SM9KiieEPd8S5mpYeCKFhzlzjgZwmYlf9K5P6K8zOP2S8eOsRZgNulMwrd+o AJAPvAfdpDyBvhSE7hK2VceorN7X4/EZRaOmoicDOSjeENCnwx2xN3sRiQVpfFIIAdnl /OnL6AXkMdIFbcBU+E66ZSMWcfYXI4grr2HtDxbSAgcBzXpMa45t3sYOqaHbKg1dMooI uHb5HzhbDWR8C86Xoq75DzoFgodgJ62khsuCudXbzyPgUjeJV3tpNFFudhoJDGoN6b76 UgCXkVXaBeBatcd3ZB8nDJbJgOxLe+zt0CjfFuVXXQ29u7HiL00++xx9WVH1YGsXSs1w goGA== 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=PsR62Tb/c3E/HIKOTY7w0ALpqA7AZ3b0zxAqIpRIkzs=; b=MVzRWXfh9ckxfyYMExmYUcSXTGcDlvYqbcICsR0YUoDRDcXSu+4BQd7w5HzcbuY6sk IKZMX3RgLeZPGjgicsEsAygG17uN5BySnet2zMSvFjNvCXRR3Hqrh7oBw67b3oEb61n7 bmiEv2jof4GepFOFyfQcBS48WgH9J+WfYSDdyH6uF2AsV22CJCj8oCFK81AhP7ojzggW 3Lgj1GBE3Blb81ja0VfsKtqBzKssbaqbhHJEnIFLjBk5pwFcq9DAlq2A/67YFhxr9ale u0o+7hvRE9wR0fKCvkX+L3uMWMv/zSrUA2dB5utBpiQB8n+kxU3dy99TDXgpxyhPSeY8 eEqQ== X-Gm-Message-State: APjAAAUcO/OrUC43UaP1h96RoOihzTQWZvXlP18+8vhK38X5gByWAI6b NcDFcOi+2y65vTjKP52yNtcrpPL5 X-Google-Smtp-Source: APXvYqzC2f+o9YCQ3KDXdwdiEiXiKZtPE+qP8PYwLXvYxXJ18xo5x3cyBaHVM95OM4n3BW8oAna1cQ== X-Received: by 2002:a5d:6206:: with SMTP id y6mr19141wru.130.1576018782044; Tue, 10 Dec 2019 14:59:42 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:41 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 11/17] fix expansion of initializer (mismatching size) Date: Tue, 10 Dec 2019 23:59:15 +0100 Message-Id: <20191210225921.94897-12-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, the expansion of constant initializers is done whenever the offset in the initializer match the one we're expanding. However, it's not correct to do this expansion if their size doesn't match since in this case the value of one doesn't represent the value of the other. Fix this by adding a check for the size. Signed-off-by: Luc Van Oostenryck --- expand.c | 8 ++++---- validation/expand/constant-union-size.c | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/expand.c b/expand.c index ae764153d3e7..04b072c53b5a 100644 --- a/expand.c +++ b/expand.c @@ -625,8 +625,6 @@ static int expand_addressof(struct expression *expr) * Look up a trustable initializer value at the requested offset. * * Return NULL if no such value can be found or statically trusted. - * - * FIXME!! We should check that the size is right! */ static struct expression *constant_symbol_value(struct symbol *sym, int offset) { @@ -688,11 +686,13 @@ static int expand_dereference(struct expression *expr) if (unop->type == EXPR_SYMBOL) { struct symbol *sym = unop->symbol; + struct symbol *ctype = expr->ctype; struct expression *value = constant_symbol_value(sym, offset); /* Const symbol with a constant initializer? */ - if (value) { - /* FIXME! We should check that the size is right! */ + if (value && value->ctype) { + if (ctype->bit_size != value->ctype->bit_size) + return UNSAFE; if (value->type == EXPR_VALUE) { if (is_bitfield_type(value->ctype)) return UNSAFE; diff --git a/validation/expand/constant-union-size.c b/validation/expand/constant-union-size.c index b6c3ac75ae4b..8a16bf3e8033 100644 --- a/validation/expand/constant-union-size.c +++ b/validation/expand/constant-union-size.c @@ -13,7 +13,6 @@ static int foo(void) * check-name: constant-union-size * check description: the size of the initializer doesn't match * check-command: test-linearize -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-contains: load\\. From patchwork Tue Dec 10 22:59:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5C54930 for ; Tue, 10 Dec 2019 22:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C41372073B for ; Tue, 10 Dec 2019 22:59:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FrBj2mhU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727386AbfLJW7p (ORCPT ); Tue, 10 Dec 2019 17:59:45 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34596 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727313AbfLJW7p (ORCPT ); Tue, 10 Dec 2019 17:59:45 -0500 Received: by mail-wr1-f68.google.com with SMTP id t2so21994196wrr.1 for ; Tue, 10 Dec 2019 14:59:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=trnik3hp+CwVO2qEo8GM2UEPZkROfkBmfZGriDP/KOM=; b=FrBj2mhULcdowVCJ385LHYI0UWLaSUvo0NJTmsdstRpwnNTnIrUOlNCYaZkhQLIq1i JLN2wt+htkzORZWkpKOUvE+GXBrAVIkdGy6Ih4R161EVNGteO7AzxLvEXdZqi4PiXx2w ZTzG7QQqHQnJbf+g83+D4lSmdt0g+ADoRYmRPq0hzT4manPrcdzMkjig1SC8B8k+HWmV T08w3k7Fa2FnF8uLl7SdWur0kfr3A/Jbwhvdj9Ck8NQi+2oEbOK3t6eGQC0GwbqO9dwa LWIlO/6WoQOAmZH8CpBImNl/sFVMcqyARu/vG1qF1daih2C/FAbzDKhEtvev6NaDTpmC gdPg== 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=trnik3hp+CwVO2qEo8GM2UEPZkROfkBmfZGriDP/KOM=; b=gcE2YUj0d0+o/Bg2UDeJxWc5em3Gwo9uphSPrzXIvfmPn264L8Yx65xGVxdkR6/2+S PxRJVLbGjI9aPnpmov0KwfGajO5EpZTYzHiDwlolgbWqKgyYLM44czWP+MpCX5BK/24V oOpBfzTeZjUymq7/39UuhzIcPjDeaWJ1dZQsRoxDOzGhXEMY4v1XaTYxyWwgP8s1yWBW fgoJSf52jPYJ+8fVGpMBs3cOzDA/SKfDbSq/moaPy8O37yReCQGzyJXJ8YIz8Iugtjsk M11GaYtcY+E2pZeHCJY1yi3EsPrIX58siwyo/Fz0N+sGP+K94HOVcPfS+sN0EydRbY9h Y5eQ== X-Gm-Message-State: APjAAAWXSzAMhoyvq3by5AK8TKcmCgZxcb6L1NTfibR9lIKlzDOcmhKS TkTns49nkxFIhz5N1jMKk0Boe0wX X-Google-Smtp-Source: APXvYqyGLEkoO3rWIh5+dGxkhHW0S+3jymQH/f6BGeZj8xIDMwt8LRFQJl33+dXoqYf+kSywilU88Q== X-Received: by 2002:adf:e3d0:: with SMTP id k16mr5997917wrm.241.1576018783408; Tue, 10 Dec 2019 14:59:43 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:42 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 12/17] fix expansion of initializer (mismatching type) Date: Tue, 10 Dec 2019 23:59:16 +0100 Message-Id: <20191210225921.94897-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, the expansion of constant initializers is done whenever the offset in the initializer match the one being expanded. However, it's not correct to do this expansion of an integer with the initializer for a float and vice-versa. Fix this by adding the corresponding tests to the other tests of the value. Signed-off-by: Luc Van Oostenryck --- expand.c | 4 ++++ validation/expand/constant-union-flt2int.c | 1 - validation/expand/constant-union-int2flt.c | 1 - 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/expand.c b/expand.c index 04b072c53b5a..9ab259b13a82 100644 --- a/expand.c +++ b/expand.c @@ -694,6 +694,8 @@ static int expand_dereference(struct expression *expr) if (ctype->bit_size != value->ctype->bit_size) return UNSAFE; if (value->type == EXPR_VALUE) { + if (!is_integral_type(ctype)) + return UNSAFE; if (is_bitfield_type(value->ctype)) return UNSAFE; expr->type = EXPR_VALUE; @@ -701,6 +703,8 @@ static int expand_dereference(struct expression *expr) expr->taint = 0; return 0; } else if (value->type == EXPR_FVALUE) { + if (!is_float_type(ctype)) + return UNSAFE; expr->type = EXPR_FVALUE; expr->fvalue = value->fvalue; return 0; diff --git a/validation/expand/constant-union-flt2int.c b/validation/expand/constant-union-flt2int.c index 1c8f480b6c81..5e25b592b204 100644 --- a/validation/expand/constant-union-flt2int.c +++ b/validation/expand/constant-union-flt2int.c @@ -13,7 +13,6 @@ static int foo(void) * check-name: constant-union-float-to-int * check description: must not infer the int value from the float * check-command: test-linearize -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): setfval\\. diff --git a/validation/expand/constant-union-int2flt.c b/validation/expand/constant-union-int2flt.c index ff0a642ad67d..16ce1c6f3fe3 100644 --- a/validation/expand/constant-union-int2flt.c +++ b/validation/expand/constant-union-int2flt.c @@ -13,7 +13,6 @@ static float foo(void) * check-name: constant-union-int-to-float * check description: must not infer the float value from the int * check-command: test-linearize -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(1): load\\. From patchwork Tue Dec 10 22:59:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFDE614B7 for ; Tue, 10 Dec 2019 22:59:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE10D2073B for ; Tue, 10 Dec 2019 22:59:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RYPQfRpO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbfLJW7q (ORCPT ); Tue, 10 Dec 2019 17:59:46 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33748 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfLJW7q (ORCPT ); Tue, 10 Dec 2019 17:59:46 -0500 Received: by mail-wr1-f68.google.com with SMTP id b6so21996417wrq.0 for ; Tue, 10 Dec 2019 14:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kVioipiXHEmhP5HVeMLPs3PQdUVGvSb9ElSwxREjrH4=; b=RYPQfRpOADo33JWRCwPRF4McSH+Jrx7BL880FDqHsHQ+eiuDVW5YFws2DaRCRsT5KG PuoHslgLcVcITrtd3+ivXjh6VMjqORfkrZiEm0KSPZeF/Zr/CYYTk9OirqA9bFBCTKxA Aenm9Qe3/M1R9BKtNuCKk1Hwf/jPTfeYOcc63y5vTjf5ICRGEm2c6OIqG+2ZOdwSAoWd +gH8AAPvlk/0cyUXW79kZmir17I8qhhyo/T6LFihAoHZVXRgYF6CnnX+5naiGzXoEYq2 BouiznK8ZZ39TrSRZJDM9NRiWppCdJhbseGusgqjwZe0NerAHiadHuGkfGM2z+DmrXdL DX+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=kVioipiXHEmhP5HVeMLPs3PQdUVGvSb9ElSwxREjrH4=; b=n/8FUd/NFxDyjWTF0RLmSa1kaoywE1O85qxMIyoRjJUJxt0iu4zwklAn6KKmXJOJ2b a1bU89XeeARDPfFKBzLzbtApHhAQ9utCxrW5vre++7RvjbdAUDHW5Vhe8yJbykAtA/7C /TbXrzHf0UJu2HBPZqhexXoy6qlUDI4A3TK0+hEuW7bNp8m4yHaY7XGtKKOtTrIyoYna 6q0VJSwXibVfAABqm38QLRqFIe38icsES5AJKDcSxYgzshqO5TSHrKbBm05uEuO7XSbM f/2ZRVZ2AoGlvu/mPl7cggpWslaXrBo8vf2K7ZBesp+gPjWIcMMpWJ54lfAkLN1OOmNJ 4T/Q== X-Gm-Message-State: APjAAAXjrsReRJFeCRDMNd60A134xVaj90d/Q8J3uR/OXOs+5eGsgTd+ pK3kdG2x/Kw6gHX/D94D3ZHycKuO X-Google-Smtp-Source: APXvYqxWAkMOOj6eWc4BMZ945/oAGEezjKV7O2IDADZjt3v3k9Qi6w9r5M5kTg4jxq7ba3NMaeKKTQ== X-Received: by 2002:adf:df03:: with SMTP id y3mr7075wrl.260.1576018784592; Tue, 10 Dec 2019 14:59:44 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:43 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 13/17] fix expansion of initializer (default) Date: Tue, 10 Dec 2019 23:59:17 +0100 Message-Id: <20191210225921.94897-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, constant_symbol_value() is doing the expansion of a constant initializer when an explicit one is found but nothing is done if the initilizer is an implicit one. Fix this by: * adding an helper to lookup the corresponding type from offset; * using this helper to get the correct kind for the value: - a 0-valued EXPR_VALUE for integers - a 0.0-valued EXPR_FVALUE for floats. Signed-off-by: Luc Van Oostenryck --- expand.c | 65 ++++++++++++++++++++++++- validation/expand/default-init-struct.c | 1 - 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/expand.c b/expand.c index 9ab259b13a82..cd348bf5833e 100644 --- a/expand.c +++ b/expand.c @@ -621,6 +621,66 @@ static int expand_addressof(struct expression *expr) return expand_expression(expr->unop); } +/// +// lookup the type of a struct's memeber at the requested offset +static struct symbol *find_member(struct symbol *sym, int offset) +{ + struct ptr_list *head, *list; + + head = (struct ptr_list *) sym->symbol_list; + list = head; + if (!head) + return NULL; + do { + int nr = list->nr; + int i; + for (i = 0; i < nr; i++) { + struct symbol *ent = (struct symbol *) list->list[i]; + int curr = ent->offset; + if (curr == offset) + return ent; + if (curr > offset) + return NULL; + } + } while ((list = list->next) != head); + return NULL; +} + +/// +// lookup a suitable default initializer value at the requested offset +static struct expression *default_initializer(struct symbol *sym, int offset) +{ + static struct expression value; + struct symbol *type; + +redo: + switch (sym->type) { + case SYM_NODE: + sym = sym->ctype.base_type; + goto redo; + case SYM_STRUCT: + type = find_member(sym, offset); + if (!type) + return NULL; + break; + case SYM_ARRAY: + type = sym->ctype.base_type; + break; + default: + return NULL; + } + + if (is_integral_type(type)) + value.type = EXPR_VALUE; + else if (is_float_type(type)) + value.type = EXPR_FVALUE; + else + return NULL; + + value.ctype = type; + return &value; +} + /* * Look up a trustable initializer value at the requested offset. * @@ -646,10 +706,11 @@ static struct expression *constant_symbol_value(struct symbol *sym, int offset) if (entry->init_offset < offset) continue; if (entry->init_offset > offset) - return NULL; + break; return entry->init_expr; } END_FOR_EACH_PTR(entry); - return NULL; + + value = default_initializer(sym, offset); } return value; } diff --git a/validation/expand/default-init-struct.c b/validation/expand/default-init-struct.c index c843a1abb960..085dd2d6dca9 100644 --- a/validation/expand/default-init-struct.c +++ b/validation/expand/default-init-struct.c @@ -15,7 +15,6 @@ int test_struct(void) /* * check-name: default-init-struct * check-command: test-linearize -Wno-decl -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-contains: phisrc\\..*return.*\\$0 From patchwork Tue Dec 10 22:59:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283525 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC80D14B7 for ; Tue, 10 Dec 2019 22:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CAA362073B for ; Tue, 10 Dec 2019 22:59:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bUAlFjr4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727403AbfLJW7s (ORCPT ); Tue, 10 Dec 2019 17:59:48 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46855 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfLJW7s (ORCPT ); Tue, 10 Dec 2019 17:59:48 -0500 Received: by mail-wr1-f68.google.com with SMTP id z7so21857252wrl.13 for ; Tue, 10 Dec 2019 14:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oaIbsdT6lakziWuf1dkiOeWdtPSd6EsteHwxBEXTC0Q=; b=bUAlFjr46iIL01OdxejMDXKJmmOgO2JSKau4i/id5e4oMoR4ZqPwgU8VGvwVD/70+o F+w9CMnQm8dJY6S7Ik9/wknXvaWY1Ru+6QoYzkoX0a16GrK3OqoZOGzHEnmHy3MLBWwK SY1Fe2HbvwBFuMMrgg0XtdDQCWANogXTgJv1r52ji3Ukfsxy4TDCRd9JASYLjFGPiPGw gHwMjOxI8jKuSy3yRmGhVKOE3UfuL1qH8utU72umS6k/V0jiEKfVod3YaLIycaI+M8hR SlXOT7fTsGZDjZFiQTFACnJUGkJTd1AyFCr93oNvDi+8UueTiXIW3+XsanlqqsnaCr3C MClQ== 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=oaIbsdT6lakziWuf1dkiOeWdtPSd6EsteHwxBEXTC0Q=; b=E0UNSGQiRp/5MfUTqgaRGAQN/Xwa/0HX2GkRDxgnQQIemK8yDnDbIni5YNsAkRJIby BvQzUk23Wj1mVBaunXY5NbfTcKyAmlmy2ZuNt+BoVLdFvee7Q5J4Ug1AZ15kzleOpYyJ OjrpwKLSnonnB5p7FWwuGOgOm7/gL7lRrfqBn7R0Vx1vVbiLy29iHFRt4932GS4MxdCS pJzf8ILMzC6+tSnQuMzZ/axgjt1MiCXPReBwqW9KLRj62ulrtHmoEpShUGV1v0LDSWul yODTLw8XvIp5/g3ai8me2tDll1dk+sx1YoTdNfb3C7bkqBqFcH7EeeaMdd1bX0GOkXBv V8OA== X-Gm-Message-State: APjAAAWwUoMRofxEDvyXl23NRt07D6fnIW6wpcX2xvePa38nYdakrBDM lPt3EUUKpjQ7sd7wYlx2GJvfqQzP X-Google-Smtp-Source: APXvYqyA3CszOiyKokoqTNfsaMvk8Iy3TImluFLDD40hCRmT6CPPHdnk0FuSwBLSTQe9SgNyLyD9Ow== X-Received: by 2002:adf:e6c5:: with SMTP id y5mr10677wrm.210.1576018785669; Tue, 10 Dec 2019 14:59:45 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:44 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 14/17] fix simplify_loads() when doing type punning Date: Tue, 10 Dec 2019 23:59:18 +0100 Message-Id: <20191210225921.94897-15-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org When doing loads simplification for a location where floats & integers are mixed, loads are systematically replaced with the value of their dominating memop (this checks if the corresponding write or load overlaps). However, this must not be done if the involved operations are doing some form of integer/float type punning. Fix this by refusing to convert load of an integer by a previous float value or the opposite. Note: another way to describe this problem would be to say that floats need to have their own memory operations: OP_FSTORE & OP_FLOAD or that instructions need to have some form of 'machine type' in addition of the size (like clang's i32/f32, ...). Signed-off-by: Luc Van Oostenryck --- memops.c | 11 +++++++++++ validation/memops/type-punning-flt2int.c | 1 - validation/memops/type-punning-int2flt.c | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/memops.c b/memops.c index 5df2c0339415..f071e556da8a 100644 --- a/memops.c +++ b/memops.c @@ -82,6 +82,15 @@ static int local_pseudo(pseudo_t pseudo) && !address_taken(pseudo); } +static bool compatible_loads(struct instruction *a, struct instruction *b) +{ + if (is_integral_type(a->type) && is_float_type(b->type)) + return false; + if (is_float_type(a->type) && is_integral_type(b->type)) + return false; + return true; +} + static void simplify_loads(struct basic_block *bb) { struct instruction *insn; @@ -114,6 +123,8 @@ static void simplify_loads(struct basic_block *bb) continue; goto next_load; } + if (!compatible_loads(insn, dom)) + goto next_load; /* Yeehaa! Found one! */ convert_load_instruction(insn, dom->target); goto next_load; diff --git a/validation/memops/type-punning-flt2int.c b/validation/memops/type-punning-flt2int.c index a76c6c1da534..fadaf6876d13 100644 --- a/validation/memops/type-punning-flt2int.c +++ b/validation/memops/type-punning-flt2int.c @@ -13,7 +13,6 @@ static int foo(void) * check-name: type-punning-float-to-int * check description: must not infer the int value from the float * check-command: test-linearize $file - * check-known-to-fail * * check-output-ignore * check-output-contains: load\\. diff --git a/validation/memops/type-punning-int2flt.c b/validation/memops/type-punning-int2flt.c index c05ce252f305..061b742352c4 100644 --- a/validation/memops/type-punning-int2flt.c +++ b/validation/memops/type-punning-int2flt.c @@ -13,7 +13,6 @@ static float foo(void) * check-name: type-punning-int-to-float * check description: must not infer the float value from the int * check-command: test-linearize $file - * check-known-to-fail * * check-output-ignore * check-output-contains: load\\. From patchwork Tue Dec 10 22:59:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70C11930 for ; Tue, 10 Dec 2019 22:59:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F37A2073B for ; Tue, 10 Dec 2019 22:59:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DGek/RHX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727412AbfLJW7t (ORCPT ); Tue, 10 Dec 2019 17:59:49 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36726 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727387AbfLJW7s (ORCPT ); Tue, 10 Dec 2019 17:59:48 -0500 Received: by mail-wr1-f65.google.com with SMTP id z3so21991865wru.3 for ; Tue, 10 Dec 2019 14:59:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DFUyKwET9lwtSSv7M8XNv8rx6z+WBjnnOhRZq+THPkI=; b=DGek/RHXssskA2rZlKAaPeHw78SG1GnF77dAfG4y0UbjJh0By8cjVY4gNi26cDzFFj fNzenDq8SSH8sh8jYskdFYiRDwv9RewqiFpdv4/kqkTxh/n9GtDTZAvM7SAA+WV9aVEx z0jkcbTofDwEjhZtVf/ob9VDDyhlNopyFO+w8/JVsXMR/qufPwdXDEUvqmUTadnWDeVu I8j11jh4NZR/9/+oz0QmneJy9wrvuUcRRrJI0IL6A7utXYusz+88FVK/eYhhdyhTSLOB QZwFNIEYzYBkMXw84lp4nb/ZhMhUIiXBxlQDrT+Q5Vuj2SD1++Om28NWj+XSDChnONpe a0JA== 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=DFUyKwET9lwtSSv7M8XNv8rx6z+WBjnnOhRZq+THPkI=; b=gHabg/MkENnu9TPK+6/laBzx223DymCDRXEWaH1WR56mfxR3hlgLKuFT7NvMuTY/P+ pKQdnf+tQ5X5D5TFCncd3NXKUt6jhb2/SXkFRLPvXM+69QQ4C5LCw6Yt0JmHhNoHt70s zwGkojbd7WkSDUweEsSHCqKMnfU4chGpr+b+8a36ROsuX5fcN7by8IvDqCQMi5YE0jkY D0P85iMoMrxAZYP0kmvt2LIBXIdw8RKRa4CE5EtEPbo/1FNZI+p4/pdXwiU/z1jtzDnX Jul9pfL1Dw3tCgIZq3u8ilGfNuweazCuUPhmOHWuukTCD9gOzqh+BH25E5fyHOhyJuob I3+Q== X-Gm-Message-State: APjAAAVrAUH4E6KVm4EQgXKz0TlEk9+jCeYJQOR3w6tTf0Y7mDMwjAm4 02xd2eogTGdrSn9qCriXzjeZPswI X-Google-Smtp-Source: APXvYqzQrbjiVIZ2xrQjSVE2s23pb8a7frp3WKl+9E9xON29ST0alT1pdKQsF5zPDt9VbZTcVKtvkw== X-Received: by 2002:adf:f091:: with SMTP id n17mr6005043wro.387.1576018786766; Tue, 10 Dec 2019 14:59:46 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:46 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 15/17] fix cost of dereference of symbols with complex type Date: Tue, 10 Dec 2019 23:59:19 +0100 Message-Id: <20191210225921.94897-16-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, in expand_dereference(), the dereference of a symbol with a complex type is considered as costing as high as a non-symbol because it's not recognised it's a symbol. However, both cases should have exactly the same cost since they address calculation amounts to 'symbol + offset'. So, instead of taking in account a single level of symbol + offset let's use a loop for this in order to handle symbol [+ offset]* Signed-off-by: Luc Van Oostenryck --- expand.c | 10 +++++----- validation/expand/cost-deref-nested.c | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/expand.c b/expand.c index cd348bf5833e..36612c8672dd 100644 --- a/expand.c +++ b/expand.c @@ -737,12 +737,12 @@ static int expand_dereference(struct expression *expr) * Is it "symbol" or "symbol + offset"? */ offset = 0; - if (unop->type == EXPR_BINOP && unop->op == '+') { + while (unop->type == EXPR_BINOP && unop->op == '+') { struct expression *right = unop->right; - if (right->type == EXPR_VALUE) { - offset = right->value; - unop = unop->left; - } + if (right->type != EXPR_VALUE) + break; + offset += right->value; + unop = unop->left; } if (unop->type == EXPR_SYMBOL) { diff --git a/validation/expand/cost-deref-nested.c b/validation/expand/cost-deref-nested.c index b09602b6acc6..d6b623961378 100644 --- a/validation/expand/cost-deref-nested.c +++ b/validation/expand/cost-deref-nested.c @@ -14,7 +14,6 @@ static int foo(int c) /* * check-name: cost-deref-nested * check-command: test-linearize -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: cbr From patchwork Tue Dec 10 22:59:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C693F930 for ; Tue, 10 Dec 2019 22:59:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A52432073B for ; Tue, 10 Dec 2019 22:59:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C1ZmcN1t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727415AbfLJW7u (ORCPT ); Tue, 10 Dec 2019 17:59:50 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38247 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfLJW7u (ORCPT ); Tue, 10 Dec 2019 17:59:50 -0500 Received: by mail-wr1-f67.google.com with SMTP id y17so21977223wrh.5 for ; Tue, 10 Dec 2019 14:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WsP56QjgXWbas/s2njX9/d1C3XRf3eqUj+LW3UyRMiA=; b=C1ZmcN1tKWXlMTo2Q8TiedbRE5G0Fb6nozAyD3+CmopksIuQHPmVLBT4cU7S6WOaH1 it6SHZ5xnblgLKgN1AJ/ZDrLv3Jh02yr5bybjpLGADo1TCyi4HmN5oAiu1tFXwl0eZv0 KlLZwC/crWvJjSZi3yE3CIz3VRk8CiAU1VHgv3UhKCOqTNIsufXq5cUWxM4COpRZOyJS +mli8kB9NMXklcIP7u36MlVM0ls1spv4p+BnVhpedoW6IxIZLLuTXLSNDu2UiJuXgVPm A2DxaLA+chFsuaGxSIfs5Ku0H1gOFGHiEV1DKz6K8X9/r3cgqYUox1G33F7MV3u0RD/w le+Q== 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=WsP56QjgXWbas/s2njX9/d1C3XRf3eqUj+LW3UyRMiA=; b=GpN4evS6J3iqnqNmaiiEFvdp9yqzKSEQkHfg/HT+SfayyHuNQ1oBQB8N4KGIsEUWaH iE69c/hk1MOodZ0IRR0ARa3Fg47yWO9xpoei7sSGtqvm861bgGOmKJLrw69iebIhqE8b /70TdY9aDukHqgZouALljYctkifSxPaSBDLP2z8TZp35bf08zPorsCuMiH0VrIUVRXQW GyIfWAQlRw+kW1ZkY7RmYewWDjJKIad8vNdIxBXW/ZWZMmU2JmtAdqVtjwUHIpPg2M9u k/PB0oGouXXNR7k6vIkRNvOdRwUhUY3LgOQf7UqgPVvLwuyir75rid/5lDq0NBaYTKor 2EYg== X-Gm-Message-State: APjAAAV2KF3uSJqNSoJrRgsBxDwE31dQuWjJeW4MlBETs0MJljGAW7z+ aFuvIyHGXOdFjlFKAtC3yGKYKgld X-Google-Smtp-Source: APXvYqyfWad58Bodn60WHin3u2v6yhfQAqQD8f84GhiBeNi5fiCvYUMP4ZesddGZx0UuwUrel0XQhg== X-Received: by 2002:a05:6000:1044:: with SMTP id c4mr11711wrx.204.1576018787886; Tue, 10 Dec 2019 14:59:47 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:47 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 16/17] RFC: allow expansion of accessed constants if 'static const' Date: Tue, 10 Dec 2019 23:59:20 +0100 Message-Id: <20191210225921.94897-17-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org Currently, constant_symbol_value() safely refuses to convert a symbol that is accessed. But accessing a 'static const' object should be fine since it should never be modified. So, allow to also expand symbol marked as accessed but being 'static const'. Note: a simple 'const' should be enough and 'static' doesn't make it 'more const'. In both cases, the object can be modified via a cast to a non-const pointer (which is UB). The only thing that 'static' changes is that *if* the object's address is not taken (so all accesses are const-expanded) then it's not needed to allocate memory for thsi object. OTOH, GCC also seems to do some these expansions only if the object is static const. So, I dunno. Signed-off-by: Luc Van Oostenryck --- expand.c | 7 +++++-- validation/expand/constant-init-array.c | 4 ++-- validation/expand/constant-static.c | 16 ++++++++++++++++ validation/expand/default-init-array.c | 1 - 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 validation/expand/constant-static.c diff --git a/expand.c b/expand.c index 36612c8672dd..1885a4eaad2a 100644 --- a/expand.c +++ b/expand.c @@ -689,9 +689,12 @@ redo: static struct expression *constant_symbol_value(struct symbol *sym, int offset) { struct expression *value; + unsigned long mods = sym->ctype.modifiers; - if (sym->ctype.modifiers & MOD_ACCESS) - return NULL; + if (mods & MOD_ACCESS) { + if ((mods & (MOD_STATIC | MOD_CONST)) != (MOD_STATIC | MOD_CONST)) + return NULL; + } value = sym->initializer; if (!value) return NULL; diff --git a/validation/expand/constant-init-array.c b/validation/expand/constant-init-array.c index 94949be54244..861885630f18 100644 --- a/validation/expand/constant-init-array.c +++ b/validation/expand/constant-init-array.c @@ -10,6 +10,6 @@ int test_array(int i) * check-command: test-linearize -Wno-decl -fdump-ir $file * * check-output-ignore - * check-output-excludes: phisrc\\..*return.*\\$2 - * check-output-contains: load\\. + * check-output-contains: phisrc\\..*return.*\\$2 + * check-output-excludes: load\\. */ diff --git a/validation/expand/constant-static.c b/validation/expand/constant-static.c new file mode 100644 index 000000000000..df6673eeef47 --- /dev/null +++ b/validation/expand/constant-static.c @@ -0,0 +1,16 @@ +static const int a = 3; + +static int foo(void) +{ + int *p = (int*) &a; + return a; +} + +/* + * check-name: constant-static + * check-command: test-linearize $file + * + * check-output-ignore + * check-output-contains: ret\\.32 *\\$3 + * check-output-excludes: load\\. + */ diff --git a/validation/expand/default-init-array.c b/validation/expand/default-init-array.c index b372ea09534b..5f2e44ef21a3 100644 --- a/validation/expand/default-init-array.c +++ b/validation/expand/default-init-array.c @@ -8,7 +8,6 @@ int test_array(int i) /* * check-name: default-init-array * check-command: test-linearize -Wno-decl -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-contains: phisrc\\..*return.*\\$0 From patchwork Tue Dec 10 22:59:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 11283531 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C23614B7 for ; Tue, 10 Dec 2019 22:59:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5ABEF2073B for ; Tue, 10 Dec 2019 22:59:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tXlwLeaV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727137AbfLJW7v (ORCPT ); Tue, 10 Dec 2019 17:59:51 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33752 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727387AbfLJW7u (ORCPT ); Tue, 10 Dec 2019 17:59:50 -0500 Received: by mail-wr1-f68.google.com with SMTP id b6so21996532wrq.0 for ; Tue, 10 Dec 2019 14:59:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KufPX5EofecYUyC20FIgVvuRL3M0cmrdIjd/soNFE2w=; b=tXlwLeaVU+h41uksU93X4kOPkh6eRgIxm4XrWRGZ2pR/ohXKD+dZUI9685vLNvnvVu wnOwzS/cIWHZX9uQOuZNqHqGHw6TehaVIdD2fE6PKFSE7OP2EUCtJe1t+T/I+QJkekKx QM8XJ1jrSoq+g3W4Je5ctpcPZQOrU1JnJCYy1y7l4iWxX+FzdOTp4C7Jwn6kW4MdYDaU ZlxLSksRsUc5uMiFKuA4VjrUGKDiBh32TR0QAoQ7iz5+dNOcerEVfETQLAfXp2kY/mAA flp/URIqNuJy6QgwhEw6WH5n4c3TjxfM0j/HEj97IbtWMAeUTLJvE6kSeWImh+eLl8gp iHKg== 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=KufPX5EofecYUyC20FIgVvuRL3M0cmrdIjd/soNFE2w=; b=En1113aR0jURVitBp5z4NGY7N/v4qX+McjyvyT9zfzumBf+5av/3ZK8IFByr6qA3La D7zpW8P6TYhcC+WGJ7nUJvN1QLXXWkBm+vgncn7qNqz+EzgsRSV7rLv8oUPyssM+95J1 LxZQOrWXIphWCbnYp1yBueoKql2g24+lHQ6+qh6uF2J3mEaPMXvUXSk8kfzcRPsAbImL CM5JkDLIWs+J7MNSVObVK5/nnr2wZQ+2BwdbISU3NxkxUAiDg5ATGQXAPexJA2A+gsBY 09eINt26iWLYGxI+AUIAyDUwF1PouItzUzLWirK7IWSNGFiAD8oczEgQEJcXu/+D0oTh M+1g== X-Gm-Message-State: APjAAAXr87FT4A4IqHa9gVDKDNsVnGRa2djXSlTc2cdXq/SwRRWblvED jbbr4WPtQtTb+GToYZOW0sLyz7rO X-Google-Smtp-Source: APXvYqxxW1fCIW4hwuT+yds/0JQaRBY38N39D+x1qDqRRAp/cHECid7/dXxf6kgy85vc5HCXuuG4Tg== X-Received: by 2002:a5d:6748:: with SMTP id l8mr12690wrw.188.1576018789086; Tue, 10 Dec 2019 14:59:49 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:40f6:4600:ccc5:3de6:2efd:b014]) by smtp.gmail.com with ESMTPSA id j21sm33535wmj.39.2019.12.10.14.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 14:59:48 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Luc Van Oostenryck Subject: [PATCH 17/17] constant expansion of strings Date: Tue, 10 Dec 2019 23:59:21 +0100 Message-Id: <20191210225921.94897-18-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> References: <20191210225921.94897-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org EXPR_STRING can be considered as a kind of specialized initializer for strings. Using EXPR_INITIALIZER for them would be much more costly. However, unlike EXPR_INITIALIZER, EXPR_STRING are not used by constant_symbol_value() to expand dereferences of symbols with constant value. Change this by adding to constant_symbol_value() the code needed to expand dereferences of strings. Two situations need to be handled: one for string literals and another for declared strings. Signed-off-by: Luc Van Oostenryck --- expand.c | 30 ++++++++++++++++++++++++ validation/expand/constant-init-string.c | 1 - 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/expand.c b/expand.c index 1885a4eaad2a..eeddb633c9bf 100644 --- a/expand.c +++ b/expand.c @@ -681,6 +681,27 @@ redo: return &value; } +static struct expression *constant_string_value(struct expression *e, int offset) +{ + static struct expression value; + struct string *string; + struct symbol *ctype; + + if (e->wide) + return NULL; + string = e->string; + if (offset >= string->length) + return NULL; + ctype = e->ctype; + if (!ctype) + return NULL; + + value.type = EXPR_VALUE; + value.value = string->data[offset]; + value.ctype = get_base_type(ctype->ctype.base_type); + return &value; +} + /* * Look up a trustable initializer value at the requested offset. * @@ -714,6 +735,15 @@ static struct expression *constant_symbol_value(struct symbol *sym, int offset) } END_FOR_EACH_PTR(entry); value = default_initializer(sym, offset); + } else if (value->type == EXPR_STRING) { + value = constant_string_value(value, offset); + } else if (value->type == EXPR_PREOP && value->op == '*') { + if (value->unop->type == EXPR_SYMBOL) { + struct symbol *sym = value->unop->symbol; + struct expression *init = sym->initializer; + if (init && init->type == EXPR_STRING) + value = constant_string_value(init, offset); + } } return value; } diff --git a/validation/expand/constant-init-string.c b/validation/expand/constant-init-string.c index 42ae9bd3d8a4..033882a0bed9 100644 --- a/validation/expand/constant-init-string.c +++ b/validation/expand/constant-init-string.c @@ -7,7 +7,6 @@ char foo(void) /* * check-name: constant-init-nested-array * check-command: test-linearize -Wno-decl -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-contains: phisrc\\..*\\$63