From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- gcc/testsuite/g++.dg/opt/pr6713.C | 117 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 gcc/testsuite/g++.dg/opt/pr6713.C (limited to 'gcc/testsuite/g++.dg/opt/pr6713.C') diff --git a/gcc/testsuite/g++.dg/opt/pr6713.C b/gcc/testsuite/g++.dg/opt/pr6713.C new file mode 100644 index 000000000..d89fef81b --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr6713.C @@ -0,0 +1,117 @@ +// PR optimization/6713 +// This testcase segfaulted on x86 because a dangling REG_EQUAL note +// resulted in incorrect substitutions later. +// { dg-do run } +// { dg-options "-O2" } + +template class basic_iterator +{ + public: + basic_iterator(_CharT* _p) : _M_current(_p) {} + basic_iterator& operator++() { ++_M_current; return *this; } + _CharT& operator*() const { return *_M_current; } + bool operator!=(basic_iterator &_rhs) { return _M_current != _rhs._M_current; } + + private: + _CharT* _M_current; +}; + +template class basic_string +{ + public: + typedef unsigned int size_type; + typedef basic_iterator<_CharT> iterator; + + private: + struct _Rep + { + size_type _M_length; + size_type _M_capacity; + int _M_references; + + bool _M_is_leaked() const { return _M_references < 0; } + bool _M_is_shared() const { return _M_references > 0; } + void _M_set_leaked() { _M_references = -1; } + void _M_set_sharable() { _M_references = 0; } + }; + + struct _Rep _M_rep; + + struct _Alloc_hider + { + _CharT _raw[16]; + _CharT* _M_p; + }; + + mutable _Alloc_hider _M_dataplus; + + _CharT* _M_data() const { return _M_dataplus._M_p; } + + void _M_leak() { if (!_M_rep._M_is_leaked()) _M_leak_hard(); } + + static int count; + + static void _M_leak_hard(); + + public: + explicit basic_string(const _CharT* __s); + + iterator begin() { _M_leak(); return iterator(_M_data()); } + + iterator end() { _M_leak(); return iterator(_M_data() + this->size()); } + + size_type size() const { return _M_rep._M_length; } +}; + +template basic_string<_CharT>:: +basic_string(const _CharT* __s) +{ + int i; + + for (i=0; i<15; i++) { + if (!__s[i]) + break; + + _M_dataplus._raw[i] = __s[i]; + } + + _M_dataplus._raw[i] = 0; + _M_dataplus._M_p = _M_dataplus._raw; + + _M_rep._M_length = i; + _M_rep._M_capacity = i; + _M_rep._M_references = 1; +} + +template int basic_string<_CharT>::count = 0; + +template void basic_string<_CharT>:: +_M_leak_hard() +{ + count++; +} + +typedef basic_string string; + +template int basic_string::count; + +int isspa(int ch) +{ + return 0; +} + +void foo(string& str) +{ + string::iterator it = str.begin(); + string::iterator stop = str.end(); + + for (; it != stop; ++it) + if (isspa(*it)) + break; +} + +int main() +{ + string str("test"); + foo(str); +} -- cgit v1.2.3