diff options
Diffstat (limited to 'gcc-4.4.3/gcc/testsuite/g++.dg')
66 files changed, 2184 insertions, 27 deletions
diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/abi/forced.C b/gcc-4.4.3/gcc/testsuite/g++.dg/abi/forced.C index 7a9c35964..f846732c3 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/abi/forced.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/abi/forced.C @@ -1,6 +1,8 @@ // This test only applies to glibc (NPTL) targets. // { dg-do run { target *-*-linux* } } // { dg-options "-pthread" } +// Does not work on a QEMU set-up because of the status wrapper. +//{ dg-require-effective-target unwrapped } #include <pthread.h> #include <cxxabi.h> diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/lineno-simple1.C b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/lineno-simple1.C new file mode 100644 index 000000000..e0ef7f71c --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/lineno-simple1.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-g -O0 -dA" } + +struct C { // { dg-function-on-line {_ZN1CC[12]Ev} } + virtual void + foo() {} // { dg-function-on-line _ZN1C3fooEv } +}; +static C dummy; + +int +main (void) +{ // { dg-function-on-line main } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr41063.C b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr41063.C new file mode 100644 index 000000000..f23efef13 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr41063.C @@ -0,0 +1,20 @@ +// Contributed by Cary Coutant <ccoutant@google.com> +// Origin: PR debug/41063 +// { dg-do compile } + +struct A { + virtual void run(); +}; + +void test() { + struct B : public A { + void run() { + struct C : public A { + C() { } + B *b_; + }; + C c; + } + }; + B b; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr44641.C b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr44641.C new file mode 100644 index 000000000..ecfb71323 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr44641.C @@ -0,0 +1,43 @@ +// Origin: PR 44641 +// { dg-do compile } +// { dg-options "-g -O0 -dA" } + +template <class A> struct MisplacedDbg; +template<class T> struct MisplacedDbg<T*>; +struct Full; +template<> struct MisplacedDbg<Full>; + +struct Arg; +typedef MisplacedDbg<Arg> Typedef1; +typedef MisplacedDbg<Arg*> Typedef2; +typedef MisplacedDbg<Full> Typedef3; + +template<typename T> struct Base { + virtual ~Base() { + } +}; + +template <> +struct MisplacedDbg<Full> + : public Base<int> +{ // { dg-function-on-line {_ZN12MisplacedDbgI4FullEC[12]Ev} } + // { dg-function-on-line {_ZN12MisplacedDbgI4FullED0Ev} { target *-*-* } 23 } +}; + +template <class T> +struct MisplacedDbg<T*> + : public Base<int> +{ // { dg-function-on-line {_ZN12MisplacedDbgIP3ArgEC[12]Ev} } + // { dg-function-on-line {_ZN12MisplacedDbgIP3ArgED0Ev} { target *-*-* } 30 } +}; + +template <class A> +struct MisplacedDbg + : public Base<int> +{ // { dg-function-on-line {_ZN12MisplacedDbgI3ArgEC[12]Ev} } + // { dg-function-on-line {_ZN12MisplacedDbgI3ArgED0Ev} { target *-*-* } 37 } +}; + +static MisplacedDbg<Arg> static_var1; +static MisplacedDbg<Arg*> static_var2; +static MisplacedDbg<Full> static_var3; diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr46527.C b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr46527.C new file mode 100644 index 000000000..dfc983b17 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/debug/dwarf2/pr46527.C @@ -0,0 +1,18 @@ +// Origin: PR 46527 +// { dg-do compile } +// { dg-options "-g -O0 -dA" } + +template <typename T> struct Struct { + double defined_later(); +}; +struct WrapperStruct { + Struct<double> ClassInstantiated; +}; +template <typename T> double +Struct<T>::defined_later() // { dg-function-on-line {_ZN6StructIdE13defined_laterEv} } +{ + return 1; +} +void InstantiateMethod() { + Struct<double>().defined_later(); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/init/pr42556.C b/gcc-4.4.3/gcc/testsuite/g++.dg/init/pr42556.C new file mode 100644 index 000000000..27370af79 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/init/pr42556.C @@ -0,0 +1,10 @@ +// { dg-do compile } +// { dg-options "-fdump-tree-gimple" } + +void foo (int a, int b, int c, int d) +{ + int v[4] = {a, b, c, d}; +} + +// { dg-final { scan-tree-dump-not "v = {}" "gimple" } } +// { dg-final { cleanup-tree-dump "gimple" } } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/ipa/ipa-cp-1.C b/gcc-4.4.3/gcc/testsuite/g++.dg/ipa/ipa-cp-1.C new file mode 100644 index 000000000..954097655 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/ipa/ipa-cp-1.C @@ -0,0 +1,309 @@ +/* Test for segfault during updating of jump function in + interprocedural constant propagation (b/3124518). */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +namespace std __attribute__ ((__visibility__ ("default"))) { + template<class _CharT> + struct char_traits; +} +typedef long int ptrdiff_t; +typedef long unsigned int size_t; +namespace std __attribute__ ((__visibility__ ("default"))) { + void __throw_bad_cast(void) __attribute__((__noreturn__)); + typedef ptrdiff_t streamsize; + template<> struct char_traits<char> + { + typedef char char_type; + static size_t length(const char_type* __s) { + } + }; +} +extern "C++" { + namespace std { + class exception { + }; + } + void operator delete(void*) throw(); +} +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { + template<typename _Tp> + class new_allocator { + public: + typedef size_t size_type; + typedef _Tp* pointer; + template<typename _Tp1> + struct rebind { + typedef new_allocator<_Tp1> other; + }; + void deallocate(pointer __p, size_type) { + ::operator delete(__p); + } + }; +} +namespace std __attribute__ ((__visibility__ ("default"))) { + template<typename _Tp> + class allocator + : public __gnu_cxx::new_allocator<_Tp> { + }; + template<typename _CharT, typename _Traits = char_traits<_CharT> > + class basic_ostream; + template<typename _CharT, typename _Traits = char_traits<_CharT> > + class basic_fstream; + typedef basic_ostream<char> ostream; + typedef basic_fstream<char> fstream; +} +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { + template<typename _CharT, typename _Traits, typename _Alloc> + class __sso_string_base; + template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Alloc = std::allocator<_CharT>, template <typename, typename, typename> class _Base = __sso_string_base> + class __versa_string; + template<typename _CharT, typename _Traits, typename _Alloc> + struct __vstring_utility { + typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; + template<typename _Alloc1> + struct _Alloc_hider + : public _Alloc1 { + _Alloc_hider(_CharT* __ptr) + : _Alloc1(), _M_p(__ptr) { + } + _CharT* _M_p; + }; + }; + template<typename _CharT, typename _Traits, typename _Alloc> + class __sso_string_base + : protected __vstring_utility<_CharT, _Traits, _Alloc> { + public: + typedef _Traits traits_type; + typedef __vstring_utility<_CharT, _Traits, _Alloc> _Util_Base; + typedef typename _Util_Base::_CharT_alloc_type _CharT_alloc_type; + typedef typename _CharT_alloc_type::size_type size_type; + private: + typename _Util_Base::template _Alloc_hider<_CharT_alloc_type> + _M_dataplus; + enum { + _S_local_capacity = 15 }; + union { + _CharT _M_local_data[_S_local_capacity + 1]; + size_type _M_allocated_capacity; + }; + bool _M_is_local() const { + } + void _M_dispose() { + if (!_M_is_local()) _M_destroy(_M_allocated_capacity); + } + void _M_destroy(size_type __size) throw() { + _M_get_allocator().deallocate(_M_data(), __size + 1); + } + public: + size_type _M_max_size() const { + } + _CharT* _M_data() const { + return _M_dataplus._M_p; + } + __sso_string_base() + : _M_dataplus(_M_local_data) { + } + __sso_string_base(const __sso_string_base& __rcs); + template<typename _InputIterator> + __sso_string_base(_InputIterator __beg, _InputIterator __end, const _Alloc& __a); + ~__sso_string_base() { + _M_dispose(); + } + _CharT_alloc_type& _M_get_allocator() { + } + }; + template<typename _CharT, typename _Traits, typename _Alloc, template <typename, typename, typename> class _Base> + class __versa_string + : private _Base<_CharT, _Traits, _Alloc> { + typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; + typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; + public: + typedef _Traits traits_type; + typedef typename _CharT_alloc_type::size_type size_type; + static const size_type npos = static_cast<size_type>(-1); + public: + __versa_string() + : __vstring_base() { + } + __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) + : __vstring_base(__s, __s ? __s + traits_type::length(__s) + : __s + npos, __a) { + } + }; +} +namespace std __attribute__ ((__visibility__ ("default"))) { + template<typename _CharT, typename _Traits, typename _Alloc, template <typename, typename, typename> class _Base> + inline basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) { + } +} +template<typename _CharT, typename _Traits = std::char_traits<_CharT>, typename _Alloc = std::allocator<_CharT> > +class basic_string + : public __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc> { +public: + typedef __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc> __base; + inline basic_string() + : __base() { + } + basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) + : __base(__s, __a) { + } +}; +typedef basic_string<char> string; +namespace std __attribute__ ((__visibility__ ("default"))) { + class locale { + class facet; + }; + class locale::facet { + }; + class ios_base { + }; + struct ctype_base { + }; + template<typename _CharT> + class __ctype_abstract_base + : public locale::facet, public ctype_base { + }; + template<typename _CharT> + class ctype + : public __ctype_abstract_base<_CharT> { + public: + typedef char char_type; + mutable char _M_widen_ok; + mutable char _M_widen[1 + static_cast<unsigned char>(-1)]; + char_type widen(char __c) const { + if (_M_widen_ok) return _M_widen[static_cast<unsigned char>(__c)]; + this->_M_widen_init(); + return this->do_widen(__c); + } + virtual char_type do_widen(char __c) const { + } + void _M_widen_init() const; + }; + template<typename _Facet> + inline const _Facet& __check_facet(const _Facet* __f) { + if (!__f) __throw_bad_cast(); + } + template<typename _CharT, typename _Traits> + class basic_ios + : public ios_base { + public: + typedef _CharT char_type; + typedef ctype<_CharT> __ctype_type; + const __ctype_type* _M_ctype; + bool eof() const { + } + char_type widen(char __c) const { + return __check_facet(_M_ctype).widen(__c); + } + }; + template<typename _CharT, typename _Traits> class basic_ostream + : virtual public basic_ios<_CharT, _Traits> + { + public: + typedef _CharT char_type; + typedef basic_ostream<_CharT, _Traits> __ostream_type; + __ostream_type& operator<<(__ostream_type& (*__pf)(__ostream_type&)) { + } + __ostream_type& put(char_type __c); + }; + template<typename _CharT, typename _Traits> + inline basic_ostream<_CharT, _Traits>& endl(basic_ostream<_CharT, _Traits>& __os) { + return flush(__os.put(__os.widen('\n'))); + } + template<typename _CharT, typename _Traits> + inline basic_ostream<_CharT, _Traits>& flush(basic_ostream<_CharT, _Traits>& __os) { + } +} +using std::endl; +namespace std __attribute__ ((__visibility__ ("default"))) { + template<typename _CharT, typename _Traits> class basic_istream + : virtual public basic_ios<_CharT, _Traits> + { + public: + typedef _CharT char_type; + typedef basic_istream<_CharT, _Traits> __istream_type; + virtual ~basic_istream() { + } + __istream_type& getline(char_type* __s, streamsize __n, char_type __delim); + __istream_type& getline(char_type* __s, streamsize __n) { + return this->getline(__s, __n, this->widen('\n')); + } + }; + template<typename _CharT, typename _Traits> + class basic_iostream + : public basic_istream<_CharT, _Traits>, public basic_ostream<_CharT, _Traits> { + }; +} +using std::ostream; +namespace std __attribute__ ((__visibility__ ("default"))) { + template<typename _CharT, typename _Traits> + class basic_fstream + : public basic_iostream<_CharT, _Traits> { + }; +} +namespace FooNamespace { + class ExceptionLocation { + public: + ExceptionLocation(const string& filename = string(), const string& funcName = string()) throw() + : functionName(funcName) { + } + private: + string fileName; + string functionName; + }; + class Exception { + public: + Exception() throw(); + Exception(const string& errorText, const unsigned long& errorId = 0) throw(); + Exception& addLocation(const ExceptionLocation& location) throw(); + }; + class FooError + : public FooNamespace::Exception { + public: + FooError() throw() + : FooNamespace::Exception() { + } + FooError(string a, unsigned long b = 0) throw() + : FooNamespace::Exception(a, b) { + }; + }; + class EndOfFile + : public FooNamespace::FooError { + public: + EndOfFile() throw() + : FooNamespace::FooError() { + } + EndOfFile(string a, unsigned long b = 0) throw() + : FooNamespace::FooError(a, b) { + }; + }; + class FooTextStream : public std::fstream { + public: + inline void Fubar(const bool expectEOF = false ) throw(EndOfFile, FooError, FooNamespace::Exception) { + try { + const int MAX_LINE_LENGTH = 256; + char templine[MAX_LINE_LENGTH + 1]; + getline(templine, MAX_LINE_LENGTH); + EndOfFile err(""); + } + catch(std::exception &e) { + if (expectEOF) { + EndOfFile err(""); + err.addLocation(FooNamespace::ExceptionLocation("", "")); + throw err; + } + } + }; + }; + class BarHeader { + virtual void dump(std::ostream& s) const { + s << endl; + } + virtual void DoIt(std::fstream& s); + }; + void BarHeader::DoIt(std::fstream& ffs) { + FooTextStream* buz = 0; + buz->Fubar(); + } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig5.C b/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig5.C index 139e3b866..6ecc25daa 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig5.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig5.C @@ -8,39 +8,39 @@ namespace N { struct A {}; - void One (...); // { dg-error "conflict with" "" } - void (*Two) (...); // { dg-error "not a function" "" } - namespace Three {} // { dg-error "lookup finds|not a function" "" } + void One (...); + void (*Two) (...); + namespace Three {} } namespace M { struct B {}; - struct One {}; // { dg-error "lookup finds|not a function" "" } - void (*Two) (...); // { dg-error "conflict with" "" } - void Three (...); // { dg-error "conflict with" "" } + struct One {}; + void (*Two) (...); + void Three (...); } namespace O { struct C {}; - void Two (...); // { dg-error "conflict with" "" } + void Two (...); } void g (N::A *a, M::B *b, O::C *c) { One (a); // ok - One (b); // { dg-error "in call to" "" } - One (a, b); // { dg-error "in call to" "" } + One (a, b); // ok + One (b); // { dg-error "not declared" } - Two (a); // ok - Two (a, a); // ok - Two (b); // ok Two (c); // ok - Two (a, b); // { dg-error "in call to" "" } - Two (a, c); // { dg-error "in call to" "" } + Two (a, c); // ok + Two (a); // { dg-error "not declared" } + Two (a, a); // error masked by earlier error + Two (b); // error masked by earlier error + Two (a, b); // error masked by earlier error - Three (a); // { dg-error "in call to" "" } Three (b); // ok - Three (a, b); // { dg-error "in call to" "" } + Three (a, b); // ok + Three (a); // { dg-error "not declared" } } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig6.C b/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig6.C new file mode 100644 index 000000000..9fdf771e0 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/lookup/koenig6.C @@ -0,0 +1,18 @@ +// PR c++/17365 +// ADL should not find B::N. + +namespace A +{ + namespace B + { + template <typename T> struct N {int n_;}; + } + template <typename T> int N( T p ) { return p->n_; } + template <typename T> void f( T p ) { N(p); } // #1 +} +int main() +{ + A::B::N<int> n; + A::f(&n); + return 0; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn10.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn10.C new file mode 100644 index 000000000..dcd5d2776 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn10.C @@ -0,0 +1,54 @@ +/* The purpose of this test is to check if the attributes of the clone + correctly shadow the parent function. In this case, function "dispatch" + is cloned but is a static function. The other file, "mversn10a.C" also + has a dispatch function that is cloned. So, if the attributes of the + clone are not correct the linker will complain. */ + +/* { dg-do run } */ +/* { dg-additional-sources "mversn10a.C" } */ +/* { dg-options "-O2 -fclone-hot-version-paths -fdump-tree-final_cleanup" } */ + +static int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} + +static int foo () +{ + return 0; +} + +static int bar () +{ + return 1; +} + +static int __attribute__ ((noinline)) +dispatch () +{ + __builtin_dispatch (featureTest, (void *)foo, (void *)bar); + return 0; +} + +int +fn1 () +{ + for (int i = 0; i < 1000; i++) + dispatch (); + return 0; +} + +extern int fn2 (); + +int __attribute__ ((hot)) +main () +{ + fn1 (); + fn2 (); + return 0; +} + +/* { dg-final { scan-tree-dump "dispatchv_clone_0" "final_cleanup" } } */ +/* { dg-final { scan-tree-dump "dispatchv_clone_1" "final_cleanup" } } */ +/* { dg-final { cleanup-tree-dump "final_cleanup" } } */ diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn10a.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn10a.C new file mode 100644 index 000000000..f762cf649 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn10a.C @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fclone-hot-version-paths -fdump-tree-final_cleanup" } */ + +static int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} + +static int foo () +{ + return 0; +} + +static int bar () +{ + return 1; +} + +static int __attribute__ ((noinline)) +dispatch () +{ + __builtin_dispatch (featureTest, (void *)foo, (void *)bar); + return 0; +} + +int +fn2 () +{ + for (int i = 0; i < 1000; i++) + dispatch (); + return 0; +} + +/* { dg-final { scan-tree-dump "dispatchv_clone_0" "final_cleanup" } } */ +/* { dg-final { scan-tree-dump "dispatchv_clone_1" "final_cleanup" } } */ +/* { dg-final { cleanup-tree-dump "final_cleanup" } } */ diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn12.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn12.C new file mode 100644 index 000000000..b21b9a36f --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn12.C @@ -0,0 +1,43 @@ +/* Check if everything is fine if the versioned functions are static + member functions. */ + +/* { dg-do run } */ +/* { dg-options "-O2 -fclone-hot-version-paths" } */ + +int __attribute__ ((version_selector)) +featureTest() +{ + return 1;; +} + +class TestClass +{ + public: + static int foo () + { + return 0; + } + + static int bar () + { + return 1; + } + + int dispatch () + { + int a = __builtin_dispatch (featureTest, + (void*)(&TestClass::foo), + (void*)(&TestClass::bar)); + int b = __builtin_dispatch (featureTest, + (void*)(&TestClass::bar), + (void*)(&TestClass::foo)); + return a * b; + } +}; + +int +main () +{ + TestClass c1; + return c1.dispatch (); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn14.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn14.C new file mode 100644 index 000000000..dcf6f19fa --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn14.C @@ -0,0 +1,26 @@ +/* Check if everything is fine when the feature test body is in a different + module that does not have a __builtin-dispatch". Requires mversn14a.C. */ + +/* { dg-do run } */ +/* { dg-additional-sources "mversn14a.C" } */ +/* { dg-options "-O2 -fclone-hot-version-paths" } */ + +int __attribute__ ((version_selector)) +featureTest (); + +int +foo () +{ + return 0; +} + +int +bar () +{ + return 1; +} + +int main () +{ + return __builtin_dispatch (featureTest, (void *)foo, (void *)bar); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn14a.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn14a.C new file mode 100644 index 000000000..513c5a402 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn14a.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn16.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn16.C new file mode 100644 index 000000000..90e2fc28f --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn16.C @@ -0,0 +1,39 @@ +/* dispatch is cloned. Make sure the double is returned to main correctly. */ + +/* { dg-do run } */ +/* { dg-options "-O2 -fclone-hot-version-paths -fdump-tree-final_cleanup" } */ + +#include "assert.h" + +int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} + +static int foo () +{ + return 0; +} + +static int bar () +{ + return 1; +} + +double +dispatch () +{ + __builtin_dispatch (featureTest, (void *)foo, (void *)bar); + return 2.536; +} + +int main () +{ + double d = dispatch (); + assert (d == 2.536); + return 0; +} + +/* { dg-final { scan-tree-dump "dispatchv_clone" "final_cleanup" } } */ +/* { dg-final { cleanup-tree-dump "final_cleanup" } } */ diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn8.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn8.C new file mode 100644 index 000000000..4e4168a87 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn8.C @@ -0,0 +1,44 @@ +/* Call the caller of __builtin_dispatch indirectly. Specify the + feature test function as a function pointer. Make sure cloning + still happens. */ + +/* { dg-do run } */ +/* { dg-options "-O2 -fclone-hot-version-paths -fdump-tree-final_cleanup" } */ + +int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} + +int __attribute__ ((cold)) +foo () +{ + return 0; +} + +int __attribute__ ((cold)) +bar () +{ + return 1; +} + +int +dispatch () +{ + int (*funcp)() = featureTest; + int ret = __builtin_dispatch (funcp, (void *)foo, (void *)bar); + return ret; +} + +int main (int argc, char **argv) +{ + int (*ptr)() = dispatch; + return (*ptr)(); +} + +/* { dg-final { scan-tree-dump "dispatchv_clone_0" "final_cleanup" } } */ +/* { dg-final { scan-tree-dump "dispatchv_clone_1" "final_cleanup" } } */ +/* { dg-final { scan-tree-dump "main_clone_0" "final_cleanup" } } */ +/* { dg-final { scan-tree-dump "main_clone_1" "final_cleanup" } } */ +/* { dg-final { cleanup-tree-dump "final_cleanup" } } */ diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/mversn9.C b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn9.C new file mode 100644 index 000000000..d884d6f28 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/mversn9.C @@ -0,0 +1,31 @@ +/* Two __builtin_dispatch calls in different basic blocks. */ + +/* { dg-do run } */ +/* { dg-options "-O2 -fclone-hot-version-paths" } */ + +int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} + +int +foo () +{ + return 0; +} + +int +bar () +{ + return 1; +} + +int main (int argc, char **argv) +{ + if (argc) + return __builtin_dispatch (featureTest, (void *)foo, (void *)bar); + else + return (__builtin_dispatch (featureTest, (void *)bar, (void *)foo) - 1); +} + diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-5.C b/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-5.C new file mode 100644 index 000000000..25a70b7df --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-5.C @@ -0,0 +1,16 @@ +// Origin: PR c++/42758 +// { dg-do compile } + +template<class T> struct less {}; + +template<class T, typename U = less<T> > struct set {}; + +struct int_less_than {}; + +void assert_fail (const char*); + +int f(const set<int, int_less_than>&) +{ + assert_fail (__PRETTY_FUNCTION__); + +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-7.C b/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-7.C new file mode 100644 index 000000000..d5bc892c0 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-7.C @@ -0,0 +1,19 @@ +// Origin: PR c++/42336 +// { dg-options "-std=c++0x -O2 -g" } +// { dg-do compile } + +struct X { + void func() {} +}; + +template<typename T, void (X::*P)() = &T::func> +void b(T) {} + +int main() { + b(X()); /* line 9 */ + X().func(); + + return 0; +} + + diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-8.C b/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-8.C new file mode 100644 index 000000000..c260431d5 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/other/crash-8.C @@ -0,0 +1,109 @@ +// Origin: PR c++/42797 +// { dg-options "-g -O2 -std=c++0x" } + +template<typename _Tp, _Tp __v> struct integral_constant { + static const _Tp value = __v; +}; + +template<typename _Tp> _Tp declval(); + +template<typename _Tp, typename... _Args> +class __is_constructible_helper { +}; + +template<typename _Tp, typename _Arg> +class __is_constructible_helper<_Tp, _Arg> { + + template<typename _Tp1, typename _Arg1> + static decltype(static_cast<_Tp1>(declval<_Arg1>()), char()) __test(int); +public: + static const bool __value = sizeof(__test<_Tp, _Arg>(0)) == 1; +}; + +template<typename _Tp, typename... _Args> +struct is_constructible : public integral_constant<bool,__is_constructible_helper<_Tp, _Args...>::__value> { }; + +template<bool, typename _Tp = void> +struct enable_if { }; + +template<typename _Tp> +struct enable_if<true, _Tp> { + typedef _Tp type; +}; + +template<class _T1, class _T2> struct pair { + _T1 first; + _T2 second; + + template<class _U2, class = typename enable_if<is_constructible<_T2, _U2&&>::value>::type> + pair(const _T1& __x, _U2&& __y) : first(__x), + second(__y) { } +}; + +namespace __gnu_cxx { +template<typename _Tp> +class new_allocator { +public: + new_allocator() throw() { } + new_allocator(const new_allocator&) throw() { } +}; +} + +template<typename _Tp> +class allocator: public __gnu_cxx::new_allocator<_Tp> { +public: + + template<typename _Tp1> + struct rebind { + typedef allocator<_Tp1> other; + }; +}; + + +template<typename _Tp, typename _Alloc> struct _Vector_base { + typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; + + struct _Vector_impl : public _Tp_alloc_type { + _Vector_impl() + { } + }; +public: + + _Vector_impl _M_impl; +}; + +template<typename _Tp, typename _Alloc = allocator<_Tp> > +class vector : protected _Vector_base<_Tp, _Alloc> { + typedef _Alloc allocator_type; +public: + vector() { } + explicit vector(int, const allocator_type& __a = allocator_type()) + { + } +}; + + +template <typename _Key, typename _Tp> +class map { + typedef _Key key_type; + typedef _Tp mapped_type; + typedef pair<const _Key, _Tp> value_type; +public: + + void insert(const value_type& __x) + { + } + + mapped_type& operator[](const key_type& __k) { + insert(value_type(__k, mapped_type())); + } + +}; + +struct Foo { + Foo() {} template<typename Tp> Foo(Tp *p) {} }; +void foo() { + map <int, vector<Foo>> the_map; + the_map[1] = vector<Foo>(); +} + diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/template/crash56.C b/gcc-4.4.3/gcc/testsuite/g++.dg/template/crash56.C index 1efa3500d..03bddf42a 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/template/crash56.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/template/crash56.C @@ -7,10 +7,10 @@ namespace N { - struct A { A (A*); }; // { dg-error "lookup finds" "" } + struct A { A (A*); }; } template<typename T> void g (N::A *p) { - (void) A (p); // { dg-error "in call" "" } + (void) A (p); // { dg-message "" "" } } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/template/defarg13.C b/gcc-4.4.3/gcc/testsuite/g++.dg/template/defarg13.C new file mode 100644 index 000000000..ba2980bfa --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/template/defarg13.C @@ -0,0 +1,19 @@ +// PR c++/14912 +// Bug: We were instantiating A<B> in order to compare it to the matching +// argument for C<B,B>, which fails. + +template <class T> +struct A +{ + typedef typename T::F F; +}; + +struct B { }; + +template <class T, class U = typename A<T>::F > +struct C +{ + typename T::F f; // { dg-error "no type" } +}; + +C<B, B> c; // { dg-message "instantiated" } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/template/error39.C b/gcc-4.4.3/gcc/testsuite/g++.dg/template/error39.C new file mode 100644 index 000000000..49faa3654 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/template/error39.C @@ -0,0 +1,11 @@ +// PR c++/14912 + +template <class T, int N=0, int X=1> +struct A +{ +}; + +void foo(void) +{ + A<void> a = 0; // { dg-error "A<void>" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_common.h b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_common.h index 192c84e84..a21af97fe 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_common.h +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_common.h @@ -27,6 +27,11 @@ #define SHARED_LOCKS_REQUIRED(...) \ __attribute__ ((shared_locks_required(__VA_ARGS__))) #define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis)) +#define IGNORE_READS_BEGIN __attribute__ ((ignore_reads_begin)) +#define IGNORE_READS_END __attribute__ ((ignore_reads_end)) +#define IGNORE_WRITES_BEGIN __attribute__ ((ignore_writes_begin)) +#define IGNORE_WRITES_END __attribute__ ((ignore_writes_end)) +#define UNPROTECTED_READ __attribute__ ((unprotected_read)) #else @@ -48,6 +53,11 @@ #define EXCLUSIVE_LOCKS_REQUIRED(...) #define SHARED_LOCKS_REQUIRED(...) #define NO_THREAD_SAFETY_ANALYSIS +#define IGNORE_READS_BEGIN +#define IGNORE_READS_END +#define IGNORE_WRITES_BEGIN +#define IGNORE_WRITES_END +#define UNPROTECTED_READ #endif // defined(__GNUC__) && defined(__SUPPORT_TS_ANNOTATION__) @@ -81,4 +91,41 @@ class SCOPED_LOCKABLE ReleasableMutexLock { void Release() UNLOCK_FUNCTION(); }; +void AnnotateIgnoreReadsBegin(const char *file, int line) IGNORE_READS_BEGIN; +void AnnotateIgnoreReadsEnd(const char *file, int line) IGNORE_READS_END; +void AnnotateIgnoreWritesBegin(const char *file, int line) IGNORE_WRITES_BEGIN; +void AnnotateIgnoreWritesEnd(const char *file, int line) IGNORE_WRITES_END; + +#define ANNOTATE_IGNORE_READS_BEGIN() \ + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) + +#define ANNOTATE_IGNORE_READS_END() \ + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) + +#define ANNOTATE_IGNORE_WRITES_BEGIN() \ + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) + +#define ANNOTATE_IGNORE_WRITES_END() \ + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) + +#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ + do { \ + ANNOTATE_IGNORE_READS_BEGIN(); \ + ANNOTATE_IGNORE_WRITES_BEGIN(); \ + }while(0) \ + +#define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ + do { \ + ANNOTATE_IGNORE_WRITES_END(); \ + ANNOTATE_IGNORE_READS_END(); \ + }while(0) \ + +template <class T> +inline T ANNOTATE_UNPROTECTED_READ(const T &x) UNPROTECTED_READ { + ANNOTATE_IGNORE_READS_BEGIN(); + T res = x; + ANNOTATE_IGNORE_READS_END(); + return res; +} + #endif // THREAD_ANNOT_COMMON_H diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-50.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-50.C new file mode 100644 index 000000000..e1e24c18e --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-50.C @@ -0,0 +1,22 @@ +// Test the support for allowing non-const but non-modifying methods to be +// protected by reader locks. +// This is a good test case. (i.e. There should be no warning emitted by the +// compiler.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include <map> +#include "thread_annot_common.h" + +typedef std::map<int, int> MyMapType; + +Mutex mu; +MyMapType MyMap GUARDED_BY(mu); + +int foo(int key) { + ReaderMutexLock l(&mu); + MyMapType::const_iterator iter = MyMap.find(key); + if (iter != MyMap.end()) { + return iter->second; + } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-51.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-51.C new file mode 100644 index 000000000..400c81e82 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-51.C @@ -0,0 +1,44 @@ +// Test the support for allowing non-const but non-modifying methods to be +// protected by reader locks. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +class Foo { + public: + int GetVal1(int a) const { + return a + val1; + } + + int GetVal1(int a) { + return a + val1; + } + + int GetVal1(int a, float b) { + return a + b + val1; + } + + int GetVal2(int a) { + return a + val2; + } + + int GetVal2(float a) { + return val2; + } + + + private: + int val1; + int val2; +}; + +Mutex mu; +Foo foo GUARDED_BY(mu); + +int main() { + mu.ReaderLock(); + int x = foo.GetVal1(3); // should not warn + int y = foo.GetVal2(3); // { dg-warning "Writing to variable" } + mu.Unlock(); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-52.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-52.C new file mode 100644 index 000000000..5535034b0 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-52.C @@ -0,0 +1,39 @@ +// Test the support for use of point_to_guarded{_by} on smart/scoped pointers. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +template<class T> +class scoped_ptr { + public: + typedef T element_type; + + explicit scoped_ptr(T * p = 0); + ~scoped_ptr(); + + void reset(T * p = 0); + + T & operator*() const; + T * operator->() const; + T * get() const; +}; + +class Foo { + public: + int x; +}; + +Mutex mu1, mu2; +scoped_ptr<int> a PT_GUARDED_BY(mu1); +scoped_ptr<Foo> b GUARDED_BY(mu2) PT_GUARDED_VAR; + +main() +{ + *a = 5; // { dg-warning "Access to memory location pointed to" } + a.reset(); + b->x = 3 + *a; // { dg-warning "Reading variable" } +} + +// { dg-warning "Access to memory location pointed to by variable 'b'" "" { target *-*-* } 35 } +// { dg-warning "Access to memory location pointed to by variable 'a'" "" { target *-*-* } 35 } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-53.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-53.C new file mode 100644 index 000000000..0c03d77d9 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-53.C @@ -0,0 +1,40 @@ +// Test the support for use of point_to_guarded{_by} on smart/scoped pointers. +// This is a good test case. (i.e. There should be no warning emitted by the +// compiler.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +template<class T> +class scoped_ptr { + public: + typedef T element_type; + + explicit scoped_ptr(T * p = 0); + ~scoped_ptr(); + + void reset(T * p = 0); + + T & operator*() const; + T * operator->() const; + T * get() const; +}; + +class Foo { + public: + int x; +}; + +Mutex mu1, mu2; +scoped_ptr<int> a PT_GUARDED_BY(mu1); +scoped_ptr<Foo> b GUARDED_BY(mu2) PT_GUARDED_VAR; + +main() +{ + MutexLock l1(&mu1); + MutexLock l2(&mu2); + *a = 5; + a.reset(); + b->x = 3 + *a; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-54.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-54.C new file mode 100644 index 000000000..e90652407 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-54.C @@ -0,0 +1,35 @@ +// Test the handling of the annotations with function parameters. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +class Base { + private: + Mutex mu1_; + + public: + Mutex *mutable_mu() LOCK_RETURNED(mu1_) { return &mu1_; } +}; + +class Foo { + public: + Mutex mu2_; + void Test1(Mutex* mu) const EXCLUSIVE_LOCKS_REQUIRED(mu, mu2_); + void Test2(Mutex* mu) const LOCKS_EXCLUDED(mu); +}; + +class Bar : public Base { + private: + Foo foo_; + + public: + void Test3(); +}; + +void Bar::Test3() { + mutable_mu()->Lock(); + foo_.Test1(mutable_mu()); // { dg-warning "Calling function" } + foo_.Test2(mutable_mu()); // { dg-warning "Cannot call function" } + mutable_mu()->Unlock(); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-55.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-55.C new file mode 100644 index 000000000..10a12d43e --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-55.C @@ -0,0 +1,38 @@ +// Test the handling of the annotations with function parameters. +// This is a good test case. (i.e. There should be no warning emitted by the +// compiler.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +class Base { + private: + Mutex mu1_; + + public: + Mutex *mutable_mu() LOCK_RETURNED(mu1_) { return &mu1_; } +}; + +class Foo { + public: + Mutex mu2_; + void Test1(Mutex* mu) const EXCLUSIVE_LOCKS_REQUIRED(mu, mu2_); + void Test2(Mutex* mu) const LOCKS_EXCLUDED(mu); +}; + +class Bar : public Base { + private: + Foo foo_; + + public: + void Test3(); +}; + +void Bar::Test3() { + MutexLock l(&foo_.mu2_); + mutable_mu()->Lock(); + foo_.Test1(mutable_mu()); + mutable_mu()->Unlock(); + foo_.Test2(mutable_mu()); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-56.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-56.C new file mode 100644 index 000000000..71221eb5f --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-56.C @@ -0,0 +1,36 @@ +// Test the handling of a method with lock annotations accessed through a +// smart/scoped pointer. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +template<class T> +class scoped_ptr { + public: + typedef T element_type; + + explicit scoped_ptr(T * p = 0); + ~scoped_ptr(); + + void reset(T * p = 0); + + T & operator*() const; + T * operator->() const; + T * get() const; +}; + +class LOCKABLE Foo { + public: + Mutex *mutex_; + int x; + int GetValue() EXCLUSIVE_LOCKS_REQUIRED(mutex); +}; + +scoped_ptr<Foo> b; + +main() +{ + int a; + a = b->GetValue(); // { dg-warning "Calling function 'GetValue' requires" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-57.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-57.C new file mode 100644 index 000000000..a12150436 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-57.C @@ -0,0 +1,22 @@ +// Test handling of arguments passed to reference parameters. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +struct Foo { + int a; +}; + +void func1(Foo &f); + +void func2(Foo *f); + +Mutex mu; + +Foo foo GUARDED_BY(mu); + +main() { + func1(foo); // { dg-warning "Reading variable 'foo' requires lock" } + func2(&foo); // should not warn +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-58.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-58.C new file mode 100644 index 000000000..858e63558 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-58.C @@ -0,0 +1,32 @@ +// Test handling of arguments passed to reference parameters. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include <string> +#include "thread_annot_common.h" + +class Base { + public: + Base() {} + protected: + Mutex* mutex() const LOCK_RETURNED(mutex_) { return &mutex_; } + private: + mutable Mutex mutex_; +}; + +class Subclass : public Base { + public: + Subclass() {} + + void ClearValue() { SetValueLocked(0); } + std::string GetValue() const; + + private: + void SetValueLocked(std::string value) { value_ = value; } + + std::string value_ GUARDED_BY(mutex_); +}; + +std::string Subclass::GetValue() const { + return value_; // { dg-warning "Reading variable 'value_' requires lock" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-59.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-59.C new file mode 100644 index 000000000..158c940e2 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-59.C @@ -0,0 +1,34 @@ +// Test handling of additional (finer-grained) escape hatche attributes. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +Mutex *mu1, *mu2; + +struct Foo { + int a GUARDED_BY(mu1); +}; + +int x GUARDED_BY(mu1) = 1; +int y GUARDED_BY(mu2); + +main() { + int z; + Foo w; + ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN(); + y = x + 1; + x = y; + ANNOTATE_IGNORE_READS_AND_WRITES_END(); + + z = ANNOTATE_UNPROTECTED_READ(w.a) + 1; + if (z > 1) { + ANNOTATE_IGNORE_READS_BEGIN(); + z = x + 2; + } + else { + ANNOTATE_IGNORE_READS_BEGIN(); + z = x + 1; + } + z = y; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-60.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-60.C new file mode 100644 index 000000000..099aa8290 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-60.C @@ -0,0 +1,37 @@ +// Test handling of additional (finer-grained) escape hatche attributes. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +Mutex *mu1, *mu2; + +struct Foo { + int a GUARDED_BY(mu1); +}; + +int x GUARDED_BY(mu1) = 1; +int y GUARDED_BY(mu2); + +main() { + int z; + Foo w; + ANNOTATE_IGNORE_READS_BEGIN(); + y = x + 1; // { dg-warning "Writing to variable 'y' requires lock" } + x = y; // { dg-warning "Writing to variable 'x' requires lock" } + ANNOTATE_IGNORE_READS_END(); + ANNOTATE_IGNORE_WRITES_BEGIN(); + y = x + 1; // { dg-warning "Reading variable 'x' requires lock" } + x = y; // { dg-warning "Reading variable 'y' requires lock" } + ANNOTATE_IGNORE_WRITES_END(); + + z = w.a + 1; // { dg-warning "Reading variable 'w.a' requires lock" } + if (z > 1) { + z = x + 2; // { dg-warning "Reading variable 'x' requires lock" } + } + else { + ANNOTATE_IGNORE_READS_BEGIN(); + z = x + 1; + } + z = y; // { dg-warning "Reading variable 'y' requires lock" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-61.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-61.C new file mode 100644 index 000000000..11f6308eb --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-61.C @@ -0,0 +1,15 @@ +// Test the fix for a bug introduced by the support of pass-by-reference +// paramters. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +struct Foo { Foo & operator<< (bool) {} }; +struct Bar { Foo & func () {} }; +struct Bas { void operator& (Foo &) {} }; +void mumble() +{ + Bas() & Bar().func() << "" << ""; + Bas() & Bar().func() << ""; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-62.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-62.C new file mode 100644 index 000000000..95f318699 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-62.C @@ -0,0 +1,18 @@ +// Test the support for allowing non-const but non-modifying overloaded +// operator to be protected by reader locks. +// This is a good test case. (i.e. There should be no warning emitted by the +// compiler.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include <vector> +#include "thread_annot_common.h" + +Mutex mu; + +std::vector<int> counts GUARDED_BY(mu); + +int foo(int key) { + ReaderMutexLock l(&mu); + return counts[key]; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-65.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-65.C new file mode 100644 index 000000000..d129fc94c --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-65.C @@ -0,0 +1,30 @@ +// Test the fix for a bug in the support of allowing reader locks for +// non-const, non-modifying overload functions. (We didn't handle the builtin +// properly.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +enum MyFlags { + Zero, + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine +}; + +inline MyFlags +operator|(MyFlags a, MyFlags b) +{ + return MyFlags(static_cast<int>(a) | static_cast<int>(b)); +} + +inline MyFlags& +operator|=(MyFlags& a, MyFlags b) +{ + return a = a | b; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-66.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-66.C new file mode 100644 index 000000000..c341973e7 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-66.C @@ -0,0 +1,35 @@ +// Test annotations on out-of-line definitions of member functions where the +// annotations refer to locks that are also data members in the class. +// This is a good test case. (i.e. There should be no warning emitted by the +// compiler.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +Mutex mu; + +class Foo { + public: + int method1(int i); + int data GUARDED_BY(mu1); + Mutex *mu1; + Mutex *mu2; +}; + +int Foo::method1(int i) SHARED_LOCKS_REQUIRED(mu1, mu, mu2) +{ + return data + i; +} + +main() +{ + Foo a; + + MutexLock l(a.mu2); + a.mu1->Lock(); + mu.Lock(); + a.method1(1); + mu.Unlock(); + a.mu1->Unlock(); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-67.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-67.C new file mode 100644 index 000000000..be228ec20 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-67.C @@ -0,0 +1,32 @@ +// Test annotations on out-of-line definitions of member functions where the +// annotations refer to locks that are also data members in the class. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +Mutex mu; + +class Foo { + public: + int method1(int i); + int data GUARDED_BY(mu1); + Mutex *mu1; + Mutex *mu2; +}; + +int Foo::method1(int i) SHARED_LOCKS_REQUIRED(mu1, mu, mu2, mu3) +{ + return data + i; +} + +main() +{ + Foo a; + + a.method1(1); // { dg-warning "Calling function 'method1' requires lock" } +} + +// { dg-warning "Calling function 'method1' requires lock 'mu'" { target *-*-* } 27 } +// { dg-warning "Calling function 'method1' requires lock 'a.mu2'" { target *-*-* } 27 } +// { dg-warning "Calling function 'method1' requires lock 'mu3'" { target *-*-* } 27 } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-68.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-68.C new file mode 100644 index 000000000..95e8d6908 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-68.C @@ -0,0 +1,34 @@ +// Test a fix to a bug in the delayed name binding with nested template +// instantiation. We use a stack to make sure a name is not resolved to an +// inner context. +// This is a good test case. (i.e. There should be no warning emitted by the +// compiler.) +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +template <typename T> +class Bar { + Mutex mu_; +}; + +template <typename T> +class Foo { + public: + void func(T x) { + MutexLock l(&mu_); + count_ = x; + } + + private: + T count_ GUARDED_BY(mu_); + Bar<T> bar_; + Mutex mu_; +}; + +int main() +{ + Foo<int> *foo; + foo->func(5); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-69.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-69.C new file mode 100644 index 000000000..478e8b273 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-69.C @@ -0,0 +1,31 @@ +// Test a fix to a bug in the delayed name binding with nested template +// instantiation. We use a stack to make sure a name is not resolved to an +// inner context. +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +template <typename T> +class Bar { + Mutex mu_; +}; + +template <typename T> +class Foo { + public: + void func(T x) { + count_ = x; // { dg-warning "Writing to variable 'count_' requires lock" } + } + + private: + T count_ GUARDED_BY(mu_); + Bar<T> bar_; + Mutex mu_; +}; + +int main() +{ + Foo<int> *foo; + foo->func(5); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-70.C b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-70.C new file mode 100644 index 000000000..782d13af4 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-70.C @@ -0,0 +1,38 @@ +// Test a fix to a bug when handling calls to virtual functions that are +// annotated with LOCK/UNLOCK_FUNCTION. More specifically, the bug happens +// when we tried to assert the function decl of a gimple call statement +// returned by gimple_call_fndecl is non-NULL, which is not true when the call +// is a virtual function call. Instead, we should either get the function decl +// through the reference object, or (as is the fix) simply pass the function +// decl that we have extracted earlier all the way to +// handle_lock_primitive_attrs where the assertion fails. +// +// This is a good test case. (i.e. There should be no error/warning/ICE +// triggered.) +// +// { dg-do compile } +// { dg-options "-Wthread-safety -O" } + +#include "thread_annot_common.h" + +class Base { + protected: + virtual void Lock() EXCLUSIVE_LOCK_FUNCTION(mu_) { mu_.Lock(); } + virtual void Unlock() UNLOCK_FUNCTION(mu_) { mu_.Unlock(); } + Mutex mu_; +}; + +class Child: public Base { + int a; + public: + void func1() { + Lock(); + a += 1; + Unlock(); + } +}; + +main() { + Child c; + c.func1(); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn11.C b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn11.C new file mode 100644 index 000000000..a5416dbf2 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn11.C @@ -0,0 +1,40 @@ +/* Check if parameters are passed correctly to the versioned function. */ + +/* { dg-do run } */ + +#include <stdio.h> +#include <assert.h> + +int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} + +int __attribute__ ((noinline)) +foo (int n1, double n2, char n3) +{ + assert (n1 == 10); + assert (n2 == 20.0); + assert (n3 == 'c'); + return n1; +} + + +int __attribute__ ((noinline)) +bar (int n1, double n2, char n3) +{ + assert (n1 == 10); + assert (n2 == 20.0); + assert (n3 == 'c'); + return 0; +} + +int main () +{ + int a = __builtin_dispatch (featureTest, (void *)foo, (void *)bar, + 10, 20.0, 'c'); + int b = __builtin_dispatch (featureTest, (void *)bar, (void *)foo, + 10, 20.0, 'c'); + return a * b; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5.C b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5.C new file mode 100644 index 000000000..a596d01f4 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5.C @@ -0,0 +1,28 @@ +/* Check that global inline feature test functions are correctly handled. This + test case also needs mversn5a.c. extern_func calls foo and returns 0.*/ + +/* { dg-do run } */ +/* { dg-additional-sources "mversn5a.C" } */ + +#include "mversn5.h" + +extern int extern_func (); + +int foo () +{ + return 0; +} + +int bar () +{ + return 1; +} + +int __attribute__ ((cold)) +main () +{ + int a = 1, b = 1; + a = extern_func (); + b = __builtin_dispatch (featureTest, (void *)bar, (void *) foo); + return a * b; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5.h b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5.h new file mode 100644 index 000000000..253d3ff6d --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5.h @@ -0,0 +1,5 @@ +inline int __attribute__ ((version_selector)) +featureTest () +{ + return 1; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5a.C b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5a.C new file mode 100644 index 000000000..4c8a6804c --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/torture/mversn5a.C @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +#include "mversn5.h" + +extern int foo (); +extern int bar (); + + +int extern_func () +{ + return __builtin_dispatch (featureTest, (void *)foo, (void *) bar); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn13.C b/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn13.C new file mode 100644 index 000000000..3a7a543db --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn13.C @@ -0,0 +1,37 @@ +/* Make sure -fprofile-generate and -fprofile-use work fine. */ + +/* { dg-options "-O2 -fclone-hot-version-paths" } */ + +static int glob = 0; +int __attribute__ ((version_selector)) +featureTest () +{ + return glob; +} + +int bar (int i) +{ + if (i > 500) + return 2 * i; + return 3 * i; +} + +int foo (int i) +{ + bar (i); +} + +int +dispatch () +{ + int ret = 0; + for (int i = 0; i < 1000; i++) + ret += __builtin_dispatch (featureTest, (void *)foo, (void *)bar, i); + return ret; +} + +int main () +{ + int val = dispatch (); + return val > 10000000; +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn15.C b/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn15.C new file mode 100644 index 000000000..dfab1bdf3 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn15.C @@ -0,0 +1,23 @@ +/* Make sure LIPO works correctly. dispatch is defined in mversn15a.C. It either + calls foo or bar and both returns 1. So, the value of ret is always 1000. + After cross-module inlining, main must return 0. */ + +/* { dg-additional-sources "mversn15a.C" } */ +/* { dg-options "-O2 -fclone-hot-version-paths -fripa -fdump-tree-final_cleanup" } */ + +extern int foo (); +extern int bar (); +extern int dispatch (); + +int +main () +{ + int ret = 0; + for (int i = 1; i <= 1000; i++) + ret += dispatch (); + return ret - 1000; +} + +/* { dg-final-use { scan-tree-dump "main_clone" "final_cleanup" } } */ +/* { dg-final-use { scan-tree-dump "return 0" "final_cleanup" } } */ +/* { dg-final-use { cleanup-tree-dump "final_cleanup" } } */ diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn15a.C b/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn15a.C new file mode 100644 index 000000000..79e7b630a --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/tree-prof/mversn15a.C @@ -0,0 +1,26 @@ +/* { dg-options "-O2 -fclone-hot-version-paths -fripa" } */ +/* { dg-additional-sources "mversn15.C" } */ + +#include <stdio.h> + +inline int + __attribute__ ((version_selector)) +featureTest() +{ + return 1; +} + +int foo () +{ + return 1; +} + +int bar () +{ + return 1; +} + +int dispatch () +{ + return __builtin_dispatch (featureTest, (void *)foo, (void *)bar); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/uninit-pred-3_a.C b/gcc-4.4.3/gcc/testsuite/g++.dg/uninit-pred-3_a.C new file mode 100644 index 000000000..910140790 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/uninit-pred-3_a.C @@ -0,0 +1,77 @@ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized -O2" } */ + +/* Multiple initialization paths. */ + +typedef long long int64; +void incr (); +bool is_valid (int); +int get_time (); + +class A +{ +public: + A (); + ~A () { + if (I) delete I; + } + +private: + int* I; +}; + +bool get_url (A *); +bool get_url2 (A *); + +class M { + + public: + __attribute__ ((always_inline)) + bool GetC (int *c) { + + A details_str; + /* Intialization path 1 */ + if (get_url (&details_str)) + { + *c = get_time (); + return true; + } + + /* insert dtor calls (inlined) into following return paths */ + A tmp_str; + + /* Intializtion path 2 */ + if (get_url2 (&details_str)) + { + *c = get_time (); + return true; + } + + return false; + } + + void do_sth(); + void do_sth2(); + + void P (int64 t) + { + int cc; + if (!GetC (&cc)) /* return flag checked properly */ + return; + + if (cc <= 0) /* { dg-bogus "uninitialized" "uninitialized variable warning" } */ + { + this->do_sth(); + return; + } + + do_sth2(); + } +}; + +M* m; +void test(int x) +{ + m = new M; + m->P(x); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/uninit-pred-3_b.C b/gcc-4.4.3/gcc/testsuite/g++.dg/uninit-pred-3_b.C new file mode 100644 index 000000000..cfe2113bb --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/uninit-pred-3_b.C @@ -0,0 +1,87 @@ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized -O2" } */ + +/* Multiple initialization paths. */ + +typedef long long int64; +void incr (); +bool is_valid (int); +int get_time (); + +class A +{ +public: + A (); + ~A () { + if (I) delete I; + } + +private: + int* I; +}; + +bool get_url (A *); +bool get_url2 (A *); +bool get_url3 (A *); + +class M { + + public: + __attribute__ ((always_inline)) + bool GetC (int *c) { + + A details_str; + + /* Initialization path 1 */ + if (get_url (&details_str)) + { + *c = get_time (); + return true; + } + + /* Destructor call before return*/ + A tmp_str; + + /* Initialization path 2 */ + if (get_url2 (&details_str)) + { + *c = get_time (); + return true; + } + + /* Fail to initialize in this path but + still returns true */ + if (get_url2 (&details_str)) + { + /* Fail to initialize *c */ + return true; + } + + return false; + } + + void do_sth(); + void do_sth2(); + + void P (int64 t) + { + int cc; /* { dg-excess-errors "note: 'cc' was declared here" } */ + if (!GetC (&cc)) + return; + + if (cc <= 0) /* { dg-warning "uninitialized" "uninitialized variable warning" } */ + { + this->do_sth(); + return; + } + + do_sth2(); + } +}; + +M* m; +void test(int x) +{ + m = new M; + m->P(x); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnonnull-1.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnonnull-1.C new file mode 100644 index 000000000..837c6d6d8 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnonnull-1.C @@ -0,0 +1,16 @@ +// { dg-do compile } +// { dg-options "-Wnonnull" } + +#include <stddef.h> + +class Foo { + char *name; + public: + void func1(const int *ptr) __attribute__((nonnull(2))) {} + Foo(char *str) __attribute__((nonnull)) : name(str) {} +}; + +void Bar() { + Foo foo(NULL); // { dg-warning "null argument where non-null required" } + foo.func1(NULL); // { dg-warning "null argument where non-null required" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C index 561482914..511f091f2 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-1.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-Wnull-conversion" } +// { dg-options "-Wconversion-null" } #include <stddef.h> diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C index eb5f8b0c1..92a87d1e7 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-Wnull-conversion" } +// { dg-options "-Wconversion-null" } #include <stddef.h> diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-1.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-1.C index 6538d68d0..f15280501 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-1.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-1.C @@ -40,8 +40,8 @@ int func() *f = *f; // { dg-warning "assigned to itself" } bar1->b_ = bar1->b_; // { dg-warning "assigned to itself" } bar2.c_ = bar2.c_; // { dg-warning "assigned to itself" } - local_foo = local_foo; // { dg-warning "assigned to itself" } - foo = foo; // { dg-warning "assigned to itself" } + local_foo = local_foo; + foo = foo; foo.setA(5); bar_array[3].c_ = bar_array[3].c_; // { dg-warning "assigned to itself" } bar_array[x+g].b_ = bar_array[x+g].b_; // { dg-warning "assigned to itself" } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-2.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-2.C index c221787cf..35c3d8476 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-2.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-2.C @@ -18,9 +18,9 @@ template<typename T> T DoSomething(T y) { T a[5], *p; Bar<T> b; - b.x = b.x; // { dg-warning "assigned to itself" } - *p = *p; // { dg-warning "assigned to itself" } - a[2] = a[2]; // { dg-warning "assigned to itself" } + b.x = b.x; + *p = *p; + a[2] = a[2]; return *p; } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-3.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-3.C index ce6bec191..bc5732de9 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-3.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-3.C @@ -27,7 +27,7 @@ class Bar { template <class T> void func(T t) { ::testing::Bar(1) = ::testing::Foo(); // used to trigger a segfault - ::testing::Foo() = ::testing::Foo(); // { dg-warning "assigned to itself" } + ::testing::Foo() = ::testing::Foo(); } main() { diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-4.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-4.C index 465aadc3a..abe96b55d 100644 --- a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-4.C +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-4.C @@ -43,6 +43,6 @@ int func() bar_array[x+g].b_ = bar_array[x+g].b_ / 1; // should not warn x += 0; y -= 0; - foo = foo; // { dg-warning "assigned to itself" } + foo = foo; foo.operator=(foo); // should not warn } diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-5.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-5.C new file mode 100644 index 000000000..20df214dd --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-5.C @@ -0,0 +1,38 @@ +// Test -Wself-assign does not warn on self-assignment of non-POD variables. +// { dg-do compile } +// { dg-options "-Wself-assign" } + +template<typename T> +class Foo { + private: + T a_; + public: + Foo() : a_(a_) {} // { dg-warning "assigned to itself" } + void Set() { a_ = a_; } +}; + +struct Bar { + int b_; + int c_; + void operator=(Bar& rhs) { + this->b_ = rhs.b_; + this->c_ = rhs.c_; + } +}; + +template <typename T> +void func() { + T a; + a = a; +} + +main() +{ + Foo<Bar> foo; + Bar *bar1, bar2; + func<int>(); + foo = foo; + bar2 = bar2; + bar1 = bar1; // { dg-warning "assigned to itself" } + bar2.b_ = bar2.b_; // { dg-warning "assigned to itself" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-1.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-1.C new file mode 100644 index 000000000..6f9dfb73c --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-1.C @@ -0,0 +1,54 @@ +// Test the self-assignemnt detection and warning. +// { dg-do compile } +// { dg-options "-Wself-assign -Wself-assign-non-pod" } + +class Foo { + private: + int a_; + + public: + Foo() : a_(a_) {} // { dg-warning "assigned to itself" } + + void setA(int a) { + a_ = a_; // { dg-warning "assigned to itself" } + } + + void operator=(Foo& rhs) { + this->a_ = rhs.a_; + } +}; + +struct Bar { + int b_; + int c_; +}; + +int g = g; // { dg-warning "assigned to itself" } +Foo foo = foo; // { dg-warning "assigned to itself" } + +int func() +{ + Bar *bar1, bar2; + Foo local_foo; + int x = x; // { dg-warning "assigned to itself" } + static int y = y; // { dg-warning "assigned to itself" } + float *f; + Bar bar_array[5]; + char n; + int overflow; + + *f = *f; // { dg-warning "assigned to itself" } + bar1->b_ = bar1->b_; // { dg-warning "assigned to itself" } + bar2.c_ = bar2.c_; // { dg-warning "assigned to itself" } + local_foo = local_foo; // { dg-warning "assigned to itself" } + foo = foo; // { dg-warning "assigned to itself" } + foo.setA(5); + bar_array[3].c_ = bar_array[3].c_; // { dg-warning "assigned to itself" } + bar_array[x+g].b_ = bar_array[x+g].b_; // { dg-warning "assigned to itself" } + y = x; + x = y; + x += 0; // should not warn + y -= 0; // should not warn + x /= x; // should not warn + y *= y; // should not warn +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-2.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-2.C new file mode 100644 index 000000000..b31b57534 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-2.C @@ -0,0 +1,31 @@ +// Test the handling of expressions that depend on template parameters in +// self-assignemnt detection. +// { dg-do compile } +// { dg-options "-Wself-assign -Wself-assign-non-pod" } + +template<typename T> +struct Bar { + T x; + Bar operator++(int) { + Bar tmp = *this; + ++x; + tmp = tmp; // { dg-warning "assigned to itself" } + return tmp; + } +}; + +template<typename T> +T DoSomething(T y) { + T a[5], *p; + Bar<T> b; + b.x = b.x; // { dg-warning "assigned to itself" } + *p = *p; // { dg-warning "assigned to itself" } + a[2] = a[2]; // { dg-warning "assigned to itself" } + return *p; +} + +main() { + Bar<int> bar; + bar++; + DoSomething(5); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-3.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-3.C new file mode 100644 index 000000000..4c37f5764 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-3.C @@ -0,0 +1,35 @@ +// Test how operands_equal_p handles a NULL operand. +// { dg-do compile } +// { dg-options "-Wself-assign -Wself-assign-non-pod" } + +#include <cstdio> + +namespace testing { + +class Foo { + int f; + public: + Foo() { printf("Construct Foo\n"); } +}; + +class Bar { + int b; + public: + Bar(int x) { printf("Construct Bar\n"); } + + void operator=(const Foo& foo) { + printf("Assign Foo to Bar\n"); + } +}; + +} + +template <class T> +void func(T t) { + ::testing::Bar(1) = ::testing::Foo(); // used to trigger a segfault + ::testing::Foo() = ::testing::Foo(); // { dg-warning "assigned to itself" } +} + +main() { + func(2); +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-4.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-4.C new file mode 100644 index 000000000..86db4e3c6 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-4.C @@ -0,0 +1,48 @@ +// Test how self-assignment detection handles constant-folding happening +// when parsing the RHS or the initializer. +// { dg-do compile } +// { dg-options "-Wself-assign -Wself-assign-non-pod" } + +class Foo { + private: + int a_; + + public: + Foo() : a_(a_+0) {} // should not warn + + void setA(int a) { + a_ = a_ + 0; // should not warn + } + + void operator=(Foo& rhs) { + this->a_ = rhs.a_; + } +}; + +struct Bar { + int b_; + float c_; +}; + +int g = g * 1; // should not warn + +int func() +{ + Bar *bar1, bar2; + Foo foo; + int x = x - 0; // should not warn + static int y = y / 1; // should not warn + float *f; + Bar bar_array[5]; + + *f = *f / 1; // should not warn + bar1->b_ = bar1->b_ * 1; // should not warn + bar2.c_ = bar2.c_ - 0; // should not warn + foo.setA(5); + bar_array[3].c_ = bar_array[3].c_ * 1; // should not warn + bar_array[x+g].b_ = bar_array[x+g].b_ / 1; // should not warn + x += 0; + y -= 0; + foo = foo; // { dg-warning "assigned to itself" } + foo.operator=(foo); // should not warn +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-5.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-5.C new file mode 100644 index 000000000..898ddecd7 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/Wself-assign-non-pod-5.C @@ -0,0 +1,38 @@ +// Test -Wself-assign and -Wself-assign-non-pod. +// { dg-do compile } +// { dg-options "-Wself-assign -Wself-assign-non-pod" } + +template<typename T> +class Foo { + private: + T a_; + public: + Foo() : a_(a_) {} // { dg-warning "assigned to itself" } + void Set() { a_ = a_; } // { dg-warning "assigned to itself" } +}; + +struct Bar { + int b_; + int c_; + void operator=(Bar& rhs) { + this->b_ = rhs.b_; + this->c_ = rhs.c_; + } +}; + +template <typename T> +void func() { + T a; + a = a; // { dg-warning "assigned to itself" } +} + +main() +{ + Foo<Bar> foo; + Bar *bar1, bar2; + func<int>(); + foo = foo; // { dg-warning "assigned to itself" } + bar2 = bar2; // { dg-warning "assigned to itself" } + bar1 = bar1; // { dg-warning "assigned to itself" } + bar2.b_ = bar2.b_; // { dg-warning "assigned to itself" } +} diff --git a/gcc-4.4.3/gcc/testsuite/g++.dg/warn/nonnull2.C b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/nonnull2.C new file mode 100644 index 000000000..03006b1b2 --- /dev/null +++ b/gcc-4.4.3/gcc/testsuite/g++.dg/warn/nonnull2.C @@ -0,0 +1,14 @@ +// Test that "nonnull" attribute should not be applied to 'this' pointer. +// { dg-do compile } + +#define NULL 0 + +class Foo { + public: + void method1(const int *ptr) __attribute__((nonnull(1, 2))); // { dg-warning "nonnull argument references 'this' pointer" } + void method2(int *ptr1, int a, int *ptr2) __attribute__((nonnull(2, 3, 4))); // { dg-error "nonnull argument references non-pointer operand" } + static void func3(int *ptr) __attribute__((nonnull(1))); // should not warn + Foo(char *str) __attribute__((nonnull())) {} +}; + +int func4(int *ptr1, int a) __attribute__((nonnull(1))); // should not warn |