r208114 - Reapply: DebugInfo: Emit the definition of enums when the definition preceeds the declaration and initial use.
David Blaikie
dblaikie at gmail.com
Tue May 6 11:35:21 PDT 2014
Author: dblaikie
Date: Tue May 6 13:35:21 2014
New Revision: 208114
URL: http://llvm.org/viewvc/llvm-project?rev=208114&view=rev
Log:
Reapply: DebugInfo: Emit the definition of enums when the definition preceeds the declaration and initial use.
Reverting r208106 to reapply r208065 with a fix for the regression. The
issue was that the enum tried to be built even if the declaration hadn't
been constructed for debug info - presenting problems for enum templates
and typedefs of enums with names for linkage purposes.
Original commit message:
This regressed a little further 208055 though it was already a little
broken.
While the requiresCompleteType optimization should be implemented here.
Future (possibly near future) work.
Added:
cfe/trunk/test/CodeGen/debug-info-enum.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/test/CodeGenCXX/debug-info-enum-class.cpp
cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=208114&r1=208113&r2=208114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue May 6 13:35:21 2014
@@ -1427,6 +1427,21 @@ llvm::DIType CGDebugInfo::getOrCreateInt
return T;
}
+void CGDebugInfo::completeType(const EnumDecl *ED) {
+ if (DebugKind <= CodeGenOptions::DebugLineTablesOnly)
+ return;
+ QualType Ty = CGM.getContext().getEnumType(ED);
+ void* TyPtr = Ty.getAsOpaquePtr();
+ auto I = TypeCache.find(TyPtr);
+ if (I == TypeCache.end() ||
+ !llvm::DIType(cast<llvm::MDNode>(static_cast<llvm::Value *>(I->second)))
+ .isForwardDecl())
+ return;
+ llvm::DIType Res = CreateTypeDefinition(Ty->castAs<EnumType>());
+ assert(!Res.isForwardDecl());
+ TypeCache[TyPtr] = Res;
+}
+
void CGDebugInfo::completeType(const RecordDecl *RD) {
if (DebugKind > CodeGenOptions::LimitedDebugInfo ||
!CGM.getLangOpts().CPlusPlus)
@@ -1915,6 +1930,20 @@ llvm::DIType CGDebugInfo::CreateEnumType
return RetTy;
}
+ return CreateTypeDefinition(Ty);
+}
+
+llvm::DIType CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
+ const EnumDecl *ED = Ty->getDecl();
+ uint64_t Size = 0;
+ uint64_t Align = 0;
+ if (!ED->getTypeForDecl()->isIncompleteType()) {
+ Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
+ Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
+ }
+
+ SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
+
// Create DIEnumerator elements for each enumerator.
SmallVector<llvm::Value *, 16> Enumerators;
ED = ED->getDefinition();
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=208114&r1=208113&r2=208114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue May 6 13:35:21 2014
@@ -135,6 +135,7 @@ class CGDebugInfo {
llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
llvm::DIType CreateType(const AtomicType *Ty, llvm::DIFile F);
llvm::DIType CreateEnumType(const EnumType *Ty);
+ llvm::DIType CreateTypeDefinition(const EnumType *Ty);
llvm::DIType CreateSelfType(const QualType &QualTy, llvm::DIType Ty);
llvm::DIType getTypeOrNull(const QualType);
llvm::DICompositeType getOrCreateMethodType(const CXXMethodDecl *Method,
@@ -295,6 +296,7 @@ public:
llvm::DIType getOrCreateInterfaceType(QualType Ty,
SourceLocation Loc);
+ void completeType(const EnumDecl *ED);
void completeType(const RecordDecl *RD);
void completeRequiredType(const RecordDecl *RD);
void completeClassData(const RecordDecl *RD);
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=208114&r1=208113&r2=208114&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Tue May 6 13:35:21 2014
@@ -242,6 +242,10 @@ void CodeGenTypes::UpdateCompletedType(c
if (!ConvertType(ED->getIntegerType())->isIntegerTy(32))
TypeCache.clear();
}
+ // If necessary, provide the full definition of a type only used with a
+ // declaration so far.
+ if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
+ DI->completeType(ED);
return;
}
Added: cfe/trunk/test/CodeGen/debug-info-enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-enum.c?rev=208114&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-enum.c (added)
+++ cfe/trunk/test/CodeGen/debug-info-enum.c Tue May 6 13:35:21 2014
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -emit-llvm -g %s -o - | FileCheck %s
+
+// CHECK: metadata [[TEST3_ENUMS:![0-9]*]], {{[^,]*}}, null, null, null} ; [ DW_TAG_enumeration_type ] [e]
+// CHECK: [[TEST3_ENUMS]] = metadata !{metadata [[TEST3_E:![0-9]*]]}
+// CHECK: [[TEST3_E]] = {{.*}}, metadata !"E", i64 -1} ; [ DW_TAG_enumerator ] [E :: -1]
+
+enum e;
+void func(enum e *p) {
+}
+enum e { E = -1 };
Modified: cfe/trunk/test/CodeGenCXX/debug-info-enum-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-enum-class.cpp?rev=208114&r1=208113&r2=208114&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-enum-class.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-enum-class.cpp Tue May 6 13:35:21 2014
@@ -12,7 +12,6 @@ D d;
// CHECK: ; [ DW_TAG_enumeration_type ] [A] [line 3, size 32, align 32, offset 0] [def] [from int]
// CHECK: ; [ DW_TAG_enumeration_type ] [B] [line 4, size 64, align 64, offset 0] [def] [from long unsigned int]
// CHECK: ; [ DW_TAG_enumeration_type ] [C] [line 5, size 32, align 32, offset 0] [def] [from ]
-// CHECK: ; [ DW_TAG_enumeration_type ] [D] [line 6, size 16, align 16, offset 0] [decl] [from ]
namespace PR14029 {
// Make sure this doesn't crash/assert.
@@ -27,3 +26,54 @@ namespace PR14029 {
};
Test<int> t;
}
+
+namespace test2 {
+// FIXME: this should just be a declaration under -fno-standalone-debug
+// CHECK: metadata !{i32 {{[^,]*}}, {{[^,]*}}, metadata [[TEST2:![0-9]*]], {{.*}}, metadata [[TEST_ENUMS:![0-9]*]], {{[^,]*}}, null, null, metadata !"_ZTSN5test21EE"} ; [ DW_TAG_enumeration_type ] [E]
+// CHECK: [[TEST2]] = {{.*}} ; [ DW_TAG_namespace ] [test2]
+// CHECK: [[TEST_ENUMS]] = metadata !{metadata [[TEST_E:![0-9]*]]}
+// CHECK: [[TEST_E]] = {{.*}}, metadata !"e", i64 0} ; [ DW_TAG_enumerator ] [e :: 0]
+enum E : int;
+void func(E *) {
+}
+enum E : int { e };
+}
+
+namespace test3 {
+// FIXME: this should just be a declaration under -fno-standalone-debug
+// CHECK: metadata !{i32 {{[^,]*}}, {{[^,]*}}, metadata [[TEST3:![0-9]*]], {{.*}}, metadata [[TEST_ENUMS]], {{[^,]*}}, null, null, metadata !"_ZTSN5test31EE"} ; [ DW_TAG_enumeration_type ] [E]
+// CHECK: [[TEST3]] = {{.*}} ; [ DW_TAG_namespace ] [test3]
+enum E : int { e };
+void func(E *) {
+}
+}
+
+namespace test4 {
+// CHECK: metadata !{i32 {{[^,]*}}, {{[^,]*}}, metadata [[TEST4:![0-9]*]], {{.*}}, metadata [[TEST_ENUMS]], {{[^,]*}}, null, null, metadata !"_ZTSN5test41EE"} ; [ DW_TAG_enumeration_type ] [E]
+// CHECK: [[TEST4]] = {{.*}} ; [ DW_TAG_namespace ] [test4]
+enum E : int;
+void f1(E *) {
+}
+enum E : int { e };
+void f2(E) {
+}
+}
+
+// CHECK: ; [ DW_TAG_enumeration_type ] [D] [line 6, size 16, align 16, offset 0] [decl] [from ]
+
+namespace test5 {
+// CHECK: metadata !{i32 {{[^,]*}}, {{[^,]*}}, metadata [[TEST5:![0-9]*]], {{.*}}, null, {{[^,]*}}, null, null, metadata !"_ZTSN5test51EE"} ; [ DW_TAG_enumeration_type ] [E]
+// CHECK: [[TEST5]] = {{.*}} ; [ DW_TAG_namespace ] [test5]
+enum E : int;
+void f1(E *) {
+}
+}
+
+namespace test6 {
+// Ensure typedef'd enums aren't manifest by debug info generation.
+// This could cause "typedef changes linkage of anonymous type, but linkage was
+// already computed" errors.
+// CHECK-NOT: test7
+typedef enum {
+} E;
+}
Modified: cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp?rev=208114&r1=208113&r2=208114&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp Tue May 6 13:35:21 2014
@@ -34,3 +34,12 @@ void func() {
e x;
}
}
+
+namespace test4 {
+// Don't try to build debug info for a dependent enum.
+// CHECK-NOT: test4
+template <typename T>
+struct S {
+ enum e { E = T::v };
+};
+}
More information about the cfe-commits
mailing list