[cfe-dev] Adding a new type qualifier
John McCall
rjmccall at apple.com
Mon May 10 13:28:50 PDT 2010
On May 10, 2010, at 11:50 AM, kalyan ponnala wrote:
> I am trying to add a new qualifier to the existing clang architecture. So far I was looking into replacing one of the existing qualifiers "volatile or restrict" from the "fast qualifiers". Now I think its a bad idea to do that. Can someone tell me
>
> >> whats the best way to add a new type quailfier?
The first question you should ask yourself is whether this is really a qualifier. Does it need to apply to arbitrary types? Is it more appropriately modeled as an attribute on specific type declarations, or possibly an independent type kind? Does it behave like a normal C qualifier, e.g. it is lost during r-value conversion?
Assuming that's true, read on.
> >> Why are there only 3 fast qualifiers added to the qualtype?
The fast qualifiers are mangled into the low bits of the type pointer; that's why they're fast, because they don't need to be stored separately. Other qualifiers are stored in a separately-allocated ExtQuals structure.
If we allocate Types with 8-byte alignment, we have three bits available. Currently only const and restrict are fast, and the third bit is used to indicate that the type has extended qualifiers.
> >> How can I increase the size of the fast qualifiers, I mean how to add new qualifier to qualtype without actually disturbing the existing fast quals : const, volatile, restrict.
I would strongly suggest that you avoid changing the fast-qualifiers representation. Just add your new qualifier to the Qualifiers structure and make sure the Profile method includes it, and then you'll just need to worry about the N places in the code which assume they know about every qualifier (I consider such code to be buggy, but surprisingly that judgement doesn't by itself fix any bugs :) ).
John.
More information about the cfe-dev
mailing list