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

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 15 21:17:45 PST 2023


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

>From 72b46d891d34e7c0810bec335221a109cf4fb3a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 9 Nov 2023 14:29:51 +0100
Subject: [PATCH] [clang][Interp] Implement bitwise operations for IntegralAP

---
 clang/lib/AST/Interp/IntegralAP.h |  8 +++-----
 clang/test/AST/Interp/intap.cpp   | 12 ++++++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h
index 88de1f1392e6813..c8850a4bbb574aa 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -219,21 +219,19 @@ template <bool Signed> class IntegralAP final {
 
   static bool bitAnd(IntegralAP A, IntegralAP B, unsigned OpBits,
                      IntegralAP *R) {
-    // FIXME: Implement.
-    assert(false);
+    *R = IntegralAP(A.V & B.V);
     return false;
   }
 
   static bool bitOr(IntegralAP A, IntegralAP B, unsigned OpBits,
                     IntegralAP *R) {
-    assert(false);
+    *R = IntegralAP(A.V | B.V);
     return false;
   }
 
   static bool bitXor(IntegralAP A, IntegralAP B, unsigned OpBits,
                      IntegralAP *R) {
-    // FIXME: Implement.
-    assert(false);
+    *R = IntegralAP(A.V ^ B.V);
     return false;
   }
 
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 34c8d0565082994..729d144012713fb 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -157,4 +157,16 @@ 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, "");
+  static_assert((Max & 1) == 1, "");
+  static_assert((UZero | 1) == 1, "");
+  static_assert((Max ^ UZero) == Max, "");
+}
+
 #endif



More information about the cfe-commits mailing list