[PATCH] D38643: PR13575: Fix USR mangling for fixed-size arrays.

Jan Korous via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 6 13:10:08 PDT 2017


jkorous-apple created this revision.

Added array type mangling to USR generation. Included test from bug report.


Repository:
  rL LLVM

https://reviews.llvm.org/D38643

Files:
  lib/Index/USRGeneration.cpp
  test/Index/USR/array-type.cpp


Index: test/Index/USR/array-type.cpp
===================================================================
--- /dev/null
+++ test/Index/USR/array-type.cpp
@@ -0,0 +1,8 @@
+// RUN: c-index-test core -print-source-symbols -- %s | grep "function(Gen,TS)/C++" | grep foo | cut -s -d "|" -f 4 | uniq | wc -l | grep 3
+
+// Function template specializations differing in array type parameter should have unique USRs.
+
+template<class buffer> void foo(buffer);
+template<> void foo<char[16]>(char[16]);
+template<> void foo<char[32]>(char[32]);
+template<> void foo<char[64]>(char[64]);
Index: lib/Index/USRGeneration.cpp
===================================================================
--- lib/Index/USRGeneration.cpp
+++ lib/Index/USRGeneration.cpp
@@ -816,6 +816,22 @@
       T = VT->getElementType();
       continue;
     }
+    if (const ArrayType *const AT = dyn_cast<ArrayType>(T)) {
+      VisitType(AT->getElementType());
+      Out << "[";
+
+      switch( AT->getSizeModifier() ) {
+        case ArrayType::Static  : Out << "s"; break;
+        case ArrayType::Star    : Out << "*"; break;
+        default                 : ;
+      }
+      if (const ConstantArrayType* const CAT = dyn_cast<ConstantArrayType>(T)) {
+        Out << CAT->getSize();
+      }
+
+      Out << "]";
+      return;
+    }
 
     // Unhandled type.
     Out << ' ';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38643.118060.patch
Type: text/x-patch
Size: 1352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171006/12a512ed/attachment.bin>


More information about the cfe-commits mailing list