After some discussion with Doug, we decided that it made a lot more sense
for __unknown_anytype resolution to destructively modify the AST.  So that's
what it does now, which significantly simplifies some of the implementation.
Normal member calls work pretty cleanly now, and I added support for
propagating unknown-ness through &.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129331 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCXXABI.cpp b/lib/CodeGen/CGCXXABI.cpp
index e8b6f56..92f1c63 100644
--- a/lib/CodeGen/CGCXXABI.cpp
+++ b/lib/CodeGen/CGCXXABI.cpp
@@ -99,8 +99,7 @@
   return GetBogusMemberPointer(CGM, QualType(MPT, 0));
 }
 
-llvm::Constant *CGCXXABI::EmitMemberPointer(const CXXMethodDecl *MD,
-                                            QualType unknownType) {
+llvm::Constant *CGCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) {
   return GetBogusMemberPointer(CGM,
                          CGM.getContext().getMemberPointerType(MD->getType(),
                                          MD->getParent()->getTypeForDecl()));
diff --git a/lib/CodeGen/CGCXXABI.h b/lib/CodeGen/CGCXXABI.h
index a34ca9b..de4df3d 100644
--- a/lib/CodeGen/CGCXXABI.h
+++ b/lib/CodeGen/CGCXXABI.h
@@ -119,12 +119,7 @@
   virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
 
   /// Create a member pointer for the given method.
-  ///
-  /// \param unknownType - if non-null, use this type as the operand
-  ///   to CodeGenModule::getAddrOfUnknownAnyDecl instead of
-  ///   fetching the method's address in the normal way
-  virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD,
-                                            QualType unknownType = QualType());
+  virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
 
   /// Create a member pointer for the given field.
   virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 496c3fc..92e6a19 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1792,35 +1792,6 @@
   return MakeAddrLValue(phi, expr->getType());
 }
 
-static LValue emitUnknownAnyLValue(CodeGenFunction &CGF,
-                                   const Expr *operand,
-                                   QualType resolvedType) {
-  const ValueDecl *decl;
-  if (const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(operand)) {
-    decl = ref->getDecl();
-  } else if (const MemberExpr *mem = dyn_cast<MemberExpr>(operand)) {
-    decl = mem->getMemberDecl();
-
-    // Emit (and ignore) the base.
-    if (mem->isArrow())
-      CGF.EmitScalarExpr(mem->getBase());
-    else
-      CGF.EmitLValue(mem->getBase());
-  } else {
-    llvm_unreachable("unexpected operand of unknown-any resolution!");
-    decl = 0;
-  }
-  llvm::Value *addr = CGF.CGM.getAddrOfUnknownAnyDecl(decl, resolvedType);
-
-  QualType type = resolvedType;
-  if (const ReferenceType *ref = type->getAs<ReferenceType>()) {
-    addr = CGF.Builder.CreateLoad(addr, "ref.value");
-    type = ref->getPointeeType();
-  }
-
-  return CGF.MakeAddrLValue(addr, type);
-}
-
 /// EmitCastLValue - Casts are never lvalues unless that cast is a dynamic_cast.
 /// If the cast is a dynamic_cast, we can have the usual lvalue result,
 /// otherwise if a cast is needed by the code generator in an lvalue context,
@@ -1959,13 +1930,6 @@
                                            ConvertType(ToType));
     return MakeAddrLValue(V, E->getType());
   }
-  case CK_ResolveUnknownAnyType:
-    return emitUnknownAnyLValue(*this, E->getSubExpr(), E->getType());
-  case CK_ResolveUnknownAnyTypeToReference: {
-    // l-value vs. r-value reference type shouldn't matter here.
-    QualType type = getContext().getLValueReferenceType(E->getType());
-    return emitUnknownAnyLValue(*this, E->getSubExpr(), type);
-  }
   }
   
   llvm_unreachable("Unhandled lvalue cast kind?");
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index 5d22fc3..177d0a4 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -310,11 +310,6 @@
     llvm_unreachable("should not be emitting lvalue bitcast as rvalue");
     break;
 
-  case CK_ResolveUnknownAnyType:
-  case CK_ResolveUnknownAnyTypeToReference:
-    EmitAggLoadOfLValue(E);
-    break;
-      
   case CK_Dependent:
   case CK_BitCast:
   case CK_ArrayToPointerDecay:
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index b04ff0a..3a2fb9b 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -552,8 +552,6 @@
     case CK_GetObjCProperty:
     case CK_ToVoid:
     case CK_Dynamic:
-    case CK_ResolveUnknownAnyType:
-    case CK_ResolveUnknownAnyTypeToReference:
       return 0;
 
     // These might need to be supported for constexpr.
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index f2ab0a2..a44c03e 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1127,22 +1127,6 @@
     return RV.getScalarVal();
   }
 
-  case CK_ResolveUnknownAnyType:
-    // Special case: resolving a member pointer constant.
-    if (const UnaryOperator *uo = dyn_cast<UnaryOperator>(E)) {
-      DeclRefExpr *declRef = cast<DeclRefExpr>(uo->getSubExpr());
-      const CXXMethodDecl *method = cast<CXXMethodDecl>(declRef->getDecl());
-
-      const MemberPointerType *mpt = CE->getType()->castAs<MemberPointerType>();
-      QualType resolvedType = mpt->getPointeeType();
-
-      return CGF.CGM.getCXXABI().EmitMemberPointer(method, resolvedType);
-    }
-    // fallthrough
-
-  case CK_ResolveUnknownAnyTypeToReference:
-    return EmitLoadOfLValue(CE);
-      
   case CK_LValueToRValue:
     assert(CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy));
     assert(E->isGLValue() && "lvalue-to-rvalue applied to r-value!");
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 8f304ff..944b24c 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1072,54 +1072,6 @@
   return GetOrCreateLLVMGlobal(MangledName, PTy, D);
 }
 
