0037-clang-Call-printName-to-get-name-of-Decl.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From d33d6a8c4f43907cb53130730a2bc48624a34b74 Mon Sep 17 00:00:00 2001
  2. From: Dan McGregor <dan.mcgregor@usask.ca>
  3. Date: Tue, 21 Mar 2023 13:04:51 -0600
  4. Subject: [PATCH] [clang] Call printName to get name of Decl
  5. Rather than sending a name directly to the stream, use printName
  6. to preserve any PrintingPolicy. This ensures that names are properly
  7. affected by path remapping.
  8. Differential Revision: https://reviews.llvm.org/D149272
  9. Upstream-Status: Pending
  10. ---
  11. clang/lib/AST/Decl.cpp | 4 ++--
  12. clang/lib/AST/DeclarationName.cpp | 4 ++--
  13. clang/test/CodeGen/debug-prefix-map.cpp | 11 +++++++++++
  14. 3 files changed, 15 insertions(+), 4 deletions(-)
  15. create mode 100644 clang/test/CodeGen/debug-prefix-map.cpp
  16. diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
  17. index e60cc28f6e0f..24de6156c0f5 100644
  18. --- a/clang/lib/AST/Decl.cpp
  19. +++ b/clang/lib/AST/Decl.cpp
  20. @@ -1626,8 +1626,8 @@ Module *Decl::getOwningModuleForLinkage(bool IgnoreLinkage) const {
  21. llvm_unreachable("unknown module kind");
  22. }
  23. -void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy&) const {
  24. - OS << Name;
  25. +void NamedDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const {
  26. + Name.print(OS, Policy);
  27. }
  28. void NamedDecl::printName(raw_ostream &OS) const {
  29. diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp
  30. index c1219041a466..da8b3886c340 100644
  31. --- a/clang/lib/AST/DeclarationName.cpp
  32. +++ b/clang/lib/AST/DeclarationName.cpp
  33. @@ -117,12 +117,12 @@ static void printCXXConstructorDestructorName(QualType ClassType,
  34. Policy.adjustForCPlusPlus();
  35. if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) {
  36. - OS << *ClassRec->getDecl();
  37. + ClassRec->getDecl()->printName(OS, Policy);
  38. return;
  39. }
  40. if (Policy.SuppressTemplateArgsInCXXConstructors) {
  41. if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) {
  42. - OS << *InjTy->getDecl();
  43. + InjTy->getDecl()->printName(OS, Policy);
  44. return;
  45. }
  46. }
  47. diff --git a/clang/test/CodeGen/debug-prefix-map.cpp b/clang/test/CodeGen/debug-prefix-map.cpp
  48. new file mode 100644
  49. index 000000000000..7ddaee531282
  50. --- /dev/null
  51. +++ b/clang/test/CodeGen/debug-prefix-map.cpp
  52. @@ -0,0 +1,11 @@
  53. +// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
  54. +
  55. +struct alignas(64) an {
  56. + struct {
  57. + unsigned char x{0};
  58. + } arr[64];
  59. +};
  60. +
  61. +struct an *pan = new an;
  62. +
  63. +// CHECK: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}",