Ensures further conditional branch tainting instructions are added in the proper...
authorPeizhao Ou <peizhaoo@uci.edu>
Wed, 7 Mar 2018 21:31:50 +0000 (13:31 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Wed, 7 Mar 2018 21:31:50 +0000 (13:31 -0800)
lib/CodeGen/CodeGenPrepare.cpp

index 5b1f8a0..f9b3b2d 100644 (file)
@@ -801,12 +801,6 @@ void TaintRelaxedLoads(Instruction* UsageInst, Instruction* InsertPoint) {
   Type* TargetIntegerType =
       IntegerType::get(UsageInst->getContext(),
                        BB->getModule()->getDataLayout().getPointerSizeInBits());
-  if (UsageInst->getType() == TargetIntegerType) {
-    AndTarget = UsageInst;
-  } else {
-    IRBuilder<true, NoFolder> Builder(InsertPoint);
-    AndTarget = createCast(Builder, UsageInst, TargetIntegerType);
-  }
 
   // Check whether InsertPoint is a added fake conditional branch.
   BranchInst* BI = nullptr;
@@ -831,6 +825,11 @@ void TaintRelaxedLoads(Instruction* UsageInst, Instruction* InsertPoint) {
           // Now we have a previously added fake cond branch.
           auto* Op00 = Op0->getOperand(0);
           IRBuilder<true, NoFolder> Builder(CmpInst);
+          if (UsageInst->getType() == TargetIntegerType) {
+            AndTarget = UsageInst;
+          } else {
+            AndTarget = createCast(Builder, UsageInst, TargetIntegerType);
+          }
           AndTarget = Builder.CreateAnd(Op00, AndTarget);
           auto* AndZero = dyn_cast<Instruction>(Builder.CreateAnd(
               AndTarget, Constant::getNullValue(AndTarget->getType())));
@@ -842,6 +841,11 @@ void TaintRelaxedLoads(Instruction* UsageInst, Instruction* InsertPoint) {
   }
 
   IRBuilder<true, NoFolder> Builder(InsertPoint);
+  if (UsageInst->getType() == TargetIntegerType) {
+    AndTarget = UsageInst;
+  } else {
+    AndTarget = createCast(Builder, UsageInst, TargetIntegerType);
+  }
   auto* AndZero = dyn_cast<Instruction>(
       Builder.CreateAnd(AndTarget, Constant::getNullValue(AndTarget->getType())));
   auto* FakeCondition = dyn_cast<Instruction>(Builder.CreateICmp(