[PATCH] D63423: [Diagnostics] Diagnose misused xor as pow

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 17 10:57:47 PDT 2019


jfb added a comment.

Why have `.c` and `.cpp` tests?



================
Comment at: test/Sema/warn-xor-as-pow.c:43
+  res = TWO_ULL ^ 16;
+  res = 2 ^ 32; // expected-warning {{result of '2 ^ 32' is 34; maybe you mean '1<<32', but shift count >= width of type}}
+  // expected-note at -1 {{replace expression with '(2) ^ 32' to silence this warning}}
----------------
I think we want to suggest `1LL << 32` or something like that. Whatever we usually do with this type of suggestion.


================
Comment at: test/Sema/warn-xor-as-pow.c:45
+  // expected-note at -1 {{replace expression with '(2) ^ 32' to silence this warning}}
+  res = 2 ^ 64; // expected-warning {{result of '2 ^ 64' is 66; maybe you mean '1<<64', but shift count >= width of type}}
+  // expected-note at -1 {{replace expression with '(2) ^ 64' to silence this warning}}
----------------
This one hits a ceiling, we can't really suggest anything for this value IMO. Maybe we need to see if the user is doing `2^64 - 1`? In that case we can offer a suggestion.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63423/new/

https://reviews.llvm.org/D63423





More information about the cfe-commits mailing list