[cfe-commits] r146778 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGenCXX/debug-info-fwd-ref.cpp

Eric Christopher echristo at apple.com
Fri Dec 16 15:40:15 PST 2011


Author: echristo
Date: Fri Dec 16 17:40:14 2011
New Revision: 146778

URL: http://llvm.org/viewvc/llvm-project?rev=146778&view=rev
Log:
Start down the path of getting clang to internally agree on structs versus
classes.

Part of rdar://10520586 and a couple others.

Added:
    cfe/trunk/test/CodeGenCXX/debug-info-fwd-ref.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=146778&r1=146777&r2=146778&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Dec 16 17:40:14 2011
@@ -499,7 +499,12 @@
     llvm::DIDescriptor FDContext =
       getContextDescriptor(cast<Decl>(RD->getDeclContext()));
 
-    if (RD->isStruct())
+    CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
+    if (CXXDecl)
+      return DBuilder.createClassType(FDContext, RD->getName(), DefUnit,
+                                      Line, 0, 0, 0, llvm::DIType::FlagFwdDecl,
+                                      llvm::DIType(), llvm::DIArray());
+    else if (RD->isStruct())
       return DBuilder.createStructType(FDContext, RD->getName(), DefUnit,
                                        Line, 0, 0, llvm::DIType::FlagFwdDecl,
                                        llvm::DIArray());
@@ -507,12 +512,8 @@
       return DBuilder.createUnionType(FDContext, RD->getName(), DefUnit,
                                       Line, 0, 0, llvm::DIType::FlagFwdDecl,
                                       llvm::DIArray());
-    else {
-      assert(RD->isClass() && "Unknown RecordType!");
-      return DBuilder.createClassType(FDContext, RD->getName(), DefUnit,
-                                      Line, 0, 0, 0, llvm::DIType::FlagFwdDecl,
-                                      llvm::DIType(), llvm::DIArray());
-    }
+    else
+      llvm_unreachable("Unknown RecordDecl type!");
   }
   return getOrCreateType(PointeeTy, Unit);
 
@@ -1175,11 +1176,13 @@
     else if (CXXDecl->isDynamicClass()) 
       ContainingType = FwdDecl;
 
-   RealDecl = DBuilder.createClassType(RDContext, RDName, DefUnit, Line,
-                                       Size, Align, 0, 0, llvm::DIType(),
-                                       Elements, ContainingType,
-                                       TParamsArray);
-  } else 
+    // FIXME: This could be a struct type giving a default visibility different
+    // than C++ class type, but needs llvm metadata changes first.
+    RealDecl = DBuilder.createClassType(RDContext, RDName, DefUnit, Line,
+                                        Size, Align, 0, 0, llvm::DIType(),
+                                        Elements, ContainingType,
+                                        TParamsArray);
+  } else
     RealDecl = DBuilder.createStructType(RDContext, RDName, DefUnit, Line,
                                          Size, Align, 0, Elements);
 

Added: cfe/trunk/test/CodeGenCXX/debug-info-fwd-ref.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-fwd-ref.cpp?rev=146778&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-fwd-ref.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-fwd-ref.cpp Fri Dec 16 17:40:14 2011
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -g %s -o - | FileCheck %s
+
+struct baz {
+    int h;
+    baz(int a) : h(a) {}
+};
+
+struct bar {
+    baz b;
+    baz& b_ref;
+    bar(int x) : b(x), b_ref(b) {}
+};
+
+int main(int argc, char** argv) {
+    bar myBar(1);
+    return 0;
+}
+
+// Make sure we have two DW_TAG_class_types for baz and bar for their forward
+// references.
+// FIXME: These should be struct types to match the declaration.
+// CHECK: !17 = metadata !{i32 720898, null, metadata !"baz", metadata !6, i32 3, i64 0, i64 0, i32 0, i32 4, null, null, i32 0, null, null} ; [ DW_TAG_class_type ]
+// CHECK: !26 = metadata !{i32 720898, null, metadata !"bar", metadata !6, i32 8, i64 0, i64 0, i32 0, i32 4, null, null, i32 0, null, null} ; [ DW_TAG_class_type ]





More information about the cfe-commits mailing list