From: David Malcolm <dmalcolm@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org, David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 08/10] Fix g++.dg/ubsan/pr63956.C
Date: Thu, 03 Dec 2015 14:37:00 -0000 [thread overview]
Message-ID: <1449154548-43964-9-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <1449154548-43964-1-git-send-email-dmalcolm@redhat.com>
With the location patch, various errors in g++.dg/ubsan/pr63956.C
change:
8 constexpr int
9 fn1 (int a, int b)
10 {
11 if (b != 2)
12 a <<= b;
13 return a;
14 }
15
16 constexpr int i1 = fn1 (5, 3);
17 constexpr int i2 = fn1 (5, -2); // { dg-error "is negative" }
Here's the first error as printed by the status quo:
g++.dg/ubsan/pr63956.C:17:24: in constexpr expansion of ‘fn1(5, -2)’
g++.dg/ubsan/pr63956.C:17:30: error: right operand of shift expression ‘(5 << -2)’ is negative
constexpr int i2 = fn1 (5, -2); // { dg-error "is negative" }
^
...and with the location patch:
g++.dg/ubsan/pr63956.C:17:24: in constexpr expansion of ‘fn1(5, -2)’
g++.dg/ubsan/pr63956.C:12:11: error: right operand of shift expression ‘(5 << -2)’ is negative
a <<= b;
^
I believe this is an improvement: we're now identifying both relevant
places, rather than just one, and clearly highlighting the exact
subexpression of interest.
Hence this patch updates the testcase to reflect the improved
location information.
gcc/testsuite/ChangeLog:
* g++.dg/ubsan/pr63956.C: Update dg directives to reflect
improved location information.
---
gcc/testsuite/g++.dg/ubsan/pr63956.C | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/gcc/testsuite/g++.dg/ubsan/pr63956.C b/gcc/testsuite/g++.dg/ubsan/pr63956.C
index 185a719..b265631 100644
--- a/gcc/testsuite/g++.dg/ubsan/pr63956.C
+++ b/gcc/testsuite/g++.dg/ubsan/pr63956.C
@@ -10,15 +10,18 @@ fn1 (int a, int b)
{
if (b != 2)
a <<= b;
+ // { dg-error "5 << -2.. is negative" "" { target *-*-* } 12 }
+ // { dg-error "is >= than the precision of the left operand" "" { target *-*-* } 12 }
+ // { dg-error "-2 << 4.. is negative" "" { target *-*-* } 12 }
return a;
}
constexpr int i1 = fn1 (5, 3);
-constexpr int i2 = fn1 (5, -2); // { dg-error "is negative" }
-constexpr int i3 = fn1 (5, sizeof (int) * __CHAR_BIT__); // { dg-error "is >= than the precision of the left operand" }
-constexpr int i4 = fn1 (5, 256); // { dg-error "is >= than the precision of the left operand" }
+constexpr int i2 = fn1 (5, -2); // { dg-message "in constexpr expansion" }
+constexpr int i3 = fn1 (5, sizeof (int) * __CHAR_BIT__); // { dg-message "in constexpr expansion" }
+constexpr int i4 = fn1 (5, 256); // { dg-message "in constexpr expansion" }
constexpr int i5 = fn1 (5, 2);
-constexpr int i6 = fn1 (-2, 4); // { dg-error "is negative" }
+constexpr int i6 = fn1 (-2, 4); // { dg-message "in constexpr expansion" }
constexpr int i7 = fn1 (0, 2);
SA (i1 == 40);
@@ -30,13 +33,16 @@ fn2 (int a, int b)
{
if (b != 2)
a >>= b;
+ // { dg-error "4 >> -1.. is negative" "" { target *-*-* } 35 }
+ // { dg-error "is >= than the precision of the left operand" "" { target *-*-* } 35 }
+
return a;
}
constexpr int j1 = fn2 (4, 1);
-constexpr int j2 = fn2 (4, -1); // { dg-error "is negative" }
-constexpr int j3 = fn2 (10, sizeof (int) * __CHAR_BIT__); // { dg-error "is >= than the precision of the left operand" }
-constexpr int j4 = fn2 (1, 256); // { dg-error "is >= than the precision of the left operand" }
+constexpr int j2 = fn2 (4, -1); // { dg-message "in constexpr expansion" }
+constexpr int j3 = fn2 (10, sizeof (int) * __CHAR_BIT__); // { dg-message "in constexpr expansion" }
+constexpr int j4 = fn2 (1, 256); // { dg-message "in constexpr expansion" }
constexpr int j5 = fn2 (5, 2);
constexpr int j6 = fn2 (-2, 4);
constexpr int j7 = fn2 (0, 4);
@@ -49,12 +55,12 @@ constexpr int
fn3 (int a, int b)
{
if (b != 2)
- a = a / b;
+ a = a / b; // { dg-error "..7 / 0.. is not a constant expression" }
return a;
}
constexpr int k1 = fn3 (8, 4);
-constexpr int k2 = fn3 (7, 0); // { dg-error "is not a constant expression" }
+constexpr int k2 = fn3 (7, 0); // { dg-message "in constexpr expansion" }
constexpr int k3 = fn3 (INT_MIN, -1); // { dg-error "overflow in constant expression" }
SA (k1 == 2);
@@ -63,12 +69,12 @@ constexpr float
fn4 (float a, float b)
{
if (b != 2.0)
- a = a / b;
+ a = a / b; // { dg-error "is not a constant expression" }
return a;
}
constexpr float l1 = fn4 (5.0, 3.0);
-constexpr float l2 = fn4 (7.0, 0.0); // { dg-error "is not a constant expression" }
+constexpr float l2 = fn4 (7.0, 0.0); // { dg-message "in constexpr expansion" }
constexpr int
fn5 (const int *a, int b)
--
1.8.5.3
next prev parent reply other threads:[~2015-12-03 14:37 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-07 3:40 [PATCH/RFC] C++ FE: expression ranges (work in progress) David Malcolm
2015-11-15 4:43 ` [PATCH/RFC] C++ FE: expression ranges (v2) David Malcolm
2015-11-19 20:46 ` Jason Merrill
2015-11-21 8:22 ` Jason Merrill
2015-11-21 8:22 ` Jakub Jelinek
2015-11-23 10:02 ` Richard Biener
2015-11-23 16:58 ` David Malcolm
2015-11-23 17:08 ` Jakub Jelinek
2015-11-23 17:09 ` Marek Polacek
2015-11-23 19:45 ` Jason Merrill
2015-11-24 9:42 ` Richard Biener
2015-11-24 11:08 ` David Malcolm
2015-11-24 11:50 ` Richard Biener
2015-11-24 12:15 ` Marek Polacek
2015-11-25 20:32 ` [PATCH/RFC 0/2] C++ FE: expression ranges (v3) David Malcolm
2015-11-25 20:32 ` [PATCH 1/2] RFC: C++: attempt to provide location_t in more places David Malcolm
2015-11-25 21:33 ` Jason Merrill
2015-12-03 14:36 ` [PATCH 00/10] C++ expression ranges v4 David Malcolm
2015-12-03 14:36 ` [PATCH 04/10] Fix g++.dg/template/crash55.C David Malcolm
2015-12-03 14:37 ` [PATCH 07/10] Fix g++.dg/template/ref3.C David Malcolm
2015-12-03 20:38 ` Jason Merrill
2015-12-03 22:08 ` David Malcolm
2015-12-04 16:01 ` Jason Merrill
2015-12-04 16:45 ` [PATCH] Add XFAIL to g++.dg/template/ref3.C (PR c++/68699) David Malcolm
2015-12-04 17:09 ` Jason Merrill
2015-12-03 14:37 ` [PATCH 01/10] C++ FE: expression ranges v4 David Malcolm
2015-12-04 17:10 ` Jason Merrill
2015-12-04 18:13 ` David Malcolm
2015-12-03 14:37 ` [PATCH 10/10] Fix g++.dg/warn/Wconversion-real-integer2.C David Malcolm
2015-12-03 14:37 ` [PATCH 03/10] Fix g++.dg/gomp/loop-1.C David Malcolm
2015-12-03 14:37 ` [PATCH 02/10] Fix g++.dg/cpp0x/nsdmi-template14.C David Malcolm
2015-12-03 20:33 ` Jason Merrill
2015-12-03 21:43 ` David Malcolm
2015-12-03 22:17 ` Jason Merrill
2015-12-04 14:22 ` [PATCH 02/10 v2] Fix g++.dg/cpp0x/nsdmi-template14.C (v2) David Malcolm
2015-12-03 14:37 ` [PATCH 05/10] Fix location of dg-error within g++.dg/template/pr64100.C David Malcolm
2015-12-03 14:37 ` [PATCH 09/10] Fix g++.dg/warn/pr35635.C David Malcolm
2015-12-03 14:37 ` David Malcolm [this message]
2015-12-03 14:53 ` [PATCH 06/10] Fix g++.dg/template/pseudodtor3.C David Malcolm
2015-11-25 20:38 ` [PATCH 2/2] RFC: C++ FE: expression ranges (work in progress) v3 David Malcolm
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=1449154548-43964-9-git-send-email-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.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 read-only IMAP folder(s) and NNTP newsgroup(s).