This is the mail archive of the gcc@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: Redundant malloc in structure optimization? (testsuite/gcc.dg/struct/wo_prof_global_var.c)


>  Sure, a malloc call has side-effects, so a DCE pass cannot just remove it.
>  Only struct-reorg knows that it has replaced all side-effects with others.

Malloc only has side effects if the result is used.


For example, LLVM will transform


int main(int argc, char** argv){
  if(malloc(sizeof(int)) == NULL){ return 0; }
  else{ return 1; }
}

into return 1

There is a thread going on in the llvm mailing lists about this right
now, and so far all the text people can find in standards says this is
okay (though I think susv2/POSIX says differently).

Chris says:
"
LLVM should not (and does not, afaik) assume the malloc succeeds in
general.

If LLVM is able to eliminate all users of the malloc assuming the
malloc succeeded (as in this case), then it is safe to assume the malloc
returned success."




>
>  Richard.
>


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