[clang] [NFC] Minor fix to tryEmitAbstract type in EmitCXXNewAllocSize (PR #123433)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 13:04:52 PST 2025
andykaylor wrote:
> Shouldn't there be a pointer-vs-intty difference in the LLVM-IR here?
No, because in this case tryEmitAbstract() is only using the size of the type that's passed in. After a few visits, it eventually calls this function:
```
llvm::Constant *ProduceIntToIntCast(const Expr *E, QualType DestType) {
QualType FromType = E->getType();
// See also HandleIntToIntCast in ExprConstant.cpp
if (FromType->isIntegerType())
if (llvm::Constant *C = Visit(E, FromType))
if (auto *CI = dyn_cast<llvm::ConstantInt>(C)) {
unsigned SrcWidth = CGM.getContext().getIntWidth(FromType);
unsigned DstWidth = CGM.getContext().getIntWidth(DestType);
if (DstWidth == SrcWidth)
return CI;
llvm::APInt A = FromType->isSignedIntegerType()
? CI->getValue().sextOrTrunc(DstWidth)
: CI->getValue().zextOrTrunc(DstWidth);
return llvm::ConstantInt::get(CGM.getLLVMContext(), A);
}
return nullptr;
}
```
The DestType parameter is only used to resize the constant if necessary (which in this case it won't be). The equivalent function in CIR was asserting that DestType was an integer type, which is what led me to this change.
https://github.com/llvm/llvm-project/pull/123433
More information about the cfe-commits
mailing list