Author: Bogdan Vetrenko Date: 2026-03-21T23:46:03-07:00 New Revision: 24546d96445a6d4d7f6209795975faa7e3310356
URL: https://github.com/llvm/llvm-project/commit/24546d96445a6d4d7f6209795975faa7e3310356 DIFF: https://github.com/llvm/llvm-project/commit/24546d96445a6d4d7f6209795975faa7e3310356.diff LOG: [clang][CodeGen] Use FieldDecl::getFieldIndex() in VisitOffsetOfExpr (#187826) Use FieldDecl::getFieldIndex() instead of manually iterating over fields. Added: Modified: clang/lib/CodeGen/CGExprScalar.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 14f846131bbbe..1fe462c249ca5 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -3758,20 +3758,12 @@ Value *ScalarExprEmitter::VisitOffsetOfExpr(OffsetOfExpr *E) { auto *RD = CurrentType->castAsRecordDecl(); const ASTRecordLayout &RL = CGF.getContext().getASTRecordLayout(RD); - // Compute the index of the field in its parent. - unsigned i = 0; - // FIXME: It would be nice if we didn't have to loop here! - for (RecordDecl::field_iterator Field = RD->field_begin(), - FieldEnd = RD->field_end(); - Field != FieldEnd; ++Field, ++i) { - if (*Field == MemberDecl) - break; - } - assert(i < RL.getFieldCount() && "offsetof field in wrong type"); + // Get the index of the field in its parent. + unsigned FieldIndex = MemberDecl->getFieldIndex(); // Compute the offset to the field - int64_t OffsetInt = RL.getFieldOffset(i) / - CGF.getContext().getCharWidth(); + int64_t OffsetInt = + RL.getFieldOffset(FieldIndex) / CGF.getContext().getCharWidth(); Offset = llvm::ConstantInt::get(ResultType, OffsetInt); // Save the element type. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
