Pierre created this revision.
Pierre added reviewers: Anastasia, svenvh.
Pierre added projects: clang, LLVM.
Herald added subscribers: cfe-commits, kristina.

When hitting an ambigous call to a builtin function with the
-fdeclare-opencl-builtins option, diagnostics don't print the prototypes
that clash.
When not using the option above, they are displayed.
This patch prints them.

This is changing this diagnostic:

  test.cl:86:11: error: call to 'acos' is ambiguous
    int a = acos(p);
            ^~~~
  test.cl:86:11: note: candidate function
  test.cl:86:11: note: candidate function
  [not printing everything ...]
  test.cl:86:11: note: candidate function
  1 error generated.

To this:

  test.cl:86:11: error: call to 'acos' is ambiguous
    int a = acos(p);
            ^~~~
  test.cl:86:11: note: candidate function
  float acos(float)
  test.cl:86:11: note: candidate function
  double acos(double)
  [not printing everything ...]
  test.cl:86:11: note: candidate function
  __fp16 __attribute__((ext_vector_type(16))) acos(__fp16 
__attribute__((ext_vector_type(16))))
  1 error generated.


Repository:
  rC Clang

https://reviews.llvm.org/D64320

Files:
  clang/lib/Sema/SemaOverload.cpp


Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10425,6 +10425,25 @@
 
     // We don't really have anything else to say about viable candidates.
     S.NoteOverloadCandidate(Cand->FoundDecl, Fn);
+
+    // If this is a builtin function, give the available definitions.
+    if (S.getLangOpts().OpenCL && Fn->isImplicit()) {
+      raw_ostream &OS = llvm::outs();
+      unsigned NumParams = Fn->getNumParams();
+
+      OS << Fn->getReturnType().getAsString() << " ";
+      OS << Fn->getNameInfo().getAsString() << "(";
+
+      if (NumParams > 0) {
+        OS << Fn->getParamDecl(0)->getOriginalType().getAsString();
+      }
+      for (unsigned i = 1; i < NumParams; i++) {
+        OS << ", ";
+        OS << Fn->getParamDecl(i)->getOriginalType().getAsString();
+      }
+      OS << ")\n";
+    }
+
     return;
   }
 


Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10425,6 +10425,25 @@
 
     // We don't really have anything else to say about viable candidates.
     S.NoteOverloadCandidate(Cand->FoundDecl, Fn);
+
+    // If this is a builtin function, give the available definitions.
+    if (S.getLangOpts().OpenCL && Fn->isImplicit()) {
+      raw_ostream &OS = llvm::outs();
+      unsigned NumParams = Fn->getNumParams();
+
+      OS << Fn->getReturnType().getAsString() << " ";
+      OS << Fn->getNameInfo().getAsString() << "(";
+
+      if (NumParams > 0) {
+        OS << Fn->getParamDecl(0)->getOriginalType().getAsString();
+      }
+      for (unsigned i = 1; i < NumParams; i++) {
+        OS << ", ";
+        OS << Fn->getParamDecl(i)->getOriginalType().getAsString();
+      }
+      OS << ")\n";
+    }
+
     return;
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to