Be careful about comdat boundary in ICF (PR ipa/82352).
[official-gcc.git] / gcc / testsuite / g++.dg / opt / pr6713.C
blobd89fef81b2c97342943217f88c9a95a7139ef04b
1 // PR optimization/6713
2 // This testcase segfaulted on x86 because a dangling REG_EQUAL note
3 // resulted in incorrect substitutions later.
4 // { dg-do run }
5 // { dg-options "-O2" }
7 template<typename _CharT> class basic_iterator
9   public:
10     basic_iterator(_CharT* _p) : _M_current(_p) {}
11     basic_iterator& operator++() { ++_M_current; return *this; }
12     _CharT& operator*() const { return *_M_current; }
13     bool operator!=(basic_iterator &_rhs) { return _M_current != _rhs._M_current; }
15   private:
16     _CharT* _M_current;
19 template<typename _CharT> class basic_string
21   public:
22     typedef unsigned int size_type;
23     typedef basic_iterator<_CharT> iterator;
25   private:
26     struct _Rep
27     {
28       size_type _M_length;
29       size_type _M_capacity;
30       int _M_references;
32       bool _M_is_leaked() const { return _M_references < 0; }
33       bool _M_is_shared() const { return _M_references > 0; }
34       void _M_set_leaked() { _M_references = -1; }
35       void _M_set_sharable() { _M_references = 0; }
36     };
38     struct _Rep _M_rep;
40     struct _Alloc_hider
41     {
42       _CharT _raw[16];
43       _CharT* _M_p;
44     };
46     mutable _Alloc_hider _M_dataplus;
48     _CharT* _M_data() const { return _M_dataplus._M_p; }
50     void _M_leak() { if (!_M_rep._M_is_leaked()) _M_leak_hard(); }
52     static int count;
54     static void _M_leak_hard();
56   public:
57     explicit basic_string(const _CharT* __s);
59     iterator begin() { _M_leak(); return iterator(_M_data()); }
61     iterator end() { _M_leak(); return iterator(_M_data() + this->size()); }
63     size_type size() const { return _M_rep._M_length; }
66 template<typename _CharT> basic_string<_CharT>::
67 basic_string(const _CharT* __s)
69   int i;
71   for (i=0; i<15; i++) {
72     if (!__s[i])
73       break;
75     _M_dataplus._raw[i] = __s[i];
76   }
78   _M_dataplus._raw[i] = 0;
79   _M_dataplus._M_p = _M_dataplus._raw;
81   _M_rep._M_length = i;
82   _M_rep._M_capacity = i;
83   _M_rep._M_references = 1;
84 }     
86 template<typename _CharT> int basic_string<_CharT>::count = 0;
88 template<typename _CharT> void basic_string<_CharT>::
89 _M_leak_hard()
91   count++;
94 typedef basic_string<char> string;
96 template int basic_string<char>::count;
98 int isspa(int ch)
100   return 0;
103 void foo(string& str)
105   string::iterator it = str.begin();
106   string::iterator stop = str.end();
108   for (; it != stop; ++it)
109     if (isspa(*it))
110       break;
113 int main()
115   string str("test");
116   foo(str);