Fix another debug info crash with virtual bases.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94520 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index e1aeb5e..cb8752e 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -615,21 +615,28 @@
     for (CXXRecordDecl::base_class_const_iterator BI = Decl->bases_begin(),
            BE = Decl->bases_end(); BI != BE; ++BI) {
       unsigned BFlags = 0;
-      if (BI->isVirtual())
+      uint64_t BaseOffset;
+      
+      const CXXRecordDecl *Base =
+        cast<CXXRecordDecl>(BI->getType()->getAs<RecordType>()->getDecl());
+
+      if (BI->isVirtual()) {
+        BaseOffset = RL.getVBaseClassOffset(Base);
         BFlags = llvm::DIType::FlagVirtual;
+      } else
+        BaseOffset = RL.getBaseClassOffset(Base);
+
       AccessSpecifier Access = BI->getAccessSpecifier();
       if (Access == clang::AS_private)
         BFlags |= llvm::DIType::FlagPrivate;
       else if (Access == clang::AS_protected)
         BFlags |= llvm::DIType::FlagProtected;
 
-      const CXXRecordDecl *Base =
-        cast<CXXRecordDecl>(BI->getType()->getAs<RecordType>()->getDecl());
       llvm::DIType DTy =
         DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
                                        RecordTy, llvm::StringRef(), 
                                        llvm::DICompileUnit(), 0, 0, 0,
-                                       RL.getBaseClassOffset(Base), BFlags,
+                                       BaseOffset, BFlags,
                                        getOrCreateType(BI->getType(),
                                                        Unit));
       EltTys.push_back(DTy);
diff --git a/test/CodeGenCXX/debug-info.cpp b/test/CodeGenCXX/debug-info.cpp
index f18e9b0..6bb9533 100644
--- a/test/CodeGenCXX/debug-info.cpp
+++ b/test/CodeGenCXX/debug-info.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm-only -g
+// RUN: %clang_cc1 -emit-llvm-only -g %s
 template<typename T> struct Identity {
   typedef T Type;
 };
@@ -41,3 +41,12 @@
   
   Y::~Y() { }
 }
+
+namespace VirtualBase {
+  struct A { };
+  struct B : virtual A { };
+
+  void f() {
+    B b;
+  }
+}