Add support for enum forward declarations.

Part of rdar://11570854

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157786 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2012-06-01 00:22:32 +00:00
parent 547d8045fb
commit fc4199bf4a
4 changed files with 34 additions and 9 deletions

View File

@ -329,10 +329,12 @@ namespace llvm {
/// @param SizeInBits Member size.
/// @param AlignInBits Member alignment.
/// @param Elements Enumeration elements.
/// @param Flags Flags (e.g. forward decl)
DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
DIFile File, unsigned LineNumber,
uint64_t SizeInBits, uint64_t AlignInBits,
DIArray Elements, DIType ClassType);
DIArray Elements, DIType ClassType,
unsigned Flags);
/// createSubroutineType - Create subroutine type.
/// @param File File in which this subroutine is defined.

View File

@ -549,7 +549,7 @@ DIType DIBuilder::createEnumerationType(DIDescriptor Scope, StringRef Name,
uint64_t SizeInBits,
uint64_t AlignInBits,
DIArray Elements,
DIType ClassType) {
DIType ClassType, unsigned Flags) {
// TAG_enumeration_type is encoded in DICompositeType format.
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_enumeration_type),
@ -560,7 +560,7 @@ DIType DIBuilder::createEnumerationType(DIDescriptor Scope, StringRef Name,
ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
ConstantInt::get(Type::getInt32Ty(VMContext), 0),
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
ClassType,
Elements,
ConstantInt::get(Type::getInt32Ty(VMContext), 0),

View File

@ -935,15 +935,16 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
Tag == dwarf::DW_TAG_structure_type ||
Tag == dwarf::DW_TAG_union_type) {
// Add size if non-zero (derived types might be zero-sized.)
// TODO: Do we care about size for enum forward declarations?
if (Size)
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, Size);
else {
else if (!CTy.isForwardDecl())
// Add zero size if it is not a forward declaration.
if (CTy.isForwardDecl())
addUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
else
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0);
}
addUInt(&Buffer, dwarf::DW_AT_byte_size, 0, 0);
// If we're a forward decl, say so.
if (CTy.isForwardDecl())
addUInt(&Buffer, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
// Add source line info if available.
if (!CTy.isForwardDecl())

View File

@ -0,0 +1,22 @@
; RUN: llc -O0 -mtriple=x86_64-apple-darwin %s -o %t -filetype=obj
; RUN: llvm-dwarfdump %t | FileCheck %s
@e = global i16 0, align 2
!llvm.dbg.cu = !{!0}
!0 = metadata !{i32 786449, i32 0, i32 4, metadata !"foo.cpp", metadata !"/Users/echristo/tmp", metadata !"clang version 3.2 (trunk 157772) (llvm/trunk 157761)", i1 true, i1 false, metadata !"", i32 0, metadata !1, metadata !6, metadata !6, metadata !7} ; [ DW_TAG_compile_unit ]
!1 = metadata !{metadata !2}
!2 = metadata !{metadata !3}
!3 = metadata !{i32 786436, null, metadata !"E", metadata !4, i32 1, i64 16, i64 16, i32 0, i32 4, null, metadata !5, i32 0, i32 0} ; [ DW_TAG_enumeration_type ]
!4 = metadata !{i32 786473, metadata !"foo.cpp", metadata !"/Users/echristo/tmp", null} ; [ DW_TAG_file_type ]
!5 = metadata !{i32 0}
!6 = metadata !{metadata !5}
!7 = metadata !{metadata !8}
!8 = metadata !{metadata !9}
!9 = metadata !{i32 786484, i32 0, null, metadata !"e", metadata !"e", metadata !"", metadata !4, i32 2, metadata !3, i32 0, i32 1, i16* @e} ; [ DW_TAG_variable ]
; CHECK: DW_TAG_enumeration_type
; CHECK-NEXT: DW_AT_name
; CHECK-NEXT: DW_AT_byte_size
; CHECK-NEXT: DW_AT_declaration