Linux-Sparse Archive on lore.kernel.org
 help / color / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 4/4] [RFC] fix evaluation error with assignment of qualified arrays
Date: Fri, 10 Jul 2020 02:13:22 +0200
Message-ID: <20200710001322.18391-5-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200710001322.18391-1-luc.vanoostenryck@gmail.com>

This is a fix for a problem reported today to the mailing list.

In check_assignment_types(), the first 'level' is checked by the
function itself but the next level is checked by the type_difference().
This later function take as arguments, beside the types to be
checked, the modifiers that can be assumed for each of the types
(this works as a kind of reverse mask).
But these modifiers are taken from target_qualifiers() which,
purposely ignore the modifiers for arrays introduced in commit
    984b7b66457c ("[PATCH] deal correctly with qualifiers on arrays")
with the comment:
    "Pointers to any array are considered as pointers to unqualified
    type as far as implicit conversions are concerned"

But by dropping these modifiers, type_difference() reports
incorrect results for pointers to qualified arrays.

So, do not use target_qualifiers() but take the modifiers directly
from the ctypes. Admittingly, I'm far from sure that this is the
right fix but it solve several wrong cases.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                     | 4 ++--
 validation/eval/array-quals0.c | 1 -
 validation/eval/array-quals1.c | 1 -
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index f515ce6f2de6..dddea76182ad 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1444,8 +1444,8 @@ static int check_assignment_types(struct symbol *target, struct expression **rp,
 		}
 		b1 = examine_pointer_target(t);
 		b2 = examine_pointer_target(s);
-		mod1 = target_qualifiers(t);
-		mod2 = target_qualifiers(s);
+		mod1 = t->ctype.modifiers & MOD_IGN;
+		mod2 = s->ctype.modifiers & MOD_IGN;
 		if (whitelist_pointers(b1, b2)) {
 			/*
 			 * assignments to/from void * are OK, provided that
diff --git a/validation/eval/array-quals0.c b/validation/eval/array-quals0.c
index 9cb08c1722d7..30727490289e 100644
--- a/validation/eval/array-quals0.c
+++ b/validation/eval/array-quals0.c
@@ -3,5 +3,4 @@ static const int (*p)[3] = a;
 
 /*
  * check-name: array-quals0
- * check-known-to-fail
  */
diff --git a/validation/eval/array-quals1.c b/validation/eval/array-quals1.c
index a1c3905826d5..d3e54f3ec8dc 100644
--- a/validation/eval/array-quals1.c
+++ b/validation/eval/array-quals1.c
@@ -25,7 +25,6 @@ static          void *const ko_vi__a = &vi__a;
 
 /*
  * check-name: array-quals1
- * check-known-to-fail
  *
  * check-error-start
 eval/array-quals1.c:12:38: warning: incorrect type in initializer (different modifiers)
-- 
2.27.0


      parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10  0:13 [PATCH 0/4] fix evaluation of assignment and " Luc Van Oostenryck
2020-07-10  0:13 ` [PATCH 1/4] add a testcase for assignment to const <type> (*)[] Luc Van Oostenryck
2020-07-10  0:13 ` [PATCH 2/4] add another testcase with const array/pointer Luc Van Oostenryck
2020-07-10  0:13 ` [PATCH 3/4] add testcase for missing warning for assignment to const Luc Van Oostenryck
2020-07-10  0:13 ` Luc Van Oostenryck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200710001322.18391-5-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Sparse Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sparse/0 linux-sparse/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sparse linux-sparse/ https://lore.kernel.org/linux-sparse \
		linux-sparse@vger.kernel.org
	public-inbox-index linux-sparse

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sparse


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git