Adding tests for -ast-dump; NFC.
authorAaron Ballman <aaron@aaronballman.com>
Fri, 30 Nov 2018 17:19:06 +0000 (17:19 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Fri, 30 Nov 2018 17:19:06 +0000 (17:19 +0000)
This adds tests for GenericSelectionExpr; note that it points out a minor whitespace bug for selection expression cases.

llvm-svn: 348008

clang/test/Misc/ast-dump-stmt.c

index 4618931..fe90fa6 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-dump -ast-dump-filter Test %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -std=c11 -ast-dump -ast-dump-filter Test %s | FileCheck -strict-whitespace %s
 
 int TestLocation = 0;
 // CHECK:      VarDecl{{.*}}TestLocation
@@ -65,3 +65,64 @@ void TestUnaryOperatorExpr(void) {
   // CHECK-NEXT:     ImplicitCastExpr\r
   // CHECK-NEXT:       DeclRefExpr{{.*}}'T2' 'int'\r
 }\r
+\r
+void TestGenericSelectionExpressions(int i) {\r
+  _Generic(i, int : 12);\r
+  // CHECK: GenericSelectionExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:23> 'int'\r
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}\r
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // FIXME: note that the following test line has a spurious whitespace.\r
+  // CHECK-NEXT: case  'int' selected\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:21> 'int' 12\r
+  _Generic(i, int : 12, default : 0);\r
+  // CHECK: GenericSelectionExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:36> 'int'\r
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}\r
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // FIXME: note that the following test line has a spurious whitespace.\r
+  // CHECK-NEXT: case  'int' selected\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:21> 'int' 12\r
+  // CHECK-NEXT: default\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:35> 'int' 0\r
+  _Generic(i, default : 0, int : 12);\r
+  // CHECK: GenericSelectionExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:36> 'int'\r
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}\r
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // CHECK-NEXT: default\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:25> 'int' 0\r
+  // FIXME: note that the following test line has a spurious whitespace.\r
+  // CHECK-NEXT: case  'int' selected\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:34> 'int' 12\r
+  _Generic(i, int : 12, float : 10, default : 100);\r
+  // CHECK: GenericSelectionExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:50> 'int'\r
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}\r
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // FIXME: note that the following test line has a spurious whitespace.\r
+  // CHECK-NEXT: case  'int' selected\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:21> 'int' 12\r
+  // FIXME: note that the following test line has a spurious whitespace.\r
+  // CHECK-NEXT: case  'float'\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'float'\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:33> 'int' 10\r
+  // CHECK-NEXT: default\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:47> 'int' 100\r
+\r
+  int j = _Generic(i, int : 12);\r
+  // CHECK: DeclStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:32>\r
+  // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:3, col:31> col:7 j 'int' cinit\r
+  // CHECK-NEXT: GenericSelectionExpr 0x{{[^ ]*}} <col:11, col:31> 'int'\r
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}\r
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:20> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // FIXME: note that the following test line has a spurious whitespace.\r
+  // CHECK-NEXT: case  'int' selected\r
+  // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'\r
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:29> 'int' 12\r
+}\r