[cfe-dev] SymbolRef and SVal confusion

Richard tarka.t.otter at googlemail.com
Thu Jan 3 10:03:18 PST 2013


I had a quick attempt at this, by creating a SymbolExtent of a weak function decl code region and creating a SymbolicRegion with that. This actually fixes the checker I was writing, which is nice. I am not sure if I understand fully the implications of doing this however. Where does the SymbolicRegion need to be constrained back to a FunctionTextRegion?

Index: Core/SValBuilder.cpp
===================================================================
--- Core/SValBuilder.cpp	(revision 171384)
+++ Core/SValBuilder.cpp	(working copy)
@@ -190,7 +190,13 @@
 }
 
 DefinedSVal SValBuilder::getFunctionPointer(const FunctionDecl *func) {
-  return loc::MemRegionVal(MemMgr.getFunctionTextRegion(func));
+  const FunctionTextRegion *Region = MemMgr.getFunctionTextRegion(func);
+  if (func->isWeak()) {
+    const SymbolExtent *Sym = SymMgr.getExtentSymbol(Region);
+    return loc::MemRegionVal(MemMgr.getSymbolicRegion(Sym));
+  }
+    
+  return loc::MemRegionVal(Region);
 }
 
 DefinedSVal SValBuilder::getBlockPointer(const BlockDecl *block,

On 20 Dec 2012, at 19:31, Ted Kremenek <kremenek at apple.com> wrote:

> On Dec 20, 2012, at 10:14 AM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
>> The problem is that functions are represented by FunctionTextRegions. As you noticed, our design is that only SymbolicRegions can represent NULL—all other regions are known to have an address. However, this is not true for weak symbols (functions or otherwise). In order to get this right, we probably need to enhance the analyzer to treat weak extern symbols like references, and then automatically dereference them upon use.
> 
> I don't think the "references" analogy is quite right.  Functions are already modeled in the AST using function pointers, and they are dereferenced during a function call.  We could possibly model weak-linked functions using SymbolicRegions, that are then later constrained to alias a specific FunctionTextRegion.  Aliasing is something we need to handle better anyway, and I think this would nicely fit into that model.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130103/62736d38/attachment.html>


More information about the cfe-dev mailing list