public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58689] New: Enhance returns_nonnull
@ 2013-10-11 12:19 glisse at gcc dot gnu.org
  2013-10-11 16:50 ` [Bug tree-optimization/58689] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-11 12:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58689
           Summary: Enhance returns_nonnull
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: diagnostic, missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
        Depends on: 21856, 24825

For PR 20318, we added an attribute "returns_nonnull". For now, it is quite
basic and only used by fold-const and VRP to assert in callers that the return
value is != 0. However, there are many other things that could be done with it,
see this conversation for details:

http://gcc.gnu.org/ml/gcc-patches/2013-10/msg00498.html
http://gcc.gnu.org/ml/gcc-patches/2013-10/msg00501.html
http://gcc.gnu.org/ml/gcc-patches/2013-10/msg00509.html

This includes in particular:
1) warn if a returns_nonnull function returns null (both using static analysis
and runtime tests);
2) optimize the callee, back-propagating this non-null property and marking as
unreachable the paths that would return 0;
3) preserve the nonnull property when inlining the function (assert_expr?);
4) mark a number of gcc functions with this attribute.

A number of these changes could be shared with the nonnull attribute and
pointer dereferencing.


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

* [Bug tree-optimization/58689] Enhance returns_nonnull
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
@ 2013-10-11 16:50 ` jakub at gcc dot gnu.org
  2013-10-11 17:23 ` glisse at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-10-11 16:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, guess the warning could have many false positives.
Anyway, if you code for such warning, you could as well just assume the
attribute on the functions and if you set it before IPA, perhaps you could even
propagate it during IPA, then functions can make use of those.
Though, such implicit attributes unlike explicit ones could be used (or even
set) only if decl_binds_to_current_def_p (decl), otherwise you can very well
have
void *foo (void) { return "abc"; } in current CU and foo be preempted during
dynamic linking and the preempted foo could return NULL.


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

* [Bug tree-optimization/58689] Enhance returns_nonnull
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
  2013-10-11 16:50 ` [Bug tree-optimization/58689] " jakub at gcc dot gnu.org
@ 2013-10-11 17:23 ` glisse at gcc dot gnu.org
  2013-10-29 13:15 ` glisse at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-11 17:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> Well, guess the warning could have many false positives.

Not more than the other -Wsuggest-attribute= warnings, no? I don't see how it
could be wrong. Sure you may not want to add the attribute, but if gcc says the
return is non-0, it is.

> Anyway, if you code for such warning, you could as well just assume the
> attribute on the functions

Ah, ok, that's different from what I was suggesting, but potentially more
interesting.

> and if you set it before IPA, perhaps you could
> even propagate it during IPA, then functions can make use of those.

IPA is early I think? You need at least VRP1 to detect a non-0 return, and
possibly you would need to alternate between IPA and VRP to propagate through
functions.


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

* [Bug tree-optimization/58689] Enhance returns_nonnull
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
  2013-10-11 16:50 ` [Bug tree-optimization/58689] " jakub at gcc dot gnu.org
  2013-10-11 17:23 ` glisse at gcc dot gnu.org
@ 2013-10-29 13:15 ` glisse at gcc dot gnu.org
  2014-04-24 20:27 ` eduardo.abinader at openbossa dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-29 13:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
Author: glisse
Date: Tue Oct 29 13:15:48 2013
New Revision: 204159

URL: http://gcc.gnu.org/viewcvs?rev=204159&root=gcc&view=rev
Log:
2013-10-29  Marc Glisse  <marc.glisse@inria.fr>

    PR tree-optimization/58689
include/
    * 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, reconcat, concat_copy2, choose_temp_base, xstrerror,
    xmalloc, xrealloc, xcalloc, xstrdup, xstrndup, xmemdup, pex_init):
    Mark with attribute returns_nonnull.

libiberty/
    * concat.c: Remove note about xmalloc.

Modified:
    trunk/include/ChangeLog
    trunk/include/ansidecl.h
    trunk/include/libiberty.h
    trunk/libiberty/ChangeLog
    trunk/libiberty/concat.c


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

