[cfe-dev] Custom calling conventions in C code

Chris Lattner clattner at apple.com
Thu Jul 10 10:58:10 PDT 2008


On Jul 10, 2008, at 1:54 AM, Matthijs Kooijman wrote:
>> I think it would be a great thing for compiler hackers to have a  
>> mechanism
>> to access an arbitrary calling convention, but I also think it  
>> would be a
>> disaster to expose this to end user code.  The problem is that not  
>> all
>> constructs are valid with every calling convention, and if there is  
>> ever a
>> large install base of code using "calling convention 19" in their C  
>> code,
>> we'd have to support that forever.  CC#'s are supposed to be an  
>> internal
>> implementation detail of the IR.
> In our case, we are working with a specific C variant, which is  
> mostly C
> compatible and can therefore be parsed by clang completely. So, I'm  
> looking
> for a way to be able to write down a custom calling convention from  
> within
> that language, without having to modify clang locally. So, support  
> for a
> __attribute__(()) extension would be just fine.

Ok, so you have specific conventions you want to support. Something  
like:

void foo() __interrupt__ {

}

or whatever.  The best way to do this is to have __interrupt__ be a  
target-specific #define for __attribute__((interrupt)) and then have  
your target handle the interrupt attribute however you want.

> backend is going to be handling your code. Support a specific calling
> convention is then something for the backend, which might or might not
> continue support for a specific calling convention. Doesn't that sound
> reasonable?

Yep, supporting specific calling conventions is fine, I just don't  
want something like:

__attribute__((callingconv(47)))

-Chris



More information about the cfe-dev mailing list