nullptr bit-value for DebugInfo in non-default address spaces

Hi llvm-dev@,

It recently transpired that LLVM doesn’t correctly preserve debugging information when null pointer constants are assigned to variables [0], with the debug records getting dropped by SelectionDAG. Fixing that [1] raises a few questions about the bit-value of null in different address spaces, so I’d like to ask:

  • Can we just assume that null is zero-valued for all address spaces?

  • If not, are there APIs available for determining an address spaces’ null-value?

What’s permissible / disallowed for address spaces is unclear to me. Various comments around the code base suggest that nullptr is always zero for address space zero; I’m not aware of rules for other address spaces. Without further information, the current solution is to have non-zero address space nulls marked as “optimized out”.

[0] https://bugs.llvm.org/show_bug.cgi?id=39787
[1] https://reviews.llvm.org/D55227

I’m pretty sure the null pointer for address space zero is necessarily zero - but off-hand don’t know if/where that’s specified, hopefully someone else can cchime in with that info.

If that’s the only guarantee (& there’s no guarantee on non-zero address space’s null pointer representation) is that sufficient to address some cases you’re dealing with, or is the address space not known at the point where you’re trying to make this decision? (ie: you could only use zero if you know all address spaces have zero null pointers)

  • Dave

Hi,

I suspect you would need to implement some new target hook that would report back the nullptr value for a given address space. The default implementation would return zero. AMDGPU (and possibly others) would implement the hook to return the appropriate value.

–paulr

It's not explicitly stated anywhere in LangRef, but in practice a ConstantPointerNull must have a zero bit-pattern in all address-spaces. Patch welcome if you want to modify LangRef.

Note that this might not match the C notion of a "null pointer"... LLVM optimizations for C library functions assume a ConstantPointerNull is in fact a null pointer in address-space zero, but otherwise it generally doesn't care. clang supports mapping a null pointer to other values.

-Eli