================
@@ -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};
+}
----------------
BStott6 wrote:
> Can we use some existing utilities (perhaps `std::from_chars` or from
> `StringRef`) to avoid manually parsing numbers?
As I understand it, use of standard library functions in the sanitizers is not
allowed as users may not be linking to the (C or C++) standard libraries, and
interceptors may erroneously intercept any calls. However, there is an existing
function `internal_atoll` in `sanitizer_libc` which can be used for this
purpose 👍
https://github.com/llvm/llvm-project/pull/166381
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits