Skip to content

Commit 0936a71

Browse files
committed
[clang][CGObjCGNU] Remove no-op ptr-to-ptr bitcasts (NFC)
Opaque ptr cleanup effort (NFC).
1 parent 796d48b commit 0936a71

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
10141014
if (CGM.getTriple().isOSBinFormatCOFF()) {
10151015
cast<llvm::GlobalValue>(isa)->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
10161016
}
1017-
} else if (isa->getType() != PtrToIdTy)
1018-
isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
1017+
}
10191018

10201019
// struct
10211020
// {
@@ -1108,10 +1107,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
11081107
std::pair<llvm::GlobalVariable*, int> v{ObjCStrGV, 0};
11091108
EarlyInitList.emplace_back(Sym, v);
11101109
}
1111-
llvm::Constant *ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStrGV, IdTy);
1112-
ObjCStrings[Str] = ObjCStr;
1113-
ConstantStrings.push_back(ObjCStr);
1114-
return ConstantAddress(ObjCStr, IdElemTy, Align);
1110+
ObjCStrings[Str] = ObjCStrGV;
1111+
ConstantStrings.push_back(ObjCStrGV);
1112+
return ConstantAddress(ObjCStrGV, IdElemTy, Align);
11151113
}
11161114

11171115
void PushProperty(ConstantArrayBuilder &PropertiesArray,
@@ -1193,9 +1191,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
11931191
ReferencedProtocols.end());
11941192
SmallVector<llvm::Constant *, 16> Protocols;
11951193
for (const auto *PI : RuntimeProtocols)
1196-
Protocols.push_back(
1197-
llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
1198-
ProtocolPtrTy));
1194+
Protocols.push_back(GenerateProtocolRef(PI));
11991195
return GenerateProtocolList(Protocols);
12001196
}
12011197

@@ -1305,7 +1301,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
13051301
llvm::GlobalValue::ExternalLinkage, nullptr, Name);
13061302
GV->setAlignment(CGM.getPointerAlign().getAsAlign());
13071303
}
1308-
return llvm::ConstantExpr::getBitCast(GV, ProtocolPtrTy);
1304+
return GV;
13091305
}
13101306

13111307
/// Existing protocol references.
@@ -1322,9 +1318,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
13221318
std::string RefName = SymbolForProtocolRef(Name);
13231319
assert(!TheModule.getGlobalVariable(RefName));
13241320
// Emit a reference symbol.
1325-
auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy,
1326-
false, llvm::GlobalValue::LinkOnceODRLinkage,
1327-
llvm::ConstantExpr::getBitCast(Protocol, ProtocolPtrTy), RefName);
1321+
auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy, false,
1322+
llvm::GlobalValue::LinkOnceODRLinkage,
1323+
Protocol, RefName);
13281324
GV->setComdat(TheModule.getOrInsertComdat(RefName));
13291325
GV->setSection(sectionName<ProtocolReferenceSection>());
13301326
GV->setAlignment(CGM.getPointerAlign().getAsAlign());
@@ -1381,9 +1377,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
13811377
auto RuntimeProtocols =
13821378
GetRuntimeProtocolList(PD->protocol_begin(), PD->protocol_end());
13831379
for (const auto *PI : RuntimeProtocols)
1384-
Protocols.push_back(
1385-
llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
1386-
ProtocolPtrTy));
1380+
Protocols.push_back(GenerateProtocolRef(PI));
13871381
llvm::Constant *ProtocolList = GenerateProtocolList(Protocols);
13881382

13891383
// Collect information about methods
@@ -1420,8 +1414,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
14201414
GV->setSection(sectionName<ProtocolSection>());
14211415
GV->setComdat(TheModule.getOrInsertComdat(SymName));
14221416
if (OldGV) {
1423-
OldGV->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GV,
1424-
OldGV->getType()));
1417+
OldGV->replaceAllUsesWith(GV);
14251418
OldGV->removeFromParent();
14261419
GV->setName(SymName);
14271420
}
@@ -2493,10 +2486,9 @@ ConstantAddress CGObjCGNU::GenerateConstantString(const StringLiteral *SL) {
24932486
llvm::Constant *isa = TheModule.getNamedGlobal(Sym);
24942487

24952488
if (!isa)
2496-
isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */false,
2497-
llvm::GlobalValue::ExternalWeakLinkage, nullptr, Sym);
2498-
else if (isa->getType() != PtrToIdTy)
2499-
isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
2489+
isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */ false,
2490+
llvm::GlobalValue::ExternalWeakLinkage,
2491+
nullptr, Sym);
25002492

25012493
ConstantInitBuilder Builder(CGM);
25022494
auto Fields = Builder.beginStruct();

0 commit comments

Comments
 (0)