Skip to content

Conversation

@steakhal
Copy link

@steakhal steakhal commented Jan 5, 2026

Previously, if the result type was 'large' (at least 65 bits), then the ASTContext::getIntTypeForBitwidth would return an empty QualType, causing later a crash when we assume it's non-empty.

Instead of using this API, we could piggyback on the BigInt type to formulate a "large enough" type for calculating the mathematically correct result for the operation to check against. Crash: https://godbolt.org/z/dGY3vh39a

void bigint(_BitInt(63) a, _BitInt(63) b) {
  _BitInt(63) result = 0;
  (void)__builtin_add_overflow(a, b, &result); // crashes here
}

Fixes llvm#173795

rdar://166709144
(cherry picked from commit 984c577)

)

Previously, if the result type was 'large' (at least 65 bits), then the
ASTContext::getIntTypeForBitwidth would return an empty QualType,
causing later a crash when we assume it's non-empty.

Instead of using this API, we could piggyback on the BigInt type to
formulate a "large enough" type for calculating the mathematically
correct result for the operation to check against.
Crash: https://godbolt.org/z/dGY3vh39a
```c++
void bigint(_BitInt(63) a, _BitInt(63) b) {
  _BitInt(63) result = 0;
  (void)__builtin_add_overflow(a, b, &result); // crashes here
}
```

Fixes llvm#173795

rdar://166709144
(cherry picked from commit 984c577)
@steakhal steakhal requested a review from a team as a code owner January 5, 2026 14:29
@steakhal
Copy link
Author

steakhal commented Jan 5, 2026

@swift-ci please test

@steakhal
Copy link
Author

steakhal commented Jan 5, 2026

The linux test failure doesn't seem related.

Copy link

@ziqingluo-90 ziqingluo-90 left a comment

Choose a reason for hiding this comment

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

The fix LGTM. I'm curious whether the behavior of ASTContext::getIntTypeForBitwidth is considered correct or not?

@steakhal
Copy link
Author

steakhal commented Jan 5, 2026

The fix LGTM. I'm curious whether the behavior of ASTContext::getIntTypeForBitwidth is considered correct or not?

Yes. It depends on the contract. It works for the usual types and powers of 2.
It's just my unique case that I want arbitrary bitwidth arithmetic because we are lazy to overthink it. (see the multiplication by 2 to be sure it fits).

@steakhal
Copy link
Author

steakhal commented Jan 6, 2026

@swift-ci please test Linux

@steakhal
Copy link
Author

steakhal commented Jan 6, 2026

@swift-ci please test macOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants