]> granicus.if.org Git - clang/commitdiff
Debug info: use the file a typedef is defined in as its decl_file instead
authorAdrian Prantl <aprantl@apple.com>
Tue, 21 Jan 2014 18:20:52 +0000 (18:20 +0000)
committerAdrian Prantl <aprantl@apple.com>
Tue, 21 Jan 2014 18:20:52 +0000 (18:20 +0000)
of the current compilation unit.
As a side effect this enables many more LTO uniquing opportunities.

rdar://problem/15851206

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199757 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
test/CodeGen/debug-info-typedef.c [new file with mode: 0644]
test/CodeGen/debug-info-typedef.h [new file with mode: 0644]

index faf6fbba1a450eebc0c21ebf397659d669507ff9..ff17a03dccd7db5dad787cefca118a758e1a796a 100644 (file)
@@ -739,14 +739,16 @@ llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile Unit) {
     return llvm::DIType();
   // We don't set size information, but do specify where the typedef was
   // declared.
-  unsigned Line = getLineNumber(Ty->getDecl()->getLocation());
+  SourceLocation Loc = Ty->getDecl()->getLocation();
+  llvm::DIFile File = getOrCreateFile(Loc);
+  unsigned Line = getLineNumber(Loc);
   const TypedefNameDecl *TyDecl = Ty->getDecl();
 
   llvm::DIDescriptor TypedefContext =
     getContextDescriptor(cast<Decl>(Ty->getDecl()->getDeclContext()));
 
   return
-    DBuilder.createTypedef(Src, TyDecl->getName(), Unit, Line, TypedefContext);
+    DBuilder.createTypedef(Src, TyDecl->getName(), File, Line, TypedefContext);
 }
 
 llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty,
diff --git a/test/CodeGen/debug-info-typedef.c b/test/CodeGen/debug-info-typedef.c
new file mode 100644 (file)
index 0000000..c3adcf1
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -emit-llvm -g -I%p %s -o - | FileCheck %s
+// Test that the location of the typedef points to the header file.
+#include "typedef.h"
+
+MyType a;
+
+// CHECK: metadata ![[HEADER:[0-9]+]]} ; [ DW_TAG_typedef ] [MyType] [line 1, size 0, align 0, offset 0] [from int]
+// CHECK: ![[HEADER]] = {{.*}}debug-info-typedef.h",
diff --git a/test/CodeGen/debug-info-typedef.h b/test/CodeGen/debug-info-typedef.h
new file mode 100644 (file)
index 0000000..afdb9fb
--- /dev/null
@@ -0,0 +1,2 @@
+typedef int MyType;
+