Anastasia created this revision.
Anastasia added a reviewer: rjmccall.
Herald added a subscriber: ebevhan.

As discussed in https://reviews.llvm.org/D69938#inline-629726 this commit 
improves the diagnostic of addr spaces. The approach is currently reusing 
diagnostic streaming of `Qualifiers`.

There are a number of issues however:

1. Address spaces don't always have representation i.e. in C++ it is just a 
number or `Default` address space doesn't correspond to anything at all. For 
the former case with the current approach  we will get 
`'__attribute__((address_space(N)))'` printed into the diagnostic. For the 
latter one it will print `unqualified`.

2. In OpenCL we threat `__private` and `Default` in the same way and therefore 
it doesn't get printed. With this patch therefore `unqualified` will appear 
even if `__private` was specified in the original source. There is a bug open 
to fix that however: https://bugs.llvm.org/show_bug.cgi?id=43295. Perhaps it 
should be fixed as soon as this gets committed.


https://reviews.llvm.org/D71111

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/address-space-references.cpp
  clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  clang/test/SemaOpenCLCXX/address-space-lambda.cl
  clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl

Index: clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
===================================================================
--- clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
+++ clang/test/SemaOpenCLCXX/address-space-of-this-class-scope.cl
@@ -7,8 +7,8 @@
 };
 
 void bar(__local C*);
