summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUmesh Kalappa <umesh.kalappa0@gmail.com>2021-01-08 21:41:13 -0800
committerDavid Blaikie <dblaikie@gmail.com>2021-01-08 22:11:16 -0800
commit33c8e16f660de9bbe177c1bf821063c146278d8e (patch)
tree88ce028c56088c48b00c9439b22dacd7bbbff7ab
parent04359eece132d5406be24cddd0df55b0b9bffdc1 (diff)
downloadllvm-33c8e16f660de9bbe177c1bf821063c146278d8e.tar.gz
PR47391: Canonicalize DIFiles
Like @aprantl suggested, modify to use the canonicalized DIFile, if we don't know the loc info and filename for the compiler generated functions for example static initialization functions. Reviewed By: dblaikie, aprantl Differential Revision: https://reviews.llvm.org/D87147
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp30
-rw-r--r--clang/test/CodeGen/debug-info-oslog.c2
-rw-r--r--clang/test/CodeGenCXX/difile_entry.cpp12
3 files changed, 29 insertions, 15 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7b20d43b0f17..8bc28b28c048 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -404,17 +404,23 @@ Optional<StringRef> CGDebugInfo::getSource(const SourceManager &SM,
}
llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
- if (!Loc.isValid())
- // If Location is not valid then use main input file.
- return TheCU->getFile();
-
SourceManager &SM = CGM.getContext().getSourceManager();
- PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+ StringRef FileName;
+ FileID FID;
- StringRef FileName = PLoc.getFilename();
- if (PLoc.isInvalid() || FileName.empty())
- // If the location is not valid then use main input file.
- return TheCU->getFile();
+ if (Loc.isInvalid()) {
+ FileName = TheCU->getFile()->getFilename();
+ } else {
+ PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+ FileName = PLoc.getFilename();
+
+ if (FileName.empty()) {
+ FileName = TheCU->getFile()->getFilename();
+ } else {
+ FileName = PLoc.getFilename();
+ }
+ FID = PLoc.getFileID();
+ }
// Cache the results.
auto It = DIFileCache.find(FileName.data());
@@ -426,11 +432,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
SmallString<32> Checksum;
- // Compute the checksum if possible. If the location is affected by a #line
- // directive that refers to a file, PLoc will have an invalid FileID, and we
- // will correctly get no checksum.
- Optional<llvm::DIFile::ChecksumKind> CSKind =
- computeChecksum(PLoc.getFileID(), Checksum);
+ Optional<llvm::DIFile::ChecksumKind> CSKind = computeChecksum(FID, Checksum);
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
if (CSKind)
CSInfo.emplace(*CSKind, Checksum);
diff --git a/clang/test/CodeGen/debug-info-oslog.c b/clang/test/CodeGen/debug-info-oslog.c
index c32c79eb8a6f..11a1cd64dedf 100644
--- a/clang/test/CodeGen/debug-info-oslog.c
+++ b/clang/test/CodeGen/debug-info-oslog.c
@@ -11,5 +11,5 @@ void test_builtin_os_log(void *buf, int i, const char *data) {
// number between file and type.
// CHECK: distinct !DISubprogram(name: "__os_log_helper_1_0_1_4_0",
-// CHECK-SAME: file: !{{[0-9+]}}, type
+// CHECK-SAME: file: !{{.*}}, type
// CHECK-SAME: flags: DIFlagArtificial
diff --git a/clang/test/CodeGenCXX/difile_entry.cpp b/clang/test/CodeGenCXX/difile_entry.cpp
new file mode 100644
index 000000000000..9ef80fe8184c
--- /dev/null
+++ b/clang/test/CodeGenCXX/difile_entry.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t/test_dir
+// RUN: mkdir -p %t/test_dir
+// RUN: cd %t/test_dir
+// RUN: cp %s .
+// RUN: %clang_cc1 -main-file-name difile_entry.cpp -debug-info-kind=limited ../test_dir/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck ../test_dir/difile_entry.cpp
+int x();
+static int i = x();
+
+// CHECK: [[FILE: *]] = !DIFile(filename: "{{.*}}difile_entry.cpp",
+// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", scope: {{.*}}, file: [[FILE]]
+// CHECK: {{.*}} = distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]]
+