Skip to content

Commit 3be2be5

Browse files
committed
[MemoryBehavior] Cleanup and document logic for access to readonly memory location.
1 parent 5ed14f1 commit 3be2be5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Diff for: lib/SILAnalysis/MemoryBehavior.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ class MemoryBehaviorVisitor
6666
// If we do not have any more information, just use the general memory
6767
// behavior implementation.
6868
auto Behavior = Inst->getMemoryBehavior();
69-
if (!isLetPointer(V))
69+
bool ReadOnlyAccess = isLetPointer(V);
70+
71+
// If this is a regular read-write access then return the computed memory
72+
// behavior.
73+
if (!ReadOnlyAccess)
7074
return Behavior;
7175

76+
// If this is a read-only access to 'let variable' then we can strip away
77+
// the write access.
7278
switch (Behavior) {
73-
case MemBehavior::MayHaveSideEffects:
74-
return MemBehavior::MayRead;
75-
case MemBehavior::MayReadWrite:
76-
return MemBehavior::MayRead;
77-
case MemBehavior::MayWrite:
78-
return MemBehavior::None;
79-
default:
80-
return Behavior;
79+
case MemBehavior::MayHaveSideEffects: return MemBehavior::MayRead;
80+
case MemBehavior::MayReadWrite: return MemBehavior::MayRead;
81+
case MemBehavior::MayWrite: return MemBehavior::None;
82+
default: return Behavior;
8183
}
8284
}
8385

0 commit comments

Comments
 (0)