public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46181] New: Feature request: "free-like" attribute
@ 2010-10-26 10:17 m.j.thayer at googlemail dot com
  2010-10-26 18:29 ` [Bug middle-end/46181] attribute for marking things as undefined use after a function call pinskia at gcc dot gnu.org
  2020-10-27  1:28 ` msebor at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: m.j.thayer at googlemail dot com @ 2010-10-26 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Feature request: "free-like" attribute
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: m.j.thayer@googlemail.com


It would be nice for purposes of static error checking to be able to mark
functions as destructors for some resource.  Specifically, that a if a value is
passed from a variable to argument n of the function then it is no longer valid
after the call to the function.  Optionally with an "invalid" value that may be
assigned to the variable afterwards.

E.g.

int close(int fd) __attribute__(( free(1, -1) ));  /* Says that the value
passed to the first argument is invalid hereafter, and that the variable it
came from can be marked invalid by setting it to -1 */

So that the compiler can see that the following is bad:

int fd = open("filename", O_CREAT);
...
if (close(fd) < 0) { ... }
do_something_with(fd);

but the following might be alright:

int fd = open("filename", O_CREAT);
...
if (close(fd) < 0) { ... }
fd = -1;
do_something_with(fd);

It might also make sense to be able to tag a typedef as a resource type with
information about a free-like function and an invalid value:

typedef int myfile __attribute(( resource(close, -1) ));


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

* [Bug middle-end/46181] attribute for marking things as undefined use after a function call
  2010-10-26 10:17 [Bug c/46181] New: Feature request: "free-like" attribute m.j.thayer at googlemail dot com
@ 2010-10-26 18:29 ` pinskia at gcc dot gnu.org
  2020-10-27  1:28 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2010-10-26 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2010.10.26 18:29:33
          Component|c                           |middle-end
            Summary|Feature request:            |attribute for marking
                   |"free-like" attribute       |things as undefined use
                   |                            |after a function call
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-10-26 18:29:33 UTC ---
Confirmed.


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

* [Bug middle-end/46181] attribute for marking things as undefined use after a function call
  2010-10-26 10:17 [Bug c/46181] New: Feature request: "free-like" attribute m.j.thayer at googlemail dot com
  2010-10-26 18:29 ` [Bug middle-end/46181] attribute for marking things as undefined use after a function call pinskia at gcc dot gnu.org
@ 2020-10-27  1:28 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-10-27  1:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46181

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
                 CC|                            |msebor at gcc dot gnu.org
             Status|NEW                         |RESOLVED
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=94527

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Pr94527 requests a subset of this functionality but there's enough discussion
to resolve this as a duplicate.

*** This bug has been marked as a duplicate of bug 94527 ***

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

end of thread, other threads:[~2020-10-27  1:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-26 10:17 [Bug c/46181] New: Feature request: "free-like" attribute m.j.thayer at googlemail dot com
2010-10-26 18:29 ` [Bug middle-end/46181] attribute for marking things as undefined use after a function call pinskia at gcc dot gnu.org
2020-10-27  1:28 ` msebor 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).