[PATCH] D123436: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

Jun Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 26 16:50:30 PDT 2022


junaire added a comment.

In D123436#3475002 <https://reviews.llvm.org/D123436#3475002>, @dblaikie wrote:

> In D123436#3462567 <https://reviews.llvm.org/D123436#3462567>, @dblaikie wrote:
>
>> Perhaps GlobalModuleIndex should create the cursor itself - it's being handed the buffer anyway?
>
> Ping on this ^ - would this be a better direction that addresses the concerns?

Sorry about missing this! :(
However, I'm not sure that I understand your idea. Do you mean we can simply pass the buffer to the `GlobalModuleIndex` then we can construct the cursor in the constructor itself? IMHO, we can't. that's because we need to use the cursor to sniff for the signature of the buffer, and we will return an error if it is failed. Please let me know if I understand you wrong :)

    /// The main bitstream cursor for the main block.
    llvm::BitstreamCursor Cursor(*Buffer);
  
    // Sniff for the signature.
    for (unsigned char C : {'B', 'C', 'G', 'I'}) {
      if (Expected<llvm::SimpleBitstreamCursor::word_t> Res = Cursor.Read(8)) {
        if (Res.get() != C)
          return std::make_pair(
              nullptr, llvm::createStringError(std::errc::illegal_byte_sequence,
                                               "expected signature BCGI"));
      } else
        return std::make_pair(nullptr, Res.takeError());
    }
  
    return std::make_pair(new GlobalModuleIndex(std::move(Buffer), std::move(Cursor)),
                          llvm::Error::success());
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436



More information about the cfe-commits mailing list