From patchwork Fri Sep 27 23:43:03 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: 11165253 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 7D91B17EE for ; Fri, 27 Sep 2019 23:43:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5921A20863 for ; Fri, 27 Sep 2019 23:43:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iIkkMQTZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728543AbfI0Xn1 (ORCPT ); Fri, 27 Sep 2019 19:43:27 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:42621 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbfI0Xn1 (ORCPT ); Fri, 27 Sep 2019 19:43:27 -0400 Received: by mail-ed1-f67.google.com with SMTP id y91so3702997ede.9 for ; Fri, 27 Sep 2019 16:43:25 -0700 (PDT) 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=lIBoOXtmPsiHKadSfcW/ICWo+eiSR3AbN/colqn7DN0=; b=iIkkMQTZdlReBE0PNJQiSFfd5Jx7axs1tBdskgdYKfheHBZ4ydkKbzZN7jo37mDWk9 fXXU97wtSlKZms7KeBKWFKtd7e5DEKZXxaEuMIPOVwsn9hTZkfgVAAGhCVjatg8r7LX7 TUdesB6gf9tqsYeIg3NPWYocZKxu5wOzxghirOvDTI7bRt+pK9DzhEdjikjViPBbUhfS O/nDhx8ow3KZ18VcqHKwp+XqPilj5gN6ts53FiTezamK9gLrqcqdDoxAL8l8YZXxfav+ ++2Zb6+BhbbkEvlH/wVT4nuNaolsGML6jsCZyximjenrnWwEQIZrZd5MOJqdkYhNUR/c Zzjw== 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=lIBoOXtmPsiHKadSfcW/ICWo+eiSR3AbN/colqn7DN0=; b=Lde2tIo9AIf+dfrjXmyhol6IE9L0TKGzx4QU/gSx17iH0smkOreAiubIfRvM1RDCvs fxRaaMrKcvIYZRlQmFkwZiv6hGU/1rjhimvyIXt9MiXqVHa+8DAqmdDG6Ft6g7wHaeBj uaSIUPvyS8TGYzN8QFzM+PXo3xWxC5A6AYMZzPL4j1BQxv2w2OD6xm13muqqS4ikzLX8 NfUarZXmA8plvA/brjLQdgWmi9uliDS0MGD2+t41C5l5EhDJ5v/oatXXUbl+H70H54Y0 UBGKYQhr0+19+FyFa1LdrDxM9KsgpbHdWbsQ2u3OB3knJ32PUCKeGoivbY9splxhy0Eu mf6g== X-Gm-Message-State: APjAAAWs+oiBWGBMEN14JA6vQm2pYXn7JKneexbyBDl/ePbb8wEwUKKU WJA0FKzXo4cwmpxwIR1r91IVPYzw X-Google-Smtp-Source: APXvYqwtWyDhtzYnXii6X1EackTEKYmzGJc4RMTSk5ao9Ri2xEvn6bBRm2JKHXJ2aN+D+lY/ykfKhA== X-Received: by 2002:a05:6402:1688:: with SMTP id a8mr7276561edv.225.1569627804880; Fri, 27 Sep 2019 16:43:24 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:24 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 1/2] add test for evaluation of invalid assignments Date: Sat, 28 Sep 2019 01:43:03 +0200 Message-Id: <20190927234322.5157-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Due to the way compatible_assignment_types()'s handle type incompatibilities and how expression with an invalid type are nevertheless processed by linearize_expression(), some invalid assignments retunr unwanted error messages (and working around them can create some others). Here are 2 relatively simple tests triggering the situation. Signed-off-by: Luc Van Oostenryck --- validation/eval-bad-assign1.c | 15 +++++++++++++++ validation/eval-bad-assign2.c | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 validation/eval-bad-assign1.c create mode 100644 validation/eval-bad-assign2.c diff --git a/validation/eval-bad-assign1.c b/validation/eval-bad-assign1.c new file mode 100644 index 000000000..bce4d3d38 --- /dev/null +++ b/validation/eval-bad-assign1.c @@ -0,0 +1,15 @@ +static void kos(int *r, int a) +{ + r = ({ __builtin_types_compatible_p(int, int); }); +} + +/* + * check-name: eval-bad-assign1 + * check-known-to-fail + * + * check-error-start +eval-bad-assign1.c:3:11: warning: incorrect type in assignment (different base types) +eval-bad-assign1.c:3:11: expected int *r +eval-bad-assign1.c:3:11: got int + * check-error-end + */ diff --git a/validation/eval-bad-assign2.c b/validation/eval-bad-assign2.c new file mode 100644 index 000000000..4d08cb907 --- /dev/null +++ b/validation/eval-bad-assign2.c @@ -0,0 +1,22 @@ +struct s { + char c[1]; +}; + +struct s fun(void); + + +static void foo(void) +{ + char c[1]; + c = fun().c; +} + +/* + * check-name: eval-bad-assign2 + * + * check-error-start +eval-bad-assign2.c:11:11: warning: incorrect type in assignment (invalid types) +eval-bad-assign2.c:11:11: expected char c[1] +eval-bad-assign2.c:11:11: got char * + * check-error-end + */ From patchwork Fri Sep 27 23:43: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: 11165257 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 03DFD1747 for ; Fri, 27 Sep 2019 23:43:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D62C920863 for ; Fri, 27 Sep 2019 23:43:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BgVqKYGl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728763AbfI0Xn3 (ORCPT ); Fri, 27 Sep 2019 19:43:29 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:36432 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbfI0Xn3 (ORCPT ); Fri, 27 Sep 2019 19:43:29 -0400 Received: by mail-ed1-f65.google.com with SMTP id h2so3746130edn.3 for ; Fri, 27 Sep 2019 16:43:27 -0700 (PDT) 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=UdajxMr2+P+kt6tSUAwxxGAJHtZoSF/M61YKLkSgbeI=; b=BgVqKYGlry2BWrhvkjeFYe0NLvrsKqrXjKL1Tq0T/tbCFyAYU8vobwwnNCAv+93HOw bwF377Cry0bt2r8Rub0VT/VO9ORiQ53fH8FYVlcD3MUxh4WJ7Bxp/wF45o2YfB/wXEKp WV3PlAZbQf1ayDLlVvstL4c0PE9dxJLOLYulp2/I4fLZ+PL8I5iQm1N2yo3OGp8sxZkg 5PCk1kuAy5jk7EjYHg6eULalEi9ChFvl8tFPurZzQtuCOTTWQnuG+qpifpSKYrHrSXGP TJFSBw9vi8x3SfPjppI+7swdtjtRtUGai4zCct4lM1jDc5ASvHq/UN37FsV2LwHc+e06 Z1eA== 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=UdajxMr2+P+kt6tSUAwxxGAJHtZoSF/M61YKLkSgbeI=; b=axK4Ezlqvu6sV4EmMJ4Ox4M8mCUKs+uapXDkCryomLcIQ0cY1SbV+rrDm09Y9xV7tf QogFJGaSwERIiqHcgZ57VQ6nnbiqOSNJsMgFAaigZcS1SRgzWENcmfZKfAKQc44jnHD1 8grC7dq8BCcK0JgJTJ5YgmDYwDzHuN/Le7TlliNsbjgQ02FQwA5LXG8nXFhfE24wfhYA sQcPIKpSTB0Iy3kMX7OgBQnP4k9AwntOvWlPR13sM9WvfxUqxnuyk76I2b/pMYHC4iiK X+wo5wmnhBrhlBTvFsgceUq+pw9kSXtNQfRuU60DQ08q0lfQzmiSwx9EreSxaOR9mtWj fVRQ== X-Gm-Message-State: APjAAAWR1nIE57VSPb166GyT16s/rnQqQjJtA4H5v2RHlbz6BtwbS5eM CJOMZosnCR6RrQU9ix1vK9KVLkg+ X-Google-Smtp-Source: APXvYqyxlAvDC8aKveJZ3+DVsPFOY9CptBLf2eUODnbreQS6cUYbJzpb8XhJFAr0AQUvMnuoTL5iRw== X-Received: by 2002:a05:6402:1583:: with SMTP id c3mr7554772edv.286.1569627807081; Fri, 27 Sep 2019 16:43:27 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:26 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 02/18] shorter message for non-scalar in conditionals Date: Sat, 28 Sep 2019 01:43:06 +0200 Message-Id: <20190927234322.5157-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 The diagnostic message is a bit long with the non-really-informative part 'incorrect type' first and the explanation later in parentheses. Change this by using a shorter message "non-scalar type in ...". Signed-off-by: Luc Van Oostenryck --- evaluate.c | 2 +- validation/bad-type-twice0.c | 2 +- validation/conditional-type.c | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/evaluate.c b/evaluate.c index 3821bb3d7..f6dfcced7 100644 --- a/evaluate.c +++ b/evaluate.c @@ -910,7 +910,7 @@ static struct symbol *evaluate_conditional(struct expression *expr, int iterator if (Waddress) warning(expr->pos, "the address of %s will always evaluate as true", "an array"); } else if (!is_scalar_type(ctype)) { - sparse_error(expr->pos, "incorrect type in conditional (non-scalar type):"); + sparse_error(expr->pos, "non-scalar type in conditional:"); info(expr->pos, " %s", show_typename(ctype)); return NULL; } diff --git a/validation/bad-type-twice0.c b/validation/bad-type-twice0.c index 45234699e..9e834d47d 100644 --- a/validation/bad-type-twice0.c +++ b/validation/bad-type-twice0.c @@ -7,7 +7,7 @@ static int foo(a) * check-name: bad-type-twice0 * * check-error-start -bad-type-twice0.c:3:16: error: incorrect type in conditional (non-scalar type): +bad-type-twice0.c:3:16: error: non-scalar type in conditional: bad-type-twice0.c:3:16: incomplete type a * check-error-end */ diff --git a/validation/conditional-type.c b/validation/conditional-type.c index 34cfcc687..6e2da9b52 100644 --- a/validation/conditional-type.c +++ b/validation/conditional-type.c @@ -79,21 +79,21 @@ static int good_if_ptr(void *ptr) * check-name: conditional-type * * check-error-start -conditional-type.c:18:18: error: incorrect type in conditional (non-scalar type): +conditional-type.c:18:18: error: non-scalar type in conditional: conditional-type.c:18:18: void -conditional-type.c:19:13: error: incorrect type in conditional (non-scalar type): +conditional-type.c:19:13: error: non-scalar type in conditional: conditional-type.c:19:13: struct state s -conditional-type.c:24:18: error: incorrect type in conditional (non-scalar type): +conditional-type.c:24:18: error: non-scalar type in conditional: conditional-type.c:24:18: void -conditional-type.c:29:21: error: incorrect type in conditional (non-scalar type): +conditional-type.c:29:21: error: non-scalar type in conditional: conditional-type.c:29:21: void -conditional-type.c:30:16: error: incorrect type in conditional (non-scalar type): +conditional-type.c:30:16: error: non-scalar type in conditional: conditional-type.c:30:16: struct state s -conditional-type.c:34:21: error: incorrect type in conditional (non-scalar type): +conditional-type.c:34:21: error: non-scalar type in conditional: conditional-type.c:34:21: void -conditional-type.c:36:20: error: incorrect type in conditional (non-scalar type): +conditional-type.c:36:20: error: non-scalar type in conditional: conditional-type.c:36:20: void -conditional-type.c:40:21: error: incorrect type in conditional (non-scalar type): +conditional-type.c:40:21: error: non-scalar type in conditional: conditional-type.c:40:21: void * check-error-end */ From patchwork Fri Sep 27 23:43: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: 11165261 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 C2EA113B1 for ; Fri, 27 Sep 2019 23:43:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0CBD21655 for ; Fri, 27 Sep 2019 23:43:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="svBQwg4a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728742AbfI0Xna (ORCPT ); Fri, 27 Sep 2019 19:43:30 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36435 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728573AbfI0Xn3 (ORCPT ); Fri, 27 Sep 2019 19:43:29 -0400 Received: by mail-ed1-f67.google.com with SMTP id h2so3746148edn.3 for ; Fri, 27 Sep 2019 16:43:28 -0700 (PDT) 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=i48AorL/QX6PUj4RrX0pYJ7Oarrksg8nCzm7dmWkIq0=; b=svBQwg4aJmKMTDiaMRaJCUeZwwOsma/EVIvxQ++VyklJE2Ad+0gXZgL4O3+zR9ZlYF C5TUBaDKZhxyzo+WUGXFUQmrYFuHmIQiUNwGAkbyiVHPJX+4B0N1F+OxHfb2UUpF5H4k ZdC64k5688tvEJhhaG+9a5QYKrycSL2JnKonVAphASRcoGw6KkvztSi4tCBayP5dyl9c ZYvsvgAXUHazYZm0rQct0AFB1TM8YnwbsEhdUdBN2eqqPfQrSpbHIRjgWX7DmzjlCzR+ jloWX1AGyEjHMYLcQ1MNpolqoGM0+dilRAl1AlC2jSvevDQGqFaTrMqaiC2UGQFBQOaG 7I+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=i48AorL/QX6PUj4RrX0pYJ7Oarrksg8nCzm7dmWkIq0=; b=YZDBXCE7LIHceavAb56YeP6C3mpi2oTXI5eY3ct3JbjEnbShe5r1GMMZppnUIK9dVs Kv5FJ3BQOOgD8MDQ2KrX1Rzw6paVW3fHiBOovXD+UYQeWzxRV8zHO9hz9J3Sd25Sa5oM lBkcTMHTomEixfbdCP58FkucLCcauSPXwZdZ1Lh9wXmq/2oiTkpm3curQr1uw/4mrB+B 57BJW5FIwY/kmGNcd/QHi1Uc7ToJZXjPiolFjH4Std+wbiYLPz5pywD58OKtEupf0IFk lQlObJLd19tWG73I/ir3H7rapAnMHbHQFw09tmquuHIc+KZabQzU65G+QFSjgJSBN2SM IcGA== X-Gm-Message-State: APjAAAXAd0E6+Le5eaBzzi8TSvGg8r1FfHZYgpyGAQEPQWox/P1xcgGU gsrQml7ZewpdjPWG7VLoYsBhzytq X-Google-Smtp-Source: APXvYqy54eVuj/KxCho1FND26t23WjEN/90/crKkr+12iYSwaG065bEWwziQvb7+1IwbVQonvMd/VA== X-Received: by 2002:a50:9512:: with SMTP id u18mr7357786eda.182.1569627808029; Fri, 27 Sep 2019 16:43:28 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:27 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 03/18] expand: add test for expansion of compound literals Date: Sat, 28 Sep 2019 01:43:07 +0200 Message-Id: <20190927234322.5157-6-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Compound literals are currently not expanded. Add a test for this. Signed-off-by: Luc Van Oostenryck --- validation/expand/compound-literal.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 validation/expand/compound-literal.c diff --git a/validation/expand/compound-literal.c b/validation/expand/compound-literal.c new file mode 100644 index 000000000..7401b0191 --- /dev/null +++ b/validation/expand/compound-literal.c @@ -0,0 +1,27 @@ +#define SAME_TYPE(A, B) \ + __builtin_types_compatible_p(A, B) + +struct s { + int i; +}; + +static void foo(struct s *p) +{ + *p = (struct s) { .i = SAME_TYPE(int, int), }; +} + +/* + * check-name: compound-literal + * check-command: test-linearize $file + * check-known-to-fail + * + * check-output-start +foo: +.L0: + + store.32 $1 -> 0[%arg1] + ret + + + * check-output-end + */ From patchwork Fri Sep 27 23:43: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: 11165267 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 CBB5D1747 for ; Fri, 27 Sep 2019 23:43:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A9F3B20863 for ; Fri, 27 Sep 2019 23:43:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IHO5r4QN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728714AbfI0Xnd (ORCPT ); Fri, 27 Sep 2019 19:43:33 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:35802 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728519AbfI0Xnc (ORCPT ); Fri, 27 Sep 2019 19:43:32 -0400 Received: by mail-ed1-f67.google.com with SMTP id v8so3751843eds.2 for ; Fri, 27 Sep 2019 16:43:29 -0700 (PDT) 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=S1mmSASL+TWtdhYmO0Uno4xpJaj86uEFyNPETeHL3Cs=; b=IHO5r4QNFh3pKfjEEIgPFZW6Iqun9D1Njlxsp0a9shAkIAghvsyJAAvZuGvbnyiVWF coGF4R/XRXRqkJ/HugFpFuzw0iGQFDi/Qf0dA3AawvYdyf+dIlHuO3B+dr5WVVKtCCZg 890uSIQMEX7hN3HY+JoRlYcECSTaOUyieo9iKd+Bpu2DdKFMu6xomsqaILwrIoHiRUEH zUEYuH8EIJgjFT7lGA/LCU5sfYLOumQ5hk3cq6Y3JX4pi13yRYVzteO2xIeLC8ACgWKu kUDLo2hiuQgEU2l/6p7LGDIWSRZd3nF/0gyQmqr33WBI243gRLxEJGfoxEIzyveYfFdU jyLw== 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=S1mmSASL+TWtdhYmO0Uno4xpJaj86uEFyNPETeHL3Cs=; b=hno/a1daLiCaAuE5LJpficHwq4c6zCFhSZuOrM8TfnkKmSHZQv/vNyNs3a/otW/nAx d98OUY3QOTWaPIe6Eu8ZEnzi6kxPOlzeHZsN71JowSKa3t/oo+7ppM2YjHoNNZrPjEP1 5eVfvatHs4SuNvVXSIzVUnqrxqt3YLREjWx6KxptVhfibdOoqo5hI9ZS0rwRw6FAW1A7 Xjrot0avfAVEVZZPBWCZzMdUgb9pR/2ozjwrfI84u6hin1puj81ZG/C4po/6jzYDjRLC D/qaQH/2zrEBUPa526EIcsAO8TQtffBV7o/poliW/VcqTlW+PRsVcPXgRlmmSrGtjHWa L/Ng== X-Gm-Message-State: APjAAAWYxSyFlOZI03NvGAYYwQ5wzQ7nrfq2e/0xxv2Hb0cE1tHw5rCg PNoL5jfum6h6qjCfaw8w/y4fFUki X-Google-Smtp-Source: APXvYqyVh13byIIB9Cr5ymsji/S5qZP84fOLu1HFehx+j8a5gb1Jq9CuGHer7vtBsw7oAKCILoHvBA== X-Received: by 2002:aa7:c614:: with SMTP id h20mr7258430edq.209.1569627808715; Fri, 27 Sep 2019 16:43:28 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:28 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 04/18] expand: add missing expansion of compound literals Date: Sat, 28 Sep 2019 01:43:08 +0200 Message-Id: <20190927234322.5157-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Compound literals, like all other expressions, need to be be expanded before linearization, but this is currently not done. As consequence, some builtins are unexpectedly still present, same for EXPR_TYPEs, ... with error messages like: warning: unknown expression at linearization. Fix this by adding the missing expansion of compound literals. Note: as explained in the code itself, it's not totally clear how compound literals can be identified after evaluation. The code here consider all anonymous symbols with an initializer as being a compound literal. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 1 + expand.c | 8 ++++++++ validation/expand/compound-literal.c | 1 - validation/linear/compound-literal02.c | 1 - 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index f6dfcced7..70d76523e 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2935,6 +2935,7 @@ static struct symbol *evaluate_cast(struct expression *expr) * initializer, in which case we need to pass * the type value down to that initializer rather * than trying to evaluate it as an expression + * (cfr. compound literals: C99 & C11 6.5.2.5). * * A more complex case is when the initializer is * dereferenced as part of a post-fix expression. diff --git a/expand.c b/expand.c index e8e50b080..aba20b8cf 100644 --- a/expand.c +++ b/expand.c @@ -61,6 +61,14 @@ static int expand_symbol_expression(struct expression *expr) expr->taint = 0; return 0; } + + // expand compound literals (C99 & C11 6.5.2.5) + // FIXME: is this the correct way to identify them? + // All compound literals are anonymous but is + // the reverse true? + if (sym->initializer && !expr->symbol_name) + return expand_expression(sym->initializer); + /* The cost of a symbol expression is lower for on-stack symbols */ return (sym->ctype.modifiers & (MOD_STATIC | MOD_EXTERN)) ? 2 : 1; } diff --git a/validation/expand/compound-literal.c b/validation/expand/compound-literal.c index 7401b0191..034164bca 100644 --- a/validation/expand/compound-literal.c +++ b/validation/expand/compound-literal.c @@ -13,7 +13,6 @@ static void foo(struct s *p) /* * check-name: compound-literal * check-command: test-linearize $file - * check-known-to-fail * * check-output-start foo: diff --git a/validation/linear/compound-literal02.c b/validation/linear/compound-literal02.c index 87b98d76b..6ed5809eb 100644 --- a/validation/linear/compound-literal02.c +++ b/validation/linear/compound-literal02.c @@ -13,7 +13,6 @@ int bar(void) * check-name: compound-literal02.c * check-command: test-linearize -Wno-decl $file * - * check-known-to-fail * check-output-ignore * check-output-contains: ret\\..*\\$6 */ From patchwork Fri Sep 27 23:43: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: 11165263 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 C818F13B1 for ; Fri, 27 Sep 2019 23:43:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A62D720863 for ; Fri, 27 Sep 2019 23:43:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cVYtARNZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728573AbfI0Xnb (ORCPT ); Fri, 27 Sep 2019 19:43:31 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:37994 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728445AbfI0Xnb (ORCPT ); Fri, 27 Sep 2019 19:43:31 -0400 Received: by mail-ed1-f67.google.com with SMTP id l21so3731230edr.5 for ; Fri, 27 Sep 2019 16:43:30 -0700 (PDT) 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=DPwVNx+lPXox5W7VTjOmZAerlpPa/X711BI9OahrWUY=; b=cVYtARNZe+l5qcQq/o7F3qXkNKyctdkuffUUelYBYvdmXFHKeKXbP1K8DzRPoo05OE BZ5VFsUkUYjdsqgLBiNm939WRNHB6/BM+gzLgDWwA+mbOzc+Zqw353MPdBMLf1QaV9X3 uQe+N75F9SJHT+r1ZCw96GaYOQS+T+9LEC5xGAOTRBAadnrBR4j1VsoR9ewdLX4+2NPg Et17hwEP5iT6W1fPPA5w00BKDrwnO/MBKIq5ZVYpBWLJVt051NUhB8vzvApoNFc+Hb3k IzkNBKE6gpCaTL7h0ELEIeydgYLhBf2mbC0UzjKkdLLTNTgrtT3N0Ryvx/bpDGAr0ttY JPGg== 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=DPwVNx+lPXox5W7VTjOmZAerlpPa/X711BI9OahrWUY=; b=e3J00C0sUNEx4MSfEmc3WdqiQV9MCfw8VLhW2MnxsvDyanwxnrxesxUOmSFWjna/RP PEGHp6TGMO5YLFDLgiack4aXCgcked9tn8pnMUdJAz3Hsotosjm7mgzCn+kviZWot0w/ 8WvCnr4rIgOPJMRsGMwz5wFtpiGZbJgIV17LBjn4t5UIgT15dNvxvfE8TbRbJ7neUUo5 /s/QJkd9iLkdO/gXivuC0LB7EVUFRNujwdYjqbGibNL8n6IUXJ8Uing5PhizI+N6Xb2+ Q8t3KMGoS26XsD/yYhTiJTjMvUj3rbhVq6eXGTgXhklDSbrn9bJLgEzIFaG2XeWY4D1t uCYQ== X-Gm-Message-State: APjAAAUzhuLB2GDUSf/9llH0pUSTaWP0KczqWWUH+hygk1wJcUs30otN +a8pUT9Iobm1Na0rRDmQ6N/0k8/z X-Google-Smtp-Source: APXvYqzmjFfLCfsJdSR1wg2vdlztydpIRjMRxcPwbrh20R8hF6g4TPRKOGvHpss+OOAja7gdyOVv/Q== X-Received: by 2002:a50:9625:: with SMTP id y34mr7350388eda.72.1569627809392; Fri, 27 Sep 2019 16:43:29 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:28 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 05/18] dissect: fix processing of ASM statements Date: Sat, 28 Sep 2019 01:43:09 +0200 Message-Id: <20190927234322.5157-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Before commit 756731e9 ("use a specific struct for asm operands"), ASM operands ('name', 'constraint, 'expression') were stored as a sequence of 3 expressions. After, they had their own expression type: EXPR_ASM_OPERAND. However, dissect.c:do_asm_xputs() was not adapated for this change. Fix this in do_asm_xputs() by processing the 'expression' of every entries (instead of only processing every third entries). CC: Oleg Nesterov Signed-off-by: Luc Van Oostenryck --- dissect.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/dissect.c b/dissect.c index 5f067eb4c..b50c268b9 100644 --- a/dissect.c +++ b/dissect.c @@ -452,11 +452,7 @@ again: static void do_asm_xputs(usage_t mode, struct expression_list *xputs) { - int nr = 0; - - DO_LIST(xputs, expr, - if (++nr % 3 == 0) - do_expression(U_W_AOF | mode, expr)); + DO_LIST(xputs, op, do_expression(U_W_AOF | mode, op->expr)); } static struct symbol *do_statement(usage_t mode, struct statement *stmt) From patchwork Fri Sep 27 23:43: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: 11165265 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 768181747 for ; Fri, 27 Sep 2019 23:43:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 549BB20863 for ; Fri, 27 Sep 2019 23:43:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ph/UHqYy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728445AbfI0Xnc (ORCPT ); Fri, 27 Sep 2019 19:43:32 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:34519 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728430AbfI0Xnb (ORCPT ); Fri, 27 Sep 2019 19:43:31 -0400 Received: by mail-ed1-f65.google.com with SMTP id p10so3756023edq.1 for ; Fri, 27 Sep 2019 16:43:30 -0700 (PDT) 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=Iyo07vaFi/DcIHZMVGbaIxl3tAsuXZpqlLgs54vokRM=; b=Ph/UHqYyiZBacQBq6eOXi6QhD6NQVuiWOI3cTHy5l6ESSMYZUiknymSwGVNyA6Qk8v zd9RM2VxqmlM/QD0reXcI7YuMc2QAB/I5W9kjZ2trKHd/wAf5Dy62fcEmY8r75eUbUpN 1ctTiOg8RIe1bmT2x8J9zIYEVYAYR5gj6KGp+kTd584ba3At9ELwc5woZeSXFRpZ7YoP ZlYF2CjmUxzRPc7hp9P82NTUOhRvRTgce1TU18HzUgaCKQ+LN2nXfiWUJcg5B3UgaOu+ oO+s6wZxILeovJ6I9HGcvNLAegPLX2iH0ofCxNW7JqLJOejYPTgsYjKV4QSnc7/5ZHDY zoig== 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=Iyo07vaFi/DcIHZMVGbaIxl3tAsuXZpqlLgs54vokRM=; b=BoNNHuFCLqHlI3d0DJn8ocuqBl9w0o6ucRYXsSZRoi9H0LoOwQxpoX9CnITAXkdjvr g9lFLN8nhu+5SmFRVLNKXDenVb4qcBdhkbKrP5icfWlh6JatmcFNd8ma/dYPt0zbyneq 1HaagiUyo+eaf5qP+BwDykEEJ8QUMYLoMkQ9a/bJskRxN6yVl4AoB576/dI0+Qr57D0L rLtOE8WN45jngnlpovEleOjvUV84YME+YXhY359svJd2Y89TRHEk9FqRBGhv9kk6890d 4BL8aIeTNtfRaNUWeF6z4IBy0L+i4adNGyd24IMEoWFTkK87O0nuuhULyubxbdLfTu3r fR5A== X-Gm-Message-State: APjAAAUTKeY4Uz70040mUgIYSTEs1CIDXyXeeHe3ovMqaco0KerLPQBh 8QE2aH233ldtU7QipYcfs7evSUEz X-Google-Smtp-Source: APXvYqx/fSAdz2CZjB5SJe6ssDRbJ2gWAH24YCWijIc0g0h5d0caCNCL92AcEw5CK+pwN2aLyJMUaw== X-Received: by 2002:aa7:dc55:: with SMTP id g21mr7401947edu.210.1569627810048; Fri, 27 Sep 2019 16:43:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:29 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 06/18] string: add helper string_expression() Date: Sat, 28 Sep 2019 01:43:10 +0200 Message-Id: <20190927234322.5157-9-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 will help to detect earlier syntax errors concerning string constants. Signed-off-by: Luc Van Oostenryck --- expression.c | 11 +++++++++++ expression.h | 1 + 2 files changed, 12 insertions(+) diff --git a/expression.c b/expression.c index f955fb159..ffb6cb9dc 100644 --- a/expression.c +++ b/expression.c @@ -83,6 +83,17 @@ struct token *parens_expression(struct token *token, struct expression **expr, c return expect(token, ')', where); } +struct token *string_expression(struct token *token, struct expression **expr, const char *where) +{ + struct token *next = primary_expression(token, expr); + + if (!*expr || (*expr)->type != EXPR_STRING) { + sparse_error(token->pos, "string literal expected for %s", where); + *expr = NULL; + } + return next; +} + /* * Handle __func__, __FUNCTION__ and __PRETTY_FUNCTION__ token * conversion diff --git a/expression.h b/expression.h index ed6f4d65d..13f35e64b 100644 --- a/expression.h +++ b/expression.h @@ -270,6 +270,7 @@ struct token *parse_expression(struct token *token, struct expression **tree); struct token *conditional_expression(struct token *token, struct expression **tree); struct token *primary_expression(struct token *token, struct expression **tree); struct token *parens_expression(struct token *token, struct expression **expr, const char *where); +struct token *string_expression(struct token *token, struct expression **expr, const char *where); struct token *assignment_expression(struct token *token, struct expression **tree); extern int expand_symbol(struct symbol *); From patchwork Fri Sep 27 23:43: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: 11165271 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 D15681747 for ; Fri, 27 Sep 2019 23:43:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF7DF20863 for ; Fri, 27 Sep 2019 23:43:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TvuN3+yJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbfI0Xne (ORCPT ); Fri, 27 Sep 2019 19:43:34 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:42625 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728520AbfI0Xne (ORCPT ); Fri, 27 Sep 2019 19:43:34 -0400 Received: by mail-ed1-f65.google.com with SMTP id y91so3703090ede.9 for ; Fri, 27 Sep 2019 16:43:31 -0700 (PDT) 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=WrqyW+/Ecoy8saG0Oe3STO1BJadEoUJzHWhA/P0uqSc=; b=TvuN3+yJFekRh0LwjUmTSZf1q4r+xakh4I1Oj/f2+nznzMeUPZsaLjN3/+p7gqohQp 5hd4NKcBfTuhZXc8GxBBgbEOqW3vnzC0uTNnL+wZQ1SNEgCdIG+EeNS1nipW9KqRmurn 4SvpgzHWql4gn7RQ0XlBu3vlAnP3UadJg6uuAxFTWCxlPZug1qTDcEUADhCLe+I+EZEH RLVhWuge3sXCg4BMrNPp00ORvSxMtl89r0WubiMIi21W1drALR4JQWujE49tSvKfRqOg DH5DN3roW5eAnUnaYkQ5q643nkFH3NkwoIEmsBR0SbBKgdwsV1p7Agpl7zgOWwEzs3XK GNew== 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=WrqyW+/Ecoy8saG0Oe3STO1BJadEoUJzHWhA/P0uqSc=; b=tmedZZ7UO7Ddhtu0Ym4Obg6Gt8KGrD41jOpEYHYGxTEFtgNRpp1fl54FZq9EYyvsKU ORFgVIqkpUFn2bXzKd+F+uv6zyXNbWvY++25G5RW7We/ijRN7w/i0yxLv4SI2i35fGra wHBaHBiwdusglQKP/dT5X3+M3aw8dcDrO0bA60GQgl/HEUa2+KBp9lpJZcAwNxD9QbWI u8ttmyxvV5C3nv45UvS9HlSb89k/PGGNJydQsL/HhW7/jpkajl3z03ylqaxuMacO0yAZ ugIPvrRH7IxgBLhxCagqyQUg8qzhpFG15n/Y9dVqjcCSGvkAuVsSYR5eLIM5nCdZMUro cZxg== X-Gm-Message-State: APjAAAXNYYL+n0cTkWN7T75j4QmMoiWDHvUmRKcxjaNt4/AwuiVeJlu9 c2hrYLdFTsrSlYeMtm2CIv7oL3Ie X-Google-Smtp-Source: APXvYqzTo/hULhZvdY90j/AtAiqHmjtXxuxmtq8cERqfO7788FmIpRQxKoyGqzHXtcCBFcLrvDw5vw== X-Received: by 2002:a05:6402:713:: with SMTP id w19mr7363690edx.126.1569627810804; Fri, 27 Sep 2019 16:43:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:30 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 07/18] string: use string_expression() in parse_static_assert() Date: Sat, 28 Sep 2019 01:43:11 +0200 Message-Id: <20190927234322.5157-10-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 The error handling during the parsing of _Static_assert()'s message string is relatively complex. Simplify this by using the new helper string_expression(). Signed-off-by: Luc Van Oostenryck --- parse.c | 9 ++------- validation/static_assert.c | 6 +++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/parse.c b/parse.c index 795434322..401f91a1f 100644 --- a/parse.c +++ b/parse.c @@ -2132,14 +2132,9 @@ static struct token *parse_static_assert(struct token *token, struct symbol_list if (!cond) sparse_error(token->pos, "Expected constant expression"); token = expect(token, ',', "after conditional expression in _Static_assert"); - token = parse_expression(token, &message); - if (!message || message->type != EXPR_STRING) { - struct position pos; - - pos = message ? message->pos : token->pos; - sparse_error(pos, "bad or missing string literal"); + token = string_expression(token, &message, "_Static_assert()"); + if (!message) cond = NULL; - } token = expect(token, ')', "after diagnostic message in _Static_assert"); token = expect(token, ';', "after _Static_assert()"); diff --git a/validation/static_assert.c b/validation/static_assert.c index d9e96294f..dd5e0c08c 100644 --- a/validation/static_assert.c +++ b/validation/static_assert.c @@ -61,11 +61,11 @@ static_assert.c:19:16: error: static assertion failed: "expected assertion failu static_assert.c:22:16: error: bad constant expression static_assert.c:25:16: error: bad constant expression static_assert.c:27:16: error: bad constant expression -static_assert.c:35:19: error: bad or missing string literal +static_assert.c:35:19: error: string literal expected for _Static_assert() static_assert.c:37:18: error: bad constant expression -static_assert.c:52:19: error: bad or missing string literal +static_assert.c:52:19: error: string literal expected for _Static_assert() static_assert.c:53:16: error: Expected constant expression static_assert.c:54:16: error: Expected constant expression -static_assert.c:54:17: error: bad or missing string literal +static_assert.c:54:17: error: string literal expected for _Static_assert() * check-error-end */ From patchwork Fri Sep 27 23:43: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: 11165269 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 A6D0513B1 for ; Fri, 27 Sep 2019 23:43:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7B1B920863 for ; Fri, 27 Sep 2019 23:43:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QjSuHc62" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728484AbfI0Xne (ORCPT ); Fri, 27 Sep 2019 19:43:34 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:35805 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728430AbfI0Xne (ORCPT ); Fri, 27 Sep 2019 19:43:34 -0400 Received: by mail-ed1-f66.google.com with SMTP id v8so3751880eds.2 for ; Fri, 27 Sep 2019 16:43:32 -0700 (PDT) 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=XutRhQUaApduDr3EyOX07z7ClYBMA3XDqFvjeJRpMMc=; b=QjSuHc62vJf9UiOkA7wmfB6shhUNrn8cQLzdMV3uIukgHFFdeV5m/45cJIowJFnEvU J8GwxOm2FzulXlcj/kKeskZEvqCfy+IxBEfPa7CsA/tR8lA5dP8R+FIijGh9hW8ZuivF ZydCs4vuBHtFxEcLE91K/AgCUIDLr1nbCVaNIXhRMkbCErF+FgEWHQ6ew2fAtIYWOeOM 3YIdg6mw52YFbba7wewchVM/r7Dl03ctle+DqohGkA1kxGYimkiY+AYORtg4AY7olUqT kqFQPuzgRkMjG9ZaNy3mIYAFWdt80AZ0CcXm1kOdLjlE2WnXOXud+NFa/GbZde6C3Gba 1Aig== 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=XutRhQUaApduDr3EyOX07z7ClYBMA3XDqFvjeJRpMMc=; b=OqwHC7QY6zzdX+hjUjzDc9TLv4krnx1XXGNdy7JF+CaTyDL3ZDs4+t2Gfem5vngVNJ Zk9I91Ta0jRLv2vK+CTfVtEGSkAB1nwcG6ZA54xZbgqnnNLeAIp+Eug4d9Xd4bX6TFBW o2AA6rHVTV92trrEWyBxtrmwtAObqDWS9wq+lrsKrME0ak5W3rlGGrOSLa3ZgjdRyt0w KSRS4vp8fbgjdyKAbQwPjGKTpSV92LlGppTrv0r36iMRNMHSJ1B+Fn9dl2lw81kcHj5r 3FfnUDTQ54Lt55Qi0a9Wgzali8U+pkbo8vSEWOs0jNhoCmXsCBg07CnH4X7PPVXLgSL1 bt4A== X-Gm-Message-State: APjAAAWPDwUATaHyAIISK+YJy1/BY22jMnWW8mM8zaUazkelVw4ZE3qf e22WQ1MAGP4gw5mbq9sdNWlzZ4Qh X-Google-Smtp-Source: APXvYqx5kLWPJr1HpPoijiSt0YMnzfOnTvA19AuBAhuef468vW1SGzhKXNXcohkPzRL02kWxKpi+Mg== X-Received: by 2002:a50:a8a2:: with SMTP id k31mr7341231edc.79.1569627811479; Fri, 27 Sep 2019 16:43:31 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:31 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 08/18] asm: add test evaluation, expansion & linearization of ASM operands Date: Sat, 28 Sep 2019 01:43:12 +0200 Message-Id: <20190927234322.5157-11-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 ASM statements are quite complex. Add some tests to catch some potential errors. Signed-off-by: Luc Van Oostenryck --- validation/asm-bad0.c | 41 ++++++++++++++++++++++++++++++ validation/eval/asm-degen.c | 37 +++++++++++++++++++++++++++ validation/eval/asm-memop.c | 48 +++++++++++++++++++++++++++++++++++ validation/expand/asm0.c | 24 ++++++++++++++++++ validation/linear/asm-memop.c | 24 ++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 validation/asm-bad0.c create mode 100644 validation/eval/asm-degen.c create mode 100644 validation/eval/asm-memop.c create mode 100644 validation/expand/asm0.c create mode 100644 validation/linear/asm-memop.c diff --git a/validation/asm-bad0.c b/validation/asm-bad0.c new file mode 100644 index 000000000..fcd9b1c4d --- /dev/null +++ b/validation/asm-bad0.c @@ -0,0 +1,41 @@ +extern char string[]; +extern int *var; + +static void templ(void) +{ + asm(string); +} + +static void ocons(void) +{ + asm("template" : [out] string (var) : [in] "r" (0)); +} + +static void icons(void) +{ + asm("template" : [out] "=r" (var): [in] string (0)); +} + +static void oexpr(oid) +{ + asm("template" : [out] "=" (var[) : [in] "r" (0)); +} + +static void iexpr(void) +{ + asm("template" : [out] "=r" (var) : [in] "r" (var[)); +} + +/* + * check-name: asm-bad0 + * + * check-error-start +asm-bad0.c:21:41: error: Expected ] at end of array dereference +asm-bad0.c:21:41: error: got ) +asm-bad0.c:26:59: error: Expected ] at end of array dereference +asm-bad0.c:26:59: error: got ) +asm-bad0.c:6:9: error: need constant string for inline asm +asm-bad0.c:11:32: error: asm output constraint is not a string +asm-bad0.c:16:49: error: asm input constraint is not a string + * check-error-end + */ diff --git a/validation/eval/asm-degen.c b/validation/eval/asm-degen.c new file mode 100644 index 000000000..5f3191597 --- /dev/null +++ b/validation/eval/asm-degen.c @@ -0,0 +1,37 @@ +#ifdef __CHECKER__ +#define __percpu __attribute__((noderef)) +#else +#define __percpu +#endif + +static __percpu int var; +static __percpu int arr[4]; + +static void foo(void) +{ + asm("" :: "r" (var)); +} + +static void bar(void) +{ + asm("" :: "r" (arr)); +} + +static void baz(void) +{ + asm("" :: "m" (var)); +} + +static void qux(void) +{ + asm("" :: "m" (arr)); +} + +/* + * check-name: asm-degen + * check-known-to-fail + * + * check-error-start +eval/asm-degen.c:12:24: warning: dereference of noderef expression + * check-error-end + */ diff --git a/validation/eval/asm-memop.c b/validation/eval/asm-memop.c new file mode 100644 index 000000000..9bbb3a305 --- /dev/null +++ b/validation/eval/asm-memop.c @@ -0,0 +1,48 @@ +extern int g; + +void fo0(int *p) { asm volatile ("op %0" :: "p" (&g)); } +void fo1(int *p) { asm volatile ("op %0" :: "m" (g)); } + +void fo2(int *p) { asm volatile ("op %0" :: "p" (p)); } +void fo3(int *p) { asm volatile ("op %0" :: "m" (*p)); } + +/* + * check-name: eval-asm-memop + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-start +fo0: +.L0: + + asm "op %0" + in: "p" (g) + ret + + +fo1: +.L2: + + asm "op %0" + in: "m" (g) + ret + + +fo2: +.L4: + + asm "op %0" + in: "p" (%arg1) + ret + + +fo3: +.L6: + + asm "op %0" + in: "m" (%arg1) + ret + + + * check-output-end + */ diff --git a/validation/expand/asm0.c b/validation/expand/asm0.c new file mode 100644 index 000000000..0664b6224 --- /dev/null +++ b/validation/expand/asm0.c @@ -0,0 +1,24 @@ +static void foo(void) +{ + asm("" :: "i" (42 & 3)); + asm("" :: "i" (__builtin_constant_p(0))); +} + +/* + * check-name: expand-asm0 + * check-command: test-linearize $file + * check-known-to-fail + * + * check-output-start +foo: +.L0: + + asm "" + in: "i" ($2) + asm "" + in: "i" ($1) + ret + + + * check-output-end + */ diff --git a/validation/linear/asm-memop.c b/validation/linear/asm-memop.c new file mode 100644 index 000000000..97df98e22 --- /dev/null +++ b/validation/linear/asm-memop.c @@ -0,0 +1,24 @@ +static int foo(int *p) +{ + asm("op %0" : "=m" (p[0])); + + return p[0]; +} + +/* + * check-name: linear-asm-memop + * check-command: test-linearize $file + * check-known-to-fail + * + * check-output-start +foo: +.L0: + + asm "op %0" + out: "=m" (%arg1) + load.32 %r4 <- 0[%arg1] + ret.32 %r4 + + + * check-output-end + */ From patchwork Fri Sep 27 23:43: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: 11165273 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 A936713B1 for ; Fri, 27 Sep 2019 23:43:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 876BE20863 for ; Fri, 27 Sep 2019 23:43:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="t7MlNdWm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728520AbfI0Xnf (ORCPT ); Fri, 27 Sep 2019 19:43:35 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:39032 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbfI0Xnf (ORCPT ); Fri, 27 Sep 2019 19:43:35 -0400 Received: by mail-ed1-f66.google.com with SMTP id a15so3730764edt.6 for ; Fri, 27 Sep 2019 16:43:33 -0700 (PDT) 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=eA1k5J4wUXgHTrV9QWEvq/Ju/Id3sNEYL7pdfni3J4c=; b=t7MlNdWm2Kb62qmRIOJHv3XpOrAyNBoTGqrwX4S2SSUrwn0R6EJ5H9uIj1buzB3T1u ltm8G5Y4dF2KZtz9c5zHooSgJJKwGY3K4mBl3FpD8RwjjHH6zdZwBmN68nBfnYVErmqs 0K1ifF2FcTkmKthYKs0jFcS3jrUlsLqxdoM9Ul9+7ZnR/plV7WrU7Zlao/E8HyH/FIwq O0zzDXlVg78Ki8FgyUaN+v/1FC/6VSQo5JK1VcPtRdnv9SgOWYgAd4Lts/ufJs0fwpda CDFF5erPlnfFQE3Nwp2cWjh5ZUxJO5qXhsRYehojyfO+2/nCJRIBjGiZCDgRjgmmMvXC fTgw== 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=eA1k5J4wUXgHTrV9QWEvq/Ju/Id3sNEYL7pdfni3J4c=; b=Z3MlXNy0HKI+HJugLodf4nqK7PEVetHplgsFOdfF2/AGeAuC8nq7I76lYc+0Woma5L T4QdwEr/v8deo+nZm5giQ4xkQMybfgmqcINdb5ksldYCcUxvBeMBDAW2+GChzfDSsL4W z4dn6vIs3ni5A4Qwrxx89RvV5RQMQ4cwk188H/lLJ4q0m5YzGGY4q9sKylyy2WfhPUaq BsFnuzUW23vLiPmSGsOAJI2NvIoK1KzYJqyF+d397wa5a/EdR4imrXNEkFuvOkflBkiR TgwSpMDY2xkPauIrBqWs3crnIMtBTeqRrg2WtgpyHW1bKHZn8UAEjVtymSHuwOqndDuk Trbw== X-Gm-Message-State: APjAAAWTKGo82j9nDMgAC2I6Kflj1q5Fj5o1vZ7c1f8kMC4OIM1U8a6r 90a3YrwzaxHDRFzvD1a0LtVQw0OV X-Google-Smtp-Source: APXvYqw90sf9gUEVn09nXQJZZLzQwP/jzvFGVXjglFKimfiz7oZq7su1rLt/FC6puY2mTiL8KVnPWw== X-Received: by 2002:a17:906:7f03:: with SMTP id d3mr9873325ejr.115.1569627812305; Fri, 27 Sep 2019 16:43:32 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:31 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 09/18] asm: check earlier that body & constraints are strings Date: Sat, 28 Sep 2019 01:43:13 +0200 Message-Id: <20190927234322.5157-12-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 The syntax of extended ASM statements requires that the bodies & constraints are given via a literal string. However, at parsing time more general expressions are accepted and it's checked only at evaluation time if these are effectively string literals. This has at least two drawbacks: *) evaluate_asm_statement() is slightly more complicated than needed, mixing these checks with the real evaluation code *) in case of error, the diagnostic is issued later than other syntaxic warnings. Fix this by checking at parse-time that ASM bodies & constraints are string literals and not some arbitrary expressions. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 14 +++----------- parse.c | 7 ++++--- validation/asm-bad0.c | 6 +++--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/evaluate.c b/evaluate.c index 70d76523e..634da4b93 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3523,20 +3523,15 @@ static void evaluate_asm_statement(struct statement *stmt) struct symbol *sym; expr = stmt->asm_string; - if (!expr || expr->type != EXPR_STRING) { - sparse_error(stmt->pos, "need constant string for inline asm"); + if (!expr) return; - } FOR_EACH_PTR(stmt->asm_outputs, op) { /* Identifier */ /* Constraint */ expr = op->constraint; - if (!expr || expr->type != EXPR_STRING) { - sparse_error(expr ? expr->pos : stmt->pos, "asm output constraint is not a string"); - op->constraint = NULL; - } else + if (expr) verify_output_constraint(expr, expr->string->data); /* Expression */ @@ -3553,10 +3548,7 @@ static void evaluate_asm_statement(struct statement *stmt) /* Constraint */ expr = op->constraint; - if (!expr || expr->type != EXPR_STRING) { - sparse_error(expr ? expr->pos : stmt->pos, "asm input constraint is not a string"); - op->constraint = NULL; - } else + if (expr) verify_input_constraint(expr, expr->string->data); /* Expression */ diff --git a/parse.c b/parse.c index 401f91a1f..23c0ee012 100644 --- a/parse.c +++ b/parse.c @@ -2050,7 +2050,8 @@ static struct token *parse_asm_operands(struct token *token, struct statement *s op->name = token->next->next->ident; token = token->next->next->next; } - token = primary_expression(token->next, &op->constraint); + token = token->next; + token = string_expression(token, &op->constraint, "asm constraint"); token = parens_expression(token, &op->expr, "in asm parameter"); add_expression(inout, op); } while (match_op(token, ',')); @@ -2101,7 +2102,7 @@ static struct token *parse_asm_statement(struct token *token, struct statement * token = token->next; } token = expect(token, '(', "after asm"); - token = parse_expression(token, &stmt->asm_string); + token = string_expression(token, &stmt->asm_string, "inline asm"); if (match_op(token, ':')) token = parse_asm_operands(token, stmt, &stmt->asm_outputs); if (match_op(token, ':')) @@ -2118,7 +2119,7 @@ static struct token *parse_asm_declarator(struct token *token, struct decl_state { struct expression *expr; token = expect(token, '(', "after asm"); - token = parse_expression(token->next, &expr); + token = string_expression(token, &expr, "inline asm"); token = expect(token, ')', "after asm"); return token; } diff --git a/validation/asm-bad0.c b/validation/asm-bad0.c index fcd9b1c4d..aa9bf28d7 100644 --- a/validation/asm-bad0.c +++ b/validation/asm-bad0.c @@ -30,12 +30,12 @@ static void iexpr(void) * check-name: asm-bad0 * * check-error-start +asm-bad0.c:6:13: error: string literal expected for inline asm +asm-bad0.c:11:32: error: string literal expected for asm constraint +asm-bad0.c:16:49: error: string literal expected for asm constraint asm-bad0.c:21:41: error: Expected ] at end of array dereference asm-bad0.c:21:41: error: got ) asm-bad0.c:26:59: error: Expected ] at end of array dereference asm-bad0.c:26:59: error: got ) -asm-bad0.c:6:9: error: need constant string for inline asm -asm-bad0.c:11:32: error: asm output constraint is not a string -asm-bad0.c:16:49: error: asm input constraint is not a string * check-error-end */ From patchwork Fri Sep 27 23:43: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: 11165281 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 1314A1747 for ; Fri, 27 Sep 2019 23:43:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC3A520863 for ; Fri, 27 Sep 2019 23:43:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G2YpsWKq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbfI0Xnh (ORCPT ); Fri, 27 Sep 2019 19:43:37 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:40929 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728535AbfI0Xnh (ORCPT ); Fri, 27 Sep 2019 19:43:37 -0400 Received: by mail-ed1-f65.google.com with SMTP id v38so3712826edm.7 for ; Fri, 27 Sep 2019 16:43:34 -0700 (PDT) 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=Huq8YTiZwzsszN6KQaZr5IDTyewyWJ83YX7Qsl8FtRw=; b=G2YpsWKqrj8xtc1u1Ix9ParCkZ2RSAoKo1dWw05BqNc2uezMta0j9CF5nKGs9R+66z SZdI6nC9Yht5W5CMcLws62ppUCho94GoMR4P0zU7pfQK2cunPjSe9QHewltRr24XxY1T VbsqiCJQyni6y7mnFv/Co8WbWkJ7ozzb6cB+wXeomEcHubKYlXeVfRGtHmJKkHSeNv8O 1bQmAG9NGnFQK84AxVTLUNhQ40J4yWro94IBwt0ofeQ1vz3hU3TiT1m2rL7pjxe2adj7 AKvl1fHqKa3i5peEIwC70pN6B2FZqHR2BjvGubBmUwah8mj4ErTPNb7gg+rQYVVUBAv3 wh1A== 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=Huq8YTiZwzsszN6KQaZr5IDTyewyWJ83YX7Qsl8FtRw=; b=PXgMAfIywghqjKj5rV5J0peBecyI2MPO5jyZEOpqQre/cYiTjnbimlIzV1KaFw5Zqy gj/2LrO/BFE9uiHfKz3s/ZdiMbXyDzuLxLLSkRirNqHqDTu7Cc35etCMTkBrNQC14wR2 fG4d4xF0/OO0kUakSxDxcZt5WjwXW0DJDK4isdIPPRnpz4vq413gowfhMU9GndH37lpc V2pfvjSkSmknthv82EM0jnwUawuDaH1tEQmqfLWCow/i1jBtEbY4xcPzVuyKLI+Bclke KQuY35Sz/Gfr3yJ5WxBZXmsfkL0EdyctkhOLFZHAb3Af+CpKMMlyPNpZv3L4IwYkkA/a HPEA== X-Gm-Message-State: APjAAAVBq4SQVDbcWeGpjPVoPLpvJIxcbIVHlVzZ8Qk3CVJN4og7gFTH KUpnFgkmO7hb11rfYTg6A9dvY0UP X-Google-Smtp-Source: APXvYqy12ZOHAAEdb/2rbjUzJtjkv+Z3N4g3nGfUz0eVMzNc+kp8dXPEwqQfL+6sZt6HNlY+vugSMQ== X-Received: by 2002:a50:a7c4:: with SMTP id i62mr7339360edc.92.1569627813147; Fri, 27 Sep 2019 16:43:33 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:32 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 10/18] asm: use a specific struct for asm operands Date: Sat, 28 Sep 2019 01:43:14 +0200 Message-Id: <20190927234322.5157-13-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Before commit 756731e9 ("use a specific struct for asm operands") ASM operands where stored as a list of n times 3 expressions. After this commit, the triplets where stored inside a single expression of type EXPR_ASM_OPERAND. However, while this improved the parsing and use of ASM operands it needlessly reuse 'struct expression' for something that is not an expression at all. Fix this by really using a specific struct for ASM operands. Signed-off-by: Luc Van Oostenryck --- allocate.c | 1 + allocate.h | 1 + dissect.c | 2 +- evaluate.c | 5 +---- expand.c | 3 --- expression.h | 13 ++++++------- inline.c | 28 +++++++++++++--------------- lib.h | 2 ++ linearize.c | 19 ++++++++++--------- parse.c | 6 +++--- parse.h | 4 ++-- show-parse.c | 3 --- 12 files changed, 40 insertions(+), 47 deletions(-) diff --git a/allocate.c b/allocate.c index 152fa8964..bef85192e 100644 --- a/allocate.c +++ b/allocate.c @@ -141,6 +141,7 @@ ALLOCATOR(ident, "identifiers"); ALLOCATOR(token, "tokens"); ALLOCATOR(context, "contexts"); ALLOCATOR(symbol, "symbols"); +ALLOCATOR(asm_operand, "asmops"); ALLOCATOR(expression, "expressions"); ALLOCATOR(statement, "statements"); ALLOCATOR(string, "strings"); diff --git a/allocate.h b/allocate.h index 5137ae934..a6d305371 100644 --- a/allocate.h +++ b/allocate.h @@ -82,6 +82,7 @@ DECLARE_ALLOCATOR(ident); DECLARE_ALLOCATOR(token); DECLARE_ALLOCATOR(context); DECLARE_ALLOCATOR(symbol); +DECLARE_ALLOCATOR(asm_operand); DECLARE_ALLOCATOR(expression); DECLARE_ALLOCATOR(statement); DECLARE_ALLOCATOR(string); diff --git a/dissect.c b/dissect.c index b50c268b9..14d57bf5b 100644 --- a/dissect.c +++ b/dissect.c @@ -450,7 +450,7 @@ again: return ret; } -static void do_asm_xputs(usage_t mode, struct expression_list *xputs) +static void do_asm_xputs(usage_t mode, struct asm_operand_list *xputs) { DO_LIST(xputs, op, do_expression(U_W_AOF | mode, op->expr)); } diff --git a/evaluate.c b/evaluate.c index 634da4b93..7cc695c7e 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3354,9 +3354,6 @@ struct symbol *evaluate_expression(struct expression *expr) case EXPR_SLICE: expression_error(expr, "internal front-end error: SLICE re-evaluated"); return NULL; - case EXPR_ASM_OPERAND: - expression_error(expr, "internal front-end error: ASM_OPERAND evaluated"); - return NULL; } return NULL; } @@ -3519,7 +3516,7 @@ static void verify_input_constraint(struct expression *expr, const char *constra static void evaluate_asm_statement(struct statement *stmt) { struct expression *expr; - struct expression *op; + struct asm_operand *op; struct symbol *sym; expr = stmt->asm_string; diff --git a/expand.c b/expand.c index aba20b8cf..487a44943 100644 --- a/expand.c +++ b/expand.c @@ -1091,9 +1091,6 @@ static int expand_expression(struct expression *expr) case EXPR_OFFSETOF: expression_error(expr, "internal front-end error: sizeof in expansion?"); return UNSAFE; - case EXPR_ASM_OPERAND: - expression_error(expr, "internal front-end error: ASM_OPERAND in expansion?"); - return UNSAFE; } return SIDE_EFFECTS; } diff --git a/expression.h b/expression.h index 13f35e64b..a06bfe130 100644 --- a/expression.h +++ b/expression.h @@ -64,7 +64,6 @@ enum expression_type { EXPR_FVALUE, EXPR_SLICE, EXPR_OFFSETOF, - EXPR_ASM_OPERAND, }; @@ -136,6 +135,12 @@ enum { Taint_comma = 1, }; /* for expr->taint */ +struct asm_operand { + struct ident *name; + struct expression *constraint; + struct expression *expr; +}; + struct expression { enum expression_type type:8; unsigned flags:8; @@ -235,12 +240,6 @@ struct expression { struct expression *index; }; }; - // EXPR_ASM_OPERAND - struct { - struct ident *name; - struct expression *constraint; - struct expression *expr; - }; }; }; diff --git a/inline.c b/inline.c index fcc43db5c..6f73a3055 100644 --- a/inline.c +++ b/inline.c @@ -274,26 +274,24 @@ static struct expression * copy_expression(struct expression *expr) } break; } - case EXPR_ASM_OPERAND: { - expr = dup_expression(expr); - expr->constraint = copy_expression(expr->constraint); - expr->expr = copy_expression(expr->expr); - break; - } default: warning(expr->pos, "trying to copy expression type %d", expr->type); } return expr; } -static struct expression_list *copy_asm_constraints(struct expression_list *in) +static struct asm_operand_list *copy_asm_operands(struct asm_operand_list *in) { - struct expression_list *out = NULL; - struct expression *expr; - - FOR_EACH_PTR(in, expr) { - add_expression(&out, copy_expression(expr)); - } END_FOR_EACH_PTR(expr); + struct asm_operand_list *out = NULL; + struct asm_operand *old; + + FOR_EACH_PTR(in, old) { + struct asm_operand *new = __alloc_asm_operand(0); + new->name = old->name; + new->constraint = copy_expression(old->constraint); + new->expr = copy_expression(old->expr); + add_ptr_list(&out, new); + } END_FOR_EACH_PTR(old); return out; } @@ -445,8 +443,8 @@ static struct statement *copy_one_statement(struct statement *stmt) } case STMT_ASM: { stmt = dup_statement(stmt); - stmt->asm_inputs = copy_asm_constraints(stmt->asm_inputs); - stmt->asm_outputs = copy_asm_constraints(stmt->asm_outputs); + stmt->asm_inputs = copy_asm_operands(stmt->asm_inputs); + stmt->asm_outputs = copy_asm_operands(stmt->asm_outputs); /* no need to dup "clobbers", since they are all constant strings */ break; } diff --git a/lib.h b/lib.h index 322408be3..697c977a1 100644 --- a/lib.h +++ b/lib.h @@ -67,6 +67,7 @@ struct ident; struct token; struct symbol; struct statement; +struct asm_operand; struct expression; struct basic_block; struct entrypoint; @@ -76,6 +77,7 @@ struct pseudo; DECLARE_PTR_LIST(symbol_list, struct symbol); DECLARE_PTR_LIST(statement_list, struct statement); +DECLARE_PTR_LIST(asm_operand_list, struct asm_operand); DECLARE_PTR_LIST(expression_list, struct expression); DECLARE_PTR_LIST(basic_block_list, struct basic_block); DECLARE_PTR_LIST(instruction_list, struct instruction); diff --git a/linearize.c b/linearize.c index 415bf7e50..69f2dfe6b 100644 --- a/linearize.c +++ b/linearize.c @@ -2106,9 +2106,10 @@ static void add_asm_output(struct entrypoint *ep, struct instruction *insn, stru static pseudo_t linearize_asm_statement(struct entrypoint *ep, struct statement *stmt) { - struct expression *expr; struct instruction *insn; + struct expression *expr; struct asm_rules *rules; + struct asm_operand *op; const char *constraint; insn = alloc_instruction(OP_ASM, 0); @@ -2123,18 +2124,18 @@ static pseudo_t linearize_asm_statement(struct entrypoint *ep, struct statement insn->asm_rules = rules; /* Gather the inputs.. */ - FOR_EACH_PTR(stmt->asm_inputs, expr) { - constraint = expr->constraint ? expr->constraint->string->data : ""; - add_asm_input(ep, insn, expr->expr, constraint, expr->name); - } END_FOR_EACH_PTR(expr); + FOR_EACH_PTR(stmt->asm_inputs, op) { + constraint = op->constraint ? op->constraint->string->data : ""; + add_asm_input(ep, insn, op->expr, constraint, op->name); + } END_FOR_EACH_PTR(op); add_one_insn(ep, insn); /* Assign the outputs */ - FOR_EACH_PTR(stmt->asm_outputs, expr) { - constraint = expr->constraint ? expr->constraint->string->data : ""; - add_asm_output(ep, insn, expr->expr, constraint, expr->name); - } END_FOR_EACH_PTR(expr); + FOR_EACH_PTR(stmt->asm_outputs, op) { + constraint = op->constraint ? op->constraint->string->data : ""; + add_asm_output(ep, insn, op->expr, constraint, op->name); + } END_FOR_EACH_PTR(op); return VOID; } diff --git a/parse.c b/parse.c index 23c0ee012..d132a15a0 100644 --- a/parse.c +++ b/parse.c @@ -2037,13 +2037,13 @@ static struct token *expression_statement(struct token *token, struct expression } static struct token *parse_asm_operands(struct token *token, struct statement *stmt, - struct expression_list **inout) + struct asm_operand_list **inout) { /* Allow empty operands */ if (match_op(token->next, ':') || match_op(token->next, ')')) return token->next; do { - struct expression *op = alloc_expression(token->pos, EXPR_ASM_OPERAND); + struct asm_operand *op = __alloc_asm_operand(0); if (match_op(token->next, '[') && token_type(token->next->next) == TOKEN_IDENT && match_op(token->next->next->next, ']')) { @@ -2053,7 +2053,7 @@ static struct token *parse_asm_operands(struct token *token, struct statement *s token = token->next; token = string_expression(token, &op->constraint, "asm constraint"); token = parens_expression(token, &op->expr, "in asm parameter"); - add_expression(inout, op); + add_ptr_list(inout, op); } while (match_op(token, ',')); return token; } diff --git a/parse.h b/parse.h index 505c91c2c..0742a2a87 100644 --- a/parse.h +++ b/parse.h @@ -106,8 +106,8 @@ struct statement { }; struct /* asm */ { struct expression *asm_string; - struct expression_list *asm_outputs; - struct expression_list *asm_inputs; + struct asm_operand_list *asm_outputs; + struct asm_operand_list *asm_inputs; struct expression_list *asm_clobbers; struct symbol_list *asm_labels; }; diff --git a/show-parse.c b/show-parse.c index 3aa06e47c..371041675 100644 --- a/show-parse.c +++ b/show-parse.c @@ -1185,9 +1185,6 @@ int show_expression(struct expression *expr) case EXPR_TYPE: warning(expr->pos, "unable to show type expression"); return 0; - case EXPR_ASM_OPERAND: - warning(expr->pos, "unable to show asm operand expression"); - return 0; } return 0; } From patchwork Fri Sep 27 23:43: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: 11165275 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 D22A413B1 for ; Fri, 27 Sep 2019 23:43:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFBA421655 for ; Fri, 27 Sep 2019 23:43:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T4MCgcvK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728539AbfI0Xng (ORCPT ); Fri, 27 Sep 2019 19:43:36 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:39033 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728519AbfI0Xng (ORCPT ); Fri, 27 Sep 2019 19:43:36 -0400 Received: by mail-ed1-f66.google.com with SMTP id a15so3730793edt.6 for ; Fri, 27 Sep 2019 16:43:34 -0700 (PDT) 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=j3Qvg0HNus1RCaCiDUYQh1e7G28x1XC0p6SePImSKB0=; b=T4MCgcvK/CX3Kv4na+M5IC8brOAntIeuSJEMOYkkZSMUtBJCSCOWJSBrOMCBmdUmHH OUWSqPShc4bjk9on1aVWb5UcjaxjYB7FEf51wGSLxjx+9V/Vaolb+4r7Phvr2rseKGkz FJPJAT7SkMg7zNn/DAtYScKqalKG1FRS64HVMBip8CwimJvHArtTBVi5766l8c5hvRuM QULSIJTKqOE/1EnhVvzLbBQIAv60MDBerqz3xhvbOTOX+4AZaGI9XsJsh13rEyFdOm74 mvYFEzDKJ4+SfLI1RGtRVFEDoAGURuAWVo65b+U9QkpAmFIRhlkdwswIim5lf9jlRw2T TDpg== 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=j3Qvg0HNus1RCaCiDUYQh1e7G28x1XC0p6SePImSKB0=; b=bsNfEUxudZGO3B0On2AoTOvV7eEQKmdHK0e4wqHs9Pa2AYJgvP39qFVVHJO13Hc2eJ VDbZ0uiH4gGPEalb9GgMoL+9eCbfJch+W9V2OG1jRvjBQL00LqKQbnh/hSjN8exiL7JY jcA0dQBMUECVqQkdipvIIdAhU9hkY9Tikv5MHxIj8dKT1FYIoTBmtwozApFecGrkgrGL CyKX9rGO5R/FRy3wINf/P8zdK234deNhO9KomiTw6xg3DoRRKYUxoz6QKbpz6H5hf85e aK9AqUiMCc9C74Mb+jF+fvdIJLMwg6WSy6zyedVWPTTUWaSjNc4Hzv/ZV2YVBm0t5YP4 UBFg== X-Gm-Message-State: APjAAAUE3EdH0YYO3BIS+p6NXbBhYk9QWeatlJSUMdrkSnbMRkChCwLy tPdD4svoYov3BE3A/rwrKhoEmvHw X-Google-Smtp-Source: APXvYqxqmuRnZ0nGYpzMolkuk7anxv3EtbFepKJwTp1Ydn2bWMRep1fmXSdNKym69qWlnQrh4KwxAA== X-Received: by 2002:a17:906:9498:: with SMTP id t24mr9770136ejx.88.1569627813995; Fri, 27 Sep 2019 16:43:33 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:33 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 11/18] asm: keep using struct asm_operand during linearization Date: Sat, 28 Sep 2019 01:43:15 +0200 Message-Id: <20190927234322.5157-14-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 In linearize_asm_statement(), the functions asm_add_{input,output}() are given the ASM operand 'name', 'constraint' & 'expression' as argument. However, it's much simpler to simply give the whole struct asm_operad. Signed-off-by: Luc Van Oostenryck --- linearize.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/linearize.c b/linearize.c index 69f2dfe6b..7724350ba 100644 --- a/linearize.c +++ b/linearize.c @@ -2075,31 +2075,29 @@ static pseudo_t linearize_range(struct entrypoint *ep, struct statement *stmt) ALLOCATOR(asm_rules, "asm rules"); ALLOCATOR(asm_constraint, "asm constraints"); -static void add_asm_input(struct entrypoint *ep, struct instruction *insn, struct expression *expr, - const char *constraint, const struct ident *ident) +static void add_asm_input(struct entrypoint *ep, struct instruction *insn, struct asm_operand *op) { - pseudo_t pseudo = linearize_expression(ep, expr); + pseudo_t pseudo = linearize_expression(ep, op->expr); struct asm_constraint *rule = __alloc_asm_constraint(0); - rule->ident = ident; - rule->constraint = constraint; + rule->ident = op->name; + rule->constraint = op->constraint ? op->constraint->string->data : ""; use_pseudo(insn, pseudo, &rule->pseudo); add_ptr_list(&insn->asm_rules->inputs, rule); } -static void add_asm_output(struct entrypoint *ep, struct instruction *insn, struct expression *expr, - const char *constraint, const struct ident *ident) +static void add_asm_output(struct entrypoint *ep, struct instruction *insn, struct asm_operand *op) { struct access_data ad = { NULL, }; pseudo_t pseudo = alloc_pseudo(insn); struct asm_constraint *rule; - if (!expr || !linearize_address_gen(ep, expr, &ad)) + if (!op->expr || !linearize_address_gen(ep, op->expr, &ad)) return; linearize_store_gen(ep, pseudo, &ad); rule = __alloc_asm_constraint(0); - rule->ident = ident; - rule->constraint = constraint; + rule->ident = op->name; + rule->constraint = op->constraint ? op->constraint->string->data : ""; use_pseudo(insn, pseudo, &rule->pseudo); add_ptr_list(&insn->asm_rules->outputs, rule); } @@ -2110,7 +2108,6 @@ static pseudo_t linearize_asm_statement(struct entrypoint *ep, struct statement struct expression *expr; struct asm_rules *rules; struct asm_operand *op; - const char *constraint; insn = alloc_instruction(OP_ASM, 0); expr = stmt->asm_string; @@ -2125,16 +2122,14 @@ static pseudo_t linearize_asm_statement(struct entrypoint *ep, struct statement /* Gather the inputs.. */ FOR_EACH_PTR(stmt->asm_inputs, op) { - constraint = op->constraint ? op->constraint->string->data : ""; - add_asm_input(ep, insn, op->expr, constraint, op->name); + add_asm_input(ep, insn, op); } END_FOR_EACH_PTR(op); add_one_insn(ep, insn); /* Assign the outputs */ FOR_EACH_PTR(stmt->asm_outputs, op) { - constraint = op->constraint ? op->constraint->string->data : ""; - add_asm_output(ep, insn, op->expr, constraint, op->name); + add_asm_output(ep, insn, op); } END_FOR_EACH_PTR(op); return VOID; From patchwork Fri Sep 27 23:43: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: 11165277 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 5E5581747 for ; Fri, 27 Sep 2019 23:43:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C33320863 for ; Fri, 27 Sep 2019 23:43:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UASWG3il" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728519AbfI0Xnh (ORCPT ); Fri, 27 Sep 2019 19:43:37 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:43222 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728538AbfI0Xng (ORCPT ); Fri, 27 Sep 2019 19:43:36 -0400 Received: by mail-ed1-f68.google.com with SMTP id r9so3710095edl.10 for ; Fri, 27 Sep 2019 16:43:35 -0700 (PDT) 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=SnOM5Pb5Vnf7nnww3gdTizCR+rYOAfPt/wLezCRlGLc=; b=UASWG3ilQkkFs4lUDR2OCHCGZ9IvaBWghep0VAt+aFvY7rXR3lkfEMAMN+bnTa3kRx NDXq6OnsbLKhyXX8AqhouwsCQYN09XoWZfd78s4u3zzFm69sYlOVjdRnJXx8im7cYdPW ++l6MSSt4DRJoq15J+pJkWGrfsKhwe8CdHRzTcnJWhJwSa5emy+m88Ww12i5Jw4nf2qi 91m3NpxDlITVpkW4zsrOnplpN3nMrA4hr28Ns5pJVcZvuduxlRpHzawSOYA3iJei78CL B44JWEFTwyEAoFag4cErii8tz7KNa8Hw7hgdE2tAT4vdAaszB4TNxJar2J69bVAgINKa kiDw== 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=SnOM5Pb5Vnf7nnww3gdTizCR+rYOAfPt/wLezCRlGLc=; b=NaiDwgJ1VMPRvV3e7Q9ADaw1ilEj+0ZvMkIShuMNsx1IIo5KbZvP5TK4blvOYg7oud gAvhxldmhfnqWSwqxDFlggzTqZab0oJA+c6awrOtAORjeQ/nUw6VCYKiPM5f4/RKdoC2 rBdGASGluW4BrEdzWFYkiRTbvk/MuXYmtID/21rRPlyUBDG3ndygqGQmJ/HIhaQWOI3r jvrJUwYvcFhjgsMeP2NKKmb1P5EIeH3ltsB7OUk/Iykh6uINLwN6J8X12z5KnZpQ9AvB NIfPc8ThyR7ieCVhbZxggAcUl1Ees7zdTwel/5PSsxz5lCAINSzspNuhKgpt02+Yafv1 83Cg== X-Gm-Message-State: APjAAAU3lvtD9uzMjQd4ss3SRPCzjF9RpkbVYvlxAy4v6oCV00yrf8p2 s0mIDRCd/tRDjgfVi4GD4e3Ug1jI X-Google-Smtp-Source: APXvYqzdHKZvjbndEEN5o0BitQf7Hk+ntLktY28QMDByBY6TjbUyxU6bzKIhm9dJPJ/Z7uFj9aSOaA== X-Received: by 2002:a17:906:5214:: with SMTP id g20mr9802321ejm.220.1569627814777; Fri, 27 Sep 2019 16:43:34 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:34 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 12/18] asm: parse constraints Date: Sat, 28 Sep 2019 01:43:16 +0200 Message-Id: <20190927234322.5157-15-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 The details of the ASM constraint strings are needed for their validation but also for the proper evaluation of the operands. So, parse these strings and store the significant properties in struct asm_operand where they can be used for the next steps. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++-- expression.h | 6 +++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/evaluate.c b/evaluate.c index 7cc695c7e..4c5c2c255 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3493,6 +3493,74 @@ static void evaluate_iterator(struct statement *stmt) evaluate_statement(stmt->iterator_post_statement); } + +static void parse_asm_constraint(struct asm_operand *op) +{ + struct expression *constraint = op->constraint; + const char *str = constraint->string->data; + int c; + + switch (str[0]) { + case '+': + op->is_modify = true; + /* fall-through */ + case '=': + op->is_assign = true; + str++; + break; + } + + while ((c = *str++)) { + switch (c) { + case '=': + case '+': + sparse_error(constraint->pos, "invalid ASM constraint '%c'", c); + break; + + case '&': + op->is_earlyclobber = true; + break; + case '%': + op->is_commutative = true; + break; + case 'r': + op->is_register = true; + break; + + case 'm': + case 'o': + case 'V': + case 'Q': + op->is_memory = true; + break; + + case '<': + case '>': + // FIXME: ignored for now + break; + + case ',': + // FIXME: multiple alternative constraints + break; + + case '0' ... '9': + // FIXME: numeric matching constraint? + break; + case '[': + // FIXME: symbolic matching constraint + return; + + default: + // FIXME: arch-specific (and multi-letter) constraints + break; + } + } + + // FIXME: how to deal with multi-constraint? + if (op->is_register) + op->is_memory = 0; +} + static void verify_output_constraint(struct expression *expr, const char *constraint) { switch (*constraint) { @@ -3528,8 +3596,10 @@ static void evaluate_asm_statement(struct statement *stmt) /* Constraint */ expr = op->constraint; - if (expr) + if (expr) { + parse_asm_constraint(op); verify_output_constraint(expr, expr->string->data); + } /* Expression */ expr = op->expr; @@ -3545,8 +3615,10 @@ static void evaluate_asm_statement(struct statement *stmt) /* Constraint */ expr = op->constraint; - if (expr) + if (expr) { + parse_asm_constraint(op); verify_input_constraint(expr, expr->string->data); + } /* Expression */ if (!evaluate_expression(op->expr)) diff --git a/expression.h b/expression.h index a06bfe130..3b79e0f11 100644 --- a/expression.h +++ b/expression.h @@ -139,6 +139,12 @@ struct asm_operand { struct ident *name; struct expression *constraint; struct expression *expr; + unsigned int is_assign:1; + unsigned int is_modify:1; + unsigned int is_earlyclobber:1; + unsigned int is_commutative:1; + unsigned int is_register:1; + unsigned int is_memory:1; }; struct expression { From patchwork Fri Sep 27 23:43: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: 11165279 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 D0AD913B1 for ; Fri, 27 Sep 2019 23:43:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AEC6720863 for ; Fri, 27 Sep 2019 23:43:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V+AohnJt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728607AbfI0Xnh (ORCPT ); Fri, 27 Sep 2019 19:43:37 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:44900 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728526AbfI0Xnh (ORCPT ); Fri, 27 Sep 2019 19:43:37 -0400 Received: by mail-ed1-f66.google.com with SMTP id r16so3694294edq.11 for ; Fri, 27 Sep 2019 16:43:36 -0700 (PDT) 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=JQequhl2PPsaKXoLPtX2x02a5Oj9hYUGHbm555GcZDk=; b=V+AohnJthP+PN+DSPnLAJBf1f3Cmgk/4NemoI5VuqhJodmxvR6ohVVyaAubGo25eDb XKIaVhq7aTu0pOp/DfG2m6iXXkKd4lrU582A/icDFHGYzczcZ8NqY/CFIaTpNjmX+A+S 5Ccq/2VCo6ZqRMrCtKzYmC3NLsNtXanAguW6ly/zt4HGKPp8D+bvWgbC5vuiMFcNtYWy auARCeB+zrpdo7RpJlbe+ETMBmiP365Bgew6coznUjEYtNVdknltViG0uIcFayz5PbQi SUX3HLVYQZOcEBHSHHHqPvhljQ4wW0B3U8R3vQ1wolNwfPiFWPZRzbbIJULeRAW042XA ovUQ== 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=JQequhl2PPsaKXoLPtX2x02a5Oj9hYUGHbm555GcZDk=; b=KmujiLGy10QS+tByEYXqgycj/OkbS0aRwKxW1EW+J/y682y8Ge9DZSabqxEGIHhxP/ sipy0Vpb1cNLrO3C9i4snQhH34ofkKqMfF8BnhtqRn1NkZY/0Al1kXUpI+65TuNJjoqk xhDV7hIokvxxWFvAp14hwPtIWW4mxclYc6YerG0kUV6hUKv7Cw7dIQHOw/e/Ut97pyTR sBBnwNQjyEaPhkOvoDDauy86wp9w0hFRpb+LdRJwU1knWMfjSJtLhed3IE4XPub5UmU4 /uLmr0rVMg3zuPgZ69cIQ/P26ZftE3VAqUpxfAHN8rI9QeSiJEYilZ7DHY2Ro4Vjm6Iv UHUg== X-Gm-Message-State: APjAAAV3mODRB40d+2tdozTrpubtyPfZDz1JI19ruNTCSuH1Xev64jtV tfNIl/C471IsKyHe82VS2Lhvb0qP X-Google-Smtp-Source: APXvYqyw1xhh4cpG1dEk1lkJifGRZz9rMTytUbiNWrTJcP9n1PS69+MeU9kmUvlbmtP8PBXV49GG1A== X-Received: by 2002:a17:906:4bc3:: with SMTP id x3mr9915390ejv.200.1569627815498; Fri, 27 Sep 2019 16:43:35 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:35 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 13/18] asm: use parse_asm_constraint() to verify constraints Date: Sat, 28 Sep 2019 01:43:17 +0200 Message-Id: <20190927234322.5157-16-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 In extended ASM statements, output constraints need to be prefixed with "=" or "+" and input constraints must not. This is checked in verify_{output,input}_constraint() where the constraint string is analyzed to look after these two chars. However, the needed information is now already available thanks to parse_asm_constraint(). So, use the result of the parsing of the constraint strings to avoid to analyze again these strings during their verification. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/evaluate.c b/evaluate.c index 4c5c2c255..f0f9b4b34 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3561,24 +3561,22 @@ static void parse_asm_constraint(struct asm_operand *op) op->is_memory = 0; } -static void verify_output_constraint(struct expression *expr, const char *constraint) +static void verify_output_constraint(struct asm_operand *op) { - switch (*constraint) { - case '=': /* Assignment */ - case '+': /* Update */ - break; - default: + struct expression *expr = op->constraint; + const char *constraint = expr->string->data; + + if (!op->is_assign) expression_error(expr, "output constraint is not an assignment constraint (\"%s\")", constraint); - } } -static void verify_input_constraint(struct expression *expr, const char *constraint) +static void verify_input_constraint(struct asm_operand *op) { - switch (*constraint) { - case '=': /* Assignment */ - case '+': /* Update */ + struct expression *expr = op->constraint; + const char *constraint = expr->string->data; + + if (op->is_assign) expression_error(expr, "input constraint with assignment (\"%s\")", constraint); - } } static void evaluate_asm_statement(struct statement *stmt) @@ -3587,18 +3585,16 @@ static void evaluate_asm_statement(struct statement *stmt) struct asm_operand *op; struct symbol *sym; - expr = stmt->asm_string; - if (!expr) + if (!stmt->asm_string) return; FOR_EACH_PTR(stmt->asm_outputs, op) { /* Identifier */ /* Constraint */ - expr = op->constraint; - if (expr) { + if (op->constraint) { parse_asm_constraint(op); - verify_output_constraint(expr, expr->string->data); + verify_output_constraint(op); } /* Expression */ @@ -3614,10 +3610,9 @@ static void evaluate_asm_statement(struct statement *stmt) /* Identifier */ /* Constraint */ - expr = op->constraint; - if (expr) { + if (op->constraint) { parse_asm_constraint(op); - verify_input_constraint(expr, expr->string->data); + verify_input_constraint(op); } /* Expression */ From patchwork Fri Sep 27 23:43: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: 11165283 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 D02A11747 for ; Fri, 27 Sep 2019 23:43:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE64B20863 for ; Fri, 27 Sep 2019 23:43:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bQncEjgd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728535AbfI0Xni (ORCPT ); Fri, 27 Sep 2019 19:43:38 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:41399 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728538AbfI0Xni (ORCPT ); Fri, 27 Sep 2019 19:43:38 -0400 Received: by mail-ed1-f65.google.com with SMTP id f20so3711538edv.8 for ; Fri, 27 Sep 2019 16:43:37 -0700 (PDT) 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=sIxF0fk3/UNrjRYRUSTrX1zPJ94k+QatPGej04y0ilI=; b=bQncEjgdtxMwGcKofiAErxPfOQou6u0kDYUySpGgOz8tuFBNEtseFuUiaXAHVI3cR7 t1Ebijn3/3U14DE6xWT1BXd05TVMmbxsYThecdFHWYAVs7U9lR62y8DjgeEK0qDqWBvf iwOLUWmFqlQTVW4+QUxQ3ajFBUExN1rAEWgUpOZg6Jst9FgMT7RD8LEofJcJqFAhiSXx KIYzBvM+epVbHi4RvCn65xvV61KOmB7zCsYBOIbxX0XnyzSxmV6/aQRhKg9AxtiZ8mof SiWtML5QOtfgqqWkA73Uw3I+koMpRpBoEzqFpLXEBRUyY//trh906OBdL7GxYFRKNi7L S9Sg== 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=sIxF0fk3/UNrjRYRUSTrX1zPJ94k+QatPGej04y0ilI=; b=rYHBnng1aXDOpu6eHByK7BwhS6VRxdmOTsNNnfdBavGJgV0OaDNLDoQWfeb2hBVSFB +cSCcWN5EENrDxMjDc7IzkMLWA5zlJC9+GTIYNptpxgnrzmWaFE95fZn2l1Mg9Ex6Hgs V7aCHWVG5ijKJPKbHzDiRqqqRt1GhYTzvKl0DqDOWK3wh33bnAtPIu0o9RgaQ5obtxxn Y4+bB8TDAo7uSxq+L79layP6YKI0iJ6TRqSkHfhYX0P9QMY9mTIRoBeFg+vV97NsRRR6 gu4YV3mOfYutNAh3EdSVBwMBoBb6hs2615cOAru9M4VAhEUD0HszLApGQVDD1eOLPV43 t9TQ== X-Gm-Message-State: APjAAAXKbSV9K24PBX5hinTUxVL5UMBatXgM+X+2Ulh54sg/HFNu6AyZ Z75/Cy7i5QHSfxOfSRZJf0liM6OV X-Google-Smtp-Source: APXvYqzxvXUP7jSbvOnU0Yosh/tCQslISAaRg4m5Y6sOU14zRLvwTJNPPpUT+Ly7Wd4T2CMHZrfPRQ== X-Received: by 2002:a17:906:f4a:: with SMTP id h10mr9847450ejj.158.1569627816267; Fri, 27 Sep 2019 16:43:36 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:35 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 14/18] asm: missing evaluation of asm statements Date: Sat, 28 Sep 2019 01:43:18 +0200 Message-Id: <20190927234322.5157-17-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 The operands of extended ASM need to have their type evaluated, exactly like any other expression. So, add the missing evaluation of ASM operands. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 18 ++++++++++++++++++ validation/eval/asm-memop.c | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/evaluate.c b/evaluate.c index f0f9b4b34..4f7efc480 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3579,6 +3579,22 @@ static void verify_input_constraint(struct asm_operand *op) expression_error(expr, "input constraint with assignment (\"%s\")", constraint); } +static void evaluate_asm_memop(struct asm_operand *op) +{ + if (op->is_memory) { + struct expression *expr = op->expr; + struct expression *addr; + + // implicit addressof + addr = alloc_expression(expr->pos, EXPR_PREOP); + addr->op = '&'; + addr->unop = expr; + + evaluate_addressof(addr); + op->expr = addr; + } +} + static void evaluate_asm_statement(struct statement *stmt) { struct expression *expr; @@ -3604,6 +3620,7 @@ static void evaluate_asm_statement(struct statement *stmt) if (!lvalue_expression(expr)) warning(expr->pos, "asm output is not an lvalue"); evaluate_assign_to(expr, expr->ctype); + evaluate_asm_memop(op); } END_FOR_EACH_PTR(op); FOR_EACH_PTR(stmt->asm_inputs, op) { @@ -3618,6 +3635,7 @@ static void evaluate_asm_statement(struct statement *stmt) /* Expression */ if (!evaluate_expression(op->expr)) return; + evaluate_asm_memop(op); } END_FOR_EACH_PTR(op); FOR_EACH_PTR(stmt->asm_clobbers, expr) { diff --git a/validation/eval/asm-memop.c b/validation/eval/asm-memop.c index 9bbb3a305..33ba0e5a5 100644 --- a/validation/eval/asm-memop.c +++ b/validation/eval/asm-memop.c @@ -9,7 +9,6 @@ void fo3(int *p) { asm volatile ("op %0" :: "m" (*p)); } /* * check-name: eval-asm-memop * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-start fo0: From patchwork Fri Sep 27 23:43: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: 11165287 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 D243113B1 for ; Fri, 27 Sep 2019 23:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE42021655 for ; Fri, 27 Sep 2019 23:43:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="reg1Yd6s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbfI0Xnk (ORCPT ); Fri, 27 Sep 2019 19:43:40 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:35810 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728526AbfI0Xnk (ORCPT ); Fri, 27 Sep 2019 19:43:40 -0400 Received: by mail-ed1-f65.google.com with SMTP id v8so3751972eds.2 for ; Fri, 27 Sep 2019 16:43:37 -0700 (PDT) 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=Kxo4izDidFVysmwdv+kfyq0Qbyy1ne+H7jf+alrQCx4=; b=reg1Yd6s4nPbhjdPU/a59tavpevW4zrhdAygvvhUr4MBKx/fZ7V0ejBM4l2an6S51H qUbTRwwGqzw2/1CedjUqGkFQYMfyg6ziTFCOLubIvULBGua+c5UPyIH3kyQHqx3LTZAL 5hZLCtVn2PS0Bp9zIhWBsDR5s7O+C/ijcSB7IJSu7ERD7epO2CEAtv6EaCoEITIrT2F/ VP+NCv/rpb2KxIKJA9gftarGFZaSkV7MkMgM4SGNTjYeVIJ67zWxbh5q4srE8/zOgCTL gGVqoYJn5oKAvyy6uLJZJoDrssEL6J4zMJS/3ULJDVvL21fuiA/YthBdN1/gQWKUqZvG k6BA== 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=Kxo4izDidFVysmwdv+kfyq0Qbyy1ne+H7jf+alrQCx4=; b=pSnouju2mWDkwDrC2QEgMLveJgxq3X+4OcotExNdahtP5dgApH1zs/ws+I7835yu+O Xbgt12v28GoEL0BwOGm123XUpKCDhQrtj5PFRL8XIW4+T2QKh38ydyRPUF4600in5cj0 gRgiPKHb2ya9Iwfvi6HmrDFRW34KYS89eJoTVaD0p+0aIHPrmCvg8qQQOTyofCkkhYaK xWH401LrrEVaL0Qayai6DzjU1EF1LqNeRW6m4cGSclgwNaZ5icIVzE0bFgY2xIJjHBdJ g19xqBXZyYLDyq3hvW7CKIauRnC8/CkDa58D/2Tcfmia3lpPFjH6JroyffLf/uPCWaf9 /BDA== X-Gm-Message-State: APjAAAXB+XhwPn09a9mxTweW6GiMr1DzX8cHXIwzPqZ6hgeFyXZnqPog 6ZEn6sQA/UDelm2ILALRsDvy4FFt X-Google-Smtp-Source: APXvYqzcZqlEGNDSz+xTpXVdHkq1zg1BxTR3zQoujCGkTV3R/EOqpbK/hG+OV+lstGyHTbgZ5JsylQ== X-Received: by 2002:a05:6402:346:: with SMTP id r6mr7349359edw.124.1569627816958; Fri, 27 Sep 2019 16:43:36 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:36 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 15/18] asm: linearization of output memory operands is different Date: Sat, 28 Sep 2019 01:43:19 +0200 Message-Id: <20190927234322.5157-18-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 ASM memory operands are considered by GCC as some kind of implicit reference. Their linearization should thus not create any storage statement: the storage is done by the ASM code itself. Adjust the linearization of such operands accordingly. Signed-off-by: Luc Van Oostenryck --- linearize.c | 13 +++++++++---- validation/linear/asm-memop.c | 1 - 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/linearize.c b/linearize.c index 7724350ba..68be3ab1e 100644 --- a/linearize.c +++ b/linearize.c @@ -2089,12 +2089,17 @@ static void add_asm_input(struct entrypoint *ep, struct instruction *insn, struc static void add_asm_output(struct entrypoint *ep, struct instruction *insn, struct asm_operand *op) { struct access_data ad = { NULL, }; - pseudo_t pseudo = alloc_pseudo(insn); + pseudo_t pseudo; struct asm_constraint *rule; - if (!op->expr || !linearize_address_gen(ep, op->expr, &ad)) - return; - linearize_store_gen(ep, pseudo, &ad); + if (op->is_memory) { + pseudo = linearize_expression(ep, op->expr); + } else { + if (!linearize_address_gen(ep, op->expr, &ad)) + return; + pseudo = alloc_pseudo(insn); + linearize_store_gen(ep, pseudo, &ad); + } rule = __alloc_asm_constraint(0); rule->ident = op->name; rule->constraint = op->constraint ? op->constraint->string->data : ""; diff --git a/validation/linear/asm-memop.c b/validation/linear/asm-memop.c index 97df98e22..245c8d0f0 100644 --- a/validation/linear/asm-memop.c +++ b/validation/linear/asm-memop.c @@ -8,7 +8,6 @@ static int foo(int *p) /* * check-name: linear-asm-memop * check-command: test-linearize $file - * check-known-to-fail * * check-output-start foo: From patchwork Fri Sep 27 23:43: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: 11165285 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 1310213B1 for ; Fri, 27 Sep 2019 23:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E525221655 for ; Fri, 27 Sep 2019 23:43:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IfbVSztQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728538AbfI0Xnj (ORCPT ); Fri, 27 Sep 2019 19:43:39 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:36444 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728639AbfI0Xnj (ORCPT ); Fri, 27 Sep 2019 19:43:39 -0400 Received: by mail-ed1-f66.google.com with SMTP id h2so3746300edn.3 for ; Fri, 27 Sep 2019 16:43:38 -0700 (PDT) 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=yiBVmjLvtUxLkBWELtNSRiQfWzyWOYMOqHSYgFqWD6w=; b=IfbVSztQwUzZu2uFhMTkoUON1UuDkW6NS4QSquRc4FtcdBrxw0UauOGZ9oGFGde7nT 14FZDwnS1hwUAl2Rj4wYUSXAraKQCVl1SyLFUOUalHNTaAloOxmj9ZBa73DlPSDNkTo0 FM5fkJJznqPs0cKBuCFDjQp49InXWrOZCkbpBCXBNiUBexGcy6mx/hKHMtH3E1H3munB B73omc387R7CuVeNNOEVF7z0Bip3itqBs5YcieHXSGqJatBWiQzwD+PqxGmHHorFdiZS BZjnMXhTFj5y24VKuMgx11y73TEx787cgdRJZkqi4wC+RQ+9fTz4j/JOgaMGPB1bwGcc jwNw== 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=yiBVmjLvtUxLkBWELtNSRiQfWzyWOYMOqHSYgFqWD6w=; b=Zf6HB47lIBEVjubZV0MJuNrv7SrmzvonJdHbXhsdaVeaIzgZu/4VRz16z4ltJaTmTh PVDkgrhYUlpHCUxWmNbD29Lu8O1C4lx4VEw5UvP30D7SWdZbea9VDvKHx9lDipbI16K2 oHPak9AznSAXxaaG+erRWBtropeJZ8QW1CJN1Hw9EiFOIFrOVNiCRFz7XD7NXrLeHdf6 fBE8lM90hKlRWD71+mxXYAWv7rXOmA5/x31DyyrDvN6kmMii1NtdLN1CgqzKa7U9CSCE hUQb0woL4MFFOHQFNMjebW6Rp8vQmbcBU5KY/PuQ40NP+ZrYP6WITOFv4xsezMD7a8nh fpOQ== X-Gm-Message-State: APjAAAXQ8WeGs8ybQLr086ZRw4H4JeOPEo5RHWlfDy6amrNnx1Komzg0 aGE8OaSgtWFMc41xq833ixbvA6gE X-Google-Smtp-Source: APXvYqzkYSVT7YzQngtSaxrmNPkzohyTdEI79YADGqp0UclbYOMcgISn0QV9NIPLb+TF9UV1LXxyfA== X-Received: by 2002:a50:fd01:: with SMTP id i1mr7364595eds.184.1569627817727; Fri, 27 Sep 2019 16:43:37 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:37 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 16/18] asm: fix liveness memory operand Date: Sat, 28 Sep 2019 01:43:20 +0200 Message-Id: <20190927234322.5157-19-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Since memory operands are only some kind of reference, the pseudo in an output operand is not defined by the statement, the reference is only used. Fix the liveness processing accordingly. Signed-off-by: Luc Van Oostenryck --- linearize.c | 1 + linearize.h | 1 + liveness.c | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/linearize.c b/linearize.c index 68be3ab1e..09b1c7ee8 100644 --- a/linearize.c +++ b/linearize.c @@ -2101,6 +2101,7 @@ static void add_asm_output(struct entrypoint *ep, struct instruction *insn, stru linearize_store_gen(ep, pseudo, &ad); } rule = __alloc_asm_constraint(0); + rule->is_memory = op->is_memory; rule->ident = op->name; rule->constraint = op->constraint ? op->constraint->string->data : ""; use_pseudo(insn, pseudo, &rule->pseudo); diff --git a/linearize.h b/linearize.h index 89da3db6e..76efd0b47 100644 --- a/linearize.h +++ b/linearize.h @@ -68,6 +68,7 @@ struct asm_constraint { pseudo_t pseudo; const char *constraint; const struct ident *ident; + unsigned int is_memory:1; }; DECLARE_ALLOCATOR(asm_constraint); diff --git a/liveness.c b/liveness.c index 93a7cc300..33cd04831 100644 --- a/liveness.c +++ b/liveness.c @@ -39,7 +39,10 @@ static void asm_liveness(struct basic_block *bb, struct instruction *insn, } END_FOR_EACH_PTR(entry); FOR_EACH_PTR(insn->asm_rules->outputs, entry) { - def(bb, entry->pseudo); + if (entry->is_memory) + use(bb, entry->pseudo); + else + def(bb, entry->pseudo); } END_FOR_EACH_PTR(entry); } From patchwork Fri Sep 27 23:43: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: 11165291 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 81A9C1747 for ; Fri, 27 Sep 2019 23:43:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FC4221655 for ; Fri, 27 Sep 2019 23:43:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eGthPUNl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726116AbfI0Xnm (ORCPT ); Fri, 27 Sep 2019 19:43:42 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:46377 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728526AbfI0Xnl (ORCPT ); Fri, 27 Sep 2019 19:43:41 -0400 Received: by mail-ed1-f65.google.com with SMTP id t3so3695792edw.13 for ; Fri, 27 Sep 2019 16:43:39 -0700 (PDT) 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=ZjyMZuwrBy4r/LWYnbd1FBAyoOnRAHv6EWO7rzdfMR0=; b=eGthPUNlIkeWqgvyG0kOD2vSxoVlIsYxobZyYbkqjcDZuCT33cEFE06knkXWhk8D8k ixYo7BHJw86IJQGMXq0n8FQ57z0wB+2bsO7Pdu32XFre9xJkLNgN20t94I5o1oGzBt7r dkr9IfptE39UCOSlljYY3C2+00ZIUKiYzhMgcsCKXkWMviIZ7bvW/7H+XD6f79XeVaLg 9Xg+mufsC1kxn9efP8yihBC9ihvlKlmbXQMAfjfm31oGRHZVr1qRnCwR5XT44y3hTVFn Bp2HEkB+uauyZvMspl3JrxpqqKa5akMUGj9JmKlG9wtmbrLoTzq8RyN8+nppcghy78Ty ItiA== 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=ZjyMZuwrBy4r/LWYnbd1FBAyoOnRAHv6EWO7rzdfMR0=; b=KjONXTzAv368ACCTEfgwXCH8qxcMvWYLgYMEdC+e9MnAgq5Qc1LGp0QZnVym9EWYTQ iq0XayGY9rutBfzJcIHBW+yhvKgkUQc80uBsgk6AxsGMGfBcyiEJtORYVy09r1PL298S ciK25Sbf/9xrZ01jE0KkT/djxpA3Drn0hXnXgmYgUPD/uhYFQwxLWe5jDibJN5NJmKEt zE0bJAh21ZeSazKXiO6ozQ3OR3gtwHrmzZxyoEgTzQOk49tZ4tStZeEvJJJ5ik4OOF41 A/1HtnkPKO/D/mHPL/rfSCB2nBpIEuJghgzHUKIeqUempcICUyGbGV5/kV3Gu8tPHrWu 5AQA== X-Gm-Message-State: APjAAAVYNs3b3WnonsmkF88dNvBdPDFiFj/plQCfHQFSFRPiLcCXIKTb NHamnzVWm2L7eo/BB3exPc5MIxwd X-Google-Smtp-Source: APXvYqw5vXNRkcmagIiLuZswURb8tciATOUJgzXnDEIBEyk6iKCd/9o/1Oj5E1IzB638cyAHrTlA3w== X-Received: by 2002:a50:cd1a:: with SMTP id z26mr7359368edi.75.1569627818383; Fri, 27 Sep 2019 16:43:38 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:37 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 17/18] asm: fix missing expansion of asm statements Date: Sat, 28 Sep 2019 01:43:21 +0200 Message-Id: <20190927234322.5157-20-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 The operands of extended ASM need to be expanded, exactly like any other expression. For example, without this expansion expressions with __builtin_compatible_types_p() can't be linearized and will issue a 'warning unknown expression". So, add the missing expansion of ASM operands. Signed-off-by: Luc Van Oostenryck --- expand.c | 18 +++++++++++++++++- validation/expand/asm0.c | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/expand.c b/expand.c index 487a44943..ac6686e45 100644 --- a/expand.c +++ b/expand.c @@ -1160,6 +1160,22 @@ static int expand_if_statement(struct statement *stmt) return SIDE_EFFECTS; } +static int expand_asm_statement(struct statement *stmt) +{ + struct asm_operand *op; + int cost = 0; + + FOR_EACH_PTR(stmt->asm_outputs, op) { + cost += expand_expression(op->expr); + } END_FOR_EACH_PTR(op); + + FOR_EACH_PTR(stmt->asm_inputs, op) { + cost += expand_expression(op->expr); + } END_FOR_EACH_PTR(op); + + return cost; +} + /* * Expanding a compound statement is really just * about adding up the costs of each individual @@ -1250,7 +1266,7 @@ static int expand_statement(struct statement *stmt) case STMT_NONE: break; case STMT_ASM: - /* FIXME! Do the asm parameter evaluation! */ + expand_asm_statement(stmt); break; case STMT_CONTEXT: expand_expression(stmt->expression); diff --git a/validation/expand/asm0.c b/validation/expand/asm0.c index 0664b6224..568a4d198 100644 --- a/validation/expand/asm0.c +++ b/validation/expand/asm0.c @@ -7,7 +7,6 @@ static void foo(void) /* * check-name: expand-asm0 * check-command: test-linearize $file - * check-known-to-fail * * check-output-start foo: From patchwork Fri Sep 27 23:43:22 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: 11165289 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 7EE661747 for ; Fri, 27 Sep 2019 23:43:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C29E21655 for ; Fri, 27 Sep 2019 23:43:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ii3todN7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728639AbfI0Xnl (ORCPT ); Fri, 27 Sep 2019 19:43:41 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:44905 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728565AbfI0Xnl (ORCPT ); Fri, 27 Sep 2019 19:43:41 -0400 Received: by mail-ed1-f68.google.com with SMTP id r16so3694356edq.11 for ; Fri, 27 Sep 2019 16:43:39 -0700 (PDT) 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=e4OmaF6OC3gjZP120sptRVAm/496uYugpt1ZAoFC1dw=; b=Ii3todN7AkzAtOmlhktxi3km/XjS8pVefR0czlVCODnDPHUJY/xGRgIAJPPlF+5ScF H85EF83BZykS/uDkQxWoTULFU2eQDS0o0rjVPva/naestq3m3e5HpPTrY4HPICNOZGVn 87j+1qr7a3kyvvfUMTC34zr29SgJjVDB7l+av+X8+vMf97Z+8QBUxd7Pq2uSrpUSZ6qR MuXhKcn3hbRBzpyMSqjxZVqGDW67jIKvUTENW1BZjUPZ3J6XuKAPhftab2SORcmLgM4j uUZksKRpQERvcv2bF64voyLOg9M1ClPOlOOJG9FiQH4UOGJvkVO0vE+Yn1nPt1TeIV4Y fV+A== 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=e4OmaF6OC3gjZP120sptRVAm/496uYugpt1ZAoFC1dw=; b=ufnsJgfJ/JfE1AIyTtZipSXqj4vPWy8h+dzxhK/++TYcVaFFRdpwOL1zG2+tCr5tVr yMGslqctuEODu1EI+qujtvKf0vWWbwaMcFIY5L4wGrySWP0WjMqBCLhcwg4VcWsIQltL RBnHBz5VtUl8eEQ/6ZFtvKVoofYQVPP5OnKv/7VF+RinuHnukaQjGALSeqwJBZ4FD4rc 28rxI6vVTAPf42C14NuZzzu9Jy/tVeRSJC0/jQWcQcLFyg1lOhxyquFyKU/3ChCIyF9c Hvde6cbqCyH2pMdGfqwMIGtO51wy+qVg1PQqWXBYM8Y66qjkCSIYe6dRg/8qXuTOWa40 swSw== X-Gm-Message-State: APjAAAXwK3DI21MjJzHF8l6DUhhXFxFVn1vt5iVJa+AKK6q1Nuf/CWhE 7u0qEf+islckRBCqgKeoU+jhHY2q X-Google-Smtp-Source: APXvYqxGWxUKizdtIlfr5DvhAK/wOwlDmpkbdJ0e6AOMTQOibdCakqcw5Nn4KVEDcJ3IDY5EqIZ4sQ== X-Received: by 2002:a17:906:3286:: with SMTP id 6mr9966972ejw.37.1569627819044; Fri, 27 Sep 2019 16:43:39 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:4080:1900:da8:650b:f6cc:5bcf]) by smtp.gmail.com with ESMTPSA id ng5sm730393ejb.9.2019.09.27.16.43.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2019 16:43:38 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Linus Torvalds Subject: [PATCH 18/18] asm: arrays & functions in non-memory operand degenerate into pointers Date: Sat, 28 Sep 2019 01:43:22 +0200 Message-Id: <20190927234322.5157-21-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190927234322.5157-1-luc.vanoostenryck@gmail.com> References: <20190927234322.5157-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 Non-memory asm operands are very much like the argument of a function and as such any array (or function designator) given need to degenerate into the corresponding pointer. Signed-off-by: Luc Van Oostenryck --- evaluate.c | 3 +++ validation/eval/asm-degen.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/evaluate.c b/evaluate.c index 4f7efc480..157260691 100644 --- a/evaluate.c +++ b/evaluate.c @@ -3592,6 +3592,9 @@ static void evaluate_asm_memop(struct asm_operand *op) evaluate_addressof(addr); op->expr = addr; + } else { + evaluate_expression(op->expr); + degenerate(op->expr); } } diff --git a/validation/eval/asm-degen.c b/validation/eval/asm-degen.c index 5f3191597..7bbed9255 100644 --- a/validation/eval/asm-degen.c +++ b/validation/eval/asm-degen.c @@ -29,7 +29,6 @@ static void qux(void) /* * check-name: asm-degen - * check-known-to-fail * * check-error-start eval/asm-degen.c:12:24: warning: dereference of noderef expression