[PATCH] Extend the `sentinel' attribute

Ludovic Courtès ludo@gnu.org
Thu Apr 17 16:31:00 GMT 2008


Hi,

Tom Tromey <tromey@redhat.com> writes:

> Ludovic> In addition, it would be nice to no limit sentinel values to
> Ludovic> pointer types but this would be an incompatible change.  What
> Ludovic> do you think?
>
> Is this a common pattern in real applications?

Not sure.  In Guile, the `SCM' type can be defined to be either a union,
a pointer, or an integer, although in practice it's defined to be a
pointer type by default (see `SCM_DEBUG_TYPING_STRICTNESS' in
"libguile/tags.h").  I don't have any other example at hand.

Yet, it feels better to not limit ourselves to pointer types, as long as
we don't need to break anything to achieve this (see below).

> Ludovic> PS: I have not (yet) assigned copyright to the FSF, but maybe
> Ludovic> the change is trivial enough that it's not necessary?
>
> No, sorry, I think it is over the limit.

OK, will do.

> It looks to me like this will do the wrong thing if there is a
> user-provided sentinel but -Wstrict-null-sentinel is passed.

Indeed, I had overlooked this.

Here's an updated patch, with test cases.  The first difference with the
previous patch is that it should interact well with
`-Wstrict-null-sentinel'.  The second one is that it now checks whether
the "pointerness" of the sentinel matches that of the expected value.
This allows both regular integers and pointer types to be used as
sentinels.  Opinions?

(Speaking of which, I'm not completely satisfied with the wording in the
documentation patch.)

Thanks,
Ludovic.

gcc/ChangeLog
2008-04-17  Ludovic Courtès  <ludo@gnu.org>

	PR28319
        * c-common.c (c_common_attribute_table)[sentinel]: Set max
        argument count to 2.
        (check_function_sentinel): Check SENTINEL against the
        user-provided value rather than against zero.  Check 
        SENTINEL's "pointerness" against that of the user-specified
        value instead of always expecting a pointer type.
        (handle_sentinel_attribute): Validate second optional argument.
        * doc/extend.texi (Function Attributes): Document `sentinel'
        change.

gcc/testsuite/ChangeLog
2008-04-17  Ludovic Courtès  <ludo@gnu.org>

	PR28319
        * gcc.dg/format/sentinel-1.c (foo10): Add third `sentinel'
        argument.
        (foo11, foo12, foo13, foo14, foo15): New declarations.
        (bar): Use them.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ,,sentinel-2.diff
Type: text/x-patch
Size: 8005 bytes
Desc: The patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080417/a73481e5/attachment.bin>


More information about the Gcc-patches mailing list