aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2023-07-18 16:31:49 +0100
committerGaius Mulley <gaiusmod2@gmail.com>2023-07-18 16:31:49 +0100
commitb80e3c468e373cc6fd4e41a5879dbca95a40ac8c (patch)
treea0f4d0da67f82ad968eb2fae01526b4f1fdb58cb /gcc/doc
parentcbe5f6859a73b2acf203bd7d13f9fb245d63cbd4 (diff)
downloadgcc-b80e3c468e373cc6fd4e41a5879dbca95a40ac8c.zip
gcc-b80e3c468e373cc6fd4e41a5879dbca95a40ac8c.tar.gz
gcc-b80e3c468e373cc6fd4e41a5879dbca95a40ac8c.tar.bz2
[modula2] Uninitialized variable static analysis improvements
This patch fixes many limitations of the uninitialized static analysis. NEW is understood, local variable pointers and non var parameters will be tracked. gcc/ChangeLog: * doc/gm2.texi (Semantic checking): Change example testwithptr to testnew6. gcc/m2/ChangeLog: * Make-lang.in: Minor formatting change. * gm2-compiler/M2GCCDeclare.mod (DeclareUnboundedProcedureParameters): Rename local variables. (WalkUnboundedProcedureParameters): Rename local variables. (DoVariableDeclaration): Avoid declaration of a variable if it is on the heap (used by static analysis only). * gm2-compiler/M2GenGCC.mod: Formatting. * gm2-compiler/M2Quads.def (GetQuadTrash): New procedure function. * gm2-compiler/M2Quads.mod (GetQuadTrash): New procedure function. (QuadFrame): Add Trash field. (BuildRealFuncProcCall): Detect ALLOCATE and DEALLOCATE and create a heap variable for parameter 1 saving it as the trashed variable for static analysis. (GenQuadOTrash): New procedure. (DisplayQuadRange): Bugfix. Write the scope number. * gm2-compiler/M2SymInit.mod: Rewritten to separate LValue equivalence from LValue to RValue pairings. Comprehensive detection of variant record implemented. Allow dereferencing of pointers through LValue/RValue chains. * gm2-compiler/SymbolTable.def (PutVarHeap): New procedure. (IsVarHeap): New procedure function. (ForeachParamSymDo): New procedure. * gm2-compiler/SymbolTable.mod (PutVarHeap): New procedure. (IsVarHeap): New procedure function. (ForeachParamSymDo): New procedure. (MakeVariableForParam): Reformatted. (CheckForUnknownInModule): Reformatted. (SymVar): Add field Heap. (MakeVar): Assign Heap to FALSE. gcc/testsuite/ChangeLog: * gm2/switches/uninit-variable-checking/pass/assignparam.mod: New test. * gm2/switches/uninit-variable-checking/pass/tiny.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/switches-uninit-variable-checking-procedures-fail.exp: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testnew.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testnew2.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testnew3.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testnew4.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testnew5.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testnew6.mod: New test. * gm2/switches/uninit-variable-checking/procedures/fail/testptrptr.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/assignparam2.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/switches-uninit-variable-checking-procedures-pass.exp: New test. * gm2/switches/uninit-variable-checking/procedures/pass/testnew5.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/testnew6.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/testparamlvalue.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/testparamrvalue.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/testproc.mod: New test. * gm2/switches/uninit-variable-checking/procedures/pass/testptrptr.mod: New test. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/gm2.texi25
1 files changed, 12 insertions, 13 deletions
diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index 8d5d95f..9f7f8ce 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -1471,7 +1471,7 @@ plugin is invoked.
The @samp{-Wuninit-variable-checking} can be used to identify
uninitialized variables within the first basic block in a procedure.
The checking is limited to variables so long as they are
-not an array or set or a variant record.
+not an array or set or a variant record or var parameter.
The following example detects whether a sub component within a record
is uninitialized.
@@ -1551,22 +1551,20 @@ access expression before it has been initialized
@end example
@example
-MODULE testwithptr ;
+MODULE testnew6 ;
-FROM SYSTEM IMPORT ADR ;
+FROM Storage IMPORT ALLOCATE ;
TYPE
- PtrToVec = POINTER TO Vec ;
- Vec = RECORD
- x, y: CARDINAL ;
- END ;
+ PtrToVec = POINTER TO RECORD
+ x, y: INTEGER ;
+ END ;
PROCEDURE test ;
VAR
p: PtrToVec ;
- v: Vec ;
BEGIN
- p := ADR (v) ;
+ NEW (p) ;
WITH p^ DO
x := 1 ;
x := 2 (* Deliberate typo, user meant y. *)
@@ -1576,16 +1574,17 @@ BEGIN
END
END test ;
+
BEGIN
test
-END testwithptr.
+END testnew6.
@end example
@example
-gm2 -c -Wuninit-variable-checking testwithptr.mod
-testwithptr.mod:26:9: warning: In procedure ‘test’: attempting to
+$ gm2 -g -c -Wuninit-variable-checking testnew6.mod
+testnew6.mod:19:9: warning: In procedure ‘test’: attempting to
access expression before it has been initialized
- 26 | IF p^.y = 2
+ 19 | IF p^.y = 2
| ~~^~
@end example