[to cfe-commits, bcc llvm-commits]
Sorry, got the wrong list.
On 9 November 2011 16:47, Nick Lewycky <[email protected]> wrote:
> This patch fixes PR11345, a case where we emit debug info for a class,
> just because we define a static member inside the class. This is
> implemented by changing getContextDescriptor() to use a newly refactored
> getTypeOrFwdDecl() method, instead of always requiring a full definition.
>
> Please review! In particular, this patch causes the code that emits
> pointers which used to always emit a new fwd-decl of the record type, to
> now use the full type if that type is already defined and emitted. I don't
> think this has any ill effects, but it's difficult to prove.
>
> Nick
>
>
Index: test/CodeGenCXX/debug-elide-fn.cpp
===================================================================
--- test/CodeGenCXX/debug-elide-fn.cpp (revision 0)
+++ test/CodeGenCXX/debug-elide-fn.cpp (revision 0)
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -g -emit-llvm -o - | FileCheck %s
+// PR11345
+
+// CHECK-NOT: _M_add_reference
+
+class locale {
+private:
+ void _M_add_reference() const throw() {
+ }
+};
+class ios_base {
+ locale _M_ios_locale;
+public:
+ class Init {
+ };
+};
+static ios_base::Init __ioinit;
+
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h (revision 144248)
+++ lib/CodeGen/CGDebugInfo.h (working copy)
@@ -244,6 +244,10 @@
/// getOrCreateMainFile - Get the file info for main compile unit.
llvm::DIFile getOrCreateMainFile();
+ /// getTypeOrFwdDecl - Get the type from the cache if it's there, or create
+ /// a forward declaration and return that.
+ llvm::DIType getTypeOrFwdDecl(QualType Ty, llvm::DIFile F);
+
/// getOrCreateType - Get the type from the cache or create a new type if
/// necessary.
llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F);
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp (revision 144248)
+++ lib/CodeGen/CGDebugInfo.cpp (working copy)
@@ -104,8 +104,8 @@
if (const RecordDecl *RDecl = dyn_cast<RecordDecl>(Context)) {
if (!RDecl->isDependentType()) {
- llvm::DIType Ty = getOrCreateType(CGM.getContext().getTypeDeclType(RDecl),
- getOrCreateMainFile());
+ llvm::DIType Ty = getTypeOrFwdDecl(
+ CGM.getContext().getTypeDeclType(RDecl), getOrCreateMainFile());
return llvm::DIDescriptor(Ty);
}
}
@@ -486,36 +486,12 @@
if (!CGM.getCodeGenOpts().LimitDebugInfo)
return getOrCreateType(PointeeTy, Unit);
- // Limit debug info for the pointee type.
-
// Handle qualifiers.
if (PointeeTy.hasLocalQualifiers())
return CreateQualifiedType(PointeeTy, Unit);
- if (const RecordType *RTy = dyn_cast<RecordType>(PointeeTy)) {
- RecordDecl *RD = RTy->getDecl();
- llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
- unsigned Line = getLineNumber(RD->getLocation());
- llvm::DIDescriptor FDContext =
- getContextDescriptor(cast<Decl>(RD->getDeclContext()));
-
- if (RD->isStruct())
- return DBuilder.createStructType(FDContext, RD->getName(), DefUnit,
- Line, 0, 0, llvm::DIType::FlagFwdDecl,
- llvm::DIArray());
- else if (RD->isUnion())
- 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());
- }
- }
- return getOrCreateType(PointeeTy, Unit);
-
+ // Limit debug info for the pointee type.
+ return getTypeOrFwdDecl(PointeeTy, Unit);
}
llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag,
@@ -1559,6 +1535,55 @@
return T;
}
+/// getTypeOrFwdDecl - Get the type from the cache or create a new forward
+/// declaration if none is available.
+llvm::DIType CGDebugInfo::getTypeOrFwdDecl(QualType Ty, llvm::DIFile Unit) {
+ if (Ty.isNull())
+ return llvm::DIType();
+
+ // Unwrap the type as needed for debug information.
+ Ty = UnwrapTypeForDebugInfo(Ty);
+
+ // Check for existing entry.
+ llvm::DenseMap<void *, llvm::WeakVH>::iterator it =
+ TypeCache.find(Ty.getAsOpaquePtr());
+ if (it != TypeCache.end()) {
+ // Verify that the debug info still exists.
+ if (&*it->second)
+ return llvm::DIType(cast<llvm::MDNode>(it->second));
+ }
+
+ // If we can emit a forward-decl, do so.
+ if (const RecordType *RTy = dyn_cast<RecordType>(Ty)) {
+ RecordDecl *RD = RTy->getDecl();
+ llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
+ unsigned Line = getLineNumber(RD->getLocation());
+ llvm::DIDescriptor FDContext =
+ getContextDescriptor(cast<Decl>(RD->getDeclContext()));
+
+ if (RD->isStruct())
+ return DBuilder.createStructType(FDContext, RD->getName(), DefUnit,
+ Line, 0, 0, llvm::DIType::FlagFwdDecl,
+ llvm::DIArray());
+ if (RD->isUnion())
+ return DBuilder.createUnionType(FDContext, RD->getName(), DefUnit,
+ Line, 0, 0, llvm::DIType::FlagFwdDecl,
+ llvm::DIArray());
+
+ assert(RD->isClass() && "Unknown RecordType!");
+ return DBuilder.createClassType(FDContext, RD->getName(), DefUnit,
+ Line, 0, 0, 0, llvm::DIType::FlagFwdDecl,
+ llvm::DIType(), llvm::DIArray());
+ }
+
+ // Otherwise create the type.
+ llvm::DIType Res = CreateTypeNode(Ty, Unit);
+
+ // And update the type cache.
+ TypeCache[Ty.getAsOpaquePtr()] = Res;
+ return Res;
+}
+
/// getOrCreateType - Get the type from the cache or create a new
/// one if necessary.
llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits