[llvm] 1faff79 - [DFSan] Properly set argument ABI attributes

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 2 22:24:58 PDT 2021


Author: Arthur Eubanks
Date: 2021-06-02T22:24:46-07:00
New Revision: 1faff79b7ca144e505da6bc74aa2b2f7cffbbf23

URL: https://github.com/llvm/llvm-project/commit/1faff79b7ca144e505da6bc74aa2b2f7cffbbf23
DIFF: https://github.com/llvm/llvm-project/commit/1faff79b7ca144e505da6bc74aa2b2f7cffbbf23.diff

LOG: [DFSan] Properly set argument ABI attributes

Calls must properly match argument ABI attributes with the callee.

Found via D103412.

Reviewed By: morehouse

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
    llvm/test/Instrumentation/DataFlowSanitizer/memset.ll
    llvm/test/Instrumentation/DataFlowSanitizer/origin_mem_intrinsic.ll
    llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
    llvm/test/Instrumentation/DataFlowSanitizer/origin_store_threshold.ll
    llvm/test/Instrumentation/DataFlowSanitizer/origin_track_load.ll
    llvm/test/Instrumentation/DataFlowSanitizer/shadow-args-zext.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index bd4f32a472fc..f28d757aa6ae 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1241,6 +1241,7 @@ DataFlowSanitizer::buildWrapperFunction(Function *F, StringRef NewFName,
     std::vector<Value *> Args(ArgIt, ArgIt + FT->getNumParams());
 
     CallInst *CI = CallInst::Create(F, Args, "", BB);
+    CI->setAttributes(F->getAttributes());
     if (FT->getReturnType()->isVoidTy())
       ReturnInst::Create(*Ctx, BB);
     else
@@ -2480,13 +2481,17 @@ void DFSanVisitor::visitLoadInst(LoadInst &LI) {
 Value *DFSanFunction::updateOriginIfTainted(Value *Shadow, Value *Origin,
                                             IRBuilder<> &IRB) {
   assert(DFS.shouldTrackOrigins());
-  return IRB.CreateCall(DFS.DFSanChainOriginIfTaintedFn, {Shadow, Origin});
+  auto *CB = IRB.CreateCall(DFS.DFSanChainOriginIfTaintedFn, {Shadow, Origin});
+  CB->setAttributes(CB->getCalledFunction()->getAttributes());
+  return CB;
 }
 
 Value *DFSanFunction::updateOrigin(Value *V, IRBuilder<> &IRB) {
   if (!DFS.shouldTrackOrigins())
     return V;
-  return IRB.CreateCall(DFS.DFSanChainOriginFn, V);
+  auto *CB = IRB.CreateCall(DFS.DFSanChainOriginFn, V);
+  CB->setAttributes(CB->getCalledFunction()->getAttributes());
+  return CB;
 }
 
 Value *DFSanFunction::originToIntptr(IRBuilder<> &IRB, Value *Origin) {
@@ -2561,10 +2566,11 @@ void DFSanFunction::storeOrigin(Instruction *Pos, Value *Addr, uint64_t Size,
   }
 
   if (shouldInstrumentWithCall()) {
-    IRB.CreateCall(DFS.DFSanMaybeStoreOriginFn,
-                   {CollapsedShadow,
-                    IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()),
-                    ConstantInt::get(DFS.IntptrTy, Size), Origin});
+    auto *CB = IRB.CreateCall(DFS.DFSanMaybeStoreOriginFn,
+                              {CollapsedShadow,
+                               IRB.CreatePointerCast(Addr, IRB.getInt8PtrTy()),
+                               ConstantInt::get(DFS.IntptrTy, Size), Origin});
+    CB->setAttributes(CB->getCalledFunction()->getAttributes());
   } else {
     Value *Cmp = convertToBool(CollapsedShadow, IRB, "_dfscmp");
     Instruction *CheckTerm = SplitBlockAndInsertIfThen(
@@ -2937,11 +2943,12 @@ void DFSanVisitor::visitMemSetInst(MemSetInst &I) {
   Value *ValOrigin = DFSF.DFS.shouldTrackOrigins()
                          ? DFSF.getOrigin(I.getValue())
                          : DFSF.DFS.ZeroOrigin;
-  IRB.CreateCall(
+  auto *CB = IRB.CreateCall(
       DFSF.DFS.DFSanSetLabelFn,
       {ValShadow, ValOrigin,
        IRB.CreateBitCast(I.getDest(), Type::getInt8PtrTy(*DFSF.DFS.Ctx)),
        IRB.CreateZExtOrTrunc(I.getLength(), DFSF.DFS.IntptrTy)});
+  CB->setAttributes(CB->getCalledFunction()->getAttributes());
 }
 
 void DFSanVisitor::visitMemTransferInst(MemTransferInst &I) {

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/memset.ll b/llvm/test/Instrumentation/DataFlowSanitizer/memset.ll
index 01ea56e9469f..933ced70450b 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/memset.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/memset.ll
@@ -10,7 +10,7 @@ declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1)
 define void @ms(i8* %p, i8 %v) {
   ; CHECK-LABEL: @"dfs$ms"
   ; CHECK-SAME: (i8* %0, i8 %1, i[[#SBITS]] %2, i[[#SBITS]] %3)
-  ; CHECK: call void @__dfsan_set_label(i[[#SBITS]] %3, i32 0, i8* %0, i64 1)
+  ; CHECK: call void @__dfsan_set_label(i[[#SBITS]] zeroext %3, i32 zeroext 0, i8* %0, i64 1)
   call void @llvm.memset.p0i8.i64(i8* %p, i8 %v, i64 1, i1 1)
   ret void
 }

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/origin_mem_intrinsic.ll b/llvm/test/Instrumentation/DataFlowSanitizer/origin_mem_intrinsic.ll
index 6edb6d566b0f..eaf0bf940308 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/origin_mem_intrinsic.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/origin_mem_intrinsic.ll
@@ -36,7 +36,7 @@ define void @memset(i8* %p, i8 %v) {
   ; CHECK: @"dfs$memset"
   ; CHECK: [[O:%.*]] = load i32, i32* getelementptr inbounds ([200 x i32], [200 x i32]* @__dfsan_arg_origin_tls, i64 0, i64 1), align 4
   ; CHECK: [[S:%.*]] = load i[[#SBITS]], i[[#SBITS]]* inttoptr (i64 add (i64 ptrtoint ([100 x i64]* @__dfsan_arg_tls to i64), i64 2) to i[[#SBITS]]*), align [[ALIGN:2]]
-  ; CHECK: call void @__dfsan_set_label(i[[#SBITS]] [[S]], i32 [[O]], i8* %p, i64 1)
+  ; CHECK: call void @__dfsan_set_label(i[[#SBITS]] zeroext [[S]], i32 zeroext [[O]], i8* %p, i64 1)
   call void @llvm.memset.p0i8.i64(i8* %p, i8 %v, i64 1, i1 1)
   ret void
-}
\ No newline at end of file
+}

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll b/llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
index 72d7c6e81645..f670a80841f3 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/origin_store.ll
@@ -63,7 +63,7 @@ define void @store_nonzero_to_escaped_alloca(i16 %a) {
   ; CHECK:        %_dfscmp = icmp ne i[[#SBITS]] %[[#AS]], 0
   ; CHECK-NEXT:   br i1 %_dfscmp, label %[[L1:.*]], label %[[L2:.*]],
   ; CHECK:       [[L1]]:
-  ; CHECK-NEXT:   %[[#NO:]] = call i32 @__dfsan_chain_origin(i32 %[[#AO]])
+  ; CHECK-NEXT:   %[[#NO:]] = call zeroext i32 @__dfsan_chain_origin(i32 zeroext %[[#AO]])
   ; CHECK-NEXT:   store i32 %[[#NO]], i32* %[[#ORIGIN_PTR]], align 4
   ; CHECK-NEXT:   br label %[[L2]]
   ; CHECK:       [[L2]]:
@@ -91,7 +91,7 @@ define void @store64_align8(i64* %p, i64 %a) {
   ; CHECK:       %_dfscmp = icmp ne i[[#SBITS]] %[[#AS]], 0
   ; CHECK-NEXT:  br i1 %_dfscmp, label %[[L1:.*]], label %[[L2:.*]],
   ; CHECK:      [[L1]]:
-  ; CHECK-NEXT:  %[[#NO:]] = call i32 @__dfsan_chain_origin(i32 %[[#AO]])
+  ; CHECK-NEXT:  %[[#NO:]] = call zeroext i32 @__dfsan_chain_origin(i32 zeroext %[[#AO]])
   ; CHECK-NEXT:  %[[#NO_ZEXT:]] = zext i32 %[[#NO]] to i64
   ; CHECK-NEXT:  %[[#NO_SHL:]] = shl i64 %[[#NO_ZEXT]], 32
   ; CHECK-NEXT:  %[[#NO2:]] = or i64 %[[#NO_ZEXT]], %[[#NO_SHL]]
@@ -121,7 +121,7 @@ define void @store64_align2(i64* %p, i64 %a) {
   ; CHECK:      %_dfscmp = icmp ne i[[#SBITS]] %[[#AS]], 0
   ; CHECK-NEXT: br i1 %_dfscmp, label %[[L1:.*]], label %[[L2:.*]],
   ; CHECK:     [[L1]]:
-  ; CHECK-NEXT: %[[#NO:]] = call i32 @__dfsan_chain_origin(i32 %[[#AO]])
+  ; CHECK-NEXT: %[[#NO:]] = call zeroext i32 @__dfsan_chain_origin(i32 zeroext %[[#AO]])
   ; CHECK-NEXT: store i32 %[[#NO]], i32* %[[#O_PTR0:]], align 4
   ; CHECK-NEXT: %[[#O_PTR1:]] = getelementptr i32, i32* %[[#O_PTR0]], i32 1
   ; CHECK-NEXT: store i32 %[[#NO]], i32* %[[#O_PTR1]], align 4
@@ -148,7 +148,7 @@ define void @store96_align8(i96* %p, i96 %a) {
   ; CHECK:      %_dfscmp = icmp ne i[[#SBITS]] %[[#AS]], 0
   ; CHECK-NEXT: br i1 %_dfscmp, label %[[L1:.*]], label %[[L2:.*]],
   ; CHECK:     [[L1]]:
-  ; CHECK-NEXT: %[[#NO:]] = call i32 @__dfsan_chain_origin(i32 %[[#AO]])
+  ; CHECK-NEXT: %[[#NO:]] = call zeroext i32 @__dfsan_chain_origin(i32 zeroext %[[#AO]])
   ; CHECK-NEXT: %[[#NO_ZEXT:]] = zext i32 %[[#NO]] to i64
   ; CHECK-NEXT: %[[#NO_SHL:]] = shl i64 %[[#NO_ZEXT]], 32
   ; CHECK-NEXT: %[[#NO2:]] = or i64 %[[#NO_ZEXT]], %[[#NO_SHL]]

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/origin_store_threshold.ll b/llvm/test/Instrumentation/DataFlowSanitizer/origin_store_threshold.ll
index ce1ec49e0f9f..393ad5c75074 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/origin_store_threshold.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/origin_store_threshold.ll
@@ -14,7 +14,7 @@ define void @store_threshold([2 x i64]* %p, [2 x i64] %a) {
   ; CHECK: [[AS1:%.*]] = extractvalue [2 x i[[#SBITS]]] [[AS]], 1
   ; CHECK: [[AS01:%.*]] = or i[[#SBITS]] [[AS0]], [[AS1]]
   ; CHECK: [[ADDR:%.*]] = bitcast [2 x i64]* %p to i8*
-  ; CHECK: call void @__dfsan_maybe_store_origin(i[[#SBITS]] [[AS01]], i8* [[ADDR]], i64 16, i32 [[AO]])
+  ; CHECK: call void @__dfsan_maybe_store_origin(i[[#SBITS]] zeroext [[AS01]], i8* [[ADDR]], i64 16, i32 zeroext [[AO]])
   ; CHECK: store [2 x i64] %a, [2 x i64]* %p, align 8
 
   store [2 x i64] %a, [2 x i64]* %p

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/origin_track_load.ll b/llvm/test/Instrumentation/DataFlowSanitizer/origin_track_load.ll
index f16a96aa76cb..522af8a0f5a8 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/origin_track_load.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/origin_track_load.ll
@@ -17,7 +17,7 @@ define i64 @load64(i64* %p) {
   ; CHECK-NEXT: %[[#LABEL_ORIGIN_H32:]] = lshr i64 %[[#LABEL_ORIGIN]], 32
   ; CHECK-NEXT: %[[#LABEL:]] = trunc i64 %[[#LABEL_ORIGIN_H32]] to i[[#SBITS]]
   ; CHECK-NEXT: %[[#ORIGIN:]] = trunc i64 %[[#LABEL_ORIGIN]] to i32
-  ; CHECK-NEXT: %[[#ORIGIN_CHAINED:]] = call i32 @__dfsan_chain_origin_if_tainted(i[[#SBITS]] %[[#LABEL]], i32 %[[#ORIGIN]])
+  ; CHECK-NEXT: %[[#ORIGIN_CHAINED:]] = call zeroext i32 @__dfsan_chain_origin_if_tainted(i[[#SBITS]] zeroext %[[#LABEL]], i32 zeroext %[[#ORIGIN]])
 
   ; CHECK-NEXT: %[[#LABEL:]] = or i[[#SBITS]] %[[#LABEL]], %[[#PS]]
   ; CHECK-NEXT: %[[#NZ:]] = icmp ne i[[#SBITS]] %[[#PS]], 0

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/shadow-args-zext.ll b/llvm/test/Instrumentation/DataFlowSanitizer/shadow-args-zext.ll
index 9c7440e5ebaf..3cea914e8989 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/shadow-args-zext.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/shadow-args-zext.ll
@@ -41,15 +41,15 @@ entry:
 
 declare zeroext i16 @dfsan_get_label(i64 signext)
 ; CHECK-LABEL: @"dfsw$dfsan_get_label"
-; CHECK: %{{.*}} = call i16 @__dfsw_dfsan_get_label(i64 %0, i[[#SBITS]] zeroext %1, i[[#SBITS]]* %{{.*}})
+; CHECK: %{{.*}} = call zeroext i16 @__dfsw_dfsan_get_label(i64 signext %0, i[[#SBITS]] zeroext %1, i[[#SBITS]]* %{{.*}})
 
 declare zeroext i16 @k2(i64 signext, i64 signext)
 ; CHECK-LABEL: @"dfsw$k2"
-; CHECK: %{{.*}} = call i16 @__dfsw_k2(i64 %{{.*}}, i64 %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]]* %{{.*}})
+; CHECK: %{{.*}} = call zeroext i16 @__dfsw_k2(i64 signext %{{.*}}, i64 signext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]]* %{{.*}})
 
 declare zeroext i16 @k4(i64 signext, i64 signext, i64 signext, i64 signext)
 ; CHECK-LABEL: @"dfsw$k4"
-; CHECK: %{{.*}} = call i16 @__dfsw_k4(i64 %{{.*}}, i64 %{{.*}}, i64  %{{.*}}, i64 %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]]* %{{.*}})
+; CHECK: %{{.*}} = call zeroext i16 @__dfsw_k4(i64 signext %{{.*}}, i64 signext %{{.*}}, i64 signext %{{.*}}, i64 signext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]] zeroext %{{.*}}, i[[#SBITS]]* %{{.*}})
 
 
 ; CHECK: declare zeroext i16 @__dfsw_dfsan_get_label(i64 signext, i[[#SBITS]], i[[#SBITS]]*)


        


More information about the llvm-commits mailing list