[LLVMdev] Dereferencing null pointers
Hal Finkel
hfinkel at anl.gov
Thu Dec 11 11:13:25 PST 2014
----- Original Message -----
> From: "Thomas F Raoux" <thomas.f.raoux at intel.com>
> To: llvmdev at cs.uiuc.edu
> Sent: Thursday, December 11, 2014 1:03:39 PM
> Subject: [LLVMdev] Dereferencing null pointers
>
> 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?
Correct, it is valid to have a null pointer dereference in address spaces 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?
But it does, no? it has && LI.getPointerAddressSpace() == 0
-Hal
>
>
>
> Cheers,
>
> Thomas
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
--
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory
More information about the llvm-dev
mailing list