[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGenCXX/difile_entry.cpp:1
+// RUN: rm -rf %t/test_dir
+// RUN: mkdir -p %t/test_dir

MaskRay wrote:
> @umesh.kalappa0 Can you clarify how this test demonstrates the behavior 
> difference?
> 
> Reverting the code part does not make the test fail.
Seems that absolute path needs to be used. `../test_dir/difile_entry.cpp` 
cannot demonstrate the difference. I'll improve the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87147/new/

https://reviews.llvm.org/D87147

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGenCXX/difile_entry.cpp:1
+// RUN: rm -rf %t/test_dir
+// RUN: mkdir -p %t/test_dir

@umesh.kalappa0 Can you clarify how this test demonstrates the behavior 
difference?

Reverting the code part does not make the test fail.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87147/new/

https://reviews.llvm.org/D87147

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-09 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/CodeGenCXX/difile_entry.cpp:11
+// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", 
scope: {{.*}}, file: [[FILE]]
+// CHECK: {{.*}} = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]]
+

MaskRay wrote:
> The behavior is default triple dependent. `*-windows-msvc` triples use 
> different static constructor mechanism. I fixed the test by adding `-triple 
> %itanium_abi_triple`
Thanks for the fix!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87147/new/

https://reviews.llvm.org/D87147

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/CodeGenCXX/difile_entry.cpp:11
+// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", 
scope: {{.*}}, file: [[FILE]]
+// CHECK: {{.*}} = distinct !DISubprogram(linkageName: 
"_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]]
+

The behavior is default triple dependent. `*-windows-msvc` triples use 
different static constructor mechanism. I fixed the test by adding `-triple 
%itanium_abi_triple`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87147/new/

https://reviews.llvm.org/D87147

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87147: PR-47391 : Two DIFile entries are describing the same file two different ways

2021-01-08 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33c8e16f660d: PR47391: Canonicalize DIFiles (authored by 
umesh.kalappa0, committed by dblaikie).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87147/new/

https://reviews.llvm.org/D87147

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-oslog.c
  clang/test/CodeGenCXX/difile_entry.cpp


Index: clang/test/CodeGenCXX/difile_entry.cpp
===
--- /dev/null
+++ 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]]
+
Index: clang/test/CodeGen/debug-info-oslog.c
===
--- clang/test/CodeGen/debug-info-oslog.c
+++ clang/test/CodeGen/debug-info-oslog.c
@@ -11,5 +11,5 @@
 // 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
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -404,17 +404,23 @@
 }
 
 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 @@
 
   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 CSKind =
-  computeChecksum(PLoc.getFileID(), Checksum);
+  Optional CSKind = computeChecksum(FID, Checksum);
   Optional> CSInfo;
   if (CSKind)
 CSInfo.emplace(*CSKind, Checksum);


Index: clang/test/CodeGenCXX/difile_entry.cpp
===
--- /dev/null
+++ 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]]
+
Index: clang/test/CodeGen/debug-info-oslog.c
===
--- clang/test/CodeGen/debug-info-oslog.c
+++ clang/test/CodeGen/debug-info-oslog.c
@@ -11,5 +11,5 @@
 // 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
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -404,17 +404,23 @@
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
-  if (!Loc.isValid())
-