Static Value-Flow Analysis
Loading...
Searching...
No Matches
PAGBuilder.cpp File Reference

Go to the source code of this file.

Functions

static const Type * getAggregateFieldType (const Type *type, const std::vector< unsigned > &indices)
 Return the type at a constant aggregate path, including fixed vector lanes.
static std::optional< unsigned > getFixedVectorLane (const Type *type, const Value *index)
static bool canModelAggregateReturn (const Function *fun)

Function Documentation

◆ canModelAggregateReturn()

bool canModelAggregateReturn ( const Function * fun)
static

Require a returning, nonvariadic definition whose uses are all ordinary direct calls with matching types, so each call can pass the output pointers.

Definition at line 1554 of file PAGBuilder.cpp.

1555{
1556 if (!fun || LLVMUtil::isExtCall(fun) || fun->isVarArg() ||
1557 fun->doesNotReturn() || !fun->getReturnType()->isAggregateType() ||
1558 fun->hasAddressTaken())
1559 return false;
1560 for (const User* user : fun->users())
1561 {
1562 const auto* call = SVFUtil::dyn_cast<CallInst>(user);
1563 if (!call || call->getCalledFunction() != fun ||
1564 call->getFunctionType() != fun->getFunctionType())
1565 return false;
1566 }
1567 return true;
1568}
bool isExtCall(const Function *fun)
Definition LLVMUtil.cpp:385
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405
llvm::User User
Definition BasicTypes.h:143

◆ getAggregateFieldType()

const Type * getAggregateFieldType ( const Type * type,
const std::vector< unsigned > & indices )
static

Return the type at a constant aggregate path, including fixed vector lanes.

Definition at line 1331 of file PAGBuilder.cpp.

1333{
1334 for (unsigned index : indices)
1335 {
1336 if (const auto* structure = SVFUtil::dyn_cast<StructType>(type))
1337 {
1338 if (index >= structure->getNumElements())
1339 return nullptr;
1340 type = structure->getElementType(index);
1341 }
1342 else if (const auto* array = SVFUtil::dyn_cast<ArrayType>(type))
1343 {
1344 if (index >= array->getNumElements())
1345 return nullptr;
1346 type = array->getElementType();
1347 }
1348 else if (const auto* vector = SVFUtil::dyn_cast<llvm::FixedVectorType>(type))
1349 {
1350 if (index >= vector->getNumElements())
1351 return nullptr;
1352 type = vector->getElementType();
1353 }
1354 else
1355 return nullptr;
1356 }
1357 return type;
1358}
newitem type
Definition cJSON.cpp:2739
int index
Definition cJSON.h:170

◆ getFixedVectorLane()

std::optional< unsigned > getFixedVectorLane ( const Type * type,
const Value * index )
static

Return the selected fixed-vector lane, or no lane for other vector types, variable indices and out-of-range indices.

Definition at line 1362 of file PAGBuilder.cpp.

1364{
1365 const auto* vector = SVFUtil::dyn_cast<llvm::FixedVectorType>(type);
1366 const auto* constant = SVFUtil::dyn_cast<ConstantInt>(index);
1367 if (!vector || !constant ||
1368 constant->getValue().uge(vector->getNumElements()))
1369 return std::nullopt;
1370 return static_cast<unsigned>(constant->getZExtValue());
1371}