[LLVMdev] Dereferencing null pointers

Raoux, Thomas F thomas.f.raoux at intel.com
Thu Dec 11 11:03:39 PST 2014


Hi,

I would like to understand better the meaning of constant null pointer in LLVM IR.

Can the optimizer assume that dereferencing a null pointer is always unreachable? Or is it only the case for address space 0? Is it ok to have null pointer be a valid pointer for an address space other than 0?

In InstCombine pass in InstCombiner::visitLoadInst(LoadInst &LI) I see that we replace load of null pointer by unreachable only for address space 0. But there is also code doing the following transformation for all the address spaces:
      // load (select (cond, null, P)) -> load P
      if(isa<ConstantPointerNull>(SI->getOperand(1)) &&
          LI.getPointerAddressSpace() == 0) {
        LI.setOperand(0, SI->getOperand(2));
        return &LI;
      }

Is this a bug? Would the correct behavior be to check that the pointers' address space is 0?

Cheers,
Thomas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141211/caeab170/attachment.html>


More information about the llvm-dev mailing list