|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This contains code dealing with C++ code generation of classes |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "CIRGenFunction.h" |
| 14 | + |
| 15 | +#include "clang/AST/RecordLayout.h" |
| 16 | +#include "clang/CIR/MissingFeatures.h" |
| 17 | + |
| 18 | +using namespace clang; |
| 19 | +using namespace clang::CIRGen; |
| 20 | + |
| 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!"); |
| 26 | + |
| 27 | + if ((*path.begin())->isVirtual()) { |
| 28 | + // The implementation here is actually complete, but let's flag this |
| 29 | + // as an error until the rest of the virtual base class support is in place. |
| 30 | + cgm.errorNYI(loc, "getAddrOfBaseClass: virtual base"); |
| 31 | + return Address::invalid(); |
| 32 | + } |
| 33 | + |
| 34 | + // Compute the static offset of the ultimate destination within its |
| 35 | + // allocating subobject (the virtual base, if there is one, or else |
| 36 | + // the "complete" object that we see). |
| 37 | + CharUnits nonVirtualOffset = |
| 38 | + cgm.computeNonVirtualBaseClassOffset(derived, path); |
| 39 | + |
| 40 | + // Get the base pointer type. |
| 41 | + mlir::Type baseValueTy = convertType((path.end()[-1])->getType()); |
| 42 | + assert(!cir::MissingFeatures::addressSpace()); |
| 43 | + |
| 44 | + // The if statement here is redundant now, but it will be needed when we add |
| 45 | + // support for virtual base classes. |
| 46 | + // If there is no virtual base, use cir.base_class_addr. It takes care of |
| 47 | + // the adjustment and the null pointer check. |
| 48 | + if (nonVirtualOffset.isZero()) { |
| 49 | + assert(!cir::MissingFeatures::sanitizers()); |
| 50 | + return builder.createBaseClassAddr(getLoc(loc), value, baseValueTy, 0, |
| 51 | + /*assumeNotNull=*/true); |
| 52 | + } |
| 53 | + |
| 54 | + assert(!cir::MissingFeatures::sanitizers()); |
| 55 | + |
| 56 | + // Apply the offset |
| 57 | + value = builder.createBaseClassAddr(getLoc(loc), value, baseValueTy, |
| 58 | + nonVirtualOffset.getQuantity(), |
| 59 | + /*assumeNotNull=*/true); |
| 60 | + |
| 61 | + // Cast to the destination type. |
| 62 | + value = value.withElementType(builder, baseValueTy); |
| 63 | + |
| 64 | + return value; |
| 65 | +} |
0 commit comments