aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/Designator.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 18:10:10 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 18:10:10 +0000
commitc2c2e1771bf9b747f38dc145b5201b45c579d465 (patch)
tree09c752f360e56f523eb87e4a6dc17751be56210b /lib/CodeGen/Designator.cc
parenta44f1246dbe24fc813a212a5ef3f5811b1d6402a (diff)
fix: close type-safety holes found by adversarial review; update docs
Review findings (all reproduced, then fixed and re-verified): - '^x' leaked as a raw address into any builtin context (s <- ^x printed the variable's bytes as a C string; NOT ^x, '&', and ^x = ^x compiled). Address-of is now rejected everywhere except a pointer-typed target. - A whole-array variable passed the nominal gate as a value of its ELEMENT type (s <- arrayOfSeason stored the raw data pointer; = on it emitted invalid IR). Whole arrays are now rejected as operands and as coercion sources; array parameters are unaffected. - Enum values smuggled into INTEGER through array subscripts and DECLARE bounds (a[Autumn], ARRAY[Spring:Winter]); both now go through emitCoercedExpr like every other INTEGER context. - An array DECLAREd inside an IF/WHILE/REPEAT/FOR body and used after the block was a wild-pointer write (constant bounds) or a verifier dump (runtime bounds). Arrays are now block-scoped: control-flow bodies snapshot and restore the ArrayTable, so escape is a clean compile error. - Duplicate parameter names silently shadowed (BYREF write-back defeated); now a parse error. Trailing comma in parameter lists accepted; now a parse error consistent with every other list. - A variable/array/parameter/function could reuse a TYPE name; reserved. - RETURN with a value inside a PROCEDURE was silently discarded (control did not return); now an error, as is a bare RETURN in a FUNCTION. - INPUT r.f mis-parsed into a three-error cascade; now one clear error. - Assigning to an enum constant now says so instead of 'Unknown variable'. Docs: ARCH/CONVENTIONS/EXTENDING/SUBSYSTEMS/PITFALLS rewritten for the TYPE system (ABI additions, nominal-typing invariants, admission-gate doors, array-parameter ABI, new recipes, new sharp edges); README features/TODO updated — random files are unblocked. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/Designator.cc')
-rw-r--r--lib/CodeGen/Designator.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/CodeGen/Designator.cc b/lib/CodeGen/Designator.cc
index a0ffe28..ad0cc49 100644
--- a/lib/CodeGen/Designator.cc
+++ b/lib/CodeGen/Designator.cc
@@ -200,6 +200,15 @@ Value *CodeGen::loadFromLValue(const LValueInfo &LV) {
Value *CodeGen::emitCoercedExpr(ExprAST *E, const TypeInfo *Target) {
if (!E || !Target) return nullptr;
+ // A whole-array reference evaluates to its raw data pointer, and
+ // getExprTypeInfo reports the ELEMENT type for it — both would slip
+ // through the name check and smash the pointer into the target.
+ if (isWholeArrayVar(E)) {
+ reportError("A whole array cannot be used as a value of type %s; index it",
+ Target->Name.c_str());
+ return nullptr;
+ }
+
const TypeInfo *Src = getExprTypeInfo(E);
if (Target->isUserKind()) {
@@ -239,6 +248,14 @@ Value *CodeGen::emitCoercedExpr(ExprAST *E, const TypeInfo *Target) {
return emitExpr(E); // same nominal type: no conversion needed
}
+ // ^x is a raw address: admissible ONLY where a pointer type is expected.
+ // Without this check the ptr would coerce into STRING/BOOLEAN silently.
+ if (dynamic_cast<AddrOfExprAST*>(E)) {
+ reportError("'^' (address-of) can only be used where a pointer type is expected (got %s)",
+ Target->Name.c_str());
+ return nullptr;
+ }
+
if (Src && Src->isUserKind()) {
reportError("Cannot use a value of type %s where %s is expected",
Src->Name.c_str(), Target->Name.c_str());