Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a bug of int128 #1624

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions svf-llvm/include/SVF-LLVM/LLVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@
return SVFUtil::isa<CallBase>(val);
}

inline double getDoubleValue(const ConstantFP* fpValue) {
double dval = 0;
if (fpValue->isNormalFP())
{
const llvm::fltSemantics& semantics = fpValue->getValueAPF().getSemantics();
if (&semantics == &llvm::APFloat::IEEEhalf() ||
&semantics == &llvm::APFloat::IEEEsingle() ||
&semantics == &llvm::APFloat::IEEEdouble() ||
&semantics == &llvm::APFloat::IEEEquad() ||
&semantics == &llvm::APFloat::x87DoubleExtended())

Check warning on line 64 in svf-llvm/include/SVF-LLVM/LLVMUtil.h

View check run for this annotation

Codecov / codecov/patch

svf-llvm/include/SVF-LLVM/LLVMUtil.h#L63-L64

Added lines #L63 - L64 were not covered by tests
{
dval = fpValue->getValueAPF().convertToDouble();
}
else
{
assert (false && "Unsupported floating point type");

Check warning on line 70 in svf-llvm/include/SVF-LLVM/LLVMUtil.h

View check run for this annotation

Codecov / codecov/patch

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

Added line #L70 was not covered by tests
abort();
}
}
else
{
// other cfp type, like isZero(), isInfinity(), isNegative(), etc.
// do nothing
}
return dval;
}

inline std::pair<s64_t, u64_t> getIntegerValue(const ConstantInt* intValue) {
if (intValue->getBitWidth() <= 64 && intValue->getBitWidth() >= 1)
return std::make_pair(intValue->getSExtValue(), intValue->getZExtValue());
else
return std::make_pair(0,0);

Check warning on line 86 in svf-llvm/include/SVF-LLVM/LLVMUtil.h

View check run for this annotation

Codecov / codecov/patch

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

Added line #L86 was not covered by tests
}

/// Return LLVM callsite given a value
inline const CallBase* getLLVMCallSite(const Value* value)
Expand Down
8 changes: 4 additions & 4 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ void SVFIRBuilder::initialiseNodes()
}
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
{
pag->addConstantFPValNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second, icfgNode);
pag->addConstantFPValNode(iter->first, LLVMUtil::getDoubleValue(fpValue), iter->second, icfgNode);
llvmModuleSet()->addToLLVMVal2SVFVarMap(
fpValue, pag->getGNode(iter->second));
}
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
{
pag->addConstantIntValNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second, icfgNode);
pag->addConstantIntValNode(iter->first, LLVMUtil::getIntegerValue(intValue), iter->second, icfgNode);
llvmModuleSet()->addToLLVMVal2SVFVarMap(
intValue, pag->getGNode(iter->second));
}
Expand Down Expand Up @@ -322,13 +322,13 @@ void SVFIRBuilder::initialiseNodes()
}
else if (auto fpValue = SVFUtil::dyn_cast<ConstantFP>(llvmValue))
{
pag->addConstantFPObjNode(iter->first, fpValue->getValueAPF().convertToDouble(), iter->second);
pag->addConstantFPObjNode(iter->first, LLVMUtil::getDoubleValue(fpValue), iter->second);
llvmModuleSet()->addToLLVMVal2SVFVarMap(
fpValue, pag->getGNode(iter->second));
}
else if (auto intValue = SVFUtil::dyn_cast<ConstantInt>(llvmValue))
{
pag->addConstantIntObjNode(iter->first, intValue->getSExtValue(), intValue->getZExtValue(), iter->second);
pag->addConstantIntObjNode(iter->first, LLVMUtil::getIntegerValue(intValue), iter->second);
llvmModuleSet()->addToLLVMVal2SVFVarMap(
intValue, pag->getGNode(iter->second));
}
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRExtAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
{
SymbolTableBuilder builder(pag->getSymbolInfo());
builder.collectSym(offset);
pag->addConstantIntValNode(svfOffset, offset->getSExtValue(), offset->getZExtValue(), pag->getSymbolInfo()->getValSym(svfOffset), nullptr);
pag->addConstantIntValNode(svfOffset, std::make_pair(offset->getSExtValue(), offset->getZExtValue()), pag->getSymbolInfo()->getValSym(svfOffset), nullptr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVMUtil::getIntegerValue(offset)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::make_pair(offset->getSExtValue(), offset->getZExtValue()) => LLVMUtil::getIntegerValue(offset)

}
ls.addOffsetVarAndGepTypePair(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)), nullptr);
fields.push_back(ls);
Expand Down
9 changes: 4 additions & 5 deletions svf/include/SVFIR/SVFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,10 @@ class SVFIR : public IRGraph
return addNode(node, i);
}

inline NodeID addConstantIntValNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i,
inline NodeID addConstantIntValNode(const SVFValue* curInst, std::pair<s64_t, u64_t> intValue, const NodeID i,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::pair<s64_t, u64_t>&

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::pair<s64_t, u64_t>& intValue

const ICFGNode* icfgNode)
{
SVFVar* node = new ConstantIntValVar(curInst, sval, zval, i, icfgNode);
SVFVar* node = new ConstantIntValVar(curInst, intValue.first, intValue.second, i, icfgNode);
return addNode(node, i);
}

Expand Down Expand Up @@ -656,13 +656,12 @@ class SVFIR : public IRGraph
}


inline NodeID addConstantIntObjNode(const SVFValue* curInst, s64_t sval, u64_t zval, const NodeID i)
{
inline NodeID addConstantIntObjNode(const SVFValue* curInst, std::pair<s64_t, u64_t> intValue, const NodeID i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::pair<s64_t, u64_t>&

const MemObj* mem = getMemObj(curInst);
NodeID base = mem->getId();
memToFieldsMap[base].set(mem->getId());
ConstantIntObjVar* node =
new ConstantIntObjVar(curInst, sval, zval, mem->getId(), mem);
new ConstantIntObjVar(curInst, intValue.first, intValue.second, mem->getId(), mem);
return addObjNode(curInst, node, mem->getId());
}

Expand Down
Loading