[PATCH] D138658: [DebugInfo] Store optional DIFile::Source as pointer

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 02:26:33 PST 2022


Hahnfeld added a comment.

FWIW if we keep the `std::optional` and just deal with the possibility of a `nullptr` inside, all we seem to need is

  patch
  diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
  index c85c21ddd9f1..2a757fb74674 100644
  --- a/llvm/include/llvm/IR/DebugInfoMetadata.h
  +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
  @@ -654,8 +654,9 @@ public:
       return StringRefChecksum;
     }
     std::optional<StringRef> getSource() const {
  -    return Source ? std::optional<StringRef>((*Source)->getString())
  -                  : std::nullopt;
  +    if (!Source)
  +      return std::nullopt;
  +    return std::optional<StringRef>(*Source ? (*Source)->getString() : "");
     }
   
     MDString *getRawFilename() const { return getOperandAs<MDString>(0); }

and the same tests as added here will pass.


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

https://reviews.llvm.org/D138658



More information about the llvm-commits mailing list