public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46936] New: turn __attribute__ ((nonnull (x))) into assert in debug mode
@ 2010-12-14 12:54 eike@sf-mail.de
  2013-10-23 13:47 ` [Bug c/46936] " neleai at seznam dot cz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eike@sf-mail.de @ 2010-12-14 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: turn __attribute__ ((nonnull (x))) into assert in
                    debug mode
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eike@sf-mail.de


I have this simple function to free a linked list:

void freeips(struct ips *p)
{
    while (p) {
        struct ips *thisip = p;

        p = thisip->next;
        free(thisip);
    }
}

I accidentially annotated this as __attribute__ ((nonnull (1))) and called it
with a NULL argument. This still worked as long as I was building with -g. Once
I build this in release mode it crashed (correctly). I would like to have some
sort of automatic assert once I annotate a function this way. So when I build
this function annotated and pass NULL I get a meaningful crash and I can debug
this. If I need to explicitely switch this on by a command line switch it's
fine for me.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/46936] turn __attribute__ ((nonnull (x))) into assert in debug mode
  2010-12-14 12:54 [Bug c/46936] New: turn __attribute__ ((nonnull (x))) into assert in debug mode eike@sf-mail.de
@ 2013-10-23 13:47 ` neleai at seznam dot cz
  2013-10-24  4:05 ` brooks at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: neleai at seznam dot cz @ 2013-10-23 13:47 UTC (permalink / raw)
  To: gcc-bugs

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

Ondrej Bilka <neleai at seznam dot cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |neleai at seznam dot cz

--- Comment #1 from Ondrej Bilka <neleai at seznam dot cz> ---
I put it here to avoid being marked as duplicate,

I also wanted propose nonnul checks but they should be enabled by
FORTIFY_SOURCE.

In glibc we played with idea of scanning headers for nonnull attribute and
automatically generate wrappers of these functions. Then by LD_PRELOADing these
enable extra checks if attribute is null. We realized that offloading this
functionality to gcc is better as it will cover everybody that annotates
prototypes with nonnull, checks when pointer is known nonnull can be avoided.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/46936] turn __attribute__ ((nonnull (x))) into assert in debug mode
  2010-12-14 12:54 [Bug c/46936] New: turn __attribute__ ((nonnull (x))) into assert in debug mode eike@sf-mail.de
  2013-10-23 13:47 ` [Bug c/46936] " neleai at seznam dot cz
@ 2013-10-24  4:05 ` brooks at gcc dot gnu.org
  2013-11-05 14:41 ` neleai at seznam dot cz
  2013-11-05 14:51 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: brooks at gcc dot gnu.org @ 2013-10-24  4:05 UTC (permalink / raw)
  To: gcc-bugs

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

Brooks Moses <brooks at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brooks at gcc dot gnu.org

--- Comment #2 from Brooks Moses <brooks at gcc dot gnu.org> ---
As per http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html, the
annotation on the example function there "causes the compiler to check that, in
calls to my_memcpy, arguments dest and src are non-null."  Is this a
documentation bug, or does the functionality that you're asking for already
exist?

(My guess is that this is a documentation bug.  If so, a patch to fix it may
call some attention to this feature request!)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/46936] turn __attribute__ ((nonnull (x))) into assert in debug mode
  2010-12-14 12:54 [Bug c/46936] New: turn __attribute__ ((nonnull (x))) into assert in debug mode eike@sf-mail.de
  2013-10-23 13:47 ` [Bug c/46936] " neleai at seznam dot cz
  2013-10-24  4:05 ` brooks at gcc dot gnu.org
@ 2013-11-05 14:41 ` neleai at seznam dot cz
  2013-11-05 14:51 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: neleai at seznam dot cz @ 2013-11-05 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ondrej Bilka <neleai at seznam dot cz> ---
> As per http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html, the
> annotation on the example function there "causes the compiler to check that, in > calls to my_memcpy, arguments dest and src are non-null."  Is this a 
> documentation bug, or does the functionality that you're asking for already exist?

Gcc does not check that. Also this is not documentation request but request to
add checks when _FORTIFY_SOURCE is defined.

This would also mostly solve following bug
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/46936] turn __attribute__ ((nonnull (x))) into assert in debug mode
  2010-12-14 12:54 [Bug c/46936] New: turn __attribute__ ((nonnull (x))) into assert in debug mode eike@sf-mail.de
                   ` (2 preceding siblings ...)
  2013-11-05 14:41 ` neleai at seznam dot cz
@ 2013-11-05 14:51 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-11-05 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
_FORTIFY_SOURCE is not a debug mode you put all kinds of extra checks into.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-05 14:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-14 12:54 [Bug c/46936] New: turn __attribute__ ((nonnull (x))) into assert in debug mode eike@sf-mail.de
2013-10-23 13:47 ` [Bug c/46936] " neleai at seznam dot cz
2013-10-24  4:05 ` brooks at gcc dot gnu.org
2013-11-05 14:41 ` neleai at seznam dot cz
2013-11-05 14:51 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).