Skip to content

[clang][Interp] Fix creating APSInt from IntegralAP #71410

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
Nov 8, 2023

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Nov 6, 2023

The boolean argument in the APSInt constructor is IsUnsigned, not IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.

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

llvmbot commented Nov 6, 2023

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

The boolean argument in the APSInt constructor is IsUnsigned, not IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.


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

2 Files Affected:

  • (modified) clang/lib/AST/Interp/IntegralAP.h (+2-2)
  • (modified) clang/test/AST/Interp/intap.cpp (+4)
diff --git a/clang/lib/AST/Interp/IntegralAP.h b/clang/lib/AST/Interp/IntegralAP.h
index 1f535d420bcd54b..134b602d1bb61ca 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,8 +119,8 @@ template <bool Signed> class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
-  APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
+  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
+  APValue toAPValue() const {return APValue(APSInt(V, !Signed)); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..5f08b76a565c25a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -56,6 +56,10 @@ namespace i128 {
 
   static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
   static_assert(UINT128_MAX == -1, "");
+  static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion failed}} \
+                                       // expected-note {{'340282366920938463463374607431768211455 == 1'}} \
+                                       // ref-error {{static assertion failed}} \
+                                       // ref-note {{'340282366920938463463374607431768211455 == 1'}}
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");

Copy link

github-actions bot commented Nov 6, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

The boolean argument in the APSInt constructor is IsUnsigned, not
IsSigned.

This marks the 10th time I've run into this issue. Happy anniversary.
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, sorry for missing that during previous review!

@tbaederr tbaederr merged commit e6a94dc into llvm:main Nov 8, 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.

3 participants