This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR83648


On January 3, 2018 7:03:26 AM GMT+01:00, Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote:
>Hi,
>malloc_candidate_p() in ipa-pure-const misses detecting that a
>function is malloc-like if the  return value is result of PHI and one
>of the arguments of PHI is 0.
>For example:
>
>void g(unsigned n)
>{
>  return (n) ? __builtin_malloc (n) : 0;
>}
>
>The reason is that the following check:
>if (TREE_CODE (arg) != SSA_NAME)
>  DUMP_AND_RETURN ("phi arg is not SSA_NAME.")
>
>fails for arg with constant value 0 and malloc_candidate_p returns
>false.
>The patch simply skips the arg if it equals null_pointer_node.
>Does it look OK ?

Please use integer_zerop instead of a literal compare. I'm not sure how to handle targets where address zero is valid (flag_no_delete_null_pointer_chekcs) 

>One concern I have is that with the patch, malloc_candidate_p will
>return true if all the args to PHI are NULL:
>retval = PHI<0, 0>
>return retval
>
>However I expect that PHI with all 0 args would be constant folded to
>0 earlier, so this case shouldn't occur in practice ?

You may not rely on folding for correctness. 

>Bootstrapped+tested on x86_64-unknown-linux-gnu.
>Cross-testing on arm*-*-* and aarch64*-*-* in progress.
>
>Thanks,
>Prathamesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]