public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug modula2/113889] Incorrect constant string value if declared in a definition module Date: Mon, 19 Feb 2024 13:02:32 +0000 [thread overview] Message-ID: <bug-113889-4-5qUKVL1fV1@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-113889-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113889 --- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>: https://gcc.gnu.org/g:78b72ee5a80f45bd761a55006e2b3fc2cbe749bc commit r14-9063-g78b72ee5a80f45bd761a55006e2b3fc2cbe749bc Author: Gaius Mulley <gaiusmod2@gmail.com> Date: Mon Feb 19 12:59:36 2024 +0000 PR modula2/113889 Incorrect constant string value if declared in a definition module This patch fixes a bug exposed when a constant string is declared in a definition module and imported by a program module. The bug fix was to defer the string assignment and concatenation until quadruples were generated. The conststring symbol has a known field which must be checked prior to retrieving the string contents. gcc/m2/ChangeLog: PR modula2/113889 * gm2-compiler/M2ALU.mod (StringFitsArray): Add tokeno parameter to GetStringLength. (InitialiseArrayOfCharWithString): Add tokeno parameter to GetStringLength. (CheckGetCharFromString): Add tokeno parameter to GetStringLength. * gm2-compiler/M2Const.mod (constResolveViaMeta): Replace PutConstString with PutConstStringKnown. * gm2-compiler/M2GCCDeclare.mod (DeclareCharConstant): Add tokenno parameter and add assert. Use tokenno to generate location. (DeclareStringConstant): Add tokenno and add asserts. Add tokenno parameter to calls to GetStringLength. (PromoteToString): Add assert and add tokenno parameter to GetStringLength. (PromoteToCString): Add assert and add tokenno parameter to GetStringLength. (DeclareConstString): New procedure function. (TryDeclareConst): Remove size local variable. Check IsConstStringKnown. Call DeclareConstString. (PrintString): New procedure. (PrintVerboseFromList): Call PrintString. (CheckResolveSubrange): Check IsConstStringKnown before creating subrange for char or issuing an error. * gm2-compiler/M2GenGCC.mod (ResolveConstantExpressions): Add StringLengthOp, StringConvertM2nulOp, StringConvertCnulOp case clauses. (FindSize): Add assert IsConstStringKnown. (StringToChar): New variable tokenno. Add tokenno parameter to GetStringLength. (FoldStringLength): New procedure. (FoldStringConvertM2nul): New procedure. (FoldStringConvertCnul): New procedure. (CodeAddr): Add tokenno parameter. Replace CurrentQuadToken with tokenno. Add tokenno parameter to GetStringLength. (PrepareCopyString): Rewrite. (IsConstStrKnown): New procedure function. (FoldAdd): Detect conststring op2 and op3 which are known and concat. Place result into op1. (FoldStandardFunction): Pass tokenno as a parameter to GetStringLength. (CodeXIndr): Rewrite comment. Rename op1 to left, op3 to right. Pass rightpos to GetStringLength. * gm2-compiler/M2Quads.def (QuadrupleOp): Add StringConvertCnulOp, StringConvertM2nulOp and StringLengthOp. * gm2-compiler/M2Quads.mod (import): Remove MakeConstLitString. Add CopyConstString and PutConstStringKnown. (IsInitialisingConst): Add StringConvertCnulOp, StringConvertM2nulOp and StringLengthOp. (callRequestDependant): Replace MakeConstLitString with MakeConstString. (DeferMakeConstStringCnul): New procedure function. (DeferMakeConstStringM2nul): New procedure function. (CheckParameter): Add early return if the string const is unknown. (DescribeType): Add token parameter to GetStringLength. Check for IsConstStringKnown. (ManipulateParameters): Use DeferMakeConstStringCnul and DeferMakeConstStringM2nul. (MakeLengthConst): Remove and replace with... (DeferMakeLengthConst): ... this. (doBuildBinaryOp): Create ConstString and set it to contents unknown. Check IsConstStringKnown before generating error message. (WriteQuad): Add StringConvertCnulOp, StringConvertM2nulOp and StringLengthOp. (WriteOperator): Add StringConvertCnulOp, StringConvertM2nulOp and StringLengthOp. * gm2-compiler/M2SymInit.mod (CheckReadBeforeInitQuad): Add StringConvertCnulOp, StringConvertM2nulOp and StringLengthOp. * gm2-compiler/NameKey.mod (LengthKey): Allow NulName to return 0. * gm2-compiler/P2SymBuild.mod (BuildString): Replace MakeConstLitString with MakeConstString. (DetermineType): Replace PutConstString with PutConstStringKnown. * gm2-compiler/SymbolTable.def (MakeConstVar): Tidy up comment. (MakeConstLitString): Remove. (MakeConstString): New procedure function. (MakeConstStringCnul): New procedure function. (MakeConstStringM2nul): New procedure function. (PutConstStringKnown): New procedure. (CopyConstString): New procedure. (IsConstStringKnown): New procedure function. (IsConstStringM2): New procedure function. (IsConstStringC): New procedure function. (IsConstStringM2nul): New procedure function. (IsConstStringCnul): New procedure function. (GetStringLength): Add token parameter. (PutConstString): Remove. (GetConstStringM2): Remove. (GetConstStringC): Remove. (GetConstStringM2nul): Remove. (GetConstStringCnul): Remove. (MakeConstStringC): Remove. * gm2-compiler/SymbolTable.mod (SymConstString): Remove M2Variant, NulM2Variant, CVariant, NulCVariant. Add Known. (CheckAnonymous): Replace $$ with __anon. (IsNameAnonymous): Replace $$ with __anon. (MakeConstVar): Detect whether the name is nul and treat as a temporary constant. (MakeConstLitString): Remove. (BackFillString): Remove. (InitConstString): Rewrite. (GetConstStringM2): Remove. (GetConstStringC): Remove. (GetConstStringContent): New procedure function. (GetConstStringM2nul): Remove. (GetConstStringCnul): Remove. (MakeConstStringCnul): Rewrite. (MakeConstStringM2nul): Rewrite. (MakeConstStringC): Remove. (MakeConstString): Rewrite. (PutConstStringKnown): New procedure. (CopyConstString): New procedure. (PutConstString): Remove. (IsConstStringKnown): New procedure function. (IsConstStringM2): New procedure function. (IsConstStringC): Rewrite. (IsConstStringM2nul): Rewrite. (IsConstStringCnul): Rewrite. (GetConstStringKind): New procedure function. (GetString): Check Known. (GetStringLength): Add token parameter and check Known. gcc/testsuite/ChangeLog: PR modula2/113889 * gm2/pim/run/pass/pim-run-pass.exp: Add filter for constdef.mod. * gm2/extensions/run/pass/callingc2.mod: New test. * gm2/extensions/run/pass/callingc3.mod: New test. * gm2/extensions/run/pass/callingc4.mod: New test. * gm2/extensions/run/pass/callingc5.mod: New test. * gm2/extensions/run/pass/callingc6.mod: New test. * gm2/extensions/run/pass/callingc7.mod: New test. * gm2/extensions/run/pass/callingc8.mod: New test. * gm2/extensions/run/pass/fixedarray.mod: New test. * gm2/extensions/run/pass/fixedarray2.mod: New test. * gm2/pim/run/pass/constdef.def: New test. * gm2/pim/run/pass/constdef.mod: New test. * gm2/pim/run/pass/testimportconst.mod: New test. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
next prev parent reply other threads:[~2024-02-19 13:02 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-12 12:25 [Bug modula2/113889] New: " gaius at gcc dot gnu.org 2024-02-12 12:26 ` [Bug modula2/113889] " gaius at gcc dot gnu.org 2024-02-18 1:26 ` gaius at gcc dot gnu.org 2024-02-19 13:02 ` cvs-commit at gcc dot gnu.org [this message] 2024-02-19 13:03 ` gaius at gcc dot gnu.org
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=bug-113889-4-5qUKVL1fV1@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@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).