public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement
@ 2023-06-05 12:34 admin@tho-otto.de
2023-06-06 13:45 ` [Bug modula2/110125] " gaius at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: admin@tho-otto.de @ 2023-06-05 12:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
Bug ID: 110125
Summary: Variables are reported as uninitialized when only set
inside WITH statement
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: modula2
Assignee: gaius at gcc dot gnu.org
Reporter: admin@tho-otto.de
Target Milestone: ---
In the following fragment:
MODULE foo;
TYPE
Date = RECORD
day: INTEGER;
END;
PROCEDURE test(): Date;
VAR d: Date;
BEGIN
WITH d DO
day := 0;
END;
RETURN d;
END test;
END foo.
When compiling with
$ gm2 -c -O2 -Wall foo.mod
i get reports about d being uninitialized:
foo.mod:9:5: warning: In procedure ‘test’: variable ‘d’ is being used but it is
never initialized in procedure ‘test’
9 | VAR d: Date;
| ^
This does not happen when *not* using WITH, eg
MODULE foo;
TYPE
Date = RECORD
day: INTEGER;
END;
PROCEDURE test(): Date;
VAR d: Date;
BEGIN
d.day := 0;
RETURN d;
END test;
END foo.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
@ 2023-06-06 13:45 ` gaius at gcc dot gnu.org
2023-06-08 12:09 ` admin@tho-otto.de
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-06-06 13:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-06-06
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Yes indeed - will fix - thanks for the report.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
2023-06-06 13:45 ` [Bug modula2/110125] " gaius at gcc dot gnu.org
@ 2023-06-08 12:09 ` admin@tho-otto.de
2023-06-18 1:49 ` gaius at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: admin@tho-otto.de @ 2023-06-08 12:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
--- Comment #2 from Thorsten Otto <admin@tho-otto.de> ---
Maybe related to this:
MODULE foo;
TYPE Head = RECORD
magic: INTEGER;
END;
Carrier = RECORD
head: Head;
tail: Head;
END;
PROCEDURE test(VAR carrier: Carrier);
BEGIN
carrier.head.magic := 0;
carrier.tail.magic := 0;
END test;
VAR x: Carrier;
BEGIN
test(x);
END foo.
also gives warning about unused parameter "carrier" in function test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
2023-06-06 13:45 ` [Bug modula2/110125] " gaius at gcc dot gnu.org
2023-06-08 12:09 ` admin@tho-otto.de
@ 2023-06-18 1:49 ` gaius at gcc dot gnu.org
2023-07-02 20:42 ` gaius at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-06-18 1:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gaius at gcc dot gnu.org
--- Comment #3 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 55357
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55357&action=edit
Proposed fix
Thanks for the bug report - here is a work in progress patch.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
` (2 preceding siblings ...)
2023-06-18 1:49 ` gaius at gcc dot gnu.org
@ 2023-07-02 20:42 ` gaius at gcc dot gnu.org
2023-07-03 10:19 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-07-02 20:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #55357|0 |1
is obsolete| |
--- Comment #4 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 55454
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55454&action=edit
Proposed fix v5
Here is the latest patch which fixes the PR - I propose to commit the patch
(if/when) the bootstrap is successful.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
` (3 preceding siblings ...)
2023-07-02 20:42 ` gaius at gcc dot gnu.org
@ 2023-07-03 10:19 ` cvs-commit at gcc dot gnu.org
2023-07-03 10:28 ` gaius at gcc dot gnu.org
2023-07-30 1:20 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-03 10:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
--- Comment #5 from CVS 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:b0762d4c7e7894845e70e839c8513ae4c9e9d42e
commit r14-2263-gb0762d4c7e7894845e70e839c8513ae4c9e9d42e
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Mon Jul 3 11:18:20 2023 +0100
PR modula2/110125 variables reported as uninitialized when set inside WITH
The modula-2 static analysis incorrectly identifies variables as
uninitialized if they are initialized within a WITH statement. This bug
fix re-implements the variable static analysis and will detect simple
pointer record fields being accessed before being initialized.
The static analysis is limited to the first basic block in a procedure.
It does not check variant records, arrays or sets. A new option
-Wuninit-variable-checking will turn on the new semantic checking
(-Wall also enables the new checking).
gcc/ChangeLog:
PR modula2/110125
* doc/gm2.texi (Semantic checking): Include examples using
-Wuninit-variable-checking.
gcc/m2/ChangeLog:
PR modula2/110125
* Make-lang.in (GM2-COMP-BOOT-DEFS): Add M2SymInit.def.
(GM2-COMP-BOOT-MODS): Add M2SymInit.mod.
* gm2-compiler/M2BasicBlock.mod: Formatting changes.
* gm2-compiler/M2Code.mod: Remove import of VariableAnalysis from
M2Quads. Import VariableAnalysis from M2SymInit.mod.
* gm2-compiler/M2GCCDeclare.mod (PrintVerboseFromList):
Add debugging print for a component.
(TypeConstFullyDeclared): Call RememberType for every type.
* gm2-compiler/M2GenGCC.mod (CodeReturnValue): Add parameter to
GetQuadOtok.
(CodeBecomes): Add parameter to GetQuadOtok.
(CodeXIndr): Add parameter to GetQuadOtok.
* gm2-compiler/M2Optimize.mod (ReduceBranch): Reformat and
preserve operand token positions when reducing the branch
quadruples.
(ReduceGoto): Reformat.
(FoldMultipleGoto): Reformat.
(KnownReachable): Reformat.
* gm2-compiler/M2Options.def (UninitVariableChecking): New
variable declared and exported.
(SetUninitVariableChecking): New procedure.
* gm2-compiler/M2Options.mod (SetWall): Set
UninitVariableChecking.
(SetUninitVariableChecking): New procedure.
* gm2-compiler/M2Quads.def (PutQuadOtok): Exported and declared.
(VariableAnalysis): Removed.
* gm2-compiler/M2Quads.mod (PutQuadOtok): New procedure.
(doVal): Reformatted.
(MarkAsWrite): Reformatted.
(MarkArrayAsWritten): Reformatted.
(doIndrX): Use PutQuadOtok.
(MakeRightValue): Use GenQuadOtok.
(MakeLeftValue): Use GenQuadOtok.
(CheckReadBeforeInitialized): Remove.
(IsNeverAltered): Reformat.
(DebugLocation): New procedure.
(BuildDesignatorPointer): Use GenQuadO to preserve operand token
position.
(BuildRelOp): Use GenQuadOtok ditto.
* gm2-compiler/SymbolTable.def (VarCheckReadInit): New procedure.
(VarInitState): New procedure.
(PutVarInitialized): New procedure.
(PutVarFieldInitialized): New procedure function.
(GetVarFieldInitialized): New procedure function.
(PrintInitialized): New procedure.
* gm2-compiler/SymbolTable.mod (VarCheckReadInit): New procedure.
(VarInitState): New procedure.
(PutVarInitialized): New procedure.
(PutVarFieldInitialized): New procedure function.
(GetVarFieldInitialized): New procedure function.
(PrintInitialized): New procedure.
(LRInitDesc): New type.
(SymVar): InitState new field.
(MakeVar): Initialize InitState.
* gm2-gcc/m2options.h (M2Options_SetUninitVariableChecking):
New function declaration.
* gm2-lang.cc (gm2_langhook_handle_option): Detect
OPT_Wuninit_variable_checking and call SetUninitVariableChecking.
* lang.opt: Add Wuninit-variable-checking.
* gm2-compiler/M2SymInit.def: New file.
* gm2-compiler/M2SymInit.mod: New file.
gcc/testsuite/ChangeLog:
PR modula2/110125
* gm2/switches/uninit-variable-checking/fail/testinit.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testlarge.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testlarge2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testrecinit.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testrecinit2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testrecinit5.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testsmallrec.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testsmallrec2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testsmallvec.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testvarinit.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithnoptr.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithptr.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithptr2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithptr3.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testrecinit3.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testrecinit5.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testsmallrec.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testsmallrec2.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testvarinit.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testwithptr.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testwithptr2.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testwithptr3.mod: New
test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
` (4 preceding siblings ...)
2023-07-03 10:19 ` cvs-commit at gcc dot gnu.org
@ 2023-07-03 10:28 ` gaius at gcc dot gnu.org
2023-07-30 1:20 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-07-03 10:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #6 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing as patch has been applied.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug modula2/110125] Variables are reported as uninitialized when only set inside WITH statement
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
` (5 preceding siblings ...)
2023-07-03 10:28 ` gaius at gcc dot gnu.org
@ 2023-07-30 1:20 ` cvs-commit at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-30 1:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110125
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Gaius Mulley
<gaius@gcc.gnu.org>:
https://gcc.gnu.org/g:3fd979bf568d91016b797818e6c9c940b6f389bd
commit r13-7650-g3fd979bf568d91016b797818e6c9c940b6f389bd
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Sun Jul 30 02:18:57 2023 +0100
PR modula2/110125 variables reported as uninitialized when set inside WITH
The modula-2 static analysis incorrectly identifies variables as
uninitialized if they are initialized within a WITH statement. This bug
fix re-implements the variable static analysis and will detect simple
pointer record fields being accessed before being initialized.
The static analysis is limited to the first basic block in a procedure.
It does not check variant records, arrays or sets. A new option
-Wuninit-variable-checking will turn on the new semantic checking
(-Wall also enables the new checking).
gcc/ChangeLog:
PR modula2/110125
* doc/gm2.texi (Semantic checking): Include examples using
-Wuninit-variable-checking.
gcc/m2/ChangeLog:
PR modula2/110125
* Make-lang.in (GM2-COMP-BOOT-DEFS): Add M2SymInit.def.
(GM2-COMP-BOOT-MODS): Add M2SymInit.mod.
* gm2-compiler/M2BasicBlock.mod: Formatting changes.
* gm2-compiler/M2Code.mod: Remove import of VariableAnalysis from
M2Quads. Import VariableAnalysis from M2SymInit.mod.
* gm2-compiler/M2GCCDeclare.mod (PrintVerboseFromList):
Add debugging print for a component.
(TypeConstFullyDeclared): Call RememberType for every type.
* gm2-compiler/M2GenGCC.mod (CodeReturnValue): Add parameter to
GetQuadOtok.
(CodeBecomes): Add parameter to GetQuadOtok.
(CodeXIndr): Add parameter to GetQuadOtok.
* gm2-compiler/M2Optimize.mod (ReduceBranch): Reformat and
preserve operand token positions when reducing the branch
quadruples.
(ReduceGoto): Reformat.
(FoldMultipleGoto): Reformat.
(KnownReachable): Reformat.
* gm2-compiler/M2Options.def (UninitVariableChecking): New
variable declared and exported.
(SetUninitVariableChecking): New procedure.
* gm2-compiler/M2Options.mod (SetWall): Set
UninitVariableChecking.
(SetUninitVariableChecking): New procedure.
* gm2-compiler/M2Quads.def (PutQuadOtok): Exported and declared.
(VariableAnalysis): Removed.
* gm2-compiler/M2Quads.mod (PutQuadOtok): New procedure.
(doVal): Reformatted.
(MarkAsWrite): Reformatted.
(MarkArrayAsWritten): Reformatted.
(doIndrX): Use PutQuadOtok.
(MakeRightValue): Use GenQuadOtok.
(MakeLeftValue): Use GenQuadOtok.
(CheckReadBeforeInitialized): Remove.
(IsNeverAltered): Reformat.
(DebugLocation): New procedure.
(BuildDesignatorPointer): Use GenQuadO to preserve operand token
position.
(BuildRelOp): Use GenQuadOtok ditto.
* gm2-compiler/SymbolTable.def (VarCheckReadInit): New procedure.
(VarInitState): New procedure.
(PutVarInitialized): New procedure.
(PutVarFieldInitialized): New procedure function.
(GetVarFieldInitialized): New procedure function.
(PrintInitialized): New procedure.
* gm2-compiler/SymbolTable.mod (VarCheckReadInit): New procedure.
(VarInitState): New procedure.
(PutVarInitialized): New procedure.
(PutVarFieldInitialized): New procedure function.
(GetVarFieldInitialized): New procedure function.
(PrintInitialized): New procedure.
(LRInitDesc): New type.
(SymVar): InitState new field.
(MakeVar): Initialize InitState.
* gm2-gcc/m2options.h (M2Options_SetUninitVariableChecking):
New function declaration.
* gm2-lang.cc (gm2_langhook_handle_option): Detect
OPT_Wuninit_variable_checking and call SetUninitVariableChecking.
* lang.opt: Add Wuninit-variable-checking.
* gm2-compiler/M2SymInit.def: New file.
* gm2-compiler/M2SymInit.mod: New file.
gcc/testsuite/ChangeLog:
PR modula2/110125
* gm2/switches/uninit-variable-checking/fail/testinit.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testlarge.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testlarge2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testrecinit.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testrecinit2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testrecinit5.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testsmallrec.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testsmallrec2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testsmallvec.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testvarinit.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithnoptr.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithptr.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithptr2.mod: New
test.
* gm2/switches/uninit-variable-checking/fail/testwithptr3.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testrecinit3.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testrecinit5.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testsmallrec.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testsmallrec2.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testvarinit.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testwithptr.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testwithptr2.mod: New
test.
* gm2/switches/uninit-variable-checking/pass/testwithptr3.mod: New
test.
(cherry picked from commit b0762d4c7e7894845e70e839c8513ae4c9e9d42e)
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-07-30 1:20 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 12:34 [Bug modula2/110125] New: Variables are reported as uninitialized when only set inside WITH statement admin@tho-otto.de
2023-06-06 13:45 ` [Bug modula2/110125] " gaius at gcc dot gnu.org
2023-06-08 12:09 ` admin@tho-otto.de
2023-06-18 1:49 ` gaius at gcc dot gnu.org
2023-07-02 20:42 ` gaius at gcc dot gnu.org
2023-07-03 10:19 ` cvs-commit at gcc dot gnu.org
2023-07-03 10:28 ` gaius at gcc dot gnu.org
2023-07-30 1:20 ` cvs-commit 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).