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

[APInt] Enable APInt ctor assertion by default #112670

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Oct 17, 2024

This enables the assertion introduced in #106524, which checks that the value passed to the APInt constructor is indeed a valid N-bit signed or unsigned integer.

Places that previously violated the assertion were updated in advance, e.g. in #80309.

It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true.

This enables the assertion introduced in
llvm#106524, which checks
that the value passed to the constructor is indeed a valid
N-bit signed or unsigned integer.

Places that previously violated the assertion were updated in
advance, e.g. in llvm#80309.

It is possible to opt-out of the check and restore the previous
behavior by setting implicitTrunc=true.
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 17, 2024

@llvm/pr-subscribers-llvm-adt

Author: Nikita Popov (nikic)

Changes

This enables the assertion introduced in #106524, which checks that the value passed to the APInt constructor is indeed a valid N-bit signed or unsigned integer.

Places that previously violated the assertion were updated in advance, e.g. in #80309.

It is possible to opt-out of the check and restore the previous behavior by setting implicitTrunc=true.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/APInt.h (+1-1)
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 63a138527b32e1..953b2a27b71526 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -109,7 +109,7 @@ class [[nodiscard]] APInt {
   /// \param implicitTrunc allow implicit truncation of non-zero/sign bits of
   ///                      val beyond the range of numBits
   APInt(unsigned numBits, uint64_t val, bool isSigned = false,
-        bool implicitTrunc = true)
+        bool implicitTrunc = false)
       : BitWidth(numBits) {
     if (!implicitTrunc) {
       if (isSigned) {

Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

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

LGTM.

@nikic nikic merged commit ba1ee2b into llvm:main Oct 18, 2024
10 checks passed
@nikic nikic deleted the apint-assert-enable branch October 18, 2024 07:23
nikic added a commit that referenced this pull request Oct 18, 2024
This reverts commit ba1ee2b.

Causes some buildbot failures on aarch64.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants