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++; }
Value* code_emitter::emit_sizeof (Type *type) { Value *size = builder->CreateGEP(ConstantPointerNull::get(PointerType::getUnqual(type)), make_int_const(1)); return builder->CreatePtrToInt(size, sizeof(gpointer) == 4 ? Type::Int32Ty : Type::Int64Ty); }