Skip to content

Commit 5532d67

Browse files
committed
[clang] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort (NFC)
1 parent 957efa4 commit 5532d67

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
164164
CGM.getLangOpts().getGC() == LangOptions::NonGC) {
165165
descName = getBlockDescriptorName(blockInfo, CGM);
166166
if (llvm::GlobalValue *desc = CGM.getModule().getNamedValue(descName))
167-
return llvm::ConstantExpr::getBitCast(desc,
168-
CGM.getBlockDescriptorType());
167+
return desc;
169168
}
170169

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

245-
return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType());
244+
return global;
246245
}
247246

248247
/*

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D,
126126
CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(DestAS));
127127
auto SrcAS = D.getType().getQualifiers().getAddressSpace();
128128
if (DestAS == SrcAS)
129-
Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy);
129+
Argument = Addr.getPointer();
130130
else
131131
// FIXME: On addr space mismatch we are passing NULL. The generation
132132
// of the global destructor function should be adjusted accordingly.
@@ -167,8 +167,7 @@ void CodeGenFunction::EmitInvariantStart(llvm::Constant *Addr, CharUnits Size) {
167167

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

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,13 +1630,8 @@ namespace {
16301630
IndexValues[i] = llvm::ConstantInt::get(CGM.Int32Ty, Indices[i]);
16311631
}
16321632

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

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

0 commit comments

Comments
 (0)