[libc][NFC] Make x86_64 fenv functions msan safe.
These functions used inline asm to read FPU state. This change adds
explicit unpoisoning in these functions as the sanitizers don't see the
read operations.
GitOrigin-RevId: 001a12ed59c354aa759ff3e104748c36803cfaa2
diff --git a/src/__support/CMakeLists.txt b/src/__support/CMakeLists.txt
index 980b510..32f538e 100644
--- a/src/__support/CMakeLists.txt
+++ b/src/__support/CMakeLists.txt
@@ -2,4 +2,5 @@
common
HDRS
common.h
+ sanitizer_annotations.h
)
diff --git a/utils/FPUtil/CMakeLists.txt b/utils/FPUtil/CMakeLists.txt
index 2c1c166..43ee643 100644
--- a/utils/FPUtil/CMakeLists.txt
+++ b/utils/FPUtil/CMakeLists.txt
@@ -31,6 +31,7 @@
libc.include.math
libc.include.errno
libc.include.fenv
+ libc.src.__support.common
libc.utils.CPP.standalone_cpp
)
diff --git a/utils/FPUtil/x86_64/FEnv.h b/utils/FPUtil/x86_64/FEnv.h
index 3fb4881..1196aba 100644
--- a/utils/FPUtil/x86_64/FEnv.h
+++ b/utils/FPUtil/x86_64/FEnv.h
@@ -12,6 +12,8 @@
#include <fenv.h>
#include <stdint.h>
+#include "src/__support/sanitizer_annotations.h"
+
namespace __llvm_libc {
namespace fputil {
@@ -95,6 +97,7 @@
static inline uint16_t getX87ControlWord() {
uint16_t w;
__asm__ __volatile__("fnstcw %0" : "=m"(w)::);
+ SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w));
return w;
}
@@ -105,6 +108,7 @@
static inline uint16_t getX87StatusWord() {
uint16_t w;
__asm__ __volatile__("fnstsw %0" : "=m"(w)::);
+ SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w));
return w;
}
@@ -115,6 +119,7 @@
static inline uint32_t getMXCSR() {
uint32_t w;
__asm__ __volatile__("stmxcsr %0" : "=m"(w)::);
+ SANITIZER_MEMORY_INITIALIZED(&w, sizeof(w));
return w;
}
@@ -124,6 +129,7 @@
static inline void getX87StateDescriptor(X87StateDescriptor &s) {
__asm__ __volatile__("fnstenv %0" : "=m"(s));
+ SANITIZER_MEMORY_INITIALIZED(&s, sizeof(s));
}
static inline void writeX87StateDescriptor(const X87StateDescriptor &s) {