-
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 by leveraging the `cir.scope` operation return value and aggregate copies. This does not implement the full semantics of statement expressions. ghstack-source-id: 59cb541c953907bfa4c645e5f9ec8ac36908fd46 Pull Request resolved: #314
- Loading branch information
1 parent
e8d283e
commit 44d42d5
Showing
5 changed files
with
106 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir-enable -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 l-value. | ||
void test2(int x) { ({ x;}); } | ||
// CHECK: @test2 | ||
// CHECK: %{{.+}} = cir.scope { | ||
// CHECK: %[[#V6:]] = cir.alloca !s32i, cir.ptr <!s32i>, ["tmp"] | ||
// CHECK: %[[#V7:]] = cir.load %{{.+}} : cir.ptr <!s32i>, !s32i | ||
// CHECK: cir.store %[[#V7]], %[[#V6]] : !s32i, cir.ptr <!s32i> | ||
// CHECK: cir.yield %[[#V6]] : !cir.ptr<!s32i> | ||
// CHECK: } | ||
|
||
// Yields an aggregate. | ||
struct S { int x; }; | ||
void test4() { ({ struct S s = {1}; s; }); } | ||
// CHECK: @test4 | ||
// CHECK: %[[#RET:]] = 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 %[[#RET]] : !cir.ptr<!ty_22S22> | ||
// CHECK: } | ||
|
||
// TODO(cir): Missing label support. | ||
// // Expression is wrapped in a label. | ||
// // void test5(int x) { x = ({ label: x; }); } | ||
|
||
// TODO(cir): Can't think of an example for this. | ||
// // Expression is wrapped in an expression attribute. |