Skip to content

Commit a45d5ca

Browse files
authored
Merge pull request #38131 from etcwilde/ewilde/swift-next/fix-StringRef-withNullAsEmpty
[Swift Next] fix missing `StringRef::withNullAsEmpty`
2 parents d928d79 + f08e3eb commit a45d5ca

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ using llvm::BCBlockRAII;
7878

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

81+
static StringRef withNullAsEmptyStringRef(const char *data) {
82+
return StringRef(data ? data : "");
83+
}
84+
8185
/// Used for static_assert.
8286
static constexpr bool declIDFitsIn32Bits() {
8387
using Int32Info = std::numeric_limits<uint32_t>;
@@ -5554,7 +5558,7 @@ void swift::serializeToBuffers(
55545558
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
55555559
const SILModule *M) {
55565560

5557-
assert(!StringRef::withNullAsEmpty(options.OutputPath).empty());
5561+
assert(!withNullAsEmptyStringRef(options.OutputPath).empty());
55585562
{
55595563
FrontendStatsTracer tracer(getContext(DC).Stats,
55605564
"Serialization, swiftmodule, to buffer");
@@ -5575,7 +5579,7 @@ void swift::serializeToBuffers(
55755579
std::move(buf), options.OutputPath);
55765580
}
55775581

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

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

56195623
if (StringRef(options.OutputPath) == "-") {
56205624
// Special-case writing to stdout.
56215625
Serializer::writeToStream(llvm::outs(), DC, M, options, DG);
5622-
assert(StringRef::withNullAsEmpty(options.DocOutputPath).empty());
5626+
assert(withNullAsEmptyStringRef(options.DocOutputPath).empty());
56235627
return;
56245628
}
56255629

@@ -5634,7 +5638,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56345638
if (hadError)
56355639
return;
56365640

5637-
if (!StringRef::withNullAsEmpty(options.DocOutputPath).empty()) {
5641+
if (!withNullAsEmptyStringRef(options.DocOutputPath).empty()) {
56385642
(void)withOutputFile(getContext(DC).Diags,
56395643
options.DocOutputPath,
56405644
[&](raw_ostream &out) {
@@ -5645,7 +5649,7 @@ void swift::serialize(ModuleOrSourceFile DC,
56455649
});
56465650
}
56475651

5648-
if (!StringRef::withNullAsEmpty(options.SourceInfoOutputPath).empty()) {
5652+
if (!withNullAsEmptyStringRef(options.SourceInfoOutputPath).empty()) {
56495653
(void)withOutputFile(getContext(DC).Diags,
56505654
options.SourceInfoOutputPath,
56515655
[&](raw_ostream &out) {

0 commit comments

Comments
 (0)