<br><br><div class="gmail_quote">On Tue, Mar 10, 2009 at 5:54 AM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Mar 9, 2009, at 2:41 AM, Zhongxing Xu wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Ted,<br>
<br>
This patch report false warning on this test case:<br>
<br>
#include <sys/socket.h><br>
void f(int sock) {<br>
  struct sockaddr_storage storage;<br>
  struct sockaddr* sockaddr = (struct sockaddr*)&storage;<br>
  socklen_t addrlen = sizeof(storage);<br>
  getsockname(sock, sockaddr, &addrlen);<br>
  switch (sockaddr->sa_family) {<br>
  default:<br>
    ;<br>
  }<br>
}<br>
<br>
$ clang -analyze -analyzer-store=region -checker-cfref 1.c<br>
1.c:7:3: warning: Branch condition evaluates to an uninitialized value.<br>
  switch (sockaddr->sa_family) {<br>
  ^       ~~~~~~~~~~~~~~~~~~~<br>
1 diagnostic generated.<br>
<br>
Perhaps we should not 'blast through' TypedViewRegion?<br>
</blockquote>
<br></div>
The motivation for ignoring the TypedViewRegions has to do with typedefs.  Conceptually we want to handle bindings through typedefs and the desugared type as the same:<br>
<br>
typedef struct s* MyPointer;<br>
<br>
MyPointer *p = foo();<br>
p->f = ...<br>
struct s* q = p;<br>
... = q->f;<br>
<br>
Here 'p' will bind to a TypedViewRegion that wraps a SymbolicRegion.<br>
<br>
Depending on the return type of foo() (i.e., if it is 'void*' or 'struct s*') then 'q' should bind either to a TypedViewRegion or a SymbolicRegion with type 'struct s*'.<br>
<br>
In this case, we should be reasoning about the same locations for 'q->f' and 'p->f'.<br>
<br>
I admit that this work should probably happen in RegionStore.  Indeed, all invalidation of values should probably go directly through the StoreManager at some point.<br>
<br>
The issue here is that some type views are "sugar" and others change the nature of the binding (e.g., layerind "struct s*' on top of 'void*').<br>
<br>
Perhaps we can add a "SugarTypedRegion" (or something with a better name) to represent region views that are just sugar but don't change the semantics?  This could be useful for RegionStore to help canonicalize the names of locations.  Alternatively, the StoreManager can implement a method called "getCanonicalRegion()" to to transform a MemRegion* into its canonical version that is used for binding values.<br>

</blockquote></div><br>Hi Ted,<br><br>We don't have any casts for this example. So why would p and q point to different region?<br><br>typedef struct s* MyPointer;<br><br>struct s* foo();<br><br>void bar() {<br>  MyPointer p = foo();<br>
  struct s* q = p;<br>}<br><br>$ clang -ast-dump 1.c<br>(CompoundStmt 0x986bba8 <1.c:5:12, line:11:1><br>  (DeclStmt 0x986cc98 <line:7:3><br>    0x986c878 "MyPointer p =<br>      (CallExpr 0x986cc78 <col:17, col:21> 'struct s *'<br>
        (ImplicitCastExpr 0x986cc58 <col:17> 'struct s *(*)()'<br>          (DeclRefExpr 0x986cc20 <col:17> 'struct s *()' FunctionDecl='foo' 0x986c830)))"<br>  (DeclStmt 0x986cd00 <line:9:3><br>
    0x986ccb0 "struct s *q =<br>      (DeclRefExpr 0x986cce0 <col:17> 'MyPointer':'struct s *' Var='p' 0x986c878)")<br><br><br>