This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix ubsan and C++14 constexpr ICEs (PR sanitizer/63956)
- From: Marek Polacek <polacek at redhat dot com>
- To: Mike Stump <mikestump at comcast dot net>
- Cc: Jason Merrill <jason at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 11 Feb 2015 21:58:17 +0100
- Subject: Re: [PATCH] Fix ubsan and C++14 constexpr ICEs (PR sanitizer/63956)
- Authentication-results: sourceware.org; auth=none
- References: <20141120171452 dot GG29446 at redhat dot com> <20141120172725 dot GT1745 at tucnak dot redhat dot com> <20141120190404 dot GH29446 at redhat dot com> <547607F1 dot 5090909 at redhat dot com> <20141127135729 dot GB15555 at redhat dot com> <547BE7CC dot 2000306 at redhat dot com> <20141201105255 dot GK15555 at redhat dot com> <41BF253D-853D-4948-8BEB-EECED93CDB50 at comcast dot net> <20150211122414 dot GQ28333 at redhat dot com> <F11E0771-98F3-4CD0-B3FE-FF5942F25435 at comcast dot net>
On Wed, Feb 11, 2015 at 09:44:24AM -0800, Mike Stump wrote:
> On Feb 11, 2015, at 4:24 AM, Marek Polacek <polacek@redhat.com> wrote:
> >
> > The following patch splits the test into C and C++ test cases, so
> > hopefully fixing the issue. Ok for trunk?
> >
> > 2015-02-11 Marek Polacek <polacek@redhat.com>
> >
> > * g++.dg/ubsan/shift-1.C: New test.
> > * gcc.dg/ubsan/c-shift-2.c: New test.
> > * c-c++-common/ubsan/shift-5.c: Remove file.
> >
> > diff --git gcc/testsuite/g++.dg/ubsan/shift-1.C gcc/testsuite/g++.dg/ubsan/shift-1.C
> > index e69de29..8a71279 100644
> > --- gcc/testsuite/g++.dg/ubsan/shift-1.C
> > +++ gcc/testsuite/g++.dg/ubsan/shift-1.C
> > @@ -0,0 +1,37 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-fsanitize=shift -w" } */
> > +/* { dg-shouldfail "ubsan" } */
> > +
> > +int
> > +foo (int x)
> > +{
> > + /* None of the following should pass. */
> > + switch (x)
> > + {
> > + case 1 >> -1:
> > +/* { dg-error "is not a constant expression" "" { xfail { *-*-* } } 11 } */
>
> Never include line numbers, unless there is no other way. Here, I think you can drop it, and merely ensure this is on the right line?
>
> An example from gcc.dg:
>
> int g2(int a; __attribute__((unused))); /* { dg-error "just a forward declaration" "no parms" { xfail *-*-* } } */
>
> Iâm hoping that style will work.
Yeah, it works, I don't know why I changed it for the C test case, but
not for the C++ one.
> Ok with the above fixes, if applicable.
Thanks.
2015-02-11 Marek Polacek <polacek@redhat.com>
* g++.dg/ubsan/shift-1.C: New test.
* gcc.dg/ubsan/c-shift-2.c: New test.
* c-c++-common/ubsan/shift-5.c: Remove file.
diff --git gcc/testsuite/g++.dg/ubsan/shift-1.C gcc/testsuite/g++.dg/ubsan/shift-1.C
index e69de29..05e049e 100644
--- gcc/testsuite/g++.dg/ubsan/shift-1.C
+++ gcc/testsuite/g++.dg/ubsan/shift-1.C
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift -w" } */
+/* { dg-shouldfail "ubsan" } */
+
+int
+foo (int x)
+{
+ /* None of the following should pass. */
+ switch (x)
+ {
+ case 1 >> -1: /* { dg-error "is not a constant expression" "" { xfail { *-*-* } } } */
+ case -1 >> -1: /* { dg-error "is not a constant expression" "" { xfail { *-*-* } } } */
+ case 1 << -1: /* { dg-error "is not a constant expression" "" { xfail { *-*-* } } } */
+ case -1 << -1: /* { dg-error "is not a constant expression" "" { xfail { *-*-* } } } */
+ return 1;
+ }
+ return 0;
+}
+
+int
+bar (int x)
+{
+ /* None of the following should pass. */
+ switch (x)
+ {
+ case -1 >> 200: /* { dg-error "is not a constant expression" "" { xfail { *-*-* } } } */
+ case 1 << 200: /* { dg-error "is not a constant expression" "" { xfail { *-*-* } } } */
+ return 1;
+ }
+ return 0;
+}
diff --git gcc/testsuite/gcc.dg/ubsan/c-shift-2.c gcc/testsuite/gcc.dg/ubsan/c-shift-2.c
index e69de29..beb0dbe 100644
--- gcc/testsuite/gcc.dg/ubsan/c-shift-2.c
+++ gcc/testsuite/gcc.dg/ubsan/c-shift-2.c
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=shift -w" } */
+/* { dg-shouldfail "ubsan" } */
+
+int
+foo (int x)
+{
+ /* None of the following should pass. */
+ switch (x)
+ {
+ case 1 >> -1: /* { dg-error "case label does not reduce to an integer constant" } */
+ case -1 >> -1: /* { dg-error "case label does not reduce to an integer constant" } */
+ case 1 << -1: /* { dg-error "case label does not reduce to an integer constant" } */
+ case -1 << -1: /* { dg-error "case label does not reduce to an integer constant" } */
+ return 1;
+ }
+ return 0;
+}
+
+int
+bar (int x)
+{
+ /* None of the following should pass. */
+ switch (x)
+ {
+ case -1 >> 200: /* { dg-error "case label does not reduce to an integer constant" } */
+ case 1 << 200: /* { dg-error "case label does not reduce to an integer constant" } */
+ return 1;
+ }
+ return 0;
+}
Marek