G++ internal pointer cast NULL check inefficiency

Mike Stump mrs@wrs.com
Sun Jan 31 23:58:00 GMT 1999


> Date: Thu, 07 Jan 1999 18:11:00 -0500
> From: David Edelsohn <dje@watson.ibm.com>

> 	I think that one can assert nonnull unconditionally for the case I
> found.  One of the tests that guards the conversion is:

>           /* If EXPR is NULL, then we don't need to do any arithmetic
>              to convert it:

>                [conv.ptr]

>                The null pointer value is converted to the null pointer
>                value of the destination type.  */
>           && !integer_zerop (expr))

> so it seems the compiler already has ensured the originating pointer
> expression is non-null and therefore no need to re-test that assertion at
> runtime. 

No, this is wrong.  Think of the words always sometimes never...  If
integer_zerop is true, the value is always zero.  If it is false, we
know it is sometimes zero or never zero, but not which.

You must look to the caller of this function, its caller, or the one
just above that.

> 	* cvt.c (cp_convert_to_pointer): Do not re-test EXPR for NULL when
> 	building vbase path.

I think this patch is wrong.



More information about the Gcc mailing list