MCPcopy Create free account
hub / github.com/avast/retdec / changeObjectDeclarationType

Method changeObjectDeclarationType

src/bin2llvmir/utils/ir_modifier.cpp:724–790  ·  view source on GitHub ↗

* Change @c val declaration to @c toType. Only the object type is changed, * not its usages. Because of this, it is not safe to use this function alone. * This function is not public, i.e. accessible from other modules. * @param objf Object file for this object -- needed to initialize it values. * @param val Value which type to change. * @param toType Type to change it to. * @param init

Source from the content-addressed store, hash-verified

722 * value's type can be mutated, or a new object if it cannot.
723 */
724llvm::Value* IrModifier::changeObjectDeclarationType(
725 FileImage* objf,
726 llvm::Value* val,
727 llvm::Type* toType,
728 llvm::Constant* init,
729 bool wideString)
730{
731 if (val->getType() == toType)
732 {
733 return val;
734 }
735
736 if (auto* alloca = dyn_cast<AllocaInst>(val))
737 {
738 auto* ret = new AllocaInst(
739 toType,
740 Abi::DEFAULT_ADDR_SPACE,
741 alloca->getName(),
742 alloca);
743 ret->takeName(alloca);
744 return ret;
745 }
746 else if (auto* ogv = dyn_cast<GlobalVariable>(val))
747 {
748 if (init == nullptr)
749 {
750 init = objf->getConstant(
751 toType,
752 _config->getGlobalAddress(ogv),
753 wideString);
754 }
755
756 auto* old = ogv;
757 ogv = new GlobalVariable(
758 *_module,
759 init ? init->getType() : toType,
760 old->isConstant(),
761 old->getLinkage(),
762 init,
763 old->getName());
764 ogv->takeName(old);
765
766 auto* ecgv = _config->getConfigGlobalVariable(ogv);
767 if (ecgv)
768 {
769 retdec::common::Object cgv(
770 ecgv->getName(),
771 ecgv->getStorage());
772 cgv.type.setLlvmIr(
773 llvmObjToString(ogv->getType()->getPointerElementType()));
774 cgv.type.setIsWideString(wideString);
775 _config->getConfig().globals.insert(cgv);
776 }
777
778 return ogv;
779 }
780 else if (auto* arg = dyn_cast<Argument>(val))
781 {

Callers

nothing calls this directly

Calls 11

getConstantMethod · 0.80
getGlobalAddressMethod · 0.80
isConstantMethod · 0.80
setLlvmIrMethod · 0.80
setIsWideStringMethod · 0.80
llvmObjToStringFunction · 0.70
getTypeMethod · 0.45
getNameMethod · 0.45
insertMethod · 0.45
getConfigMethod · 0.45

Tested by

no test coverage detected