[clang] 663e47a - [OpenCL] Reduce emitting candidate notes for builtins

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 27 01:56:01 PDT 2022


Author: Sven van Haastregt
Date: 2022-06-27T09:55:44+01:00
New Revision: 663e47a50f50c9ff0da9ba805f804c06645638ed

URL: https://github.com/llvm/llvm-project/commit/663e47a50f50c9ff0da9ba805f804c06645638ed
DIFF: https://github.com/llvm/llvm-project/commit/663e47a50f50c9ff0da9ba805f804c06645638ed.diff

LOG: [OpenCL] Reduce emitting candidate notes for builtins

When overload resolution fails, clang emits a note diagnostic for each
candidate.  For OpenCL builtins this often leads to many repeated note
diagnostics with no new information.  Stop emitting such notes.

Update a test that was relying on counting those notes to check how
many builtins are available for certain extension configurations.

Differential Revision: https://reviews.llvm.org/D127961

Added: 
    

Modified: 
    clang/lib/Sema/SemaOverload.cpp
    clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c627d631714d5..c226ed6254790 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11266,6 +11266,13 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
   if (shouldSkipNotingLambdaConversionDecl(Fn))
     return;
 
+  // There is no physical candidate declaration to point to for OpenCL builtins.
+  // Except for failed conversions, the notes are identical for each candidate,
+  // so do not generate such notes.
+  if (S.getLangOpts().OpenCL && Fn->isImplicit() &&
+      Cand->FailureKind != ovl_fail_bad_conversion)
+    return;
+
   // Note deleted candidates, but only if they're viable.
   if (Cand->Viable) {
     if (Fn->isDeleted()) {

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 737632fdf07b1..bf943a400320c 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -171,14 +171,14 @@ void test_atomic_fetch_with_address_space(volatile __generic atomic_float *a_flo
 // extension is disabled.  Test this by counting the number of notes about
 // candidate functions.
 void test_atomic_double_reporting(volatile __generic atomic_int *a) {
-  atomic_init(a);
+  atomic_init(a, a);
   // expected-error at -1{{no matching function for call to 'atomic_init'}}
 #if defined(NO_FP64)
   // Expecting 5 candidates: int, uint, long, ulong, float
-  // expected-note at -4 5 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at -4 5 {{candidate function not viable: no known conversion}}
 #else
   // Expecting 6 candidates: int, uint, long, ulong, float, double
-  // expected-note at -7 6 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
+  // expected-note at -7 6 {{candidate function not viable: no known conversion}}
 #endif
 }
 
@@ -198,7 +198,6 @@ void test_atomics_without_scope_device(volatile __generic atomic_int *a_int) {
 
   atomic_exchange_explicit(a_int, d, memory_order_seq_cst);
   // expected-error at -1{{no matching function for call to 'atomic_exchange_explicit'}}
-  // expected-note at -2 + {{candidate function not viable}}
 
   atomic_exchange_explicit(a_int, d, memory_order_seq_cst, memory_scope_work_group);
 }
@@ -272,9 +271,7 @@ kernel void basic_image_readonly(read_only image2d_t image_read_only_image2d) {
   res = read_imageh(image_read_only_image2d, i2);
 #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 && !defined(__OPENCL_CPP_VERSION__)
   // expected-error at -3{{no matching function for call to 'read_imagef'}}
-  // expected-note at -4 + {{candidate function not viable}}
-  // expected-error at -4{{no matching function for call to 'read_imageh'}}
-  // expected-note at -5 + {{candidate function not viable}}
+  // expected-error at -3{{no matching function for call to 'read_imageh'}}
 #endif
   res = read_imageh(image_read_only_image2d, sampler, i2);
 
@@ -304,7 +301,6 @@ kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_i
   write_imagef(image3dwo, i4, i, f4);
 #if __OPENCL_C_VERSION__ <= CL_VERSION_1_2 && !defined(__OPENCL_CPP_VERSION__)
   // expected-error at -2{{no matching function for call to 'write_imagef'}}
-  // expected-note at -3 + {{candidate function not viable}}
 #endif
 }
 


        


More information about the cfe-commits mailing list