Skip to content

Commit 25a3875

Browse files
bjjwwangbjjwwang
authored andcommitted
fix a bug of int128 (SVF-tools#1624)
* fix a bug of int128 * wrap integer value function * revise the std::make_pair * Revert "revise the std::make_pair" This reverts commit 75be147. * fix addConstantIntObjNode and addConstantIntValNode * remove getSExt ZExt in SVF-LLVM --------- Co-authored-by: bjjwwang <bjjwwang@github.com>
1 parent c93ac04 commit 25a3875

File tree

10 files changed

+57
-25
lines changed

10 files changed

+57
-25
lines changed

svf-llvm/include/SVF-LLVM/LLVMUtil.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,39 @@ inline bool isCallSite(const Value* val)
5252
return SVFUtil::isa<CallBase>(val);
5353
}
5454

55+
inline double getDoubleValue(const ConstantFP* fpValue) {
56+
double dval = 0;
57+
if (fpValue->isNormalFP())
58+
{
59+
const llvm::fltSemantics& semantics = fpValue->getValueAPF().getSemantics();
60+
if (&semantics == &llvm::APFloat::IEEEhalf() ||
61+
&semantics == &llvm::APFloat::IEEEsingle() ||
62+
&semantics == &llvm::APFloat::IEEEdouble() ||
63+
&semantics == &llvm::APFloat::IEEEquad() ||
64+
&semantics == &llvm::APFloat::x87DoubleExtended())
65+
{
66+
dval = fpValue->getValueAPF().convertToDouble();
67+
}
68+
else
69+
{
70+
assert (false && "Unsupported floating point type");
71+
abort();
72+
}
73+
}
74+
else
75+
{
76+
// other cfp type, like isZero(), isInfinity(), isNegative(), etc.
77+
// do nothing
78+
}
79+
return dval;
80+
}
81+
82+
inline std::pair<s64_t, u64_t> getIntegerValue(const ConstantInt* intValue) {
83+
if (intValue->getBitWidth() <= 64 && intValue->getBitWidth() >= 1)
84+
return std::make_pair(intValue->getSExtValue(), intValue->getZExtValue());
85+
else
86+
return std::make_pair(0,0);
87+
}
5588

5689
/// Return LLVM callsite given a value
5790
inline const CallBase* getLLVMCallSite(const Value* value)

svf-llvm/lib/CppUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ s32_t cppUtil::getVCallIdx(const CallBase* cs)
661661
}
662662
else
663663
{
664-
idx_value = (s32_t)idx->getSExtValue();
664+
idx_value = LLVMUtil::getIntegerValue(idx).first;
665665
}
666666
return idx_value;
667667
}

svf-llvm/lib/DCHG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ std::string DCHGraph::diTypeToStr(const DIType *t)
10871087
int64_t count = -1;
10881088
if (const ConstantInt* ci = sr->getCount().dyn_cast<ConstantInt* >())
10891089
{
1090-
count = ci->getSExtValue();
1090+
count = LLVMUtil::getIntegerValue(ci).first;
10911091
}
10921092

10931093
ss << "[" << count << "]";

svf-llvm/lib/ICFGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void ICFGBuilder::processFunBody(WorkList& worklist)
196196
/// default case is set to -1;
197197
s64_t val = -1;
198198
if (condVal && condVal->getBitWidth() <= 64)
199-
val = condVal->getSExtValue();
199+
val = LLVMUtil::getIntegerValue(condVal).first;
200200
icfg->addConditionalIntraEdge(srcNode, dstNode,val);
201201
}
202202
else

