Revert "Module Debugging: Emit forward declarations for types that are defined in"

This reverts commit r247369 to facilitate reviewing of the following patch.

llvm-svn: 247431
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7f9216a..693d0f6 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -148,9 +148,7 @@
 }
 
 llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(const Decl *D) {
-  llvm::DIScope *Mod = getParentModuleOrNull(D);
-  return getContextDescriptor(cast<Decl>(D->getDeclContext()),
-                              Mod ? Mod : TheCU);
+  return getContextDescriptor(cast<Decl>(D->getDeclContext()), TheCU);
 }
 
 llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context,
@@ -1450,9 +1448,6 @@
     if (CXXDecl->isDynamicClass())
       return;
 
-  if (DebugTypeExtRefs && RD->isFromASTFile())
-    return;
-
   QualType Ty = CGM.getContext().getRecordType(RD);
   llvm::DIType *T = getTypeOrNull(Ty);
   if (T && T->isForwardDecl())
@@ -1674,9 +1669,9 @@
       TheCU->getSourceLanguage(), internString(Mod.ModuleName),
       internString(Mod.Path), TheCU->getProducer(), true, StringRef(), 0,
       internString(Mod.ASTFile), llvm::DIBuilder::FullDebug, Mod.Signature);
-  llvm::DIModule *M = DIB.createModule(
-      CU, Mod.ModuleName, ConfigMacros, internString(Mod.Path),
-      internString(CGM.getHeaderSearchOpts().Sysroot));
+  llvm::DIModule *M =
+      DIB.createModule(CU, Mod.ModuleName, ConfigMacros, internString(Mod.Path),
+                       internString(CGM.getHeaderSearchOpts().Sysroot));
   DIB.finalize();
   ModRef.reset(M);
   return M;
@@ -2086,16 +2081,9 @@
   if (auto *T = getTypeOrNull(Ty))
     return T;
 
-  llvm::DIType *Res = nullptr;
-  if (DebugTypeExtRefs)
-    // Make a forward declaration of an external type.
-    Res = getTypeExtRefOrNull(Ty, Unit);
-
   // Otherwise create the type.
-  if (!Res)
-    Res = CreateTypeNode(Ty, Unit);
-
-  void* TyPtr = Ty.getAsOpaquePtr();
+  llvm::DIType *Res = CreateTypeNode(Ty, Unit);
+  void *TyPtr = Ty.getAsOpaquePtr();
 
   // And update the type cache.
   TypeCache[TyPtr].reset(Res);
@@ -2127,123 +2115,6 @@
   }
 }
 
-llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) {
-  if (!DebugTypeExtRefs || !D || !D->isFromASTFile())
-    return nullptr;
-
-  llvm::DIModule *ModuleRef = nullptr;
-  auto *Reader = CGM.getContext().getExternalSource();
-  auto Idx = D->getOwningModuleID();
-  auto Info = Reader->getSourceDescriptor(Idx);
-  if (Info)
-    ModuleRef = getOrCreateModuleRef(*Info);
-  return ModuleRef;
-}
-
-llvm::DIType *CGDebugInfo::getTypeExtRefOrNull(QualType Ty, llvm::DIFile *F,
-                                               bool Anchored) {
-  assert(DebugTypeExtRefs && "module debugging only");
-  Decl *TyDecl = nullptr;
-  StringRef Name;
-  SmallString<256> UID;
-  unsigned Tag = 0;
-
-  // Handle all types that have a declaration.
-  switch (Ty->getTypeClass()) {
-  case Type::Typedef: {
-    TyDecl = cast<TypedefType>(Ty)->getDecl();
-    if (!TyDecl->isFromASTFile())
-      return nullptr;
-
-    // A typedef will anchor a type in the module.
-    if (auto *TD = dyn_cast<TypedefDecl>(TyDecl)) {
-      // This is a working around the fact that LLVM does not allow
-      // typedefs to be forward declarations.
-      QualType Ty = TD->getUnderlyingType();
-      Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());
-      if (auto *AnchoredTy = getTypeExtRefOrNull(Ty, F, /*Anchored=*/true)) {
-        TypeCache[Ty.getAsOpaquePtr()].reset(AnchoredTy);
-        SourceLocation Loc = TD->getLocation();
-        return DBuilder.createTypedef(AnchoredTy, TD->getName(),
-                                      getOrCreateFile(Loc), getLineNumber(Loc),
-                                      getDeclContextDescriptor(TD));
-      }
-    }
-    break;
-  }
-
-  case Type::Record: {
-    TyDecl = cast<RecordType>(Ty)->getDecl();
-    if (!TyDecl->isFromASTFile())
-      return nullptr;
-
-    if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(TyDecl))
-      if (!CTSD->isExplicitInstantiationOrSpecialization() && !Anchored)
-        // We may not assume that this type made it into the module.
-        return nullptr;
-    // C++ classes and template instantiations.
-    if (auto *RD = dyn_cast<CXXRecordDecl>(TyDecl)) {
-      if (!RD->getDefinition())
-        return nullptr;
-      Tag = getTagForRecord(RD);
-      UID =
-          getUniqueTagTypeName(cast<TagType>(RD->getTypeForDecl()), CGM, TheCU);
-      Name = getClassName(RD);
-    } else if (auto *RD = dyn_cast<RecordDecl>(TyDecl)) {
-      // C-style structs.
-      if (!RD->getDefinition())
-        return nullptr;
-      Tag = getTagForRecord(RD);
-      Name = getClassName(RD);
-    }
-    break;
-  }
-
-  case Type::Enum: {
-    TyDecl = cast<EnumType>(Ty)->getDecl();
-    if (!TyDecl->isFromASTFile())
-      return nullptr;
-
-    if (auto *ED = dyn_cast<EnumDecl>(TyDecl)) {
-      if (!ED->getDefinition())
-        return nullptr;
-      Tag = llvm::dwarf::DW_TAG_enumeration_type;
-      if ((TheCU->getSourceLanguage() == llvm::dwarf::DW_LANG_C_plus_plus) ||
-          (TheCU->getSourceLanguage() == llvm::dwarf::DW_LANG_ObjC_plus_plus)) {
-        UID = getUniqueTagTypeName(cast<TagType>(ED->getTypeForDecl()), CGM,
-                                   TheCU);
-        Name = ED->getName();
-      }
-    }
-    break;
-  }
-
-  case Type::ObjCInterface: {
-    TyDecl = cast<ObjCInterfaceType>(Ty)->getDecl();
-    if (!TyDecl->isFromASTFile())
-      return nullptr;
-
-    if (auto *ID = dyn_cast<ObjCInterfaceDecl>(TyDecl)) {
-      if (!ID->getDefinition())
-        return nullptr;
-      Tag = llvm::dwarf::DW_TAG_structure_type;
-      Name = ID->getName();
-    }
-    break;
-  }
-
-  default:
-    return nullptr;
-  }
-
-  if (Tag && !Name.empty()) {
-    assert(TyDecl);
-    auto *Ctx = getDeclContextDescriptor(TyDecl);
-    return DBuilder.createForwardDecl(Tag, Name, Ctx, F, 0, 0, 0, 0, UID);
-  } else
-    return nullptr;
-}
-
 llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
   // Handle qualifiers, which recursively handles what they refer to.
   if (Ty.hasLocalQualifiers())
@@ -2454,10 +2325,8 @@
         dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
       FDContext = getOrCreateNameSpace(NSDecl);
     else if (const RecordDecl *RDecl =
-             dyn_cast_or_null<RecordDecl>(FD->getDeclContext())) {
-      llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
-      FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
-    }
+             dyn_cast_or_null<RecordDecl>(FD->getDeclContext()))
+      FDContext = getContextDescriptor(RDecl, TheCU);
     // Collect template parameters.
     TParamsArray = CollectFunctionTemplateParams(FD, Unit);
   }
@@ -2505,9 +2374,7 @@
   // outside the class by putting it in the global scope.
   if (DC->isRecord())
     DC = CGM.getContext().getTranslationUnitDecl();
-
- llvm::DIScope *Mod = getParentModuleOrNull(VD);
- VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
+  VDContext = getContextDescriptor(cast<Decl>(DC), TheCU);
 }
 
 llvm::DISubprogram *
@@ -3432,8 +3299,7 @@
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
   if (!LexicalBlockStack.empty())
     return LexicalBlockStack.back();
-  llvm::DIScope *Mod = getParentModuleOrNull(D);
-  return getContextDescriptor(D, Mod ? Mod : TheCU);
+  return getContextDescriptor(D, TheCU);
 }
 
 void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {