|Null pointer analysis in C firstname.lastname@example.org (2008-01-20)|
|Null pointer analysis in C email@example.com (Naseer) (2008-02-24)|
|Re: Null pointer analysis in C firstname.lastname@example.org (Diego Novillo) (2008-02-24)|
|Re: Null pointer analysis in C email@example.com (2008-02-25)|
|From:||"Diego Novillo" <firstname.lastname@example.org>|
|Date:||Sun, 24 Feb 2008 12:43:41 -0500|
|Posted-Date:||24 Feb 2008 12:52:24 EST|
On Sun, Feb 24, 2008 at 12:04 PM, Naseer <email@example.com> wrote:
> What are the issues/problems of Null pointer in C and how they can be
> resolved "statically". i.e. while doing static analysis(compile time)
> how can we find whether a pointer is null or not.
During constant and value-range propagation, the compiler can infer
non-NULL values for a pointer. For instance
*ptr = 4;
If the compiler knows that dereferencing a NULL pointer causes the
program to halt with an exception, the if (ptr) will always succeed,
so it can be folded away. In GCC this is performed by the value-range
propagation pass (in gcc/tree-vrp.c if you download the GCC sources).
Another opportunity during constant propagation, happens with code of
ptr = &var;
*ptr = 3;
Assuming that 'var' is a local variable, constant propagation can do
two things here: (1) propagate the value &var to all the uses of
'ptr', (2) realize that 'if (&var)' is always true (since addresses of
local variables are always at an address different than 0).
This has other consequences for variable 'var', since the compiler can
now determine that its address has not been taken, which usually opens
more optimization opportunities for 'var'.
[The general problem of telling when a pointer will have a null value
is intractable, but there are certainly lots of useful subcases that
a compiler can catch with dataflow analysis. -John]
Return to the
Search the comp.compilers archives again.