[PATCH] D156378: [clang][CGExprConstant] handle unary negation on integrals

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 2 16:13:11 PDT 2023


nickdesaulniers updated this revision to Diff 546634.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

- prefer VisitUnaryMinus as per @efriedma


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156378

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1363,6 +1363,13 @@
     return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitUnaryMinus(UnaryOperator *U, QualType T) {
+    if (llvm::Constant *C = Visit(U->getSubExpr(), T))
+      if (auto *CI = dyn_cast<llvm::ConstantInt>(C))
+        return llvm::ConstantInt::get(CGM.getLLVMContext(), -CI->getValue());
+    return nullptr;
+  }
+
   // Utility methods
   llvm::Type *ConvertType(QualType T) {
     return CGM.getTypes().ConvertType(T);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156378.546634.patch
Type: text/x-patch
Size: 653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230802/23e83f53/attachment.bin>


More information about the cfe-commits mailing list