-/// getAddrOfUnknownAnyDecl - Return an llvm::Constant for the address
-/// of a global which was declared with unknown type.  It is possible
-/// for a VarDecl to end up getting resolved to have function type,
-/// which complicates this substantially; on the other hand, these are
-/// always external references, which does simplify the logic a lot.
-llvm::Constant *
-CodeGenModule::getAddrOfUnknownAnyDecl(const NamedDecl *decl, QualType type) {
-  GlobalDecl global;
-
-  // FunctionDecls will always end up with function types, but
-  // VarDecls can end up with them too.
-  if (isa<FunctionDecl>(decl))
-    global = GlobalDecl(cast<FunctionDecl>(decl));
-  else
-    global = GlobalDecl(cast<VarDecl>(decl));
-  llvm::StringRef mangledName = getMangledName(global);
-
-  const llvm::Type *ty = getTypes().ConvertTypeForMem(type);
-  const llvm::PointerType *pty =
-    llvm::PointerType::get(ty, getContext().getTargetAddressSpace(type));
-
-
-  // Check for an existing global value with this name.
-  llvm::GlobalValue *entry = GetGlobalValue(mangledName);
-  if (entry)
-    return llvm::ConstantExpr::getBitCast(entry, pty);
-
-  // If we're creating something with function type, go ahead and
-  // create a function.
-  if (const llvm::FunctionType *fnty = dyn_cast<llvm::FunctionType>(ty)) {
-    llvm::Function *fn = llvm::Function::Create(fnty,
-                                                llvm::Function::ExternalLinkage,
-                                                mangledName, &getModule());
-    return fn;
-
-  // Otherwise, make a global variable.
-  } else {
-    llvm::GlobalVariable *var
-      = new llvm::GlobalVariable(getModule(), ty, false,
-                                 llvm::GlobalValue::ExternalLinkage,
-                                 0, mangledName, 0,
-                                 false, pty->getAddressSpace());
-    if (isa<VarDecl>(decl) && cast<VarDecl>(decl)->isThreadSpecified())
-      var->setThreadLocal(true);
-    return var;
-  }
-}
-
 /// CreateRuntimeVariable - Create a new runtime global variable with the
 /// specified type and name.
 llvm::Constant *
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index b29437d..99c973c 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -358,7 +358,6 @@
   llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
                                      const llvm::Type *Ty = 0);
 
-  llvm::Constant *getAddrOfUnknownAnyDecl(const NamedDecl *D, QualType type);
 
   /// GetAddrOfFunction - Return the address of the given function.  If Ty is
   /// non-null, then this function will use the specified type if it has to
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp
index 6c864ca..ca3efb5 100644
--- a/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/lib/CodeGen/ItaniumCXXABI.cpp
@@ -78,8 +78,7 @@
 
   llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
 
-  llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD,
-                                    QualType unknownType);
+  llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
   llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
                                         CharUnits offset);
 
@@ -503,8 +502,7 @@
   return llvm::ConstantInt::get(getPtrDiffTy(), offset.getQuantity());
 }
 
-llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const CXXMethodDecl *MD,
-                                                 QualType unknownType) {
+llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) {
   assert(MD->isInstance() && "Member function must not be static!");
   MD = MD->getCanonicalDecl();
 
@@ -539,25 +537,20 @@
       MemPtr[1] = llvm::ConstantInt::get(ptrdiff_t, 0);
     }
   } else {
-    llvm::Constant *addr;
-    if (!unknownType.isNull()) {
-      addr = CGM.getAddrOfUnknownAnyDecl(MD, unknownType);
+    QualType fnType = MD->getType();
+    const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
+    const llvm::Type *Ty;
+    // Check whether the function has a computable LLVM signature.
+    if (!CodeGenTypes::VerifyFuncTypeComplete(FPT)) {
+      // The function has a computable LLVM signature; use the correct type.
+      Ty = Types.GetFunctionType(Types.getFunctionInfo(MD),
+                                 FPT->isVariadic());
     } else {
-      QualType fnType = MD->getType();
-      const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
-      const llvm::Type *Ty;
-      // Check whether the function has a computable LLVM signature.
-      if (!CodeGenTypes::VerifyFuncTypeComplete(FPT)) {
-        // The function has a computable LLVM signature; use the correct type.
-        Ty = Types.GetFunctionType(Types.getFunctionInfo(MD),
-                                   FPT->isVariadic());
-      } else {
-        // Use an arbitrary non-function type to tell GetAddrOfFunction that the
-        // function type is incomplete.
-        Ty = ptrdiff_t;
-      }
-      addr = CGM.GetAddrOfFunction(MD, Ty);
+      // Use an arbitrary non-function type to tell GetAddrOfFunction that the
+      // function type is incomplete.
+      Ty = ptrdiff_t;
     }
+    llvm::Constant *addr = CGM.GetAddrOfFunction(MD, Ty);
 
     MemPtr[0] = llvm::ConstantExpr::getPtrToInt(addr, ptrdiff_t);
     MemPtr[1] = llvm::ConstantInt::get(ptrdiff_t, 0);