Skip to content

Commit 6a2f786

Browse files
jemarchAlexei Starovoitov
authored andcommitted
bpf: ignore expected GCC warning in test_global_func10.c
The BPF selftest global_func10 in progs/test_global_func10.c contains: struct Small { long x; }; struct Big { long x; long y; }; [...] __noinline int foo(const struct Big *big) { if (!big) return 0; return bpf_get_prandom_u32() < big->y; } [...] SEC("cgroup_skb/ingress") __failure __msg("invalid indirect access to stack") int global_func10(struct __sk_buff *skb) { const struct Small small = {.x = skb->len }; return foo((struct Big *)&small) ? 1 : 0; } GCC emits a "maybe uninitialized" warning for the code above, because it knows `foo' accesses `big->y'. Since the purpose of this selftest is to check that the verifier will fail on this sort of invalid memory access, this patch just silences the compiler warning. Tested in bpf-next master. No regressions. Signed-off-by: Jose E. Marchesi <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Yonghong Song <[email protected]> Cc: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7386898 commit 6a2f786

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/testing/selftests/bpf/progs/test_global_func10.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <bpf/bpf_helpers.h>
55
#include "bpf_misc.h"
66

7+
#if !defined(__clang__)
8+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
9+
#endif
10+
711
struct Small {
812
long x;
913
};

0 commit comments

Comments
 (0)