[msan] Fix handling of byval arguments with large alignment.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 17 Oct 2014 23:29:44 +0000 (23:29 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 17 Oct 2014 23:29:44 +0000 (23:29 +0000)
MSan param-tls slots are 8-byte aligned. This change clips
alignment of memcpy into param-tls to 8.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220101 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/MemorySanitizer.cpp
test/Instrumentation/MemorySanitizer/byval-alignment.ll [new file with mode: 0644]

index 3a311edf5e38178e0103a0636f15518a3f597efc..5a261c62f229587c495e5f2a7815c5547321da60 100644 (file)
@@ -2329,7 +2329,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
         assert(A->getType()->isPointerTy() &&
                "ByVal argument is not a pointer!");
         Size = MS.DL->getTypeAllocSize(A->getType()->getPointerElementType());
-        unsigned Alignment = CS.getParamAlignment(i + 1);
+        unsigned ParamAlignment = CS.getParamAlignment(i + 1);
+        unsigned Alignment = std::min(ParamAlignment, kShadowTLSAlignment);
         Store = IRB.CreateMemCpy(ArgShadowBase,
                                  getShadowPtr(A, Type::getInt8Ty(*MS.C), IRB),
                                  Size, Alignment);
diff --git a/test/Instrumentation/MemorySanitizer/byval-alignment.ll b/test/Instrumentation/MemorySanitizer/byval-alignment.ll
new file mode 100644 (file)
index 0000000..43e204a
--- /dev/null
@@ -0,0 +1,20 @@
+; Test that copy alignment for byval arguments is limited by param-tls slot alignment.
+
+; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.S = type { i64, i64, i64, [8 x i8] }
+
+; CHECK: [[A:%.*]] = bitcast i64* {{.*}} add {{.*}} ptrtoint {{.*}} @__msan_param_tls {{.*}} i64 8)
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[A]], i8* {{.*}}, i64 32, i32 8, i1 false)
+
+define void @Caller() sanitize_memory {
+entry:
+  %agg.tmp = alloca %struct.S, align 16
+  call void @Callee(i32 1, %struct.S* byval align 16 %agg.tmp)
+  ret void
+}
+
+declare void @Callee(i32, %struct.S* byval align 16)