Skip to content

Commit 0b35988

Browse files
committed
Resolve one integration test failure
Also tolerate blank lines and trim whitespace in patch function files.
1 parent 44c4643 commit 0b35988

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ CodeGenModule::CodeGenModule(ASTContext &C,
464464
const llvm::MemoryBuffer &FileBuffer = **BufOrErr;
465465
for (llvm::line_iterator I(FileBuffer.getMemBufferRef(), true), E;
466466
I != E; ++I) {
467-
this->MSHotPatchFunctions.push_back(std::string{*I});
467+
llvm::StringRef Line = llvm::StringRef(*I).trim();
468+
if (!Line.empty()) {
469+
this->MSHotPatchFunctions.push_back(std::string{Line});
470+
}
468471
}
469472
} else {
470473
auto &DE = Context.getDiagnostics();

clang/test/CodeGen/ms-hotpatch-file.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This verifies that hotpatch function attributes are correctly propagated when compiling directly to OBJ.
2+
//
3+
// RUN: echo this_gets_hotpatched > %t-hotpatch-functions.txt
4+
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-file=%t-hotpatch-functions.txt /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+
17+
int __declspec(noinline) this_does_not_get_hotpatched() {
18+
return this_gets_hotpatched() + 100;
19+
}
20+
21+
// CHECK-NOT: S_HOTPATCHFUNC

clang/test/CodeGen/ms-hotpatch-functions.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

clang/test/CodeGen/ms-hotpatch-lto.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// This verifies that hotpatch function attributes are correctly propagated through LLVM IR when compiling with LTO.
22
//
3-
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-file=%S/ms-hotpatch-functions.txt -flto /Fo%t.bc %s
3+
// RUN: echo this_gets_hotpatched > %t-hotpatch-functions.txt
4+
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-file=%t-hotpatch-functions.txt -flto /Fo%t.bc %s
45
// RUN: llvm-dis %t.bc -o - | FileCheck %s
56
//
67
// CHECK: ; Function Attrs: marked_for_windows_hot_patching mustprogress nofree noinline norecurse nosync nounwind sspstrong willreturn memory(none) uwtable
7-
// CHECK-NEXT: define dso_local noundef i32 @this_gets_hotpatched() local_unnamed_addr #0 !dbg !13 {
8+
// CHECK-NEXT: define dso_local noundef i32 @this_gets_hotpatched()
89
//
910
// CHECK: ; Function Attrs: mustprogress nofree noinline norecurse nosync nounwind sspstrong willreturn memory(none) uwtable
10-
// CHECK-NEXT: define dso_local noundef i32 @this_does_not_get_hotpatched() local_unnamed_addr #1 !dbg !19 {
11+
// CHECK-NEXT: define dso_local noundef i32 @this_does_not_get_hotpatched()
1112

1213
int __declspec(noinline) this_gets_hotpatched() {
1314
return 42;

clang/test/CodeGen/ms-hotpatch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This verifies that hotpatch function attributes are correctly propagated when compiling directly to OBJ.
22
//
3-
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-file=%S/ms-hotpatch-functions.txt /Fo%t.obj %s
3+
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 -fms-hotpatch-functions-list=this_gets_hotpatched /Fo%t.obj %s
44
// RUN: llvm-readobj --codeview %t.obj | FileCheck %s
55

66
void this_might_have_side_effects();

llvm/lib/CodeGen/WindowsHotPatch.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ bool WindowsHotPatch::runOnModule(Module &M) {
9898
const llvm::MemoryBuffer &FileBuffer = **BufOrErr;
9999
for (llvm::line_iterator I(FileBuffer.getMemBufferRef(), true), E;
100100
I != E; ++I) {
101-
HotPatchFunctionsList.push_back(std::string{*I});
101+
auto Line = llvm::StringRef(*I).trim();
102+
if (!Line.empty()) {
103+
HotPatchFunctionsList.push_back(std::string{Line});
104+
}
102105
}
103106
} else {
104107
M.getContext().diagnose(llvm::DiagnosticInfoGeneric{

0 commit comments

Comments
 (0)