Haojian Wu | 70e2c7a | 2020-07-20 15:29:14 +0200 | [diff] [blame] | 1 | // RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast -fno-recovery-ast-type -ast-dump %s | FileCheck -strict-whitespace %s |
| 2 | |
| 3 | int some_func(int); |
| 4 | |
| 5 | // CHECK: VarDecl {{.*}} unmatch_arg_call 'int' cinit |
| 6 | // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors |
| 7 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func' |
| 8 | int unmatch_arg_call = some_func(); |
| 9 | |
| 10 | const int a = 1; |
| 11 | |
| 12 | // CHECK: VarDecl {{.*}} postfix_inc |
| 13 | // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors |
| 14 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'a' |
| 15 | int postfix_inc = a++; |
| 16 | |
| 17 | // CHECK: VarDecl {{.*}} unary_address |
| 18 | // CHECK-NEXT:`-RecoveryExpr {{.*}} contains-errors |
| 19 | // CHECK-NEXT: `-ParenExpr {{.*}} |
| 20 | // CHECK-NEXT: `-BinaryOperator {{.*}} '+' |
| 21 | // CHECK-NEXT: |-ImplicitCastExpr |
| 22 | // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'a' |
| 23 | // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' |
| 24 | int unary_address = &(a + 1); |
| 25 | |
| 26 | // CHECK: VarDecl {{.*}} ternary 'int' cinit |
Haojian Wu | 8852d30 | 2020-10-12 11:24:45 +0200 | [diff] [blame] | 27 | // CHECK-NEXT: `-ConditionalOperator {{.*}} |
Haojian Wu | 70e2c7a | 2020-07-20 15:29:14 +0200 | [diff] [blame] | 28 | // CHECK-NEXT: |-DeclRefExpr {{.*}} 'a' |
Haojian Wu | 8852d30 | 2020-10-12 11:24:45 +0200 | [diff] [blame] | 29 | // CHECK-NEXT: |-RecoveryExpr {{.*}} |
Haojian Wu | 70e2c7a | 2020-07-20 15:29:14 +0200 | [diff] [blame] | 30 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'a' |
Haojian Wu | 70e2c7a | 2020-07-20 15:29:14 +0200 | [diff] [blame] | 31 | int ternary = a ? undef : a; |
| 32 | |
| 33 | void test1() { |
| 34 | // CHECK: `-RecoveryExpr {{.*}} contains-errors |
| 35 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'a' 'const int' |
| 36 | static int foo = a++; // verify no crash on local static var decl. |
| 37 | } |
Haojian Wu | 706a435 | 2020-07-22 10:03:51 +0200 | [diff] [blame] | 38 | |
| 39 | void test2() { |
| 40 | int* ptr; |
Haojian Wu | 70d9dc8 | 2020-10-06 08:51:49 +0200 | [diff] [blame] | 41 | // CHECK: BinaryOperator {{.*}} 'int *' contains-errors '=' |
| 42 | // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ptr' 'int *' |
| 43 | // CHECK-NEXT: `-RecoveryExpr {{.*}} |
| 44 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func' |
Haojian Wu | 706a435 | 2020-07-22 10:03:51 +0200 | [diff] [blame] | 45 | ptr = some_func(); // should not crash |
Haojian Wu | 70d9dc8 | 2020-10-06 08:51:49 +0200 | [diff] [blame] | 46 | |
| 47 | int compoundOp; |
| 48 | // CHECK: CompoundAssignOperator {{.*}} 'int' contains-errors '+=' |
| 49 | // CHECK-NEXT: |-DeclRefExpr {{.*}} 'compoundOp' |
| 50 | // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors |
| 51 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func' |
| 52 | compoundOp += some_func(); |
| 53 | |
| 54 | // CHECK: BinaryOperator {{.*}} 'int' contains-errors '||' |
| 55 | // CHECK-NEXT: |-RecoveryExpr {{.*}} |
| 56 | // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'some_func' |
| 57 | // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1 |
| 58 | some_func() || 1; |
| 59 | |
| 60 | // CHECK: BinaryOperator {{.*}} '<dependent type>' contains-errors ',' |
| 61 | // CHECK-NEXT: |-IntegerLiteral {{.*}} 'int' 1 |
| 62 | // CHECK-NEXT: `-RecoveryExpr {{.*}} |
| 63 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func' |
| 64 | 1, some_func(); |
| 65 | // CHECK: BinaryOperator {{.*}} 'int' contains-errors ',' |
| 66 | // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>' |
| 67 | // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'some_func' |
| 68 | // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1 |
| 69 | some_func(), 1; |
Haojian Wu | 334ec6f | 2020-10-07 09:33:57 +0200 | [diff] [blame] | 70 | |
| 71 | // conditional operator (comparison is invalid) |
| 72 | float f; |
| 73 | // CHECK: ConditionalOperator {{.*}} '<dependent type>' contains-errors |
| 74 | // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>' |
| 75 | // CHECK-NEXT: | |-DeclRefExpr {{.*}} 'int *' lvalue |
| 76 | // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'float' lvalue |
| 77 | // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int *' lvalue |
| 78 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue |
| 79 | (ptr > f ? ptr : f); |
Haojian Wu | a96bcfb | 2020-10-08 10:00:29 +0200 | [diff] [blame] | 80 | |
| 81 | // CHECK: CStyleCastExpr {{.*}} 'float' contains-errors <Dependent> |
| 82 | // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' |
| 83 | // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func' |
| 84 | (float)some_func(); |
Haojian Wu | 706a435 | 2020-07-22 10:03:51 +0200 | [diff] [blame] | 85 | } |
Haojian Wu | bb406f3 | 2020-10-12 11:12:58 +0200 | [diff] [blame] | 86 | |
| 87 | void test3() { |
| 88 | // CHECK: CallExpr {{.*}} '<dependent type>' contains-errors |
| 89 | // CHECK-NEXT: |-ParenExpr {{.*}} contains-errors lvalue |
| 90 | // CHECK-NEXT: | `-RecoveryExpr {{.*}} contains-errors |
| 91 | // CHECK-NEXT: | `-DeclRefExpr {{.*}} '__builtin_classify_type' |
| 92 | // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1 |
| 93 | (*__builtin_classify_type)(1); |
| 94 | |
| 95 | extern void ext(); |
| 96 | // CHECK: CallExpr {{.*}} 'void' contains-errors |
| 97 | // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext' |
| 98 | // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>' |
| 99 | ext(undef_var); |
| 100 | } |