From fb2bdbb83d3913d9d32b28c1de3f3d8b4e6dfc8a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 28 Sep 2023 16:44:52 +0200 Subject: [CodeGen] Avoid use of ConstantExpr::getZExt() (NFC) Use the constant folding API instead. In preparation for dropping zext constant expressions. --- clang/lib/CodeGen/CGExprConstant.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CGExprConstant.cpp') diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 2c847f0bb13f..9b67a8b3335a 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -25,6 +25,7 @@ #include "clang/Basic/Builtins.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Sequence.h" +#include "llvm/Analysis/ConstantFolding.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" @@ -1761,7 +1762,10 @@ llvm::Constant *ConstantEmitter::emitForMemory(CodeGenModule &CGM, // Zero-extend bool. if (C->getType()->isIntegerTy(1) && !destType->isBitIntType()) { llvm::Type *boolTy = CGM.getTypes().ConvertTypeForMem(destType); - return llvm::ConstantExpr::getZExt(C, boolTy); + llvm::Constant *Res = llvm::ConstantFoldCastOperand( + llvm::Instruction::ZExt, C, boolTy, CGM.getDataLayout()); + assert(Res && "Constant folding must succeed"); + return Res; } return C; -- cgit v1.2.3