Skip to content

Commit

Permalink
[clang] Remove no-op ptr-to-ptr bitcasts (NFC)
Browse files Browse the repository at this point in the history
Opaque ptr cleanup effort (NFC)
  • Loading branch information
JOE1994 committed Nov 2, 2023
1 parent 957efa4 commit 5532d67
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGBlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
CGM.getLangOpts().getGC() == LangOptions::NonGC) {
descName = getBlockDescriptorName(blockInfo, CGM);
if (llvm::GlobalValue *desc = CGM.getModule().getNamedValue(descName))
return llvm::ConstantExpr::getBitCast(desc,
CGM.getBlockDescriptorType());
return desc;
}

// If there isn't an equivalent block descriptor global variable, create a new
Expand Down Expand Up @@ -242,7 +241,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
global->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
}

return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType());
return global;
}

/*
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(DestAS));
auto SrcAS = D.getType().getQualifiers().getAddressSpace();
if (DestAS == SrcAS)
Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy);
Argument = Addr.getPointer();
else
// FIXME: On addr space mismatch we are passing NULL. The generation
// of the global destructor function should be adjusted accordingly.
Expand Down Expand Up @@ -167,8 +167,7 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant *Addr, CharUnits Size) {

// Emit a call with the size in bytes of the object.
uint64_t Width = Size.getQuantity();
llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(Int64Ty, Width),
llvm::ConstantExpr::getBitCast(Addr, Int8PtrTy)};
llvm::Value *Args[2] = {llvm::ConstantInt::getSigned(Int64Ty, Width), Addr};
Builder.CreateCall(InvariantStart, Args);
}

Expand Down
11 changes: 2 additions & 9 deletions clang/lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1630,13 +1630,8 @@ namespace {
IndexValues[i] = llvm::ConstantInt::get(CGM.Int32Ty, Indices[i]);
}

// Form a GEP and then bitcast to the placeholder type so that the
// replacement will succeed.
llvm::Constant *location =
llvm::ConstantExpr::getInBoundsGetElementPtr(BaseValueTy,
Base, IndexValues);
location = llvm::ConstantExpr::getBitCast(location,
placeholder->getType());
llvm::Constant *location = llvm::ConstantExpr::getInBoundsGetElementPtr(
BaseValueTy, Base, IndexValues);

Locations.insert({placeholder, location});
}
Expand Down Expand Up @@ -2037,8 +2032,6 @@ ConstantLValue
ConstantLValueEmitter::VisitAddrLabelExpr(const AddrLabelExpr *E) {
assert(Emitter.CGF && "Invalid address of label expression outside function");
llvm::Constant *Ptr = Emitter.CGF->GetAddrOfLabel(E->getLabel());
Ptr = llvm::ConstantExpr::getBitCast(Ptr,
CGM.getTypes().ConvertType(E->getType()));
return Ptr;
}

Expand Down

0 comments on commit 5532d67

Please sign in to comment.