Ejemplo n.º 1
0
void DataChecks::CreateCrossCheck(IRBuilder<> &Builder, Value *V) {
  IntegerType *PtrIntTy = Builder.getIntPtrTy(*DL);

  // Cast the value to IntPtrType
  auto *VTy = V->getType();
  if (VTy->isPointerTy())
    V = Builder.CreatePtrToInt(V, PtrIntTy);
  else
    V = Builder.CreateZExtOrTrunc(V, PtrIntTy);

  // Call the check function.
  // TODO: Optimize by inlining the call?
  if (XCheckLog) {
    DebugLoc Loc = Builder.GetInsertPoint()->getDebugLoc();
    Value *caller = Builder.CreateGlobalStringPtr(Builder.GetInsertBlock()->getParent()->getName());
    Value *line, *col, *file;
    if (Loc) {
      line = Builder.getInt32(Loc.getLine());
      col = Builder.getInt32(Loc.getCol());
      file = Builder.CreateGlobalStringPtr(Loc->getFilename());
    } else {
      line = Builder.getInt32(-1);
      col = Builder.getInt32(-1);
      file = Builder.CreateGlobalStringPtr("unknown");
    }
    Builder.CreateCall(CheckFnTy, CheckFn, { caller, file, line, col, V });
  } else {
    Builder.CreateCall(CheckFnTy, CheckFn, {V});
  }

  NumCrossChecks++;
}