[llvm-commits] [PATCH] Skip NULL pointer check for free

Dmitri Gribenko gribozavr at gmail.com
Fri Dec 21 15:59:40 PST 2012


On Sat, Dec 22, 2012 at 1:53 AM, Nick Lewycky <nicholas at mxc.ca> wrote:
> On 12/21/2012 03:43 PM, Quentin Colombet wrote:
>>
>> Hi,
>>
>> Here is a patch to help llvm turning a code like this:
>> if (foo)
>> free(foo)
>>
>> into that:
>> free(foo)
>>
>> It is legal and safe, since free is already checking its argument
>> against NULL internally (I may find the reference in the Standard if
>> needed :)).
>
> It's legal and safe, but is it desirable? Calling a function is expensive
> even if the function doesn't do anything.

That's true, but there's another viewpoint: programmers usually write
'if(!foo) free(foo);' not because they are manually inlining the fast
path of free(), but because they think that free(NULL) is UB.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the llvm-commits mailing list