diff options
| author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2016-07-01 22:49:59 +0000 |
|---|---|---|
| committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2016-07-01 22:49:59 +0000 |
| commit | b736335dc3e3aca2c2dd0cfb676d00e119e3cc91 (patch) | |
| tree | 36dec7d3b49caa24a9eea094ceb60c05363b183d | |
| parent | 327bb5ad82328bb92907bb2acf87e2282593e1e4 (diff) | |
| download | bcm5719-llvm-b736335dc3e3aca2c2dd0cfb676d00e119e3cc91.tar.gz bcm5719-llvm-b736335dc3e3aca2c2dd0cfb676d00e119e3cc91.zip | |
[msan] Fix __msan_maybe_ for non-standard type sizes.
Fix incorrect calculation of the type size for __msan_maybe_warning_N
call that resulted in an invalid (narrowing) zext instruction and
"Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed."
Only happens in very large functions (with more than 3500 MSan
checks) operating on integer types that are not power-of-two.
llvm-svn: 274395
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp | 2 | ||||
| -rw-r--r-- | llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll | 85 |
2 files changed, 86 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 30c8f023cb2..970f9ab86e8 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -610,7 +610,7 @@ CreateVarArgHelper(Function &Func, MemorySanitizer &Msan, unsigned TypeSizeToSizeIndex(unsigned TypeSize) { if (TypeSize <= 8) return 0; - return Log2_32_Ceil(TypeSize / 8); + return Log2_32_Ceil((TypeSize + 7) / 8); } /// This class does all the work for a given function. Store and Load diff --git a/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll b/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll new file mode 100644 index 00000000000..2a3cbf70ea5 --- /dev/null +++ b/llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll @@ -0,0 +1,85 @@ +; RUN: opt < %s -msan -msan-instrumentation-with-call-threshold=0 -S | FileCheck %s + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define <4 x i32> @test1(<4 x i32> %vec, i1 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i1 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test1( +; CHECK: %[[A:.*]] = zext i1 {{.*}} to i8 +; CHECK: call void @__msan_maybe_warning_1(i8 %[[A]], i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test2(<4 x i32> %vec, i2 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i2 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test2( +; CHECK: %[[A:.*]] = zext i2 {{.*}} to i8 +; CHECK: call void @__msan_maybe_warning_1(i8 %[[A]], i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test8(<4 x i32> %vec, i8 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i8 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test8( +; zext i8 -> i8 unnecessary. +; CHECK: call void @__msan_maybe_warning_1(i8 %{{.*}}, i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test9(<4 x i32> %vec, i9 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i9 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test9( +; CHECK: %[[A:.*]] = zext i9 {{.*}} to i16 +; CHECK: call void @__msan_maybe_warning_2(i16 %[[A]], i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test16(<4 x i32> %vec, i16 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i16 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test16( +; CHECK: call void @__msan_maybe_warning_2(i16 %{{.*}}, i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test17(<4 x i32> %vec, i17 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i17 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test17( +; CHECK: %[[A:.*]] = zext i17 {{.*}} to i32 +; CHECK: call void @__msan_maybe_warning_4(i32 %[[A]], i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test42(<4 x i32> %vec, i42 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i42 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test42( +; CHECK: %[[A:.*]] = zext i42 {{.*}} to i64 +; CHECK: call void @__msan_maybe_warning_8(i64 %[[A]], i32 0) +; CHECK: ret <4 x i32> + +define <4 x i32> @test64(<4 x i32> %vec, i64 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i64 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test64( +; CHECK: call void @__msan_maybe_warning_8(i64 %{{.*}}, i32 0) +; CHECK: ret <4 x i32> + +; Type size too large => inline check. +define <4 x i32> @test65(<4 x i32> %vec, i65 %idx, i32 %x) sanitize_memory { + %vec1 = insertelement <4 x i32> %vec, i32 %x, i65 %idx + ret <4 x i32> %vec1 +} +; CHECK-LABEL: @test65( +; CHECK-NOT: call void @__msan_maybe_warning_ +; CHECK: icmp ne i65 %{{.*}}, 0 +; CHECK-NOT: call void @__msan_maybe_warning_ +; CHECK: ret <4 x i32>
\ No newline at end of file |

