Skip to content

Commit cde0862

Browse files
authored
Merge pull request swiftlang#21537 from compnerd/optimize-incorrectly
SILOptimizer: fix a few instances of use-after-free
2 parents 608b79e + bd93229 commit cde0862

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,13 @@ void LifetimeChecker::handleStoreUse(unsigned UseID) {
925925
// a diagnostic.
926926
if (!shouldEmitError(Use.Inst))
927927
continue;
928-
928+
929929
std::string PropertyName;
930930
auto *VD = TheMemory.getPathStringToElement(i, PropertyName);
931931
diagnose(Module, Use.Inst->getLoc(),
932-
diag::immutable_property_already_initialized, PropertyName);
933-
932+
diag::immutable_property_already_initialized,
933+
StringRef(PropertyName));
934+
934935
if (auto *Var = dyn_cast<VarDecl>(VD)) {
935936
if (Var->getParentInitializer())
936937
diagnose(Module, SILLocation(VD),
@@ -1085,7 +1086,7 @@ void LifetimeChecker::handleInOutUse(const DIMemoryUse &Use) {
10851086

10861087
std::string PropertyName;
10871088
auto VD = TheMemory.getPathStringToElement(i, PropertyName);
1088-
1089+
10891090
// Try to produce a specific error message about the inout use. If this is
10901091
// a call to a method or a mutating property access, indicate that.
10911092
// Otherwise, we produce a generic error.
@@ -1150,15 +1151,15 @@ void LifetimeChecker::handleInOutUse(const DIMemoryUse &Use) {
11501151
: diag::using_mutating_accessor_on_immutable_value,
11511152
accessor->getStorage()->getBaseName(),
11521153
isa<SubscriptDecl>(accessor->getStorage()),
1153-
PropertyName);
1154+
StringRef(PropertyName));
11541155
} else if (FD && FD->isOperator()) {
11551156
diagnose(Module, Use.Inst->getLoc(),
11561157
diag::mutating_method_called_on_immutable_value,
1157-
FD->getName(), /*operator*/ 1, PropertyName);
1158+
FD->getName(), /*operator*/ 1, StringRef(PropertyName));
11581159
} else if (FD && isSelfParameter) {
11591160
diagnose(Module, Use.Inst->getLoc(),
11601161
diag::mutating_method_called_on_immutable_value,
1161-
FD->getName(), /*method*/ 0, PropertyName);
1162+
FD->getName(), /*method*/ 0, StringRef(PropertyName));
11621163
} else if (isAssignment) {
11631164
diagnose(Module, Use.Inst->getLoc(),
11641165
diag::assignment_to_immutable_value, StringRef(PropertyName));

0 commit comments

Comments
 (0)