replace a dirty hack with a clean solution.  Too bad we can't 
use Blocks for our callbacks ;-)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65083 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 83ccd22..893eae5 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -175,7 +175,8 @@
 static void DummyArgToStringFn(Diagnostic::ArgumentKind AK, intptr_t QT,
                                const char *Modifier, unsigned ML,
                                const char *Argument, unsigned ArgLen,
-                               llvm::SmallVectorImpl<char> &Output) {
+                               llvm::SmallVectorImpl<char> &Output,
+                               void *Cookie) {
   const char *Str = "<can't format argument>";
   Output.append(Str, Str+strlen(Str));
 }
@@ -199,6 +200,7 @@
   LastDiagLevel = Fatal;
   
   ArgToStringFn = DummyArgToStringFn;
+  ArgToStringCookie = 0;
 }
 
 Diagnostic::~Diagnostic() {
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 1ffaf93..2bb6a17 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -24,7 +24,9 @@
 static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val,
                                  const char *Modifier, unsigned ModLen,
                                  const char *Argument, unsigned ArgLen,
-                                 llvm::SmallVectorImpl<char> &Output) {
+                                 llvm::SmallVectorImpl<char> &Output,
+                                 void *Cookie) {
+  ASTContext &Context = *static_cast<ASTContext*>(Cookie);
   
   std::string S;
   if (Kind == Diagnostic::ak_qualtype) {
@@ -47,8 +49,14 @@
         // it will turn into an attribute mess. People want their "vec4".
         !isa<VectorType>(DesugaredTy) &&
       
-        // Don't desugar objc types.  FIXME: THIS IS A HACK.
-        S != "id" && S != "Class") {
+        // Don't desugar magic Objective-C types.
+        Ty.getUnqualifiedType() != Context.getObjCIdType() &&
+        Ty.getUnqualifiedType() != Context.getObjCSelType() &&
+        Ty.getUnqualifiedType() != Context.getObjCProtoType() &&
+        Ty.getUnqualifiedType() != Context.getObjCClassType() &&
+        
+        // Not va_list.
+        Ty.getUnqualifiedType() != Context.getBuiltinVaListType()) {
       S = "'"+S+"' (aka '";
       S += DesugaredTy.getAsString();
       S += "')";
@@ -165,7 +173,7 @@
     FieldCollector.reset(new CXXFieldCollector());
       
   // Tell diagnostics how to render things from the AST library.
-  PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn);
+  PP.getDiagnostics().SetArgToStringFn(ConvertArgToStringFn, &Context);
 }
 
 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.