[clang] [clang][Interp] Implement bitwise operations for IntegralAP (PR #71807)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 11:15:26 PST 2023


================
@@ -157,4 +157,13 @@ namespace Bitfields {
                         // expected-warning {{changes value from 100 to 0}}
 }
 
+namespace BitOps {
+  constexpr unsigned __int128 UZero = 0;
+  constexpr unsigned __int128 Max = ~UZero;
+  static_assert(Max == ~0, "");
+  static_assert((Max & 0) == 0, "");
+  static_assert((UZero | 0) == 0, "");
+  static_assert((Max ^ Max) == 0, "");
----------------
AaronBallman wrote:

```suggestion
  static_assert((Max & 0) == 0, "");
  static_assert((UZero | 0) == 0, "");
  static_assert((Max ^ Max) == 0, "");
  static_assert((Max & 1) == 1, "");
  static_assert((UZero | 1) == 1, "");
  static_assert((Max ^ UZero) == Max, "");
```
Let's add some tests where the results aren't zero.

https://github.com/llvm/llvm-project/pull/71807


More information about the cfe-commits mailing list