[PATCH] D137399: [clang][Interp] Emit negated integers directly as constants

2022-11-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

This was just to make the byte code a little more readable, but given the 
amount of pending patches I already have, I'll abandon this and maybe revisit 
at a later point, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137399/new/

https://reviews.llvm.org/D137399

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137399: [clang][Interp] Emit negated integers directly as constants

2022-11-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This is missing test coverage (possibly around integer promotion behavior as 
well).




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1525
+return true;
+  APSInt V = APSInt(IL->getValue(), /*IsUnsigned=*/false);
+  return this->emitConst(-V, E);

Are you sure about `IsUnsigned`? http://eel.is/c++draft/expr.unary.op#8 reads 
to me like `-0ULL` will remain unsigned as a result.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137399/new/

https://reviews.llvm.org/D137399

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137399: [clang][Interp] Emit negated integers directly as constants

2022-11-04 Thread Timm Bäder via Phabricator via cfe-commits
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(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);


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(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);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits