adding attribute bits to types

Hi,

I am currently working on an experiment where I am adding additional type qualifiers on struct instances (this is done with the __attribute__ syntax).

Syntactically in C, I am trying to do something like this at the moment:

typedef struct Foo {
   ...
} Foo;

#define BAR __attribute__((bar))

void f(void) {
   BAR Foo *baz = ...;
   ...
}

This attribute will then be used to influence the code generator.

I made some hacks to add these extra attributes in the attribute parser and then some in SemaType.cpp: ProcessTypeAttributeList in order to process these attributes. So far that works well.

My idea then is that I add some extra tag bits to the RecordType class (or to subclass it, but that's a minor issue) in order to keep track of these extra qualifiers, but that then means that I probably need to unique these as new record types and add the new (attribute) qualified types to the ASTContext, right? Here I am stuck at the moment, and I do not understand how and where a record type is looked up and added to the AST context. Some pointers where I should look would be nice.

Would it be a better and/or easier approach, to add the bits to the QualType class instead?

Regards,
Mattias

You can put them into ExtQualType, if they have to be on the type. If you see how they handle address spaces or the GC attributes, you just copy those bits, and you're done. The rest of the system works to make what needs to happen, happen. If you don't need them on the type, they are already on the decl, just fetch the attributes from the decl, see:

           if (FD->hasAttr<NoReturnAttr>()) {
             NoReturnEdge = true;
             HasFakeEdge = true;

for example, in SemaDecl.cpp.

Mike is right. We don't want to be adding qualifier bits to the Type objects themselves.

Mike Stump wrote:

You can put them into ExtQualType, if they have to be on the type. If you see how they handle address spaces or the GC attributes, you just copy those bits, and you're done. The rest of the system works to make what needs to happen, happen. If you don't need them on the type, they are already on the decl, just fetch the attributes from the decl, see:

Thanks, I did need to place the attributes in this case on the type and it just "magically" started to work after I realized how the ExtQualType actually worked. Thanks for pointing it out.

/ Mattias

Mike Stump wrote:

You can put them into ExtQualType, if they have to be on the type. If
you see how they handle address spaces or the GC attributes, you just
copy those bits, and you're done. The rest of the system works to
make what needs to happen, happen. If you don't need them on the
type, they are already on the decl, just fetch the attributes from the
decl, see:

Thanks, I did need to place the attributes in this case on the type and
it just "magically" started to work after I realized how the ExtQualType
actually worked. Thanks for pointing it out.

The tricky part for type attributes is to make sure that other attributes are retained when you
are adding a new type. There are several examples of that, including objc's __weak/__strong.

- fariborz

Mike Stump wrote:

You can put them into ExtQualType, if they have to be on the type.
If
you see how they handle address spaces or the GC attributes, you just
copy those bits, and you're done. The rest of the system works to
make what needs to happen, happen. If you don't need them on the
type, they are already on the decl, just fetch the attributes from
the
decl, see:

Thanks, I did need to place the attributes in this case on the type
and
it just "magically" started to work after I realized how the
ExtQualType
actually worked. Thanks for pointing it out.

The tricky part for type attributes is to make sure that other
attributes are retained when you
are adding a new type. There are several examples of that, including

which I meant to say when you are adding a new attribute.

- fariborz

Mattias Holm wrote:

Mike Stump wrote:
  
You can put them into ExtQualType, if they have to be on the type.  If  
you see how they handle address spaces or the GC attributes, you just  
copy those bits, and you're done.  The rest of the system works to  
make what needs to happen, happen.  If you don't need them on the  
type, they are already on the decl, just fetch the attributes from the  
decl, see:
    

Thanks, I did need to place the attributes in this case on the type and 
it just "magically" started to work after I realized how the ExtQualType 
actually worked. Thanks for pointing it out.
  

Anything you add to ExtQualType needs to also be supported in QualifierSet. There
should probably be a comment to that effect.

John.