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-5463] PR-108557 Stuck compilation for empty file Date: Fri, 27 Jan 2023 22:19:11 +0000 (GMT) [thread overview] Message-ID: <20230127221911.F1F273858D20@sourceware.org> (raw) https://gcc.gnu.org/g:97bf709f35af45f9cf2902904d82493efed0d2ec commit r13-5463-g97bf709f35af45f9cf2902904d82493efed0d2ec Author: Gaius Mulley <gaiusmod2@gmail.com> Date: Fri Jan 27 22:18:46 2023 +0000 PR-108557 Stuck compilation for empty file Trying to compile an empty file causes cc1gm2 to hang. The bug occurs when M2LexBuf.mod calls m2flex.GetToken after an eof token has been seen which results in m2flex attempting to read from stdin. The bug fix detects eof per file and blocks subsequent calls to m2flex.GetToken. gcc/m2/ChangeLog: * gm2-compiler/M2Comp.mod: Import MetaString0. (ExamineCompilationUnit): New variable Message. Create and format error string. * gm2-compiler/M2LexBuf.mod: New variable SeenEof. (GetNonEofToken): New procedure. (Init): Set SeenEof to FALSE. (GetToken): Use GetNonEofToken instead of calls to m2flex.GetToken and GetToken. (AddTok): Detect eoftok and set SeenEof. gcc/testsuite/ChangeLog: * gm2/pim/fail/empty.mod: New test. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com> Diff: --- gcc/m2/gm2-compiler/M2Comp.mod | 21 ++++++++++--------- gcc/m2/gm2-compiler/M2LexBuf.mod | 39 ++++++++++++++++++++++++++++++------ gcc/testsuite/gm2/pim/fail/empty.mod | 1 + 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/gcc/m2/gm2-compiler/M2Comp.mod b/gcc/m2/gm2-compiler/M2Comp.mod index 05eaaccb554..3c2c3643b18 100644 --- a/gcc/m2/gm2-compiler/M2Comp.mod +++ b/gcc/m2/gm2-compiler/M2Comp.mod @@ -39,7 +39,7 @@ FROM libc IMPORT exit ; FROM M2Error IMPORT ErrorStringAt, ErrorStringAt2, ErrorStringsAt2, WriteFormat0, FlushErrors, FlushWarnings, ResetErrorScope ; -FROM M2MetaError IMPORT MetaErrorString1, MetaError0, MetaError1 ; +FROM M2MetaError IMPORT MetaErrorString0, MetaErrorString1, MetaError0, MetaError1, MetaString0 ; FROM FormatStrings IMPORT Sprintf1 ; FROM P0SymBuild IMPORT P0Init, P1Init ; @@ -173,6 +173,8 @@ END compile ; *) PROCEDURE ExamineCompilationUnit (VAR name: ADDRESS; VAR isdefimp: BOOLEAN) ; +VAR + Message: String ; BEGIN isdefimp := FALSE ; (* default to program module *) (* stop if we see eof, ';' or '[' *) @@ -189,8 +191,9 @@ BEGIN END ; GetToken END ; - m2flex.M2Error(string(InitString('failed to find module name'))) ; - exit(1) + Message := MetaString0 (InitString ('no {%kMODULE} name found')) ; + m2flex.M2Error (string (Message)) ; + exit (1) END ExamineCompilationUnit ; @@ -204,20 +207,20 @@ VAR name : ADDRESS ; isdefimp: BOOLEAN ; BEGIN - IF OpenSource(s) + IF OpenSource (s) THEN - ExamineCompilationUnit(name, isdefimp) ; + ExamineCompilationUnit (name, isdefimp) ; IF isdefimp THEN - SetMainModule(MakeImplementationSource(GetTokenNo(), makekey(name))) + SetMainModule (MakeImplementationSource (GetTokenNo (), makekey (name))) ELSE - SetMainModule(MakeProgramSource(GetTokenNo(), makekey(name))) + SetMainModule (MakeProgramSource (GetTokenNo (), makekey (name))) END ; CloseSource ; ReInitialize ELSE - fprintf1(StdErr, 'failed to open %s\n', s) ; - exit(1) + fprintf1 (StdErr, 'failed to open %s\n', s) ; + exit (1) END END PeepInto ; diff --git a/gcc/m2/gm2-compiler/M2LexBuf.mod b/gcc/m2/gm2-compiler/M2LexBuf.mod index a557f4ebeae..ac496f2d932 100644 --- a/gcc/m2/gm2-compiler/M2LexBuf.mod +++ b/gcc/m2/gm2-compiler/M2LexBuf.mod @@ -82,6 +82,8 @@ VAR ListOfTokens : ListDesc ; CurrentTokNo : CARDINAL ; InsertionIndex : CARDINAL ; + SeenEof : BOOLEAN ; (* Have we seen eof since the last call + to OpenSource. *) (* @@ -122,6 +124,7 @@ END InitTokenList ; PROCEDURE Init ; BEGIN + SeenEof := FALSE ; InsertionIndex := 0 ; currenttoken := eoftok ; CurrentTokNo := InitialSourceToken ; @@ -337,6 +340,7 @@ END SetFile ; PROCEDURE OpenSource (s: String) : BOOLEAN ; BEGIN + SeenEof := FALSE ; IF UseBufferedTokens THEN GetToken ; @@ -605,6 +609,27 @@ BEGIN END DumpTokens ; +(* + GetNonEofToken - providing that we have not already seen an eof for this source + file call m2flex.GetToken and GetToken if requested. +*) + +PROCEDURE GetNonEofToken (callGetToken: BOOLEAN) ; +BEGIN + IF SeenEof + THEN + currenttoken := eoftok + ELSE + (* Call the lexical phase to place a new token into the last bucket. *) + m2flex.GetToken () ; + IF callGetToken + THEN + GetToken + END + END +END GetNonEofToken ; + + (* GetToken - gets the next token into currenttoken. *) @@ -622,7 +647,7 @@ BEGIN ELSE IF ListOfTokens.tail=NIL THEN - m2flex.GetToken () ; + GetNonEofToken (FALSE) ; IF ListOfTokens.tail=NIL THEN HALT @@ -630,16 +655,14 @@ BEGIN END ; IF CurrentTokNo>=ListOfTokens.LastBucketOffset THEN - (* CurrentTokNo is in the last bucket or needs to be read *) + (* CurrentTokNo is in the last bucket or needs to be read. *) IF CurrentTokNo-ListOfTokens.LastBucketOffset<ListOfTokens.tail^.len THEN UpdateFromBucket (ListOfTokens.tail, CurrentTokNo-ListOfTokens.LastBucketOffset) ELSE - (* call the lexical phase to place a new token into the last bucket *) - m2flex.GetToken () ; - GetToken ; (* and call ourselves again to collect the token from bucket *) - RETURN + (* and call ourselves again to collect the token from bucket *) + GetNonEofToken (TRUE) END ELSE t := CurrentTokNo ; @@ -1175,6 +1198,10 @@ PROCEDURE AddTok (t: toktype) ; VAR s: String ; BEGIN + IF t = eoftok + THEN + SeenEof := TRUE + END ; IF NOT ((t=eoftok) AND IsLastTokenEof()) THEN AddTokToList(t, NulName, 0, diff --git a/gcc/testsuite/gm2/pim/fail/empty.mod b/gcc/testsuite/gm2/pim/fail/empty.mod new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/gcc/testsuite/gm2/pim/fail/empty.mod @@ -0,0 +1 @@ +
reply other threads:[~2023-01-27 22:19 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=20230127221911.F1F273858D20@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).