linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Stafford Horne <shorne@gmail.com>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 3/4] shift-assign: restrict shift count to unsigned int
Date: Thu,  6 Aug 2020 21:30:02 +0200	[thread overview]
Message-ID: <20200806193003.10144-4-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200806193003.10144-1-luc.vanoostenryck@gmail.com>

After the RHS of shift-assigns had been integer-promoted,
both gcc & clang seems to restrict it to an unsigned int.
This only make a difference when the shift count is negative
and would it make it UB.

Better to have the same generated code, so make the same here.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c                        | 5 +++++
 validation/linear/shift-assign2.c | 1 -
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/evaluate.c b/evaluate.c
index 6d8ecd7f6c25..a9adc72f6b57 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -1348,6 +1348,11 @@ static int evaluate_assign_op(struct expression *expr)
 			unrestrict(expr->right, sclass, &s);
 			source = integer_promotion(s);
 			expr->right = cast_to(expr->right, source);
+
+			// both gcc & clang seems to do this, so ...
+			if (target->bit_size > source->bit_size)
+				expr->right = cast_to(expr->right, &uint_ctype);
+
 			goto Cast;
 		} else if (!(sclass & TYPE_RESTRICT))
 			goto usual;
diff --git a/validation/linear/shift-assign2.c b/validation/linear/shift-assign2.c
index 30d74376478e..9990ac38e800 100644
--- a/validation/linear/shift-assign2.c
+++ b/validation/linear/shift-assign2.c
@@ -13,7 +13,6 @@ u64 u64s32(u64 a, s32 b) { a >>= b; return a; }
 /*
  * check-name: shift-assign2
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-start
 s64s16:
-- 
2.28.0


  parent reply	other threads:[~2020-08-06 19:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-06 19:29 [PATCH 0/4] Fix shifts-assigns and avoid warns on deadcode Luc Van Oostenryck
2020-08-06 19:30 ` [PATCH 1/4] shift-assign: add more testcases for bogus linearization Luc Van Oostenryck
2020-08-06 19:30 ` [PATCH 2/4] shift-assign: fix linearization of shift-assign Luc Van Oostenryck
2020-08-06 19:30 ` Luc Van Oostenryck [this message]
2020-08-06 19:30 ` [PATCH 4/4] bad-shift: wait dead code elimination to warn about bad shifts Luc Van Oostenryck
2020-08-15  9:57   ` Stafford Horne
2020-08-15 11:15     ` Luc Van Oostenryck
2020-08-15 13:51       ` Stafford Horne
2020-08-15  9:59 ` [PATCH 0/4] Fix shifts-assigns and avoid warns on deadcode Stafford Horne
2020-08-15 11:03   ` Luc Van Oostenryck

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=20200806193003.10144-4-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=shorne@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).