Author: Nikita Popov Date: 2021-07-08T20:38:54+02:00 New Revision: 693251fb2f001ac06591ae7d1254be265d36c9c7
URL: https://github.com/llvm/llvm-project/commit/693251fb2f001ac06591ae7d1254be265d36c9c7 DIFF: https://github.com/llvm/llvm-project/commit/693251fb2f001ac06591ae7d1254be265d36c9c7.diff LOG: [CodeGen] Avoid CreateGEP with nullptr type (NFC) In preparation for dropping support for it. I've replaced it with a proper type where the correct type was obvious and left an explicit getPointerElementType() where it wasn't. Added: Modified: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGObjCGNU.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 4ff6c632b61df..814464926797e 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1012,8 +1012,8 @@ static void forConstantArrayExpansion(CodeGenFunction &CGF, BaseAddr.getAlignment().alignmentOfArrayElement(EltSize); for (int i = 0, n = CAE->NumElts; i < n; i++) { - llvm::Value *EltAddr = - CGF.Builder.CreateConstGEP2_32(nullptr, BaseAddr.getPointer(), 0, i); + llvm::Value *EltAddr = CGF.Builder.CreateConstGEP2_32( + BaseAddr.getElementType(), BaseAddr.getPointer(), 0, i); Fn(Address(EltAddr, EltAlign)); } } diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index a790841caa0b3..9e47dbf7bdf1e 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -739,9 +739,11 @@ class CGObjCGNUstep : public CGObjCGNU { /// Function to perform atomic copies of C++ objects with nontrivial copy /// constructors to Objective-C ivars. LazyRuntimeFunction CxxAtomicObjectSetFn; - /// Type of an slot structure pointer. This is returned by the various + /// Type of a slot structure pointer. This is returned by the various /// lookup functions. llvm::Type *SlotTy; + /// Type of a slot structure. + llvm::Type *SlotStructTy; public: llvm::Constant *GetEHType(QualType T) override; @@ -780,7 +782,7 @@ class CGObjCGNUstep : public CGObjCGNU { // Load the imp from the slot llvm::Value *imp = Builder.CreateAlignedLoad( - IMPTy, Builder.CreateStructGEP(nullptr, slot, 4), + IMPTy, Builder.CreateStructGEP(SlotStructTy, slot, 4), CGF.getPointerAlign()); // The lookup function may have changed the receiver, so make sure we use @@ -800,7 +802,7 @@ class CGObjCGNUstep : public CGObjCGNU { slot->setOnlyReadsMemory(); return Builder.CreateAlignedLoad( - IMPTy, Builder.CreateStructGEP(nullptr, slot, 4), + IMPTy, Builder.CreateStructGEP(SlotStructTy, slot, 4), CGF.getPointerAlign()); } @@ -811,8 +813,7 @@ class CGObjCGNUstep : public CGObjCGNU { CGObjCGNU(Mod, ABI, ProtocolABI, ClassABI) { const ObjCRuntime &R = CGM.getLangOpts().ObjCRuntime; - llvm::StructType *SlotStructTy = - llvm::StructType::get(PtrTy, PtrTy, PtrTy, IntTy, IMPTy); + SlotStructTy = llvm::StructType::get(PtrTy, PtrTy, PtrTy, IntTy, IMPTy); SlotTy = llvm::PointerType::getUnqual(SlotStructTy); // Slot_t objc_msg_lookup_sender(id *receiver, SEL selector, id sender); SlotLookupFn.init(&CGM, "objc_msg_lookup_sender", SlotTy, PtrToIdTy, diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 578b8a811817e..91480b0824a2b 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1084,7 +1084,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, unsigned Idx = CurFnInfo->getReturnInfo().getInAllocaFieldIndex(); llvm::Function::arg_iterator EI = CurFn->arg_end(); --EI; - llvm::Value *Addr = Builder.CreateStructGEP(nullptr, &*EI, Idx); + llvm::Value *Addr = Builder.CreateStructGEP( + EI->getType()->getPointerElementType(), &*EI, Idx); llvm::Type *Ty = cast<llvm::GetElementPtrInst>(Addr)->getResultElementType(); ReturnValuePointer = Address(Addr, getPointerAlign()); diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index cf277ca347e43..697feafc7369b 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1535,7 +1535,7 @@ llvm::Value *ItaniumCXXABI::EmitDynamicCastToVoid(CodeGenFunction &CGF, // Get the offset-to-top from the vtable. OffsetToTop = - CGF.Builder.CreateConstInBoundsGEP1_32(/*Type=*/nullptr, VTable, -2U); + CGF.Builder.CreateConstInBoundsGEP1_32(CGM.Int32Ty, VTable, -2U); OffsetToTop = CGF.Builder.CreateAlignedLoad( CGM.Int32Ty, OffsetToTop, CharUnits::fromQuantity(4), "offset.to.top"); } else { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits