-// RUN: %clang_cc1 -std=c11 -ast-dump -ast-dump-filter Test %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -std=gnu11 -ast-dump %s | FileCheck -strict-whitespace %s
int TestLocation = 0;
// CHECK: VarDecl{{.*}}TestLocation
int TestIndent = 1 + (1);
// CHECK: VarDecl{{.*}}TestIndent
-// CHECK-NEXT: {{^}}`-BinaryOperator{{[^()]*$}}
-// CHECK-NEXT: {{^}} |-IntegerLiteral{{.*0[^()]*$}}
-// CHECK-NEXT: {{^}} `-ParenExpr{{.*0[^()]*$}}
-// CHECK-NEXT: {{^}} `-IntegerLiteral{{.*0[^()]*$}}
+// CHECK-NEXT: {{^}}| `-BinaryOperator{{[^()]*$}}
+// CHECK-NEXT: {{^}}| |-IntegerLiteral{{.*0[^()]*$}}
+// CHECK-NEXT: {{^}}| `-ParenExpr{{.*0[^()]*$}}
+// CHECK-NEXT: {{^}}| `-IntegerLiteral{{.*0[^()]*$}}
void TestDeclStmt() {
int x = 0;
// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:29> 'int' 12\r
}\r
+\r
+void TestLabelsAndGoto(void) {\r
+ // Note: case and default labels are handled by TestSwitch().\r
+\r
+label1:\r
+ ;\r
+ // CHECK: LabelStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:1, line:[[@LINE-1]]:3> 'label1'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <col:3>\r
+\r
+ goto label2;\r
+ // CHECK-NEXT: GotoStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:8> 'label2' 0x{{[^ ]*}}\r
+\r
+label2:\r
+ 0;\r
+ // CHECK-NEXT: LabelStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:1, line:[[@LINE-1]]:3> 'label2'\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:3> 'int' 0\r
+\r
+ void *ptr = &&label1;\r
+ // CHECK-NEXT: DeclStmt\r
+ // CHECK-NEXT: VarDecl\r
+ // CHECK-NEXT: AddrLabelExpr 0x{{[^ ]*}} <col:15, col:17> 'void *' label1 0x{{[^ ]*}}\r
+\r
+ goto *ptr;\r
+ // CHECK-NEXT: IndirectGotoStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:9>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:9> 'void *' lvalue Var 0x{{[^ ]*}} 'ptr' 'void *'\r
+}\r
+\r
+void TestSwitch(int i) {\r
+ switch (i) {\r
+ // CHECK: SwitchStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, line:[[@LINE+32]]:3>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:11> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'\r
+ // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:14, line:[[@LINE+29]]:3>\r
+ case 0:\r
+ break;\r
+ // CHECK-NEXT: CaseStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: ConstantExpr\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:8> 'int' 0\r
+ // CHECK-NEXT: BreakStmt 0x{{[^ ]*}} <line:[[@LINE-4]]:5>\r
+ case 1:\r
+ case 2:\r
+ break;\r
+ // CHECK-NEXT: CaseStmt 0x{{[^ ]*}} <line:[[@LINE-3]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: ConstantExpr\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:8> 'int' 1\r
+ // CHECK-NEXT: CaseStmt 0x{{[^ ]*}} <line:[[@LINE-5]]:3, line:[[@LINE-4]]:5>\r
+ // CHECK-NEXT: ConstantExpr\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:8> 'int' 2\r
+ // CHECK-NEXT: BreakStmt 0x{{[^ ]*}} <line:[[@LINE-7]]:5>\r
+ default:\r
+ break;\r
+ // CHECK-NEXT: DefaultStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: BreakStmt 0x{{[^ ]*}} <col:5>\r
+ case 3 ... 5:\r
+ break;\r
+ // CHECK-NEXT: CaseStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5> gnu_range\r
+ // CHECK-NEXT: ConstantExpr\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:8> 'int' 3\r
+ // CHECK-NEXT: ConstantExpr\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:14> 'int' 5\r
+ // CHECK-NEXT: BreakStmt 0x{{[^ ]*}} <line:[[@LINE-6]]:5>\r
+ }\r
+}\r
+\r
+void TestIf(_Bool b) {\r
+ if (b)\r
+ ;\r
+ // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:7> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt\r
+\r
+ if (b) {}\r
+ // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:11>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:7> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: CompoundStmt\r
+\r
+ if (b)\r
+ ;\r
+ else\r
+ ;\r
+ // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-4]]:3, line:[[@LINE-1]]:5> has_else\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:7> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-6]]:5>\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-5]]:5>\r
+\r
+ if (b) {}\r
+ else {}\r
+ // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:9> has_else\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:7> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <col:10, col:11>\r
+ // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} <line:[[@LINE-5]]:8, col:9>\r
+\r
+ if (b)\r
+ ;\r
+ else if (b)\r
+ ;\r
+ // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-4]]:3, line:[[@LINE-1]]:5> has_else\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:7> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-6]]:5>\r
+ // CHECK-NEXT: IfStmt 0x{{[^ ]*}} <line:[[@LINE-6]]:8, line:[[@LINE-5]]:5>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-8]]:5>\r
+\r
+ if (b)\r
+ ;\r
+ else if (b)\r
+ ;\r
+ else\r
+ ;\r
+ // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-6]]:3, line:[[@LINE-1]]:5> has_else\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:7> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-8]]:5>\r
+ // CHECK-NEXT: IfStmt 0x{{[^ ]*}} <line:[[@LINE-8]]:8, line:[[@LINE-5]]:5> has_else\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-10]]:5>\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-9]]:5>\r
+}\r
+\r
+void TestIteration(_Bool b) {\r
+ while (b)\r
+ ;\r
+ // CHECK: WhileStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-4]]:5>\r
+\r
+ do\r
+ ;\r
+ while (b);\r
+ // CHECK: DoStmt 0x{{[^ ]*}} <line:[[@LINE-3]]:3, line:[[@LINE-1]]:11>\r
+ // CHECK-NEXT: NullStmt 0x{{[^ ]*}} <line:[[@LINE-3]]:5>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+\r
+ for (int i = 0; i < 10; ++i)\r
+ ;\r
+ // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: DeclStmt\r
+ // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:16> col:12 used i 'int' cinit\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:16> 'int' 0\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:19, col:23> 'int' '<'\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:19> 'int' lvalue Var 0x{{[^ ]*}} 'i' 'int'\r
+ // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:23> 'int' 10\r
+ // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:27, col:29> 'int' prefix '++'\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:29> 'int' lvalue Var 0x{{[^ ]*}} 'i' 'int'\r
+ // CHECK-NEXT: NullStmt\r
+\r
+ for (b; b; b)\r
+ ;\r
+ // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:8> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:11> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt\r
+\r
+ for (; b; b = !b)\r
+ ;\r
+ // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:13, col:18> '_Bool' '='\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:13> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:17, col:18> 'int' prefix '!' cannot overflow\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:18> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt\r
+\r
+ for (; b;)\r
+ ;\r
+ // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:10> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: NullStmt\r
+\r
+ for (;; b = !b)\r
+ ;\r
+ // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <line:[[@LINE-6]]:11, col:16> '_Bool' '='\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:11> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:15, col:16> 'int' prefix '!' cannot overflow\r
+ // CHECK-NEXT: ImplicitCastExpr\r
+ // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> '_Bool' lvalue ParmVar 0x{{[^ ]*}} 'b' '_Bool'\r
+ // CHECK-NEXT: NullStmt\r
+\r
+ for (;;)\r
+ ;\r
+ // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: <<<NULL>>>\r
+ // CHECK-NEXT: NullStmt\r
+}\r
+\r
+void TestJumps(void) {\r
+ // goto and computed goto was tested in TestLabelsAndGoto().\r
+\r
+ while (1) {\r
+ continue;\r
+ // CHECK: ContinueStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:5>\r
+ break;\r
+ // CHECK: BreakStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:5>\r
+ }\r
+ return;\r
+ // CHECK: ReturnStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3>\r
+\r
+ return TestSwitch(1);\r
+ // CHECK: ReturnStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:22>\r
+ // CHECK-NEXT: CallExpr 0x{{[^ ]*}} <col:10, col:22> 'void'\r
+}\r