[clang] [clang][FMV] Fix crash with cpu_specific attribute. (PR #115762)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 11 12:28:31 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-codegen
Author: Alexandros Lamprineas (labrinea)
<details>
<summary>Changes</summary>
Raised here https://github.com/llvm/llvm-project/issues/115299.
The commit a2d3099 introduced `replaceDeclarationWith`, but it shouldn't be called by the fallthrough code which handles the cpu_specific attribute.
---
Full diff: https://github.com/llvm/llvm-project/pull/115762.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (-2)
- (modified) clang/test/CodeGen/attr-cpuspecific.c (+6-6)
``````````diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index ba376f9ecfacde..27b1ccb8137356 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4597,8 +4597,6 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
assert(isa<llvm::GlobalValue>(Resolver) &&
"Resolver should be created for the first time");
SetCommonAttributes(FD, cast<llvm::GlobalValue>(Resolver));
- if (ResolverGV)
- replaceDeclarationWith(ResolverGV, Resolver);
return Resolver;
}
diff --git a/clang/test/CodeGen/attr-cpuspecific.c b/clang/test/CodeGen/attr-cpuspecific.c
index 628892d5809b4e..91f6c9e9e06b88 100644
--- a/clang/test/CodeGen/attr-cpuspecific.c
+++ b/clang/test/CodeGen/attr-cpuspecific.c
@@ -114,8 +114,8 @@ void ThreeVersionsSameAttr(void){}
// CHECK: define {{.*}}void @ThreeVersionsSameAttr.Z() #[[K]]
ATTR(cpu_specific(knl))
-void CpuSpecificNoDispatch(void) {}
-// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z() #[[K:[0-9]+]]
+void CpuSpecificNoDispatch(void (*f)(void)) {}
+// CHECK: define {{.*}}void @CpuSpecificNoDispatch.Z(ptr noundef %f) #[[K:[0-9]+]]
ATTR(cpu_dispatch(knl))
void OrderDispatchUsageSpecific(void);
@@ -151,9 +151,9 @@ void usages(void) {
ThreeVersionsSameAttr();
// LINUX: @ThreeVersionsSameAttr.ifunc()
// WINDOWS: @ThreeVersionsSameAttr()
- CpuSpecificNoDispatch();
- // LINUX: @CpuSpecificNoDispatch.ifunc()
- // WINDOWS: @CpuSpecificNoDispatch()
+ CpuSpecificNoDispatch((void (*)(void))CpuSpecificNoDispatch);
+ // LINUX: @CpuSpecificNoDispatch.ifunc(ptr noundef @CpuSpecificNoDispatch.ifunc)
+ // WINDOWS: @CpuSpecificNoDispatch(ptr noundef @CpuSpecificNoDispatch)
OrderDispatchUsageSpecific();
// LINUX: @OrderDispatchUsageSpecific.ifunc()
// WINDOWS: @OrderDispatchUsageSpecific()
@@ -162,7 +162,7 @@ void usages(void) {
// WINDOWS: @OrderSpecificUsageDispatch()
}
-// LINUX: declare void @CpuSpecificNoDispatch.ifunc()
+// LINUX: declare void @CpuSpecificNoDispatch.ifunc(ptr)
// has an extra config to emit!
ATTR(cpu_dispatch(ivybridge, knl, atom))
``````````
</details>
https://github.com/llvm/llvm-project/pull/115762
More information about the cfe-commits
mailing list