Skip to content

Commit 3cab953

Browse files
committed
Use range for path iterators
1 parent 6fb2850 commit 3cab953

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818
using namespace clang;
1919
using namespace clang::CIRGen;
2020

21-
Address
22-
CIRGenFunction::getAddressOfBaseClass(Address value,
23-
const CXXRecordDecl *derived,
24-
CastExpr::path_const_iterator pathBegin,
25-
CastExpr::path_const_iterator pathEnd,
26-
bool nullCheckValue, SourceLocation loc) {
27-
assert(pathBegin != pathEnd && "Base path should not be empty!");
21+
Address CIRGenFunction::getAddressOfBaseClass(
22+
Address value, const CXXRecordDecl *derived,
23+
llvm::iterator_range<CastExpr::path_const_iterator> path,
24+
bool nullCheckValue, SourceLocation loc) {
25+
assert(!path.empty() && "Base path should not be empty!");
2826

29-
CastExpr::path_const_iterator start = pathBegin;
30-
31-
if ((*start)->isVirtual()) {
27+
if ((*path.begin())->isVirtual()) {
3228
// The implementation here is actually complete, but let's flag this
3329
// as an error until the rest of the virtual base class support is in place.
3430
cgm.errorNYI(loc, "getAddrOfBaseClass: virtual base");
@@ -39,10 +35,10 @@ CIRGenFunction::getAddressOfBaseClass(Address value,
3935
// allocating subobject (the virtual base, if there is one, or else
4036
// the "complete" object that we see).
4137
CharUnits nonVirtualOffset =
42-
cgm.computeNonVirtualBaseClassOffset(derived, start, pathEnd);
38+
cgm.computeNonVirtualBaseClassOffset(derived, path);
4339

4440
// Get the base pointer type.
45-
mlir::Type baseValueTy = convertType((pathEnd[-1])->getType());
41+
mlir::Type baseValueTy = convertType((path.end()[-1])->getType());
4642
assert(!cir::MissingFeatures::addressSpace());
4743

4844
// The if statement here is redundant now, but it will be needed when we add

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr *expr,
102102
Address addr = emitPointerWithAlignment(ce->getSubExpr(), baseInfo);
103103
const CXXRecordDecl *derived =
104104
ce->getSubExpr()->getType()->getPointeeCXXRecordDecl();
105-
return getAddressOfBaseClass(
106-
addr, derived, ce->path_begin(), ce->path_end(),
107-
shouldNullCheckClassCastValue(ce), ce->getExprLoc());
105+
return getAddressOfBaseClass(addr, derived, ce->path(),
106+
shouldNullCheckClassCastValue(ce),
107+
ce->getExprLoc());
108108
}
109109

110110
case CK_AnyPointerToBlockPointerCast:
@@ -876,9 +876,9 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
876876
Address thisAddr = lv.getAddress();
877877

878878
// Perform the derived-to-base conversion
879-
Address baseAddr = getAddressOfBaseClass(
880-
thisAddr, derivedClassDecl, e->path_begin(), e->path_end(),
881-
/*NullCheckValue=*/false, e->getExprLoc());
879+
Address baseAddr =
880+
getAddressOfBaseClass(thisAddr, derivedClassDecl, e->path(),
881+
/*NullCheckValue=*/false, e->getExprLoc());
882882

883883
// TODO: Support accesses to members of base classes in TBAA. For now, we
884884
// conservatively pretend that the complete object is of the base class

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,10 @@ class CIRGenFunction : public CIRGenTypeCache {
447447
return Address(ptr, convertTypeForMem(t), alignment);
448448
}
449449

450-
Address getAddressOfBaseClass(Address value, const CXXRecordDecl *derived,
451-
CastExpr::path_const_iterator pathBegin,
452-
CastExpr::path_const_iterator pathEnd,
453-
bool nullCheckValue, SourceLocation loc);
450+
Address getAddressOfBaseClass(
451+
Address value, const CXXRecordDecl *derived,
452+
llvm::iterator_range<CastExpr::path_const_iterator> path,
453+
bool nullCheckValue, SourceLocation loc);
454454

455455
LValue makeAddrLValue(Address addr, QualType ty,
456456
AlignmentSource source = AlignmentSource::Type) {

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,15 +1680,14 @@ bool CIRGenModule::verifyModule() const {
16801680

16811681
// TODO(cir): this can be shared with LLVM codegen.
16821682
CharUnits CIRGenModule::computeNonVirtualBaseClassOffset(
1683-
const CXXRecordDecl *derivedClass, CastExpr::path_const_iterator start,
1684-
CastExpr::path_const_iterator end) {
1683+
const CXXRecordDecl *derivedClass,
1684+
llvm::iterator_range<CastExpr::path_const_iterator> path) {
16851685
CharUnits offset = CharUnits::Zero();
16861686

16871687
const ASTContext &astContext = getASTContext();
16881688
const CXXRecordDecl *rd = derivedClass;
16891689

1690-
for (CastExpr::path_const_iterator i = start; i != end; ++i) {
1691-
const CXXBaseSpecifier *base = *i;
1690+
for (const CXXBaseSpecifier *base : path) {
16921691
assert(!base->isVirtual() && "Should not see virtual bases here!");
16931692

16941693
// Get the layout.

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@ class CIRGenModule : public CIRGenTypeCache {
141141
getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty = {},
142142
ForDefinition_t isForDefinition = NotForDefinition);
143143

144-
CharUnits
145-
computeNonVirtualBaseClassOffset(const CXXRecordDecl *derivedClass,
146-
CastExpr::path_const_iterator start,
147-
CastExpr::path_const_iterator end);
144+
CharUnits computeNonVirtualBaseClassOffset(
145+
const CXXRecordDecl *derivedClass,
146+
llvm::iterator_range<CastExpr::path_const_iterator> path);
148147

149148
/// Return a constant array for the given string.
150149
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);

0 commit comments

Comments
 (0)