Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers > Re: Null pointe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 2340 of 2534
Post > Topic >>

Re: Null pointer analysis in C

by "Diego Novillo" <dnovillo@[EMAIL PROTECTED] > Feb 24, 2008 at 12:43 PM

On Sun, Feb 24, 2008 at 12:04 PM, Naseer <naseer.naseer@[EMAIL PROTECTED]
> 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 (ptr)
   ....

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 op****tunity during constant propagation, happens with code of
the form:

ptr = &var;
if (ptr)
  *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 op****tunities for 'var'.

Diego.
[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]
 




 3 Posts in Topic:
Null pointer analysis in C
Naseer <naseer.naseer@  2008-02-24 09:04:56 
Re: Null pointer analysis in C
"Diego Novillo"  2008-02-24 12:43:41 
Re: Null pointer analysis in C
torbenm@[EMAIL PROTECTED]  2008-02-25 11:48:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:29:56 CDT 2008.