]> gcc.gnu.org Git - gcc.git/commit
[modula2] Variable analysis understands DISPOSE and NIL
authorGaius Mulley <gaiusmod2@gmail.com>
Wed, 19 Jul 2023 12:38:07 +0000 (13:38 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Wed, 19 Jul 2023 12:38:07 +0000 (13:38 +0100)
commite029635cb72e6db72f1826b6b43fa4b299b2145f
tree6ac2d8c6c638bd457c94e9ae179d52f91693f812
parentfcb38196423cd5f99a7ee44c882751b3dd37618d
[modula2] Variable analysis understands DISPOSE and NIL

This patch allows the uninitialized variable analysis to detect pointer
through NIL and incorrectly reusing a pointer after a call to DISPOSE.

gcc/m2/ChangeLog:

* gm2-compiler/M2Quads.mod (BuildRealFuncProcCall): Set the trash
parameter value to NIL if DEALLOCATE is detected.
* gm2-compiler/M2SymInit.mod (CheckDeferredRecordAccess): Pass
tok to SetVarInitialized.  Pass tok to GetVarComponentInitialized.
(ComponentFindVar): Add tok parameter.  Check aliased pointer
against Nil and generate warning if necessary.
(deRefComponent): Add tok and sym parameters and pass them to
getContent.
(SetVarComponentInitialized): Add tok parameter.  Pass tok to
ComponentFindVar.  Pass tok and sym to deRefComponent.
(GetVarComponentInitialized): Add tok parameter.  Pass tok to
ComponentFindVar.  Pass tok to deRefComponent.
(SetVarInitialized): Add tok parameter.  Pass tok to
SetVarComponentInitialized.
(doGetVarInitialized): Add tok parameter.  Pass tok to
GetVarComponentInitialized.
(CheckXIndr): Pass lhs and lhstok to getContent.
(CheckIndrX): Pass rhs and rhstok to getContent.
(CheckBecomes): Pass destok to ComponentFindVar.  Pass des and
destok to deRefComponent.
(CheckAddr): Pass contenttok to GetVarInitialized.  Pass ptrtok
to SetVarInitialized.
(CheckReadBeforeInitQuad): Pass op1tok to SetVarInitialized for
op1 cases and op3tok for op3 cases.
(trashParam): Get operand tokens.  Pass op3tok to
SetVarInitialized.  Pass op3 and op3tok to getContent.
Alias ptr to NIL if procedure is DEALLOCATE.  Pass op3tok to
SetVarInitialized.
(IsDeallocate): New procedure function.
(DetectTrash): Use IsDeallocate.
(SetupLAlias): Allow exp to be Nil.
(getContent): Generate warning message if ptr is Nil.

gcc/testsuite/ChangeLog:

* gm2/switches/uninit-variable-checking/procedures/fail/testdispose.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testdispose2.mod: New test.
* gm2/switches/uninit-variable-checking/procedures/fail/testnil.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-compiler/M2Quads.mod
gcc/m2/gm2-compiler/M2SymInit.mod
gcc/testsuite/gm2/switches/uninit-variable-checking/procedures/fail/testdispose.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/procedures/fail/testdispose2.mod [new file with mode: 0644]
gcc/testsuite/gm2/switches/uninit-variable-checking/procedures/fail/testnil.mod [new file with mode: 0644]
This page took 0.063203 seconds and 5 git commands to generate.