| 1 |
// PR tree-optimization/109462 |
| 2 |
// { dg-do run { target c++11 } } |
| 3 |
// { dg-options "-O2" } |
| 4 |
|
| 5 |
struct A { |
| 6 |
A (const char *); |
| 7 |
A (const char *, int); |
| 8 |
bool empty (); |
| 9 |
int size (); |
| 10 |
bool equals (A); |
| 11 |
A trim (char); |
| 12 |
A trim (); |
| 13 |
}; |
| 14 |
[[gnu::noipa]] A::A (const char *) {} |
| 15 |
[[gnu::noipa]] A::A (const char *, int) { __builtin_abort (); } |
| 16 |
[[gnu::noipa]] bool A::empty () { __builtin_abort (); } |
| 17 |
[[gnu::noipa]] int A::size () { __builtin_abort (); } |
| 18 |
[[gnu::noipa]] bool A::equals (A) { return true; } |
| 19 |
[[gnu::noipa]] A A::trim (char) { __builtin_abort (); } |
| 20 |
[[gnu::noipa]] A A::trim () { __builtin_abort (); } |
| 21 |
|
| 22 |
enum B { raw_identifier = 6, l_paren = 21, r_paren = 22 }; |
| 23 |
[[gnu::noipa]] bool isAnyIdentifier (B) { return true; } |
| 24 |
[[gnu::noipa]] bool isStringLiteral (B) { __builtin_abort (); } |
| 25 |
|
| 26 |
struct C { |
| 27 |
B c; |
| 28 |
B getKind () { return c; } |
| 29 |
bool is (B x) { return c == x; } |
| 30 |
unsigned getLength () { __builtin_abort (); } |
| 31 |
A getRawIdentifier () { |
| 32 |
A x (""); |
| 33 |
c == raw_identifier ? void () : __builtin_abort (); |
| 34 |
return x; |
| 35 |
} |
| 36 |
const char *getLiteralData (); |
| 37 |
}; |
| 38 |
[[gnu::noipa]] const char *C::getLiteralData () { __builtin_abort (); } |
| 39 |
|
| 40 |
struct D { |
| 41 |
D (); |
| 42 |
bool LexFromRawLexer (C &); |
| 43 |
}; |
| 44 |
[[gnu::noipa]] D::D () {} |
| 45 |
[[gnu::noipa]] bool D::LexFromRawLexer (C &t) { |
| 46 |
static int cnt; |
| 47 |
C tok[] = { { raw_identifier }, { l_paren }, { raw_identifier }, { r_paren } }; |
| 48 |
t = tok[cnt++]; |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
bool ok = false; |
| 53 |
[[gnu::noipa]] void reportEmptyContextError () |
| 54 |
{ |
| 55 |
ok = true; |
| 56 |
} |
| 57 |
|
| 58 |
[[gnu::noipa]] void |
| 59 |
VisitObjCMessageExpr () |
| 60 |
{ |
| 61 |
D TheLexer; |
| 62 |
C I; |
| 63 |
C Result; |
| 64 |
int p_count = 0; |
| 65 |
while (!TheLexer.LexFromRawLexer (I)) { |
| 66 |
if (I.getKind () == l_paren) |
| 67 |
++p_count; |
| 68 |
if (I.getKind () == r_paren) { |
| 69 |
if (p_count == 1) |
| 70 |
break; |
| 71 |
--p_count; |
| 72 |
} |
| 73 |
Result = I; |
| 74 |
} |
| 75 |
if (isAnyIdentifier (Result.getKind ())) { |
| 76 |
if (Result.getRawIdentifier ().equals ("nil")) { |
| 77 |
reportEmptyContextError (); |
| 78 |
return; |
| 79 |
} |
| 80 |
} |
| 81 |
if (!isStringLiteral (Result.getKind ())) |
| 82 |
return; |
| 83 |
A Comment = A (Result.getLiteralData (), Result.getLength ()).trim ('"'); |
| 84 |
if ((Comment.trim ().size () == 0 && Comment.size () > 0) || Comment.empty ()) |
| 85 |
reportEmptyContextError (); |
| 86 |
} |
| 87 |
|
| 88 |
int |
| 89 |
main () |
| 90 |
{ |
| 91 |
VisitObjCMessageExpr (); |
| 92 |
if (!ok) |
| 93 |
__builtin_abort (); |
| 94 |
} |