Skip to contentSkip to conversation

test_bpf: Fix a new clang warning about xor-ing two numbers

PATCH Applied Nathan Chancellor 3 participants 3 messages Aug 19, 2019 – Aug 20, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test_bpf: Fix a new clang warning about xor-ing two numbers

r369217 in clang added a new warning about potential misuse of the xor operator as an exponentiation operator:

../lib/test_bpf.c:870:13: warning: result of '10 ^ 300' is 294; did you mean '1e300'? [-Wxor-used-as-pow]

                { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
                       ~~~^~~~~
                       1e300

../lib/test_bpf.c:870:13: note: replace expression with '0xA ^ 300' to silence this warning
../lib/test_bpf.c:870:31: warning: result of '10 ^ 300' is 294; did you mean '1e300'? [-Wxor-used-as-pow]

                { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
                                         ~~~^~~~~
                                         1e300

../lib/test_bpf.c:870:31: note: replace expression with '0xA ^ 300' to silence this warning

The commit link for this new warning has some good logic behind wanting to add it but this instance appears to be a false positive. Adopt its suggestion to silence the warning but not change the code. According to the differential review link in the clang commit, GCC may eventually adopt this warning as well.

---

I highly doubt that 1e300 was intented but if it was (or something else was), please let me know. Commit history wasn't entirely clear on why this expression was used over just a raw number.

 lib/test_bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_bpf.c +1 -1
index c41705835cba..5ef3eccee27c 100644
@@ -867,7 +867,7 @@ static struct bpf_test tests[] = {
 		},
 		CLASSIC,
 		{ },
-		{ { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
+		{ { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
 	},
 	{
 		"SPILL_FILL",
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 24 lines · Nathan Chancellor

r369217 in clang added a new warning about potential misuse of the xor operator as an exponentiation operator:

../lib/test_bpf.c:870:13: warning: result of '10 ^ 300' is 294; did you mean '1e300'? [-Wxor-used-as-pow]

                 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
                        ~~~^~~~~
                        1e300

../lib/test_bpf.c:870:13: note: replace expression with '0xA ^ 300' to silence this warning
../lib/test_bpf.c:870:31: warning: result of '10 ^ 300' is 294; did you mean '1e300'? [-Wxor-used-as-pow]

                 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
                                          ~~~^~~~~
                                          1e300

../lib/test_bpf.c:870:31: note: replace expression with '0xA ^ 300' to silence this warning

The commit link for this new warning has some good logic behind wanting to add it but this instance appears to be a false positive. Adopt its suggestion to silence the warning but not change the code. According to the differential review link in the clang commit, GCC may eventually adopt this warning as well.

Quoted 3 lines

Verified that latest trunk clang indeed has this warning, and below change indeed fixed the warning in the correct way.

Quoted 23 lines

---

I highly doubt that 1e300 was intented but if it was (or something else was), please let me know. Commit history wasn't entirely clear on why this expression was used over just a raw number.

  lib/test_bpf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_bpf.c +1 -1
index c41705835cba..5ef3eccee27c 100644
@@ -867,7 +867,7 @@ static struct bpf_test tests[] = {
  		},
  		CLASSIC,
  		{ },
-		{ { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
+		{ { 4, 0xA ^ 300 }, { 20, 0xA ^ 300 } },
  	},
  	{
  		"SPILL_FILL",
maintainer Applied
#2 lore raw
In reply to Nathan Chancellor
Quoted 24 lines · Nathan Chancellor

r369217 in clang added a new warning about potential misuse of the xor operator as an exponentiation operator:

../lib/test_bpf.c:870:13: warning: result of '10 ^ 300' is 294; did you mean '1e300'? [-Wxor-used-as-pow]

                 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
                        ~~~^~~~~
                        1e300

../lib/test_bpf.c:870:13: note: replace expression with '0xA ^ 300' to silence this warning
../lib/test_bpf.c:870:31: warning: result of '10 ^ 300' is 294; did you mean '1e300'? [-Wxor-used-as-pow]

                 { { 4, 10 ^ 300 }, { 20, 10 ^ 300 } },
                                          ~~~^~~~~
                                          1e300

../lib/test_bpf.c:870:31: note: replace expression with '0xA ^ 300' to silence this warning

The commit link for this new warning has some good logic behind wanting to add it but this instance appears to be a false positive. Adopt its suggestion to silence the warning but not change the code. According to the differential review link in the clang commit, GCC may eventually adopt this warning as well.

Quoted 3 lines

Applied, thanks!