Skip to content

Commit 3b01f31

Browse files
committed
Add back testcases with updated checks
1 parent 91c2333 commit 3b01f31

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,14 @@ void TestMiscStmts(void) {
399399
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:13> 'int' 10
400400
// CHECK-NEXT: ImplicitCastExpr
401401
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:17> 'int' lvalue Var 0x{{[^ ]*}} 'a' 'int'
402+
({int a = 10; a;;; });
403+
// CHECK-NEXT: StmtExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:23> 'void'
404+
// CHECK-NEXT: CompoundStmt
405+
// CHECK-NEXT: DeclStmt
406+
// CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:5, col:13> col:9 used a 'int' cinit
407+
// CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:13> 'int' 10
408+
// CHECK-NEXT: ImplicitCastExpr
409+
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:17> 'int' lvalue Var 0x{{[^ ]*}} 'a' 'int'
410+
// CHECK-NEXT: NullStmt
411+
// CHECK-NEXT: NullStmt
402412
}

clang/test/CodeGen/exprs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,20 @@ void f18(void) {
193193
}
194194
// CHECK-LABEL: define{{.*}} void @f18()
195195
// CHECK: call i32 @returns_int()
196+
197+
// Ensure the right stmt is returned
198+
int f19(void) {
199+
return ({ 3;;4; });
200+
}
201+
// CHECK-LABEL: define{{.*}} i32 @f19()
202+
// CHECK: [[T:%.*]] = alloca i32
203+
// CHECK: store i32 4, ptr [[T]]
204+
// CHECK: [[L:%.*]] = load i32, ptr [[T]]
205+
// CHECK: ret i32 [[L]]
206+
207+
// PR166036: The trailing NullStmt should result in a void.
208+
void f20(void) {
209+
return ({ 3;;4;; });
210+
}
211+
// CHECK-LABEL: define{{.*}} void @f20()
212+
// CHECK: ret void

clang/test/Sema/statements.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,22 @@ void test_pr22849(void) {
118118
SIZE = sizeof(({unsigned long __ptr; __ptr;}))
119119
};
120120
}
121+
122+
// Empty statements at the end of compound expressions have a result type 'void'.
123+
void test13(void) {
124+
int a;
125+
a = ({ 1; });
126+
a = ({ 1; 2; }); // expected-warning {{expression result unused}}
127+
a = ({ 1;; }); // expected-error {{assigning to 'int' from incompatible type 'void'}}
128+
// expected-warning@-1 {{expression result unused}}
129+
a = ({int x = 1; (void)x; }); // expected-error {{assigning to 'int' from incompatible type 'void'}}
130+
a = ({int x = 1;; }); // expected-error {{assigning to 'int' from incompatible type 'void'}}
131+
}
132+
133+
void test14(void) { return ({}); }
134+
void test15(void) {
135+
return ({;;;; });
136+
}
137+
void test16(void) {
138+
return ({test:;; });
139+
}

clang/test/SemaCXX/statements.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ void test5() {
3838
struct MMX_t {};
3939
void test6() { __asm__("" : "=m"(*(MMX_t *)0)); }
4040

41+
template <typename T>
42+
T test7(T v) {
43+
return ({ // expected-warning{{use of GNU statement expression extension}}
44+
T a = v;
45+
a;
46+
});
47+
}
48+
49+
void test8() {
50+
int a = test7(1);
51+
double b = test7(2.0);
52+
}
53+
54+
template <typename T>
55+
T test9(T v) {
56+
return ({ // expected-warning {{use of GNU statement expression extension}}
57+
T a = v;
58+
a; // expected-warning {{expression result unused}}
59+
;
60+
;
61+
});
62+
}
63+
64+
void test10() {
65+
int a = test9(1); // expected-note {{in instantiation of function template specialization 'test9<int>' requested here}}
66+
// expected-error@-10 {{cannot initialize return object of type 'int' with an rvalue of type 'void'}}
67+
}
68+
4169
namespace GH48405 {
4270
void foo() {
4371
struct S {

0 commit comments

Comments
 (0)