(I assume this goes into the category 'web', I couldn't find one for
'documentation')...

The documentation for the 'nonnull' attribute (section 5.27) currently says:

"The compiler may also choose to make optimizations based on the knowledge that
certain function arguments will not be null".

This is somewhat misleading in that it doesn't quite convey the effects that
may result from incorrect use of nonnull, and in particular the fact that while
analysis and issuing of warnings on nonnull is performed by the front-end, use
of nonnull for code-generation is done by the back-end.  As a result there can
be cases where no warning is issued because the analysis required to reveal
this would have to be done by the back-end, but the back-end optimiser still
changes the code that it generates under the assumption that the pointer is
never null.

Obviously this can be excused by saying that it's the programmer's fault for
applying the attribute incorrectly, but if its primary use is as a code-
diagnosis tool then the programmers may not be aware of the sometimes drastic
code-generation side-effects.

To make developers aware of this issue it'd be useful to amend the docs to
append to the above sentence the additional text:

"Note that the use of 'nonnull' to generate warnings and to generate code are
performed by different passes of the compiler.  The optimiser may completely
remove sections of code (for example checks for a pointer being null) if it
encounters a parameter with the 'nonnull' attribute set.  This attribute should
therefore be used with care".


-- 
           Summary: Documentation for the 'nonnull' attribute is a bit
                    misleading
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: web
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pgut001 at cs dot auckland dot ac dot nz


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36166

Reply via email to