diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 0d2e74267e46c..f02938cf799ac 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -1014,8 +1014,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { if (CGM.getTriple().isOSBinFormatCOFF()) { cast(isa)->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); } - } else if (isa->getType() != PtrToIdTy) - isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy); + } // struct // { @@ -1108,10 +1107,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { std::pair v{ObjCStrGV, 0}; EarlyInitList.emplace_back(Sym, v); } - llvm::Constant *ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStrGV, IdTy); - ObjCStrings[Str] = ObjCStr; - ConstantStrings.push_back(ObjCStr); - return ConstantAddress(ObjCStr, IdElemTy, Align); + ObjCStrings[Str] = ObjCStrGV; + ConstantStrings.push_back(ObjCStrGV); + return ConstantAddress(ObjCStrGV, IdElemTy, Align); } void PushProperty(ConstantArrayBuilder &PropertiesArray, @@ -1193,9 +1191,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { ReferencedProtocols.end()); SmallVector Protocols; for (const auto *PI : RuntimeProtocols) - Protocols.push_back( - llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI), - ProtocolPtrTy)); + Protocols.push_back(GenerateProtocolRef(PI)); return GenerateProtocolList(Protocols); } @@ -1305,7 +1301,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { llvm::GlobalValue::ExternalLinkage, nullptr, Name); GV->setAlignment(CGM.getPointerAlign().getAsAlign()); } - return llvm::ConstantExpr::getBitCast(GV, ProtocolPtrTy); + return GV; } /// Existing protocol references. @@ -1322,9 +1318,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { std::string RefName = SymbolForProtocolRef(Name); assert(!TheModule.getGlobalVariable(RefName)); // Emit a reference symbol. - auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy, - false, llvm::GlobalValue::LinkOnceODRLinkage, - llvm::ConstantExpr::getBitCast(Protocol, ProtocolPtrTy), RefName); + auto GV = new llvm::GlobalVariable(TheModule, ProtocolPtrTy, false, + llvm::GlobalValue::LinkOnceODRLinkage, + Protocol, RefName); GV->setComdat(TheModule.getOrInsertComdat(RefName)); GV->setSection(sectionName()); GV->setAlignment(CGM.getPointerAlign().getAsAlign()); @@ -1381,9 +1377,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { auto RuntimeProtocols = GetRuntimeProtocolList(PD->protocol_begin(), PD->protocol_end()); for (const auto *PI : RuntimeProtocols) - Protocols.push_back( - llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI), - ProtocolPtrTy)); + Protocols.push_back(GenerateProtocolRef(PI)); llvm::Constant *ProtocolList = GenerateProtocolList(Protocols); // Collect information about methods @@ -1420,8 +1414,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { GV->setSection(sectionName()); GV->setComdat(TheModule.getOrInsertComdat(SymName)); if (OldGV) { - OldGV->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GV, - OldGV->getType())); + OldGV->replaceAllUsesWith(GV); OldGV->removeFromParent(); GV->setName(SymName); } @@ -2493,10 +2486,9 @@ ConstantAddress CGObjCGNU::GenerateConstantString(const StringLiteral *SL) { llvm::Constant *isa = TheModule.getNamedGlobal(Sym); if (!isa) - isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */false, - llvm::GlobalValue::ExternalWeakLinkage, nullptr, Sym); - else if (isa->getType() != PtrToIdTy) - isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy); + isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */ false, + llvm::GlobalValue::ExternalWeakLinkage, + nullptr, Sym); ConstantInitBuilder Builder(CGM); auto Fields = Builder.beginStruct();