Fix Reg<long double> for MSAN

On x86 `long double` has 10 bytes of meaningful data, but `sizeof(long double)` is 16 - the remaining bytes are random garbage.

PiperOrigin-RevId: 367423349
Change-Id: I769b3444ce4fa60f941ccd2115b0b09ccc809f13
This commit is contained in:
Wiktor Garbacz 2021-04-08 07:10:16 -07:00 committed by Copybara-Service
parent 17f561f221
commit 16880d4e3c
4 changed files with 8 additions and 3 deletions

View File

@ -157,6 +157,7 @@ cc_library(
"//sandboxed_api/sandbox2:comms",
"//sandboxed_api/util:status",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:dynamic_annotations",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",

View File

@ -150,6 +150,7 @@ add_library(sapi_vars ${SAPI_LIB_TYPE}
add_library(sapi::vars ALIAS sapi_vars)
target_link_libraries(sapi_vars
PRIVATE absl::core_headers
absl::dynamic_annotations
absl::status
absl::statusor
absl::str_format

View File

@ -396,6 +396,8 @@ void ServeRequest(sandbox2::Comms* comms) {
}
if (ret.ret_type == v::Type::kFloat) {
// Make MSAN happy with long double.
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(ret.float_val, sizeof(ret.float_val));
VLOG(1) << "Returned value: " << ret.float_val
<< ", Success: " << (ret.success ? "Yes" : "No");
} else {

View File

@ -19,6 +19,7 @@
#include <type_traits>
#include <glog/logging.h>
#include "absl/base/dynamic_annotations.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "sandboxed_api/var_abstract.h"
@ -57,10 +58,10 @@ class Reg : public Callable {
"Only register-sized types are allowed as template argument "
"for class Reg.");
Reg() : Reg(static_cast<T>(0)) {}
explicit Reg(const T val) {
explicit Reg(const T val = {}) {
val_ = val;
// Make MSAN happy with long double.
ABSL_ANNOTATE_MEMORY_IS_INITIALIZED(val_, sizeof(val_));
SetLocal(&val_);
}