aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/opt/pr56999.C
blob: 6db2f270ecfd57c104dae546cabcf6698aefac4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// PR rtl-optimization/56999
// { dg-do run }
// { dg-options "-O2" }
// { dg-additional-options "-fpic" { target fpic } }
// { dg-additional-options "-march=i686 -mtune=atom" { target ia32 } }
// { dg-require-visibility "" }

extern "C" void abort (void);
extern "C" void exit (int);
volatile bool do_exit = true;
struct JSScript;
struct JITScript { int i; };
#pragma GCC visibility push(hidden)
typedef struct JSCompartment JSCompartment;
typedef struct JSContext JSContext;
namespace js
{
  struct ContextFriendFields
  {
    JSCompartment *compartment;
  };
  struct TempAllocPolicy
  {
  };
  template <class T>
  struct Vector
  {
    T *mBegin;
    T *begin () { return mBegin; }
    T & operator[] (unsigned i) { return begin ()[i]; }
    template <class U>
    __attribute__((noinline, noclone))
    bool append (U) { asm volatile ("" : : : "memory"); if (do_exit) abort (); return false; }
  };
  namespace types
  {
    struct TypeCompartment;
  }
  namespace mjit
  {
  }
  namespace ion
  {
    struct IonScript;
  }
  namespace types
  {
    struct CompilerOutput
    {
      enum Kind { MethodJIT, ParallelIon };
      JSScript *script;
      unsigned kindInt : 2;
      bool constructing : 1;
      bool barriers : 1;
      bool pendingRecompilation : 1;
      Kind kind () const { return static_cast <Kind> (kindInt); }
      bool isValid () const;
    };
    struct RecompileInfo
    {
      unsigned outputIndex;
      CompilerOutput *compilerOutput (TypeCompartment & types) const;
      CompilerOutput *compilerOutput (JSContext *cx) const;
    };
    struct TypeCompartment
    {
      Vector <CompilerOutput> *constrainedOutputs;
      Vector <RecompileInfo> *pendingRecompiles;
      void addPendingRecompile (JSContext *cx, const RecompileInfo & info);
    };
  }
}
struct JSScript
{
  struct JITScriptHandle
  {
    static volatile JITScript *UNJITTABLE __attribute__((visibility ("default")));
    JITScript *value;
    bool isValid () { return value != UNJITTABLE; }
    JITScript *getValid () { return value; }
  };
  struct JITScriptSet
  {
    JITScriptHandle jitHandleNormal, jitHandleNormalBarriered;
    JITScriptHandle jitHandleCtor, jitHandleCtorBarriered;
    JITScriptHandle jitNull1, jitNull2;
  };
  JITScriptSet *mJITInfo;
  void *ion;
  JITScriptHandle *jitHandle (bool constructing, bool barriers)
  {
    return constructing ? (barriers ? &mJITInfo->jitHandleCtorBarriered
				    : &mJITInfo->jitHandleCtor)
			: (barriers ? &mJITInfo->jitHandleNormalBarriered
				    : &mJITInfo->jitHandleNormal);
  }
  JITScript *getJIT (bool constructing, bool barriers)
  {
    JITScriptHandle *jith = jitHandle (constructing, barriers);
    return jith->isValid () ? jith->getValid () : __null;
  }
};
struct JSContext : js::ContextFriendFields
{
};
namespace js
{
  __attribute__((noinline, noclone))
  void CancelOffThreadIonCompile (JSCompartment *, JSScript *)
  {
    if (do_exit)
      exit (0);
  }
}
struct JSCompartment
{
  js::types::TypeCompartment types;
};
namespace js
{
  namespace types
  {
    inline bool CompilerOutput::isValid () const
    {
      if (!script)
	return false;
      switch (kind ())
	{
	case MethodJIT:
	  {
	    JITScript *jit = script->getJIT (constructing, barriers);
	    if (!jit)
	      return false;
	  }
	case ParallelIon:
	  return true;
	}
      return false;
    }
    inline CompilerOutput *RecompileInfo::compilerOutput (TypeCompartment & types) const
    {
      return &(*types.constrainedOutputs)[outputIndex];
    }
    inline CompilerOutput *RecompileInfo::compilerOutput (JSContext *cx) const
    {
      return compilerOutput (cx->compartment->types);
    }
  }
}
using namespace js::types;
__attribute__((noinline, noclone)) void
TypeCompartment::addPendingRecompile (JSContext *cx, const RecompileInfo & info)
{
  CompilerOutput *co = info.compilerOutput (cx);
  if (co->pendingRecompilation)
    if (co->isValid ())
      CancelOffThreadIonCompile (cx->compartment, co->script);
  if (co->isValid ())
    pendingRecompiles->append (info);
}
volatile JITScript *JSScript::JITScriptHandle::UNJITTABLE;
int
main ()
{
  JSContext cx;
  JSCompartment com;
  RecompileInfo info;
  cx.compartment = &com;
  info.outputIndex = 0;
  js::Vector<CompilerOutput> v;
  JITScript js;
  JSScript::JITScriptSet set;
  __builtin_memset (&set, 0, sizeof set);
  set.jitHandleCtor.value = &js;
  JSScript s;
  s.mJITInfo = &set;
  CompilerOutput co;
  co.kindInt = 0;
  co.constructing = true;
  co.barriers = false;
  co.pendingRecompilation = true;
  co.script = &s;
  v.mBegin = &co;
  com.types.constrainedOutputs = &v;
  com.types.pendingRecompiles = __null;
  com.types.addPendingRecompile (&cx, info);
  abort ();
}