Introduce a compiler-optimization safe memset() alternative

memset() may be optimized away by the
compiler if zero'ing is considered to
have no side-effects.

This change adds always_memset(), an
implementation that indirects writes via
a volatile pointer and hence survives
optimization.

Tested against x86-64 Clang 3.9.0,
x86-64 Gcc 6.2, ARM64 gcc 4.8, and
ARM gcc 4.8.2.

BRANCH=none
BUG=none
TEST=compilation succeeds

Change-Id: Ib1d3d0c0450bf2c95b3ffcf566a484e1db6a908d
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/400467
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Marius Schilder <mschilder@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
4 files changed