public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types
@ 2022-08-05 12:39 jose.marchesi at oracle dot com
  2022-08-05 15:38 ` [Bug c/106537] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jose.marchesi at oracle dot com @ 2022-08-05 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106537
           Summary: GCC doesn't support
                    -W[no-]compare-distinct-pointer-types
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jose.marchesi at oracle dot com
  Target Milestone: ---

GCC emits pedwarns unconditionally when comparing pointers of different types,
for example:

  int xdp_context (struct xdp_md *xdp)
  {
    void *data = (void *)(long)xdp->data;
    __u32 *metadata = (void *)(long)xdp->data_meta;
    __u32 ret;

    if (metadata + 1 > data)
      return 0;
    return 1;
  }

  /home/jemarch/foo.c: In function ‘xdp_context’:
  /home/jemarch/foo.c:15:20: warning: comparison of distinct pointer types
lacks a cast
     15 |   if (metadata + 1 > data)
        |                    ^

LLVM supports an option -W[no-]compare-distinct-pointer-types that can be used
in order to enable or disable the emission of such warnings.  It is enabled by
default.

This option is used in the kernel source tree for some BPF programs.

I already got a patch for this.

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
@ 2022-08-05 15:38 ` pinskia at gcc dot gnu.org
  2022-08-05 15:51 ` jose.marchesi at oracle dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-05 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> This option is used in the kernel source tree for some BPF programs.

Why not fix the sources? Seems not hard to add a cast or two.

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
  2022-08-05 15:38 ` [Bug c/106537] " pinskia at gcc dot gnu.org
@ 2022-08-05 15:51 ` jose.marchesi at oracle dot com
  2022-08-06  0:18 ` egallager at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jose.marchesi at oracle dot com @ 2022-08-05 15:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jose E. Marchesi <jose.marchesi at oracle dot com> ---
