OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [opt/] [pr6713.C] - Blame information for rev 693

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
// 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" }
6
 
7
template class basic_iterator
8
{
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; }
14
 
15
  private:
16
    _CharT* _M_current;
17
};
18
 
19
template class basic_string
20
{
21
  public:
22
    typedef unsigned int size_type;
23
    typedef basic_iterator<_CharT> iterator;
24
 
25
  private:
26
    struct _Rep
27
    {
28
      size_type _M_length;
29
      size_type _M_capacity;
30
      int _M_references;
31
 
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
    };
37
 
38
    struct _Rep _M_rep;
39
 
40
    struct _Alloc_hider
41
    {
42
      _CharT _raw[16];
43
      _CharT* _M_p;
44
    };
45
 
46
    mutable _Alloc_hider _M_dataplus;
47
 
48
    _CharT* _M_data() const { return _M_dataplus._M_p; }
49
 
50
    void _M_leak() { if (!_M_rep._M_is_leaked()) _M_leak_hard(); }
51
 
52
    static int count;
53
 
54
    static void _M_leak_hard();
55
 
56
  public:
57
    explicit basic_string(const _CharT* __s);
58
 
59
    iterator begin() { _M_leak(); return iterator(_M_data()); }
60
 
61
    iterator end() { _M_leak(); return iterator(_M_data() + this->size()); }
62
 
63
    size_type size() const { return _M_rep._M_length; }
64
};
65
 
66
template basic_string<_CharT>::
67
basic_string(const _CharT* __s)
68
{
69
  int i;
70
 
71
  for (i=0; i<15; i++) {
72
    if (!__s[i])
73
      break;
74
 
75
    _M_dataplus._raw[i] = __s[i];
76
  }
77
 
78
  _M_dataplus._raw[i] = 0;
79
  _M_dataplus._M_p = _M_dataplus._raw;
80
 
81
  _M_rep._M_length = i;
82
  _M_rep._M_capacity = i;
83
  _M_rep._M_references = 1;
84
}
85
 
86
template int basic_string<_CharT>::count = 0;
87
 
88
template void basic_string<_CharT>::
89
_M_leak_hard()
90
{
91
  count++;
92
}
93
 
94
typedef basic_string string;
95
 
96
template int basic_string::count;
97
 
98
int isspa(int ch)
99
{
100
  return 0;
101
}
102
 
103
void foo(string& str)
104
{
105
  string::iterator it = str.begin();
106
  string::iterator stop = str.end();
107
 
108
  for (; it != stop; ++it)
109
    if (isspa(*it))
110
      break;
111
}
112
 
113
int main()
114
{
115
  string str("test");
116
  foo(str);
117
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.