[test] Improve CodeGenCXX/difile_entry.cpp
authorFangrui Song <i@maskray.me>
Sun, 10 Jan 2021 20:24:49 +0000 (12:24 -0800)
committerFangrui Song <i@maskray.me>
Sun, 10 Jan 2021 20:24:49 +0000 (12:24 -0800)
The test added in D87147 did not actually test PR47391.
Use an absolute path to test the canonicalization.

clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/difile_entry.cpp

index 8bc28b2..5bdda26 100644 (file)
@@ -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);
index 1ae36e4..8bf6dc3 100644 (file)
@@ -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]]