<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=koi8-r">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Run <span style="text-decoration:none solid rgb(0,0,0); color:rgb(0,0,0); background-color:rgb(190,190,190)"><span style="text-decoration:none solid rgb(0,0,0); color:rgb(0,0,0); background-color:rgb(190,190,190)"><span style="text-decoration:none solid rgb(0,0,0); color:rgb(0,0,0); background-color:rgb(190,190,190)"><span style="text-decoration:none solid rgb(255,255,255); color:rgb(0,0,0); background-color:rgb(190,190,190)"><span style="color:rgb(0,0,0); text-decoration:none solid rgb(0,0,0); background-color:rgb(190,190,190)"><span style="background-color:rgb(190,190,190)">clang
 --analyze</span></span></span></span></span></span> on these two code snippets:<br>
</p>
<p><strong>global ptr:</strong></p>
<blockquote style="margin:0 0 0 40px; border:none; padding:0px">
<div><span style="font-size:16px; background-color:rgb(255,255,255); font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">int *x = 0;</span></span></div>
<div><span style="font-size:12pt; font-family:Consolas,monospace"><span style="font-family:Consolas,monospace">void foo() {</span></span></div>
<div><span style="font-family:Consolas,monospace">  int y = *x;</span></div>
<div><span style="font-family:Consolas,monospace">}</span></div>
</blockquote>
<div><strong>local </strong><strong style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px; background-color:rgb(255,255,255)">ptr:</strong></div>
<blockquote style="margin:0 0 0 40px; border:none; padding:0px">
<div>
<div style="font-size:16px"><span style="font-family:Consolas,monospace">void foo() {</span></div>
</div>
<div>
<div style="font-size:16px"><span style="font-family:Consolas,monospace">  int *x = 0;</span></div>
</div>
<div>
<div style="font-size:16px"><span style="font-family:Consolas,monospace">  int y = *x;</span></div>
</div>
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px"><span style="font-family:Consolas,monospace">}</span></div>
</div>
</blockquote>
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px"><span style="font-family:Consolas,monospace"><span style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px; background-color:rgb(255,255,255)">I met a </span><span style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px; background-color:rgb(255,255,255)">weird
 result.</span><span style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px; background-color:rgb(255,255,255)">​ </span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px"><span style="font-family:Consolas,monospace"><span style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px; background-color:rgb(255,255,255)"></span></span>The <strong>global
</strong>version does not generate a <span style="text-decoration:underline">warning</span> like the
<strong>local </strong>one does?<br>
</div>
</div>
<blockquote style="margin:0 0 0 40px; border:none; padding:0px">
<div>
<div style="font-size:16px"><span style="font-family:Consolas,monospace; background-color:rgb(190,190,190)"><span style="background-color:rgb(190,190,190)">test.cpp:3:11: warning: Dereference of null pointer (loaded from variable 'x') [core.NullDereference]</span></span></div>
</div>
</blockquote>
<span style="background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif"><span style="background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif"><span style="font-family:Calibri,Arial,Helvetica,sans-serif">​Another
 observation is that for the global verion analyzer does not handle init expression <em>(int *x = 0;)</em>, but for the local one it does. Therefore it stores <strong>x</strong> as <strong>&SymRegion{reg_$0<int * x>}</strong> for the global and
<strong>0</strong> for the local.</span></span></span>
<div><br>
</div>
<div><span style="background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif"><span style="background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif"><span style="font-family:Calibri,Arial,Helvetica,sans-serif"></span></span></span>Example graphs
 attached.
<div>
<div style="font-size:16px"><span style="font-family:Calibri,Arial,Helvetica,sans-serif"><span style="font-family:Calibri,Arial,Helvetica,sans-serif"><br>
</span></span></div>
<div style="font-size:16px"><span style="font-family:Calibri,Arial,Helvetica,sans-serif"><span style="font-family:Calibri,Arial,Helvetica,sans-serif">Who can explain why it is so?</span></span></div>
</div>
<p>​<br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<hr>
<div><b>Denys Petrov</b></div>
<div>Senior ó++ Developer | Kharkiv, Ukraine</div>
<div><br>
</div>
<div></div>
</div>
</div>
</div>
</body>
</html>