[CodeGen] Avoid some pointer element type accesses

This commit is contained in:
Nikita Popov 2021-12-15 14:10:27 +01:00
parent e7007b69d4
commit b9492ec649
4 changed files with 10 additions and 9 deletions

View File

@ -4648,13 +4648,13 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
//
// In other cases, we assert that the types match up (until pointers stop
// having pointee types).
llvm::Type *TypeFromVal;
if (Callee.isVirtual())
TypeFromVal = Callee.getVirtualFunctionType();
else
TypeFromVal =
Callee.getFunctionPointer()->getType()->getPointerElementType();
assert(IRFuncTy == TypeFromVal);
assert(IRFuncTy == Callee.getVirtualFunctionType());
else {
llvm::PointerType *PtrTy =
llvm::cast<llvm::PointerType>(Callee.getFunctionPointer()->getType());
assert(PtrTy->isOpaqueOrPointeeTypeMatches(IRFuncTy));
}
}
#endif

View File

@ -115,7 +115,8 @@ public:
AbstractInfo = abstractInfo;
assert(functionPtr && "configuring callee without function pointer");
assert(functionPtr->getType()->isPointerTy());
assert(functionPtr->getType()->getPointerElementType()->isFunctionTy());
assert(functionPtr->getType()->isOpaquePointerTy() ||
functionPtr->getType()->getPointerElementType()->isFunctionTy());
}
static CGCallee forBuiltin(unsigned builtinID,

View File

@ -1146,7 +1146,7 @@ Address CodeGenModule::createUnnamedGlobalFrom(const VarDecl &D,
CacheEntry->setAlignment(Align.getAsAlign());
}
return Address(CacheEntry, Align);
return Address(CacheEntry, CacheEntry->getValueType(), Align);
}
static Address createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM,

View File

@ -3697,7 +3697,7 @@ static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
idx, DbgInfo);
}
return Address(eltPtr, eltAlign);
return Address(eltPtr, CGF.ConvertTypeForMem(eltType), eltAlign);
}
LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,