[llvm] [SPIR-V] Do not use OpenCL metadata for ptr element type resolution (PR #82678)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 10:32:57 PST 2024
================
@@ -567,22 +608,20 @@ void SPIRVEmitIntrinsics::processGlobalValue(GlobalVariable &GV) {
void SPIRVEmitIntrinsics::insertAssignPtrTypeIntrs(Instruction *I) {
reportFatalOnTokenType(I);
- if (I->getType()->isVoidTy() || !requireAssignPtrType(I))
+ if (!I->getType()->isPointerTy() || !requireAssignType(I) ||
+ isa<BitCastInst>(I))
return;
setInsertPointSkippingPhis(*IRB, I->getNextNode());
Constant *EltTyConst;
- unsigned AddressSpace = 0;
- if (auto *AI = dyn_cast<AllocaInst>(I)) {
+ unsigned AddressSpace = I->getType()->getPointerAddressSpace();
+ if (auto *AI = dyn_cast<AllocaInst>(I))
EltTyConst = UndefValue::get(AI->getAllocatedType());
- AddressSpace = AI->getAddressSpace();
- } else if (auto *GEP = dyn_cast<GetElementPtrInst>(I)) {
+ else if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
EltTyConst = UndefValue::get(GEP->getResultElementType());
- AddressSpace = GEP->getPointerAddressSpace();
- } else {
- llvm_unreachable("Unexpected instruction!");
- }
+ else if (I->getType()->isPointerTy())
+ EltTyConst = UndefValue::get(IntegerType::getInt8Ty(I->getContext()));
----------------
bogner wrote:
Dropping the else/llvm_unreachable case here results in a `-Wsometimes-uninitialized` warning. We probably want to add it back to get a reliable crash in debug builds rather than UB.
```
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp:623:12: error: variable 'EltTyConst' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
else if (I->getType()->isPointerTy())
^~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp:626:67: note: uninitialized use occurs here
buildIntrWithMD(Intrinsic::spv_assign_ptr_type, {I->getType()}, EltTyConst, I,
^~~~~~~~~~
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp:623:8: note: remove the 'if' if its condition is always true
else if (I->getType()->isPointerTy())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp:617:23: note: initialize the variable 'EltTyConst' to silence this warning
Constant *EltTyConst;
^
= nullptr
```
https://github.com/llvm/llvm-project/pull/82678
More information about the llvm-commits
mailing list