[clang] [NFC] Minor fix to tryEmitAbstract type in EmitCXXNewAllocSize (PR #123433)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 13:14:49 PST 2025
erichkeane 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.
Oooh, hrmph. I find myself thinking that `ProduceIntToIntCast` shouldn't be necessary in most cases, since the `size_t is pointer type` is pretty uniform. Though I think I saw above you found some platforms we support doing this, so an assert wouldn't be a good replacement.
I can see now why this isn't really testable, this is really quite unfortunate here.
https://github.com/llvm/llvm-project/pull/123433
More information about the cfe-commits
mailing list