Hi, On Wed, 12 Jun 2019, Martin Sebor wrote:
> > Otherwise LGTM as the patch, but I'd like to hear from others whether > > it is kosher to add such a special case to the warn_unused_result > > attribute warning. And if the agreement is yes, I think it should be > > documented somewhere that alloca (0) will not warn even when the call > > has such an attribute (probably in the description of > > warn_unused_result attribute). > > I'm not very happy about adding another special case to alloca > (on top of not diagnosing zero allocation by -Walloc-zero). > There is no valid use case for the zero argument, whether or not > the return value is used. That's the thing, there _is_ a valid use case for supplying a zero argument and then the returned value should _not_ be used. There are alloca implementations that do something (freeing memory) when called with a zero size, so some (older) programs contain such calls. Warning on those calls for the unused results is exactly the wrong thing to do, if anything if the result is used we'd have to warn. (That's of course non-standard, but so is alloca itself) And just removing these calls isn't correct either except if it's ensured to not use an alloca implementation with that behaviour. (In fact I think our builtin_alloca implementation could benefit when we added that behaviour as well; it's a natural wish to be able to free memory that you allocated). Ciao, Michael.