public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104693] New: Can't disable "comparison between pointer and integer"
@ 2022-02-25 17:50 charles.nicholson at gmail dot com
  2022-02-25 17:50 ` [Bug c/104693] " charles.nicholson at gmail dot com
  2022-02-26  8:51 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: charles.nicholson at gmail dot com @ 2022-02-25 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104693
           Summary: Can't disable "comparison between pointer and integer"
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: charles.nicholson at gmail dot com
  Target Milestone: ---

The following code causes gcc to emit a warning that does not seem to have a
diagnostic name, which makes it hard (impossible?) to disable:

=========================================
#include <stddef.h>
#include <stdbool.h>

bool foo(unsigned long not_a_pointer) {
  return not_a_pointer == NULL;
}
=========================================
<source>: In function 'foo':
<source>:5:24: warning: comparison between pointer and integer
    5 |   return not_a_pointer == NULL;
      |                        ^~
=========================================
Godbolt link: https://gcc.godbolt.org/z/chcxYevvf

I don't think anyone would argue that this is "good" (portable, defined, etc) C
code; it is vendor code that I'm stuck with. Additionally, on the architecture
I'm targeting, the implementation does the right thing: the unsigned long is
pointer-sized, and is compared against the NULL literal 0, which is used in
this context as a sentinel value. The code should use the literal 0 instead of
NULL, but it does not.

I have 3 suggestions, if they're helpful:

1. If this warning can be disabled, update the diagnostic message to include
the name as a hint on how to disable it.

2. If this warning can not be disabled, consider giving it a formal diagnostic
name and making it controllable via the standard methods (-Wno-, pragma, etc)

3. If this is truly heinous / unsafe enough, promote it to an error.

Thanks for all of your efforts on gcc!

Best,
Charles

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

* [Bug c/104693] Can't disable "comparison between pointer and integer"
  2022-02-25 17:50 [Bug c/104693] New: Can't disable "comparison between pointer and integer" charles.nicholson at gmail dot com
@ 2022-02-25 17:50 ` charles.nicholson at gmail dot com
  2022-02-26  8:51 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: charles.nicholson at gmail dot com @ 2022-02-25 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Charles Nicholson <charles.nicholson at gmail dot com> ---
Oh, also, this warning appears to go all the way back to gcc 4.1.2, the
earliest that godbolt still supports.

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

* [Bug c/104693] Can't disable "comparison between pointer and integer"
  2022-02-25 17:50 [Bug c/104693] New: Can't disable "comparison between pointer and integer" charles.nicholson at gmail dot com
  2022-02-25 17:50 ` [Bug c/104693] " charles.nicholson at gmail dot com
@ 2022-02-26  8:51 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-26  8:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor
   Last reconfirmed|                            |2022-02-26
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, the C++ front-end can turn off this warning with -Wno-pointer-arith
so I don't see why the C front-end could be made to do the same.

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

end of thread, other threads:[~2022-02-26  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 17:50 [Bug c/104693] New: Can't disable "comparison between pointer and integer" charles.nicholson at gmail dot com
2022-02-25 17:50 ` [Bug c/104693] " charles.nicholson at gmail dot com
2022-02-26  8:51 ` pinskia 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).