1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00
llvm-mirror/test/Instrumentation/MemorySanitizer/mul_by_constant.ll
Philip Pfaffe 65df098609 [NewPM] Port Msan
Summary:
Keeping msan a function pass requires replacing the module level initialization:
That means, don't define a ctor function which calls __msan_init, instead just
declare the init function at the first access, and add that to the global ctors
list.

Changes:
- Pull the actual sanitizer and the wrapper pass apart.
- Add a newpm msan pass. The function pass inserts calls to runtime
  library functions, for which it inserts declarations as necessary.
- Update tests.

Caveats:
- There is one test that I dropped, because it specifically tested the
  definition of the ctor.

Reviewers: chandlerc, fedor.sergeev, leonardchan, vitalybuka

Subscribers: sdardis, nemanjai, javed.absar, hiraditya, kbarton, bollu, atanasyan, jsji

Differential Revision: https://reviews.llvm.org/D55647

llvm-svn: 350305
2019-01-03 13:42:44 +00:00

120 lines
3.3 KiB
LLVM

; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan 2>&1 | FileCheck \
; RUN: %s
; RUN: opt < %s -msan -msan-check-access-address=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"
; Check instrumentation mul when one of the operands is a constant.
define i64 @MulConst(i64 %x) sanitize_memory {
entry:
%y = mul i64 %x, 42949672960000
ret i64 %y
}
; 42949672960000 = 2**32 * 10000
; 36 trailing zero bits
; 68719476736 = 2**36
; CHECK-LABEL: @MulConst(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], 68719476736
; CHECK: store i64 [[B]], i64* {{.*}} @__msan_retval_tls
define i64 @MulZero(i64 %x) sanitize_memory {
entry:
%y = mul i64 %x, 0
ret i64 %y
}
; CHECK-LABEL: @MulZero(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], 0{{$}}
; CHECK: store i64 [[B]], i64* {{.*}} @__msan_retval_tls
define i64 @MulNeg(i64 %x) sanitize_memory {
entry:
%y = mul i64 %x, -16
ret i64 %y
}
; CHECK-LABEL: @MulNeg(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], 16
; CHECK: store i64 [[B]], i64* {{.*}} @__msan_retval_tls
define i64 @MulNeg2(i64 %x) sanitize_memory {
entry:
%y = mul i64 %x, -48
ret i64 %y
}
; CHECK-LABEL: @MulNeg2(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], 16
; CHECK: store i64 [[B]], i64* {{.*}} @__msan_retval_tls
define i64 @MulOdd(i64 %x) sanitize_memory {
entry:
%y = mul i64 %x, 12345
ret i64 %y
}
; CHECK-LABEL: @MulOdd(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], 1
; CHECK: store i64 [[B]], i64* {{.*}} @__msan_retval_tls
define i64 @MulLarge(i64 %x) sanitize_memory {
entry:
%y = mul i64 %x, -9223372036854775808
ret i64 %y
}
; -9223372036854775808 = 0x7000000000000000
; CHECK-LABEL: @MulLarge(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], -9223372036854775808
; CHECK: store i64 [[B]], i64* {{.*}} @__msan_retval_tls
define <4 x i32> @MulVectorConst(<4 x i32> %x) sanitize_memory {
entry:
%y = mul <4 x i32> %x, <i32 3072, i32 0, i32 -16, i32 -48>
ret <4 x i32> %y
}
; CHECK-LABEL: @MulVectorConst(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul <4 x i32> [[A]], <i32 1024, i32 0, i32 16, i32 16>
; CHECK: store <4 x i32> [[B]], <4 x i32>* {{.*}} @__msan_retval_tls
; The constant in multiplication does not have to be a literal integer constant.
@X = linkonce_odr global i8* null
define i64 @MulNonIntegerConst(i64 %a) sanitize_memory {
%mul = mul i64 %a, ptrtoint (i8** @X to i64)
ret i64 %mul
}
; CHECK-LABEL: @MulNonIntegerConst(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul i64 [[A]], 1
; CHECK: store i64 [[B]], {{.*}}@__msan_retval_tls
define <2 x i64> @MulNonIntegerVectorConst(<2 x i64> %a) sanitize_memory {
%mul = mul <2 x i64> %a, <i64 3072, i64 ptrtoint (i8** @X to i64)>
ret <2 x i64> %mul
}
; CHECK-LABEL: @MulNonIntegerVectorConst(
; CHECK: [[A:%.*]] = load {{.*}} @__msan_param_tls
; CHECK: [[B:%.*]] = mul <2 x i64> [[A]], <i64 1024, i64 1>
; CHECK: store <2 x i64> [[B]], {{.*}}@__msan_retval_tls