================
@@ -40,20 +41,62 @@ tysan_copy_types(const void *daddr, const void *saddr, uptr 
size) {
     internal_memmove(shadow_for(daddr), shadow_for(saddr), size * 
sizeof(uptr));
 }
 
-static const char *getDisplayName(const char *Name) {
+/// Struct returned by `parseIndirectionPrefix`.
+struct ParseIndirectionPrefixResult {
+  /// Level of indirection - 0 if the prefix is not found.
+  size_t Indirection;
+  /// Pointer to the remaining part of the name after the indirection prefix.
+  /// (This is the original pointer if the prefix is not found.)
+  const char *RemainingName;
+};
+
+/// Parses the "p{indirection} " prefix given to pointer type names in TBAA.
+static ParseIndirectionPrefixResult parseIndirectionPrefix(const char *Name) {
+  size_t CharIndex = 0;
+
+  // Parse 'p'.
+  // This also handles the case of an empty string.
+  if (Name[CharIndex++] != 'p')
+    return {0, Name};
+
+  // Parse indirection level.
+  size_t Indirection = 0;
+  while (isdigit(Name[CharIndex])) {
+    const auto DigitValue = static_cast<size_t>(Name[CharIndex] - '0');
+    Indirection = Indirection * 10 + DigitValue;
+    ++CharIndex;
+  }
+
+  // Parse space.
+  if (Name[CharIndex++] != ' ')
+    return {0, Name};
+
+  return {Indirection, Name + CharIndex};
+}
----------------
fhahn wrote:

Can we use some existing utilities (perhaps `std::from_chars` or from 
`StringRef`) to avoid manually parsing numbers?

https://github.com/llvm/llvm-project/pull/166381
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to