free(nullptr) does not violate the nofree specification
authorPhilip Reames <listmail@philipreames.com>
Tue, 20 Apr 2021 16:06:28 +0000 (09:06 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 20 Apr 2021 16:08:05 +0000 (09:08 -0700)
commit3b1474cab26b27c4d71a2c21cb45a62eefdacb6a
tree994bac5e58343b2550e2ab5199afd6c82d93351f
parent4cd6ca102a94e1b64ba3f940cc26b4d7b2b82964
free(nullptr) does not violate the nofree specification

This fixes a subtle and nasty bug in my 86664638. The problem is that free(nullptr) is well defined (and common).

The specification for the nofree attributes talks about memory objects, and doesn't explicitly address null, but I think it's reasonable to assume that nofree doesn't disallow a call to free(nullptr). If it did, we'd have to prove nonnull on an argument to ever infer nofree which doesn't seem to be the intent.

This was found by Nuno and Alive2 over in https://reviews.llvm.org/D100141#2697374.

Differential Revision: https://reviews.llvm.org/D100779
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/malloc-free-delete.ll