This is the mail archive of the gcc-patches@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: [PATCH] __attribute__((nonnull))


On Sun, May 19, 2002 at 12:02:35PM +0100, Joseph S. Myers wrote:

 > You're reimplementing the recursion used for format functions, but without
 > the recursion into gettext/ngettext functions.  I think it would be
 > desirable for the general recursion used here to be shared.  (At least if
 > it isn't shared, the old comment in check_format_info_recurse about how it
 > might be needs to go.)

Hm.  Okay.  Should the nonnull code be moved into c-format.c, then?  Or
should c-format.c export the recursion mechanism?

I was hoping to keep the null check stuff completely separate from the
format check stuff -- it just seemed more clean to do so.  (I mean,
decoupling them is really the whole point...)

...anyway, in the mean time, I have updated the comment in c-format.c.

 > The documentation needs to make it clear: is this attribute just for
 > *warning*, or may the compiler assume that a nonconstant argument, where
 > there is a nonnull attribute, must not be null, and optimise on that
 > basis?

Ok, I have updated the documentation to say that the compiler issues
a warning when it encounters a null being passed in an argument marked
as non-null.

(I certainly think using this information for optimization purposes is
a fine thing to do, but I have not implemented that, obviously...)

 > The patch lacks testcases.

Test cases added.  Updated patch attached.

       * c-common.c (c_common_attribute_table): Add "nonnull" attribute.
       (handle_nonnull_attribute, check_function_nonnull, nonnull_check_p,
       check_function_nonnull_recurse, get_nonnull_operand): New functions.
       * c-common.h (check_function_arguments, check_function_nonnull): New
       prototypes.
       * c-format.c (check_format_info_recurse): Update comment.
       * c-typeck.c (build_function_call): Call check_function_arguments
       instead of check_function_format.
       (check_function_arguments): New function.
       * doc/extend.texi: Document "nonnull" attribute.
       * testsuite/gcc.dg/nonnull-1.c: New test.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

Attachment: nonnull-patch
Description: Text document


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