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: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 7/9] div0: warn also during simplification
Date: Wed, 31 May 2017 05:22:05 +0200	[thread overview]
Message-ID: <20170531032207.95830-8-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170531032207.95830-1-luc.vanoostenryck@gmail.com>

sparse now warn about divion by zero during linearization
but during simplification some expression can become constants
and so some new divisions by zero can appears.

Warn also on those new and to avoid to warn also here on the old
ones, mark the instructions for wich we have already be warned.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c              |  1 +
 simplify.c               | 12 ++++++++++++
 validation/div-by-zero.c |  2 ++
 3 files changed, 15 insertions(+)

diff --git a/linearize.c b/linearize.c
index 604a67b82..51405539d 100644
--- a/linearize.c
+++ b/linearize.c
@@ -969,6 +969,7 @@ static void warn_undef_insn(struct instruction *insn, int warn)
 		if (is_pseudo_value(insn->src2, 0)) {
 			if (warn && Wdiv_by_zero)
 				warning(insn->pos, "division by zero");
+			insn->warned = 1;
 		}
 		break;
 	default:
diff --git a/simplify.c b/simplify.c
index a141ddd43..40e1c253b 100644
--- a/simplify.c
+++ b/simplify.c
@@ -404,6 +404,15 @@ static int simplify_asr(struct instruction *insn, pseudo_t pseudo, long long val
 	return 0;
 }
 
+static void check_divide_by_zero(struct instruction *insn, long long value)
+{
+	if (value != 0 || insn->warned)
+		return;
+	if (Wdiv_by_zero)
+		warning(insn->pos, "division by zero");
+	insn->warned = 1;
+}
+
 static int simplify_mul_div(struct instruction *insn, long long value)
 {
 	unsigned long long sbit = 1ULL << (insn->size - 1);
@@ -525,9 +534,12 @@ static int simplify_constant_rightside(struct instruction *insn)
 	case OP_MODU: case OP_MODS:
 		if (value == 1)
 			return replace_with_pseudo(insn, value_pseudo(0));
+		check_divide_by_zero(insn, value);
 		return 0;
 
 	case OP_DIVU: case OP_DIVS:
+		check_divide_by_zero(insn, value);
+		/* Fall through */
 	case OP_MULU: case OP_MULS:
 		return simplify_mul_div(insn, value);
 
diff --git a/validation/div-by-zero.c b/validation/div-by-zero.c
index a06944a58..353c85889 100644
--- a/validation/div-by-zero.c
+++ b/validation/div-by-zero.c
@@ -49,7 +49,9 @@ div-by-zero.c:18:30: warning: division by zero
 div-by-zero.c:19:30: warning: division by zero
 div-by-zero.c:21:42: warning: division by zero
 div-by-zero.c:22:33: warning: division by zero
+div-by-zero.c:23:38: warning: division by zero
 div-by-zero.c:25:42: warning: division by zero
 div-by-zero.c:26:33: warning: division by zero
+div-by-zero.c:27:38: warning: division by zero
  * check-error-end
  */
-- 
2.13.0


  parent reply	other threads:[~2017-05-31  3:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31  3:21 [PATCH 0/9] division by zero warnings Luc Van Oostenryck
2017-05-31  3:21 ` [PATCH 1/9] add is_pseudo_value() Luc Van Oostenryck
2017-05-31  3:22 ` [PATCH 2/9] add a .warned field to struct instruction Luc Van Oostenryck
2017-05-31  3:22 ` [PATCH 3/9] div0: warn on integer divide by 0 also when the lhs is not constant Luc Van Oostenryck
2017-05-31  3:22 ` [PATCH 4/9] div0: warn on division by zero - general case Luc Van Oostenryck
2017-05-31  3:22 ` [PATCH 5/9] div0: add warning option -Wdiv-by-zero Luc Van Oostenryck
2017-05-31  3:22 ` [PATCH 6/9] div0: use -Wdiv-by-zero Luc Van Oostenryck
2017-05-31  3:22 ` Luc Van Oostenryck [this message]
2017-05-31  3:22 ` [PATCH 8/9] div0: warn on float divide by 0 also when the lhs is not constant Luc Van Oostenryck
2017-05-31  3:22 ` [PATCH 9/9] div0: add missing tests for floating point div by zero 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=20170531032207.95830-8-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
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).