[cfe-commits] [patch] Qualifiers refactor

John McCall rjmccall at apple.com
Wed Sep 23 02:04:54 PDT 2009


The attached patch refactors how qualifiers are represented in clang.

Currently, QualType uses the bottom three bits of a type pointer to 
represent the const, volatile, and restrict qualifiers.  Extended 
qualifiers are represented using an ExtQualType object, which is an 
ordinary node in the type hierarchy --- except that it isn't.  Most 
common operations on types have to explicitly check for these special 
qualifier nodes and handle them differently.

This patch changes QualType to store only two qualifiers directly on the 
pointer;  the third bit is repurposed to signal whether the pointer is a 
Type or an ExtQuals object (which holds, but is not, a Type).  This 
makes it very cheap to decide whether a type carries any qualifiers, as 
well as to compute the unqualified version of a type.

Because there are only two remaining bits, it's necessary to store 
'volatile' on the ExtQuals object, 'const' being ubiquitous and 
'restrict' being common in certain system headers.  This could be 
avoided by using 16-byte alignment on Types, which would be extremely 
straightforward to do under the patch (modulo any possible required 
changes to the allocator, which I haven't investigated).

This patch also audits many of the uses of qualifiers in clang, 
adjusting them to handle arbitrary qualifiers (or be augmentable for 
future qualifiers) when that was reasonably straightforward.

John.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.diff.txt
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090923/23348a5b/attachment.txt>


More information about the cfe-commits mailing list