summaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2013-08-08 07:40:37 +0000
committerEric Christopher <echristo@gmail.com>2013-08-08 07:40:37 +0000
commitdc1363f5af47542a602c80e726749bc06d8ef3f8 (patch)
tree1a40cc31a04e00da38310920dd3d125dbcf8b92c /lib/CodeGen
parentafdd1f8a851349e2b3cdc6d441043ac3f4cdb9b9 (diff)
downloadllvm-dc1363f5af47542a602c80e726749bc06d8ef3f8.tar.gz
llvm-dc1363f5af47542a602c80e726749bc06d8ef3f8.tar.bz2
llvm-dc1363f5af47542a602c80e726749bc06d8ef3f8.tar.xz
Make sure that if we're going to attempt to add a type to a DIE that
the type exists. Fix up cases where we weren't checking for optional types and add an assert to addType to make sure we catch this in the future. Fix up a testcase that was using the tag for DW_TAG_array_type when it meant DW_TAG_enumeration_type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187963 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 0c9bc23a9e..2937b9019c 100644
--- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -776,8 +776,7 @@ DIE *CompileUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
/// addType - Add a new type attribute to the specified entity.
void CompileUnit::addType(DIE *Entity, DIType Ty, uint16_t Attribute) {
- if (!Ty.isType())
- return;
+ assert(Ty && "Trying to add a type that doesn't exist?");
// Check for pre-existence.
DIEEntry *Entry = getDIEEntry(Ty);
@@ -863,7 +862,8 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
// Map to main type, void will not have a type.
DIType FromTy = DTy.getTypeDerivedFrom();
- addType(&Buffer, FromTy);
+ if (FromTy)
+ addType(&Buffer, FromTy);
// Add name if not anonymous or intermediate type.
if (!Name.empty())
@@ -947,10 +947,11 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
}
break;
case dwarf::DW_TAG_subroutine_type: {
- // Add return type.
+ // Add return type. A void return won't have a type.
DIArray Elements = CTy.getTypeArray();
DIDescriptor RTy = Elements.getElement(0);
- addType(&Buffer, DIType(RTy));
+ if (RTy)
+ addType(&Buffer, DIType(RTy));
bool isPrototyped = true;
// Add arguments.
@@ -1137,7 +1138,11 @@ CompileUnit::getOrCreateTemplateValueParameterDIE(DITemplateValueParameter VP) {
return ParamDIE;
ParamDIE = new DIE(VP.getTag());
- addType(ParamDIE, VP.getType());
+
+ // Add the type if there is one, template template and template parameter
+ // packs will not have a type.
+ if (VP.getType())
+ addType(ParamDIE, VP.getType());
if (!VP.getName().empty())
addString(ParamDIE, dwarf::DW_AT_name, VP.getName());
if (Value *Val = VP.getValue()) {
@@ -1246,13 +1251,14 @@ DIE *CompileUnit::getOrCreateSubprogramDIE(DISubprogram SP) {
Language == dwarf::DW_LANG_ObjC))
addFlag(SPDie, dwarf::DW_AT_prototyped);
- // Add Return Type.
+ // Add Return Type. A void return type will not have a type.
DICompositeType SPTy = SP.getType();
assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type &&
"the type of a subprogram should be a subroutine");
DIArray Args = SPTy.getTypeArray();
- addType(SPDie, DIType(Args.getElement(0)));
+ if (Args.getElement(0))
+ addType(SPDie, DIType(Args.getElement(0)));
unsigned VK = SP.getVirtuality();
if (VK) {
@@ -1502,9 +1508,8 @@ void CompileUnit::constructArrayTypeDIE(DIE &Buffer,
if (CTy->isVector())
addFlag(&Buffer, dwarf::DW_AT_GNU_vector);
- // Emit derived type.
+ // Emit the element type.
addType(&Buffer, CTy->getTypeDerivedFrom());
- DIArray Elements = CTy->getTypeArray();
// Get an anonymous type for index type.
// FIXME: This type should be passed down from the front end
@@ -1522,6 +1527,7 @@ void CompileUnit::constructArrayTypeDIE(DIE &Buffer,
}
// Add subranges to array type.
+ DIArray Elements = CTy->getTypeArray();
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIDescriptor Element = Elements.getElement(i);
if (Element.getTag() == dwarf::DW_TAG_subrange_type)