blob: 81c64123dfdb5574ad9b31578b83e35be393fa04 [file] [log] [blame]
John McCalled1ae862011-01-28 11:13:47 +00001//===-- CGCleanup.h - Classes for cleanups IR generation --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// These classes support the generation of LLVM IR for cleanups.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_CODEGEN_CGCLEANUP_H
15#define LLVM_CLANG_LIB_CODEGEN_CGCLEANUP_H
John McCalled1ae862011-01-28 11:13:47 +000016
Reid Klecknerd29f1342013-06-19 17:07:50 +000017#include "EHScopeStack.h"
Reid Kleckner200fe222013-06-09 16:45:02 +000018#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/SmallVector.h"
Reid Klecknerd29f1342013-06-19 17:07:50 +000020
21namespace llvm {
22class BasicBlock;
23class Value;
24class ConstantInt;
25class AllocaInst;
26}
John McCalled1ae862011-01-28 11:13:47 +000027
28namespace clang {
29namespace CodeGen {
30
31/// A protected scope for zero-cost EH handling.
32class EHScope {
33 llvm::BasicBlock *CachedLandingPad;
John McCall8e4c74b2011-08-11 02:22:43 +000034 llvm::BasicBlock *CachedEHDispatchBlock;
John McCalled1ae862011-01-28 11:13:47 +000035
John McCall8e4c74b2011-08-11 02:22:43 +000036 EHScopeStack::stable_iterator EnclosingEHScope;
37
38 class CommonBitFields {
39 friend class EHScope;
40 unsigned Kind : 2;
41 };
42 enum { NumCommonBits = 2 };
John McCalled1ae862011-01-28 11:13:47 +000043
44protected:
John McCall8e4c74b2011-08-11 02:22:43 +000045 class CatchBitFields {
46 friend class EHCatchScope;
47 unsigned : NumCommonBits;
48
49 unsigned NumHandlers : 32 - NumCommonBits;
50 };
51
52 class CleanupBitFields {
53 friend class EHCleanupScope;
54 unsigned : NumCommonBits;
55
56 /// Whether this cleanup needs to be run along normal edges.
57 unsigned IsNormalCleanup : 1;
58
59 /// Whether this cleanup needs to be run along exception edges.
60 unsigned IsEHCleanup : 1;
61
62 /// Whether this cleanup is currently active.
63 unsigned IsActive : 1;
64
David Majnemerdc012fa2015-04-22 21:38:15 +000065 /// Whether this cleanup is a lifetime marker
66 unsigned IsLifetimeMarker : 1;
67
John McCall8e4c74b2011-08-11 02:22:43 +000068 /// Whether the normal cleanup should test the activation flag.
69 unsigned TestFlagInNormalCleanup : 1;
70
71 /// Whether the EH cleanup should test the activation flag.
72 unsigned TestFlagInEHCleanup : 1;
73
74 /// The amount of extra storage needed by the Cleanup.
75 /// Always a multiple of the scope-stack alignment.
76 unsigned CleanupSize : 12;
77
78 /// The number of fixups required by enclosing scopes (not including
79 /// this one). If this is the top cleanup scope, all the fixups
80 /// from this index onwards belong to this scope.
David Majnemerdc012fa2015-04-22 21:38:15 +000081 unsigned FixupDepth : 32 - 18 - NumCommonBits; // currently 13
John McCall8e4c74b2011-08-11 02:22:43 +000082 };
83
84 class FilterBitFields {
85 friend class EHFilterScope;
86 unsigned : NumCommonBits;
87
88 unsigned NumFilters : 32 - NumCommonBits;
89 };
90
91 union {
92 CommonBitFields CommonBits;
93 CatchBitFields CatchBits;
94 CleanupBitFields CleanupBits;
95 FilterBitFields FilterBits;
96 };
John McCalled1ae862011-01-28 11:13:47 +000097
98public:
99 enum Kind { Cleanup, Catch, Terminate, Filter };
100
John McCall8e4c74b2011-08-11 02:22:43 +0000101 EHScope(Kind kind, EHScopeStack::stable_iterator enclosingEHScope)
Craig Topper8a13c412014-05-21 05:09:00 +0000102 : CachedLandingPad(nullptr), CachedEHDispatchBlock(nullptr),
John McCall8e4c74b2011-08-11 02:22:43 +0000103 EnclosingEHScope(enclosingEHScope) {
104 CommonBits.Kind = kind;
105 }
John McCalled1ae862011-01-28 11:13:47 +0000106
John McCall8e4c74b2011-08-11 02:22:43 +0000107 Kind getKind() const { return static_cast<Kind>(CommonBits.Kind); }
John McCalled1ae862011-01-28 11:13:47 +0000108
109 llvm::BasicBlock *getCachedLandingPad() const {
110 return CachedLandingPad;
111 }
112
John McCall8e4c74b2011-08-11 02:22:43 +0000113 void setCachedLandingPad(llvm::BasicBlock *block) {
114 CachedLandingPad = block;
115 }
116
117 llvm::BasicBlock *getCachedEHDispatchBlock() const {
118 return CachedEHDispatchBlock;
119 }
120
121 void setCachedEHDispatchBlock(llvm::BasicBlock *block) {
122 CachedEHDispatchBlock = block;
123 }
124
125 bool hasEHBranches() const {
126 if (llvm::BasicBlock *block = getCachedEHDispatchBlock())
127 return !block->use_empty();
128 return false;
129 }
130
131 EHScopeStack::stable_iterator getEnclosingEHScope() const {
132 return EnclosingEHScope;
John McCalled1ae862011-01-28 11:13:47 +0000133 }
134};
135
136/// A scope which attempts to handle some, possibly all, types of
137/// exceptions.
138///
James Dennettbe302452012-06-15 22:10:14 +0000139/// Objective C \@finally blocks are represented using a cleanup scope
John McCalled1ae862011-01-28 11:13:47 +0000140/// after the catch scope.
141class EHCatchScope : public EHScope {
John McCalled1ae862011-01-28 11:13:47 +0000142 // In effect, we have a flexible array member
143 // Handler Handlers[0];
144 // But that's only standard in C99, not C++, so we have to do
145 // annoying pointer arithmetic instead.
146
147public:
148 struct Handler {
149 /// A type info value, or null (C++ null, not an LLVM null pointer)
150 /// for a catch-all.
Rafael Espindolabb9e7a32014-06-04 18:51:46 +0000151 llvm::Constant *Type;
John McCalled1ae862011-01-28 11:13:47 +0000152
153 /// The catch handler for this type.
154 llvm::BasicBlock *Block;
155
Craig Topper8a13c412014-05-21 05:09:00 +0000156 bool isCatchAll() const { return Type == nullptr; }
John McCalled1ae862011-01-28 11:13:47 +0000157 };
158
159private:
160 friend class EHScopeStack;
161
162 Handler *getHandlers() {
163 return reinterpret_cast<Handler*>(this+1);
164 }
165
166 const Handler *getHandlers() const {
167 return reinterpret_cast<const Handler*>(this+1);
168 }
169
170public:
171 static size_t getSizeForNumHandlers(unsigned N) {
172 return sizeof(EHCatchScope) + N * sizeof(Handler);
173 }
174
John McCall8e4c74b2011-08-11 02:22:43 +0000175 EHCatchScope(unsigned numHandlers,
176 EHScopeStack::stable_iterator enclosingEHScope)
177 : EHScope(Catch, enclosingEHScope) {
178 CatchBits.NumHandlers = numHandlers;
John McCalled1ae862011-01-28 11:13:47 +0000179 }
180
181 unsigned getNumHandlers() const {
John McCall8e4c74b2011-08-11 02:22:43 +0000182 return CatchBits.NumHandlers;
John McCalled1ae862011-01-28 11:13:47 +0000183 }
184
185 void setCatchAllHandler(unsigned I, llvm::BasicBlock *Block) {
Craig Topper8a13c412014-05-21 05:09:00 +0000186 setHandler(I, /*catchall*/ nullptr, Block);
John McCalled1ae862011-01-28 11:13:47 +0000187 }
188
Rafael Espindolabb9e7a32014-06-04 18:51:46 +0000189 void setHandler(unsigned I, llvm::Constant *Type, llvm::BasicBlock *Block) {
John McCalled1ae862011-01-28 11:13:47 +0000190 assert(I < getNumHandlers());
191 getHandlers()[I].Type = Type;
192 getHandlers()[I].Block = Block;
193 }
194
195 const Handler &getHandler(unsigned I) const {
196 assert(I < getNumHandlers());
197 return getHandlers()[I];
198 }
199
Kostya Serebryanyba4aced2014-01-09 09:22:32 +0000200 // Clear all handler blocks.
201 // FIXME: it's better to always call clearHandlerBlocks in DTOR and have a
202 // 'takeHandler' or some such function which removes ownership from the
203 // EHCatchScope object if the handlers should live longer than EHCatchScope.
204 void clearHandlerBlocks() {
205 for (unsigned I = 0, N = getNumHandlers(); I != N; ++I)
206 delete getHandler(I).Block;
207 }
208
John McCalled1ae862011-01-28 11:13:47 +0000209 typedef const Handler *iterator;
210 iterator begin() const { return getHandlers(); }
211 iterator end() const { return getHandlers() + getNumHandlers(); }
212
213 static bool classof(const EHScope *Scope) {
214 return Scope->getKind() == Catch;
215 }
216};
217
218/// A cleanup scope which generates the cleanup blocks lazily.
219class EHCleanupScope : public EHScope {
John McCalled1ae862011-01-28 11:13:47 +0000220 /// The nearest normal cleanup scope enclosing this one.
221 EHScopeStack::stable_iterator EnclosingNormal;
222
John McCall8e4c74b2011-08-11 02:22:43 +0000223 /// The nearest EH scope enclosing this one.
John McCalled1ae862011-01-28 11:13:47 +0000224 EHScopeStack::stable_iterator EnclosingEH;
225
226 /// The dual entry/exit block along the normal edge. This is lazily
227 /// created if needed before the cleanup is popped.
228 llvm::BasicBlock *NormalBlock;
229
John McCalled1ae862011-01-28 11:13:47 +0000230 /// An optional i1 variable indicating whether this cleanup has been
231 /// activated yet.
232 llvm::AllocaInst *ActiveFlag;
233
234 /// Extra information required for cleanups that have resolved
235 /// branches through them. This has to be allocated on the side
236 /// because everything on the cleanup stack has be trivially
237 /// movable.
238 struct ExtInfo {
239 /// The destinations of normal branch-afters and branch-throughs.
240 llvm::SmallPtrSet<llvm::BasicBlock*, 4> Branches;
241
242 /// Normal branch-afters.
Chris Lattner01cf8db2011-07-20 06:58:45 +0000243 SmallVector<std::pair<llvm::BasicBlock*,llvm::ConstantInt*>, 4>
John McCalled1ae862011-01-28 11:13:47 +0000244 BranchAfters;
John McCalled1ae862011-01-28 11:13:47 +0000245 };
246 mutable struct ExtInfo *ExtInfo;
247
248 struct ExtInfo &getExtInfo() {
249 if (!ExtInfo) ExtInfo = new struct ExtInfo();
250 return *ExtInfo;
251 }
252
253 const struct ExtInfo &getExtInfo() const {
254 if (!ExtInfo) ExtInfo = new struct ExtInfo();
255 return *ExtInfo;
256 }
257
258public:
259 /// Gets the size required for a lazy cleanup scope with the given
260 /// cleanup-data requirements.
261 static size_t getSizeForCleanupSize(size_t Size) {
262 return sizeof(EHCleanupScope) + Size;
263 }
264
265 size_t getAllocatedSize() const {
John McCall8e4c74b2011-08-11 02:22:43 +0000266 return sizeof(EHCleanupScope) + CleanupBits.CleanupSize;
John McCalled1ae862011-01-28 11:13:47 +0000267 }
268
John McCall8e4c74b2011-08-11 02:22:43 +0000269 EHCleanupScope(bool isNormal, bool isEH, bool isActive,
270 unsigned cleanupSize, unsigned fixupDepth,
271 EHScopeStack::stable_iterator enclosingNormal,
272 EHScopeStack::stable_iterator enclosingEH)
273 : EHScope(EHScope::Cleanup, enclosingEH), EnclosingNormal(enclosingNormal),
Craig Topper8a13c412014-05-21 05:09:00 +0000274 NormalBlock(nullptr), ActiveFlag(nullptr), ExtInfo(nullptr) {
John McCall8e4c74b2011-08-11 02:22:43 +0000275 CleanupBits.IsNormalCleanup = isNormal;
276 CleanupBits.IsEHCleanup = isEH;
277 CleanupBits.IsActive = isActive;
David Majnemerdc012fa2015-04-22 21:38:15 +0000278 CleanupBits.IsLifetimeMarker = false;
John McCall8e4c74b2011-08-11 02:22:43 +0000279 CleanupBits.TestFlagInNormalCleanup = false;
280 CleanupBits.TestFlagInEHCleanup = false;
281 CleanupBits.CleanupSize = cleanupSize;
282 CleanupBits.FixupDepth = fixupDepth;
283
284 assert(CleanupBits.CleanupSize == cleanupSize && "cleanup size overflow");
John McCalled1ae862011-01-28 11:13:47 +0000285 }
286
Kostya Serebryanyb21aa762014-10-08 18:31:54 +0000287 void Destroy() {
John McCalled1ae862011-01-28 11:13:47 +0000288 delete ExtInfo;
289 }
Kostya Serebryanyb21aa762014-10-08 18:31:54 +0000290 // Objects of EHCleanupScope are not destructed. Use Destroy().
Aaron Ballmanabc18922015-02-15 22:54:08 +0000291 ~EHCleanupScope() = delete;
John McCalled1ae862011-01-28 11:13:47 +0000292
John McCall8e4c74b2011-08-11 02:22:43 +0000293 bool isNormalCleanup() const { return CleanupBits.IsNormalCleanup; }
John McCalled1ae862011-01-28 11:13:47 +0000294 llvm::BasicBlock *getNormalBlock() const { return NormalBlock; }
295 void setNormalBlock(llvm::BasicBlock *BB) { NormalBlock = BB; }
296
John McCall8e4c74b2011-08-11 02:22:43 +0000297 bool isEHCleanup() const { return CleanupBits.IsEHCleanup; }
John McCalled1ae862011-01-28 11:13:47 +0000298
John McCall8e4c74b2011-08-11 02:22:43 +0000299 bool isActive() const { return CleanupBits.IsActive; }
300 void setActive(bool A) { CleanupBits.IsActive = A; }
John McCalled1ae862011-01-28 11:13:47 +0000301
David Majnemerdc012fa2015-04-22 21:38:15 +0000302 bool isLifetimeMarker() const { return CleanupBits.IsLifetimeMarker; }
303 void setLifetimeMarker() { CleanupBits.IsLifetimeMarker = true; }
304
John McCalled1ae862011-01-28 11:13:47 +0000305 llvm::AllocaInst *getActiveFlag() const { return ActiveFlag; }
306 void setActiveFlag(llvm::AllocaInst *Var) { ActiveFlag = Var; }
307
John McCall8e4c74b2011-08-11 02:22:43 +0000308 void setTestFlagInNormalCleanup() {
309 CleanupBits.TestFlagInNormalCleanup = true;
310 }
311 bool shouldTestFlagInNormalCleanup() const {
312 return CleanupBits.TestFlagInNormalCleanup;
313 }
John McCalled1ae862011-01-28 11:13:47 +0000314
John McCall8e4c74b2011-08-11 02:22:43 +0000315 void setTestFlagInEHCleanup() {
316 CleanupBits.TestFlagInEHCleanup = true;
317 }
318 bool shouldTestFlagInEHCleanup() const {
319 return CleanupBits.TestFlagInEHCleanup;
320 }
John McCalled1ae862011-01-28 11:13:47 +0000321
John McCall8e4c74b2011-08-11 02:22:43 +0000322 unsigned getFixupDepth() const { return CleanupBits.FixupDepth; }
John McCalled1ae862011-01-28 11:13:47 +0000323 EHScopeStack::stable_iterator getEnclosingNormalCleanup() const {
324 return EnclosingNormal;
325 }
John McCalled1ae862011-01-28 11:13:47 +0000326
John McCall8e4c74b2011-08-11 02:22:43 +0000327 size_t getCleanupSize() const { return CleanupBits.CleanupSize; }
John McCalled1ae862011-01-28 11:13:47 +0000328 void *getCleanupBuffer() { return this + 1; }
329
330 EHScopeStack::Cleanup *getCleanup() {
331 return reinterpret_cast<EHScopeStack::Cleanup*>(getCleanupBuffer());
332 }
333
334 /// True if this cleanup scope has any branch-afters or branch-throughs.
335 bool hasBranches() const { return ExtInfo && !ExtInfo->Branches.empty(); }
336
337 /// Add a branch-after to this cleanup scope. A branch-after is a
338 /// branch from a point protected by this (normal) cleanup to a
339 /// point in the normal cleanup scope immediately containing it.
340 /// For example,
341 /// for (;;) { A a; break; }
342 /// contains a branch-after.
343 ///
344 /// Branch-afters each have their own destination out of the
345 /// cleanup, guaranteed distinct from anything else threaded through
346 /// it. Therefore branch-afters usually force a switch after the
347 /// cleanup.
348 void addBranchAfter(llvm::ConstantInt *Index,
349 llvm::BasicBlock *Block) {
350 struct ExtInfo &ExtInfo = getExtInfo();
David Blaikie82e95a32014-11-19 07:49:47 +0000351 if (ExtInfo.Branches.insert(Block).second)
John McCalled1ae862011-01-28 11:13:47 +0000352 ExtInfo.BranchAfters.push_back(std::make_pair(Block, Index));
353 }
354
355 /// Return the number of unique branch-afters on this scope.
356 unsigned getNumBranchAfters() const {
357 return ExtInfo ? ExtInfo->BranchAfters.size() : 0;
358 }
359
360 llvm::BasicBlock *getBranchAfterBlock(unsigned I) const {
361 assert(I < getNumBranchAfters());
362 return ExtInfo->BranchAfters[I].first;
363 }
364
365 llvm::ConstantInt *getBranchAfterIndex(unsigned I) const {
366 assert(I < getNumBranchAfters());
367 return ExtInfo->BranchAfters[I].second;
368 }
369
370 /// Add a branch-through to this cleanup scope. A branch-through is
371 /// a branch from a scope protected by this (normal) cleanup to an
372 /// enclosing scope other than the immediately-enclosing normal
373 /// cleanup scope.
374 ///
375 /// In the following example, the branch through B's scope is a
376 /// branch-through, while the branch through A's scope is a
377 /// branch-after:
378 /// for (;;) { A a; B b; break; }
379 ///
380 /// All branch-throughs have a common destination out of the
381 /// cleanup, one possibly shared with the fall-through. Therefore
382 /// branch-throughs usually don't force a switch after the cleanup.
383 ///
384 /// \return true if the branch-through was new to this scope
385 bool addBranchThrough(llvm::BasicBlock *Block) {
David Blaikie82e95a32014-11-19 07:49:47 +0000386 return getExtInfo().Branches.insert(Block).second;
John McCalled1ae862011-01-28 11:13:47 +0000387 }
388
389 /// Determines if this cleanup scope has any branch throughs.
390 bool hasBranchThroughs() const {
391 if (!ExtInfo) return false;
392 return (ExtInfo->BranchAfters.size() != ExtInfo->Branches.size());
393 }
394
John McCalled1ae862011-01-28 11:13:47 +0000395 static bool classof(const EHScope *Scope) {
396 return (Scope->getKind() == Cleanup);
397 }
398};
399
400/// An exceptions scope which filters exceptions thrown through it.
401/// Only exceptions matching the filter types will be permitted to be
402/// thrown.
403///
404/// This is used to implement C++ exception specifications.
405class EHFilterScope : public EHScope {
John McCalled1ae862011-01-28 11:13:47 +0000406 // Essentially ends in a flexible array member:
407 // llvm::Value *FilterTypes[0];
408
409 llvm::Value **getFilters() {
410 return reinterpret_cast<llvm::Value**>(this+1);
411 }
412
413 llvm::Value * const *getFilters() const {
414 return reinterpret_cast<llvm::Value* const *>(this+1);
415 }
416
417public:
John McCall8e4c74b2011-08-11 02:22:43 +0000418 EHFilterScope(unsigned numFilters)
419 : EHScope(Filter, EHScopeStack::stable_end()) {
420 FilterBits.NumFilters = numFilters;
John McCalled1ae862011-01-28 11:13:47 +0000421 }
422
John McCall8e4c74b2011-08-11 02:22:43 +0000423 static size_t getSizeForNumFilters(unsigned numFilters) {
424 return sizeof(EHFilterScope) + numFilters * sizeof(llvm::Value*);
John McCalled1ae862011-01-28 11:13:47 +0000425 }
426
John McCall8e4c74b2011-08-11 02:22:43 +0000427 unsigned getNumFilters() const { return FilterBits.NumFilters; }
428
429 void setFilter(unsigned i, llvm::Value *filterValue) {
430 assert(i < getNumFilters());
431 getFilters()[i] = filterValue;
John McCalled1ae862011-01-28 11:13:47 +0000432 }
433
John McCall8e4c74b2011-08-11 02:22:43 +0000434 llvm::Value *getFilter(unsigned i) const {
435 assert(i < getNumFilters());
436 return getFilters()[i];
437 }
438
439 static bool classof(const EHScope *scope) {
440 return scope->getKind() == Filter;
John McCalled1ae862011-01-28 11:13:47 +0000441 }
442};
443
444/// An exceptions scope which calls std::terminate if any exception
445/// reaches it.
446class EHTerminateScope : public EHScope {
John McCalled1ae862011-01-28 11:13:47 +0000447public:
John McCall8e4c74b2011-08-11 02:22:43 +0000448 EHTerminateScope(EHScopeStack::stable_iterator enclosingEHScope)
449 : EHScope(Terminate, enclosingEHScope) {}
John McCalled1ae862011-01-28 11:13:47 +0000450 static size_t getSize() { return sizeof(EHTerminateScope); }
451
John McCall8e4c74b2011-08-11 02:22:43 +0000452 static bool classof(const EHScope *scope) {
453 return scope->getKind() == Terminate;
John McCalled1ae862011-01-28 11:13:47 +0000454 }
455};
456
457/// A non-stable pointer into the scope stack.
458class EHScopeStack::iterator {
459 char *Ptr;
460
461 friend class EHScopeStack;
462 explicit iterator(char *Ptr) : Ptr(Ptr) {}
463
464public:
Craig Topper8a13c412014-05-21 05:09:00 +0000465 iterator() : Ptr(nullptr) {}
John McCalled1ae862011-01-28 11:13:47 +0000466
467 EHScope *get() const {
468 return reinterpret_cast<EHScope*>(Ptr);
469 }
470
471 EHScope *operator->() const { return get(); }
472 EHScope &operator*() const { return *get(); }
473
474 iterator &operator++() {
475 switch (get()->getKind()) {
476 case EHScope::Catch:
477 Ptr += EHCatchScope::getSizeForNumHandlers(
478 static_cast<const EHCatchScope*>(get())->getNumHandlers());
479 break;
480
481 case EHScope::Filter:
482 Ptr += EHFilterScope::getSizeForNumFilters(
483 static_cast<const EHFilterScope*>(get())->getNumFilters());
484 break;
485
486 case EHScope::Cleanup:
487 Ptr += static_cast<const EHCleanupScope*>(get())
488 ->getAllocatedSize();
489 break;
490
491 case EHScope::Terminate:
492 Ptr += EHTerminateScope::getSize();
493 break;
494 }
495
496 return *this;
497 }
498
499 iterator next() {
500 iterator copy = *this;
501 ++copy;
502 return copy;
503 }
504
505 iterator operator++(int) {
506 iterator copy = *this;
507 operator++();
508 return copy;
509 }
510
511 bool encloses(iterator other) const { return Ptr >= other.Ptr; }
512 bool strictlyEncloses(iterator other) const { return Ptr > other.Ptr; }
513
514 bool operator==(iterator other) const { return Ptr == other.Ptr; }
515 bool operator!=(iterator other) const { return Ptr != other.Ptr; }
516};
517
518inline EHScopeStack::iterator EHScopeStack::begin() const {
519 return iterator(StartOfData);
520}
521
522inline EHScopeStack::iterator EHScopeStack::end() const {
523 return iterator(EndOfBuffer);
524}
525
526inline void EHScopeStack::popCatch() {
527 assert(!empty() && "popping exception stack when not empty");
528
John McCall8e4c74b2011-08-11 02:22:43 +0000529 EHCatchScope &scope = cast<EHCatchScope>(*begin());
530 InnermostEHScope = scope.getEnclosingEHScope();
531 StartOfData += EHCatchScope::getSizeForNumHandlers(scope.getNumHandlers());
John McCalled1ae862011-01-28 11:13:47 +0000532}
533
534inline void EHScopeStack::popTerminate() {
535 assert(!empty() && "popping exception stack when not empty");
536
John McCall8e4c74b2011-08-11 02:22:43 +0000537 EHTerminateScope &scope = cast<EHTerminateScope>(*begin());
538 InnermostEHScope = scope.getEnclosingEHScope();
John McCalled1ae862011-01-28 11:13:47 +0000539 StartOfData += EHTerminateScope::getSize();
John McCalled1ae862011-01-28 11:13:47 +0000540}
541
542inline EHScopeStack::iterator EHScopeStack::find(stable_iterator sp) const {
543 assert(sp.isValid() && "finding invalid savepoint");
544 assert(sp.Size <= stable_begin().Size && "finding savepoint after pop");
545 return iterator(EndOfBuffer - sp.Size);
546}
547
548inline EHScopeStack::stable_iterator
549EHScopeStack::stabilize(iterator ir) const {
550 assert(StartOfData <= ir.Ptr && ir.Ptr <= EndOfBuffer);
551 return stable_iterator(EndOfBuffer - ir.Ptr);
552}
553
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000554}
555}
John McCalled1ae862011-01-28 11:13:47 +0000556
557#endif