diff options
Diffstat (limited to 'libmudflap/testsuite/libmudflap.c++')
17 files changed, 276 insertions, 0 deletions
diff --git a/libmudflap/testsuite/libmudflap.c++/c++frags.exp b/libmudflap/testsuite/libmudflap.c++/c++frags.exp new file mode 100644 index 000000000..eb900d799 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/c++frags.exp @@ -0,0 +1,22 @@ +global MUDFLAP_FLAGS +set MUDFLAP_FLAGS [list {} {-static} { -O} {-O2} {-O3}] + +libmudflap-init c++ +if {$cxx == "g++"} then { + unsupported "g++ not found" + return +} + +dg-init + +global srcdir + +foreach flags $MUDFLAP_FLAGS { + foreach srcfile [lsort [glob -nocomplain ${srcdir}/libmudflap.c++/*frag.cxx]] { + set bsrc [file tail $srcfile] + setenv MUDFLAP_OPTIONS "-viol-segv" + dg-runtest $srcfile $flags "-fmudflap -lmudflap" + } +} + +dg-finish diff --git a/libmudflap/testsuite/libmudflap.c++/ctors-1.cxx b/libmudflap/testsuite/libmudflap.c++/ctors-1.cxx new file mode 100644 index 000000000..7717c805c --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/ctors-1.cxx @@ -0,0 +1,20 @@ +#include <iostream> + + +extern char k []; + +class foo +{ + public: + foo (char *m) { m [40] = 20; } +}; + + +foo f1 (k); +foo f2 (k); +foo f3 (k); + +int main () +{ + return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/ctors-2.cxx b/libmudflap/testsuite/libmudflap.c++/ctors-2.cxx new file mode 100644 index 000000000..c1a501979 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/ctors-2.cxx @@ -0,0 +1 @@ +char k [500]; diff --git a/libmudflap/testsuite/libmudflap.c++/ctors.exp b/libmudflap/testsuite/libmudflap.c++/ctors.exp new file mode 100644 index 000000000..b3dda8fd6 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/ctors.exp @@ -0,0 +1,48 @@ +global MUDFLAP_FLAGS +set MUDFLAP_FLAGS [list {} {-static} {-O2} {-O3}] + +libmudflap-init c++ +if {$cxx == "g++"} then { + unsupported "g++ not found" + return +} + +dg-init + +global srcdir subdir + +foreach flags $MUDFLAP_FLAGS { + set l1 [libmudflap_target_compile "$srcdir/$subdir/ctors-1.cxx" "ctors-1.o" object {additional_flags=-fmudflap}] + set test "ctors-1 compilation ${flags}" + if [string match "*mudflap cannot track unknown size extern *k*" $l1] { pass $test } { fail $test } + + set l2 [libmudflap_target_compile "$srcdir/$subdir/ctors-2.cxx" "ctors-2.o" object {additional_flags=-fmudflap}] + set test "ctors-2 compilation ${flags}" + if [string match "" $l2] { pass $test } { fail $test } + + set l3 [libmudflap_target_compile "ctors-1.o ctors-2.o" "ctors-12.exe" executable {additional_flags=-fmudflap additional_flags=-lmudflap additional_flags=-lstdc++}] + set test "ctors-12 linkage ${flags}" + if [string match "" $l3] { pass $test } { fail $test } + + set l4 [libmudflap_target_compile "ctors-2.o ctors-1.o" "ctors-21.exe" executable {additional_flags=-fmudflap additional_flags=-lmudflap additional_flags=-lstdc++}] + set test "ctors-21 linkage ${flags}" + if [string match "" $l3] { pass $test } { fail $test } + + setenv MUDFLAP_OPTIONS "-viol-segv" + + remote_spawn host "./ctors-12.exe" + set l5 [remote_wait host 10] + set test "ctors-12 execution ${flags}" + if {[lindex $l5 0] == 0} { pass $test } { fail $test } + + remote_spawn host "./ctors-21.exe" + set l6 [remote_wait host 10] + set test "ctors-21 execution ${flags}" + if {[lindex $l6 0] == 0} { pass $test } { fail $test } + + foreach f [glob -nocomplain "ctors-*"] { + remote_file build delete $f + } +} + +dg-finish diff --git a/libmudflap/testsuite/libmudflap.c++/error1-frag.cxx b/libmudflap/testsuite/libmudflap.c++/error1-frag.cxx new file mode 100644 index 000000000..8bfe85328 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/error1-frag.cxx @@ -0,0 +1,5 @@ +// PR 26789 +// { dg-do compile } + +struct A; +A a; // { dg-error "incomplete" } diff --git a/libmudflap/testsuite/libmudflap.c++/error2-frag.cxx b/libmudflap/testsuite/libmudflap.c++/error2-frag.cxx new file mode 100644 index 000000000..0e89e117f --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/error2-frag.cxx @@ -0,0 +1,10 @@ +// PR 26790 +// { dg-do compile } + +struct A; + +A foo() // { dg-error "incomplete" } +{ + A a; // { dg-error "incomplete" } + return a; +} diff --git a/libmudflap/testsuite/libmudflap.c++/fail24-frag.cxx b/libmudflap/testsuite/libmudflap.c++/fail24-frag.cxx new file mode 100644 index 000000000..e3467ddaf --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/fail24-frag.cxx @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char zoo [10]; + +int main () +{ +int i = strlen ("twelve") + strlen ("zero") + strlen ("seventeen"); +zoo[i] = 'a'; +return 0; +} +/* { dg-output "mudflap violation 1.*" } */ +/* { dg-output "Nearby object.*" } */ +/* { dg-output "mudflap object.*zoo.*static.*" } */ +/* { dg-do run { xfail *-*-* } } */ diff --git a/libmudflap/testsuite/libmudflap.c++/pass27-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass27-frag.cxx new file mode 100644 index 000000000..aca2ea3a3 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass27-frag.cxx @@ -0,0 +1,12 @@ +class foo { + char z [10]; +public: + char *get_z () { return & this->z[0]; } +}; + +int main () +{ +foo x; +x.get_z()[9] = 'a'; +return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/pass28-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass28-frag.cxx new file mode 100644 index 000000000..75e14ba14 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass28-frag.cxx @@ -0,0 +1,20 @@ +class foo { + char z [10]; +public: + virtual char *get_z () { return & this->z[0]; } +}; + +class bar: public foo { + char q [20]; +public: + char *get_z () { return & this->q[0]; } +}; + +int main () { +foo *x = new bar (); + +x->get_z()[9] = 'a'; + +delete x; +return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/pass31-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass31-frag.cxx new file mode 100644 index 000000000..6c4b9f9a7 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass31-frag.cxx @@ -0,0 +1,12 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char zoo [10]; + +int main () +{ +int i = strlen ("eight") + strlen ("one"); +zoo[i] = 'a'; +return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/pass41-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass41-frag.cxx new file mode 100644 index 000000000..06896c7f6 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass41-frag.cxx @@ -0,0 +1,13 @@ +#include <string> +#include <iostream> + +int +main (int argc, char *argv[]) +{ + std::string myStr = "Hello, World!"; + std::cout << myStr << std::endl; + return 0; +} + +/* Ignore a warning that is irrelevant to the purpose of this test. */ +/* { dg-prune-output ".*mudflap cannot track unknown size extern.*" } */ diff --git a/libmudflap/testsuite/libmudflap.c++/pass55-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass55-frag.cxx new file mode 100644 index 000000000..e83c12461 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass55-frag.cxx @@ -0,0 +1,7 @@ +#include <vector> + +int main() { + std::vector<int> v; + v.push_back(1); + return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/pass57-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass57-frag.cxx new file mode 100644 index 000000000..8be1a2d11 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass57-frag.cxx @@ -0,0 +1,28 @@ +#include <vector> +#include <string> + +class fitscolumn + { + private: + std::string name_, unit_; + int i, t; + public: + fitscolumn (const std::string &nm, const std::string &un,int i1,int t1) + : name_(nm), unit_(un), i(i1), t(t1){} + }; + +void init_bintab(std::vector<fitscolumn> & columns_) +{ + char ttype[81], tunit[81], tform[81]; + long repc; + int typecode; + columns_.push_back (fitscolumn (ttype,tunit,1,typecode)); +} + +int main () +{ + return 0; +} + +/* Ignore a warning that is irrelevant to the purpose of this test. */ +/* { dg-prune-output ".*mudflap cannot track unknown size extern.*" } */ diff --git a/libmudflap/testsuite/libmudflap.c++/pass58-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass58-frag.cxx new file mode 100644 index 000000000..96da05fca --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass58-frag.cxx @@ -0,0 +1,12 @@ +// PR 19319 +struct k { + int data; + k(int j): data(j) {} +}; +k make_k () { return k(1); } + +int main () +{ + k foo = make_k (); + return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/pass60-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass60-frag.cxx new file mode 100644 index 000000000..35989d122 --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass60-frag.cxx @@ -0,0 +1,13 @@ +// PR 26442 + +struct A +{ + A(); +}; + +int main() +{ + if (0) + A(); + return 0; +} diff --git a/libmudflap/testsuite/libmudflap.c++/pass61-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass61-frag.cxx new file mode 100644 index 000000000..03046112c --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass61-frag.cxx @@ -0,0 +1,20 @@ +// PR c++/34619 +// { dg-do compile } + +template <typename> struct A +{ + typedef int X; + static const int N = 1; +}; + +template <typename T> struct B +{ + typedef typename A <int [A <T>::N]>::X Y; + template <typename U> B (Y, U) {} +}; + +int main () +{ +} + +B <int>b (0, 0); diff --git a/libmudflap/testsuite/libmudflap.c++/pass66-frag.cxx b/libmudflap/testsuite/libmudflap.c++/pass66-frag.cxx new file mode 100644 index 000000000..989c7ca6f --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c++/pass66-frag.cxx @@ -0,0 +1,17 @@ +// PR c++/37568 +// { dg-do compile } +// { dg-options "-fmudflap -O" } + +struct A +{ + int i; +}; + +A +foo () +{ + A a = { 1 }; + return a; +} + +A a = foo (); |