From bcc0a0056f14ab4c7cbbba6ee51b39eaceb92ebf Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Wed, 9 Jul 2025 09:59:38 +0200 Subject: [PATCH] Fix generation of min/max calls for SYCL SYCL 2020 specification does not define min/max overloads accepting `bool` data type, but yarpgen generates code that calls them. Of course, such code does not compile and to fix this, we do a promotion from `bool` to `char` (or `signed char`, to be precise). Signed-off-by: Alexey Sachkov --- src/expr.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/expr.cpp b/src/expr.cpp index 3d238fb..6cf042b 100644 --- a/src/expr.cpp +++ b/src/expr.cpp @@ -3033,6 +3033,21 @@ void LibCallExpr::cxxArgPromotion(std::shared_ptr &arg, true); } +// SYCL 2020 specification defines min and max as accepting two GenInt values. +// GenInt does *not* include bool, so we need to turn it into a char. +void static syclBoolPromotion(std::shared_ptr &expr) { + auto expr_type = expr->getValue()->getType(); + if (!expr_type->isIntType()) + return; + + auto expr_int_type = std::static_pointer_cast(expr_type); + if (expr_int_type->getIntTypeId() != IntTypeID::BOOL) + return; + + auto int_type = IntegralType::init(IntTypeID::SCHAR); + expr = std::make_shared(expr, int_type, false); +} + MinMaxCallBase::MinMaxCallBase(std::shared_ptr _a, std::shared_ptr _b, LibCallKind _kind) : a(std::move(_a)), b(std::move(_b)), kind(_kind) {} @@ -3052,6 +3067,11 @@ bool MinMaxCallBase::propagateType() { ispcBoolPromotion(b); } + if (options.isSYCL()) { + syclBoolPromotion(a); + syclBoolPromotion(b); + } + IntTypeID top_type_id = getTopIntID({a, b}); cxxArgPromotion(a, top_type_id); cxxArgPromotion(b, top_type_id);