Skip to content

Commit ded9781

Browse files
authored
Revert "[msan] Automatically print shadow for failing outlined checks (#145107)"
This reverts commit 1b71ea4.
1 parent d06c2ef commit ded9781

File tree

5 files changed

+22
-142
lines changed

5 files changed

+22
-142
lines changed

compiler-rt/lib/msan/msan.cpp

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -352,69 +352,23 @@ void __sanitizer::BufferedStackTrace::UnwindImpl(
352352

353353
using namespace __msan;
354354

355-
// N.B. Only [shadow, shadow+size) is defined. shadow is *not* a pointer into
356-
// an MSan shadow region.
357-
static void print_shadow_value(void *shadow, u64 size) {
358-
Printf("Shadow value (%llu byte%s):", size, size == 1 ? "" : "s");
359-
for (unsigned int i = 0; i < size; i++) {
360-
if (i % 4 == 0)
361-
Printf(" ");
362-
363-
unsigned char x = ((unsigned char *)shadow)[i];
364-
Printf("%x%x", x >> 4, x & 0xf);
365-
}
366-
Printf("\n");
367-
Printf(
368-
"Caveat: the shadow value does not necessarily directly correspond to a "
369-
"single user variable. The correspondence is stronger, but not always "
370-
"perfect, when origin tracking is enabled.\n");
371-
Printf("\n");
372-
}
373-
374-
#define MSAN_MAYBE_WARNING(type, size) \
375-
void __msan_maybe_warning_##size(type s, u32 o) { \
376-
GET_CALLER_PC_BP; \
377-
\
378-
if (UNLIKELY(s)) { \
379-
if (Verbosity() >= 1) \
380-
print_shadow_value((void *)(&s), sizeof(s)); \
381-
PrintWarningWithOrigin(pc, bp, o); \
382-
if (__msan::flags()->halt_on_error) { \
383-
Printf("Exiting\n"); \
384-
Die(); \
385-
} \
386-
} \
355+
#define MSAN_MAYBE_WARNING(type, size) \
356+
void __msan_maybe_warning_##size(type s, u32 o) { \
357+
GET_CALLER_PC_BP; \
358+
if (UNLIKELY(s)) { \
359+
PrintWarningWithOrigin(pc, bp, o); \
360+
if (__msan::flags()->halt_on_error) { \
361+
Printf("Exiting\n"); \
362+
Die(); \
363+
} \
364+
} \
387365
}
388366

389367
MSAN_MAYBE_WARNING(u8, 1)
390368
MSAN_MAYBE_WARNING(u16, 2)
391369
MSAN_MAYBE_WARNING(u32, 4)
392370
MSAN_MAYBE_WARNING(u64, 8)
393371

