Reikriam

clang patch

May 8th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
  2. index 6a3d2b30e46..145d9909dbb 100644
  3. --- a/clang/lib/AST/TemplateBase.cpp
  4. +++ b/clang/lib/AST/TemplateBase.cpp
  5. @@ -352,7 +352,37 @@ void TemplateArgument::print(const PrintingPolicy &Policy,
  6.  
  7. case Declaration: {
  8. NamedDecl *ND = getAsDecl();
  9. - if (!getParamTypeForDecl()->isReferenceType())
  10. + bool needsRef = true;
  11. + if (auto *VD = dyn_cast<ValueDecl>(ND)) {
  12. + const clang::Type *ArgTy = VD->getType()->getUnqualifiedDesugaredType();
  13. + const clang::Type *ParmTy =
  14. + getParamTypeForDecl()->getUnqualifiedDesugaredType();
  15. + clang::ASTContext &Ctx = ND->getASTContext();
  16. + needsRef = !Ctx.hasSameType(ArgTy, ParmTy);
  17. + if (needsRef && (ArgTy->isArrayType() || ArgTy->isFunctionType())) {
  18. + const clang::Type *decayedArgTy =
  19. + Ctx.getDecayedType(clang::QualType(ArgTy, 0)).getTypePtr();
  20. + needsRef = !Ctx.hasSameType(decayedArgTy, ParmTy);
  21. + if (!needsRef) {
  22. + int deptharg = 0, depthparam = 0;
  23. + clang::QualType NestArgTy = VD->getType();
  24. + while (const auto *Array =
  25. + dyn_cast<ArrayType>(NestArgTy.getCanonicalType())) {
  26. + deptharg++;
  27. + NestArgTy = Array->getElementType();
  28. + }
  29. + clang::QualType NestParmTy = getParamTypeForDecl();
  30. + while (const auto *Array =
  31. + dyn_cast<ArrayType>(NestParmTy.getCanonicalType())) {
  32. + depthparam++;
  33. + NestParmTy = Array->getElementType();
  34. + }
  35. + if ((deptharg > 0) && (depthparam > 0) && (deptharg != depthparam))
  36. + needsRef = true;
  37. + }
  38. + }
  39. + }
  40. + if (!getParamTypeForDecl()->isReferenceType() && needsRef)
  41. Out << '&';
  42. ND->printQualifiedName(Out);
  43. break;
  44. diff --git a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
  45. index ab3344bc991..86b9fb69901 100644
  46. --- a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
  47. +++ b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
  48. @@ -90,7 +90,7 @@ template <typename T, void (*)(void)>
  49. void fn_tmpl() {}
  50.  
  51. template void fn_tmpl<int, freefunc>();
  52. -// CHECK-DAG: "fn_tmpl<int,&freefunc>"
  53. +// CHECK-DAG: "fn_tmpl<int,freefunc>"
  54.  
  55. template <typename A, typename B, typename C> struct ClassTemplate { A a; B b; C c; };
  56. ClassTemplate<char, short, ClassTemplate<int, int, int> > f;
  57. diff --git a/clang/test/CodeGenCXX/debug-info-template.cpp b/clang/test/CodeGenCXX/debug-info-template.cpp
  58. index a07222ace15..c79441cbb5c 100644
  59. --- a/clang/test/CodeGenCXX/debug-info-template.cpp
  60. +++ b/clang/test/CodeGenCXX/debug-info-template.cpp
  61. @@ -1,6 +1,6 @@
  62. // RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
  63.  
  64. -// CHECK: @tci = dso_local global %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested" zeroinitializer, align 1, !dbg [[TCI:![0-9]+]]
  65. +// CHECK: @tci = dso_local global %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, foo::g, 1, 2, 3>::nested" zeroinitializer, align 1, !dbg [[TCI:![0-9]+]]
  66. // CHECK: @tcn = dso_local global %struct.TC zeroinitializer, align 1, !dbg [[TCN:![0-9]+]]
  67. // CHECK: @nn = dso_local global %struct.NN zeroinitializer, align 1, !dbg [[NN:![0-9]+]]
  68.  
  69. @@ -31,7 +31,7 @@ void func();
  70. // CHECK: ![[TCNESTED]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "nested",
  71. // CHECK-SAME: scope: ![[TC:[0-9]+]],
  72.  
  73. -// CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>"
  74. +// CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC<unsigned int, 2, &glb, &foo::e, &foo::f, foo::g, 1, 2, 3>"
  75. // CHECK-SAME: templateParams: [[TCARGS:![0-9]*]]
  76. TC
  77. // CHECK: [[TCARGS]] = !{[[TCARG1:![0-9]*]], [[TCARG2:![0-9]*]], [[TCARG3:![0-9]*]], [[TCARG4:![0-9]*]], [[TCARG5:![0-9]*]], [[TCARG6:![0-9]*]], [[TCARG7:![0-9]*]]}
  78. diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
  79. index 460b6def5d6..b080fa28478 100644
  80. --- a/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
  81. +++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
  82. @@ -65,3 +65,22 @@ namespace PR42513 {
  83.  
  84. void use() { f<X1>(); }
  85. }
  86. +
  87. +using FourChars = const char[4];
  88. +constexpr FourChars kEta = "Eta";
  89. +constexpr const char* kNull = "Phi";
  90. +
  91. +template <const char*, typename T> class Column {};
  92. +template <const char[], typename T> class Dolumn {};
  93. +template <const char(*)[4], typename T> class Folumn {};
  94. +template <FourChars*, typename T> class Golumn {};
  95. +template <const char* const *, typename T> class Holumn {};
  96. +
  97. +void lookup() {
  98. + Column<kEta,double>().ls(); // expected-error {{<kEta,}}
  99. + Column<nullptr, double>().ls(); // expected-error {{<nullptr,}}
  100. + Dolumn<kEta, double>().ls(); // expected-error {{<kEta,}}
  101. + Folumn<&kEta, double>().ls(); // expected-error {{<&kEta,}}
  102. + Golumn<&kEta, double>().ls(); // expected-error {{<&kEta,}}
  103. + Holumn<&kNull, double>().ls(); // expected-error {{<&kNull,}}
  104. +}
Add Comment
Please, Sign In to add comment