public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/113889] New: Incorrect constant string value if declared in a definition module
@ 2024-02-12 12:25 gaius at gcc dot gnu.org
2024-02-12 12:26 ` [Bug modula2/113889] " gaius at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-12 12:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113889
Bug ID: 113889
Summary: Incorrect constant string value if declared in a
definition module
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: modula2
Assignee: gaius at gcc dot gnu.org
Reporter: gaius at gcc dot gnu.org
Target Milestone: ---
As reported on the gm2 mailing list. Constant strings are not handled
correctly if they are exported from a definition module (and appear as a nul
string).
DEFINITION MODULE Foo;
CONST Bar = "Blech";
END Foo.
IMPLEMENTATION MODULE Foo;
END Foo.
MODULE test_foo;
IMPORT Foo;
FROM STextIO IMPORT WriteString, WriteLn;
FROM Foo IMPORT Bar;
BEGIN
WriteString("Bar => ");
WriteString(Foo.Bar);
WriteLn;
WriteString("Bar => ");
WriteString(Bar);
WriteLn;
END test_foo.
At test program run time, Bar becomes an empty string, with the following
result:
Bar =>
Bar =>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/113889] Incorrect constant string value if declared in a definition module
2024-02-12 12:25 [Bug modula2/113889] New: Incorrect constant string value if declared in a definition module gaius at gcc dot gnu.org
@ 2024-02-12 12:26 ` gaius at gcc dot gnu.org
2024-02-18 1:26 ` gaius at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-12 12:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113889
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2024-02-12
Ever confirmed|0 |1
--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Indeed - observed and reproduced.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/113889] Incorrect constant string value if declared in a definition module
2024-02-12 12:25 [Bug modula2/113889] New: Incorrect constant string value if declared in a definition module 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
2024-02-19 13:03 ` gaius at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-18 1:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113889
--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 57453
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57453&action=edit
Proposed fix
Here is a proposed patch and associated testcases.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/113889] Incorrect constant string value if declared in a definition module
2024-02-12 12:25 [Bug modula2/113889] New: Incorrect constant string value if declared in a definition module 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
2024-02-19 13:03 ` gaius at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-19 13:02 UTC (permalink / raw)
To: gcc-bugs
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>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/113889] Incorrect constant string value if declared in a definition module
2024-02-12 12:25 [Bug modula2/113889] New: Incorrect constant string value if declared in a definition module gaius at gcc dot gnu.org
` (2 preceding siblings ...)
2024-02-19 13:02 ` cvs-commit at gcc dot gnu.org
@ 2024-02-19 13:03 ` gaius at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-19 13:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113889
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now the patch has been applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-19 13:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 12:25 [Bug modula2/113889] New: Incorrect constant string value if declared in a definition module 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
2024-02-19 13:03 ` gaius at gcc dot gnu.org
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).