MCPcopy Create free account
hub / github.com/SVF-tools/SVF / getStructFieldOffset

Method getStructFieldOffset

svf/lib/MemoryModel/AccessPath.cpp:98–115  ·  view source on GitHub ↗

Return byte offset from the beginning of the structure to the field where it is located for struct type e.g. idxOperandVar: i32 2 idxOperandType: %struct.Student = type { i32, [i8 x 12], i32 } we accumulate field 0 (i32) byte size (4 Bytes), and field 1 ([i8x12]) byte size (12 Bytes) then the return byte offset is 16 Bytes.

Source from the content-addressed store, hash-verified

96// we accumulate field 0 (i32) byte size (4 Bytes), and field 1 ([i8x12]) byte size (12 Bytes)
97// then the return byte offset is 16 Bytes.
98u32_t AccessPath::getStructFieldOffset(const ValVar* idxOperandVar, const SVFStructType* idxOperandType) const
99{
100 u32_t structByteOffset = 0;
101 if (const ConstIntValVar*op = SVFUtil::dyn_cast<ConstIntValVar>(idxOperandVar))
102 {
103 for (u32_t structField = 0; structField < (u32_t) op->getSExtValue(); ++structField)
104 {
105 u32_t flattenIdx = idxOperandType->getTypeInfo()->getFlattenedFieldIdxVec()[structField];
106 structByteOffset += idxOperandType->getTypeInfo()->getOriginalElemType(flattenIdx)->getByteSize();
107 }
108 return structByteOffset;
109 }
110 else
111 {
112 assert(false && "struct type can only pair with constant idx");
113 abort();
114 }
115}
116
117/// Return accumulated constant offset
118///

Callers 1

getGepByteOffsetMethod · 0.80

Calls 4

getByteSizeMethod · 0.80
getSExtValueMethod · 0.45
getTypeInfoMethod · 0.45
getOriginalElemTypeMethod · 0.45

Tested by

no test coverage detected