public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Gaius Mulley <gaius@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5216] Detect errors when dereferencing an undeclared variable. Date: Mon, 16 Jan 2023 18:10:29 +0000 (GMT) [thread overview] Message-ID: <20230116181029.EDB5F3858D32@sourceware.org> (raw) 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)
reply other threads:[~2023-01-16 18:10 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230116181029.EDB5F3858D32@sourceware.org \ --to=gaius@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).