From patchwork Fri Oct 11 20:36:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 282932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B271D2C0330 for ; Sat, 12 Oct 2013 07:36:36 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=D5/JApCzNHQde+Y+ F8RW08Sc/JRkBwUTvisXTyRp7xHgYrei8hcPFFsufk0GdFPhZ1+fru98B+4KAwHo 5ooWJRPBcApVihGRql5RcpVIXO8hUrthXtZtn4o+ZXBxdRr0I+wyf1GnnBTgKiiP u9ot/0p518FYnuy0LDx980AJibs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=8tXg5QFDAqhuiC/VZOctN0 ggDFk=; b=dcRgwqfAyuPvlgx+fFPOGgcff5xbcNA6v0ZbTikawor2E20oPqgtW1 3e5HvFO9gVzUxBKE2hJ/CuJt7nbdMBzZliU8iVBdMtIURoNer25LTxEh8NpikImK SVtoBS3qvaQZXJXxQ3PTKHaTg3+zacdbovTf+RR5qRvL2afOYeO4M= Received: (qmail 21351 invoked by alias); 11 Oct 2013 20:36:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 21341 invoked by uid 89); 11 Oct 2013 20:36:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Fri, 11 Oct 2013 20:36:28 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 11 Oct 2013 22:36:24 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1VUjRh-0002JX-Kd; Fri, 11 Oct 2013 22:36:25 +0200 Date: Fri, 11 Oct 2013 22:36:25 +0200 (CEST) From: Marc Glisse To: DJ Delorie cc: gcc-patches@gcc.gnu.org Subject: Re: Apply attribute returns_nonnull in libiberty In-Reply-To: <201310111830.r9BIUDTR021438@greed.delorie.com> Message-ID: References: <201310111830.r9BIUDTR021438@greed.delorie.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 On Fri, 11 Oct 2013, DJ Delorie wrote: > Your patch changes the rule that the application can override > xmalloc() and get functions that return NULL... How about this more limited version? I'll see about following Jakub's advice to apply the attributes to the other functions only in gcc. 2013-10-11 Marc Glisse PR tree-optimization/58689 * ansidecl.h (ATTRIBUTE_RETURNS_NONNULL): New macro. * libiberty.h (basename, lbasename, dos_lbasename, unix_lbasename, concat_copy): Mark with attributes nonnull(1) and returns_nonnull. (concat_copy2, xstrerror): Mark with attribute returns_nonnull. Index: ansidecl.h =================================================================== --- ansidecl.h (revision 203451) +++ ansidecl.h (working copy) @@ -304,20 +304,29 @@ So instead we use the macro below and te /* Attribute `nonnull' was valid as of gcc 3.3. */ #ifndef ATTRIBUTE_NONNULL # if (GCC_VERSION >= 3003) # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) # else # define ATTRIBUTE_NONNULL(m) # endif /* GNUC >= 3.3 */ #endif /* ATTRIBUTE_NONNULL */ +/* Attribute `returns_nonnull' was valid as of gcc 4.9. */ +#ifndef ATTRIBUTE_RETURNS_NONNULL +# if (GCC_VERSION >= 4009) +# define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__)) +# else +# define ATTRIBUTE_RETURNS_NONNULL +# endif /* GNUC >= 4.9 */ +#endif /* ATTRIBUTE_RETURNS_NONNULL */ + /* Attribute `pure' was valid as of gcc 3.0. */ #ifndef ATTRIBUTE_PURE # if (GCC_VERSION >= 3000) # define ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define ATTRIBUTE_PURE # endif /* GNUC >= 3.0 */ #endif /* ATTRIBUTE_PURE */ /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL. Index: libiberty.h =================================================================== --- libiberty.h (revision 203451) +++ libiberty.h (working copy) @@ -100,43 +100,43 @@ extern int countargv (char**); across different systems, sometimes as "char *" and sometimes as "const char *" */ /* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is undefined, we haven't run the autoconf check so provide the declaration without arguments. If it is 0, we checked and failed to find the declaration so provide a fully prototyped one. If it is 1, we found it so don't provide any declaration at all. */ #if !HAVE_DECL_BASENAME #if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME) -extern char *basename (const char *); +extern char *basename (const char *) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURNS_NONNULL; #else /* Do not allow basename to be used if there is no prototype seen. We either need to use the above prototype or have one from autoconf which would result in HAVE_DECL_BASENAME being set. */ #define basename basename_cannot_be_used_without_a_prototype #endif #endif /* A well-defined basename () that is always compiled in. */ -extern const char *lbasename (const char *); +extern const char *lbasename (const char *) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURNS_NONNULL; /* Same, but assumes DOS semantics (drive name, backslash is also a dir separator) regardless of host. */ -extern const char *dos_lbasename (const char *); +extern const char *dos_lbasename (const char *) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURNS_NONNULL; /* Same, but assumes Unix semantics (absolute paths always start with a slash, only forward slash is accepted as dir separator) regardless of host. */ -extern const char *unix_lbasename (const char *); +extern const char *unix_lbasename (const char *) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURNS_NONNULL; /* A well-defined realpath () that is always compiled in. */ extern char *lrealpath (const char *); /* Concatenate an arbitrary number of strings. You must pass NULL as the last argument of this function, to terminate the list of strings. Allocates memory using xmalloc. */ extern char *concat (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_SENTINEL; @@ -154,28 +154,28 @@ extern char *reconcat (char *, const cha strings. You must pass NULL as the last argument of this function, to terminate the list of strings. */ extern unsigned long concat_length (const char *, ...) ATTRIBUTE_SENTINEL; /* Concatenate an arbitrary number of strings into a SUPPLIED area of memory. You must pass NULL as the last argument of this function, to terminate the list of strings. The supplied memory is assumed to be large enough. */ -extern char *concat_copy (char *, const char *, ...) ATTRIBUTE_SENTINEL; +extern char *concat_copy (char *, const char *, ...) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_SENTINEL; /* Concatenate an arbitrary number of strings into a GLOBAL area of memory. You must pass NULL as the last argument of this function, to terminate the list of strings. The supplied memory is assumed to be large enough. */ -extern char *concat_copy2 (const char *, ...) ATTRIBUTE_SENTINEL; +extern char *concat_copy2 (const char *, ...) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_SENTINEL; /* This is the global area used by concat_copy2. */ extern char *libiberty_concat_ptr; /* Concatenate an arbitrary number of strings. You must pass NULL as the last argument of this function, to terminate the list of strings. Allocates memory using alloca. The arguments are evaluated twice! */ #define ACONCAT(ACONCAT_PARAMS) \ @@ -249,21 +249,21 @@ extern int errno_max (void); "EINVAL"). */ extern const char *strerrno (int); /* Given the name of an errno value, return the value. */ extern int strtoerrno (const char *); /* ANSI's strerror(), but more robust. */ -extern char *xstrerror (int); +extern char *xstrerror (int) ATTRIBUTE_RETURNS_NONNULL; /* Return the maximum signal number for which strsignal will return a string. */ extern int signo_max (void); /* Return a signal message string for a signal number (e.g., strsignal (SIGHUP) returns something like "Hangup"). */ /* This is commented out as it can conflict with one in system headers. We still document its existence though. */