]> gcc.gnu.org Git - gcc.git/commit
PR modula2/110125 variables reported as uninitialized when set inside WITH
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 3 Jul 2023 10:18:20 +0000 (11:18 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 3 Jul 2023 10:18:20 +0000 (11:18 +0100)
commitb0762d4c7e7894845e70e839c8513ae4c9e9d42e
treebdff23cd62678c7079701d171819ac5507c0cf33
parent49485639c25c77b116d35c2f9c3dbfb8bf4cf814
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>
42 files changed:
gcc/doc/gm2.texi
gcc/m2/Make-lang.in
gcc/m2/gm2-compiler/M2BasicBlock.mod
gcc/m2/gm2-compiler/M2Code.mod
gcc/m2/gm2-compiler/M2GCCDeclare.mod
gcc/m2/gm2-compiler/M2GenGCC.mod
gcc/m2/gm2-compiler/M2Optimize.mod
gcc/m2/gm2-compiler/M2Options.def
gcc/m2/gm2-compiler/M2Options.mod
gcc/m2/gm2-compiler/M2Quads.def
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-compiler/M2SymInit.def [new file with mode: 0644]
gcc/m2/gm2-compiler/M2SymInit.mod [new file with mode: 0644]
gcc/m2/gm2-compiler/SymbolTable.def
gcc/m2/gm2-compiler/SymbolTable.mod
gcc/m2/gm2-gcc/m2options.h
gcc/m2/gm2-lang.cc
gcc/m2/lang.opt
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/switches-uninit-variable-checking-fail.exp [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testinit.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testlarge.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testlarge2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testrecinit.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testrecinit2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testrecinit5.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testsmallrec.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testsmallrec2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testsmallvec.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testvarinit.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testwithnoptr.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testwithptr.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testwithptr2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/fail/testwithptr3.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/switches-uninit-variable-checking-pass.exp [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testrecinit3.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testrecinit5.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testsmallrec.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testsmallrec2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testvarinit.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testwithptr.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testwithptr2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/pass/testwithptr3.mod [new file with mode: 0644]
This page took 0.064172 seconds and 5 git commands to generate.