Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -8099,6 +8099,10 @@ "missing actual type specifier for pipe">; def err_reference_pipe_type : Error < "pipes packet types cannot be of reference type">; +def warn_ocl_bultin_potential_ambiguity : Warning< + "implicit conversion from integral type to floating point type for" + " overloadable function might lead to ambiguity">, + InGroup>, DefaultIgnore; def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 'main'">; def err_opencl_kernel_attr : Error<"attribute %0 can only be applied to a kernel function">; Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -2472,6 +2472,19 @@ if (FDecl) { for (const auto *I : FDecl->specific_attrs()) CheckArgumentWithTypeTag(I, Args.data()); + + if (getLangOpts().OpenCL) { + // Check if overloadble built-in function with floating point arguments takes + // integer values. + if (FDecl->hasAttr()) { + for (const auto* Arg : Args) { + const ImplicitCastExpr *ICE = dyn_cast(Arg); + if (!ICE || ICE->getCastKind() != CK_IntegralToFloating) + continue; + Diag(Loc, diag::warn_ocl_bultin_potential_ambiguity) << Range; + } + } + } } } } Index: test/SemaOpenCL/warn-potential-abiguity.cl =================================================================== --- /dev/null +++ test/SemaOpenCL/warn-potential-abiguity.cl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wconversion-might-lead-to-ambiguity %s + +float __attribute__((overloadable)) ocl_builtin_func(float f) { return f; } +float __attribute__((overloadable)) ocl_builtin_func_2args(float arg1, float arg2) { return arg1 + arg2; } + +__kernel void test() { + int p = ocl_builtin_func(3); // expected-warning {{implicit conversion from integral type to floating point type for overloadable function might lead to ambiguity}} + int q = ocl_builtin_func_2args(3.f, 3); // expected-warning {{implicit conversion from integral type to floating point type for overloadable function might lead to ambiguity}} +}