Bug in restricted pointers (C99)?
Jim Wilson
wilson@specifixinc.com
Tue Jun 8 19:00:00 GMT 2004
The Thodes wrote:
> GCC 3.3.1 on i686-pc-cygwin does not squawk if I try to pass the same
> address twice to a fn taking two restrict-qualified ptrs as args... (src,
> output follows)
This is a programmer bug, not a compiler bug. The ISO C99 standard says
that the behaviour of the program is undefined. There is no requirement
for the compiler to emit a diagnostic here. It is the programmer's
responsibility to use restrict correctly, and there is no requirement
for the compiler to do any checking of it.
In general, it is not possible for a compiler to determine when there
are problems with uses of the restrict keyword. Doing this would
require perfect interprocedural aliasing analysis, and that is difficult
to impossible. Thus the compiler is not required to emit any warnings,
even in obvious cases like this. If we did have perfect aliasing info,
then we wouldn't need the restrict keyword. The restrict keyword exists
as an optimization, because compilers can't determine this info themselves.
We could perhaps emit a warning in an obvious case like this as an
enhancement. We will never be able to warn for all incorrect uses though.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com
More information about the Gcc-bugs
mailing list