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: memset zero bytes at NULL - isolate-erroneous-paths


On Mon, Nov 18, 2013 at 12:08:27PM +0100, Richard Biener wrote:
> I'd say that turning memset (0, '\0', 0) into a trap is bad from a QOI
> perspective.  Jeff, is there an easy way to avoid this?  Testcase:
> 
> void fn (void *addr, int a)
> {
>   if (a == 0)
>     addr = (void *)0;
>   __builtin_memset (addr, '\0', a);
> }
> 
> I wonder where in isolate-paths you check for builtins at all?  ah,
> it's probably from the nonnull attribute on memset.  Which also
> means that trying to catch this case reliably isn't going to work
> (you cannot prove the program has len == 0 in this case and
> conditionally not trapping would somewhat defeat the purpose
> of isolating this path)

Well, if some function has nonnull attribute on some argument, then that
argument shouldn't have NULL value even if some length argument is 0.
In the case of memset (and various other functions) C99 clearly says that
memset (NULL, 0, 0); is invalid, if there are some functions that have
a pointer, length argument pair and for length 0 pointer is allowed to be
NULL, then those functions shouldn't have nonnull attribute.

	Jakub


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