gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

latest uninitialised variable analysis changes


From: Gaius Mulley
Subject: latest uninitialised variable analysis changes
Date: Thu, 20 Jul 2023 23:37:06 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Hello,

I've just pushed some changes on gcc git relating to
-Wuninit-variable-checking=all.  The gm2 static analysis option
-Wuninit-variable-checking (also enabled by -Wall) now understands
NEW/DISPOSE and NIL pointer tracking.  For example:

$ cat testnew6.mod
MODULE testnew6 ;

FROM Storage IMPORT ALLOCATE ;

TYPE
   PtrToVec = POINTER TO RECORD
                           x, y: INTEGER ;
                         END ;

PROCEDURE test ;
VAR
   p: PtrToVec ;
BEGIN
   NEW (p) ;
   WITH p^ DO
      x := 1 ;
      x := 2   (* Deliberate typo, user meant y.  *)
   END ;
   IF p^.y = 2
   THEN
   END
END test ;


BEGIN
   test
END testnew6.

$ gm2 -Wall testnew6.mod
testnew6.mod:19:9: warning: In procedure ‘test’: attempting to access 
expression before it has been initialized
   19 |    IF p^.y = 2
      |       ~~^~

$ cat testdispose3.mod
MODULE testdispose3 ;

FROM Storage IMPORT DEALLOCATE ;

TYPE
   PtrToVec = POINTER TO RECORD
                            x, y: INTEGER ;
                         END ;


PROCEDURE test (VAR ptr: PtrToVec) ;
BEGIN
   DISPOSE (ptr) ;
   IF ptr^.x = 1
   THEN
   END
END test ;


VAR
   p: PtrToVec ;
BEGIN
   test (p)
END testdispose3.

$ gm2 -Wall testdispose3.mod
testdispose3.mod:14:10: warning: In procedure ‘test’: attempting to access 
expression before it has been initialized
   14 |    IF ptr^.x = 1
      |          ^
testdispose3.mod:14:11: warning: attempting to access expression before it has 
been initialized
   14 |    IF ptr^.x = 1
      |       ~~~~^~
testdispose3.mod:14:11: warning: attempting to dereference expression
   which will be a NIL pointer
   
regards,
Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]