BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: David Vernet <void@manifault.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com
Subject: Re: [PATCH bpf-next] selftests/bpf: fix a few clang compilation errors
Date: Wed, 11 May 2022 15:10:32 -0700	[thread overview]
Message-ID: <a5f32630-85e3-f9c6-3afc-e6e862b9a820@fb.com> (raw)
In-Reply-To: <20220511190841.4oxswcsebp7teaa3@dev0025.ash9.facebook.com>



On 5/11/22 12:08 PM, David Vernet wrote:
> On Wed, May 11, 2022 at 11:47:35AM -0700, Yonghong Song wrote:
>> With latest clang, I got the following compilation errors:
>>    .../prog_tests/test_tunnel.c:291:6: error: variable 'local_ip_map_fd' is used uninitialized
>>       whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>>         if (attach_tc_prog(&tc_hook, -1, set_dst_prog_fd))
>>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>    .../bpf/prog_tests/test_tunnel.c:312:6: note: uninitialized use occurs here
>>          if (local_ip_map_fd >= 0)
>>              ^~~~~~~~~~~~~~~
>>    ...
>>    .../prog_tests/kprobe_multi_test.c:346:6: error: variable 'err' is used uninitialized
>>        whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
>>          if (IS_ERR(map))
>>              ^~~~~~~~~~~
>>    .../prog_tests/kprobe_multi_test.c:388:6: note: uninitialized use occurs here
>>          if (err) {
>>              ^~~
>>
>> This patch fixed the above compilation errors.
> 
> I'd argue that these are real bugs that the compiler happens to have
> caught, and that the patch should perhaps be framed as fixing them rather
> than as avoiding compilation failures, but that might be unnecessarily
> nit-picky and I don't feel strongly about it.
> 
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c | 4 +++-
>>   tools/testing/selftests/bpf/prog_tests/test_tunnel.c       | 4 ++--
>>   2 files changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
>> index 816eacededd1..586dc52d6fb9 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
>> @@ -343,8 +343,10 @@ static int get_syms(char ***symsp, size_t *cntp)
>>   		return -EINVAL;
>>   
>>   	map = hashmap__new(symbol_hash, symbol_equal, NULL);
>> -	if (IS_ERR(map))
>> +	if (IS_ERR(map)) {
>> +		err = libbpf_get_error(map);
>>   		goto error;
>> +	}
>>   
>>   	while (fgets(buf, sizeof(buf), f)) {
>>   		/* skip modules */
>> diff --git a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
>> index 071c9c91b50f..3bba4a2a0530 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
>> @@ -246,7 +246,7 @@ static void test_vxlan_tunnel(void)
>>   {
>>   	struct test_tunnel_kern *skel = NULL;
>>   	struct nstoken *nstoken;
>> -	int local_ip_map_fd;
>> +	int local_ip_map_fd = -1;
>>   	int set_src_prog_fd, get_src_prog_fd;
>>   	int set_dst_prog_fd;
>>   	int key = 0, ifindex = -1;
>> @@ -319,7 +319,7 @@ static void test_ip6vxlan_tunnel(void)
>>   {
>>   	struct test_tunnel_kern *skel = NULL;
>>   	struct nstoken *nstoken;
>> -	int local_ip_map_fd;
>> +	int local_ip_map_fd = -1;
>>   	int set_src_prog_fd, get_src_prog_fd;
>>   	int set_dst_prog_fd;
>>   	int key = 0, ifindex = -1;
>> -- 
>> 2.30.2
>>
> 
> I'm a bit surprised this ever successfully compiled. What version of clang
> did you have to upgrade to in order to see this error? IIRC I've used
> -Wsometimes-uninitialized on much older versions of clang.

I compiled with latest llvm-project source (llvm15 main branch).
Since latest pahole (built from source) by default will do parallel
dwarf parsing and btf generation when build vmlinux, you might need this 
patch as well for pahole:
   https://lore.kernel.org/bpf/20220511220249.525908-1-yhs@fb.com/

> 
> Anyways, looks good to me.
> 
> Acked-by: David Vernet <void@manifault.com>

  reply	other threads:[~2022-05-11 22:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11 18:47 [PATCH bpf-next] selftests/bpf: fix a few clang compilation errors Yonghong Song
2022-05-11 19:08 ` David Vernet
2022-05-11 22:10   ` Yonghong Song [this message]
2022-05-11 20:00 ` patchwork-bot+netdevbpf

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=a5f32630-85e3-f9c6-3afc-e6e862b9a820@fb.com \
    --to=yhs@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=void@manifault.com \
    /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