================
@@ -309,6 +309,37 @@ RecordType::computeStructAlignment(const mlir::DataLayout
&dataLayout) const {
return recordAlignment;
}
+uint64_t RecordType::getElementOffset(const ::mlir::DataLayout &dataLayout,
+ unsigned idx) const {
+ assert(idx < getMembers().size() && "access not valid");
+
+ // All union elements are at offset zero.
+ if (isUnion() || idx == 0)
+ return 0;
+
+ assert(isComplete() && "Cannot get layout of incomplete records");
+ assert(idx < getNumElements());
+ llvm::ArrayRef<mlir::Type> members = getMembers();
+
+ unsigned offset = 0;
+
+ for (unsigned i = 0, e = idx; i != e; ++i) {
----------------
erichkeane wrote:
Typically clang prefers range-for for readability and avoiding the
'error-prone-ness' of an index. Readability is because it assures that we are
only visiting anything 'once', and the index is unchanged between iterations.
Typically when I see one of these types of loops, it means "funny-business is
happening in the body, so look closely".
https://github.com/llvm/llvm-project/pull/136383
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits