[PATCH] D137399: [clang][Interp] Emit negated integers directly as constants
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 4 01:18:29 PDT 2022
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137399
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1518,6 +1518,13 @@
// The Inv doesn't change anything, so skip it if we don't need the result.
return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E);
case UO_Minus: // -x
+ // Emit negated integers directly.
+ if (const auto *IL = dyn_cast<IntegerLiteral>(SubExpr)) {
+ if (DiscardResult)
+ return true;
+ APSInt V = APSInt(IL->getValue(), /*IsUnsigned=*/false);
+ return this->emitConst(-V, E);
+ }
if (!this->visit(SubExpr))
return false;
return DiscardResult ? this->emitPop(*T, E) : this->emitNeg(*T, E);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137399.473152.patch
Type: text/x-patch
Size: 793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221104/6a6c0579/attachment.bin>
More information about the cfe-commits
mailing list