File tree Expand file tree Collapse file tree 4 files changed +74
-0
lines changed
Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,34 @@ void test5() {
3838struct MMX_t {};
3939void 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+
4169namespace GH48405 {
4270void foo () {
4371 struct S {
You can’t perform that action at this time.
0 commit comments