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

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 09:30:41 PDT 2021


aganea added a comment.

Thanks for integrating the 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);
----------------
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;
```


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