https://github.com/apolloww created https://github.com/llvm/llvm-project/pull/174881
Fix an issue where `FunctionSamples::getCanonicalFnName` incorrectly canonicalizes coro await suspense wrapper functions to collide with the coro function itself. This causes the sample annotation to skip coro function. Canonicalization strips everything comes after the first dot (.), unless the function attribute "sample-profile-suffix-elision-policy" is set to "selected", in which case it strips after the known suffixes. The wrapper function name has the suffix of ".__await_suspend_wrapper__" + await_kind. Add the attribute to wrapper function so that the suffix is not stripped. >From 475083230b3e93d004bb3134aab4e50ccff74089 Mon Sep 17 00:00:00 2001 From: Wei Wang <[email protected]> Date: Wed, 7 Jan 2026 12:20:04 -0800 Subject: [PATCH] [SampleProf] Handle coro wrapper function name canonicalization --- clang/lib/CodeGen/CGCoroutine.cpp | 1 + clang/test/CodeGenCoroutines/coro-attributes.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/clang/lib/CodeGen/CGCoroutine.cpp b/clang/lib/CodeGen/CGCoroutine.cpp index c80bb0e004367..7282c42420657 100644 --- a/clang/lib/CodeGen/CGCoroutine.cpp +++ b/clang/lib/CodeGen/CGCoroutine.cpp @@ -447,6 +447,7 @@ CodeGenFunction::generateAwaitSuspendWrapper(Twine const &CoroName, Fn->setMustProgress(); Fn->addFnAttr(llvm::Attribute::AttrKind::AlwaysInline); + Fn->addFnAttr("sample-profile-suffix-elision-policy", "selected"); StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args); diff --git a/clang/test/CodeGenCoroutines/coro-attributes.cpp b/clang/test/CodeGenCoroutines/coro-attributes.cpp index 8f171771a8cbc..2dfb6cc052ce9 100644 --- a/clang/test/CodeGenCoroutines/coro-attributes.cpp +++ b/clang/test/CodeGenCoroutines/coro-attributes.cpp @@ -15,8 +15,12 @@ struct coro { // CHECK: void @_Z3foov() #[[FOO_ATTR_NUM:[0-9]+]] // CHECK: declare token @llvm.coro.save(ptr) #[[SAVE_ATTR_NUM:[0-9]+]] +// CHECK: void @_Z3foov.__await_suspend_wrapper__init({{.*}}) #[[WRAPPER_ATTR_NUM:[0-9]+]] +// CHECK: void @_Z3foov.__await_suspend_wrapper__await({{.*}}) #[[WRAPPER_ATTR_NUM:[0-9]+]] +// CHECK: void @_Z3foov.__await_suspend_wrapper__final({{.*}}) #[[WRAPPER_ATTR_NUM:[0-9]+]] // CHECK: attributes #[[FOO_ATTR_NUM]] = { {{.*}} presplitcoroutine // CHECK: attributes #[[SAVE_ATTR_NUM]] = { {{.*}}nomerge +// CHECK: attributes #[[WRAPPER_ATTR_NUM]] = { {{.*}}"sample-profile-suffix-elision-policy"="selected" coro foo() { co_await suspend_always{}; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
