Skip to content

Commit 8d2e9bb

Browse files
yonghong-songNobody
authored andcommitted
selftests/bpf: fix clang compilation errors
llvm upstream patch ([1]) added to issue warning for code like void test() { int j = 0; for (int i = 0; i < 1000; i++) j++; return; } This triggered several errors in selftests/bpf build since compilation flag -Werror is used. ... test_lpm_map.c:212:15: error: variable 'n_matches' set but not used [-Werror,-Wunused-but-set-variable] size_t i, j, n_matches, n_matches_after_delete, n_nodes, n_lookups; ^ test_lpm_map.c:212:26: error: variable 'n_matches_after_delete' set but not used [-Werror,-Wunused-but-set-variable] size_t i, j, n_matches, n_matches_after_delete, n_nodes, n_lookups; ^ ... prog_tests/get_stack_raw_tp.c:32:15: error: variable 'cnt' set but not used [-Werror,-Wunused-but-set-variable] static __u64 cnt; ^ ... For test_lpm_map.c, 'n_matches'/'n_matches_after_delete' are changed to be volatile in order to silent the warning. I didn't remove these two declarations since they are referenced in a commented code which might be used by people in certain cases. For get_stack_raw_tp.c, the variable 'cnt' is removed. [1] https://reviews.llvm.org/D122271 Signed-off-by: Yonghong Song <yhs@fb.com>
1 parent 8286418 commit 8d2e9bb

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ static void get_stack_print_output(void *ctx, int cpu, void *data, __u32 size)
2929
*/
3030
struct get_stack_trace_t e;
3131
int i, num_stack;
32-
static __u64 cnt;
3332
struct ksym *ks;
3433

35-
cnt++;
36-
3734
memset(&e, 0, sizeof(e));
3835
memcpy(&e, data, size <= sizeof(e) ? size : sizeof(e));
3936

tools/testing/selftests/bpf/test_lpm_map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ static void test_lpm_order(void)
209209
static void test_lpm_map(int keysize)
210210
{
211211
LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
212-
size_t i, j, n_matches, n_matches_after_delete, n_nodes, n_lookups;
212+
volatile size_t n_matches, n_matches_after_delete;
213+
size_t i, j, n_nodes, n_lookups;
213214
struct tlpm_node *t, *list = NULL;
214215
struct bpf_lpm_trie_key *key;
215216
uint8_t *data, *value;

0 commit comments

Comments
 (0)