public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33925] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
@ 2012-04-18 16:34 ` manu at gcc dot gnu.org
  2012-04-18 17:04 ` redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-18 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Target|i686-pc-linux-gnu           |
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-04-18
               Host|i686-pc-linux-gnu           |
     Ever Confirmed|0                           |1
              Build|i686-pc-linux-gnu           |

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-18 16:32:46 UTC ---
OK, but I don't think anyone is going to step up soon to implement this, so
feel free to give it a try yourself.


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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
  2012-04-18 16:34 ` [Bug c++/33925] gcc -Waddress lost some useful warnings manu at gcc dot gnu.org
@ 2012-04-18 17:04 ` redi at gcc dot gnu.org
  2012-04-18 17:07 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-18 17:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-18 17:01:23 UTC ---
(In reply to comment #3)
> First, I think the C++ standard forbids a function from having a null 
> address:

But GCC extensions allow it, see the weakref attribute:

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bweakref_007d-attribute-2648

That's used (among other places) by GCC's pthreads abstraction layer to declare
a weak alias to pthread_create, which has a null address unless libpthread is
linked to.  Testing whether the address is null (i.. whether the application
was linked to libpthread) is used for important optimisations.


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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
  2012-04-18 16:34 ` [Bug c++/33925] gcc -Waddress lost some useful warnings manu at gcc dot gnu.org
  2012-04-18 17:04 ` redi at gcc dot gnu.org
@ 2012-04-18 17:07 ` redi at gcc dot gnu.org
  2012-04-20 12:59 ` manu at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-18 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-04-18 17:04:25 UTC ---
... That's not an argument against improving the warning though.  GCC's uses
occur in system headers so warnings are suppressed, and could be worked around
anyway with further extensions such as #pragma GCC diagnostic


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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2012-04-18 17:07 ` redi at gcc dot gnu.org
@ 2012-04-20 12:59 ` manu at gcc dot gnu.org
  2021-10-01 18:09 ` msebor at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu.org @ 2012-04-20 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-04-20 12:57:59 UTC ---
(In reply to comment #6)
> ... That's not an argument against improving the warning though.  GCC's uses
> occur in system headers so warnings are suppressed, and could be worked around
> anyway with further extensions such as #pragma GCC diagnostic

Or even better, only skip the warning for functions marked as weakref, which I
guess is a very small subset. I think a patch that did that would be accepted. 

Unfortunately, Michael, I don't think there is anyone with enough free time to
work on this, so if you submitted a patch, that would be great! Thanks.


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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2012-04-20 12:59 ` manu at gcc dot gnu.org
@ 2021-10-01 18:09 ` msebor at gcc dot gnu.org
  2021-10-04 19:20 ` [Bug c++/33925] [10/11/12 Regression] " msebor at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-01 18:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
                 CC|                            |msebor at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
With pr102103 resolved, let me handle this.

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

* [Bug c++/33925] [10/11/12 Regression] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2021-10-01 18:09 ` msebor at gcc dot gnu.org
@ 2021-10-04 19:20 ` msebor at gcc dot gnu.org
  2021-11-16 12:58 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-04 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
      Known to fail|                            |11.2.0, 12.0, 4.1.0
            Summary|gcc -Waddress lost some     |[10/11/12 Regression] gcc
                   |useful warnings             |-Waddress lost some useful
                   |                            |warnings

--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
As noted in comment 1, this is a regression.

Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-October/580899.html

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

* [Bug c++/33925] [10/11/12 Regression] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2021-10-04 19:20 ` [Bug c++/33925] [10/11/12 Regression] " msebor at gcc dot gnu.org
@ 2021-11-16 12:58 ` rguenth at gcc dot gnu.org
  2021-11-19 16:48 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-16 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
   Target Milestone|---                         |10.4

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

* [Bug c++/33925] [10/11/12 Regression] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2021-11-16 12:58 ` rguenth at gcc dot gnu.org
@ 2021-11-19 16:48 ` cvs-commit at gcc dot gnu.org
  2021-11-19 16:49 ` [Bug c++/33925] [10/11 " msebor at gcc dot gnu.org
  2022-01-26 17:46 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-19 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:16137fbb9256ef365dd498d39024eb33de1a4cd8

commit r12-5410-g16137fbb9256ef365dd498d39024eb33de1a4cd8
Author: Martin Sebor <msebor@redhat.com>
Date:   Fri Nov 19 09:44:31 2021 -0700

    Restore ancient -Waddress for weak symbols [PR33925].

    Resolves:
    PR c/33925 - gcc -Waddress lost some useful warnings
    PR c/102867 - -Waddress from macro expansion in readelf.c

    gcc/c-family/ChangeLog:

            PR c++/33925
            PR c/102867
            * c-common.c (decl_with_nonnull_addr_p): Call maybe_nonzero_address
            and improve handling tof defined symbols.

    gcc/c/ChangeLog:

            PR c++/33925
            PR c/102867
            * c-typeck.c (maybe_warn_for_null_address): Suppress warnings for
            code resulting from macro expansion.

    gcc/cp/ChangeLog:

            PR c++/33925
            PR c/102867
            * typeck.c (warn_for_null_address): Suppress warnings for code
            resulting from macro expansion.

    gcc/ChangeLog:

            PR c++/33925
            PR c/102867
            * doc/invoke.texi (-Waddress): Update.

    gcc/testsuite/ChangeLog:

            PR c++/33925
            PR c/102867
            * g++.dg/warn/Walways-true-2.C: Adjust to avoid a valid warning.
            * c-c++-common/Waddress-5.c: New test.
            * c-c++-common/Waddress-6.c: New test.
            * g++.dg/warn/Waddress-7.C: New test.
            * gcc.dg/Walways-true-2.c: Adjust to avoid a valid warning.
            * gcc.dg/weak/weak-3.c: Expect a warning.

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

* [Bug c++/33925] [10/11 Regression] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2021-11-19 16:48 ` cvs-commit at gcc dot gnu.org
@ 2021-11-19 16:49 ` msebor at gcc dot gnu.org
  2022-01-26 17:46 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-19 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |12.0
            Summary|[10/11/12 Regression] gcc   |[10/11 Regression] gcc
                   |-Waddress lost some useful  |-Waddress lost some useful
                   |warnings                    |warnings
      Known to fail|12.0                        |10.2.0

--- Comment #11 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in GCC 12.

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

* [Bug c++/33925] [10/11 Regression] gcc -Waddress lost some useful warnings
       [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2021-11-19 16:49 ` [Bug c++/33925] [10/11 " msebor at gcc dot gnu.org
@ 2022-01-26 17:46 ` msebor at gcc dot gnu.org
  9 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-26 17:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #12 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm not planning to backport the GCC 12 changes.

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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
  2007-10-27 17:17 [Bug c++/33925] New: " mec at google dot com
  2008-01-31  2:46 ` [Bug c++/33925] " manu at gcc dot gnu dot org
  2009-07-31 15:13 ` manu at gcc dot gnu dot org
@ 2009-07-31 16:04 ` mec at google dot com
  2 siblings, 0 replies; 13+ messages in thread
From: mec at google dot com @ 2009-07-31 16:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from mec at google dot com  2009-07-31 16:04 -------
Subject: Re:  gcc -Waddress lost some useful warnings

Yes, I think this is a bug, because the behavior of gcc doesn't match 
its documentation.

First, I think the C++ standard forbids a function from having a null 
address:

[conv.ptr] 4.10 -1- A null pointer constant is an integral constant 
expression (5.19) rvalue of integer type that evalutes to zero.  A null 
pointer constant can be converted to a pointer type; the result is the 
null pointer value of that type and is distinguishable from every other 
value of pointer to object or pointer to function type.

Even if you break this to allow for weak pointers to functions, the 
documentation for -Waddress says:

http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Warning-Options.html#Warning-Options

"Warn about suspicious uses of memory addresses.  These include the 
address of a function in a conditional expression such as void 
func(void); if (func) ... such uses typically indicate a programmer 
error: the address of a function always evaluates to true, so their use 
in a conditional usually indicate that the programmer forgot the 
parentheses in a function call ...".

This documentation repeats the claim that "the address of a function is 
always true".

More than that: "warnings are diagnostic messages that report 
constructions which are not inherently erroneous but which are risky or 
suggest there may have been an error".  By enabling -Waddress, I believe 
the user intends to report all instances of "if (func)" with the 
expectation that most of them are mistaken versions of "if (func())" or 
"if (func(some_parameters ...))".  If the user is building 
(non-standard) code where the addresses of some functions may be null 
and "if (func)" is likely the intended meaning, then they can decline to 
turn on -Waddress.  If such code is common, you may want to re-think the 
inclusion of -Waddress in -Wall.

As it is, -Waddress sometimes prints the message that it is documented 
to print, and sometimes does not.


-- 


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


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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
  2007-10-27 17:17 [Bug c++/33925] New: " mec at google dot com
  2008-01-31  2:46 ` [Bug c++/33925] " manu at gcc dot gnu dot org
@ 2009-07-31 15:13 ` manu at gcc dot gnu dot org
  2009-07-31 16:04 ` mec at google dot com
  2 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-07-31 15:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2009-07-31 15:13 -------
Is this really a bug or not?


-- 


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


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

* [Bug c++/33925] gcc -Waddress lost some useful warnings
  2007-10-27 17:17 [Bug c++/33925] New: " mec at google dot com
@ 2008-01-31  2:46 ` manu at gcc dot gnu dot org
  2009-07-31 15:13 ` manu at gcc dot gnu dot org
  2009-07-31 16:04 ` mec at google dot com
  2 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-01-31  2:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from manu at gcc dot gnu dot org  2008-01-31 01:32 -------
I am not sure if this is actually a bug, since I think functions with weak
linkage can actually have a null-address if they are not instantiated.
Nonetheless, a regression hunt identifies this patch as the cause:

r104103 | mmitchel | 2005-09-09 20:56:16 +0200 (Fri, 09 Sep 2005) | 15 lines

        PR c++/22252
        * decl.c (start_preparsed_function): Do not pay attention to
        #pragma interface for implicitly-defined methods.
        * decl2.c (cp_finish_file): Do not complain about uses of inline
        functions that have bodies, even if we decided not to emit the
        body in this translation unit.
        * semantics.c (note_decl_for_pch): Do not mess with linkage.
        (expand_or_defer_fn): Make inline, non-template functions COMDAT
        at this point.

        PR c++/22252
        * g++.dg/ext/interface1.C: New test.
        * g++.dg/ext/interface1.h: Likewise.
        * g++.dg/ext/interface1a.cc: Likewise.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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


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

end of thread, other threads:[~2022-01-26 17:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-33925-4@http.gcc.gnu.org/bugzilla/>
2012-04-18 16:34 ` [Bug c++/33925] gcc -Waddress lost some useful warnings manu at gcc dot gnu.org
2012-04-18 17:04 ` redi at gcc dot gnu.org
2012-04-18 17:07 ` redi at gcc dot gnu.org
2012-04-20 12:59 ` manu at gcc dot gnu.org
2021-10-01 18:09 ` msebor at gcc dot gnu.org
2021-10-04 19:20 ` [Bug c++/33925] [10/11/12 Regression] " msebor at gcc dot gnu.org
2021-11-16 12:58 ` rguenth at gcc dot gnu.org
2021-11-19 16:48 ` cvs-commit at gcc dot gnu.org
2021-11-19 16:49 ` [Bug c++/33925] [10/11 " msebor at gcc dot gnu.org
2022-01-26 17:46 ` msebor at gcc dot gnu.org
2007-10-27 17:17 [Bug c++/33925] New: " mec at google dot com
2008-01-31  2:46 ` [Bug c++/33925] " manu at gcc dot gnu dot org
2009-07-31 15:13 ` manu at gcc dot gnu dot org
2009-07-31 16:04 ` mec at google dot com

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).