Skip to content

[Swift Next] fix missing StringRef::withNullAsEmpty #38131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ using llvm::BCBlockRAII;

ASTContext &SerializerBase::getASTContext() const { return M->getASTContext(); }

static StringRef withNullAsEmptyStringRef(const char *data) {
return StringRef(data ? data : "");
}

/// Used for static_assert.
static constexpr bool declIDFitsIn32Bits() {
using Int32Info = std::numeric_limits<uint32_t>;
Expand Down Expand Up @@ -5554,7 +5558,7 @@ void swift::serializeToBuffers(
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
const SILModule *M) {

assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());
{
FrontendStatsTracer tracer(getContext(DC).Stats,
"Serialization, swiftmodule, to buffer");
Expand All @@ -5575,7 +5579,7 @@ void swift::serializeToBuffers(
std::move(buf), options.OutputPath);
}

if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
FrontendStatsTracer tracer(getContext(DC).Stats,
"Serialization, swiftdoc, to buffer");
llvm::SmallString<1024> buf;
Expand All @@ -5592,7 +5596,7 @@ void swift::serializeToBuffers(
std::move(buf), options.DocOutputPath);
}

if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
FrontendStatsTracer tracer(getContext(DC).Stats,
"Serialization, swiftsourceinfo, to buffer");
llvm::SmallString<1024> buf;
Expand All @@ -5614,12 +5618,12 @@ void swift::serialize(ModuleOrSourceFile DC,
const SerializationOptions &options,
const SILModule *M,
const fine_grained_dependencies::SourceFileDepGraph *DG) {
assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());

if (StringRef(options.OutputPath) == "-") {
// Special-case writing to stdout.
Serializer::writeToStream(llvm::outs(), DC, M, options, DG);
assert(StringRef::withNullAsEmpty(options.DocOutputPath).empty());
assert(withNullAsEmptyStringRef(options.DocOutputPath).empty());
return;
}

Expand All @@ -5634,7 +5638,7 @@ void swift::serialize(ModuleOrSourceFile DC,
if (hadError)
return;

if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
(void)withOutputFile(getContext(DC).Diags,
options.DocOutputPath,
[&](raw_ostream &out) {
Expand All @@ -5645,7 +5649,7 @@ void swift::serialize(ModuleOrSourceFile DC,
});
}

if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
(void)withOutputFile(getContext(DC).Diags,
options.SourceInfoOutputPath,
[&](raw_ostream &out) {
Expand Down