Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: Fix pointer-to-int-cast warning in newer Clang #10522

Merged
merged 1 commit into from Mar 10, 2020

Conversation

pchaigno
Copy link
Member

@pchaigno pchaigno commented Mar 10, 2020

Latest Clang (9658d895 "[Sema] Adds the pointer-to-int-cast diagnostic") emits the following warning for our __fetch code:

In file included from bpf_lxc.c:18:
In file included from /home/paul/cilium/bpf/lib/maps.h:8:
In file included from /home/paul/cilium/bpf/lib/ipv6.h:9:
/home/paul/cilium/bpf/lib/dbg.h:155:13: error: cast to smaller integer type '__u32' (aka 'unsigned int') from '__u32 *' (aka 'unsigned int *') [-Werror,-Wpointer-to-int-cast]
                .source = EVENT_SOURCE,
                          ^~~~~~~~~~~~
bpf_lxc.c:12:22: note: expanded from macro 'EVENT_SOURCE'
#define EVENT_SOURCE LXC_ID
                     ^~~~~~
/home/paul/cilium/bpf/lxc_config.h:14:16: note: expanded from macro 'LXC_ID'
#define LXC_ID fetch_u32(LXC_ID)
               ^~~~~~~~~~~~~~~~~
/home/paul/cilium/bpf/lib/static_data.h:11:22: note: expanded from macro 'fetch_u32'
#define fetch_u32(x) __fetch(x)
                     ^~~~~~~~~~
/home/paul/cilium/bpf/include/bpf/ctx/../compiler.h:46:22: note: expanded from macro '__fetch'
# define __fetch(X)             (__u32)(&(X))
                                ^~~~~~~~~~~~~

Fix it by casting to __u64 first.


This change is Reviewable

Latest Clang (9658d895 "[Sema] Adds the pointer-to-int-cast diagnostic")
emits the following warning for our __fetch code:

    In file included from bpf_lxc.c:18:
    In file included from /home/paul/cilium/bpf/lib/maps.h:8:
    In file included from /home/paul/cilium/bpf/lib/ipv6.h:9:
    /home/paul/cilium/bpf/lib/dbg.h:155:13: error: cast to smaller integer type '__u32' (aka 'unsigned int') from '__u32 *' (aka 'unsigned int *') [-Werror,-Wpointer-to-int-cast]
                    .source = EVENT_SOURCE,
                              ^~~~~~~~~~~~
    bpf_lxc.c:12:22: note: expanded from macro 'EVENT_SOURCE'
    #define EVENT_SOURCE LXC_ID
                         ^~~~~~
    /home/paul/cilium/bpf/lxc_config.h:14:16: note: expanded from macro 'LXC_ID'
    #define LXC_ID fetch_u32(LXC_ID)
                   ^~~~~~~~~~~~~~~~~
    /home/paul/cilium/bpf/lib/static_data.h:11:22: note: expanded from macro 'fetch_u32'
    #define fetch_u32(x) __fetch(x)
                         ^~~~~~~~~~
    /home/paul/cilium/bpf/include/bpf/ctx/../compiler.h:46:22: note: expanded from macro '__fetch'
    # define __fetch(X)             (__u32)(&(X))
                                    ^~~~~~~~~~~~~
Fix it by casting to __u64 first.

Signed-off-by: Paul Chaignon <paul@cilium.io>
@pchaigno pchaigno added pending-review sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/misc This PR makes changes that have no direct user impact. labels Mar 10, 2020
@pchaigno pchaigno requested a review from a team March 10, 2020 08:13
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.8.0 Mar 10, 2020
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 45.624% when pulling 07ce43d on pr/pchaigno/fix-ptr-to-int-warning into 8ea7239 on master.

@brb
Copy link
Member

brb commented Mar 10, 2020

test-me-please

@joestringer joestringer merged commit e43c2ff into master Mar 10, 2020
1.8.0 automation moved this from In progress to Merged Mar 10, 2020
@joestringer joestringer deleted the pr/pchaigno/fix-ptr-to-int-warning branch March 10, 2020 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc This PR makes changes that have no direct user impact. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
No open projects
1.8.0
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

6 participants