[cfe-dev] Reference counting

Chris Lattner clattner at apple.com
Thu Jan 21 11:37:04 PST 2010


On Jan 21, 2010, at 8:10 AM, Jochen Wilhelmy wrote:

> Hi!
>
> when developing with clang/llvm I have quite a mess with
> pointers, references, llvm::OwningPtr and get()
>
> My suggestion would be (which won't get accepted due to the huge
> code base) to have a llvm::Object that has a reference counter and
> then a llvm::Pointer that increments/decrements the ref-count inside
> the object.
> Then for every class there has to be decided if it derives from  
> Object and
> always allocated with new and always passed as Pointer<>
> or a struct and never allocated with new.
>
> I use this scheme quite long now and never have problems except ring
> references in complex graphs which have to be broken manually.

The major reason we don't use reference counting in clang the clang  
AST (or llvm IR) is that it is a) expensive, and b) we have (or aim to  
have) very simple ownership policies that make it unnecessary.  For  
other heavier objects (e.g. ASTContext itself), it might make sense  
though.

-Chris



More information about the cfe-dev mailing list