diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/g++.dg/ubsan | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/g++.dg/ubsan')
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-1.C | 18 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-2.C | 10 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx1y-vla.C | 13 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C | 10 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59250.C | 18 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59306.C | 13 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59331.C | 8 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59415.C | 8 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59437.C | 24 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr60569.C | 21 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-1.C | 27 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-2.C | 33 | ||||
-rw-r--r-- | gcc-4.9/gcc/testsuite/g++.dg/ubsan/ubsan.exp | 34 |
13 files changed, 237 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-1.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-1.C new file mode 100644 index 000000000..f2b2cbd1c --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-1.C @@ -0,0 +1,18 @@ +/* { dg-do run { target c++11 } } */ +/* { dg-options "-fsanitize=shift -w" } */ + +#include <stdio.h> + +int +main (void) +{ + fputs ("UBSAN TEST START\n", stderr); + + int a = 1; + a <<= 31; + + fputs ("UBSAN TEST END\n", stderr); + return 0; +} + +/* { dg-output "UBSAN TEST START(\n|\r\n|\r)UBSAN TEST END" } */ diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-2.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-2.C new file mode 100644 index 000000000..867908aef --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx11-shift-2.C @@ -0,0 +1,10 @@ +/* { dg-do run { target c++11 } } */ +/* { dg-options "-fsanitize=shift -w" } */ + +int +main (void) +{ + int a = -42; + a <<= 1; +} +/* { dg-output "left shift of negative value -42" } */ diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx1y-vla.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx1y-vla.C new file mode 100644 index 000000000..ca1e922d6 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/cxx1y-vla.C @@ -0,0 +1,13 @@ +/* { dg-do run { target c++1y } } */ +/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */ +/* { dg-shouldfail "ubsan" } */ + +int +main (void) +{ + int y = -18; + int a[y]; + return 0; +} + +/* { dg-output "terminate called after throwing an instance" } */ diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C new file mode 100644 index 000000000..88acfa151 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/div-by-zero-1.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=integer-divide-by-zero -w" } */ + +void +foo (int i) +{ + switch (i) + case 0 * (1 / 0): /* { dg-error "is not a constant expression" } */ + ; +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59250.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59250.C new file mode 100644 index 000000000..e438d24fd --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59250.C @@ -0,0 +1,18 @@ +// PR sanitizer/59250 +// { dg-do compile } +// { dg-options "-fsanitize=undefined" } + +struct E { + int i; +}; + +struct S { + const char *s; + S (const char *); + static E *e; +}; + +S::S (const char *) : s (0) +{ + e = new E (); +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59306.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59306.C new file mode 100644 index 000000000..621093c6b --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59306.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-fsanitize=undefined" } + +class A { + void bar (void (A::*) (int)); + void foo (int); + void B (); +}; + +void A::B() +{ + bar (&A::foo); +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59331.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59331.C new file mode 100644 index 000000000..1bb3666ef --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59331.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */ + +void foo(int i) +{ + /* Don't warn here with "value computed is not used". */ + char a[i]; +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59415.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59415.C new file mode 100644 index 000000000..4c373f7c9 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59415.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=null -Wall -fvtable-verify=std" } */ + +void +foo (void) +{ + throw 0; +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59437.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59437.C new file mode 100644 index 000000000..0e77ccde4 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr59437.C @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "-fsanitize=null -fvtable-verify=std" } +// { dg-skip-if "" { *-*-* } { "-flto" } { "" } } + +template < typename T > struct A +{ + T foo (); +}; +template < typename T > struct C: virtual public A < T > +{ + C & operator<< (C & (C &)); +}; +template < typename T > +C < T > &endl (C < int > &c) +{ + c.foo (); + return c; +} +C < int > cout; +void +fn () +{ + cout << endl; +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr60569.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr60569.C new file mode 100644 index 000000000..df57c06be --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/pr60569.C @@ -0,0 +1,21 @@ +// PR sanitizer/60569 +// { dg-do link } +// { dg-require-effective-target lto } +// { dg-options "-fsanitize=undefined -flto" } + +struct A +{ + void foo (); + struct + { + int i; + void bar () { i = 0; } + } s; +}; + +void A::foo () { s.bar (); } + +int +main () +{ +} diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-1.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-1.C new file mode 100644 index 000000000..43791b9e3 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-1.C @@ -0,0 +1,27 @@ +// { dg-do run } +// { dg-options "-fsanitize=return" } +// { dg-shouldfail "ubsan" } + +struct S { S (); ~S (); }; + +S::S () {} +S::~S () {} + +int +foo (int x) +{ + S a; + { + S b; + if (x) + return 1; + } +} + +int +main () +{ + foo (0); +} + +// { dg-output "execution reached the end of a value-returning function without returning a value" } diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-2.C b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-2.C new file mode 100644 index 000000000..546f17810 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/return-2.C @@ -0,0 +1,33 @@ +// { dg-do run } +// { dg-options "-fsanitize=return" } + +#include <stdio.h> + +struct S { S (); ~S (); }; + +S::S () {} +S::~S () {} + +int +foo (int x) +{ + S a; + { + S b; + if (x) + return 1; + } +} + +int +main () +{ + fputs ("UBSAN TEST START\n", stderr); + + foo (1); + foo (14); + + fputs ("UBSAN TEST END\n", stderr); +} + +/* { dg-output "UBSAN TEST START(\n|\r\n|\r)UBSAN TEST END" } */ diff --git a/gcc-4.9/gcc/testsuite/g++.dg/ubsan/ubsan.exp b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/ubsan.exp new file mode 100644 index 000000000..7d5e9ba72 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/g++.dg/ubsan/ubsan.exp @@ -0,0 +1,34 @@ +# Copyright (C) 2013-2014 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# Load support procs. +load_lib g++-dg.exp +load_lib ubsan-dg.exp + +# Initialize `dg'. +dg-init +if [ubsan_init] { + +# Main loop. +gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C $srcdir/c-c++-common/ubsan/*.c]] "" + +} + +# All done. +ubsan_finish +dg-finish |