[PATCH] D27334: [OpenCL] Ambiguous function call.

Egor Churaev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 00:54:23 PST 2016


echuraev created this revision.
echuraev added a reviewer: Anastasia.
echuraev added subscribers: bader, cfe-commits, yaxunl.

Added warning about potential ambiguity error with built-in overloading.

Patch by Alexey Bader


https://reviews.llvm.org/D27334

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaOpenCL/warn-potential-abiguity.cl


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}}
+}
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<ArgumentWithTypeTagAttr>())
         CheckArgumentWithTypeTag(I, Args.data());
+
+      if (getLangOpts().OpenCL) {
+        // Check if overloadble built-in function with floating point arguments takes
+        // integer values.
+        if (FDecl->hasAttr<OverloadableAttr>()) {
+          for (const auto* Arg : Args) {
+            const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Arg);
+            if (!ICE || ICE->getCastKind() != CK_IntegralToFloating)
+              continue;
+            Diag(Loc, diag::warn_ocl_bultin_potential_ambiguity) << Range;
+          }
+        }
+      }
     }
   }
 }
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<DiagGroup<"conversion-might-lead-to-ambiguity">>, 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">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27334.80037.patch
Type: text/x-patch
Size: 2535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161202/47ec0e84/attachment-0001.bin>


More information about the cfe-commits mailing list