[llvm-branch-commits] [clang] abfe348 - [test] Improve CodeGenCXX/difile_entry.cpp
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Jan 10 12:28:59 PST 2021
Author: Fangrui Song
Date: 2021-01-10T12:24:49-08:00
New Revision: abfe348e6b4c50c750d70adcf0b99fd3d8d4132e
URL: https://github.com/llvm/llvm-project/commit/abfe348e6b4c50c750d70adcf0b99fd3d8d4132e
DIFF: https://github.com/llvm/llvm-project/commit/abfe348e6b4c50c750d70adcf0b99fd3d8d4132e.diff
LOG: [test] Improve CodeGenCXX/difile_entry.cpp
The test added in D87147 did not actually test PR47391.
Use an absolute path to test the canonicalization.
Added:
Modified:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/difile_entry.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8bc28b28c048..5bdda26a2e8e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -409,6 +409,9 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
FileID FID;
if (Loc.isInvalid()) {
+ // The DIFile used by the CU is distinct from the main source file. Call
+ // createFile() below for canonicalization if the source file was specified
+ // with an absolute path.
FileName = TheCU->getFile()->getFilename();
} else {
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
diff --git a/clang/test/CodeGenCXX/difile_entry.cpp b/clang/test/CodeGenCXX/difile_entry.cpp
index 1ae36e4355ce..8bf6dc325470 100644
--- a/clang/test/CodeGenCXX/difile_entry.cpp
+++ b/clang/test/CodeGenCXX/difile_entry.cpp
@@ -1,12 +1,13 @@
-// RUN: rm -rf %t/test_dir
-// RUN: mkdir -p %t/test_dir
-// RUN: cd %t/test_dir
+/// PR47391: if the filename is absolute and starts with current working
+/// directory, there may be two ways describing the filename field of DIFile.
+/// Test that we canonicalize the DIFile.
+// RUN: rm -rf %t && mkdir %t && cd %t
// RUN: cp %s .
-// RUN: %clang_cc1 -triple %itanium_abi_triple -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
+// RUN: %clang_cc1 -triple %itanium_abi_triple -main-file-name difile_entry.cpp -debug-info-kind=limited %t/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck %s
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]]
-
+// CHECK: distinct !DIGlobalVariable(name: "i", {{.*}}, file: ![[#FILE:]],
+// CHECK: ![[#FILE]] = !DIFile(filename: "difile_entry.cpp", directory:
+// CHECK: distinct !DISubprogram(name: "__cxx_global_var_init", {{.*}}, file: ![[#FILE]],
+// CHECK: distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_difile_entry.cpp", {{.*}}, file: ![[#FILE]]
More information about the llvm-branch-commits
mailing list