Mitigation for MSL atomic bounds check. (#1703)

[msl-out] Correct output for bounds-checked atomic accesses.
This commit is contained in:
glalonde authored and GitHub committed 2022-02-01 16:37:09 -08:00
1 parent 2ddc8d1929
commit bb604fd6a3
5 files changed
+100 -1

No files matched your search

+19 -1
View File
@@ -791,15 +791,33 @@ impl<W: Write> Writer<W> {
value: Handle<crate::Expression>,
context: &ExpressionContext,
) -> BackendResult {
// If the pointer we're passing to the atomic operation needs to be conditional
// for `ReadZeroSkipWrite`, the condition needs to *surround* the atomic op, and
// the pointer operand should be unchecked.
let policy = context.choose_bounds_check_policy(pointer);
let checked = policy == index::BoundsCheckPolicy::ReadZeroSkipWrite
&& self.put_bounds_checks(pointer, context, back::Level(0), "")?;
// If requested and successfully put bounds checks, continue the ternary expression.
if checked {
write!(self.out, " ? ")?;
}
write!(
self.out,
"{}::atomic_fetch_{}_explicit({}",
NAMESPACE, key, ATOMIC_REFERENCE
)?;
self.put_expression(pointer, context, true)?;
self.put_access_chain(pointer, policy, context)?;
write!(self.out, ", ")?;
self.put_expression(value, context, true)?;
write!(self.out, ", {}::memory_order_relaxed)", NAMESPACE)?;
// Finish the ternary expression.
if checked {
write!(self.out, " : DefaultConstructible()")?;
}
Ok(())
}