Debian Codegraph @

clang/test/AST/ast-dump-recovery.c

raw
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 void test1() {
27 // CHECK: `-RecoveryExpr {{.*}} contains-errors
28 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'a' 'const int'
29 static int foo = a++; // verify no crash on local static var decl.
30 }
31
32 void test2() {
33 int* ptr;
34 // CHECK: BinaryOperator {{.*}} 'int *' contains-errors '='
35 // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ptr' 'int *'
36 // CHECK-NEXT: `-RecoveryExpr {{.*}}
37 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func'
38 ptr = some_func(); // should not crash
39
40 int compoundOp;
41 // CHECK: CompoundAssignOperator {{.*}} 'int' contains-errors '+='
42 // CHECK-NEXT: |-DeclRefExpr {{.*}} 'compoundOp'
43 // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors
44 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func'
45 compoundOp += some_func();
46
47 // CHECK: BinaryOperator {{.*}} 'int' contains-errors '||'
48 // CHECK-NEXT: |-RecoveryExpr {{.*}}
49 // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'some_func'
50 // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
51 some_func() || 1;
52
53 // CHECK: BinaryOperator {{.*}} '<dependent type>' contains-errors ','
54 // CHECK-NEXT: |-IntegerLiteral {{.*}} 'int' 1
55 // CHECK-NEXT: `-RecoveryExpr {{.*}}
56 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func'
57 1, some_func();
58 // CHECK: BinaryOperator {{.*}} 'int' contains-errors ','
59 // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>'
60 // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'some_func'
61 // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
62 some_func(), 1;
63
64 // conditional operator (comparison is invalid)
65 float f;
66 // CHECK: ConditionalOperator {{.*}} '<dependent type>' contains-errors
67 // CHECK-NEXT: |-RecoveryExpr {{.*}} '<dependent type>'
68 // CHECK-NEXT: | |-DeclRefExpr {{.*}} 'int *' lvalue
69 // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'float' lvalue
70 // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int *' lvalue
71 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue
72 (ptr > f ? ptr : f);
73
74 // CHECK: CStyleCastExpr {{.*}} 'float' contains-errors <Dependent>
75 // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
76 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func'
77 (float)some_func();
78 }
79
80 void test3() {
81 // CHECK: CallExpr {{.*}} '<dependent type>' contains-errors
82 // CHECK-NEXT: |-ParenExpr {{.*}} contains-errors lvalue
83 // CHECK-NEXT: | `-RecoveryExpr {{.*}} contains-errors
84 // CHECK-NEXT: | `-DeclRefExpr {{.*}} '__builtin_classify_type'
85 // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
86 (*__builtin_classify_type)(1);
87 }
88
89 // Verify no crash.
90 void test4() {
91 enum GH62446 {
92 // CHECK: RecoveryExpr {{.*}} '<dependent type>' contains-errors lvalue
93 // CHECK-NEXT: |-StringLiteral {{.*}} "a"
94 // CHECK-NEXT: `-IntegerLiteral {{.*}} 2
95 invalid_enum_value = "a" * 2,
96 b,
97 };
98 }
99
100 // No crash on DeclRefExpr that refers to ValueDecl with invalid initializers.
101 void test7() {
102 int b[] = {""()};
103
104 // CHECK: CStyleCastExpr {{.*}} 'unsigned int' contains-errors
105 // CHECK-NEXT: | `-DeclRefExpr {{.*}} 'int[]' contains-errors
106 (unsigned) b; // GH50236
107
108 // CHECK: BinaryOperator {{.*}} '<dependent type>' contains-errors '+'
109 // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int[]' contains-errors
110 // CHECK-NEXT: `-IntegerLiteral {{.*}}
111 b + 1; // GH50243
112
113 // CHECK: CallExpr {{.*}} '<dependent type>' contains-errors
114 // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()' Function
115 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int[]' contains-errors
116 return c(b); // GH48636
117 }
118 int test8_GH50320_b[] = {""()};
119 // CHECK: ArraySubscriptExpr {{.*}} 'int' contains-errors lvalue
120 int test8 = test_8GH50320_b[0];