394-
// N.B. Only [shadow, shadow+size) is defined. shadow is *not* a pointer into
395-
// an MSan shadow region.
396-
void __msan_maybe_warning_N(void *shadow, u64 size, u32 o) {
397-
GET_CALLER_PC_BP;
398-
399-
bool allZero = true;
400-
for (unsigned int i = 0; i < size; i++) {
401-
if (((char *)shadow)[i]) {
402-
allZero = false;
403-
break;
404-
}
405-
}
406-
407-
if (UNLIKELY(!allZero)) {
408-
if (Verbosity() >= 1)
409-
print_shadow_value(shadow, size);
410-
PrintWarningWithOrigin(pc, bp, o);
411-
if (__msan::flags()->halt_on_error) {
412-
Printf("Exiting\n");
413-
Die();
414-
}
415-
}
416-
}
417-
418372
#define MSAN_MAYBE_STORE_ORIGIN(type, size) \
419373
void __msan_maybe_store_origin_##size(type s, void *p, u32 o) { \
420374
if (UNLIKELY(s)) { \

compiler-rt/lib/msan/msan_interface_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ SANITIZER_INTERFACE_ATTRIBUTE
6060
void __msan_maybe_warning_4(u32 s, u32 o);
6161
SANITIZER_INTERFACE_ATTRIBUTE
6262
void __msan_maybe_warning_8(u64 s, u32 o);
63-
SANITIZER_INTERFACE_ATTRIBUTE
64-
void __msan_maybe_warning_N(void *shadow, u64 size, u32 o);
6563

6664
SANITIZER_INTERFACE_ATTRIBUTE
6765
void __msan_maybe_store_origin_1(u8 s, void *p, u32 o);

compiler-rt/test/msan/msan_print_shadow_on_outlined_check.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ class MemorySanitizer {
665665

666666
// These arrays are indexed by log2(AccessSize).
667667
FunctionCallee MaybeWarningFn[kNumberOfAccessSizes];
668-
FunctionCallee MaybeWarningVarSizeFn;
669668
FunctionCallee MaybeStoreOriginFn[kNumberOfAccessSizes];
670669

671670
/// Run-time helper that generates a new origin value for a stack
@@ -940,9 +939,7 @@ void MemorySanitizer::createUserspaceApi(Module &M,
940939
MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction(
941940
FunctionName, TLI.getAttrList(C, {0, 1}, /*Signed=*/false),
942941
IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), IRB.getInt32Ty());
943-
MaybeWarningVarSizeFn = M.getOrInsertFunction(
944-
"__msan_maybe_warning_N", TLI.getAttrList(C, {}, /*Signed=*/false),
945-
IRB.getVoidTy(), PtrTy, IRB.getInt64Ty(), IRB.getInt32Ty());
942+
946943
FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize);
947944
MaybeStoreOriginFn[AccessSizeIndex] = M.getOrInsertFunction(
948945
FunctionName, TLI.getAttrList(C, {0, 2}, /*Signed=*/false),
@@ -1251,6 +1248,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
12511248
// Constants likely will be eliminated by follow-up passes.
12521249
if (isa<Constant>(V))
12531250
return false;
1251+
12541252
++SplittableBlocksCount;
12551253
return ClInstrumentationWithCallThreshold >= 0 &&
12561254
SplittableBlocksCount > ClInstrumentationWithCallThreshold;
@@ -1449,32 +1447,18 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
14491447
const DataLayout &DL = F.getDataLayout();
14501448
TypeSize TypeSizeInBits = DL.getTypeSizeInBits(ConvertedShadow->getType());
14511449
unsigned SizeIndex = TypeSizeToSizeIndex(TypeSizeInBits);
1452-
if (instrumentWithCalls(ConvertedShadow) && !MS.CompileKernel) {
1450+
if (instrumentWithCalls(ConvertedShadow) &&
1451+
SizeIndex < kNumberOfAccessSizes && !MS.CompileKernel) {
1452+
FunctionCallee Fn = MS.MaybeWarningFn[SizeIndex];
14531453
// ZExt cannot convert between vector and scalar
14541454
ConvertedShadow = convertShadowToScalar(ConvertedShadow, IRB);
14551455
Value *ConvertedShadow2 =
14561456
IRB.CreateZExt(ConvertedShadow, IRB.getIntNTy(8 * (1 << SizeIndex)));
1457-
1458-
if (SizeIndex < kNumberOfAccessSizes) {
1459-
FunctionCallee Fn = MS.MaybeWarningFn[SizeIndex];
1460-
CallBase *CB = IRB.CreateCall(
1461-
Fn,
1462-
{ConvertedShadow2,
1463-
MS.TrackOrigins && Origin ? Origin : (Value *)IRB.getInt32(0)});
1464-
CB->addParamAttr(0, Attribute::ZExt);
1465-
CB->addParamAttr(1, Attribute::ZExt);
1466-
} else {
1467-
FunctionCallee Fn = MS.MaybeWarningVarSizeFn;
1468-
Value *ShadowAlloca = IRB.CreateAlloca(ConvertedShadow2->getType(), 0u);
1469-
IRB.CreateStore(ConvertedShadow2, ShadowAlloca);
1470-
unsigned ShadowSize = DL.getTypeAllocSize(ConvertedShadow2->getType());
1471-
CallBase *CB = IRB.CreateCall(
1472-
Fn,
1473-
{ShadowAlloca, ConstantInt::get(IRB.getInt64Ty(), ShadowSize),
1474-
MS.TrackOrigins && Origin ? Origin : (Value *)IRB.getInt32(0)});
1475-
CB->addParamAttr(1, Attribute::ZExt);
1476-
CB->addParamAttr(2, Attribute::ZExt);
1477-
}
1457+
CallBase *CB = IRB.CreateCall(
1458+
Fn, {ConvertedShadow2,
1459+
MS.TrackOrigins && Origin ? Origin : (Value *)IRB.getInt32(0)});
1460+
CB->addParamAttr(0, Attribute::ZExt);
1461+
CB->addParamAttr(1, Attribute::ZExt);
14781462
} else {
14791463
Value *Cmp = convertToBool(ConvertedShadow, IRB, "_mscmp");
14801464
Instruction *CheckTerm = SplitBlockAndInsertIfThen(

llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,13 @@ define <4 x i32> @test64(<4 x i32> %vec, i64 %idx, i32 %x) sanitize_memory {
7373
; CHECK: call void @__msan_maybe_warning_8(i64 zeroext %{{.*}}, i32 zeroext 0)
7474
; CHECK: ret <4 x i32>
7575

76-
; Type size too large => use variable-size handler.
76+
; Type size too large => inline check.
7777
define <4 x i32> @test65(<4 x i32> %vec, i65 %idx, i32 %x) sanitize_memory {
7878
%vec1 = insertelement <4 x i32> %vec, i32 %x, i65 %idx
7979
ret <4 x i32> %vec1
8080
}
8181
; CHECK-LABEL: @test65(
82-
; CHECK: %[[A:.*]] = zext i65 %1 to i128
83-
; CHECK: call void @__msan_maybe_warning_N(ptr %{{.*}}, i64 zeroext 16, i32 zeroext 0)
84-
; CHECK: ret <4 x i32>
85-
86-
define <4 x i32> @test128(<4 x i32> %vec, i128 %idx, i32 %x) sanitize_memory {
87-
%vec1 = insertelement <4 x i32> %vec, i32 %x, i128 %idx
88-
ret <4 x i32> %vec1
89-
}
90-
; CHECK-LABEL: @test128(
91-
; CHECK: call void @__msan_maybe_warning_N(ptr %{{.*}}, i64 zeroext 16, i32 zeroext 0)
92-
; CHECK: ret <4 x i32>
93-
94-
define <4 x i32> @test256(<4 x i32> %vec, i256 %idx, i32 %x) sanitize_memory {
95-
%vec1 = insertelement <4 x i32> %vec, i32 %x, i256 %idx
96-
ret <4 x i32> %vec1
97-
}
98-
; CHECK-LABEL: @test256(
99-
; CHECK: call void @__msan_maybe_warning_N(ptr %{{.*}}, i64 zeroext 32, i32 zeroext 0)
82+
; CHECK: call void @__msan_warning_noreturn
10083
; CHECK: ret <4 x i32>
10184

10285
define <4 x i32> @testUndef(<4 x i32> %vec, i32 %x) sanitize_memory {

0 commit comments

Comments
 (0)