diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /clang/lib/CodeGen/ConstantInitBuilder.cpp | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'clang/lib/CodeGen/ConstantInitBuilder.cpp')
-rw-r--r-- | clang/lib/CodeGen/ConstantInitBuilder.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/ConstantInitBuilder.cpp b/clang/lib/CodeGen/ConstantInitBuilder.cpp index 2d63d88020bed..24e3ca19709cb 100644 --- a/clang/lib/CodeGen/ConstantInitBuilder.cpp +++ b/clang/lib/CodeGen/ConstantInitBuilder.cpp @@ -128,8 +128,14 @@ void ConstantAggregateBuilderBase::addSize(CharUnits size) { llvm::Constant * ConstantAggregateBuilderBase::getRelativeOffset(llvm::IntegerType *offsetType, llvm::Constant *target) { + return getRelativeOffsetToPosition(offsetType, target, + Builder.Buffer.size() - Begin); +} + +llvm::Constant *ConstantAggregateBuilderBase::getRelativeOffsetToPosition( + llvm::IntegerType *offsetType, llvm::Constant *target, size_t position) { // Compute the address of the relative-address slot. - auto base = getAddrOfCurrentPosition(offsetType); + auto base = getAddrOfPosition(offsetType, position); // Subtract. base = llvm::ConstantExpr::getPtrToInt(base, Builder.CGM.IntPtrTy); @@ -145,6 +151,20 @@ ConstantAggregateBuilderBase::getRelativeOffset(llvm::IntegerType *offsetType, } llvm::Constant * +ConstantAggregateBuilderBase::getAddrOfPosition(llvm::Type *type, + size_t position) { + // Make a global variable. We will replace this with a GEP to this + // position after installing the initializer. + auto dummy = new llvm::GlobalVariable(Builder.CGM.getModule(), type, true, + llvm::GlobalVariable::PrivateLinkage, + nullptr, ""); + Builder.SelfReferences.emplace_back(dummy); + auto &entry = Builder.SelfReferences.back(); + (void)getGEPIndicesTo(entry.Indices, position + Begin); + return dummy; +} + +llvm::Constant * ConstantAggregateBuilderBase::getAddrOfCurrentPosition(llvm::Type *type) { // Make a global variable. We will replace this with a GEP to this // position after installing the initializer. |