public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5216] Detect errors when dereferencing an undeclared variable.
@ 2023-01-16 18:10 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2023-01-16 18:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a0c595386fa322e1874d33742fc56c6a0c13c4a5

commit r13-5216-ga0c595386fa322e1874d33742fc56c6a0c13c4a5
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Mon Jan 16 18:09:04 2023 +0000

    Detect errors when dereferencing an undeclared variable.
    
    Attempting to dereference an undeclared variable will cause an ICE.
    Also attempting to pass an undeclared variable as an array of type
    will also cause an ICE.  This patch detects both conditions and
    generates an appropriate error.
    
    gcc/m2/ChangeLog:
    
            * gm2-compiler/M2Quads.mod (AssignUnboundedVar): Check Type
            against NulSym and call MetaErrorT1 if necessary.
            (AssignUnboundedNonVar): Check Type against NulSym and
            call MetaErrorT1 if necessary.
            (BuildDesignatorPointer): Check Type1 against NulSym and
            call MetaErrorT1 if necessary.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 263fb7c7417..a58de93e4a8 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -6327,7 +6327,10 @@ BEGIN
    ELSIF IsVar(Sym)
    THEN
       Type := GetDType(Sym) ;
-      IF IsUnbounded(Type)
+      IF Type = NulSym
+      THEN
+         MetaErrorT1 (tok, '{%1ad} has no type and cannot be passed to a VAR formal parameter', Sym)
+      ELSIF IsUnbounded(Type)
       THEN
          IF Type = GetSType (UnboundedSym)
          THEN
@@ -6382,7 +6385,10 @@ BEGIN
    ELSIF IsVar (Sym)
    THEN
       Type := GetDType (Sym) ;
-      IF IsUnbounded (Type)
+      IF Type = NulSym
+      THEN
+         MetaErrorT1 (tok, '{%1ad} has no type and cannot be passed to a non VAR formal parameter', Sym)
+      ELSIF IsUnbounded (Type)
       THEN
          UnboundedNonVarLinkToArray (tok, Sym, ArraySym, UnboundedSym, ParamType, dim)
       ELSIF IsArray (Type) OR IsGenericSystemType (ParamType)
@@ -11386,7 +11392,10 @@ VAR
 BEGIN
    PopTFrwtok (Sym1, Type1, rw, exprtok) ;
    Type1 := SkipType (Type1) ;
-   IF IsUnknown (Sym1)
+   IF Type1 = NulSym
+   THEN
+      MetaErrorT1 (ptrtok, '{%1ad} has no type and therefore cannot be dereferenced by ^', Sym1)
+   ELSIF IsUnknown (Sym1)
    THEN
       MetaError1 ('{%1EMad} is undefined and therefore {%1ad}^ cannot be resolved', Sym1)
    ELSIF IsPointer (Type1)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-16 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16 18:10 [gcc r13-5216] Detect errors when dereferencing an undeclared variable Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).