[llvm] af93157 - [DFSan] Handle landingpad inst explicitly as zero shadow.

Andrew Browne via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 15 18:30:00 PDT 2021


Author: Andrew Browne
Date: 2021-06-15T18:28:20-07:00
New Revision: af93157625ef26679883a17711b53aac8521306c

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

LOG: [DFSan] Handle landingpad inst explicitly as zero shadow.

Before this change, DFSan was relying fallback cases when getting origin
address.

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
    llvm/test/Instrumentation/DataFlowSanitizer/call.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index af4d43378e437..9b24f1139d9a5 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -721,6 +721,7 @@ class DFSanVisitor : public InstVisitor<DFSanVisitor> {
   void visitBitCastInst(BitCastInst &BCI);
   void visitCastInst(CastInst &CI);
   void visitCmpInst(CmpInst &CI);
+  void visitLandingPadInst(LandingPadInst &LPI);
   void visitGetElementPtrInst(GetElementPtrInst &GEPI);
   void visitLoadInst(LoadInst &LI);
   void visitStoreInst(StoreInst &SI);
@@ -2561,6 +2562,22 @@ void DFSanVisitor::visitCmpInst(CmpInst &CI) {
   }
 }
 
+void DFSanVisitor::visitLandingPadInst(LandingPadInst &LPI) {
+  // We do not need to track data through LandingPadInst.
+  //
+  // For the C++ exceptions, if a value is thrown, this value will be stored
+  // in a memory location provided by __cxa_allocate_exception(...) (on the
+  // throw side) or  __cxa_begin_catch(...) (on the catch side).
+  // This memory will have a shadow, so with the loads and stores we will be
+  // able to propagate labels on data thrown through exceptions, without any
+  // special handling of the LandingPadInst.
+  //
+  // The second element in the pair result of the LandingPadInst is a
+  // register value, but it is for a type ID and should never be tainted.
+  DFSF.setShadow(&LPI, DFSF.DFS.getZeroShadow(&LPI));
+  DFSF.setOrigin(&LPI, DFSF.DFS.ZeroOrigin);
+}
+
 void DFSanVisitor::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
   if (ClCombineOffsetLabelsOnGEP) {
     visitInstOperands(GEPI);

diff  --git a/llvm/test/Instrumentation/DataFlowSanitizer/call.ll b/llvm/test/Instrumentation/DataFlowSanitizer/call.ll
index feb8ff6910581..8766c64a1bbdc 100644
--- a/llvm/test/Instrumentation/DataFlowSanitizer/call.ll
+++ b/llvm/test/Instrumentation/DataFlowSanitizer/call.ll
@@ -48,7 +48,7 @@ lpad:
           catch i8* null
   %1 = extractvalue { i8*, i32 } %0, 0
 
-  ; CHECK: store {{.*}} @__dfsan_arg_tls
+  ; CHECK: store i8 0,{{.*}} @__dfsan_arg_tls
   ; CHECK: call {{.*}} @"dfs$__cxa_begin_catch"
   ; CHECK: load {{.*}} @__dfsan_retval_tls
   %2 = tail call i8* @__cxa_begin_catch(i8* %1)


        


More information about the llvm-commits mailing list