From f0686569cc5789f93d76461143c232882b7ff2e9 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Fri, 5 Mar 2021 13:43:30 +0000 Subject: [PATCH] [OpenCL] Fix `mix` builtin overloads `mix` is subtly different from `clamp`: in the overloads where the last argument is a scalar, the second argument should be a gentype for `mix`. As scalars can be implicitly converted to vectors, this cannot be caught in the Sema test. Hence adding a CodeGen test, where we can verify the types using the mangled name. --- clang/lib/Sema/OpenCLBuiltins.td | 8 +++++++- clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index f2a9b98196e8..05dd6a1bd8f8 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -651,12 +651,18 @@ foreach name = ["step"] in { } // --- 3 arguments --- -foreach name = ["clamp", "mix"] in { +foreach name = ["clamp"] in { def : Builtin; def : Builtin; def : Builtin; def : Builtin; } +foreach name = ["mix"] in { + def : Builtin; + def : Builtin; + def : Builtin; + def : Builtin; +} foreach name = ["smoothstep"] in { def : Builtin; def : Builtin; diff --git a/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl b/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl index e4f4db0cd174..a59357e331e7 100644 --- a/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl @@ -1,5 +1,13 @@ // RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header %s | FileCheck %s +// Test that mix is correctly defined. +// CHECK-LABEL: @test_float +// CHECK: call <4 x float> @_Z3mixDv4_fS_f +// CHECK: ret +void test_float(float4 x, float a) { + float4 ret = mix(x, x, a); +} + // Test that Attr.Const from OpenCLBuiltins.td is lowered to a readnone attribute. // CHECK-LABEL: @test_const_attr // CHECK: call i32 @_Z3maxii({{.*}}) [[ATTR_CONST:#[0-9]]]