[Bug tree-optimization/95663] static_cast checks for null even when the pointer is dereferenced

law at redhat dot com gcc-bugzilla@gcc.gnu.org
Thu Jan 7 20:00:02 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95663

--- Comment #18 from Jeffrey A. Law <law at redhat dot com> ---
Jon, there's no way for the optimizers to improve the to_derived_bad case as
there's nothing in the IL after we leave the front-end that's useful.  In the
.original dump we have:

;; Function derived& to_derived_bad(base2*) (null)
;; enabled by -tree-original


return <retval> = b != 0B ? (struct derived &) b + 18446744073709551612 : 0;


There's just nothing the optimizers can do with that.  The front-end would have
to provide more information or remove the check itself (as is done for the
to_derived_good case which has this .original dump):

;; Function derived& to_derived_good(base2*) (null)
;; enabled by -tree-original


return <retval> = (struct derived &) NON_LVALUE_EXPR <b> +
18446744073709551612;


More information about the Gcc-bugs mailing list