* [Bug tree-optimization/58689] Enhance returns_nonnull
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-10-29 13:15 ` glisse at gcc dot gnu.org
@ 2014-04-24 20:27 ` eduardo.abinader at openbossa dot org
  2014-04-24 20:47 ` glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: eduardo.abinader at openbossa dot org @ 2014-04-24 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

Eduardo Abinader <eduardo.abinader at openbossa dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eduardo.abinader@openbossa.
                   |                            |org

--- Comment #5 from Eduardo Abinader <eduardo.abinader at openbossa dot org> ---
This new macro ATTRIBUTE_RETURNS_NONNULL should work ok for gcc 4.8.2? I am
having problems including libiberty.h in ubuntu 14.04. 

/usr/include/libiberty/libiberty.h: In function ‘basename’:
/usr/include/libiberty/libiberty.h:110:38: error: expected declaration
specifiers before ‘ATTRIBUTE_RETURNS_NONNULL’
 extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL
ATTRIBUTE_NONNULL(1); 
  /usr/include/libiberty/libiberty.h:121:45: error: expected ‘=’, ‘,’, ‘;’,
‘asm’ or ‘__attribute__’ before ‘ATTRIBUTE_RETURNS_NONNULL’
 extern const char *lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL
ATTRIBUTE_NONNULL(1); 
                                             ^
/usr/include/libiberty/libiberty.h:126:49: error: expected ‘=’, ‘,’, ‘;’, ‘asm’
or ‘__attribute__’ before ‘ATTRIBUTE_RETURNS_NONNULL’
 extern const char *dos_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL
ATTRIBUTE_NONNULL(1);
                                                 ^
/usr/include/libiberty/libiberty.h:132:50: error: expected ‘=’, ‘,’, ‘;’, ‘asm’
or ‘__attribute__’ before ‘ATTRIBUTE_RETURNS_NONNULL’
 extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL
ATTRIBUTE_NONNULL(1);
...

they seem to face the same problem:
https://linuxmusicians.com/viewtopic.php?f=24&t=12307&start=15



Thanks.
>From gcc-bugs-return-449826-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Apr 24 20:44:48 2014
Return-Path: <gcc-bugs-return-449826-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 23029 invoked by alias); 24 Apr 2014 20:44:48 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 22987 invoked by uid 48); 24 Apr 2014 20:44:45 -0000
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/60957] [4.9/4.10 Regression] Bogus error: array subscript is above array bounds [-Werror=array-bounds]
Date: Thu, 24 Apr 2014 20:44:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pinskia at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: keywords bug_status everconfirmed
Message-ID: <bug-60957-4-Zn14vhEpOP@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60957-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60957-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-04/txt/msg01846.txt.bz2
Content-length: 1575

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`957

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|NEW                         |UNCONFIRMED
     Ever confirmed|1                           |0

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is not fully a bogus warning.  The warning is true if xxx._enabled is
false and bar returns something which is > 8.

Here is a shorter testcase:
extern bool foobar(const unsigned int);
extern void foo (void);
extern void bar2(bool *enabled, unsigned int old_width)
{
  static const unsigned int size_map[] = { 0, 1, 2, 0, 4, 0, 0, 0, 8};
  if(old_width > 8)
    if(*enabled)
      foo ();
  unsigned int size = size_map[old_width];
  if(size == 0)
    if(*enabled)
      foo ();
  if(foobar(size))
    foo ();
}

We are transforming the above into:
extern bool foobar(const unsigned int);
extern void foo (void);
extern void bar2(bool *enabled, unsigned int old_width)
{
  unsigned int size;
  static const unsigned int size_map[] = { 0, 1, 2, 0, 4, 0, 0, 0, 8};
  if(old_width > 8)
  {
    if(*enabled)
      foo ();
    else
      {
        size = size_map[old_width];
        goto t;
      }
  }
  size = size_map[old_width];
  if(size == 0)
    if(*enabled)
      foo ();
t:
  if(foobar(size))
    foo ();
}


Which is correct and we are warning about the access under the else statement.


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

* [Bug tree-optimization/58689] Enhance returns_nonnull
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-04-24 20:27 ` eduardo.abinader at openbossa dot org
@ 2014-04-24 20:47 ` glisse at gcc dot gnu.org
  2014-04-24 21:05 ` eduardo.abinader at openbossa dot org
  2024-06-18  6:21 ` [Bug tree-optimization/58689] [meta-bug] __attribute__((returns_nonnull)) enhancements sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-04-24 20:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Eduardo Abinader from comment #5)
> This new macro ATTRIBUTE_RETURNS_NONNULL should work ok for gcc 4.8.2?

Yes. Probably you are picking up a wrong ansidecl.h, maybe because it came with
old binutils and you are doing something strange.

> ubuntu 14.04. 

Please report a bug to Ubuntu instead. And you will need to give them a lot
more details so they can reproduce the issue...


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

* [Bug tree-optimization/58689] Enhance returns_nonnull
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-04-24 20:47 ` glisse at gcc dot gnu.org
@ 2014-04-24 21:05 ` eduardo.abinader at openbossa dot org
  2024-06-18  6:21 ` [Bug tree-optimization/58689] [meta-bug] __attribute__((returns_nonnull)) enhancements sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: eduardo.abinader at openbossa dot org @ 2014-04-24 21:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Eduardo Abinader <eduardo.abinader at openbossa dot org> ---
Thanks for the feedback.

I just realized that bfd.h is referring /usr/include/ansidecl.h and not
/usr/include/libiberty/ansidecl.h.

Changed this path in bfd.h and compiled ok. Don't know if that's an ubuntu
issue or binutils.


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

* [Bug tree-optimization/58689] [meta-bug] __attribute__((returns_nonnull)) enhancements
  2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-04-24 21:05 ` eduardo.abinader at openbossa dot org
@ 2024-06-18  6:21 ` sjames at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-18  6:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58689
Bug 58689 depends on bug 84203, which changed state.

Bug 84203 Summary: add -Wsuggest-attribute=returns_nonnull
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84203

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

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

end of thread, other threads:[~2024-06-18  6:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-11 12:19 [Bug tree-optimization/58689] New: Enhance returns_nonnull glisse at gcc dot gnu.org
2013-10-11 16:50 ` [Bug tree-optimization/58689] " jakub at gcc dot gnu.org
2013-10-11 17:23 ` glisse at gcc dot gnu.org
2013-10-29 13:15 ` glisse at gcc dot gnu.org
2014-04-24 20:27 ` eduardo.abinader at openbossa dot org
2014-04-24 20:47 ` glisse at gcc dot gnu.org
2014-04-24 21:05 ` eduardo.abinader at openbossa dot org
2024-06-18  6:21 ` [Bug tree-optimization/58689] [meta-bug] __attribute__((returns_nonnull)) enhancements sjames 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).