On 2/9/21 3:11 PM, Jakub Jelinek wrote:
On Tue, Feb 09, 2021 at 03:00:20PM -0500, Jason Merrill wrote:
With -fno-delete-null-pointer-checks which is e.g. implied by
-fsanitize=undefined or default on some embedded targets, the middle-end
folder doesn't consider addresses of global VAR_DECLs to be non-NULL, as one
of them could have address 0.

Hmm, are these VAR_DECLs going into the symtab?  That seems undesirable.

They are not in the symtab from the C++ FE.  And we don't allow those VAR_DECLs 
or their
addresses to leak into the IL anyway.
But, they are TREE_STATIC because pretending they are automatic didn't
really work (e.g. address of automatic variables is not a constant expression).
The generic folding code uses maybe_nonzero_address predicate which
apprently creates a symtab entry for them but as nothing uses them they
won't be emitted.

Ah.

If we wanted to avoid that, we'd need to either add some generic VAR_DECL
bit for those vars or add a target hook that would return true for them and
then handle them in the middle-end.

I'm surprised that nonzero_address has such a limited set of things it will actually believe have non-zero addresses with -fno-delete-null-pointer-checks. But it seems that we should be able to arrange to satisfy

  if (definition && !DECL_EXTERNAL (decl)

since these "variables" are indeed defined within the current translation unit.

Jason

Reply via email to