aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-22 15:06:13 +0000
committer_ov4 <ov4@ov4.org>2026-10-22 15:21:11 +0000
commitfa83b7df5a0711bf5f4a5162cc33b0a4123a53c7 (patch)
treedcfd24756256fcef21c43f19aa6e914455435806 /include
parent353c38e23108856daa2c5d0e86443ac5136dcaa7 (diff)
fix(arrays): reject inverted bounds and check array allocation
Constant inverted bounds are a compile error and other bounds are checked at run time. Allocation sizes use overflow-checked arithmetic, and a NULL malloc (including the BYVAL copy) reports that the array is too large. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include')
-rw-r--r--include/cps/ArrayHandler.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/cps/ArrayHandler.h b/include/cps/ArrayHandler.h
index a09e708..f2d3490 100644
--- a/include/cps/ArrayHandler.h
+++ b/include/cps/ArrayHandler.h
@@ -52,6 +52,15 @@ class ArrayHandler {
std::vector<llvm::Value*> Lows,
std::vector<llvm::Value*> Highs,
llvm::Value *&TotalElements);
+ // Validates every dimension (upper >= lower) and returns the allocation
+ // size in bytes, trapping on overflow. Constant bounds were already checked
+ // at compile time; the others get a runtime check.
+ llvm::Value *emitCheckedByteSize(const std::string &Name,
+ const std::vector<llvm::Value*> &Lows,
+ const std::vector<llvm::Value*> &Highs,
+ llvm::Constant *ElementSize, int Line);
+ // Traps with "Array NAME is too large" when Ptr (a malloc result) is null.
+ void emitAllocCheck(llvm::Value *Ptr, const std::string &Name, int Line);
bool emitCheckedIndices(const std::string &Name,
const std::vector<std::unique_ptr<ExprAST>> &IndexExprs,
int Line,