(In reply to Andrew Pinski from comment #1)
> > This option is used in the kernel source tree for some BPF programs.
> 
> Why not fix the sources? Seems not hard to add a cast or two.

That's what I would recommend.  But since LLVM supports that switch it becomes
difficult to convince people to not use it in case they are already using it.

Sent a proposal patch in:
https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599393.html

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
  2022-08-05 15:38 ` [Bug c/106537] " pinskia at gcc dot gnu.org
  2022-08-05 15:51 ` jose.marchesi at oracle dot com
@ 2022-08-06  0:18 ` egallager at gcc dot gnu.org
  2023-08-17 15:36 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-08-06  0:18 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org
             Blocks|                            |44209

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
This is an example of bug 44209


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44209
[Bug 44209] [meta-bug] Some warnings are not linked to diagnostics options

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (2 preceding siblings ...)
  2022-08-06  0:18 ` egallager at gcc dot gnu.org
@ 2023-08-17 15:36 ` cvs-commit at gcc dot gnu.org
  2023-08-17 15:37 ` jemarch at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-17 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jose E. Marchesi <jemarch@gcc.gnu.org>:

https://gcc.gnu.org/g:e1f45bea2741c271efbc4c2f9dfad93cbcd644c0

commit r14-3291-ge1f45bea2741c271efbc4c2f9dfad93cbcd644c0
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Date:   Thu Aug 17 15:36:26 2023 +0200

    Add warning options -W[no-]compare-distinct-pointer-types

    GCC emits pedwarns unconditionally when comparing pointers of
    different types, for example:

      int xdp_context (struct xdp_md *xdp)
        {
            void *data = (void *)(long)xdp->data;
            __u32 *metadata = (void *)(long)xdp->data_meta;
            __u32 ret;

            if (metadata + 1 > data)
              return 0;
            return 1;
       }

      /home/jemarch/foo.c: In function âxdp_contextâ:
      /home/jemarch/foo.c:15:20: warning: comparison of distinct pointer types
lacks a cast
             15 |   if (metadata + 1 > data)
                     |                    ^

    LLVM supports an option -W[no-]compare-distinct-pointer-types that can
    be used in order to enable or disable the emission of such warnings.
    It is enabled by default.

    This patch adds the same options to GCC.

    Documentation and testsuite updated included.
    Regtested in x86_64-linu-gnu.
    No regressions observed.

    gcc/ChangeLog:

            PR c/106537
            * doc/invoke.texi (Option Summary): Mention
            -Wcompare-distinct-pointer-types under `Warning Options'.
            (Warning Options): Document -Wcompare-distinct-pointer-types.

    gcc/c-family/ChangeLog:

            PR c/106537
            * c.opt (Wcompare-distinct-pointer-types): New option.

    gcc/c/ChangeLog:

            PR c/106537
            * c-typeck.cc (build_binary_op): Warning on comparing distinct
            pointer types only when -Wcompare-distinct-pointer-types.

    gcc/testsuite/ChangeLog:

            PR c/106537
            * gcc.c-torture/compile/pr106537-1.c: New test.
            * gcc.c-torture/compile/pr106537-2.c: Likewise.
            * gcc.c-torture/compile/pr106537-3.c: Likewise.

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (3 preceding siblings ...)
  2023-08-17 15:36 ` cvs-commit at gcc dot gnu.org
@ 2023-08-17 15:37 ` jemarch at gcc dot gnu.org
  2023-08-19  0:13 ` egallager at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jemarch at gcc dot gnu.org @ 2023-08-17 15:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jose E. Marchesi <jemarch at gcc dot gnu.org> changed:

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

--- Comment #5 from Jose E. Marchesi <jemarch at gcc dot gnu.org> ---
Fixed in the commit above.

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (4 preceding siblings ...)
  2023-08-17 15:37 ` jemarch at gcc dot gnu.org
@ 2023-08-19  0:13 ` egallager at gcc dot gnu.org
  2023-08-24 13:29 ` dje at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: egallager at gcc dot gnu.org @ 2023-08-19  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Eric Gallager <egallager at gcc dot gnu.org> ---
Would it be possible to add a fix-it hint to this warning, too, while you're at
it?

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (5 preceding siblings ...)
  2023-08-19  0:13 ` egallager at gcc dot gnu.org
@ 2023-08-24 13:29 ` dje at gcc dot gnu.org
  2023-08-24 13:53 ` jemarch at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dje at gcc dot gnu.org @ 2023-08-24 13:29 UTC (permalink / raw)
  To: gcc-bugs

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

David Edelsohn <dje at gcc dot gnu.org> changed:

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

--- Comment #7 from David Edelsohn <dje at gcc dot gnu.org> ---
The new testcases in the testsuite for this PR are failing.  Is anyone working
on these new failures? Is this being tracked in this PR or a new PR for the
failures?

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (6 preceding siblings ...)
  2023-08-24 13:29 ` dje at gcc dot gnu.org
@ 2023-08-24 13:53 ` jemarch at gcc dot gnu.org
  2023-08-24 15:14 ` cvs-commit at gcc dot gnu.org
  2023-12-01  8:45 ` sjames at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jemarch at gcc dot gnu.org @ 2023-08-24 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jose E. Marchesi <jemarch at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2023-08-24
         Resolution|FIXED                       |---

--- Comment #8 from Jose E. Marchesi <jemarch at gcc dot gnu.org> ---
I am on it.

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (7 preceding siblings ...)
  2023-08-24 13:53 ` jemarch at gcc dot gnu.org
@ 2023-08-24 15:14 ` cvs-commit at gcc dot gnu.org
  2023-12-01  8:45 ` sjames at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-24 15:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jose E. Marchesi <jemarch@gcc.gnu.org>:

https://gcc.gnu.org/g:721f7e2c4e5eed645593258624dd91e6c39f3bd2

commit r14-3470-g721f7e2c4e5eed645593258624dd91e6c39f3bd2
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Date:   Thu Aug 24 17:10:52 2023 +0200

    Fix tests for PR 106537.

    This patch fixes the tests for PR 106537 (support for
    -W[no]-compare-distinct-pointer-types) which were expecting the
    warning when checking for equality/inequality of void pointers with
    non-function pointers.

    gcc/testsuite/ChangeLog:

            PR c/106537
            * gcc.c-torture/compile/pr106537-1.c: Comparing void pointers to
            non-function pointers is legit.
            * gcc.c-torture/compile/pr106537-2.c: Likewise.

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

* [Bug c/106537] GCC doesn't support -W[no-]compare-distinct-pointer-types
  2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
                   ` (8 preceding siblings ...)
  2023-08-24 15:14 ` cvs-commit at gcc dot gnu.org
@ 2023-12-01  8:45 ` sjames at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-12-01  8:45 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
           Assignee|unassigned at gcc dot gnu.org      |jemarch at gcc dot gnu.org
   Target Milestone|---                         |14.0
         Resolution|---                         |FIXED

--- Comment #10 from Sam James <sjames at gcc dot gnu.org> ---
Done for 14, I think?

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

end of thread, other threads:[~2023-12-01  8:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05 12:39 [Bug c/106537] New: GCC doesn't support -W[no-]compare-distinct-pointer-types jose.marchesi at oracle dot com
2022-08-05 15:38 ` [Bug c/106537] " pinskia at gcc dot gnu.org
2022-08-05 15:51 ` jose.marchesi at oracle dot com
2022-08-06  0:18 ` egallager at gcc dot gnu.org
2023-08-17 15:36 ` cvs-commit at gcc dot gnu.org
2023-08-17 15:37 ` jemarch at gcc dot gnu.org
2023-08-19  0:13 ` egallager at gcc dot gnu.org
2023-08-24 13:29 ` dje at gcc dot gnu.org
2023-08-24 13:53 ` jemarch at gcc dot gnu.org
2023-08-24 15:14 ` cvs-commit at gcc dot gnu.org
2023-12-01  8:45 ` 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).