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.

Reply via email to