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

Set target features in StartFunction(), which is in particular used by 
generateAwaitSuspendWrapper(). This ensures that inlining works without having 
to rely on target-specific feature compatibility logic (after 
https://github.com/llvm/llvm-project/pull/205113).

TBH I'm very confused by Clang's attribute assignment logic for functions -- 
there are *so many* different APIs for setting attributes, and it feels like 
the attribute assignment is split randomly across them. I don't understand what 
the layering here is supposed to be.

I initially wanted to move this case from ConstructAttributeList() to 
StartFunction() entirely, as target-features should only be assigned to 
definitions, not declarations (as we currently do), but then it turns out that 
some places only use SetLLVMFunctionAttributes() but not StartFunction(), so 
that doesn't work.

Or maybe the right fix is to not change StartFunction() at all and instead call 
SetLLVMFunctionAttributes() from the coro code?

>From 32a58fe51c9e5dab08267289022c294d7830981d Mon Sep 17 00:00:00 2001
From: Nikita Popov <[email protected]>
Date: Mon, 6 Jul 2026 10:29:41 +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 5c08ac0b026c39a67243390edd115e5d2d1be486 Mon Sep 17 00:00:00 2001
From: Nikita Popov <[email protected]>
Date: Mon, 6 Jul 2026 11:07:14 +0200
Subject: [PATCH 2/2] Set target features in StartFunction

---
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++++
 clang/lib/CodeGen/CodeGenModule.h     | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index b920266b59808..7fcbcbed8efeb 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1124,6 +1124,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
         getLLVMContext(), VScaleRange->first, VScaleRange->second));
   }
 
+  llvm::AttrBuilder Attrs(getLLVMContext());
+  CGM.GetCPUAndFeaturesAttributes(GD, Attrs);
+  Fn->addFnAttrs(Attrs);
+
   llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn);
 
   // Create a marker to make it easy to insert allocas into the entryblock
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index b1e70a7c347db..b1137d900dccf 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1992,9 +1992,11 @@ class CodeGenModule : public CodeGenTypeCache {
   void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD,
                                StringRef &CurName);
 
+public:
   bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
                                    llvm::AttrBuilder &AttrBuilder,
                                    bool SetTargetFeatures = true);
+private:
   void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO);
 
   /// Set function attributes for a function declaration.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to