-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][bytecode] Explicitly truncate in IntegralAP::from() #112683
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
Conversation
Add Integral::toAPInt(), which truncates to the given BitWidth, similar to the toAPSInt() we already have.
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesAdd Integral::toAPInt(), which truncates to the given BitWidth, similar to the toAPSInt() we already have. Full diff: https://github.com/llvm/llvm-project/pull/112683.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Integral.h b/clang/lib/AST/ByteCode/Integral.h
index e06ec1669259da..be537d22d5af1b 100644
--- a/clang/lib/AST/ByteCode/Integral.h
+++ b/clang/lib/AST/ByteCode/Integral.h
@@ -122,11 +122,14 @@ template <unsigned Bits, bool Signed> class Integral final {
APSInt toAPSInt() const {
return APSInt(APInt(Bits, static_cast<uint64_t>(V), Signed), !Signed);
}
- APSInt toAPSInt(unsigned NumBits) const {
+ APSInt toAPSInt(unsigned BitWidth) const { return APSInt(toAPInt(BitWidth)); }
+ APInt toAPInt(unsigned BitWidth) const {
if constexpr (Signed)
- return APSInt(toAPSInt().sextOrTrunc(NumBits), !Signed);
+ return APInt(Bits, static_cast<uint64_t>(V), Signed)
+ .sextOrTrunc(BitWidth);
else
- return APSInt(toAPSInt().zextOrTrunc(NumBits), !Signed);
+ return APInt(Bits, static_cast<uint64_t>(V), Signed)
+ .zextOrTrunc(BitWidth);
}
APValue toAPValue(const ASTContext &) const { return APValue(toAPSInt()); }
diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h
index 252d7243bee73e..f8aeaaca398fe8 100644
--- a/clang/lib/AST/ByteCode/IntegralAP.h
+++ b/clang/lib/AST/ByteCode/IntegralAP.h
@@ -112,12 +112,7 @@ template <bool Signed> class IntegralAP final {
template <unsigned Bits, bool InputSigned>
static IntegralAP from(Integral<Bits, InputSigned> I, unsigned BitWidth) {
- // TODO: Avoid implicit trunc?
- // See https://github.com/llvm/llvm-project/issues/112510.
- APInt Copy = APInt(BitWidth, static_cast<uint64_t>(I), InputSigned,
- /*implicitTrunc=*/true);
-
- return IntegralAP<Signed>(Copy);
+ return IntegralAP<Signed>(I.toAPInt(BitWidth));
}
static IntegralAP zero(int32_t BitWidth) {
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/55/builds/2871 Here is the relevant piece of the build log for the reference |
Add Integral::toAPInt(), which truncates to the given BitWidth, similar to the toAPSInt() we already have.