[clang] [CIR] Don't store the result of a call returning an empty record (PR #245084)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 22 14:05:27 PST 2026
https://github.com/mmha created https://github.com/llvm/llvm-project/pull/245084
ClangIR could overwrite the member next to a `[[no_unique_address]]` member or an empty base when it initialized that subobject from a call returning an empty record. For
```c++
struct E {};
E make();
struct T { char x; [[no_unique_address]] E e; };
int f() { T t{42, make()}; return t.x; }
```
the ClangIR path returned garbage instead of 42 at -O1 and -O2.
An empty record holds no data, but the destination of the call can share its storage with other data. A `[[no_unique_address]]` member or an empty base is a potentially-overlapping subobject, which may have zero size and the address of another member. ClangIR stored the whole returned record into the destination. x86-64 ignores an empty record return, so the ABI lowering turned the stored value into poison, and the store destroyed the byte of the member that shares the storage.
Classic codegen omits the store of an empty record's call result. Do the same in the ABI lowering, where the return classification is known. When the return is ignored, erase the stores of the call result.
Assisted-By: Claude Opus 5.5 + GPT-6.2 Sol as reviewer
>From 72c08eee8c1e2a8d1e63c16caa4fd80515ed4565 Mon Sep 17 00:00:00 2001
From: Morris Hafner <mhafner at nvidia.com>
Date: Thu, 19 Nov 2026 18:19:10 +0000
Subject: [PATCH] [CIR] Don't store the result of a call returning an empty
record
ClangIR could overwrite the member next to a [[no_unique_address]]
member or an empty base when it initialized that subobject from a call
returning an empty record. For
struct E {};
E make();
struct T { char x; [[no_unique_address]] E e; };
int f() { T t{42, make()}; return t.x; }
the ClangIR build returned garbage instead of 42 at -O1 and -O2.
An empty record holds no data, but the destination of the call can
share its storage with other data. A [[no_unique_address]] member or an
empty base is a potentially-overlapping subobject, which may have zero
size and the address of another member (C++20 [intro.object]p8-9,
N4861 6.7.2). ClangIR stored the whole returned record into the
destination. x86-64 ignores an empty record return, so the ABI lowering
turned the stored value into poison, and the store destroyed the byte
of the member that shares the storage.
Classic codegen omits the store of an empty record's call result
(CGCall.cpp, "An empty record can overlap other data"). Do the same in
the ABI lowering, where the return classification is known: when the
return is ignored, erase the stores of the call result. A return in
memory keeps its store, because the lowering uses the store's
destination as the sret slot the callee constructs into. An
over-aligned empty record, which x86-64 returns in memory, is such a
case, and the test covers it.
Found by the Perennial C++ validation suite, where the empty object had
a byte of its own, so the overwritten byte was unused, and reduced to
the example above.
---
.../TargetLowering/CIRABIRewriteContext.cpp | 14 ++++--
.../call-conv-lowering-x86_64-empty.cpp | 47 +++++++++++++++++++
.../CodeGen/cxx-rewritten-binary-operator.cpp | 10 ----
.../test/CIR/CodeGenCoroutines/coro-task.cpp | 40 +---------------
.../abi-lowering/x86_64-empty-class.cir | 8 ++--
5 files changed, 63 insertions(+), 56 deletions(-)
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
index 4b826f4ddb7545..9b20a6c5c9f877 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
@@ -2500,10 +2500,16 @@ CIRABIRewriteContext::rewriteCallSite(mlir::Operation *callOp,
}
if (hasResult && fc.returnInfo.kind == ArgKind::Ignore) {
- // The new call returns void, but the original call's result may still
- // have uses. Substitute a poison constant of the original type so
- // those uses remain well-formed without pretending we have a real
- // value at the ABI boundary.
+ // An ignored result holds no data (an empty record), but its destination
+ // can share storage with other data: a [[no_unique_address]] member or an
+ // empty base may be laid out over another member. Storing the result
+ // would clobber that member, so drop the stores, like classic codegen
+ // ("An empty record can overlap other data" in CGCall.cpp).
+ for (mlir::Operation *user :
+ llvm::make_early_inc_range(call.getResult().getUsers()))
+ if (auto store = mlir::dyn_cast<cir::StoreOp>(user);
+ store && store.getValue() == call.getResult())
+ store->erase();
if (!call.getResult().use_empty()) {
builder.setInsertionPointAfter(newCall);
mlir::Value poison =
diff --git a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp
index e8ed80181c81e4..6a478deba3d038 100644
--- a/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp
+++ b/clang/test/CIR/CodeGen/call-conv-lowering-x86_64-empty.cpp
@@ -543,3 +543,50 @@ int caller(int k) {
// CIR: cir.call @_Z9takeEmpty5Emptyi(%{{[0-9]+}}) : (!s32i {llvm.noundef}) -> (!s32i {llvm.noundef})
// LLVM: define dso_local noundef i32 @_Z6calleri(i32 noundef %{{[^,]+}})
// LLVM: call noundef i32 @_Z9takeEmpty5Emptyi(i32 noundef %{{[^,]+}})
+
+Empty makeEmpty();
+struct NuaHolder { char x; [[no_unique_address]] Empty e; };
+static_assert(sizeof(NuaHolder) == 1);
+
+int initNuaHolder() {
+ NuaHolder h{42, makeEmpty()};
+ return h.x;
+}
+
+// CIR: cir.func {{.*}}@_Z13initNuaHolderv()
+// CIR: cir.store {{.*}} : !s8i, !cir.ptr<!s8i>
+// CIR: cir.call @_Z9makeEmptyv() : () -> ()
+// CIR-NOT: cir.store
+// CIR: cir.load {{.*}} : !cir.ptr<!s8i>, !s8i
+// LLVM: define dso_local noundef i32 @_Z13initNuaHolderv()
+// LLVM: store i8 42, ptr %{{.+}}
+// LLVM: call void @_Z9makeEmptyv()
+// LLVM-NOT: store
+// LLVM: load i8, ptr %{{.+}}
+
+struct NonTrivialEmpty {
+ NonTrivialEmpty();
+ NonTrivialEmpty(const NonTrivialEmpty &);
+};
+NonTrivialEmpty makeNonTrivialEmpty();
+void initNonTrivialEmpty() { NonTrivialEmpty n = makeNonTrivialEmpty(); }
+
+// LLVM: define dso_local void @_Z19initNonTrivialEmptyv()
+// LLVM: %[[N:.+]] = alloca %struct.NonTrivialEmpty
+// LLVM: call void @_Z19makeNonTrivialEmptyv(ptr {{.*}}sret(%struct.NonTrivialEmpty) {{.*}}%[[N]])
+
+struct alignas(128) [[clang::trivial_abi]] AlignedEmpty {
+ AlignedEmpty();
+ ~AlignedEmpty();
+};
+AlignedEmpty makeAlignedEmpty();
+void initAlignedEmpty() { AlignedEmpty a = makeAlignedEmpty(); }
+
+// CIR: cir.func {{.*}}@_Z16initAlignedEmptyv()
+// CIR: %[[A:.+]] = cir.alloca "a"
+// CIR: cir.call @_Z16makeAlignedEmptyv(%[[A]])
+// CIR: cir.call @_ZN12AlignedEmptyD1Ev(%[[A]])
+// LLVM: define dso_local void @_Z16initAlignedEmptyv()
+// LLVM: %[[A:.+]] = alloca %struct.AlignedEmpty, align 128
+// LLVM: call void @_Z16makeAlignedEmptyv(ptr {{.*}}sret(%struct.AlignedEmpty) align 128 %[[A]])
+// LLVM: call void @_ZN12AlignedEmptyD1Ev(ptr {{.*}}%[[A]])
diff --git a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp
index 5115b6fc540e8a..2b40125672a152 100644
--- a/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp
+++ b/clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp
@@ -57,8 +57,6 @@ void cxx_rewritten_binary_operator_complex_expr() {
// CIR: %[[R_ADDR:.*]] = cir.alloca "r" {{.*}} init : !cir.ptr<!cir.complex<!s32i>>
// CIR: %[[TMP_ADDR:.*]] = cir.alloca "ref.tmp0" {{.*}} : !cir.ptr<!rec_SpaceshipComplexResult>
// CIR: cir.call @_ZNK11ComplexItemssERKS_(%[[A_ADDR]], %[[B_ADDR]]) : (!cir.ptr<!rec_ComplexItem> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !cir.ptr<!rec_ComplexItem> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}) -> ()
-// CIR: %[[POISON:.*]] = cir.const #cir.poison : !rec_SpaceshipComplexResult
-// CIR: cir.store {{.*}} %[[POISON]], %[[TMP_ADDR]] : !rec_SpaceshipComplexResult, !cir.ptr<!rec_SpaceshipComplexResult>
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
// CIR: %[[RESULT:.*]] = cir.call @_ZNK22SpaceshipComplexResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipComplexResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> (!u64i {llvm.noundef})
// CIR: cir.store %[[RESULT]], %[[R_SLOT:.*]] : !u64i, !cir.ptr<!u64i>
@@ -116,8 +114,6 @@ void cxx_rewritten_binary_operator_aggr_expr() {
// CIR: %[[R_ADDR:.*]] = cir.alloca "r" {{.*}} init : !cir.ptr<!rec_Result>
// CIR: %[[TMP_ADDR:.*]] = cir.alloca "ref.tmp0" {{.*}} : !cir.ptr<!rec_SpaceshipResult>
// CIR: cir.call @_ZNK4ItemssERKS_(%[[A_ADDR]], %[[B_ADDR]]) : (!cir.ptr<!rec_Item> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !cir.ptr<!rec_Item> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}) -> ()
-// CIR: %[[OP_RESULT:.*]] = cir.const #cir.poison : !rec_SpaceshipResult
-// CIR: cir.store {{.*}} %[[OP_RESULT]], %[[TMP_ADDR]] : !rec_SpaceshipResult, !cir.ptr<!rec_SpaceshipResult>
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
// CIR: %[[RESULT:.*]] = cir.call @_ZNK15SpaceshipResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> !s32i
// CIR: cir.store %[[RESULT]], %[[R_SLOT:.*]] : !s32i, !cir.ptr<!s32i>
@@ -129,7 +125,6 @@ void cxx_rewritten_binary_operator_aggr_expr() {
// LLVM: %[[R_ADDR:.*]] = alloca %struct.Result, align 4
// LLVM: %[[TMP_ADDR:.*]] = alloca %struct.SpaceshipResult, align 1
// LLVM: call void @_ZNK4ItemssERKS_(ptr noundef nonnull align 1 dereferenceable(1) %[[A_ADDR]], ptr noundef nonnull align 1 dereferenceable(1) %[[B_ADDR]])
-// LLVM: store %struct.SpaceshipResult poison, ptr %[[TMP_ADDR]], align 1
// LLVM: %[[RESULT:.*]] = call i32 @_ZNK15SpaceshipResultltEi(ptr noundef nonnull align 1 dereferenceable(1) %[[TMP_ADDR]], i32 noundef 0)
// LLVM: store i32 %[[RESULT]], ptr %[[R_SLOT:.*]], align 4
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[R_ADDR]], ptr align 4 %[[R_SLOT]], i64 4, i1 false)
@@ -162,9 +157,6 @@ void cxx_rewritten_binary_operator_lvalue_expr() {
// CIR: %[[REF_ADDR:.*]] = cir.alloca "ref" {{.*}} init const : !cir.ptr<!cir.ptr<!s32i>>
// CIR: %[[TMP_ADDR:.*]] = cir.alloca "ref.tmp0" {{.*}} : !cir.ptr<!rec_SpaceshipLValueResult>
// CIR: cir.call @_ZNK10LValueItemssERKS_(%[[A_ADDR]], %[[B_ADDR]]) : (!cir.ptr<!rec_LValueItem> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !cir.ptr<!rec_LValueItem> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}) -> ()
-// FIXME: CIR stores a poison aggregate into the temporary due to empty-record-return behavior; OGCG omits this store.
-// CIR: %[[OP_RESULT:.*]] = cir.const #cir.poison : !rec_SpaceshipLValueResult
-// CIR: cir.store {{.*}} %[[OP_RESULT]], %[[TMP_ADDR]] : !rec_SpaceshipLValueResult, !cir.ptr<!rec_SpaceshipLValueResult>
// CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
// CIR: %[[RESULT:.*]] = cir.call @_ZNK21SpaceshipLValueResultltEi(%[[TMP_ADDR]], %[[CONST_0]]) : (!cir.ptr<!rec_SpaceshipLValueResult> {llvm.align = 1 : i64, llvm.dereferenceable = 1 : i64, llvm.nonnull, llvm.noundef}, !s32i {llvm.noundef}) -> (!cir.ptr<!s32i> {llvm.align = 4 : i64, llvm.dereferenceable = 4 : i64, llvm.nonnull, llvm.noundef})
// CIR: cir.store {{.*}} %[[RESULT]], %[[REF_ADDR]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
@@ -174,8 +166,6 @@ void cxx_rewritten_binary_operator_lvalue_expr() {
// LLVM: %[[REF_ADDR:.*]] = alloca ptr, align 8
// LLVM: %[[TMP_ADDR:.*]] = alloca %struct.SpaceshipLValueResult, align 1
// LLVM: call void @_ZNK10LValueItemssERKS_(ptr noundef nonnull align 1 dereferenceable(1) %[[A_ADDR]], ptr noundef nonnull align 1 dereferenceable(1) %[[B_ADDR]])
-// FIXME: CIR stores a poison aggregate into the temporary due to empty-record-return behavior; OGCG omits this store.
-// LLVM: store %struct.SpaceshipLValueResult poison, ptr %[[TMP_ADDR]], align 1
// LLVM: %[[RESULT:.*]] = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK21SpaceshipLValueResultltEi(ptr noundef nonnull align 1 dereferenceable(1) %[[TMP_ADDR]], i32 noundef 0)
// LLVM: store ptr %[[RESULT]], ptr %[[REF_ADDR]], align 8
diff --git a/clang/test/CIR/CodeGenCoroutines/coro-task.cpp b/clang/test/CIR/CodeGenCoroutines/coro-task.cpp
index f45d8c9ef69805..c84715f03fe499 100644
--- a/clang/test/CIR/CodeGenCoroutines/coro-task.cpp
+++ b/clang/test/CIR/CodeGenCoroutines/coro-task.cpp
@@ -105,17 +105,12 @@ VoidTask silly_task() {
// Call promise.get_return_object() to retrieve the task object.
-// Empty records are ignored, so calls returning one return nothing and the
-// slot takes a poison placeholder.
-
// CIR: cir.coroutine initialSuspend : {
// CIR: cir.call @_ZN5folly4coro4TaskIvE12promise_type17get_return_objectEv(%[[VoidPromisseAddr]]) nothrow : {{.*}} -> ()
-// CIR: %[[RetObj:.*]] = cir.const #cir.poison : ![[VoidTask]]
-// CIR: cir.store{{.*}} %[[RetObj]], %[[VoidTaskAddr]] : ![[VoidTask]]
+// CIR-NOT: cir.store{{.*}} : ![[VoidTask]]
// LLVM: call void @_ZN5folly4coro4TaskIvE12promise_type17get_return_objectEv(ptr noundef nonnull align 1 dereferenceable(1) %[[VoidPromisseAddr]])
-// LLVM: store %[[VoidTask]] poison, ptr %[[VoidTaskAddr]]
// OGCG: call void @llvm.lifetime.start.p0(ptr %[[VoidPromisseAddr]])
// OGCG: call void @_ZN5folly4coro4TaskIvE12promise_type17get_return_objectEv(ptr noundef nonnull align 1 dereferenceable(1) %[[VoidPromisseAddr]])
@@ -128,11 +123,8 @@ VoidTask silly_task() {
// the suspend_always struct to use for cir.await.
// CIR: cir.call @_ZN5folly4coro4TaskIvE12promise_type15initial_suspendEv(%[[VoidPromisseAddr]])
-// CIR: %[[Tmp0:.*]] = cir.const #cir.poison : ![[SuspendAlways]]
-// CIR: cir.store{{.*}} %[[Tmp0]], %[[SuspendAlwaysAddr]]
// LLVM: call void @_ZN5folly4coro4TaskIvE12promise_type15initial_suspendEv(ptr noundef nonnull align 1 dereferenceable(1) %[[VoidPromisseAddr]])
-// LLVM: store %[[SuspendAlways]] poison, ptr %[[SuspendAlwaysAddr]]
// OGCG: call void @_ZN5folly4coro4TaskIvE12promise_type15initial_suspendEv(ptr noundef nonnull align 1 dereferenceable(1) %[[VoidPromisseAddr]])
@@ -165,8 +157,6 @@ VoidTask silly_task() {
// CIR-NEXT: }, suspend : {
// CIR-NEXT: cir.call @_ZNSt16coroutine_handleIN5folly4coro4TaskIvE12promise_typeEE12from_addressEPv(%[[CoroFrameAddr]])
-// CIR-NEXT: %[[FromAddrRes:.*]] = cir.const #cir.poison : ![[CoroHandlePromiseVoid]]
-// CIR-NEXT: cir.store{{.*}} %[[FromAddrRes]], %[[CoroHandlePromiseAddr]] : ![[CoroHandlePromiseVoid]]
// CIR-NEXT: %[[CoroHandlePromiseReload:.*]] = cir.load{{.*}} %[[CoroHandlePromiseAddr]]
// CIR-NEXT: cir.call @_ZNSt16coroutine_handleIvEC1IN5folly4coro4TaskIvE12promise_typeEEES_IT_E(%[[CoroHandleVoidAddr]])
// CIR-NEXT: %[[CoroHandleVoidReload:.*]] = cir.load{{.*}} %[[CoroHandleVoidAddr]] : !cir.ptr<![[CoroHandleVoid]]>, ![[CoroHandleVoid]]
@@ -494,18 +484,12 @@ folly::coro::Task<int> byRef(const std::string& s) {
// CIR: cir.coroutine initialSuspend : {
// CIR: cir.call @_ZN5folly4coro4TaskIiE12promise_type17get_return_objectEv(%[[IntPromisseAddr]]) nothrow : {{.*}} -> ()
-// CIR: %[[RetObj:.*]] = cir.const #cir.poison : ![[IntTask]]
-// CIR: cir.store {{.*}} %[[RetObj]], %[[IntTaskAddr]] : ![[IntTask]]
// CIR: cir.call @_ZN5folly4coro4TaskIiE12promise_type15initial_suspendEv(%[[IntPromisseAddr]])
-// CIR: %[[Tmp0:.*]] = cir.const #cir.poison : ![[SuspendAlways]]
-// CIR: cir.store{{.*}} %[[Tmp0]], %[[SuspendAlwaysAddr]]
// CIR: cir.await(init, ready : {
// CIR: %[[TmpCallRes:.*]] = cir.call @_ZNSt14suspend_always11await_readyEv(%[[SuspendAlwaysAddr]])
// CIR: cir.condition(%[[TmpCallRes]])
// CIR: }, suspend : {
// CIR: cir.call @_ZNSt16coroutine_handleIN5folly4coro4TaskIiE12promise_typeEE12from_addressEPv(%[[CoroFrameAddr:.*]])
-// CIR: %[[FromAddrRes:.*]] = cir.const #cir.poison : ![[CoroHandlePromiseInt]]
-// CIR: cir.store{{.*}} %[[FromAddrRes]], %[[CoroHandlePromiseAddr]] : ![[CoroHandlePromiseInt]]
// CIR: %[[CoroHandlePromiseReload:.*]] = cir.load{{.*}} %[[CoroHandlePromiseAddr]]
// CIR: cir.call @_ZNSt16coroutine_handleIvEC1IN5folly4coro4TaskIiE12promise_typeEEES_IT_E(%[[CoroHandleVoidAddr]])
// CIR: %[[CoroHandleVoidReload:.*]] = cir.load{{.*}} %[[CoroHandleVoidAddr]] : !cir.ptr<![[CoroHandleVoid]]>, ![[CoroHandleVoid]]
@@ -669,15 +653,11 @@ folly::coro::Task<void> yield1() {
// CIR: cir.coroutine initialSuspend : {
// initial_suspend + await(init)
// CIR: cir.call @_ZN5folly4coro4TaskIvE12promise_type15initial_suspendEv(%[[PROMISE]]){{.*}}
-// CIR: %[[INIT_SUSP:.*]] = cir.const #cir.poison : ![[SuspendAlways]]
-// CIR: cir.store{{.*}} %[[INIT_SUSP]], %[[SUSP0]]
// CIR: cir.await(init, ready : {
// CIR: %[[READY0:.*]] = cir.call @_ZNSt14suspend_always11await_readyEv(%[[SUSP0]]){{.*}}
// CIR: cir.condition(%[[READY0]])
// CIR: }, suspend : {
// CIR: cir.call @_ZNSt16coroutine_handleIN5folly4coro4TaskIvE12promise_typeEE12from_addressEPv(%{{.*}}){{.*}}
-// CIR: %[[FROMADDR0:.*]] = cir.const #cir.poison : ![[CoroHandlePromiseVoid]]
-// CIR: cir.store{{.*}} %[[FROMADDR0]], %[[CH_PROM0]]
// CIR: %[[PROM_RELOAD0:.*]] = cir.load{{.*}} %[[CH_PROM0]]
// CIR: cir.call @_ZNSt16coroutine_handleIvEC1IN5folly4coro4TaskIvE12promise_typeEEES_IT_E(%[[CH_VOID0]]){{.*}}
// CIR: %[[VOID_RELOAD0:.*]] = cir.load{{.*}} %[[CH_VOID0]]
@@ -692,19 +672,13 @@ folly::coro::Task<void> yield1() {
// yield_value + await(yield)
// CIR: }, body : {
// CIR: cir.call @_Z5yieldv(){{.*}}
-// CIR: %[[YIELD_TASK:.*]] = cir.const #cir.poison : ![[VoidTask]]
-// CIR: cir.store{{.*}} %[[YIELD_TASK]], %[[T_ADDR]]
// CIR: %[[AWAITER:.*]] = cir.load{{.*}} %[[AWAITER_COPY_ADDR]]
// CIR: cir.call @_ZN5folly4coro4TaskIvE12promise_type11yield_valueES2_(%[[PROMISE]]){{.*}}
-// CIR: %[[YIELD_SUSP:.*]] = cir.const #cir.poison : ![[SuspendAlways]]
-// CIR: cir.store{{.*}} %[[YIELD_SUSP]], %[[SUSP1]]
// CIR: cir.await(yield, ready : {
// CIR: %[[READY1:.*]] = cir.call @_ZNSt14suspend_always11await_readyEv(%[[SUSP1]]){{.*}}
// CIR: cir.condition(%[[READY1]])
// CIR: }, suspend : {
// CIR: cir.call @_ZNSt16coroutine_handleIN5folly4coro4TaskIvE12promise_typeEE12from_addressEPv(%{{.*}}){{.*}}
-// CIR: %[[FROMADDR1:.*]] = cir.const #cir.poison : ![[CoroHandlePromiseVoid]]
-// CIR: cir.store{{.*}} %[[FROMADDR1]], %[[CH_PROM1]]
// CIR: %[[PROM_RELOAD1:.*]] = cir.load{{.*}} %[[CH_PROM1]]
// CIR: cir.call @_ZNSt16coroutine_handleIvEC1IN5folly4coro4TaskIvE12promise_typeEEES_IT_E(%[[CH_VOID1]]){{.*}}
// CIR: %[[VOID_RELOAD1:.*]] = cir.load{{.*}} %[[CH_VOID1]]
@@ -720,15 +694,11 @@ folly::coro::Task<void> yield1() {
// return_void + await(final)
// CIR: cir.call @_ZN5folly4coro4TaskIvE12promise_type13final_suspendEv(%[[PROMISE]]){{.*}}
-// CIR: %[[FINAL_SUSP:.*]] = cir.const #cir.poison : ![[SuspendAlways]]
-// CIR: cir.store{{.*}} %[[FINAL_SUSP]], %[[SUSP2]]
// CIR: cir.await(final, ready : {
// CIR: %[[READY2:.*]] = cir.call @_ZNSt14suspend_always11await_readyEv(%[[SUSP2]]){{.*}}
// CIR: cir.condition(%[[READY2]])
// CIR: }, suspend : {
// CIR: cir.call @_ZNSt16coroutine_handleIN5folly4coro4TaskIvE12promise_typeEE12from_addressEPv(%{{.*}}){{.*}}
-// CIR: %[[FROMADDR2:.*]] = cir.const #cir.poison : ![[CoroHandlePromiseVoid]]
-// CIR: cir.store{{.*}} %[[FROMADDR2]], %[[CH_PROM2]]
// CIR: %[[PROM_RELOAD2:.*]] = cir.load{{.*}} %[[CH_PROM2]]
// CIR: cir.call @_ZNSt16coroutine_handleIvEC1IN5folly4coro4TaskIvE12promise_typeEEES_IT_E(%[[CH_VOID2]]){{.*}}
// CIR: %[[VOID_RELOAD2:.*]] = cir.load{{.*}} %[[CH_VOID2]]
@@ -851,8 +821,6 @@ folly::coro::Task<int> go1() {
// CIR: %[[One:.*]] = cir.const #cir.int<1> : !s32i
// CIR: cir.store{{.*}} %[[One]], %[[OneAddr]] : !s32i, !cir.ptr<!s32i>
// CIR: cir.call @_Z2goRKi(%[[OneAddr]]) : (!cir.ptr<!s32i>{{.*}}) -> ()
-// CIR: %[[IntTaskTmp:.*]] = cir.const #cir.poison : ![[IntTask]]
-// CIR: cir.store{{.*}} %[[IntTaskTmp]], %[[IntTaskAddr]] : ![[IntTask]], !cir.ptr<![[IntTask]]>
// CIR: cir.await(user, ready : {
// CIR: }, suspend : {
@@ -1126,11 +1094,9 @@ folly::coro::Task<int> go4() {
// CIR: %[[FN_LOWERED:.*]] = cir.cast bitcast %[[FN]] : !cir.ptr<!cir.func<(!cir.ptr<!s32i>) -> ![[IntTask]]>> -> !cir.ptr<!cir.func<(!cir.ptr<!s32i>)>>
// CIR: cir.call %[[FN_LOWERED]](%[[ARG]]) : (!cir.ptr<!cir.func<(!cir.ptr<!s32i>)>>, !cir.ptr<!s32i> {{.*}}) -> ()
-// CIR: %[[CALLRES:.*]] = cir.const #cir.poison : ![[IntTask]]
-// CIR: cir.store{{.*}} %[[CALLRES]], %[[TASK_ADDR:.*]] : ![[IntTask]], !cir.ptr<![[IntTask]]>
// CIR: cir.await(user, ready : {
-// CIR: = cir.call @_ZN5folly4coro4TaskIiE11await_readyEv(%[[TASK_ADDR]])
+// CIR: = cir.call @_ZN5folly4coro4TaskIiE11await_readyEv(%{{.+}})
// CIR: cir.condition(
// CIR: }, suspend : {
// CIR: cir.coro.suspend_point
@@ -2445,8 +2411,6 @@ folly::coro::Task<int __complex__> complex_co_await() noexcept {
// CIR: }, body : {
// CIR: cir.call @_Z9fetchDatav() nothrow : () -> ()
-// CIR: %[[CALL:.*]] = cir.const #cir.poison : !rec_folly3A3Acoro3A3ATask3C_Complex_int3E
-// CIR: cir.store {{.*}} %[[CALL]], %[[COMPLEX_ADDR]] : !rec_folly3A3Acoro3A3ATask3C_Complex_int3E, !cir.ptr<!rec_folly3A3Acoro3A3ATask3C_Complex_int3E>
// CIR: cir.await(user, ready : {
// CIR: }, suspend : {
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
index fa220a8a2591af..fca2b6f0400ed6 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
@@ -262,8 +262,6 @@ module attributes {
// CHECK: cir.call @take_mixed(%arg0) : (!s32i) -> !s32i
// LLVM: define i32 @caller(i32 %{{.*}})
- // A dropped return leaves the call with no result, so uses of it become
- // poison rather than dangling.
cir.func private @mk_empty() -> !rec_E requires_call_conv_lowering
cir.func @caller_ret_empty() -> !s32i requires_call_conv_lowering {
%0 = cir.call @mk_empty() : () -> !rec_E
@@ -275,8 +273,10 @@ module attributes {
// CHECK: cir.func{{.*}} @caller_ret_empty() -> !s32i
// CHECK: cir.call @mk_empty() : () -> ()
- // CHECK: %[[POISON:.*]] = cir.const #cir.poison : !rec_E
- // CHECK: cir.store %[[POISON]], %{{.*}} : !rec_E, !cir.ptr<!rec_E>
+ // CHECK-NOT: cir.store
+ // CHECK: cir.return
// LLVM: define i32 @caller_ret_empty()
// LLVM: call void @mk_empty()
+ // LLVM-NOT: store
+ // LLVM: ret i32 7
}
More information about the cfe-commits
mailing list