-// expected-note@-1{{candidate function not viable: address space mismatch in 1st argument ('decltype(this)' (aka '__global C *')), parameter type must be '__local C *'}}
-// expected-note@-2{{candidate function not viable: address space mismatch in 1st argument ('decltype(this)' (aka 'C *')), parameter type must be '__local C *'}}
+// expected-note@-1{{candidate function not viable: cannot convert address spaces in 1st argument ('decltype(this)' (aka '__global C *')) from '__global' to '__local'}}
+// expected-note@-2{{candidate function not viable: cannot convert address spaces in 1st argument ('decltype(this)' (aka 'C *')) from unqualified to '__local'}}
 
 __global C Glob;
 void foo(){
Index: clang/test/SemaOpenCLCXX/address-space-lambda.cl
===================================================================
--- clang/test/SemaOpenCLCXX/address-space-lambda.cl
+++ clang/test/SemaOpenCLCXX/address-space-lambda.cl
@@ -12,7 +12,7 @@
   // Test lambda with default parameters
 //CHECK: CXXMethodDecl {{.*}} constexpr operator() 'void () const __generic'
   [&] {i++;} ();
-  __constant auto err = [&]() {}; //expected-note-re{{candidate function not viable: address space mismatch in 'this' argument ('__constant (lambda at {{.*}})'), parameter type must be 'const __generic (lambda at {{.*}})'}}
+  __constant auto err = [&]() {}; //expected-note-re{{candidate function not viable: cannot convert address spaces in 'this' argument ('__constant (lambda at {{.*}}') from '__constant' to '__generic'}}
   err();                          //expected-error-re{{no matching function for call to object of type '__constant (lambda at {{.*}})'}}
   // FIXME: There is very limited addr space functionality
   // we can test when taking lambda type from the object.
Index: clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
===================================================================
--- clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
+++ clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
@@ -42,7 +42,7 @@
 #if !__OPENCL_CPP_VERSION__
 // expected-note@-3{{passing argument to parameter 'arg_glob' here}}
 #else
-// expected-note-re@-5{{candidate function not viable: address space mismatch in 1st argument ('__{{generic|constant}} int *'), parameter type must be '__global int *'}}
+// expected-note-re@-5{{candidate function not viable: cannot convert address spaces in 1st argument ('__{{generic|constant}} int *') from '__{{generic|constant}}' to '__global'}}
 #endif
 #endif
 
@@ -50,7 +50,7 @@
 #if !__OPENCL_CPP_VERSION__
 // expected-note@-2{{passing argument to parameter 'arg_loc' here}}
 #else
-// expected-note-re@-4{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic|constant}} int *'), parameter type must be '__local int *'}}
+// expected-note-re@-4{{candidate function not viable: cannot convert address spaces in 1st argument ('__{{global|generic|constant}} int *') from '__{{global|generic|constant}}' to '__local'}}
 #endif
 
 void f_const(__constant int *arg_const) {}
@@ -58,7 +58,7 @@
 #if !__OPENCL_CPP_VERSION__
 // expected-note@-3{{passing argument to parameter 'arg_const' here}}
 #else
-// expected-note-re@-5{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic}} int *'), parameter type must be '__constant int *'}}
+// expected-note-re@-5{{candidate function not viable: cannot convert address spaces in 1st argument ('__{{global|generic}} int *') from '__{{global|generic}}' to '__constant'}}
 #endif
 #endif
 
@@ -66,7 +66,7 @@
 #if !__OPENCL_CPP_VERSION__
 // expected-note@-2{{passing argument to parameter 'arg_priv' here}}
 #else
-// expected-note-re@-4{{candidate function not viable: address space mismatch in 1st argument ('__{{global|generic|constant}} int *'), parameter type must be 'int *'}}
+// expected-note-re@-4{{candidate function not viable: cannot convert address spaces in 1st argument ('__{{global|generic|constant}} int *') from '__{{global|generic|constant}}' to unqualified}}
 #endif
 
 void f_gen(__generic int *arg_gen) {}
@@ -74,7 +74,7 @@
 #if !__OPENCL_CPP_VERSION__
 // expected-note@-3{{passing argument to parameter 'arg_gen' here}}
 #else
-// expected-note@-5{{candidate function not viable: address space mismatch in 1st argument ('__constant int *'), parameter type must be '__generic int *'}}
+// expected-note@-5{{candidate function not viable: cannot convert address spaces in 1st argument ('__constant int *') from '__constant' to '__generic'}}
 #endif
 #endif
 
Index: clang/test/SemaCXX/address-space-references.cpp
===================================================================
--- clang/test/SemaCXX/address-space-references.cpp
+++ clang/test/SemaCXX/address-space-references.cpp
@@ -3,10 +3,10 @@
 typedef int __attribute__((address_space(1))) int_1;
 typedef int __attribute__((address_space(2))) int_2;
 
-void f0(int_1 &); // expected-note{{candidate function not viable: address space mismatch in 1st argument ('int'), parameter type must be 'int_1 &' (aka '__attribute__((address_space(1))) int &')}} \
-// expected-note{{candidate function not viable: address space mismatch in 1st argument ('int_2' (aka '__attribute__((address_space(2))) int')), parameter type must be 'int_1 &' (aka '__attribute__((address_space(1))) int &')}}
-void f0(const int_1 &); // expected-note{{candidate function not viable: address space mismatch in 1st argument ('int'), parameter type must be 'const int_1 &' (aka 'const __attribute__((address_space(1))) int &')}} \
-// expected-note{{candidate function not viable: address space mismatch in 1st argument ('int_2' (aka '__attribute__((address_space(2))) int')), parameter type must be 'const int_1 &' (aka 'const __attribute__((address_space(1))) int &')}}
+void f0(int_1 &);       // expected-note{{candidate function not viable: cannot convert address spaces in 1st argument ('int') from unqualified to '__attribute__((address_space(1)))'}} \
+// expected-note{{candidate function not viable: cannot convert address spaces in 1st argument ('int_2' (aka '__attribute__((address_space(2))) int')) from '__attribute__((address_space(2)))' to '__attribute__((address_space(1)))'}}
+void f0(const int_1 &); // expected-note{{candidate function not viable: cannot convert address spaces in 1st argument ('int') from unqualified to '__attribute__((address_space(1)))'}} \
+// expected-note{{candidate function not viable: cannot convert address spaces in 1st argument ('int_2' (aka '__attribute__((address_space(2))) int')) from '__attribute__((address_space(2)))' to '__attribute__((address_space(1)))'}}
 
 void test_f0() {
   int i;
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -9772,10 +9772,16 @@
     Qualifiers ToQs = CToTy.getQualifiers();
 
     if (FromQs.getAddressSpace() != ToQs.getAddressSpace()) {
+      Qualifiers FromQs2Print;
+      if (FromQs.getAddressSpace() != LangAS::Default)
+        FromQs2Print.addAddressSpace(FromQs.getAddressSpace());
+      Qualifiers ToQs2Print;
+      if (ToQs.getAddressSpace() != LangAS::Default)
+        ToQs2Print.addAddressSpace(ToQs.getAddressSpace());
       S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_addrspace)
           << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc
           << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy
-          << ToTy << (unsigned)isObjectArgument << I + 1;
+          << (unsigned)isObjectArgument << FromQs2Print << ToQs2Print << I + 1;
       MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
       return;
     }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3829,8 +3829,8 @@
     "%select{%ordinal4 argument|object argument}3">;
 def note_ovl_candidate_bad_addrspace : Note<
     "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
-    "address space mismatch in %select{%ordinal6|'this'}5 argument (%3), "
-    "parameter type must be %4">;
+    "cannot convert address spaces in %select{%ordinal7|'this'}4 "
+    "argument (%3) from %5 to %6">;
 def note_ovl_candidate_bad_gc : Note<
     "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
     "%select{%ordinal7|'this'}6 argument (%3) has %select{no|__weak|__strong}4 "
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to