[dfsan] Correctly handle loads and stores of zero size.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 1 Aug 2014 21:18:18 +0000 (21:18 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 1 Aug 2014 21:18:18 +0000 (21:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214561 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
test/Instrumentation/DataFlowSanitizer/load.ll
test/Instrumentation/DataFlowSanitizer/store.ll

index 35057cdd47e9783c70f482ad95e5c49cc9025b28..aa68ff59b4b0321b26f6abb4820f0ee8990fa4f5 100644 (file)
@@ -1092,6 +1092,11 @@ Value *DFSanFunction::loadShadow(Value *Addr, uint64_t Size, uint64_t Align,
 
 void DFSanVisitor::visitLoadInst(LoadInst &LI) {
   uint64_t Size = DFSF.DFS.DL->getTypeStoreSize(LI.getType());
 
 void DFSanVisitor::visitLoadInst(LoadInst &LI) {
   uint64_t Size = DFSF.DFS.DL->getTypeStoreSize(LI.getType());
+  if (Size == 0) {
+    DFSF.setShadow(&LI, DFSF.DFS.ZeroShadow);
+    return;
+  }
+
   uint64_t Align;
   if (ClPreserveAlignment) {
     Align = LI.getAlignment();
   uint64_t Align;
   if (ClPreserveAlignment) {
     Align = LI.getAlignment();
@@ -1166,6 +1171,9 @@ void DFSanFunction::storeShadow(Value *Addr, uint64_t Size, uint64_t Align,
 void DFSanVisitor::visitStoreInst(StoreInst &SI) {
   uint64_t Size =
       DFSF.DFS.DL->getTypeStoreSize(SI.getValueOperand()->getType());
 void DFSanVisitor::visitStoreInst(StoreInst &SI) {
   uint64_t Size =
       DFSF.DFS.DL->getTypeStoreSize(SI.getValueOperand()->getType());
+  if (Size == 0)
+    return;
+
   uint64_t Align;
   if (ClPreserveAlignment) {
     Align = SI.getAlignment();
   uint64_t Align;
   if (ClPreserveAlignment) {
     Align = SI.getAlignment();
index 6cd5151b1260b814ff3de2b5c936b307aec29dc1..832422437a8ec924f416024b657e1a90911394a8 100644 (file)
@@ -2,6 +2,18 @@
 ; RUN: opt < %s -dfsan -dfsan-combine-pointer-labels-on-load=0 -S | FileCheck %s --check-prefix=NO_COMBINE_PTR_LABEL
 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"
 
 ; RUN: opt < %s -dfsan -dfsan-combine-pointer-labels-on-load=0 -S | FileCheck %s --check-prefix=NO_COMBINE_PTR_LABEL
 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"
 
+define {} @load0({}* %p) {
+  ; COMBINE_PTR_LABEL: @"dfs$load0"
+  ; COMBINE_PTR_LABEL: load
+  ; COMBINE_PTR_LABEL-NOT: load
+
+  ; NO_COMBINE_PTR_LABEL: @"dfs$load0"
+  ; NO_COMBINE_PTR_LABEL: load
+  ; NO_COMBINE_PTR_LABEL-NOT: load
+  %a = load {}* %p
+  ret {} %a
+}
+
 define i8 @load8(i8* %p) {
   ; COMBINE_PTR_LABEL: @"dfs$load8"
   ; COMBINE_PTR_LABEL: load i16*
 define i8 @load8(i8* %p) {
   ; COMBINE_PTR_LABEL: @"dfs$load8"
   ; COMBINE_PTR_LABEL: load i16*
@@ -152,4 +164,4 @@ define i64 @load64(i64* %p) {
 
   %a = load i64* %p
   ret i64 %a
 
   %a = load i64* %p
   ret i64 %a
-}
\ No newline at end of file
+}
index 8060537f3152af51f5270f61710e77648659a2b2..d14bdb6fb61d7ff562f60bb8061800be6db30f5e 100644 (file)
@@ -2,6 +2,19 @@
 ; RUN: opt < %s -dfsan -dfsan-combine-pointer-labels-on-store=0 -S | FileCheck %s --check-prefix=NO_COMBINE_PTR_LABEL
 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"
 
 ; RUN: opt < %s -dfsan -dfsan-combine-pointer-labels-on-store=0 -S | FileCheck %s --check-prefix=NO_COMBINE_PTR_LABEL
 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"
 
+define void @store0({} %v, {}* %p) {
+  ; COMBINE_PTR_LABEL: @"dfs$store0"
+  ; COMBINE_PTR_LABEL: store
+  ; COMBINE_PTR_LABEL-NOT: store
+
+  ; NO_COMBINE_PTR_LABEL: @"dfs$store0"
+  ; NO_COMBINE_PTR_LABEL: store
+  ; NO_COMBINE_PTR_LABEL-NOT: store
+
+  store {} %v, {}* %p
+  ret void
+}
+
 define void @store8(i8 %v, i8* %p) {
   ; NO_COMBINE_PTR_LABEL: @"dfs$store8"
   ; NO_COMBINE_PTR_LABEL: load i16* {{.*}} @__dfsan_arg_tls
 define void @store8(i8 %v, i8* %p) {
   ; NO_COMBINE_PTR_LABEL: @"dfs$store8"
   ; NO_COMBINE_PTR_LABEL: load i16* {{.*}} @__dfsan_arg_tls