[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
static analysis within gm2 for variables
From: |
Gaius Mulley |
Subject: |
static analysis within gm2 for variables |
Date: |
Mon, 03 Jul 2023 14:09:32 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
Hello,
I've just pushed some changes into the gcc repro which fixes PR-110125.
(Variables are reported as uninitialized when only set inside WITH
statement).
A new switch is available -Wuninit-variable-checking (or -Wall).
There are a number of new test cases in the regression testsuite
(under gcc/testsuite/gm2/switches/uninit-variable-checking)
and one of the more interesting is shown below:
module testwithptr ;
from SYSTEM import adr ;
type
PtrToVec = pointer to Vec ;
Vec = record
x, y: cardinal ;
end ;
procedure test ;
var
p: PtrToVec ;
v: Vec ;
begin
p := adr (v) ;
with p^ do
x := 1 ;
x := 2 (* Deliberate typo - should be y. *)
end ;
if p^.y = 2
then
end
end test ;
begin
test
end testwithptr.
where gm2 will now report:
$ gm2 -Wall testwithptr.mod
testwithptr.mod:26:9: warning: In procedure ‘test’: attempting to access
expression before it has been initialized
26 | IF p^.y = 2
| ~~^~
Here is a small video describing the failure cases in the testsuite:
https://www.youtube.com/watch?v=0AxI8Iv40iU
as a by product to the fix, token accuracy has been improved for pointer
sub-expressions (and with expressions).
Limitations
===========
The variable static analysis is rather limited at present as it:
(i) works with scalar variables or record typed variable providing
they have no variant components.
(ii) assumes all parameters are fully initialized.
(iii) does not check array/set types.
(iv) only considers the first basic block in a procedure
It would be reasonably straightforward to include two user attributes
one to tell the compiler a variable is uninitialized.
Secondly another attribute to assert that all fields should be
initialized. It should also be possible to check subsequent basic
blocks providing they were not in any loop.
Hope this is useful,
regards,
Gaius
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- static analysis within gm2 for variables,
Gaius Mulley <=