Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang][Interp] Implement bitwise operations for IntegralAP #71807

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Nov 9, 2023

No description provided.

@tbaederr tbaederr added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 9, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 9, 2023

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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

2 Files Affected:

  • (modified) clang/lib/AST/Interp/IntegralAP.h (+3-5)
  • (modified) clang/test/AST/Interp/intap.cpp (+9)
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..a8893c8cb4eb9b8 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -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, "");
+}
+
 #endif

@tbaederr
Copy link
Contributor Author

Ping

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but asking for some extra tests.

clang/test/AST/Interp/intap.cpp Show resolved Hide resolved
@tbaederr tbaederr merged commit aa4e34b into llvm:main Nov 16, 2023
3 checks passed
sr-tream pushed a commit to sr-tream/llvm-project that referenced this pull request Nov 20, 2023
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants