Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3b8055a

Browse files
committed
[HotColdSplit] Disable splitting for sanitized functions
Splitting can make sanitizer errors harder to understand, as the trapping instruction may not be in the function where the bug was detected. rdar://48142697 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354931 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a764eb9 commit 3b8055a

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

lib/Transforms/IPO/HotColdSplitting.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ bool unlikelyExecuted(BasicBlock &BB) {
111111
if (BB.isEHPad() || isa<ResumeInst>(BB.getTerminator()))
112112
return true;
113113

114-
// The block is cold if it calls/invokes a cold function.
114+
// The block is cold if it calls/invokes a cold function. However, do not
115+
// mark sanitizer traps as cold.
115116
for (Instruction &I : BB)
116117
if (auto CS = CallSite(&I))
117-
if (CS.hasFnAttr(Attribute::Cold))
118+
if (CS.hasFnAttr(Attribute::Cold) && !CS->getMetadata("nosanitize"))
118119
return true;
119120

120121
// The block is cold if it has an unreachable terminator, unless it's
@@ -235,6 +236,12 @@ bool HotColdSplitting::shouldOutlineFrom(const Function &F) const {
235236
if (F.hasFnAttribute(Attribute::NoInline))
236237
return false;
237238

239+
if (F.hasFnAttribute(Attribute::SanitizeAddress) ||
240+
F.hasFnAttribute(Attribute::SanitizeHWAddress) ||
241+
F.hasFnAttribute(Attribute::SanitizeThread) ||
242+
F.hasFnAttribute(Attribute::SanitizeMemory))
243+
return false;
244+
238245
return true;
239246
}
240247

test/Transforms/HotColdSplit/X86/do-not-split.ll

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,78 @@ if.end: ; preds = %entry
110110
ret void
111111
}
112112

113+
; CHECK-LABEL: @sanitize_address
114+
; CHECK-NOT: sanitize_address.cold.1
115+
define void @sanitize_address() sanitize_address {
116+
entry:
117+
br i1 undef, label %if.then, label %if.end
118+
119+
if.then: ; preds = %entry
120+
call void @sink()
121+
ret void
122+
123+
if.end: ; preds = %entry
124+
ret void
125+
}
126+
127+
; CHECK-LABEL: @sanitize_hwaddress
128+
; CHECK-NOT: sanitize_hwaddress.cold.1
129+
define void @sanitize_hwaddress() sanitize_hwaddress {
130+
entry:
131+
br i1 undef, label %if.then, label %if.end
132+
133+
if.then: ; preds = %entry
134+
call void @sink()
135+
ret void
136+
137+
if.end: ; preds = %entry
138+
ret void
139+
}
140+
141+
; CHECK-LABEL: @sanitize_thread
142+
; CHECK-NOT: sanitize_thread.cold.1
143+
define void @sanitize_thread() sanitize_thread {
144+
entry:
145+
br i1 undef, label %if.then, label %if.end
146+
147+
if.then: ; preds = %entry
148+
call void @sink()
149+
ret void
150+
151+
if.end: ; preds = %entry
152+
ret void
153+
}
154+
155+
; CHECK-LABEL: @sanitize_memory
156+
; CHECK-NOT: sanitize_memory.cold.1
157+
define void @sanitize_memory() sanitize_memory {
158+
entry:
159+
br i1 undef, label %if.then, label %if.end
160+
161+
if.then: ; preds = %entry
162+
call void @sink()
163+
ret void
164+
165+
if.end: ; preds = %entry
166+
ret void
167+
}
168+
169+
declare void @llvm.trap() cold noreturn
170+
171+
; CHECK-LABEL: @nosanitize_call
172+
; CHECK-NOT: nosanitize_call.cold.1
173+
define void @nosanitize_call() sanitize_memory {
174+
entry:
175+
br i1 undef, label %if.then, label %if.end
176+
177+
if.then: ; preds = %entry
178+
call void @llvm.trap(), !nosanitize !2
179+
unreachable
180+
181+
if.end: ; preds = %entry
182+
ret void
183+
}
184+
113185
declare void @llvm.dbg.value(metadata, metadata, metadata)
114186

115187
declare void @sink() cold

0 commit comments

Comments
 (0)