This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/21305] flag_delete_null_pointer_checks is target specific
- From: "schlie at comcast dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 May 2005 03:55:27 -0000
- Subject: [Bug middle-end/21305] flag_delete_null_pointer_checks is target specific
- References: <20050430204842.21305.roger@eyesopen.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From schlie at comcast dot net 2005-05-19 03:55 -------
(In reply to comment #0)
> The current -fdelete_null_pointer_checks implementation makes assumptions that
> the target processor will trap on reads or writes to address zero. Unfortunately,
> these assumptions are target (often operating system) specific.
> ...
> I propose we should add target macros, TARGET_NULL_POINTER_READABLE and
> TARGET_NULL_POINTER_WRITABLE and control the effects of the
> -fdelete_null_pointer_checks with that. The current situation is that
> these transformations are enabled automatically at -O2 without regard to
> the target environment.
Correct, and as coppied from PR21479:
> > "a null reference is undefined" => "may trap" => "will trap"
> > is simply wrong, and is not justifyable; such an optimization
> > is target specific, as it depends on "will trap" target semantics.
>
> Right. However, the logic here is simply "a null pointer dereference is
> undefined" => "if you still do it, your code may behave however gcc feels
> like", which is backed by the C standard. So this is invalid.
No, only the "null pointer dereference" itself is undefined. which means
that upon a null pointer reference any or no value may be returned.
Is says, implies, and grants no rights what so ever to an implementation,
to define that an arbitrary behavior will occure which may be subsequenlty
relied upon to occure unless the implementation inforces that behavior.
More specifically, unless GCC can warrent that a "null pointer dereference"
will trap will terminate program execution, it must preserve the semantics
of the remaining programs execution as defined by the standard, which
includes but not limited to preserving null-pointer comparision semantics,
as defined by the standard; as not to do so would be in violation of the same.
("If -O2 or greater, enable -fdelete-null-pointer-checks" can not be
unconditionally enabled without violating the semantics of the language.)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21305