| 1 |
// PR rtl-optimization/104869 |
| 2 |
// { dg-do run } |
| 3 |
// { dg-options "-O2 -fvisibility=hidden -std=c++11" } |
| 4 |
// { dg-require-visibility "" } |
| 5 |
|
| 6 |
struct QBasicAtomicInteger { |
| 7 |
[[gnu::noipa]] int loadRelaxed() { return 1; } |
| 8 |
}; |
| 9 |
struct RefCount { |
| 10 |
bool deref() { |
| 11 |
int count = atomic.loadRelaxed(); |
| 12 |
if (count) |
| 13 |
return false; |
| 14 |
return deref(); |
| 15 |
} |
| 16 |
QBasicAtomicInteger atomic; |
| 17 |
}; |
| 18 |
struct QArrayData { |
| 19 |
RefCount ref; |
| 20 |
}; |
| 21 |
struct QString { |
| 22 |
~QString(); |
| 23 |
QArrayData d; |
| 24 |
}; |
| 25 |
int ok; |
| 26 |
QString::~QString() { d.ref.deref(); } |
| 27 |
struct Label { |
| 28 |
bool isValid() { return generator; } |
| 29 |
int *generator; |
| 30 |
int index; |
| 31 |
}; |
| 32 |
struct ControlFlow; |
| 33 |
struct Codegen { |
| 34 |
[[gnu::noipa]] bool visit(); |
| 35 |
ControlFlow *controlFlow; |
| 36 |
}; |
| 37 |
struct ControlFlow { |
| 38 |
enum UnwindType { EE }; |
| 39 |
struct UnwindTarget { |
| 40 |
Label linkLabel; |
| 41 |
}; |
| 42 |
ControlFlow *parent; |
| 43 |
UnwindType unwindTarget_type; |
| 44 |
UnwindTarget unwindTarget() { |
| 45 |
QString label; |
| 46 |
ControlFlow *flow = this; |
| 47 |
while (flow) { |
| 48 |
Label l = getUnwindTarget(unwindTarget_type, label); |
| 49 |
if (l.isValid()) |
| 50 |
return {l}; |
| 51 |
flow = flow->parent; |
| 52 |
} |
| 53 |
return UnwindTarget(); |
| 54 |
} |
| 55 |
[[gnu::noipa]] Label getUnwindTarget(UnwindType, QString &) { |
| 56 |
Label l = { &ok, 0 }; |
| 57 |
return l; |
| 58 |
} |
| 59 |
}; |
| 60 |
[[gnu::noipa]] void foo(int) { |
| 61 |
ok = 1; |
| 62 |
} |
| 63 |
[[gnu::noipa]] bool Codegen::visit() { |
| 64 |
if (!controlFlow) |
| 65 |
return false; |
| 66 |
ControlFlow::UnwindTarget target = controlFlow->unwindTarget(); |
| 67 |
if (target.linkLabel.isValid()) |
| 68 |
foo(2); |
| 69 |
return false; |
| 70 |
} |
| 71 |
#ifdef __hpux__ |
| 72 |
extern int main(void) __attribute__ ((visibility ("default"))); |
| 73 |
#endif |
| 74 |
int |
| 75 |
main() { |
| 76 |
ControlFlow cf = { nullptr, ControlFlow::UnwindType::EE }; |
| 77 |
Codegen c = { &cf }; |
| 78 |
c.visit(); |
| 79 |
if (!ok) |
| 80 |
__builtin_abort (); |
| 81 |
} |