diff options
Diffstat (limited to 'lib/CodeGen/Designator.cc')
| -rw-r--r-- | lib/CodeGen/Designator.cc | 17 |
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()); |
