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.
| 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. |
| 98 | u32_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 | /// |
no test coverage detected