svf-llvm/lib/LLVMModule.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,7 @@ std::vector<const Function* > LLVMModuleSet::getLLVMGlobalFunctions(const Global
704704

705705
if (priority && func)
706706
{
707-
queue.push(LLVMGlobalFunction(priority
708-
->getZExtValue(),
707+
queue.push(LLVMGlobalFunction(LLVMUtil::getIntegerValue(priority).second,
709708
func));
710709
}
711710
}

svf-llvm/lib/ObjTypeInference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void ObjTypeInference::validateTypeCheck(const CallBase *cs)
628628
SVFUtil::dyn_cast<llvm::ConstantInt>(cs->getOperand(1));
629629
assert(pInt && "the second argument is a integer");
630630
u32_t iTyNum = objTyToNumFields(objType);
631-
if (iTyNum >= pInt->getZExtValue())
631+
if (iTyNum >= LLVMUtil::getIntegerValue(pInt).second)
632632
SVFUtil::outs() << SVFUtil::sucMsg("\t SUCCESS :") << dumpValueAndDbgInfo(cs)
633633
<< SVFUtil::pasMsg(" TYPE: ")
634634
<< dumpType(objType) << "\n";

svf-llvm/lib/SVFIRBuilder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ void SVFIRBuilder::initialiseNodes()
247247
}
248248
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
249249
{
250-
pag->addConstantFPValNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second, icfgNode);
250+
pag->addConstantFPValNode(iter->first, LLVMUtil::getDoubleValue(fpValue), iter->second, icfgNode);
251251
llvmModuleSet()->addToLLVMVal2SVFVarMap(
252252
fpValue, pag->getGNode(iter->second));
253253
}
254254
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
255255
{
256-
pag->addConstantIntValNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second, icfgNode);
256+
pag->addConstantIntValNode(iter->first, LLVMUtil::getIntegerValue(intValue), iter->second, icfgNode);
257257
llvmModuleSet()->addToLLVMVal2SVFVarMap(
258258
intValue, pag->getGNode(iter->second));
259259
}
@@ -322,13 +322,13 @@ void SVFIRBuilder::initialiseNodes()
322322
}
323323
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
324324
{
325-
pag->addConstantFPObjNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second);
325+
pag->addConstantFPObjNode(iter->first, LLVMUtil::getDoubleValue(fpValue), iter->second);
326326
llvmModuleSet()->addToLLVMVal2SVFVarMap(
327327
fpValue, pag->getGNode(iter->second));
328328
}
329329
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
330330
{
331-
pag->addConstantIntObjNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second);
331+
pag->addConstantIntObjNode(iter->first, LLVMUtil::getIntegerValue(intValue), iter->second);
332332
llvmModuleSet()->addToLLVMVal2SVFVarMap(
333333
intValue, pag->getGNode(iter->second));
334334
}
@@ -457,17 +457,17 @@ bool SVFIRBuilder::computeGepOffset(const User *V, AccessPath& ap)
457457
// but we can distinguish different field of an array of struct, e.g. s[1].f1 is different from s[0].f2
458458
if(const ArrayType* arrTy = SVFUtil::dyn_cast<ArrayType>(gepTy))
459459
{
460-
if(!op || (arrTy->getArrayNumElements() <= (u32_t)op->getSExtValue()))
460+
if(!op || (arrTy->getArrayNumElements() <= (u32_t)LLVMUtil::getIntegerValue(op).first))
461461
continue;
462-
APOffset idx = op->getSExtValue();
462+
APOffset idx = (u32_t)LLVMUtil::getIntegerValue(op).first;
463463
u32_t offset = pag->getSymbolInfo()->getFlattenedElemIdx(llvmModuleSet()->getSVFType(arrTy), idx);
464464
ap.setFldIdx(ap.getConstantStructFldIdx() + offset);
465465
}
466466
else if (const StructType *ST = SVFUtil::dyn_cast<StructType>(gepTy))
467467
{
468468
assert(op && "non-const offset accessing a struct");
469469
//The actual index
470-
APOffset idx = op->getSExtValue();
470+
APOffset idx = (u32_t)LLVMUtil::getIntegerValue(op).first;
471471
u32_t offset = pag->getSymbolInfo()->getFlattenedElemIdx(llvmModuleSet()->getSVFType(ST), idx);
472472
ap.setFldIdx(ap.getConstantStructFldIdx() + offset);
473473
}
@@ -1176,7 +1176,7 @@ void SVFIRBuilder::visitSwitchInst(SwitchInst &inst)
11761176
/// default case is set to -1;
11771177
s64_t val = -1;
11781178
if (condVal && condVal->getBitWidth() <= 64)
1179-
val = condVal->getSExtValue();
1179+
val = (u32_t)LLVMUtil::getIntegerValue(condVal).first;
11801180
const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(succInst);
11811181
successors.push_back(std::make_pair(icfgNode, val));
11821182
}
@@ -1297,7 +1297,7 @@ const Value* SVFIRBuilder::getBaseValueForExtArg(const Value* V)
12971297
for (bridge_gep_iterator gi = bridge_gep_begin(gep), ge = bridge_gep_end(gep); gi != ge; ++gi)
12981298
{
12991299
if(const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(gi.getOperand()))
1300-
totalidx += op->getSExtValue();
1300+
totalidx += LLVMUtil::getIntegerValue(op).first;
13011301
}
13021302
if(totalidx == 0 && !SVFUtil::isa<StructType>(value->getType()))
13031303
value = gep->getPointerOperand();

