[clang] [CIR] Implement emitNewArrayInit for constant and strings (PR #192666)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 17 15:02:43 PDT 2026
================
@@ -488,9 +488,13 @@ static mlir::Value emitCXXNewAllocSize(CIRGenFunction &cgf, const CXXNewExpr *e,
// The equivalent code in CodeGen/CGExprCXX.cpp handles these cases as
// overflow, but that should never happen. The size argument is implicitly
// cast to a size_t, so it can never be negative and numElementsWidth will
- // always equal sizeWidth.
+ // always equal sizeWidth. However, sometimes in operator-new, it seems that
+ // `numElements` might remain an 'int', so we have to support smaller than
+ // that. We immediately do the zextOrTrunc below (which should really only
+ // do zext, since our assert handles the trunc), but it will make sure the
+ // width is correct.
assert(!count.isNegative() && "Expected non-negative array size");
- assert(numElementsWidth == sizeWidth &&
+ assert(numElementsWidth <= sizeWidth &&
----------------
andykaylor wrote:
As I read your change to the comment above, something about it seemed really familiar. I thought for a second I had forgotten to post a patch I made changing the size handling for pre-C++14 behavior but after investigating I found that I only changed it for the non-constant handling. I think we probably need to implement the overflow handling that the comment above says isn't necessary. That isn't necessarily related to the PR, of course.
https://github.com/llvm/llvm-project/pull/192666
More information about the cfe-commits
mailing list