mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Allow $$max and $$min to also work on ints.
This commit is contained in:
@@ -4540,7 +4540,50 @@ void llvm_emit_builtin_call(GenContext *c, BEValue *result_value, Expr *expr)
|
||||
llvm_emit_syscall(c, result_value, expr);
|
||||
return;
|
||||
}
|
||||
llvm_emit_intrinsic_expr(c, llvm_get_intrinsic(func), result_value, expr);
|
||||
unsigned intrinsic;
|
||||
if (func == BUILTIN_MAX)
|
||||
{
|
||||
Type *type = type_flatten(expr->call_expr.arguments[0]->type);
|
||||
switch (type->type_kind)
|
||||
{
|
||||
case ALL_SIGNED_INTS:
|
||||
intrinsic = intrinsic_id.smax;
|
||||
break;
|
||||
case TYPE_BOOL:
|
||||
case ALL_UNSIGNED_INTS:
|
||||
intrinsic = intrinsic_id.umax;
|
||||
break;
|
||||
case ALL_FLOATS:
|
||||
intrinsic = intrinsic_id.maxnum;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE
|
||||
}
|
||||
}
|
||||
else if (func == BUILTIN_MIN)
|
||||
{
|
||||
Type *type = type_flatten(expr->call_expr.arguments[0]->type);
|
||||
switch (type->type_kind)
|
||||
{
|
||||
case ALL_SIGNED_INTS:
|
||||
intrinsic = intrinsic_id.smin;
|
||||
break;
|
||||
case TYPE_BOOL:
|
||||
case ALL_UNSIGNED_INTS:
|
||||
intrinsic = intrinsic_id.umin;
|
||||
break;
|
||||
case ALL_FLOATS:
|
||||
intrinsic = intrinsic_id.minnum;
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
intrinsic = llvm_get_intrinsic(func);
|
||||
}
|
||||
llvm_emit_intrinsic_expr(c, intrinsic, result_value, expr);
|
||||
}
|
||||
|
||||
void llvm_add_abi_call_attributes(GenContext *c, LLVMValueRef call_value, int count, ABIArgInfo **infos)
|
||||
|
||||
@@ -2703,14 +2703,25 @@ static inline bool sema_expr_analyse_builtin_call(SemaContext *context, Expr *ex
|
||||
break;
|
||||
|
||||
case BUILTIN_POW:
|
||||
case BUILTIN_MAX:
|
||||
case BUILTIN_MIN:
|
||||
if (!sema_check_builtin_args(args,
|
||||
(BuiltinArg[]) { BA_FLOATLIKE, BA_FLOATLIKE },
|
||||
arg_count)) return false;
|
||||
if (!sema_check_builtin_args_match(args, arg_count)) return false;
|
||||
rtype = args[0]->type;
|
||||
break;
|
||||
case BUILTIN_MAX:
|
||||
case BUILTIN_MIN:
|
||||
if (type_is_integer(args[0]->type))
|
||||
{
|
||||
if (!sema_check_builtin_args(args, (BuiltinArg[]) { BA_INTLIKE, BA_INTLIKE }, arg_count)) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sema_check_builtin_args(args, (BuiltinArg[]) { BA_FLOATLIKE, BA_FLOATLIKE }, arg_count)) return false;
|
||||
}
|
||||
if (!sema_check_builtin_args_match(args, arg_count)) return false;
|
||||
rtype = args[0]->type;
|
||||
break;
|
||||
case BUILTIN_FMA:
|
||||
if (!sema_check_builtin_args(args,
|
||||
(BuiltinArg[]) { BA_FLOATLIKE, BA_FLOATLIKE, BA_FLOATLIKE },
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define COMPILER_VERSION "0.3.30"
|
||||
#define COMPILER_VERSION "0.3.31"
|
||||
Reference in New Issue
Block a user