Skip to content

[clang][bytecode] Fix IntegralAP::{isMin,isMax} #145339

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

Merged
merged 1 commit into from
Jun 23, 2025
Merged

Conversation

tbaederr
Copy link
Contributor

We need to take signeness into account here.

We need to take signeness into account here.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Jun 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

We need to take signeness into account here.


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

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/IntegralAP.h (+10-2)
  • (modified) clang/test/AST/ByteCode/intap.cpp (+7)
diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h
index e7499fc9bf5a9..6683db941c736 100644
--- a/clang/lib/AST/ByteCode/IntegralAP.h
+++ b/clang/lib/AST/ByteCode/IntegralAP.h
@@ -163,8 +163,16 @@ template <bool Signed> class IntegralAP final {
       return !getValue().isNonNegative();
     return false;
   }
-  bool isMin() const { return getValue().isMinValue(); }
-  bool isMax() const { return getValue().isMaxValue(); }
+  bool isMin() const {
+    if constexpr (Signed)
+      return getValue().isMinSignedValue();
+    return getValue().isMinValue();
+  }
+  bool isMax() const {
+    if constexpr (Signed)
+      return getValue().isMaxSignedValue();
+    return getValue().isMaxValue();
+  }
   static constexpr bool isSigned() { return Signed; }
   bool isMinusOne() const { return Signed && getValue().isAllOnes(); }
 
diff --git a/clang/test/AST/ByteCode/intap.cpp b/clang/test/AST/ByteCode/intap.cpp
index 11dd9edb61a94..a7e43b34a7d2b 100644
--- a/clang/test/AST/ByteCode/intap.cpp
+++ b/clang/test/AST/ByteCode/intap.cpp
@@ -48,6 +48,13 @@ static_assert(DivA / DivB == 2, "");
 constexpr _BitInt(4) DivC = DivA / 0; // both-error {{must be initialized by a constant expression}} \
                                       // both-note {{division by zero}}
 
+constexpr __int128 isMinDiv() {
+  return __int128{0} / __int128{-1};
+}
+static_assert(isMinDiv() == 0, "");
+
+
+
 constexpr _BitInt(7) RemA = 47;
 constexpr _BitInt(6) RemB = 9;
 static_assert(RemA % RemB == 2, "");

@tbaederr tbaederr merged commit 836ff36 into llvm:main Jun 23, 2025
11 checks passed
Jaddyen pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 23, 2025
We need to take signeness into account here.
@antmox
Copy link
Contributor

antmox commented Jun 24, 2025

Hi,
Could this be the cause of this buildbot failure ?
https://lab.llvm.org/buildbot/#/builders/122/builds/1647

File /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/llvm/clang/test/AST/ByteCode/intap.cpp Line 51: __int128 is not supported on this target
File /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/llvm/clang/test/AST/ByteCode/intap.cpp Line 52: __int128 is not supported on this target
File /home/tcwg-buildbot/worker/clang-armv8-lld-2stage/llvm/clang/test/AST/ByteCode/intap.cpp Line 52: __int128 is not supported on this target

@tbaederr
Copy link
Contributor Author

Yes, you need 0e461d1 as well

@antmox
Copy link
Contributor

antmox commented Jun 24, 2025

Oops Ok! missed this one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:bytecode Issues for the clang bytecode constexpr interpreter 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.

3 participants