llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-coroutines Author: llvmbot <details> <summary>Changes</summary> Backport efb01c1 Requested by: @<!-- -->SLTozer --- Full diff: https://github.com/llvm/llvm-project/pull/195869.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGDecl.cpp (+7-2) - (added) clang/test/CodeGenCoroutines/coro-param-fake-use.cpp (+42) ``````````diff diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 8b1cd83af2396..aeecf0bac1b87 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -2829,8 +2829,13 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg, (CGM.getCodeGenOpts().getExtendVariableLiveness() == CodeGenOptions::ExtendVariableLivenessKind::This && &D == CXXABIThisDecl)) { - if (shouldExtendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl)) - EHStack.pushCleanup<FakeUse>(NormalFakeUse, DeclPtr); + // We don't emit fake uses for coroutine parameters, other than `this`. + if (auto *FnDecl = dyn_cast_or_null<FunctionDecl>(CurCodeDecl); + &D == CXXABIThisDecl || !FnDecl || + FnDecl->getBody()->getStmtClass() != Stmt::CoroutineBodyStmtClass) { + if (shouldExtendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl)) + EHStack.pushCleanup<FakeUse>(NormalFakeUse, DeclPtr); + } } // Emit debug info for param declarations in non-thunk functions. diff --git a/clang/test/CodeGenCoroutines/coro-param-fake-use.cpp b/clang/test/CodeGenCoroutines/coro-param-fake-use.cpp new file mode 100644 index 0000000000000..0a0da815975d9 --- /dev/null +++ b/clang/test/CodeGenCoroutines/coro-param-fake-use.cpp @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -emit-llvm -fextend-variable-liveness -o - %s -disable-llvm-passes -fexceptions | FileCheck %s + +// See issue #192351 +// Tests that parameters to a coroutine do not have fake uses inserted for them +// when we enable -fextend-variable-liveness, except for `this`, which is not +// stored in the coroutine frame. + +#include "Inputs/coroutine.h" + +struct task { + struct promise_type { + task get_return_object() noexcept { return {}; } + std::suspend_never initial_suspend() noexcept { return {}; } + std::suspend_never final_suspend() noexcept { return {}; } + void return_void() noexcept {} + void unhandled_exception() noexcept {} + }; +}; + +class C { +public: + C() {} + + // CHECK-LABEL: void @_ZN1C1fEb(ptr noundef{{.*}} %this, i1 noundef{{.*}} %b) + task f(bool b) { + // CHECK: store ptr %this, ptr %[[THIS_ADDR:.+]] + // CHECK-NOT: llvm.fake.use + + // CHECK: coro.ret: + // CHECK-NEXT: call void @llvm.coro.end( + // CHECK-NEXT: %[[THIS_FAKE_USE:.+]] = load ptr, ptr %[[THIS_ADDR]] + // CHECK-NEXT: notail call void (...) @llvm.fake.use(ptr %[[THIS_FAKE_USE]]) + // CHECK-NEXT: ret void + if (b) { + co_await std::suspend_always{}; + } + } +}; + +void foo() { + C().f(false); +} `````````` </details> https://github.com/llvm/llvm-project/pull/195869 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
