[clang] 5084891 - [CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 1 04:02:27 PDT 2023


Author: Nikita Popov
Date: 2023-11-01T12:02:19+01:00
New Revision: 50848916e5e4f07231c7366e6d0014de6f7bc362

URL: https://github.com/llvm/llvm-project/commit/50848916e5e4f07231c7366e6d0014de6f7bc362
DIFF: https://github.com/llvm/llvm-project/commit/50848916e5e4f07231c7366e6d0014de6f7bc362.diff

LOG: [CGExprConstant] Avoid use of ConstantExpr::getIntegerCast() (NFC)

We're working on a ConstantInt here, so folding cannot fail. Only
avoid the API use.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGExprConstant.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index c46f38d651972bc..cd91a698a9336f8 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1930,8 +1930,9 @@ ConstantLValueEmitter::tryEmitAbsolute(llvm::Type *destTy) {
   // FIXME: signedness depends on the original integer type.
   auto intptrTy = CGM.getDataLayout().getIntPtrType(destPtrTy);
   llvm::Constant *C;
-  C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy,
-                                         /*isSigned*/ false);
+  C = llvm::ConstantFoldIntegerCast(getOffset(), intptrTy, /*isSigned*/ false,
+                                    CGM.getDataLayout());
+  assert(C && "Must have folded, as Offset is a ConstantInt");
   C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy);
   return C;
 }


        


More information about the cfe-commits mailing list