[DebugInfo] Add a free helper to get empty locations, NFC
(cherry picked from commit e33f3b663d52c5aab059159123e1ea78d2b87569)
diff --git a/include/swift/SIL/SILLocation.h b/include/swift/SIL/SILLocation.h
index 7b7ab4e..9964ba1 100644
--- a/include/swift/SIL/SILLocation.h
+++ b/include/swift/SIL/SILLocation.h
@@ -502,6 +502,10 @@
}
};
+/// Empty locations may be applied to instructions without any clear
+/// correspondence to an AST node.
+static inline RegularLocation getEmptyLocation() { return {SourceLoc()}; }
+
/// Used to represent a return instruction in user code.
///
/// Allowed on an BranchInst, ReturnInst.
@@ -705,7 +709,7 @@
SILLocation Location;
public:
- SILDebugLocation() : Scope(nullptr), Location(RegularLocation(SourceLoc())) {}
+ SILDebugLocation() : Scope(nullptr), Location(getEmptyLocation()) {}
SILDebugLocation(SILLocation Loc, const SILDebugScope *DS)
: Scope(DS), Location(Loc) {}
SILLocation getLocation() const { return Location; }
diff --git a/lib/SILGen/SILGenProlog.cpp b/lib/SILGen/SILGenProlog.cpp
index ca307e3..531b774 100644
--- a/lib/SILGen/SILGenProlog.cpp
+++ b/lib/SILGen/SILGenProlog.cpp
@@ -522,7 +522,7 @@
// Record the ArgNo of the artificial $error inout argument.
unsigned ArgNo = emitter.getNumArgs();
if (throws) {
- RegularLocation Loc{SourceLoc()};
+ RegularLocation Loc = getEmptyLocation();
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC))
Loc = AFD->getThrowsLoc();
else if (auto *ACE = dyn_cast<AbstractClosureExpr>(DC))
diff --git a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
index a801cb1..12e16cd 100644
--- a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
+++ b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
@@ -2177,7 +2177,7 @@
// Use an empty location for the alloc_stack. If Loc is variable declaration
// the alloc_stack would look like the storage of that variable.
auto *ControlVariableBox =
- B.createAllocStack(RegularLocation(SourceLoc()), IVType);
+ B.createAllocStack(getEmptyLocation(), IVType);
// Find all the return blocks in the function, inserting a dealloc_stack
// before the return.
diff --git a/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp b/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp
index cf293f0..edea7c1 100644
--- a/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp
+++ b/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp
@@ -979,12 +979,10 @@
if (Arg->getType().isAddress()) {
assert(AD.PInfo->getConvention() == ParameterConvention::Indirect_In
&& F.getConventions().useLoweredAddresses());
- Builder.createDestroyAddr(RegularLocation(SourceLoc()),
- F.getArguments()[AD.Index]);
+ Builder.createDestroyAddr(getEmptyLocation(), F.getArguments()[AD.Index]);
return;
}
- Builder.createReleaseValue(RegularLocation(SourceLoc()),
- F.getArguments()[AD.Index],
+ Builder.createReleaseValue(getEmptyLocation(), F.getArguments()[AD.Index],
Builder.getDefaultAtomicity());
}
@@ -1028,13 +1026,13 @@
SILInstruction *Call = findOnlyApply(F);
if (auto AI = dyn_cast<ApplyInst>(Call)) {
Builder.setInsertionPoint(&*std::next(SILBasicBlock::iterator(AI)));
- Builder.createRetainValue(RegularLocation(SourceLoc()), AI,
+ Builder.createRetainValue(getEmptyLocation(), AI,
Builder.getDefaultAtomicity());
} else {
SILBasicBlock *NormalBB = cast<TryApplyInst>(Call)->getNormalBB();
Builder.setInsertionPoint(&*NormalBB->begin());
- Builder.createRetainValue(RegularLocation(SourceLoc()),
- NormalBB->getArgument(0), Builder.getDefaultAtomicity());
+ Builder.createRetainValue(getEmptyLocation(), NormalBB->getArgument(0),
+ Builder.getDefaultAtomicity());
}
}
diff --git a/lib/SILOptimizer/Utils/Local.cpp b/lib/SILOptimizer/Utils/Local.cpp
index 0b49b82..6f66457 100644
--- a/lib/SILOptimizer/Utils/Local.cpp
+++ b/lib/SILOptimizer/Utils/Local.cpp
@@ -50,7 +50,7 @@
// Set up the builder we use to insert at our insertion point.
SILBuilder B(InsertPt);
- auto Loc = RegularLocation(SourceLoc());
+ auto Loc = getEmptyLocation();
// If Ptr is refcounted itself, create the strong_retain and
// return.
@@ -75,7 +75,7 @@
// Setup the builder we will use to insert at our insertion point.
SILBuilder B(InsertPt);
- auto Loc = RegularLocation(SourceLoc());
+ auto Loc = getEmptyLocation();
// If Ptr has reference semantics itself, create a strong_release.
if (Ptr->getType().isReferenceCounted(B.getModule())) {
diff --git a/lib/SILOptimizer/Utils/LoopUtils.cpp b/lib/SILOptimizer/Utils/LoopUtils.cpp
index e8e8e4b..bef98dd 100644
--- a/lib/SILOptimizer/Utils/LoopUtils.cpp
+++ b/lib/SILOptimizer/Utils/LoopUtils.cpp
@@ -35,7 +35,7 @@
}
// Create the branch to the header.
- SILBuilder(Preheader).createBranch(RegularLocation(SourceLoc()), Header,
+ SILBuilder(Preheader).createBranch(getEmptyLocation(), Header,
Args);
return Preheader;
diff --git a/lib/Serialization/DeserializeSIL.cpp b/lib/Serialization/DeserializeSIL.cpp
index fad1870..360bd28 100644
--- a/lib/Serialization/DeserializeSIL.cpp
+++ b/lib/Serialization/DeserializeSIL.cpp
@@ -452,7 +452,7 @@
auto fn = existingFn;
// TODO: use the correct SILLocation from module.
- SILLocation loc = RegularLocation(SourceLoc());
+ SILLocation loc = getEmptyLocation();
// If we have an existing function, verify that the types match up.
if (fn) {