53 changes: 28 additions & 25 deletions clang/lib/CodeGen/CGAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace {
AtomicSizeInBits = C.toBits(
C.toCharUnitsFromBits(Offset + OrigBFI.Size + C.getCharWidth() - 1)
.alignTo(lvalue.getAlignment()));
llvm::Value *BitFieldPtr = lvalue.getBitFieldPointer();
llvm::Value *BitFieldPtr = lvalue.getRawBitFieldPointer(CGF);
auto OffsetInChars =
(C.toCharUnitsFromBits(OrigBFI.Offset) / lvalue.getAlignment()) *
lvalue.getAlignment();
Expand Down Expand Up @@ -139,13 +139,13 @@ namespace {
const LValue &getAtomicLValue() const { return LVal; }
llvm::Value *getAtomicPointer() const {
if (LVal.isSimple())
return LVal.getPointer(CGF);
return LVal.emitRawPointer(CGF);
else if (LVal.isBitField())
return LVal.getBitFieldPointer();
return LVal.getRawBitFieldPointer(CGF);
else if (LVal.isVectorElt())
return LVal.getVectorPointer();
return LVal.getRawVectorPointer(CGF);
assert(LVal.isExtVectorElt());
return LVal.getExtVectorPointer();
return LVal.getRawExtVectorPointer(CGF);
}
Address getAtomicAddress() const {
llvm::Type *ElTy;
Expand Down Expand Up @@ -368,7 +368,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
return false;

CGF.Builder.CreateMemSet(
addr.getPointer(), llvm::ConstantInt::get(CGF.Int8Ty, 0),
addr.emitRawPointer(CGF), llvm::ConstantInt::get(CGF.Int8Ty, 0),
CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits).getQuantity(),
LVal.getAlignment().getAsAlign());
return true;
Expand Down Expand Up @@ -1055,7 +1055,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
return getTargetHooks().performAddrSpaceCast(
*this, V, AS, LangAS::opencl_generic, DestType, false);
};
Args.add(RValue::get(CastToGenericAddrSpace(Ptr.getPointer(),

Args.add(RValue::get(CastToGenericAddrSpace(Ptr.emitRawPointer(*this),
E->getPtr()->getType())),
getContext().VoidPtrTy);

Expand Down Expand Up @@ -1086,10 +1087,10 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
LibCallName = "__atomic_compare_exchange";
RetTy = getContext().BoolTy;
HaveRetTy = true;
Args.add(RValue::get(CastToGenericAddrSpace(Val1.getPointer(),
Args.add(RValue::get(CastToGenericAddrSpace(Val1.emitRawPointer(*this),
E->getVal1()->getType())),
getContext().VoidPtrTy);
Args.add(RValue::get(CastToGenericAddrSpace(Val2.getPointer(),
Args.add(RValue::get(CastToGenericAddrSpace(Val2.emitRawPointer(*this),
E->getVal2()->getType())),
getContext().VoidPtrTy);
Args.add(RValue::get(Order), getContext().IntTy);
Expand All @@ -1105,7 +1106,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
case AtomicExpr::AO__scoped_atomic_exchange:
case AtomicExpr::AO__scoped_atomic_exchange_n:
LibCallName = "__atomic_exchange";
Args.add(RValue::get(CastToGenericAddrSpace(Val1.getPointer(),
Args.add(RValue::get(CastToGenericAddrSpace(Val1.emitRawPointer(*this),
E->getVal1()->getType())),
getContext().VoidPtrTy);
break;
Expand All @@ -1120,7 +1121,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
LibCallName = "__atomic_store";
RetTy = getContext().VoidTy;
HaveRetTy = true;
Args.add(RValue::get(CastToGenericAddrSpace(Val1.getPointer(),
Args.add(RValue::get(CastToGenericAddrSpace(Val1.emitRawPointer(*this),
E->getVal1()->getType())),
getContext().VoidPtrTy);
break;
Expand Down Expand Up @@ -1199,7 +1200,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
if (!HaveRetTy) {
// Value is returned through parameter before the order.
RetTy = getContext().VoidTy;
Args.add(RValue::get(CastToGenericAddrSpace(Dest.getPointer(), RetTy)),
Args.add(RValue::get(
CastToGenericAddrSpace(Dest.emitRawPointer(*this), RetTy)),
getContext().VoidPtrTy);
}
// Order is always the last parameter.
Expand Down Expand Up @@ -1513,7 +1515,7 @@ RValue AtomicInfo::EmitAtomicLoad(AggValueSlot ResultSlot, SourceLocation Loc,
} else
TempAddr = CreateTempAlloca();

EmitAtomicLoadLibcall(TempAddr.getPointer(), AO, IsVolatile);
EmitAtomicLoadLibcall(TempAddr.emitRawPointer(CGF), AO, IsVolatile);

// Okay, turn that back into the original value or whole atomic (for
// non-simple lvalues) type.
Expand Down Expand Up @@ -1673,9 +1675,9 @@ std::pair<RValue, llvm::Value *> AtomicInfo::EmitAtomicCompareExchange(
if (shouldUseLibcall()) {
// Produce a source address.
Address ExpectedAddr = materializeRValue(Expected);
Address DesiredAddr = materializeRValue(Desired);
auto *Res = EmitAtomicCompareExchangeLibcall(ExpectedAddr.getPointer(),
DesiredAddr.getPointer(),
llvm::Value *ExpectedPtr = ExpectedAddr.emitRawPointer(CGF);
llvm::Value *DesiredPtr = materializeRValue(Desired).emitRawPointer(CGF);
auto *Res = EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr,
Success, Failure);
return std::make_pair(
convertAtomicTempToRValue(ExpectedAddr, AggValueSlot::ignored(),
Expand Down Expand Up @@ -1757,7 +1759,7 @@ void AtomicInfo::EmitAtomicUpdateLibcall(

Address ExpectedAddr = CreateTempAlloca();

EmitAtomicLoadLibcall(ExpectedAddr.getPointer(), AO, IsVolatile);
EmitAtomicLoadLibcall(ExpectedAddr.emitRawPointer(CGF), AO, IsVolatile);
auto *ContBB = CGF.createBasicBlock("atomic_cont");
auto *ExitBB = CGF.createBasicBlock("atomic_exit");
CGF.EmitBlock(ContBB);
Expand All @@ -1771,10 +1773,10 @@ void AtomicInfo::EmitAtomicUpdateLibcall(
AggValueSlot::ignored(),
SourceLocation(), /*AsValue=*/false);
EmitAtomicUpdateValue(CGF, *this, OldRVal, UpdateOp, DesiredAddr);
llvm::Value *ExpectedPtr = ExpectedAddr.emitRawPointer(CGF);
llvm::Value *DesiredPtr = DesiredAddr.emitRawPointer(CGF);
auto *Res =
EmitAtomicCompareExchangeLibcall(ExpectedAddr.getPointer(),
DesiredAddr.getPointer(),
AO, Failure);
EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr, AO, Failure);
CGF.Builder.CreateCondBr(Res, ExitBB, ContBB);
CGF.EmitBlock(ExitBB, /*IsFinished=*/true);
}
Expand Down Expand Up @@ -1843,7 +1845,7 @@ void AtomicInfo::EmitAtomicUpdateLibcall(llvm::AtomicOrdering AO,

Address ExpectedAddr = CreateTempAlloca();

EmitAtomicLoadLibcall(ExpectedAddr.getPointer(), AO, IsVolatile);
EmitAtomicLoadLibcall(ExpectedAddr.emitRawPointer(CGF), AO, IsVolatile);
auto *ContBB = CGF.createBasicBlock("atomic_cont");
auto *ExitBB = CGF.createBasicBlock("atomic_exit");
CGF.EmitBlock(ContBB);
Expand All @@ -1854,10 +1856,10 @@ void AtomicInfo::EmitAtomicUpdateLibcall(llvm::AtomicOrdering AO,
CGF.Builder.CreateStore(OldVal, DesiredAddr);
}
EmitAtomicUpdateValue(CGF, *this, UpdateRVal, DesiredAddr);
llvm::Value *ExpectedPtr = ExpectedAddr.emitRawPointer(CGF);
llvm::Value *DesiredPtr = DesiredAddr.emitRawPointer(CGF);
auto *Res =
EmitAtomicCompareExchangeLibcall(ExpectedAddr.getPointer(),
DesiredAddr.getPointer(),
AO, Failure);
EmitAtomicCompareExchangeLibcall(ExpectedPtr, DesiredPtr, AO, Failure);
CGF.Builder.CreateCondBr(Res, ExitBB, ContBB);
CGF.EmitBlock(ExitBB, /*IsFinished=*/true);
}
Expand Down Expand Up @@ -1957,7 +1959,8 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, LValue dest,
args.add(RValue::get(atomics.getAtomicSizeValue()),
getContext().getSizeType());
args.add(RValue::get(atomics.getAtomicPointer()), getContext().VoidPtrTy);
args.add(RValue::get(srcAddr.getPointer()), getContext().VoidPtrTy);
args.add(RValue::get(srcAddr.emitRawPointer(*this)),
getContext().VoidPtrTy);
args.add(
RValue::get(llvm::ConstantInt::get(IntTy, (int)llvm::toCABI(AO))),
getContext().IntTy);
Expand Down
34 changes: 19 additions & 15 deletions clang/lib/CodeGen/CGBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef name)
: Name(name), CXXThisIndex(0), CanBeGlobal(false), NeedsCopyDispose(false),
NoEscape(false), HasCXXObject(false), UsesStret(false),
HasCapturedVariableLayout(false), CapturesNonExternalType(false),
LocalAddress(Address::invalid()), StructureType(nullptr), Block(block) {
LocalAddress(RawAddress::invalid()), StructureType(nullptr),
Block(block) {

// Skip asm prefix, if any. 'name' is usually taken directly from
// the mangled name of the enclosing function.
Expand Down Expand Up @@ -794,7 +795,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {

// Otherwise, we have to emit this as a local block.

Address blockAddr = blockInfo.LocalAddress;
RawAddress blockAddr = blockInfo.LocalAddress;
assert(blockAddr.isValid() && "block has no address!");

llvm::Constant *isa;
Expand Down Expand Up @@ -939,7 +940,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
if (CI.isNested())
byrefPointer = Builder.CreateLoad(src, "byref.capture");
else
byrefPointer = src.getPointer();
byrefPointer = src.emitRawPointer(*this);

// Write that void* into the capture field.
Builder.CreateStore(byrefPointer, blockField);
Expand All @@ -961,10 +962,10 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
}

// If it's a reference variable, copy the reference into the block field.
} else if (type->isReferenceType()) {
Builder.CreateStore(src.getPointer(), blockField);
} else if (auto refType = type->getAs<ReferenceType>()) {
Builder.CreateStore(src.emitRawPointer(*this), blockField);

// If type is const-qualified, copy the value into the block field.
// If type is const-qualified, copy the value into the block field.
} else if (type.isConstQualified() &&
type.getObjCLifetime() == Qualifiers::OCL_Strong &&
CGM.getCodeGenOpts().OptimizationLevel != 0) {
Expand Down Expand Up @@ -1377,7 +1378,7 @@ void CodeGenFunction::setBlockContextParameter(const ImplicitParamDecl *D,

// Allocate a stack slot like for any local variable to guarantee optimal
// debug info at -O0. The mem2reg pass will eliminate it when optimizing.
Address alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
RawAddress alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
Builder.CreateStore(arg, alloc);
if (CGDebugInfo *DI = getDebugInfo()) {
if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
Expand Down Expand Up @@ -1497,7 +1498,7 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
// frame setup instruction by llvm::DwarfDebug::beginFunction().
auto NL = ApplyDebugLocation::CreateEmpty(*this);
Builder.CreateStore(BlockPointer, Alloca);
BlockPointerDbgLoc = Alloca.getPointer();
BlockPointerDbgLoc = Alloca.emitRawPointer(*this);
}

// If we have a C++ 'this' reference, go ahead and force it into
Expand Down Expand Up @@ -1557,8 +1558,8 @@ llvm::Function *CodeGenFunction::GenerateBlockFunction(
const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
if (capture.isConstant()) {
auto addr = LocalDeclMap.find(variable)->second;
(void)DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(),
Builder);
(void)DI->EmitDeclareOfAutoVariable(
variable, addr.emitRawPointer(*this), Builder);
continue;
}

Expand Down Expand Up @@ -1662,7 +1663,7 @@ struct CallBlockRelease final : EHScopeStack::Cleanup {
if (LoadBlockVarAddr) {
BlockVarAddr = CGF.Builder.CreateLoad(Addr);
} else {
BlockVarAddr = Addr.getPointer();
BlockVarAddr = Addr.emitRawPointer(CGF);
}

CGF.BuildBlockRelease(BlockVarAddr, FieldFlags, CanThrow);
Expand Down Expand Up @@ -1962,13 +1963,15 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
// it. It's not quite worth the annoyance to avoid creating it in the
// first place.
if (!needsEHCleanup(captureType.isDestructedType()))
cast<llvm::Instruction>(dstField.getPointer())->eraseFromParent();
if (auto *I =
cast_or_null<llvm::Instruction>(dstField.getBasePointer()))
I->eraseFromParent();
}
break;
}
case BlockCaptureEntityKind::BlockObject: {
llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
llvm::Value *dstAddr = dstField.getPointer();
llvm::Value *dstAddr = dstField.emitRawPointer(*this);
llvm::Value *args[] = {
dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, flags.getBitMask())
};
Expand Down Expand Up @@ -2139,7 +2142,7 @@ class ObjectByrefHelpers final : public BlockByrefHelpers {
llvm::Value *flagsVal = llvm::ConstantInt::get(CGF.Int32Ty, flags);
llvm::FunctionCallee fn = CGF.CGM.getBlockObjectAssign();

llvm::Value *args[] = { destField.getPointer(), srcValue, flagsVal };
llvm::Value *args[] = {destField.emitRawPointer(CGF), srcValue, flagsVal};
CGF.EmitNounwindRuntimeCall(fn, args);
}

Expand Down Expand Up @@ -2696,7 +2699,8 @@ void CodeGenFunction::emitByrefStructureInit(const AutoVarEmission &emission) {
storeHeaderField(V, getPointerSize(), "byref.isa");

// Store the address of the variable into its own forwarding pointer.
storeHeaderField(addr.getPointer(), getPointerSize(), "byref.forwarding");
storeHeaderField(addr.emitRawPointer(*this), getPointerSize(),
"byref.forwarding");

// Blocks ABI:
// c) the flags field is set to either 0 if no helper functions are
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGBlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ class CGBlockInfo {
/// The block's captures. Non-constant captures are sorted by their offsets.
llvm::SmallVector<Capture, 4> SortedCaptures;

Address LocalAddress;
// Currently we assume that block-pointer types are never signed.
RawAddress LocalAddress;
llvm::StructType *StructureType;
const BlockDecl *Block;
const BlockExpr *BlockExpression;
Expand Down
234 changes: 160 additions & 74 deletions clang/lib/CodeGen/CGBuilder.h

Large diffs are not rendered by default.

173 changes: 90 additions & 83 deletions clang/lib/CodeGen/CGBuiltin.cpp

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions clang/lib/CodeGen/CGCUDANV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
llvm::ConstantInt::get(SizeTy, std::max<size_t>(1, Args.size())));
// Store pointers to the arguments in a locally allocated launch_args.
for (unsigned i = 0; i < Args.size(); ++i) {
llvm::Value* VarPtr = CGF.GetAddrOfLocalVar(Args[i]).getPointer();
llvm::Value *VarPtr = CGF.GetAddrOfLocalVar(Args[i]).emitRawPointer(CGF);
llvm::Value *VoidVarPtr = CGF.Builder.CreatePointerCast(VarPtr, PtrTy);
CGF.Builder.CreateDefaultAlignedStore(
VoidVarPtr,
CGF.Builder.CreateConstGEP1_32(PtrTy, KernelArgs.getPointer(), i));
VoidVarPtr, CGF.Builder.CreateConstGEP1_32(
PtrTy, KernelArgs.emitRawPointer(CGF), i));
}

llvm::BasicBlock *EndBlock = CGF.createBasicBlock("setup.end");
Expand Down Expand Up @@ -393,9 +393,10 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
/*isVarArg=*/false),
addUnderscoredPrefixToName("PopCallConfiguration"));

CGF.EmitRuntimeCallOrInvoke(cudaPopConfigFn,
{GridDim.getPointer(), BlockDim.getPointer(),
ShmemSize.getPointer(), Stream.getPointer()});
CGF.EmitRuntimeCallOrInvoke(cudaPopConfigFn, {GridDim.emitRawPointer(CGF),
BlockDim.emitRawPointer(CGF),
ShmemSize.emitRawPointer(CGF),
Stream.emitRawPointer(CGF)});

// Emit the call to cudaLaunch
llvm::Value *Kernel =
Expand All @@ -405,7 +406,7 @@ void CGNVCUDARuntime::emitDeviceStubBodyNew(CodeGenFunction &CGF,
cudaLaunchKernelFD->getParamDecl(0)->getType());
LaunchKernelArgs.add(RValue::getAggregate(GridDim), Dim3Ty);
LaunchKernelArgs.add(RValue::getAggregate(BlockDim), Dim3Ty);
LaunchKernelArgs.add(RValue::get(KernelArgs.getPointer()),
LaunchKernelArgs.add(RValue::get(KernelArgs, CGF),
cudaLaunchKernelFD->getParamDecl(3)->getType());
LaunchKernelArgs.add(RValue::get(CGF.Builder.CreateLoad(ShmemSize)),
cudaLaunchKernelFD->getParamDecl(4)->getType());
Expand Down Expand Up @@ -438,8 +439,8 @@ void CGNVCUDARuntime::emitDeviceStubBodyLegacy(CodeGenFunction &CGF,
auto TInfo = CGM.getContext().getTypeInfoInChars(A->getType());
Offset = Offset.alignTo(TInfo.Align);
llvm::Value *Args[] = {
CGF.Builder.CreatePointerCast(CGF.GetAddrOfLocalVar(A).getPointer(),
PtrTy),
CGF.Builder.CreatePointerCast(
CGF.GetAddrOfLocalVar(A).emitRawPointer(CGF), PtrTy),
llvm::ConstantInt::get(SizeTy, TInfo.Width.getQuantity()),
llvm::ConstantInt::get(SizeTy, Offset.getQuantity()),
};
Expand Down
21 changes: 15 additions & 6 deletions clang/lib/CodeGen/CGCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ using namespace CodeGen;

CGCXXABI::~CGCXXABI() { }

Address CGCXXABI::getThisAddress(CodeGenFunction &CGF) {
return CGF.makeNaturalAddressForPointer(
CGF.CXXABIThisValue, CGF.CXXABIThisDecl->getType()->getPointeeType(),
CGF.CXXABIThisAlignment);
}

void CGCXXABI::ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S) {
DiagnosticsEngine &Diags = CGF.CGM.getDiags();
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
Expand All @@ -44,8 +50,12 @@ CGCallee CGCXXABI::EmitLoadOfMemberFunctionPointer(
llvm::Value *MemPtr, const MemberPointerType *MPT) {
ErrorUnsupportedABI(CGF, "calls through member pointers");

ThisPtrForCall = This.getPointer();
const auto *FPT = MPT->getPointeeType()->castAs<FunctionProtoType>();
const auto *RD =
cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl());
ThisPtrForCall =
CGF.getAsNaturalPointerTo(This, CGF.getContext().getRecordType(RD));
const FunctionProtoType *FPT =
MPT->getPointeeType()->getAs<FunctionProtoType>();
llvm::Constant *FnPtr = llvm::Constant::getNullValue(
llvm::PointerType::getUnqual(CGM.getLLVMContext()));
return CGCallee::forDirect(FnPtr, FPT);
Expand Down Expand Up @@ -251,16 +261,15 @@ void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,

// If we don't need an array cookie, bail out early.
if (!requiresArrayCookie(expr, eltTy)) {
allocPtr = ptr.getPointer();
allocPtr = ptr.emitRawPointer(CGF);
numElements = nullptr;
cookieSize = CharUnits::Zero();
return;
}

cookieSize = getArrayCookieSizeImpl(eltTy);
Address allocAddr =
CGF.Builder.CreateConstInBoundsByteGEP(ptr, -cookieSize);
allocPtr = allocAddr.getPointer();
Address allocAddr = CGF.Builder.CreateConstInBoundsByteGEP(ptr, -cookieSize);
allocPtr = allocAddr.emitRawPointer(CGF);
numElements = readArrayCookieImpl(CGF, allocAddr, cookieSize);
}

Expand Down
14 changes: 2 additions & 12 deletions clang/lib/CodeGen/CGCXXABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ class CGCXXABI {
llvm::Value *getThisValue(CodeGenFunction &CGF) {
return CGF.CXXABIThisValue;
}
Address getThisAddress(CodeGenFunction &CGF) {
return Address(
CGF.CXXABIThisValue,
CGF.ConvertTypeForMem(CGF.CXXABIThisDecl->getType()->getPointeeType()),
CGF.CXXABIThisAlignment);
}

Address getThisAddress(CodeGenFunction &CGF);

/// Issue a diagnostic about unsupported features in the ABI.
void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
Expand Down Expand Up @@ -475,12 +471,6 @@ class CGCXXABI {
BaseSubobject Base,
const CXXRecordDecl *NearestVBase) = 0;

/// Get the address point of the vtable for the given base subobject while
/// building a constexpr.
virtual llvm::Constant *
getVTableAddressPointForConstExpr(BaseSubobject Base,
const CXXRecordDecl *VTableClass) = 0;

/// Get the address of the vtable for the given record decl which should be
/// used for the vptr at the given offset in RD.
virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
Expand Down
171 changes: 97 additions & 74 deletions clang/lib/CodeGen/CGCall.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions clang/lib/CodeGen/CGCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ class ReturnValueSlot {
Address getValue() const { return Addr; }
bool isUnused() const { return IsUnused; }
bool isExternallyDestructed() const { return IsExternallyDestructed; }
Address getAddress() const { return Addr; }
};

/// Adds attributes to \p F according to our \p CodeGenOpts and \p LangOpts, as
Expand Down
76 changes: 45 additions & 31 deletions clang/lib/CodeGen/CGClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ Address CodeGenFunction::LoadCXXThisAddress() {
CXXThisAlignment = CGM.getClassPointerAlignment(MD->getParent());
}

llvm::Type *Ty = ConvertType(MD->getFunctionObjectParameterType());
return Address(LoadCXXThis(), Ty, CXXThisAlignment, KnownNonNull);
return makeNaturalAddressForPointer(
LoadCXXThis(), MD->getFunctionObjectParameterType(), CXXThisAlignment,
false, nullptr, nullptr, KnownNonNull);
}

/// Emit the address of a field using a member data pointer.
Expand Down Expand Up @@ -270,7 +271,7 @@ ApplyNonVirtualAndVirtualOffset(CodeGenFunction &CGF, Address addr,
}

// Apply the base offset.
llvm::Value *ptr = addr.getPointer();
llvm::Value *ptr = addr.emitRawPointer(CGF);
ptr = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ptr, baseOffset, "add.ptr");

// If we have a virtual component, the alignment of the result will
Expand Down Expand Up @@ -338,8 +339,8 @@ Address CodeGenFunction::GetAddressOfBaseClass(
if (sanitizePerformTypeCheck()) {
SanitizerSet SkippedChecks;
SkippedChecks.set(SanitizerKind::Null, !NullCheckValue);
EmitTypeCheck(TCK_Upcast, Loc, Value.getPointer(),
DerivedTy, DerivedAlign, SkippedChecks);
EmitTypeCheck(TCK_Upcast, Loc, Value.emitRawPointer(*this), DerivedTy,
DerivedAlign, SkippedChecks);
}
return Value.withElementType(BaseValueTy);
}
Expand All @@ -354,7 +355,7 @@ Address CodeGenFunction::GetAddressOfBaseClass(
llvm::BasicBlock *notNullBB = createBasicBlock("cast.notnull");
endBB = createBasicBlock("cast.end");

llvm::Value *isNull = Builder.CreateIsNull(Value.getPointer());
llvm::Value *isNull = Builder.CreateIsNull(Value);
Builder.CreateCondBr(isNull, endBB, notNullBB);
EmitBlock(notNullBB);
}
Expand All @@ -363,14 +364,15 @@ Address CodeGenFunction::GetAddressOfBaseClass(
SanitizerSet SkippedChecks;
SkippedChecks.set(SanitizerKind::Null, true);
EmitTypeCheck(VBase ? TCK_UpcastToVirtualBase : TCK_Upcast, Loc,
Value.getPointer(), DerivedTy, DerivedAlign, SkippedChecks);
Value.emitRawPointer(*this), DerivedTy, DerivedAlign,
SkippedChecks);
}

// Compute the virtual offset.
llvm::Value *VirtualOffset = nullptr;
if (VBase) {
VirtualOffset =
CGM.getCXXABI().GetVirtualBaseClassOffset(*this, Value, Derived, VBase);
CGM.getCXXABI().GetVirtualBaseClassOffset(*this, Value, Derived, VBase);
}

// Apply both offsets.
Expand All @@ -387,7 +389,7 @@ Address CodeGenFunction::GetAddressOfBaseClass(
EmitBlock(endBB);

llvm::PHINode *PHI = Builder.CreatePHI(PtrTy, 2, "cast.result");
PHI->addIncoming(Value.getPointer(), notNullBB);
PHI->addIncoming(Value.emitRawPointer(*this), notNullBB);
PHI->addIncoming(llvm::Constant::getNullValue(PtrTy), origBB);
Value = Value.withPointer(PHI, NotKnownNonNull);
}
Expand Down Expand Up @@ -424,15 +426,19 @@ CodeGenFunction::GetAddressOfDerivedClass(Address BaseAddr,
CastNotNull = createBasicBlock("cast.notnull");
CastEnd = createBasicBlock("cast.end");

llvm::Value *IsNull = Builder.CreateIsNull(BaseAddr.getPointer());
llvm::Value *IsNull = Builder.CreateIsNull(BaseAddr);
Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
EmitBlock(CastNotNull);
}

// Apply the offset.
llvm::Value *Value = BaseAddr.getPointer();
Value = Builder.CreateInBoundsGEP(
Int8Ty, Value, Builder.CreateNeg(NonVirtualOffset), "sub.ptr");
Address Addr = BaseAddr.withElementType(Int8Ty);
Addr = Builder.CreateInBoundsGEP(
Addr, Builder.CreateNeg(NonVirtualOffset), Int8Ty,
CGM.getClassPointerAlignment(Derived), "sub.ptr");

// Just cast.
Addr = Addr.withElementType(DerivedValueTy);

// Produce a PHI if we had a null-check.
if (NullCheckValue) {
Expand All @@ -441,13 +447,15 @@ CodeGenFunction::GetAddressOfDerivedClass(Address BaseAddr,
Builder.CreateBr(CastEnd);
EmitBlock(CastEnd);

llvm::Value *Value = Addr.emitRawPointer(*this);
llvm::PHINode *PHI = Builder.CreatePHI(Value->getType(), 2);
PHI->addIncoming(Value, CastNotNull);
PHI->addIncoming(llvm::Constant::getNullValue(Value->getType()), CastNull);
Value = PHI;
return Address(PHI, Addr.getElementType(),
CGM.getClassPointerAlignment(Derived));
}

return Address(Value, DerivedValueTy, CGM.getClassPointerAlignment(Derived));
return Addr;
}

llvm::Value *CodeGenFunction::GetVTTParameter(GlobalDecl GD,
Expand Down Expand Up @@ -1719,7 +1727,7 @@ namespace {
// Use the base class declaration location as inline DebugLocation. All
// fields of the class are destroyed.
DeclAsInlineDebugLocation InlineHere(CGF, *BaseClass);
EmitSanitizerDtorFieldsCallback(CGF, Addr.getPointer(),
EmitSanitizerDtorFieldsCallback(CGF, Addr.emitRawPointer(CGF),
BaseSize.getQuantity());

// Prevent the current stack frame from disappearing from the stack trace.
Expand Down Expand Up @@ -2022,7 +2030,7 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(const CXXConstructorDecl *ctor,

// Find the end of the array.
llvm::Type *elementType = arrayBase.getElementType();
llvm::Value *arrayBegin = arrayBase.getPointer();
llvm::Value *arrayBegin = arrayBase.emitRawPointer(*this);
llvm::Value *arrayEnd = Builder.CreateInBoundsGEP(
elementType, arrayBegin, numElements, "arrayctor.end");

Expand Down Expand Up @@ -2118,14 +2126,15 @@ void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
Address This = ThisAVS.getAddress();
LangAS SlotAS = ThisAVS.getQualifiers().getAddressSpace();
LangAS ThisAS = D->getFunctionObjectParameterType().getAddressSpace();
llvm::Value *ThisPtr = This.getPointer();
llvm::Value *ThisPtr =
getAsNaturalPointerTo(This, D->getThisType()->getPointeeType());

if (SlotAS != ThisAS) {
unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS);
llvm::Type *NewType =
llvm::PointerType::get(getLLVMContext(), TargetThisAS);
ThisPtr = getTargetHooks().performAddrSpaceCast(*this, This.getPointer(),
ThisAS, SlotAS, NewType);
ThisPtr = getTargetHooks().performAddrSpaceCast(*this, ThisPtr, ThisAS,
SlotAS, NewType);
}

// Push the this ptr.
Expand Down Expand Up @@ -2194,7 +2203,7 @@ void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
const CXXRecordDecl *ClassDecl = D->getParent();

if (!NewPointerIsChecked)
EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, Loc, This.getPointer(),
EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, Loc, This,
getContext().getRecordType(ClassDecl), CharUnits::Zero());

if (D->isTrivial() && D->isDefaultConstructor()) {
Expand All @@ -2207,10 +2216,9 @@ void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
// model that copy.
if (isMemcpyEquivalentSpecialMember(D)) {
assert(Args.size() == 2 && "unexpected argcount for trivial ctor");

QualType SrcTy = D->getParamDecl(0)->getType().getNonReferenceType();
Address Src = Address(Args[1].getRValue(*this).getScalarVal(), ConvertTypeForMem(SrcTy),
CGM.getNaturalTypeAlignment(SrcTy));
Address Src = makeNaturalAddressForPointer(
Args[1].getRValue(*this).getScalarVal(), SrcTy);
LValue SrcLVal = MakeAddrLValue(Src, SrcTy);
QualType DestTy = getContext().getTypeDeclType(ClassDecl);
LValue DestLVal = MakeAddrLValue(This, DestTy);
Expand Down Expand Up @@ -2263,7 +2271,9 @@ void CodeGenFunction::EmitInheritedCXXConstructorCall(
const CXXConstructorDecl *D, bool ForVirtualBase, Address This,
bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E) {
CallArgList Args;
CallArg ThisArg(RValue::get(This.getPointer()), D->getThisType());
CallArg ThisArg(RValue::get(getAsNaturalPointerTo(
This, D->getThisType()->getPointeeType())),
D->getThisType());

// Forward the parameters.
if (InheritedFromVBase &&
Expand Down Expand Up @@ -2388,12 +2398,14 @@ CodeGenFunction::EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D,
CallArgList Args;

// Push the this ptr.
Args.add(RValue::get(This.getPointer()), D->getThisType());
Args.add(RValue::get(getAsNaturalPointerTo(This, D->getThisType())),
D->getThisType());

// Push the src ptr.
QualType QT = *(FPT->param_type_begin());
llvm::Type *t = CGM.getTypes().ConvertType(QT);
llvm::Value *SrcVal = Builder.CreateBitCast(Src.getPointer(), t);
llvm::Value *Val = getAsNaturalPointerTo(Src, D->getThisType());
llvm::Value *SrcVal = Builder.CreateBitCast(Val, t);
Args.add(RValue::get(SrcVal), QT);

// Skip over first argument (Src).
Expand All @@ -2418,7 +2430,9 @@ CodeGenFunction::EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor,

// this
Address This = LoadCXXThisAddress();
DelegateArgs.add(RValue::get(This.getPointer()), (*I)->getType());
DelegateArgs.add(RValue::get(getAsNaturalPointerTo(
This, (*I)->getType()->getPointeeType())),
(*I)->getType());
++I;

// FIXME: The location of the VTT parameter in the parameter list is
Expand Down Expand Up @@ -2775,7 +2789,7 @@ void CodeGenFunction::EmitVTablePtrCheckForCast(QualType T, Address Derived,

if (MayBeNull) {
llvm::Value *DerivedNotNull =
Builder.CreateIsNotNull(Derived.getPointer(), "cast.nonnull");
Builder.CreateIsNotNull(Derived.emitRawPointer(*this), "cast.nonnull");

llvm::BasicBlock *CheckBlock = createBasicBlock("cast.check");
ContBlock = createBasicBlock("cast.cont");
Expand Down Expand Up @@ -2976,7 +2990,7 @@ void CodeGenFunction::EmitLambdaBlockInvokeBody() {

QualType ThisType = getContext().getPointerType(getContext().getRecordType(Lambda));
Address ThisPtr = GetAddrOfBlockDecl(variable);
CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType);
CallArgs.add(RValue::get(getAsNaturalPointerTo(ThisPtr, ThisType)), ThisType);

// Add the rest of the parameters.
for (auto *param : BD->parameters())
Expand Down Expand Up @@ -3004,7 +3018,7 @@ void CodeGenFunction::EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD) {
QualType LambdaType = getContext().getRecordType(Lambda);
QualType ThisType = getContext().getPointerType(LambdaType);
Address ThisPtr = CreateMemTemp(LambdaType, "unused.capture");
CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType);
CallArgs.add(RValue::get(ThisPtr.emitRawPointer(*this)), ThisType);

EmitLambdaDelegatingInvokeBody(MD, CallArgs);
}
Expand Down
110 changes: 41 additions & 69 deletions clang/lib/CodeGen/CGCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,77 +27,48 @@ bool DominatingValue<RValue>::saved_type::needsSaving(RValue rv) {
if (rv.isScalar())
return DominatingLLVMValue::needsSaving(rv.getScalarVal());
if (rv.isAggregate())
return DominatingLLVMValue::needsSaving(rv.getAggregatePointer());
return DominatingValue<Address>::needsSaving(rv.getAggregateAddress());
return true;
}

DominatingValue<RValue>::saved_type
DominatingValue<RValue>::saved_type::save(CodeGenFunction &CGF, RValue rv) {
if (rv.isScalar()) {
llvm::Value *V = rv.getScalarVal();

// These automatically dominate and don't need to be saved.
if (!DominatingLLVMValue::needsSaving(V))
return saved_type(V, nullptr, ScalarLiteral);

// Everything else needs an alloca.
Address addr =
CGF.CreateDefaultAlignTempAlloca(V->getType(), "saved-rvalue");
CGF.Builder.CreateStore(V, addr);
return saved_type(addr.getPointer(), nullptr, ScalarAddress);
return saved_type(DominatingLLVMValue::save(CGF, V),
DominatingLLVMValue::needsSaving(V) ? ScalarAddress
: ScalarLiteral);
}

if (rv.isComplex()) {
CodeGenFunction::ComplexPairTy V = rv.getComplexVal();
llvm::Type *ComplexTy =
llvm::StructType::get(V.first->getType(), V.second->getType());
Address addr = CGF.CreateDefaultAlignTempAlloca(ComplexTy, "saved-complex");
CGF.Builder.CreateStore(V.first, CGF.Builder.CreateStructGEP(addr, 0));
CGF.Builder.CreateStore(V.second, CGF.Builder.CreateStructGEP(addr, 1));
return saved_type(addr.getPointer(), nullptr, ComplexAddress);
return saved_type(DominatingLLVMValue::save(CGF, V.first),
DominatingLLVMValue::save(CGF, V.second));
}

assert(rv.isAggregate());
Address V = rv.getAggregateAddress(); // TODO: volatile?
if (!DominatingLLVMValue::needsSaving(V.getPointer()))
return saved_type(V.getPointer(), V.getElementType(), AggregateLiteral,
V.getAlignment().getQuantity());

Address addr =
CGF.CreateTempAlloca(V.getType(), CGF.getPointerAlign(), "saved-rvalue");
CGF.Builder.CreateStore(V.getPointer(), addr);
return saved_type(addr.getPointer(), V.getElementType(), AggregateAddress,
V.getAlignment().getQuantity());
Address V = rv.getAggregateAddress();
return saved_type(
DominatingValue<Address>::save(CGF, V), rv.isVolatileQualified(),
DominatingValue<Address>::needsSaving(V) ? AggregateAddress
: AggregateLiteral);
}

/// Given a saved r-value produced by SaveRValue, perform the code
/// necessary to restore it to usability at the current insertion
/// point.
RValue DominatingValue<RValue>::saved_type::restore(CodeGenFunction &CGF) {
auto getSavingAddress = [&](llvm::Value *value) {
auto *AI = cast<llvm::AllocaInst>(value);
return Address(value, AI->getAllocatedType(),
CharUnits::fromQuantity(AI->getAlign().value()));
};
switch (K) {
case ScalarLiteral:
return RValue::get(Value);
case ScalarAddress:
return RValue::get(CGF.Builder.CreateLoad(getSavingAddress(Value)));
return RValue::get(DominatingLLVMValue::restore(CGF, Vals.first));
case AggregateLiteral:
case AggregateAddress:
return RValue::getAggregate(
Address(Value, ElementType, CharUnits::fromQuantity(Align)));
case AggregateAddress: {
auto addr = CGF.Builder.CreateLoad(getSavingAddress(Value));
return RValue::getAggregate(
Address(addr, ElementType, CharUnits::fromQuantity(Align)));
}
DominatingValue<Address>::restore(CGF, AggregateAddr), IsVolatile);
case ComplexAddress: {
Address address = getSavingAddress(Value);
llvm::Value *real =
CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(address, 0));
llvm::Value *imag =
CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(address, 1));
llvm::Value *real = DominatingLLVMValue::restore(CGF, Vals.first);
llvm::Value *imag = DominatingLLVMValue::restore(CGF, Vals.second);
return RValue::getComplex(real, imag);
}
}
Expand Down Expand Up @@ -294,22 +265,22 @@ void EHScopeStack::popNullFixups() {
BranchFixups.pop_back();
}

Address CodeGenFunction::createCleanupActiveFlag() {
RawAddress CodeGenFunction::createCleanupActiveFlag() {
// Create a variable to decide whether the cleanup needs to be run.
Address active = CreateTempAllocaWithoutCast(
RawAddress active = CreateTempAllocaWithoutCast(
Builder.getInt1Ty(), CharUnits::One(), "cleanup.cond");

// Initialize it to false at a site that's guaranteed to be run
// before each evaluation.
setBeforeOutermostConditional(Builder.getFalse(), active);
setBeforeOutermostConditional(Builder.getFalse(), active, *this);

// Initialize it to true at the current location.
Builder.CreateStore(Builder.getTrue(), active);

return active;
}

void CodeGenFunction::initFullExprCleanupWithFlag(Address ActiveFlag) {
void CodeGenFunction::initFullExprCleanupWithFlag(RawAddress ActiveFlag) {
// Set that as the active flag in the cleanup.
EHCleanupScope &cleanup = cast<EHCleanupScope>(*EHStack.begin());
assert(!cleanup.hasActiveFlag() && "cleanup already has active flag?");
Expand All @@ -322,15 +293,17 @@ void CodeGenFunction::initFullExprCleanupWithFlag(Address ActiveFlag) {
void EHScopeStack::Cleanup::anchor() {}

static void createStoreInstBefore(llvm::Value *value, Address addr,
llvm::Instruction *beforeInst) {
auto store = new llvm::StoreInst(value, addr.getPointer(), beforeInst);
llvm::Instruction *beforeInst,
CodeGenFunction &CGF) {
auto store = new llvm::StoreInst(value, addr.emitRawPointer(CGF), beforeInst);
store->setAlignment(addr.getAlignment().getAsAlign());
}

static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name,
llvm::Instruction *beforeInst) {
return new llvm::LoadInst(addr.getElementType(), addr.getPointer(), name,
false, addr.getAlignment().getAsAlign(),
llvm::Instruction *beforeInst,
CodeGenFunction &CGF) {
return new llvm::LoadInst(addr.getElementType(), addr.emitRawPointer(CGF),
name, false, addr.getAlignment().getAsAlign(),
beforeInst);
}

Expand All @@ -357,8 +330,8 @@ static void ResolveAllBranchFixups(CodeGenFunction &CGF,
// entry which we're currently popping.
if (Fixup.OptimisticBranchBlock == nullptr) {
createStoreInstBefore(CGF.Builder.getInt32(Fixup.DestinationIndex),
CGF.getNormalCleanupDestSlot(),
Fixup.InitialBranch);
CGF.getNormalCleanupDestSlot(), Fixup.InitialBranch,
CGF);
Fixup.InitialBranch->setSuccessor(0, CleanupEntry);
}

Expand All @@ -385,7 +358,7 @@ static llvm::SwitchInst *TransitionToCleanupSwitch(CodeGenFunction &CGF,
if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
assert(Br->isUnconditional());
auto Load = createLoadInstBefore(CGF.getNormalCleanupDestSlot(),
"cleanup.dest", Term);
"cleanup.dest", Term, CGF);
llvm::SwitchInst *Switch =
llvm::SwitchInst::Create(Load, Br->getSuccessor(0), 4, Block);
Br->eraseFromParent();
Expand Down Expand Up @@ -513,8 +486,8 @@ void CodeGenFunction::PopCleanupBlocks(
I += Header.getSize();

if (Header.isConditional()) {
Address ActiveFlag =
reinterpret_cast<Address &>(LifetimeExtendedCleanupStack[I]);
RawAddress ActiveFlag =
reinterpret_cast<RawAddress &>(LifetimeExtendedCleanupStack[I]);
initFullExprCleanupWithFlag(ActiveFlag);
I += sizeof(ActiveFlag);
}
Expand Down Expand Up @@ -888,7 +861,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
if (NormalCleanupDestSlot->hasOneUse()) {
NormalCleanupDestSlot->user_back()->eraseFromParent();
NormalCleanupDestSlot->eraseFromParent();
NormalCleanupDest = Address::invalid();
NormalCleanupDest = RawAddress::invalid();
}

llvm::BasicBlock *BranchAfter = Scope.getBranchAfterBlock(0);
Expand All @@ -912,9 +885,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
// pass the abnormal exit flag to Fn (SEH cleanup)
cleanupFlags.setHasExitSwitch();

llvm::LoadInst *Load =
createLoadInstBefore(getNormalCleanupDestSlot(), "cleanup.dest",
nullptr);
llvm::LoadInst *Load = createLoadInstBefore(
getNormalCleanupDestSlot(), "cleanup.dest", nullptr, *this);
llvm::SwitchInst *Switch =
llvm::SwitchInst::Create(Load, Default, SwitchCapacity);

Expand Down Expand Up @@ -961,8 +933,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
if (!Fixup.Destination) continue;
if (!Fixup.OptimisticBranchBlock) {
createStoreInstBefore(Builder.getInt32(Fixup.DestinationIndex),
getNormalCleanupDestSlot(),
Fixup.InitialBranch);
getNormalCleanupDestSlot(), Fixup.InitialBranch,
*this);
Fixup.InitialBranch->setSuccessor(0, NormalEntry);
}
Fixup.OptimisticBranchBlock = NormalExit;
Expand Down Expand Up @@ -1135,7 +1107,7 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) {

// Store the index at the start.
llvm::ConstantInt *Index = Builder.getInt32(Dest.getDestIndex());
createStoreInstBefore(Index, getNormalCleanupDestSlot(), BI);
createStoreInstBefore(Index, getNormalCleanupDestSlot(), BI, *this);

// Adjust BI to point to the first cleanup block.
{
Expand Down Expand Up @@ -1269,9 +1241,9 @@ static void SetupCleanupBlockActivation(CodeGenFunction &CGF,
// If we're in a conditional block, ignore the dominating IP and
// use the outermost conditional branch.
if (CGF.isInConditionalBranch()) {
CGF.setBeforeOutermostConditional(value, var);
CGF.setBeforeOutermostConditional(value, var, CGF);
} else {
createStoreInstBefore(value, var, dominatingIP);
createStoreInstBefore(value, var, dominatingIP, CGF);
}
}

Expand Down Expand Up @@ -1321,7 +1293,7 @@ void CodeGenFunction::DeactivateCleanupBlock(EHScopeStack::stable_iterator C,
Scope.setActive(false);
}

Address CodeGenFunction::getNormalCleanupDestSlot() {
RawAddress CodeGenFunction::getNormalCleanupDestSlot() {
if (!NormalCleanupDest.isValid())
NormalCleanupDest =
CreateDefaultAlignTempAlloca(Builder.getInt32Ty(), "cleanup.dest.slot");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class alignas(8) EHCleanupScope : public EHScope {
Address getActiveFlag() const {
return ActiveFlag;
}
void setActiveFlag(Address Var) {
void setActiveFlag(RawAddress Var) {
assert(Var.getAlignment().isOne());
ActiveFlag = Var;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,8 @@ void CodeGenFunction::EmitCoroutineBody(const CoroutineBodyStmt &S) {
EmitStmt(S.getPromiseDeclStmt());

Address PromiseAddr = GetAddrOfLocalVar(S.getPromiseDecl());
auto *PromiseAddrVoidPtr =
new llvm::BitCastInst(PromiseAddr.getPointer(), VoidPtrTy, "", CoroId);
auto *PromiseAddrVoidPtr = new llvm::BitCastInst(
PromiseAddr.emitRawPointer(*this), VoidPtrTy, "", CoroId);
// Update CoroId to refer to the promise. We could not do it earlier because
// promise local variable was not emitted yet.
CoroId->setArgOperand(1, PromiseAddrVoidPtr);
Expand Down
28 changes: 16 additions & 12 deletions clang/lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
bool EmitDebugInfo = DI && CGM.getCodeGenOpts().hasReducedDebugInfo();

Address address = Address::invalid();
Address AllocaAddr = Address::invalid();
RawAddress AllocaAddr = RawAddress::invalid();
Address OpenMPLocalAddr = Address::invalid();
if (CGM.getLangOpts().OpenMPIRBuilder)
OpenMPLocalAddr = OMPBuilderCBHelpers::getAddressOfLocalVariable(*this, &D);
Expand Down Expand Up @@ -1524,7 +1524,10 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
// return slot, so that we can elide the copy when returning this
// variable (C++0x [class.copy]p34).
address = ReturnValue;
AllocaAddr = ReturnValue;
AllocaAddr =
RawAddress(ReturnValue.emitRawPointer(*this),
ReturnValue.getElementType(), ReturnValue.getAlignment());
;

if (const RecordType *RecordTy = Ty->getAs<RecordType>()) {
const auto *RD = RecordTy->getDecl();
Expand All @@ -1535,7 +1538,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
// to this variable. Set it to zero to indicate that NRVO was not
// applied.
llvm::Value *Zero = Builder.getFalse();
Address NRVOFlag =
RawAddress NRVOFlag =
CreateTempAlloca(Zero->getType(), CharUnits::One(), "nrvo");
EnsureInsertPoint();
Builder.CreateStore(Zero, NRVOFlag);
Expand Down Expand Up @@ -1678,7 +1681,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
}

if (D.hasAttr<AnnotateAttr>() && HaveInsertPoint())
EmitVarAnnotations(&D, address.getPointer());
EmitVarAnnotations(&D, address.emitRawPointer(*this));

// Make sure we call @llvm.lifetime.end.
if (emission.useLifetimeMarkers())
Expand Down Expand Up @@ -1851,12 +1854,13 @@ void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
llvm::Value *BaseSizeInChars =
llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity());
Address Begin = Loc.withElementType(Int8Ty);
llvm::Value *End = Builder.CreateInBoundsGEP(
Begin.getElementType(), Begin.getPointer(), SizeVal, "vla.end");
llvm::Value *End = Builder.CreateInBoundsGEP(Begin.getElementType(),
Begin.emitRawPointer(*this),
SizeVal, "vla.end");
llvm::BasicBlock *OriginBB = Builder.GetInsertBlock();
EmitBlock(LoopBB);
llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur");
Cur->addIncoming(Begin.getPointer(), OriginBB);
Cur->addIncoming(Begin.emitRawPointer(*this), OriginBB);
CharUnits CurAlign = Loc.getAlignment().alignmentOfArrayElement(EltSize);
auto *I =
Builder.CreateMemCpy(Address(Cur, Int8Ty, CurAlign),
Expand Down Expand Up @@ -2283,7 +2287,7 @@ void CodeGenFunction::emitDestroy(Address addr, QualType type,
checkZeroLength = false;
}

llvm::Value *begin = addr.getPointer();
llvm::Value *begin = addr.emitRawPointer(*this);
llvm::Value *end =
Builder.CreateInBoundsGEP(addr.getElementType(), begin, length);
emitArrayDestroy(begin, end, type, elementAlign, destroyer,
Expand Down Expand Up @@ -2543,7 +2547,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
}

Address DeclPtr = Address::invalid();
Address AllocaPtr = Address::invalid();
RawAddress AllocaPtr = Address::invalid();
bool DoStore = false;
bool IsScalar = hasScalarEvaluationKind(Ty);
bool UseIndirectDebugAddress = false;
Expand All @@ -2555,8 +2559,8 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
// Indirect argument is in alloca address space, which may be different
// from the default address space.
auto AllocaAS = CGM.getASTAllocaAddressSpace();
auto *V = DeclPtr.getPointer();
AllocaPtr = DeclPtr;
auto *V = DeclPtr.emitRawPointer(*this);
AllocaPtr = RawAddress(V, DeclPtr.getElementType(), DeclPtr.getAlignment());

// For truly ABI indirect arguments -- those that are not `byval` -- store
// the address of the argument on the stack to preserve debug information.
Expand Down Expand Up @@ -2695,7 +2699,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
}

if (D.hasAttr<AnnotateAttr>())
EmitVarAnnotations(&D, DeclPtr.getPointer());
EmitVarAnnotations(&D, DeclPtr.emitRawPointer(*this));

// We can only check return value nullability if all arguments to the
// function satisfy their nullability preconditions. This makes it necessary
Expand Down
19 changes: 11 additions & 8 deletions clang/lib/CodeGen/CGException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ namespace {
void CodeGenFunction::EmitAnyExprToExn(const Expr *e, Address addr) {
// Make sure the exception object is cleaned up if there's an
// exception during initialization.
pushFullExprCleanup<FreeException>(EHCleanup, addr.getPointer());
pushFullExprCleanup<FreeException>(EHCleanup, addr.emitRawPointer(*this));
EHScopeStack::stable_iterator cleanup = EHStack.stable_begin();

// __cxa_allocate_exception returns a void*; we need to cast this
Expand All @@ -416,8 +416,8 @@ void CodeGenFunction::EmitAnyExprToExn(const Expr *e, Address addr) {
/*IsInit*/ true);

// Deactivate the cleanup block.
DeactivateCleanupBlock(cleanup,
cast<llvm::Instruction>(typedAddr.getPointer()));
DeactivateCleanupBlock(
cleanup, cast<llvm::Instruction>(typedAddr.emitRawPointer(*this)));
}

Address CodeGenFunction::getExceptionSlot() {
Expand Down Expand Up @@ -1834,7 +1834,8 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
llvm::Value *ParentFP) {
llvm::CallInst *RecoverCall = nullptr;
CGBuilderTy Builder(*this, AllocaInsertPt);
if (auto *ParentAlloca = dyn_cast<llvm::AllocaInst>(ParentVar.getPointer())) {
if (auto *ParentAlloca =
dyn_cast_or_null<llvm::AllocaInst>(ParentVar.getBasePointer())) {
// Mark the variable escaped if nobody else referenced it and compute the
// localescape index.
auto InsertPair = ParentCGF.EscapedLocals.insert(
Expand All @@ -1851,8 +1852,8 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
// If the parent didn't have an alloca, we're doing some nested outlining.
// Just clone the existing localrecover call, but tweak the FP argument to
// use our FP value. All other arguments are constants.
auto *ParentRecover =
cast<llvm::IntrinsicInst>(ParentVar.getPointer()->stripPointerCasts());
auto *ParentRecover = cast<llvm::IntrinsicInst>(
ParentVar.emitRawPointer(*this)->stripPointerCasts());
assert(ParentRecover->getIntrinsicID() == llvm::Intrinsic::localrecover &&
"expected alloca or localrecover in parent LocalDeclMap");
RecoverCall = cast<llvm::CallInst>(ParentRecover->clone());
Expand Down Expand Up @@ -1925,7 +1926,8 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
if (isa<ImplicitParamDecl>(D) &&
D->getType() == getContext().VoidPtrTy) {
assert(D->getName().starts_with("frame_pointer"));
FramePtrAddrAlloca = cast<llvm::AllocaInst>(I.second.getPointer());
FramePtrAddrAlloca =
cast<llvm::AllocaInst>(I.second.getBasePointer());
break;
}
}
Expand Down Expand Up @@ -1986,7 +1988,8 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
LValue ThisFieldLValue =
EmitLValueForLambdaField(LambdaThisCaptureField);
if (!LambdaThisCaptureField->getType()->isPointerType()) {
CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer();
CXXThisValue =
ThisFieldLValue.getAddress(*this).emitRawPointer(*this);
} else {
CXXThisValue = EmitLoadOfLValue(ThisFieldLValue, SourceLocation())
.getScalarVal();
Expand Down
227 changes: 119 additions & 108 deletions clang/lib/CodeGen/CGExpr.cpp

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions clang/lib/CodeGen/CGExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ void AggExprEmitter::withReturnValueSlot(
// Otherwise, EmitCall will emit its own, notice that it's "unused", and end
// its lifetime before we have the chance to emit a proper destructor call.
bool UseTemp = Dest.isPotentiallyAliased() || Dest.requiresGCollection() ||
(RequiresDestruction && !Dest.getAddress().isValid());
(RequiresDestruction && Dest.isIgnored());

Address RetAddr = Address::invalid();
Address RetAllocaAddr = Address::invalid();
RawAddress RetAllocaAddr = RawAddress::invalid();

EHScopeStack::stable_iterator LifetimeEndBlock;
llvm::Value *LifetimeSizePtr = nullptr;
Expand Down Expand Up @@ -329,7 +329,8 @@ void AggExprEmitter::withReturnValueSlot(
if (!UseTemp)
return;

assert(Dest.isIgnored() || Dest.getPointer() != Src.getAggregatePointer());
assert(Dest.isIgnored() || Dest.emitRawPointer(CGF) !=
Src.getAggregatePointer(E->getType(), CGF));
EmitFinalDestCopy(E->getType(), Src);

if (!RequiresDestruction && LifetimeStartInst) {
Expand Down Expand Up @@ -448,7 +449,8 @@ AggExprEmitter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
llvm::Value *Zero = llvm::ConstantInt::get(CGF.PtrDiffTy, 0);
llvm::Value *IdxStart[] = { Zero, Zero };
llvm::Value *ArrayStart = Builder.CreateInBoundsGEP(
ArrayPtr.getElementType(), ArrayPtr.getPointer(), IdxStart, "arraystart");
ArrayPtr.getElementType(), ArrayPtr.emitRawPointer(CGF), IdxStart,
"arraystart");
CGF.EmitStoreThroughLValue(RValue::get(ArrayStart), Start);
++Field;

Expand All @@ -465,7 +467,8 @@ AggExprEmitter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
// End pointer.
llvm::Value *IdxEnd[] = { Zero, Size };
llvm::Value *ArrayEnd = Builder.CreateInBoundsGEP(
ArrayPtr.getElementType(), ArrayPtr.getPointer(), IdxEnd, "arrayend");
ArrayPtr.getElementType(), ArrayPtr.emitRawPointer(CGF), IdxEnd,
"arrayend");
CGF.EmitStoreThroughLValue(RValue::get(ArrayEnd), EndOrLength);
} else if (Ctx.hasSameType(Field->getType(), Ctx.getSizeType())) {
// Length.
Expand Down Expand Up @@ -516,9 +519,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
// down a level.
llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0);
llvm::Value *indices[] = { zero, zero };
llvm::Value *begin = Builder.CreateInBoundsGEP(
DestPtr.getElementType(), DestPtr.getPointer(), indices,
"arrayinit.begin");
llvm::Value *begin = Builder.CreateInBoundsGEP(DestPtr.getElementType(),
DestPtr.emitRawPointer(CGF),
indices, "arrayinit.begin");

CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
CharUnits elementAlign =
Expand Down Expand Up @@ -1059,7 +1062,7 @@ void AggExprEmitter::VisitBinCmp(const BinaryOperator *E) {
if (RV.isScalar())
return {RV.getScalarVal(), nullptr};
if (RV.isAggregate())
return {RV.getAggregatePointer(), nullptr};
return {RV.getAggregatePointer(E->getType(), CGF), nullptr};
assert(RV.isComplex());
return RV.getComplexVal();
};
Expand Down Expand Up @@ -1818,7 +1821,7 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
// else, clean it up for -O0 builds and general tidiness.
if (!pushedCleanup && LV.isSimple())
if (llvm::GetElementPtrInst *GEP =
dyn_cast<llvm::GetElementPtrInst>(LV.getPointer(CGF)))
dyn_cast<llvm::GetElementPtrInst>(LV.emitRawPointer(CGF)))
if (GEP->use_empty())
GEP->eraseFromParent();
}
Expand Down Expand Up @@ -1849,9 +1852,9 @@ void AggExprEmitter::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E,
// destPtr is an array*. Construct an elementType* by drilling down a level.
llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0);
llvm::Value *indices[] = {zero, zero};
llvm::Value *begin = Builder.CreateInBoundsGEP(
destPtr.getElementType(), destPtr.getPointer(), indices,
"arrayinit.begin");
llvm::Value *begin = Builder.CreateInBoundsGEP(destPtr.getElementType(),
destPtr.emitRawPointer(CGF),
indices, "arrayinit.begin");

// Prepare to special-case multidimensional array initialization: we avoid
// emitting multiple destructor loops in that case.
Expand Down
111 changes: 51 additions & 60 deletions clang/lib/CodeGen/CGExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ RValue CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(
LValueBaseInfo BaseInfo;
TBAAAccessInfo TBAAInfo;
Address ThisValue = EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
This = MakeAddrLValue(ThisValue, Base->getType(), BaseInfo, TBAAInfo);
This = MakeAddrLValue(ThisValue, Base->getType()->getPointeeType(),
BaseInfo, TBAAInfo);
} else {
This = EmitLValue(Base);
}
Expand Down Expand Up @@ -353,10 +354,8 @@ RValue CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(
if (IsImplicitObjectCXXThis || isa<DeclRefExpr>(IOA))
SkippedChecks.set(SanitizerKind::Null, true);
}
EmitTypeCheck(CodeGenFunction::TCK_MemberCall, CallLoc,
This.getPointer(*this),
C.getRecordType(CalleeDecl->getParent()),
/*Alignment=*/CharUnits::Zero(), SkippedChecks);
EmitTypeCheck(CodeGenFunction::TCK_MemberCall, CallLoc, This,
C.getRecordType(CalleeDecl->getParent()), SkippedChecks);

// C++ [class.virtual]p12:
// Explicit qualification with the scope operator (5.1) suppresses the
Expand Down Expand Up @@ -455,7 +454,7 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
else
This = EmitLValue(BaseExpr, KnownNonNull).getAddress(*this);

EmitTypeCheck(TCK_MemberCall, E->getExprLoc(), This.getPointer(),
EmitTypeCheck(TCK_MemberCall, E->getExprLoc(), This.emitRawPointer(*this),
QualType(MPT->getClass(), 0));

// Get the member function pointer.
Expand Down Expand Up @@ -1109,9 +1108,10 @@ void CodeGenFunction::EmitNewArrayInitializer(
// alloca.
EndOfInit = CreateTempAlloca(BeginPtr.getType(), getPointerAlign(),
"array.init.end");
CleanupDominator = Builder.CreateStore(BeginPtr.getPointer(), EndOfInit);
pushIrregularPartialArrayCleanup(BeginPtr.getPointer(), EndOfInit,
ElementType, ElementAlign,
CleanupDominator =
Builder.CreateStore(BeginPtr.emitRawPointer(*this), EndOfInit);
pushIrregularPartialArrayCleanup(BeginPtr.emitRawPointer(*this),
EndOfInit, ElementType, ElementAlign,
getDestroyer(DtorKind));
Cleanup = EHStack.stable_begin();
}
Expand All @@ -1123,16 +1123,17 @@ void CodeGenFunction::EmitNewArrayInitializer(
// element. TODO: some of these stores can be trivially
// observed to be unnecessary.
if (EndOfInit.isValid()) {
Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
Builder.CreateStore(CurPtr.emitRawPointer(*this), EndOfInit);
}
// FIXME: If the last initializer is an incomplete initializer list for
// an array, and we have an array filler, we can fold together the two
// initialization loops.
StoreAnyExprIntoOneUnit(*this, IE, IE->getType(), CurPtr,
AggValueSlot::DoesNotOverlap);
CurPtr = Address(Builder.CreateInBoundsGEP(
CurPtr.getElementType(), CurPtr.getPointer(),
Builder.getSize(1), "array.exp.next"),
CurPtr = Address(Builder.CreateInBoundsGEP(CurPtr.getElementType(),
CurPtr.emitRawPointer(*this),
Builder.getSize(1),
"array.exp.next"),
CurPtr.getElementType(),
StartAlign.alignmentAtOffset((++i) * ElementSize));
}
Expand Down Expand Up @@ -1186,7 +1187,7 @@ void CodeGenFunction::EmitNewArrayInitializer(
// FIXME: Share this cleanup with the constructor call emission rather than
// having it create a cleanup of its own.
if (EndOfInit.isValid())
Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
Builder.CreateStore(CurPtr.emitRawPointer(*this), EndOfInit);

// Emit a constructor call loop to initialize the remaining elements.
if (InitListElements)
Expand Down Expand Up @@ -1249,15 +1250,15 @@ void CodeGenFunction::EmitNewArrayInitializer(
llvm::BasicBlock *ContBB = createBasicBlock("new.loop.end");

// Find the end of the array, hoisted out of the loop.
llvm::Value *EndPtr =
Builder.CreateInBoundsGEP(BeginPtr.getElementType(), BeginPtr.getPointer(),
NumElements, "array.end");
llvm::Value *EndPtr = Builder.CreateInBoundsGEP(
BeginPtr.getElementType(), BeginPtr.emitRawPointer(*this), NumElements,
"array.end");

// If the number of elements isn't constant, we have to now check if there is
// anything left to initialize.
if (!ConstNum) {
llvm::Value *IsEmpty =
Builder.CreateICmpEQ(CurPtr.getPointer(), EndPtr, "array.isempty");
llvm::Value *IsEmpty = Builder.CreateICmpEQ(CurPtr.emitRawPointer(*this),
EndPtr, "array.isempty");
Builder.CreateCondBr(IsEmpty, ContBB, LoopBB);
}

Expand All @@ -1267,19 +1268,20 @@ void CodeGenFunction::EmitNewArrayInitializer(
// Set up the current-element phi.
llvm::PHINode *CurPtrPhi =
Builder.CreatePHI(CurPtr.getType(), 2, "array.cur");
CurPtrPhi->addIncoming(CurPtr.getPointer(), EntryBB);
CurPtrPhi->addIncoming(CurPtr.emitRawPointer(*this), EntryBB);

CurPtr = Address(CurPtrPhi, CurPtr.getElementType(), ElementAlign);

// Store the new Cleanup position for irregular Cleanups.
if (EndOfInit.isValid())
Builder.CreateStore(CurPtr.getPointer(), EndOfInit);
Builder.CreateStore(CurPtr.emitRawPointer(*this), EndOfInit);

// Enter a partial-destruction Cleanup if necessary.
if (!CleanupDominator && needsEHCleanup(DtorKind)) {
pushRegularPartialArrayCleanup(BeginPtr.getPointer(), CurPtr.getPointer(),
ElementType, ElementAlign,
getDestroyer(DtorKind));
llvm::Value *BeginPtrRaw = BeginPtr.emitRawPointer(*this);
llvm::Value *CurPtrRaw = CurPtr.emitRawPointer(*this);
pushRegularPartialArrayCleanup(BeginPtrRaw, CurPtrRaw, ElementType,
ElementAlign, getDestroyer(DtorKind));
Cleanup = EHStack.stable_begin();
CleanupDominator = Builder.CreateUnreachable();
}
Expand All @@ -1295,9 +1297,8 @@ void CodeGenFunction::EmitNewArrayInitializer(
}

// Advance to the next element by adjusting the pointer type as necessary.
llvm::Value *NextPtr =
Builder.CreateConstInBoundsGEP1_32(ElementTy, CurPtr.getPointer(), 1,
"array.next");
llvm::Value *NextPtr = Builder.CreateConstInBoundsGEP1_32(
ElementTy, CurPtr.emitRawPointer(*this), 1, "array.next");

// Check whether we've gotten to the end of the array and, if so,
// exit the loop.
Expand Down Expand Up @@ -1523,14 +1524,9 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF,

typedef CallDeleteDuringNew<DirectCleanupTraits> DirectCleanup;

DirectCleanup *Cleanup = CGF.EHStack
.pushCleanupWithExtra<DirectCleanup>(EHCleanup,
E->getNumPlacementArgs(),
E->getOperatorDelete(),
NewPtr.getPointer(),
AllocSize,
E->passAlignment(),
AllocAlign);
DirectCleanup *Cleanup = CGF.EHStack.pushCleanupWithExtra<DirectCleanup>(
EHCleanup, E->getNumPlacementArgs(), E->getOperatorDelete(),
NewPtr.emitRawPointer(CGF), AllocSize, E->passAlignment(), AllocAlign);
for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
auto &Arg = NewArgs[I + NumNonPlacementArgs];
Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty);
Expand All @@ -1541,7 +1537,7 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF,

// Otherwise, we need to save all this stuff.
DominatingValue<RValue>::saved_type SavedNewPtr =
DominatingValue<RValue>::save(CGF, RValue::get(NewPtr.getPointer()));
DominatingValue<RValue>::save(CGF, RValue::get(NewPtr, CGF));
DominatingValue<RValue>::saved_type SavedAllocSize =
DominatingValue<RValue>::save(CGF, RValue::get(AllocSize));

Expand Down Expand Up @@ -1618,14 +1614,14 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
// In these cases, discard the computed alignment and use the
// formal alignment of the allocated type.
if (BaseInfo.getAlignmentSource() != AlignmentSource::Decl)
allocation = allocation.withAlignment(allocAlign);
allocation.setAlignment(allocAlign);

// Set up allocatorArgs for the call to operator delete if it's not
// the reserved global operator.
if (E->getOperatorDelete() &&
!E->getOperatorDelete()->isReservedGlobalPlacementOperator()) {
allocatorArgs.add(RValue::get(allocSize), getContext().getSizeType());
allocatorArgs.add(RValue::get(allocation.getPointer()), arg->getType());
allocatorArgs.add(RValue::get(allocation, *this), arg->getType());
}

} else {
Expand Down Expand Up @@ -1713,8 +1709,7 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
llvm::BasicBlock *notNullBB = createBasicBlock("new.notnull");
contBB = createBasicBlock("new.cont");

llvm::Value *isNull =
Builder.CreateIsNull(allocation.getPointer(), "new.isnull");
llvm::Value *isNull = Builder.CreateIsNull(allocation, "new.isnull");
Builder.CreateCondBr(isNull, contBB, notNullBB);
EmitBlock(notNullBB);
}
Expand Down Expand Up @@ -1760,12 +1755,12 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
SkippedChecks.set(SanitizerKind::Null, nullCheck);
EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall,
E->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
result.getPointer(), allocType, result.getAlignment(),
SkippedChecks, numElements);
result, allocType, result.getAlignment(), SkippedChecks,
numElements);

EmitNewInitializer(*this, E, allocType, elementTy, result, numElements,
allocSizeWithoutCookie);
llvm::Value *resultPtr = result.getPointer();
llvm::Value *resultPtr = result.emitRawPointer(*this);
if (E->isArray()) {
// NewPtr is a pointer to the base element type. If we're
// allocating an array of arrays, we'll need to cast back to the
Expand Down Expand Up @@ -1909,7 +1904,8 @@ static void EmitDestroyingObjectDelete(CodeGenFunction &CGF,
CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,
Dtor);
else
CGF.EmitDeleteCall(DE->getOperatorDelete(), Ptr.getPointer(), ElementType);
CGF.EmitDeleteCall(DE->getOperatorDelete(), Ptr.emitRawPointer(CGF),
ElementType);
}

/// Emit the code for deleting a single object.
Expand All @@ -1925,8 +1921,7 @@ static bool EmitObjectDelete(CodeGenFunction &CGF,
// dynamic type, the static type shall be a base class of the dynamic type
// of the object to be deleted and the static type shall have a virtual
// destructor or the behavior is undefined.
CGF.EmitTypeCheck(CodeGenFunction::TCK_MemberCall,
DE->getExprLoc(), Ptr.getPointer(),
CGF.EmitTypeCheck(CodeGenFunction::TCK_MemberCall, DE->getExprLoc(), Ptr,
ElementType);

const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
Expand Down Expand Up @@ -1975,9 +1970,8 @@ static bool EmitObjectDelete(CodeGenFunction &CGF,
// Make sure that we call delete even if the dtor throws.
// This doesn't have to a conditional cleanup because we're going
// to pop it off in a second.
CGF.EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup,
Ptr.getPointer(),
OperatorDelete, ElementType);
CGF.EHStack.pushCleanup<CallObjectDelete>(
NormalAndEHCleanup, Ptr.emitRawPointer(CGF), OperatorDelete, ElementType);

if (Dtor)
CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete,
Expand Down Expand Up @@ -2064,7 +2058,7 @@ static void EmitArrayDelete(CodeGenFunction &CGF,
CharUnits elementAlign =
deletedPtr.getAlignment().alignmentOfArrayElement(elementSize);

llvm::Value *arrayBegin = deletedPtr.getPointer();
llvm::Value *arrayBegin = deletedPtr.emitRawPointer(CGF);
llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP(
deletedPtr.getElementType(), arrayBegin, numElements, "delete.end");

Expand Down Expand Up @@ -2095,7 +2089,7 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
llvm::BasicBlock *DeleteNotNull = createBasicBlock("delete.notnull");
llvm::BasicBlock *DeleteEnd = createBasicBlock("delete.end");

llvm::Value *IsNull = Builder.CreateIsNull(Ptr.getPointer(), "isnull");
llvm::Value *IsNull = Builder.CreateIsNull(Ptr, "isnull");

Builder.CreateCondBr(IsNull, DeleteEnd, DeleteNotNull);
EmitBlock(DeleteNotNull);
Expand Down Expand Up @@ -2130,10 +2124,8 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
GEP.push_back(Zero);
}

Ptr = Address(Builder.CreateInBoundsGEP(Ptr.getElementType(),
Ptr.getPointer(), GEP, "del.first"),
ConvertTypeForMem(DeleteTy), Ptr.getAlignment(),
Ptr.isKnownNonNull());
Ptr = Builder.CreateInBoundsGEP(Ptr, GEP, ConvertTypeForMem(DeleteTy),
Ptr.getAlignment(), "del.first");
}

assert(ConvertTypeForMem(DeleteTy) == Ptr.getElementType());
Expand Down Expand Up @@ -2191,7 +2183,7 @@ static llvm::Value *EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E,
// destruction and the static type of the operand is neither the constructor
// or destructor’s class nor one of its bases, the behavior is undefined.
CGF.EmitTypeCheck(CodeGenFunction::TCK_DynamicOperation, E->getExprLoc(),
ThisPtr.getPointer(), SrcRecordTy);
ThisPtr, SrcRecordTy);

// C++ [expr.typeid]p2:
// If the glvalue expression is obtained by applying the unary * operator to
Expand All @@ -2207,7 +2199,7 @@ static llvm::Value *EmitTypeidFromVTable(CodeGenFunction &CGF, const Expr *E,
CGF.createBasicBlock("typeid.bad_typeid");
llvm::BasicBlock *EndBlock = CGF.createBasicBlock("typeid.end");

llvm::Value *IsNull = CGF.Builder.CreateIsNull(ThisPtr.getPointer());
llvm::Value *IsNull = CGF.Builder.CreateIsNull(ThisPtr);
CGF.Builder.CreateCondBr(IsNull, BadTypeidBlock, EndBlock);

CGF.EmitBlock(BadTypeidBlock);
Expand Down Expand Up @@ -2293,8 +2285,7 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(Address ThisAddr,
// construction or destruction and the static type of the operand is not a
// pointer to or object of the constructor or destructor’s own class or one
// of its bases, the dynamic_cast results in undefined behavior.
EmitTypeCheck(TCK_DynamicOperation, DCE->getExprLoc(), ThisAddr.getPointer(),
SrcRecordTy);
EmitTypeCheck(TCK_DynamicOperation, DCE->getExprLoc(), ThisAddr, SrcRecordTy);

if (DCE->isAlwaysNull()) {
if (llvm::Value *T = EmitDynamicCastToNull(*this, DestTy)) {
Expand Down Expand Up @@ -2329,7 +2320,7 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(Address ThisAddr,
CastNull = createBasicBlock("dynamic_cast.null");
CastNotNull = createBasicBlock("dynamic_cast.notnull");

llvm::Value *IsNull = Builder.CreateIsNull(ThisAddr.getPointer());
llvm::Value *IsNull = Builder.CreateIsNull(ThisAddr);
Builder.CreateCondBr(IsNull, CastNull, CastNotNull);
EmitBlock(CastNotNull);
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ bool ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD,
// Add a vtable pointer, if we need one and it hasn't already been added.
if (Layout.hasOwnVFPtr()) {
llvm::Constant *VTableAddressPoint =
CGM.getCXXABI().getVTableAddressPointForConstExpr(
BaseSubobject(CD, Offset), VTableClass);
CGM.getCXXABI().getVTableAddressPoint(BaseSubobject(CD, Offset),
VTableClass);
if (!AppendBytes(Offset, VTableAddressPoint))
return false;
}
Expand Down
23 changes: 19 additions & 4 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2250,21 +2250,22 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
// performed and the object is not of the derived type.
if (CGF.sanitizePerformTypeCheck())
CGF.EmitTypeCheck(CodeGenFunction::TCK_DowncastPointer, CE->getExprLoc(),
Derived.getPointer(), DestTy->getPointeeType());
Derived, DestTy->getPointeeType());

if (CGF.SanOpts.has(SanitizerKind::CFIDerivedCast))
CGF.EmitVTablePtrCheckForCast(DestTy->getPointeeType(), Derived,
/*MayBeNull=*/true,
CodeGenFunction::CFITCK_DerivedCast,
CE->getBeginLoc());

return Derived.getPointer();
return CGF.getAsNaturalPointerTo(Derived, CE->getType()->getPointeeType());
}
case CK_UncheckedDerivedToBase:
case CK_DerivedToBase: {
// The EmitPointerWithAlignment path does this fine; just discard
// the alignment.
return CGF.EmitPointerWithAlignment(CE).getPointer();
return CGF.getAsNaturalPointerTo(CGF.EmitPointerWithAlignment(CE),
CE->getType()->getPointeeType());
}

case CK_Dynamic: {
Expand All @@ -2274,7 +2275,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
}

case CK_ArrayToPointerDecay:
return CGF.EmitArrayToPointerDecay(E).getPointer();
return CGF.getAsNaturalPointerTo(CGF.EmitArrayToPointerDecay(E),
CE->getType()->getPointeeType());
case CK_FunctionToPointerDecay:
return EmitLValue(E).getPointer(CGF);

Expand Down Expand Up @@ -5588,3 +5590,16 @@ CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr,

return GEPVal;
}

Address CodeGenFunction::EmitCheckedInBoundsGEP(
Address Addr, ArrayRef<Value *> IdxList, llvm::Type *elementType,
bool SignedIndices, bool IsSubtraction, SourceLocation Loc, CharUnits Align,
const Twine &Name) {
if (!SanOpts.has(SanitizerKind::PointerOverflow))
return Builder.CreateInBoundsGEP(Addr, IdxList, elementType, Align, Name);

return RawAddress(
EmitCheckedInBoundsGEP(Addr.getElementType(), Addr.emitRawPointer(*this),
IdxList, SignedIndices, IsSubtraction, Loc, Name),
elementType, Align);
}
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/CGNonTrivialStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ template <class Derived> struct GenFuncBase {
llvm::Value *SizeInBytes =
CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
llvm::Value *DstArrayEnd = CGF.Builder.CreateInBoundsGEP(
CGF.Int8Ty, DstAddr.getPointer(), SizeInBytes);
CGF.Int8Ty, DstAddr.emitRawPointer(CGF), SizeInBytes);
llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();

// Create the header block and insert the phi instructions.
Expand All @@ -376,7 +376,7 @@ template <class Derived> struct GenFuncBase {

for (unsigned I = 0; I < N; ++I) {
PHIs[I] = CGF.Builder.CreatePHI(CGF.CGM.Int8PtrPtrTy, 2, "addr.cur");
PHIs[I]->addIncoming(StartAddrs[I].getPointer(), PreheaderBB);
PHIs[I]->addIncoming(StartAddrs[I].emitRawPointer(CGF), PreheaderBB);
}

// Create the exit and loop body blocks.
Expand Down Expand Up @@ -410,7 +410,7 @@ template <class Derived> struct GenFuncBase {
// Instrs to update the destination and source addresses.
// Update phi instructions.
NewAddrs[I] = getAddrWithOffset(NewAddrs[I], EltSize);
PHIs[I]->addIncoming(NewAddrs[I].getPointer(), LoopBB);
PHIs[I]->addIncoming(NewAddrs[I].emitRawPointer(CGF), LoopBB);
}

// Insert an unconditional branch to the header block.
Expand Down Expand Up @@ -488,7 +488,7 @@ template <class Derived> struct GenFuncBase {

for (unsigned I = 0; I < N; ++I) {
Alignments[I] = Addrs[I].getAlignment();
Ptrs[I] = Addrs[I].getPointer();
Ptrs[I] = Addrs[I].emitRawPointer(CallerCGF);
}

if (llvm::Function *F =
Expand Down
43 changes: 19 additions & 24 deletions clang/lib/CodeGen/CGObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ CodeGenFunction::EmitObjCBoxedExpr(const ObjCBoxedExpr *E) {
// and cast value to correct type
Address Temporary = CreateMemTemp(SubExpr->getType());
EmitAnyExprToMem(SubExpr, Temporary, Qualifiers(), /*isInit*/ true);
llvm::Value *BitCast =
Builder.CreateBitCast(Temporary.getPointer(), ConvertType(ArgQT));
llvm::Value *BitCast = Builder.CreateBitCast(
Temporary.emitRawPointer(*this), ConvertType(ArgQT));
Args.add(RValue::get(BitCast), ArgQT);

// Create char array to store type encoding
Expand Down Expand Up @@ -204,11 +204,11 @@ llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,
ObjCMethodDecl::param_const_iterator PI = MethodWithObjects->param_begin();
const ParmVarDecl *argDecl = *PI++;
QualType ArgQT = argDecl->getType().getUnqualifiedType();
Args.add(RValue::get(Objects.getPointer()), ArgQT);
Args.add(RValue::get(Objects, *this), ArgQT);
if (DLE) {
argDecl = *PI++;
ArgQT = argDecl->getType().getUnqualifiedType();
Args.add(RValue::get(Keys.getPointer()), ArgQT);
Args.add(RValue::get(Keys, *this), ArgQT);
}
argDecl = *PI;
ArgQT = argDecl->getType().getUnqualifiedType();
Expand Down Expand Up @@ -827,7 +827,7 @@ static void emitStructGetterCall(CodeGenFunction &CGF, ObjCIvarDecl *ivar,
// sizeof (Type of Ivar), isAtomic, false);
CallArgList args;

llvm::Value *dest = CGF.ReturnValue.getPointer();
llvm::Value *dest = CGF.ReturnValue.emitRawPointer(CGF);
args.add(RValue::get(dest), Context.VoidPtrTy);
args.add(RValue::get(src), Context.VoidPtrTy);

Expand Down Expand Up @@ -1147,8 +1147,8 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
callCStructCopyConstructor(Dst, Src);
} else {
ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
emitCPPObjectAtomicGetterCall(*this, ReturnValue.getPointer(), ivar,
AtomicHelperFn);
emitCPPObjectAtomicGetterCall(*this, ReturnValue.emitRawPointer(*this),
ivar, AtomicHelperFn);
}
return;
}
Expand All @@ -1163,7 +1163,7 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
}
else {
ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl();
emitCPPObjectAtomicGetterCall(*this, ReturnValue.getPointer(),
emitCPPObjectAtomicGetterCall(*this, ReturnValue.emitRawPointer(*this),
ivar, AtomicHelperFn);
}
return;
Expand Down Expand Up @@ -1287,7 +1287,7 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
case TEK_Scalar: {
llvm::Value *value;
if (propType->isReferenceType()) {
value = LV.getAddress(*this).getPointer();
value = LV.getAddress(*this).emitRawPointer(*this);
} else {
// We want to load and autoreleaseReturnValue ARC __weak ivars.
if (LV.getQuals().getObjCLifetime() == Qualifiers::OCL_Weak) {
Expand Down Expand Up @@ -1821,16 +1821,14 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
CallArgList Args;

// The first argument is a temporary of the enumeration-state type.
Args.add(RValue::get(StatePtr.getPointer()),
getContext().getPointerType(StateTy));
Args.add(RValue::get(StatePtr, *this), getContext().getPointerType(StateTy));

// The second argument is a temporary array with space for NumItems
// pointers. We'll actually be loading elements from the array
// pointer written into the control state; this buffer is so that
// collections that *aren't* backed by arrays can still queue up
// batches of elements.
Args.add(RValue::get(ItemsPtr.getPointer()),
getContext().getPointerType(ItemsTy));
Args.add(RValue::get(ItemsPtr, *this), getContext().getPointerType(ItemsTy));

// The third argument is the capacity of that temporary array.
llvm::Type *NSUIntegerTy = ConvertType(getContext().getNSUIntegerType());
Expand Down Expand Up @@ -2198,7 +2196,7 @@ static llvm::Value *emitARCLoadOperation(CodeGenFunction &CGF, Address addr,
if (!fn)
fn = getARCIntrinsic(IntID, CGF.CGM);

return CGF.EmitNounwindRuntimeCall(fn, addr.getPointer());
return CGF.EmitNounwindRuntimeCall(fn, addr.emitRawPointer(CGF));
}

/// Perform an operation having the following signature:
Expand All @@ -2216,9 +2214,8 @@ static llvm::Value *emitARCStoreOperation(CodeGenFunction &CGF, Address addr,
llvm::Type *origType = value->getType();

llvm::Value *args[] = {
CGF.Builder.CreateBitCast(addr.getPointer(), CGF.Int8PtrPtrTy),
CGF.Builder.CreateBitCast(value, CGF.Int8PtrTy)
};
CGF.Builder.CreateBitCast(addr.emitRawPointer(CGF), CGF.Int8PtrPtrTy),
CGF.Builder.CreateBitCast(value, CGF.Int8PtrTy)};
llvm::CallInst *result = CGF.EmitNounwindRuntimeCall(fn, args);

if (ignored) return nullptr;
Expand All @@ -2237,9 +2234,8 @@ static void emitARCCopyOperation(CodeGenFunction &CGF, Address dst, Address src,
fn = getARCIntrinsic(IntID, CGF.CGM);

llvm::Value *args[] = {
CGF.Builder.CreateBitCast(dst.getPointer(), CGF.Int8PtrPtrTy),
CGF.Builder.CreateBitCast(src.getPointer(), CGF.Int8PtrPtrTy)
};
CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF), CGF.Int8PtrPtrTy),
CGF.Builder.CreateBitCast(src.emitRawPointer(CGF), CGF.Int8PtrPtrTy)};
CGF.EmitNounwindRuntimeCall(fn, args);
}

Expand Down Expand Up @@ -2490,9 +2486,8 @@ llvm::Value *CodeGenFunction::EmitARCStoreStrongCall(Address addr,
fn = getARCIntrinsic(llvm::Intrinsic::objc_storeStrong, CGM);

llvm::Value *args[] = {
Builder.CreateBitCast(addr.getPointer(), Int8PtrPtrTy),
Builder.CreateBitCast(value, Int8PtrTy)
};
Builder.CreateBitCast(addr.emitRawPointer(*this), Int8PtrPtrTy),
Builder.CreateBitCast(value, Int8PtrTy)};
EmitNounwindRuntimeCall(fn, args);

if (ignored) return nullptr;
Expand Down Expand Up @@ -2643,7 +2638,7 @@ void CodeGenFunction::EmitARCDestroyWeak(Address addr) {
if (!fn)
fn = getARCIntrinsic(llvm::Intrinsic::objc_destroyWeak, CGM);

EmitNounwindRuntimeCall(fn, addr.getPointer());
EmitNounwindRuntimeCall(fn, addr.emitRawPointer(*this));
}

/// void \@objc_moveWeak(i8** %dest, i8** %src)
Expand Down
42 changes: 22 additions & 20 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ class CGObjCGCC : public CGObjCGNU {
llvm::Value *cmd, MessageSendInfo &MSI) override {
CGBuilderTy &Builder = CGF.Builder;
llvm::Value *lookupArgs[] = {
EnforceType(Builder, ObjCSuper.getPointer(), PtrToObjCSuperTy), cmd};
EnforceType(Builder, ObjCSuper.emitRawPointer(CGF), PtrToObjCSuperTy),
cmd};
return CGF.EmitNounwindRuntimeCall(MsgLookupSuperFn, lookupArgs);
}

Expand Down Expand Up @@ -761,8 +762,8 @@ class CGObjCGNUstep : public CGObjCGNU {
llvm::FunctionCallee LookupFn = SlotLookupFn;

// Store the receiver on the stack so that we can reload it later
Address ReceiverPtr =
CGF.CreateTempAlloca(Receiver->getType(), CGF.getPointerAlign());
RawAddress ReceiverPtr =
CGF.CreateTempAlloca(Receiver->getType(), CGF.getPointerAlign());
Builder.CreateStore(Receiver, ReceiverPtr);

llvm::Value *self;
Expand All @@ -778,9 +779,9 @@ class CGObjCGNUstep : public CGObjCGNU {
LookupFn2->addParamAttr(0, llvm::Attribute::NoCapture);

llvm::Value *args[] = {
EnforceType(Builder, ReceiverPtr.getPointer(), PtrToIdTy),
EnforceType(Builder, cmd, SelectorTy),
EnforceType(Builder, self, IdTy) };
EnforceType(Builder, ReceiverPtr.getPointer(), PtrToIdTy),
EnforceType(Builder, cmd, SelectorTy),
EnforceType(Builder, self, IdTy)};
llvm::CallBase *slot = CGF.EmitRuntimeCallOrInvoke(LookupFn, args);
slot->setOnlyReadsMemory();
slot->setMetadata(msgSendMDKind, node);
Expand All @@ -800,7 +801,7 @@ class CGObjCGNUstep : public CGObjCGNU {
llvm::Value *cmd,
MessageSendInfo &MSI) override {
CGBuilderTy &Builder = CGF.Builder;
llvm::Value *lookupArgs[] = {ObjCSuper.getPointer(), cmd};
llvm::Value *lookupArgs[] = {ObjCSuper.emitRawPointer(CGF), cmd};

llvm::CallInst *slot =
CGF.EmitNounwindRuntimeCall(SlotLookupSuperFn, lookupArgs);
Expand Down Expand Up @@ -1221,10 +1222,10 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
llvm::Value *cmd, MessageSendInfo &MSI) override {
// Don't access the slot unless we're trying to cache the result.
CGBuilderTy &Builder = CGF.Builder;
llvm::Value *lookupArgs[] = {CGObjCGNU::EnforceType(Builder,
ObjCSuper.getPointer(),
PtrToObjCSuperTy),
cmd};
llvm::Value *lookupArgs[] = {
CGObjCGNU::EnforceType(Builder, ObjCSuper.emitRawPointer(CGF),
PtrToObjCSuperTy),
cmd};
return CGF.EmitNounwindRuntimeCall(MsgLookupSuperFn, lookupArgs);
}

Expand Down Expand Up @@ -2186,7 +2187,8 @@ class CGObjCObjFW: public CGObjCGNU {
llvm::Value *cmd, MessageSendInfo &MSI) override {
CGBuilderTy &Builder = CGF.Builder;
llvm::Value *lookupArgs[] = {
EnforceType(Builder, ObjCSuper.getPointer(), PtrToObjCSuperTy), cmd,
EnforceType(Builder, ObjCSuper.emitRawPointer(CGF), PtrToObjCSuperTy),
cmd,
};

if (CGM.ReturnTypeUsesSRet(MSI.CallInfo))
Expand Down Expand Up @@ -4201,15 +4203,15 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,
llvm::Value * CGObjCGNU::EmitObjCWeakRead(CodeGenFunction &CGF,
Address AddrWeakObj) {
CGBuilderTy &B = CGF.Builder;
return B.CreateCall(WeakReadFn,
EnforceType(B, AddrWeakObj.getPointer(), PtrToIdTy));
return B.CreateCall(
WeakReadFn, EnforceType(B, AddrWeakObj.emitRawPointer(CGF), PtrToIdTy));
}

void CGObjCGNU::EmitObjCWeakAssign(CodeGenFunction &CGF,
llvm::Value *src, Address dst) {
CGBuilderTy &B = CGF.Builder;
src = EnforceType(B, src, IdTy);
llvm::Value *dstVal = EnforceType(B, dst.getPointer(), PtrToIdTy);
llvm::Value *dstVal = EnforceType(B, dst.emitRawPointer(CGF), PtrToIdTy);
B.CreateCall(WeakAssignFn, {src, dstVal});
}

Expand All @@ -4218,7 +4220,7 @@ void CGObjCGNU::EmitObjCGlobalAssign(CodeGenFunction &CGF,
bool threadlocal) {
CGBuilderTy &B = CGF.Builder;
src = EnforceType(B, src, IdTy);
llvm::Value *dstVal = EnforceType(B, dst.getPointer(), PtrToIdTy);
llvm::Value *dstVal = EnforceType(B, dst.emitRawPointer(CGF), PtrToIdTy);
// FIXME. Add threadloca assign API
assert(!threadlocal && "EmitObjCGlobalAssign - Threal Local API NYI");
B.CreateCall(GlobalAssignFn, {src, dstVal});
Expand All @@ -4229,15 +4231,15 @@ void CGObjCGNU::EmitObjCIvarAssign(CodeGenFunction &CGF,
llvm::Value *ivarOffset) {
CGBuilderTy &B = CGF.Builder;
src = EnforceType(B, src, IdTy);
llvm::Value *dstVal = EnforceType(B, dst.getPointer(), IdTy);
llvm::Value *dstVal = EnforceType(B, dst.emitRawPointer(CGF), IdTy);
B.CreateCall(IvarAssignFn, {src, dstVal, ivarOffset});
}

void CGObjCGNU::EmitObjCStrongCastAssign(CodeGenFunction &CGF,
llvm::Value *src, Address dst) {
CGBuilderTy &B = CGF.Builder;
src = EnforceType(B, src, IdTy);
llvm::Value *dstVal = EnforceType(B, dst.getPointer(), PtrToIdTy);
llvm::Value *dstVal = EnforceType(B, dst.emitRawPointer(CGF), PtrToIdTy);
B.CreateCall(StrongCastAssignFn, {src, dstVal});
}

Expand All @@ -4246,8 +4248,8 @@ void CGObjCGNU::EmitGCMemmoveCollectable(CodeGenFunction &CGF,
Address SrcPtr,
llvm::Value *Size) {
CGBuilderTy &B = CGF.Builder;
llvm::Value *DestPtrVal = EnforceType(B, DestPtr.getPointer(), PtrTy);
llvm::Value *SrcPtrVal = EnforceType(B, SrcPtr.getPointer(), PtrTy);
llvm::Value *DestPtrVal = EnforceType(B, DestPtr.emitRawPointer(CGF), PtrTy);
llvm::Value *SrcPtrVal = EnforceType(B, SrcPtr.emitRawPointer(CGF), PtrTy);

B.CreateCall(MemMoveFn, {DestPtrVal, SrcPtrVal, Size});
}
Expand Down
Loading