-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR][CIRGen] Partially support statement expressions return values
Adds support for GCC statement expressions return values as well as StmtExpr LValue emissions. To simplify the lowering process, the scope return value is not used. Instead, a temporary allocation is created on the parent scope where the return value is stored. For classes, a second scope is created around this temporary allocation to ensure any destructors are called. This does not implement the full semantics of statement expressions. ghstack-source-id: 64e03fc3df45975590ddbcab44959c2b49601101 Pull Request resolved: #314
- Loading branch information
1 parent
e18afb3
commit 88b01cb
Showing
10 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
// Yields void. | ||
void test1() { ({ }); } | ||
// CHECK: @test1 | ||
// CHECK: cir.scope { | ||
// CHECK-NOT: cir.yield | ||
// CHECK: } | ||
|
||
// Yields an out-of-scope scalar. | ||
void test2() { ({int x = 3; x; }); } | ||
// CHECK: @test2 | ||
// CHECK: %[[#RETVAL:]] = cir.alloca !s32i, cir.ptr <!s32i> | ||
// CHECK: cir.scope { | ||
// CHECK: %[[#VAR:]] = cir.alloca !s32i, cir.ptr <!s32i>, ["x", init] | ||
// [...] | ||
// CHECK: %[[#TMP:]] = cir.load %[[#VAR]] : cir.ptr <!s32i>, !s32i | ||
// CHECK: cir.store %[[#TMP]], %[[#RETVAL]] : !s32i, cir.ptr <!s32i> | ||
// CHECK: } | ||
// CHECK: %{{.+}} = cir.load %[[#RETVAL]] : cir.ptr <!s32i>, !s32i | ||
|
||
// Yields an aggregate. | ||
struct S { int x; }; | ||
int test3() { return ({ struct S s = {1}; s; }).x; } | ||
// CHECK: @test3 | ||
// CHECK: %[[#RETVAL:]] = cir.alloca !ty_22S22, cir.ptr <!ty_22S22> | ||
// CHECK: cir.scope { | ||
// CHECK: %[[#VAR:]] = cir.alloca !ty_22S22, cir.ptr <!ty_22S22> | ||
// [...] | ||
// CHECK: cir.copy %[[#VAR]] to %[[#RETVAL]] : !cir.ptr<!ty_22S22> | ||
// CHECK: } | ||
// CHECK: %[[#RETADDR:]] = cir.get_member %1[0] {name = "x"} : !cir.ptr<!ty_22S22> -> !cir.ptr<!s32i> | ||
// CHECK: %{{.+}} = cir.load %[[#RETADDR]] : cir.ptr <!s32i>, !s32i | ||
|
||
// Expression is wrapped in an expression attribute (just ensure it does not crash). | ||
void test4(int x) { ({[[gsl::suppress("foo")]] x;}); } | ||
// CHECK: @test4 | ||
|
||
// TODO(cir): Missing label support. | ||
// // Expression is wrapped in a label. | ||
// // void test5(int x) { x = ({ label: x; }); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
class A { | ||
public: | ||
A(): x(0) {} | ||
A(A &a) : x(a.x) {} | ||
// TODO(cir): Ensure dtors are properly called. The dtor below crashes. | ||
// ~A() {} | ||
int x; | ||
void Foo() {} | ||
}; | ||
|
||
void test1() { | ||
({ | ||
A a; | ||
a; | ||
}).Foo(); | ||
} | ||
// CHECK: @_Z5test1v | ||
// CHECK: cir.scope { | ||
// CHECK: %[[#RETVAL:]] = cir.alloca !ty_22A22, cir.ptr <!ty_22A22> | ||
// CHECK: cir.scope { | ||
// CHECK: %[[#VAR:]] = cir.alloca !ty_22A22, cir.ptr <!ty_22A22>, ["a", init] {alignment = 4 : i64} | ||
// CHECK: cir.call @_ZN1AC1Ev(%[[#VAR]]) : (!cir.ptr<!ty_22A22>) -> () | ||
// CHECK: cir.call @_ZN1AC1ERS_(%[[#RETVAL]], %[[#VAR]]) : (!cir.ptr<!ty_22A22>, !cir.ptr<!ty_22A22>) -> () | ||
// TODO(cir): the local VAR should be destroyed here. | ||
// CHECK: } | ||
// CHECK: cir.call @_ZN1A3FooEv(%[[#RETVAL]]) : (!cir.ptr<!ty_22A22>) -> () | ||
// TODO(cir): the temporary RETVAL should be destroyed here. | ||
// CHECK: } |