Skip to content

Commit

Permalink
[clang][opaque pointers] Fix up a bunch of "getType()->getElementType()"
Browse files Browse the repository at this point in the history
In contexts where we know an LLVM type is a pointer, there's generally
some simpler way to get the pointee type.
  • Loading branch information
efriedma-quic committed Apr 4, 2020
1 parent 3e5d671 commit 83fa811
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -1233,7 +1233,7 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,

if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy)) {
Src = EnterStructPointerForCoercedAccess(Src, SrcSTy, DstSize, CGF);
SrcTy = Src.getType()->getElementType();
SrcTy = Src.getElementType();
}

uint64_t SrcSize = CGF.CGM.getDataLayout().getTypeAllocSize(SrcTy);
Expand Down Expand Up @@ -1299,7 +1299,7 @@ static void CreateCoercedStore(llvm::Value *Src,
bool DstIsVolatile,
CodeGenFunction &CGF) {
llvm::Type *SrcTy = Src->getType();
llvm::Type *DstTy = Dst.getType()->getElementType();
llvm::Type *DstTy = Dst.getElementType();
if (SrcTy == DstTy) {
CGF.Builder.CreateStore(Src, Dst, DstIsVolatile);
return;
Expand All @@ -1309,7 +1309,7 @@ static void CreateCoercedStore(llvm::Value *Src,

if (llvm::StructType *DstSTy = dyn_cast<llvm::StructType>(DstTy)) {
Dst = EnterStructPointerForCoercedAccess(Dst, DstSTy, SrcSize, CGF);
DstTy = Dst.getType()->getElementType();
DstTy = Dst.getElementType();
}

llvm::PointerType *SrcPtrTy = llvm::dyn_cast<llvm::PointerType>(SrcTy);
Expand Down Expand Up @@ -4304,7 +4304,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
llvm::StructType *STy =
dyn_cast<llvm::StructType>(ArgInfo.getCoerceToType());
if (STy && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) {
llvm::Type *SrcTy = Src.getType()->getElementType();
llvm::Type *SrcTy = Src.getElementType();
uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDecl.cpp
Expand Up @@ -341,7 +341,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
// the global to match the initializer. (We have to do this
// because some types, like unions, can't be completely represented
// in the LLVM type system.)
if (GV->getType()->getElementType() != Init->getType()) {
if (GV->getValueType() != Init->getType()) {
llvm::GlobalVariable *OldGV = GV;

GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/CGObjCMac.cpp
Expand Up @@ -3634,7 +3634,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
// Check for a forward reference.
llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true);
if (GV) {
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
assert(GV->getValueType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type.");
values.finishAndSetAsInitializer(GV);
GV->setSection(Section);
Expand Down Expand Up @@ -3697,7 +3697,7 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID,
// Check for a forward reference.
llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true);
if (GV) {
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
assert(GV->getValueType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type.");
values.finishAndSetAsInitializer(GV);
} else {
Expand Down Expand Up @@ -3728,7 +3728,7 @@ llvm::Constant *CGObjCMac::EmitMetaClassRef(const ObjCInterfaceDecl *ID) {
llvm::GlobalValue::PrivateLinkage, nullptr,
Name);

assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
assert(GV->getValueType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type.");
return GV;
}
Expand All @@ -3742,7 +3742,7 @@ llvm::Value *CGObjCMac::EmitSuperClassRef(const ObjCInterfaceDecl *ID) {
llvm::GlobalValue::PrivateLinkage, nullptr,
Name);

assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
assert(GV->getValueType() == ObjCTypes.ClassTy &&
"Forward class metadata reference has incorrect type.");
return GV;
}
Expand Down
14 changes: 7 additions & 7 deletions clang/lib/CodeGen/CodeGenModule.cpp
Expand Up @@ -3176,7 +3176,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
}

if ((isa<llvm::Function>(Entry) || isa<llvm::GlobalAlias>(Entry)) &&
(Entry->getType()->getElementType() == Ty)) {
(Entry->getValueType() == Ty)) {
return Entry;
}

Expand Down Expand Up @@ -3225,7 +3225,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
}

llvm::Constant *BC = llvm::ConstantExpr::getBitCast(
F, Entry->getType()->getElementType()->getPointerTo());
F, Entry->getValueType()->getPointerTo());
addGlobalValReplacement(Entry, BC);
}

Expand Down Expand Up @@ -3284,7 +3284,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(

// Make sure the result is of the requested type.
if (!IsIncompleteFunction) {
assert(F->getType()->getElementType() == Ty);
assert(F->getFunctionType() == Ty);
return F;
}

Expand Down Expand Up @@ -3575,7 +3575,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
llvm::Constant *Init = emitter.tryEmitForInitializer(*InitDecl);
if (Init) {
auto *InitType = Init->getType();
if (GV->getType()->getElementType() != InitType) {
if (GV->getValueType() != InitType) {
// The type of the initializer does not match the definition.
// This happens when an initializer has a different type from
// the type of the global (because of padding at the end of a
Expand Down Expand Up @@ -3648,7 +3648,7 @@ llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable(

if (GV) {
// Check if the variable has the right type.
if (GV->getType()->getElementType() == Ty)
if (GV->getValueType() == Ty)
return GV;

// Because C++ name mangling, the only way we can end up with an already
Expand Down Expand Up @@ -3992,7 +3992,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
// "extern int x[];") and then a definition of a different type (e.g.
// "int x[10];"). This also happens when an initializer has a different type
// from the type of the global (this happens with unions).
if (!GV || GV->getType()->getElementType() != InitType ||
if (!GV || GV->getValueType() != InitType ||
GV->getType()->getAddressSpace() !=
getContext().getTargetAddressSpace(GetGlobalVarAddressSpace(D))) {

Expand Down Expand Up @@ -4472,7 +4472,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
llvm::FunctionType *Ty = getTypes().GetFunctionType(FI);

// Get or create the prototype for the function.
if (!GV || (GV->getType()->getElementType() != Ty))
if (!GV || (GV->getValueType() != Ty))
GV = cast<llvm::GlobalValue>(GetAddrOfFunction(GD, Ty, /*ForVTable=*/false,
/*DontDefer=*/true,
ForDefinition));
Expand Down

0 comments on commit 83fa811

Please sign in to comment.