Skip to content

Commit 44c4643

Browse files
committed
Address PR feedback
* Simply use F.getName() for function name. * Fix llvm/test/CodeGen/Generic/ms-hotpatch-direct-global-access.ll * Add negative testing for functions that are not supposed to be hotpatched
1 parent 69be013 commit 44c4643

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This verifies that hotpatch function attributes are correctly propagated when compiling directly to OBJ,
2+
// and that name mangling works as expected.
3+
//
4+
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-list=?this_gets_hotpatched@@YAHXZ /Fo%t.obj %s
5+
// RUN: llvm-readobj --codeview %t.obj | FileCheck %s
6+
7+
void this_might_have_side_effects();
8+
9+
int __declspec(noinline) this_gets_hotpatched() {
10+
this_might_have_side_effects();
11+
return 42;
12+
}
13+
14+
// CHECK: Kind: S_HOTPATCHFUNC (0x1169)
15+
// CHECK-NEXT: Function: this_gets_hotpatched
16+
// CHECK-NEXT: Name: ?this_gets_hotpatched@@YAHXZ
17+
18+
extern "C" int __declspec(noinline) this_does_not_get_hotpatched() {
19+
return this_gets_hotpatched() + 100;
20+
}
21+
22+
// CHECK-NOT: S_HOTPATCHFUNC

clang/test/CodeGen/ms-hotpatch.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//
33
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-file=%S/ms-hotpatch-functions.txt /Fo%t.obj %s
44
// RUN: llvm-readobj --codeview %t.obj | FileCheck %s
5-
// CHECK: Kind: S_HOTPATCHFUNC (0x1169)
6-
// CHECK-NEXT: Function: this_gets_hotpatched
75

86
void this_might_have_side_effects();
97

@@ -12,6 +10,11 @@ int __declspec(noinline) this_gets_hotpatched() {
1210
return 42;
1311
}
1412

13+
// CHECK: Kind: S_HOTPATCHFUNC (0x1169)
14+
// CHECK-NEXT: Function: this_gets_hotpatched
15+
1516
int __declspec(noinline) this_does_not_get_hotpatched() {
1617
return this_gets_hotpatched() + 100;
1718
}
19+
20+
// CHECK-NOT: S_HOTPATCHFUNC

llvm/include/llvm/IR/Attributes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def MarkedForWindowsHotPatching
398398
/// decl, not the hotpatched function.
399399
def AllowDirectAccessInHotPatchFunction
400400
: EnumAttr<"allow_direct_access_in_hot_patch_function",
401-
IntersectPreserve, []>;
401+
IntersectPreserve, [FnAttr]>;
402402

403403
/// Target-independent string attributes.
404404
def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;

llvm/lib/CodeGen/WindowsHotPatch.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,7 @@ bool WindowsHotPatch::runOnModule(Module &M) {
130130
continue;
131131
}
132132

133-
llvm::StringRef FuncName{};
134-
if (auto *SP = F.getSubprogram(); SP != nullptr) {
135-
FuncName = SP->getLinkageName();
136-
if (FuncName.empty()) {
137-
FuncName = F.getName();
138-
}
139-
} else {
140-
FuncName = F.getName();
141-
}
142-
if (HotPatchFunctionsSet.contains(FuncName)) {
133+
if (HotPatchFunctionsSet.contains(F.getName())) {
143134
F.addFnAttr(Attribute::MarkedForWindowsHotPatching);
144135
}
145136
}

0 commit comments

Comments
 (0)