[cfe-commits] r46132 - in /cfe/trunk: AST/Expr.cpp AST/StmtPrinter.cpp CodeGen/CGBuiltin.cpp CodeGen/CGExpr.cpp CodeGen/CGExprScalar.cpp CodeGen/CodeGenFunction.h Parse/ParseExpr.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def include/clang/Basic/DiagnosticKinds.def include/clang/Basic/TokenKinds.def include/clang/Parse/Action.h

Nate Begeman natebegeman at mac.com
Thu Jan 17 14:49:32 PST 2008


On Jan 17, 2008, at 2:33 PM, Neil Booth wrote:

> Nate Begeman wrote:-
>
>> Author: sampo
>> Date: Thu Jan 17 11:46:27 2008
>> New Revision: 46132
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=46132&view=rev
>> Log:
>> Implement basic overload support via a new builtin,  
>> __builtin_overload.
>>
>> __builtin_overload takes 2 or more arguments:
>> 0) a non-zero constant-expr for the number of arguments the  
>> overloaded
>>   functions will take
>> 1) the arguments to pass to the matching overloaded function
>> 2) a list of functions to match.
>>
>> The return type of __builtin_overload is inferred from the function  
>> whose args
>> match the types of the arguments passed to the builtin.  For example:
>>
>> float a;
>> float sinf(float);
>> int   sini(int);
>>
>> float b = __builtin_overload(1, a, sini, sinf);
>>
>> Says that we are overloading functions that take one argument, and  
>> trying to
>> pass an argument of the same type as 'a'.  sini() does not match  
>> since it takes
>> and argument of type int.  sinf does match, so at codegen time this  
>> will turn
>> into float b = sinf(a);
>
> This looks interesting; a similar concept to EDG's __generic.
>
> What happens for a two-argument function with types float and double,
> say pow?

Right now the exact types have to match; in the future we may do some  
kind of type promotion or something; there's definitely room for  
improvement :)

So for pow, you'd have

double d1, d2;
float f1, f2;

__builtin_overload(2, d1, d2, pow, powf, powl) would be a call to  
pow() at codegen time.
__builtin_overload(2, f1, f2, pow, powf, powl) would be a call to  
powf() at codegen time.
__builtin_overload(2, d1, f1, pow, powf, powl) would get you a  
diagnostic saying no overloads matched the argument types.

Thanks,
Nate



More information about the cfe-commits mailing list