svf-llvm/lib/SVFIRExtAPI.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
5050
/// use user-specified size for this copy operation if the size is a constaint int
5151
if(szValue && SVFUtil::isa<ConstantInt>(szValue))
5252
{
53-
numOfElems = (numOfElems > SVFUtil::cast<ConstantInt>(szValue)->getSExtValue()) ? SVFUtil::cast<ConstantInt>(szValue)->getSExtValue() : numOfElems;
53+
auto szIntVal = LLVMUtil::getIntegerValue(SVFUtil::cast<ConstantInt>(szValue));
54+
numOfElems = (numOfElems > szIntVal.first) ? szIntVal.first : numOfElems;
5455
}
5556

5657
LLVMContext& context = LLVMModuleSet::getLLVMModuleSet()->getContext();
@@ -64,7 +65,7 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
6465
{
6566
SymbolTableBuilder builder(pag->getSymbolInfo());
6667
builder.collectSym(offset);
67-
pag->addConstantIntValNode(svfOffset, offset->getSExtValue(), offset->getZExtValue(), pag->getSymbolInfo()->getValSym(svfOffset), nullptr);
68+
pag->addConstantIntValNode(svfOffset, LLVMUtil::getIntegerValue(offset), pag->getSymbolInfo()->getValSym(svfOffset), nullptr);
6869
}
6970
ls.addOffsetVarAndGepTypePair(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)), nullptr);
7071
fields.push_back(ls);

svf-llvm/lib/SymbolTableBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ u32_t SymbolTableBuilder::analyzeHeapAllocByteSize(const Value* val)
781781
llvm::dyn_cast<llvm::ConstantInt>(arg))
782782
{
783783
// Multiply the constant Value if all Args are const
784-
product *= constIntArg->getZExtValue();
784+
product *= LLVMUtil::getIntegerValue(constIntArg).second;
785785
}
786786
else
787787
{
@@ -871,8 +871,8 @@ void SymbolTableBuilder::initTypeInfo(ObjTypeInfo* typeinfo, const Value* val,
871871
/// In most cases, `NumElements` is not specified in the instruction, which means there is only one element (objSize=1).
872872
if(const ConstantInt* sz = SVFUtil::dyn_cast<ConstantInt>(allocaInst->getArraySize()))
873873
{
874-
elemNum = sz->getZExtValue() * getNumOfElements(objTy);
875-
byteSize = sz->getZExtValue() * typeinfo->getType()->getByteSize();
874+
elemNum = LLVMUtil::getIntegerValue(sz).second * getNumOfElements(objTy);
875+
byteSize = LLVMUtil::getIntegerValue(sz).second * typeinfo->getType()->getByteSize();
876876
}
877877
/// if ArraySize is not constant, byteSize is not static determined.
878878
else

svf/include/SVFIR/SVFIR.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ class SVFIR : public IRGraph
585585
return addNode(node, i);
586586
}
587587

588-
inline NodeID addConstantIntValNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i,
588+
inline NodeID addConstantIntValNode(const SVFValue* curInst, const std::pair<s64_t, u64_t>& intValue, const NodeID i,
589589
const ICFGNode* icfgNode)
590590
{
591-
SVFVar* node = new ConstantIntValVar(curInst, sval, zval, i, icfgNode);
591+
SVFVar* node = new ConstantIntValVar(curInst, intValue.first, intValue.second, i, icfgNode);
592592
return addNode(node, i);
593593
}
594594

@@ -656,13 +656,12 @@ class SVFIR : public IRGraph
656656
}
657657

658658

659-
inline NodeID addConstantIntObjNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i)
660-
{
659+
inline NodeID addConstantIntObjNode(const SVFValue* curInst, const std::pair<s64_t, u64_t>& intValue, const NodeID i) {
661660
const MemObj* mem = getMemObj(curInst);
662661
NodeID base = mem->getId();
663662
memToFieldsMap[base].set(mem->getId());
664663
ConstantIntObjVar* node =
665-
new ConstantIntObjVar(curInst, sval, zval, mem->getId(), mem);
664+
new ConstantIntObjVar(curInst, intValue.first, intValue.second, mem->getId(), mem);
666665
return addObjNode(curInst, node, mem->getId());
667666
}
668667

0 commit comments

Comments
 (0)