public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "david.faust at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/107846] error: result of '8000 << 8' requires 22 bits to represent, but 'short int' only has 16 bits
Date: Wed, 23 Nov 2022 18:26:22 +0000	[thread overview]
Message-ID: <bug-107846-4-0AuPnBa8t7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107846-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #1 from David Faust <david.faust at oracle dot com> ---
I think this is a bug in the test itself (or with these macros from libbpf).

libbpf/src/bpf_endian.h
#define ___bpf_mvb(x, b, n, m) ((__u##b)(x) << (b-(n+1)*8) >> (b-8) << (m*8))

#define ___bpf_swab16(x) ((__u16)(                      \
                          ___bpf_mvb(x, 16, 0, 1) |     \
                          ___bpf_mvb(x, 16, 1, 0)))

# define __bpf_constant_htons(x)        ___bpf_swab16(x)

In tools/testing/selftests/bpf/progs/test_tc_tunnel.c:

static const int cfg_port = 8000;
static const int cfg_udp_src = 20000;
...

then at e.g. line 276

        if (tcph.dest != __bpf_constant_htons(cfg_port))
                return TC_ACT_OK;

Expanding this __bpf_constant_htons macro:

__bpf_constant_htons (cfg_port)
__bpf_constant_htons (8000)
((__u16)(8000) << (16-(0+1)*8) >> (16-8) << (1*8)
((__u16)(8000) << (16-(1)*8) >> (8) << 8)
((__u16)(8000) << (8) >> 8 << 8
((__u16)(8000) << 8)

...which raises the shift-overflow warning.

  reply	other threads:[~2022-11-23 18:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 17:45 [Bug target/107846] New: " james.hilliard1 at gmail dot com
2022-11-23 18:26 ` david.faust at oracle dot com [this message]
2022-11-23 19:02 ` [Bug target/107846] " pinskia at gcc dot gnu.org
2022-11-23 19:09 ` [Bug c/107846] [13 Regression] " pinskia at gcc dot gnu.org
2022-11-23 19:12 ` pinskia at gcc dot gnu.org
2022-11-23 19:20 ` jakub at gcc dot gnu.org
2022-11-29 15:26 ` jakub at gcc dot gnu.org
2022-11-29 18:57 ` james.hilliard1 at gmail dot com
2022-11-29 18:59 ` jakub at gcc dot gnu.org
2022-11-29 19:00 ` pinskia at gcc dot gnu.org
2022-11-29 19:06 ` james.hilliard1 at gmail dot com
2023-03-04  9:15 ` cvs-commit at gcc dot gnu.org
2023-03-04  9:24 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107846-4-0AuPnBa8t7@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).