Skip to content

Commit

Permalink
[clang][CGExpr] Remove no-op ptr-to-ptr bitcasts (NFC)
Browse files Browse the repository at this point in the history
Opaque ptr cleanup effort.
  • Loading branch information
JOE1994 committed Nov 2, 2023
1 parent e9a48f9 commit 14f2025
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
Address Object = createReferenceTemporary(*this, M, E);
if (auto *Var = dyn_cast<llvm::GlobalVariable>(Object.getPointer())) {
llvm::Type *Ty = ConvertTypeForMem(E->getType());
Object = Address(llvm::ConstantExpr::getBitCast(
Var, Ty->getPointerTo(Object.getAddressSpace())),
Ty, Object.getAlignment());
Object = Object.withElementType(Ty);

// createReferenceTemporary will promote the temporary to a global with a
// constant initializer if it can. It can only do this to a value of
Expand Down Expand Up @@ -508,11 +506,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
if (auto *Var = dyn_cast<llvm::GlobalVariable>(
Object.getPointer()->stripPointerCasts())) {
llvm::Type *TemporaryType = ConvertTypeForMem(E->getType());
Object = Address(llvm::ConstantExpr::getBitCast(
cast<llvm::Constant>(Object.getPointer()),
TemporaryType->getPointerTo()),
TemporaryType,
Object.getAlignment());
Object = Object.withElementType(TemporaryType);
// If the temporary is a global and has a constant initializer or is a
// constant temporary that we promoted to a global, we may have already
// initialized it.
Expand Down Expand Up @@ -2678,19 +2672,6 @@ static llvm::Constant *EmitFunctionDeclPointer(CodeGenModule &CGM,
}

llvm::Constant *V = CGM.GetAddrOfFunction(GD);
if (!FD->hasPrototype()) {
if (const FunctionProtoType *Proto =
FD->getType()->getAs<FunctionProtoType>()) {
// Ugly case: for a K&R-style definition, the type of the definition
// isn't the same as the type of a use. Correct for this with a
// bitcast.
QualType NoProtoType =
CGM.getContext().getFunctionNoProtoType(Proto->getReturnType());
NoProtoType = CGM.getContext().getPointerType(NoProtoType);
V = llvm::ConstantExpr::getBitCast(V,
CGM.getTypes().ConvertType(NoProtoType));
}
}
return V;
}

Expand Down

0 comments on commit 14f2025

Please sign in to comment.