[llvm] [SPIRV] Fix code quality issues. (PR #152005)
Marcos Maronas via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 07:57:44 PDT 2025
================
@@ -893,9 +893,11 @@ Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(
bool Change = false;
for (unsigned i = 0; i < U->getNumOperands(); ++i) {
Value *Op = U->getOperand(i);
- Type *OpTy = Op->getType();
- Type *Ty = OpTy;
+ Type *OpTy = nullptr;
+ Type *Ty = nullptr;
if (Op) {
+ OpTy = Op->getType();
+ Ty = OpTy;
----------------
maarquitos14 wrote:
The problem here, from the point of view of the tool, is that we're deref'ing `Op` just before checking if it is `nullptr`. The chain of thought of the tool is: if `Op` is nullptr-checked, it can be nullptr, so there's risk that you're deref'ing a nullptr. To be fair, it makes sense. `assert(OpTy)` wouldn't prevent the risk of deref'ing `Op` if it's nullptr. I also agree with your point of view, so I'd say we drop `if (Op) {`, and add `assert(Op && "Operands should not be null.");`. Does that work for you?
https://github.com/llvm/llvm-project/pull/152005
More information about the llvm-commits
mailing list