| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
| 3 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
// Simply including <exception> was enough to crash sixgill at one point. |
| 8 |
#include <exception> |
| 9 |
|
| 10 |
#define ANNOTATE(property) __attribute__((annotate(property))) |
| 11 |
|
| 12 |
struct Cell { |
| 13 |
int f; |
| 14 |
} ANNOTATE("GC Thing"); |
| 15 |
|
| 16 |
extern void GC() ANNOTATE("GC Call"); |
| 17 |
|
| 18 |
void GC() { |
| 19 |
// If the implementation is too trivial, the function body won't be emitted at |
| 20 |
// all. |
| 21 |
asm(""); |
| 22 |
} |
| 23 |
|
| 24 |
class RAII_GC { |
| 25 |
public: |
| 26 |
RAII_GC() {} |
| 27 |
~RAII_GC() { GC(); } |
| 28 |
}; |
| 29 |
|
| 30 |
// ~AutoSomething calls GC because of the RAII_GC field. The constructor, |
| 31 |
// though, should *not* GC -- unless it throws an exception. Which is not |
| 32 |
// possible when compiled with -fno-exceptions. This test will try it both |
| 33 |
// ways. |
| 34 |
class AutoSomething { |
| 35 |
RAII_GC gc; |
| 36 |
|
| 37 |
public: |
| 38 |
AutoSomething() : gc() { |
| 39 |
asm(""); // Ooh, scary, this might throw an exception |
| 40 |
} |
| 41 |
~AutoSomething() { asm(""); } |
| 42 |
}; |
| 43 |
|
| 44 |
extern Cell* getcell(); |
| 45 |
|
| 46 |
extern void usevar(Cell* cell); |
| 47 |
|
| 48 |
void f() { |
| 49 |
Cell* thing = getcell(); // Live range starts here |
| 50 |
|
| 51 |
// When compiling with -fexceptions, there should be a hazard below. With |
| 52 |
// -fno-exceptions, there should not be one. We will check both. |
| 53 |
{ |
| 54 |
AutoSomething smth; // Constructor can GC only if exceptions are enabled |
| 55 |
usevar(thing); // Live range ends here |
| 56 |
} // In particular, 'thing' is dead at the destructor, so no hazard |
| 57 |
} |