Skip to content

Commit 14f2025

Browse files
committed
[clang][CGExpr] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort.
1 parent e9a48f9 commit 14f2025

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,7 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
450450
Address Object = createReferenceTemporary(*this, M, E);
451451
if (auto *Var = dyn_cast<llvm::GlobalVariable>(Object.getPointer())) {
452452
llvm::Type *Ty = ConvertTypeForMem(E->getType());
453-
Object = Address(llvm::ConstantExpr::getBitCast(
454-
Var, Ty->getPointerTo(Object.getAddressSpace())),
455-
Ty, Object.getAlignment());
453+
Object = Object.withElementType(Ty);
456454

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

26802674
llvm::Constant *V = CGM.GetAddrOfFunction(GD);
2681-
if (!FD->hasPrototype()) {
2682-
if (const FunctionProtoType *Proto =
2683-
FD->getType()->getAs<FunctionProtoType>()) {
2684-
// Ugly case: for a K&R-style definition, the type of the definition
2685-
// isn't the same as the type of a use. Correct for this with a
2686-
// bitcast.
2687-
QualType NoProtoType =
2688-
CGM.getContext().getFunctionNoProtoType(Proto->getReturnType());
2689-
NoProtoType = CGM.getContext().getPointerType(NoProtoType);
2690-
V = llvm::ConstantExpr::getBitCast(V,
2691-
CGM.getTypes().ConvertType(NoProtoType));
2692-
}
2693-
}
26942675
return V;
26952676
}
26962677

0 commit comments

Comments
 (0)