[flang-commits] [flang] [flang] handle allocation of zero-sized objects (PR #149165)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Wed Jul 16 12:03:03 PDT 2025
================
@@ -1119,9 +1119,19 @@ struct AllocMemOpConversion : public fir::FIROpConversion<fir::AllocMemOp> {
mlir::Value size = genTypeSizeInBytes(loc, ity, rewriter, llvmObjectTy);
if (auto scaleSize = genAllocationScaleSize(heap, ity, rewriter))
size = rewriter.create<mlir::LLVM::MulOp>(loc, ity, size, scaleSize);
- for (mlir::Value opnd : adaptor.getOperands())
- size = rewriter.create<mlir::LLVM::MulOp>(
- loc, ity, size, integerCast(loc, rewriter, ity, opnd));
+ for (mlir::Value opnd : adaptor.getOperands()) {
+ auto arg = integerCast(loc, rewriter, ity, opnd);
+ auto val = fir::getIntIfConstant(arg);
----------------
vzakhari wrote:
Thanks for the changes!
Is that possible to have a dynamic size value in `fir.allocmem` operation? I think it is, so the check has to be dynamic, i.e. we need to generate a select `size <= 0 ? 1 : size` instead.
https://github.com/llvm/llvm-project/pull/149165
More information about the flang-commits
mailing list