[PATCH] D99978: [lld] Fixed CodeView GuidAdapter::format to handle GUID bytes in the right order.

Alex Orlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 16:08:49 PDT 2021


aorlov marked an inline comment as done.
aorlov added inline comments.


================
Comment at: llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp:163
+  MSGuid G = {};
+  bool GotHex = to_integer(StringRef(Scalar.data() + 1, 8), G.Data1, 16);
+  GotHex &= to_integer(StringRef(Scalar.data() + 10, 4), G.Data2, 16);
----------------
aganea wrote:
> In order to avoid any magical offsets into the string, can you possibly keep a loop, but add a counter and successively write into Data1, Data2, Data3, etc.? Something like:
> ```
>   uint8_t *OutBuffer = S.Guid;
>   unsigned Index = 0;
>   uint64_t D41{}, D42{};
>   bool GotHex;
>   for (auto Iter = Scalar.begin(); Iter != Scalar.end(); ++Iter) {
>     auto Next = std::find_if(Iter, Scalar.end(), std::isxdigit);
>     if (Next == Scalar.end())
>       break;
>     StringRef Group(Iter, Next - Iter);
>     if (Index == 0)
>       GotHex = to_integer(Group, G.Data1, 16);
>     else if (Index == 1)
>       GotHex &= to_integer(Group, G.Data2, 16);
>     else if (Index == 2)
>       GotHex &= to_integer(Group, G.Data3, 16);
>     else if (Index == 3)
>       GotHex &= to_integer(Group, D41, 16);
>     else if (Index == 4)
>       GotHex &= to_integer(Group, D42, 16);
>     ++Index;
>   }
>   G.Data4 = (D41 << 48) | D42;
> ```
No magical offsets, no loops. But I kept the maximal validation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99978/new/

https://reviews.llvm.org/D99978



More information about the llvm-commits mailing list