Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

release/21.x: [Clang] Fix FE crash during CGCoroutine GRO Alloca Emission (#148962)#149013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tru merged 1 commit intollvm:release/21.xfromllvmbot:issue148962
Jul 17, 2025

Conversation

llvmbot
Copy link
Member

Backportc36156d

Requested by:@efriedma-quic

@llvmbot
Copy link
MemberAuthor

@bcardosolopes What do you think about merging this PR to the release branch?

@llvmbotllvmbot added clangClang issues not falling into any other category clang:codegenIR generation bugs: mangling, exceptions, etc. coroutinesC++20 coroutines labelsJul 16, 2025
@llvmbot
Copy link
MemberAuthor

llvmbot commentedJul 16, 2025
edited
Loading

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-coroutines

Author: None (llvmbot)

Changes

Backportc36156d

Requested by: @efriedma-quic


Full diff:https://github.com/llvm/llvm-project/pull/149013.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGCoroutine.cpp (+9-5)
  • (modified) clang/test/CodeGenCoroutines/coro-gro.cpp (+28-1)
diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cppindex 0fc488e98aaf0..117ef3d16e21b 100644--- a/clang/lib/CodeGen/CGCoroutine.cpp+++ b/clang/lib/CodeGen/CGCoroutine.cpp@@ -707,11 +707,15 @@ struct GetReturnObjectManager {     Builder.CreateStore(Builder.getFalse(), GroActiveFlag);      GroEmission = CGF.EmitAutoVarAlloca(*GroVarDecl);-    auto *GroAlloca = dyn_cast_or_null<llvm::AllocaInst>(-        GroEmission.getOriginalAllocatedAddress().getPointer());-    assert(GroAlloca && "expected alloca to be emitted");-    GroAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,-                           llvm::MDNode::get(CGF.CGM.getLLVMContext(), {}));++    if (!GroVarDecl->isNRVOVariable()) {+      // NRVO variables don't have allocas and won't have the same issue.+      auto *GroAlloca = dyn_cast_or_null<llvm::AllocaInst>(+          GroEmission.getOriginalAllocatedAddress().getPointer());+      assert(GroAlloca && "expected alloca to be emitted");+      GroAlloca->setMetadata(llvm::LLVMContext::MD_coro_outside_frame,+                             llvm::MDNode::get(CGF.CGM.getLLVMContext(), {}));+    }      // Remember the top of EHStack before emitting the cleanup.     auto old_top = CGF.EHStack.stable_begin();diff --git a/clang/test/CodeGenCoroutines/coro-gro.cpp b/clang/test/CodeGenCoroutines/coro-gro.cppindex b62134317cef2..037fd03349e76 100644--- a/clang/test/CodeGenCoroutines/coro-gro.cpp+++ b/clang/test/CodeGenCoroutines/coro-gro.cpp@@ -106,4 +106,31 @@ invoker g() {   // CHECK: call void @_ZN7invoker15invoker_promise17get_return_objectEv({{.*}} %[[AggRes]]   co_return; }-// CHECK: ![[OutFrameMetadata]] = !{}\ No newline at end of file++namespace gh148953 {++struct Task {+  struct promise_type {+    Task get_return_object();+    std::suspend_always initial_suspend() { return {}; }+    std::suspend_always final_suspend() noexcept { return {}; }+    void return_void() {}+    void unhandled_exception() {}+  };+  Task() {}+  // Different from `invoker`, this Task is copy constructible.+  Task(const Task&) {};+};++// NRVO on const qualified return type should work.+// CHECK: define{{.*}} void @_ZN8gh1489537exampleEv({{.*}} sret(%"struct.gh148953::Task") align 1 %[[NrvoRes:.+]])+const Task example() {+  // CHECK: %[[ResultPtr:.+]] = alloca ptr+  // CHECK: store ptr %[[NrvoRes]], ptr %[[ResultPtr]]+  // CHECK: coro.init:+  // CHECK: call void @_ZN8gh1489534Task12promise_type17get_return_objectEv({{.*}} %[[NrvoRes:.+]], {{.*}})+  co_return;+}++} // namespace gh148953+// CHECK: ![[OutFrameMetadata]] = !{}

@tru
Copy link
Collaborator

tru commentedJul 17, 2025

@bcardosolopes can you review this for inclusion in the release branch?

bcardosolopes reacted with thumbs up emoji

@trutru moved this fromNeeds Triage toNeeds Review inLLVM Release StatusJul 17, 2025
Copy link
Member

@bcardosolopesbcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@github-project-automationgithub-project-automationbot moved this fromNeeds Review toNeeds Merge inLLVM Release StatusJul 17, 2025
)Fixes:llvm#148953Currently when coroutine return object type is const qualified, we don'tdo direct emission. The regular emission logic assumed that the auto varemission will always result in an `AllocaInst`. However, based on myfindings, NRVO var emissions don't result in `AllocaInst`s. Therefore,this[assertion](https://github.com/llvm/llvm-project/blob/1a940bfff9176fb38a71b0045d7ae25df9a4ca7d/clang/lib/CodeGen/CGCoroutine.cpp#L712)will fail.Since the NRVOed returned object don't live on the coroutine frame, wewon't have the problem of it outliving the coroutine frame, therefore,we can safely omit this metadata.(cherry picked from commitc36156d)
@trutru merged commitad90510 intollvm:release/21.xJul 17, 2025
1 check was pending
@github-project-automationgithub-project-automationbot moved this fromNeeds Merge toDone inLLVM Release StatusJul 17, 2025
@github-actionsGitHub Actions
Copy link

@efriedma-quic (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@bcardosolopesbcardosolopesbcardosolopes approved these changes

Assignees
No one assigned
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.clangClang issues not falling into any other categorycoroutinesC++20 coroutines
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants
@llvmbot@tru@bcardosolopes@yuxuanchen1997

[8]ページ先頭

©2009-2025 Movatter.jp