Skip to content

Commit fb1f68c

Browse files
committed
fmt
1 parent a684405 commit fb1f68c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

clang/test/CodeGen/ms-secure-hotpatch-globals.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This verifies that global variable redirection works correctly when using hotpatching.
22
//
33
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 \
4-
// RUN: -fms-secure-hotpatch-functions-list=hp1,hp2,hp3,hp4,hp5_phi_ptr_mixed,hp_phi_ptr_both \
4+
// RUN: -fms-secure-hotpatch-functions-list=hp1,hp2,hp3,hp4,hp5_phi_ptr_mixed,hp_phi_ptr_both,hp_const_ptr_sub \
55
// RUN: /clang:-S /clang:-o- %s | FileCheck %s
66

77
#ifdef __clang__
@@ -114,10 +114,20 @@ void hp_phi_ptr_both(int x) NO_TAIL {
114114
take_data(y);
115115
}
116116

117-
// CHECK: hp_phi_ptr_both
117+
// CHECK: hp_phi_ptr_both:
118118
// CHECK: .seh_endprologue
119119
// CHECK: test ecx, ecx
120120
// CHECK: mov rsi, qword ptr [rip + __ref_g_has_pointers]
121121
// CHECK: mov rsi, qword ptr [rip + __ref_g_data]
122122
// CHECK: take_data
123123
// CHECK: .seh_endproc
124+
125+
// Test a constant expression which references global variable addresses.
126+
size_t hp_const_ptr_sub() NO_TAIL {
127+
return (unsigned char*)&g_has_pointers - (unsigned char*)&g_data;
128+
}
129+
130+
// CHECK: hp_const_ptr_sub:
131+
// CHECK: mov rax, qword ptr [rip + __ref_g_has_pointers]
132+
// CHECK: sub rax, qword ptr [rip + __ref_g_data]
133+
// CHECK: ret

llvm/lib/CodeGen/WindowsSecureHotPatching.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ static GlobalVariable *getOrCreateRefVariable(
395395
// If this function creates new instructions, then it will insert them
396396
// before InsertionPoint.
397397
static Value *rewriteGlobalVariablesInConstant(
398-
Constant *C,
399-
SmallDenseMap<GlobalVariable *, Value *> &GVLoadMap,
398+
Constant *C, SmallDenseMap<GlobalVariable *, Value *> &GVLoadMap,
400399
IRBuilder<> &IRBuilderAtEntry) {
401400
if (C->getValueID() == Value::GlobalVariableVal) {
402401
GlobalVariable *GV = cast<GlobalVariable>(C);

0 commit comments

Comments
 (0)