[clang] [CodeGen] Set attributes on coroutine wrapper functions (PR #207961)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 7 03:26:14 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/207961

Call SetInternalFunctionAttributes() so that target feature attributes get set. This ensures that inlining works without having to reason about target-specific inline compatibility logic.

>From 9e9e055f0c99a2e46bb51e58f253e2a112b18fdf Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 7 Jul 2026 09:45:55 +0200
Subject: [PATCH 1/2] Revert "[Clang] Require X86 backend for some coroutine
 tests (#207681)"

This reverts commit bf74249b5ecd651ca99043bea11a8b64301557d3.
---
 clang/test/CodeGenCoroutines/coro-elide.cpp | 3 ---
 clang/test/CodeGenCoroutines/coro-halo.cpp  | 3 ---
 clang/test/CodeGenCoroutines/pr65018.cpp    | 3 ---
 3 files changed, 9 deletions(-)

diff --git a/clang/test/CodeGenCoroutines/coro-elide.cpp b/clang/test/CodeGenCoroutines/coro-elide.cpp
index 3bff2a29c6e07..1902dd64b5e5a 100644
--- a/clang/test/CodeGenCoroutines/coro-elide.cpp
+++ b/clang/test/CodeGenCoroutines/coro-elide.cpp
@@ -1,8 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm %s -o - | FileCheck %s
 
-// FIXME: Generate wrappers with correct target features.
-// REQUIRES: x86-registered-target
-
 #include "Inputs/coroutine.h"
 
 namespace {
diff --git a/clang/test/CodeGenCoroutines/coro-halo.cpp b/clang/test/CodeGenCoroutines/coro-halo.cpp
index 6dd785f5c1f8e..e75bedaf81fa2 100644
--- a/clang/test/CodeGenCoroutines/coro-halo.cpp
+++ b/clang/test/CodeGenCoroutines/coro-halo.cpp
@@ -3,9 +3,6 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -O2 -emit-llvm %s \
 // RUN:   -fcxx-exceptions -fexceptions -o - | FileCheck %s
 
-// FIXME: Generate wrappers with correct target features.
-// REQUIRES: x86-registered-target
-
 #include "Inputs/coroutine.h"
 #include "Inputs/numeric.h"
 
diff --git a/clang/test/CodeGenCoroutines/pr65018.cpp b/clang/test/CodeGenCoroutines/pr65018.cpp
index f3b903dc0b396..f1cde461cabc2 100644
--- a/clang/test/CodeGenCoroutines/pr65018.cpp
+++ b/clang/test/CodeGenCoroutines/pr65018.cpp
@@ -1,9 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
 // RUN:      -O1 -emit-llvm %s -o - | FileCheck %s
 
-// FIXME: Generate wrappers with correct target features.
-// REQUIRES: x86-registered-target
-
 #include "Inputs/coroutine.h"
 
 // A simple awaiter type with an await_suspend method that can't be

>From 32f5d9150b0fcbf6274e2a3166f0064f59eb7720 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 7 Jul 2026 09:59:00 +0200
Subject: [PATCH 2/2] Set attributes on coro wrapper

---
 clang/lib/CodeGen/CGCoroutine.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cpp
index c1ea145934143..bf896f1338ab4 100644
--- a/clang/lib/CodeGen/CGCoroutine.cpp
+++ b/clang/lib/CodeGen/CGCoroutine.cpp
@@ -437,6 +437,7 @@ CodeGenFunction::generateAwaitSuspendWrapper(Twine const &CoroName,
 
   llvm::Function *Fn = llvm::Function::Create(
       LTy, llvm::GlobalValue::InternalLinkage, FuncName, &CGM.getModule());
+  CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
 
   Fn->addParamAttr(0, llvm::Attribute::AttrKind::NonNull);
   Fn->addParamAttr(0, llvm::Attribute::AttrKind::NoUndef);
@@ -444,6 +445,7 @@ CodeGenFunction::generateAwaitSuspendWrapper(Twine const &CoroName,
   Fn->addParamAttr(1, llvm::Attribute::AttrKind::NoUndef);
 
   Fn->setMustProgress();
+  Fn->removeFnAttr(llvm::Attribute::AttrKind::NoInline);
   Fn->addFnAttr(llvm::Attribute::AttrKind::AlwaysInline);
   Fn->addFnAttr("sample-profile-suffix-elision-policy", "selected");
 



More information about the cfe-commits mailing list