Skip to content

Commit 443f677

Browse files
author
Anders Carlsson
committed
Simplify the debug info code, handle lvalue references and template specializations.
llvm-svn: 86277
1 parent c2d71b5 commit 443f677

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,32 +242,37 @@ llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit U
242242

243243
llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
244244
llvm::DICompileUnit Unit) {
245-
llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit);
246-
247-
// Bit size, align and offset of the type.
248-
uint64_t Size = M->getContext().getTypeSize(Ty);
249-
uint64_t Align = M->getContext().getTypeAlign(Ty);
250-
251245
llvm::DIType DbgTy =
252-
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
253-
"", llvm::DICompileUnit(),
254-
0, Size, Align, 0, 0, EltTy);
246+
CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
247+
Ty->getPointeeType(), Unit);
255248
TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
256249
return DbgTy;
257250
}
258251

259252
llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
260253
llvm::DICompileUnit Unit) {
261-
llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit);
254+
return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
255+
Ty->getPointeeType(), Unit);
256+
}
257+
258+
llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag,
259+
const Type *Ty,
260+
QualType PointeeTy,
261+
llvm::DICompileUnit Unit) {
262+
llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit);
262263

263264
// Bit size, align and offset of the type.
264-
uint64_t Size = M->getContext().getTypeSize(Ty);
265+
266+
// Size is always the size of a pointer. We can't use getTypeSize here
267+
// because that does not return the correct value for references.
268+
uint64_t Size =
269+
M->getContext().Target.getPointerWidth(PointeeTy.getAddressSpace());
265270
uint64_t Align = M->getContext().getTypeAlign(Ty);
266271

267272
return
268-
DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
269-
"", llvm::DICompileUnit(),
273+
DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
270274
0, Size, Align, 0, 0, EltTy);
275+
271276
}
272277

273278
llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
@@ -802,6 +807,11 @@ llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
802807
return DbgTy;
803808
}
804809

810+
llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty,
811+
llvm::DICompileUnit Unit) {
812+
return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type,
813+
Ty, Ty->getPointeeType(), Unit);
814+
}
805815

806816
/// getOrCreateType - Get the type from the cache or create a new
807817
/// one if necessary.
@@ -890,6 +900,14 @@ llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty,
890900
return CreateTypeNode(T->getReplacementType(), Unit);
891901
}
892902

903+
case Type::TemplateSpecialization: {
904+
const TemplateSpecializationType *T = cast<TemplateSpecializationType>(Ty);
905+
return CreateTypeNode(T->desugar(), Unit);
906+
}
907+
908+
case Type::LValueReference:
909+
return CreateType(cast<LValueReferenceType>(Ty), Unit);
910+
893911
}
894912
}
895913

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class CGDebugInfo {
7373
llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U);
7474
llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U);
7575
llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U);
76+
llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U);
7677

78+
llvm::DIType CreatePointerLikeType(unsigned Tag,
79+
const Type *Ty, QualType PointeeTy,
80+
llvm::DICompileUnit U);
7781
public:
7882
CGDebugInfo(CodeGenModule *m);
7983
~CGDebugInfo();

clang/test/CodeGenCXX/debug-info.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ template<typename T> struct Identity {
44
};
55

66
void f(Identity<int>::Type a) {}
7+
void f(Identity<int> a) {}
8+
void f(int& a) { }

0 commit comments

Comments
 (0)